Skip to content
This repository was archived by the owner on Dec 24, 2018. It is now read-only.

Commit 518ba74

Browse files
committed
Add Games menu now works again, and now caches banners at correct size
1 parent c23412e commit 518ba74

File tree

10 files changed

+177
-101
lines changed

10 files changed

+177
-101
lines changed

flashcard-side/arm7/source/main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ int main() {
5454
//---------------------------------------------------------------------------------
5555
nocashMessage("ARM7 main.c main");
5656

57-
REG_SCFG_ROM = 0x703;
58-
REG_SCFG_CLK = 0x0187;
57+
//REG_SCFG_ROM = 0x703;
58+
//REG_SCFG_CLK = 0x0187;
5959
// REG_SCFG_EXT = 0x93A40000;
6060

6161
// SCFG_CLK
@@ -65,7 +65,7 @@ int main() {
6565
// REG_SCFG_CLK = 0x0181;
6666

6767
readUserSettings();
68-
ledBlink(0);
68+
//ledBlink(0);
6969

7070
irqInit();
7171
// Start the RTC tracking IRQ
@@ -80,7 +80,7 @@ int main() {
8080
irqSet(IRQ_VCOUNT, VcountHandler);
8181
irqSet(IRQ_VBLANK, VblankHandler);
8282

83-
irqEnable( IRQ_VBLANK | IRQ_VCOUNT | IRQ_NETWORK);
83+
irqEnable( IRQ_VBLANK | IRQ_VCOUNT );
8484

8585
setPowerButtonCB(powerButtonCB);
8686

flashcard-side/arm9/source/iconTitle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void iconTitleInit (void) {
129129

130130
// everything's ready :)
131131
writeRow (0,"...initializing...");
132-
writeRow (1,"===>>> HBMenu+ <<<===");
132+
writeRow (1,"===>>> Add Games <<<===");
133133
writeRow (2,"(this text should disappear...");
134134
writeRow (3,"...otherwise, trouble!)");
135135
}

flashcard-side/arm9/source/log.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <stdio.h>
22
#include "log.h"
33

4-
bool LogCreated = true; // It's already done by the GUI
4+
bool LogCreated = false;
55

66
int createLog(void) {
77
if (!LogCreated){

flashcard-side/arm9/source/main.cpp

Lines changed: 61 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
#include "inifile.h"
4343
#include "log.h"
4444

45+
sNDSHeaderExt ndsHeader;
46+
sNDSBannerExt ndsBanner;
47+
4548
using namespace std;
4649

4750
bool logEnabled = false;
@@ -126,38 +129,52 @@ void RemoveTrailingSlashes(string& path)
126129
}
127130
}
128131

129-
130132
//---------------------------------------------------------------------------------
131133
int main(int argc, char **argv) {
132134
//---------------------------------------------------------------------------------
133-
// REG_SCFG_CLK = 0x80;
134-
REG_SCFG_CLK = 0x85;
135-
136135
bool TriggerExit = false;
137136
std::string fcromfolder;
138137
char fcfolder_path[256];
139138

139+
iconTitleInit();
140+
141+
// Subscreen as a console
142+
videoSetModeSub(MODE_0_2D);
143+
vramSetBankH(VRAM_H_SUB_BG);
144+
consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true);
145+
140146
/* Log file is dissabled by default. If _nds/twloader/log exist, we turn log file on, else, log is dissabled */
141-
struct stat logBuf;
142-
logEnabled = stat("sd:/_nds/twloader/log", &logBuf) == 0;
147+
//struct stat logBuf;
148+
//logEnabled = stat("sd:/_nds/twloader/log", &logBuf) == 0;
143149
/* Log configuration file end */
144150

145-
if (fatInitDefault()) {
151+
if(fatInitDefault()) {
152+
printf ("Reading TWLoader settings\n");
146153
CIniFile twloaderini( "sd:/_nds/twloader/settings.ini" );
147-
if (logEnabled) LogFM("Flashcard.Main", "Fat inited");
154+
printf ("TWLoader settings read\n");
155+
// if (logEnabled) LogFM("Flashcard.Main", "Fat inited");
148156

149157
// overwrite reboot stub identifier
150158
// extern u64 *fake_heap_end;
151159
// *fake_heap_end = 0;
152160

153161
// defaultExceptionHandler();
154-
162+
163+
printf ("Reading flashcard ini folder\n");
155164
fcromfolder = twloaderini.GetString( "FRONTEND", "FCROM_FOLDER", "");
165+
printf ("Removing trailing slashes\n");
156166
RemoveTrailingSlashes(fcromfolder);
167+
printf ("Done!\n");
157168
if (fcromfolder.empty()) {
158169
fcromfolder = "roms/flashcard/nds";
159170
}
160171
snprintf(fcfolder_path, sizeof(fcfolder_path), "sd:/%s", fcromfolder.c_str());
172+
} else {
173+
iprintf ("fatInitDefault failed!\n");
174+
175+
doPause();
176+
177+
TriggerExit = true;
161178
}
162179

163180
int pathLen;
@@ -167,21 +184,6 @@ int main(int argc, char **argv) {
167184
char inifilepath[256];
168185
std::string inifilepathfixed;
169186

170-
iconTitleInit();
171-
172-
// Subscreen as a console
173-
videoSetModeSub(MODE_0_2D);
174-
vramSetBankH(VRAM_H_SUB_BG);
175-
consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true);
176-
177-
if (!fatInitDefault()) {
178-
iprintf ("fatinitDefault failed!\n");
179-
180-
doPause();
181-
182-
TriggerExit = true;
183-
}
184-
185187
chdir ("fat:/"); // Change directory to flashcard root
186188

187189
keysSetRepeat(25,5);
@@ -217,50 +219,55 @@ int main(int argc, char **argv) {
217219
iprintf (filePath);
218220
iprintf (" \n");
219221

220-
TWLDsNDSHeader NDSHeader;
221-
222-
if (logEnabled) LogFMA("Flashcard.Main", "Reading .NDS file:", filePath);
222+
// if (logEnabled) LogFMA("Flashcard.Main", "Reading .NDS file:", filePath);
223223
fseek ( ndsFile , 0 , SEEK_SET );
224-
fread(&NDSHeader,1,sizeof(NDSHeader),ndsFile);
225-
if (logEnabled) LogFMA("Flashcard.Main", ".NDS file read:", filePath);
224+
fread(&ndsHeader,1,sizeof(ndsHeader),ndsFile);
225+
// if (logEnabled) LogFMA("Flashcard.Main", ".NDS file read:", filePath);
226226

227227
// Set banner path
228-
free(bannerfilepath);
229228
snprintf(bannerfilepath, sizeof(bannerfilepath), "sd:/_nds/twloader/bnricons/flashcard/%s.bin", filename.c_str());
230229
bannerfilepathfixed = ReplaceAll(bannerfilepath, ".nds", ".ini");
231230

232231
// Set .ini path
233-
free(inifilepath);
234232
snprintf(inifilepath, sizeof(inifilepath), "%s/%s", fcfolder_path, filename.c_str());
235233
inifilepathfixed = ReplaceAll(inifilepath, ".nds", ".ini");
236234

237235
if( access( bannerfilepathfixed.c_str(), F_OK ) == -1 ) {
238236
FILE* filetosave = fopen(bannerfilepathfixed.c_str(), "wb");
239-
240-
TWLDsNDSBannersize1 myBannersize1;
241-
TWLDsNDSBannersize2 myBannersize2;
242-
TWLDsNDSBannersize3 myBannersize3;
243-
TWLDsNDSBannersize4 myBanner;
244-
245-
if (NDSHeader.bannerOffset != 0x00000000) {
246-
fseek ( ndsFile , NDSHeader.bannerOffset , SEEK_SET );
247-
248-
fread(&myBanner,1,sizeof(myBanner),ndsFile);
249-
237+
238+
if (ndsHeader.bannerOffset != 0x00000000) {
239+
int ret;
240+
241+
ret = fseek (ndsFile, ndsHeader.bannerOffset, SEEK_SET);
242+
if (ret == 0)
243+
ret = fread(&ndsBanner, 1, sizeof(ndsBanner), ndsFile); // read if seek succeed
244+
else
245+
ret = 0; // if seek fails set to !=1
246+
247+
if (ret != 1)
248+
{
249+
// try again, but using regular banner size
250+
ret = fseek (ndsFile, ndsHeader.bannerOffset, SEEK_SET);
251+
if (ret == 0)
252+
ret = fread(&ndsBanner, NDS_BANNER_SIZE_ORIGINAL, 1, ndsFile); // read if seek succeed
253+
else
254+
ret = 0; // if seek fails set to !=1
255+
}
256+
250257
iprintf ("Now caching banner data.\n");
251-
if (logEnabled) LogFMA("Flashcard.Main", "Caching banner data:", NDSHeader.gameCode);
252-
if (myBanner.version == 0x0103) {
253-
fwrite(&myBanner,1,sizeof(myBanner),filetosave);
254-
} else if (myBanner.version == 0x0003) {
255-
fwrite(&myBanner,1,sizeof(myBannersize3),filetosave);
256-
} else if (myBanner.version == 0x0002) {
257-
fwrite(&myBanner,1,sizeof(myBannersize2),filetosave);
258+
// if (logEnabled) LogFMA("Flashcard.Main", "Caching banner data:", NDSHeader.gameCode);
259+
if (ndsBanner.version == 0x0103) {
260+
fwrite(&ndsBanner,1,NDS_BANNER_SIZE_DSi,filetosave);
261+
} else if (ndsBanner.version == 0x0003) {
262+
fwrite(&ndsBanner,1,NDS_BANNER_SIZE_ZH_KO,filetosave);
263+
} else if (ndsBanner.version == 0x0002) {
264+
fwrite(&ndsBanner,1,NDS_BANNER_SIZE_ZH,filetosave);
258265
} else {
259-
fwrite(&myBanner,1,sizeof(myBannersize1),filetosave);
266+
fwrite(&ndsBanner,1,NDS_BANNER_SIZE_ORIGINAL,filetosave);
260267
}
261268

262-
if (logEnabled) iprintf ("Banner data cached.\n");
263-
if (logEnabled) LogFMA("Flashcard.Main", "Banner data cached:", NDSHeader.gameCode);
269+
// if (logEnabled) iprintf ("Banner data cached.\n");
270+
// if (logEnabled) LogFMA("Flashcard.Main", "Banner data cached:", NDSHeader.gameCode);
264271
for (int i = 0; i < 60; i++) { swiWaitForVBlank(); }
265272
} else {
266273
iprintf ("Banner data doesn't exist.\n");
@@ -275,9 +282,9 @@ int main(int argc, char **argv) {
275282
if( access( inifilepathfixed.c_str(), F_OK ) == -1 ) {
276283
CIniFile rominini( inifilepathfixed );
277284
rominini.SetString("FLASHCARD-ROM", "NDS_PATH", filePath+5);
278-
rominini.SetString("FLASHCARD-ROM", "TID", NDSHeader.gameCode);
285+
rominini.SetString("FLASHCARD-ROM", "TID", ndsHeader.gameCode);
279286
iprintf (".ini file created.\n");
280-
if (logEnabled) LogFMA("Flashcard.Main", ".ini file created:", NDSHeader.gameCode);
287+
// if (logEnabled) LogFMA("Flashcard.Main", ".ini file created:", NDSHeader.gameCode);
281288
rominini.SaveIniFile( inifilepathfixed );
282289
for (int i = 0; i < 60; i++) { swiWaitForVBlank(); }
283290
} else {

flashcard-side/arm9/source/ndsheaderbanner.h

Lines changed: 93 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,46 @@
3232
#ifndef NDS_HEADER2
3333
#define NDS_HEADER2
3434

35+
#include <nds.h>
36+
37+
typedef struct
38+
{
39+
u32 auto_load_list_offset;
40+
u32 auto_load_list_end;
41+
u32 auto_load_start;
42+
u32 static_bss_start;
43+
u32 static_bss_end;
44+
u32 compressed_static_end;
45+
u32 sdk_version;
46+
u32 nitro_code_be;
47+
u32 nitro_code_le;
48+
} module_params_t;
49+
3550
/*!
36-
\brief the NDS banner format.
37-
See gbatek for more information.
51+
\brief the GBA file header format.
52+
See gbatek for more info.
53+
*/
54+
typedef struct {
55+
u32 entryPoint; //!< 32 bits arm opcode to jump to executable code.
56+
u8 logo[156]; //!< nintendo logo needed for booting the game.
57+
char title[0xC]; //!< 12 characters for the game title.
58+
char gamecode[0x4]; //!< 4 characters for the game code. first character is usally A or B, next 2 characters is a short title
59+
//!< and last character is for destination/language.
60+
u16 makercode; //!< identifies the (commercial) developer.
61+
u8 is96h; //!< fixed value that is always 96h.
62+
u8 unitcode; //!< identifies the required hardware.
63+
u8 devicecode; //!< used by nintedo's hardware debuggers. normally 0.
64+
u8 unused[7];
65+
u8 version; //!< the version of the game.
66+
u8 complement; //!< complement checksum of the gba header.
67+
u16 checksum; //!< a 16 bit checksum? (gbatek says its unused/reserved).
68+
} sGBAHeader2;
69+
70+
//#define GBA_HEADER (*(tGBAHeader *)0x08000000)
71+
72+
/*!
73+
\brief the NDS file header format
74+
See gbatek for more info.
3875
*/
3976
typedef struct {
4077
char gameTitle[12]; //!< 12 characters for the game title.
@@ -94,43 +131,25 @@ typedef struct {
94131
u32 offset_0x16C; //reserved?
95132

96133
u8 zero[0x90];
97-
} TWLDsNDSHeader;
98134

99-
typedef struct {
100-
u16 version; //!< version of the banner.
101-
u16 crc[4]; //!< CRC-16s of the banner.
102-
u8 reserved[22];
103-
u8 icon[512]; //!< 32*32 icon of the game with 4 bit per pixel.
104-
u16 palette[16]; //!< the pallete of the icon.
105-
u16 titles[8][128]; //!< title of the game in 8 different languages.
106-
} TWLDsNDSBanner;
135+
// 0x200
136+
// TODO: More DSi-specific fields.
137+
u8 dsi1[0x30];
138+
u32 dsi_tid;
139+
u8 dsi2[0x180];
140+
} sNDSHeaderExt;
107141

108142
typedef struct {
109-
u16 version; //!< version of the banner.
110-
u16 crc[4]; //!< CRC-16s of the banner.
111-
u8 reserved[22];
112-
u8 icon[512]; //!< 32*32 icon of the game with 4 bit per pixel.
113-
u16 palette[16]; //!< the palette of the icon.
114-
u16 titles[6][128]; //!< title of the game in 6 different languages.
115-
} TWLDsNDSBannersize1;
143+
char gameTitle[12]; //!< 12 characters for the game title.
144+
char gameCode[4]; //!< 4 characters for the game code.
145+
} sNDSHeadertitlecodeonly;
116146

117-
typedef struct {
118-
u16 version; //!< version of the banner.
119-
u16 crc[4]; //!< CRC-16s of the banner.
120-
u8 reserved[22];
121-
u8 icon[512]; //!< 32*32 icon of the game with 4 bit per pixel.
122-
u16 palette[16]; //!< the palette of the icon.
123-
u16 titles[7][128]; //!< title of the game in 7 different languages.
124-
} TWLDsNDSBannersize2;
125147

126-
typedef struct {
127-
u16 version; //!< version of the banner.
128-
u16 crc[4]; //!< CRC-16s of the banner.
129-
u8 reserved[22];
130-
u8 icon[512]; //!< 32*32 icon of the game with 4 bit per pixel.
131-
u16 palette[16]; //!< the palette of the icon.
132-
u16 titles[8][128]; //!< title of the game in 8 different languages.
133-
} TWLDsNDSBannersize3;
148+
//#define __NDSHeader ((tNDSHeader *)0x02FFFE00)
149+
150+
// Make sure the banner size is correct.
151+
static_assert(sizeof(sNDSHeaderExt) == 0x3B4, "sizeof(sNDSHeaderExt) is not 0x3B4 bytes");
152+
134153

135154
/*!
136155
\brief the NDS banner format.
@@ -151,7 +170,45 @@ typedef struct {
151170
u8 dsi_icon[8][512]; //!< DSi animated icon frame data.
152171
u16 dsi_palette[8][16]; //!< Palette for each DSi icon frame.
153172
u16 dsi_seq[64]; //!< DSi animated icon sequence.
154-
} TWLDsNDSBannersize4;
155-
173+
} sNDSBannerExt;
174+
175+
// sNDSBanner version.
176+
typedef enum {
177+
NDS_BANNER_VER_ORIGINAL = 0x0001,
178+
NDS_BANNER_VER_ZH = 0x0002,
179+
NDS_BANNER_VER_ZH_KO = 0x0003,
180+
NDS_BANNER_VER_DSi = 0x0103,
181+
} sNDSBannerVersion;
182+
183+
// sNDSBanner sizes.
184+
typedef enum {
185+
NDS_BANNER_SIZE_ORIGINAL = 0x0840,
186+
NDS_BANNER_SIZE_ZH = 0x0940,
187+
NDS_BANNER_SIZE_ZH_KO = 0x0A40,
188+
NDS_BANNER_SIZE_DSi = 0x23C0,
189+
} sNDSBannerSize;
190+
191+
// Make sure the banner size is correct.
192+
static_assert(sizeof(sNDSBannerExt) == NDS_BANNER_SIZE_DSi, "sizeof(sNDSBannerExt) is not 0x23C0 bytes");
193+
194+
// Language indexes.
195+
typedef enum {
196+
// DS and 3DS
197+
NDS_LANG_JAPANESE = 0,
198+
NDS_LANG_ENGLISH = 1,
199+
NDS_LANG_FRENCH = 2,
200+
NDS_LANG_GERMAN = 3,
201+
NDS_LANG_ITALIAN = 4,
202+
NDS_LANG_SPANISH = 5,
203+
NDS_LANG_CHINESE = 6,
204+
NDS_LANG_KOREAN = 7,
205+
206+
// 3DS only
207+
N3DS_LANG_CHINESE_SIMPLIFIED = 6,
208+
N3DS_LANG_DUTCH = 8,
209+
N3DS_LANG_PORTUGUESE = 9,
210+
N3DS_LANG_RUSSIAN = 10,
211+
N3DS_LANG_CHINESE_TRADITIONAL = 11,
212+
} sNDSLanguage;
156213

157214
#endif // NDS_HEADER2

flashcard-side/clean and compile.bat

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@echo off
2+
make clean
3+
make
4+
copy "flashcard-side.nds" "../7zfile/flashcardsdroot (all)/_nds/twloader.nds"
5+
copy "flashcard-side.nds" "../TWLoader-update/twloader.nds"
6+
pause

0 commit comments

Comments
 (0)