mirror of
https://github.com/freitz85/AppleIISd.git
synced 2025-01-22 05:30:39 +00:00
Use array access instead of pointers
This commit is contained in:
parent
f6ee86a2f7
commit
bc8c53b517
@ -1,8 +1,10 @@
|
||||
#include "AppleIISd.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <conio.h>
|
||||
#include <string.h>
|
||||
#include <apple2enh.h>
|
||||
|
||||
// Binary can't be larger than 2k
|
||||
@ -20,14 +22,12 @@ typedef enum
|
||||
} STATE_CURSOR_T;
|
||||
|
||||
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 boolean verifyChip(const uint8* pSource, volatile uint8* pDest, uint16 length);
|
||||
static void printStatus(uint8 percentage);
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
int retval = 1;
|
||||
@ -41,9 +41,9 @@ int main()
|
||||
|
||||
videomode(VIDEOMODE_40COL);
|
||||
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");
|
||||
|
||||
|
||||
// ask for slot
|
||||
cursor(1); // enable blinking cursor
|
||||
cprintf("Slot number (1-7): ");
|
||||
@ -76,8 +76,8 @@ int main()
|
||||
|
||||
if(erase)
|
||||
{
|
||||
// buffer is already filled with 0
|
||||
fileSize = BUFFER_SIZE;
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -113,11 +113,11 @@ int main()
|
||||
// write to SLOTROM
|
||||
cprintf("\r\n\r\nFlashing SLOTROM: ");
|
||||
writeChip(buffer, pSlotRom, 256);
|
||||
cprintf("\r\n\r\nVerifying SLOTROM: ");
|
||||
cprintf("\r\nVerifying SLOTROM: ");
|
||||
if(verifyChip(buffer, pSlotRom, 256))
|
||||
{
|
||||
// write to EXTROM
|
||||
cprintf("\r\nFlashing EXTROM: ");
|
||||
cprintf("\r\n\r\nFlashing EXTROM: ");
|
||||
writeChip(buffer + 256, EXT_ROM_START, fileSize - 256);
|
||||
cprintf("\r\nVerifying EXTROM: ");
|
||||
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)
|
||||
{
|
||||
uint32 i;
|
||||
volatile uint8 data = 0;
|
||||
volatile uint8 readData;
|
||||
|
||||
for(i=0; i<length; i++)
|
||||
{
|
||||
// set 0 if no source
|
||||
if(pSource)
|
||||
{
|
||||
data = pSource[i];
|
||||
}
|
||||
|
||||
*pDest = data;
|
||||
pDest[i] = pSource[i];
|
||||
printStatus((i * 100u / length) + 1);
|
||||
|
||||
// wait for write cycle
|
||||
do
|
||||
{
|
||||
readData = *pDest;
|
||||
readData = pDest[i];
|
||||
}
|
||||
while((readData & 0x80) != (data & 0x80));
|
||||
|
||||
pDest++;
|
||||
while((readData & 0x80) != (pSource[i] & 0x80));
|
||||
}
|
||||
}
|
||||
|
||||
static boolean verifyChip(const uint8* pSource, volatile uint8* pDest, uint16 length)
|
||||
{
|
||||
uint32 i;
|
||||
volatile uint8 data = 0;
|
||||
|
||||
for(i=0; i<length; i++)
|
||||
{
|
||||
// set 0 if no source
|
||||
if(pSource)
|
||||
{
|
||||
data = pSource[i];
|
||||
}
|
||||
|
||||
printStatus((i * 100u / length) + 1);
|
||||
|
||||
if(*pDest != data)
|
||||
if(pDest[i] != pSource[i])
|
||||
{
|
||||
// verification not successful
|
||||
cprintf("\r\n\r\n!!! Verification failed at %p !!!\r\n", pDest);
|
||||
cprintf("Was 0x%02hhX, should be 0x%02hhX\r\n", *pDest, data);
|
||||
cprintf("\r\n\r\n!!! Verification failed at %p !!!\r\n", &pDest[i]);
|
||||
cprintf("Was 0x%02hhX, should be 0x%02hhX\r\n", pDest[i], pSource[i]);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
pDest++;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
Loading…
x
Reference in New Issue
Block a user