Add menu for GB Camera Flashcart

This one: https://github.com/HDR/Gameboy-Camera-Flashcart
This commit is contained in:
sanni 2022-03-08 18:13:04 +01:00
parent f66d4f83ec
commit 02e78fa06b
4 changed files with 162 additions and 99 deletions

View File

@ -4,8 +4,8 @@
This project represents a community-driven effort to provide This project represents a community-driven effort to provide
an easy to build and easy to modify cartridge dumper. an easy to build and easy to modify cartridge dumper.
Date: 27.02.2022 Date: 08.03.2022
Version: 7.8 Version: 7.9
SD lib: https://github.com/greiman/SdFat SD lib: https://github.com/greiman/SdFat
OLED lib: https://github.com/adafruit/Adafruit_SSD1306 OLED lib: https://github.com/adafruit/Adafruit_SSD1306
@ -45,7 +45,7 @@
**********************************************************************************/ **********************************************************************************/
char ver[5] = "7.8"; char ver[5] = "7.9";
/****************************************** /******************************************
Libraries Libraries

View File

@ -20,8 +20,9 @@ word lastByte = 0;
static const char gbxMenuItem1[] PROGMEM = "Game Boy (Color)"; static const char gbxMenuItem1[] PROGMEM = "Game Boy (Color)";
static const char gbxMenuItem2[] PROGMEM = "Game Boy Advance"; static const char gbxMenuItem2[] PROGMEM = "Game Boy Advance";
static const char gbxMenuItem3[] PROGMEM = "Flash GBC Cart"; static const char gbxMenuItem3[] PROGMEM = "Flash GBC Cart";
static const char gbxMenuItem4[] PROGMEM = "Reset"; static const char gbxMenuItem4[] PROGMEM = "NPower GB Memory";
static const char* const menuOptionsGBx[] PROGMEM = {gbxMenuItem1, gbxMenuItem2, gbxMenuItem3, gbxMenuItem4}; static const char gbxMenuItem5[] PROGMEM = "Reset";
static const char* const menuOptionsGBx[] PROGMEM = {gbxMenuItem1, gbxMenuItem2, gbxMenuItem3, gbxMenuItem4, gbxMenuItem5};
// GB menu items // GB menu items
static const char GBMenuItem1[] PROGMEM = "Read Rom"; static const char GBMenuItem1[] PROGMEM = "Read Rom";
@ -31,11 +32,11 @@ 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 // GB Flash items
static const char GBFlashItem1[] PROGMEM = "CFI Cart"; static const char GBFlashItem1[] PROGMEM = "29F Cart (MBC3)";
static const char GBFlashItem2[] PROGMEM = "CFI Cart and Save"; static const char GBFlashItem2[] PROGMEM = "29F Cart (MBC5)";
static const char GBFlashItem3[] PROGMEM = "29F Cart (MBC3)"; static const char GBFlashItem3[] PROGMEM = "29F Cart (CAM)";
static const char GBFlashItem4[] PROGMEM = "29F Cart (MBC5)"; static const char GBFlashItem4[] PROGMEM = "CFI Cart";
static const char GBFlashItem5[] PROGMEM = "NPower GB Memory"; static const char GBFlashItem5[] PROGMEM = "CFI Cart and Save";
static const char GBFlashItem6[] PROGMEM = "GB Smart"; static const char GBFlashItem6[] PROGMEM = "GB Smart";
static const char GBFlashItem7[] PROGMEM = "Reset"; 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};
@ -45,8 +46,8 @@ void gbxMenu() {
// create menu with title and 4 options to choose from // create menu with title and 4 options to choose from
unsigned char gbType; unsigned char gbType;
// Copy menuOptions out of progmem // Copy menuOptions out of progmem
convertPgm(menuOptionsGBx, 4); convertPgm(menuOptionsGBx, 5);
gbType = question_box(F("Select Game Boy"), menuOptions, 4, 0); gbType = question_box(F("Select Game Boy"), menuOptions, 5, 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 (gbType) switch (gbType)
@ -76,6 +77,83 @@ void gbxMenu() {
switch (gbFlash) switch (gbFlash)
{ {
case 0: case 0:
//Flash MBC3
display_Clear();
display_Update();
setup_GB();
mode = mode_GB;
// Change working dir to root
sd.chdir("/");
//MBC3
writeFlash29F_GB(3, 1);
// Reset
println_Msg(F("Press Button..."));
display_Update();
wait();
resetArduino();
break;
case 1:
//Flash MBC5
display_Clear();
display_Update();
setup_GB();
mode = mode_GB;
// Change working dir to root
sd.chdir("/");
//MBC5
writeFlash29F_GB(5, 1);
// Reset
println_Msg(F("Press Button..."));
display_Update();
wait();
resetArduino();
break;
case 2:
//Flash GB Camera
display_Clear();
display_Update();
setup_GB();
mode = mode_GB;
//Flash first bank with erase
// Change working dir to root
sd.chdir("/");
//MBC3
writeFlash29F_GB(3, 1);
println_Msg(F("Press Button..."));
display_Update();
wait();
display_Clear();
println_Msg(F("Please change the"));
println_Msg(F("switch on the cart"));
println_Msg(F("to B2 (Bank 2)"));
println_Msg(F("if you want to flash"));
println_Msg(F("a second game"));
println_Msg(F(""));
println_Msg(F("Press Button..."));
display_Update();
wait();
// Flash second bank without erase
// Change working dir to root
sd.chdir("/");
//MBC3
writeFlash29F_GB(3, 0);
// Reset
println_Msg(F(""));
println_Msg(F("Press Button..."));
display_Update();
wait();
resetArduino();
break;
case 3:
// Flash CFI // Flash CFI
display_Clear(); display_Clear();
display_Update(); display_Update();
@ -102,7 +180,7 @@ void gbxMenu() {
resetArduino(); resetArduino();
break; break;
case 1: case 4:
// Flash CFI and Save // Flash CFI and Save
display_Clear(); display_Clear();
display_Update(); display_Update();
@ -178,46 +256,6 @@ void gbxMenu() {
resetArduino(); resetArduino();
break; break;
case 2:
//Flash MBC3
display_Clear();
display_Update();
setup_GB();
mode = mode_GB;
// Change working dir to root
sd.chdir("/");
//MBC3
writeFlash29F_GB(3);
// Reset
wait();
resetArduino();
break;
case 3:
//Flash MBC5
display_Clear();
display_Update();
setup_GB();
mode = mode_GB;
// Change working dir to root
sd.chdir("/");
//MBC5
writeFlash29F_GB(5);
// Reset
wait();
resetArduino();
break;
case 4:
// Flash GB Memory
display_Clear();
display_Update();
setup_GBM();
mode = mode_GBM;
break;
case 5: case 5:
// Flash GB Smart // Flash GB Smart
display_Clear(); display_Clear();
@ -233,6 +271,14 @@ void gbxMenu() {
break; break;
case 3: case 3:
// Flash GB Memory
display_Clear();
display_Update();
setup_GBM();
mode = mode_GBM;
break;
case 4:
resetArduino(); resetArduino();
break; break;
} }
@ -666,7 +712,7 @@ void readROM_GB() {
//Initialize progress bar //Initialize progress bar
uint32_t processedProgressBar = 0; uint32_t processedProgressBar = 0;
uint32_t totalProgressBar = (uint32_t)(romBanks - 1); uint32_t totalProgressBar = (uint32_t)(romBanks - 2);
draw_progressbar(0, totalProgressBar); draw_progressbar(0, totalProgressBar);
for (word currBank = 1; currBank < romBanks; currBank++) { for (word currBank = 1; currBank < romBanks; currBank++) {
@ -966,7 +1012,7 @@ unsigned long verifySRAM_GB() {
// Write 29F032 flashrom // Write 29F032 flashrom
// A0-A13 directly connected to cart edge -> 16384(0x0-0x3FFF) bytes per bank -> 256(0x0-0xFF) banks // A0-A13 directly connected to cart edge -> 16384(0x0-0x3FFF) bytes per bank -> 256(0x0-0xFF) banks
// A14-A21 connected to MBC5 // A14-A21 connected to MBC5
void writeFlash29F_GB(byte MBC) { void writeFlash29F_GB(byte MBC, boolean flashErase) {
// Launch filebrowser // Launch filebrowser
filePath[0] = '\0'; filePath[0] = '\0';
sd.chdir("/"); sd.chdir("/");
@ -1085,6 +1131,8 @@ void writeFlash29F_GB(byte MBC) {
writeByte_GB(0x555, 0xf0); writeByte_GB(0x555, 0xf0);
delay(100); delay(100);
if (flashErase) {
println_Msg(F("Erasing flash")); println_Msg(F("Erasing flash"));
display_Update(); display_Update();
@ -1137,6 +1185,7 @@ void writeFlash29F_GB(byte MBC) {
} }
} }
} }
}
if (MBC == 3) { if (MBC == 3) {
println_Msg(F("Writing flash MBC3")); println_Msg(F("Writing flash MBC3"));
@ -1148,6 +1197,11 @@ void writeFlash29F_GB(byte MBC) {
word currAddr = 0; word currAddr = 0;
word endAddr = 0x3FFF; word endAddr = 0x3FFF;
//Initialize progress bar
uint32_t processedProgressBar = 0;
uint32_t totalProgressBar = (uint32_t)(romBanks - 2);
draw_progressbar(0, totalProgressBar);
for (int currBank = 0; currBank < romBanks; currBank++) { for (int currBank = 0; currBank < romBanks; currBank++) {
// Blink led // Blink led
blinkLED(); blinkLED();
@ -1189,6 +1243,8 @@ void writeFlash29F_GB(byte MBC) {
} }
currAddr += 512; currAddr += 512;
} }
processedProgressBar += 1;
draw_progressbar(processedProgressBar, totalProgressBar);
} }
} }
@ -1199,6 +1255,11 @@ void writeFlash29F_GB(byte MBC) {
// Write flash // Write flash
dataOut(); dataOut();
//Initialize progress bar
uint32_t processedProgressBar = 0;
uint32_t totalProgressBar = (uint32_t)(romBanks - 2);
draw_progressbar(0, totalProgressBar);
for (int currBank = 0; currBank < romBanks; currBank++) { for (int currBank = 0; currBank < romBanks; currBank++) {
// Blink led // Blink led
blinkLED(); blinkLED();
@ -1236,13 +1297,15 @@ void writeFlash29F_GB(byte MBC) {
dataOut(); dataOut();
} }
} }
processedProgressBar += 1;
draw_progressbar(processedProgressBar, totalProgressBar);
} }
} }
// Set data pins to input again // Set data pins to input again
dataIn_GB(); dataIn_GB();
println_Msg(F("Verifying")); print_Msg(F("Verifying..."));
display_Update(); display_Update();
// Go back to file beginning // Go back to file beginning
@ -1297,10 +1360,10 @@ void writeFlash29F_GB(byte MBC) {
display_Update(); display_Update();
} }
else { else {
print_Msg(F("Error: ")); println_Msg(F("Error"));
print_Msg(writeErrors); print_Msg(writeErrors);
println_Msg(F(" bytes ")); println_Msg(F(" bytes "));
print_Error(F("did not verify."), false); print_Error(F("did not verify."), true);
} }
} }
else { else {

View File

@ -2,7 +2,7 @@
// !!! CHOOSE HARDWARE VERSION !!! // !!! CHOOSE HARDWARE VERSION !!!
//****************************************** //******************************************
// Remove // in front of the line with your hardware version // Remove // in front of the line with your hardware version
#define HW4 //#define HW4
//#define HW3 //#define HW3
//#define HW2 //#define HW2
//#define HW1 //#define HW1

View File

@ -56,7 +56,7 @@ int32_t initializeClockOffset() {
i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, clock_offset); i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, clock_offset);
} else { } else {
i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0); i2c_found = clockgen.init(SI5351_CRYSTAL_LOAD_8PF, 0, 0);
if(clock_file.open("/snes_clk.txt", O_WRITE | O_CREAT | O_TRUNC)) { if (clock_file.open("/snes_clk.txt", O_WRITE | O_CREAT | O_TRUNC)) {
clock_file.write(zero_char_arr, 1); clock_file.write(zero_char_arr, 1);
clock_file.close(); clock_file.close();
} }