Merge pull request #2 from Pickle/master

Added support for SDD1 and warning fixes by Pickle
This commit is contained in:
sanni 2016-07-31 09:29:12 +02:00 committed by GitHub
commit 9930fcc8b3
4 changed files with 136 additions and 88 deletions

View File

@ -74,7 +74,7 @@ Si5351 clockgen;
// set pins of red, green and blue
RGBTools rgb(12, 11, 10);
typedef enum {
typedef enum COLOR_T{
blue_color,
red_color,
purple_color,
@ -82,7 +82,7 @@ typedef enum {
turquoise_color,
yellow_color,
white_color,
};
} color_t;
// SD Card (Pin 50 = MISO, Pin 51 = MOSI, Pin 52 = SCK, Pin 53 = SS)
#include <SdFat.h>
@ -549,7 +549,7 @@ void print_Msg(const __FlashStringHelper *string) {
Serial.print(string);
}
void print_Msg(char string[]) {
void print_Msg(const char string[]) {
if (enable_OLED)
display.print(string);
if (enable_Serial)
@ -591,7 +591,7 @@ void println_Msg(byte message, int outputFormat) {
Serial.println(message, outputFormat);
}
void println_Msg(char message[]) {
void println_Msg(const char message[]) {
if (enable_OLED)
display.println(message);
if (enable_Serial)
@ -624,7 +624,7 @@ void display_Clear() {
}
}
unsigned char question_box(char* question, char answers[7][20], int num_answers, int default_choice) {
unsigned char question_box(const char* question, char answers[7][20], int num_answers, int default_choice) {
if (enable_OLED) {
return questionBox_OLED(question, answers, num_answers, default_choice);
}
@ -633,7 +633,7 @@ unsigned char question_box(char* question, char answers[7][20], int num_answers,
}
}
void fileBrowser(char browserTitle[]) {
void fileBrowser(const char browserTitle[]) {
if (enable_OLED) {
fileBrowser_OLED(browserTitle);
}
@ -652,7 +652,7 @@ void wait_serial() {
Serial.println("");
}
byte questionBox_Serial(char* question, char answers[7][20], int num_answers, int default_choice) {
byte questionBox_Serial(const char* question, char answers[7][20], int num_answers, int default_choice) {
// Print menu to serial monitor
Serial.print(question);
Serial.println(F(" Menu"));
@ -677,7 +677,7 @@ byte questionBox_Serial(char* question, char answers[7][20], int num_answers, in
}
// Prompt a filename from the Serial Monitor
void fileBrowser_Serial(char browserTitle[]) {
void fileBrowser_Serial(const char browserTitle[]) {
Serial.println(browserTitle);
// Print all files in root of SD
Serial.println(F("Name - Size"));
@ -832,7 +832,7 @@ void wait_btn() {
}
// Display a question box with selectable answers. Make sure default choice is in (0, num_answers]
unsigned char questionBox_OLED(char* question, char answers[7][20], int num_answers, int default_choice) {
unsigned char questionBox_OLED(const char* question, char answers[7][20], int num_answers, int default_choice) {
//clear the screen
display.clearDisplay();
@ -956,7 +956,7 @@ unsigned char questionBox_OLED(char* question, char answers[7][20], int num_answ
/******************************************
Filebrowser Module
*****************************************/
void fileBrowser_OLED(char browserTitle[]) {
void fileBrowser_OLED(const char browserTitle[]) {
char fileNames[30][26];
int currFile;
filebrowse = 1;

View File

@ -802,8 +802,8 @@ void readBlock(word myAddress) {
// Read Controller Pak command
unsigned char command[] = {0x02};
// Address Command
unsigned char addressHigh[] = {myAddressCRC >> 8};
unsigned char addressLow[] = {myAddressCRC & 0xff};
unsigned char addressHigh[] = {(unsigned char)(myAddressCRC >> 8)};
unsigned char addressLow[] = {(unsigned char)(myAddressCRC & 0xff)};
// don't want interrupts getting in the way
noInterrupts();
@ -902,8 +902,8 @@ void writeMPK() {
// Write Controller Pak command
unsigned char command[] = {0x03};
// Address Command
unsigned char addressHigh[] = {myAddressCRC >> 8};
unsigned char addressLow[] = {myAddressCRC & 0xff};
unsigned char addressHigh[] = {(unsigned char)(myAddressCRC >> 8)};
unsigned char addressLow[] = {(unsigned char)(myAddressCRC & 0xff)};
// don't want interrupts getting in the way
noInterrupts();

View File

@ -616,14 +616,14 @@ void resetFlash_NP(int startBank) {
// Reset command sequence
if (romType) {
writeBank_SNES(startBank, 0x5555 * 2, 0xaa);
writeBank_SNES(startBank, 0x2AAA * 2, 0x55);
writeBank_SNES(startBank, 0x5555 * 2, 0xf0);
writeBank_SNES(startBank, 0x5555L * 2, 0xaa);
writeBank_SNES(startBank, 0x2AAAL * 2, 0x55);
writeBank_SNES(startBank, 0x5555L * 2, 0xf0);
}
else {
writeBank_SNES(1, 0x8000 + 0x1555 * 2, 0xaa);
writeBank_SNES(0, 0x8000 + 0x2AAA * 2, 0x55);
writeBank_SNES(1, 0x8000 + 0x1555 * 2, 0xf0);
writeBank_SNES(1, 0x8000 + 0x1555L * 2, 0xaa);
writeBank_SNES(0, 0x8000 + 0x2AAAL * 2, 0x55);
writeBank_SNES(1, 0x8000 + 0x1555L * 2, 0xf0);
}
}
@ -636,9 +636,9 @@ void idFlash_NP(int startBank) {
if (romType) {
// ID command sequence
writeBank_SNES(startBank, 0x5555 * 2, 0xaa);
writeBank_SNES(startBank, 0x2AAA * 2, 0x55);
writeBank_SNES(startBank, 0x5555 * 2, 0x90);
writeBank_SNES(startBank, 0x5555L * 2, 0xaa);
writeBank_SNES(startBank, 0x2AAAL * 2, 0x55);
writeBank_SNES(startBank, 0x5555L * 2, 0x90);
// Set data pins to input again
dataIn();
@ -649,9 +649,9 @@ void idFlash_NP(int startBank) {
sprintf(flashid, "%x%x", readBank_SNES(startBank, 0x00), readBank_SNES(startBank, 0x02));
}
else {
writeBank_SNES(1, 0x8000 + 0x1555 * 2, 0xaa);
writeBank_SNES(0, 0x8000 + 0x2AAA * 2, 0x55);
writeBank_SNES(1, 0x8000 + 0x1555 * 2, 0x90);
writeBank_SNES(1, 0x8000 + 0x1555L * 2, 0xaa);
writeBank_SNES(0, 0x8000 + 0x2AAAL * 2, 0x55);
writeBank_SNES(1, 0x8000 + 0x1555L * 2, 0x90);
// Set data pins to input again
dataIn();
@ -690,9 +690,9 @@ void writeFlash_NP(int startBank, uint32_t pos) {
for (unsigned long currByte = 0; currByte < 0x10000; currByte += 128) {
myFile.read(sdBuffer, 128);
// Write command sequence
writeBank_SNES(startBank, 0x5555 * 2, 0xaa);
writeBank_SNES(startBank, 0x2AAA * 2, 0x55);
writeBank_SNES(startBank, 0x5555 * 2, 0xa0);
writeBank_SNES(startBank, 0x5555L * 2, 0xaa);
writeBank_SNES(startBank, 0x2AAAL * 2, 0x55);
writeBank_SNES(startBank, 0x5555L * 2, 0xa0);
for (byte c = 0; c < 128; c++) {
@ -715,9 +715,9 @@ void writeFlash_NP(int startBank, uint32_t pos) {
for (unsigned long currByte = 0x8000; currByte < 0x10000; currByte += 128) {
myFile.read(sdBuffer, 128);
// Write command sequence
writeBank_SNES(1, 0x8000 + 0x1555 * 2, 0xaa);
writeBank_SNES(0, 0x8000 + 0x2AAA * 2, 0x55);
writeBank_SNES(1, 0x8000 + 0x1555 * 2, 0xa0);
writeBank_SNES(1, 0x8000 + 0x1555L * 2, 0xaa);
writeBank_SNES(0, 0x8000 + 0x2AAAL * 2, 0x55);
writeBank_SNES(1, 0x8000 + 0x1555L * 2, 0xa0);
for (byte c = 0; c < 128; c++) {
// Write one byte of data
@ -786,20 +786,20 @@ void eraseFlash_NP(int startBank) {
if (romType) {
// Erase command sequence
writeBank_SNES(startBank, 0x5555 * 2, 0xaa);
writeBank_SNES(startBank, 0x2AAA * 2, 0x55);
writeBank_SNES(startBank, 0x5555 * 2, 0x80);
writeBank_SNES(startBank, 0x5555 * 2, 0xaa);
writeBank_SNES(startBank, 0x2AAA * 2, 0x55);
writeBank_SNES(startBank, 0x5555 * 2, 0x10);
writeBank_SNES(startBank, 0x5555L * 2, 0xaa);
writeBank_SNES(startBank, 0x2AAAL * 2, 0x55);
writeBank_SNES(startBank, 0x5555L * 2, 0x80);
writeBank_SNES(startBank, 0x5555L * 2, 0xaa);
writeBank_SNES(startBank, 0x2AAAL * 2, 0x55);
writeBank_SNES(startBank, 0x5555L * 2, 0x10);
}
else {
writeBank_SNES(1, 0x8000 + 0x1555 * 2, 0xaa);
writeBank_SNES(0, 0x8000 + 0x2AAA * 2, 0x55);
writeBank_SNES(1, 0x8000 + 0x1555 * 2, 0x80);
writeBank_SNES(1, 0x8000 + 0x1555 * 2, 0xaa);
writeBank_SNES(0, 0x8000 + 0x2AAA * 2, 0x55);
writeBank_SNES(1, 0x8000 + 0x1555 * 2, 0x10);
writeBank_SNES(1, 0x8000 + 0x1555L * 2, 0xaa);
writeBank_SNES(0, 0x8000 + 0x2AAAL * 2, 0x55);
writeBank_SNES(1, 0x8000 + 0x1555L * 2, 0x80);
writeBank_SNES(1, 0x8000 + 0x1555L * 2, 0xaa);
writeBank_SNES(0, 0x8000 + 0x2AAAL * 2, 0x55);
writeBank_SNES(1, 0x8000 + 0x1555L * 2, 0x10);
}
// Wait for erase to complete
@ -943,9 +943,9 @@ void readSectorProtection_NP(byte startBank) {
dataOut();
// Display Sector Protection Status
writeBank_SNES(startBank, 0x5555 * 2, 0xaa);
writeBank_SNES(startBank, 0x2AAA * 2, 0x55);
writeBank_SNES(startBank, 0x5555 * 2, 0x90);
writeBank_SNES(startBank, 0x5555L * 2, 0xaa);
writeBank_SNES(startBank, 0x2AAAL * 2, 0x55);
writeBank_SNES(startBank, 0x5555L * 2, 0x90);
// Configure control pins
controlIn_SNES();
@ -1002,14 +1002,14 @@ void printMapping() {
controlOut_SNES();
// Reset Flash
writeBank_SNES(0xC0, 0x5555 * 2, 0xaa);
writeBank_SNES(0xC0, 0x2AAA * 2, 0x55);
writeBank_SNES(0xC0, 0x5555 * 2, 0xf0);
writeBank_SNES(0xC0, 0x5555L * 2, 0xaa);
writeBank_SNES(0xC0, 0x2AAAL * 2, 0x55);
writeBank_SNES(0xC0, 0x5555L * 2, 0xf0);
// Reset Flash
writeBank_SNES(0xE0, 0x5555 * 2, 0xaa);
writeBank_SNES(0xE0, 0x2AAA * 2, 0x55);
writeBank_SNES(0xE0, 0x5555 * 2, 0xf0);
writeBank_SNES(0xE0, 0x5555L * 2, 0xaa);
writeBank_SNES(0xE0, 0x2AAAL * 2, 0x55);
writeBank_SNES(0xE0, 0x5555L * 2, 0xf0);
// Switch to read
dataIn();
@ -1089,14 +1089,14 @@ void readMapping() {
controlOut_SNES();
// Reset Flash
writeBank_SNES(0xC0, 0x5555 * 2, 0xaa);
writeBank_SNES(0xC0, 0x2AAA * 2, 0x55);
writeBank_SNES(0xC0, 0x5555 * 2, 0xf0);
writeBank_SNES(0xC0, 0x5555L * 2, 0xaa);
writeBank_SNES(0xC0, 0x2AAAL * 2, 0x55);
writeBank_SNES(0xC0, 0x5555L * 2, 0xf0);
// Reset Flash
writeBank_SNES(0xE0, 0x5555 * 2, 0xaa);
writeBank_SNES(0xE0, 0x2AAA * 2, 0x55);
writeBank_SNES(0xE0, 0x5555 * 2, 0xf0);
writeBank_SNES(0xE0, 0x5555L * 2, 0xaa);
writeBank_SNES(0xE0, 0x2AAAL * 2, 0x55);
writeBank_SNES(0xE0, 0x5555L * 2, 0xf0);
// Switch to read
dataIn();
@ -1121,13 +1121,13 @@ void eraseMapping(byte startBank) {
controlOut_SNES();
// Prepare to erase/write Page Buffer
writeBank_SNES(startBank, 0x5555 * 2, 0xaa);
writeBank_SNES(startBank, 0x2AAA * 2, 0x55);
writeBank_SNES(startBank, 0x5555 * 2, 0x77);
writeBank_SNES(startBank, 0x5555L * 2, 0xaa);
writeBank_SNES(startBank, 0x2AAAL * 2, 0x55);
writeBank_SNES(startBank, 0x5555L * 2, 0x77);
// Erase Page Buffer
writeBank_SNES(startBank, 0x5555 * 2, 0xaa);
writeBank_SNES(startBank, 0x2AAA * 2, 0x55);
writeBank_SNES(startBank, 0x5555 * 2, 0xe0);
writeBank_SNES(startBank, 0x5555L * 2, 0xaa);
writeBank_SNES(startBank, 0x2AAAL * 2, 0x55);
writeBank_SNES(startBank, 0x5555L * 2, 0xe0);
// Wait until complete
busyCheck_NP(startBank);
@ -1204,14 +1204,14 @@ byte blankcheckMapping() {
controlOut_SNES();
// Reset Flash
writeBank_SNES(0xC0, 0x5555 * 2, 0xaa);
writeBank_SNES(0xC0, 0x2AAA * 2, 0x55);
writeBank_SNES(0xC0, 0x5555 * 2, 0xf0);
writeBank_SNES(0xC0, 0x5555L * 2, 0xaa);
writeBank_SNES(0xC0, 0x2AAAL * 2, 0x55);
writeBank_SNES(0xC0, 0x5555L * 2, 0xf0);
// Reset Flash
writeBank_SNES(0xE0, 0x5555 * 2, 0xaa);
writeBank_SNES(0xE0, 0x2AAA * 2, 0x55);
writeBank_SNES(0xE0, 0x5555 * 2, 0xf0);
writeBank_SNES(0xE0, 0x5555L * 2, 0xaa);
writeBank_SNES(0xE0, 0x2AAAL * 2, 0x55);
writeBank_SNES(0xE0, 0x5555L * 2, 0xf0);
// Switch to read
dataIn();
@ -1242,13 +1242,13 @@ void writeMapping(byte startBank, uint32_t pos) {
// Write to Page Buffer
for (unsigned long currByte = 0xFF00; currByte < 0xFFFF; currByte += 128) {
// Prepare to erase/write Page Buffer
writeBank_SNES(startBank, 0x5555 * 2, 0xaa);
writeBank_SNES(startBank, 0x2AAA * 2, 0x55);
writeBank_SNES(startBank, 0x5555 * 2, 0x77);
writeBank_SNES(startBank, 0x5555L * 2, 0xaa);
writeBank_SNES(startBank, 0x2AAAL * 2, 0x55);
writeBank_SNES(startBank, 0x5555L * 2, 0x77);
// Write Page Buffer Command
writeBank_SNES(startBank, 0x5555 * 2, 0xaa);
writeBank_SNES(startBank, 0x2AAA * 2, 0x55);
writeBank_SNES(startBank, 0x5555 * 2, 0x99);
writeBank_SNES(startBank, 0x5555L * 2, 0xaa);
writeBank_SNES(startBank, 0x2AAAL * 2, 0x55);
writeBank_SNES(startBank, 0x5555L * 2, 0x99);
myFile.read(sdBuffer, 128);

View File

@ -392,6 +392,9 @@ void getCartInfo_SNES() {
println_Msg(F("SA1 RAM BATT"));
romType = SA;
}
else if (romChips == 69) {
println_Msg(F("SDD1 BATT"));
}
else if (romChips == 227)
println_Msg(F("RAM GBoy"));
else if (romChips == 246)
@ -500,17 +503,26 @@ boolean checkcart_SNES() {
// Check RomChips
romChips = readBank_SNES(0, 65494);
// Check RomSize
byte romSizeExp = readBank_SNES(0, 65495) - 7;
romSize = 1;
while (romSizeExp--)
romSize *= 2;
if ((romType == EX) || (romType == SA)) {
numBanks = long(romSize) * 2;
if (romChips == 69)
{
romSize = 48;
numBanks = 96;
romType = HI;
}
else {
numBanks = (long(romSize) * 1024 * 1024 / 8) / (32768 + (long(romType) * 32768));
else
{
// Check RomSize
byte romSizeExp = readBank_SNES(0, 65495) - 7;
romSize = 1;
while (romSizeExp--)
romSize *= 2;
if ((romType == EX) || (romType == SA)) {
numBanks = long(romSize) * 2;
}
else {
numBanks = (long(romSize) * 1024 * 1024 / 8) / (32768 + (long(romType) * 32768));
}
}
//Check SD card for alt config
@ -803,7 +815,7 @@ void readROM_SNES() {
}
}
// Dump High-type ROM
else if ((romType == HI) || (romType == SA) || (romType == EX)) {
else if (((romType == HI) || (romType == SA) || (romType == EX)) && (romChips != 69)) {
println_Msg(F("Dumping HiRom..."));
display_Update();
@ -816,6 +828,42 @@ void readROM_SNES() {
}
}
}
// Dump SDD1 High-type ROM
else if ((romType == HI) && (romChips == 69)) {
println_Msg(F("Dumping SDD1 HiRom..."));
display_Update();
controlIn_SNES();
byte initialSOMap = readBank_SNES(0, 18439);
for (int currMemmap=0; currMemmap < (numBanks / 16); currMemmap++) {
dataOut();
controlOut_SNES();
writeBank_SNES(0, 18439, currMemmap);
dataIn();
controlIn_SNES();
for (int currBank = 240; currBank < 256; currBank++) {
for (long currByte = 0; currByte < 65536; currByte += 512) {
for (unsigned long c = 0; c < 512; c++) {
sdBuffer[c] = readBank_SNES(currBank, currByte + c);
}
myFile.write(sdBuffer, 512);
}
}
}
dataOut();
controlOut_SNES();
writeBank_SNES(0, 18439, initialSOMap);
dataIn();
controlIn_SNES();
}
// Close the file:
myFile.close();