add vram tile viewer thing

This commit is contained in:
Matthew Laux 2022-07-14 02:11:20 -05:00
parent b1dca59463
commit bc3f717285
3 changed files with 45 additions and 5 deletions

View File

@ -50,6 +50,7 @@ GLuint make_output_texture() {
}
unsigned char output_image[256 * 256 * 4];
unsigned char vram_tiles[256 * 96 * 4];
void convert_output(struct lcd *lcd) {
int x, y;
@ -66,6 +67,33 @@ void convert_output(struct lcd *lcd) {
}
}
void convert_vram(struct dmg *dmg) {
int tile_y, tile_x;
int off, in;
for (tile_y = 0; tile_y < 12; tile_y++) {
for (tile_x = 0; tile_x < 32; tile_x++) {
off = 256 * 8 * tile_y + 8 * tile_x;
in = 16 * (tile_y * 32 + tile_x);
int b, i;
for (b = 0; b < 16; b += 2) {
int data1 = dmg->video_ram[in + b];
int data2 = dmg->video_ram[in + b + 1];
for (i = 7; i >= 0; i--) {
// monochrome for now
int fill = (data1 & (1 << i)) ? 255 : 0;
vram_tiles[4 * off + 0] = fill;
vram_tiles[4 * off + 1] = fill;
vram_tiles[4 * off + 2] = fill;
vram_tiles[4 * off + 3] = 255;
//dmg->lcd->buf[off] |= (data2 & (1 << i)) ? 1 : 0;
off++;
}
off += 248;
}
}
}
}
char full_address_space[0x10000];
void fill_memory_editor(struct dmg *dmg)
{
@ -165,6 +193,7 @@ int main(int argc, char *argv[])
// setup output
GLuint texture = make_output_texture();
GLuint vram_texture = make_output_texture();
// Our state
bool z_flag = false;
@ -247,6 +276,17 @@ int main(int argc, char *argv[])
ImGui::End();
}
{
ImGui::Begin("VRAM");
convert_vram(&dmg);
glBindTexture(GL_TEXTURE_2D, vram_texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 96, 0, GL_RGBA, GL_UNSIGNED_BYTE, vram_tiles);
ImGui::Image((void*)(intptr_t) vram_texture, ImVec2(256, 96));
ImGui::End();
}
fill_memory_editor(&dmg);
editor.DrawWindow("Memory", full_address_space, 0x10000, 0x0000);

View File

@ -136,12 +136,12 @@ static u8 rlc(struct cpu *cpu, u8 val)
static u8 rotate_right(struct cpu *regs, u8 reg)
{
// copy old rightmost bit to carry flag
int old_carry = flag_isset(regs, FLAG_CARRY) << 7;
// copy old rightmost bit to carry flag, clear ZNH
regs->f = (reg & 0x01) << 4;
// rotate
int result = reg >> 1;
// restore rightmost bit to left
result |= (regs->f & FLAG_CARRY) << 3;
int result = old_carry | reg >> 1;
if (!result) set_flag(regs, FLAG_ZERO);
return result;
}

View File

@ -92,7 +92,7 @@ void dmg_step(void *_dmg)
int use_unsigned = lcdc & LCDC_BG_TILE_DATA;
int tilebase = use_unsigned ? 0x8000 : 0x9000;
printf("bg_base %04x, tilebase %04x\n", bg_base, tilebase);
printf("tile map: %04x, tile data: %04x\n", bg_base, tilebase);
int k = 0, off = 0;
int tile_y = 0, tile_x = 0;