-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevel.asm
1208 lines (949 loc) · 14.3 KB
/
level.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
travel: .macro
mov \1,tx
; debug_num
mov \2,ty
; debug_num
mov \3,td
; debug_num
jsr travel_func
pha
mov ttx,\4
; debug_num
mov tty,\5
; debug_num
pla
.endm
travel_func:
cmp #dir_up
beq .up
cmp #dir_down
beq .down
cmp #dir_left
beq .left
cmp #dir_right
beq .right
jmp .no
.up: lda ty ; top of map
beq .no
tax
dex
stx tty
mov tx,ttx
jmp .yes
.down: lda ty
cmp #9
beq .no
tax
inx
stx tty
mov tx,ttx
jmp .yes
.left: lda tx
beq .no
tax
dex
stx ttx
mov ty,tty
jmp .yes
.right: lda tx
cmp #17
beq .no
tax
inx
stx ttx
mov ty,tty
jmp .yes
.no: mov tx,ttx
mov ty,tty
lda #0
rts
.yes: lda #1
rts
tileat: .macro
ldx \1
ldy \2
jsr tileat_func
.endm
tileat_func:
jsr xy_to_index
tax
lda tiles, X
; debug_p ds_tileat
; debug_num
rts
flagat: .macro
ldx \1
ldy \2
jsr flagat_func
.endm
flagat_func:
jsr xy_to_index
tax
lda flags, X
rts
destat: .macro
ldx \1
ldy \2
jsr destat_func
.endm
destat_func:
jsr xy_to_index
tax
lda dests, X
rts
xy_to_index:
; debug_p ds_xy_to_index
clc
txa
.yloop: dey
bmi .done
adc #18
jmp .yloop
.done:
; debug_num
rts
where: ;; index is in A, put x and y in X and Y
debug_p ds_where
tax
ldy #0
sec
debug_num
.loop: sbc #18
bcc .done
iny
tax
jmp .loop
.done:
; stx debug_port
; sty debug_port
rts
settile: .macro
ldx \1
ldy \2
mov \3,new_tile
jsr settile_func
.endm
settile_func:
jsr xy_to_index
sta tile_pos
tax
lda new_tile
sta tiles, X
jmp update_tile_buffer
swaptiles: .macro
mov \1,swap_tile_1
mov \2,swap_tile_2
jsr swaptiles_func
.endm
swaptiles_func:
debug_p ds_swaptiles
ldx #180
.loop:
dex
beq .done
lda tiles, X
cmp swap_tile_1
beq .update1
cmp swap_tile_2
beq .update2
jmp .loop
.update1:
lda swap_tile_2
jmp .update
.update2:
lda swap_tile_1
.update:
sta tiles, X
stx tile_pos
jsr update_tile_buffer
ldx tile_pos
jmp .loop
.done:
rts
checkstepoff:
ldx gx
ldy gy
jsr tileat_func
cmp #T_TRAP1
beq .t_hole
cmp #T_TRAP2
beq .t_trap1
rts
.t_hole:
mov #T_HOLE,new_tile
jmp settile_func
.t_trap1
mov #T_TRAP1,new_tile
jmp settile_func
checkleavepanel:
ldx gx
ldy gy
jsr tileat_func
cmp #T_PANEL
beq .swap
rts
.swap:
destat gx,gy
jmp swapo
issphere: .macro
ldx \1
ldy \2
jsr issphere_func
.endm
issphere_func:
jsr tileat_func
cmp #T_SPHERE
beq .yes
cmp #T_BSPHERE
beq .yes
cmp #T_GSPHERE
beq .yes
cmp #T_RSPHERE
beq .yes
;; no
lda #0
rts
.yes: lda #1
rts
realpanel:
tax ; save the flag
and #TF_RPANELH
beq .not_rpanelh
txa
and #TF_RPANELL
beq .is_gpanel
lda #T_RPANEL
rts
.is_gpanel:
lda #T_GPANEL
rts
.not_rpanelh:
txa
and #TF_RPANELL
beq .is_panel
lda #T_BPANEL
rts
.is_panel:
lda #T_PANEL
rts
swapo:
;; index in A
tax
lda tiles,X
tay
lda otiles,X
sta tiles,X
sta new_tile
tya
sta otiles,X
stx tile_pos
jsr update_tile_buffer
;; crazy stuff
ldx tile_pos
lda flags,X
tay ; save
;; erase old flags
and #~(TF_HASPANEL | TF_OPANEL | TF_RPANELL | TF_RPANELH | TF_ROPANELL | TF_ROPANELH)
sta tmp
;; swap panel bits
tya
and #TF_HASPANEL ; if haspanel, set opanel (in parallel!)
beq .next1
lda tmp
ora #TF_OPANEL
sta tmp
.next1:
tya
and #TF_OPANEL ; if opanel, set haspanel
beq .next2
lda tmp
ora #TF_HASPANEL
sta tmp
.next2:
tya
and #TF_RPANELL
beq .next3
lda tmp
ora #TF_ROPANELL
sta tmp
.next3:
tya
and #TF_RPANELH
beq .next4
lda tmp
ora #TF_ROPANELH
sta tmp
.next4:
tya
and #TF_ROPANELL
beq .next5
lda tmp
ora #TF_RPANELL
sta tmp
.next5:
tya
and #TF_ROPANELH
beq .next6
lda tmp
ora #TF_RPANELH
sta tmp
.next6:
;; finally, set!
lda tmp
sta flags,X
rts
do_move:
step_table_target .equ tmp16
mov #0,doswap
lda newd
sta gd
travel gx,gy,newd,newx,newy
bne .continue ; check for actual movement
;; no movement!
jmp no_move
.continue:
debug_p ds_step_table
tileat newx,newy
sta target
asl A
tax
debug_num
lda step_table, X
sta step_table_target
inx
lda step_table, X
sta step_table_target+1
jmp [step_table_target]
panel_step:
destat newx,newy
jsr swapo
plain_move:
debug_p ds_plain_move
jsr checkleavepanel
jsr checkstepoff
mov newx,gx
debug_num
mov newy,gy
debug_num
jsr make_step_sound
jmp update_scroll_from_guy
push_block:
;; directional blocks can only go the correct way
lda target
cmp #T_LR
beq .lr
cmp #T_UD
beq .ud
jmp .next1
.lr:
lda newd
cmp #dir_up
bne .lr1
jmp no_move
.lr1: cmp #dir_down
bne .next1
jmp no_move
.ud:
lda newd
cmp #dir_left
bne .ud1
jmp no_move
.ud1: cmp #dir_right
bne .next1
jmp no_move
.next1:
;; check to make sure the block can move
travel newx,newy,newd,destx,desty
bne .next1_1
jmp no_move
.next1_1:
;; check the TF_HASPANEL flag
flagat newx,newy
and #TF_HASPANEL
beq .replace_with_floor
;; if it has it, then set the replacement to be the panel
flagat newx,newy
jsr realpanel
sta replacement
jmp .next2
;; otherwise, T_FLOOR
.replace_with_floor:
mov #T_FLOOR,replacement
.next2:
tileat destx,desty
cmp #T_FLOOR
bne .next3
;; floor
settile destx,desty,target
settile newx,newy,replacement
jmp plain_move
.next3: ; colored panels
tileat destx,desty
cmp #T_BPANEL
beq .colored_panel
cmp #T_RPANEL
beq .colored_panel
cmp #T_GPANEL
beq .colored_panel
jmp .next4
.colored_panel:
lda target
cmp #T_LR
bne .colored_panel1
jmp no_move
.colored_panel1:
cmp #T_UD
bne .colored_panel2
jmp no_move
.colored_panel2:
settile destx,desty,target
settile newx,newy,replacement
jmp plain_move
.next4: ; electric
tileat destx,desty
cmp #T_ELECTRIC
bne .next5
lda target
cmp #T_LR
bne .next4_1
jmp no_move
.next4_1:
cmp #T_UD
bne .next4_2
jmp no_move
.next4_2:
settile newx,newy,replacement
jsr make_zap_sound ; block is zapped!
jmp plain_move
.next5:
tileat destx,desty ; grey into hole
cmp #T_HOLE
bne .next6
lda target
cmp #T_GREY
beq .next5_1
jmp no_move
.next5_1:
settile destx,desty, #T_FLOOR
settile newx,newy,replacement
jsr make_hole_plug_sound
jmp plain_move
.next6: ; regular panel
tileat destx,desty
cmp #T_PANEL
beq .next6_1
jmp no_move
.next6_1:
lda target
cmp #T_LR
bne .next6_2
jmp no_move
.next6_2:
cmp #T_UD
bne .next6_3
jmp no_move
.next6_3:
settile destx,desty,target
settile newx,newy,replacement
jsr plain_move
;; special thing for panel (doswap in the C++ version)
destat destx,desty
jmp swapo
push_green:
;; check to make sure the block can move
travel newx,newy,newd,destx,desty
bne .next1
jmp no_move
.next1:
tileat destx,desty
cmp #T_FLOOR
bne no_move
;; set stuff
settile destx,desty, #T_BLUE
settile newx,newy, #T_FLOOR
jmp plain_move
electric_off:
settile newx,newy, #T_OFF
;; iterate over all
debug_p ds_electric_off
ldx #180
.e_loop:
dex
beq .done
lda tiles, X
cmp #T_ELECTRIC
beq .update
jmp .e_loop
.update:
lda #T_FLOOR
sta tiles, X
stx tile_pos
jsr update_tile_buffer
ldx tile_pos
jmp .e_loop
.done:
jmp make_electric_off_sound
no_move:
debug_p ds_no_move
jmp make_no_move_sound
slide_push:
debug_p ds_slide_push
.while:
issphere newx,newy
beq .wend
travel newx,newy,newd,tnx,tny
beq .wend
issphere tnx,tny
beq .wend
debug_p ds_sphere_sliding
mov tnx,newx
mov tny,newy
tileat tnx,tny
sta target
debug_num
jmp .while
.wend:
mov newx,goldx
mov newy,goldy
;; remove gold block
flagat goldx,goldy
and #TF_HASPANEL
beq .not_panel
;; set replacement to be panel
flagat goldx,goldy
jsr realpanel
sta new_tile
ldx goldx
ldy goldy
jsr settile_func
jmp .next1
.not_panel:
;; replace with floor
settile goldx,goldy,#T_FLOOR
.next1:
.while2:
travel goldx,goldy,newd,tgoldx,tgoldy
bne .slide_block
jmp .wend2
.slide_block:
debug_p ds_block_sliding
tileat tgoldx,tgoldy
cmp #T_ELECTRIC
beq .no_while2_break
cmp #T_PANEL
beq .no_while2_break
cmp #T_BPANEL
beq .no_while2_break
cmp #T_RPANEL
beq .no_while2_break
cmp #T_GPANEL
beq .no_while2_break
cmp #T_FLOOR
beq .no_while2_break
jmp .wend2
.no_while2_break:
ldx tgoldx
stx goldx
ldy tgoldy
sty goldy
cmp #T_ELECTRIC
beq .wend2
jmp .while2
.wend2:
;; goldx is dest, newx is source
lda goldx
cmp newx
bne .next2
lda goldy
cmp newy
bne .next2
;; else, didn't move, put it back
settile newx,newy,target
jmp no_move
.next2:
tileat goldx,goldy
sta landon
lda #0
sta doswap
;; untrigger from source
flagat newx,newy
tax
and #TF_HASPANEL
bne .next3
txa
jsr realpanel
cmp #T_PANEL ; if panel, do swap, or if the sphere matches
beq .set_doswap
tax
lda target
cmp #T_GSPHERE
beq .gsphere
cmp #T_RSPHERE
beq .rsphere
cmp #T_BSPHERE
beq .bsphere
jmp .next3
.gsphere:
txa
cmp #T_GPANEL
beq .set_doswap
jmp .next3
.rsphere:
txa
cmp #T_RPANEL
beq .set_doswap
jmp .next3
.bsphere:
txa
cmp #T_BPANEL
beq .set_doswap
jmp .next3
.set_doswap:
mov #1,doswap
.next3:
lda landon
;; only the correct color sphere can trigger the colored panels
cmp #T_GPANEL
beq .gsphere2
cmp #T_BPANEL
beq .bsphere2
cmp #T_RPANEL
beq .rsphere2
cmp #T_PANEL
beq .do_gold_swapo
jmp .next4
.gsphere2:
lda target
cmp #T_GSPHERE
beq .do_gold_swapo
jmp .next4
.bsphere2:
lda target
cmp #T_BSPHERE
beq .do_gold_swapo
jmp .next4
.rsphere2:
lda target
cmp #T_RSPHERE
beq .do_gold_swapo
jmp .next4
.do_gold_swapo:
destat goldx,goldy
jsr swapo
.next4:
settile goldx,goldy,target
lda landon
cmp #T_ELECTRIC
bne .next5
;; gold is zapped, cover some corner case too
settile goldx,goldy,#T_ELECTRIC
jsr make_zap_sound
.next5:
lda doswap
bne .no_swap
;; swap
destat newx,newy
jsr swapo
.no_swap:
jmp make_slide_sound
transport_guy:
destat newx,newy
jsr where
stx newx
sty newy
jsr plain_move
tileat newx,newy
cmp #T_PANEL
bne .no_swap
;; swap
destat newx,newy
jsr swapo
.no_swap:
jmp make_transport_sound
break_block:
settile newx,newy,#T_FLOOR
jmp make_break_sound
t_0_hit:
swaptiles #T_UD,#T_LR
settile newx,newy,#T_1
jmp make_swap_sound
t_1_hit:
swaptiles #T_UD,#T_LR
settile newx,newy,#T_0
jmp make_swap_sound
send_pulse:
mov #dir_up, pulsed
jsr .send_pulse_helper
mov #dir_down, pulsed
jsr .send_pulse_helper
mov #dir_left, pulsed
jsr .send_pulse_helper
mov #dir_right, pulsed
jsr .send_pulse_helper
jmp make_pulse_sound
.send_pulse_helper:
mov newx,pulsex
mov newy,pulsey
.while: travel pulsex,pulsey,pulsed,pulsex,pulsey
bne .continue
jmp .wend
.continue:
tileat pulsex,pulsey
cmp #T_BLIGHT
beq .t_blight
cmp #T_RLIGHT
beq .t_rlight
cmp #T_GLIGHT
beq .t_glight
cmp #T_NS
beq .t_ns
cmp #T_WE
beq .t_we
cmp #T_NW
beq .t_nw
cmp #T_SW
beq .t_sw
cmp #T_NE
beq .t_ne
cmp #T_SE
bne .not_se
jmp .t_se
.not_se:
jmp .wend
.t_blight:
swaptiles #T_BUP, #T_BDOWN
jmp .wend
.t_rlight:
swaptiles #T_RUP, #T_RDOWN
jmp .wend
.t_glight:
swaptiles #T_GUP, #T_GDOWN
jmp .wend
.t_ns:
lda pulsed
cmp #dir_up
bne .t_ns1
jmp .while
.t_ns1:
cmp #dir_down
bne .t_ns2
jmp .while
.t_ns2:
jmp .wend
.t_we:
lda pulsed
cmp #dir_left
bne .t_we1
jmp .while
.t_we1:
cmp #dir_right
bne .t_we2
jmp .while
.t_we2:
jmp .wend
.t_nw:
lda pulsed
cmp #dir_down
beq .dir_left
cmp #dir_right
beq .dir_up
jmp .wend
.t_sw:
lda pulsed
cmp #dir_up
beq .dir_left
cmp #dir_right
beq .dir_down
jmp .wend
.t_ne:
lda pulsed
cmp #dir_down
beq .dir_right
cmp #dir_left
beq .dir_up
jmp .wend
.t_se:
lda pulsed
cmp #dir_up
beq .dir_right
cmp #dir_left
beq .dir_down
jmp .wend
.dir_left:
mov #dir_left,pulsed
jmp .while
.dir_right: