From 586e2f5007ee6cf3632e6f29af16417a951b7c23 Mon Sep 17 00:00:00 2001 From: Brian Peek Date: Sat, 9 Jul 2022 18:08:39 -0700 Subject: [PATCH] 2 serial modes + SD card --- src/main.cpp | 47 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 97d4e60..db25f40 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,6 @@ #include +#include +#include // forced to a 2mbit eprom // FLASHMEM @@ -7,16 +9,12 @@ #define ROM_BUFFER_LEN (256*1024) char buffer[ROM_BUFFER_LEN]; +const char *filename = "rom.bin"; -// v1 uses 30/31 -int32_t inPins[] = { 19,18,14,15,40,41,17,16,22,23,20,21,38,39,26,27,24,25,/*30,31,*/-1 }; +int32_t inPins[] = { 19,18,14,15,40,41,17,16,22,23,20,21,38,39,26,27,24,25,-1 }; int32_t outPins[] = { 10,12,11,13,8,7,36,37,-1 }; -// v1 -//int32_t cePin = 30; -//int32_t pgmPin = 31; - -void readFile() +void readFile(int port) { const int length = 1024; char buff[length]; @@ -30,7 +28,17 @@ void readFile() do { memset(buff, 0, length); - read = Serial.readBytes(buff, length); + + switch(port) + { + case 0: + read = Serial.readBytes(buff, length); + break; + case 1: + read = Serial1.readBytes(buff, length); + break; + } + total += read; if(read > 0) { @@ -43,6 +51,12 @@ void readFile() // on GG (and lynx?) top address bit gets stuck high (?) so mirror to upper region too? if(total == 131072) memcpy(p, buffer, 131072); + + SD.remove(filename); + + File f = SD.open(filename, O_WRITE); + f.write(buffer, ROM_BUFFER_LEN); + f.close(); } void setPinMode(int32_t* pins, int32_t direction) @@ -57,7 +71,17 @@ void setup() setPinMode(outPins, OUTPUT); GPIO7_DR = 0; + SD.begin(BUILTIN_SDCARD); + + if(SD.exists(filename)) + { + File f = SD.open(filename, O_READ); + f.read(buffer, f.size()); + f.close(); + } + Serial.begin(115200); + Serial1.begin(3000000); } void loop() @@ -73,9 +97,12 @@ void loop() // set data pins outb = ((b & 0x0F) << 0) | ((b & 0xF0) << 12); - GPIO7_DR = outb; + // read file from either serial port, if available if(Serial.available()) - readFile(); + readFile(0); + + if(Serial1.available()) + readFile(1); }