- [NEW] conectat el mem::reset

- [NEW] Break on unknown opcode
- [FIX] Solventats mil bugs de pintat del background
This commit is contained in:
2025-01-19 08:32:52 +01:00
parent 7272414f29
commit 9b1e6047d0
6 changed files with 48 additions and 35 deletions

View File

@@ -5,4 +5,7 @@ run: compile
./gb
debug: compile
gdb --args gb tetris.gb
debug1: compile
gdb -ex run gb

View File

@@ -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<dt;++i)
{
// Açò va volcant els pixels del line_buffer en pantalla
uint16_t current_pixel = dots_in_scanline-80;
if (current_pixel<160) *(ptr_pixel++) = line_buffer[current_pixel];
if ( (STAT&0x3)==3) {
uint16_t current_pixel = dots_in_scanline-80;
if (current_pixel<160) {
*(ptr_pixel++) = line_buffer[current_pixel];
}
}
// gestió de en quin dot i linea estem, i tot el que ha de passar
bool stat_interrupt = false;

View File

@@ -70,17 +70,8 @@ namespace mbc_none
}
void init(uint8_t *rom, uint32_t rom_size, uint32_t ram_size)
void reset()
{
mem::readMem = mbc_none::readMem;
mem::writeMem = mbc_none::writeMem;
mem::getTag = mbc_none::getTag;
mem::setTag = mbc_none::setTag;
mem::saveState = mbc_none::saveState;
mem::loadState = mbc_none::loadState;
mbc_none::rom = rom;
FILE *f = fopen("dmg_boot.bin", "rb");
if (!f) { printf("ABORTING: 'dmg_boot.bin' not found!\n"); exit(1); }
fseek(f, 0, SEEK_END);
@@ -95,4 +86,19 @@ namespace mbc_none
for (int i=0; i<512; ++i) { hram[i] = 0; }
for (int i=0; i<65536; ++i) { tags[i] = MEMTAG_NONE; }
}
void init(uint8_t *rom, uint32_t rom_size, uint32_t ram_size)
{
mem::readMem = mbc_none::readMem;
mem::writeMem = mbc_none::writeMem;
mem::getTag = mbc_none::getTag;
mem::setTag = mbc_none::setTag;
mem::saveState = mbc_none::saveState;
mem::loadState = mbc_none::loadState;
mem::reset = mbc_none::reset;
mbc_none::rom = rom;
reset();
}
}

View File

@@ -32,9 +32,4 @@ namespace mem
};
}
void reset()
{
}
}

2
mem.h
View File

@@ -25,7 +25,7 @@ namespace mem
#define MBC7 7
void init(uint8_t* rom, const int size);
void reset();
extern void (*reset)(void);
extern uint8_t(*readMem)(uint16_t);
extern void (*writeMem)(uint16_t, uint8_t);

View File

@@ -680,9 +680,12 @@ namespace sm83
bool opcode_ignored = false;
void IgnoreOpcode()
{
t-=3;
debug::setcursor(rPC);
debug::history::store();
debug::stop();
/*t-=3;
rPC--;
opcode_ignored=true;
opcode_ignored=true;*/
}
void reset()