-
Notifications
You must be signed in to change notification settings - Fork 2
/
Macros.asm
1760 lines (1510 loc) · 47.5 KB
/
Macros.asm
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
; ===========================================================================
; Macros
; ===========================================================================
; ---------------------------------------------------------------------------
; simplifying macros and functions
; nameless temporary symbols should NOT be used inside macros because they can interfere with the surrounding code
; normal labels should be used instead (which automatically become local to the macro)
; ---------------------------------------------------------------------------
; makes a VDP address difference
vdpCommDelta function addr,((addr&$3FFF)<<16)|((addr&$C000)>>14)
; makes a VDP command
vdpComm function addr,type,rwd,(((type&rwd)&3)<<30)|((addr&$3FFF)<<16)|(((type&rwd)&$FC)<<2)|((addr&$C000)>>14)
; sign-extends a 32-bit integer to 64-bit
; all RAM addresses are run through this function to allow them to work in both 16-bit and 32-bit addressing modes
ramaddr function x,-(-x)&$FFFFFFFF
; function using these variables
id function ptr,((ptr-offset)/ptrsize+idstart)
; function to convert two separate nibble into a byte
nibbles_to_byte function nibble1,nibble2,(((nibble1)<<4)&$F0)|((nibble2)&$FF)
; function to convert two separate bytes into a word
bytes_to_word function byte1,byte2,(((byte1)<<8)&$FF00)|((byte2)&$FF)
; function to convert two separate word into a long
words_to_long function word1,word2,(((word1)<<16)&$FFFF0000)|((word2)&$FFFF)
; function to convert two separate bytes and word into a word
bytes_word_to_long function byte1,byte2,word,((((byte1)<<24)&$FF000000)|(((byte2)<<16)&$FF0000)|((word)&$FFFF))
; function to convert four separate bytes into a long
bytes_to_long function byte1,byte2,byte3,byte4,(((byte1)<<24)&$FF000000)|(((byte2)<<16)&$FF0000)|(((byte3)<<8)&$FF00)|((byte4)&$FF)
; ---------------------------------------------------------------------------
; values for the type argument
VRAM = %100001
CRAM = %101011
VSRAM = %100101
; values for the rwd argument
READ = %001100
WRITE = %000111
DMA = %100111
; ---------------------------------------------------------------------------
; tells the VDP to copy a region of 68k memory to VRAM or CRAM or VSRAM
dma68kToVDP macro source,dest,length,type
move.l #(($9400|((((length)>>1)&$FF00)>>8))<<16)|($9300|(((length)>>1)&$FF)),VDP_control_port-VDP_control_port(a5)
move.l #(($9600|((((source)>>1)&$FF00)>>8))<<16)|($9500|(((source)>>1)&$FF)),VDP_control_port-VDP_control_port(a5)
move.w #$9700|(((((source)>>1)&$FF0000)>>16)&$7F),VDP_control_port-VDP_control_port(a5)
move.w #(vdpComm(dest,type,DMA)>>16)&$FFFF,VDP_control_port-VDP_control_port(a5)
move.w #vdpComm(dest,type,DMA)&$FFFF,-(sp)
move.w (sp)+,VDP_control_port-VDP_control_port(a5)
; From ' § 7 DMA TRANSFER' of https://emu-docs.org/Genesis/sega2f.htm:
;
; "In the case of ROM to VRAM transfers,
; a hardware feature causes occasional failure of DMA unless the
; following two conditions are observed:
;
; --The destination address write (to address $C00004) must be a word
; write.
;
; --The final write must use the work RAM.
; There are two ways to accomplish this, by copying the DMA program
; into RAM or by doing a final "move.w ram address $C00004""
endm
; tells the VDP to fill a region of VRAM with a certain byte
dmaFillVRAM macro byte,addr,length
move.w #$8F01,VDP_control_port-VDP_control_port(a5) ; VRAM pointer increment: $0001
move.l #(($9400|((((length)-1)&$FF00)>>8))<<16)|($9300|(((length)-1)&$FF)),VDP_control_port-VDP_control_port(a5) ; DMA length ...
move.w #$9780,VDP_control_port-VDP_control_port(a5) ; VRAM fill
move.l #vdpComm(addr,VRAM,DMA),VDP_control_port-VDP_control_port(a5) ; start at ...
move.w #bytes_to_word(byte,byte),(VDP_data_port).l ; fill with byte
.loop:
moveq #2,d1
and.w VDP_control_port-VDP_control_port(a5),d1
bne.s .loop ; busy loop until the VDP is finished filling...
move.w #$8F02,VDP_control_port-VDP_control_port(a5) ; VRAM pointer increment: $0002
endm
; -------------------------------------------------------------
; Macro to check button presses
; Arguments:
; 1 - buttons to check
; -------------------------------------------------------------
tpress macro press,player
if player=2
move.b (Ctrl_2_pressed).w,d0
else
move.b (Ctrl_1_pressed).w,d0
endif
andi.b #(press),d0
endm
; -------------------------------------------------------------
; Macro to check if buttons are held
; Arguments:
; 1 - buttons to check
; -------------------------------------------------------------
theld macro press,player
if player=2
move.b (Ctrl_2_held).w,d0
else
move.b (Ctrl_1_held).w,d0
endif
andi.b #(press),d0
endm
; ---------------------------------------------------------------------------
; set a VRAM address via the VDP control port.
; input: 16-bit VRAM address, control port (default is (VDP_control_port).l)
; ---------------------------------------------------------------------------
locVRAM macro loc, controlport
if ("controlport"=="")
move.l #$40000000|vdpCommDelta(loc),(VDP_control_port).l
else
move.l #$40000000|vdpCommDelta(loc),controlport
endif
endm
; ---------------------------------------------------------------------------
; macro for a debug object list header
; must be on the same line as a label that has a corresponding _end label later
; ---------------------------------------------------------------------------
dbglistheader macro {INTLABEL}
__LABEL__ label *
dc.w ((__LABEL___end - __LABEL__ - 2) / $A)
endm
; macro to define debug list object data
dbglistobj macro obj, mapaddr, subtype, frame, vram, pal, pri
dc.l frame<<24|((obj)&$FFFFFF)
dc.l subtype<<24|((mapaddr)&$FFFFFF)
dc.w make_art_tile(vram,pal,pri)
endm
; ---------------------------------------------------------------------------
; macro for declaring a "main level load block" (MLLB)
; ---------------------------------------------------------------------------
levartptrs macro art1,art2,map16x16r,map16x161,map16x162,map128x128r,map128x1281,map128x1282,palette,wpalette,music
dc.l (palette)<<24|((art1)&$FFFFFF),art2
dc.l (wpalette)<<24|((map16x16r)&$FFFFFF),map16x161,map16x162
dc.l (music)<<24|((map128x128r)&$FFFFFF),map128x1281,map128x1282
endm
; ---------------------------------------------------------------------------
palptr macro ptr,lineno
dc.l ptr
dc.w (Normal_palette+lineno*palette_line_size)&$FFFF
dc.w bytesToLcnt(ptr_end-ptr)
endm
mSBZh macro {INTLABEL}
__LABEL__ label *
dc.w ((__LABEL___end-__LABEL__-2)/8)-1
endm
mSBZp macro duration,colours,paladdress,ramaddress
dc.b duration,colours
dc.l (paladdress)
dc.w ((ramaddress)&$FFFF)
endm
; ---------------------------------------------------------------------------
; macro to declare sub-object data
subObjData macro mappings,vram,pal,pri,height,width,prio,frame,collision
dc.l mappings
dc.w make_art_tile(vram,pal,pri)
dc.b (height/2),(width/2)
dc.w sprite_priority(prio)
dc.b frame,collision
endm
; macro to declare sub-object data
subObjData2 macro vram,pal,pri,height,width,prio,frame,collision
dc.w make_art_tile(vram,pal,pri)
dc.b (height/2),(width/2)
dc.w sprite_priority(prio)
dc.b frame,collision
endm
; macro to declare sub-object data
subObjData3 macro height,width,prio,frame,collision
dc.b (height/2),(width/2)
dc.w sprite_priority(prio)
dc.b frame,collision
endm
; macro to declare sub-object slotted data
subObjSlotData macro slots,vram,pal,pri,offset,index,mappings,height,width,prio,frame,collision
dc.w slots,make_art_tile(vram,pal,pri),offset,index
dc.l mappings
dc.b (height/2),(width/2)
dc.w sprite_priority(prio)
dc.b frame,collision
endm
; macro to declare sub-object data
subObjMainData macro address,render,routine,height,width,prio,vram,pal,pri,mappings,frame,collision
dc.l address
dc.b render,routine,(height/2),(width/2)
dc.w sprite_priority(prio),make_art_tile(vram,pal,pri)
dc.l mappings
dc.b frame, collision
endm
; macro to declare sub-object data
subObjMainData2 macro address,render,routine,height,width,prio,vram,pal,pri,mappings
dc.l address
dc.b render,routine,(height/2),(width/2)
dc.w sprite_priority(prio),make_art_tile(vram,pal,pri)
dc.l mappings
endm
; macro to declare sub-object data
subObjMainData3 macro render,routine,height,width,prio,vram,pal,pri,mappings
dc.b render,routine,(height/2),(width/2)
dc.w sprite_priority(prio),make_art_tile(vram,pal,pri)
dc.l mappings
endm
; ---------------------------------------------------------------------------
; macro to level select icons
setRSDKIcons macro pal, icon
dc.w (pal)*palette_line_size, (icon)*tiles_to_bytes(dmaLength(12))
endm
; ---------------------------------------------------------------------------
zoneAnimals macro first,second
dc.ATTRIBUTE (Obj_Animal_Properties_first - Obj_Animal_Properties), (Obj_Animal_Properties_second - Obj_Animal_Properties)
endm
objanimaldecl macro mappings, address, xvel, yvel, {INTLABEL}
Obj_Animal_Properties___LABEL__: label *
dc.l mappings, address
dc.w xvel, yvel
endm
objanimalending macro address, mappings, vram, xvel, yvel
dc.l address, mappings
dc.w vram, xvel, yvel
dc.w 0 ; even
endm
; ---------------------------------------------------------------------------
LargeGrassEntry macro ptr,frame,width
offsetTableEntry.w ptr
dc.b frame,(width/2)
endm
StillSpritesEntry macro prio,vram,pal,pri,height,width
dc.w sprite_priority(prio),make_art_tile(vram,pal,pri)
dc.b (height/2),(width/2)
endm
; ---------------------------------------------------------------------------
titlecardresultsheader macro {INTLABEL}
__LABEL__ label *
dc.w ((__LABEL___end - __LABEL__) / $E)-1
endm
titlecardresultsobjdata macro address,xdest,xpos,ypos,frame,width,exit
dc.l address ; object address
dc.w 128+xdest,128+xpos,128+ypos ; x destination, xpos, ypos
dc.b frame,(width/2) ; mapping frame, width
dc.w exit ; place in exit queue
endm
; ---------------------------------------------------------------------------
; macro to declare Special Stage data
specialStageData macro frame,mappings,palette,vram
dc.l mappings|(frame<<24)
dc.w make_art_tile(vram,palette,0)
endm
; macro to declare Special Stage BG data
SSBGData macro time,anim,plane,index,flag1,flag2
dc.b (time),(anim),(plane)>>13
if flag1
dc.b (index)|$80|(flag2)
else
dc.b (index)*12
endif
endm
; macro to declare Special Stage FG data
SSFGData macro plane,y
dc.b (plane)>>10,(y)>>8
endm
specialresultsheader macro {INTLABEL}
__LABEL__ label *
dc.w ((__LABEL___end - __LABEL__) / $C)-1
endm
specialresultsobjdata macro address,xdest,xpos,ypos,frame,width
dc.l address ; object address
dc.w 128+xdest,128+xpos,128+ypos ; x destination, xpos, ypos
dc.b frame,(width/2) ; mapping frame, width
endm
; ---------------------------------------------------------------------------
objTeleportSize macro {INTLABEL}
__LABEL__ label *
dc.w __LABEL___end-__LABEL__-2
endm
; ---------------------------------------------------------------------------
; calculates initial loop counter value for a dbf loop
; that writes n bytes total at 4 bytes per iteration
bytesTo4Lcnt function n,n>>4
; calculates initial loop counter value for a dbf loop
; that writes n bytes total at 4 bytes per iteration
bytesTo2Lcnt function n,n>>2
; calculates initial loop counter value for a dbf loop
; that writes n bytes total at 4 bytes per iteration
bytesToLcnt function n,n>>2-1
; calculates initial loop counter value for a dbf loop
; that writes n bytes total at 2 bytes per iteration
bytesToWcnt function n,n>>1-1
; calculates initial loop counter value for a dbf loop
; that writes n bytes total at x bytes per iteration
bytesToXcnt function n,x,n/x-1
; ---------------------------------------------------------------------------
; fills a region of 68k RAM with 0
clearRAM macro startaddr,endaddr
if startaddr>endaddr
fatal "Starting address of clearRAM \{startaddr} is after ending address \{endaddr}."
elseif startaddr==endaddr
warning "clearRAM is clearing zero bytes. Turning this into a nop instead."
exitm
endif
if ((startaddr)&$8000)==0
lea (startaddr).l,a1
else
lea (startaddr).w,a1
endif
moveq #0,d0
if ((startaddr)&1)
move.b d0,(a1)+
endif
if ((bytesToLcnt((endaddr-startaddr) - ((startaddr)&1)))<=$7F)
moveq #bytesToLcnt((endaddr-startaddr) - ((startaddr)&1)),d1
else
move.w #bytesToLcnt((endaddr-startaddr) - ((startaddr)&1)),d1
endif
.clear:
move.l d0,(a1)+
dbf d1,.clear
if (((endaddr-startaddr) - ((startaddr)&1))&2)
move.w d0,(a1)+
endif
if (((endaddr-startaddr) - ((startaddr)&1))&1)
move.b d0,(a1)+
endif
endm
; fills a region of 68k RAM with 0
clearRAM2 macro startaddr,endaddr
if startaddr>endaddr
fatal "Starting address of clearRAM2 \{startaddr} is after ending address \{endaddr}."
elseif startaddr==endaddr
warning "clearRAM2 is clearing zero bytes. Turning this into a nop instead."
exitm
endif
if ((startaddr)&$8000)==0
lea (startaddr).l,a1
else
lea (startaddr).w,a1
endif
moveq #0,d0
if ((startaddr)&1)
move.b d0,(a1)+
endif
rept bytesTo2Lcnt((endaddr-startaddr) - ((startaddr)&1))
move.l d0,(a1)+
endr
if (((endaddr-startaddr) - ((startaddr)&1))&2)
move.w d0,(a1)+
endif
if (((endaddr-startaddr) - ((startaddr)&1))&1)
move.b d0,(a1)+
endif
endm
; fills a region of 68k RAM with 0
clearRAM3 macro startaddr,endaddr
if startaddr>endaddr
fatal "Starting address of clearRAM \{startaddr} is after ending address \{endaddr}."
elseif startaddr==endaddr
warning "clearRAM is clearing zero bytes. Turning this into a nop instead."
exitm
endif
if ((startaddr)&$8000)==0
lea (startaddr).l,a1
else
lea (startaddr).w,a1
endif
moveq #0,d0
if ((startaddr)&1)
move.b d0,(a1)+
endif
if ((bytesToXcnt(((endaddr-startaddr) - ((startaddr)&1)),(16*4)))<=$7F)
moveq #bytesToXcnt(((endaddr-startaddr) - ((startaddr)&1)),(16*4)),d1
else
move.w #bytesToXcnt(((endaddr-startaddr) - ((startaddr)&1)),(16*4)),d1
endif
.clear:
rept 16
move.l d0,(a1)+
endr
dbf d1,.clear
if (((endaddr-startaddr) - ((startaddr)&1))&2)
move.w d0,(a1)+
endif
if (((endaddr-startaddr) - ((startaddr)&1))&1)
move.b d0,(a1)+
endif
endm
; copy 68k RAM
copyRAM macro startaddr,endaddr,startaddr2
if startaddr>endaddr
fatal "Starting address of copyRAM \{startaddr} is after ending address \{endaddr}."
elseif startaddr==endaddr
warning "copyRAM is copy zero bytes. Turning this into a nop instead."
exitm
endif
if ((startaddr)&$8000)==0
lea (startaddr).l,a1
else
lea (startaddr).w,a1
endif
if ((startaddr2)&$8000)==0
lea (startaddr2).l,a2
else
lea (startaddr2).w,a2
endif
moveq #0,d0
if ((startaddr)&1)
move.b (a1)+,(a2)+
endif
if ((bytesToLcnt((endaddr-startaddr) - ((startaddr)&1)))<=$7F)
moveq #bytesToLcnt((endaddr-startaddr) - ((startaddr)&1)),d1
else
move.w #bytesToLcnt((endaddr-startaddr) - ((startaddr)&1)),d1
endif
.clear:
move.l (a1)+,(a2)+
dbf d1,.clear
if (((endaddr-startaddr) - ((startaddr)&1))&2)
move.w (a1)+,(a2)+
endif
if (((endaddr-startaddr) - ((startaddr)&1))&1)
move.b (a1)+,(a2)+
endif
endm
; copy 68k RAM
copyRAM2 macro startaddr,endaddr,startaddr2
if startaddr>endaddr
fatal "Starting address of copyRAM2 \{startaddr} is after ending address \{endaddr}."
elseif startaddr==endaddr
warning "copyRAM2 is copy zero bytes. Turning this into a nop instead."
exitm
endif
if ((startaddr)&$8000)==0
lea (startaddr).l,a1
else
lea (startaddr).w,a1
endif
if ((startaddr2)&$8000)==0
lea (startaddr2).l,a2
else
lea (startaddr2).w,a2
endif
moveq #0,d0
if ((startaddr)&1)
move.b (a1)+,(a2)+
endif
rept bytesTo2Lcnt((endaddr-startaddr) - ((startaddr)&1))
move.l (a1)+,(a2)+
endr
if (((endaddr-startaddr) - ((startaddr)&1))&2)
move.w (a1)+,(a2)+
endif
if (((endaddr-startaddr) - ((startaddr)&1))&1)
move.b (a1)+,(a2)+
endif
endm
; ---------------------------------------------------------------------------
; load Kosinski Plus and Kosinski Plus Moduled
; ---------------------------------------------------------------------------
; load Kosinski Plus data to RAM
QueueKosPlus macro data,ram,terminate
lea (data).l,a1
if ((ram)&$8000)==0
lea (ram).l,a2
else
lea (ram).w,a2
endif
if ("terminate"="0") || ("terminate"="")
jsr (Queue_KosPlus).w
else
jmp (Queue_KosPlus).w
endif
endm
; load Kosinski Plus Moduled art to VRAM
QueueKosPlusModule macro art,vram,terminate
lea (art).l,a1
if ((vram)<=3)
moveq #tiles_to_bytes(vram),d2
else
move.w #tiles_to_bytes(vram),d2
endif
if ("terminate"="0") || ("terminate"="")
jsr (Queue_KosPlus_Module).w
else
jmp (Queue_KosPlus_Module).w
endif
endm
; ---------------------------------------------------------------------------
; load Enigma
; ---------------------------------------------------------------------------
; load Enigma data to RAM
EniDecomp macro data,ram,vram,palette,pri,terminate
lea (data).l,a0
if ((ram)&$8000)==0
lea (ram).l,a1
else
lea (ram).w,a1
endif
move.w #make_art_tile(vram,palette,pri),d0
if ("terminate"="0") || ("terminate"="")
jsr (Eni_Decomp).w
else
jmp (Eni_Decomp).w
endif
endm
; ---------------------------------------------------------------------------
; load DMA
; ---------------------------------------------------------------------------
; load DMA
AddToDMAQueue macro art,vram,size,terminate
move.l #dmaSource(art),d1
move.w #tiles_to_bytes(vram),d2
if ((size/2)<=$7F)
moveq #(size/2),d3
else
move.w #(size/2),d3
endif
if ("terminate"="0") || ("terminate"="")
jsr (Add_To_DMA_Queue).w
else
jmp (Add_To_DMA_Queue).w
endif
endm
; ---------------------------------------------------------------------------
; check if object moves out of range
; input: location to jump to if out of range, x-axis pos (x_pos(a0) by default)
; ---------------------------------------------------------------------------
out_of_xrange macro exit, xpos
moveq #-$80,d0 ; round down to nearest $80
if ("xpos"<>"")
and.w xpos,d0 ; get object position (if specified as not x_pos)
else
and.w x_pos(a0),d0 ; get object position
endif
out_of_xrange2.ATTRIBUTE exit
endm
out_of_xrange2 macro exit
sub.w (Camera_X_pos_coarse_back).w,d0 ; get screen position
cmpi.w #$80+320+$40+$80,d0 ; this gives an object $80 pixels of room offscreen before being unloaded (the $40 is there to round up 320 to a multiple of $80)
bhi.ATTRIBUTE exit
endm
; ---------------------------------------------------------------------------
; check if object moves out of range
; input: location to jump to if out of range, x-axis pos (y_pos(a0) by default)
; ---------------------------------------------------------------------------
out_of_yrange macro exit, ypos
moveq #-$80,d0 ; round down to nearest $80
if ("ypos"<>"")
and.w ypos,d0 ; get object position (if specified as not y_pos)
else
and.w y_pos(a0),d0 ; get object position
endif
out_of_yrange2.ATTRIBUTE exit
endm
out_of_yrange2 macro exit
sub.w (Camera_Y_pos_coarse_back).w,d0
cmpi.w #$80+256+$80,d0
bhi.ATTRIBUTE exit
endm
; ---------------------------------------------------------------------------
; object respawn delete
; ---------------------------------------------------------------------------
respawn_delete macro terminate
move.w respawn_addr(a0),d0 ; get address in respawn table
beq.s .delete ; if it's zero, it isn't remembered
movea.w d0,a2 ; load address into a2
bclr #7,(a2)
.delete
if ("terminate"="0") <> ("terminate"="")
jmp (Delete_Current_Sprite).w
endif
endm
; ---------------------------------------------------------------------------
; macros for frequently used subroutines
; ---------------------------------------------------------------------------
getobjectRAMslot macro address
if ("address"=="")
fatal "Error! Empty value!"
endif
move.w #Dynamic_object_RAM_end,d0
sub.w a0,d0
lsr.w #6,d0 ; divide by $40... even though SSTs are $4A bytes long in this game
lea (Create_New_Sprite3.find_first_sprite_table).w,address
move.b (address,d0.w),d0 ; use a look-up table to get the right loop counter
endm
MoveSprite macro address, gravity, terminate
if ("address"=="")
fatal "Error! Empty value!"
endif
movem.w x_vel(address),d0/d2 ; load xy speed
asl.l #8,d0 ; shift velocity to line up with the middle 16 bits of the 32-bit position
asl.l #8,d2 ; shift velocity to line up with the middle 16 bits of the 32-bit position
add.l d0,x_pos(address) ; add to x-axis position ; note this affects the subpixel position x_sub(address) = 2+x_pos(address)
add.l d2,y_pos(address) ; add to y-axis position ; note this affects the subpixel position y_sub(address) = 2+y_pos(address)
if ("gravity"<>"")
addi.w #gravity,y_vel(address) ; increase vertical speed (apply gravity)
else
addi.w #$38,y_vel(address) ; increase vertical speed (apply gravity)
endif
if ("terminate"<>"")
rts
endif
endm
MoveSprite2 macro address, terminate
if ("address"=="")
fatal "Error! Empty value!"
endif
movem.w x_vel(address),d0/d2 ; load xy speed
asl.l #8,d0 ; shift velocity to line up with the middle 16 bits of the 32-bit position
asl.l #8,d2 ; shift velocity to line up with the middle 16 bits of the 32-bit position
add.l d0,x_pos(address) ; add to x-axis position ; note this affects the subpixel position x_sub(address) = 2+x_pos(address)
add.l d2,y_pos(address) ; add to y-axis position ; note this affects the subpixel position y_sub(address) = 2+y_pos(address)
if ("terminate"<>"")
rts
endif
endm
MoveSpriteXOnly macro address, terminate
if ("address"=="")
fatal "Error! Empty value!"
endif
move.w x_vel(address),d0 ; load x speed
ext.l d0
asl.l #8,d0 ; shift velocity to line up with the middle 16 bits of the 32-bit position
add.l d0,x_pos(address) ; add to x-axis position ; note this affects the subpixel position x_sub(address) = 2+x_pos(address)
if ("terminate"<>"")
rts
endif
endm
MoveSpriteYOnly macro address, gravity, terminate
if ("address"=="")
fatal "Error! Empty value!"
endif
move.w y_vel(address),d0 ; load y speed
ext.l d0
asl.l #8,d0 ; shift velocity to line up with the middle 16 bits of the 32-bit position
add.l d0,y_pos(address) ; add to y-axis position ; note this affects the subpixel position y_sub(a0) = 2+y_pos(a0)
if ("gravity"<>"")
addi.w #gravity,y_vel(address) ; increase vertical speed (apply gravity)
else
addi.w #$38,y_vel(address) ; increase vertical speed (apply gravity)
endif
if ("terminate"<>"")
rts
endif
endm
MoveSprite2YOnly macro address, terminate
if ("address"=="")
fatal "Error! Empty value!"
endif
move.w y_vel(address),d0 ; load y speed
ext.l d0
asl.l #8,d0 ; shift velocity to line up with the middle 16 bits of the 32-bit position
add.l d0,y_pos(address) ; add to y-axis position ; note this affects the subpixel position y_sub(a0) = 2+y_pos(a0)
if ("terminate"<>"")
rts
endif
endm
Add_SpriteToCollisionResponseList macro address, terminate
if ("address"=="")
fatal "Error! Empty value!"
endif
lea (Collision_response_list).w,address
move.w (address),d0 ; get list to d0
addq.b #2,d0 ; is list full? ($80)
bmi.s .full ; if so, return
move.w d0,(address) ; save list ($7E)
move.w a0,(address,d0.w) ; store RAM address in list
.full
if ("terminate"<>"")
rts
endif
endm
CreateNewSprite macro obj, terminate
jsr (Create_New_Sprite).w
bne.s .skip
move.l #obj,address(a1)
.skip
if ("terminate"<>"")
rts
endif
endm
CreateNewSprite3 macro obj, terminate
jsr (Create_New_Sprite3).w
bne.s .skip
move.l #obj,address(a1)
.skip
if ("terminate"<>"")
rts
endif
endm
; ---------------------------------------------------------------------------
; macro to simplify editing the demo scripts
; ---------------------------------------------------------------------------
demoinput macro duration,buttons
btns_mask := 0
irpc btn,"buttons"
switch "btn"
case "U"
btns_mask := btns_mask|button_up_mask
case "D"
btns_mask := btns_mask|button_down_mask
case "L"
btns_mask := btns_mask|button_left_mask
case "R"
btns_mask := btns_mask|button_right_mask
case "A"
btns_mask := btns_mask|button_A_mask
case "B"
btns_mask := btns_mask|button_B_mask
case "C"
btns_mask := btns_mask|button_C_mask
case "S"
btns_mask := btns_mask|button_start_mask
elsecase
if ("buttons"<>"")
fatal "Error! Button variable not defined!"
endif
endcase
endm
dc.b duration-1,btns_mask
endm
; ---------------------------------------------------------------------------
; macro for marking the boundaries of an object layout file
; ---------------------------------------------------------------------------
ObjectLayoutBoundary macro
dc.w -1, 0, 0
endm
; ---------------------------------------------------------------------------
; macro for marking the boundaries of an ring layout file
; ---------------------------------------------------------------------------
RingLayoutBoundary macro
dc.w 0, 0, -1, -1
endm
; ---------------------------------------------------------------------------
; function to make a little-endian 16-bit pointer for the Z80 sound driver
; ---------------------------------------------------------------------------
z80_ptr function x,(x)<<8&$FF00|(x)>>8&$7F|$80
; ---------------------------------------------------------------------------
; macro to declare a little-endian 16-bit pointer for the Z80 sound driver
; ---------------------------------------------------------------------------
rom_ptr_z80 macro addr
dc.w z80_ptr(addr)
endm
; ---------------------------------------------------------------------------
; clear the Z80 RAM
; ---------------------------------------------------------------------------
clearZ80RAM macro
lea (Z80_RAM).l,a0
move.w #$1FFF,d0
.clear:
clr.b (a0)+
dbf d0,.clear
endm
paddingZ80RAM macro
moveq #0,d0
.clear:
move.b d0,(a1)+
cmpa.l #(Z80_RAM_end),a1
bne.s .clear
endm
; ---------------------------------------------------------------------------
; stop the Z80
; ---------------------------------------------------------------------------
; tells the Z80 to stop, and waits for it to finish stopping (acquire bus)
stopZ80 macro
if OptimiseStopZ80=0
move.w #$100,(Z80_bus_request).l ; stop the Z80
.wait:
btst #0,(Z80_bus_request).l
bne.s .wait ; loop until it says it's stopped
endif
endm
; tells the Z80 to stop, and waits for it to finish stopping (acquire bus)
stopZ80a macro
if OptimiseStopZ80=0
move.w #$100,(Z80_bus_request).l ; stop the Z80
endif
endm
; ---------------------------------------------------------------------------
; wait for Z80 to stop
; ---------------------------------------------------------------------------
; tells the Z80 to wait for it to finish stopping (acquire bus)
waitZ80 macro
if OptimiseStopZ80=0
.wait:
btst #0,(Z80_bus_request).l
bne.s .wait ; loop until
endif
endm
; ---------------------------------------------------------------------------
; reset the Z80
; ---------------------------------------------------------------------------
; tells the Z80 to reset
resetZ80 macro
if OptimiseStopZ80=0
move.w #$100,(Z80_reset).l
endif
endm
; tells the Z80 to reset
resetZ80a macro
if OptimiseStopZ80=0
move.w #0,(Z80_reset).l
endif
endm
; ---------------------------------------------------------------------------
; start the Z80
; ---------------------------------------------------------------------------
; tells the Z80 to start again
startZ80 macro
if OptimiseStopZ80=0
move.w #0,(Z80_bus_request).l ; start the Z80
endif
endm
; ---------------------------------------------------------------------------
; stop the Z80 (2)
; ---------------------------------------------------------------------------
; tells the Z80 to stop, and waits for it to finish stopping (acquire bus)
stopZ802 macro
if OptimiseStopZ80=2
move.w #$100,(Z80_bus_request).l ; stop the Z80
.wait:
btst #0,(Z80_bus_request).l
bne.s .wait ; loop until it says it's stopped
endif
endm
; ---------------------------------------------------------------------------
; start the Z80 (2)
; ---------------------------------------------------------------------------
; tells the Z80 to start again
startZ802 macro
if OptimiseStopZ80=2
move.w #0,(Z80_bus_request).l ; start the Z80
endif
endm
; ---------------------------------------------------------------------------
; wait for the Z80
; ---------------------------------------------------------------------------
waitZ80time macro time
move.w #(time),d0
.wait:
nop
nop
nop
nop
dbf d0,.wait
endm
; ---------------------------------------------------------------------------
; disable interrupts
; ---------------------------------------------------------------------------
disableInts macro
move #$2700,sr
endm
; ---------------------------------------------------------------------------
; enable interrupts
; ---------------------------------------------------------------------------
enableInts macro
move #$2300,sr
endm
; ---------------------------------------------------------------------------
; disable interrupts
; ---------------------------------------------------------------------------