all repos — mgba @ e019c54aad2e28e7035868bb9e0f14a1b9369e2c

mGBA Game Boy Advance Emulator

GB: Improve initialization
Jeffrey Pfau jeffrey@endrift.com
Sun, 17 Jan 2016 00:52:01 -0800
commit

e019c54aad2e28e7035868bb9e0f14a1b9369e2c

parent

31b509e0333e27aedd9cafe0e0447ddc389d9dd1

3 files changed, 49 insertions(+), 2 deletions(-)

jump to
M src/gb/gb.csrc/gb/gb.c

@@ -37,6 +37,8 @@ gb->cpu = cpu;

GBInterruptHandlerInit(&cpu->irqh); GBMemoryInit(gb); + + gb->video.p = gb; GBVideoInit(&gb->video); gb->romVf = 0;

@@ -123,9 +125,8 @@ gb->memory.romSize = gb->yankedRomSize;

gb->yankedRomSize = 0; } GBMemoryReset(gb); - - gb->video.p = gb; GBVideoReset(&gb->video); + GBIOReset(gb); } void GBUpdateIRQs(struct GB* gb) {
M src/gb/io.csrc/gb/io.c

@@ -11,6 +11,43 @@ void GBIOInit(struct GB* gb) {

memset(gb->memory.io, 0, sizeof(gb->memory.io)); } +void GBIOReset(struct GB* gb) { + memset(gb->memory.io, 0, sizeof(gb->memory.io)); + + GBIOWrite(gb, 0x05, 0); + GBIOWrite(gb, 0x06, 0); + GBIOWrite(gb, 0x07, 0); + GBIOWrite(gb, 0x10, 0x80); + GBIOWrite(gb, 0x11, 0xBF); + GBIOWrite(gb, 0x12, 0xF3); + GBIOWrite(gb, 0x12, 0xF3); + GBIOWrite(gb, 0x14, 0xBF); + GBIOWrite(gb, 0x16, 0x3F); + GBIOWrite(gb, 0x17, 0x00); + GBIOWrite(gb, 0x19, 0xBF); + GBIOWrite(gb, 0x1A, 0x7F); + GBIOWrite(gb, 0x1B, 0xFF); + GBIOWrite(gb, 0x1C, 0x9F); + GBIOWrite(gb, 0x1E, 0xBF); + GBIOWrite(gb, 0x20, 0xFF); + GBIOWrite(gb, 0x21, 0x00); + GBIOWrite(gb, 0x22, 0x00); + GBIOWrite(gb, 0x23, 0xBF); + GBIOWrite(gb, 0x24, 0x77); + GBIOWrite(gb, 0x25, 0xF3); + GBIOWrite(gb, 0x26, 0xF1); + GBIOWrite(gb, 0x40, 0x91); + GBIOWrite(gb, 0x42, 0x00); + GBIOWrite(gb, 0x43, 0x00); + GBIOWrite(gb, 0x45, 0x00); + GBIOWrite(gb, 0x47, 0xFC); + GBIOWrite(gb, 0x48, 0xFF); + GBIOWrite(gb, 0x49, 0xFF); + GBIOWrite(gb, 0x4A, 0x00); + GBIOWrite(gb, 0x4B, 0x00); + GBIOWrite(gb, 0xFF, 0x00); +} + void GBIOWrite(struct GB* gb, unsigned address, uint8_t value) { switch (address) { case REG_IF:
M src/gb/video.csrc/gb/video.c

@@ -145,6 +145,15 @@ video->p->cpu->nextEvent = video->nextEvent;

} return; } + if (GBRegisterLCDCIsEnable(video->p->memory.io[REG_LCDC]) && !GBRegisterLCDCIsEnable(value)) { + video->mode = 0; + video->nextMode = INT_MAX; + video->nextEvent = INT_MAX; + video->stat = GBRegisterSTATSetMode(video->stat, video->mode); + video->p->memory.io[REG_STAT] = video->stat; + video->ly = 0; + video->p->memory.io[REG_LY] = 0; + } } void GBVideoWriteSTAT(struct GBVideo* video, GBRegisterSTAT value) {