comparison vdp.c @ 1638:f27142c48567

Initial stab at CRAM debug in a detached window
author Michael Pavone <pavone@retrodev.com>
date Wed, 14 Nov 2018 22:16:35 -0800
parents 95880d947257
children 93518786f882
comparison
equal deleted inserted replaced
1637:95880d947257 1638:f27142c48567
1674 printf("Line %d took %d cycles\n", context->vcounter, diff); 1674 printf("Line %d took %d cycles\n", context->vcounter, diff);
1675 } 1675 }
1676 } 1676 }
1677 last_line = context->cycles; 1677 last_line = context->cycles;
1678 #endif 1678 #endif
1679 context->vcounter++; 1679 uint16_t jump_start, jump_end;
1680
1681 uint8_t is_mode_5 = context->regs[REG_MODE_2] & BIT_MODE_5; 1680 uint8_t is_mode_5 = context->regs[REG_MODE_2] & BIT_MODE_5;
1682 if (is_mode_5) { 1681 if (is_mode_5) {
1683 if (context->flags2 & FLAG2_REGION_PAL) { 1682 if (context->flags2 & FLAG2_REGION_PAL) {
1684 if (context->regs[REG_MODE_2] & BIT_PAL) { 1683 if (context->regs[REG_MODE_2] & BIT_PAL) {
1685 if (context->vcounter == 0x10B) { 1684 jump_start = 0x10B;
1686 context->vcounter = 0x1D2; 1685 jump_end = 0x1D2;
1687 } 1686 } else {
1688 } else if (context->vcounter == 0x103){ 1687 jump_start = 0x103;
1689 context->vcounter = 0x1CA; 1688 jump_end = 0x1CA;
1690 } 1689 }
1691 } else { 1690 } else if (context->regs[REG_MODE_2] & BIT_PAL) {
1692 if (context->regs[REG_MODE_2] & BIT_PAL) { 1691 jump_start = 0x100;
1693 if (context->vcounter == 0x100) { 1692 jump_end = 0x1FA;
1694 context->vcounter = 0x1FA; 1693 } else {
1695 } 1694 jump_start = 0xEB;
1696 } else if (context->vcounter == 0xEB) { 1695 jump_end = 0x1E5;
1697 context->vcounter = 0x1E5; 1696 }
1698 } 1697 } else {
1699 } 1698 jump_start = 0xDB;
1700 } else if (context->vcounter == 0xDB) { 1699 jump_end = 0x1D5;
1701 context->vcounter = 0x1D5; 1700 }
1702 } 1701
1703 context->vcounter &= 0x1FF; 1702 if (context->enabled_debuggers & (1 << VDP_DEBUG_CRAM)) {
1703 uint32_t line = context->vcounter;
1704 if (line >= jump_end) {
1705 line -= jump_end - jump_start;
1706 }
1707 uint32_t total_lines = (context->flags2 & FLAG2_REGION_PAL) ? 313 : 262;
1708
1709 if (total_lines - line <= context->border_top) {
1710 line -= total_lines - context->border_top;
1711 } else {
1712 line += context->border_top;
1713 }
1714 uint32_t *fb = context->debug_fbs[VDP_DEBUG_CRAM] + context->debug_fb_pitch[VDP_DEBUG_CRAM] * line / sizeof(uint32_t);
1715 for (int i = 0; i < 64; i++)
1716 {
1717 for (int x = 0; x < 8; x++)
1718 {
1719 *(fb++) = context->colors[i];
1720 }
1721 }
1722 }
1723 context->vcounter++;
1724 if (context->vcounter == jump_start) {
1725 context->vcounter = jump_end;
1726 } else {
1727 context->vcounter &= 0x1FF;
1728 }
1704 if (context->state == PREPARING) { 1729 if (context->state == PREPARING) {
1705 context->state = ACTIVE; 1730 context->state = ACTIVE;
1706 } 1731 }
1707 if (context->vcounter == 0x1FF) { 1732 if (context->vcounter == 0x1FF) {
1708 context->flags2 &= ~FLAG2_PAUSE; 1733 context->flags2 &= ~FLAG2_PAUSE;
1846 } 1871 }
1847 } 1872 }
1848 } 1873 }
1849 1874
1850 render_framebuffer_updated(context->debug_fb_indices[VDP_DEBUG_VRAM], 1024); 1875 render_framebuffer_updated(context->debug_fb_indices[VDP_DEBUG_VRAM], 1024);
1876 }
1877
1878 if (context->enabled_debuggers & (1 << VDP_DEBUG_CRAM)) {
1879 uint32_t starting_line = 512 - 32*4;
1880 uint32_t *line = context->debug_fbs[VDP_DEBUG_CRAM]
1881 + context->debug_fb_pitch[VDP_DEBUG_CRAM] * starting_line / sizeof(uint32_t);
1882 for (int pal = 0; pal < 4; pal ++)
1883 {
1884 uint32_t *cur;
1885 for (int y = 0; y < 31; y++)
1886 {
1887 cur = line;
1888 for (int offset = 0; offset < 16; offset++)
1889 {
1890 for (int x = 0; x < 31; x++)
1891 {
1892 *(cur++) = context->colors[pal * 16 + offset];
1893 }
1894 *(cur++) = 0xFF000000;
1895 }
1896 line += context->debug_fb_pitch[VDP_DEBUG_CRAM] / sizeof(uint32_t);
1897 }
1898 cur = line;
1899 for (int x = 0; x < 512; x++)
1900 {
1901 *(cur++) = 0xFF000000;
1902 }
1903 line += context->debug_fb_pitch[VDP_DEBUG_CRAM] / sizeof(uint32_t);
1904 }
1905 render_framebuffer_updated(context->debug_fb_indices[VDP_DEBUG_CRAM], 512);
1906 context->debug_fbs[VDP_DEBUG_CRAM] = render_get_framebuffer(context->debug_fb_indices[VDP_DEBUG_CRAM], &context->debug_fb_pitch[VDP_DEBUG_CRAM]);
1851 } 1907 }
1852 } 1908 }
1853 1909
1854 void vdp_force_update_framebuffer(vdp_context *context) 1910 void vdp_force_update_framebuffer(vdp_context *context)
1855 { 1911 {
3878 { 3934 {
3879 if (context->enabled_debuggers & 1 << debug_type) { 3935 if (context->enabled_debuggers & 1 << debug_type) {
3880 //TODO: implement me 3936 //TODO: implement me
3881 } else { 3937 } else {
3882 uint32_t width,height; 3938 uint32_t width,height;
3939 uint8_t fetch_immediately = 0;
3883 char *caption; 3940 char *caption;
3884 switch(debug_type) 3941 switch(debug_type)
3885 { 3942 {
3886 case VDP_DEBUG_PLANE: 3943 case VDP_DEBUG_PLANE:
3887 caption = "BlastEm - VDP Plane Debugger"; 3944 caption = "BlastEm - VDP Plane Debugger";
3890 case VDP_DEBUG_VRAM: 3947 case VDP_DEBUG_VRAM:
3891 caption = "BlastEm - VDP VRAM Debugger"; 3948 caption = "BlastEm - VDP VRAM Debugger";
3892 width = 1024; 3949 width = 1024;
3893 height = 512; 3950 height = 512;
3894 break; 3951 break;
3952 case VDP_DEBUG_CRAM:
3953 caption = "BlastEm - VDP CRAM Debugger";
3954 width = 512;
3955 height = 512;
3956 fetch_immediately = 1;
3957 break;
3895 default: 3958 default:
3896 return; 3959 return;
3897 } 3960 }
3898 context->debug_fb_indices[debug_type] = render_create_window(caption, width, height); 3961 context->debug_fb_indices[debug_type] = render_create_window(caption, width, height);
3899 if (context->debug_fb_indices[debug_type]) { 3962 if (context->debug_fb_indices[debug_type]) {
3900 context->enabled_debuggers |= 1 << debug_type; 3963 context->enabled_debuggers |= 1 << debug_type;
3964 }
3965 if (fetch_immediately) {
3966 context->debug_fbs[debug_type] = render_get_framebuffer(context->debug_fb_indices[debug_type], &context->debug_fb_pitch[debug_type]);
3901 } 3967 }
3902 } 3968 }
3903 } 3969 }
3904 3970
3905 void vdp_inc_debug_mode(vdp_context *context) 3971 void vdp_inc_debug_mode(vdp_context *context)