Skip to content

Commit

Permalink
B4DS: Add support for *System FLAW*
Browse files Browse the repository at this point in the history
Requires DS Debug console
  • Loading branch information
RocketRobz committed Sep 9, 2024
1 parent eda7d71 commit 62d8825
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion retail/arm9/source/conf_sd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1869,7 +1869,7 @@ int loadFromSD(configuration* conf, const char *bootstrapPath) {
}
}

const bool foto = (strncmp(romTid, "DMF", 3) == 0);
const bool foto = (strncmp(romTid, "DMF", 3) == 0 || strncmp(romTid, "DSY", 3) == 0);

// Load ce9 binary
if (b4dsDebugRam) {
Expand Down
25 changes: 25 additions & 0 deletions retail/bootloader/source/arm7/dsi2ds_patches.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,31 @@ void patchDSiModeToDSMode(cardengineArm9* ce9, const tNDSHeader* ndsHeader) {
*(u32*)0x02072984 += 0xE0000000; // beq -> b
}

// System FLAW (USA)
// Requires 8MB of RAM
else if (strcmp(romTid, "DSYE") == 0 && extendedMemory) {
*(u32*)0x0200D0A0 = 0xE3A00000; // mov r0, #0
*(u32*)0x0200F964 = 0xE1A00000; // nop
*(u32*)0x02012A90 = 0xE1A00000; // nop
patchInitDSiWare(0x02018070, heapEnd);
*(u32*)0x020183E0 = *(u32*)0x020510B4;
setBL(0x0201DA1C, (int)ce9->patches->musicPlay); // Play video
/* *(u32*)0x02023320 = 0xE12FFF1E; // bx lr (Disable music)
*(u32*)0x020234F0 = 0xE12FFF1E; // bx lr (Disable sound)
*(u32*)0x02023614 = 0xE12FFF1E; // bx lr (Disable sound) */
}

// System FLAW (Europe)
// Requires 8MB of RAM
else if (strcmp(romTid, "DSYP") == 0 && extendedMemory) {
*(u32*)0x0200D0F4 = 0xE3A00000; // mov r0, #0
*(u32*)0x0200F9B8 = 0xE1A00000; // nop
*(u32*)0x02012AE4 = 0xE1A00000; // nop
patchInitDSiWare(0x020180C4, heapEnd);
*(u32*)0x02018434 = *(u32*)0x020510C8;
setBL(0x0201DA70, (int)ce9->patches->musicPlay); // Play video
}

// Patch DSiWare to run in DS mode

// 1st Class Poker & BlackJack (USA)
Expand Down
1 change: 1 addition & 0 deletions retail/bootloader/source/arm7/patch_arm9.c
Original file line number Diff line number Diff line change
Expand Up @@ -2187,6 +2187,7 @@ u32 patchCardNdsArm9(cardengineArm9* ce9, const tNDSHeader* ndsHeader, const mod
|| (strncmp(romTid, "DMD", 3) == 0 && extendedMemory)
|| strncmp(romTid, "DMP", 3) == 0
|| strncmp(romTid, "DHS", 3) == 0
|| (strncmp(romTid, "DSY", 3) == 0 && extendedMemory)
) && arm7mbk == 0x080037C0 && donorFileCluster != CLUSTER_FREE) {
u32 startOffset = (u32)ndsHeader->arm9executeAddress;
if (moduleParams->sdk_version > 0x5050000) {
Expand Down
31 changes: 31 additions & 0 deletions retail/cardengine/arm9/source/cardengine.c
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,37 @@ void musicPlay(int id)
#endif
{
#ifdef FOTO
if (strncmp(getRomTid(ndsHeader), "DSY", 3) == 0) {
// This is System FLAW
if (ce9->musicCluster == 0 || ce9->musicsSize < 0x18004*2) {
return;
}

videoFrameLoading = true;
const u16 exmemcnt = REG_EXMEMCNT;
setDeviceOwner();

u32 frameOffset = (ndsHeader->gameCode[3] == 'P') ? 0x020767E0 : 0x02077C60;
static u32 frameOffsetAdd = 0x30000;

fileRead((char*)frameOffset+frameOffsetAdd, &musicsFile, videoPos, (256*192)*2);
frameOffsetAdd += 0x30000;
if (frameOffsetAdd > 0x30000*4) frameOffsetAdd = 0;

videoPos += 0x18004; // Seek to next frame
if (videoPos >= ce9->musicsSize) videoPos = 0; // Loop back to first frame after last frame has been reached

REG_EXMEMCNT = exmemcnt;
videoFrameLoading = false;

for (int i = 0; i < videoFrameDelayMax/2; i++) {
while (REG_VCOUNT != 191);
while (REG_VCOUNT == 191);
}
return;
}

// Otherwise, this is Foto Showdown
if (ce9->musicCluster == 0 || ce9->musicsSize < 0x18000) {
toncset16((u16*)0x06008000, 0x8000, 256*192);
return;
Expand Down

0 comments on commit 62d8825

Please sign in to comment.