DS Slot-1: Fix SPI addressing wrap
Vicki Pfau vi@endrift.com
Mon, 24 Apr 2017 19:29:29 -0700
1 files changed,
4 insertions(+),
12 deletions(-)
jump to
M
src/ds/slot1.c
→
src/ds/slot1.c
@@ -276,9 +276,7 @@ ++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.spiAddress &= dscore->p->memory.slot1.spiSize - 1; dscore->p->memory.slot1.spiData[dscore->p->memory.slot1.spiAddress] = datum; ++dscore->p->memory.slot1.spiAddress; break;@@ -306,23 +304,17 @@
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; - } + 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: // PP - if (dscore->p->memory.slot1.spiAddress >= dscore->p->memory.slot1.spiSize) { - break; - } + dscore->p->memory.slot1.spiAddress &= dscore->p->memory.slot1.spiSize - 1; 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; - } + 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.spiData[dscore->p->memory.slot1.spiAddress] = datum; ++dscore->p->memory.slot1.spiAddress;