From 9b1e6047d086762305d86eb9943e8c998404dab9 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Sun, 19 Jan 2025 08:32:52 +0100 Subject: [PATCH] - [NEW] conectat el mem::reset - [NEW] Break on unknown opcode - [FIX] Solventats mil bugs de pintat del background --- Makefile | 3 +++ gbscreen.cpp | 40 +++++++++++++++++++++++----------------- mbc_none.cpp | 26 ++++++++++++++++---------- mem.cpp | 5 ----- mem.h | 2 +- sm83.cpp | 7 +++++-- 6 files changed, 48 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index 5d09430..7f9febf 100644 --- a/Makefile +++ b/Makefile @@ -5,4 +5,7 @@ run: compile ./gb debug: compile + gdb --args gb tetris.gb + +debug1: compile gdb -ex run gb diff --git a/gbscreen.cpp b/gbscreen.cpp index 317208f..0679165 100644 --- a/gbscreen.cpp +++ b/gbscreen.cpp @@ -10,6 +10,7 @@ namespace gbscreen { uint32_t palette[4] = { + //0xFFFFFF, 0xFF0000, 0x00FF00, 0x0000FF 0xFFFFFF, 0xAAAAAA, 0x555555, 0x000000 }; SDL_Window *win = nullptr; @@ -21,13 +22,13 @@ namespace gbscreen uint32_t t_states_per_scanline = 456; uint32_t vsync_lines = 10; - uint8_t zoom = 1; + uint8_t zoom = 2; bool fullscreen = false; bool full_refresh = true; int fullscreen_scale = 1; SDL_Rect dest_rect; - uint32_t time=0; + //uint32_t time=0; uint32_t t_screen = 0; @@ -136,33 +137,34 @@ namespace gbscreen const uint8_t LCDC = mem::readMem(0xff40); const uint8_t SCY = mem::readMem(0xff42); const uint8_t SCX = mem::readMem(0xff43); - const uint8_t ty = uint8_t(SCY+LY) >> 3; + const uint16_t ty = uint8_t(SCY+LY) >> 3; const uint8_t ly = uint8_t(SCY+LY) & 0x7; - uint8_t tx = SCX >> 3; + uint16_t tx = SCX >> 3; uint8_t ox = SCX & 0x7; - uint16_t tilemap_address = LCDC&0x8 ? 0x9c00 : 0x9800; - tilemap_address += tx + (ty<<5); - uint8_t tile = mem::readMem(tilemap_address); - uint16_t tile_address = 0x8000; - if ( ((LCDC&0x10)==0) && (tile<128) ) tile_address = 0x9000; - tile_address = tile_address + (tile<<8); + uint16_t base_tilemap_address = LCDC&0x8 ? 0x9c00 : 0x9800; int pi = 0; while(true) { - uint8_t a = mem::readMem(tile_address++); - uint8_t b = mem::readMem(tile_address++); + uint16_t tilemap_address = base_tilemap_address + tx + (ty<<5); + uint16_t tile = mem::readMem(tilemap_address); + uint16_t base_tile_address = 0x8000; + if ( ((LCDC&0x10)==0) && (tile<128) ) base_tile_address = 0x9000; + uint16_t tile_address = base_tile_address + (tile<<4) + (ly*2); + + uint8_t a = mem::readMem(tile_address); + uint8_t b = mem::readMem(tile_address+1); for (int i=0; i<8; ++i) { if (ox==0) { - line_buffer[pi++] = (a&0x10 ? 1 : 0) + (b&0x10 ? 2 : 0 ); + line_buffer[pi++] = (a&0x80 ? 1 : 0) + (b&0x80 ? 2 : 0 ); } else { ox--; } - a<<1; b<<1; + a=a<<1; b=b<<1; if (pi==160) return; } + tx = (tx+1)&0x1f; } - } void refresh(const uint32_t dt, const bool full) @@ -176,8 +178,12 @@ namespace gbscreen for (int i=0;i