diff options
-rw-r--r-- | vdp.c | 81 |
1 files changed, 81 insertions, 0 deletions
@@ -462,6 +462,86 @@ void vdp_print_sprite_table(vdp_context * context) } } +static void redraw_debug_sprite(vdp_context *context, uint32_t *fb, uint32_t tile_id, uint8_t pal) +{ + // "tl" stands for tiles, "px" stands for pixels, "pt" stands for points, + // "b" stands for bytes. + const uint32_t pxppt = 2; // Pixels per point + const uint32_t ptptl = 8; // Points per tile + const uint32_t ptpb = 2; // Points per byte + const uint32_t win_width_tl = 64; + const uint32_t win_height_tl = 32; + const uint32_t win_width_pt = win_width_tl * ptptl; + const uint32_t win_height_pt = win_height_tl * ptptl; + const uint32_t win_width_px = win_width_pt * pxppt; + const uint32_t tile_width_b = 4; + const uint32_t tile_width_pt = ptptl; + const uint32_t tile_height_pt = ptptl; + const uint32_t tile_size_b = tile_width_b * tile_height_pt; + const uint32_t col_tl = tile_id % win_width_tl; + const uint32_t row_tl = tile_id / win_width_tl; + for (uint32_t r_pt = 0; r_pt < tile_height_pt; r_pt++) { + const uint32_t row_pt = row_tl * tile_height_pt + r_pt; + const uint32_t col_pt = col_tl * tile_width_pt; + for (uint32_t r_px = 0; r_px < pxppt; r_px++) { + const uint32_t row_px = row_pt * pxppt + r_px; + for (uint32_t b = 0; b < tile_width_b; b++) { + const uint32_t address = tile_id * tile_size_b + r_pt * tile_width_b + b; + const uint8_t byte = context->vdpmem[address]; + const uint8_t left = byte >> 4; + const uint8_t right = byte & 0xF; + const uint32_t line_offset = row_px * win_width_px + col_pt * pxppt + b * ptpb * pxppt; + fb[line_offset + 0] = context->colors[left | (pal * 16)]; + fb[line_offset + 1] = context->colors[left | (pal * 16)]; + fb[line_offset + 2] = context->colors[right | (pal * 16)]; + fb[line_offset + 3] = context->colors[right | (pal * 16)]; + } + } + } +} + +static void redraw_debug_sprites_with_correct_colors(vdp_context * context, uint32_t *fb) +{ + if (context->regs[REG_MODE_2] & BIT_MODE_5) { + uint16_t sat_address = mode5_sat_address(context); + uint16_t current_index = 0; + uint8_t count = 0; + do { + uint16_t address = current_index * 8 + sat_address; + uint16_t cache_address = current_index * 4; + uint8_t height = ((context->sat_cache[cache_address+2] & 0x3) + 1); + uint8_t width = (((context->sat_cache[cache_address+2] >> 2) & 0x3) + 1); + uint16_t link = context->sat_cache[cache_address+3] & 0x7F; + uint8_t pal = context->vdpmem[address + 4] >> 5 & 0x3; + uint16_t tile_id = ((context->vdpmem[address + 4] << 8) | context->vdpmem[address + 5]) & 0x7FF; + uint32_t count = height * width; + for (uint32_t i = 0; i < count; i++) { + if (tile_id + i < 2048) { + redraw_debug_sprite(context, fb, tile_id + i, pal); + } + } + current_index = link; + count++; + } while (current_index != 0 && count < 80); + } else { + uint16_t sat_address = (context->regs[REG_SAT] & 0x7E) << 7; + for (int i = 0; i < 64; i++) + { + uint8_t y = context->vdpmem[mode4_address_map[sat_address + (i ^ 1)]]; + if (y == 0xD0) { + break; + } + uint8_t x = context->vdpmem[mode4_address_map[sat_address + 0x80 + i*2 + 1]]; + uint16_t tile_address = context->vdpmem[mode4_address_map[sat_address + 0x80 + i*2]] * 32 + + (context->regs[REG_STILE_BASE] << 11 & 0x2000); + if (context->regs[REG_MODE_2] & BIT_SPRITE_SZ) { + tile_address &= ~32; + } + printf("Sprite %d: X=%d, Y=%d, Pat=%X\n", i, x, y, tile_address); + } + } +} + #define VRAM_READ 0 //0000 #define VRAM_WRITE 1 //0001 //2 would trigger register write 0010 @@ -2039,6 +2119,7 @@ static void vdp_update_per_frame_debug(vdp_context *context) } } + redraw_debug_sprites_with_correct_colors(context, fb); render_framebuffer_updated(context->debug_fb_indices[VDP_DEBUG_VRAM], 1024); } |