diff --git a/cli/imgui_example.cpp b/cli/imgui_example.cpp index 1cb86e6..1ba310d 100644 --- a/cli/imgui_example.cpp +++ b/cli/imgui_example.cpp @@ -48,14 +48,14 @@ GLuint make_output_texture() { return image_texture; } -unsigned char output_image[160 * 144 * 4]; +unsigned char output_image[256 * 256 * 4]; void convert_output(struct lcd *lcd) { int x, y; int out_index = 0; - for (y = 0; y < 144; y++) { - for (x = 0; x < 160; x++) { - int val = lcd->pixels[y * 160 + x]; + for (y = 0; y < 256; y++) { + for (x = 0; x < 256; x++) { + int val = lcd->buf[y * 256 + x]; int fill = val ? 255 : 0; output_image[out_index++] = val; output_image[out_index++] = val; @@ -77,10 +77,10 @@ void fill_memory_editor(struct dmg *dmg) // Main code int main(int argc, char *argv[]) { - struct cpu cpu; - struct rom rom; - struct dmg dmg; - struct lcd lcd; + struct cpu cpu = { 0 }; + struct rom rom = { 0 }; + struct dmg dmg = { 0 }; + struct lcd lcd = { 0 }; int executed; @@ -237,8 +237,8 @@ int main(int argc, char *argv[]) convert_output(dmg.lcd); glBindTexture(GL_TEXTURE_2D, texture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 160, 144, 0, GL_RGBA, GL_UNSIGNED_BYTE, output_image); - ImGui::Image((void*)(intptr_t) texture, ImVec2(160, 144)); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, output_image); + ImGui::Image((void*)(intptr_t) texture, ImVec2(256, 256)); ImGui::End(); } @@ -246,6 +246,7 @@ int main(int argc, char *argv[]) fill_memory_editor(&dmg); editor.DrawWindow("Memory", full_address_space, 0x10000, 0x0000); + editor.DrawWindow("LCD", dmg.lcd->buf, 0x2000, 0); // Rendering ImGui::Render(); diff --git a/src/dmg.c b/src/dmg.c index 8c64701..985c733 100644 --- a/src/dmg.c +++ b/src/dmg.c @@ -1,4 +1,5 @@ #include +#include #include "cpu.h" #include "rom.h" @@ -82,6 +83,36 @@ void dmg_step(void *_dmg) if (next_scanline == 144) { // vblank has started, draw all the stuff from ram into the lcd + int lcdc = lcd_read(dmg->lcd, REG_LCDC); + int bg_base = (lcdc & LCDC_BG_TILE_MAP) ? 0x9c00 : 0x9800; + int window_base = (lcdc & LCDC_WINDOW_TILE_MAP) ? 0x9c00 : 0x9800; + int use_unsigned = lcdc & LCDC_BG_TILE_DATA; + int tilebase = use_unsigned ? 0x8000 : 0x9000; + + printf("base is %04x\n", bg_base); + + int k, off = 0; + for (k = 0; k < 1024; k++) { + int tile = dmg_read(dmg, bg_base + k); + int eff_addr; + if (use_unsigned) { + eff_addr = tilebase + 16 * tile; + } else { + eff_addr = tilebase + 16 * (signed char) tile; + } + int b, i; + for (b = 0; b < 16; b += 2) { + int data1 = dmg_read(dmg, eff_addr + b); + int data2 = dmg_read(dmg, eff_addr + b + 1); + for (i = 0; i < 8; i++) { + // monochrome for now + dmg->lcd->buf[off] |= (data1 & (1 << i)) ? 1 : 0; + dmg->lcd->buf[off] |= (data2 & (1 << i)) ? 1 : 0; + off++; + } + } + } + // now copy 256x256 buf to 160x144 based on window registers lcd_copy(dmg->lcd); lcd_draw(dmg->lcd); diff --git a/src/lcd.c b/src/lcd.c index 5ec0f53..85f8afe 100644 --- a/src/lcd.c +++ b/src/lcd.c @@ -59,7 +59,7 @@ void lcd_put_pixel(struct lcd *lcd, u8 x, u8 y, u8 value) void lcd_copy(struct lcd *lcd) { // use all the registers to compute the pixel data - + } int lcd_step(struct lcd *lcd)