mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 21:52:48 +00:00
gamecart: Replaced ID file with info file
This commit is contained in:
parent
25a22d30d0
commit
647d5722aa
@ -6,6 +6,7 @@
|
|||||||
#include "nds.h"
|
#include "nds.h"
|
||||||
#include "ncch.h"
|
#include "ncch.h"
|
||||||
#include "ncsd.h"
|
#include "ncsd.h"
|
||||||
|
#include "rtc.h"
|
||||||
|
|
||||||
#define CART_INSERTED (!(REG_CARDSTATUS & 0x1))
|
#define CART_INSERTED (!(REG_CARDSTATUS & 0x1))
|
||||||
|
|
||||||
@ -44,6 +45,8 @@ typedef struct {
|
|||||||
u32 arm9i_rom_offset;
|
u32 arm9i_rom_offset;
|
||||||
} PACKED_ALIGN(16) CartDataNtrTwl;
|
} PACKED_ALIGN(16) CartDataNtrTwl;
|
||||||
|
|
||||||
|
DsTime init_time;
|
||||||
|
|
||||||
u32 GetCartName(char* name, CartData* cdata) {
|
u32 GetCartName(char* name, CartData* cdata) {
|
||||||
if (cdata->cart_type & CART_CTR) {
|
if (cdata->cart_type & CART_CTR) {
|
||||||
CartDataCtr* cdata_i = (CartDataCtr*)cdata;
|
CartDataCtr* cdata_i = (CartDataCtr*)cdata;
|
||||||
@ -59,7 +62,32 @@ u32 GetCartName(char* name, CartData* cdata) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32 GetCartInfoString(char* info, CartData* cdata) {
|
||||||
|
if (cdata->cart_type & CART_CTR) {
|
||||||
|
CartDataCtr* cdata_i = (CartDataCtr*)cdata;
|
||||||
|
NcsdHeader* ncsd = &(cdata_i->ncsd);
|
||||||
|
NcchHeader* ncch = &(cdata_i->ncch);
|
||||||
|
snprintf(info, 256, "Title ID : %016llX\nProduct Code : %.10s\nRevision : %lu\nCart ID : %08lX\nPlatform : %s\nTimestamp : 20%02X-%02X-%02X %02X:%02X:%02X\nGM9 Version : %s\n",
|
||||||
|
ncsd->mediaId, ncch->productcode, cdata_i->rom_version, cdata_i->cart_id,
|
||||||
|
(ncch->flags[4] == 0x2) ? "N3DS" : "O3DS",
|
||||||
|
init_time.bcd_Y, init_time.bcd_M, init_time.bcd_D,
|
||||||
|
init_time.bcd_h, init_time.bcd_m, init_time.bcd_s,
|
||||||
|
VERSION);
|
||||||
|
} else if (cdata->cart_type & CART_NTR) {
|
||||||
|
CartDataNtrTwl* cdata_i = (CartDataNtrTwl*)cdata;
|
||||||
|
TwlHeader* nds = &(cdata_i->ntr_header);
|
||||||
|
snprintf(info, 256, "Title String : %.12s\nProduct Code : %.6s\nRevision : %u\nCart ID : %08lX\nPlatform : %s\nTimestamp : 20%02X-%02X-%02X %02X:%02X:%02X\nGM9 Version : %s\n",
|
||||||
|
nds->game_title, nds->game_code, nds->rom_version, cdata_i->cart_id,
|
||||||
|
(nds->unit_code == 0x2) ? "DSi Enhanced" : (nds->unit_code == 0x3) ? "DSi Exclusive" : "DS",
|
||||||
|
init_time.bcd_Y, init_time.bcd_M, init_time.bcd_D,
|
||||||
|
init_time.bcd_h, init_time.bcd_m, init_time.bcd_s,
|
||||||
|
VERSION);
|
||||||
|
} else return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
u32 InitCartRead(CartData* cdata) {
|
u32 InitCartRead(CartData* cdata) {
|
||||||
|
get_dstime(&init_time);
|
||||||
memset(cdata, 0x00, sizeof(CartData));
|
memset(cdata, 0x00, sizeof(CartData));
|
||||||
cdata->cart_type = CART_NONE;
|
cdata->cart_type = CART_NONE;
|
||||||
if (!CART_INSERTED) return 1;
|
if (!CART_INSERTED) return 1;
|
||||||
@ -264,17 +292,17 @@ u32 ReadCartPrivateHeader(void* buffer, u64 offset, u64 count, CartData* cdata)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 ReadCartId(u8* buffer, u64 offset, u64 count, CartData* cdata) {
|
u32 ReadCartInfo(u8* buffer, u64 offset, u64 count, CartData* cdata) {
|
||||||
u8 ownBuf[GAMECART_ID_SIZE] = { 0 };
|
char info[256];
|
||||||
u32 id;
|
u32 len;
|
||||||
u8 sReg;
|
|
||||||
if (offset >= GAMECART_ID_SIZE) return 1;
|
GetCartInfoString(info, cdata);
|
||||||
if (offset + count > GAMECART_ID_SIZE) count = GAMECART_ID_SIZE - offset;
|
len = strnlen(info, 255);
|
||||||
ownBuf[0] = (cdata->cart_id >> 24) & 0xff;
|
|
||||||
ownBuf[1] = (cdata->cart_id >> 16) & 0xff;
|
if (offset >= len) return 0;
|
||||||
ownBuf[2] = (cdata->cart_id >> 8) & 0xff;
|
if (offset + count > len) count = len - offset;
|
||||||
ownBuf[3] = cdata->cart_id & 0xff;
|
memcpy(buffer, info + offset, count);
|
||||||
memcpy(buffer, ownBuf + offset, count);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
#define MODC_AREA_SIZE 0x4000
|
#define MODC_AREA_SIZE 0x4000
|
||||||
#define PRIV_HDR_SIZE 0x50
|
#define PRIV_HDR_SIZE 0x50
|
||||||
#define JEDECID_AND_SREG_SIZE 0x4
|
#define JEDECID_AND_SREG_SIZE 0x4
|
||||||
#define GAMECART_ID_SIZE 0x4
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u8 header[0x8000]; // NTR header + secure area / CTR header + private header
|
u8 header[0x8000]; // NTR header + secure area / CTR header + private header
|
||||||
@ -26,11 +25,12 @@ typedef struct {
|
|||||||
} PACKED_ALIGN(16) CartData;
|
} PACKED_ALIGN(16) CartData;
|
||||||
|
|
||||||
u32 GetCartName(char* name, CartData* cdata);
|
u32 GetCartName(char* name, CartData* cdata);
|
||||||
|
u32 GetCartInfoString(char* info, CartData* cdata);
|
||||||
u32 InitCartRead(CartData* cdata);
|
u32 InitCartRead(CartData* cdata);
|
||||||
u32 ReadCartSectors(void* buffer, u32 sector, u32 count, CartData* cdata);
|
u32 ReadCartSectors(void* buffer, u32 sector, u32 count, CartData* cdata);
|
||||||
u32 ReadCartBytes(void* buffer, u64 offset, u64 count, CartData* cdata);
|
u32 ReadCartBytes(void* buffer, u64 offset, u64 count, CartData* cdata);
|
||||||
u32 ReadCartPrivateHeader(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 ReadCartInfo(u8* buffer, u64 offset, u64 count, CartData* cdata);
|
||||||
u32 ReadCartSave(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 WriteCartSave(const u8* buffer, u64 offset, u64 count, CartData* cdata);
|
||||||
u32 ReadCartSaveJedecId(u8* buffer, u64 offset, u64 count, CartData* cdata);
|
u32 ReadCartSaveJedecId(u8* buffer, u64 offset, u64 count, CartData* cdata);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "gamecart.h"
|
#include "gamecart.h"
|
||||||
|
|
||||||
#define FAT_LIMIT 0x100000000
|
#define FAT_LIMIT 0x100000000
|
||||||
#define VFLAG_GAMECART_ID (1UL<<28)
|
#define VFLAG_GAMECART_NFO (1UL<<28)
|
||||||
#define VFLAG_JEDECID_AND_SRFG (1UL<<29)
|
#define VFLAG_JEDECID_AND_SRFG (1UL<<29)
|
||||||
#define VFLAG_SAVEGAME (1UL<<30)
|
#define VFLAG_SAVEGAME (1UL<<30)
|
||||||
#define VFLAG_PRIV_HDR (1UL<<31)
|
#define VFLAG_PRIV_HDR (1UL<<31)
|
||||||
@ -63,10 +63,12 @@ bool ReadVCartDir(VirtualFile* vfile, VirtualDir* vdir) {
|
|||||||
vfile->size = cdata->save_size;
|
vfile->size = cdata->save_size;
|
||||||
vfile->flags = VFLAG_SAVEGAME;
|
vfile->flags = VFLAG_SAVEGAME;
|
||||||
return true;
|
return true;
|
||||||
} else if (vdir->index == 7) { // gamecart ID
|
} else if (vdir->index == 7) { // gamecart info
|
||||||
strcpy(vfile->name, "gamecart_id.bin");
|
char info[256];
|
||||||
vfile->size = GAMECART_ID_SIZE;
|
GetCartInfoString(info, cdata);
|
||||||
vfile->flags |= VFLAG_GAMECART_ID;
|
snprintf(vfile->name, 32, "%s.txt", name);
|
||||||
|
vfile->size = strnlen(info, 255);
|
||||||
|
vfile->flags |= VFLAG_GAMECART_NFO;
|
||||||
return true;
|
return true;
|
||||||
} else if ((vdir->index == 8) && cdata->save_type.chip) { // JEDEC id and status register
|
} else if ((vdir->index == 8) && cdata->save_type.chip) { // JEDEC id and status register
|
||||||
strcpy(vfile->name, "jedecid_and_sreg.bin");
|
strcpy(vfile->name, "jedecid_and_sreg.bin");
|
||||||
@ -86,8 +88,8 @@ int ReadVCartFile(const VirtualFile* vfile, void* buffer, u64 offset, u64 count)
|
|||||||
return ReadCartPrivateHeader(buffer, foffset, count, cdata);
|
return ReadCartPrivateHeader(buffer, foffset, count, cdata);
|
||||||
else if (vfile->flags & VFLAG_SAVEGAME)
|
else if (vfile->flags & VFLAG_SAVEGAME)
|
||||||
return ReadCartSave(buffer, foffset, count, cdata);
|
return ReadCartSave(buffer, foffset, count, cdata);
|
||||||
else if (vfile->flags & VFLAG_GAMECART_ID)
|
else if (vfile->flags & VFLAG_GAMECART_NFO)
|
||||||
return ReadCartId(buffer, foffset, count, cdata);
|
return ReadCartInfo(buffer, foffset, count, cdata);
|
||||||
else if (vfile->flags & VFLAG_JEDECID_AND_SRFG)
|
else if (vfile->flags & VFLAG_JEDECID_AND_SRFG)
|
||||||
return ReadCartSaveJedecId(buffer, foffset, count, cdata);
|
return ReadCartSaveJedecId(buffer, foffset, count, cdata);
|
||||||
else return ReadCartBytes(buffer, foffset, count, cdata);
|
else return ReadCartBytes(buffer, foffset, count, cdata);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user