Compress internal SRL binaries...

* Compressed internal SRL binaries for built in
stage2/udisk/nrio-usb-disk. This saves space in the main NDS file and
managed to get main NDS file below 1MB.
* uDisk updator arm9 BIN files updated to flash 8 0x20000 blocks instead
of 9 now that xulumenu is small enough to fit in 8.
* tonccpy moved to ITCM.
* nrio_detect moved to ITCM.
* Moved ram location second bootloader uses as tmp memory to load built
in SRL binaries. Was 0x02200000 but now is 0x02300000. This is to make
room for buffer needed for decompression function.
This commit is contained in:
ApacheThunder 2024-11-16 22:49:32 -06:00
parent 94c962ec60
commit 66f91bb555
21 changed files with 95 additions and 30 deletions

Binary file not shown.

View File

@ -1,3 +1,5 @@
@Echo off
ndstool -c autorun1_bootleg.nds -9 arm9_bootleg.bin -7 arm7.bin -t banner_bootleg.bin -h header.bin -d NitroFS_Bootleg
ndstool -c autorun2_bootleg.nds -9 arm9_bootleg.bin -7 arm7.bin -t banner_bootleg.bin -h header.bin -d NitroFS_Bootleg
ndstool -c autorun3_bootleg.nds -9 arm9_bootleg.bin -7 arm7.bin -t banner_bootleg.bin -h header.bin -d NitroFS_Bootleg
pause

View File

@ -1,3 +1,5 @@
@Echo off
ndstool -c autorun1.nds -9 arm9.bin -7 arm7.bin -t banner.bin -h header.bin -d NitroFS
ndstool -c autorun2.nds -9 arm9.bin -7 arm7.bin -t banner.bin -h header.bin -d NitroFS
ndstool -c autorun3.nds -9 arm9.bin -7 arm7.bin -t banner.bin -h header.bin -d NitroFS
pause

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,20 +0,0 @@
#ifndef BINARIES_H
#define BINARIES_H
#ifdef __cplusplus
extern "C" {
#endif
extern void udiskData();
extern void udiskData_end();
extern void stage2Data();
extern void stage2Data_end();
extern void nriousbData();
extern void nriousbData_end();
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,16 +1,15 @@
.arm
.global udiskData, udiskData_end, stage2Data, stage2Data_end, nriousbData, nriousbData_end
.global udiskData, stage2Data, nriousbData
.align 16
udiskData:
.incbin "../binaries/udisk.srl"
udiskData_end:
.align 16
stage2Data:
.incbin "../binaries/stage2.srl"
stage2Data_end:
.align 16
nriousbData:
.incbin "../binaries/nriousb.srl"
nriousbData_end:

32
arm9/source/lzss.c Normal file
View File

@ -0,0 +1,32 @@
#include "lzss.h"
#include <string.h>
#define __itcm __attribute__((section(".itcm")))
void __itcm
LZ77_Decompress(u8* source, u8* destination){
u32 leng = (source[1] | (source[2] << 8) | (source[3] << 16));
int Offs = 4;
int dstoffs = 0;
while (true) {
u8 header = source[Offs++];
for (int i = 0; i < 8; i++) {
if ((header & 0x80) == 0) destination[dstoffs++] = source[Offs++];
else
{
u8 a = source[Offs++];
u8 b = source[Offs++];
int offs = (((a & 0xF) << 8) | b) + 1;
int length = (a >> 4) + 3;
for (int j = 0; j < length; j++) {
destination[dstoffs] = destination[dstoffs - offs];
dstoffs++;
}
}
if (dstoffs >= (int)leng) return;
header <<= 1;
}
}
}

15
arm9/source/lzss.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef LZ77_DECOMPRESS_H
#define LZ77_DECOMPRESS_H
#include <nds/ndstypes.h>
#ifdef __cplusplus
extern "C" {
#endif
void LZ77_Decompress(u8* source, u8* destination);
#ifdef __cplusplus
}
#endif
#endif /* DECOMPRESS_H */

View File

@ -29,7 +29,7 @@
#include "load_bin.h"
#include "udiskloader_bin.h"
#include "binaries.h"
#include "lzss.h"
#include "tonccpy.h"
#ifndef _NO_BOOTSTUB_
@ -39,7 +39,7 @@
#include "nds_loader_arm9.h"
#define TMP_DATA 0x02200000
#define TMP_DATA 0x02300000
#define LCDC_BANK_D (u16*)0x06860000
#define STORED_FILE_CLUSTER (*(((u32*)LCDC_BANK_D) + 1))
@ -223,13 +223,30 @@ static bool dldiPatchLoader (data_t *binData, u32 binSize, bool clearBSS) {
return true;
}
#define nriousbData_size 0x1D6B8
#define stage2Data_size 0x14600
#define udiskData_size 0x91810
#define nriousbData_lz_size 0x13CE9
#define stage2Data_lz_size 0xBD06
#define udiskData_lz_size 0x69BA6
ALIGN(16) extern unsigned char nriousbData[nriousbData_lz_size];
ALIGN(16) extern unsigned char stage2Data[stage2Data_lz_size];
ALIGN(16) extern unsigned char udiskData[udiskData_lz_size];
ALIGN(16) volatile u8* buffer;
int runSRLbinary(int srlType) {
switch (srlType) {
/*switch (srlType) {
case 1: tonccpy((void*)TMP_DATA, (void*)stage2Data, (stage2Data_end - stage2Data)); break;
case 2: tonccpy((void*)TMP_DATA, (void*)nriousbData, (nriousbData_end - nriousbData)); break;
default: tonccpy((void*)TMP_DATA, (void*)udiskData, (udiskData_end - udiskData)); break;
}
}*/
/*switch (srlType) {
case 1: decompress((u8*)stage2Data, (u8*)TMP_DATA, LZ77Vram); break;
@ -237,6 +254,24 @@ int runSRLbinary(int srlType) {
default: decompress((u8*)udiskData, (u8*)TMP_DATA, LZ77Vram); break;
}*/
switch (srlType) {
case 1: {
buffer = malloc(stage2Data_size);
LZ77_Decompress((u8*)stage2Data, (u8*)buffer);
tonccpy((void*)TMP_DATA, (void*)buffer, stage2Data_size);
} break;
case 2: {
buffer = malloc(nriousbData_size);
LZ77_Decompress((u8*)nriousbData, (u8*)buffer);
tonccpy((void*)TMP_DATA, (void*)buffer, nriousbData_size);
} break;
default: {
buffer = malloc(udiskData_size);
LZ77_Decompress((u8*)udiskData, (u8*)buffer);
tonccpy((void*)TMP_DATA, (void*)buffer, udiskData_size);
} break;
}
// Start Bootloader
irqDisable(IRQ_ALL);
// Direct CPU access to VRAM bank D

View File

@ -47,7 +47,7 @@
#include "tonccpy.h"
#define TMP_DATA 0x02200000
#define TMP_DATA 0x02300000
extern void arm7_clearmem (void* loc, size_t len);
extern void arm7_reset (void);