First flasher version, untested

This commit is contained in:
Florian Reitz 2019-02-26 00:42:47 +01:00
parent 781d283c3c
commit 5ba4e08c84
4 changed files with 144 additions and 6 deletions

View File

@ -19,6 +19,9 @@
<ItemGroup>
<ClCompile Include="src\Flasher.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\AppleIISd.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{B2CF2E9D-62A7-4A68-9477-9B15A8707E78}</ProjectGuid>
<Keyword>MakeFileProj</Keyword>

View File

@ -9,4 +9,7 @@
<ItemGroup>
<ClCompile Include="src\Flasher.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\AppleIISd.h" />
</ItemGroup>
</Project>

62
Software/src/AppleIISd.h Normal file
View File

@ -0,0 +1,62 @@
#ifndef APPLE_II_SD_H
#define APPLE_II_SD_H
typedef unsigned char byte;
#define SLOT_IO_START (byte*)0xC080
#define SLOT_ROM_START (byte*)0xC000
#define EXT_ROM_START (byte*)0xC800
#define CFFF (byte*)0xCFFF
typedef struct
{
// data register
// +0
byte data;
// status register
// +1
union
{
struct
{
unsigned pgmen : 1;
unsigned : 1;
unsigned ece : 1;
unsigned : 1;
unsigned frx : 1;
const unsigned bsy : 1;
unsigned : 1;
const unsigned tc : 1;
};
byte status;
} status;
// clock divisor register
// +2
union
{
unsigned clkDiv : 2;
};
// slave select and card state register
// +3
union
{
struct
{
unsigned slaveSel : 1;
unsigned : 3;
unsigned sdhc : 1;
unsigned wp : 1;
unsigned card : 1;
unsigned inited : 1;
};
byte ss_card;
} ss_card;
} APPLE_II_SD_T;
#endif

View File

@ -1,18 +1,38 @@
#include "AppleIISd.h"
#include <stdio.h>
#include <errno.h>
#include <conio.h>
#include <apple2enh.h>
typedef enum
{
STATE_0 = 0x7C, // pipe
STATE_1 = 0x2F, // slash
STATE_2 = 0x2D, // hyphen
STATE_3 = 0x5C, // backslash
STATE_LAST // don't use
} STATE_CURSOR_T;
void writeChip(const byte* pSource, byte* pDest, unsigned length);
void printStatus(byte percentage);
// Binary can't be larger than 2k
byte buffer[2048] = { 0 };
int main()
{
// Binary can't be larger than 2k
char buffer[2048];
char* pBuf = buffer;
FILE* pFile;
size_t fileSize;
char slotNum;
APPLE_II_SD_T* pAIISD = (APPLE_II_SD_T*)SLOT_IO_START;
byte* pSlotRom = SLOT_ROM_START;
byte* pExtRom = EXT_ROM_START;
videomode(VIDEOMODE_80COL);
clrscr();
cprintf("AppleIISd firmware flasher\r");
cprintf("(c) 2019 Florian Reitz\r\r");
@ -29,23 +49,40 @@ int main()
return 1; // failure
}
((byte*)pAIISD) += slotNum << 4;
pSlotRom += slotNum << 8;
// open file
pFile = fopen("AppleIISd.bin", "rb");
if(pFile)
{
// read buffer
fileSize = fread(buffer, sizeof(buffer), 1, pFile);
unsigned fileSize = fread(buffer, sizeof(buffer), 1, pFile);
// enable write
pAIISD->status.pgmen = 1;
// clear 0xCFFF
*((char*)0xCFFF) = 0;
*CFFF = 0;
// write to SLOTROM
cprintf("\r\rFlashing SLOTROM: ");
writeChip(buffer, pSlotRom, 256);
// write to EXTROM
cprintf("\r\rFlashing EXTROM: ");
writeChip(buffer + 256, pExtRom, fileSize - 256);
// zero rest of chip
if(fileSize < 2048)
{
cprintf("\r\rErase rest of chip: ");
writeChip(NULL, pExtRom + fileSize, 2048 - fileSize);
}
// disable write
pAIISD->status.pgmen = 0;
cprintf("\r\r Flashing finished!\r");
}
else
{
@ -56,4 +93,37 @@ int main()
return 0; // success
}
void writeChip(const byte* pSource, byte* pDest, unsigned length)
{
unsigned i;
for(i=0; i<length; i++)
{
if(pSource)
{
*pDest = pSource[i];
}
else
{
// erase if no source
*pDest = 0;
}
printStatus(i * 100 / length);
pDest++;
}
}
void printStatus(byte percentage)
{
static STATE_CURSOR_T state = STATE_0;
byte x = wherex();
cprintf("% 2hhu %c", percentage, (char)state);
gotox(x);
state++;
if(state == STATE_LAST)
{
state = STATE_0;
}
}