-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplanet2.asm
4272 lines (3898 loc) · 77.8 KB
/
planet2.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
; vi: syntax=asmM6502 ts=4 sw=4
; Acornsoft Planetoid, BBC Micro
; Written by Neil Raine, 1982
; 6502 disassembly by rainbow
; 2020.02.08
; https://github.com/r41n60w/planetoid-disasm
; file: PLANET2
; 8960 bytes, ~35 pages
; all assembly code
org $1100
;$1100,+3 1loc
;Entry point (NOT PLANET2's exec addr!)
;@$.PLANET1 (BASIC program):
; *L. PLANET2:CALL &1100
entrypoint: jmp boot
;$1103,+13 5 loc
;Interrupt hook, IRQ1V vectors here
;interrupt void irq_hook(void);
irq_hook: lda #%00000010 ;bit 1/Vs?
bit SYS6522 +13 ;SyVIA R13
beq + ;IRQstatus
inc vsync ;vsync++
+ jmp (!_irq1v) ;emter IRQ
; addr: $1110:+10 bytes,, 5 loc
;Busy wait until vsync
;void wait_vsync(void);
wait_vsync: lda vsync ;vsync ->
cmp _vsync0 ;++c > c0?
beq wait_vsync ;no,loop
; vsync -> now within vblank
sta _vsync0 ;equalize
rts ;again
;@@@ Timing:
;wait_vsync() is entered at any time before the next frame/vblank, depending on the frame's AI load, # to repaint etc.
; Returning from it however, will be at a specific, constant time (relative to each frame's 20ms period).
; The vertical sync pulse just fired, so the timing here about halfway through the monitor's vertical blanking interval.
; The BBC micro's vblank lasts ~ 4ms, so after wait_vsync() there's:
; ~2ms vblank -> draw + change palette
; ~16ms raster scanning, top to bottom
; another ~2ms of next vblank
; ... then the next frames wait_vsync().
; Useless of course with full screen sprite handling, BUT no problem with Planetoid thanks to the divided screen (minimap at top, playfield bottom) ..
; This accurate timing cycle is used to exploit the top-to-bottom raster scan, namely to paint/erase the main game while rasters near the top @minimap, and vice versa! =)
;$111a,+6 3loc
;Test if vsync
;bool is_vsync(void);
is_vsync: lda vsync
cmp _vsync0
rts
;Like wait_vsync(), but returns test (presumably in Z) instead of blocking.
;Called once from ai_batch() but return is discarded (?)
;$1120,+8 5loc
;Map _p_hysical to _l_ogical colour
;void set_palette(palette_t logical,
; colour_t physical)
set_palette:pha
eor #%111 ;llllpppp
sta ULAPALETTE ;video ULA
pla ;"Palette"
rts ;reg $fe21
;$1128,+7 3loc
;Write a byte of data to a 6845 CRTC reg
; arg X: register # -> $fe00
; arg Y: data byte -> $fe01
;void out6845(uint8_t reg,
; uint8_t data);
out6845: stx SHEILA ;reg #0-17
sta SHEILA + 1 ;byte out
rts
;$112f,+12 5loc
;Init + start hardware timer 1 (@user VIA)
;Loading T1C-H auto starts timer
;timer T1 flags @aux ctrl reg:
; one-shot mode, disable latch/shift reg
; arg X: counter lo byte
; arg Y: " hi byte (cycles @1MHz)
;void start_timer(uint16_t count);
start_timer:lda #%10000000 ;setup T1
sta USR6522 +11 ;ACR
stx USR6522 +4 ;T1C-L
sty USR6522 +5 ;T1C-H
rts
;$113b,+4 2loc
; Test timer state (input reg B -> PB7)
; ret N: set if timer has run out
;bool timerstate(void);
timerstate: bit USR6522 +0 ;IRB.PB7?
rts ;ret -> N
;$113f,+67 33loc
;Process batch of unit AIs
;void ai_batch( size_t batch,
; id_t id);
ai_batch:
; ldx #SHIP
; jsr get_xscr ;useless?
; sta _ship_xscr
xrange: lda #0
sta _min_xscr
lda #77
sta _max_xscr
lda _scrolloff_l
bpl rrange ;if(>0)
lrange: clc
adc #77 ;(77-8*dx)
sta _max_xscr
bne batchinit ;else
rrange: sta _min_xscr ;(8*dx)
batchinit: lda _batch ;init.ly 5
sta _batchc ;loop idx
ldx _id ;curr id #
batchloop: jsr ai_unit
ldx _id ;[0,]2-31
nextid: inx ;id++
cpx #HITCH
beq nextid ;skip #1
cpx #ID_MAX + 1 ;#32
bne batchid ;@last sl?
ldx #ID_MIN ;#2
lda Anim + SHIP ;ship
beq batchid ;normal?
ldx #SHIP ;#0(hyper)
batchid: stx _id
; jsr is_vsync ;useless?
batchnext: dec _batchc ;while(--)
bne batchloop ;[5+,1]
rts
;$1182,+15 8loc
;Process one of ID_ALT<123>
;void ai_alt(void);
ai_alt: ldx _id_alt ;1182
jsr ai_unit
inx ;[34,36]
cpx #ID_ALT3 + 1
bne altid ;#37?
ldx #ID_ALT1 ;-> #34
altid: stx _id_alt
rts
;static id_t _id_alt =
; ID_ALT1, ID_ALT2, ID_ALT3;
;$1191,+43 19loc
;Process unit AI
; arg X: unit id #
;void ai_unit(id_t id);
ai_unit: lda Unit,x
bpl noai ;BLIT?
;-> if(unit & UPDATE)
aivec: asl ;spr# <<1
tay ;AI vector
bmi noai ;EMPTY?
lsr ;clr hibit
setblit: sta Unit,x ;-> BLIT
lda Anim,x
beq aijump ;present?
bmi aiexplode
aiwarp: jsr anim_frame ;warp in
jmp mm_update
;rts
aiexplode: jmp anim_frame ;explode
;rts
aijump: lda AiVector,y
sta _destptr_l
lda AiVector + 1,y
sta _destptr_h ;jump
jmp (!_destptr) ;to vector
;...rts
noai: rts ;fail,exit
;$11bc,+3 1loc
;AI vector for U_SHIP
; arg X: unit id #
;void ai_ship(id_t id);
ai_ship: jmp move_unit
;rts
;Only execd when ship exploding,
; ie all slots become U_SHIP
;$11bf,+27 12loc
;AI vector for KUGEL,S250,S500
; arg X: unit id #
;void ai_object(id_t id);
ai_kugel: ;#8
ai_250: ;#9
ai_500: ;#10
ai_object: ldy Param,x
iny ;age++
tya
sta Param,x
cpy #160 ;> frames
bne + ;too old?
jmp erase_unit
;rts
aisprmove: jsr move_unit ;straight
lda pNext_h,x ;NULL/
bne + ;offscrn?
jmp erase_unit ;-> erase
;rts
aispr_ret: rts
;unsigned age = Param[id];
;$11da,+391
;AI vector for LANDER
; arg X: unit id #
;void ai_lander(id_t id);
ai_lander: lda _humanc
bne ldrshoot ;noplanet?
jsr erase_unit ;lander
lda #MUTANT ;#2
sta Unit,x ;->
jmp ai_mutant ;mutant
ldrshoot: lda #10
jsr shootchance ;1:25 odds
lda Param,x
pha
and #%111111
tay
pla
bne + ;(param)?
jmp j1v_e ;12d2
+ bmi j1v_c ;11fb
lda Y_h,x
cmp #190
bcc toj7v_0 ;1227
lda #MAN ;6
jsr is_linked
bne j1v_b
tya ;mutant
tax
jsr kill_unit
ldx _id
jsr erase_unit
lda #MUTANT
sta Unit,x
jmp ai_mutant
j1v_a: ldy #LANDER ;121d 1
jsr init_dxy
- lda #0 ;1222
sta Param,x
toj7v_0: jmp ai_update ;1227
j1v_b: jsr erase_unit ;122a
lda #LANDER
sta Unit,x
jmp init_unit
;rts
j1v_c: lda Param,x ;1235
asl
bmi j1v_d ;1266
lda #MAN
jsr is_unlinked
bne -
lda X_h,x
cmp X_h,y
beq +
jmp j1v_f
+ lda #$fc ;-4 124d
sta dY_h,x
lda dX_l,y
sta dX_l,x
lda dX_h,y
sta dX_h,x
lda Param,x ;set b6
ora #%0100 0000
sta Param,x
j1v_d: lda Unit,y ;1266
and #%0111 1111 ;sprite #
cmp #MAN
bne j1v_a
lda Param,y
and #%1100 0000
bne j1v_a ;b6 || b7?
lda Param,y
beq +
lda #0
sta dY_l,x
sta dY_h,x
jmp ai_update
+ lda Y_h,x ;1286
sec
sbc #10
cmp Y_h,y
bcs toj7v_1
sta Y_h,y
lda dXMinInit + LANDER
lsr ;2e46
lsr ; / 4
sec
sbc #1 ;dy--
sta dY_h,x
sta dY_h,y
lda #0
sta dY_l,x
sta dY_l,y
sta dX_l,x
sta dX_h,x
sta dX_l,y
sta dX_h,y
clc
lda X_l,x
adc #$80 ;+2px
sta X_l,y
lda X_h,x
adc #0
sta X_h,y
tya
sta Param,x
txa
sta Param,y
toj7v_1: jmp ai_update ;12cf
j1v_e: jsr random ;12d2
and #%11111 ;[0,31]
; cmp #32
; bcs j1v_e ;impossbl?
cmp #ID_MIN ;2
bcc j1v_e
tay ;[2,31]
lda #MAN
jsr is_unlinked
bne j1v_f
sec
lda X_h,y
sbc X_h,x ;horz disq
sta _temp ;Xy - Xx
lda dX_h,x
asl ;dirctn->C
lda _temp ;A: +dispX
bcc + ;going R?
lda #0
sbc _temp ;A: -dispX
+ cmp #50 ;12fc
bcs j1v_f ;>= 50?
tya
ora #%10000000
sta Param,x
j1v_f: lda dX_l,x ;1306
sta _temp_l
asl _temp_l
rol
asl _temp_l
rol
asl _temp_l ; *= 8
rol
sta _temp_h
jsr get_ysurf
sta _temp_l
sec
lda Y_h,x
sbc _temp_l
cmp #20
bcc moveup
cmp #30
bcs movedown
jmp ai_update
moveup: bit _temp_h ;132f
bpl yadd
bmi ysub
movedown: bit _temp_h ;1335
bmi yadd
;bpl ..
ysub: sec ;1339
lda Y_l,x
sbc _temp_l
sta Y_l,x
lda Y_h,x
sbc _temp_h
sta Y_h,x
jmp ai_update
yadd: clc ;134d
lda Y_l,x
adc _temp_l
sta Y_l,x
lda Y_h,x
adc _temp_h
sta Y_h,x
jmp ai_update
;$1361,+151
;AI vector for MUTANT
; arg X: unit id #
;void ai_mutant(id_t id);
ai_mutant: lda #25
jsr shootchance ;1:10 odds
lda pSprite_h,x
beq + ;null ptr?
jsr random
cmp #20
bcs + ;1:13 odds
lda #16
jsr playsound
+ jsr get_xdisph ;1377
cmp #10
bpl j13b3
cmp #$ec ;-20
bmi j13ca ;near shp?
j1382: jsr abs_ydisp ;1382
j1385: ldy #6 ;1385below
lda #0 ;(go up)
bcs + ;above?
ldy #$fa ;-6
; lda #0 ;(go down)
+ sta dY_l,x ;138f
tya ;set vert
sta dY_h,x ;velocity
j1396: sec ;1396
lda X_h + SHIP
sbc X_h,x
php ; save N
lda #80
plp
bpl +
ldy #$fd ;-3
lda #$b0 ;-80
+ sta dX_l,x ;13a9
tya
sta dX_h,x ; -592
jmp ai_update
j13b3: cmp #50 ;13b3
bpl j13ca
jsr abs_ydisp
cmp #40
bcs j1382
jsr abs_ydisp ;ret C
php
pla ;get flags
eor #1 ;~carry
pha ;write
plp
jmp j1385
;status: 7 NV_BDIZC 0
j13ca: jsr random ;13ca
and #1
pha
plp ;random C
jmp j1385
get_xdisph: ldy X_h + SHIP ;13d4
lda _ddx_h
asl ;facing R:
lda X_h,x ;(xid-xme)
bcc + ;facing L?
tya ;-> negate
ldy X_h,x ;(xme-xid)
+ sty _temp ;13e3
sec ;+ in frnt
sbc _temp ;- behind
rts ;horz disp
abs_ydisp: sec ;13e9
lda Y_h,x
sbc Y_h + SHIP
pha ;vert disp
asl ;above: !C
pla ;below: C
bpl + ;-ve?
eor #$ff ;absolute
+ rts ;13f7 retC
;$13f8,+53 21loc
;AI vector for BAITER
; arg X: unit id #
;void ai_baiter(id_t id);
ai_baiter: lda #40
jsr shootchance ;1:6 odds
lda Param,x
beq baitcount ;re target
dec Param,x ;count--
jmp ai_update
;rts
baitcount: jsr random
and #%111
clc ;rand
adc #10 ;[10,17]
sta Param,x ;new count
baitchase: txa
tay ;arg =id
jsr target_ship
asl dY_l,x
rol dY_h,x
asl dX_l,x
rol dX_h,x
asl dX_l,x
rol dX_h,x
jmp ai_update
;rts
;$142d,+9 3loc
;AI vector for BOMBER
; arg X: unit id #
;void ai_bomber(id_t id);
ai_bomber: jsr minechance
jsr dy_sine
jmp ai_update
;rts
;$1436,+58 24loc
;AI vector for SWARMER
; arg X: unit id #
;void ai_swarmer(id_t id);
ai_swarmer: jsr dy_sine
sec
lda X_h,x
sbc X_h + SHIP
sta _temp
eor dX_h,x
bmi ++
lda _temp
bpl +
eor #$ff
+ cmp #20 ;144d
bcs +
jmp ai_update
+ jmp j1396 ;1454
++ lda pSprite_h,x ;1457
beq + ;null ptr?
jsr random
cmp #15
bcs + ;1:17
lda #19
jsr playsound
+ lda #30 ;1468
jsr shootchance ;1:8
jmp ai_update
;$1470,+65 33loc
;Moves unit vertically in a sine wave
; arg X: unit id
; ret: alters dY[id] in place
;vector_t dysine(id_t id);
dy_sine: lda #0
sta _temp
lda Y_h,x
sec ;Y' axis
sbc #98 ;=(Y-98)
bcs uppersine ;Y' > 0??
lowersine: eor #$ff ;[-88,-2]
clc ;negate
adc #1 ;-> [88,2]
asl ; * 4
rol _temp ;+ve accel
asl ;ddY_l
rol _temp ;ddY_h
accelup: clc
adc dY_l,x ;vel +=
sta dY_l,x ;accel
lda _temp
adc dY_h,x
sta dY_h,x
rts
uppersine: asl
rol _temp ;* 4
asl
rol _temp ;ddY HI
sta _temp2 ;ddY LO
acceldown: sec ;-ve accel
lda dY_l,x ;/subtract
sbc _temp2 ;dY
sta dY_l,x ;-= accel
lda dY_h,x
sbc _temp
sta dY_h,x
rts
; accel greatest at screen top/bottom,
; 0 at midscreen (Y' == 0)
;$14b1,+183
;AI vector for MAN
; arg X: unit id #
;void ai_human(id_t id);
ai_human: lda Param,x
bne manlink ;active?
jmp walk ;no
manlink: bmi manfall
tay ;id
lda #LANDER ;#1
jsr is_linked
bne startfall
jmp ai_update
manfall: asl
bmi falling
stx _xreg ;ai id
ldx #HITCH
jsr get_ysurf ;Ysurf
ldx _xreg
cmp Y_h + HITCH ;landed?
bcs rescued ;drop off
rts
rescued: dec _hikerc ;hikerc--
lda X_h + HITCH
sta X_h,x
lda Y_h + HITCH ;update id
sta Y_h,x
lda #0
sta dY_h,x
sta dY_l,x ;standing
sta Param,x ;idle
lda #15
jsr playsound
jsr score500
jmp ai_update
startfall: lda #$ff
sta Param,x ;falling
lda #0
sta dY_l,x
sta dY_h,x
falling: sec
lda dY_l,x
sbc #64 ;gravity
sta dY_l,x ;accel
lda dY_h,x
sbc #0
sta dY_h,x
jsr get_ysurf
cmp Y_h,x ;man hit
bcc ai_update ;ground?
lda dY_h,x ;fall velc
cmp #$fb ;> -5?
bcs +
jmp kill_unit ;splat
landsafe: lda #0 ;safely
sta Param,x ;fell
ldy #MAN ;walking
jsr init_dxy ;speed
lda #15
jsr playsound
jmp score250 ;flash 250
walk: lda dX_l,x
sta _temp_l
lda dX_h,x
asl _temp_l
rol
asl _temp_l
rol
asl _temp_l
rol
sta _temp_h ;signed
jsr get_ysurf
sec
sbc Y_h,x
cmp #4
bmi walkdown
cmp #8
bpl walkup
bmi ai_update
walkup: jmp moveup
walkdown: jmp movedown
;$1568,+10 4loc
;AI vector for POD/all other AIs jump here
; arg X: unit id #
;void ai_pod(id_t id);
ai_pod:
ai_update: ldx _id
jsr move_unit
ldx _id
jmp mm_update
;rts
;$1572,68 35loc
;Play a sound
; arg A: sound #
;void playsound(uint8_t sound);
playsound: sta _temp ;sound #
txa
pha
tya
pha
ldx _temp ;arg A
lda HoldSync,x
sta _temp ;#of chans
sndloop: lda HoldSync,x
sta ParamBlk +1
lda FlushChan,x ;chan #
sta ParamBlk
ldy #2
lda AmplEnvel,x
jsr ins_param
lda Pitch,x
jsr ins_param
lda Duration,x
jsr ins_param
sound: txa
pha ;save chn#
ldx #<ParamBlk
ldy #>ParamBlk
lda #7
jsr OSWORD ;SOUND(..)
sndnext: pla
tax ;channel #
inx
dec _temp
bpl sndloop
sndend: pla
tay
pla
tax
rts
;$15b6,+16 9loc
;Sign extend parameter byte + add to block
; arg Y: ParamBlock[index]
; arg A: signed data byte (-> word)
;void ins_param( uint8_t index,
; int8_t data);
ins_param: sta ParamBlk,y ;lo byte
iny
asl
lda #0
bcc inshi ;-ve parm?
lda #$ff
insmsb: sta ParamBlk,y ;hi byte
iny ;word->blk
rts
repaint_map:lda _min_xscr ;15c6
pha
lda _max_xscr ;not needed?
pha
lda #0
sta _min_xscr
lda #80
sta _max_xscr
ldx #31
rpmaploop: stx _xreg ;15d6
lda Unit,x
bpl rpmapnext ; b7 clear?
asl
bmi rpmapnext ; b6 set?
ldy pDot_l,x
sty _destptr_l
ldy pDot_h,x
beq rpmapnext
sty _destptr_h
lda Dot,x
tax
stx _yreg
jsr mm_blit ; erase old
ldx _xreg ; current slot
clc
lda _destptr_l
adc _scrolloff_l ; scroll
sta _destptr_l
sta pDot_l,x
lda _destptr_h
adc _scrolloff_h
bpl + ; wrap screen ram
sec
sbc #$50
+ cmp #$30 ;160a
bcs +
adc #$50
+ sta _destptr_h ;1610
sta pDot_h,x
ldx _yreg ; 2x sprite #
jsr mm_blit ; paint new
rpmapnext: ldx _xreg ; 161a
dex ; loop over slots #0-#31
bpl rpmaploop
pla
sta _max_xscr ;not needed?
pla
sta _min_xscr
rts
;$1626
;mm_blit
mm_blit: lda _destptr_h
bne hiblit ;onscreen?
rts ;NULL/no
hiblit: ldy #0
lda (_destptr),y
eor imgDot,x ;xor blit
sta (_destptr),y
hicopy: lda _destptr_h ;copy
sta _srcptr_h ;ptr
lda _destptr_l ; dest
sta _srcptr_l ;-> src
and #%111 ;row [0,7]
cmp #7 ;last row?
bne lowerdot
cellbelow: clc ;point one
lda _srcptr_l ;cell down
adc #120 ;+120
sta _srcptr_l
lda _srcptr_h
adc #2 ;+512
bpl lowerp ;=(+640-8)
sec
sbc #$50 ;wrap vram
loptr: sta _srcptr_h
loblit: iny ;ptr++
lda (_srcptr),y ;/down 1px
eor imgDot+1,x
sta (_srcptr),y ;xor blit
rts
;$165d
mm_update: jsr timerstate ;wait til
bpl mm_update ;raster >
cpx #ID_MAX + 1 ;#32
bcc mmupd2 ;id > MAX?
rts ;not unit
mmupd2: lda _min_xscr
pha
lda _max_xscr
pha
txa
pha ;save id
lda #0
sta _min_xscr
lda #80
sta _max_xscr
mmerase: lda pDot_l,x ;old dot
sta _destptr_l ;@vram
lda pDot_h,x
sta _destptr_h
lda Dot,x
tax
jsr mm_blit ;erase old
ydot: pla
pha ;id
tax
lda Y_h,x
lsr
lsr ;Yunit / 4
clc
adc #196 ;+ Yline
tay ;-> Ydot
xdot: sec
lda X_l,x
sbc _xrel_l
lda X_h,x
sbc _xrel_h ;-> Xscr/2
jsr xoffset110
lsr ;+27
lsr
php ; store carry = bit 1
clc
adc #8 ;+8
tax ;=35+(X/8)
jsr xy_to_vidp
plp
pla ;restore
tax ;arg X
php
lda _destptr_l ;new dot
sta pDot_l,x ;@vram
lda _destptr_h
sta pDot_h,x
lda Unit,x
asl
plp
bcc aligned
adc #21
aligned: sta Dot,x
tax
jsr mm_blit
pla
sta _max_xscr
pla
sta _min_xscr
rts
;$16d1
key_fire: ldx #KEY_RETURN ;-74
jsr scan_inkey
beq kfire2 ;!keydown?
eor _inkey_enter
kfire2: stx _inkey_enter
beq kfire_ret ;keypress?
ldx #3 ;[4] find
kfireloop: lda _Laser,x ;free beam
beq fire_laser ;found?
dex ;[3,0]
bpl kfireloop ;loop
kfire_ret: rts
;$16e8
fire_laser: stx _xreg ;beam[0,3]
lda Y_h + SHIP
sec
sbc #6 ;from nose
tay
ldx #SHIP
jsr get_xscr
tax
fireleft: dex ;L side
lda #$81 ;shoot L
bit _ddx_h
bmi + ;facing R?
fireright: txa
clc ;R side
adc #7 ;width+1
tax
lda #$01 ;shoot R
+ pha ;1705
txa
pha ;save
tya ;coords
pha
jsr xy_to_vidp ;_destptr
ldx _xreg ;beam slot
lda _destptr_l
sta _pTail_l,x
sta _pHead_l,x
lda _destptr_h
sta _pTail_h,x
sta _pHead_h,x
pla ;Y coord
sta _BeamY,x
pla ;X "
sta _BeamX,x
pla ;01/81
sta _Laser,x ;bm taken
lda #0
sta _Tail,x
sta _Head,x
lda #4
jmp playsound ;laser snd
;rts