all repos — mgba @ c2f43bc503e1bfd181fdd76ead42dc67eea0b4f1

mGBA Game Boy Advance Emulator

DS Slot-1: Fix SPI addressing a bit
Vicki Pfau vi@endrift.com
Sat, 15 Apr 2017 12:03:57 -0700
commit

c2f43bc503e1bfd181fdd76ead42dc67eea0b4f1

parent

8fcf9bee070251b6f2cefc9339e2e87842d00895

2 files changed, 22 insertions(+), 2 deletions(-)

jump to
M include/mgba/internal/ds/slot1.hinclude/mgba/internal/ds/slot1.h

@@ -56,6 +56,7 @@ uint8_t statusReg;

int spiAddressingRemaining; uint32_t spiAddress; int spiAddressingBits; + uint32_t spiSize; uint8_t* spiData; struct VFile* spiVf;
M src/ds/slot1.csrc/ds/slot1.c

@@ -30,6 +30,7 @@ ds->memory.slot1.savedataType = DS_SAVEDATA_AUTODETECT;

ds->memory.slot1.spiVf = vf; ds->memory.slot1.spiRealVf = vf; ds->memory.slot1.spiData = NULL; + ds->memory.slot1.spiSize = 0; } void DSSlot1Reset(struct DS* ds) {

@@ -262,12 +263,19 @@ if (!dscore->p->memory.slot1.spiData) {

return 0xFF; } + uint8_t oldValue; switch (dscore->p->memory.slot1.spiCommand) { case 0x03: // RDLO case 0x0B: // RDHI - return dscore->p->memory.slot1.spiData[dscore->p->memory.slot1.spiAddress++]; + dscore->p->memory.slot1.spiAddress &= dscore->p->memory.slot1.spiSize - 1; + oldValue = dscore->p->memory.slot1.spiData[dscore->p->memory.slot1.spiAddress]; + ++dscore->p->memory.slot1.spiAddress; + return oldValue; case 0x02: // WRLO case 0x0A: // WRHI + if (dscore->p->memory.slot1.spiAddress >= dscore->p->memory.slot1.spiSize) { + break; + } dscore->p->memory.slot1.spiData[dscore->p->memory.slot1.spiAddress] = datum; ++dscore->p->memory.slot1.spiAddress; break;

@@ -295,14 +303,23 @@

uint8_t oldValue; switch (dscore->p->memory.slot1.spiCommand) { case 0x03: // RD + if (dscore->p->memory.slot1.spiAddress >= dscore->p->memory.slot1.spiSize) { + return 0xFF; + } oldValue = dscore->p->memory.slot1.spiData[dscore->p->memory.slot1.spiAddress]; ++dscore->p->memory.slot1.spiAddress; return oldValue; case 0x02: // PP + if (dscore->p->memory.slot1.spiAddress >= dscore->p->memory.slot1.spiSize) { + break; + } dscore->p->memory.slot1.spiData[dscore->p->memory.slot1.spiAddress] = datum; ++dscore->p->memory.slot1.spiAddress; break; case 0x0A: // PW + if (dscore->p->memory.slot1.spiAddress >= dscore->p->memory.slot1.spiSize) { + break; + } oldValue = dscore->p->memory.slot1.spiData[dscore->p->memory.slot1.spiAddress]; dscore->p->memory.slot1.spiData[dscore->p->memory.slot1.spiAddress] = datum; ++dscore->p->memory.slot1.spiAddress;

@@ -377,6 +394,7 @@ return false;

} if (slot1->spiAddress >= slot1->spiVf->size(slot1->spiVf)) { size_t size = toPow2(slot1->spiAddress + 1); + slot1->spiSize = size; size_t oldSize = slot1->spiVf->size(slot1->spiVf); if (slot1->spiData) { slot1->spiVf->unmap(slot1->spiVf, slot1->spiData, oldSize);

@@ -415,7 +433,7 @@ ds->memory.slot1.savedataType = DS_SAVEDATA_FLASH;

} else { ds->memory.slot1.savedataType = DS_SAVEDATA_EEPROM; } - if (size >= 0x10000) { + if (size > 0x10000) { ds->memory.slot1.spiAddressingBits = 24; } else if (size <= 0x200) { ds->memory.slot1.spiAddressingBits = 8;

@@ -424,6 +442,7 @@ } else {

ds->memory.slot1.spiAddressingBits = 16; } ds->memory.slot1.spiAddress = size - 1; + ds->memory.slot1.spiSize = size; _slot1GuaranteeSize(&ds->memory.slot1); }