aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Cart_Reader/COLV.ino106
-rw-r--r--Cart_Reader/Cart_Reader.ino483
-rw-r--r--Cart_Reader/FLASH.ino361
-rw-r--r--Cart_Reader/GB.ino283
-rw-r--r--Cart_Reader/GBA.ino447
-rw-r--r--Cart_Reader/GBM.ino69
-rw-r--r--Cart_Reader/GBS.ino251
-rw-r--r--Cart_Reader/INTV.ino277
-rw-r--r--Cart_Reader/MD.ino1116
-rw-r--r--Cart_Reader/N64.ino749
-rw-r--r--Cart_Reader/NES.ino1871
-rw-r--r--Cart_Reader/NGP.ino41
-rw-r--r--Cart_Reader/PCE.ino281
-rw-r--r--Cart_Reader/PCW.ino191
-rw-r--r--Cart_Reader/SFM.ino213
-rw-r--r--Cart_Reader/SMS.ino133
-rw-r--r--Cart_Reader/SNES.ino516
-rw-r--r--Cart_Reader/SV.ino194
-rw-r--r--Cart_Reader/VBOY.ino168
-rw-r--r--Cart_Reader/WS.ino454
-rw-r--r--Cart_Reader/WSV.ino79
21 files changed, 4172 insertions, 4111 deletions
diff --git a/Cart_Reader/COLV.ino b/Cart_Reader/COLV.ino
index 87d070a..3937e51 100644
--- a/Cart_Reader/COLV.ino
+++ b/Cart_Reader/COLV.ino
@@ -34,9 +34,9 @@
// /C000(PH5) - CHIP 2 - SNES /WR
// /E000(PH6) - CHIP 3 - SNES /RD
-byte COL[] = {8, 12, 16, 20, 24, 32};
-byte collo = 0; // Lowest Entry
-byte colhi = 5; // Highest Entry
+byte COL[] = { 8, 12, 16, 20, 24, 32 };
+byte collo = 0; // Lowest Entry
+byte colhi = 5; // Highest Entry
byte colsize;
byte newcolsize;
@@ -52,10 +52,9 @@ static const char colMenuItem1[] PROGMEM = "Select Cart";
static const char colMenuItem2[] PROGMEM = "Read ROM";
static const char colMenuItem3[] PROGMEM = "Set Size";
static const char colMenuItem4[] PROGMEM = "Reset";
-static const char* const menuOptionsCOL[] PROGMEM = {colMenuItem1, colMenuItem2, colMenuItem3, colMenuItem4};
+static const char* const menuOptionsCOL[] PROGMEM = { colMenuItem1, colMenuItem2, colMenuItem3, colMenuItem4 };
-void setup_COL()
-{
+void setup_COL() {
// Set Address Pins to Output
// Colecovision uses A0-A14 [A15-A23 UNUSED]
//A0-A7
@@ -67,10 +66,10 @@ void setup_COL()
// Set Control Pins to Output
// ---(PH0) ---(PH1) /8000(PH3) /A000(PH4) /C000(PH5) /E000(PH6)
- DDRH |= (1 << 0) | (1 << 1) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6);
+ DDRH |= (1 << 0) | (1 << 1) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6);
// Set TIME(PJ0) to Output (UNUSED)
- DDRJ |= (1 << 0);
+ DDRJ |= (1 << 0);
// Set Pins (D0-D7) to Input
DDRC = 0x00;
@@ -84,8 +83,8 @@ void setup_COL()
// Set Unused Pins HIGH
PORTA = 0xFF;
- PORTL = 0xFF; // A16-A23
- PORTJ |= (1 << 0); // TIME(PJ0)
+ PORTL = 0xFF; // A16-A23
+ PORTJ |= (1 << 0); // TIME(PJ0)
checkStatus_COL();
strcpy(romName, "COLECO");
@@ -93,13 +92,11 @@ void setup_COL()
mode = mode_COL;
}
-void colMenu()
-{
+void colMenu() {
convertPgm(menuOptionsCOL, 4);
uint8_t mainMenu = question_box(F("COLECOVISION MENU"), menuOptions, 4, 0);
- switch (mainMenu)
- {
+ switch (mainMenu) {
case 0:
// Select Cart
setCart_COL();
@@ -134,31 +131,29 @@ void colMenu()
// /C000(PH5) - CHIP 2
// /E000(PH6) - CHIP 3
-uint8_t readData_COL(uint32_t addr)
-{
+uint8_t readData_COL(uint32_t addr) {
// SELECT ROM CHIP - PULL /CE LOW
uint8_t chipdecode = ((addr >> 13) & 0x3);
- if (chipdecode == 3) // CHIP 3
- PORTH &= ~(1 << 6); // /E000 LOW (ENABLE)
- else if (chipdecode == 2) // CHIP 2
- PORTH &= ~(1 << 5); // /C000 LOW (ENABLE)
- else if (chipdecode == 1) // CHIP 1
- PORTH &= ~(1 << 4); // /A000 LOW (ENABLE)
- else // CHIP 0
- PORTH &= ~(1 << 3); // /8000 LOW (ENABLE)
-
- PORTF = addr & 0xFF; // A0-A7
- PORTK = (addr >> 8) & 0xFF; // A8-A15
+ if (chipdecode == 3) // CHIP 3
+ PORTH &= ~(1 << 6); // /E000 LOW (ENABLE)
+ else if (chipdecode == 2) // CHIP 2
+ PORTH &= ~(1 << 5); // /C000 LOW (ENABLE)
+ else if (chipdecode == 1) // CHIP 1
+ PORTH &= ~(1 << 4); // /A000 LOW (ENABLE)
+ else // CHIP 0
+ PORTH &= ~(1 << 3); // /8000 LOW (ENABLE)
+
+ PORTF = addr & 0xFF; // A0-A7
+ PORTK = (addr >> 8) & 0xFF; // A8-A15
// LATCH ADDRESS - PULL /CE HIGH
- PORTH |= (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6); // ALL /CE HIGH (DISABLE)
+ PORTH |= (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6); // ALL /CE HIGH (DISABLE)
uint8_t ret = PINC;
return ret;
}
-void readSegment_COL(uint32_t startaddr, uint32_t endaddr)
-{
+void readSegment_COL(uint32_t startaddr, uint32_t endaddr) {
for (uint32_t addr = startaddr; addr < endaddr; addr += 512) {
for (int w = 0; w < 512; w++) {
uint8_t temp = readData_COL(addr + w);
@@ -168,8 +163,7 @@ void readSegment_COL(uint32_t startaddr, uint32_t endaddr)
}
}
-void readROM_COL()
-{
+void readROM_COL() {
strcpy(fileName, romName);
strcat(fileName, ".col");
@@ -197,17 +191,17 @@ void readROM_COL()
// RESET ALL CS PINS HIGH (DISABLE)
PORTH |= (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6);
- readSegment_COL(0x8000, 0xA000); // 8K
+ readSegment_COL(0x8000, 0xA000); // 8K
if (colsize > 0) {
- readSegment_COL(0xA000, 0xB000); // +4K = 12K
+ readSegment_COL(0xA000, 0xB000); // +4K = 12K
if (colsize > 1) {
- readSegment_COL(0xB000, 0xC000); // +4K = 16K
+ readSegment_COL(0xB000, 0xC000); // +4K = 16K
if (colsize > 2) {
- readSegment_COL(0xC000, 0xD000); // +4K = 20K
+ readSegment_COL(0xC000, 0xD000); // +4K = 20K
if (colsize > 3) {
- readSegment_COL(0xD000, 0xE000); // +4K = 24K
+ readSegment_COL(0xD000, 0xE000); // +4K = 24K
if (colsize > 4) {
- readSegment_COL(0xE000, 0x10000); // +8K = 32K
+ readSegment_COL(0xE000, 0x10000); // +8K = 32K
}
}
}
@@ -231,8 +225,7 @@ void readROM_COL()
// ROM SIZE
//******************************************
-void setROMSize_COL()
-{
+void setROMSize_COL() {
#if (defined(enable_OLED) || defined(enable_LCD))
display_Clear();
if (collo == colhi)
@@ -256,7 +249,7 @@ void setROMSize_COL()
while (1) {
b = checkButton();
- if (b == 2) { // Previous (doubleclick)
+ if (b == 2) { // Previous (doubleclick)
if (i == collo)
i = colhi;
else
@@ -276,7 +269,7 @@ void setROMSize_COL()
#endif
display_Update();
}
- if (b == 1) { // Next (press)
+ if (b == 1) { // Next (press)
if (i == colhi)
i = collo;
else
@@ -296,12 +289,12 @@ void setROMSize_COL()
#endif
display_Update();
}
- if (b == 3) { // Long Press - Execute (hold)
+ if (b == 3) { // Long Press - Execute (hold)
newcolsize = i;
break;
}
}
- display.setCursor(0, 56); // Display selection at bottom
+ display.setCursor(0, 56); // Display selection at bottom
}
print_Msg(F("ROM SIZE "));
print_Msg(COL[newcolsize]);
@@ -340,8 +333,7 @@ setrom:
colsize = newcolsize;
}
-void checkStatus_COL()
-{
+void checkStatus_COL() {
EEPROM_readAnything(8, colsize);
if (colsize > 5) {
colsize = 0;
@@ -404,12 +396,10 @@ void setCart_COL() {
while (1) {
if (myFile.curPosition() == 0) {
break;
- }
- else if (myFile.peek() == '\n') {
+ } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1);
break;
- }
- else {
+ } else {
myFile.seekSet(myFile.curPosition() - 1);
}
}
@@ -451,9 +441,8 @@ void setCart_COL() {
// Remove leading 0 for single digit cart sizes
if (cartSize != 0) {
- cartSize = cartSize * 10 + myFile.read() - 48;
- }
- else {
+ cartSize = cartSize * 10 + myFile.read() - 48;
+ } else {
cartSize = myFile.read() - 48;
}
@@ -498,12 +487,10 @@ void setCart_COL() {
while (1) {
if (myFile.curPosition() == 0) {
break;
- }
- else if (myFile.peek() == '\n') {
+ } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1);
break;
- }
- else {
+ } else {
myFile.seekSet(myFile.curPosition() - 1);
}
}
@@ -551,12 +538,11 @@ void setCart_COL() {
}
}
}
- }
- else {
+ } else {
print_Error(F("Database file not found"), true);
}
}
#endif
//******************************************
// End of File
-//******************************************
+//****************************************** \ No newline at end of file
diff --git a/Cart_Reader/Cart_Reader.ino b/Cart_Reader/Cart_Reader.ino
index 49011bd..1c64d50 100644
--- a/Cart_Reader/Cart_Reader.ino
+++ b/Cart_Reader/Cart_Reader.ino
@@ -4,8 +4,8 @@
This project represents a community-driven effort to provide
an easy to build and easy to modify cartridge dumper.
- Date: 09.10.2022
- Version: 10.2
+ Date: 13.10.2022
+ Version: 10.3
SD lib: https://github.com/greiman/SdFat
LCD lib: https://github.com/olikraus/u8g2
@@ -15,7 +15,7 @@
RTC lib: https://github.com/adafruit/RTClib
Frequency lib: https://github.com/PaulStoffregen/FreqCount
- Compiled with Arduino 1.8.19
+ Compiled with Arduino IDE 2.0.0
Thanks to:
MichlK - ROM Reader for Super Nintendo
@@ -56,7 +56,7 @@
**********************************************************************************/
-char ver[5] = "10.2";
+char ver[5] = "10.3";
//******************************************
// !!! CHOOSE HARDWARE VERSION !!!
@@ -70,7 +70,7 @@ char ver[5] = "10.2";
// #define SERIAL_MONITOR
#if !(defined(HW1) || defined(HW2) || defined(HW3) || defined(HW4) || defined(HW5) || defined(SERIAL_MONITOR))
-# error !!! PLEASE CHOOSE HARDWARE VERSION !!!
+#error !!! PLEASE CHOOSE HARDWARE VERSION !!!
#endif
//******************************************
@@ -102,7 +102,7 @@ char ver[5] = "10.2";
#if (defined(HW4) || defined(HW5))
#define enable_LCD
#define enable_neopixel
-#define background_color 100,0,0 //Green, Red, Blue
+#define background_color 100, 0, 0 //Green, Red, Blue
#define enable_rotary
// #define rotate_counter_clockwise
#define clockgen_installed
@@ -141,7 +141,7 @@ char ver[5] = "10.2";
#define global_log
// Renames ROM if found in database
-#define no-intro
+#define nointro
// Ignores errors that normally force a reset if button 2 is pressed
// #define debug_mode
@@ -186,10 +186,10 @@ boolean dont_log = false;
// AVR Eeprom
#include <EEPROM.h>
// forward declarations for "T" (for non Arduino IDE)
-template <class T> int EEPROM_writeAnything(int ee, const T& value);
-template <class T> int EEPROM_readAnything(int ee, T& value);
+template<class T> int EEPROM_writeAnything(int ee, const T& value);
+template<class T> int EEPROM_readAnything(int ee, T& value);
-template <class T> int EEPROM_writeAnything(int ee, const T& value) {
+template<class T> int EEPROM_writeAnything(int ee, const T& value) {
const byte* p = (const byte*)(const void*)&value;
unsigned int i;
for (i = 0; i < sizeof(value); i++)
@@ -197,7 +197,7 @@ template <class T> int EEPROM_writeAnything(int ee, const T& value) {
return i;
}
-template <class T> int EEPROM_readAnything(int ee, T& value) {
+template<class T> int EEPROM_readAnything(int ee, T& value) {
byte* p = (byte*)(void*)&value;
unsigned int i;
for (i = 0; i < sizeof(value); i++)
@@ -208,7 +208,7 @@ template <class T> int EEPROM_readAnything(int ee, T& value) {
// Graphic SPI LCD
#ifdef enable_LCD
#include <U8g2lib.h>
-U8G2_ST7567_OS12864_F_4W_HW_SPI display(U8G2_R2, /* cs=*/ 12, /* dc=*/ 11, /* reset=*/ 10);
+U8G2_ST7567_OS12864_F_4W_HW_SPI display(U8G2_R2, /* cs=*/12, /* dc=*/11, /* reset=*/10);
#endif
// Rotary Encoder
@@ -244,7 +244,7 @@ typedef enum COLOR_T {
// Graphic I2C OLED
#ifdef enable_OLED
#include <U8g2lib.h>
-U8G2_SSD1306_128X64_NONAME_F_HW_I2C display(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
+U8G2_SSD1306_128X64_NONAME_F_HW_I2C display(U8G2_R0, /* reset=*/U8X8_PIN_NONE);
#endif
// Adafruit Clock Generator
@@ -297,50 +297,50 @@ bool i2c_found;
#define mode_PCW 27
// optimization-safe nop delay
-#define NOP __asm__ __volatile__ ("nop\n\t")
+#define NOP __asm__ __volatile__("nop\n\t")
// Button timing
-#define debounce 20 // ms debounce period to prevent flickering when pressing or releasing the button
-#define DCgap 250 // max ms between clicks for a double click event
-#define holdTime 2000 // ms hold period: how long to wait for press+hold event
-#define longHoldTime 5000 // ms long hold period: how long to wait for press+hold event
+#define debounce 20 // ms debounce period to prevent flickering when pressing or releasing the button
+#define DCgap 250 // max ms between clicks for a double click event
+#define holdTime 2000 // ms hold period: how long to wait for press+hold event
+#define longHoldTime 5000 // ms long hold period: how long to wait for press+hold event
/******************************************
Variables
*****************************************/
#ifdef enable_rotary
// Button debounce
-boolean buttonState = HIGH; // the current reading from the input pin
-boolean lastButtonState = HIGH; // the previous reading from the input pin
+boolean buttonState = HIGH; // the current reading from the input pin
+boolean lastButtonState = HIGH; // the previous reading from the input pin
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
#endif
#ifdef enable_OLED
// Button 1
-boolean buttonVal1 = HIGH; // value read from button
-boolean buttonLast1 = HIGH; // buffered value of the button's previous state
-boolean DCwaiting1 = false; // whether we're waiting for a double click (down)
-boolean DConUp1 = false; // whether to register a double click on next release, or whether to wait and click
-boolean singleOK1 = true; // whether it's OK to do a single click
-long downTime1 = -1; // time the button was pressed down
-long upTime1 = -1; // time the button was released
-boolean ignoreUp1 = false; // whether to ignore the button release because the click+hold was triggered
-boolean waitForUp1 = false; // when held, whether to wait for the up event
-boolean holdEventPast1 = false; // whether or not the hold event happened already
-boolean longholdEventPast1 = false;// whether or not the long hold event happened already
+boolean buttonVal1 = HIGH; // value read from button
+boolean buttonLast1 = HIGH; // buffered value of the button's previous state
+boolean DCwaiting1 = false; // whether we're waiting for a double click (down)
+boolean DConUp1 = false; // whether to register a double click on next release, or whether to wait and click
+boolean singleOK1 = true; // whether it's OK to do a single click
+long downTime1 = -1; // time the button was pressed down
+long upTime1 = -1; // time the button was released
+boolean ignoreUp1 = false; // whether to ignore the button release because the click+hold was triggered
+boolean waitForUp1 = false; // when held, whether to wait for the up event
+boolean holdEventPast1 = false; // whether or not the hold event happened already
+boolean longholdEventPast1 = false; // whether or not the long hold event happened already
// Button 2
-boolean buttonVal2 = HIGH; // value read from button
-boolean buttonLast2 = HIGH; // buffered value of the button's previous state
-boolean DCwaiting2 = false; // whether we're waiting for a double click (down)
-boolean DConUp2 = false; // whether to register a double click on next release, or whether to wait and click
-boolean singleOK2 = true; // whether it's OK to do a single click
-long downTime2 = -1; // time the button was pressed down
-long upTime2 = -1; // time the button was released
-boolean ignoreUp2 = false; // whether to ignore the button release because the click+hold was triggered
-boolean waitForUp2 = false; // when held, whether to wait for the up event
-boolean holdEventPast2 = false; // whether or not the hold event happened already
-boolean longholdEventPast2 = false;// whether or not the long hold event happened already
+boolean buttonVal2 = HIGH; // value read from button
+boolean buttonLast2 = HIGH; // buffered value of the button's previous state
+boolean DCwaiting2 = false; // whether we're waiting for a double click (down)
+boolean DConUp2 = false; // whether to register a double click on next release, or whether to wait and click
+boolean singleOK2 = true; // whether it's OK to do a single click
+long downTime2 = -1; // time the button was pressed down
+long upTime2 = -1; // time the button was released
+boolean ignoreUp2 = false; // whether to ignore the button release because the click+hold was triggered
+boolean waitForUp2 = false; // when held, whether to wait for the up event
+boolean holdEventPast2 = false; // whether or not the hold event happened already
+boolean longholdEventPast2 = false; // whether or not the long hold event happened already
#endif
#ifdef enable_serial
@@ -404,7 +404,7 @@ byte sdBuffer[512];
// soft reset Arduino: jumps to 0
// using the watchdog timer would be more elegant but some Mega2560 bootloaders are buggy with it
-void(*resetArduino) (void) = 0;
+void (*resetArduino)(void) = 0;
// Progressbar
void draw_progressbar(uint32_t processedsize, uint32_t totalsize);
@@ -413,7 +413,7 @@ void draw_progressbar(uint32_t processedsize, uint32_t totalsize);
byte eepbit[8];
byte eeptemp;
-#ifdef no-intro
+#ifdef nointro
// Array to hold iNES header
byte iNES_HEADER[16];
//ID 0-3
@@ -435,49 +435,49 @@ byte iNES_HEADER[16];
//******************************************
// CRC32 lookup table // 256 entries
static const uint32_t crc_32_tab[] PROGMEM = { /* CRC polynomial 0xedb88320 */
- 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
- 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
- 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
- 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
- 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
- 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
- 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
- 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
- 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
- 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
- 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
- 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
- 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
- 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
- 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
- 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
- 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
- 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
- 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
- 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
- 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
- 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
- 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
- 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
- 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
- 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
- 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
- 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
- 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
- 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
- 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
- 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
- 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
- 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
- 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
- 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
- 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
- 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
- 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
- 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
- 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
- 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
- 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
+ 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
+ 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
+ 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
+ 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
+ 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
+ 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
+ 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
+ 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
+ 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
+ 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
+ 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
+ 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
+ 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
+ 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
+ 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
+ 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
+ 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
+ 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
+ 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
+ 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
+ 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
+ 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
+ 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
+ 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
+ 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
+ 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
+ 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
+ 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
+ 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
+ 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
+ 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
+ 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
+ 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
+ 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
+ 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
+ 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
+ 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
+ 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
+ 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
+ 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
+ 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
+ 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
+ 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
};
inline uint32_t updateCRC(uint8_t ch, uint32_t crc) {
@@ -506,8 +506,7 @@ uint32_t calculateCRC(char* fileName, char* folder, int offset) {
// Close the file:
myFile.close();
return ~oldcrc32;
- }
- else {
+ } else {
display_Clear();
print_Msg(F("File "));
//print_Msg(folder);
@@ -521,39 +520,33 @@ uint32_t calculateCRC(char* fileName, char* folder, int offset) {
// Functions for CRC32 database
//******************************************
//Skip line
-void skip_line(FsFile* readfile)
-{
+void skip_line(FsFile* readfile) {
int i = 0;
char str_buf;
- while (readfile->available())
- {
+ while (readfile->available()) {
//Read 1 byte from file
str_buf = readfile->read();
//if end of file or newline found, execute command
- if (str_buf == '\r')
- {
- readfile->read(); //dispose \n because \r\n
+ if (str_buf == '\r') {
+ readfile->read(); //dispose \n because \r\n
break;
}
i++;
- }//End while
+ } //End while
}
//Get line from file
-void get_line(char* str_buf, FsFile* readfile, uint8_t maxi)
-{
+void get_line(char* str_buf, FsFile* readfile, uint8_t maxi) {
// Status LED on
statusLED(true);
int i = 0;
- while (readfile->available())
- {
+ while (readfile->available()) {
//If line size is more than maximum array, limit it.
- if (i >= maxi)
- {
+ if (i >= maxi) {
i = maxi - 1;
}
@@ -561,19 +554,18 @@ void get_line(char* str_buf, FsFile* readfile, uint8_t maxi)
str_buf[i] = readfile->read();
//if end of file or newline found, execute command
- if (str_buf[i] == '\r')
- {
+ if (str_buf[i] == '\r') {
str_buf[i] = '\0';
- readfile->read(); //dispose \n because \r\n
+ readfile->read(); //dispose \n because \r\n
break;
}
i++;
- }//End while
+ } //End while
}
// Calculate CRC32 if needed and compare it to CRC read from database
boolean compareCRC(char* database, char* crcString, boolean renamerom, int offset) {
-#ifdef no-intro
+#ifdef nointro
char crcStr[9];
if (crcString == 0) {
//go to root
@@ -582,8 +574,7 @@ boolean compareCRC(char* database, char* crcString, boolean renamerom, int offse
print_Msg(F("CRC32... "));
display_Update();
sprintf(crcStr, "%08lX", calculateCRC(fileName, folder, offset));
- }
- else {
+ } else {
// Use precalculated crc
print_Msg(F("CRC32... "));
display_Update();
@@ -605,11 +596,10 @@ boolean compareCRC(char* database, char* crcString, boolean renamerom, int offse
//Read 2 lines (game name and CRC)
get_line(gamename, &myFile, 96);
get_line(crc_search, &myFile, 9);
- skip_line(&myFile); //Skip every 3rd line
+ skip_line(&myFile); //Skip every 3rd line
//if checksum search successful, rename the file and end search
- if (strcmp(crc_search, crcStr) == 0)
- {
+ if (strcmp(crc_search, crcStr) == 0) {
#ifdef enable_NES
if ((mode == mode_NES) && (offset != 0)) {
// Rewind to iNES Header
@@ -653,7 +643,7 @@ boolean compareCRC(char* database, char* crcString, boolean renamerom, int offse
if (renamerom) {
println_Msg(gamename);
- // Rename file to no-intro
+ // Rename file to nointro
sd.chdir(folder);
delay(100);
if (myFile.open(fileName, O_READ)) {
@@ -661,21 +651,18 @@ boolean compareCRC(char* database, char* crcString, boolean renamerom, int offse
// Close the file:
myFile.close();
}
- }
- else {
+ } else {
println_Msg("OK");
}
return 1;
break;
}
}
- if (strcmp(crc_search, crcStr) != 0)
- {
+ if (strcmp(crc_search, crcStr) != 0) {
println_Msg(F(" -> Not found"));
return 0;
}
- }
- else {
+ } else {
println_Msg(F(" -> Error"));
println_Msg(F("Database missing"));
return 0;
@@ -712,16 +699,14 @@ byte starting_letter() {
while (1) {
int b = checkButton();
- if (b == 2) { // Previous
+ if (b == 2) { // Previous
if ((selection == 0) && (line > 0)) {
line--;
selection = 6;
- }
- else if ((selection == 0) && (line == 0)) {
+ } else if ((selection == 0) && (line == 0)) {
line = 3;
selection = 6;
- }
- else if (selection > 0) {
+ } else if (selection > 0) {
selection--;
}
display.setDrawColor(0);
@@ -735,16 +720,14 @@ byte starting_letter() {
}
- else if (b == 1) { // Next
+ else if (b == 1) { // Next
if ((selection == 6) && (line < 3)) {
line++;
selection = 0;
- }
- else if ((selection == 6) && (line == 3)) {
+ } else if ((selection == 6) && (line == 3)) {
line = 0;
selection = 0;
- }
- else if (selection < 6) {
+ } else if (selection < 6) {
selection++;
}
display.setDrawColor(0);
@@ -757,7 +740,7 @@ byte starting_letter() {
display_Update();
}
- else if (b == 3) { // Long Press - Execute
+ else if (b == 3) { // Long Press - Execute
if ((selection + line * 7) != 27) {
display_Clear();
println_Msg(F("Please wait..."));
@@ -804,7 +787,7 @@ static const char modeItem13[] PROGMEM = "Watara Supervision";
static const char modeItem14[] PROGMEM = "Pocket Challenge W";
static const char modeItem15[] PROGMEM = "Flashrom Programmer";
static const char modeItem16[] PROGMEM = "About";
-static const char* const modeOptions[] PROGMEM = {modeItem1, modeItem2, modeItem3, modeItem4, modeItem5, modeItem6, modeItem7, modeItem8, modeItem9, modeItem10, modeItem11, modeItem12, modeItem13, modeItem14, modeItem15, modeItem16};
+static const char* const modeOptions[] PROGMEM = { modeItem1, modeItem2, modeItem3, modeItem4, modeItem5, modeItem6, modeItem7, modeItem8, modeItem9, modeItem10, modeItem11, modeItem12, modeItem13, modeItem14, modeItem15, modeItem16 };
// All included slots
void mainMenu() {
@@ -843,8 +826,7 @@ void mainMenu() {
currPage = 1;
// wait for user choice to come back from the question box menu
- switch (modeMenu)
- {
+ switch (modeMenu) {
#ifdef enable_GBX
case 0:
gbxMenu();
@@ -857,7 +839,7 @@ void mainMenu() {
display_Clear();
display_Update();
setup_NES();
-#ifdef no-intro
+#ifdef nointro
if (getMapping() == 0) {
selectMapping();
}
@@ -992,14 +974,14 @@ static const char modeItem4[] PROGMEM = "Nintendo 64(3V EEP)";
static const char modeItem5[] PROGMEM = "Game Boy";
static const char modeItem6[] PROGMEM = "About";
static const char modeItem7[] PROGMEM = "Reset";
-static const char* const modeOptions[] PROGMEM = {modeItem1, modeItem2, modeItem3, modeItem4, modeItem5, modeItem6, modeItem7};
+static const char* const modeOptions[] PROGMEM = { modeItem1, modeItem2, modeItem3, modeItem4, modeItem5, modeItem6, modeItem7 };
// Add-ons submenu
static const char addonsItem1[] PROGMEM = "Consoles";
static const char addonsItem2[] PROGMEM = "Handhelds";
static const char addonsItem3[] PROGMEM = "Flashrom Programmer";
static const char addonsItem4[] PROGMEM = "Reset";
-static const char* const addonsOptions[] PROGMEM = {addonsItem1, addonsItem2, addonsItem3, addonsItem4};
+static const char* const addonsOptions[] PROGMEM = { addonsItem1, addonsItem2, addonsItem3, addonsItem4 };
// Consoles submenu
static const char consolesItem1[] PROGMEM = "NES/Famicom";
@@ -1008,7 +990,7 @@ static const char consolesItem3[] PROGMEM = "SMS/GG/MIII/SG-1000";
static const char consolesItem4[] PROGMEM = "Intellivision";
static const char consolesItem5[] PROGMEM = "Colecovision";
static const char consolesItem6[] PROGMEM = "Reset";
-static const char* const consolesOptions[] PROGMEM = {consolesItem1, consolesItem2, consolesItem3, consolesItem4, consolesItem5, consolesItem6};
+static const char* const consolesOptions[] PROGMEM = { consolesItem1, consolesItem2, consolesItem3, consolesItem4, consolesItem5, consolesItem6 };
// Handhelds submenu
static const char handheldsItem1[] PROGMEM = "Virtual Boy";
@@ -1017,7 +999,7 @@ static const char handheldsItem3[] PROGMEM = "NeoGeo Pocket";
static const char handheldsItem4[] PROGMEM = "Watara Supervision";
static const char handheldsItem5[] PROGMEM = "Pocket Challenge W";
static const char handheldsItem6[] PROGMEM = "Reset";
-static const char* const handheldsOptions[] PROGMEM = {handheldsItem1, handheldsItem2, handheldsItem3, handheldsItem4, handheldsItem5, handheldsItem6};
+static const char* const handheldsOptions[] PROGMEM = { handheldsItem1, handheldsItem2, handheldsItem3, handheldsItem4, handheldsItem5, handheldsItem6 };
// All included slots
void mainMenu() {
@@ -1028,8 +1010,7 @@ void mainMenu() {
modeMenu = question_box(F("OPENSOURCE CARTREADER"), menuOptions, 7, 0);
// wait for user choice to come back from the question box menu
- switch (modeMenu)
- {
+ switch (modeMenu) {
case 0:
addonMenu();
break;
@@ -1077,8 +1058,7 @@ void addonMenu() {
addonsMenu = question_box(F("Type"), menuOptions, 4, 0);
// wait for user choice to come back from the question box menu
- switch (addonsMenu)
- {
+ switch (addonsMenu) {
// Consoles
case 0:
consoleMenu();
@@ -1116,15 +1096,14 @@ void consoleMenu() {
consolesMenu = question_box(F("Choose Adapter"), menuOptions, 6, 0);
// wait for user choice to come back from the question box menu
- switch (consolesMenu)
- {
+ switch (consolesMenu) {
#ifdef enable_NES
case 0:
mode = mode_NES;
display_Clear();
display_Update();
setup_NES();
-#ifdef no-intro
+#ifdef nointro
if (getMapping() == 0) {
selectMapping();
}
@@ -1181,8 +1160,7 @@ void handheldMenu() {
handheldsMenu = question_box(F("Choose Adapter"), menuOptions, 6, 0);
// wait for user choice to come back from the question box menu
- switch (handheldsMenu)
- {
+ switch (handheldsMenu) {
#ifdef enable_VBOY
case 0:
setup_VBOY();
@@ -1311,8 +1289,7 @@ void draw_progressbar(uint32_t processed, uint32_t total) {
if (i == (19)) {
//If end of progress bar, finish progress bar by drawing "]"
println_Msg(F("]"));
- }
- else {
+ } else {
print_Msg(F("*"));
}
}
@@ -1332,7 +1309,7 @@ RTC_DS3231 rtc;
// Start Time
void RTCStart() {
// Start RTC
- if (! rtc.begin()) {
+ if (!rtc.begin()) {
abort();
}
@@ -1385,7 +1362,7 @@ int32_t cal_factor = 0;
int32_t old_cal = 0;
int32_t cal_offset = 100;
-void clkcal() {
+void clkcal() {
// Adafruit Clock Generator
// last number is the clock correction factor which is custom for each clock generator
cal_factor = readClockOffset();
@@ -1424,8 +1401,7 @@ void clkcal() {
// Frequency Counter
delay(500);
FreqCount.begin(1000);
- while (1)
- {
+ while (1) {
if (old_cal != cal_factor) {
display_Clear();
println_Msg(F(""));
@@ -1444,8 +1420,7 @@ void clkcal() {
clockgen.set_freq(307200000ULL, SI5351_CLK2);
old_cal = cal_factor;
delay(500);
- }
- else {
+ } else {
clockgen.update_status();
while (clockgen.dev_status.SYS_INIT == 1) {
}
@@ -1493,15 +1468,13 @@ void clkcal() {
// if the cart readers input buttons is double clicked
if (a == 2) {
cal_offset /= 10ULL;
- if (cal_offset < 1)
- {
+ if (cal_offset < 1) {
cal_offset = 100000000ULL;
}
}
if (b == 2) {
cal_offset *= 10ULL;
- if (cal_offset > 100000000ULL)
- {
+ if (cal_offset > 100000000ULL) {
cal_offset = 1;
}
}
@@ -1517,7 +1490,7 @@ void clkcal() {
//Handle inputs for either rotary encoder or single button interface.
int a = checkButton();
- if (a == 1) { //clockwise rotation or single click
+ if (a == 1) { //clockwise rotation or single click
old_cal = cal_factor;
cal_factor += cal_offset;
}
@@ -1527,15 +1500,14 @@ void clkcal() {
cal_factor -= cal_offset;
}
- if (a == 3) { //button short hold
+ if (a == 3) { //button short hold
cal_offset *= 10ULL;
- if (cal_offset > 100000000ULL)
- {
+ if (cal_offset > 100000000ULL) {
cal_offset = 1;
}
}
- if (a == 4) { //button long hold
+ if (a == 4) { //button long hold
savetofile();
}
#endif
@@ -1543,8 +1515,7 @@ void clkcal() {
}
}
-void print_right(int32_t number)
-{
+void print_right(int32_t number) {
int32_t abs_number = number;
if (abs_number < 0)
abs_number *= -1;
@@ -1553,8 +1524,7 @@ void print_right(int32_t number)
if (abs_number == 0)
abs_number = 1;
- while (abs_number < 100000000ULL)
- {
+ while (abs_number < 100000000ULL) {
print_Msg(F(" "));
abs_number *= 10ULL;
}
@@ -1661,7 +1631,7 @@ int32_t readClockOffset() {
int32_t initializeClockOffset() {
#ifdef clockgen_calibration
FsFile clock_file;
- const char zero_char_arr[] = {'0'};
+ const char zero_char_arr[] = { '0' };
int32_t clock_offset = readClockOffset();
if (clock_offset > INT32_MIN) {
i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, clock_offset);
@@ -1731,9 +1701,9 @@ void setup() {
digitalWrite(10, 1);
#endif
// Configure 4 Pin RGB LED pins as output
- DDRB |= (1 << DDB6); // Red LED (pin 12)
- DDRB |= (1 << DDB5); // Green LED (pin 11)
- DDRB |= (1 << DDB4); // Blue LED (pin 10)
+ DDRB |= (1 << DDB6); // Red LED (pin 12)
+ DDRB |= (1 << DDB5); // Green LED (pin 11)
+ DDRB |= (1 << DDB4); // Blue LED (pin 10)
#endif
#endif
@@ -1854,7 +1824,7 @@ void convertPgm(const char* const pgmOptions[], byte numArrays) {
}
}
-void print_Error(const __FlashStringHelper * errorMessage, boolean forceReset) {
+void print_Error(const __FlashStringHelper* errorMessage, boolean forceReset) {
errorLvl = 1;
setColor_RGB(255, 0, 0);
println_Msg(errorMessage);
@@ -1867,8 +1837,7 @@ void print_Error(const __FlashStringHelper * errorMessage, boolean forceReset) {
wait();
if (ignoreError == 0) {
resetArduino();
- }
- else {
+ } else {
ignoreError = 0;
display_Clear();
println_Msg(F(""));
@@ -1885,9 +1854,9 @@ void wait() {
statusLED(false);
#if defined(enable_LCD)
wait_btn();
-#elif defined (enable_OLED)
+#elif defined(enable_OLED)
wait_btn();
-#elif defined (enable_serial)
+#elif defined(enable_serial)
wait_serial();
#endif
}
@@ -1911,8 +1880,7 @@ void save_log() {
if (tempStr[0] == '\r') {
// skip \n
myLog.read();
- }
- else {
+ } else {
// Read more lines
tempStr[1] = myLog.read();
tempStr[2] = myLog.read();
@@ -1925,9 +1893,8 @@ void save_log() {
str_buf = myLog.read();
//break out of loop if CRLF is found
- if (str_buf == '\r')
- {
- myLog.read(); //dispose \n because \r\n
+ if (str_buf == '\r') {
+ myLog.read(); //dispose \n because \r\n
break;
}
}
@@ -1958,8 +1925,7 @@ void save_log() {
sdBuffer[i] = myLog.read();
}
myFile.write(sdBuffer, 512);
- }
- else {
+ } else {
word i = 0;
for (i = 0; i < myLog.available(); i++) {
sdBuffer[i] = myLog.read();
@@ -1973,12 +1939,12 @@ void save_log() {
#endif
#ifdef global_log
-void println_Log(const __FlashStringHelper * string) {
+void println_Log(const __FlashStringHelper* string) {
myLog.println(string);
}
#endif
-void print_Msg(const __FlashStringHelper * string) {
+void print_Msg(const __FlashStringHelper* string) {
#if (defined(enable_LCD) || defined(enable_OLED))
display.print(string);
#endif
@@ -1986,7 +1952,7 @@ void print_Msg(const __FlashStringHelper * string) {
Serial.print(string);
#endif
#ifdef global_log
- if (!dont_log)myLog.print(string);
+ if (!dont_log) myLog.print(string);
#endif
}
@@ -2007,8 +1973,7 @@ void print_Msg(const char myString[]) {
display.print(myString[strPos]);
strPos++;
}
- }
- else {
+ } else {
display.print(myString);
}
#endif
@@ -2016,7 +1981,7 @@ void print_Msg(const char myString[]) {
Serial.print(myString);
#endif
#ifdef global_log
- if (!dont_log)myLog.print(myString);
+ if (!dont_log) myLog.print(myString);
#endif
}
@@ -2028,7 +1993,7 @@ void print_Msg(long unsigned int message) {
Serial.print(message);
#endif
#ifdef global_log
- if (!dont_log)myLog.print(message);
+ if (!dont_log) myLog.print(message);
#endif
}
@@ -2040,7 +2005,7 @@ void print_Msg(byte message, int outputFormat) {
Serial.print(message, outputFormat);
#endif
#ifdef global_log
- if (!dont_log)myLog.print(message, outputFormat);
+ if (!dont_log) myLog.print(message, outputFormat);
#endif
}
@@ -2052,7 +2017,7 @@ void print_Msg(word message, int outputFormat) {
Serial.print(message, outputFormat);
#endif
#ifdef global_log
- if (!dont_log)myLog.print(message, outputFormat);
+ if (!dont_log) myLog.print(message, outputFormat);
#endif
}
@@ -2064,7 +2029,7 @@ void print_Msg(int message, int outputFormat) {
Serial.print(message, outputFormat);
#endif
#ifdef global_log
- if (!dont_log)myLog.print(message, outputFormat);
+ if (!dont_log) myLog.print(message, outputFormat);
#endif
}
@@ -2076,7 +2041,7 @@ void print_Msg(long unsigned int message, int outputFormat) {
Serial.print(message, outputFormat);
#endif
#ifdef global_log
- if (!dont_log)myLog.print(message, outputFormat);
+ if (!dont_log) myLog.print(message, outputFormat);
#endif
}
@@ -2088,7 +2053,7 @@ void print_Msg(String string) {
Serial.print(string);
#endif
#ifdef global_log
- if (!dont_log)myLog.print(string);
+ if (!dont_log) myLog.print(string);
#endif
}
@@ -2098,15 +2063,15 @@ void print_Msg_PaddedHexByte(byte message) {
}
void print_Msg_PaddedHex16(word message) {
- print_Msg_PaddedHexByte((message >> 8) & 0xFF);
- print_Msg_PaddedHexByte((message >> 0) & 0xFF);
+ print_Msg_PaddedHexByte((message >> 8) & 0xFF);
+ print_Msg_PaddedHexByte((message >> 0) & 0xFF);
}
void print_Msg_PaddedHex32(unsigned long message) {
print_Msg_PaddedHexByte((message >> 24) & 0xFF);
print_Msg_PaddedHexByte((message >> 16) & 0xFF);
- print_Msg_PaddedHexByte((message >> 8) & 0xFF);
- print_Msg_PaddedHexByte((message >> 0) & 0xFF);
+ print_Msg_PaddedHexByte((message >> 8) & 0xFF);
+ print_Msg_PaddedHexByte((message >> 0) & 0xFF);
}
void println_Msg(String string) {
#if (defined(enable_LCD) || defined(enable_OLED))
@@ -2117,7 +2082,7 @@ void println_Msg(String string) {
Serial.println(string);
#endif
#ifdef global_log
- if (!dont_log)myLog.println(string);
+ if (!dont_log) myLog.println(string);
#endif
}
@@ -2130,7 +2095,7 @@ void println_Msg(byte message, int outputFormat) {
Serial.println(message, outputFormat);
#endif
#ifdef global_log
- if (!dont_log)myLog.println(message, outputFormat);
+ if (!dont_log) myLog.println(message, outputFormat);
#endif
}
@@ -2151,8 +2116,7 @@ void println_Msg(const char myString[]) {
display.print(myString[strPos]);
strPos++;
}
- }
- else {
+ } else {
display.print(myString);
}
display.setCursor(0, display.ty + 8);
@@ -2161,11 +2125,11 @@ void println_Msg(const char myString[]) {
Serial.println(myString);
#endif
#ifdef global_log
- if (!dont_log)myLog.println(myString);
+ if (!dont_log) myLog.println(myString);
#endif
}
-void println_Msg(const __FlashStringHelper * string) {
+void println_Msg(const __FlashStringHelper* string) {
#if (defined(enable_LCD) || defined(enable_OLED))
display.print(string);
display.setCursor(0, display.ty + 8);
@@ -2175,9 +2139,9 @@ void println_Msg(const __FlashStringHelper * string) {
#endif
#ifdef global_log
char myBuffer[15];
- strlcpy_P(myBuffer, (char *)string, 15);
+ strlcpy_P(myBuffer, (char*)string, 15);
if ((strncmp(myBuffer, "Press Button...", 14) != 0) && (strncmp(myBuffer, "Select file", 10) != 0)) {
- if (!dont_log)myLog.println(string);
+ if (!dont_log) myLog.println(string);
}
#endif
}
@@ -2191,7 +2155,7 @@ void println_Msg(long unsigned int message) {
Serial.println(message);
#endif
#ifdef global_log
- if (!dont_log)myLog.println(message);
+ if (!dont_log) myLog.println(message);
#endif
}
@@ -2203,7 +2167,7 @@ void display_Update() {
delay(100);
#endif
#ifdef global_log
- if (!dont_log)myLog.flush();
+ if (!dont_log) myLog.flush();
#endif
}
@@ -2213,7 +2177,7 @@ void display_Clear() {
display.setCursor(0, 8);
#endif
#ifdef global_log
- if (!dont_log)myLog.println("");
+ if (!dont_log) myLog.println("");
#endif
}
@@ -2276,7 +2240,7 @@ void statusLED(boolean on) {
PORTD |= (1 << 7);
else
PORTD &= ~(1 << 7);
- /*
+ /*
#elif defined(enable_OLED)
if (!on)
PORTB |= (1 << 4);
@@ -2305,7 +2269,7 @@ void statusLED(boolean on) {
/******************************************
Menu system
*****************************************/
-unsigned char question_box(const __FlashStringHelper * question, char answers[7][20], int num_answers, int default_choice) {
+unsigned char question_box(const __FlashStringHelper* question, char answers[7][20], int num_answers, int default_choice) {
#if (defined(enable_LCD) || defined(enable_OLED))
return questionBox_Display(question, answers, num_answers, default_choice);
#endif
@@ -2316,7 +2280,7 @@ unsigned char question_box(const __FlashStringHelper * question, char answers[7]
#if defined(enable_serial)
// Serial Monitor
-byte questionBox_Serial(const __FlashStringHelper * question, char answers[7][20], int num_answers, int default_choice) {
+byte questionBox_Serial(const __FlashStringHelper* question, char answers[7][20], int num_answers, int default_choice) {
// Print menu to serial monitor
//Serial.println(question);
Serial.println("");
@@ -2379,8 +2343,7 @@ byte questionBox_Serial(const __FlashStringHelper * question, char answers[7][20
if (currPage > 1) {
lastPage = currPage;
currPage--;
- }
- else {
+ } else {
root = 1;
}
}
@@ -2404,7 +2367,7 @@ byte questionBox_Serial(const __FlashStringHelper * question, char answers[7][20
// OLED & LCD
#if (defined(enable_LCD) || defined(enable_OLED))
// Display a question box with selectable answers. Make sure default choice is in (0, num_answers]
-unsigned char questionBox_Display(const __FlashStringHelper * question, char answers[7][20], int num_answers, int default_choice) {
+unsigned char questionBox_Display(const __FlashStringHelper* question, char answers[7][20], int num_answers, int default_choice) {
//clear the screen
display.clearDisplay();
display.updateDisplay();
@@ -2444,10 +2407,9 @@ unsigned char questionBox_Display(const __FlashStringHelper * question, char ans
if (currentColor < 7) {
currentColor++;
if (currentColor == 1) {
- currentColor = 2; // skip red as that signifies an error to the user
+ currentColor = 2; // skip red as that signifies an error to the user
}
- }
- else {
+ } else {
currentColor = 0;
}
}
@@ -2476,16 +2438,13 @@ unsigned char questionBox_Display(const __FlashStringHelper * question, char ans
lastPage = currPage;
currPage--;
break;
- }
- else if (filebrowse == 1) {
+ } else if (filebrowse == 1) {
root = 1;
break;
}
- }
- else if (choice > 0) {
+ } else if (choice > 0) {
choice--;
- }
- else {
+ } else {
choice = num_answers - 1;
}
@@ -2507,12 +2466,11 @@ unsigned char questionBox_Display(const __FlashStringHelper * question, char ans
display.setDrawColor(1);
display.updateDisplay();
- if ((choice == num_answers - 1 ) && (numPages > currPage)) {
+ if ((choice == num_answers - 1) && (numPages > currPage)) {
lastPage = currPage;
currPage++;
break;
- }
- else
+ } else
choice = (choice + 1) % num_answers;
// draw selection box
@@ -2523,7 +2481,7 @@ unsigned char questionBox_Display(const __FlashStringHelper * question, char ans
rgbLed(choice);
}
- // if the Cart Dumpers button is hold continiously leave the menu
+ // if the Cart Readers button is hold continiously leave the menu
// so the currently highlighted action can be executed
if (b == 3) {
@@ -2663,7 +2621,7 @@ int checkButton1() {
}
}
// Test for normal click event: DCgap expired
- if ( buttonVal1 == HIGH && (millis() - upTime1) >= DCgap && DCwaiting1 == true && DConUp1 == false && singleOK1 == true) {
+ if (buttonVal1 == HIGH && (millis() - upTime1) >= DCgap && DCwaiting1 == true && DConUp1 == false && singleOK1 == true) {
event = 1;
DCwaiting1 = false;
}
@@ -2723,7 +2681,7 @@ int checkButton2() {
}
}
// Test for normal click event: DCgap expired
- if ( buttonVal2 == HIGH && (millis() - upTime2) >= DCgap && DCwaiting2 == true && DConUp2 == false && singleOK2 == true) {
+ if (buttonVal2 == HIGH && (millis() - upTime2) >= DCgap && DCwaiting2 == true && DConUp2 == false && singleOK2 == true) {
event = 1;
DCwaiting2 = false;
}
@@ -2757,8 +2715,7 @@ void wait_btn() {
if (errorLvl == 0)
rgbLed(green_color);
- while (1)
- {
+ while (1) {
// get input button
int b = checkButton();
@@ -2808,16 +2765,13 @@ int checkButton() {
if (rotaryDir == 1) {
rotaryPos = newPos;
return 1;
- }
- else if (rotaryDir == -1) {
+ } else if (rotaryDir == -1) {
rotaryPos = newPos;
return 2;
- }
- else {
+ } else {
return 0;
}
- }
- else if (reading == buttonState) {
+ } else if (reading == buttonState) {
return 0;
}
// Check if button has changed
@@ -2833,7 +2787,8 @@ int checkButton() {
if (buttonState == 0) {
unsigned long pushTime = millis();
// Wait until button was let go again
- while ((PING & (1 << PING2)) >> PING2 == 0);
+ while ((PING & (1 << PING2)) >> PING2 == 0)
+ ;
lastButtonState = reading;
// If the hold time was over 10 seconds, super long press for resetting eeprom in about screen
@@ -2845,13 +2800,11 @@ int checkButton() {
return 3;
}
}
- }
- else {
+ } else {
lastButtonState = reading;
return 0;
}
- }
- else {
+ } else {
lastButtonState = reading;
return 0;
}
@@ -2864,8 +2817,7 @@ void wait_btn() {
if (errorLvl == 0)
rgbLed(green_color);
- while (1)
- {
+ while (1) {
// get input button
int b = checkButton();
@@ -2904,8 +2856,7 @@ void wait_encoder() {
if (errorLvl == 0)
rgbLed(green_color);
- while (1)
- {
+ while (1) {
// Get rotary encoder
encoder.tick();
int newPos = encoder.getPosition();
@@ -2931,7 +2882,7 @@ void wait_encoder() {
/******************************************
Filebrowser Module
*****************************************/
-void fileBrowser(const __FlashStringHelper * browserTitle) {
+void fileBrowser(const __FlashStringHelper* browserTitle) {
char fileNames[7][FILENAME_LENGTH];
int currFile;
filebrowse = 1;
@@ -3055,9 +3006,9 @@ page:
}
myDir.close();
- for (byte i = 0; i < 8; i++ ) {
+ for (byte i = 0; i < 8; i++) {
// Copy short string into fileOptions
- snprintf( answers[i], FILEOPTS_LENGTH, "%s", fileNames[i] );
+ snprintf(answers[i], FILEOPTS_LENGTH, "%s", fileNames[i]);
}
// Create menu with title and 1-7 options to choose from
@@ -3081,8 +3032,7 @@ page:
}
// wait for user choice to come back from the question box menu
- switch (answer)
- {
+ switch (answer) {
case 0:
strncpy(fileName, fileNames[0], FILENAME_LENGTH - 1);
break;
@@ -3126,8 +3076,7 @@ page:
sd.chdir(dirName);
// Start browser in new directory again
goto browserstart;
- }
- else {
+ } else {
// Afer everything is done change SD working directory back to root
sd.chdir("/");
}
@@ -3141,12 +3090,12 @@ void loop() {
#ifdef enable_N64
if (mode == mode_N64_Controller) {
n64ControllerMenu();
- }
- else if (mode == mode_N64_Cart) {
+ } else if (mode == mode_N64_Cart) {
n64CartMenu();
}
#else
- if (1 == 0) { }
+ if (1 == 0) {
+ }
#endif
#ifdef enable_SNES
else if (mode == mode_SNES) {
@@ -3160,8 +3109,7 @@ void loop() {
#ifdef enable_FLASH16
else if (mode == mode_FLASH16) {
flashromMenu16();
- }
- else if (mode == mode_EPROM) {
+ } else if (mode == mode_EPROM) {
epromMenu();
}
#endif
@@ -3174,8 +3122,7 @@ void loop() {
#ifdef enable_GBX
else if (mode == mode_GB) {
gbMenu();
- }
- else if (mode == mode_GBA) {
+ } else if (mode == mode_GBA) {
gbaMenu();
}
#endif
@@ -3227,11 +3174,9 @@ void loop() {
#ifdef enable_GBX
else if (mode == mode_GB_GBSmart) {
gbSmartMenu();
- }
- else if (mode == mode_GB_GBSmart_Flash) {
+ } else if (mode == mode_GB_GBSmart_Flash) {
gbSmartFlashMenu();
- }
- else if (mode == mode_GB_GBSmart_Game) {
+ } else if (mode == mode_GB_GBSmart_Game) {
gbSmartGameOptions();
}
#endif
@@ -3287,4 +3232,4 @@ void loop() {
//******************************************
// End of File
-//******************************************
+//****************************************** \ No newline at end of file
diff --git a/Cart_Reader/FLASH.ino b/Cart_Reader/FLASH.ino
index fe6db6b..7e815f6 100644
--- a/Cart_Reader/FLASH.ino
+++ b/Cart_Reader/FLASH.ino
@@ -28,7 +28,7 @@ static const char flash8MenuItem4[] PROGMEM = "Write";
static const char flash8MenuItem5[] PROGMEM = "ID";
static const char flash8MenuItem6[] PROGMEM = "Print";
static const char flash8MenuItem7[] PROGMEM = "Reset";
-static const char* const menuOptionsFLASH8[] PROGMEM = {flash8MenuItem1, flash8MenuItem2, flash8MenuItem3, flash8MenuItem4, flash8MenuItem5, flash8MenuItem6, flash8MenuItem7};
+static const char* const menuOptionsFLASH8[] PROGMEM = { flash8MenuItem1, flash8MenuItem2, flash8MenuItem3, flash8MenuItem4, flash8MenuItem5, flash8MenuItem6, flash8MenuItem7 };
#ifdef enable_FLASH16
// Flash start menu
@@ -36,7 +36,7 @@ static const char flashMenuItem1[] PROGMEM = "8bit Flash adapter";
static const char flashMenuItem2[] PROGMEM = "Eprom adapter";
static const char flashMenuItem3[] PROGMEM = "MX26L6420 adapter";
static const char flashMenuItem4[] PROGMEM = "Reset";
-static const char* const menuOptionsFlash[] PROGMEM = {flashMenuItem1, flashMenuItem2, flashMenuItem3, flashMenuItem4};
+static const char* const menuOptionsFlash[] PROGMEM = { flashMenuItem1, flashMenuItem2, flashMenuItem3, flashMenuItem4 };
// 16bit Flash menu items
static const char flash16MenuItem1[] PROGMEM = "Blankcheck";
@@ -46,7 +46,7 @@ static const char flash16MenuItem4[] PROGMEM = "Write";
static const char flash16MenuItem5[] PROGMEM = "ID";
static const char flash16MenuItem6[] PROGMEM = "Print";
static const char flash16MenuItem7[] PROGMEM = "Reset";
-static const char* const menuOptionsFLASH16[] PROGMEM = {flash16MenuItem1, flash16MenuItem2, flash16MenuItem3, flash16MenuItem4, flash16MenuItem5, flash16MenuItem6, flash16MenuItem7};
+static const char* const menuOptionsFLASH16[] PROGMEM = { flash16MenuItem1, flash16MenuItem2, flash16MenuItem3, flash16MenuItem4, flash16MenuItem5, flash16MenuItem6, flash16MenuItem7 };
// Eprom menu items
static const char epromMenuItem1[] PROGMEM = "Blankcheck";
@@ -55,7 +55,7 @@ static const char epromMenuItem3[] PROGMEM = "Write";
static const char epromMenuItem4[] PROGMEM = "Verify";
static const char epromMenuItem5[] PROGMEM = "Print";
static const char epromMenuItem6[] PROGMEM = "Reset";
-static const char* const menuOptionsEprom[] PROGMEM = {epromMenuItem1, epromMenuItem2, epromMenuItem3, epromMenuItem4, epromMenuItem5, epromMenuItem6};
+static const char* const menuOptionsEprom[] PROGMEM = { epromMenuItem1, epromMenuItem2, epromMenuItem3, epromMenuItem4, epromMenuItem5, epromMenuItem6 };
void flashMenu() {
// create menu with title and 3 options to choose from
@@ -65,8 +65,7 @@ void flashMenu() {
flashSlot = question_box(F("Select adapter PCB"), menuOptions, 4, 0);
// wait for user choice to come back from the question box menu
- switch (flashSlot)
- {
+ switch (flashSlot) {
case 0:
display_Clear();
display_Update();
@@ -74,14 +73,14 @@ void flashMenu() {
setup_Flash8();
id_Flash8();
wait();
- mode = mode_FLASH8;
+ mode = mode_FLASH8;
break;
case 1:
display_Clear();
display_Update();
setup_Eprom();
- mode = mode_EPROM;
+ mode = mode_EPROM;
break;
case 2:
@@ -90,7 +89,7 @@ void flashMenu() {
setup_Flash16();
id_Flash16();
wait();
- mode = mode_FLASH16;
+ mode = mode_FLASH16;
break;
case 3:
@@ -108,8 +107,7 @@ void flashromMenu8() {
mainMenu = question_box(F("Flashrom Writer 8"), menuOptions, 7, 0);
// wait for user choice to come back from the question box menu
- switch (mainMenu)
- {
+ switch (mainMenu) {
case 0:
display_Clear();
println_Msg(F("Blankcheck"));
@@ -159,16 +157,12 @@ void flashromMenu8() {
writeFlash29F1601();
else if ((strcmp(flashid, "C2F1") == 0) || (strcmp(flashid, "C2F9") == 0))
writeFlash29F1610();
- else if ((strcmp(flashid, "C2C4") == 0) || (strcmp(flashid, "C249") == 0) ||
- (strcmp(flashid, "C2A7") == 0) || (strcmp(flashid, "C2A8") == 0) ||
- (strcmp(flashid, "C2C9") == 0) || (strcmp(flashid, "C2CB") == 0))
+ else if ((strcmp(flashid, "C2C4") == 0) || (strcmp(flashid, "C249") == 0) || (strcmp(flashid, "C2A7") == 0) || (strcmp(flashid, "C2A8") == 0) || (strcmp(flashid, "C2C9") == 0) || (strcmp(flashid, "C2CB") == 0))
writeFlash29LV640();
else if (strcmp(flashid, "017E") == 0) {
// sector size, write buffer size
writeFlash29GL(sectorSize, bufferSize);
- }
- else if ((strcmp(flashid, "0458") == 0) || (strcmp(flashid, "0158") == 0) ||
- (strcmp(flashid, "01AB") == 0))
+ } else if ((strcmp(flashid, "0458") == 0) || (strcmp(flashid, "0158") == 0) || (strcmp(flashid, "01AB") == 0))
writeFlash29F800();
break;
@@ -242,8 +236,7 @@ void flashromMenu16() {
mainMenu = question_box(F("Flashrom Writer 16"), menuOptions, 7, 0);
// wait for user choice to come back from the question box menu
- switch (mainMenu)
- {
+ switch (mainMenu) {
case 0:
display_Clear();
println_Msg(F("Blankcheck"));
@@ -279,11 +272,9 @@ void flashromMenu16() {
time = millis();
if (strcmp(flashid, "C2F3") == 0) {
writeFlash16_29F1601();
- }
- else if ((strcmp(flashid, "C2C4") == 0) || (strcmp(flashid, "C249") == 0) || (strcmp(flashid, "C2A7") == 0) || (strcmp(flashid, "C2A8") == 0) || (strcmp(flashid, "C2C9") == 0) || (strcmp(flashid, "C2CB") == 0) || (strcmp(flashid, "C2FC") == 0)) {
+ } else if ((strcmp(flashid, "C2C4") == 0) || (strcmp(flashid, "C249") == 0) || (strcmp(flashid, "C2A7") == 0) || (strcmp(flashid, "C2A8") == 0) || (strcmp(flashid, "C2C9") == 0) || (strcmp(flashid, "C2CB") == 0) || (strcmp(flashid, "C2FC") == 0)) {
writeFlash16_29LV640();
- }
- else {
+ } else {
writeFlash16();
}
delay(100);
@@ -338,8 +329,7 @@ void epromMenu() {
mainMenu = question_box(F("Eprom Writer"), menuOptions, 6, 0);
// wait for user choice to come back from the question box menu
- switch (mainMenu)
- {
+ switch (mainMenu) {
case 0:
display_Clear();
println_Msg(F("Blankcheck"));
@@ -419,87 +409,71 @@ idtheflash:
println_Msg(F("MX29F1610 detected"));
flashSize = 2097152;
flashromType = 2;
- }
- else if (strcmp(flashid, "C2F3") == 0) {
+ } else if (strcmp(flashid, "C2F3") == 0) {
println_Msg(F("MX29F1601 detected"));
flashSize = 2097152;
flashromType = 2;
- }
- else if (strcmp(flashid, "C2F9") == 0) {
+ } else if (strcmp(flashid, "C2F9") == 0) {
println_Msg(F("MX29L3211 detected"));
println_Msg(F("ATTENTION 3.3V"));
flashSize = 4194304;
flashromType = 2;
- }
- else if ((strcmp(flashid, "C2C4") == 0) || (strcmp(flashid, "C249") == 0)) {
+ } else if ((strcmp(flashid, "C2C4") == 0) || (strcmp(flashid, "C249") == 0)) {
println_Msg(F("MX29LV160 detected"));
println_Msg(F("ATTENTION 3.3V"));
flashSize = 2097152;
flashromType = 2;
- }
- else if ((strcmp(flashid, "C2A7") == 0) || (strcmp(flashid, "C2A8") == 0)) {
+ } else if ((strcmp(flashid, "C2A7") == 0) || (strcmp(flashid, "C2A8") == 0)) {
println_Msg(F("MX29LV320 detected"));
println_Msg(F("ATTENTION 3.3V"));
flashSize = 4194304;
flashromType = 2;
- }
- else if ((strcmp(flashid, "C2C9") == 0) || (strcmp(flashid, "C2CB") == 0)) {
+ } else if ((strcmp(flashid, "C2C9") == 0) || (strcmp(flashid, "C2CB") == 0)) {
println_Msg(F("MX29LV640 detected"));
println_Msg(F("ATTENTION 3.3V"));
flashSize = 8388608;
flashromType = 2;
- }
- else if (strcmp(flashid, "0141") == 0) {
+ } else if (strcmp(flashid, "0141") == 0) {
println_Msg(F("AM29F032B detected"));
flashSize = 4194304;
flashromType = 1;
- }
- else if (strcmp(flashid, "01AD") == 0) {
+ } else if (strcmp(flashid, "01AD") == 0) {
println_Msg(F("AM29F016B detected"));
flashSize = 2097152;
flashromType = 1;
- }
- else if (strcmp(flashid, "20AD") == 0) {
+ } else if (strcmp(flashid, "20AD") == 0) {
println_Msg(F("AM29F016D detected"));
flashSize = 2097152;
flashromType = 1;
- }
- else if (strcmp(flashid, "04AD") == 0) {
+ } else if (strcmp(flashid, "04AD") == 0) {
println_Msg(F("AM29F016D detected"));
flashSize = 2097152;
flashromType = 1;
- }
- else if (strcmp(flashid, "04D4") == 0) {
+ } else if (strcmp(flashid, "04D4") == 0) {
println_Msg(F("MBM29F033C detected"));
flashSize = 4194304;
flashromType = 1;
- }
- else if (strcmp(flashid, "04D5") == 0) {
+ } else if (strcmp(flashid, "04D5") == 0) {
println_Msg(F("MBM29F080C detected"));
flashSize = 1048576;
flashromType = 1;
- }
- else if (strcmp(flashid, "0458") == 0) {
+ } else if (strcmp(flashid, "0458") == 0) {
println_Msg(F("MBM29F800BA detected"));
flashSize = 1048576;
flashromType = 2;
- }
- else if (strcmp(flashid, "01AB") == 0) {
+ } else if (strcmp(flashid, "01AB") == 0) {
println_Msg(F("AM29F400AB detected"));
flashSize = 131072 * 4;
flashromType = 2;
- }
- else if (strcmp(flashid, "0158") == 0) {
+ } else if (strcmp(flashid, "0158") == 0) {
println_Msg(F("AM29F800BB detected"));
flashSize = 1048576;
flashromType = 2;
- }
- else if (strcmp(flashid, "01A3") == 0) {
+ } else if (strcmp(flashid, "01A3") == 0) {
println_Msg(F("AM29LV033C detected"));
flashSize = 131072 * 32;
flashromType = 1;
- }
- else if (strcmp(flashid, "017E") == 0) {
+ } else if (strcmp(flashid, "017E") == 0) {
// S29GL032M
if (readByte_Flash(28) == 0x1A) {
println_Msg(F("S29GL032M detected"));
@@ -523,8 +497,7 @@ idtheflash:
}
println_Msg(F("ATTENTION 3.3V"));
flashromType = 2;
- }
- else if (strcmp(flashid, "B088") == 0) {
+ } else if (strcmp(flashid, "B088") == 0) {
// LH28F016SUT
println_Msg(F("LH28F016SUT detected"));
println_Msg(F("ATTENTION 3/5 setting"));
@@ -532,10 +505,7 @@ idtheflash:
sectorSize = 65536;
bufferSize = 256;
flashromType = 3;
- }
- else if ((strcmp(flashid, "8916") == 0) ||
- (strcmp(flashid, "8917") == 0) ||
- (strcmp(flashid, "8918") == 0)) {
+ } else if ((strcmp(flashid, "8916") == 0) || (strcmp(flashid, "8917") == 0) || (strcmp(flashid, "8918") == 0)) {
// E28FXXXJ3A
print_Msg(F("E28F"));
@@ -558,15 +528,13 @@ idtheflash:
sectorSize = 131072;
bufferSize = 32;
flashromType = 3;
- }
- else if (secondID == 1) {
+ } else if (secondID == 1) {
// Read ID a second time using a different command (type 1 flashrom)
resetFlash8();
idFlash29F032();
secondID = 2;
goto idtheflash;
- }
- else if (secondID == 2) {
+ } else if (secondID == 2) {
// Backup first ID read-out
strncpy(vendorID, flashid, 5);
@@ -575,8 +543,7 @@ idtheflash:
idFlash29F1610();
secondID = 0;
goto idtheflash;
- }
- else {
+ } else {
// ID not found
display_Clear();
println_Msg(F("Flashrom Writer 8bit"));
@@ -624,43 +591,36 @@ void id_Flash16() {
println_Msg("");
flashSize = 2097152;
flashromType = 2;
- }
- else if (strcmp(flashid, "C2F3") == 0) {
+ } else if (strcmp(flashid, "C2F3") == 0) {
println_Msg(F("MX29F1601 detected"));
flashSize = 2097152;
flashromType = 2;
- }
- else if (strcmp(flashid, "C2F9") == 0) {
+ } else if (strcmp(flashid, "C2F9") == 0) {
println_Msg(F("MX29L3211 detected"));
println_Msg(F("ATTENTION 3.3V"));
flashSize = 4194304;
flashromType = 2;
- }
- else if ((strcmp(flashid, "C2C4") == 0) || (strcmp(flashid, "C249") == 0)) {
+ } else if ((strcmp(flashid, "C2C4") == 0) || (strcmp(flashid, "C249") == 0)) {
println_Msg(F("MX29LV160 detected"));
println_Msg(F("ATTENTION 3.3V"));
flashSize = 2097152;
flashromType = 2;
- }
- else if ((strcmp(flashid, "C2A7") == 0) || (strcmp(flashid, "C2A8") == 0)) {
+ } else if ((strcmp(flashid, "C2A7") == 0) || (strcmp(flashid, "C2A8") == 0)) {
println_Msg(F("MX29LV320 detected"));
println_Msg(F("ATTENTION 3.3V"));
flashSize = 4194304;
flashromType = 2;
- }
- else if ((strcmp(flashid, "C2C9") == 0) || (strcmp(flashid, "C2CB") == 0)) {
+ } else if ((strcmp(flashid, "C2C9") == 0) || (strcmp(flashid, "C2CB") == 0)) {
println_Msg(F("MX29LV640 detected"));
println_Msg(F("ATTENTION 3.3V"));
flashSize = 8388608;
flashromType = 2;
- }
- else if (strcmp(flashid, "C2FC") == 0) {
+ } else if (strcmp(flashid, "C2FC") == 0) {
println_Msg(F("MX26L6420 detected"));
println_Msg(F("ATTENTION 3.3V"));
flashSize = 8388608;
flashromType = 2;
- }
- else {
+ } else {
print_Error(F("Unknown flashrom"), true);
println_Msg("");
}
@@ -683,7 +643,7 @@ void setup_Flash8() {
DDRL = 0xFF;
// Set Control Pins to Output RST(PH0) OE(PH1) OE_SNS(PH3) WE(PH4) WE_SNS(PH5) CE(PH6)
- DDRH |= (1 << 0) | (1 << 1) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6);
+ DDRH |= (1 << 0) | (1 << 1) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6);
// Setting RST(PH0) OE(PH1) OE_SNS(PH3) WE(PH4) WE_SNS(PH5) HIGH
PORTH |= (1 << 0) | (1 << 1) | (1 << 3) | (1 << 4) | (1 << 5);
// Setting CE(PH6) LOW
@@ -819,10 +779,9 @@ void writeByte_Flash(unsigned long myAddress, byte myData) {
if (!(((myAddress >> 16) & 0xFF) & 0x40)) {
// if PL6 is 0 set PL7 to 1
PORTL |= (1 << 7);
- }
- else if (((myAddress >> 16) & 0xFF) & 0x40) {
+ } else if (((myAddress >> 16) & 0xFF) & 0x40) {
// if PL6 is 1 set PL7 to 0
- PORTL &= ~ (1 << 7);
+ PORTL &= ~(1 << 7);
}
// Switch SNES BA6(PL6) to HIGH to disable SRAM
PORTL |= (1 << 6);
@@ -833,19 +792,34 @@ void writeByte_Flash(unsigned long myAddress, byte myData) {
// Arduino running at 16Mhz -> one nop = 62.5ns
// Wait till output is stable
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Switch WE(PH4) WE_SNS(PH5) to LOW
PORTH &= ~((1 << 4) | (1 << 5));
// Leave WE low for at least 60ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Switch WE(PH4) WE_SNS(PH5) to HIGH
PORTH |= (1 << 4) | (1 << 5);
// Leave WE high for at least 50ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
}
byte readByte_Flash(unsigned long myAddress) {
@@ -889,29 +863,43 @@ byte readByte_Flash(unsigned long myAddress) {
if (!(((myAddress >> 16) & 0xFF) & 0x40)) {
// if PL6 is 0 set PL7 to 1
PORTL |= (1 << 7);
- }
- else if (((myAddress >> 16) & 0xFF) & 0x40) {
+ } else if (((myAddress >> 16) & 0xFF) & 0x40) {
// if PL6 is 1 set PL7 to 0
- PORTL &= ~ (1 << 7);
+ PORTL &= ~(1 << 7);
}
// Switch SNES BA6(PL6) to HIGH to disable SRAM
PORTL |= (1 << 6);
}
// Arduino running at 16Mhz -> one nop = 62.5ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Setting OE(PH1) OE_SNS(PH3) LOW
PORTH &= ~((1 << 1) | (1 << 3));
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read
byte tempByte = PINC;
// Setting OE(PH1) OE_SNS(PH3) HIGH
PORTH |= (1 << 1) | (1 << 3);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
return tempByte;
}
@@ -932,13 +920,23 @@ void writeWord_Flash(unsigned long myAddress, word myData) {
PORTH &= ~(1 << 4);
// Leave WE low for at least 60ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Switch WE(PH4) to HIGH
PORTH |= (1 << 4);
// Leave WE high for at least 50ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
}
word readWord_Flash(unsigned long myAddress) {
@@ -952,16 +950,26 @@ word readWord_Flash(unsigned long myAddress) {
// Setting OE(PH1) LOW
PORTH &= ~(1 << 1);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read
- word tempWord = ( ( PINA & 0xFF ) << 8 ) | ( PINC & 0xFF );
+ word tempWord = ((PINA & 0xFF) << 8) | (PINC & 0xFF);
__asm__("nop\n\t");
// Setting OE(PH1) HIGH
PORTH |= (1 << 1);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
return tempWord;
}
@@ -1104,8 +1112,7 @@ void writeFlash29F032() {
// Close the file:
myFile.close();
- }
- else {
+ } else {
println_Msg(F("Can't open file"));
display_Update();
}
@@ -1119,7 +1126,7 @@ int busyCheck29F032(uint32_t addr, byte c) {
// Setting OE(PH1) OE_SNS(PH3) CE(PH6)LOW
PORTH &= ~((1 << 1) | (1 << 3) | (1 << 6));
// Setting WE(PH4) WE_SNES(PH5) HIGH
- PORTH |= (1 << 4) | (1 << 5);
+ PORTH |= (1 << 4) | (1 << 5);
//When the Embedded Program algorithm is complete, the device outputs the datum programmed to D7
for (;;) {
@@ -1217,8 +1224,7 @@ void writeFlash29F1610() {
// Close the file:
myFile.close();
- }
- else {
+ } else {
println_Msg(F("Can't open file on SD"));
display_Update();
}
@@ -1277,8 +1283,7 @@ void writeFlash29F1601() {
// Close the file:
myFile.close();
- }
- else {
+ } else {
println_Msg(F("Can't open file on SD"));
display_Update();
}
@@ -1406,8 +1411,7 @@ void writeFlash29LV640() {
dataIn8();
// Close the file:
myFile.close();
- }
- else {
+ } else {
println_Msg(F("Can't open file on SD"));
display_Update();
}
@@ -1474,8 +1478,7 @@ void writeFlash29GL(unsigned long sectorSize, byte bufferSize) {
dataIn8();
// Close the file:
myFile.close();
- }
- else {
+ } else {
println_Msg(F("Can't open file on SD"));
display_Update();
}
@@ -1524,8 +1527,7 @@ void writeFlash29F800() {
// Close the file:
myFile.close();
- }
- else {
+ } else {
println_Msg(F("Can't open file on SD"));
display_Update();
}
@@ -1562,14 +1564,14 @@ uint8_t statusFlash28FXXX() {
void eraseFlash28FXXX() {
// only can erase block by block
- for (uint32_t ba = 0; ba < flashSize; ba += sectorSize)
- {
+ for (uint32_t ba = 0; ba < flashSize; ba += sectorSize) {
dataOut();
writeByte_Flash(ba, 0x20);
writeByte_Flash(ba, 0xd0);
dataIn8();
- while ((readByte_Flash(ba) & 0x80) == 0x00);
+ while ((readByte_Flash(ba) & 0x80) == 0x00)
+ ;
// blink LED
blinkLED();
@@ -1586,15 +1588,12 @@ void writeFlash28FXXX() {
if (myFile.open(filePath, O_READ)) {
if ((strcmp(flashid, "B088") == 0))
writeFlashLH28F0XX();
- else if ((strcmp(flashid, "8916") == 0) ||
- (strcmp(flashid, "8917") == 0) ||
- (strcmp(flashid, "8918") == 0)) {
+ else if ((strcmp(flashid, "8916") == 0) || (strcmp(flashid, "8917") == 0) || (strcmp(flashid, "8918") == 0)) {
writeFlashE28FXXXJ3A();
}
myFile.close();
- }
- else {
+ } else {
println_Msg(F("Can't open file on SD"));
display_Update();
}
@@ -1627,7 +1626,8 @@ void writeFlashE28FXXXJ3A() {
// waiting for buffer available
dataIn8();
- while ((readByte_Flash(block_addr) & 0x80) == 0x00);
+ while ((readByte_Flash(block_addr) & 0x80) == 0x00)
+ ;
dataOut();
// set write byte count
@@ -1642,7 +1642,8 @@ void writeFlashE28FXXXJ3A() {
// waiting for finishing
dataIn8();
- while ((readByte_Flash(block_addr) & 0x80) == 0x00);
+ while ((readByte_Flash(block_addr) & 0x80) == 0x00)
+ ;
}
}
@@ -1667,20 +1668,21 @@ void writeFlashLH28F0XX() {
// sequence load to page
dataOut();
writeByte_Flash(0x0, 0xe0);
- writeByte_Flash(0x0, bufferSize - 1); // BCL
- writeByte_Flash(0x0, 0x00); // BCH should be 0x00
+ writeByte_Flash(0x0, bufferSize - 1); // BCL
+ writeByte_Flash(0x0, 0x00); // BCH should be 0x00
for (uint32_t d = 0; d < bufferSize; d++)
writeByte_Flash(d, sdBuffer[c + d]);
// start flashing page
writeByte_Flash(0x0, 0x0c);
- writeByte_Flash(0x0, bufferSize - 1); // BCL
- writeByte_Flash(currByte + c, 0x00); // BCH should be 0x00
+ writeByte_Flash(0x0, bufferSize - 1); // BCL
+ writeByte_Flash(currByte + c, 0x00); // BCH should be 0x00
// waiting for finishing
dataIn8();
- while ((readByte_Flash(currByte + c) & 0x80) == 0x00);
+ while ((readByte_Flash(currByte + c) & 0x80) == 0x00)
+ ;
}
}
@@ -1705,8 +1707,7 @@ void blankcheck_Flash() {
if (blank) {
println_Msg(F("Flashrom is empty"));
display_Update();
- }
- else {
+ } else {
print_Error(F("Error: Not blank"), false);
}
}
@@ -1735,8 +1736,7 @@ void verifyFlash() {
if (blank == 0) {
println_Msg(F("Flashrom verified OK"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Error: "));
print_Msg(blank);
println_Msg(F(" bytes "));
@@ -1744,8 +1744,7 @@ void verifyFlash() {
}
// Close the file:
myFile.close();
- }
- else {
+ } else {
println_Msg(F("Can't open file on SD"));
display_Update();
}
@@ -1793,7 +1792,7 @@ void printFlash(int numBytes) {
for (int currByte = 0; currByte < numBytes; currByte += 10) {
for (int c = 0; c < 10; c++) {
- itoa (readByte_Flash(currByte + c), myBuffer, 16);
+ itoa(readByte_Flash(currByte + c), myBuffer, 16);
for (int i = 0; i < 2 - strlen(myBuffer); i++) {
print_Msg(F("0"));
}
@@ -1869,7 +1868,7 @@ void writeFlash16() {
// Write one full page at a time
for (byte c = 0; c < 64; c++) {
- word currWord = ( ( sdBuffer[d + 1] & 0xFF ) << 8 ) | ( sdBuffer[d] & 0xFF );
+ word currWord = ((sdBuffer[d + 1] & 0xFF) << 8) | (sdBuffer[d] & 0xFF);
writeWord_Flash(currByte + c, currWord);
d += 2;
}
@@ -1884,8 +1883,7 @@ void writeFlash16() {
// Close the file:
myFile.close();
- }
- else {
+ } else {
println_Msg(F("Can't open file on SD."));
display_Update();
}
@@ -1928,7 +1926,7 @@ void writeFlash16_29F1601() {
// Write one full page at a time
for (byte c = 0; c < 64; c++) {
- word currWord = ( ( sdBuffer[d + 1] & 0xFF ) << 8 ) | ( sdBuffer[d] & 0xFF );
+ word currWord = ((sdBuffer[d + 1] & 0xFF) << 8) | (sdBuffer[d] & 0xFF);
writeWord_Flash(currByte + c, currWord);
if (c == 63) {
@@ -1948,8 +1946,7 @@ void writeFlash16_29F1601() {
// Close the file:
myFile.close();
- }
- else {
+ } else {
println_Msg(F("Can't open file on SD."));
display_Update();
}
@@ -2021,8 +2018,7 @@ void blankcheck16() {
if (blank) {
println_Msg(F("Flashrom is empty."));
display_Update();
- }
- else {
+ } else {
print_Error(F("Error: Not blank"), false);
}
}
@@ -2057,8 +2053,7 @@ void verifyFlash16() {
if (blank == 0) {
println_Msg(F("Flashrom verified OK"));
display_Update();
- }
- else {
+ } else {
println_Msg(F("Verification ERROR!"));
print_Msg(blank);
print_Error(F("B did not verify."), false);
@@ -2066,8 +2061,7 @@ void verifyFlash16() {
}
// Close the file:
myFile.close();
- }
- else {
+ } else {
println_Msg(F("Can't open file on SD."));
display_Update();
}
@@ -2097,7 +2091,8 @@ void readFlash16() {
if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
println_Msg(F("Can't create file on SD."));
display_Update();
- while (1);
+ while (1)
+ ;
}
word d = 0;
for (unsigned long currByte = 0; currByte < flashSize / 2; currByte += 256) {
@@ -2105,7 +2100,7 @@ void readFlash16() {
word currWord = readWord_Flash(currByte + c);
// Split word into two bytes
// Right
- sdBuffer[d + 1] = (( currWord >> 8 ) & 0xFF);
+ sdBuffer[d + 1] = ((currWord >> 8) & 0xFF);
// Left
sdBuffer[d] = (currWord & 0xFF);
d += 2;
@@ -2136,17 +2131,17 @@ void printFlash16(int numBytes) {
// Split word into two bytes
byte left_byte = currWord & 0xFF;
- byte right_byte = ( currWord >> 8 ) & 0xFF;
+ byte right_byte = (currWord >> 8) & 0xFF;
- sprintf (buf, "%x", left_byte);
+ sprintf(buf, "%x", left_byte);
for (int i = 0; i < 2 - strlen(buf); i++) {
print_Msg(F("0"));
}
// Now print the significant bits
print_Msg(buf);
- sprintf (buf, "%x", right_byte);
+ sprintf(buf, "%x", right_byte);
for (int i = 0; i < 2 - strlen(buf); i++) {
print_Msg(F("0"));
}
@@ -2225,7 +2220,7 @@ void writeFlash16_29LV640() {
writeWord_Flash(0x5555, 0xa0);
// Write current word
- word myWord = ( ( sdBuffer[d + 1] & 0xFF ) << 8 ) | ( sdBuffer[d] & 0xFF );
+ word myWord = ((sdBuffer[d + 1] & 0xFF) << 8) | (sdBuffer[d] & 0xFF);
writeWord_Flash(currWord + c, myWord);
d += 2;
// Check if write is complete
@@ -2238,8 +2233,7 @@ void writeFlash16_29LV640() {
// Close the file:
myFile.close();
- }
- else {
+ } else {
println_Msg(F("Can't open file on SD."));
display_Update();
}
@@ -2291,7 +2285,10 @@ word writeWord_Eprom(unsigned long myAddress, word myData) {
DDRA = 0x00;
// Arduino running at 16Mhz -> one nop = 62.5ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Setting CE(PH6) LOW
PORTH &= ~(1 << 6);
@@ -2300,15 +2297,20 @@ word writeWord_Eprom(unsigned long myAddress, word myData) {
delayMicroseconds(3);
// Read
- word tempWord = ( ( PINA & 0xFF ) << 8 ) | ( PINC & 0xFF );
+ word tempWord = ((PINA & 0xFF) << 8) | (PINC & 0xFF);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Setting CE(PH6) HIGH
PORTH |= (1 << 6);
// Delay 130ns for Chip Enable High to Output Hi-Z
- __asm__("nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
return tempWord;
}
@@ -2329,10 +2331,15 @@ word readWord_Eprom(unsigned long myAddress) {
PORTH &= ~(1 << 6);
// Delay for 100ns for Address Valid/Chip Enable Low to Output Valid
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read
- word tempWord = ( ( PINA & 0xFF ) << 8 ) | ( PINC & 0xFF );
+ word tempWord = ((PINA & 0xFF) << 8) | (PINC & 0xFF);
// Setting CE(PH6) HIGH
PORTH |= (1 << 6);
@@ -2354,8 +2361,7 @@ void blankcheck_Eprom() {
if (blank) {
println_Msg(F("Flashrom is empty."));
display_Update();
- }
- else {
+ } else {
print_Error(F("Error: Not blank"), false);
}
}
@@ -2384,7 +2390,8 @@ void read_Eprom() {
if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
println_Msg(F("Can't create file on SD."));
display_Update();
- while (1);
+ while (1)
+ ;
}
word d = 0;
for (unsigned long currWord = 0; currWord < flashSize / 2; currWord += 256) {
@@ -2392,7 +2399,7 @@ void read_Eprom() {
word myWord = readWord_Eprom(currWord + c);
// Split word into two bytes
// Right
- sdBuffer[d + 1] = ((myWord >> 8 ) & 0xFF);
+ sdBuffer[d + 1] = ((myWord >> 8) & 0xFF);
// Left
sdBuffer[d] = (myWord & 0xFF);
d += 2;
@@ -2437,7 +2444,7 @@ void write_Eprom() {
// Work through SD buffer
for (int c = 0; c < 256; c++) {
word checkWord;
- word myWord = ( ( sdBuffer[d + 1] & 0xFF ) << 8 ) | ( sdBuffer[d] & 0xFF );
+ word myWord = ((sdBuffer[d + 1] & 0xFF) << 8) | (sdBuffer[d] & 0xFF);
// Error counter
byte n = 0;
@@ -2457,15 +2464,13 @@ void write_Eprom() {
print_Error(F("Press button to reset"), true);
}
n++;
- }
- while (checkWord != myWord);
+ } while (checkWord != myWord);
d += 2;
}
}
// Close the file:
myFile.close();
- }
- else {
+ } else {
println_Msg(F("Can't open file on SD."));
display_Update();
}
@@ -2501,8 +2506,7 @@ void verify_Eprom() {
if (blank == 0) {
println_Msg(F("Eprom verified OK"));
display_Update();
- }
- else {
+ } else {
println_Msg(F("Verification ERROR!"));
print_Msg(blank);
print_Error(F(" words did not verify."), false);
@@ -2510,8 +2514,7 @@ void verify_Eprom() {
}
// Close the file:
myFile.close();
- }
- else {
+ } else {
println_Msg(F("Can't open file on SD."));
display_Update();
}
@@ -2527,17 +2530,17 @@ void print_Eprom(int numBytes) {
// Split word into two bytes
byte left_byte = currWord & 0xFF;
- byte right_byte = ( currWord >> 8 ) & 0xFF;
+ byte right_byte = (currWord >> 8) & 0xFF;
- sprintf (buf, "%x", left_byte);
+ sprintf(buf, "%x", left_byte);
for (int i = 0; i < 2 - strlen(buf); i++) {
print_Msg(F("0"));
}
// Now print the significant bits
print_Msg(buf);
- sprintf (buf, "%x", right_byte);
+ sprintf(buf, "%x", right_byte);
for (int i = 0; i < 2 - strlen(buf); i++) {
print_Msg(F("0"));
}
@@ -2553,4 +2556,4 @@ void print_Eprom(int numBytes) {
//******************************************
// End of File
-//******************************************
+//****************************************** \ No newline at end of file
diff --git a/Cart_Reader/GB.ino b/Cart_Reader/GB.ino
index d797177..c4445bc 100644
--- a/Cart_Reader/GB.ino
+++ b/Cart_Reader/GB.ino
@@ -20,14 +20,14 @@ static const char gbxMenuItem2[] PROGMEM = "GB Advance (3V)";
static const char gbxMenuItem3[] PROGMEM = "Flash GBC Cart";
static const char gbxMenuItem4[] PROGMEM = "NPower GB Memory";
static const char gbxMenuItem5[] PROGMEM = "Reset";
-static const char* const menuOptionsGBx[] PROGMEM = {gbxMenuItem1, gbxMenuItem2, gbxMenuItem3, gbxMenuItem4, gbxMenuItem5};
+static const char* const menuOptionsGBx[] PROGMEM = { gbxMenuItem1, gbxMenuItem2, gbxMenuItem3, gbxMenuItem4, gbxMenuItem5 };
// GB menu items
static const char GBMenuItem1[] PROGMEM = "Read ROM";
static const char GBMenuItem2[] PROGMEM = "Read Save";
static const char GBMenuItem3[] PROGMEM = "Write Save";
static const char GBMenuItem4[] PROGMEM = "Reset";
-static const char* const menuOptionsGB[] PROGMEM = {GBMenuItem1, GBMenuItem2, GBMenuItem3, GBMenuItem4};
+static const char* const menuOptionsGB[] PROGMEM = { GBMenuItem1, GBMenuItem2, GBMenuItem3, GBMenuItem4 };
// GB Flash items
static const char GBFlashItem1[] PROGMEM = "29F Cart (MBC3)";
@@ -37,7 +37,7 @@ static const char GBFlashItem4[] PROGMEM = "CFI Cart";
static const char GBFlashItem5[] PROGMEM = "CFI Cart and Save";
static const char GBFlashItem6[] PROGMEM = "GB Smart";
static const char GBFlashItem7[] PROGMEM = "Reset";
-static const char* const menuOptionsGBFlash[] PROGMEM = {GBFlashItem1, GBFlashItem2, GBFlashItem3, GBFlashItem4, GBFlashItem5, GBFlashItem6, GBFlashItem7};
+static const char* const menuOptionsGBFlash[] PROGMEM = { GBFlashItem1, GBFlashItem2, GBFlashItem3, GBFlashItem4, GBFlashItem5, GBFlashItem6, GBFlashItem7 };
// Start menu for both GB and GBA
void gbxMenu() {
@@ -48,20 +48,19 @@ void gbxMenu() {
gbType = question_box(F("Select Game Boy"), menuOptions, 5, 0);
// wait for user choice to come back from the question box menu
- switch (gbType)
- {
+ switch (gbType) {
case 0:
display_Clear();
display_Update();
setup_GB();
- mode = mode_GB;
+ mode = mode_GB;
break;
case 1:
display_Clear();
display_Update();
setup_GBA();
- mode = mode_GBA;
+ mode = mode_GBA;
break;
case 2:
@@ -72,14 +71,13 @@ void gbxMenu() {
gbFlash = question_box(F("Select type"), menuOptions, 7, 0);
// wait for user choice to come back from the question box menu
- switch (gbFlash)
- {
+ switch (gbFlash) {
case 0:
//Flash MBC3
display_Clear();
display_Update();
setup_GB();
- mode = mode_GB;
+ mode = mode_GB;
// Change working dir to root
sd.chdir("/");
@@ -97,7 +95,7 @@ void gbxMenu() {
display_Clear();
display_Update();
setup_GB();
- mode = mode_GB;
+ mode = mode_GB;
// Change working dir to root
sd.chdir("/");
@@ -115,7 +113,7 @@ void gbxMenu() {
display_Clear();
display_Update();
setup_GB();
- mode = mode_GB;
+ mode = mode_GB;
//Flash first bank with erase
// Change working dir to root
@@ -156,7 +154,7 @@ void gbxMenu() {
display_Clear();
display_Update();
setup_GB();
- mode = mode_GB;
+ mode = mode_GB;
// Change working dir to root
sd.chdir("/");
@@ -183,7 +181,7 @@ void gbxMenu() {
display_Clear();
display_Update();
setup_GB();
- mode = mode_GB;
+ mode = mode_GB;
// Change working dir to root
sd.chdir("/");
@@ -231,8 +229,7 @@ void gbxMenu() {
if (wrErrors == 0) {
println_Msg(F("Verified OK"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Error: "));
print_Msg(wrErrors);
println_Msg(F(" bytes "));
@@ -245,8 +242,7 @@ void gbxMenu() {
if (!saveFound) {
println_Msg(F("Error: No save found."));
}
- }
- else {
+ } else {
print_Error(F("Cart has no Sram"), false);
}
// Reset
@@ -273,7 +269,7 @@ void gbxMenu() {
display_Clear();
display_Update();
setup_GBM();
- mode = mode_GBM;
+ mode = mode_GBM;
break;
case 4:
@@ -290,8 +286,7 @@ void gbMenu() {
mainMenu = question_box(F("GB Cart Reader"), menuOptions, 4, 0);
// wait for user choice to come back from the question box menu
- switch (mainMenu)
- {
+ switch (mainMenu) {
case 0:
display_Clear();
// Change working dir to root
@@ -313,8 +308,7 @@ void gbMenu() {
readSRAMFLASH_MBC6_GB();
else
readSRAM_GB();
- }
- else {
+ } else {
print_Error(F("No save or unsupported type"), false);
}
println_Msg(F(""));
@@ -331,24 +325,21 @@ void gbMenu() {
if (romType == 32) {
writeSRAMFLASH_MBC6_GB();
- }
- else {
+ } else {
writeSRAM_GB();
unsigned long wrErrors;
wrErrors = verifySRAM_GB();
if (wrErrors == 0) {
println_Msg(F("Verified OK"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Error: "));
print_Msg(wrErrors);
println_Msg(F(" bytes "));
print_Error(F("did not verify."), false);
}
}
- }
- else {
+ } else {
print_Error(F("No save or unsupported type"), false);
}
println_Msg(F(""));
@@ -498,19 +489,15 @@ void showCartInfo_GB() {
case 0:
if (romType == 6) {
print_Msg(F("512 Byte"));
- }
- else if (romType == 0x22) {
+ } else if (romType == 0x22) {
if (strncmp(cartID, "KCEJ", 4) == 0) {
print_Msg(F("512 Byte"));
- }
- else {
+ } else {
print_Msg(F("256 Byte"));
}
- }
- else if (romType == 0xFD) {
+ } else if (romType == 0xFD) {
print_Msg(F("32 Byte"));
- }
- else {
+ } else {
print_Msg(F("None"));
}
break;
@@ -550,8 +537,7 @@ void showCartInfo_GB() {
println_Msg(F("Press Button..."));
display_Update();
wait();
- }
- else {
+ } else {
print_Error(F("GAMEPAK ERROR"), true);
}
}
@@ -568,12 +554,18 @@ byte readByte_GB(word myAddress) {
// Enable pullups
PORTC = 0xFF;
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Switch RD(PH6) to LOW
PORTH &= ~(1 << 6);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read
byte tempByte = PINC;
@@ -581,7 +573,10 @@ byte readByte_GB(word myAddress) {
// Switch and RD(PH6) to HIGH
PORTH |= (1 << 6);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
return tempByte;
}
@@ -596,18 +591,27 @@ void writeByte_GB(int myAddress, byte myData) {
DDRC = 0xFF;
// Wait till output is stable
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Pull WR(PH5) low
PORTH &= ~(1 << 5);
// Leave WR low for at least 60ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Pull WR(PH5) HIGH
PORTH |= (1 << 5);
// Leave WR high for at least 50ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Switch data pins to input
DDRC = 0x00;
@@ -624,29 +628,37 @@ byte readByteSRAM_GB(word myAddress) {
// Enable pullups
PORTC = 0xFF;
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Pull CS(PH3) CLK(PH1)(for FRAM MOD) LOW
PORTH &= ~((1 << 3) | (1 << 1));
// Pull RD(PH6) LOW
PORTH &= ~(1 << 6);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read
byte tempByte = PINC;
// Pull RD(PH6) HIGH
- PORTH |= (1 << 6);
+ PORTH |= (1 << 6);
if (romType == 252) {
// Pull CS(PH3) HIGH
PORTH |= (1 << 3);
- }
- else {
+ } else {
// Pull CS(PH3) CLK(PH1)(for FRAM MOD) HIGH
PORTH |= (1 << 3) | (1 << 1);
}
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
return tempByte;
}
@@ -661,7 +673,10 @@ void writeByteSRAM_GB(int myAddress, byte myData) {
// Switch data pins to output
DDRC = 0xFF;
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
if (romType == 252 || romType == 253) {
// Pull CS(PH3) LOW
@@ -670,8 +685,7 @@ void writeByteSRAM_GB(int myAddress, byte myData) {
PORTH |= (1 << 1);
// Pull WR(PH5) low
PORTH &= ~(1 << 5);
- }
- else {
+ } else {
// Pull CS(PH3) CLK(PH1)(for FRAM MOD) LOW
PORTH &= ~((1 << 3) | (1 << 1));
// Pull WR(PH5) low
@@ -679,7 +693,10 @@ void writeByteSRAM_GB(int myAddress, byte myData) {
}
// Leave WR low for at least 60ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
if (romType == 252 || romType == 253) {
// Pull WR(PH5) HIGH
@@ -688,8 +705,7 @@ void writeByteSRAM_GB(int myAddress, byte myData) {
PORTH |= (1 << 3);
// Pull CLK(PH1) LOW (for GB CAM)
PORTH &= ~(1 << 1);
- }
- else {
+ } else {
// Pull WR(PH5) HIGH
PORTH |= (1 << 5);
// Pull CS(PH3) CLK(PH1)(for FRAM MOD) HIGH
@@ -697,7 +713,10 @@ void writeByteSRAM_GB(int myAddress, byte myData) {
}
// Leave WR high for at least 50ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Switch data pins to input
DDRC = 0x00;
@@ -829,8 +848,7 @@ void getCartInfo_GB() {
}
if (sramSize == 1) {
lastByte = 0xA7FF;
- }
- else if (sramSize > 1) {
+ } else if (sramSize > 1) {
lastByte = 0xBFFF;
}
@@ -890,21 +908,13 @@ void getCartInfo_GB() {
// MMM01 (Mani 4 in 1)
if (
- (strncmp(romName, "BOUKENJIMA2 SET", 15) == 0) && (sdBuffer[0x14D] == 0) ||
- (strncmp(romName, "BUBBLEBOBBLE SET", 16) == 0) && (sdBuffer[0x14D] == 0xC6) ||
- (strncmp(romName, "GANBARUGA SET", 13) == 0) && (sdBuffer[0x14D] == 0x90) ||
- (strncmp(romName, "RTYPE 2 SET", 11) == 0) && (sdBuffer[0x14D] == 0x32)) {
+ (strncmp(romName, "BOUKENJIMA2 SET", 15) == 0) && (sdBuffer[0x14D] == 0) || (strncmp(romName, "BUBBLEBOBBLE SET", 16) == 0) && (sdBuffer[0x14D] == 0xC6) || (strncmp(romName, "GANBARUGA SET", 13) == 0) && (sdBuffer[0x14D] == 0x90) || (strncmp(romName, "RTYPE 2 SET", 11) == 0) && (sdBuffer[0x14D] == 0x32)) {
romType = 0x0B;
}
// MBC1M
if (
- (strncmp(romName, "MOMOCOL", 7) == 0) && (sdBuffer[0x14D] == 0x28) ||
- (strncmp(romName, "BOMCOL", 6) == 0) && (sdBuffer[0x14D] == 0x86) ||
- (strncmp(romName, "GENCOL", 6) == 0) && (sdBuffer[0x14D] == 0x8A) ||
- (strncmp(romName, "SUPERCHINESE 123", 16) == 0) && (sdBuffer[0x14D] == 0xE4) ||
- (strncmp(romName, "MORTALKOMBATI&II", 16) == 0) && (sdBuffer[0x14D] == 0xB9) ||
- (strncmp(romName, "MORTALKOMBAT DUO", 16) == 0) && (sdBuffer[0x14D] == 0xA7)) {
+ (strncmp(romName, "MOMOCOL", 7) == 0) && (sdBuffer[0x14D] == 0x28) || (strncmp(romName, "BOMCOL", 6) == 0) && (sdBuffer[0x14D] == 0x86) || (strncmp(romName, "GENCOL", 6) == 0) && (sdBuffer[0x14D] == 0x8A) || (strncmp(romName, "SUPERCHINESE 123", 16) == 0) && (sdBuffer[0x14D] == 0xE4) || (strncmp(romName, "MORTALKOMBATI&II", 16) == 0) && (sdBuffer[0x14D] == 0xB9) || (strncmp(romName, "MORTALKOMBAT DUO", 16) == 0) && (sdBuffer[0x14D] == 0xA7)) {
romType += 0x100;
}
@@ -948,7 +958,7 @@ void readROM_GB() {
//Initialize progress bar
uint32_t processedProgressBar = 0;
- uint32_t totalProgressBar = (uint32_t)(romBanks) * 16384;
+ uint32_t totalProgressBar = (uint32_t)(romBanks)*16384;
draw_progressbar(0, totalProgressBar);
// M161 banks are double size and start with 0
@@ -1028,13 +1038,11 @@ void readROM_GB() {
// for every 4Mbits ROM, restart from 0x0000
romAddress = 0x0000;
currBank++;
- }
- else {
+ } else {
writeByte_GB(0x6000, 0);
writeByte_GB(0x2000, (currBank & 0x1f));
}
- }
- else {
+ } else {
if ((romType >= 0x19 && romType <= 0x1E) && (currBank == 0 || currBank == 256)) {
writeByte_GB(0x3000, (currBank >> 8) & 0xFF);
}
@@ -1065,7 +1073,7 @@ void readROM_GB() {
}
// Calculate checksum
-unsigned int calc_checksum_GB (char* fileName, char* folder) {
+unsigned int calc_checksum_GB(char* fileName, char* folder) {
unsigned int calcChecksum = 0;
// int calcFilesize = 0; // unused
unsigned long i = 0;
@@ -1115,8 +1123,7 @@ void compare_checksums_GB() {
print_Msg(calcsumStr);
if (strcmp(calcsumStr, checksumStr) == 0) {
println_Msg(F(" -> OK"));
- }
- else {
+ } else {
print_Msg(F(" != "));
println_Msg(checksumStr);
print_Error(F("Invalid Checksum"), false);
@@ -1188,8 +1195,7 @@ void readSRAM_GB() {
print_Msg(folder);
println_Msg(F("/"));
display_Update();
- }
- else {
+ } else {
print_Error(F("Cart has no SRAM"), false);
}
}
@@ -1232,12 +1238,10 @@ void writeSRAM_GB() {
println_Msg(F("SRAM writing finished"));
display_Update();
- }
- else {
+ } else {
print_Error(F("File doesnt exist"), false);
}
- }
- else {
+ } else {
print_Error(F("Cart has no SRAM"), false);
}
}
@@ -1256,8 +1260,8 @@ unsigned long verifySRAM_GB() {
// Check SRAM size
if (lastByte > 0) {
- if (romType <= 4) { // MBC1
- writeByte_GB(0x6000, 1); // Set RAM Mode
+ if (romType <= 4) { // MBC1
+ writeByte_GB(0x6000, 1); // Set RAM Mode
}
// Initialise MBC
@@ -1284,8 +1288,7 @@ unsigned long verifySRAM_GB() {
// Close the file:
myFile.close();
return writeErrors;
- }
- else {
+ } else {
print_Error(F("Can't open file"), true);
}
}
@@ -1464,8 +1467,7 @@ void writeSRAMFLASH_MBC6_GB() {
print_Error(F("Error erasing FLASH sector."), true);
}
}
- }
- else {
+ } else {
writeByte_GB(0x2800, 0x08);
writeByte_GB(0x3800, 0x08);
writeByte_GB(0x2000, currBank);
@@ -1521,8 +1523,7 @@ void writeSRAMFLASH_MBC6_GB() {
myFile.close();
println_Msg(F("Save writing finished"));
display_Update();
- }
- else {
+ } else {
print_Error(F("File doesnt exist"), false);
}
}
@@ -1606,36 +1607,31 @@ void writeFlash29F_GB(byte MBC, boolean flashErase) {
print_Msg(romBanks);
println_Msg(F("/256"));
display_Update();
- }
- else if (strcmp(flashid, "0141") == 0) {
+ } else if (strcmp(flashid, "0141") == 0) {
println_Msg(F("AM29F032B"));
print_Msg(F("Banks: "));
print_Msg(romBanks);
println_Msg(F("/256"));
display_Update();
- }
- else if (strcmp(flashid, "01AD") == 0) {
+ } else if (strcmp(flashid, "01AD") == 0) {
println_Msg(F("AM29F016B"));
print_Msg(F("Banks: "));
print_Msg(romBanks);
println_Msg(F("/128"));
display_Update();
- }
- else if (strcmp(flashid, "04AD") == 0) {
+ } else if (strcmp(flashid, "04AD") == 0) {
println_Msg(F("AM29F016D"));
print_Msg(F("Banks: "));
print_Msg(romBanks);
println_Msg(F("/128"));
display_Update();
- }
- else if (strcmp(flashid, "01D5") == 0) {
+ } else if (strcmp(flashid, "01D5") == 0) {
println_Msg(F("AM29F080B"));
print_Msg(F("Banks: "));
print_Msg(romBanks);
println_Msg(F("/64"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Flash ID: "));
println_Msg(flashid);
display_Update();
@@ -1703,7 +1699,7 @@ void writeFlash29F_GB(byte MBC, boolean flashErase) {
//Initialize progress bar
uint32_t processedProgressBar = 0;
- uint32_t totalProgressBar = (uint32_t)(romBanks) * 16384;
+ uint32_t totalProgressBar = (uint32_t)(romBanks)*16384;
draw_progressbar(0, totalProgressBar);
for (int currBank = 0; currBank < romBanks; currBank++) {
@@ -1753,7 +1749,7 @@ void writeFlash29F_GB(byte MBC, boolean flashErase) {
// Write flash
//Initialize progress bar
uint32_t processedProgressBar = 0;
- uint32_t totalProgressBar = (uint32_t)(romBanks) * 16384;
+ uint32_t totalProgressBar = (uint32_t)(romBanks)*16384;
draw_progressbar(0, totalProgressBar);
for (int currBank = 0; currBank < romBanks; currBank++) {
@@ -1805,13 +1801,12 @@ void writeFlash29F_GB(byte MBC, boolean flashErase) {
// Read number of banks and switch banks
for (word bank = 1; bank < romBanks; bank++) {
- if (romType >= 5) { // MBC2 and above
- writeByte_GB(0x2100, bank); // Set ROM bank
- }
- else { // MBC1
- writeByte_GB(0x6000, 0); // Set ROM Mode
- writeByte_GB(0x4000, bank >> 5); // Set bits 5 & 6 (01100000) of ROM bank
- writeByte_GB(0x2000, bank & 0x1F); // Set bits 0 & 4 (00011111) of ROM bank
+ if (romType >= 5) { // MBC2 and above
+ writeByte_GB(0x2100, bank); // Set ROM bank
+ } else { // MBC1
+ writeByte_GB(0x6000, 0); // Set ROM Mode
+ writeByte_GB(0x4000, bank >> 5); // Set bits 5 & 6 (01100000) of ROM bank
+ writeByte_GB(0x2000, bank & 0x1F); // Set bits 0 & 4 (00011111) of ROM bank
}
if (bank > 1) {
@@ -1839,15 +1834,13 @@ void writeFlash29F_GB(byte MBC, boolean flashErase) {
if (writeErrors == 0) {
println_Msg(F("OK"));
display_Update();
- }
- else {
+ } else {
println_Msg(F("Error"));
print_Msg(writeErrors);
println_Msg(F(" bytes "));
print_Error(F("did not verify."), true);
}
- }
- else {
+ } else {
println_Msg(F("Can't open file"));
display_Update();
}
@@ -1890,15 +1883,15 @@ byte writeByteCompensated(int address, byte data) {
void startCFIMode(boolean x16Mode) {
if (x16Mode) {
- writeByte_GB(0x555, 0xf0); //x16 mode reset command
+ writeByte_GB(0x555, 0xf0); //x16 mode reset command
delay(500);
- writeByte_GB(0x555, 0xf0); //Double reset to get out of possible Autoselect + CFI mode
+ writeByte_GB(0x555, 0xf0); //Double reset to get out of possible Autoselect + CFI mode
delay(500);
writeByte_GB(0x55, 0x98); //x16 CFI Query command
} else {
- writeByte_GB(0xAAA, 0xf0); //x8 mode reset command
+ writeByte_GB(0xAAA, 0xf0); //x8 mode reset command
delay(100);
- writeByte_GB(0xAAA, 0xf0); //Double reset to get out of possible Autoselect + CFI mode
+ writeByte_GB(0xAAA, 0xf0); //Double reset to get out of possible Autoselect + CFI mode
delay(100);
writeByte_GB(0xAA, 0x98); //x8 CFI Query command
}
@@ -1910,42 +1903,42 @@ void startCFIMode(boolean x16Mode) {
void identifyCFI_GB() {
// Reset flash
display_Clear();
- writeByte_GB(0x6000, 0); // Set ROM Mode
- writeByte_GB(0x2000, 0); // Set Bank to 0
+ writeByte_GB(0x6000, 0); // Set ROM Mode
+ writeByte_GB(0x2000, 0); // Set Bank to 0
writeByte_GB(0x3000, 0);
- startCFIMode(false); // Trying x8 mode first
+ startCFIMode(false); // Trying x8 mode first
display_Clear();
// Try x8 mode first
char cfiQRYx8[7];
char cfiQRYx16[7];
sprintf(cfiQRYx8, "%02X%02X%02X", readByte_GB(0x20), readByte_GB(0x22), readByte_GB(0x24));
- sprintf(cfiQRYx16, "%02X%02X%02X", readByte_GB(0x10), readByte_GB(0x11), readByte_GB(0x12)); // some devices use x8-style CFI Query command even though they are in x16 command mode
- if (strcmp(cfiQRYx8, "515259") == 0) { // QRY in x8 mode
+ sprintf(cfiQRYx16, "%02X%02X%02X", readByte_GB(0x10), readByte_GB(0x11), readByte_GB(0x12)); // some devices use x8-style CFI Query command even though they are in x16 command mode
+ if (strcmp(cfiQRYx8, "515259") == 0) { // QRY in x8 mode
println_Msg(F("Normal CFI x8 Mode"));
flashX16Mode = false;
flashSwitchLastBits = false;
- } else if (strcmp(cfiQRYx8, "52515A") == 0) { // QRY in x8 mode with switched last bit
+ } else if (strcmp(cfiQRYx8, "52515A") == 0) { // QRY in x8 mode with switched last bit
println_Msg(F("Switched CFI x8 Mode"));
flashX16Mode = false;
flashSwitchLastBits = true;
- } else if (strcmp(cfiQRYx16, "515259") == 0) { // QRY in x16 mode
+ } else if (strcmp(cfiQRYx16, "515259") == 0) { // QRY in x16 mode
println_Msg(F("Normal CFI x16 Mode"));
flashX16Mode = true;
flashSwitchLastBits = false;
- } else if (strcmp(cfiQRYx16, "52515A") == 0) { // QRY in x16 mode with switched last bit
+ } else if (strcmp(cfiQRYx16, "52515A") == 0) { // QRY in x16 mode with switched last bit
println_Msg(F("Switched CFI x16 Mode"));
flashX16Mode = true;
flashSwitchLastBits = true;
} else {
- startCFIMode(true); // Try x16 mode next
+ startCFIMode(true); // Try x16 mode next
sprintf(cfiQRYx16, "%02X%02X%02X", readByte_GB(0x10), readByte_GB(0x11), readByte_GB(0x12));
- if (strcmp(cfiQRYx16, "515259") == 0) { // QRY in x16 mode
+ if (strcmp(cfiQRYx16, "515259") == 0) { // QRY in x16 mode
println_Msg(F("Normal CFI x16 Mode"));
flashX16Mode = true;
flashSwitchLastBits = false;
- } else if (strcmp(cfiQRYx16, "52515A") == 0) { // QRY in x16 mode with switched last bit
+ } else if (strcmp(cfiQRYx16, "52515A") == 0) { // QRY in x16 mode with switched last bit
println_Msg(F("Switched CFI x16 Mode"));
flashX16Mode = true;
flashSwitchLastBits = true;
@@ -1956,7 +1949,7 @@ void identifyCFI_GB() {
return;
}
}
- flashBanks = 1 << (readByteCompensated(0x4E) - 14); // - flashX16Mode);
+ flashBanks = 1 << (readByteCompensated(0x4E) - 14); // - flashX16Mode);
// Reset flash
writeByteCompensated(0xAAA, 0xf0);
@@ -2134,12 +2127,12 @@ bool writeCFI_GB() {
while ((PINC & 0x80) != (sdBuffer[currByte] & 0x80)) {
i++;
if (i > 500) {
- if (currAddr < 0x4000) { // This happens when trying to flash an MBC5 as if it was an MBC3. Retry to flash as MBC5, starting from last successfull byte.
+ if (currAddr < 0x4000) { // This happens when trying to flash an MBC5 as if it was an MBC3. Retry to flash as MBC5, starting from last successfull byte.
currByte--;
currAddr += 0x4000;
endAddr = 0x7FFF;
break;
- } else { // If a timeout happens while trying to flash MBC5-style, flashing failed.
+ } else { // If a timeout happens while trying to flash MBC5-style, flashing failed.
return false;
}
}
@@ -2147,8 +2140,7 @@ bool writeCFI_GB() {
// Switch CS(PH3) and OE/RD(PH6) to HIGH
PORTH |= (1 << 3) | (1 << 6);
- __asm__("nop\n\tnop\n\tnop\n\t"); // Waste a few CPU cycles to remove write errors
-
+ __asm__("nop\n\tnop\n\tnop\n\t"); // Waste a few CPU cycles to remove write errors
}
currAddr += 512;
}
@@ -2168,13 +2160,12 @@ bool writeCFI_GB() {
// Read number of banks and switch banks
for (word bank = 1; bank < romBanks; bank++) {
- if (romType >= 5) { // MBC2 and above
- writeByte_GB(0x2100, bank); // Set ROM bank
- }
- else { // MBC1
- writeByte_GB(0x6000, 0); // Set ROM Mode
- writeByte_GB(0x4000, bank >> 5); // Set bits 5 & 6 (01100000) of ROM bank
- writeByte_GB(0x2000, bank & 0x1F); // Set bits 0 & 4 (00011111) of ROM bank
+ if (romType >= 5) { // MBC2 and above
+ writeByte_GB(0x2100, bank); // Set ROM bank
+ } else { // MBC1
+ writeByte_GB(0x6000, 0); // Set ROM Mode
+ writeByte_GB(0x4000, bank >> 5); // Set bits 5 & 6 (01100000) of ROM bank
+ writeByte_GB(0x2000, bank & 0x1F); // Set bits 0 & 4 (00011111) of ROM bank
}
if (bank > 1) {
@@ -2202,15 +2193,13 @@ bool writeCFI_GB() {
if (writeErrors == 0) {
println_Msg(F("OK"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Error: "));
print_Msg(writeErrors);
println_Msg(F(" bytes "));
print_Error(F("did not verify."), false);
}
- }
- else {
+ } else {
println_Msg(F("Can't open file"));
display_Update();
}
@@ -2221,4 +2210,4 @@ bool writeCFI_GB() {
//******************************************
// End of File
-//******************************************
+//****************************************** \ No newline at end of file
diff --git a/Cart_Reader/GBA.ino b/Cart_Reader/GBA.ino
index 4631373..e8352ad 100644
--- a/Cart_Reader/GBA.ino
+++ b/Cart_Reader/GBA.ino
@@ -19,7 +19,7 @@ static const char GBAMenuItem3[] PROGMEM = "Write Save";
static const char GBAMenuItem4[] PROGMEM = "Force Savetype";
static const char GBAMenuItem5[] PROGMEM = "Flash Repro";
static const char GBAMenuItem6[] PROGMEM = "Reset";
-static const char* const menuOptionsGBA[] PROGMEM = {GBAMenuItem1, GBAMenuItem2, GBAMenuItem3, GBAMenuItem4, GBAMenuItem5, GBAMenuItem6};
+static const char* const menuOptionsGBA[] PROGMEM = { GBAMenuItem1, GBAMenuItem2, GBAMenuItem3, GBAMenuItem4, GBAMenuItem5, GBAMenuItem6 };
// Rom menu
static const char GBARomItem1[] PROGMEM = "1 MB";
@@ -28,7 +28,7 @@ static const char GBARomItem3[] PROGMEM = "4 MB";
static const char GBARomItem4[] PROGMEM = "8 MB";
static const char GBARomItem5[] PROGMEM = "16 MB";
static const char GBARomItem6[] PROGMEM = "32 MB";
-static const char* const romOptionsGBA[] PROGMEM = {GBARomItem1, GBARomItem2, GBARomItem3, GBARomItem4, GBARomItem5, GBARomItem6};
+static const char* const romOptionsGBA[] PROGMEM = { GBARomItem1, GBARomItem2, GBARomItem3, GBARomItem4, GBARomItem5, GBARomItem6 };
// Save menu
static const char GBASaveItem1[] PROGMEM = "4K EEPROM";
@@ -37,7 +37,7 @@ static const char GBASaveItem3[] PROGMEM = "256K SRAM/FRAM";
static const char GBASaveItem4[] PROGMEM = "512K SRAM/FRAM";
static const char GBASaveItem5[] PROGMEM = "512K FLASH";
static const char GBASaveItem6[] PROGMEM = "1M FLASH";
-static const char* const saveOptionsGBA[] PROGMEM = {GBASaveItem1, GBASaveItem2, GBASaveItem3, GBASaveItem4, GBASaveItem5, GBASaveItem6};
+static const char* const saveOptionsGBA[] PROGMEM = { GBASaveItem1, GBASaveItem2, GBASaveItem3, GBASaveItem4, GBASaveItem5, GBASaveItem6 };
void gbaMenu() {
// create menu with title and 4 options to choose from
@@ -47,12 +47,10 @@ void gbaMenu() {
mainMenu = question_box(F("GBA Cart Reader"), menuOptions, 6, 0);
// wait for user choice to come back from the question box menu
- switch (mainMenu)
- {
+ switch (mainMenu) {
case 0:
// Read rom
- switch (cartSize)
- {
+ switch (cartSize) {
case 0:
// create submenu with title and 4 options to choose from
unsigned char GBARomMenu;
@@ -61,8 +59,7 @@ void gbaMenu() {
GBARomMenu = question_box(F("Select ROM size"), menuOptions, 6, 0);
// wait for user choice to come back from the question box menu
- switch (GBARomMenu)
- {
+ switch (GBARomMenu) {
case 0:
// 1MB
cartSize = 0x100000;
@@ -147,8 +144,7 @@ void gbaMenu() {
GBASaveMenu = question_box(F("Select save type"), menuOptions, 6, 0);
// wait for user choice to come back from the question box menu
- switch (GBASaveMenu)
- {
+ switch (GBASaveMenu) {
case 0:
// 4K EEPROM
saveType = 1;
@@ -180,8 +176,7 @@ void gbaMenu() {
break;
}
}
- switch (saveType)
- {
+ switch (saveType) {
case 1:
display_Clear();
sd.chdir("/");
@@ -250,8 +245,7 @@ void gbaMenu() {
convertPgm(saveOptionsGBA, 6);
GBASavesMenu = question_box(F("Select save type"), menuOptions, 6, 0);
// wait for user choice to come back from the question box menu
- switch (GBASavesMenu)
- {
+ switch (GBASavesMenu) {
case 0:
// 4K EEPROM
saveType = 1;
@@ -284,8 +278,7 @@ void gbaMenu() {
}
}
- switch (saveType)
- {
+ switch (saveType) {
case 1:
display_Clear();
sd.chdir("/");
@@ -295,8 +288,7 @@ void gbaMenu() {
if (writeErrors == 0) {
println_Msg(F("Verified OK"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Error: "));
print_Msg(writeErrors);
println_Msg(F(" bytes "));
@@ -314,8 +306,7 @@ void gbaMenu() {
if (writeErrors == 0) {
println_Msg(F("Verified OK"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Error: "));
print_Msg(writeErrors);
println_Msg(F(" bytes "));
@@ -334,8 +325,7 @@ void gbaMenu() {
if (writeErrors == 0) {
println_Msg(F("Verified OK"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Error: "));
print_Msg(writeErrors);
println_Msg(F(" bytes "));
@@ -357,17 +347,13 @@ void gbaMenu() {
println_Msg(F("FLASH Type: "));
if (strcmp(flashid, "1F3D") == 0) {
println_Msg(F("Atmel AT29LV512"));
- }
- else if (strcmp(flashid, "BFD4") == 0) {
+ } else if (strcmp(flashid, "BFD4") == 0) {
println_Msg(F("SST 39VF512"));
- }
- else if (strcmp(flashid, "C21C") == 0) {
+ } else if (strcmp(flashid, "C21C") == 0) {
println_Msg(F("Macronix MX29L512"));
- }
- else if (strcmp(flashid, "321B") == 0) {
+ } else if (strcmp(flashid, "321B") == 0) {
println_Msg(F("Panasonic MN63F805MNP"));
- }
- else {
+ } else {
println_Msg(F("Unknown"));
//print_Error(F(""), true);
}
@@ -378,7 +364,7 @@ void gbaMenu() {
display_Clear();
display_Update();
- if (strcmp(flashid, "1F3D") == 0) { // Atmel
+ if (strcmp(flashid, "1F3D") == 0) { // Atmel
writeFLASH_GBA(1, 65536, 0, 1);
verifyFLASH_GBA(65536, 0);
} else {
@@ -386,8 +372,7 @@ void gbaMenu() {
if (blankcheckFLASH_GBA(65536)) {
writeFLASH_GBA(1, 65536, 0, 0);
verifyFLASH_GBA(65536, 0);
- }
- else {
+ } else {
print_Error(F("Erase failed"), false);
}
}
@@ -407,11 +392,9 @@ void gbaMenu() {
println_Msg(F("Flashrom Type: "));
if (strcmp(flashid, "C209") == 0) {
println_Msg(F("Macronix MX29L010"));
- }
- else if (strcmp(flashid, "6213") == 0) {
+ } else if (strcmp(flashid, "6213") == 0) {
println_Msg(F("SANYO LE26FV10N1TS"));
- }
- else {
+ } else {
println_Msg(F("Unknown"));
//print_Error(F(""), true);
}
@@ -429,8 +412,7 @@ void gbaMenu() {
if (blankcheckFLASH_GBA(65536)) {
writeFLASH_GBA(1, 65536, 0, 0);
verifyFLASH_GBA(65536, 0);
- }
- else {
+ } else {
print_Error(F("Erase failed"), false);
}
switchBank_GBA(0x1);
@@ -438,8 +420,7 @@ void gbaMenu() {
if (blankcheckFLASH_GBA(65536)) {
writeFLASH_GBA(0, 65536, 65536, 0);
verifyFLASH_GBA(65536, 65536);
- }
- else {
+ } else {
print_Error(F("Erase failed"), false);
}
setROM_GBA();
@@ -455,8 +436,7 @@ void gbaMenu() {
if (writeErrors == 0) {
println_Msg(F("Verified OK"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Error: "));
print_Msg(writeErrors);
println_Msg(F(" bytes "));
@@ -480,8 +460,7 @@ void gbaMenu() {
GBASaveMenu = question_box(F("Select save type"), menuOptions, 6, 0);
// wait for user choice to come back from the question box menu
- switch (GBASaveMenu)
- {
+ switch (GBASaveMenu) {
case 0:
// 4K EEPROM
saveType = 1;
@@ -529,7 +508,6 @@ void gbaMenu() {
resetArduino();
break;
}
-
}
/******************************************
@@ -557,8 +535,7 @@ void setup_GBA() {
println_Msg(F(" MB"));
}
print_Msg(F("Save Type: "));
- switch (saveType)
- {
+ switch (saveType) {
case 0:
println_Msg(F("None/Unknown"));
break;
@@ -598,13 +575,17 @@ void setup_GBA() {
*****************************************/
void setROM_GBA() {
// CS_SRAM(PH0)
- DDRH |= (1 << 0); PORTH |= (1 << 0);
+ DDRH |= (1 << 0);
+ PORTH |= (1 << 0);
// CS_ROM(PH3)
- DDRH |= (1 << 3); PORTH |= (1 << 3);
+ DDRH |= (1 << 3);
+ PORTH |= (1 << 3);
// WR(PH5)
- DDRH |= (1 << 5); PORTH |= (1 << 5);
+ DDRH |= (1 << 5);
+ PORTH |= (1 << 5);
// RD(PH6)
- DDRH |= (1 << 6); PORTH |= (1 << 6);
+ DDRH |= (1 << 6);
+ PORTH |= (1 << 6);
// AD0-AD7
DDRF = 0xFF;
// AD8-AD15
@@ -630,7 +611,7 @@ word readWord_GBA(unsigned long myAddress) {
PORTC = myAddress >> 16;
// Pull CS(PH3) to LOW
- PORTH &= ~ (1 << 3);
+ PORTH &= ~(1 << 3);
// Set address/data ports to input
PORTF = 0x0;
@@ -639,10 +620,13 @@ word readWord_GBA(unsigned long myAddress) {
DDRK = 0x0;
// Pull RD(PH6) to LOW
- PORTH &= ~ (1 << 6);
+ PORTH &= ~(1 << 6);
// Delay here or read error with repro
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
word myWord = (PINK << 8) | PINF;
@@ -670,18 +654,20 @@ void writeWord_GBA(unsigned long myAddress, word myWord) {
PORTC = myAddress >> 16;
// Pull CS(PH3) to LOW
- PORTH &= ~ (1 << 3);
+ PORTH &= ~(1 << 3);
- __asm__("nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t");
// Output data
PORTF = myWord & 0xFF;
PORTK = myWord >> 8;
// Pull WR(PH5) to LOW
- PORTH &= ~ (1 << 5);
+ PORTH &= ~(1 << 5);
- __asm__("nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t");
// Switch WR(PH5) to HIGH
PORTH |= (1 << 5);
@@ -691,13 +677,12 @@ void writeWord_GBA(unsigned long myAddress, word myWord) {
}
// This function swaps bit at positions p1 and p2 in an integer n
-word swapBits(word n, word p1, word p2)
-{
+word swapBits(word n, word p1, word p2) {
// Move p1'th to rightmost side
- word bit1 = (n >> p1) & 1;
+ word bit1 = (n >> p1) & 1;
// Move p2'th to rightmost side
- word bit2 = (n >> p2) & 1;
+ word bit2 = (n >> p2) & 1;
// XOR the two bits */
word x = (bit1 ^ bit2);
@@ -738,7 +723,14 @@ byte readByte_GBA(unsigned long myAddress) {
PORTH &= ~(1 << 0);
// Hold address for at least 25ns and wait 150ns before access
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read byte
byte tempByte = PINC;
@@ -765,7 +757,14 @@ void writeByte_GBA(unsigned long myAddress, byte myData) {
PORTC = myData;
// Wait till output is stable
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Pull WE_SRAM(PH5) to LOW
PORTH &= ~(1 << 5);
@@ -773,7 +772,16 @@ void writeByte_GBA(unsigned long myAddress, byte myData) {
PORTH &= ~(1 << 0);
// Leave WR low for at least 60ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Pull CE_SRAM(PH0) HIGH
PORTH |= (1 << 0);
@@ -781,7 +789,14 @@ void writeByte_GBA(unsigned long myAddress, byte myData) {
PORTH |= (1 << 5);
// Leave WR high for at least 50ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
}
/******************************************
@@ -817,8 +832,7 @@ void getCartInfo_GBA() {
println_Msg(F("to try again"));
display_Update();
wait();
- }
- else {
+ } else {
char tempStr2[2];
char tempStr[5];
@@ -868,12 +882,10 @@ void getCartInfo_GBA() {
while (1) {
if (myFile.curPosition() == 0) {
break;
- }
- else if (myFile.peek() == '\n') {
+ } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1);
break;
- }
- else {
+ } else {
myFile.seekSet(myFile.curPosition() - 1);
}
}
@@ -905,9 +917,8 @@ void getCartInfo_GBA() {
cartSize = myFile.read() - 48;
// Remove leading 0 for single digit cart sizes
if (cartSize != 0) {
- cartSize = cartSize * 10 + myFile.read() - 48;
- }
- else {
+ cartSize = cartSize * 10 + myFile.read() - 48;
+ } else {
cartSize = myFile.read() - 48;
}
@@ -961,12 +972,10 @@ void getCartInfo_GBA() {
while (1) {
if (myFile.curPosition() == 0) {
break;
- }
- else if (myFile.peek() == '\n') {
+ } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1);
break;
- }
- else {
+ } else {
myFile.seekSet(myFile.curPosition() - 1);
}
}
@@ -1000,8 +1009,7 @@ void getCartInfo_GBA() {
// Enable log again
dont_log = false;
#endif
- }
- else {
+ } else {
print_Error(F("GBA.txt missing"), true);
}
@@ -1074,8 +1082,7 @@ void getCartInfo_GBA() {
if (saveTypeStr[0] == 'N') {
saveType = 0;
- }
- else if (saveTypeStr[0] == 'E') {
+ } else if (saveTypeStr[0] == 'E') {
// Test if 4kbit or 64kbit EEPROM
// Disable interrupts for more uniform clock pulses
@@ -1096,14 +1103,11 @@ void getCartInfo_GBA() {
break;
}
}
- }
- else if (saveTypeStr[0] == 'S') {
+ } else if (saveTypeStr[0] == 'S') {
saveType = 3;
- }
- else if ((saveTypeStr[0] == 'F') && (saveTypeStr[5] == '1')) {
+ } else if ((saveTypeStr[0] == 'F') && (saveTypeStr[5] == '1')) {
saveType = 5;
- }
- else if (saveTypeStr[0] == 'F') {
+ } else if (saveTypeStr[0] == 'F') {
saveType = 4;
}
}
@@ -1166,7 +1170,7 @@ void readROM_GBA() {
}
// Calculate the checksum of the dumped rom
-boolean compare_checksum_GBA () {
+boolean compare_checksum_GBA() {
print_Msg(F("Checksum: "));
display_Update();
@@ -1199,8 +1203,7 @@ boolean compare_checksum_GBA () {
println_Msg(F(" -> OK"));
display_Update();
return 1;
- }
- else {
+ } else {
print_Msg(F(" != "));
println_Msg(checksumStr);
print_Error(F("Invalid Checksum"), false);
@@ -1297,8 +1300,7 @@ void writeSRAM_GBA(boolean browseFile, unsigned long sramSize, uint32_t pos) {
println_Msg(F("SRAM writing finished"));
display_Update();
- }
- else {
+ } else {
print_Error(F("File doesnt exist"), false);
}
}
@@ -1327,8 +1329,7 @@ unsigned long verifySRAM_GBA(unsigned long sramSize, uint32_t pos) {
// Close the file:
myFile.close();
return writeErrors;
- }
- else {
+ } else {
print_Error(F("Can't open file"), false);
}
}
@@ -1337,7 +1338,7 @@ unsigned long verifySRAM_GBA(unsigned long sramSize, uint32_t pos) {
GBA FRAM SAVE Functions
*****************************************/
// MB85R256 FRAM (Ferroelectric Random Access Memory) 32,768 words x 8 bits
-void readFRAM_GBA (unsigned long framSize) {
+void readFRAM_GBA(unsigned long framSize) {
// Output a HIGH signal on CS_ROM(PH3) WE_SRAM(PH5)
PORTH |= (1 << 3) | (1 << 5);
@@ -1385,13 +1386,16 @@ void readFRAM_GBA (unsigned long framSize) {
// Arduino running at 16Mhz -> one nop = 62.5ns
// Leave CS_SRAM HIGH for at least 85ns
- __asm__("nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t");
// Pull OE_SRAM(PH6) LOW
- PORTH &= ~ (1 << 6);
+ PORTH &= ~(1 << 6);
// Hold address for at least 25ns and wait 150ns before access
- __asm__("nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read byte
sdBuffer[c] = PINC;
@@ -1408,7 +1412,7 @@ void readFRAM_GBA (unsigned long framSize) {
}
// Write file to SRAM
-void writeFRAM_GBA (boolean browseFile, unsigned long framSize) {
+void writeFRAM_GBA(boolean browseFile, unsigned long framSize) {
// Output a HIGH signal on CS_ROM(PH3) and OE_SRAM(PH6)
PORTH |= (1 << 3) | (1 << 6);
@@ -1429,8 +1433,7 @@ void writeFRAM_GBA (boolean browseFile, unsigned long framSize) {
// Create filepath
sprintf(filePath, "%s/%s", filePath, fileName);
display_Clear();
- }
- else
+ } else
sprintf(filePath, "%s", fileName);
//open file on sd card
@@ -1455,13 +1458,16 @@ void writeFRAM_GBA (boolean browseFile, unsigned long framSize) {
PORTK = ((currAddress + c) >> 8) & 0xFF;
// Leave WE_SRAM (PH5) HIGH for at least 85ns
- __asm__("nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t");
// Pull WE_SRAM (PH5) LOW
- PORTH &= ~ (1 << 5);
+ PORTH &= ~(1 << 5);
// Hold address for at least 25ns and wait 150ns before next write
- __asm__("nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
}
}
// Close the file:
@@ -1469,8 +1475,7 @@ void writeFRAM_GBA (boolean browseFile, unsigned long framSize) {
println_Msg(F("SRAM writing finished"));
display_Update();
- }
- else {
+ } else {
print_Error(F("File doesnt exist"), false);
}
}
@@ -1510,13 +1515,16 @@ unsigned long verifyFRAM_GBA(unsigned long framSize) {
// Arduino running at 16Mhz -> one nop = 62.5ns
// Leave CS_SRAM HIGH for at least 85ns
- __asm__("nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t");
// Pull OE_SRAM(PH6) LOW
- PORTH &= ~ (1 << 6);
+ PORTH &= ~(1 << 6);
// Hold address for at least 25ns and wait 150ns before access
- __asm__("nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read byte
if (PINC != sdBuffer[c]) {
@@ -1528,8 +1536,7 @@ unsigned long verifyFRAM_GBA(unsigned long framSize) {
// Close the file:
myFile.close();
return writeErrors;
- }
- else {
+ } else {
print_Error(F("Can't open file"), false);
}
}
@@ -1564,7 +1571,9 @@ void idFlash_GBA() {
// Wait 150ns before reading ID
// Arduino running at 16Mhz -> one nop = 62.5ns
- __asm__("nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read the two id bytes into a string
sprintf(flashid, "%02X%02X", readByteFlash_GBA(0), readByteFlash_GBA(1));
@@ -1606,13 +1615,19 @@ byte readByteFlash_GBA(unsigned long myAddress) {
PORTK = (myAddress >> 8) & 0xFF;
// Wait until byte is ready to read
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read byte
byte tempByte = PINC;
// Arduino running at 16Mhz -> one nop = 62.5ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
return tempByte;
}
@@ -1624,19 +1639,28 @@ void writeByteFlash_GBA(unsigned long myAddress, byte myData) {
// Arduino running at 16Mhz -> one nop = 62.5ns
// Wait till output is stable
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Switch WE_FLASH(PH5) to LOW
PORTH &= ~(1 << 5);
// Leave WE low for at least 40ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Switch WE_FLASH(PH5) to HIGH
PORTH |= (1 << 5);
// Leave WE high for a bit
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
}
// Erase FLASH
@@ -1668,7 +1692,7 @@ void eraseFLASH_GBA() {
delay(500);
}
-boolean blankcheckFLASH_GBA (unsigned long flashSize) {
+boolean blankcheckFLASH_GBA(unsigned long flashSize) {
// Output a HIGH signal on CS_ROM(PH3) WE_FLASH(PH5)
PORTH |= (1 << 3) | (1 << 5);
@@ -1739,7 +1763,7 @@ void switchBank_GBA(byte bankNum) {
PORTH |= (1 << 0);
}
-void readFLASH_GBA (boolean browseFile, unsigned long flashSize, uint32_t pos) {
+void readFLASH_GBA(boolean browseFile, unsigned long flashSize, uint32_t pos) {
// Output a HIGH signal on CS_ROM(PH3) WE_FLASH(PH5)
PORTH |= (1 << 3) | (1 << 5);
@@ -1822,7 +1846,7 @@ void busyCheck_GBA(int currByte) {
DDRC = 0xFF;
}
-void writeFLASH_GBA (boolean browseFile, unsigned long flashSize, uint32_t pos, boolean isAtmel) {
+void writeFLASH_GBA(boolean browseFile, unsigned long flashSize, uint32_t pos, boolean isAtmel) {
// Output a HIGH signal on CS_ROM(PH3) WE_FLASH(PH5) and OE_FLASH(PH6)
PORTH |= (1 << 3) | (1 << 5) | (1 << 6);
@@ -1871,8 +1895,7 @@ void writeFLASH_GBA (boolean browseFile, unsigned long flashSize, uint32_t pos,
busyCheck_GBA(c);
}
}
- }
- else {
+ } else {
for (unsigned long currAddress = 0; currAddress < flashSize; currAddress += 128) {
//fill sdBuffer
myFile.read(sdBuffer, 128);
@@ -1895,8 +1918,7 @@ void writeFLASH_GBA (boolean browseFile, unsigned long flashSize, uint32_t pos,
println_Msg(F("done"));
display_Update();
- }
- else {
+ } else {
println_Msg(F("Error"));
print_Error(F("File doesnt exist"), false);
}
@@ -1949,8 +1971,7 @@ void verifyFLASH_GBA(unsigned long flashSize, uint32_t pos) {
if (wrError == 0) {
println_Msg(F("OK"));
- }
- else {
+ } else {
print_Msg(wrError);
print_Error(F(" Errors"), false);
}
@@ -1991,8 +2012,7 @@ void writeEeprom_GBA(word eepSize) {
myFile.close();
println_Msg(F("done"));
display_Update();
- }
- else {
+ } else {
println_Msg(F("Error"));
print_Error(F("File doesnt exist"), false);
}
@@ -2048,19 +2068,18 @@ void send_GBA(word currAddr, word numBits) {
for (word addrBit = numBits; addrBit > 0; addrBit--) {
// If you want the k-th bit of n, then do
// (n & ( 1 << k )) >> k
- if (((currAddr & ( 1 << (addrBit - 1))) >> (addrBit - 1))) {
+ if (((currAddr & (1 << (addrBit - 1))) >> (addrBit - 1))) {
// Set A0(PF0) to High
PORTF |= (1 << 0);
// Set WR(PH5) to LOW
- PORTH &= ~ (1 << 5);
+ PORTH &= ~(1 << 5);
// Set WR(PH5) to High
PORTH |= (1 << 5);
- }
- else {
+ } else {
// Set A0(PF0) to Low
- PORTF &= ~ (1 << 0);
+ PORTF &= ~(1 << 0);
// Set WR(PH5) to LOW
- PORTH &= ~ (1 << 5);
+ PORTH &= ~(1 << 5);
// Set WR(PH5) to High
PORTH |= (1 << 5);
}
@@ -2084,36 +2103,43 @@ void writeBlock_EEP(word startAddr, word eepSize) {
// Set A23/D7(PC7) to High
PORTC |= (1 << 7);
- __asm__("nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t");
// Write 64*8=512 bytes
for (word currAddr = startAddr; currAddr < startAddr + 64; currAddr++) {
// Set CS_ROM(PH3) to LOW
- PORTH &= ~ (1 << 3);
+ PORTH &= ~(1 << 3);
// Send write request "10"
// Set A0(PF0) to High
PORTF |= (1 << 0);
// Set WR(PH5) to LOW
- PORTH &= ~ (1 << 5);
+ PORTH &= ~(1 << 5);
// Set WR(PH5) to High
PORTH |= (1 << 5);
// Set A0(PF0) to LOW
- PORTF &= ~ (1 << 0);
+ PORTF &= ~(1 << 0);
// Set WR(PH5) to LOW
- PORTH &= ~ (1 << 5);
+ PORTH &= ~(1 << 5);
// Set WR(PH5) to High
PORTH |= (1 << 5);
// Send either 6 or 14 bit address
if (eepSize == 4) {
send_GBA(currAddr, 6);
- }
- else {
+ } else {
send_GBA(currAddr, 14);
}
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Send data
for (byte currByte = 0; currByte < 8; currByte++) {
@@ -2122,26 +2148,25 @@ void writeBlock_EEP(word startAddr, word eepSize) {
// Send stop bit
// Set A0(PF0) to LOW
- PORTF &= ~ (1 << 0);
+ PORTF &= ~(1 << 0);
// Set WR(PH5) to LOW
- PORTH &= ~ (1 << 5);
+ PORTH &= ~(1 << 5);
// WR(PH5) to High
- PORTH |= (1 << 5);
+ PORTH |= (1 << 5);
// Set CS_ROM(PH3) to High
PORTH |= (1 << 3);
// Wait until done
// Set A0(PF0) to Input
- DDRF &= ~ (1 << 0);
+ DDRF &= ~(1 << 0);
do {
// Set CS_ROM(PH3) RD(PH6) to LOW
PORTH &= ~((1 << 3) | (1 << 6));
// Set CS_ROM(PH3) RD(PH6) to High
- PORTH |= (1 << 3) | (1 << 6);
- }
- while ((PINF & 0x1) == 0);
+ PORTH |= (1 << 3) | (1 << 6);
+ } while ((PINF & 0x1) == 0);
// Set A0(PF0) to Output
DDRF |= (1 << 0);
@@ -2165,49 +2190,56 @@ void readBlock_EEP(word startAddress, word eepSize) {
// Set A23/D7(PC7) to High
PORTC |= (1 << 7);
- __asm__("nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t");
// Read 64*8=512 bytes
for (word currAddr = startAddress; currAddr < startAddress + 64; currAddr++) {
// Set CS_ROM(PH3) to LOW
- PORTH &= ~ (1 << 3);
+ PORTH &= ~(1 << 3);
// Send read request "11"
// Set A0(PF0) to High
PORTF |= (1 << 0);
// Set WR(PH5) to LOW
- PORTH &= ~ (1 << 5);
+ PORTH &= ~(1 << 5);
// Set WR(PH5) to High
PORTH |= (1 << 5);
// Set WR(PH5) to LOW
- PORTH &= ~ (1 << 5);
+ PORTH &= ~(1 << 5);
// Set WR(PH5) to High
PORTH |= (1 << 5);
// Send either 6 or 14 bit address
if (eepSize == 4) {
send_GBA(currAddr, 6);
- }
- else {
+ } else {
send_GBA(currAddr, 14);
}
// Send stop bit
// Set A0(PF0) to LOW
- PORTF &= ~ (1 << 0);
+ PORTF &= ~(1 << 0);
// Set WR(PH5) to LOW
- PORTH &= ~ (1 << 5);
+ PORTH &= ~(1 << 5);
// WR(PH5) to High
- PORTH |= (1 << 5);
+ PORTH |= (1 << 5);
// Set CS_ROM(PH3) to High
PORTH |= (1 << 3);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read data
// Set A0(PF0) to Input
- DDRF &= ~ (1 << 0);
+ DDRF &= ~(1 << 0);
// Set CS_ROM(PH3) to low
PORTH &= ~(1 << 3);
@@ -2217,17 +2249,17 @@ void readBlock_EEP(word startAddress, word eepSize) {
// Ignore the first 4 bits
for (byte i = 0; i < 4; i++) {
// Set RD(PH6) to LOW
- PORTH &= ~ (1 << 6);
+ PORTH &= ~(1 << 6);
// Set RD(PH6) to High
- PORTH |= (1 << 6);
+ PORTH |= (1 << 6);
}
// Read the remaining 64bits into array
for (byte currBit = 0; currBit < 64; currBit++) {
// Set RD(PH6) to LOW
- PORTH &= ~ (1 << 6);
+ PORTH &= ~(1 << 6);
// Set RD(PH6) to High
- PORTH |= (1 << 6);
+ PORTH |= (1 << 6);
// Read bit from A0(PF0)
tempBits[currBit] = (PINF & 0x1);
@@ -2304,7 +2336,14 @@ boolean sectorCheckMX29GL128E_GBA() {
void idFlashrom_GBA() {
// Send Intel ID command to flashrom
writeWord_GBA(0, 0x90);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read flashrom ID
sprintf(flashid, "%02X%02X", ((readWord_GBA(0x2) >> 8) & 0xFF), (readWord_GBA(0x4) & 0xFF));
@@ -2312,13 +2351,19 @@ void idFlashrom_GBA() {
// Intel Strataflash
if (strcmp(flashid, "8802") == 0 || (strcmp(flashid, "8816") == 0)) {
cartSize = 0x2000000;
- }
- else {
+ } else {
// Send swapped MX29GL128E/MSP55LV128 ID command to flashrom
writeWord_GAB(0xAAA, 0xAA);
writeWord_GAB(0x555, 0x55);
writeWord_GAB(0xAAA, 0x90);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read flashrom ID
sprintf(flashid, "%02X%02X", ((readWord_GAB(0x2) >> 8) & 0xFF), (readWord_GAB(0x2) & 0xFF));
@@ -2329,8 +2374,7 @@ void idFlashrom_GBA() {
romType = (readWord_GAB(0x0) & 0xFF);
cartSize = 0x1000000;
resetMX29GL128E_GBA();
- }
- else {
+ } else {
println_Msg(F("Error"));
println_Msg(F(""));
println_Msg(F("Unknown Flash"));
@@ -2601,7 +2645,7 @@ void writeIntel4000_GBA() {
// Write buffer
for (byte currByte = 0; currByte < 64; currByte += 2) {
// Join two bytes into one word
- word currWord = ( ( sdBuffer[currWriteBuffer + currByte + 1] & 0xFF ) << 8 ) | ( sdBuffer[currWriteBuffer + currByte] & 0xFF );
+ word currWord = ((sdBuffer[currWriteBuffer + currByte + 1] & 0xFF) << 8) | (sdBuffer[currWriteBuffer + currByte] & 0xFF);
writeWord_GBA(currBlock + currSdBuffer + currWriteBuffer + currByte, currWord);
}
@@ -2642,7 +2686,7 @@ void writeMSP55LV128_GBA() {
word currWord;
for (byte currByte = 0; currByte < 32; currByte += 2) {
// Join two bytes into one word
- currWord = ( ( sdBuffer[currWriteBuffer + currByte + 1] & 0xFF ) << 8 ) | ( sdBuffer[currWriteBuffer + currByte] & 0xFF );
+ currWord = ((sdBuffer[currWriteBuffer + currByte + 1] & 0xFF) << 8) | (sdBuffer[currWriteBuffer + currByte] & 0xFF);
writeWord_GBA(currSector + currSdBuffer + currWriteBuffer + currByte, currWord);
}
@@ -2684,7 +2728,7 @@ void writeMX29GL128E_GBA() {
word currWord;
for (byte currByte = 0; currByte < 64; currByte += 2) {
// Join two bytes into one word
- currWord = ( ( sdBuffer[currWriteBuffer + currByte + 1] & 0xFF ) << 8 ) | ( sdBuffer[currWriteBuffer + currByte] & 0xFF );
+ currWord = ((sdBuffer[currWriteBuffer + currByte + 1] & 0xFF) << 8) | (sdBuffer[currWriteBuffer + currByte] & 0xFF);
writeWord_GBA(currSector + currSdBuffer + currWriteBuffer + currByte, currWord);
}
@@ -2716,7 +2760,7 @@ boolean verifyFlashrom_GBA() {
for (int currByte = 0; currByte < 512; currByte += 2) {
// Join two bytes into one word
- word currWord = ( ( sdBuffer[currByte + 1] & 0xFF ) << 8 ) | ( sdBuffer[currByte] & 0xFF );
+ word currWord = ((sdBuffer[currByte + 1] & 0xFF) << 8) | (sdBuffer[currByte] & 0xFF);
// Compare both
if (readWord_GBA(currSector + currSdBuffer + currByte) != currWord) {
@@ -2731,12 +2775,10 @@ boolean verifyFlashrom_GBA() {
myFile.close();
if (writeErrors == 0) {
return 1;
- }
- else {
+ } else {
return 0;
}
- }
- else {
+ } else {
print_Error(F("Can't open file"), true);
return 9999;
}
@@ -2757,17 +2799,13 @@ void flashRepro_GBA() {
// MX is 0xC2 and MSP55LV128 is 0x4 and MSP55LV128N 0x1
if (romType == 0xC2) {
println_Msg(F("Macronix MX29GL128E"));
- }
- else if ((romType == 0x1) || (romType == 0x4)) {
+ } else if ((romType == 0x1) || (romType == 0x4)) {
println_Msg(F("Fujitsu MSP55LV128N"));
- }
- else if ((romType == 0x89)) {
+ } else if ((romType == 0x89)) {
println_Msg(F("Intel PC28F256M29"));
- }
- else if ((romType == 0x20)) {
+ } else if ((romType == 0x20)) {
println_Msg(F("ST M29W128GH"));
- }
- else {
+ } else {
print_Msg(F("romType: 0x"));
println_Msg(romType, HEX);
print_Error(F("Unknown manufacturer"), true);
@@ -2815,14 +2853,12 @@ void flashRepro_GBA() {
display_Update();
eraseIntel4000_GBA();
resetIntel_GBA(0x200000);
- }
- else if (strcmp(flashid, "8816") == 0) {
+ } else if (strcmp(flashid, "8816") == 0) {
println_Msg(F("Erasing..."));
display_Update();
eraseIntel4400_GBA();
resetIntel_GBA(0x200000);
- }
- else if (strcmp(flashid, "227E") == 0) {
+ } else if (strcmp(flashid, "227E") == 0) {
//if (sectorCheckMX29GL128E_GBA()) {
//print_Error(F("Sector Protected"), true);
//}
@@ -2833,8 +2869,7 @@ void flashRepro_GBA() {
//MX29GL128E
//PC28F256M29 (0x89)
sectorEraseMX29GL128E_GBA();
- }
- else if ((romType == 0x1) || (romType == 0x4)) {
+ } else if ((romType == 0x1) || (romType == 0x4)) {
//MSP55LV128(N)
sectorEraseMSP55LV128_GBA();
}
@@ -2853,14 +2888,12 @@ void flashRepro_GBA() {
display_Update();
if ((strcmp(flashid, "8802") == 0) || (strcmp(flashid, "8816") == 0)) {
writeIntel4000_GBA();
- }
- else if (strcmp(flashid, "227E") == 0) {
+ } else if (strcmp(flashid, "227E") == 0) {
if ((romType == 0xC2) || (romType == 0x89) || (romType == 0x20)) {
//MX29GL128E (0xC2)
//PC28F256M29 (0x89)
writeMX29GL128E_GBA();
- }
- else if ((romType == 0x1) || (romType == 0x4)) {
+ } else if ((romType == 0x1) || (romType == 0x4)) {
//MSP55LV128(N)
writeMSP55LV128_GBA();
}
@@ -2880,8 +2913,7 @@ void flashRepro_GBA() {
delay(1000);
resetIntel_GBA(0x200000);
delay(1000);
- }
- else if (strcmp(flashid, "8816") == 0) {
+ } else if (strcmp(flashid, "8816") == 0) {
resetIntel_GBA(0x200000);
delay(1000);
}
@@ -2893,8 +2925,7 @@ void flashRepro_GBA() {
if (verifyFlashrom_GBA() == 1) {
println_Msg(F("OK"));
display_Update();
- }
- else {
+ } else {
print_Error(F("ERROR"), true);
}
/* Skipped blankcheck
@@ -2903,12 +2934,10 @@ void flashRepro_GBA() {
print_Error(F("failed"), true);
}
*/
- }
- else {
+ } else {
print_Error(F("Can't open file"), true);
}
- }
- else {
+ } else {
println_Msg(F("Error"));
println_Msg(F(""));
println_Msg(F("Unknown Flash"));
@@ -2923,4 +2952,4 @@ void flashRepro_GBA() {
//******************************************
// End of File
-//******************************************
+//****************************************** \ No newline at end of file
diff --git a/Cart_Reader/GBM.ino b/Cart_Reader/GBM.ino
index 4a56fba..7e388b6 100644
--- a/Cart_Reader/GBM.ino
+++ b/Cart_Reader/GBM.ino
@@ -14,7 +14,7 @@ static const char gbmMenuItem4[] PROGMEM = "Blankcheck";
static const char gbmMenuItem5[] PROGMEM = "Write Flash";
static const char gbmMenuItem6[] PROGMEM = "Read Mapping";
static const char gbmMenuItem7[] PROGMEM = "Write Mapping";
-static const char* const menuOptionsGBM[] PROGMEM = {gbmMenuItem1, gbmMenuItem2, gbmMenuItem3, gbmMenuItem4, gbmMenuItem5, gbmMenuItem6, gbmMenuItem7};
+static const char* const menuOptionsGBM[] PROGMEM = { gbmMenuItem1, gbmMenuItem2, gbmMenuItem3, gbmMenuItem4, gbmMenuItem5, gbmMenuItem6, gbmMenuItem7 };
void gbmMenu() {
// create menu with title and 7 options to choose from
@@ -24,8 +24,7 @@ void gbmMenu() {
mainMenu = question_box(F("GB Memory Menu"), menuOptions, 7, 0);
// wait for user choice to come back from the question box menu
- switch (mainMenu)
- {
+ switch (mainMenu) {
// Read Flash ID
case 0:
// Clear screen
@@ -87,8 +86,7 @@ void gbmMenu() {
if (blankcheckFlash_GBM()) {
println_Msg(F("OK"));
display_Update();
- }
- else {
+ } else {
println_Msg(F("ERROR"));
display_Update();
}
@@ -163,8 +161,7 @@ void gbmMenu() {
if (blankcheckMapping_GBM()) {
println_Msg(F("OK"));
display_Update();
- }
- else {
+ } else {
print_Error(F("Erasing failed"), false);
break;
}
@@ -211,7 +208,26 @@ void setup_GBM() {
while (readByte_GBM(0x120) != 0x21) {
// Enable ports 0x120h (F2)
send_GBM(0x09);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
timeout++;
if (timeout > 10) {
println_Msg(F("Error: Time Out"));
@@ -230,13 +246,19 @@ byte readByte_GBM(word myAddress) {
PORTF = myAddress & 0xFF;
PORTK = (myAddress >> 8) & 0xFF;
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Switch CS(PH3) and RD(PH6) to LOW
PORTH &= ~(1 << 3);
PORTH &= ~(1 << 6);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read
byte tempByte = PINC;
@@ -260,13 +282,19 @@ void writeByte_GBM(word myAddress, byte myData) {
PORTH &= ~(1 << 3);
PORTH &= ~(1 << 5);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Pull CS(PH3) and write(PH5) high
PORTH |= (1 << 5);
PORTH |= (1 << 3);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Set data pins to Input (or read errors??!)
DDRC = 0x0;
@@ -306,8 +334,7 @@ void readROM_GBM(word numBanks) {
// Open file on sd card
if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
print_Error(F("Can't create file on SD"), true);
- }
- else {
+ } else {
// Read rom
word currAddress = 0;
@@ -472,8 +499,7 @@ boolean readFlashID_GBM() {
display_Update();
resetFlash_GBM();
return 1;
- }
- else {
+ } else {
print_Msg(F("Flash ID: "));
println_Msg(flashid);
print_Error(F("Unknown Flash ID"), true);
@@ -652,8 +678,7 @@ void writeFlash_GBM() {
// Close the file:
myFile.close();
println_Msg(F("Done"));
- }
- else {
+ } else {
print_Error(F("Can't open file"), false);
}
}
@@ -692,8 +717,7 @@ void readMapping_GBM() {
// Open file on sd card
if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
print_Error(F("Can't create file on SD"), true);
- }
- else {
+ } else {
for (byte currByte = 0; currByte < 128; currByte++) {
sdBuffer[currByte] = readByte_GBM(currByte);
}
@@ -868,8 +892,7 @@ void writeMapping_GBM() {
// Close the file:
myFile.close();
println_Msg(F("Done"));
- }
- else {
+ } else {
print_Error(F("Can't open file"), false);
}
}
@@ -878,4 +901,4 @@ void writeMapping_GBM() {
//******************************************
// End of File
-//******************************************
+//****************************************** \ No newline at end of file
diff --git a/Cart_Reader/GBS.ino b/Cart_Reader/GBS.ino
index 7820eee..0c4aedd 100644
--- a/Cart_Reader/GBS.ino
+++ b/Cart_Reader/GBS.ino
@@ -3,7 +3,7 @@
// Supports 32M cart with LH28F016SUT flash
//******************************************
#ifdef enable_GBX
-#define GB_SMART_GAMES_PER_PAGE 6
+#define GB_SMART_GAMES_PER_PAGE 6
/******************************************
Menu
@@ -12,19 +12,19 @@
static const char gbSmartMenuItem1[] PROGMEM = "Game Menu";
static const char gbSmartMenuItem2[] PROGMEM = "Flash Menu";
static const char gbSmartMenuItem3[] PROGMEM = "Reset";
-static const char* const menuOptionsGBSmart[] PROGMEM = {gbSmartMenuItem1, gbSmartMenuItem2, gbSmartMenuItem3};
+static const char* const menuOptionsGBSmart[] PROGMEM = { gbSmartMenuItem1, gbSmartMenuItem2, gbSmartMenuItem3 };
static const char gbSmartFlashMenuItem1[] PROGMEM = "Read Flash";
static const char gbSmartFlashMenuItem2[] PROGMEM = "Write Flash";
static const char gbSmartFlashMenuItem3[] PROGMEM = "Back";
-static const char* const menuOptionsGBSmartFlash[] PROGMEM = {gbSmartFlashMenuItem1, gbSmartFlashMenuItem2, gbSmartFlashMenuItem3};
+static const char* const menuOptionsGBSmartFlash[] PROGMEM = { gbSmartFlashMenuItem1, gbSmartFlashMenuItem2, gbSmartFlashMenuItem3 };
static const char gbSmartGameMenuItem1[] PROGMEM = "Read Game";
static const char gbSmartGameMenuItem2[] PROGMEM = "Read SRAM";
static const char gbSmartGameMenuItem3[] PROGMEM = "Write SRAM";
static const char gbSmartGameMenuItem4[] PROGMEM = "Switch Game";
static const char gbSmartGameMenuItem5[] PROGMEM = "Reset";
-static const char* const menuOptionsGBSmartGame[] PROGMEM = {gbSmartGameMenuItem1, gbSmartGameMenuItem2, gbSmartGameMenuItem3, gbSmartGameMenuItem4, gbSmartGameMenuItem5};
+static const char* const menuOptionsGBSmartGame[] PROGMEM = { gbSmartGameMenuItem1, gbSmartGameMenuItem2, gbSmartGameMenuItem3, gbSmartGameMenuItem4, gbSmartGameMenuItem5 };
typedef struct
{
@@ -80,8 +80,7 @@ boolean compare_checksum_GBS() {
println_Msg(F("Checksum matches"));
display_Update();
return 1;
- }
- else {
+ } else {
print_Msg(F("Result: "));
println_Msg(calcsumStr);
print_Error(F("Checksum Error"), false);
@@ -93,12 +92,18 @@ byte readByte_GBS(word myAddress) {
PORTF = myAddress & 0xFF;
PORTK = (myAddress >> 8) & 0xFF;
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Switch CS(PH3) and RD(PH6) to LOW
PORTH &= ~((1 << 3) | (1 << 6));
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read
byte tempByte = PINC;
@@ -106,13 +111,15 @@ byte readByte_GBS(word myAddress) {
// Switch CS(PH3) and RD(PH6) to HIGH
PORTH |= (1 << 3) | (1 << 6);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
return tempByte;
}
-void setup_GBSmart()
-{
+void setup_GBSmart() {
// take from setup_GB
// Set RST(PH0) to Input
DDRH &= ~(1 << 0);
@@ -150,8 +157,7 @@ void setup_GBSmart()
display_Update();
}
-void gbSmartMenu()
-{
+void gbSmartMenu() {
uint8_t mainMenu;
// Copy menuOptions out of progmem
@@ -159,8 +165,7 @@ void gbSmartMenu()
mainMenu = question_box(F("GB Smart"), menuOptions, 3, 0);
// wait for user choice to come back from the question box menu
- switch (mainMenu)
- {
+ switch (mainMenu) {
case 0:
{
gbSmartGameMenu();
@@ -173,22 +178,20 @@ void gbSmartMenu()
}
default:
{
- asm volatile (" jmp 0");
+ asm volatile(" jmp 0");
break;
}
}
}
-void gbSmartGameOptions()
-{
+void gbSmartGameOptions() {
uint8_t gameSubMenu;
convertPgm(menuOptionsGBSmartGame, 5);
gameSubMenu = question_box(F("GB Smart Game Menu"), menuOptions, 5, 0);
- switch (gameSubMenu)
- {
- case 0: // Read Game
+ switch (gameSubMenu) {
+ case 0: // Read Game
{
display_Clear();
sd.chdir("/");
@@ -196,26 +199,23 @@ void gbSmartGameOptions()
compare_checksum_GBS();
break;
}
- case 1: // Read SRAM
+ case 1: // Read SRAM
{
display_Clear();
sd.chdir("/");
readSRAM_GB();
break;
}
- case 2: // Write SRAM
+ case 2: // Write SRAM
{
display_Clear();
sd.chdir("/");
writeSRAM_GB();
uint32_t wrErrors = verifySRAM_GB();
- if (wrErrors == 0)
- {
+ if (wrErrors == 0) {
println_Msg(F("Verified OK"));
display_Update();
- }
- else
- {
+ } else {
print_Msg(F("Error: "));
print_Msg(wrErrors);
println_Msg(F(" bytes"));
@@ -223,7 +223,7 @@ void gbSmartGameOptions()
}
break;
}
- case 3: // Switch Game
+ case 3: // Switch Game
{
gameMenuStartBank = 0x02;
gbSmartGameMenu();
@@ -231,13 +231,12 @@ void gbSmartGameOptions()
}
default:
{
- asm volatile (" jmp 0");
+ asm volatile(" jmp 0");
break;
}
}
- if (gameSubMenu != 3)
- {
+ if (gameSubMenu != 3) {
println_Msg(F(""));
println_Msg(F("Press Button..."));
display_Update();
@@ -245,8 +244,7 @@ void gbSmartGameOptions()
}
}
-void gbSmartGameMenu()
-{
+void gbSmartGameMenu() {
uint8_t gameSubMenu = 0;
gb_smart_load_more_games:
if (gameMenuStartBank > 0xfe)
@@ -254,8 +252,7 @@ gb_smart_load_more_games:
gbSmartGetGames();
- if (hasMenu)
- {
+ if (hasMenu) {
char menuOptionsGBSmartGames[7][20];
int i = 0;
for (; i < numGames; i++)
@@ -266,9 +263,7 @@ gb_smart_load_more_games:
if (gameSubMenu >= i)
goto gb_smart_load_more_games;
- }
- else
- {
+ } else {
gameSubMenu = 0;
}
@@ -283,15 +278,13 @@ gb_smart_load_more_games:
mode = mode_GB_GBSmart_Game;
}
-void gbSmartFlashMenu()
-{
+void gbSmartFlashMenu() {
uint8_t flashSubMenu;
convertPgm(menuOptionsGBSmartFlash, 3);
flashSubMenu = question_box(F("GB Smart Flash Menu"), menuOptions, 3, 0);
- switch (flashSubMenu)
- {
+ switch (flashSubMenu) {
case 0:
{
// read flash
@@ -343,9 +336,8 @@ void gbSmartFlashMenu()
wait();
}
-void gbSmartGetGames()
-{
- static const byte menu_title[] = {0x47, 0x42, 0x31, 0x36, 0x4d};
+void gbSmartGetGames() {
+ static const byte menu_title[] = { 0x47, 0x42, 0x31, 0x36, 0x4d };
// reset remap setting
gbSmartRemapStartBank(0x00, gbSmartRomSizeGB, gbSmartSramSizeGB);
@@ -356,19 +348,15 @@ void gbSmartGetGames()
// check if contain menu
hasMenu = true;
dataIn();
- for (i = 0; i < 5; i++)
- {
- if (readByte_GBS(0x0134 + i) != menu_title[i])
- {
+ for (i = 0; i < 5; i++) {
+ if (readByte_GBS(0x0134 + i) != menu_title[i]) {
hasMenu = false;
break;
}
}
- if (hasMenu)
- {
- for (i = gameMenuStartBank, numGames = 0; i < gbSmartBanks && numGames < GB_SMART_GAMES_PER_PAGE; )
- {
+ if (hasMenu) {
+ for (i = gameMenuStartBank, numGames = 0; i < gbSmartBanks && numGames < GB_SMART_GAMES_PER_PAGE;) {
myLength = 0;
// switch bank
@@ -377,21 +365,17 @@ void gbSmartGetGames()
dataIn();
// read signature
- for (uint8_t j = 0x00; j < 0x30; j++)
- {
- if (readByte_GBS(0x4104 + j) != signature[j])
- {
+ for (uint8_t j = 0x00; j < 0x30; j++) {
+ if (readByte_GBS(0x4104 + j) != signature[j]) {
i += 0x02;
goto gb_smart_get_game_loop_end;
}
}
- for (uint8_t j = 0; j < 15; j++)
- {
+ for (uint8_t j = 0; j < 15; j++) {
myByte = readByte_GBS(0x4134 + j);
- if (((char(myByte) >= 0x30 && char(myByte) <= 0x39) ||
- (char(myByte) >= 0x41 && char(myByte) <= 0x7a)))
+ if (((char(myByte) >= 0x30 && char(myByte) <= 0x39) || (char(myByte) >= 0x41 && char(myByte) <= 0x7a)))
gbSmartGames[numGames].title[myLength++] = char(myByte);
}
@@ -408,16 +392,12 @@ gb_smart_get_game_loop_end:;
}
gameMenuStartBank = i;
- }
- else
- {
+ } else {
dataIn();
- for (uint8_t j = 0; j < 15; j++)
- {
+ for (uint8_t j = 0; j < 15; j++) {
myByte = readByte_GBS(0x0134 + j);
- if (((char(myByte) >= 0x30 && char(myByte) <= 0x39) ||
- (char(myByte) >= 0x41 && char(myByte) <= 0x7a)))
+ if (((char(myByte) >= 0x30 && char(myByte) <= 0x39) || (char(myByte) >= 0x41 && char(myByte) <= 0x7a)))
gbSmartGames[0].title[myLength++] = char(myByte);
}
@@ -432,8 +412,7 @@ gb_smart_get_game_loop_end:;
}
}
-void gbSmartReadFlash()
-{
+void gbSmartReadFlash() {
print_Msg(F("Saving as GB/GBS/"));
print_Msg(fileName);
println_Msg(F("..."));
@@ -451,8 +430,7 @@ void gbSmartReadFlash()
// dump fixed bank 0x00
dataIn();
- for (uint16_t addr = 0x0000; addr <= 0x3fff; addr += 512)
- {
+ for (uint16_t addr = 0x0000; addr <= 0x3fff; addr += 512) {
for (uint16_t c = 0; c < 512; c++)
sdBuffer[c] = readByte_GBS(addr + c);
@@ -460,14 +438,12 @@ void gbSmartReadFlash()
}
// read rest banks
- for (uint16_t bank = 0x01; bank < gbSmartBanks; bank++)
- {
+ for (uint16_t bank = 0x01; bank < gbSmartBanks; bank++) {
dataOut();
writeByte_GB(0x2100, bank);
dataIn();
- for (uint16_t addr = 0x4000; addr <= 0x7fff; addr += 512)
- {
+ for (uint16_t addr = 0x4000; addr <= 0x7fff; addr += 512) {
for (uint16_t c = 0; c < 512; c++)
sdBuffer[c] = readByte_GBS(addr + c);
@@ -484,10 +460,8 @@ void gbSmartReadFlash()
display_Update();
}
-void gbSmartWriteFlash()
-{
- for (int bank = 0x00; bank < gbSmartBanks; bank += gbSmartBanksPerFlashChip)
- {
+void gbSmartWriteFlash() {
+ for (int bank = 0x00; bank < gbSmartBanks; bank += gbSmartBanksPerFlashChip) {
display_Clear();
print_Msg(F("Erasing..."));
@@ -517,13 +491,10 @@ void gbSmartWriteFlash()
display_Update();
writeErrors = gbSmartVerifyFlash();
- if (writeErrors == 0)
- {
+ if (writeErrors == 0) {
println_Msg(F("OK"));
display_Update();
- }
- else
- {
+ } else {
print_Msg(F("Error: "));
print_Msg(writeErrors);
println_Msg(F(" bytes "));
@@ -531,8 +502,7 @@ void gbSmartWriteFlash()
}
}
-void gbSmartWriteFlash(uint32_t start_bank)
-{
+void gbSmartWriteFlash(uint32_t start_bank) {
if (!myFile.open(filePath, O_READ))
print_Error(F("Can't open file on SD"), true);
@@ -550,8 +520,7 @@ void gbSmartWriteFlash(uint32_t start_bank)
gbSmartWriteFlashFromMyFile(0x0000);
// handle rest banks on 0x4000
- for (uint8_t bank = 0x01; bank < gbSmartBanksPerFlashChip; bank++)
- {
+ for (uint8_t bank = 0x01; bank < gbSmartBanksPerFlashChip; bank++) {
dataOut();
writeByte_GB(0x2100, bank);
@@ -562,17 +531,15 @@ void gbSmartWriteFlash(uint32_t start_bank)
println_Msg("");
}
-void gbSmartWriteFlashFromMyFile(uint32_t addr)
-{
- for (uint16_t i = 0; i < 16384; i += 256)
- {
+void gbSmartWriteFlashFromMyFile(uint32_t addr) {
+ for (uint16_t i = 0; i < 16384; i += 256) {
myFile.read(sdBuffer, 256);
// sequence load to page
dataOut();
gbSmartWriteFlashByte(addr, 0xe0);
gbSmartWriteFlashByte(addr, 0xff);
- gbSmartWriteFlashByte(addr, 0x00); // BCH should be 0x00
+ gbSmartWriteFlashByte(addr, 0x00); // BCH should be 0x00
// fill page buffer
for (int d = 0; d < 256; d++)
@@ -585,53 +552,45 @@ void gbSmartWriteFlashFromMyFile(uint32_t addr)
// waiting for finishing
dataIn();
- while ((readByte_GBS(addr + i) & 0x80) == 0x00);
+ while ((readByte_GBS(addr + i) & 0x80) == 0x00)
+ ;
}
// blink LED
blinkLED();
}
-uint32_t gbSmartVerifyFlash()
-{
+uint32_t gbSmartVerifyFlash() {
uint32_t verified = 0;
- if (!myFile.open(filePath, O_READ))
- {
+ if (!myFile.open(filePath, O_READ)) {
verified = 0xffffffff;
print_Error(F("Can't open file on SD"), false);
- }
- else
- {
+ } else {
// remaps mmc to full access
gbSmartRemapStartBank(0x00, gbSmartRomSizeGB, gbSmartSramSizeGB);
// verify bank 0x00
dataIn();
- for (uint16_t addr = 0x0000; addr <= 0x3fff; addr += 512)
- {
+ for (uint16_t addr = 0x0000; addr <= 0x3fff; addr += 512) {
myFile.read(sdBuffer, 512);
- for (uint16_t c = 0; c < 512; c++)
- {
+ for (uint16_t c = 0; c < 512; c++) {
if (readByte_GBS(addr + c) != sdBuffer[c])
verified++;
}
}
// verify rest banks
- for (uint16_t bank = 0x01; bank < gbSmartBanks; bank++)
- {
+ for (uint16_t bank = 0x01; bank < gbSmartBanks; bank++) {
dataOut();
writeByte_GB(0x2100, bank);
dataIn();
- for (uint16_t addr = 0x4000; addr <= 0x7fff; addr += 512)
- {
+ for (uint16_t addr = 0x4000; addr <= 0x7fff; addr += 512) {
myFile.read(sdBuffer, 512);
- for (uint16_t c = 0; c < 512; c++)
- {
+ for (uint16_t c = 0; c < 512; c++) {
if (readByte_GBS(addr + c) != sdBuffer[c])
verified++;
}
@@ -647,27 +606,23 @@ uint32_t gbSmartVerifyFlash()
return verified;
}
-byte gbSmartBlankCheckingFlash(uint8_t flash_start_bank)
-{
+byte gbSmartBlankCheckingFlash(uint8_t flash_start_bank) {
gbSmartRemapStartBank(flash_start_bank, gbSmartFlashSizeGB, gbSmartSramSizeGB);
// check first bank
dataIn();
- for (uint16_t addr = 0x0000; addr <= 0x3fff; addr++)
- {
+ for (uint16_t addr = 0x0000; addr <= 0x3fff; addr++) {
if (readByte_GBS(addr) != 0xff)
return 0;
}
// check rest banks
- for (uint16_t bank = 0x01; bank < gbSmartBanksPerFlashChip; bank++)
- {
+ for (uint16_t bank = 0x01; bank < gbSmartBanksPerFlashChip; bank++) {
dataOut();
writeByte_GB(0x2100, bank);
dataIn();
- for (uint16_t addr = 0x4000; addr <= 0x7fff; addr++)
- {
+ for (uint16_t addr = 0x4000; addr <= 0x7fff; addr++) {
if (readByte_GBS(addr) != 0xff)
return 0;
}
@@ -676,16 +631,14 @@ byte gbSmartBlankCheckingFlash(uint8_t flash_start_bank)
return 1;
}
-void gbSmartResetFlash(uint8_t flash_start_bank)
-{
+void gbSmartResetFlash(uint8_t flash_start_bank) {
gbSmartRemapStartBank(flash_start_bank, gbSmartFlashSizeGB, gbSmartSramSizeGB);
dataOut();
gbSmartWriteFlashByte(0x0, 0xff);
}
-void gbSmartEraseFlash(uint8_t flash_start_bank)
-{
+void gbSmartEraseFlash(uint8_t flash_start_bank) {
gbSmartRemapStartBank(flash_start_bank, gbSmartFlashSizeGB, gbSmartSramSizeGB);
// handling first flash block
@@ -694,14 +647,14 @@ void gbSmartEraseFlash(uint8_t flash_start_bank)
gbSmartWriteFlashByte(0x0000, 0xd0);
dataIn();
- while ((readByte_GBS(0x0000) & 0x80) == 0x00);
+ while ((readByte_GBS(0x0000) & 0x80) == 0x00)
+ ;
// blink LED
blinkLED();
// rest of flash block
- for (uint32_t ba = gbSmartBanksPerFlashBlock; ba < gbSmartBanksPerFlashChip; ba += gbSmartBanksPerFlashBlock)
- {
+ for (uint32_t ba = gbSmartBanksPerFlashBlock; ba < gbSmartBanksPerFlashChip; ba += gbSmartBanksPerFlashBlock) {
dataOut();
writeByte_GB(0x2100, ba);
@@ -709,15 +662,15 @@ void gbSmartEraseFlash(uint8_t flash_start_bank)
gbSmartWriteFlashByte(0x4000, 0xd0);
dataIn();
- while ((readByte_GBS(0x4000) & 0x80) == 0x00);
+ while ((readByte_GBS(0x4000) & 0x80) == 0x00)
+ ;
// blink LED
blinkLED();
}
}
-void gbSmartWriteFlashByte(uint32_t myAddress, uint8_t myData)
-{
+void gbSmartWriteFlashByte(uint32_t myAddress, uint8_t myData) {
PORTF = myAddress & 0xff;
PORTK = (myAddress >> 8) & 0xff;
PORTC = myData;
@@ -739,8 +692,7 @@ void gbSmartWriteFlashByte(uint32_t myAddress, uint8_t myData)
}
// rom_start_bank = 0x00 means back to original state
-void gbSmartRemapStartBank(uint8_t rom_start_bank, uint8_t rom_size, uint8_t sram_size)
-{
+void gbSmartRemapStartBank(uint8_t rom_start_bank, uint8_t rom_size, uint8_t sram_size) {
rom_start_bank &= 0xfe;
dataOut();
@@ -751,8 +703,7 @@ void gbSmartRemapStartBank(uint8_t rom_start_bank, uint8_t rom_size, uint8_t sra
writeByte_GB(0x1000, 0x98);
writeByte_GB(0x2000, rom_start_bank);
- if (rom_start_bank > 1)
- {
+ if (rom_start_bank > 1) {
// start set new base bank
writeByte_GB(0x1000, 0xa5);
@@ -773,35 +724,25 @@ void gbSmartRemapStartBank(uint8_t rom_start_bank, uint8_t rom_size, uint8_t sra
// Use for setting correct rom and sram size
// Code logic is take from SmartCard32M V1.3 menu code,
// see 0x2db2 to 0x2e51 (0xa0 bytes)
-uint8_t gbSmartGetResizeParam(uint8_t rom_size, uint8_t sram_size)
-{
- if (rom_size < 0x0f)
- {
+uint8_t gbSmartGetResizeParam(uint8_t rom_size, uint8_t sram_size) {
+ if (rom_size < 0x0f) {
rom_size &= 0x07;
rom_size ^= 0x07;
- }
- else
- {
+ } else {
rom_size = 0x01;
}
- if (sram_size > 0)
- {
- if (sram_size > 1)
- {
+ if (sram_size > 0) {
+ if (sram_size > 1) {
sram_size--;
sram_size ^= 0x03;
sram_size <<= 4;
sram_size &= 0x30;
+ } else {
+ sram_size = 0x20; // 2KiB treat as 8KiB
}
- else
- {
- sram_size = 0x20; // 2KiB treat as 8KiB
- }
- }
- else
- {
- sram_size = 0x30; // no sram
+ } else {
+ sram_size = 0x30; // no sram
}
return (sram_size | rom_size);
@@ -810,4 +751,4 @@ uint8_t gbSmartGetResizeParam(uint8_t rom_size, uint8_t sram_size)
#endif
//******************************************
// End of File
-//******************************************
+//****************************************** \ No newline at end of file
diff --git a/Cart_Reader/INTV.ino b/Cart_Reader/INTV.ino
index a749a2b..1c9c335 100644
--- a/Cart_Reader/INTV.ino
+++ b/Cart_Reader/INTV.ino
@@ -57,27 +57,27 @@
// Cart Configurations
// Format = {mapper,romlo,romhi,ramsize}
-static const byte PROGMEM intvmapsize [] = {
- 0, 0, 2, 0, // default mattel up to 32K (8K/16K/24K/32K)
- 1, 1, 3, 0, // demo cart 16K, championship tennis 32K, wsml baseball 48K
- 2, 1, 3, 0, // up to 48K (16K/32K/48K)
- 3, 4, 4, 0, // tower of doom 48K
- 4, 0, 1, 1, // uscf chess 16K + RAM 1K
- 5, 2, 3, 0, // congo bongo/defender/pac-man 24K, dig dug 32K
- 6, 1, 1, 0, // centipede 16K
- 7, 1, 1, 0, // imagic carts 16K
- 8, 1, 1, 0, // mte-201 test cart 16K
- 9, 3, 3, 2, // triple challenge 32K + RAM 2K
+static const byte PROGMEM intvmapsize[] = {
+ 0, 0, 2, 0, // default mattel up to 32K (8K/16K/24K/32K)
+ 1, 1, 3, 0, // demo cart 16K, championship tennis 32K, wsml baseball 48K
+ 2, 1, 3, 0, // up to 48K (16K/32K/48K)
+ 3, 4, 4, 0, // tower of doom 48K
+ 4, 0, 1, 1, // uscf chess 16K + RAM 1K
+ 5, 2, 3, 0, // congo bongo/defender/pac-man 24K, dig dug 32K
+ 6, 1, 1, 0, // centipede 16K
+ 7, 1, 1, 0, // imagic carts 16K
+ 8, 1, 1, 0, // mte-201 test cart 16K
+ 9, 3, 3, 2, // triple challenge 32K + RAM 2K
};
-byte intvmapcount = 10; // (sizeof(mapsize)/sizeof(mapsize[0])) / 4;
+byte intvmapcount = 10; // (sizeof(mapsize)/sizeof(mapsize[0])) / 4;
boolean intvmapfound = false;
byte intvmapselect;
int intvindex;
-byte INTV[] = {8, 16, 24, 32, 48};
-byte intvlo = 0; // Lowest Entry
-byte intvhi = 4; // Highest Entry
+byte INTV[] = { 8, 16, 24, 32, 48 };
+byte intvlo = 0; // Lowest Entry
+byte intvhi = 4; // Highest Entry
byte intvmapper;
byte newintvmapper;
@@ -96,10 +96,9 @@ static const char intvMenuItem1[] PROGMEM = "Select Cart";
static const char intvMenuItem2[] PROGMEM = "Read ROM";
static const char intvMenuItem3[] PROGMEM = "Set Mapper + Size";
static const char intvMenuItem4[] PROGMEM = "Reset";
-static const char* const menuOptionsINTV[] PROGMEM = {intvMenuItem1, intvMenuItem2, intvMenuItem3, intvMenuItem4};
+static const char* const menuOptionsINTV[] PROGMEM = { intvMenuItem1, intvMenuItem2, intvMenuItem3, intvMenuItem4 };
-void setup_INTV()
-{
+void setup_INTV() {
// Set Address Pins to Output (UNUSED)
//A0-A7
DDRF = 0xFF;
@@ -113,7 +112,7 @@ void setup_INTV()
DDRH |= (1 << 0) | (1 << 1) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6);
// Set TIME(PJ0) to Output (UNUSED)
- DDRJ |= (1 << 0);
+ DDRJ |= (1 << 0);
// Set Pins (DB0-DB15) to Input
DDRC = 0x00;
@@ -124,10 +123,10 @@ void setup_INTV()
PORTH |= (1 << 0) | (1 << 1) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6);
// Set Unused Pins HIGH
- PORTF = 0xFF; // A0-A7
- PORTK = 0xFF; // A8-A15
- PORTL = 0xFF; // A16-A23
- PORTJ |= (1 << 0); // TIME(PJ0)
+ PORTF = 0xFF; // A0-A7
+ PORTK = 0xFF; // A8-A15
+ PORTL = 0xFF; // A16-A23
+ PORTJ |= (1 << 0); // TIME(PJ0)
checkStatus_INTV();
strcpy(romName, "INTV");
@@ -135,13 +134,11 @@ void setup_INTV()
mode = mode_INTV;
}
-void intvMenu()
-{
+void intvMenu() {
convertPgm(menuOptionsINTV, 4);
uint8_t mainMenu = question_box(F("INTELLIVISION MENU"), menuOptions, 4, 0);
- switch (mainMenu)
- {
+ switch (mainMenu) {
case 0:
// Select Cart
setCart_INTV();
@@ -185,8 +182,7 @@ void intvMenu()
// DIRECT ADDRESSING MODE READ SEQUENCE: BAR-NACT-ADAR-NACT-DTB-NACT
// NO ACTION (NACT) - 0/0/0
-void NACT_INT()
-{
+void NACT_INT() {
// Switch BC1(PH4) + BC2(PH5) + BDIR(PH6) to LOW
PORTH &= ~(1 << 4) & ~(1 << 5) & ~(1 << 6);
// DB0..DB15 INPUT
@@ -195,8 +191,7 @@ void NACT_INT()
}
// SET ADDRESS - BUS TO ADDR (BAR) - 1/0/0
-void BAR_INT()
-{
+void BAR_INT() {
// Switch BDIR(PH6) to HIGH
PORTH |= (1 << 6);
// Switch BC1(PH4) + BC2(PH5) to LOW
@@ -207,8 +202,7 @@ void BAR_INT()
}
// READ DATA - DATA TO BUS (DTB) - 0/1/1
-void DTB_INT()
-{
+void DTB_INT() {
// Switch BDIR(PH6) to LOW
PORTH &= ~(1 << 6);
// Switch BC1(PH4) + BC2(PH5) to HIGH
@@ -219,8 +213,7 @@ void DTB_INT()
}
// ADDRESS DATA TO ADDRESS REGISTER (ADAR) - 0/1/0
-void ADAR_INT()
-{
+void ADAR_INT() {
// Switch BC2(PH5) + BDIR(PH6) to LOW
PORTH &= ~(1 << 5) & ~(1 << 6);
// Switch BC1(PH4) to HIGH
@@ -231,8 +224,7 @@ void ADAR_INT()
// DATA SHOULD BE STABLE ACROSS BOTH
// DATA WRITE (DW) - 1/1/0
-void DW_INT()
-{
+void DW_INT() {
// Switch BC1(PH4) + BDIR(PH6) to HIGH
PORTH |= (1 << 4) | (1 << 6);
// Switch BC2(PH5) to LOW
@@ -240,8 +232,7 @@ void DW_INT()
}
// DATA WRITE STROBE (DWS) - 1/0/1
-void DWS_INT()
-{
+void DWS_INT() {
// Switch BC2(PH5) + BDIR(PH6) to HIGH
PORTH |= (1 << 5) | (1 << 6);
// Switch BC1(PH4) to LOW
@@ -252,25 +243,40 @@ void DWS_INT()
// READ CODE
//******************************************
-uint16_t readData_INTV(uint32_t addr)
-{
+uint16_t readData_INTV(uint32_t addr) {
PORTC = addr & 0xFF;
PORTA = (addr >> 8) & 0xFF;
BAR_INT();
// Wait for bus
// 5 x 62.5ns = 312.5ns
- NOP; NOP; NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
NACT_INT();
- NOP; NOP; NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
DTB_INT();
- NOP; NOP; NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
uint16_t ret = (((PINA & 0xFF) << 8) | (PINC & 0xFF));
NACT_INT();
- NOP; NOP; NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
return ret;
}
@@ -287,8 +293,7 @@ uint16_t readData_INTV(uint32_t addr)
// 8: 0x50-0x60,0x70-0x80, // mte-201 test cart 16K
// 9: 0x50-0x70,0x90-0xB0,[0xC0-0xC8,0xD0-0xD8] // triple challenge 32K + RAM 2K [0xC0 + 0xD0 segments are not needed]
-void readSegment_INTV(uint32_t startaddr, uint32_t endaddr)
-{
+void readSegment_INTV(uint32_t startaddr, uint32_t endaddr) {
for (uint32_t addr = startaddr; addr < endaddr; addr += 256) {
for (uint16_t w = 0; w < 256; w++) {
uint16_t temp = readData_INTV(addr + w);
@@ -300,8 +305,7 @@ void readSegment_INTV(uint32_t startaddr, uint32_t endaddr)
}
// MODIFIED READ ROUTINE FOR ALL 10 MAPPERS
-void readROM_INTV()
-{
+void readROM_INTV() {
strcpy(fileName, romName);
strcat(fileName, ".int");
@@ -326,88 +330,88 @@ void readROM_INTV()
EEPROM_writeAnything(0, foldern);
switch (intvmapper) {
- case 0: //default mattel up to 32K (8K/16K/24K/32K)
- readSegment_INTV(0x5000, 0x6000); // 8K
+ case 0: //default mattel up to 32K (8K/16K/24K/32K)
+ readSegment_INTV(0x5000, 0x6000); // 8K
if (intvsize > 0) {
- readSegment_INTV(0x6000, 0x7000); // +8K = 16K
+ readSegment_INTV(0x6000, 0x7000); // +8K = 16K
if (intvsize > 1) {
- readSegment_INTV(0xD000, 0xE000); // +8K = 24K
+ readSegment_INTV(0xD000, 0xE000); // +8K = 24K
if (intvsize > 2)
- readSegment_INTV(0xF000, 0x10000); // +8K = 32K
+ readSegment_INTV(0xF000, 0x10000); // +8K = 32K
}
}
break;
- case 1: // demo cart/championship tennis/wsml baseball
- readSegment_INTV(0x5000, 0x7000); // 16K Demo Cart
+ case 1: // demo cart/championship tennis/wsml baseball
+ readSegment_INTV(0x5000, 0x7000); // 16K Demo Cart
if (intvsize > 1) {
- readSegment_INTV(0xD000, 0xE000); // +8K = 24K [NONE]
+ readSegment_INTV(0xD000, 0xE000); // +8K = 24K [NONE]
if (intvsize > 2) {
- readSegment_INTV(0xE000, 0xF000); // +8K = 32K Championship Tennis
+ readSegment_INTV(0xE000, 0xF000); // +8K = 32K Championship Tennis
if (intvsize > 3) {
- readSegment_INTV(0xF000, 0x10000); // +8K = 40K WSML Baseball [MISSING 8K ECS BANK]
+ readSegment_INTV(0xF000, 0x10000); // +8K = 40K WSML Baseball [MISSING 8K ECS BANK]
// ecs bank switch
- ecsBank(0xFFFF, 0x1); // switch ecs page 1 to 0xF000
- readSegment_INTV(0xF000, 0x10000); // + 8K = 48K WSML Baseball
- ecsBank(0xFFFF, 0x0); // reset ecs page 0 to 0xF000
+ ecsBank(0xFFFF, 0x1); // switch ecs page 1 to 0xF000
+ readSegment_INTV(0xF000, 0x10000); // + 8K = 48K WSML Baseball
+ ecsBank(0xFFFF, 0x0); // reset ecs page 0 to 0xF000
}
}
}
break;
- case 2: // up to 48K (16K/32K/48K)
- readSegment_INTV(0x5000, 0x7000); // 16K
+ case 2: // up to 48K (16K/32K/48K)
+ readSegment_INTV(0x5000, 0x7000); // 16K
if (intvsize > 1) {
- readSegment_INTV(0x9000, 0xA000); // +8K = 24K [NONE]
+ readSegment_INTV(0x9000, 0xA000); // +8K = 24K [NONE]
if (intvsize > 2) {
- readSegment_INTV(0xA000, 0xB000); // +8K = 32K
+ readSegment_INTV(0xA000, 0xB000); // +8K = 32K
if (intvsize > 3) {
- readSegment_INTV(0xB000, 0xC000); // +8K = 40K
- readSegment_INTV(0xD000, 0xE000); // +8K = 48K
+ readSegment_INTV(0xB000, 0xC000); // +8K = 40K
+ readSegment_INTV(0xD000, 0xE000); // +8K = 48K
}
}
}
break;
- case 3: // tower of doom 48K
- readSegment_INTV(0x5000, 0x7000); // 16K
- readSegment_INTV(0x9000, 0xB000); // +16K = 32K
- readSegment_INTV(0xD000, 0xE000); // +8K = 40K
- readSegment_INTV(0xF000, 0x10000); // +8K = 48K
+ case 3: // tower of doom 48K
+ readSegment_INTV(0x5000, 0x7000); // 16K
+ readSegment_INTV(0x9000, 0xB000); // +16K = 32K
+ readSegment_INTV(0xD000, 0xE000); // +8K = 40K
+ readSegment_INTV(0xF000, 0x10000); // +8K = 48K
break;
- case 4: // chess 16K
- PORTH &= ~(1 << 3); // /MSYNC to LOW
- readSegment_INTV(0x5000, 0x6000); // 8K
- PORTH |= (1 << 3); // /MSYNC to HIGH
- readSegment_INTV(0x6000, 0x7000); // 8K
+ case 4: // chess 16K
+ PORTH &= ~(1 << 3); // /MSYNC to LOW
+ readSegment_INTV(0x5000, 0x6000); // 8K
+ PORTH |= (1 << 3); // /MSYNC to HIGH
+ readSegment_INTV(0x6000, 0x7000); // 8K
break;
- case 5:// congo bongo/defender/pac-man/dig dug
- readSegment_INTV(0x5000, 0x7000); // 16K
- readSegment_INTV(0x7000, 0x8000); // +8K = 24K Congo Bongo/Defender/Pac-Man
+ case 5: // congo bongo/defender/pac-man/dig dug
+ readSegment_INTV(0x5000, 0x7000); // 16K
+ readSegment_INTV(0x7000, 0x8000); // +8K = 24K Congo Bongo/Defender/Pac-Man
if (intvsize > 2) {
- readSegment_INTV(0x9000, 0xA000); // +8K = 32K Dig Dug
+ readSegment_INTV(0x9000, 0xA000); // +8K = 32K Dig Dug
//readSegment_INTV(0xA000,0xC000); // +16K = 48K [UNUSED]
}
break;
- case 6: // centipede 16K
- readSegment_INTV(0x6000, 0x8000); // 16K
+ case 6: // centipede 16K
+ readSegment_INTV(0x6000, 0x8000); // 16K
break;
- case 7: // imagic carts 16K
- readSegment_INTV(0x4800, 0x6800); // 16K
+ case 7: // imagic carts 16K
+ readSegment_INTV(0x4800, 0x6800); // 16K
break;
- case 8: //mte-201 test cart 16K
- readSegment_INTV(0x5000, 0x6000); // 8K
- readSegment_INTV(0x7000, 0x8000); // +8K = 16K
+ case 8: //mte-201 test cart 16K
+ readSegment_INTV(0x5000, 0x6000); // 8K
+ readSegment_INTV(0x7000, 0x8000); // +8K = 16K
break;
- case 9: // triple challenge 32K [KNOWN ROM 44K BAD!]
- readSegment_INTV(0x5000, 0x7000); // 16K
- readSegment_INTV(0x9000, 0xB000); // +16K = 32K
+ case 9: // triple challenge 32K [KNOWN ROM 44K BAD!]
+ readSegment_INTV(0x5000, 0x7000); // 16K
+ readSegment_INTV(0x9000, 0xB000); // +16K = 32K
// 0xC000 + 0xD000 SEGMENTS ARE NOT NEEDED (PER INTVNUT POST)
// readSegment_INTV(0xC000,0xC800); // +4K = 36K
// readSegment_INTV(0xD000,0xE000); // +8K = 44K
@@ -429,7 +433,7 @@ void readROM_INTV()
// x = rom location ($x000 - $xFFF)
// y = page (up to 16 - WSML Baseball only uses 0/1)
void ecsBank(uint32_t addr, uint8_t bank) {
- uint16_t ecsdata = (addr & 0xF000) + 0x0A50 + bank; // $xA5y
+ uint16_t ecsdata = (addr & 0xF000) + 0x0A50 + bank; // $xA5y
// Data OUT
DDRA = 0xFF;
@@ -440,47 +444,62 @@ void ecsBank(uint32_t addr, uint8_t bank) {
PORTC = addr & 0xFF;
BAR_INT();
- NOP; NOP; NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
NACT_INT();
NOP;
// Data OUT
DDRA = 0xFF;
DDRC = 0xFF;
- PORTA = (ecsdata >> 8) & 0xFF; // $xA
- PORTC = ecsdata & 0xFF; // $5y
+ PORTA = (ecsdata >> 8) & 0xFF; // $xA
+ PORTC = ecsdata & 0xFF; // $5y
DW_INT();
- NOP; NOP; NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
DWS_INT();
- NOP; NOP; NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
NACT_INT();
- NOP; NOP; NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
}
//******************************************
// MAPPER CODE
//******************************************
-void setMapper_INTV()
-{
+void setMapper_INTV() {
#if (defined(enable_OLED) || defined(enable_LCD))
int b = 0;
int i = 0;
// Check Button Status
#if defined(enable_OLED)
- buttonVal1 = (PIND & (1 << 7)); // PD7
+ buttonVal1 = (PIND & (1 << 7)); // PD7
#elif defined(enable_LCD)
- boolean buttonVal1 = (PING & (1 << 2)); // PG2
+ boolean buttonVal1 = (PING & (1 << 2)); // PG2
#endif
- if (buttonVal1 == LOW) { // Button Pressed
- while (1) { // Scroll Mapper List
+ if (buttonVal1 == LOW) { // Button Pressed
+ while (1) { // Scroll Mapper List
#if defined(enable_OLED)
- buttonVal1 = (PIND & (1 << 7)); // PD7
+ buttonVal1 = (PIND & (1 << 7)); // PD7
#elif defined(enable_LCD)
- boolean buttonVal1 = (PING & (1 << 2)); // PG2
+ boolean buttonVal1 = (PING & (1 << 2)); // PG2
#endif
- if (buttonVal1 == HIGH) { // Button Released
+ if (buttonVal1 == HIGH) { // Button Released
// Correct Overshoot
if (i == 0)
i = intvmapcount - 1;
@@ -520,7 +539,7 @@ void setMapper_INTV()
while (1) {
b = checkButton();
- if (b == 2) { // Previous Mapper (doubleclick)
+ if (b == 2) { // Previous Mapper (doubleclick)
if (i == 0)
i = intvmapcount - 1;
else
@@ -542,7 +561,7 @@ void setMapper_INTV()
#endif
display_Update();
}
- if (b == 1) { // Next Mapper (press)
+ if (b == 1) { // Next Mapper (press)
if (i == (intvmapcount - 1))
i = 0;
else
@@ -564,7 +583,7 @@ void setMapper_INTV()
#endif
display_Update();
}
- if (b == 3) { // Long Press - Execute (hold)
+ if (b == 3) { // Long Press - Execute (hold)
newintvmapper = intvmapselect;
break;
}
@@ -613,8 +632,7 @@ void checkMapperSize_INTV() {
}
}
-void setROMSize_INTV()
-{
+void setROMSize_INTV() {
#if (defined(enable_OLED) || defined(enable_LCD))
display_Clear();
if (intvlo == intvhi)
@@ -639,7 +657,7 @@ void setROMSize_INTV()
while (1) {
b = checkButton();
- if (b == 2) { // Previous (doubleclick)
+ if (b == 2) { // Previous (doubleclick)
if (i == intvlo)
i = intvhi;
else
@@ -659,7 +677,7 @@ void setROMSize_INTV()
#endif
display_Update();
}
- if (b == 1) { // Next (press)
+ if (b == 1) { // Next (press)
if (i == intvhi)
i = intvlo;
else
@@ -678,12 +696,12 @@ void setROMSize_INTV()
#endif
display_Update();
}
- if (b == 3) { // Long Press - Execute (hold)
+ if (b == 3) { // Long Press - Execute (hold)
newintvsize = i;
break;
}
}
- display.setCursor(0, 56); // Display selection at bottom
+ display.setCursor(0, 56); // Display selection at bottom
}
print_Msg(F("ROM SIZE "));
print_Msg(INTV[newintvsize]);
@@ -722,8 +740,7 @@ setrom:
intvsize = newintvsize;
}
-void checkStatus_INTV()
-{
+void checkStatus_INTV() {
EEPROM_readAnything(7, intvmapper);
EEPROM_readAnything(8, intvsize);
if (intvmapper > 9) {
@@ -793,12 +810,10 @@ void setCart_INTV() {
while (1) {
if (myFile.curPosition() == 0) {
break;
- }
- else if (myFile.peek() == '\n') {
+ } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1);
break;
- }
- else {
+ } else {
myFile.seekSet(myFile.curPosition() - 1);
}
}
@@ -846,9 +861,8 @@ void setCart_INTV() {
// Remove leading 0 for single digit cart sizes
if (cartSize != 0) {
- cartSize = cartSize * 10 + myFile.read() - 48;
- }
- else {
+ cartSize = cartSize * 10 + myFile.read() - 48;
+ } else {
cartSize = myFile.read() - 48;
}
@@ -900,12 +914,10 @@ void setCart_INTV() {
while (1) {
if (myFile.curPosition() == 0) {
break;
- }
- else if (myFile.peek() == '\n') {
+ } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1);
break;
- }
- else {
+ } else {
myFile.seekSet(myFile.curPosition() - 1);
}
}
@@ -950,12 +962,11 @@ void setCart_INTV() {
}
}
}
- }
- else {
+ } else {
print_Error(F("Database file not found"), true);
}
}
#endif
//******************************************
// End of File
-//******************************************
+//****************************************** \ No newline at end of file
diff --git a/Cart_Reader/MD.ino b/Cart_Reader/MD.ino
index 228695a..3498fcf 100644
--- a/Cart_Reader/MD.ino
+++ b/Cart_Reader/MD.ino
@@ -29,50 +29,50 @@ byte eepType;
// chksum is located in ROM at 0x18E (0xC7)
// eepType and eepSize are combined to conserve memory
//*********************************************************
-static const word PROGMEM eepid [] = {
+static const word PROGMEM eepid[] = {
// ACCLAIM TYPE 1
0x5B9F, 0x101, // NBA Jam (J)
0x694F, 0x101, // NBA Jam (UE) (Rev 0)
0xBFA9, 0x101, // NBA Jam (UE) (Rev 1)
// ACCLAIM TYPE 2
- 0x16B2, 0x102, // Blockbuster World Videogame Championship II (U) [NO HEADER SAVE DATA]
- 0xCC3F, 0x102, // NBA Jam Tournament Edition (W) (Rev 0) [NO HEADER SAVE DATA]
- 0x8AE1, 0x102, // NBA Jam Tournament Edition (W) (Rev 1) [NO HEADER SAVE DATA]
- 0xDB97, 0x102, // NBA Jam Tournament Edition 32X (W)
- 0x7651, 0x102, // NFL Quarterback Club (W)
- 0xDFE4, 0x102, // NFL Quarterback Club 32X (W)
- 0x3DE6, 0x802, // NFL Quarterback Club '96 (UE)
- 0xCB78, 0x2002, // Frank Thomas Big Hurt Baseball (UE)
- 0x6DD9, 0x2002, // College Slam (U)
+ 0x16B2, 0x102, // Blockbuster World Videogame Championship II (U) [NO HEADER SAVE DATA]
+ 0xCC3F, 0x102, // NBA Jam Tournament Edition (W) (Rev 0) [NO HEADER SAVE DATA]
+ 0x8AE1, 0x102, // NBA Jam Tournament Edition (W) (Rev 1) [NO HEADER SAVE DATA]
+ 0xDB97, 0x102, // NBA Jam Tournament Edition 32X (W)
+ 0x7651, 0x102, // NFL Quarterback Club (W)
+ 0xDFE4, 0x102, // NFL Quarterback Club 32X (W)
+ 0x3DE6, 0x802, // NFL Quarterback Club '96 (UE)
+ 0xCB78, 0x2002, // Frank Thomas Big Hurt Baseball (UE)
+ 0x6DD9, 0x2002, // College Slam (U)
// CAPCOM
- 0xAD23, 0x83, // Mega Man: The Wily Wars (E)
- 0xEA80, 0x83, // Rockman Megaworld (J)
+ 0xAD23, 0x83, // Mega Man: The Wily Wars (E)
+ 0xEA80, 0x83, // Rockman Megaworld (J)
// SEGA
- 0x760F, 0x83, // Evander "Real Deal" Holyfield Boxing (JU)
- 0x95E7, 0x83, // Greatest Heavyweights of the Ring (E)
- 0x0000, 0x83, // Greatest Heavyweights of the Ring (J) [BLANK CHECKSUM 0000]
- 0x7270, 0x83, // Greatest Heavyweights of the Ring (U)
- 0xBACC, 0x83, // Honoo no Toukyuuji Dodge Danpei (J)
- 0xB939, 0x83, // MLBPA Sports Talk Baseball (U) [BAD HEADER SAVE DATA]
- 0x487C, 0x83, // Ninja Burai Densetsu (J)
- 0x740D, 0x83, // Wonder Boy in Monster World (B)
- 0x0278, 0x83, // Wonder Boy in Monster World (J)
- 0x9D79, 0x83, // Wonder Boy in Monster World (UE)
+ 0x760F, 0x83, // Evander "Real Deal" Holyfield Boxing (JU)
+ 0x95E7, 0x83, // Greatest Heavyweights of the Ring (E)
+ 0x0000, 0x83, // Greatest Heavyweights of the Ring (J) [BLANK CHECKSUM 0000]
+ 0x7270, 0x83, // Greatest Heavyweights of the Ring (U)
+ 0xBACC, 0x83, // Honoo no Toukyuuji Dodge Danpei (J)
+ 0xB939, 0x83, // MLBPA Sports Talk Baseball (U) [BAD HEADER SAVE DATA]
+ 0x487C, 0x83, // Ninja Burai Densetsu (J)
+ 0x740D, 0x83, // Wonder Boy in Monster World (B)
+ 0x0278, 0x83, // Wonder Boy in Monster World (J)
+ 0x9D79, 0x83, // Wonder Boy in Monster World (UE)
// EA
- 0x8512, 0x84, // Bill Walsh College Football (UE) [BAD HEADER SAVE DATA]
- 0xA107, 0x84, // John Madden Football '93 (UE) [NO HEADER SAVE DATA]
- 0x5807, 0x84, // John Madden Football '93 Championship Edition (U) [NO HEADER SAVE DATA]
- 0x2799, 0x84, // NHLPA Hockey '93 (UE) (Rev 0) [NO HEADER SAVE DATA]
- 0xFA57, 0x84, // NHLPA Hockey '93 (UE) (Rev 1) [NO HEADER SAVE DATA]
- 0x8B9F, 0x84, // Rings of Power (UE) [NO HEADER SAVE DATA]
+ 0x8512, 0x84, // Bill Walsh College Football (UE) [BAD HEADER SAVE DATA]
+ 0xA107, 0x84, // John Madden Football '93 (UE) [NO HEADER SAVE DATA]
+ 0x5807, 0x84, // John Madden Football '93 Championship Edition (U) [NO HEADER SAVE DATA]
+ 0x2799, 0x84, // NHLPA Hockey '93 (UE) (Rev 0) [NO HEADER SAVE DATA]
+ 0xFA57, 0x84, // NHLPA Hockey '93 (UE) (Rev 1) [NO HEADER SAVE DATA]
+ 0x8B9F, 0x84, // Rings of Power (UE) [NO HEADER SAVE DATA]
// CODEMASTERS
- 0x7E65, 0x405, // Brian Lara Cricket (E) [NO HEADER SAVE DATA]
- 0x9A5C, 0x2005, // Brian Lara Cricket 96 (E) (Rev 1.0) [NO HEADER SAVE DATA]
- 0xC4EE, 0x2005, // Brian Lara Cricket 96 (E) (Rev 1.1) [NO HEADER SAVE DATA]
- 0x7E50, 0x805, // Micro Machines 2 (E) (J-Cart) [NO HEADER SAVE DATA]
- 0x165E, 0x805, // Micro Machines '96 (E) (J-Cart) (Rev 1.0/1.1) [NO HEADER SAVE DATA]
- 0x168B, 0x405, // Micro Machines Military (E) (J-Cart) [NO HEADER SAVE DATA]
- 0x12C1, 0x2005, // Shane Warne Cricket (E) [NO HEADER SAVE DATA]
+ 0x7E65, 0x405, // Brian Lara Cricket (E) [NO HEADER SAVE DATA]
+ 0x9A5C, 0x2005, // Brian Lara Cricket 96 (E) (Rev 1.0) [NO HEADER SAVE DATA]
+ 0xC4EE, 0x2005, // Brian Lara Cricket 96 (E) (Rev 1.1) [NO HEADER SAVE DATA]
+ 0x7E50, 0x805, // Micro Machines 2 (E) (J-Cart) [NO HEADER SAVE DATA]
+ 0x165E, 0x805, // Micro Machines '96 (E) (J-Cart) (Rev 1.0/1.1) [NO HEADER SAVE DATA]
+ 0x168B, 0x405, // Micro Machines Military (E) (J-Cart) [NO HEADER SAVE DATA]
+ 0x12C1, 0x2005, // Shane Warne Cricket (E) [NO HEADER SAVE DATA]
};
byte eepcount = (sizeof(eepid) / sizeof(eepid[0])) / 2;
@@ -134,8 +134,8 @@ void mdLoadConf() {
//print_Msg(F("read line: "));
//println_Msg(line);
if (line[0] == '[') {
- char *name;
- char *value;
+ char* name;
+ char* value;
i = 1;
name = line + i;
for (; i < sizeof(line); i++) {
@@ -192,7 +192,7 @@ static const char MDMenuItem1[] PROGMEM = "Game Cartridge";
static const char MDMenuItem2[] PROGMEM = "SegaCD RamCart";
static const char MDMenuItem3[] PROGMEM = "Flash Repro";
static const char MDMenuItem4[] PROGMEM = "Reset";
-static const char* const menuOptionsMD[] PROGMEM = {MDMenuItem1, MDMenuItem2, MDMenuItem3, MDMenuItem4};
+static const char* const menuOptionsMD[] PROGMEM = { MDMenuItem1, MDMenuItem2, MDMenuItem3, MDMenuItem4 };
// Cart menu items
static const char MDCartMenuItem1[] PROGMEM = "Read Rom";
@@ -202,13 +202,13 @@ static const char MDCartMenuItem4[] PROGMEM = "Read EEPROM";
static const char MDCartMenuItem5[] PROGMEM = "Write EEPROM";
static const char MDCartMenuItem6[] PROGMEM = "Cycle cart";
static const char MDCartMenuItem7[] PROGMEM = "Reset";
-static const char* const menuOptionsMDCart[] PROGMEM = {MDCartMenuItem1, MDCartMenuItem2, MDCartMenuItem3, MDCartMenuItem4, MDCartMenuItem5, MDCartMenuItem6, MDCartMenuItem7};
+static const char* const menuOptionsMDCart[] PROGMEM = { MDCartMenuItem1, MDCartMenuItem2, MDCartMenuItem3, MDCartMenuItem4, MDCartMenuItem5, MDCartMenuItem6, MDCartMenuItem7 };
// Sega CD Ram Backup Cartridge menu items
static const char SCDMenuItem1[] PROGMEM = "Read Backup RAM";
static const char SCDMenuItem2[] PROGMEM = "Write Backup RAM";
static const char SCDMenuItem3[] PROGMEM = "Reset";
-static const char* const menuOptionsSCD[] PROGMEM = {SCDMenuItem1, SCDMenuItem2, SCDMenuItem3};
+static const char* const menuOptionsSCD[] PROGMEM = { SCDMenuItem1, SCDMenuItem2, SCDMenuItem3 };
// Sega start menu
void mdMenu() {
@@ -219,8 +219,7 @@ void mdMenu() {
mdDev = question_box(F("Select MD device"), menuOptions, 4, 0);
// wait for user choice to come back from the question box menu
- switch (mdDev)
- {
+ switch (mdDev) {
case 0:
display_Clear();
display_Update();
@@ -232,7 +231,7 @@ void mdMenu() {
display_Clear();
display_Update();
setup_MD();
- mode = mode_SEGA_CD;
+ mode = mode_SEGA_CD;
break;
#ifdef enable_FLASH
@@ -240,7 +239,7 @@ void mdMenu() {
display_Clear();
display_Update();
setup_MD();
- mode = mode_MD_Cart;
+ mode = mode_MD_Cart;
// Change working dir to root
filePath[0] = '\0';
sd.chdir("/");
@@ -258,8 +257,7 @@ void mdMenu() {
if (strcmp(flashid, "C2F1") == 0) {
println_Msg(F("MX29F1610 detected"));
flashSize = 2097152;
- }
- else {
+ } else {
print_Error(F("Error: Unknown flashrom"), true);
}
display_Update();
@@ -296,8 +294,7 @@ void mdCartMenu() {
mainMenu = question_box(F("MEGA DRIVE Reader"), menuOptions, 7, 0);
// wait for user choice to come back from the question box menu
- switch (mainMenu)
- {
+ switch (mainMenu) {
case 0:
display_Clear();
@@ -308,12 +305,10 @@ void mdCartMenu() {
sd.chdir("/");
if (realtec) {
readRealtec_MD();
- }
- else {
+ } else {
readROM_MD();
}
- }
- else {
+ } else {
print_Error(F("Cart has no ROM"), false);
}
#ifdef global_log
@@ -332,8 +327,7 @@ void mdCartMenu() {
enableSram_MD(1);
readSram_MD();
enableSram_MD(0);
- }
- else {
+ } else {
print_Error(F("Cart has no Sram"), false);
}
break;
@@ -354,15 +348,13 @@ void mdCartMenu() {
if (writeErrors == 0) {
println_Msg(F("Sram verified OK"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Error: "));
print_Msg(writeErrors);
println_Msg(F(" bytes "));
print_Error(F("did not verify."), false);
}
- }
- else {
+ } else {
print_Error(F("Cart has no Sram"), false);
}
break;
@@ -383,8 +375,7 @@ void mdCartMenu() {
fileBrowser(F("Select eep file"));
display_Clear();
writeEEP_MD();
- }
- else {
+ } else {
print_Error(F("Cart has no EEPROM"), false);
}
break;
@@ -421,8 +412,7 @@ void segaCDMenu() {
scdMenu = question_box(F("SEGA CD RAM"), menuOptions, 3, 0);
// wait for user choice to come back from the question box menu
- switch (scdMenu)
- {
+ switch (scdMenu) {
case 0:
display_Clear();
if (bramSize > 0)
@@ -439,15 +429,14 @@ void segaCDMenu() {
fileBrowser(F("Select brm file"));
display_Clear();
writeBram_MD();
- }
- else {
+ } else {
print_Error(F("Not CD Backup RAM Cart"), false);
}
break;
case 2:
// Reset
- asm volatile (" jmp 0");
+ asm volatile(" jmp 0");
break;
}
println_Msg(F(""));
@@ -473,10 +462,10 @@ void setup_MD() {
DDRL = 0xFF;
// Set Control Pins to Output RST(PH0) CLK(PH1) CS(PH3) WRH(PH4) WRL(PH5) OE(PH6)
- DDRH |= (1 << 0) | (1 << 1) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6);
+ DDRH |= (1 << 0) | (1 << 1) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6);
// Set TIME(PJ0) to Output
- DDRJ |= (1 << 0);
+ DDRJ |= (1 << 0);
// Set Data Pins (D0-D15) to Input
DDRC = 0x00;
@@ -510,7 +499,8 @@ void writeWord_MD(unsigned long myAddress, word myData) {
// Arduino running at 16Mhz -> one nop = 62.5ns
// Wait till output is stable
- __asm__("nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t");
// Switch WR(PH5) to LOW
PORTH &= ~(1 << 5);
@@ -518,7 +508,18 @@ void writeWord_MD(unsigned long myAddress, word myData) {
PORTH &= ~(1 << 3);
// Leave WR low for at least 200ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Setting CS(PH3) HIGH
PORTH |= (1 << 3);
@@ -526,7 +527,12 @@ void writeWord_MD(unsigned long myAddress, word myData) {
PORTH |= (1 << 5);
// Leave WR high for at least 50ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
}
word readWord_MD(unsigned long myAddress) {
@@ -543,10 +549,15 @@ word readWord_MD(unsigned long myAddress) {
PORTH &= ~(1 << 6);
// most MD ROMs are 200ns, comparable to SNES > use similar access delay of 6 x 62.5 = 375ns
- NOP; NOP; NOP; NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
// Read
- word tempWord = ( ( PINA & 0xFF ) << 8 ) | ( PINC & 0xFF );
+ word tempWord = ((PINA & 0xFF) << 8) | (PINC & 0xFF);
// Setting CS(PH3) HIGH
PORTH |= (1 << 3);
@@ -554,7 +565,12 @@ word readWord_MD(unsigned long myAddress) {
PORTH |= (1 << 6);
// these 6x nop delays have been here before, unknown what they mean
- NOP; NOP; NOP; NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
return tempWord;
}
@@ -574,13 +590,27 @@ void writeFlash_MD(unsigned long myAddress, word myData) {
PORTH &= ~(1 << 5);
// Leave WE low for at least 60ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Switch WE(PH5)to HIGH
PORTH |= (1 << 5);
// Leave WE high for at least 50ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
}
word readFlash_MD(unsigned long myAddress) {
@@ -594,16 +624,30 @@ word readFlash_MD(unsigned long myAddress) {
// Setting OE(PH6) LOW
PORTH &= ~(1 << 6);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read
- word tempWord = ( ( PINA & 0xFF ) << 8 ) | ( PINC & 0xFF );
+ word tempWord = ((PINA & 0xFF) << 8) | (PINC & 0xFF);
__asm__("nop\n\t");
// Setting OE(PH6) HIGH
PORTH |= (1 << 6);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
return tempWord;
}
@@ -635,8 +679,8 @@ void getCartInfo_MD() {
// Zero Wing Check
if (cartSize == 0x80000) {
switch (chksum) {
- case 0xD07D: //Zero Wing (J) 8Mbit
- cartSize = 0x100000; //1MB instead of 512KB
+ case 0xD07D: //Zero Wing (J) 8Mbit
+ cartSize = 0x100000; //1MB instead of 512KB
chksum = 0xF204;
break;
}
@@ -645,9 +689,9 @@ void getCartInfo_MD() {
// Super Street Fighter 2 Check
if (cartSize == 0x400000) {
switch (chksum) {
- case 0xCE25: // Super Street Fighter 2 (J) 40Mbit
- case 0xE41D: // Super Street Fighter 2 (E) 40Mbit
- case 0xE017: // Super Street Fighter 2 (U) 40Mbit
+ case 0xCE25: // Super Street Fighter 2 (J) 40Mbit
+ case 0xE41D: // Super Street Fighter 2 (E) 40Mbit
+ case 0xE017: // Super Street Fighter 2 (U) 40Mbit
cartSize = 0x500000;
break;
}
@@ -713,7 +757,7 @@ void getCartInfo_MD() {
idLockon[i] = char(sdBuffer[i]);
}
- if (!(strncmp("GM 00001009-0", idLockon, 13) & strncmp("GM 00004049-0", idLockon, 13) )) {
+ if (!(strncmp("GM 00001009-0", idLockon, 13) & strncmp("GM 00004049-0", idLockon, 13))) {
//Sonic1 ID:GM 00001009-0? or GM 00004049-0?
SnKmode = 2;
} else if (!(strcmp("GM 00001051-00", idLockon) & strcmp("GM 00001051-01", idLockon) & strcmp("GM 00001051-02", idLockon))) {
@@ -721,7 +765,7 @@ void getCartInfo_MD() {
SnKmode = 3;
// Prepare Sonic2 Banks
- writeSSF2Map(0x509878, 1); // 0xA130F1
+ writeSSF2Map(0x509878, 1); // 0xA130F1
} else if (!strcmp("GM MK-1079 -00", idLockon)) {
//Sonic3 ID:GM MK-1079 -00
@@ -745,7 +789,7 @@ void getCartInfo_MD() {
eepdata = pgm_read_word(eepid + index + 1);
eepType = eepdata & 0x7;
eepSize = eepdata & 0xFFF8;
- saveType = 4; // SERIAL EEPROM
+ saveType = 4; // SERIAL EEPROM
break;
}
}
@@ -754,7 +798,7 @@ void getCartInfo_MD() {
// Other non-save carts might have the same blank chksum
// Check header for Serial EEPROM Data
if (chksum == 0x0000) {
- if (readWord_MD(0xD9) != 0xE840) { // NOT SERIAL EEPROM
+ if (readWord_MD(0xD9) != 0xE840) { // NOT SERIAL EEPROM
eepType = 0;
eepSize = 0;
saveType = 0;
@@ -766,7 +810,7 @@ void getCartInfo_MD() {
// Carts with checksum 0x165E or 0x168B could be EEPROM or non-EEPROM
// Check the first DWORD in ROM (0x444E4C44) to identify the EEPROM carts
if ((chksum == 0x165E) || (chksum == 0x168B)) {
- if (readWord_MD(0x00) != 0x444E) { // NOT SERIAL EEPROM
+ if (readWord_MD(0x00) != 0x444E) { // NOT SERIAL EEPROM
eepType = 0;
eepSize = 0;
saveType = 0;
@@ -777,12 +821,12 @@ void getCartInfo_MD() {
// 4 = 128KB (2045 Blocks) Sega CD Backup RAM Cart
// 6 = 512KB (8189 Blocks) Ultra CD Backup RAM Cart (Aftermarket)
word bramCheck = readWord_MD(0x00);
- if ( (((bramCheck & 0xFF) == 0x04) && ((chksum & 0xFF) == 0x04))
- || (((bramCheck & 0xFF) == 0x06) && ((chksum & 0xFF) == 0x06))) {
+ if ((((bramCheck & 0xFF) == 0x04) && ((chksum & 0xFF) == 0x04))
+ || (((bramCheck & 0xFF) == 0x06) && ((chksum & 0xFF) == 0x06))) {
unsigned long p = 1 << (bramCheck & 0xFF);
bramSize = p * 0x2000L;
}
- if (saveType != 4) { // NOT SERIAL EEPROM
+ if (saveType != 4) { // NOT SERIAL EEPROM
// Check if cart has sram
saveType = 0;
sramSize = 0;
@@ -793,30 +837,28 @@ void getCartInfo_MD() {
// 0x5241E020 SRAM (BOTH BYTES)
if (readWord_MD(0xD8) == 0x5241) {
word sramType = readWord_MD(0xD9);
- if ((sramType == 0xF820) || (sramType == 0xF840)) { // SRAM/FRAM ODD/EVEN BYTES
+ if ((sramType == 0xF820) || (sramType == 0xF840)) { // SRAM/FRAM ODD/EVEN BYTES
// Get sram start and end
sramBase = ((long(readWord_MD(0xDA)) << 16) | readWord_MD(0xDB));
sramEnd = ((long(readWord_MD(0xDC)) << 16) | readWord_MD(0xDD));
- if (sramBase == 0x20000020 && sramEnd == 0x00010020) { // Fix for Psy-o-blade
+ if (sramBase == 0x20000020 && sramEnd == 0x00010020) { // Fix for Psy-o-blade
sramBase = 0x200001;
sramEnd = 0x203fff;
}
// Check alignment of sram
- if ((sramBase == 0x200001) || (sramBase == 0x300001)) { // ADDED 0x300001 FOR HARDBALL '95 (U)
+ if ((sramBase == 0x200001) || (sramBase == 0x300001)) { // ADDED 0x300001 FOR HARDBALL '95 (U)
// low byte
- saveType = 1; // ODD
+ saveType = 1; // ODD
sramSize = (sramEnd - sramBase + 2) / 2;
// Right shift sram base address so [A21] is set to high 0x200000 = 0b001[0]00000000000000000000
sramBase = sramBase >> 1;
- }
- else if (sramBase == 0x200000) {
+ } else if (sramBase == 0x200000) {
// high byte
- saveType = 2; // EVEN
+ saveType = 2; // EVEN
sramSize = (sramEnd - sramBase + 1) / 2;
// Right shift sram base address so [A21] is set to high 0x200000 = 0b001[0]00000000000000000000
sramBase = sramBase / 2;
- }
- else {
+ } else {
print_Msg(("sramType: "));
print_Msg_PaddedHex16(sramType);
println_Msg(F(""));
@@ -828,23 +870,20 @@ void getCartInfo_MD() {
println_Msg(F(""));
print_Error(F("Unknown Sram Base"), true);
}
- }
- else if (sramType == 0xE020) { // SRAM BOTH BYTES
+ } else if (sramType == 0xE020) { // SRAM BOTH BYTES
// Get sram start and end
sramBase = ((long(readWord_MD(0xDA)) << 16) | readWord_MD(0xDB));
sramEnd = ((long(readWord_MD(0xDC)) << 16) | readWord_MD(0xDD));
if (sramBase == 0x200001) {
- saveType = 3; // BOTH
+ saveType = 3; // BOTH
sramSize = sramEnd - sramBase + 2;
sramBase = sramBase >> 1;
- }
- else if (sramBase == 0x200000) {
- saveType = 3; // BOTH
+ } else if (sramBase == 0x200000) {
+ saveType = 3; // BOTH
sramSize = sramEnd - sramBase + 1;
sramBase = sramBase >> 1;
- }
- else {
+ } else {
print_Msg(("sramType: "));
print_Msg_PaddedHex16(sramType);
println_Msg(F(""));
@@ -857,45 +896,44 @@ void getCartInfo_MD() {
print_Error(F("Unknown Sram Base"), true);
}
}
- }
- else {
+ } else {
// SRAM CARTS WITH BAD/MISSING HEADER SAVE DATA
switch (chksum) {
- case 0xC2DB: // Winter Challenge (UE)
- saveType = 1; // ODD
+ case 0xC2DB: // Winter Challenge (UE)
+ saveType = 1; // ODD
sramBase = 0x200001;
sramEnd = 0x200FFF;
break;
- case 0xD7B6: // Buck Rogers: Countdown to Doomsday (UE)
- case 0xFE3E: // NBA Live '98 (U)
- case 0xFDAD: // NFL '94 starring Joe Montana (U)
- case 0x632E: // PGA Tour Golf (UE) (Rev 1)
- case 0xD2BA: // PGA Tour Golf (UE) (Rev 2)
- case 0x44FE: // Super Hydlide (J)
- saveType = 1; // ODD
+ case 0xD7B6: // Buck Rogers: Countdown to Doomsday (UE)
+ case 0xFE3E: // NBA Live '98 (U)
+ case 0xFDAD: // NFL '94 starring Joe Montana (U)
+ case 0x632E: // PGA Tour Golf (UE) (Rev 1)
+ case 0xD2BA: // PGA Tour Golf (UE) (Rev 2)
+ case 0x44FE: // Super Hydlide (J)
+ saveType = 1; // ODD
sramBase = 0x200001;
sramEnd = 0x203FFF;
break;
- case 0xDB5E: // Might & Magic: Gates to Another World (UE) (Rev 1)
- case 0x3428: // Starflight (UE) (Rev 0)
- case 0x43EE: // Starflight (UE) (Rev 1)
- saveType = 3; // BOTH
+ case 0xDB5E: // Might & Magic: Gates to Another World (UE) (Rev 1)
+ case 0x3428: // Starflight (UE) (Rev 0)
+ case 0x43EE: // Starflight (UE) (Rev 1)
+ saveType = 3; // BOTH
sramBase = 0x200001;
sramEnd = 0x207FFF;
break;
- case 0xBF72: // College Football USA '96 (U)
- case 0x72EF: // FIFA Soccer '97 (UE)
- case 0xD723: // Hardball III (U)
- case 0x06C1: // Madden NFL '98 (U)
- case 0xDB17: // NHL '96 (UE)
- case 0x5B3A: // NHL '98 (U)
- case 0x2CF2: // NFL Sports Talk Football '93 starring Joe Montana (UE)
- case 0xE9B1: // Summer Challenge (U)
- case 0xEEE8: // Test Drive II: The Duel (U)
- saveType = 1; // ODD
+ case 0xBF72: // College Football USA '96 (U)
+ case 0x72EF: // FIFA Soccer '97 (UE)
+ case 0xD723: // Hardball III (U)
+ case 0x06C1: // Madden NFL '98 (U)
+ case 0xDB17: // NHL '96 (UE)
+ case 0x5B3A: // NHL '98 (U)
+ case 0x2CF2: // NFL Sports Talk Football '93 starring Joe Montana (UE)
+ case 0xE9B1: // Summer Challenge (U)
+ case 0xEEE8: // Test Drive II: The Duel (U)
+ saveType = 1; // ODD
sramBase = 0x200001;
sramEnd = 0x20FFFF;
break;
@@ -903,8 +941,7 @@ void getCartInfo_MD() {
if (saveType == 1) {
sramSize = (sramEnd - sramBase + 2) / 2;
sramBase = sramBase >> 1;
- }
- else if (saveType == 3) {
+ } else if (saveType == 3) {
sramSize = sramEnd - sramBase + 2;
sramBase = sramBase >> 1;
}
@@ -960,11 +997,10 @@ void getCartInfo_MD() {
case 4: strcat(romName, "SONIC3"); break;
case 5: strcat(romName, romNameLockon); break;
}
-
}
// Realtec Mapper Check
- word realtecCheck1 = readWord_MD(0x3F080); // 0x7E100 "SEGA" (BootROM starts at 0x7E000)
+ word realtecCheck1 = readWord_MD(0x3F080); // 0x7E100 "SEGA" (BootROM starts at 0x7E000)
word realtecCheck2 = readWord_MD(0x3F081);
if ((realtecCheck1 == 0x5345) && (realtecCheck2 == 0x4741)) {
realtec = 1;
@@ -987,19 +1023,19 @@ void getCartInfo_MD() {
println_Msg(bramSize >> 10);
}
print_Msg(F("Size: "));
- print_Msg(cartSize * 8 / 1024 / 1024 );
+ print_Msg(cartSize * 8 / 1024 / 1024);
switch (SnKmode) {
case 2:
case 4:
case 5:
print_Msg(F("+"));
- print_Msg(cartSizeLockon * 8 / 1024 / 1024 );
+ print_Msg(cartSizeLockon * 8 / 1024 / 1024);
break;
case 3:
print_Msg(F("+"));
- print_Msg(cartSizeLockon * 8 / 1024 / 1024 );
+ print_Msg(cartSizeLockon * 8 / 1024 / 1024);
print_Msg(F("+"));
- print_Msg(cartSizeSonic2 * 8 / 1024 / 1024 );
+ print_Msg(cartSizeSonic2 * 8 / 1024 / 1024);
break;
}
println_Msg(F(" MBit"));
@@ -1028,14 +1064,12 @@ void getCartInfo_MD() {
print_Msg(F("Serial EEPROM: "));
print_Msg(eepSize * 8 / 1024);
println_Msg(F(" KBit"));
- }
- else {
+ } else {
print_Msg(F("Sram: "));
if (sramSize > 0) {
print_Msg(sramSize * 8 / 1024);
println_Msg(F(" KBit"));
- }
- else
+ } else
println_Msg(F("None"));
}
println_Msg(F(" "));
@@ -1064,7 +1098,8 @@ void writeSSF2Map(unsigned long myAddress, word myData) {
// Arduino running at 16Mhz -> one nop = 62.5ns
// Wait till output is stable
- __asm__("nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t");
// Strobe TIME(PJ0) LOW to latch the data
PORTJ &= ~(1 << 0);
@@ -1072,7 +1107,18 @@ void writeSSF2Map(unsigned long myAddress, word myData) {
PORTH &= ~(1 << 5);
// Leave WR low for at least 200ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Switch WR(PH5) to HIGH
PORTH |= (1 << 5);
@@ -1129,8 +1175,8 @@ void readROM_MD() {
// Prepare SSF2 Banks
if (cartSize > 0x400000) {
- writeSSF2Map(0x50987E, 6); // 0xA130FD
- writeSSF2Map(0x50987F, 7); // 0xA130FF
+ writeSSF2Map(0x50987E, 6); // 0xA130FD
+ writeSSF2Map(0x50987F, 7); // 0xA130FF
}
byte offsetSSF2Bank = 0;
word d = 0;
@@ -1138,8 +1184,8 @@ void readROM_MD() {
//Initialize progress bar
uint32_t processedProgressBar = 0;
uint32_t totalProgressBar = (uint32_t)(cartSize);
- if (SnKmode >= 2) totalProgressBar += (uint32_t) cartSizeLockon;
- if (SnKmode == 3) totalProgressBar += (uint32_t) cartSizeSonic2;
+ if (SnKmode >= 2) totalProgressBar += (uint32_t)cartSizeLockon;
+ if (SnKmode == 3) totalProgressBar += (uint32_t)cartSizeSonic2;
draw_progressbar(0, totalProgressBar);
for (unsigned long currBuffer = 0; currBuffer < cartSize / 2; currBuffer += 512) {
@@ -1148,11 +1194,10 @@ void readROM_MD() {
blinkLED();
if ((currBuffer == 0x200000) && (cartSize > 0x400000)) {
- writeSSF2Map(0x50987E, 8); // 0xA130FD
+ writeSSF2Map(0x50987E, 8); // 0xA130FD
offsetSSF2Bank = 1;
- }
- else if ((currBuffer == 0x240000) && (cartSize > 0x400000)) {
- writeSSF2Map(0x50987F, 9); // 0xA130FF
+ } else if ((currBuffer == 0x240000) && (cartSize > 0x400000)) {
+ writeSSF2Map(0x50987F, 9); // 0xA130FF
offsetSSF2Bank = 1;
}
@@ -1171,10 +1216,15 @@ void readROM_MD() {
// Setting OE(PH6) LOW
PORTH &= ~(1 << 6);
// most MD ROMs are 200ns, comparable to SNES > use similar access delay of 6 x 62.5 = 375ns
- NOP; NOP; NOP; NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
// Read
- buffer[d] = PINA;
+ buffer[d] = PINA;
buffer[d + 1] = PINC;
// Setting CS(PH3) HIGH
@@ -1215,10 +1265,15 @@ void readROM_MD() {
// Setting OE(PH6) LOW
PORTH &= ~(1 << 6);
// most MD ROMs are 200ns, comparable to SNES > use similar access delay of 6 x 62.5 = 375ns
- NOP; NOP; NOP; NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
// Read
- buffer[d] = PINA;
+ buffer[d] = PINA;
buffer[d + 1] = PINC;
// Setting CS(PH3) HIGH
@@ -1260,10 +1315,15 @@ void readROM_MD() {
// Setting OE(PH6) LOW
PORTH &= ~(1 << 6);
// most MD ROMs are 200ns, comparable to SNES > use similar access delay of 6 x 62.5 = 375ns
- NOP; NOP; NOP; NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
// Read
- buffer[d] = PINA;
+ buffer[d] = PINA;
buffer[d + 1] = PINC;
// Setting CS(PH3) HIGH
@@ -1286,8 +1346,8 @@ void readROM_MD() {
// Reset SSF2 Banks
if (cartSize > 0x400000) {
- writeSSF2Map(0x50987E, 6); // 0xA130FD
- writeSSF2Map(0x50987F, 7); // 0xA130FF
+ writeSSF2Map(0x50987E, 6); // 0xA130FD
+ writeSSF2Map(0x50987F, 7); // 0xA130FF
}
// print elapsed time
@@ -1302,8 +1362,7 @@ void readROM_MD() {
if (chksum == calcCKS) {
println_Msg(F("OK"));
display_Update();
- }
- else {
+ } else {
println_Msg(F("Error"));
char calcsumStr[5];
sprintf(calcsumStr, "%04X", calcCKS);
@@ -1312,7 +1371,7 @@ void readROM_MD() {
display_Update();
}
- // Calculate and compare CRC32 with no-intro
+ // Calculate and compare CRC32 with nointro
if (readWord_MD(0x105) == 0x3332)
//database, crcString, renamerom, offset
compareCRC("32x.txt", 0, 1, 0);
@@ -1324,8 +1383,7 @@ void readROM_MD() {
if (chksumLockon == calcCKSLockon) {
println_Msg(F("Checksum2 OK"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Checksum2 Error: "));
char calcsumStr[5];
sprintf(calcsumStr, "%04X", calcCKSLockon);
@@ -1338,8 +1396,7 @@ void readROM_MD() {
if (chksumSonic2 == calcCKSSonic2) {
println_Msg(F("Checksum3 OK"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Checksum3 Error: "));
char calcsumStr[5];
sprintf(calcsumStr, "%04X", calcCKSSonic2);
@@ -1362,10 +1419,20 @@ void enableSram_MD(boolean enableSram) {
// Strobe TIME(PJ0) LOW to latch the data
PORTJ &= ~(1 << 0);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Set TIME(PJ0) HIGH
PORTJ |= (1 << 0);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
dataIn_MD();
}
@@ -1411,16 +1478,14 @@ void writeSram_MD() {
data |= (myFile.read() & 0xFF);
writeWord_MD(currByte, data);
}
- }
- else
+ } else
print_Error(F("Unknown save type"), false);
// Close the file:
myFile.close();
println_Msg(F("Done"));
display_Update();
- }
- else {
+ } else {
print_Error(F("SD Error"), true);
}
dataIn_MD();
@@ -1456,13 +1521,12 @@ void readSram_MD() {
if (saveType == 2) {
// Only use the upper byte
if (segaSram16bit > 0) {
- sdBuffer[(currWord * 2) + 0] = (( myWord >> 8 ) & 0xFF);
- sdBuffer[(currWord * 2) + 1] = (( myWord >> 8 ) & 0xFF);
+ sdBuffer[(currWord * 2) + 0] = ((myWord >> 8) & 0xFF);
+ sdBuffer[(currWord * 2) + 1] = ((myWord >> 8) & 0xFF);
} else {
- sdBuffer[currWord] = (( myWord >> 8 ) & 0xFF);
+ sdBuffer[currWord] = ((myWord >> 8) & 0xFF);
}
- }
- else if (saveType == 1) {
+ } else if (saveType == 1) {
// Only use the lower byte
if (segaSram16bit > 0) {
sdBuffer[(currWord * 2) + 0] = (myWord & 0xFF);
@@ -1470,9 +1534,8 @@ void readSram_MD() {
} else {
sdBuffer[currWord] = (myWord & 0xFF);
}
- }
- else if (saveType == 3) { // BOTH
- sdBuffer[currWord * 2] = (( myWord >> 8 ) & 0xFF);
+ } else if (saveType == 3) { // BOTH
+ sdBuffer[currWord * 2] = ((myWord >> 8) & 0xFF);
sdBuffer[(currWord * 2) + 1] = (myWord & 0xFF);
}
}
@@ -1487,7 +1550,7 @@ void readSram_MD() {
sdBuffer[i] = 0xFF;
}
unsigned long padsize = (1UL << 16) - (sramSize << 1);
- unsigned long padblockcount = padsize >> 9; // number of 512 byte blocks
+ unsigned long padblockcount = padsize >> 9; // number of 512 byte blocks
for (int i = 0; i < padblockcount; i++) {
myFile.write(sdBuffer, 512);
}
@@ -1512,14 +1575,12 @@ unsigned long verifySram_MD() {
if (saveType == 2) {
// Only use the upper byte
- sdBuffer[currWord * 2] = (( myWord >> 8 ) & 0xFF);
- }
- else if (saveType == 1) {
+ sdBuffer[currWord * 2] = ((myWord >> 8) & 0xFF);
+ } else if (saveType == 1) {
// Only use the lower byte
sdBuffer[currWord * 2] = (myWord & 0xFF);
- }
- else if (saveType == 3) { // BOTH
- sdBuffer[(currWord * 2) + 0] = (( myWord >> 8 ) & 0xFF);
+ } else if (saveType == 3) { // BOTH
+ sdBuffer[(currWord * 2) + 0] = ((myWord >> 8) & 0xFF);
sdBuffer[(currWord * 2) + 1] = (myWord & 0xFF);
}
}
@@ -1543,8 +1604,7 @@ unsigned long verifySram_MD() {
// Close the file:
myFile.close();
- }
- else {
+ } else {
print_Error(F("SD Error"), true);
}
// Return 0 if verified ok, or number of errors
@@ -1603,7 +1663,7 @@ void write29F1610_MD() {
// Write one full page at a time
for (byte c = 0; c < 64; c++) {
- word currWord = ( ( sdBuffer[d] & 0xFF ) << 8 ) | ( sdBuffer[d + 1] & 0xFF );
+ word currWord = ((sdBuffer[d] & 0xFF) << 8) | (sdBuffer[d + 1] & 0xFF);
writeFlash_MD(currByte + c, currWord);
d += 2;
}
@@ -1619,8 +1679,7 @@ void write29F1610_MD() {
// Close the file:
myFile.close();
- }
- else {
+ } else {
println_Msg(F("Can't open file"));
display_Update();
}
@@ -1723,8 +1782,7 @@ void verifyFlash_MD() {
if (blank == 0) {
println_Msg(F("Flashrom verified OK"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Error: "));
print_Msg(blank);
println_Msg(F(" bytes "));
@@ -1732,8 +1790,7 @@ void verifyFlash_MD() {
}
// Close the file:
myFile.close();
- }
- else {
+ } else {
println_Msg(F("Can't open file"));
display_Update();
}
@@ -1759,20 +1816,42 @@ void busyCheck_MD() {
//******************************************
// EEPROM Functions
//******************************************
-void EepromInit(byte eepmode) { // Acclaim Type 2
- PORTF = 0x00; // ADDR A0-A7
- PORTK = 0x00; // ADDR A8-A15
- PORTL = 0x10; // ADDR A16-A23
- PORTA = 0x00; // DATA D8-D15
- PORTH |= (1 << 0); // /RES HIGH
-
- PORTC = eepmode; // EEPROM Switch: 0 = Enable (Read EEPROM), 1 = Disable (Read ROM)
- PORTH &= ~(1 << 3); // CE LOW
- PORTH &= ~(1 << 4) & ~(1 << 5); // /UDSW + /LDSW LOW
- PORTH |= (1 << 6); // OE HIGH
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
- PORTH |= (1 << 4) | (1 << 5); // /UDSW + /LDSW HIGH
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+void EepromInit(byte eepmode) { // Acclaim Type 2
+ PORTF = 0x00; // ADDR A0-A7
+ PORTK = 0x00; // ADDR A8-A15
+ PORTL = 0x10; // ADDR A16-A23
+ PORTA = 0x00; // DATA D8-D15
+ PORTH |= (1 << 0); // /RES HIGH
+
+ PORTC = eepmode; // EEPROM Switch: 0 = Enable (Read EEPROM), 1 = Disable (Read ROM)
+ PORTH &= ~(1 << 3); // CE LOW
+ PORTH &= ~(1 << 4) & ~(1 << 5); // /UDSW + /LDSW LOW
+ PORTH |= (1 << 6); // OE HIGH
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
+ PORTH |= (1 << 4) | (1 << 5); // /UDSW + /LDSW HIGH
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
}
void writeWord_SDA(unsigned long myAddress, word myData) { /* D0 goes to /SDA when only /LWR is asserted */
@@ -1780,17 +1859,39 @@ void writeWord_SDA(unsigned long myAddress, word myData) { /* D0 goes to /SDA wh
PORTK = (myAddress >> 8) & 0xFF;
PORTL = (myAddress >> 16) & 0xFF;
PORTC = myData;
- PORTH &= ~(1 << 3); // CE LOW
- PORTH &= ~(1 << 5); // /LDSW LOW
- PORTH |= (1 << 4); // /UDSW HIGH
- PORTH |= (1 << 6); // OE HIGH
+ PORTH &= ~(1 << 3); // CE LOW
+ PORTH &= ~(1 << 5); // /LDSW LOW
+ PORTH |= (1 << 4); // /UDSW HIGH
+ PORTH |= (1 << 6); // OE HIGH
if (eepSize > 0x100)
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
else
delayMicroseconds(100);
- PORTH |= (1 << 5); // /LDSW HIGH
+ PORTH |= (1 << 5); // /LDSW HIGH
if (eepSize > 0x100)
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
else
delayMicroseconds(100);
}
@@ -1800,22 +1901,44 @@ void writeWord_SCL(unsigned long myAddress, word myData) { /* D0 goes to /SCL wh
PORTK = (myAddress >> 8) & 0xFF;
PORTL = (myAddress >> 16) & 0xFF;
PORTC = myData;
- PORTH &= ~(1 << 3); // CE LOW
- PORTH &= ~(1 << 4); // /UDSW LOW
- PORTH |= (1 << 5); // /LDSW HIGH
- PORTH |= (1 << 6); // OE HIGH
+ PORTH &= ~(1 << 3); // CE LOW
+ PORTH &= ~(1 << 4); // /UDSW LOW
+ PORTH |= (1 << 5); // /LDSW HIGH
+ PORTH |= (1 << 6); // OE HIGH
if (eepSize > 0x100)
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
else
delayMicroseconds(100);
- PORTH |= (1 << 4); // /UDSW HIGH
+ PORTH |= (1 << 4); // /UDSW HIGH
if (eepSize > 0x100)
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
else
delayMicroseconds(100);
}
-void writeWord_CM(unsigned long myAddress, word myData) { // Codemasters
+void writeWord_CM(unsigned long myAddress, word myData) { // Codemasters
PORTF = myAddress & 0xFF;
PORTK = (myAddress >> 8) & 0xFF;
PORTL = (myAddress >> 16) & 0xFF;
@@ -1824,7 +1947,8 @@ void writeWord_CM(unsigned long myAddress, word myData) { // Codemasters
// Arduino running at 16Mhz -> one nop = 62.5ns
// Wait till output is stable
- __asm__("nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t");
// Switch WR(PH4) to LOW
PORTH &= ~(1 << 4);
@@ -1834,7 +1958,18 @@ void writeWord_CM(unsigned long myAddress, word myData) { // Codemasters
PORTH ^= (1 << 1);
// Leave WR low for at least 200ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Pulse CLK(PH1)
PORTH ^= (1 << 1);
@@ -1844,332 +1979,308 @@ void writeWord_CM(unsigned long myAddress, word myData) { // Codemasters
PORTH |= (1 << 4);
// Leave WR high for at least 50ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
}
// EEPROM COMMANDS
void EepromStart() {
- if (eepType == 2) { // Acclaim Type 2
- writeWord_SDA(0x100000, 0x00); // sda low
- writeWord_SCL(0x100000, 0x00); // scl low
- writeWord_SDA(0x100000, 0x01); // sda high
- writeWord_SCL(0x100000, 0x01); // scl high
- writeWord_SDA(0x100000, 0x00); // sda low
- writeWord_SCL(0x100000, 0x00); // scl low
- }
- else if (eepType == 4) { // EA
- writeWord_MD(0x100000, 0x00); // sda low, scl low
- writeWord_MD(0x100000, 0xC0); // sda, scl high
- writeWord_MD(0x100000, 0x40); // sda low, scl high
- writeWord_MD(0x100000, 0x00); // START
- }
- else if (eepType == 5) { // Codemasters
- writeWord_CM(0x180000, 0x00); // sda low, scl low
- writeWord_CM(0x180000, 0x02); // sda low, scl high
- writeWord_CM(0x180000, 0x03); // sda, scl high
- writeWord_CM(0x180000, 0x02); // sda low, scl high
- writeWord_CM(0x180000, 0x00); // START
- }
- else {
- writeWord_MD(0x100000, 0x00); // sda low, scl low
- writeWord_MD(0x100000, 0x03); // sda, scl high
- writeWord_MD(0x100000, 0x02); // sda low, scl high
- writeWord_MD(0x100000, 0x00); // START
+ if (eepType == 2) { // Acclaim Type 2
+ writeWord_SDA(0x100000, 0x00); // sda low
+ writeWord_SCL(0x100000, 0x00); // scl low
+ writeWord_SDA(0x100000, 0x01); // sda high
+ writeWord_SCL(0x100000, 0x01); // scl high
+ writeWord_SDA(0x100000, 0x00); // sda low
+ writeWord_SCL(0x100000, 0x00); // scl low
+ } else if (eepType == 4) { // EA
+ writeWord_MD(0x100000, 0x00); // sda low, scl low
+ writeWord_MD(0x100000, 0xC0); // sda, scl high
+ writeWord_MD(0x100000, 0x40); // sda low, scl high
+ writeWord_MD(0x100000, 0x00); // START
+ } else if (eepType == 5) { // Codemasters
+ writeWord_CM(0x180000, 0x00); // sda low, scl low
+ writeWord_CM(0x180000, 0x02); // sda low, scl high
+ writeWord_CM(0x180000, 0x03); // sda, scl high
+ writeWord_CM(0x180000, 0x02); // sda low, scl high
+ writeWord_CM(0x180000, 0x00); // START
+ } else {
+ writeWord_MD(0x100000, 0x00); // sda low, scl low
+ writeWord_MD(0x100000, 0x03); // sda, scl high
+ writeWord_MD(0x100000, 0x02); // sda low, scl high
+ writeWord_MD(0x100000, 0x00); // START
}
}
void EepromSet0() {
- if (eepType == 2) { // Acclaim Type 2
- writeWord_SDA(0x100000, 0x00); // sda low
- writeWord_SCL(0x100000, 0x01); // scl high
- writeWord_SDA(0x100000, 0x00); // sda low
- writeWord_SCL(0x100000, 0x00); // scl low
- }
- else if (eepType == 4) { // EA
- writeWord_MD(0x100000, 0x00); // sda low, scl low
- writeWord_MD(0x100000, 0x40); // sda low, scl high // 0
- writeWord_MD(0x100000, 0x00); // sda low, scl low
- }
- else if (eepType == 5) { // Codemasters
- writeWord_CM(0x180000, 0x00); // sda low, scl low
- writeWord_CM(0x180000, 0x02); // sda low, scl high // 0
- writeWord_CM(0x180000, 0x00); // sda low, scl low
- }
- else {
- writeWord_MD(0x100000, 0x00); // sda low, scl low
- writeWord_MD(0x100000, 0x02); // sda low, scl high // 0
- writeWord_MD(0x100000, 0x00); // sda low, scl low
+ if (eepType == 2) { // Acclaim Type 2
+ writeWord_SDA(0x100000, 0x00); // sda low
+ writeWord_SCL(0x100000, 0x01); // scl high
+ writeWord_SDA(0x100000, 0x00); // sda low
+ writeWord_SCL(0x100000, 0x00); // scl low
+ } else if (eepType == 4) { // EA
+ writeWord_MD(0x100000, 0x00); // sda low, scl low
+ writeWord_MD(0x100000, 0x40); // sda low, scl high // 0
+ writeWord_MD(0x100000, 0x00); // sda low, scl low
+ } else if (eepType == 5) { // Codemasters
+ writeWord_CM(0x180000, 0x00); // sda low, scl low
+ writeWord_CM(0x180000, 0x02); // sda low, scl high // 0
+ writeWord_CM(0x180000, 0x00); // sda low, scl low
+ } else {
+ writeWord_MD(0x100000, 0x00); // sda low, scl low
+ writeWord_MD(0x100000, 0x02); // sda low, scl high // 0
+ writeWord_MD(0x100000, 0x00); // sda low, scl low
}
}
void EepromSet1() {
- if (eepType == 2) { // Acclaim Type 2
- writeWord_SDA(0x100000, 0x01); // sda high
- writeWord_SCL(0x100000, 0x01); // scl high
- writeWord_SDA(0x100000, 0x01); // sda high
- writeWord_SCL(0x100000, 0x00); // scl low
- }
- else if (eepType == 4) { // EA
- writeWord_MD(0x100000, 0x80); // sda high, scl low
- writeWord_MD(0x100000, 0xC0); // sda high, scl high // 1
- writeWord_MD(0x100000, 0x80); // sda high, scl low
- writeWord_MD(0x100000, 0x00); // sda low, scl low
- }
- else if (eepType == 5) { // Codemasters
- writeWord_CM(0x180000, 0x01); // sda high, scl low
- writeWord_CM(0x180000, 0x03); // sda high, scl high // 1
- writeWord_CM(0x180000, 0x01); // sda high, scl low
- writeWord_CM(0x180000, 0x00); // sda low, scl low
- }
- else {
- writeWord_MD(0x100000, 0x01); // sda high, scl low
- writeWord_MD(0x100000, 0x03); // sda high, scl high // 1
- writeWord_MD(0x100000, 0x01); // sda high, scl low
- writeWord_MD(0x100000, 0x00); // sda low, scl low
+ if (eepType == 2) { // Acclaim Type 2
+ writeWord_SDA(0x100000, 0x01); // sda high
+ writeWord_SCL(0x100000, 0x01); // scl high
+ writeWord_SDA(0x100000, 0x01); // sda high
+ writeWord_SCL(0x100000, 0x00); // scl low
+ } else if (eepType == 4) { // EA
+ writeWord_MD(0x100000, 0x80); // sda high, scl low
+ writeWord_MD(0x100000, 0xC0); // sda high, scl high // 1
+ writeWord_MD(0x100000, 0x80); // sda high, scl low
+ writeWord_MD(0x100000, 0x00); // sda low, scl low
+ } else if (eepType == 5) { // Codemasters
+ writeWord_CM(0x180000, 0x01); // sda high, scl low
+ writeWord_CM(0x180000, 0x03); // sda high, scl high // 1
+ writeWord_CM(0x180000, 0x01); // sda high, scl low
+ writeWord_CM(0x180000, 0x00); // sda low, scl low
+ } else {
+ writeWord_MD(0x100000, 0x01); // sda high, scl low
+ writeWord_MD(0x100000, 0x03); // sda high, scl high // 1
+ writeWord_MD(0x100000, 0x01); // sda high, scl low
+ writeWord_MD(0x100000, 0x00); // sda low, scl low
}
}
-void EepromDevice() { // 24C02+
+void EepromDevice() { // 24C02+
EepromSet1();
EepromSet0();
EepromSet1();
EepromSet0();
}
-void EepromSetDeviceAddress(word addrhi) { // 24C02+
+void EepromSetDeviceAddress(word addrhi) { // 24C02+
for (int i = 0; i < 3; i++) {
- if ((addrhi >> 2) & 0x1) // Bit is HIGH
+ if ((addrhi >> 2) & 0x1) // Bit is HIGH
EepromSet1();
- else // Bit is LOW
+ else // Bit is LOW
EepromSet0();
- addrhi <<= 1; // rotate to the next bit
+ addrhi <<= 1; // rotate to the next bit
}
}
-void EepromStatus() { // ACK
+void EepromStatus() { // ACK
byte eepStatus = 1;
- if (eepType == 1) { // Acclaim Type 1
- writeWord_MD(0x100000, 0x01); // sda high, scl low
- writeWord_MD(0x100000, 0x03); // sda high, scl high
+ if (eepType == 1) { // Acclaim Type 1
+ writeWord_MD(0x100000, 0x01); // sda high, scl low
+ writeWord_MD(0x100000, 0x03); // sda high, scl high
do {
dataIn_MD();
eepStatus = ((readWord_MD(0x100000) >> 1) & 0x1);
dataOut_MD();
delayMicroseconds(4);
- }
- while (eepStatus == 1);
- writeWord_MD(0x100000, 0x01); // sda high, scl low
- }
- else if (eepType == 2) { // Acclaim Type 2
- writeWord_SDA(0x100000, 0x01); // sda high
- writeWord_SCL(0x100000, 0x01); // scl high
+ } while (eepStatus == 1);
+ writeWord_MD(0x100000, 0x01); // sda high, scl low
+ } else if (eepType == 2) { // Acclaim Type 2
+ writeWord_SDA(0x100000, 0x01); // sda high
+ writeWord_SCL(0x100000, 0x01); // scl high
do {
dataIn_MD();
eepStatus = (readWord_MD(0x100000) & 0x1);
dataOut_MD();
delayMicroseconds(4);
- }
- while (eepStatus == 1);
- writeWord_SCL(0x100000, 0x00); // scl low
- }
- else if (eepType == 3) { // Capcom/Sega
- writeWord_MD(0x100000, 0x01); // sda high, scl low
- writeWord_MD(0x100000, 0x03); // sda high, scl high
+ } while (eepStatus == 1);
+ writeWord_SCL(0x100000, 0x00); // scl low
+ } else if (eepType == 3) { // Capcom/Sega
+ writeWord_MD(0x100000, 0x01); // sda high, scl low
+ writeWord_MD(0x100000, 0x03); // sda high, scl high
do {
dataIn_MD();
eepStatus = (readWord_MD(0x100000) & 0x1);
dataOut_MD();
delayMicroseconds(4);
- }
- while (eepStatus == 1);
- writeWord_MD(0x100000, 0x01); // sda high, scl low
- }
- else if (eepType == 4) { // EA
- writeWord_MD(0x100000, 0x80); // sda high, scl low
- writeWord_MD(0x100000, 0xC0); // sda high, scl high
+ } while (eepStatus == 1);
+ writeWord_MD(0x100000, 0x01); // sda high, scl low
+ } else if (eepType == 4) { // EA
+ writeWord_MD(0x100000, 0x80); // sda high, scl low
+ writeWord_MD(0x100000, 0xC0); // sda high, scl high
do {
dataIn_MD();
eepStatus = ((readWord_MD(0x100000) >> 7) & 0x1);
dataOut_MD();
delayMicroseconds(4);
- }
- while (eepStatus == 1);
- writeWord_MD(0x100000, 0x80); // sda high, scl low
- }
- else if (eepType == 5) { // Codemasters
- writeWord_CM(0x180000, 0x01); // sda high, scl low
- writeWord_CM(0x180000, 0x03); // sda high, scl high
+ } while (eepStatus == 1);
+ writeWord_MD(0x100000, 0x80); // sda high, scl low
+ } else if (eepType == 5) { // Codemasters
+ writeWord_CM(0x180000, 0x01); // sda high, scl low
+ writeWord_CM(0x180000, 0x03); // sda high, scl high
do {
dataIn_MD();
eepStatus = ((readWord_MD(0x1C0000) >> 7) & 0x1);
dataOut_MD();
delayMicroseconds(4);
- }
- while (eepStatus == 1);
- writeWord_CM(0x180000, 0x01); // sda high, scl low
+ } while (eepStatus == 1);
+ writeWord_CM(0x180000, 0x01); // sda high, scl low
}
}
void EepromReadMode() {
- EepromSet1(); // READ
- EepromStatus(); // ACK
+ EepromSet1(); // READ
+ EepromStatus(); // ACK
}
void EepromWriteMode() {
- EepromSet0(); // WRITE
- EepromStatus(); // ACK
+ EepromSet0(); // WRITE
+ EepromStatus(); // ACK
}
void EepromReadData() {
- if (eepType == 1) { // Acclaim Type 1
+ if (eepType == 1) { // Acclaim Type 1
for (int i = 0; i < 8; i++) {
- writeWord_MD(0x100000, 0x03); // sda high, scl high
+ writeWord_MD(0x100000, 0x03); // sda high, scl high
dataIn_MD();
- eepbit[i] = ((readWord_MD(0x100000) >> 1) & 0x1); // Read 0x100000 with Mask 0x1 (bit 1)
+ eepbit[i] = ((readWord_MD(0x100000) >> 1) & 0x1); // Read 0x100000 with Mask 0x1 (bit 1)
dataOut_MD();
- writeWord_MD(0x100000, 0x01); // sda high, scl low
+ writeWord_MD(0x100000, 0x01); // sda high, scl low
}
- }
- else if (eepType == 2) { // Acclaim Type 2
+ } else if (eepType == 2) { // Acclaim Type 2
for (int i = 0; i < 8; i++) {
- writeWord_SDA(0x100000, 0x01); // sda high
- writeWord_SCL(0x100000, 0x01); // scl high
+ writeWord_SDA(0x100000, 0x01); // sda high
+ writeWord_SCL(0x100000, 0x01); // scl high
dataIn_MD();
- eepbit[i] = (readWord_MD(0x100000) & 0x1); // Read 0x100000 with Mask 0x1 (bit 0)
+ eepbit[i] = (readWord_MD(0x100000) & 0x1); // Read 0x100000 with Mask 0x1 (bit 0)
dataOut_MD();
- writeWord_SDA(0x100000, 0x01); // sda high
- writeWord_SCL(0x100000, 0x00); // scl low
+ writeWord_SDA(0x100000, 0x01); // sda high
+ writeWord_SCL(0x100000, 0x00); // scl low
}
- }
- else if (eepType == 3) { // Capcom/Sega
+ } else if (eepType == 3) { // Capcom/Sega
for (int i = 0; i < 8; i++) {
- writeWord_MD(0x100000, 0x03); // sda high, scl high
+ writeWord_MD(0x100000, 0x03); // sda high, scl high
dataIn_MD();
- eepbit[i] = (readWord_MD(0x100000) & 0x1); // Read 0x100000 with Mask 0x1 (bit 0)
+ eepbit[i] = (readWord_MD(0x100000) & 0x1); // Read 0x100000 with Mask 0x1 (bit 0)
dataOut_MD();
- writeWord_MD(0x100000, 0x01); // sda high, scl low
+ writeWord_MD(0x100000, 0x01); // sda high, scl low
}
- }
- else if (eepType == 4) { // EA
+ } else if (eepType == 4) { // EA
for (int i = 0; i < 8; i++) {
- writeWord_MD(0x100000, 0xC0); // sda high, scl high
+ writeWord_MD(0x100000, 0xC0); // sda high, scl high
dataIn_MD();
- eepbit[i] = ((readWord_MD(0x100000) >> 7) & 0x1); // Read 0x100000 with Mask (bit 7)
+ eepbit[i] = ((readWord_MD(0x100000) >> 7) & 0x1); // Read 0x100000 with Mask (bit 7)
dataOut_MD();
- writeWord_MD(0x100000, 0x80); // sda high, scl low
+ writeWord_MD(0x100000, 0x80); // sda high, scl low
}
- }
- else if (eepType == 5) { // Codemasters
+ } else if (eepType == 5) { // Codemasters
for (int i = 0; i < 8; i++) {
- writeWord_CM(0x180000, 0x03); // sda high, scl high
+ writeWord_CM(0x180000, 0x03); // sda high, scl high
dataIn_MD();
- eepbit[i] = ((readWord_MD(0x1C0000) >> 7) & 0x1); // Read 0x1C0000 with Mask 0x1 (bit 7)
+ eepbit[i] = ((readWord_MD(0x1C0000) >> 7) & 0x1); // Read 0x1C0000 with Mask 0x1 (bit 7)
dataOut_MD();
- writeWord_CM(0x180000, 0x01); // sda high, scl low
+ writeWord_CM(0x180000, 0x01); // sda high, scl low
}
}
}
void EepromWriteData(byte data) {
for (int i = 0; i < 8; i++) {
- if ((data >> 7) & 0x1) // Bit is HIGH
+ if ((data >> 7) & 0x1) // Bit is HIGH
EepromSet1();
- else // Bit is LOW
+ else // Bit is LOW
EepromSet0();
- data <<= 1; // rotate to the next bit
+ data <<= 1; // rotate to the next bit
}
- EepromStatus(); // ACK
+ EepromStatus(); // ACK
}
void EepromFinish() {
- if (eepType == 2) { // Acclaim Type 2
- writeWord_SDA(0x100000, 0x00); // sda low
- writeWord_SCL(0x100000, 0x00); // scl low
- writeWord_SDA(0x100000, 0x01); // sda high
- writeWord_SCL(0x100000, 0x00); // scl low
- writeWord_SDA(0x100000, 0x01); // sda high
- writeWord_SCL(0x100000, 0x01); // scl high
- writeWord_SDA(0x100000, 0x01); // sda high
- writeWord_SCL(0x100000, 0x00); // scl low
- writeWord_SDA(0x100000, 0x00); // sda low
- writeWord_SCL(0x100000, 0x00); // scl low
- }
- else if (eepType == 4) { // EA
- writeWord_MD(0x100000, 0x00); // sda low, scl low
- writeWord_MD(0x100000, 0x80); // sda high, scl low
- writeWord_MD(0x100000, 0xC0); // sda high, scl high
- writeWord_MD(0x100000, 0x80); // sda high, scl low
- writeWord_MD(0x100000, 0x00); // sda low, scl low
- }
- else if (eepType == 5) { // Codemasters
- writeWord_CM(0x180000, 0x00); // sda low, scl low
- writeWord_CM(0x180000, 0x01); // sda high, scl low
- writeWord_CM(0x180000, 0x03); // sda high, scl high
- writeWord_CM(0x180000, 0x01); // sda high, scl low
- writeWord_CM(0x180000, 0x00); // sda low, scl low
- }
- else {
- writeWord_MD(0x100000, 0x00); // sda low, scl low
- writeWord_MD(0x100000, 0x01); // sda high, scl low
- writeWord_MD(0x100000, 0x03); // sda high, scl high
- writeWord_MD(0x100000, 0x01); // sda high, scl low
- writeWord_MD(0x100000, 0x00); // sda low, scl low
+ if (eepType == 2) { // Acclaim Type 2
+ writeWord_SDA(0x100000, 0x00); // sda low
+ writeWord_SCL(0x100000, 0x00); // scl low
+ writeWord_SDA(0x100000, 0x01); // sda high
+ writeWord_SCL(0x100000, 0x00); // scl low
+ writeWord_SDA(0x100000, 0x01); // sda high
+ writeWord_SCL(0x100000, 0x01); // scl high
+ writeWord_SDA(0x100000, 0x01); // sda high
+ writeWord_SCL(0x100000, 0x00); // scl low
+ writeWord_SDA(0x100000, 0x00); // sda low
+ writeWord_SCL(0x100000, 0x00); // scl low
+ } else if (eepType == 4) { // EA
+ writeWord_MD(0x100000, 0x00); // sda low, scl low
+ writeWord_MD(0x100000, 0x80); // sda high, scl low
+ writeWord_MD(0x100000, 0xC0); // sda high, scl high
+ writeWord_MD(0x100000, 0x80); // sda high, scl low
+ writeWord_MD(0x100000, 0x00); // sda low, scl low
+ } else if (eepType == 5) { // Codemasters
+ writeWord_CM(0x180000, 0x00); // sda low, scl low
+ writeWord_CM(0x180000, 0x01); // sda high, scl low
+ writeWord_CM(0x180000, 0x03); // sda high, scl high
+ writeWord_CM(0x180000, 0x01); // sda high, scl low
+ writeWord_CM(0x180000, 0x00); // sda low, scl low
+ } else {
+ writeWord_MD(0x100000, 0x00); // sda low, scl low
+ writeWord_MD(0x100000, 0x01); // sda high, scl low
+ writeWord_MD(0x100000, 0x03); // sda high, scl high
+ writeWord_MD(0x100000, 0x01); // sda high, scl low
+ writeWord_MD(0x100000, 0x00); // sda low, scl low
}
}
void EepromStop() {
- if (eepType == 2) { // Acclaim Type 2
- writeWord_SDA(0x100000, 0x00); // sda low
- writeWord_SCL(0x100000, 0x01); // scl high
- writeWord_SDA(0x100000, 0x01); // sda high
- writeWord_SCL(0x100000, 0x01); // scl high
- writeWord_SDA(0x100000, 0x01); // sda high
- writeWord_SCL(0x100000, 0x00); // scl low
- writeWord_SDA(0x100000, 0x00); // sda low
- writeWord_SCL(0x100000, 0x00); // scl low // STOP
- }
- else if (eepType == 4) { // EA
- writeWord_MD(0x100000, 0x00); // sda, scl low
- writeWord_MD(0x100000, 0x40); // sda low, scl high
- writeWord_MD(0x100000, 0xC0); // sda, scl high
- writeWord_MD(0x100000, 0x80); // sda high, scl low
- writeWord_MD(0x100000, 0x00); // STOP
- }
- else if (eepType == 5) { // Codemasters
- writeWord_CM(0x180000, 0x00); // sda low, scl low
- writeWord_CM(0x180000, 0x02); // sda low, scl high
- writeWord_CM(0x180000, 0x03); // sda, scl high
- writeWord_CM(0x180000, 0x01); // sda high, scl low
- writeWord_CM(0x180000, 0x00); // STOP
- }
- else {
- writeWord_MD(0x100000, 0x00); // sda, scl low
- writeWord_MD(0x100000, 0x02); // sda low, scl high
- writeWord_MD(0x100000, 0x03); // sda, scl high
- writeWord_MD(0x100000, 0x01); // sda high, scl low
- writeWord_MD(0x100000, 0x00); // STOP
+ if (eepType == 2) { // Acclaim Type 2
+ writeWord_SDA(0x100000, 0x00); // sda low
+ writeWord_SCL(0x100000, 0x01); // scl high
+ writeWord_SDA(0x100000, 0x01); // sda high
+ writeWord_SCL(0x100000, 0x01); // scl high
+ writeWord_SDA(0x100000, 0x01); // sda high
+ writeWord_SCL(0x100000, 0x00); // scl low
+ writeWord_SDA(0x100000, 0x00); // sda low
+ writeWord_SCL(0x100000, 0x00); // scl low // STOP
+ } else if (eepType == 4) { // EA
+ writeWord_MD(0x100000, 0x00); // sda, scl low
+ writeWord_MD(0x100000, 0x40); // sda low, scl high
+ writeWord_MD(0x100000, 0xC0); // sda, scl high
+ writeWord_MD(0x100000, 0x80); // sda high, scl low
+ writeWord_MD(0x100000, 0x00); // STOP
+ } else if (eepType == 5) { // Codemasters
+ writeWord_CM(0x180000, 0x00); // sda low, scl low
+ writeWord_CM(0x180000, 0x02); // sda low, scl high
+ writeWord_CM(0x180000, 0x03); // sda, scl high
+ writeWord_CM(0x180000, 0x01); // sda high, scl low
+ writeWord_CM(0x180000, 0x00); // STOP
+ } else {
+ writeWord_MD(0x100000, 0x00); // sda, scl low
+ writeWord_MD(0x100000, 0x02); // sda low, scl high
+ writeWord_MD(0x100000, 0x03); // sda, scl high
+ writeWord_MD(0x100000, 0x01); // sda high, scl low
+ writeWord_MD(0x100000, 0x00); // STOP
}
}
void EepromSetAddress(word address) {
- if (eepSize > 0x80) { // 24C02+
+ if (eepSize > 0x80) { // 24C02+
for (int i = 0; i < 8; i++) {
- if ((address >> 7) & 0x1) // Bit is HIGH
+ if ((address >> 7) & 0x1) // Bit is HIGH
EepromSet1();
- else // Bit is LOW
+ else // Bit is LOW
EepromSet0();
- address <<= 1; // rotate to the next bit
+ address <<= 1; // rotate to the next bit
}
- EepromStatus(); // ACK
- }
- else { // 24C01
+ EepromStatus(); // ACK
+ } else { // 24C01
for (int i = 0; i < 7; i++) {
- if ((address >> 6) & 0x1) // Bit is HIGH
+ if ((address >> 6) & 0x1) // Bit is HIGH
EepromSet1();
- else // Bit is LOW
+ else // Bit is LOW
EepromSet0();
- address <<= 1; // rotate to the next bit
+ address <<= 1; // rotate to the next bit
}
}
}
@@ -2179,35 +2290,34 @@ void readEepromByte(word address) {
addrlo = address & 0xFF;
dataOut_MD();
if (eepType == 2)
- EepromInit(0); // Enable EEPROM
- EepromStart(); // START
+ EepromInit(0); // Enable EEPROM
+ EepromStart(); // START
if (eepSize > 0x80) {
- EepromDevice(); // DEVICE [1010]
- if (eepSize > 0x800) { // MODE 3 [24C65]
+ EepromDevice(); // DEVICE [1010]
+ if (eepSize > 0x800) { // MODE 3 [24C65]
EepromSetDeviceAddress(0);
EepromWriteMode();
- EepromSetAddress(addrhi); // ADDR [A15..A8]
- }
- else { // MODE 2 [24C02/24C08/24C16]
- EepromSetDeviceAddress(addrhi); // ADDR [A10..A8]
+ EepromSetAddress(addrhi); // ADDR [A15..A8]
+ } else { // MODE 2 [24C02/24C08/24C16]
+ EepromSetDeviceAddress(addrhi); // ADDR [A10..A8]
EepromWriteMode();
}
}
EepromSetAddress(addrlo);
if (eepSize > 0x80) {
- EepromStart(); // START
- EepromDevice(); // DEVICE [1010]
- if (eepSize > 0x800) // MODE 3 [24C65]
+ EepromStart(); // START
+ EepromDevice(); // DEVICE [1010]
+ if (eepSize > 0x800) // MODE 3 [24C65]
EepromSetDeviceAddress(0);
- else // MODE 2 [24C02/24C08/24C16]
- EepromSetDeviceAddress(addrhi); // ADDR [A10..A8]
+ else // MODE 2 [24C02/24C08/24C16]
+ EepromSetDeviceAddress(addrhi); // ADDR [A10..A8]
}
EepromReadMode();
EepromReadData();
EepromFinish();
- EepromStop(); // STOP
+ EepromStop(); // STOP
if (eepType == 2)
- EepromInit(1); // Disable EEPROM
+ EepromInit(1); // Disable EEPROM
// OR 8 bits into byte
eeptemp = eepbit[0] << 7 | eepbit[1] << 6 | eepbit[2] << 5 | eepbit[3] << 4 | eepbit[4] << 3 | eepbit[5] << 2 | eepbit[6] << 1 | eepbit[7];
sdBuffer[addrlo] = eeptemp;
@@ -2219,29 +2329,27 @@ void writeEepromByte(word address) {
eeptemp = sdBuffer[addrlo];
dataOut_MD();
if (eepType == 2)
- EepromInit(0); // Enable EEPROM
- EepromStart(); // START
+ EepromInit(0); // Enable EEPROM
+ EepromStart(); // START
if (eepSize > 0x80) {
- EepromDevice(); // DEVICE [1010]
- if (eepSize > 0x800) { // MODE 3 [24C65]
- EepromSetDeviceAddress(0); // [A2-A0] = 000
- EepromWriteMode(); // WRITE
- EepromSetAddress(addrhi); // ADDR [A15-A8]
- }
- else { // MODE 2 [24C02/24C08/24C16]
- EepromSetDeviceAddress(addrhi); // ADDR [A10-A8]
- EepromWriteMode(); // WRITE
+ EepromDevice(); // DEVICE [1010]
+ if (eepSize > 0x800) { // MODE 3 [24C65]
+ EepromSetDeviceAddress(0); // [A2-A0] = 000
+ EepromWriteMode(); // WRITE
+ EepromSetAddress(addrhi); // ADDR [A15-A8]
+ } else { // MODE 2 [24C02/24C08/24C16]
+ EepromSetDeviceAddress(addrhi); // ADDR [A10-A8]
+ EepromWriteMode(); // WRITE
}
EepromSetAddress(addrlo);
- }
- else { // 24C01
+ } else { // 24C01
EepromSetAddress(addrlo);
- EepromWriteMode(); // WRITE
+ EepromWriteMode(); // WRITE
}
EepromWriteData(eeptemp);
- EepromStop(); // STOP
+ EepromStop(); // STOP
if (eepType == 2)
- EepromInit(1); // Disable EEPROM
+ EepromInit(1); // Disable EEPROM
}
// Read EEPROM and save to the SD card
@@ -2270,7 +2378,7 @@ void readEEP_MD() {
if (!myFile.open(fileName, O_RDWR | O_CREAT)) {
print_Error(F("SD Error"), true);
}
- if (eepSize > 0x100) { // 24C04+
+ if (eepSize > 0x100) { // 24C04+
for (word currByte = 0; currByte < eepSize; currByte += 256) {
print_Msg(F("*"));
display_Update();
@@ -2279,8 +2387,7 @@ void readEEP_MD() {
}
myFile.write(sdBuffer, 256);
}
- }
- else { // 24C01/24C02
+ } else { // 24C01/24C02
for (word currByte = 0; currByte < eepSize; currByte++) {
if ((currByte != 0) && ((currByte + 1) % 16 == 0)) {
print_Msg(F("*"));
@@ -2311,25 +2418,24 @@ void writeEEP_MD() {
// Open file on sd card
if (myFile.open(filePath, O_READ)) {
- if (eepSize > 0x100) { // 24C04+
+ if (eepSize > 0x100) { // 24C04+
for (word currByte = 0; currByte < eepSize; currByte += 256) {
myFile.read(sdBuffer, 256);
for (int i = 0; i < 256; i++) {
writeEepromByte(currByte + i);
- delay(50); // DELAY NEEDED
+ delay(50); // DELAY NEEDED
}
print_Msg(F("."));
display_Update();
}
- }
- else { // 24C01/24C02
+ } else { // 24C01/24C02
myFile.read(sdBuffer, eepSize);
for (word currByte = 0; currByte < eepSize; currByte++) {
writeEepromByte(currByte);
print_Msg(F("."));
if ((currByte != 0) && ((currByte + 1) % 64 == 0))
println_Msg(F(""));
- display_Update(); // ON SERIAL = delay(100)
+ display_Update(); // ON SERIAL = delay(100)
}
}
// Close the file:
@@ -2338,8 +2444,7 @@ void writeEEP_MD() {
display_Clear();
println_Msg(F("Done"));
display_Update();
- }
- else {
+ } else {
print_Error(F("SD Error"), true);
}
dataIn_MD();
@@ -2403,7 +2508,7 @@ void writeBram_MD() {
if (myFile.open(filePath, O_READ)) {
// 0x700000-0x7FFFFF: Writes by /LWR latch D0; 1=RAM write enabled, 0=disabled
- writeWord_MD(0x380000, 1); // Enable BRAM Writes
+ writeWord_MD(0x380000, 1); // Enable BRAM Writes
for (unsigned long currByte = 0; currByte < bramSize; currByte += 512) {
myFile.read(sdBuffer, 512);
@@ -2411,15 +2516,14 @@ void writeBram_MD() {
writeWord_MD(0x300000 + currByte + i, sdBuffer[i]);
}
}
- writeWord_MD(0x380000, 0); // Disable BRAM Writes
+ writeWord_MD(0x380000, 0); // Disable BRAM Writes
// Close the file:
myFile.close();
println_Msg(F(""));
display_Clear();
println_Msg(F("Done"));
display_Update();
- }
- else {
+ } else {
print_Error(F("SD Error"), true);
}
dataIn_MD();
@@ -2428,18 +2532,18 @@ void writeBram_MD() {
//******************************************
// Realtec Mapper Functions
//******************************************
-void writeRealtec(unsigned long address, byte value) { // Realtec 0x404000 (UPPER)/0x400000 (LOWER)
+void writeRealtec(unsigned long address, byte value) { // Realtec 0x404000 (UPPER)/0x400000 (LOWER)
dataOut_MD();
- PORTF = address & 0xFF; // 0x00 ADDR A0-A7
- PORTK = (address >> 8) & 0xFF; // ADDR A8-A15
- PORTL = (address >> 16) & 0xFF; //0x20 ADDR A16-A23
- PORTA = 0x00; // DATA D8-D15
- PORTH |= (1 << 0); // /RES HIGH
+ PORTF = address & 0xFF; // 0x00 ADDR A0-A7
+ PORTK = (address >> 8) & 0xFF; // ADDR A8-A15
+ PORTL = (address >> 16) & 0xFF; //0x20 ADDR A16-A23
+ PORTA = 0x00; // DATA D8-D15
+ PORTH |= (1 << 0); // /RES HIGH
- PORTH |= (1 << 3); // CE HIGH
+ PORTH |= (1 << 3); // CE HIGH
PORTC = value;
- PORTH &= ~(1 << 4) & ~(1 << 5); // /UDSW + /LDSW LOW
- PORTH |= (1 << 4) | (1 << 5); // /UDSW + /LDSW HIGH
+ PORTH &= ~(1 << 4) & ~(1 << 5); // /UDSW + /LDSW LOW
+ PORTH |= (1 << 4) | (1 << 5); // /UDSW + /LDSW HIGH
dataIn_MD();
}
@@ -2473,9 +2577,9 @@ void readRealtec_MD() {
}
// Realtec Registers
- writeWord_MD(0x201000, 4); // Number of 128K Blocks 0x402000 (0x201000)
- writeRealtec(0x200000, 1); // ROM Lower Address 0x400000 (0x200000)
- writeRealtec(0x202000, 0); // ROM Upper Address 0x404000 (0x202000)
+ writeWord_MD(0x201000, 4); // Number of 128K Blocks 0x402000 (0x201000)
+ writeRealtec(0x200000, 1); // ROM Lower Address 0x400000 (0x200000)
+ writeRealtec(0x202000, 0); // ROM Upper Address 0x404000 (0x202000)
word d = 0;
for (unsigned long currBuffer = 0; currBuffer < cartSize / 2; currBuffer += 256) {
@@ -2487,7 +2591,7 @@ void readRealtec_MD() {
word myWord = readWord_MD(currBuffer + currWord);
// Split word into two bytes
// Left
- sdBuffer[d] = (( myWord >> 8 ) & 0xFF);
+ sdBuffer[d] = ((myWord >> 8) & 0xFF);
// Right
sdBuffer[d + 1] = (myWord & 0xFF);
d += 2;
@@ -2503,4 +2607,4 @@ void readRealtec_MD() {
//******************************************
// End of File
-//******************************************
+//****************************************** \ No newline at end of file
diff --git a/Cart_Reader/N64.ino b/Cart_Reader/N64.ino
index 9584a45..4d09619 100644
--- a/Cart_Reader/N64.ino
+++ b/Cart_Reader/N64.ino
@@ -26,12 +26,11 @@ int eepPages;
char N64_raw_dump[265];
// Array that holds one Controller Pak block of 32 bytes data
byte myBlock[33];
-String rawStr = ""; // above char array read into a string
+String rawStr = ""; // above char array read into a string
struct {
char stick_x;
char stick_y;
-}
-N64_status;
+} N64_status;
//stings that hold the buttons
String button = "N/A";
String lastbutton = "N/A";
@@ -60,14 +59,14 @@ static const char n64MenuItem2[] PROGMEM = "Controller";
static const char n64MenuItem3[] PROGMEM = "Flash Repro";
static const char n64MenuItem4[] PROGMEM = "Flash Gameshark";
static const char n64MenuItem5[] PROGMEM = "Reset";
-static const char* const menuOptionsN64[] PROGMEM = {n64MenuItem1, n64MenuItem2, n64MenuItem3, n64MenuItem4, n64MenuItem5};
+static const char* const menuOptionsN64[] PROGMEM = { n64MenuItem1, n64MenuItem2, n64MenuItem3, n64MenuItem4, n64MenuItem5 };
// N64 controller menu items
static const char N64ContMenuItem1[] PROGMEM = "Test Controller";
static const char N64ContMenuItem2[] PROGMEM = "Read ControllerPak";
static const char N64ContMenuItem3[] PROGMEM = "Write ControllerPak";
static const char N64ContMenuItem4[] PROGMEM = "Reset";
-static const char* const menuOptionsN64Controller[] PROGMEM = {N64ContMenuItem1, N64ContMenuItem2, N64ContMenuItem3, N64ContMenuItem4};
+static const char* const menuOptionsN64Controller[] PROGMEM = { N64ContMenuItem1, N64ContMenuItem2, N64ContMenuItem3, N64ContMenuItem4 };
// N64 cart menu items
static const char N64CartMenuItem1[] PROGMEM = "Read ROM";
@@ -75,14 +74,14 @@ static const char N64CartMenuItem2[] PROGMEM = "Read Save";
static const char N64CartMenuItem3[] PROGMEM = "Write Save";
static const char N64CartMenuItem4[] PROGMEM = "Force Savetype";
static const char N64CartMenuItem5[] PROGMEM = "Reset";
-static const char* const menuOptionsN64Cart[] PROGMEM = {N64CartMenuItem1, N64CartMenuItem2, N64CartMenuItem3, N64CartMenuItem4, N64CartMenuItem5};
+static const char* const menuOptionsN64Cart[] PROGMEM = { N64CartMenuItem1, N64CartMenuItem2, N64CartMenuItem3, N64CartMenuItem4, N64CartMenuItem5 };
// N64 CRC32 error menu items
static const char N64CRCMenuItem1[] PROGMEM = "No";
static const char N64CRCMenuItem2[] PROGMEM = "Yes and keep old";
static const char N64CRCMenuItem3[] PROGMEM = "Yes and delete old";
static const char N64CRCMenuItem4[] PROGMEM = "Reset";
-static const char* const menuOptionsN64CRC[] PROGMEM = {N64CRCMenuItem1, N64CRCMenuItem2, N64CRCMenuItem3, N64CRCMenuItem4};
+static const char* const menuOptionsN64CRC[] PROGMEM = { N64CRCMenuItem1, N64CRCMenuItem2, N64CRCMenuItem3, N64CRCMenuItem4 };
// Rom menu
static const char N64RomItem1[] PROGMEM = "4 MB";
@@ -91,7 +90,7 @@ static const char N64RomItem3[] PROGMEM = "12 MB";
static const char N64RomItem4[] PROGMEM = "16 MB";
static const char N64RomItem5[] PROGMEM = "32 MB";
static const char N64RomItem6[] PROGMEM = "64 MB";
-static const char* const romOptionsN64[] PROGMEM = {N64RomItem1, N64RomItem2, N64RomItem3, N64RomItem4, N64RomItem5, N64RomItem6};
+static const char* const romOptionsN64[] PROGMEM = { N64RomItem1, N64RomItem2, N64RomItem3, N64RomItem4, N64RomItem5, N64RomItem6 };
// Save menu
static const char N64SaveItem1[] PROGMEM = "None";
@@ -99,21 +98,21 @@ static const char N64SaveItem2[] PROGMEM = "4K EEPROM";
static const char N64SaveItem3[] PROGMEM = "16K EEPROM";
static const char N64SaveItem4[] PROGMEM = "SRAM";
static const char N64SaveItem5[] PROGMEM = "FLASH";
-static const char* const saveOptionsN64[] PROGMEM = {N64SaveItem1, N64SaveItem2, N64SaveItem3, N64SaveItem4, N64SaveItem5};
+static const char* const saveOptionsN64[] PROGMEM = { N64SaveItem1, N64SaveItem2, N64SaveItem3, N64SaveItem4, N64SaveItem5 };
// Repro write buffer menu
static const char N64BufferItem1[] PROGMEM = "No buffer";
static const char N64BufferItem2[] PROGMEM = "32 Byte";
static const char N64BufferItem3[] PROGMEM = "64 Byte";
static const char N64BufferItem4[] PROGMEM = "128 Byte";
-static const char* const bufferOptionsN64[] PROGMEM = {N64BufferItem1, N64BufferItem2, N64BufferItem3, N64BufferItem4};
+static const char* const bufferOptionsN64[] PROGMEM = { N64BufferItem1, N64BufferItem2, N64BufferItem3, N64BufferItem4 };
// Repro sector size menu
static const char N64SectorItem1[] PROGMEM = "8 KB";
static const char N64SectorItem2[] PROGMEM = "32 KB";
static const char N64SectorItem3[] PROGMEM = "64 KB";
static const char N64SectorItem4[] PROGMEM = "128 KB";
-static const char* const sectorOptionsN64[] PROGMEM = {N64SectorItem1, N64SectorItem2, N64SectorItem3, N64SectorItem4};
+static const char* const sectorOptionsN64[] PROGMEM = { N64SectorItem1, N64SectorItem2, N64SectorItem3, N64SectorItem4 };
// N64 start menu
void n64Menu() {
@@ -124,8 +123,7 @@ void n64Menu() {
n64Dev = question_box(F("Select N64 device"), menuOptions, 5, 0);
// wait for user choice to come back from the question box menu
- switch (n64Dev)
- {
+ switch (n64Dev) {
case 0:
display_Clear();
display_Update();
@@ -174,8 +172,7 @@ void n64ControllerMenu() {
mainMenu = question_box(F("N64 Controller"), menuOptions, 4, 0);
// wait for user choice to come back from the question box menu
- switch (mainMenu)
- {
+ switch (mainMenu) {
case 0:
resetController();
display_Clear();
@@ -238,8 +235,7 @@ void n64CartMenu() {
mainMenu = question_box(F("N64 Cart Reader"), menuOptions, 5, 0);
// wait for user choice to come back from the question box menu
- switch (mainMenu)
- {
+ switch (mainMenu) {
case 0:
sd.chdir("/");
readRom_N64();
@@ -253,14 +249,12 @@ void n64CartMenu() {
println_Msg(F("Reading SRAM..."));
display_Update();
readSram(32768, 1);
- }
- else if (saveType == 4) {
+ } else if (saveType == 4) {
getFramType();
println_Msg(F("Reading FLASH..."));
display_Update();
readFram(flashramType);
- }
- else if ((saveType == 5) || (saveType == 6)) {
+ } else if ((saveType == 5) || (saveType == 6)) {
println_Msg(F("Reading EEPROM..."));
display_Update();
#ifdef clockgen_installed
@@ -268,8 +262,7 @@ void n64CartMenu() {
#else
readEeprom_CLK();
#endif
- }
- else {
+ } else {
print_Error(F("Savetype Error"), false);
}
println_Msg(F(""));
@@ -291,15 +284,13 @@ void n64CartMenu() {
if (writeErrors == 0) {
println_Msg(F("SRAM verified OK"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Error: "));
print_Msg(writeErrors);
println_Msg(F(" bytes "));
print_Error(F("did not verify."), false);
}
- }
- else if (saveType == 4) {
+ } else if (saveType == 4) {
// Launch file browser
fileBrowser(F("Select fla file"));
display_Clear();
@@ -311,16 +302,14 @@ void n64CartMenu() {
if (writeErrors == 0) {
println_Msg(F("OK"));
display_Update();
- }
- else {
+ } else {
println_Msg("");
print_Msg(F("Error: "));
print_Msg(writeErrors);
println_Msg(F(" bytes "));
print_Error(F("did not verify."), false);
}
- }
- else if ((saveType == 5) || (saveType == 6)) {
+ } else if ((saveType == 5) || (saveType == 6)) {
// Launch file browser
fileBrowser(F("Select eep file"));
display_Clear();
@@ -336,15 +325,13 @@ void n64CartMenu() {
if (writeErrors == 0) {
println_Msg(F("EEPROM verified OK"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Error: "));
print_Msg(writeErrors);
println_Msg(F(" bytes "));
print_Error(F("did not verify."), false);
}
- }
- else {
+ } else {
display_Clear();
print_Error(F("Save Type Error"), false);
}
@@ -361,8 +348,7 @@ void n64CartMenu() {
N64SaveMenu = question_box(F("Select save type"), menuOptions, 5, 0);
// wait for user choice to come back from the question box menu
- switch (N64SaveMenu)
- {
+ switch (N64SaveMenu) {
case 0:
// None
saveType = 0;
@@ -442,7 +428,7 @@ void setup_N64_Cart() {
clockgen.set_freq(200000000ULL, SI5351_CLK1);
// Start outputting Eeprom clock
- clockgen.output_enable(SI5351_CLK1, 1); // Eeprom clock
+ clockgen.output_enable(SI5351_CLK1, 1); // Eeprom clock
#else
// Set Eeprom Clock Pin(PH1) to Output
@@ -525,13 +511,23 @@ void setAddress_N64(unsigned long myAddress) {
PORTK = (myAdrLowOut >> 8) & 0xFF;
// Leave ale_L high for ~125ns
- __asm__("nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t");
// Pull ale_L(PC0) low
PORTC &= ~(1 << 0);
// Wait ~600ns just to be sure address is set
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Set data pins to input
adIn_N64();
@@ -543,10 +539,14 @@ word readWord_N64() {
PORTH &= ~(1 << 6);
// Wait ~310ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Join bytes from PINF and PINK into a word
- word tempWord = ( ( PINK & 0xFF ) << 8 ) | ( PINF & 0xFF );
+ word tempWord = ((PINK & 0xFF) << 8) | (PINF & 0xFF);
// Pull read(PH6) high
PORTH |= (1 << 6);
@@ -572,13 +572,18 @@ void writeWord_N64(word myWord) {
PORTH &= ~(1 << 5);
// Wait ~310ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Pull write(PH5) high
PORTH |= (1 << 5);
// Wait ~125ns
- __asm__("nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t");
// Set data pins to input
adIn_N64();
@@ -596,7 +601,7 @@ static word addrCRC(word address) {
// Go through each bit in the address, and if set, xor the right value into the output
for (int i = 15; i >= 5; i--) {
// Is this bit set?
- if ( ((address >> i) & 0x1)) {
+ if (((address >> i) & 0x1)) {
crc ^= xor_table[i];
}
}
@@ -606,17 +611,17 @@ static word addrCRC(word address) {
return address | crc;
}
-static uint8_t dataCRC( uint8_t *data ) {
+static uint8_t dataCRC(uint8_t* data) {
uint8_t ret = 0;
- for ( int i = 0; i <= 32; i++ ) {
- for ( int j = 7; j >= 0; j-- ) {
+ for (int i = 0; i <= 32; i++) {
+ for (int j = 7; j >= 0; j--) {
int tmp = 0;
- if ( ret & 0x80 ) {
+ if (ret & 0x80) {
tmp = 0x85;
}
ret <<= 1;
- if ( i < 32 ) {
- if ( data[i] & (0x01 << j) ) {
+ if (i < 32) {
+ if (data[i] & (0x01 << j)) {
ret |= 0x1;
}
}
@@ -629,7 +634,7 @@ static uint8_t dataCRC( uint8_t *data ) {
/******************************************
N64 Controller Protocol Functions
*****************************************/
-void N64_send(unsigned char *buffer, char length) {
+void N64_send(unsigned char* buffer, char length) {
// Send these bytes
char bits;
@@ -643,80 +648,77 @@ void N64_send(unsigned char *buffer, char length) {
// over the outputted assembly. I can insert nops where it was impossible
// with a for loop
- asm volatile (";Starting outer for loop");
+ asm volatile(";Starting outer for loop");
outer_loop:
{
- asm volatile (";Starting inner for loop");
+ asm volatile(";Starting inner for loop");
bits = 8;
inner_loop:
{
// Starting a bit, set the line low
- asm volatile (";Setting line to low");
- N64_LOW; // 1 op, 2 cycles
+ asm volatile(";Setting line to low");
+ N64_LOW; // 1 op, 2 cycles
- asm volatile (";branching");
+ asm volatile(";branching");
if (*buffer >> 7) {
- asm volatile (";Bit is a 1");
+ asm volatile(";Bit is a 1");
// 1 bit
// remain low for 1us, then go high for 3us
// nop block 1
- asm volatile ("nop\nnop\nnop\nnop\nnop\n");
+ asm volatile("nop\nnop\nnop\nnop\nnop\n");
- asm volatile (";Setting line to high");
+ asm volatile(";Setting line to high");
N64_HIGH;
// nop block 2
// we'll wait only 2us to sync up with both conditions
// at the bottom of the if statement
- asm volatile ("nop\nnop\nnop\nnop\nnop\n"
- "nop\nnop\nnop\nnop\nnop\n"
- "nop\nnop\nnop\nnop\nnop\n"
- "nop\nnop\nnop\nnop\nnop\n"
- "nop\nnop\nnop\nnop\nnop\n"
- "nop\nnop\nnop\nnop\nnop\n"
- );
-
- }
- else {
- asm volatile (";Bit is a 0");
+ asm volatile("nop\nnop\nnop\nnop\nnop\n"
+ "nop\nnop\nnop\nnop\nnop\n"
+ "nop\nnop\nnop\nnop\nnop\n"
+ "nop\nnop\nnop\nnop\nnop\n"
+ "nop\nnop\nnop\nnop\nnop\n"
+ "nop\nnop\nnop\nnop\nnop\n");
+
+ } else {
+ asm volatile(";Bit is a 0");
// 0 bit
// remain low for 3us, then go high for 1us
// nop block 3
- asm volatile ("nop\nnop\nnop\nnop\nnop\n"
- "nop\nnop\nnop\nnop\nnop\n"
- "nop\nnop\nnop\nnop\nnop\n"
- "nop\nnop\nnop\nnop\nnop\n"
- "nop\nnop\nnop\nnop\nnop\n"
- "nop\nnop\nnop\nnop\nnop\n"
- "nop\nnop\nnop\nnop\nnop\n"
- "nop\n");
-
- asm volatile (";Setting line to high");
+ asm volatile("nop\nnop\nnop\nnop\nnop\n"
+ "nop\nnop\nnop\nnop\nnop\n"
+ "nop\nnop\nnop\nnop\nnop\n"
+ "nop\nnop\nnop\nnop\nnop\n"
+ "nop\nnop\nnop\nnop\nnop\n"
+ "nop\nnop\nnop\nnop\nnop\n"
+ "nop\nnop\nnop\nnop\nnop\n"
+ "nop\n");
+
+ asm volatile(";Setting line to high");
N64_HIGH;
// wait for 1us
- asm volatile ("; end of conditional branch, need to wait 1us more before next bit");
-
+ asm volatile("; end of conditional branch, need to wait 1us more before next bit");
}
// end of the if, the line is high and needs to remain
// high for exactly 16 more cycles, regardless of the previous
// branch path
- asm volatile (";finishing inner loop body");
+ asm volatile(";finishing inner loop body");
--bits;
if (bits != 0) {
// nop block 4
// this block is why a for loop was impossible
- asm volatile ("nop\nnop\nnop\nnop\nnop\n"
- "nop\nnop\nnop\nnop\n");
+ asm volatile("nop\nnop\nnop\nnop\nnop\n"
+ "nop\nnop\nnop\nnop\n");
// rotate bits
- asm volatile (";rotating out bits");
+ asm volatile(";rotating out bits");
*buffer <<= 1;
goto inner_loop;
- } // fall out of inner loop
+ } // fall out of inner loop
}
- asm volatile (";continuing outer loop");
+ asm volatile(";continuing outer loop");
// In this case: the inner loop exits and the outer loop iterates,
// there are /exactly/ 16 cycles taken up by the necessary operations.
// So no nops are needed here (that was lucky!)
@@ -724,30 +726,30 @@ inner_loop:
if (length != 0) {
++buffer;
goto outer_loop;
- } // fall out of outer loop
+ } // fall out of outer loop
}
}
void N64_stop() {
// send a single stop (1) bit
// nop block 5
- asm volatile ("nop\nnop\nnop\nnop\n");
+ asm volatile("nop\nnop\nnop\nnop\n");
N64_LOW;
// wait 1 us, 16 cycles, then raise the line
// 16-2=14
// nop block 6
- asm volatile ("nop\nnop\nnop\nnop\nnop\n"
- "nop\nnop\nnop\nnop\nnop\n"
- "nop\nnop\nnop\nnop\n");
+ asm volatile("nop\nnop\nnop\nnop\nnop\n"
+ "nop\nnop\nnop\nnop\nnop\n"
+ "nop\nnop\nnop\nnop\n");
N64_HIGH;
}
void N64_get(word bitcount) {
// listen for the expected bitcount/8 bytes of data back from the controller and
// blast it out to the N64_raw_dump array, one bit per byte for extra speed.
- asm volatile (";Starting to listen");
+ asm volatile(";Starting to listen");
unsigned char timeout;
- char *bitbin = N64_raw_dump;
+ char* bitbin = N64_raw_dump;
// Again, using gotos here to make the assembly more predictable and
// optimization easier (please don't kill me)
@@ -759,14 +761,13 @@ read_loop:
return;
}
// wait approx 2us and poll the line
- asm volatile (
+ asm volatile(
"nop\nnop\nnop\nnop\nnop\n"
"nop\nnop\nnop\nnop\nnop\n"
"nop\nnop\nnop\nnop\nnop\n"
"nop\nnop\nnop\nnop\nnop\n"
"nop\nnop\nnop\nnop\nnop\n"
- "nop\nnop\nnop\nnop\nnop\n"
- );
+ "nop\nnop\nnop\nnop\nnop\n");
*bitbin = N64_QUERY;
++bitbin;
--bitcount;
@@ -786,8 +787,7 @@ read_loop:
/******************************************
N64 Controller Functions
*****************************************/
-void get_button()
-{
+void get_button() {
// Command to send to the gamecube
// The last bit is rumble, flip it to rumble
// yes this does need to be inside the loop, the
@@ -836,16 +836,11 @@ void get_button()
if (rawStr.substring(0, 16) == "0000000000000000") {
lastbutton = button;
button = F("Press a button");
- }
- else
- {
- for (int i = 0; i < 16; i++)
- {
+ } else {
+ for (int i = 0; i < 16; i++) {
// seems to be 16, 8 or 4 depending on what pin is used
- if (N64_raw_dump[i] == 16)
- {
- switch (i)
- {
+ if (N64_raw_dump[i] == 16) {
+ switch (i) {
case 7:
button = F("D-Right");
break;
@@ -944,8 +939,7 @@ void controllerTest_Serial() {
int startscreen = 1;
int test = 1;
-void printSTR(String st, int x, int y)
-{
+void printSTR(String st, int x, int y) {
char buf[st.length() + 1];
if (x == CENTER) {
@@ -956,24 +950,19 @@ void printSTR(String st, int x, int y)
display.drawStr(x, y, buf);
}
-void nextscreen()
-{
- if (button == "Press a button" && lastbutton == "START")
- {
+void nextscreen() {
+ if (button == "Press a button" && lastbutton == "START") {
// reset button
lastbutton = "N/A";
display.clearDisplay();
if (startscreen != 4)
startscreen = startscreen + 1;
- else
- {
+ else {
startscreen = 1;
test = 1;
}
- }
- else if (button == "Press a button" && lastbutton == "Z" && startscreen == 4)
- {
+ } else if (button == "Press a button" && lastbutton == "Z" && startscreen == 4) {
// Quit
quit = 0;
}
@@ -986,9 +975,9 @@ void controllerTest_Display() {
String anastick = "";
// Graph
- int xax = 24; // midpoint x
- int yax = 24; // midpoint y
- int zax = 24; // size
+ int xax = 24; // midpoint x
+ int yax = 24; // midpoint y
+ int zax = 24; // size
// variables to display test data of different sticks
int upx = 0;
@@ -1038,8 +1027,7 @@ void controllerTest_Display() {
// Get Button and analog stick
get_button();
- switch (startscreen)
- {
+ switch (startscreen) {
case 1:
{
display.drawStr(32, 8, "Controller Test");
@@ -1092,8 +1080,7 @@ void controllerTest_Display() {
display.drawStr(36, 8, "Range Test");
display.drawLine(0, 9, 128, 9);
- if (mode == 0)
- {
+ if (mode == 0) {
// Print Stick X Value
String stickx = String("X:" + String(N64_status.stick_x, DEC) + " ");
printSTR(stickx, 22 + 54, 26);
@@ -1117,14 +1104,11 @@ void controllerTest_Display() {
display.drawPixel(10 + xax - 68 / 4, 12 + yax + 68 / 4);
//Draw Analog Stick
- if (mode == 1)
- {
+ if (mode == 1) {
display.drawPixel(10 + xax + N64_status.stick_x / 4, 12 + yax - N64_status.stick_y / 4);
//Update LCD
display.updateDisplay();
- }
- else
- {
+ } else {
display.drawCircle(10 + xax + N64_status.stick_x / 4, 12 + yax - N64_status.stick_y / 4, 2);
//Update LCD
display.updateDisplay();
@@ -1132,15 +1116,11 @@ void controllerTest_Display() {
}
// switch mode
- if (button == "Press a button" && lastbutton == "Z")
- {
- if (mode == 0)
- {
+ if (button == "Press a button" && lastbutton == "Z") {
+ if (mode == 0) {
mode = 1;
display.clearDisplay();
- }
- else
- {
+ } else {
mode = 0;
display.clearDisplay();
}
@@ -1168,8 +1148,7 @@ void controllerTest_Display() {
//Update LCD
display.updateDisplay();
- if (button == "Press a button" && lastbutton == "Z")
- {
+ if (button == "Press a button" && lastbutton == "Z") {
// reset button
lastbutton = "N/A";
@@ -1181,12 +1160,10 @@ void controllerTest_Display() {
}
case 4:
{
- switch ( test )
- {
+ switch (test) {
case 0: // Display results
{
- switch (results)
- {
+ switch (results) {
case 0:
{
anastick = "Your Stick";
@@ -1207,8 +1184,7 @@ void controllerTest_Display() {
upleftx = bupleftx;
uplefty = buplefty;
- if (button == "Press a button" && lastbutton == "A")
- {
+ if (button == "Press a button" && lastbutton == "A") {
// reset button
lastbutton = "N/A";
results = 1;
@@ -1261,8 +1237,7 @@ void controllerTest_Display() {
upleftx = -68;
uplefty = 68;
- if (button == "Press a button" && lastbutton == "A")
- {
+ if (button == "Press a button" && lastbutton == "A") {
// reset button
lastbutton = "N/A";
results = 0;
@@ -1296,18 +1271,17 @@ void controllerTest_Display() {
break;
}
- } //results
+ } //results
break;
- } //display results
+ } //display results
- case 1:// +y Up
+ case 1: // +y Up
{
display.drawStr(34, 26, "Hold Stick Up");
display.drawStr(34, 34, "then press A");
//display.drawBitmap(110, 60, ana1);
- if (button == "Press a button" && lastbutton == "A")
- {
+ if (button == "Press a button" && lastbutton == "A") {
bupx = N64_status.stick_x;
bupy = N64_status.stick_y;
// reset button
@@ -1319,13 +1293,12 @@ void controllerTest_Display() {
break;
}
- case 2:// +y+x Up-Right
+ case 2: // +y+x Up-Right
{
- display.drawStr(42, 26, "Up-Right" );
+ display.drawStr(42, 26, "Up-Right");
//display.drawBitmap(110, 60, ana2);
- if (button == "Press a button" && lastbutton == "A")
- {
+ if (button == "Press a button" && lastbutton == "A") {
buprightx = N64_status.stick_x;
buprighty = N64_status.stick_y;
test = 3;
@@ -1337,13 +1310,12 @@ void controllerTest_Display() {
break;
}
- case 3:// +x Right
+ case 3: // +x Right
{
- display.drawStr(50, 26, "Right" );
+ display.drawStr(50, 26, "Right");
//display.drawBitmap(110, 60, ana3);
- if (button == "Press a button" && lastbutton == "A")
- {
+ if (button == "Press a button" && lastbutton == "A") {
brightx = N64_status.stick_x;
brighty = N64_status.stick_y;
test = 4;
@@ -1355,13 +1327,12 @@ void controllerTest_Display() {
break;
}
- case 4:// -y+x Down-Right
+ case 4: // -y+x Down-Right
{
display.drawStr(38, 26, "Down-Right");
//display.drawBitmap(110, 60, ana4);
- if (button == "Press a button" && lastbutton == "A")
- {
+ if (button == "Press a button" && lastbutton == "A") {
bdownrightx = N64_status.stick_x;
bdownrighty = N64_status.stick_y;
test = 5;
@@ -1373,13 +1344,12 @@ void controllerTest_Display() {
break;
}
- case 5:// -y Down
+ case 5: // -y Down
{
display.drawStr(49, 26, "Down");
//display.drawBitmap(110, 60, ana5);
- if (button == "Press a button" && lastbutton == "A")
- {
+ if (button == "Press a button" && lastbutton == "A") {
bdownx = N64_status.stick_x;
bdowny = N64_status.stick_y;
test = 6;
@@ -1391,13 +1361,12 @@ void controllerTest_Display() {
break;
}
- case 6:// -y-x Down-Left
+ case 6: // -y-x Down-Left
{
display.drawStr(39, 26, "Down-Left");
//display.drawBitmap(110, 60, ana6);
- if (button == "Press a button" && lastbutton == "A")
- {
+ if (button == "Press a button" && lastbutton == "A") {
bdownleftx = N64_status.stick_x;
bdownlefty = N64_status.stick_y;
test = 7;
@@ -1409,13 +1378,12 @@ void controllerTest_Display() {
break;
}
- case 7:// -x Left
+ case 7: // -x Left
{
- display.drawStr(51, 26, "Left" );
+ display.drawStr(51, 26, "Left");
//display.drawBitmap(110, 60, ana7);
- if (button == "Press a button" && lastbutton == "A")
- {
+ if (button == "Press a button" && lastbutton == "A") {
bleftx = N64_status.stick_x;
blefty = N64_status.stick_y;
test = 8;
@@ -1427,13 +1395,12 @@ void controllerTest_Display() {
break;
}
- case 8:// +y+x Up-Left
+ case 8: // +y+x Up-Left
{
display.drawStr(43, 26, "Up-Left");
//display.drawBitmap(110, 60, ana8);
- if (button == "Press a button" && lastbutton == "A")
- {
+ if (button == "Press a button" && lastbutton == "A") {
bupleftx = N64_status.stick_x;
buplefty = N64_status.stick_y;
test = 0;
@@ -1445,8 +1412,7 @@ void controllerTest_Display() {
break;
}
}
- if (test != 0)
- {
+ if (test != 0) {
display.drawStr(38, 8, "Benchmark");
display.drawLine(0, 9, 128, 9);
}
@@ -1457,7 +1423,6 @@ void controllerTest_Display() {
}
}
}
-
}
#endif
@@ -1468,7 +1433,7 @@ void controllerTest_Display() {
// Reset the controller
void resetController() {
// Reset controller
- unsigned char command[] = {0xFF};
+ unsigned char command[] = { 0xFF };
// don't want interrupts getting in the way
noInterrupts();
// Send command
@@ -1489,7 +1454,7 @@ void checkController() {
print_Error(F("Data line LOW"), true);
// Send status command
- unsigned char command[] = {0x0};
+ unsigned char command[] = { 0x0 };
// Empty buffer
for (word i = 0; i < 265; i++) {
@@ -1541,10 +1506,10 @@ byte readBlock(word myAddress) {
word myAddressCRC = addrCRC(myAddress);
// Read Controller Pak command
- unsigned char command[] = {0x02};
+ unsigned char command[] = { 0x02 };
// Address Command
- unsigned char addressHigh[] = {(unsigned char)(myAddressCRC >> 8)};
- unsigned char addressLow[] = {(unsigned char)(myAddressCRC & 0xff)};
+ unsigned char addressHigh[] = { (unsigned char)(myAddressCRC >> 8) };
+ unsigned char addressLow[] = { (unsigned char)(myAddressCRC & 0xff) };
// Empty buffer
for (word i = 0; i < 265; i++) {
@@ -1749,8 +1714,7 @@ void verifyCRC() {
println_Msg(F("Read successfully"));
sd.remove(filePath);
display_Update();
- }
- else {
+ } else {
print_Msg(F("Error: "));
print_Msg(writeErrors);
println_Msg(F(" blocks "));
@@ -1770,8 +1734,7 @@ boolean checkHeader(byte startAddress) {
if ((((sdBuffer[startAddress + 28] & 0xFF) << 8) | (sdBuffer[startAddress + 29] & 0xFF)) != (sum & 0xFFFF)) {
return 0;
- }
- else {
+ } else {
return 1;
}
}
@@ -1814,7 +1777,7 @@ void validateMPK() {
myFile.read(sdBuffer, 256);
// Calculate TOC checksum
- for (int i = 5; i < 128; i++ ) {
+ for (int i = 5; i < 128; i++) {
sum += sdBuffer[(i << 1) + 1];
}
if (sdBuffer[1] != (sum & 0xFF))
@@ -1856,14 +1819,14 @@ void writeMPK() {
// Copy 32 byte block from SdBuffer
for (byte currByte = 0; currByte < 32; currByte++) {
- myBlock[currByte] = sdBuffer[currBlock + currByte] ;
+ myBlock[currByte] = sdBuffer[currBlock + currByte];
}
// Write Controller Pak command
- unsigned char command[] = {0x03};
+ unsigned char command[] = { 0x03 };
// Address Command
- unsigned char addressHigh[] = {(unsigned char)(myAddressCRC >> 8)};
- unsigned char addressLow[] = {(unsigned char)(myAddressCRC & 0xff)};
+ unsigned char addressHigh[] = { (unsigned char)(myAddressCRC >> 8) };
+ unsigned char addressLow[] = { (unsigned char)(myAddressCRC & 0xff) };
// don't want interrupts getting in the way
noInterrupts();
@@ -1892,8 +1855,7 @@ void writeMPK() {
}
// Close the file:
myFile.close();
- }
- else {
+ } else {
print_Error(F("Can't open file on SD"), true);
}
}
@@ -1948,8 +1910,7 @@ void verifyMPK() {
if (writeErrors == 0) {
println_Msg(F("Written successfully"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Error: "));
print_Msg(writeErrors);
println_Msg(F(" bytes "));
@@ -2005,8 +1966,7 @@ void printCartInfo_N64() {
println_Msg(F("Press Button..."));
display_Update();
wait();
- }
- else {
+ } else {
// Display error
display_Clear();
println_Msg(F("GAMEPAK ERROR"));
@@ -2033,8 +1993,7 @@ void printCartInfo_N64() {
N64RomMenu = question_box(F("Select ROM size"), menuOptions, 6, 0);
// wait for user choice to come back from the question box menu
- switch (N64RomMenu)
- {
+ switch (N64RomMenu) {
case 0:
// 4MB
cartSize = 4;
@@ -2069,10 +2028,9 @@ void printCartInfo_N64() {
}
// improved strcmp function that ignores case to prevent checksum comparison issues
-int strcicmp(char const * a, char const * b)
-{
+int strcicmp(char const* a, char const* b) {
for (;; a++, b++) {
- int d = tolower((unsigned char) * a) - tolower((unsigned char) * b);
+ int d = tolower((unsigned char)*a) - tolower((unsigned char)*b);
if (d != 0 || !*a)
return d;
}
@@ -2174,9 +2132,8 @@ void getCartInfo_N64() {
cartSize = myFile.read() - 48;
// Remove leading 0 for single digit cart sizes
if (cartSize != 0) {
- cartSize = cartSize * 10 + myFile.read() - 48;
- }
- else {
+ cartSize = cartSize * 10 + myFile.read() - 48;
+ } else {
cartSize = myFile.read() - 48;
}
@@ -2199,8 +2156,7 @@ void getCartInfo_N64() {
}
// Close the file:
myFile.close();
- }
- else {
+ } else {
print_Error(F("n64.txt missing"), true);
}
}
@@ -2391,12 +2347,10 @@ void writeEeprom_CLK() {
println_Msg(F("Done"));
display_Update();
delay(600);
- }
- else {
+ } else {
print_Error(F("SD Error"), true);
}
- }
- else {
+ } else {
print_Error(F("Savetype Error"), true);
}
}
@@ -2466,8 +2420,7 @@ void readEeprom_CLK() {
print_Msg(folder);
println_Msg(F("/"));
display_Update();
- }
- else {
+ } else {
print_Error(F("Savetype Error"), true);
}
}
@@ -2525,16 +2478,14 @@ unsigned long verifyEeprom_CLK() {
}
// Close the file:
myFile.close();
- }
- else {
+ } else {
// SD Error
writeErrors = 999999;
print_Error(F("SD Error"), true);
}
// Return 0 if verified ok, or number of errors
return writeErrors;
- }
- else {
+ } else {
print_Error(F("Savetype Error"), true);
}
}
@@ -2550,15 +2501,85 @@ void sendData(byte data) {
// if current bit is 1, pull high after ~1us
if (data >> 7) {
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
N64_HIGH;
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
}
// if current bit is 0 pull high after ~3us
else {
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
N64_HIGH;
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
}
// rotate to the next bit
@@ -2569,9 +2590,49 @@ void sendData(byte data) {
// Send stop bit to eeprom
void sendStop() {
N64_LOW;
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
N64_HIGH;
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
}
// Capture 8 bytes in 64 bits into bit array tempBits
@@ -2583,7 +2644,22 @@ void readData() {
}
// Skip over the 1us low part of a high bit, Arduino running at 16Mhz -> one nop = 62.5ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read bit
tempBits[i] = N64_QUERY;
@@ -2640,12 +2716,10 @@ void writeEeprom() {
println_Msg(F("Done"));
display_Update();
delay(600);
- }
- else {
+ } else {
print_Error(F("SD Error"), true);
}
- }
- else {
+ } else {
print_Error(F("Savetype Error"), true);
}
}
@@ -2713,8 +2787,7 @@ void readEeprom() {
print_Msg(folder);
println_Msg(F("/"));
display_Update();
- }
- else {
+ } else {
print_Error(F("Savetype Error"), true);
}
}
@@ -2771,16 +2844,14 @@ unsigned long verifyEeprom() {
}
// Close the file:
myFile.close();
- }
- else {
+ } else {
// SD Error
writeErrors = 999999;
print_Error(F("SD Error"), true);
}
// Return 0 if verified ok, or number of errors
return writeErrors;
- }
- else {
+ } else {
print_Error(F("Savetype Error"), true);
}
}
@@ -2809,7 +2880,7 @@ void writeSram(unsigned long sramSize) {
for (int c = 0; c < 512; c += 2) {
// Join bytes to word
- word myWord = ( ( sdBuffer[c] & 0xFF ) << 8 ) | ( sdBuffer[c + 1] & 0xFF );
+ word myWord = ((sdBuffer[c] & 0xFF) << 8) | (sdBuffer[c + 1] & 0xFF);
// Write word
writeWord_N64(myWord);
@@ -2819,13 +2890,11 @@ void writeSram(unsigned long sramSize) {
myFile.close();
println_Msg(F("Done"));
display_Update();
- }
- else {
+ } else {
print_Error(F("SD Error"), true);
}
- }
- else {
+ } else {
print_Error(F("Savetype Error"), true);
}
}
@@ -2844,11 +2913,9 @@ void readSram(unsigned long sramSize, byte flashramType) {
if (saveType == 4) {
strcat(fileName, ".fla");
- }
- else if (saveType == 1) {
+ } else if (saveType == 1) {
strcat(fileName, ".sra");
- }
- else {
+ } else {
print_Error(F("Savetype Error"), true);
}
@@ -2926,8 +2993,7 @@ unsigned long verifySram(unsigned long sramSize, byte flashramType) {
}
// Close the file:
myFile.close();
- }
- else {
+ } else {
print_Error(F("SD Error"), true);
}
// Return 0 if verified ok, or number of errors
@@ -2938,7 +3004,7 @@ unsigned long verifySram(unsigned long sramSize, byte flashramType) {
Flashram functions
*****************************************/
// Send a command to the flashram command register
-void sendFramCmd (unsigned long myCommand) {
+void sendFramCmd(unsigned long myCommand) {
// Split command into two words
word myComLowOut = myCommand & 0xFFFF;
word myComHighOut = myCommand >> 16;
@@ -2972,8 +3038,7 @@ void writeFram(byte flashramType) {
if (blankcheck_N64(flashramType) == 0) {
println_Msg(F("OK"));
display_Update();
- }
- else {
+ } else {
println_Msg(F("FAIL"));
display_Update();
}
@@ -3011,7 +3076,7 @@ void writeFram(byte flashramType) {
// Send 128 bytes, 64 words
for (byte c = 0; c < 128; c += 2) {
// Join two bytes into one word
- word myWord = ( ( sdBuffer[c] & 0xFF ) << 8 ) | ( sdBuffer[c + 1] & 0xFF );
+ word myWord = ((sdBuffer[c] & 0xFF) << 8) | (sdBuffer[c + 1] & 0xFF);
// Write word
writeWord_N64(myWord);
}
@@ -3034,12 +3099,10 @@ void writeFram(byte flashramType) {
println_Msg("");
// Close the file:
myFile.close();
- }
- else {
+ } else {
print_Error(F("SD Error"), true);
}
- }
- else {
+ } else {
print_Error(F("Savetype Error"), true);
}
}
@@ -3067,8 +3130,7 @@ void eraseFram() {
delay(1);
}
}
- }
- else {
+ } else {
print_Error(F("Savetype Error"), true);
}
}
@@ -3081,8 +3143,7 @@ void readFram(byte flashramType) {
sendFramCmd(0xF0000000);
// Read Flashram
readSram(131072, flashramType);
- }
- else {
+ } else {
print_Error(F("Savetype Error"), true);
}
}
@@ -3140,9 +3201,9 @@ unsigned long blankcheck_N64(byte flashramType) {
// Wait until current operation is done
byte waitForFram(byte flashramType) {
byte framStatus = 0;
- byte statusMXL1100[] = {0x11, 0x11, 0x80, 0x01, 0x00, 0xC2, 0x00, 0x1E};
- byte statusMXL1101[] = {0x11, 0x11, 0x80, 0x01, 0x00, 0xC2, 0x00, 0x1D};
- byte statusMN63F81[] = {0x11, 0x11, 0x80, 0x01, 0x00, 0x32, 0x00, 0xF1};
+ byte statusMXL1100[] = { 0x11, 0x11, 0x80, 0x01, 0x00, 0xC2, 0x00, 0x1E };
+ byte statusMXL1101[] = { 0x11, 0x11, 0x80, 0x01, 0x00, 0xC2, 0x00, 0x1D };
+ byte statusMN63F81[] = { 0x11, 0x11, 0x80, 0x01, 0x00, 0x32, 0x00, 0xF1 };
// FRAM_STATUS_MODE_CMD
sendFramCmd(0xE1000000);
@@ -3169,8 +3230,7 @@ byte waitForFram(byte flashramType) {
framStatus = 1;
}
}
- }
- else if (flashramType == 1) {
+ } else if (flashramType == 1) {
//MX29L1101
if (MN63F81MPN == false) {
for (byte c = 0; c < 8; c++) {
@@ -3213,27 +3273,27 @@ void getFramType() {
sdBuffer[c + 1] = loByte;
}
//MX29L1100
- if (sdBuffer[7] == 0x1e ) {
+ if (sdBuffer[7] == 0x1e) {
flashramType = 2;
println_Msg(F("Type: MX29L1100"));
display_Update();
}
//MX29L1101
- else if (sdBuffer[7] == 0x1d ) {
+ else if (sdBuffer[7] == 0x1d) {
flashramType = 1;
MN63F81MPN = false;
println_Msg(F("Type: MX29L1101"));
display_Update();
}
//MN63F81MPN
- else if (sdBuffer[7] == 0xf1 ) {
+ else if (sdBuffer[7] == 0xf1) {
flashramType = 1;
MN63F81MPN = true;
println_Msg(F("Type: MN63F81MPN"));
display_Update();
}
// 29L1100KC-15B0 compat MX29L1101
- else if ((sdBuffer[7] == 0x8e ) || (sdBuffer[7] == 0x84 )) {
+ else if ((sdBuffer[7] == 0x8e) || (sdBuffer[7] == 0x84)) {
flashramType = 1;
MN63F81MPN = false;
println_Msg(F("Type: 29L1100KC-15B0"));
@@ -3320,7 +3380,7 @@ redumpsamefolder:
//Initialize progress bar
uint32_t processedProgressBar = 0;
- uint32_t totalProgressBar = (uint32_t)(cartSize) * 1024 * 1024;
+ uint32_t totalProgressBar = (uint32_t)(cartSize)*1024 * 1024;
draw_progressbar(0, totalProgressBar);
// prepare crc32
@@ -3344,11 +3404,15 @@ redumpsamefolder:
// Pull read(PH6) low
PORTH &= ~(1 << 6);
// Wait ~310ns
- NOP; NOP; NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
// data on PINK and PINF is valid now, read into sd card buffer
- buffer[c] = PINK; // hiByte
- buffer[c + 1] = PINF; // loByte
+ buffer[c] = PINK; // hiByte
+ buffer[c + 1] = PINF; // loByte
// Pull read(PH6) high
PORTH |= (1 << 6);
@@ -3371,11 +3435,15 @@ redumpsamefolder:
// Pull read(PH6) low
PORTH &= ~(1 << 6);
// Wait ~310ns
- NOP; NOP; NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
// data on PINK and PINF is valid now, read into sd card buffer
- buffer[c] = PINK; // hiByte
- buffer[c + 1] = PINF; // loByte
+ buffer[c] = PINK; // hiByte
+ buffer[c + 1] = PINF; // loByte
// Pull read(PH6) high
PORTH |= (1 << 6);
@@ -3405,9 +3473,9 @@ redumpsamefolder:
// Search n64.txt for crc
if (compareCRC("n64.txt", crcStr, 1, 0)) {
#endif
- unsigned long timeElapsed = (millis() - startTime) / 1000; // seconds
+ unsigned long timeElapsed = (millis() - startTime) / 1000; // seconds
print_Msg(F("Done ("));
- print_Msg(timeElapsed); // include elapsed time
+ print_Msg(timeElapsed); // include elapsed time
println_Msg(F("s)"));
println_Msg(F(""));
println_Msg(F("Press Button..."));
@@ -3420,8 +3488,7 @@ redumpsamefolder:
save_log();
#endif
wait();
- }
- else {
+ } else {
// Dump was bad or unknown
errorLvl = 1;
setColor_RGB(255, 0, 0);
@@ -3442,8 +3509,7 @@ redumpsamefolder:
CRCMenu = question_box(F("Redump cartridge?"), menuOptions, 4, 0);
// wait for user choice to come back from the question box menu
- switch (CRCMenu)
- {
+ switch (CRCMenu) {
case 0:
// Return to N64 menu
display_Clear();
@@ -3546,8 +3612,7 @@ void savesummary_N64(boolean checkfound, char crcStr[9], unsigned long timeElaps
// Dump was a known good rom
// myFile.println(F("Checksum matches"));
myFile.println(" [Match]");
- }
- else {
+ } else {
// myFile.println(F("Checksum not found"));
myFile.println(" [No Match]");
}
@@ -3574,27 +3639,23 @@ void flashRepro_N64() {
// If the ID is known continue
if (cartSize != 0) {
// Print flashrom name
- if ((strcmp(flashid, "227E") == 0) && (strcmp(cartID, "2201") == 0)) {
+ if ((strcmp(flashid, "227E") == 0) && (strcmp(cartID, "2201") == 0)) {
print_Msg(F("Spansion S29GL256N"));
if (cartSize == 64)
println_Msg(F(" x2"));
else
println_Msg("");
- }
- else if ((strcmp(flashid, "227E") == 0) && (strcmp(cartID, "2101") == 0)) {
+ } else if ((strcmp(flashid, "227E") == 0) && (strcmp(cartID, "2101") == 0)) {
print_Msg(F("Spansion S29GL128N"));
- }
- else if ((strcmp(flashid, "227E") == 0) && (strcmp(cartID, "2100") == 0)) {
+ } else if ((strcmp(flashid, "227E") == 0) && (strcmp(cartID, "2100") == 0)) {
print_Msg(F("ST M29W128GL"));
- }
- else if ((strcmp(flashid, "22C9") == 0) || (strcmp(flashid, "22CB") == 0)) {
+ } else if ((strcmp(flashid, "22C9") == 0) || (strcmp(flashid, "22CB") == 0)) {
print_Msg(F("Macronix MX29LV640"));
if (cartSize == 16)
println_Msg(F(" x2"));
else
println_Msg("");
- }
- else if (strcmp(flashid, "8816") == 0)
+ } else if (strcmp(flashid, "8816") == 0)
println_Msg(F("Intel 4400L0ZDQ0"));
else if (strcmp(flashid, "7E7E") == 0)
println_Msg(F("Fujitsu MSP55LV100S"));
@@ -3617,8 +3678,7 @@ void flashRepro_N64() {
println_Msg(F("Press Button..."));
display_Update();
wait();
- }
- else {
+ } else {
println_Msg(F("Unknown flashrom"));
print_Msg(F("ID: "));
print_Msg(vendorID);
@@ -3649,8 +3709,7 @@ void flashRepro_N64() {
N64RomMenu = question_box(F("Select flash size"), menuOptions, 6, 0);
// wait for user choice to come back from the question box menu
- switch (N64RomMenu)
- {
+ switch (N64RomMenu) {
case 0:
// 4MB
cartSize = 4;
@@ -3689,8 +3748,7 @@ void flashRepro_N64() {
N64BufferMenu = question_box(F("Select buffer size"), menuOptions, 4, 0);
// wait for user choice to come back from the question box menu
- switch (N64BufferMenu)
- {
+ switch (N64BufferMenu) {
case 0:
// no buffer
bufferSize = 0;
@@ -3719,8 +3777,7 @@ void flashRepro_N64() {
N64SectorMenu = question_box(F("Select sector size"), menuOptions, 4, 0);
// wait for user choice to come back from the question box menu
- switch (N64SectorMenu)
- {
+ switch (N64SectorMenu) {
case 0:
// 8KB sectors
sectorSize = 0x2000;
@@ -3771,21 +3828,17 @@ void flashRepro_N64() {
if (strcmp(flashid, "227E") == 0) {
// Spansion S29GL256N or Fujitsu MSP55LV512 with 0x20000 sector size and 32 byte buffer
eraseSector_N64(0x20000);
- }
- else if (strcmp(flashid, "7E7E") == 0) {
+ } else if (strcmp(flashid, "7E7E") == 0) {
// Fujitsu MSP55LV100S
eraseMSP55LV100_N64();
- }
- else if ((strcmp(flashid, "8813") == 0) || (strcmp(flashid, "8816") == 0)) {
+ } else if ((strcmp(flashid, "8813") == 0) || (strcmp(flashid, "8816") == 0)) {
// Intel 4400L0ZDQ0
eraseIntel4400_N64();
resetIntel4400_N64();
- }
- else if ((strcmp(flashid, "22C9") == 0) || (strcmp(flashid, "22CB") == 0)) {
+ } else if ((strcmp(flashid, "22C9") == 0) || (strcmp(flashid, "22CB") == 0)) {
// Macronix MX29LV640, C9 is top boot and CB is bottom boot block
eraseSector_N64(0x8000);
- }
- else {
+ } else {
eraseFlashrom_N64();
}
@@ -3800,32 +3853,25 @@ void flashRepro_N64() {
if ((strcmp(cartID, "3901") == 0) && (strcmp(flashid, "227E") == 0)) {
// Intel 512M29EW(64MB) with 0x20000 sector size and 128 byte buffer
writeFlashBuffer_N64(0x20000, 128);
- }
- else if ((strcmp(cartID, "2100") == 0) && (strcmp(flashid, "227E") == 0)) {
+ } else if ((strcmp(cartID, "2100") == 0) && (strcmp(flashid, "227E") == 0)) {
// ST M29W128GH(16MB) with 0x20000 sector size and 64 byte buffer
writeFlashBuffer_N64(0x20000, 64);
- }
- else if (strcmp(flashid, "227E") == 0) {
+ } else if (strcmp(flashid, "227E") == 0) {
// Spansion S29GL128N/S29GL256N or Fujitsu MSP55LV512 with 0x20000 sector size and 32 byte buffer
writeFlashBuffer_N64(0x20000, 32);
- }
- else if (strcmp(flashid, "7E7E") == 0) {
+ } else if (strcmp(flashid, "7E7E") == 0) {
//Fujitsu MSP55LV100S
writeMSP55LV100_N64(0x20000);
- }
- else if ((strcmp(flashid, "22C9") == 0) || (strcmp(flashid, "22CB") == 0)) {
+ } else if ((strcmp(flashid, "22C9") == 0) || (strcmp(flashid, "22CB") == 0)) {
// Macronix MX29LV640 without buffer and 0x8000 sector size
writeFlashrom_N64(0x8000);
- }
- else if ((strcmp(flashid, "8813") == 0) || (strcmp(flashid, "8816") == 0)) {
+ } else if ((strcmp(flashid, "8813") == 0) || (strcmp(flashid, "8816") == 0)) {
// Intel 4400L0ZDQ0
writeIntel4400_N64();
resetIntel4400_N64();
- }
- else if (bufferSize == 0) {
+ } else if (bufferSize == 0) {
writeFlashrom_N64(sectorSize);
- }
- else {
+ } else {
writeFlashBuffer_N64(sectorSize, bufferSize);
}
@@ -3839,20 +3885,17 @@ void flashRepro_N64() {
if (writeErrors == 0) {
println_Msg(F("OK"));
display_Update();
- }
- else {
+ } else {
print_Msg(writeErrors);
print_Msg(F(" bytes "));
print_Error(F("did not verify."), false);
}
- }
- else {
+ } else {
// Close the file
myFile.close();
print_Error(F("failed"), false);
}
- }
- else {
+ } else {
print_Error(F("Can't open file"), false);
}
@@ -3906,7 +3949,7 @@ void idFlashrom_N64() {
sprintf(flashid, "%04X", readWord_N64());
// Read 2 bytes secondary flashrom ID
setAddress_N64(romBase + 0x1C);
- sprintf(cartID, "%04X", ((readWord_N64() << 8) | (readWord_N64() & 0xFF)));
+ sprintf(cartID, "%04X", ((readWord_N64() << 8) | (readWord_N64() & 0xFF)));
// Spansion S29GL256N(32MB/64MB) with either one or two flashrom chips
if ((strcmp(cartID, "2201") == 0) && (strcmp(flashid, "227E") == 0)) {
@@ -3931,7 +3974,7 @@ void idFlashrom_N64() {
sprintf(tempID, "%04X", readWord_N64());
// Check if second flashrom chip is present
- if (strcmp(tempID, "227E") == 0) {
+ if (strcmp(tempID, "227E") == 0) {
cartSize = 64;
}
resetFlashrom_N64(romBase + 0x2000000);
@@ -3986,7 +4029,7 @@ void idFlashrom_N64() {
sprintf(cartID, "%04X", readWord_N64());
if (strcmp(cartID, "8813") == 0) {
cartSize = 64;
- strncpy(flashid , cartID, 5);
+ strncpy(flashid, cartID, 5);
}
resetIntel4400_N64();
// Empty cartID string
@@ -4029,7 +4072,7 @@ void idFlashrom_N64() {
}
//Test for Fujitsu MSP55LV100S (64MB)
- else {
+ else {
// Send flashrom ID command
setAddress_N64(romBase + (0x555 << 1));
writeWord_N64(0xAAAA);
@@ -4047,7 +4090,7 @@ void idFlashrom_N64() {
if (strcmp(cartID, "7E7E") == 0) {
resetMSP55LV100_N64(romBase);
cartSize = 64;
- strncpy(flashid , cartID, 5);
+ strncpy(flashid, cartID, 5);
}
}
if ((strcmp(flashid, "1240") == 0) && (strcmp(cartID, "1240") == 0)) {
@@ -4338,7 +4381,7 @@ void writeIntel4400_N64() {
// Write buffer
for (byte currByte = 0; currByte < 64; currByte += 2) {
// Join two bytes into one word
- word currWord = ( ( sdBuffer[currWriteBuffer + currByte] & 0xFF ) << 8 ) | ( sdBuffer[currWriteBuffer + currByte + 1] & 0xFF );
+ word currWord = ((sdBuffer[currWriteBuffer + currByte] & 0xFF) << 8) | (sdBuffer[currWriteBuffer + currByte + 1] & 0xFF);
setAddress_N64(romBase + currSector + currSdBuffer + currWriteBuffer + currByte);
writeWord_N64(currWord);
}
@@ -4392,7 +4435,7 @@ void writeMSP55LV100_N64(unsigned long sectorSize) {
for (byte currByte = 0; currByte < 32; currByte += 2) {
// Join two bytes into one word
- currWord = ( ( sdBuffer[currWriteBuffer + currByte] & 0xFF ) << 8 ) | ( sdBuffer[currWriteBuffer + currByte + 1] & 0xFF );
+ currWord = ((sdBuffer[currWriteBuffer + currByte] & 0xFF) << 8) | (sdBuffer[currWriteBuffer + currByte + 1] & 0xFF);
// Load Buffer Words
setAddress_N64(romBase + currSector + currSdBuffer + currWriteBuffer + currByte);
@@ -4454,7 +4497,7 @@ void writeFlashBuffer_N64(unsigned long sectorSize, byte bufferSize) {
for (byte currByte = 0; currByte < bufferSize; currByte += 2) {
// Join two bytes into one word
- currWord = ( ( sdBuffer[currWriteBuffer + currByte] & 0xFF ) << 8 ) | ( sdBuffer[currWriteBuffer + currByte + 1] & 0xFF );
+ currWord = ((sdBuffer[currWriteBuffer + currByte] & 0xFF) << 8) | (sdBuffer[currWriteBuffer + currByte + 1] & 0xFF);
// Load Buffer Words
setAddress_N64(romBase + currSector + currSdBuffer + currWriteBuffer + currByte);
@@ -4496,7 +4539,7 @@ void writeFlashrom_N64(unsigned long sectorSize) {
myFile.read(sdBuffer, 512);
for (int currByte = 0; currByte < 512; currByte += 2) {
// Join two bytes into one word
- word currWord = ( ( sdBuffer[currByte] & 0xFF ) << 8 ) | ( sdBuffer[currByte + 1] & 0xFF );
+ word currWord = ((sdBuffer[currByte] & 0xFF) << 8) | (sdBuffer[currByte + 1] & 0xFF);
// 2 unlock commands
setAddress_N64(flashBase + (0x555 << 1));
writeWord_N64(0xAA);
@@ -4534,7 +4577,7 @@ unsigned long verifyFlashrom_N64() {
myFile.read(sdBuffer, 512);
for (int currByte = 0; currByte < 512; currByte += 2) {
// Join two bytes into one word
- word currWord = ( ( sdBuffer[currByte] & 0xFF ) << 8 ) | ( sdBuffer[currByte + 1] & 0xFF );
+ word currWord = ((sdBuffer[currByte] & 0xFF) << 8) | (sdBuffer[currByte + 1] & 0xFF);
// Read flash
setAddress_N64(romBase + currSector + currSdBuffer + currByte);
// Compare both
@@ -4554,8 +4597,7 @@ unsigned long verifyFlashrom_N64() {
// Close the file:
myFile.close();
return writeErrors;
- }
- else {
+ } else {
println_Msg(F("Can't open file"));
display_Update();
return 9999;
@@ -4635,15 +4677,14 @@ void flashGameshark_N64() {
println_Msg(F(""));
println_Msg(F("Turn Cart Reader off now"));
display_Update();
- while (1);
- }
- else {
+ while (1)
+ ;
+ } else {
print_Msg(writeErrors);
print_Msg(F(" bytes "));
print_Error(F("did not verify."), false);
}
- }
- else {
+ } else {
print_Error(F("Can't open file"), false);
}
}
@@ -4806,15 +4847,14 @@ unsigned long verifyGameshark_N64() {
myFile.read(sdBuffer, 512);
for (int currByte = 0; currByte < 512; currByte += 2) {
// Join two bytes into one word
- word currWord = ( ( sdBuffer[currByte] & 0xFF ) << 8 ) | ( sdBuffer[currByte + 1] & 0xFF );
+ word currWord = ((sdBuffer[currByte] & 0xFF) << 8) | (sdBuffer[currByte + 1] & 0xFF);
// Read flash
setAddress_N64(romBase + 0xC00000 + currSector + currSdBuffer + currByte);
// Compare both
if (readWord_N64() != currWord) {
- if ( (strcmp(flashid, "0808") == 0) && (currSector + currSdBuffer + currByte > 0x3F) && (currSector + currSdBuffer + currByte < 0x1080)) {
+ if ((strcmp(flashid, "0808") == 0) && (currSector + currSdBuffer + currByte > 0x3F) && (currSector + currSdBuffer + currByte < 0x1080)) {
// Gameshark maps this area to the bootcode of the plugged in cartridge
- }
- else {
+ } else {
writeErrors++;
}
}
@@ -4824,8 +4864,7 @@ unsigned long verifyGameshark_N64() {
// Close the file:
myFile.close();
return writeErrors;
- }
- else {
+ } else {
println_Msg(F("Can't open file"));
display_Update();
return 9999;
@@ -4836,4 +4875,4 @@ unsigned long verifyGameshark_N64() {
//******************************************
// End of File
-//******************************************
+//****************************************** \ No newline at end of file
diff --git a/Cart_Reader/NES.ino b/Cart_Reader/NES.ino
index bcf2a2f..7e4f32c 100644
--- a/Cart_Reader/NES.ino
+++ b/Cart_Reader/NES.ino
@@ -29,95 +29,95 @@
*****************************************/
// Supported Mapper Array (iNES Mapper #s)
// Format = {mapper,prglo,prghi,chrlo,chrhi,ramlo,ramhi}
-static const byte PROGMEM mapsize [] = {
- 0, 0, 1, 0, 1, 0, 2, // nrom [sram r/w]
- 1, 1, 5, 0, 5, 0, 3, // mmc1 [sram r/w]
- 2, 3, 4, 0, 0, 0, 0, // uxrom
- 3, 0, 1, 0, 3, 0, 0, // cnrom
- 4, 1, 5, 0, 6, 0, 1, // mmc3/mmc6 [sram/prgram r/w]
- 5, 3, 5, 5, 7, 0, 3, // mmc5 [sram r/w]
- 7, 2, 4, 0, 0, 0, 0, // axrom
- 9, 3, 3, 5, 5, 0, 0, // mmc2 (punch out)
- 10, 3, 4, 4, 5, 1, 1, // mmc4 [sram r/w]
- 11, 1, 3, 1, 5, 0, 0, // Color Dreams [UNLICENSED]
- 13, 1, 1, 0, 0, 0, 0, // cprom (videomation)
- 16, 3, 4, 5, 6, 0, 1, // bandai x24c02 [eep r/w]
- 18, 3, 4, 5, 6, 0, 1, // jaleco ss8806 [sram r/w]
- 19, 3, 4, 5, 6, 0, 1, // namco 106/163 [sram/prgram r/w]
- 21, 4, 4, 5, 6, 0, 1, // vrc4a/vrc4c [sram r/w]
- 22, 3, 3, 5, 5, 0, 0, // vrc2a
- 23, 3, 3, 5, 6, 0, 0, // vrc2b/vrc4e
- 24, 4, 4, 5, 5, 0, 0, // vrc6a (akumajou densetsu)
- 25, 3, 4, 5, 6, 0, 1, // vrc2c/vrc4b/vrc4d [sram r/w]
- 26, 4, 4, 5, 6, 1, 1, // vrc6b [sram r/w]
- 30, 4, 5, 0, 0, 0, 0, // unrom 512 (NESmaker) [UNLICENSED]
- 32, 3, 4, 5, 5, 0, 0, // irem g-101
- 33, 3, 4, 5, 6, 0, 0, // taito tc0190
- 34, 3, 3, 0, 0, 0, 0, // bnrom [nina-1 NOT SUPPORTED]
- 37, 4, 4, 6, 6, 0, 0, // (super mario bros + tetris + world cup)
- 45, 3, 6, 0, 8, 0, 0, // ga23c asic multicart [UNLICENSED]
- 47, 4, 4, 6, 6, 0, 0, // (super spike vball + world cup)
- 48, 3, 4, 6, 6, 0, 0, // taito tc0690
- 64, 2, 3, 4, 5, 0, 0, // tengen rambo-1 [UNLICENSED]
- 65, 3, 4, 5, 6, 0, 0, // irem h-3001
- 66, 2, 3, 2, 3, 0, 0, // gxrom/mhrom
- 67, 3, 3, 5, 5, 0, 0, // sunsoft 3
- 68, 3, 3, 5, 6, 0, 1, // sunsoft 4 [sram r/w]
- 69, 3, 4, 5, 6, 0, 1, // sunsoft fme-7/5a/5b [sram r/w]
- 70, 3, 3, 5, 5, 0, 0, // bandai
- 71, 2, 4, 0, 0, 0, 0, // camerica/codemasters [UNLICENSED]
- 72, 3, 3, 5, 5, 0, 0, // jaleco jf-17
- 73, 3, 3, 0, 0, 0, 0, // vrc3 (salamander)
- 75, 3, 3, 5, 5, 0, 0, // vrc1
- 76, 3, 3, 5, 5, 0, 0, // namco 109 variant (megami tensei: digital devil story)
- 77, 3, 3, 3, 3, 0, 0, // (napoleon senki)
- 78, 3, 3, 5, 5, 0, 0, // irem 74hc161/32
- 79, 1, 2, 2, 3, 0, 0, // NINA-03/06 by AVE [UNLICENSED]
- 80, 3, 3, 5, 6, 0, 1, // taito x1-005 [prgram r/w]
- 82, 3, 3, 5, 6, 0, 1, // taito x1-017 [prgram r/w]
- 85, 3, 5, 0, 5, 0, 1, // vrc7 [sram r/w]
- 86, 3, 3, 4, 4, 0, 0, // jaleco jf-13 (moero pro yakyuu)
+static const byte PROGMEM mapsize[] = {
+ 0, 0, 1, 0, 1, 0, 2, // nrom [sram r/w]
+ 1, 1, 5, 0, 5, 0, 3, // mmc1 [sram r/w]
+ 2, 3, 4, 0, 0, 0, 0, // uxrom
+ 3, 0, 1, 0, 3, 0, 0, // cnrom
+ 4, 1, 5, 0, 6, 0, 1, // mmc3/mmc6 [sram/prgram r/w]
+ 5, 3, 5, 5, 7, 0, 3, // mmc5 [sram r/w]
+ 7, 2, 4, 0, 0, 0, 0, // axrom
+ 9, 3, 3, 5, 5, 0, 0, // mmc2 (punch out)
+ 10, 3, 4, 4, 5, 1, 1, // mmc4 [sram r/w]
+ 11, 1, 3, 1, 5, 0, 0, // Color Dreams [UNLICENSED]
+ 13, 1, 1, 0, 0, 0, 0, // cprom (videomation)
+ 16, 3, 4, 5, 6, 0, 1, // bandai x24c02 [eep r/w]
+ 18, 3, 4, 5, 6, 0, 1, // jaleco ss8806 [sram r/w]
+ 19, 3, 4, 5, 6, 0, 1, // namco 106/163 [sram/prgram r/w]
+ 21, 4, 4, 5, 6, 0, 1, // vrc4a/vrc4c [sram r/w]
+ 22, 3, 3, 5, 5, 0, 0, // vrc2a
+ 23, 3, 3, 5, 6, 0, 0, // vrc2b/vrc4e
+ 24, 4, 4, 5, 5, 0, 0, // vrc6a (akumajou densetsu)
+ 25, 3, 4, 5, 6, 0, 1, // vrc2c/vrc4b/vrc4d [sram r/w]
+ 26, 4, 4, 5, 6, 1, 1, // vrc6b [sram r/w]
+ 30, 4, 5, 0, 0, 0, 0, // unrom 512 (NESmaker) [UNLICENSED]
+ 32, 3, 4, 5, 5, 0, 0, // irem g-101
+ 33, 3, 4, 5, 6, 0, 0, // taito tc0190
+ 34, 3, 3, 0, 0, 0, 0, // bnrom [nina-1 NOT SUPPORTED]
+ 37, 4, 4, 6, 6, 0, 0, // (super mario bros + tetris + world cup)
+ 45, 3, 6, 0, 8, 0, 0, // ga23c asic multicart [UNLICENSED]
+ 47, 4, 4, 6, 6, 0, 0, // (super spike vball + world cup)
+ 48, 3, 4, 6, 6, 0, 0, // taito tc0690
+ 64, 2, 3, 4, 5, 0, 0, // tengen rambo-1 [UNLICENSED]
+ 65, 3, 4, 5, 6, 0, 0, // irem h-3001
+ 66, 2, 3, 2, 3, 0, 0, // gxrom/mhrom
+ 67, 3, 3, 5, 5, 0, 0, // sunsoft 3
+ 68, 3, 3, 5, 6, 0, 1, // sunsoft 4 [sram r/w]
+ 69, 3, 4, 5, 6, 0, 1, // sunsoft fme-7/5a/5b [sram r/w]
+ 70, 3, 3, 5, 5, 0, 0, // bandai
+ 71, 2, 4, 0, 0, 0, 0, // camerica/codemasters [UNLICENSED]
+ 72, 3, 3, 5, 5, 0, 0, // jaleco jf-17
+ 73, 3, 3, 0, 0, 0, 0, // vrc3 (salamander)
+ 75, 3, 3, 5, 5, 0, 0, // vrc1
+ 76, 3, 3, 5, 5, 0, 0, // namco 109 variant (megami tensei: digital devil story)
+ 77, 3, 3, 3, 3, 0, 0, // (napoleon senki)
+ 78, 3, 3, 5, 5, 0, 0, // irem 74hc161/32
+ 79, 1, 2, 2, 3, 0, 0, // NINA-03/06 by AVE [UNLICENSED]
+ 80, 3, 3, 5, 6, 0, 1, // taito x1-005 [prgram r/w]
+ 82, 3, 3, 5, 6, 0, 1, // taito x1-017 [prgram r/w]
+ 85, 3, 5, 0, 5, 0, 1, // vrc7 [sram r/w]
+ 86, 3, 3, 4, 4, 0, 0, // jaleco jf-13 (moero pro yakyuu)
87, 0, 1, 2, 3, 0, 0,
- 88, 3, 3, 5, 5, 0, 0, // namco (dxrom variant)
- 89, 3, 3, 5, 5, 0, 0, // sunsoft 2 variant (tenka no goikenban: mito koumon)
- 92, 4, 4, 5, 5, 0, 0, // jaleco jf-19/jf-21
- 93, 3, 3, 0, 0, 0, 0, // sunsoft 2
- 94, 3, 3, 0, 0, 0, 0, // hvc-un1rom (senjou no ookami)
- 95, 3, 3, 3, 3, 0, 0, // namcot-3425 (dragon buster)
- 96, 3, 3, 0, 0, 0, 0, // (oeka kids)
- 97, 4, 4, 0, 0, 0, 0, // irem tam-s1 (kaiketsu yanchamaru)
- 105, 4, 4, 0, 0, 0, 0, // (nintendo world Championships 1990) [UNTESTED]
- 118, 3, 4, 5, 5, 0, 1, // txsrom/mmc3 [sram r/w]
- 119, 3, 3, 4, 4, 0, 0, // tqrom/mmc3
- 140, 3, 3, 3, 5, 0, 0, // jaleco jf-11/jf-14
- 146, 1, 2, 2, 3, 0, 0, // Sachen 3015 [UNLICENSED]
+ 88, 3, 3, 5, 5, 0, 0, // namco (dxrom variant)
+ 89, 3, 3, 5, 5, 0, 0, // sunsoft 2 variant (tenka no goikenban: mito koumon)
+ 92, 4, 4, 5, 5, 0, 0, // jaleco jf-19/jf-21
+ 93, 3, 3, 0, 0, 0, 0, // sunsoft 2
+ 94, 3, 3, 0, 0, 0, 0, // hvc-un1rom (senjou no ookami)
+ 95, 3, 3, 3, 3, 0, 0, // namcot-3425 (dragon buster)
+ 96, 3, 3, 0, 0, 0, 0, // (oeka kids)
+ 97, 4, 4, 0, 0, 0, 0, // irem tam-s1 (kaiketsu yanchamaru)
+ 105, 4, 4, 0, 0, 0, 0, // (nintendo world Championships 1990) [UNTESTED]
+ 118, 3, 4, 5, 5, 0, 1, // txsrom/mmc3 [sram r/w]
+ 119, 3, 3, 4, 4, 0, 0, // tqrom/mmc3
+ 140, 3, 3, 3, 5, 0, 0, // jaleco jf-11/jf-14
+ 146, 1, 2, 2, 3, 0, 0, // Sachen 3015 [UNLICENSED]
152, 2, 3, 5, 5, 0, 0,
- 153, 5, 5, 0, 0, 1, 1, // (famicom jump ii) [sram r/w]
- 154, 3, 3, 5, 5, 0, 0, // namcot-3453 (devil man)
- 155, 3, 3, 3, 5, 0, 1, // mmc1 variant [sram r/w]
- 158, 3, 3, 5, 5, 0, 0, // tengen rambo-1 variant (alien syndrome (u)) [UNLICENSED]
- 159, 3, 4, 5, 6, 1, 1, // bandai x24c01 [eep r/w]
- 180, 3, 3, 0, 0, 0, 0, // unrom variant (crazy climber)
- 184, 1, 1, 2, 3, 0, 0, // sunsoft 1
- 185, 0, 1, 1, 1, 0, 0, // cnrom lockout
- 206, 1, 3, 2, 4, 0, 0, // dxrom
- 207, 4, 4, 5, 5, 0, 0, // taito x1-005 variant (fudou myouou den)
- 210, 3, 5, 5, 6, 0, 0, // namco 175/340
+ 153, 5, 5, 0, 0, 1, 1, // (famicom jump ii) [sram r/w]
+ 154, 3, 3, 5, 5, 0, 0, // namcot-3453 (devil man)
+ 155, 3, 3, 3, 5, 0, 1, // mmc1 variant [sram r/w]
+ 158, 3, 3, 5, 5, 0, 0, // tengen rambo-1 variant (alien syndrome (u)) [UNLICENSED]
+ 159, 3, 4, 5, 6, 1, 1, // bandai x24c01 [eep r/w]
+ 180, 3, 3, 0, 0, 0, 0, // unrom variant (crazy climber)
+ 184, 1, 1, 2, 3, 0, 0, // sunsoft 1
+ 185, 0, 1, 1, 1, 0, 0, // cnrom lockout
+ 206, 1, 3, 2, 4, 0, 0, // dxrom
+ 207, 4, 4, 5, 5, 0, 0, // taito x1-005 variant (fudou myouou den)
+ 210, 3, 5, 5, 6, 0, 0, // namco 175/340
};
/******************************************
Defines
*****************************************/
-#define ROMSEL_HI PORTF |= (1<<1)
-#define ROMSEL_LOW PORTF &= ~(1<<1)
-#define PHI2_HI PORTF |= (1<<0)
-#define PHI2_LOW PORTF &= ~(1<<0)
-#define PRG_READ PORTF |= (1<<7)
-#define PRG_WRITE PORTF &= ~(1<<7)
-#define CHR_READ_HI PORTF |= (1<<5)
-#define CHR_READ_LOW PORTF &= ~(1<<5)
-#define CHR_WRITE_HI PORTF |= (1<<2)
-#define CHR_WRITE_LOW PORTF &= ~(1<<2)
+#define ROMSEL_HI PORTF |= (1 << 1)
+#define ROMSEL_LOW PORTF &= ~(1 << 1)
+#define PHI2_HI PORTF |= (1 << 0)
+#define PHI2_LOW PORTF &= ~(1 << 0)
+#define PRG_READ PORTF |= (1 << 7)
+#define PRG_WRITE PORTF &= ~(1 << 7)
+#define CHR_READ_HI PORTF |= (1 << 5)
+#define CHR_READ_LOW PORTF &= ~(1 << 5)
+#define CHR_WRITE_HI PORTF |= (1 << 2)
+#define CHR_WRITE_LOW PORTF &= ~(1 << 2)
// RGB LED COMMON ANODE
#define LED_RED_OFF setColor_RGB(0, 0, 0)
@@ -127,7 +127,11 @@ static const byte PROGMEM mapsize [] = {
#define LED_BLUE_OFF setColor_RGB(0, 0, 0)
#define LED_BLUE_ON setColor_RGB(0, 0, 255)
-#define MODE_READ { PORTK = 0xFF; DDRK = 0; }
+#define MODE_READ \
+ { \
+ PORTK = 0xFF; \
+ DDRK = 0; \
+ }
#define MODE_WRITE DDRK = 0xFF
#define press 1
@@ -143,17 +147,17 @@ byte mapcount = (sizeof(mapsize) / sizeof(mapsize[0])) / 7;
boolean mapfound = false;
byte mapselect;
-int PRG[] = {16, 32, 64, 128, 256, 512, 1024};
-byte prglo = 0; // Lowest Entry
-byte prghi = 6; // Highest Entry
+int PRG[] = { 16, 32, 64, 128, 256, 512, 1024 };
+byte prglo = 0; // Lowest Entry
+byte prghi = 6; // Highest Entry
-int CHR[] = {0, 8, 16, 32, 64, 128, 256, 512, 1024};
-byte chrlo = 0; // Lowest Entry
-byte chrhi = 8; // Highest Entry
+int CHR[] = { 0, 8, 16, 32, 64, 128, 256, 512, 1024 };
+byte chrlo = 0; // Lowest Entry
+byte chrhi = 8; // Highest Entry
-byte RAM[] = {0, 8, 16, 32};
-byte ramlo = 0; // Lowest Entry
-byte ramhi = 3; // Highest Entry
+byte RAM[] = { 0, 8, 16, 32 };
+byte ramlo = 0; // Lowest Entry
+byte ramhi = 3; // Highest Entry
int banks;
int prg;
@@ -168,12 +172,12 @@ byte prgchk3;
int eepsize;
byte bytecheck;
byte firstbyte;
-boolean flashfound = false; // NESmaker 39SF040 Flash Cart
+boolean flashfound = false; // NESmaker 39SF040 Flash Cart
// Files
char fileCount[3];
-#ifndef no-intro
+#ifndef nointro
FsFile nesFile;
uint32_t prg_crc32;
uint32_t chr_crc32;
@@ -207,18 +211,18 @@ static const char nesMenuItem4[] PROGMEM = "Write Sram";
static const char nesMenuItem5[] PROGMEM = "Change Mapper";
static const char nesMenuItem6[] PROGMEM = "Flash NESMaker";
static const char nesMenuItem7[] PROGMEM = "Reset";
-static const char* const menuOptionsNES[] PROGMEM = {nesMenuItem1, nesMenuItem2, nesMenuItem3, nesMenuItem4, nesMenuItem5, nesMenuItem6, nesMenuItem7};
+static const char* const menuOptionsNES[] PROGMEM = { nesMenuItem1, nesMenuItem2, nesMenuItem3, nesMenuItem4, nesMenuItem5, nesMenuItem6, nesMenuItem7 };
// NES chips menu
-#ifndef no-intro
-static const char nesChipsMenuItem1[] PROGMEM = "Read PRG & CHR";
+#ifndef nointro
+static const char nesChipsMenuItem1[] PROGMEM = "Read PRG & CHR";
#else
-static const char nesChipsMenuItem1[] PROGMEM = "Combined PRG+CHR";
+static const char nesChipsMenuItem1[] PROGMEM = "Combined PRG+CHR";
#endif
-static const char nesChipsMenuItem2[] PROGMEM = "Read only PRG";
-static const char nesChipsMenuItem3[] PROGMEM = "Read only CHR";
-static const char nesChipsMenuItem4[] PROGMEM = "Back";
-static const char* const menuOptionsNESChips[] PROGMEM = {nesChipsMenuItem1, nesChipsMenuItem2, nesChipsMenuItem3, nesChipsMenuItem4};
+static const char nesChipsMenuItem2[] PROGMEM = "Read only PRG";
+static const char nesChipsMenuItem3[] PROGMEM = "Read only CHR";
+static const char nesChipsMenuItem4[] PROGMEM = "Back";
+static const char* const menuOptionsNESChips[] PROGMEM = { nesChipsMenuItem1, nesChipsMenuItem2, nesChipsMenuItem3, nesChipsMenuItem4 };
// NES start menu
void nesMenu() {
@@ -230,7 +234,7 @@ void nesMenu() {
switch (answer) {
// Read Rom
case 0:
-#ifndef no-intro
+#ifndef nointro
CartStart();
readPRG(false);
delay(2000);
@@ -303,8 +307,7 @@ void nesMenu() {
if (mapper == 30) {
writeFLASH();
resetROM();
- }
- else {
+ } else {
display_Clear();
println_Msg(F("Error:"));
println_Msg(F("Can't write to this cartridge"));
@@ -331,7 +334,7 @@ void nesChipMenu() {
switch (answer) {
// Read combined PRG/CHR
case 0:
-#ifndef no-intro
+#ifndef nointro
CreateROMFolderInSD();
readPRG(false);
resetROM();
@@ -417,16 +420,15 @@ void setup_NES() {
}
/******************************************
- Get Mapping from no-intro SD database
+ Get Mapping from nointro SD database
*****************************************/
-#ifdef no-intro
+#ifdef nointro
// no clue (taken from fceux)
uint32_t uppow2(uint32_t n) {
int x;
for (x = 31; x >= 0; x--)
- if (n & (1u << x))
- {
+ if (n & (1u << x)) {
if ((1u << x) != n)
return (1u << (x + 1));
break;
@@ -443,7 +445,7 @@ void printPRG(unsigned long myOffset) {
for (word currLine = 0; currLine < 512; currLine += 16) {
for (byte currByte = 0; currByte < 16; currByte++) {
- itoa (read_prg_byte(myOffset + currLine + currByte), myBuffer, 16);
+ itoa(read_prg_byte(myOffset + currLine + currByte), myBuffer, 16);
for (word i = 0; i < 2 - strlen(myBuffer); i++) {
print_Msg(F("0"));
}
@@ -512,8 +514,7 @@ boolean getMapping() {
romName[3] = 'T';
romName[4] = '\0';
return 0;
- }
- else {
+ } else {
//Search for CRC32 in file
char gamename[100];
char crc_search[9];
@@ -560,12 +561,10 @@ boolean getMapping() {
while (1) {
if (myFile.curPosition() == 0) {
break;
- }
- else if (myFile.peek() == '\n') {
+ } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1);
break;
- }
- else {
+ } else {
myFile.seekSet(myFile.curPosition() - 1);
}
}
@@ -622,11 +621,10 @@ boolean getMapping() {
// PRG size
if ((iNES_HEADER[9] & 0x0F) != 0x0F) {
// simple notation
- prgsize = (iNES_HEADER[4] | ((iNES_HEADER[9] & 0x0F) << 8)); //*16
- }
- else {
+ prgsize = (iNES_HEADER[4] | ((iNES_HEADER[9] & 0x0F) << 8)); //*16
+ } else {
// exponent-multiplier notation
- prgsize = (((1 << (iNES_HEADER[4] >> 2)) * ((iNES_HEADER[4] & 0b11) * 2 + 1)) >> 14); //*16
+ prgsize = (((1 << (iNES_HEADER[4] >> 2)) * ((iNES_HEADER[4] & 0b11) * 2 + 1)) >> 14); //*16
}
if (prgsize != 0)
prgsize = (int(log(prgsize) / log(2)));
@@ -634,37 +632,36 @@ boolean getMapping() {
// CHR size
if ((iNES_HEADER[9] & 0xF0) != 0xF0) {
// simple notation
- chrsize = (uppow2(iNES_HEADER[5] | ((iNES_HEADER[9] & 0xF0) << 4))) * 2; //*4
- }
- else {
- chrsize = (((1 << (iNES_HEADER[5] >> 2)) * ((iNES_HEADER[5] & 0b11) * 2 + 1)) >> 13) * 2; //*4
+ chrsize = (uppow2(iNES_HEADER[5] | ((iNES_HEADER[9] & 0xF0) << 4))) * 2; //*4
+ } else {
+ chrsize = (((1 << (iNES_HEADER[5] >> 2)) * ((iNES_HEADER[5] & 0b11) * 2 + 1)) >> 13) * 2; //*4
}
if (chrsize != 0)
chrsize = (int(log(chrsize) / log(2)));
// RAM size
- ramsize = ((iNES_HEADER[10] & 0xF0) ? (64 << ((iNES_HEADER[10] & 0xF0) >> 4)) : 0) / 4096; //*4
+ ramsize = ((iNES_HEADER[10] & 0xF0) ? (64 << ((iNES_HEADER[10] & 0xF0) >> 4)) : 0) / 4096; //*4
if (ramsize != 0)
ramsize = (int(log(ramsize) / log(2)));
prg = (int_pow(2, prgsize)) * 16;
if (chrsize == 0)
- chr = 0; // 0K
+ chr = 0; // 0K
else
chr = (int_pow(2, chrsize)) * 4;
if (ramsize == 0)
- ram = 0; // 0K
+ ram = 0; // 0K
else if (mapper == 82)
- ram = 5; // 5K
+ ram = 5; // 5K
else
ram = (int_pow(2, ramsize)) * 4;
// Mapper Variants
// Identify variant for use across multiple functions
- if (mapper == 4) { // Check for MMC6/MMC3
+ if (mapper == 4) { // Check for MMC6/MMC3
checkMMC6();
if (mmc6)
- ram = 1; // 1K
+ ram = 1; // 1K
}
#ifdef global_log
@@ -685,23 +682,20 @@ boolean getMapping() {
if (mapper == 0) {
print_Msg(ram / 4);
println_Msg(F("K"));
- }
- else if ((mapper == 16) || (mapper == 80) || (mapper == 159)) {
+ } else if ((mapper == 16) || (mapper == 80) || (mapper == 159)) {
if (mapper == 16)
print_Msg(ram * 32);
else
print_Msg(ram * 16);
println_Msg(F("B"));
- }
- else if (mapper == 19) {
+ } else if (mapper == 19) {
if (ramsize == 2)
println_Msg(F("128B"));
else {
print_Msg(ram);
println_Msg(F("K"));
}
- }
- else {
+ } else {
print_Msg(ram);
println_Msg(F("K"));
}
@@ -737,12 +731,10 @@ boolean getMapping() {
while (1) {
if (myFile.curPosition() == 0) {
break;
- }
- else if (myFile.peek() == '\n') {
+ } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1);
break;
- }
- else {
+ } else {
myFile.seekSet(myFile.curPosition() - 1);
}
}
@@ -806,8 +798,7 @@ boolean getMapping() {
romName[3] = 'T';
romName[4] = '\0';
return 0;
- }
- else {
+ } else {
println_Msg(F("Database file not found"));
return 0;
}
@@ -833,8 +824,7 @@ void selectMapping() {
setPRGSize();
setCHRSize();
setRAMSize();
- }
- else {
+ } else {
// Open database
if (myFile.open("nes.txt", O_READ)) {
@@ -864,12 +854,10 @@ void selectMapping() {
while (1) {
if (myFile.curPosition() == 0) {
break;
- }
- else if (myFile.peek() == '\n') {
+ } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1);
break;
- }
- else {
+ } else {
myFile.seekSet(myFile.curPosition() - 1);
}
}
@@ -926,11 +914,10 @@ void selectMapping() {
// PRG size
if ((iNES_HEADER[9] & 0x0F) != 0x0F) {
// simple notation
- prgsize = (iNES_HEADER[4] | ((iNES_HEADER[9] & 0x0F) << 8)); //*16
- }
- else {
+ prgsize = (iNES_HEADER[4] | ((iNES_HEADER[9] & 0x0F) << 8)); //*16
+ } else {
// exponent-multiplier notation
- prgsize = (((1 << (iNES_HEADER[4] >> 2)) * ((iNES_HEADER[4] & 0b11) * 2 + 1)) >> 14); //*16
+ prgsize = (((1 << (iNES_HEADER[4] >> 2)) * ((iNES_HEADER[4] & 0b11) * 2 + 1)) >> 14); //*16
}
if (prgsize != 0)
prgsize = (int(log(prgsize) / log(2)));
@@ -938,37 +925,36 @@ void selectMapping() {
// CHR size
if ((iNES_HEADER[9] & 0xF0) != 0xF0) {
// simple notation
- chrsize = (uppow2(iNES_HEADER[5] | ((iNES_HEADER[9] & 0xF0) << 4))) * 2; //*4
- }
- else {
- chrsize = (((1 << (iNES_HEADER[5] >> 2)) * ((iNES_HEADER[5] & 0b11) * 2 + 1)) >> 13) * 2; //*4
+ chrsize = (uppow2(iNES_HEADER[5] | ((iNES_HEADER[9] & 0xF0) << 4))) * 2; //*4
+ } else {
+ chrsize = (((1 << (iNES_HEADER[5] >> 2)) * ((iNES_HEADER[5] & 0b11) * 2 + 1)) >> 13) * 2; //*4
}
if (chrsize != 0)
chrsize = (int(log(chrsize) / log(2)));
// RAM size
- ramsize = ((iNES_HEADER[10] & 0xF0) ? (64 << ((iNES_HEADER[10] & 0xF0) >> 4)) : 0) / 4096; //*4
+ ramsize = ((iNES_HEADER[10] & 0xF0) ? (64 << ((iNES_HEADER[10] & 0xF0) >> 4)) : 0) / 4096; //*4
if (ramsize != 0)
ramsize = (int(log(ramsize) / log(2)));
prg = (int_pow(2, prgsize)) * 16;
if (chrsize == 0)
- chr = 0; // 0K
+ chr = 0; // 0K
else
chr = (int_pow(2, chrsize)) * 4;
if (ramsize == 0)
- ram = 0; // 0K
+ ram = 0; // 0K
else if (mapper == 82)
- ram = 5; // 5K
+ ram = 5; // 5K
else
ram = (int_pow(2, ramsize)) * 4;
// Mapper Variants
// Identify variant for use across multiple functions
- if (mapper == 4) { // Check for MMC6/MMC3
+ if (mapper == 4) { // Check for MMC6/MMC3
checkMMC6();
if (mmc6)
- ram = 1; // 1K
+ ram = 1; // 1K
}
println_Msg(gamename);
@@ -984,23 +970,20 @@ void selectMapping() {
if (mapper == 0) {
print_Msg(ram / 4);
println_Msg(F("K"));
- }
- else if ((mapper == 16) || (mapper == 80) || (mapper == 159)) {
+ } else if ((mapper == 16) || (mapper == 80) || (mapper == 159)) {
if (mapper == 16)
print_Msg(ram * 32);
else
print_Msg(ram * 16);
println_Msg(F("B"));
- }
- else if (mapper == 19) {
+ } else if (mapper == 19) {
if (ramsize == 2)
println_Msg(F("128B"));
else {
print_Msg(ram);
println_Msg(F("K"));
}
- }
- else {
+ } else {
print_Msg(ram);
println_Msg(F("K"));
}
@@ -1032,12 +1015,10 @@ void selectMapping() {
while (1) {
if (myFile.curPosition() == 0) {
break;
- }
- else if (myFile.peek() == '\n') {
+ } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1);
break;
- }
- else {
+ } else {
myFile.seekSet(myFile.curPosition() - 1);
}
}
@@ -1085,8 +1066,7 @@ void selectMapping() {
// Enable log again
dont_log = false;
#endif
- }
- else {
+ } else {
print_Error(F("Database file not found"), true);
}
}
@@ -1120,7 +1100,7 @@ void readRom_NES() {
//Initialize progress bar
uint32_t processedProgressBar = 0;
- uint32_t totalProgressBar = (uint32_t)(16 + prgsize * 16 * 1024 + chrsize * 4 * 1024);
+ uint32_t totalProgressBar = (uint32_t)(16 + prgsize * 16 * 1024 + chrsize * 4 * 1024);
draw_progressbar(0, totalProgressBar);
//Write iNES header
@@ -1179,7 +1159,7 @@ void readRaw_NES() {
//Initialize progress bar
uint32_t processedProgressBar = 0;
- uint32_t totalProgressBar = (uint32_t)(prgsize * 16 * 1024 + chrsize * 4 * 1024);
+ uint32_t totalProgressBar = (uint32_t)(prgsize * 16 * 1024 + chrsize * 4 * 1024);
draw_progressbar(0, totalProgressBar);
//Write PRG
@@ -1268,12 +1248,12 @@ static void write_prg_byte(unsigned int address, uint8_t data) {
PRG_WRITE;
PORTK = data;
- set_address(address); // PHI2 low, ROMSEL always HIGH
+ set_address(address); // PHI2 low, ROMSEL always HIGH
// _delay_us(1);
PHI2_HI;
//_delay_us(10);
- set_romsel(address); // ROMSEL is low if need, PHI2 high
- _delay_us(1); // WRITING
+ set_romsel(address); // ROMSEL is low if need, PHI2 high
+ _delay_us(1); // WRITING
//_delay_ms(1); // WRITING
// PHI2 low, ROMSEL high
PHI2_LOW;
@@ -1296,10 +1276,10 @@ static void write_chr_byte(unsigned int address, uint8_t data) {
MODE_WRITE;
PORTK = data;
- set_address(address); // PHI2 low, ROMSEL always HIGH
+ set_address(address); // PHI2 low, ROMSEL always HIGH
//_delay_us(10);
CHR_WRITE_LOW;
- _delay_us(1); // WRITING
+ _delay_us(1); // WRITING
//_delay_ms(1); // WRITING
CHR_WRITE_HI;
//_delay_us(1);
@@ -1350,15 +1330,14 @@ void resetROM() {
ROMSEL_HI;
}
-void write_mmc1_byte(unsigned int address, uint8_t data) { // write loop for 5 bit register
+void write_mmc1_byte(unsigned int address, uint8_t data) { // write loop for 5 bit register
if (address >= 0xE000) {
for (int i = 0; i < 5; i++) {
- write_reg_byte(address, data >> i); // shift 1 bit into temp register [WRITE RAM SAFE]
+ write_reg_byte(address, data >> i); // shift 1 bit into temp register [WRITE RAM SAFE]
}
- }
- else {
+ } else {
for (int j = 0; j < 5; j++) {
- write_prg_byte(address, data >> j); // shift 1 bit into temp register
+ write_prg_byte(address, data >> j); // shift 1 bit into temp register
}
}
}
@@ -1374,19 +1353,19 @@ void write_mmc1_byte(unsigned int address, uint8_t data) { // write loop for 5 b
// PORTF 0 = PHI2 (M2)
// WRITE RAM SAFE TO REGISTERS 0xE000/0xF000
-static void write_reg_byte(unsigned int address, uint8_t data) { // FIX FOR MMC1 RAM CORRUPTION
+static void write_reg_byte(unsigned int address, uint8_t data) { // FIX FOR MMC1 RAM CORRUPTION
PHI2_LOW;
- ROMSEL_HI; // A15 HI = E000
+ ROMSEL_HI; // A15 HI = E000
MODE_WRITE;
- PRG_WRITE; // CPU R/W LO
+ PRG_WRITE; // CPU R/W LO
PORTK = data;
- set_address(address); // PHI2 low, ROMSEL always HIGH
+ set_address(address); // PHI2 low, ROMSEL always HIGH
// DIRECT PIN TO PREVENT RAM CORRUPTION
// DIFFERENCE BETWEEN M2 LO AND ROMSEL HI MUST BE AROUND 33ns
// IF TIME IS GREATER THAN 33ns THEN WRITES TO 0xE000/0xF000 WILL CORRUPT RAM AT 0x6000/0x7000
- PORTF = 0b01111101; // ROMSEL LO/M2 HI
- PORTF = 0b01111110; // ROMSEL HI/M2 LO
+ PORTF = 0b01111101; // ROMSEL LO/M2 HI
+ PORTF = 0b01111110; // ROMSEL HI/M2 LO
_delay_us(1);
// Back to read mode
PRG_READ;
@@ -1396,17 +1375,17 @@ static void write_reg_byte(unsigned int address, uint8_t data) { // FIX FOR MMC1
PHI2_HI;
}
-static void write_ram_byte(unsigned int address, uint8_t data) { // Mapper 19 (Namco 106/163) WRITE RAM SAFE ($E000-$FFFF)
+static void write_ram_byte(unsigned int address, uint8_t data) { // Mapper 19 (Namco 106/163) WRITE RAM SAFE ($E000-$FFFF)
PHI2_LOW;
ROMSEL_HI;
MODE_WRITE;
PRG_WRITE;
PORTK = data;
- set_address(address); // PHI2 low, ROMSEL always HIGH
+ set_address(address); // PHI2 low, ROMSEL always HIGH
PHI2_HI;
- ROMSEL_LOW; // SET /ROMSEL LOW OTHERWISE CORRUPTS RAM
- _delay_us(1); // WRITING
+ ROMSEL_LOW; // SET /ROMSEL LOW OTHERWISE CORRUPTS RAM
+ _delay_us(1); // WRITING
// PHI2 low, ROMSEL high
PHI2_LOW;
_delay_us(1);
@@ -1419,7 +1398,7 @@ static void write_ram_byte(unsigned int address, uint8_t data) { // Mapper 19 (N
PHI2_HI;
}
-static void write_wram_byte(unsigned int address, uint8_t data) { // Mapper 5 (MMC5) RAM
+static void write_wram_byte(unsigned int address, uint8_t data) { // Mapper 5 (MMC5) RAM
PHI2_LOW;
ROMSEL_HI;
set_address(address);
@@ -1429,7 +1408,7 @@ static void write_wram_byte(unsigned int address, uint8_t data) { // Mapper 5 (M
MODE_WRITE;
PRG_WRITE;
PHI2_HI;
- _delay_us(1); // WRITING
+ _delay_us(1); // WRITING
PHI2_LOW;
ROMSEL_HI;
// Back to read mode
@@ -1440,7 +1419,7 @@ static void write_wram_byte(unsigned int address, uint8_t data) { // Mapper 5 (M
PHI2_HI;
}
-int int_pow(int base, int exp) { // Power for int
+int int_pow(int base, int exp) { // Power for int
int result = 1;
while (exp) {
if (exp & 1)
@@ -1457,7 +1436,7 @@ int int_pow(int base, int exp) { // Power for int
FsFile crcFile;
char tempCRC[9];
-uint32_t crc32(FsFile & file, uint32_t &charcnt) {
+uint32_t crc32(FsFile& file, uint32_t& charcnt) {
uint32_t oldcrc32 = 0xFFFFFFFF;
charcnt = 0;
while (file.available()) {
@@ -1471,7 +1450,7 @@ uint32_t crc32(FsFile & file, uint32_t &charcnt) {
return ~oldcrc32;
}
-uint32_t crc32EEP(FsFile & file, uint32_t &charcnt) {
+uint32_t crc32EEP(FsFile& file, uint32_t& charcnt) {
uint32_t oldcrc32 = 0xFFFFFFFF;
charcnt = 0;
while (file.available()) {
@@ -1590,10 +1569,10 @@ void CreateRAMFileInSD() {
}
}
-#ifndef no-intro
+#ifndef nointro
void CartStart() {
sd.chdir();
- EEPROM_readAnything(0, foldern); // FOLDER #
+ EEPROM_readAnything(0, foldern); // FOLDER #
sprintf(folder, "NES/CART/%d", foldern);
sd.mkdir(folder, true);
sd.chdir(folder);
@@ -1601,7 +1580,7 @@ void CartStart() {
void CartFinish() {
foldern += 1;
- EEPROM_writeAnything(0, foldern); // FOLDER #
+ EEPROM_writeAnything(0, foldern); // FOLDER #
sd.chdir();
}
#endif
@@ -1609,7 +1588,7 @@ void CartFinish() {
/******************************************
NES 2.0 Header Functions
*****************************************/
-#ifndef no-intro
+#ifndef nointro
int32_t atoi32_signed(const char* input_string) {
if (input_string == NULL) {
return 0;
@@ -1687,7 +1666,6 @@ void outputNES() {
println_Msg(F("PRG FILE FAILED!"));
display_Update();
print_Error(F("SD Error"), true);
-
}
if (has_header) {
@@ -1710,8 +1688,7 @@ void outputNES() {
print_Error(F("SD Error"), true);
}
- if (has_header)
- {
+ if (has_header) {
nesFile.write(nes_header_bytes, 16);
free(nes_header_bytes);
display_Clear();
@@ -1733,7 +1710,6 @@ void outputNES() {
println_Msg(F("CHR FILE FAILED!"));
display_Update();
print_Error(F("SD Error"), true);
-
}
while ((n = myFile.read(sdBuffer, sizeof(sdBuffer))) > 0) {
nesFile.write(sdBuffer, n);
@@ -2082,8 +2058,7 @@ chooseMapper:
display.drawLine(40, 30, 50, 30);
display.drawLine(60, 30, 70, 30);
display.setDrawColor(1);
- }
- else if (digit == 1) {
+ } else if (digit == 1) {
display.setDrawColor(0);
display.drawLine(20, 30, 30, 30);
display.setDrawColor(1);
@@ -2091,8 +2066,7 @@ chooseMapper:
display.setDrawColor(0);
display.drawLine(60, 30, 70, 30);
display.setDrawColor(1);
- }
- else if (digit == 2) {
+ } else if (digit == 2) {
display.setDrawColor(0);
display.drawLine(20, 30, 30, 30);
display.drawLine(40, 30, 50, 30);
@@ -2115,59 +2089,51 @@ chooseMapper:
hundreds++;
else
hundreds = 0;
- }
- else if (digit == 1) {
+ } else if (digit == 1) {
if (hundreds == 2) {
if (tens < 1)
tens++;
else
tens = 0;
- }
- else {
+ } else {
if (tens < 9)
tens++;
else
tens = 0;
}
- }
- else if (digit == 2) {
+ } else if (digit == 2) {
if (units < 9)
units++;
else
units = 0;
}
break;
- }
- else if (b == 2) {
+ } else if (b == 2) {
if (digit == 0) {
if (hundreds > 0)
hundreds--;
else
hundreds = 2;
- }
- else if (digit == 1) {
+ } else if (digit == 1) {
if (hundreds == 2) {
if (tens > 0)
tens--;
else
tens = 1;
- }
- else {
+ } else {
if (tens > 0)
tens--;
else
tens = 9;
}
- }
- else if (digit == 2) {
+ } else if (digit == 2) {
if (units > 0)
units--;
else
units = 9;
}
break;
- }
- else if (b == 3) {
+ } else if (b == 3) {
digit++;
break;
}
@@ -2209,7 +2175,7 @@ chooseMapper:
while (1) {
int b = checkButton();
- if (b == 2) { // Previous Mapper
+ if (b == 2) { // Previous Mapper
if (i == 0)
i = mapcount - 1;
else
@@ -2225,7 +2191,7 @@ chooseMapper:
display_Update();
}
- else if (b == 1) { // Next Mapper
+ else if (b == 1) { // Next Mapper
if (i == (mapcount - 1))
i = 0;
else
@@ -2241,7 +2207,7 @@ chooseMapper:
display_Update();
}
- else if (b == 3) { // Long Press - Execute
+ else if (b == 3) { // Long Press - Execute
newmapper = mapselect;
break;
}
@@ -2271,8 +2237,7 @@ setmapper:
Serial.println(F(""));
else
Serial.print(F("\t"));
- }
- else
+ } else
Serial.println(F(""));
}
Serial.print(F("Enter Mapper: "));
@@ -2350,7 +2315,7 @@ void setPRGSize() {
while (1) {
b = checkButton();
- if (b == doubleclick) { // Previous
+ if (b == doubleclick) { // Previous
if (i == prglo)
i = prghi;
else
@@ -2369,7 +2334,7 @@ void setPRGSize() {
#endif
display_Update();
}
- if (b == press) { // Next
+ if (b == press) { // Next
if (i == prghi)
i = prglo;
else
@@ -2388,13 +2353,13 @@ void setPRGSize() {
#endif
display_Update();
}
- if (b == hold) { // Long Press - Execute
+ if (b == hold) { // Long Press - Execute
newprgsize = i;
break;
}
}
- display.setCursor(0, 56); // Display selection at bottom
+ display.setCursor(0, 56); // Display selection at bottom
}
print_Msg(F("PRG SIZE "));
print_Msg(PRG[newprgsize]);
@@ -2470,7 +2435,7 @@ void setCHRSize() {
while (1) {
b = checkButton();
- if (b == doubleclick) { // Previous
+ if (b == doubleclick) { // Previous
if (i == chrlo)
i = chrhi;
else
@@ -2490,7 +2455,7 @@ void setCHRSize() {
display_Update();
}
- if (b == press) { // Next
+ if (b == press) { // Next
if (i == chrhi)
i = chrlo;
else
@@ -2510,12 +2475,12 @@ void setCHRSize() {
display_Update();
}
- if (b == hold) { // Long Press - Execute
+ if (b == hold) { // Long Press - Execute
newchrsize = i;
break;
}
}
- display.setCursor(0, 56); // Display selection at bottom
+ display.setCursor(0, 56); // Display selection at bottom
}
print_Msg(F("CHR SIZE "));
print_Msg(CHR[newchrsize]);
@@ -2586,8 +2551,7 @@ void setRAMSize() {
println_Msg(F("128"));
else
println_Msg(RAM[i]);
- }
- else if ((mapper == 159) || (mapper == 80))
+ } else if ((mapper == 159) || (mapper == 80))
println_Msg(RAM[i] * 16);
else if (mapper == 82)
println_Msg(i * 5);
@@ -2606,7 +2570,7 @@ void setRAMSize() {
while (1) {
b = checkButton();
- if (b == doubleclick) { // Previous Mapper
+ if (b == doubleclick) { // Previous Mapper
if (i == 0)
i = ramhi;
else
@@ -2623,8 +2587,7 @@ void setRAMSize() {
println_Msg(F("128"));
else
println_Msg(RAM[i]);
- }
- else if ((mapper == 159) || (mapper == 80))
+ } else if ((mapper == 159) || (mapper == 80))
println_Msg(RAM[i] * 16);
else if (mapper == 82)
println_Msg(i * 5);
@@ -2641,7 +2604,7 @@ void setRAMSize() {
display_Update();
}
- if (b == press) { // Next
+ if (b == press) { // Next
if (i == ramhi)
i = 0;
else
@@ -2658,8 +2621,7 @@ void setRAMSize() {
println_Msg(F("128"));
else
println_Msg(RAM[i]);
- }
- else if ((mapper == 159) || (mapper == 80))
+ } else if ((mapper == 159) || (mapper == 80))
println_Msg(RAM[i] * 16);
else if (mapper == 82)
println_Msg(i * 5);
@@ -2676,13 +2638,13 @@ void setRAMSize() {
display_Update();
}
- if (b == hold) { // Long Press - Execute
+ if (b == hold) { // Long Press - Execute
newramsize = i;
break;
}
}
- display.setCursor(0, 56); // Display selection at bottom
+ display.setCursor(0, 56); // Display selection at bottom
}
if ((mapper == 16) || (mapper == 159)) {
int sizeEEP = 0;
@@ -2693,8 +2655,7 @@ void setRAMSize() {
sizeEEP = RAM[newramsize] * 16;
print_Msg(sizeEEP);
println_Msg(F("B"));
- }
- else if (mapper == 19) {
+ } else if (mapper == 19) {
print_Msg(F("RAM SIZE "));
if (newramsize == 2)
println_Msg(F("128B"));
@@ -2702,13 +2663,11 @@ void setRAMSize() {
print_Msg(RAM[newramsize]);
println_Msg(F("K"));
}
- }
- else if (mapper == 80) {
+ } else if (mapper == 80) {
print_Msg(F("RAM SIZE "));
print_Msg(RAM[newramsize] * 16);
println_Msg(F("B"));
- }
- else {
+ } else {
print_Msg(F("RAM SIZE "));
if (mapper == 0)
print_Msg(newramsize * 2);
@@ -2734,23 +2693,20 @@ setram:
if (mapper == 0) {
Serial.print(RAM[i] / 4);
Serial.println(F("K"));
- }
- else if ((mapper == 16) || (mapper == 159)) {
+ } else if ((mapper == 16) || (mapper == 159)) {
if (mapper == 16)
Serial.print(RAM[i + ramlo] * 32);
else
Serial.print(RAM[i + ramlo] * 16);
Serial.println(F("B"));
- }
- else if (mapper == 19) {
+ } else if (mapper == 19) {
if (i == 2)
Serial.println(F("128B"));
else {
Serial.print(RAM[i + ramlo]);
Serial.println(F("K"));
}
- }
- else {
+ } else {
Serial.print(RAM[i + ramlo]);
Serial.println(F("K"));
}
@@ -2776,8 +2732,7 @@ setram:
Serial.print(sizeEEP);
Serial.println(F("B"));
Serial.println(F(""));
- }
- else if (mapper == 19) {
+ } else if (mapper == 19) {
Serial.print(F("RAM Size = "));
if (newramsize == 2)
Serial.println(F("128B"));
@@ -2786,14 +2741,12 @@ setram:
Serial.println(F("K"));
}
Serial.println(F(""));
- }
- else if (mapper == 80) {
+ } else if (mapper == 80) {
Serial.print(F("RAM Size = "));
Serial.print(RAM[newramsize] * 16);
Serial.println(F("B"));
Serial.println(F(""));
- }
- else {
+ } else {
Serial.print(F("RAM Size = "));
if (mapper == 0)
Serial.print(newramsize * 2);
@@ -2817,15 +2770,15 @@ setram:
// MMC6 Detection
// Mapper 4 includes both MMC3 AND MMC6
// RAM is mapped differently between MMC3 and MMC6
-void checkMMC6() { // Detect MMC6 Carts - read PRG 0x3E00A ("STARTROPICS")
- write_prg_byte(0x8000, 6); // PRG Bank 0 ($8000-$9FFF)
- write_prg_byte(0x8001, 0x1F); // 0x3E000
+void checkMMC6() { // Detect MMC6 Carts - read PRG 0x3E00A ("STARTROPICS")
+ write_prg_byte(0x8000, 6); // PRG Bank 0 ($8000-$9FFF)
+ write_prg_byte(0x8001, 0x1F); // 0x3E000
prgchk0 = read_prg_byte(0x800A);
prgchk1 = read_prg_byte(0x800B);
prgchk2 = read_prg_byte(0x800C);
prgchk3 = read_prg_byte(0x800D);
if ((prgchk0 == 0x53) && (prgchk1 == 0x54) && (prgchk2 == 0x41) && (prgchk3 == 0x52))
- mmc6 = true; // MMC6 Cart
+ mmc6 = true; // MMC6 Cart
}
void checkStatus_NES() {
@@ -2835,25 +2788,24 @@ void checkStatus_NES() {
EEPROM_readAnything(10, ramsize);
prg = (int_pow(2, prgsize)) * 16;
if (chrsize == 0)
- chr = 0; // 0K
+ chr = 0; // 0K
else
chr = (int_pow(2, chrsize)) * 4;
if (ramsize == 0)
- ram = 0; // 0K
+ ram = 0; // 0K
else if (mapper == 82)
- ram = 5; // 5K
+ ram = 5; // 5K
else
ram = (int_pow(2, ramsize)) * 4;
// Mapper Variants
// Identify variant for use across multiple functions
- if (mapper == 4) { // Check for MMC6/MMC3
+ if (mapper == 4) { // Check for MMC6/MMC3
checkMMC6();
if (mmc6)
- ram = 1; // 1K
- }
- else if (mapper == 30) // Check for Flashable/Non-Flashable
- NESmaker_ID(); // Flash ID
+ ram = 1; // 1K
+ } else if (mapper == 30) // Check for Flashable/Non-Flashable
+ NESmaker_ID(); // Flash ID
display_Clear();
println_Msg(F("NES CART READER"));
@@ -2872,23 +2824,20 @@ void checkStatus_NES() {
if (mapper == 0) {
print_Msg(ram / 4);
println_Msg(F("K"));
- }
- else if ((mapper == 16) || (mapper == 80) || (mapper == 159)) {
+ } else if ((mapper == 16) || (mapper == 80) || (mapper == 159)) {
if (mapper == 16)
print_Msg(ram * 32);
else
print_Msg(ram * 16);
println_Msg(F("B"));
- }
- else if (mapper == 19) {
+ } else if (mapper == 19) {
if (ramsize == 2)
println_Msg(F("128B"));
else {
print_Msg(ram);
println_Msg(F("K"));
}
- }
- else {
+ } else {
print_Msg(ram);
println_Msg(F("K"));
}
@@ -2915,7 +2864,7 @@ void dumpCHR(word address) {
myFile.write(sdBuffer, 512);
}
-void dumpCHR_M2(word address) { // MAPPER 45 - PULSE M2 LO/HI
+void dumpCHR_M2(word address) { // MAPPER 45 - PULSE M2 LO/HI
for (int x = 0; x < 512; x++) {
PHI2_LOW;
sdBuffer[x] = read_chr_byte(address + x);
@@ -2923,7 +2872,7 @@ void dumpCHR_M2(word address) { // MAPPER 45 - PULSE M2 LO/HI
myFile.write(sdBuffer, 512);
}
-void dumpMMC5RAM(word base, word address) { // MMC5 SRAM DUMP - PULSE M2 LO/HI
+void dumpMMC5RAM(word base, word address) { // MMC5 SRAM DUMP - PULSE M2 LO/HI
for (int x = 0; x < 512; x++) {
PHI2_LOW;
sdBuffer[x] = read_prg_byte(base + address + x);
@@ -2931,19 +2880,18 @@ void dumpMMC5RAM(word base, word address) { // MMC5 SRAM DUMP - PULSE M2 LO/HI
myFile.write(sdBuffer, 512);
}
-void writeMMC5RAM(word base, word address) { // MMC5 SRAM WRITE
+void writeMMC5RAM(word base, word address) { // MMC5 SRAM WRITE
myFile.read(sdBuffer, 512);
for (int x = 0; x < 512; x++) {
do {
- write_prg_byte(0x5102, 2); // PRG RAM PROTECT1
- write_prg_byte(0x5103, 1); // PRG RAM PROTECT2
+ write_prg_byte(0x5102, 2); // PRG RAM PROTECT1
+ write_prg_byte(0x5103, 1); // PRG RAM PROTECT2
write_wram_byte(base + address + x, sdBuffer[x]);
bytecheck = read_prg_byte(base + address + x);
- }
- while (bytecheck != sdBuffer[x]); // CHECK WRITTEN BYTE
+ } while (bytecheck != sdBuffer[x]); // CHECK WRITTEN BYTE
}
- write_prg_byte(0x5102, 0); // PRG RAM PROTECT1
- write_prg_byte(0x5103, 0); // PRG RAM PROTECT2
+ write_prg_byte(0x5102, 0); // PRG RAM PROTECT1
+ write_prg_byte(0x5103, 0); // PRG RAM PROTECT2
}
void readPRG(boolean readrom) {
@@ -2955,8 +2903,7 @@ void readPRG(boolean readrom) {
set_address(0);
_delay_us(1);
CreatePRGFileInSD();
- }
- else {
+ } else {
set_address(0);
_delay_us(1);
}
@@ -2968,36 +2915,36 @@ void readPRG(boolean readrom) {
case 0:
case 3:
case 13:
- case 87: // 16K/32K
- case 184: // 32K
- case 185: // 16K/32K
- for (word address = 0; address < ((prgsize * 0x4000) + 0x4000); address += 512) { // 16K or 32K
+ case 87: // 16K/32K
+ case 184: // 32K
+ case 185: // 16K/32K
+ for (word address = 0; address < ((prgsize * 0x4000) + 0x4000); address += 512) { // 16K or 32K
dumpPRG(base, address);
}
break;
case 1:
- case 155: // 32K/64K/128K/256K/512K
+ case 155: // 32K/64K/128K/256K/512K
banks = int_pow(2, prgsize) - 1;
- for (int i = 0; i < banks; i++) { // 16K Banks ($8000-$BFFF)
- write_prg_byte(0x8000, 0x80); // Clear Register
- write_mmc1_byte(0x8000, 0x0C); // Switch 16K Bank ($8000-$BFFF) + Fixed Last Bank ($C000-$FFFF)
- if (prgsize > 4) // 512K
- write_mmc1_byte(0xA000, 0x00); // Reset 512K Flag for Lower 256K
- if (i > 15) // Switch Upper 256K
- write_mmc1_byte(0xA000, 0x10); // Set 512K Flag
+ for (int i = 0; i < banks; i++) { // 16K Banks ($8000-$BFFF)
+ write_prg_byte(0x8000, 0x80); // Clear Register
+ write_mmc1_byte(0x8000, 0x0C); // Switch 16K Bank ($8000-$BFFF) + Fixed Last Bank ($C000-$FFFF)
+ if (prgsize > 4) // 512K
+ write_mmc1_byte(0xA000, 0x00); // Reset 512K Flag for Lower 256K
+ if (i > 15) // Switch Upper 256K
+ write_mmc1_byte(0xA000, 0x10); // Set 512K Flag
write_mmc1_byte(0xE000, i);
for (word address = 0x0; address < 0x4000; address += 512) {
dumpPRG(base, address);
}
}
- for (word address = 0x4000; address < 0x8000; address += 512) { // Final Bank ($C000-$FFFF)
+ for (word address = 0x4000; address < 0x8000; address += 512) { // Final Bank ($C000-$FFFF)
dumpPRG(base, address);
}
break;
- case 2: // 128K/256K
- for (int i = 0; i < 8; i++) { // 128K/256K
+ case 2: // 128K/256K
+ for (int i = 0; i < 8; i++) { // 128K/256K
write_prg_byte(0x8000, i);
for (word address = 0x0; address < (((prgsize - 3) * 0x4000) + 0x4000); address += 512) {
dumpPRG(base, address);
@@ -3013,35 +2960,35 @@ void readPRG(boolean readrom) {
case 158:
banks = ((int_pow(2, prgsize) * 2)) - 2; // Set Number of Banks
if (mapper == 47)
- write_prg_byte(0xA001, 0x80); // Block Register - PRG RAM Chip Enable, Writable
- for (int i = 0; i < banks; i += 2) { // 32K/64K/128K/256K/512K
+ write_prg_byte(0xA001, 0x80); // Block Register - PRG RAM Chip Enable, Writable
+ for (int i = 0; i < banks; i += 2) { // 32K/64K/128K/256K/512K
if (mapper == 47) {
if (i == 0)
- write_prg_byte(0x6000, 0); // Switch to Lower Block
+ write_prg_byte(0x6000, 0); // Switch to Lower Block
else if (i == 16)
- write_prg_byte(0x6000, 1); // Switch to Upper Block
+ write_prg_byte(0x6000, 1); // Switch to Upper Block
}
- write_prg_byte(0x8000, 6); // PRG Bank 0 ($8000-$9FFF)
+ write_prg_byte(0x8000, 6); // PRG Bank 0 ($8000-$9FFF)
write_prg_byte(0x8001, i);
- write_prg_byte(0x8000, 7); // PRG Bank 1 ($A000-$BFFF)
+ write_prg_byte(0x8000, 7); // PRG Bank 1 ($A000-$BFFF)
write_prg_byte(0x8001, i + 1);
for (word address = 0x0; address < 0x4000; address += 512) {
dumpPRG(base, address);
}
}
if ((mapper == 64) || (mapper == 158)) {
- write_prg_byte(0x8000, 15); // PRG Bank 2 ($C000-$DFFF)
+ write_prg_byte(0x8000, 15); // PRG Bank 2 ($C000-$DFFF)
write_prg_byte(0x8001, banks);
}
- for (word address = 0x4000; address < 0x8000; address += 512) { // Final 2 Banks ($C000-$FFFF)
+ for (word address = 0x4000; address < 0x8000; address += 512) { // Final 2 Banks ($C000-$FFFF)
dumpPRG(base, address);
}
break;
- case 5: // 128K/256K/512K
+ case 5: // 128K/256K/512K
banks = int_pow(2, prgsize) * 2;
- write_prg_byte(0x5100, 3); // 8K PRG Banks
- for (int i = 0; i < banks; i += 2) { // 128K/256K/512K
+ write_prg_byte(0x5100, 3); // 8K PRG Banks
+ for (int i = 0; i < banks; i += 2) { // 128K/256K/512K
write_prg_byte(0x5114, i | 0x80);
write_prg_byte(0x5115, (i + 1) | 0x80);
for (word address = 0x0; address < 0x4000; address += 512) {
@@ -3050,66 +2997,66 @@ void readPRG(boolean readrom) {
}
break;
- case 7: // 128K/256K
+ case 7: // 128K/256K
case 34:
case 77:
- case 96: // 128K
+ case 96: // 128K
banks = int_pow(2, prgsize) / 2;
- for (int i = 0; i < banks; i++) { // 32K Banks
+ for (int i = 0; i < banks; i++) { // 32K Banks
write_prg_byte(0x8000, i);
- for (word address = 0x0; address < 0x8000; address += 512) { // 32K Banks ($8000-$FFFF)
+ for (word address = 0x0; address < 0x8000; address += 512) { // 32K Banks ($8000-$FFFF)
dumpPRG(base, address);
}
}
break;
- case 9: // 128K
- for (int i = 0; i < 13; i++) { // 16-3 = 13 = 128K
- write_prg_byte(0xA000, i); // $8000-$9FFF
- for (word address = 0x0; address < 0x2000; address += 512) { // Switch Bank ($8000-$9FFF)
+ case 9: // 128K
+ for (int i = 0; i < 13; i++) { // 16-3 = 13 = 128K
+ write_prg_byte(0xA000, i); // $8000-$9FFF
+ for (word address = 0x0; address < 0x2000; address += 512) { // Switch Bank ($8000-$9FFF)
dumpPRG(base, address);
}
}
- for (word address = 0x2000; address < 0x8000; address += 512) { // Final 3 Banks ($A000-$FFFF)
+ for (word address = 0x2000; address < 0x8000; address += 512) { // Final 3 Banks ($A000-$FFFF)
dumpPRG(base, address);
}
break;
- case 10: // 128K/256K
+ case 10: // 128K/256K
for (int i = 0; i < (((prgsize - 3) * 8) + 7); i++) {
- write_prg_byte(0xA000, i); // $8000-$BFFF
- for (word address = 0x0; address < 0x4000; address += 512) { // Switch Bank ($8000-$BFFF)
+ write_prg_byte(0xA000, i); // $8000-$BFFF
+ for (word address = 0x0; address < 0x4000; address += 512) { // Switch Bank ($8000-$BFFF)
dumpPRG(base, address);
}
}
- for (word address = 0x4000; address < 0x8000; address += 512) { // Final Bank ($C000-$FFFF)
+ for (word address = 0x4000; address < 0x8000; address += 512) { // Final Bank ($C000-$FFFF)
dumpPRG(base, address);
}
break;
-
+
case 11:
banks = int_pow(2, prgsize) / 2;
for (int i = 0; i < banks; i++) {
- write_prg_byte(0xFFB0+i, i);
+ write_prg_byte(0xFFB0 + i, i);
for (word address = 0x0; address < 0x8000; address += 512) {
dumpPRG(base, address);
}
}
break;
-
+
case 16:
- case 159: // 128K/256K
+ case 159: // 128K/256K
banks = int_pow(2, prgsize);
for (int i = 0; i < banks; i++) {
- write_prg_byte(0x6008, i); // Submapper 4
- write_prg_byte(0x8008, i); // Submapper 5
- for (word address = 0x0; address < 0x4000; address += 512) { // 16K Banks ($8000-$BFFF)
+ write_prg_byte(0x6008, i); // Submapper 4
+ write_prg_byte(0x8008, i); // Submapper 5
+ for (word address = 0x0; address < 0x4000; address += 512) { // 16K Banks ($8000-$BFFF)
dumpPRG(base, address);
}
}
break;
- case 18: // 128K/256K
+ case 18: // 128K/256K
banks = int_pow(2, prgsize) * 2;
for (int i = 0; i < banks; i += 2) {
write_prg_byte(0x8000, i & 0xF);
@@ -3122,13 +3069,13 @@ void readPRG(boolean readrom) {
}
break;
- case 19: // 128K/256K
- for (int j = 0; j < 64; j++) { // Init Register
- write_ram_byte(0xE000, 0); // PRG Bank 0 ($8000-$9FFF)
+ case 19: // 128K/256K
+ for (int j = 0; j < 64; j++) { // Init Register
+ write_ram_byte(0xE000, 0); // PRG Bank 0 ($8000-$9FFF)
}
banks = int_pow(2, prgsize) * 2;
for (int i = 0; i < banks; i++) {
- write_ram_byte(0xE000, i); // PRG Bank 0 ($8000-$9FFF)
+ write_ram_byte(0xE000, i); // PRG Bank 0 ($8000-$9FFF)
for (word address = 0x0; address < 0x2000; address += 512) {
dumpPRG(base, address);
}
@@ -3149,7 +3096,7 @@ void readPRG(boolean readrom) {
case 23:
case 25:
case 65:
- case 75: // 128K/256K
+ case 75: // 128K/256K
banks = int_pow(2, prgsize) * 2;
for (int i = 0; i < banks; i += 2) {
write_prg_byte(0x8000, i);
@@ -3161,48 +3108,48 @@ void readPRG(boolean readrom) {
break;
case 24:
- case 26: // 256K
- case 78: // 128K
+ case 26: // 256K
+ case 78: // 128K
banks = int_pow(2, prgsize);
- for (int i = 0; i < banks; i++) { // 128K
+ for (int i = 0; i < banks; i++) { // 128K
write_prg_byte(0x8000, i);
- for (word address = 0x0; address < 0x4000; address += 512) { // 16K Banks ($8000-$BFFF)
+ for (word address = 0x0; address < 0x4000; address += 512) { // 16K Banks ($8000-$BFFF)
dumpPRG(base, address);
}
}
break;
- case 30: // 256K/512K
+ case 30: // 256K/512K
banks = int_pow(2, prgsize);
- for (int i = 0; i < banks; i++) { // 256K/512K
+ for (int i = 0; i < banks; i++) { // 256K/512K
if (flashfound)
- write_prg_byte(0xC000 + i, i); // Flashable
+ write_prg_byte(0xC000 + i, i); // Flashable
else
- write_prg_byte(0x8000 + i, i); // Non-Flashable
- for (word address = 0x0; address < 0x4000; address += 512) { // 16K Banks ($8000-$BFFF)
+ write_prg_byte(0x8000 + i, i); // Non-Flashable
+ for (word address = 0x0; address < 0x4000; address += 512) { // 16K Banks ($8000-$BFFF)
dumpPRG(base, address);
}
}
break;
- case 32: // 128K/256K
+ case 32: // 128K/256K
banks = int_pow(2, prgsize) * 2;
- for (int i = 0; i < banks; i++) { // 128K/256K
- write_prg_byte(0x9000, 1); // PRG Mode 0 - Read $A000-$BFFF to avoid difference between Modes 0 and 1
- write_prg_byte(0xA000, i); // PRG Bank
- for (word address = 0x2000; address < 0x4000; address += 512) { // 8K Banks ($A000-$BFFF)
+ for (int i = 0; i < banks; i++) { // 128K/256K
+ write_prg_byte(0x9000, 1); // PRG Mode 0 - Read $A000-$BFFF to avoid difference between Modes 0 and 1
+ write_prg_byte(0xA000, i); // PRG Bank
+ for (word address = 0x2000; address < 0x4000; address += 512) { // 8K Banks ($A000-$BFFF)
dumpPRG(base, address);
}
}
break;
case 33:
- case 48: // 128K/256K
+ case 48: // 128K/256K
banks = int_pow(2, prgsize) * 2;
for (int i = 0; i < banks; i += 2) {
- write_prg_byte(0x8000, i); // PRG Bank 0 ($8000-$9FFF)
- write_prg_byte(0x8001, i + 1); // PRG Bank 1 ($A000-$BFFF)
- for (word address = 0x0; address < 0x4000; address += 512) { // 8K Banks ($8000-$BFFF)
+ write_prg_byte(0x8000, i); // PRG Bank 0 ($8000-$9FFF)
+ write_prg_byte(0x8001, i + 1); // PRG Bank 1 ($A000-$BFFF)
+ for (word address = 0x0; address < 0x4000; address += 512) { // 8K Banks ($8000-$BFFF)
dumpPRG(base, address);
}
}
@@ -3210,97 +3157,97 @@ void readPRG(boolean readrom) {
case 37:
banks = ((int_pow(2, prgsize) * 2)) - 2; // Set Number of Banks
- write_prg_byte(0xA001, 0x80); // Block Register - PRG RAM Chip Enable, Writable
- for (int i = 0; i < banks; i += 2) { // 256K
+ write_prg_byte(0xA001, 0x80); // Block Register - PRG RAM Chip Enable, Writable
+ for (int i = 0; i < banks; i += 2) { // 256K
if (i == 0)
- write_prg_byte(0x6000, 0); // Switch to Lower Block ($0000-$FFFF)
+ write_prg_byte(0x6000, 0); // Switch to Lower Block ($0000-$FFFF)
else if (i == 8)
- write_prg_byte(0x6000, 3); // Switch to 2nd 64K Block ($10000-$1FFFF)
+ write_prg_byte(0x6000, 3); // Switch to 2nd 64K Block ($10000-$1FFFF)
else if (i == 16)
- write_prg_byte(0x6000, 4); // Switch to 128K Block ($20000-$3FFFF)
- write_prg_byte(0x8000, 6); // PRG Bank 0 ($8000-$9FFF)
+ write_prg_byte(0x6000, 4); // Switch to 128K Block ($20000-$3FFFF)
+ write_prg_byte(0x8000, 6); // PRG Bank 0 ($8000-$9FFF)
write_prg_byte(0x8001, i);
- write_prg_byte(0x8000, 7); // PRG Bank 1 ($A000-$BFFF)
+ write_prg_byte(0x8000, 7); // PRG Bank 1 ($A000-$BFFF)
write_prg_byte(0x8001, i + 1);
for (word address = 0x0; address < 0x4000; address += 512) {
dumpPRG(base, address);
}
}
- for (word address = 0x4000; address < 0x8000; address += 512) { // Final 2 Banks ($C000-$FFFF)
+ for (word address = 0x4000; address < 0x8000; address += 512) { // Final 2 Banks ($C000-$FFFF)
dumpPRG(base, address);
}
break;
- case 45: // MMC3 Clone with Outer Registers
+ case 45: // MMC3 Clone with Outer Registers
banks = ((int_pow(2, prgsize) * 2)) - 2; // Set Number of Banks
- for (int i = 0; i < banks; i += 2) { // 128K/256K/512K/1024K
+ for (int i = 0; i < banks; i += 2) { // 128K/256K/512K/1024K
// set outer bank registers
- write_prg_byte(0x6000, 0x00); // CHR-OR
- write_prg_byte(0x6000, (i & 0xC0)); // PRG-OR
- write_prg_byte(0x6000, ((i >> 2) & 0xC0)); // CHR-AND,CHR-OR/PRG-OR
- write_prg_byte(0x6000, 0x80); // PRG-AND
+ write_prg_byte(0x6000, 0x00); // CHR-OR
+ write_prg_byte(0x6000, (i & 0xC0)); // PRG-OR
+ write_prg_byte(0x6000, ((i >> 2) & 0xC0)); // CHR-AND,CHR-OR/PRG-OR
+ write_prg_byte(0x6000, 0x80); // PRG-AND
// set inner bank registers
- write_prg_byte(0x8000, 6); // PRG Bank 0 ($8000-$9FFF)
+ write_prg_byte(0x8000, 6); // PRG Bank 0 ($8000-$9FFF)
write_prg_byte(0x8001, i);
for (word address = 0x0; address < 0x2000; address += 512) {
dumpPRG(base, address);
}
// set outer bank registers
- write_prg_byte(0x6000, 0x00); // CHR-OR
- write_prg_byte(0x6000, ((i + 1) & 0xC0)); // PRG-OR
- write_prg_byte(0x6000, (((i + 1) >> 2) & 0xC0)); // CHR-AND,CHR-OR/PRG-OR
- write_prg_byte(0x6000, 0x80); // PRG-AND
+ write_prg_byte(0x6000, 0x00); // CHR-OR
+ write_prg_byte(0x6000, ((i + 1) & 0xC0)); // PRG-OR
+ write_prg_byte(0x6000, (((i + 1) >> 2) & 0xC0)); // CHR-AND,CHR-OR/PRG-OR
+ write_prg_byte(0x6000, 0x80); // PRG-AND
// set inner bank registers
- write_prg_byte(0x8000, 7); // PRG Bank 1 ($A000-$BFFF)
+ write_prg_byte(0x8000, 7); // PRG Bank 1 ($A000-$BFFF)
write_prg_byte(0x8001, i + 1);
for (word address = 0x2000; address < 0x4000; address += 512) {
dumpPRG(base, address);
}
}
- for (word address = 0x4000; address < 0x8000; address += 512) { // Final 2 Banks ($C000-$FFFF)
+ for (word address = 0x4000; address < 0x8000; address += 512) { // Final 2 Banks ($C000-$FFFF)
dumpPRG(base, address);
}
break;
- case 66: // 64K/128K
+ case 66: // 64K/128K
banks = int_pow(2, prgsize) / 2;
- for (int i = 0; i < banks; i++) { // 64K/128K
- write_prg_byte(0x8000, i << 4); // bits 4-5
- for (word address = 0x0; address < 0x8000; address += 512) { // 32K Banks ($8000-$FFFF)
+ for (int i = 0; i < banks; i++) { // 64K/128K
+ write_prg_byte(0x8000, i << 4); // bits 4-5
+ for (word address = 0x0; address < 0x8000; address += 512) { // 32K Banks ($8000-$FFFF)
dumpPRG(base, address);
}
}
break;
- case 67: // 128K
+ case 67: // 128K
banks = int_pow(2, prgsize);
- for (int i = 0; i < banks; i++) { // 128K
- write_reg_byte(0xF800, i); // [WRITE RAM SAFE]
- for (word address = 0x0; address < 0x4000; address += 512) { // 16K Banks ($8000-$BFFF)
+ for (int i = 0; i < banks; i++) { // 128K
+ write_reg_byte(0xF800, i); // [WRITE RAM SAFE]
+ for (word address = 0x0; address < 0x4000; address += 512) { // 16K Banks ($8000-$BFFF)
dumpPRG(base, address);
}
}
break;
case 68:
- case 73: // 128K
+ case 73: // 128K
banks = int_pow(2, prgsize);
- for (int i = 0; i < banks; i++) { // 128K
- write_reg_byte(0xF000, i); // [WRITE RAM SAFE]
- for (word address = 0x0; address < 0x4000; address += 512) { // 16K Banks ($8000-$BFFF)
+ for (int i = 0; i < banks; i++) { // 128K
+ write_reg_byte(0xF000, i); // [WRITE RAM SAFE]
+ for (word address = 0x0; address < 0x4000; address += 512) { // 16K Banks ($8000-$BFFF)
dumpPRG(base, address);
}
}
break;
- case 69: // 128K/256K
+ case 69: // 128K/256K
banks = int_pow(2, prgsize) * 2;
- write_prg_byte(0x8000, 8); // Command Register - PRG Bank 0
- write_prg_byte(0xA000, 0); // Parameter Register - PRG RAM Disabled, PRG ROM, Bank 0 to $6000-$7FFF
- for (int i = 0; i < banks; i++) { // 128K/256K
- write_prg_byte(0x8000, 9); // Command Register - PRG Bank 1
- write_prg_byte(0xA000, i); // Parameter Register - ($8000-$9FFF)
- for (word address = 0x0000; address < 0x2000; address += 512) { // 8K Banks ($8000-$9FFF)
+ write_prg_byte(0x8000, 8); // Command Register - PRG Bank 0
+ write_prg_byte(0xA000, 0); // Parameter Register - PRG RAM Disabled, PRG ROM, Bank 0 to $6000-$7FFF
+ for (int i = 0; i < banks; i++) { // 128K/256K
+ write_prg_byte(0x8000, 9); // Command Register - PRG Bank 1
+ write_prg_byte(0xA000, i); // Parameter Register - ($8000-$9FFF)
+ for (word address = 0x0000; address < 0x2000; address += 512) { // 8K Banks ($8000-$9FFF)
dumpPRG(base, address);
}
}
@@ -3308,33 +3255,33 @@ void readPRG(boolean readrom) {
case 70:
case 89:
- case 152: // 64K/128K
+ case 152: // 64K/128K
banks = int_pow(2, prgsize);
- for (int i = 0; i < banks; i++) { // 128K
+ for (int i = 0; i < banks; i++) { // 128K
write_prg_byte(0x8000, i << 4);
- for (word address = 0x0; address < 0x4000; address += 512) { // 16K Banks ($8000-$BFFF)
+ for (word address = 0x0; address < 0x4000; address += 512) { // 16K Banks ($8000-$BFFF)
dumpPRG(base, address);
}
}
break;
- case 71: // 64K/128K/256K
+ case 71: // 64K/128K/256K
banks = int_pow(2, prgsize);
for (int i = 0; i < banks; i++) {
write_prg_byte(0xC000, i);
- for (word address = 0x0; address < 0x4000; address += 512) { // 16K Banks ($8000-$BFFF)
+ for (word address = 0x0; address < 0x4000; address += 512) { // 16K Banks ($8000-$BFFF)
dumpPRG(base, address);
}
}
break;
- case 72: // 128K
+ case 72: // 128K
banks = int_pow(2, prgsize);
- write_prg_byte(0x8000, 0); // Reset Register
- for (int i = 0; i < banks; i++) { // 128K
- write_prg_byte(0x8000, i | 0x80); // PRG Command + Bank
- write_prg_byte(0x8000, i); // PRG Bank
- for (word address = 0x0; address < 0x4000; address += 512) { // 16K Banks ($8000-$BFFF)
+ write_prg_byte(0x8000, 0); // Reset Register
+ for (int i = 0; i < banks; i++) { // 128K
+ write_prg_byte(0x8000, i | 0x80); // PRG Command + Bank
+ write_prg_byte(0x8000, i); // PRG Bank
+ for (word address = 0x0; address < 0x4000; address += 512) { // 16K Banks ($8000-$BFFF)
dumpPRG(base, address);
}
}
@@ -3343,15 +3290,15 @@ void readPRG(boolean readrom) {
case 76:
case 88:
case 95:
- case 154: // 128K
- case 206: // 32K/64K/128K
+ case 154: // 128K
+ case 206: // 32K/64K/128K
banks = int_pow(2, prgsize) * 2;
for (int i = 0; i < banks; i += 2) {
- write_prg_byte(0x8000, 6); // PRG ROM Command ($8000-$9FFF)
- write_prg_byte(0x8001, i); // PRG Bank
- write_prg_byte(0x8000, 7); // PRG ROM Command ($A000-$BFFF)
- write_prg_byte(0x8001, i + 1); // PRG Bank
- for (word address = 0x0; address < 0x4000; address += 512) { // 8K Banks ($8000-$BFFF)
+ write_prg_byte(0x8000, 6); // PRG ROM Command ($8000-$9FFF)
+ write_prg_byte(0x8001, i); // PRG Bank
+ write_prg_byte(0x8000, 7); // PRG ROM Command ($A000-$BFFF)
+ write_prg_byte(0x8001, i + 1); // PRG Bank
+ for (word address = 0x0; address < 0x4000; address += 512) { // 8K Banks ($8000-$BFFF)
dumpPRG(base, address);
}
}
@@ -3367,58 +3314,58 @@ void readPRG(boolean readrom) {
}
}
break;
-
- case 80: // 128K
- case 207: // 256K [CART SOMETIMES NEEDS POWERCYCLE]
+
+ case 80: // 128K
+ case 207: // 256K [CART SOMETIMES NEEDS POWERCYCLE]
banks = int_pow(2, prgsize) * 2;
for (int i = 0; i < banks; i += 2) {
- write_prg_byte(0x7EFA, i); // PRG Bank 0 ($8000-$9FFF)
- write_prg_byte(0x7EFC, i + 1); // PRG Bank 1 ($A000-$BFFF)
+ write_prg_byte(0x7EFA, i); // PRG Bank 0 ($8000-$9FFF)
+ write_prg_byte(0x7EFC, i + 1); // PRG Bank 1 ($A000-$BFFF)
for (word address = 0x0; address < 0x4000; address += 512) {
dumpPRG(base, address);
}
}
break;
- case 82: // 128K
+ case 82: // 128K
banks = int_pow(2, prgsize) * 2;
for (int i = 0; i < banks; i += 2) {
- write_prg_byte(0x7EFA, i << 2); // PRG Bank 0 ($8000-$9FFF)
- write_prg_byte(0x7EFB, (i + 1) << 2); // PRG Bank 1 ($A000-$BFFF)
- for (word address = 0x0; address < 0x4000; address += 512) { // 8K Banks ($8000-$BFFF)
+ write_prg_byte(0x7EFA, i << 2); // PRG Bank 0 ($8000-$9FFF)
+ write_prg_byte(0x7EFB, (i + 1) << 2); // PRG Bank 1 ($A000-$BFFF)
+ for (word address = 0x0; address < 0x4000; address += 512) { // 8K Banks ($8000-$BFFF)
dumpPRG(base, address);
}
}
break;
- case 85: // 128K/512K
+ case 85: // 128K/512K
banks = int_pow(2, prgsize) * 2;
for (int i = 0; i < banks; i++) {
- write_prg_byte(0x8000, i); // PRG Bank 0 ($8000-$9FFF)
- for (word address = 0x0; address < 0x2000; address += 512) { // 8K Banks ($8000-$9FFF)
+ write_prg_byte(0x8000, i); // PRG Bank 0 ($8000-$9FFF)
+ for (word address = 0x0; address < 0x2000; address += 512) { // 8K Banks ($8000-$9FFF)
dumpPRG(base, address);
}
}
break;
case 86:
- case 140: // 128K
+ case 140: // 128K
banks = int_pow(2, prgsize) / 2;
- for (int i = 0; i < banks; i++) { // 128K
- write_prg_byte(0x6000, i << 4); // bits 4-5
- for (word address = 0x0; address < 0x8000; address += 512) { // 32K Banks ($8000-$FFFF)
+ for (int i = 0; i < banks; i++) { // 128K
+ write_prg_byte(0x6000, i << 4); // bits 4-5
+ for (word address = 0x0; address < 0x8000; address += 512) { // 32K Banks ($8000-$FFFF)
dumpPRG(base, address);
}
}
break;
- case 92: // 256K
+ case 92: // 256K
banks = int_pow(2, prgsize);
- write_prg_byte(0x8000, 0); // Reset Register
- for (int i = 0; i < banks; i++) { // 256K
- write_prg_byte(0x8000, i | 0x80); // PRG Command + Bank
- write_prg_byte(0x8000, i); // PRG Bank
- for (word address = 0x4000; address < 0x8000; address += 512) { // 16K Banks ($C000-$FFFF)
+ write_prg_byte(0x8000, 0); // Reset Register
+ for (int i = 0; i < banks; i++) { // 256K
+ write_prg_byte(0x8000, i | 0x80); // PRG Command + Bank
+ write_prg_byte(0x8000, i); // PRG Bank
+ for (word address = 0x4000; address < 0x8000; address += 512) { // 16K Banks ($C000-$FFFF)
dumpPRG(base, address);
}
}
@@ -3437,7 +3384,7 @@ void readPRG(boolean readrom) {
case 94:
banks = int_pow(2, prgsize);
- for (int i = 0; i < banks; i++) { // 128K
+ for (int i = 0; i < banks; i++) { // 128K
write_prg_byte(0x8000, i << 2);
for (word address = 0x0; address < 0x4000; address += 512) {
dumpPRG(base, address);
@@ -3445,64 +3392,64 @@ void readPRG(boolean readrom) {
}
break;
- case 97: // 256K
+ case 97: // 256K
banks = int_pow(2, prgsize);
- for (int i = 0; i < banks; i++) { // 256K
- write_prg_byte(0x8000, i); // PRG Bank
- for (word address = 0x4000; address < 0x8000; address += 512) { // 16K Banks ($C000-$FFFF)
+ for (int i = 0; i < banks; i++) { // 256K
+ write_prg_byte(0x8000, i); // PRG Bank
+ for (word address = 0x4000; address < 0x8000; address += 512) { // 16K Banks ($C000-$FFFF)
dumpPRG(base, address);
}
}
break;
- case 105: // 256K
- write_mmc1_byte(0xA000, 0x00); // Clear PRG Init/IRQ (Bit 4)
- write_mmc1_byte(0xA000, 0x10); // Set PRG Init/IRQ (Bit 4) to enable bank swapping
- for (int i = 0; i < 4; i++) { // PRG CHIP 1 128K
+ case 105: // 256K
+ write_mmc1_byte(0xA000, 0x00); // Clear PRG Init/IRQ (Bit 4)
+ write_mmc1_byte(0xA000, 0x10); // Set PRG Init/IRQ (Bit 4) to enable bank swapping
+ for (int i = 0; i < 4; i++) { // PRG CHIP 1 128K
write_mmc1_byte(0xA000, i << 1);
- for (word address = 0x0; address < 0x8000; address += 512) { // 32K Banks ($8000-$FFFF)
+ for (word address = 0x0; address < 0x8000; address += 512) { // 32K Banks ($8000-$FFFF)
dumpPRG(base, address);
}
}
- write_mmc1_byte(0x8000, 0x0C); // Switch 16K Bank ($8000-$BFFF) + Fixed Last Bank ($C000-$FFFF)
- write_mmc1_byte(0xA000, 0x08); // Select PRG CHIP 2 (Bit 3)
- for (int j = 0; j < 8; j++) { // PRG CHIP 2 128K
+ write_mmc1_byte(0x8000, 0x0C); // Switch 16K Bank ($8000-$BFFF) + Fixed Last Bank ($C000-$FFFF)
+ write_mmc1_byte(0xA000, 0x08); // Select PRG CHIP 2 (Bit 3)
+ for (int j = 0; j < 8; j++) { // PRG CHIP 2 128K
write_mmc1_byte(0xE000, j);
- for (word address = 0x0; address < 0x4000; address += 512) { // 16K Banks ($8000-$BFFF)
+ for (word address = 0x0; address < 0x4000; address += 512) { // 16K Banks ($8000-$BFFF)
dumpPRG(base, address);
}
}
break;
- case 180: // 128K
+ case 180: // 128K
banks = int_pow(2, prgsize);
for (int i = 0; i < banks; i++) {
write_prg_byte(0x8000, i);
- for (word address = 0x4000; address < 0x8000; address += 512) { // 16K Banks ($C000-$FFFF)
+ for (word address = 0x4000; address < 0x8000; address += 512) { // 16K Banks ($C000-$FFFF)
dumpPRG(base, address);
}
}
break;
- case 153: // 512K
+ case 153: // 512K
banks = int_pow(2, prgsize);
- for (int i = 0; i < banks; i++) { // 512K
- write_prg_byte(0x8000, i >> 4); // PRG Outer Bank (Documentation says duplicate over $8000-$8003 registers)
- write_prg_byte(0x8001, i >> 4); // PRG Outer Bank
- write_prg_byte(0x8002, i >> 4); // PRG Outer Bank
- write_prg_byte(0x8003, i >> 4); // PRG Outer Bank
- write_prg_byte(0x8008, i & 0xF); // PRG Inner Bank
- for (word address = 0x0000; address < 0x4000; address += 512) { // 16K Banks ($8000-$BFFF)
+ for (int i = 0; i < banks; i++) { // 512K
+ write_prg_byte(0x8000, i >> 4); // PRG Outer Bank (Documentation says duplicate over $8000-$8003 registers)
+ write_prg_byte(0x8001, i >> 4); // PRG Outer Bank
+ write_prg_byte(0x8002, i >> 4); // PRG Outer Bank
+ write_prg_byte(0x8003, i >> 4); // PRG Outer Bank
+ write_prg_byte(0x8008, i & 0xF); // PRG Inner Bank
+ for (word address = 0x0000; address < 0x4000; address += 512) { // 16K Banks ($8000-$BFFF)
dumpPRG(base, address);
}
}
break;
- case 210: // 128K/256K
+ case 210: // 128K/256K
banks = int_pow(2, prgsize) * 2;
for (int i = 0; i < banks; i += 2) {
- write_prg_byte(0xE000, i); // PRG Bank 0 ($8000-$9FFF) [WRITE NO RAM]
- write_prg_byte(0xE800, i + 1); // PRG Bank 1 ($A000-$BFFF) [WRITE NO RAM]
+ write_prg_byte(0xE000, i); // PRG Bank 0 ($8000-$9FFF) [WRITE NO RAM]
+ write_prg_byte(0xE800, i + 1); // PRG Bank 1 ($A000-$BFFF) [WRITE NO RAM]
for (word address = 0x0; address < 0x4000; address += 512) {
dumpPRG(base, address);
}
@@ -3516,7 +3463,7 @@ void readPRG(boolean readrom) {
println_Msg(F("PRG FILE DUMPED!"));
println_Msg(F(""));
display_Update();
-#ifndef no-intro
+#ifndef nointro
calcCRC(fileName, prg * 1024, &prg_crc32, 0);
#endif
}
@@ -3539,14 +3486,13 @@ void readCHR(boolean readrom) {
if (chrsize == 0) {
println_Msg(F("CHR SIZE 0K"));
display_Update();
- }
- else {
+ } else {
if (!readrom) {
CreateCHRFileInSD();
}
if (myFile) {
switch (mapper) {
- case 0: // 8K
+ case 0: // 8K
for (word address = 0x0; address < 0x2000; address += 512) {
dumpCHR(address);
}
@@ -3555,8 +3501,8 @@ void readCHR(boolean readrom) {
case 1:
case 155:
banks = int_pow(2, chrsize);
- for (int i = 0; i < banks; i += 2) { // 8K/16K/32K/64K/128K (Bank #s are based on 4K Banks)
- write_prg_byte(0x8000, 0x80); // Clear Register
+ for (int i = 0; i < banks; i += 2) { // 8K/16K/32K/64K/128K (Bank #s are based on 4K Banks)
+ write_prg_byte(0x8000, 0x80); // Clear Register
write_mmc1_byte(0xA000, i);
for (word address = 0x0; address < 0x2000; address += 512) {
dumpCHR(address);
@@ -3564,13 +3510,13 @@ void readCHR(boolean readrom) {
}
break;
- case 3: // 8K/16K/32K
- case 66: // 16K/32K
+ case 3: // 8K/16K/32K
+ case 66: // 16K/32K
case 70:
- case 152: // 128K
+ case 152: // 128K
banks = int_pow(2, chrsize) / 2;
- for (int i = 0; i < banks; i++) { // 8K Banks
- write_prg_byte(0x8000, i); // CHR Bank 0
+ for (int i = 0; i < banks; i++) { // 8K Banks
+ write_prg_byte(0x8000, i); // CHR Bank 0
for (word address = 0x0; address < 0x2000; address += 512) {
dumpCHR(address);
}
@@ -3585,17 +3531,17 @@ void readCHR(boolean readrom) {
case 158:
banks = int_pow(2, chrsize) * 4;
if (mapper == 47)
- write_prg_byte(0xA001, 0x80); // Block Register - PRG RAM Chip Enable, Writable
- for (int i = 0; i < banks; i += 4) { // 8K/16K/32K/64K/128K/256K
+ write_prg_byte(0xA001, 0x80); // Block Register - PRG RAM Chip Enable, Writable
+ for (int i = 0; i < banks; i += 4) { // 8K/16K/32K/64K/128K/256K
if (mapper == 47) {
if (i == 0)
- write_prg_byte(0x6000, 0); // Switch to Lower Block
+ write_prg_byte(0x6000, 0); // Switch to Lower Block
else if (i == 128)
- write_prg_byte(0x6000, 1); // Switch to Upper Block
+ write_prg_byte(0x6000, 1); // Switch to Upper Block
}
- write_prg_byte(0x8000, 0); // CHR Bank 0 ($0000-$07FF)
+ write_prg_byte(0x8000, 0); // CHR Bank 0 ($0000-$07FF)
write_prg_byte(0x8001, i);
- write_prg_byte(0x8000, 1); // CHR Bank 1 ($0800-$0FFF)
+ write_prg_byte(0x8000, 1); // CHR Bank 1 ($0800-$0FFF)
write_prg_byte(0x8001, i + 2);
for (word address = 0x0; address < 0x1000; address += 512) {
dumpCHR(address);
@@ -3603,32 +3549,32 @@ void readCHR(boolean readrom) {
}
break;
- case 5: // 128K/256K/512K
+ case 5: // 128K/256K/512K
banks = int_pow(2, chrsize) / 2;
- write_prg_byte(0x5101, 0); // 8K CHR Banks
+ write_prg_byte(0x5101, 0); // 8K CHR Banks
for (int i = 0; i < banks; i++) {
if (i == 0)
- write_prg_byte(0x5130, 0); // Set Upper 2 bits
+ write_prg_byte(0x5130, 0); // Set Upper 2 bits
else if (i == 8)
- write_prg_byte(0x5130, 1); // Set Upper 2 bits
+ write_prg_byte(0x5130, 1); // Set Upper 2 bits
else if (i == 16)
- write_prg_byte(0x5130, 2); // Set Upper 2 bits
+ write_prg_byte(0x5130, 2); // Set Upper 2 bits
else if (i == 24)
- write_prg_byte(0x5130, 3); // Set Upper 2 bits
+ write_prg_byte(0x5130, 3); // Set Upper 2 bits
write_prg_byte(0x5127, i);
- for (word address = 0x0; address < 0x2000; address += 512) { // ($0000-$1FFF)
+ for (word address = 0x0; address < 0x2000; address += 512) { // ($0000-$1FFF)
dumpCHR(address);
}
}
break;
case 9:
- case 10: // Mapper 9: 128K, Mapper 10: 64K/128K
+ case 10: // Mapper 9: 128K, Mapper 10: 64K/128K
if (mapper == 9)
banks = 32;
- else // Mapper 10
+ else // Mapper 10
banks = int_pow(2, chrsize);
- for (int i = 0; i < banks; i++) { // 64K/128K
+ for (int i = 0; i < banks; i++) { // 64K/128K
write_prg_byte(0xB000, i);
write_prg_byte(0xC000, i);
for (word address = 0x0; address < 0x1000; address += 512) {
@@ -3636,33 +3582,33 @@ void readCHR(boolean readrom) {
}
}
break;
-
+
case 11:
banks = int_pow(2, chrsize) / 2;
for (int i = 0; i < banks; i++) {
- write_prg_byte(0xFFB0+i, i << 4);
+ write_prg_byte(0xFFB0 + i, i << 4);
for (word address = 0x0; address < 0x2000; address += 512) {
dumpCHR(address);
}
}
break;
-
+
case 16:
- case 159: // 128K/256K
+ case 159: // 128K/256K
banks = int_pow(2, chrsize) * 4;
for (int i = 0; i < banks; i++) {
- write_prg_byte(0x6000, i); // Submapper 4
- write_prg_byte(0x8000, i); // Submapper 5
+ write_prg_byte(0x6000, i); // Submapper 4
+ write_prg_byte(0x8000, i); // Submapper 5
for (word address = 0x0; address < 0x400; address += 512) {
dumpCHR(address);
}
}
break;
- case 18: // 128K/256K
+ case 18: // 128K/256K
banks = int_pow(2, chrsize) * 4;
for (int i = 0; i < banks; i++) {
- write_prg_byte(0xA000, i & 0xF); // CHR Bank Lower 4 bits
+ write_prg_byte(0xA000, i & 0xF); // CHR Bank Lower 4 bits
write_prg_byte(0xA001, (i >> 4) & 0xF); // CHR Bank Upper 4 bits
for (word address = 0x0; address < 0x400; address += 512) {
dumpCHR(address);
@@ -3670,34 +3616,34 @@ void readCHR(boolean readrom) {
}
break;
- case 19: // 128K/256K
- for (int j = 0; j < 64; j++) { // Init Register
- write_ram_byte(0xE800, 0xC0); // CHR RAM High/Low Disable (ROM Enable)
+ case 19: // 128K/256K
+ for (int j = 0; j < 64; j++) { // Init Register
+ write_ram_byte(0xE800, 0xC0); // CHR RAM High/Low Disable (ROM Enable)
}
banks = int_pow(2, chrsize) * 4;
- write_ram_byte(0xE800, 0xC0); // CHR RAM High/Low Disable (ROM Enable)
+ write_ram_byte(0xE800, 0xC0); // CHR RAM High/Low Disable (ROM Enable)
for (int i = 0; i < banks; i += 8) {
- write_prg_byte(0x8000, i); // CHR Bank 0
- write_prg_byte(0x8800, i + 1); // CHR Bank 1
- write_prg_byte(0x9000, i + 2); // CHR Bank 2
- write_prg_byte(0x9800, i + 3); // CHR Bank 3
- write_prg_byte(0xA000, i + 4); // CHR Bank 4
- write_prg_byte(0xA800, i + 5); // CHR Bank 5
- write_prg_byte(0xB000, i + 6); // CHR Bank 6
- write_prg_byte(0xB800, i + 7); // CHR Bank 7
+ write_prg_byte(0x8000, i); // CHR Bank 0
+ write_prg_byte(0x8800, i + 1); // CHR Bank 1
+ write_prg_byte(0x9000, i + 2); // CHR Bank 2
+ write_prg_byte(0x9800, i + 3); // CHR Bank 3
+ write_prg_byte(0xA000, i + 4); // CHR Bank 4
+ write_prg_byte(0xA800, i + 5); // CHR Bank 5
+ write_prg_byte(0xB000, i + 6); // CHR Bank 6
+ write_prg_byte(0xB800, i + 7); // CHR Bank 7
for (word address = 0x0; address < 0x2000; address += 512) {
dumpCHR(address);
}
}
break;
- case 21: // 128K/256K
+ case 21: // 128K/256K
banks = int_pow(2, chrsize) * 4;
for (int i = 0; i < banks; i++) {
- write_prg_byte(0xB000, i & 0xF); // CHR Bank Lower 4 bits
- if (chrsize == 5) // Check CHR Size to determine VRC4a (128K) or VRC4c (256K)
+ write_prg_byte(0xB000, i & 0xF); // CHR Bank Lower 4 bits
+ if (chrsize == 5) // Check CHR Size to determine VRC4a (128K) or VRC4c (256K)
write_prg_byte(0xB002, (i >> 4) & 0xF); // CHR Bank Upper 4 bits VRC4a (Wai Wai World 2)
- else // banks == 256
+ else // banks == 256
write_prg_byte(0xB040, (i >> 4) & 0xF); // CHR Bank Upper 4 bits VRC4c (Ganbare Goemon Gaiden 2)
for (word address = 0x0; address < 0x400; address += 512) {
dumpCHR(address);
@@ -3705,10 +3651,10 @@ void readCHR(boolean readrom) {
}
break;
- case 22: // 128K
+ case 22: // 128K
banks = int_pow(2, chrsize) * 4;
for (int i = 0; i < banks; i++) {
- write_prg_byte(0xB000, (i << 1) & 0xF); // CHR Bank Lower 4 bits
+ write_prg_byte(0xB000, (i << 1) & 0xF); // CHR Bank Lower 4 bits
write_prg_byte(0xB002, (i >> 3) & 0xF); // CHR Bank Upper 4 bits
for (word address = 0x0; address < 0x400; address += 512) {
dumpCHR(address);
@@ -3716,18 +3662,18 @@ void readCHR(boolean readrom) {
}
break;
- case 23: // 128K
+ case 23: // 128K
// Detect VRC4e Carts - read PRG 0x1FFF6 (DATE)
// Boku Dracula-kun = 890810, Tiny Toon = 910809
// Crisis Force = 910701, Parodius Da! = 900916
write_prg_byte(0x8000, 15);
prgchk0 = read_prg_byte(0x9FF6);
- if (prgchk0 == 0x30) { // Check for "0" in middle of date
- vrc4e = true; // VRC4e Cart
+ if (prgchk0 == 0x30) { // Check for "0" in middle of date
+ vrc4e = true; // VRC4e Cart
}
banks = int_pow(2, chrsize) * 4;
for (int i = 0; i < banks; i++) {
- write_prg_byte(0xB000, i & 0xF); // CHR Bank Lower 4 bits
+ write_prg_byte(0xB000, i & 0xF); // CHR Bank Lower 4 bits
if (vrc4e == true)
write_prg_byte(0xB004, (i >> 4) & 0xF); // CHR Bank Upper 4 bits VRC4e
else
@@ -3738,29 +3684,29 @@ void readCHR(boolean readrom) {
}
break;
- case 24: // 128K
+ case 24: // 128K
banks = int_pow(2, chrsize) * 4;
- write_prg_byte(0xB003, 0); // PPU Banking Mode 0
+ write_prg_byte(0xB003, 0); // PPU Banking Mode 0
for (int i = 0; i < banks; i += 8) {
- write_prg_byte(0xD000, i); // CHR Bank 0
- write_prg_byte(0xD001, i + 1); // CHR Bank 1
- write_prg_byte(0xD002, i + 2); // CHR Bank 2
- write_prg_byte(0xD003, i + 3); // CHR Bank 3
- write_prg_byte(0xE000, i + 4); // CHR Bank 4 [WRITE NO RAM]
- write_prg_byte(0xE001, i + 5); // CHR Bank 5 [WRITE NO RAM]
- write_prg_byte(0xE002, i + 6); // CHR Bank 6 [WRITE NO RAM]
- write_prg_byte(0xE003, i + 7); // CHR Bank 7 [WRITE NO RAM]
- for (word address = 0x0; address < 0x2000; address += 512) { // 1K Banks
+ write_prg_byte(0xD000, i); // CHR Bank 0
+ write_prg_byte(0xD001, i + 1); // CHR Bank 1
+ write_prg_byte(0xD002, i + 2); // CHR Bank 2
+ write_prg_byte(0xD003, i + 3); // CHR Bank 3
+ write_prg_byte(0xE000, i + 4); // CHR Bank 4 [WRITE NO RAM]
+ write_prg_byte(0xE001, i + 5); // CHR Bank 5 [WRITE NO RAM]
+ write_prg_byte(0xE002, i + 6); // CHR Bank 6 [WRITE NO RAM]
+ write_prg_byte(0xE003, i + 7); // CHR Bank 7 [WRITE NO RAM]
+ for (word address = 0x0; address < 0x2000; address += 512) { // 1K Banks
dumpCHR(address);
}
}
break;
- case 25: // 128K/256K
+ case 25: // 128K/256K
banks = int_pow(2, chrsize) * 4;
for (int i = 0; i < banks; i++) {
- write_prg_byte(0xB000, i & 0xF); // CHR Bank Lower 4 bits
- if ((ramsize > 0) || (banks == 128)) // VRC2c (Ganbare Goemon Gaiden)/VRC4b (Bio Miracle/Gradius 2/Racer Mini)
+ write_prg_byte(0xB000, i & 0xF); // CHR Bank Lower 4 bits
+ if ((ramsize > 0) || (banks == 128)) // VRC2c (Ganbare Goemon Gaiden)/VRC4b (Bio Miracle/Gradius 2/Racer Mini)
write_prg_byte(0xB002, (i >> 4) & 0xF); // CHR Bank Upper 4 bits VRC2c/VRC4b
else
write_prg_byte(0xB008, (i >> 4) & 0xF); // CHR Bank Upper 4 bits VRC4d (Teenage Mutant Ninja Turtles)
@@ -3770,44 +3716,44 @@ void readCHR(boolean readrom) {
}
break;
- case 26: // 128K/256K
+ case 26: // 128K/256K
banks = int_pow(2, chrsize) * 4;
write_prg_byte(0xB003, 0x00);
for (int i = 0; i < banks; i += 4) {
- write_prg_byte(0xD000, i + 0); // CHR Bank 0
- write_prg_byte(0xD002, i + 1); // CHR Bank 1
- write_prg_byte(0xD001, i + 2); // CHR Bank 2
- write_prg_byte(0xD003, i + 3); // CHR Bank 3
- for (word address = 0x0; address < 0x1000; address += 512) { // 1K Banks
+ write_prg_byte(0xD000, i + 0); // CHR Bank 0
+ write_prg_byte(0xD002, i + 1); // CHR Bank 1
+ write_prg_byte(0xD001, i + 2); // CHR Bank 2
+ write_prg_byte(0xD003, i + 3); // CHR Bank 3
+ for (word address = 0x0; address < 0x1000; address += 512) { // 1K Banks
dumpCHR(address);
}
}
break;
- case 32: // 128K
- case 65: // 128K/256K
+ case 32: // 128K
+ case 65: // 128K/256K
banks = int_pow(2, chrsize) * 4;
for (int i = 0; i < banks; i += 8) {
- write_prg_byte(0xB000, i); // CHR Bank 0
- write_prg_byte(0xB001, i + 1); // CHR Bank 1
- write_prg_byte(0xB002, i + 2); // CHR Bank 2
- write_prg_byte(0xB003, i + 3); // CHR Bank 3
- write_prg_byte(0xB004, i + 4); // CHR Bank 4
- write_prg_byte(0xB005, i + 5); // CHR Bank 5
- write_prg_byte(0xB006, i + 6); // CHR Bank 6
- write_prg_byte(0xB007, i + 7); // CHR Bank 7
+ write_prg_byte(0xB000, i); // CHR Bank 0
+ write_prg_byte(0xB001, i + 1); // CHR Bank 1
+ write_prg_byte(0xB002, i + 2); // CHR Bank 2
+ write_prg_byte(0xB003, i + 3); // CHR Bank 3
+ write_prg_byte(0xB004, i + 4); // CHR Bank 4
+ write_prg_byte(0xB005, i + 5); // CHR Bank 5
+ write_prg_byte(0xB006, i + 6); // CHR Bank 6
+ write_prg_byte(0xB007, i + 7); // CHR Bank 7
for (word address = 0x0; address < 0x2000; address += 512) {
dumpCHR(address);
}
}
break;
- case 33: // 128K/256K
- case 48: // 256K
+ case 33: // 128K/256K
+ case 48: // 256K
banks = int_pow(2, chrsize) * 2;
- for (int i = 0; i < banks; i += 2) { // 2K Banks
- write_prg_byte(0x8002, i); // CHR Bank 0
- write_prg_byte(0x8003, i + 1); // CHR Bank 1
+ for (int i = 0; i < banks; i += 2) { // 2K Banks
+ write_prg_byte(0x8002, i); // CHR Bank 0
+ write_prg_byte(0x8003, i + 1); // CHR Bank 1
for (word address = 0x0; address < 0x1000; address += 512) {
dumpCHR(address);
}
@@ -3816,15 +3762,15 @@ void readCHR(boolean readrom) {
case 37:
banks = int_pow(2, chrsize) * 4;
- write_prg_byte(0xA001, 0x80); // Block Register - PRG RAM Chip Enable, Writable
- for (int i = 0; i < banks; i += 4) { // 256K
+ write_prg_byte(0xA001, 0x80); // Block Register - PRG RAM Chip Enable, Writable
+ for (int i = 0; i < banks; i += 4) { // 256K
if (i == 0)
- write_prg_byte(0x6000, 0); // Switch to Lower Block ($00000-$1FFFF)
+ write_prg_byte(0x6000, 0); // Switch to Lower Block ($00000-$1FFFF)
else if (i == 128)
- write_prg_byte(0x6000, 4); // Switch to Upper Block ($20000-$3FFFF)
- write_prg_byte(0x8000, 0); // CHR Bank 0 ($0000-$07FF)
+ write_prg_byte(0x6000, 4); // Switch to Upper Block ($20000-$3FFFF)
+ write_prg_byte(0x8000, 0); // CHR Bank 0 ($0000-$07FF)
write_prg_byte(0x8001, i);
- write_prg_byte(0x8000, 1); // CHR Bank 1 ($0800-$0FFF)
+ write_prg_byte(0x8000, 1); // CHR Bank 1 ($0800-$0FFF)
write_prg_byte(0x8001, i + 2);
for (word address = 0x0; address < 0x1000; address += 512) {
dumpCHR(address);
@@ -3832,128 +3778,128 @@ void readCHR(boolean readrom) {
}
break;
- case 45: // 128K/256K/512K/1024K
+ case 45: // 128K/256K/512K/1024K
banks = int_pow(2, chrsize) * 4;
- write_prg_byte(0xA001, 0x80); // Unlock Write Protection - not used by some carts
+ write_prg_byte(0xA001, 0x80); // Unlock Write Protection - not used by some carts
for (int i = 0; i < banks; i++) {
// set outer bank registers
- write_prg_byte(0x6000, 0x00); // CHR-OR
- write_prg_byte(0x6000, 0x00); // PRG-OR
- write_prg_byte(0x6000, (((i / 256) << 4) | 0x0F)); // CHR-AND,CHR-OR/PRG-OR
- write_prg_byte(0x6000, 0x80); // PRG-AND
+ write_prg_byte(0x6000, 0x00); // CHR-OR
+ write_prg_byte(0x6000, 0x00); // PRG-OR
+ write_prg_byte(0x6000, (((i / 256) << 4) | 0x0F)); // CHR-AND,CHR-OR/PRG-OR
+ write_prg_byte(0x6000, 0x80); // PRG-AND
// set inner bank registers
- write_prg_byte(0x8000, 0x2); // CHR Bank 2 ($1000-$13FF)
+ write_prg_byte(0x8000, 0x2); // CHR Bank 2 ($1000-$13FF)
write_prg_byte(0x8001, i);
for (word address = 0x1000; address < 0x1200; address += 512) {
- dumpCHR_M2(address); // Read CHR with M2 Pulse
+ dumpCHR_M2(address); // Read CHR with M2 Pulse
}
// set outer bank registers
- write_prg_byte(0x6000, 0x00); // CHR-OR
- write_prg_byte(0x6000, 0x00); // PRG-OR
- write_prg_byte(0x6000, (((i / 256) << 4) | 0x0F)); // CHR-AND,CHR-OR/PRG-OR
- write_prg_byte(0x6000, 0x80); // PRG-AND
+ write_prg_byte(0x6000, 0x00); // CHR-OR
+ write_prg_byte(0x6000, 0x00); // PRG-OR
+ write_prg_byte(0x6000, (((i / 256) << 4) | 0x0F)); // CHR-AND,CHR-OR/PRG-OR
+ write_prg_byte(0x6000, 0x80); // PRG-AND
// set inner bank registers
- write_prg_byte(0x8000, 0x2); // CHR Bank 2 ($1000-$13FF)
+ write_prg_byte(0x8000, 0x2); // CHR Bank 2 ($1000-$13FF)
write_prg_byte(0x8001, i);
for (word address = 0x1200; address < 0x1400; address += 512) {
- dumpCHR_M2(address); // Read CHR with M2 Pulse
+ dumpCHR_M2(address); // Read CHR with M2 Pulse
}
}
break;
- case 67: // 128K
+ case 67: // 128K
banks = int_pow(2, chrsize) * 2;
- for (int i = 0; i < banks; i += 4) { // 2K Banks
- write_prg_byte(0x8800, i); // CHR Bank 0
- write_prg_byte(0x9800, i + 1); // CHR Bank 1
- write_prg_byte(0xA800, i + 2); // CHR Bank 2
- write_prg_byte(0xB800, i + 3); // CHR Bank 3
+ for (int i = 0; i < banks; i += 4) { // 2K Banks
+ write_prg_byte(0x8800, i); // CHR Bank 0
+ write_prg_byte(0x9800, i + 1); // CHR Bank 1
+ write_prg_byte(0xA800, i + 2); // CHR Bank 2
+ write_prg_byte(0xB800, i + 3); // CHR Bank 3
for (word address = 0x0; address < 0x2000; address += 512) {
dumpCHR(address);
}
}
break;
- case 68: // 128K/256K
+ case 68: // 128K/256K
banks = int_pow(2, chrsize) * 2;
- for (int i = 0; i < banks; i += 4) { // 2K Banks
- write_prg_byte(0x8000, i); // CHR Bank 0
- write_prg_byte(0x9000, i + 1); // CHR Bank 1
- write_prg_byte(0xA000, i + 2); // CHR Bank 2
- write_prg_byte(0xB000, i + 3); // CHR Bank 3
+ for (int i = 0; i < banks; i += 4) { // 2K Banks
+ write_prg_byte(0x8000, i); // CHR Bank 0
+ write_prg_byte(0x9000, i + 1); // CHR Bank 1
+ write_prg_byte(0xA000, i + 2); // CHR Bank 2
+ write_prg_byte(0xB000, i + 3); // CHR Bank 3
for (word address = 0x0; address < 0x2000; address += 512) {
dumpCHR(address);
}
}
break;
- case 69: // 128K/256K
+ case 69: // 128K/256K
banks = int_pow(2, chrsize) * 4;
for (int i = 0; i < banks; i++) {
- write_prg_byte(0x8000, 0); // Command Register - CHR Bank 0
- write_prg_byte(0xA000, i); // Parameter Register - ($0000-$03FF)
- for (word address = 0x0; address < 0x400; address += 512) { // 1K Banks
+ write_prg_byte(0x8000, 0); // Command Register - CHR Bank 0
+ write_prg_byte(0xA000, i); // Parameter Register - ($0000-$03FF)
+ for (word address = 0x0; address < 0x400; address += 512) { // 1K Banks
dumpCHR(address);
}
}
break;
- case 72: // 128K
+ case 72: // 128K
banks = int_pow(2, chrsize) / 2;
- write_prg_byte(0x8000, 0); // Reset Register
- for (int i = 0; i < banks; i++) { // 8K Banks
- write_prg_byte(0x8000, i | 0x40); // CHR Command + Bank
- write_prg_byte(0x8000, i); // CHR Bank
+ write_prg_byte(0x8000, 0); // Reset Register
+ for (int i = 0; i < banks; i++) { // 8K Banks
+ write_prg_byte(0x8000, i | 0x40); // CHR Command + Bank
+ write_prg_byte(0x8000, i); // CHR Bank
for (word address = 0x0; address < 0x2000; address += 512) {
dumpCHR(address);
}
}
break;
- case 75: // 128K
+ case 75: // 128K
banks = int_pow(2, chrsize);
- for (int i = 0; i < banks; i++) { // 4K Banks
- write_reg_byte(0xE000, i); // CHR Bank Low Bits [WRITE RAM SAFE]
- write_prg_byte(0x9000, (i & 0x10) >> 3); // High Bit
+ for (int i = 0; i < banks; i++) { // 4K Banks
+ write_reg_byte(0xE000, i); // CHR Bank Low Bits [WRITE RAM SAFE]
+ write_prg_byte(0x9000, (i & 0x10) >> 3); // High Bit
for (word address = 0x0; address < 0x1000; address += 512) {
dumpCHR(address);
}
}
break;
- case 76: // 128K
+ case 76: // 128K
banks = int_pow(2, chrsize) * 2;
- for (int i = 0; i < banks; i += 2) { // 2K Banks
- write_prg_byte(0x8000, 2); // CHR Command ($0000-$07FF) 2K Bank
- write_prg_byte(0x8001, i); // CHR Bank
- write_prg_byte(0x8000, 3); // CHR Command ($0800-$0FFF) 2K Bank
- write_prg_byte(0x8001, i + 1); // CHR Bank
+ for (int i = 0; i < banks; i += 2) { // 2K Banks
+ write_prg_byte(0x8000, 2); // CHR Command ($0000-$07FF) 2K Bank
+ write_prg_byte(0x8001, i); // CHR Bank
+ write_prg_byte(0x8000, 3); // CHR Command ($0800-$0FFF) 2K Bank
+ write_prg_byte(0x8001, i + 1); // CHR Bank
for (word address = 0x0000; address < 0x1000; address += 512) {
dumpCHR(address);
}
}
break;
- case 77: // 32K
+ case 77: // 32K
banks = int_pow(2, chrsize) * 2;
- for (int i = 0; i < banks; i++) { // 2K Banks
- write_prg_byte(0x8000, i << 4); // CHR Bank 0
+ for (int i = 0; i < banks; i++) { // 2K Banks
+ write_prg_byte(0x8000, i << 4); // CHR Bank 0
for (word address = 0x0; address < 0x800; address += 512) {
dumpCHR(address);
}
}
break;
- case 78: // 128K
+ case 78: // 128K
banks = int_pow(2, chrsize) / 2;
- for (int i = 0; i < banks; i++) { // 8K Banks
- write_prg_byte(0x8000, i << 4); // CHR Bank 0
- for (word address = 0x0; address < 0x2000; address += 512) { // 8K Banks ($0000-$1FFF)
+ for (int i = 0; i < banks; i++) { // 8K Banks
+ write_prg_byte(0x8000, i << 4); // CHR Bank 0
+ for (word address = 0x0; address < 0x2000; address += 512) { // 8K Banks ($0000-$1FFF)
dumpCHR(address);
}
}
break;
-
+
case 79:
case 146:
banks = int_pow(2, chrsize) / 2;
@@ -3963,14 +3909,14 @@ void readCHR(boolean readrom) {
dumpCHR(address);
}
}
- break;
+ break;
- case 80: // 128K/256K
- case 82: // 128K/256K
- case 207: // 128K [CART SOMETIMES NEEDS POWERCYCLE]
+ case 80: // 128K/256K
+ case 82: // 128K/256K
+ case 207: // 128K [CART SOMETIMES NEEDS POWERCYCLE]
banks = int_pow(2, chrsize) * 4;
for (int i = 0; i < banks; i += 4) {
- write_prg_byte(0x7EF2, i); // CHR Bank 2 [REGISTERS 0x7EF0/0x7EF1 WON'T WORK]
+ write_prg_byte(0x7EF2, i); // CHR Bank 2 [REGISTERS 0x7EF0/0x7EF1 WON'T WORK]
write_prg_byte(0x7EF3, i + 1); // CHR Bank 3
write_prg_byte(0x7EF4, i + 2); // CHR Bank 4
write_prg_byte(0x7EF5, i + 3); // CHR Bank 5
@@ -3980,26 +3926,26 @@ void readCHR(boolean readrom) {
}
break;
- case 85: // 128K
+ case 85: // 128K
banks = int_pow(2, chrsize) * 4;
for (int i = 0; i < banks; i += 8) {
- write_prg_byte(0xA000, i); // CHR Bank 0
- write_prg_byte(0xA008, i + 1); // CHR Bank 1
- write_prg_byte(0xB000, i + 2); // CHR Bank 2
- write_prg_byte(0xB008, i + 3); // CHR Bank 3
- write_prg_byte(0xC000, i + 4); // CHR Bank 4
- write_prg_byte(0xC008, i + 5); // CHR Bank 5
- write_prg_byte(0xD000, i + 6); // CHR Bank 6
- write_prg_byte(0xD008, i + 7); // CHR Bank 7
+ write_prg_byte(0xA000, i); // CHR Bank 0
+ write_prg_byte(0xA008, i + 1); // CHR Bank 1
+ write_prg_byte(0xB000, i + 2); // CHR Bank 2
+ write_prg_byte(0xB008, i + 3); // CHR Bank 3
+ write_prg_byte(0xC000, i + 4); // CHR Bank 4
+ write_prg_byte(0xC008, i + 5); // CHR Bank 5
+ write_prg_byte(0xD000, i + 6); // CHR Bank 6
+ write_prg_byte(0xD008, i + 7); // CHR Bank 7
for (word address = 0x0; address < 0x2000; address += 512) {
dumpCHR(address);
}
}
break;
- case 86: // 64K
+ case 86: // 64K
banks = int_pow(2, chrsize) / 2;
- for (int i = 0; i < banks; i++) { // 8K Banks
+ for (int i = 0; i < banks; i++) { // 8K Banks
if (i < 4)
write_prg_byte(0x6000, i & 0x3);
else
@@ -4010,9 +3956,9 @@ void readCHR(boolean readrom) {
}
break;
- case 87: // 16K/32K
+ case 87: // 16K/32K
banks = int_pow(2, chrsize) / 2;
- for (int i = 0; i < banks; i++) { // 16K/32K
+ for (int i = 0; i < banks; i++) { // 16K/32K
write_prg_byte(0x6000, (((i & 0x1) << 1) | ((i & 0x2) >> 1)));
for (word address = 0x0; address < 0x2000; address += 512) {
dumpCHR(address);
@@ -4020,24 +3966,23 @@ void readCHR(boolean readrom) {
}
break;
- case 88: // 128K
- case 95: // 32K
- case 154: // 128K
- case 206: // 16K/32K/64K
+ case 88: // 128K
+ case 95: // 32K
+ case 154: // 128K
+ case 206: // 16K/32K/64K
banks = int_pow(2, chrsize) * 4;
- for (int i = 0; i < banks; i += 2) { // 1K Banks
+ for (int i = 0; i < banks; i += 2) { // 1K Banks
if (i < 64) {
- write_prg_byte(0x8000, 0); // CHR Command ($0000-$07FF) 2K Bank
- write_prg_byte(0x8001, i & 0x3F); // CHR Bank
+ write_prg_byte(0x8000, 0); // CHR Command ($0000-$07FF) 2K Bank
+ write_prg_byte(0x8001, i & 0x3F); // CHR Bank
for (word address = 0x0; address < 0x800; address += 512) {
dumpCHR(address);
}
- }
- else {
- write_prg_byte(0x8000, 2); // CHR Command ($1000-$13FF) 1K Bank
- write_prg_byte(0x8001, i); // CHR Bank
- write_prg_byte(0x8000, 3); // CHR Command ($1400-$17FF) 1K Bank
- write_prg_byte(0x8001, i + 1); // CHR Bank
+ } else {
+ write_prg_byte(0x8000, 2); // CHR Command ($1000-$13FF) 1K Bank
+ write_prg_byte(0x8001, i); // CHR Bank
+ write_prg_byte(0x8000, 3); // CHR Command ($1400-$17FF) 1K Bank
+ write_prg_byte(0x8001, i + 1); // CHR Bank
for (word address = 0x1000; address < 0x1800; address += 512) {
dumpCHR(address);
}
@@ -4045,9 +3990,9 @@ void readCHR(boolean readrom) {
}
break;
- case 89: // 128K
+ case 89: // 128K
banks = int_pow(2, chrsize) / 2;
- for (int i = 0; i < banks; i++) { // 8K Banks
+ for (int i = 0; i < banks; i++) { // 8K Banks
if (i < 8)
write_prg_byte(0x8000, i & 0x7);
else
@@ -4058,21 +4003,21 @@ void readCHR(boolean readrom) {
}
break;
- case 92: // 128K
+ case 92: // 128K
banks = int_pow(2, chrsize) / 2;
- write_prg_byte(0x8000, 0); // Reset Register
- for (int i = 0; i < banks; i++) { // 8K Banks
- write_prg_byte(0x8000, i | 0x40); // CHR Command + Bank
- write_prg_byte(0x8000, i); // CHR Bank
+ write_prg_byte(0x8000, 0); // Reset Register
+ for (int i = 0; i < banks; i++) { // 8K Banks
+ write_prg_byte(0x8000, i | 0x40); // CHR Command + Bank
+ write_prg_byte(0x8000, i); // CHR Bank
for (word address = 0x0; address < 0x2000; address += 512) {
dumpCHR(address);
}
}
break;
- case 140: // 32K/128K
+ case 140: // 32K/128K
banks = int_pow(2, chrsize) / 2;
- for (int i = 0; i < banks; i++) { // 8K Banks
+ for (int i = 0; i < banks; i++) { // 8K Banks
write_prg_byte(0x6000, i);
for (word address = 0x0; address < 0x2000; address += 512) {
dumpCHR(address);
@@ -4080,18 +4025,18 @@ void readCHR(boolean readrom) {
}
break;
- case 184: // 16K/32K
+ case 184: // 16K/32K
banks = int_pow(2, chrsize);
- for (int i = 0; i < banks; i++) { // 4K Banks
- write_prg_byte(0x6000, i); // CHR LOW (Bits 0-2) ($0000-$0FFF)
- for (word address = 0x0; address < 0x1000; address += 512) { // 4K Banks ($0000-$0FFF)
+ for (int i = 0; i < banks; i++) { // 4K Banks
+ write_prg_byte(0x6000, i); // CHR LOW (Bits 0-2) ($0000-$0FFF)
+ for (word address = 0x0; address < 0x1000; address += 512) { // 4K Banks ($0000-$0FFF)
dumpCHR(address);
}
}
break;
- case 185: // 8K [READ 32K TO OVERRIDE LOCKOUT]
- for (int i = 0; i < 4; i++) { // Read 32K to locate valid 8K
+ case 185: // 8K [READ 32K TO OVERRIDE LOCKOUT]
+ for (int i = 0; i < 4; i++) { // Read 32K to locate valid 8K
write_prg_byte(0x8000, i);
byte chrcheck = read_chr_byte(0);
for (word address = 0x0; address < 0x2000; address += 512) {
@@ -4104,18 +4049,18 @@ void readCHR(boolean readrom) {
}
break;
- case 210: // 128K/256K
+ case 210: // 128K/256K
banks = int_pow(2, chrsize) * 4;
- write_prg_byte(0xE800, 0xC0); // CHR RAM DISABLE (Bit 6 and 7) [WRITE NO RAM]
+ write_prg_byte(0xE800, 0xC0); // CHR RAM DISABLE (Bit 6 and 7) [WRITE NO RAM]
for (int i = 0; i < banks; i += 8) {
- write_prg_byte(0x8000, i); // CHR Bank 0
- write_prg_byte(0x8800, i + 1); // CHR Bank 1
- write_prg_byte(0x9000, i + 2); // CHR Bank 2
- write_prg_byte(0x9800, i + 3); // CHR Bank 3
- write_prg_byte(0xA000, i + 4); // CHR Bank 4
- write_prg_byte(0xA800, i + 5); // CHR Bank 5
- write_prg_byte(0xB000, i + 6); // CHR Bank 6
- write_prg_byte(0xB800, i + 7); // CHR Bank 7
+ write_prg_byte(0x8000, i); // CHR Bank 0
+ write_prg_byte(0x8800, i + 1); // CHR Bank 1
+ write_prg_byte(0x9000, i + 2); // CHR Bank 2
+ write_prg_byte(0x9800, i + 3); // CHR Bank 3
+ write_prg_byte(0xA000, i + 4); // CHR Bank 4
+ write_prg_byte(0xA800, i + 5); // CHR Bank 5
+ write_prg_byte(0xB000, i + 6); // CHR Bank 6
+ write_prg_byte(0xB800, i + 7); // CHR Bank 7
for (word address = 0x0; address < 0x2000; address += 512) {
dumpCHR(address);
}
@@ -4129,7 +4074,7 @@ void readCHR(boolean readrom) {
println_Msg(F("CHR FILE DUMPED!"));
println_Msg(F(""));
display_Update();
-#ifndef no-intro
+#ifndef nointro
calcCRC(fileName, chr * 1024, &chr_crc32, 0);
#endif
}
@@ -4156,86 +4101,83 @@ void readRAM() {
println_Msg(F("RAM SIZE 0K"));
display_Update();
- }
- else {
+ } else {
CreateRAMFileInSD();
word base = 0x6000;
if (myFile) {
switch (mapper) {
- case 0: // 2K/4K
- for (word address = 0x0; address < (0x800 * ramsize); address += 512) { // 2K/4K
- dumpPRG(base, address); // SWITCH MUST BE IN OFF POSITION
+ case 0: // 2K/4K
+ for (word address = 0x0; address < (0x800 * ramsize); address += 512) { // 2K/4K
+ dumpPRG(base, address); // SWITCH MUST BE IN OFF POSITION
}
break;
case 1:
- case 155: // 8K/16K/32K
- banks = int_pow(2, ramsize) / 2; // banks = 1,2,4
- for (int i = 0; i < banks; i++) { // 8K Banks ($6000-$7FFF)
- write_prg_byte(0x8000, 0x80); // Clear Register
+ case 155: // 8K/16K/32K
+ banks = int_pow(2, ramsize) / 2; // banks = 1,2,4
+ for (int i = 0; i < banks; i++) { // 8K Banks ($6000-$7FFF)
+ write_prg_byte(0x8000, 0x80); // Clear Register
write_mmc1_byte(0x8000, 1 << 3);
write_mmc1_byte(0xE000, 0);
- if (banks == 4) // 32K
+ if (banks == 4) // 32K
write_mmc1_byte(0xA000, i << 2);
else
write_mmc1_byte(0xA000, i << 3);
- for (word address = 0x0; address < 0x2000; address += 512) { // 8K
+ for (word address = 0x0; address < 0x2000; address += 512) { // 8K
dumpPRG(base, address);
}
}
break;
- case 4: // 1K/8K (MMC6/MMC3)
- if (mmc6) { // MMC6 1K
- write_prg_byte(0x8000, 0x20); // PRG RAM ENABLE
- write_prg_byte(0xA001, 0x20); // PRG RAM PROTECT - Enable reading RAM at $7000-$71FF
- for (word address = 0x1000; address < 0x1200; address += 512) { // 512B
+ case 4: // 1K/8K (MMC6/MMC3)
+ if (mmc6) { // MMC6 1K
+ write_prg_byte(0x8000, 0x20); // PRG RAM ENABLE
+ write_prg_byte(0xA001, 0x20); // PRG RAM PROTECT - Enable reading RAM at $7000-$71FF
+ for (word address = 0x1000; address < 0x1200; address += 512) { // 512B
dumpMMC5RAM(base, address);
}
- write_prg_byte(0x8000, 0x20); // PRG RAM ENABLE
- write_prg_byte(0xA001, 0x80); // PRG RAM PROTECT - Enable reading RAM at $7200-$73FF
- for (word address = 0x1200; address < 0x1400; address += 512) { // 512B
+ write_prg_byte(0x8000, 0x20); // PRG RAM ENABLE
+ write_prg_byte(0xA001, 0x80); // PRG RAM PROTECT - Enable reading RAM at $7200-$73FF
+ for (word address = 0x1200; address < 0x1400; address += 512) { // 512B
dumpMMC5RAM(base, address);
}
- write_prg_byte(0x8000, 6); // PRG RAM DISABLE
- }
- else { // MMC3 8K
- write_prg_byte(0xA001, 0xC0); // PRG RAM CHIP ENABLE - Chip Enable, Write Protect
- for (word address = 0; address < 0x2000; address += 512) { // 8K
+ write_prg_byte(0x8000, 6); // PRG RAM DISABLE
+ } else { // MMC3 8K
+ write_prg_byte(0xA001, 0xC0); // PRG RAM CHIP ENABLE - Chip Enable, Write Protect
+ for (word address = 0; address < 0x2000; address += 512) { // 8K
dumpPRG(base, address);
}
}
break;
- case 5: // 8K/16K/32K
- write_prg_byte(0x5100, 3); // 8K PRG Banks
- banks = int_pow(2, ramsize) / 2; // banks = 1,2,4
- if (banks == 2) { // 16K - Split SRAM Chips 8K/8K
- for (int i = 0; i < (banks / 2); i++) { // Chip 1
+ case 5: // 8K/16K/32K
+ write_prg_byte(0x5100, 3); // 8K PRG Banks
+ banks = int_pow(2, ramsize) / 2; // banks = 1,2,4
+ if (banks == 2) { // 16K - Split SRAM Chips 8K/8K
+ for (int i = 0; i < (banks / 2); i++) { // Chip 1
write_prg_byte(0x5113, i);
- for (word address = 0; address < 0x2000; address += 512) { // 8K
+ for (word address = 0; address < 0x2000; address += 512) { // 8K
dumpMMC5RAM(base, address);
}
}
- for (int j = 4; j < (banks / 2) + 4; j++) { // Chip 2
+ for (int j = 4; j < (banks / 2) + 4; j++) { // Chip 2
write_prg_byte(0x5113, j);
- for (word address = 0; address < 0x2000; address += 512) { // 8K
+ for (word address = 0; address < 0x2000; address += 512) { // 8K
dumpMMC5RAM(base, address);
}
}
- }
- else { // 8K/32K Single SRAM Chip
- for (int i = 0; i < banks; i++) { // banks = 1 or 4
+ } else { // 8K/32K Single SRAM Chip
+ for (int i = 0; i < banks; i++) { // banks = 1 or 4
write_prg_byte(0x5113, i);
- for (word address = 0; address < 0x2000; address += 512) { // 8K
+ for (word address = 0; address < 0x2000; address += 512) { // 8K
dumpMMC5RAM(base, address);
}
}
}
break;
- case 16: // 256-byte EEPROM 24C02
- case 159: // 128-byte EEPROM 24C01 [Little Endian]
+ case 16: // 256-byte EEPROM 24C02
+ case 159: // 128-byte EEPROM 24C01 [Little Endian]
if (mapper == 159)
eepsize = 128;
else
@@ -4248,73 +4190,70 @@ void readRAM() {
break;
case 19:
- if (ramsize == 2) { // PRG RAM 128B
+ if (ramsize == 2) { // PRG RAM 128B
for (int x = 0; x < 128; x++) {
- write_ram_byte(0xF800, x); // PRG RAM ENABLE
- sdBuffer[x] = read_prg_byte(0x4800); // DATA PORT
+ write_ram_byte(0xF800, x); // PRG RAM ENABLE
+ sdBuffer[x] = read_prg_byte(0x4800); // DATA PORT
}
myFile.write(sdBuffer, 128);
- }
- else { // SRAM 8K
- for (int i = 0; i < 64; i++) { // Init Register
+ } else { // SRAM 8K
+ for (int i = 0; i < 64; i++) { // Init Register
write_ram_byte(0xE000, 0);
}
- for (word address = 0; address < 0x2000; address += 512) { // 8K
+ for (word address = 0; address < 0x2000; address += 512) { // 8K
dumpPRG(base, address);
}
}
break;
- case 80: // 1K
- write_prg_byte(0x7EF8, 0xA3); // PRG RAM ENABLE 0
- write_prg_byte(0x7EF9, 0xA3); // PRG RAM ENABLE 1
+ case 80: // 1K
+ write_prg_byte(0x7EF8, 0xA3); // PRG RAM ENABLE 0
+ write_prg_byte(0x7EF9, 0xA3); // PRG RAM ENABLE 1
for (int x = 0; x < 128; x++) { // PRG RAM 1K ($7F00-$7FFF) MIRRORED ONCE
sdBuffer[x] = read_prg_byte(0x7F00 + x);
}
myFile.write(sdBuffer, 128);
- write_prg_byte(0x7EF8, 0xFF); // PRG RAM DISABLE 0
- write_prg_byte(0x7EF9, 0xFF); // PRG RAM DISABLE 1
+ write_prg_byte(0x7EF8, 0xFF); // PRG RAM DISABLE 0
+ write_prg_byte(0x7EF9, 0xFF); // PRG RAM DISABLE 1
break;
- case 82: // 5K
- write_prg_byte(0x7EF7, 0xCA); // PRG RAM ENABLE 0 ($6000-$67FF)
- write_prg_byte(0x7EF8, 0x69); // PRG RAM ENABLE 1 ($6800-$6FFF)
- write_prg_byte(0x7EF9, 0x84); // PRG RAM ENABLE 2 ($7000-$73FF)
- for (word address = 0x0; address < 0x1400; address += 512) { // PRG RAM 5K ($6000-$73FF)
+ case 82: // 5K
+ write_prg_byte(0x7EF7, 0xCA); // PRG RAM ENABLE 0 ($6000-$67FF)
+ write_prg_byte(0x7EF8, 0x69); // PRG RAM ENABLE 1 ($6800-$6FFF)
+ write_prg_byte(0x7EF9, 0x84); // PRG RAM ENABLE 2 ($7000-$73FF)
+ for (word address = 0x0; address < 0x1400; address += 512) { // PRG RAM 5K ($6000-$73FF)
dumpMMC5RAM(base, address);
}
- write_prg_byte(0x7EF7, 0xFF); // PRG RAM DISABLE 0 ($6000-$67FF)
- write_prg_byte(0x7EF8, 0xFF); // PRG RAM DISABLE 1 ($6800-$6FFF)
- write_prg_byte(0x7EF9, 0xFF); // PRG RAM DISABLE 2 ($7000-$73FF)
+ write_prg_byte(0x7EF7, 0xFF); // PRG RAM DISABLE 0 ($6000-$67FF)
+ write_prg_byte(0x7EF8, 0xFF); // PRG RAM DISABLE 1 ($6800-$6FFF)
+ write_prg_byte(0x7EF9, 0xFF); // PRG RAM DISABLE 2 ($7000-$73FF)
break;
default:
- if (mapper == 118) // 8K
- write_prg_byte(0xA001, 0xC0); // PRG RAM CHIP ENABLE - Chip Enable, Write Protect
+ if (mapper == 118) // 8K
+ write_prg_byte(0xA001, 0xC0); // PRG RAM CHIP ENABLE - Chip Enable, Write Protect
else if (mapper == 19) {
- for (int i = 0; i < 64; i++) { // Init Register
+ for (int i = 0; i < 64; i++) { // Init Register
write_ram_byte(0xE000, 0);
}
- }
- else if ((mapper == 21) || (mapper == 25)) // 8K
+ } else if ((mapper == 21) || (mapper == 25)) // 8K
write_prg_byte(0x8000, 0);
- else if (mapper == 26) // 8K
- write_prg_byte(0xB003, 0x80); // PRG RAM ENABLE
- else if (mapper == 68) // 8K
- write_reg_byte(0xF000, 0x10); // PRG RAM ENABLE [WRITE RAM SAFE]
- else if (mapper == 69) { // 8K
- write_prg_byte(0x8000, 8); // Command Register - PRG Bank 0
- write_prg_byte(0xA000, 0xC0); // Parameter Register - PRG RAM Enabled, PRG RAM, Bank 0 to $6000-$7FFF
- }
- else if (mapper == 85) // 8K
- write_ram_byte(0xE000, 0x80); // PRG RAM ENABLE
- else if (mapper == 153) // 8K
- write_prg_byte(0x800D, 0x20); // PRG RAM Chip Enable
- for (word address = 0; address < 0x2000; address += 512) { // 8K
+ else if (mapper == 26) // 8K
+ write_prg_byte(0xB003, 0x80); // PRG RAM ENABLE
+ else if (mapper == 68) // 8K
+ write_reg_byte(0xF000, 0x10); // PRG RAM ENABLE [WRITE RAM SAFE]
+ else if (mapper == 69) { // 8K
+ write_prg_byte(0x8000, 8); // Command Register - PRG Bank 0
+ write_prg_byte(0xA000, 0xC0); // Parameter Register - PRG RAM Enabled, PRG RAM, Bank 0 to $6000-$7FFF
+ } else if (mapper == 85) // 8K
+ write_ram_byte(0xE000, 0x80); // PRG RAM ENABLE
+ else if (mapper == 153) // 8K
+ write_prg_byte(0x800D, 0x20); // PRG RAM Chip Enable
+ for (word address = 0; address < 0x2000; address += 512) { // 8K
dumpPRG(base, address);
}
- if (mapper == 85) // 8K
- write_reg_byte(0xE000, 0); // PRG RAM DISABLE [WRITE RAM SAFE]
+ if (mapper == 85) // 8K
+ write_reg_byte(0xE000, 0); // PRG RAM DISABLE [WRITE RAM SAFE]
break;
}
myFile.flush();
@@ -4342,8 +4281,7 @@ void writeRAM() {
if (ramsize == 0) {
print_Error(F("RAM SIZE 0K"), false);
- }
- else {
+ } else {
fileBrowser(F("Select RAM File"));
word base = 0x6000;
@@ -4359,27 +4297,27 @@ void writeRAM() {
//open file on sd card
if (myFile.open(filePath, O_READ)) {
switch (mapper) {
- case 0: // 2K/4K
- for (word address = 0x0; address < (0x800 * ramsize); address += 512) { // 2K/4K
+ case 0: // 2K/4K
+ for (word address = 0x0; address < (0x800 * ramsize); address += 512) { // 2K/4K
myFile.read(sdBuffer, 512);
for (int x = 0; x < 512; x++) {
- write_prg_byte(base + address + x, sdBuffer[x]); // SWITCH MUST BE IN OFF POSITION
+ write_prg_byte(base + address + x, sdBuffer[x]); // SWITCH MUST BE IN OFF POSITION
}
}
break;
case 1:
case 155:
- banks = int_pow(2, ramsize) / 2; // banks = 1,2,4
- for (int i = 0; i < banks; i++) { // 8K Banks ($6000-$7FFF)
- write_prg_byte(0x8000, 0x80); // Clear Register
- write_mmc1_byte(0x8000, 1 << 3); // PRG ROM MODE 32K
- write_mmc1_byte(0xE000, 0); // PRG RAM ENABLED
- if (banks == 4) // 32K
+ banks = int_pow(2, ramsize) / 2; // banks = 1,2,4
+ for (int i = 0; i < banks; i++) { // 8K Banks ($6000-$7FFF)
+ write_prg_byte(0x8000, 0x80); // Clear Register
+ write_mmc1_byte(0x8000, 1 << 3); // PRG ROM MODE 32K
+ write_mmc1_byte(0xE000, 0); // PRG RAM ENABLED
+ if (banks == 4) // 32K
write_mmc1_byte(0xA000, i << 2);
else
write_mmc1_byte(0xA000, i << 3);
- for (word address = 0x0; address < 0x2000; address += 512) { // 8K
+ for (word address = 0x0; address < 0x2000; address += 512) { // 8K
myFile.read(sdBuffer, 512);
for (int x = 0; x < 512; x++) {
write_prg_byte(base + address + x, sdBuffer[x]);
@@ -4388,67 +4326,65 @@ void writeRAM() {
}
break;
- case 4: // 1K/8K (MMC6/MMC3)
- if (mmc6) { // MMC6 1K
- write_prg_byte(0x8000, 0x20); // PRG RAM ENABLE
- write_prg_byte(0xA001, 0x30); // PRG RAM PROTECT - Enable reading/writing to RAM at $7000-$71FF
- for (word address = 0x1000; address < 0x1200; address += 512) { // 512B
+ case 4: // 1K/8K (MMC6/MMC3)
+ if (mmc6) { // MMC6 1K
+ write_prg_byte(0x8000, 0x20); // PRG RAM ENABLE
+ write_prg_byte(0xA001, 0x30); // PRG RAM PROTECT - Enable reading/writing to RAM at $7000-$71FF
+ for (word address = 0x1000; address < 0x1200; address += 512) { // 512B
myFile.read(sdBuffer, 512);
for (int x = 0; x < 512; x++) {
write_wram_byte(base + address + x, sdBuffer[x]);
}
}
- write_prg_byte(0x8000, 0x20); // PRG RAM ENABLE
- write_prg_byte(0xA001, 0xC0); // PRG RAM PROTECT - Enable reading/writing to RAM at $7200-$73FF
- for (word address = 0x1200; address < 0x1400; address += 512) { // 512B
+ write_prg_byte(0x8000, 0x20); // PRG RAM ENABLE
+ write_prg_byte(0xA001, 0xC0); // PRG RAM PROTECT - Enable reading/writing to RAM at $7200-$73FF
+ for (word address = 0x1200; address < 0x1400; address += 512) { // 512B
myFile.read(sdBuffer, 512);
for (int x = 0; x < 512; x++) {
write_wram_byte(base + address + x, sdBuffer[x]);
}
}
- write_prg_byte(0x8000, 0x6); // PRG RAM DISABLE
- }
- else { // MMC3 8K
- write_prg_byte(0xA001, 0x80); // PRG RAM CHIP ENABLE - Chip Enable, Allow Writes
- for (word address = 0; address < 0x2000; address += 512) { // 8K
+ write_prg_byte(0x8000, 0x6); // PRG RAM DISABLE
+ } else { // MMC3 8K
+ write_prg_byte(0xA001, 0x80); // PRG RAM CHIP ENABLE - Chip Enable, Allow Writes
+ for (word address = 0; address < 0x2000; address += 512) { // 8K
myFile.read(sdBuffer, 512);
for (int x = 0; x < 512; x++) {
write_prg_byte(base + address + x, sdBuffer[x]);
}
}
- write_prg_byte(0xA001, 0xC0); // PRG RAM CHIP ENABLE - Chip Enable, Write Protect
+ write_prg_byte(0xA001, 0xC0); // PRG RAM CHIP ENABLE - Chip Enable, Write Protect
}
break;
- case 5: // 8K/16K/32K
- write_prg_byte(0x5100, 3); // 8K PRG Banks
- banks = int_pow(2, ramsize) / 2; // banks = 1,2,4
- if (banks == 2) { // 16K - Split SRAM Chips 8K/8K [ETROM = 16K (ONLY 1ST 8K BATTERY BACKED)]
- for (int i = 0; i < (banks / 2); i++) { // Chip 1
+ case 5: // 8K/16K/32K
+ write_prg_byte(0x5100, 3); // 8K PRG Banks
+ banks = int_pow(2, ramsize) / 2; // banks = 1,2,4
+ if (banks == 2) { // 16K - Split SRAM Chips 8K/8K [ETROM = 16K (ONLY 1ST 8K BATTERY BACKED)]
+ for (int i = 0; i < (banks / 2); i++) { // Chip 1
write_prg_byte(0x5113, i);
- for (word address = 0; address < 0x2000; address += 512) { // 8K
+ for (word address = 0; address < 0x2000; address += 512) { // 8K
writeMMC5RAM(base, address);
}
}
- for (int j = 4; j < (banks / 2) + 4; j++) { // Chip 2
+ for (int j = 4; j < (banks / 2) + 4; j++) { // Chip 2
write_prg_byte(0x5113, j);
- for (word address = 0; address < 0x2000; address += 512) { // 8K
+ for (word address = 0; address < 0x2000; address += 512) { // 8K
writeMMC5RAM(base, address);
}
}
- }
- else { // 8K/32K Single SRAM Chip [EKROM = 8K BATTERY BACKED, EWROM = 32K BATTERY BACKED]
- for (int i = 0; i < banks; i++) { // banks = 1 or 4
+ } else { // 8K/32K Single SRAM Chip [EKROM = 8K BATTERY BACKED, EWROM = 32K BATTERY BACKED]
+ for (int i = 0; i < banks; i++) { // banks = 1 or 4
write_prg_byte(0x5113, i);
- for (word address = 0; address < 0x2000; address += 512) { // 8K
+ for (word address = 0; address < 0x2000; address += 512) { // 8K
writeMMC5RAM(base, address);
}
}
}
break;
- case 16: // 256-byte EEPROM 24C02
- case 159: // 128-byte EEPROM 24C01 [Little Endian]
+ case 16: // 256-byte EEPROM 24C02
+ case 159: // 128-byte EEPROM 24C01 [Little Endian]
if (mapper == 159)
eepsize = 128;
else
@@ -4464,46 +4400,45 @@ void writeRAM() {
break;
case 19:
- if (ramsize == 2) { // PRG RAM 128B
+ if (ramsize == 2) { // PRG RAM 128B
myFile.read(sdBuffer, 128);
for (int x = 0; x < 128; x++) {
- write_ram_byte(0xF800, x); // PRG RAM ENABLE
- write_prg_byte(0x4800, sdBuffer[x]); // DATA PORT
+ write_ram_byte(0xF800, x); // PRG RAM ENABLE
+ write_prg_byte(0x4800, sdBuffer[x]); // DATA PORT
}
- }
- else { // SRAM 8K
- for (int i = 0; i < 64; i++) { // Init Register
- write_ram_byte(0xF800, 0x40); // PRG RAM WRITE ENABLE
+ } else { // SRAM 8K
+ for (int i = 0; i < 64; i++) { // Init Register
+ write_ram_byte(0xF800, 0x40); // PRG RAM WRITE ENABLE
}
- write_ram_byte(0xF800, 0x40); // PRG RAM WRITE ENABLE
- for (word address = 0; address < 0x2000; address += 512) { // 8K
+ write_ram_byte(0xF800, 0x40); // PRG RAM WRITE ENABLE
+ for (word address = 0; address < 0x2000; address += 512) { // 8K
myFile.read(sdBuffer, 512);
for (int x = 0; x < 512; x++) {
write_prg_byte(base + address + x, sdBuffer[x]);
}
}
- write_ram_byte(0xF800, 0x0F); // PRG RAM WRITE PROTECT
+ write_ram_byte(0xF800, 0x0F); // PRG RAM WRITE PROTECT
}
break;
- case 80: // 1K
- write_prg_byte(0x7EF8, 0xA3); // PRG RAM ENABLE 0
- write_prg_byte(0x7EF9, 0xA3); // PRG RAM ENABLE 1
- for (word address = 0x1F00; address < 0x2000; address += 512) { // PRG RAM 1K ($7F00-$7FFF)
+ case 80: // 1K
+ write_prg_byte(0x7EF8, 0xA3); // PRG RAM ENABLE 0
+ write_prg_byte(0x7EF9, 0xA3); // PRG RAM ENABLE 1
+ for (word address = 0x1F00; address < 0x2000; address += 512) { // PRG RAM 1K ($7F00-$7FFF)
myFile.read(sdBuffer, 128);
for (int x = 0; x < 128; x++) {
write_prg_byte(base + address + x, sdBuffer[x]);
}
}
- write_prg_byte(0x7EF8, 0xFF); // PRG RAM DISABLE 0
- write_prg_byte(0x7EF9, 0xFF); // PRG RAM DISABLE 1
+ write_prg_byte(0x7EF8, 0xFF); // PRG RAM DISABLE 0
+ write_prg_byte(0x7EF9, 0xFF); // PRG RAM DISABLE 1
break;
- case 82: // 5K
- write_prg_byte(0x7EF7, 0xCA); // PRG RAM ENABLE 0 ($6000-$67FF)
- write_prg_byte(0x7EF8, 0x69); // PRG RAM ENABLE 1 ($6800-$6FFF)
- write_prg_byte(0x7EF9, 0x84); // PRG RAM ENABLE 2 ($7000-$73FF)
- for (word address = 0x0; address < 0x1400; address += 1024) { // PRG RAM 5K ($6000-$73FF)
+ case 82: // 5K
+ write_prg_byte(0x7EF7, 0xCA); // PRG RAM ENABLE 0 ($6000-$67FF)
+ write_prg_byte(0x7EF8, 0x69); // PRG RAM ENABLE 1 ($6800-$6FFF)
+ write_prg_byte(0x7EF9, 0x84); // PRG RAM ENABLE 2 ($7000-$73FF)
+ for (word address = 0x0; address < 0x1400; address += 1024) { // PRG RAM 5K ($6000-$73FF)
myFile.read(sdBuffer, 512);
firstbyte = sdBuffer[0];
for (int x = 0; x < 512; x++)
@@ -4511,48 +4446,46 @@ void writeRAM() {
myFile.read(sdBuffer, 512);
for (int x = 0; x < 512; x++)
write_prg_byte(base + address + x + 512, sdBuffer[x]);
- write_prg_byte(base + address, firstbyte); // REWRITE 1ST BYTE
+ write_prg_byte(base + address, firstbyte); // REWRITE 1ST BYTE
}
- write_prg_byte(0x7EF7, 0xFF); // PRG RAM DISABLE 0 ($6000-$67FF)
- write_prg_byte(0x7EF8, 0xFF); // PRG RAM DISABLE 1 ($6800-$6FFF)
- write_prg_byte(0x7EF9, 0xFF); // PRG RAM DISABLE 2 ($7000-$73FF)
+ write_prg_byte(0x7EF7, 0xFF); // PRG RAM DISABLE 0 ($6000-$67FF)
+ write_prg_byte(0x7EF8, 0xFF); // PRG RAM DISABLE 1 ($6800-$6FFF)
+ write_prg_byte(0x7EF9, 0xFF); // PRG RAM DISABLE 2 ($7000-$73FF)
break;
default:
- if (mapper == 118) // 8K
- write_prg_byte(0xA001, 0x80); // PRG RAM CHIP ENABLE - Chip Enable, Allow Writes
- else if ((mapper == 21) || (mapper == 25)) // 8K
+ if (mapper == 118) // 8K
+ write_prg_byte(0xA001, 0x80); // PRG RAM CHIP ENABLE - Chip Enable, Allow Writes
+ else if ((mapper == 21) || (mapper == 25)) // 8K
write_prg_byte(0x8000, 0);
- else if (mapper == 26) // 8K
- write_prg_byte(0xB003, 0x80); // PRG RAM ENABLE
+ else if (mapper == 26) // 8K
+ write_prg_byte(0xB003, 0x80); // PRG RAM ENABLE
// else if (mapper == 68) // 8K
// write_reg_byte(0xF000, 0x10); // PRG RAM ENABLE [WRITE RAM SAFE]
- else if (mapper == 69) { // 8K
- write_prg_byte(0x8000, 8); // Command Register - PRG Bank 0
- write_prg_byte(0xA000, 0xC0); // Parameter Register - PRG RAM Enabled, PRG RAM, Bank 0 to $6000-$7FFF
- }
- else if (mapper == 85) // 8K
- write_ram_byte(0xE000, 0x80); // PRG RAM ENABLE
- else if (mapper == 153) // 8K
- write_prg_byte(0x800D, 0x20); // PRG RAM Chip Enable
- for (word address = 0; address < 0x2000; address += 512) { // 8K
+ else if (mapper == 69) { // 8K
+ write_prg_byte(0x8000, 8); // Command Register - PRG Bank 0
+ write_prg_byte(0xA000, 0xC0); // Parameter Register - PRG RAM Enabled, PRG RAM, Bank 0 to $6000-$7FFF
+ } else if (mapper == 85) // 8K
+ write_ram_byte(0xE000, 0x80); // PRG RAM ENABLE
+ else if (mapper == 153) // 8K
+ write_prg_byte(0x800D, 0x20); // PRG RAM Chip Enable
+ for (word address = 0; address < 0x2000; address += 512) { // 8K
myFile.read(sdBuffer, 512);
for (int x = 0; x < 512; x++) {
write_prg_byte(base + address + x, sdBuffer[x]);
}
}
- if (mapper == 118) // 8K
- write_prg_byte(0xA001, 0xC0); // PRG RAM CHIP ENABLE - Chip Enable, Write Protect
- else if (mapper == 26) // 8K
- write_prg_byte(0xB003, 0); // PRG RAM DISABLE
+ if (mapper == 118) // 8K
+ write_prg_byte(0xA001, 0xC0); // PRG RAM CHIP ENABLE - Chip Enable, Write Protect
+ else if (mapper == 26) // 8K
+ write_prg_byte(0xB003, 0); // PRG RAM DISABLE
// else if (mapper == 68) // 8K
// write_reg_byte(0xF000, 0x00); // PRG RAM DISABLE [WRITE RAM SAFE]
- else if (mapper == 69) { // 8K
- write_prg_byte(0x8000, 8); // Command Register - PRG Bank 0
- write_prg_byte(0xA000, 0); // Parameter Register - PRG RAM Disabled, PRG ROM, Bank 0 to $6000-$7FFF
- }
- else if (mapper == 85) // 8K
- write_reg_byte(0xE000, 0); // PRG RAM DISABLE [WRITE RAM SAFE]
+ else if (mapper == 69) { // 8K
+ write_prg_byte(0x8000, 8); // Command Register - PRG Bank 0
+ write_prg_byte(0xA000, 0); // Parameter Register - PRG RAM Disabled, PRG ROM, Bank 0 to $6000-$7FFF
+ } else if (mapper == 85) // 8K
+ write_reg_byte(0xE000, 0); // PRG RAM DISABLE [WRITE RAM SAFE]
break;
}
myFile.close();
@@ -4562,16 +4495,15 @@ void writeRAM() {
println_Msg(F("RAM FILE WRITTEN!"));
display_Update();
- }
- else {
+ } else {
print_Error(F("SD ERROR"), true);
}
}
LED_RED_OFF;
LED_GREEN_OFF;
- sd.chdir(); // root
- filePath[0] = '\0'; // Reset filePath
+ sd.chdir(); // root
+ filePath[0] = '\0'; // Reset filePath
}
/******************************************
@@ -4587,160 +4519,158 @@ void writeRAM() {
// 10 RAM SIZE
void resetEEPROM() {
- EEPROM_writeAnything(0, 0); // FOLDER #
- EEPROM_writeAnything(2, 0); // CARTMODE
- EEPROM_writeAnything(3, 0); // RETRY
- EEPROM_writeAnything(4, 0); // STATUS
- EEPROM_writeAnything(5, 0); // UNKNOWNCRC
- EEPROM_writeAnything(6, 1); // LED (RESET TO ON)
- EEPROM_writeAnything(7, 0); // MAPPER
- EEPROM_writeAnything(8, 0); // PRG SIZE
- EEPROM_writeAnything(9, 0); // CHR SIZE
- EEPROM_writeAnything(10, 0); // RAM SIZE
+ EEPROM_writeAnything(0, 0); // FOLDER #
+ EEPROM_writeAnything(2, 0); // CARTMODE
+ EEPROM_writeAnything(3, 0); // RETRY
+ EEPROM_writeAnything(4, 0); // STATUS
+ EEPROM_writeAnything(5, 0); // UNKNOWNCRC
+ EEPROM_writeAnything(6, 1); // LED (RESET TO ON)
+ EEPROM_writeAnything(7, 0); // MAPPER
+ EEPROM_writeAnything(8, 0); // PRG SIZE
+ EEPROM_writeAnything(9, 0); // CHR SIZE
+ EEPROM_writeAnything(10, 0); // RAM SIZE
}
void EepromStart_NES() {
- write_prg_byte(0x800D, 0x00); // sda low, scl low
- write_prg_byte(0x800D, 0x60); // sda, scl high
- write_prg_byte(0x800D, 0x20); // sda low, scl high
- write_prg_byte(0x800D, 0x00); // START
+ write_prg_byte(0x800D, 0x00); // sda low, scl low
+ write_prg_byte(0x800D, 0x60); // sda, scl high
+ write_prg_byte(0x800D, 0x20); // sda low, scl high
+ write_prg_byte(0x800D, 0x00); // START
}
void EepromStop_NES() {
- write_prg_byte(0x800D, 0x00); // sda, scl low
- write_prg_byte(0x800D, 0x20); // sda low, scl high
- write_prg_byte(0x800D, 0x60); // sda, scl high
- write_prg_byte(0x800D, 0x40); // sda high, scl low
- write_prg_byte(0x800D, 0x00); // STOP
+ write_prg_byte(0x800D, 0x00); // sda, scl low
+ write_prg_byte(0x800D, 0x20); // sda low, scl high
+ write_prg_byte(0x800D, 0x60); // sda, scl high
+ write_prg_byte(0x800D, 0x40); // sda high, scl low
+ write_prg_byte(0x800D, 0x00); // STOP
}
void EepromSet0_NES() {
- write_prg_byte(0x800D, 0x00); // sda low, scl low
- write_prg_byte(0x800D, 0x20); // sda low, scl high // 0
- write_prg_byte(0x800D, 0x00); // sda low, scl low
+ write_prg_byte(0x800D, 0x00); // sda low, scl low
+ write_prg_byte(0x800D, 0x20); // sda low, scl high // 0
+ write_prg_byte(0x800D, 0x00); // sda low, scl low
}
void EepromSet1_NES() {
- write_prg_byte(0x800D, 0x40); // sda high, scl low
- write_prg_byte(0x800D, 0x60); // sda high, scl high // 1
- write_prg_byte(0x800D, 0x40); // sda high, scl low
- write_prg_byte(0x800D, 0x00); // sda low, scl low
+ write_prg_byte(0x800D, 0x40); // sda high, scl low
+ write_prg_byte(0x800D, 0x60); // sda high, scl high // 1
+ write_prg_byte(0x800D, 0x40); // sda high, scl low
+ write_prg_byte(0x800D, 0x00); // sda low, scl low
}
-void EepromStatus_NES() { // ACK
- write_prg_byte(0x800D, 0x40); // sda high, scl low
- write_prg_byte(0x800D, 0x60); // sda high, scl high
- write_prg_byte(0x800D, 0xE0); // sda high, scl high, read high
+void EepromStatus_NES() { // ACK
+ write_prg_byte(0x800D, 0x40); // sda high, scl low
+ write_prg_byte(0x800D, 0x60); // sda high, scl high
+ write_prg_byte(0x800D, 0xE0); // sda high, scl high, read high
byte eepStatus = 1;
do {
eepStatus = (read_prg_byte(0x6000) & 0x10) >> 4;
delayMicroseconds(4);
- }
- while (eepStatus == 1);
- write_prg_byte(0x800D, 0x40); // sda high, scl low
+ } while (eepStatus == 1);
+ write_prg_byte(0x800D, 0x40); // sda high, scl low
}
void EepromReadData_NES() {
// read serial data into buffer
for (int i = 0; i < 8; i++) {
- write_prg_byte(0x800D, 0x60); // sda high, scl high, read low
- write_prg_byte(0x800D, 0xE0); // sda high, scl high, read high
- eepbit[i] = (read_prg_byte(0x6000) & 0x10) >> 4; // Read 0x6000 with Mask 0x10 (bit 4)
- write_prg_byte(0x800D, 0x40); // sda high, scl low
+ write_prg_byte(0x800D, 0x60); // sda high, scl high, read low
+ write_prg_byte(0x800D, 0xE0); // sda high, scl high, read high
+ eepbit[i] = (read_prg_byte(0x6000) & 0x10) >> 4; // Read 0x6000 with Mask 0x10 (bit 4)
+ write_prg_byte(0x800D, 0x40); // sda high, scl low
}
}
-void EepromDevice_NES() { // 24C02 ONLY
+void EepromDevice_NES() { // 24C02 ONLY
EepromSet1_NES();
EepromSet0_NES();
EepromSet1_NES();
EepromSet0_NES();
- EepromSet0_NES(); // A2
- EepromSet0_NES(); // A1
- EepromSet0_NES(); // A0
+ EepromSet0_NES(); // A2
+ EepromSet0_NES(); // A1
+ EepromSet0_NES(); // A0
}
void EepromReadMode_NES() {
- EepromSet1_NES(); // READ
- EepromStatus_NES(); // ACK
+ EepromSet1_NES(); // READ
+ EepromStatus_NES(); // ACK
}
void EepromWriteMode_NES() {
- EepromSet0_NES(); // WRITE
- EepromStatus_NES(); // ACK
+ EepromSet0_NES(); // WRITE
+ EepromStatus_NES(); // ACK
}
void EepromFinish_NES() {
- write_prg_byte(0x800D, 0x00); // sda low, scl low
- write_prg_byte(0x800D, 0x40); // sda high, scl low
- write_prg_byte(0x800D, 0x60); // sda high, scl high
- write_prg_byte(0x800D, 0x40); // sda high, scl low
- write_prg_byte(0x800D, 0x00); // sda low, scl low
+ write_prg_byte(0x800D, 0x00); // sda low, scl low
+ write_prg_byte(0x800D, 0x40); // sda high, scl low
+ write_prg_byte(0x800D, 0x60); // sda high, scl high
+ write_prg_byte(0x800D, 0x40); // sda high, scl low
+ write_prg_byte(0x800D, 0x00); // sda low, scl low
}
-void EepromSetAddress01(byte address) { // 24C01 [Little Endian]
+void EepromSetAddress01(byte address) { // 24C01 [Little Endian]
for (int i = 0; i < 7; i++) {
- if (address & 0x1) // Bit is HIGH
+ if (address & 0x1) // Bit is HIGH
EepromSet1_NES();
- else // Bit is LOW
+ else // Bit is LOW
EepromSet0_NES();
- address >>= 1; // rotate to the next bit
+ address >>= 1; // rotate to the next bit
}
}
-void EepromSetAddress02(byte address) { // 24C02
+void EepromSetAddress02(byte address) { // 24C02
for (int i = 0; i < 8; i++) {
- if ((address >> 7) & 0x1) // Bit is HIGH
+ if ((address >> 7) & 0x1) // Bit is HIGH
EepromSet1_NES();
- else // Bit is LOW
+ else // Bit is LOW
EepromSet0_NES();
- address <<= 1; // rotate to the next bit
+ address <<= 1; // rotate to the next bit
}
- EepromStatus_NES(); // ACK
+ EepromStatus_NES(); // ACK
}
-void EepromWriteData01() { // 24C01 [Little Endian]
+void EepromWriteData01() { // 24C01 [Little Endian]
for (int i = 0; i < 8; i++) {
- if (eeptemp & 0x1) // Bit is HIGH
+ if (eeptemp & 0x1) // Bit is HIGH
EepromSet1_NES();
- else // Bit is LOW
+ else // Bit is LOW
EepromSet0_NES();
- eeptemp >>= 1; // rotate to the next bit
+ eeptemp >>= 1; // rotate to the next bit
}
- EepromStatus_NES(); // ACK
+ EepromStatus_NES(); // ACK
}
-void EepromWriteData02() { // 24C02
+void EepromWriteData02() { // 24C02
for (int i = 0; i < 8; i++) {
- if ((eeptemp >> 7) & 0x1) // Bit is HIGH
+ if ((eeptemp >> 7) & 0x1) // Bit is HIGH
EepromSet1_NES();
- else // Bit is LOW
+ else // Bit is LOW
EepromSet0_NES();
- eeptemp <<= 1; // rotate to the next bit
+ eeptemp <<= 1; // rotate to the next bit
}
- EepromStatus_NES(); // ACK
+ EepromStatus_NES(); // ACK
}
void EepromREAD(byte address) {
- EepromStart_NES(); // START
- if (mapper == 159) { // 24C01
- EepromSetAddress01(address); // 24C01 [Little Endian]
+ EepromStart_NES(); // START
+ if (mapper == 159) { // 24C01
+ EepromSetAddress01(address); // 24C01 [Little Endian]
EepromReadMode_NES();
EepromReadData_NES();
EepromFinish_NES();
- EepromStop_NES(); // STOP
+ EepromStop_NES(); // STOP
// OR 8 bits into byte
eeptemp = eepbit[7] << 7 | eepbit[6] << 6 | eepbit[5] << 5 | eepbit[4] << 4 | eepbit[3] << 3 | eepbit[2] << 2 | eepbit[1] << 1 | eepbit[0];
- }
- else { // 24C02
- EepromDevice_NES(); // DEVICE [1010] + ADDR [A2-A0]
+ } else { // 24C02
+ EepromDevice_NES(); // DEVICE [1010] + ADDR [A2-A0]
EepromWriteMode_NES();
EepromSetAddress02(address);
- EepromStart_NES(); // START
- EepromDevice_NES(); // DEVICE [1010] + ADDR [A2-A0]
+ EepromStart_NES(); // START
+ EepromDevice_NES(); // DEVICE [1010] + ADDR [A2-A0]
EepromReadMode_NES();
EepromReadData_NES();
EepromFinish_NES();
- EepromStop_NES(); // STOP
+ EepromStop_NES(); // STOP
// OR 8 bits into byte
eeptemp = eepbit[0] << 7 | eepbit[1] << 6 | eepbit[2] << 5 | eepbit[3] << 4 | eepbit[4] << 3 | eepbit[5] << 2 | eepbit[6] << 1 | eepbit[7];
}
@@ -4749,42 +4679,41 @@ void EepromREAD(byte address) {
void EepromWRITE(byte address) {
eeptemp = sdBuffer[address];
- EepromStart_NES(); // START
- if (mapper == 159) { // 24C01
- EepromSetAddress01(address); // 24C01 [Little Endian]
+ EepromStart_NES(); // START
+ if (mapper == 159) { // 24C01
+ EepromSetAddress01(address); // 24C01 [Little Endian]
EepromWriteMode_NES();
- EepromWriteData01(); // 24C01 [Little Endian]
- }
- else { // 24C02
- EepromDevice_NES(); // DEVICE [1010] + ADDR [A2-A0]
+ EepromWriteData01(); // 24C01 [Little Endian]
+ } else { // 24C02
+ EepromDevice_NES(); // DEVICE [1010] + ADDR [A2-A0]
EepromWriteMode_NES();
EepromSetAddress02(address);
EepromWriteData02();
}
- EepromStop_NES(); // STOP
+ EepromStop_NES(); // STOP
}
/******************************************
NESmaker Flash Cart [SST 39SF40]
*****************************************/
-void NESmaker_ResetFlash() { // Reset Flash
+void NESmaker_ResetFlash() { // Reset Flash
write_prg_byte(0xC000, 0x01);
write_prg_byte(0x9555, 0xAA);
write_prg_byte(0xC000, 0x00);
write_prg_byte(0xAAAA, 0x55);
write_prg_byte(0xC000, 0x01);
- write_prg_byte(0x9555, 0xFF); // Reset
+ write_prg_byte(0x9555, 0xFF); // Reset
}
// SST 39SF040 Software ID
-void NESmaker_ID() { // Read Flash ID
+void NESmaker_ID() { // Read Flash ID
NESmaker_ResetFlash();
write_prg_byte(0xC000, 0x01);
write_prg_byte(0x9555, 0xAA);
write_prg_byte(0xC000, 0x00);
write_prg_byte(0xAAAA, 0x55);
write_prg_byte(0xC000, 0x01);
- write_prg_byte(0x9555, 0x90); // Software ID Entry
+ write_prg_byte(0x9555, 0x90); // Software ID Entry
unsigned char ID1 = read_prg_byte(0x8000);
unsigned char ID2 = read_prg_byte(0x8001);
sprintf(flashid, "%02X%02X", ID1, ID2);
@@ -4793,8 +4722,8 @@ void NESmaker_ID() { // Read Flash ID
write_prg_byte(0xC000, 0x00);
write_prg_byte(0xAAAA, 0x55);
write_prg_byte(0xC000, 0x01);
- write_prg_byte(0x9555, 0xF0); // Software ID Exit
- if (strcmp(flashid, "BFB7") == 0) // SST 39SF040
+ write_prg_byte(0x9555, 0xF0); // Software ID Exit
+ if (strcmp(flashid, "BFB7") == 0) // SST 39SF040
flashfound = 1;
}
@@ -4809,8 +4738,8 @@ void NESmaker_SectorErase(byte bank, word address) {
write_prg_byte(0x9555, 0xAA);
write_prg_byte(0xC000, 0x00);
write_prg_byte(0xAAAA, 0x55);
- write_prg_byte(0xC000, bank); // $00-$1F
- write_prg_byte(address, 0x30); // Sector Erase ($8000/$9000/$A000/$B000)
+ write_prg_byte(0xC000, bank); // $00-$1F
+ write_prg_byte(address, 0x30); // Sector Erase ($8000/$9000/$A000/$B000)
}
void NESmaker_ByteProgram(byte bank, word address, byte data) {
@@ -4820,12 +4749,12 @@ void NESmaker_ByteProgram(byte bank, word address, byte data) {
write_prg_byte(0xAAAA, 0x55);
write_prg_byte(0xC000, 0x01);
write_prg_byte(0x9555, 0xA0);
- write_prg_byte(0xC000, bank); // $00-$1F
- write_prg_byte(address, data); // $8000-$BFFF
+ write_prg_byte(0xC000, bank); // $00-$1F
+ write_prg_byte(address, data); // $8000-$BFFF
}
// SST 39SF040 Chip Erase [NOT IMPLEMENTED]
-void NESmaker_ChipErase() { // Typical 70ms
+void NESmaker_ChipErase() { // Typical 70ms
write_prg_byte(0xC000, 0x01);
write_prg_byte(0x9555, 0xAA);
write_prg_byte(0xC000, 0x00);
@@ -4837,7 +4766,7 @@ void NESmaker_ChipErase() { // Typical 70ms
write_prg_byte(0xC000, 0x00);
write_prg_byte(0xAAAA, 0x55);
write_prg_byte(0xC000, 0x01);
- write_prg_byte(0x9555, 0x10); // Chip Erase
+ write_prg_byte(0x9555, 0x10); // Chip Erase
}
void writeFLASH() {
@@ -4846,8 +4775,7 @@ void writeFLASH() {
LED_RED_ON;
println_Msg(F("FLASH NOT DETECTED"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Flash ID: "));
println_Msg(flashid);
println_Msg(F(""));
@@ -4871,18 +4799,17 @@ void writeFLASH() {
//open file on sd card
if (myFile.open(filePath, O_READ)) {
- banks = int_pow(2, prgsize); // 256K/512K
- for (int i = 0; i < banks; i++) { // 16K Banks
- for (word sector = 0; sector < 0x4000; sector += 0x1000) { // 4K Sectors ($8000/$9000/$A000/$B000)
+ banks = int_pow(2, prgsize); // 256K/512K
+ for (int i = 0; i < banks; i++) { // 16K Banks
+ for (word sector = 0; sector < 0x4000; sector += 0x1000) { // 4K Sectors ($8000/$9000/$A000/$B000)
// Sector Erase
NESmaker_SectorErase(i, base + sector);
- delay(18); // Typical 18ms
- for (byte j = 0; j < 2; j++) { // Confirm erase twice
+ delay(18); // Typical 18ms
+ for (byte j = 0; j < 2; j++) { // Confirm erase twice
do {
bytecheck = read_prg_byte(base + sector);
delay(18);
- }
- while (bytecheck != 0xFF);
+ } while (bytecheck != 0xFF);
}
// Program Byte
for (word addr = 0x0; addr < 0x1000; addr += 512) {
@@ -4890,13 +4817,12 @@ void writeFLASH() {
for (int x = 0; x < 512; x++) {
word location = base + sector + addr + x;
NESmaker_ByteProgram(i, base + sector + addr + x, sdBuffer[x]);
- delayMicroseconds(14); // Typical 14us
- for (byte k = 0; k < 2; k++) { // Confirm write twice
+ delayMicroseconds(14); // Typical 14us
+ for (byte k = 0; k < 2; k++) { // Confirm write twice
do {
bytecheck = read_prg_byte(base + sector + addr + x);
delayMicroseconds(14);
- }
- while (bytecheck != sdBuffer[x]);
+ } while (bytecheck != sdBuffer[x]);
}
}
}
@@ -4917,8 +4843,7 @@ void writeFLASH() {
println_Msg(F(""));
println_Msg(F("FLASH FILE WRITTEN!"));
display_Update();
- }
- else {
+ } else {
LED_RED_ON;
println_Msg(F("SD ERROR"));
display_Update();
@@ -4927,10 +4852,10 @@ void writeFLASH() {
display_Clear();
LED_RED_OFF;
LED_GREEN_OFF;
- sd.chdir(); // root
- filePath[0] = '\0'; // Reset filePath
+ sd.chdir(); // root
+ filePath[0] = '\0'; // Reset filePath
}
#endif
//******************************************
// End of File
-//******************************************
+//****************************************** \ No newline at end of file
diff --git a/Cart_Reader/NGP.ino b/Cart_Reader/NGP.ino
index e91f337..79386f3 100644
--- a/Cart_Reader/NGP.ino
+++ b/Cart_Reader/NGP.ino
@@ -6,13 +6,13 @@
static const char ngpMenuItem1[] PROGMEM = "Read Rom";
static const char ngpMenuItem2[] PROGMEM = "Read chip info";
static const char ngpMenuItemReset[] PROGMEM = "Reset";
-static const char* const menuOptionsNGP[] PROGMEM = {ngpMenuItem1, ngpMenuItem2, ngpMenuItemReset};
+static const char* const menuOptionsNGP[] PROGMEM = { ngpMenuItem1, ngpMenuItem2, ngpMenuItemReset };
static const char ngpRomItem1[] PROGMEM = "4 Mbits / 512 KB";
static const char ngpRomItem2[] PROGMEM = "8 Mbits / 1 MB";
static const char ngpRomItem3[] PROGMEM = "16 Mbits / 2 MB";
static const char ngpRomItem4[] PROGMEM = "32 Mbits / 4 MB";
-static const char* const ngpRomOptions[] PROGMEM = {ngpRomItem1, ngpRomItem2, ngpRomItem3, ngpRomItem4};
+static const char* const ngpRomOptions[] PROGMEM = { ngpRomItem1, ngpRomItem2, ngpRomItem3, ngpRomItem4 };
char ngpRomVersion[3];
uint8_t ngpSystemType;
@@ -79,7 +79,7 @@ void ngpMenu() {
}
bool getCartInfo_NGP() {
- uint8_t *tmp;
+ uint8_t* tmp;
// enter autoselect mode
dataOut();
@@ -99,13 +99,13 @@ bool getCartInfo_NGP() {
switch (romSize) {
- case 0xffff: return false; break; // detection error (no cart inserted or hw problem)
- case 0x98ab: cartSize = 524288; break; // 4 Mbits - Toshiba
- case 0x204c: cartSize = 524288; break; // 4 Mbits - STMicroelectronics ?
- case 0x982c: cartSize = 1048576; break; // 8 Mbits - Toshiba
- case 0xec2c: cartSize = 1048576; break; // 8 Mbits - Samsung
- case 0x982f: cartSize = 2097152; break; // 16 Mbits - Toshiba
- case 0xec2f: cartSize = 2097152; break; // 16 Mbits - Samsung
+ case 0xffff: return false; break; // detection error (no cart inserted or hw problem)
+ case 0x98ab: cartSize = 524288; break; // 4 Mbits - Toshiba
+ case 0x204c: cartSize = 524288; break; // 4 Mbits - STMicroelectronics ?
+ case 0x982c: cartSize = 1048576; break; // 8 Mbits - Toshiba
+ case 0xec2c: cartSize = 1048576; break; // 8 Mbits - Samsung
+ case 0x982f: cartSize = 2097152; break; // 16 Mbits - Toshiba
+ case 0xec2f: cartSize = 2097152; break; // 16 Mbits - Samsung
}
// reset to read mode
@@ -123,7 +123,7 @@ bool getCartInfo_NGP() {
snprintf(cartID, 5, "%02X%02X", readByte_NGP(0x21), readByte_NGP(0x20));
// force rom size to 32 Mbits for few titles
- if (strcmp(cartID, "0060") == 0 || strcmp(cartID, "0061") == 0 || strcmp(cartID, "0069") == 0 )
+ if (strcmp(cartID, "0060") == 0 || strcmp(cartID, "0061") == 0 || strcmp(cartID, "0069") == 0)
cartSize = 4194304;
// get app version
@@ -164,8 +164,7 @@ void printCartInfo_NGP() {
print_Msg(F("ROM Size: "));
if (cartSize == 0) {
println_Msg(F("Unknown"));
- }
- else {
+ } else {
print_Msg((cartSize >> 17));
println_Msg(F(" Mbits"));
}
@@ -175,7 +174,7 @@ void printCartInfo_NGP() {
wait();
}
-void readROM_NGP(char *outPathBuf, size_t bufferSize) {
+void readROM_NGP(char* outPathBuf, size_t bufferSize) {
// Set cartsize manually if chip ID is unknown
if (cartSize == 0) {
unsigned char ngpRomMenu;
@@ -300,8 +299,7 @@ void scanChip_NGP() {
myFile.println("Warning: this cart is 32Mbits. Only the first 16Mbits chip will be scanned.");
myFile.println("");
addrMax = 2097152;
- }
- else
+ } else
addrMax = cartSize;
myFile.println("Sector | Start address | Status");
@@ -309,7 +307,7 @@ void scanChip_NGP() {
// browse sectors
for (uint32_t addr = 0; addr < addrMax; addr += 0x1000) {
- if ( (addr % 0x10000 == 0) || (addr == addrMax - 0x8000) || (addr == addrMax - 0x6000) || (addr == addrMax - 0x4000)) {
+ if ((addr % 0x10000 == 0) || (addr == addrMax - 0x8000) || (addr == addrMax - 0x6000) || (addr == addrMax - 0x4000)) {
myFile.print("#" + String(sectorID) + " | 0x" + String(addr, HEX) + " | ");
@@ -344,7 +342,8 @@ void writeByte_NGP(uint32_t addr, uint8_t data) {
PORTH |= data;
PORTH |= (1 << 5);
- NOP; NOP;
+ NOP;
+ NOP;
}
uint8_t readByte_NGP(uint32_t addr) {
@@ -361,7 +360,9 @@ uint8_t readByte_NGP(uint32_t addr) {
PORTH &= ~data;
PORTH &= ~(1 << 6);
- NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
data = PINC;
@@ -374,4 +375,4 @@ uint8_t readByte_NGP(uint32_t addr) {
#endif
//******************************************
// End of File
-//******************************************
+//****************************************** \ No newline at end of file
diff --git a/Cart_Reader/PCE.ino b/Cart_Reader/PCE.ino
index 9e8d98f..5c44f5a 100644
--- a/Cart_Reader/PCE.ino
+++ b/Cart_Reader/PCE.ino
@@ -42,7 +42,7 @@ void read_rom_PCE(void);
/******************************************
Variables
*****************************************/
-uint8_t pce_internal_mode; //0 - HuCARD, 1 - TurboChip
+uint8_t pce_internal_mode; //0 - HuCARD, 1 - TurboChip
uint16_t pce_force_rom_size = 0;
uint8_t tennokoe_bank_index = 0;
@@ -55,7 +55,7 @@ static const char pceMenuItem1[] PROGMEM = "HuCARD (swapped)";
static const char pceMenuItem2[] PROGMEM = "HuCARD(not swapped)";
static const char pceMenuItem3[] PROGMEM = "Turbochip";
static const char pceMenuItem4[] PROGMEM = "Reset";
-static const char* const menuOptionspce[] PROGMEM = {pceMenuItem1, pceMenuItem2, pceMenuItem3, pceMenuItem4};
+static const char *const menuOptionspce[] PROGMEM = { pceMenuItem1, pceMenuItem2, pceMenuItem3, pceMenuItem4 };
// PCE card menu items
static const char pceCartMenuItem1[] = "Read ROM";
@@ -70,7 +70,7 @@ static char menuOptionspceCart[7][20];
// Turbochip menu items
static const char pceTCMenuItem1[] PROGMEM = "Read ROM";
static const char pceTCMenuItem2[] PROGMEM = "Reset";
-static const char* const menuOptionspceTC[] PROGMEM = {pceTCMenuItem1, pceTCMenuItem2};
+static const char *const menuOptionspceTC[] PROGMEM = { pceTCMenuItem1, pceTCMenuItem2 };
// PCE start menu
void pcsMenu(void) {
@@ -81,8 +81,7 @@ void pcsMenu(void) {
pceDev = question_box(F("Select device"), menuOptions, 3, 0);
// wait for user choice to come back from the question box menu
- switch (pceDev)
- {
+ switch (pceDev) {
case 0:
//Hucard
display_Clear();
@@ -116,8 +115,7 @@ void pcsMenu(void) {
}
}
-void pin_read_write_PCE(void)
-{
+void pin_read_write_PCE(void) {
// Set Address Pins to Output
//A0-A7
DDRF = 0xFF;
@@ -153,8 +151,7 @@ void pin_read_write_PCE(void)
reset_cart_PCE();
}
-void pin_init_PCE(void)
-{
+void pin_init_PCE(void) {
//Set Address Pins to input and pull up
DDRF = 0x00;
@@ -175,61 +172,67 @@ void pin_init_PCE(void)
DDRC = 0x00;
// Enable Internal Pullups
PORTC = 0xFF;
-
}
-void setup_cart_PCE(void)
-{
+void setup_cart_PCE(void) {
// Set cicrstPin(PG1) to Output
DDRG |= (1 << 1);
// Output a high to disable CIC
PORTG |= (1 << 1);
pin_init_PCE();
-
}
-void reset_cart_PCE(void)
-{
+void reset_cart_PCE(void) {
//Set RESET as Low
PORTH &= ~(1 << 0);
delay(200);
//Set RESET as High
PORTH |= (1 << 0);
delay(200);
-
}
-void set_address_PCE(uint32_t address)
-{
+void set_address_PCE(uint32_t address) {
//Set address
PORTF = address & 0xFF;
PORTK = (address >> 8) & 0xFF;
PORTL = (PORTL & 0xF0) | ((address >> 16) & 0x0F);
}
-void set_cs_rd_low_PCE ()
-{
+void set_cs_rd_low_PCE() {
// Set CS(PL4) and RD(PH3) as LOW
PORTL &= ~(1 << 4);
PORTH &= ~(1 << 3);
}
-uint8_t read_byte_PCE(uint32_t address)
-{
+uint8_t read_byte_PCE(uint32_t address) {
uint8_t ret;
set_address_PCE(address);
// Arduino running at 16Mhz -> one nop = 62.5ns -> 1000ns total
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
//read byte
ret = PINC;
//Swap bit order for PC Engine HuCARD
- if (pce_internal_mode == HUCARD)
- {
+ if (pce_internal_mode == HUCARD) {
ret = ((ret & 0x01) << 7) | ((ret & 0x02) << 5) | ((ret & 0x04) << 3) | ((ret & 0x08) << 1) | ((ret & 0x10) >> 1) | ((ret & 0x20) >> 3) | ((ret & 0x40) >> 5) | ((ret & 0x80) >> 7);
}
@@ -237,12 +240,12 @@ uint8_t read_byte_PCE(uint32_t address)
return ret;
}
-void data_output_PCE () {
+void data_output_PCE() {
// Set Data Pins (D0-D7) to Output
DDRC = 0xFF;
}
-void data_input_PCE () {
+void data_input_PCE() {
// Set Data Pins (D0-D7) to Input
DDRC = 0x00;
// Enable Internal Pullups
@@ -251,17 +254,30 @@ void data_input_PCE () {
set_cs_rd_low_PCE();
}
-void write_byte_PCE(uint32_t address, uint8_t data)
-{
+void write_byte_PCE(uint32_t address, uint8_t data) {
//PORTH |= (1 << 3); // RD HIGH
set_address_PCE(address);
// Arduino running at 16Mhz -> one nop = 62.5ns -> 1000ns total
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
//Swap bit order for PC Engine HuCARD
- if (pce_internal_mode == HUCARD)
- {
+ if (pce_internal_mode == HUCARD) {
data = ((data & 0x01) << 7) | ((data & 0x02) << 5) | ((data & 0x04) << 3) | ((data & 0x08) << 1) | ((data & 0x10) >> 1) | ((data & 0x20) >> 3) | ((data & 0x40) >> 5) | ((data & 0x80) >> 7);
}
@@ -273,7 +289,22 @@ void write_byte_PCE(uint32_t address, uint8_t data)
PORTH &= ~(1 << 5);
// Arduino running at 16Mhz -> one nop = 62.5ns -> 1000ns total
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Set CS(PL4) and WR(PH5) as HIGH
PORTL |= (1 << 4);
@@ -281,8 +312,7 @@ void write_byte_PCE(uint32_t address, uint8_t data)
}
//Confirm the size of ROM - 128Kb, 256Kb, 384Kb, 512Kb, 768Kb or 1024Kb
-uint32_t detect_rom_size_PCE(void)
-{
+uint32_t detect_rom_size_PCE(void) {
uint32_t rom_size;
uint8_t read_byte;
uint8_t current_byte;
@@ -299,8 +329,7 @@ uint32_t detect_rom_size_PCE(void)
//Confirm where mirror address start from(128KB, 256KB, 512KB, 768, or 1024KB)
for (current_byte = 0; current_byte < DETECTION_SIZE; current_byte++) {
- if ((current_byte != detect_128) && (current_byte != detect_256) && (current_byte != detect_512) && (current_byte != detect_768))
- {
+ if ((current_byte != detect_128) && (current_byte != detect_256) && (current_byte != detect_512) && (current_byte != detect_768)) {
//If none matched, it is 1024KB
break;
}
@@ -309,38 +338,30 @@ uint32_t detect_rom_size_PCE(void)
read_byte = read_byte_PCE(current_byte);
//128KB detection
- if (current_byte == detect_128)
- {
- if (read_byte_PCE(current_byte + 128UL * 1024UL) == read_byte)
- {
+ if (current_byte == detect_128) {
+ if (read_byte_PCE(current_byte + 128UL * 1024UL) == read_byte) {
detect_128++;
}
}
//256KB detection
- if (current_byte == detect_256)
- {
- if (read_byte_PCE(current_byte + 256UL * 1024UL) == read_byte)
- {
+ if (current_byte == detect_256) {
+ if (read_byte_PCE(current_byte + 256UL * 1024UL) == read_byte) {
detect_256++;
}
}
//512KB detection
- if (current_byte == detect_512)
- {
- if (read_byte_PCE(current_byte + 512UL * 1024UL) == read_byte)
- {
+ if (current_byte == detect_512) {
+ if (read_byte_PCE(current_byte + 512UL * 1024UL) == read_byte) {
detect_512++;
}
}
//768KB detection
read_byte = read_byte_PCE(current_byte + 512UL * 1024UL);
- if (current_byte == detect_768)
- {
- if (read_byte_PCE(current_byte + 768UL * 1024UL) == read_byte)
- {
+ if (current_byte == detect_768) {
+ if (read_byte_PCE(current_byte + 768UL * 1024UL) == read_byte) {
detect_768++;
}
}
@@ -351,43 +372,29 @@ uint32_t detect_rom_size_PCE(void)
//println_Msg(fileName);
//ROM size detection by result
- if (detect_128 == DETECTION_SIZE)
- {
+ if (detect_128 == DETECTION_SIZE) {
rom_size = 128;
- }
- else if (detect_256 == DETECTION_SIZE)
- {
- if (detect_512 == DETECTION_SIZE)
- {
+ } else if (detect_256 == DETECTION_SIZE) {
+ if (detect_512 == DETECTION_SIZE) {
rom_size = 256;
- }
- else
- {
+ } else {
//rom_size = 1024;
//Another confirmation for 384KB because 384KB hucard has data in 0x0--0x40000 and 0x80000--0xA0000(0x40000 is mirror of 0x00000)
rom_size = 384;
}
- }
- else if (detect_512 == DETECTION_SIZE)
- {
+ } else if (detect_512 == DETECTION_SIZE) {
rom_size = 512;
- }
- else if (detect_768 == DETECTION_SIZE)
- {
+ } else if (detect_768 == DETECTION_SIZE) {
rom_size = 768;
- }
- else
- {
+ } else {
rom_size = 1024;
}
//If rom size is more than or equal to 512KB, detect Street fighter II'
- if (rom_size >= 512)
- {
+ if (rom_size >= 512) {
//Look for "NEC HE "
- if (read_byte_PCE(0x7FFF9) == 'N' && read_byte_PCE(0x7FFFA) == 'E' && read_byte_PCE(0x7FFFB) == 'C'
- && read_byte_PCE(0x7FFFC) == ' ' && read_byte_PCE(0x7FFFD) == 'H' && read_byte_PCE(0x7FFFE) == 'E')
- {
+ if (read_byte_PCE(0x7FFF9) == 'N' && read_byte_PCE(0x7FFFA) == 'E' && read_byte_PCE(0x7FFFB) == 'C'
+ && read_byte_PCE(0x7FFFC) == ' ' && read_byte_PCE(0x7FFFD) == 'H' && read_byte_PCE(0x7FFFE) == 'E') {
rom_size = 2560;
}
}
@@ -396,8 +403,7 @@ uint32_t detect_rom_size_PCE(void)
}
/* Must be address_start and address_end should be 512 byte aligned */
-void read_bank_PCE_ROM(uint32_t address_start, uint32_t address_end, uint32_t *processed_size, uint32_t total_size, uint32_t *crcp)
-{
+void read_bank_PCE_ROM(uint32_t address_start, uint32_t address_end, uint32_t *processed_size, uint32_t total_size, uint32_t *crcp) {
uint32_t currByte;
uint16_t c;
@@ -414,29 +420,26 @@ void read_bank_PCE_ROM(uint32_t address_start, uint32_t address_end, uint32_t *p
}
}
-void read_bank_PCE_RAM(uint32_t address_start, int block_index)
-{
+void read_bank_PCE_RAM(uint32_t address_start, int block_index) {
uint32_t start = address_start + block_index * 512;
for (uint16_t c = 0; c < 512; c++) {
sdBuffer[c] = read_byte_PCE(start + c);
}
}
-uint32_t calculate_crc32(int n, unsigned char c[], uint32_t r)
-{
+uint32_t calculate_crc32(int n, unsigned char c[], uint32_t r) {
int i, j;
for (i = 0; i < n; i++) {
r ^= c[i];
for (j = 0; j < 8; j++)
if (r & 1) r = (r >> 1) ^ 0xEDB88320UL;
- else r >>= 1;
+ else r >>= 1;
}
return r;
}
-void crc_search(char *file_p, char *folder_p, uint32_t rom_size, uint32_t crc)
-{
+void crc_search(char *file_p, char *folder_p, uint32_t rom_size, uint32_t crc) {
FsFile rom, script;
uint32_t r, processedsize;
char gamename[100];
@@ -445,16 +448,14 @@ void crc_search(char *file_p, char *folder_p, uint32_t rom_size, uint32_t crc)
flag = CHKSUM_SKIP;
//Open list file. If no list file found, just skip
- sd.chdir("/"); //Set read directry to root
- if (script.open("pce.txt", O_READ))
- {
+ sd.chdir("/"); //Set read directry to root
+ if (script.open("pce.txt", O_READ)) {
//Calculate CRC of ROM file
sd.chdir(folder_p);
- if (rom.open(file_p, O_READ))
- {
+ if (rom.open(file_p, O_READ)) {
//Initialize flag as error
flag = CHKSUM_ERROR;
- crc = crc ^ 0xFFFFFFFFUL; //Finish CRC calculation and progress bar
+ crc = crc ^ 0xFFFFFFFFUL; //Finish CRC calculation and progress bar
//Display calculated CRC
sprintf(crc_file, "%08lX", crc);
@@ -463,11 +464,10 @@ void crc_search(char *file_p, char *folder_p, uint32_t rom_size, uint32_t crc)
//Read 2 lines (game name and CRC)
get_line(gamename, &script, 96);
get_line(crc_search, &script, 9);
- skip_line(&script); //Skip every 3rd line
+ skip_line(&script); //Skip every 3rd line
//if checksum search successful, rename the file and end search
- if (strcmp(crc_search, crc_file) == 0)
- {
+ if (strcmp(crc_search, crc_file) == 0) {
print_Msg(F("Chksum OK "));
println_Msg(crc_file);
print_Msg(F("Saved to "));
@@ -486,15 +486,12 @@ void crc_search(char *file_p, char *folder_p, uint32_t rom_size, uint32_t crc)
}
- if (flag == CHKSUM_SKIP)
- {
+ if (flag == CHKSUM_SKIP) {
print_Msg(F("Saved to "));
print_Msg(folder_p);
print_Msg(F("/"));
print_Msg(file_p);
- }
- else if (flag == CHKSUM_ERROR)
- {
+ } else if (flag == CHKSUM_ERROR) {
print_Msg(F("Chksum Error "));
println_Msg(crc_file);
print_Msg(F("Saved to "));
@@ -504,27 +501,23 @@ void crc_search(char *file_p, char *folder_p, uint32_t rom_size, uint32_t crc)
}
script.close();
-
}
-void unlock_tennokoe_bank_RAM()
-{
- write_byte_PCE(0x0D0000, 0x68); //Unlock RAM sequence 1 Bank 68
- write_byte_PCE(0x0F0000, 0x00); //Unlock RAM sequence 2 Bank 78
- write_byte_PCE(0x0F0000, 0x73); //Unlock RAM sequence 3 Bank 78
- write_byte_PCE(0x0F0000, 0x73); //Unlock RAM sequence 4 Bank 78
- write_byte_PCE(0x0F0000, 0x73); //Unlock RAM sequence 5 Bank 78
+void unlock_tennokoe_bank_RAM() {
+ write_byte_PCE(0x0D0000, 0x68); //Unlock RAM sequence 1 Bank 68
+ write_byte_PCE(0x0F0000, 0x00); //Unlock RAM sequence 2 Bank 78
+ write_byte_PCE(0x0F0000, 0x73); //Unlock RAM sequence 3 Bank 78
+ write_byte_PCE(0x0F0000, 0x73); //Unlock RAM sequence 4 Bank 78
+ write_byte_PCE(0x0F0000, 0x73); //Unlock RAM sequence 5 Bank 78
}
-void lock_tennokoe_bank_RAM()
-{
- write_byte_PCE(0x0D0000, 0x68); //Lock RAM sequence 1 Bank 68
- write_byte_PCE(0x0F0001, 0x00); //Lock RAM sequence 2 Bank 78
- write_byte_PCE(0x0C0001, 0x60); //Lock RAM sequence 3 Bank 60
+void lock_tennokoe_bank_RAM() {
+ write_byte_PCE(0x0D0000, 0x68); //Lock RAM sequence 1 Bank 68
+ write_byte_PCE(0x0F0001, 0x00); //Lock RAM sequence 2 Bank 78
+ write_byte_PCE(0x0C0001, 0x60); //Lock RAM sequence 3 Bank 60
}
-void read_tennokoe_bank_PCE(int bank_index)
-{
+void read_tennokoe_bank_PCE(int bank_index) {
uint32_t processed_size = 0;
uint32_t verify_loop;
uint8_t verify_flag = 1;
@@ -599,8 +592,8 @@ void read_tennokoe_bank_PCE(int bank_index)
}
if (block_index == 0 && sdBuffer[2] == 0x42 && sdBuffer[3] == 0x4D) {
if (sdBuffer[0] != 0x48 || sdBuffer[1] != 0x55) {
- sdBuffer[0] = 0x48; // H
- sdBuffer[1] = 0x55; // U
+ sdBuffer[0] = 0x48; // H
+ sdBuffer[1] = 0x55; // U
println_Msg(F("Corrected header"));
} else {
println_Msg(F("Header is correct"));
@@ -613,11 +606,9 @@ void read_tennokoe_bank_PCE(int bank_index)
//Close the file:
myFile.close();
-
}
-void write_tennokoe_bank_PCE(int bank_index)
-{
+void write_tennokoe_bank_PCE(int bank_index) {
//Display file Browser and wait user to select a file. Size must be 2KB.
filePath[0] = '\0';
sd.chdir("/");
@@ -708,14 +699,12 @@ void write_tennokoe_bank_PCE(int bank_index)
println_Msg(F("Finished"));
display_Update();
wait();
- }
- else {
+ } else {
print_Error(F("File doesn't exist"), false);
}
}
-void read_rom_PCE(void)
-{
+void read_rom_PCE(void) {
uint32_t rom_size;
uint32_t processed_size = 0;
@@ -762,36 +751,31 @@ void read_rom_PCE(void)
//Initialize progress bar by setting processed size as 0
draw_progressbar(0, rom_size * 1024UL);
- uint32_t crc = 0xFFFFFFFFUL; //Initialize CRC
- if (rom_size == 384)
- {
+ uint32_t crc = 0xFFFFFFFFUL; //Initialize CRC
+ if (rom_size == 384) {
//Read two sections. 0x000000--0x040000 and 0x080000--0x0A0000 for 384KB
read_bank_PCE_ROM(0, 0x40000, &processed_size, rom_size * 1024UL, &crc);
read_bank_PCE_ROM(0x80000, 0xA0000, &processed_size, rom_size * 1024UL, &crc);
- }
- else if (rom_size == 2560)
- {
+ } else if (rom_size == 2560) {
//Dump Street fighter II' Champion Edition
read_bank_PCE_ROM(0, 0x80000, &processed_size, rom_size * 1024UL, &crc); //Read first bank
data_output_PCE();
- write_byte_PCE(0x1FF0, 0xFF); //Display second bank
+ write_byte_PCE(0x1FF0, 0xFF); //Display second bank
data_input_PCE();
- read_bank_PCE_ROM(0x80000, 0x100000, &processed_size, rom_size * 1024UL, &crc); //Read second bank
+ read_bank_PCE_ROM(0x80000, 0x100000, &processed_size, rom_size * 1024UL, &crc); //Read second bank
data_output_PCE();
- write_byte_PCE(0x1FF1, 0xFF); //Display third bank
+ write_byte_PCE(0x1FF1, 0xFF); //Display third bank
data_input_PCE();
- read_bank_PCE_ROM(0x80000, 0x100000, &processed_size, rom_size * 1024UL, &crc); //Read third bank
+ read_bank_PCE_ROM(0x80000, 0x100000, &processed_size, rom_size * 1024UL, &crc); //Read third bank
data_output_PCE();
- write_byte_PCE(0x1FF2, 0xFF); //Display forth bank
+ write_byte_PCE(0x1FF2, 0xFF); //Display forth bank
data_input_PCE();
- read_bank_PCE_ROM(0x80000, 0x100000, &processed_size, rom_size * 1024UL, &crc); //Read forth bank
+ read_bank_PCE_ROM(0x80000, 0x100000, &processed_size, rom_size * 1024UL, &crc); //Read forth bank
data_output_PCE();
- write_byte_PCE(0x1FF3, 0xFF); //Display fifth bank
+ write_byte_PCE(0x1FF3, 0xFF); //Display fifth bank
data_input_PCE();
- read_bank_PCE_ROM(0x80000, 0x100000, &processed_size, rom_size * 1024UL, &crc); //Read fifth bank
- }
- else
- {
+ read_bank_PCE_ROM(0x80000, 0x100000, &processed_size, rom_size * 1024UL, &crc); //Read fifth bank
+ } else {
//Read start form 0x000000 and keep reading until end of ROM
read_bank_PCE_ROM(0, rom_size * 1024UL, &processed_size, rom_size * 1024UL, &crc);
}
@@ -810,8 +794,7 @@ void pceMenu() {
// create menu with title and 7 options to choose from
unsigned char mainMenu;
- if (pce_internal_mode == HUCARD || pce_internal_mode == HUCARD_NOSWAP)
- {
+ if (pce_internal_mode == HUCARD || pce_internal_mode == HUCARD_NOSWAP) {
sprintf(pceCartMenuItem2, "Read RAM Bank %d", tennokoe_bank_index + 1);
sprintf(pceCartMenuItem3, "Write RAM Bank %d", tennokoe_bank_index + 1);
strcpy(menuOptionspceCart[0], pceCartMenuItem1);
@@ -829,8 +812,7 @@ void pceMenu() {
mainMenu = question_box(F("PCE HuCARD menu"), menuOptionspceCart, 7, 0);
// wait for user choice to come back from the question box menu
- switch (mainMenu)
- {
+ switch (mainMenu) {
case 0:
display_Clear();
// Change working dir to root
@@ -862,16 +844,13 @@ void pceMenu() {
pce_force_rom_size = 1024;
break;
}
- }
- else
- {
+ } else {
// Copy menuOptions out of progmem
convertPgm(menuOptionspceTC, 2);
mainMenu = question_box(F("TG TurboChip menu"), menuOptions, 2, 0);
// wait for user choice to come back from the question box menu
- switch (mainMenu)
- {
+ switch (mainMenu) {
case 0:
display_Clear();
// Change working dir to root
@@ -895,4 +874,4 @@ void pceMenu() {
//******************************************
// End of File
-//******************************************
+//****************************************** \ No newline at end of file
diff --git a/Cart_Reader/PCW.ino b/Cart_Reader/PCW.ino
index 1144d87..f0f0122 100644
--- a/Cart_Reader/PCW.ino
+++ b/Cart_Reader/PCW.ino
@@ -75,19 +75,23 @@
#define NAND_1A_HIGH PORTH |= (1 << 3)
#define NAND_1A_LOW PORTH &= ~(1 << 3)
#define NAND_1B_HIGH PORTH |= (1 << 4)
-#define NAND_1B_LOW PORTH &= ~(1 << 4) // Built-in RAM + I/O
+#define NAND_1B_LOW PORTH &= ~(1 << 4) // Built-in RAM + I/O
#define WE_HIGH PORTH |= (1 << 5)
#define WE_LOW PORTH &= ~(1 << 5)
#define OE_HIGH PORTH |= (1 << 6)
#define OE_LOW PORTH &= ~(1 << 6)
-#define MODE_READ DDRC = 0 // [INPUT]
-#define MODE_WRITE DDRC = 0xFF //[OUTPUT]
+#define MODE_READ DDRC = 0 // [INPUT]
+#define MODE_WRITE DDRC = 0xFF //[OUTPUT]
-#define DATA_READ { DDRC = 0; PORTC = 0xFF; } // [INPUT PULLUP]
-#define ADDR_WRITE DDRC = 0xFF // [OUTPUT]
+#define DATA_READ \
+ { \
+ DDRC = 0; \
+ PORTC = 0xFF; \
+ } // [INPUT PULLUP]
+#define ADDR_WRITE DDRC = 0xFF // [OUTPUT]
-boolean multipack = 0; // Multi-Pack Cart
+boolean multipack = 0; // Multi-Pack Cart
byte bank0;
byte bank1;
@@ -107,17 +111,17 @@ void setup_PCW() {
DDRH |= (1 << 0) | (1 << 1) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6);
// Set TIME(PJ0) to Output (UNUSED)
- DDRJ |= (1 << 0);
+ DDRJ |= (1 << 0);
// Set Address/Data Pins AD0-AD7 (PC0-PC7) to Input
- MODE_READ; // DDRC = 0
+ MODE_READ; // DDRC = 0
// Setting Control Pins to HIGH
// LE(PH0) ---(PH1) 1A(PH3) 1B(PH4) WE(PH5) OE(PH6)
PORTH |= (1 << 0) | (1 << 1) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6);
// Set Unused Pins HIGH
- PORTJ |= (1 << 0); // TIME(PJ0)
+ PORTJ |= (1 << 0); // TIME(PJ0)
// Multi-Pack Cart Check
check_multi_PCW();
@@ -134,15 +138,13 @@ static const char pcwmenuItem1[] PROGMEM = "Read ROM";
static const char pcwmenuItem2[] PROGMEM = "Read SRAM";
static const char pcwmenuItem3[] PROGMEM = "Write SRAM";
static const char pcwmenuItem4[] PROGMEM = "Reset";
-static const char* const menuOptionsPCW[] PROGMEM = {pcwmenuItem1, pcwmenuItem2, pcwmenuItem3, pcwmenuItem4};
+static const char* const menuOptionsPCW[] PROGMEM = { pcwmenuItem1, pcwmenuItem2, pcwmenuItem3, pcwmenuItem4 };
-void pcwMenu()
-{
+void pcwMenu() {
convertPgm(menuOptionsPCW, 4);
uint8_t mainMenu = question_box(F(" POCKET CHALLENGE W"), menuOptions, 4, 0);
- switch (mainMenu)
- {
+ switch (mainMenu) {
case 0:
// Read ROM
sd.chdir("/");
@@ -178,8 +180,7 @@ void pcwMenu()
if (writeErrors == 0) {
println_Msg(F("SRAM verified OK"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Error: "));
print_Msg(writeErrors);
println_Msg(F(" bytes "));
@@ -215,14 +216,15 @@ unsigned char read_rom_byte_PCW(unsigned long address) {
PORTK = (address >> 8) & 0xFF;
// Latch Address on AD0-AD7
ADDR_WRITE;
- LE_HIGH; // Latch Enable
- PORTC = address & 0xFF; // A0-A7
- LE_LOW; // Address Latched
- __asm__("nop\n\t""nop\n\t");
+ LE_HIGH; // Latch Enable
+ PORTC = address & 0xFF; // A0-A7
+ LE_LOW; // Address Latched
+ __asm__("nop\n\t"
+ "nop\n\t");
// Read Data on AD0-AD7
OE_LOW;
DATA_READ;
- delayMicroseconds(5); // 3+ Microseconds for Problem Carts
+ delayMicroseconds(5); // 3+ Microseconds for Problem Carts
unsigned char data = PINC;
OE_HIGH;
@@ -237,18 +239,33 @@ unsigned char read_ram_byte_1A_PCW(unsigned long address) {
PORTK = (address >> 8) & 0xFF;
// Latch Address on AD0-AD7
ADDR_WRITE;
- LE_HIGH; // Latch Enable
- PORTC = address & 0xFF; // A0-A7
- LE_LOW; // Address Latched
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ LE_HIGH; // Latch Enable
+ PORTC = address & 0xFF; // A0-A7
+ LE_LOW; // Address Latched
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read Data on AD0-AD7
OE_LOW;
DATA_READ;
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
unsigned char data = PINC;
OE_HIGH;
NAND_1A_HIGH;
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
return data;
}
@@ -267,18 +284,33 @@ unsigned char read_ram_byte_1B_PCW(unsigned long address) {
PORTK = (address >> 8) & 0xFF;
// Latch Address on AD0-AD7
ADDR_WRITE;
- LE_HIGH; // Latch Enable
- PORTC = address & 0xFF; // A0-A7
- LE_LOW; // Address Latched
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ LE_HIGH; // Latch Enable
+ PORTC = address & 0xFF; // A0-A7
+ LE_LOW; // Address Latched
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read Data on AD0-AD7
OE_LOW;
DATA_READ;
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
unsigned char data = PINC;
OE_HIGH;
NAND_1B_HIGH;
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
return data;
}
@@ -290,13 +322,16 @@ void write_ram_byte_1A_PCW(unsigned long address, unsigned char data) {
PORTK = (address >> 8) & 0xFF;
// Latch Address on AD0-AD7
ADDR_WRITE;
- LE_HIGH; // Latch Enable
- PORTC = address & 0xFF; // A0-A7
- LE_LOW; // Address Latched
+ LE_HIGH; // Latch Enable
+ PORTC = address & 0xFF; // A0-A7
+ LE_LOW; // Address Latched
// Write Data on AD0-AD7 - WE LOW ~240-248ns
WE_LOW;
PORTC = data;
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
WE_HIGH;
NAND_1A_HIGH;
}
@@ -311,14 +346,22 @@ void write_ram_byte_1B_PCW(unsigned long address, unsigned char data) {
PORTK = (address >> 8) & 0xFF;
// Latch Address on AD0-AD7
ADDR_WRITE;
- LE_HIGH; // Latch Enable
- PORTC = address & 0xFF; // A0-A7
- LE_LOW; // Address Latched
+ LE_HIGH; // Latch Enable
+ PORTC = address & 0xFF; // A0-A7
+ LE_LOW; // Address Latched
// Write Data on AD0-AD7 - WE LOW ~740ns
WE_LOW;
PORTC = data;
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
WE_HIGH;
NAND_1B_HIGH;
}
@@ -353,18 +396,18 @@ void write_ram_byte_1B_PCW(unsigned long address, unsigned char data) {
// MULTI-PACK CART CHECK
void check_multi_PCW() {
read_setup_PCW();
- byte tempbyte = read_rom_byte_PCW(0x3FFC); // Bank 0 Switch
+ byte tempbyte = read_rom_byte_PCW(0x3FFC); // Bank 0 Switch
if (tempbyte) {
- bank0 = tempbyte; // Store Bank 0 Switch
- tempbyte = read_rom_byte_PCW(0x3FFD); // Bank 1 Switch
+ bank0 = tempbyte; // Store Bank 0 Switch
+ tempbyte = read_rom_byte_PCW(0x3FFD); // Bank 1 Switch
if (tempbyte) {
- bank1 = tempbyte; // Store Bank 1 Switch
+ bank1 = tempbyte; // Store Bank 1 Switch
// Check for 00s
- tempbyte = read_rom_byte_PCW(0x3FFB); // Should be 00
+ tempbyte = read_rom_byte_PCW(0x3FFB); // Should be 00
if (!tempbyte) {
- tempbyte = read_rom_byte_PCW(0x3FFF); // Should be 00
+ tempbyte = read_rom_byte_PCW(0x3FFF); // Should be 00
if (!tempbyte)
- multipack = 1; // Flag Multi-Cart
+ multipack = 1; // Flag Multi-Cart
else {
bank0 = 0;
bank1 = 0;
@@ -380,26 +423,33 @@ void write_bank_byte_PCW(unsigned char data) {
NAND_1B_LOW;
// Write to Address 0xFFFF
PORTL = 0x00;
- PORTK = 0xFF; // A8-A15
+ PORTK = 0xFF; // A8-A15
// Latch Address on AD0-AD7
ADDR_WRITE;
- LE_HIGH; // Latch Enable
- PORTC = 0xFF; // A0-A7
- LE_LOW; // Address Latched
+ LE_HIGH; // Latch Enable
+ PORTC = 0xFF; // A0-A7
+ LE_LOW; // Address Latched
// Write Data on AD0-AD7 - WE LOW ~728-736ns
WE_LOW;
PORTC = data;
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
WE_HIGH;
NAND_1B_HIGH;
}
void switchBank_PCW(int bank) {
- if (bank == 1) { // Upper Half
+ if (bank == 1) { // Upper Half
write_bank_byte_PCW(bank1);
- }
- else { // Lower Half (default)
+ } else { // Lower Half (default)
write_bank_byte_PCW(bank0);
}
}
@@ -430,7 +480,7 @@ void readROM_PCW() {
print_Error(F("SD Error"), true);
}
read_setup_PCW();
- for (unsigned long address = 0; address < 0x400000; address += 512) { // 4MB
+ for (unsigned long address = 0; address < 0x400000; address += 512) { // 4MB
for (unsigned int x = 0; x < 512; x++) {
sdBuffer[x] = read_rom_byte_PCW(address + x);
}
@@ -478,7 +528,7 @@ void readMultiROM_PCW() {
read_setup_PCW();
// Lower Half
switchBank_PCW(0);
- for (unsigned long address = 0; address < 0x200000; address += 512) { // 2MB
+ for (unsigned long address = 0; address < 0x200000; address += 512) { // 2MB
for (unsigned int x = 0; x < 512; x++) {
sdBuffer[x] = read_rom_byte_PCW(address + x);
}
@@ -487,7 +537,7 @@ void readMultiROM_PCW() {
read_setup_PCW();
// Upper Half
switchBank_PCW(1);
- for (unsigned long address = 0x200000; address < 0x400000; address += 512) { // 2MB
+ for (unsigned long address = 0x200000; address < 0x400000; address += 512) { // 2MB
for (unsigned int x = 0; x < 512; x++) {
sdBuffer[x] = read_rom_byte_PCW(address + x);
}
@@ -513,7 +563,7 @@ void readMultiROM_PCW() {
// SRAM
//******************************************
-void readSRAM_PCW() { // readSRAM_1A()
+void readSRAM_PCW() { // readSRAM_1A()
strcpy(fileName, romName);
strcat(fileName, ".srm");
@@ -530,7 +580,7 @@ void readSRAM_PCW() { // readSRAM_1A()
}
display_Clear();
read_setup_PCW();
- for (unsigned long address = 0x0; address < 0x8000; address += 512) { // 32K
+ for (unsigned long address = 0x0; address < 0x8000; address += 512) { // 32K
for (unsigned int x = 0; x < 512; x++) {
sdBuffer[x] = read_ram_byte_1A_PCW(address + x);
}
@@ -563,7 +613,7 @@ void writeSRAM_PCW() {
//open file on sd card
if (myFile.open(filePath, O_READ)) {
read_setup_PCW();
- for (unsigned int address = 0x0; address < 0x8000; address += 512) { // 32K
+ for (unsigned int address = 0x0; address < 0x8000; address += 512) { // 32K
myFile.read(sdBuffer, 512);
for (unsigned int x = 0; x < 512; x++) {
write_ram_byte_1A_PCW(address + x, sdBuffer[x]);
@@ -572,12 +622,10 @@ void writeSRAM_PCW() {
myFile.close();
println_Msg(F("Done"));
display_Update();
- }
- else {
+ } else {
print_Error(F("SD Error"), true);
}
- }
- else {
+ } else {
print_Error(F("SD Error"), true);
}
display_Clear();
@@ -588,7 +636,7 @@ unsigned long verifySRAM_PCW() {
if (myFile.open(filePath, O_READ)) {
read_setup_PCW();
- for (unsigned int address = 0x0; address < 0x8000; address += 512) { // 32K
+ for (unsigned int address = 0x0; address < 0x8000; address += 512) { // 32K
for (unsigned int x = 0; x < 512; x++) {
byte myByte = read_ram_byte_1A_PCW(address + x);
sdBuffer[x] = myByte;
@@ -600,8 +648,7 @@ unsigned long verifySRAM_PCW() {
}
}
myFile.close();
- }
- else {
+ } else {
print_Error(F("SD Error"), true);
}
@@ -610,4 +657,4 @@ unsigned long verifySRAM_PCW() {
#endif
//******************************************
// End of File
-//******************************************
+//****************************************** \ No newline at end of file
diff --git a/Cart_Reader/SFM.ino b/Cart_Reader/SFM.ino
index 97a2fec..709ef8f 100644
--- a/Cart_Reader/SFM.ino
+++ b/Cart_Reader/SFM.ino
@@ -35,7 +35,7 @@ boolean hirom[8];
static const char sfmMenuItem1[] PROGMEM = "Game Menu";
static const char sfmMenuItem2[] PROGMEM = "Flash Menu";
static const char sfmMenuItem3[] PROGMEM = "Reset";
-static const char* const menuOptionsSFM[] PROGMEM = {sfmMenuItem1, sfmMenuItem2, sfmMenuItem3};
+static const char* const menuOptionsSFM[] PROGMEM = { sfmMenuItem1, sfmMenuItem2, sfmMenuItem3 };
// SFM flash menu items
static const char sfmFlashMenuItem1[] PROGMEM = "Read Flash";
@@ -44,7 +44,7 @@ static const char sfmFlashMenuItem3[] PROGMEM = "Print Mapping";
static const char sfmFlashMenuItem4[] PROGMEM = "Read Mapping";
static const char sfmFlashMenuItem5[] PROGMEM = "Write Mapping";
static const char sfmFlashMenuItem6[] PROGMEM = "Back";
-static const char* const menuOptionsSFMFlash[] PROGMEM = {sfmFlashMenuItem1, sfmFlashMenuItem2, sfmFlashMenuItem3, sfmFlashMenuItem4, sfmFlashMenuItem5, sfmFlashMenuItem6};
+static const char* const menuOptionsSFMFlash[] PROGMEM = { sfmFlashMenuItem1, sfmFlashMenuItem2, sfmFlashMenuItem3, sfmFlashMenuItem4, sfmFlashMenuItem5, sfmFlashMenuItem6 };
// SFM game menu items
static const char sfmGameMenuItem1[] PROGMEM = "Read Sram";
@@ -52,7 +52,7 @@ static const char sfmGameMenuItem2[] PROGMEM = "Read Game";
static const char sfmGameMenuItem3[] PROGMEM = "Write Sram";
static const char sfmGameMenuItem4[] PROGMEM = "Switch Game";
static const char sfmGameMenuItem5[] PROGMEM = "Reset";
-static const char* const menuOptionsSFMGame[] PROGMEM = {sfmGameMenuItem1, sfmGameMenuItem2, sfmGameMenuItem3, sfmGameMenuItem4, sfmGameMenuItem5};
+static const char* const menuOptionsSFMGame[] PROGMEM = { sfmGameMenuItem1, sfmGameMenuItem2, sfmGameMenuItem3, sfmGameMenuItem4, sfmGameMenuItem5 };
void sfmMenu() {
// create menu with title and 3 options to choose from
@@ -62,8 +62,7 @@ void sfmMenu() {
mainMenu = question_box(F("SF Memory"), menuOptions, 3, 0);
// wait for user choice to come back from the question box menu
- switch (mainMenu)
- {
+ switch (mainMenu) {
// Game menu
case 0:
sfmGameMenu();
@@ -127,8 +126,7 @@ void sfmGameMenu() {
// Print info
getCartInfo_SFM();
mode = mode_SFM_Game;
- }
- else {
+ } else {
// No menu so switch to only game
// Switch to game
send_SFM(0x80);
@@ -141,8 +139,7 @@ void sfmGameMenu() {
getCartInfo_SFM();
mode = mode_SFM_Game;
}
- }
- else {
+ } else {
print_Error(F("Switch to HiRom failed"), false);
}
}
@@ -155,8 +152,7 @@ void sfmGameOptions() {
gameSubMenu = question_box(F("SFM Game Menu"), menuOptions, 5, 0);
// wait for user choice to come back from the question box menu
- switch (gameSubMenu)
- {
+ switch (gameSubMenu) {
// Read sram
case 0:
display_Clear();
@@ -185,8 +181,7 @@ void sfmGameOptions() {
if (wrErrors == 0) {
println_Msg(F("Verified OK"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Error: "));
print_Msg(wrErrors);
println_Msg(F(" bytes "));
@@ -221,8 +216,7 @@ void sfmFlashMenu() {
flashSubMenu = question_box(F("SFM Flash Menu"), menuOptions, 6, 0);
// wait for user choice to come back from the question box menu
- switch (flashSubMenu)
- {
+ switch (flashSubMenu) {
// Read Flash
case 0:
// Clear screen
@@ -258,8 +252,7 @@ void sfmFlashMenu() {
// Read flash
readFlash_SFM();
- }
- else {
+ } else {
print_Error(F("Switch to HiRom failed"), false);
}
break;
@@ -328,16 +321,13 @@ void sfmFlashMenu() {
printMapping();
resetFlash_SFM(0xC0);
resetFlash_SFM(0xE0);
- }
- else {
+ } else {
print_Error(F("Error: Wrong Flash ID"), true);
}
- }
- else {
+ } else {
print_Error(F("Error: Wrong Flash ID"), true);
}
- }
- else {
+ } else {
print_Error(F("failed"), false);
}
break;
@@ -368,16 +358,13 @@ void sfmFlashMenu() {
readMapping();
resetFlash_SFM(0xC0);
resetFlash_SFM(0xE0);
- }
- else {
+ } else {
print_Error(F("Error: Wrong Flash ID"), true);
}
- }
- else {
+ } else {
print_Error(F("Error: Wrong Flash ID"), true);
}
- }
- else {
+ } else {
print_Error(F("failed"), false);
}
break;
@@ -410,8 +397,7 @@ void sfmFlashMenu() {
if (blankcheckMapping_SFM()) {
println_Msg(F("OK"));
display_Update();
- }
- else {
+ } else {
println_Msg(F("Nope"));
break;
}
@@ -458,7 +444,7 @@ void getGames() {
controlIn_SFM();
// Check if menu is present
- byte menuString[] = {0x4D, 0x45, 0x4E, 0x55, 0x20, 0x50, 0x52, 0x4F, 0x47, 0x52, 0x41, 0x4D};
+ byte menuString[] = { 0x4D, 0x45, 0x4E, 0x55, 0x20, 0x50, 0x52, 0x4F, 0x47, 0x52, 0x41, 0x4D };
for (int i = 0; i < 12; i++) {
if (menuString[i] != readBank_SFM(0xC0, 0x7FC0 + i)) {
hasMenu = false;
@@ -468,7 +454,7 @@ void getGames() {
if (hasMenu) {
// Count number of games
for (word i = 0x0000; i < 0xE000; i += 0x2000) {
- if (readBank_SFM(0xC6, i) == numGames )
+ if (readBank_SFM(0xC6, i) == numGames)
numGames++;
}
@@ -482,11 +468,9 @@ void getGames() {
//check if hirom
if (readBank_SFM(gameAddress[i], 0xFFD5) == 0x31) {
hirom[i] = true;
- }
- else if (readBank_SFM(gameAddress[i], 0xFFD5) == 0x21) {
+ } else if (readBank_SFM(gameAddress[i], 0xFFD5) == 0x21) {
hirom[i] = true;
- }
- else {
+ } else {
hirom[i] = false;
}
@@ -510,13 +494,11 @@ void getGames() {
// End char array in case game code is less than 9 chars
gameCode[i][myLength] = '\0';
}
- }
- else {
+ } else {
//check if hirom
if (readBank_SFM(0xC0, 0xFFD5) == 0x31) {
hirom[0] = true;
- }
- else {
+ } else {
hirom[0] = false;
}
@@ -537,8 +519,7 @@ void getGames() {
gameSize[0] = 1;
while (romSizeExp--)
gameSize[0] *= 2;
- }
- else {
+ } else {
gameVersion[0] = readBank_SFM(0xC0, 0x7FDB);
gameCode[0][0] = 'G';
gameCode[0][1] = 'A';
@@ -674,19 +655,56 @@ void writeBank_SFM(byte myBank, word myAddress, byte myData) {
// Arduino running at 16Mhz -> one nop = 62.5ns
// Wait till output is stable
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Switch WR(PH5) to LOW
PORTH &= ~(1 << 5);
// Leave WR low for at least 60ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Switch WR(PH5) to HIGH
PORTH |= (1 << 5);
// Leave WR high for at least 50ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
}
// Read one byte of data from a location specified by bank and address, 00:0000
@@ -696,7 +714,22 @@ byte readBank_SFM(byte myBank, word myAddress) {
PORTK = (myAddress >> 8) & 0xFF;
// Arduino running at 16Mhz -> one nop = 62.5ns -> 1000ns total
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read
byte tempByte = PINC;
@@ -781,10 +814,9 @@ boolean checkcart_SFM() {
romType = readBank_SFM(0, 0xFFD5);
if ((romType >> 5) != 1) { // Detect invalid romType byte due to too long ROM name (22 chars)
- romType = 0; // LoROM // Krusty's Super Fun House (U) 1.0 & Contra 3 (U)
- }
- else {
- romType &= 1; // Must be LoROM or HiROM
+ romType = 0; // LoROM // Krusty's Super Fun House (U) 1.0 & Contra 3 (U)
+ } else {
+ romType &= 1; // Must be LoROM or HiROM
}
// Check RomSize
@@ -846,8 +878,7 @@ boolean checkcart_SFM() {
sramSize = 1;
while (sramSizeExp--)
sramSize *= 2;
- }
- else {
+ } else {
sramSize = 0;
}
@@ -855,11 +886,10 @@ boolean checkcart_SFM() {
romVersion = readBank_SFM(0, 65499);
// Test if checksum is equal to reverse checksum
- if (((word(readBank_SFM(0, 65500)) + (word(readBank_SFM(0, 65501)) * 256)) + (word(readBank_SFM(0, 65502)) + (word(readBank_SFM(0, 65503)) * 256))) == 65535 ) {
+ if (((word(readBank_SFM(0, 65500)) + (word(readBank_SFM(0, 65501)) * 256)) + (word(readBank_SFM(0, 65502)) + (word(readBank_SFM(0, 65503)) * 256))) == 65535) {
if (strcmp("0000", checksumStr) == 0) {
return 0;
- }
- else {
+ } else {
return 1;
}
}
@@ -953,8 +983,7 @@ void resetFlash_SFM(int startBank) {
writeBank_SFM(startBank, 0x5555L * 2, 0xaa);
writeBank_SFM(startBank, 0x2AAAL * 2, 0x55);
writeBank_SFM(startBank, 0x5555L * 2, 0xf0);
- }
- else {
+ } else {
writeBank_SFM(1, 0x8000 + 0x1555L * 2, 0xaa);
writeBank_SFM(0, 0x8000 + 0x2AAAL * 2, 0x55);
writeBank_SFM(1, 0x8000 + 0x1555L * 2, 0xf0);
@@ -981,8 +1010,7 @@ void idFlash_SFM(int startBank) {
// Read the two id bytes into a string
sprintf(flashid, "%x%x", readBank_SFM(startBank, 0x00), readBank_SFM(startBank, 0x02));
- }
- else {
+ } else {
writeBank_SFM(1, 0x8000 + 0x1555L * 2, 0xaa);
writeBank_SFM(0, 0x8000 + 0x2AAAL * 2, 0x55);
writeBank_SFM(1, 0x8000 + 0x1555L * 2, 0x90);
@@ -1042,8 +1070,7 @@ void writeFlash_SFM(int startBank, uint32_t pos) {
busyCheck_SFM(startBank);
}
}
- }
- else {
+ } else {
// Write lorom
for (int currBank = 0; currBank < numBanks; currBank++) {
for (unsigned long currByte = 0x8000; currByte < 0x10000; currByte += 128) {
@@ -1070,8 +1097,7 @@ void writeFlash_SFM(int startBank, uint32_t pos) {
// Close the file:
myFile.close();
println_Msg("");
- }
- else {
+ } else {
print_Error(F("Can't open file on SD"), true);
}
}
@@ -1126,8 +1152,7 @@ void eraseFlash_SFM(int startBank) {
writeBank_SFM(startBank, 0x5555L * 2, 0xaa);
writeBank_SFM(startBank, 0x2AAAL * 2, 0x55);
writeBank_SFM(startBank, 0x5555L * 2, 0x10);
- }
- else {
+ } else {
writeBank_SFM(1, 0x8000 + 0x1555L * 2, 0xaa);
writeBank_SFM(0, 0x8000 + 0x2AAAL * 2, 0x55);
writeBank_SFM(1, 0x8000 + 0x1555L * 2, 0x80);
@@ -1153,13 +1178,12 @@ byte blankcheck_SFM(int startBank) {
for (int currBank = startBank; currBank < startBank + numBanks; currBank++) {
for (unsigned long currByte = 0; currByte < 0x10000; currByte++) {
if (readBank_SFM(currBank, currByte) != 0xFF) {
- currBank = startBank + numBanks;
+ currBank = startBank + numBanks;
blank = 0;
}
}
}
- }
- else {
+ } else {
for (int currBank = 0; currBank < numBanks; currBank++) {
for (unsigned long currByte = 0x8000; currByte < 0x10000; currByte++) {
if (readBank_SFM(currBank, currByte) != 0xFF) {
@@ -1174,7 +1198,7 @@ byte blankcheck_SFM(int startBank) {
// Check if a write succeeded, returns 0 if all is ok and number of errors if not
unsigned long verifyFlash_SFM(int startBank, uint32_t pos) {
- unsigned long verified = 0;
+ unsigned long verified = 0;
// Open file on sd card
if (myFile.open(filePath, O_READ)) {
@@ -1199,8 +1223,7 @@ unsigned long verifyFlash_SFM(int startBank, uint32_t pos) {
}
}
}
- }
- else {
+ } else {
for (int currBank = 0; currBank < numBanks; currBank++) {
for (unsigned long currByte = 0x8000; currByte < 0x10000; currByte += 512) {
// Fill SDBuffer
@@ -1215,8 +1238,7 @@ unsigned long verifyFlash_SFM(int startBank, uint32_t pos) {
}
// Close the file:
myFile.close();
- }
- else {
+ } else {
// SD Error
verified = 999999;
print_Error(F("Can't open file on SD"), false);
@@ -1250,8 +1272,7 @@ void readFlash_SFM() {
myFile.write(sdBuffer, 512);
}
}
- }
- else {
+ } else {
for (int currBank = 0; currBank < numBanks; currBank++) {
for (unsigned long currByte = 0x8000; currByte < 0x10000; currByte += 512) {
for (int c = 0; c < 512; c++) {
@@ -1320,7 +1341,7 @@ void printMapping() {
for (int currByte = 0xFF00; currByte < 0xFF50; currByte += 10) {
for (int c = 0; c < 10; c++) {
- itoa (readBank_SFM(0xC0, currByte + c), buffer, 16);
+ itoa(readBank_SFM(0xC0, currByte + c), buffer, 16);
for (int i = 0; i < 2 - strlen(buffer); i++) {
print_Msg(F("0"));
}
@@ -1469,12 +1490,10 @@ void eraseMapping(byte startBank) {
// Switch to read
dataIn();
controlIn_SFM();
- }
- else {
+ } else {
print_Error(F("Error: Wrong Flash ID"), true);
}
- }
- else {
+ } else {
print_Error(F("Unlock failed"), true);
}
}
@@ -1599,20 +1618,17 @@ void writeMapping_SFM(byte startBank, uint32_t pos) {
// Close the file:
myFile.close();
println_Msg("");
- }
- else {
+ } else {
print_Error(F("Can't open file on SD"), false);
}
// Switch to read
dataIn();
controlIn_SFM();
- }
- else {
+ } else {
print_Error(F("Error: Wrong Flash ID"), true);
}
- }
- else {
+ } else {
print_Error(F("Unlock failed"), true);
}
}
@@ -1636,14 +1652,12 @@ boolean unlockHirom() {
println_Msg(F("OK"));
display_Update();
return 1;
- }
- else {
+ } else {
println_Msg(F("failed"));
display_Update();
return 0;
}
- }
- else {
+ } else {
println_Msg(F("failed"));
display_Update();
return 0;
@@ -1709,8 +1723,7 @@ void write_SFM(int startBank, uint32_t pos) {
if (blankcheck_SFM(startBank)) {
println_Msg(F("OK"));
display_Update();
- }
- else {
+ } else {
println_Msg(F("Nope"));
display_Clear();
print_Msg(F("Erasing..."));
@@ -1723,8 +1736,7 @@ void write_SFM(int startBank, uint32_t pos) {
if (blankcheck_SFM(startBank)) {
println_Msg(F("OK"));
display_Update();
- }
- else {
+ } else {
print_Error(F("Could not erase flash"), true);
}
}
@@ -1741,19 +1753,16 @@ void write_SFM(int startBank, uint32_t pos) {
if (writeErrors == 0) {
println_Msg(F("OK"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Error: "));
print_Msg(writeErrors);
println_Msg(F(" bytes "));
print_Error(F("did not verify."), true);
}
- }
- else {
+ } else {
print_Error(F("Error: Wrong Flash ID"), true);
}
- }
- else {
+ } else {
print_Error(F("Unlock failed"), true);
}
}
@@ -1762,4 +1771,4 @@ void write_SFM(int startBank, uint32_t pos) {
//******************************************
// End of File
-//******************************************
+//****************************************** \ No newline at end of file
diff --git a/Cart_Reader/SMS.ino b/Cart_Reader/SMS.ino
index 39630e4..51a5b7f 100644
--- a/Cart_Reader/SMS.ino
+++ b/Cart_Reader/SMS.ino
@@ -12,7 +12,7 @@ static const char SMSAdapterItem2[] PROGMEM = "SG-1000 raphnet";
static const char SMSAdapterItem3[] PROGMEM = "SMS Retrode";
static const char SMSAdapterItem4[] PROGMEM = "GG Retrode";
static const char SMSAdapterItem5[] PROGMEM = "GG Retron 3in1";
-static const char* const menuAdapterSMS[] PROGMEM = {SMSAdapterItem1, SMSAdapterItem2, SMSAdapterItem3, SMSAdapterItem4, SMSAdapterItem5};
+static const char* const menuAdapterSMS[] PROGMEM = { SMSAdapterItem1, SMSAdapterItem2, SMSAdapterItem3, SMSAdapterItem4, SMSAdapterItem5 };
// MD menu items
static const char SMSMenuItem1[] PROGMEM = "Read Rom";
@@ -20,7 +20,7 @@ static const char SMSMenuItem2[] PROGMEM = "Read from SRAM";
static const char SMSMenuItem3[] PROGMEM = "Write to SRAM";
static const char SMSMenuItem4[] PROGMEM = "Reset";
static const char SMSMenuItem5[] PROGMEM = "Change Retrode Mode";
-static const char* const menuOptionsSMS[] PROGMEM = {SMSMenuItem1, SMSMenuItem2, SMSMenuItem3, SMSMenuItem4, SMSMenuItem5};
+static const char* const menuOptionsSMS[] PROGMEM = { SMSMenuItem1, SMSMenuItem2, SMSMenuItem3, SMSMenuItem4, SMSMenuItem5 };
// Rom Size menu
static const char SMSRomItem1[] PROGMEM = "8KB";
@@ -30,12 +30,12 @@ static const char SMSRomItem4[] PROGMEM = "32KB";
static const char SMSRomItem5[] PROGMEM = "40KB";
static const char SMSRomItem6[] PROGMEM = "48KB";
static const char SMSRomItem7[] PROGMEM = "512KB";
-static const char* const romOptionsSMS[] PROGMEM = {SMSRomItem1, SMSRomItem2, SMSRomItem3, SMSRomItem4, SMSRomItem5, SMSRomItem6, SMSRomItem7};
+static const char* const romOptionsSMS[] PROGMEM = { SMSRomItem1, SMSRomItem2, SMSRomItem3, SMSRomItem4, SMSRomItem5, SMSRomItem6, SMSRomItem7 };
// Set retrode_mode to true when using a retrode SMS/GG adapter
static bool retrode_mode = false;
-static bool retrode_mode_sms = false; // true: SMS/Mark3 false: GG
-static bool raphnet_mode_sg1000 = false; // true: SG-1000 false: SMS/Mark3
+static bool retrode_mode_sms = false; // true: SMS/Mark3 false: GG
+static bool raphnet_mode_sg1000 = false; // true: SG-1000 false: SMS/Mark3
static bool retron_mode = false;
@@ -48,21 +48,18 @@ void _smsMenu() {
int noptions = sizeof(menuOptionsSMS) / sizeof(menuOptionsSMS[0]);
convertPgm(menuOptionsSMS, noptions);
mainMenu = question_box(retrode_mode ? (retrode_mode_sms ? F("Retrode:SMS") : F("Retrode:GG")) : F("SMS/GG Retrode:NO"), menuOptions, noptions, 0);
- }
- else if (retron_mode) {
+ } else if (retron_mode) {
// Copy menuOptions out of progmem
convertPgm(menuOptionsSMS, 4);
mainMenu = question_box(F("Game Gear"), menuOptions, 4, 0);
- }
- else {
+ } else {
// Copy menuOptions out of progmem
- convertPgm(menuOptionsSMS, (raphnet_mode_sg1000 ? 1 : 4));
- mainMenu = question_box((raphnet_mode_sg1000 ? F("SG-1000") : F("SMS/Mark III") ), menuOptions, (raphnet_mode_sg1000 ? 1 : 4), 0);
+ convertPgm(menuOptionsSMS, (raphnet_mode_sg1000 ? 1 : 4));
+ mainMenu = question_box((raphnet_mode_sg1000 ? F("SG-1000") : F("SMS/Mark III")), menuOptions, (raphnet_mode_sg1000 ? 1 : 4), 0);
}
// wait for user choice to come back from the question box menu
- switch (mainMenu)
- {
+ switch (mainMenu) {
case 0:
display_Clear();
mode = mode_SMS;
@@ -72,8 +69,7 @@ void _smsMenu() {
readROM_SMS();
if ((retrode_mode && !retrode_mode_sms) || retron_mode) {
compareCRC("gg.txt", 0, 1, 0);
- }
- else {
+ } else {
compareCRC("sms.txt", 0, 1, 0);
}
#ifdef global_log
@@ -117,8 +113,7 @@ void _smsMenu() {
if (retrode_mode) {
println_Msg(retrode_mode ? (retrode_mode_sms ? F("Retrode Mode SMS") : F("Retrode Mode GG")) : F("Retrode Mode Off"));
println_Msg(F("Press Button..."));
- }
- else {
+ } else {
println_Msg(F(""));
println_Msg(F("Press Button..."));
}
@@ -134,8 +129,7 @@ void smsMenu() {
SMSAdapterMenu = question_box(F("Select System/Adapter"), menuOptions, 5, 0);
// wait for user choice to come back from the question box menu
- switch (SMSAdapterMenu)
- {
+ switch (SMSAdapterMenu) {
case 0:
// raphnet SMS/Mark3
retrode_mode = false;
@@ -267,7 +261,10 @@ void writeByte_SMS(word myAddress, byte myData) {
// Arduino running at 16Mhz -> one nop = 62.5ns
// Wait till output is stable
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
if (retrode_mode) {
// Switch WR(PL5) and OE/CE(PH6) to LOW
@@ -280,7 +277,10 @@ void writeByte_SMS(word myAddress, byte myData) {
}
// Leave WR low for at least 60ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
if (retrode_mode) {
// Switch WR(PL5) and OE/CE(PH6) to HIGH
@@ -293,7 +293,10 @@ void writeByte_SMS(word myAddress, byte myData) {
}
// Leave WR high for at least 50ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
if (retrode_mode && !retrode_mode_sms) {
// Set Data Pins (D8-D15) to Input
@@ -321,7 +324,10 @@ byte readByte_SMS(word myAddress) {
PORTH = (PORTH & 0b11110111) | ((myAddress >> 12) & 0b00001000);
}
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
if (retrode_mode) {
// Switch RD(PL6) and OE(PH6) to LOW
@@ -333,7 +339,10 @@ byte readByte_SMS(word myAddress) {
PORTH &= ~(1 << 6);
}
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read
byte tempByte = (retrode_mode && !retrode_mode_sms) ? PINA : PINC;
@@ -348,7 +357,10 @@ byte readByte_SMS(word myAddress) {
PORTL |= (1 << 1);
}
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
return tempByte;
}
@@ -372,38 +384,38 @@ void getCartInfo_SMS() {
switch (readNibble(readByte_SMS(0x7fff), 0)) {
case 0xa:
// Adding UL gets rid of integer overflow compiler warning
- cartSize = 8 * 1024UL;
+ cartSize = 8 * 1024UL;
break;
case 0xb:
- cartSize = 16 * 1024UL;
+ cartSize = 16 * 1024UL;
break;
case 0xc:
- cartSize = 32 * 1024UL;
+ cartSize = 32 * 1024UL;
break;
case 0xd:
- cartSize = 48 * 1024UL;
+ cartSize = 48 * 1024UL;
break;
case 0xe:
- cartSize = 64 * 1024UL;
+ cartSize = 64 * 1024UL;
break;
case 0xf:
- cartSize = 128 * 1024UL;
+ cartSize = 128 * 1024UL;
break;
case 0x0:
- cartSize = 256 * 1024UL;
+ cartSize = 256 * 1024UL;
break;
case 0x1:
- cartSize = 512 * 1024UL;
+ cartSize = 512 * 1024UL;
break;
case 0x2:
- cartSize = 512 * 1024UL;
+ cartSize = 512 * 1024UL;
break;
case 0x3:
// 0x3 is (only?) used in The Pro Yakyuu '91 (Game Gear)
- cartSize = 128 * 1024UL;
+ cartSize = 128 * 1024UL;
break;
default:
- cartSize = 48 * 1024UL;
+ cartSize = 48 * 1024UL;
// LED Error
setColor_RGB(0, 0, 255);
@@ -455,7 +467,7 @@ void getCartInfo_SMS() {
if (strcmp(headerFZ, "COPYRIGHT SEGAPRG. BY T.ASAI") == 0) {
strcpy(romName, "TMR SEGA");
- cartSize = 128 * 1024UL;
+ cartSize = 128 * 1024UL;
}
}
@@ -464,45 +476,44 @@ void getCartInfo_SMS() {
// Set cartsize manually
unsigned char SMSRomMenu;
// Copy menuOptions out of progmem
- convertPgm(romOptionsSMS, (raphnet_mode_sg1000 ? 4 : 7));
- SMSRomMenu = question_box(F("Select ROM size"), menuOptions, (raphnet_mode_sg1000 ? 4 : 7), 0);
+ convertPgm(romOptionsSMS, (raphnet_mode_sg1000 ? 4 : 7));
+ SMSRomMenu = question_box(F("Select ROM size"), menuOptions, (raphnet_mode_sg1000 ? 4 : 7), 0);
// wait for user choice to come back from the question box menu
- switch (SMSRomMenu)
- {
+ switch (SMSRomMenu) {
case 0:
// 8KB
- cartSize = 8 * 1024UL;
+ cartSize = 8 * 1024UL;
break;
case 1:
// 16KB
- cartSize = 16 * 1024UL;
+ cartSize = 16 * 1024UL;
break;
case 2:
// 24KB
- cartSize = 24 * 1024UL;
+ cartSize = 24 * 1024UL;
break;
case 3:
// 32KB
- cartSize = 32 * 1024UL;
+ cartSize = 32 * 1024UL;
break;
case 4:
// 40KB
- cartSize = 40 * 1024UL;
+ cartSize = 40 * 1024UL;
break;
case 5:
// 48KB
- cartSize = 48 * 1024UL;
+ cartSize = 48 * 1024UL;
break;
case 6:
// 512KB
- cartSize = 512 * 1024UL;
+ cartSize = 512 * 1024UL;
break;
}
@@ -523,8 +534,7 @@ void getCartInfo_SMS() {
display_Clear();
if ((retrode_mode && !retrode_mode_sms) || retron_mode) {
println_Msg(F("GG Header Info"));
- }
- else {
+ } else {
println_Msg(F("SMS Header Info"));
}
println_Msg(F(" "));
@@ -552,8 +562,7 @@ void readROM_SMS() {
strcpy(fileName, romName);
if ((retrode_mode && !retrode_mode_sms) || retron_mode) {
strcat(fileName, ".gg");
- }
- else {
+ } else {
strcat(fileName, ".sms");
}
@@ -561,8 +570,7 @@ void readROM_SMS() {
EEPROM_readAnything(0, foldern);
if ((retrode_mode && !retrode_mode_sms) || retron_mode) {
sprintf(folder, "GG/ROM/%s/%d", romName, foldern);
- }
- else {
+ } else {
sprintf(folder, "SMS/ROM/%s/%d", romName, foldern);
}
sd.mkdir(folder, true);
@@ -609,7 +617,7 @@ void readROM_SMS() {
for (word currBuffer = 0; currBuffer < bankSize; currBuffer += 512) {
// Fill SD buffer
for (int currByte = 0; currByte < 512; currByte++) {
- sdBuffer[currByte] = readByte_SMS((raphnet_mode_sg1000 || (cartSize == 32 * 1024UL) ? 0 : 0x8000) + currBuffer + currByte);
+ sdBuffer[currByte] = readByte_SMS((raphnet_mode_sg1000 || (cartSize == 32 * 1024UL) ? 0 : 0x8000) + currBuffer + currByte);
}
// hexdump for debugging:
// if (currBank == 0 && currBuffer == 0) {
@@ -647,8 +655,7 @@ void readSRAM_SMS() {
EEPROM_readAnything(0, foldern);
if ((retrode_mode && !retrode_mode_sms) || retron_mode) {
sprintf(folder, "GG/SAVE/%s/%d", romName, foldern);
- }
- else {
+ } else {
sprintf(folder, "SMS/SAVE/%s/%d", romName, foldern);
}
sd.mkdir(folder, true);
@@ -694,8 +701,7 @@ void writeSRAM_SMS() {
if (false) {
print_Error(F("DISABLED"), false);
- }
- else {
+ } else {
fileBrowser(F("Select file"));
sd.chdir();
@@ -736,19 +742,18 @@ void writeSRAM_SMS() {
println_Msg(F(""));
println_Msg(F("DONE"));
display_Update();
- }
- else {
+ } else {
print_Error(F("SD ERROR"), true);
}
}
display_Clear();
- sd.chdir(); // root
- filePath[0] = '\0'; // Reset filePath
+ sd.chdir(); // root
+ filePath[0] = '\0'; // Reset filePath
}
#endif
//******************************************
// End of File
-//******************************************
+//****************************************** \ No newline at end of file
diff --git a/Cart_Reader/SNES.ino b/Cart_Reader/SNES.ino
index 9856401..24d54d7 100644
--- a/Cart_Reader/SNES.ino
+++ b/Cart_Reader/SNES.ino
@@ -16,10 +16,10 @@
Variables
*****************************************/
// Define SNES Cart Reader Variables
-int romSpeed = 0; // 0 = SlowROM, 3 = FastROM
-int romChips = 0; // 0 = ROM only, 1 = ROM & RAM, 2 = ROM & Save RAM, 3 = ROM & DSP1, 4 = ROM & RAM & DSP1, 5 = ROM & Save RAM & DSP1, 19 = ROM & SFX
+int romSpeed = 0; // 0 = SlowROM, 3 = FastROM
+int romChips = 0; // 0 = ROM only, 1 = ROM & RAM, 2 = ROM & Save RAM, 3 = ROM & DSP1, 4 = ROM & RAM & DSP1, 5 = ROM & Save RAM & DSP1, 19 = ROM & SFX
// 227 = ROM & RAM & GameBoy data, 243 = CX4, 246 = ROM & DSP2
-byte romSizeExp = 0; // ROM-Size Exponent
+byte romSizeExp = 0; // ROM-Size Exponent
boolean NP = false;
byte cx4Type = 0;
byte cx4Map = 0;
@@ -36,10 +36,10 @@ static const char snsMenuItem4[] PROGMEM = "Flash repro";
#ifdef clockgen_calibration
static const char snsMenuItem5[] PROGMEM = "Calibrate Clock";
static const char snsMenuItem6[] PROGMEM = "Reset";
-static const char* const menuOptionsSNS[] PROGMEM = {snsMenuItem1, snsMenuItem2, snsMenuItem3, snsMenuItem4, snsMenuItem5, snsMenuItem6};
+static const char* const menuOptionsSNS[] PROGMEM = { snsMenuItem1, snsMenuItem2, snsMenuItem3, snsMenuItem4, snsMenuItem5, snsMenuItem6 };
#else
static const char snsMenuItem5[] PROGMEM = "Reset";
-static const char* const menuOptionsSNS[] PROGMEM = {snsMenuItem1, snsMenuItem2, snsMenuItem3, snsMenuItem4, snsMenuItem5};
+static const char* const menuOptionsSNS[] PROGMEM = { snsMenuItem1, snsMenuItem2, snsMenuItem3, snsMenuItem4, snsMenuItem5 };
#endif
// SNES menu items
@@ -50,7 +50,7 @@ static const char SnesMenuItem4[] PROGMEM = "Test SRAM";
static const char SnesMenuItem5[] PROGMEM = "Cycle cart";
static const char SnesMenuItem6[] PROGMEM = "Force cart type";
static const char SnesMenuItem7[] PROGMEM = "Reset";
-static const char* const menuOptionsSNES[] PROGMEM = {SnesMenuItem1, SnesMenuItem2, SnesMenuItem3, SnesMenuItem4, SnesMenuItem5, SnesMenuItem6, SnesMenuItem7};
+static const char* const menuOptionsSNES[] PROGMEM = { SnesMenuItem1, SnesMenuItem2, SnesMenuItem3, SnesMenuItem4, SnesMenuItem5, SnesMenuItem6, SnesMenuItem7 };
// Manual config menu items
static const char confMenuItem1[] PROGMEM = "Use header info";
@@ -58,7 +58,7 @@ static const char confMenuItem2[] PROGMEM = "4MB LoROM 256K SRAM";
static const char confMenuItem3[] PROGMEM = "4MB HiROM 64K SRAM";
static const char confMenuItem4[] PROGMEM = "6MB ExROM 256K SRAM";
static const char confMenuItem5[] PROGMEM = "Reset";
-static const char* const menuOptionsConfManual[] PROGMEM = {confMenuItem1, confMenuItem2, confMenuItem3, confMenuItem4, confMenuItem5};
+static const char* const menuOptionsConfManual[] PROGMEM = { confMenuItem1, confMenuItem2, confMenuItem3, confMenuItem4, confMenuItem5 };
// Repro menu items
static const char reproMenuItem1[] PROGMEM = "LoROM (P0)";
@@ -66,7 +66,7 @@ static const char reproMenuItem2[] PROGMEM = "HiROM (P0)";
static const char reproMenuItem3[] PROGMEM = "ExLoROM (P1)";
static const char reproMenuItem4[] PROGMEM = "ExHiROM (P1)";
static const char reproMenuItem5[] PROGMEM = "Reset";
-static const char* const menuOptionsRepro[] PROGMEM = {reproMenuItem1, reproMenuItem2, reproMenuItem3, reproMenuItem4, reproMenuItem5};
+static const char* const menuOptionsRepro[] PROGMEM = { reproMenuItem1, reproMenuItem2, reproMenuItem3, reproMenuItem4, reproMenuItem5 };
// SNES repro menu
void reproMenu() {
@@ -77,8 +77,7 @@ void reproMenu() {
snsRepro = question_box(F("Select Repro Type"), menuOptions, 5, 0);
// wait for user choice to come back from the question box menu
- switch (snsRepro)
- {
+ switch (snsRepro) {
#ifdef enable_FLASH
case 0:
// LoRom
@@ -145,8 +144,7 @@ void snsMenu() {
#endif
// wait for user choice to come back from the question box menu
- switch (snsCart)
- {
+ switch (snsCart) {
case 0:
display_Clear();
display_Update();
@@ -199,8 +197,7 @@ void snesMenu() {
mainMenu = question_box(F("SNES Cart Reader"), menuOptions, 7, 0);
// wait for user choice to come back from the question box menu
- switch (mainMenu)
- {
+ switch (mainMenu) {
case 0:
{
if (numBanks > 0) {
@@ -219,8 +216,7 @@ void snesMenu() {
save_log();
#endif
display_Update();
- }
- else {
+ } else {
display_Clear();
print_Error(F("Does not have ROM"), false);
}
@@ -233,8 +229,7 @@ void snesMenu() {
// Change working dir to root
sd.chdir("/");
readSRAM();
- }
- else {
+ } else {
display_Clear();
print_Error(F("Does not have SRAM"), false);
}
@@ -251,15 +246,13 @@ void snesMenu() {
if (wrErrors == 0) {
println_Msg(F("Verified OK"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Error: "));
print_Msg(wrErrors);
println_Msg(F(" bytes "));
print_Error(F("did not verify."), false);
}
- }
- else {
+ } else {
display_Clear();
print_Error(F("Does not have SRAM"), false);
}
@@ -288,15 +281,13 @@ void snesMenu() {
if (wrErrors == 0) {
println_Msg(F("Restored OK"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Error: "));
print_Msg(wrErrors);
println_Msg(F(" bytes "));
print_Error(F("did not verify."), false);
}
- }
- else {
+ } else {
display_Clear();
print_Error(F("Does not have SRAM"), false);
}
@@ -346,8 +337,7 @@ void confMenuManual() {
subMenu = question_box(F("Choose mapping"), menuOptions, 5, 0);
// wait for user choice to come back from the question box menu
- switch (subMenu)
- {
+ switch (subMenu) {
case 0:
break;
@@ -381,14 +371,14 @@ void confMenuManual() {
}
void stopSnesClocks_resetCic_resetCart() {
- DDRG |= (1 << 1); // Set cicrstPin(PG1) to Output
- PORTG |= (1 << 1); // pull high = reset CIC
- DDRH |= (1 << 0); // Set RST(PH0) pin to Output
- PORTH &= ~(1 << 0); // Switch RST(PH0) to LOW
+ DDRG |= (1 << 1); // Set cicrstPin(PG1) to Output
+ PORTG |= (1 << 1); // pull high = reset CIC
+ DDRH |= (1 << 0); // Set RST(PH0) pin to Output
+ PORTH &= ~(1 << 0); // Switch RST(PH0) to LOW
if (i2c_found) {
- clockgen.output_enable(SI5351_CLK1, 0); // CPU clock
- clockgen.output_enable(SI5351_CLK2, 0); // CIC clock
- clockgen.output_enable(SI5351_CLK0, 0); // master clock
+ clockgen.output_enable(SI5351_CLK1, 0); // CPU clock
+ clockgen.output_enable(SI5351_CLK2, 0); // CIC clock
+ clockgen.output_enable(SI5351_CLK0, 0); // master clock
}
}
@@ -460,14 +450,14 @@ void setup_Snes() {
if (i2c_found) {
// Set clocks to 4Mhz/1Mhz for better SA-1 unlocking
- clockgen.set_freq(100000000ULL, SI5351_CLK1); // CPU
- clockgen.set_freq(100000000ULL, SI5351_CLK2); // CIC
- clockgen.set_freq(400000000ULL, SI5351_CLK0); // EXT
+ clockgen.set_freq(100000000ULL, SI5351_CLK1); // CPU
+ clockgen.set_freq(100000000ULL, SI5351_CLK2); // CIC
+ clockgen.set_freq(400000000ULL, SI5351_CLK0); // EXT
// Start outputting master clock, CIC clock
- clockgen.output_enable(SI5351_CLK1, 0); // no CPU clock yet; seems to affect SA-1 success a lot
- clockgen.output_enable(SI5351_CLK2, 1); // CIC clock (should go before master clock)
- clockgen.output_enable(SI5351_CLK0, 1); // master clock
+ clockgen.output_enable(SI5351_CLK1, 0); // no CPU clock yet; seems to affect SA-1 success a lot
+ clockgen.output_enable(SI5351_CLK2, 1); // CIC clock (should go before master clock)
+ clockgen.output_enable(SI5351_CLK0, 1); // master clock
// Wait for clock generator
clockgen.update_status();
@@ -528,19 +518,56 @@ void writeBank_SNES(byte myBank, word myAddress, byte myData) {
// Arduino running at 16Mhz -> one nop = 62.5ns
// Wait till output is stable
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Switch WR(PH5) to LOW
PORTH &= ~(1 << 5);
// Leave WR low for at least 60ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Switch WR(PH5) to HIGH
PORTH |= (1 << 5);
// Leave WR high for at least 50ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
}
// Read one byte of data from a location specified by bank and address, 00:0000
@@ -553,15 +580,19 @@ byte readBank_SNES(byte myBank, word myAddress) {
// Arduino running at 16Mhz -> one nop = 62.5ns
// slowRom is good for 200ns, fastRom is <= 120ns; S-CPU best case read speed: 3.57MHz / 280ns
// let's be conservative and use 6 x 62.5 = 375ns
- NOP; NOP; NOP; NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
// Read
byte tempByte = PINC;
return tempByte;
}
-void readLoRomBanks( unsigned int start, unsigned int total, FsFile *file)
-{
+void readLoRomBanks(unsigned int start, unsigned int total, FsFile* file) {
byte buffer[1024] = { 0 };
uint16_t c = 0;
@@ -589,7 +620,12 @@ void readLoRomBanks( unsigned int start, unsigned int total, FsFile *file)
// Arduino running at 16Mhz -> one nop = 62.5ns
// slowRom is good for 200ns, fastRom is <= 120ns; S-CPU best case read speed: 3.57MHz / 280ns
// let's be conservative and use 6 x 62.5 = 375ns
- NOP; NOP; NOP; NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
buffer[c] = PINC;
c++;
@@ -607,8 +643,7 @@ void readLoRomBanks( unsigned int start, unsigned int total, FsFile *file)
}
}
-void readHiRomBanks( unsigned int start, unsigned int total, FsFile *file)
-{
+void readHiRomBanks(unsigned int start, unsigned int total, FsFile* file) {
byte buffer[1024] = { 0 };
uint16_t c = 0;
@@ -636,7 +671,12 @@ void readHiRomBanks( unsigned int start, unsigned int total, FsFile *file)
// Arduino running at 16Mhz -> one nop = 62.5ns
// slowRom is good for 200ns, fastRom is <= 120ns; S-CPU best case read speed: 3.57MHz / 280ns
// let's be conservative and use 6 x 62.5 = 375ns
- NOP; NOP; NOP; NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
buffer[c] = PINC;
c++;
@@ -673,7 +713,12 @@ void getCartInfo_SNES() {
// Arduino running at 16Mhz -> one nop = 62.5ns
// slowRom is good for 200ns, fastRom is <= 120ns; S-CPU best case read speed: 3.57MHz / 280ns
// let's be conservative and use 6 x 62.5 = 375ns
- NOP; NOP; NOP; NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
buffer[c] = PINC;
c++;
@@ -746,18 +791,14 @@ void getCartInfo_SNES() {
else if (romChips == 52) {
println_Msg(F("SA1 RAM"));
romType = SA;
- }
- else if (romChips == 53) {
+ } else if (romChips == 53) {
println_Msg(F("SA1 RAM BATT"));
romType = SA;
- }
- else if (romChips == 67) {
+ } else if (romChips == 67) {
println_Msg(F("SDD1"));
- }
- else if (romChips == 69) {
+ } else if (romChips == 69) {
println_Msg(F("SDD1 BATT"));
- }
- else if (romChips == 227)
+ } else if (romChips == 227)
println_Msg(F("RAM GBoy"));
else if (romChips == 243)
println_Msg(F("CX4"));
@@ -861,10 +902,10 @@ void checkAltConf(char crcStr[9]) {
myFile.seekSet(myFile.curPosition() + 1);
// Read number of banks
- byte numBanks2 = (myFile.read() - 48) * 100 + (myFile.read() - 48) * 10 + (myFile.read() - 48);
+ byte numBanks2 = (myFile.read() - 48) * 100 + (myFile.read() - 48) * 10 + (myFile.read() - 48);
// Some games have the same checksum, so compare CRC32 of header area with database too
- if (strcmp(tempStr3, crcStr) == 0) {
+ if (strcmp(tempStr3, crcStr) == 0) {
println_Msg(F(""));
println_Msg(F("Found"));
display_Update();
@@ -888,7 +929,7 @@ void checkAltConf(char crcStr[9]) {
display_Update();
delay(1000);
romSize = romSize2;
- numBanks = numBanks2;
+ numBanks = numBanks2;
altconf = 1;
}
break;
@@ -921,7 +962,18 @@ boolean checkcart_SNES() {
PORTF = (currByte & 0xFF);
PORTK = ((currByte >> 8) & 0xFF);
- NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
snesHeader[c] = PINC;
c++;
@@ -941,16 +993,13 @@ boolean checkcart_SNES() {
romType = snesHeader[0xFFD5 - headerStart];
if ((romType >> 5) != 1) { // Detect invalid romType byte due to too long ROM name (22 chars)
- romType = LO; // LoROM // Krusty's Super Fun House (U) 1.0 & Contra 3 (U)
- }
- else if (romType == 0x35) {
- romType = EX; // Check if ExHiROM
- }
- else if (romType == 0x3A) {
- romType = HI; // Check if SPC7110
- }
- else {
- romType &= 1; // Must be LoROM or HiROM
+ romType = LO; // LoROM // Krusty's Super Fun House (U) 1.0 & Contra 3 (U)
+ } else if (romType == 0x35) {
+ romType = EX; // Check if ExHiROM
+ } else if (romType == 0x3A) {
+ romType = HI; // Check if SPC7110
+ } else {
+ romType &= 1; // Must be LoROM or HiROM
}
// Check RomSpeed
@@ -963,32 +1012,26 @@ boolean checkcart_SNES() {
romSize = 48;
numBanks = 96;
romType = HI;
- }
- else if (romChips == 67) {
+ } else if (romChips == 67) {
romSize = 32;
numBanks = 64;
romType = HI;
- }
- else if (romChips == 243) {
+ } else if (romChips == 243) {
cx4Type = snesHeader[0xFFC9 - headerStart] & 0xF;
- if (cx4Type == 2) { // X2
+ if (cx4Type == 2) { // X2
romSize = 12;
numBanks = 48;
- }
- else if (cx4Type == 3) { // X3
+ } else if (cx4Type == 3) { // X3
romSize = 16;
numBanks = 64;
}
- }
- else if ((romChips == 245) && (romType == HI)) {
+ } else if ((romChips == 245) && (romType == HI)) {
romSize = 24;
numBanks = 48;
- }
- else if ((romChips == 249) && (romType == HI)) {
+ } else if ((romChips == 249) && (romType == HI)) {
romSize = 40;
numBanks = 80;
- }
- else {
+ } else {
// Check RomSize
byte romSizeExp = snesHeader[0xFFD7 - headerStart] - 7;
romSize = 1;
@@ -997,8 +1040,7 @@ boolean checkcart_SNES() {
if ((romType == EX) || (romType == SA)) {
numBanks = long(romSize) * 2;
- }
- else {
+ } else {
numBanks = (long(romSize) * 1024 * 1024 / 8) / (32768 + (long(romType) * 32768));
}
}
@@ -1062,17 +1104,14 @@ boolean checkcart_SNES() {
// SuperFX
if (snesHeader[0x7FDA - headerStart] == 0x33) {
sramSizeExp = snesHeader[0x7FBD - headerStart];
- }
- else {
+ } else {
if (strncmp(romName, "STARFOX2", 8) == 0) {
sramSizeExp = 6;
- }
- else {
+ } else {
sramSizeExp = 5;
}
}
- }
- else {
+ } else {
// No SuperFX
sramSizeExp = snesHeader[0xFFD8 - headerStart];
}
@@ -1084,8 +1123,7 @@ boolean checkcart_SNES() {
sramSize = 1;
while (sramSizeExp--)
sramSize *= 2;
- }
- else {
+ } else {
sramSize = 0;
}
@@ -1096,11 +1134,10 @@ boolean checkcart_SNES() {
romVersion = snesHeader[0xFFDB - headerStart];
// Test if checksum is equal to reverse checksum
- if (((word(snesHeader[0xFFDC - headerStart]) + (word(snesHeader[0xFFDD - headerStart]) * 256)) + (word(snesHeader[0xFFDE - headerStart]) + (word(snesHeader[0xFFDF - headerStart]) * 256))) == 65535 ) {
+ if (((word(snesHeader[0xFFDC - headerStart]) + (word(snesHeader[0xFFDD - headerStart]) * 256)) + (word(snesHeader[0xFFDE - headerStart]) + (word(snesHeader[0xFFDF - headerStart]) * 256))) == 65535) {
if (strcmp("0000", checksumStr) == 0) {
return 0;
- }
- else {
+ } else {
return 1;
}
}
@@ -1110,7 +1147,7 @@ boolean checkcart_SNES() {
}
}
-unsigned int calc_checksum (char* fileName, char* folder) {
+unsigned int calc_checksum(char* fileName, char* folder) {
unsigned int calcChecksum = 0;
unsigned int calcChecksumChunk = 0;
int calcFilesize = 0;
@@ -1135,9 +1172,8 @@ unsigned int calc_checksum (char* fileName, char* folder) {
}
calcChecksum = calcChecksumChunk;
}
- calcChecksum += 0xF47C; // FFs from 0x60000-0x80000
- }
- else if ((calcFilesize == 10) || (calcFilesize == 12) || (calcFilesize == 20) || (calcFilesize == 24)) {
+ calcChecksum += 0xF47C; // FFs from 0x60000-0x80000
+ } else if ((calcFilesize == 10) || (calcFilesize == 12) || (calcFilesize == 20) || (calcFilesize == 24)) {
unsigned long calcBase = 0;
unsigned long calcMirror = 0;
byte calcMirrorCount = 0;
@@ -1157,8 +1193,7 @@ unsigned int calc_checksum (char* fileName, char* folder) {
}
}
calcChecksum = 2 * calcChecksumChunk;
- }
- else {
+ } else {
// Base 8/16 Mbit chunk
for (j = 0; j < (calcBase / 512); j++) {
myFile.read(sdBuffer, 512);
@@ -1175,10 +1210,9 @@ unsigned int calc_checksum (char* fileName, char* folder) {
calcChecksumChunk += sdBuffer[c];
}
}
- calcChecksum += calcMirrorCount * calcChecksumChunk;
+ calcChecksum += calcMirrorCount * calcChecksumChunk;
}
- }
- else if ((calcFilesize == 40) && (romChips == 85)) {
+ } else if ((calcFilesize == 40) && (romChips == 85)) {
// Daikaijuu Monogatari 2 Fix 5MB (40Mbit)
// Add the 4MB (32Mbit) start
for (j = 0; j < (4194304 / 512); j++) {
@@ -1196,9 +1230,8 @@ unsigned int calc_checksum (char* fileName, char* folder) {
calcChecksumChunk += sdBuffer[c];
}
}
- calcChecksum += 4 * calcChecksumChunk;
- }
- else if (calcFilesize == 48) {
+ calcChecksum += 4 * calcChecksumChunk;
+ } else if (calcFilesize == 48) {
// Star Ocean/Tales of Phantasia Fix 6MB (48Mbit)
// Add the 4MB (32Mbit) start
for (j = 0; j < (4194304 / 512); j++) {
@@ -1216,9 +1249,8 @@ unsigned int calc_checksum (char* fileName, char* folder) {
calcChecksumChunk += sdBuffer[c];
}
}
- calcChecksum += 2 * calcChecksumChunk;
- }
- else {
+ calcChecksum += 2 * calcChecksumChunk;
+ } else {
//calcFilesize == 2 || 4 || 8 || 16 || 32 || 40 || etc
for (i = 0; i < (myFile.fileSize() / 512); i++) {
myFile.read(sdBuffer, 512);
@@ -1231,8 +1263,7 @@ unsigned int calc_checksum (char* fileName, char* folder) {
myFile.close();
sd.chdir();
return (calcChecksum);
- }
- else {
+ } else {
// Else show error
print_Error(F("DUMP ROM 1ST"), false);
return 0;
@@ -1258,8 +1289,7 @@ boolean compare_checksum() {
println_Msg(F(" -> OK"));
display_Update();
return 1;
- }
- else {
+ } else {
print_Msg(F(" != "));
println_Msg(checksumStr);
print_Error(F("Invalid Checksum"), false);
@@ -1326,35 +1356,34 @@ void readROM_SNES() {
//Dump Low-type ROM
else if (romType == LO) {
- if (romChips == 243) { //0xF3
- cx4Map = readBank_SNES(0, 32594); //0x7F52
- if ((cx4Type == 2) && (cx4Map != 0)) { //X2
+ if (romChips == 243) { //0xF3
+ cx4Map = readBank_SNES(0, 32594); //0x7F52
+ if ((cx4Type == 2) && (cx4Map != 0)) { //X2
dataOut();
controlOut_SNES();
- writeBank_SNES(0, 32594, 0); // Set 0x7F52 to 0
+ writeBank_SNES(0, 32594, 0); // Set 0x7F52 to 0
dataIn();
controlIn_SNES();
- }
- else if ((cx4Type == 3) && (cx4Map == 0)) { //X3
+ } else if ((cx4Type == 3) && (cx4Map == 0)) { //X3
dataOut();
controlOut_SNES();
- writeBank_SNES(0, 32594, 1); // Set 0x7F52 to 1
+ writeBank_SNES(0, 32594, 1); // Set 0x7F52 to 1
dataIn();
controlIn_SNES();
}
}
if (romSize > 24) {
// ROM > 96 banks (up to 128 banks)
- readLoRomBanks( 0x80, numBanks + 0x80, &myFile );
+ readLoRomBanks(0x80, numBanks + 0x80, &myFile);
} else {
// Read up to 96 banks starting at bank 0×00.
- readLoRomBanks( 0, numBanks, &myFile );
+ readLoRomBanks(0, numBanks, &myFile);
}
- if (romChips == 243) { //0xF3
+ if (romChips == 243) { //0xF3
// Restore CX4 Mapping Register
dataOut();
controlOut_SNES();
- writeBank_SNES(0, 32594, cx4Map); // 0x7F52
+ writeBank_SNES(0, 32594, cx4Map); // 0x7F52
dataIn();
controlIn_SNES();
}
@@ -1377,7 +1406,7 @@ void readROM_SNES() {
dataIn();
controlIn_SNES();
- readHiRomBanks( 240, 256, &myFile );
+ readHiRomBanks(240, 256, &myFile);
if (currMemmap == 2) display_Clear(); // need more space for the progress bars
}
@@ -1398,13 +1427,13 @@ void readROM_SNES() {
// 0xC00000-0xDFFFFF
//print_Msg(F("Part 1"));
display_Update();
- readHiRomBanks( 192, 224, &myFile );
+ readHiRomBanks(192, 224, &myFile);
if (numBanks > 32) {
dataOut();
controlOut_SNES();
// Set 0x4834 to 0xFF
- writeBank_SNES( 0, 0x4834, 0xFF );
+ writeBank_SNES(0, 0x4834, 0xFF);
dataIn();
controlIn_SNES();
@@ -1412,19 +1441,19 @@ void readROM_SNES() {
// 0xE00000-0xEFFFFF
//print_Msg(F(" 2"));
display_Update();
- readHiRomBanks( 224, 240, &myFile );
+ readHiRomBanks(224, 240, &myFile);
if (numBanks > 48) {
// 0xF00000-0xFFFFFF
//print_Msg(F(" 3"));
display_Update();
- readHiRomBanks( 240, 256, &myFile );
+ readHiRomBanks(240, 256, &myFile);
dataOut();
controlOut_SNES();
// Set 0x4833 to 3
- writeBank_SNES( 0, 0x4833, 3 );
+ writeBank_SNES(0, 0x4833, 3);
dataIn();
controlIn_SNES();
@@ -1432,7 +1461,7 @@ void readROM_SNES() {
// 0xF00000-0xFFFFFF
//print_Msg(F(" 4"));
display_Update();
- readHiRomBanks( 240, 256, &myFile );
+ readHiRomBanks(240, 256, &myFile);
}
//println_Msg(F(""));
display_Clear(); // need more space due to the 4 progress bars
@@ -1441,8 +1470,8 @@ void readROM_SNES() {
dataOut();
controlOut_SNES();
- writeBank_SNES( 0, 0x4833, 2 );
- writeBank_SNES( 0, 0x4834, 0 );
+ writeBank_SNES(0, 0x4833, 2);
+ writeBank_SNES(0, 0x4834, 0);
dataIn();
controlIn_SNES();
@@ -1454,7 +1483,7 @@ void readROM_SNES() {
println_Msg(F("Dumping HiRom..."));
display_Update();
- readHiRomBanks( 192, numBanks + 192, &myFile );
+ readHiRomBanks(192, numBanks + 192, &myFile);
}
// Close the file:
@@ -1465,7 +1494,7 @@ void readROM_SNES() {
SNES SRAM Functions
*****************************************/
// Write file to SRAM
-void writeSRAM (boolean browseFile) {
+void writeSRAM(boolean browseFile) {
if (browseFile) {
filePath[0] = '\0';
sd.chdir("/");
@@ -1473,8 +1502,7 @@ void writeSRAM (boolean browseFile) {
// Create filepath
sprintf(filePath, "%s/%s", filePath, fileName);
display_Clear();
- }
- else
+ } else
sprintf(filePath, "%s", fileName);
//open file on sd card
@@ -1492,38 +1520,35 @@ void writeSRAM (boolean browseFile) {
// Sram size
long lastByte = (long(sramSize) * 128);
- if ((romChips == 19) || (romChips == 20) || (romChips == 21) || (romChips == 26)) { // SuperFX
- if (lastByte > 0x10000) { // Large SuperFX SRAM (no known carts)
+ if ((romChips == 19) || (romChips == 20) || (romChips == 21) || (romChips == 26)) { // SuperFX
+ if (lastByte > 0x10000) { // Large SuperFX SRAM (no known carts)
sramBanks = lastByte / 0x10000;
for (int currBank = 0x70; currBank < sramBanks + 0x70; currBank++) {
for (long currByte = 0x0000; currByte < 0x10000; currByte++) {
writeBank_SNES(currBank, currByte, myFile.read());
}
}
- }
- else { // SuperFX SRAM
+ } else { // SuperFX SRAM
for (long currByte = 0; currByte < lastByte; currByte++) {
writeBank_SNES(0x70, currByte, myFile.read());
}
}
- }
- else if (lastByte > 0x8000) { // Large SRAM Fix
+ } else if (lastByte > 0x8000) { // Large SRAM Fix
sramBanks = lastByte / 0x8000;
for (int currBank = 0x70; currBank < sramBanks + 0x70; currBank++) {
for (long currByte = 0x0000; currByte < 0x8000; currByte++) {
writeBank_SNES(currBank, currByte, myFile.read());
}
}
- }
- else {
- for (long currByte = 0; currByte < lastByte; currByte++) {
+ } else {
+ for (long currByte = 0; currByte < lastByte; currByte++) {
writeBank_SNES(0x70, currByte, myFile.read());
}
}
}
// HiRom
else if (romType == HI) {
- if ((romChips == 245) || (romChips == 249)) { // SPC7110 SRAM
+ if ((romChips == 245) || (romChips == 249)) { // SPC7110 SRAM
// Configure SPC7110 SRAM Register
// Set 0x4830 to 0x80
writeBank_SNES(0, 0x4830, 0x80);
@@ -1538,21 +1563,19 @@ void writeSRAM (boolean browseFile) {
// Reset 0x4830 to 0x0
writeBank_SNES(0, 0x4830, 0);
dataIn();
- }
- else {
+ } else {
// Writing SRAM on HiRom needs CS(PH3) to be high
- PORTH |= (1 << 3);
+ PORTH |= (1 << 3);
// Sram size
long lastByte = (long(sramSize) * 128);
- if (lastByte > 0x2000) { // Large SRAM Fix
+ if (lastByte > 0x2000) { // Large SRAM Fix
sramBanks = lastByte / 0x2000;
for (int currBank = 0x30; currBank < sramBanks + 0x30; currBank++) {
for (long currByte = 0x6000; currByte < 0x8000; currByte++) {
writeBank_SNES(currBank, currByte, myFile.read());
}
}
- }
- else {
+ } else {
lastByte += 0x6000;
// Write to sram bank
for (long currByte = 0x6000; currByte < lastByte; currByte++) {
@@ -1564,7 +1587,7 @@ void writeSRAM (boolean browseFile) {
// ExHiRom
else if (romType == EX) {
// Writing SRAM on HiRom needs CS(PH3) to be high
- PORTH |= (1 << 3);
+ PORTH |= (1 << 3);
// Sram size
long lastByte = (long(sramSize) * 128) + 0x6000;
for (long currByte = 0x6000; currByte < lastByte; currByte++) {
@@ -1632,13 +1655,12 @@ void writeSRAM (boolean browseFile) {
println_Msg(F("SRAM writing finished"));
display_Update();
- }
- else {
+ } else {
print_Error(F("File doesnt exist"), false);
}
}
-void readSRAM () {
+void readSRAM() {
// set control
controlIn_SNES();
@@ -1664,37 +1686,33 @@ void readSRAM () {
if (romType == LO) {
// Sram size
long lastByte = (long(sramSize) * 128);
- if ((romChips == 19) || (romChips == 20) || (romChips == 21) || (romChips == 26)) { // SuperFX
- if (lastByte > 0x10000) { // Large SuperFX SRAM (no known carts)
+ if ((romChips == 19) || (romChips == 20) || (romChips == 21) || (romChips == 26)) { // SuperFX
+ if (lastByte > 0x10000) { // Large SuperFX SRAM (no known carts)
sramBanks = lastByte / 0x10000;
for (int currBank = 0x70; currBank < sramBanks + 0x70; currBank++) {
for (long currByte = 0x0000; currByte < 0x10000; currByte++) {
myFile.write(readBank_SNES(currBank, currByte));
}
}
- }
- else { // SuperFX SRAM
+ } else { // SuperFX SRAM
for (long currByte = 0; currByte < lastByte; currByte++) {
myFile.write(readBank_SNES(0x70, currByte));
}
}
- }
- else if (lastByte > 0x8000) { // Large SRAM Fix
+ } else if (lastByte > 0x8000) { // Large SRAM Fix
sramBanks = lastByte / 0x8000;
for (int currBank = 0x70; currBank < sramBanks + 0x70; currBank++) {
for (long currByte = 0x0000; currByte < 0x8000; currByte++) {
myFile.write(readBank_SNES(currBank, currByte));
}
}
- }
- else {
+ } else {
for (long currByte = 0; currByte < lastByte; currByte++) {
myFile.write(readBank_SNES(0x70, currByte));
}
}
- }
- else if (romType == HI) {
- if ((romChips == 245) || (romChips == 249)) { // SPC7110 SRAM
+ } else if (romType == HI) {
+ if ((romChips == 245) || (romChips == 249)) { // SPC7110 SRAM
// Configure SPC7110 SRAM Register
dataOut();
// Set 0x4830 to 0x80
@@ -1709,40 +1727,36 @@ void readSRAM () {
// Reset 0x4830 to 0x0
writeBank_SNES(0, 0x4830, 0);
dataIn();
- }
- else {
+ } else {
// Dumping SRAM on HiRom needs CS(PH3) to be high
- PORTH |= (1 << 3);
+ PORTH |= (1 << 3);
// Sram size
long lastByte = (long(sramSize) * 128);
- if (lastByte > 0x2000) { // Large SRAM Fix
+ if (lastByte > 0x2000) { // Large SRAM Fix
sramBanks = lastByte / 0x2000;
for (int currBank = 0x30; currBank < sramBanks + 0x30; currBank++) {
for (long currByte = 0x6000; currByte < 0x8000; currByte++) {
myFile.write(readBank_SNES(currBank, currByte));
}
}
- }
- else {
+ } else {
lastByte += 0x6000;
for (long currByte = 0x6000; currByte < lastByte; currByte++) {
myFile.write(readBank_SNES(0x30, currByte));
}
}
}
- }
- else if (romType == EX) {
+ } else if (romType == EX) {
// Dumping SRAM on HiRom needs CS(PH3) to be high
- PORTH |= (1 << 3);
+ PORTH |= (1 << 3);
// Sram size
long lastByte = (long(sramSize) * 128) + 0x6000;
for (long currByte = 0x6000; currByte < lastByte; currByte++) {
myFile.write(readBank_SNES(0xB0, currByte));
}
- }
- else if (romType == SA) {
+ } else if (romType == SA) {
// Dumping SRAM on HiRom needs CS(PH3) to be high
- PORTH |= (1 << 3);
+ PORTH |= (1 << 3);
// Sram size
long lastByte = (long(sramSize) * 128);
if (lastByte > 0x10000) {
@@ -1752,8 +1766,7 @@ void readSRAM () {
myFile.write(readBank_SNES(currBank, currByte));
}
}
- }
- else {
+ } else {
for (long currByte = 0x0; currByte < lastByte; currByte++) {
myFile.write(readBank_SNES(0x40, currByte));
}
@@ -1786,8 +1799,8 @@ unsigned long verifySRAM() {
if (romType == LO) {
// Sram size
long lastByte = (long(sramSize) * 128);
- if ((romChips == 19) || (romChips == 20) || (romChips == 21) || (romChips == 26)) { // SuperFX
- if (lastByte > 0x10000) { // Large SuperFX SRAM (no known carts)
+ if ((romChips == 19) || (romChips == 20) || (romChips == 21) || (romChips == 26)) { // SuperFX
+ if (lastByte > 0x10000) { // Large SuperFX SRAM (no known carts)
sramBanks = lastByte / 0x10000;
for (int currBank = 0x70; currBank < sramBanks + 0x70; currBank++) {
for (long currByte = 0; currByte < 0x10000; currByte += 512) {
@@ -1800,8 +1813,7 @@ unsigned long verifySRAM() {
}
}
}
- }
- else { // SuperFX SRAM
+ } else { // SuperFX SRAM
for (long currByte = 0; currByte < lastByte; currByte += 512) {
//fill sdBuffer
myFile.read(sdBuffer, 512);
@@ -1812,8 +1824,7 @@ unsigned long verifySRAM() {
}
}
}
- }
- else if (lastByte > 0x8000) { // Large SRAM Fix
+ } else if (lastByte > 0x8000) { // Large SRAM Fix
sramBanks = lastByte / 0x8000;
for (int currBank = 0x70; currBank < sramBanks + 0x70; currBank++) {
for (long currByte = 0; currByte < 0x8000; currByte += 512) {
@@ -1826,8 +1837,7 @@ unsigned long verifySRAM() {
}
}
}
- }
- else {
+ } else {
for (long currByte = 0; currByte < lastByte; currByte += 512) {
//fill sdBuffer
myFile.read(sdBuffer, 512);
@@ -1838,9 +1848,8 @@ unsigned long verifySRAM() {
}
}
}
- }
- else if (romType == HI) {
- if ((romChips == 245) || (romChips == 249)) { // SPC7110 SRAM
+ } else if (romType == HI) {
+ if ((romChips == 245) || (romChips == 249)) { // SPC7110 SRAM
// Configure SPC7110 SRAM Register
dataOut();
// Set 0x4830 to 0x80
@@ -1861,13 +1870,12 @@ unsigned long verifySRAM() {
// Reset 0x4830 to 0x0
writeBank_SNES(0, 0x4830, 0);
dataIn();
- }
- else {
+ } else {
// Dumping SRAM on HiRom needs CS(PH3) to be high
- PORTH |= (1 << 3);
+ PORTH |= (1 << 3);
// Sram size
long lastByte = (long(sramSize) * 128);
- if (lastByte > 0x2000) { // Large SRAM Fix
+ if (lastByte > 0x2000) { // Large SRAM Fix
sramBanks = lastByte / 0x2000;
for (int currBank = 0x30; currBank < sramBanks + 0x30; currBank++) {
for (long currByte = 0x6000; currByte < 0x8000; currByte += 512) {
@@ -1880,8 +1888,7 @@ unsigned long verifySRAM() {
}
}
}
- }
- else {
+ } else {
lastByte += 0x6000;
for (long currByte = 0x6000; currByte < lastByte; currByte += 512) {
//fill sdBuffer
@@ -1894,10 +1901,9 @@ unsigned long verifySRAM() {
}
}
}
- }
- else if (romType == EX) {
+ } else if (romType == EX) {
// Dumping SRAM on HiRom needs CS(PH3) to be high
- PORTH |= (1 << 3);
+ PORTH |= (1 << 3);
// Sram size
long lastByte = (long(sramSize) * 128) + 0x6000;
for (long currByte = 0x6000; currByte < lastByte; currByte += 512) {
@@ -1909,10 +1915,9 @@ unsigned long verifySRAM() {
}
}
}
- }
- else if (romType == SA) {
+ } else if (romType == SA) {
// Dumping SRAM on HiRom needs CS(PH3) to be high
- PORTH |= (1 << 3);
+ PORTH |= (1 << 3);
// Sram size
long lastByte = (long(sramSize) * 128);
@@ -1929,8 +1934,7 @@ unsigned long verifySRAM() {
}
}
}
- }
- else {
+ } else {
for (long currByte = 0x0; currByte < lastByte; currByte += 512) {
//fill sdBuffer
myFile.read(sdBuffer, 512);
@@ -1948,8 +1952,7 @@ unsigned long verifySRAM() {
myFile.close();
if (writeErrors == 0) {
println_Msg(F("Verified OK"));
- }
- else {
+ } else {
print_Msg(F("Error: "));
print_Msg(writeErrors);
println_Msg(F(" bytes "));
@@ -1969,14 +1972,13 @@ unsigned long verifySRAM() {
// Close the file:
myFile.close();
return writeErrors;
- }
- else {
+ } else {
print_Error(F("Can't open file"), false);
}
}
// Overwrite the entire SRAM
-boolean eraseSRAM (byte b) {
+boolean eraseSRAM(byte b) {
print_Msg(F("0x"));
print_Msg(b, HEX);
print_Msg(F(": "));
@@ -1993,37 +1995,33 @@ boolean eraseSRAM (byte b) {
// Sram size
long lastByte = (long(sramSize) * 128);
- if ((romChips == 19) || (romChips == 20) || (romChips == 21) || (romChips == 26)) { // SuperFX
- if (lastByte > 0x10000) { // Large SuperFX SRAM (no known carts)
+ if ((romChips == 19) || (romChips == 20) || (romChips == 21) || (romChips == 26)) { // SuperFX
+ if (lastByte > 0x10000) { // Large SuperFX SRAM (no known carts)
sramBanks = lastByte / 0x10000;
for (int currBank = 0x70; currBank < sramBanks + 0x70; currBank++) {
for (long currByte = 0x0000; currByte < 0x10000; currByte++) {
writeBank_SNES(currBank, currByte, b);
}
}
- }
- else { // SuperFX SRAM
+ } else { // SuperFX SRAM
for (long currByte = 0; currByte < lastByte; currByte++) {
writeBank_SNES(0x70, currByte, b);
}
}
- }
- else if (lastByte > 0x8000) { // Large SRAM Fix
+ } else if (lastByte > 0x8000) { // Large SRAM Fix
sramBanks = lastByte / 0x8000;
for (int currBank = 0x70; currBank < sramBanks + 0x70; currBank++) {
for (long currByte = 0x0000; currByte < 0x8000; currByte++) {
writeBank_SNES(currBank, currByte, b);
}
}
- }
- else {
- for (long currByte = 0; currByte < lastByte; currByte++) {
+ } else {
+ for (long currByte = 0; currByte < lastByte; currByte++) {
writeBank_SNES(0x70, currByte, b);
}
}
- }
- else if (romType == HI) {
- if ((romChips == 245) || (romChips == 249)) { // SPC7110 SRAM
+ } else if (romType == HI) {
+ if ((romChips == 245) || (romChips == 249)) { // SPC7110 SRAM
// Configure SPC7110 SRAM Register
// Set 0x4830 to 0x80
writeBank_SNES(0, 0x4830, 0x80);
@@ -2038,21 +2036,19 @@ boolean eraseSRAM (byte b) {
// Reset 0x4830 to 0x0
writeBank_SNES(0, 0x4830, 0);
dataIn();
- }
- else {
+ } else {
// Writing SRAM on HiRom needs CS(PH3) to be high
- PORTH |= (1 << 3);
+ PORTH |= (1 << 3);
// Sram size
long lastByte = (long(sramSize) * 128);
- if (lastByte > 0x2000) { // Large SRAM Fix
+ if (lastByte > 0x2000) { // Large SRAM Fix
sramBanks = lastByte / 0x2000;
for (int currBank = 0x30; currBank < sramBanks + 0x30; currBank++) {
for (long currByte = 0x6000; currByte < 0x8000; currByte++) {
writeBank_SNES(currBank, currByte, b);
}
}
- }
- else {
+ } else {
lastByte += 0x6000;
// Write to sram bank
for (long currByte = 0x6000; currByte < lastByte; currByte++) {
@@ -2064,7 +2060,7 @@ boolean eraseSRAM (byte b) {
// ExHiRom
else if (romType == EX) {
// Writing SRAM on HiRom needs CS(PH3) to be high
- PORTH |= (1 << 3);
+ PORTH |= (1 << 3);
// Sram size
long lastByte = (long(sramSize) * 128) + 0x6000;
for (long currByte = 0x6000; currByte < lastByte; currByte++) {
@@ -2133,8 +2129,8 @@ boolean eraseSRAM (byte b) {
if (romType == LO) {
// Sram size
long lastByte = (long(sramSize) * 128);
- if ((romChips == 19) || (romChips == 20) || (romChips == 21) || (romChips == 26)) { // SuperFX
- if (lastByte > 0x10000) { // Large SuperFX SRAM (no known carts)
+ if ((romChips == 19) || (romChips == 20) || (romChips == 21) || (romChips == 26)) { // SuperFX
+ if (lastByte > 0x10000) { // Large SuperFX SRAM (no known carts)
sramBanks = lastByte / 0x10000;
for (int currBank = 0x70; currBank < sramBanks + 0x70; currBank++) {
for (long currByte = 0; currByte < 0x10000; currByte += 512) {
@@ -2145,8 +2141,7 @@ boolean eraseSRAM (byte b) {
}
}
}
- }
- else { // SuperFX SRAM
+ } else { // SuperFX SRAM
for (long currByte = 0; currByte < lastByte; currByte += 512) {
for (int c = 0; c < 512; c++) {
if ((readBank_SNES(0x70, currByte + c)) != b) {
@@ -2155,8 +2150,7 @@ boolean eraseSRAM (byte b) {
}
}
}
- }
- else if (lastByte > 0x8000) { // Large SRAM Fix
+ } else if (lastByte > 0x8000) { // Large SRAM Fix
sramBanks = lastByte / 0x8000;
for (int currBank = 0x70; currBank < sramBanks + 0x70; currBank++) {
for (long currByte = 0; currByte < 0x8000; currByte += 512) {
@@ -2167,8 +2161,7 @@ boolean eraseSRAM (byte b) {
}
}
}
- }
- else {
+ } else {
for (long currByte = 0; currByte < lastByte; currByte += 512) {
for (int c = 0; c < 512; c++) {
if ((readBank_SNES(0x70, currByte + c)) != b) {
@@ -2177,9 +2170,8 @@ boolean eraseSRAM (byte b) {
}
}
}
- }
- else if (romType == HI) {
- if ((romChips == 245) || (romChips == 249)) { // SPC7110 SRAM
+ } else if (romType == HI) {
+ if ((romChips == 245) || (romChips == 249)) { // SPC7110 SRAM
// Configure SPC7110 SRAM Register
dataOut();
// Set 0x4830 to 0x80
@@ -2198,13 +2190,12 @@ boolean eraseSRAM (byte b) {
// Reset 0x4830 to 0x0
writeBank_SNES(0, 0x4830, 0);
dataIn();
- }
- else {
+ } else {
// Dumping SRAM on HiRom needs CS(PH3) to be high
- PORTH |= (1 << 3);
+ PORTH |= (1 << 3);
// Sram size
long lastByte = (long(sramSize) * 128);
- if (lastByte > 0x2000) { // Large SRAM Fix
+ if (lastByte > 0x2000) { // Large SRAM Fix
sramBanks = lastByte / 0x2000;
for (int currBank = 0x30; currBank < sramBanks + 0x30; currBank++) {
for (long currByte = 0x6000; currByte < 0x8000; currByte += 512) {
@@ -2215,8 +2206,7 @@ boolean eraseSRAM (byte b) {
}
}
}
- }
- else {
+ } else {
lastByte += 0x6000;
for (long currByte = 0x6000; currByte < lastByte; currByte += 512) {
for (int c = 0; c < 512; c++) {
@@ -2227,10 +2217,9 @@ boolean eraseSRAM (byte b) {
}
}
}
- }
- else if (romType == EX) {
+ } else if (romType == EX) {
// Dumping SRAM on HiRom needs CS(PH3) to be high
- PORTH |= (1 << 3);
+ PORTH |= (1 << 3);
// Sram size
long lastByte = (long(sramSize) * 128) + 0x6000;
for (long currByte = 0x6000; currByte < lastByte; currByte += 512) {
@@ -2240,10 +2229,9 @@ boolean eraseSRAM (byte b) {
}
}
}
- }
- else if (romType == SA) {
+ } else if (romType == SA) {
// Dumping SRAM on HiRom needs CS(PH3) to be high
- PORTH |= (1 << 3);
+ PORTH |= (1 << 3);
// Sram size
long lastByte = (long(sramSize) * 128);
if (lastByte > 0x10000) {
@@ -2257,8 +2245,7 @@ boolean eraseSRAM (byte b) {
}
}
}
- }
- else {
+ } else {
for (long currByte = 0x0; currByte < lastByte; currByte += 512) {
for (int c = 0; c < 512; c++) {
if ((readBank_SNES(0x40, currByte + c)) != b) {
@@ -2271,8 +2258,7 @@ boolean eraseSRAM (byte b) {
if (writeErrors == 0) {
println_Msg(F("OK"));
return 1;
- }
- else {
+ } else {
println_Msg(F("ERROR"));
return 0;
}
@@ -2283,4 +2269,4 @@ boolean eraseSRAM (byte b) {
//******************************************
// End of File
-//******************************************
+//****************************************** \ No newline at end of file
diff --git a/Cart_Reader/SV.ino b/Cart_Reader/SV.ino
index a2a147c..dafad9a 100644
--- a/Cart_Reader/SV.ino
+++ b/Cart_Reader/SV.ino
@@ -17,7 +17,7 @@ extern void draw_progressbar(uint32_t processedsize, uint32_t totalsize);
//void svMenu();
void readROM_SV();
//void setup_SV();
-void writeROM_SV (void);
+void writeROM_SV(void);
void eraseCheck_SV(void);
void supplyCheck_SV(void);
void writeCheck_SV(void);
@@ -38,7 +38,7 @@ static const char svFlashMenuItem2[] PROGMEM = "Write Memory Pack";
static const char svFlashMenuItem3[] PROGMEM = "Read BS-X Sram";
static const char svFlashMenuItem4[] PROGMEM = "Write BS-X Sram";
static const char svFlashMenuItem5[] PROGMEM = "Back";
-static const char* const menuOptionsSVFlash[] PROGMEM = {svFlashMenuItem1, svFlashMenuItem2, svFlashMenuItem3, svFlashMenuItem4, svFlashMenuItem5};
+static const char* const menuOptionsSVFlash[] PROGMEM = { svFlashMenuItem1, svFlashMenuItem2, svFlashMenuItem3, svFlashMenuItem4, svFlashMenuItem5 };
void svMenu() {
@@ -49,8 +49,7 @@ void svMenu() {
mainMenu = question_box(F("Satellaview 8M Memory"), menuOptions, 5, 0);
// wait for user choice to come back from the question box menu
- switch (mainMenu)
- {
+ switch (mainMenu) {
// Read memory pack
case 0:
// Change working dir to root
@@ -82,8 +81,7 @@ void svMenu() {
if (wrErrors == 0) {
println_Msg(F("Verified OK"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Error: "));
print_Msg(wrErrors);
println_Msg(F(" bytes "));
@@ -181,7 +179,7 @@ void setup_SV() {
//PORTJ &= ~(1 << 0);
// Start CIC by outputting a low signal to cicrstPin(PG1)
- PORTG &= ~(1 << 1);
+ PORTG &= ~(1 << 1);
// Wait for CIC reset
delay(1000);
@@ -199,19 +197,56 @@ void writeBank_SV(byte myBank, word myAddress, byte myData) {
// Arduino running at 16Mhz -> one nop = 62.5ns
// Wait till output is stable
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Switch WR(PH5) to LOW
PORTH &= ~(1 << 5);
// Leave WR low for at least 60ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Switch WR(PH5) to HIGH
PORTH |= (1 << 5);
// Leave WR high for at least 50ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
}
// Read one byte of data from a location specified by bank and address, 00:0000
@@ -221,7 +256,22 @@ byte readBank_SV(byte myBank, word myAddress) {
PORTK = (myAddress >> 8) & 0xFF;
// Arduino running at 16Mhz -> one nop = 62.5ns -> 1000ns total
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read
byte tempByte = PINC;
@@ -231,7 +281,7 @@ byte readBank_SV(byte myBank, word myAddress) {
/******************************************
SatellaView BS-X Sram functions
*****************************************/
-void readSRAM_SV () {
+void readSRAM_SV() {
// set control
controlIn_SNES();
@@ -254,7 +304,7 @@ void readSRAM_SV () {
}
int sramBanks = 0;
- readBank_SV(0x10, 0); // Preconfigure to fix corrupt 1st byte
+ readBank_SV(0x10, 0); // Preconfigure to fix corrupt 1st byte
// Sram size
long lastByte = (long(sramSize) * 0x80);
@@ -325,8 +375,7 @@ void writeSRAM_SV() {
println_Msg("");
println_Msg(F("SRAM writing finished"));
display_Update();
- }
- else {
+ } else {
print_Error(F("File doesnt exist"), false);
}
}
@@ -361,8 +410,7 @@ unsigned long verifySRAM_SV() {
// Close the file:
myFile.close();
return writeErrors;
- }
- else {
+ } else {
print_Error(F("Can't open file"), false);
}
}
@@ -412,7 +460,7 @@ void readROM_SV() {
myFile.write(sdBuffer, 512);
}
}
- draw_progressbar(0x100000, 0x100000); //Finish drawing progress bar
+ draw_progressbar(0x100000, 0x100000); //Finish drawing progress bar
// Close the file:
myFile.close();
@@ -421,15 +469,14 @@ void readROM_SV() {
wait();
}
-void writeROM_SV (void) {
+void writeROM_SV(void) {
// Get Checksum as string to make sure that BS-X cart is inserted
dataIn();
controlIn_SNES();
sprintf(checksumStr, "%02X%02X", readBank_SV(0, 65503), readBank_SV(0, 65502));
//if CRC is not 8B86, BS-X cart is not inserted. Display error and reset
- if (strcmp("8B86", checksumStr) != 0)
- {
+ if (strcmp("8B86", checksumStr) != 0) {
display_Clear();
print_Error(F("Error: Must use BS-X cart"), true);
}
@@ -457,8 +504,8 @@ void writeROM_SV (void) {
//Disable 8M memory pack write protection
dataOut();
controlOut_SNES();
- writeBank_SV(0x0C, 0x5000, 0x80); //Modify write enable register
- writeBank_SV(0x0E, 0x5000, 0x80); //Commit register modification
+ writeBank_SV(0x0C, 0x5000, 0x80); //Modify write enable register
+ writeBank_SV(0x0E, 0x5000, 0x80); //Commit register modification
//Erase memory pack
println_Msg(F("Erasing pack..."));
@@ -474,8 +521,7 @@ void writeROM_SV (void) {
for (int currBank = 0xC0; currBank < 0xD0; currBank++) {
draw_progressbar(((currBank - 0xC0) * 0x10000), 0x100000);
for (long currByte = 0; currByte < 65536; currByte++) {
- if (0xFF != readBank_SV(currBank, currByte))
- {
+ if (0xFF != readBank_SV(currBank, currByte)) {
println_Msg(F(""));
println_Msg(F("Erase failed"));
display_Update();
@@ -496,30 +542,29 @@ void writeROM_SV (void) {
draw_progressbar(((currBank - 0xC0) * 0x10000), 0x100000);
for (long currByte = 0; currByte < 65536; currByte++) {
- writeBank_SV(0xC0, 0x0000, 0x10); //Program Byte
+ writeBank_SV(0xC0, 0x0000, 0x10); //Program Byte
writeBank_SV(currBank, currByte, myFile.read());
- writeBank_SV(0xC0, 0x0000, 0x70); //Status Mode
+ writeBank_SV(0xC0, 0x0000, 0x70); //Status Mode
writeCheck_SV();
}
}
- writeBank_SV(0xC0, 0x0000, 0x70); //Status Mode
+ writeBank_SV(0xC0, 0x0000, 0x70); //Status Mode
writeCheck_SV();
- writeBank_SV(0xC0, 0x0000, 0xFF); //Terminate write
+ writeBank_SV(0xC0, 0x0000, 0xFF); //Terminate write
draw_progressbar(0x100000, 0x100000);
//Verify
- dataIn(); //Set pins to input
+ dataIn(); //Set pins to input
controlIn_SNES();
- myFile.seekSet(0); // Go back to file beginning
+ myFile.seekSet(0); // Go back to file beginning
println_Msg(F("Verifying..."));
display_Update();
for (int currBank = 0xC0; currBank < 0xD0; currBank++) {
draw_progressbar(((currBank - 0xC0) * 0x10000), 0x100000);
for (long currByte = 0; currByte < 65536; currByte++) {
- if (myFile.read() != readBank_SV(currBank, currByte))
- {
+ if (myFile.read() != readBank_SV(currBank, currByte)) {
println_Msg(F(""));
println_Msg(F("Verify failed"));
display_Update();
@@ -537,8 +582,7 @@ void writeROM_SV (void) {
display_Update();
wait();
- }
- else {
+ } else {
print_Error(F("File doesn't exist"), false);
}
}
@@ -553,15 +597,25 @@ void eraseCheck_SV(void) {
// CE or OE must be toggled with each subsequent status read or the
// completion of a program or erase operation will not be evident.
- while ((ret & 0x80) == 0x00) { //Wait until X.bit7 = 1
+ while ((ret & 0x80) == 0x00) { //Wait until X.bit7 = 1
controlOut_SNES();
// Switch CS(PH3) High
PORTH |= (1 << 3);
// Leave CE high for at least 60ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
controlIn_SNES();
// Leave CE low for at least 50ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read register
ret = readBank_SV(0xC0, 0x0004);
}
@@ -580,15 +634,25 @@ void supplyCheck_SV(void) {
// CE or OE must be toggled with each subsequent status read or the
// completion of a program or erase operation will not be evident.
- while ((ret & 0x08) == 0x08) { //Wait until X.bit3 = 0
+ while ((ret & 0x08) == 0x08) { //Wait until X.bit3 = 0
controlOut_SNES();
// Switch CS(PH3) High
PORTH |= (1 << 3);
// Leave CE high for at least 60ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
controlIn_SNES();
// Leave CE low for at least 50ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read register
ret = readBank_SV(0xC0, 0x0004);
}
@@ -612,10 +676,20 @@ void writeCheck_SV(void) {
// Switch CS(PH3) High
PORTH |= (1 << 3);
// Leave CE high for at least 60ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
controlIn_SNES();
// Leave CE low for at least 50ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read register
ret = readBank_SV(0xC0, 0x0000);
}
@@ -638,8 +712,7 @@ void detectCheck_SV(void) {
// completion of a program or erase operation will not be evident.
while ((ret & 0x80) == 0x00) {
i++;
- if ( i > 10000)
- {
+ if (i > 10000) {
//timeout
break;
}
@@ -647,10 +720,20 @@ void detectCheck_SV(void) {
// Switch CS(PH3) High
PORTH |= (1 << 3);
// Leave CE high for at least 60ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
controlIn_SNES();
// Leave CE low for at least 50ns
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Read register
ret = readBank_SV(0xC0, 0x0002);
}
@@ -660,22 +743,21 @@ void detectCheck_SV(void) {
}
-void eraseAll_SV(void)
-{
+void eraseAll_SV(void) {
dataOut();
controlOut_SNES();
- writeBank_SV(0xC0, 0x0000, 0x50); //Clear Status Registers
- writeBank_SV(0xC0, 0x0000, 0x71); //Status Mode
+ writeBank_SV(0xC0, 0x0000, 0x50); //Clear Status Registers
+ writeBank_SV(0xC0, 0x0000, 0x71); //Status Mode
supplyCheck_SV();
- writeBank_SV(0xC0, 0x0000, 0xA7); //Chip Erase
- writeBank_SV(0xC0, 0x0000, 0xD0); //Confirm
- writeBank_SV(0xC0, 0x0000, 0x71); //Status Mode
+ writeBank_SV(0xC0, 0x0000, 0xA7); //Chip Erase
+ writeBank_SV(0xC0, 0x0000, 0xD0); //Confirm
+ writeBank_SV(0xC0, 0x0000, 0x71); //Status Mode
eraseCheck_SV();
- writeBank_SV(0xC0, 0x0000, 0xFF); //Teriminate
+ writeBank_SV(0xC0, 0x0000, 0xFF); //Teriminate
}
#endif
//******************************************
// End of File
-//******************************************
+//****************************************** \ No newline at end of file
diff --git a/Cart_Reader/VBOY.ino b/Cart_Reader/VBOY.ino
index ad1c193..36ef1e2 100644
--- a/Cart_Reader/VBOY.ino
+++ b/Cart_Reader/VBOY.ino
@@ -55,8 +55,7 @@
// SETUP
//******************************************
-void setup_VBOY()
-{
+void setup_VBOY() {
// Set Address Pins to Output
//A0-A7
DDRF = 0xFF;
@@ -70,7 +69,7 @@ void setup_VBOY()
DDRH |= (1 << 0) | (1 << 1) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6);
// Set TIME(PJ0) to Output (UNUSED)
- DDRJ |= (1 << 0);
+ DDRJ |= (1 << 0);
// Set Pins (D0-D15) to Input
DDRC = 0x00;
@@ -83,7 +82,7 @@ void setup_VBOY()
PORTH &= ~(1 << 0);
// Set Unused Pins HIGH
- PORTJ |= (1 << 0); // TIME(PJ0)
+ PORTJ |= (1 << 0); // TIME(PJ0)
getCartInfo_VB();
@@ -99,15 +98,13 @@ static const char vboyMenuItem1[] PROGMEM = "Read ROM";
static const char vboyMenuItem2[] PROGMEM = "Read SRAM";
static const char vboyMenuItem3[] PROGMEM = "Write SRAM";
static const char vboyMenuItem4[] PROGMEM = "Reset";
-static const char* const menuOptionsVBOY[] PROGMEM = {vboyMenuItem1, vboyMenuItem2, vboyMenuItem3, vboyMenuItem4};
+static const char* const menuOptionsVBOY[] PROGMEM = { vboyMenuItem1, vboyMenuItem2, vboyMenuItem3, vboyMenuItem4 };
-void vboyMenu()
-{
+void vboyMenu() {
convertPgm(menuOptionsVBOY, 4);
uint8_t mainMenu = question_box(F("VIRTUALBOY MENU"), menuOptions, 4, 0);
- switch (mainMenu)
- {
+ switch (mainMenu) {
case 0:
// Read ROM
sd.chdir("/");
@@ -124,8 +121,7 @@ void vboyMenu()
display_Update();
readSRAM_VB();
sd.chdir("/");
- }
- else {
+ } else {
print_Error(F("Cart has no SRAM"), false);
}
#if (defined(enable_OLED) || defined(enable_LCD))
@@ -148,15 +144,13 @@ void vboyMenu()
if (writeErrors == 0) {
println_Msg(F("SRAM verified OK"));
display_Update();
- }
- else {
+ } else {
print_Msg(F("Error: "));
print_Msg(writeErrors);
println_Msg(F(" bytes "));
print_Error(F("did not verify."), false);
}
- }
- else {
+ } else {
print_Error(F("Cart has no SRAM"), false);
}
#if (defined(enable_OLED) || defined(enable_LCD))
@@ -192,12 +186,22 @@ void writeByte_VB(unsigned long myAddress, byte myData) {
// Set /CS1(PH4), /WE0(PH5) to LOW
PORTH &= ~(1 << 4) & ~(1 << 5);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Set CS2(PH0), /CS1(PH4), /WE0(PH5) to HIGH
PORTH |= (1 << 0) | (1 << 4) | (1 << 5);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
}
word readWord_VB(unsigned long myAddress) {
@@ -212,21 +216,31 @@ word readWord_VB(unsigned long myAddress) {
// Set /CE(PH3), /OE(PH6) to LOW
PORTH &= ~(1 << 3) & ~(1 << 6);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
- word tempWord = ( ( PINA & 0xFF ) << 8 ) | ( PINC & 0xFF );
+ word tempWord = ((PINA & 0xFF) << 8) | (PINC & 0xFF);
// Set /CE(PH3), /OE(PH6) to HIGH
PORTH |= (1 << 3) | (1 << 6);
// Setting CS2(PH0) LOW
PORTH &= ~(1 << 0);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
return tempWord;
}
-byte readByte_VB(unsigned long myAddress) { // SRAM BYTE
+byte readByte_VB(unsigned long myAddress) { // SRAM BYTE
PORTF = myAddress & 0xFF;
PORTK = (myAddress >> 8) & 0xFF;
PORTL = (myAddress >> 16) & 0xFF;
@@ -238,18 +252,33 @@ byte readByte_VB(unsigned long myAddress) { // SRAM BYTE
// Set /CS1(PH4), /OE(PH6) to LOW
PORTH &= ~(1 << 4) & ~(1 << 6);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
byte tempByte = PINA;
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
// Set /CS1(PH4), /OE(PH6) to HIGH
PORTH |= (1 << 3) | (1 << 6);
// Setting CS2(PH0) LOW
PORTH &= ~(1 << 0);
- __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");
+ __asm__("nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t"
+ "nop\n\t");
return tempByte;
}
@@ -277,52 +306,51 @@ void getCartInfo_VB() {
cartSize = 0;
for (unsigned long address = 0x80000; address <= 0x400000; address *= 2) {
// Get Serial
- word vbSerial = readWord_VB((address - 0x204) / 2); // Cart Serial
-
- switch (vbSerial)
- {
- case 0x4D54: // MT = Mario's Tennis
- case 0x4832: // H2 = Panic Bomber/Tobidase! Panibomb
- case 0x5350: // SP = Space Invaders
- case 0x5353: // SS = Space Squash
- case 0x5452: // TR = V-Tetris
- cartSize = 0x80000; // 512KB
+ word vbSerial = readWord_VB((address - 0x204) / 2); // Cart Serial
+
+ switch (vbSerial) {
+ case 0x4D54: // MT = Mario's Tennis
+ case 0x4832: // H2 = Panic Bomber/Tobidase! Panibomb
+ case 0x5350: // SP = Space Invaders
+ case 0x5353: // SS = Space Squash
+ case 0x5452: // TR = V-Tetris
+ cartSize = 0x80000; // 512KB
break;
- case 0x494D: // IM = Insmouse no Yakata
- case 0x4A42: // JB = Jack Bros.
- case 0x4D43: // MC = Mario Clash
- case 0x5245: // RE = Red Alarm
- case 0x4833: // H3 = Vertical Force
- case 0x5642: // VB = Virtual Bowling
- case 0x5646: // VF = Virtual Fishing
- case 0x4A56: // JV = Virtual Lab
- case 0x5650: // VP = Virtual League Baseball/Virtual Pro Yakyuu '95
- cartSize = 0x100000; // 1MB
+ case 0x494D: // IM = Insmouse no Yakata
+ case 0x4A42: // JB = Jack Bros.
+ case 0x4D43: // MC = Mario Clash
+ case 0x5245: // RE = Red Alarm
+ case 0x4833: // H3 = Vertical Force
+ case 0x5642: // VB = Virtual Bowling
+ case 0x5646: // VF = Virtual Fishing
+ case 0x4A56: // JV = Virtual Lab
+ case 0x5650: // VP = Virtual League Baseball/Virtual Pro Yakyuu '95
+ cartSize = 0x100000; // 1MB
break;
- case 0x5042: // PB = 3-D Tetris
- case 0x4750: // GP = Galactic Pinball
- case 0x5344: // SD = SD Gundam Dimension War
- case 0x5442: // TB = Teleroboxer
- cartSize = 0x100000; // 1MB
- sramSize = 0x2000; // 8KB
+ case 0x5042: // PB = 3-D Tetris
+ case 0x4750: // GP = Galactic Pinball
+ case 0x5344: // SD = SD Gundam Dimension War
+ case 0x5442: // TB = Teleroboxer
+ cartSize = 0x100000; // 1MB
+ sramSize = 0x2000; // 8KB
break;
- case 0x5647: // VG = Golf/T&E Virtual Golf
- case 0x4E46: // NF = Nester's Funky Bowling
- case 0x5745: // WE = Waterworld
- cartSize = 0x200000; // 2MB
+ case 0x5647: // VG = Golf/T&E Virtual Golf
+ case 0x4E46: // NF = Nester's Funky Bowling
+ case 0x5745: // WE = Waterworld
+ cartSize = 0x200000; // 2MB
break;
- case 0x5743: // WC = Virtual Boy Wario Land
- cartSize = 0x200000; // 2MB
- sramSize = 0x2000; // 8KB
+ case 0x5743: // WC = Virtual Boy Wario Land
+ cartSize = 0x200000; // 2MB
+ sramSize = 0x2000; // 8KB
break;
- case 0x4644: // FD = Hyper Fighting
- cartSize = 0x400000; // 4MB
- sramSize = 0x2000; // 8KB
+ case 0x4644: // FD = Hyper Fighting
+ cartSize = 0x400000; // 4MB
+ sramSize = 0x2000; // 8KB
break;
}
@@ -355,14 +383,13 @@ void getCartInfo_VB() {
print_Msg(F("Name: "));
println_Msg(romName);
print_Msg(F("Size: "));
- print_Msg(cartSize * 8 / 1024 / 1024 );
+ print_Msg(cartSize * 8 / 1024 / 1024);
println_Msg(F(" MBit"));
print_Msg(F("Sram: "));
if (sramSize > 0) {
print_Msg(sramSize * 8 / 1024);
println_Msg(F(" KBit"));
- }
- else
+ } else
println_Msg(F("None"));
println_Msg(F(" "));
@@ -413,20 +440,19 @@ void readROM_VB() {
for (int currWord = 0; currWord < 256; currWord++) {
word myWord = readWord_VB(currBuffer + currWord);
// Split word into two bytes
- sdBuffer[d] = (( myWord >> 8 ) & 0xFF);
+ sdBuffer[d] = ((myWord >> 8) & 0xFF);
sdBuffer[d + 1] = (myWord & 0xFF);
d += 2;
}
myFile.write(sdBuffer, 512);
d = 0;
}
- }
- else {
+ } else {
for (unsigned long currBuffer = 0; currBuffer < cartSize / 2; currBuffer += 256) {
for (int currWord = 0; currWord < 256; currWord++) {
word myWord = readWord_VB(currBuffer + currWord);
// Split word into two bytes
- sdBuffer[d] = (( myWord >> 8 ) & 0xFF);
+ sdBuffer[d] = ((myWord >> 8) & 0xFF);
sdBuffer[d + 1] = (myWord & 0xFF);
d += 2;
}
@@ -469,8 +495,7 @@ void writeSRAM_VB() {
myFile.close();
println_Msg(F("Done"));
display_Update();
- }
- else {
+ } else {
print_Error(F("SD Error"), true);
}
dataIn_VB();
@@ -524,8 +549,7 @@ unsigned long verifySRAM_VB() {
}
}
myFile.close();
- }
- else {
+ } else {
print_Error(F("SD Error"), true);
}
@@ -534,4 +558,4 @@ unsigned long verifySRAM_VB() {
#endif
//******************************************
// End of File
-//******************************************
+//****************************************** \ No newline at end of file
diff --git a/Cart_Reader/WS.ino b/Cart_Reader/WS.ino
index 49855f2..5be2800 100644
--- a/Cart_Reader/WS.ino
+++ b/Cart_Reader/WS.ino
@@ -37,7 +37,7 @@ static const char wsMenuItem2[] PROGMEM = "Read Save";
static const char wsMenuItem3[] PROGMEM = "Write Save";
static const char wsMenuItem4[] PROGMEM = "Reset";
static const char wsMenuItem5[] PROGMEM = "Write WitchOS";
-static const char* const menuOptionsWS[] PROGMEM = {wsMenuItem1, wsMenuItem2, wsMenuItem3, wsMenuItem4, wsMenuItem5};
+static const char *const menuOptionsWS[] PROGMEM = { wsMenuItem1, wsMenuItem2, wsMenuItem3, wsMenuItem4, wsMenuItem5 };
static const uint8_t wwLaunchCode[] PROGMEM = { 0xea, 0x00, 0x00, 0x00, 0xe0, 0x00, 0xff, 0xff };
@@ -47,8 +47,7 @@ static uint16_t wsGameChecksum = 0;
static uint8_t wsEepromShiftReg[2];
static boolean wsWitch = false;
-void setup_WS()
-{
+void setup_WS() {
// A-1 - A6
DDRF = 0xff;
// A7 - A14
@@ -88,8 +87,7 @@ void setup_WS()
do {
unlockMMC2003_WS();
- }
- while (!headerCheck());
+ } while (!headerCheck());
getCartInfo_WS();
@@ -100,18 +98,18 @@ boolean headerCheck() {
dataIn_WS();
for (uint32_t i = 0; i < 16; i += 2)
- * ((uint16_t*)(sdBuffer + i)) = readWord_WS(0xffff0 + i);
+ *((uint16_t *)(sdBuffer + i)) = readWord_WS(0xffff0 + i);
uint8_t startByte = sdBuffer[0];
- if (startByte == 0xEA) { // Start should be 0xEA
+ if (startByte == 0xEA) { // Start should be 0xEA
uint8_t zeroByte = sdBuffer[5];
- if (zeroByte == 0) { // Zero Byte
+ if (zeroByte == 0) { // Zero Byte
uint8_t systemByte = sdBuffer[7];
- if (systemByte < 2) { // System < 2
+ if (systemByte < 2) { // System < 2
uint8_t revisionByte = sdBuffer[9];
- if ((revisionByte < 7) || (revisionByte == 0x80)) { // Known Revisions: 0 to 6 and 0x80
+ if ((revisionByte < 7) || (revisionByte == 0x80)) { // Known Revisions: 0 to 6 and 0x80
uint8_t sizeByte = sdBuffer[10];
- if (sizeByte < 10) // Rom Size < 10
+ if (sizeByte < 10) // Rom Size < 10
return true;
}
}
@@ -120,15 +118,13 @@ boolean headerCheck() {
return false;
}
-void wsMenu()
-{
+void wsMenu() {
uint8_t mainMenu = (wsWitch ? 5 : 4);
convertPgm(menuOptionsWS, mainMenu);
mainMenu = question_box(F("WS Menu"), menuOptions, mainMenu, 0);
- switch (mainMenu)
- {
+ switch (mainMenu) {
case 0:
{
// Read Rom
@@ -142,8 +138,7 @@ void wsMenu()
{
// Read Save
sd.chdir("/");
- switch (saveType)
- {
+ switch (saveType) {
case 0: println_Msg(F("No save for this game")); break;
case 1: readSRAM_WS(); break;
case 2: readEEPROM_WS(); break;
@@ -156,8 +151,7 @@ void wsMenu()
{
// Write Save
sd.chdir("/");
- switch (saveType)
- {
+ switch (saveType) {
case 0: println_Msg(F("No save for this game")); break;
case 1:
{
@@ -184,7 +178,7 @@ void wsMenu()
default:
{
// reset
- asm volatile (" jmp 0");
+ asm volatile(" jmp 0");
break;
}
}
@@ -196,20 +190,18 @@ void wsMenu()
wait();
}
-uint8_t getCartInfo_WS()
-{
+uint8_t getCartInfo_WS() {
dataIn_WS();
// for (uint32_t i = 0; i < 16; i += 2)
// *((uint16_t*)(sdBuffer + i)) = readWord_WS(0xffff0 + i);
- wsGameChecksum = *(uint16_t*)(sdBuffer + 14);
+ wsGameChecksum = *(uint16_t *)(sdBuffer + 14);
wsWitch = false;
// some game has wrong info in header
// patch here
- switch (wsGameChecksum)
- {
+ switch (wsGameChecksum) {
// games with wrong save type/size
// 256kbits sram
case 0xe600: // BAN007
@@ -247,11 +239,9 @@ uint8_t getCartInfo_WS()
{
// developerId/cartId/checksum are all filled with 0x00 in witch based games
dataIn_WS();
- if (readWord_WS(0xf0000) == 0x4c45 && readWord_WS(0xf0002) == 0x5349 && readWord_WS(0xf0004) == 0x0041)
- {
+ if (readWord_WS(0xf0000) == 0x4c45 && readWord_WS(0xf0002) == 0x5349 && readWord_WS(0xf0004) == 0x0041) {
// check witch BIOS
- if (readWord_WS(0xfff5e) == 0x006c && readWord_WS(0xfff60) == 0x5b1b)
- {
+ if (readWord_WS(0xfff5e) == 0x006c && readWord_WS(0xfff60) == 0x5b1b) {
// check flashchip
// should be a MBM29DL400TC
dataOut_WS();
@@ -272,39 +262,30 @@ uint8_t getCartInfo_WS()
sdBuffer[8] = 0x03;
}
// check service menu
- else if (readWord_WS(0xfff22) == 0x006c && readWord_WS(0xfff24) == 0x5b1b)
- {
- if (readWord_WS(0x93246) == 0x4a2f && readWord_WS(0x93248) == 0x5353 && readWord_WS(0x9324a) == 0x2e32)
- {
+ else if (readWord_WS(0xfff22) == 0x006c && readWord_WS(0xfff24) == 0x5b1b) {
+ if (readWord_WS(0x93246) == 0x4a2f && readWord_WS(0x93248) == 0x5353 && readWord_WS(0x9324a) == 0x2e32) {
// jss2
- sdBuffer[6] = 0xff; // WWGP
- sdBuffer[8] = 0x1a; // 2001A
- sdBuffer[7] = 0x01; // color only
+ sdBuffer[6] = 0xff; // WWGP
+ sdBuffer[8] = 0x1a; // 2001A
+ sdBuffer[7] = 0x01; // color only
- if (readWord_WS(0x93e9c) == 0x4648 && readWord_WS(0x93e9e) == 0x0050)
- {
+ if (readWord_WS(0x93e9c) == 0x4648 && readWord_WS(0x93e9e) == 0x0050) {
// WWGP2001A3 -> HFP Version
sdBuffer[9] = 0x03;
wsGameChecksum = 0x4870;
- }
- else
- {
+ } else {
// TODO check other jss2 version
}
- }
- else if (readWord_WS(0xe4260) == 0x6b64 && readWord_WS(0xe4262) == 0x696e)
- {
+ } else if (readWord_WS(0xe4260) == 0x6b64 && readWord_WS(0xe4262) == 0x696e) {
// dknight
- sdBuffer[6] = 0xff; // WWGP
- sdBuffer[8] = 0x2b; // 2002B
- sdBuffer[7] = 0x01; // color only
+ sdBuffer[6] = 0xff; // WWGP
+ sdBuffer[8] = 0x2b; // 2002B
+ sdBuffer[7] = 0x01; // color only
sdBuffer[9] = 0x00;
wsGameChecksum = 0x8b1c;
}
}
- }
- else if (sdBuffer[6] == 0x2a && sdBuffer[8] == 0x01 && sdBuffer[9] == 0x01)
- {
+ } else if (sdBuffer[6] == 0x2a && sdBuffer[8] == 0x01 && sdBuffer[9] == 0x01) {
// Mobile WonderGate v1.1, checksum is filled with 0x0000
wsGameChecksum = 0x1da0;
}
@@ -313,7 +294,7 @@ uint8_t getCartInfo_WS()
}
}
- romType = (sdBuffer[7] & 0x01); // wsc only = 1
+ romType = (sdBuffer[7] & 0x01); // wsc only = 1
romVersion = sdBuffer[9];
romSize = sdBuffer[10];
sramSize = sdBuffer[11];
@@ -325,8 +306,7 @@ uint8_t getCartInfo_WS()
snprintf(checksumStr, 5, "%04X", wsGameChecksum);
snprintf(romName, 17, "%s%s", vendorID, cartID);
- switch (romSize)
- {
+ switch (romSize) {
case 0x01: cartSize = 131072 * 2; break;
case 0x02: cartSize = 131072 * 4; break;
case 0x03: cartSize = 131072 * 8; break;
@@ -339,17 +319,43 @@ uint8_t getCartInfo_WS()
default: cartSize = 0; break;
}
- switch (sramSize)
- {
- case 0x00: saveType = 0; sramSize = 0; break;
- case 0x01: saveType = 1; sramSize = 64; break;
- case 0x02: saveType = 1; sramSize = 256; break;
- case 0x03: saveType = 1; sramSize = 1024; break;
- case 0x04: saveType = 1; sramSize = 2048; break;
- case 0x05: saveType = 1; sramSize = 4096; break;
- case 0x10: saveType = 2; sramSize = 1; break;
- case 0x20: saveType = 2; sramSize = 16; break;
- case 0x50: saveType = 2; sramSize = 8; break;
+ switch (sramSize) {
+ case 0x00:
+ saveType = 0;
+ sramSize = 0;
+ break;
+ case 0x01:
+ saveType = 1;
+ sramSize = 64;
+ break;
+ case 0x02:
+ saveType = 1;
+ sramSize = 256;
+ break;
+ case 0x03:
+ saveType = 1;
+ sramSize = 1024;
+ break;
+ case 0x04:
+ saveType = 1;
+ sramSize = 2048;
+ break;
+ case 0x05:
+ saveType = 1;
+ sramSize = 4096;
+ break;
+ case 0x10:
+ saveType = 2;
+ sramSize = 1;
+ break;
+ case 0x20:
+ saveType = 2;
+ sramSize = 16;
+ break;
+ case 0x50:
+ saveType = 2;
+ sramSize = 8;
+ break;
default: saveType = 0xff; break;
}
@@ -360,8 +366,7 @@ uint8_t getCartInfo_WS()
return sdBuffer[0];
}
-void showCartInfo_WS()
-{
+void showCartInfo_WS() {
display_Clear();
println_Msg(F("WS Cart Info"));
@@ -372,18 +377,24 @@ void showCartInfo_WS()
print_Msg(F("Rom Size: "));
if (cartSize == 0x00)
println_Msg(romSize, HEX);
- else
- {
+ else {
print_Msg((cartSize >> 17));
println_Msg(F(" Mb"));
}
print_Msg(F("Save: "));
- switch (saveType)
- {
+ switch (saveType) {
case 0: println_Msg(F("None")); break;
- case 1: print_Msg(F("Sram ")); print_Msg(sramSize); println_Msg(F(" Kb")); break;
- case 2: print_Msg(F("Eeprom ")); print_Msg(sramSize); println_Msg(F(" Kb")); break;
+ case 1:
+ print_Msg(F("Sram "));
+ print_Msg(sramSize);
+ println_Msg(F(" Kb"));
+ break;
+ case 2:
+ print_Msg(F("Eeprom "));
+ print_Msg(sramSize);
+ println_Msg(F(" Kb"));
+ break;
default: println_Msg(sramSize, HEX); break;
}
@@ -398,15 +409,13 @@ void showCartInfo_WS()
wait();
}
-void getDeveloperName(uint8_t id, char *buf, size_t length)
-{
+void getDeveloperName(uint8_t id, char *buf, size_t length) {
if (buf == NULL)
return;
char *devName = NULL;
- switch (id)
- {
+ switch (id) {
case 0x01: devName = PSTR("BAN"); break;
case 0x02: devName = PSTR("TAT"); break;
case 0x03: devName = PSTR("TMY"); break;
@@ -433,7 +442,7 @@ void getDeveloperName(uint8_t id, char *buf, size_t length)
case 0x1e: devName = PSTR("NAP"); break;
case 0x1f: devName = PSTR("BVL"); break;
case 0x20: devName = PSTR("ATN"); break;
- case 0x21: devName = PSTR("KDX"); break; // KDK for Memories of Festa?
+ case 0x21: devName = PSTR("KDX"); break; // KDK for Memories of Festa?
case 0x22: devName = PSTR("HAL"); break;
case 0x23: devName = PSTR("YKE"); break;
case 0x24: devName = PSTR("OMM"); break;
@@ -452,17 +461,18 @@ void getDeveloperName(uint8_t id, char *buf, size_t length)
// custom developerId
case 0x7a: devName = PSTR("7AC"); break; // witch
- case 0xff: devName = PSTR("WWGP"); break; // WWGP series (jss2, dknight)
+ case 0xff:
+ devName = PSTR("WWGP");
+ break; // WWGP series (jss2, dknight)
// if not found, use id
- default: snprintf(buf, length, "%02X", id); return;
+ default: snprintf(buf, length, "%02X", id); return;
}
strlcpy_P(buf, devName, length);
}
-void readROM_WS(char *outPathBuf, size_t bufferSize)
-{
+void readROM_WS(char *outPathBuf, size_t bufferSize) {
// generate fullname of rom file
snprintf(fileName, FILENAME_LENGTH, "%s.ws%c", romName, ((romType & 1) ? 'c' : '\0'));
@@ -497,8 +507,7 @@ void readROM_WS(char *outPathBuf, size_t bufferSize)
draw_progressbar(0, cartSize);
// start reading rom
- for (; bank <= 0xff; bank++)
- {
+ for (; bank <= 0xff; bank++) {
// switch bank on segment 0x2
dataOut_WS();
writeByte_WSPort(0xc2, bank);
@@ -508,14 +517,13 @@ void readROM_WS(char *outPathBuf, size_t bufferSize)
writeByte_WSPort(0xcd, (bank & 0x03));
dataIn_WS();
- for (uint32_t addr = 0; addr < 0x10000; addr += 512)
- {
+ for (uint32_t addr = 0; addr < 0x10000; addr += 512) {
// blink LED
if ((addr & ((1 << 14) - 1)) == 0)
blinkLED();
for (uint32_t w = 0; w < 512; w += 2)
- * ((uint16_t*)(sdBuffer + w)) = readWord_WS(0x20000 + addr + w);
+ *((uint16_t *)(sdBuffer + w)) = readWord_WS(0x20000 + addr + w);
myFile.write(sdBuffer, 512);
progress += 512;
@@ -525,8 +533,7 @@ void readROM_WS(char *outPathBuf, size_t bufferSize)
}
// turn off LEDs (only for BANC33)
- if (wsGameChecksum == 0xeafd)
- {
+ if (wsGameChecksum == 0xeafd) {
dataOut_WS();
writeByte_WSPort(0xcd, 0x00);
}
@@ -534,8 +541,7 @@ void readROM_WS(char *outPathBuf, size_t bufferSize)
myFile.close();
}
-void readSRAM_WS()
-{
+void readSRAM_WS() {
// generate fullname of rom file
snprintf(fileName, FILENAME_LENGTH, "%s.sav", romName);
@@ -565,14 +571,12 @@ void readSRAM_WS()
uint16_t bank = 0;
- do
- {
+ do {
dataOut_WS();
writeByte_WSPort(0xc1, bank);
dataIn_WS();
- for (uint32_t addr = 0; addr < bank_size; addr += 512)
- {
+ for (uint32_t addr = 0; addr < bank_size; addr += 512) {
// blink LED
if ((addr & ((1 << 14) - 1)) == 0)
blinkLED();
@@ -591,13 +595,11 @@ void readSRAM_WS()
display_Update();
}
-void verifySRAM_WS()
-{
+void verifySRAM_WS() {
print_Msg(F("Verifying... "));
display_Update();
- if (myFile.open(filePath, O_READ))
- {
+ if (myFile.open(filePath, O_READ)) {
uint32_t bank_size = (sramSize << 7);
uint16_t end_bank = (bank_size >> 16); // 64KB per bank
uint16_t bank = 0;
@@ -606,19 +608,16 @@ void verifySRAM_WS()
if (bank_size > 0x10000)
bank_size = 0x10000;
- do
- {
+ do {
dataOut_WS();
writeByte_WSPort(0xc1, bank);
dataIn_WS();
- for (uint32_t addr = 0; addr < bank_size && myFile.available(); addr += 512)
- {
+ for (uint32_t addr = 0; addr < bank_size && myFile.available(); addr += 512) {
myFile.read(sdBuffer, 512);
// SRAM data on D0-D7, with A-1 to select high/low byte
- for (uint32_t w = 0; w < 512; w++)
- {
+ for (uint32_t w = 0; w < 512; w++) {
if (readByte_WS(0x10000 + addr + w) != sdBuffer[w])
write_errors++;
}
@@ -627,27 +626,21 @@ void verifySRAM_WS()
myFile.close();
- if (write_errors == 0)
- {
+ if (write_errors == 0) {
println_Msg(F("passed"));
- }
- else
- {
+ } else {
println_Msg(F("failed"));
print_Msg(F("Error: "));
print_Msg(write_errors);
println_Msg(F(" bytes "));
print_Error(F("did not verify."), false);
}
- }
- else
- {
+ } else {
print_Error(F("File doesn't exist"), false);
}
}
-void writeSRAM_WS()
-{
+void writeSRAM_WS() {
filePath[0] = 0;
sd.chdir("/");
fileBrowser(F("Select sav file"));
@@ -659,8 +652,7 @@ void writeSRAM_WS()
println_Msg(F("..."));
display_Update();
- if (myFile.open(filePath, O_READ))
- {
+ if (myFile.open(filePath, O_READ)) {
uint32_t bank_size = (sramSize << 7);
uint16_t end_bank = (bank_size >> 16); // 64KB per bank
@@ -669,12 +661,10 @@ void writeSRAM_WS()
uint16_t bank = 0;
dataOut_WS();
- do
- {
+ do {
writeByte_WSPort(0xc1, bank);
- for (uint32_t addr = 0; addr < bank_size && myFile.available(); addr += 512)
- {
+ for (uint32_t addr = 0; addr < bank_size && myFile.available(); addr += 512) {
// blink LED
if ((addr & ((1 << 14) - 1)) == 0)
blinkLED();
@@ -691,15 +681,12 @@ void writeSRAM_WS()
println_Msg(F("Writing finished"));
display_Update();
- }
- else
- {
+ } else {
print_Error(F("File doesn't exist"), false);
}
}
-void readEEPROM_WS()
-{
+void readEEPROM_WS() {
// generate fullname of eep file
snprintf(fileName, FILENAME_LENGTH, "%s.eep", romName);
@@ -724,10 +711,8 @@ void readEEPROM_WS()
uint32_t eepromSize = (sramSize << 7);
uint32_t bufSize = (eepromSize < 512 ? eepromSize : 512);
- for (uint32_t i = 0; i < eepromSize; i += bufSize)
- {
- for (uint32_t j = 0; j < bufSize; j += 2)
- {
+ for (uint32_t i = 0; i < eepromSize; i += bufSize) {
+ for (uint32_t j = 0; j < bufSize; j += 2) {
// blink LED
if ((j & 0x1f) == 0x00)
blinkLED();
@@ -756,23 +741,19 @@ void readEEPROM_WS()
println_Msg(F("Done"));
}
-void verifyEEPROM_WS()
-{
+void verifyEEPROM_WS() {
print_Msg(F("Verifying... "));
display_Update();
- if (myFile.open(filePath, O_READ))
- {
+ if (myFile.open(filePath, O_READ)) {
uint32_t write_errors = 0;
uint32_t eepromSize = (sramSize << 7);
uint32_t bufSize = (eepromSize < 512 ? eepromSize : 512);
- for (uint32_t i = 0; i < eepromSize; i += bufSize)
- {
+ for (uint32_t i = 0; i < eepromSize; i += bufSize) {
myFile.read(sdBuffer, bufSize);
- for (uint32_t j = 0; j < bufSize; j += 2)
- {
+ for (uint32_t j = 0; j < bufSize; j += 2) {
// blink LED
if ((j & 0x1f) == 0x00)
blinkLED();
@@ -799,27 +780,21 @@ void verifyEEPROM_WS()
myFile.close();
- if (write_errors == 0)
- {
+ if (write_errors == 0) {
println_Msg(F("passed"));
- }
- else
- {
+ } else {
println_Msg(F("failed"));
print_Msg(F("Error: "));
print_Msg(write_errors);
println_Msg(F(" bytes "));
print_Error(F("did not verify."), false);
}
- }
- else
- {
+ } else {
print_Error(F("File doesn't exist"), false);
}
}
-void writeEEPROM_WS()
-{
+void writeEEPROM_WS() {
filePath[0] = 0;
sd.chdir("/");
fileBrowser(F("Select eep file"));
@@ -831,17 +806,14 @@ void writeEEPROM_WS()
println_Msg(F("..."));
display_Update();
- if (myFile.open(filePath, O_READ))
- {
+ if (myFile.open(filePath, O_READ)) {
uint32_t eepromSize = (sramSize << 7);
uint32_t bufSize = (eepromSize < 512 ? eepromSize : 512);
- for (uint32_t i = 0; i < eepromSize; i += bufSize)
- {
+ for (uint32_t i = 0; i < eepromSize; i += bufSize) {
myFile.read(sdBuffer, bufSize);
- for (uint32_t j = 0; j < bufSize; j += 2)
- {
+ for (uint32_t j = 0; j < bufSize; j += 2) {
// blink LED
if ((j & 0x1f) == 0x00)
blinkLED();
@@ -861,23 +833,19 @@ void writeEEPROM_WS()
dataIn_WS();
do {
pulseCLK_WS(128);
- }
- while ((readByte_WSPort(0xc8) & 0x02) == 0x00);
+ } while ((readByte_WSPort(0xc8) & 0x02) == 0x00);
}
}
myFile.close();
println_Msg(F("Done"));
- }
- else
- {
+ } else {
print_Error(F("File doesn't exist"), false);
}
}
-void writeWitchOS_WS()
-{
+void writeWitchOS_WS() {
// make sure that OS sectors not protected
dataOut_WS();
writeWord_WS(0x80aaa, 0xaaaa);
@@ -885,13 +853,10 @@ void writeWitchOS_WS()
writeWord_WS(0xe0aaa, 0x9090);
dataIn_WS();
- if (readWord_WS(0xe0004) || readWord_WS(0xe4004) || readWord_WS(0xec004) || readWord_WS(0xee004))
- {
+ if (readWord_WS(0xe0004) || readWord_WS(0xe4004) || readWord_WS(0xec004) || readWord_WS(0xee004)) {
display_Clear();
print_Error(F("OS sectors are protected!"), false);
- }
- else
- {
+ } else {
filePath[0] = 0;
sd.chdir("/");
fileBrowser(F("Select fbin file"));
@@ -899,8 +864,7 @@ void writeWitchOS_WS()
display_Clear();
- if (myFile.open(filePath, O_READ))
- {
+ if (myFile.open(filePath, O_READ)) {
println_Msg(F("Erasing OS..."));
display_Update();
eraseWitchFlashSector_WS(0xe0000);
@@ -930,8 +894,7 @@ void writeWitchOS_WS()
writeWord_WS(0x80aaa, 0x2020);
// 128bytes per block
- for (i = 0; i < fbin_length; i += 128)
- {
+ for (i = 0; i < fbin_length; i += 128) {
// blink LED
if ((i & 0x3ff) == 0)
blinkLED();
@@ -940,8 +903,7 @@ void writeWitchOS_WS()
key = 0xff;
bytes_read = myFile.read(sdBuffer, 128);
- for (uint32_t j = 0; j < bytes_read; j += 2)
- {
+ for (uint32_t j = 0; j < bytes_read; j += 2) {
// for each decoded[n] = encoded[n] ^ key
// where key = encoded[n - 1]
// key = 0xff when n = 0, 0 <= n < 128
@@ -954,10 +916,10 @@ void writeWitchOS_WS()
// write jmpf instruction and block counts at 0xe0000
memcpy_P(sdBuffer, wwLaunchCode, 8);
- *((uint16_t*)(sdBuffer + 6)) = ((i >> 7) & 0xffff);
+ *((uint16_t *)(sdBuffer + 6)) = ((i >> 7) & 0xffff);
for (uint32_t i = 0; i < 8; i += 2)
- fastProgramWitchFlash_WS(0xefff0 + i, *((uint16_t*)(sdBuffer + i)));
+ fastProgramWitchFlash_WS(0xefff0 + i, *((uint16_t *)(sdBuffer + i)));
// leave fast program mode
dataOut_WS();
@@ -967,9 +929,7 @@ void writeWitchOS_WS()
myFile.close();
println_Msg(F("Done"));
- }
- else
- {
+ } else {
print_Error(F("File doesn't exist"), false);
}
}
@@ -978,19 +938,18 @@ void writeWitchOS_WS()
writeWord_WS(0x80000, 0xf0f0);
}
-void fastProgramWitchFlash_WS(uint32_t addr, uint16_t data)
-{
+void fastProgramWitchFlash_WS(uint32_t addr, uint16_t data) {
dataOut_WS();
writeWord_WS(addr, 0xa0a0);
writeWord_WS(addr, data);
dataIn_WS();
- while (readWord_WS(addr) != data);
+ while (readWord_WS(addr) != data)
+ ;
}
-void eraseWitchFlashSector_WS(uint32_t sector_addr)
-{
+void eraseWitchFlashSector_WS(uint32_t sector_addr) {
// blink LED
blinkLED();
@@ -1003,19 +962,18 @@ void eraseWitchFlashSector_WS(uint32_t sector_addr)
writeWord_WS(sector_addr, 0x3030);
dataIn_WS();
- while ((readWord_WS(sector_addr) & 0x0080) == 0x0000);
+ while ((readWord_WS(sector_addr) & 0x0080) == 0x0000)
+ ;
}
-boolean compareChecksum_WS(const char *wsFilePath)
-{
+boolean compareChecksum_WS(const char *wsFilePath) {
if (wsFilePath == NULL)
return 0;
println_Msg(F("Calculating Checksum"));
display_Update();
- if (!myFile.open(wsFilePath, O_READ))
- {
+ if (!myFile.open(wsFilePath, O_READ)) {
print_Error(F("Failed to open file"), false);
return 0;
}
@@ -1023,15 +981,13 @@ boolean compareChecksum_WS(const char *wsFilePath)
uint32_t calLength = myFile.fileSize() - 512;
uint32_t checksum = 0;
- if (wsWitch)
- {
+ if (wsWitch) {
// only calcuate last 128Kbytes for wonderwitch (OS and BIOS region)
myFile.seekCur(myFile.fileSize() - 131072);
calLength = 131072 - 512;
}
- for (uint32_t i = 0; i < calLength; i += 512)
- {
+ for (uint32_t i = 0; i < calLength; i += 512) {
myFile.read(sdBuffer, 512);
for (uint32_t j = 0; j < 512; j++)
checksum += sdBuffer[j];
@@ -1056,21 +1012,17 @@ boolean compareChecksum_WS(const char *wsFilePath)
print_Msg(F("Result: "));
println_Msg(result);
- if (checksum == calLength)
- {
+ if (checksum == calLength) {
println_Msg(F("Checksum matches"));
display_Update();
return 1;
- }
- else
- {
+ } else {
print_Error(F("Checksum Error"), false);
return 0;
}
}
-void writeByte_WSPort(uint8_t port, uint8_t data)
-{
+void writeByte_WSPort(uint8_t port, uint8_t data) {
PORTF = (port & 0x0f);
PORTL = (port >> 4);
@@ -1086,14 +1038,14 @@ void writeByte_WSPort(uint8_t port, uint8_t data)
// switch WE(PH5) to HIGH
PORTH |= (1 << 5);
- NOP; NOP;
+ NOP;
+ NOP;
// switch CART(PH3), MMC(PH4) to HIGH
PORTH |= ((1 << 3) | (1 << 4));
}
-uint8_t readByte_WSPort(uint8_t port)
-{
+uint8_t readByte_WSPort(uint8_t port) {
PORTF = (port & 0x0f);
PORTL = (port >> 4);
@@ -1102,7 +1054,9 @@ uint8_t readByte_WSPort(uint8_t port)
// switch OE(PH6) to LOW
PORTH &= ~(1 << 6);
- NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
uint8_t ret = PINC;
@@ -1115,8 +1069,7 @@ uint8_t readByte_WSPort(uint8_t port)
return ret;
}
-void writeWord_WS(uint32_t addr, uint16_t data)
-{
+void writeWord_WS(uint32_t addr, uint16_t data) {
PORTF = addr & 0xff;
PORTK = (addr >> 8) & 0xff;
PORTL = (addr >> 16) & 0x0f;
@@ -1130,18 +1083,20 @@ void writeWord_WS(uint32_t addr, uint16_t data)
// switch CART(PH3) and WE(PH5) to HIGH
PORTH |= (1 << 3) | (1 << 5);
- NOP; NOP;
+ NOP;
+ NOP;
}
-uint16_t readWord_WS(uint32_t addr)
-{
+uint16_t readWord_WS(uint32_t addr) {
PORTF = addr & 0xff;
PORTK = (addr >> 8) & 0xff;
PORTL = (addr >> 16) & 0x0f;
// switch CART(PH3) and OE(PH6) to LOW
PORTH &= ~((1 << 3) | (1 << 6));
- NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
uint16_t ret = ((PINA << 8) | PINC);
@@ -1151,8 +1106,7 @@ uint16_t readWord_WS(uint32_t addr)
return ret;
}
-void writeByte_WS(uint32_t addr, uint8_t data)
-{
+void writeByte_WS(uint32_t addr, uint8_t data) {
PORTF = addr & 0xff;
PORTK = (addr >> 8) & 0xff;
PORTL = (addr >> 16) & 0x0f;
@@ -1165,18 +1119,20 @@ void writeByte_WS(uint32_t addr, uint8_t data)
// switch CART(PH3) and WE(PH5) to HIGH
PORTH |= (1 << 3) | (1 << 5);
- NOP; NOP;
+ NOP;
+ NOP;
}
-uint8_t readByte_WS(uint32_t addr)
-{
+uint8_t readByte_WS(uint32_t addr) {
PORTF = addr & 0xff;
PORTK = (addr >> 8) & 0xff;
PORTL = (addr >> 16) & 0x0f;
// switch CART(PH3) and OE(PH6) to LOW
PORTH &= ~((1 << 3) | (1 << 6));
- NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
uint8_t ret = PINC;
@@ -1186,8 +1142,7 @@ uint8_t readByte_WS(uint32_t addr)
return ret;
}
-void unprotectEEPROM()
-{
+void unprotectEEPROM() {
generateEepromInstruction_WS(wsEepromShiftReg, 0x0, 0x3);
dataOut_WS();
@@ -1201,23 +1156,19 @@ void unprotectEEPROM()
// generate data for port 0xc6 to 0xc7
// number of CLK pulses needed for each instruction is 1 + (16 or 32) + 3
-void generateEepromInstruction_WS(uint8_t *instruction, uint8_t opcode, uint16_t addr)
-{
+void generateEepromInstruction_WS(uint8_t *instruction, uint8_t opcode, uint16_t addr) {
uint8_t addr_bits = (sramSize > 1 ? 10 : 6);
- uint16_t *ptr = (uint16_t*)instruction;
- *ptr = 0x0001; // initial with a start bit
+ uint16_t *ptr = (uint16_t *)instruction;
+ *ptr = 0x0001; // initial with a start bit
- if (opcode == 0)
- {
+ if (opcode == 0) {
// 2bits opcode = 0x00
*ptr <<= 2;
// 2bits ext cmd (from addr)
*ptr <<= 2;
*ptr |= (addr & 0x0003);
*ptr <<= (addr_bits - 2);
- }
- else
- {
+ } else {
// 2bits opcode
*ptr <<= 2;
*ptr |= (opcode & 0x03);
@@ -1230,8 +1181,7 @@ void generateEepromInstruction_WS(uint8_t *instruction, uint8_t opcode, uint16_t
// 2003 MMC need to be unlock,
// or it will reject all reading and bank switching
// All signals' timing are analyzed by using LogicAnalyzer
-boolean unlockMMC2003_WS()
-{
+boolean unlockMMC2003_WS() {
// initialize all control pin state
// RST(PH0) and CLK(PE3or5) to LOW
// CART(PH3) MMC(PH4) WE(PH5) OE(PH6) to HIGH
@@ -1261,8 +1211,7 @@ boolean unlockMMC2003_WS()
writeByte_WSPort(0xc3, 0x55);
dataIn_WS();
- if (readByte_WSPort(0xc2) == 0xaa && readByte_WSPort(0xc3) == 0x55)
- {
+ if (readByte_WSPort(0xc2) == 0xaa && readByte_WSPort(0xc3) == 0x55) {
// now set initial bank number to MMC
dataOut_WS();
writeByte_WSPort(0xc0, 0x2f);
@@ -1276,35 +1225,31 @@ boolean unlockMMC2003_WS()
}
// doing a L->H on CLK pin
-void pulseCLK_WS(uint8_t count)
-{
+void pulseCLK_WS(uint8_t count) {
register uint8_t tic;
// about 384KHz, 50% duty cycle
- asm volatile
- ("L0_%=:\n\t"
- "cpi %[count], 0\n\t"
- "breq L3_%=\n\t"
- "dec %[count]\n\t"
- "cbi %[porte], %[ws_clk_bit]\n\t"
- "ldi %[tic], 6\n\t"
- "L1_%=:\n\t"
- "dec %[tic]\n\t"
- "brne L1_%=\n\t"
- "sbi %[porte], %[ws_clk_bit]\n\t"
- "ldi %[tic], 5\n\t"
- "L2_%=:\n\t"
- "dec %[tic]\n\t"
- "brne L2_%=\n\t"
- "rjmp L0_%=\n\t"
- "L3_%=:\n\t"
- : [tic] "=a" (tic)
- : [count] "a" (count), [porte] "I" (_SFR_IO_ADDR(PORTE)), [ws_clk_bit] "I" (WS_CLK_BIT)
- );
+ asm volatile("L0_%=:\n\t"
+ "cpi %[count], 0\n\t"
+ "breq L3_%=\n\t"
+ "dec %[count]\n\t"
+ "cbi %[porte], %[ws_clk_bit]\n\t"
+ "ldi %[tic], 6\n\t"
+ "L1_%=:\n\t"
+ "dec %[tic]\n\t"
+ "brne L1_%=\n\t"
+ "sbi %[porte], %[ws_clk_bit]\n\t"
+ "ldi %[tic], 5\n\t"
+ "L2_%=:\n\t"
+ "dec %[tic]\n\t"
+ "brne L2_%=\n\t"
+ "rjmp L0_%=\n\t"
+ "L3_%=:\n\t"
+ : [tic] "=a"(tic)
+ : [count] "a"(count), [porte] "I"(_SFR_IO_ADDR(PORTE)), [ws_clk_bit] "I"(WS_CLK_BIT));
}
-void dataIn_WS()
-{
+void dataIn_WS() {
DDRC = 0x00;
DDRA = 0x00;
@@ -1314,8 +1259,7 @@ void dataIn_WS()
PORTA = 0x00;
}
-void dataOut_WS()
-{
+void dataOut_WS() {
DDRC = 0xff;
DDRA = 0xff;
}
@@ -1323,4 +1267,4 @@ void dataOut_WS()
#endif
//******************************************
// End of File
-//******************************************
+//****************************************** \ No newline at end of file
diff --git a/Cart_Reader/WSV.ino b/Cart_Reader/WSV.ino
index 0ed2984..d7ed265 100644
--- a/Cart_Reader/WSV.ino
+++ b/Cart_Reader/WSV.ino
@@ -38,9 +38,9 @@
// /WR - (PH5)
// /RD - (PH6)
-word WSV[] = {32, 64, 512};
-byte wsvlo = 0; // Lowest Entry
-byte wsvhi = 2; // Highest Entry
+word WSV[] = { 32, 64, 512 };
+byte wsvlo = 0; // Lowest Entry
+byte wsvhi = 2; // Highest Entry
byte wsvsize;
byte newwsvsize;
@@ -52,8 +52,7 @@ byte newwsvsize;
// SETUP
//******************************************
-void setup_WSV()
-{
+void setup_WSV() {
// Set Address Pins to Output
//A0-A7
DDRF = 0xFF;
@@ -87,7 +86,7 @@ void setup_WSV()
// Set Unused Pins HIGH
PORTL = 0xE0;
PORTA = 0xFF;
- PORTJ |= (1 << 0); // TIME(PJ0)
+ PORTJ |= (1 << 0); // TIME(PJ0)
checkStatus_WSV();
strcpy(romName, "SUPERVISION");
@@ -104,15 +103,13 @@ static const char wsvMenuItem1[] PROGMEM = "Select Cart";
static const char wsvMenuItem2[] PROGMEM = "Read ROM";
static const char wsvMenuItem3[] PROGMEM = "Set Size";
static const char wsvMenuItem4[] PROGMEM = "Reset";
-static const char* const menuOptionsSV[] PROGMEM = {wsvMenuItem1, wsvMenuItem2, wsvMenuItem3, wsvMenuItem4};
+static const char* const menuOptionsSV[] PROGMEM = { wsvMenuItem1, wsvMenuItem2, wsvMenuItem3, wsvMenuItem4 };
-void wsvMenu()
-{
+void wsvMenu() {
convertPgm(menuOptionsSV, 4);
uint8_t mainMenu = question_box(F("SUPERVISION MENU"), menuOptions, 4, 0);
- switch (mainMenu)
- {
+ switch (mainMenu) {
case 0:
// Select Cart
setCart_WSV();
@@ -157,25 +154,27 @@ void controlIn_WSV() {
PORTH &= ~(1 << 6);
}
-void dataIn_WSV()
-{
+void dataIn_WSV() {
DDRC = 0x00;
}
-void dataOut_WSV()
-{
+void dataOut_WSV() {
DDRC = 0xFF;
}
-uint8_t readByte_WSV(uint32_t addr)
-{
+uint8_t readByte_WSV(uint32_t addr) {
PORTF = addr & 0xFF;
PORTK = (addr >> 8) & 0xFF;
PORTL = (addr >> 16) & 0xFF;
// Wait for data bus
// 6 x 62.5ns = 375ns
- NOP; NOP; NOP; NOP; NOP; NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
+ NOP;
uint8_t ret = PINC;
NOP;
@@ -187,8 +186,7 @@ uint8_t readByte_WSV(uint32_t addr)
// READ CODE
//******************************************
-void readROM_WSV()
-{
+void readROM_WSV() {
strcpy(fileName, romName);
strcat(fileName, ".sv");
@@ -223,8 +221,7 @@ void readROM_WSV()
if (romSize < 64)
romStart = 0x8000;
uint32_t romEnd = (uint32_t)romSize * 0x400;
- for (uint32_t addr = 0; addr < romEnd; addr += 512)
- {
+ for (uint32_t addr = 0; addr < romEnd; addr += 512) {
for (uint16_t w = 0; w < 512; w++)
sdBuffer[w] = readByte_WSV(romStart + addr + w);
myFile.write(sdBuffer, 512);
@@ -245,8 +242,7 @@ void readROM_WSV()
// ROM SIZE
//******************************************
-void setROMSize_WSV()
-{
+void setROMSize_WSV() {
#if (defined(enable_OLED) || defined(enable_LCD))
display_Clear();
if (wsvlo == wsvhi)
@@ -270,7 +266,7 @@ void setROMSize_WSV()
while (1) {
b = checkButton();
- if (b == 2) { // Previous (doubleclick)
+ if (b == 2) { // Previous (doubleclick)
if (i == wsvlo)
i = wsvhi;
else
@@ -290,7 +286,7 @@ void setROMSize_WSV()
#endif
display_Update();
}
- if (b == 1) { // Next (press)
+ if (b == 1) { // Next (press)
if (i == wsvhi)
i = wsvlo;
else
@@ -310,12 +306,12 @@ void setROMSize_WSV()
#endif
display_Update();
}
- if (b == 3) { // Long Press - Execute (hold)
+ if (b == 3) { // Long Press - Execute (hold)
newwsvsize = i;
break;
}
}
- display.setCursor(0, 56); // Display selection at bottom
+ display.setCursor(0, 56); // Display selection at bottom
}
print_Msg(F("ROM SIZE "));
print_Msg(WSV[newwsvsize]);
@@ -354,11 +350,10 @@ setrom:
wsvsize = newwsvsize;
}
-void checkStatus_WSV()
-{
+void checkStatus_WSV() {
EEPROM_readAnything(8, wsvsize);
if (wsvsize > 2) {
- wsvsize = 1; // default 64K
+ wsvsize = 1; // default 64K
EEPROM_writeAnything(8, wsvsize);
}
@@ -416,12 +411,10 @@ void setCart_WSV() {
while (1) {
if (myFile.curPosition() == 0) {
break;
- }
- else if (myFile.peek() == '\n') {
+ } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1);
break;
- }
- else {
+ } else {
myFile.seekSet(myFile.curPosition() - 1);
}
}
@@ -463,9 +456,8 @@ void setCart_WSV() {
// Remove leading 0 for single digit cart sizes
if (cartSize != 0) {
- cartSize = cartSize * 10 + myFile.read() - 48;
- }
- else {
+ cartSize = cartSize * 10 + myFile.read() - 48;
+ } else {
cartSize = myFile.read() - 48;
}
@@ -513,12 +505,10 @@ void setCart_WSV() {
while (1) {
if (myFile.curPosition() == 0) {
break;
- }
- else if (myFile.peek() == '\n') {
+ } else if (myFile.peek() == '\n') {
myFile.seekSet(myFile.curPosition() - 1);
break;
- }
- else {
+ } else {
myFile.seekSet(myFile.curPosition() - 1);
}
}
@@ -550,12 +540,11 @@ void setCart_WSV() {
}
}
}
- }
- else {
+ } else {
print_Error(F("Database file not found"), true);
}
}
#endif
//******************************************
// End of File
-//******************************************
+//****************************************** \ No newline at end of file