V22 Added GBA database

This commit is contained in:
sanni 2017-02-11 16:45:16 +01:00 committed by GitHub
parent 6d65a0adde
commit 5cfdb5cb98
3 changed files with 259 additions and 54 deletions

View File

@ -2,8 +2,8 @@
Cartridge Reader for Arduino Mega2560 Cartridge Reader for Arduino Mega2560
Author: sanni Author: sanni
Date: 2017-01-30 Date: 2017-02-11
Version: V21A Version: V22
SD lib: https://github.com/greiman/SdFat SD lib: https://github.com/greiman/SdFat
LCD lib: https://github.com/adafruit/Adafruit_SSD1306 LCD lib: https://github.com/adafruit/Adafruit_SSD1306
@ -34,7 +34,7 @@
YamaArashi - GBA flashrom bank switch command YamaArashi - GBA flashrom bank switch command
**********************************************************************************/ **********************************************************************************/
char ver[5] = "V21A"; char ver[5] = "V22";
/****************************************** /******************************************
Define Output Define Output
@ -181,6 +181,7 @@ char fileOptions[30][20];
char romName[10]; char romName[10];
int sramSize = 0; int sramSize = 0;
int romType = 0; int romType = 0;
byte saveType;
int romSize = 0; int romSize = 0;
byte numBanks = 128; byte numBanks = 128;
char checksumStr[5]; char checksumStr[5];
@ -337,7 +338,7 @@ const char flashMenuItem2[] PROGMEM = "16bit slot";
const char* const menuOptionsFlash[] PROGMEM = {flashMenuItem1, flashMenuItem2}; const char* const menuOptionsFlash[] PROGMEM = {flashMenuItem1, flashMenuItem2};
// GBx Submenu // GBx Submenu
const char gbxMenuItem1[] PROGMEM = "Game Boy Color"; const char gbxMenuItem1[] PROGMEM = "Game Boy (Color)";
const char gbxMenuItem2[] PROGMEM = "Game Boy Advance"; const char gbxMenuItem2[] PROGMEM = "Game Boy Advance";
const char* const menuOptionsGBx[] PROGMEM = {gbxMenuItem1, gbxMenuItem2}; const char* const menuOptionsGBx[] PROGMEM = {gbxMenuItem1, gbxMenuItem2};

View File

@ -32,11 +32,13 @@ const char GBAMenuItem4[] PROGMEM = "Reset";
const char* const menuOptionsGBA[] PROGMEM = {GBAMenuItem1, GBAMenuItem2, GBAMenuItem3, GBAMenuItem4}; const char* const menuOptionsGBA[] PROGMEM = {GBAMenuItem1, GBAMenuItem2, GBAMenuItem3, GBAMenuItem4};
// Rom menu // Rom menu
const char GBARomItem1[] PROGMEM = "4MB"; const char GBARomItem1[] PROGMEM = "1MB";
const char GBARomItem2[] PROGMEM = "8MB"; const char GBARomItem2[] PROGMEM = "2MB";
const char GBARomItem3[] PROGMEM = "16MB"; const char GBARomItem3[] PROGMEM = "4MB";
const char GBARomItem4[] PROGMEM = "32MB"; const char GBARomItem4[] PROGMEM = "8MB";
const char* const romOptionsGBA[] PROGMEM = {GBARomItem1, GBARomItem2, GBARomItem3, GBARomItem4}; const char GBARomItem5[] PROGMEM = "16MB";
const char GBARomItem6[] PROGMEM = "32MB";
const char* const romOptionsGBA[] PROGMEM = {GBARomItem1, GBARomItem2, GBARomItem3, GBARomItem4, GBARomItem5, GBARomItem6};
// Save menu // Save menu
const char GBASaveItem1[] PROGMEM = "4K EEPROM"; const char GBASaveItem1[] PROGMEM = "4K EEPROM";
@ -59,36 +61,75 @@ void gbaMenu() {
{ {
case 0: case 0:
// Read rom // Read rom
switch (cartSize)
{
case 0:
// create submenu with title and 4 options to choose from // create submenu with title and 4 options to choose from
unsigned char GBARomMenu; unsigned char GBARomMenu;
// Copy menuOptions out of progmem // Copy menuOptions out of progmem
convertPgm(romOptionsGBA, 4); convertPgm(romOptionsGBA, 6);
GBARomMenu = question_box("Select ROM size", menuOptions, 4, 0); GBARomMenu = question_box("Select ROM size", menuOptions, 6, 0);
// wait for user choice to come back from the question box menu // wait for user choice to come back from the question box menu
switch (GBARomMenu) switch (GBARomMenu)
{ {
case 0: case 0:
// 1MB
cartSize = 0x100000;
break;
case 1:
// 2MB
cartSize = 0x200000;
break;
case 2:
// 4MB // 4MB
cartSize = 0x400000; cartSize = 0x400000;
break; break;
case 1: case 3:
// 8MB // 8MB
cartSize = 0x800000; cartSize = 0x800000;
break; break;
case 2: case 4:
// 16MB // 16MB
cartSize = 0x1000000; cartSize = 0x1000000;
break; break;
case 3: case 5:
// 32MB // 32MB
cartSize = 0x2000000; cartSize = 0x2000000;
break; break;
} }
break;
case 1:
// 1MB
cartSize = 0x100000;
break;
case 4:
// 4MB
cartSize = 0x400000;
break;
case 8:
// 8MB
cartSize = 0x800000;
break;
case 16:
// 16MB
cartSize = 0x1000000;
break;
case 32:
// 32MB
cartSize = 0x2000000;
break;
}
display_Clear(); display_Clear();
// Change working dir to root // Change working dir to root
sd.chdir("/"); sd.chdir("/");
@ -99,6 +140,7 @@ void gbaMenu() {
case 1: case 1:
// Read save // Read save
if (saveType == 0) {
// create submenu with title and 6 options to choose from // create submenu with title and 6 options to choose from
unsigned char GBASaveMenu; unsigned char GBASaveMenu;
// Copy menuOptions out of progmem // Copy menuOptions out of progmem
@ -109,6 +151,39 @@ void gbaMenu() {
switch (GBASaveMenu) switch (GBASaveMenu)
{ {
case 0: case 0:
// 4K EEPROM
saveType = 1;
break;
case 1:
// 64K EEPROM
saveType = 2;
break;
case 2:
// 256K SRAM/FRAM
saveType = 3;
break;
case 3:
// 512K SRAM/FRAM
saveType = 6;
break;
case 4:
// 512K FLASH
saveType = 4;
break;
case 5:
// 1M FLASH
saveType = 5;
break;
}
}
switch (saveType)
{
case 1:
display_Clear(); display_Clear();
sd.chdir("/"); sd.chdir("/");
// 4K EEPROM // 4K EEPROM
@ -116,7 +191,7 @@ void gbaMenu() {
setROM_GBA(); setROM_GBA();
break; break;
case 1: case 2:
display_Clear(); display_Clear();
sd.chdir("/"); sd.chdir("/");
// 64K EEPROM // 64K EEPROM
@ -124,7 +199,7 @@ void gbaMenu() {
setROM_GBA(); setROM_GBA();
break; break;
case 2: case 3:
display_Clear(); display_Clear();
sd.chdir("/"); sd.chdir("/");
// 256K SRAM/FRAM // 256K SRAM/FRAM
@ -132,14 +207,6 @@ void gbaMenu() {
setROM_GBA(); setROM_GBA();
break; break;
case 3:
display_Clear();
sd.chdir("/");
// 512K SRAM/FRAM
readFRAM_GBA(65536);
setROM_GBA();
break;
case 4: case 4:
display_Clear(); display_Clear();
sd.chdir("/"); sd.chdir("/");
@ -160,21 +227,75 @@ void gbaMenu() {
readFLASH_GBA(0, 65536, 65536); readFLASH_GBA(0, 65536, 65536);
setROM_GBA(); setROM_GBA();
break; break;
case 6:
display_Clear();
sd.chdir("/");
// 512K SRAM/FRAM
// Change working dir to root
writeFRAM_GBA(1, 65536);
writeErrors = verifyFRAM_GBA(65536);
if (writeErrors == 0) {
println_Msg(F("Verified OK"));
display_Update();
}
else {
print_Msg(F("Error: "));
print_Msg(writeErrors);
println_Msg(F(" bytes "));
print_Error(F("did not verify."), false);
}
setROM_GBA();
break;
} }
break; break;
case 2: case 2:
// Write save // Write save
if (saveType == 0) {
// create submenu with title and 6 options to choose from // create submenu with title and 6 options to choose from
unsigned char GBASavesMenu; unsigned char GBASavesMenu;
// Copy menuOptions out of progmem // Copy menuOptions out of progmem
convertPgm(saveOptionsGBA, 6); convertPgm(saveOptionsGBA, 6);
GBASavesMenu = question_box("Select save type", menuOptions, 6, 0); GBASavesMenu = question_box("Select save type", menuOptions, 6, 0);
// wait for user choice to come back from the question box menu // wait for user choice to come back from the question box menu
switch (GBASavesMenu) switch (GBASavesMenu)
{ {
case 0: case 0:
// 4K EEPROM
saveType = 1;
break;
case 1:
// 64K EEPROM
saveType = 2;
break;
case 2:
// 256K SRAM/FRAM
saveType = 3;
break;
case 3:
// 512K SRAM/FRAM
saveType = 6;
break;
case 4:
// 512K FLASH
saveType = 4;
break;
case 5:
// 1024K FLASH
saveType = 5;
break;
}
}
switch (saveType)
{
case 1:
display_Clear(); display_Clear();
sd.chdir("/"); sd.chdir("/");
// 4K EEPROM // 4K EEPROM
@ -193,7 +314,7 @@ void gbaMenu() {
setROM_GBA(); setROM_GBA();
break; break;
case 1: case 2:
display_Clear(); display_Clear();
sd.chdir("/"); sd.chdir("/");
// 64K EEPROM // 64K EEPROM
@ -212,7 +333,7 @@ void gbaMenu() {
setROM_GBA(); setROM_GBA();
break; break;
case 2: case 3:
display_Clear(); display_Clear();
sd.chdir("/"); sd.chdir("/");
// 256K SRAM/FRAM // 256K SRAM/FRAM
@ -232,7 +353,7 @@ void gbaMenu() {
setROM_GBA(); setROM_GBA();
break; break;
case 3: case 6:
display_Clear(); display_Clear();
sd.chdir("/"); sd.chdir("/");
// 512K SRAM/FRAM // 512K SRAM/FRAM
@ -333,16 +454,49 @@ void setup_GBA() {
display_Clear(); display_Clear();
println_Msg(F("GBA Cart Info")); println_Msg(F("GBA Cart Info"));
println_Msg("");
print_Msg(F("Rom Name: ")); print_Msg(F("Rom Name: "));
println_Msg(romName); println_Msg(romName);
print_Msg(F("Cart ID: ")); print_Msg(F("Cart ID: "));
println_Msg(cartID); println_Msg(cartID);
print_Msg(F("Rom Size: "));
if (cartSize == 0)
println_Msg(F("Unknown"));
else {
print_Msg(cartSize);
println_Msg(F("MB"));
}
print_Msg(F("Save: "));
switch (saveType)
{
case 0:
println_Msg(F("Unknown"));
break;
case 1:
println_Msg(F("4K Eeprom"));
break;
case 2:
println_Msg(F("64K Eeprom"));
break;
case 3:
println_Msg(F("256K Sram"));
break;
case 4:
println_Msg(F("512K Flash"));
break;
case 5:
println_Msg(F("1024K Flash"));
break;
}
print_Msg(F("Checksum: ")); print_Msg(F("Checksum: "));
println_Msg(checksumStr); println_Msg(checksumStr);
print_Msg(F("Version: 1.")); print_Msg(F("Version: 1."));
println_Msg(romVersion); println_Msg(romVersion);
println_Msg("");
// Wait for user input // Wait for user input
println_Msg(F("Press Button...")); println_Msg(F("Press Button..."));
@ -521,12 +675,64 @@ void getCartInfo_GBA() {
print_Error(F("Nintendo Logo Error"), true); print_Error(F("Nintendo Logo Error"), true);
} }
else { else {
char tempStr2[2];
char tempStr[5];
char sizeStr[3];
char saveStr[2];
// cart not in list
cartSize = 0;
saveType = 0;
// Get cart ID // Get cart ID
cartID[0] = char(sdBuffer[0xAC]); cartID[0] = char(sdBuffer[0xAC]);
cartID[1] = char(sdBuffer[0xAD]); cartID[1] = char(sdBuffer[0xAD]);
cartID[2] = char(sdBuffer[0xAE]); cartID[2] = char(sdBuffer[0xAE]);
cartID[3] = char(sdBuffer[0xAF]); cartID[3] = char(sdBuffer[0xAF]);
if (myFile.open("gba.txt", O_READ)) {
// Loop through file
while (myFile.available()) {
// Read 4 bytes into String, do it one at a time so byte order doesn't get mixed up
sprintf(tempStr, "%c", myFile.read());
for (byte i = 0; i < 3; i++) {
sprintf(tempStr2, "%c", myFile.read());
strcat(tempStr, tempStr2);
}
// Check if string is a match
if (strcmp(tempStr, cartID) == 0) {
// Skip the , in the file
myFile.seekSet(myFile.curPosition() + 1);
// Read the next ascii character and subtract 48 to convert to decimal
cartSize = myFile.read() - 48;
// Remove leading 0 for single digit cart sizes
if (cartSize != 0) {
cartSize = cartSize * 10 + myFile.read() - 48;
}
else {
cartSize = myFile.read() - 48;
}
// Skip the , in the file
myFile.seekSet(myFile.curPosition() + 1);
// Read the next ascii character and subtract 48 to convert to decimal
saveType = myFile.read() - 48;
}
// If no match, empty string, advance by 7 and try again
else {
myFile.seekSet(myFile.curPosition() + 7);
}
}
// Close the file:
myFile.close();
}
else {
print_Error(F("GBA.txt missing"), true);
}
// Dump name into 8.3 compatible format // Dump name into 8.3 compatible format
byte myByte = 0; byte myByte = 0;
byte myLength = 0; byte myLength = 0;

View File

@ -19,8 +19,6 @@
// Received N64 Eeprom data bits, 1 page // Received N64 Eeprom data bits, 1 page
bool tempBits[65]; bool tempBits[65];
int eepPages; int eepPages;
// Savetype
byte saveType;
// N64 Controller // N64 Controller
// 256 bits of received Controller data // 256 bits of received Controller data