Merge pull request #226 from PsyK0p4T/master

Update NGP.ino
This commit is contained in:
sanni 2021-08-17 07:27:28 +02:00 committed by GitHub
commit bd4999b716

View File

@ -11,6 +11,8 @@ static const char* const menuOptionsNGP[] PROGMEM = {ngpMenuItem1, ngpMenuItemRe
char ngpRomVersion[3]; char ngpRomVersion[3];
uint8_t ngpSystemType; uint8_t ngpSystemType;
uint8_t manufacturerID;
uint8_t deviceID;
void setup_NGP() { void setup_NGP() {
// A0 - A7 // A0 - A7
@ -36,14 +38,14 @@ void setup_NGP() {
if (getCartInfo_NGP()) if (getCartInfo_NGP())
{ {
showCartInfo_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(""));
println_Msg(F("Rom Size Error")); println_Msg(F("Cartridge read error"));
println_Msg(F("")); println_Msg(F(""));
println_Msg(F("Press Button...")); println_Msg(F("Press Button..."));
display_Update(); display_Update();
@ -86,97 +88,120 @@ bool getCartInfo_NGP() {
writeByte_NGP(0x555, 0x90); writeByte_NGP(0x555, 0x90);
dataIn(); dataIn();
cartSize = 0; cartSize = 0;
// get chip manufacturer and device IDs
manufacturerID = readByte_NGP(0);
deviceID = readByte_NGP(1);
tmp = (uint8_t*)&romSize; tmp = (uint8_t*)&romSize;
*(tmp + 0) = readByte_NGP(0); *(tmp + 0) = deviceID;
*(tmp + 1) = readByte_NGP(1); *(tmp + 1) = manufacturerID;
switch (romSize) switch (romSize)
{ {
// detection error
case 0xffff:
return false;
break;
// 4 Mbits // 4 Mbits
// Toshiba // Toshiba
case 0xab98: case 0x98ab:
cartSize = 524288; cartSize = 524288;
break; break;
// Toshiba ? // Toshiba ?
case 0x4c20: case 0x204c:
cartSize = 524288; cartSize = 524288;
break; break;
// 8 Mbits // 8 Mbits
// Toshiba // Toshiba
case 0x2c98: case 0x982c:
cartSize = 1048576; cartSize = 1048576;
break; break;
// Samsung // Samsung
case 0x2cec: case 0xec2c:
cartSize = 1048576; cartSize = 1048576;
break; break;
// 16 Mbits // 16 Mbits
// Toshiba // Toshiba
case 0x2f98: case 0x982f:
cartSize = 2097152; cartSize = 2097152;
break; break;
// Samsung // Samsung
case 0x2fec: case 0xec2f:
cartSize = 2097152; cartSize = 2097152;
break; break;
} }
// reset to read mode // reset to read mode
dataOut(); dataOut();
writeByte_NGP(0x000000, 0xf0); writeByte_NGP(0x0, 0xf0);
if (cartSize == 0)
return false;
dataIn(); dataIn();
// confirm NGP cart recognition
for (uint32_t addr = 0; addr < 28; addr++) for (uint32_t addr = 0; addr < 28; addr++)
sdBuffer[addr] = readByte_NGP(addr); sdBuffer[addr] = readByte_NGP(addr);
if (memcmp_P(sdBuffer, PSTR("COPYRIGHT BY SNK CORPORATION"), 28) != 0 && memcmp_P(sdBuffer, PSTR(" LICENSED BY SNK CORPORATION"), 28) != 0) if (memcmp_P(sdBuffer, PSTR("COPYRIGHT BY SNK CORPORATION"), 28) != 0 && memcmp_P(sdBuffer, PSTR(" LICENSED BY SNK CORPORATION"), 28) != 0)
return false; return false;
snprintf(cartID, 5, "%02X%02X", readByte_NGP(0x000021), readByte_NGP(0x000020)); // get app ID
snprintf(ngpRomVersion, 3, "%02X", readByte_NGP(0x000022)); snprintf(cartID, 5, "%02X%02X", readByte_NGP(0x21), readByte_NGP(0x20));
ngpSystemType = readByte_NGP(0x000023);
// force rom size to 32Mbits for few titles
if (strcmp(cartID,"0060") == 0 || strcmp(cartID,"0061") == 0 || strcmp(cartID,"0069") == 0 )
cartSize = 4194304;
// get app version
snprintf(ngpRomVersion, 3, "%02X", readByte_NGP(0x22));
// get app system compatibility
ngpSystemType = readByte_NGP(0x23);
// get app name
for (uint32_t i = 0; i < 17; i++) for (uint32_t i = 0; i < 17; i++)
romName[i] = readByte_NGP(0x24 + i); romName[i] = readByte_NGP(0x24 + i);
return true; return true;
} }
void showCartInfo_NGP() { void printCartInfo_NGP() {
display_Clear(); display_Clear();
println_Msg(F("NGP Cart Info")); println_Msg(F("NGP Cart Info"));
print_Msg(F("Game: ")); print_Msg(F("Name: "));
println_Msg(romName); println_Msg(romName);
print_Msg(F("GameID: ")); print_Msg(F("ID: "));
println_Msg(cartID); println_Msg(cartID);
print_Msg(F("Version: ")); print_Msg(F("Version: "));
println_Msg(ngpRomVersion); println_Msg(ngpRomVersion);
print_Msg(F("System: ")); print_Msg(F("System: "));
if (ngpSystemType == 0) if (ngpSystemType == 0x0)
println_Msg(F("NGPMonochrome")); println_Msg(F("NGPMonochrome"));
else if (ngpSystemType == 16) else if (ngpSystemType == 0x10)
println_Msg(F("NGPColor")); println_Msg(F("NGPColor"));
else else
println_Msg(F("Unknown")); println_Msg(F("Unknown"));
print_Msg(F("Rom Size: ")); print_Msg(F("Rom Size: "));
if (cartSize == 0)
{
println_Msg(F("Unknown"));
print_Msg(F("Chip ID: "));
println_Msg(String(manufacturerID,HEX) + " " + String(deviceID,HEX));
}
else
{
print_Msg((cartSize >> 17)); print_Msg((cartSize >> 17));
println_Msg(F(" Mbits")); println_Msg(F(" Mbits"));
}
println_Msg(F(""));
println_Msg(F("Press Button...")); println_Msg(F("Press Button..."));
display_Update(); display_Update();
wait(); wait();
@ -214,6 +239,7 @@ void readROM_NGP(char *outPathBuf, size_t bufferSize) {
dataOut(); dataOut();
writeByte_NGP(0x0, 0xf0); writeByte_NGP(0x0, 0xf0);
// read rom
dataIn(); dataIn();
for (uint32_t addr = 0; addr < cartSize; addr += 512) { for (uint32_t addr = 0; addr < cartSize; addr += 512) {