Skip to content

Commit

Permalink
Merge branch 'master' of github.com:sanni/cartreader into cps3
Browse files Browse the repository at this point in the history
  • Loading branch information
herzmx committed Sep 12, 2024
2 parents 62c4f5e + d5252f2 commit c301d61
Show file tree
Hide file tree
Showing 19 changed files with 9,284 additions and 3,235 deletions.
9 changes: 3 additions & 6 deletions Cart_Reader/Cart_Reader.ino
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ uint32_t calculateCRC(char* fileName, char* folder, unsigned long offset) {
/******************************************
CRC Functions for Atari, Fairchild, Ody2, Arc, etc. modules
*****************************************/
#if (defined(ENABLE_ODY2) || defined(ENABLE_ARC) || defined(ENABLE_FAIRCHILD) || defined(ENABLE_MSX) || defined(ENABLE_POKE) || defined(ENABLE_2600) || defined(ENABLE_7800) || defined(ENABLE_C64) || defined(ENABLE_VECTREX) || defined(ENABLE_NES) || defined(ENABLE_LYNX) || defined(ENABLE_ATARI8) || defined(ENABLE_BALLY) || defined(ENABLE_LEAP) || defined(ENABLE_LJ) || defined(ENABLE_LJPRO) || defined(ENABLE_PV1000) || defined(ENABLE_PYUUTA) || defined(ENABLE_RCA) || defined(ENABLE_TI99) || defined(ENABLE_TRS80) || defined(ENABLE_VIC20) || defined(ENABLE_VSMILE))
#if (defined(ENABLE_ODY2) || defined(ENABLE_ARC) || defined(ENABLE_FAIRCHILD) || defined(ENABLE_MSX) || defined(ENABLE_POKE) || defined(ENABLE_2600) || defined(ENABLE_7800) || defined(ENABLE_C64) || defined(ENABLE_VECTREX) || defined(ENABLE_NES) || defined(ENABLE_LYNX) || defined(ENABLE_ATARI8) || defined(ENABLE_BALLY) || defined(ENABLE_LEAP) || defined(ENABLE_LJ) || defined(ENABLE_LJPRO) || defined(ENABLE_PV1000) || defined(ENABLE_PYUUTA) || defined(ENABLE_RCA) || defined(ENABLE_TI99) || defined(ENABLE_TRS80) || defined(ENABLE_VIC20) || defined(ENABLE_VSMILE) || defined(ENABLE_CPS3))

void printCRC(char* checkFile, uint32_t* crcCopy, unsigned long offset) {
uint32_t crc = calculateCRC(checkFile, folder, offset);
Expand Down Expand Up @@ -883,8 +883,6 @@ boolean checkCartSelection(FsFile& database, void (*readData)(FsFile&, void*), v
return false;
}

#if ( \
defined(ENABLE_ODY2) || defined(ENABLE_ARC) || defined(ENABLE_FAIRCHILD) || defined(ENABLE_MSX) || defined(ENABLE_POKE) || defined(ENABLE_2600) || defined(ENABLE_5200) || defined(ENABLE_7800) || defined(ENABLE_C64) || defined(ENABLE_VECTREX) || defined(ENABLE_NES) || defined(ENABLE_GBX) || defined(ENABLE_BALLY) || defined(ENABLE_PV1000) || defined(ENABLE_PYUUTA) || defined(ENABLE_RCA) || defined(ENABLE_TRS80) || defined(ENABLE_VIC20) || defined(ENABLE_LEAP) || defined(ENABLE_LJ) || defined(ENABLE_VSMILE) || defined(ENABLE_TI99) || defined(ENABLE_ATARI8) || defined(ENABLE_CPS3))
void printInstructions() {
println_Msg(FS(FSTRING_EMPTY));

Expand Down Expand Up @@ -988,7 +986,6 @@ int navigateMenu(__attribute__((unused)) int min, __attribute__((unused)) int ma
return selectedNumber;
}
#endif /* (ENABLE_OLED | ENABLE_LCD) */
#endif /* ENABLE_<CORES> */

#if (defined(ENABLE_OLED) || defined(ENABLE_LCD))
void starting_letter__subDraw(byte selection, byte line) {
Expand Down Expand Up @@ -2344,8 +2341,8 @@ void setup() {
}

// Start new log if file is too big
if (myLog.fileSize() > 262144) {
EEPROM_readAnything(0, foldern);
EEPROM_readAnything(0, foldern);
if ((myLog.fileSize() > 262144) && (foldern < 9999) && (foldern > 0)){
sprintf(folder, "%s%d%s", "OSCR_LOG_", foldern, ".txt");
foldern = foldern + 1;
EEPROM_writeAnything(0, foldern);
Expand Down
15 changes: 3 additions & 12 deletions Cart_Reader/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@
/****/

/* [ Clock Generator ---------------------------------------------- ]
Enable this if you have the clock generator module. This will
automatically be enabled if you selected HW2 or newer above.
Disable this if you don't have the clock generator module.
*/

//#define ENABLE_CLOCKGEN
#define ENABLE_CLOCKGEN

/****/

Expand Down Expand Up @@ -535,7 +534,7 @@
with all Cart Readers
*/

//#define OPTION_N64_FASTCRC
#define OPTION_N64_FASTCRC

/****/

Expand Down Expand Up @@ -566,29 +565,21 @@
#define ENABLE_NEOPIXEL
#define ENABLE_ROTARY
//# define rotate_counter_clockwise
#define ENABLE_CLOCKGEN
#define OPTION_N64_FASTCRC
#define OPTION_WS_ADAPTER_V2
#endif

#if (defined(HW2) || defined(HW3))
#define ENABLE_OLED
#define ENABLE_BUTTON2
#define ENABLE_CLOCKGEN
#define ENABLE_CA_LED
#define OPTION_N64_FASTCRC
#endif

#if defined(HW1)
#define ENABLE_OLED
//#define ENABLE_CLOCKGEN
//#define OPTION_N64_FASTCRC
#endif

#if defined(SERIAL_MONITOR)
#define ENABLE_SERIAL
//#define ENABLE_CLOCKGEN
//#define OPTION_N64_FASTCRC
#endif

/* Firmware updater only works with HW3 and HW5 */
Expand Down
105 changes: 100 additions & 5 deletions Cart_Reader/MD.ino
Original file line number Diff line number Diff line change
Expand Up @@ -268,28 +268,34 @@ void mdMenu() {
resetFlash_MD();
idFlash_MD();
resetFlash_MD();
print_Msg(F("Flash ID: "));
println_Msg(flashid_str);
if (flashid == 0xC2F1) {
println_Msg(F("MX29F1610 detected"));
flashSize = 2097152;
} else if (flashid == 0x017E) {
println_Msg(F("S29GL064N detected"));
flashSize = 4194304;
} else {
print_Msg(F("Flash ID: "));
println_Msg(flashid_str);
print_FatalError(F("Error: Unknown flashrom"));
}
println_Msg("Erasing...");
display_Update();

eraseFlash_MD();
resetFlash_MD();
blankcheck_MD();
write29F1610_MD();
if (flashid == 0xC2F1)
write29F1610_MD();
else if (flashid == 0x017E)
write29GL_MD();
resetFlash_MD();
delay(1000);
resetFlash_MD();
delay(1000);
println_Msg("Verifying...");
verifyFlash_MD();
// Set CS(PH3) HIGH
PORTH |= (1 << 3);
println_Msg(FS(FSTRING_EMPTY));
// Prints string out of the common strings array either with or without newline
print_STR(press_button_STR, 1);
display_Update();
Expand Down Expand Up @@ -1976,6 +1982,11 @@ void write29F1610_MD() {
// Set data pins to output
dataOut_MD();

//Initialize progress bar
uint32_t processedProgressBar = 0;
uint32_t totalProgressBar = (uint32_t)fileSize / 2;
draw_progressbar(0, totalProgressBar);

// Fill sdBuffer with 1 page at a time then write it repeat until all bytes are written
int d = 0;
for (unsigned long currByte = 0; currByte < fileSize / 2; currByte += 64) {
Expand All @@ -2002,6 +2013,90 @@ void write29F1610_MD() {
// Check if write is complete
delayMicroseconds(100);
busyCheck_MD();

// update progress bar
processedProgressBar += 64;
draw_progressbar(processedProgressBar, totalProgressBar);
}

// Set data pins to input again
dataIn_MD();

// Close the file:
myFile.close();
} else {
print_STR(open_file_STR, 1);
display_Update();
}
}

void write29GL_MD() {
// Create filepath
sprintf(filePath, "%s/%s", filePath, fileName);
print_STR(flashing_file_STR, 0);
print_Msg(filePath);
println_Msg(F("..."));
display_Update();

// Open file on sd card
if (myFile.open(filePath, O_READ)) {
// Get rom size from file
fileSize = myFile.fileSize();
if (fileSize > flashSize) {
print_FatalError(file_too_big_STR);
}
// Set data pins to output
dataOut_MD();

//Initialize progress bar
uint32_t processedProgressBar = 0;
uint32_t totalProgressBar = (uint32_t)fileSize;
draw_progressbar(0, totalProgressBar);

for (unsigned long currSdBuffer = 0; currSdBuffer < fileSize; currSdBuffer += 512) {
myFile.read(sdBuffer, 512);

// Blink led
if (currSdBuffer % 4096 == 0) {
blinkLED();
}

for (int currWriteBuffer = 0; currWriteBuffer < 512; currWriteBuffer += 32) {
// Two unlock cycles
writeFlash_MD(0x555, 0xaa);
writeFlash_MD(0x2aa, 0x55);
// Write Buffer Load command to Sector Address
writeFlash_MD((currSdBuffer + currWriteBuffer) / 2, 0x25);
// Sector Address, Word count
writeFlash_MD((currSdBuffer + currWriteBuffer) / 2, 16 - 1);

// Load buffer
word currWord;
for (byte currByte = 0; currByte < 32; currByte += 2) {
currWord = ((sdBuffer[currWriteBuffer + currByte] & 0xFF) << 8) | (sdBuffer[currWriteBuffer + currByte + 1] & 0xFF);
writeFlash_MD((currSdBuffer + currWriteBuffer + currByte) / 2, currWord);
}

// Write buffer
writeFlash_MD((currSdBuffer + currWriteBuffer + 32 - 2) / 2, 0x29);

// Check if write is complete
// Set data pins to input
dataIn_MD();

// Read the status register
word statusReg = readFlash_MD((currSdBuffer + currWriteBuffer + 32 - 2) / 2);

while ((statusReg | 0xFF7F) != (currWord | 0xFF7F)) {
statusReg = readFlash_MD((currSdBuffer + currWriteBuffer + 32 - 2) / 2);
}

// Set data pins to output
dataOut_MD();
}
// update progress bar
processedProgressBar += 512;
draw_progressbar(processedProgressBar, totalProgressBar);
}

// Set data pins to input again
Expand Down
61 changes: 33 additions & 28 deletions Cart_Reader/NES.ino
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static const struct mapper_NES PROGMEM mapsize[] = {
{ 78, 3, 3, 5, 5, 0, 0 }, // irem 74hc161/32
{ 79, 1, 2, 2, 3, 0, 0 }, // NINA-03/06 by AVE [UNLICENSED]
{ 80, 3, 3, 5, 6, 0, 1 }, // taito x1-005 [prgram r/w]
{ 82, 3, 3, 5, 6, 0, 1 }, // taito x1-017 [prgram r/w]
{ 82, 3, 3, 5, 6, 0, 1 }, // taito x1-017 wrong bank order [prgram r/w]
// 84 - bad mapper, not used
{ 85, 3, 5, 0, 5, 0, 1 }, // vrc7 [sram r/w]
{ 86, 3, 3, 4, 4, 0, 0 }, // jaleco jf-13 (moero pro yakyuu)
Expand Down Expand Up @@ -174,7 +174,8 @@ static const struct mapper_NES PROGMEM mapsize[] = {
{ 246, 5, 5, 7, 7, 0, 0 }, // C&E Feng Shen Bang [UNLICENSED]
// 248 - bad mapper, not used
{ 255, 4, 7, 5, 8, 0, 0 }, // 110-in-1 multicart (same as 225) [UNLICENSED]
{ 446, 0, 8, 0, 0, 0, 0 } // Mindkids SMD172B_FGPA submapper 0 & 1
{ 446, 0, 8, 0, 0, 0, 0 }, // Mindkids SMD172B_FGPA submapper 0 & 1
{ 552, 0, 5, 0, 6, 0, 0 } // Taito X1-017 actual bank order
};

const char _file_name_no_number_fmt[] PROGMEM = "%s.%s";
Expand Down Expand Up @@ -2286,19 +2287,17 @@ void readPRG(bool readrom) {
case 80: // 128K
case 207: // 256K [CART SOMETIMES NEEDS POWERCYCLE]
banks = int_pow(2, prgsize) * 2;
for (size_t i = 0; i < banks; i += 2) {
for (size_t i = 0; i < banks; i++) {
write_prg_byte(0x7EFA, i); // PRG Bank 0 ($8000-$9FFF)
write_prg_byte(0x7EFC, i + 1); // PRG Bank 1 ($A000-$BFFF)
dumpBankPRG(0x0, 0x4000, base);
dumpBankPRG(0x0, 0x2000, base);
}
break;

case 82: // 128K
banks = int_pow(2, prgsize) * 2;
for (size_t i = 0; i < banks; i += 2) {
write_prg_byte(0x7EFA, i << 2); // PRG Bank 0 ($8000-$9FFF)
write_prg_byte(0x7EFB, (i + 1) << 2); // PRG Bank 1 ($A000-$BFFF)
dumpBankPRG(0x0, 0x4000, base); // 8K Banks ($8000-$BFFF)
for (size_t i = 0; i < banks; i++) {
write_prg_byte(0x7EFA, i << 2); // PRG Bank 0 ($8000-$9FFF)
dumpBankPRG(0x0, 0x2000, base); // 8K Banks ($8000-$BFFF)
}
break;

Expand Down Expand Up @@ -2736,18 +2735,24 @@ void readPRG(bool readrom) {
break;

case 446:
{
banks = int_pow(2, prgsize) * 2;
write_prg_byte(0x5003, 0);
write_prg_byte(0x5005, 0);
for (uint8_t i = 0; i < banks; i++) { // 8192 for 64MiB
write_prg_byte(0x5002, i >> 8); // outer bank LSB
write_prg_byte(0x5001, i); // outer bank MSB
write_prg_byte(0x8000, 0);
dumpBankPRG(0x0, 0x2000, base);
}
break;
banks = int_pow(2, prgsize) * 2;
write_prg_byte(0x5003, 0);
write_prg_byte(0x5005, 0);
for (uint8_t i = 0; i < banks; i++) { // 8192 for 64MiB
write_prg_byte(0x5002, i >> 8); // outer bank LSB
write_prg_byte(0x5001, i); // outer bank MSB
write_prg_byte(0x8000, 0);
dumpBankPRG(0x0, 0x2000, base);
}
break;

case 552:
banks = int_pow(2, prgsize) * 2;
for (size_t i = 0; i < banks; i++) {
write_prg_byte(0x7EFA, ((i & 0x01) << 5) | ((i & 0x02) << 3) | ((i & 0x04) << 1) | ((i & 0x08) >> 1) | ((i & 0x10) >> 3) | ((i & 0x20) >> 5)); // PRG Bank 0 ($8000-$9FFF)
dumpBankPRG(0x0, 0x2000, base); // 8K Banks ($8000-$BFFF)
}
break;
}
if (!readrom) {
myFile.flush();
Expand Down Expand Up @@ -3296,13 +3301,13 @@ void readCHR(bool readrom) {
case 80: // 128K/256K
case 82: // 128K/256K
case 207: // 128K [CART SOMETIMES NEEDS POWERCYCLE]
banks = int_pow(2, chrsize) * 4;
for (size_t i = 0; i < banks; i += 4) {
write_prg_byte(0x7EF2, i); // CHR Bank 2 [REGISTERS 0x7EF0/0x7EF1 WON'T WORK]
write_prg_byte(0x7EF3, i + 1); // CHR Bank 3
write_prg_byte(0x7EF4, i + 2); // CHR Bank 4
write_prg_byte(0x7EF5, i + 3); // CHR Bank 5
dumpBankCHR(0x0, 0x2000);
case 552:
banks = int_pow(2, chrsize) * 2;
write_prg_byte(0x7EF6, 0x00); // CHR mode [2x 2KiB banks at $0000-$0FFF]
for (size_t i = 0; i < banks; i += 2) {
write_prg_byte(0x7EF0, i << 1);
write_prg_byte(0x7EF1, (i + 1) << 1);
dumpBankCHR(0x0, 0x1000);
}
break;

Expand Down Expand Up @@ -4651,4 +4656,4 @@ void A29040B_writeFLASH() {
#endif
//******************************************
// End of File
//******************************************
//******************************************
Loading

0 comments on commit c301d61

Please sign in to comment.