forked from Mirror/GodMode9
Temporarily disable IR carts
And massively simplify chip detection
This commit is contained in:
parent
c51d8a7191
commit
2f24f37e7b
@ -438,24 +438,28 @@ int _SPIIsDataMirrored(CardSPIType type, int size, bool* mirrored) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CardSPIGetCardSPIType(CardSPIType* type, int infrared) {
|
||||
int CardSPIGetCardSPIType(CardSPIType* type, bool infrared) {
|
||||
u8 sr = 0;
|
||||
u32 jedec = 0;
|
||||
u32 tries = 0;
|
||||
CardSPIType t = { &FLASH_DUMMY, infrared == 1 };
|
||||
CardSPIType t = {NO_CHIP, infrared};
|
||||
int res;
|
||||
|
||||
u32 maxTries = (infrared == -1) ? 2 : 1; // note: infrared = -1 fails 1/3 of the time
|
||||
while(tries < maxTries){
|
||||
res = CardSPIReadJEDECIDAndStatusReg(t, &jedec, &sr); // dummy
|
||||
if(infrared) {
|
||||
// Infrared carts currently not supported, need additional handling!
|
||||
*type = (CardSPIType) {NO_CHIP, true};
|
||||
return 0;
|
||||
}
|
||||
|
||||
res = CardSPIReadJEDECIDAndStatusReg(t, &jedec, &sr);
|
||||
if (res) return res;
|
||||
|
||||
if ((sr & 0xfd) == 0x00 && (jedec != 0x00ffffff)) { break; }
|
||||
if ((sr & 0xfd) == 0x00 && (jedec != 0x00ffffff)) { t.chip = &FLASH_DUMMY; }
|
||||
if ((sr & 0xfd) == 0xF0 && (jedec == 0x00ffffff)) { *type = (CardSPIType) { EEPROM_512B, false }; return 0; }
|
||||
if ((sr & 0xfd) == 0x00 && (jedec == 0x00ffffff)) { t = (CardSPIType) { &EEPROM_DUMMY, false }; break; }
|
||||
if ((sr & 0xfd) == 0x00 && (jedec == 0x00ffffff)) { t = (CardSPIType) { &EEPROM_DUMMY, false }; }
|
||||
|
||||
++tries;
|
||||
t.infrared = true;
|
||||
if(t.chip == NO_CHIP) {
|
||||
*type = (CardSPIType) {NO_CHIP, false};
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (t.chip == &EEPROM_DUMMY) {
|
||||
@ -473,17 +477,14 @@ int CardSPIGetCardSPIType(CardSPIType* type, int infrared) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (infrared == 0 && t.infrared) *type = (CardSPIType) { NO_CHIP, false }; // did anything go wrong?
|
||||
if (infrared == 1 && !t.infrared) *type = (CardSPIType) { NO_CHIP, true };
|
||||
|
||||
for(size_t i = 0; i < sizeof(flashTypes) / sizeof(CardSPITypeData); i++) {
|
||||
if (flashTypes[i].jedecId == jedec) {
|
||||
*type = (CardSPIType) { flashTypes + i, t.infrared };
|
||||
*type = (CardSPIType) { flashTypes + i, infrared };
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
*type = (CardSPIType) { NO_CHIP, t.infrared };
|
||||
*type = (CardSPIType) { NO_CHIP, infrared };
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ const CardSPITypeData * const FLASH_256KB_2;
|
||||
const CardSPITypeData * const FLASH_512KB_1;
|
||||
const CardSPITypeData * const FLASH_512KB_2;
|
||||
const CardSPITypeData * const FLASH_1MB;
|
||||
const CardSPITypeData * const FLASH_8MB; // <- can't restore savegames, and maybe not read them atm
|
||||
const CardSPITypeData * const FLASH_8MB;
|
||||
|
||||
const CardSPITypeData * const FLASH_128KB_CTR; // Most common, including Ocarina of time 3D
|
||||
const CardSPITypeData * const FLASH_512KB_CTR; // Also common, including Detective Pikachu
|
||||
@ -70,7 +70,7 @@ int CardSPIWriteRead(CardSPIType type, const void* cmd, u32 cmdSize, void* answe
|
||||
int CardSPIWaitWriteEnd(CardSPIType type);
|
||||
int CardSPIEnableWriting(CardSPIType type);
|
||||
int CardSPIReadJEDECIDAndStatusReg(CardSPIType type, u32* id, u8* statusReg);
|
||||
int CardSPIGetCardSPIType(CardSPIType* type, int infrared);
|
||||
int CardSPIGetCardSPIType(CardSPIType* type, bool infrared);
|
||||
u32 CardSPIGetPageSize(CardSPIType type);
|
||||
u32 CardSPIGetCapacity(CardSPIType type);
|
||||
u32 CardSPIGetEraseSize(CardSPIType type);
|
||||
|
@ -134,7 +134,7 @@ u32 InitCartRead(CartData* cdata) {
|
||||
if (cdata->data_size > cdata->cart_size) return 1;
|
||||
|
||||
// save data
|
||||
u32 infrared = (*(nds_header->game_code) == 'I') ? 1 : 0;
|
||||
bool infrared = *(nds_header->game_code) == 'I';
|
||||
if (CardSPIGetCardSPIType(&(cdata->save_type), infrared) != 0) {
|
||||
cdata->save_type = (CardSPIType) { NO_CHIP, false };
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user