Skip to content

Commit

Permalink
Compress NRIO DLDI driver to fit in bootstub (without loading from Ni…
Browse files Browse the repository at this point in the history
…troFS)
  • Loading branch information
RocketRobz committed Nov 14, 2024
1 parent d852daa commit 9c243aa
Show file tree
Hide file tree
Showing 9 changed files with 1,496 additions and 375 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <nds.h>
#include <nds/ndstypes.h>

TWL_CODE ALIGN(4) unsigned char nrio_dldi[19724] = {
0xED, 0xA5, 0x8D, 0xBF, 0x20, 0x43, 0x68, 0x69, 0x73, 0x68, 0x6D, 0x00,
Expand Down
2 changes: 1 addition & 1 deletion arm9/dldi-include/dldi-include.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

extern unsigned char ak2_dldi[];
extern unsigned char r4tf_dldi[];
extern unsigned char nrio_dldi[];
extern unsigned char nrio_lz77[];

// extern unsigned char dstwo_dldi[];
// extern unsigned char ttio_dldi[];
Expand Down
1,047 changes: 1,047 additions & 0 deletions arm9/dldi-include/nrio_lz77.c

Large diffs are not rendered by default.

31 changes: 30 additions & 1 deletion arm9/source/driveOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,35 @@ TWL_CODE void dldiLoadFromBin (const u8 dldiAddr[]) {
dldiRelocateBinary ((data_t*)dldiAddr, dldiSize);
}

TWL_CODE void dldiLoadFromLzss (const u8 dldiLzss[], const u32 len) {
*(u32*)0x02FF8000 = 0x53535A4C;
tonccpy((u32*)0x02FF8004, dldiLzss, len);

u32* dldiAddr = new u32[0x8000/sizeof(u32)];
LZ77_Decompress((u8*)0x02FF8004, (u8*)dldiAddr);

// Check that it is a valid DLDI
if (!dldiIsValid ((DLDI_INTERFACE*)dldiAddr)) {
delete[] dldiAddr;
return;
}

DLDI_INTERFACE* device = (DLDI_INTERFACE*)dldiAddr;
size_t dldiSize;

// Calculate actual size of DLDI
// Although the file may only go to the dldiEnd, the BSS section can extend past that
if (device->dldiEnd > device->bssEnd) {
dldiSize = (char*)device->dldiEnd - (char*)device->dldiStart;
} else {
dldiSize = (char*)device->bssEnd - (char*)device->dldiStart;
}
dldiSize = (dldiSize + 0x03) & ~0x03; // Round up to nearest integer multiple

dldiRelocateBinary ((data_t*)dldiAddr, dldiSize);
delete[] dldiAddr;
}

TWL_CODE bool UpdateCardInfo(char* gameid, char* gamename) {
cardReadHeader((uint8*)0x02000000);
tonccpy(&nds, (void*)0x02000000, sizeof(sNDSHeader));
Expand Down Expand Up @@ -416,7 +445,7 @@ TWL_CODE bool twl_flashcardMount(void) {
dldiLoadFromBin(r4tf_dldi);
fatMountSimple("fat", dldiGet());
} else if (!memcmp(gameid, "DSGB", 4)) {
dldiLoadFromBin(nrio_dldi);
dldiLoadFromLzss(nrio_lz77, 0x30DD);
fatMountSimple("fat", dldiGet());
} /* else if (!memcmp(gameid, "ALXX", 4)) { // SuperCard DSTWO
dldiLoadFromBin(dstwo_dldi);
Expand Down
2 changes: 1 addition & 1 deletion arm9/source/dumpOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "fileOperations.h"
#include "font.h"
#include "gba.h"
#include "lzss.h"
#include "lzss_enc.h"
#include "main.h"
#include "ndsheaderbanner.h"
#include "read_card.h"
Expand Down
Loading

0 comments on commit 9c243aa

Please sign in to comment.