This repository has been archived by the owner on Aug 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
leapop.c
9331 lines (8836 loc) · 274 KB
/
leapop.c
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
/* SPDX-License-Identifier: GPL-3.0-or-later */
/* leapop v1.0 (November 2022)
* Copyright (C) 2017-2022 Norbert de Jonge <[email protected]>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see [ www.gnu.org/licenses/ ].
*
* To properly read this code, set your program's tab stop to: 2.
*/
/*========== Includes ==========*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <dirent.h>
#include <ctype.h>
#include <time.h>
#include <math.h>
#include <limits.h>
#if defined WIN32 || _WIN32 || WIN64 || _WIN64
#include <windows.h>
#undef PlaySound
#endif
#include <SDL.h>
#include <SDL_audio.h>
#include <SDL_thread.h>
#include <SDL_ttf.h>
#include <SDL_image.h>
/*========== Includes ==========*/
/*========== Defines ==========*/
#if defined WIN32 || _WIN32 || WIN64 || _WIN64
#define SLASH "\\"
#define DEVNULL "NUL"
#else
#define SLASH "/"
#define DEVNULL "/dev/null"
#endif
#define EXIT_NORMAL 0
#define EXIT_ERROR 1
#define EDITOR_NAME "leapop"
#define EDITOR_VERSION "v1.0 (November 2022)"
#define COPYRIGHT "Copyright (C) 2022 Norbert de Jonge"
#define LEVEL_SIZE 2304
#define LEVELS 15
#define ROOMS 24
#define TILES 30
#define EVENTS 256
#define DISK_DIR_A "disk_appleii"
#define BACKUP_A DISK_DIR_A SLASH "disk.bak"
#define DISK_DIR_B "disk_bbcmaster"
#define BACKUP_B DISK_DIR_B SLASH "disk.bak"
#define DISK_DIR_C "disk_c64"
#define BACKUP_C DISK_DIR_C SLASH "disk.bak"
#define MAX_PATHFILE 200
#define MAX_TOWRITE 720
#define WINDOW_WIDTH 560 + 2 + 50 /*** 612 ***/
#define WINDOW_HEIGHT 384 + 2 + 75 /*** 461 ***/
#define MAX_IMG 200
#define MAX_CON 30
#define REFRESH_PROG 25 /*** That is 40 fps (1000/25). ***/
#define REFRESH_GAME 50 /*** That is 20 fps (1000/50). ***/
#define FONT_SIZE_15 15
#define FONT_SIZE_11 11
#define FONT_SIZE_20 20
#define NUM_SOUNDS 20 /*** Sounds that may play at the same time. ***/
#define MAX_TEXT 100
#define ADJ_BASE_X 339
#define ADJ_BASE_Y 63
#define MAX_OPTION 100
#define MAX_WARNING 200
#define MAX_ERROR 200
#define MAX_INFO 200
#define TABS_GUARD 8
#define TABS_LEVEL 15
#define BAR_FULL 437
/*** Apple II: adamgreen (A0) ***/
#define A0_PRODOS_OFFSET_1 0x103
#define A0_PRODOS_OFFSET_2 0x42C
#define A0_PRODOS_TEXT "PRODOS"
#define A0_POP_OFFSET_1 0x12E6
#define A0_POP_OFFSET_2 0x29600
#define A0_POP_TEXT "Prince of Persia"
/*** Apple II: peterferrie (A1) ***/
#define A1_PRODOS_OFFSET_1 0x103
#define A1_PRODOS_OFFSET_2 0x42C
#define A1_PRODOS_TEXT "PRODOS"
#define A1_POP_OFFSET_1 0x405
#define A1_POP_OFFSET_2 0x47A
#define A1_POP_TEXT "PRINCEUNP"
/*** BBC Master: kieranhj 1.0 (B0) ***/
#define B0_POPBBCM_OFFSET 0
#define B0_POPBBCM_TEXT "POP BEEB"
#define B0_VANDB_OFFSET 0x26F0
/*** v1.0 2018-03-29 22:00 kc ***/
#define B0_VANDB_TEXT "\x10\x18\x03\x29\x22\x00\x6B\x63"
/*** BBC Master: kieranhj 1.1 (B1) ***/
#define B1_POPBBCM_OFFSET 0
#define B1_POPBBCM_TEXT "POP BEEB"
#define B1_VANDB_OFFSET 0x26F0
/*** v1.1 2018-04-01 20:35 kc ***/
#define B1_VANDB_TEXT "\x11\x18\x04\x01\x20\x35\x6B\x63"
/*** C64: mrsid (C0) ***/
#define C0_C64CART_OFFSET 0x00
#define C0_C64CART_TEXT "C64 CARTRIDGE"
#define C0_DATE_OFFSET 0x688C1
#define C0_DATE_TEXT "05/11/2011"
#define BROKEN_ROOM_X 355
#define BROKEN_ROOM_Y 79
#define BROKEN_LEFT_X 340
#define BROKEN_LEFT_Y 79
#define BROKEN_RIGHT_X 370
#define BROKEN_RIGHT_Y 79
#define BROKEN_UP_X 355
#define BROKEN_UP_Y 64
#define BROKEN_DOWN_X 355
#define BROKEN_DOWN_Y 94
#define PNG_VARIOUS "various"
#define PNG_LIVING "living"
#define PNG_SLIVING "sliving"
#define PNG_BUTTONS "buttons"
#define PNG_EXTRAS "extras"
#define PNG_ROOMS "rooms"
#define PNG_GAMEPAD "gamepad"
#define OFFSETD_X 25 - 1 /*** Left column, pixels from the left. ***/
#define OFFSETD_Y 50 + 6 + 2 /*** Top row, pixels from the top. ***/
#define TTPD_1 20 /*** Top row, pixels behind interface/floor. ***/
#define TTPD_O 20 /*** Other rows, pixels behind superjacent rows. ***/
#define DD_X 56 /*** Horizontal distance between (overlapping) tiles. ***/
#define DD_Y 126 /*** Vertical distance between (overlapping) tiles. ***/
#define TILEWIDTH 42 /*** On tiles screen. ***/
#define TILEHEIGHT 52 /*** On tiles screen. ***/
#define TILESX1 (TILEWIDTH + 2) * 0
#define TILESX2 (TILEWIDTH + 2) * 1
#define TILESX3 (TILEWIDTH + 2) * 2
#define TILESX4 (TILEWIDTH + 2) * 3
#define TILESX5 (TILEWIDTH + 2) * 4
#define TILESX6 (TILEWIDTH + 2) * 5
#define TILESX7 (TILEWIDTH + 2) * 6
#define TILESX8 (TILEWIDTH + 2) * 7
#define TILESX9 (TILEWIDTH + 2) * 8
#define TILESX10 (TILEWIDTH + 2) * 9
#define TILESX11 (TILEWIDTH + 2) * 10
#define TILESX12 (TILEWIDTH + 2) * 11
#define TILESX13 (TILEWIDTH + 2) * 12
#define TILESY1 2 + (TILEHEIGHT + 2) * 0
#define TILESY2 2 + (TILEHEIGHT + 2) * 1
#define TILESY3 2 + (TILEHEIGHT + 2) * 2
#define TILESY4 2 + (TILEHEIGHT + 2) * 3
#define TILESY5 2 + (TILEHEIGHT + 2) * 4
#define TILESY6 2 + (TILEHEIGHT + 2) * 5
#define TILESY7 2 + (TILEHEIGHT + 2) * 6
#ifndef O_BINARY
#define O_BINARY 0
#endif
/*========== Defines ==========*/
int iDebug;
unsigned char arLevel[LEVEL_SIZE + 2];
int iLevelRead;
char sPathFileA[MAX_PATHFILE + 2];
char sPathFileB[MAX_PATHFILE + 2];
char sPathFileC[MAX_PATHFILE + 2];
char sPathFile[MAX_PATHFILE + 2];
int iChanged;
int iScreen;
TTF_Font *font1;
TTF_Font *font2;
TTF_Font *font3;
SDL_Window *window;
SDL_Renderer *ascreen;
int iScale;
int iFullscreen;
SDL_Cursor *curArrow;
SDL_Cursor *curWait;
SDL_Cursor *curHand;
int iNoAudio;
int iNoController;
int iPreLoaded;
int iNrToPreLoad;
int iCurrentBarHeight;
int iDownAt;
int iSelected;
int iChangeEvent;
int iGuardType;
int iCurLevel;
int iExtras;
int arBrokenRoomLinks[LEVELS + 2];
int iCurRoom;
int iMovingRoom;
int iMovingNewBusy;
int iChangingBrokenRoom;
int iChangingBrokenSide;
int iLastX, iLastTile, iLastMod;
int iXPos, iYPos;
int iInfo;
int arMovingRooms[ROOMS + 1 + 2][ROOMS + 2];
unsigned int gamespeed;
Uint32 looptime;
char cCurType;
int iCurGuard;
int arDone[ROOMS + 2];
int iStartRoomsX, iStartRoomsY;
int iMovingNewX, iMovingNewY;
int iMinX, iMaxX, iMinY, iMaxY;
int iMovingOldX, iMovingOldY;
int arRoomConnectionsBroken[LEVELS + 2][ROOMS + 2][4 + 2];
int iOnTile;
int iOnTileOld;
Uint32 ontile;
int iCloseOn;
int iHelpOK;
int iEXESave;
int iOKOn;
int iYesOn;
int iNoOn;
int iCopied;
int iStartLevel;
int iCustomX, iCustomTile, iCustomMod;
int iCustomHover, iCustomHoverOld;
int iEmulator;
char sInfo[MAX_INFO + 2];
int iNoAnim;
int iFlameFrame;
int cChecksum;
Uint32 oldticks, newticks;
int iMouse;
int iGuardTooltip;
int iEventHover;
int iHomeComputer;
int iDiskImageA;
int iDiskImageB;
int iDiskImageC;
int iAppleII;
int iOnAppleII;
int iBBCMaster;
int iOnBBCMaster;
int iC64;
int iOnC64;
int iHomeComputerActive;
int iModified;
/*** EXE ***/
int iEXEPrinceHP;
int iEXEShadowHP;
int iEXEChomperDelay;
int iEXEMouseDelay;
static const int arDefaultGuard[][12] = {
{ 0x4B, 0x64, 0x4B, 0x4B, 0x4B, 0x32, 0x64, 0xDC, 0x00, 0x3C, 0x28, 0x3C },
{ 0x00, 0x00, 0x00, 0x05, 0x05, 0xAF, 0x14, 0x0A, 0x00, 0xFF, 0xFF, 0x96 },
{ 0x00, 0x96, 0x96, 0xC8, 0xC8, 0xFF, 0xC8, 0xFA, 0x00, 0xFF, 0xFF, 0xFF },
{ 0x00, 0x4B, 0x4B, 0x64, 0x64, 0x91, 0x64, 0xFA, 0x00, 0x91, 0xFF, 0xAF },
{ 0xFF, 0xC8, 0xC8, 0xC8, 0xFF, 0xFF, 0xC8, 0x00, 0x00, 0xFF, 0x64, 0x64 },
{ 0x14, 0x14, 0x14, 0x14, 0x0A, 0x0A, 0x0A, 0x0A, 0x00, 0x0A, 0x00, 0x00 },
{ 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01 },
{ 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
};
static const int arDefaultGuardHP[TABS_LEVEL] = { 4, 3, 3, 3, 3, 4, 5, 4, 4, 5, 5, 5, 4, 6, 1 }; /*** Last value is not used. ***/
static const int arDefaultGuardU[TABS_LEVEL] = { 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 96 }; /*** Last value is not used. ***/
static const int arDefaultGuardS[TABS_LEVEL] = { 0, 0, 0, 1, 2, 2, 3, 2, 2, 2, 2, 2, 4, 5, 5 }; /*** Last value is not used. ***/
static const int arDefaultEnv1[TABS_LEVEL] = { 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x01 };
static const int arDefaultEnv2[TABS_LEVEL] = { 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x01, 0x01, 0x02, 0x02, 0x01 };
/* The following offsets are for:
* ...A[] = { adamgreen (A0), peterferrie (A1) }
* ...B[] = { kieranhj 1.0 (B0), kieranhj 1.1 (B1) }
* ...C[] = { mrsid (C0) }
* 0x00 = unused
*/
static const unsigned long arLevelOffsetsA[][15] = /*** 0 - 14 ***/
{
{
0x26900 + (1 * 0x900),
0x26900 + (2 * 0x900),
0x26900 + (0 * 0x900),
0x49000 + (10 * 0x900),
0x49000 + (11 * 0x900),
0x49000 + (8 * 0x900),
0x49000 + (9 * 0x900),
0x49000 + (6 * 0x900),
0x49000 + (7 * 0x900),
0x49000 + (4 * 0x900),
0x49000 + (5 * 0x900),
0x49000 + (2 * 0x900),
0x49000 + (3 * 0x900),
0x49000 + (0 * 0x900),
0x49000 + (1 * 0x900)
},
{
0x28D00 + (1 * 0x900),
0x28D00 + (2 * 0x900),
0x28D00 + (0 * 0x900),
0x48A00 + (10 * 0x900),
0x48A00 + (11 * 0x900),
0x48A00 + (8 * 0x900),
0x48A00 + (9 * 0x900),
0x48A00 + (6 * 0x900),
0x48A00 + (7 * 0x900),
0x48A00 + (4 * 0x900),
0x48A00 + (5 * 0x900),
0x48A00 + (2 * 0x900),
0x48A00 + (3 * 0x900),
0x48A00 + (0 * 0x900),
0x48A00 + (1 * 0x900)
}
};
static const unsigned long arLevelOffsetsB[][15] = /*** 0 - 14 ***/
{
{
0x24200 + (0 * 0xA00),
0x24200 + (1 * 0xA00),
0x24200 + (2 * 0xA00),
0x24200 + (3 * 0xA00),
0x24200 + (4 * 0xA00),
0x24200 + (5 * 0xA00),
0x24200 + (6 * 0xA00),
0x24200 + (7 * 0xA00),
0x24200 + (8 * 0xA00),
0x24200 + (9 * 0xA00),
0x24200 + (10 * 0xA00),
0x24200 + (11 * 0xA00),
0x24200 + (12 * 0xA00),
0x24200 + (13 * 0xA00),
0x24200 + (14 * 0xA00)
},
{
0x24200 + (0 * 0xA00),
0x24200 + (1 * 0xA00),
0x24200 + (2 * 0xA00),
0x24200 + (3 * 0xA00),
0x24200 + (4 * 0xA00),
0x24200 + (5 * 0xA00),
0x24200 + (6 * 0xA00),
0x24200 + (7 * 0xA00),
0x24200 + (8 * 0xA00),
0x24200 + (9 * 0xA00),
0x24200 + (10 * 0xA00),
0x24200 + (11 * 0xA00),
0x24200 + (12 * 0xA00),
0x24200 + (13 * 0xA00),
0x24200 + (14 * 0xA00)
}
};
static const unsigned long arLevelOffsetsC[][15] = /*** 0 - 14 ***/
{
{
0x00,
0x100D0,
0x109D0,
0x112D0,
0x140F0,
0x149F0,
0x152F0,
0x18110,
0x18A10,
0x19310,
0x1C130,
0x1CA30,
0x1D330,
0x20150,
0x20A50
}
};
/* In theory, ulStartLevelA for A1 could be set to 0x7343, but this only
* seems to work for level 2. Perhaps because of packing. Additionally,
* 0x731A might skip the intro. And the ProDOS info, by changing 9D to BD at
* 0x1638, 0x1643, 0x164E, 0x1659.
*/
static const unsigned long ulSkipIntroA[] = { 0x00, 0x00 };
static const unsigned long ulSkipIntroB[] = { 0x428, 0x428 };
static const unsigned long ulSkipIntroC[] = { 0x00 };
static const unsigned long ulStartLevelA[] = { 0x00, 0x00 };
static const unsigned long ulStartLevelB[] = { 0x12F9, 0x12F9 };
static const unsigned long ulStartLevelC[] = { 0x00 };
static const unsigned long ulSavedLevelA[] = { 0x43600, 0x00 };
static const unsigned long ulSavedLevelB[] = { 0x00, 0x00 };
static const unsigned long ulSavedLevelC[] = { 0x00 };
/*** A5 7C 30 04 A9 40 85 7D ***/
static const unsigned long ulCopyProtA[] = { 0x19497, 0x1BA97 };
static const unsigned long ulCopyProtB[] = { 0x00, 0x00 };
static const unsigned long ulCopyProtC[] = { 0x00 };
static const unsigned long ulPrinceHPA[] = { 0x7258, 0xA058 };
static const unsigned long ulPrinceHPB[] = { 0x14CB, 0x14CB };
static const unsigned long ulPrinceHPC[] = { 0x00 }; /*** Inaccessible. ***/
static const unsigned long ulShadowHPA[] = { 0x15F44, 0x18B44 };
static const unsigned long ulShadowHPB[] = { 0x00, 0x00 };
static const unsigned long ulShadowHPC[] = { 0x00 };
static const unsigned long ulChomperDelayA[] = { 0x19E9A, 0x1C29A };
static const unsigned long ulChomperDelayB[] = { 0x00, 0x00 };
static const unsigned long ulChomperDelayC[] = { 0x00 };
static const unsigned long ulMouseDelayA[] = { 0x79B8, 0xA7BB };
static const unsigned long ulMouseDelayB[] = { 0x00, 0x00 };
static const unsigned long ulMouseDelayC[] = { 0x00 };
/***
Defaults, as used in arDefaultGuard[][]:
4B 64 4B 4B 4B 32 64 DC 00 3C 28 3C strike prob.
00 00 00 05 05 AF 14 0A 00 FF FF 96 re-strike prob.
00 96 96 C8 C8 FF C8 FA 00 FF FF FF block prob.
00 4B 4B 64 64 91 64 FA 00 91 FF AF imp. block prob.
FF C8 C8 C8 FF FF C8 00 00 FF 64 64 advance prob.
14 14 14 14 0A 0A 0A 0A 00 0A 00 00 refractory timer
00 00 00 01 00 01 01 00 00 00 00 01 special color
00 00 00 00 01 00 00 00 00 00 00 00 extra strength
***/
static const unsigned long ulGuardA[][TABS_GUARD] =
{
{
0x15A1C + (0 * 0x0C),
0x15A1C + (1 * 0x0C),
0x15A1C + (2 * 0x0C),
0x15A1C + (3 * 0x0C),
0x15A1C + (4 * 0x0C),
0x15A1C + (5 * 0x0C),
0x15A1C + (6 * 0x0C),
0x15A1C + (7 * 0x0C)
},
{
0x1861C + (0 * 0x0C),
0x1861C + (1 * 0x0C),
0x1861C + (2 * 0x0C),
0x1861C + (3 * 0x0C),
0x1861C + (4 * 0x0C),
0x1861C + (5 * 0x0C),
0x1861C + (6 * 0x0C),
0x1861C + (7 * 0x0C)
}
};
static const unsigned long ulGuardB[][TABS_GUARD] =
{
{
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00
},
{
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00,
0x00
}
};
static const unsigned long ulGuardC[][TABS_GUARD] =
{
{
0xEC42,
0xEC4E,
0xEC5A,
0xEC66,
0xEC72,
0xEC7E,
0xEC8A,
0xEC96
}
};
/*** 04 03 03 03 03 04 05 04 04 05 05 05 04 06 (01) ***/
static const unsigned long ulGuardHPA[] = { 0x15A7C, 0x1867C };
static const unsigned long ulGuardHPB[] = { 0x00, 0x00 };
static const unsigned long ulGuardHPC[] = { 0xECA2 };
/*** 01 00 00 00 01 01 01 00 00 00 01 01 00 00 (60) ***/
static const unsigned long ulGuardUniformA[] = { 0x15A8A, 0x1868A };
static const unsigned long ulGuardUniformB[] = { 0x00, 0x00 };
static const unsigned long ulGuardUniformC[] = { 0x00 };
/*** 00 00 00 01 02 02 03 02 02 02 02 02 04 05 (05) ***/
static const unsigned long ulGuardSpriteA[] = { 0x1A8D5, 0x1CCD5 };
static const unsigned long ulGuardSpriteB[] = { 0x114A, 0x114A };
static const unsigned long ulGuardSpriteC[] = { 0x00 };
/*** 00 00 00 00 01 01 01 02 02 02 01 01 02 02 01 ***/
static const unsigned long ulEnv1A[] = { 0x1A8B7, 0x1CCB7 };
static const unsigned long ulEnv1B[] = { 0x00, 0x00 };
static const unsigned long ulEnv1C[] = { 0x00 };
/*** 00 00 00 00 01 01 01 02 02 02 01 01 02 02 01 ***/
static const unsigned long ulEnv2A[] = { 0x1A8C6, 0x1CCC6 };
static const unsigned long ulEnv2B[] = { 0x00, 0x00 };
static const unsigned long ulEnv2C[] = { 0x00 };
int iEXEGuard[TABS_GUARD + 2][12 + 2];
int iEXEGuardHP[TABS_LEVEL + 2];
int iEXEGuardU[TABS_LEVEL + 2];
int iEXEGuardS[TABS_LEVEL + 2];
int iEXEEnv1[TABS_LEVEL + 2];
int iEXEEnv2[TABS_LEVEL + 2];
int iEXETab, iEXETabS;
/*** for text ***/
SDL_Color color_bl = {0x00, 0x00, 0x00, 255};
SDL_Color color_wh = {0xff, 0xff, 0xff, 255};
SDL_Color color_blue = {0x00, 0x00, 0xff, 255};
SDL_Color color_gray = {0xbf, 0xbf, 0xbf, 255};
SDL_Surface *message;
SDL_Texture *messaget;
SDL_Rect offset;
/*** for copying ***/
int arCopyPasteX[TILES + 2];
unsigned char arCopyPasteTile[TILES + 2];
unsigned char arCopyPasteMod[TILES + 2];
unsigned char cCopyPasteGuardTile;
unsigned char cCopyPasteGuardDir;
unsigned char cCopyPasteGuardSkill;
unsigned char cCopyPasteGuardC;
/*** controller ***/
int iController;
SDL_GameController *controller;
char sControllerName[MAX_CON + 2];
SDL_Joystick *joystick;
SDL_Haptic *haptic;
Uint32 joyleft, joyright, joyup, joydown;
Uint32 trigleft, trigright;
int iXJoy1, iYJoy1, iXJoy2, iYJoy2;
/*** These are the levels. ***/
int arRoomX[LEVELS + 2][ROOMS + 2][TILES + 2];
unsigned char arRoomTiles[LEVELS + 2][ROOMS + 2][TILES + 2];
unsigned char arRoomMod[LEVELS + 2][ROOMS + 2][TILES + 2];
unsigned char arEventsRoom[LEVELS + 2][EVENTS + 2];
unsigned char arEventsTile[LEVELS + 2][EVENTS + 2];
int arEventsNext[LEVELS + 2][EVENTS + 2];
unsigned char arEventsTimer[LEVELS + 2][EVENTS + 2];
unsigned char arRoomLinks[LEVELS + 2][ROOMS + 2][4 + 2];
unsigned char arBytes64[LEVELS + 2][64 + 2];
unsigned char arStartLocation[LEVELS + 2][3 + 2];
unsigned char arBytes4[LEVELS + 2][4 + 2];
unsigned char arGuardTile[LEVELS + 2][ROOMS + 2];
unsigned char arGuardDir[LEVELS + 2][ROOMS + 2];
unsigned char arGuardUnk1[LEVELS + 2][ROOMS + 2]; /*** GdStartX ***/
unsigned char arGuardUnk2[LEVELS + 2][ROOMS + 2]; /*** GdStartSeqL ***/
unsigned char arGuardSkill[LEVELS + 2][ROOMS + 2];
unsigned char arGuardUnk3[LEVELS + 2][ROOMS + 2]; /*** GdStartSeqH ***/
unsigned char arGuardC[LEVELS + 2][ROOMS + 2]; /*** ? ***/
unsigned char arBytes16[LEVELS + 2][16 + 2];
int iDX, iDY, iTTP1, iTTPO;
int iHor[10 + 2];
int iVer0, iVer1, iVer2, iVer3, iVer4;
SDL_Texture *imgloading;
SDL_Texture *imgd[0xFF + 2][0xFF + 2][2 + 2];
SDL_Texture *imgp[0xFF + 2][0xFF + 2][2 + 2];
SDL_Texture *imgblack;
SDL_Texture *imgprincel[2 + 2], *imgprincer[2 + 2];
SDL_Texture *imgguardl[2 + 2], *imgguardr[2 + 2];
SDL_Texture *imgskell[2 + 2], *imgskelr[2 + 2];
SDL_Texture *imgfatl[2 + 2], *imgfatr[2 + 2];
SDL_Texture *imgshadowl[2 + 2], *imgshadowr[2 + 2];
SDL_Texture *imgjaffarl[2 + 2], *imgjaffarr[2 + 2];
SDL_Texture *imgdisabled;
SDL_Texture *imgunk[2 + 2];
SDL_Texture *imgup_0;
SDL_Texture *imgup_1;
SDL_Texture *imgdown_0;
SDL_Texture *imgdown_1;
SDL_Texture *imgleft_0;
SDL_Texture *imgleft_1;
SDL_Texture *imgright_0;
SDL_Texture *imgright_1;
SDL_Texture *imgudno;
SDL_Texture *imglrno;
SDL_Texture *imgudnonfo;
SDL_Texture *imgprevon_0;
SDL_Texture *imgprevon_1;
SDL_Texture *imgnexton_0;
SDL_Texture *imgnexton_1;
SDL_Texture *imgprevoff;
SDL_Texture *imgnextoff;
SDL_Texture *imgbara, *imgbarb, *imgbarc;
SDL_Texture *imgextras[10 + 2];
SDL_Texture *imgroomson_0;
SDL_Texture *imgroomson_1;
SDL_Texture *imgroomsoff;
SDL_Texture *imgbroomson_0;
SDL_Texture *imgbroomson_1;
SDL_Texture *imgbroomsoff;
SDL_Texture *imgeventson_0;
SDL_Texture *imgeventson_1;
SDL_Texture *imgeventsoff;
SDL_Texture *imgsaveon_0;
SDL_Texture *imgsaveon_1;
SDL_Texture *imgsaveoff;
SDL_Texture *imgquit_0;
SDL_Texture *imgquit_1;
SDL_Texture *imgrl;
SDL_Texture *imgbrl;
SDL_Texture *imgsrc;
SDL_Texture *imgsrs;
SDL_Texture *imgsrm;
SDL_Texture *imgsrp;
SDL_Texture *imgsrb;
SDL_Texture *imgevents;
SDL_Texture *imgsele;
SDL_Texture *imgeventu;
SDL_Texture *imgsell;
SDL_Texture *imgdungeon;
SDL_Texture *imgpalace;
SDL_Texture *imgclosebig_0;
SDL_Texture *imgclosebig_1;
SDL_Texture *imgborderb;
SDL_Texture *imgborders;
SDL_Texture *imgbordersl;
SDL_Texture *imgborderbl;
SDL_Texture *imgfadedl;
SDL_Texture *imgpopup;
SDL_Texture *imgok[2 + 2];
SDL_Texture *imgsave[2 + 2];
SDL_Texture *imgpopup_yn;
SDL_Texture *imgyes[2 + 2];
SDL_Texture *imgno[2 + 2];
SDL_Texture *imghelp;
SDL_Texture *imgexe;
SDL_Texture *imgfadeds;
SDL_Texture *imgroom[24 + 2];
SDL_Texture *imgchover;
SDL_Texture *imgemulator;
SDL_Texture *imgspriteflamed;
SDL_Texture *imgspriteflamep;
SDL_Texture *imgexetab;
SDL_Texture *imgexetabs;
SDL_Texture *imgexeenvok;
SDL_Texture *imgexeenvwarn;
SDL_Texture *imgmouse;
SDL_Texture *imgtooltipg;
SDL_Texture *imgpreviewb;
SDL_Texture *imgeventh;
SDL_Texture *imghc;
SDL_Texture *imghcadis, *imghcaoff, *imghcaon, *imghcalb;
SDL_Texture *imghcbdis, *imghcboff, *imghcbon, *imghcblb;
SDL_Texture *imghccdis, *imghccoff, *imghccon, *imghcclb;
struct sample {
Uint8 *data;
Uint32 dpos;
Uint32 dlen;
} sounds[NUM_SOUNDS];
void ShowUsage (void);
int GetPathFileA (void);
int GetPathFileB (void);
int GetPathFileC (void);
void LoadLevels (int iAtLevel);
void SaveLevels (void);
void PrintTileName (int iLevel, int iRoom, int iTile, int iTileValue);
void PrintMod (int iTileValue, int iModValue);
void PrIfDe (char *sString);
char cShowDirection (int iDirection);
void Quit (void);
void InitScreen (void);
void InitPopUpSave (void);
void ShowPopUpSave (void);
void LoadFonts (void);
void MixAudio (void *unused, Uint8 *stream, int iLen);
void PlaySound (char *sFile);
void PreLoadSet (char cTypeP, int iTile, int iMod);
void PreLoad (char *sPath, char *sPNG, SDL_Texture **imgImage);
void ShowScreen (void);
void InitPopUp (void);
void ShowPopUp (void);
void Help (void);
void ShowHelp (void);
void EXE (void);
void ShowEXE (void);
void InitScreenAction (char *sAction);
void RunLevel (int iLevel);
int StartGame (void *unused);
void ClearRoom (void);
void UseTile (int iTile, int iLocation, int iRoom);
void Zoom (int iToggleFull);
void LinkMinus (void);
int BrokenRoomLinks (int iPrint);
void ChangeEvent (int iAmount, int iChangePos);
void ChangeCustom (int iAmount, int iType);
void Prev (void);
void Next (void);
void CallSave (void);
void Sprinkle (void);
void SetLocation (int iRoom, int iLocation, int iTile, int iMod);
void FlipRoom (int iAxis);
void CopyPaste (int iAction);
int InArea (int iUpperLeftX, int iUpperLeftY,
int iLowerRightX, int iLowerRightY);
int MouseSelectAdj (void);
int OnLevelBar (void);
void ChangePos (void);
void RemoveOldRoom (void);
void AddNewRoom (int iX, int iY, int iRoom);
void LinkPlus (void);
void ShowImage (SDL_Texture *img, int iX, int iY, char *sImageInfo);
void CustomRenderCopy (SDL_Texture* src, SDL_Rect* srcrect,
SDL_Rect *dstrect, char *sImageInfo);
void CreateBAK (void);
void DisplayText (int iStartX, int iStartY, int iFontSize,
char arText[9 + 2][MAX_TEXT + 2], int iLines, TTF_Font *font);
void InitRooms (void);
void WhereToStart (void);
void CheckSides (int iRoom, int iX, int iY);
void ShowRooms (int iRoom, int iX, int iY, int iNext);
void BrokenRoomChange (int iRoom, int iSide, int *iX, int *iY);
void ShowChange (void);
int OnTile (void);
void ChangePosAction (char *sAction);
void DisableSome (void);
int IsDisabled (int iTile);
void CenterNumber (int iNumber, int iX, int iY,
SDL_Color fore, int iHex);
int Unused (int iTile);
void OpenURL (char *sURL);
void EXELoad (void);
void EXESave (void);
int PlusMinus (int *iWhat, int iX, int iY,
int iMin, int iMax, int iChange, int iAddChanged);
void GetOptionValue (char *sArgv, char *sValue);
int BitsToInt (char *sString);
void IntToBits (int iInt, char *sOutput, int iBits);
void GetAsEightBits (unsigned char cChar, char *sBinary);
int ChecksumOrWrite (int iFd, int iLevel);
int Verify (int iFd, int iOffset, char *sText);
void GetTileMod (int iGetRoom, int iGetTile, int *iTile, int *iMod);
void GetTileModChange (int iGetTile, int *iTile, int *iMod);
void ApplySkillIfNecessary (int iTile);
void LoadingBar (int iBarHeight);
void HomeComputerAction (char *sAction);
void HomeComputer (void);
void ShowHomeComputer (void);
void PlaytestStart (int iLevel);
void PlaytestStop (void);
/*****************************************************************************/
int main (int argc, char *argv[])
/*****************************************************************************/
{
int iArgLoop;
SDL_version verc, verl;
time_t tm;
char sStartLevel[MAX_OPTION + 2];
iDebug = 0;
iExtras = 0;
iLastX = 0;
iLastTile = 0x00;
iLastMod = 0x00;
iInfo = 0;
iScale = 1;
iOnTile = 1;
iOnTileOld = 1;
iCopied = 0;
iNoAudio = 0;
iFullscreen = 0;
iNoController = 0;
iStartLevel = 1;
iCustomMod = 0;
iCustomTile = 0x00;
iCustomMod = 0x00;
iEmulator = 0;
iNoAnim = 0;
iMouse = 0;
iGuardTooltip = 0;
iEventHover = 0;
iHomeComputer = 0;
iModified = 0;
if (argc > 1)
{
for (iArgLoop = 1; iArgLoop <= argc - 1; iArgLoop++)
{
if ((strcmp (argv[iArgLoop], "-h") == 0) ||
(strcmp (argv[iArgLoop], "-?") == 0) ||
(strcmp (argv[iArgLoop], "--help") == 0))
{
ShowUsage();
}
else if ((strcmp (argv[iArgLoop], "-v") == 0) ||
(strcmp (argv[iArgLoop], "--version") == 0))
{
printf ("%s %s\n", EDITOR_NAME, EDITOR_VERSION);
exit (EXIT_NORMAL);
}
else if ((strcmp (argv[iArgLoop], "-d") == 0) ||
(strcmp (argv[iArgLoop], "--debug") == 0))
{
iDebug = 1;
}
else if ((strcmp (argv[iArgLoop], "-n") == 0) ||
(strcmp (argv[iArgLoop], "--noaudio") == 0))
{
iNoAudio = 1;
}
else if ((strcmp (argv[iArgLoop], "-z") == 0) ||
(strcmp (argv[iArgLoop], "--zoom") == 0))
{
iScale = 2;
}
else if ((strcmp (argv[iArgLoop], "-f") == 0) ||
(strcmp (argv[iArgLoop], "--fullscreen") == 0))
{
iFullscreen = SDL_WINDOW_FULLSCREEN_DESKTOP;
}
else if ((strncmp (argv[iArgLoop], "-l=", 3) == 0) ||
(strncmp (argv[iArgLoop], "--level=", 8) == 0))
{
GetOptionValue (argv[iArgLoop], sStartLevel);
iStartLevel = atoi (sStartLevel);
if ((iStartLevel < 1) || (iStartLevel > LEVELS))
{
iStartLevel = 1;
}
}
else if ((strcmp (argv[iArgLoop], "-s") == 0) ||
(strcmp (argv[iArgLoop], "--static") == 0))
{
iNoAnim = 1;
}
else if ((strcmp (argv[iArgLoop], "-k") == 0) ||
(strcmp (argv[iArgLoop], "--keyboard") == 0))
{
iNoController = 1;
}
else if ((strcmp (argv[iArgLoop], "-a") == 0) ||
(strcmp (argv[iArgLoop], "--appleii") == 0))
{
iHomeComputer = 1;
}
else if ((strcmp (argv[iArgLoop], "-b") == 0) ||
(strcmp (argv[iArgLoop], "--bbcmaster") == 0))
{
iHomeComputer = 2;
}
else if ((strcmp (argv[iArgLoop], "-c") == 0) ||
(strcmp (argv[iArgLoop], "--c64") == 0))
{
iHomeComputer = 3;
}
else
{
ShowUsage();
}
}
}
iAppleII = GetPathFileA();
iBBCMaster = GetPathFileB();
iC64 = GetPathFileC();
srand ((unsigned)time(&tm));
/*** Show the SDL version used for compiling and linking. ***/
if (iDebug == 1)
{
SDL_VERSION (&verc);
SDL_GetVersion (&verl);
printf ("[ INFO ] Compiled with SDL %u.%u.%u, linked with SDL %u.%u.%u.\n",
verc.major, verc.minor, verc.patch, verl.major, verl.minor, verl.patch);
}
InitScreen();
Quit();
return 0;
}
/*****************************************************************************/
void ShowUsage (void)
/*****************************************************************************/
{
printf ("%s %s\n%s\n\n", EDITOR_NAME, EDITOR_VERSION, COPYRIGHT);
printf ("Usage:\n");
printf (" %s [OPTIONS]\n\nOptions:\n", EDITOR_NAME);
printf (" -h, -?, --help display this help and exit\n");
printf (" -v, --version output version information and"
" exit\n");
printf (" -d, --debug also show levels on the console\n");
printf (" -n, --noaudio do not play sound effects\n");
printf (" -z, --zoom double the interface size\n");
printf (" -f, --fullscreen start in fullscreen mode\n");
printf (" -l=NR, --level=NR start in level NR\n");
printf (" -s, --static do not display animations\n");
printf (" -k, --keyboard do not use a game controller\n");
printf (" -a, --appleii edit Apple II levels\n");
printf (" -b, --bbcmaster edit BBC Master levels\n");
printf (" -c, --c64 edit C64 levels\n");
printf ("\n");
exit (EXIT_NORMAL);
}
/*****************************************************************************/
int GetPathFileA (void)
/*****************************************************************************/
{
int iFound;
DIR *dDir;
struct dirent *stDirent;
char sExtension[100 + 2];
char sWarning[MAX_WARNING + 2];
int iFd;
int iVerify[10 + 2];
iFound = 0;
dDir = opendir (DISK_DIR_A);
if (dDir == NULL)
{
printf ("[ WARN ] Cannot open directory \"%s\": %s!\n",
DISK_DIR_A, strerror (errno));
return (0);
}
while ((stDirent = readdir (dDir)) != NULL)
{
if (iFound == 0)
{
if ((strcmp (stDirent->d_name, ".") != 0) &&
(strcmp (stDirent->d_name, "..") != 0))
{
snprintf (sExtension, 100, "%s", strrchr (stDirent->d_name, '.'));
if ((toupper (sExtension[1]) == 'P') &&
(toupper (sExtension[2]) == 'O'))
{
iFound = 1;
snprintf (sPathFileA, MAX_PATHFILE, "%s%s%s", DISK_DIR_A, SLASH,
stDirent->d_name);
if (iDebug == 1)
{
printf ("[ OK ] Found Apple II disk image \"%s\".\n",
sPathFileA);
}
}
}
}
}
closedir (dDir);
if (iFound == 0)
{
snprintf (sWarning, MAX_WARNING, "Cannot find a .po disk image in"
" directory \"%s\"!", DISK_DIR_A);
printf ("[ WARN ] %s\n", sWarning);
SDL_ShowSimpleMessageBox (SDL_MESSAGEBOX_ERROR,
"Warning", sWarning, NULL);
return (0);
}
/*** Is the file accessible? ***/
if (access (sPathFileA, R_OK|W_OK) == -1)
{
printf ("[ WARN ] Cannot access \"%s\": %s!\n",
sPathFileA, strerror (errno));
return (0);
}
/*** Which disk image: adamgreen (A0) or peterferrie (A1)? ***/
iDiskImageA = -1;
iFd = open (sPathFileA, O_RDONLY|O_BINARY);
if (iFd == -1)
{
printf ("[ WARN ] Could not open \"%s\": %s!\n",
sPathFileA, strerror (errno));
return (0);
}
/*** A0 version (adamgreen) ***/
if (iDiskImageA == -1)
{
iVerify[1] = Verify (iFd, A0_PRODOS_OFFSET_1, A0_PRODOS_TEXT);
iVerify[2] = Verify (iFd, A0_PRODOS_OFFSET_2, A0_PRODOS_TEXT);
iVerify[3] = Verify (iFd, A0_POP_OFFSET_1, A0_POP_TEXT);
iVerify[4] = Verify (iFd, A0_POP_OFFSET_2, A0_POP_TEXT);
if ((iVerify[1] == 1) && (iVerify[2] == 1) &&
(iVerify[3] == 1) && (iVerify[4] == 1))
{
iDiskImageA = 0;
PrIfDe ("[ INFO ] adamgreen (A0)\n");
}