From 9a35691a03d1dc9250208f2a7ab8cdc7fb8bf2aa Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Wed, 12 Apr 2017 00:54:32 -0700 Subject: [PATCH] DS: Attempt to detect if a game is homebrew --- CHANGES | 1 + include/mgba/internal/ds/ds.h | 11 +++++++++++ src/ds/ds.c | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/CHANGES b/CHANGES index 5a4618c24..2f4241d6e 100644 --- a/CHANGES +++ b/CHANGES @@ -17,6 +17,7 @@ Misc: - ARM9: Implement SMLAW and SMULW - Qt: Add .nds files to the extension list in Info.plist - ARM9: Implement STRD/LDRD + - DS: Attempt to detect if a game is homebrew 0.6.0: (Future) Features: diff --git a/include/mgba/internal/ds/ds.h b/include/mgba/internal/ds/ds.h index 1f95a161f..baa2b4a17 100644 --- a/include/mgba/internal/ds/ds.h +++ b/include/mgba/internal/ds/ds.h @@ -123,6 +123,8 @@ struct DS { struct mTimingEvent divEvent; struct mTimingEvent sqrtEvent; + + bool isHomebrew; }; struct DSCartridge { @@ -158,6 +160,15 @@ struct DSCartridge { uint32_t iconOffset; uint16_t secureAreaCrc16; uint16_t secureAreaDelay; + uint32_t arm9Autoload; + uint32_t arm7Autoload; + uint8_t secureAreaDisable[8]; + uint32_t usedSize; + uint32_t romHeaderSize; + uint8_t reserved2[56]; + uint8_t logo[156]; + uint16_t logoCrc16; + uint16_t headerCrc16; // TODO: Fill in more // And ROM data... }; diff --git a/src/ds/ds.c b/src/ds/ds.c index c64af2100..4409d3575 100644 --- a/src/ds/ds.c +++ b/src/ds/ds.c @@ -294,6 +294,7 @@ void DS7Reset(struct ARMCore* cpu) { DS7IOInit(ds); DSConfigureWRAM(&ds->memory, 3); + ds->isHomebrew = false; struct DSCartridge* header = ds->romVf->map(ds->romVf, sizeof(*header), MAP_READ); if (header) { @@ -304,6 +305,9 @@ void DS7Reset(struct ARMCore* cpu) { ds->memory.ram[0x3FFC40 >> 2] = 1; memcpy(&ds->memory.ram[0x3FFE00 >> 2], header, 0x170); DS7IOWrite32(ds, DS_REG_ROMCNT_LO, header->busTiming | 0x2700000); + + ds->isHomebrew = memcmp(&header->logoCrc16, DS_ROM_MAGIC, sizeof(header->logoCrc16)); + // TODO: Error check ds->romVf->seek(ds->romVf, header->arm7Offset, SEEK_SET); uint32_t base = header->arm7Base;