-
Notifications
You must be signed in to change notification settings - Fork 6
/
UTIL.ASM
1567 lines (1468 loc) · 44.7 KB
/
UTIL.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
.FILE 'UTIL.ASM'
; SHELL PROGRAM - DO NOT MODIFY!
; MARK TURMELL - MAY 24, 1989
;
.TITLE " UTILITY - GENERAL PURPOSE SUBROUTINES"
**************************************************************************
* *
* COPYRIGHT (C) 1988 WILLIAMS ELECTRONICS GAMES, INC. *
* ALL RIGHTS RESERVED. *
* *
**************************************************************************
.WIDTH 132
.OPTION B,D,L
.MNOLIST
* GET THE SYSTEM STUFF
.INCLUDE "MPROC.EQU" ;MPROC EQUATES
.INCLUDE "DISP.EQU" ;DISPLAY PROCESSOR EQUATES
.INCLUDE "\VIDEO\SYS\GSP.INC" ;GSP ASSEMBLER EQUATES
.INCLUDE "\VIDEO\SYS\SYS.INC" ;ZUNIT SYSTEM EQUATES
.INCLUDE "\VIDEO\SYS\MACROS.HDR" ;MACROS, YEAH!
.INCLUDE ROBO.EQU ;FOR TEXTOID!
*UTILITY SUBROUTINE EQUATES
.GLOBAL SCRCLR,MYOINIT,SETPPROC,GPALOBJ,GBPALOBJ
.GLOBAL SHVELCPY,SHVELFLP,FLP,OBJOFF,OBJON,CLRPDATA
.GLOBAL ADDSUPP,DELSUPP,STRLNRM,STRCNRM,STRCNRMO,STRLNRMO
.GLOBAL RANDU,RANDOM,SRAND,RANGRAND,RANDPER,BLNKAREA,DTIME
.GLOBAL FRANIM,AUTOEOFF,AUTOEON,DMAQWAIT,SYNCHALF
.GLOBAL STRNGLEN,DMAN,CLRWORLD,CLR_SCRN
.GLOBAL STRRNRM,FILLAREA,SYNCFULL,SCRFIL,GETCPNT
*PAL EQUATES
.GLOBL DELPAL,GETFPAL,INITBPAL,FINDPAL,INITPAL,PALSET
*RAM EQUATES
.GLOBL INTSYNC0,INTSYNC1,NOAUTOE,SYSCOPY
.GLOBL GAMERASE
; .REF GOUP ;ROBOATT
.REF MYID ;WAVES
.DEF STRNGRAM,HEXTOASC,GETANIX,DMAHALT,WRLD,PSTOP
.BSS STRNGRAM,20*16
.BSS WRLD,16
.EVEN
.TEXT
**************************************************************************
* *
* HEXTOASC - CONVERTS A 32 BIT HEX # TO AN ASCII STRING TERMINATED *
* BY 0 *
* A8 = HEX # *
* RETURNS: *
* A8 PTR TO THE STRING *
* *
**************************************************************************
HEXTOASC
MMTM SP,A1,A2,A9
CLR A1
CLR A2 ;COMMA COUNT
MOVE A1,-*SP,W ;HERE'S THE NULL TERMINATOR
MOVK 10,A1 ;DIVISOR FOR DECIMAL
MOVE A8,A9
HEXTASC2
CLR A8
DIVU A1,A8
ADDI '0',A9 ;MAKE THE REMAINDER ASCII
MOVE A9,-*SP,W ;SAVE HERE
MOVE A8,A9
JRZ HEXTASC3 ;BR = DONE!
INC A2
CMPI 3,A2 ;COMMA CHECK
JRLO HEXTASC2 ;BR = NO COMMA
MOVI ',',A2
MOVE A2,-*SP,W ;STUFF A COMMA
CLR A2
JRUC HEXTASC2
HEXTASC3
MOVI STRNGRAM,A1 ;STORE HERE FOR BLOW OUT
MOVE A1,A8
HEXTASC4
MOVE *SP+,A9,W
MOVB A9,*A1
ADDK 8,A1
MOVE A9,A9
JRNZ HEXTASC4
MMFM SP,A1,A2,A9
RETS
**************************************************************************
* *
* STRINGER - OUTPUT A TEXT STRING, THIS IS A PROCESS! *
* A0 = SLEEP TIME BETWEEN CHARACTERS *
* A4 = DMA CONTROL *
* A6 = COLOR (16 BITS) *
* A8 = PTR TO STRING *
* A9 = [Y,X] SCREEN ADDRESS OF STRING *
* A10 = [Y,X] SPACING *
* A11 = POINTER TO FONT TABLE *
* A14 = FLAGS - INSERT:JUSTIFY *
* WRLD = ADJUST FOR WORLD COORDINATES
* BIT 16 = 1 INSERT ON OBJECT LIST, 0 JUST QUEUE THE DMA *
* JUSTIFY = 0 LEFT JUSTIFY *
* 1 CENTER JUSTIFY *
* 2 RIGHT JUSTIFY *
* RETURNS: *
* A8 = POINTS TO NEXT BYTE AFTER STRING TERMINATOR *
* A9 = NEXT CURSOR POSITION AFTER THE STRING *
* NOTE: CALL WITH JSRP *
* *
**************************************************************************
*
*STRING ENTRYPOINT, LEFT JUSTIFY, NORMAL, NOT PUT ON THE OBJECT LIST
STRLNRM
MMTM A12,A1,A4,A6,A14
MOVI DMACNZ,A4
CLR A14
JRUC STRINGR1
*
*STRING ENTRYPOINT, CENTER JUSTIFY, NORMAL, NOT ON THE OBJECT LIST
STRCNRM
MMTM A12,A1,A4,A6,A14
MOVI DMACNZ,A4
MOVK 1,A14
JRUC STRINGR1
*
*STRING ENTRYPOINT, RIGHT JUSTIFY, NORMAL, NOT PUT ON THE OBJECT LIST
STRRNRM
MMTM A12,A1,A4,A6,A14
MOVI DMACNZ,A4
MOVK 2,A14
JRUC STRINGR1
*
*STRING ENTRYPOINT, LEFT JUSTIFY, INVERTED, NOT ON THE OBJECT LIST
STRLINV
MMTM A12,A1,A4,A6,A14
MOVI DMACZ,A4
CLR A14
JRUC STRINGR1
*
*STRING ENTRYPOINT, CENTER JUSTIFY, INVERTED, NOT ON THE OBJECT LIST
STRCINV
MMTM A12,A1,A4,A6,A14
MOVI DMACZ,A4
MOVK 1,A14
JRUC STRINGR1
*
*STRING ENTRYPOINT, LEFT JUSTIFY, NORMAL, OBJECT LIST
STRLNRMO
MMTM A12,A1,A4,A6,A14
MOVI DMACNZ+M_NOCOLL,A4
MOVI 10000H,A14
JRUC STRINGR1
*
*STRING ENTRYPOINT, CENTER JUSTIFY, NORMAL, OBJECT LIST
STRCNRMO
MMTM A12,A1,A4,A6,A14
MOVI DMACNZ+M_NOCOLL,A4
MOVI 10001H,A14
JRUC STRINGR1
STRINGER
MMTM A12,A1,A4,A6,A14
STRINGR1
MOVE A6,A5
SLL 16,A5 ;SETUP CONSTANT COLOR IN FIXED PALETTE
CLR A7
MOVX A14,A7
DEC A7
JRN STRINGR2 ;NORMAL LEFT JUSTIFY
JREQ STRINGRC
*RIGHT JUSTIFY
CALLR STRNGLEN ;GET THE STRING LENGTH
JRUC STRINGRA
*CENTER JUSTIFY
STRINGRC
CALLR STRNGLEN
SRL 1,A7 ;STRNGLEN/2
STRINGRA
SUBXY A7,A9 ;ADJUST STRING STARTING POSITION
STRINGR2
MOVB *A8,A7 ;GET A CHARACTER
SLL 24,A7
SRL 24,A7 ;MAKE SURE WE'RE POSITIVE
JREQ STRINGRX ;BR = STRING BE GONE BROTHA
ADDK 8,A8 ;NEXT BYTE
PUSH A0
CMPI 20H,A7
JRNE STRNCHAR ;BR = IT'S KOSH BABY
MOVK 5,A7 ;HARD CODE A SPACE
ADDXY A7,A9 ;AND ADD IT IN
ADDXY A10,A9 ;ADD SPACING
PULL A0
JRUC STRINGR2 ;DON'T SLEEP ON A SPACE, IT LOOKS STUPID!!!
STRNCHAR
MMTM SP,A2,A3,A4,A10,A14
MOVE A11,A1 ;ESCAPE TO THE OTHER SIDE
SUBI 21H,A7 ;GET A BASE
SLL 5,A7
ADD A7,A1
MOVE *A1,A1,L ;LOAD THE ADDRESS OF THE IMAGE HEADER
CALLA GSAGOF
CALLA GANIOF
BTST 16,A14
JREQ STRNQDMA ;BR = DO NORMAL DMA OF STRING
*CREATE THE CHARACTER AS AN OBJECT, HERE
CALLA GETOBJ
JREQ STRNGDUN ;BR = NO OBJECT
MOVE A1,*A0(OIMG),L
MOVE A5,*A0(OPAL),L
; MOVE A4,*A0(OFLAGS),W
; MOVB @GOUP,A14
; JRZ NOUP
; MOVI -08000H,A14
; JRUC UP
;NOUP
CLR A14
;UP
MOVE A14,*A0(OYVEL),L
CLR A14
MOVE A14,*A0(OXVEL),L
MOVE A0,A14
ADDI OSIZE+20H,A14
MMTM A14,A2,A3,A4 ;STUFF VITAL SHIT!!!!
; CLR A14
; ADDI OZVEL+20H,A0
; ADDI OZPOS+20H,A0
; MOVK 6,A4
;STRNGOL
; MOVE A14,-*A0,L
; DSJS A4,STRNGOL ;ZERO OUT THE VELS & POSITIONS
; SUBI 64,A0 ;BACK TO NORMAL
MOVB @MYID,A14
; JRZ REG
; MOVI CLSNEUT|TYPTEXT|SUBSCOR,A14
JRNZ REG2
;REG
MOVI CLSNEUT|TYPTEXT|SUBTXT,A14
REG2
MOVE A14,*A0(OID),W ;STUF A FINDABLE I.D.
MOVE A9,A14
MOVE A14,*A0(OXPOS),W
SRL 16,A14
MOVE A14,*A0(OYPOS),W ;STUFF POSITIONS
MOVI 07FD1H,A14
; MOVI 07FFEH,A14
MOVE A14,*A0(OZPOS),W
MOVE @WRLD,A2,W
JRNZ NOADJST
CALLA ADJSTWTL ;PUT US IN THE WORLD
NOADJST:
CALLA INSOBJ ;STUFF THIS SHEEEEEEET
MMTM SP,A0,A2,A3,A4
MOVE *A0(OYVAL),A2,L
MOVE *A0(OXVAL),A3,L
MOVE *A0(OFLAGS),A4
CALLA GANISAG
MOVE A2,*A0(OYVAL),L
MOVE A3,*A0(OXVAL),L
;
;ADJUST ANI POINT
* GANISAG - ADJUST CURRENT OBJECT IMAGE WITH RESPECT TO IT'S *
* ANIMATION PNT. AND FLIP FLAGS *
* NOTE: CALL ONLY AFTER INITIALIZING WITH STFOBJ, OR SOMETHING. *
* A0 = PTR TO OBJECT BLOCK *
* A2 = NEW OYVAL *
* A3 = NEW OXVAL *
* A4 = NEW FLAGS *
* RETURNS *
* A2 = ADJUSTED OYVAL *
* A3 = ADJUSTED OXVAL *
MMFM SP,A0,A2,A3,A4
JRUC STRNGDUN
*SIMPLY DMA THE SUCKER, HERE
STRNQDMA
MOVE A1,A10
MOVE A5,A1 ;CONSTANT:PALETTE
MOVE A4,A5 ;OFFSET:CONTROL
MOVE A3,A4 ;SAG
CLR A14
MOVY A9,A14
CLR A3
MOVX A9,A3
SRL 16,A6
SUBXY A6,A3
SUBXY A7,A14 ;MOVE TO CORRECT POSITION
MOVY A14,A3 ;A3 = DAG
CALLA DMAN
MOVE A1,A5
MOVE A10,A1
STRNGDUN
MOVE *A1(ISIZE),A6,W ;GET THE VISIBLE HORIZONTAL SIZE
MMFM SP,A2,A3,A4,A10,A14
ADDXY A6,A9 ;GET TO THE OTHER SIDE
ADDXY A10,A9
MOVE *SP+,A0,L
JREQ STRINGR2 ;BR = NO SLEEP
MMTM A12,A0,A4,A5,A14
CALLA PRCSLP
MMFM A12,A0,A4,A5,A14
JRUC STRINGR2
STRINGRX
ADDK 8,A8 ;GET TO THE NEXT BYTE
MMFM A12,A1,A4,A6,A14
RETP
**************************************************************************
* *
* STRNGLEN - RETURNS THE LENGTH, IN PIXELS, OF A GIVEN STRING *
* A8 = PTR TO STRING *
* A10 = [Y,X] SPACING OF STRING *
* A11 = PTR TO FONT TABLE *
* RETURNS: *
* A7 = LENGTH OF STRING *
* Z BIT SET IF LENGTH IS ZERO *
* *
**************************************************************************
STRNGLEN
MMTM SP,A8,A14
CLR A14
MOVB *A8,A7
SLL 24,A7
SRL 24,A7 ;MAKE SURE WE'RE POSITIVE
JREQ STRNLENX
STRNLEN
ADDK 8,A8 ;POINT TO NEXT
CMPI 20H,A7
JRNE STRNLEN1 ;BR = IT'S NOT A SPACE
MOVK 5,A7 ;HARD CODE A SPACE
JRUC STRNLEN2
STRNLEN1
SUBI 21H,A7 ;GET A BASE
SLL 5,A7
ADD A11,A7 ;A7 = PTR TO CORRECT CHARACTER HEADER
MOVE *A7,A7,L
MOVE *A7(ISIZE),A7,W ;GET THE ACTUAL X LENGTH
STRNLEN2
ADDXY A7,A14 ;ADD DIGIT LENGTH
MOVX A10,A7
ADDXY A7,A14 ;ADD SPACE LENGTH
MOVB *A8,A7
SLL 24,A7
SRL 24,A7 ;MAKE SURE WE'RE POSITIVE
JRNE STRNLEN ;NEXT CHARACTER
STRNLENX
MOVE A14,A7 ;PASS RETURN VALUE IN A7
MMFM SP,A8,A14
RETS
**************************************************************************
* *
* OBJECT BLOCK INITIALIZATION ROUTINES *
* *
**************************************************************************
**************************************************************************
* *
* GPALOBJ - GET A PALETTE AND AN OBJECT BLOCK *
* A14 = PTR TO PLAYER INITIALIZATION TABLE. *
* RETURNS: *
* A0 = PTR TO OBJECT *
* Z BIT SET = FAILURE,A0 = 0 *
* *
**************************************************************************
GPALOBJ
CALLA GETOBJ
JRZ GPALOBJX ;OBJECT BLOCK FAILURE
CALLA INITPAL ;GET THE PALETTE
; JRNZ GPALOBJX
; CLR A0
; MOVE A0,@CURPAL,W
; CALLA FREEOBJ
; CLR A0
GPALOBJX
RETS
**************************************************************************
* *
* GBPALOBJ - GET A BACKGROUND PALETTE AND AN OBJECT BLOCK *
* A14 = PTR TO PLAYER INITIALIZATION TABLE. *
* RETURNS: *
* A0 = PTR TO OBJECT *
* Z BIT SET = FAILURE,A0 = 0 *
* *
**************************************************************************
GBPALOBJ
CALLA GETOBJ
JRZ GBPALOX ;OBJECT BLOCK FAILURE
CALLA INITBPAL ;GET THE BACKGROUND PALETTE
JRNZ GBPALOX
CALLA FREEOBJ
CLR A0
GBPALOX
RETS
*
*SHVELCPY - COPY VELOCITIES TO SHADOW (IF ANY)
*A8=OBJECT
*
;SHVELCPY:
; MMTM SP,A0,A1
; MOVE *A8(OSHAD),A0,L
; JREQ SHVLCPX
; MOVE *A8(OXVEL),*A0(OXVEL),L
;** MOVE *A8(OZVEL),A1,L
; MOVE *A8(OYVEL),A1,L
;** MOVE A1,*A0(OZVEL),L
; MOVE A1,*A0(OYVEL),L
;SHVLCPX:
; MMFM SP,A0,A1
; RETS
*
*SHVELFLP - COPY SHADOW VELOCITY AND FLIP HIM
*A8=OBJECT
*A3=OXVEL
;SHVELFLP:
; CALLR SHVELCPY
; MOVE *A8(OXVEL+>10),A14,W ;TEST X VELOCITY
*FLIPDUDE
*A8=OBJECT, N=SIGN OF XVEL
FLP:
JAN YFLP
JAUC NOYFLP
**************************************************************************
* *
* OBJOFF - TURN AN OBJECT "OFF" I.E. SET DMA OUTPUT TO 0 *
* A0 = PTR TO OBJECT BLOCK *
* *
**************************************************************************
OBJOFF
PUSH A4
MOVE *A0(OFLAGS),A4,W
SRL 4,A4
SLL 4,A4
MOVE A4,*A0(OFLAGS),W
PULL A4
RETS
**************************************************************************
* *
* OBJON - TURN AN OBJECT "ON" I.E. SET DMA OUTPUT TO WRITE <> 0 *
* A0 = PTR TO OBJECT BLOCK *
* *
**************************************************************************
OBJON
PUSH A4
MOVE *A0(OFLAGS),A4,W
SRL 4,A4
SLL 4,A4
ADDK 2,A4
MOVE A4,*A0(OFLAGS),W
PULL A4
RETS
**************************************************************************
* *
* Z POSITIONING ROUTINES *
* *
**************************************************************************
*
*XZCHK
*CALLING PARAMETERS:
*A8=OBJECT SEEKING
*A0=OBJECT SEEKED
*A5=X RANGE
*A6=Z RANGE
*RETURNS:
*CARRY SET IF HE IS CLOSE ENOUGH
*A1=DELTA X
*A2=DELTA Z
*A3=ABS DELTA X
*A4=ABS DELTA Z
;XZCHK:
; MOVE A0,A4
; CALLR GETANIX ;GET X ANIMATION POINT
; MOVE A0,A3
; SWAP A4,A8
; CALLR GETANIX
; MOVE A0,A1
; MOVE A8,A0
; MOVE A4,A8
; MOVE *A8(OZPOS),A4,W
; MOVE *A0(OZPOS),A2,W
; SUB A4,A2
; SUB A3,A1
; MOVE A1,A3
; MOVE A2,A4
; ABS A3
; ABS A4
; CMP A5,A3
; JRNC XZCHKX
; CMP A6,A4
;XZCHKX:
; RETS
**************************************************************************
* *
* CLRPDATA - CLEAR THE PDATA AREA OF A PROCESS BLOCK *
* A13 = PTR TO PROCESS BLOCK *
* *
**************************************************************************
;CLRPDATA
; MMTM SP,A1,A6,A14
; MOVE A13,A14
; CLR A1
; ADDI PDATA,A14
; MOVI (PSDATA-PDATA)/16,A6
;CLRSHL
; SRL 1,A6
; JRNC CLRPDL
; MOVE A1,*A14+,W ;STUFF THE ODD WORD
;CLRPDL
; MOVE A1,*A14+,L
; DSJS A6,CLRPDL
; MMFM SP,A1,A6,A14
; RETS
**************************************************************************
* *
* DFRMGRND - RETURNS THE DISTANCE FROM THE BOTTOM OF *
* AN OBJECT TO THE "GROUND." *
* A8 = OBJECT BLOCK *
* RETURN(S) *
* A1 = DISTANCE FROM GROUND (16 BITS) *
* STATUS BITS SET ACCORDING TO THE SIGN OF A1 *
* NOTE: MAX ACCEPTABLE Y = +32K, MIN ACCEPTABLE Y = -32K *
* *
**************************************************************************
;ZORIGIN EQU 200 ;Y COORDINATE OF THE Z ORIGIN
;DFRMGRND
; PUSH A2
; MOVE *A8(OYPOS),A1,W
; MOVE *A8(OSIZEY),A2,W
; ADD A1,A2 ;A2 = BOTTOM Y
; MOVE *A8(OZPOS),A1,W
; SUB A2,A1
; ADDI ZORIGIN,A1
; MMFM SP,A2
; RETS
**************************************************************************
* *
* GET BOTTOM Y OF AN OBJECT *
* A8 = OBJECT BLOCK PTR *
* RETURN(S) *
* A1 = 16 BIT BOTTOM Y IN LSW *
* STATUS SET ACCORDING TO THE BOTTOM Y *
*NOTE: MAKE SURE OBLOCK IS INIT'D WITH GSAGOF BEFORE CALLING *
* *
**************************************************************************
;GETBOTY
; PUSH A2
; MOVE *A8(OYPOS),A1,W ;GET Y POSITION
; MOVE *A8(OSIZEY),A2,W ;GET THE CURRENT SIZE
; ADD A2,A1 ;A1 = BOTTOM Y
; MMFM SP,A2
; RETS
**************************************************************************
* *
* GETCPNT - RETURNS THE CENTER XY POSITION OF A GIVEN IMAGE *
* A8 = IMAGE OBLOCK *
* RETURN(S) *
* A1 = CENTER Y:CENTER X *
* *
**************************************************************************
GETCPNT MOVE A0,-*SP,L
MOVE *A8(OYPOS),A0,W
SLL 16,A0
MOVE *A8(OXPOS),A1,W
MOVX A1,A0
MOVE *A8(OSIZE),A1,L
CALLR GETCENT
SLL 16,A0
MOVY A0,A1
MOVE *SP+,A0,L
RETS
**************************************************************************
* *
* GETCENT - RETURNS THE CENTER POINT OF A BOX *
* A0 = UPPER LEFT Y:UPPER LEFT X *
* A1 = Y_SIZE:X_SIZE *
* RETURN(S) *
* A0 = CENTER Y(LSW) *
* A1 = CENTER X(LSW) *
* *
**************************************************************************
GETCENT MOVE A2,-*SP,L
MOVY A1,A2
SRL 17,A2 ;YSIZE/2
SLL 16,A2 ;BACK TO Y HALF
SLL 16,A1 ;CLEAR Y
SRL 17,A1 ;XSIZE/2
MOVY A2,A1
ADDXY A1,A0 ;OFFSET TO CENTER
CLR A1
MOVX A0,A1 ;RETURN THESE IN USEFUL POSITIONS
SRL 16,A0
MOVE *SP+,A2,L
RETS
**************************************************************************
* *
* GETSCRRX - THE THE WORLD X COORDINATE OF THE SCREEN RIGHT END *
* RETURNS *
* A0 = SCREEN RIGHT X, 32 BITS *
* *
**************************************************************************
;GETSCRRX
; PUSH A2
; MOVE @SCRNLR,A0,W
; MOVE @WORLDTL,A2,W
; ADD A2,A0 ;GET SCREEN LOWER RT.
; SLL 16,A0
; PULL A2
; RETS
*
*GETANIX - GET ANIMATION POINT X COORD
*CALLING PARMS: A8=OBJECT
*RETURNS A0=16 BIT WORLD COORD OF UPPER LEFT
*
GETANIX:
MMTM SP,A1,A2
MOVE *A8(OIMG),A1,L
MOVE *A1(IANIOFF),A2,W
MOVE *A8(OFLAGS),A0,W
BTST B_FLIPH,A0
JRZ GETAX1
MOVE *A1(ISIZE),A0,W
SUB A2,A0
DEC A0
MOVE A0,A2
GETAX1:
MOVE *A8(OXPOS),A0,W
ADD A2,A0
MMFM SP,A1,A2
RETS
**************************************************************************
* *
* CLRWORLD - CLEAR ALL WORLD COORDINATES AND SCROLL VELOCITIES. *
* *
**************************************************************************
CLRWORLD
PUSH A0
CLR A0
MOVE A0,@SCROLLX,L ;X SCROLL VALUE
MOVE A0,@SCROLLY,L ;Y SCROLL VALUE
MOVE A0,@WORLDTLX,L ;TOP LEFT X SCREEN COORD (WORLD)
MOVE A0,@WORLDTLY,L ;TOP LEFT Y SCREEN COORD (WORLD)
MOVE A0,@WORLDTL,L
; MOVE A0,@BAK2TLY,L ;TOP LFT Y SLOW SCROLL BACKGROUND
; MOVE A0,@BAK2TLX,L ;TOP LFT X SLOW SCROLL BACKGROUND
MOVI SCRNST,A0
MOVE A0,@SCRNTL,L
MOVI SCRNEND,A0
MOVE A0,@SCRNLR,L
PULL A0
RETS
**************************************************************************
* *
* GETSCRBY - THE THE WORLD Y COORDINATE OF THE SCREEN BOTTOM *
* RETURNS *
* A0 = SCREEN BOTTOM Y *
* *
**************************************************************************
;GETSCRBY
; PUSH A2
; MOVE @SCRNLR+16,A0,W
; MOVE @WORLDTL+16,A2,W
; ADD A2,A0 ;GET SCREEN BOTTOM Y
; SLL 16,A0 ;MAKE IT A 32 BIT VALUE
; PULL A2
; RETS
**************************************************************************
* *
* MYOINIT - INITIALIZE SUPPLEMENTAL OBJECT LIST HEADERS *
* *
**************************************************************************
MYOINIT
MMTM SP,A0,A1,A2,A3,A4,A5
PUSHST
DINT
MOVE @INTENB,A0,W
ANDNI X1E,A0 ;NO MORE DMA INTERRUPTS
MOVE A0,@INTENB,W
POPST
CLR A0
MOVE A0,@GAMERASE
CALLA AUTOEOFF ;DISABLE AUTOERASE
CALLR DMAWAIT ;WAIT ON DMA
MOVI ERASECOL,A1
SLL 16,A1 ;CONSTANT:PALETTE
MOVI [2,511],A2 ;HEIGHT:WIDTH
MOVI [510,0],A3 ;DAG
MOVI 2000000H,A4 ;SAG
MOVI DMAREGS,A0
MMTM A0,A1,A2,A3,A4 ;STORE TO LAST 2 LINES OF BITMAP
CLR A5 ;STUFF OFFSET
MOVE A5,-*A0,W
MOVI DMACAL,A5 ;CONTROL &
MOVE A5,-*A0,W ;GO!
MMFM SP,A0,A1,A2,A3,A4,A5
JAUC OINIT
*************************************************************************
* *
* ADDSUPP - ADD OBJECT TO A SUPPLEMENTAL LIST *
* A0 = PTR TO OBJECT *
* A1 = MEMORY LOCATION OF SUPPLEMENTAL LIST HEADER *
* *
**************************************************************************
;ADDSUPP
; MOVE *A1(0),*A0(OSLINK),L ;LINK SLIST TO THIS BLOCK
; MOVE A0,*A1,L ;NEW HEAD OF THE SLIST
; RETS
**************************************************************************
* *
* DELSBOBJ - DELETE OBJECT FROM SUPPLEMENTAL BACKGROUND LIST *
* A0 = PTR TO OBJECT *
* *
**************************************************************************
;DELSBOBJ
; PUSH A1
; MOVI BACKSLST,A1
; CALLR DELSUPP
; PULL A1
; RETS
**************************************************************************
* *
* DELSUPP - DELETE OBJECT FROM THE SUPPLEMENTAL LIST *
* A0 = PTR TO OBJECT *
* A1 = MEMORY LOCATION OF SUPPLEMENTAL LIST HEADER *
* *
**************************************************************************
;DELSUPP
; MMTM SP,A1,A2
; MOVE A1,A2
; MOVE *A1,A1,L ;SPECIAL CASE THE HEADER
; JRNZ DELSCHK1
; LOCKUP
; JRUC DELSX
;DELSCHK1
; CMP A1,A0
; JRNE DELSLUP
; MOVE *A1(OSLINK),*A2(0),L ;LINK AROUND THIS GUY
;DELSX
; MMFM SP,A1,A2
; RETS
;
;DELSLUP ;
; MOVE A1,A2 ;SAVE PREVIOUS
; MOVE *A1(OSLINK),A1,L ;SEARCHING FOR THE ELEMENT IN THE LIST
; JRNZ DELSCHK2
; LOCKUP
; JRUC DELSX
;DELSCHK2
; CMP A1,A0
; JRNE DELSLUP ;NOT FOUND KEEP LOOKING
;
; MOVE *A1(OSLINK),*A2(OSLINK),L ;LINK AROUND THIS GUY
;
; MMFM SP,A1,A2
; RETS
**************************************************************************
* *
* ISSUPP - IS AN OBJECT ON A SUPPLEMENTAL LIST *
* A0 = PTR TO OBJECT *
* A1 = MEMORY LOCATION OF SUPPLEMENTAL LIST HEADER *
* RETURNS: *
* Z BIT SET = NOT ON *
* Z BIT CLR = IS ON *
* *
**************************************************************************
;ISSUPP
; PUSH A1
; MOVE *A1,A1,L ;SPECIAL CASE THE HEADER
; JREQ ISEND
; CMP A1,A0
; JRNE ISSEARCH
;ISFOUND
; MOVE A1,A1 ;SET Z BIT
;ISEND
; PULL A1
; RETS
;ISSEARCH
; MOVE *A1(OSLINK),A1,L ;SEARCHING FOR THE ELEMENT IN THE LIST
; JREQ ISEND ;ELEMENT DOES NOT EXIST
; CMP A1,A0
; JRNE ISSEARCH ;NOT FOUND KEEP LOOKING
; JRUC ISFOUND ;FOUND RETURN
;
**************************************************************************
* *
* ISSUPPID - IS AN OBJECT ON A SUPPLEMENTAL LIST(SEARCH BY OBJECT I.D.) *
* A0 = OBJECT I.D. *
* A1 = MEMORY LOCATION OF SUPPLEMENTAL LIST HEADER *
* RETURNS: *
* Z BIT SET = NOT ON *
* A1 = ZERO *
* Z BIT CLR = IS ON *
* A1 = PTR TO OBJECT *
* *
**************************************************************************
;ISSUPPID
; PUSH A2
; MOVE *A1,A1,L ;SPECIAL CASE THE HEADER
; JREQ ISENDID
; MOVE *A1(OID),A2,W
; CMP A2,A0
; JRNE ISSRCHID
;ISFNDID
; MOVE A1,A1 ;SET Z BIT
;ISENDID
; PULL A2
; RETS
;ISSRCHID
; MOVE *A1(OSLINK),A1,L ;SEARCHING FOR THE ELEMENT IN THE LIST
; JREQ ISENDID ;ELEMENT DOES NOT EXIST
; MOVE *A1(OID),A2,W
; CMP A2,A0
; JRNE ISSRCHID ;NOT FOUND KEEP LOOKING
; JRUC ISFNDID ;FOUND RETURN
**************************************************************************
* *
* CNTSUPP - COUNT THE NUMBER OF OBJECTS ON GIVEN SUPPLEMENTAL LIST. *
* A1 = SUPPLEMENTAL LIST *
* RETURNS: *
* A0 = OBJECT CNT *
* *
**************************************************************************
;CNTSUPP
; PUSH A1
; CLR A0
; MOVE *A1,A1,L
; JRZ CNTSUPPX
;CNTSUPPL
; INC A0
; CMPI NOBJ,A0
; JRHS CNTSUPPX ;WE'VE MAXED, SOMETHING IS WRONG
; MOVE *A1(OSLINK),A1,L
; JRNZ CNTSUPPL
;CNTSUPPX
; PULL A1
; RETS
**************************************************************************
* *
* RANDOM - GENERATE A RANDOM NUMBER *
* RETURNS: *
* A0 = 32 BIT RANDOM # *
* *
**************************************************************************
RANDOM: PUSH A1
MOVE @RAND,A0,L
SLA 1,A0
JRV RND2
ORI 2,A0
RND2: MOVE A0,@RAND,L
CLR A1
ADDC A1,A0 ;GET LAST BIT BACK TO MAKE 32
MOVE @HCOUNT,A1
RL A1,A0 ;RANDOM ROTATION
MOVE A0,A0 ;SET STATUS BITS
MMFM SP,A1
RETS
**************************************************************************
* *
* RANDU - GENERATE A UNIFORMLY DISTRIBUTED RANDOM # BETWEEN 1 AND [A0] *
* A0 = RANGE INPUT *
* RETURNS: *
* A0 = RANDOM # *
* *
**************************************************************************
RANDU: PUSH A1
MOVE A0,A1
CALLR RANDOM
MPYU A1,A0
INC A0
MMFM SP,A1
RETS
*
*GET SIGNED RANDOM # IN RANGE +/- A0
*CALLING PARAMETERS: A0
*RETURNS A0
*
SRAND:
MMTM SP,A1
MOVE A0,A1
SLL 1,A0
CALLA RANDU
SUB A1,A0
MMFM SP,A1
RETS
**************************************************************************
* *
* RANGRAND - GENERATE A RANDOM NUMBER IN A GIVEN RANGE. *
* B0 = LOWER BOUND *
* B1 = UPPER BOUND *
* RETURNS *
* A0 = RANDOM # *
* *
**************************************************************************
RANGRAND
PUSH A1
PUSH B1
SUB B0,B1 ;NORMALIZE THE RANGE
MOVE B1,A0 ;SET RANGE FOR RANDU
CALLR RANDU
MOVE B0,A1
ADD A1,A0
PULL B1
PULL A1
RETS
*
*RANDPER - RANDOM % ROUTINE
*CALLING PARAMETERS:
*A0=PROBABILITY OF EVENT (0-1000) P(A0=1000) = 1; P(A0=1) = 1/1000.
*RETURNS CS IF PROBABILITY IS TRUE, CC FOR FALSE
*RETURNS A0 = ACTUAL RANDOM # 0-999
RANDPER:
MMTM SP,A1,A2
MOVE A0,A2
CALLA RANDOM
MOVI 1000,A1
MPYU A1,A0
CMP A2,A0
MMFM SP,A1,A2
RETS
**************************************************************************
* *
* FILLAREA - FILL A GIVEN SQUARE AREA ON THE SCREEN WITH A COLOR *
* A1 = [COLOR,PALETTE] *
* A3 = DAG OF AREA [YPOS,XPOS] *
* A4 = [Y,X] SIZE OF AREA *
* *
**************************************************************************
FILLAREA
MMTM SP,A1,A2,A4,A5
JRUC AREACON
**************************************************************************
* *
* BLNKAREA - BLANK A GIVEN SQUARE AREA ON THE SCREEN *
* A3 = DAG OF AREA [YPOS,XPOS] *
* A4 = [Y,X] SIZE OF AREA *
* *
**************************************************************************
BLNKAREA
MMTM SP,A1,A2,A4,A5
CLR A1 ;CONSTANT 0:PALETTE 0
AREACON
MOVE A4,A2
MOVI 2000000H,A4 ;SOMEWHERE IN IMAGE ROM
MOVI DMACAL,A5
CALLR DMAN
MMFM SP,A1,A2,A4,A5
RETS
**************************************************************************
* *
* PFRAME - GET NEXT FRAME FROM ANIMATION LIST *
* A8 = POINTER TO OBJECT BLOCK *
* A11 = POINTER TO NEXT FRAME IN THE ANIMATION LIST *