-
-
Notifications
You must be signed in to change notification settings - Fork 78
/
zc_sys.cpp
9687 lines (8434 loc) · 252 KB
/
zc_sys.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "zc/zc_sys.h"
#include "allegro/gfx.h"
#include "allegro5/joystick.h"
#include "base/qrs.h"
#include "base/dmap.h"
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <map>
#include <filesystem>
#include <ctype.h>
#include <sstream>
#include "base/zc_alleg.h"
#include "gamedata.h"
#include "zc/zc_init.h"
#include "init.h"
#include "zc/replay.h"
#include "zc/cheats.h"
#include "zc/render.h"
#include "base/zc_math.h"
#include "base/zapp.h"
#include "dialog/cheatkeys.h"
#include "metadata/metadata.h"
#include "zc/zelda.h"
#include "zc/saves.h"
#include "tiles.h"
#include "base/colors.h"
#include "pal.h"
#include "base/zsys.h"
#include "qst.h"
#include "zc/zc_sys.h"
#include "play_midi.h"
#include "jwin_a5.h"
#include "base/jwinfsel.h"
#include "base/gui.h"
#include "midi.h"
#include "subscr.h"
#include "zc/maps.h"
#include "sprite.h"
#include "zc/guys.h"
#include "zc/hero.h"
#include "zc/title.h"
#include "particles.h"
#include "zcmusic.h"
#include "zconsole.h"
#include "zc/ffscript.h"
#include "dialog/info.h"
#include "dialog/alert.h"
#include "zc/combos.h"
#include "zc/jit.h"
#include "zc/zc_subscr.h"
#include <fmt/format.h>
#include "zinfo.h"
#include "base/misctypes.h"
#ifdef __EMSCRIPTEN__
#include "base/emscripten_utils.h"
#endif
using namespace std::chrono_literals;
extern FFScript FFCore;
extern bool Playing;
int32_t sfx_voice[WAV_COUNT];
int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c);
int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c);
static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c);
extern byte monochrome_console;
extern HeroClass Hero;
extern ZModule zcm;
extern zcmodule moduledata;
extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations;
extern particle_list particles;
extern int32_t loadlast;
extern char *sfx_string[WAV_COUNT];
byte use_dwm_flush;
byte use_save_indicator;
int32_t paused_midi_pos = 0;
byte midi_suspended = 0;
byte zc_192b163_warp_compatibility;
char modulepath[2048];
bool epilepsyFlashReduction;
signed char pause_in_background_menu_init = 0;
byte pause_in_background = 0;
bool is_sys_pal = false;
static bool load_control_called_this_frame;
extern PALETTE* hw_palette;
extern bool update_hw_pal;
extern const char* dmaplist(int32_t index, int32_t* list_size);
int32_t getnumber(const char *prompt,int32_t initialval);
extern bool kb_typing_mode; //script only, for disbaling key presses affecting Hero, etc.
extern int32_t cheat_modifier_keys[4]; //two options each, default either control and either shift
//extern byte refresh_select_screen;
//extern movingblock mblock2; //mblock[4]?
//extern int32_t db;
static const char *ZC_str = "ZQuest Classic";
#if defined(ALLEGRO_WINDOWS)
const char *qst_dir_name = "win_qst_dir";
static const char *qst_module_name = "current_module";
#elif defined(ALLEGRO_LINUX)
const char *qst_dir_name = "linux_qst_dir";
static const char *qst_module_name = "current_module";
#elif defined(__APPLE__)
const char *qst_dir_name = "osx_qst_dir";
static const char *qst_module_name = "current_module";
#endif
#ifdef ALLEGRO_LINUX
static const char *samplepath = "samplesoundset/patches.dat";
#endif
char qst_files_path[2048];
#ifdef _MSC_VER
#define getcwd _getcwd
#endif
bool rF11();
bool rI();
bool rQ();
bool zc_key_pressed();
#ifdef _WIN32
// This should only be necessary for MinGW, since it doesn't have a dwmapi.h. Add another #ifdef if you like.
extern "C"
{
typedef HRESULT(WINAPI *t_DwmFlush)();
typedef HRESULT(WINAPI *t_DwmIsCompositionEnabled)(BOOL *pfEnabled);
}
void do_DwmFlush()
{
static HMODULE shell = LoadLibrary("dwmapi.dll");
if(!shell)
return;
static t_DwmFlush flush=reinterpret_cast<t_DwmFlush>(GetProcAddress(shell, "DwmFlush"));
static t_DwmIsCompositionEnabled isEnabled=reinterpret_cast<t_DwmIsCompositionEnabled>(GetProcAddress(shell, "DwmIsCompositionEnabled"));
BOOL enabled;
isEnabled(&enabled);
if(isEnabled)
flush();
}
#endif // _WIN32
bool flash_reduction_enabled(bool check_qr)
{
return (check_qr && get_qr(qr_EPILEPSY)) || epilepsyFlashReduction || replay_is_debug();
}
// Dialogue largening
void large_dialog(DIALOG *d)
{
large_dialog(d, 1.5);
}
void large_dialog(DIALOG *d, float RESIZE_AMT)
{
if(!d[0].d1)
{
d[0].d1 = 1;
int32_t oldwidth = d[0].w;
int32_t oldheight = d[0].h;
int32_t oldx = d[0].x;
int32_t oldy = d[0].y;
d[0].x -= int32_t(d[0].w/RESIZE_AMT);
d[0].y -= int32_t(d[0].h/RESIZE_AMT);
d[0].w = int32_t(d[0].w*RESIZE_AMT);
d[0].h = int32_t(d[0].h*RESIZE_AMT);
for(int32_t i=1; d[i].proc !=NULL; i++)
{
// Place elements horizontally
double xpc = ((double)(d[i].x - oldx) / (double)oldwidth);
d[i].x = int32_t(d[0].x + (xpc*d[0].w));
if(d[i].proc != d_stringloader)
{
if(d[i].proc==d_bitmap_proc)
{
d[i].w *= 2;
}
else d[i].w = int32_t(d[i].w*RESIZE_AMT);
}
// Place elements vertically
double ypc = ((double)(d[i].y - oldy) / (double)oldheight);
d[i].y = int32_t(d[0].y + (ypc*d[0].h));
// Vertically resize elements
if(d[i].proc == jwin_edit_proc || d[i].proc == jwin_check_proc || d[i].proc == jwin_checkfont_proc)
{
d[i].h = int32_t((double)d[i].h*1.5);
}
else if(d[i].proc == jwin_droplist_proc || d[i].proc == d_joylist_proc)
{
d[i].y += int32_t((double)d[i].h*0.25);
d[i].h = int32_t((double)d[i].h*1.25);
}
else if(d[i].proc==d_bitmap_proc)
{
d[i].h *= 2;
}
else d[i].h = int32_t(d[i].h*RESIZE_AMT);
// Fix frames
if(d[i].proc == jwin_frame_proc)
{
d[i].x++;
d[i].y++;
d[i].w-=4;
d[i].h-=4;
}
}
}
for(int32_t i=1; d[i].proc!=NULL; i++)
{
if(d[i].proc==jwin_slider_proc)
continue;
// Bigger font
bool bigfontproc = (d[i].proc != d_midilist_proc && d[i].proc != jwin_droplist_proc && d[i].proc != jwin_abclist_proc && d[i].proc != jwin_list_proc && d[i].proc != d_joylist_proc);
if(!d[i].dp2 && bigfontproc)
{
d[i].dp2 = get_zc_font(font_lfont_l);
}
else if(!bigfontproc)
{
((ListData *)d[i].dp)->font = &a4fonts[font_lfont_l];
}
// Make checkboxes work
if(d[i].proc == jwin_check_proc)
d[i].proc = jwin_checkfont_proc;
else if(d[i].proc == jwin_radio_proc)
d[i].proc = jwin_radiofont_proc;
}
jwin_center_dialog(d);
}
/**********************************/
/******** System functions ********/
/**********************************/
static char cfg_sect[] = "zeldadx"; //We need to rename this.
static char ctrl_sect[] = "Controls";
static char sfx_sect[] = "Volume";
int32_t d_dummy_proc(int32_t,DIALOG *,int32_t)
{
return D_O_K;
}
bool is_reserved_key(int c)
{
switch(c)
{
case KEY_ESC:
return true;
}
return false;
}
bool is_reserved_keycombo(int c, int modflag)
{
if(c==KEY_F4 && (modflag&KB_ALT_FLAG))
return true;
return false;
}
bool checkcheat(Cheat cheat)
{
if(cheatkeys[cheat][0] && zc_readkey(cheatkeys[cheat][0]))
return true; //Main key pressed
if(cheatkeys[cheat][1] && zc_readkey(cheatkeys[cheat][1]))
return true; //Alt key pressed
return false;
}
void load_default_cheatkeys()
{
memset(cheatkeys, 0, sizeof(cheatkeys));
cheatkeys[Cheat::Life][0] = KEY_H;
cheatkeys[Cheat::Life][1] = KEY_ASTERISK;
cheatkeys[Cheat::Magic][0] = KEY_M;
cheatkeys[Cheat::Magic][1] = KEY_SLASH_PAD;
cheatkeys[Cheat::Rupies][0] = KEY_R;
cheatkeys[Cheat::Bombs][0] = KEY_B;
cheatkeys[Cheat::Arrows][0] = KEY_A;
cheatkeys[Cheat::Clock][0] = KEY_I;
cheatkeys[Cheat::Walls][0] = KEY_F11;
cheatkeys[Cheat::Fast][0] = KEY_Q;
cheatkeys[Cheat::Light][0] = KEY_L;
cheatkeys[Cheat::IgnoreSideView][0] = KEY_V;
cheatkeys[Cheat::Kill][0] = KEY_K;
cheatkeys[Cheat::GoTo][0] = KEY_G;
cheatkeys[Cheat::TrigSecrets][0] = KEY_S;
cheatkeys[Cheat::ShowL0][0] = KEY_0;
cheatkeys[Cheat::ShowL1][0] = KEY_1;
cheatkeys[Cheat::ShowL2][0] = KEY_2;
cheatkeys[Cheat::ShowL3][0] = KEY_3;
cheatkeys[Cheat::ShowL4][0] = KEY_4;
cheatkeys[Cheat::ShowL5][0] = KEY_5;
cheatkeys[Cheat::ShowL6][0] = KEY_6;
cheatkeys[Cheat::ShowFFC][0] = KEY_7;
cheatkeys[Cheat::ShowSprites][0] = KEY_8;
cheatkeys[Cheat::ShowWalkability][0] = KEY_W;
cheatkeys[Cheat::ShowEffects][0] = KEY_E;
cheatkeys[Cheat::ShowOverhead][0] = KEY_O;
cheatkeys[Cheat::ShowPushblock][0] = KEY_P;
cheatkeys[Cheat::ShowHitbox][0] = KEY_C;
cheatkeys[Cheat::ShowFFCScripts][0] = KEY_F;
}
void load_game_configs()
{
strcpy(moduledata.module_name,zc_get_config("ZCMODULE",qst_module_name,"classic.zmod"));
joystick_index = zc_get_config(ctrl_sect,"joystick_index",0);
js_stick_1_x_stick = zc_get_config(ctrl_sect,"js_stick_1_x_stick",0);
js_stick_1_x_axis = zc_get_config(ctrl_sect,"js_stick_1_x_axis",0);
js_stick_1_x_offset = zc_get_config(ctrl_sect,"js_stick_1_x_offset",0) ? 128 : 0;
js_stick_1_y_stick = zc_get_config(ctrl_sect,"js_stick_1_y_stick",0);
js_stick_1_y_axis = zc_get_config(ctrl_sect,"js_stick_1_y_axis",1);
js_stick_1_y_offset = zc_get_config(ctrl_sect,"js_stick_1_y_offset",0) ? 128 : 0;
js_stick_2_x_stick = zc_get_config(ctrl_sect,"js_stick_2_x_stick",1);
js_stick_2_x_axis = zc_get_config(ctrl_sect,"js_stick_2_x_axis",0);
js_stick_2_x_offset = zc_get_config(ctrl_sect,"js_stick_2_x_offset",0) ? 128 : 0;
js_stick_2_y_stick = zc_get_config(ctrl_sect,"js_stick_2_y_stick",1);
js_stick_2_y_axis = zc_get_config(ctrl_sect,"js_stick_2_y_axis",1);
js_stick_2_y_offset = zc_get_config(ctrl_sect,"js_stick_2_y_offset",0) ? 128 : 0;
analog_movement = (zc_get_config(ctrl_sect,"analog_movement",1));
//cheat modifier keya
cheat_modifier_keys[0] = zc_get_config(ctrl_sect,"key_cheatmod_a1",KEY_ZC_LCONTROL);
cheat_modifier_keys[1] = zc_get_config(ctrl_sect,"key_cheatmod_a2",0);
cheat_modifier_keys[2] = zc_get_config(ctrl_sect,"key_cheatmod_b1",KEY_ZC_RCONTROL);
cheat_modifier_keys[3] = zc_get_config(ctrl_sect,"key_cheatmod_b2",0);
//cheat keys
load_default_cheatkeys();
char buf[256];
for(size_t q = 1; q < Cheat::Last; ++q)
{
if(!bindable_cheat((Cheat)q)) continue;
std::string cheatname = cheat_to_string((Cheat)q);
util::lowerstr(cheatname);
sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
cheatkeys[q][0] = zc_get_config(ctrl_sect,buf,cheatkeys[q][0]);
sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
cheatkeys[q][1] = zc_get_config(ctrl_sect,buf,cheatkeys[q][1]);
}
if((uint32_t)joystick_index >= MAX_JOYSTICKS)
joystick_index = 0;
Akey = zc_get_config(ctrl_sect,"key_a",KEY_Z);
Bkey = zc_get_config(ctrl_sect,"key_b",KEY_X);
Skey = zc_get_config(ctrl_sect,"key_s",KEY_ENTER);
Lkey = zc_get_config(ctrl_sect,"key_l",KEY_Q);
Rkey = zc_get_config(ctrl_sect,"key_r",KEY_W);
Pkey = zc_get_config(ctrl_sect,"key_p",KEY_SPACE);
Exkey1 = zc_get_config(ctrl_sect,"key_ex1",KEY_A);
Exkey2 = zc_get_config(ctrl_sect,"key_ex2",KEY_S);
Exkey3 = zc_get_config(ctrl_sect,"key_ex3",KEY_D);
Exkey4 = zc_get_config(ctrl_sect,"key_ex4",KEY_C);
DUkey = zc_get_config(ctrl_sect,"key_up", KEY_UP);
DDkey = zc_get_config(ctrl_sect,"key_down", KEY_DOWN);
DLkey = zc_get_config(ctrl_sect,"key_left", KEY_LEFT);
DRkey = zc_get_config(ctrl_sect,"key_right",KEY_RIGHT);
Abtn = zc_get_config(ctrl_sect,"btn_a",2);
Bbtn = zc_get_config(ctrl_sect,"btn_b",1);
Sbtn = zc_get_config(ctrl_sect,"btn_s",10);
Mbtn = zc_get_config(ctrl_sect,"btn_m",9);
Lbtn = zc_get_config(ctrl_sect,"btn_l",5);
Rbtn = zc_get_config(ctrl_sect,"btn_r",6);
Pbtn = zc_get_config(ctrl_sect,"btn_p",12);
Exbtn1 = zc_get_config(ctrl_sect,"btn_ex1",7);
Exbtn2 = zc_get_config(ctrl_sect,"btn_ex2",8);
Exbtn3 = zc_get_config(ctrl_sect,"btn_ex3",4);
Exbtn4 = zc_get_config(ctrl_sect,"btn_ex4",3);
DUbtn = zc_get_config(ctrl_sect,"btn_up",13);
DDbtn = zc_get_config(ctrl_sect,"btn_down",14);
DLbtn = zc_get_config(ctrl_sect,"btn_left",15);
DRbtn = zc_get_config(ctrl_sect,"btn_right",16);
epilepsyFlashReduction = zc_get_config(cfg_sect,"epilepsy_flash_reduction",0);
digi_volume = zc_get_config(sfx_sect,"digi",248);
midi_volume = zc_get_config(sfx_sect,"midi",255);
sfx_volume = zc_get_config(sfx_sect,"sfx",248);
emusic_volume = zc_get_config(sfx_sect,"emusic",248);
pan_style = zc_get_config(sfx_sect,"pan",1);
// 1 <= zcmusic_bufsz <= 128
zcmusic_bufsz = vbound(zc_get_config(sfx_sect,"zcmusic_bufsz",64),1,128);
volkeys = zc_get_config(sfx_sect,"volkeys",0)!=0;
zc_vsync = zc_get_config(cfg_sect,"vsync",0);
Throttlefps = zc_get_config(cfg_sect,"throttlefps",1)!=0;
TransLayers = zc_get_config(cfg_sect,"translayers",1)!=0;
SnapshotFormat = zc_get_config(cfg_sect,"snapshot_format",3);
NameEntryMode = zc_get_config(cfg_sect,"name_entry_mode",0);
#ifdef __EMSCRIPTEN__
if (em_is_mobile()) NameEntryMode = 2;
#endif
ShowFPS = zc_get_config(cfg_sect,"showfps",0)!=0;
NESquit = zc_get_config(cfg_sect,"fastquit",0)!=0;
ClickToFreeze = zc_get_config(cfg_sect,"clicktofreeze",1)!=0;
abc_patternmatch = zc_get_config(cfg_sect, "lister_pattern_matching", 1);
pause_in_background = zc_get_config(cfg_sect, "pause_in_background", 0);
//default - scale x2, 640 x 480
window_width = resx = zc_get_config(cfg_sect,"window_width",640);
window_height = resy = zc_get_config(cfg_sect,"window_height",480);
SaveDragResize = zc_get_config(cfg_sect,"save_drag_resize",0)!=0;
DragAspect = zc_get_config(cfg_sect,"drag_aspect",0)!=0;
SaveWinPos = zc_get_config(cfg_sect,"save_window_position",0)!=0;
scaleForceInteger = zc_get_config("zeldadx","scaling_force_integer",1)!=0;
stretchGame = zc_get_config("zeldadx","stretch_game_area",0)!=0;
loadlast = zc_get_config(cfg_sect,"load_last",0);
fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
zc_color_depth = (byte) zc_get_config(cfg_sect,"color_depth",8);
forceExit = (byte) zc_get_config(cfg_sect,"force_exit",0);
info_opacity = zc_get_config("zc","debug_info_opacity",255);
#ifdef _WIN32
zasm_debugger = (byte) zc_get_config("CONSOLE","print_ZASM",0);
zscript_debugger = (byte) zc_get_config("CONSOLE","ZScript_Debugger",0);
//use_win7_keyboard_fix = (byte) zc_get_config(cfg_sect,"use_win7_key_fix",0);
use_win32_proc = (byte) zc_get_config(cfg_sect,"zc_win_proc_fix",0); //buggy
// This one's for Aero
use_dwm_flush = (byte) zc_get_config("zeldadx","use_dwm_flush",0);
monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
#else //UNIX
zasm_debugger = (byte) zc_get_config("CONSOLE","print_ZASM",0);
zscript_debugger = (byte) zc_get_config("CONSOLE","ZScript_Debugger",0);
monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
#endif
clearConsoleOnLoad = zc_get_config("CONSOLE","clear_console_on_load",1)!=0;
clearConsoleOnReload = zc_get_config("CONSOLE","clear_console_on_reload",0)!=0;
strcpy(qstdir,zc_get_config(cfg_sect,qst_dir_name,""));
if(strlen(qstdir)==0)
{
getcwd(qstdir,2048);
fix_filename_case(qstdir);
fix_filename_slashes(qstdir);
put_backslash(qstdir);
}
else
{
chop_path(qstdir);
}
strcpy(qstpath,qstdir); //qstpath is the local (for this run of ZC) quest path, qstdir is the universal quest dir.
ss_enable = zc_get_config(cfg_sect,"ss_enable",1) ? 1 : 0;
ss_after = vbound(zc_get_config(cfg_sect,"ss_after",14), 0, 14);
ss_speed = vbound(zc_get_config(cfg_sect,"ss_speed",2), 0, 6);
ss_density = vbound(zc_get_config(cfg_sect,"ss_density",3), 0, 6);
heart_beep = zc_get_config(cfg_sect,"heart_beep",1)!=0;
//gui_colorset = zc_get_config(cfg_sect,"gui_colorset",0);
sfxdat = zc_get_config(cfg_sect,"use_sfx_dat",1);
fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
use_save_indicator = zc_get_config(cfg_sect,"save_indicator",0);
zc_192b163_warp_compatibility = zc_get_config(cfg_sect,"zc_192b163_warp_compatibility",0);
}
void save_control_configs(bool kb)
{
if(kb)
{
zc_set_config(ctrl_sect,"key_cheatmod_a1",cheat_modifier_keys[0]);
zc_set_config(ctrl_sect,"key_cheatmod_a2",cheat_modifier_keys[1]);
zc_set_config(ctrl_sect,"key_cheatmod_b1",cheat_modifier_keys[2]);
zc_set_config(ctrl_sect,"key_cheatmod_b2",cheat_modifier_keys[3]);
if (!replay_is_replaying())
{
zc_set_config(ctrl_sect,"key_a",Akey);
zc_set_config(ctrl_sect,"key_b",Bkey);
zc_set_config(ctrl_sect,"key_s",Skey);
zc_set_config(ctrl_sect,"key_l",Lkey);
zc_set_config(ctrl_sect,"key_r",Rkey);
zc_set_config(ctrl_sect,"key_p",Pkey);
zc_set_config(ctrl_sect,"key_ex1",Exkey1);
zc_set_config(ctrl_sect,"key_ex2",Exkey2);
zc_set_config(ctrl_sect,"key_ex3",Exkey3);
zc_set_config(ctrl_sect,"key_ex4",Exkey4);
zc_set_config(ctrl_sect,"key_up", DUkey);
zc_set_config(ctrl_sect,"key_down", DDkey);
zc_set_config(ctrl_sect,"key_left", DLkey);
zc_set_config(ctrl_sect,"key_right",DRkey);
}
}
else
{
zc_set_config(ctrl_sect,"joystick_index",joystick_index);
zc_set_config(ctrl_sect,"js_stick_1_x_stick",js_stick_1_x_stick);
zc_set_config(ctrl_sect,"js_stick_1_x_axis",js_stick_1_x_axis);
zc_set_config(ctrl_sect,"js_stick_1_x_offset",js_stick_1_x_offset ? 1 : 0);
zc_set_config(ctrl_sect,"js_stick_1_y_stick",js_stick_1_y_stick);
zc_set_config(ctrl_sect,"js_stick_1_y_axis",js_stick_1_y_axis);
zc_set_config(ctrl_sect,"js_stick_1_y_offset",js_stick_1_y_offset ? 1 : 0);
zc_set_config(ctrl_sect,"js_stick_2_x_stick",js_stick_2_x_stick);
zc_set_config(ctrl_sect,"js_stick_2_x_axis",js_stick_2_x_axis);
zc_set_config(ctrl_sect,"js_stick_2_x_offset",js_stick_2_x_offset ? 1 : 0);
zc_set_config(ctrl_sect,"js_stick_2_y_stick",js_stick_2_y_stick);
zc_set_config(ctrl_sect,"js_stick_2_y_axis",js_stick_2_y_axis);
zc_set_config(ctrl_sect,"js_stick_2_y_offset",js_stick_2_y_offset ? 1 : 0);
zc_set_config(ctrl_sect,"analog_movement",analog_movement);
zc_set_config(ctrl_sect,"btn_a",Abtn);
zc_set_config(ctrl_sect,"btn_b",Bbtn);
zc_set_config(ctrl_sect,"btn_s",Sbtn);
zc_set_config(ctrl_sect,"btn_m",Mbtn);
zc_set_config(ctrl_sect,"btn_l",Lbtn);
zc_set_config(ctrl_sect,"btn_r",Rbtn);
zc_set_config(ctrl_sect,"btn_p",Pbtn);
zc_set_config(ctrl_sect,"btn_ex1",Exbtn1);
zc_set_config(ctrl_sect,"btn_ex2",Exbtn2);
zc_set_config(ctrl_sect,"btn_ex3",Exbtn3);
zc_set_config(ctrl_sect,"btn_ex4",Exbtn4);
zc_set_config(ctrl_sect,"btn_up",DUbtn);
zc_set_config(ctrl_sect,"btn_down",DDbtn);
zc_set_config(ctrl_sect,"btn_left",DLbtn);
zc_set_config(ctrl_sect,"btn_right",DRbtn);
}
}
void save_cheatkeys()
{
char buf[256];
for(size_t q = 1; q < Cheat::Last; ++q)
{
if(!bindable_cheat((Cheat)q)) continue;
std::string cheatname = cheat_to_string((Cheat)q);
util::lowerstr(cheatname);
sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
zc_set_config(ctrl_sect,buf,cheatkeys[q][0]);
sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
if(cheatkeys[q][1])
zc_set_config(ctrl_sect,buf,cheatkeys[q][1]);
else zc_set_config(ctrl_sect,buf,(char*)nullptr);
}
}
void save_game_configs()
{
packfile_password("");
zc_set_config("ZCMODULE",qst_module_name,moduledata.module_name);
if (all_get_display() && !all_get_fullscreen_flag()&& SaveWinPos)
{
int o_window_x, o_window_y;
al_get_window_position(all_get_display(), &o_window_x, &o_window_y);
zc_set_config(cfg_sect,"window_x",o_window_x);
zc_set_config(cfg_sect,"window_y",o_window_y);
}
if (all_get_display() && !all_get_fullscreen_flag() && SaveDragResize)
{
double monitor_scale = zc_get_monitor_scale();
window_width = al_get_display_width(all_get_display()) / monitor_scale;
window_height = al_get_display_height(all_get_display()) / monitor_scale;
zc_set_config(cfg_sect,"window_width",window_width);
zc_set_config(cfg_sect,"window_height",window_height);
}
zc_set_config(cfg_sect,"load_last",loadlast);
chop_path(qstdir);
zc_set_config(cfg_sect,qst_dir_name,qstdir);
zc_set_config(cfg_sect,"use_sfx_dat",sfxdat);
flush_config_file();
#ifdef __EMSCRIPTEN__
em_sync_fs();
#endif
}
//----------------------------------------------------------------
// Timers
void fps_callback()
{
lastfps=framecnt;
dword tempsecs = fps_secs;
++tempsecs;
//avgfps=((long double)avgfps*fps_secs+lastfps)/(++fps_secs); // DJGPP doesn't like this
avgfps=((long double)avgfps*fps_secs+lastfps)/(tempsecs);
++fps_secs;
framecnt=0;
}
END_OF_FUNCTION(fps_callback)
int32_t Z_init_timers()
{
static bool didit = false;
const static char *err_str = "Couldn't allocate timer";
err_str = err_str; //Unused variable warning
if(didit)
return 1;
didit = true;
LOCK_VARIABLE(lastfps);
LOCK_VARIABLE(framecnt);
LOCK_FUNCTION(fps_callback);
if(install_int_ex(fps_callback,SECS_TO_TIMER(1)))
return 0;
return 1;
}
void Z_remove_timers()
{
remove_int(fps_callback);
}
//----------------------------------------------------------------
void go()
{
blit(screen,tmp_scr,scrx,scry,0,0,screen->w,screen->h);
}
void comeback()
{
blit(tmp_scr,screen,0,0,scrx,scry,screen->w,screen->h);
}
void dump_pal(BITMAP *dest)
{
for(int32_t i=0; i<256; i++)
rectfill(dest,(i&63)<<2,(i&0xFC0)>>4,((i&63)<<2)+3,((i&0xFC0)>>4)+3,i);
}
//----------------------------------------------------------------
int game_mouse_index = ZCM_BLANK;
static bool system_mouse = false;
bool sys_mouse()
{
system_mouse = true;
return MouseSprite::set(ZCM_NORMAL);
}
bool game_mouse()
{
system_mouse = false;
return MouseSprite::set(game_mouse_index);
}
void custom_mouse(BITMAP* bmp, int fx, int fy, bool sys_recolor, bool user_scale)
{
if(!bmp)
return;
float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
int scaledw = bmp->w*scale, scaledh = bmp->h*scale;
if(bmp->w == scaledw && bmp->h == scaledh)
user_scale = false;
if(user_scale || sys_recolor)
{
if(!user_scale) scale = 1;
BITMAP* tmpbmp = create_bitmap_ex(8,bmp->w*scale,bmp->h*scale);
if(user_scale)
stretch_blit(bmp, tmpbmp, 0, 0, bmp->w, bmp->h, 0, 0, tmpbmp->w, tmpbmp->h);
else
blit(bmp, tmpbmp, 0, 0, 0, 0, bmp->w, bmp->h);
if(sys_recolor)
recolor_mouse(tmpbmp);
MouseSprite::assign(ZCM_CUSTOM, tmpbmp, fx*scale, fy*scale);
destroy_bitmap(tmpbmp);
}
else
{
MouseSprite::assign(ZCM_CUSTOM, bmp, fx, fy);
}
}
//Handles converting the mouse sprite from the .dat file
void recolor_mouse(BITMAP* bmp)
{
for(int32_t x = 0; x < bmp->w; ++x)
{
for(int32_t y = 0; y < bmp->h; ++y)
{
int32_t color = getpixel(bmp, x, y);
switch(color)
{
case dvc(1):
color = jwin_pal[jcCURSORMISC];
break;
case dvc(2):
color = jwin_pal[jcCURSOROUTLINE];
break;
case dvc(3):
color = jwin_pal[jcCURSORLIGHT];
break;
case dvc(5):
color = jwin_pal[jcCURSORDARK];
break;
default:
continue;
}
putpixel(bmp, x, y, color);
}
}
}
void load_mouse()
{
enter_sys_pal();
MouseSprite::set(-1);
float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
int32_t sz = 16*scale;
for(int32_t j = 0; j < 1; ++j)
{
BITMAP* tmpbmp = create_bitmap_ex(8,16,16);
if(zcmouse[j])
destroy_bitmap(zcmouse[j]);
zcmouse[j] = create_bitmap_ex(8,sz,sz);
clear_bitmap(zcmouse[j]);
clear_bitmap(tmpbmp);
blit((BITMAP*)datafile[BMP_MOUSE].dat,tmpbmp,1,j*17+1,0,0,16,16);
recolor_mouse(tmpbmp);
if(sz!=16)
stretch_blit(tmpbmp, zcmouse[j], 0, 0, 16, 16, 0, 0, sz, sz);
else
blit(tmpbmp, zcmouse[j], 0, 0, 0, 0, 16, 16);
destroy_bitmap(tmpbmp);
}
if(!hw_palette) hw_palette = &RAMpal;
zc_set_palette(*hw_palette);
BITMAP* blankmouse = create_bitmap_ex(8,16,16);
clear_bitmap(blankmouse);
MouseSprite::assign(ZCM_NORMAL, zcmouse[0], 1*scale, 1*scale);
MouseSprite::assign(ZCM_BLANK, blankmouse);
//Don't assign ZCM_CUSTOM. That'll be handled by scripts.
//Reload the mouse
if(system_mouse)
sys_mouse();
else game_mouse();
destroy_bitmap(blankmouse);
exit_sys_pal();
}
// sets the video mode and initializes the palette and mouse sprite
bool game_vid_mode(int32_t mode,int32_t wait)
{
if (is_headless())
return true;
if(set_gfx_mode(mode,resx,resy,0,0)!=0)
{
return false;
}
scrx = (resx-320)>>1;
scry = (resy-240)>>1;
for(int32_t q = 0; q < NUM_ZCMOUSE; ++q)
zcmouse[q] = NULL;
load_mouse();
for(int32_t i=240; i<256; i++)
RAMpal[i]=((RGB*)datafile[PAL_GUI].dat)[i];
zc_set_palette(RAMpal);
clear_to_color(screen,BLACK);
rest(wait);
return true;
}
void null_quest()
{
char qstdat_string[2048];
strcpy(qstdat_string, "modules/classic/default.qst");
#ifdef __EMSCRIPTEN__
// The quest template data file is not included because it's really big and isn't really needed
// for the player, except to initialize some graphics. Those same graphics exist in this quest file,
// which is much smaller.
strcpy(qstdat_string, "modules/classic/title_gfx.dat");
#endif
byte skip_flags[4] = { 0 };
loadquest(qstdat_string,&QHeader,&QMisc,tunes+ZC_MIDI_COUNT,false,skip_flags,0,false);
}
void init_NES_mode()
{
null_quest();
}
//----------------------------------------------------------------
qword trianglelines[16]=
{
0x0000000000000000ULL,
0xFD00000000000000ULL,
0xFDFD000000000000ULL,
0xFDFDFD0000000000ULL,
0xFDFDFDFD00000000ULL,
0xFDFDFDFDFD000000ULL,
0xFDFDFDFDFDFD0000ULL,
0xFDFDFDFDFDFDFD00ULL,
0xFDFDFDFDFDFDFDFDULL,
0x00FDFDFDFDFDFDFDULL,
0x0000FDFDFDFDFDFDULL,
0x000000FDFDFDFDFDULL,
0x00000000FDFDFDFDULL,
0x0000000000FDFDFDULL,
0x000000000000FDFDULL,
0x00000000000000FDULL,
};
word screen_triangles[28][32];
/*
qword triangles[4][16]= //[direction][value]
{
{
0x00000000, 0x10000000, 0x21000000, 0x32100000, 0x43210000, 0x54321000, 0x65432100, 0x76543210, 0x87654321, 0x88765432, 0x88876543, 0x88887654, 0x88888765, 0x88888876, 0x88888887, 0x88888888
},
{
0x00000000, 0xF0000000, 0xEF000000, 0xFDF00000, 0xCFDF0000, 0xBCFDF000, 0xABCFDF00, 0x9ABCFDF0, 0x89ABCFDF, 0x889ABCFD, 0x8889ABCD, 0x88889ABC, 0x888889AB, 0x8888889A, 0x88888889, 0x88888888
},
{
0x00000000, 0x00000001, 0x00000012, 0x00000123, 0x00001234, 0x00012345, 0x00123456, 0x01234567, 0x12345678, 0x23456788, 0x34567888, 0x45678888, 0x56788888, 0x67888888, 0x78888888, 0x88888888
},
{
0x00000000, 0x0000000F, 0x000000FE, 0x00000FED, 0x0000FEDC, 0x000FEDCB, 0x00FEDCBA, 0x0FEDCBA9, 0xFEDCBA98, 0xEDCBA988, 0xDCBA9888, 0xCBA98888, 0xBA988888, 0xA9888888, 0x98888888, 0x88888888
}
};
*/
/*
byte triangles[4][16][8]= //[direction][value][line]
{
{
{
0, 0, 0, 0, 0, 0, 0, 0
},
{
1, 0, 0, 0, 0, 0, 0, 0
},
{
2, 1, 0, 0, 0, 0, 0, 0
},
{
3, 2, 1, 0, 0, 0, 0, 0
},
{
4, 3, 2, 1, 0, 0, 0, 0
},
{
5, 4, 3, 2, 1, 0, 0, 0
},
{
6, 5, 4, 3, 2, 1, 0, 0
},
{
7, 6, 5, 4, 3, 2, 1, 0
},
{
8, 7, 6, 5, 4, 3, 2, 1
},
{
8, 8, 7, 6, 5, 4, 3, 2
},
{
8, 8, 8, 7, 6, 5, 4, 3
},
{
8, 8, 8, 8, 7, 6, 5, 4
},
{
8, 8, 8, 8, 8, 7, 6, 5
},
{
8, 8, 8, 8, 8, 8, 7, 6
},
{
8, 8, 8, 8, 8, 8, 8, 7
},
{
8, 8, 8, 8, 8, 8, 8, 8
}
},
{
{
0, 0, 0, 0, 0, 0, 0, 0
},
{
15, 0, 0, 0, 0, 0, 0, 0
},
{
14, 15, 0, 0, 0, 0, 0, 0
},
{
13, 14, 15, 0, 0, 0, 0, 0
},
{
12, 13, 14, 15, 0, 0, 0, 0
},
{
11, 12, 13, 14, 15, 0, 0, 0
},
{
10, 11, 12, 13, 14, 15, 0, 0
},
{
9, 10, 11, 12, 13, 14, 15, 0
},
{
8, 9, 10, 11, 12, 13, 14, 15
},
{
8, 8, 9, 10, 11, 12, 13, 14
},
{
8, 8, 8, 9, 10, 11, 12, 13
},
{
8, 8, 8, 8, 9, 10, 11, 12
},
{
8, 8, 8, 8, 8, 9, 10, 11
},
{
8, 8, 8, 8, 8, 8, 9, 10
},
{
8, 8, 8, 8, 8, 8, 8, 9
},
{
8, 8, 8, 8, 8, 8, 8, 8
}
},
{
{
0, 0, 0, 0, 0, 0, 0, 0
},
{
0, 0, 0, 0, 0, 0, 0, 1
},
{
0, 0, 0, 0, 0, 0, 1, 2
},
{
0, 0, 0, 0, 0, 1, 2, 3
},
{
0, 0, 0, 0, 1, 2, 3, 4
},
{
0, 0, 0, 1, 2, 3, 4, 5
},
{
0, 0, 1, 2, 3, 4, 5, 6
},
{
0, 1, 2, 3, 4, 5, 6, 7
},
{
1, 2, 3, 4, 5, 6, 7, 8
},
{
2, 3, 4, 5, 6, 7, 8, 8
},
{
3, 4, 5, 6, 7, 8, 8, 8
},
{
4, 5, 6, 7, 8, 8, 8, 8
},