Use array access instead of pointers

This commit is contained in:
Florian Reitz 2020-10-03 11:30:57 +02:00
parent f6ee86a2f7
commit bc8c53b517
1 changed files with 14 additions and 32 deletions

View File

@ -1,8 +1,10 @@
#include "AppleIISd.h" #include "AppleIISd.h"
#include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <conio.h> #include <conio.h>
#include <string.h>
#include <apple2enh.h> #include <apple2enh.h>
// Binary can't be larger than 2k // Binary can't be larger than 2k
@ -20,14 +22,12 @@ typedef enum
} STATE_CURSOR_T; } STATE_CURSOR_T;
const char state_char[STATE_LAST] = { '|', '/', '-', '\\' }; const char state_char[STATE_LAST] = { '|', '/', '-', '\\' };
uint8 buffer[BUFFER_SIZE] = { 0 }; static uint8 buffer[BUFFER_SIZE];
static void writeChip(const uint8* pSource, volatile uint8* pDest, uint16 length); static void writeChip(const uint8* pSource, volatile uint8* pDest, uint16 length);
static boolean verifyChip(const uint8* pSource, volatile uint8* pDest, uint16 length); static boolean verifyChip(const uint8* pSource, volatile uint8* pDest, uint16 length);
static void printStatus(uint8 percentage); static void printStatus(uint8 percentage);
int main() int main()
{ {
int retval = 1; int retval = 1;
@ -41,9 +41,9 @@ int main()
videomode(VIDEOMODE_40COL); videomode(VIDEOMODE_40COL);
clrscr(); clrscr();
cprintf("AppleIISd firmware flasher\r\n"); cprintf("AppleIISd firmware flasher V1.2\r\n");
cprintf("(c) 2019-2020 Florian Reitz\r\n\r\n"); cprintf("(c) 2019-2020 Florian Reitz\r\n\r\n");
// ask for slot // ask for slot
cursor(1); // enable blinking cursor cursor(1); // enable blinking cursor
cprintf("Slot number (1-7): "); cprintf("Slot number (1-7): ");
@ -76,8 +76,8 @@ int main()
if(erase) if(erase)
{ {
// buffer is already filled with 0
fileSize = BUFFER_SIZE; fileSize = BUFFER_SIZE;
memset(buffer, 0, sizeof(buffer));
} }
else else
{ {
@ -113,11 +113,11 @@ int main()
// write to SLOTROM // write to SLOTROM
cprintf("\r\n\r\nFlashing SLOTROM: "); cprintf("\r\n\r\nFlashing SLOTROM: ");
writeChip(buffer, pSlotRom, 256); writeChip(buffer, pSlotRom, 256);
cprintf("\r\n\r\nVerifying SLOTROM: "); cprintf("\r\nVerifying SLOTROM: ");
if(verifyChip(buffer, pSlotRom, 256)) if(verifyChip(buffer, pSlotRom, 256))
{ {
// write to EXTROM // write to EXTROM
cprintf("\r\nFlashing EXTROM: "); cprintf("\r\n\r\nFlashing EXTROM: ");
writeChip(buffer + 256, EXT_ROM_START, fileSize - 256); writeChip(buffer + 256, EXT_ROM_START, fileSize - 256);
cprintf("\r\nVerifying EXTROM: "); cprintf("\r\nVerifying EXTROM: ");
if(verifyChip(buffer + 256, EXT_ROM_START, fileSize - 256)) if(verifyChip(buffer + 256, EXT_ROM_START, fileSize - 256))
@ -138,55 +138,37 @@ int main()
static void writeChip(const uint8* pSource, volatile uint8* pDest, uint16 length) static void writeChip(const uint8* pSource, volatile uint8* pDest, uint16 length)
{ {
uint32 i; uint32 i;
volatile uint8 data = 0;
volatile uint8 readData; volatile uint8 readData;
for(i=0; i<length; i++) for(i=0; i<length; i++)
{ {
// set 0 if no source pDest[i] = pSource[i];
if(pSource)
{
data = pSource[i];
}
*pDest = data;
printStatus((i * 100u / length) + 1); printStatus((i * 100u / length) + 1);
// wait for write cycle // wait for write cycle
do do
{ {
readData = *pDest; readData = pDest[i];
} }
while((readData & 0x80) != (data & 0x80)); while((readData & 0x80) != (pSource[i] & 0x80));
pDest++;
} }
} }
static boolean verifyChip(const uint8* pSource, volatile uint8* pDest, uint16 length) static boolean verifyChip(const uint8* pSource, volatile uint8* pDest, uint16 length)
{ {
uint32 i; uint32 i;
volatile uint8 data = 0;
for(i=0; i<length; i++) for(i=0; i<length; i++)
{ {
// set 0 if no source
if(pSource)
{
data = pSource[i];
}
printStatus((i * 100u / length) + 1); printStatus((i * 100u / length) + 1);
if(*pDest != data) if(pDest[i] != pSource[i])
{ {
// verification not successful // verification not successful
cprintf("\r\n\r\n!!! Verification failed at %p !!!\r\n", pDest); cprintf("\r\n\r\n!!! Verification failed at %p !!!\r\n", &pDest[i]);
cprintf("Was 0x%02hhX, should be 0x%02hhX\r\n", *pDest, data); cprintf("Was 0x%02hhX, should be 0x%02hhX\r\n", pDest[i], pSource[i]);
return FALSE; return FALSE;
} }
pDest++;
} }
return TRUE; return TRUE;