From 782db58ab1e6a4028e09965c4d3267210f7d50c8 Mon Sep 17 00:00:00 2001 From: sanni Date: Sun, 19 Feb 2023 21:45:52 +0100 Subject: [PATCH] Add fallback if ROM size in MD header is 0 --- Cart_Reader/MD.ino | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Cart_Reader/MD.ino b/Cart_Reader/MD.ino index 69b74d1..659555a 100644 --- a/Cart_Reader/MD.ino +++ b/Cart_Reader/MD.ino @@ -1091,6 +1091,17 @@ void getCartInfo_MD() { cartSize = 0x80000; } + // Some games are missing the ROM size in the header, in this case calculate ROM size by looking for mirror of the first line of the ROM + // This does not work for cartridges that have SRAM mapped directly after the maskrom like Striker (Europe) + if ((cartSize < 0x8000) || (cartSize > 0xEAF400)) { + for (cartSize = 0x20000 / 2; cartSize < 0x400000 / 2; cartSize += 0x20000 / 2) { + if ((readWord_MD(0x0) == readWord_MD(cartSize)) && (readWord_MD(0x1) == readWord_MD(0x1 + cartSize)) && (readWord_MD(0x2) == readWord_MD(0x2 + cartSize)) && (readWord_MD(0x3) == readWord_MD(0x3 + cartSize)) && (readWord_MD(0x4) == readWord_MD(0x4 + cartSize)) && (readWord_MD(0x5) == readWord_MD(0x5 + cartSize)) && (readWord_MD(0x6) == readWord_MD(0x6 + cartSize)) && (readWord_MD(0x7) == readWord_MD(0x7 + cartSize)) && (readWord_MD(0x8) == readWord_MD(0x8 + cartSize))) { + break; + } + } + cartSize = cartSize * 2; + } + display_Clear(); println_Msg(F("Cart Info")); println_Msg(F(" ")); @@ -1249,9 +1260,6 @@ void readROM_MD() { byte buffer[1024] = { 0 }; - // get current time - // unsigned long startTime = millis(); - // Phantasy Star/Beyond Oasis with 74HC74 and 74HC139 switch ROM/SRAM at address 0x200000 if (0x200000 < cartSize && cartSize < 0x400000) { enableSram_MD(0); @@ -1475,12 +1483,6 @@ void readROM_MD() { writeSSF2Map(0x50987F, 7); // 0xA130FF } - // print elapsed time - //print_Msg(F("Time elapsed: ")); - //print_Msg((millis() - startTime) / 1000); - //println_Msg(F("s")); - //display_Update(); - // Calculate internal checksum print_Msg(F("Internal checksum...")); display_Update();