Mercurial > repos > blastem
comparison vdp.c @ 1641:bc9bb4e5856f
Basic version of layer compositing debug view in a separate window
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 19 Nov 2018 09:52:07 -0800 |
parents | 3602f3b20072 |
children | c6b2c0f8cc61 |
comparison
equal
deleted
inserted
replaced
1640:3602f3b20072 | 1641:bc9bb4e5856f |
---|---|
1265 } | 1265 } |
1266 | 1266 |
1267 static void render_map_output(uint32_t line, int32_t col, vdp_context * context) | 1267 static void render_map_output(uint32_t line, int32_t col, vdp_context * context) |
1268 { | 1268 { |
1269 uint32_t *dst; | 1269 uint32_t *dst; |
1270 uint8_t *debug_dst; | |
1270 uint8_t output_disabled = (context->test_port & TEST_BIT_DISABLE) != 0; | 1271 uint8_t output_disabled = (context->test_port & TEST_BIT_DISABLE) != 0; |
1271 uint8_t test_layer = context->test_port >> 7 & 3; | 1272 uint8_t test_layer = context->test_port >> 7 & 3; |
1272 if (context->state == PREPARING && !test_layer) { | 1273 if (context->state == PREPARING && !test_layer) { |
1273 if (col) { | 1274 if (col) { |
1274 col -= 2; | 1275 col -= 2; |
1297 int plane_a_off, plane_b_off; | 1298 int plane_a_off, plane_b_off; |
1298 if (col) | 1299 if (col) |
1299 { | 1300 { |
1300 col-=2; | 1301 col-=2; |
1301 dst = context->output + BORDER_LEFT + col * 8; | 1302 dst = context->output + BORDER_LEFT + col * 8; |
1303 debug_dst = context->layer_debug_buf + BORDER_LEFT + col * 8; | |
1304 | |
1302 if (context->debug < 2) { | 1305 if (context->debug < 2) { |
1303 sprite_buf = context->linebuf + col * 8; | 1306 sprite_buf = context->linebuf + col * 8; |
1304 uint8_t a_src, src; | 1307 uint8_t a_src, src; |
1305 if (context->flags & FLAG_WINDOW) { | 1308 if (context->flags & FLAG_WINDOW) { |
1306 plane_a_off = context->buf_a_off; | 1309 plane_a_off = context->buf_a_off; |
1378 if (output_disabled && pixel) { | 1381 if (output_disabled && pixel) { |
1379 src = DBG_SRC_B; | 1382 src = DBG_SRC_B; |
1380 } | 1383 } |
1381 break; | 1384 break; |
1382 } | 1385 } |
1383 | 1386 *(debug_dst++) = src; |
1384 uint32_t outpixel; | 1387 *(dst++) = colors[pixel & 0x3F]; |
1385 if (context->debug) { | |
1386 outpixel = context->debugcolors[src]; | |
1387 } else { | |
1388 outpixel = colors[pixel & 0x3F]; | |
1389 } | |
1390 *(dst++) = outpixel; | |
1391 } | 1388 } |
1392 } else { | 1389 } else { |
1393 for (int i = 0; i < 16; ++plane_a_off, ++plane_b_off, ++sprite_buf, ++i) { | 1390 for (int i = 0; i < 16; ++plane_a_off, ++plane_b_off, ++sprite_buf, ++i) { |
1394 plane_a = context->tmp_buf_a + (plane_a_off & SCROLL_BUFFER_MASK); | 1391 plane_a = context->tmp_buf_a + (plane_a_off & SCROLL_BUFFER_MASK); |
1395 plane_b = context->tmp_buf_b + (plane_b_off & SCROLL_BUFFER_MASK); | 1392 plane_b = context->tmp_buf_b + (plane_b_off & SCROLL_BUFFER_MASK); |
1433 if (output_disabled && pixel) { | 1430 if (output_disabled && pixel) { |
1434 src = DBG_SRC_B; | 1431 src = DBG_SRC_B; |
1435 } | 1432 } |
1436 break; | 1433 break; |
1437 } | 1434 } |
1438 uint32_t outpixel; | 1435 *(dst++) = context->colors[pixel & 0x3F]; |
1439 if (context->debug) { | 1436 *(debug_dst++) = src; |
1440 outpixel = context->debugcolors[src]; | |
1441 } else { | |
1442 outpixel = context->colors[pixel & 0x3F]; | |
1443 } | |
1444 *(dst++) = outpixel; | |
1445 } | 1437 } |
1446 } | 1438 } |
1447 } else if (context->debug == 2) { | 1439 } else if (context->debug == 2) { |
1448 if (col < 32) { | 1440 if (col < 32) { |
1449 *(dst++) = context->colors[col * 2]; | 1441 *(dst++) = context->colors[col * 2]; |
1488 address++; | 1480 address++; |
1489 } | 1481 } |
1490 } | 1482 } |
1491 } else { | 1483 } else { |
1492 dst = context->output; | 1484 dst = context->output; |
1485 debug_dst = context->layer_debug_buf; | |
1493 uint8_t pixel = context->regs[REG_BG_COLOR] & 0x3F; | 1486 uint8_t pixel = context->regs[REG_BG_COLOR] & 0x3F; |
1494 if (output_disabled) { | 1487 if (output_disabled) { |
1495 pixel = 0x3F; | 1488 pixel = 0x3F; |
1496 } | 1489 } |
1497 uint32_t bg_color = context->colors[pixel]; | 1490 uint32_t bg_color = context->colors[pixel]; |
1498 if (test_layer) { | 1491 if (test_layer) { |
1499 switch(test_layer) | 1492 switch(test_layer) |
1500 { | 1493 { |
1501 case 1: | 1494 case 1: |
1502 bg_color = context->colors[0]; | 1495 bg_color = context->colors[0]; |
1503 for (int i = 0; i < BORDER_LEFT; i++, dst++) | 1496 for (int i = 0; i < BORDER_LEFT; i++, dst++, debug_dst++) |
1504 { | 1497 { |
1505 *dst = bg_color; | 1498 *dst = bg_color; |
1499 *debug_dst = DBG_SRC_BG; | |
1500 | |
1506 } | 1501 } |
1507 break; | 1502 break; |
1508 case 2: { | 1503 case 2: { |
1509 //plane A | 1504 //plane A |
1510 //TODO: Deal with Window layer | 1505 //TODO: Deal with Window layer |
1511 int i; | 1506 int i; |
1512 i = 0; | 1507 i = 0; |
1513 uint8_t buf_off = context->buf_a_off - (context->hscroll_a & 0xF) + (16 - BORDER_LEFT); | 1508 uint8_t buf_off = context->buf_a_off - (context->hscroll_a & 0xF) + (16 - BORDER_LEFT); |
1514 //uint8_t *src = context->tmp_buf_a + ((context->buf_a_off + (i ? 0 : (16 - BORDER_LEFT) - (context->hscroll_a & 0xF))) & SCROLL_BUFFER_MASK); | 1509 //uint8_t *src = context->tmp_buf_a + ((context->buf_a_off + (i ? 0 : (16 - BORDER_LEFT) - (context->hscroll_a & 0xF))) & SCROLL_BUFFER_MASK); |
1515 for (; i < BORDER_LEFT; buf_off++, i++, dst++) | 1510 for (; i < BORDER_LEFT; buf_off++, i++, dst++, debug_dst++) |
1516 { | 1511 { |
1517 *dst = context->colors[context->tmp_buf_a[buf_off & SCROLL_BUFFER_MASK]]; | 1512 *dst = context->colors[context->tmp_buf_a[buf_off & SCROLL_BUFFER_MASK]]; |
1513 *debug_dst = DBG_SRC_A; | |
1518 } | 1514 } |
1519 break; | 1515 break; |
1520 } | 1516 } |
1521 case 3: { | 1517 case 3: { |
1522 //plane B | 1518 //plane B |
1523 int i; | 1519 int i; |
1524 i = 0; | 1520 i = 0; |
1525 uint8_t buf_off = context->buf_b_off - (context->hscroll_b & 0xF) + (16 - BORDER_LEFT); | 1521 uint8_t buf_off = context->buf_b_off - (context->hscroll_b & 0xF) + (16 - BORDER_LEFT); |
1526 //uint8_t *src = context->tmp_buf_b + ((context->buf_b_off + (i ? 0 : (16 - BORDER_LEFT) - (context->hscroll_b & 0xF))) & SCROLL_BUFFER_MASK); | 1522 //uint8_t *src = context->tmp_buf_b + ((context->buf_b_off + (i ? 0 : (16 - BORDER_LEFT) - (context->hscroll_b & 0xF))) & SCROLL_BUFFER_MASK); |
1527 for (; i < BORDER_LEFT; buf_off++, i++, dst++) | 1523 for (; i < BORDER_LEFT; buf_off++, i++, dst++, debug_dst++) |
1528 { | 1524 { |
1529 *dst = context->colors[context->tmp_buf_b[buf_off & SCROLL_BUFFER_MASK]]; | 1525 *dst = context->colors[context->tmp_buf_b[buf_off & SCROLL_BUFFER_MASK]]; |
1526 *debug_dst = DBG_SRC_B; | |
1530 } | 1527 } |
1531 break; | 1528 break; |
1532 } | 1529 } |
1533 } | 1530 } |
1534 } else { | 1531 } else { |
1535 for (int i = 0; i < BORDER_LEFT; i++, dst++) | 1532 for (int i = 0; i < BORDER_LEFT; i++, dst++, debug_dst++) |
1536 { | 1533 { |
1537 *dst = bg_color; | 1534 *dst = bg_color; |
1535 *debug_dst = DBG_SRC_BG; | |
1538 } | 1536 } |
1539 } | 1537 } |
1540 } | 1538 } |
1541 context->done_output = dst; | 1539 context->done_output = dst; |
1542 context->buf_a_off = (context->buf_a_off + SCROLL_BUFFER_DRAW) & SCROLL_BUFFER_MASK; | 1540 context->buf_a_off = (context->buf_a_off + SCROLL_BUFFER_DRAW) & SCROLL_BUFFER_MASK; |
1692 } else { | 1690 } else { |
1693 jump_start = 0xDB; | 1691 jump_start = 0xDB; |
1694 jump_end = 0x1D5; | 1692 jump_end = 0x1D5; |
1695 } | 1693 } |
1696 | 1694 |
1697 if (context->enabled_debuggers & (1 << VDP_DEBUG_CRAM)) { | 1695 if (context->enabled_debuggers & (1 << VDP_DEBUG_CRAM | 1 << VDP_DEBUG_COMPOSITE)) { |
1698 uint32_t line = context->vcounter; | 1696 uint32_t line = context->vcounter; |
1699 if (line >= jump_end) { | 1697 if (line >= jump_end) { |
1700 line -= jump_end - jump_start; | 1698 line -= jump_end - jump_start; |
1701 } | 1699 } |
1702 uint32_t total_lines = (context->flags2 & FLAG2_REGION_PAL) ? 313 : 262; | 1700 uint32_t total_lines = (context->flags2 & FLAG2_REGION_PAL) ? 313 : 262; |
1704 if (total_lines - line <= context->border_top) { | 1702 if (total_lines - line <= context->border_top) { |
1705 line -= total_lines - context->border_top; | 1703 line -= total_lines - context->border_top; |
1706 } else { | 1704 } else { |
1707 line += context->border_top; | 1705 line += context->border_top; |
1708 } | 1706 } |
1709 uint32_t *fb = context->debug_fbs[VDP_DEBUG_CRAM] + context->debug_fb_pitch[VDP_DEBUG_CRAM] * line / sizeof(uint32_t); | 1707 if (context->enabled_debuggers & (1 << VDP_DEBUG_CRAM)) { |
1710 for (int i = 0; i < 64; i++) | 1708 uint32_t *fb = context->debug_fbs[VDP_DEBUG_CRAM] + context->debug_fb_pitch[VDP_DEBUG_CRAM] * line / sizeof(uint32_t); |
1711 { | 1709 for (int i = 0; i < 64; i++) |
1712 for (int x = 0; x < 8; x++) | |
1713 { | 1710 { |
1714 *(fb++) = context->colors[i]; | 1711 for (int x = 0; x < 8; x++) |
1715 } | 1712 { |
1716 } | 1713 *(fb++) = context->colors[i]; |
1717 } | 1714 } |
1715 } | |
1716 } | |
1717 if ( | |
1718 context->enabled_debuggers & (1 << VDP_DEBUG_COMPOSITE) | |
1719 && line < (context->inactive_start + context->border_bot + context->border_top) | |
1720 ) { | |
1721 uint32_t *fb = context->debug_fbs[VDP_DEBUG_COMPOSITE] + context->debug_fb_pitch[VDP_DEBUG_COMPOSITE] * line / sizeof(uint32_t); | |
1722 for (int i = 0; i < LINEBUF_SIZE; i++) | |
1723 { | |
1724 *(fb++) = context->debugcolors[context->layer_debug_buf[i]]; | |
1725 } | |
1726 } | |
1727 } | |
1728 | |
1718 context->vcounter++; | 1729 context->vcounter++; |
1719 if (context->vcounter == jump_start) { | 1730 if (context->vcounter == jump_start) { |
1720 context->vcounter = jump_end; | 1731 context->vcounter = jump_end; |
1721 } else { | 1732 } else { |
1722 context->vcounter &= 0x1FF; | 1733 context->vcounter &= 0x1FF; |
1898 line += context->debug_fb_pitch[VDP_DEBUG_CRAM] / sizeof(uint32_t); | 1909 line += context->debug_fb_pitch[VDP_DEBUG_CRAM] / sizeof(uint32_t); |
1899 } | 1910 } |
1900 render_framebuffer_updated(context->debug_fb_indices[VDP_DEBUG_CRAM], 512); | 1911 render_framebuffer_updated(context->debug_fb_indices[VDP_DEBUG_CRAM], 512); |
1901 context->debug_fbs[VDP_DEBUG_CRAM] = render_get_framebuffer(context->debug_fb_indices[VDP_DEBUG_CRAM], &context->debug_fb_pitch[VDP_DEBUG_CRAM]); | 1912 context->debug_fbs[VDP_DEBUG_CRAM] = render_get_framebuffer(context->debug_fb_indices[VDP_DEBUG_CRAM], &context->debug_fb_pitch[VDP_DEBUG_CRAM]); |
1902 } | 1913 } |
1914 if (context->enabled_debuggers & (1 << VDP_DEBUG_COMPOSITE)) { | |
1915 render_framebuffer_updated(context->debug_fb_indices[VDP_DEBUG_COMPOSITE], LINEBUF_SIZE); | |
1916 context->debug_fbs[VDP_DEBUG_COMPOSITE] = render_get_framebuffer(context->debug_fb_indices[VDP_DEBUG_COMPOSITE], &context->debug_fb_pitch[VDP_DEBUG_COMPOSITE]); | |
1917 } | |
1903 } | 1918 } |
1904 | 1919 |
1905 void vdp_force_update_framebuffer(vdp_context *context) | 1920 void vdp_force_update_framebuffer(vdp_context *context) |
1906 { | 1921 { |
1907 uint16_t lines_max = (context->flags2 & FLAG2_REGION_PAL) | 1922 uint16_t lines_max = (context->flags2 & FLAG2_REGION_PAL) |
3948 caption = "BlastEm - VDP CRAM Debugger"; | 3963 caption = "BlastEm - VDP CRAM Debugger"; |
3949 width = 512; | 3964 width = 512; |
3950 height = 512; | 3965 height = 512; |
3951 fetch_immediately = 1; | 3966 fetch_immediately = 1; |
3952 break; | 3967 break; |
3968 case VDP_DEBUG_COMPOSITE: | |
3969 caption = "BlastEm - VDP Plane Composition Debugger"; | |
3970 width = LINEBUF_SIZE; | |
3971 height = context->inactive_start + context->border_top + context->border_bot; | |
3972 fetch_immediately = 1; | |
3973 break; | |
3953 default: | 3974 default: |
3954 return; | 3975 return; |
3955 } | 3976 } |
3956 context->debug_fb_indices[debug_type] = render_create_window(caption, width, height); | 3977 context->debug_fb_indices[debug_type] = render_create_window(caption, width, height); |
3957 if (context->debug_fb_indices[debug_type]) { | 3978 if (context->debug_fb_indices[debug_type]) { |