;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;
; Auto-generated by Regenerator 2000 v0.9.24
; https://github.com/ricardoquesada/regenerator2000
;
; Exported from: c64_frogger_8k.regen2000proj
;
; Assemble with 64tass:
; 64tass -C -o c64_frogger_8k.prg c64_frogger_8k.asm
;
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
; EXTERNAL LABELS
; zpf_ = Zero Page Field
; zpa_ = Zero Page Absolute Address
; f_ = Field
; a_ = Absolute Address
; p_ = Pointer
; L_ = Other / User-defined
CPU_PORT_DDR = $00; x-ref: $8a0e, $94ee, $94f0, $94f3, $94f7
CPU_PORT = $01; x-ref: $8a0a, $8a4c
zp_ptr_src_lo = $02; x-ref: $899f, $89c4, $89e7, $8a58, $8a7b, ...
zp_ptr_src_hi = $03; x-ref: $89a5, $89c8, $89eb, $8a5c, $8a7f, ...
zp_ptr_lane_cfg_lo = $04; x-ref: $8abd, $8b21, $9184, $945d, $946a, ...
zp_ptr_lane_cfg_hi = $05; x-ref: $8ac1, $8b25, $9460, $946e, $94bc, ...
zp_ptr_dst_lo = $06; x-ref: $8964, $89d4, $89dd, $89f7, $8a00, ...
zp_ptr_dst_hi = $07; x-ref: $8968, $89d8, $89e1, $89fb, $8a04, ...
zp_ptr_aux_dst_lo = $08; x-ref: $8ac5, $8b29, $902a, $9064, $906d, ...
zp_ptr_aux_dst_hi = $09; x-ref: $8ac9, $8b2d, $9068, $9071, $907f, ...
zp_tile_strip_len = $0a; x-ref: $89ae, $8ad1, $8af6, $8b13, $8b35, ...
zp_tile_horiz_dir = $0b; x-ref: $8acd, $8b0f, $8b52, $9217, $925a, ...
zp_lane_obj_col = $0c; x-ref: $9189, $9195, $919b, $919f, $91e0, ...
zp_lane_obj_type = $0d; x-ref: $918b, $98bf, $9935, $9d63
zp_lane_obj_size = $0e; x-ref: $9245, $92da, $933a, $98a5, $98b0, ...
zp_scroll_lane_idx = $0f; x-ref: $917c, $91b8, $91c8, $91e5, $92de, ...
zp_fill_run_len = $10; x-ref: $8971, $8b68, $8fd9, $9054
zp_fill_skip_len = $11; x-ref: $896d, $8b6c, $8b81, $8fe3, $9050
zp_block_len_lo = $12; x-ref: $8978, $8982, $89cc, $89ef, $8a60, ...
zp_block_len_hi = $13; x-ref: $89d0, $89f3, $8a64, $909f, $90a4, ...
zp_tile_span_cols = $14; x-ref: $9222, $924f, $9265, $9292, $92c5, ...
zp_ptr_lane_top_lo = $15; x-ref: $91d0, $920b, $9239, $927c, $92ae
zp_ptr_lane_top_hi = $16; x-ref: $91da
zp_ptr_lane_bot_lo = $17; x-ref: $91d4, $920d, $923e, $9281, $92b4
zp_ptr_lane_bot_hi = $18; x-ref: $91de
zp_lane_tile_id = $19; x-ref: $921e, $9237, $9249, $924b, $9261, ...
zp_charset_dest_id = $1b; x-ref: $89b6, $9003, $9060
zp_ptr_top_charset_lo = $1c; x-ref: $898c, $89d2, $89df, $8a10, $8a27, ...
zp_ptr_top_charset_hi = $1d; x-ref: $8990, $89d6, $89e3, $8a14, $8a2b, ...
zp_ptr_bot_charset_lo = $1e; x-ref: $8994, $89f5, $8a02, $8a2d, $8a44, ...
zp_ptr_bot_charset_hi = $1f; x-ref: $8998, $89f9, $8a06, $8a31, $8a48, ...
zp_mirror_src_idx = $20; x-ref: $901e, $9020, $902c, $9533, $953b, ...
zp_mirror_dst_idx = $21; x-ref: $901a, $9028, $9034, $952f, $9547, ...
zp_saved_y = $22; x-ref: $918f, $91c1
zp_saved_x = $23; x-ref: $918d, $91c3, $99eb, $9a07, $9cb6, ...
zp_ptr_sprite_dst_lo = $24; x-ref: $8a50, $8a66, $8a73, $9549, $9577
zp_ptr_sprite_dst_hi = $25; x-ref: $8a54, $8a6a, $8a77
zp_bay_col_cnt = $26; x-ref: $9412, $942d, $9434, $9456
zp_tmp_tile_or_ticks = $27; x-ref: $9326, $932b, $96bf, $96c5, $96cd, ...
zp_preshift_or_col_cnt = $28; x-ref: $8af2, $8af8, $8afe, $8b0b, $8b15, ...
zp_fill_run_cnt = $29; x-ref: $8fc6, $8fcf, $8fd7, $8fdf
zp_fill_skip_cnt = $2a; x-ref: $8fc8, $8fe1, $8fe9, $8fee
zp_tile_loop_cnt = $2b; x-ref: $9229, $9240, $9243, $926c, $9283, ...
zp_unpack_or_shift_cnt = $2c; x-ref: $8ff7, $9024, $902e, $945b, $94b2
zp_scratch_byte = $2d; x-ref: $8add, $8ae9, $8b02, $8b41, $8f5c, ...
zp_raster_split_line = $2e; x-ref: $8bd1, $8be4, $8bf2, $8ede
zp_turtle_dive_phase = $30; x-ref: $92ff, $9309
zp_frog_hop_dir = $31; x-ref: $8e62, $8e6e, $8e7a, $8e86, $8ea2, ...
zp_lane_scroll_delay = $32; x-ref: $9341, $99fc
zp_lane_scroll_step = $3b; x-ref: $9350, $9354, $9356, $93d7, $9a05, ...
zp_unused_44 = $44; x-ref: $95c0
zp_frog_hop_px_cnt = $45; x-ref: $8e9a, $8ea0, $8f19, $8f3f, $8f81, ...
zp_joy_hop_prev = $46; x-ref: $8e48, $8e4f
zp_frog_life_timer = $47; x-ref: $8d78, $8d83, $9642, $96bd, $9855
zp_half_sec_prescaler = $48; x-ref: $8c9f, $8ca8, $960c, $99db
zp_home_bay_idx = $49; x-ref: $8cf4, $8d32, $8d4c, $9117, $915f, ...
zp_frog_row = $4a; x-ref: $8f23, $8f25, $8f49, $8f4d, $8f53, ...
zp_frog_best_row = $4b; x-ref: $8f27, $8f2b, $9648
zp_saved_hop_px_cnt = $4c; x-ref: $93d5, $93fa
zp_home_bay_color = $4d; x-ref: $8cda, $8d12, $8d3a, $911b, $9136, ...
zp_bay_tile_id = $4e; x-ref: $8cd6, $8d0e, $8d36, $9132, $9146, ...
zp_bay_pickup_cnt = $4f; x-ref: $9659, $97ef, $9888, $9958
zp_vehicle_type_idx = $50; x-ref: $91bc, $92cd
zp_frog_drift_px_cnt = $51; x-ref: $93da, $93e8, $93f6
zp_snake_step_px = $52; x-ref: $9a64, $9ace, $9b67
zp_death_spr_frame = $53; x-ref: $8d7e, $8de9, $8dee, $9799, $9924, ...
zp_key_row_prev = $54; x-ref: $8c09, $8c0d
zp_key_col_prev = $55; x-ref: $8c1f, $8c23
zp_ptr_sound_stream_lo = $56; x-ref: $9b8a, $9b93, $9b9d, $9ba4, $9beb, ...
zp_ptr_sound_stream_hi = $57; x-ref: $9b8f, $9c77, $9c79
zp_joy_fire_prev = $58; x-ref: $8c63, $8c67
zp_bay_time_bcd = $59; x-ref: $971d, $9727, $9954
zp_spr_coll_mask = $5a; x-ref: $97e1, $97e7, $9803, $9813, $981d
zp_speed_mode = $5b; x-ref: $8bb4, $8c3a, $8c3c, $9743, $99e3
zp_hazard_rng_consumed = $5c; x-ref: $9ca3, $9ca7
zp_hazard_rng_sample = $5d; x-ref: $99dd, $9c9a, $9ca1
zp_two_player_flag = $5e; x-ref: $8bb6, $8c46, $8c4a, $8d5e, $8e1e, ...
zp_joy_port_offset = $5f; x-ref: $8c5b, $8e2e, $8e43, $95b6
zp_wrapped_span_left = $60; x-ref: $98f4, $9913, $9917, $992a
zp_wrapped_span_right = $61; x-ref: $9904, $9911, $991b, $992e
zp_span_raw_left = $62; x-ref: $98d2, $98dc, $98e9
zp_span_raw_right = $63; x-ref: $98cd, $98e0, $98f9
zp_lane_cfg_idx = $64; x-ref: $917e, $98a0, $9d5b
zp_log_span_width = $65; x-ref: $98b6, $98de
zp_turtle_span_width = $66; x-ref: $98ae, $98d0
zp_ptr_spr_x_lo = $67; x-ref: $939e, $93b1, $9ad2, $9ae9, $9b55, ...
zp_ptr_spr_x_hi = $68; x-ref: $93a2, $93b5, $9ad6, $9b59
zp_ptr_spr_x_msb_lo = $69; x-ref: $9392, $9ada, $9aed, $9b5d, $9cc1, ...
zp_ptr_spr_x_msb_hi = $6a; x-ref: $9396, $9ade, $9b61
zp_spr_x_msb_mask = $6b; x-ref: $93a6, $93b9, $9ae2, $9b65, $9cc7, ...
zp_spr_x_step_dir = $6c; x-ref: $9b6d, $9cb4, $9cbd
zp_spr_x_step_cnt = $6d; x-ref: $9b69, $9caf, $9ce1
zp_sound_active = $6e; x-ref: $8c73, $8c80, $9b75, $9b7f, $9bba, ...
zp_sound_stream_id = $6f; x-ref: $8c84, $9b7b, $9b83, $9bb0
zp_sound_tempo_period = $70; x-ref: $9b97, $9c15
zp_sound_voice_cnt = $71; x-ref: $9ba6, $9c53, $9c57
zp_sound_tempo_cnt = $72; x-ref: $9b99, $9b9b, $9c11, $9c13, $9c1b
zp_sound_voice_init_flag = $73; x-ref: $9b81, $9bc9, $9c0e
zp_sound_preempt_mute = $74; x-ref: $9bb6, $9bbe, $9bc4
zp_req_sound_stream_id = $75; x-ref: $9b73, $9b79, $9bae
zp_sound_freq_mode = $76; x-ref: $9ba1, $9c2c
zp_screen_wipe_state = $77; x-ref: $8c7c, $8e37, $8ee9, $9112, $9179, ...
zp_lane_fine_phase = $78; x-ref: $9219, $925c, $92d2, $9301, $9385
zp_frog_hop_active = $79; x-ref: $8cea, $8e3f, $8e8f, $8e96, $93c9, ...
zp_score_delta_bcd_lo = $7a; x-ref: $8f2f, $976b, $9779, $985a
zp_score_delta_bcd_hi = $7b; x-ref: $977b, $9876
zp_frog_state_timer = $7d; x-ref: $8ba4, $8d5a, $8d70, $8dcc, $8df0, ...
zp_pause_flag = $7e; x-ref: $8c6d, $8c71, $8c98, $8ee5
zp_bay_timer_banner_cnt = $7f; x-ref: $8d9a, $8da1, $970c, $985e
zp_home_bay_cursor = $80; x-ref: $9c7c, $9c92, $9c95
zp_active_player = $81; x-ref: $8c51, $8d62, $8d66, $8df8, $8e2a, ...
zp_player_game_over = $82; x-ref: $8e00, $8e0a, $8e0e, $8e26, $95bc
zp_frog_died_flag = $84; x-ref: $8df4, $9657, $99ce
zp_round_clear_freeze = $85; x-ref: $8d72, $8dc4, $90f4, $9874
zp_bay_bonus_freeze = $86; x-ref: $8d74, $8d9c, $8dc8, $9860
zp_score_bcd_lo = $87; x-ref: $9692, $969d, $9769, $976d, $9d34, ...
zp_score_bcd_hi = $88; x-ref: $977d
zp_extra_life_bcd_digit = $8a; x-ref: $9781, $9785
zp_lane_coarse_col = $8b; x-ref: $91e7, $936a, $9376, $9381, $98e2
zp_lane_fine_scroll = $94; x-ref: $934e, $9359, $935b, $9363, $9383, ...
zp_lane_turtle_phase_ofs = $9d; x-ref: $92f1, $95a9
zp_lane_turtle_dive_phase = $a2; x-ref: $92fd, $9941
zp_home_bay_state = $a7; x-ref: $8ce5, $8cfb, $8d1f, $8d2e, $8d41, ...
zp_level_layout_idx = $ac; x-ref: $8ba8, $90b2, $90bb, $961f, $9d4c
zp_round_speed_tier = $ad; x-ref: $90bd, $90c6, $99e1
zp_bay_gator_phase = $ae; x-ref: $8d01, $8d1d, $8d28, $8d58
zp_round_bcd = $af; x-ref: $90c8, $90ce, $9621, $9638, $96f7, ...
zp_snake_unlocked = $b0; x-ref: $90e6, $9b1f
zp_turtle_anim_phase = $b1; x-ref: $8caa, $8cac, $8cb4, $92f4
zp_bays_remaining = $b2; x-ref: $90f0, $9634, $9865
zp_player_lives = $b3; x-ref: $8dfa, $95c8, $96af, $9787, $9790, ...
zp_bay_fly_idx = $b4; x-ref: $8cc9, $8cd2, $8cf2, $8cff, $9886
zp_bay_fly_timer = $b5; x-ref: $8ce1, $8cee
zp_lady_frog_spawned = $b6; x-ref: $8da3, $8dc2, $9653
zp_bay_gator_timer = $b7; x-ref: $8d19, $8d24, $8d45
zp_bay_gator_bay_idx = $b8; x-ref: $8d0a, $8d2c, $8d4a
zp_snake_left_x_lo = $b9; x-ref: $9a18, $9a33, $9a41, $9a75, $9b03
zp_snake_left_x_msb = $ba; x-ref: $9a1c, $9a37, $9a4b, $9a6e, $9b07
zp_snake_right_x_lo = $bb; x-ref: $9a20, $9a3b, $9a99, $9b0b
zp_snake_right_x_msb = $bc; x-ref: $9a24, $9a3f, $9a92, $9b0f
zp_snake_log_left_x_lo = $bd; x-ref: $95db, $9a16, $9ad0, $9ad4, $9b01
zp_snake_log_left_x_msb = $be; x-ref: $95df, $9a1a, $9ad8, $9adc, $9b05
zp_snake_log_right_x_lo = $bf; x-ref: $95e3, $9a1e, $9ae7, $9b09
zp_snake_log_right_x_msb = $c0; x-ref: $95e7, $9a22, $9aeb, $9b0d
zp_snake_dir = $c1; x-ref: $9a52, $9a7b, $9a7d, $9aa5, $9af9, ...
zp_snake_anim_timer = $c2; x-ref: $9610, $9a9d, $9aa3
zp_player_state_backup = $c3; x-ref: $9d3d, $9d45
backup_vic_sprite_regs = $0100; x-ref: $9d1c, $9d24
KERNAL_CINV_LO = $0314; IRQ ; x-ref: $8bba
KERNAL_CINV_HI = $0315; IRQ ; x-ref: $8bbf
KERNAL_NMINV_LO = $0318; NMI ; x-ref: $8908
KERNAL_NMINV_HI = $0319; NMI ; x-ref: $890d
SCREEN_RAM = $4400; x-ref: $8b9a, $9422, $9427, $9449, $9450, ...
SCREEN_RAM_ROW00_COL38 = $4426; x-ref: $8b5e, $8b62
SCREEN_RAM_ROW03_COL00 = $4478; x-ref: $8009, $9102, $910a
SCREEN_RAM_ROW05_COL00 = $44c8; x-ref: $800b
SCREEN_RAM_ROW07_COL00 = $4518; x-ref: $800d
SCREEN_RAM_ROW09_COL00 = $4568; x-ref: $800f
SCREEN_RAM_ROW11_COL00 = $45b8; x-ref: $8011
SCREEN_RAM_ROW13_COL00 = $4608; x-ref: $8b77, $8b7b
SCREEN_RAM_ROW15_COL00 = $4658; x-ref: $8013, $9169, $9171
SCREEN_RAM_ROW17_COL00 = $46a8; x-ref: $8015
SCREEN_RAM_ROW19_COL00 = $46f8; x-ref: $8017
SCREEN_RAM_ROW21_COL00 = $4748; x-ref: $8019
SCREEN_RAM_ROW23_COL00 = $4798; x-ref: $8b88, $8b8c
SCREEN_RAM_ROW24_COL00 = $47c0; x-ref: $898a, $898e, $8abb, $8abf
SCREEN_RAM_ROW24_COL01 = $47c1; x-ref: $974c, $975a
SCREEN_RAM_ROW24_COL16 = $47d0; x-ref: $9715, $9724, $9730, $973b
SCREEN_RAM_ROW24_COL34 = $47e2; x-ref: $96ee, $96fd, $9709
SCREEN_RAM_SPR0_PTR = $47f8; x-ref: $8de3, $8deb, $8e66, $8e72, $8e7e, ...
SCREEN_RAM_SPR1_PTR = $47f9; x-ref: $9602
SCREEN_RAM_SPR2_PTR = $47fa; x-ref: $8cbf, $8cc6, $9607, $9809
SCREEN_RAM_SPR3_PTR = $47fb; x-ref: $9a56, $9a83, $9a89, $9aab, $9ab2, ...
SCREEN_RAM_SPR4_PTR = $47fc; x-ref: $9823
ROAD_CHARSET_RAM = $5000; x-ref: $8992, $8996, $8b1f, $8b23
SPRITE_DATA_RAM = $5800; x-ref: $8a4e, $8a52
COLOR_RAM = $d800; x-ref: $8962, $8966, $941a, $941d, $9441, ...
; ENUMS
; Enum: CharsetDescTarget
CharsetDescTarget .block
CHARSET_DEST_ROAD = $00
CHARSET_DEST_RIVER = $01
CHARSET_DESC_END = $02
.bend
; Enum: FrogHopDir
FrogHopDir .block
HOP_DIR_UP = $01
HOP_DIR_DOWN = $02
HOP_DIR_LEFT = $04
HOP_DIR_RIGHT = $08
.bend
; Enum: HomeBayState
HomeBayState .block
HOME_BAY_EMPTY = $00
HOME_BAY_BONUS_FLY = $01
HOME_BAY_GATOR_EMERGING = $02
HOME_BAY_GATOR_OPEN_JAWS = $fe
HOME_BAY_FROG_CLAIMED = $ff
.bend
; Enum: LaneObjType
LaneObjType .block
LANE_OBJ_LOG_OR_GATOR = $01
LANE_OBJ_TURTLES = $02
LANE_OBJ_VEHICLE = $03
.bend
; Enum: RasterSplitLine
RasterSplitLine .block
RASTER_SPLIT_MEDIAN = $a1
RASTER_SPLIT_BOTTOM = $fc
.bend
; Enum: ScreenWipeState
ScreenWipeState .block
SCREEN_WIPE_NEXT_ROUND = $00
SCREEN_WIPE_DONE = $01
SCREEN_WIPE_BAYS_ROAD = $fe
SCREEN_WIPE_FULL = $ff
.bend
; Enum: SoundStreamId
SoundStreamId .block
SFX_FROG_HOP = $00
SFX_LADY_FROG = $01
SFX_HOME_BAY = $02
SFX_DROWN_DEATH = $03
SFX_SQUASH_DEATH = $04
SFX_LOW_TIME_ALERT = $05
MELODY_GAME_OVER = $06
MELODY_ROUND_CLEAR = $07
MELODY_MAIN_THEME = $08
.bend
; Enum: SpriteCollisionMask
SpriteCollisionMask .block
SPR0_FROG = $01
SPR1_LADY_FROG = $02
SPR2_RIVER_GATOR = $04
SPR3_SNAKE = $08
SPR4_HAZARD_SLOT = $10
.bend
; Enum: TileHorizDir
TileHorizDir .block
TILE_DIR_LEFT = $00
TILE_DIR_RIGHT = $01
.bend
; C64 8K Cartridge CBM80 Header ($8000-$8008)
$8000cart_cold_start_vec.wordcart_cold_warm_start; Cold start vector -> $8906
$8002cart_warm_start_vec.wordcart_cold_warm_start; Warm start / RESTORE NMI vector -> $8906
.encode
.enc"none"
$8004cart_cbm80_sig.text$c3, $c2, $cd, "80"; PETSCII autostart signature "CBM80" ($C3,$C2,$CD,$38,$30)
.endencode
; Screen RAM ($4400) top-row pointers for the 9 scrolling lanes (5 river rows 3..11, 4 road rows 15..21)
lane_screen_row_ptr_tbl
$8009.wordSCREEN_RAM_ROW03_COL00, SCREEN_RAM_ROW05_COL00, SCREEN_RAM_ROW07_COL00, SCREEN_RAM_ROW09_COL00, SCREEN_RAM_ROW11_COL00; River lanes 0..4 top rows ($4478..$45B8, rows 3/5/7/9/11) ; x-ref: $91cc, $91d7
$8013.wordSCREEN_RAM_ROW15_COL00, SCREEN_RAM_ROW17_COL00, SCREEN_RAM_ROW19_COL00, SCREEN_RAM_ROW21_COL00; Road lanes 5..8 top rows ($4658..$4748, rows 15/17/19/21)
; Zero-terminated (byte_count, color_nybble) RLE table initializing all 1000 Color RAM bytes ($D800-$DBE7)
color_ram_rle_init_tbl
$801B.byte$20, $01, $08, $02, $50, $0d, $50, $0f; x-ref: $8973, $897b
$8023.byte$50, $0d, $a0, $0f, $50, $0d, $50, $0a
$802B.byte$50, $09, $50, $0c, $50, $0f, $50, $0a
$8033.byte$50, $05, $00
; Pointers to the 5 per-level lane object configuration tables ($812E-$8295, 9 lanes * 8 bytes = 72 bytes each)
level_lane_cfg_ptr_tbl
$8036.wordlevel1_lane_cfg_tbl, level2_lane_cfg_tbl, level3_lane_cfg_tbl, level4_lane_cfg_tbl, level5_lane_cfg_tbl; x-ref: $9d50, $9d56
; 3-byte mirrored-tile unpack descriptors: .word src_gfx, .byte (half_tiles<<4)|dest_charset_id; mode $02 ends table
charset_mirror_desc_tbl
$8040.wordtile_gfx_river_set1; x-ref: $899c, $89a2, $89a8, $89b0
$8042.byte$31
$8043.wordtile_gfx_river_set0
$8045.byte$31
$8046.wordtile_gfx_river_set2
$8048.byte$31
$8049.wordtile_gfx_river_set3
$804B.byte$31
$804C.wordtile_gfx_river_set4
$804E.byte$51
$804F.wordtile_gfx_road_set0
$8051.byte$80
$8052.wordtile_gfx_road_set2
$8054.byte$40
$8055.wordtile_gfx_road_set1
$8057.byte$40
$8058.wordtile_gfx_road_set3
$805A.byte$40
charset_mirror_desc_end
$805B.byte$00, $00, $02; End-of-table sentinel (mode = $02)
; Top HUD custom font tile template (32 cols -> $4400): " 1 UP 00000 FROGS 4 TIME "
$805Estr_hud_top_row.byte$5d, $5d, $5d, $5d, $5f, $5d, $53, $68; x-ref: $8b97
$8066.byte$5d, $5e, $5e, $5e, $5e, $5e, $5d, $5d
$806E.byte$5d, $55, $5a, $59, $56, $5b, $5d, $63
$8076.byte$5d, $5d, $5d, $5c, $57, $58, $54, $5d
; Bottom status custom tile string (4 chars -> $47C1): "FAST"
$807Estr_status_fast.byte$34, $33, $37, $38; x-ref: $9757
; Bottom status custom tile string (4 chars -> $47C1): "SLOW"
$8082str_status_slow.byte$37, $35, $36, $39; x-ref: $9749
; Bottom status custom tile string (5 chars -> $47D0): "TIMER"
$8086str_status_timer.byte$38, $3a, $3b, $3c, $3d; x-ref: $9712
; Bottom status custom tile prefix (2 chars -> $47E2): "R="
str_status_round_prefix
$808B.byte$3d, $3e; x-ref: $96eb
; Bottom status 8 inverse spaces ($31 -> $47D0) clearing "TIMER XX" field
$808Dstr_status_blank8.fill8, $31; x-ref: $9738
; C64 Character ROM ($D000) screencode indices (22 glyphs: "UEFGIMORST 0123456789P") copied to top charset
hud_char_rom_glyph_tbl
$8095.byte$15, $05, $06, $07, $09, $0d, $0f, $12; x-ref: $8a1a
$809D.byte$13, $14, $20, $30, $31, $32, $33, $34
$80A5.byte$35, $36, $37, $38, $39, $10
; C64 Character ROM ($D400) reverse-video screencode indices (22 glyphs: "AFLOSTWIMER=0123456789") copied to bottom charset
status_rev_rom_glyph_tbl
$80AB.byte$81, $86, $8c, $8f, $93, $94, $97, $89; x-ref: $8a37
$80B3.byte$8d, $85, $92, $bd, $b0, $b1, $b2, $b3
$80BB.byte$b4, $b5, $b6, $b7, $b8, $b9
; Pre-shifted base tile IDs (4 horizontal scroll phases) for swimming river turtles
tile_base_turtle_swim
$80C1.byte$00, $79, $69, $71; x-ref: $9323
; Pre-shifted base tile IDs (4 horizontal scroll phases) for river logs
$80C5tile_base_log.byte$18, $e5, $cb, $b1; x-ref: $921b
; Pre-shifted base tile IDs (4 horizontal scroll phases) for diving turtles (stage 1)
tile_base_turtle_dive1
$80C9.byte$08, $a1, $91, $81; x-ref: $9317
; Pre-shifted base tile IDs (4 horizontal scroll phases) for diving turtles (stage 2)
tile_base_turtle_dive2
$80CD.byte$10, $a9, $99, $89; x-ref: $931d
; Pre-shifted base tile IDs (4 horizontal scroll phases) for river alligators
$80D1tile_base_alligator.byte$24, $f1, $d7, $bd; x-ref: $925e
; Pre-shifted base tile IDs (4 vehicle types * 4 scroll phases = 16 bytes) for road traffic
tile_base_road_vehicles
$80D5.byte$00, $81, $65, $49, $1c, $c5, $b1, $9d; x-ref: $92d5
$80DD.byte$12, $93, $77, $5b, $26, $cf, $bb, $a7
; Lane speed profiles (6 profiles [3 FAST + 3 SLOW] * 9 lanes = 54 bytes): (pixel_step<<4) | frame_delay
lane_speed_profile_tbl
$80E5.byte$11, $21, $21, $12, $11, $21, $21, $11; x-ref: $99f7, $99fe
$80ED.byte$11, $21, $11, $12, $21, $11, $21, $41
$80F5.byte$11, $21, $21, $11, $11, $12, $11, $41
$80FD.byte$41, $11, $11, $12, $11, $11, $12, $12
$8105.byte$21, $11, $11, $11, $11, $12, $12, $11
$810D.byte$11, $11, $21, $11, $11, $11, $12, $11
$8115.byte$12, $12, $21, $21, $11, $12
; Horizontal scroll direction per lane (9 lanes: 1 = right, 0 = left)
$811Blane_scroll_dir_tbl.byte$01, $00, $01, $01, $00, $01, $00, $01; x-ref: $91eb, $92e0, $9365, $93dc, $9cb1
$8123.byte$00
; Home bay frog landing X-coordinate [min_x, max_x_excl] pairs for bays 0..4 (bay 4 uses $D010 X-MSB = 1)
home_bay_x_bounds_tbl
$8124.byte$2a, $38, $6a, $78, $aa, $b8, $ea, $f8; x-ref: $9995, $999b
$812C.byte$2a, $38
; Level 1 lane object layout table (9 lanes * 8 bytes = 72 bytes)
$812Elevel1_lane_cfg_tbl.byte$01, $07, $02, $11, $20, $00, $00, $00; x-ref: $8036
$8136.byte$02, $02, $0b, $1a, $a9, $00, $00, $00
$813E.byte$01, $0d, $01, $1a, $00, $00, $00, $00
$8146.byte$01, $05, $02, $14, $26, $00, $00, $00
$814E.byte$02, $03, $10, $a0, $30, $00, $00, $00
$8156.byte$03, $09, $19, $00, $00, $00, $00, $00
$815E.byte$03, $05, $0b, $1f, $00, $00, $00, $00
$8166.byte$03, $05, $0e, $18, $22, $2c, $00, $00
$816E.byte$03, $05, $0f, $19, $23, $2d, $00, $00
; Level 2 lane object layout table (9 lanes * 8 bytes = 72 bytes)
$8176level2_lane_cfg_tbl.byte$01, $07, $82, $11, $20, $00, $00, $00; x-ref: $8038
$817E.byte$02, $02, $0b, $15, $9f, $00, $00, $00
$8186.byte$01, $0d, $1a, $00, $00, $00, $00, $00
$818E.byte$01, $05, $02, $14, $26, $00, $00, $00
$8196.byte$02, $03, $10, $a0, $00, $00, $00, $00
$819E.byte$03, $09, $0f, $1e, $00, $00, $00, $00
$81A6.byte$03, $05, $0b, $1f, $00, $00, $00, $00
$81AE.byte$03, $05, $0e, $18, $22, $2c, $00, $00
$81B6.byte$03, $05, $0f, $19, $23, $2d, $00, $00
; Level 3 lane object layout table (9 lanes * 8 bytes = 72 bytes)
$81BElevel3_lane_cfg_tbl.byte$01, $07, $82, $11, $00, $00, $00, $00; x-ref: $803a
$81C6.byte$02, $02, $0b, $15, $9f, $00, $00, $00
$81CE.byte$01, $0d, $1a, $00, $00, $00, $00, $00
$81D6.byte$01, $05, $02, $14, $26, $00, $00, $00
$81DE.byte$02, $03, $10, $a0, $00, $00, $00, $00
$81E6.byte$03, $09, $0f, $1e, $00, $00, $00, $00
$81EE.byte$03, $05, $0b, $1f, $00, $00, $00, $00
$81F6.byte$03, $05, $04, $0e, $18, $22, $2c, $00
$81FE.byte$03, $05, $0f, $19, $23, $2d, $00, $00
; Level 4 lane object layout table (9 lanes * 8 bytes = 72 bytes)
$8206level4_lane_cfg_tbl.byte$01, $07, $82, $11, $00, $00, $00, $00; x-ref: $803c
$820E.byte$02, $02, $0b, $9f, $00, $00, $00, $00
$8216.byte$01, $0d, $1a, $00, $00, $00, $00, $00
$821E.byte$01, $05, $02, $14, $00, $00, $00, $00
$8226.byte$02, $03, $10, $a0, $00, $00, $00, $00
$822E.byte$03, $09, $01, $10, $1f, $00, $00, $00
$8236.byte$03, $05, $0b, $15, $1f, $00, $00, $00
$823E.byte$03, $05, $0e, $18, $22, $2c, $00, $00
$8246.byte$03, $05, $0f, $19, $23, $2d, $00, $00
; Level 5+ lane object layout table (9 lanes * 8 bytes = 72 bytes)
$824Elevel5_lane_cfg_tbl.byte$01, $07, $82, $00, $00, $00, $00, $00; x-ref: $803e
$8256.byte$02, $02, $0b, $1a, $a9, $00, $00, $00
$825E.byte$01, $0d, $1a, $00, $00, $00, $00, $00
$8266.byte$01, $05, $02, $14, $00, $00, $00, $00
$826E.byte$02, $03, $10, $a0, $00, $00, $00, $00
$8276.byte$03, $09, $0f, $1e, $00, $00, $00, $00
$827E.byte$03, $05, $0b, $15, $1f, $00, $00, $00
$8286.byte$03, $05, $04, $0e, $18, $22, $2c, $00
$828E.byte$03, $05, $05, $0f, $19, $23, $2d, $00
; Mirrored multicolor river tile source graphics (9 groups, $8296-$831D) and road vehicle source graphics ($831E-$83BD)
$8296tile_gfx_river_set0.byte$55, $95, $a5, $65, $e5, $f5, $fd, $fd; x-ref: $8043
$829E.byte$55, $56, $55, $bf, $ff, $ff, $ff, $ff
$82A6.byte$55, $59, $69, $56, $56, $57, $a7, $aa
$82AEtile_gfx_river_set1.byte$55, $56, $5a, $65, $e5, $f5, $fd, $fd; x-ref: $8040
$82B6.byte$55, $69, $65, $bf, $ff, $ff, $ff, $ff
$82BE.byte$55, $55, $55, $55, $55, $57, $a7, $aa
$82C6tile_gfx_river_set2.byte$55, $55, $55, $55, $55, $d5, $f5, $f5; x-ref: $8046
$82CE.byte$55, $55, $55, $7d, $7d, $ff, $ff, $ff
$82D6.fill8, $55
$82DEtile_gfx_river_set3.byte$55, $55, $55, $55, $55, $55, $51, $55; x-ref: $8049
$82E6.byte$55, $41, $55, $55, $41
$82EB.fill9, $55
$82F4.byte$45, $55
$82F6tile_gfx_river_set4.byte$55, $56, $5a, $5a, $6a, $6a, $6f, $6a; x-ref: $804c
$82FE.byte$55, $a6, $ea, $ea, $ba, $aa, $af, $aa
$8306.byte$55, $a6, $ea, $ea, $ba, $aa, $af, $aa
$830E.byte$55, $9a, $aa, $aa, $fb, $ab, $af, $ab
$8316.byte$55, $b5, $fd, $fd, $ef, $ab, $ab, $bb
$831Etile_gfx_road_set0.byte$00, $00, $0a, $0a, $ff, $ff, $ff, $ff; x-ref: $804f
$8326.byte$00, $00, $a0, $a0, $ff, $ff, $ff, $ff
$832E.byte$00, $00, $00, $00, $ff, $ff, $ff, $ff
$8336.byte$00, $00, $00, $00, $ff, $ff, $ff, $ff
$833E.byte$00, $00, $02, $02, $ff, $ff, $ff, $ff
$8346.byte$00, $00, $a8, $a8, $ff, $ff, $ff, $ff
$834E.byte$00, $00, $02, $0f, $cf, $cf, $df, $df
$8356.byte$00, $00, $80, $f0, $f4, $f4, $f4, $f4
$835Etile_gfx_road_set1.byte$00, $aa, $aa, $aa, $28, $fc, $5f, $ef; x-ref: $8055
$8366.byte$00, $00, $00, $00, $00, $ff, $fd, $fe
$836E.byte$00, $00, $aa, $aa, $a8, $ff, $f7, $df
$8376.byte$00, $00, $02, $02, $00, $0f, $3f, $ff
$837Etile_gfx_road_set2.byte$00, $0b, $0b, $03, $03, $0f, $3f, $3f; x-ref: $8052
$8386.byte$00, $bb, $bb, $cf, $cf, $ff, $f7, $f5
$838E.byte$00, $80, $80, $00, $01, $fd, $fc, $7c
$8396.byte$00, $3c, $30, $7c, $70, $3c, $30, $3c
$839Etile_gfx_road_set3.byte$00, $00, $80, $80, $f0, $f0, $74, $70; x-ref: $8058
$83A6.byte$00, $00, $0a, $0a, $7f, $ff, $f5, $f5
$83AE.byte$00, $00, $80, $80, $fd, $ff, $df, $df
$83B6.byte$00, $00, $02, $02, $07, $1f, $1f, $1f
; Direct character set glyph bitmaps for top charset ($83BE-$8535 = 47 chars * 8 bytes; home bays, frogs, alligator, median, timer bars)
charset_top_direct_gfx
$83BE.fill8, $55; x-ref: $89c2, $89c6
$83C6.byte$59, $6e, $aa
$83C9.fill11, $55
$83D4.byte$59, $5a, $6a, $ab, $aa, $56, $56, $5a
$83DC.byte$55, $55, $55, $55, $55, $55, $59, $6a
$83E4.byte$aa, $ab, $aa, $ba, $aa, $95, $95, $55
$83EC.byte$55, $55, $55, $55, $55, $55, $59, $6a
$83F4.byte$aa, $ab, $aa, $ba, $aa
$83F9.fill10, $55
$8403.byte$56, $aa, $fa, $aa, $af, $aa, $5a, $5a
$840B.byte$69, $55, $55, $55, $55, $55, $65, $a9
$8413.byte$ba, $ba, $aa, $aa, $ab, $aa, $95
$841A.fill20, $55
$842E.byte$00, $fc, $fc, $fc, $00, $cf, $cf, $cf
$8436.byte$ff, $ef, $ff, $bf, $fe, $ff, $ff, $ef
$843E.byte$ff, $ef, $fc, $b0, $f0, $c0, $00, $00
$8446.byte$ff, $c3, $00, $00, $00, $00, $00, $00
$844E.byte$ff, $fb, $3f, $0e, $0f, $03, $00, $00
$8456.byte$ff, $cf, $fc, $31, $f7, $c6, $07, $03
$845E.byte$7b, $79, $7d, $7f, $3f, $3d, $1f, $0f
$8466.byte$ff, $c3, $00, $81, $e7, $66, $ff, $ff
$846E.byte$bd, $c3, $ff, $ff, $ff, $c3, $c3, $c3
$8476.byte$ff, $f3, $3f, $8c, $ef, $63, $e0, $c0
$847E.byte$de, $9e, $be, $fe, $fc, $bc, $f8, $f0
$8486.byte$ff, $ef, $fc, $b0, $f0, $c0, $01, $09
$848E.byte$1a, $2a, $1a, $09, $00, $00, $00, $00
$8496.byte$ff, $c3, $00, $05, $15, $55, $55, $5a
$849E.byte$aa, $aa, $5a, $55, $55, $15, $05, $00
$84A6.byte$ff, $fb, $3f, $4f, $4f, $43, $00, $00
$84AE.byte$80, $80, $00, $00, $40, $40, $40, $00
$84B6.byte$ff, $ef, $fc, $b0, $f0, $c0, $00, $00
$84BE.byte$00, $80, $aa, $aa, $55, $aa, $00, $00
$84C6.byte$ff, $c3, $00, $00, $00, $00, $00, $00
$84CE.byte$08, $26, $aa, $aa, $55, $aa, $0a, $00
$84D6.byte$ff, $fb, $3f, $0f, $0f, $03
$84DC.fill10, $00
$84E6.byte$ff, $ef, $fc, $b0, $f0, $c0, $20, $a8
$84EE.byte$9a, $9a, $aa, $aa, $a9, $aa, $80, $00
$84F6.byte$ff, $c3, $00, $00, $00, $00, $00, $00
$84FE.byte$02, $aa, $a8, $84, $51, $aa, $00, $00
$8506.byte$ff, $fb, $3f, $0f, $0f, $0b, $2a, $a6
$850E.byte$aa, $44, $00, $00, $11, $aa, $0a, $00
$8516.fill8, $ff
$851E.fill8, $fc
$8526.fill8, $f0
; Shared/extra 3 character cells ($852E-$8545 = 24 bytes) copied to bottom charset ($852E-$8535 shared with top charset)
charset_bottom_shared_gfx
$852E.fill8, $c0; x-ref: $89e5, $89e9
$8536.fill8, $ff
$853E.byte$00, $fc, $fc, $fc, $00, $cf, $cf, $cf
; Hardware sprite sheet ($8546-$8905 = 15 sprites * 64 bytes -> $5800-$5BBF, VIC pointers $60-$6E); Sprite $60: Frog idle facing up / Lady Frog (v-flipped at runtime for down)
$8546spr_frog_idle_up.fill13, $00; x-ref: $8a56, $8a5a, $8a79, $8a7d
$8553.byte$3c, $00, $07, $7e, $e0, $03, $7e, $c0
$855B.byte$01, $ff, $80, $00, $7e, $00, $00, $7e
$8563.byte$00, $0d, $ff, $b0, $1f, $ff, $f8, $0f
$856B.byte$ff, $f0, $07, $ff, $e0, $03, $ff, $c0
$8573.byte$00, $e7
$8575.fill17, $00
; Sprite $61 (64 bytes): Frog idle facing right (180-deg flipped at runtime for left)
$8586spr_frog_idle_right.fill16, $00; x-ref: $8a84, $8a88
$8596.byte$78, $00, $01, $f8, $c0, $03, $e3, $c0
$859E.byte$07, $f7, $00, $07, $ff, $e0, $03, $ff
$85A6.byte$f0, $03, $ff, $f0, $07, $ff, $e0, $07
$85AE.byte$f7, $00, $03, $e3, $c0, $01, $f8, $c0
$85B6.byte$00, $78
$85B8.fill14, $00
; Sprite $62 (64 bytes): Frog jumping up (v-flipped at runtime for down)
$85C6spr_frog_jump_up.byte$00, $00, $00, $00, $00, $00, $03, $81; x-ref: $8a8f, $8a93
$85CE.byte$c0, $03, $00, $c0, $07, $3c, $e0, $07
$85D6.byte$7e, $e0, $07, $7e, $e0, $03, $ff, $c0
$85DE.byte$00, $ff, $00, $00, $7e, $00, $00, $7e
$85E6.byte$00, $00, $7e, $00, $00, $ff, $00, $00
$85EE.byte$ff, $00, $00, $ff, $00, $00, $e7, $00
$85F6.byte$00, $e7, $00, $00, $c3, $00, $00, $c3
$85FE.byte$00, $00, $c3, $00, $01, $81, $80, $00
; Sprite $63 (64 bytes): Frog jumping right (180-deg flipped at runtime for left)
$8606spr_frog_jump_right.fill23, $00; x-ref: $8a9a, $8a9e
$861D.byte$fe, $cf, $e1, $c3, $79, $ff, $f0, $03
$8625.byte$ff, $f8, $03, $ff, $f8, $79, $ff, $f0
$862D.byte$cf, $e1, $c3, $00, $00, $fe
$8633.fill19, $00
; Sprite $64 (64 bytes): Frog skull-and-crossbones death frame
spr_frog_death_skull
$8646.byte$00, $7e, $00, $01, $ff, $80, $03, $ff
$864E.byte$c0, $03, $ff, $c0, $07, $ff, $e0, $07
$8656.byte$ff, $e0, $07, $ff, $e0, $07, $18, $e0
$865E.byte$03, $3c, $c0, $01, $e7, $80, $00, $f7
$8666.byte$00, $00, $ff, $00, $18, $db, $18, $3c
$866E.byte$6c, $3c, $3e, $00, $7c, $03, $c3, $c0
$8676.byte$00, $7e, $00, $03, $c3, $c0, $3e, $00
$867E.byte$7c, $3c, $00, $3c, $18, $00, $18, $00
; Sprite $65 (64 bytes): "200" bonus score popup
$8686spr_bonus_200.fill15, $00
$8695.byte$1e, $1c, $1c, $33, $36, $36, $63, $63
$869D.byte$63, $03, $63, $63, $06, $63, $63, $0c
$86A5.byte$63, $63, $18, $63, $63, $30, $36, $36
$86AD.byte$7f, $1c, $1c
$86B0.fill22, $00
; Sprite $66 (64 bytes): "400" bonus score popup
$86C6spr_bonus_400.fill15, $00
$86D5.byte$cc, $1c, $1c, $cc, $36, $36, $cc, $63
$86DD.byte$63, $cc, $63, $63, $ff, $63, $63, $0c
$86E5.byte$63, $63, $0c, $63, $63, $0c, $36, $36
$86ED.byte$0c, $1c, $1c
$86F0.fill22, $00
; Sprite $67 (64 bytes, multicolor): Home-bay alligator (jaws open)
spr_bay_alligator_open
$8706.byte$00, $08, $00, $00, $2a, $00, $00, $22
$870E.byte$00, $00, $a8, $00, $02, $8c, $00, $0a
$8716.byte$c0, $00, $a8, $00, $00, $ac, $00, $00
$871E.byte$80, $00, $00, $33, $33, $00, $aa, $aa
$8726.byte$00, $00, $0a
$8729.fill29, $00
; Sprite $68 (64 bytes, multicolor): Home-bay alligator (jaws closed)
spr_bay_alligator_closed
$8746.fill16, $00
$8756.byte$08, $00, $80, $2a, $00, $aa, $ae, $00
$875E.byte$aa, $aa, $00, $ff, $ff, $00, $aa, $aa
$8766.byte$00, $00, $0a
$8769.fill29, $00
; Sprite $69 (64 bytes, X-expanded): Snake slithering left frame 1 (flipped at runtime to $73 for right)
$8786spr_snake_left_1.fill20, $00; x-ref: $8aa5, $8aa9
$879A.byte$30, $00, $18, $5c, $00, $3c, $fc, $00
$87A2.byte$7e, $e0, $00, $ff, $fc, $01, $cf, $f8
$87AA.byte$07, $87, $c0, $0f, $03, $80
$87B0.fill22, $00
; Sprite $6A (64 bytes $87C6-$8805, crosses $87FF/$8800 boundary): Snake slithering left frame 2 (flipped at runtime to $74 for right)
$87C6spr_snake_left_2.fill20, $00; x-ref: $8ab0, $8ab4
$87DA.byte$18, $00, $00, $2e, $00, $f0, $7e, $03
$87E2.byte$fe, $70, $0f, $ff, $fe, $1f, $3f, $fc
$87EA.byte$3c, $0f, $c0, $f0, $03, $80
$87F0.fill16, $00
$8800.byte$00, $00, $00, $00, $00, $00; Trailing 6 bytes (row 20 + pad) of 64-byte snake sprite $6A ($87C6-$8805, copied to $5A80)
; Sprite $6B (copied to $5AC0, 64 bytes): Frog squashed death animation frame 1 (road collision / timeout)
$8806spr_frog_squash_1.fill9, $00
$880F.byte$07, $00, $e0, $0f, $3c, $f0, $0f, $7e
$8817.byte$f0, $0f, $ff, $f0, $07, $ff, $e0, $03
$881F.byte$ff, $c0, $03, $ff, $c0, $03, $ff, $c0
$8827.byte$0f, $ff, $f0, $3f, $ff, $fc, $3f, $ff
$882F.byte$fc, $1f, $ff, $f8, $1f, $ff, $f0, $0f
$8837.byte$ff, $e0, $03, $ff, $80, $00, $fe
$883E.fill8, $00
; Sprite $6C (copied to $5B00, 64 bytes): Frog squashed death animation frame 2 (road collision / timeout)
$8846spr_frog_squash_2.byte$00, $00, $00, $00, $00, $00, $38, $78
$884E.byte$70, $7c, $fc, $f8, $7f, $ff, $f8, $7f
$8856.byte$ff, $f8, $3f, $ff, $f0, $3f, $ff, $f0
$885E.byte$3f, $ff, $f0, $1f, $ff, $e0, $0f, $ff
$8866.byte$c0, $7f, $ff, $f8, $7f, $ff, $f8, $7f
$886E.byte$ff, $f8, $3f, $ff, $f0, $3f, $ff, $f0
$8876.byte$1f, $ff, $e0, $0f, $ff, $c0, $03, $ff
$887E.fill8, $00
; Sprite $6D (copied to $5B40, 64 bytes): Frog drowning splash animation frame 1 (river / home bay hazard)
$8886spr_frog_splash_1.byte$00, $00, $00, $00, $00, $00, $0c, $01
$888E.byte$80
$888F.fill10, $00
$8899.byte$6c, $00, $18, $00, $30, $00, $00, $00
$88A1.byte$00, $00, $00, $01, $83, $00, $00, $00
$88A9.byte$00, $00, $00, $00, $18, $00, $30, $00
$88B1.byte$6c
$88B2.fill10, $00
$88BC.byte$06, $01, $80, $00, $00, $00, $00, $00
$88C4.byte$00, $00
; Sprite $6E (copied to $5B80, 64 bytes): Frog drowning splash animation frame 2 (river / home bay hazard)
$88C6spr_frog_splash_2.byte$06, $01, $80, $00, $00, $00, $00, $00
$88CE.byte$00, $00, $c3, $03, $c0, $00, $00, $00
$88D6.byte$00, $00, $18, $6c, $30
$88DB.fill9, $00
$88E4.byte$31, $83, $18
$88E7.fill9, $00
$88F0.byte$18, $6c, $33, $00, $00, $00, $c0, $00
$88F8.byte$00, $00, $c3, $00, $00, $00, $00, $00
$8900.byte$00, $00, $03, $00, $c0, $00
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Initializes C64 hardware, unpacks and pre-shifts dual RAM charsets and sprites
; in VIC Bank 1 ($4000-$7FFF), draws the static playfield and HUD, installs the
; split-screen raster IRQ handler, and enters the foreground idle loop.
;
; Inputs: None (entered on cold boot via $8000 or RESTORE warm start via $8002/$0318)
; Outputs: None (never returns; spins in main_idle_loop at $8BDC after CLI)
; Side Effects:
; - Sets NMINV ($0318/$0319) to $8906 and CINV ($0314/$0315) to $8BDF
; - Selects VIC Bank 1 ($4000-$7FFF), multicolor char mode, border/bg/sprite colors
; - Disables CIA1/CIA2 interrupts and clears pending CIA/VIC interrupt flags
; - Temporarily banks in Character ROM via $00/$01 to copy 44 HUD/status glyphs
; - Builds top river charset ($4800-$4FF7), bottom road charset ($5000-$56C7),
; 21 sprite blocks ($5800-$5D3F), Color RAM ($D800-$DBE7), and Screen RAM ($4400)
; - Initializes attract-mode state via s_9594, enables raster IRQ at line $A1, and executes CLI
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
cart_cold_warm_start
$8906a9 06lda#<cart_cold_warm_start; x-ref: $8000, $8002, $8906, $890b
$89088d 18 03staKERNAL_NMINV_LO; Set NMINV low byte -> RESTORE triggers warm restart at $8906; NMI
$890Ba9 89lda#>cart_cold_warm_start
$890D8d 19 03staKERNAL_NMINV_HI; Set NMINV high byte; NMI
$8910a9 00lda#$00
$89128d 11 d0sta$d011; Blank display (DEN=0) while building VRAM, charsets, and sprites; VIC Control Register 1
$8915a9 03lda#$03
$89178d 02 ddsta$dd02; Set CIA2 Port A bits 0-1 as outputs for VIC bank select; CIA2: Data Direction Register A
$891Aa9 02lda#$02
$891C8d 00 ddsta$dd00; Select VIC Bank 1 (%10 -> $4000-$7FFF); CIA2: Data Port Register A
$891Fa9 18lda#$18
$89218d 16 d0sta$d016; Enable multicolor character mode (MCM=1) and 40 columns (CSEL=1); VIC Control Register 2
$8924a9 05lda#$05
$89268d 20 d0sta$d020; Border color = green ($05); Border Color
$8929a9 00lda#$00
$892B8d 21 d0sta$d021; Background color 0 = black ($00, road asphalt); Background Color 0
$892Ea9 0elda#$0e
$89308d 22 d0sta$d022; Multicolor 1 = light blue ($0E); Background Color 1, Multi-Color Register 0
$8933a9 09lda#$09
$89358d 23 d0sta$d023; Multicolor 2 = brown ($09, logs / brickwork); Background Color 2, Multi-Color Register 1
$8938a9 07lda#$07
$893A8d 28 d0sta$d028; Sprite 1 color = yellow ($07, Lady Frog / bonus); Sprite 1 Color
$893Da9 09lda#$09
$893F8d 29 d0sta$d029; Sprite 2 color = brown ($09, home-bay alligator); Sprite 2 Color
$8942a9 01lda#$01
$89448d 2a d0sta$d02a; Sprite 3 color = white ($01, median/log snake); Sprite 3 Color
$89478d 26 d0sta$d026; Sprite multicolor 1 = white ($01); Sprite Multi-Color Register 1
$894Aa9 04lda#%00000100
$894C8d 1c d0sta$d01c; Enable multicolor mode for Sprite 2 (home-bay alligator); Sprites Multi-Color Mode Select
$894Fa9 08lda#%00001000
$89518d 1d d0sta$d01d; Enable 2x horizontal expansion for Sprite 3 (snake); Sprites Expand 2x Horizontal (X)
$8954a9 1flda#$1f; Bit 7 = 0: clear mask for CIA interrupt enable bits 0-4
$89568d 0d dcsta$dc0d; Disable all CIA1 IRQ sources (including KERNAL Timer A); CIA1: CIA Interrupt Control Register
$89598d 0d ddsta$dd0d; Disable all CIA2 NMI sources; CIA2: CIA Interrupt Control Register
$895Cad 0d ddlda$dd0d; Acknowledge any pending CIA2 NMI flags; CIA2: CIA Interrupt Control Register
$895Fad 0d dclda$dc0d; Acknowledge any pending CIA1 IRQ flags; CIA1: CIA Interrupt Control Register
$8962a9 00lda#<COLOR_RAM; Low byte of $D800 (C64 Color RAM base)
$896485 06stazp_ptr_dst_lo; zpa_06/$07 = $D800 (Color RAM write pointer)
$8966a9 d8lda#>COLOR_RAM; High byte of $D800 (C64 Color RAM base)
$896885 07stazp_ptr_dst_hi
$896Aa9 00lda#$00
$896Caatax
$896D85 11stazp_fill_skip_len; Skip gap = 0 (contiguous Color RAM fill)
$896Fa9 01lda#$01
$897185 10stazp_fill_run_len; Write run = 1 byte
$8973bd 1b 80init_color_ram_loopldacolor_ram_rle_init_tbl,x; Read RLE span byte count ($00 = end of table) ; x-ref: $8987
$8976f0 12bequnpack_mirrored_tiles
$897885 12stazp_block_len_lo; Store Color RAM RLE band byte count
$897Ae8inx
$897Bbd 1b 80ldacolor_ram_rle_init_tbl,x; Read Color RAM nybble value for this band
$897E20 c2 8fjsrfill_patterned_span; Fill zpa_12 bytes at (zpa_06) with color A
$8981e8inx
$8982a5 12ldazp_block_len_lo; Reload band byte count to advance Color RAM pointer
$898420 d5 94jsradvance_dst_ptr; Advance Color RAM pointer zpa_06/$07 by zpa_12
$89874c 73 89jmpinit_color_ram_loop
unpack_mirrored_tiles
$898Aa9 c0lda#<SCREEN_RAM_ROW24_COL00; Low byte of $47C0 (Screen RAM row 24, col 0; stages 64-byte alt turtle strip before $4800 at init) ; x-ref: $8976
$898C85 1cstazp_ptr_top_charset_lo; Init top/river charset cursor low byte ($47C0 stages alt turtle strip before $4800)
$898Ea9 47lda#>SCREEN_RAM_ROW24_COL00; High byte of $47C0 (Screen RAM row 24, col 0)
$899085 1dstazp_ptr_top_charset_hi; Init top/river charset cursor high byte ($47)
$8992a9 00lda#<ROAD_CHARSET_RAM; Low byte of $5000 (VIC Bank 1 bottom road/status RAM charset base)
$899485 1estazp_ptr_bot_charset_lo; Init bottom/road charset cursor low byte ($00 -> $5000)
$8996a9 50lda#>ROAD_CHARSET_RAM; High byte of $5000 (VIC Bank 1 bottom road/status RAM charset base)
$899885 1fstazp_ptr_bot_charset_hi; Init bottom/road charset cursor high byte ($50)
$899Aa2 00ldx#$00
unpack_tile_desc_loop
$899Cbd 40 80ldacharset_mirror_desc_tbl,x; Read source tile graphics pointer low byte ; x-ref: $89bf
$899F85 02stazp_ptr_src_lo; Store tile graphics source pointer low byte
$89A1e8inx
$89A2bd 40 80ldacharset_mirror_desc_tbl,x; Read source tile graphics pointer high byte
$89A585 03stazp_ptr_src_hi; Store tile graphics source pointer high byte
$89A7e8inx
$89A8bd 40 80ldacharset_mirror_desc_tbl,x
$89AB29 f0and#$f0
$89AD4alsra
$89AE85 0astazp_tile_strip_len; zp_tile_strip_len = (upper_nybble * 8) source bytes to mirror vertically
$89B0bd 40 80ldacharset_mirror_desc_tbl,x
$89B3e8inx
$89B429 0fand#$0f
$89B685 1bstazp_charset_dest_id; Save target charset ID (CharsetDescTarget: 0 = $5000 road, 1 = $47C0/$4800 river, 2 = end)
$89B8c9 02cmp#CharsetDescTarget.CHARSET_DESC_END
$89BAf0 06beqcopy_direct_charset_gfx
$89BC20 f5 8fjsrunpack_charset_entry; Unpack vertically mirrored 16px lane tiles + trailing blank column
$89BF4c 9c 89jmpunpack_tile_desc_loop
copy_direct_charset_gfx
$89C2a9 belda#<charset_top_direct_gfx; x-ref: $89ba
$89C485 02stazp_ptr_src_lo; Source = $83BE (47 direct top-charset glyphs: alligator, bays, median, timer)
$89C6a9 83lda#>charset_top_direct_gfx
$89C885 03stazp_ptr_src_hi
$89CAa9 77lda#$77; Byte count - 1 = $0177 (376 bytes -> $4920-$4A97, chars $24-$52)
$89CC85 12stazp_block_len_lo; Store low byte of (byte count - 1) = $77
$89CEa9 01lda#$01
$89D085 13stazp_block_len_hi; Store high byte of (byte count - 1) = $01
$89D2a5 1cldazp_ptr_top_charset_lo; Load top/river charset cursor low byte ($4920)
$89D485 06stazp_ptr_dst_lo; Load top-charset write cursor into destination pointer
$89D6a5 1dldazp_ptr_top_charset_hi; Load top/river charset cursor high byte
$89D885 07stazp_ptr_dst_hi
$89DA20 84 90jsrcopy_memory_block; Copy 376 bytes from (zpa_02) to top charset cursor (zpa_06)
$89DDa5 06ldazp_ptr_dst_lo; Save advanced destination pointer back to top-charset cursor
$89DF85 1cstazp_ptr_top_charset_lo; Save advanced top/river charset cursor low byte ($4A98)
$89E1a5 07ldazp_ptr_dst_hi
$89E385 1dstazp_ptr_top_charset_hi; Save advanced top/river charset cursor high byte
$89E5a9 2elda#<charset_bottom_shared_gfx
$89E785 02stazp_ptr_src_lo; Source = $852E (3 bottom-charset glyphs: timer cell, solid block, median brick)
$89E9a9 85lda#>charset_bottom_shared_gfx
$89EB85 03stazp_ptr_src_hi
$89EDa9 17lda#$17; Byte count - 1 = $0017 (24 bytes -> $5180-$5197, chars $30-$32)
$89EF85 12stazp_block_len_lo; Store low byte of (byte count - 1) = $17
$89F1a9 00lda#$00
$89F385 13stazp_block_len_hi; Store high byte of (byte count - 1) = $00
$89F5a5 1eldazp_ptr_bot_charset_lo; Load bottom/road charset cursor low byte ($5180)
$89F785 06stazp_ptr_dst_lo; Load bottom-charset write cursor into destination pointer
$89F9a5 1fldazp_ptr_bot_charset_hi; Load bottom/road charset cursor high byte
$89FB85 07stazp_ptr_dst_hi
$89FD20 84 90jsrcopy_memory_block; Copy 24 bytes from (zpa_02) to bottom charset cursor (zpa_06)
$8A00a5 06ldazp_ptr_dst_lo; Save advanced destination pointer back to bottom-charset cursor
$8A0285 1estazp_ptr_bot_charset_lo; Save advanced bottom/road charset cursor low byte ($5198)
$8A04a5 07ldazp_ptr_dst_hi
$8A0685 1fstazp_ptr_bot_charset_hi; Save advanced bottom/road charset cursor high byte
$8A08a9 03lda#$03
$8A0A85 01staCPU_PORT; 6510 port $01 = $03 (CHAREN=0): map Character ROM into $D000-$DFFF
$8A0Ca9 07lda#$07
$8A0E85 00staCPU_PORT_DDR; 6510 DDR $00 = $07: set banking bits 0-2 as outputs
$8A10a5 1cldazp_ptr_top_charset_lo; Load top/river charset cursor low byte ($4A98) for HUD ROM glyphs
$8A1285 06stazp_ptr_dst_lo; Set destination pointer to top-charset HUD font slot ($4A98)
$8A14a5 1dldazp_ptr_top_charset_hi; Load top/river charset cursor high byte
$8A1685 07stazp_ptr_dst_hi
$8A18a2 00ldx#$00
copy_hud_rom_glyph_loop
$8A1Abd 95 80ldahud_char_rom_glyph_tbl,x; Read Character ROM screencode for top HUD font ("UEFGIMORST 0-9P") ; x-ref: $8a23
$8A1D20 fa 94jsrcopy_char_rom_glyph; Copy 8-byte glyph from $D000+(A*8) to top charset ($4A98-$4B47, chars $53-$68)
$8A20e8inx
$8A21e0 16cpx#$16; 22 HUD glyphs copied?
$8A23d0 f5bnecopy_hud_rom_glyph_loop
$8A25a5 06ldazp_ptr_dst_lo; Save updated top-charset write cursor ($4B48)
$8A2785 1cstazp_ptr_top_charset_lo; Save updated top/river charset cursor low byte ($4B48)
$8A29a5 07ldazp_ptr_dst_hi
$8A2B85 1dstazp_ptr_top_charset_hi; Save updated top/river charset cursor high byte
$8A2Da5 1eldazp_ptr_bot_charset_lo; Load bottom/road charset cursor low byte ($5198) for status ROM glyphs
$8A2F85 06stazp_ptr_dst_lo; Set destination pointer to bottom-charset status font slot ($5198)
$8A31a5 1fldazp_ptr_bot_charset_hi; Load bottom/road charset cursor high byte
$8A3385 07stazp_ptr_dst_hi
$8A35a2 00ldx#$00
copy_status_rom_glyph_loop
$8A37bd ab 80ldastatus_rev_rom_glyph_tbl,x; Read reverse-video screencode for bottom status font ("AFLOSTWIMER=0-9") ; x-ref: $8a40
$8A3A20 fa 94jsrcopy_char_rom_glyph; Copy 8-byte glyph from $D000+(A*8) to bottom charset ($5198-$5247, chars $33-$48)
$8A3De8inx
$8A3Ee0 16cpx#$16; 22 status bar glyphs copied?
$8A40d0 f5bnecopy_status_rom_glyph_loop
$8A42a5 06ldazp_ptr_dst_lo; Save updated bottom-charset write cursor ($5248)
$8A4485 1estazp_ptr_bot_charset_lo; Save updated bottom/road charset cursor low byte ($5248)
$8A46a5 07ldazp_ptr_dst_hi
$8A4885 1fstazp_ptr_bot_charset_hi; Save updated bottom/road charset cursor high byte
$8A4Aa9 07lda#$07
$8A4C85 01staCPU_PORT; 6510 port $01 = $07 (CHAREN=1): restore I/O registers at $D000-$DFFF
$8A4Ea9 00lda#<SPRITE_DATA_RAM; Low byte of VIC Bank 1 sprite data RAM buffer ($5800-$5D3F, blocks $60-$74)
$8A5085 24stazp_ptr_sprite_dst_lo; Init RAM sprite cursor low byte ($00) -> $5800 (VIC Bank 1 block $60)
$8A52a9 58lda#>SPRITE_DATA_RAM; High byte of VIC Bank 1 sprite data RAM buffer ($5800)
$8A5485 25stazp_ptr_sprite_dst_hi; Init RAM sprite cursor high byte ($58) -> $5800
$8A56a9 46lda#<spr_frog_idle_up
$8A5885 02stazp_ptr_src_lo; Source = $8546 (start of 15 base ROM sprites)
$8A5Aa9 85lda#>spr_frog_idle_up
$8A5C85 03stazp_ptr_src_hi
$8A5Ea9 bflda#$bf; Byte count - 1 = $03BF (960 bytes = 15 sprites * 64B -> $5800-$5BBF, ptrs $60-$6E)
$8A6085 12stazp_block_len_lo; Store low byte of (byte count - 1) = $BF
$8A62a9 03lda#$03
$8A6485 13stazp_block_len_hi; Store high byte of (byte count - 1) = $03
$8A66a5 24ldazp_ptr_sprite_dst_lo; Load RAM sprite cursor low byte ($5800) for base sprite copy
$8A6885 06stazp_ptr_dst_lo; Set destination pointer to RAM sprite block base ($5800)
$8A6Aa5 25ldazp_ptr_sprite_dst_hi; Load RAM sprite cursor high byte ($5800)
$8A6C85 07stazp_ptr_dst_hi
$8A6E20 84 90jsrcopy_memory_block; Copy 15 base sprites from ROM ($8546-$8905) to $5800-$5BBF
$8A71a5 06ldazp_ptr_dst_lo; Save advanced sprite write cursor ($5BC0)
$8A7385 24stazp_ptr_sprite_dst_lo; Save advanced sprite cursor low byte ($C0 -> $5BC0, block $6F)
$8A75a5 07ldazp_ptr_dst_hi
$8A7785 25stazp_ptr_sprite_dst_hi; Save advanced sprite cursor high byte ($5B -> $5BC0)
$8A79a9 46lda#<spr_frog_idle_up
$8A7B85 02stazp_ptr_src_lo; Source = $8546 (frog idle up sprite to vertically flip)
$8A7Da9 85lda#>spr_frog_idle_up
$8A7F85 03stazp_ptr_src_hi
$8A8120 67 95jsrflip_sprite_vertical; Vertically flip spr_frog_idle_up -> $5BC0 (ptr $6F: frog idle down)
$8A84a9 86lda#<spr_frog_idle_right
$8A8685 02stazp_ptr_src_lo; Source = $8586 (frog idle right sprite to horizontally mirror)
$8A88a9 85lda#>spr_frog_idle_right
$8A8A85 03stazp_ptr_src_hi
$8A8C20 2d 95jsrmirror_sprite_horizontal; Horizontally mirror spr_frog_idle_right -> $5C00 (ptr $70: frog idle left)
$8A8Fa9 c6lda#<spr_frog_jump_up
$8A9185 02stazp_ptr_src_lo; Source = $85C6 (frog jump up sprite to vertically flip)
$8A93a9 85lda#>spr_frog_jump_up
$8A9585 03stazp_ptr_src_hi
$8A9720 67 95jsrflip_sprite_vertical; Vertically flip spr_frog_jump_up -> $5C40 (ptr $71: frog jumping down)
$8A9Aa9 06lda#<spr_frog_jump_right
$8A9C85 02stazp_ptr_src_lo; Source = $8606 (frog jump right sprite to horizontally mirror)
$8A9Ea9 86lda#>spr_frog_jump_right
$8AA085 03stazp_ptr_src_hi
$8AA220 2d 95jsrmirror_sprite_horizontal; Horizontally mirror spr_frog_jump_right -> $5C80 (ptr $72: frog jumping left)
$8AA5a9 86lda#<spr_snake_left_1
$8AA785 02stazp_ptr_src_lo; Source = $8786 (snake left frame 1 sprite to horizontally mirror)
$8AA9a9 87lda#>spr_snake_left_1
$8AAB85 03stazp_ptr_src_hi
$8AAD20 2d 95jsrmirror_sprite_horizontal; Horizontally mirror spr_snake_left_1 -> $5CC0 (ptr $73: snake right frame 1)
$8AB0a9 c6lda#<spr_snake_left_2
$8AB285 02stazp_ptr_src_lo; Source = $87C6 (snake left frame 2 sprite to horizontally mirror)
$8AB4a9 87lda#>spr_snake_left_2
$8AB685 03stazp_ptr_src_hi
$8AB820 2d 95jsrmirror_sprite_horizontal; Horizontally mirror spr_snake_left_2 -> $5D00 (ptr $74: snake right frame 2)
$8ABBa9 c0lda#<SCREEN_RAM_ROW24_COL00; Low byte of $47C0 (staged 64-byte alt swimming turtle strip at Screen RAM row 24, col 0)
$8ABD85 04stazp_ptr_lane_cfg_lo; zp_ptr_lane_cfg = $47C0 (reused at init as staged alt swimming turtle strip)
$8ABFa9 47lda#>SCREEN_RAM_ROW24_COL00; High byte of $47C0 (Screen RAM row 24, col 0)
$8AC185 05stazp_ptr_lane_cfg_hi; Init source strip pointer high byte ($47)
$8AC3a5 1cldazp_ptr_top_charset_lo; Load top/river charset cursor low byte ($4B48) for pre-shifted tiles
$8AC585 08stazp_ptr_aux_dst_lo; zpa_08/$09 = $4B48 (top charset pre-shift output cursor, char $69)
$8AC7a5 1dldazp_ptr_top_charset_hi; Load top/river charset cursor high byte
$8AC985 09stazp_ptr_aux_dst_hi; High byte of top/river charset pre-shift destination cursor ($08/$09)
$8ACBa9 00lda#TileHorizDir.TILE_DIR_LEFT
$8ACD85 0bstazp_tile_horiz_dir; Shift direction = 0 (ROL left for left-scrolling turtle lanes)
$8ACFa9 04lda#$04
$8AD185 0astazp_tile_strip_len; Strip width = 4 column-pairs (8 chars = 64 bytes)
$8AD3a9 04lda#$04
$8AD520 5b 94jsrpreshift_tile_strip; Shift alt turtle left 4 bits (2 mc px) -> char $69 ($4B48)
$8AD8a9 06lda#$06
$8ADA20 5b 94jsrpreshift_tile_strip; Shift alt turtle left 6 bits (3 mc px) -> char $71 ($4B88)
$8ADDa5 2dldazp_scratch_byte; Reload previous strip byte size ($40 = 64 bytes) returned by preshift_tile_strip
$8ADFa2 04ldx#$04
$8AE120 ed 94jsradvance_zp_ptr_x; Advance zp_ptr_lane_cfg by $40 to $4800 (base swimming turtle strip)
$8AE4a9 02lda#$02
$8AE620 5b 94jsrpreshift_tile_strip; Shift base turtle left 2 bits (1 mc px) -> char $79 ($4BC8)
$8AE9a5 2dldazp_scratch_byte; Reload previous strip byte size ($40 = 64 bytes) returned by preshift_tile_strip
$8AEBa2 04ldx#$04
$8AED20 ed 94jsradvance_zp_ptr_x; Advance zp_ptr_lane_cfg by $40 to $4840 (diving turtle stages 1 & 2)
$8AF0a2 03ldx#$03
$8AF286 28stxzp_preshift_or_col_cnt; 3 multicolor pixel pre-shift phases (3 -> 2 -> 1)
$8AF4a9 08lda#$08
$8AF685 0astazp_tile_strip_len; Strip width = 8 column-pairs (16 chars = $80 bytes)
preshift_diving_turtles_loop
$8AF8a5 28ldazp_preshift_or_col_cnt; Phase * 2 via ASL = 6, 4, 2 bit left shifts ; x-ref: $8b00
$8AFA0aasla
$8AFB20 5b 94jsrpreshift_tile_strip; Generate 6-, 4-, and 2-bit left-shifted diving turtle tiles ($81-$A9)
$8AFEc6 28deczp_preshift_or_col_cnt; Next pre-shift phase (stops at 0)
$8B00d0 f6bnepreshift_diving_turtles_loop
$8B02a5 2dldazp_scratch_byte; Reload previous strip byte size ($80 = 128 bytes) returned by preshift_tile_strip
$8B04a2 04ldx#$04
$8B0620 ed 94jsradvance_zp_ptr_x; Advance zp_ptr_lane_cfg by $80 to $48C0 (river log + river alligator)
$8B09a2 03ldx#$03
$8B0B86 28stxzp_preshift_or_col_cnt; 3 multicolor pixel pre-shift phases (3 -> 2 -> 1)
$8B0Da9 01lda#TileHorizDir.TILE_DIR_RIGHT
$8B0F85 0bstazp_tile_horiz_dir; Shift direction = 1 (ROR right for right-scrolling log/alligator lanes)
$8B11a9 0dlda#$0d
$8B1385 0astazp_tile_strip_len; Strip width = 13 column-pairs (26 chars = $D0 bytes)
preshift_logs_gators_loop
$8B15a5 28ldazp_preshift_or_col_cnt; Phase * 2 via ASL = 6, 4, 2 bit right shifts ; x-ref: $8b1d
$8B170aasla
$8B1820 5b 94jsrpreshift_tile_strip; Generate 6-, 4-, and 2-bit right-shifted log & alligator tiles ($B1-$F1)
$8B1Bc6 28deczp_preshift_or_col_cnt; Next pre-shift phase (stops at 0)
$8B1Dd0 f6bnepreshift_logs_gators_loop
$8B1Fa9 00lda#<ROAD_CHARSET_RAM; Low byte of $5000 (unshifted truck & racecar strips at start of road charset)
$8B2185 04stazp_ptr_lane_cfg_lo; zp_ptr_lane_cfg = $5000 (reused at init as road truck + racecar unshifted strips)
$8B23a9 50lda#>ROAD_CHARSET_RAM; High byte of $5000 (road/status RAM charset base)
$8B2585 05stazp_ptr_lane_cfg_hi; Init source strip pointer high byte ($50)
$8B27a5 1eldazp_ptr_bot_charset_lo; Load bottom/road charset cursor low byte ($5248) for pre-shift output
$8B2985 08stazp_ptr_aux_dst_lo; zpa_08/$09 = $5248 (bottom charset pre-shift output cursor, char $49)
$8B2Ba5 1fldazp_ptr_bot_charset_hi; Load bottom/road charset cursor high byte
$8B2D85 09stazp_ptr_aux_dst_hi; High byte of bottom/road charset pre-shift destination cursor ($08/$09)
$8B2Fa2 03ldx#$03
$8B3186 28stxzp_preshift_or_col_cnt; 3 multicolor pixel pre-shift phases (3 -> 2 -> 1)
$8B33a9 0elda#$0e
$8B3585 0astazp_tile_strip_len; Strip width = 14 column-pairs (truck 9 + racecar 5 = $E0 bytes, shift right)
preshift_right_vehicles_loop
$8B37a5 28ldazp_preshift_or_col_cnt; Phase * 2 via ASL = 6, 4, 2 bit right shifts ; x-ref: $8b3f
$8B390aasla
$8B3A20 5b 94jsrpreshift_tile_strip; Generate 6-, 4-, and 2-bit right-shifted truck & racecar tiles ($49-$93)
$8B3Dc6 28deczp_preshift_or_col_cnt; Next pre-shift phase (stops at 0)
$8B3Fd0 f6bnepreshift_right_vehicles_loop
$8B41a5 2dldazp_scratch_byte; Reload previous strip byte size ($E0 = 224 bytes) returned by preshift_tile_strip
$8B43a2 04ldx#$04
$8B4520 ed 94jsradvance_zp_ptr_x; Advance zp_ptr_lane_cfg by $E0 to $50E0 (car + bulldozer unshifted strips)
$8B48a9 0alda#$0a
$8B4A85 0astazp_tile_strip_len; Strip width = 10 column-pairs (car 5 + bulldozer 5 = $A0 bytes)
$8B4Ca2 03ldx#$03
$8B4E86 28stxzp_preshift_or_col_cnt; 3 multicolor pixel pre-shift phases (3 -> 2 -> 1)
$8B50a9 00lda#TileHorizDir.TILE_DIR_LEFT
$8B5285 0bstazp_tile_horiz_dir; Shift direction = 0 (ROL left for left-scrolling car/bulldozer lanes)
preshift_left_vehicles_loop
$8B54a5 28ldazp_preshift_or_col_cnt; Phase * 2 via ASL = 6, 4, 2 bit left shifts ; x-ref: $8b5c
$8B560aasla
$8B5720 5b 94jsrpreshift_tile_strip; Generate 6-, 4-, and 2-bit left-shifted car & bulldozer tiles ($9D-$CF)
$8B5Ac6 28deczp_preshift_or_col_cnt; Next pre-shift phase (stops at 0)
$8B5Cd0 f6bnepreshift_left_vehicles_loop
$8B5Ea9 26lda#<SCREEN_RAM_ROW00_COL38; Low byte of Screen RAM row 0, col 38 ($4426): start of 82-byte home-bay wall pattern
$8B6085 06stazp_ptr_dst_lo; zpa_06/$07 = $4426 (Screen RAM row 0 col 38 -> home bay rows 1-2)
$8B62a9 44lda#>SCREEN_RAM_ROW00_COL38; High byte of Screen RAM row 0, col 38 ($4426)
$8B6485 07stazp_ptr_dst_hi
$8B66a9 05lda#$05
$8B6885 10stazp_fill_run_len; Pattern write run = 5 home-bay wall tiles
$8B6Aa9 03lda#$03
$8B6C85 11stazp_fill_skip_len; Pattern skip gap = 3 bay-opening tiles
$8B6Ea9 52lda#$52
$8B7085 12stazp_block_len_lo; Span = $52 (82 bytes -> $4426-$4477 across home bay rows 1-2)
$8B72a9 33lda#$33
$8B7420 c2 8fjsrfill_patterned_span; Draw 5 home-bay wall dividers with tile $33
$8B77a9 08lda#<SCREEN_RAM_ROW13_COL00; Low byte of Screen RAM row 13, col 0 ($4608): start of 2-row purple brick median strip
$8B7985 06stazp_ptr_dst_lo; zpa_06/$07 = $4608 (Screen RAM row 13 col 0: median strip)
$8B7Ba9 46lda#>SCREEN_RAM_ROW13_COL00; High byte of Screen RAM row 13, col 0 ($4608)
$8B7D85 07stazp_ptr_dst_hi; Set destination pointer high byte ($46)
$8B7Fa9 00lda#$00
$8B8185 11stazp_fill_skip_len; Pattern skip gap = 0 (solid fill; run stays 5)
$8B83a9 32lda#$32
$8B8520 c2 8fjsrfill_patterned_span; Fill 82 bytes ($4608-$4659, rows 13-14) with purple brick tile $32
$8B88a9 98lda#<SCREEN_RAM_ROW23_COL00; Low byte of Screen RAM row 23, col 0 ($4798): start bank & bottom status bar
$8B8A85 06stazp_ptr_dst_lo; zpa_06/$07 = $4798 (Screen RAM row 23 col 0: start bank & status bar)
$8B8Ca9 47lda#>SCREEN_RAM_ROW23_COL00; High byte of Screen RAM row 23, col 0 ($4798)
$8B8E85 07stazp_ptr_dst_hi; Set destination pointer high byte ($47)
$8B90a9 31lda#$31
$8B9220 c2 8fjsrfill_patterned_span; Fill 82 bytes ($4798-$47E9, rows 23-24) with solid block $31 (clears $47C0 staging)
$8B95a2 00ldx#$00
$8B97bd 5e 80copy_hud_row_loopldastr_hud_top_row,x; x-ref: $8ba0
$8B9A9d 00 44staSCREEN_RAM,x; Copy 32-char HUD header (" 1 UP 00000 FROGS 4 TIME ") to row 0
$8B9De8inx
$8B9Ee0 20cpx#$20
$8BA0d0 f5bnecopy_hud_row_loop
$8BA2a9 fflda#$ff
$8BA485 7dstazp_frog_state_timer; Set attract/demo mode flag ($FF = not in active 1P game)
$8BA6a9 03lda#$03
$8BA885 acstazp_level_layout_idx; Initialize attract/round cycle index to 3
$8BAAad 15 d0lda$d015; Sprite display Enable
$8BAD29 feand#%11111110
$8BAF8d 15 d0sta$d015; Hide Sprite 0 (player frog) during attract mode; Sprite display Enable
$8BB2a9 00lda#$00
$8BB485 5bstazp_speed_mode; Default speed mode = 0 (FAST)
$8BB685 5estazp_two_player_flag; Default to 1-player mode ($00 = 1P, $01 = 2P)
$8BB8a9 dflda#<raster_irq_handler
$8BBA8d 14 03staKERNAL_CINV_LO; Set CINV ($0314) low byte -> raster_irq_handler ($8BDF); IRQ
$8BBDa9 8blda#>raster_irq_handler
$8BBF8d 15 03staKERNAL_CINV_HI; Set CINV ($0315) high byte; IRQ
$8BC2a9 01lda#$01
$8BC48d 1a d0sta$d01a; Enable VIC-II raster compare interrupt (ERST=1); VIC Interrupt Mask Register (IMR)
$8BC7a9 fflda#$ff
$8BC98d 19 d0sta$d019; Acknowledge any pending VIC-II interrupt flags; VIC Interrupt Request Register (IRR)
$8BCCa9 a1lda#RasterSplitLine.RASTER_SPLIT_MEDIAN
$8BCE8d 12 d0sta$d012; First raster split at line $A1 (161, mid-screen median charset switch); Raster Position
$8BD185 2estazp_raster_split_line; Shadow initial raster split scanline ($A1 = median strip)
$8BD3a9 1blda#$1b
$8BD58d 11 d0sta$d011; Unblank screen: 25 rows, YSCROLL=3, DEN=1, RST8=0; VIC Control Register 1
$8BD820 94 95jsrreset_standby_session; Initialize attract-mode game state, lane objects, sprites, and HUD
$8BDB58cli; Enable IRQ; all game logic runs inside raster_irq_handler
$8BDC4c dc 8bmain_idle_loopjmpmain_idle_loop; Foreground spin loop (never exits) ; x-ref: $8bdc
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Two-phase VIC-II split-screen raster ISR ($0314/$0315) multiplexing scanline
; $A1 (road/status charset $5000, F1/F3/F5 & joystick input, timers, home-bay
; hazards, collisions, death/respawn, 2P swap, and frog hops) and scanline $FC
; (HUD/river charset $4800, road wipe, 3x lane scrolling, and SID playback).
;
; Inputs: zpa_2E (active raster trigger: $A1 or $FC), CIA1 $DC00/$DC01 ports,
; VIC-II sprite state ($D002, $D010, $D015, $D01E), and gameplay state
; globals (zpa_31, zpa_45..zpa_48, zpa_53..zpa_55, zpa_58, zpa_5B,
; zpa_5E..zpa_5F, zpa_6E..zpa_6F, zpa_77, zpa_79, zpa_7D..zpa_7F,
; zpa_81, zpf_82, zpa_84..zpa_86, zpf_A7, zpa_AE, zpa_B1, zpa_B3..B8)
; Outputs: zpa_2E (next raster trigger), input/mode state (zpa_46, zpa_54,
; zpa_55, zpa_58, zpa_5B, zpa_5E..zpa_5F, zpa_7E), wipe state zpa_77,
; timers/hazards (zpa_45, zpa_47..zpa_48, zpa_53, zpa_79, zpa_7D,
; zpa_7F, zpa_86, zpa_AE, zpa_B1, zpa_B4..zpa_B8, zpf_A7), and player
; turn/game-over state (zpa_81, zpf_82)
; Side Effects: Switches $D018 charset ($5000 / $4800), chains $D012/$D011 IRQ,
; reconfigures CIA1 $DC00..$DC03, updates SID $D418 & streams, updates
; Screen/Color RAM ($4400/$D800) & sprite pointers/enable, acks $D019,
; and pops Y/X/A pushed by KERNAL $FF48 before RTI.
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$8BDFa9 14raster_irq_handlerlda#$14; Screen $4400 + bottom road/status charset $5000 (VIC bank 1) ; x-ref: $8bb8, $8bbd
$8BE18d 18 d0sta$d018; VIC Memory Control Register
$8BE4a5 2eldazp_raster_split_line; Check active raster split phase ($A1 median vs $FC bottom border)
$8BE6c9 fccmp#RasterSplitLine.RASTER_SPLIT_BOTTOM
$8BE8d0 03bneirq_mid_raster_phase
$8BEA4c d4 8ejmpirq_top_raster_phase; At scanline $FC: switch to top charset and scroll lanes
; --- Mid-screen raster phase (scanline $A1, median strip) ---
irq_mid_raster_phase
$8BEDa9 fclda#RasterSplitLine.RASTER_SPLIT_BOTTOM; Schedule next raster IRQ at bottom border scanline $FC (252) ; x-ref: $8be8
$8BEF8d 12 d0sta$d012; Raster Position
$8BF285 2estazp_raster_split_line; Shadow next raster split scanline ($FC = bottom border)
$8BF4a9 1blda#$1b; 25 rows, display enabled, Y-scroll 3, raster bit 8 = 0
$8BF68d 11 d0sta$d011; VIC Control Register 1
$8BF9a9 fflda#$ff; CIA1 keyboard pass 1: Port B output ($FF), Port A input ($00)
$8BFB8d 03 dcsta$dc03; CIA1: Data Direction Register B
$8BFEa9 00lda#$00
$8C008d 02 dcsta$dc02; CIA1: Data Direction Register A
$8C038d 01 dcsta$dc01; Drive all keyboard columns PB0-PB7 low; CIA1: Data Port Register B
$8C06ae 00 dcldx$dc00; Read active keyboard row bits PA0-PA7 into X; CIA1: Data Port Register A
$8C09e4 54cpxzp_key_row_prev; Debounce keyboard row state against previous frame
$8C0Bf0 31beqcheck_f5_players_key
$8C0D86 54stxzp_key_row_prev; Latch new CIA1 Port A keyboard row bitmask ($FF = idle, $FE = PA0)
$8C0Fa9 fflda#$ff; CIA1 keyboard pass 2: Port A output ($FF), Port B input ($00)
$8C118d 02 dcsta$dc02; CIA1: Data Direction Register A
$8C14a9 00lda#$00
$8C168d 03 dcsta$dc03; CIA1: Data Direction Register B
$8C198d 00 dcsta$dc00; Drive all keyboard rows PA0-PA7 low; CIA1: Data Port Register A
$8C1Cac 01 dcldy$dc01; Read active keyboard column bits PB0-PB7 into Y; CIA1: Data Port Register B
$8C1Fc4 55cpyzp_key_col_prev; Debounce keyboard column state against previous frame
$8C21f0 1bbeqcheck_f5_players_key
$8C2384 55styzp_key_col_prev; Latch new CIA1 Port B keyboard column bitmask ($EF=F1, $DF=F3, $BF=F5)
$8C25e0 fecpx#$fe; Row PA0 ($FE) + Col PB4 ($EF) = F1 key (Start Game)
$8C27d0 07bnecheck_f3_speed_key
$8C29c0 efcpy#$ef
$8C2Bd0 03bnecheck_f3_speed_key
$8C2D20 99 95jsrstart_new_game; Start new game and trigger opening theme (stream 8)
$8C30e0 fecheck_f3_speed_keycpx#$fe; Row PA0 ($FE) + Col PB5 ($DF) = F3 key (FAST/SLOW) ; x-ref: $8c27, $8c2b
$8C32d0 0abnecheck_f5_players_key
$8C34c0 dfcpy#$df
$8C36d0 06bnecheck_f5_players_key
$8C38a9 01lda#$01
$8C3A45 5beorzp_speed_mode; Toggle game speed flag (0 = FAST, 1 = SLOW)
$8C3C85 5bstazp_speed_mode; Store updated F3 game speed mode ($00 = FAST, $01 = SLOW)
check_f5_players_key
$8C3Ee0 fecpx#$fe; Row PA0 ($FE) + Col PB6 ($BF) = F5 key (1UP/2UP) ; x-ref: $8c0b, $8c21, $8c32, $8c36
$8C40d0 0dbnecheck_fire_pause_toggle
$8C42c0 bfcpy#$bf
$8C44d0 09bnecheck_fire_pause_toggle
$8C46a5 5eldazp_two_player_flag
$8C4849 01eor#$01; Toggle player count flag (0 = 1P, 1 = 2P)
$8C4A85 5estazp_two_player_flag; Store updated 1P/2P mode flag ($00 = 1P, $01 = 2P)
$8C4C20 94 95jsrreset_standby_session; Reset game to standby/attract state for new player count
check_fire_pause_toggle
$8C4Fa9 fflda#$ff; x-ref: $8c40, $8c44
$8C51a6 81ldxzp_active_player; Drive opposite CIA1 port high (0=Port A for P1, 1=Port B for P2)
$8C539d 02 dcsta$dc02,x; CIA1: Data Direction Register A
$8C569d 00 dcsta$dc00,x; CIA1: Data Port Register A
$8C59a9 00lda#$00
$8C5Ba6 5fldxzp_joy_port_offset; Active joystick port offset (1 = Port 1 for P1, 0 = Port 2 for P2)
$8C5D9d 02 dcsta$dc02,x; CIA1: Data Direction Register A
$8C60bd 00 dclda$dc00,x; Read active player's joystick port and debounce fire state; CIA1: Data Port Register A
$8C63c5 58cmpzp_joy_fire_prev; Compare against previous joystick reading to edge-detect Fire pause toggle
$8C65f0 15beqcheck_screen_wipe_state
$8C6785 58stazp_joy_fire_prev; Latch active-low joystick port reading for Fire button debounce
$8C6929 10and#$10; Isolate Fire button (bit 4, active-low: 0 = pressed)
$8C6Bd0 0fbnecheck_screen_wipe_state
$8C6Da5 7eldazp_pause_flag; Load current game pause flag ($00 = running, $0F = paused)
$8C6F49 0feor#$0f; Toggle pause flag ($00 = running, $0F = paused)
$8C7185 7estazp_pause_flag; Store toggled pause flag ($0F mutes SID via EOR #$0F below)
$8C73a6 6eldxzp_sound_active; Update SID master volume only if a sound stream is active
$8C75f0 05beqcheck_screen_wipe_state
$8C7749 0feor#$0f
$8C798d 18 d4sta$d418; Mute SID volume ($00) on pause, or restore ($0F) on resume; Select Filter Mode and Volume
check_screen_wipe_state
$8C7Ca5 77ldazp_screen_wipe_state; Screen/round state ($00=round clear, $FF/$FE=wipe, $01=play) ; x-ref: $8c65, $8c6b, $8c75
$8C7Ed0 10bnecheck_river_wipe_req
$8C80a5 6eldazp_sound_active; If no SID sound stream is active, advance round immediately
$8C82f0 06beqadvance_round_and_wipe
$8C84a5 6fldazp_sound_stream_id; Check active stream ID while waiting for round-clear fanfare
$8C86c9 07cmp#SoundStreamId.MELODY_ROUND_CLEAR; Keep waiting while round-clear fanfare (stream 7) plays
$8C88f0 0ebeqcheck_game_paused
advance_round_and_wipe
$8C8A20 a9 90jsradvance_to_next_round; Advance round/speed and wipe river tiles ($77 -> $FE) ; x-ref: $8c82
$8C8D4c 01 8fjmpirq_ack_exit
check_river_wipe_req
$8C9010 06bplcheck_game_paused; x-ref: $8c7e
$8C9220 fe 90jsrwipe_river_screen; Wipe river screen area with water tiles ($77: $FF -> $FE)
$8C954c 01 8fjmpirq_ack_exit
$8C98a5 7echeck_game_pausedldazp_pause_flag; Skip all gameplay updates while paused ($0F) ; x-ref: $8c88, $8c90
$8C9Af0 03beqtick_half_sec_prescaler
$8C9C4c 01 8fjmpirq_ack_exit
tick_half_sec_prescaler
$8C9Fc6 48deczp_half_sec_prescaler; 30-frame (~0.5s) prescaler for turtle & 1Hz hazard timers ; x-ref: $8c9a
$8CA1f0 03beqadvance_turtle_anim_phase
$8CA34c 8e 8djmprun_frame_gameplay_checks
advance_turtle_anim_phase
$8CA6a9 1elda#$1e; Reload 30-frame prescaler ; x-ref: $8ca1
$8CA885 48stazp_half_sec_prescaler; Reset 30-frame (~0.5s) prescaler countdown ($1E)
$8CAAe6 b1inczp_turtle_anim_phase; Advance diving-turtle animation phase (0..11)
$8CACa5 b1ldazp_turtle_anim_phase; Wrap global turtle animation phase modulo 12 (0..11)
$8CAEc9 0ccmp#$0c
$8CB030 02bmistore_turtle_anim_phase
$8CB2a9 00lda#$00
store_turtle_anim_phase
$8CB485 b1stazp_turtle_anim_phase; Store updated global turtle animation phase (0..11) ; x-ref: $8cb0
$8CB629 01and#$01; Run hazard, attract, and life timers on even phases (~1 Hz)
$8CB8f0 03beqrun_one_sec_hazards
$8CBA4c 8e 8djmprun_frame_gameplay_checks
$8CBDa9 67run_one_sec_hazardslda#$67; Toggle river alligator Sprite 2 between $67 (open) & $68 (closed) ; x-ref: $8cb8
$8CBFcd fa 47cmpSCREEN_RAM_SPR2_PTR; Is Sprite 2 river alligator head currently open ($67)?
$8CC2d0 02bnestore_river_gator_frame
$8CC4a9 68lda#$68
store_river_gator_frame
$8CC68d fa 47staSCREEN_RAM_SPR2_PTR; Update Sprite 2 pointer ($67 = open jaws, $68 = closed mouth) ; x-ref: $8cc2
$8CC9a5 b4ldazp_bay_fly_idx; Active bonus-fly bay index (0..4, or $FF if none)
$8CCB10 1dbpltick_bay_fly_timer
$8CCD20 7c 9cjsrtry_select_empty_home_bay; Try to select a pseudo-random empty home bay in X
$8CD030 2fbmiupdate_bay_alligator
$8CD286 b4stxzp_bay_fly_idx; Record home bay index (0..4) hosting active bonus fly
$8CD4a9 3dlda#$3d; Bonus fly base tile ($3D) and light-green color ($0D)
$8CD685 4estazp_bay_tile_id; Set home-bay base tile = $3D (bonus fly 3x2 graphic)
$8CD8a9 0dlda#$0d
$8CDA85 4dstazp_home_bay_color; Multicolor green ($0D) Color RAM attr for bonus fly
$8CDC20 32 94jsrdraw_home_bay_tiles; Draw bonus fly in home bay X for 4 ticks (~4s)
$8CDFa9 04lda#$04
$8CE185 b5stazp_bay_fly_timer; Set 4-tick (~4s) bonus-fly lifetime countdown
$8CE3a9 01lda#HomeBayState.HOME_BAY_BONUS_FLY
$8CE595 a7stazp_home_bay_state,x; Mark bay X as containing bonus fly ($01)
$8CE74c 01 8djmpupdate_bay_alligator
$8CEAa5 79tick_bay_fly_timerldazp_frog_hop_active; Do not despawn bonus fly while frog is mid-hop ; x-ref: $8ccb
$8CECd0 13bneupdate_bay_alligator
$8CEEc6 b5deczp_bay_fly_timer; Decrement bonus-fly countdown (~1 Hz); 0 = expired
$8CF0d0 0fbneupdate_bay_alligator
$8CF2a6 b4ldxzp_bay_fly_idx; Load home bay index (0..4) of expired bonus fly
$8CF486 49stxzp_home_bay_idx; Target home bay index (0..4) for draw_empty_home_bay
$8CF620 07 94jsrdraw_empty_home_bay; Erase expired bonus fly back to empty home bay
$8CF9a9 00lda#HomeBayState.HOME_BAY_EMPTY
$8CFB95 a7stazp_home_bay_state,x; Mark home bay X as empty ($00) after bonus fly expires
$8CFDa9 fflda#$ff
$8CFF85 b4stazp_bay_fly_idx; Mark no home-bay bonus fly active ($FF)
update_bay_alligator
$8D01a5 aeldazp_bay_gator_phase; Home-bay alligator phase (0=none, 2=emerging, 1=open jaws) ; x-ref: $8cd0, $8ce7, $8cec, $8cf0
$8D03d0 1fbnetick_bay_gator_timer
$8D0520 7c 9cjsrtry_select_empty_home_bay
$8D0830 50bmiupdate_life_timer_or_attract
$8D0A86 b8stxzp_bay_gator_bay_idx; Save home bay index (0..4) hosting the emerging alligator
$8D0Ca9 43lda#$43; Emerging alligator base tile ($43) and light-green ($0D)
$8D0E85 4estazp_bay_tile_id; Set home-bay base tile = $43 (emerging alligator)
$8D10a9 0dlda#$0d
$8D1285 4dstazp_home_bay_color; Multicolor green ($0D) Color RAM attr for emerging alligator
$8D1420 32 94jsrdraw_home_bay_tiles; Draw emerging alligator in home bay X for 2 ticks
$8D17a9 02lda#$02
$8D1985 b7stazp_bay_gator_timer; Set emerging-alligator countdown = 2 (counts 2..0 -> 3 1Hz ticks)
$8D1Ba9 02lda#$02
$8D1D85 aestazp_bay_gator_phase; Set home-bay alligator phase to 2 (emerging head)
$8D1F95 a7stazp_home_bay_state,x; Mark home bay X as containing emerging alligator ($02)
$8D214c 5a 8djmpupdate_life_timer_or_attract
tick_bay_gator_timer
$8D24c6 b7deczp_bay_gator_timer; Count down current bay-alligator phase duration ; x-ref: $8d03
$8D2610 32bplupdate_life_timer_or_attract
$8D28c6 aedeczp_bay_gator_phase; Advance bay alligator phase (2 -> 1 open jaws, 1 -> 0 expired)
$8D2Af0 1ebeqclear_bay_alligator
$8D2Ca6 b8ldxzp_bay_gator_bay_idx; Reload home bay index (0..4) of active bay alligator
$8D2Eb5 a7ldazp_home_bay_state,x; Abort alligator if frog already claimed bay X ($FF)
$8D3030 26bmicancel_bay_alligator
$8D3286 49stxzp_home_bay_idx; Target home bay index (0..4) for draw_home_bay_tiles
$8D34a9 49lda#$49; Open-jaws lethal alligator tile ($49) and light-green ($0D)
$8D3685 4estazp_bay_tile_id; Set home-bay base tile = $49 (open-jaws alligator)
$8D38a9 0dlda#$0d
$8D3A85 4dstazp_home_bay_color; Multicolor green ($0D) Color RAM attr for open-jaws alligator
$8D3C20 32 94jsrdraw_home_bay_tiles
$8D3Fa9 felda#HomeBayState.HOME_BAY_GATOR_OPEN_JAWS; Mark bay X as lethal alligator jaws ($FE) for 4 ticks
$8D4195 a7stazp_home_bay_state,x; Store lethal open-jaws alligator state ($FE) in home bay X
$8D43a9 04lda#$04
$8D4585 b7stazp_bay_gator_timer; Set open-jaws countdown = 4 (counts 4..0 -> 5 1Hz ticks)
$8D474c 5a 8djmpupdate_life_timer_or_attract
$8D4Aa6 b8clear_bay_alligatorldxzp_bay_gator_bay_idx; Reload home bay index (0..4) to erase expired alligator ; x-ref: $8d2a
$8D4C86 49stxzp_home_bay_idx; Target home bay index (0..4) for draw_empty_home_bay
$8D4E20 07 94jsrdraw_empty_home_bay; Clear expired alligator back to empty home bay
$8D51a9 00lda#HomeBayState.HOME_BAY_EMPTY
$8D5395 a7stazp_home_bay_state,x; Mark home bay X as empty ($00) after alligator despawns
$8D554c 5a 8djmpupdate_life_timer_or_attract
cancel_bay_alligator
$8D58c6 aedeczp_bay_gator_phase; Cancel bay alligator phase (1 -> 0) if frog already claimed bay ; x-ref: $8d30
update_life_timer_or_attract
$8D5Aa5 7dldazp_frog_state_timer; Frog state ($FF = game over/standby, 0 = alive, >0 = dying/pause) ; x-ref: $8d08, $8d21, $8d26, $8d47, $8d55
$8D5C10 12bpltick_frog_life_timer
$8D5Ea5 5eldazp_two_player_flag; In 2P standby/game-over, alternate P1/P2 HUD score every ~1s
$8D60f0 2cbeqrun_frame_gameplay_checks
$8D62a5 81ldazp_active_player
$8D6449 01eor#$01
$8D6685 81stazp_active_player; Toggle active player index (0 = P1, 1 = P2) for 2P attract HUD alternation
$8D68a2 00ldx#$00
$8D6A20 2d 9djsrswap_player_score_state; Swap P1 and P2 4-byte score/lives HUD blocks
$8D6D4c 8e 8djmprun_frame_gameplay_checks
tick_frog_life_timer
$8D70a5 7dldazp_frog_state_timer; Tick TIME bar only when frog is alive and not in round/bay pause ; x-ref: $8d5c
$8D7205 85orazp_round_clear_freeze; Hold life timer while round-clear fanfare freeze ($01) is active
$8D7405 86orazp_bay_bonus_freeze; Hold life timer while post-bay bonus pause ($01..$60) is active
$8D76d0 16bnerun_frame_gameplay_checks
$8D78c6 47deczp_frog_life_timer; Decrement frog life countdown timer (starts at 30)
$8D7Ad0 07bnecheck_low_time_alert
$8D7Ca9 6blda#$6b; Use squash death sprite ($6B) and trigger timeout death
$8D7E85 53stazp_death_spr_frame; Set initial death sprite frame ($6B = squash)
$8D8020 b2 99jsrtrigger_frog_death
check_low_time_alert
$8D83a5 47ldazp_frog_life_timer; Play low-time alert SFX (stream 5) when 5 ticks remain ; x-ref: $8d7a
$8D85c9 05cmp#$05
$8D87d0 05bnerun_frame_gameplay_checks
$8D89a9 05lda#SoundStreamId.SFX_LOW_TIME_ALERT
$8D8B20 73 9bjsrstart_sound_stream
run_frame_gameplay_checks
$8D8E20 83 96jsrupdate_hud_and_status; Refresh HUD score, lives, TIME bar, round, and FAST/SLOW status ; x-ref: $8ca3, $8cba, $8d60, $8d6d, $8d76, ...
$8D9120 62 9ajsrupdate_snake_patrol; Update Sprite 3 snake position and slither animation
$8D9420 8d 98jsrcheck_river_frog_support; Check river log/turtle/gator support or water drowning
$8D9720 93 97jsrcheck_frog_collisions_and_home_bay; Check bounds, road/sprite collisions, and home-bay landing
$8D9Aa6 7fldxzp_bay_timer_banner_cnt; Decrement post-bay bonus TIME display countdown
$8D9C86 86stxzp_bay_bonus_freeze; Latch pre-decrement banner count ($00..$60) as bay-bonus freeze
$8D9Ef0 03beqcheck_lady_frog_spawn
$8DA0cadex
$8DA186 7fstxzp_bay_timer_banner_cnt; Store decremented "TIMER XX" banner frame countdown
check_lady_frog_spawn
$8DA3a5 b6ldazp_lady_frog_spawned; Enable Sprite 1 (lady frog) once it wraps to left edge (< $000F) ; x-ref: $8d9e
$8DA5d0 1dbnecheck_frog_active_or_dying
$8DA7ad 10 d0lda$d010; Sprites 0-7 MSB of X coordinate
$8DAA29 02and#$02
$8DACd0 16bnecheck_frog_active_or_dying
$8DAEad 02 d0lda$d002; Sprite 1 X Pos
$8DB1c9 0fcmp#$0f
$8DB3b0 0fbcscheck_frog_active_or_dying
$8DB5ad 15 d0lda$d015; Sprite display Enable
$8DB809 02ora#$02
$8DBA8d 15 d0sta$d015; Sprite display Enable
$8DBDad 1e d0lda$d01e; Read $D01E to clear any stale sprite-to-sprite collision latch; Sprite to Sprite Collision Detect
$8DC0a9 01lda#$01
$8DC285 b6stazp_lady_frog_spawned; Mark Lady Frog (Sprite 1) spawned for current frog life ($01)
check_frog_active_or_dying
$8DC4a5 85ldazp_round_clear_freeze; Freeze frog control during round-clear ($85) or bay-bonus ($86) pause ; x-ref: $8da5, $8dac, $8db3
$8DC6d0 0abneexit_mid_irq
$8DC8a5 86ldazp_bay_bonus_freeze; Freeze frog respawn/input while bay-bonus pause ($01..$60) is active
$8DCAd0 06bneexit_mid_irq
$8DCCa5 7dldazp_frog_state_timer; 0 = alive (poll joystick), >0 = death/respawn timer, $FF = standby
$8DCEf0 6fbeqpoll_joystick_hop_input
$8DD010 03bplupdate_death_anim_and_respawn
$8DD24c 01 8fexit_mid_irqjmpirq_ack_exit; x-ref: $8dc6, $8dca
update_death_anim_and_respawn
$8DD5c9 5acmp#$5a; Step death sprite at ticks $5A (frame 1), $41 (frame 2), $28 (skull) ; x-ref: $8dd0
$8DD7f0 10beqadvance_death_sprite_frame
$8DD9c9 41cmp#$41
$8DDBf0 0cbeqadvance_death_sprite_frame
$8DDDc9 28cmp#$28
$8DDFd0 0fbnedec_death_respawn_timer
$8DE1a9 64lda#$64; Display skull sprite ($64) for final phase of death animation
$8DE38d f8 47staSCREEN_RAM_SPR0_PTR; Set Sprite 0 pointer to skull death frame ($64 -> $5900)
$8DE64c f0 8djmpdec_death_respawn_timer
advance_death_sprite_frame
$8DE9a5 53ldazp_death_spr_frame; Load current death sprite frame ($6B/$6C squash, $6D/$6E splash) ; x-ref: $8dd7, $8ddb
$8DEB8d f8 47staSCREEN_RAM_SPR0_PTR; Set Sprite 0 pointer to active squash/splash death frame
$8DEEe6 53inczp_death_spr_frame; Advance to stage-2 death sprite frame ($6C or $6E)
dec_death_respawn_timer
$8DF0c6 7ddeczp_frog_state_timer; Count down death/bay-arrival delay until respawn ; x-ref: $8ddf, $8de6
$8DF2d0 58bnejmp_step_active_hop
$8DF4a5 84ldazp_frog_died_flag; 0 = frog reached home bay (respawn); 1 = frog died (check lives)
$8DF6f0 41beqrespawn_frog_and_exit
$8DF8a6 81ldxzp_active_player; Load active player index (0 = P1, 1 = P2)
$8DFAa5 b3ldazp_player_lives; Check active player's remaining lives (0 = out of lives)
$8DFCd0 20bnecheck_two_player_swap
$8DFEa9 01lda#$01
$8E0095 82stazp_player_game_over,x; Mark current player X as out of lives (game over)
$8E02ad 15 d0lda$d015; Sprite display Enable
$8E0529 feand#$fe; Hide frog Sprite 0
$8E078d 15 d0sta$d015; Sprite display Enable
$8E0Aa5 82ldazp_player_game_over; Check if both Player 1 and Player 2 are now game over
$8E0Cf0 10beqcheck_two_player_swap
$8E0Ea5 83ldazp_player_game_over + 1; Check Player 2 game-over flag (1 = out of lives, or 1P mode)
$8E10f0 0cbeqcheck_two_player_swap
$8E12a9 fflda#$ff; Enter Game Over standby ($FF) and play game-over melody (stream 6)
$8E1485 7dstazp_frog_state_timer; Set frog state to $FF (Game Over / standby)
$8E16a9 06lda#SoundStreamId.MELODY_GAME_OVER
$8E1820 73 9bjsrstart_sound_stream
$8E1B4c 3f 8ejmppoll_joystick_hop_input
check_two_player_swap
$8E1Ea5 5eldazp_two_player_flag; In 2P mode, switch to the other player if they still have lives ; x-ref: $8dfc, $8e0c, $8e10
$8E20f0 17beqrespawn_frog_and_exit
$8E228atxa
$8E2349 01eor#$01
$8E25aatax
$8E26b4 82ldyzp_player_game_over,x; Check if other player X is already game over (1 = out of lives)
$8E28d0 0fbnerespawn_frog_and_exit
$8E2A86 81stxzp_active_player; Switch active player index (0 = P1, 1 = P2) to incoming player
$8E2C49 01eor#$01
$8E2E85 5fstazp_joy_port_offset; Set CIA1 joystick port offset (1 = $DC01 Port 1 for P1, 0 = $DC00 Port 2 for P2)
$8E30a2 00ldx#$00
$8E3220 09 9djsrswap_player_sprites_and_state; Swap active player state and sprite registers with backup buffer
$8E35a9 fflda#ScreenWipeState.SCREEN_WIPE_FULL; Request full river + home-bay + road redraw ($77 = $FF)
$8E3785 77stazp_screen_wipe_state; Queue two-phase playfield wipe ($FF) for incoming player
respawn_frog_and_exit
$8E3920 40 96jsrreset_player_frog; Reset frog Sprite 0 to starting road home position ; x-ref: $8df6, $8e20, $8e28
$8E3C4c 01 8fjmpirq_ack_exit
poll_joystick_hop_input
$8E3Fa5 79ldazp_frog_hop_active; If frog is already mid-hop, continue stepping current hop ; x-ref: $8dce, $8e1b
$8E41d0 09bnejmp_step_active_hop
$8E43a6 5fldxzp_joy_port_offset; Active CIA1 joystick port offset (1 = Port 1, 0 = Port 2)
$8E45bd 00 dclda$dc00,x; Read active joystick port and edge-detect new direction press; CIA1: Data Port Register A
$8E48c5 46cmpzp_joy_hop_prev; Compare against previous joystick reading to edge-detect new hop press
$8E4Ad0 03bnedecode_joystick_dir
$8E4C4c 96 8ejmp_step_active_hopjmpstep_active_frog_hop; x-ref: $8df2, $8e41
$8E4F85 46decode_joystick_dirstazp_joy_hop_prev; Latch active-low joystick port reading ($FF = centered/idle) ; x-ref: $8e4a
$8E516arora; Shift active-low bits 0..3 (Up, Down, Left, Right) into Carry
$8E5290 0cbccstart_hop_up
$8E546arora
$8E5590 15bccstart_hop_down
$8E576arora
$8E5890 1ebccstart_hop_left
$8E5A6arora
$8E5B90 27bccstart_hop_right
$8E5D4c 96 8ejmpstep_active_frog_hop
$8E60a9 01start_hop_uplda#FrogHopDir.HOP_DIR_UP; Hop Up: set frog jump-up sprite ($62) ; x-ref: $8e52
$8E6285 31stazp_frog_hop_dir; Latch active frog hop direction = $01 (up)
$8E64a9 62lda#$62
$8E668d f8 47staSCREEN_RAM_SPR0_PTR; Set Sprite 0 pointer to frog jump-up frame ($62 -> $5880)
$8E694c 8d 8ejmptrigger_hop_sfx
$8E6Ca9 02start_hop_downlda#FrogHopDir.HOP_DIR_DOWN; Hop Down: set frog jump-down sprite ($71) ; x-ref: $8e55
$8E6E85 31stazp_frog_hop_dir; Latch active frog hop direction = $02 (down)
$8E70a9 71lda#$71
$8E728d f8 47staSCREEN_RAM_SPR0_PTR; Set Sprite 0 pointer to frog jump-down frame ($71 -> $5C40)
$8E754c 8d 8ejmptrigger_hop_sfx
$8E78a9 04start_hop_leftlda#FrogHopDir.HOP_DIR_LEFT; Hop Left: set frog jump-left sprite ($72) ; x-ref: $8e58
$8E7A85 31stazp_frog_hop_dir; Latch active frog hop direction = $04 (left)
$8E7Ca9 72lda#$72
$8E7E8d f8 47staSCREEN_RAM_SPR0_PTR; Set Sprite 0 pointer to frog jump-left frame ($72 -> $5C80)
$8E814c 8d 8ejmptrigger_hop_sfx
$8E84a9 08start_hop_rightlda#FrogHopDir.HOP_DIR_RIGHT; Hop Right: set frog jump-right sprite ($63) ; x-ref: $8e5b
$8E8685 31stazp_frog_hop_dir; Latch active frog hop direction = $08 (right)
$8E88a9 63lda#$63
$8E8A8d f8 47staSCREEN_RAM_SPR0_PTR; Set Sprite 0 pointer to frog jump-right frame ($63 -> $58C0)
$8E8Da9 01trigger_hop_sfxlda#$01; Mark hop active ($79 = 1) and trigger hop SFX (stream 0) ; x-ref: $8e69, $8e75, $8e81
$8E8F85 79stazp_frog_hop_active; Set frog hop-in-progress flag ($01 = mid-hop)
$8E91a9 00lda#SoundStreamId.SFX_FROG_HOP
$8E9320 73 9bjsrstart_sound_stream
step_active_frog_hop
$8E96a5 79ldazp_frog_hop_active; Exit if no hop is in progress ; x-ref: $8e4c, $8e5d
$8E98f0 67beqirq_ack_exit
$8E9Aa5 45ldazp_frog_hop_px_cnt; Check hop pixel counter ($FF = start new hop, $0F..$00 = mid-hop)
$8E9C10 04bpldispatch_frog_hop_dir
$8E9Ea9 0flda#$0f; Initialize 16-pixel hop counter (15..0, 2 px/frame = 8 frames)
$8EA085 45stazp_frog_hop_px_cnt; Reload 16-pixel hop countdown ($0F down to $00 -> $FF)
dispatch_frog_hop_dir
$8EA2a5 31ldazp_frog_hop_dir; Shift active hop direction bitmask ($01/$02/$04/$08) into Carry ; x-ref: $8e9c
$8EA46arora
$8EA590 09bcccheck_hop_down
$8EA720 0c 8fjsrfrog_hop_step_up; Advance frog 2 pixels upward this frame
$8EAA20 0c 8fjsrfrog_hop_step_up
$8EAD4c 01 8fjmpirq_ack_exit
$8EB06acheck_hop_downrora; x-ref: $8ea5
$8EB190 09bcccheck_hop_left
$8EB320 32 8fjsrfrog_hop_step_down; Advance frog 2 pixels downward this frame
$8EB620 32 8fjsrfrog_hop_step_down
$8EB94c 01 8fjmpirq_ack_exit
$8EBC6acheck_hop_leftrora; x-ref: $8eb1
$8EBD90 09bcccheck_hop_right
$8EBF20 56 8fjsrfrog_hop_step_left; Advance frog 2 pixels left this frame
$8EC220 56 8fjsrfrog_hop_step_left
$8EC54c 01 8fjmpirq_ack_exit
$8EC86acheck_hop_rightrora; x-ref: $8ebd
$8EC990 36bccirq_ack_exit
$8ECB20 8c 8fjsrfrog_hop_step_right; Advance frog 2 pixels right this frame
$8ECE20 8c 8fjsrfrog_hop_step_right
$8ED14c 01 8fjmpirq_ack_exit
; --- Bottom-border raster phase (scanline $FC): top charset & lane scroll ---
irq_top_raster_phase
$8ED4a9 12lda#$12; Screen $4400 + top HUD/river charset $4800 (VIC bank 1) ; x-ref: $8bea
$8ED68d 18 d0sta$d018; VIC Memory Control Register
$8ED9a9 a1lda#RasterSplitLine.RASTER_SPLIT_MEDIAN; Schedule next raster IRQ at median strip scanline $A1 (161)
$8EDB8d 12 d0sta$d012; Raster Position
$8EDE85 2estazp_raster_split_line; Shadow next raster split scanline ($A1 = median strip)
$8EE0a9 1blda#$1b
$8EE28d 11 d0sta$d011; VIC Control Register 1
$8EE5a5 7eldazp_pause_flag; Freeze lane scrolling and SID playback while paused
$8EE7d0 18bneirq_ack_exit
$8EE9a5 77ldazp_screen_wipe_state; If screen wipe phase 2 ($FE), redraw home bays and clear road
$8EEBc9 fecmp#ScreenWipeState.SCREEN_WIPE_BAYS_ROAD
$8EEDd0 06bnescroll_lanes_and_tick_sfx
$8EEF20 15 91jsrredraw_home_bays_and_wipe_road; Redraw all 5 home bays, fill road tiles, and set $77 = $01
$8EF24c 01 8fjmpirq_ack_exit
scroll_lanes_and_tick_sfx
$8EF520 3f 93jsrupdate_scrolling_lane; Service 3 of 9 river/road lanes per frame (full pass every 3 frames) ; x-ref: $8eed
$8EF820 3f 93jsrupdate_scrolling_lane
$8EFB20 3f 93jsrupdate_scrolling_lane
$8EFE20 ba 9bjsrupdate_sound_stream; Advance 3-voice SID sound/music stream player
; --- Shared VIC-II raster IRQ acknowledge and KERNAL stack exit ---
$8F01a9 01irq_ack_exitlda#$01; Acknowledge VIC-II raster interrupt flag ($D019 bit 0) ; x-ref: $8c8d, $8c95, $8c9c, $8dd2, $8e3c, ...
$8F038d 19 d0sta$d019; VIC Interrupt Request Register (IRR)
$8F0668pla; Restore Y, X, A pushed by KERNAL $FF48 IRQ prologue and RTI
$8F07a8tay
$8F0868pla
$8F09aatax
$8F0A68pla
$8F0B40rti
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Steps the player frog (Sprite 0) 1 pixel upward (clamped at home-bay ceiling
; Y = $38) and, when the 16-pixel hop completes, sets the landed up-facing
; sprite, decrements the current row index, and queues a 10-point BCD bonus on
; new upward row progress.
;
; Inputs: VIC-II $D001 (Sprite 0 Y position); zpa_45 (remaining hop pixel step
; counter, $0F..$00); zpa_4A (current signed frog row, $0A down to
; $FF/-1); zpa_4B (furthest upward signed row reached this life);
; zpa_48 (30-frame prescaler, sampled via finish_frog_hop)
; Outputs: zpa_45 decremented ($FF on hop completion); Y = updated Sprite 0 Y
; ($38..$E7). Mid-hop (zpa_45 >= 0): A and X preserved. On hop
; completion (zpa_45 = $FF): X = $60; zpa_79 = $00; zpa_5D = zpa_48;
; zpa_4A decremented; if signed zpa_4A < zpa_4B, zpa_4B = zpa_4A and
; zpa_7A = $01 (+10 BCD pts); A, N, Z, C modified
; Side Effects: Updates VIC-II $D001 (Sprite 0 Y); on hop completion, writes
; Sprite 0 pointer $47F8 = $60 (landed up frame) and reads VIC-II
; $D01F to clear mid-hop sprite-background collisions
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$8F0Cac 01 d0frog_hop_step_upldy$d001; Load current Sprite 0 (player frog) Y coordinate ; x-ref: $8ea7, $8eaa; Sprite 0 Y Pos
$8F0F88dey; Move frog 1 pixel upward (called twice/frame = 2 px/frame)
$8F10c0 37cpy#$37; Moved past top home-bay ceiling (Y = $38 / 56)?
$8F12d0 02bnestore_frog_up_y
$8F14a0 38ldy#$38; Clamp Sprite 0 Y to home-bay row ($38)
$8F168c 01 d0store_frog_up_ysty$d001; Commit updated Sprite 0 Y position ; x-ref: $8f12; Sprite 0 Y Pos
$8F19c6 45deczp_frog_hop_px_cnt; Decrement 16-pixel hop step counter (15..0 -> $FF)
$8F1B30 01bmicomplete_hop_up; Underflow to $FF (-1) marks final (16th) pixel of hop
$8F1D60rts; Hop still in progress (zpa_45 >= 0)
$8F1Ea2 60complete_hop_upldx#$60; Landed up-facing frog sprite pointer ($60 -> $5800 in Bank 1) ; x-ref: $8f1b
$8F2020 d1 99jsrfinish_frog_hop; Set landed sprite, clear $D01F collisions, end hop, latch RNG
$8F23c6 4adeczp_frog_row; Advance signed frog row upward (10 = sidewalk .. 0 = river, -1 = bay)
$8F25a5 4aldazp_frog_row; Load updated frog row to check for new upward progress
$8F27c5 4bcmpzp_frog_best_row; Signed compare against furthest upward row reached this life
$8F2910 06bplhop_step_up_done; Skip forward-progress bonus if row >= best row (handles row -1/$FF)
$8F2B85 4bstazp_frog_best_row; Record new furthest-upward row watermark
$8F2Da9 01lda#$01; Load +10 points ($01 in 10-point BCD units) for new upward row progress
$8F2F85 7astazp_score_delta_bcd_lo; Queue +10-point forward-hop bonus in pending BCD score delta low byte
$8F3160hop_step_up_donerts; x-ref: $8f29
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Steps the player frog (Sprite 0) 1 pixel downward, clamped at the bottom
; sidewalk (Y = $E8), and decrements the 16-pixel hop counter; on the 16th
; step, completes the downward hop with the idle-down frame ($6F) and advances
; the frog's row index (clamped at row $0A).
;
; Inputs: $D001 = Sprite 0 Y coordinate; zpa_45 = remaining hop pixel counter
; ($0F..$00); zpa_4A = current frog row index ($00..$0A);
; zpa_48 = 30-frame prescaler count (sampled via finish_frog_hop)
; Outputs: Y = updated Sprite 0 Y coordinate (clamped to <= $E8);
; zpa_45 decremented ($0E..$FF);
; when hop completes (zpa_45 == $FF): X = $6F, A clobbered,
; zpa_4A = min(zpa_4A + 1, $0A), a_47F8 = $6F, zpa_79 = $00,
; zpa_5D = zpa_48 (otherwise A and X preserved)
; Side Effects: Writes VIC-II Sprite 0 Y position ($D001); on the 16th step,
; calls finish_frog_hop (updates Sprite 0 pointer $47F8 and reads
; $D01F to clear latched sprite-to-background collisions)
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$8F32ac 01 d0frog_hop_step_downldy$d001; Read current frog (Sprite 0) Y coordinate ; x-ref: $8eb3, $8eb6; Sprite 0 Y Pos
$8F35c8iny; Step 1 pixel downward (called twice/frame = 2 px/frame)
$8F36c0 e9cpy#$e9; Past bottom starting sidewalk at Y = $E8 (232)?
$8F38d0 02bnestore_hop_down_y
$8F3Aa0 e8ldy#$e8; Clamp frog Y to bottom sidewalk boundary ($E8)
$8F3C8c 01 d0store_hop_down_ysty$d001; Write updated Sprite 0 Y position ; x-ref: $8f38; Sprite 0 Y Pos
$8F3Fc6 45deczp_frog_hop_px_cnt; Decrement 16-pixel hop step counter ($0F down to $FF)
$8F4130 01bmifinish_hop_down; Branch when 16th pixel step finishes ($00 -> $FF)
$8F4360rts; Hop still in progress (steps 1..15)
$8F44a2 6ffinish_hop_downldx#$6f; Sprite 0 pointer $6F = landed frog facing down ; x-ref: $8f41
$8F4620 d1 99jsrfinish_frog_hop; Set landed frame, clear $D01F, end hop, and latch RNG
$8F49e6 4ainczp_frog_row; Advance frog row index downward (0 = top river .. 10 = sidewalk)
$8F4Ba9 0alda#$0a; Max row index = $0A (10, bottom starting sidewalk)
$8F4Dc5 4acmpzp_frog_row; Check signed ($0A - zpa_4A) >= 0 (zpa_4A <= $0A)
$8F4F10 04bplhop_down_done; Row index within playfield bounds (0..10)
$8F51a9 0alda#$0a
$8F5385 4astazp_frog_row; Clamp frog row index to bottom sidewalk ($0A)
$8F5560hop_down_donerts; x-ref: $8f4f
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Steps the player frog (Sprite 0) 1 pixel left across its 9-bit VIC-II X
; coordinate ($D010 bit 0:$D000), clamping at left border X = $0011 and
; completing the 16-pixel hop via finish_frog_hop when zpa_45 underflows.
;
; Inputs: $D000 = Sprite 0 X low byte; $D010 bit 0 = Sprite 0 X MSB;
; zpa_45 = remaining hop pixel counter (0..15 for player hop, or >= 1
; when drifted left by a river turtle lane); zpa_48 = 30-frame prescaler
; Outputs: $D000/$D010 bit 0 = decremented 9-bit X coordinate (clamped >= $0011);
; zpa_2D = updated Sprite 0 X low byte; zpa_45 = zpa_45 - 1;
; if zpa_45 < 0: X = $70, a_47F8 = $70, zpa_79 = $00, zpa_5D = zpa_48;
; A clobbered (X clobbered only on hop completion; Y preserved)
; Side Effects: Updates VIC-II Sprite 0 X position ($D000/$D010); when hop
; completes (zpa_45 < 0), updates Sprite 0 pointer ($47F8 = $70)
; and reads $D01F to clear mid-hop background collisions
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$8F5638frog_hop_step_leftsec; Step Sprite 0 left by 1 pixel (player hop or turtle drift) ; x-ref: $8ebf, $8ec2, $93f3
$8F57ad 00 d0lda$d000; Sprite 0 X Pos
$8F5Ae9 01sbc#$01; Decrement Sprite 0 X low byte by 1
$8F5C85 2dstazp_scratch_byte; Save candidate Sprite 0 X low byte in scratch
$8F5Eb0 0bbcscheck_frog_left_bound; No borrow (C=1) -> X low did not wrap $00 -> $FF
$8F60ad 10 d0lda$d010; Sprites 0-7 MSB of X coordinate
$8F6329 feand#$fe; Borrow across $0100 -> $00FF: clear Sprite 0 X-MSB (bit 0)
$8F658d 10 d0sta$d010; Sprites 0-7 MSB of X coordinate
$8F684c 7c 8fjmpapply_frog_left_x; X is now $00FF (255); skip left-border clamp check
check_frog_left_bound
$8F6Bad 10 d0lda$d010; x-ref: $8f5e; Sprites 0-7 MSB of X coordinate
$8F6E29 01and#$01; Test Sprite 0 X-MSB (bit 0)
$8F70d0 0abneapply_frog_left_x; X >= 256 (right side of screen) -> no left-border clamp needed
$8F72a5 2dldazp_scratch_byte; Reload candidate Sprite 0 X low byte for left-border clamp check
$8F74c9 10cmp#$10; Did 9-bit X step past left playfield limit ($0011)?
$8F76d0 02bnestore_clamped_left_x
$8F78a9 11lda#$11; Clamp minimum Sprite 0 X position to $0011 (17)
store_clamped_left_x
$8F7A85 2dstazp_scratch_byte; Save clamped Sprite 0 X low byte ; x-ref: $8f76
$8F7Ca5 2dapply_frog_left_xldazp_scratch_byte; Load final Sprite 0 X low byte to commit to $D000 ; x-ref: $8f68, $8f70
$8F7E8d 00 d0sta$d000; Commit updated Sprite 0 X low byte; Sprite 0 X Pos
$8F81c6 45deczp_frog_hop_px_cnt; Decrement remaining pixel steps in current hop
$8F8330 01bmifinish_left_hop; Underflow ($00 -> $FF) marks 16th pixel of hop complete
$8F8560rts; Mid-hop (or river drift step with zpa_45 = 2 -> 1): done
$8F86a2 70finish_left_hopldx#$70; Sprite 0 pointer $70 = landed left-facing frog ($5C00) ; x-ref: $8f83
$8F8820 d1 99jsrfinish_frog_hop; Set landed frame, clear $D01F collisions, end hop ($79=0)
$8F8B60rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Steps the player frog (Sprite 0) 1 pixel to the right across the 9-bit VIC-II
; X coordinate ($D010 bit 0 : $D000), clamped at the right playfield boundary
; ($0147 / 327), and decrements the hop pixel counter; on the 16th hop pixel,
; completes the rightward hop with the landed right-facing sprite ($61). Also
; called with a dummy counter (zpa_45 = $02) to carry the frog on right-moving
; river lanes.
;
; Inputs: $D000 = Sprite 0 X low byte; $D010 bit 0 = Sprite 0 X MSB;
; zpa_45 = remaining hop pixel counter ($0F..$00, or $02 on river);
; zpa_48 = 30-frame prescaler count (sampled via finish_frog_hop)
; Outputs: zpa_2D = updated (clamped) Sprite 0 X low byte;
; zpa_45 decremented ($0E..$FF, or $01 on river carry);
; mid-hop/river (zpa_45 >= 0): A = zpa_2D, X and Y preserved;
; when hop completes (zpa_45 == $FF): X = $61, a_47F8 = $61,
; zpa_79 = $00, A = zpa_5D = zpa_48, Y preserved
; Side Effects: Updates VIC-II Sprite 0 9-bit X position ($D000 and $D010 bit 0);
; on the 16th hop step, calls finish_frog_hop (writes Sprite 0
; pointer $47F8 = $61 and reads $D01F to clear latched collisions)
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$8F8C18frog_hop_step_rightclc; x-ref: $8ecb, $8ece, $93e5
$8F8Dad 00 d0lda$d000; Read current frog (Sprite 0) X low byte; Sprite 0 X Pos
$8F9069 01adc#$01; Step 1 pixel right (2 px/frame on hop, or river carry)
$8F9285 2dstazp_scratch_byte; Stage candidate Sprite 0 X low byte in scratch
$8F9490 0bbcccheck_hop_right_clamp; No $FF -> $00 wrap; check right-edge clamp if MSB = 1
$8F96ad 10 d0lda$d010; Sprites 0-7 MSB of X coordinate
$8F9909 01ora#$01; Carry wrapped X across 256 ($00FF -> $0100): set Sprite 0 X MSB
$8F9B8d 10 d0sta$d010; Sprites 0-7 MSB of X coordinate
$8F9E4c b2 8fjmpstore_hop_right_x; Commit X = $0100 (within playfield bounds)
check_hop_right_clamp
$8FA1ad 10 d0lda$d010; x-ref: $8f94; Sprites 0-7 MSB of X coordinate
$8FA429 01and#$01; Test Sprite 0 X MSB (bit 0); clamp only when X >= 256
$8FA6f0 0abeqstore_hop_right_x; X < 256 ($0001..$00FF): no right-border clamp needed
$8FA8a5 2dldazp_scratch_byte; Reload candidate Sprite 0 X low byte for right-border clamp check
$8FAAc9 48cmp#$48; Past right playfield boundary at 9-bit X = $0147 (327)?
$8FACd0 02bnesave_hop_right_x_lo
$8FAEa9 47lda#$47; Clamp Sprite 0 X low byte to $47 (9-bit X = $0147 / 327)
$8FB085 2dsave_hop_right_x_lostazp_scratch_byte; Save clamped Sprite 0 X low byte ; x-ref: $8fac
$8FB2a5 2dstore_hop_right_xldazp_scratch_byte; Load final Sprite 0 X low byte to commit to $D000 ; x-ref: $8f9e, $8fa6
$8FB48d 00 d0sta$d000; Write updated Sprite 0 X low byte; Sprite 0 X Pos
$8FB7c6 45deczp_frog_hop_px_cnt; Decrement hop pixel counter ($0F..$00 -> $FF; $02 -> $01 on river)
$8FB930 01bmifinish_hop_right; Branch when 16th pixel step finishes ($00 -> $FF)
$8FBB60rts; Hop still in progress (or river carry step complete)
$8FBCa2 61finish_hop_rightldx#$61; Sprite 0 pointer $61 = landed frog facing right ($5840 in Bank 1) ; x-ref: $8fb9
$8FBE20 d1 99jsrfinish_frog_hop; Set landed frame, clear $D01F collisions, end hop, latch RNG
$8FC160rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Fills a zpa_12-byte memory span at (zpa_06) with byte A in repeating runs of
; zpa_10 written bytes followed by zpa_11 skipped (unmodified) bytes. When
; zpa_11 = 0, performs a contiguous solid fill.
;
; Inputs: A = fill byte; zpa_06/$07 = 16-bit destination pointer;
; zpa_10 = write run length; zpa_11 = skip gap length (0 = solid);
; zpa_12 = total span byte count ($00 = 256 bytes)
; Outputs: Y = zpa_12; zpa_2D = fill byte; A, zpa_29, zpa_2A clobbered;
; X and zpa_06/$07 preserved; Z = 1, C = 1
; Side Effects: Writes patterned byte runs into (zpa_06)[0..zpa_12-1] (Screen
; RAM, Color RAM, or RAM character sets)
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$8FC285 2dfill_patterned_spanstazp_scratch_byte; Cache fill byte value across patterned fill loop ; x-ref: $897e, $8b74, $8b85, $8b92, $9058
$8FC4a9 00lda#$00
$8FC685 29stazp_fill_run_cnt; Reset write-run byte counter
$8FC885 2astazp_fill_skip_cnt; Reset skip-gap byte counter
$8FCAa8tay; Start at destination offset Y = 0
$8FCBa5 2dspan_write_loopldazp_scratch_byte; Reload cached fill byte for current destination write ; x-ref: $8fdb, $8feb
$8FCD91 06sta(zp_ptr_dst_lo),y; Store fill byte at destination + Y
$8FCFe6 29inczp_fill_run_cnt; Count byte written in current run
$8FD1c8iny
$8FD2c4 12cpyzp_block_len_lo; Reached total span length?
$8FD4d0 01bnecheck_run_done
$8FD660rts; Span finished during write run
$8FD7a5 29check_run_doneldazp_fill_run_cnt; Load current write-run byte count ; x-ref: $8fd4
$8FD9c5 10cmpzp_fill_run_len; Completed zp_fill_run_len consecutive writes?
$8FDBd0 eebnespan_write_loop; Continue writing current run if not full
$8FDDa9 00lda#$00
$8FDF85 29stazp_fill_run_cnt; Reset write-run counter for next cycle
$8FE1a5 2aspan_skip_loopldazp_fill_skip_cnt; Load current skip-gap byte count ; x-ref: $8ff2
$8FE3c5 11cmpzp_fill_skip_len; Skipped zp_fill_skip_len gap bytes? (0 = solid fill)
$8FE5d0 06bneskip_span_byte; Advance Y without writing while in gap
$8FE7a9 00lda#$00
$8FE985 2astazp_fill_skip_cnt; Reset skip-gap counter for next cycle
$8FEBf0 debeqspan_write_loop; Unconditional branch (Z=1) to next write run
$8FEDc8skip_span_byteiny; Leave (zpa_06),Y unmodified and advance offset ; x-ref: $8fe5
$8FEEe6 2ainczp_fill_skip_cnt; Count skipped byte in current gap
$8FF0c4 12cpyzp_block_len_lo; Reached total span length during gap?
$8FF2d0 edbnespan_skip_loop
$8FF460rts; Span finished during skip gap
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Unpacks a descriptor of N 8-byte top-half lane glyphs from (zpa_02) into N
; vertically mirrored 16-byte (8x16 top/bottom) character pairs in the selected
; RAM charset, appends one 16-byte background-filled blank character pair ($00
; road asphalt or $55 river water), and advances the active charset cursor.
;
; Inputs: zpa_02/zpa_03 = 16-bit ROM source pointer (N * 8 top-half glyph bytes);
; zpa_0A = total source byte count to unpack (N * 8);
; zpa_1B = target charset selector ($00 = road $5000, non-zero = river $47C0/$4800);
; zpa_1C/zpa_1D = 16-bit river/top charset write cursor (when zpa_1B != 0);
; zpa_1E/zpa_1F = 16-bit road/bottom charset write cursor (when zpa_1B == 0)
; Outputs: zpa_1E/zpa_1F (if zpa_1B == 0) or zpa_1C/zpa_1D (if zpa_1B != 0)
; advanced by (2 * zpa_0A) + $10 bytes;
; zpa_08/zpa_09 = updated cursor; zpa_06/zpa_07 = updated cursor - $10;
; zpa_02/zpa_03 = entry source + zpa_0A - 8; zpa_2C = zpa_0A;
; zpa_2D = $00 or $55; zpa_20 = $08, zpa_21 = $01, zpa_10 = $01,
; zpa_11 = $00, zpa_12 = $10, zpa_29 = $00, zpa_2A = $00;
; A = zpa_09, Y = $10; X preserved (caller descriptor index)
; Side Effects: Writes (2 * zpa_0A) + 16 bytes of mirrored 2-row lane tiles and a
; trailing blank column into RAM ($47C0/$4800 river or $5000 road charset)
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
unpack_charset_entry
$8FF5a9 00lda#$00; x-ref: $89bc
$8FF785 2cstazp_unpack_or_shift_cnt; Reset unpacked source byte counter
$8FF985 2dstazp_scratch_byte; Default blank-column fill = $00 (multicolor 00 = black road)
$8FFBa5 1eldazp_ptr_bot_charset_lo; Default zp_ptr_dst low byte = bottom/road charset cursor
$8FFD85 06stazp_ptr_dst_lo
$8FFFa5 1fldazp_ptr_bot_charset_hi; Default zp_ptr_dst high byte = bottom/road charset cursor
$900185 07stazp_ptr_dst_hi
$9003a5 1bldazp_charset_dest_id; Target charset selector (0 = $5000 road, 1 = $47C0/$4800 river)
$9005f0 0cbeqmirror_glyph_col_loop; Keep road cursor and $00 fill when zp_charset_dest_id == 0
$9007a5 1cldazp_ptr_top_charset_lo; Load top/river charset write cursor low byte into zp_ptr_dst
$900985 06stazp_ptr_dst_lo
$900Ba5 1dldazp_ptr_top_charset_hi; Load top/river charset write cursor high byte into zp_ptr_dst
$900D85 07stazp_ptr_dst_hi
$900Fa9 55lda#$55; %01010101 multicolor 01 fill (light blue river water, $D022)
$901185 2dstazp_scratch_byte; Store $55 river water fill byte for trailing blank column
mirror_glyph_col_loop
$9013a9 07lda#$07; Set zpa_08/$09 = zpa_06/$07 + 7 so Y = 8..1 writes offsets +15..+8 ; x-ref: $9005, $9042
$901520 76 90jsrcalc_offset_dst_ptr
$9018a0 08ldy#$08; zpa_21 = 8: reverse row index (8..1) for bottom 8x8 glyph
$901A84 21styzp_mirror_dst_idx; Initialize mirrored bottom-glyph row index (8..1)
$901Ca0 00ldy#$00; zpa_20 = 0: forward row index (0..7) for source and top 8x8 glyph
$901E84 20styzp_mirror_src_idx; Initialize forward source/top-glyph row index (0..7)
mirror_glyph_row_loop
$9020a4 20ldyzp_mirror_src_idx; Load forward glyph scanline index (0..7) ; x-ref: $9036
$9022b1 02lda(zp_ptr_src_lo),y; Read scanline Y (0..7) from top-half source glyph
$9024e6 2cinczp_unpack_or_shift_cnt; Count unpacked source byte (1..zpa_0A)
$902691 06sta(zp_ptr_dst_lo),y; Write unflipped scanline to top char at (zpa_06) + 0..7
$9028a4 21ldyzp_mirror_dst_idx; Load reverse bottom-glyph scanline index (8..1)
$902A91 08sta(zp_ptr_aux_dst_lo),y; Write vertically mirrored scanline to bottom char at (zpa_06) + 15..8
$902Ce6 20inczp_mirror_src_idx; Advance forward scanline index (0..7)
$902Ea5 2cldazp_unpack_or_shift_cnt; Load unpacked source glyph byte count
$9030c5 0acmpzp_tile_strip_len; Unpacked all zp_tile_strip_len source bytes for this tile set?
$9032f0 11beqappend_blank_tile_col; All columns mirrored: append trailing 16-byte blank column
$9034c6 21deczp_mirror_dst_idx; Step reverse scanline index down (8 -> 0)
$9036d0 e8bnemirror_glyph_row_loop; Loop until all 8 scanlines of current column pair are written
$9038a9 10lda#$10; Advance zpa_06/$07 by 16 bytes (2 chars) to next column pair
$903A20 d5 94jsradvance_dst_ptr
$903Da9 08lda#$08; Advance zpa_02/$03 by 8 bytes to next top-half source glyph
$903F20 e1 94jsradvance_src_ptr
$90424c 13 90jmpmirror_glyph_col_loop; Unpack and mirror next 8x16 glyph column
append_blank_tile_col
$9045a9 10lda#$10; Span length = 16 bytes (1 top + 1 bottom blank character) ; x-ref: $9032
$904785 12stazp_block_len_lo; Store 16-byte fill span for trailing blank char pair
$9049a9 10lda#$10
$904B20 d5 94jsradvance_dst_ptr; Advance zpa_06/$07 by 16 past final mirrored column pair
$904Ea9 00lda#$00
$905085 11stazp_fill_skip_len; Skip gap = 0 (contiguous solid fill)
$9052a9 01lda#$01
$905485 10stazp_fill_run_len; Write run = 1 byte
$9056a5 2dldazp_scratch_byte; Load trailing blank-column fill byte ($00 road or $55 river)
$905820 c2 8fjsrfill_patterned_span; Fill 16-byte trailing blank column with $00 (road) or $55 (river)
$905Ba9 10lda#$10
$905D20 76 90jsrcalc_offset_dst_ptr; Compute zpa_08/$09 = zpa_06/$07 + 16 (cursor past blank column)
$9060a5 1bldazp_charset_dest_id; Write updated cursor back to selected charset pointer
$9062f0 09beqsave_road_charset_cursor
$9064a5 08ldazp_ptr_aux_dst_lo
$906685 1cstazp_ptr_top_charset_lo; Save updated top/river charset write cursor low byte
$9068a5 09ldazp_ptr_aux_dst_hi
$906A85 1dstazp_ptr_top_charset_hi; Save updated top/river charset write cursor high byte
$906C60rts
save_road_charset_cursor
$906Da5 08ldazp_ptr_aux_dst_lo; x-ref: $9062
$906F85 1estazp_ptr_bot_charset_lo; Save updated bottom/road charset write cursor low byte
$9071a5 09ldazp_ptr_aux_dst_hi
$907385 1fstazp_ptr_bot_charset_hi; Save updated bottom/road charset write cursor high byte
$907560rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Adds an unsigned 8-bit byte offset in A to the 16-bit destination pointer at
; $06/$07 and stores the resulting 16-bit address into the auxiliary pointer at
; $08/$09, leaving $06/$07 unchanged.
;
; Inputs: A = unsigned 8-bit byte offset; zpa_06/zpa_07 = 16-bit base pointer
; Outputs: zpa_08/zpa_09 = zpa_06/zpa_07 + A; A = low byte (zpa_08); N/Z from A
; Side Effects: None
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$907618calc_offset_dst_ptrclc; Clear carry for unsigned offset addition ; x-ref: $9015, $905d
$907765 06adczp_ptr_dst_lo; Add byte offset in A to base pointer low byte ($06)
$907985 08stazp_ptr_aux_dst_lo; Store offset pointer low byte ($08)
$907Ba5 07ldazp_ptr_dst_hi
$907D69 00adc#$00; Propagate page-crossing carry into high byte ($07)
$907F85 09stazp_ptr_aux_dst_hi; Store offset pointer high byte ($09)
$9081a5 08ldazp_ptr_aux_dst_lo; Return offset pointer low byte in A
$908360rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Copies (zpa_13:zpa_12 + 1) contiguous bytes from source pointer (zpa_02/$03)
; to destination pointer (zpa_06/$07), advancing both pointers past the block.
;
; Inputs: zpa_02/zpa_03 = 16-bit source address; zpa_06/zpa_07 = 16-bit
; destination address; zpa_12/zpa_13 = 16-bit byte count minus 1
; Outputs: zpa_02/zpa_03 = source + count; zpa_06/zpa_07 = destination + count;
; zpa_12/zpa_13 = $FFFF; A = $FF, Y = $00, C = 0
; Side Effects: Writes copied block (charset/sprite graphics) to target RAM
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$9084a0 00copy_memory_blockldy#$00; Y = 0 fixed offset for (ptr),Y indirect addressing ; x-ref: $89da, $89fd, $8a6e
$9086b1 02copy_byte_looplda(zp_ptr_src_lo),y; Read next byte from source pointer ; x-ref: $909d, $90a6
$908891 06sta(zp_ptr_dst_lo),y; Write byte to destination pointer
$908Ae6 02inczp_ptr_src_lo; Advance 16-bit source pointer (zpa_02/zpa_03)
$908Cd0 02bnecopy_inc_dest
$908Ee6 03inczp_ptr_src_hi
$9090e6 06copy_inc_destinczp_ptr_dst_lo; Advance 16-bit destination pointer (zpa_06/zpa_07) ; x-ref: $908c
$9092d0 02bnecopy_dec_count
$9094e6 07inczp_ptr_dst_hi
$9096a5 12copy_dec_countldazp_block_len_lo; Decrement low byte of remaining (count - 1) ; x-ref: $9092
$909838sec
$9099e9 01sbc#$01
$909B85 12stazp_block_len_lo
$909Db0 e7bcscopy_byte_loop; No borrow ($00 -> $FF not reached): copy next byte
$909Fa5 13ldazp_block_len_hi; Borrow from high byte of remaining (count - 1)
$90A138sec
$90A2e9 01sbc#$01
$90A485 13stazp_block_len_hi
$90A6b0 debcscopy_byte_loop; More 256-byte pages remain: continue copying
$90A860rts; Count underflowed to $FFFF; copy complete
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Advances the level layout (modulo 5), speed tier (modulo 3), and BCD round
; counter, updates hazard sprite enables (river alligator Sprite 2 and snake
; unlock), resets all 5 home bays, and falls through into wipe_river_screen.
;
; Inputs: zpa_7D = frog/mode state ($FF = attract/standby, >= 0 = active game)
; zpa_AC = current level lane layout index (0..4)
; zpa_AD = current round speed tier (0..2)
; zpa_AF = packed BCD round counter ($01..$99)
; VIC-II $D015 = current sprite display enable mask
; Outputs: zpa_AC = (zpa_AC + 1) mod 5; zpa_AD = (zpa_AD + 1) mod 3;
; zpa_AF = zpa_AF + 1 (packed BCD, CLD restored);
; zpa_B0 = $01 when new zpa_AC >= 2 (snake permanently unlocked);
; zpa_B2 = $05 (empty bays remaining), zpa_85 = $00 (round freeze off),
; zpf_A7[0..4] ($00A7..$00AB) = $00 (all 5 home bays empty);
; via wipe_river_screen fall-through: zpa_77 = $FE, A = $FE,
; X = updated zpa_AD (0..2), Y = $00, N/Z/C clobbered
; Side Effects: Starts theme melody (stream $08 via start_sound_stream) when
; zpa_7D >= 0; updates VIC-II $D015 bit 2 (Sprite 2 river
; alligator) and reads $D01E to clear sprite-to-sprite collisions;
; falls through to wipe_river_screen ($90FE), filling river Screen
; RAM $4478..$4607 with water tiles ($07)
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
advance_to_next_round
$90A9a5 7dldazp_frog_state_timer; Skip theme music restart during attract/standby mode ($FF) ; x-ref: $8c8a
$90AB30 05bmiadvance_level_counters
$90ADa9 08lda#SoundStreamId.MELODY_MAIN_THEME; Sound stream 8 = main 3-voice Frogger theme melody
$90AF20 73 9bjsrstart_sound_stream
advance_level_counters
$90B2a4 acldyzp_level_layout_idx; Advance level lane layout index (0..4) modulo 5 in Y ; x-ref: $90ab
$90B4c8iny
$90B5c0 05cpy#$05
$90B7d0 02bnestore_level_layout
$90B9a0 00ldy#$00
$90BB84 acstore_level_layoutstyzp_level_layout_idx; Save updated layout index (0..4); keep in Y for sprite rules below ; x-ref: $90b7
$90BDa6 adldxzp_round_speed_tier; Advance round speed profile tier (0..2) modulo 3 in X
$90BFe8inx
$90C0e0 03cpx#$03
$90C2d0 02bnestore_speed_tier
$90C4a2 00ldx#$00
$90C686 adstore_speed_tierstxzp_round_speed_tier; Save updated speed tier (picked up on next lane delay expiry) ; x-ref: $90c2
$90C8a5 afldazp_round_bcd; Increment packed BCD round counter ("R=01".."R=99")
$90CA18clc
$90CBf8sed
$90CC69 01adc#$01
$90CE85 afstazp_round_bcd; Store updated packed BCD round number
$90D0d8cld; Restore binary arithmetic mode after BCD round increment
$90D1ad 15 d0lda$d015; Read active VIC-II sprite display enable mask; Sprite display Enable
$90D4c0 00cpy#$00; Did level layout wrap to 0 (Round 1, 6, 11...)?
$90D6d0 02bnecheck_river_gator_enable
$90D829 fband#$fb; Clear bit 2: hide Sprite 2 (top-lane river alligator) on layout 0
check_river_gator_enable
$90DAc0 01cpy#$01; Layout index Y >= 1 (layouts 1..4)? ; x-ref: $90d6
$90DC30 02bmicheck_snake_unlock
$90DE09 04ora#$04; Set bit 2: enable Sprite 2 (river alligator) on layouts 1..4
$90E0c0 02check_snake_unlockcpy#$02; Layout index Y >= 2 (Round 3+ or attract layout 4)? ; x-ref: $90dc
$90E230 04bmiapply_round_sprite_mask
$90E4a0 01ldy#$01; Unlock Sprite 3 (median/log snake patrol) for rest of game
$90E684 b0styzp_snake_unlocked; Mark snake hazard permanently unlocked ($01) for rest of game
apply_round_sprite_mask
$90E88d 15 d0sta$d015; Commit updated VIC-II sprite display enable mask ; x-ref: $90e2; Sprite display Enable
$90EBad 1e d0lda$d01e; Read $D01E to clear any latched sprite-to-sprite collisions; Sprite to Sprite Collision Detect
$90EEa9 05lda#$05; Reset remaining unfilled home-bay count to 5
$90F085 b2stazp_bays_remaining; Reset remaining unfilled home bays to 5 for new round
$90F2a9 00lda#$00; Clear post-round-clear frog/timer freeze flag
$90F485 85stazp_round_clear_freeze; Release round-clear frog/timer freeze ($00) for new round
$90F6a0 04ldy#$04; Index Y = 4..0 across all 5 home-bay state slots ($A7..$AB)
clear_home_bays_loop
$90F899 a7 00sta@w zp_home_bay_state,y; Reset home bay Y state to $00 (empty); falls through to wipe_river_screen ; x-ref: $90fc
$90FB88dey
$90FC10 fabplclear_home_bays_loop
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Fills all 400 bytes of the 10-row river playfield in Screen RAM ($4478-$4607,
; rows 3-12) with water tile $07 and sets zpa_77 to $FE for phase-2 road wipe.
; Entered via JSR from $8C92 or via fall-through from s_90A9.
;
; Inputs: None
; Outputs: zpa_77 = $FE (phase-2 bay/road wipe pending), A = $FE, Y = $00
; Side Effects: Overwrites river Screen RAM $4478-$4607 (5 lanes, 400 bytes).
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$90FEa9 07wipe_river_screenlda#$07; Water background tile ($07) in $4800 top charset ; x-ref: $8c92
$9100a0 ffldy#$ff; 1-based count = 255 bytes ($4478-$4576)
wipe_river_chunk1_loop
$910299 77 44staSCREEN_RAM_ROW03_COL00 - 1,y; Fill river bytes 0..254 with water tile ; x-ref: $9106
$910588dey
$9106d0 fabnewipe_river_chunk1_loop
$9108a0 91ldy#$91; 1-based count = 145 bytes ($4577-$4607; total 400 = 10 rows)
wipe_river_chunk2_loop
$910A99 76 45staSCREEN_RAM_ROW03_COL00 + $fe,y; Fill river bytes 255..399 up to median strip ($4608) ; x-ref: $910e
$910D88dey
$910Ed0 fabnewipe_river_chunk2_loop
$9110a9 felda#ScreenWipeState.SCREEN_WIPE_BAYS_ROAD; Schedule phase-2 home-bay redraw & road wipe at scanline $FC
$911285 77stazp_screen_wipe_state; Advance screen wipe state to phase 2 ($FE = bays + road)
$911460rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Redraws all 5 home bays on Screen/Color RAM rows 1-2 from their saved state
; array (zpf_A7[0..4]), fills all 320 bytes of the 8-row road playfield
; ($4658-$4797, rows 15-22) with pavement tile $11, and sets zpa_77 = $01 to
; complete the phase-2 screen wipe and resume gameplay.
;
; Inputs: zpf_A7[0..4] = per-bay occupancy state ($00 = empty, $01 = bonus fly,
; $02 = emerging alligator, $FE = open-jaws alligator, $FF = frog)
; Outputs: zpa_77 = $01 (active gameplay); A = $01; Y = $00; X preserved;
; zpa_49 = $FF; zpa_26 = $00; zpa_4D, zpa_4E clobbered (Z = 0, N = 0)
; Side Effects: Redraws five 3x2 home bays in Screen RAM ($4428-$4477) and Color
; RAM ($D828-$D877); overwrites road Screen RAM $4658-$4797
; (4 lanes, 320 bytes) with road pavement tile $11
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
redraw_home_bays_and_wipe_road
$9115a0 04ldy#$04; Start from rightmost home bay 4 down to bay 0 ; x-ref: $8eef
$911784 49styzp_home_bay_idx; Initialize home bay redraw index (4 down to 0)
redraw_home_bay_loop
$9119a9 0dlda#$0d; Default Color RAM nybble $0D = multicolor ($08) + green ($05) ; x-ref: $9163
$911B85 4dstazp_home_bay_color; Set default multicolor green ($0D) bay Color RAM attr
$911Db9 a7 00lda@w zp_home_bay_state,y; Read occupancy state of home bay Y (0..4)
$9120f0 1cbeqredraw_bay_empty; State $00: bay is empty
$912230 08bmicheck_bay_negative_state; Negative state ($FE open jaws or $FF claimed frog)
$9124c9 01cmp#HomeBayState.HOME_BAY_BONUS_FLY
$9126f0 1cbeqredraw_bay_bonus_fly
$9128c9 02cmp#HomeBayState.HOME_BAY_GATOR_EMERGING
$912Af0 22beqredraw_bay_gator_emerging
check_bay_negative_state
$912Cc9 fecmp#HomeBayState.HOME_BAY_GATOR_OPEN_JAWS; x-ref: $9122
$912Ef0 28beqredraw_bay_gator_jaws
$9130a9 37lda#$37; State $FF: landed home-bay frog base tile ($37..$3C)
$913285 4estazp_bay_tile_id; Set home-bay base tile = $37 (landed frog)
$9134a9 05lda#$05; Override Color RAM nybble to hires green ($05)
$913685 4dstazp_home_bay_color; Use hi-res green ($05) Color RAM attr for claimed frog
$913820 32 94jsrdraw_home_bay_tiles
$913B4c 5f 91jmpnext_home_bay
$913E20 07 94redraw_bay_emptyjsrdraw_empty_home_bay; Draw empty arch hedge ($34..$36) and water ($5D) tiles ; x-ref: $9120
$91414c 5f 91jmpnext_home_bay
redraw_bay_bonus_fly
$9144a9 3dlda#$3d; State $01: bonus fly base tile ($3D..$42), multicolor green ; x-ref: $9126
$914685 4estazp_bay_tile_id; Set home-bay base tile = $3D (bonus fly)
$914820 32 94jsrdraw_home_bay_tiles
$914B4c 5f 91jmpnext_home_bay
redraw_bay_gator_emerging
$914Ea9 43lda#$43; State $02: emerging alligator base tile ($43..$48) ; x-ref: $912a
$915085 4estazp_bay_tile_id; Set home-bay base tile = $43 (emerging alligator)
$915220 32 94jsrdraw_home_bay_tiles
$91554c 5f 91jmpnext_home_bay
redraw_bay_gator_jaws
$9158a9 49lda#$49; State $FE: lethal open-jaws alligator base tile ($49..$4E) ; x-ref: $912e
$915A85 4estazp_bay_tile_id; Set home-bay base tile = $49 (open-jaws alligator)
$915C20 32 94jsrdraw_home_bay_tiles
$915Fc6 49next_home_baydeczp_home_bay_idx; Step down to previous home bay (4..0 -> $FF) ; x-ref: $913b, $9141, $914b, $9155
$9161a4 49ldyzp_home_bay_idx; Load current home bay index into Y ($FF exits loop)
$916310 b4bplredraw_home_bay_loop
$9165a9 11lda#$11; Empty road pavement tile ($11) in bottom road charset
$9167a0 ffldy#$ff; 1-based count = 255 bytes ($4658-$4756)
wipe_road_chunk1_loop
$916999 57 46staSCREEN_RAM_ROW15_COL00 - 1,y; Fill road bytes 0..254 with pavement tile ; x-ref: $916d
$916C88dey
$916Dd0 fabnewipe_road_chunk1_loop
$916Fa0 41ldy#$41; 1-based count = 65 bytes ($4757-$4797; total 320 = 8 rows)
wipe_road_chunk2_loop
$917199 56 47staSCREEN_RAM_ROW15_COL00 + $fe,y; Fill road bytes 255..319 up to start sidewalk ($4798) ; x-ref: $9175
$917488dey
$9175d0 fabnewipe_road_chunk2_loop
$9177a9 01lda#ScreenWipeState.SCREEN_WIPE_DONE; Mark screen wipe complete ($01 = active gameplay)
$917985 77stazp_screen_wipe_state; Set screen wipe state to $01 (active gameplay)
$917B60rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Iterates over the active level's $00-terminated object list for scrolling
; lane zpa_0F and dispatches the renderer for each river alligator, river log,
; turtle group, or road vehicle.
;
; Inputs: zpa_0F = scrolling lane index (0..4 river, 5..8 road)
; zpa_AC = active level layout index (0..4, via load_lane_cfg_header)
; zpa_78 = lane fine horizontal scroll phase (0..3)
; zpf_8B[0..8] = per-lane coarse scroll offset (0..49)
; zpa_B1, zpf_9D[0..4] = turtle animation phase state (for type $02)
; Outputs: zpa_64 = zpa_0F; zpa_04/$05 = active level lane config table pointer
; zpa_0D = lane object type ($01 = log/gator, $02 = turtles, $03 = road)
; zpa_0E = object size/count; zpa_0C = last object's base column byte
; zpa_50 = road vehicle type index 0..3 (zpa_0F - 5, road lanes only)
; zpa_22, zpa_23 = saved/restored Y and X; renderer scratch ZP modified
; A = $00 (Z = 1), X = (zpa_AC * 2) + 1, Y = offset of $00 sentinel
; Side Effects: Erases vacated trailing columns and writes 2-row pre-shifted
; object tiles into VIC Bank 1 Screen RAM ($4400)
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$917Ca5 0fdraw_lane_objectsldazp_scroll_lane_idx; Pass active lane index (0..4 river, 5..8 road) to load_lane_cfg_header ; x-ref: $9387
$917E85 64stazp_lane_cfg_idx; Set target lane index (0..8) for load_lane_cfg_header
$918020 4c 9djsrload_lane_cfg_header; Load zpa_04/$05 cfg ptr, zpa_0D type, zpa_0E size; Y = lane*8 + 1
$9183c8draw_lane_obj_loopiny; Advance Y to next object column byte (+2..+7) in 8-byte lane record ; x-ref: $91c5
$9184b1 04lda(zp_ptr_lane_cfg_lo),y; Read next object base-column/subtype byte (+2..+7) from active lane config table
$9186d0 01bnedispatch_lane_obj; Non-zero entry = active lane object; $00 = end-of-lane sentinel
$918860rts
$918985 0cdispatch_lane_objstazp_lane_obj_col; Store object byte (bits 0..6 = base col 1..48, bit 7 = subtype flag) ; x-ref: $9186
$918Ba5 0dldazp_lane_obj_type; Load lane object type ($01=log/gator, $02=turtles, $03=vehicle)
$918D86 23stxzp_saved_x; Save X index across lane object draw subroutine
$918F84 22styzp_saved_y; Save lane config object offset Y (+2..+7) across draw subroutine
$9191c9 01cmp#LaneObjType.LANE_OBJ_LOG_OR_GATOR; Type $01: river log or river alligator lane
$9193d0 18bnecheck_lane_turtle_obj
$9195a5 0cldazp_lane_obj_col
$919729 80and#$80; Bit 7 = 1 selects a 10-column river alligator instead of a log
$9199f0 0cbeqdraw_lane_log_obj
$919Ba5 0cldazp_lane_obj_col
$919D29 7fand#$7f; Clear bit 7 subtype flag to leave 7-bit base column (1..48)
$919F85 0cstazp_lane_obj_col; Store stripped 7-bit base column (1..48) for river alligator draw
$91A120 55 92jsrdraw_river_alligator; Erase trailing water column and render 2-row river alligator
$91A44c c1 91jmprestore_lane_cfg_idx
$91A720 12 92draw_lane_log_objjsrdraw_river_log; Erase trailing water column and render 2-row river log ; x-ref: $9199
$91AA4c c1 91jmprestore_lane_cfg_idx
check_lane_turtle_obj
$91ADc9 02cmp#LaneObjType.LANE_OBJ_TURTLES; Type $02: swimming or diving turtle group lane ; x-ref: $9193
$91AFd0 06bnedraw_lane_vehicle_obj
$91B120 e9 92jsrdraw_lane_turtle_group; Erase trailing water column and render turtle group (bit 7 = diving)
$91B44c c1 91jmprestore_lane_cfg_idx
draw_lane_vehicle_obj
$91B738sec; x-ref: $91af
$91B8a5 0fldazp_scroll_lane_idx; Load active road lane index (5..8)
$91BAe9 05sbc#$05; Type $03 (road lanes 5..8): map lane to vehicle type index 0..3
$91BC85 50stazp_vehicle_type_idx; Store road vehicle type index (0..3 for lanes 5..8)
$91BE20 ca 92jsrdraw_road_vehicle; Erase trailing pavement column and render 2-row road vehicle
restore_lane_cfg_idx
$91C1a4 22ldyzp_saved_y; Restore lane config object offset Y (+2..+7) for next object ; x-ref: $91a4, $91aa, $91b4
$91C3a6 23ldxzp_saved_x; Restore saved X index
$91C54c 83 91jmpdraw_lane_obj_loop
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Initializes the top and bottom Screen RAM row pointers for scrolling lane
; zpa_0F, computes the current lane object's scrolled column anchor (zpa_2D),
; and erases its vacated 1-column trailing edge when visible on screen.
;
; Inputs: zpa_0F = lane index (0..4 river, 5..8 road);
; zpa_0C = object offset byte (bits 0..6 = base col 1..48, bit 7 = flag);
; zpf_8B[0..8] = per-lane coarse scroll offset (0..49)
; Outputs: zpa_15/$16 = lane top Screen RAM row pointer;
; zpa_17/$18 = lane bottom Screen RAM row pointer (top + 40);
; Y, zpa_2D = unwrapped object anchor column; X = lane index; A clobbered
; Side Effects: Writes background tile $07 (river water) or $11 (road pavement)
; to both rows of the vacated trailing column in Screen RAM ($4400)
; when column < 40
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
prep_lane_obj_and_erase_trail
$91C8a5 0fldazp_scroll_lane_idx; Lane index (0..8: 0..4 river, 5..8 road) ; x-ref: $9212, $9255, $92ca, $9328
$91CA0aasla; Word offset X = lane * 2 into lane_screen_row_ptr_tbl
$91CBaatax
$91CCbd 09 80ldalane_screen_row_ptr_tbl,x; Load lane top Screen RAM ($4400) row pointer low byte; River lanes 0..4 top rows ($4478..$45B8, rows 3/5/7/9/11)
$91CF18clc
$91D085 15stazp_ptr_lane_top_lo; Store Screen RAM ($4400) pointer low byte for lane top row
$91D269 28adc#$28; Add 40 columns ($28) to reach lane bottom row
$91D485 17stazp_ptr_lane_bot_lo; Store Screen RAM ($4400) pointer low byte for lane bottom row (+40)
$91D6e8inx
$91D7bd 09 80ldalane_screen_row_ptr_tbl,x; Load lane top Screen RAM ($4400) row pointer high byte; River lanes 0..4 top rows ($4478..$45B8, rows 3/5/7/9/11)
$91DA85 16stazp_ptr_lane_top_hi; Store Screen RAM ($4400) pointer high byte for lane top row
$91DC69 00adc#$00
$91DE85 18stazp_ptr_lane_bot_hi; Store Screen RAM ($4400) pointer high byte for lane bottom row
$91E0a5 0cldazp_lane_obj_col; Load lane object byte (bits 0..6 = base col 1..48, bit 7 = subtype)
$91E229 7fand#$7f; Strip bit 7 subtype flag (alligator/diving turtle) -> base col 1..48
$91E418clc
$91E5a6 0fldxzp_scroll_lane_idx; X = active scrolling lane index (0..8)
$91E775 8badczp_lane_coarse_col,x; Add lane X coarse scroll column offset (0..49) -> unwrapped col 1..97 (C=0)
$91E985 2dstazp_scratch_byte; Save object anchor column for caller
$91EBbc 1b 81ldylane_scroll_dir_tbl,x; Check lane scroll direction (0 = left, 1 = right)
$91EEf0 06beqtrail_col_scroll_left; Scrolling left: trailing edge is at anchor + 1
$91F038sec
$91F1e9 01sbc#$01; Scrolling right: trailing edge is at anchor - 1 (0..96)
$91F34c f8 91jmpwrap_trail_col_mod50
trail_col_scroll_left
$91F669 01adc#$01; C=0 from $91E7: trailing right column = anchor + 1 (2..98) ; x-ref: $91ee
wrap_trail_col_mod50
$91F8c9 32cmp#$32; Wrap trailing column modulo 50 ($32 virtual track width) ; x-ref: $91f3
$91FA90 02bcccheck_trail_col_visible
$91FCe9 32sbc#$32
check_trail_col_visible
$91FEa8tay; x-ref: $91fa
$91FFc0 28cpy#$28; Is wrapped column within visible 40-column screen (0..39)?
$920110 0cbplload_obj_anchor_col_rts; Skip erase when column is in offscreen wrap zone (40..49)
$9203a9 07lda#$07; Default erase tile = $07 (empty river water)
$9205e0 05cpx#$05; Lanes 0..4 are river; lanes 5..8 are road
$920730 02bmierase_trail_col_rows
$9209a9 11lda#$11; Road lane: use $11 (empty road pavement tile)
erase_trail_col_rows
$920B91 15sta(zp_ptr_lane_top_lo),y; Erase trailing column on top character row ; x-ref: $9207
$920D91 17sta(zp_ptr_lane_bot_lo),y; Erase trailing column on bottom character row in Screen RAM ($4400)
load_obj_anchor_col_rts
$920Fa4 2dldyzp_scratch_byte; Return Y = unwrapped object anchor column for tile drawing ; x-ref: $9201
$921160rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Renders a 2-row river log into Screen RAM ($4400) at its current scroll phase,
; erasing its vacated trailing column and drawing a 2-column left cap, zpa_0E
; repeating middle body columns, and a 3-column right cap (wrapped modulo 50).
;
; Inputs: zpa_0F = river lane index (0..4)
; zpa_0C = log base column offset (1..48)
; zpa_0E = repeatable middle-section column count (from lane config)
; zpa_78 = fine horizontal scroll phase (0..3)
; zpf_8B[0..4] = per-lane coarse scroll offset (0..49)
; Outputs: zpa_15/zpa_16 = Screen RAM ($4400) pointer to lane top row
; zpa_17/zpa_18 = Screen RAM ($4400) pointer to lane bottom row (+40)
; zpa_0B = $01, zpa_14 = $00, zpa_2B = zpa_0E
; zpa_19 = tile_base_log[zpa_78] + 12
; Y = virtual column index stepped one column past the log's right cap
; A = $01, X = zpa_78
; Side Effects: Erases vacated trailing column ($07 water) and writes visible
; columns (0..39) of both log rows into VIC Bank 1 Screen RAM ($4400)
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$921220 c8 91draw_river_logjsrprep_lane_obj_and_erase_trail; Set up lane row pointers, erase trailing col, Y = left anchor ; x-ref: $91a7
$9215a9 01lda#TileHorizDir.TILE_DIR_RIGHT; Step rightward (INY) across log columns
$921785 0bstazp_tile_horiz_dir; Step right ($01 = INY) in draw_lane_tile_span
$9219a6 78ldxzp_lane_fine_phase; X = lane fine horizontal scroll phase (0..3)
$921Bbd c5 80ldatile_base_log,x; Pre-shifted base tile ID for log at phase X
$921E85 19stazp_lane_tile_id; Initialize active lane top-row tile ID for log left cap
$9220a9 02lda#$02; Span width = 2 columns for log left cap (tiles +0..+3)
$922285 14stazp_tile_span_cols; Set 2-column span countdown for log left cap
$922420 98 92jsrdraw_lane_tile_span; Draw 2-column left cap; advances zpa_19 to body tile (+4)
$9227a9 00lda#$00
$922985 2bstazp_tile_loop_cnt; Initialize middle body column counter = 0
$922B98log_mid_col_looptya; x-ref: $9247
$922Cc9 32cmp#$32; Wrap virtual column modulo 50 ($32 lane ring width)
$922E90 03bcclog_mid_col_clip
$9230e9 32sbc#$32; Y >= 50 (Carry = 1): subtract 50
$9232a8tay
$9233c0 28log_mid_col_clipcpy#$28; Clip against 40 visible screen columns ($28) ; x-ref: $922e
$923510 09bpllog_mid_col_next; Skip Screen RAM write in off-screen wrap zone (40..49)
$9237a5 19ldazp_lane_tile_id; Top-row repeating log bark tile (base + 4)
$923991 15sta(zp_ptr_lane_top_lo),y; Write lane top character row in Screen RAM ($4400)
$923B18clc
$923C69 01adc#$01; Paired bottom-row log bark tile (base + 5)
$923E91 17sta(zp_ptr_lane_bot_lo),y; Write lane bottom character row (+40 bytes) in Screen RAM ($4400)
$9240e6 2blog_mid_col_nextinczp_tile_loop_cnt; Advance middle body column counter and virtual column Y ; x-ref: $9235
$9242c8iny
$9243a5 2bldazp_tile_loop_cnt; Check repeated log body columns drawn
$9245c5 0ecmpzp_lane_obj_size; Rendered all zp_lane_obj_size middle body columns?
$9247d0 e2bnelog_mid_col_loop
$9249e6 19inczp_lane_tile_id; Advance lane tile ID by +2 past body pair to right cap (+6)
$924Be6 19inczp_lane_tile_id
$924Da9 03lda#$03; Span width = 3 columns for log right cap (tiles +6..+11)
$924F85 14stazp_tile_span_cols; Set 3-column span countdown for log right cap
$925120 98 92jsrdraw_lane_tile_span; Draw 3-column right cap across both lane rows
$925460rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Erases the vacated trailing column and renders a 10-column (2-row) river
; alligator across the 50-column virtual river ring: 3 tail columns, 4 repeated
; middle body columns, and 3 head/jaw columns, using pre-shifted tiles for the
; lane's fine scroll phase.
;
; Inputs: zpa_0F = river lane index (0..4)
; zpa_0C = object base column offset (1..48, bit 7 cleared by caller)
; zpf_8B[zpa_0F] = lane coarse column scroll offset (0..49)
; zpa_78 = lane fine horizontal scroll phase (0..3)
; Outputs: zpa_15/$16 = lane top Screen RAM row pointer ($4400)
; zpa_17/$18 = lane bottom Screen RAM row pointer (top + 40)
; zpa_2D = unwrapped object anchor column
; Y = virtual column index stepped one column past the 10-column gator
; zpa_19 = advanced by +14 ($0E) past the alligator tile set
; zpa_0B = $01, zpa_14 = $00, zpa_2B = $04, A = $01, X = zpa_78
; Side Effects: Erases trailing water column ($07) and writes visible columns
; (0..39) of the 2-row alligator into VIC Bank 1 Screen RAM ($4400)
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
draw_river_alligator
$925520 c8 91jsrprep_lane_obj_and_erase_trail; Set lane row ptrs, erase trail col, Y = anchor col ; x-ref: $91a1
$9258a9 01lda#TileHorizDir.TILE_DIR_RIGHT; Step direction = $01 (advance right / INY)
$925A85 0bstazp_tile_horiz_dir; Step right ($01 = INY) in draw_lane_tile_span
$925Ca6 78ldxzp_lane_fine_phase; X = lane fine horizontal scroll phase (0..3)
$925Ebd d1 80ldatile_base_alligator,x; Pre-shifted alligator base tile ($24/$F1/$D7/$BD)
$926185 19stazp_lane_tile_id; Initialize active lane top-row tile ID for alligator tail
$9263a9 03lda#$03; Left tail section width = 3 columns
$926585 14stazp_tile_span_cols; Set 3-column span countdown for alligator tail
$926720 98 92jsrdraw_lane_tile_span; Draw 3-col tail span (advances zpa_19 by +6)
$926Aa9 00lda#$00
$926C85 2bstazp_tile_loop_cnt; Reset repeated middle body column counter
$926E98gator_body_col_looptya; x-ref: $928a
$926Fc9 32cmp#$32; Wrap virtual column Y modulo 50 ($32)
$927190 03bccgator_body_clip_col
$9273e9 32sbc#$32
$9275a8tay
$9276c0 28gator_body_clip_colcpy#$28; Clip against 40 visible screen columns ($28) ; x-ref: $9271
$927810 09bplgator_body_next_col; Skip Screen RAM write for off-screen cols 40..49
$927Aa5 19ldazp_lane_tile_id; Top-row repeating body tile (base + 6)
$927C91 15sta(zp_ptr_lane_top_lo),y; Write top row in VIC Bank 1 Screen RAM ($4400)
$927E18clc
$927F69 01adc#$01; Bottom-row repeating body tile (base + 7)
$928191 17sta(zp_ptr_lane_bot_lo),y; Write bottom row (+40 bytes) in VIC Bank 1 Screen RAM ($4400)
$9283e6 2bgator_body_next_colinczp_tile_loop_cnt; Advance repeated alligator body column counter ; x-ref: $9278
$9285c8iny; Advance one column right
$9286a5 2bldazp_tile_loop_cnt; Check repeated alligator body columns drawn
$9288c9 04cmp#$04; Repeat middle body tile pair across 4 columns
$928Ad0 e2bnegator_body_col_loop
$928Ce6 19inczp_lane_tile_id; Advance lane tile ID by +2 to head/jaw tiles (base + 8)
$928Ee6 19inczp_lane_tile_id
$9290a9 03lda#$03; Right head/jaw section width = 3 columns
$929285 14stazp_tile_span_cols; Set 3-column span countdown for alligator head/jaws
$929420 98 92jsrdraw_lane_tile_span; Draw 3-col head/jaw span (completes 10-col gator)
$929760rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Draws a horizontal span of sequential 2-row character tile pairs across a
; scrolling 50-column river or road lane, wrapping column indices modulo 50
; ($32) and clipping off-screen columns 40..49 ($28..$31).
;
; Inputs: Y = starting virtual column index (-1..50, wrapped modulo $32)
; zpa_15/zpa_16 = Screen RAM ($4400) pointer to lane top row
; zpa_17/zpa_18 = Screen RAM ($4400) pointer to lane bottom row (+40)
; zpa_19 = initial top-row character code (bottom row uses zpa_19 + 1)
; zpa_14 = column width counter (> 0)
; zpa_0B = step direction ($00 = left / DEY, non-zero = right / INY)
; Outputs: Y = virtual column index stepped one column past the span
; zpa_19 = advanced by 2 * count to next sequential top-row tile code
; zpa_14 = $00, A = zpa_0B (X preserved)
; Side Effects: Writes visible columns (0..39) into VIC Bank 1 Screen RAM ($4400)
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$929898draw_lane_tile_spantya; A = current virtual column index Y ; x-ref: $9224, $9251, $9267, $9294, $92c7, ...
$929910 06bpltile_span_check_hi_wrap; If Y >= 0, check upper 50-column wrap bound
$929B18clc
$929C69 32adc#$32; Y < 0 (stepped left past 0): wrap modulo 50 ($32)
$929E4c a7 92jmptile_span_clip_and_draw
tile_span_check_hi_wrap
$92A1c9 32cmp#$32; Compare against 50-column ($32) virtual lane ring width ; x-ref: $9299
$92A390 02bcctile_span_clip_and_draw; Already within [0, 49]
$92A5e9 32sbc#$32; Y >= 50 (Carry = 1): wrap modulo 50 ($32)
tile_span_clip_and_draw
$92A7a8tay; Update wrapped virtual column Y (0..49) ; x-ref: $929e, $92a3
$92A8c0 28cpy#$28; Clip against 40 visible screen columns ($28)
$92AA10 0cbpltile_span_next_col; Columns 40..49 ($28..$31) are off-screen: skip write
$92ACa5 19ldazp_lane_tile_id; Load top-row character code for this column
$92AE91 15sta(zp_ptr_lane_top_lo),y; Write lane top character row in Screen RAM ($4400)
$92B0e6 19inczp_lane_tile_id; Select paired bottom-row character code (top + 1)
$92B2a5 19ldazp_lane_tile_id; Load paired bottom-row character code for this column
$92B491 17sta(zp_ptr_lane_bot_lo),y; Write lane bottom character row (+40 bytes) in Screen RAM ($4400)
$92B6c6 19deczp_lane_tile_id; Restore base top-row character code
$92B8e6 19tile_span_next_colinczp_lane_tile_id; Advance tile index by +2 to next column pair ; x-ref: $92aa
$92BAe6 19inczp_lane_tile_id
$92BCa5 0bldazp_tile_horiz_dir; Horizontal step direction (0 = left, non-zero = right)
$92BEf0 04beqtile_span_step_left
$92C0c8iny; Step right to next column
$92C14c c5 92jmptile_span_dec_count
$92C488tile_span_step_leftdey; Step left to previous column ; x-ref: $92be
$92C5c6 14tile_span_dec_countdeczp_tile_span_cols; Decrement remaining column count in span ; x-ref: $92c1
$92C7d0 cfbnedraw_lane_tile_span; Loop until all span columns are processed
$92C960rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Erases the vacated trailing column and draws a 2-row road vehicle (truck,
; racecar, bulldozer, or car) across a scrolling 50-column road lane using its
; pre-shifted horizontal scroll phase tiles.
;
; Inputs: zpa_0F = road lane index (5..8);
; zpa_50 = road vehicle type index (0..3, i.e. zpa_0F - 5);
; zpa_78 = fine horizontal scroll phase (0..3);
; zpa_0C = vehicle base column offset (1..48);
; zpa_0E = vehicle column width (9 for truck, 5 for cars/bulldozer);
; zpf_8B[5..8] = per-lane coarse scroll offset (0..49)
; Outputs: zpa_15/$16 = lane top Screen RAM row pointer;
; zpa_17/$18 = lane bottom Screen RAM row pointer (top + 40);
; zpa_19 = next tile code past vehicle span; zpa_14 = $00;
; zpa_0B = lane scroll direction ($00 = left, $01 = right);
; zpa_2D = unwrapped anchor column;
; A = zpa_0B, X = zpa_0F, Y = column past vehicle span
; Side Effects: Erases vacated trailing column with pavement tile ($11) and
; writes visible vehicle tile pairs (columns 0..39) into VIC
; Bank 1 Screen RAM ($4400)
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$92CA20 c8 91draw_road_vehiclejsrprep_lane_obj_and_erase_trail; Set lane row ptrs, erase vacated trail col, Y = anchor col ; x-ref: $91be
$92CDa5 50ldazp_vehicle_type_idx; Road vehicle type index (0..3 for lanes 5..8)
$92CF0aasla
$92D00aasla; zp_vehicle_type_idx * 4 (4 horizontal scroll phases per vehicle)
$92D118clc
$92D265 78adczp_lane_fine_phase; Add fine scroll phase (0..3) -> table offset 0..15
$92D4aatax
$92D5bd d5 80ldatile_base_road_vehicles,x; Look up pre-shifted starting top-row vehicle tile ID
$92D885 19stazp_lane_tile_id; Initial top-row character code for span draw
$92DAa5 0eldazp_lane_obj_size; Vehicle width in columns (9 = truck, 5 = car/dozer)
$92DC85 14stazp_tile_span_cols; Column count for draw_lane_tile_span
$92DEa6 0fldxzp_scroll_lane_idx; Road lane index (5..8)
$92E0bd 1b 81ldalane_scroll_dir_tbl,x; Column step direction ($00 = left, $01 = right)
$92E385 0bstazp_tile_horiz_dir; Configure horizontal step direction for span draw
$92E520 98 92jsrdraw_lane_tile_span; Render 2-row vehicle tile span into Screen RAM ($4400)
$92E860rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Computes the per-lane 12-step diving-turtle animation phase, selects the
; pre-shifted swimming, half-submerged, or underwater ripple tile strip, erases
; the vacated trailing column, and draws a group of turtles into Screen RAM.
;
; Inputs: zpa_0F = river lane index (0..4; turtle lanes are 1 and 4)
; zpa_0C = group config byte (bits 0..6 = base col 1..48, bit 7 = dive)
; zpa_0E = turtles per group (2 or 3)
; zpa_78 = lane fine horizontal scroll phase (0..3)
; zpa_B1 = global 30-frame turtle animation phase (0..11)
; zpf_9D[0..4] = per-lane phase offset (lane 1 = 8, others = 0)
; zpf_8B[0..8] = per-lane coarse scroll offset (0..49)
; Outputs: zpf_A2[zpa_0F], zpa_30 = lane dive phase (0..11; phase 9 drowns frog)
; zpa_27 = selected pre-shifted turtle base tile ID
; zpa_15/$16, zpa_17/$18 = lane top/bottom Screen RAM row pointers
; zpa_2D = unwrapped group anchor col; zpa_19 = zpa_27 + 8
; zpa_0B = $00, zpa_14 = $00, zpa_2B = zpa_0E
; A = zpa_0E, X = zpa_0F, Y = column one step left of drawn group
; Side Effects: Erases trailing water column ($07) and writes zpa_0E * 4 visible
; 2-row turtle columns (0..39) into VIC Bank 1 Screen RAM ($4400)
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
draw_lane_turtle_group
$92E9a9 00lda#$00; x-ref: $91b1
$92EB85 0bstazp_tile_horiz_dir; Step leftward (DEY) in draw_lane_tile_span
$92ED85 2bstazp_tile_loop_cnt; Turtle-in-group counter = 0
$92EFa6 0fldxzp_scroll_lane_idx; X = river lane index (0..4)
$92F1b5 9dldazp_lane_turtle_phase_ofs,x; Per-lane phase offset (lane 1 = 8 to desync dive cycles, others = 0)
$92F318clc
$92F465 b1adczp_turtle_anim_phase; Add global 30-frame turtle animation phase (0..11)
$92F6c9 0ccmp#$0c; Wrap lane animation phase modulo 12 ($0C)
$92F830 03bmistore_lane_turtle_phase
$92FA38sec
$92FBe9 0csbc#$0c
store_lane_turtle_phase
$92FD95 a2stazp_lane_turtle_dive_phase,x; Store per-river-lane dive phase (0..11 in $A2..$A6; phase 9 drowns frog at $9941) ; x-ref: $92f8
$92FF85 30stazp_turtle_dive_phase; Cache active lane turtle dive phase (0..11) for tile selection
$9301a6 78ldxzp_lane_fine_phase; X = lane fine horizontal pixel scroll phase (0..3)
$9303a4 0cldyzp_lane_obj_col; Check bit 7 diving-turtle subtype flag in zp_lane_obj_col
$9305c0 80cpy#$80; zpa_0C < $80 sets N=1 -> non-diving turtle group always swims
$930730 1abmiuse_turtle_swim_tiles
$9309a5 30ldazp_turtle_dive_phase; Reload cached lane turtle dive phase (0..11)
$930Bc9 07cmp#$07; Phases 0..6: swimming on surface (safe)
$930D30 14bmiuse_turtle_swim_tiles
$930Fc9 09cmp#$09; Phases 7..8: submerging (dive stage 1, still rideable)
$931130 04bmiuse_turtle_dive1_tiles
$9313c9 0acmp#$0a; Phase 9: fully submerged ripples (dive stage 2, lethal); 10..11 resurface
$931530 06bmiuse_turtle_dive2_tiles
use_turtle_dive1_tiles
$9317bd c9 80ldatile_base_turtle_dive1,x; Half-submerged turtle tile strip (phases 7..8 and resurfacing 10..11) ; x-ref: $9311
$931A4c 26 93jmpprep_and_draw_turtles
use_turtle_dive2_tiles
$931Dbd cd 80ldatile_base_turtle_dive2,x; Underwater water-ripple tile strip (phase 9 only) ; x-ref: $9315
$93204c 26 93jmpprep_and_draw_turtles
use_turtle_swim_tiles
$9323bd c1 80ldatile_base_turtle_swim,x; Surface swimming turtle tile strip (non-diving or phases 0..6) ; x-ref: $9307, $930d
prep_and_draw_turtles
$932685 27stazp_tmp_tile_or_ticks; Save selected base top-row tile ID for all turtles in group ; x-ref: $931a, $9320
$932820 c8 91jsrprep_lane_obj_and_erase_trail; Set lane row ptrs, erase right trail col, load Y = right anchor col
draw_turtle_group_loop
$932Ba5 27ldazp_tmp_tile_or_ticks; Reload saved base top-row tile ID for next turtle in group ; x-ref: $933c
$932D85 19stazp_lane_tile_id; Reset lane tile ID to turtle's first column top-row tile ID
$932Fa9 04lda#$04
$933185 14stazp_tile_span_cols; Each turtle spans 4 character columns (3 body + 1 gap/shift col)
$933320 98 92jsrdraw_lane_tile_span; Draw 4-column 2-row turtle leftward, advancing Y by -4 (mod 50)
$9336e6 2binczp_tile_loop_cnt; Advance turtle-in-group loop counter
$9338a5 2bldazp_tile_loop_cnt; Check turtles drawn in group
$933Ac5 0ecmpzp_lane_obj_size; All zp_lane_obj_size turtles in group drawn?
$933Cd0 edbnedraw_turtle_group_loop
$933E60rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Ticks the active river or road lane at round-robin cursor zpa_0F (8 down to 0,
; called 3 times per frame): when zpf_32,X expires, reloads its speed profile,
; advances fine/coarse scroll state, redraws lane tiles, steps river companion/
; hazard sprites (lanes 0, 2, 3), and carries Sprite 0 horizontally on river lanes.
;
; Inputs: zpa_0F = active lane cursor (0..4 river, 5..8 road)
; zpf_32[0..8] = per-lane frame delay countdown (1..2 ticks)
; zpf_94[0..8] = per-lane fine scroll phase (0..3 multicolor px)
; zpf_8B[0..8] = per-lane coarse scroll offset (0..49 columns)
; lane_scroll_dir_tbl[0..8] = horizontal direction ($00 = left, $01 = right)
; zpa_4A = player frog row, zpa_79 = hop active flag, zpa_31 = hop dir,
; zpa_45 = hop pixel counter (plus globals read by sub-calls)
; Outputs: zpa_0F decremented (wraps $00 -> $08 via $FF -> X = $08);
; on expired zpf_32,X: reloads zpf_32,X, clamps effective step zpf_3B,X
; to (4 - old zpf_94,X), updates zpf_94,X (0..3) and zpf_8B,X (0..49),
; sets zpa_78 = zpf_94,X; preserves zpa_45 via zpa_4C; zpa_51 = $00 on
; frog drift; A, X, Y, N, Z, C modified
; Side Effects: Redraws lane objects in Screen RAM ($4400) via draw_lane_objects;
; steps VIC-II Sprite 1 ($D002/$D010, Lady Frog on lane 3), Sprite 2
; ($D004/$D010, river alligator jaws on lane 0), Sprite 3 & snake log
; bounds (lane 2), and Sprite 0 ($D000/$D010, player frog river carry);
; modifies ZP pointer/scratch workspace (zpa_67..zpa_6D, zpa_23, etc.)
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
update_scrolling_lane
$933Fa6 0fldxzp_scroll_lane_idx; X = active lane cursor (8 down to 0: 5..8 road, 0..4 river) ; x-ref: $8ef5, $8ef8, $8efb
$9341d6 32deczp_lane_scroll_delay,x; Decrement lane X scroll-delay countdown (1..2 lane ticks); scroll on 0
$9343f0 03beqadvance_lane_scroll; Countdown expired -> scroll and redraw lane X
$93454c fe 93jmpadvance_next_lane_cursor; Still waiting -> advance cursor zpa_0F to next lane
$934820 e0 99advance_lane_scrolljsrload_lane_speed_profile; Reload lane X delay (zpf_32,X) and nominal step (zpf_3B,X) ; x-ref: $9343
$934Ba9 04lda#$04; Compute remaining quarter-tile phases (4 - zpf_94,X) to column wrap
$934D38sec
$934Ef5 94sbczp_lane_fine_scroll,x; Remaining quarter-tile steps (1..4) to next column wrap
$9350d5 3bcmpzp_lane_scroll_step,x; Compare (4 - phase) against nominal step (1, 2, or 4 multicolor px)
$935230 02bmistore_effective_lane_step; Clamp step if nominal step would overshoot fine phase 4
$9354b5 3bldazp_lane_scroll_step,x; Use unclamped nominal lane step (1, 2, or 4 multicolor px)
store_effective_lane_step
$935695 3bstazp_lane_scroll_step,x; Commit effective multicolor-px step (1..4) for tiles and sprites ; x-ref: $9352
$935818clc
$935975 94adczp_lane_fine_scroll,x; Add current lane fine scroll phase (0..3 mc-px) to step
$935B95 94stazp_lane_fine_scroll,x; Advance lane X fine scroll phase (now 1..4)
$935Dc9 04cmp#$04; Reached 4 quarter-tile steps (1 full character column)?
$935F30 22bmirender_scrolled_lane; Phases 1..3 stay within current coarse column
$9361a9 00lda#$00; Wrap fine scroll phase 4 -> 0 on coarse column boundary
$936395 94stazp_lane_fine_scroll,x; Reset lane X fine scroll phase to 0 on column wrap
$9365bd 1b 81ldalane_scroll_dir_tbl,x; Check lane X horizontal direction ($00 = left, $01 = right)
$9368d0 0cbneinc_lane_coarse_col
$936Ab5 8bldazp_lane_coarse_col,x; Scrolling left: decrement lane X coarse column offset (0..49)
$936C38sec
$936De9 01sbc#$01
$936F10 10bplstore_lane_coarse_col
$9371a9 31lda#$31; Wrap coarse column underflow (-1) to 49 ($31) in 50-col ring
$93734c 81 93jmpstore_lane_coarse_col
$9376b5 8binc_lane_coarse_colldazp_lane_coarse_col,x; Scrolling right: increment lane X coarse column offset (0..49) ; x-ref: $9368
$937818clc
$937969 01adc#$01
$937Bc9 32cmp#$32; Reached end of 50-column ($32) virtual lane ring?
$937Dd0 02bnestore_lane_coarse_col
$937Fa9 00lda#$00; Wrap coarse column 50 -> 0
store_lane_coarse_col
$938195 8bstazp_lane_coarse_col,x; Save updated lane X coarse column offset (0..49) ; x-ref: $936f, $9373, $937d
render_scrolled_lane
$9383b5 94ldazp_lane_fine_scroll,x; Pass lane X fine scroll phase (0..3) to draw_lane_objects ; x-ref: $935f
$938585 78stazp_lane_fine_phase; Cache active lane fine scroll phase (0..3) for object tile renderers
$938720 7c 91jsrdraw_lane_objects; Erase trailing edges and redraw all objects in lane zpa_0F
$938Aa6 0fldxzp_scroll_lane_idx; Reload lane index X (0..8) clobbered by draw_lane_objects
$938Ce0 05cpx#$05; Lanes 5..8 are road lanes (no river sprites or frog drift)
$938E10 6ebpladvance_next_lane_cursor
$9390a9 10lda#<$d010; Point zp_ptr_spr_x_msb_lo/hi to VIC-II $D010 (Sprite X-MSB register)
$939285 69stazp_ptr_spr_x_msb_lo
$9394a9 d0lda#>$d010
$939685 6astazp_ptr_spr_x_msb_hi
$9398e0 03cpx#$03; River lane 3: step Sprite 1 (Lady Frog on log)
$939Ad0 0fbnecheck_lane0_gator_sprite
$939Ca9 02lda#<$d002; Point zpa_67/zpa_68 to VIC-II $D002 (Sprite 1 X low byte)
$939E85 67stazp_ptr_spr_x_lo; Store Sprite 1 X ($D002) pointer low byte
$93A0a9 d0lda#>$d002
$93A285 68stazp_ptr_spr_x_hi; Store Sprite 1 X ($D002) pointer high byte
$93A4a9 02lda#$02; Sprite 1 X-MSB bitmask ($02 = bit 1)
$93A685 6bstazp_spr_x_msb_mask; Pass Sprite 1 X-MSB mask ($02) to step_lane_sprite_x
$93A820 ac 9cjsrstep_lane_sprite_x; Advance Lady Frog (Sprite 1) 9-bit X along river lane 3
check_lane0_gator_sprite
$93ABe0 00cpx#$00; Top river lane 0: step Sprite 2 (river alligator jaws) ; x-ref: $939a
$93ADd0 0fbnecheck_lane2_snake_log
$93AFa9 04lda#<$d004; Point zpa_67/zpa_68 to VIC-II $D004 (Sprite 2 X low byte)
$93B185 67stazp_ptr_spr_x_lo; Store Sprite 2 X ($D004) pointer low byte
$93B3a9 d0lda#>$d004
$93B585 68stazp_ptr_spr_x_hi; Store Sprite 2 X ($D004) pointer high byte
$93B7a9 04lda#$04; Sprite 2 X-MSB bitmask ($04 = bit 2)
$93B985 6bstazp_spr_x_msb_mask; Pass Sprite 2 X-MSB mask ($04) to step_lane_sprite_x
$93BB20 ac 9cjsrstep_lane_sprite_x; Advance river alligator jaws (Sprite 2) 9-bit X along lane 0
check_lane2_snake_log
$93BEe0 02cpx#$02; River lane 2: step snake log X bounds and Sprite 3 ; x-ref: $93ad
$93C0d0 03bnecheck_frog_river_drift
$93C220 cb 9ajsrupdate_snake_log_and_spawn; Advance tracked log bounds, carry snake on log, check spawn
check_frog_river_drift
$93C5e4 4acpxzp_frog_row; Is player frog (Sprite 0) currently on river row X (0..4)? ; x-ref: $93c0
$93C7d0 35bneadvance_next_lane_cursor
$93C9a5 79ldazp_frog_hop_active; Check if player frog is mid-hop (zpa_79 != 0)
$93CBf0 06beqcarry_frog_with_river_lane; Idle on river lane X -> carry frog horizontally with lane
$93CDa5 31ldazp_frog_hop_dir; Read active frog hop direction bitmask
$93CF29 03and#$03; Test vertical hop bits ($01 = UP, $02 = DOWN); L/R hops still drift
$93D1d0 2bbneadvance_next_lane_cursor; Hopping vertically between rows -> skip horizontal river drift
carry_frog_with_river_lane
$93D3a5 45ldazp_frog_hop_px_cnt; Preserve frog's real hop pixel counter ($FF idle, or L/R hop step) ; x-ref: $93cb
$93D585 4cstazp_saved_hop_px_cnt; Save zp_frog_hop_px_cnt across river-drift step loop
$93D7b5 3bldazp_lane_scroll_step,x; Convert lane step (1..4 multicolor px) to hi-res pixels (2..8)
$93D90aasla
$93DA85 51stazp_frog_drift_px_cnt; Pixel loop counter = hi-res pixels (2..8) to carry Sprite 0
$93DCbd 1b 81ldalane_scroll_dir_tbl,x; Carry frog right ($01) or left ($00) to match river lane X
$93DFf0 0ebeqdrift_frog_left_loop
drift_frog_right_loop
$93E1a9 02lda#$02; Dummy hop counter $02 prevents DEC zpa_45 from ending hop ; x-ref: $93ea
$93E385 45stazp_frog_hop_px_cnt; Set dummy counter ($02) for 1-px rightward river drift step
$93E520 8c 8fjsrfrog_hop_step_right; Step Sprite 0 right 1 px (clamped at right border $0147)
$93E8c6 51deczp_frog_drift_px_cnt; Count down remaining rightward river drift pixels
$93EAd0 f5bnedrift_frog_right_loop
$93EC4c fa 93jmprestore_frog_hop_counter
drift_frog_left_loop
$93EFa9 02lda#$02; Dummy hop counter $02 prevents DEC zpa_45 from ending hop ; x-ref: $93df, $93f8
$93F185 45stazp_frog_hop_px_cnt; Set dummy counter ($02) for 1-px leftward river drift step
$93F320 56 8fjsrfrog_hop_step_left; Step Sprite 0 left 1 px (clamped at left border $0011)
$93F6c6 51deczp_frog_drift_px_cnt; Count down remaining leftward river drift pixels
$93F8d0 f5bnedrift_frog_left_loop
restore_frog_hop_counter
$93FAa5 4cldazp_saved_hop_px_cnt; Restore frog's true hop pixel counter ($FF or active L/R step) ; x-ref: $93ec
$93FC85 45stazp_frog_hop_px_cnt; Restore saved frog hop pixel counter after river drift
advance_next_lane_cursor
$93FEc6 0fdeczp_scroll_lane_idx; Advance round-robin lane cursor downward (8 -> ... -> 0 -> -1) ; x-ref: $9345, $938e, $93c7, $93d1
$940010 04bplupdate_scrolling_lane_rts
$9402a2 08ldx#$08; Wrap lane cursor past 0 ($FF) back to bottom road lane 8
$940486 0fstxzp_scroll_lane_idx; Reset round-robin scrolling lane cursor to road lane 8
update_scrolling_lane_rts
$940660rts; x-ref: $9400
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Draws an empty 3x2 home bay at index zpa_49 (0..4) on Screen RAM ($4400) rows 1-2 and Color RAM ($D800) rows 1-2, placing top-arch hedge tiles ($34-$36), bottom blank water tiles ($5D), and multicolor green ($0D) attributes.
;
; Inputs: zpa_49 = home bay index (0..4)
; Outputs: A = $5D, Y = (zpa_49 * 8) + 6, zpa_26 = $00, zpa_4E = $37 (Z = 1, N = 0)
; Side Effects: Writes 3x2 character cells in Screen RAM ($4428,Y / $4450,Y) and Color RAM ($D828,Y / $D850,Y); clobbers A, Y, zpa_26, zpa_4E
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$9407a5 49draw_empty_home_bayldazp_home_bay_idx; Home bay index (0..4) ; x-ref: $8cf6, $8d4e, $913e
$94090aasla
$940A0aasla
$940B0aasla; A = bay_index * 8 (8-column center-to-center bay stride)
$940Ca8tay
$940Dc8iny
$940Ec8iny
$940Fc8iny; Y = (bay_index * 8) + 3 (left column: 3, 11, 19, 27, or 35)
$9410a9 03lda#$03
$941285 26stazp_bay_col_cnt; Loop counter = 3 columns per home bay
$9414a9 34lda#$34
$941685 4estazp_bay_tile_id; Starting top-row empty-bay arch tile ($34..$36)
draw_empty_bay_col_loop
$9418a9 0dlda#$0d; Color nybble $0D = multicolor ($08) + green ($05) ; x-ref: $942f
$941A99 28 d8staCOLOR_RAM + 40,y; Set Color RAM row 1 (home bay top row)
$941D99 50 d8staCOLOR_RAM + 80,y; Set Color RAM row 2 (home bay bottom row)
$9420a5 4eldazp_bay_tile_id; Load current empty-bay top-row arch tile ($34..$36)
$942299 28 44staSCREEN_RAM + 40,y; Write top-row arch tile ($34..$36) to Screen RAM row 1
$9425a9 5dlda#$5d
$942799 50 44staSCREEN_RAM + 80,y; Write blank water tile ($5D) to Screen RAM row 2
$942Ae6 4einczp_bay_tile_id; Advance top-row arch tile ($34 -> $35 -> $36)
$942Cc8iny
$942Dc6 26deczp_bay_col_cnt; Count down remaining home bay columns (3 -> 0)
$942Fd0 e7bnedraw_empty_bay_col_loop; Repeat across all 3 bay columns
$943160rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Draws a 3x2 character graphic (landed frog, bonus fly, or alligator) in home
; bay zpa_49 (0..4) across Screen RAM ($4400) rows 1-2 and Color RAM ($D800)
; rows 1-2 using 6 sequential column-major tiles from zpa_4E and color zpa_4D.
;
; Inputs: zpa_49 = home bay index (0..4)
; zpa_4D = Color RAM nybble ($05 hires green frog, $0D multicolor green)
; zpa_4E = base tile screencode ($37 frog, $3D fly, $43/$49 alligator)
; Outputs: A = initial zpa_4E + 5, Y = (zpa_49 * 8) + 6, zpa_26 = $00,
; zpa_4E = initial zpa_4E + 6, X preserved (Z = 1, N = 0, C = 0)
; Side Effects: Writes 3x2 cells in Screen RAM ($4400 + 40/80,Y) and Color RAM
; ($D800 + 40/80,Y); clobbers A, Y, zpa_26, zpa_4E
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$9432a9 03draw_home_bay_tileslda#$03; x-ref: $8cdc, $8d14, $8d3c, $9138, $9148, ...
$943485 26stazp_bay_col_cnt; Loop counter = 3 columns per home bay
$9436a5 49ldazp_home_bay_idx; Home bay index (0..4)
$94380aasla
$94390aasla
$943A0aasla; A = bay_index * 8 (8-column center-to-center bay stride)
$943Ba8tay
$943Cc8iny
$943Dc8iny
$943Ec8iny; Y = (bay_index * 8) + 3 (left column: 3, 11, 19, 27, or 35)
draw_bay_tiles_col_loop
$943Fa5 4dldazp_home_bay_color; Color nybble ($05 hires green frog, $0D multicolor green fly/gator) ; x-ref: $9458
$944199 28 d8staCOLOR_RAM + 40,y; Set Color RAM row 1 (home bay top row)
$944499 50 d8staCOLOR_RAM + 80,y; Set Color RAM row 2 (home bay bottom row)
$9447a5 4eldazp_bay_tile_id; Load current column's top-row tile screencode
$944999 28 44staSCREEN_RAM + 40,y; Write top-row tile for current column to Screen RAM row 1
$944Ce6 4einczp_bay_tile_id; Advance to bottom-row tile in column-major 3x2 set
$944Ea5 4eldazp_bay_tile_id; Load current column's bottom-row tile screencode
$945099 50 44staSCREEN_RAM + 80,y; Write bottom-row tile for current column to Screen RAM row 2
$9453e6 4einczp_bay_tile_id; Advance to next column's top-row tile
$9455c8iny
$9456c6 26deczp_bay_col_cnt; Count down remaining home bay columns (3 -> 0)
$9458d0 e5bnedraw_bay_tiles_col_loop; Repeat across all 3 bay columns (6 tiles total)
$945A60rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Generates a pre-shifted horizontal scroll copy of a 2-row (16-scanline)
; multicolor tile strip from (zpa_04) into RAM charset cursor (zpa_08) by
; circularly rotating all zpa_0A 16-byte column-pairs left or right by A bits,
; then advances zpa_08/zpa_09 past the generated strip.
;
; Inputs: A = bit-rotation count (2, 4, or 6 bits = 1, 2, or 3 multicolor px)
; zpa_04/zpa_05 = 16-bit unshifted source strip pointer (preserved)
; zpa_08/zpa_09 = 16-bit RAM charset destination cursor
; zpa_0A = strip width in 16-byte (2-char) column-pairs (4..14)
; zpa_0B = shift direction ($00 = left ROL, non-zero = right ROR)
; Outputs: zpa_08/zpa_09 = entry zpa_08/zpa_09 + (zpa_0A * 16)
; zpa_2D = strip byte size (zpa_0A * 16); zpa_04/zpa_05 preserved
; zpa_2C = $00, zpa_2B = zpa_0A, zpa_02/$03 & zpa_06/$07 = last col
; A = updated zpa_09, X = $09, Y = $10
; Side Effects: Writes zpa_0A * 16 pre-shifted glyph bytes to RAM charset at
; [entry zpa_08/zpa_09 .. + (zpa_0A * 16) - 1]; uses 3 bytes of
; hardware stack temporarily (2 for zpa_04/$05, 1 for PHP/PLP)
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$945B85 2cpreshift_tile_stripstazp_unpack_or_shift_cnt; Remaining 1-bit rotation passes (2, 4, or 6 bits = 1..3 multicolor px) ; x-ref: $8ad5, $8ada, $8ae6, $8afb, $8b18, ...
$945Da5 04ldazp_ptr_lane_cfg_lo
$945F48pha; Save caller's unshifted source strip pointer low byte (zp_ptr_lane_cfg_lo)
$9460a5 05ldazp_ptr_lane_cfg_hi
$946248pha; Save caller's unshifted source strip pointer high byte (zp_ptr_lane_cfg_hi)
preshift_bit_pass_loop
$9463a0 00ldy#$00; Y = scanline row index (0..7 top char, 8..15 bottom char) ; x-ref: $94be
$946518clc; Clear initial Carry before scanline 0 horizontal bit-rotate chain
preshift_scanline_loop
$9466a9 00lda#$00; x-ref: $94b0
$946885 2bstazp_tile_loop_cnt; Reset column-pair index = 0 (C = 0 from CLC or CPY #$10 borrow)
$946Aa5 04ldazp_ptr_lane_cfg_lo
$946C85 02stazp_ptr_src_lo; Working source column pointer zpa_02/zpa_03 = zpa_04/zpa_05
$946Ea5 05ldazp_ptr_lane_cfg_hi
$947085 03stazp_ptr_src_hi
$9472a5 08ldazp_ptr_aux_dst_lo
$947485 06stazp_ptr_dst_lo; Working destination column pointer zpa_06/zpa_07 = zpa_08/zpa_09
$9476a5 09ldazp_ptr_aux_dst_hi
$947885 07stazp_ptr_dst_hi
preshift_column_loop
$947Ab1 02lda(zp_ptr_src_lo),y; Read scanline Y byte from current 16-byte (2-row) column-pair ; x-ref: $949b
$947Ca6 0bldxzp_tile_horiz_dir; Shift direction: $00 = left (ROL), non-zero = right (ROR)
$947Ef0 04beqrotate_strip_byte_left
$94806arora; Rotate right 1 bit: Carry -> bit 7, bit 0 -> Carry (left-to-right cols)
$94814c 85 94jmpstore_shifted_strip_byte
rotate_strip_byte_left
$94842arola; Rotate left 1 bit: Carry -> bit 0, bit 7 -> Carry (right-to-left cols) ; x-ref: $947e
store_shifted_strip_byte
$948508php; Preserve outgoing Carry flag across 16-bit pointer advances ; x-ref: $9481
$948691 06sta(zp_ptr_dst_lo),y; Write rotated scanline Y byte to destination column-pair
$9488e6 2binczp_tile_loop_cnt; Advance rotated strip column-pair counter
$948Aa5 2bldazp_tile_loop_cnt; Check column-pairs rotated on scanline
$948Cc5 0acmpzp_tile_strip_len; Rotated all zp_tile_strip_len column-pairs on this scanline?
$948Ef0 0ebeqwrap_strip_carry_bit
$9490a9 10lda#$10; Stride = $10 (16 bytes = 2 stacked 8x8 chars) to next column-pair
$949220 e1 94jsradvance_src_ptr; Advance source column pointer zpa_02/zpa_03 by $10
$9495a9 10lda#$10
$949720 d5 94jsradvance_dst_ptr; Advance destination column pointer zpa_06/zpa_07 by $10
$949A28plp; Restore Carry shifted out of previous column-pair
$949B4c 7a 94jmppreshift_column_loop
wrap_strip_carry_bit
$949Ea9 01lda#$01; Wrap bitmask = $01 (bit 0 of col 0) when rotating left (ROL) ; x-ref: $948e
$94A0a6 0bldxzp_tile_horiz_dir; Check shift direction ($00 = left ROL, $01 = right ROR) for carry wrap
$94A2f0 02beqapply_wrapped_carry_bit
$94A4a9 80lda#$80; Wrap bitmask = $80 (bit 7 of col 0) when rotating right (ROR)
apply_wrapped_carry_bit
$94A628plp; Restore Carry shifted out of final column-pair (zp_tile_strip_len - 1) ; x-ref: $94a2
$94A790 04bccnext_strip_scanline; Skip wrap-around merge if final outgoing bit was 0
$94A911 08ora(zp_ptr_aux_dst_lo),y; Circularly wrap Carry bit into column 0 at (zpa_08),Y
$94AB91 08sta(zp_ptr_aux_dst_lo),y; Store updated column-0 scanline byte with wrapped Carry bit
$94ADc8next_strip_scanlineiny; x-ref: $94a7
$94AEc0 10cpy#$10; All 16 scanlines rotated? (Y < $10 also clears Carry for next row)
$94B0d0 b4bnepreshift_scanline_loop
$94B2c6 2cdeczp_unpack_or_shift_cnt; Decrement remaining 1-bit rotation passes
$94B4f0 0bbeqpreshift_strip_done
$94B6a5 08ldazp_ptr_aux_dst_lo
$94B885 04stazp_ptr_lane_cfg_lo; Point zpa_04/zpa_05 at destination (zpa_08/zpa_09) to rotate in place
$94BAa5 09ldazp_ptr_aux_dst_hi
$94BC85 05stazp_ptr_lane_cfg_hi
$94BE4c 63 94jmppreshift_bit_pass_loop
$94C168preshift_strip_donepla; x-ref: $94b4
$94C285 05stazp_ptr_lane_cfg_hi; Restore caller's unshifted source strip pointer high byte (zp_ptr_lane_cfg_hi)
$94C468pla
$94C585 04stazp_ptr_lane_cfg_lo; Restore caller's unshifted source strip pointer low byte (zp_ptr_lane_cfg_lo)
$94C7a5 0aldazp_tile_strip_len; Load strip width in 16-byte column-pairs (4..14)
$94C90aasla
$94CA0aasla
$94CB0aasla
$94CC0aasla; A = zp_tile_strip_len * 16 (total byte size of generated strip: $40..$E0)
$94CD85 2dstazp_scratch_byte; Return strip byte size ($40..$E0) for caller's source-pointer advance
$94CFa2 08ldx#$08; Select zero-page charset output cursor zpa_08/zpa_09 ($08/$09)
$94D120 ed 94jsradvance_zp_ptr_x; Advance zpa_08/zpa_09 by strip byte size to next output slot
$94D460rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Adds an unsigned 8-bit byte offset in A to the 16-bit destination pointer at
; zpa_06/zpa_07 in place.
;
; Inputs: A = unsigned 8-bit byte offset; zpa_06/zpa_07 = 16-bit destination pointer
; Outputs: zpa_06/zpa_07 = zpa_06/zpa_07 + A; A = updated high byte (zpa_07);
; X, Y preserved; N, Z, C, V set from high-byte addition
; Side Effects: None
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$94D518advance_dst_ptrclc; Clear carry for unsigned 16-bit pointer addition ; x-ref: $8984, $903a, $904b, $9497, $951d
$94D665 06adczp_ptr_dst_lo; Add byte offset in A to destination pointer low byte ($06)
$94D885 06stazp_ptr_dst_lo; Store updated destination pointer low byte
$94DAa5 07ldazp_ptr_dst_hi
$94DC69 00adc#$00; Propagate page-crossing carry into destination pointer high byte ($07)
$94DE85 07stazp_ptr_dst_hi; Store updated destination pointer high byte
$94E060rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Adds an unsigned 8-bit byte offset in A to the 16-bit source pointer at
; zpa_02/zpa_03 in place.
;
; Inputs: A = unsigned 8-bit byte offset; zpa_02/zpa_03 = 16-bit source pointer
; Outputs: zpa_02/zpa_03 = zpa_02/zpa_03 + A; A = updated high byte (zpa_03);
; X, Y preserved; N, Z, C, V set from high-byte addition
; Side Effects: None
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$94E118advance_src_ptrclc; Clear carry for unsigned 16-bit pointer addition ; x-ref: $903f, $9492
$94E265 02adczp_ptr_src_lo; Add byte offset in A to source pointer low byte ($02)
$94E485 02stazp_ptr_src_lo; Store updated source pointer low byte ($02)
$94E6a5 03ldazp_ptr_src_hi
$94E869 00adc#$00; Propagate page-crossing carry into source pointer high byte ($03)
$94EA85 03stazp_ptr_src_hi; Store updated source pointer high byte ($03)
$94EC60rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Adds an unsigned 8-bit byte offset in A to the 16-bit zero-page pointer at
; $00,X/$01,X in place (used for zpa_04/zpa_05, zpa_08/zpa_09, and zpa_24/zpa_25).
;
; Inputs: A = unsigned 8-bit byte offset; X = zero-page offset of pointer low byte;
; $00,X/$01,X = 16-bit zero-page pointer
; Outputs: $00,X/$01,X (at entry X) = pointer + A; A = updated pointer high byte;
; X = X + 1 (pointer high-byte offset); Y preserved; N, Z, C, V from ADC
; Side Effects: None
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$94ED18advance_zp_ptr_xclc; Clear carry for unsigned 16-bit pointer addition ; x-ref: $8ae1, $8aed, $8b06, $8b45, $94d1, ...
$94EE75 00adcCPU_PORT_DDR,x; Add byte offset in A to zero-page pointer low byte ($00,X ZP base)
$94F095 00staCPU_PORT_DDR,x; Store updated zero-page pointer low byte ($00,X)
$94F2e8inx; Advance X to zero-page pointer high byte ($01,X)
$94F3b5 00ldaCPU_PORT_DDR,x; Load zero-page pointer high byte ($00,X ZP base after INX)
$94F569 00adc#$00; Propagate page-crossing carry into pointer high byte
$94F795 00staCPU_PORT_DDR,x; Store updated zero-page pointer high byte ($00,X ZP base)
$94F960rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Copies one 8-byte glyph for Character ROM screencode A ($00-$3F or $80-$BF)
; from $D000 + ((A & $BF) * 8) to (zpa_06), and advances zpa_06/zpa_07 by 8.
;
; Inputs: A = Character ROM screencode (bit 6 = 0: $00-$3F normal or $80-$BF
; reverse-video); zpa_06/zpa_07 = 16-bit RAM charset destination
; pointer; 6510 port $01 CHAREN = 0 (Character ROM mapped at $D000)
; Outputs: zpa_02/zpa_03 = $D000 + ((entry A & $BF) * 8); zpa_06/zpa_07 += 8;
; A = updated zpa_07; Y = $08; X preserved; N, Z, C, V from high-byte ADC
; Side Effects: Writes 8 glyph bytes to RAM at [entry zpa_06/zpa_07 .. +7];
; uses 1 byte of stack temporarily via PHP/PLA
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$94FA18copy_char_rom_glyphclc; Clear carry before screencode bit shifts ; x-ref: $8a1d, $8a3a
$94FB0aasla; Shift screencode bit 7 (reverse-video flag $80) into C
$94FC08php; Save P on stack to preserve bit 7 in C (bit 0)
$94FD0aasla; Shift out bit 6 (always 0 for $00-$3F / $80-$BF glyphs)
$94FE0aasla; A = (screencode & $1F) * 8; C = screencode bit 5
$94FF85 02stazp_ptr_src_lo; Store Character ROM glyph source pointer low byte ($02)
$9501a9 00lda#$00; Clear A while preserving screencode bit 5 in C
$950369 d0adc#$d0; A = $D0 + bit 5 ($D0/$D1 ROM page); clears C
$950585 03stazp_ptr_src_hi; Store intermediate source pointer high byte ($03)
$950768pla; Pull saved P status byte (C remains 0)
$950829 01and#$01; Isolate saved C flag (screencode bit 7: 0 or 1)
$950A0aasla
$950B0aasla; A = bit 7 * 4 ($00 normal $D000, $04 reverse $D400); C = 0
$950C65 03adczp_ptr_src_hi; Combine into final ROM page ($D0, $D1, $D4, or $D5)
$950E85 03stazp_ptr_src_hi; Store Character ROM glyph source pointer high byte ($03)
$9510a0 00ldy#$00; Initialize glyph row byte index Y = 0
copy_glyph_byte_loop
$9512b1 02lda(zp_ptr_src_lo),y; Read glyph row byte from Character ROM at $D000+ ; x-ref: $9519
$951491 06sta(zp_ptr_dst_lo),y; Write glyph row byte to RAM custom charset
$9516c8iny
$9517c0 08cpy#$08; All 8 bytes of character glyph copied?
$9519d0 f7bnecopy_glyph_byte_loop
$951Ba9 08lda#$08; A = 8 bytes per character glyph
$951D20 d5 94jsradvance_dst_ptr; Advance charset destination pointer zpa_06/zpa_07 by 8
$952060rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Zeroes Y contiguous bytes starting at Zero-Page address $0000 + A via
; (zpa_06),Y (called at $95A4 to clear gameplay session state $0077-$00B1).
;
; Inputs: A = starting Zero-Page address low byte; Y = byte count (1..255, or 0 = 256)
; Outputs: A = $00; Y = $00; zpa_06/zpa_07 = $0000 + entry A; Z = 1, N = 0 (X preserved)
; Side Effects: Writes $00 across [$0000 + A .. $0000 + A + Y - 1]
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$952185 06clear_zp_rangestazp_ptr_dst_lo; Set destination pointer low byte ($06) from A ; x-ref: $95a4
$9523a9 00lda#$00; A = $00 (page-0 high byte and zero fill value)
$952585 07stazp_ptr_dst_hi; Set destination pointer high byte ($07) = $00 ($00xx)
$952788clear_zp_loopdey; Pre-decrement index/counter (writes offsets Y - 1 down to 0) ; x-ref: $952a
$952891 06sta(zp_ptr_dst_lo),y; Clear target byte at ($0000 + A) + Y (preserves Z flag)
$952Ad0 fbbneclear_zp_loop; Loop until offset 0 has been cleared (Y == 0)
$952C60rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Horizontally mirrors a 63-byte (24x21) high-resolution sprite from (zpa_02)
; into (zpa_24) by reversing both the 3-byte column order per row and the 8 bit
; positions per byte, then advances zpa_24/zpa_25 by $40 to the next sprite slot.
;
; Inputs: zpa_02/zpa_03 = 16-bit source sprite pointer (63-byte hires bitmap);
; zpa_24/zpa_25 = 16-bit destination RAM sprite slot pointer
; Outputs: zpa_24/zpa_25 = entry pointer + $0040; A = updated zpa_25; X = $25;
; Y = $00; zpa_20 = $02, zpa_21 = $FF, zpa_28 = $01, zpa_2D = scratch
; Side Effects: Writes 63 mirrored sprite bytes to [(zpa_24) + $00 .. + $3E]
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
mirror_sprite_horizontal
$952Da0 3eldy#$3e; Dest offset = $3E (62: row 20, right byte of 63-byte sprite) ; x-ref: $8a8c, $8aa2, $8aad, $8ab8
$952F84 21styzp_mirror_dst_idx; zpa_21 = destination sprite byte index ($3E down to $00)
$9531a0 3cldy#$3c; Src offset = $3C (60: row 20, left byte of bottom sprite row)
$953384 20styzp_mirror_src_idx; zpa_20 = source sprite byte index (scans left-to-right per row)
mirror_sprite_row_loop
$9535a9 03lda#$03; 3 bytes per 24-pixel sprite row ; x-ref: $955c
$953785 28stazp_preshift_or_col_cnt; Remaining column bytes in current sprite row (3..1)
mirror_sprite_byte_loop
$9539a2 08ldx#$08; 8 bits per high-resolution sprite byte ; x-ref: $9553
$953Ba4 20ldyzp_mirror_src_idx; Load current source sprite byte offset
$953Db1 02lda(zp_ptr_src_lo),y; Fetch source sprite byte at row*3 + col
reverse_byte_bits_loop
$953F6arora; Shift next source bit (LSB..MSB) into Carry ; x-ref: $9543
$954026 2drolzp_scratch_byte; Shift Carry bit in to reverse sprite byte bit order (7..0 -> 0..7)
$9542cadex
$9543d0 fabnereverse_byte_bits_loop
$9545a5 2dldazp_scratch_byte; Load horizontally bit-reversed sprite byte
$9547a4 21ldyzp_mirror_dst_idx; Load mirrored destination sprite byte offset ($3E..$00)
$954991 24sta(zp_ptr_sprite_dst_lo),y; Store bit-reversed byte at mirrored column row*3 + (2 - col)
$954Bc6 21deczp_mirror_dst_idx; Step destination index backward toward byte $00
$954D30 10bmimirror_sprite_done; Exit once all 63 bytes ($3E..$00) are written (zpa_21 == $FF)
$954Fe6 20inczp_mirror_src_idx; Advance source index to next byte in current row
$9551c6 28deczp_preshift_or_col_cnt; Decrement column counter (3 -> 2 -> 1 -> 0)
$9553d0 e4bnemirror_sprite_byte_loop; Next byte in current 3-byte sprite row
$9555a5 20ldazp_mirror_src_idx
$955738sec
$9558e9 06sbc#$06; Step source index back 6 bytes from (row+1)*3 to (row-1)*3
$955A85 20stazp_mirror_src_idx; Save rewound source offset for next sprite row upward
$955C4c 35 95jmpmirror_sprite_row_loop; Mirror next sprite row upward
$955Fa2 24mirror_sprite_doneldx#$24; X = $24 (select zp_ptr_sprite_dst_lo/hi cursor) ; x-ref: $954d
$9561a9 40lda#$40; A = $40 (64 bytes = 1 VIC-II sprite block)
$956320 ed 94jsradvance_zp_ptr_x; Advance zp_ptr_sprite_dst by $40 to next 64-byte RAM sprite slot
$956660rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Vertically flips a 24x21 hardware sprite (63 active bytes, 21 rows x 3 bytes)
; from (zpa_02) into the destination sprite slot at (zpa_24), reversing top-to-
; bottom scanline order while preserving horizontal byte/bit order, then advances
; zpa_24/zpa_25 by 64 bytes ($40) to the next VIC-II sprite block.
;
; Inputs: zpa_02/zpa_03 = 16-bit source sprite pointer (e.g., ROM frog up frames)
; zpa_24/zpa_25 = 16-bit destination sprite RAM cursor (VIC Bank 1)
; Outputs: zpa_24/zpa_25 = zpa_24/zpa_25 + $0040; A = updated zpa_25; X = $25;
; Y = $00; zpa_20 = $3C; zpa_21 = $FF (zpa_02/zpa_03 preserved)
; Side Effects: Writes 63 flipped sprite bytes to (zpa_24)+$00..+$3E (byte +$3F
; untouched); clobbers A, X, Y, zpa_20, zpa_21, and N/Z/C/V flags
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
flip_sprite_vertical
$9567a0 3eldy#$3e; Start destination offset at $3E (62 = row 20, col 2; byte $3F unused) ; x-ref: $8a81, $8a97
$956984 21styzp_mirror_dst_idx; zpa_21 = destination sprite byte index ($3E down to $00)
$956Ba0 02ldy#$02; Start source offset at $02 (row 0, col 2)
$956D84 20styzp_mirror_src_idx; zpa_20 = source sprite byte index
$956Fa2 03vflip_row_loopldx#$03; Copy 3 bytes per sprite scanline (col 2 -> col 1 -> col 0) ; x-ref: $9589
$9571a4 20vflip_byte_loopldyzp_mirror_src_idx; Load source sprite byte offset (row*3 + col) ; x-ref: $9580
$9573b1 02lda(zp_ptr_src_lo),y; Read source byte at src[3*r + c]
$9575a4 21ldyzp_mirror_dst_idx; Load flipped destination sprite byte offset ($3E..$00)
$957791 24sta(zp_ptr_sprite_dst_lo),y; Write to vertically mirrored row at dst[3*(20 - r) + c]
$9579c6 21deczp_mirror_dst_idx; Step destination sprite byte offset down toward $00
$957B30 0fbmivflip_advance_dst; Exit once all 63 active bytes are copied (zpa_21 wraps $00 -> $FF)
$957Dc6 20deczp_mirror_src_idx; Step left to previous column byte in current source row
$957Fcadex
$9580d0 efbnevflip_byte_loop; Finish copying all 3 bytes of current scanline
$958218clc
$9583a5 20ldazp_mirror_src_idx
$958569 06adc#$06; Advance source from (3*r - 1) to 3*(r + 1) + 2 (next row, col 2)
$958785 20stazp_mirror_src_idx; Save source offset for col 2 of next sprite row
$95894c 6f 95jmpvflip_row_loop
$958Ca2 24vflip_advance_dstldx#$24; X = $24 (select zp_ptr_sprite_dst_lo/hi cursor) ; x-ref: $957b
$958Ea9 40lda#$40; 64-byte ($40) hardware sprite block stride
$959020 ed 94jsradvance_zp_ptr_x; Advance zp_ptr_sprite_dst by $40 to next 64-byte RAM sprite slot
$959360rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Selects standby/attract mode (X = $01, called on boot and F5 1UP/2UP toggle)
; and tail-calls reset_session_common ($95A0) without queuing the theme melody.
;
; Inputs: zpa_5E = player count flag ($00 = 1P, $01 = 2P, read by $95A0)
; zpa_5B = game speed mode ($00 = FAST, $01 = SLOW, read by $95A0)
; Outputs: X = $01 (non-zero standby/attract mode flag for $95A0), N = 0, Z = 0
; Side Effects: Tail-calls reset_session_common ($95A0).
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
reset_standby_session
$9594a2 01ldx#$01; Mode X = $01: standby/attract session (vs X = $00 active game at $959E) ; x-ref: $8bd8, $8c4c
$95964c a0 95jmpreset_session_common; Tail-call shared session reset without playing opening theme
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Starts a new 1P or 2P game (F1) by queuing the 3-voice Frogger theme melody
; (stream $08) and running the shared session-reset tail ($95A0, also entered
; from s_9594 with X = $01 for standby/attract mode) to clear gameplay state,
; initialize lane speeds, sprites, and Round 1, and clone Player 1's state into
; Player 2's backup buffers.
;
; Inputs: zpa_5E = player count flag ($00 = 1P, $01 = 2P)
; zpa_5B = game speed mode ($00 = FAST, $01 = SLOW)
; zpa_6E/zpa_6F = active SID stream state (for start_sound_stream)
; (At reset_session_common $95A0: X = $00 for new game, X != $00 standby)
; Outputs: $0077..$00B1 cleared to $00 via clear_zp_range, then:
; zpf_9D + 1 = $08 (lane 1 turtle dive offset), zpa_0F = $08
; zpf_32[0..8], zpf_3B[0..8] loaded for speed tier 0; zpa_5F = $01 (P1)
; zpf_82 + 1 = $01 in 1P mode ($00 in 2P); zpa_31 = $01, zpa_44 = $01
; zpa_45 = $FF, zpa_47 = $1E, zpa_48 = $1E, zpa_4A/4B = $0A, zpa_B3 = $05
; zpa_B9..BC = median snake bounds ($0182..$015A), zpa_BD..C0 = log snake
; bounds ($00D0..$015A), zpa_C1 = $01, zpa_C2 = $0C, zpa_B6 = $00
; New game (X = $00): zpa_77 = $FF, zpa_B2 = $05, zpa_AF = $01 ("R=01")
; Standby (X != $00): zpa_7D = $FF, zpa_AC = $03, zpa_AF = $03, zpa_77 = $00
; $0100..$0114 and zpf_C3..$00FE cloned from P1 state; A=$00, X=$01, Y=$00
; Side Effects: Queues SID theme stream $08 (via $9599); configures VIC-II sprites
; ($D000..$D007, $D009, $D010, $D015, $D027), reads $D01E to clear
; collision latches, and sets sprite pointers a_47F8..a_47FB.
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$9599a9 08start_new_gamelda#SoundStreamId.MELODY_MAIN_THEME; Sound stream $08 = main 3-voice Frogger theme melody ; x-ref: $8c2d
$959B20 73 9bjsrstart_sound_stream
$959Ea2 00ldx#$00; Mode X = $00: active new game (vs X = $01 standby from s_9594)
reset_session_common
$95A0a0 3bldy#$3b; Clear 59 ($3B) ZP bytes ($0077..$00B1: scores, scroll, bays, flags) ; x-ref: $9596
$95A2a9 77lda#<zp_screen_wipe_state; Start zero-page session clear at $0077 (zp_screen_wipe_state)
$95A420 21 95jsrclear_zp_range
$95A7a0 08ldy#$08
$95A984 9estyzp_lane_turtle_phase_ofs + 1; Desync river lane 1 turtle dive phase by +8 steps (of 12)
$95AB84 0fstyzp_scroll_lane_idx; Iterate zp_scroll_lane_idx from lane 8 down to lane 0
init_lane_speeds_loop
$95AD20 e0 99jsrload_lane_speed_profile; Unpack initial tier-0 delay (zpf_32) and step (zpf_3B) for lane zpa_0F ; x-ref: $95b2
$95B0c6 0fdeczp_scroll_lane_idx; Step down to next lane (8..0) during speed profile init
$95B210 f9bplinit_lane_speeds_loop
$95B4a9 01lda#$01
$95B685 5fstazp_joy_port_offset; Select CIA1 Port 1 ($DC01, offset 1) as Player 1 joystick port
$95B8a4 5eldyzp_two_player_flag; Check player count flag (0 = 1P, 1 = 2P)
$95BAd0 02bneset_initial_hop_dir
$95BC85 83stazp_player_game_over + 1; In 1P mode, pre-mark Player 2 as out of lives to disable 2P swap
$95BE85 31set_initial_hop_dirstazp_frog_hop_dir; Default frog hop direction = $01 (HOP_DIR_UP) ; x-ref: $95ba
$95C085 44stazp_unused_44; Unused ZP byte ($0044, never read) set to $01
$95C2a9 fflda#$ff
$95C485 45stazp_frog_hop_px_cnt; Mark frog hop pixel counter idle ($FF -> reloaded to $0F on hop)
$95C6a9 05lda#$05
$95C885 b3stazp_player_lives; Grant 5 total lives (1 active + 4 reserve -> HUD "FROGS 4")
$95CAa9 32lda#$32; Sprite 1 (Lady Frog on river lane 3) initial X = $0032 (50)
$95CC8d 02 d0sta$d002; Sprite 1 X Pos
$95CFa9 6dlda#$6d; Sprite 2 (top-lane river alligator jaws) initial X = $006D (109)
$95D18d 04 d0sta$d004; Sprite 2 X Pos
$95D4a9 4alda#$4a; Sprite 2 Y = $4A (74, river lane 0)
$95D68d 05 d0sta$d005; Sprite 2 Y Pos
$95D9a9 d0lda#$d0; Tracked river-lane-2 log left snake bound = $00D0 (MSB mask $00)
$95DB85 bdstazp_snake_log_left_x_lo; Init river-log snake left X bound low byte ($D0)
$95DDa9 00lda#$00
$95DF85 bestazp_snake_log_left_x_msb; Init river-log snake left X-MSB mask ($00 = X < $100)
$95E1a9 5alda#$5a; Tracked river-lane-2 log right snake bound = $015A (MSB mask $08)
$95E385 bfstazp_snake_log_right_x_lo; Init river-log snake right X bound low byte ($5A)
$95E5a9 08lda#$08
$95E785 c0stazp_snake_log_right_x_msb; Init river-log snake right X-MSB mask ($08 = X >= $100)
$95E985 0fstazp_scroll_lane_idx; Start per-frame lane scroller cursor at road lane 8
$95EBa9 68lda#$68; Preload Sprite 3 Y = $68 (river log) so toggle moves snake to median ($98)
$95ED8d 07 d0sta$d007; Sprite 3 Y Pos
$95F020 0a 9ajsrtoggle_snake_patrol_lane
$95F3a9 00lda#$00; Hide all sprites ($D015 = 0) and clear all X MSBs ($D010 = 0)
$95F58d 15 d0sta$d015; Sprite display Enable
$95F88d 10 d0sta$d010; Sprites 0-7 MSB of X coordinate
$95FBa9 79lda#$79; Sprite 1 (Lady Frog) Y = $79 (121, river log lane 3)
$95FD8d 03 d0sta$d003; Sprite 1 Y Pos
$9600a9 60lda#$60; Upward-facing frog sprite block $60 ($5800) for Lady Frog
$96028d f9 47staSCREEN_RAM_SPR1_PTR; Sprite 1 pointer ($47F9) = $60 (upward frog sprite at $5800)
$9605a9 68lda#$68
$96078d fa 47staSCREEN_RAM_SPR2_PTR; Sprite 2 pointer ($47FA) = $68 (closed alligator head at $5A00)
$960Aa9 1elda#$1e
$960C85 48stazp_half_sec_prescaler; 30-frame (~0.5 s) turtle/hazard prescaler = $1E
$960Ea9 0clda#$0c
$961085 c2stazp_snake_anim_timer; 12-frame snake slither animation timer = $0C
$961220 40 96jsrreset_player_frog; Place Sprite 0 frog on start sidewalk and refill life timer (preserves X)
$9615e0 00cpx#$00; X == $00 -> active new game; X != $00 -> attract/standby mode
$9617f0 15beqinit_active_game_round
$9619a9 fflda#$ff
$961B85 7dstazp_frog_state_timer; Standby/attract state ($FF disables frog input & life timer)
$961Da9 03lda#$03; Preload layout 3 & R=03 so next-frame advance_to_next_round enters layout 4 / R=04
$961F85 acstazp_level_layout_idx; Preload standby/attract level layout index = 3 (advances to layout 4)
$962185 afstazp_round_bcd; Preload attract-mode round = $03 (advances to R=04 next frame)
$9623ad 15 d0lda$d015; Sprite display Enable
$962629 feand#$fe; Hide player frog (Sprite 0) during attract/standby mode
$96288d 15 d0sta$d015; Sprite display Enable
$962B4c 3a 96jmpclone_player2_initial_state
init_active_game_round
$962Ea9 fflda#ScreenWipeState.SCREEN_WIPE_FULL; x-ref: $9617
$963085 77stazp_screen_wipe_state; Request full two-phase river + bay/road wipe ($FF) for Round 1
$9632a9 05lda#$05
$963485 b2stazp_bays_remaining; 5 empty home bays remaining to clear Round 1
$9636a9 01lda#$01
$963885 afstazp_round_bcd; Initial packed BCD round counter = $01 ("R=01")
clone_player2_initial_state
$963Aa2 01ldx#$01; X = $01 (copy mode): clone P1 sprite regs ($0100..$0114) & ZP ($87..$C2 -> $C3..$FE) ; x-ref: $962b
$963C20 09 9djsrswap_player_sprites_and_state
$963F60rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Resets the player frog (Sprite 0) to its bottom-sidewalk starting position,
; refills the life countdown timer, and clears per-life status/collision flags.
;
; Inputs: VIC-II $D015 (Sprite 1 enable bit tested for active Lady Frog)
; Outputs: A, N/Z clobbered; X and Y preserved (relied upon by caller at $9612);
; zpa_47 = $1E (30-tick life timer), zpa_4A = zpa_4B = $0A (start row),
; zpa_84 = 0 (death flag), zpa_4F = 0 (home-bay bonus count),
; zpa_B6 = 0 if Sprite 1 is currently disabled
; Side Effects: Positions Sprite 0 at ($00A0, $E8) with idle-up frame ($60) and
; light green color ($0D), enables Sprite 0 ($D015/$D010), and
; reads $D01E to clear latched sprite-to-sprite collisions.
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$9640a9 1ereset_player_froglda#$1e; Refill frog life countdown timer to 30 ticks ($1E) ; x-ref: $8e39, $9612
$964285 47stazp_frog_life_timer; Store initial 30-tick (~1 Hz) frog life countdown
$9644a9 0alda#$0a; Reset current ($4A) and furthest-upward ($4B) lane row to sidewalk (10)
$964685 4astazp_frog_row; Start frog on bottom sidewalk row ($0A = 10)
$964885 4bstazp_frog_best_row; Reset furthest-upward row watermark for new life to $0A
$964Aad 15 d0lda$d015; Check if Sprite 1 (Lady Frog) is currently visible; Sprite display Enable
$964D29 02and#$02
$964Fd0 04bneclear_frog_spawn_flags
$9651a9 00lda#$00
$965385 b6stazp_lady_frog_spawned; Allow Lady Frog to respawn on next wrap if Sprite 1 is hidden
clear_frog_spawn_flags
$9655a9 00lda#$00; Clear frog death flag ($84) and home-bay bonus counter ($4F) ; x-ref: $964f
$965785 84stazp_frog_died_flag; Clear frog-died flag ($00 = alive / safe bay respawn)
$965985 4fstazp_bay_pickup_cnt; Reset per-life Lady Frog / bonus fly pickup count (0)
$965Ba9 a0lda#$a0; Center Sprite 0 horizontally at X = $00A0 (160)
$965D8d 00 d0sta$d000; Sprite 0 X Pos
$9660a9 e8lda#$e8; Place Sprite 0 on bottom starting sidewalk at Y = $E8 (232)
$96628d 01 d0sta$d001; Sprite 0 Y Pos
$9665a9 60lda#$60; Set Sprite 0 pointer ($47F8) to idle upward-facing frog ($60 -> $5800)
$96678d f8 47staSCREEN_RAM_SPR0_PTR; Set Sprite 0 pointer to idle upward frog frame ($60 -> $5800)
$966Aa9 0dlda#$0d; Restore Sprite 0 color to light green ($0D)
$966C8d 27 d0sta$d027; Sprite 0 Color
$966Fad 15 d0lda$d015; Sprite display Enable
$967209 01ora#$01; Enable Sprite 0 display
$96748d 15 d0sta$d015; Sprite display Enable
$9677ad 1e d0lda$d01e; Read $D01E to clear any stale sprite-to-sprite collision latch; Sprite to Sprite Collision Detect
$967Aad 10 d0lda$d010; Sprites 0-7 MSB of X coordinate
$967D29 feand#$fe; Clear Sprite 0 X-coordinate MSB (X < 256)
$967F8d 10 d0sta$d010; Sprites 0-7 MSB of X coordinate
$968260rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Applies any pending BCD score increment and refreshes the top HUD row ($4400:
; active player "1/2 UP", 5-digit score, reserve lives, and 8-cell TIME bar)
; and bottom status row ($47C0: "R=XX" round, post-bay "TIMER XX", and
; "FAST"/"SLOW" speed indicator).
;
; Inputs: zpa_81 = active player index (0 = P1, 1 = P2)
; zpa_7A/zpa_7B = pending 16-bit packed BCD score delta (10-pt units)
; zpf_87/zpa_88 = active player's 16-bit packed BCD score (10-pt units)
; zpa_8A = previous 10,000-point BCD digit threshold
; zpa_B3 = active player's total lives (1..9; 0 during final death)
; zpa_47 = frog life countdown timer ticks ($00..$1E)
; zpa_AF = current round number (packed BCD $01..$99)
; zpa_7F = post-bay "TIMER XX" display countdown (0 = hidden)
; zpa_59 = packed BCD remaining bay time ($00..$60)
; zpa_5B = game speed flag (0 = FAST, 1 = SLOW)
; Outputs: zpf_87/zpa_88, zpa_7A/zpa_7B, zpa_8A, zpa_B3 updated via
; add_pending_score_bcd; zpa_27 = $00; A, X = $04, Y, and P clobbered
; Side Effects: Updates VIC Bank 1 Screen RAM row 0 ($4400-$4427, top charset
; $4800) and row 24 ($47C1-$47E5, bottom reverse charset $5000);
; temporarily pushes/pulls P on stack via add_pending_score_bcd
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
update_hud_and_status
$9683a5 81ldazp_active_player; Active player index (0 = P1, 1 = P2) ; x-ref: $8d8e
$968518clc
$968669 5fadc#$5f; Convert to top-HUD digit tile ('1' = $5F, '2' = $60)
$96888d 04 44staSCREEN_RAM + 4; Write player digit ("1 UP" / "2 UP") at row 0, col 4
$968B20 63 97jsradd_pending_score_bcd; Fold pending BCD score delta ($7A/$7B) into score ($87/$88)
$968Ea2 00ldx#$00
$9690a0 0cldy#$0c; Start at col 12 ($440C, tens digit; col 13 stays fixed '0')
render_score_byte_loop
$9692b5 87ldazp_score_bcd_lo,x; Unpack packed BCD score byte (X=0: tens/hundreds, X=1: thousands/10k) ; x-ref: $96ad
$969429 0fand#$0f
$969618clc
$969769 5eadc#$5e; Convert low BCD nybble to top-HUD digit ('0' = $5E .. '9' = $67)
$969999 00 44staSCREEN_RAM,y; Write low-nybble BCD score digit to HUD row 0 (cols 12, 10)
$969C88dey
$969Db5 87ldazp_score_bcd_lo,x; Reload packed BCD score byte to extract high nybble digit
$969F4alsra
$96A04alsra
$96A14alsra
$96A24alsra
$96A318clc
$96A469 5eadc#$5e; Convert high BCD nybble to top-HUD digit
$96A699 00 44staSCREEN_RAM,y; Write high-nybble BCD score digit to HUD row 0 (cols 11, 9)
$96A988dey
$96AAe8inx
$96ABc0 08cpy#$08; All 4 leading score digits written ($440C down to $4409)?
$96ADd0 e3bnerender_score_byte_loop
$96AFa5 b3ldazp_player_lives; Total lives including active frog (5 at start -> "FROGS 4")
$96B118clc
$96B269 5dadc#$5d; Map lives-1 to top-HUD digit ($5D + 1 = $5E '0'); 0 yields space $5D
$96B4c9 5dcmp#$5d
$96B6d0 02bnestore_hud_lives_digit
$96B8a9 5elda#$5e; Clamp 0 total lives (during final death) to '0' ($5E) instead of blank
store_hud_lives_digit
$96BA8d 17 44staSCREEN_RAM + 23; Write reserve lives digit after "FROGS " at row 0, col 23 ; x-ref: $96b6
$96BDa5 47ldazp_frog_life_timer; Copy remaining frog life timer ticks (0..30) to scratch counter $27
$96BF85 27stazp_tmp_tile_or_ticks; Working TIME-bar subtick countdown (0..30)
$96C1a2 20ldx#$20; Start at row 0, col 32 ($4420, first of 8 TIME bar cells)
$96C3a0 52time_bar_cell_loopldy#$52; Step cell fill from 1/4 bar ($52) down to full 4/4 bar ($4F) ; x-ref: $96d9
time_bar_subtick_loop
$96C5a5 27ldazp_tmp_tile_or_ticks; Check remaining TIME-bar ticks before drawing quarter-bar step ; x-ref: $96d2
$96C7f0 13beqclear_time_bar_tail_loop
$96C998tya
$96CA9d 00 44staSCREEN_RAM,x; Write progressive TIME bar glyph ($52=2px, $51=4px, $50=6px, $4F=8px)
$96CDc6 27deczp_tmp_tile_or_ticks; Consume 1 timer tick for rendered quarter-cell step
$96CF88dey
$96D0c0 4ecpy#$4e; 4 ticks consumed in current 8x8 cell?
$96D2d0 f1bnetime_bar_subtick_loop
$96D4a5 27ldazp_tmp_tile_or_ticks; All ticks exhausted on 4-tick cell boundary?
$96D6f0 04beqclear_time_bar_tail_loop
$96D8e8inx
$96D94c c3 96jmptime_bar_cell_loop
clear_time_bar_tail_loop
$96DCe8inx; Blank remaining trailing TIME bar cells ($4421..$4427) with space ($5D) ; x-ref: $96c7, $96d6, $96e6
$96DDe0 28cpx#$28
$96DFf0 08beqrender_status_round
$96E1a9 5dlda#$5d
$96E39d 00 44staSCREEN_RAM,x; Clear trailing TIME bar cell (cols 33..39) with space ($5D)
$96E64c dc 96jmpclear_time_bar_tail_loop
$96E9a2 00render_status_roundldx#$00; x-ref: $96df
copy_round_prefix_loop
$96EBbd 8b 80ldastr_status_round_prefix,x; Write reverse-video "R=" prefix to row 24, cols 34-35 ($47E2-$47E3) ; x-ref: $96f4
$96EE9d e2 47staSCREEN_RAM_ROW24_COL34,x; Store reverse-video "R=" prefix char at row 24, cols 34-35 ($47E2-$47E3)
$96F1e8inx
$96F2e0 02cpx#$02
$96F4d0 f5bnecopy_round_prefix_loop
$96F618clc
$96F7a5 afldazp_round_bcd; Unpack packed BCD round number ($01..$99) to reverse-video digits
$96F929 0fand#$0f
$96FB69 3fadc#$3f; Convert low BCD nybble to bottom-status digit ('0' = $3F .. '9' = $48)
$96FD8d e5 47staSCREEN_RAM_ROW24_COL34 + 3; Write round units digit at row 24, col 37 ($47E5)
$9700a5 afldazp_round_bcd; Reload packed BCD round number to extract tens digit
$97024alsra
$97034alsra
$97044alsra
$97054alsra
$970618clc
$970769 3fadc#$3f
$97098d e4 47staSCREEN_RAM_ROW24_COL34 + 2; Write round tens digit at row 24, col 36 ($47E4)
$970Ca5 7fldazp_bay_timer_banner_cnt; Post-bay remaining-time banner active ($7F > 0)?
$970Ef0 26beqclear_status_timer_field
$9710a2 00ldx#$00
copy_timer_label_loop
$9712bd 86 80ldastr_status_timer,x; Write reverse-video "TIMER" label to row 24, cols 16-20 ($47D0-$47D4) ; x-ref: $971b
$97159d d0 47staSCREEN_RAM_ROW24_COL16,x; Store reverse-video "TIMER" char at row 24, cols 16-20 ($47D0-$47D4)
$9718e8inx
$9719e0 05cpx#$05
$971Bd0 f5bnecopy_timer_label_loop
$971Da5 59ldazp_bay_time_bcd; Unpack packed BCD remaining bay time ($00..$60 half-seconds)
$971F29 0fand#$0f
$972118clc
$972269 3fadc#$3f
$97248d d7 47staSCREEN_RAM_ROW24_COL16 + 7; Write remaining-time units digit at row 24, col 23 ($47D7)
$9727a5 59ldazp_bay_time_bcd; Extract high BCD nybble (tens digit) of remaining bay time
$97294alsra
$972A4alsra
$972B4alsra
$972C4alsra
$972D18clc
$972E69 3fadc#$3f
$97308d d6 47staSCREEN_RAM_ROW24_COL16 + 6; Write remaining-time tens digit at row 24, col 22 ($47D6)
$97334c 43 97jmprender_status_speed
clear_status_timer_field
$9736a2 00ldx#$00; x-ref: $970e
clear_timer_field_loop
$9738bd 8d 80ldastr_status_blank8,x; Blank 8-char "TIMER XX" field ($47D0-$47D7) with reverse spaces ($31) ; x-ref: $9741
$973B9d d0 47staSCREEN_RAM_ROW24_COL16,x; Clear "TIMER XX" status field at row 24, cols 16-23 ($47D0-$47D7)
$973Ee8inx
$973Fe0 08cpx#$08
$9741d0 f5bneclear_timer_field_loop
$9743a5 5brender_status_speedldazp_speed_mode; Check F3 speed mode flag (0 = FAST, 1 = SLOW) ; x-ref: $9733
$9745f0 0ebeqrender_fast_label
$9747a2 00ldx#$00
copy_slow_label_loop
$9749bd 82 80ldastr_status_slow,x; Write reverse-video "SLOW" to row 24, cols 1-4 ($47C1-$47C4) ; x-ref: $9752
$974C9d c1 47staSCREEN_RAM_ROW24_COL01,x; Store reverse-video 'SLOW' char at Screen RAM row 24, col 1 + X ($47C1-$47C4)
$974Fe8inx
$9750e0 04cpx#$04
$9752d0 f5bnecopy_slow_label_loop
$975460rts
$9755a2 00render_fast_labelldx#$00; x-ref: $9745
copy_fast_label_loop
$9757bd 7e 80ldastr_status_fast,x; Write reverse-video "FAST" to row 24, cols 1-4 ($47C1-$47C4) ; x-ref: $9760
$975A9d c1 47staSCREEN_RAM_ROW24_COL01,x; Store reverse-video 'FAST' char at Screen RAM row 24, col 1 + X ($47C1-$47C4)
$975De8inx
$975Ee0 04cpx#$04
$9760d0 f5bnecopy_fast_label_loop
$976260rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Adds the pending 2-byte BCD score increment ($7A/$7B, in 10-point units) to
; the active player's 2-byte BCD score ($87/$88), clears the pending delta, and
; awards an extra life (capped at 9) whenever a 10,000-point boundary is crossed.
;
; Inputs: zpa_7A/zpa_7B (pending 16-bit packed BCD score delta, in 10-point units),
; zpf_87/zpa_88 (active player's 16-bit packed BCD score),
; zpa_8A (previous ten-thousands BCD digit threshold),
; zpa_B3 (active player's remaining lives)
; Outputs: zpf_87/zpa_88 (updated BCD score),
; zpa_7A/zpa_7B (cleared to $00),
; zpa_8A (updated ten-thousands BCD digit if changed),
; zpa_B3 (incremented on new 10,000-point digit, capped at $09),
; A, X, P clobbered (D flag cleared on exit)
; Side Effects: Temporarily pushes/pulls processor status on stack during BCD loop
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
add_pending_score_bcd
$976318clc; Clear carry and enter BCD mode for 4-digit score addition ; x-ref: $968b, $9862, $9878
$9764f8sed
$976508php; Save initial C=0, D=1 on stack for byte 0 iteration
$9766a2 00ldx#$00
$976828bcd_score_byte_loopplp; Restore BCD carry from previous byte ; x-ref: $9773
$9769b5 87ldazp_score_bcd_lo,x; Load player BCD score byte (X=0: tens/hundreds, X=1: thousands/ten-thousands)
$976B75 7aadczp_score_delta_bcd_lo,x; Add pending BCD score delta byte (X=0: 10s/100s, X=1: 1,000s/10,000s)
$976D95 87stazp_score_bcd_lo,x; Store updated player BCD score byte (X=0: 10s/100s, X=1: 1,000s/10,000s)
$976F08php; Preserve BCD carry across CPX
$9770e8inx
$9771e0 02cpx#$02
$9773d0 f3bnebcd_score_byte_loop
$977528plp; Discard final saved status and exit BCD mode
$9776d8cld
$9777a9 00lda#$00; Clear pending BCD score delta ($7A/$7B = 0)
$977985 7astazp_score_delta_bcd_lo; Clear pending BCD score delta low byte (10s/100s pts)
$977B85 7bstazp_score_delta_bcd_hi; Clear pending BCD score delta high byte (1,000s/10,000s pts)
$977Da5 88ldazp_score_bcd_hi; Check ten-thousands BCD nybble of updated score
$977F29 f0and#$f0
$9781c5 8acmpzp_extra_life_bcd_digit; Compare against last 10,000-point extra-life BCD nybble ($00..$90)
$9783f0 0dbeqadd_pending_score_done
$978585 8astazp_extra_life_bcd_digit; Record new 10,000-point BCD nybble threshold and award 1UP
$9787a6 b3ldxzp_player_lives; Load active player's total lives to award 10,000-pt 1UP
$9789e8inx
$978Ae0 0acpx#$0a; Cap total lives at 9 (displays up to 8 reserve frogs on HUD)
$978Cd0 02bnestore_extra_life_count
$978Ea2 09ldx#$09
store_extra_life_count
$979086 b3stxzp_player_lives; Store incremented total lives count (capped at 9) ; x-ref: $978c
add_pending_score_done
$979260rts; x-ref: $9783
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Checks the active player frog (Sprite 0) for river horizontal bounds, road
; vehicle background collisions, median/river sprite collisions (Lady Frog
; pickup, river alligator jaws, snake), and home-bay landing, bonus scoring,
; and round completion.
;
; Inputs: zpa_7D = frog state ($00 = alive, non-zero = dying/bay delay/standby)
; zpa_79 = hop-in-progress flag ($00 = landed, non-zero = mid-hop)
; VIC-II $D000/$D001/$D010 = Sprite 0 9-bit X and Y coordinates
; VIC-II $D01E/$D01F = latched sprite-sprite & sprite-bg collisions
; a_47FA/a_47FC = Sprite 2 (river gator) & Sprite 4 data pointers
; zpf_A7[0..4] = home-bay occupancy states; zpa_47 = life timer ticks;
; zpa_4F = pickup count; zpa_B2 = remaining unfilled home bays
; Outputs: zpa_53 = $6B (squash death sprite base) when zpa_7D == $00;
; zpa_5A = $D01E latch on median/river; zpa_4F, zpa_B4 updated on
; Lady Frog / fly pickup; on home-bay claim: zpf_A7[bay] = $FF,
; zpa_7F = zpa_86 = $60, zpa_B2 decremented (and if 0: zpa_77 = $00,
; zpa_85 = $01, +1,000 BCD pts); A, X, Y, P clobbered
; Side Effects: Reads (clearing) VIC-II $D01F and $D01E; updates $D015 and
; $D027 on Lady Frog pickup or bay arrival; draws home-bay frog
; tiles in Screen/Color RAM; triggers death, SFX/fanfare, and BCD
; score/1UP updates via subroutines
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
check_frog_collisions_and_home_bay
$9793a5 7dldazp_frog_state_timer; 0 = frog alive; >0 = death/bay pause; $FF = game over/standby ; x-ref: $8d97
$9795d0 24bnefrog_checks_inactive_rts; Skip all bounds/collision checks when frog is not alive
$9797a9 6blda#$6b; Default death sprite base = $6B (squash/hazard hit)
$979985 53stazp_death_spr_frame; Preload squash death sprite frame ($6B) for collision/bounds checks
$979Bad 01 d0lda$d001; Read player frog (Sprite 0) Y coordinate; Sprite 0 Y Pos
$979Ec9 98cmp#$98; At or below median strip (Y >= $98 / 152)?
$97A010 1abplcheck_landed_zone_collisions; Median/road/sidewalk have no lateral drift death; skip X check
$97A2ae 00 d0ldx$d000; Above median (river/home bay): check 9-bit X in [$0014, $0144); Sprite 0 X Pos
$97A5ad 10 d0lda$d010; Sprites 0-7 MSB of X coordinate
$97A829 01and#$01; Isolate Sprite 0 X-MSB (bit 8)
$97AAf0 08beqcheck_river_left_bound
$97ACe0 44cpx#$44; X-MSB = 1: drifted/hopped past right river limit ($0144 / 324)?
$97AE90 0cbcccheck_landed_zone_collisions
$97B020 b2 99jsrtrigger_frog_death; Carried off right edge of river -> trigger frog death
$97B360rts
check_river_left_bound
$97B4e0 14cpx#$14; X-MSB = 0: drifted/hopped past left river limit ($0014 / 20)? ; x-ref: $97aa
$97B6b0 04bcscheck_landed_zone_collisions
$97B820 b2 99jsrtrigger_frog_death; Carried off left edge of river -> trigger frog death
frog_checks_inactive_rts
$97BB60rts; x-ref: $9795
check_landed_zone_collisions
$97BCad 1f d0lda$d01f; Read & clear latched sprite-to-background collisions (kept in A) ; x-ref: $97a0, $97ae, $97b6; Sprite to Background Collision Detect
$97BFa6 79ldxzp_frog_hop_active; Defer road, sprite, and bay checks while frog is mid-hop ($79 != 0)
$97C1d0 6abnefrog_collision_done_rts
$97C3ae 01 d0ldx$d001; Dispatch landed collision check by frog Y zone; Sprite 0 Y Pos
$97C6e0 e8cpx#$e8; On bottom starting sidewalk (Y >= $E8 / 232)? Safe zone
$97C8b0 63bcsfrog_collision_done_rts
$97CAe0 a8cpx#$a8; Above top road lane (Y < $A8 / 168)? Branch to median/river/bay
$97CC30 08bmicheck_median_river_or_bay
$97CE29 01and#$01; Road lanes ($A8..$D8): test Sprite 0 vs. vehicle tile ($D01F bit 0)
$97D0f0 5bbeqfrog_collision_done_rts
$97D220 b2 99jsrtrigger_frog_death; Struck a road vehicle -> trigger squash death
$97D560rts
check_median_river_or_bay
$97D6e0 98cpx#$98; On purple median strip (Y == $98)? Check snake sprite collision ; x-ref: $97cc
$97D810 04bplcheck_sprite_collisions
$97DAe0 48cpx#$48; Above top river lane (Y < $48 -> home bay Y = $38)?
$97DC30 50bmihandle_home_bay_arrival
check_sprite_collisions
$97DEad 1e d0lda$d01e; Median or river ($48..$98): read & clear sprite-to-sprite collisions ; x-ref: $97d8; Sprite to Sprite Collision Detect
$97E185 5astazp_spr_coll_mask; Latch $D01E sprite-to-sprite collision bitmask (read clears $D01E)
$97E329 01and#SpriteCollisionMask.SPR0_FROG; Exit if Sprite 0 (player frog) was not involved in any collision
$97E5f0 46beqfrog_collision_done_rts
$97E7a5 5aldazp_spr_coll_mask; Reload latched $D01E sprite collision bitmask
$97E929 02and#SpriteCollisionMask.SPR1_LADY_FROG; Collided with Sprite 1 (Lady Frog on river log)?
$97EBf0 16beqcheck_river_gator_collision
$97EDa9 01lda#$01; Record Lady Frog pickup (zpa_4F = 1)
$97EF85 4fstazp_bay_pickup_cnt; Set home-bay pickup count = 1 (carrying Lady Frog)
$97F1ad 15 d0lda$d015; Sprite display Enable
$97F429 fdand#$fd; Clear bit 1 to hide Sprite 1 (Lady Frog picked up)
$97F68d 15 d0sta$d015; Sprite display Enable
$97F9a9 07lda#$07; Tint player frog (Sprite 0) yellow ($07) while carrying Lady Frog
$97FB8d 27 d0sta$d027; Sprite 0 Color
$97FEa9 01lda#SoundStreamId.SFX_LADY_FROG; Play Lady Frog pickup SFX (sound stream 1)
$980020 73 9bjsrstart_sound_stream
check_river_gator_collision
$9803a5 5aldazp_spr_coll_mask; Reload latched $D01E sprite collision bitmask ; x-ref: $97eb
$980529 04and#SpriteCollisionMask.SPR2_RIVER_GATOR; Collided with Sprite 2 (top-lane river alligator head)?
$9807f0 0abeqcheck_snake_collision
$9809ad fa 47ldaSCREEN_RAM_SPR2_PTR; Check Sprite 2 pointer ($67 = open jaws, $68 = closed mouth)
$980Cc9 68cmp#$68
$980Ef0 03beqcheck_snake_collision; Closed mouth ($68) is safe; open jaws ($67) is fatal
$981020 b2 99jsrtrigger_frog_death
check_snake_collision
$9813a5 5aldazp_spr_coll_mask; Reload latched $D01E sprite collision bitmask ; x-ref: $9807, $980e
$981529 08and#SpriteCollisionMask.SPR3_SNAKE; Collided with Sprite 3 (median/log snake)?
$9817f0 04beqcheck_sprite4_collision
$981920 b2 99jsrtrigger_frog_death; Bitten by snake -> trigger frog death
$981C60rts
check_sprite4_collision
$981Da5 5aldazp_spr_coll_mask; Reload latched $D01E sprite collision bitmask ; x-ref: $9817
$981F29 10and#SpriteCollisionMask.SPR4_HAZARD_SLOT; Collided with Sprite 4 (unimplemented hazard slot, e.g. otter)?
$9821f0 0abeqfrog_collision_done_rts
$9823ad fc 47ldaSCREEN_RAM_SPR4_PTR; Check Sprite 4 shape ptr ($47FC) for cut hazard frame $76 (unused in 8K ROM)
$9826c9 76cmp#$76
$9828d0 03bnefrog_collision_done_rts
$982A20 b2 99jsrtrigger_frog_death
frog_collision_done_rts
$982D60rts; x-ref: $97c1, $97c8, $97d0, $97e5, $9821, ...
handle_home_bay_arrival
$982Ea9 0dlda#$0d; Home-bay row (Y = $38): restore frog color to light green ($0D) ; x-ref: $97dc
$98308d 27 d0sta$d027; Sprite 0 Color
$983320 84 99jsrfind_frog_home_bay; Find home bay index (A = 0..4) for frog X, or $FF (N=1) on hedge
$983630 44bmifatal_home_bay_landing; Missed bay opening (hit hedge) -> fatal landing
$9838aatax
$9839b5 a7ldazp_home_bay_state,x; Read bay X state ($00=empty, $01=fly, $02=emerging, $FE=jaws, $FF=frog)
$983B30 3fbmifatal_home_bay_landing; Negative state ($FE open-jaws gator or $FF occupied bay) -> fatal
$983Dd0 41bnecheck_bay_bonus_fly; Positive state ($01 fly or $02 emerging gator) -> check fly bonus
$983F86 49claim_home_baystxzp_home_bay_idx; Pass claimed bay index X (0..4) to draw_home_bay_tiles ; x-ref: $9882, $988a
$9841a9 37lda#$37; Landed home-bay frog 3x2 base screencode ($37..$3C)
$984385 4estazp_bay_tile_id; Set home-bay base tile = $37 (landed frog)
$9845a9 05lda#$05; Hi-res green Color RAM nybble ($05) for landed bay frog
$984785 4dstazp_home_bay_color; Pass hi-res green ($05) Color RAM attr to draw_home_bay_tiles
$984920 32 94jsrdraw_home_bay_tiles
$984Ca9 fflda#HomeBayState.HOME_BAY_FROG_CLAIMED; Mark home bay X as claimed ($FF)
$984E95 a7stazp_home_bay_state,x; Record home bay X as claimed by landed frog ($FF)
$9850a9 02lda#SoundStreamId.SFX_HOME_BAY; Play home-bay arrival SFX (sound stream 2)
$985220 73 9bjsrstart_sound_stream
$9855a6 47ldxzp_frog_life_timer; Pass remaining life timer ticks (0..30) in X for time bonus
$985720 48 99jsrcalc_home_bay_bonus
$985A85 7astazp_score_delta_bcd_lo; Queue BCD bay + time + pickup score delta (10-pt units)
$985Ca9 60lda#$60; Arm 96-frame ($60) "TIME XX" banner ($7F) and bay pause ($86)
$985E85 7fstazp_bay_timer_banner_cnt; Start 96-frame ($60) "TIMER XX" status banner countdown
$986085 86stazp_bay_bonus_freeze; Arm 96-frame ($60) post-bay bonus freeze on life timer & respawn
$986220 63 97jsradd_pending_score_bcd
$9865c6 b2deczp_bays_remaining; Decrement remaining unfilled home bays (5 down to 0)
$9867d0 12bnehome_bay_done_rts
$9869a9 00lda#ScreenWipeState.SCREEN_WIPE_NEXT_ROUND; All 5 bays filled: set $77 = $00 to trigger next round after fanfare
$986B85 77stazp_screen_wipe_state; Mark round clear ($00) to advance round after fanfare
$986Da9 07lda#SoundStreamId.MELODY_ROUND_CLEAR; Play round-clear fanfare melody (sound stream 7)
$986F20 73 9bjsrstart_sound_stream
$9872a9 01lda#$01; Set round-clear freeze ($85 = 1) and +1,000 BCD bonus ($7B = $01)
$987485 85stazp_round_clear_freeze; Freeze frog control & life timer ($01) during round-clear fanfare
$987685 7bstazp_score_delta_bcd_hi; Queue +1,000-point round-clear bonus ($01 in BCD thousands)
$987820 63 97jsradd_pending_score_bcd
$987B60home_bay_done_rtsrts; x-ref: $9867
fatal_home_bay_landing
$987C20 b2 99jsrtrigger_frog_death; Fatal home-bay miss, duplicate bay, or open-jaws alligator ; x-ref: $9836, $983b
$987F60rts
$9880c9 01check_bay_bonus_flycmp#HomeBayState.HOME_BAY_BONUS_FLY; Bonus fly ($01) in bay? ($02 emerging gator is safe with no bonus) ; x-ref: $983d
$9882d0 bbbneclaim_home_bay
$9884a9 fflda#$ff; Clear active bonus-fly bay index ($FF = none)
$988685 b4stazp_bay_fly_idx; Mark bonus fly consumed ($FF = none active)
$9888e6 4finczp_bay_pickup_cnt; Increment home-bay pickup count (1 = fly, 2 = Lady Frog + fly)
$988A4c 3f 98jmpclaim_home_bay
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Tests whether the landed player frog on a river lane (rows 0..4) is
; horizontally supported within the 200-multicolor-pixel ($C8) virtual ring span
; of an active log, river alligator, or non-submerged turtle group, triggering
; river drowning ($6D splash sprite) if over open water or on a diving turtle
; group during its submerged phase ($09).
;
; Inputs: zpa_79 = hop-in-progress flag (0 = landed, non-zero = mid-hop)
; zpa_7D = death/respawn/standby timer (0 = active/alive)
; zpa_4A = signed frog row index (0..4 = river; -1 = bay; 5..10 = safe)
; zpa_AC = level layout index (0..4, via load_lane_cfg_header)
; zpf_8B[0..4] = per-lane coarse scroll offset in columns (0..49)
; zpf_94[0..4] = per-lane fine scroll offset in multicolor px (0..3)
; zpf_A2[0..4] = per-lane 12-step turtle dive phase (0..11; 9 = under)
; VIC-II $D000 / $D010 bit 0 = 9-bit Sprite 0 (player frog) X position
; zpa_B3 = remaining frog lives (decremented via trigger_frog_death)
; Outputs: Early exit (mid-hop, dying/standby, or non-river row): A clobbered,
; X and Y preserved.
; Active river check: A, X, Y clobbered; zpa_64 = zpa_4A; zpa_04/$05,
; zpa_0D, zpa_0E set via load_lane_cfg_header; zpa_2D, zpa_60..$63,
; zpa_65, zpa_66 updated with 2-px multicolor span calculations.
; On drowning: zpa_53 = $6D, zpa_7D = $5A, zpa_B3 decremented, zpa_84 = 1
; Side Effects: On drowning, calls trigger_frog_death (sets VIC-II $D027 = $0D
; light green and queues SID drowning SFX stream $03); else None
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
check_river_frog_support
$988Da5 79ldazp_frog_hop_active; Skip river support check while frog is mid-hop ($79 != 0) ; x-ref: $8d94
$988Fd0 0cbneriver_support_early_rts
$9891a5 7dldazp_frog_state_timer; Skip if frog is dying/respawning (>0) or in standby ($FF)
$9893d0 08bneriver_support_early_rts
$9895a5 4aldazp_frog_row; Check signed frog row ($FF=bay, 0..4=river, 5..10=median/road/start)
$989730 04bmiriver_support_early_rts
$9899c9 05cmp#$05; Only rows 0..4 are river lanes; rows >= 5 cannot drown
$989B30 01bmiscan_river_lane_objects
river_support_early_rts
$989D60rts; x-ref: $988f, $9893, $9897
scan_river_lane_objects
$989Ea6 4aldxzp_frog_row; Pass river lane index (0..4) to load_lane_cfg_header ; x-ref: $989b
$98A086 64stxzp_lane_cfg_idx; Set target river lane index (0..4) for load_lane_cfg_header
$98A220 4c 9djsrload_lane_cfg_header; Load zpa_04/$05 table ptr, zpa_0D obj type, zpa_0E size, Y = lane*8+1
$98A5a5 0eldazp_lane_obj_size; Precompute turtle span width in 2-px mc units: (count * 16) - 4
$98A70aasla
$98A80aasla
$98A90aasla
$98AA0aasla
$98AB38sec
$98ACe9 04sbc#$04
$98AE85 66stazp_turtle_span_width; Store turtle group support width (28 or 44 mc-px for 2 or 3 turtles)
$98B0a5 0eldazp_lane_obj_size; Precompute log/gator span width: (inner_cols * 4) + 18 (ASL leaves C=0)
$98B20aasla
$98B30aasla
$98B469 12adc#$12
$98B685 65stazp_log_span_width; Store log/alligator support width (38, 46, or 70 mc-px)
$98B8c8next_river_lane_objiny; Advance Y to next object offset byte (+2..+7) in lane config record ; x-ref: $9919, $991d, $9932
$98B9b1 04lda(zp_ptr_lane_cfg_lo),y; Read next river lane object column/subtype byte (+2..+7) from lane config table
$98BBf0 65beqdrown_frog_in_river; $00 terminator = no supporting object under frog -> drown
$98BD0aasla; Strip bit 7 subtype flag and scale 7-bit base col * 4 -> mc-px (C=0)
$98BE0aasla
$98BFa6 0dldxzp_lane_obj_type; Load river lane object type ($01=log/gator, $02=turtles)
$98C1e0 01cpx#LaneObjType.LANE_OBJ_LOG_OR_GATOR; Type 1 = right-scrolling log/alligator; Type 2 = left-scrolling turtles
$98C3f0 12beqcalc_log_span_bounds
$98C5a6 4aldxzp_frog_row; Turtles grow left from right anchor col and fine-scroll left by zpf_94,X
$98C738sec
$98C8f5 94sbczp_lane_fine_scroll,x; Subtract lane fine scroll (0..3 mc-px) for left-moving turtles
$98CA18clc
$98CB69 04adc#$04
$98CD85 63stazp_span_raw_right; Store pre-coarse-scroll turtle right bound: (base_col * 4) - fine + 4
$98CF38sec
$98D0e5 66sbczp_turtle_span_width; Subtract turtle group support width (28 or 44 mc-px) from right bound
$98D285 62stazp_span_raw_left; Store pre-coarse-scroll turtle left bound: right_bound - turtle_width
$98D44c e2 98jmpwrap_obj_bounds_mod200
calc_log_span_bounds
$98D7a6 4aldxzp_frog_row; Logs/gators grow right from left anchor col and fine-scroll right ; x-ref: $98c3
$98D918clc
$98DA75 94adczp_lane_fine_scroll,x; Add lane fine scroll (0..3 mc-px) for right-moving log/gator
$98DC85 62stazp_span_raw_left; Store pre-coarse-scroll log/gator left bound: (base_col * 4) + fine (C=0)
$98DE65 65adczp_log_span_width; Add log/alligator support width (mc-px) to left bound
$98E085 63stazp_span_raw_right; Store pre-coarse-scroll log/gator right bound: left_bound + log_width
wrap_obj_bounds_mod200
$98E2b5 8bldazp_lane_coarse_col,x; Convert river lane X coarse scroll offset (0..49 cols) * 4 -> 0..196 mc-px ; x-ref: $98d4
$98E40aasla
$98E50aasla
$98E685 2dstazp_scratch_byte; Cache coarse lane scroll offset in multicolor pixels (0..196)
$98E818clc
$98E965 62adczp_span_raw_left; Add coarse scroll to raw left bound and wrap modulo $C8 (200 mc-px = 50 cols)
$98EBb0 04bcswrap_span_left_sub200
$98EDc9 c8cmp#$c8
$98EF90 03bccstore_wrapped_span_left
wrap_span_left_sub200
$98F138sec; x-ref: $98eb
$98F2e9 c8sbc#$c8
store_wrapped_span_left
$98F485 60stazp_wrapped_span_left; Store wrapped inclusive left support bound (0..199 mc-px) ; x-ref: $98ef
$98F6a5 2dldazp_scratch_byte; Reload coarse lane scroll offset (mc-px) for right-bound wrap
$98F818clc
$98F965 63adczp_span_raw_right; Add coarse scroll to raw right bound and wrap modulo $C8 (200 mc-px)
$98FBb0 04bcswrap_span_right_sub200
$98FDc9 c8cmp#$c8
$98FF90 03bccstore_wrapped_span_right
wrap_span_right_sub200
$990138sec; x-ref: $98fb
$9902e9 c8sbc#$c8
store_wrapped_span_right
$990485 61stazp_wrapped_span_right; Store wrapped exclusive right support bound (0..199 mc-px) ; x-ref: $98ff
$9906ad 10 d0lda$d010; Shift Sprite 0 X-MSB ($D010 bit 0) into Carry; Sprites 0-7 MSB of X coordinate
$99094alsra
$990Aad 00 d0lda$d000; Sprite 0 X Pos
$990D6arora; A = 9-bit Sprite 0 X >> 1 (convert hi-res px to 2-px mc units)
$990E38sec
$990Fe9 06sbc#$06; A = (Sprite0_X >> 1) - 6 = frog center X from left border (X=24) in mc-px
$9911a6 61ldxzp_wrapped_span_right; Load wrapped exclusive right bound to test for ring-seam wrap
$9913e4 60cpxzp_wrapped_span_left; Does [zp_wrapped_span_left, zp_wrapped_span_right) wrap across $C8 seam?
$991590 13bcccheck_wrapped_obj_span
$9917c5 60cmpzp_wrapped_span_left; Contiguous span (left <= right): test zp_wrapped_span_left <= frog_x < right
$991990 9dbccnext_river_lane_obj
$991Bc5 61cmpzp_wrapped_span_right; Reject object if frog_x >= wrapped exclusive right support bound
$991Db0 99bcsnext_river_lane_obj
$991F4c 35 99jmpcheck_diving_turtle_submerged
$9922a9 6ddrown_frog_in_riverlda#$6d; Set river splash death sprite ($6D -> $5B40) and trigger drowning ; x-ref: $98bb, $9945
$992485 53stazp_death_spr_frame; Set initial drowning death sprite frame ($6D = water splash)
$992620 b2 99jsrtrigger_frog_death
river_log_supported_rts
$992960rts; x-ref: $9939
check_wrapped_obj_span
$992Ac5 60cmpzp_wrapped_span_left; Seam-wrapped span (right < left): supported if frog_x >= left or < right ; x-ref: $9915
$992Cb0 07bcscheck_diving_turtle_submerged
$992Ec5 61cmpzp_wrapped_span_right; Seam-wrapped span: supported if frog_x < wrapped exclusive right bound
$993090 03bcccheck_diving_turtle_submerged
$99324c b8 98jmpnext_river_lane_obj
check_diving_turtle_submerged
$9935a5 0dldazp_lane_obj_type; Frog is within object span; logs & river alligators always support ; x-ref: $991f, $992c, $9930
$9937c9 02cmp#LaneObjType.LANE_OBJ_TURTLES
$9939d0 eebneriver_log_supported_rts
$993Bb1 04lda(zp_ptr_lane_cfg_lo),y; Check turtle group subtype flag (bit 7 = 0: normal swimming turtles)
$993D10 08bplriver_turtle_supported_rts
$993Fa6 4aldxzp_frog_row; Load frog river lane index (0..4) to inspect turtle dive phase
$9941b5 a2ldazp_lane_turtle_dive_phase,x; Diving turtle group (bit 7 = 1): read lane dive phase (0..11; 9 = submerged)
$9943c9 09cmp#$09; Phase 9 = stage-2 fully submerged underwater -> frog drowns
$9945f0 dbbeqdrown_frog_in_river
river_turtle_supported_rts
$994760rts; x-ref: $993d
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Calculates the BCD home-bay arrival score bonus from remaining timer ticks and
; lady-frog/fly pickups, updates the "TIME XX" display value and bonus popup
; sprite (or hides Sprite 0), arms the respawn delay, and returns the BCD score
; delta in A.
;
; Inputs: X = remaining life timer ticks (zpa_47, 0..30 binary)
; zpa_4F = home-bay pickup count (0 = none, 1 = lady frog or fly, 2 = both)
; Outputs: A = packed BCD score bonus in units of 10 pts (stored to zpa_7A by caller)
; X = $05 (clobbered)
; zpa_59 = packed BCD remaining time ($00-$60) for "TIME XX" HUD status
; zpa_7D = $05 (post-bay respawn countdown timer)
; Side Effects: Temporarily enables 6502 decimal mode (SED..CLD); clears $D015
; bit 0 to hide Sprite 0 when zpa_4F == 0, or writes $65 ("200") /
; $66 ("400") to Sprite 0 pointer a_47F8 when zpa_4F >= 1.
; Note: CPX #$01 sets C=1 while SED is active, so ADC #$14 / #$28
; awards +150 / +290 pts ($15 / $29 BCD) instead of +200 / +400 pts.
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$9948f8calc_home_bay_bonussed; Enable BCD decimal mode for home-bay bonus calculation ; x-ref: $9857
$994918clc
$994Aa9 00lda#$00; Initialize BCD remaining-time bonus to $00
$994Ccabcd_time_bonus_loopdex; Count down remaining binary timer ticks (0..30) ; x-ref: $9951
$994D30 05bmiadd_bay_base_bonus
$994F69 02adc#$02; Add $02 BCD (20 pts / 2 half-sec) per tick; max $60 keeps C=0
$99514c 4c 99jmpbcd_time_bonus_loop
$995485 59add_bay_base_bonusstazp_bay_time_bcd; Save 2-digit BCD remaining time ($00-$60) for "TIME XX" status ; x-ref: $994d
$995669 05adc#$05; Add 50 pts ($05 BCD) base bonus for reaching a home bay
$9958a6 4fldxzp_bay_pickup_cnt; 0 = no pickup, 1 = lady frog or bay fly, 2 = both
$995Ad0 0dbneapply_pickup_bonus
$995Caatax; Save BCD score delta in X across $D015 read-modify-write
$995Dad 15 d0lda$d015; Sprite display Enable
$996029 feand#$fe; Hide player frog Sprite 0 (no bonus popup to display)
$99628d 15 d0sta$d015; Sprite display Enable
$99658atxa
$99664c 7e 99jmpset_bay_respawn_delay
$9969e0 01apply_pickup_bonuscpx#$01; Single pickup (lady frog OR fly)? Also sets C=1 since X >= 1 ; x-ref: $995a
$996Bd0 0abneapply_double_pickup_bonus
$996Da2 65ldx#$65; Show "200" bonus popup sprite ($65) on Sprite 0 ($47F8)
$996F8e f8 47stxSCREEN_RAM_SPR0_PTR; Set Sprite 0 pointer to "200" bonus popup frame ($65 -> $5940)
$997269 14adc#$14; Intended +200 pts (#20=$14), but SED + C=1 adds $15 BCD (+150 pts)
$99744c 7e 99jmpset_bay_respawn_delay
apply_double_pickup_bonus
$9977a2 66ldx#$66; Show "400" bonus popup sprite ($66) on Sprite 0 ($47F8) ; x-ref: $996b
$99798e f8 47stxSCREEN_RAM_SPR0_PTR; Set Sprite 0 pointer to "400" bonus popup frame ($66 -> $5980)
$997C69 28adc#$28; Intended +400 pts (#40=$28), but SED + C=1 adds $29 BCD (+290 pts)
set_bay_respawn_delay
$997Ea2 05ldx#$05; Arm 5-tick respawn timer (held while bay-bonus pause zpa_86 > 0) ; x-ref: $9966, $9974
$998086 7dstxzp_frog_state_timer; Store 5-frame post-bay respawn countdown ($05)
$9982d8cld; Restore binary arithmetic mode before returning
$998360rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Checks the player frog's 9-bit Sprite 0 X coordinate against the five home
; bay landing windows and returns the matching bay index (0..4) or $FF on miss.
;
; Inputs: VIC-II $D000 (Sprite 0 X low byte), $D010 bit 0 (Sprite 0 X-MSB),
; home_bay_x_bounds_tbl ($8124: five [min_x, max_x_excl] byte pairs)
; Outputs: A = home bay index (0..4, N=0) if inside a bay opening, or $FF (N=1)
; if the frog hit the hedge between/outside bays
; X = clobbered (bounds table index)
; Flags: N=1 on miss ($FF), N=0 on valid bay (0..4)
; Side Effects: None
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$9984ad 10 d0find_frog_home_baylda$d010; Read VIC-II Sprite X-MSB register ; x-ref: $9833; Sprites 0-7 MSB of X coordinate
$998729 01and#$01; Isolate Sprite 0 (player frog) X-coordinate bit 8 (+256)
$9989d0 05bnebay_4_x_msb_set
$998Ba2 00ldx#$00; X-MSB = 0: scan bays 0..3 (table indices 0..7)
$998D4c 92 99jmpcheck_bay_x_bounds_loop
$9990a2 08bay_4_x_msb_setldx#$08; X-MSB = 1: scan bay 4 only (table indices 8..9, X >= 256) ; x-ref: $9989
check_bay_x_bounds_loop
$9992ad 00 d0lda$d000; Player frog Sprite 0 X low byte ; x-ref: $998d, $99a9; Sprite 0 X Pos
$9995dd 24 81cmphome_bay_x_bounds_tbl,x; Compare against current bay inclusive min_x (X = 2 * bay)
$999890 12bcchome_bay_miss; X < min_x -> frog is in hedge left of this bay
$999Ae8inx
$999Bdd 24 81cmphome_bay_x_bounds_tbl,x; Compare against current bay exclusive max_x (X = 2 * bay + 1)
$999E90 0fbcchome_bay_found; min_x <= X < max_x_excl -> landed inside this home bay
$99A0e8inx
$99A1e0 08cpx#$08; Checked all 4 bays in X-MSB = 0 group (indices 0..7)?
$99A3f0 07beqhome_bay_miss
$99A5e0 0acpx#$0a; Checked bay 4 in X-MSB = 1 group (indices 8..9)?
$99A7f0 03beqhome_bay_miss
$99A94c 92 99jmpcheck_bay_x_bounds_loop
$99ACa9 ffhome_bay_misslda#$ff; Return $FF (N=1) to indicate missed bay / fatal landing ; x-ref: $9998, $99a3, $99a7
$99AE60rts
$99AF8ahome_bay_foundtxa; X = 2 * bay + 1 (1, 3, 5, 7, or 9) ; x-ref: $999e
$99B04alsra; A = X >> 1 = home bay index (0..4, N=0)
$99B160rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Initiates player frog death by arming the 90-frame death animation timer,
; starting the squash or drowning sound stream, restoring Sprite 0 color to
; light green, decrementing remaining lives, and setting the frog-died flag.
;
; Inputs: zpa_53 = initial death sprite pointer ($6B = squash/hazard/timeout,
; $6D = river drowning); zpa_B3 = current player remaining lives
; Outputs: zpa_7D = $5A (90-frame death animation/respawn countdown),
; zpa_B3 = zpa_B3 - 1, zpa_84 = $01 (frog-died flag);
; A = $01 (N=0, Z=0); X, Y, and sound-driver ZP ($56/$57, $6E-$76)
; modified via start_sound_stream
; Side Effects: Sets VIC-II $D027 (Sprite 0 color) to $0D (light green, clearing
; any yellow lady-frog tint) and queues SID stream $04 (squash) or
; $03 (drowning) via start_sound_stream
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$99B2a9 5atrigger_frog_deathlda#$5a; Arm 90-frame ($5A) 3-stage death animation & respawn timer ; x-ref: $8d80, $97b0, $97b8, $97d2, $9810, ...
$99B485 7dstazp_frog_state_timer; Store 90-frame ($5A) death animation and respawn countdown
$99B6a5 53ldazp_death_spr_frame; Check death sprite base ($6B = squash/hit, $6D = water splash)
$99B8c9 6bcmp#$6b
$99BAd0 04bneuse_drown_death_sfx
$99BCa9 04lda#SoundStreamId.SFX_SQUASH_DEATH; Stream 4 = road/hazard/timeout squash death SFX
$99BEd0 02bneplay_frog_death_sfx; Unconditional branch (A = $04 != 0)
$99C0a9 03use_drown_death_sfxlda#SoundStreamId.SFX_DROWN_DEATH; Stream 3 = river drowning/plunk death SFX ; x-ref: $99ba
$99C220 73 9bplay_frog_death_sfxjsrstart_sound_stream; Queue selected death SFX in SID sound driver ; x-ref: $99be
$99C5a9 0dlda#$0d; Restore Sprite 0 color to light green ($0D), clearing lady-frog yellow
$99C78d 27 d0sta$d027; Sprite 0 Color
$99CAc6 b3deczp_player_lives; Decrement active player's remaining frog lives
$99CCa9 01lda#$01
$99CE85 84stazp_frog_died_flag; Set frog-died flag ($01 = check lives/game over when zp_frog_state_timer hits 0)
$99D060rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Completes a 16-pixel directional frog hop by setting Sprite 0's landed frame,
; clearing mid-hop VIC-II background collisions, resetting the hop-active flag,
; and sampling the 30-frame prescaler into the hazard RNG latch.
;
; Inputs: X = landed Sprite 0 data pointer ($60 = up, $61 = right, $6F = down,
; $70 = left); zpa_48 = current 30-frame ($01..$1E) prescaler count
; Outputs: a_47F8 = X; zpa_79 = $00 (hop inactive); zpa_5D = A = zpa_48;
; X and Y preserved; N and Z set from zpa_48
; Side Effects: Updates Sprite 0 pointer ($47F8) in VIC Bank 1 Screen RAM and
; reads $D01F to clear latched sprite-to-background collisions
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$99D18e f8 47finish_frog_hopstxSCREEN_RAM_SPR0_PTR; Set Sprite 0 pointer ($47F8) to landed directional frog frame ; x-ref: $8f20, $8f46, $8f88, $8fbe
$99D4ad 1f d0lda$d01f; Clear latched mid-hop sprite-to-background collision flags; Sprite to Background Collision Detect
$99D7a9 00lda#$00
$99D985 79stazp_frog_hop_active; Clear hop-in-progress flag so landed checks & input resume
$99DBa5 48ldazp_half_sec_prescaler; Sample 30-frame prescaler on hop completion as player-timed RNG
$99DD85 5dstazp_hazard_rng_sample; Latch hop-sampled prescaler ($01..$1E) for fly, bay gator, and snake RNG
$99DF60rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Looks up the packed speed byte for lane zpa_0F (0..8) in lane_speed_profile_tbl using round speed tier zpa_AD (0..2) and speed mode zpa_5B (0 = FAST, 1 = SLOW), unpacking the delay countdown into zpf_32,X and scroll step into zpf_3B,X.
;
; Inputs: zpa_0F = lane index (0..8), zpa_AD = round speed tier (0..2), zpa_5B = game speed flag (0 = FAST, non-zero = SLOW), X = preserved via zpa_23
; Outputs: zpf_32 + zpa_0F = lane delay countdown (1..2 ticks), zpf_3B + zpa_0F = lane scroll step (1, 2, or 4 multicolor-px / quarter-tile units), A = scroll step, Y = (profile * 9) + zpa_0F (0..53), X = preserved
; Side Effects: Clobbers A, Y, zpa_23, zpa_2D
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
load_lane_speed_profile
$99E018clc; x-ref: $9348, $95ad
$99E1a5 adldazp_round_speed_tier; Round speed tier (0..2, cycles modulo 3 across rounds)
$99E3a4 5bldyzp_speed_mode; Game speed mode flag (0 = FAST, 1 = SLOW)
$99E5f0 02beqcalc_speed_tbl_index; FAST mode uses profiles 0..2
$99E769 03adc#$03; SLOW mode offsets to profiles 3..5
calc_speed_tbl_index
$99E985 2dstazp_scratch_byte; Save selected profile index P (0..5) ; x-ref: $99e5
$99EB86 23stxzp_saved_x; Save caller X register (lane index 0..8 or reset mode flag)
$99EDa6 0fldxzp_scroll_lane_idx; X = lane index (0..8)
$99EF0aasla
$99F00aasla
$99F10aasla; A = P * 8 (Carry = 0 since P <= 5)
$99F265 2dadczp_scratch_byte; A = P * 9 (row offset for 9 lanes per profile)
$99F465 0fadczp_scroll_lane_idx; A = (P * 9) + lane index (0..53)
$99F6a8tay
$99F7b9 e5 80ldalane_speed_profile_tbl,y; Packed byte: (scroll_step << 4) | frame_delay
$99FA29 0fand#$0f; Low nybble = delay countdown (1..2 ticks)
$99FC95 32stazp_lane_scroll_delay,x; Store unpacked 1..2-tick scroll delay in zp_lane_scroll_delay[0..8] ($32-$3A)
$99FEb9 e5 80ldalane_speed_profile_tbl,y
$9A014alsra
$9A024alsra
$9A034alsra
$9A044alsra; High nybble = scroll step (1, 2, or 4 multicolor px)
$9A0595 3bstazp_lane_scroll_step,x; Store nominal lane scroll step zp_lane_scroll_step[0..8] (1, 2, or 4 multicolor px)
$9A07a6 23ldxzp_saved_x; Restore caller X register
$9A0960rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Toggles Sprite 3 (snake) between river log lane 2 (Y = $68) and the median
; strip (Y = $98), loads the corresponding 9-bit left/right patrol X bounds,
; places the snake at the left bound facing right, and hides Sprite 3 until
; off-screen spawn conditions are met.
;
; Inputs: $D007 (current Sprite 3 Y position: $68 = river log, else median),
; zpa_BD/zpa_BE (tracked river-log left X low / $D010 bit-3 MSB),
; zpa_BF/zpa_C0 (tracked river-log right X low / $D010 bit-3 MSB)
; Outputs: zpa_B9/zpa_BA (active snake left X bound low / $D010 bit-3 MSB),
; zpa_BB/zpa_BC (active snake right X bound low / $D010 bit-3 MSB),
; zpa_C1 = $01 (rightward patrol direction), A clobbered (X, Y preserved)
; Side Effects: Updates VIC-II $D006, $D007, $D009 (unused Sprite 4 Y = $98 on
; median switch), $D010 bit 3, $D015 bit 3 (disables Sprite 3),
; and Screen RAM Sprite 3 pointer a_47FB ($69).
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
toggle_snake_patrol_lane
$9A0Aad 07 d0lda$d007; Check Sprite 3 Y: $68 = river log lane 2, $98 = median strip ; x-ref: $95f0, $9b4f; Sprite 3 Y Pos
$9A0Dc9 68cmp#$68
$9A0Ff0 18beqset_snake_median_bounds; On river log -> switch snake down to median strip
$9A11a9 68lda#$68
$9A138d 07 d0sta$d007; Move Sprite 3 up to river log lane 2 (Y = $68); Sprite 3 Y Pos
$9A16a5 bdldazp_snake_log_left_x_lo; Copy tracked river-log left X bound (low + $D010 bit-3 MSB)
$9A1885 b9stazp_snake_left_x_lo; Set active snake left X bound low byte from river log
$9A1Aa5 beldazp_snake_log_left_x_msb; Load tracked river-log left X-MSB shadow ($00 or $08)
$9A1C85 bastazp_snake_left_x_msb; Set active snake left X-MSB mask ($00/$08) from river log
$9A1Ea5 bfldazp_snake_log_right_x_lo; Copy tracked river-log right X bound (low + $D010 bit-3 MSB)
$9A2085 bbstazp_snake_right_x_lo; Set active snake right X bound low byte from river log
$9A22a5 c0ldazp_snake_log_right_x_msb; Load tracked river-log right X-MSB shadow ($00 or $08)
$9A2485 bcstazp_snake_right_x_msb; Set active snake right X-MSB mask ($00/$08) from river log
$9A264c 41 9ajmpreset_snake_at_left_bound
set_snake_median_bounds
$9A29a9 98lda#$98; x-ref: $9a0f
$9A2B8d 07 d0sta$d007; Move Sprite 3 down to purple median strip (Y = $98); Sprite 3 Y Pos
$9A2E8d 09 d0sta$d009; Also set unused Sprite 4 Y to $98 (vestigial hazard slot); Sprite 4 Y Pos
$9A31a9 82lda#$82; Median left bound = $0182 (386, wrapped off-screen left)
$9A3385 b9stazp_snake_left_x_lo; Set active snake left X bound low byte = $82
$9A35a9 08lda#$08
$9A3785 bastazp_snake_left_x_msb; Set active snake left X-MSB mask = $08 ($D010 bit 3)
$9A39a9 5alda#$5a; Median right bound = $015A (346, just past right border)
$9A3B85 bbstazp_snake_right_x_lo; Set active snake right X bound low byte = $5A
$9A3Da9 08lda#$08
$9A3F85 bcstazp_snake_right_x_msb; Set active snake right X-MSB mask = $08 ($D010 bit 3)
reset_snake_at_left_bound
$9A41a5 b9ldazp_snake_left_x_lo; Load active snake left patrol X bound low byte ; x-ref: $9a26
$9A438d 06 d0sta$d006; Position Sprite 3 X at active left patrol bound; Sprite 3 X Pos
$9A46ad 10 d0lda$d010; Sprites 0-7 MSB of X coordinate
$9A4929 f7and#$f7; Replace $D010 bit 3 (Sprite 3 X MSB) with zpa_BA
$9A4B05 baorazp_snake_left_x_msb; Apply active snake left X-MSB mask ($00 or $08)
$9A4D8d 10 d0sta$d010; Sprites 0-7 MSB of X coordinate
$9A50a9 01lda#$01; Patrol direction = 1 (slither right)
$9A5285 c1stazp_snake_dir; Set initial snake patrol direction = right ($01)
$9A54a9 69lda#$69; Sprite 3 pointer = $69 (right-facing snake frame 1)
$9A568d fb 47staSCREEN_RAM_SPR3_PTR; Set Sprite 3 pointer = $69 (right-facing snake frame 1 at $5A40)
$9A59ad 15 d0lda$d015; Sprite display Enable
$9A5C29 f7and#$f7; Disable Sprite 3 until re-enabled in off-screen window
$9A5E8d 15 d0sta$d015; Sprite display Enable
$9A6160rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Advances Sprite 3 (snake) by 1 pixel per frame along its active 9-bit
; patrol span, reverses patrol direction when hitting the left or right bound,
; and toggles its 2-frame directional slither animation every 12 frames.
;
; Inputs: $D006 / $D010 bit 3 = current Sprite 3 9-bit X coordinate
; zpa_B9 / zpa_BA = active left patrol bound X low / $D010 bit-3 MSB
; zpa_BB / zpa_BC = active right patrol bound X low / $D010 bit-3 MSB
; zpa_C1 = patrol direction ($00 = left, $01 = right)
; zpa_C2 = slither animation countdown timer (1..12 frames)
; a_47FB = current Sprite 3 data pointer ($69/$6A right, $73/$74 left)
; Outputs: zpa_52 = $01; zpa_C1 toggled ($00 <-> $01) on bound hit;
; zpa_C2 decremented (reloaded to $0C at zero when not turning);
; zpa_67..zpa_6D and zpa_23 updated via step_snake_sprite_x;
; A and Y clobbered; X preserved
; Side Effects: Updates VIC-II Sprite 3 9-bit X ($D006 and $D010 bit 3) and
; VIC Bank 1 Screen RAM Sprite 3 pointer a_47FB ($47FB)
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$9A62a9 01update_snake_patrollda#$01; Step Sprite 3 horizontally by 1 pixel per frame ; x-ref: $8d91
$9A6485 52stazp_snake_step_px; Set snake X step = 1 px for slither patrol
$9A6620 53 9bjsrstep_snake_sprite_x; Advance Sprite 3 9-bit X ($D006 / $D010 bit 3) in direction zpa_C1
$9A69ad 10 d0lda$d010; Sprites 0-7 MSB of X coordinate
$9A6C29 08and#$08; Isolate Sprite 3 X-MSB ($D010 bit 3) and test active left bound
$9A6Ec5 bacmpzp_snake_left_x_msb; Compare Sprite 3 X-MSB against active snake left X-MSB
$9A70d0 1bbnecheck_snake_right_bound; X-MSB != zpa_BA -> not at left patrol bound
$9A72ad 06 d0lda$d006; Sprite 3 X Pos
$9A75c5 b9cmpzp_snake_left_x_lo; Compare Sprite 3 X low byte against active snake left X bound
$9A77d0 14bnecheck_snake_right_bound
flip_snake_direction
$9A79a9 01lda#$01; At patrol bound: toggle direction zp_snake_dir ($00 = left <-> $01 = right) ; x-ref: $9a9b
$9A7B45 c1eorzp_snake_dir; Flip snake patrol direction ($00 = left <-> $01 = right)
$9A7D85 c1stazp_snake_dir; Store reversed snake patrol direction
$9A7Ff0 06beqset_snake_left_frame; New zp_snake_dir == 0 -> switched to leftward patrol
$9A81a9 69lda#$69; Right-facing snake frame 1 ($69 -> $5A40 in VIC Bank 1)
$9A838d fb 47staSCREEN_RAM_SPR3_PTR; Set Sprite 3 pointer = $69 (right-facing snake frame 1)
$9A8660rts
set_snake_left_frame
$9A87a9 73lda#$73; Left-facing snake frame 1 ($73 -> $5CC0 in VIC Bank 1) ; x-ref: $9a7f
$9A898d fb 47staSCREEN_RAM_SPR3_PTR; Set Sprite 3 pointer = $73 (left-facing snake frame 1)
$9A8C60rts
check_snake_right_bound
$9A8Dad 10 d0lda$d010; x-ref: $9a70, $9a77; Sprites 0-7 MSB of X coordinate
$9A9029 08and#$08; Isolate Sprite 3 X-MSB ($D010 bit 3) and test active right bound
$9A92c5 bccmpzp_snake_right_x_msb; Compare Sprite 3 X-MSB against active snake right X-MSB
$9A94d0 07bnetick_snake_anim
$9A96ad 06 d0lda$d006; Sprite 3 X Pos
$9A99c5 bbcmpzp_snake_right_x_lo; Compare Sprite 3 X low byte against active snake right X bound
$9A9Bf0 dcbeqflip_snake_direction; Hit right patrol bound -> reverse direction
$9A9Dc6 c2tick_snake_animdeczp_snake_anim_timer; Tick slither animation frame countdown timer ; x-ref: $9a94
$9A9Fd0 14bnesnake_patrol_done
$9AA1a9 0clda#$0c; Reload 12-frame slither animation period
$9AA385 c2stazp_snake_anim_timer; Reload 12-frame snake slither animation timer ($0C)
$9AA5a5 c1ldazp_snake_dir; Select sprite frame pair for current direction ($00 = left, $01 = right)
$9AA7f0 11beqtoggle_snake_left_frame
$9AA9a9 69lda#$69; Toggle right-facing snake frames: $69 <-> $6A
$9AABcd fb 47cmpSCREEN_RAM_SPR3_PTR; Check if Sprite 3 is showing right-facing snake frame 1 ($69)
$9AAEd0 06bnestore_snake_right_frame1
$9AB0a9 6alda#$6a; Was frame 1 ($69) -> switch to right-facing frame 2 ($6A)
$9AB28d fb 47staSCREEN_RAM_SPR3_PTR; Set Sprite 3 pointer = $6A (right-facing snake frame 2 at $5A80)
$9AB560snake_patrol_donerts; x-ref: $9a9f
store_snake_right_frame1
$9AB68d fb 47staSCREEN_RAM_SPR3_PTR; Was frame 2 ($6A) -> restore right-facing frame 1 ($69) ; x-ref: $9aae
$9AB960rts
toggle_snake_left_frame
$9ABAa9 73lda#$73; Toggle left-facing snake frames: $73 <-> $74 ; x-ref: $9aa7
$9ABCcd fb 47cmpSCREEN_RAM_SPR3_PTR; Check if Sprite 3 is showing left-facing snake frame 1 ($73)
$9ABFd0 06bnestore_snake_left_frame1
$9AC1a9 74lda#$74; Was frame 1 ($73) -> switch to left-facing frame 2 ($74)
$9AC38d fb 47staSCREEN_RAM_SPR3_PTR; Set Sprite 3 pointer = $74 (left-facing snake frame 2 at $5D00)
$9AC660rts
store_snake_left_frame1
$9AC78d fb 47staSCREEN_RAM_SPR3_PTR; Was frame 2 ($74) -> restore left-facing frame 1 ($73) ; x-ref: $9abf
$9ACA60rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Advances the tracked 9-bit river-log patrol bounds (zpa_BD/zpa_BE and
; zpa_BF/zpa_C0) along river lane 2, carries Sprite 3 (snake) rightward with
; the log when patrolling lane 2 ($D007 != $98), and handles off-screen
; (X >= $015A) Sprite 3 reveal (zpa_B0 != 0) and RNG lane switching.
;
; Inputs: X = $02 (river log lane 2 index; preserved across all calls)
; zpf_3B,X = lane 2 scroll step in multicolor pixels (1..4)
; zpa_BD/zpa_BE, zpa_BF/zpa_C0 = tracked river-log left/right X bounds
; zpa_B0 = snake hazard unlock flag ($00 = Rounds 1-2, $01 = Round 3+)
; zpa_C1 = snake slither patrol direction ($00 = left, $01 = right)
; zpa_5C/zpa_5D = consumed/current hop-sampled RNG state
; $D006, $D007, $D010 bit 3, $D015 bit 3 = live VIC-II Sprite 3 state
; Outputs: zpa_52 = 2 * zpf_3B,X (hi-res sprite pixel step, 2..8)
; zpa_BD/zpa_BE, zpa_BF/zpa_C0 = stepped rightward with lane 2 wrap
; zpa_B9..zpa_BC = synced with log when $D007 != $98 (or reset on switch)
; zpa_67..zpa_6D, zpa_23 = updated (zpa_2D clobbered when $D007 != $98)
; zpa_5C = updated on RNG hit; zpa_C1 = $01 if lane switch triggers
; X preserved ($02); A, Y, N, Z, C clobbered
; Side Effects: Steps VIC-II Sprite 3 9-bit X ($D006, $D010 bit 3) when on log;
; sets $D015 bit 3 when unlocked and off-screen (X >= $015A);
; may call toggle_snake_patrol_lane ($D006/$D007/$D009/$D010/$D015,
; Screen RAM Sprite 3 pointer a_47FB)
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
update_snake_log_and_spawn
$9ACBb5 3bldazp_lane_scroll_step,x; Load river log lane 2 (X = 2) scroll step in multicolor px (1..4) ; x-ref: $93c2
$9ACD0aasla; Convert multicolor pixels to hi-res sprite X pixels (2..8 px)
$9ACE85 52stazp_snake_step_px; Save lane pixel step for carrying Sprite 3 on river log
$9AD0a9 bdlda#<zp_snake_log_left_x_lo; Point zp_ptr_spr_x_lo/hi to river-log left X bound ($00BD)
$9AD285 67stazp_ptr_spr_x_lo; Store river-log left X-bound ($00BD) pointer low byte
$9AD4a9 00lda#>zp_snake_log_left_x_lo; Zero-page high byte ($00) of river-log left X bound
$9AD685 68stazp_ptr_spr_x_hi; Store river-log X-bound pointer high byte ($00)
$9AD8a9 belda#<zp_snake_log_left_x_msb; Point zp_ptr_spr_x_msb_lo/hi to $00BE (river-log left X-MSB shadow)
$9ADA85 69stazp_ptr_spr_x_msb_lo
$9ADCa9 00lda#>zp_snake_log_left_x_msb; Zero-page high byte ($00) of river-log left X-MSB shadow
$9ADE85 6astazp_ptr_spr_x_msb_hi
$9AE0a9 08lda#$08; Sprite 3 X-MSB bitmask ($08 = bit 3)
$9AE285 6bstazp_spr_x_msb_mask; Set Sprite 3 X-MSB mask ($08) for river-log bounds
$9AE420 ac 9cjsrstep_lane_sprite_x; Advance tracked river-log left 9-bit X bound along lane 2
$9AE7a9 bflda#<zp_snake_log_right_x_lo; Point zp_ptr_spr_x_lo/hi to river-log right X bound ($00BF; hi stays $00)
$9AE985 67stazp_ptr_spr_x_lo; Point low byte to river-log right X-bound ($00BF; high byte stays $00)
$9AEBa9 c0lda#<zp_snake_log_right_x_msb; Point zp_ptr_spr_x_msb_lo/hi to $00C0 (river-log right X-MSB; hi byte stays $00)
$9AED85 69stazp_ptr_spr_x_msb_lo
$9AEF20 ac 9cjsrstep_lane_sprite_x; Advance tracked river-log right 9-bit X bound along lane 2
$9AF2a9 98lda#$98; Check if Sprite 3 is patrolling the purple median strip (Y = $98)
$9AF4cd 07 d0cmp$d007; Sprite 3 Y Pos
$9AF7f0 1fbeqcheck_snake_visibility; On median strip -> skip river-log drift sync
$9AF9a5 c1ldazp_snake_dir; On river log (Y = $68): save snake's own patrol direction in zpa_2D
$9AFB85 2dstazp_scratch_byte; Save snake's independent patrol direction during river-log drift step
$9AFDa9 01lda#$01; Temporarily force direction = right ($01) to match lane 2 log drift
$9AFF85 c1stazp_snake_dir; Override snake direction = right ($01) during river-log drift step
$9B01a5 bdldazp_snake_log_left_x_lo; Load drifted river-log left X bound low byte
$9B0385 b9stazp_snake_left_x_lo; Sync active snake left X bound low byte with river log
$9B05a5 beldazp_snake_log_left_x_msb; Load drifted river-log left X-MSB shadow ($00 or $08)
$9B0785 bastazp_snake_left_x_msb; Sync active snake left X-MSB mask ($00/$08) with river log
$9B09a5 bfldazp_snake_log_right_x_lo; Load drifted river-log right X bound low byte
$9B0B85 bbstazp_snake_right_x_lo; Sync active snake right X bound low byte with river log
$9B0Da5 c0ldazp_snake_log_right_x_msb; Load drifted river-log right X-MSB shadow ($00 or $08)
$9B0F85 bcstazp_snake_right_x_msb; Sync active snake right X-MSB mask ($00/$08) with river log
$9B1120 53 9bjsrstep_snake_sprite_x; Carry Sprite 3 rightward by zpa_52 pixels along with river log
$9B14a5 2dldazp_scratch_byte; Restore snake's independent slither patrol direction
$9B1685 c1stazp_snake_dir; Restore snake's independent slither patrol direction
check_snake_visibility
$9B18ad 15 d0lda$d015; Test whether Sprite 3 (snake) is currently enabled ($D015 bit 3) ; x-ref: $9af7; Sprite display Enable
$9B1B29 08and#$08
$9B1Dd0 1bbnecheck_snake_lane_switch; Already visible -> check for off-screen RNG lane switch
$9B1Fa5 b0ldazp_snake_unlocked; Hidden: check if snake hazard is unlocked (Round 3+ / layout >= 2)
$9B21f0 2fbeqsnake_log_update_done; Locked on Rounds 1-2 -> keep Sprite 3 disabled
$9B23ad 10 d0lda$d010; Sprites 0-7 MSB of X coordinate
$9B2629 08and#$08; Require Sprite 3 X-MSB == 1 (X >= $0100) before revealing
$9B28f0 28beqsnake_log_update_done
$9B2Aad 06 d0lda$d006; Sprite 3 X Pos
$9B2Dc9 5acmp#$5a; Require X >= $015A (346, off-screen past right border) to avoid pop-in
$9B2F90 21bccsnake_log_update_done
$9B31ad 15 d0lda$d015; Sprite display Enable
$9B3409 08ora#$08; Enable Sprite 3 ($D015 bit 3) inside off-screen wrap zone ($015A..$018F)
$9B368d 15 d0sta$d015; Sprite display Enable
$9B3960rts
check_snake_lane_switch
$9B3Aad 10 d0lda$d010; x-ref: $9b1d; Sprites 0-7 MSB of X coordinate
$9B3D29 08and#$08; Visible: only allow lane switch when Sprite 3 is off-screen (X >= $0100)
$9B3Ff0 11beqsnake_log_update_done
$9B41ad 06 d0lda$d006; Sprite 3 X Pos
$9B44c9 5acmp#$5a; Confirm Sprite 3 is past right border (X >= $015A)
$9B4690 0abccsnake_log_update_done
$9B48a9 10lda#$10; RNG upper threshold $10 for snake log <-> median lane switch
$9B4A20 9a 9cjsrcheck_hazard_rng; Returns Z = 1 (A = $00) once per qualifying frog-hop RNG sample
$9B4Dd0 03bnesnake_log_update_done
$9B4F20 0a 9ajsrtoggle_snake_patrol_lane; Switch snake between river log ($68) and median ($98), hiding Sprite 3
snake_log_update_done
$9B5260rts; x-ref: $9b21, $9b28, $9b2f, $9b3f, $9b46, ...
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Configures zero-page pointer and bitmask parameters for Sprite 3 (snake) and
; steps its 9-bit horizontal coordinate ($D006 / $D010 bit 3) by zpa_52 pixels
; in direction zpa_C1 via step_sprite_x_9bit.
;
; Inputs: zpa_52 = horizontal pixel step count (1 px patrol or log scroll step)
; zpa_C1 = horizontal direction ($00 = left, non-zero = right)
; X = caller index (preserved across step_sprite_x_9bit)
; Outputs: zpa_67/zpa_68 = $D006, zpa_69/zpa_6A = $D010, zpa_6B = $08,
; zpa_6C = zpa_C1, zpa_6D = $00; A, Y = updated Sprite 3 X low byte;
; X preserved
; Side Effects: Updates VIC-II Sprite 3 9-bit X coordinate ($D006 and $D010
; bit 3) with horizontal wraparound; modifies zpa_23
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$9B53a9 06step_snake_sprite_xlda#<$d006; Target X-low pointer zpa_67/zpa_68 = $D006 (VIC-II Sprite 3 X) ; x-ref: $9a66, $9b11
$9B5585 67stazp_ptr_spr_x_lo; Store Sprite 3 X ($D006) pointer low byte
$9B57a9 d0lda#>$d006
$9B5985 68stazp_ptr_spr_x_hi; Store Sprite 3 X ($D006) pointer high byte
$9B5Ba9 10lda#<$d010; Point zp_ptr_spr_x_msb_lo/hi to VIC-II $D010 (Sprites 0-7 X-MSB register)
$9B5D85 69stazp_ptr_spr_x_msb_lo
$9B5Fa9 d0lda#>$d010
$9B6185 6astazp_ptr_spr_x_msb_hi
$9B63a9 08lda#$08; Sprite 3 X-MSB bitmask ($08 = bit 3 in $D010)
$9B6585 6bstazp_spr_x_msb_mask; Pass Sprite 3 X-MSB mask ($08) to step_sprite_x_9bit
$9B67a5 52ldazp_snake_step_px; Pixel step count (1 px slither or river-log scroll step)
$9B6985 6dstazp_spr_x_step_cnt; Pass snake pixel step count (1 or 2..8 px) to step_sprite_x_9bit
$9B6Ba5 c1ldazp_snake_dir; Movement direction ($00 = left, $01 = right)
$9B6D85 6cstazp_spr_x_step_dir; Pass snake horizontal step direction ($00 = left, $01 = right)
$9B6F20 b6 9cjsrstep_sprite_x_9bit; Step Sprite 3 9-bit X coordinate with wraparound
$9B7260rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Starts or preempts playback of a SID sound/music stream (0..8) when no stream
; is active (zpa_6E == 0) or when the requested stream ID has equal or higher
; priority than the active stream (A >= zpa_6F). Parses the 2-byte stream header
; (tempo period, frequency mode, and active voice count) and advances the stream
; pointer (zpa_56/zpa_57) to the 3-byte SID voice setup block.
;
; Inputs: A = requested sound stream ID ($00..$08; higher ID = higher priority:
; 0=hop, 1=lady frog, 2=home bay, 3/4=death, 5=low-time alert,
; 6=game over, 7=round clear, 8=theme)
; zpa_6E = stream active flag ($00 = idle, $01 = playing)
; zpa_6F = currently active stream ID ($00..$08)
; sound_stream_ptr_table = 16-bit sound stream pointer table ($9D6B)
; Outputs: zpa_75 = requested stream ID
; If accepted: zpa_6F = stream ID, zpa_6E = $01, zpa_73 = $01 (voice init
; pending), zpa_74 = $01 if preempting an active stream, zpa_56/zpa_57 =
; stream_base + 2, zpa_70 = tempo, zpa_72 = tempo - 1, zpa_76 = freq mode
; ($80 direct hi-byte / $00 scaled), zpa_71 = voice count (1..3);
; A = zpa_57, X = stream_id * 2, Y = $01
; If rejected (A < zpa_6F while active): active state and X/Y preserved,
; A = zpa_75, C = 0
; Side Effects: None (SID register updates are deferred to per-frame tick s_9BBA)
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$9B7385 75start_sound_streamstazp_req_sound_stream_id; Save requested sound stream ID (0..8) ; x-ref: $8d8b, $8e18, $8e93, $90af, $959b, ...
$9B75a5 6eldazp_sound_active; Check if a sound stream is currently playing
$9B77d0 35bnecheck_sound_priority; Stream active: check whether new request preempts it
$9B79a5 75init_sound_streamldazp_req_sound_stream_id; Record accepted stream ID as active priority level ; x-ref: $9bb8
$9B7B85 6fstazp_sound_stream_id; Latch accepted stream ID ($00..$08) as active stream & priority
$9B7Da9 01lda#$01; Set stream active (zp_sound_active=1) and voice-init pending (zpa_73=1)
$9B7F85 6estazp_sound_active; Mark SID sound stream playback active ($01)
$9B8185 73stazp_sound_voice_init_flag; Request SID voice setup ($01) on first playback frame
$9B83a5 6fldazp_sound_stream_id; Load active stream ID ($00..$08) to index pointer table
$9B850aasla; Word-index into sound_stream_ptr_table (stream_id * 2)
$9B86aatax
$9B87bd 6b 9dldasound_stream_ptr_table,x; Load 16-bit sound stream pointer low byte
$9B8A85 56stazp_ptr_sound_stream_lo; Store active SID sound stream pointer low byte
$9B8Cbd 6c 9dldasound_stream_ptr_table + 1,x; Load 16-bit sound stream pointer high byte
$9B8F85 57stazp_ptr_sound_stream_hi; Store active SID sound stream pointer high byte
$9B91a0 00ldy#$00; Read header byte 0: bit 7 = freq mode, bits 0..6 = tempo
$9B93b1 56lda(zp_ptr_sound_stream_lo),y; Read stream header byte 0 (freq mode | 7-bit tempo)
$9B9529 7fand#$7f; Extract 7-bit tempo period (frames per step)
$9B9785 70stazp_sound_tempo_period; Store active stream tempo period (1, 3, 4, or 12 frames/step)
$9B9985 72stazp_sound_tempo_cnt; Initialize tempo counter to stream tempo period
$9B9Bc6 72deczp_sound_tempo_cnt; Preload counter to tempo-1 so step 0 fires right after init
$9B9Db1 56lda(zp_ptr_sound_stream_lo),y
$9B9F29 80and#$80; Isolate freq mode ($80 = direct hi-byte, $00 = scaled note)
$9BA185 76stazp_sound_freq_mode; Store stream frequency mode ($80 = direct hi-byte SFX, $00 = note * 64)
$9BA3c8iny; Read header byte 1: active SID voice count per step (1..3)
$9BA4b1 56lda(zp_ptr_sound_stream_lo),y; Fetch header byte 1 (active voice count 1..3)
$9BA685 71stazp_sound_voice_cnt; Store active SID voice count per step (1..3)
$9BA8a9 02lda#$02; Advance pointer past 2-byte header to voice setup bytes
$9BAA20 70 9cjsradvance_sound_stream_ptr
$9BAD60start_sound_donerts; x-ref: $9bb2
check_sound_priority
$9BAEa5 75ldazp_req_sound_stream_id; Compare requested stream ID against active stream ID ; x-ref: $9b77
$9BB0c5 6fcmpzp_sound_stream_id; Compare requested stream ID against active stream priority
$9BB290 f9bccstart_sound_done; Ignore request if lower priority (requested < active)
$9BB4a9 01lda#$01; Request 1-frame SID gate-off/mute before new stream starts
$9BB685 74stazp_sound_preempt_mute; Set 1-frame SID preemption mute flag ($01)
$9BB8d0 bfbneinit_sound_stream; Unconditional (A = 1): initialize preempting stream
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Advances the active 3-voice SID sound/music stream once per frame: performs a
; 1-frame SID gate-off/mute on preemption, initializes SID voice envelopes, 50%
; pulse widths, waveforms, and gate bits on stream startup, and steps per-voice
; frequencies on each tempo tick until reaching the $FF end-of-stream marker.
;
; Inputs: zpa_6E = stream active flag ($00 = idle, $01 = playing)
; zpa_74 = preemption 1-frame mute flag ($01 = gate off before init)
; zpa_73 = voice setup pending flag ($01 = load 3-byte voice header)
; zpa_70 = tempo period (frames per note/SFX step)
; zpa_72 = current frame tempo counter ($00..zpa_70-1)
; zpa_71 = active voice count per step (1..3)
; zpa_76 = frequency encoding ($80 = direct hi-byte, $00 = note * 64)
; zpa_56/zpa_57 = 16-bit pointer to current byte in active sound stream
; Outputs: Updates zpa_74, zpa_73, zpa_72, zpa_6E, and zpa_56/zpa_57 according to
; stream phase; A, X, Y, N, Z, C modified (X, Y preserved when idle or
; between tempo ticks)
; Side Effects: Writes SID volume/filter ($D417-$D418) and Voices 1-3 frequency,
; pulse width, control/gate, attack/decay, and sustain/release
; registers ($D400-$D414). Original ROM bug at $9BD5/$9BD7 clears
; zero-page zpa_0C and zpa_13 instead of SID $D40C and $D413.
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$9BBAa5 6eupdate_sound_streamldazp_sound_active; Check if a SID sound/music stream is currently active ; x-ref: $8efe
$9BBCf0 52beqsound_update_done; Idle: nothing to play
$9BBEa5 74ldazp_sound_preempt_mute; Preempting an active stream? Mute/gate-off for 1 frame first
$9BC0f0 07beqcheck_sound_voice_init
$9BC2a9 00lda#$00; Clear preemption mute flag so next frame initializes voices
$9BC485 74stazp_sound_preempt_mute; Clear 1-frame SID preemption mute flag ($00)
$9BC64c 61 9cjmpsilence_sid_voices; Gate off Voices 1-3 and zero SID volume for 1 frame
check_sound_voice_init
$9BC9a5 73ldazp_sound_voice_init_flag; First frame of new stream? Configure SID voices from 3-byte setup block ; x-ref: $9bc0
$9BCBf0 44beqtick_sound_tempo; Voices already configured: advance tempo counter
$9BCDa9 00lda#$00; Mute SID volume ($D418) and zero Voice 1 Attack/Decay ($D405)
$9BCF8d 18 d4sta$d418; Select Filter Mode and Volume
$9BD28d 05 d4sta$d405; Voice 1: Attack / Decay Cycle Control
$9BD585 0cstazp_lane_obj_col; Original ROM bug: intended STA $D40C (Voice 2 AD), assembled as ZP $0C
$9BD785 13stazp_block_len_hi; Original ROM bug: intended STA $D413 (Voice 3 AD), assembled as ZP $13
$9BD98d 17 d4sta$d417; Disable SID filter resonance and voice filter routing; Filter Resonance Control / Voice Input Control
$9BDCa9 08lda#$08; Set 50% pulse duty cycle ($0800) on Voices 1-3 ($D403/$D40A/$D411)
$9BDE8d 03 d4sta$d403; Voice 1: Pulse Waveform Width - High-Nybble
$9BE18d 0a d4sta$d40a; Voice 2: Pulse Waveform Width - High-Nybble
$9BE48d 11 d4sta$d411; Voice 3: Pulse Waveform Width - High-Nybble
$9BE7a2 00ldx#$00; X = SID voice register offset ($00, $07, $0E); Y = voice index (0..2)
$9BE9a0 00ldy#$00
$9BEBb1 56init_sid_voice_looplda(zp_ptr_sound_stream_lo),y; Read packed voice setup byte (hi nybble = Sustain, lo nybble = Waveform) ; x-ref: $9c05
$9BED29 f0and#$f0; Store Sustain level (bits 7..4) with Release = 0 to $D406,X
$9BEF9d 06 d4sta$d406,x; Voice 1: Sustain / Release Cycle Control
$9BF2b1 56lda(zp_ptr_sound_stream_lo),y
$9BF40aasla; Shift low-nybble waveform bits into high nybble (bits 7..4)
$9BF50aasla
$9BF60aasla
$9BF70aasla
$9BF809 01ora#$01; Set Gate bit (bit 0) and write Voice Control register ($D404,X)
$9BFA9d 04 d4sta$d404,x; Voice 1: Control Register
$9BFD8atxa
$9BFE18clc
$9BFF69 07adc#$07; Advance X by 7 bytes to next SID voice register block
$9C01aatax
$9C02c8iny
$9C03c0 03cpy#$03; Configure all 3 SID voices
$9C05d0 e4bneinit_sid_voice_loop
$9C07a9 03lda#$03; Advance stream pointer past 3-byte voice setup block to step data
$9C0920 70 9cjsradvance_sound_stream_ptr
$9C0Ca9 00lda#$00; Clear voice-init pending flag; step 0 plays on next frame
$9C0E85 73stazp_sound_voice_init_flag; Mark SID voice setup complete ($00)
$9C1060sound_update_donerts; x-ref: $9bbc, $9c17
$9C11e6 72tick_sound_tempoinczp_sound_tempo_cnt; Increment frame tempo divider and compare against tempo period (zpa_70) ; x-ref: $9bcb
$9C13a5 72ldazp_sound_tempo_cnt; Read updated sound tempo frame counter
$9C15c5 70cmpzp_sound_tempo_period; Reached active stream tempo period?
$9C17d0 f7bnesound_update_done; Hold current frequencies until tempo period elapses
$9C19a9 00lda#$00; Reset tempo counter for new step
$9C1B85 72stazp_sound_tempo_cnt; Zero sound tempo counter for next note/SFX step
$9C1Da9 0flda#$0f; Enable full SID master volume ($0F, no filter)
$9C1F8d 18 d4sta$d418; Select Filter Mode and Volume
$9C22a2 00ldx#$00; X = SID voice register offset ($00, $07, $0E); Y = step voice index
$9C24a0 00ldy#$00
update_sid_voice_freq_loop
$9C26b1 56lda(zp_ptr_sound_stream_lo),y; Read next stream frequency byte; $FF marks end of stream ; x-ref: $9c55
$9C28c9 ffcmp#$ff
$9C2Af0 31beqend_sound_stream; End-of-stream sentinel reached: stop playback and silence SID
$9C2Ca5 76ldazp_sound_freq_mode; Check frequency mode ($80 = direct hi-byte SFX, $00 = scaled note * 64)
$9C2Ef0 0cbeqset_scaled_voice_freq
$9C30b1 56lda(zp_ptr_sound_stream_lo),y; Direct mode: write byte to Freq Hi ($D401,X) and $00 to Freq Lo ($D400,X)
$9C329d 01 d4sta$d401,x; Voice 1: Frequency Control - High-Byte
$9C35a9 00lda#$00
$9C379d 00 d4sta$d400,x; Voice 1: Frequency Control - Low-Byte
$9C3Af0 11beqnext_sid_voice_freq; Unconditional branch (A = $00) to advance to next voice
set_scaled_voice_freq
$9C3Cb1 56lda(zp_ptr_sound_stream_lo),y; Scaled mode (note * 64): Freq Hi ($D401,X) = note >> 2 (leaves bit 1 in C) ; x-ref: $9c2e
$9C3E4alsra
$9C3F4alsra
$9C409d 01 d4sta$d401,x; Voice 1: Frequency Control - High-Byte
$9C43b1 56lda(zp_ptr_sound_stream_lo),y; Reload note (preserving C = bit 1); 3 RORs place bits 1..0 into bits 7..6
$9C456arora
$9C466arora
$9C476arora
$9C4829 c0and#$c0; Mask (note & $03) << 6 into Freq Lo ($D400,X)
$9C4A9d 00 d4sta$d400,x; Voice 1: Frequency Control - Low-Byte
$9C4D8anext_sid_voice_freqtxa; x-ref: $9c3a
$9C4E18clc
$9C4F69 07adc#$07; Step X by +7 to next SID voice block
$9C51aatax
$9C52c8iny
$9C53c4 71cpyzp_sound_voice_cnt; Loop across all active voices in this step (1..3)
$9C55d0 cfbneupdate_sid_voice_freq_loop
$9C57a5 71ldazp_sound_voice_cnt; Advance stream pointer by active voice count to next step
$9C5920 70 9cjsradvance_sound_stream_ptr
$9C5C60rts
$9C5Da9 00end_sound_streamlda#$00; Mark sound stream inactive (zp_sound_active = $00) ; x-ref: $9c2a
$9C5F85 6estazp_sound_active; Clear SID sound stream active flag ($00)
$9C61a9 00silence_sid_voiceslda#$00; Mute SID volume ($D418) and clear Gate/Control on Voices 1-3 ; x-ref: $9bc6
$9C638d 18 d4sta$d418; Select Filter Mode and Volume
$9C668d 04 d4sta$d404; Voice 1: Control Register
$9C698d 0b d4sta$d40b; Voice 2: Control Register
$9C6C8d 12 d4sta$d412; Voice 3: Control Register
$9C6F60rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Advances the 16-bit SID sound stream pointer ($56/$57) by the unsigned byte
; offset in A.
;
; Inputs: A = unsigned byte offset to add, zp_ptr_sound_stream_lo/zp_ptr_sound_stream_hi = 16-bit stream pointer
; Outputs: zp_ptr_sound_stream_lo/zp_ptr_sound_stream_hi = advanced 16-bit stream pointer, A = updated high byte (X, Y preserved)
; Side Effects: None
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
advance_sound_stream_ptr
$9C7018clc; Clear carry for 16-bit pointer addition ; x-ref: $9baa, $9c09, $9c59
$9C7165 56adczp_ptr_sound_stream_lo; Add byte offset in A to stream pointer low byte
$9C7385 56stazp_ptr_sound_stream_lo; Update sound stream pointer low byte
$9C75a9 00lda#$00; Propagate carry into stream pointer high byte
$9C7765 57adczp_ptr_sound_stream_hi; Add carry into sound stream pointer high byte
$9C7985 57stazp_ptr_sound_stream_hi; Update sound stream pointer high byte
$9C7B60rts; Return with X and Y preserved
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Advances the round-robin home bay cursor (zpa_80) modulo 5 and selects the
; candidate bay if it is empty and passes the hop-latched RNG threshold ($05).
;
; Inputs: zpa_80 = previous round-robin home bay index (0..4)
; zpf_A7[0..4] = per-bay occupancy state ($00 = empty)
; zpa_5D, zpa_5C = hop-sampled RNG state (via check_hazard_rng)
; Outputs: On success: X = selected bay index (0..4), zpa_49 = X, zpa_80 = X,
; A = $00, N = 0, Z = 1 (zpa_5C updated via check_hazard_rng)
; On reject: X = $FF (N = 1, Z = 0), zpa_80 = advanced bay index (0..4)
; Side Effects: Consumes hop-sampled RNG (zpa_5C = zpa_5D) when a bay is selected
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
try_select_empty_home_bay
$9C7Ca6 80ldxzp_home_bay_cursor; Advance round-robin home bay cursor (0..4) ; x-ref: $8ccd, $8d05
$9C7Ee8inx
$9C7Fe0 05cpx#$05; Wrap bay cursor past bay 4 back to bay 0
$9C81d0 02bnecheck_candidate_bay
$9C83a2 00ldx#$00
$9C85b5 a7check_candidate_bayldazp_home_bay_state,x; Check candidate bay state ($00 = empty, non-zero = occupied/hazard) ; x-ref: $9c81
$9C87d0 0cbnebay_select_reject
$9C89a9 05lda#$05; Upper RNG threshold $05 (out of 1..30 hop-sampled ticks)
$9C8B20 9a 9cjsrcheck_hazard_rng; Returns A = $00 (Z=1, N=0) if triggered and unconsumed
$9C8Ed0 05bnebay_select_reject
$9C9086 49stxzp_home_bay_idx; Set target bay index for draw_home_bay_tiles (preserves N=0)
$9C9286 80stxzp_home_bay_cursor; Save updated round-robin bay cursor; return X = 0..4 (N=0)
$9C9460rts
$9C9586 80bay_select_rejectstxzp_home_bay_cursor; Save advanced bay cursor even when candidate is rejected ; x-ref: $9c87, $9c8e
$9C97a2 ffldx#$ff; Return X = $FF (N=1) so caller BMI skips spawn
$9C9960rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Tests whether the hop-latched prescaler RNG value (zp_hazard_rng_sample) is at
; or below the upper threshold in A and has not yet been consumed
; (zp_hazard_rng_sample != zp_hazard_rng_consumed), latching zp_hazard_rng_sample
; into zp_hazard_rng_consumed on a match so each sample triggers at most once.
;
; Inputs: A = inclusive upper RNG threshold ($05 for home-bay fly/alligator,
; $10 for snake row switch); zp_hazard_rng_sample = 30-frame prescaler
; sample latched on frog hop; zp_hazard_rng_consumed = previously
; consumed zp_hazard_rng_sample value
; Outputs: A = $00 (Z=1) if triggered (and zp_hazard_rng_consumed updated to
; zp_hazard_rng_sample), or A = $01 (Z=0) if rejected; X and Y
; preserved; C and N modified
; Side Effects: None
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$9C9Ac5 5dcheck_hazard_rngcmpzp_hazard_rng_sample; Compare upper threshold A against hop-sampled RNG value ($01..$1E) ; x-ref: $9b4a, $9c8b
$9C9Cb0 03bcscheck_rng_unconsumed; Branch if A >= zp_hazard_rng_sample (sample within threshold)
$9C9Ea9 01rng_check_rejectlda#$01; Return $01 (Z=0): out of range or sample already consumed ; x-ref: $9ca5
$9CA060rts
check_rng_unconsumed
$9CA1a5 5dldazp_hazard_rng_sample; Load current hop-sampled RNG value ($01..$1E) ; x-ref: $9c9c
$9CA3c5 5ccmpzp_hazard_rng_consumed; Compare against last consumed RNG sample to prevent duplicate triggers
$9CA5f0 f7beqrng_check_reject; Reject duplicate trigger until a later hop latches a different value
$9CA785 5cstazp_hazard_rng_consumed; Record sample as consumed so it triggers at most once
$9CA9a9 00lda#$00; Return $00 (Z=1): RNG check passed
$9CAB60rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Converts lane X's multicolor scroll step (zpf_3B,X) into hi-res sprite pixels
; (zpa_6D = 2 * zpf_3B,X), loads the lane's horizontal scroll direction into
; zpa_6C, and falls through into step_sprite_x_9bit to advance a 9-bit sprite X
; coordinate or X-bound shadow along with river lane X.
;
; Inputs: X = lane index (0..8; called for river lanes 0, 2, and 3)
; zpf_3B,X = lane scroll step in multicolor pixels (1..4)
; lane_scroll_dir_tbl,X = lane scroll direction ($00 = left, $01 = right)
; zpa_67/zpa_68 = pointer to target 8-bit X-coordinate low byte
; zpa_69/zpa_6A = pointer to target X-MSB bitfield byte ($D010 or ZP)
; zpa_6B = sprite X-MSB bitmask ($02 = Spr 1, $04 = Spr 2, $08 = Spr 3)
; Outputs: *(zpa_67) and *(zpa_69) updated with wrapped 9-bit X coordinate;
; zpa_6C = lane scroll direction; zpa_6D = $00; X preserved;
; A and Y = final X low byte (via step_sprite_x_9bit fall-through)
; Side Effects: Falls through into step_sprite_x_9bit; updates VIC-II sprite
; X/MSB registers ($D002/$D004, $D010) or ZP X-bound shadows;
; modifies zpa_23
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$9CACb5 3bstep_lane_sprite_xldazp_lane_scroll_step,x; Load lane X scroll step in multicolor pixels (1..4) ; x-ref: $93a8, $93bb, $9ae4, $9aef
$9CAE0aasla; Convert multicolor px to hi-res sprite X pixels (2..8 px)
$9CAF85 6dstazp_spr_x_step_cnt; Store hi-res pixel step count (2..8 px) for step_sprite_x_9bit
$9CB1bd 1b 81ldalane_scroll_dir_tbl,x; Load lane X horizontal direction ($00 = left, $01 = right)
$9CB485 6cstazp_spr_x_step_dir; Set step direction and fall through into step_sprite_x_9bit
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Steps a 9-bit sprite X-coordinate left or right by zpa_6D pixels via indirect
; low-byte and X-MSB pointers, wrapping horizontally across the 50-column virtual
; lane span ($18F -> $000 moving right; $000 -> $18E moving left). Entered via
; fall-through from s_9CAC (river lane sprites & snake log bounds) or JSR from
; s_9B53 (Sprite 3 snake movement).
;
; Inputs: zpa_67/zpa_68 = pointer to 8-bit X-coordinate low byte ($D002/$D004/$D006 or ZP)
; zpa_69/zpa_6A = pointer to X-MSB bitfield byte ($D010 or ZP shadow)
; zpa_6B = sprite bitmask in *(zpa_69) ($02 = Spr 1, $04 = Spr 2, $08 = Spr 3)
; zpa_6C = horizontal direction ($00 = left, non-zero = right)
; zpa_6D = pixel step count (1..8 pixels, must be >= 1)
; X = caller index preserved across routine via zpa_23
; Outputs: *(zpa_67) and *(zpa_69) updated with wrapped 9-bit X coordinate;
; zpa_6D = $00; X preserved; A and Y = final X low byte
; Side Effects: Updates VIC-II sprite X/MSB registers ($D002/$D004/$D006, $D010)
; or zero-page X-bound shadows; modifies zpa_23
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$9CB686 23step_sprite_x_9bitstxzp_saved_x; Preserve caller's X register (e.g. lane index 0..8) ; x-ref: $9b6f
$9CB8a2 00ldx#$00; X = 0 for (zp,X) indirect addressing while Y holds X-low
$9CBAa1 67step_x_pixel_looplda(zp_ptr_spr_x_lo,x); Read current 8-bit X-coordinate low byte ; x-ref: $9ce3
$9CBCa8tay
$9CBDa5 6cldazp_spr_x_step_dir; Direction flag: 0 = step left, non-zero = step right
$9CBFf0 27beqstep_x_left; Branch to decrement path when stepping left
$9CC1a1 69lda(zp_ptr_spr_x_msb_lo,x); Read current X-MSB bitfield byte ($D010 or ZP shadow)
$9CC3c0 ffcpy#$ff; At $0FF? Next +1 pixel crosses into $100 (MSB = 1)
$9CC5d0 04bnecheck_right_x_wrap
$9CC705 6borazp_spr_x_msb_mask; Set sprite X-MSB bit for $0FF -> $100 carry
$9CC981 69sta(zp_ptr_spr_x_msb_lo,x); Write updated X-MSB bitfield back to target
$9CCB25 6bcheck_right_x_wrapandzp_spr_x_msb_mask; Test whether sprite X-MSB bit is currently set ; x-ref: $9cc5
$9CCDf0 0ebeqinc_x_low_byte
$9CCFc0 8fcpy#$8f; With MSB = 1, check right wrap limit $18F (399 px)
$9CD1d0 0abneinc_x_low_byte
$9CD3a5 6bldazp_spr_x_msb_mask; At $18F: clear X-MSB bit to wrap right edge to $000
$9CD549 ffeor#$ff
$9CD721 69and(zp_ptr_spr_x_msb_lo,x)
$9CD981 69sta(zp_ptr_spr_x_msb_lo,x); Write cleared X-MSB bitfield back on right-edge wrap
$9CDBa0 ffldy#$ff; Preload $FF so following INY wraps X low byte to $00
$9CDDc8inc_x_low_byteiny; Advance X low byte by +1 pixel ; x-ref: $9ccd, $9cd1
store_x_low_and_next
$9CDE98tya; x-ref: $9d06
$9CDF81 67sta(zp_ptr_spr_x_lo,x); Write updated X low byte back to target
$9CE1c6 6ddeczp_spr_x_step_cnt; Decrement remaining pixel steps; loop until 0
$9CE3d0 d5bnestep_x_pixel_loop
$9CE5a6 23ldxzp_saved_x; Restore caller's X register
$9CE760rts
$9CE8c0 00step_x_leftcpy#$00; Stepping left: check if X low byte is at $00 ; x-ref: $9cbf
$9CEAd0 19bnedec_x_low_byte
$9CECa1 69lda(zp_ptr_spr_x_msb_lo,x); Read current X-MSB bitfield byte ($D010 or ZP shadow)
$9CEE25 6bandzp_spr_x_msb_mask; At low byte $00: test X-MSB to distinguish $100 vs $000
$9CF0f0 0bbeqwrap_left_x_edge; MSB == 0 means X == $000: wrap around left edge
$9CF2a5 6bldazp_spr_x_msb_mask; At $100: clear X-MSB bit for borrow into $0FF
$9CF449 ffeor#$ff
$9CF621 69and(zp_ptr_spr_x_msb_lo,x)
$9CF881 69sta(zp_ptr_spr_x_msb_lo,x); Write cleared X-MSB bitfield back on $100 -> $0FF borrow
$9CFA4c 05 9djmpdec_x_low_byte
$9CFDa1 69wrap_left_x_edgelda(zp_ptr_spr_x_msb_lo,x); x-ref: $9cf0
$9CFF05 6borazp_spr_x_msb_mask; At $000: set X-MSB bit to wrap around to right side
$9D0181 69sta(zp_ptr_spr_x_msb_lo,x); Write X-MSB bitfield with bit set on $000 -> $18E wrap
$9D03a0 8fldy#$8f; Preload $8F (subsequent DEY yields $18E = 398 px)
$9D0588dec_x_low_bytedey; Decrement X low byte by 1 pixel ; x-ref: $9cea, $9cfa
$9D064c de 9cjmpstore_x_low_and_next
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Swaps (or clones) the active player's VIC-II sprite registers ($D001..$D010
; and $D015, skipping live raster/control registers $D011 and $D012) with the
; 21-byte inactive-player backup buffer ($0100..$0114), then tail-jumps to
; swap_full_player_zp_state ($9D32) to swap or copy the 60-byte per-player
; zero-page state ($0087..$00C2 <-> $00C3..$00FE).
;
; Inputs: X = transfer mode ($00 = swap active <-> backup; non-zero = copy active -> backup)
; VIC-II $D001..$D015 and zpf_87..$00C2 = active player hardware/ZP state
; $0100..$0114 and zpf_C3..$00FE = inactive player backup buffers (read if X = $00)
; Outputs: $0100..$0114 = overwritten with previous VIC-II $D001..$D015 reads
; zpf_87..$00C2 and zpf_C3..$00FE = swapped (X = $00) or copied (X != $00) via $9D32
; zpa_2D = scratch byte overwritten when X = $00
; Y = $00, A = original $0087 byte, X preserved, N/Z/C clobbered
; Side Effects: When X = $00, restores VIC-II $D001..$D010 and $D015 from $0100..$0114
; (writes to read-only $D013/$D014 ignored; $D000 reset by caller).
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
swap_player_sprites_and_state
$9D09a0 15ldy#$15; Sweep Y = $15 down to $01 ($D015..$D001; $D000 reset by caller) ; x-ref: $8e32, $963c
player_sprite_swap_loop
$9D0Bb9 00 d0lda$d000,y; Read live VIC-II register ($D001..$D015) ; x-ref: $9d28; Sprite 0 X Pos
$9D0Ec0 11cpy#$11; Skip $D011 (VIC Control 1 / raster MSB) on hardware write-back
$9D10f0 12beqstore_backup_sprite_reg
$9D12c0 12cpy#$12; Skip $D012 (raster IRQ compare line) on hardware write-back
$9D14f0 0ebeqstore_backup_sprite_reg
$9D16e0 00cpx#$00; X = 0 swaps active <-> backup; X != 0 copies active -> backup
$9D18d0 0abnestore_backup_sprite_reg
$9D1A85 2dstazp_scratch_byte; Save outgoing player's VIC-II register byte in scratch
$9D1Cb9 ff 00lda@w backup_vic_sprite_regs - 1,y; Load incoming player's backed-up register byte ($0100..$0114)
$9D1F99 00 d0sta$d000,y; Restore incoming player's sprite register ($D013/$D014 writes ignored); Sprite 0 X Pos
$9D22a5 2dldazp_scratch_byte; Reload outgoing player's VIC-II register byte for backup buffer
store_backup_sprite_reg
$9D2499 ff 00sta@w backup_vic_sprite_regs - 1,y; Store outgoing/cloned VIC-II byte into $0100..$0114 backup buffer ; x-ref: $9d10, $9d14, $9d18
$9D2788dey
$9D28d0 e1bneplayer_sprite_swap_loop; Loop down through $D001 (exits at Y = 0)
$9D2A4c 32 9djmpswap_full_player_zp_state; Tail-call $9D32 to swap/copy 60-byte player ZP state ($87..$C2 <-> $C3..$FE)
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Swaps (or copies) the 4-byte player score and extra-life state header
; ($0087..$008A) between the active player slot and the inactive player backup
; buffer ($00C3..$00C6); also provides the swap_full_player_zp_state ($9D32)
; tail entry used by $9D09 to swap or clone the entire 60-byte per-player
; zero-page block ($0087..$00C2 <-> $00C3..$00FE).
;
; Inputs: X = transfer mode ($00 = swap active <-> backup; non-zero = copy active -> backup)
; zpf_87..zpa_8A ($0087..$008A via $9D2D, or $0087..$00C2 via $9D32) = active player state
; $00C3..$00C6 (via $9D2D) or $00C3..$00FE (via $9D32) = inactive player backup (read if X = $00)
; Outputs: zpf_87..zpa_8A (or $0087..$00C2 via $9D32) = updated from $00C3.. when X = $00
; $00C3..$00C6 (or $00C3..$00FE via $9D32) = overwritten with previous $0087.. bytes
; zpa_2D = scratch byte overwritten when X = $00
; Y = $00, A = original $0087 byte, X preserved, N/Z/C clobbered
; Side Effects: None
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
swap_player_score_state
$9D2Da0 04ldy#$04; Count = 4 bytes: BCD score ($87-$88), pad ($89), and 1UP threshold ($8A) ; x-ref: $8d6a
$9D2F4c 34 9djmpplayer_zp_swap_loop
swap_full_player_zp_state
$9D32a0 3cldy#$3c; Tail entry from $9D09: count = 60 ($3C) bytes ($87..$C2 <-> $C3..$FE) ; x-ref: $9d2a
$9D34b9 86 00player_zp_swap_looplda@w zp_score_bcd_lo - 1,y; Load active player byte (1-based Y index into $0087..$00C2) ; x-ref: $9d2f, $9d49
$9D37e0 00cpx#$00; X = 0 swaps active <-> backup; X != 0 copies active -> backup
$9D39d0 0abnestore_backup_zp_byte
$9D3B85 2dstazp_scratch_byte; Save active player byte temporarily during swap
$9D3Db9 c2 00lda@w zp_player_state_backup - 1,y; Read inactive player's corresponding backup byte ($00C3..$00FE)
$9D4099 86 00sta@w zp_score_bcd_lo - 1,y; Promote backup byte into active player zero-page slot
$9D43a5 2dldazp_scratch_byte; Reload previous active player byte for inactive backup slot
store_backup_zp_byte
$9D4599 c2 00sta@w zp_player_state_backup - 1,y; Store previous active byte into inactive player backup buffer ; x-ref: $9d39
$9D4888dey
$9D49d0 e9bneplayer_zp_swap_loop
$9D4B60rts
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
; Resolves the active level's lane configuration table pointer and loads the
; 2-byte header (object type and size/count) for the target lane's 8-byte record,
; leaving Y positioned right before its object column list.
;
; Inputs: zpa_AC = level layout index (0..4, selecting level1..level5_lane_cfg_tbl)
; zpa_64 = lane index (0..4 river lanes, 5..8 road lanes)
; Outputs: zpa_04/zpa_05 = pointer to active level's 72-byte lane config table
; zpa_0D = lane object type ($01 = log/alligator, $02 = turtles, $03 = road)
; zpa_0E = object size/count (log inner cols, turtles/group, or vehicle cols)
; Y = (zpa_64 * 8) + 1 (caller INY reads object offsets at bytes +2..+7)
; A = zpa_0E, X = (zpa_AC * 2) + 1
; Side Effects: None
; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
load_lane_cfg_header
$9D4Ca5 acldazp_level_layout_idx; Current level layout index (0..4) ; x-ref: $9180, $98a2
$9D4E0aasla; Word offset X = level * 2 into level_lane_cfg_ptr_tbl
$9D4Faatax
$9D50bd 36 80ldalevel_lane_cfg_ptr_tbl,x; Load active level lane config table pointer low byte
$9D5385 04stazp_ptr_lane_cfg_lo; Store active level lane config table pointer low byte
$9D55e8inx
$9D56bd 36 80ldalevel_lane_cfg_ptr_tbl,x; Load active level lane config table pointer high byte
$9D5985 05stazp_ptr_lane_cfg_hi; Store active level lane config table pointer high byte
$9D5Ba5 64ldazp_lane_cfg_idx; Target lane index (0..4 river, 5..8 road)
$9D5D0aasla; Multiply lane index by 8 (8 bytes per lane record)
$9D5E0aasla
$9D5F0aasla
$9D60a8tay; Y = lane * 8 (start of lane's 8-byte config record)
$9D61b1 04lda(zp_ptr_lane_cfg_lo),y; Record +0: lane object type ($01=log/gator, $02=turtles, $03=vehicle)
$9D6385 0dstazp_lane_obj_type; Store active lane object type ($01=log/gator, $02=turtles, $03=road)
$9D65c8iny
$9D66b1 04lda(zp_ptr_lane_cfg_lo),y; Record +1: object size/count (log inner cols, turtle count, or vehicle width)
$9D6885 0estazp_lane_obj_size; Store active lane object size/count (inner log cols, turtles/group, or vehicle cols)
$9D6A60rts; Return with Y = lane * 8 + 1 (before object positions at +2..+7)
; SID sound/music stream pointer table (9 16-bit entries, indexed by sound ID 0..8 * 2 in $9B73; higher index = higher priority)
sound_stream_ptr_table
$9D6B.wordsound_stream_0_sfx, sound_stream_1_sfx, sound_stream_2_home_bay_sfx, sound_stream_3_death_sfx, sound_stream_4_death_alt_sfx; x-ref: $9b87, $9b8c
$9D75.wordsound_stream_5_alert, sound_stream_6_melody, sound_stream_7_round_clear, sound_stream_8_theme
; Sound stream 8 (93 bytes): 3-voice theme melody (tempo=12, scaled freq mode, V1-V3 SR=$90/pulse, 29 3-byte steps, $FF end)
sound_stream_8_theme
$9D7D.byte$0c, $03, $94, $94, $94, $71, $2d, $00; x-ref: $9d7b
$9D85.byte$59, $2d, $38, $59, $22, $00, $59, $2d
$9D8D.byte$38, $71, $2d, $00, $59, $2d, $38, $59
$9D95.byte$22, $00, $59, $2d, $38, $77, $32, $00
$9D9D.byte$77, $32, $3c, $71, $26, $00, $71, $32
$9DA5.byte$3c, $64, $32, $00, $00, $32, $3c, $00
$9DAD.byte$22, $00, $00, $32, $3c, $77, $32, $00
$9DB5.byte$77, $32, $3c, $71, $22, $00, $71, $32
$9DBD.byte$3c, $64, $32, $00, $64, $32, $3c, $96
$9DC5.byte$22, $00, $96, $32, $3c, $86, $32, $00
$9DCD.byte$77, $32, $3c, $71, $22, $00, $64, $32
$9DD5.byte$3c, $59, $2d, $38, $ff
; Sound stream 6 (126 bytes): 2-voice melody (tempo=4, scaled freq mode, V1-V2 SR=$90/pulse, 60 2-byte steps, $FF end)
sound_stream_6_melody
$9DDA.byte$04, $02, $94, $94, $04, $64, $2a, $64; x-ref: $9d77
$9DE2.byte$2a, $64, $2a, $64, $2a, $00, $32, $00
$9DEA.byte$32, $64, $32, $64, $32, $86, $2a, $86
$9DF2.byte$2a, $86, $2a, $00, $00, $86, $32, $86
$9DFA.byte$32, $86, $32, $86, $32, $a9, $22, $a9
$9E02.byte$22, $a9, $22, $a9, $22, $96, $32, $86
$9E0A.byte$32, $7f, $32, $71, $32, $64, $2a, $64
$9E12.byte$2a, $64, $2a, $64, $2a, $64, $32, $64
$9E1A.byte$32, $64, $32, $64, $32, $59, $26, $59
$9E22.byte$26, $59, $26, $00, $00, $64, $32, $64
$9E2A.byte$32, $64, $32, $00, $00, $4b, $2d, $4b
$9E32.byte$2d, $4b, $2d, $00, $00, $64, $32, $64
$9E3A.byte$32, $64, $32, $00, $00, $55, $22, $55
$9E42.byte$22, $55, $22, $00, $00, $64, $32, $64
$9E4A.byte$32, $64, $32, $00, $00, $43, $2a, $43
$9E52.byte$2a, $43, $2a, $43, $2a, $ff
; Sound stream 7 (64 bytes): 2-voice round-clear fanfare (tempo=12, scaled freq mode, V1-V2 SR=$90/pulse, 29 2-byte steps, $FF end)
sound_stream_7_round_clear
$9E58.byte$0c, $02, $94, $94, $04, $59, $38, $64; x-ref: $9d79
$9E60.byte$43, $71, $38, $77, $43, $86, $38, $00
$9E68.byte$43, $71, $38, $00, $43, $59, $38, $64
$9E70.byte$43, $71, $38, $64, $43, $59, $38, $00
$9E78.byte$43, $59, $38, $00, $43, $59, $38, $64
$9E80.byte$43, $71, $38, $77, $43, $86, $38, $00
$9E88.byte$43, $71, $38, $00, $43, $86, $3c, $77
$9E90.byte$43, $71, $3c, $64, $43, $59, $38, $ff
; Sound stream 0 (30 bytes): 3-voice SFX (tempo=1, direct hi-byte freq mode $80, 8 3-byte steps, $FF end)
$9E98sound_stream_0_sfx.byte$81, $03, $84, $44, $24, $09, $24, $17; x-ref: $9d6b
$9EA0.byte$26, $fe, $fe, $2f, $fe, $fe, $30, $fe
$9EA8.byte$fe, $39, $fe, $fe, $3a, $fe, $fe, $4b
$9EB0.byte$e2, $fe, $42, $4c, $e3, $ff
; Sound stream 4 (93 bytes): 3-voice frog death SFX when frame=$6B (tempo=1, direct hi-byte freq mode $80, 29 3-byte steps, $FF end)
sound_stream_4_death_alt_sfx
$9EB6.byte$81, $03, $c4, $24, $14, $08, $2d, $e2; x-ref: $9d73
$9EBE.byte$1b, $fe, $fe, $18, $79, $fe, $16, $43
$9EC6.byte$fe, $14, $3d, $fe, $12, $fe, $fe, $10
$9ECE.byte$32, $fe, $10, $2e, $fe, $0f, $2b, $fe
$9ED6.byte$10, $43, $fe, $0d, $3f, $fe, $0b, $24
$9EDE.byte$fe, $0c, $21, $fe, $0b, $1f, $fe, $0a
$9EE6.byte$1e, $32, $0a, $1d, $30, $09, $1b, $2d
$9EEE.byte$09, $2c, $3e, $09, $19, $fe, $08, $19
$9EF6.byte$fe, $08, $17, $26, $07, $17, $43, $07
$9EFE.byte$17, $42, $07, $14, $3f, $06, $15, $2f
$9F06.byte$07, $14, $2e, $13, $2c, $fe, $06, $13
$9F0E.byte$1e, $06, $12, $1d, $ff
; Sound stream 3 (72 bytes): 2-voice frog death SFX (tempo=1, direct hi-byte freq mode $80, 33 2-byte steps, $FF end)
sound_stream_3_death_sfx
$9F13.byte$81, $02, $64, $14, $04, $08, $0f, $07; x-ref: $9d71
$9F1B.byte$10, $1e, $27, $22, $65, $26, $74, $2b
$9F23.byte$09, $32, $fe, $36, $fe, $2f, $38, $28
$9F2B.byte$31, $23, $2b, $1f, $2b, $1d, $58, $1e
$9F33.byte$3b, $22, $65, $25, $73, $2b, $1e, $32
$9F3B.byte$27, $33, $1d, $2c, $1d, $26, $34, $22
$9F43.byte$66, $1e, $2a, $1f, $57, $1e, $5e, $23
$9F4B.byte$6a, $28, $21, $2d, $1e, $1f, $34, $32
$9F53.byte$27, $2b, $1d, $25, $31, $22, $11, $ff
; Sound stream 2 (56 bytes): 2-voice frog home-bay arrival SFX (tempo=1, direct hi-byte freq mode $80, 25 2-byte steps, $FF end)
sound_stream_2_home_bay_sfx
$9F5B.byte$81, $02, $54, $24, $04, $04, $0e, $17; x-ref: $9d6f
$9F63.byte$26, $16, $31, $16, $1c, $17, $28, $16
$9F6B.byte$2b, $18, $27, $1b, $28, $1c, $2a, $16
$9F73.byte$1e, $18, $30, $1b, $34, $1c, $10, $1c
$9F7B.byte$40, $1f, $33, $1f, $44, $04, $1f, $03
$9F83.byte$1b, $1d, $2e, $08, $23, $1b, $23, $1d
$9F8B.byte$2a, $13, $1d, $1d, $41, $1e, $44, $ff
; Sound stream 1 (79 bytes): 1-voice ascending sweep SFX (tempo=1, direct hi-byte freq mode $80, 73 1-byte steps, $FF end)
$9F93sound_stream_1_sfx.byte$81, $01, $b4, $04, $04, $0a, $0b, $0b; x-ref: $9d6d
$9F9B.byte$0c, $0e, $0b, $0c, $0c, $0d, $0d, $0b
$9FA3.byte$0c, $0d, $0c, $0e, $0f, $0e, $0c, $0e
$9FAB.byte$0f, $10, $0e, $0e, $0f, $0f, $10, $0d
$9FB3.byte$0f, $0f, $10, $12, $10, $0f, $10, $12
$9FBB.byte$13, $10, $10, $10, $12, $14, $12, $11
$9FC3.byte$12, $14, $16, $19, $12, $14, $16, $19
$9FCB.byte$1b, $13, $16, $18, $1a, $1d, $14, $18
$9FD3.byte$1a, $1d, $1e, $16, $19, $1d, $1f, $24
$9FDB.byte$2b, $1c, $1e, $24, $2b, $32, $ff
; Sound stream 5 (23 bytes): 1-voice alert motif (tempo=3, scaled freq mode, V1 SR=$90/pulse, 17 1-byte steps, $FF end)
sound_stream_5_alert
$9FE2.byte$03, $01, $94, $04, $04, $2d, $00, $28; x-ref: $9d75
$9FEA.byte$00, $26, $00, $2d, $00, $28, $00, $26
$9FF2.byte$00, $2d, $00, $28, $00, $26, $ff
; Unused 8K cartridge ROM end padding (7 bytes: alternating $AA/$55 fill)
$9FF9rom_padding_9ff9.byte$aa, $55, $55, $aa, $55, $55, $aa