mirror of
https://github.com/sanni/cartreader.git
synced 2024-11-27 15:04:15 +01:00
Move to Arduino IDE 2.0.0 (different auto formatting, no code changes)
This commit is contained in:
parent
6ddb206a63
commit
4badfff458
@ -54,8 +54,7 @@ static const char colMenuItem3[] PROGMEM = "Set Size";
|
||||
static const char colMenuItem4[] PROGMEM = "Reset";
|
||||
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
|
||||
@ -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,8 +131,7 @@ 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
|
||||
@ -157,8 +153,7 @@ uint8_t readData_COL(uint32_t addr)
|
||||
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");
|
||||
|
||||
@ -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)
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -452,8 +442,7 @@ void setCart_COL() {
|
||||
// Remove leading 0 for single digit cart sizes
|
||||
if (cartSize != 0) {
|
||||
cartSize = cartSize * 10 + myFile.read() - 48;
|
||||
}
|
||||
else {
|
||||
} 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,8 +538,7 @@ void setCart_COL() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
print_Error(F("Database file not found"), true);
|
||||
}
|
||||
}
|
||||
|
@ -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 !!!
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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,19 +520,16 @@ 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')
|
||||
{
|
||||
if (str_buf == '\r') {
|
||||
readfile->read(); //dispose \n because \r\n
|
||||
break;
|
||||
}
|
||||
@ -542,18 +538,15 @@ void skip_line(FsFile* readfile)
|
||||
}
|
||||
|
||||
//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,8 +554,7 @@ 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
|
||||
break;
|
||||
@ -573,7 +565,7 @@ void get_line(char* str_buf, FsFile* readfile, uint8_t maxi)
|
||||
|
||||
// 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();
|
||||
@ -608,8 +599,7 @@ boolean compareCRC(char* database, char* crcString, boolean renamerom, int offse
|
||||
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;
|
||||
@ -716,12 +703,10 @@ byte starting_letter() {
|
||||
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);
|
||||
@ -739,12 +724,10 @@ byte starting_letter() {
|
||||
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);
|
||||
@ -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();
|
||||
}
|
||||
@ -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("*"));
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
@ -1529,8 +1502,7 @@ void clkcal() {
|
||||
|
||||
if (a == 3) { //button short hold
|
||||
cal_offset *= 10ULL;
|
||||
if (cal_offset > 100000000ULL)
|
||||
{
|
||||
if (cal_offset > 100000000ULL) {
|
||||
cal_offset = 1;
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
@ -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(""));
|
||||
@ -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,8 +1893,7 @@ void save_log() {
|
||||
str_buf = myLog.read();
|
||||
|
||||
//break out of loop if CRLF is found
|
||||
if (str_buf == '\r')
|
||||
{
|
||||
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();
|
||||
@ -2007,8 +1973,7 @@ void print_Msg(const char myString[]) {
|
||||
display.print(myString[strPos]);
|
||||
strPos++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
display.print(myString);
|
||||
}
|
||||
#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);
|
||||
@ -2379,8 +2343,7 @@ byte questionBox_Serial(const __FlashStringHelper * question, char answers[7][20
|
||||
if (currPage > 1) {
|
||||
lastPage = currPage;
|
||||
currPage--;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
root = 1;
|
||||
}
|
||||
}
|
||||
@ -2446,8 +2409,7 @@ unsigned char questionBox_Display(const __FlashStringHelper * question, char ans
|
||||
if (currentColor == 1) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -2511,8 +2470,7 @@ unsigned char questionBox_Display(const __FlashStringHelper * question, char ans
|
||||
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) {
|
||||
@ -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();
|
||||
@ -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
|
||||
|
@ -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();
|
||||
@ -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("");
|
||||
}
|
||||
@ -819,8 +779,7 @@ 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);
|
||||
}
|
||||
@ -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,8 +863,7 @@ 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);
|
||||
}
|
||||
@ -899,19 +872,34 @@ byte readByte_Flash(unsigned long myAddress) {
|
||||
}
|
||||
|
||||
// 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,7 +950,12 @@ 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);
|
||||
@ -961,7 +964,12 @@ word readWord_Flash(unsigned long myAddress) {
|
||||
|
||||
// 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();
|
||||
}
|
||||
@ -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)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1680,7 +1681,8 @@ void writeFlashLH28F0XX() {
|
||||
|
||||
// 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();
|
||||
}
|
||||
@ -1884,8 +1883,7 @@ void writeFlash16() {
|
||||
|
||||
// Close the file:
|
||||
myFile.close();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
println_Msg(F("Can't open file on SD."));
|
||||
display_Update();
|
||||
}
|
||||
@ -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) {
|
||||
@ -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);
|
||||
@ -2302,13 +2299,18 @@ word writeWord_Eprom(unsigned long myAddress, word myData) {
|
||||
// Read
|
||||
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,7 +2331,12 @@ 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);
|
||||
@ -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) {
|
||||
@ -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();
|
||||
}
|
||||
|
@ -48,8 +48,7 @@ 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();
|
||||
@ -72,8 +71,7 @@ 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();
|
||||
@ -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
|
||||
@ -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,14 +628,20 @@ 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;
|
||||
@ -641,12 +651,14 @@ byte readByteSRAM_GB(word myAddress) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -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();
|
||||
@ -1807,8 +1803,7 @@ void writeFlash29F_GB(byte MBC, boolean flashErase) {
|
||||
for (word bank = 1; bank < romBanks; bank++) {
|
||||
if (romType >= 5) { // MBC2 and above
|
||||
writeByte_GB(0x2100, bank); // Set ROM bank
|
||||
}
|
||||
else { // MBC1
|
||||
} 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
|
||||
@ -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();
|
||||
}
|
||||
@ -2148,7 +2141,6 @@ 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
|
||||
|
||||
}
|
||||
currAddr += 512;
|
||||
}
|
||||
@ -2170,8 +2162,7 @@ bool writeCFI_GB() {
|
||||
for (word bank = 1; bank < romBanks; bank++) {
|
||||
if (romType >= 5) { // MBC2 and above
|
||||
writeByte_GB(0x2100, bank); // Set ROM bank
|
||||
}
|
||||
else { // MBC1
|
||||
} 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
|
||||
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
@ -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
|
||||
@ -642,7 +623,10 @@ word readWord_GBA(unsigned long myAddress) {
|
||||
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;
|
||||
|
||||
@ -672,7 +656,8 @@ void writeWord_GBA(unsigned long myAddress, word myWord) {
|
||||
// Pull CS(PH3) to LOW
|
||||
PORTH &= ~(1 << 3);
|
||||
|
||||
__asm__("nop\n\t""nop\n\t");
|
||||
__asm__("nop\n\t"
|
||||
"nop\n\t");
|
||||
|
||||
// Output data
|
||||
PORTF = myWord & 0xFF;
|
||||
@ -681,7 +666,8 @@ void writeWord_GBA(unsigned long myAddress, word myWord) {
|
||||
// Pull WR(PH5) to LOW
|
||||
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,8 +677,7 @@ 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;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -906,8 +918,7 @@ void getCartInfo_GBA() {
|
||||
// Remove leading 0 for single digit cart sizes
|
||||
if (cartSize != 0) {
|
||||
cartSize = cartSize * 10 + myFile.read() - 48;
|
||||
}
|
||||
else {
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
|
||||
// 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;
|
||||
@ -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);
|
||||
|
||||
// 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);
|
||||
|
||||
// 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
|
||||
@ -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);
|
||||
}
|
||||
@ -2055,8 +2075,7 @@ void send_GBA(word currAddr, word numBits) {
|
||||
PORTH &= ~(1 << 5);
|
||||
// Set WR(PH5) to High
|
||||
PORTH |= (1 << 5);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Set A0(PF0) to Low
|
||||
PORTF &= ~(1 << 0);
|
||||
// Set WR(PH5) to LOW
|
||||
@ -2084,7 +2103,8 @@ 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++) {
|
||||
@ -2108,12 +2128,18 @@ void writeBlock_EEP(word startAddr, word eepSize) {
|
||||
// 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++) {
|
||||
@ -2140,8 +2166,7 @@ void writeBlock_EEP(word startAddr, word eepSize) {
|
||||
PORTH &= ~((1 << 3) | (1 << 6));
|
||||
// Set CS_ROM(PH3) RD(PH6) to High
|
||||
PORTH |= (1 << 3) | (1 << 6);
|
||||
}
|
||||
while ((PINF & 0x1) == 0);
|
||||
} while ((PINF & 0x1) == 0);
|
||||
|
||||
// Set A0(PF0) to Output
|
||||
DDRF |= (1 << 0);
|
||||
@ -2165,7 +2190,8 @@ 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++) {
|
||||
@ -2187,8 +2213,7 @@ void readBlock_EEP(word startAddress, word eepSize) {
|
||||
// Send either 6 or 14 bit address
|
||||
if (eepSize == 4) {
|
||||
send_GBA(currAddr, 6);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
send_GBA(currAddr, 14);
|
||||
}
|
||||
|
||||
@ -2203,7 +2228,14 @@ void readBlock_EEP(word startAddress, word eepSize) {
|
||||
// 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
|
||||
@ -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"));
|
||||
@ -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"));
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
@ -179,15 +184,13 @@ void gbSmartMenu()
|
||||
}
|
||||
}
|
||||
|
||||
void gbSmartGameOptions()
|
||||
{
|
||||
void gbSmartGameOptions() {
|
||||
uint8_t gameSubMenu;
|
||||
|
||||
convertPgm(menuOptionsGBSmartGame, 5);
|
||||
gameSubMenu = question_box(F("GB Smart Game Menu"), menuOptions, 5, 0);
|
||||
|
||||
switch (gameSubMenu)
|
||||
{
|
||||
switch (gameSubMenu) {
|
||||
case 0: // Read Game
|
||||
{
|
||||
display_Clear();
|
||||
@ -209,13 +212,10 @@ void gbSmartGameOptions()
|
||||
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"));
|
||||
@ -236,8 +236,7 @@ void gbSmartGameOptions()
|
||||
}
|
||||
}
|
||||
|
||||
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,8 +336,7 @@ void gbSmartFlashMenu()
|
||||
wait();
|
||||
}
|
||||
|
||||
void gbSmartGetGames()
|
||||
{
|
||||
void gbSmartGetGames() {
|
||||
static const byte menu_title[] = { 0x47, 0x42, 0x31, 0x36, 0x4d };
|
||||
|
||||
// reset remap setting
|
||||
@ -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,10 +531,8 @@ 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
|
||||
@ -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,34 +724,24 @@ 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
|
||||
{
|
||||
} else {
|
||||
sram_size = 0x20; // 2KiB treat as 8KiB
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
sram_size = 0x30; // no sram
|
||||
}
|
||||
|
||||
|
@ -98,8 +98,7 @@ static const char intvMenuItem3[] PROGMEM = "Set Mapper + Size";
|
||||
static const char intvMenuItem4[] PROGMEM = "Reset";
|
||||
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;
|
||||
@ -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");
|
||||
|
||||
@ -440,7 +444,11 @@ 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;
|
||||
|
||||
@ -451,19 +459,30 @@ void ecsBank(uint32_t addr, uint8_t bank) {
|
||||
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;
|
||||
@ -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)
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -847,8 +862,7 @@ void setCart_INTV() {
|
||||
// Remove leading 0 for single digit cart sizes
|
||||
if (cartSize != 0) {
|
||||
cartSize = cartSize * 10 + myFile.read() - 48;
|
||||
}
|
||||
else {
|
||||
} 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,8 +962,7 @@ void setCart_INTV() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
print_Error(F("Database file not found"), true);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
@ -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,8 +429,7 @@ void segaCDMenu() {
|
||||
fileBrowser(F("Select brm file"));
|
||||
display_Clear();
|
||||
writeBram_MD();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
print_Error(F("Not CD Backup RAM Cart"), false);
|
||||
}
|
||||
break;
|
||||
@ -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,7 +549,12 @@ 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);
|
||||
@ -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,7 +624,14 @@ 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);
|
||||
@ -603,7 +640,14 @@ word readFlash_MD(unsigned long myAddress) {
|
||||
|
||||
// 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;
|
||||
}
|
||||
@ -808,15 +852,13 @@ void getCartInfo_MD() {
|
||||
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
|
||||
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,8 +870,7 @@ 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));
|
||||
@ -838,13 +879,11 @@ void getCartInfo_MD() {
|
||||
saveType = 3; // BOTH
|
||||
sramSize = sramEnd - sramBase + 2;
|
||||
sramBase = sramBase >> 1;
|
||||
}
|
||||
else if (sramBase == 0x200000) {
|
||||
} 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,8 +896,7 @@ 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)
|
||||
@ -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,7 +997,6 @@ void getCartInfo_MD() {
|
||||
case 4: strcat(romName, "SONIC3"); break;
|
||||
case 5: strcat(romName, romNameLockon); break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Realtec Mapper Check
|
||||
@ -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);
|
||||
@ -1150,8 +1196,7 @@ void readROM_MD() {
|
||||
if ((currBuffer == 0x200000) && (cartSize > 0x400000)) {
|
||||
writeSSF2Map(0x50987E, 8); // 0xA130FD
|
||||
offsetSSF2Bank = 1;
|
||||
}
|
||||
else if ((currBuffer == 0x240000) && (cartSize > 0x400000)) {
|
||||
} else if ((currBuffer == 0x240000) && (cartSize > 0x400000)) {
|
||||
writeSSF2Map(0x50987F, 9); // 0xA130FF
|
||||
offsetSSF2Bank = 1;
|
||||
}
|
||||
@ -1171,7 +1216,12 @@ 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;
|
||||
@ -1215,7 +1265,12 @@ 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;
|
||||
@ -1260,7 +1315,12 @@ 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;
|
||||
@ -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();
|
||||
@ -1461,8 +1526,7 @@ void readSram_MD() {
|
||||
} else {
|
||||
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,8 +1534,7 @@ void readSram_MD() {
|
||||
} else {
|
||||
sdBuffer[currWord] = (myWord & 0xFF);
|
||||
}
|
||||
}
|
||||
else if (saveType == 3) { // BOTH
|
||||
} else if (saveType == 3) { // BOTH
|
||||
sdBuffer[currWord * 2] = ((myWord >> 8) & 0xFF);
|
||||
sdBuffer[(currWord * 2) + 1] = (myWord & 0xFF);
|
||||
}
|
||||
@ -1513,12 +1576,10 @@ unsigned long verifySram_MD() {
|
||||
if (saveType == 2) {
|
||||
// Only use the upper byte
|
||||
sdBuffer[currWord * 2] = ((myWord >> 8) & 0xFF);
|
||||
}
|
||||
else if (saveType == 1) {
|
||||
} else if (saveType == 1) {
|
||||
// Only use the lower byte
|
||||
sdBuffer[currWord * 2] = (myWord & 0xFF);
|
||||
}
|
||||
else if (saveType == 3) { // BOTH
|
||||
} 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
|
||||
@ -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();
|
||||
}
|
||||
@ -1770,9 +1827,31 @@ void EepromInit(byte eepmode) { // Acclaim Type 2
|
||||
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");
|
||||
__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");
|
||||
__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 */
|
||||
@ -1785,12 +1864,34 @@ void writeWord_SDA(unsigned long myAddress, word myData) { /* D0 goes to /SDA wh
|
||||
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
|
||||
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);
|
||||
}
|
||||
@ -1805,12 +1906,34 @@ void writeWord_SCL(unsigned long myAddress, word myData) { /* D0 goes to /SCL wh
|
||||
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
|
||||
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);
|
||||
}
|
||||
@ -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,7 +1979,12 @@ 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
|
||||
@ -1856,21 +1996,18 @@ void EepromStart() {
|
||||
writeWord_SCL(0x100000, 0x01); // scl high
|
||||
writeWord_SDA(0x100000, 0x00); // sda low
|
||||
writeWord_SCL(0x100000, 0x00); // scl low
|
||||
}
|
||||
else if (eepType == 4) { // EA
|
||||
} 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
|
||||
} 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 {
|
||||
} else {
|
||||
writeWord_MD(0x100000, 0x00); // sda low, scl low
|
||||
writeWord_MD(0x100000, 0x03); // sda, scl high
|
||||
writeWord_MD(0x100000, 0x02); // sda low, scl high
|
||||
@ -1884,18 +2021,15 @@ void EepromSet0() {
|
||||
writeWord_SCL(0x100000, 0x01); // scl high
|
||||
writeWord_SDA(0x100000, 0x00); // sda low
|
||||
writeWord_SCL(0x100000, 0x00); // scl low
|
||||
}
|
||||
else if (eepType == 4) { // EA
|
||||
} 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
|
||||
} 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 {
|
||||
} 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
|
||||
@ -1908,20 +2042,17 @@ void EepromSet1() {
|
||||
writeWord_SCL(0x100000, 0x01); // scl high
|
||||
writeWord_SDA(0x100000, 0x01); // sda high
|
||||
writeWord_SCL(0x100000, 0x00); // scl low
|
||||
}
|
||||
else if (eepType == 4) { // EA
|
||||
} 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
|
||||
} 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 {
|
||||
} 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
|
||||
@ -1957,11 +2088,9 @@ void EepromStatus() { // ACK
|
||||
eepStatus = ((readWord_MD(0x100000) >> 1) & 0x1);
|
||||
dataOut_MD();
|
||||
delayMicroseconds(4);
|
||||
}
|
||||
while (eepStatus == 1);
|
||||
} while (eepStatus == 1);
|
||||
writeWord_MD(0x100000, 0x01); // sda high, scl low
|
||||
}
|
||||
else if (eepType == 2) { // Acclaim Type 2
|
||||
} else if (eepType == 2) { // Acclaim Type 2
|
||||
writeWord_SDA(0x100000, 0x01); // sda high
|
||||
writeWord_SCL(0x100000, 0x01); // scl high
|
||||
do {
|
||||
@ -1969,11 +2098,9 @@ void EepromStatus() { // ACK
|
||||
eepStatus = (readWord_MD(0x100000) & 0x1);
|
||||
dataOut_MD();
|
||||
delayMicroseconds(4);
|
||||
}
|
||||
while (eepStatus == 1);
|
||||
} while (eepStatus == 1);
|
||||
writeWord_SCL(0x100000, 0x00); // scl low
|
||||
}
|
||||
else if (eepType == 3) { // Capcom/Sega
|
||||
} else if (eepType == 3) { // Capcom/Sega
|
||||
writeWord_MD(0x100000, 0x01); // sda high, scl low
|
||||
writeWord_MD(0x100000, 0x03); // sda high, scl high
|
||||
do {
|
||||
@ -1981,11 +2108,9 @@ void EepromStatus() { // ACK
|
||||
eepStatus = (readWord_MD(0x100000) & 0x1);
|
||||
dataOut_MD();
|
||||
delayMicroseconds(4);
|
||||
}
|
||||
while (eepStatus == 1);
|
||||
} while (eepStatus == 1);
|
||||
writeWord_MD(0x100000, 0x01); // sda high, scl low
|
||||
}
|
||||
else if (eepType == 4) { // EA
|
||||
} else if (eepType == 4) { // EA
|
||||
writeWord_MD(0x100000, 0x80); // sda high, scl low
|
||||
writeWord_MD(0x100000, 0xC0); // sda high, scl high
|
||||
do {
|
||||
@ -1993,11 +2118,9 @@ void EepromStatus() { // ACK
|
||||
eepStatus = ((readWord_MD(0x100000) >> 7) & 0x1);
|
||||
dataOut_MD();
|
||||
delayMicroseconds(4);
|
||||
}
|
||||
while (eepStatus == 1);
|
||||
} while (eepStatus == 1);
|
||||
writeWord_MD(0x100000, 0x80); // sda high, scl low
|
||||
}
|
||||
else if (eepType == 5) { // Codemasters
|
||||
} else if (eepType == 5) { // Codemasters
|
||||
writeWord_CM(0x180000, 0x01); // sda high, scl low
|
||||
writeWord_CM(0x180000, 0x03); // sda high, scl high
|
||||
do {
|
||||
@ -2005,8 +2128,7 @@ void EepromStatus() { // ACK
|
||||
eepStatus = ((readWord_MD(0x1C0000) >> 7) & 0x1);
|
||||
dataOut_MD();
|
||||
delayMicroseconds(4);
|
||||
}
|
||||
while (eepStatus == 1);
|
||||
} while (eepStatus == 1);
|
||||
writeWord_CM(0x180000, 0x01); // sda high, scl low
|
||||
}
|
||||
}
|
||||
@ -2030,8 +2152,7 @@ void EepromReadData() {
|
||||
dataOut_MD();
|
||||
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
|
||||
@ -2041,8 +2162,7 @@ void EepromReadData() {
|
||||
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
|
||||
dataIn_MD();
|
||||
@ -2050,8 +2170,7 @@ void EepromReadData() {
|
||||
dataOut_MD();
|
||||
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
|
||||
dataIn_MD();
|
||||
@ -2059,8 +2178,7 @@ void EepromReadData() {
|
||||
dataOut_MD();
|
||||
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
|
||||
dataIn_MD();
|
||||
@ -2094,22 +2212,19 @@ void EepromFinish() {
|
||||
writeWord_SCL(0x100000, 0x00); // scl low
|
||||
writeWord_SDA(0x100000, 0x00); // sda low
|
||||
writeWord_SCL(0x100000, 0x00); // scl low
|
||||
}
|
||||
else if (eepType == 4) { // EA
|
||||
} 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
|
||||
} 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 {
|
||||
} 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
|
||||
@ -2128,22 +2243,19 @@ void EepromStop() {
|
||||
writeWord_SCL(0x100000, 0x00); // scl low
|
||||
writeWord_SDA(0x100000, 0x00); // sda low
|
||||
writeWord_SCL(0x100000, 0x00); // scl low // STOP
|
||||
}
|
||||
else if (eepType == 4) { // EA
|
||||
} 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
|
||||
} 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 {
|
||||
} else {
|
||||
writeWord_MD(0x100000, 0x00); // sda, scl low
|
||||
writeWord_MD(0x100000, 0x02); // sda low, scl high
|
||||
writeWord_MD(0x100000, 0x03); // sda, scl high
|
||||
@ -2162,8 +2274,7 @@ void EepromSetAddress(word address) {
|
||||
address <<= 1; // rotate to the next bit
|
||||
}
|
||||
EepromStatus(); // ACK
|
||||
}
|
||||
else { // 24C01
|
||||
} else { // 24C01
|
||||
for (int i = 0; i < 7; i++) {
|
||||
if ((address >> 6) & 0x1) // Bit is HIGH
|
||||
EepromSet1();
|
||||
@ -2187,8 +2298,7 @@ void readEepromByte(word address) {
|
||||
EepromSetDeviceAddress(0);
|
||||
EepromWriteMode();
|
||||
EepromSetAddress(addrhi); // ADDR [A15..A8]
|
||||
}
|
||||
else { // MODE 2 [24C02/24C08/24C16]
|
||||
} else { // MODE 2 [24C02/24C08/24C16]
|
||||
EepromSetDeviceAddress(addrhi); // ADDR [A10..A8]
|
||||
EepromWriteMode();
|
||||
}
|
||||
@ -2227,14 +2337,12 @@ void writeEepromByte(word address) {
|
||||
EepromSetDeviceAddress(0); // [A2-A0] = 000
|
||||
EepromWriteMode(); // WRITE
|
||||
EepromSetAddress(addrhi); // ADDR [A15-A8]
|
||||
}
|
||||
else { // MODE 2 [24C02/24C08/24C16]
|
||||
} else { // MODE 2 [24C02/24C08/24C16]
|
||||
EepromSetDeviceAddress(addrhi); // ADDR [A10-A8]
|
||||
EepromWriteMode(); // WRITE
|
||||
}
|
||||
EepromSetAddress(addrlo);
|
||||
}
|
||||
else { // 24C01
|
||||
} else { // 24C01
|
||||
EepromSetAddress(addrlo);
|
||||
EepromWriteMode(); // WRITE
|
||||
}
|
||||
@ -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("*"));
|
||||
@ -2321,8 +2428,7 @@ void writeEEP_MD() {
|
||||
print_Msg(F("."));
|
||||
display_Update();
|
||||
}
|
||||
}
|
||||
else { // 24C01/24C02
|
||||
} else { // 24C01/24C02
|
||||
myFile.read(sdBuffer, eepSize);
|
||||
for (word currByte = 0; currByte < eepSize; currByte++) {
|
||||
writeEepromByte(currByte);
|
||||
@ -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();
|
||||
@ -2418,8 +2523,7 @@ void writeBram_MD() {
|
||||
display_Clear();
|
||||
println_Msg(F("Done"));
|
||||
display_Update();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
print_Error(F("SD Error"), true);
|
||||
}
|
||||
dataIn_MD();
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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
|
||||
@ -173,7 +177,7 @@ 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;
|
||||
@ -210,7 +214,7 @@ static const char nesMenuItem7[] PROGMEM = "Reset";
|
||||
static const char* const menuOptionsNES[] PROGMEM = { nesMenuItem1, nesMenuItem2, nesMenuItem3, nesMenuItem4, nesMenuItem5, nesMenuItem6, nesMenuItem7 };
|
||||
|
||||
// NES chips menu
|
||||
#ifndef no-intro
|
||||
#ifndef nointro
|
||||
static const char nesChipsMenuItem1[] PROGMEM = "Read PRG & CHR";
|
||||
#else
|
||||
static const char nesChipsMenuItem1[] PROGMEM = "Combined PRG+CHR";
|
||||
@ -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;
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -623,8 +622,7 @@ boolean getMapping() {
|
||||
if ((iNES_HEADER[9] & 0x0F) != 0x0F) {
|
||||
// simple notation
|
||||
prgsize = (iNES_HEADER[4] | ((iNES_HEADER[9] & 0x0F) << 8)); //*16
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// exponent-multiplier notation
|
||||
prgsize = (((1 << (iNES_HEADER[4] >> 2)) * ((iNES_HEADER[4] & 0b11) * 2 + 1)) >> 14); //*16
|
||||
}
|
||||
@ -635,8 +633,7 @@ boolean getMapping() {
|
||||
if ((iNES_HEADER[9] & 0xF0) != 0xF0) {
|
||||
// simple notation
|
||||
chrsize = (uppow2(iNES_HEADER[5] | ((iNES_HEADER[9] & 0xF0) << 4))) * 2; //*4
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
chrsize = (((1 << (iNES_HEADER[5] >> 2)) * ((iNES_HEADER[5] & 0b11) * 2 + 1)) >> 13) * 2; //*4
|
||||
}
|
||||
if (chrsize != 0)
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -927,8 +915,7 @@ void selectMapping() {
|
||||
if ((iNES_HEADER[9] & 0x0F) != 0x0F) {
|
||||
// simple notation
|
||||
prgsize = (iNES_HEADER[4] | ((iNES_HEADER[9] & 0x0F) << 8)); //*16
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// exponent-multiplier notation
|
||||
prgsize = (((1 << (iNES_HEADER[4] >> 2)) * ((iNES_HEADER[4] & 0b11) * 2 + 1)) >> 14); //*16
|
||||
}
|
||||
@ -939,8 +926,7 @@ void selectMapping() {
|
||||
if ((iNES_HEADER[9] & 0xF0) != 0xF0) {
|
||||
// simple notation
|
||||
chrsize = (uppow2(iNES_HEADER[5] | ((iNES_HEADER[9] & 0xF0) << 4))) * 2; //*4
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
chrsize = (((1 << (iNES_HEADER[5] >> 2)) * ((iNES_HEADER[5] & 0b11) * 2 + 1)) >> 13) * 2; //*4
|
||||
}
|
||||
if (chrsize != 0)
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -1355,8 +1335,7 @@ void write_mmc1_byte(unsigned int address, uint8_t data) { // write loop for 5 b
|
||||
for (int i = 0; i < 5; i++) {
|
||||
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
|
||||
}
|
||||
@ -1590,7 +1569,7 @@ void CreateRAMFileInSD() {
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef no-intro
|
||||
#ifndef nointro
|
||||
void CartStart() {
|
||||
sd.chdir();
|
||||
EEPROM_readAnything(0, foldern); // FOLDER #
|
||||
@ -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;
|
||||
}
|
||||
@ -2271,8 +2237,7 @@ setmapper:
|
||||
Serial.println(F(""));
|
||||
else
|
||||
Serial.print(F("\t"));
|
||||
}
|
||||
else
|
||||
} else
|
||||
Serial.println(F(""));
|
||||
}
|
||||
Serial.print(F("Enter Mapper: "));
|
||||
@ -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);
|
||||
@ -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);
|
||||
@ -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);
|
||||
@ -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);
|
||||
@ -2851,8 +2804,7 @@ void checkStatus_NES() {
|
||||
checkMMC6();
|
||||
if (mmc6)
|
||||
ram = 1; // 1K
|
||||
}
|
||||
else if (mapper == 30) // Check for Flashable/Non-Flashable
|
||||
} else if (mapper == 30) // Check for Flashable/Non-Flashable
|
||||
NESmaker_ID(); // Flash ID
|
||||
|
||||
display_Clear();
|
||||
@ -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"));
|
||||
}
|
||||
@ -2939,8 +2888,7 @@ void writeMMC5RAM(word base, word address) { // MMC5 SRAM WRITE
|
||||
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
|
||||
@ -2955,8 +2903,7 @@ void readPRG(boolean readrom) {
|
||||
set_address(0);
|
||||
_delay_us(1);
|
||||
CreatePRGFileInSD();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
set_address(0);
|
||||
_delay_us(1);
|
||||
}
|
||||
@ -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,8 +3486,7 @@ void readCHR(boolean readrom) {
|
||||
if (chrsize == 0) {
|
||||
println_Msg(F("CHR SIZE 0K"));
|
||||
display_Update();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (!readrom) {
|
||||
CreateCHRFileInSD();
|
||||
}
|
||||
@ -4032,8 +3978,7 @@ void readCHR(boolean readrom) {
|
||||
for (word address = 0x0; address < 0x800; address += 512) {
|
||||
dumpCHR(address);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} 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
|
||||
@ -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,8 +4101,7 @@ void readRAM() {
|
||||
|
||||
println_Msg(F("RAM SIZE 0K"));
|
||||
display_Update();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
CreateRAMFileInSD();
|
||||
word base = 0x6000;
|
||||
if (myFile) {
|
||||
@ -4198,8 +4142,7 @@ void readRAM() {
|
||||
dumpMMC5RAM(base, address);
|
||||
}
|
||||
write_prg_byte(0x8000, 6); // PRG RAM DISABLE
|
||||
}
|
||||
else { // MMC3 8K
|
||||
} 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);
|
||||
@ -4223,8 +4166,7 @@ void readRAM() {
|
||||
dumpMMC5RAM(base, address);
|
||||
}
|
||||
}
|
||||
}
|
||||
else { // 8K/32K Single SRAM Chip
|
||||
} 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
|
||||
@ -4254,8 +4196,7 @@ void readRAM() {
|
||||
sdBuffer[x] = read_prg_byte(0x4800); // DATA PORT
|
||||
}
|
||||
myFile.write(sdBuffer, 128);
|
||||
}
|
||||
else { // SRAM 8K
|
||||
} else { // SRAM 8K
|
||||
for (int i = 0; i < 64; i++) { // Init Register
|
||||
write_ram_byte(0xE000, 0);
|
||||
}
|
||||
@ -4295,8 +4236,7 @@ void readRAM() {
|
||||
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
|
||||
@ -4305,8 +4245,7 @@ void readRAM() {
|
||||
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
|
||||
} 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
|
||||
@ -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;
|
||||
|
||||
@ -4407,8 +4345,7 @@ void writeRAM() {
|
||||
}
|
||||
}
|
||||
write_prg_byte(0x8000, 0x6); // PRG RAM DISABLE
|
||||
}
|
||||
else { // MMC3 8K
|
||||
} 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);
|
||||
@ -4436,8 +4373,7 @@ void writeRAM() {
|
||||
writeMMC5RAM(base, address);
|
||||
}
|
||||
}
|
||||
}
|
||||
else { // 8K/32K Single SRAM Chip [EKROM = 8K BATTERY BACKED, EWROM = 32K BATTERY BACKED]
|
||||
} 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
|
||||
@ -4470,8 +4406,7 @@ void writeRAM() {
|
||||
write_ram_byte(0xF800, x); // PRG RAM ENABLE
|
||||
write_prg_byte(0x4800, sdBuffer[x]); // DATA PORT
|
||||
}
|
||||
}
|
||||
else { // SRAM 8K
|
||||
} else { // SRAM 8K
|
||||
for (int i = 0; i < 64; i++) { // Init Register
|
||||
write_ram_byte(0xF800, 0x40); // PRG RAM WRITE ENABLE
|
||||
}
|
||||
@ -4530,8 +4465,7 @@ void writeRAM() {
|
||||
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
|
||||
} 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
|
||||
@ -4550,8 +4484,7 @@ void writeRAM() {
|
||||
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
|
||||
} else if (mapper == 85) // 8K
|
||||
write_reg_byte(0xE000, 0); // PRG RAM DISABLE [WRITE RAM SAFE]
|
||||
break;
|
||||
}
|
||||
@ -4562,8 +4495,7 @@ void writeRAM() {
|
||||
println_Msg(F("RAM FILE WRITTEN!"));
|
||||
display_Update();
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
print_Error(F("SD ERROR"), true);
|
||||
}
|
||||
}
|
||||
@ -4635,8 +4567,7 @@ void EepromStatus_NES() { // ACK
|
||||
do {
|
||||
eepStatus = (read_prg_byte(0x6000) & 0x10) >> 4;
|
||||
delayMicroseconds(4);
|
||||
}
|
||||
while (eepStatus == 1);
|
||||
} while (eepStatus == 1);
|
||||
write_prg_byte(0x800D, 0x40); // sda high, scl low
|
||||
}
|
||||
|
||||
@ -4730,8 +4661,7 @@ void EepromREAD(byte address) {
|
||||
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
|
||||
} else { // 24C02
|
||||
EepromDevice_NES(); // DEVICE [1010] + ADDR [A2-A0]
|
||||
EepromWriteMode_NES();
|
||||
EepromSetAddress02(address);
|
||||
@ -4754,8 +4684,7 @@ void EepromWRITE(byte address) {
|
||||
EepromSetAddress01(address); // 24C01 [Little Endian]
|
||||
EepromWriteMode_NES();
|
||||
EepromWriteData01(); // 24C01 [Little Endian]
|
||||
}
|
||||
else { // 24C02
|
||||
} else { // 24C02
|
||||
EepromDevice_NES(); // DEVICE [1010] + ADDR [A2-A0]
|
||||
EepromWriteMode_NES();
|
||||
EepromSetAddress02(address);
|
||||
@ -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(""));
|
||||
@ -4881,8 +4809,7 @@ void writeFLASH() {
|
||||
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) {
|
||||
@ -4895,8 +4822,7 @@ void writeFLASH() {
|
||||
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();
|
||||
|
@ -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"));
|
||||
}
|
||||
@ -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");
|
||||
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
@ -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')
|
||||
{
|
||||
&& 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,16 +420,14 @@ 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++) {
|
||||
@ -435,8 +439,7 @@ uint32_t calculate_crc32(int n, unsigned char c[], uint32_t r)
|
||||
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];
|
||||
@ -446,12 +449,10 @@ void crc_search(char *file_p, char *folder_p, uint32_t rom_size, uint32_t crc)
|
||||
|
||||
//Open list file. If no list file found, just skip
|
||||
sd.chdir("/"); //Set read directry to root
|
||||
if (script.open("pce.txt", O_READ))
|
||||
{
|
||||
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
|
||||
@ -466,8 +467,7 @@ void crc_search(char *file_p, char *folder_p, uint32_t rom_size, uint32_t crc)
|
||||
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,11 +501,9 @@ void crc_search(char *file_p, char *folder_p, uint32_t rom_size, uint32_t crc)
|
||||
}
|
||||
|
||||
script.close();
|
||||
|
||||
}
|
||||
|
||||
void unlock_tennokoe_bank_RAM()
|
||||
{
|
||||
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
|
||||
@ -516,15 +511,13 @@ void unlock_tennokoe_bank_RAM()
|
||||
write_byte_PCE(0x0F0000, 0x73); //Unlock RAM sequence 5 Bank 78
|
||||
}
|
||||
|
||||
void lock_tennokoe_bank_RAM()
|
||||
{
|
||||
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;
|
||||
@ -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;
|
||||
|
||||
@ -763,14 +752,11 @@ void read_rom_PCE(void)
|
||||
draw_progressbar(0, rom_size * 1024UL);
|
||||
|
||||
uint32_t crc = 0xFFFFFFFFUL; //Initialize CRC
|
||||
if (rom_size == 384)
|
||||
{
|
||||
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();
|
||||
@ -789,9 +775,7 @@ void read_rom_PCE(void)
|
||||
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
|
||||
{
|
||||
} 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
|
||||
|
@ -84,7 +84,11 @@
|
||||
#define MODE_READ DDRC = 0 // [INPUT]
|
||||
#define MODE_WRITE DDRC = 0xFF //[OUTPUT]
|
||||
|
||||
#define DATA_READ { DDRC = 0; PORTC = 0xFF; } // [INPUT PULLUP]
|
||||
#define DATA_READ \
|
||||
{ \
|
||||
DDRC = 0; \
|
||||
PORTC = 0xFF; \
|
||||
} // [INPUT PULLUP]
|
||||
#define ADDR_WRITE DDRC = 0xFF // [OUTPUT]
|
||||
|
||||
boolean multipack = 0; // Multi-Pack Cart
|
||||
@ -136,13 +140,11 @@ static const char pcwmenuItem3[] PROGMEM = "Write SRAM";
|
||||
static const char pcwmenuItem4[] PROGMEM = "Reset";
|
||||
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 "));
|
||||
@ -218,7 +219,8 @@ unsigned char read_rom_byte_PCW(unsigned long address) {
|
||||
LE_HIGH; // Latch Enable
|
||||
PORTC = address & 0xFF; // A0-A7
|
||||
LE_LOW; // Address Latched
|
||||
__asm__("nop\n\t""nop\n\t");
|
||||
__asm__("nop\n\t"
|
||||
"nop\n\t");
|
||||
// Read Data on AD0-AD7
|
||||
OE_LOW;
|
||||
DATA_READ;
|
||||
@ -240,15 +242,30 @@ unsigned char read_ram_byte_1A_PCW(unsigned long address) {
|
||||
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");
|
||||
__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;
|
||||
}
|
||||
@ -270,15 +287,30 @@ unsigned char read_ram_byte_1B_PCW(unsigned long address) {
|
||||
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");
|
||||
__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;
|
||||
}
|
||||
@ -296,7 +328,10 @@ void write_ram_byte_1A_PCW(unsigned long address, unsigned char data) {
|
||||
// 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;
|
||||
}
|
||||
@ -317,8 +352,16 @@ void write_ram_byte_1B_PCW(unsigned long address, unsigned char data) {
|
||||
// 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;
|
||||
}
|
||||
@ -389,8 +432,16 @@ void write_bank_byte_PCW(unsigned char data) {
|
||||
// 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;
|
||||
}
|
||||
@ -398,8 +449,7 @@ void write_bank_byte_PCW(unsigned char data) {
|
||||
void switchBank_PCW(int bank) {
|
||||
if (bank == 1) { // Upper Half
|
||||
write_bank_byte_PCW(bank1);
|
||||
}
|
||||
else { // Lower Half (default)
|
||||
} else { // Lower Half (default)
|
||||
write_bank_byte_PCW(bank0);
|
||||
}
|
||||
}
|
||||
@ -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();
|
||||
@ -600,8 +648,7 @@ unsigned long verifySRAM_PCW() {
|
||||
}
|
||||
}
|
||||
myFile.close();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
print_Error(F("SD Error"), true);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
@ -782,8 +815,7 @@ 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 {
|
||||
} else {
|
||||
romType &= 1; // Must be LoROM or HiROM
|
||||
}
|
||||
|
||||
@ -846,8 +878,7 @@ boolean checkcart_SFM() {
|
||||
sramSize = 1;
|
||||
while (sramSizeExp--)
|
||||
sramSize *= 2;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sramSize = 0;
|
||||
}
|
||||
|
||||
@ -858,8 +889,7 @@ boolean checkcart_SFM() {
|
||||
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);
|
||||
@ -1158,8 +1183,7 @@ byte blankcheck_SFM(int startBank) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
for (int currBank = 0; currBank < numBanks; currBank++) {
|
||||
for (unsigned long currByte = 0x8000; currByte < 0x10000; currByte++) {
|
||||
if (readBank_SFM(currBank, currByte) != 0xFF) {
|
||||
@ -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++) {
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
@ -468,8 +480,7 @@ void getCartInfo_SMS() {
|
||||
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;
|
||||
@ -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);
|
||||
@ -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,8 +742,7 @@ void writeSRAM_SMS() {
|
||||
println_Msg(F(""));
|
||||
println_Msg(F("DONE"));
|
||||
display_Update();
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
print_Error(F("SD ERROR"), true);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
@ -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"));
|
||||
@ -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++;
|
||||
@ -942,14 +994,11 @@ 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) {
|
||||
} else if (romType == 0x35) {
|
||||
romType = EX; // Check if ExHiROM
|
||||
}
|
||||
else if (romType == 0x3A) {
|
||||
} else if (romType == 0x3A) {
|
||||
romType = HI; // Check if SPC7110
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
romType &= 1; // Must be LoROM or HiROM
|
||||
}
|
||||
|
||||
@ -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
|
||||
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;
|
||||
}
|
||||
|
||||
@ -1099,8 +1137,7 @@ boolean checkcart_SNES() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -1136,8 +1173,7 @@ 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)) {
|
||||
} 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);
|
||||
@ -1177,8 +1212,7 @@ unsigned int calc_checksum (char* fileName, char* folder) {
|
||||
}
|
||||
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++) {
|
||||
@ -1197,8 +1231,7 @@ unsigned int calc_checksum (char* fileName, char* folder) {
|
||||
}
|
||||
}
|
||||
calcChecksum += 4 * calcChecksumChunk;
|
||||
}
|
||||
else if (calcFilesize == 48) {
|
||||
} else if (calcFilesize == 48) {
|
||||
// Star Ocean/Tales of Phantasia Fix 6MB (48Mbit)
|
||||
// Add the 4MB (32Mbit) start
|
||||
for (j = 0; j < (4194304 / 512); j++) {
|
||||
@ -1217,8 +1250,7 @@ unsigned int calc_checksum (char* fileName, char* folder) {
|
||||
}
|
||||
}
|
||||
calcChecksum += 2 * calcChecksumChunk;
|
||||
}
|
||||
else {
|
||||
} 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);
|
||||
@ -1334,8 +1364,7 @@ void readROM_SNES() {
|
||||
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
|
||||
@ -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
|
||||
@ -1500,22 +1528,19 @@ void writeSRAM (boolean browseFile) {
|
||||
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 {
|
||||
} else {
|
||||
for (long currByte = 0; currByte < lastByte; currByte++) {
|
||||
writeBank_SNES(0x70, currByte, myFile.read());
|
||||
}
|
||||
@ -1538,8 +1563,7 @@ 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);
|
||||
// Sram size
|
||||
@ -1551,8 +1575,7 @@ void writeSRAM (boolean browseFile) {
|
||||
writeBank_SNES(currBank, currByte, myFile.read());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
lastByte += 0x6000;
|
||||
// Write to sram bank
|
||||
for (long currByte = 0x6000; currByte < lastByte; currByte++) {
|
||||
@ -1632,8 +1655,7 @@ void writeSRAM (boolean browseFile) {
|
||||
println_Msg(F("SRAM writing finished"));
|
||||
display_Update();
|
||||
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
print_Error(F("File doesnt exist"), false);
|
||||
}
|
||||
}
|
||||
@ -1672,28 +1694,24 @@ void readSRAM () {
|
||||
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) {
|
||||
} else if (romType == HI) {
|
||||
if ((romChips == 245) || (romChips == 249)) { // SPC7110 SRAM
|
||||
// Configure SPC7110 SRAM Register
|
||||
dataOut();
|
||||
@ -1709,8 +1727,7 @@ 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);
|
||||
// Sram size
|
||||
@ -1722,16 +1739,14 @@ void readSRAM () {
|
||||
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);
|
||||
// Sram size
|
||||
@ -1739,8 +1754,7 @@ void readSRAM () {
|
||||
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);
|
||||
// Sram size
|
||||
@ -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));
|
||||
}
|
||||
@ -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,8 +1848,7 @@ unsigned long verifySRAM() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (romType == HI) {
|
||||
} else if (romType == HI) {
|
||||
if ((romChips == 245) || (romChips == 249)) { // SPC7110 SRAM
|
||||
// Configure SPC7110 SRAM Register
|
||||
dataOut();
|
||||
@ -1861,8 +1870,7 @@ 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);
|
||||
// Sram size
|
||||
@ -1880,8 +1888,7 @@ unsigned long verifySRAM() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
lastByte += 0x6000;
|
||||
for (long currByte = 0x6000; currByte < lastByte; currByte += 512) {
|
||||
//fill sdBuffer
|
||||
@ -1894,8 +1901,7 @@ unsigned long verifySRAM() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (romType == EX) {
|
||||
} else if (romType == EX) {
|
||||
// Dumping SRAM on HiRom needs CS(PH3) to be high
|
||||
PORTH |= (1 << 3);
|
||||
// Sram size
|
||||
@ -1909,8 +1915,7 @@ unsigned long verifySRAM() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (romType == SA) {
|
||||
} else if (romType == SA) {
|
||||
// Dumping SRAM on HiRom needs CS(PH3) to be high
|
||||
PORTH |= (1 << 3);
|
||||
// Sram size
|
||||
@ -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,8 +1972,7 @@ unsigned long verifySRAM() {
|
||||
// Close the file:
|
||||
myFile.close();
|
||||
return writeErrors;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
print_Error(F("Can't open file"), false);
|
||||
}
|
||||
}
|
||||
@ -2001,28 +2003,24 @@ boolean eraseSRAM (byte b) {
|
||||
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 {
|
||||
} else {
|
||||
for (long currByte = 0; currByte < lastByte; currByte++) {
|
||||
writeBank_SNES(0x70, currByte, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (romType == HI) {
|
||||
} else if (romType == HI) {
|
||||
if ((romChips == 245) || (romChips == 249)) { // SPC7110 SRAM
|
||||
// Configure SPC7110 SRAM Register
|
||||
// Set 0x4830 to 0x80
|
||||
@ -2038,8 +2036,7 @@ 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);
|
||||
// Sram size
|
||||
@ -2051,8 +2048,7 @@ boolean eraseSRAM (byte b) {
|
||||
writeBank_SNES(currBank, currByte, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
lastByte += 0x6000;
|
||||
// Write to sram bank
|
||||
for (long currByte = 0x6000; currByte < lastByte; currByte++) {
|
||||
@ -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,8 +2170,7 @@ boolean eraseSRAM (byte b) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (romType == HI) {
|
||||
} else if (romType == HI) {
|
||||
if ((romChips == 245) || (romChips == 249)) { // SPC7110 SRAM
|
||||
// Configure SPC7110 SRAM Register
|
||||
dataOut();
|
||||
@ -2198,8 +2190,7 @@ 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);
|
||||
// Sram size
|
||||
@ -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,8 +2217,7 @@ 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);
|
||||
// Sram size
|
||||
@ -2240,8 +2229,7 @@ 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);
|
||||
// Sram size
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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 "));
|
||||
@ -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;
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -428,8 +476,7 @@ void writeROM_SV (void) {
|
||||
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);
|
||||
}
|
||||
@ -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();
|
||||
@ -518,8 +564,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 (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);
|
||||
}
|
||||
}
|
||||
@ -558,10 +602,20 @@ void eraseCheck_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, 0x0004);
|
||||
}
|
||||
@ -585,10 +639,20 @@ void supplyCheck_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, 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,8 +743,7 @@ void detectCheck_SV(void) {
|
||||
}
|
||||
|
||||
|
||||
void eraseAll_SV(void)
|
||||
{
|
||||
void eraseAll_SV(void) {
|
||||
dataOut();
|
||||
controlOut_SNES();
|
||||
writeBank_SV(0xC0, 0x0000, 0x50); //Clear Status Registers
|
||||
|
@ -55,8 +55,7 @@
|
||||
// SETUP
|
||||
//******************************************
|
||||
|
||||
void setup_VBOY()
|
||||
{
|
||||
void setup_VBOY() {
|
||||
// Set Address Pins to Output
|
||||
//A0-A7
|
||||
DDRF = 0xFF;
|
||||
@ -101,13 +100,11 @@ static const char vboyMenuItem3[] PROGMEM = "Write SRAM";
|
||||
static const char vboyMenuItem4[] PROGMEM = "Reset";
|
||||
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,7 +216,12 @@ 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);
|
||||
|
||||
@ -221,7 +230,12 @@ word readWord_VB(unsigned long myAddress) {
|
||||
// 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;
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
@ -279,8 +308,7 @@ void getCartInfo_VB() {
|
||||
// Get Serial
|
||||
word vbSerial = readWord_VB((address - 0x204) / 2); // Cart Serial
|
||||
|
||||
switch (vbSerial)
|
||||
{
|
||||
switch (vbSerial) {
|
||||
case 0x4D54: // MT = Mario's Tennis
|
||||
case 0x4832: // H2 = Panic Bomber/Tobidase! Panibomb
|
||||
case 0x5350: // SP = Space Invaders
|
||||
@ -361,8 +389,7 @@ void getCartInfo_VB() {
|
||||
if (sramSize > 0) {
|
||||
print_Msg(sramSize * 8 / 1024);
|
||||
println_Msg(F(" KBit"));
|
||||
}
|
||||
else
|
||||
} else
|
||||
println_Msg(F("None"));
|
||||
println_Msg(F(" "));
|
||||
|
||||
@ -420,8 +447,7 @@ void readROM_VB() {
|
||||
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);
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
||||
@ -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:
|
||||
{
|
||||
@ -196,8 +190,7 @@ void wsMenu()
|
||||
wait();
|
||||
}
|
||||
|
||||
uint8_t getCartInfo_WS()
|
||||
{
|
||||
uint8_t getCartInfo_WS() {
|
||||
dataIn_WS();
|
||||
|
||||
// for (uint32_t i = 0; i < 16; i += 2)
|
||||
@ -208,8 +201,7 @@ uint8_t getCartInfo_WS()
|
||||
|
||||
// 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,28 +262,21 @@ 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
|
||||
|
||||
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
|
||||
@ -302,9 +285,7 @@ uint8_t getCartInfo_WS()
|
||||
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;
|
||||
}
|
||||
@ -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;
|
||||
@ -452,7 +461,9 @@ 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;
|
||||
@ -461,8 +472,7 @@ void getDeveloperName(uint8_t id, char *buf, size_t length)
|
||||
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,8 +517,7 @@ 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();
|
||||
@ -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
|
||||
@ -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
|
||||
|
||||
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,13 +1225,11 @@ 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"
|
||||
asm volatile("L0_%=:\n\t"
|
||||
"cpi %[count], 0\n\t"
|
||||
"breq L3_%=\n\t"
|
||||
"dec %[count]\n\t"
|
||||
@ -1299,12 +1246,10 @@ void pulseCLK_WS(uint8_t count)
|
||||
"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)
|
||||
);
|
||||
: [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;
|
||||
}
|
||||
|
@ -52,8 +52,7 @@ byte newwsvsize;
|
||||
// SETUP
|
||||
//******************************************
|
||||
|
||||
void setup_WSV()
|
||||
{
|
||||
void setup_WSV() {
|
||||
// Set Address Pins to Output
|
||||
//A0-A7
|
||||
DDRF = 0xFF;
|
||||
@ -106,13 +105,11 @@ static const char wsvMenuItem3[] PROGMEM = "Set Size";
|
||||
static const char wsvMenuItem4[] PROGMEM = "Reset";
|
||||
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)
|
||||
@ -354,8 +350,7 @@ setrom:
|
||||
wsvsize = newwsvsize;
|
||||
}
|
||||
|
||||
void checkStatus_WSV()
|
||||
{
|
||||
void checkStatus_WSV() {
|
||||
EEPROM_readAnything(8, wsvsize);
|
||||
if (wsvsize > 2) {
|
||||
wsvsize = 1; // default 64K
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -464,8 +457,7 @@ void setCart_WSV() {
|
||||
// Remove leading 0 for single digit cart sizes
|
||||
if (cartSize != 0) {
|
||||
cartSize = cartSize * 10 + myFile.read() - 48;
|
||||
}
|
||||
else {
|
||||
} 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,8 +540,7 @@ void setCart_WSV() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
print_Error(F("Database file not found"), true);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user