-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlatformGameEngine.Asc
1394 lines (1193 loc) · 34.2 KB
/
PlatformGameEngine.Asc
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
'Dual Playfield Tile Scroller Platform Game Engine For AmosPro
'Author: Alper Sönmez (06.04.2021) v0.34
'Background graphics: Amatnieks (aamatniekss.itch.io)
'Sprite graphics: Legnops (legnops.itch.io)
Set Buffer 24
Gosub _INIT_VARIABLES
PREP_SCREEN_BITMAPS
Load "Tileset.abk",2
Gosub _READ_MAP
CUSTOM_SPRITE_LOAD["sprites.spr"]
Copper Off
CUSTOM_COPPER_LIST
INIT_FADE
_FADE=IN
Gosub _FILL_SCREEN
'Main Loop
'*********
Do
_TIMER=Timer
_ODD_FRAME=Btst(0,_TIMER)
If PL_Y>200 Then Goto QUIT
If Key State($4C)=True
Gosub _JUMP
End If
If Key State($4D)=True
End If
If Key State($4E)=True
Gosub _GO_RIGHT
Else If Key State($4F)=True
Gosub _GO_LEFT
Else
Gosub _IDLE
End If
If Key State($45)=True and _FADE=0
_FADE=OUT
End If
Gosub _DO_ANIM
Gosub _VBL_ACTIONS
Loop
QUIT:
'Production state code -- You can remove below 3 before release
'*********************
Copper On
Erase 2
Erase 5
'*********************
End
'***********
'Subroutines
'***********
_INIT_VARIABLES:
'Scroll Engine specific variables
'********************************
'Scroll Position: The amount of pixels the screen is scrolled right.
' With this implementation you can only initialize it
' to 0. :(
' SCR_MAX holds the maximum value for SCR_POS
SCR_POS=0
'Map Position: Indicates what column of map data is being displayed
' at the current SCR_POS. At SCR_POS=0, MAP_POS must be -1
' because of the way the algorithm is implemented.
' At SCR_POS=1 it is 1, at SCR_POS=16 it is still 1, yet
' at SCR_POS=17 it is 2... etc.
' MRR and MRC is calculated from MAP_POS.
' MRR: (M)ap (R)ead (R)ow, holds row of the next incoming
' tile to be filled from map data.
' MRC: (M)ap (R)ead (C)olumn, holds the current column
' of the map data the incoming tiles will be read.
MAP_POS=-1
'(N)ext (F)ill (R)ow: Holds the screen Y coordinate on the fill column
' for the next incoming tile to be filled.
NFR_Y=0
'(F)ill (C)olumn (L)eft: The screen X coordinate of the left fill column
' At SCR_POS=0 it must be initialized to 336.
' At SCR_POS=1 it becomes 0 as expected.
' At SCR_POS=16 it is still 0.
' At SCR_POS=17 it becomes 16.
' At SCR_POS=352 it becomes 0 again, and so on...
FCL_X=336
'Scroll speed: How many pixels to scroll with a call to _SCROLL_LEFT/RIGHT
SPEED=1
'An internal modulus value to be memorized after every scroll.
OLD_SCR_MOD=16
'Sprite Engine variables
'***********************
'Sprite Strobe Addresses
' 8 two LONGs of memory. Each first long will be a strobe register. The
' address held in it will be set to the corresponding sprite instruction
' on the copper list during the vertical blank (vbl) and after that will
' be set back to zero.
' Each 2nd LONG will hold the two control WORDs that will be poked into
' the corresponding sprite structure the 1st LONG points to.
' All this is to be able to do the sprite calculations during display
' and setting the results to the copper list only during vbl.
Dim _SPRITE_STROBE(15)
_SPRITE_STROBE_PT=Varptr(_SPRITE_STROBE(0))
'Color palette (values for all color instructions in the copper list)
'*************
' This implementation has 33 color instructions on the custom copper list
' it creates.
' A color value in ECS/OCS is 2 bytes. So WORDs are used to store
' them to conserve memory. Every array item in Amos is a LONG so we can
' store 2 color values per every item. One in 1st WORD other in the 2nd.
' The table is dimensioned as: 33/2=16 and traversed using a pointer.
' When new color instructions are added to the copper list, first thing
' to do is to update the value below. Otherwise memory will be trashed.
' Using the helper procedure DUMP_COPPER_COLORS is recommended.
_COLOR_INSTRUCTIONS=33
Dim _COLOR_TABLE(_COLOR_INSTRUCTIONS/2)
_COLOR_TABLE_PT=Varptr(_COLOR_TABLE(0))
_COLOR_TABLE(0)=$58D07AD
_COLOR_TABLE(1)=$ACE0386
_COLOR_TABLE(2)=$DEF0255
_COLOR_TABLE(3)=$7BA05A7
_COLOR_TABLE(4)=$446
_COLOR_TABLE(5)=$CE40212
_COLOR_TABLE(6)=$5320963
_COLOR_TABLE(7)=$18406C1
_COLOR_TABLE(8)=$111
_COLOR_TABLE(9)=$AAA0822
_COLOR_TABLE(10)=$2010221
_COLOR_TABLE(11)=$4010534
_COLOR_TABLE(12)=$6440554
_COLOR_TABLE(13)=$6550755
_COLOR_TABLE(14)=$A540A64
_COLOR_TABLE(15)=$9880A99
_COLOR_TABLE(16)=$0
'FADE ENGINE variables
'*********************
' _FADE_TABLE() holds precalculated increment and current state values
' for the 3 components of all color values for all color instructions
' in the copper list (yes we fade the Rainbows too).
' So it will use a fair amount of memory if the copper is rich with color
' instructions. But this is essential to be able to calculate every fade
' step using only lookups and additions.
Dim _FADE_TABLE(_COLOR_INSTRUCTIONS*3)
_FADE_TABLE_PT=Varptr(_FADE_TABLE(0))
'FADE_STEPS determines fade speed (in how many frames the fade will take)
' It can be minimum 1 and maximum 256!
_FADE_STEPS=20
'Setting variable _FADE to one of the below will start a fade (in or out)
IN=_FADE_STEPS
OUT=-_FADE_STEPS
R=0 : Rem Red component of the color value
G=0 : Rem Green component of the color value
B=0 : Rem Blue component of the color value
W=0 : Rem (4 bytes of) work buffer
'Some pointers to 3rd byte of each above variables
W3=Varptr(W)+2
R3=Varptr(R)+2
G3=Varptr(G)+2
B3=Varptr(B)+2
'Player Animation specific values
'*********************************
'Player direction (only used in sprite animations)
RIGHT=1
LEFT=0
PL_DIRECTION=RIGHT
'Player states
STANDING=0
WALKING=1
JUMPING=2
FALLING=3
LANDING=4
PL_STATE=STANDING
'Jump animation acceleration values
Dim _JUMP_ACCEL(8)
_JUMP_ACCEL(0)=0
_JUMP_ACCEL(1)=0
_JUMP_ACCEL(2)=-8
_JUMP_ACCEL(3)=-7
_JUMP_ACCEL(4)=-6
_JUMP_ACCEL(5)=-5
_JUMP_ACCEL(6)=-4
_JUMP_ACCEL(7)=-3
_JUMP_ACCEL(8)=-1
'Fall animation acceleration values
Dim _FALL_ACCEL(10)
_FALL_ACCEL(0)=1
_FALL_ACCEL(1)=3
_FALL_ACCEL(2)=4
_FALL_ACCEL(3)=5
_FALL_ACCEL(4)=6
_FALL_ACCEL(5)=7
_FALL_ACCEL(6)=8
_FALL_ACCEL(7)=10
_FALL_ACCEL(8)=12
_FALL_ACCEL(9)=14
_FALL_ACCEL(10)=16 : Rem Warning! Can not go more than tile height!!!
'Sprite image bank specific values
IMG_IDLE_STR_R=0
IMG_IDLE_END_R=17
IMG_IDLE_STR_L=61
IMG_IDLE_END_L=78
IMG_WALK_STR_R=18
IMG_WALK_END_R=41
IMG_WALK_STR_L=79
IMG_WALK_END_L=102
IMG_JUMP_STR_R=42
IMG_JUMP_END_R=50
IMG_JUMP_STR_L=103
IMG_JUMP_END_L=111
IMG_FALL_STR_R=51
IMG_FALL_END_R=55
IMG_FALL_RPT_R=54
IMG_FALL_STR_L=112
IMG_FALL_END_L=116
IMG_FALL_RPT_L=115
IMG_LAND_STR_R=57
IMG_LAND_END_R=60
IMG_LAND_STR_L=118
IMG_LAND_END_L=121
'Player sprite start coordinates
SCR_CENTER=146
PL_X=0
PL_Y=107
'Precalculated offsets for each foot of the player sprite image used in
' detecting if the player is standing on a platform.
' Values depend on the player image artwork.
_LEFT_FOOT=27
_RIGHT_FOOT=33
'TILESET SPECIFIC values
'***********************
' Tile TS_PLATFORM and ahead will be treated as platforms which player
' can stand on. This value is specific to the tileset. So obviously the
' the tileset must be ordered to have platform tiles to be contigous and
' in the end of the set.
TS_PLATFORM=42
Return
'Animation Subroutines
'*********************
_DO_ANIM:
'A dispatcher for all animation events
'Only animate on even frames
If _ODD_FRAME=False
If _OLD_DIRECTION<>PL_DIRECTION
If PL_DIRECTION=RIGHT
'IMG_IDLE_STR_L is the first image that is facing left
'All images before that are facing right
Add IMG_NUM,-IMG_IDLE_STR_L
Else
Add IMG_NUM,IMG_IDLE_STR_L
End If
End If
_OLD_DIRECTION=PL_DIRECTION
If PL_STATE=STANDING
Gosub _DO_IDLE
Else If PL_STATE=WALKING
Gosub _DO_WALK
Gosub _CHECK_PLATFORM
Else If PL_STATE=JUMPING
Gosub _DO_JUMP
Else If PL_STATE=FALLING
Gosub _DO_FALL
Gosub _CHECK_PLATFORM
Else If PL_STATE=LANDING
Gosub _DO_LAND
Gosub _CHECK_PLATFORM
End If
End If
CUSTOM_SPRITE[0,IMG_NUM,PL_X,PL_Y]
Return
_IDLE:
If PL_STATE=WALKING
PL_STATE=STANDING
End If
Return
_DO_IDLE:
If PL_DIRECTION=RIGHT
If IMG_NUM>=IMG_IDLE_STR_R and IMG_NUM<=IMG_IDLE_END_R : Rem Already idling
Inc IMG_NUM
If IMG_NUM>IMG_IDLE_END_R
IMG_NUM=IMG_IDLE_STR_R
End If
Else
IMG_NUM=IMG_IDLE_STR_R
End If
Else
If IMG_NUM>=IMG_IDLE_STR_L and IMG_NUM<=IMG_IDLE_END_L : Rem Already idling
Inc IMG_NUM
If IMG_NUM>IMG_IDLE_END_L
IMG_NUM=IMG_IDLE_STR_L
End If
Else
IMG_NUM=IMG_IDLE_STR_L
End If
End If
Return
_GO_RIGHT:
PL_DIRECTION=RIGHT
'Corner case when the player is on the left edge of the map
If SCR_POS=0 and PL_X<SCR_CENTER
Inc PL_X
If PL_STATE>=JUMPING
Return
Else
PL_STATE=WALKING
Return
End If
End If
'Corner case when the player is on the right edge of the map
If SCR_POS=SCR_MAX
Inc PL_X
If PL_STATE>=JUMPING
Else
PL_STATE=WALKING
End If
If PL_X>288
PL_X=288
If PL_STATE=WALKING
PL_STATE=STANDING
End If
End If
Return
End If
Gosub _SCROLL_RIGHT
If PL_STATE>=JUMPING Then Return
PL_STATE=WALKING
Return
_GO_LEFT:
PL_DIRECTION=LEFT
'Corner case when the player is on the right edge of the map
If SCR_POS=SCR_MAX and PL_X>SCR_CENTER
Dec PL_X
If PL_STATE>=JUMPING
Return
Else
PL_STATE=WALKING
Return
End If
End If
'Corner case when the player is on the left edge of the map
If SCR_POS=0
Dec PL_X
If PL_STATE>=JUMPING
Else
PL_STATE=WALKING
End If
If PL_X<0
PL_X=0
If PL_STATE=WALKING
PL_STATE=STANDING
End If
End If
Return
End If
Gosub _SCROLL_LEFT
If PL_STATE>=JUMPING Then Return
PL_STATE=WALKING
Return
_DO_WALK:
If PL_DIRECTION=RIGHT
If IMG_NUM>=IMG_WALK_STR_R and IMG_NUM<=IMG_WALK_END_R : Rem Already walking
Inc IMG_NUM
If IMG_NUM>IMG_WALK_END_R
IMG_NUM=IMG_WALK_STR_R
End If
Else : Rem Was not walking
IMG_NUM=IMG_WALK_STR_R
End If
Else
If IMG_NUM>=IMG_WALK_STR_L and IMG_NUM<=IMG_WALK_END_L : Rem Already walking
Inc IMG_NUM
If IMG_NUM>IMG_WALK_END_L
IMG_NUM=IMG_WALK_STR_L
End If
Else : Rem Was not walking
IMG_NUM=IMG_WALK_STR_L
End If
End If
Return
_JUMP:
If PL_STATE<JUMPING
PL_STATE=JUMPING
_JUMP_INDEX=0
End If
Return
_DO_JUMP:
If PL_DIRECTION=RIGHT
If IMG_NUM>=IMG_JUMP_STR_R and IMG_NUM<=IMG_JUMP_END_R
Inc IMG_NUM
Inc _JUMP_INDEX
If IMG_NUM=IMG_JUMP_END_R
PL_STATE=FALLING
End If
Else
IMG_NUM=IMG_JUMP_STR_R
End If
Else
If IMG_NUM>=IMG_JUMP_STR_L and IMG_NUM<=IMG_JUMP_END_L
Inc IMG_NUM
Inc _JUMP_INDEX
If IMG_NUM=IMG_JUMP_END_L
PL_STATE=FALLING
End If
Else
IMG_NUM=IMG_JUMP_STR_L
End If
End If
Add PL_Y,_JUMP_ACCEL(_JUMP_INDEX)
Return
_DO_FALL:
If PL_DIRECTION=RIGHT
If IMG_NUM>=IMG_FALL_STR_R and IMG_NUM<=IMG_FALL_END_R
Inc IMG_NUM
Inc _FALL_INDEX
If IMG_NUM>IMG_FALL_END_R
IMG_NUM=IMG_FALL_RPT_R
End If
Else
IMG_NUM=IMG_FALL_STR_R
_FALL_INDEX=0
End If
Else
If IMG_NUM>=IMG_FALL_STR_L and IMG_NUM<=IMG_FALL_END_L
Inc IMG_NUM
Inc _FALL_INDEX
If IMG_NUM>IMG_FALL_END_L
IMG_NUM=IMG_FALL_RPT_L
End If
Else
IMG_NUM=IMG_FALL_STR_L
_FALL_INDEX=0
End If
End If
If _FALL_INDEX>10
_FALL_INDEX=10
End If
Add PL_Y,_FALL_ACCEL(_FALL_INDEX)
Return
_DO_LAND:
_FALL_INDEX=0
If PL_DIRECTION=RIGHT
If IMG_NUM>=IMG_LAND_STR_R and IMG_NUM<=IMG_LAND_END_R
Inc IMG_NUM
If IMG_NUM=IMG_LAND_END_R
PL_STATE=STANDING
End If
Else
IMG_NUM=IMG_LAND_STR_R
End If
Else
If IMG_NUM>=IMG_LAND_STR_L and IMG_NUM<=IMG_LAND_END_L
Inc IMG_NUM
If IMG_NUM=IMG_LAND_END_L
PL_STATE=STANDING
End If
Else
IMG_NUM=IMG_LAND_STR_L
End If
End If
Return
_READ_MAP:
Open In 1,"TestMap.txt"
Input #1,MAP_X_SIZE,MAP_Y_SIZE
MAP_MODULO=MAP_X_SIZE+2
Dim MAP(MAP_MODULO*MAP_Y_SIZE)
For R=0 To MAP_Y_SIZE-1
MAP(MAP_MODULO*R)=1
For C=1 To MAP_MODULO-2
Input #1,MAP(C+MAP_MODULO*R)
Next C
MAP(MAP_MODULO*(R+1)-1)=1
Next R
Close 1
SCR_MAX=MAP_X_SIZE*16-320
'Create correspondence table
Dim TABLE(17)
TABLE(0)=MAP_Y_SIZE
For I=1 To 15
TABLE(I)=((I*MAP_Y_SIZE)/16)
Next I
TABLE(16)=MAP_Y_SIZE
TABLE(17)=0
Return
_FILL_SCREEN:
Screen 1
For R=0 To MAP_Y_SIZE-1
For C=0 To 24
Paste Icon C*16,R*16,MAP(R*MAP_MODULO+C)
Next C
Next R
Return
_SCROLL_LEFT:
Add SCR_POS,-SPEED
If SCR_POS<0
DISTANCE=SPEED-(0-SCR_POS)
SCR_POS=0
Else
DISTANCE=SPEED
End If
SCR_MOD=SCR_POS mod 16
'TODO: Table this??
If SCR_MOD=0
P2HS=0
Else
P2HS=16-SCR_MOD
End If
MRC=MAP_POS
If OLD_SCR_MOD-DISTANCE<1
'Fill all incoming tiles for the current fill up column
COUNT=TABLE(OLD_SCR_MOD)
While COUNT>0
Dec MRR
Add NFR_Y,-16
Gosub _FILL_TILE
Dec COUNT
Wend
'Recalculate MAP_POS, MRC
Dec MAP_POS
Dec MRC
'Recalculate BPL pointers, FCR_X and FCL_X
Add BPL2,-2
Add BPL4,-2
Add BPL6,-2
If BPL2<BPL2PT
Add BPL2,44
Add BPL4,44
Add BPL6,44
End If
Add FCL_X,-16
If FCL_X<0
Add FCL_X,352
End If
FCR_X=FCL_X+352 : Rem 352=22*16
BPL2_UPD=True
'Reset NFR_Y and MRR
NFR_Y=192
MRR=MAP_Y_SIZE
OLD_SCR_MOD=0
End If
'Fill as much tiles needed for this screen position
COUNT=TABLE(OLD_SCR_MOD)-TABLE(SCR_MOD)
While COUNT>0
Dec MRR
Add NFR_Y,-16
Gosub _FILL_TILE
Dec COUNT
Wend
Gosub _SCROLL_APPLY
Return
_SCROLL_RIGHT:
Add SCR_POS,SPEED
If SCR_POS>SCR_MAX
DISTANCE=SPEED-(SCR_POS-SCR_MAX)
SCR_POS=SCR_MAX
Else
DISTANCE=SPEED
End If
SCR_MOD=SCR_POS mod 16
'TODO: Table this??
If SCR_MOD=0
P2HS=0
Else
P2HS=16-SCR_MOD
End If
MRC=MAP_POS+22
If DISTANCE+OLD_SCR_MOD>16
'Fill all incoming tiles for current fill up column
COUNT=MAP_Y_SIZE-TABLE(OLD_SCR_MOD)
While COUNT>0
Gosub _FILL_TILE
Inc MRR
Add NFR_Y,16
Dec COUNT
Wend
'Recalculate MAP_POS, MRC
Inc MAP_POS
Inc MRC
'Recalculate BPL pointers, FCR_X and FCL_X
Add BPL2,2
Add BPL4,2
Add BPL6,2
If BPL2>=BPL2PTM
Add BPL2,-44
Add BPL4,-44
Add BPL6,-44
End If
Add FCL_X,16
If FCL_X>=352
Add FCL_X,-352
End If
FCR_X=FCL_X+352 : Rem 352=22*16
BPL2_UPD=True
'Reset NFR_Y and MRR
NFR_Y=0
MRR=0
OLD_SCR_MOD=17
End If
'Fill as much tiles needed at this screen position
COUNT=TABLE(SCR_MOD)-TABLE(OLD_SCR_MOD)
While COUNT>0
Gosub _FILL_TILE
Inc MRR
Add NFR_Y,16
Dec COUNT
Wend
Gosub _SCROLL_APPLY
Return
_SCROLL_APPLY:
'Memorize the current SCR_MOD for future scroll calculations
'TODO: Table this?
If SCR_MOD=0
OLD_SCR_MOD=16
Else
OLD_SCR_MOD=SCR_MOD
End If
'Background scroll
'*****************
OLD_BG_POS=BG_POS+16
BG_POS=SCR_POS/2 : Rem Scroll Plane 1 half as fast
BG_POS=BG_POS mod 320
'Calculate new bitmap addresses
'TODO: Optimize using tables and use addition+margin check?
BG_SCR_MOD=BG_POS mod 16
If BG_SCR_MOD=0
P1HS=0
P1BPLO=((BG_POS/16)*2)
Else
P1HS=16-BG_SCR_MOD
P1BPLO=2+((BG_POS/16)*2)
End If
If BPL1<>BPL1PT+P1BPLO
BPL1_UPD=True
BPL1=BPL1PT+P1BPLO
BPL3=BPL3PT+P1BPLO
BPL5=BPL5PT+P1BPLO
End If
BPLCON1_VAL=P1HS+(P2HS*16)
SCRL_UPD=True
Return
_VBL_ACTIONS:
'By waiting the beam to pass line 192 (where our display ends in this
'implementation) instead of using Wait Vbl, we can begin to process our
'vbl actions earlier. Value 242 is Y Hard(192)
Repeat
Until Peek($DFF005)>0 or Peek($DFF006)>242
If SCRL_UPD=True
'Set new bitmap addresses in copper list
If BPL1_UPD=True
Doke BPL1PTH,Deek(Varptr(BPL1))
Doke BPL1PTL,Deek(Varptr(BPL1)+2)
Doke BPL3PTH,Deek(Varptr(BPL3))
Doke BPL3PTL,Deek(Varptr(BPL3)+2)
Doke BPL5PTH,Deek(Varptr(BPL5))
Doke BPL5PTL,Deek(Varptr(BPL5)+2)
BPL1_UPD=False
End If
If BPL2_UPD=True
Doke BPL2PTH,Deek(Varptr(BPL2))
Doke BPL2PTL,Deek(Varptr(BPL2)+2)
Doke BPL4PTH,Deek(Varptr(BPL4))
Doke BPL4PTL,Deek(Varptr(BPL4)+2)
Doke BPL6PTH,Deek(Varptr(BPL6))
Doke BPL6PTL,Deek(Varptr(BPL6)+2)
BPL2_UPD=False
End If
'Set hscroll values
Doke BPLCON1,BPLCON1_VAL
SCRL_UPD=False
End If
'Process sprite activities
SI=_SPRITE_STROBE_PT
SE=_SPRITE_STROBE_PT : Add SE,64
SC=SPT0PTH
While SI<SE
If Leek(SI)<>0
'get sprite address
SA=Leek(SI)
'Poke copper list
Doke SC,Deek(SI) : Add SC,4 : Add SI,2
Doke SC,Deek(SI) : Add SI,-2
'reset strobe
Loke SI,0
'set sprite's control words
Add SI,4
Loke SA,Leek(SI)
'step to the next hardware sprite
Add SI,4
Add SC,4
Else
Add SI,8
Add SC,8
End If
Wend
If _FADE>0
Dec _FADE
Gosub _FADE_IN
Else If _FADE<0
Inc _FADE
Gosub _FADE_OUT
End If
'To call a WaitTOF() just call a Wait Vbl ;)
Wait Vbl
Return
_FILL_TILE:
'We need MRR, MRC, NFR_Y, FCL_X and FCR_X set before coming here
Paste Icon FCL_X,NFR_Y,MAP(MRR*MAP_MODULO+MRC)
Paste Icon FCR_X,NFR_Y,MAP(MRR*MAP_MODULO+MRC)
Return
_CHECK_PLATFORM:
_MYP=(PL_Y+37+_FALL_ACCEL(_FALL_INDEX))/16
If _MYP<0 or _MYP>11 Then Return
TILE1=MAP(((SCR_POS+PL_X+_LEFT_FOOT)/16)+_MYP*MAP_MODULO)
TILE2=MAP(((SCR_POS+PL_X+_RIGHT_FOOT)/16)+_MYP*MAP_MODULO)
If TILE1>TS_PLATFORM or TILE2>TS_PLATFORM
If PL_STATE=FALLING
PL_STATE=LANDING
PL_Y=(_MYP*16)-37
End If
Else
PL_STATE=FALLING
End If
Return
_FADE_IN:
WA=CL_COLORS_PT
RA=_FADE_TABLE_PT
If _FADE=0
Gosub _SET_PALETTE_TO_COLOR_TABLE
Else
While Leek(WA)<>$FFFFFFFE
I=Deek(WA) : Add WA,2
If I>=$180 and I<=$1BE
'Get the current state of the split R,G,B values of this color
Add RA,2 : R=Deek(RA)
Add RA,4 : G=Deek(RA)
Add RA,4 : B=Deek(RA) : Add RA,-10
'Add the precalculated incremental
Add R,Deek(RA) : Add RA,4
Add G,Deek(RA) : Add RA,4
Add B,Deek(RA) : Add RA,-6
'Store the current state
Doke RA,R : Add RA,4
Doke RA,G : Add RA,4
Doke RA,B : Add RA,2
'Pack the split R,B,G values into a color value
W=0
Poke W3,Peek(B3) : Ror.l 4,W
Poke W3,Peek(G3) : Ror.l 4,W
Poke W3,Peek(R3)
'Update the color value on the copper list
Doke WA,W
End If
Add WA,2
Wend
End If
Return
_FADE_OUT:
WA=CL_COLORS_PT
RA=_FADE_TABLE_PT
If _FADE=0
Gosub _SET_PALETTE_TO_BLACK
Else
While Leek(WA)<>$FFFFFFFE
I=Deek(WA) : Add WA,2
If I>=$180 and I<=$1BE
Add RA,2 : R=Deek(RA)
Add RA,4 : G=Deek(RA)
Add RA,4 : B=Deek(RA) : Add RA,-10
Add R,-Deek(RA) : Add RA,4
Add G,-Deek(RA) : Add RA,4
Add B,-Deek(RA) : Add RA,-6
Doke RA,R : Add RA,4
Doke RA,G : Add RA,4
Doke RA,B : Add RA,2
W=0
Poke W3,Peek(B3) : Ror.l 4,W
Poke W3,Peek(G3) : Ror.l 4,W
Poke W3,Peek(R3)
Doke WA,W
End If
Add WA,2
Wend
End If
Return
_SET_PALETTE_TO_COLOR_TABLE:
WA=CL_COLORS_PT
RA=_COLOR_TABLE_PT
While Leek(WA)<>$FFFFFFFE
I=Deek(WA) : Add WA,2
If I>=$180 and I<=$1BE
Doke WA,Deek(RA)
Add RA,2
End If
Add WA,2
Wend
Return
_SET_PALETTE_TO_BLACK:
WA=CL_COLORS_PT
While Leek(WA)<>$FFFFFFFE
I=Deek(WA) : Add WA,2
If I>=$180 and I<=$1BE
Doke WA,$0
End If
Add WA,2
Wend
Goto QUIT
Return
'**********
'Procedures
'**********
Procedure PREP_SCREEN_BITMAPS
Auto View Off
'DualPlayfield: 0)Distant background / 1)TileMapped Background
Screen Open 0,656,200,8,Lowres : Screen Hide 0 : Curs Off : Flash Off : Cls 0
Screen Open 1,704,200,8,Lowres : Screen Hide 1 : Curs Off : Flash Off : Cls 0
'Distant background image
Load Iff "Background.iff",2 : Screen Hide 2
Screen Copy 2,0,0,320,200 To 0,16,0
Screen Copy 2,0,0,320,200 To 0,336,0
Screen Close 2
Screen 0
End Proc
Procedure CUSTOM_COPPER_LIST
Shared CL_PT,CL_COLORS_PT
Shared BPL1PT,BPL2PT,BPL3PT,BPL4PT,BPL5PT,BPL6PT
Shared BPL1,BPL2,BPL3,BPL4,BPL5,BPL6
Shared BPL1PTM,BPL2PTM
Shared BPL1PTH,BPL1PTL,BPL2PTH,BPL2PTL,BPL3PTH,BPL3PTL
Shared BPL4PTH,BPL4PTL,BPL5PTH,BPL5PTL,BPL6PTH,BPL6PTL
Shared BPLCON0,BPLCON1,BPLCON2,BPLCON3
Shared SPT0PTH,SPT0PTL,SPT1PTH,SPT1PTL,SPT2PTH,SPT2PTL,SPT3PTH,SPT3PTL
Shared SPT4PTH,SPT4PTL,SPT5PTH,SPT5PTL,SPT6PTH,SPT6PTL,SPT7PTH,SPT7PTL
'Dummy Sprite Address
DSA=Start(5)
DSA_H=Deek(Varptr(DSA))
DSA_L=Deek(Varptr(DSA)+2)
'Address of our new copper list
CL_PT=Cop Logic
'Get bitplane addresses
Screen 0
BPL1PT=Phybase(0)
BPL3PT=Phybase(1)
BPL5PT=Phybase(2)
Screen 1
BPL2PT=Phybase(0)
BPL4PT=Phybase(1)
BPL6PT=Phybase(2)
Screen 0
BPL1=BPL1PT
BPL2=BPL2PT
BPL3=BPL3PT
BPL4=BPL4PT
BPL5=BPL5PT
BPL6=BPL6PT
BPL1PTM=BPL1PT+40
BPL2PTM=BPL2PT+44
'Prepare copper list poke addresses
' You have to count copper instructions by hand and calculate as
' byte offsets to CL_PT :(
SPT0PTH=CL_PT+2 : SPT0PTL=SPT0PTH+4
SPT1PTH=SPT0PTH+8 : SPT1PTL=SPT1PTH+4
SPT2PTH=SPT1PTH+8 : SPT2PTL=SPT2PTH+4
SPT3PTH=SPT2PTH+8 : SPT3PTL=SPT3PTH+4
SPT4PTH=SPT3PTH+8 : SPT4PTL=SPT4PTH+4
SPT5PTH=SPT4PTH+8 : SPT5PTL=SPT5PTH+4
SPT6PTH=SPT5PTH+8 : SPT6PTL=SPT6PTH+4
SPT7PTH=SPT6PTH+8 : SPT7PTL=SPT7PTH+4
BPL1PTH=CL_PT+(18*4)+2
BPL1PTL=BPL1PTH+4
BPL2PTH=BPL1PTH+8
BPL2PTL=BPL2PTH+4
BPL3PTH=BPL2PTH+8
BPL3PTL=BPL3PTH+4
BPL4PTH=BPL3PTH+8
BPL4PTL=BPL4PTH+4
BPL5PTH=BPL4PTH+8
BPL5PTL=BPL5PTH+4
BPL6PTH=BPL5PTH+8
BPL6PTL=BPL6PTH+4
BPLCON0=CL_PT+(36*4)+2