Add a vfile to show the JEDEC id for the inserted cart

This is meant to replace the Prompt I was using previously.
Fun fact: WarioWare DIY seems to have *something* on the SPI bus, as it
returns an ID of 0x000001 consistently. Or am I just glitching the
parallel flash? Or did I get a fake?
This commit is contained in:
Balint Kovacs 2019-07-10 22:09:58 +02:00 committed by d0k3
parent fd48c95deb
commit f60a4c1f63
4 changed files with 30 additions and 8 deletions

View File

@ -252,3 +252,18 @@ u32 WriteCartSave(u8* buffer, u64 offset, u64 count, CartData* cdata) {
if (offset + count > cdata->save_size) count = cdata->save_size - offset;
return (SPIWriteSaveData((CardType) cdata->save_type, offset, buffer, count) == 0) ? 0 : 1;
}
u32 ReadCartSaveJedecId(u8* buffer, u64 offset, u64 count, CartData* cdata) {
u8 ownBuf[JEDECID_AND_SREG_SIZE] = { 0 };
u32 id;
u8 sReg;
if (offset >= JEDECID_AND_SREG_SIZE) return 1;
if (offset + count > JEDECID_AND_SREG_SIZE) count = JEDECID_AND_SREG_SIZE - offset;
SPIReadJEDECIDAndStatusReg((CardType) cdata->save_type, &id, &sReg);
ownBuf[0] = (id >> 16) & 0xff;
ownBuf[1] = (id >> 8) & 0xff;
ownBuf[2] = id & 0xff;
ownBuf[JEDECID_AND_SREG_SIZE - 1] = sReg;
memcpy(buffer, ownBuf, count);
return 0;
}

View File

@ -7,8 +7,9 @@
#define CART_NTR (1<<1)
#define CART_TWL (1<<2)
#define MODC_AREA_SIZE 0x4000
#define PRIV_HDR_SIZE 0x50
#define MODC_AREA_SIZE 0x4000
#define PRIV_HDR_SIZE 0x50
#define JEDECID_AND_SREG_SIZE 0x4
typedef struct {
u8 header[0x8000]; // NTR header + secure area / CTR header + private header
@ -29,3 +30,4 @@ u32 ReadCartBytes(void* buffer, u64 offset, u64 count, CartData* cdata);
u32 ReadCartPrivateHeader(void* buffer, u64 offset, u64 count, CartData* cdata);
u32 ReadCartSave(u8* buffer, u64 offset, u64 count, CartData* cdata);
u32 WriteCartSave(u8* buffer, u64 offset, u64 count, CartData* cdata);
u32 ReadCartSaveJedecId(u8* buffer, u64 offset, u64 count, CartData* cdata);

View File

@ -19,7 +19,6 @@
#include "spi.h"
#include "spicard.h"
#include "timer.h"
#include "ui.h"
// Deliberately written in C! (except for a few lines)
@ -89,8 +88,6 @@ int SPIReadJEDECIDAndStatusReg(CardType type, u32* id, u8* statusReg) {
if(id) *id = id_;
if(statusReg) *statusReg = reg;
ShowPrompt(false, "JEDEC = %lx, StatusReg = %hhx", *id, reg);
return 0;
}

View File

@ -2,8 +2,9 @@
#include "gamecart.h"
#define FAT_LIMIT 0x100000000
#define VFLAG_SAVEGAME (1UL<<30)
#define VFLAG_PRIV_HDR (1UL<<31)
#define VFLAG_JEDECID_AND_SRFG (1UL<<29)
#define VFLAG_SAVEGAME (1UL<<30)
#define VFLAG_PRIV_HDR (1UL<<31)
static CartData* cdata = NULL;
static bool cart_init = false;
@ -32,7 +33,7 @@ bool ReadVCartDir(VirtualFile* vfile, VirtualDir* vdir) {
vfile->keyslot = 0xFF; // unused
vfile->flags = VFLAG_READONLY;
while (++vdir->index <= 6) {
while (++vdir->index <= 7) {
if ((vdir->index == 0) && (cdata->data_size < FAT_LIMIT)) { // standard full rom
snprintf(vfile->name, 32, "%s.%s", name, ext);
vfile->size = cdata->cart_size;
@ -61,6 +62,11 @@ bool ReadVCartDir(VirtualFile* vfile, VirtualDir* vdir) {
vfile->size = cdata->save_size;
vfile->flags = VFLAG_SAVEGAME;
return true;
} else if (vdir->index == 7) { // JEDEC id and status register
strcpy(vfile->name, "jedecid_and_sreg.bin");
vfile->size = JEDECID_AND_SREG_SIZE;
vfile->flags = VFLAG_JEDECID_AND_SRFG;
return true;
}
}
@ -74,6 +80,8 @@ int ReadVCartFile(const VirtualFile* vfile, void* buffer, u64 offset, u64 count)
return ReadCartPrivateHeader(buffer, foffset, count, cdata);
else if (vfile->flags & VFLAG_SAVEGAME)
return ReadCartSave(buffer, foffset, count, cdata);
else if (vfile->flags & VFLAG_JEDECID_AND_SRFG)
return ReadCartSaveJedecId(buffer, foffset, count, cdata);
else return ReadCartBytes(buffer, foffset, count, cdata);
}