mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 13:42:47 +00:00
gamecart: Added a gamecart_id.bin file.
This contains the 4-byte chip ID.
This commit is contained in:
parent
2f2b7faeb4
commit
25a22d30d0
@ -264,6 +264,20 @@ u32 ReadCartPrivateHeader(void* buffer, u64 offset, u64 count, CartData* cdata)
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 ReadCartId(u8* buffer, u64 offset, u64 count, CartData* cdata) {
|
||||
u8 ownBuf[GAMECART_ID_SIZE] = { 0 };
|
||||
u32 id;
|
||||
u8 sReg;
|
||||
if (offset >= GAMECART_ID_SIZE) return 1;
|
||||
if (offset + count > GAMECART_ID_SIZE) count = GAMECART_ID_SIZE - offset;
|
||||
ownBuf[0] = (cdata->cart_id >> 24) & 0xff;
|
||||
ownBuf[1] = (cdata->cart_id >> 16) & 0xff;
|
||||
ownBuf[2] = (cdata->cart_id >> 8) & 0xff;
|
||||
ownBuf[3] = cdata->cart_id & 0xff;
|
||||
memcpy(buffer, ownBuf + offset, count);
|
||||
return 0;
|
||||
}
|
||||
|
||||
u32 ReadCartSave(u8* buffer, u64 offset, u64 count, CartData* cdata) {
|
||||
if (offset >= cdata->save_size) return 1;
|
||||
if (offset + count > cdata->save_size) count = cdata->save_size - offset;
|
||||
|
@ -11,6 +11,7 @@
|
||||
#define MODC_AREA_SIZE 0x4000
|
||||
#define PRIV_HDR_SIZE 0x50
|
||||
#define JEDECID_AND_SREG_SIZE 0x4
|
||||
#define GAMECART_ID_SIZE 0x4
|
||||
|
||||
typedef struct {
|
||||
u8 header[0x8000]; // NTR header + secure area / CTR header + private header
|
||||
@ -29,6 +30,7 @@ u32 InitCartRead(CartData* cdata);
|
||||
u32 ReadCartSectors(void* buffer, u32 sector, u32 count, CartData* cdata);
|
||||
u32 ReadCartBytes(void* buffer, u64 offset, u64 count, CartData* cdata);
|
||||
u32 ReadCartPrivateHeader(void* buffer, u64 offset, u64 count, CartData* cdata);
|
||||
u32 ReadCartId(u8* buffer, u64 offset, u64 count, CartData* cdata);
|
||||
u32 ReadCartSave(u8* buffer, u64 offset, u64 count, CartData* cdata);
|
||||
u32 WriteCartSave(const u8* buffer, u64 offset, u64 count, CartData* cdata);
|
||||
u32 ReadCartSaveJedecId(u8* buffer, u64 offset, u64 count, CartData* cdata);
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "gamecart.h"
|
||||
|
||||
#define FAT_LIMIT 0x100000000
|
||||
#define VFLAG_GAMECART_ID (1UL<<28)
|
||||
#define VFLAG_JEDECID_AND_SRFG (1UL<<29)
|
||||
#define VFLAG_SAVEGAME (1UL<<30)
|
||||
#define VFLAG_PRIV_HDR (1UL<<31)
|
||||
@ -33,7 +34,7 @@ bool ReadVCartDir(VirtualFile* vfile, VirtualDir* vdir) {
|
||||
vfile->keyslot = 0xFF; // unused
|
||||
vfile->flags = VFLAG_READONLY;
|
||||
|
||||
while (++vdir->index <= 7) {
|
||||
while (++vdir->index <= 8) {
|
||||
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;
|
||||
@ -62,7 +63,12 @@ bool ReadVCartDir(VirtualFile* vfile, VirtualDir* vdir) {
|
||||
vfile->size = cdata->save_size;
|
||||
vfile->flags = VFLAG_SAVEGAME;
|
||||
return true;
|
||||
} else if ((vdir->index == 7) && cdata->save_type.chip) { // JEDEC id and status register
|
||||
} else if (vdir->index == 7) { // gamecart ID
|
||||
strcpy(vfile->name, "gamecart_id.bin");
|
||||
vfile->size = GAMECART_ID_SIZE;
|
||||
vfile->flags |= VFLAG_GAMECART_ID;
|
||||
return true;
|
||||
} else if ((vdir->index == 8) && cdata->save_type.chip) { // JEDEC id and status register
|
||||
strcpy(vfile->name, "jedecid_and_sreg.bin");
|
||||
vfile->size = JEDECID_AND_SREG_SIZE;
|
||||
vfile->flags |= VFLAG_JEDECID_AND_SRFG;
|
||||
@ -80,6 +86,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_GAMECART_ID)
|
||||
return ReadCartId(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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user