Skip to content

Commit 2de58ee

Browse files
committed
Clean up ZQ errors, add fonts.dat size error message
1 parent 60efdd5 commit 2de58ee

File tree

7 files changed

+74
-235
lines changed

7 files changed

+74
-235
lines changed

src/base/zdefs.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,3 +2092,17 @@ const int BUILDTM_SECOND = (
20922092
(__TIME__[7]-'0'));
20932093

20942094

2095+
size_t datcnt = 0;
2096+
void dat_callback(DATAFILE*)
2097+
{
2098+
++datcnt;
2099+
}
2100+
DATAFILE* load_datafile_count(const char* path, size_t& sz)
2101+
{
2102+
datcnt = 0;
2103+
DATAFILE* ret = load_datafile_callback(path,dat_callback);
2104+
if(ret)
2105+
sz = datcnt-1;
2106+
else sz = 0;
2107+
return ret;
2108+
}

src/base/zdefs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5696,6 +5696,10 @@ bool isDamageType(int32_t type);
56965696
bool isConveyorType(int32_t type);
56975697
bool isChestType(int32_t type);
56985698

5699+
DATAFILE* load_datafile_count(const char* path, size_t& sz);
5700+
5701+
#define FONTSDAT_CNT (FONT_ZX+1)
5702+
56995703
#define SMART_WRAP(x, mod) ((x) < 0 ? (((mod)-(-(x)%(mod)))%(mod)) : ((x)%(mod)))
57005704
#define MEMCPY_ARR(dest,src) memcpy(dest,src,sizeof(dest))
57015705

src/launcher/launcher.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "dialog/alert.h"
88
#include "launcher_dialog.h"
99
#include "base/zapp.h"
10+
#include "fontsdat.h"
1011

1112
#define QUICK_EXIT 0
1213

@@ -18,6 +19,7 @@ do{ \
1819
while(false)
1920

2021
DATAFILE *fontsdata;
22+
size_t fontsdat_cnt = 0;
2123
PALETTE RAMpal;
2224

2325
ZModule zcm;
@@ -152,7 +154,7 @@ int32_t main(int32_t argc, char* argv[])
152154
packfile_password(datapwd);
153155

154156
Z_message("....Fonts.Dat..."); //{
155-
if((fontsdata=load_datafile(moduledata.datafiles[fonts_dat]))==NULL)
157+
if((fontsdata=load_datafile_count(moduledata.datafiles[fonts_dat], fontsdat_cnt))==NULL)
156158
{
157159
Z_error_fatal("failed: load error\n");
158160
QUIT_LAUNCHER();
@@ -164,6 +166,11 @@ int32_t main(int32_t argc, char* argv[])
164166
Z_error_fatal("failed: version error\n");
165167
QUIT_LAUNCHER();
166168
}
169+
if(fontsdat_cnt != FONTSDAT_CNT)
170+
{
171+
Z_error_fatal("failed: count error (found %d != exp %d)\n", fontsdat_cnt, FONTSDAT_CNT);
172+
QUIT_LAUNCHER();
173+
}
167174
Z_message("OK\n");
168175
//} end Fonts.Dat...OK
169176
packfile_password("");

src/zc/zelda.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ BITMAP *framebuf, *menu_bmp, *gui_bmp, *scrollbuf, *tmp_bmp, *tmp_scr, *scre
335335
*script_menu_buf, *f6_menu_buf;
336336
BITMAP *zcmouse[NUM_ZCMOUSE];
337337
DATAFILE *datafile, *sfxdata, *fontsdata, *mididata;
338+
size_t fontsdat_cnt = 0;
338339
PALETTE RAMpal;
339340
byte *colordata, *trashbuf;
340341
//byte *tilebuf;
@@ -4810,11 +4811,16 @@ int main(int argc, char **argv)
48104811

48114812
Z_message("Fonts.Dat...");
48124813

4813-
if((fontsdata=load_datafile(moduledata.datafiles[fonts_dat]))==NULL)
4814+
if((fontsdata=load_datafile_count(moduledata.datafiles[fonts_dat], fontsdat_cnt))==NULL)
48144815
{
48154816
Z_error_fatal("failed");
48164817
quit_game();
48174818
}
4819+
if(fontsdat_cnt != FONTSDAT_CNT)
4820+
{
4821+
Z_error_fatal("failed: count error (found %d != exp %d)\n", fontsdat_cnt, FONTSDAT_CNT);
4822+
quit_game();
4823+
}
48184824

48194825
if(strncmp((char*)fontsdata[0].dat,fontsdat_sig,24))
48204826
{

src/zc/zelda.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ extern bool lightbeam_present;
315315
#define NUM_ZCMOUSE 1
316316
extern BITMAP *zcmouse[NUM_ZCMOUSE];
317317
extern DATAFILE *datafile, *sfxdata, *fontsdata, *mididata;
318+
extern size_t fontsdat_cnt;
318319
extern SAMPLE wav_refill;
319320
extern PALETTE RAMpal;
320321
extern byte *colordata;

0 commit comments

Comments
 (0)