From 7879736a44c167373c04c9381218a131ee1bd5c5 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Mon, 24 Apr 2017 19:29:29 -0700 Subject: [PATCH] DS Slot-1: Fix SPI addressing wrap --- src/ds/slot1.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/ds/slot1.c b/src/ds/slot1.c index 8beec18be..df98ff968 100644 --- a/src/ds/slot1.c +++ b/src/ds/slot1.c @@ -276,9 +276,7 @@ static uint8_t _slot1SPIEEPROM(struct DSCommon* dscore, uint8_t datum) { 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 @@ static uint8_t _slot1SPIFlash(struct DSCommon* dscore, uint8_t datum) { 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;