-
Notifications
You must be signed in to change notification settings - Fork 0
/
adventure.asm
2844 lines (2459 loc) · 112 KB
/
adventure.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
processor 6502
;Default 2600 Constants set up by dissasembler..
VSYNC = $00
VBLANK = $01
WSYNC = $02
RSYNC = $03
NUSIZ0 = $04
NUSIZ1 = $05
COLUP0 = $06
COLUP1 = $07
COLUPF = $08
COLUBK = $09
CTRLPF = $0A
PF0 = $0D
PF1 = $0E
PF2 = $0F
RESP0 = $10
AUDC0 = $15
AUDF0 = $17
AUDV0 = $19
AUDV1 = $1A
GRP0 = $1B
GRP1 = $1C
ENAM0 = $1D
ENAM1 = $1E
ENABL = $1F
HMP0 = $20
VDEL01 = $26
HMOVE = $2A
HMCLR = $2B
CXCLR = $2C
CXP0FB = $32
CXP1FB = $33
CXM0FB = $34
CXM1FB = $35
CXBLPF = $36
CXPPMM = $37
INPT4 = $3C
SWCHA = $0280
SWCHB = $0282
INTIM = $0284
TIM64T = $0296
ORG $F000
START:
JMP StartGame ;Jump To Start Game
;Alternate Start
.byte $78,$D8,$4C,$06,$F3 ;Setup for 6507, Start with no Variable Initialisation.
;Print Display
PrintDisplay:
STA HMCLR ;Clear horzontal motion.
LDA $86 ;Position Player00 Sprite To
LDX #$00 ; the X Coordinate of Object1.
JSR PosSpriteX
LDA $88 ;Position Player01 Sprite to
LDX #$01 ; the X Coordinate of Object2.
JSR PosSpriteX
LDA $8B ;Position Ball Strite to
LDX #$04 ; the X Coordinate of the Man.
JSR PosSpriteX
STA WSYNC ;Wait for horizontal Blank.
STA HMOVE ;Apply Horizontal Motion.
STA CXCLR ;Clear Collision Latches.
LDA $8C ;Get the Y Coordinate of the Man.
SEC
SBC #$04 ;And Adjust it (By Four Scan Lines)
STA $8D ; for printing (so Y Coordinate Specifies Middle)
PrintDisplay_1:
LDA INTIM ;Wait for end of the
BNE PrintDisplay_1 ; current fame.
LDA #$00
STA $90 ;Set Player00 definition index.
STA $91 ;Set Player01 definition index.
STA $8F ;Set room definition index.
STA GRP1 ;Clear any graphics for Player01.
LDA #$01
STA VDEL01 ;vertically delay Player 01
LDA #$68
STA $8E ;Set Scan Lind Count.
;Print top line of Room.
LDY $8F ;Get room definition index.
LDA ($80),Y ;Get first room definition byte.
STA PF0 ; and display.
INY
LDA ($80),Y ;Get Next room definition byte.
STA PF1 ; and display.
INY
LDA ($80),Y ;Get Last room defintion byte.
STA PF2 ; and display.
INY
STY $8F ;Save for Next Time.
STA WSYNC ;Wait for Horizontal Blank.
LDA #$00
STA VBLANK ;Clear any Vertical Blank.
JMP PrintPlayer00
;Print Player01 (Object 02)
PrintPlayer01:
LDA $8E ;Get Current Scan Line.
SEC ;Have we reached Object2's
SBC $89 ; Y Coordinate?
STA WSYNC ; Wait for Horzonal Blank.
BPL PrintPlayer00 ;If Not, Branch.
LDY $91 ;Get the Player01 definition index.
LDA ($84),Y ;Get the Next Player01 Definition byte
STA GRP1 ; and display.
BEQ PrintPlayer00 ;If Zero then Definition finished.
INC $91 ;Goto next Player01 definition byte.
;Print Player00 (Object01), Ball (Man) and Room.
PrintPlayer00:
LDX #$00
LDA $8E ;Get the Current Scan Line.
SEC ;Have we reached the Object1's
SBC $87 ; Y coordinate?
BPL PrintPlayer00_1 ;If not then Branch.
LDY $90 ;Get Player00 definition index.
LDA ($82),Y ;Get the Next Player00 definition byte.
TAX
BEQ PrintPlayer00_1 ;If Zero then Definition finished.
INC $90 ;Go to Next Player00 definition byte.
PrintPlayer00_1:
LDY #$00 ;Disable Ball Graphic.
LDA $8E ;Get Scan line count.
SEC ;Have we reached the Man's
SBC $8D ; Y Coordinate?
AND #$FC ;Mask value to four either side (getting depth of 8)
BNE PrintPlayer00_2 ;If Not, Branch.
LDY #$02 ;Enable Ball Graphic.
PrintPlayer00_2:
LDA $8E ;Get Scan Line Count.
AND #$0F ;Have we reached a sixteenth scan line.
BNE PrintPlayer00_4 ;If not, Branch.
STA WSYNC ;Wait for Horzontal Blank.
STY ENABL ;Enable Ball (If Wanted)
STX GRP0 ;Display Player 00 definition byte (if wanted)
LDY $8F ;Get room definition index.
LDA ($80),Y ;Get first room definition byte,
STA PF0 ; and display.
INY
LDA ($80),Y ;Get next room definition byte,
STA PF1 ; and display.
INY
LDA ($80),Y ;Get next room definition byte,
STA PF2 ; and display.
INY
STY $8F ;Save for Next Time.
PrintPlayer00_3:
DEC $8E ;Goto next scan line.
LDA $8E ;Get the scan line.
CMP #$08 ;Have we reached to within 8 scanlines of the bottom?
BPL PrintPlayer01 ;If not, Branch.
STA VBLANK ;Turn on VBLANK
JMP TidyUp
;Print Player00 (Object 01) and Ball (Man)
PrintPlayer00_4:
STA WSYNC ;Wait for Horzontal blank.
STY ENABL ;Enable Ball (If Wanted.)
STX GRP0 ;Display Player00 definition byte (if Wanted).
JMP PrintPlayer00_3
;Tidy Up
TidyUp:
LDA #$00
STA GRP1 ;Clear any graphics for Player01
STA GRP0 ;Clear any graphics for Player00
LDA #$20
STA TIM64T ;Stat Timing this frame using
RTS ; the 64 bit counter.
;Position Sprite X horizontally.
PosSpriteX:
LDY #$02 ;Start with 10 clock cycles (to avoid HBLANK)
SEC ;Divide the Coordinate.
PosSpriteX_1:
INY ; Wanted by Fifteen I.E.
SBC #$0F ; Get Course Horizontal
BCS PosSpriteX_1 ; Value (In Multiples of 5 Clock Cycles
; (Therefore giving 15 Color Cycles)
EOR #$FF ;Flip remanter to positive value (inverted).
SBC #$06 ;Convert to left or right of current position.
ASL
ASL ;Move to high nybble for TIA
ASL ; horizontal motion.
ASL
STY WSYNC ;Wait for horozontal blank.
PosSpriteX_2:
DEY ;Count down the color
BPL PosSpriteX_2 ; cycles (these are 5 machine/15 color cycles).
STA RESP0,X ;Reset the sprite, thus positioning it coursely.
STA HMP0,X ;Set horizontal (fine) motion of sprite.
RTS
;Preform VSYNC
DoVSYNC:
LDA INTIM ;Get Timer Output
BNE DoVSYNC ;Wait for Time-Out
LDA #$02
STA WSYNC ;Wait for horizonal blank.
STA VBLANK ;Start Vertical Blanking.
STA WSYNC ;Wait for horizonal blank.
STA WSYNC ;Wait for horizonal blank.
STA WSYNC ;Wait for horizonal blank.
STA VSYNC ;Start verticle sync.
STA WSYNC ;Wait for horizonal blank.
STA WSYNC ;Wait for horizonal blank.
LDA #$00
STA WSYNC ;Wait for horizonal blank.
STA VSYNC ;End Vertical sync.
LDA #$2A ;Set clock interval to
STA TIM64T ;Countdown next frame.
RTS
;Setup a room for print.
SetupRoomPrint:
LDA $8A ;Get current room number.
JSR RoomNumToAddress ;Convert it to an address.
LDY #$00
LDA ($93),Y ;Get low pointer to room
STA $80 ; Graphics
LDY #$01
LDA ($93),Y ;Get high pointer to room
STA $81 ; Graphics
;Check B&W Switch for foom graphics.
LDA SWCHB ;Get console switches.
AND #$08 ;Check black and white switch
BEQ UseBW ;Branch if B&W.
;Use Color
LDY #$02
LDA ($93),Y ;Get room color
JSR ChangeColor ;Change if necessary
STA COLUPF ;Put in Playfiled color register.
JMP UseColor
;Use B&W
UseBW:
LDY #$03
LDA ($93),Y ;Get B&W Color
JSR ChangeColor ;Change if necessary
STA COLUPF ;Put in the Playfield color register.
;Color Background.
UseColor:
LDA #$08 ;Get light grey background
JSR ChangeColor ;Change if necessary
STA COLUBK ;Put it in the Background color register.
;Playfield Control.
LDY #$04
LDA ($93),Y ;Get the playfield control value.
STA CTRLPF ;And put in the playfield control register.
AND #$C0 ;Get the "this wall" flag.
LSR
LSR
LSR ;Get the first bit into position.
LSR
LSR
STA ENAM1 ;Enable right hand thin wall. (if wanted - missile01)
LSR
STA ENAM0 ;Enable left hand thin wall (if wanted - missle00)
;Get objects to display.
JSR CacheObjects ;Get next two objects to display.
;Sort out their order.
LDA $95 ;If the object1 is the
CMP #$00 ;Invisible surround
BEQ SwapPrintObjects ;Then branch to swap (we want it as player01)
CMP #$5A ;If the first object is the bridge then
BNE SetupObjectPrint ;Swap the objects (we want it as player01)
LDA $96 ;If the object2 is the
CMP #$00 ;Invisble surround then branch to leave
BEQ SetupObjectPrint ;it (we want it as player01)
SwapPrintObjects:
LDA $95
STA $D8
LDA $96
STA $95 ;Swap the objects to print.
LDA $D8
STA $96
;Setup Object1 to print.
SetupObjectPrint:
LDX $95 ;Get Object1
LDA Store1,X ;Get low pointer to it's dynamic information.
STA $93
LDA Store2,X ;Get high pointer to it's dynamic informtion.
STA $94
LDY #$01
LDA ($93),Y ;Get Object1's X coordinate
STA $86 ;and Store for print.
LDY #$02
LDA ($93),Y ;Get Object1's Y coordinate
STA $87 ;and Store for print.
LDA Store3,X ;Get low pointer to state value.
STA $93
LDA Store4,X ;Get high pointer to state value.
STA $94
LDY #$00
LDA ($93),Y ;Retrieve Object1's current state.
STA $DC
LDA Store5,X ;Get low pointer to state information.
STA $93
LDA Store6,X ;Get high pointer to state information.
STA $94
JSR GetObjectState ;Find current state in the state information.
INY ;Index to the state's corresponding graphic pointer.
LDA ($93),Y ;Get Object1's low graphic address
STA $82 ;and store for print.
INY
LDA ($93),Y ;Get Object1's high graphic address
STA $83 ;and store for print.
;Check B&W for object01
LDA SWCHB ;Get console switches
AND #$08 ;Check B&W switches.
BEQ MakeObjectBW ;Branch if B&W.
;Colour
LDA Store7,X ;Get Object1's Color.
JSR ChangeColor ;Change if necessary.
STA COLUP0 ;And set color luminance00.
JMP ResizeObject
;B&W
MakeObjectBW:
LDA Store8,X ;Get Object's B&W Color.
JSR ChangeColor ;Change if necessary.
STA COLUP0 ;Set color luminance00.
;Object1 Size
ResizeObject:
LDA Store9,X ;Get Object1's Size
ORA #$10 ;And set to larger size if necessary.
STA NUSIZ0 ;(Used by bridge and invisible surround)
;Setup Object 2 to Print.
LDX $96 ;Get Object 2
LDA Store1,X
STA $93 ;Get low pointer to it's dynamic information.
LDA Store2,X
STA $94 ;Get high pointer to it's dynamic information.
LDY #$01
LDA ($93),Y ;Get Object2's X coordinate
STA $88 ;and store for print.
LDY #$02
LDA ($93),Y ;Get Object2's Y coordinate
STA $89 ;and store for print.
LDA Store3,X ;Get low pointer to state value.
STA $93
LDA Store4,X ;Get high pointer to state value.
STA $94
LDY #$00
LDA ($93),Y ;Retrieve Object2's current state.
STA $DC
LDA Store5,X ;Get low pointer to state information.
STA $93
LDA Store6,X ;Get high pointer to state information.
STA $94
JSR GetObjectState ;Find the current state in the state information.
INY ;Index to the state's corresponding graphic pointer.
LDA ($93),Y
STA $84 ;Get Object2's low graphic address.
INY
LDA ($93),Y ;Get Object2's high graphic address.
STA $85
;Check B&W for Object2
LDA SWCHB ;Get Console Switches
AND #$08 ;Check B&W Switch.
BEQ MakeObject2BW ;If B&W then Branch.
;Color
LDA Store7,X ;Get Object2;s Color
JSR ChangeColor ;Change if Necessary.
STA COLUP1 ;and set color luminance01.
JMP ResizeObject2
;B&W
MakeObject2BW:
LDA Store8,X ;Get Object's B&W Color.
JSR ChangeColor ;Change if Necessary.
STA COLUP1 ;and set color luminance01.
;Object2 Size
ResizeObject2:
LDA Store9,X ;Get Object2's Size
ORA #$10 ;And set to larger size if necessary.
STA NUSIZ1 ;(Used by bridge and invisible surround)
RTS
;Fill cache with two objects in this room.
CacheObjects:
LDY $9C ;Get Last Object
LDA #$A2 ;Set cache to
STA $95 ; no-ojects.
STA $96
MoveNextObject:
TYA
CLC ;Goto the next object to
ADC #$09 ;check (add nine).
CMP #$A2 ;Check if over maximum.
BCC GetObjectsInfo
LDA #$00 ;If so, wrap to zero.
GetObjectsInfo:
TAY
LDA Store1,Y ;Get low byte of object info.
STA $93
LDA Store2,Y ;Get high byte of object info.
STA $94
LDX #$00
LDA ($93,X) ;Get objects current room.
CMP $8A ;Is it in this room?
BNE CheckForMoreObjects ;If not lets try next object (branch)
LDA $95 ;Check first slot.
CMP #$A2 ;If not default (no-object)
BNE StoreObjectToPrint ;then branch.
STY $95 ;Store this object's number to print
JMP CheckForMoreObjects ; and try for more.
StoreObjectToPrint:
STY $96 ;Store this object's number to print.
JMP StoreCount ; and then give up - no slots free.
CheckForMoreObjects:
CPY $9C ;Have we done all the objets?
BNE MoveNextObject ;If not, continue.
StoreCount:
STY $9C ;If so, store current count
RTS ; for next time.
;Convert room number to address.
RoomNumToAddress:
STA $D8 ;Strore room number wanted.
STA $93
LDA #$00 ;Zero the high byte of the
STA $94 ; offset.
CLC
ROL $93
ROL $94 ;Multiply room number by eight.
ROL $93
ROL $94
ROL $93
ROL $94
LDA $D8 ;Get the original room number.
CLC
ADC $93
STA $93 ;And add it to the offset.
LDA #$00
ADC $94 ;In effect the room number is
STA $94 ; multiplied by nine.
LDA #<RoomDataTable
CLC
ADC $93 ;Add the room data base address
STA $93 ;to the offset therefore getting
LDA #>RoomDataTable ; the final room data address.
ADC $94
STA $94
RTS
;Get pointer to current state.
GetObjectState:
LDY #$00
LDA $DC ;Get the current object state.
GetObjectState_1:
CMP ($93),Y ;Have we found it in the list of states.
BCC GetObjectState_2 ;If nearing it then found it and return
BEQ GetObjectState_2 ;If found it then return.
INY
INY ;Goto next state in list of states.
INY
JMP GetObjectState_1
GetObjectState_2:
RTS
;Check for input.
CheckInput:
INC $E5 ;Increment low count.
BNE GetJoystick
INC $E6 ;Increment hight count if
BNE GetJoystick ; needed.
LDA #$80 ;Wrap the high count (indicating
STA $E6 ; timeout) if needed.
GetJoystick:
LDA SWCHA ;Get joystick values.
CMP #$FF ;If any movement then branch.
BNE GetJoystick_2
LDA SWCHB ;Get the consol switches
AND #$03 ;Mast for the reset/select switchs.
CMP #$03 ;Have either of them been used?
BEQ GetJoystick_3 ;If not branch.
GetJoystick_2:
LDA #$00 ;Zero the high count of the
STA $E6 ; switches or joystick have been used.
GetJoystick_3:
RTS
;Change color if necessary.
ChangeColor:
LSR ;If bit 0 of the color is set
BCC ChangeColor_2 ; then the room is to flash.
TAY ;Use color as an index (usually E5- the low counter).
LDA.wy $0080,Y ;Get flash color (usually the low counter.)
ChangeColor_2:
LDY $E6 ;Get the input counter.
BPL ChangeColor_3 ;If console/joystick moved reciently then branch.
EOR $E6 ;Merge the high counter with the color wanted.
AND #$FB ;Keep this color bug merge down the luminance.
ChangeColor_3:
ASL ;And restore original color if necessary.
RTS
;Get the address of the dynamic information for an object.
GetObjectAddress:
LDA Store1,X
STA $93 ;Get and store the low address.
LDA Store2,X
STA $94 ;Get and store the high address.
RTS
;Game Start
StartGame:
SEI ;Set Interupts Off
CLD
LDX #$28 ;Clear TIA Registers
LDA #$00 ;&04-&2C i.e. blank
ResetAll:
STA NUSIZ0,X ;Everything And Turn.
DEX ;Everything Off.
BPL ResetAll
TXS ;Reset Stack
SetupVars:
STA VSYNC,X ;Clear &80 to &FF User Vars.
DEX
BMI SetupVars
JSR ThinWalls ;Position the thin walls (missiles)
JSR SetupRoomObjects ;Setup objects rooms and positions.
MainGameLoop:
JSR CheckGameStart ;Check for Game Start
JSR MakeSound ;Make noise if necessary
JSR CheckInput ;Check for input.
LDA $DE ;Is The Game Active?
BNE NonActiveLoop ;If Not Branch..
LDA $B9 ;Get the room the Chalise is in.
CMP #$12 ;Is it in the yellow castle?
BNE MainGameLoop_2 ;If Not Branch..
LDA #$FF
STA $DF ;Set the note count to maximum.
STA $DE ;Set the game to inactive.
LDA #$00 ;Set the noise type to end-noise.
STA $E0
MainGameLoop_2:
LDY #$00 ;Allow joystick read - all movement.
JSR BallMovement ;Check ball collisions and move ball.
JSR MoveCarriedObject ;Move the Carried Object
JSR DoVSYNC ;Wait for VSYNC
JSR SetupRoomPrint ;Setup the room and objects for display.
JSR PrintDisplay ;Display the room and objects.
JSR PickupPutdown ;Deal with object pickup and putdown.
LDY #$01 ;Dissalow joystick read - move vertically only.
JSR BallMovement ;Check ball collisions and move ball.
JSR Surround ;Deal With Invisible Surround Moving.
JSR DoVSYNC ;Wait for VSYNC
JSR MoveBat ;Move and deal with bat.
JSR Portals ;Move and deal with portcullises.
JSR PrintDisplay ;Display the room and objects.
JSR MoveGreenDragon ;Move and deal with the green dragon.
JSR MoveYellowDragon ;Move and deal with the yellow dragon.
JSR DoVSYNC ;Wait for VSYNC.
LDY #$02 ;Dissalow joystic read/bridge check - move horrizonally only.
JSR BallMovement ;Check ball collisions and move ball.
JSR MoveRedDragon ;Move and deal with red dragon.
JSR Mag_1 ;Deal with the magnet.
JSR PrintDisplay ;Display the room and objects.
JMP MainGameLoop
;Non Active Game Loop.
NonActiveLoop:
JSR DoVSYNC ;Wait for VSYNC
JSR PrintDisplay ;Display the room and objects.
JSR SetupRoomPrint ;Set up room and objects for display.
JMP MainGameLoop
;Position missiles to "thin wall" areas.
ThinWalls:
LDA #$0D ;Position missile 00 to
LDX #$02 ;(0D,00) - left thin wall.
JSR PosSpriteX
LDA #$96 ;Position missile 01 to
LDX #$03 ;(96,00) - right thin wall.
JSR PosSpriteX
STA WSYNC ;Wait for horizonal blank.
STA HMOVE ;Apply the horizonal move.
RTS
CheckGameStart:
LDA SWCHB ;Get the console switches.
EOR #$FF ;Flip (as reset active low).
AND $92 ;Compare with what was before
AND #$01 ;And check only the reset switch
BEQ CheckReset ;If no reset then branch.
LDA $DE ;Has the Game Started?
CMP #$FF ;If not then branch.
BEQ SetupRoomObjects
LDA #$11 ;Get the yellow castle room.
STA $8A ;Make it the current room.
STA $E2 ;Make it the previous room.
LDA #$50 ;Get the X coordinate.
STA $8B ;Make it the current ball X coordinate.
STA $E3 ;Make it the previous ball X coordinate.
LDA #$20 ;Get the Y coordinate.
STA $8C ;Make it the current ball Y coordinate.
STA $E4 ;Make it the previous ball Y coordinate.
LDA #$00
STA $A8 ;Set the red dragon's state to OK.
STA $AD ;Set the yellow dragon's state to OK.
STA $B2 ;Set the green dragon's state to OK.
STA $DF ;Set the note count to zero.. (ops!??)
LDA #$A2
STA $9D ;Set no object being carried.
CheckReset:
LDA SWCHB ;Get the console switches.
EOR #$FF ;Flip (as select active low)
AND $92 ;Compare with what was before.
AND #$02 ;And check only the select switch.
BEQ StoreSwitches ;Branch if select not being used.
LDA $8A ;Get the Current Room.
CMP #$00 ;Is it the "Number" room?
BNE SetupRoomObjects ;Branch if not.
LDA $DD ;Increment the level.
CLC ;Number (by two).
ADC #$02
CMP #$06 ;Have we reached the maximum?
BCC ResetSetup
LDA #$00 ;If yep then set back to zero.
ResetSetup:
STA $DD ;Store the new level number.
SetupRoomObjects:
LDA #$00 ;Set the current room to the
STA $8A ;"Number" room.
STA $E2 ;And the previous room.
LDA #$00 ;Set the ball's Y coordinate to zero.
STA $8C ;And the previous Y coordinate.
STA $E4 ;(So can't be seen.)
LDY $DD ;Get the level number.
LDA Loc_4,Y ;Get the low pointer to object locations.
STA $93
LDA Loc_5,Y ;Get the high pointer to object locations.
STA $94
LDY #$30 ;Copy all the objects dynamic information.
SetupRoomObjects_2:
LDA ($93),Y ;(the rooms and positions) into
STA.wy $00A1,Y ;the working area.
DEY
BPL SetupRoomObjects_2
LDA $DD ;Get the level number.
CMP #$04 ;Branch if level one.
BCC SignalGameStart ;Or two (Where all objects are in defined areas.)
JSR RandomizeLevel3 ;Put some objects in random rooms.
JSR DoVSYNC ;Wait for VSYNC
JSR PrintDisplay ;Display rooms and objects.
SignalGameStart:
LDA #$00 ;Signal that the game has started.
STA $DE
LDA #$A2 ;Set no object being carried.
STA $9D
StoreSwitches:
LDA SWCHB ;Store the current console switches
STA $92
RTS
;Put objects in random rooms for level 3.
RandomizeLevel3:
LDY #$1E ;For each of the eleven objects..
RandomizeLevel3_2:
LDA $E5 ;Get the low input counter as seed.
LSR
LSR
LSR ;Generate a psudo-random
LSR ;room number.
LSR
SEC
ADC $E5 ;Store the low input counter.
STA $E5
AND #$1F ;Trim so represents a room value.
CMP Loc_2,Y ;If it is less than the
BCC RandomizeLevel3_2 ;lower bound for object then get another.
CMP Loc_3,Y ;If it equals or is
BEQ RandomizeLevel3_3 ;Less than the higher bound for object
BCS RandomizeLevel3_2 ;Then continue (branch if higher)
RandomizeLevel3_3:
LDX Loc_1,Y ;Get the dynamic data index for this object
STA VSYNC,X ;Store the new room value.
DEY
DEY ;Goto the next object.
DEY
BPL RandomizeLevel3_2 ;Untill all done
RTS
;Room Bounds Data.
;Ex. the chalise at location &B9 can only exist in rooms 13-1A for
; level 3.
Loc_1:
.byte $B9 ;
Loc_2:
.byte $13 ;Chalise
Loc_3:
.byte $1A ;
.byte $A4,$01,$1D ;Red Dragon
.byte $A9,$01,$1D ;Yellow Dragon
.byte $AE,$01,$1D ;Green Dragon
.byte $B6,$01,$1D ;Sword
.byte $BC,$01,$1D ;Bridge
.byte $BF,$01,$1D ;Yellow Key
.byte $C2,$01,$16 ;White Key
.byte $C5,$01,$12 ;Black Key
.byte $CB,$01,$1D ;Bat
.byte $B3,$01,$1D ;Magnet
Loc_4:
.byte <Game1Objects ;Pointer to object locations for game 01.
Loc_5:
.byte >Game1Objects ; --continued.
.byte <Game2Objects,>Game2Objects ;Pointer to object locations for game 02.
.byte <Game2Objects,>Game2Objects ;Pointer to object locations for game 03.
;Object locations (room and coordinate) for game 01.
Game1Objects:
.byte $15,$51,$12 ;Black dot (Room, X, Y)
.byte $0E,$50,$20,$00,$00 ;Red Dragon (Room, X, Y, Movement, State)
.byte $01,$50,$20,$00,$00 ;Yellow Dragon (Room, X, Y, Movement, State)
.byte $1D,$50,$20,$00,$00 ;Green Dragon (Room, X, Y, Movement, State)
.byte $1B,$80,$20 ;Magnet (Room,X,Y)
.byte $12,$20,$20 ;Sword (Room,X,Y)
.byte $1C,$30,$20 ;Challise (Room,X,Y)
.byte $04,$29,$37 ;Bridge (Room,X,Y)
.byte $11,$20,$40 ;Yellow Key (Room,X,Y)
.byte $0E,$20,$40 ;White Key (Room,X,Y)
.byte $1D,$20,$40 ;Black Key (Room,X,Y)
.byte $1C ;Portcullis State
.byte $1C ;Portcullis State
.byte $1C ;Portcullis State
.byte $1A,$20,$20,$00,$00 ;Bat (Room, X, Y, Movement, State)
.byte $78,$00 ;Bat (Carrying, Fed-Up)
;Object locations (room and coordinate) for Games 02 and 03.
Game2Objects:
.byte $15,$51,$12 ;Black Dot (Room,X,Y)
.byte $14,$50,$20,$A0,$00 ;Red Dragon (Room,X,Y,Movement,State)
.byte $19,$50,$20,$A0,$00 ;Yellow Dragon (Room,X,Y,Movement,State)
.byte $04,$50,$20,$A0,$00 ;Green Dragon (Room,X,Y,Movement,State)
.byte $0E,$80,$20 ;Magnet (Room,X,Y)
.byte $11,$20,$20 ;Sword (Room,X,Y)
.byte $14,$30,$20 ;Chalise (Room,X,Y)
.byte $0B,$40,$40 ;Bridge (Room,X,Y)
.byte $09,$20,$40 ;Yellow Key (Room,X,Y)
.byte $06,$20,$40 ;White Key (Room,X,Y)
.byte $19,$20,$40 ;Black Key (Room,X,Y)
.byte $1C ;Portcullis State
.byte $1C ;Portcullis State
.byte $1C ;Portcullis State
.byte $02,$20,$20,$90,$00 ;Bat (Room,X,Y,Movement,State)
.byte $78,$00 ;Bat (Carrying, Fed-Up)
;Check ball collisions and move ball.
BallMovement:
LDA CXBLPF
AND #$80 ;Get ball-playfield collision
BNE PlayerCollision ;Branch if collision (Player-Wall)
LDA CXM0FB
AND #$40 ;Get ball-missile00 collision.
BNE PlayerCollision ;Branch if collision. (Player-Left Thin)
LDA CXM1FB
AND #$40 ;Get ball-missile01 collision.
BEQ BallMovement_2 ;Branch if no collision.
LDA $96 ;If object2 (to print) is
CMP #$87 ; not the black dot then collide.
BNE PlayerCollision
BallMovement_2:
LDA CXP0FB
AND #$40 ;Get ball-player00 collision.
BEQ BallMovement_3 ;If no collision then branch.
LDA $95 ;If object1 (to print) is
CMP #$00 ; not the invisible surround then
BNE PlayerCollision ; branch (collision)
BallMovement_3:
LDA CXP1FB
AND #$40 ;Get ball-player01 collision.
BEQ NoCollision ;If no collision then branch.
LDA $96 ;If player01 to print is
CMP #$00 ; not the invisible surround then
BNE PlayerCollision ; branch (collision)
JMP NoCollision ;No collision - branch.
;Player collided (with something)
PlayerCollision:
CPY #$02 ;Are we checking for the bridge?
BNE ReadStick ;If not, branch.
LDA $9D ;Get the object being carried.
CMP #$5A ; Branch if it is the bridge.
BEQ ReadStick
LDA $8A ;Get the current room.
CMP $BC ;Is the bridge in this room.
BNE ReadStick ;If not branch.
;Check going through the bridge.
LDA $8B ;Get the ball's X coordinate.
SEC
SBC $BD ;Subtract the bridge's X coordinate.
CMP #$0A ;If less than &0A then forget it.
BCC ReadStick
CMP #$17 ;If more than &17 then forget it.
BCS ReadStick
LDA $BE ;Get the bridge's Y coordinate.
SEC
SBC $8C ;Subtrac the ball's Y coordinate.
CMP #$FC
BCS NoCollision ;If more than &FC then going through bridge.
CMP #$19 ;If more than &19 then forget it.
BCS ReadStick
;No collision (and going through bridge)
NoCollision:
LDA #$FF ;Reset the joystick input.
STA $99
LDA $8A ;Get the current room.
STA $E2 ; and store temporarily.
LDA $8B ;Get the ball's X coordinate.
STA $E3 ; and store temporarily.
LDA $8C ;Get the ball's Y coordinate.
STA $E4 ;And Store Temporarily.
;Read Sticks
ReadStick:
CPY #$00 ;???Is game in first phase?
BNE ReadStick_2 ;If not, don't bother with joystick read.
LDA SWCHA ;Read joysticks.
STA $99 ; and store value.
ReadStick_2:
LDA $E2 ;Get Temporary room.
STA $8A ; and make it the current room.
LDA $E3 ;Get temporary X coordinate
STA $8B ; and make it the man's X coordinate.
LDA $E4 ;Get temporary Y coordinate
STA $8C ; and make it the man's Y coordinate.
LDA $99 ;Get the Joystick position.
ORA ReadStick_3,Y ;Merge out movement not allowed in this phase.
STA $9B ;And store cooked movement.
LDY #$03 ;Set the delta for the ball.
LDX #$8A ;Point to ball's coordiates.
JSR MoveGroundObject ;Move the ball
RTS
;Joystick Merge Values
ReadStick_3:
.byte $00,$C0,$30 ;No change, No horizontal, No vertical.
;Deal with object pickup and putdown.
PickupPutdown:
ROL INPT4 ;Get joystick trigger.
ROR $D7 ;Merget into joystick record.
LDA $D7 ;Get joystick record.
AND #$C0 ;Merget out previous presses.
CMP #$40 ;Was it previously pressed?
BNE PickupPutdown_2 ;If not branch.
LDA #$A2
CMP $9D ;If nothing is being carried
BEQ PickupPutdown_2 ; then branch.
STA $9D ;Drop object.
LDA #$04 ;Set noise type to four.
STA $E0
LDA #$04 ;Set noise count to four.
STA $DF
PickupPutdown_2:
LDA #$FF ;????
STA $98
;Check for collision.
LDA CXP0FB
AND #$40 ;Get Ball-Player00 collision.
BEQ PickupPutdown_3 ;If nothing occured then branch.
;With Player00
LDA $95 ;Get type of Player00
STA $97 ;And Store.
JMP CollisionDetected ;Deal with collision.
PickupPutdown_3:
LDA CXP1FB
AND #$40 ;Get Ball-Player01 collision.
BEQ PickupPutdown_4 ;If nothing has happened, branch.
LDA $96 ;Get type of Player01
STA $97 ; and store.
JMP CollisionDetected ;Deal with collision.
PickupPutdown_4:
JMP NoObject ;Deal with no collision (return).
;Collision occured.
CollisionDetected:
LDX $97 ;Get the object collided with.
JSR GetObjectAddress ;Get it's dynamic information.
LDA $97 ;Get the object collided with.
CMP #$51 ;Is it carriable?
BCC NoObject ;If not, branch.
LDY #$00
LDA ($93),Y ;Get the object's room.
CMP $8A ;Is it in the current room?
BNE NoObject ;If not, branch.
LDA $97 ;Get the object collided with.
CMP $9D ;Is it the object being carried?
BEQ PickupObject ;If so, branch (and actually pick it up.)
LDA #$05 ;Set noise type to five.
STA $E0
LDA #$04 ;Set noise type to four.
STA $DF
PickupObject:
LDA $97 ;Set the object as being
STA $9D ; carried.