diff --git a/SIO2Arduino.ino b/SIO2Arduino.ino index e0bc317..f8b99dc 100644 --- a/SIO2Arduino.ino +++ b/SIO2Arduino.ino @@ -23,6 +23,7 @@ #include "config.h" #include #include +#include #include "atari.h" #include "sio_channel.h" #include "disk_drive.h" @@ -44,7 +45,7 @@ DiskDrive drive1; #ifdef SELECTOR_BUTTON boolean isSwitchPressed = false; unsigned long lastSelectionPress; -boolean isFileOpened; +boolean isFileOpened=false; #endif #ifdef RESET_BUTTON unsigned long lastResetPress; @@ -64,51 +65,53 @@ void setup() { // set pin modes #ifdef SELECTOR_BUTTON - pinMode(PIN_SELECTOR, INPUT); + pinMode(PIN_SELECTOR, INPUT_PULLUP); #endif #ifdef RESET_BUTTON - pinMode(PIN_RESET, INPUT); + pinMode(PIN_RESET, INPUT_PULLUP); #endif #ifdef LCD_DISPLAY // set up LCD if appropriate lcd.begin(16, 2); - lcd.print("SIO2Arduino"); + lcd.print(F("SIO2Arduino")); lcd.setCursor(0,1); #endif // initialize SD card - LOG_MSG("Initializing SD card..."); + LOG_MSG(F("Initializing SD card...")); pinMode(PIN_SD_CS, OUTPUT); if (!card.init(SPI_HALF_SPEED, PIN_SD_CS)) { - LOG_MSG_CR(" failed."); + LOG_MSG_CR(F(" failed.")); #ifdef LCD_DISPLAY - lcd.print("SD Init Error"); + lcd.print(F("SD Init Error")); #endif return; } if (!volume.init(&card)) { - LOG_MSG_CR(" failed."); + LOG_MSG_CR(F(" failed.")); #ifdef LCD_DISPLAY - lcd.print("SD Volume Error"); + lcd.print(F("SD Volume Error")); #endif return; } if (!currDir.openRoot(&volume)) { - LOG_MSG_CR(" failed."); + LOG_MSG_CR(F(" failed.")); #ifdef LCD_DISPLAY - lcd.print("SD Root Error"); + lcd.print(F("SD Root Error")); #endif return; } - LOG_MSG_CR(" done."); + LOG_MSG_CR(F(" done.")); #ifdef LCD_DISPLAY - lcd.print("READY"); + lcd.print(F("READY")); + delay(3000); #endif + mountFilename(0, "AUTORUN.ATR"); } void loop() { @@ -117,15 +120,14 @@ void loop() { #ifdef SELECTOR_BUTTON // watch the selector button (accounting for debounce) - if (digitalRead(PIN_SELECTOR) == HIGH && millis() - lastSelectionPress > 250) { + if (digitalRead(PIN_SELECTOR) == LOW && millis() - lastSelectionPress > 250 && isSwitchPressed==false) { lastSelectionPress = millis(); changeDisk(0); - } + } else isSwitchPressed=(digitalRead(PIN_SELECTOR) == LOW); #endif - #ifdef RESET_BUTTON // watch the reset button - if (digitalRead(PIN_RESET) == HIGH && millis() - lastResetPress > 250) { + if (digitalRead(PIN_RESET) == LOW && millis() - lastResetPress > 250) { lastResetPress = millis(); mountFilename(0, "AUTORUN.ATR"); } @@ -162,19 +164,19 @@ boolean format(int deviceId, int density) { char name[13]; // get current filename - file.getFilename(name); + file.getName(name, 13); // close and delete the current file file.close(); file.remove(); - LOG_MSG("Remove old file: "); + LOG_MSG(F("Remove old file: ")); LOG_MSG_CR(name); // open new file for writing file.open(&currDir, name, O_RDWR | O_SYNC | O_CREAT); - LOG_MSG("Created new file: "); + LOG_MSG(F("Created new file: ")); LOG_MSG_CR(name); // allow the virtual drive to format the image (and possibly alter its size) @@ -346,4 +348,4 @@ boolean mountFilename(int deviceId, char *name) { } return false; -} +} diff --git a/config.h b/config.h index 96b4dde..9e3ff19 100644 --- a/config.h +++ b/config.h @@ -23,6 +23,7 @@ #ifndef CONFIG_H #define CONFIG_H +#define USE_SD_VOLUME /** * These are SIO2Arduino feature definitions. */ @@ -40,7 +41,7 @@ // Uncomment this line if you are using a hardware button for image selection #define SELECTOR_BUTTON -// Uncomment this line if you want a reset button (automatically mounts /AUTORUN.ATR) +// Uncomment this line if you want a reset button (automatically mounts /AUTORUN.ATR) (deprecated, AUTORUN.ATR always mounted if it exists) //#define RESET_BUTTON // uncomment if using an Ethernet shield for SD capabilities @@ -132,6 +133,7 @@ #define SIO_CALLBACK serialEvent #endif +//#define DEBUG /** * Logging/debug config */ diff --git a/disk_image.cpp b/disk_image.cpp index 218dd49..8572c4c 100644 --- a/disk_image.cpp +++ b/disk_image.cpp @@ -252,9 +252,9 @@ boolean DiskImage::loadFile(SdFile *file) { m_sectorSize = atrHeader->secSize; m_sectorReadDelay = 0; - LOG_MSG("Loaded ATR with sector size "); + LOG_MSG(F("Loaded ATR with sector size ")); LOG_MSG(atrHeader->secSize); - LOG_MSG(": "); + LOG_MSG(F(": ")); return true; } @@ -288,7 +288,7 @@ boolean DiskImage::loadFile(SdFile *file) { break; } - LOG_MSG("Loaded PRO with sector size 128: "); + LOG_MSG(F("Loaded PRO with sector size 128: ")); return true; } @@ -383,12 +383,12 @@ boolean DiskImage::loadFile(SdFile *file) { file->seekSet(fileIndex); } - LOG_MSG("Loaded ATX with sector size 128: "); + LOG_MSG(F("Loaded ATX with sector size 128: ")); return true; } #endif - file->getFilename((char*)&filename); + file->getName((char*)&filename, 13); int len = strlen(filename); char *extension = filename + len - 4; @@ -401,7 +401,7 @@ boolean DiskImage::loadFile(SdFile *file) { m_sectorSize = SECTOR_SIZE_SD; m_sectorReadDelay = 0; - LOG_MSG("Loaded XFD with sector size 128: "); + LOG_MSG(F("Loaded XFD with sector size 128: ")); return true; #ifdef XEX_IMAGES } else if ((!strcmp(".XEX", extension) || !strcmp(".xex", extension))) { @@ -415,7 +415,7 @@ boolean DiskImage::loadFile(SdFile *file) { KBOOT_LOADER[9] = m_fileSize & 0xFF; KBOOT_LOADER[10] = m_fileSize >> 8; - LOG_MSG("Loaded XEX with sector size 128: "); + LOG_MSG(F("Loaded XEX with sector size 128: ")); return true; #endif } diff --git a/readme.txt b/readme.txt index 90702af..cf2a3fd 100644 --- a/readme.txt +++ b/readme.txt @@ -1,6 +1,6 @@ SIO2Arduino is an open-source implementation of the Atari SIO device protocol that runs on Arduino hardware. Arduino hardware is open-source and can be assembled by hand or purchased preassembled. -Note: You will need the SdFat library (http://code.google.com/p/sdfatlib/) in your Arduino libraries directory in order to compile. +Note: You will need the SdFat library (https://github.com/greiman/SdFat) in your Arduino libraries directory in order to compile. For more information on SIO2Arduino, see the website at: http://www.whizzosoftware.com/sio2arduino diff --git a/sdrive.cpp b/sdrive.cpp index b600395..d95be64 100644 --- a/sdrive.cpp +++ b/sdrive.cpp @@ -268,49 +268,49 @@ boolean SDriveHandler::printCmdName(byte cmd) { #ifdef DEBUG switch (cmd) { case CMD_SDRIVE_IDENT: - LOG_MSG("SDRIVE IDENT"); + LOG_MSG(F("SDRIVE IDENT")); break; case CMD_SDRIVE_INIT: - LOG_MSG("SDRIVE INIT"); + LOG_MSG(F("SDRIVE INIT")); break; case CMD_SDRIVE_CHROOT: - LOG_MSG("SDRIVE CHROOT"); + LOG_MSG(F("SDRIVE CHROOT")); break; case CMD_SDRIVE_SWAP_VDN: - LOG_MSG("SDRIVE SWAP VDN"); + LOG_MSG(F("SDRIVE SWAP VDN")); break; case CMD_SDRIVE_GETPARAMS: - LOG_MSG("SDRIVE GETPARAMS"); + LOG_MSG(F("SDRIVE GETPARAMS")); break; case CMD_SDRIVE_GET_ENTRIES: - LOG_MSG("SDRIVE GET ENTRIES"); + LOG_MSG(F("SDRIVE GET ENTRIES")); break; case CMD_SDRIVE_CHDIR_VDN: - LOG_MSG("SDRIVE CHDIR VDN"); + LOG_MSG(F("SDRIVE CHDIR VDN")); break; case CMD_SDRIVE_CHDIR: - LOG_MSG("SDRIVE CHDIR"); + LOG_MSG(F("SDRIVE CHDIR")); break; case CMD_SDRIVE_CHDIR_UP: - LOG_MSG("SDRIVE CHDIR UP"); + LOG_MSG(F("SDRIVE CHDIR UP")); break; case CMD_SDRIVE_GET20: - LOG_MSG("SDRIVE GET20"); + LOG_MSG(F("SDRIVE GET20")); break; case CMD_SDRIVE_MOUNT_D0: - LOG_MSG("SDRIVE MOUNTvD0"); + LOG_MSG(F("SDRIVE MOUNTvD0")); break; case CMD_SDRIVE_MOUNT_D1: - LOG_MSG("SDRIVE MOUNTvD1"); + LOG_MSG(F("SDRIVE MOUNTvD1")); break; case CMD_SDRIVE_MOUNT_D2: - LOG_MSG("SDRIVE MOUNTvD2"); + LOG_MSG(F("SDRIVE MOUNTvD2")); break; case CMD_SDRIVE_MOUNT_D3: - LOG_MSG("SDRIVE MOUNTvD3"); + LOG_MSG(F("SDRIVE MOUNTvD3")); break; case CMD_SDRIVE_MOUNT_D4: - LOG_MSG("SDRIVE MOUNTvD4"); + LOG_MSG(F("SDRIVE MOUNTvD4")); break; default: return false; diff --git a/sio_channel.cpp b/sio_channel.cpp index 190d44d..0fa8d43 100644 --- a/sio_channel.cpp +++ b/sio_channel.cpp @@ -127,9 +127,9 @@ void SIOChannel::processIncomingByte() { break; } default: - LOG_MSG("Ignoring byte "); + LOG_MSG(F("Ignoring byte ")); LOG_MSG(b, HEX); - LOG_MSG(" in state "); + LOG_MSG(F(" in state ")); LOG_MSG_CR(m_cmdPinState); break; } @@ -138,9 +138,9 @@ void SIOChannel::processIncomingByte() { boolean SIOChannel::isChecksumValid() { byte chkSum = checksum((byte*)&m_cmdFrame, 4); if (chkSum != m_cmdFrame.checksum) { - LOG_MSG("Checksum failed. Calculated: "); + LOG_MSG(F("Checksum failed. Calculated: ")); LOG_MSG(chkSum); - LOG_MSG("; received: "); + LOG_MSG(F("; received: ")); LOG_MSG_CR(m_cmdFrame.checksum); return false; @@ -298,7 +298,7 @@ void SIOChannel::doPutSector() { // send COMPLETE m_stream->write(COMPLETE); } else { - LOG_MSG_CR("Write to device error"); + LOG_MSG_CR(F("Write to device error")); m_stream->write(ERR); } // otherwise, NAK it @@ -306,9 +306,9 @@ void SIOChannel::doPutSector() { delay(DELAY_T4); m_stream->write(NAK); - LOG_MSG("Data frame checksum error: "); + LOG_MSG(F("Data frame checksum error: ")); LOG_MSG(chksum, HEX); - LOG_MSG(" vs. "); + LOG_MSG(F(" vs. ")); LOG_MSG_CR(m_sectorBuffer[sectorSize], HEX); } @@ -352,7 +352,7 @@ void SIOChannel::cmdFormat(int deviceId, int density) { delay(DELAY_T5); m_stream->write(COMPLETE); - LOG_MSG("Sending data frame of length "); + LOG_MSG(F("Sending data frame of length ")); LOG_MSG_CR(SD_SECTOR_SIZE); m_stream->write(0xFF); @@ -372,44 +372,44 @@ void SIOChannel::dumpCommandFrame() { // we only compile this on DEBUG to save allocating string constants #ifdef DEBUG LOG_MSG(m_cmdFrame.deviceId, HEX); - LOG_MSG(" "); + LOG_MSG(F(" ")); LOG_MSG(m_cmdFrame.command, HEX); - LOG_MSG(" "); + LOG_MSG(F(" ")); LOG_MSG(m_cmdFrame.aux1, HEX); - LOG_MSG(" "); + LOG_MSG(F(" ")); LOG_MSG(m_cmdFrame.aux2, HEX); - LOG_MSG(" "); + LOG_MSG(F(" ")); LOG_MSG(m_cmdFrame.checksum, HEX); - LOG_MSG(" : "); + LOG_MSG(F(" : ")); switch (m_cmdFrame.command) { case CMD_STATUS: - LOG_MSG("STATUS"); + LOG_MSG(F("STATUS")); break; case CMD_POLL: - LOG_MSG("POLL"); + LOG_MSG(F("POLL")); break; case CMD_READ: - LOG_MSG("READ "); + LOG_MSG(F("READ ")); LOG_MSG(getCommandSector()); break; case CMD_WRITE: - LOG_MSG("WRITE "); + LOG_MSG(F("WRITE ")); LOG_MSG(getCommandSector()); break; case CMD_PUT: - LOG_MSG("PUT "); + LOG_MSG(F("PUT ")); LOG_MSG(getCommandSector()); break; case CMD_FORMAT: - LOG_MSG("FORMAT"); + LOG_MSG(F("FORMAT")); break; case CMD_FORMAT_MD: - LOG_MSG("FORMAT MD"); + LOG_MSG(F("FORMAT MD")); break; default: if (!m_sdriveHandler.printCmdName(m_cmdFrame.command)) { - LOG_MSG("??"); + LOG_MSG(F("??")); } }