From f60a4c1f637b1b0f5a023a02d9f0297ad2643f33 Mon Sep 17 00:00:00 2001 From: Balint Kovacs Date: Wed, 10 Jul 2019 22:09:58 +0200 Subject: [PATCH] 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? --- arm9/source/gamecart/gamecart.c | 15 +++++++++++++++ arm9/source/gamecart/gamecart.h | 6 ++++-- arm9/source/gamecart/spi.c | 3 --- arm9/source/virtual/vcart.c | 14 +++++++++++--- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/arm9/source/gamecart/gamecart.c b/arm9/source/gamecart/gamecart.c index e35a0bb..ab20cd6 100644 --- a/arm9/source/gamecart/gamecart.c +++ b/arm9/source/gamecart/gamecart.c @@ -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; +} diff --git a/arm9/source/gamecart/gamecart.h b/arm9/source/gamecart/gamecart.h index dedb461..dfe4a1c 100644 --- a/arm9/source/gamecart/gamecart.h +++ b/arm9/source/gamecart/gamecart.h @@ -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); diff --git a/arm9/source/gamecart/spi.c b/arm9/source/gamecart/spi.c index 301a8ba..697993e 100644 --- a/arm9/source/gamecart/spi.c +++ b/arm9/source/gamecart/spi.c @@ -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; } diff --git a/arm9/source/virtual/vcart.c b/arm9/source/virtual/vcart.c index 0d79fc8..098074d 100644 --- a/arm9/source/virtual/vcart.c +++ b/arm9/source/virtual/vcart.c @@ -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); }