-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSUBS.ASM
5832 lines (4849 loc) · 138 KB
/
SUBS.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
;
;THIS ASSEMBLY CONTAINS LOW LEVEL SUBROUTINES THAT CORRESPOND TO THE
;DOCUMENT SUBS.DOC AS PUBLISHED BY COLOR DREAMS INC. THIS ASSEMBLY
;IS COPYRIGHTED 1989 BY COLOR DREAMS INC., ALL RIGHTS RESERVED.
;
;TO USE THIS ASSEMBLY, COPY THE OVERLAY FILE USERASM.ASM TO THE FILE
;NAME YOU WISH TO USE FOR YOUR ASSEMBLY. THEN SET THE ORIGIN IN THAT
;FILE AND PUT YOUR CODE INTO THE 3 LEGAL SUBROUTINE AREAS. THE 3 AREAS
;ALLOW BOOT UP INITILIZATION, NON-NMI PROCESSING, AND END OF NMI
;INTERRUPT PROCESSING.
;DO NOT PUT ANY CODE AT ANY OTHER LOCATION OR YOU MAY FIND IT VERY
;DIFFICULT TO UPDATE YOUR PROGRAM WHEN A NEW VERSION OF THIS MODULE
;COMES OUT. THE MODULE USERASM.ASM "INCLUDE"S THIS MODULE (SUBS.ASM)
;AND YOU NEED ONLY COPY NEW VERSIONS OF THIS MODULE IN ORDER TO TAKE
;ADVANTAGE OF A NEW ENHANCEMENT (REFER TO SUBS.DOC FOR MORE INFO).
;WHEN GETTING A NEW VERSION, CHECK THE REVISION HISTORY TO MAKE SURE THAT
;CALLING CONVENTIONS HAVE NOT CHANGED FOR SUBROUTINES USED BY YOUR CODE.
;
;
; *********************** REVISION HISTORY ****************************
;
;V 1.00 5/2/89.
;THIS VERSION DOES NOT SUPPORT 2 BY 2 MODE BACKGROUNDS OR OBJECTS AND
;BACKGROUNDS MUST BE AT LEAST 32 WIDE AND AT LEAST 30 HIGH.
;V 1.10 5/10/89
;THIS VERSION DOES NOT SUPPORT 2 BY 2 MODE BACKGROUNDS OR OBJECTS.
;ALSO, CALLS TO THE CHARACTER SET SELECT AND ANIMATION/SPRITE INIT
;ROUTINES SHOULD BE MADE ENTIRELY FROM EITHER THE NMI LEVEL OR FROM
;THE NON-NMI MAINLINE (EXCEPT FOR CALLS MADE AT BOOT). IF LEVELS
;ARE MIXED, THERE IS A SLIGHT CHANCE OF LOST SELECTIONS.
;BACKGROUND ANIMATION IS NOT SUPPORTED YET AND THERE IS NO SOUND OR
;GUN LOGIC. VERTICAL SCROLLING GETS CONFUSED SOMETIMES BUT IS USABLE
;FOR DEBUGGING YOUR GAME. HI-SCORE LOGIC IS UNTESTED.
;V 1.20 SAME AS 1.10 BUT BACKGROUND SCROLLING MUCH IMPROVED. PAL DURING
;VERTICAL SCROLL STILL GETS STAGGERED. ADDED BEEPA DEBUGGING ROUTINE.
;V 1.30 SOUND ADDED AND DEBUGGED. STILL NEEDS DOTTED NOTES. NO PUTOBJ,
;AND ANIMATION FEATURES NEED IMPROVEMENT. SEPERATED USER SUBS AREA
;INTO MODULE USERASM.ASM
;V 1.40. EXTENSIVE SPRITE ROUTINES ADDED TO ALLOW COLLISION DETECTION AND
;ANIMATION CONTROL. FIXED BUG IN SELSPSET THAT KILLED BACKGROUND SELECTION.
;V 1.50. ADDED TOP OF SCREEN STATUS BAR LOGIC.
;
;V1.60. ADDED CONTINUATION ABILITY TO THE COLLISION DETECTION SO THAT
;MULTIPLE COLLISIONS COULD BE DETECTED. GUN LOGIC INACTIVE AT THIS TIME.
;
;
;V1.70 GUN LOGIC INCLUDED BUT IT TAKES MORE MEMORY EVEN IF NOT USED.
;WILL TRY TO REMOVE IT BY USING "INCLUDE" BUT ASSEMBLER IS MAXED OUT
;ON INCLUDES AND CRASHES. NEW ABILITY TO "FLIP" A SPRITE FROM LEFT TO
;RIGHT HAS BEEN INCLUDED ALONG WITH THE ABILITY TO TURN IT UPSIDE DOWN.
;
;
;V1.80 GOT NEW ASSEMBLER AND MADE GUN LOGIC "INCLUDE". ALSO ADDED AUTOKILL
;FUNCTION FOR SPRITE ANIMATIONS. FIXED PUTOBJ BUG IN PAGE 2 (USED PAGE
;OFFSET OF 23). ADDED "TTY" CALLS.
;V1.81. FIXED GUN GETTING BAD Y LOCATION WITH GETSPRT IF SCANNING TARGETS.
;FIXED IMPROPER INIT OF SPRITE PALETTE REG 0 (IT OVERLAPS WITH BACKGROUND
;REG AND MUST NOT BE WRITTEN TO).
;V1.90 ADDED CODE TO TRIGGER AND DISABLE THE KEY CHIP CIRCUIT. THIS
; REQUIRES ANOTHER 200 BYTES OF ROM IN EACH PAGE AND ANY NEW USER'S
; WILL HAVE TO FREE THAT MUCH MEMORY.
;
;V1.91 ADDED PAGE 0 AND 1 CONTROL TO THE TTY ROUTINES. MADE THE TTY
; ROUTINES ADJUST FOR TOP OF SCREEN STATUS BAR. FIXED SOME
; BAD RAM INIT VALUES AT BOOT ON SOME MACHINES.
;
;V1.92 SPEEDED UP THE GUN LOGIC AND ADDED VIDEOREQ BYTE TO ALLOW VIDEO
; DISABLE AND ENABLE WITHOUT SCREEN WOBBLE.
;V1.93 ADDED CHANGEPAL AND SWAPSPRT.
;V1.94 REDUCED FLICKER OF SPRITES AND MADE MIRROR AND INVERT ALSO UPDATE
; THE SPRITE BLOCK WITHOUT NEED TO CALL ANOTHER ROUTINE.
;V1.95 FIXED SPRITE FLICKER. IT HAPPENED DUE TO TOP OF SCREEN STATUS BAR
; LOGIC.
;V1.96 SLIGHT IMPROVEMENT IN INITBACK FLICKER. ALSO IN TTY.ASM.
;V1.97 ADDED VARIABLES RESULTX AND RESULTY FOR USERS TO READ FOLLOWING
;MOVESPRT.
;V1.98 FIXED A BAD RETURN ON USEDINDX WHICH COULD CAUSE SYSTEM CRASH.
;V1.99 MAKE MOVESPRT STOP AT TOP IF SPRITE IS POSITIONED ABOVE TOPBAR
;AND SOLID IS BEING CHECKED. IT CHECKS FROM PIXEL ROW 0 RATHER THAN GOING
;INTO INVALID ROM AREAS.
;V2.00 ADDED VIDEOREQ BITS $80 AND $40 TO ALLOW CONTINUOUS SCROLLING
;BACKGROUNDS WHEN KILLBACK HAS BEEN USED TO TURN THEM OFF. A USER WRITTEN
;ROUTINE COULD NOT SET XSCROLL AND YSCROLL SMOOTHLY BECAUSE THAT ROUTINE
;ALSO NEEDED TO BE ABLE TO AFFECT REG2000 BIT 01 (PAGE SELECT) AT THE
;NEXT NMI.
;V2.01 ADDED YADJ AND SPYADJ AND FLASH.
;V2.02 ADDED LOSTX AND LOSTY.
;V2.03 ADDED BASESPRITE AND TOOMANY.
;V2.04 ADDED LOADALL.
;V2.05 ADDED ROUTINE NEGATE. MADE SPRITE SELECTION BY HORIZONTAL ALIGNMENT
;TAKE INTO ACCOUNT MIRRORING AND SELECT BACKWARDS IN THAT CASE
; ********************* SUBROUTINE RAM EQUATES *************************
;
;DO NOT REUSE THESE RAM AREAS WHEN DEFINING YOUR OWN EQUATES. ALSO, DO
;NOT PUT ANY OF YOUR DEFFINITIONS HERE, USE THE AREA PRECEEDING THE
;BOOT CODE THAT HAS BEEN RESERVED FOR THIS PURPOSE.
;
NMI_PTR= $00
BACKBASE= $02 ;BACKGROUND DATA PTR
BPAL_BASE= $04 ;BACKGROUND PALETTE REG DATA BASE PTR
SPAL_BASE= $06 ;SPRITE PALETTE REG DATA BASE PTR
SUBSVAR1= $08 ;VARIABLE FOR USE BY THE SUBS. OK TO
SUBSVAR2= $09 ;USE FROM BOTH NMI AND NON-NMI LEVEL
;BECAUSE ITS SAVED AT NMI. MUST STAY
;IN LOW RAM FOR A POINTER.
MAIN_PTR= $0A ;POINTER FOR USE BY MAINLINE ROUTINES
TOOMANY= $0C ;SET TRUE BY NMI IF LAST SCREEN PAINT HAD
;TOO MANY SPRITES ON THE LINE.
SAVE_SPRITES = $100 ;PLACE TO SAVE SPRITES LOCATION'S IF
;WE ARE SCANNING FOR A GUN. THIS IS THE
;LOW 64 BYTES OF THE STACK AREA AND THE
;STACK IS SIMPLE RESTRICTED WHEN SCANNING
;FOR A GUN HIT (ITS UNLIKELY TO PUSH THIS
;MUCH).
SPRAM = $200 ;SPRITE RAM. $200-$2FF
;STORED IN FORMAT REQUIRED BY NES VIDEO
;PROCESSOR EXCEPT FOR 1 BIT WE USE:
;1 BYTE VERTICAL SCAN LINE FOR TOP SPRITE ROW
;1 BYTE CHARACTER TO USE FROM CHAR SET
;1 BYTE PALETTE AND FLIP SPEC:
; 80H SET TO DISPLAY UPSIDE DOWN
; 40H SET TO DISPLAY MIRROR IMAGE
; 20H SET PUTS SPRITE BEHIND BACKGROUND
; 08H USED BY US TO MARK IN USE
; XXB = PALETTE TO USE (0-3)
;1 BYTE HORIZONTAL SCAN LINE FOR LEFT ROW
;THE FOLLOWING BUFFER IS USED TO HOLD ANY DATA TO BE WRITTEN TO THE
;SCREEN. THE BUFFER HOLDS LIMITED DATA AND THE LIMIT IS DESIGNED TO
;BE THE MAX WE CAN SAFELY WRITE TO THE SCREEN WITHOUT OVERFLOWING
;THE VERTICAL RETRACE. IF A ROUTINE WISHES TO WRITE TO SCREEN, IT
;SHOULD BE ACTIVATED FROM THE TAIL END OF NMI WITH FLAGS THAT ARE SET.
;THE FIRST THING THE ROUTINE SHOULD DO WHEN CALLED IS CHECK ITS FLAG
;TO SEE IF IT NEEDS TO WRITE TO SCREEN. IF IT DOES, IT SHOULD NEXT CHECK
;THIS BUFFER TO SEE IF IT CAN FIT ITS WRITE INTO THE REMAINING ROOM OF
;THE BUFFER. SCSIZE HAS THE MAX THE BUFFER CAN HOLD AND SCCNT HAS THE
;AMOUNT ALREADY THERE. IF THE BUFFER CAN'T HOLD THE SCREEN WRITE DATA
;THEN THE ROUTINE SHOULD LEAVE ITS FLAG SET AND FORGET IT THIS PASS
;OF NMI. IF THE BUFFER CAN HOLD THE DATA, IT SHOULD INDEX TO THE NEXT
;UNUSED POSITION IN THE BUFFER, AND PUT THE FOLLOWING DATA INTO THE
;BUFFER:
;
;HIGH BYTE OF SCREEN RAM LOCATION. BIT 80H SET IF NEED VERTICAL WRITE.
;LOW BYTE OF SCREEN RAM LOCATION
;1 BYTE LENGTH OF DATA TO WRITE
;DATA FOR LENGTH SPECIFIED.
;
;THEN THE ROUTINE SHOULD ADD THE TOTAL LENGTH OF THE ABOVE DATA TO
;THE VARIABLE SCCNT. AT NEXT NMI THE DATA WILL BE WRITTEN. NO ROUTINE
;SHOULD HOG EACH NMI OR IT MAY LOCK OUT OTHER ROUTINES.
SCBUF = $300 ;SCREEN WRITE BUFFER. LENGTH MAY CHANGE
SCSIZE = $60 ;AMOUNT THAT BUFFER CAN HOLD
SCCNT = $381 ;COUNT OF DATA IN BUFFER
BPAL_BLINK = $382 ;BACKGROUND PALETTE CONTROL RAM
BPAL_DEPTH = $383
BPAL_FREQ = $384
BPAL_INDX = $385
BPAL_CNT = $386
NEW_PAL = $387 ;BIT 01 SET IF NEW BACKGROUND PAL
;BIT 02 SET IF NEW SPRITE PAL
SPAL_BLINK = $388 ;BACKGROUND PALETTE CONTROL RAM
SPAL_DEPTH = $389
SPAL_FREQ = $38A
SPAL_INDX = $38B
SPAL_CNT = $38C
J1FLAGS = $38D ;JOYSTICK1 CURRENT STATE
J2FLAGS = $38E ;JOYSTICK2 CURRENT STATE. ON=BUTTON DOWN.
A_BUTTON = $80 ;80H = A button EQUATES TO MAKE IT
B_BUTTON = $40 ;40H = B button EASIER TO TEST J1FLAGS
SELECT = $20 ;20H = Select
START = $10 ;10H = Start
UP = 8 ;08H = Up
DOWN = 4 ;04H = Down
LEFT = 2 ;02H = Left
RIGHT = 1 ;01H = Right
J1CHANGE = $38F ;USED TO HOLD CHANGES IN JOYSTICK STATE
J2CHANGE = $390
REPCNT = $391 ;AUTOREPEAT COUNT DOWN TIMER
J1REPFLG = $392 ;HOLDS BIT FOR EACH J1 BUTTON AUTOREPEATING
J2REPFLG = $393 ;HOLDS BIT FOR EACH J1 BUTTON AUTOREPEATING
J1HOLD = $394 ;USED TO DELAY START OF AUTOREPEAT BY 1 REPEAT
J2HOLD = $395 ;USED TO DELAY START OF AUTOREPEAT BY 1 REPEAT
BEEPREG = $396 ;A BEEP ROUTINE VARIABLE
DOUBLE_BIT = $397 ;THIS VARIABLE TRACKS THE VALUE OF REG2000'S
;DOUBLE HIGH SPRITE BIT.
CLEARPASS = $398 ;TRUE IF WE ARE DOING A GUN CLEAR PASS.
;WE PAINT THE SCREEN BLACK.
VERIFYPASS = $399 ;TRUE IF WE ARE DOING A VERIFY PASS FOR THE
;GUN.
VERIFYFAILS = $39A ;NUMBER OF TIMES THE GUN VERIFY FAILED.
;INDICATES TV NEEDS ADJUSTING.
CURGUN = $39B ;0 OR 1 CURRENT LIGHT GUN THAT WE ARE CHECKING
;FOR A HIT. -1=NONE
GUNWAIT = $39C ;DELAY TO SLOW FIRING GUN.
; $39D ;2 COPIES THAT ARE INDEXED TO SUPPORT 2 GUNS.
TARGETNUM = $39E ;CURRENT TARGET BEING CHECKED BY GUNS
; $39F ;2 COPIES THAT ARE INDEXED TO SUPPORT 2 GUNS.
GUNREG = $3A0 ;USED TO TAKE SAMPLES OF THE GUN'S LIGHT BIT
; $3A1 ;DURING VIDEO SCANNING. THE FINAL SAMPLE
;IS MOVED INTO LIGHTBIT AT START OF NMI.
;THERE ARE 2 COPIES OF EACH VARIABLE BECAUSE
;THERE ARE 2 GUNS.
LIGHTBIT = $3A2 ;FALSE IF THE GUN SAW LIGHT LAST NMI CYCLE.
; $3A3 ;TRUE IF THE GUN DID NOT SEE LIGHT. FIRST
;COPY IS FOR GUN1, SECOND FOR GUN2.
BACKVALID = $3A4 ;TRUE IF THE BACKGROUND IS VALID. MAKE_SCROLL
;WILL NOT CHANGE SCROLL VALUES IF FALSE.
ROW = $3A5 ;USED WITH TTY TO HOLD THE CURSOR "ROW"
COL = $3A6 ;USED WITH TTY TO HOLD THE CURSOR "COLUMN"
TOPROW = $3A7 ;CURRENT ROW 0 FOR DISPLAY PURPOSES
SOLIDCHAR = $3A8 ;THE SOLID CHAR WE HIT WITH MOVESPRT
PAGETEMP = $3A9 ;FOR USE WITH THE PAGING LOGIC IN MEMORY.ASM
SPRITES_HIDDEN = $3AA ;SET DURING GUN SCANNING IF THE SPRITE'S Y
;LOCATIONS ARE ACTUALLY STORED IN LOW STACK
;RAM AT SAVE_SPRITES. THIS HAPPENS BECAUSE
;WE NEED TO HIDE SPRITES TO PUT UP THE GUN
;SPRITE BLOCK.
TTYBASE = $3AB ;SET TO $20 AT BOOT TO SPECIFY PAGE USED
;BY THE TTY ROUTINE.
GUNRELOAD = $3AC ;GUNDELAY RELOAD VALUE TO MAKE IT USER
;MODIFIABLE.
VIDEOREQ = $3AD ;VIDEO CHANGE REQUEST. USED BY NMI ROUTINE,
;ANYONE MAY SET BITS TO REQUEST FUNCTIONS:
;01 = DISABLE BACKGROUND VIDEO IN REG2001.
;02 = ENABLE BACKGROUND VIDEO IN REG2001
;40 = RESET BIT 01 IN REG2000
;80 = SET BIT 01 IN REG2000
;THE FOLLOWING BITS ARE VALID ONLY IF GUN
;LOGIC IS ACTIVE.
;
;04 = SET BACKGROUND COLOR TO GUN BLACK AND
; SPRITE COLOR 3 OF PALETTE 0 TO WHITE.
;08 = RESTORE BACKGROUND COLOR AND SPRITE
; COLOR 3, PALETTE 0.
LASTTARGET = $3AE ;TRUE IF WE HAVE NO MORE GUN TARGETS TO CHECK.
WORKINGPAGE = $3AF ;USED BY SELPAGE, COULD POSSIBLY BE FREED
BLACKCLR = $3B0 ;COLOR TO USE FOR GUN BLACK.
RESULTX = $3B1
RESULTY = $3B2 ;RETURNS X AND Y FOLLOWING MOVESPRT OR PUTSPRT
YADJ = $3B3 ;Y SCROLL ADJUSTMENT. USER SETTABLE.
SPYADJ = $3B4 ;SPRITE'S Y ADJUSTMENT. USER SETTABLE.
LOSTX = $3B5
LOSTY = $3B6 ;USED BY MOVESPRT
BASESPRITE = $3B7 ;BASE SPRITE TO LOAD AT. ALTERNATE BETWEEN
;0 AND $80 TO FLICKER THE SPRITES. ITS
;LOADED WITH 0 AT BOOT.
;3B8 - 3CA UNUSED
OURINDX = $3CB
COLL1 = $3CC
COLL2 = $3CD
COLL3 = $3CE
COLL4 = $3CF ;FOR USE WITH ROUTINE "COLLISION"
COLLINDX = $3D0 ;FOR USE WITH ROUTINE "NEXT_COLL".
REG4015 = $3D1 ;VOICE ENABLE REG CURRENT STATE
BPBASE = $3D2 ;BACKGROUND PALETTE INFO PTR
XOBJ = $3D4
YOBJ = $3D5 ;FOR PUTOBJ CALL
SUBSVAR3 = $3D6 ;NON-PTR CAPABLE SUBS FOR USE FROM ANY LEVEL.
SUBSVAR4 = $3D7
SUBSVAR5 = $3D8
SCRLDIF = $3D9 ;FOR USE BY SCROLL ROUTINE.
ROMPAGE = $3DA ;BITS 03H = PROGRAM ROM PAGE.
;BITS F0H = VIDEO ROM PAGE.
;BITS 0CH SHOULD BE LEFT OFF AT ALL TIMES.
MATH1 = $3DB ;TEMPORARY VARIABLES FOR USE BY MATH ROUTINES.
MATH2 = $3DC ;SAVED EACH NMI AND RESTORED TO ALLOW ALL
MATH3 = $3DD ;TO USE MATH ROUTINES. THESE MAY BE USED
MATH4 = $3DE ;AS TEMP VARIABLES ALSO BUT WILL BE CHANGED
;IF A MATH ROUTINE IS CALLED.
MOVEBACK = $3DF ;SET TRUE IF BACKGROUND NEEDS MOVING.
;BIT ORIENTED:
;01 = X MIGHT NEED SCROLLING
;02 = Y MIGHT NEED SCROLLING
BPWIDE = $3E0 ;WIDTH OF PALETTE INFO ASSOCIATED WITH BACKGRND
XBACK = $3E1 ;USER SET DESIRED X PIXEL LOCATION IN BACKGND
YBACK = $3E3 ;USER SET DESIRED Y
END_ROW = $3E5 ;USED TO ADJUST SCROLL POSITIONS
END_COL = $3E6 ;IN BACKGROUND MODE.
CURX = $3E7 ;CURRENTLY DRAWN X PIXEL BACKGROUND LOCATION
CURY = $3E9 ;CURRENTLY DRAWN Y PIXEL LOCATION
BACKSIZE = $3EB ;1 OR 2 SIZE OF BACKGROUND BLOCKS
BACKWIDE = $3EC ;WIDTH IN BLOCKS OF BACKGROUND
BACKHIGH = $3ED ;HEIGHT IN BLOCKS OF BACKGROUND
TMP_NMI1 = $3EE ;TEMPORARY VARIABLES TO USE DURING NMI INT.
TMP_NMI2 = $3EF ;RULES FOR USE: EVEN USER SUBS MAY USE
TMP_NMI3 = $3F0 ;THESE VARIABLES BUT NO ROUTINE SHOULD
TMP_NMI4 = $3F1 ;EXPECT ANY VALUES TO STAY HERE WHEN ANOTHER
TMP_NMI5 = $3F2 ;SUB IS CALLED UNLESS THAT ROUTINE
TMP_NMI6 = $3F3 ;SPECIFICALLY STATES THAT THE VARIABLES ARE
TMP_NMI7 = $3F4 ;NOT USED.
TMP_NMI8 = $3F5
TMP_NMI9 = $3F6
TMP_NMIA = $3F7
TMP_NMIB = $3F8
TMP_NMIC = $3F9
TMP_NMID = $3FA
TMP_NMIE = $3FB
XSCROLL = $3FC ;X SCREEN SCROLL VALUE
YSCROLL = $3FD ;Y SCREEN SCROLL VALUE
REG2001 = $3FE ;VALUE TO WRITE TO $2001 TO ENABLE VIDEO
REG2000 = $3FF ;THE VALUE WE WRITE TO $2000 MINUS NMI ENABLE
;****** SPRITE BLOCK AND ANIMATION RAM. ******
;
;THE SPRITE BLOCKS AND ANIMATION SPECIFICATIONS ARE STORED HERE. THE
;MAXIMUM NUMBER OF ACTIVE BLOCKS IS DETERMINED BY THE VARIABLE SPSLOTS.
;EACH BLOCK OR ANIMATION USES 7 BYTES OF RAM. YOU MAY CHANGE SPSLOTS
;BUT WATCH YOUR RAM USAGE. THIS VARIABLE IS IN USERASM.ASM
ANIM_WIDE = 11 ;WIDTH OF EACH ENTRY. NOT USER CHANGABLE.
SPMEM = SPSLOTS*ANIM_WIDE ;AMOUNT OF RAM USED BY THE SPRITE SLOTS
ANIM_RAM = $400 ;BASE SLOT OF ANIMATION/SPRITE RAM
;FORMAT:
FB = 0 ;FLAG BYTE: 0=SLOT AVAILABLE,
; 80H SET IF STRUCTURE NOT
; POSITIONED YET.
; 40H SET IF ANIMATION IS
; FROZEN.
; 20H SET IF ANIMATION UPDATE
; BY X ALIGNMENT.
; 10H SET IF ANIMATION UPDATE
; BY Y ALIGNMENT.
; 08H SET IF SOLID CHAR DEFINED.
;
; BITS 07 ARE STRUCTURE TYPE:
; 1=SPRITE, 2=SPRITE ANIM.,
; 3=OBJECT ANIMATION.
;
AF = 1 ;AUXILARY FLAGS:
; BITS 07H = SHIFT COUNT
; FOR ALIGNMENT BY X OR Y.
; BIT 20H = AUTOKILL IF SET.
; BIT 40H = MIRROR IMAGE.
; WHEN SET SPRITE IS FLIPPED
; FROM LEFT TO RIGHT.
; BIT 80H = UPSIDE DOWN
; WHEN SET SPRITE IS DISPLAYED
; UPSIDE DOWN FROM ORIGINAL
; SPECIFICATION.
PTRL = 2 ;WORD PTR TO DATA OR ANIMATION LIST
PTRH = 3
BS = 4 ;IF SPRITE, BASE SPRITE*4 INDEX (BYTE).
;IF OBJECT ANIMATION THEN LOW 4 BITS ARE
;COLUMN POSITION/4, HIGH ARE ROW POSITION/4
NS = 5 ;IF SPRITE, NUMBER OF SPRITES (BYTE).
;IF OBJECT, BIT 80H SET IF REFRESH NEEDED.
; BITS 7FH ARE AMOUNT OF RAM NEEDED
; TO WRITE AN UPDATE OUT.
FR = 6 ;CURRENT ANIMATION FRAME (BYTE)
CN = 7 ;COUNT DOWN TO NEXT FRAME CHANGE (BYTE)
RL = 8 ;RELOAD VALUE FOR COUNT DOWN (BYTE). INITIALLY
; LOADED WITH VALUE FROM ANIMATION, THEN
; ITS USER CHANGEABLE.
SL = 9 ;SOLID CHAR VALUE. ONLY VALID IF SOLID
; DEFINED BIT SET IN FLAGS.
ABL = 10 ;BLINK COUNTER. IF TRUE, HERO IS BLINKING.
;HE WILL BLINK FOR THIS MUCH IN 1/60 TICKS.
;HERE ARE THE SOUND SLOTS. THEY FOLLOW THE SPRITE SLOTS IN MEMORY AND
;USE THE EQUATES ABOVE TO DETERMINE THEIR BASE LOCATION. ALL SLOT ORIENTED
;STRUCTURES SHOULD FOLLOW THIS STRATEGY OF CALCULATING THEIR LOCATION
;BASED ON THE PREVIOUS NUMBER OF SLOTS. YOU CAN CHANGE THE NUMBER
;OF SOUND STRUCTURES BY SETTING SNDSLOTS IN USERASM.ASM
SND_WIDE = 7 ;WIDTH OF EACH ENTRY. NOT USER CHANGABLE.
SNDMEM = SNDSLOTS*SND_WIDE ;AMOUNT OF RAM USED BY THE SPRITE SLOTS
SND_RAM = $400+SPMEM ;BASE SLOT OF ANIMATION/SPRITE RAM
;FORMAT:
SF = 0 ;SOUND FLAG: BIT 80H SET IF SLOT IN USE.
; BIT 40H SET IF SOUND HAS NOT
; BEEN ASSIGNED TO A REGISTER SET.
; BIT 20H SET IF SOUND SUSPENDED
; BY ANOTHER VOICE.
; LOW BITS SPECIFY LOW BYTE OF
; REGISTER SET BASE (0,4,8,ETC).
ST = 1 ;SOUND TIMER. LOADED WITH NOTE OR PAUSE
; DURATION IN 1/60 SECOND TICKS.
SBL = 2 ;BASE POINTER (WORD) TO THE ORIGINAL SOUND
SBH = 3 ; STRUCTURE PASSED IN CALL.
SOL = 4 ;SOUND OFFSET OF CURRENT PLAY LOCATION.
SOH = 5
SI = 6 ;INSTRUMENT CURRENTLY ACTIVE. USED TO
; RESTORE SOUND IF SUSPENDED.
;************************** BOOT VECTOR ************************
;
;THIS BOOT VECTOR IS FOR THE SUBROUTINES. DON'T PUT YOUR CODE HERE,
;PUT IT IN THE LEGAL BOOT SUBROUTINE "USER_BOOT" AT THE END OF THIS ASSEMBLY.
;THIS ROUTINE SIMPLE DISABLES VIDEO AND NMI, WAITS FOR THE VIDEO PROCESSOR
;TO RESET, AND THEN INITIALIZES OUR VARIABLES. CODE WILL EVENTUALLY
;BE ADDED TO WORK IN CONJUNCTION WITH SPECIAL FEATURES OF THE COLOR
;DREAMS INC. CARTRIDGES BUT THIS IS NOT YET RELEASED INFO.
BOOT: SEI ;DISALLOW IRQ INTERRUPTS
LDA #0
STA $2000 ;MAKE SURE NMI INTS ARE OFF
;WAIT FOR VIDEO SYNC PULSES. WE NORMALLY JUST NEED TO DO THIS AT BOOT
;TO WAIT FOR THE VIDEO TO GET OUT OF RESET. AFTER THIS KEY CHIP LOGIC
;THIS IS PROBABLY UNNECESSARY.
JSR VERT_WAIT
JSR VERT_WAIT ;WAIT FOR 2 TO MAKE SURE BIT IS VALID
LDA #6
STA $2001
;INCLUDE( PULSES.ASM) ;DO THE KEY CHIP LOGIC.
.include "PULSES.ASM"
;INITIALIZE THE VARIABLES WE USE.
LDA #0 ;This is located at $0058 of the rom
STA NEW_PAL ;RESET FLAG OF PALETTE NEEDS INIT
STA ROMPAGE ;CLEAR THE VIDEO AND PROGRAM ROM PAGES
STA SCCNT ;ZERO DATA TO WRITE TO SCREEN
STA XSCROLL
STA YSCROLL ;ZERO SCROLL
STA CURX
STA CURY ;ZERO BACKGROUND SCROLL LOW VALUES FOR PUTSPRT
STA BACKVALID
STA MOVEBACK ;RESET FLAG TO SCROLL BACKGROUND
STA BPAL_BLINK
STA SPAL_BLINK ;PREVENT PALETTE UPDATES
STA J1FLAGS
STA J2FLAGS
STA J1HOLD
STA J2HOLD
STA J1REPFLG
STA J2REPFLG ;RESET BUTTON LOGIC
STA REG2000 ;AND ZERO SCREEN PAGE
STA DOUBLE_BIT
STA REG4015 ;AND SOUND ENABLE REG
STA SPRITES_HIDDEN
STA VERIFYFAILS ;RESET GUN TARGET FAILURES
STA VIDEOREQ
STA YADJ
STA SPYADJ
STA BASESPRITE
LDA #GUNDELAY ;$00A8
STA GUNWAIT ;RESET GUN DELAYS
STA GUNWAIT+1
STA GUNRELOAD ;SET RELOAD VALUE
LDA #-1
STA CURGUN
LDA #REPRATE
STA REPCNT ;RELOAD THE JOYSTICK REPEAT RATE
LDA #$20
STA TTYBASE ;$00BF
;Evenball: I'm confused... Is all the stuff below for GUNLOGIC or what?
;IFDEF( `GUNLOGIC', `
.ifdef GUNLOGIC
LDA #14
STA BLACKCLR ;SET BLACK FOR THE GUN', )
LDA #$1E
STA REG2001 ;SET UP FOR SPRITES, BACKGROUND, NO ODD COLORS
;AND 32 COL MODE FOR ALL.
JSR HIDESPRITES ;FREE UP AND HIDE THE SPRITES
JSR CLEARTOP ;AND CLEAR THAT SCREEN AREA
JSR ZERO_ANIM ;CLEAR THE ANIMATION RAM
JSR TOPSPRITE ;IF TOP SCREEN STATUS, MOVE SPRITE #0
;IFDEF( `GUNLOGIC', JSR GUNSPRITE, ) ;IF GUN ENABLED, TAKE OVER SPRITES
JSR GUNSPRITE ;I added this because I think the ifdef is redundant
;-Evenball
JSR ZERO_SOUND
;CALL THE USER'S BOOT CODE.
JSR USER_BOOT
;ALLOW NMI INTERRUPTS.
LDA REG2000
ORA #$80 ;ENABLE NMI INTS
STA $2000
;NON-INTERRUPT MAINLINE. WE TAKE LIGHT GUN SAMPLES AND
;CALL THE USER NON-NMI PROGRAM.
B1000: JSR USER_MAINLINE
;IFDEF( `GUNLOGIC', JSR AND_GUN, ) ;TAKE A LIGHT GUN SAMPLE
JSR AND_GUN ;I added this because I think the ifdef is redundant
;-Evenball
JMP B1000
.endif
;********************** USER SELECTABLE CODE AREA *******************
;
;THIS AREA JUST "INCLUDES" THE MODULES CALLED AS CHANGABLE
;SUBS AT VARIOUS POINTS IN THE PROGRAM. FOR INSTANCE, TO PUT A TOP
;SCORE STATUS BAR AT SCREEN TOP REQUIRES DIFFERENT LOGIC THAN TO NOT
;PUT ONE. THERE ARE 2 FILES DEFINED AND ONE FILE IS LOADED DEPENDING
;ON THE SITUATION. THE USER DEFINES A VARIABLE "TOPBAR" IN HIS
;USERASM FILE AND IF THIS IS DEFINED THEN THE TOP OF SCREEN STATUS FILE
;IS LOADED. OTHERWISE THE NORMAL FILE IS LOADED. BOTH FILES CONTAIN
;THE EXACT SAME SUBS BY NAME AND THESE ARE CALLED AT VARIOUS POINTS IN
;THE PROGRAM. THEY WILL BEHAVE DIFFERENTLY DEPENDING ON WHAT WAS LOADED.
;THESE VARIABLE FILE LOADS CONTROL THE TOP AND BOTTOM OF SCREEN STATUS
;BARS.
;IFDEF( `TOPBAR', `INCLUDE( TOPSTAT.ASM)', )
.ifdef TOPBAR
.include "TOPSTAT.ASM"
.endif
;IFDEF( `TOPBAR', , `INCLUDE( NORMTOP.ASM)')
; Evenball: I'm assuming the double , means ifndef
;Added by Evenball. I'm not sure where this code came from
;This code starts at $00C2 in the retail rom
.byte $A9, $1E, $8D, $FE, $03, $20
.byte $29, $9E, $20, $F2, $80, $20, $6D, $8C
.byte $20, $F2, $80, $20, $C5, $84, $20, $8B
.byte $CE, $AD, $FF, $03, $09, $80, $8D, $00
.byte $20, $20, $C1, $CE, $4C, $D1, $80
.ifndef TOPBAR
.include "NORMTOP.ASM"
.endif
;THIS FILE IS LOADED IF THE PROGRAMMER WANTS LIGHT GUN SUPPORT
;IFDEF( `GUNLOGIC', `INCLUDE( GUN.ASM)', )
.ifdef GUNLOGIC
.include "GUN.ASM"
.endif
;THIS FILE IS LOADED IF THE USER WANTS TTY OUTPUT ROUTINES
;IFDEF( `TTYFLG', `INCLUDE( TTY.ASM)', )
.ifdef TTYFLG
.include "TTY.ASM"
.endif
;************************ NMI INTERRUPT ***************************
;
;THIS IS THE NMI SERVICE ROUTINE. IT COMPLETELY CONTROLS ALL WRITES
;TO THE SCREEN AND YOUR CODE SHOULD NOT VIOLATE THIS SCHEME OR YOU
;MAY LOOSE COMPATIBILITY WITH THESE SUBS. IF YOU WANT TO DO PROCESSING
;UNDER NMI (AND IT IS STRONGLY RECOMMENDED THAT ALL OF YOUR PROCESSING
;IS DONE IN THIS MANNER) PUT YOUR CODE INTO THE ROUTINE "USER_NMI"
;AT THE END OF THIS ASSEMBLY. IF YOU WANT TO WRITE TO RAM, FOLLOW
;THE RULES FOR PUTTING DATA INTO SCBUF. SEE THE COMMENTS ON SCBUF
;IN THE RAM EQUATES.
;THIS NMI ROUTINE USES THE FOLLOWING STRATIGY:
;
;1. ALL DATA TO WRITE TO SCREEN IS KEPT IN A BUFFER WHICH CANNOT
;HOLD MORE THAN CAN BE SUCCESSFULLY WRITTEN. AT NMI START, THE
;SPRITES DMA TRANSFER IS STARTED AND THEN WHATEVER IS QUED IN THE
;BUFFER IS WRITTEN. THEN VIDEO IS RE-ENABLED (BUT NOT NMI INTS).
;
;2. ROUTINES THAT SET FLAGS TO GET PROCESSOR POWER OFF THE NMI TICK
;ARE CALLED IF THEIR FLAGS ARE SET. THEY ONLY CALCULATE AND PUT DATA
;INTO THE SCREEN BUFFER, THEY NEVER ACCESS VIDEO DIRECTLY. IF THEY
;CANNOT FIT THEIR DATA IN THE BUFFER THEY IGNORE THIS NMI.
;
;3. THE JOYSTICK IS CHECKED AND THE USER JOYSTICK ROUTINES ARE CALLED
;FOR ALL CHANGES.
;
;4. THE USER PROGRAM NMI PROCESSOR ROUTINE IS CALLED. THIS ROUTINE
;MUST ALSO USE ONLY THE BUFFER OR THE SUBROUTINES AND MUST NOT WRITE
;TO VIDEO.
;TRANSFER THE DMA AND WRITE OUT THE SCREEN BUFFER.
;located at $8236 logically, $0246 in rom
NMI: PHA
TXA
PHA
TYA
PHA ;SAVE THE REGISTERS
LDA REG2000
AND #$7F ;DISABLE NMI
STA $2000
LDA $2002 ;RESET ADDRESS REG SELECT FOR THROUGHOUT NMI.
AND #$20
STA TOOMANY
LDA #06
STA $2001 ;DISABLE VIDEO TO ALLOW SCREEN ACCESS
LDA BASESPRITE
STA $2003 ;ZERO THE SPRITE INDEX REG OR LOAD WITH THE $0262
;USER SELECTED VALUE.
LDA $2004 ;$0265
LDA $2004
OOOP: LDA #SPRAM >> 8 ;GET PAGE OF SPRITE RAM
STA $4014 ;START THE SPRITE RAM DMA TRANSFER
JSR WRITE_SCBUF ;WRITE OUT ANY DATA IN SCBUF $0270
JSR MAKE_SCROLL ;SCREEN UPDATED, MAKE ANY NEW SCROLL NEEDED
;IFDEF( `GUNLOGIC', JSR GET_SAMPLE, ) ;TAKE THE LAST SAMPLE AND PUT FOR
;GUN SUBS. RESET THE LIGHT SAMPLE.
.ifdef GUNLOGIC
JSR GET_SAMPLE
.endif
;SEE IF ANY CHANGES TO THE VIDEO STATE HAVE BEEN REQUESTED.
LDA VIDEOREQ ;$0276
BEQ N100
AND #1 ;DISABLE BACKGROUND VIDEO?
BEQ N20
EOR VIDEOREQ
STA VIDEOREQ ;RESET THAT BIT
LDA REG2001
AND #$F7 ;DISABLE BACKGROUND VIDEO
STA REG2001
N20: LDA VIDEOREQ ;SEE IF ENABLE VIDEO $028C
AND #2
BEQ N25
EOR VIDEOREQ
STA VIDEOREQ
LDA REG2001
ORA #8
STA REG2001
N25: LDA VIDEOREQ ;$02A2
AND #4 ;BLACKEN PALETTE AND WHITEN SPRITES?
BEQ N27
EOR VIDEOREQ
STA VIDEOREQ
;IFDEF( `GUNLOGIC', JSR BLACKEN_PAL, )
.ifdef GUNLOGIC
JSR BLACKEN_PAL
.endif
N27: LDA VIDEOREQ ;$02AF
AND #8 ;RESTORE PALETTE COLOR AND SPRITES?
BEQ N28
EOR VIDEOREQ
STA VIDEOREQ
N28: LDA VIDEOREQ ;$02BC
AND #$C0 ;SEE IF NEED STATE CHANGE TO REG2000
BEQ N30
TAX
EOR VIDEOREQ
STA VIDEOREQ
TXA
BPL N29
LDA REG2000
ORA #1
STA REG2000
JMP N30
N29: LDA REG2000
AND #$FE
STA REG2000
;IFDEF( `GUNLOGIC', JSR FIXPAL, )
.ifdef GUNLOGIC
JSR FIXPAL
.endif
N30: LDA #0
STA VIDEOREQ ;REMAINING BITS INVALID
;DONE WRITING OUT THE SPRITE AND SCREEN DATA. USE THE CORRECT LOGIC
;TO ENABLE VIDEO AND SCROLL AS NEEDED. THE 2 POSSIBILITIES ARE
;TOP OF SCREEN STATUS BAR OR NONE. WE JUST CALL A ROUTINE THAT IS
;SELECTIVELY LOADED DURING ASSEMBLY.
N100: JSR FINISH_TOP
;VIDEO IS ENABLED. CALL ROUTINES THAT DO PROCESSING WHEN ACTIVATED
;BY FLAGS. WE HAVE TO PRIORITIZE THEM.
;WE FIRST SAVE OFF A FEW MEMORY VARIABLES THAT ARE DEFINED TO BE USABLE
;BY ALL.
LDA SUBSVAR1
PHA
LDA SUBSVAR2
PHA
LDA SUBSVAR3
PHA
LDA SUBSVAR4
PHA
LDA SUBSVAR5
PHA ;SAVE SUB VARIABLES SO THAT THE SUBS MAY
;BE USED FROM ANY LEVEL.
LDA MATH1
PHA
LDA MATH2
PHA
LDA MATH3
PHA
LDA MATH4
PHA ;SAVE MATH SUBS VARIABLES
;IFDEF( `GUNLOGIC', JSR AND_GUN, ) ;TAKE A LIGHT GUN SAMPLE
.ifdef GUNLOGIC
JSR AND_GUN
.endif
JSR DOPAL ;UPDATE PALETTES IF NEEDED
JSR DOSCRL ;SCROLL THE BACKGROUND IF NEEDED
JSR CHECK_ANIM ;SEE IF ANIMATIONS NEED PROCESSING
JSR FEED_SOUND ;FEED THE SOUND CHIP
;CHECK FOR JOYSTICK CHANGES.
N213: LDA #1
STA $4016
LDA #0
STA $4016 ;LATCH A VALUE TO SHIFT. ALSO LATCHES 4017.
LDA #0
STA J1CHANGE ;ZERO RESULT
LDX #8
N200: LDA $4016
ROR A
ROL J1CHANGE ;MOVE BIT UP INTO OUR BYTE
DEX
BNE N200
LDA J1CHANGE ;GET NEW VALUE
TAX ;SAVE NEW VALUE
EOR J1FLAGS ;GET CHANGES
STA J1CHANGE ;SAVE CHANGES
STX J1FLAGS ;AND CURRENT STATE
LDA #0
STA J2CHANGE ;ZERO RESULT
LDX #8
;******* $0345 of the ROM ************
N210: LDA $4017
ROR A
ROL J2CHANGE ;MOVE BIT UP INTO OUR BYTE
DEX
BNE N210
LDA J2CHANGE ;GET NEW VALUE
TAX ;SAVE NEW VALUE
EOR J2FLAGS ;GET CHANGES
STA J2CHANGE ;SAVE CHANGES
STX J2FLAGS ;AND CURRENT STATE
;DO THE NECESSARY AUTOREPEAT LOGIC.
;FIRST WE RESET ANY AUTOREPEATING KEYS THAT ARE NO LONGER DOWN.
LDA J1FLAGS
AND J1REPFLG
STA J1REPFLG
LDA J1FLAGS
AND J1HOLD
STA J1HOLD ;RESET ANY NO LONGER DOWN IN JOYSTICK 1 FLAGS
LDA J2FLAGS
AND J2REPFLG
STA J2REPFLG
LDA J2FLAGS
AND J2HOLD
STA J2HOLD ;RESET ANY NO LONGER DOWN IN JOYSTICK 2 FLAGS
;SEE IF THE REPEAT COUNTER HAS RUN DOWN.
DEC REPCNT ;COUNT DOWN THE REPEAT COUNTER
BNE N215 ;SKIP IF NOT TIME TO REPEAT AGAIN.
LDA #REPRATE
STA REPCNT ;RELOAD IT
LDA J1REPFLG ;GET THE REPEATING KEYS
ORA J1CHANGE
STA J1CHANGE ;SET AS IF ITS A CHANGED KEY
LDA J2REPFLG
ORA J2CHANGE
STA J2CHANGE
LDA J1HOLD ;GET KEYS WAITING TO AUTOREPEAT NEXT PASS
AND #J1REPENA ;BUT ONLY WANT THOSE ENABLED TO REPEAT
STA J1REPFLG ;SET TO REPEAT NEXT COUNT
LDA J1FLAGS
STA J1HOLD ;MOVE CURRENT STATE INTO THE HOLDING FLAG
LDA J2HOLD ;GET KEYS WAITING TO AUTOREPEAT NEXT PASS
AND #J2REPENA ;BUT ONLY WANT THOSE ENABLED TO REPEAT
STA J2REPFLG ;SET TO REPEAT NEXT COUNT
LDA J2FLAGS ;$03B2
STA J2HOLD ;MOVE CURRENT STATE INTO THE HOLDING FLAG $03B5
;CALL THE USER JOYSTICK ROUTINES TO SERVICE ANY CHANGED BUTTON.
;IF YOU WANT TO GET ONLY BUTTONS THAT GO DOWN, REMOVE THE COMMENT FROM
;THE AND INSTRUCTION IMMEDIATLY PRECEEDING THE BIT TESTS.
; $03B8 of the ROM***************
N215: LDA J1CHANGE ;GET JOYSTICK 1 CHANGES
AND J1FLAGS ;THIS LINE SELECTS ONLY KEYS GOING DOWN.
;COMMENT THIS ROUTINE TO REPORT ALL CHANGES.
BEQ N240 ;SKIP IF NO JOYSTICK CHANGES THIS PASS.
ROR J1CHANGE
BCC N220
JSR RIGHT1
N220: ROR J1CHANGE
BCC N221
JSR LEFT1
N221: ROR J1CHANGE
BCC N222
JSR DOWN1
N222: ROR J1CHANGE
BCC N223
JSR UP1
N223: ROR J1CHANGE
BCC N224
JSR STRT1
N224: ROR J1CHANGE
BCC N225
JSR SEL1
N225: ROR J1CHANGE
BCC N226
JSR B1
N226: ROR J1CHANGE
BCC N240
JSR A1
N240: LDA J2CHANGE ;GET JOYSTICK 2 CHANGES
AND J2FLAGS ;THIS LINE SELECTS ONLY KEYS GOING DOWN.
;COMMENT THIS ROUTINE TO REPORT ALL CHANGES.
BEQ N260
ROR J2CHANGE
BCC N250
JSR RIGHT2
N250: ROR J2CHANGE
BCC N251
JSR LEFT2
N251: ROR J2CHANGE
BCC N252
JSR DOWN2
N252: ROR J2CHANGE
BCC N253
JSR UP2
N253: ROR J2CHANGE
BCC N254
JSR STRT2
N254: ROR J2CHANGE
BCC N255
JSR SEL2
N255: ROR J2CHANGE
BCC N256
JSR B2
N256: ROR J2CHANGE
BCC N260
JSR A2
;CALL THE USER SUBROUTINE.
N260:
;IFDEF( `GUNLOGIC', JSR AND_GUN, ) ;TAKE A LIGHT GUN SAMPLE
.ifdef GUNLOGIC
JSR AND_GUN
.endif
JSR USER_NMI
;CHECK FOR ACTIVE GUN SCANNING OR A NEW TRIGGER PRESS
;IFDEF( `GUNLOGIC', JSR CHECK_GUN, )
.ifdef GUNLOGIC
JSR CHECK_GUN
.endif
;DONE WITH THIS NMI. REENABLE NMI INTERRUPTS AND RESTORE REGS.
N380: PLA
STA MATH4
PLA
STA MATH3
PLA
STA MATH2
PLA
STA MATH1
PLA
STA SUBSVAR5
PLA
STA SUBSVAR4
PLA
STA SUBSVAR3
PLA
STA SUBSVAR2
PLA
STA SUBSVAR1
PLA
TAY
PLA
TAX
LDA REG2000
ORA #$80
STA $2000
PLA
RTI