comparison vdp.c @ 2243:0d1d5dccdd28

Initial implementation of oscilloscope debug view
author Michael Pavone <pavone@retrodev.com>
date Tue, 22 Nov 2022 17:57:02 -0800
parents c149c929361c
children e6bad7bd8751
comparison
equal deleted inserted replaced
2240:8e8db9141209 2243:0d1d5dccdd28
262 void vdp_free(vdp_context *context) 262 void vdp_free(vdp_context *context)
263 { 263 {
264 if (headless) { 264 if (headless) {
265 free(context->fb); 265 free(context->fb);
266 } 266 }
267 for (int i = 0; i < VDP_NUM_DEBUG_TYPES; i++) 267 for (int i = 0; i < NUM_DEBUG_TYPES; i++)
268 { 268 {
269 if (context->enabled_debuggers & (1 << i)) { 269 if (context->enabled_debuggers & (1 << i)) {
270 vdp_toggle_debug_view(context, i); 270 vdp_toggle_debug_view(context, i);
271 } 271 }
272 } 272 }
1898 } else { 1898 } else {
1899 jump_start = 0xDB; 1899 jump_start = 0xDB;
1900 jump_end = 0x1D5; 1900 jump_end = 0x1D5;
1901 } 1901 }
1902 1902
1903 if (context->enabled_debuggers & (1 << VDP_DEBUG_CRAM | 1 << VDP_DEBUG_COMPOSITE)) { 1903 if (context->enabled_debuggers & (1 << DEBUG_CRAM | 1 << DEBUG_COMPOSITE)) {
1904 uint32_t line = context->vcounter; 1904 uint32_t line = context->vcounter;
1905 if (line >= jump_end) { 1905 if (line >= jump_end) {
1906 line -= jump_end - jump_start; 1906 line -= jump_end - jump_start;
1907 } 1907 }
1908 uint32_t total_lines = (context->flags2 & FLAG2_REGION_PAL) ? 313 : 262; 1908 uint32_t total_lines = (context->flags2 & FLAG2_REGION_PAL) ? 313 : 262;
1910 if (total_lines - line <= context->border_top) { 1910 if (total_lines - line <= context->border_top) {
1911 line -= total_lines - context->border_top; 1911 line -= total_lines - context->border_top;
1912 } else { 1912 } else {
1913 line += context->border_top; 1913 line += context->border_top;
1914 } 1914 }
1915 if (context->enabled_debuggers & (1 << VDP_DEBUG_CRAM)) { 1915 if (context->enabled_debuggers & (1 << DEBUG_CRAM)) {
1916 uint32_t *fb = context->debug_fbs[VDP_DEBUG_CRAM] + context->debug_fb_pitch[VDP_DEBUG_CRAM] * line / sizeof(uint32_t); 1916 uint32_t *fb = context->debug_fbs[DEBUG_CRAM] + context->debug_fb_pitch[DEBUG_CRAM] * line / sizeof(uint32_t);
1917 if (context->regs[REG_MODE_2] & BIT_MODE_5) { 1917 if (context->regs[REG_MODE_2] & BIT_MODE_5) {
1918 for (int i = 0; i < 64; i++) 1918 for (int i = 0; i < 64; i++)
1919 { 1919 {
1920 for (int x = 0; x < 8; x++) 1920 for (int x = 0; x < 8; x++)
1921 { 1921 {
1931 } 1931 }
1932 } 1932 }
1933 } 1933 }
1934 } 1934 }
1935 if ( 1935 if (
1936 context->enabled_debuggers & (1 << VDP_DEBUG_COMPOSITE) 1936 context->enabled_debuggers & (1 << DEBUG_COMPOSITE)
1937 && line < (context->inactive_start + context->border_bot + context->border_top) 1937 && line < (context->inactive_start + context->border_bot + context->border_top)
1938 ) { 1938 ) {
1939 uint32_t *fb = context->debug_fbs[VDP_DEBUG_COMPOSITE] + context->debug_fb_pitch[VDP_DEBUG_COMPOSITE] * line / sizeof(uint32_t); 1939 uint32_t *fb = context->debug_fbs[DEBUG_COMPOSITE] + context->debug_fb_pitch[DEBUG_COMPOSITE] * line / sizeof(uint32_t);
1940 for (int i = 0; i < LINEBUF_SIZE; i++) 1940 for (int i = 0; i < LINEBUF_SIZE; i++)
1941 { 1941 {
1942 *(fb++) = context->debugcolors[context->layer_debug_buf[i]]; 1942 *(fb++) = context->debugcolors[context->layer_debug_buf[i]];
1943 } 1943 }
1944 } 1944 }
1968 } 1968 }
1969 } 1969 }
1970 1970
1971 static void vdp_update_per_frame_debug(vdp_context *context) 1971 static void vdp_update_per_frame_debug(vdp_context *context)
1972 { 1972 {
1973 if (context->enabled_debuggers & (1 << VDP_DEBUG_PLANE)) { 1973 if (context->enabled_debuggers & (1 << DEBUG_PLANE)) {
1974 uint32_t pitch; 1974 uint32_t pitch;
1975 uint32_t *fb = render_get_framebuffer(context->debug_fb_indices[VDP_DEBUG_PLANE], &pitch); 1975 uint32_t *fb = render_get_framebuffer(context->debug_fb_indices[DEBUG_PLANE], &pitch);
1976 uint16_t hscroll_mask; 1976 uint16_t hscroll_mask;
1977 uint16_t v_mul; 1977 uint16_t v_mul;
1978 uint16_t vscroll_mask = 0x1F | (context->regs[REG_SCROLL] & 0x30) << 1; 1978 uint16_t vscroll_mask = 0x1F | (context->regs[REG_SCROLL] & 0x30) << 1;
1979 switch(context->regs[REG_SCROLL] & 0x3) 1979 switch(context->regs[REG_SCROLL] & 0x3)
1980 { 1980 {
1995 hscroll_mask = 0x7F; 1995 hscroll_mask = 0x7F;
1996 v_mul = 256; 1996 v_mul = 256;
1997 break; 1997 break;
1998 } 1998 }
1999 uint16_t table_address; 1999 uint16_t table_address;
2000 switch(context->debug_modes[VDP_DEBUG_PLANE] % 3) 2000 switch(context->debug_modes[DEBUG_PLANE] % 3)
2001 { 2001 {
2002 case 0: 2002 case 0:
2003 table_address = context->regs[REG_SCROLL_A] << 10 & 0xE000; 2003 table_address = context->regs[REG_SCROLL_A] << 10 & 0xE000;
2004 break; 2004 break;
2005 case 1: 2005 case 1:
2065 address += y_diff; 2065 address += y_diff;
2066 dst += pitch / sizeof(uint32_t); 2066 dst += pitch / sizeof(uint32_t);
2067 } 2067 }
2068 } 2068 }
2069 } 2069 }
2070 render_framebuffer_updated(context->debug_fb_indices[VDP_DEBUG_PLANE], 1024); 2070 render_framebuffer_updated(context->debug_fb_indices[DEBUG_PLANE], 1024);
2071 } 2071 }
2072 2072
2073 if (context->enabled_debuggers & (1 << VDP_DEBUG_VRAM)) { 2073 if (context->enabled_debuggers & (1 << DEBUG_VRAM)) {
2074 uint32_t pitch; 2074 uint32_t pitch;
2075 uint32_t *fb = render_get_framebuffer(context->debug_fb_indices[VDP_DEBUG_VRAM], &pitch); 2075 uint32_t *fb = render_get_framebuffer(context->debug_fb_indices[DEBUG_VRAM], &pitch);
2076 2076
2077 uint8_t pal = (context->debug_modes[VDP_DEBUG_VRAM] % 4) << 4; 2077 uint8_t pal = (context->debug_modes[DEBUG_VRAM] % 4) << 4;
2078 for (int y = 0; y < 512; y++) 2078 for (int y = 0; y < 512; y++)
2079 { 2079 {
2080 uint32_t *line = fb + y * pitch / sizeof(uint32_t); 2080 uint32_t *line = fb + y * pitch / sizeof(uint32_t);
2081 int row = y >> 4; 2081 int row = y >> 4;
2082 int yoff = y >> 1 & 7; 2082 int yoff = y >> 1 & 7;
2094 *(line++) = context->colors[right]; 2094 *(line++) = context->colors[right];
2095 } 2095 }
2096 } 2096 }
2097 } 2097 }
2098 2098
2099 render_framebuffer_updated(context->debug_fb_indices[VDP_DEBUG_VRAM], 1024); 2099 render_framebuffer_updated(context->debug_fb_indices[DEBUG_VRAM], 1024);
2100 } 2100 }
2101 2101
2102 if (context->enabled_debuggers & (1 << VDP_DEBUG_CRAM)) { 2102 if (context->enabled_debuggers & (1 << DEBUG_CRAM)) {
2103 uint32_t starting_line = 512 - 32*4; 2103 uint32_t starting_line = 512 - 32*4;
2104 uint32_t *line = context->debug_fbs[VDP_DEBUG_CRAM] 2104 uint32_t *line = context->debug_fbs[DEBUG_CRAM]
2105 + context->debug_fb_pitch[VDP_DEBUG_CRAM] * starting_line / sizeof(uint32_t); 2105 + context->debug_fb_pitch[DEBUG_CRAM] * starting_line / sizeof(uint32_t);
2106 if (context->regs[REG_MODE_2] & BIT_MODE_5) { 2106 if (context->regs[REG_MODE_2] & BIT_MODE_5) {
2107 for (int pal = 0; pal < 4; pal ++) 2107 for (int pal = 0; pal < 4; pal ++)
2108 { 2108 {
2109 uint32_t *cur; 2109 uint32_t *cur;
2110 for (int y = 0; y < 31; y++) 2110 for (int y = 0; y < 31; y++)
2116 { 2116 {
2117 *(cur++) = context->colors[pal * 16 + offset]; 2117 *(cur++) = context->colors[pal * 16 + offset];
2118 } 2118 }
2119 *(cur++) = 0xFF000000; 2119 *(cur++) = 0xFF000000;
2120 } 2120 }
2121 line += context->debug_fb_pitch[VDP_DEBUG_CRAM] / sizeof(uint32_t); 2121 line += context->debug_fb_pitch[DEBUG_CRAM] / sizeof(uint32_t);
2122 } 2122 }
2123 cur = line; 2123 cur = line;
2124 for (int x = 0; x < 512; x++) 2124 for (int x = 0; x < 512; x++)
2125 { 2125 {
2126 *(cur++) = 0xFF000000; 2126 *(cur++) = 0xFF000000;
2127 } 2127 }
2128 line += context->debug_fb_pitch[VDP_DEBUG_CRAM] / sizeof(uint32_t); 2128 line += context->debug_fb_pitch[DEBUG_CRAM] / sizeof(uint32_t);
2129 } 2129 }
2130 } else { 2130 } else {
2131 for (int pal = 0; pal < 2; pal ++) 2131 for (int pal = 0; pal < 2; pal ++)
2132 { 2132 {
2133 uint32_t *cur; 2133 uint32_t *cur;
2140 { 2140 {
2141 *(cur++) = context->colors[pal * 16 + offset]; 2141 *(cur++) = context->colors[pal * 16 + offset];
2142 } 2142 }
2143 *(cur++) = 0xFF000000; 2143 *(cur++) = 0xFF000000;
2144 } 2144 }
2145 line += context->debug_fb_pitch[VDP_DEBUG_CRAM] / sizeof(uint32_t); 2145 line += context->debug_fb_pitch[DEBUG_CRAM] / sizeof(uint32_t);
2146 } 2146 }
2147 cur = line; 2147 cur = line;
2148 for (int x = 0; x < 512; x++) 2148 for (int x = 0; x < 512; x++)
2149 { 2149 {
2150 *(cur++) = 0xFF000000; 2150 *(cur++) = 0xFF000000;
2151 } 2151 }
2152 line += context->debug_fb_pitch[VDP_DEBUG_CRAM] / sizeof(uint32_t); 2152 line += context->debug_fb_pitch[DEBUG_CRAM] / sizeof(uint32_t);
2153 } 2153 }
2154 } 2154 }
2155 render_framebuffer_updated(context->debug_fb_indices[VDP_DEBUG_CRAM], 512); 2155 render_framebuffer_updated(context->debug_fb_indices[DEBUG_CRAM], 512);
2156 context->debug_fbs[VDP_DEBUG_CRAM] = render_get_framebuffer(context->debug_fb_indices[VDP_DEBUG_CRAM], &context->debug_fb_pitch[VDP_DEBUG_CRAM]); 2156 context->debug_fbs[DEBUG_CRAM] = render_get_framebuffer(context->debug_fb_indices[DEBUG_CRAM], &context->debug_fb_pitch[DEBUG_CRAM]);
2157 } 2157 }
2158 if (context->enabled_debuggers & (1 << VDP_DEBUG_COMPOSITE)) { 2158 if (context->enabled_debuggers & (1 << DEBUG_COMPOSITE)) {
2159 render_framebuffer_updated(context->debug_fb_indices[VDP_DEBUG_COMPOSITE], LINEBUF_SIZE); 2159 render_framebuffer_updated(context->debug_fb_indices[DEBUG_COMPOSITE], LINEBUF_SIZE);
2160 context->debug_fbs[VDP_DEBUG_COMPOSITE] = render_get_framebuffer(context->debug_fb_indices[VDP_DEBUG_COMPOSITE], &context->debug_fb_pitch[VDP_DEBUG_COMPOSITE]); 2160 context->debug_fbs[DEBUG_COMPOSITE] = render_get_framebuffer(context->debug_fb_indices[DEBUG_COMPOSITE], &context->debug_fb_pitch[DEBUG_COMPOSITE]);
2161 } 2161 }
2162 } 2162 }
2163 2163
2164 void vdp_force_update_framebuffer(vdp_context *context) 2164 void vdp_force_update_framebuffer(vdp_context *context)
2165 { 2165 {
4653 4653
4654 static vdp_context *current_vdp; 4654 static vdp_context *current_vdp;
4655 static void vdp_debug_window_close(uint8_t which) 4655 static void vdp_debug_window_close(uint8_t which)
4656 { 4656 {
4657 //TODO: remove need for current_vdp global, and find the VDP via current_system instead 4657 //TODO: remove need for current_vdp global, and find the VDP via current_system instead
4658 for (int i = 0; i < VDP_NUM_DEBUG_TYPES; i++) 4658 for (int i = 0; i < NUM_DEBUG_TYPES; i++)
4659 { 4659 {
4660 if (current_vdp->enabled_debuggers & (1 << i) && which == current_vdp->debug_fb_indices[i]) { 4660 if (current_vdp->enabled_debuggers & (1 << i) && which == current_vdp->debug_fb_indices[i]) {
4661 vdp_toggle_debug_view(current_vdp, i); 4661 vdp_toggle_debug_view(current_vdp, i);
4662 break; 4662 break;
4663 } 4663 }
4673 uint32_t width,height; 4673 uint32_t width,height;
4674 uint8_t fetch_immediately = 0; 4674 uint8_t fetch_immediately = 0;
4675 char *caption; 4675 char *caption;
4676 switch(debug_type) 4676 switch(debug_type)
4677 { 4677 {
4678 case VDP_DEBUG_PLANE: 4678 case DEBUG_PLANE:
4679 caption = "BlastEm - VDP Plane Debugger"; 4679 caption = "BlastEm - VDP Plane Debugger";
4680 width = height = 1024; 4680 width = height = 1024;
4681 break; 4681 break;
4682 case VDP_DEBUG_VRAM: 4682 case DEBUG_VRAM:
4683 caption = "BlastEm - VDP VRAM Debugger"; 4683 caption = "BlastEm - VDP VRAM Debugger";
4684 width = 1024; 4684 width = 1024;
4685 height = 512; 4685 height = 512;
4686 break; 4686 break;
4687 case VDP_DEBUG_CRAM: 4687 case DEBUG_CRAM:
4688 caption = "BlastEm - VDP CRAM Debugger"; 4688 caption = "BlastEm - VDP CRAM Debugger";
4689 width = 512; 4689 width = 512;
4690 height = 512; 4690 height = 512;
4691 fetch_immediately = 1; 4691 fetch_immediately = 1;
4692 break; 4692 break;
4693 case VDP_DEBUG_COMPOSITE: 4693 case DEBUG_COMPOSITE:
4694 caption = "BlastEm - VDP Plane Composition Debugger"; 4694 caption = "BlastEm - VDP Plane Composition Debugger";
4695 width = LINEBUF_SIZE; 4695 width = LINEBUF_SIZE;
4696 height = context->inactive_start + context->border_top + context->border_bot; 4696 height = context->inactive_start + context->border_top + context->border_bot;
4697 fetch_immediately = 1; 4697 fetch_immediately = 1;
4698 break; 4698 break;
4714 { 4714 {
4715 uint8_t active = render_get_active_framebuffer(); 4715 uint8_t active = render_get_active_framebuffer();
4716 if (active < FRAMEBUFFER_USER_START) { 4716 if (active < FRAMEBUFFER_USER_START) {
4717 return; 4717 return;
4718 } 4718 }
4719 for (int i = 0; i < VDP_NUM_DEBUG_TYPES; i++) 4719 for (int i = 0; i < NUM_DEBUG_TYPES; i++)
4720 { 4720 {
4721 if (context->enabled_debuggers & (1 << i) && context->debug_fb_indices[i] == active) { 4721 if (context->enabled_debuggers & (1 << i) && context->debug_fb_indices[i] == active) {
4722 context->debug_modes[i]++; 4722 context->debug_modes[i]++;
4723 return; 4723 return;
4724 } 4724 }