cartreader/Cart_Reader
2019-09-26 18:33:08 +08:00
..
Cart_Reader.ino Add support for EMS GB Smart 32M flash cart 2019-09-26 13:38:03 +08:00
FLASH.ino Add support for MBM29F800BA/AM29F800BB and LH28F016SUT 2019-09-26 18:33:08 +08:00
GB.ino Add support for EMS GB Smart 32M flash cart 2019-09-26 13:38:03 +08:00
GBA.ino n64_speedup: roughly double n64 dumping performance by using the 1024 byte file buffer and combining the checksum and dumping code; also some cleanup 2019-08-28 23:48:44 +02:00
GBSmart.ino Add support for EMS GB Smart 32M flash cart 2019-09-26 13:38:03 +08:00
MD.ino SNES, MD: avoid dumping/writing 0 Byte files to SD card 2019-09-11 20:02:26 +02:00
N64.ino Update SMS.ino 2019-09-19 16:06:19 +02:00
NES.ino Update NES.ino 2019-09-18 22:43:49 +02:00
NP.ino Update NP.ino 2019-09-08 20:27:05 +02:00
PCE.ino V3.5 Change Menu and add Sega CD Ram Cart 2019-09-01 14:36:53 +02:00
README.md Update README.md 2019-09-05 08:18:19 +02:00
SMS.ino Update SMS.ino 2019-09-20 14:50:25 +02:00
SNES.ino SNES, MD: avoid dumping/writing 0 Byte files to SD card 2019-09-11 20:02:26 +02:00
SV.ino strings_to_flash: conserve ~ 800 byte SRAM by putting menu strings in progmem. Free bytes now: ~ 4000 2019-08-28 12:02:17 +02:00

This Arduino code is written by a beginner for beginners, therefore I tried to comment every line of code. To an experienced coder this probably will seem very wrong but it really helps if you're just starting out.

Source code files:

  • Cart_Reader.ino is the main file that contains functions and variables being used by multiple submodules and also the main menu
  • FLASH.ino is for reading and writing 29F016, 29F032, 29F033, 29F1610 and 29L3211 flashroms
  • GB.ino includes everything Game Boy and Game Boy Color
  • GBA.ino includes everything Game Boy Advance
  • MD.ino includes everything for the SEGA Mega Drive
  • N64.ino includes everything Nintendo 64
  • NES.ino includes everything for the Nintendo Entertainment System
  • NP.ino includes everything for Nintendo Power SF Memory and GB Memory cartridges
  • PCE.ino includes everything for the PC Engine/TG16
  • SMS.ino includes everything for the SEGA Master System
  • SNES.ino includes everything Super Nintendo
  • SV.ino includes everything for the Super Nintendo Satellaview

Every submodule has it's own setup_XX() function that configures the needed pins and a submenu that lets you choose what you want to do. The code directly addresses the pins via the DDR, PIN and PORT registers.
Please also refer to the pinout Excel sheet.

void setup_N64_Controller() {  
  // Output a low signal  
  PORTH &= ~(1 << 4);  
  // Set Controller Data Pin(PH4) to Input  
  DDRH &= ~(1 << 4);  
}  

Would be the same as this in a more traditional Arduino sketch:

int dataPin = 7;   

void setup(){    
  // Output a low signal   
  digitalWrite(dataPin, LOW);   
  // Set controller data pin to input  
  pinMode(dataPin, INPUT);  
}  

To preserve memory every string is saved into the flash of the Arduino, also called progmem. This is done by using the F() macro.

println_Msg(F("Press Button."));  

Also all the menus are stored in progmem and are only recalled to sram when needed.

// N64 controller menu items  
const char N64ContMenuItem1[] PROGMEM = "Test Controller";  
const char N64ContMenuItem2[] PROGMEM = "Read ControllerPak";  
const char N64ContMenuItem3[] PROGMEM = "Write ControllerPak";  
const char N64ContMenuItem4[] PROGMEM = "Reset";  
const char* const menuOptionsN64Controller[] PROGMEM = {N64ContMenuItem1, N64ContMenuItem2, N64ContMenuItem3, N64ContMenuItem4};  

In an effort to keep the codebase as portable as possible instead of using the functions supplied by the OLED library directly to print out text, auxiliary functions like println_Msg are being used. So if you want to change to another display library you don't need to change all the code but only the helper functions.

void print_Msg(long unsigned int message) {
  if (enable_OLED)
    display.print(message);
  if (enable_Serial)
    Serial.print(message);
}

For development purposes you can route all the text output to the Arduino's Serial Monitor instead of to the OLED screen. In this case you control the cart reader by typing numbers into the serial monitor corresponding to the action you want to perform. If you are asked to press the button just send a random number.

// Comment out to change to Serial Output
// be sure to change the Arduino Serial Monitor to no line ending
//#define enable_OLED

To compile and upload the code please have a look at this wiki article.