forked from historicalsource/total-carnage
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNDSP1.ASM
1729 lines (1459 loc) · 36.6 KB
/
NDSP1.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
**************************************************************************
* GSP DMA OBJECT HANDLER
*
* VERSION 1.0 BY WARREN DAVIS 9/1/87
* VERSION 2.01 BY EUGENE JARVIS 10/25/87
* VERSION 3.0 BY EUGENE JARVIS 12/20/87
* VERSION 3.1 BY EUGENE JARVIS 7/4/88
* VERSION 3.2 BY EUGENE JARVIS 8/8/88
* VERSION 3.21 BY Shawn Liptak 7/24/91 - Minor improvements
* VERSION 3.3 BY Shawn Liptak 9/13/91 - More improvements
*
* COPYRIGHT (C) 1992 WILLIAMS ELECTRONICS GAMES, INC.
* ALL RIGHTS RESERVED.
*
*.Last mod - 1/7/92 13:45
**************************************************************************
.FILE "NDSP1.ASM"
.TITLE "GSP DISPLAY PROCESSOR VER. 3.3"
.WIDTH 132
.OPTION B,D,L,T
.MNOLIST
.include gsp.inc
.include sys.inc
.include macros.hdr
.INCLUDE MPROC.EQU
.INCLUDE DISP.EQU
.include "shawn.hdr" ;Macros
.if DEBUG
.include GAME.EQU
.endif
; .def QDMA
.def DMAQ,QDMAFLG,ANI ;FOR FILE SCORE USAGE
.DEF PULLOBJ
.REF HALT,GETFPAL,FRANIMQ
.if DEBUG
.ref SLDEBUG
.endif
* GLOBAL VARIABLES
.SECT "OFIXED"
OBJLST .LONG 0 ;POINTER TO ACTIVE OBJECT LIST
OFREE .LONG 0 ;POINTER TO FREE OBJECT BLOCK
ENDOFREE .LONG 0
BAKLST .LONG 0 ;BACKGROUND LIST
;BAK2LST .LONG 0 ;SLOW SCROLL BACKGROUND PLANE
.SECT ".text"
.BSS SCROLLX,32 ;X SCROLL VALUE
.BSS SCROLLY,32 ;Y SCROLL VALUE
.BSS WORLDTLX,32 ;TOP LEFT X SCREEN COORD (WORLD)
.BSS WORLDTLY,32 ;TOP LEFT Y SCREEN COORD (WORLD)
.BSS WORLDTL,32 ;PACKED TOP LEFT WORLD COORD
.BSS SCRNTL,32 ;TOP LEFT [Y,X] SCREEN (SCRN COORD.)
.BSS SCRNLR,32 ;LOWER RIGHT [Y,X] SCREEN (SCRN COORD.)
; .BSS BAK2TLY,32 ;TOP LFT Y SLOW SCROLL BACKGROUND
; .BSS BAK2TLX,32 ;TOP LFT X SLOW SCROLL BACKGROUND
.BSS QSYNC,16 ;SIGNALS ACTIVE Q
.BSS DMAQCUR,32 ;CURRENT DMAQ
.BSS DMAQCNT,16 ;CURRENT DMAQ COUNT
.BSS BOTQ0CNT,16 ;BOTTOM QUEUE COUNT #0
.BSS BOTQ1CNT,16 ;BOTTOM QUEUE COUNT #1
.BSS TOPQ0CNT,16 ;TOP QUEUE COUNT #0
.BSS TOPQ1CNT,16 ;TOP QUEUE COUNT #1
.BSS BOTQ0FLG,16 ;BOTTOM Q0 VALID FLAG VALID=NE
.BSS BOTQ1FLG,16 ;BOTTOM Q1 VALID FLAG VALID=NE
.BSS TOPQ0FLG,16 ;TOP Q0 VALID FLAG VALID=NE
.BSS TOPQ1FLG,16 ;TOP Q1 VALID FLAG VALID=NE
.BSS OBJSTR,NOBJ*OBSIZ ;OBJECT STRUCTURE LIST START
.BSS OBJLSTND,0 ;OBJECT LIST END
QSIZE .SET NOBJ*BQCELL ;SIZE OF QUEUES
.BSS BOTQ0,QSIZE ;BOTTOM OBJECT DMA Q #0
.BSS BOTQ1,QSIZE ;BOTTOM OBJECT DMA Q #1
.BSS TOPQ0,QSIZE ;TOP OBJECT DMA Q #0
.BSS TOPQ1,QSIZE ;TOP OBJECT DMA Q #1
.BSS DMAQ,QSIZE ;MISC. NON-SYNC DMA QUEUE
.BSS DISPLAYON,16 ;DO DISPLAY PROCESSING WHEN != 0
.BSS QDMAFLG,16 ;SPECIAL DMAQ BEING UPDATED=1
***************OVERLOAD
****> .BSS OVTOP,16 ;TOP SCREEN OVERLOAD
****> .BSS OVBOT,16 ;BOTTOM SCREEN OVERLOAD
* NO CODE BEFORE DMA INT!!! (Cache aligned)
********************************
* DMA INTERRUPT
DMAINT
mmtm b12,b6,b7,b8,b9 ;Stuff DMA regs
move b10,-*b12
move b11,-*b12
addi 0a0H,b12 ;DMAREGS (End of DMA)
subk 1,b13
jrle dmaint1 ;Queue empty?
subi 0140H,b14 ;Setup Q pull
mmfm b14,b6,b7,b8,b9,b10 ;Get data
move b10,b11
srl 16,b10
reti
dmaint1 callr DMANUQ ;Look to start a new q
reti
********************************
* GET NEW DMA Q CALLED FROM DMA INTERRUPT
DMANUQ
CLR B13
MOVE @TOPQ0FLG,B14
JREQ DMANUQ1
CLR B14
MOVE B14,@TOPQ0FLG
MOVE @TOPQ0CNT,B13
JREQ DMANUQ1
MOVE B14,@TOPQ0CNT
MOVI TOPQ0+(QSIZE),B14
JRUC DMANUQL
DMANUQ1 MOVE @TOPQ1FLG,B14
JREQ DMANUQ2
CLR B14
MOVE B14,@TOPQ1FLG
MOVE @TOPQ1CNT,B13
JREQ DMANUQ2
MOVE B14,@TOPQ1CNT
MOVI TOPQ1+(QSIZE),B14
JRUC DMANUQL
DMANUQ2 MOVE @BOTQ0FLG,B14
JREQ DMANUQ3
CLR B14
MOVE B14,@BOTQ0FLG
MOVE @BOTQ0CNT,B13
JREQ DMANUQ3
MOVE B14,@BOTQ0CNT
MOVI BOTQ0+(QSIZE),B14
JRUC DMANUQL
DMANUQ3 MOVE @BOTQ1FLG,B14
JREQ DMANUQX
CLR B14
MOVE B14,@BOTQ1FLG
MOVE @BOTQ1CNT,B13
JREQ DMANUQX
MOVE B14,@BOTQ1CNT
MOVI BOTQ1+(QSIZE),B14
DMANUQL SUBI 0A0H,B14
MMFM B14,B6,B7,B8,B9,B10 ;LOAD HER UP
MOVE B10,B11
SRL 16,B10
RETS
DMANUQX MOVE @INTENB,B14 ;DISABLE DMA INTERRUPT
ANDI 0FFFDH,B14
MOVE B14,@INTENB
RETS
********************************
* Load DMA Qs from obj list
* A0=*Obj list, A13=Screen BR, A14=Screen TL
* B4=World Y:X, B5=OFLAGS offset
.align
ldmaqlp move *a0(OXPOS),a10 ;
move *a0(OYVAL),a2,L ;Get int Y
movy a2,a10 ;A10=Obj Y:X
move b4,a6 ;A6=World TL Y:X
subxy a6,a10 ;-world coord to get screen coord
move b5,a3 ;Get OFLAGS offset
add a0,a3
mmfm a3,a12,a11,a9,a8
* CHECK FOR FLIPPING, NECESSITY OF CLIPPING, ADJUST OFFSET, SAG
* A3=AMOUNT TO CLIP OFF TOP, LEFT (TC,LC)
* A8=CONST:PALETTE
* A9=VS : HS
* A10=DAG (Y : X)
* A11=SAG
* A12=CONTROL WORD B0-15; OFFSET B16-31
;COMPUTE LC, RC, TC, BC
CLR A6 ;UPPER LEFT SCREEN COORDINATES
CLR A1 ;A1=USE FOR CLEARING NOW, BECOMES OFFSET LATER
MOVE A10,A2 ;
ADDXY A9,A2 ;A2=Obj BR Y:X
SUBXY A13,A2 ;PT - WEND -> A2 ( BC : RC )
JRYGE ldmaq10
MOVY A1,A2 ;CLEAR BC IF Y NEGATIVE
ldmaq10 JRXGE ldmaq20
MOVX A1,A2 ;CLEAR RC IF X NEGATIVE
ldmaq20 MOVE A14,A7 ;MOVE WSTART
CLR A3 ;
SUBXY A10,A7 ;WSTART - PT -> A7 (TC : LC)
JRYLT ldmaq30
MOVY A7,A3 ;TC IN UPPER HALF OF A3
MOVY A14,A10 ;ADJUST START POSITION TO WINDOW EDGE
ldmaq30 JRXLT ldmaq35
MOVX A7,A3 ;LC IN LOWER HALF OF A3
MOVX A14,A10 ;ADJUST START POSITION TO WINDOW EDGE
ldmaq35 MOVX A9,A6 ;GET TOTAL HORIZONTAL SIZE (MORSEL CORRECTED)
ADD A3,A2 ;(TC+BC : LC+RC) IN A2
JREQ NOCLIP ;TOTAL CLIP IS ZERO, NOCLIP
SUBXY A2,A9 ;GET CLIPPED SIZE...TOTALLY CLIPPED?
JRXLE NODIS ;Totally clipped?
JRYLE NODIS
;CLIP THE SAG, HS, VS, AND ADJUST OFFSET
MOVX A3,A1 ;GET LEFT CLIP
SRL 16,A3 ;GET TOP CLIP
JREQ CLIP1
MOVE *A0(OXCLIP),A7
ADD A6,A7 ;ADD PRECLIP TO THE WIDTH TO CALC NEW SAG
MPYS A7,A3 ;TOP CLIP X TOTAL HORIZ SIZE
CLIP1 SLL 16,A2
BTST B_FLIPH,A12
JREQ CLIP2
NEG A2 ;NEGATE RC+LC
NEG A1 ;NEGATE LC
CLIP2 BTST B_FLIPV,A12
JREQ CLIP3
NEG A3 ;NEGATE THS*TC
CLIP3 ADD A1,A3 ;ADD LEFT CLIP TERM + TC*THS
SLL 3,A3
ADD A3,A11 ;ADD TO SAG
ADD A2,A12 ;ADD CLIP OFFSET TO OFFSET
*BEAM AVOIDANCE, AT HALF SCREEN, DMA TOP HALF
* AT FULL SCREEN, DMA BOTTOM HALF
*B1=HALF SCREEN LINE COUNT
*B2=BOTTOM Q COUNT
*B3=TOP Q COUNT
*A4=BOTTOM DMA Q TO LOAD
*A5=TOP DMA Q TO LOAD
*A6=TOTAL HORIZONTAL SIZE
*A8=CONST:PALETTE XLATE
*A9=VSIZE:HSIZE
*A10=DESTINATION Y:X
*A11=IMAGE SAG
*A12=OFFSET:CONTROL
NOCLIP MOVE B1,A2 ;GET HALF SCREEN LINE NUMBER(Y ADJUSTED)
subxy a10,a2 ;WHERE'S THE IMAGE?
JRYLE BEAM_STKIMG ;Completely on the other side? Stack it
CMPXY A2,A9 ;DETERMINE HEIGHT ABOVE MID SCREEN
JRYLE BEAM_DODMA ;BR = YES, DMA AS IS
MOVE A9,B0 ;SAVE THE SIZES
MOVY A2,A9 ;STUFF NEW VSIZE AND DO IT
MMTM A5,A8,A9,A10,A11,A12 ;SAVE THE DMA REGS
INC B3
MOVE B0,A9 ;SET UP DMA REGS FOR BOTTOM HALF AND STACK EM
SRL 16,A2 ;Shift down the Y differential
MOVE *A0(OXCLIP),A3 ;ADD PRECLIP TO WIDTH
ADD A6,A3 ;WE NEED TS IN AN ODD REG. FOR 32 BIT MULT.
SLL 3,A3 ;TS = TS*8
MPYU A2,A3 ;A3 = SAG OFFSET
SLL 16,A2 ;Y DIFF BACK TO Y POS
SUBXY A2,A9 ;NEW VSIZE
ADDXY A2,A10 ;NEW DMA POSITION
BTST B_FLIPV,A12
JREQ BEAM_ADDSAG ;BR = SUBTRACT FOR NEW SAG BECAUSE OF VFLIP
NEG A3 ;SAG = -SAG
BEAM_ADDSAG
ADD A3,A11 ;SAG = SAG + OFFSET
BEAM_STKIMG
MMTM A4,A8,A9,A10,A11,A12 ;SAVE THE DMA REGS
INC B2
JRUC NODIS
BEAM_DODMA
MMTM A5,A8,A9,A10,A11,A12 ;SAVE THE DMA REGS
INC B3
NODIS move *a0,a0,L ;Get next link
jrnz ldmaqlp ;More?
rets
********************************
* DISPLAY OBJECT LIST - CALLED AT MIDSCREEN INTERRUPT
DISPLAY
move @QSYNC,a1
jrne disp1
MOVI BOTQ0+(QSIZE),A4 ;SETUP NEW INTERRUPT LOAD DMA QUEUES
MOVI TOPQ0+(QSIZE),A5
jruc disp2
disp1 MOVI BOTQ1+(QSIZE),A4 ;SETUP NEW INTERRUPT LOAD DMA QUEUES
MOVI TOPQ1+(QSIZE),A5
disp2 dint
move @INTENB,a0 ;Enable display interrupt
ori DIE,a0
move a0,@INTENB
eint
; move @DISPLAYON,a0
; jrz dispx ;Stop all new display processing?
move @HALT,a0
jrnz disp30 ;Skip vel update?
movi OBJLST,a0
callr vel_add
disp30
*CLIP AND LOAD DMA
*A4=BOTTOM DMA Q TO LOAD
*A5=TOP DMA Q TO LOAD
*B1=HALF SCREEN ADDRESS
*B2=BOTTOM Q COUNT
*B3=TOP Q COUNT
*B4=WORLD TOP LEFT [Y,X]
DCLIP
MOVI (HSINT-20)*010000H,B1 ;GET HALF SCREEN LINE #(Y ADJUSTED) ;27
CLR B3 ;TOP Q COUNT
CLR B2 ;BOTTOM Q COUNT
movi OFLAGS,b5 ;B5=PARAMETER LOCATION
move @DISPLAYON,a0
jrz disp100 ;Stop DMA of objects except for score?
; MOVE @SCROLLX,A6,L ;GET Y:X SCROLL VALUES
; MOVE @SCROLLY,A7,L
; SRA 1,A6
; SRA 1,A7 ;SCROLL 1/2 AS FAST
; MOVE @BAK2TLY,A14,L ;BACKGRD 2 SCREEN TL Y INTEGER:FRACTION
; MOVE @BAK2TLX,A13,L ;BACKGRD 2 SCREEN TL X INTEGER:FRACTION
; ADD A7,A14
; MOVE A14,@BAK2TLY,L
; ADD A6,A13
; MOVE A13,@BAK2TLX,L
; SRL 16,A13
; MOVX A13,A14 ;COMBINE TO FORM TOP LEFT Y:X
; MOVE A14,B4 ;SETUP WORLD TOP LEFT [Y,X]
; MOVE @SCRNTL,A14,L ;GET SCREEN BOUNDARIES
; MOVE @SCRNLR,A13,L
; MOVE @OVTOP,A0,W ;IF OVERLOAD SKIP BAK2 UPDATE
; MOVE @OVBOT,A1,W
; OR A0,A1
; JRNE DCLIP1
; MOVI BAK2LST,A0,L
; CALLR NODIS
;DCLIP1
MOVE @SCROLLX,A6,L ;GET Y:X SCROLL VALUES
MOVE @SCROLLY,A7,L
MOVE @WORLDTLY,A14,L ;SCROLL YOUR SCREEN FOLKS
MOVE @WORLDTLX,A13,L
ADD A6,A13
ADD A7,A14
MOVE A14,@WORLDTLY,L
MOVE A13,@WORLDTLX,L
SRL 16,A13
MOVX A13,A14 ;COMBINE TO FORM TOP LEFT Y:X
MOVE A14,B4 ;SETUP WORLD TOP LEFT [Y,X]
MOVE B4,@WORLDTL,L ;STORE THE WORLD TOP LEFT [Y,X]
MOVE @SCRNTL,A14,L ;GET SCREEN BOUNDARIES
MOVE @SCRNLR,A13,L
***********Z PLANE CHECK KLUDGE***********************************
*
* .GLOBAL PLZMIN
* MOVE @PLZMIN,A1,W
* SUBI 10,A1 ;FUDGE FACTOR
* MOVE @OBJLST,A0,L
* JREQ DISPBAK ;FORGET IT NULL LIST
* MOVE *A0(OZPOS),A2,W ;FIND STUFF IN BACK
* CMP A1,A2
* JRGE DISPBAK ;TEST FIRST ONE, NOTHING IN BACK
*DZCHL
* MOVE *A0(OZPOS),A2,W ;FIND STUFF IN BACK
* CMP A1,A2
* JRGE DZCHK1
* MOVE *A0,A0,L
* JRNE DZCHL
*
* MOVI OBJLST,A0,L ;EVERYTHINGS IN BACK
* CALLR NODIS
*
* MOVI BAKLST,A0,L
* CALLR NODIS
* JRUC DISPX
*
*DZCHK1:
* MOVE *A0,A1,L
* MMTM SP,A0,A1 ;SAVE OLD LIST POINTERS
* CLR A1
* MOVE A1,*A0,L ;ZERO OUT LIST (SPLIT IT UP)
*
* MOVI OBJLST,A0,L ;OUTPUT BACK OBJECTS
* CALLR NODIS
*
* MOVI BAKLST,A0,L ;OUTPUT BACKGROUND PLANE
* CALLR NODIS
*
* MMFM SP,A0,A1
* MOVE A1,*A0,L ;RESTORE LIST
* MOVE A0,A0
* CALLR NODIS1 ;PROCESS REST OF OBJECT LIST
* JRUC DISPX
*****************************************************************************
DISPBAK
MOVI BAKLST,A0,L
CALLR NODIS
MOVI OBJLST,A0,L
CALLR NODIS
;PUT DMA SCORE AREA ON TOP OF EVERYTHING!
disp100 MOVE @QDMAFLG,A2 ;Q BEING MODIFIED?
JRNZ DISPX0 ;YES, DON'T SCREW WITH IT
MOVE @DMAQCUR,A2,L
MOVI DMAQ+QSIZE,A1
CMP A1,A2
JREQ DISPX0 ;NONE
MOVE A1,@DMAQCUR,L ;RESET TOP OF QUEUE
DISPXL MOVE -*A1,-*A5,L ;TRANSFER YOUR Q'S
MOVE -*A1,-*A5,L
MOVE -*A1,-*A5,L
MOVE -*A1,-*A5,L
MOVE -*A1,-*A5,L
INC B3 ;INCREMENT COUNT
CMP A2,A1
JRHI DISPXL
DISPX0
MOVI NULLDMA,A0 ;PUT NULL DMA ON DMA QUEUES
MMFM A0,A8,A9,A10,A11,A12
MMTM A5,A8,A9,A10,A11,A12 ;NULL DMA JUNK TOPQ
MMTM A4,A8,A9,A10,A11,A12 ;NULL DMA JUNK BOTQ
.if DEBUG
move @SLDEBUG,a0
btst 3,a0
jrz skipline
move @ERASELOC,a1
movi 8,a0
move a0,@ERASELOC
move a1,@ERASELOC
skipline
.endif
move @QSYNC,a0
jrne dispx1
MOVE B2,@BOTQ0CNT
MOVE B3,@TOPQ0CNT
dispx rets
dispx1 MOVE B2,@BOTQ1CNT
MOVE B3,@TOPQ1CNT
rets
*NULL DMA DATA
NULLDMA .long 08000H,IROM,0,000010001H,0
********************************
* Velocity add loop
valp move a0,a1
addk 020H,a1 ;+OXVEL offset
mmfm a1,a9,a10,a11,a12 ;A12=XV, A11=YV, A10=X, A9=Y
add a11,a9 ;Add YVEL to YVAL
move a9,-*a1,L
add a12,a10 ;Add XVEL to XVAL (Uses hidden cycle!)
move a10,-*a1,L
vel_add move *a0,a0,L
jrnz valp ;!End?
rets
********************************
* ENABLE TOP DISPLAY QUEUES
DISPQT
MOVK 1,A0 ;ENABLE YOUR QUEUES
MOVE @QSYNC,A1
NOT A1
MOVE A1,@QSYNC
JRNE DISPQT1
MOVE A0,@TOPQ1FLG
jruc dmastrt
DISPQT1 MOVE A0,@TOPQ0FLG
jruc dmastrt
; MOVK 1,A1
; MOVE @DMACTRL,A0 ;DMA BUSY?
; JRN DISP3
; CLR A1 ;NO OVERLOAD
;DISP3 MOVE A1,@OVBOT ;STORE OVERLOAD
; jruc dmastrt
********************************
* PRIME DMA INTERRUPT FOR BOTTOM QUEUE
DISPH
MOVK 1,A0 ;ENABLE YOUR QUEUES
MOVE @QSYNC,A1
JRNE DISPH1
MOVE A0,@BOTQ1FLG
JRUC DISPH2
DISPH1 MOVE A0,@BOTQ0FLG
DISPH2
; MOVK 1,A1
; MOVE @DMACTRL,A0 ;DMA BUSY?
; JRN DISPH3 ;YES, DO NOT RESTART
; CLR A1
;DISPH3 MOVE A1,@OVTOP ;OVERLOAD INDICATOR
********************************
* START DMA IF APPROPRIATE
dmastrt
dint
move b13,b13
jrne dmastx ;If count > 0, DMA already going
callr DMANUQ ;Get new Q
move b13,b13
jrz dmastx ;zero count dont restart
move @INTENB,a0 ;enable dma interrupt
ori X1E,a0
move a0,@INTENB
move @DMACTRL,a0
jrn dmastx ;DMA busy?
movi DMAREGS,b12 ;Set B12 to DMAREGS
; clr a0
; move a0,@DMACTRL ;kill any pending NECESSARY???
trap 1 ;Cause DMA int
dmastx eint
rets
********************************
*QDMA PUTS IMAGE ON DMA Q
*INPUTS:
*A1=CONSTANT COLOR:PALETTE
*A3=DESTINATION Y:X
*A5=OFFSET:CONTROL
*A14=ADDRESS OF IMAGE HEADER
;QDMA
; MMTM SP,A2,A4,A13
; MOVE *A14,A2,L ;GET VSIZE:HSIZE
; MOVE *A14(ISAG),A4,L ;GET SAG
; MOVK 1,A13
; MOVE A13,@QDMAFLG ;Q BEING MODIFIED
; MOVE @DMAQCUR,A13,L
; CMPI DMAQ,A13
; JRLS QDMAX ;Q OVERLOAD, CAN IT
; MMTM A13,A1,A2,A3,A4,A5
; MOVE A13,@DMAQCUR,L
; CLR A13
; MOVE A13,@QDMAFLG
;
;QDMAX MMFM SP,A2,A4,A13
; RETS
********************************
* MANUAL DMA (SETUP YOUR OWN REGS)
* A1=CONSTANT COLOR:PALETTE
* A2=VSIZE:HSIZE
* A3=DESTINATION Y:X
* A4=SAG
* A5=OFFSET:CONTROL
* Trashes A0
QDMAN
movk 1,a0
move a0,@QDMAFLG ;Q being modified
move @DMAQCUR,a0,L
cmpi DMAQ,a0
jrls qdnx ;Q full?
mmtm a0,a1,a2,a3,a4,a5
move a0,@DMAQCUR,L
clr a0
move a0,@QDMAFLG
qdnx rets
**************************************************************************
* *
* STOPOBJS - ZEROS VELOCITIES FOR ALL OBJECTS ON OBJLST. *
* *
**************************************************************************
STOPOBJS
PUSH a0,a1
clr a0
movi OBJLST,a1
jruc so20
so10 MOVE A0,*A1(OXVEL),L
MOVE A0,*A1(OYVEL),L
so20 move *a1,a1,L
jrnz so10
PULL a0,a1
rets
********************************
* Sort object list in z:y priority
* Trashes A0-A7
.align
YZSORT movk 1,a1 ;Lowest Z
sll 31,a1 ;Make 080000000H
move a1,a5 ;Lowest Y
movi OBJLST,a0
jruc yzlp
yzlp0 move *a2(OZPOS),a6 ;Get Z
move *a2(OYPOS),a7 ;Get Y
cmp a1,a6
jrgt priok ;Next Z > Current Z?
jrlt priswap
cmp a5,a7 ;Next Y > Current Y
jrge priok
priswap dint ;>Make current after next
move a2,*a4,L ;Point last to next
move *a2,*a0,L ;Point current to block after next
move a0,*a2,L ;Point next to current
eint
move a2,a4
jruc yzlp ;Continue sort of current obj
priok move a0,a4 ;A4=*Last obj
move a2,a0 ;A0=*Current obj
move a6,a1 ;A1=Current Z
move a7,a5 ;A5=Current Y
yzlp move *a0,a2,L ;A2=*Next obj
jrnz yzlp0
rets
**************************************************************************
* TEST IF OBJECT ON SCREEN
*A8=OBJECT
*RETURNS Z IF ON SCREEN
*ENTER HERE AND PROVIDE YOUR OWN SCREEN BOUNDRIES
SCRTSTG
mmtm sp,a1,a2,a3
jruc scrtst1
*NORMAL SCREEN BOUNDRIES
SCRTST
mmtm sp,a1,a2,a3
move @SCRNTL,a2,L ;Get screen top left
move @SCRNLR,a3,L ;Get screen lower rgt
scrtst1 move *a8(OYPOS),a0
move *a8(OXPOS),a1
sll 16,a0
movx a1,a0 ;get top left of object
move @WORLDTL,a1,L
subxy a1,a0 ;subtract out world base
move *a8(OSIZE),a1,L
addxy a0,a1 ;get lower rt of object
cmpxy a3,a0 ;is it lower than lower rt?
JRYGE scrtf_d ;lower
JRXGE scrtf_r ;to the right
cmpxy a2,a1
JRYLE scrtf_u ;above...
JRXLE scrtf_l ;to the left..
mmfm sp,a1,a2,a3
clr a0 ;On screen Z
rets
scrtf_l movi 1,a0 ;Pass NZ
mmfm sp,a1,a2,a3
rets
scrtf_r movi 2,a0
mmfm sp,a1,a2,a3
rets
scrtf_u movi 3,a0
mmfm sp,a1,a2,a3
rets
scrtf_d movi 4,a0
mmfm sp,a1,a2,a3
rets
.if 0
********************************
*CLIP AN OBJECT
*INPUTS:
*A2=BOTTOM:RIGHT CLIP (RELATIVE TO CURRENT SIZE)
*A3=TOP:LEFT CLIP (RELATIVE TO CURRENT SIZE)
*A8=OBJECT BLOCK
*RETURNS
*NEW SAG,H,W,OFFSET,XCLIP IN OBJECT STRUCTURE
*ALL REGISTERS PRESERVED
CLIPOBJ
MMTM SP,A0,A1,A2,A3,A4,A5,A6,A7,A9,A11,A12
MOVE A8,A0
MOVE *A8(OXPOS),A4
MOVE *A8(OYPOS),A5
ADDI OFLAGS,A0 ;GET INDEX INTO OBJECT STRUCTURE
* A1 BECOMES OFFSET
* A6= TOTAL HORIZ. SIZE
* A9= VS:HS
* A11= SAG
* A12= OFFSET:FLAGS
MMFM A0,A9,A11,A12
MOVE *A8(OXCLIP),A7
CLR A6
MOVX A9,A6 ;GET TOTAL HORIZ SIZE
ADD A3,A2 ;LC+RC
SUBXY A2,A9 ;DECREASE H,W BY XCLIP,YCLIP
*CLIP THE SAG, HS, VS, AND ADJUST OFFSET
MOVX A3,A1 ;GET LEFT CLIP
SEXT A1
ADD A1,A4 ;ADJUST OXPOS
SRA 16,A3 ;GET TOP CLIP
ADD A3,A5 ;ADJUST OYPOS
JREQ OCLIP1
ADD A7,A6 ;ADD PRECLIP TO THE WIDTH TO CALC NEW SAG
MPYS A6,A3 ;TOP CLIP X TOTAL HORIZ SIZE
OCLIP1
ADDXY A2,A7
ZEXT A7,W ;NEW OXCLIP
SLL 16,A2
BTST B_FLIPH,A12
JREQ OCLIP2
NEG A2 ;NEGATE RC+LC
NEG A1 ;NEGATE LC
OCLIP2
BTST B_FLIPV,A12
JREQ OCLIP3
NEG A3 ;NEGATE THS*TC
OCLIP3
ADD A1,A3 ;ADD LEFT CLIP TERM + TC*THS
SLL 3,A3
ADD A3,A11 ;ADD TO SAG
ADD A2,A12 ;ADD CLIP OFFSET TO OFFSET
PUSHST
DINT
MMTM A0,A9,A11,A12
MOVE A4,*A8(OXPOS)
MOVE A5,*A8(OYPOS)
MOVE A7,*A8(OXCLIP) ;NEW OXCLIP
POPST
MMFM SP,A0,A1,A2,A3,A4,A5,A6,A7,A9,A11,A12
RETS
.endif
**************************************************************************
* *
* OBJECT BLOCK INITIALIZATION ROUTINES *
* *
**************************************************************************
**************************************************************************
* *
* OINIT - INITIALIZE FREE LIST *
* *
**************************************************************************
OINIT
MMTM SP,A0,A1,A2,A3 ;SAVE REG
CLR B13 ;CLEAR OUT DMA DEDICATED REGISTERS
CLR B14
MOVI NOBJ,A3 ;# OF OBJECT BLOCKS TO INIT
MOVI SCRNST,A0,L ;INIT SCREEN TOP LEFT [Y,X]
MOVE A0,@SCRNTL,L
MOVI SCRNEND,A0,L ;INIT SCREEN LOWER RIGHT [Y,X]
MOVE A0,@SCRNLR,L
PUSHST
DINT
MOVE @INTENB,A0,W
ANDNI X1E,A0 ;NO MORE DMA INTERRUPTS
MOVE A0,@INTENB,W
POPST
CLR A0
MOVE A0,@WORLDTLX,L
MOVE A0,@WORLDTLY,L
MOVE A0,@WORLDTL,L
; MOVE A0,@BAK2TLX,L
; MOVE A0,@BAK2TLY,L
MOVE A0,@DMAQCNT,W ;CLEAR CURRENT DMAQ COUNT
MOVE A0,@BOTQ0CNT,W ;CLEAR BOTTOM QUEUE COUNT #0
MOVE A0,@BOTQ1CNT,W ;CLEAR BOTTOM QUEUE COUNT #1
MOVE A0,@TOPQ0CNT,W ;CLEAR TOP QUEUE COUNT #0
MOVE A0,@TOPQ1CNT,W ;CLEAR TOP QUEUE COUNT #1
MOVI DMAQ+QSIZE,A1
MOVE A1,@DMAQCUR,L ;INIT MISC DMA QUEUE
MOVE A0,@SCROLLX,L ;CLEAR SCROLLX
MOVE A0,@SCROLLY,L ;CLEAR SCROLLX
; MOVE A0,@BAK2LST,L ;NULL BACKGROUND 2 OBJECT LIST
MOVE A0,@BAKLST,L ;NULL BACKGROUND OBJECT LIST
MOVE A0,@OBJLST,L ;NULL OBJECT LIST
MOVI OBJSTR,A1,L
MOVE A1,@OFREE,L ;SETUP FREE LIST
OINITL
MOVE A1,A2
ADDI OBSIZ,A1,W
MOVE A1,*A2,L ;LINK EM UP
DSJS A3,OINITL ;CONTINUE FOR NPROC
MOVE A0,*A2,L ;ZERO LAST LINK
MMFM SP,A0,A1,A2,A3 ;RESTORE REGS
RETS
**************************************************************************
* *
* GETOBJ - GET A FREE OBJECT BLOCK FOR USE *
* RETURNS *
* A0 = PTR TO OBJECT BLOCK *
* IF NO BLOCKS WERE AVAILABLE THEN THE Z FLAG IS SET *
* *
**************************************************************************
GETOBJ
move a2,*-sp,L
MOVE @OFREE,A0,L ;POINTER TO NEXT AVAILABLE OBJ BLOCK
JRZ NONELFT
MOVE *A0,A2,L
MOVE A2,@OFREE,L ;ADJUST POINTER TO FREE LIST
CLR A2
MOVE A2,*A0(OXCLIP) ;CLEAR CLIP
MOVE A2,*A0(OPLINK),L ;CLEAR LINK
MOVE A2,*A0(OFLAGS)
GETOX
move *sp+,a2,L
move a0,a0 ;Pass Z flag
rets
NONELFT
.IF DEBUG
LOCKUP
EINT
.ELSE
CALLERR 3,1
.ENDIF
JRUC GETOX
********************************
*FREE OBJECT WITH ERROR CHECKING
;FREEOBJE
; MMTM SP,A1,A2
; CMPI OBJSTR,A0
; JRHS FREEE1
;
; .IF DEBUG
; LOCKUP
;* CALLERR 2 ;PTR TOO LOW
; EINT
; .ENDIF
;
; JRUC FREERRX
;FREEE1
; CMPI OBJLSTND,A0
; JRLO FREEE2
;
; .IF DEBUG
;* CALLERR 2 ;PTR TOO HIGH
; LOCKUP
; EINT
; .ENDIF
;
; JRUC FREERRX
;FREEE2
; MOVE A0,A2
; SUBI OBJSTR,A2
; MOVI OBSIZ,A1
; MODU A1,A2
; JRZ FREEE3
;
; .IF DEBUG
;* CALLERR 2 ;PTR NOT VALID
; LOCKUP
; EINT
; .ENDIF
;
; JRUC FREERRX
;FREEE3
; CALLR ISOBJ
; JREQ FREEE4
;
; .IF DEBUG
;* CALLERR 2 ;OBJECT IS ON THE ACTIVE LIST
; LOCKUP
; EINT
; .ENDIF
;
; JRUC FREERRX
;FREEE4
; CALLR ISFREE
; JREQ FREEEC
;
; .IF DEBUG
;* CALLERR 2 ;OBJECT IS ALREADY ON THE FREE LIST
; LOCKUP
; EINT
; .ENDIF
;
;FREERRX
; MMFM SP,A1,A2 ;EXIT WITH ERROR
; RETS
;FREEEC
; MMFM SP,A1,A2 ;EVERYTHING IS O.K. CONTINUE TO FREEOBJ
********************************
*MAIN FREE OBJECT ENTRY
FREEOBJ
PUSH A2
MOVE @OFREE,A2,L
MOVE A2,*A0,L
MOVE A0,@OFREE,L ;BLOCK IS ON FREE LIST NOW
PULL A2
RETS
********************************
* PULLOBJ - PULL AN OBJECT BLOCK FROM AN OBJECT LIST
* DO NOT PUT IT BACK ON THE FREE LIST
* A0 = PTR TO BLOCK TO BE PULLED
PULLOBJ
MMTM SP,A2,A4
MOVI OBJLST,A4
PULLLOOP
MOVE A4,A2 ;PTR TO PREVIOUS IN A2
MOVE *A2,A4,L ;PTR TO NEXT IN A4
JRZ NOPULL ;BR = END OF LIST
CMP A4,A0 ;IS THIS THE GUY?
JRNE PULLLOOP ;BR = NO
MOVE *A0,*A2,L ;LINK AROUND THIS OBJECT
MMFM SP,A2,A4
RETS
NOPULL
.if DEBUG
LOCKUP
.endif
MMFM SP,A2,A4
RETS
********************************
* INSERT AN OBJECT BLOCK INTO AN OBJECT LIST
* LIST IS SORTED BY INCREASING Z AND INCREASING Y WITHIN CONSTANT Z