mirror of https://github.com/mgba-emu/mgba.git
GBA Memory: Properly initialize 1 Mb flash, and add debug logging
This commit is contained in:
parent
86ff069a5a
commit
830511472a
1
CHANGES
1
CHANGES
|
@ -16,6 +16,7 @@ Bugfixes:
|
||||||
- Debugger: Negative PC-relative loads now properly subtract the offset
|
- Debugger: Negative PC-relative loads now properly subtract the offset
|
||||||
- Qt: Fix window focus issues
|
- Qt: Fix window focus issues
|
||||||
- GBA Audio: Support 16-bit writes to FIFO audio
|
- GBA Audio: Support 16-bit writes to FIFO audio
|
||||||
|
- GBA Memory: Properly initialize 1 Mb flash, and add debug logging
|
||||||
Misc:
|
Misc:
|
||||||
- Qt: Disable sync to video by default
|
- Qt: Disable sync to video by default
|
||||||
- GBA: Exit cleanly on FATAL if the port supports it
|
- GBA: Exit cleanly on FATAL if the port supports it
|
||||||
|
|
|
@ -223,7 +223,7 @@ static void GBASetActiveRegion(struct ARMCore* cpu, uint32_t address) {
|
||||||
|
|
||||||
#define LOAD_SRAM \
|
#define LOAD_SRAM \
|
||||||
GBALog(gba, GBA_LOG_STUB, "Unimplemented memory Load32: 0x%08X", address); \
|
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) {
|
int32_t GBALoad32(struct ARMCore* cpu, uint32_t address, int* cycleCounter) {
|
||||||
struct GBA* gba = (struct GBA*) cpu->master;
|
struct GBA* gba = (struct GBA*) cpu->master;
|
||||||
|
@ -353,6 +353,7 @@ int16_t GBALoad16(struct ARMCore* cpu, uint32_t address, int* cycleCounter) {
|
||||||
case REGION_CART_SRAM:
|
case REGION_CART_SRAM:
|
||||||
case REGION_CART_SRAM_MIRROR:
|
case REGION_CART_SRAM_MIRROR:
|
||||||
GBALog(gba, GBA_LOG_STUB, "Unimplemented memory Load16: 0x%08X", address);
|
GBALog(gba, GBA_LOG_STUB, "Unimplemented memory Load16: 0x%08X", address);
|
||||||
|
value = 0xFFFF;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
GBALog(gba, GBA_LOG_GAME_ERROR, "Bad memory Load16: 0x%08X", address);
|
GBALog(gba, GBA_LOG_GAME_ERROR, "Bad memory Load16: 0x%08X", address);
|
||||||
|
|
|
@ -117,6 +117,7 @@ void GBASavedataInitFlash(struct GBASavedata* savedata) {
|
||||||
GBALog(0, GBA_LOG_WARN, "Can't re-initialize savedata");
|
GBALog(0, GBA_LOG_WARN, "Can't re-initialize savedata");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
size_t flashSize = SIZE_CART_FLASH512;
|
||||||
off_t end;
|
off_t end;
|
||||||
if (!savedata->vf) {
|
if (!savedata->vf) {
|
||||||
end = 0;
|
end = 0;
|
||||||
|
@ -125,13 +126,14 @@ void GBASavedataInitFlash(struct GBASavedata* savedata) {
|
||||||
end = savedata->vf->seek(savedata->vf, 0, SEEK_END);
|
end = savedata->vf->seek(savedata->vf, 0, SEEK_END);
|
||||||
if (end < SIZE_CART_FLASH512) {
|
if (end < SIZE_CART_FLASH512) {
|
||||||
savedata->vf->truncate(savedata->vf, SIZE_CART_FLASH1M);
|
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->data = savedata->vf->map(savedata->vf, SIZE_CART_FLASH1M, savedata->mapMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
savedata->currentBank = savedata->data;
|
savedata->currentBank = savedata->data;
|
||||||
if (end < SIZE_CART_FLASH512) {
|
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 @@ uint16_t GBASavedataReadEEPROM(struct GBASavedata* savedata) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void _flashSwitchBank(struct GBASavedata* savedata, int bank) {
|
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];
|
savedata->currentBank = &savedata->data[bank << 16];
|
||||||
if (bank > 0) {
|
if (bank > 0 && savedata->type == SAVEDATA_FLASH512) {
|
||||||
savedata->type = SAVEDATA_FLASH1M;
|
savedata->type = SAVEDATA_FLASH1M;
|
||||||
if (savedata->vf) {
|
if (savedata->vf) {
|
||||||
savedata->vf->truncate(savedata->vf, SIZE_CART_FLASH1M);
|
savedata->vf->truncate(savedata->vf, SIZE_CART_FLASH1M);
|
||||||
|
memset(&savedata->data[SIZE_CART_FLASH512], 0xFF, SIZE_CART_FLASH512);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _flashErase(struct GBASavedata* savedata) {
|
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) {
|
if (savedata->type == SAVEDATA_FLASH1M) {
|
||||||
size = 0x20000;
|
size = SIZE_CART_FLASH1M;
|
||||||
}
|
}
|
||||||
memset(savedata->data, 0xFF, size);
|
memset(savedata->data, 0xFF, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _flashEraseSector(struct GBASavedata* savedata, uint16_t sectorStart) {
|
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;
|
size_t size = 0x1000;
|
||||||
if (savedata->type == SAVEDATA_FLASH1M) {
|
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);
|
memset(&savedata->currentBank[sectorStart & ~(size - 1)], 0xFF, size);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue