-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPlatformAmiga.cpp
More file actions
2596 lines (2382 loc) · 82.9 KB
/
PlatformAmiga.cpp
File metadata and controls
2596 lines (2382 loc) · 82.9 KB
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 <proto/exec.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/dos.h>
#include <exec/libraries.h>
#include <exec/interrupts.h>
#include <exec/io.h>
#include <exec/memory.h>
#include <graphics/gfx.h>
#include <graphics/gfxbase.h>
#include <graphics/view.h>
#include <graphics/sprite.h>
#include <graphics/copper.h>
#include <graphics/gfxmacros.h>
#include <intuition/intuition.h>
#include <hardware/intbits.h>
#include <hardware/custom.h>
#include <hardware/cia.h>
#include <devices/audio.h>
#include "PT2.3F_replay_cia.h"
#ifdef PLATFORM_GZIP_SUPPORT
#include "ungzip.h"
#endif
#include "Palette.h"
#include "PlatformAmiga.h"
#include <stdio.h>
#include <stddef.h>
#define SCREEN_WIDTH PLATFORM_SCREEN_WIDTH
#define SCREEN_HEIGHT PLATFORM_SCREEN_HEIGHT
#define SCREEN_WIDTH_IN_BYTES (SCREEN_WIDTH >> 3)
#define SCREEN_SIZE (SCREEN_WIDTH_IN_BYTES * SCREEN_HEIGHT)
#ifdef PLATFORM_COLOR_SUPPORT
#define PLANES 4
#ifdef PLATFORM_GZIP_SUPPORT
#define LONGEST_FILENAME 25 // mod.metallic bop amiga.gz
#else
#define LONGEST_FILENAME 22 // mod.metallic bop amiga
#endif
#else
#define PLANES 1
#ifdef PLATFORM_GZIP_SUPPORT
#define LONGEST_FILENAME 10 // level-a.gz
#else
#define LONGEST_FILENAME 7 // level-a
#endif
#endif
#define SCREEN_PLANES_SIZE (SCREEN_SIZE * PLANES + 16 * 2)
#ifdef PLATFORM_IMAGE_BASED_TILES
#define TILES_PLANES_SIZE 0
#define TILES_WITH_MASK 12
#else
#define TILES_PLANES_SIZE (32 / 8 * 24 * PLANES * 256)
#define TILES_WITH_MASK 30
#endif
#define TILES_MASK_SIZE (32 / 8 * 24 * PLANES * TILES_WITH_MASK)
#define COMBINED_TILE_PLANES_SIZE (32 / 8 * 24 * PLANES)
#ifdef PLATFORM_MODULE_BASED_AUDIO
#define LARGEST_MODULE_SIZE 105654
#endif
#define CHIP_MEMORY_SIZE (SCREEN_PLANES_SIZE + TILES_PLANES_SIZE + TILES_MASK_SIZE + COMBINED_TILE_PLANES_SIZE)
#ifdef PLATFORM_PRELOAD_SUPPORT
#define PRELOADED_ASSETS_BUFFER_SIZE_MINIMUM (32032 + 32032 + 32032 + 69536 + 33792 + 17182)
#define PRELOADED_ASSETS_BUFFER_SIZE_ALL (PRELOADED_ASSETS_BUFFER_SIZE_MINIMUM + 71432 + 103754 + 105654 + 86504 + 14 * 8960)
#endif
#if PLATFORM_MAP_COUNT > 2
#ifdef INACTIVITY_TIMEOUT_GAME
static const char version[] = "$VER: Attack of the PETSCII Robots Arcade (2022-08-23)";
#else
static const char version[] = "$VER: Attack of the PETSCII Robots 1.3 (2022-08-23)";
#endif
#else
static const char version[] = "$VER: Attack of the PETSCII Robots Shareware (2022-08-23)";
#endif
struct SpriteData {
uint16_t posctl[2];
uint16_t data[28][2];
uint16_t reserved[2];
};
__far extern Custom custom;
__far extern CIA ciaa;
__far extern uint8_t tileset[];
__far extern uint8_t fontPlanes[];
__chip extern uint8_t facesPlanes[];
__chip extern uint8_t tilesPlanes[];
__chip extern uint8_t animTilesPlanes[];
__chip extern uint8_t spritesPlanes[];
__chip extern uint8_t spritesMask[];
__chip extern uint8_t itemsPlanes[];
__far extern uint8_t keysPlanes[];
__chip extern uint8_t healthPlanes[];
#ifdef INACTIVITY_TIMEOUT_INTRO
__far extern uint8_t attract1Planes[];
__far extern uint8_t attract2Planes[];
__far extern uint8_t attract3Planes[];
#endif
#ifdef PLATFORM_MODULE_BASED_AUDIO
__chip extern uint8_t soundFXModule[];
__chip extern int8_t soundExplosion[];
__chip extern int8_t soundMedkit[];
__chip extern int8_t soundEMP[];
__chip extern int8_t soundMagnet[];
__chip extern int8_t soundShock[];
__chip extern int8_t soundMove[];
__chip extern int8_t soundPlasma[];
__chip extern int8_t soundPistol[];
__chip extern int8_t soundItemFound[];
__chip extern int8_t soundError[];
__chip extern int8_t soundCycleWeapon[];
__chip extern int8_t soundCycleItem[];
__chip extern int8_t soundDoor[];
__chip extern int8_t soundMenuBeep[];
__chip extern int8_t soundShortBeep[];
#endif
__chip extern int8_t squareWave[];
__chip static int32_t simpleTileMask = 0xffffff00;
#ifdef PLATFORM_SPRITE_SUPPORT
__chip static SpriteData cursorData1 = {
{ 0, 0 },
{
{ 0xffff, 0 },
{ 0xffff, 0 },
{ 0xc000, 0 },
{ 0xc000, 0 },
{ 0xc000, 0 },
{ 0xc000, 0 },
{ 0xc000, 0 },
{ 0xc000, 0 },
{ 0xc000, 0 },
{ 0xc000, 0 },
{ 0xc000, 0 },
{ 0xc000, 0 },
{ 0xc000, 0 },
{ 0xc000, 0 },
{ 0xc000, 0 },
{ 0xc000, 0 },
{ 0xc000, 0 },
{ 0xc000, 0 },
{ 0xc000, 0 },
{ 0xc000, 0 },
{ 0xc000, 0 },
{ 0xc000, 0 },
{ 0xc000, 0 },
{ 0xc000, 0 },
{ 0xc000, 0 },
{ 0xc000, 0 },
{ 0xffff, 0 },
{ 0xffff, 0 }
},
{ 0, 0 }
};
__chip static SpriteData cursorData2 = {
{ 0, 0 },
{
{ 0xfff0, 0 },
{ 0xfff0, 0 },
{ 0x0030, 0 },
{ 0x0030, 0 },
{ 0x0030, 0 },
{ 0x0030, 0 },
{ 0x0030, 0 },
{ 0x0030, 0 },
{ 0x0030, 0 },
{ 0x0030, 0 },
{ 0x0030, 0 },
{ 0x0030, 0 },
{ 0x0030, 0 },
{ 0x0030, 0 },
{ 0x0030, 0 },
{ 0x0030, 0 },
{ 0x0030, 0 },
{ 0x0030, 0 },
{ 0x0030, 0 },
{ 0x0030, 0 },
{ 0x0030, 0 },
{ 0x0030, 0 },
{ 0x0030, 0 },
{ 0x0030, 0 },
{ 0x0030, 0 },
{ 0x0030, 0 },
{ 0xfff0, 0 },
{ 0xfff0, 0 }
},
{ 0, 0 }
};
#ifdef PLATFORM_CURSOR_SHAPE_SUPPORT
static uint16_t cursorUseData1[24] = {
0xc000,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000
};
static uint16_t cursorUseData2[24] = {
0x0030,
0x0030,
0x0030,
0x0030,
0x0030,
0x0030,
0x0030,
0x0030,
0x0030,
0x0030,
0x0030,
0x0030,
0x0030,
0x0030,
0x0030,
0x0030,
0x0030,
0x0030,
0x0030,
0x0030,
0x0030,
0x0030,
0x0030,
0x0030
};
static uint16_t cursorSearchData1[24] = {
0xc000,
0xc000,
0xc000,
0xc000,
0xc0f8,
0xc18e,
0xc303,
0xc609,
0xc609,
0xc601,
0xc601,
0xc303,
0xc303,
0xc18f,
0xc0f8,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000,
0xc000
};
static uint16_t cursorSearchData2[24] = {
0x0030,
0x0030,
0x0030,
0x0030,
0x0030,
0x0030,
0x0030,
0x8030,
0x8030,
0x8030,
0x8030,
0x0030,
0x0030,
0x8030,
0xc030,
0x6030,
0x3030,
0x1830,
0x0c30,
0x0630,
0x0030,
0x0030,
0x0030,
0x0030
};
static uint16_t cursorMoveData1[24] = {
0xc000,
0xc000,
0xc00c,
0xc013,
0xc072,
0xc092,
0xc092,
0xc092,
0xc092,
0xc192,
0xc292,
0xc280,
0xc280,
0xc280,
0xc200,
0xc300,
0xc100,
0xc100,
0xc080,
0xc080,
0xc040,
0xc07f,
0xc000,
0xc000
};
static uint16_t cursorMoveData2[24] = {
0x0030,
0x0030,
0x0030,
0x8030,
0x4030,
0x7030,
0x4830,
0x4830,
0x4830,
0x4830,
0x4830,
0x4830,
0x0830,
0x0830,
0x1030,
0x1030,
0x1030,
0x2030,
0x2030,
0x4030,
0x4030,
0xc030,
0x0030,
0x0030
};
#endif
#endif
__chip static uint16_t pointer[4];
uint16_t addressMap[SCREEN_WIDTH_IN_CHARACTERS * SCREEN_HEIGHT_IN_CHARACTERS];
static uint8_t tileMaskMap[256];
#ifdef PLATFORM_SPRITE_SUPPORT
static int8_t tileSpriteMap[256] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
0, 1, 49, 50, 57, 58, 59, 60, -1, -1, -1, -1, -1, -1, -1, 48,
-1, -1, -1, 73, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1, 0, 3, -1, 53, 54, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, 76, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
};
#endif
static int8_t animTileMap[256] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 16,
-1, -1, -1, -1, 4, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, 8, 10, -1, -1, 12, 14, -1, -1, 20, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
};
#ifdef PLATFORM_IMAGE_SUPPORT
static uint16_t blackPalette[16] = { 0 };
#else
static uint16_t blackPalette[16] = { 0x000, 0x0f0, 0x0f0, 0x0f0, 0x0f0, 0x0f0, 0x0f0, 0x0f0, 0x0f0, 0x0f0, 0x0f0, 0x0f0, 0x0f0, 0x0f0, 0x0f0, 0x0f0 };
#endif
static char MAPNAME[] = "level-a";
#ifdef PLATFORM_IMAGE_SUPPORT
static const char* imageFilenames[] = {
"IntroScreen.raw",
"GameScreen.raw",
"GameOver.raw"
};
#endif
#ifdef PLATFORM_MODULE_BASED_AUDIO
static const char* moduleFilenames[] = {
"mod.metal heads",
"mod.win",
"mod.lose",
"mod.metallic bop amiga",
"mod.get psyched",
"mod.robot attack",
"mod.rushin in"
};
#endif
static char* notEnoughMemoryError = "Not enough memory to run\n";
#ifdef PLATFORM_MODULE_BASED_AUDIO
static char* notEnoughMemoryForMusic = "Not enough memory for music\n";
#endif
static char* unableToInitializeDisplayError = "Unable to initialize display\n";
static char* unableToInitializeAudioError = "Unable to initialize audio\n";
static char* unableToLoadDataError = "Unable to load data\n";
static uint8_t standardControls[] = {
0x17, // MOVE UP orig: 56 (8)
0x27, // MOVE DOWN orig: 50 (2)
0x26, // MOVE LEFT orig: 52 (4)
0x28, // MOVE RIGHT orig: 54 (6)
0x11, // FIRE UP
0x21, // FIRE DOWN
0x20, // FIRE LEFT
0x22, // FIRE RIGHT
0x50, // CYCLE WEAPONS
0x51, // CYCLE ITEMS
0x40, // USE ITEM
0x31, // SEARCH OBEJCT
0x37, // MOVE OBJECT
0x42, // LIVE MAP
#if PLATFORM_MAP_COUNT > 2
0xc2, // LIVE MAP ROBOTS
#else
0x7f,
#endif
0x45, // PAUSE
0x55, // MUSIC
#if PLATFORM_MAP_COUNT > 2
0xb3, // CHEAT
#else
0x7f,
#endif
0x4c, // CURSOR UP
0x4d, // CURSOR DOWN
0x4f, // CURSOR LEFT
0x4e, // CURSOR RIGHT
0x40, // SPACE
0x44, // RETURN
#ifdef INACTIVITY_TIMEOUT_GAME
0x4f, // YES
0x4e // NO
#else
0x15, // YES
0x36 // NO
#endif
};
#ifdef PLATFORM_LIVE_MAP_SUPPORT
#define LIVE_MAP_ORIGIN_X 0
#define LIVE_MAP_WIDTH (128 * 2)
#define LIVE_MAP_ORIGIN_Y ((PLATFORM_SCREEN_HEIGHT - 32 - 64 * 2) / 2)
uint8_t tileLiveMap[] = {
0,13, 1, 1, 1, 1, 1, 1, 1, 5, 1, 1, 1, 1,13, 1,
1, 1, 1, 1, 1, 1, 1, 2, 8, 1, 1, 1, 1, 6,14,14,
15,13,14,15,15,13, 5,15, 6,13,13,12, 6,13,13,12,
1, 1, 1,12, 1, 9, 9, 6, 1, 9,15, 6,10,10, 1, 1,
1, 1, 7,13, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
2, 2,13,13,13,13,13,13, 1, 1, 1,13, 4, 4, 4, 0,
1, 1, 4,13, 4, 4, 4, 1, 1, 1, 2, 2, 2, 2, 2, 2,
1, 1,13,10, 1, 1,13, 9, 1, 1, 4, 5,13,13,13, 4,
1, 1, 1, 1,15, 5,15,15, 1, 1, 6, 6,15,15, 6, 5,
2, 2, 2, 5,13,13, 1, 7, 5, 3, 1, 7, 4, 4, 4,13,
1, 1, 1, 1, 1, 4, 4, 2, 3, 3, 3, 1, 3, 2, 3, 3,
3, 3, 3, 1, 4, 4, 9, 9, 4, 4, 2, 2, 5,11,12,12,
8, 8, 8, 9, 3, 3, 2,10, 1, 1, 1, 9, 1, 1, 1,10,
1, 1, 1,13, 8, 8,13,13, 8, 8,13,13, 3, 3,13,13,
13,13, 5,13,13,13,13,13,13,13,13,13,13,13,13,13
};
uint8_t liveMapToPlane1[256];
uint8_t liveMapToPlane2[256];
uint8_t liveMapToPlane3[256];
uint8_t liveMapToPlane4[256];
uint8_t unitTypes[48];
uint8_t unitX[48];
uint8_t unitY[48];
#else
uint8_t tileLiveMap[1];
uint8_t liveMapToPlane1[1];
uint8_t liveMapToPlane3[1];
#endif
#if PLATFORM_MAP_COUNT == 2
static char demoText[] =
" attack of the petscii robots amiga "
"shareware version is free to distribute "
" "
" you can download a free copy of the "
" user's manual or buy the full version "
" at www.the8bitguy.com "
" "
" *** full version includes *** "
" "
" - all 14 levels "
" "
" - 4 different in-game tunes "
" "
" - cd32 controller support "
" "
" - hotkey for robot locations "
" "
" - customizable keyboard controls "
" "
" - pet graphics and sound version "
" "
" - get rid of this nagging screen "
" "
" "
" press any key to continue ";
extern void convertToPETSCII(char* string);
#endif
PlatformAmiga::PlatformAmiga() :
framesPerSecond_((GfxBase->DisplayFlags & PAL) ? 50 : 60),
clock((GfxBase->DisplayFlags & PAL) ? 3546895 : 3579545),
originalDirectoryLock(-1),
screenBitmap(new BitMap),
screen(0),
window(0),
interrupt(0),
verticalBlankInterrupt(new Interrupt),
chipMemory(0),
screenPlanes(0),
#ifndef PLATFORM_IMAGE_BASED_TILES
tilesPlanes(0),
#endif
tilesMask(0),
combinedTilePlanes(0),
#ifdef PLATFORM_MODULE_BASED_AUDIO
moduleData(0),
loadedModule(ModuleSoundFX),
#endif
#ifdef PLATFORM_IMAGE_SUPPORT
loadedImage(ImageIntro),
#endif
ioAudio(0),
messagePort(0),
tilesBitMap(new BitMap),
#ifdef PLATFORM_IMAGE_SUPPORT
facesBitMap(new BitMap),
itemsBitMap(new BitMap),
healthBitMap(new BitMap),
#endif
#ifdef PLATFORM_CURSOR_SUPPORT
cursorSprite1(new SimpleSprite),
cursorSprite2(new SimpleSprite),
#endif
palette(new Palette(blackPalette, (1 << PLANES), 0)),
loadBuffer(0),
#ifdef PLATFORM_PRELOAD_SUPPORT
preloadedAssetBuffer(0),
#endif
#if defined(INACTIVITY_TIMEOUT_INTRO) || defined(INACTIVITY_TIMEOUT_GAME)
framesIdle(0),
#endif
#ifdef INACTIVITY_TIMEOUT_INTRO
userCopperList(0),
highlightedMenuRowPalette(new Palette(palette->palette() + 14, 1, 15)),
explosionPalette(new Palette(palette->palette() + 9, 6, 15)),
highlightedMenuRowFadeDelta(-1),
explosionFadeDelta(-1),
explosionFadeWait(0),
attractImageX(0),
attractImageY(0),
#endif
bplcon1DefaultValue(0),
shakeStep(0),
keyToReturn(0xff),
downKey(0xff),
shift(0),
joystickStateToReturn(0),
joystickState(0),
pendingState(0),
filterState(ciaa.ciapra & CIAF_LED ? true : false)
#ifdef PLATFORM_MODULE_BASED_AUDIO
,
effectChannel(0)
#endif
{
Palette::initialize();
for (int y = 0, i = 0; y < SCREEN_HEIGHT_IN_CHARACTERS; y++) {
for (int x = 0; x < SCREEN_WIDTH_IN_CHARACTERS; x++, i++) {
addressMap[i] = y * SCREEN_WIDTH_IN_BYTES * PLANES * 8 + x;
}
}
#ifdef PLATFORM_LIVE_MAP_SUPPORT
for (i = 0; i < 256; i++) {
uint8_t plane1 = 0;
uint8_t plane2 = 0;
uint8_t plane3 = 0;
uint8_t plane4 = 0;
if (i & 1) {
plane1 |= 0x03;
}
if (i & 2) {
plane2 |= 0x03;
}
if (i & 4) {
plane3 |= 0x03;
}
if (i & 8) {
plane4 |= 0x03;
}
if (i & 16) {
plane1 |= 0x0c;
}
if (i & 32) {
plane2 |= 0x0c;
}
if (i & 64) {
plane3 |= 0x0c;
}
if (i & 128) {
plane4 |= 0x0c;
}
liveMapToPlane1[i] = plane1;
liveMapToPlane2[i] = plane2;
liveMapToPlane3[i] = plane3;
liveMapToPlane4[i] = plane4;
}
#endif
BPTR dataLock = Lock("Data", ACCESS_READ);
if (!dataLock) {
Write(Output(), unableToLoadDataError, 20);
return;
}
originalDirectoryLock = CurrentDir(dataLock);
chipMemory = (uint8_t*)AllocMem(CHIP_MEMORY_SIZE, MEMF_CHIP | MEMF_CLEAR);
if (!chipMemory) {
Write(Output(), notEnoughMemoryError, 25);
return;
}
uint8_t* address = chipMemory;
screenPlanes = address;
address += SCREEN_PLANES_SIZE;
#ifndef PLATFORM_IMAGE_BASED_TILES
tilesPlanes = address;
address += TILES_PLANES_SIZE;
#endif
tilesMask = address;
address += TILES_MASK_SIZE;
combinedTilePlanes = address;
#ifdef PLATFORM_MODULE_BASED_AUDIO
moduleData = (uint8_t*)AllocMem(LARGEST_MODULE_SIZE, MEMF_CHIP | MEMF_CLEAR);
if (moduleData) {
loadBuffer = new uint8_t[59884];
if (!loadBuffer) {
Write(Output(), notEnoughMemoryForMusic, 28);
FreeMem(moduleData, LARGEST_MODULE_SIZE);
moduleData = 0;
}
} else {
Write(Output(), notEnoughMemoryForMusic, 28);
}
#endif
if (!loadBuffer) {
loadBuffer = new uint8_t[14351];
if (!loadBuffer) {
Write(Output(), notEnoughMemoryError, 25);
return;
}
}
#ifdef PLATFORM_PRELOAD_SUPPORT
preloadAssets();
#endif
InitBitMap(screenBitmap, PLANES, SCREEN_WIDTH, SCREEN_HEIGHT);
screenBitmap->Flags = BMF_DISPLAYABLE | BMF_INTERLEAVED;
screenBitmap->BytesPerRow = SCREEN_WIDTH_IN_BYTES * PLANES;
InitBitMap(tilesBitMap, PLANES, 32, 24 * 253);
tilesBitMap->Flags = BMF_DISPLAYABLE | BMF_INTERLEAVED;
tilesBitMap->BytesPerRow = 4 * PLANES;
#ifdef PLATFORM_IMAGE_SUPPORT
InitBitMap(facesBitMap, PLANES, 16, 24 * 3);
facesBitMap->Flags = BMF_DISPLAYABLE | BMF_INTERLEAVED;
facesBitMap->BytesPerRow = 2 * PLANES;
InitBitMap(itemsBitMap, PLANES, 48, 21 * 6);
itemsBitMap->Flags = BMF_DISPLAYABLE | BMF_INTERLEAVED;
itemsBitMap->BytesPerRow = 6 * PLANES;
InitBitMap(healthBitMap, PLANES, 48, 51 * 6);
healthBitMap->Flags = BMF_DISPLAYABLE | BMF_INTERLEAVED;
healthBitMap->BytesPerRow = 6 * PLANES;
#endif
uint8_t* screenPlane = screenPlanes;
uint8_t* tilesPlane = tilesPlanes;
#ifdef PLATFORM_IMAGE_SUPPORT
uint8_t* facesPlane = facesPlanes;
uint8_t* itemsPlane = itemsPlanes;
uint8_t* healthPlane = healthPlanes;
#endif
for (int plane = 0; plane < PLANES; plane++, screenPlane += SCREEN_WIDTH_IN_BYTES, tilesPlane += 4
#ifdef PLATFORM_IMAGE_SUPPORT
, facesPlane += 2, itemsPlane += 6, healthPlane += 6
#endif
) {
screenBitmap->Planes[plane] = screenPlane;
tilesBitMap->Planes[plane] = tilesPlane;
#ifdef PLATFORM_IMAGE_SUPPORT
facesBitMap->Planes[plane] = facesPlane;
itemsBitMap->Planes[plane] = itemsPlane;
healthBitMap->Planes[plane] = healthPlane;
#endif
}
ExtNewScreen newScreen = {0};
Screen workbenchScreen;
GetScreenData(&workbenchScreen, sizeof(Screen), WBENCHSCREEN, 0);
if (workbenchScreen.ViewPort.Modes & HIRES && workbenchScreen.ViewPort.DWidth > 640 && workbenchScreen.ViewPort.DWidth <= 724) {
newScreen.LeftEdge = (workbenchScreen.ViewPort.DWidth - 640) >> 1;
}
newScreen.Width = SCREEN_WIDTH;
newScreen.Height = SCREEN_HEIGHT;
newScreen.Depth = PLANES;
newScreen.ViewModes = SPRITES;
newScreen.Type = CUSTOMBITMAP | CUSTOMSCREEN | SCREENBEHIND | SCREENQUIET;
newScreen.DefaultTitle = (UBYTE*)"Attack of the PETSCII Robots";
newScreen.CustomBitMap = screenBitmap;
screen = OpenScreen((NewScreen*)&newScreen);
if (!screen) {
Write(Output(), unableToInitializeDisplayError, 29);
return;
}
LoadRGB4(&screen->ViewPort, blackPalette, (1 << PLANES));
SetAPen(&screen->RastPort, 0);
ExtNewWindow newWindow = {0};
newWindow.Width = SCREEN_WIDTH;
newWindow.Height = SCREEN_HEIGHT;
newWindow.Flags = WFLG_SIMPLE_REFRESH | WFLG_BACKDROP | WFLG_BORDERLESS | WFLG_RMBTRAP;
newWindow.IDCMPFlags = IDCMP_RAWKEY;
newWindow.Screen = screen;
newWindow.Type = CUSTOMSCREEN;
window = OpenWindow((NewWindow*)&newWindow);
if (!window) {
Write(Output(), unableToInitializeDisplayError, 29);
return;
}
SetPointer(window, pointer, 0, 0, 0, 0);
#if PLATFORM_MAP_COUNT == 2
SetRGB4(&screen->ViewPort, 1, 0, 15, 0);
SetAPen(&screen->RastPort, 1);
convertToPETSCII(demoText);
for (i = 0; i < 21; i++) {
demoText[8 * 40 + 9 + i] = 0x63;
}
for (i = 0; i < 1000; i++) {
uint8_t* source = fontPlanes + (demoText[i] << 3);
uint8_t* destination = screenPlanes + addressMap[i];
for (int y = 0; y < 8; y++, destination += PLANES * SCREEN_WIDTH_IN_BYTES) {
*destination = *source++;
}
}
ScreenToFront(screen);
ActivateWindow(window);
uint32_t windowSignal = 1L << window->UserPort->mp_SigBit;
for (bool done = false; !done;) {
uint32_t signals = Wait(windowSignal);
if (signals & windowSignal) {
IntuiMessage* message;
while ((message = (IntuiMessage*)GetMsg(window->UserPort))) {
uint32_t messageClass = message->Class;
uint16_t messageCode = message->Code;
ReplyMsg((Message*)message);
if (messageClass == IDCMP_RAWKEY && messageCode < 0x80) {
done = true;
}
}
}
}
SetRGB4(&screen->ViewPort, 1, 0, 0, 0);
SetAPen(&screen->RastPort, 0);
WaitTOF();
#endif
#ifdef PLATFORM_CURSOR_SUPPORT
GetSprite(cursorSprite1, 2);
GetSprite(cursorSprite2, 3);
#endif
#ifdef INACTIVITY_TIMEOUT_INTRO
userCopperList = (UCopList *)AllocMem(sizeof(UCopList), MEMF_PUBLIC | MEMF_CLEAR);
CINIT(userCopperList, 11);
CWAIT(userCopperList, 20, 0);
CMOVE(userCopperList, custom.color[15], 0);
CWAIT(userCopperList, 28, 0);
CMOVE(userCopperList, custom.color[15], 0);
CWAIT(userCopperList, 143, 0);
CMOVE(userCopperList, custom.color[9], 0);
CMOVE(userCopperList, custom.color[10], 0);
CMOVE(userCopperList, custom.color[11], 0);
CMOVE(userCopperList, custom.color[12], 0);
CMOVE(userCopperList, custom.color[13], 0);
CMOVE(userCopperList, custom.color[14], 0);
CEND(userCopperList);
#endif
verticalBlankInterrupt->is_Node.ln_Type = NT_INTERRUPT;
verticalBlankInterrupt->is_Node.ln_Pri = 127;
verticalBlankInterrupt->is_Node.ln_Name = "Attack of the PETSCII Robots VBI";
verticalBlankInterrupt->is_Data = this;
verticalBlankInterrupt->is_Code = (__stdargs void(*)())&verticalBlankInterruptServer;
AddIntServer(INTB_VERTB, verticalBlankInterrupt);
messagePort = CreatePort(NULL, 0);
if (!messagePort) {
Write(Output(), unableToInitializeAudioError, 27);
return;
}
ioAudio = new IOAudio;
ioAudio->ioa_Request.io_Message.mn_ReplyPort = messagePort;
ioAudio->ioa_Request.io_Message.mn_Node.ln_Pri = 127;
ioAudio->ioa_Request.io_Command = ADCMD_ALLOCATE;
ioAudio->ioa_Request.io_Flags = ADIOF_NOWAIT;
#ifdef PLATFORM_MODULE_BASED_AUDIO
// Allocate all channels
uint8_t requestChannels[1] = { 15 };
ioAudio->ioa_Data = requestChannels;
ioAudio->ioa_Length = 1;
if (OpenDevice((UBYTE*)AUDIONAME, 0, (IORequest*)ioAudio, 0)) {
Write(Output(), unableToInitializeAudioError, 27);
return;
}
// Clear the first two bytes of effect samples to enable the 2-byte no-loop loop
*((uint16_t*)soundExplosion) = 0;
*((uint16_t*)soundMedkit) = 0;
*((uint16_t*)soundEMP) = 0;
*((uint16_t*)soundMagnet) = 0;
*((uint16_t*)soundShock) = 0;
*((uint16_t*)soundMove) = 0;
*((uint16_t*)soundPlasma) = 0;
*((uint16_t*)soundPistol) = 0;
*((uint16_t*)soundItemFound) = 0;
*((uint16_t*)soundError) = 0;
*((uint16_t*)soundCycleWeapon) = 0;
*((uint16_t*)soundCycleItem) = 0;
*((uint16_t*)soundDoor) = 0;
*((uint16_t*)soundMenuBeep) = 0;
*((uint16_t*)soundShortBeep) = 0;
setSampleData(soundFXModule);
SetCIAInt();
disableLowpassFilter();
#else
// Don't care which channel gets allocated
uint8_t requestChannels[4] = { 1, 8, 2, 4 };
ioAudio->ioa_Data = requestChannels;
ioAudio->ioa_Length = 4;
if (OpenDevice((UBYTE*)AUDIONAME, 0, (IORequest*)ioAudio, 0)) {
Write(Output(), unableToInitializeAudioError, 27);
return;
}
ioAudio->ioa_Request.io_Command = CMD_WRITE;
ioAudio->ioa_Request.io_Flags = ADIOF_PERVOL | IOF_QUICK;
ioAudio->ioa_Volume = 0;
ioAudio->ioa_Cycles = 0;
ioAudio->ioa_Data = (uint8_t*)squareWave;
ioAudio->ioa_Length = 2;
ioAudio->ioa_Period = (uint16_t)(clock / 440 / 2);
BeginIO((IORequest*)ioAudio);
ioAudio->ioa_Request.io_Command = ADCMD_PERVOL;
enableLowpassFilter();
#endif
custom.potgo = ((custom.potinp & 0x3fff) | 0xc000);
platform = this;
}
PlatformAmiga::~PlatformAmiga()
{
if (ioAudio && ioAudio->ioa_Request.io_Device) {
#ifdef PLATFORM_MODULE_BASED_AUDIO
stopModule();
ResetCIAInt();
if (filterState) {
enableLowpassFilter();
}
#else
AbortIO((IORequest*)ioAudio);
if (!filterState) {
disableLowpassFilter();
}
#endif
CloseDevice((IORequest*)ioAudio);
}
if (messagePort) {
DeletePort(messagePort);
}
if (verticalBlankInterrupt->is_Data == this) {
RemIntServer(INTB_VERTB, verticalBlankInterrupt);
}
#ifdef INACTIVITY_TIMEOUT_INTRO
if (screen && screen->ViewPort.UCopIns) {
screen->ViewPort.UCopIns = 0;
RethinkDisplay();
}
if (userCopperList) {
FreeCopList(userCopperList->FirstCopList);
FreeMem(userCopperList, sizeof(UCopList));
}
#endif
#ifdef PLATFORM_CURSOR_SUPPORT
if (cursorSprite2->num != -1) {
FreeSprite(cursorSprite2->num);
}
if (cursorSprite1->num != -1) {
FreeSprite(cursorSprite1->num);
}
#endif
if (window) {
CloseWindow(window);
}
if (screen) {
CloseScreen(screen);
}
#ifdef PLATFORM_MODULE_BASED_AUDIO
if (moduleData) {
FreeMem(moduleData, LARGEST_MODULE_SIZE);
}
#endif
if (chipMemory) {
FreeMem(chipMemory, CHIP_MEMORY_SIZE);
}
if (originalDirectoryLock != -1) {
UnLock(CurrentDir(originalDirectoryLock));
}
#ifdef INACTIVITY_TIMEOUT_INTRO
delete explosionPalette;
delete highlightedMenuRowPalette;
#endif
delete[] loadBuffer;
delete palette;
#ifdef PLATFORM_CURSOR_SUPPORT
delete cursorSprite2;
delete cursorSprite1;