diff --git a/Software/Flasher.vcxproj b/Software/Flasher.vcxproj
index c1546b0..ffd77b2 100644
--- a/Software/Flasher.vcxproj
+++ b/Software/Flasher.vcxproj
@@ -19,6 +19,9 @@
+
+
+
{B2CF2E9D-62A7-4A68-9477-9B15A8707E78}
MakeFileProj
diff --git a/Software/Flasher.vcxproj.filters b/Software/Flasher.vcxproj.filters
index f146eaf..6cd0d9f 100644
--- a/Software/Flasher.vcxproj.filters
+++ b/Software/Flasher.vcxproj.filters
@@ -9,4 +9,7 @@
+
+
+
\ No newline at end of file
diff --git a/Software/src/AppleIISd.h b/Software/src/AppleIISd.h
new file mode 100644
index 0000000..06c6c02
--- /dev/null
+++ b/Software/src/AppleIISd.h
@@ -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
diff --git a/Software/src/Flasher.c b/Software/src/Flasher.c
index eb7e160..68085ac 100644
--- a/Software/src/Flasher.c
+++ b/Software/src/Flasher.c
@@ -1,18 +1,38 @@
+#include "AppleIISd.h"
+
#include
#include
#include
#include
+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