42
42
#include " inifile.h"
43
43
#include " log.h"
44
44
45
+ sNDSHeaderExt ndsHeader;
46
+ sNDSBannerExt ndsBanner;
47
+
45
48
using namespace std ;
46
49
47
50
bool logEnabled = false ;
@@ -126,38 +129,52 @@ void RemoveTrailingSlashes(string& path)
126
129
}
127
130
}
128
131
129
-
130
132
// ---------------------------------------------------------------------------------
131
133
int main (int argc, char **argv) {
132
134
// ---------------------------------------------------------------------------------
133
- // REG_SCFG_CLK = 0x80;
134
- REG_SCFG_CLK = 0x85 ;
135
-
136
135
bool TriggerExit = false ;
137
136
std::string fcromfolder;
138
137
char fcfolder_path[256 ];
139
138
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
+
140
146
/* 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;
143
149
/* Log configuration file end */
144
150
145
- if (fatInitDefault ()) {
151
+ if (fatInitDefault ()) {
152
+ printf (" Reading TWLoader settings\n " );
146
153
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");
148
156
149
157
// overwrite reboot stub identifier
150
158
// extern u64 *fake_heap_end;
151
159
// *fake_heap_end = 0;
152
160
153
161
// defaultExceptionHandler();
154
-
162
+
163
+ printf (" Reading flashcard ini folder\n " );
155
164
fcromfolder = twloaderini.GetString ( " FRONTEND" , " FCROM_FOLDER" , " " );
165
+ printf (" Removing trailing slashes\n " );
156
166
RemoveTrailingSlashes (fcromfolder);
167
+ printf (" Done!\n " );
157
168
if (fcromfolder.empty ()) {
158
169
fcromfolder = " roms/flashcard/nds" ;
159
170
}
160
171
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 ;
161
178
}
162
179
163
180
int pathLen;
@@ -167,21 +184,6 @@ int main(int argc, char **argv) {
167
184
char inifilepath[256 ];
168
185
std::string inifilepathfixed;
169
186
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
-
185
187
chdir (" fat:/" ); // Change directory to flashcard root
186
188
187
189
keysSetRepeat (25 ,5 );
@@ -217,50 +219,55 @@ int main(int argc, char **argv) {
217
219
iprintf (filePath);
218
220
iprintf (" \n " );
219
221
220
- TWLDsNDSHeader NDSHeader;
221
-
222
- if (logEnabled) LogFMA (" Flashcard.Main" , " Reading .NDS file:" , filePath);
222
+ // if (logEnabled) LogFMA("Flashcard.Main", "Reading .NDS file:", filePath);
223
223
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);
226
226
227
227
// Set banner path
228
- free (bannerfilepath);
229
228
snprintf (bannerfilepath, sizeof (bannerfilepath), " sd:/_nds/twloader/bnricons/flashcard/%s.bin" , filename.c_str ());
230
229
bannerfilepathfixed = ReplaceAll (bannerfilepath, " .nds" , " .ini" );
231
230
232
231
// Set .ini path
233
- free (inifilepath);
234
232
snprintf (inifilepath, sizeof (inifilepath), " %s/%s" , fcfolder_path, filename.c_str ());
235
233
inifilepathfixed = ReplaceAll (inifilepath, " .nds" , " .ini" );
236
234
237
235
if ( access ( bannerfilepathfixed.c_str (), F_OK ) == -1 ) {
238
236
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
+
250
257
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);
258
265
} else {
259
- fwrite (&myBanner ,1 ,sizeof (myBannersize1) ,filetosave);
266
+ fwrite (&ndsBanner ,1 ,NDS_BANNER_SIZE_ORIGINAL ,filetosave);
260
267
}
261
268
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);
264
271
for (int i = 0 ; i < 60 ; i++) { swiWaitForVBlank (); }
265
272
} else {
266
273
iprintf (" Banner data doesn't exist.\n " );
@@ -275,9 +282,9 @@ int main(int argc, char **argv) {
275
282
if ( access ( inifilepathfixed.c_str (), F_OK ) == -1 ) {
276
283
CIniFile rominini ( inifilepathfixed );
277
284
rominini.SetString (" FLASHCARD-ROM" , " NDS_PATH" , filePath+5 );
278
- rominini.SetString (" FLASHCARD-ROM" , " TID" , NDSHeader .gameCode );
285
+ rominini.SetString (" FLASHCARD-ROM" , " TID" , ndsHeader .gameCode );
279
286
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);
281
288
rominini.SaveIniFile ( inifilepathfixed );
282
289
for (int i = 0 ; i < 60 ; i++) { swiWaitForVBlank (); }
283
290
} else {
0 commit comments