all repos — mgba @ 830511472a3d3e9854b94216fc4e74e35d8d3081

mGBA Game Boy Advance Emulator

GBA Memory: Properly initialize 1 Mb flash, and add debug logging
Jeffrey Pfau jeffrey@endrift.com
Sun, 21 Dec 2014 14:49:54 -0800
commit

830511472a3d3e9854b94216fc4e74e35d8d3081

parent

86ff069a5a166bf4280241fbcd6facac427587ef

3 files changed, 14 insertions(+), 6 deletions(-)

jump to
M CHANGESCHANGES

@@ -16,6 +16,7 @@ - GBA BIOS: Fix BIOS prefetch after returning from a SWI

- Debugger: Negative PC-relative loads now properly subtract the offset - Qt: Fix window focus issues - GBA Audio: Support 16-bit writes to FIFO audio + - GBA Memory: Properly initialize 1 Mb flash, and add debug logging Misc: - Qt: Disable sync to video by default - GBA: Exit cleanly on FATAL if the port supports it
M src/gba/gba-memory.csrc/gba/gba-memory.c

@@ -223,7 +223,7 @@ }

#define LOAD_SRAM \ GBALog(gba, GBA_LOG_STUB, "Unimplemented memory Load32: 0x%08X", address); \ - value = 0xDEADBEEF; + value = 0xFFFFFFFF; int32_t GBALoad32(struct ARMCore* cpu, uint32_t address, int* cycleCounter) { struct GBA* gba = (struct GBA*) cpu->master;

@@ -353,6 +353,7 @@ break;

case REGION_CART_SRAM: case REGION_CART_SRAM_MIRROR: GBALog(gba, GBA_LOG_STUB, "Unimplemented memory Load16: 0x%08X", address); + value = 0xFFFF; break; default: GBALog(gba, GBA_LOG_GAME_ERROR, "Bad memory Load16: 0x%08X", address);
M src/gba/gba-savedata.csrc/gba/gba-savedata.c

@@ -117,6 +117,7 @@ if (savedata->type != SAVEDATA_FLASH512 && savedata->type != SAVEDATA_FLASH1M) {

GBALog(0, GBA_LOG_WARN, "Can't re-initialize savedata"); return; } + size_t flashSize = SIZE_CART_FLASH512; off_t end; if (!savedata->vf) { end = 0;

@@ -125,13 +126,14 @@ } else {

end = savedata->vf->seek(savedata->vf, 0, SEEK_END); if (end < SIZE_CART_FLASH512) { savedata->vf->truncate(savedata->vf, SIZE_CART_FLASH1M); + flashSize = SIZE_CART_FLASH1M; } savedata->data = savedata->vf->map(savedata->vf, SIZE_CART_FLASH1M, savedata->mapMode); } savedata->currentBank = savedata->data; if (end < SIZE_CART_FLASH512) { - memset(&savedata->data[end], 0xFF, SIZE_CART_FLASH512 - end); + memset(&savedata->data[end], 0xFF, flashSize - end); } }

@@ -348,27 +350,31 @@ return 0;

} void _flashSwitchBank(struct GBASavedata* savedata, int bank) { + GBALog(0, GBA_LOG_DEBUG, "Performing flash bank switch to bank %i", bank); savedata->currentBank = &savedata->data[bank << 16]; - if (bank > 0) { + if (bank > 0 && savedata->type == SAVEDATA_FLASH512) { savedata->type = SAVEDATA_FLASH1M; if (savedata->vf) { savedata->vf->truncate(savedata->vf, SIZE_CART_FLASH1M); + memset(&savedata->data[SIZE_CART_FLASH512], 0xFF, SIZE_CART_FLASH512); } } } void _flashErase(struct GBASavedata* savedata) { - size_t size = 0x10000; + GBALog(0, GBA_LOG_DEBUG, "Performing flash chip erase"); + size_t size = SIZE_CART_FLASH512; if (savedata->type == SAVEDATA_FLASH1M) { - size = 0x20000; + size = SIZE_CART_FLASH1M; } memset(savedata->data, 0xFF, size); } void _flashEraseSector(struct GBASavedata* savedata, uint16_t sectorStart) { + GBALog(0, GBA_LOG_DEBUG, "Performing flash sector erase at 0x%04x", sectorStart); size_t size = 0x1000; if (savedata->type == SAVEDATA_FLASH1M) { - GBALog(0, GBA_LOG_DEBUG, "Performing unknown sector-size erase at %#04x", sectorStart); + GBALog(0, GBA_LOG_DEBUG, "Performing unknown sector-size erase at 0x%04x", sectorStart); } memset(&savedata->currentBank[sectorStart & ~(size - 1)], 0xFF, size); }