-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsteps.asm
2959 lines (2736 loc) · 79.2 KB
/
steps.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
include "vcs.h"
include "macro.h"
NTSC = 0
PAL60 = 1
IFNCONST SYSTEM
SYSTEM = NTSC
ENDIF
; ----------------------------------
; constants
#if SYSTEM = NTSC
; NTSC Colors
SKY_BLUE = $A0
SKY_YELLOW = $FA
DARK_WATER = $A0
SUN_RED = $30
CLOUD_ORANGE = $22
GREY_SCALE = $02
WHITE_WATER = $0A
EARTH_BROWN = $F1
TIMER_RED = $4f
GREEN = $B3
RED = $43
YELLOW = $1f
WHITE = $0f
BLACK = 0
BROWN = $F1
SCANLINES = 262
#else
; PAL Colors
; Mapped by Al_Nafuur @ AtariAge
SKY_BLUE = $92
SKY_YELLOW = $2A
DARK_WATER = $92
SUN_RED = $42
CLOUD_ORANGE = $44
GREY_SCALE = $02
WHITE_WATER = $0A
EARTH_BROWN = $21
TIMER_RED = $6f
GREEN = $72
RED = $65
YELLOW = $2E
WHITE = $0E
BLACK = 0
BROWN = $21
SCANLINES = 262
#endif
ZARA_COLOR = WHITE_WATER
GROUND_COLOR = GREEN
LAVA_COLOR = RED
CLOCK_HZ = 60
STAIRS_MARGIN = 2
NUM_AUDIO_CHANNELS = 2
CHAR_HEIGHT = 8
DRAW_TABLE_SIZE = 18
JUMP_TABLE_SIZE = 16
JUMP_TABLE_BYTES = JUMP_TABLE_SIZE
JUMP_SOLUTION_BYTES = JUMP_TABLE_SIZE / 8
FLIGHTS_TABLE_SIZE = 16
FLIGHTS_TABLE_BYTES = FLIGHTS_TABLE_SIZE
LAVA_TIME_MODULUS = 8
PLAYER_STEP_HEALTH = ZARA_COLOR * 8
GAME_START_SECONDS = 3
GAME_STATE_TITLE = 0
GAME_STATE_SELECT = 1
GAME_STATE_START = 2
GAME_STATE_CLIMB = 3
GAME_STATE_JUMP = 4
GAME_STATE_SCROLL = 5
GAME_STATE_FALL = 6
GAME_STATE_END = 7
DIFFICULTY_LEVEL_ARRAY_MASK = $3
DIFFICULTY_LEVEL_LAVA = $4
DIFFICULTY_LEVEL_DARK = $8
AUDIO_VOLUME = 8
; ----------------------------------
; vars
SEG.U VARS
ORG $80
; frame-based "clock"
frame ds 1
game_state ds 1
difficulty_level ds 1
; game audio
audio_sequence ds 1 ; play multiple tracks in sequence
audio_timer ds 2 ; time to next note
audio_tracker ds 2 ; which note is playing
audio_vx ds 1 ; volume
; random var
seed
random ds 2
; combined player input
; bits: f...rldu
player_input ds 2
; debounced p0 input
player_input_latch ds 1
player_special_latch ds 1 ; latch for detecting sequences
player_step ds 1 ; step the player is at
player_jump ds 1 ; jump counter
player_inc ds 1 ; direction of movement
player_goal ds 1 ; next goal
player_score ds 1 ; decimal score
player_clock ds 1 ; for player timer
player_timer ds 2 ; game timer
player_health ds 1 ; health left
; night_mode
sky_palette ds 1 ;
; lava control
lava_clock ds 1
lava_height ds 1 ; height on screen
lava_jump_offset ds 1 ; height vs jump table
; game state
jump_table ds JUMP_TABLE_BYTES
jump_table_offset ds 1 ; where to locate jump table for drawing
jump_table_size ds 1 ; number of entries in jump table
;jump_solution ds JUMP_SOLUTION_BYTES
; steps drawing
jump_layout_index ds 1 ; layout index for jump table
base_layout_index ds 1 ; layout index for base of stairs
jump_layout_repeat ds 1 ; number of repeats left for jump table
base_layout_repeat ds 1 ; number of repeats left for base of stairs
draw_colubk ds 1
draw_registers_start
; steps drawing registers
draw_steps_respx ds 1
draw_steps_dir ds 1 ; top of steps direction
draw_steps_mask ds 1
draw_steps_wsync ds 1 ; amount to shim steps up/down
draw_base_dir ds 1 ; base of steps direction
draw_base_lr ds 1 ; base of steps lr position
draw_base_flight ds 1
draw_player_dir ds 1 ; player travel direction
draw_step_offset ds 1 ; what step # do we start drawing at
draw_ground_color ds 1 ; ground color
draw_lava_counter ds 1 ; how far to lava counter
draw_player_sprite ds 1
draw_table ds DRAW_TABLE_SIZE
draw_table_top ds 1 ; steps to skip at start
draw_step_colors ds DRAW_TABLE_SIZE
; draw vars used during draw kernels
draw_hmove_a ds 1 ; initial HMOVE
draw_hmove_b ds 1 ; reverse HMOVE
draw_hmove_next ds 1 ; next queued HMOVE
draw_s0_addr ds 2
draw_s1_addr ds 2
draw_s2_addr ds 2
draw_s3_addr ds 2
draw_s4_addr ds 2
draw_s5_addr ds 2
; temp vars
temp_select_index
temp_solve_current
temp_step_start
temp_step_offset
temp_margin
temp_level_ptr ; (ds 2)
temp_maze_ptr ; (ds 2)
temp_y ds 1
temp_select_repeat
temp_layout_repeat
temp_step_end
temp_solve_jump
temp_p4 ds 1
temp_select_mask
temp_timer_stack
temp_solve_stack
temp_rand ds 1
; draw registers for title and select screen
ORG draw_registers_start
; title drawing registers
draw_t0
draw_t0_p0_addr ds 2
draw_t0_p1_addr ds 2
draw_t0_p2_addr ds 2
draw_t0_p3_addr ds 2
draw_t0_p4_addr ds 2
draw_t0_jump_addr ds 2
draw_t0_data_addr ds 2
draw_t1
draw_t1_p0_addr ds 2
draw_t1_p1_addr ds 2
draw_t1_p2_addr ds 2
draw_t1_p3_addr ds 2
draw_t1_p4_addr ds 2
draw_t1_jump_addr ds 2
draw_t1_data_addr ds 2
; DONE
; - basic step display
; - static sprite moves according to rules
; - debug steps
; - visual 1
; - start on ground (first step below)
; - smooth scroll up
; - values disappear as you climb
; - gameplay 1
; - start mode
; - win condition
; - score display
; - timer display
; - mix of puzzles
; - climb step by step
; - time based randomization
; - fall step by step
; - difficulty select
; - do we need a score at all? no - just flights count
; - sounds 1
; - bounce up/down notes
; - landing song
; - final success
; - jingles on transition moments
; - fall down should use messed up voice/detuned scale
; - visual 2
; - time display have :
; - PF gutters
; - title
; - goal step has a graphic of some sort
; - stair outlines
; - color stairs
; - tune colors
; - colors don't have enough contrast
; - no zeros on stairs
; - highest step has crown
; - player points in direction of travel
; - fall tumble animation
; - gameplay 2
; - tweak scoring
; - drop mazes 10 and 14
; - improved select screen (directions l/r)
; - improved game start (no press button, countdown start?)
; - improved win no end early (scroll up win? double press)
; - way to end game when no time limit?
; - glitches
; - jacked up select
; - stabilize frames
; - stabilize stair display horizontally
; - when the player wins on a 16, can't see
; - steps at top of screen should be invisible
; - stair display horizontal align is bad for 16 across
; - steps at last flight should be invisible
; - acorn needs to be shifted based on direction
; - player needs to be shifted based on direction
; - player is floating 2 above bottom of stair
; - need the ground to appear properly
; - select screen towers should start on left
; - missing step edges on left of screen (GRP1 timing)
; - steps at bottom glitch out with direction change
; - timer display is jacked up
; - countdown timer too long
; - pressing select mid title forces the select music not the go tune
; - pressing select mid title should kill all audio
; - steps scale not progressive
; - MVP DONE
; - code size
; - shrink or remove flights array
; - optimize title screen
; - sounds 2
; - tuneup sound pass
; - glitches
; - frame rate low 243 in select
; - frame rate high 270+ at top of tower
; - counter has a glitch before dropoff
; - player at second to last step has glitch
; - dark mode doesn't handle ground
; - select screen glitch
; - select screen design, shows lava, etc
; - gameplay 3
; - lava (time attack) mode - steps "catch fire"?
; - lava should scroll appropriate to stairs scroll but "keep up" relative to bottom step
; - need fail state condition
; - dark mode - limited step visibility, double button press "plays" solution musically
; - sky black
; - steps obscured
; - sprinkles 1
; - animated squirrels in title and select
; RC 1
; - sprinkles 1
; - some kind of lose song
; - some kind of celebration on win (fireworks?)
; - glitches
; - extra line in scroll
; - leftmost step cut off
; CONSIDER
; - sprinkles 2
; - some kind of theme on lose
; - gradient/lightened sky background
; - should be no step edge in ground?
; - code
; - algorithmic maze gen
; - use incremental maze construction to conserve VBLANK
; - shrink maze size (replace with generation) - 678 bytes data + code
; - less data + code for title - 798 bytes data + code
; - shrink audio size - 256 bytes + 122 bytes code
; - sprinkles 3
; - color flashes in titles
; - some kind of graphic in sky (cloud? bird?)
; - horizontal screen transitions
; - visual 3
; - jump animation (Q: is that even feasible with this kernel)
; - size 1 stairs no number?
; - addressible colors on stairs
; - gameplay 5
; - player builds maze by dropping numbers?
; - player builds maze as numbers drop?
; - zero / missing steps in mazes
; - stair swapping / maze changing mechanic
; ****T G
; ***T2 G
; **2T3G
; - breakable stairs - 1 or two touches cause break?
; - flight jumping mechanic
; NODO
; - second player
; - flag at goal step?
; - no fall penalty from start step?
; ----------------------------------
; code
SEG
ORG $F000
Reset
CleanStart
; do the clean start macro
CLEAN_START
; PF and background
lda #0
sta COLUPF
lda #01
sta CTRLPF
lda #$70
sta PF0
; audio
lda #AUDIO_VOLUME
sta audio_vx
; init RNG
lda #17
sta seed
sta seed + 1
jsr sub_galois
newFrame
; 3 scanlines of vertical sync signal to follow
ldx #%00000010
stx VSYNC ; turn ON VSYNC bit 1
ldx #0
sta WSYNC ; wait a scanline
sta WSYNC ; another
sta WSYNC ; another = 3 lines total
stx VSYNC ; turn OFF VSYNC bit 1
; 37 scanlines of vertical blank to follow
;--------------------
; VBlank start
lda #%00000010
sta VBLANK
lda #42 ; vblank timer will land us ~ on scanline 34
sta TIM64T
; check reset switches
lda #$01
bit SWCHB
bne _end_switches
jmp CleanStart
_end_switches
;---------------------
; update kernels
inc frame
ldx sky_palette
lda SKY_PALETTE,x
sta draw_colubk
ax_sequencer
; track sequencing
ldx audio_sequence
beq ax_update
lda audio_tracker
bne ax_update
lda AUDIO_SEQUENCES,x
beq ax_update
sta audio_tracker
inx
lda AUDIO_SEQUENCES,x
sta audio_tracker + 1
lda #0
sta audio_timer + 1 ; force sync
inx
stx audio_sequence
ax_update
ldx #NUM_AUDIO_CHANNELS - 1
_ax_loop
lda audio_tracker,x
beq _ax_next
ldy audio_timer,x
beq _ax_next_note
dey
sty audio_timer,x
jmp _ax_next
_ax_next_note
tay
lda AUDIO_TRACKS,y
beq _ax_stop
lsr ; .......|C pull first bit
bcc _ax_set_all_registers ; .......|? if clear go to load all registers
lsr ; 0......|C1 pull second bit
bcc _ax_cx_vx ; 0......|?1 if clear we are loading aud(c|v)x
lsr ; 00fffff|C11 pull duration bit for later set
sta AUDF0,x ; store frequency
bpl _ax_set_timer_delta ; jump to duration (note: should always be positive)
_ax_cx_vx lsr ; 00.....|C01
bcc _ax_vx ; 00.....|?01
lsr ; 000cccc|C101
sta AUDC0,x ; store control
bpl _ax_set_timer_delta ; jump to duration (note: should always be positive)
_ax_vx
lsr ; 000vvvv|C001
sta AUDV0,x ; store volume
_ax_set_timer_delta
rol audio_timer,x ; set new timer to 0 or 1 depending on carry bit
bpl _ax_advance ; done (note: should always be positive)
_ax_set_all_registers
; processing all registers
lsr ; 00......|C0
bcc _ax_set_suspause ; 00......|?0 if clear we are suspausing
lsr ; 0000fffff|C10 pull duration bit
sta AUDF0,x ; store frequency
rol audio_timer,x ; set new timer to 0 or 1 depending on carry bit
iny ; advance 1 byte
lda AUDIO_TRACKS,y ; ccccvvvv|
sta AUDV0,x ; store volume
lsr ; 0ccccvvv|
lsr ; 00ccccvv|
lsr ; 000ccccv|
lsr ; 0000cccc|
sta AUDC0,x ; store control
bpl _ax_advance ; done (note: should always be positive)
_ax_set_suspause
lsr ; 000ddddd|C00 pull bit 3 (reserved)
sta audio_timer,x ; store timer
bcs _ax_advance ; if set we sustain
lda #0
sta AUDV0,x ; clear volume
_ax_advance
iny
sty audio_tracker,x
jmp _ax_next
_ax_stop ; got a 0
sta AUDV0,x
sta audio_timer,x
sta audio_tracker,x
_ax_next
dex
bpl _ax_loop
; update player input
jx_update
ldx #1
lda SWCHA
and #$0f
_jx_update_loop
sta player_input,x
lda #$80
and INPT4,x
ora player_input,x
sta player_input,x
_jx_update_no_signal
dex
bmi _jx_update_end
lda SWCHA
lsr
lsr
lsr
lsr
ldy player_input
jmp _jx_update_loop
_jx_update_end
tya ; debounce p0 joystick
eor #$8f
ora player_input
sta player_input_latch
; process game state
ldx game_state
lda GX_JUMP_HI,x
pha
lda GX_JUMP_LO,x
pha
rts
gx_climb
lda #<SYMBOL_GRAPHICS_ZARA
sta draw_player_sprite
gx_update
ldx player_step
lda jump_table,x ; load jump distance for any moves
and #$0f
tay
lda player_input
bpl _gx_update_special_latch
sta player_special_latch
lda player_input_latch
ror
bcs _gx_update_check_down
jmp gx_go_up
_gx_update_check_down
ror
bcs _gx_update_check_left
jmp gx_go_down
_gx_update_check_left
ror
bcs _gx_update_check_right
bit draw_player_dir
bmi _gx_update_rev_left
_gx_update_rev_right
jmp gx_go_down
_gx_update_check_right
ror
bcs gx_update_return
bit draw_player_dir
bmi _gx_update_rev_right
_gx_update_rev_left
jmp gx_go_up
_gx_update_special_latch
; rol jump_solution ; SOLVE
; rol jump_solution + 1 ; SOLVE
; bcs _gx_update_rev_left ; SOLVE
; jmp gx_go_down ; TESTING SOLVE
and player_special_latch
sta player_special_latch
bne gx_update_return
; if we hit all the switches, exit
jmp Reset
gx_update_return
ldx #1
jsr gx_player_clock
_update_lava
; lava
lda lava_height
beq _skip_lava_update
lda lava_jump_offset
sec
sbc jump_table_offset
bmi _update_lava_speedup
clc
sbc player_step
bmi _skip_player_health_drain
dec player_health
bpl _skip_player_health_drain
jsr sub_steps_lose
jmp gx_continue
_skip_player_health_drain
lda frame
and #LAVA_TIME_MODULUS
beq _end_lava_update
dec lava_clock
bne _end_lava_update
_update_lava_speedup
inc lava_height
lda difficulty_level
and #$03
tax
lda LAVA_SPEED,x
sta lava_clock
_end_lava_update
_skip_lava_update
gx_continue
jsr sub_calc_respx
; prep timer gx
lda player_timer
ldx #4
jsr sub_write_digit
lda player_score
ldx #8
jsr sub_write_digit
; player colors
lda player_health ; trick: color * 8
lsr
lsr
lsr
sta COLUP0
; step colors
ldx #(DRAW_TABLE_SIZE - 1)
lda #$1f
_gx_continue_step_colors_loop
sta draw_step_colors,x
_gx_continue_step_colors_skip_0f
clc
adc #$10
cmp #$0f
beq _gx_continue_step_colors_skip_0f
dex
bpl _gx_continue_step_colors_loop
; altitude
ldx #LAVA_COLOR
lda lava_height
cmp #10 ; BUGBUG: check flight
bpl _gx_continue_ground_calc
ldx draw_colubk
lda draw_base_flight
ora draw_step_offset
bne _gx_continue_ground_calc
ldx #GROUND_COLOR
_gx_continue_ground_calc
stx draw_ground_color
lda #138 ; BUGBUG: magic number
sec
sbc lava_height
sta draw_lava_counter
;---------------------
; climb screen
jsr sub_vblank_loop
gx_step_draw
lda #(DRAW_TABLE_SIZE - 1)
sec
sbc draw_table_top
beq gx_steps_resp_a
tax
_gx_step_draw_sky_loop
ldy #9
_gx_step_skip_step_loop
sta WSYNC
dey
bpl _gx_step_skip_step_loop
dex
bne _gx_step_draw_sky_loop
byte $2c ; skip next WSYNC
gx_steps_resp_a
sta WSYNC
gx_steps_resp_b
lda draw_player_dir
bit player_inc
bpl _gx_steps_resp_skip_invert
eor #$ff
_gx_steps_resp_skip_invert
sta REFP0
lda draw_steps_respx
ldy draw_steps_dir
jsr sub_steps_respxx
; intentional
ldy draw_steps_wsync
sty temp_step_start
ldy #$0
sty temp_step_end
ldx draw_table_top
sta WSYNC
jmp sub_write_stair_b
_gx_step_draw_loop
sub_write_stair_a
; x is stair #
; first process if we're going to flip
lda draw_steps_mask ;3 3
ldy draw_hmove_next ;3 6
sty HMP0 ;3 9
cpy draw_hmove_a ;3 12
sta WSYNC ; max here is 68
beq ._gx_draw_skip_flip ;2 2
eor #$81 ;2 4
sta draw_steps_mask ;3 7
lda draw_hmove_a ;3 10
sty draw_hmove_a ;3 13
tay ;2 15
sty draw_hmove_b ;3 18
lda #0 ; BUGBUG: kludge ;2 20
._gx_draw_skip_flip
sta GRP1 ;3 23
lda #0 ;2 25
sta GRP0 ;3 28
sty HMP1 ;3 31
sub_write_stair_b
; read graphics from a
; phg.ssss
lda draw_table,x ;4 35
; get player graphic
ldy #(<SYMBOL_GRAPHICS_BLANK) ;2 37
asl ;2 39
bcc ._gx_draw_set_p0 ;2 41
ldy draw_player_sprite ;3 44
._gx_draw_set_p0
sty draw_s0_addr ;3 47
; swap directions
asl ;2 49
ldy draw_hmove_a ;3 52
bcc ._gx_draw_end_swap_direction ;2 54
ldy draw_hmove_b ;3 57
._gx_draw_end_swap_direction
sty draw_hmove_next ;3 60
; shift ground bit, check later
asl ;2 62
; get step graphic
bne ._gx_draw_skip_blank ;2 64
lda #<SYMBOL_GRAPHICS_BLANK ;2 66
._gx_draw_skip_blank
sta draw_s1_addr ;3 69
ldy draw_step_colors,x ;4 73 - 5
bcc ._gx_draw_alt_color ;2 75 - 5
ldy draw_colubk ;3 78 - 5; NOTE: very tight timing, current max 72
._gx_draw_alt_color
sta WSYNC ;
sta HMOVE ;3 3
sty COLUP1 ;3 6
lda draw_colubk ;3 16 ; SPACE could set this earlier and save a byte
sta COLUBK ;3 19
ldy temp_step_start ;3 22
cpy temp_step_end ;3 25
beq ._gx_draw_skip_stair ;2 27
cpx draw_table_top ;2
beq _gx_draw_loop ;2
lda #$ff ;2
sta GRP1 ;3
_gx_draw_loop
sub_draw_stair
dec draw_lava_counter
bne ._gx_draw_skip_lava
stx lava_jump_offset
lda #LAVA_COLOR
sta draw_colubk
._gx_draw_skip_lava
lda (draw_s0_addr),y
bit player_inc
bmi ._gx_draw_player_r
asl
byte $80 ; skip one byte
._gx_draw_player_r
lsr
sta WSYNC
sta GRP0 ;3 3
lda (draw_s1_addr),y ;5 8
bit draw_steps_mask ;3 11
bpl ._gx_draw_stair_l ;2 13
lsr ;2 15
._gx_draw_stair_l
ora draw_steps_mask ;3 18
sta GRP1 ;3 21
lda draw_colubk ;3 24
sta COLUBK ;3 27
dey ;2 29
cpy temp_step_end ;3 32
bne _gx_draw_loop ;2 34
._gx_draw_skip_stair
dex ;2 36
bmi gx_timer ;2
bne ._gx_draw_skip_stop ;2
lda draw_ground_color
sta draw_colubk
ldy draw_steps_wsync
._gx_draw_skip_stop
sty temp_step_end
ldy #CHAR_HEIGHT
sty temp_step_start
jmp _gx_step_draw_loop
gx_timer
sta WSYNC
inx ; SPACE: was -1
stx GRP0
stx GRP1
stx GRP0
sta REFP0
; place digits
lda #94 ; BUGBUG: magic number
ldy #$ff
jsr sub_steps_respxx
sta WSYNC ; shim
; set hi digits for timer
ldx #0
stx COLUBK
lda player_timer + 1
jsr sub_write_digit
; set up for 32px display
lda #3
sta NUSIZ0
sta NUSIZ1
sta VDELP0
sta VDELP1
tsx
stx temp_timer_stack
sta WSYNC
sta HMOVE
lda #WHITE
ldx game_state
cpx #GAME_STATE_START
bne _gx_timer_color
lda player_clock
lsr
lsr
eor #TIMER_RED
_gx_timer_color
sta COLUP0
sta COLUP1
ldy #(CHAR_HEIGHT) ; go one higher to create top line
_gx_timer_loop
sta WSYNC
SLEEP 3;
lda (draw_s0_addr),y ;5 5
sta GRP0 ;3 8
lda (draw_s1_addr),y ;5 13
ora TIMER_MASK,y ;4 17
sta GRP1 ;3 20
lda (draw_s2_addr),y ;5 25
sta GRP0 ;2 27
lda (draw_s5_addr),y ;5 32
eor #$ff ;2 34
tax ;2 36
txs ;2 38
lax (draw_s3_addr),Y ;5 43
lda (draw_s4_addr),y ;5 48
eor #$ff ;2 50
stx GRP1 ;3 53
tsx ;3 56
sta GRP0 ;3 59
stx GRP1 ;3 62
sta GRP0 ;3 65
dey ;2 67
sbpl _gx_timer_loop ;3 70
ldx temp_timer_stack
txs
gx_overscan
lda #0
sta GRP0
sta GRP1
sta GRP0
sta WSYNC
ldx #32
jsr sub_wsync_loop
jmp newFrame
;
; game states
;
gx_fall
lda #1 ; BUGBUG: magic number (noise voice)
sta AUDC0
lda frame
and #$0f
bne gx_jump
lda draw_player_sprite
clc
adc #8
cmp #<(SYMBOL_GRAPHICS_TUMBLE_1 + 8)
bne _gx_fall_save_spin
lda #<SYMBOL_GRAPHICS_ZARA
_gx_fall_save_spin
sta draw_player_sprite
gx_scroll
gx_jump
; continue from wherever we were
rts
gx_title
; show title
lda audio_sequence
bne _skip_title_audio
lda #SEQ_TITLE
sta audio_sequence
_skip_title_audio
bit player_input_latch
bpl _start_select
jsr sub_galois ; cycle randomization
jmp gx_show_title
_start_select
lda #0
sta audio_tracker ; stop tracker
sta audio_tracker + 1; stop tracker
lda #SEQ_START_SELECT
sta audio_sequence
lda #GAME_STATE_SELECT
sta game_state
lda #1 ; initial difficulty
jmp gx_difficulty_set
gx_select
lda player_input_latch
bpl _gx_select_start
ror
bcs _gx_select_check_down
jmp gx_difficulty_up
_gx_select_check_down
ror
bcs _gx_select_check_left
jmp gx_difficulty_down
_gx_select_check_left
ror
bcs _gx_select_check_right
jmp gx_difficulty_down
_gx_select_check_right
ror
bcs _gx_select_continue
jmp gx_difficulty_up
_gx_select_continue
jsr sub_galois ; cycle randomization
jmp gx_show_select
_gx_select_start
; bootstrap steps
jsr sub_steps_init
lda #GAME_STATE_START
sta game_state
lda #GAME_START_SECONDS
sta player_timer
lda #SEQ_START_GAME
sta audio_sequence
jmp gx_continue
gx_start
lda #<SYMBOL_GRAPHICS_ZARA
sta draw_player_sprite
; countdown to start climb
ldx #-1
jsr gx_player_clock
lda player_timer
beq _start_game
jmp gx_continue
_start_game
lda #GAME_STATE_CLIMB
sta game_state
jmp gx_continue
;
; game control subroutines
;
sub_vblank_loop
ldx #$00
_end_vblank_loop
cpx INTIM
bmi _end_vblank_loop
stx VBLANK
; end
sub_clear_gx
sta WSYNC ; SL 35
lda draw_colubk
sta COLUBK