Update NGP.ino

- Manual rom size selection added before dumping when flash chip is unknown
- Code display rearranged
This commit is contained in:
PsyK0p4T 2021-08-18 01:00:07 +02:00 committed by GitHub
parent bd4999b716
commit 8fb0a2b11a

View File

@ -9,6 +9,12 @@ static const char ngpMenuItem1[] PROGMEM = "Read Rom";
static const char ngpMenuItemReset[] PROGMEM = "Reset"; static const char ngpMenuItemReset[] PROGMEM = "Reset";
static const char* const menuOptionsNGP[] PROGMEM = {ngpMenuItem1, ngpMenuItemReset}; static const char* const menuOptionsNGP[] PROGMEM = {ngpMenuItem1, ngpMenuItemReset};
static const char ngpRomItem1[] PROGMEM = "4 Mbits";
static const char ngpRomItem2[] PROGMEM = "8 Mbits";
static const char ngpRomItem3[] PROGMEM = "16 Mbits";
static const char ngpRomItem4[] PROGMEM = "32 Mbits";
static const char* const ngpRomOptions[] PROGMEM = {ngpRomItem1, ngpRomItem2, ngpRomItem3, ngpRomItem4};
char ngpRomVersion[3]; char ngpRomVersion[3];
uint8_t ngpSystemType; uint8_t ngpSystemType;
uint8_t manufacturerID; uint8_t manufacturerID;
@ -37,11 +43,8 @@ void setup_NGP() {
PORTH |= ((1 << 0) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6)); PORTH |= ((1 << 0) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6));
if (getCartInfo_NGP()) if (getCartInfo_NGP())
{
printCartInfo_NGP(); printCartInfo_NGP();
} else {
else
{
println_Msg(F("NeoGeo Pocket")); println_Msg(F("NeoGeo Pocket"));
println_Msg(F("")); println_Msg(F(""));
println_Msg(F("")); println_Msg(F(""));
@ -59,8 +62,7 @@ void ngpMenu() {
convertPgm(menuOptionsNGP, 2); convertPgm(menuOptionsNGP, 2);
mainMenu = question_box(F("NGP Menu"), menuOptions, 2, 0); mainMenu = question_box(F("NGP Menu"), menuOptions, 2, 0);
switch (mainMenu) switch (mainMenu) {
{
case 0: case 0:
sd.chdir("/"); sd.chdir("/");
readROM_NGP(filePath, FILEPATH_LENGTH); readROM_NGP(filePath, FILEPATH_LENGTH);
@ -97,42 +99,40 @@ bool getCartInfo_NGP() {
*(tmp + 0) = deviceID; *(tmp + 0) = deviceID;
*(tmp + 1) = manufacturerID; *(tmp + 1) = manufacturerID;
switch (romSize) switch (romSize) {
{ // detection error
// detection error case 0xffff:
case 0xffff: return false;
return false; break;
break;
// 4 Mbits
// 4 Mbits case 0x98ab:
// Toshiba cartSize = 524288;
case 0x98ab: break;
cartSize = 524288; // Toshiba ?
break; case 0x204c:
// Toshiba ? cartSize = 524288;
case 0x204c: break;
cartSize = 524288;
break;
// 8 Mbits // 8 Mbits
// Toshiba // Toshiba
case 0x982c: case 0x982c:
cartSize = 1048576; cartSize = 1048576;
break; break;
// Samsung // Samsung
case 0xec2c: case 0xec2c:
cartSize = 1048576; cartSize = 1048576;
break; break;
// 16 Mbits // 16 Mbits
// Toshiba // Toshiba
case 0x982f: case 0x982f:
cartSize = 2097152; cartSize = 2097152;
break; break;
// Samsung // Samsung
case 0xec2f: case 0xec2f:
cartSize = 2097152; cartSize = 2097152;
break; break;
} }
// reset to read mode // reset to read mode
@ -151,8 +151,8 @@ bool getCartInfo_NGP() {
snprintf(cartID, 5, "%02X%02X", readByte_NGP(0x21), readByte_NGP(0x20)); snprintf(cartID, 5, "%02X%02X", readByte_NGP(0x21), readByte_NGP(0x20));
// force rom size to 32Mbits for few titles // force rom size to 32Mbits for few titles
if (strcmp(cartID,"0060") == 0 || strcmp(cartID,"0061") == 0 || strcmp(cartID,"0069") == 0 ) if (strcmp(cartID,"0060") == 0 || strcmp(cartID,"0061") == 0 || strcmp(cartID,"0069") == 0 )
cartSize = 4194304; cartSize = 4194304;
// get app version // get app version
snprintf(ngpRomVersion, 3, "%02X", readByte_NGP(0x22)); snprintf(ngpRomVersion, 3, "%02X", readByte_NGP(0x22));
@ -190,14 +190,12 @@ void printCartInfo_NGP() {
println_Msg(F("Unknown")); println_Msg(F("Unknown"));
print_Msg(F("Rom Size: ")); print_Msg(F("Rom Size: "));
if (cartSize == 0) if (cartSize == 0) {
{
println_Msg(F("Unknown")); println_Msg(F("Unknown"));
print_Msg(F("Chip ID: ")); print_Msg(F("Chip ID: "));
println_Msg(String(manufacturerID,HEX) + " " + String(deviceID,HEX)); println_Msg(String(manufacturerID,HEX) + " " + String(deviceID,HEX));
} }
else else {
{
print_Msg((cartSize >> 17)); print_Msg((cartSize >> 17));
println_Msg(F(" Mbits")); println_Msg(F(" Mbits"));
} }
@ -208,6 +206,38 @@ void printCartInfo_NGP() {
} }
void readROM_NGP(char *outPathBuf, size_t bufferSize) { void readROM_NGP(char *outPathBuf, size_t bufferSize) {
// Set cartsize manually if chip ID is unknown
if (cartSize == 0) {
unsigned char ngpRomMenu;
// Copy menuOptions out of progmem
convertPgm(ngpRomOptions, 4);
ngpRomMenu = question_box(F("Select ROM size"), menuOptions, 4, 0);
// wait for user choice to come back from the question box menu
switch (ngpRomMenu) {
case 0:
// 4 Mbits
cartSize = 524288;
break;
case 1:
// 8 Mbits
cartSize = 1048576;
break;
case 2:
// 16 Mbits
cartSize = 2097152;
break;
case 3:
// 32 Mbits
cartSize = 4194304;
break;
}
}
// generate fullname of rom file // generate fullname of rom file
snprintf(fileName, FILENAME_LENGTH, "%s.ngp", romName); snprintf(fileName, FILENAME_LENGTH, "%s.ngp", romName);
@ -239,14 +269,14 @@ void readROM_NGP(char *outPathBuf, size_t bufferSize) {
dataOut(); dataOut();
writeByte_NGP(0x0, 0xf0); writeByte_NGP(0x0, 0xf0);
// read rom // read rom
dataIn(); dataIn();
for (uint32_t addr = 0; addr < cartSize; addr += 512) { for (uint32_t addr = 0; addr < cartSize; addr += 512) {
// blink LED // blink LED
if ((addr & ((1 << 14) - 1)) == 0) if ((addr & ((1 << 14) - 1)) == 0)
PORTB ^= (1 << 4); PORTB ^= (1 << 4);
// read block
for (uint32_t i = 0; i < 512; i++) for (uint32_t i = 0; i < 512; i++)
sdBuffer[i] = readByte_NGP(addr + i); sdBuffer[i] = readByte_NGP(addr + i);