
/workspace/scratch/063c5c4b16e7/boulderdash128/analysis/ghidra/xa_combined.s

    1 T:0600                                    ; *************************************************************************************
    2 T:0600                                    ; Boulder Dash for the Oric
    3 T:0600                                    ; by raspberrypioneer Jan 2025
    4 T:0600                                    ;

    6 T:0600                                    ;#define full_matrix_keyboard  ; Use the full matrix keyboard, comment this line out for single row keyboard

   31 T:0600                                    ;screen address in text and hires mode

   35 T:0600                                    ;map elements defines

   53 T:0600                                    ;animation states

   63 T:0600                                    ;special map states

   72 T:0600                                    ;sprite defines

  129 T:0600                                    ;Using these defines, you can easily check the content of KeyRowArrows

  139 T:0600                                    ;status_messages

  151 T:0600                                    ;sounds

  168 T:0600                                    ; *************************************************************************************
  169 T:0600                                     .zero 
  170 Z:0050                                    ; zero-page base passed as -bz 80
  171 Z:0050                           zero_page_start 

  173 Z:0050                           neighbour_cell_directions 
  174 Z:0050  00                       cell_above_left .byt 0
  175 Z:0051  00                       cell_above .byt 0
  176 Z:0052  00                       cell_above_right .byt 0
  177 Z:0053  00                       cell_left .byt 0
  178 Z:0054  00                       cell_current .byt 0
  179 Z:0055  00                       cell_right .byt 0
  180 Z:0056  00                       cell_below_left .byt 0
  181 Z:0057  00                       cell_below .byt 0
  182 Z:0058  00                       cell_below_right .byt 0

  184 Z:0059  00                       neighbour_cell_pointer .byt 0

  186 Z:005a                                    ;keyboard input

  192 Z:005a  00                       _KeyRowArrows .byt 0

  194 Z:005b  00                       irq_A     .byt 0
  195 Z:005c  00                       irq_X     .byt 0
  196 Z:005d  00                       irq_Y     .byt 0

  198 Z:005e  00                       sprite_address_low .byt 0
  199 Z:005f  00                       sprite_address_high .byt 0

  201 Z:0060  00                       screen_addr1_low .byt 0
  202 Z:0061  00                       screen_addr1_high .byt 0

  204 Z:0062  00                       screen_addr2_low .byt 0
  205 Z:0063  00                       screen_addr2_high .byt 0

  207 Z:0064  00                       map_address_low .byt 0
  208 Z:0065  00                       map_address_high .byt 0

  210 Z:0066  00                       cache_counter .byt 0

  212 Z:0067  00                       map_rows  .byt 0
  213 Z:0068  00                       map_cols  .byt 0

  215 Z:0069  00                       map_rockford_current_position_addr_low .byt 0
  216 Z:006a  00                       map_rockford_current_position_addr_high .byt 0

  218 Z:006b  00                       map_rockford_end_position_addr_low .byt 0
  219 Z:006c  00                       map_rockford_end_position_addr_high .byt 0

  221 Z:006d  00                       visible_top_left_map_x .byt 0
  222 Z:006e  00                       visible_top_left_map_y .byt 0

  224 Z:006f  00                       score_low .byt 0
  225 Z:0070  00                       score_high .byt 0

  227 Z:0071  00                       temp1     .byt 0
  228 Z:0072  00                       temp2     .byt 0

  230 Z:0073  00                       player_lives .byt 0
  231 Z:0074  00                       cave_number .byt 0
  232 Z:0075  00                       difficulty_level .byt 0
  233 Z:0076  00                       diamonds_required .byt 0
  234 Z:0077  00                       time_remaining .byt 0
  235 Z:0078  00                       bomb_counter .byt 0
  236 Z:0079  00                       bomb_delay .byt 0
  237 Z:007a  00                       gravity_timer .byt 0
  238 Z:007b  00                       magic_wall_state .byt 0
  239 Z:007c  00                       magic_wall_timer .byt 0
  240 Z:007d  00                       amoeba_growth_interval .byt 0
  241 Z:007e  00                       amoeba_counter .byt 0
  242 Z:007f  00                       amoeba_replacement .byt 0
  243 Z:0080  00                       number_of_amoeba_cells_found .byt 0
  244 Z:0081  00                       bonus_timer .byt 0
  245 Z:0082  00                       rockford_cell_value .byt 0
  246 Z:0083  00                       current_rockford_sprite .byt 0
  247 Z:0084  00                       rockford_explosion_cell_type .byt 0
  248 Z:0085  00                       current_amoeba_cell_type .byt 0
  249 Z:0086  00                       neighbour_cell_contents .byt 0
  250 Z:0087  00                       delay_trying_to_push_rock .byt 0
  251 Z:0088  00                       saved_message .byt 0
  252 Z:0089  00                       message_timer .byt 0

  254 Z:008a  00                       tick_counter .byt 0
  255 Z:008b  00                       sub_second_ticks .byt 0
  256 Z:008c  00                       ticks_since_last_direction_key_pressed .byt 0
  257 Z:008d  00                       play_sound_fx .byt 0
  258 Z:008e  00                       play_ambient_fx .byt 0
  259 Z:008f                           zero_page_end 

  261 Z:008f                                    ; *************************************************************************************
  262 Z:008f                                     .text 
  263 T:0600                           program_start 

  265 T:0600  a9 0a                              lda #8+2       ;No key click and no cursor
  266 T:0602  8d 6a 02                           sta $026a
  267 T:0605  a2 00                              ldx #0             ;Remove CAPS text
  268 T:0607  8e a3 bb                           stx $bb80+35

  270 T:060a                                    ;Clear the zero page addresses
  271 T:060a  20 4a 06                           jsr clear_zero_page

  273 T:060d  20 bc 19                           jsr select_caves_for_version                ;Let the user select the game version to play

  275 T:0610                                    ;load the redefined characters
  276 T:0610                                    ;all 96 available standard charset characters are used for sprites / tiles
  277 T:0610                                    ;most of the alternate charset is used for numbers, letters for the fixed status bar display
  278 T:0610                                    ;  (easier to use for this purpose instead of the standard character set)
  279 T:0610                                    ;the load-to address is $b500 (skips the standard charset control characters)
  280 T:0610  a0 08                              ldy #8             ;sprites location
  281 T:0612  20 7c 1b                           jsr load_TAP_using_filename

  283 T:0615  20 9e 1b                           jsr display_instructions

  285 T:0618                                    ;Get the start of the cave file name to load
  286 T:0618                           version_selected 
  287 T:0618  a9 02                              lda #2             ;self-mod, see usage, point to third option in TAP_filenames table (zero-based, first cave file)
  288 T:061a  0a                                 asl                    ;multiply by 8 (3 x asl)
  289 T:061b  0a                                 asl 
  290 T:061c  0a                                 asl 
  291 T:061d  a8                                 tay                    ;caves table location in Y
  292 T:061e  20 7c 1b                           jsr load_TAP_using_filename                ;Load all caves into memory, the load-to address is set in the TAP file header

  294 T:0621                                    ;Clear the zero page addresses (file loading affects zero page)
  295 T:0621  20 4a 06                           jsr clear_zero_page

  297 T:0624  a9 1d                              lda #>sprite_addr_all_sprites              ;all sprite characters are on the same page
  298 T:0626  85 5f                              sta sprite_address_high

  300 T:0628                                    ; *************************************************************************************
  301 T:0628                                    ; Menu to start with and return to after a game ends
  302 T:0628                           menu_loop 
  303 T:0628  20 54 06                           jsr intro_and_cave_select

  305 T:062b  a9 03                              lda #3
  306 T:062d  85 73                              sta player_lives

  308 T:062f  a9 00                              lda #0
  309 T:0631  85 6f                              sta score_low
  310 T:0633  85 70                              sta score_high
  311 T:0635  8d 5d 0f                           sta bonus_low
  312 T:0638  8d 5e 0f                           sta bonus_high

  314 T:063b                                    ;game loop for each of the player lives
  315 T:063b                           play_next_life 
  316 T:063b  20 77 0a                           jsr play_one_life
  317 T:063e  a5 73                              lda player_lives
  318 T:0640  d0 f9                              bne play_next_life

  320 T:0642                                    ;end last screen by hiding it with steel sprites via interrupt
  321 T:0642  a9 80                              lda #128
  322 T:0644  20 30 0b                           jsr screen_dissolve_effect

  324 T:0647  4c 28 06                           jmp menu_loop

  326 T:064a                                    ; *************************************************************************************
  327 T:064a                                    ; Clear the zero page addresses
  328 T:064a                           clear_zero_page 
  329 T:064a  a9 00                              lda #0
  330 T:064c  a2 3f                              ldx #zero_page_end-zero_page_start
  331 T:064e                           clear_zero_loop 
  332 T:064e  95 4f                              sta zero_page_start-1,x
  333 T:0650  ca                                 dex 
  334 T:0651  d0 fb                              bne clear_zero_loop
  335 T:0653  60                                 rts 

  337 T:0654                                    ; *************************************************************************************
  338 T:0654                                    ; Load and display the intro screen, accept the cave, level, keyset from the user and start the game
  339 T:0654                           intro_and_cave_select 

  341 T:0654  a9 14                              lda #20             ;Cave Z (intro cave)
  342 T:0656  85 74                              sta cave_number
  343 T:0658  20 87 0a                           jsr prepare_cave

  345 T:065b                                    ;knock-out Rockford and growing wall handlers for now
  346 T:065b                                    ;growing wall is ignored on the intro screen, so that the title text isn't removed when drawing the map
  347 T:065b  a9 c3                              lda #<handler_null
  348 T:065d  8d 31 1e                           sta rockford_handler_low
  349 T:0660  8d 2e 1e                           sta growing_wall_handler_low
  350 T:0663  a9 07                              lda #>handler_null
  351 T:0665  8d 41 1e                           sta rockford_handler_high
  352 T:0668  8d 3e 1e                           sta growing_wall_handler_high

  354 T:066b                                    ;set title text after caching the screen (preventing draw of growing wall which is reused for title text)
  355 T:066b  20 c0 15                           jsr update_map
  356 T:066e  20 d5 09                           jsr set_map_address_to_current_window
  357 T:0671  20 00 09                           jsr draw_grid_of_sprites
  358 T:0674  20 06 08                           jsr set_title_text

  360 T:0677                                    ;Tick counter needed for some animation
  361 T:0677  a9 1f                              lda #31
  362 T:0679  85 8a                              sta tick_counter

  364 T:067b                                    ;cave number and levels to start selection from
  365 T:067b  a9 00                              lda #0
  366 T:067d  85 74                              sta cave_number

  368 T:067f                                    ;also clear sound parameters and switch interrupt sound actions to the theme tune
  369 T:067f  8d c5 07                           sta theme_note_duration+1
  370 T:0682  8d 00 22                           sta active_sound_duration

  372 T:0685  a9 c4                              lda #<play_theme_tune
  373 T:0687  8d ed 1b                           sta sound_actions_irq+1
  374 T:068a  a9 07                              lda #>play_theme_tune
  375 T:068c  8d ee 1b                           sta sound_actions_irq+2

  377 T:068f  a9 01                              lda #1
  378 T:0691  85 75                              sta difficulty_level

  380 T:0693                                    ;set options text (all lines are the same length)
  381 T:0693  a0 29                              ldy #41
  382 T:0695                           show_options_loop 
  383 T:0695  88                                 dey 
  384 T:0696  b9 7c 21                           lda options_cave_select,y
  385 T:0699  99 80 bb                           sta $bb80,y
  386 T:069c  b9 a4 21                           lda options_level_select,y
  387 T:069f  99 a8 bb                           sta $bb80+40,y
  388 T:06a2  b9 cc 21                           lda options_start,y
  389 T:06a5  99 d0 bb                           sta $bb80+80,y
  390 T:06a8  c0 00                              cpy #0
  391 T:06aa  d0 e9                              bne show_options_loop

  393 T:06ac                                    ;draw map, waiting for keyboard input
  394 T:06ac                           wait_for_keypress 
  395 T:06ac  20 c0 15                           jsr update_map
  396 T:06af  20 d5 09                           jsr set_map_address_to_current_window
  397 T:06b2  20 00 09                           jsr draw_grid_of_sprites
  398 T:06b5  c6 8a                              dec tick_counter

  400 T:06b7  a2 0f                              ldx #$0f
  401 T:06b9  20 82 0f                           jsr delay_a_bit

  403 T:06bc  a5 5a                              lda _KeyRowArrows
  404 T:06be  c9 01                              cmp #1
  405 T:06c0  f0 1f                              beq exit_intro_keypress

  407 T:06c2  c9 08                              cmp #8
  408 T:06c4  f0 61                              beq level_up

  410 T:06c6  c9 20                              cmp #32
  411 T:06c8  f0 36                              beq cave_down

  413 T:06ca  c9 40                              cmp #64
  414 T:06cc  f0 4f                              beq level_down

  416 T:06ce  c9 80                              cmp #128
  417 T:06d0  f0 38                              beq cave_up

  419 T:06d2  c9 02                              cmp #2
  420 T:06d4  f0 64                              beq colour_map_down

  422 T:06d6  c9 04                              cmp #4
  423 T:06d8  f0 69                              beq colour_map_up

  425 T:06da  c9 10                              cmp #16
  426 T:06dc  f0 77                              beq swap_keymap

  428 T:06de  4c ac 06                           jmp wait_for_keypress

  430 T:06e1                           exit_intro_keypress 

  432 T:06e1                                    ;;switch interrupt sound actions back to normal for gameplay
  433 T:06e1  a9 ef                              lda #<update_sounds
  434 T:06e3  8d ed 1b                           sta sound_actions_irq+1
  435 T:06e6  a9 1b                              lda #>update_sounds
  436 T:06e8  8d ee 1b                           sta sound_actions_irq+2

  438 T:06eb                                    ;add back Rockford and growing wall handlers
  439 T:06eb  a9 d2                              lda #<handler_rockford
  440 T:06ed  8d 31 1e                           sta rockford_handler_low
  441 T:06f0  a9 16                              lda #>handler_rockford
  442 T:06f2  8d 41 1e                           sta rockford_handler_high
  443 T:06f5  a9 8b                              lda #<handler_growing_wall
  444 T:06f7  8d 2e 1e                           sta growing_wall_handler_low
  445 T:06fa  a9 18                              lda #>handler_growing_wall
  446 T:06fc  8d 3e 1e                           sta growing_wall_handler_high
  447 T:06ff  60                                 rts 

  449 T:0700                           cave_down 
  450 T:0700  a4 74                              ldy cave_number
  451 T:0702  b9 91 07                           lda cave_selection_cycle_down,y
  452 T:0705  85 74                              sta cave_number
  453 T:0707  4c 14 07                           jmp cave_display

  455 T:070a                           cave_up   
  456 T:070a  a4 74                              ldy cave_number
  457 T:070c  b9 81 07                           lda cave_selection_cycle_up,y
  458 T:070f  85 74                              sta cave_number
  459 T:0711  4c 14 07                           jmp cave_display

  461 T:0714                           cave_display 
  462 T:0714  18                                 clc 
  463 T:0715  69 41                              adc #"A"             ; Add letter "A" to get the cave letter for the cave number (which starts from zero)
  464 T:0717  8d 92 bb                           sta $bb80+18
  465 T:071a  4c ac 06                           jmp wait_for_keypress

  467 T:071d                           level_down 
  468 T:071d  a4 75                              ldy difficulty_level
  469 T:071f  b9 a7 07                           lda level_selection_cycle_down,y
  470 T:0722  85 75                              sta difficulty_level
  471 T:0724  4c 31 07                           jmp level_display

  473 T:0727                           level_up  
  474 T:0727  a4 75                              ldy difficulty_level
  475 T:0729  b9 a1 07                           lda level_selection_cycle_up,y
  476 T:072c  85 75                              sta difficulty_level
  477 T:072e  4c 31 07                           jmp level_display

  479 T:0731                           level_display 
  480 T:0731  18                                 clc 
  481 T:0732  69 30                              adc #"0"             ; Add digit "0" to get ASCII value of difficulty level
  482 T:0734  8d ba bb                           sta $bb80+58
  483 T:0737  4c ac 06                           jmp wait_for_keypress

  485 T:073a                           colour_map_down 
  486 T:073a  ac 25 0b                           ldy set_line_colour+1
  487 T:073d  b9 b4 07                           lda colour_selection_cycle_down,y
  488 T:0740  4c 49 07                           jmp colour_map
  489 T:0743                           colour_map_up 
  490 T:0743  ac 25 0b                           ldy set_line_colour+1
  491 T:0746  b9 ad 07                           lda colour_selection_cycle_up,y
  492 T:0749                           colour_map 
  493 T:0749  8d 25 0b                           sta set_line_colour+1
  494 T:074c  20 0c 0b                           jsr set_cave_colours
  495 T:074f  20 06 08                           jsr set_title_text                ;update the title text which need the colour setting
  496 T:0752  4c ac 06                           jmp wait_for_keypress

  498 T:0755                           swap_keymap 
  499 T:0755  ad cc 17                           lda direction_key_table
  500 T:0758  c9 80                              cmp #128
  501 T:075a  f0 0a                              beq alt_keymap
  502 T:075c                                    ;standard layout
  503 T:075c                                    ;use right arrow (right), left arrow (left), up arrow (up), down arrow (down)
  504 T:075c  a0 7e                              ldy #126
  505 T:075e  20 ab 0c                           jsr update_status_message
  506 T:0761  a0 00                              ldy #0
  507 T:0763  4c 70 07                           jmp change_direction_keys

  509 T:0766                           alt_keymap 
  510 T:0766  a0 90                              ldy #144
  511 T:0768  20 ab 0c                           jsr update_status_message
  512 T:076b  a0 04                              ldy #4
  513 T:076d  4c 70 07                           jmp change_direction_keys

  515 T:0770                           change_direction_keys 
  516 T:0770                                    ;alternate layout (more intuitive?)
  517 T:0770                                    ;the direction keys on the left of the spacebar are left, right
  518 T:0770                                    ;the direction keys on the right of the spacebar are down, up
  519 T:0770  a2 00                              ldx #0
  520 T:0772                           change_keys_loop 
  521 T:0772  b9 bb 07                           lda std_and_alt_keymap,y
  522 T:0775  c8                                 iny 
  523 T:0776  9d cc 17                           sta direction_key_table,x
  524 T:0779  e8                                 inx 
  525 T:077a  e0 04                              cpx #4
  526 T:077c  d0 f4                              bne change_keys_loop
  527 T:077e  4c ac 06                           jmp wait_for_keypress

  529 T:0781                           cave_selection_cycle_up 
  530 T:0781  01 02 03 04 05 06 07 ...           .byt 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0
  531 T:0791                           cave_selection_cycle_down 
  532 T:0791  0f 00 01 02 03 04 05 ...           .byt 15,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14

  534 T:07a1                           level_selection_cycle_up 
  535 T:07a1  00 02 03 04 05 01                  .byt 0,2,3,4,5,1
  536 T:07a7                           level_selection_cycle_down 
  537 T:07a7  00 05 01 02 03 04                  .byt 0,5,1,2,3,4

  539 T:07ad                           colour_selection_cycle_up 
  540 T:07ad  00 02 03 05 00 06 01               .byt 0,2,3,5,0,6,1
  541 T:07b4                           colour_selection_cycle_down 
  542 T:07b4  00 06 01 02 00 03 05               .byt 0,6,1,2,0,3,5

  544 T:07bb                           std_and_alt_keymap 
  545 T:07bb  80 20 08 40                        .byt 128,32,8,64;standard
  546 T:07bf  40 20 80 08                        .byt 64,32,128,8;alternate

  548 T:07c3                           handler_null 
  549 T:07c3  60                                 rts 

  551 T:07c4                                    ; *************************************************************************************
  552 T:07c4                                    ; Play title screen theme tune on repeat
  553 T:07c4                                    ; The data for each of the two channels is 256 bytes in low byte, high byte sequence
  554 T:07c4                                    ; The y register holds the pitch position and cycles back to zero after 255 is reached
  555 T:07c4                           play_theme_tune 

  557 T:07c4                           theme_note_duration 
  558 T:07c4  a9 00                              lda #0             ;self-mod, see usage
  559 T:07c6  f0 04                              beq play_theme_note                ;duration of last note complete, start a new one
  560 T:07c8  ce c5 07                           dec theme_note_duration+1
  561 T:07cb  60                                 rts 

  563 T:07cc                           play_theme_note 

  565 T:07cc  ac 00 22                           ldy active_sound_offset
  566 T:07cf  b9 a2 22                           lda theme_voice_1_pitch_low_high,y
  567 T:07d2  8d f8 07                           sta sound_theme_base
  568 T:07d5  b9 a2 23                           lda theme_voice_2_pitch_low_high,y
  569 T:07d8  8d fa 07                           sta sound_theme_base+2

  571 T:07db  c8                                 iny 

  573 T:07dc  b9 a2 22                           lda theme_voice_1_pitch_low_high,y
  574 T:07df  8d f9 07                           sta sound_theme_base+1
  575 T:07e2  b9 a2 23                           lda theme_voice_2_pitch_low_high,y
  576 T:07e5  8d fb 07                           sta sound_theme_base+3

  578 T:07e8  c8                                 iny 
  579 T:07e9  8c 00 22                           sty active_sound_offset

  581 T:07ec  a9 10                              lda #16             ;reset the duration
  582 T:07ee  8d c5 07                           sta theme_note_duration+1

  584 T:07f1  a2 f8                              ldx #<sound_theme_base
  585 T:07f3  a0 07                              ldy #>sound_theme_base
  586 T:07f5  4c 86 fa                           jmp $fa86              ; Play sound effect

  588 T:07f8                           sound_theme_base                  ;First 4 bytes are replaced with the pitch low-high bytes for both channels A, B
  589 T:07f8  00 01 02 03 00 00 00 ...           .byt 0,1,2,3,0,0,0,$7c,16,16,0,0,7,0

  591 T:0806                                    ; *************************************************************************************
  592 T:0806                                    ; Set menu screen title text
  593 T:0806                           set_title_text 
  594 T:0806  a0 00                              ldy #0
  595 T:0808                           plot_text_byte 
  596 T:0808  b9 66 21                           lda game_title,y
  597 T:080b  f0 0a                              beq plot_text_end
  598 T:080d  99 09 be                           sta $bb80+649,y
  599 T:0810  99 31 be                           sta $bb80+689,y

  601 T:0813  c8                                 iny 
  602 T:0814  4c 08 08                           jmp plot_text_byte
  603 T:0817                           plot_text_end 
  604 T:0817  ad 25 0b                           lda set_line_colour+1          ;finish title with the cave colour
  605 T:081a  99 09 be                           sta $bb80+649,y
  606 T:081d  99 31 be                           sta $bb80+689,y
  607 T:0820  60                                 rts 

  609 T:0821                                    ; *************************************************************************************
  610 T:0821                                    ; Screen addresses for start of each row, split into top and bottom addresses 
  611 T:0821                                    ;   (each character is 2 characters high)
  612 T:0821                           char_screen_low 
  613 T:0821  20 70 c0 10 60 b0 00 ...           .byt $20,$70,$c0,$10,$60,$b0,$00,$50,$a0,$f0,$40,$90
  614 T:082d                           char_screen_high 
  615 T:082d  bc bc bc bd bd bd be ...           .byt $bc,$bc,$bc,$bd,$bd,$bd,$be,$be,$be,$be,$bf,$bf

  617 T:0839                           char_screen_below_low 
  618 T:0839  48 98 e8 38 88 d8 28 ...           .byt $48,$98,$e8,$38,$88,$d8,$28,$78,$c8,$18,$68,$b8
  619 T:0845                           char_screen_below_high 
  620 T:0845  bc bc bc bd bd bd be ...           .byt $bc,$bc,$bc,$bd,$bd,$bd,$be,$be,$be,$bf,$bf,$bf

  622 T:0851                                    ; *************************************************************************************
  623 T:0851                                    ; Draw a full grid of sprites, updating the current map position first
  624 T:0851                                    ; Below is needed to point the program counter to the next page (multiple of 256)
  625 T:0851  00 ff 00 01 00 64 02 ...           .dsb 256-(*&255)    ;Add another page of bytes

  627 T:0900                           draw_grid_of_sprites 

  629 T:0900  20 0c 0a                           jsr update_grid_animations

  631 T:0903  a0 00                              ldy #0
  632 T:0905  84 66                              sty cache_counter
  633 T:0907                           loop_plot_row 
  634 T:0907  84 67                              sty map_rows             ;grid row counter

  636 T:0909  b9 21 08                           lda char_screen_low,y
  637 T:090c  8d 55 09                           sta top_left_char_addr+1
  638 T:090f  8d 62 09                           sta top_right_char_addr+1
  639 T:0912  b9 2d 08                           lda char_screen_high,y
  640 T:0915  8d 56 09                           sta top_left_char_addr+2
  641 T:0918  8d 63 09                           sta top_right_char_addr+2

  643 T:091b  b9 39 08                           lda char_screen_below_low,y
  644 T:091e  8d 5b 09                           sta bottom_left_char_addr+1
  645 T:0921  8d 68 09                           sta bottom_right_char_addr+1
  646 T:0924  b9 45 08                           lda char_screen_below_high,y
  647 T:0927  8d 5c 09                           sta bottom_left_char_addr+2
  648 T:092a  8d 69 09                           sta bottom_right_char_addr+2

  650 T:092d  a0 00                              ldy #0
  651 T:092f                           loop_plot_column 
  652 T:092f  84 68                              sty map_cols             ;grid column counter

  654 T:0931                                    ;Get sprite number from map
  655 T:0931  b1 64                              lda (map_address_low),y
  656 T:0933  10 02                              bpl normal_tile_sprite                ;branch if bit 7 is set to 0 (map_space is set in screen_dissolve_effect)
  657 T:0935  a9 03                              lda #3             ;otherwise use the titanium wall tile (map_unprocessed is set)
  658 T:0937                           normal_tile_sprite 

  660 T:0937  a6 66                              ldx cache_counter

  662 T:0939  a8                                 tay 
  663 T:093a  b9 42 1e                           lda cell_type_to_sprite,y
  664 T:093d  a8                                 tay 
  665 T:093e  dd a2 24                           cmp screen_cache_map,x
  666 T:0941  f0 27                              beq skip_plot_tile                ;Sprite is the same, don't need to redraw it
  667 T:0943  9d a2 24                           sta screen_cache_map,x

  669 T:0946                                    ;Lookup sprite low address in the sprite list table, the high byte is always the same and set at the start
  670 T:0946  b9 b4 1d                           lda sprite_addresses_low,y
  671 T:0949  85 5e                              sta sprite_address_low

  673 T:094b                                    ;Plot the top 2 and bottom 2 characters for the tile
  674 T:094b  a5 68                              lda map_cols             ;grid column counter
  675 T:094d  0a                                 asl                    ;Double the counter number to get the screen offset position
  676 T:094e  aa                                 tax 
  677 T:094f  e8                                 inx                    ;skip past first character which sets the line colour (see set_cave_colours)

  679 T:0950                                    ;Transfer the 4 bytes which make up the sprite tile to the locations below (self-mod code)
  680 T:0950  a0 00                              ldy #0
  681 T:0952  b1 5e                              lda (sprite_address_low),y
  682 T:0954                           top_left_char_addr 
  683 T:0954  9d 54 09                           sta top_left_char_addr,x           ;self-mod, see above
  684 T:0957  c8                                 iny 
  685 T:0958  b1 5e                              lda (sprite_address_low),y
  686 T:095a                           bottom_left_char_addr 
  687 T:095a  9d 5a 09                           sta bottom_left_char_addr,x           ;self-mod, see above
  688 T:095d  c8                                 iny 
  689 T:095e  e8                                 inx 
  690 T:095f  b1 5e                              lda (sprite_address_low),y
  691 T:0961                           top_right_char_addr 
  692 T:0961  9d 61 09                           sta top_right_char_addr,x           ;self-mod, see above
  693 T:0964  c8                                 iny 
  694 T:0965  b1 5e                              lda (sprite_address_low),y
  695 T:0967                           bottom_right_char_addr 
  696 T:0967  9d 67 09                           sta bottom_right_char_addr,x           ;self-mod, see above

  698 T:096a                           skip_plot_tile 
  699 T:096a  e6 66                              inc cache_counter             ;never exceeds 15 rows x 14 columns (1 byte)
  700 T:096c  a4 68                              ldy map_cols
  701 T:096e  c8                                 iny 
  702 T:096f  c0 13                              cpy #19             ;19 columns
  703 T:0971  90 bc                              bcc loop_plot_column

  705 T:0973                                    ; move tile pointer on to next row (64 bytes)
  706 T:0973  a5 64                              lda map_address_low
  707 T:0975  18                                 clc 
  708 T:0976  69 40                              adc #64
  709 T:0978  85 64                              sta map_address_low
  710 T:097a  90 02                              bcc skip_high
  711 T:097c  e6 65                              inc map_address_high
  712 T:097e                           skip_high 
  713 T:097e  a4 67                              ldy map_rows             ;grid row counter
  714 T:0980  c8                                 iny 
  715 T:0981  c0 0c                              cpy #12             ;12 rows
  716 T:0983  90 82                              bcc loop_plot_row
  717 T:0985  60                                 rts 

  719 T:0986                                    ; *************************************************************************************
  720 T:0986                                    ; Scrolls the map by setting the map_address_high/low and visible_top_left_map_x and y
  721 T:0986                                    ; Note: each time Rockford moves and pushes the boundaries, visible_top_left_map_x and y are incremented / decremented
  722 T:0986                                    ;       this means the visible position is not set based on Rockford's absolute position at the start
  723 T:0986                           update_map_scroll_position 

  725 T:0986  a5 69                              lda map_rockford_current_position_addr_low
  726 T:0988  85 64                              sta map_address_low
  727 T:098a  a5 6a                              lda map_rockford_current_position_addr_high
  728 T:098c  85 65                              sta map_address_high
  729 T:098e  20 e0 09                           jsr map_address_to_map_xy_position
  730 T:0991  38                                 sec 
  731 T:0992  e5 6d                              sbc visible_top_left_map_x
  732 T:0994  a6 6d                              ldx visible_top_left_map_x
  733 T:0996  c9 0e                              cmp #14
  734 T:0998  30 05                              bmi check_for_need_to_scroll_left
  735 T:099a  e0 15                              cpx #21
  736 T:099c  10 0a                              bpl check_for_need_to_scroll_down
  737 T:099e  e8                                 inx 
  738 T:099f                           check_for_need_to_scroll_left 
  739 T:099f  c9 05                              cmp #5
  740 T:09a1  10 05                              bpl check_for_need_to_scroll_down
  741 T:09a3  e0 01                              cpx #1
  742 T:09a5  30 01                              bmi check_for_need_to_scroll_down
  743 T:09a7  ca                                 dex 
  744 T:09a8                           check_for_need_to_scroll_down 
  745 T:09a8  a4 6e                              ldy visible_top_left_map_y
  746 T:09aa  a5 61                              lda screen_addr1_high
  747 T:09ac  38                                 sec 
  748 T:09ad  e5 6e                              sbc visible_top_left_map_y
  749 T:09af  c9 08                              cmp #8
  750 T:09b1  30 05                              bmi check_for_need_to_scroll_up
  751 T:09b3  c0 0a                              cpy #$0a
  752 T:09b5  10 0a                              bpl check_for_bonus_stages
  753 T:09b7  c8                                 iny 
  754 T:09b8                           check_for_need_to_scroll_up 
  755 T:09b8  c9 04                              cmp #4
  756 T:09ba  10 05                              bpl check_for_bonus_stages
  757 T:09bc  c0 01                              cpy #1
  758 T:09be  30 01                              bmi check_for_bonus_stages
  759 T:09c0  88                                 dey 
  760 T:09c1                           check_for_bonus_stages 
  761 T:09c1  ad 1b 26                           lda param_intermission
  762 T:09c4  f0 04                              beq skip_bonus_stage
  763 T:09c6                                    ; bonus stage is always situated in top left corner
  764 T:09c6  a9 00                              lda #0
  765 T:09c8  aa                                 tax 
  766 T:09c9  a8                                 tay 
  767 T:09ca                           skip_bonus_stage 
  768 T:09ca  86 6d                              stx visible_top_left_map_x
  769 T:09cc  86 60                              stx screen_addr1_low
  770 T:09ce  84 6e                              sty visible_top_left_map_y
  771 T:09d0  84 61                              sty screen_addr1_high
  772 T:09d2  4c f5 09                           jmp map_xy_position_to_map_address

  774 T:09d5                           set_map_address_to_current_window 
  775 T:09d5  a6 6d                              ldx visible_top_left_map_x
  776 T:09d7  86 68                              stx map_cols
  777 T:09d9  a4 6e                              ldy visible_top_left_map_y
  778 T:09db  84 67                              sty map_rows
  779 T:09dd  4c f5 09                           jmp map_xy_position_to_map_address

  781 T:09e0                                    ; *************************************************************************************
  782 T:09e0                                    ; Map address (which start at $1000) becomes row/column in screen_addr1_high and low
  783 T:09e0                                    ; e.g. $1000 is 0,0   $1098 is 2,24   $1140 is 5,0   $110f is 5,15
  784 T:09e0                           map_address_to_map_xy_position 

  786 T:09e0  a5 65                              lda map_address_high
  787 T:09e2  29 07                              and #7
  788 T:09e4  85 61                              sta screen_addr1_high
  789 T:09e6  a5 64                              lda map_address_low
  790 T:09e8  0a                                 asl 
  791 T:09e9  26 61                              rol screen_addr1_high
  792 T:09eb  0a                                 asl 
  793 T:09ec  26 61                              rol screen_addr1_high
  794 T:09ee  a5 64                              lda map_address_low
  795 T:09f0  29 3f                              and #$3f
  796 T:09f2  85 60                              sta screen_addr1_low
  797 T:09f4  60                                 rts 

  799 T:09f5                                    ; *************************************************************************************
  800 T:09f5                                    ; Convert a grid position (row/column) to a map address
  801 T:09f5                           map_xy_position_to_map_address 

  803 T:09f5  a9 00                              lda #0
  804 T:09f7  85 64                              sta map_address_low
  805 T:09f9  a5 61                              lda screen_addr1_high
  806 T:09fb  4a                                 lsr 
  807 T:09fc  66 64                              ror map_address_low
  808 T:09fe  4a                                 lsr 
  809 T:09ff  66 64                              ror map_address_low
  810 T:0a01  09 10                              ora #>tile_map_row_0
  811 T:0a03  85 65                              sta map_address_high
  812 T:0a05  a5 60                              lda screen_addr1_low
  813 T:0a07  05 64                              ora map_address_low
  814 T:0a09  85 64                              sta map_address_low
  815 T:0a0b  60                                 rts 

  817 T:0a0c                                    ; *************************************************************************************
  818 T:0a0c                                    ; Animation works by checking 14 animation sequences
  819 T:0a0c                                    ;   cell_types_that_always_animate returns an element map / map-animated value (e.g. map_anim_state1 | map_firefly)
  820 T:0a0c                                    ;   cell_type_to_sprite takes this value and looks up its sprite value (e.g. sprite_firefly4)
  821 T:0a0c                                    ;   sprite_to_next_sprite takes the sprite value and looks up the replacement sprite (e.g. sprite_firefly1)
  822 T:0a0c                                    ;   cell_type_to_sprite is updated with the replacement, so next time the lookup returns sprite_firefly1
  823 T:0a0c                                    ;     which then points to sprite_firefly2 and so on
  824 T:0a0c                           update_grid_animations 

  826 T:0a0c  a2 0e                              ldx #$0e
  827 T:0a0e  86 71                              stx temp1
  828 T:0a10                           update_sprites_to_use_loop 
  829 T:0a10  bc c2 1e                           ldy cell_types_that_always_animate,x
  830 T:0a13  be 42 1e                           ldx cell_type_to_sprite,y
  831 T:0a16                                    ; look up the next sprite in the animation sequence
  832 T:0a16  bd d1 1e                           lda sprite_to_next_sprite,x
  833 T:0a19  99 42 1e                           sta cell_type_to_sprite,y
  834 T:0a1c  c6 71                              dec temp1
  835 T:0a1e  a6 71                              ldx temp1
  836 T:0a20  10 ee                              bpl update_sprites_to_use_loop

  838 T:0a22                                    ;Animate for bonus life
  839 T:0a22  a5 81                              lda bonus_timer             ;check if bonus animation applies
  840 T:0a24  f0 0f                              beq skip_bonus_animation
  841 T:0a26  c6 81                              dec bonus_timer
  842 T:0a28  a0 1f                              ldy #31
  843 T:0a2a  a5 81                              lda bonus_timer
  844 T:0a2c  29 04                              and #4             ;every 4 ticks, switch from pathway to space sprite
  845 T:0a2e  d0 02                              bne show_bonus_animation
  846 T:0a30  a0 00                              ldy #0
  847 T:0a32                           show_bonus_animation 
  848 T:0a32  8c 42 1e                           sty cell_type_to_sprite
  849 T:0a35                           skip_bonus_animation 

  851 T:0a35                                    ; use the tick counter (bottom two bits scaled up by 16) to update amoeba animation (and apply to slime as well)
  852 T:0a35  a5 8a                              lda tick_counter
  853 T:0a37  29 03                              and #3
  854 T:0a39  0a                                 asl 
  855 T:0a3a  0a                                 asl 
  856 T:0a3b  0a                                 asl 
  857 T:0a3c  0a                                 asl 
  858 T:0a3d  aa                                 tax 
  859 T:0a3e  bd 49 1e                           lda amoeba_animated_sprite0,x
  860 T:0a41  49 01                              eor #1
  861 T:0a43  9d 49 1e                           sta amoeba_animated_sprite0,x
  862 T:0a46  9d 4b 1e                           sta slime_animated_sprite0,x
  863 T:0a49  bd 89 1e                           lda amoeba_animated_sprite4,x
  864 T:0a4c  49 01                              eor #1
  865 T:0a4e  9d 89 1e                           sta amoeba_animated_sprite4,x
  866 T:0a51  9d 8b 1e                           sta slime_animated_sprite1,x

  868 T:0a54                                    ; animate exit
  869 T:0a54  ad c8 1e                           lda exit_cell_type
  870 T:0a57  49 10                              eor #$10
  871 T:0a59  8d c8 1e                           sta exit_cell_type

  873 T:0a5c                                    ; update rockford idle animation
  874 T:0a5c  a5 8c                              lda ticks_since_last_direction_key_pressed
  875 T:0a5e  a8                                 tay 
  876 T:0a5f  29 3f                              and #$3f
  877 T:0a61  aa                                 tax 
  878 T:0a62  bd 59 1f                           lda idle_animation_data,x
  879 T:0a65                                    ; check for nearing the end of the idle animation (range $c0-$ff).
  880 T:0a65                                    ; Use the top nybbles of the data if so.
  881 T:0a65  c0 c0                              cpy #$c0
  882 T:0a67  90 04                              bcc extract_lower_nybble
  883 T:0a69                                    ; Near the end of the idle animation. Shift the upper nybble into the bottom nybble
  884 T:0a69                                    ; to get more idle sprites
  885 T:0a69  4a                                 lsr 
  886 T:0a6a  4a                                 lsr 
  887 T:0a6b  4a                                 lsr 
  888 T:0a6c  4a                                 lsr 
  889 T:0a6d                           extract_lower_nybble 
  890 T:0a6d  29 0f                              and #$0f
  891 T:0a6f                                    ; set the rockford sprite
  892 T:0a6f  09 20                              ora #32
  893 T:0a71  8d 51 1e                           sta rockford_sprite
  894 T:0a74  e6 8c                              inc ticks_since_last_direction_key_pressed
  895 T:0a76  60                                 rts 

  897 T:0a77                                    ; *************************************************************************************
  898 T:0a77                                    ; Game action starts here, playing one of Rockford's lives
  899 T:0a77                           play_one_life 

  901 T:0a77                                    ;set-up cave and variables
  902 T:0a77  20 87 0a                           jsr prepare_cave

  904 T:0a7a                                    ;main game play loop
  905 T:0a7a  20 3c 0d                           jsr gameplay_loop

  907 T:0a7d                                    ;check for game over
  908 T:0a7d  a5 73                              lda player_lives
  909 T:0a7f  d0 05                              bne not_game_over

  911 T:0a81  a0 6c                              ldy #108
  912 T:0a83  20 ab 0c                           jsr update_status_message

  914 T:0a86                           not_game_over 
  915 T:0a86  60                                 rts 

  917 T:0a87                                    ; *************************************************************************************
  918 T:0a87                           prepare_cave 

  920 T:0a87  20 38 1a                           jsr load_cave_data
  921 T:0a8a  20 ce 0a                           jsr initialise_variables
  922 T:0a8d  20 64 1a                           jsr populate_cave_from_loaded_data

  924 T:0a90  a5 74                              lda cave_number
  925 T:0a92  c9 14                              cmp #20             ;Cave Z (intro cave)
  926 T:0a94  d0 14                              bne prepare_standard_cave
  927 T:0a96                                    ;set visible map and Rockford position for drawing grid
  928 T:0a96  a9 00                              lda #0
  929 T:0a98  85 6d                              sta visible_top_left_map_x
  930 T:0a9a  85 6e                              sta visible_top_left_map_y
  931 T:0a9c  20 64 0c                           jsr set_rockford_start
  932 T:0a9f  a9 00                              lda #0             ; set growing wall sprite to space sprite for intro screen, creating a blank obstacle
  933 T:0aa1  8d 4e 1e                           sta growing_wall_sprite
  934 T:0aa4  20 6b 0f                           jsr clear_screen
  935 T:0aa7  4c c0 0a                           jmp continue_prepare_cave
  936 T:0aaa                           prepare_standard_cave 
  937 T:0aaa  20 ad 1a                           jsr populate_cave_tiles_pseudo_random
  938 T:0aad  20 c9 0b                           jsr initialise_stage
  939 T:0ab0  a9 0a                              lda #10
  940 T:0ab2  8d 4e 1e                           sta growing_wall_sprite
  941 T:0ab5  20 e0 0c                           jsr update_cave_time
  942 T:0ab8  20 97 0c                           jsr update_status_bar
  943 T:0abb  a0 ff                              ldy #255
  944 T:0abd  20 ab 0c                           jsr update_status_message
  945 T:0ac0                           continue_prepare_cave 
  946 T:0ac0                                    ;initialise cave for game
  947 T:0ac0  20 0c 0b                           jsr set_cave_colours
  948 T:0ac3  20 92 0b                           jsr draw_borders
  949 T:0ac6  20 be 0b                           jsr reset_grid_of_sprites

  951 T:0ac9                                    ;dissolve screen when starting
  952 T:0ac9  a9 00                              lda #0
  953 T:0acb  4c 30 0b                           jmp screen_dissolve_effect

  955 T:0ace                                    ; *************************************************************************************
  956 T:0ace                           initialise_variables 
  957 T:0ace  a9 9f                              lda #$9f
  958 T:0ad0  85 82                              sta rockford_cell_value
  959 T:0ad2  a9 f0                              lda #240
  960 T:0ad4  85 8c                              sta ticks_since_last_direction_key_pressed
  961 T:0ad6  a9 1f                              lda #31
  962 T:0ad8  85 8a                              sta tick_counter
  963 T:0ada  a9 0c                              lda #12
  964 T:0adc  85 8b                              sta sub_second_ticks
  965 T:0ade  a9 04                              lda #4
  966 T:0ae0  85 87                              sta delay_trying_to_push_rock
  967 T:0ae2  a9 0d                              lda #13
  968 T:0ae4  85 7b                              sta magic_wall_state
  969 T:0ae6  85 7d                              sta amoeba_growth_interval
  970 T:0ae8  a9 ff                              lda #255
  971 T:0aea  85 88                              sta saved_message
  972 T:0aec  a9 01                              lda #1
  973 T:0aee  85 7e                              sta amoeba_counter
  974 T:0af0  85 89                              sta message_timer
  975 T:0af2  a9 00                              lda #0
  976 T:0af4  85 7f                              sta amoeba_replacement
  977 T:0af6  85 80                              sta number_of_amoeba_cells_found
  978 T:0af8  85 83                              sta current_rockford_sprite
  979 T:0afa  85 84                              sta rockford_explosion_cell_type
  980 T:0afc  85 81                              sta bonus_timer
  981 T:0afe  8d 42 1e                           sta cell_type_to_sprite                ;ensure space is the first sprite in table
  982 T:0b01  85 8d                              sta play_sound_fx
  983 T:0b03  85 8e                              sta play_ambient_fx
  984 T:0b05  8d 00 22                           sta active_sound_duration
  985 T:0b08  8d 01 22                           sta active_ambient_duration
  986 T:0b0b  60                                 rts 

  988 T:0b0c                                    ; *************************************************************************************
  989 T:0b0c                                    ; Set the cave colour, which is the first line of each row on the screen
  990 T:0b0c                           set_cave_colours 

  992 T:0b0c  a0 00                              ldy #0             ;always 0 for indirect addressing in this case
  993 T:0b0e  a2 00                              ldx #0
  994 T:0b10                           loop_plot_row_colour 
  995 T:0b10  bd 21 08                           lda char_screen_low,x
  996 T:0b13  85 60                              sta screen_addr1_low
  997 T:0b15  bd 2d 08                           lda char_screen_high,x
  998 T:0b18  85 61                              sta screen_addr1_high

 1000 T:0b1a  bd 39 08                           lda char_screen_below_low,x
 1001 T:0b1d  85 62                              sta screen_addr2_low
 1002 T:0b1f  bd 45 08                           lda char_screen_below_high,x
 1003 T:0b22  85 63                              sta screen_addr2_high

 1005 T:0b24                           set_line_colour 
 1006 T:0b24  a9 03                              lda #3             ;yellow, this is a self-mod address used to choose cave colour scheme
 1007 T:0b26  91 60                              sta (screen_addr1_low),y
 1008 T:0b28  91 62                              sta (screen_addr2_low),y

 1010 T:0b2a  e8                                 inx 
 1011 T:0b2b  e0 0c                              cpx #12             ;12 rows
 1012 T:0b2d  90 e1                              bcc loop_plot_row_colour
 1013 T:0b2f  60                                 rts 

 1015 T:0b30                                    ; *************************************************************************************
 1016 T:0b30                                    ; Apply the cave open/close tiles which show/hide the tiles on screen
 1017 T:0b30                                    ; Performed in a loop using the game tick counter
 1018 T:0b30                           screen_dissolve_effect 
 1019 T:0b30  8d 6f 0b                           sta dissolve_to_solid_flag+1
 1020 T:0b33  a9 21                              lda #$21
 1021 T:0b35  85 8a                              sta tick_counter
 1022 T:0b37                           screen_dissolve_loop 
 1023 T:0b37  20 4a 0b                           jsr reveal_or_hide_more_cells
 1024 T:0b3a  20 86 09                           jsr update_map_scroll_position
 1025 T:0b3d  20 00 09                           jsr draw_grid_of_sprites
 1026 T:0b40  c6 8a                              dec tick_counter
 1027 T:0b42  10 f3                              bpl screen_dissolve_loop

 1029 T:0b44                                    ; reset dissolve_to_solid_flag which stops interrupt running this routine
 1030 T:0b44  a9 00                              lda #0
 1031 T:0b46  8d 6f 0b                           sta dissolve_to_solid_flag+1
 1032 T:0b49  60                                 rts 

 1034 T:0b4a                                    ; *************************************************************************************
 1035 T:0b4a                                    ; Apply the tile show/hide routine for each game play tick
 1036 T:0b4a                           reveal_or_hide_more_cells 
 1037 T:0b4a  a0 00                              ldy #<tile_map_row_0
 1038 T:0b4c  84 64                              sty map_address_low
 1039 T:0b4e  a9 10                              lda #>tile_map_row_0
 1040 T:0b50  85 65                              sta map_address_high

 1042 T:0b52  a2 16                              ldx #22
 1043 T:0b54                           loop_over_rows 
 1044 T:0b54                                    ; use 'random' audio pitches to play while revealing/hiding the map
 1045 T:0b54  a9 92                              lda #146
 1046 T:0b56  85 8e                              sta play_ambient_fx

 1048 T:0b58  a5 64                              lda map_address_low
 1049 T:0b5a                                    ; rows are stored in the first 40 bytes of every 64 bytes, so skip if we have
 1050 T:0b5a                                    ; exceeded the right range
 1051 T:0b5a  29 3f                              and #63
 1052 T:0b5c  c9 28                              cmp #40
 1053 T:0b5e  10 1b                              bpl skip_to_next_row
 1054 T:0b60                                    ; progress a counter in a non-obvious pattern
 1055 T:0b60  20 84 0b                           jsr get_next_random_byte
 1056 T:0b63                                    ; if it's early in the process (tick counter is low), then branch more often so we
 1057 T:0b63                                    ; reveal/hide the cells in a non-obvious pattern over time
 1058 T:0b63  4a                                 lsr 
 1059 T:0b64  4a                                 lsr 
 1060 T:0b65  4a                                 lsr 
 1061 T:0b66  c5 8a                              cmp tick_counter
 1062 T:0b68  d0 08                              bne skip_reveal_or_hide
 1063 T:0b6a  b1 64                              lda (map_address_low),y
 1064 T:0b6c                                    ; clear the top bit to reveal the cell...
 1065 T:0b6c  29 7f                              and #$7f
 1066 T:0b6e                                    ; ...or set the top bit to hide the cell
 1067 T:0b6e                           dissolve_to_solid_flag 
 1068 T:0b6e  09 00                              ora #0             ;self-mod map_space or map_unprocessed
 1069 T:0b70  91 64                              sta (map_address_low),y
 1070 T:0b72                           skip_reveal_or_hide 
 1071 T:0b72  e6 64                              inc map_address_low
 1072 T:0b74  d0 02                              bne skip_increment
 1073 T:0b76  e6 65                              inc map_address_high
 1074 T:0b78                           skip_increment 
 1075 T:0b78  18                                 clc 
 1076 T:0b79  90 d9                              bcc loop_over_rows
 1077 T:0b7b                                    ; move forward to next row. Each row is stored at 64 byte intervals. We have moved
 1078 T:0b7b                                    ; on 40 so far so add the remainder to get to the next row
 1079 T:0b7b                           skip_to_next_row 
 1080 T:0b7b  a9 18                              lda #64-40
 1081 T:0b7d  20 61 0f                           jsr add_a_to_ptr
 1082 T:0b80  ca                                 dex 
 1083 T:0b81  d0 d1                              bne loop_over_rows
 1084 T:0b83  60                                 rts 

 1086 T:0b84                                    ; *************************************************************************************
 1087 T:0b84                                    ; A small 'pseudo-random' number routine. Generates a sequence of 256 numbers.
 1088 T:0b84                           get_next_random_byte 
 1089 T:0b84  a9 00                              lda #0
 1090 T:0b86  0a                                 asl 
 1091 T:0b87  0a                                 asl 
 1092 T:0b88  0a                                 asl 
 1093 T:0b89  0a                                 asl 
 1094 T:0b8a  38                                 sec 
 1095 T:0b8b  6d 85 0b                           adc get_next_random_byte+1
 1096 T:0b8e  8d 85 0b                           sta get_next_random_byte+1
 1097 T:0b91  60                                 rts 

 1099 T:0b92                                    ; *************************************************************************************
 1100 T:0b92                                    ; Loop over all rows, plotting side borders from the cave file
 1101 T:0b92                           draw_borders 

 1103 T:0b92                                    ;set start of map
 1104 T:0b92  a9 40                              lda #<tile_map_row_1
 1105 T:0b94  85 64                              sta map_address_low
 1106 T:0b96  a9 10                              lda #>tile_map_row_1
 1107 T:0b98  85 65                              sta map_address_high

 1109 T:0b9a  a2 15                              ldx #21
 1110 T:0b9c                           write_left_and_right_borders_loop 
 1111 T:0b9c  a0 26                              ldy #38
 1112 T:0b9e                           cells_to_processed_loop 
 1113 T:0b9e  b1 64                              lda (map_address_low),y
 1114 T:0ba0  09 80                              ora #128
 1115 T:0ba2  91 64                              sta (map_address_low),y
 1116 T:0ba4  88                                 dey 
 1117 T:0ba5  d0 f7                              bne cells_to_processed_loop
 1118 T:0ba7  a9 40                              lda #$40
 1119 T:0ba9  20 61 0f                           jsr add_a_to_ptr
 1120 T:0bac  ca                                 dex 
 1121 T:0bad  d0 ed                              bne write_left_and_right_borders_loop
 1122 T:0baf                                    ; write the top and bottom borders using param_border_tile (steelwall if zero)
 1123 T:0baf  ad 2a 26                           lda param_border_tile
 1124 T:0bb2  a2 27                              ldx #39
 1125 T:0bb4                           write_top_and_bottom_borders_loop 
 1126 T:0bb4  9d 00 10                           sta tile_map_row_0,x
 1127 T:0bb7  9d 40 15                           sta tile_map_row_21,x
 1128 T:0bba  ca                                 dex 
 1129 T:0bbb  10 f7                              bpl write_top_and_bottom_borders_loop
 1130 T:0bbd  60                                 rts 

 1132 T:0bbe                                    ; *************************************************************************************
 1133 T:0bbe                           reset_grid_of_sprites 
 1134 T:0bbe  a2 e4                              ldx #(12*19)     ;12 rows x 19 columns of sprites on a screen
 1135 T:0bc0  a9 ff                              lda #$ff
 1136 T:0bc2                           reset_grid_of_sprites_loop 
 1137 T:0bc2  ca                                 dex 
 1138 T:0bc3  9d a2 24                           sta screen_cache_map,x
 1139 T:0bc6  d0 fa                              bne reset_grid_of_sprites_loop
 1140 T:0bc8  60                                 rts 

 1142 T:0bc9                                    ; *************************************************************************************
 1143 T:0bc9                                    ; Apply the parameters for the cave being played
 1144 T:0bc9                           initialise_stage 

 1146 T:0bc9                                    ;Needed for rom v1.0 (Oric-1) but kept anyway, initialise $100 onwards where a number as an ASCII string is stored
 1147 T:0bc9  a9 00                              lda #0
 1148 T:0bcb  20 d5 e0                           jsr $e0d5              ;output accumulator into an ASCII string, stored at $100 upwards, ending with $00  ;output accumulator into an ASCII string, stored at $100 upwards, ending with $00 by calling $e0d5 ($e0d1)

 1150 T:0bce  a9 14                              lda #20
 1151 T:0bd0  85 6d                              sta visible_top_left_map_x
 1152 T:0bd2  4a                                 lsr 
 1153 T:0bd3  85 6e                              sta visible_top_left_map_y

 1155 T:0bd5                                    ; set the delay between amoeba growth
 1156 T:0bd5  ad 0c 26                           lda param_amoeba_magic_wall_time
 1157 T:0bd8  85 7d                              sta amoeba_growth_interval
 1158 T:0bda  85 7c                              sta magic_wall_timer

 1160 T:0bdc                                    ; set growing wall sprite to the correct sprite (space sprite used in intro screen)
 1161 T:0bdc  a9 10                              lda #16
 1162 T:0bde  8d 4e 1e                           sta growing_wall_sprite

 1164 T:0be1                                    ; set the gravity timer
 1165 T:0be1  a0 00                              ldy #0
 1166 T:0be3  ad 29 26                           lda param_zero_gravity_time
 1167 T:0be6  f0 02                              beq dont_allow_rock_push_up
 1168 T:0be8  a0 ee                              ldy #$ee             ;Special value used to detect rock has been pushed up, only applies when gravity is off
 1169 T:0bea                           dont_allow_rock_push_up 
 1170 T:0bea  85 7a                              sta gravity_timer
 1171 T:0bec  8c 42 20                           sty rock_push_directions+2

 1173 T:0bef                                    ; initialise random seed for possible use with slime permeability
 1174 T:0bef  a9 00                              lda #0
 1175 T:0bf1  8d 79 1b                           sta random_seed2

 1177 T:0bf4                                    ; put the end tile on the map
 1178 T:0bf4  ad 21 26                           lda param_rockford_end
 1179 T:0bf7  85 61                              sta screen_addr1_high
 1180 T:0bf9  ad 22 26                           lda param_rockford_end+1
 1181 T:0bfc  85 60                              sta screen_addr1_low
 1182 T:0bfe  20 f5 09                           jsr map_xy_position_to_map_address
 1183 T:0c01  a0 00                              ldy #0
 1184 T:0c03  a9 03                              lda #3
 1185 T:0c05  91 64                              sta (map_address_low),y
 1186 T:0c07  a5 64                              lda map_address_low
 1187 T:0c09  85 6b                              sta map_rockford_end_position_addr_low
 1188 T:0c0b  a5 65                              lda map_address_high
 1189 T:0c0d  85 6c                              sta map_rockford_end_position_addr_high

 1191 T:0c0f                                    ; put the start tile on the map
 1192 T:0c0f  20 64 0c                           jsr set_rockford_start

 1194 T:0c12                                    ;set cave parameters
 1195 T:0c12  a6 75                              ldx difficulty_level
 1196 T:0c14  ca                                 dex 
 1197 T:0c15  bd 02 26                           lda param_diamonds_required,x
 1198 T:0c18  85 76                              sta diamonds_required
 1199 T:0c1a  bd 07 26                           lda param_cave_time,x
 1200 T:0c1d  85 77                              sta time_remaining
 1201 T:0c1f  ad 28 26                           lda param_bombs
 1202 T:0c22  85 78                              sta bomb_counter
 1203 T:0c24  f0 17                              beq clear_bomb_on_status_bar
 1204 T:0c26  a9 7b                              lda #"{"
 1205 T:0c28  8d 8e 20                           sta status_bar_line1+26
 1206 T:0c2b  a9 7c                              lda #"|"
 1207 T:0c2d  8d 8f 20                           sta status_bar_line1+27
 1208 T:0c30  a9 7d                              lda #"}"
 1209 T:0c32  8d b6 20                           sta status_bar_line2+26
 1210 T:0c35  a9 7e                              lda #"~"
 1211 T:0c37  8d b7 20                           sta status_bar_line2+27
 1212 T:0c3a  4c 4b 0c                           jmp update_status_bar_from_params
 1213 T:0c3d                           clear_bomb_on_status_bar 
 1214 T:0c3d  a9 20                              lda #32
 1215 T:0c3f  8d 8e 20                           sta status_bar_line1+26
 1216 T:0c42  8d 8f 20                           sta status_bar_line1+27
 1217 T:0c45  8d b6 20                           sta status_bar_line2+26
 1218 T:0c48  8d b7 20                           sta status_bar_line2+27
 1219 T:0c4b                           update_status_bar_from_params 

 1221 T:0c4b                                    ;cave letter and difficulty level on status bar
 1222 T:0c4b  a5 74                              lda cave_number
 1223 T:0c4d  18                                 clc 
 1224 T:0c4e  69 41                              adc #"A"             ; Add letter "A" to get the cave letter for the cave number (which starts from zero)
 1225 T:0c50  8d 99 20                           sta status_bar_line1+37
 1226 T:0c53  a5 75                              lda difficulty_level
 1227 T:0c55  18                                 clc 
 1228 T:0c56  69 30                              adc #"0"
 1229 T:0c58  8d 9a 20                           sta status_bar_line1+38

 1231 T:0c5b                                    ;update diamonds required, bombs available, player lives on status bar
 1232 T:0c5b  20 c8 0c                           jsr update_diamonds_required
 1233 T:0c5e  20 d1 0c                           jsr update_bombs_available
 1234 T:0c61  4c e9 0c                           jmp update_player_lives

 1236 T:0c64                                    ; *************************************************************************************
 1237 T:0c64                                    ; Set Rockford start position (row/column) on map
 1238 T:0c64                           set_rockford_start 

 1240 T:0c64  ad 1f 26                           lda param_rockford_start
 1241 T:0c67  85 61                              sta screen_addr1_high
 1242 T:0c69  ad 20 26                           lda param_rockford_start+1
 1243 T:0c6c  85 60                              sta screen_addr1_low
 1244 T:0c6e  20 f5 09                           jsr map_xy_position_to_map_address
 1245 T:0c71  a0 00                              ldy #0
 1246 T:0c73  a9 08                              lda #8
 1247 T:0c75  91 64                              sta (map_address_low),y
 1248 T:0c77  a5 64                              lda map_address_low
 1249 T:0c79  85 69                              sta map_rockford_current_position_addr_low
 1250 T:0c7b  a5 65                              lda map_address_high
 1251 T:0c7d  85 6a                              sta map_rockford_current_position_addr_high
 1252 T:0c7f  60                                 rts 

 1254 T:0c80                                    ; *************************************************************************************
 1255 T:0c80                                    ; Determine next cave to play, which depends on cave sequence, bonus caves and difficulty level
 1256 T:0c80                           calculate_next_cave_number_and_level 

 1258 T:0c80  a6 74                              ldx cave_number
 1259 T:0c82  a4 75                              ldy difficulty_level
 1260 T:0c84  bd 60 20                           lda cave_play_order,x
 1261 T:0c87  85 74                              sta cave_number
 1262 T:0c89  d0 07                              bne store_cave_number_and_difficulty_level
 1263 T:0c8b  c8                                 iny 
 1264 T:0c8c  c0 06                              cpy #6
 1265 T:0c8e  d0 02                              bne store_cave_number_and_difficulty_level
 1266 T:0c90  a0 01                              ldy #1
 1267 T:0c92                           store_cave_number_and_difficulty_level 
 1268 T:0c92  84 75                              sty difficulty_level
 1269 T:0c94  85 74                              sta cave_number
 1270 T:0c96  60                                 rts 

 1272 T:0c97                                    ; *************************************************************************************
 1273 T:0c97                                    ; Set the status bar display with values applied during the games (cave time, diamonds required, etc)
 1274 T:0c97                           update_status_bar 

 1276 T:0c97  a0 29                              ldy #41
 1277 T:0c99                           status_bar_loop 
 1278 T:0c99  88                                 dey 
 1279 T:0c9a  b9 74 20                           lda status_bar_line1,y
 1280 T:0c9d  99 80 bb                           sta $bb80,y
 1281 T:0ca0  b9 9c 20                           lda status_bar_line2,y
 1282 T:0ca3  99 a8 bb                           sta $bb80+40,y
 1283 T:0ca6  c0 00                              cpy #0
 1284 T:0ca8  d0 ef                              bne status_bar_loop
 1285 T:0caa  60                                 rts 

 1287 T:0cab                                    ; *************************************************************************************
 1288 T:0cab                                    ; Set the status message display with the required status message in Y register
 1289 T:0cab                           update_status_message 

 1291 T:0cab  a2 00                              ldx #0
 1292 T:0cad                           status_message_loop 
 1293 T:0cad  a9 20                              lda #" "
 1294 T:0caf  c0 ff                              cpy #255
 1295 T:0cb1  f0 0c                              beq plot_char
 1296 T:0cb3  e0 0a                              cpx #10
 1297 T:0cb5  90 08                              bcc plot_char
 1298 T:0cb7  e0 1c                              cpx #28
 1299 T:0cb9  b0 04                              bcs plot_char
 1300 T:0cbb  b9 c4 20                           lda status_messages,y
 1301 T:0cbe  c8                                 iny 
 1302 T:0cbf                           plot_char 
 1303 T:0cbf  9d d0 bb                           sta $bb80+80,x
 1304 T:0cc2  e8                                 inx 
 1305 T:0cc3  e0 27                              cpx #39
 1306 T:0cc5  d0 e6                              bne status_message_loop
 1307 T:0cc7  60                                 rts 

 1309 T:0cc8                                    ; *************************************************************************************
 1310 T:0cc8                           update_diamonds_required 
 1311 T:0cc8  a2 05                              ldx #5             ;diamonds required start position
 1312 T:0cca  a4 76                              ldy diamonds_required
 1313 T:0ccc  a9 00                              lda #0
 1314 T:0cce  4c f8 0c                           jmp add_to_status_bar

 1316 T:0cd1                                    ; *************************************************************************************
 1317 T:0cd1                           update_bombs_available 

 1319 T:0cd1  ad 28 26                           lda param_bombs
 1320 T:0cd4  f0 09                              beq cave_has_no_bombs

 1322 T:0cd6  a2 1e                              ldx #30             ;bombs available start position
 1323 T:0cd8  a4 78                              ldy bomb_counter
 1324 T:0cda  a9 00                              lda #0
 1325 T:0cdc  4c f8 0c                           jmp add_to_status_bar

 1327 T:0cdf                           cave_has_no_bombs 
 1328 T:0cdf  60                                 rts 

 1330 T:0ce0                                    ; *************************************************************************************
 1331 T:0ce0                           update_cave_time 
 1332 T:0ce0  a2 13                              ldx #19             ;cave time start position
 1333 T:0ce2  a4 77                              ldy time_remaining
 1334 T:0ce4  a9 00                              lda #0
 1335 T:0ce6  4c f8 0c                           jmp add_to_status_bar

 1337 T:0ce9                                    ; *************************************************************************************
 1338 T:0ce9                           update_player_lives 
 1339 T:0ce9  a2 0e                              ldx #14             ;lives available start position
 1340 T:0ceb  a4 73                              ldy player_lives
 1341 T:0ced  a9 00                              lda #0
 1342 T:0cef  4c f8 0c                           jmp add_to_status_bar

 1344 T:0cf2                                    ; *************************************************************************************
 1345 T:0cf2                           update_player_score 
 1346 T:0cf2  a2 22                              ldx #34             ;score start position
 1347 T:0cf4  a4 6f                              ldy score_low
 1348 T:0cf6  a5 70                              lda score_high

 1350 T:0cf8                                    ; *************************************************************************************
 1351 T:0cf8                                    ; Converts a given value in bytes into readable ASCII and displays it on the status bar
 1352 T:0cf8                                    ; Parameters are X register for the position of the status bar value to update, 
 1353 T:0cf8                                    ;   Y for the value (low byte), and A for the value (high byte)
 1354 T:0cf8                           add_to_status_bar 

 1356 T:0cf8  86 71                              stx temp1             ;start position of value to update
 1357 T:0cfa  85 72                              sta temp2             ;high byte of value to add
 1358 T:0cfc  20 99 d4                           jsr $d499              ;convert integer in Y(low) and A(high) to accumulator  ;convert integer in Y(low) and A(high) to accumulator by calling $d499 ($d3ed)
 1359 T:0cff  20 d5 e0                           jsr $e0d5              ;output accumulator into an ASCII string, stored at $100 upwards, ending with $00  ;output accumulator into an ASCII string, stored at $100 upwards, ending with $00 by calling $e0d5 ($e0d1)

 1361 T:0d02  a5 72                              lda temp2
 1362 T:0d04  f0 05                              beq not_high_byte_value
 1363 T:0d06  a9 06                              lda #6             ;control digits to display (applies to score)
 1364 T:0d08  4c 0d 0d                           jmp convert_integer
 1365 T:0d0b                           not_high_byte_value 
 1366 T:0d0b  a9 04                              lda #4             ;control digits to display (applies to diamonds required, bombs, cave time, lives)
 1367 T:0d0d                           convert_integer 
 1368 T:0d0d  8d 2a 0d                           sta dont_want_space+2
 1369 T:0d10  8d 2e 0d                           sta add_spaces_after+1

 1371 T:0d13  a4 71                              ldy temp1             ;start position on status bar
 1372 T:0d15  a2 00                              ldx #0
 1373 T:0d17                           copy_digits_to_status_bar 
 1374 T:0d17  bd 01 01                           lda $0101,x            ;string of ASCII characters after leading space
 1375 T:0d1a  d0 04                              bne digit_or_space
 1376 T:0d1c  e8                                 inx 
 1377 T:0d1d  4c 2d 0d                           jmp add_spaces_after
 1378 T:0d20                           digit_or_space 
 1379 T:0d20  c9 20                              cmp #32
 1380 T:0d22  f0 04                              beq dont_want_space
 1381 T:0d24  99 9c 20                           sta status_bar_line2,y
 1382 T:0d27  c8                                 iny 
 1383 T:0d28                           dont_want_space 
 1384 T:0d28  e8                                 inx 
 1385 T:0d29  e0 04                              cpx #4             ;Max will use
 1386 T:0d2b  d0 ea                              bne copy_digits_to_status_bar
 1387 T:0d2d                           add_spaces_after 
 1388 T:0d2d  e0 04                              cpx #4             ;Max will use
 1389 T:0d2f  b0 0a                              bcs add_status_return
 1390 T:0d31  a9 20                              lda #32
 1391 T:0d33  99 9c 20                           sta status_bar_line2,y
 1392 T:0d36  c8                                 iny 
 1393 T:0d37  e8                                 inx 
 1394 T:0d38  4c 2d 0d                           jmp add_spaces_after
 1395 T:0d3b                           add_status_return 
 1396 T:0d3b  60                                 rts 

 1398 T:0d3c                                    ; *************************************************************************************
 1399 T:0d3c                                    ; Plays the cave, each iteration of the loop is a game play tick
 1400 T:0d3c                                    ; The loop ends when Rockford's completes the cave or loses a life
 1401 T:0d3c                           gameplay_loop 

 1403 T:0d3c  a9 00                              lda #0
 1404 T:0d3e  85 85                              sta current_amoeba_cell_type
 1405 T:0d40  85 86                              sta neighbour_cell_contents

 1407 T:0d42                                    ; reset number of amoeba cells found, and if already zero then clear the amoeba_replacement
 1408 T:0d42  a2 00                              ldx #0
 1409 T:0d44  a5 80                              lda number_of_amoeba_cells_found
 1410 T:0d46  86 80                              stx number_of_amoeba_cells_found
 1411 T:0d48  d0 02                              bne skip_clearing_amoeba_replacement
 1412 T:0d4a  86 7f                              stx amoeba_replacement
 1413 T:0d4c                           skip_clearing_amoeba_replacement 
 1414 T:0d4c  86 85                              stx current_amoeba_cell_type

 1416 T:0d4e  20 c0 15                           jsr update_map
 1417 T:0d51  20 e0 0c                           jsr update_cave_time
 1418 T:0d54  20 97 0c                           jsr update_status_bar             ;time will always need updating, and sometimes the other values (updated for those events)

 1420 T:0d57                                    ;update status message
 1421 T:0d57  a5 89                              lda message_timer             ;check if a message should be displayed
 1422 T:0d59  f0 17                              beq skip_message_update
 1423 T:0d5b  c6 89                              dec message_timer
 1424 T:0d5d  a4 88                              ldy saved_message
 1425 T:0d5f  a5 89                              lda message_timer
 1426 T:0d61  29 04                              and #4             ;every 4 ticks, clear message then switch back to saved message
 1427 T:0d63  d0 0a                              bne show_message_update
 1428 T:0d65  c0 36                              cpy #54
 1429 T:0d67  d0 04                              bne skip_hurry_sound
 1430 T:0d69  a9 62                              lda #98             ;same as diamond_move_sound
 1431 T:0d6b  85 8d                              sta play_sound_fx
 1432 T:0d6d                           skip_hurry_sound 

 1434 T:0d6d  a0 ff                              ldy #255
 1435 T:0d6f                           show_message_update 
 1436 T:0d6f  20 ab 0c                           jsr update_status_message
 1437 T:0d72                           skip_message_update 

 1439 T:0d72                                    ; get the contents of the cell that rockford is influencing. This can be the cell
 1440 T:0d72                                    ; underneath rockford, or by holding the RETURN key down and pressing a direction
 1441 T:0d72                                    ; key it can be one of the neighbouring cells.
 1442 T:0d72                                    ; We clear the top bits to just extract the basic type.
 1443 T:0d72  a5 86                              lda neighbour_cell_contents
 1444 T:0d74  29 0f                              and #$0f
 1445 T:0d76  85 86                              sta neighbour_cell_contents
 1446 T:0d78  c9 08                              cmp #8
 1447 T:0d7a  d0 03                              bne rockford_is_not_at_end_position
 1448 T:0d7c  4c 33 0e                           jmp update_with_gameplay_not_active                ;Rockford is at the end position (rts from this jmp returns to jsr gameplay_loop)

 1450 T:0d7f                           rockford_is_not_at_end_position 
 1451 T:0d7f  20 86 09                           jsr update_map_scroll_position
 1452 T:0d82  20 00 09                           jsr draw_grid_of_sprites
 1453 T:0d85  20 33 19                           jsr update_amoeba_timing

 1455 T:0d88                                    ; check if the player is still alive by reading the current rockford sprite (branch if not)
 1456 T:0d88  a5 83                              lda current_rockford_sprite
 1457 T:0d8a  f0 17                              beq check_for_earth
 1458 T:0d8c                                    ; update game timer (sub seconds)
 1459 T:0d8c  c6 8b                              dec sub_second_ticks
 1460 T:0d8e  10 13                              bpl check_for_earth
 1461 T:0d90                                    ; each 'second' of game time has 11 game ticks
 1462 T:0d90  a2 0b                              ldx #11
 1463 T:0d92  86 8b                              stx sub_second_ticks
 1464 T:0d94                                    ; decrement time remaining ('seconds') on the status bar
 1465 T:0d94  c6 77                              dec time_remaining
 1466 T:0d96                                    ; branch if there's still time left
 1467 T:0d96  d0 0b                              bne check_for_earth
 1468 T:0d98                                    ; out of time
 1469 T:0d98  a0 48                              ldy #72
 1470 T:0d9a  20 ab 0c                           jsr update_status_message
 1471 T:0d9d  20 33 0e                           jsr update_with_gameplay_not_active
 1472 T:0da0  4c 22 0e                           jmp lose_a_life

 1474 T:0da3                           check_for_earth 
 1475 T:0da3  a5 77                              lda time_remaining
 1476 T:0da5  c9 0a                              cmp #10
 1477 T:0da7  f0 03                              beq hurry_up
 1478 T:0da9  4c b8 0d                           jmp check_for_diamond
 1479 T:0dac                           hurry_up  
 1480 T:0dac  a9 62                              lda #98             ;same as diamond_move_sound
 1481 T:0dae  85 8d                              sta play_sound_fx
 1482 T:0db0  a9 36                              lda #54
 1483 T:0db2  85 88                              sta saved_message
 1484 T:0db4  a9 67                              lda #$67
 1485 T:0db6  85 89                              sta message_timer
 1486 T:0db8                           check_for_diamond 
 1487 T:0db8  a5 86                              lda neighbour_cell_contents
 1488 T:0dba  c9 04                              cmp #4
 1489 T:0dbc  d0 0d                              bne skip_got_diamond

 1491 T:0dbe  a2 12                              ldx #18
 1492 T:0dc0  86 8d                              stx play_sound_fx

 1494 T:0dc2  20 d9 0e                           jsr got_diamond_so_update_status_bar
 1495 T:0dc5  20 c8 0c                           jsr update_diamonds_required
 1496 T:0dc8  20 f2 0c                           jsr update_player_score

 1498 T:0dcb                           skip_got_diamond 
 1499 T:0dcb                                    ; update game tick
 1500 T:0dcb  c6 8a                              dec tick_counter
 1501 T:0dcd  a5 8a                              lda tick_counter
 1502 T:0dcf  29 07                              and #7
 1503 T:0dd1  d0 1f                              bne update_death_explosion
 1504 T:0dd3                                    ;update bomb delay timer
 1505 T:0dd3  a5 79                              lda bomb_delay
 1506 T:0dd5  f0 02                              beq end_update_bomb_delay
 1507 T:0dd7  c6 79                              dec bomb_delay
 1508 T:0dd9                           end_update_bomb_delay 
 1509 T:0dd9                                    ; update gravity timer
 1510 T:0dd9  a5 7a                              lda gravity_timer
 1511 T:0ddb  f0 0d                              beq end_update_gravity_timer                ;stop at zero
 1512 T:0ddd  c9 ff                              cmp #$ff
 1513 T:0ddf  f0 09                              beq end_update_gravity_timer                ;gravity is always on if set to #$ff
 1514 T:0de1  c6 7a                              dec gravity_timer
 1515 T:0de3  d0 05                              bne end_update_gravity_timer
 1516 T:0de5  a9 00                              lda #0
 1517 T:0de7  8d 42 20                           sta rock_push_directions+2
 1518 T:0dea                           end_update_gravity_timer 
 1519 T:0dea                                    ; update magic wall timer
 1520 T:0dea  a5 7b                              lda magic_wall_state
 1521 T:0dec  c9 1d                              cmp #13|16       ;active
 1522 T:0dee  d0 02                              bne update_death_explosion
 1523 T:0df0  c6 7c                              dec magic_wall_timer
 1524 T:0df2                           update_death_explosion 
 1525 T:0df2  a6 84                              ldx rockford_explosion_cell_type
 1526 T:0df4  f0 0d                              beq check_for_escape_key_pressed_to_die
 1527 T:0df6  e8                                 inx 
 1528 T:0df7  86 84                              stx rockford_explosion_cell_type
 1529 T:0df9  e0 4b                              cpx #$4b
 1530 T:0dfb  30 06                              bmi check_for_escape_key_pressed_to_die
 1531 T:0dfd                                    ; if key is pressed at end of the death explosion sequence, then reduce player lives and exit
 1532 T:0dfd  a5 5a                              lda _KeyRowArrows
 1533 T:0dff  d0 21                              bne lose_a_life
 1534 T:0e01  c6 84                              dec rockford_explosion_cell_type
 1535 T:0e03                                    ; branch if escape not pressed
 1536 T:0e03                           check_for_escape_key_pressed_to_die 
 1537 T:0e03  a5 5a                              lda _KeyRowArrows
 1538 T:0e05  29 10                              and #16
 1539 T:0e07  f0 08                              beq check_if_pause_is_available
 1540 T:0e09                                    ; branch if explosion already underway
 1541 T:0e09  a5 84                              lda rockford_explosion_cell_type
 1542 T:0e0b  d0 04                              bne check_if_pause_is_available
 1543 T:0e0d                                    ; start death explosion
 1544 T:0e0d  a9 46                              lda #70
 1545 T:0e0f  85 84                              sta rockford_explosion_cell_type
 1546 T:0e11                                    ; branch if on a bonus stage (no pause available)
 1547 T:0e11                           check_if_pause_is_available 
 1548 T:0e11  a5 74                              lda cave_number
 1549 T:0e13  c9 10                              cmp #16
 1550 T:0e15  10 08                              bpl gameplay_loop_local
 1551 T:0e17                                    ; check if pause pressed
 1552 T:0e17  20 d4 0e                           jsr check_for_pause_key
 1553 T:0e1a  f0 03                              beq gameplay_loop_local
 1554 T:0e1c  20 33 0e                           jsr update_with_gameplay_not_active
 1555 T:0e1f                           gameplay_loop_local 
 1556 T:0e1f  4c 3c 0d                           jmp gameplay_loop

 1558 T:0e22                           lose_a_life 
 1559 T:0e22  a5 74                              lda cave_number
 1560 T:0e24  c9 10                              cmp #16             ;don't lose a life on a bonus cave, just move to next cave instead
 1561 T:0e26  b0 08                              bcs unsuccessful_bonus_cave
 1562 T:0e28  c6 73                              dec player_lives
 1563 T:0e2a  20 e9 0c                           jsr update_player_lives
 1564 T:0e2d  4c 97 0c                           jmp update_status_bar
 1565 T:0e30                           unsuccessful_bonus_cave 
 1566 T:0e30  4c 80 0c                           jmp calculate_next_cave_number_and_level

 1568 T:0e33                                    ; *************************************************************************************
 1569 T:0e33                                    ; Update screen while paused, or out of time, or at end position
 1570 T:0e33                                    ;   (i.e. when gameplay started but is not currently active)
 1571 T:0e33                           update_with_gameplay_not_active 

 1573 T:0e33                                    ; check for pause key
 1574 T:0e33  20 d4 0e                           jsr check_for_pause_key
 1575 T:0e36  f0 2a                              beq check_if_end_position_reached
 1576 T:0e38                                    ; pause mode, show pause message
 1577 T:0e38  a9 00                              lda #0
 1578 T:0e3a  8d 48 0e                           sta pause_counter+1
 1579 T:0e3d                           update_while_initially_pressing_pause_loop 
 1580 T:0e3d  20 d4 0e                           jsr check_for_pause_key
 1581 T:0e40  d0 fb                              bne update_while_initially_pressing_pause_loop
 1582 T:0e42                           pause_loop 
 1583 T:0e42  ee 48 0e                           inc pause_counter+1
 1584 T:0e45  a0 00                              ldy #0
 1585 T:0e47                                    ; toggle between showing pause and clear message every 16 ticks
 1586 T:0e47                           pause_counter 
 1587 T:0e47  a9 00                              lda #0             ;Self-mod, see above
 1588 T:0e49  29 10                              and #$10
 1589 T:0e4b  f0 02                              beq skip_showing_players_and_men
 1590 T:0e4d  a0 ff                              ldy #255
 1591 T:0e4f                           skip_showing_players_and_men 
 1592 T:0e4f  20 c2 0e                           jsr update_during_pause_or_out_of_time
 1593 T:0e52  f0 ee                              beq pause_loop
 1594 T:0e54                           update_while_finally_pressing_unpause_loop 
 1595 T:0e54  20 d4 0e                           jsr check_for_pause_key
 1596 T:0e57  d0 fb                              bne update_while_finally_pressing_unpause_loop
 1597 T:0e59  a9 ff                              lda #255
 1598 T:0e5b  85 88                              sta saved_message
 1599 T:0e5d  a9 01                              lda #1
 1600 T:0e5f  85 89                              sta message_timer
 1601 T:0e61  60                                 rts 

 1603 T:0e62                           check_if_end_position_reached 
 1604 T:0e62  a5 86                              lda neighbour_cell_contents
 1605 T:0e64                                    ; check if end position has been reached
 1606 T:0e64  c9 08                              cmp #8
 1607 T:0e66  f0 13                              beq rockford_reached_end_position
 1608 T:0e68                                    ; show out of time message for a while, then return
 1609 T:0e68  a9 3e                              lda #$3e
 1610 T:0e6a  8d 7a 0e                           sta out_of_time_message_countdown
 1611 T:0e6d  a0 48                              ldy #72
 1612 T:0e6f                           out_of_time_loop 
 1613 T:0e6f  20 c2 0e                           jsr update_during_pause_or_out_of_time
 1614 T:0e72  d0 5f                              bne gameplay_not_active_return
 1615 T:0e74  ce 7a 0e                           dec out_of_time_message_countdown
 1616 T:0e77  d0 f6                              bne out_of_time_loop
 1617 T:0e79  60                                 rts 

 1619 T:0e7a                           out_of_time_message_countdown 
 1620 T:0e7a  00                                 .byt 0

 1622 T:0e7b                                    ; clear rockford's final position, and set rockford on end position
 1623 T:0e7b                           rockford_reached_end_position 
 1624 T:0e7b  a0 00                              ldy #0
 1625 T:0e7d  b1 69                              lda (map_rockford_current_position_addr_low),y
 1626 T:0e7f  29 7f                              and #$7f
 1627 T:0e81  aa                                 tax 
 1628 T:0e82  98                                 tya 
 1629 T:0e83  91 69                              sta (map_rockford_current_position_addr_low),y
 1630 T:0e85  8a                                 txa 
 1631 T:0e86  91 6b                              sta (map_rockford_end_position_addr_low),y

 1633 T:0e88  a5 74                              lda cave_number
 1634 T:0e8a  c9 0f                              cmp #15             ; award a life if the end was reached on a bonus cave
 1635 T:0e8c  90 0d                              bcc not_a_bonus_end
 1636 T:0e8e  e6 73                              inc player_lives
 1637 T:0e90  20 e9 0c                           jsr update_player_lives

 1639 T:0e93                                    ;update message bar
 1640 T:0e93  a9 5a                              lda #90
 1641 T:0e95  85 88                              sta saved_message
 1642 T:0e97  a9 27                              lda #$27
 1643 T:0e99  85 89                              sta message_timer

 1645 T:0e9b                           not_a_bonus_end 
 1646 T:0e9b  a5 77                              lda time_remaining
 1647 T:0e9d  f0 1e                              beq skip_bonus
 1648 T:0e9f                           count_up_bonus_at_end_of_stage_loop 
 1649 T:0e9f  a9 42                              lda #66
 1650 T:0ea1  85 8d                              sta play_sound_fx

 1652 T:0ea3                                    ;countdown the remaining time and add to score
 1653 T:0ea3  c6 77                              dec time_remaining
 1654 T:0ea5  20 e0 0c                           jsr update_cave_time

 1656 T:0ea8                                    ;add 1 to score for each time unit left
 1657 T:0ea8  a9 01                              lda #1
 1658 T:0eaa  20 13 0f                           jsr update_score
 1659 T:0ead  20 f2 0c                           jsr update_player_score
 1660 T:0eb0  20 97 0c                           jsr update_status_bar

 1662 T:0eb3  20 d5 09                           jsr set_map_address_to_current_window
 1663 T:0eb6  20 00 09                           jsr draw_grid_of_sprites

 1665 T:0eb9  a5 77                              lda time_remaining
 1666 T:0ebb  d0 e2                              bne count_up_bonus_at_end_of_stage_loop
 1667 T:0ebd                           skip_bonus 

 1669 T:0ebd                                    ;Determine next cave and level to play
 1670 T:0ebd  20 80 0c                           jsr calculate_next_cave_number_and_level
 1671 T:0ec0  a0 ff                              ldy #255

 1673 T:0ec2                           update_during_pause_or_out_of_time 
 1674 T:0ec2  8c cf 0e                           sty save_message_number+1
 1675 T:0ec5  20 ab 0c                           jsr update_status_message

 1677 T:0ec8  20 d5 09                           jsr set_map_address_to_current_window
 1678 T:0ecb  20 00 09                           jsr draw_grid_of_sprites
 1679 T:0ece                           save_message_number 
 1680 T:0ece  a0 00                              ldy #0             ;self-mod, see above
 1681 T:0ed0  4c d4 0e                           jmp check_for_pause_key
 1682 T:0ed3                           gameplay_not_active_return 
 1683 T:0ed3  60                                 rts 

 1685 T:0ed4                                    ; *************************************************************************************
 1686 T:0ed4                           check_for_pause_key 

 1688 T:0ed4  a5 5a                              lda _KeyRowArrows
 1689 T:0ed6  29 04                              and #4
 1690 T:0ed8  60                                 rts 

 1692 T:0ed9                                    ; *************************************************************************************
 1693 T:0ed9                                    ; Apply updates to diamonds required, score, sound etc when a diamond is gathered
 1694 T:0ed9                                    ; Includes check if all diamonds have been gathered and opens the exit
 1695 T:0ed9                           got_diamond_so_update_status_bar 

 1697 T:0ed9  a5 76                              lda diamonds_required
 1698 T:0edb  d0 09                              bne update_diamonds_required_and_check_got_all

 1700 T:0edd                                    ;already got all the diamonds, so just update score with their extra value
 1701 T:0edd  ad 01 26                           lda param_diamond_extra_value
 1702 T:0ee0  20 13 0f                           jsr update_score
 1703 T:0ee3  4c 12 0f                           jmp got_diamond_return

 1705 T:0ee6                           update_diamonds_required_and_check_got_all 

 1707 T:0ee6  ad 00 26                           lda param_diamond_value                ;update score with diamond value
 1708 T:0ee9  20 13 0f                           jsr update_score

 1710 T:0eec  c6 76                              dec diamonds_required             ;subtract 1 from diamonds needed
 1711 T:0eee  d0 22                              bne got_diamond_return

 1713 T:0ef0                                    ; got all the diamonds
 1714 T:0ef0  a9 12                              lda #18
 1715 T:0ef2  85 88                              sta saved_message
 1716 T:0ef4  a9 27                              lda #$27
 1717 T:0ef6  85 89                              sta message_timer

 1719 T:0ef8                                    ; open the exit
 1720 T:0ef8  a0 00                              ldy #0
 1721 T:0efa  a9 18                              lda #24
 1722 T:0efc  91 6b                              sta (map_rockford_end_position_addr_low),y

 1724 T:0efe                                    ; flash path (spaces)
 1725 T:0efe  a9 09                              lda #9
 1726 T:0f00  8d 42 1e                           sta cell_type_to_sprite
 1727 T:0f03  20 d5 09                           jsr set_map_address_to_current_window
 1728 T:0f06  20 00 09                           jsr draw_grid_of_sprites
 1729 T:0f09  a9 00                              lda #0
 1730 T:0f0b  8d 42 1e                           sta cell_type_to_sprite

 1732 T:0f0e  a9 22                              lda #34
 1733 T:0f10  85 8d                              sta play_sound_fx
 1734 T:0f12                           got_diamond_return 
 1735 T:0f12  60                                 rts 

 1737 T:0f13                                    ; *************************************************************************************
 1738 T:0f13                                    ; Updates the score and bonus with accumulator value and performs the bonus life actions
 1739 T:0f13                           update_score 

 1741 T:0f13  18                                 clc 
 1742 T:0f14  65 6f                              adc score_low
 1743 T:0f16  85 6f                              sta score_low
 1744 T:0f18  90 02                              bcc score_skip_high
 1745 T:0f1a  e6 70                              inc score_high
 1746 T:0f1c                           score_skip_high 

 1748 T:0f1c                                    ;Check for bonus every 500 points
 1749 T:0f1c                                    ;Subtract score from previous bonus (which start at zero)
 1750 T:0f1c  38                                 sec 
 1751 T:0f1d  a5 6f                              lda score_low
 1752 T:0f1f  ed 5d 0f                           sbc bonus_low
 1753 T:0f22  8d 5f 0f                           sta result_low
 1754 T:0f25  a5 70                              lda score_high
 1755 T:0f27  ed 5e 0f                           sbc bonus_high
 1756 T:0f2a  8d 60 0f                           sta result_high

 1758 T:0f2d                                    ;Check if the result is over 500 (high byte = 2 or 1 and low byte >= 244)
 1759 T:0f2d  ad 60 0f                           lda result_high
 1760 T:0f30  c9 01                              cmp #1
 1761 T:0f32  90 28                              bcc score_return                ; less than
 1762 T:0f34  d0 07                              bne award_bonus_life                ;greater than
 1763 T:0f36  ad 5f 0f                           lda result_low
 1764 T:0f39  c9 f4                              cmp #244
 1765 T:0f3b  90 1f                              bcc score_return                ; less than

 1767 T:0f3d                                    ;Set the bonus score to the current score for checking next time
 1768 T:0f3d                           award_bonus_life 
 1769 T:0f3d  a5 6f                              lda score_low
 1770 T:0f3f  8d 5d 0f                           sta bonus_low
 1771 T:0f42  a5 70                              lda score_high
 1772 T:0f44  8d 5e 0f                           sta bonus_high
 1773 T:0f47  a9 27                              lda #$27             ;Set the bonus timer to animate the pathway/space sprites
 1774 T:0f49  85 81                              sta bonus_timer
 1775 T:0f4b  e6 73                              inc player_lives
 1776 T:0f4d  20 e9 0c                           jsr update_player_lives

 1778 T:0f50                                    ;play sound
 1779 T:0f50  a9 22                              lda #34             ;same as got_all_diamonds_sound
 1780 T:0f52  85 8d                              sta play_sound_fx

 1782 T:0f54                                    ;update message bar
 1783 T:0f54  a9 5a                              lda #90
 1784 T:0f56  85 88                              sta saved_message
 1785 T:0f58  a9 27                              lda #$27
 1786 T:0f5a  85 89                              sta message_timer

 1788 T:0f5c                           score_return 
 1789 T:0f5c  60                                 rts 

 1791 T:0f5d  00                       bonus_low .byt 0
 1792 T:0f5e  00                       bonus_high .byt 0
 1793 T:0f5f  00                       result_low .byt 0
 1794 T:0f60  00                       result_high .byt 0

 1796 T:0f61                                    ; *************************************************************************************
 1797 T:0f61                           add_a_to_ptr 

 1799 T:0f61  18                                 clc 
 1800 T:0f62  65 64                              adc map_address_low
 1801 T:0f64  85 64                              sta map_address_low
 1802 T:0f66  90 02                              bcc add_ptr_return
 1803 T:0f68  e6 65                              inc map_address_high
 1804 T:0f6a                           add_ptr_return 
 1805 T:0f6a  60                                 rts 

 1807 T:0f6b                                    ; ****************************************************************************************************
 1808 T:0f6b                                    ; Clears the screen (with zero values)
 1809 T:0f6b                           clear_screen 

 1811 T:0f6b                                    ;Clear screen with zero values
 1812 T:0f6b  a9 80                              lda #<$bb80
 1813 T:0f6d  85 62                              sta screen_addr2_low             ;target low
 1814 T:0f6f  a9 bb                              lda #>$bb80
 1815 T:0f71  85 63                              sta screen_addr2_high             ;target high

 1817 T:0f73                                    ;size is 1120 bytes for display (28 lines of 40 columns)
 1818 T:0f73  a9 60                              lda #$60
 1819 T:0f75  8d d5 0f                           sta clear_size
 1820 T:0f78  a9 04                              lda #$04
 1821 T:0f7a  8d d6 0f                           sta clear_size+1

 1823 T:0f7d  a9 00                              lda #0             ;clear to 0
 1824 T:0f7f  4c b0 0f                           jmp clear_memory                ;clear target for given size and value

 1826 T:0f82                                    ; ****************************************************************************************************
 1827 T:0f82                           delay_a_bit 
 1828 T:0f82                           delay1    
 1829 T:0f82  a4 ff                              ldy $ff
 1830 T:0f84                           delay2    
 1831 T:0f84  88                                 dey 
 1832 T:0f85  d0 fd                              bne delay2
 1833 T:0f87  ca                                 dex 
 1834 T:0f88  d0 f8                              bne delay1
 1835 T:0f8a  60                                 rts 

 1837 T:0f8b                                    ; *************************************************************************************
 1838 T:0f8b                                    ; Copy a number of bytes (in copy size variable) from source to target memory locations
 1839 T:0f8b                           copy_memory 

 1841 T:0f8b  a0 00                              ldy #0
 1842 T:0f8d  ae af 0f                           ldx copy_size+1
 1843 T:0f90  f0 0e                              beq copy_remaining_bytes
 1844 T:0f92                           copy_a_page 
 1845 T:0f92  b1 60                              lda (screen_addr1_low),y
 1846 T:0f94  91 62                              sta (screen_addr2_low),y
 1847 T:0f96  c8                                 iny 
 1848 T:0f97  d0 f9                              bne copy_a_page
 1849 T:0f99  e6 61                              inc screen_addr1_high
 1850 T:0f9b  e6 63                              inc screen_addr2_high
 1851 T:0f9d  ca                                 dex 
 1852 T:0f9e  d0 f2                              bne copy_a_page
 1853 T:0fa0                           copy_remaining_bytes 
 1854 T:0fa0  ae ae 0f                           ldx copy_size
 1855 T:0fa3  f0 08                              beq copy_return
 1856 T:0fa5                           copy_a_byte 
 1857 T:0fa5  b1 60                              lda (screen_addr1_low),y
 1858 T:0fa7  91 62                              sta (screen_addr2_low),y
 1859 T:0fa9  c8                                 iny 
 1860 T:0faa  ca                                 dex 
 1861 T:0fab  d0 f8                              bne copy_a_byte

 1863 T:0fad                           copy_return 
 1864 T:0fad  60                                 rts 

 1866 T:0fae                           copy_size 
 1867 T:0fae  00 00                              .byt 0,0

 1869 T:0fb0                                    ; *************************************************************************************
 1870 T:0fb0                                    ; Clear a number of bytes in target memory locations, using clear_size and clear_to_byte
 1871 T:0fb0                           clear_memory 

 1873 T:0fb0  8d cd 0f                           sta clear_to_byte+1          ;accumulator parameter

 1875 T:0fb3  a0 00                              ldy #0
 1876 T:0fb5  ae d6 0f                           ldx clear_size+1
 1877 T:0fb8  f0 0d                              beq clear_remaining_bytes
 1878 T:0fba                           clear_a_page 
 1879 T:0fba  ad cd 0f                           lda clear_to_byte+1
 1880 T:0fbd  91 62                              sta (screen_addr2_low),y
 1881 T:0fbf  c8                                 iny 
 1882 T:0fc0  d0 f8                              bne clear_a_page
 1883 T:0fc2  e6 63                              inc screen_addr2_high
 1884 T:0fc4  ca                                 dex 
 1885 T:0fc5  d0 f3                              bne clear_a_page
 1886 T:0fc7                           clear_remaining_bytes 
 1887 T:0fc7  ae d5 0f                           ldx clear_size
 1888 T:0fca  f0 08                              beq clear_return
 1889 T:0fcc                           clear_to_byte 
 1890 T:0fcc  a9 00                              lda #0             ;self-mod, see above
 1891 T:0fce  91 62                              sta (screen_addr2_low),y
 1892 T:0fd0  c8                                 iny 
 1893 T:0fd1  ca                                 dex 
 1894 T:0fd2  d0 f8                              bne clear_to_byte

 1896 T:0fd4                           clear_return 
 1897 T:0fd4  60                                 rts 

 1899 T:0fd5                           clear_size 
 1900 T:0fd5  00 00                              .byt 0,0

 1902 T:0fd7                                    ; *************************************************************************************
 1903 T:0fd7                                    ; Cave tile map
 1904 T:0fd7                                    ; Below is needed to point the program counter to the next page (multiple of 256)
 1905 T:0fd7                                    ; IMPORTANT: Address must be $1000, $2000 etc, not $1100 for example!
 1906 T:0fd7                                    ; Each row has 40 bytes used for the tiles in the game, 24 unused
 1907 T:0fd7  00 ff 00 01 00 64 02 ...           .dsb 256-(*&255)    ;Add another page of bytes

 1909 T:1000                           tile_map_row_0                  ;top border
 1910 T:1000  00 ff 40 00 00 64 fc ...           .dsb 64
 1911 T:1040                           tile_map_row_1                  ;1-20 rows between the borders
 1912 T:1040  00 28 ff 40 00 00 64 ...           .dsb (64*19)
 1913 T:1500                           tile_map_row_20 
 1914 T:1500  00 ff 40 00 00 64 fc ...           .dsb 64
 1915 T:1540                           tile_map_row_21                  ;bottom border
 1916 T:1540  00 ff 40 00 00 64 fc ...           .dsb 64
 1917 T:1580                           tile_below_store_row                  ;special row for pseudo-random generated caves with extra-tile below the random one
 1918 T:1580  00 ff 40 00 00 64 fc ...           .dsb 64

 1920 T:15c0                                    ; *************************************************************************************
 1921 T:15c0                                    ; Update the gameplay map with action handlers for each of the game actors
 1922 T:15c0                                    ; Includes logic for falling rocks, diamonds, bombs
 1923 T:15c0                           update_map 

 1925 T:15c0  a9 14                              lda #20             ; twenty rows
 1926 T:15c2  85 67                              sta map_rows
 1927 T:15c4  a9 10                              lda #>tile_map_row_0
 1928 T:15c6  85 65                              sta map_address_high
 1929 T:15c8  a9 00                              lda #<tile_map_row_0
 1930 T:15ca  85 64                              sta map_address_low
 1931 T:15cc                                    ; Each row is stored in the first 40 bytes of every 64 bytes. Here we set Y to
 1932 T:15cc                                    ; start on the second row, after the titanium wall border
 1933 T:15cc  a0 40                              ldy #$40
 1934 T:15ce                                    ; loop through the twenty rows of map
 1935 T:15ce                           tile_map_y_loop 
 1936 T:15ce  a9 26                              lda #38             ; 38 columns (cells per row)
 1937 T:15d0  85 68                              sta map_cols
 1938 T:15d2  b1 64                              lda (map_address_low),y
 1939 T:15d4  85 53                              sta cell_left
 1940 T:15d6                                    ; move to the next cell
 1941 T:15d6  c8                                 iny 
 1942 T:15d7                                    ; read current cell contents into X
 1943 T:15d7  b1 64                              lda (map_address_low),y
 1944 T:15d9  aa                                 tax 
 1945 T:15da                                    ; loop through the 38 cells in a row of map
 1946 T:15da                                    ; read next cell contents into cell_right
 1947 T:15da                           tile_map_x_loop 
 1948 T:15da  a0 42                              ldy #$42
 1949 T:15dc  b1 64                              lda (map_address_low),y
 1950 T:15de  85 55                              sta cell_right
 1951 T:15e0                                    ;Below checks if space, earth, wall, steel wall and just marks as processed, no handlers needed
 1952 T:15e0  e0 04                              cpx #4
 1953 T:15e2  30 34                              bmi mark_cell_above_as_processed_and_move_to_next_cell

 1955 T:15e4                                    ; read cells into cell_above and cell_below variables
 1956 T:15e4  a0 01                              ldy #1
 1957 T:15e6  b1 64                              lda (map_address_low),y
 1958 T:15e8  85 51                              sta cell_above
 1959 T:15ea  a0 81                              ldy #$81
 1960 T:15ec  b1 64                              lda (map_address_low),y
 1961 T:15ee  85 57                              sta cell_below

 1963 T:15f0                                    ; if current cell is already processed (top bit set), then skip to next cell
 1964 T:15f0  8a                                 txa 
 1965 T:15f1  30 25                              bmi mark_cell_above_as_processed_and_move_to_next_cell
 1966 T:15f3                                    ; mark current cell as processed (set top bit)
 1967 T:15f3  09 80                              ora #$80
 1968 T:15f5  aa                                 tax 
 1969 T:15f6                                    ; the lower four bits are the type, each of which has a handler to process it
 1970 T:15f6  29 0f                              and #$0f
 1971 T:15f8  a8                                 tay 
 1972 T:15f9  b9 32 1e                           lda handler_table_high,y
 1973 T:15fc                                    ; if we have no handler for this cell type then branch (destination was set
 1974 T:15fc                                    ; depending on where we entered this routine)
 1975 T:15fc  f0 53                              beq update_rock_or_diamond_that_can_fall
 1976 T:15fe  8d 09 16                           sta handler_high
 1977 T:1601  b9 22 1e                           lda handler_table_low,y
 1978 T:1604  8d 08 16                           sta handler_low
 1979 T:1607                                    ; call the handler for the cell based on the type (0-15)
 1980 T:1607                           jsr_handler_instruction 
 1981 T:1607                                    handler_low=jsr_handler_instruction+1
 1982 T:1607                                    handler_high=jsr_handler_instruction+2
 1983 T:1607  20 d2 16                           jsr handler_rockford

 1985 T:160a                                    ; the handler may have changed the surrounding cells, store the new cell below
 1986 T:160a  a5 57                              lda cell_below
 1987 T:160c  a0 81                              ldy #$81
 1988 T:160e  91 64                              sta (map_address_low),y
 1989 T:1610                                    ; store the new cell above
 1990 T:1610  a5 51                              lda cell_above
 1991 T:1612  29 7f                              and #$7f
 1992 T:1614  a0 01                              ldy #1
 1993 T:1616  10 06                              bpl move_to_next_cell                ; ALWAYS branch

 1995 T:1618                                    ; *************************************************************************************
 1996 T:1618                           mark_cell_above_as_processed_and_move_to_next_cell 

 1998 T:1618  a0 01                              ldy #1
 1999 T:161a  b1 64                              lda (map_address_low),y
 2000 T:161c  29 7f                              and #$7f
 2001 T:161e                           move_to_next_cell 
 2002 T:161e  91 64                              sta (map_address_low),y
 2003 T:1620                                    ; store the new cell left back into the map
 2004 T:1620  a5 53                              lda cell_left
 2005 T:1622  a0 40                              ldy #$40
 2006 T:1624  91 64                              sta (map_address_low),y
 2007 T:1626                                    ; update cell_left with the current cell value (in X)
 2008 T:1626  86 53                              stx cell_left
 2009 T:1628                                    ; update the current cell value x from the cell_right variable
 2010 T:1628  a6 55                              ldx cell_right
 2011 T:162a                                    ; move ptr to next position
 2012 T:162a  e6 64                              inc map_address_low
 2013 T:162c                                    ; loop back for the rest of the cells in the row
 2014 T:162c  c6 68                              dec map_cols
 2015 T:162e  d0 aa                              bne tile_map_x_loop
 2016 T:1630                                    ; store the final previous_cell for the row
 2017 T:1630  a5 53                              lda cell_left
 2018 T:1632  91 64                              sta (map_address_low),y
 2019 T:1634                                    ; move ptr to the start of the next row. Stride is 64, 38 entries done, so
 2020 T:1634                                    ; remainder to add is 64-38=26
 2021 T:1634  a9 1a                              lda #26
 2022 T:1636  20 61 0f                           jsr add_a_to_ptr
 2023 T:1639                                    ; loop back for the rest of the rows
 2024 T:1639  c6 67                              dec map_rows
 2025 T:163b  d0 91                              bne tile_map_y_loop
 2026 T:163d                                    ; clear top bit in final row
 2027 T:163d  a0 26                              ldy #38
 2028 T:163f                           clear_top_bit_on_final_row_loop 
 2029 T:163f  b9 00 15                           lda tile_map_row_20,y
 2030 T:1642  29 7f                              and #$7f
 2031 T:1644  99 00 15                           sta tile_map_row_20,y
 2032 T:1647  88                                 dey 
 2033 T:1648  d0 f5                              bne clear_top_bit_on_final_row_loop
 2034 T:164a                                    ; clear top bit on end position
 2035 T:164a  b1 6b                              lda (map_rockford_end_position_addr_low),y
 2036 T:164c  29 7f                              and #$7f
 2037 T:164e  91 6b                              sta (map_rockford_end_position_addr_low),y
 2038 T:1650  60                                 rts 

 2040 T:1651                                    ; *************************************************************************************
 2041 T:1651                                    ; Update for rock/diamond/bomb elements
 2042 T:1651                           update_rock_or_diamond_that_can_fall 

 2044 T:1651  c0 0b                              cpy #11
 2045 T:1653  d0 03                              bne not_a_bomb
 2046 T:1655  20 94 19                           jsr handler_bomb                ;handle the bomb timer before continuing so it behaves like a rock/diamond
 2047 T:1658                           not_a_bomb 
 2048 T:1658  a5 7a                              lda gravity_timer
 2049 T:165a  f0 11                              beq gravity_on_as_normal
 2050 T:165c                                    ;gravity is off, so a rock/diamond/bomb can float
 2051 T:165c  c0 05                              cpy #5
 2052 T:165e  d0 b8                              bne mark_cell_above_as_processed_and_move_to_next_cell             ;only want to transition the rock
 2053 T:1660  a2 95                              ldx #5|128|16 ;switch to a bubble sprite
 2054 T:1662  a5 7a                              lda gravity_timer
 2055 T:1664  c9 04                              cmp #4
 2056 T:1666  b0 b0                              bcs mark_cell_above_as_processed_and_move_to_next_cell
 2057 T:1668  a2 a5                              ldx #5|128|32 ;switch to a bubble-transition-to-rock sprite instead
 2058 T:166a  4c 18 16                           jmp mark_cell_above_as_processed_and_move_to_next_cell             ;bypass rock/diamond/bomb falling when gravity is off
 2059 T:166d                           gravity_on_as_normal 
 2060 T:166d  e0 a5                              cpx #5|128|32
 2061 T:166f  d0 02                              bne not_a_rock
 2062 T:1671  a2 85                              ldx #5|128       ;switch back to rock
 2063 T:1673                           not_a_rock 
 2064 T:1673  a0 81                              ldy #$81
 2065 T:1675  b1 64                              lda (map_address_low),y
 2066 T:1677  f0 2f                              beq cell_below_is_a_space
 2067 T:1679                                    ; check current cell
 2068 T:1679  e0 c0                              cpx #192
 2069 T:167b  30 03                              bmi not_c0_or_above
 2070 T:167d  20 af 16                           jsr process_c0_or_above
 2071 T:1680                           not_c0_or_above 
 2072 T:1680  29 4f                              and #$4f
 2073 T:1682  a8                                 tay 
 2074 T:1683  0a                                 asl 
 2075 T:1684  30 49                              bmi process_next_cell
 2076 T:1686  b9 ad 1f                           lda cell_types_that_rocks_or_diamonds_will_fall_off,y
 2077 T:1689  f0 44                              beq process_next_cell
 2078 T:168b  a5 53                              lda cell_left
 2079 T:168d  d0 06                              bne check_if_cell_right_is_empty
 2080 T:168f                                    ; cell left is empty, now check below left cell
 2081 T:168f  a0 80                              ldy #$80
 2082 T:1691  b1 64                              lda (map_address_low),y
 2083 T:1693  f0 0a                              beq rock_or_diamond_can_fall_left_or_right
 2084 T:1695                           check_if_cell_right_is_empty 
 2085 T:1695  a5 55                              lda cell_right
 2086 T:1697  d0 36                              bne process_next_cell
 2087 T:1699                                    ; cell right is empty, now check below right cell
 2088 T:1699  a0 82                              ldy #$82
 2089 T:169b  b1 64                              lda (map_address_low),y
 2090 T:169d  d0 30                              bne process_next_cell
 2091 T:169f                                    ; take the rock or diamond, and set bit 6 to indicate it has been moved this scan
 2092 T:169f                                    ; (so it won't be moved again). Then store it in the below left or below right cell
 2093 T:169f                           rock_or_diamond_can_fall_left_or_right 
 2094 T:169f  8a                                 txa 
 2095 T:16a0  09 40                              ora #$40
 2096 T:16a2  91 64                              sta (map_address_low),y
 2097 T:16a4                           set_to_unprocessed_space 
 2098 T:16a4  a2 80                              ldx #$80
 2099 T:16a6  d0 27                              bne process_next_cell                ; ALWAYS branch

 2101 T:16a8                                    ; take the rock or diamond, and set bit 6 to indicate it has been moved this scan
 2102 T:16a8                                    ; (so it won't be moved again). Then store it in the cell below.
 2103 T:16a8                           cell_below_is_a_space 
 2104 T:16a8  8a                                 txa 
 2105 T:16a9  09 40                              ora #$40
 2106 T:16ab  91 64                              sta (map_address_low),y
 2107 T:16ad  d0 f5                              bne set_to_unprocessed_space             ; ALWAYS branch

 2109 T:16af                           process_c0_or_above 
 2110 T:16af  48                                 pha 
 2111 T:16b0                                    ; look up table based on type
 2112 T:16b0  29 0f                              and #$0f
 2113 T:16b2  a8                                 tay 
 2114 T:16b3  b9 bd 1f                           lda update_cell_type_when_below_a_falling_rock_or_diamond,y
 2115 T:16b6  f0 04                              beq play_rock_or_diamond_fall_sound
 2116 T:16b8                                    ; store in cell below
 2117 T:16b8  a0 81                              ldy #$81
 2118 T:16ba  91 64                              sta (map_address_low),y
 2119 T:16bc                           play_rock_or_diamond_fall_sound 

 2121 T:16bc  a0 52                              ldy #82
 2122 T:16be  8a                                 txa 
 2123 T:16bf  29 0f                              and #$0f
 2124 T:16c1  c9 04                              cmp #4
 2125 T:16c3  d0 02                              bne save_rock_or_diamond_fall_sound
 2126 T:16c5  a0 62                              ldy #98
 2127 T:16c7                           save_rock_or_diamond_fall_sound 
 2128 T:16c7  84 8d                              sty play_sound_fx

 2130 T:16c9                                    ; mask off bit 6 for the current cell value
 2131 T:16c9  8a                                 txa 
 2132 T:16ca  29 bf                              and #$bf
 2133 T:16cc  aa                                 tax 
 2134 T:16cd  68                                 pla 
 2135 T:16ce  60                                 rts 

 2137 T:16cf                                    ;Needed because subroutine is out of range to branch to
 2138 T:16cf                           process_next_cell 
 2139 T:16cf  4c 18 16                           jmp mark_cell_above_as_processed_and_move_to_next_cell

 2141 T:16d2                                    ; *************************************************************************************
 2142 T:16d2                                    ; Handler for Rockford's actions - moving, pushing rocks, etc
 2143 T:16d2                           handler_rockford 

 2145 T:16d2  86 83                              stx current_rockford_sprite
 2146 T:16d4  a5 84                              lda rockford_explosion_cell_type
 2147 T:16d6  d0 03                              bne start_large_explosion
 2148 T:16d8  e8                                 inx 
 2149 T:16d9  d0 05                              bne check_for_direction_key_pressed
 2150 T:16db                           start_large_explosion 
 2151 T:16db  a2 46                              ldx #70
 2152 T:16dd  86 84                              stx rockford_explosion_cell_type
 2153 T:16df  60                                 rts 

 2155 T:16e0                           check_for_direction_key_pressed 
 2156 T:16e0  a5 5a                              lda _KeyRowArrows
 2157 T:16e2  85 71                              sta temp1
 2158 T:16e4  29 e8                              and #(8|64|32|128)
 2159 T:16e6  d0 10                              bne direction_key_pressed
 2160 T:16e8                                    ; player is not moving in any direction
 2161 T:16e8  a2 0f                              ldx #15
 2162 T:16ea                           update_player_at_current_location 
 2163 T:16ea  a9 41                              lda #$41
 2164 T:16ec                           play_movement_sound_and_update_current_position_address 
 2165 T:16ec  18                                 clc 
 2166 T:16ed  65 64                              adc map_address_low
 2167 T:16ef  85 69                              sta map_rockford_current_position_addr_low
 2168 T:16f1  a5 65                              lda map_address_high
 2169 T:16f3  69 00                              adc #0
 2170 T:16f5  85 6a                              sta map_rockford_current_position_addr_high
 2171 T:16f7  60                                 rts 

 2173 T:16f8                           direction_key_pressed 
 2174 T:16f8  a2 00                              ldx #0
 2175 T:16fa  86 8c                              stx ticks_since_last_direction_key_pressed
 2176 T:16fc  ca                                 dex 
 2177 T:16fd                           get_direction_index_loop 
 2178 T:16fd  e8                                 inx 
 2179 T:16fe  a5 71                              lda temp1
 2180 T:1700  3d cc 17                           and direction_key_table,x
 2181 T:1703  f0 f8                              beq get_direction_index_loop
 2182 T:1705  bd 44 20                           lda rockford_cell_value_for_direction,x
 2183 T:1708  f0 02                              beq skip_storing_rockford_cell_type
 2184 T:170a  85 82                              sta rockford_cell_value
 2185 T:170c                           skip_storing_rockford_cell_type 
 2186 T:170c  bc 4c 20                           ldy neighbour_cell_pointer_from_direction_index,x
 2187 T:170f  84 59                              sty neighbour_cell_pointer
 2188 T:1711  b9 50 00                           lda neighbour_cell_directions,y
 2189 T:1714  85 86                              sta neighbour_cell_contents
 2190 T:1716  29 0f                              and #$0f
 2191 T:1718  a8                                 tay 
 2192 T:1719                                    ; branch if movement is not possible
 2193 T:1719  b9 9d 1f                           lda obstacle_control,y
 2194 T:171c  f0 3b                              beq check_if_value_is_empty
 2195 T:171e                                    ; branch if movement is freely possible
 2196 T:171e  30 23                              bmi check_for_return_pressed
 2197 T:1720                                    ; trying to move into something difficult to move (e.g. a rock)
 2198 T:1720  bc 40 20                           ldy rock_push_directions,x
 2199 T:1723  f0 34                              beq check_if_value_is_empty
 2200 T:1725  c0 ee                              cpy #$ee             ;Special value used to detect rock has been pushed up
 2201 T:1727  f0 43                              beq check_push_up
 2202 T:1729  b1 64                              lda (map_address_low),y
 2203 T:172b  d0 2c                              bne check_if_value_is_empty
 2204 T:172d  a5 86                              lda neighbour_cell_contents
 2205 T:172f                                    ; don't try pushing a rock that's just fallen this tick (bit 6 set)
 2206 T:172f  c9 45                              cmp #$45
 2207 T:1731  f0 26                              beq check_if_value_is_empty
 2208 T:1733  c6 87                              dec delay_trying_to_push_rock
 2209 T:1735  d0 22                              bne check_if_value_is_empty
 2210 T:1737  09 80                              ora #$80
 2211 T:1739  91 64                              sta (map_address_low),y
 2212 T:173b  a9 04                              lda #4
 2213 T:173d  85 87                              sta delay_trying_to_push_rock
 2214 T:173f  a9 52                              lda #82
 2215 T:1741  85 8d                              sta play_sound_fx
 2216 T:1743                           check_for_return_pressed 
 2217 T:1743  a5 8d                              lda play_sound_fx
 2218 T:1745  d0 04                              bne keep_current_sound2                ;don't override a sound effect with Rockford default movement sound
 2219 T:1747  a9 02                              lda #2
 2220 T:1749  85 8d                              sta play_sound_fx
 2221 T:174b                           keep_current_sound2 

 2223 T:174b  a5 5a                              lda _KeyRowArrows
 2224 T:174d  29 01                              and #1
 2225 T:174f  f0 0c                              beq store_rockford_cell_value_without_return_pressed
 2226 T:1751                                    ; return and direction is pressed. clear the appropriate cell
 2227 T:1751  20 a1 17                           jsr check_if_bombs_used                ;Returns accumulator used below
 2228 T:1754  a4 59                              ldy neighbour_cell_pointer
 2229 T:1756  99 50 00                           sta neighbour_cell_directions,y

 2231 T:1759                           check_if_value_is_empty 
 2232 T:1759  a6 82                              ldx rockford_cell_value
 2233 T:175b  d0 8d                              bne update_player_at_current_location
 2234 T:175d                           store_rockford_cell_value_without_return_pressed 
 2235 T:175d  a5 82                              lda rockford_cell_value
 2236 T:175f  a4 59                              ldy neighbour_cell_pointer
 2237 T:1761  99 50 00                           sta neighbour_cell_directions,y
 2238 T:1764  bd 48 20                           lda map_offset_for_direction,x
 2239 T:1767  a2 80                              ldx #$80
 2240 T:1769  4c ec 16                           jmp play_movement_sound_and_update_current_position_address

 2242 T:176c                                    ;Subroutine to allow Rockford to push a rock upwards
 2243 T:176c                                    ;Needs to check there is a free space above the rock being pushed, allow for the push delay, then continue like other direction pushes
 2244 T:176c                           check_push_up 
 2245 T:176c  a5 65                              lda map_address_high             ;store current line pointer high/low on stack
 2246 T:176e  48                                 pha 
 2247 T:176f  a5 64                              lda map_address_low
 2248 T:1771  48                                 pha 
 2249 T:1772  38                                 sec 
 2250 T:1773  a5 64                              lda map_address_low
 2251 T:1775  e9 80                              sbc #$80             ;Need to point upwards 2 lines, so subtract (64 x 2 = 128) from pointer high/low
 2252 T:1777  85 64                              sta map_address_low
 2253 T:1779  b0 02                              bcs no_up_ptr_high_change
 2254 T:177b  c6 65                              dec map_address_high
 2255 T:177d                           no_up_ptr_high_change 
 2256 T:177d  a0 41                              ldy #$41             ;offset the line pointer with Rockford's position
 2257 T:177f  b1 64                              lda (map_address_low),y         ;this is the cell value 2 rows above Rockford
 2258 T:1781  d0 15                              bne end_check_up
 2259 T:1783  c6 87                              dec delay_trying_to_push_rock             ;ok to push up but delay
 2260 T:1785  d0 11                              bne end_check_up
 2261 T:1787  a9 15                              lda #5|16       ;delay over, store a rock in the cell 2 rows above Rockford
 2262 T:1789  91 64                              sta (map_address_low),y
 2263 T:178b  a9 04                              lda #4             ;reset the delay for next time
 2264 T:178d  85 87                              sta delay_trying_to_push_rock
 2265 T:178f  68                                 pla                    ;restore current line pointer high/low from stack
 2266 T:1790  85 64                              sta map_address_low
 2267 T:1792  68                                 pla 
 2268 T:1793  85 65                              sta map_address_high
 2269 T:1795  4c 5d 17                           jmp store_rockford_cell_value_without_return_pressed             ;continue like side/bottom pushes
 2270 T:1798                           end_check_up 
 2271 T:1798  68                                 pla                    ;restore current line pointer high/low from stack
 2272 T:1799  85 64                              sta map_address_low
 2273 T:179b  68                                 pla 
 2274 T:179c  85 65                              sta map_address_high
 2275 T:179e  4c 59 17                           jmp check_if_value_is_empty             ;continue like side/bottom non-pushes

 2277 T:17a1                                    ;Subroutine called when pressing fire + direction keys
 2278 T:17a1                                    ;if bombs are allowed, place a bomb in the space of the direction, otherwise just clear the space given by the direction
 2279 T:17a1                           check_if_bombs_used 
 2280 T:17a1  a5 78                              lda bomb_counter
 2281 T:17a3  d0 03                              bne bombs_allowed
 2282 T:17a5  a9 00                              lda #0
 2283 T:17a7  60                                 rts 

 2285 T:17a8                           bombs_allowed 
 2286 T:17a8  a5 86                              lda neighbour_cell_contents
 2287 T:17aa  f0 03                              beq check_bomb_delay
 2288 T:17ac  a9 00                              lda #0
 2289 T:17ae  60                                 rts 

 2291 T:17af                           check_bomb_delay 
 2292 T:17af  a5 79                              lda bomb_delay
 2293 T:17b1  f0 03                              beq create_a_bomb
 2294 T:17b3  a9 00                              lda #0
 2295 T:17b5  60                                 rts 

 2297 T:17b6                           create_a_bomb 
 2298 T:17b6  a9 03                              lda #3             ;delay creation of next bomb
 2299 T:17b8  85 79                              sta bomb_delay
 2300 T:17ba  c6 78                              dec bomb_counter             ;one less bomb to use
 2301 T:17bc  d0 08                              bne skip_no_bombs_message
 2302 T:17be  a9 24                              lda #36
 2303 T:17c0  85 88                              sta saved_message
 2304 T:17c2  a9 27                              lda #$27
 2305 T:17c4  85 89                              sta message_timer
 2306 T:17c6                           skip_no_bombs_message 
 2307 T:17c6                                    ;update bombs available on status bar
 2308 T:17c6  20 d1 0c                           jsr update_bombs_available
 2309 T:17c9  a9 0b                              lda #11
 2310 T:17cb  60                                 rts 

 2312 T:17cc                           direction_key_table 
 2313 T:17cc  80                                 .byt 128              ;right arrow (right)
 2314 T:17cd  20                                 .byt 32              ;left arrow (left)
 2315 T:17ce  08                                 .byt 8              ;up arrow (up)
 2316 T:17cf  40                                 .byt 64              ;down arrow (down)

 2318 T:17d0                                    ; *************************************************************************************
 2319 T:17d0                                    ; Handler for Rockford entry, converstion of amoeba into diamonds
 2320 T:17d0                                    ; Called once handler_rockford_intro_or_exit sets the last transition to $21 (x is an explosion sprite)
 2321 T:17d0                                    ; $21 becomes unprocessed (ora #$80) and subtracted from #$90 = $11 so not processed initially but X is set to $11, set in update_map
 2322 T:17d0                                    ; $11 becomes unprocessed (ora #$80) and subtracted from #$90 = $1 and using explosion_replacements table, becomes unprocessed Rockford
 2323 T:17d0                           handler_basics 

 2325 T:17d0  8a                                 txa 
 2326 T:17d1  38                                 sec 
 2327 T:17d2  e9 90                              sbc #$90
 2328 T:17d4  c9 10                              cmp #$10
 2329 T:17d6  10 04                              bpl not_in_range_so_change_nothing
 2330 T:17d8                                    ; cell is in the range $90-$9f (corresponding to $10 to $1f with the top bit set),
 2331 T:17d8                                    ; so we look up the replacement in a table. This is used to replace the final step
 2332 T:17d8                                    ; of an explosion, either with rockford during the introduction (offset $01), or a
 2333 T:17d8                                    ; space for the outro (death) explosion (offset $03)
 2334 T:17d8  aa                                 tax 
 2335 T:17d9  bd 99 1f                           lda explosion_replacements,x
 2336 T:17dc                           not_in_range_so_change_nothing 
 2337 T:17dc  aa                                 tax 
 2338 T:17dd  60                                 rts 

 2340 T:17de                                    ; *************************************************************************************
 2341 T:17de                                    ; Handler for Rockford's intro/exit
 2342 T:17de                           handler_rockford_intro_or_exit 

 2344 T:17de  8a                                 txa 
 2345 T:17df  29 7f                              and #$7f
 2346 T:17e1  aa                                 tax 
 2347 T:17e2                                    ; branch if on exit
 2348 T:17e2  e0 18                              cpx #24
 2349 T:17e4  f0 0c                              beq intro_or_exit_return
 2350 T:17e6                                    ; we have found the intro square
 2351 T:17e6                                    ; wait for flashing rockford animation to finish
 2352 T:17e6  a5 8a                              lda tick_counter
 2353 T:17e8  c9 f0                              cmp #$f0
 2354 T:17ea  10 06                              bpl intro_or_exit_return
 2355 T:17ec                                    ; start the explosion just before gameplay starts (x is an explosion sprite)
 2356 T:17ec  a2 21                              ldx #$21
 2357 T:17ee  a9 32                              lda #50
 2358 T:17f0  85 8d                              sta play_sound_fx

 2360 T:17f2                           intro_or_exit_return 
 2361 T:17f2  60                                 rts 

 2363 T:17f3                                    ; *************************************************************************************
 2364 T:17f3                                    ; Handler for Firefly/Butterfly actions, moving, exploding etc
 2365 T:17f3                                    ; Below is needed to point the program counter to the next page (multiple of 256)
 2366 T:17f3                           handler_firefly_or_butterfly 

 2368 T:17f3  e0 c0                              cpx #192
 2369 T:17f5  10 3c                              bpl show_large_explosion
 2370 T:17f7                                    ; check directions in order: cell_below, cell_right, cell_left, cell_up
 2371 T:17f7  a0 08                              ldy #8
 2372 T:17f9                           look_for_amoeba_or_player_loop 
 2373 T:17f9  b9 4f 00                           lda neighbour_cell_directions-1,y
 2374 T:17fc  29 07                              and #7
 2375 T:17fe  49 07                              eor #7
 2376 T:1800  f0 31                              beq show_large_explosion
 2377 T:1802  88                                 dey 
 2378 T:1803  88                                 dey 
 2379 T:1804  d0 f3                              bne look_for_amoeba_or_player_loop
 2380 T:1806                                    ; calculate direction to move in Y
 2381 T:1806  8a                                 txa 
 2382 T:1807  4a                                 lsr 
 2383 T:1808  4a                                 lsr 
 2384 T:1809  4a                                 lsr 
 2385 T:180a  29 07                              and #7
 2386 T:180c  a8                                 tay 
 2387 T:180d                                    ; branch if the desired direction is empty
 2388 T:180d  be 50 20                           ldx firefly_neighbour_pointers,y
 2389 T:1810  b5 50                              lda neighbour_cell_directions,x
 2390 T:1812  f0 11                              beq set_firefly_or_butterfly
 2391 T:1814                                    ; get the next direction in Y
 2392 T:1814  b9 58 20                           lda firefly_and_butterfly_next_direction_table,y
 2393 T:1817  a8                                 tay 
 2394 T:1818                                    ; branch if the second desired direction is empty
 2395 T:1818  be 50 20                           ldx firefly_neighbour_pointers,y
 2396 T:181b  b5 50                              lda neighbour_cell_directions,x
 2397 T:181d  f0 06                              beq set_firefly_or_butterfly
 2398 T:181f                                    ; set X=0 to force the use of the final possible direction
 2399 T:181f  a2 00                              ldx #0
 2400 T:1821                                    ; get the last cardinal direction that isn't a u-turn
 2401 T:1821  b9 58 20                           lda firefly_and_butterfly_next_direction_table,y
 2402 T:1824  a8                                 tay 
 2403 T:1825                           set_firefly_or_butterfly 
 2404 T:1825  b9 51 1f                           lda firefly_and_butterfly_cell_values,y
 2405 T:1828  e0 00                              cpx #0
 2406 T:182a  d0 02                              bne store_firefly_and_clear_current_cell
 2407 T:182c  aa                                 tax 
 2408 T:182d  60                                 rts 

 2410 T:182e                           store_firefly_and_clear_current_cell 
 2411 T:182e  95 50                              sta neighbour_cell_directions,x
 2412 T:1830  a2 00                              ldx #0
 2413 T:1832  60                                 rts 

 2415 T:1833                                    ; *************************************************************************************
 2416 T:1833                                    ; Handles the large explosion affecting 9 cells which turn into spaces or diamonds
 2417 T:1833                           show_large_explosion 

 2419 T:1833  8a                                 txa 
 2420 T:1834  a2 00                              ldx #<cell_types_that_will_turn_into_large_explosion
 2421 T:1836  29 08                              and #8
 2422 T:1838  f0 02                              beq set_explosion_type
 2423 T:183a  a2 10                              ldx #<cell_types_that_will_turn_into_diamonds
 2424 T:183c                           set_explosion_type 
 2425 T:183c  8e 65 18                           stx lookup_table_address_low
 2426 T:183f                                    ; activate explosion sound
 2427 T:183f  a9 72                              lda #114
 2428 T:1841  85 8d                              sta play_sound_fx
 2429 T:1843                                    ; read above left cell
 2430 T:1843  a0 00                              ldy #0
 2431 T:1845  b1 64                              lda (map_address_low),y
 2432 T:1847  85 50                              sta cell_above_left
 2433 T:1849                                    ; reset current cell to zero
 2434 T:1849  84 54                              sty cell_current
 2435 T:184b                                    ; read above right cell
 2436 T:184b  a0 02                              ldy #2
 2437 T:184d  b1 64                              lda (map_address_low),y
 2438 T:184f  85 52                              sta cell_above_right
 2439 T:1851                                    ; read below left cell
 2440 T:1851  a0 80                              ldy #$80
 2441 T:1853  b1 64                              lda (map_address_low),y
 2442 T:1855  85 56                              sta cell_below_left
 2443 T:1857                                    ; read below right cell
 2444 T:1857  a0 82                              ldy #$82
 2445 T:1859  b1 64                              lda (map_address_low),y
 2446 T:185b  85 58                              sta cell_below_right
 2447 T:185d                                    ; loop 9 times to replace all the neighbour cells with diamonds or large explosion
 2448 T:185d  a2 09                              ldx #9
 2449 T:185f                           replace_neighbours_loop 
 2450 T:185f  b5 4f                              lda neighbour_cell_directions-1,x
 2451 T:1861  29 0f                              and #$0f
 2452 T:1863  a8                                 tay 
 2453 T:1864                           read_from_table_instruction 
 2454 T:1864                                    lookup_table_address_low=read_from_table_instruction+1
 2455 T:1864  b9 00 20                           lda cell_types_that_will_turn_into_large_explosion,y
 2456 T:1867  f0 02                              beq skip_storing_explosion_into_cell
 2457 T:1869  95 4f                              sta neighbour_cell_directions-1,x
 2458 T:186b                           skip_storing_explosion_into_cell 
 2459 T:186b  ca                                 dex 
 2460 T:186c  d0 f1                              bne replace_neighbours_loop
 2461 T:186e                                    ; write new values back into the corner cells
 2462 T:186e                                    ; write to above left cell
 2463 T:186e  a0 00                              ldy #0
 2464 T:1870  a5 50                              lda cell_above_left
 2465 T:1872  29 7f                              and #$7f
 2466 T:1874  91 64                              sta (map_address_low),y
 2467 T:1876                                    ; write to above right cell
 2468 T:1876  a0 02                              ldy #2
 2469 T:1878  a5 52                              lda cell_above_right
 2470 T:187a  91 64                              sta (map_address_low),y
 2471 T:187c                                    ; write to below left cell
 2472 T:187c  a0 80                              ldy #$80
 2473 T:187e  a5 56                              lda cell_below_left
 2474 T:1880  91 64                              sta (map_address_low),y
 2475 T:1882                                    ; write to below right cell
 2476 T:1882  a0 82                              ldy #$82
 2477 T:1884  a5 58                              lda cell_below_right
 2478 T:1886  91 64                              sta (map_address_low),y
 2479 T:1888  a6 54                              ldx cell_current
 2480 T:188a  60                                 rts 

 2482 T:188b                                    ; *************************************************************************************
 2483 T:188b                                    ; Handler for growing wall which allows a wall to extend horizontally if the item beside it is empty space
 2484 T:188b                           handler_growing_wall 

 2486 T:188b  a5 53                              lda cell_left             ; read cell to the left of the growing wall
 2487 T:188d  29 0f                              and #$0f             ; getting the cell type from the lower nybble
 2488 T:188f  d0 08                              bne check_grow_right                ; If not zero (map_space) then examine cell to the right
 2489 T:1891  a9 8c                              lda #128|12       ; Otherwise replace the left cell with another growing wall
 2490 T:1893  85 53                              sta cell_left
 2491 T:1895  a9 82                              lda #130             ;same as amoeba_sound
 2492 T:1897  85 8d                              sta play_sound_fx
 2493 T:1899                           check_grow_right 
 2494 T:1899  a5 55                              lda cell_right             ; read cell to the right of the growing wall
 2495 T:189b  29 0f                              and #$0f             ; getting the cell type from the lower nybble
 2496 T:189d  d0 08                              bne growing_wall_return                ; If not zero (map_space) then end
 2497 T:189f  a9 8c                              lda #128|12       ; Otherwise replace the right cell with another growing wall
 2498 T:18a1  85 55                              sta cell_right
 2499 T:18a3  a9 82                              lda #130             ;same as amoeba_sound
 2500 T:18a5  85 8d                              sta play_sound_fx
 2501 T:18a7                           growing_wall_return 
 2502 T:18a7  60                                 rts 

 2504 T:18a8                                    ; *************************************************************************************
 2505 T:18a8                                    ; Handler for magic wall which turns rocks to diamonds (or diamonds to rocks)
 2506 T:18a8                                    ; Activated when a rock/diamond falls onto it and a rock/diamond is converted if there is
 2507 T:18a8                                    ; space below the magic wall, otherwise it disappears. Deactives when the magic wall timer
 2508 T:18a8                                    ; ends, rocks/diamonds disappear if they fall on a deactivated magic wall
 2509 T:18a8                           handler_magic_wall 

 2511 T:18a8  8a                                 txa 
 2512 T:18a9  a6 7b                              ldx magic_wall_state
 2513 T:18ab                                    ;wait for something to land on the wall to continue, see update_cell_type_when_below_a_falling_rock_or_diamond
 2514 T:18ab  c9 bd                              cmp #128|48|13
 2515 T:18ad  d0 27                              bne check_if_magic_wall_is_active
 2516 T:18af                                    ; read what's above the wall, getting the cell type from the lower nybble
 2517 T:18af  a5 51                              lda cell_above
 2518 T:18b1  29 0f                              and #$0f
 2519 T:18b3  a8                                 tay 
 2520 T:18b4                                    ; read what cell types are allowed to fall through and what is produced as a result
 2521 T:18b4                                    ; (rocks turn into diamonds and vice versa)
 2522 T:18b4  b9 20 20                           lda items_produced_by_the_magic_wall,y
 2523 T:18b7  f0 04                              beq skip_storing_space_above
 2524 T:18b9                                    ; something will fall into the wall, clear the cell above
 2525 T:18b9  a0 80                              ldy #128|0
 2526 T:18bb  84 51                              sty cell_above
 2527 T:18bd                           skip_storing_space_above 
 2528 T:18bd  e0 2d                              cpx #13|32       ;inactive
 2529 T:18bf  f0 12                              beq store_magic_wall_state
 2530 T:18c1                                    ; if the cell below isn't empty, then don't store the item below
 2531 T:18c1  a4 57                              ldy cell_below
 2532 T:18c3  d0 02                              bne magic_wall_is_active
 2533 T:18c5                                    ; store the item that has fallen through the wall below
 2534 T:18c5  85 57                              sta cell_below
 2535 T:18c7                           magic_wall_is_active 
 2536 T:18c7  a9 82                              lda #130             ;same as amoeba_sound
 2537 T:18c9  85 8e                              sta play_ambient_fx
 2538 T:18cb  a2 1d                              ldx #13|16       ;active
 2539 T:18cd  a4 7c                              ldy magic_wall_timer
 2540 T:18cf  d0 02                              bne store_magic_wall_state
 2541 T:18d1                                    ; magic wall becomes inactive once the timer has run out
 2542 T:18d1  a2 2d                              ldx #13|32       ;inactive
 2543 T:18d3                           store_magic_wall_state 
 2544 T:18d3  86 7b                              stx magic_wall_state
 2545 T:18d5  60                                 rts 

 2547 T:18d6                           check_if_magic_wall_is_active 
 2548 T:18d6  e0 1d                              cpx #13|16       ;active
 2549 T:18d8  f0 ed                              beq magic_wall_is_active
 2550 T:18da  60                                 rts 

 2552 T:18db                                    ; *************************************************************************************
 2553 T:18db                                    ; Handler for amoeba movement actions
 2554 T:18db                           handler_amoeba 

 2556 T:18db  a5 7f                              lda amoeba_replacement
 2557 T:18dd  f0 02                              beq update_amoeba
 2558 T:18df  aa                                 tax 
 2559 T:18e0  60                                 rts 

 2561 T:18e1                           update_amoeba 
 2562 T:18e1  e6 80                              inc number_of_amoeba_cells_found
 2563 T:18e3                                    ; check for surrounding space or earth allowing the amoeba to grow
 2564 T:18e3  a9 0e                              lda #$0e
 2565 T:18e5  24 51                              bit cell_above
 2566 T:18e7  f0 0c                              beq amoeba_can_grow
 2567 T:18e9  24 53                              bit cell_left
 2568 T:18eb  f0 08                              beq amoeba_can_grow
 2569 T:18ed  24 55                              bit cell_right
 2570 T:18ef  f0 04                              beq amoeba_can_grow
 2571 T:18f1  24 57                              bit cell_below
 2572 T:18f3  d0 3d                              bne amoeba_return
 2573 T:18f5                           amoeba_can_grow 
 2574 T:18f5  86 85                              stx current_amoeba_cell_type
 2575 T:18f7  a9 82                              lda #130
 2576 T:18f9  85 8e                              sta play_ambient_fx
 2577 T:18fb  e6 7e                              inc amoeba_counter
 2578 T:18fd  a5 7e                              lda amoeba_counter
 2579 T:18ff  c5 7d                              cmp amoeba_growth_interval
 2580 T:1901  d0 2f                              bne amoeba_return
 2581 T:1903  a9 00                              lda #0
 2582 T:1905  85 7e                              sta amoeba_counter
 2583 T:1907                                    ; calculate direction to grow based on current amoeba state in top bits
 2584 T:1907  8a                                 txa 
 2585 T:1908  4a                                 lsr 
 2586 T:1909  4a                                 lsr 
 2587 T:190a  4a                                 lsr 
 2588 T:190b  29 06                              and #6
 2589 T:190d                                    ; Y is set to 0,2,4, or 6 for the compass directions
 2590 T:190d  a8                                 tay 
 2591 T:190e  e0 c0                              cpx #192
 2592 T:1910  30 0d                              bmi check_for_space_or_earth
 2593 T:1912                                    ; get cell value for direction Y
 2594 T:1912  b9 51 00                           lda cell_above,y
 2595 T:1915  f0 0f                              beq found_space_or_earth_to_grow_into
 2596 T:1917                                    ; move amoeba onto next state (add 16)
 2597 T:1917                           increment_top_nybble_of_amoeba 
 2598 T:1917  8a                                 txa 
 2599 T:1918  18                                 clc 
 2600 T:1919  69 10                              adc #$10
 2601 T:191b  29 7f                              and #$7f
 2602 T:191d  aa                                 tax 
 2603 T:191e  60                                 rts 

 2605 T:191f                                    ; get cell value for direction Y
 2606 T:191f                           check_for_space_or_earth 
 2607 T:191f  b9 51 00                           lda cell_above,y
 2608 T:1922                                    ; branch if 0 or 1 (space or earth)
 2609 T:1922  29 0e                              and #$0e
 2610 T:1924  d0 f1                              bne increment_top_nybble_of_amoeba
 2611 T:1926                           found_space_or_earth_to_grow_into 
 2612 T:1926  a5 8a                              lda tick_counter
 2613 T:1928  4a                                 lsr 
 2614 T:1929  90 03                              bcc store_x
 2615 T:192b  20 17 19                           jsr increment_top_nybble_of_amoeba
 2616 T:192e                           store_x   
 2617 T:192e  8a                                 txa 
 2618 T:192f  99 51 00                           sta cell_above,y
 2619 T:1932                           amoeba_return 
 2620 T:1932  60                                 rts 

 2622 T:1933                                    ; *************************************************************************************
 2623 T:1933                                    ; Updates amoeba timing. At the end of amoeba growth time converts to diamonds if it is
 2624 T:1933                                    ; constrained and cannot grow anymore, otherwise converts to rocks
 2625 T:1933                           update_amoeba_timing 

 2627 T:1933  a5 80                              lda number_of_amoeba_cells_found
 2628 T:1935  f0 10                              beq check_for_amoeba_timeout
 2629 T:1937  a4 85                              ldy current_amoeba_cell_type
 2630 T:1939  d0 04                              bne found_amoeba
 2631 T:193b  a2 92                              ldx #128|18       ;via handler_basics and explosion_replacements table converts to diamond
 2632 T:193d  d0 06                              bne amoeba_replacement_found                ;always branch
 2633 T:193f                           found_amoeba 
 2634 T:193f  69 38                              adc #$38
 2635 T:1941  90 04                              bcc check_for_amoeba_timeout
 2636 T:1943                                    ; towards the end of the level time the amoeba turns into rock
 2637 T:1943  a2 85                              ldx #128|5
 2638 T:1945                           amoeba_replacement_found 
 2639 T:1945  86 7f                              stx amoeba_replacement
 2640 T:1947                           check_for_amoeba_timeout 
 2641 T:1947  a5 77                              lda time_remaining
 2642 T:1949  c9 32                              cmp #50
 2643 T:194b  d0 0d                              bne amoeba_timing_return
 2644 T:194d  a5 8b                              lda sub_second_ticks
 2645 T:194f  c9 07                              cmp #7
 2646 T:1951  d0 07                              bne amoeba_timing_return
 2647 T:1953  a9 01                              lda #1
 2648 T:1955  85 7d                              sta amoeba_growth_interval
 2649 T:1957                                    ; Set A=0 and zero the amoeba counter
 2650 T:1957  4a                                 lsr 
 2651 T:1958  85 7e                              sta amoeba_counter
 2652 T:195a                           amoeba_timing_return 
 2653 T:195a  60                                 rts 

 2655 T:195b                                    ; *************************************************************************************
 2656 T:195b                                    ; Handler for slime element which allows rocks and diamonds to pass through it but nothing else
 2657 T:195b                                    ; The slime permeability cave parameter controls how quickly rocks and diamonds can pass through it
 2658 T:195b                           handler_slime 

 2660 T:195b  a5 51                              lda cell_above             ; read what's above the wall, getting the cell type from the lower nybble
 2661 T:195d  29 0f                              and #$0f
 2662 T:195f  a8                                 tay 
 2663 T:1960  b9 30 20                           lda items_allowed_through_slime,y              ; read which cell types are allowed to fall through
 2664 T:1963  f0 2e                              beq slime_return                ; If not the right type (rock or diamond) then end
 2665 T:1965  8d 8e 19                           sta item_allowed+1
 2666 T:1968  a5 57                              lda cell_below
 2667 T:196a  d0 27                              bne slime_return                ; If no space below the slime for a rock or diamond to fall then end
 2668 T:196c  ad 23 26                           lda param_slime_permeability
 2669 T:196f  f0 18                              beq slime_pass_through                ; If slime permeability is zero, no delay in pass through
 2670 T:1971  a9 00                              lda #0             ; Otherwise continue and determine random delay
 2671 T:1973  8d 78 1b                           sta random_seed1
 2672 T:1976  ad 79 1b                           lda random_seed2
 2673 T:1979  d0 06                              bne slime_delay                ; If random_seed2 is not zero, use it for pseudo_random calculation
 2674 T:197b  ad 23 26                           lda param_slime_permeability                ; Otherwise set random_seed2 to slime permeability value
 2675 T:197e  8d 79 1b                           sta random_seed2
 2676 T:1981                           slime_delay 
 2677 T:1981  20 48 1b                           jsr pseudo_random                ; Call pseudo-random routine returning random_seed1 in the accumulator
 2678 T:1984  c9 04                              cmp #$04             ; A suitable delay-comparison value
 2679 T:1986  90 01                              bcc slime_pass_through                ; If random_seed1 is less than delay-comparison value then let the item pass through
 2680 T:1988  60                                 rts                    ; Otherwise skip the item. Next time in loop, will use the last random_seed2 value and eventually pass through

 2682 T:1989                           slime_pass_through 
 2683 T:1989  a9 80                              lda #128|0       ; something will fall into the wall, clear the cell above
 2684 T:198b  85 51                              sta cell_above
 2685 T:198d                           item_allowed 
 2686 T:198d  a9 00                              lda #0             ;self-mod, see above
 2687 T:198f  09 40                              ora #64             ; mark the rock / diamond / bomb as fallen
 2688 T:1991  85 57                              sta cell_below             ; store the item that has fallen through the wall below
 2689 T:1993                           slime_return 
 2690 T:1993  60                                 rts 

 2692 T:1994                                    ; *************************************************************************************
 2693 T:1994                                    ; Handler for bomb action countdown and explosion
 2694 T:1994                                    ; Rockford can lay a bomb in a space tile by holding down return and pressing a direction key
 2695 T:1994                                    ; The bomb has a fuse and when time is up, it explodes like a firefly / butterfly / Rockford can
 2696 T:1994                           handler_bomb 

 2698 T:1994  e0 cb                              cpx #11|128|$40 ;if bomb, unprocessed and falling then suspend countdown
 2699 T:1996  b0 23                              bcs bomb_return
 2700 T:1998  a5 8a                              lda tick_counter
 2701 T:199a  29 07                              and #7             ;check only bits 0,1,2 of the tick counter
 2702 T:199c  c9 07                              cmp #7             ;equals 7
 2703 T:199e  d0 1b                              bne bomb_return                ;do nothing if not 7
 2704 T:19a0  8a                                 txa                    ;x register holds current cell value
 2705 T:19a1  18                                 clc 
 2706 T:19a2  69 10                              adc #16             ;add the next animation frame
 2707 T:19a4  c9 cb                              cmp #11|128|64 ;use last animation frame to check limit
 2708 T:19a6  b0 02                              bcs bomb_explode                ;if past last frame, time to explode!
 2709 T:19a8  aa                                 tax                    ;x register holds current cell value, updated with animation frame
 2710 T:19a9  60                                 rts 

 2712 T:19aa                           bomb_explode 
 2713 T:19aa  a2 c0                              ldx #192             ;set the cell to deadly
 2714 T:19ac  20 33 18                           jsr show_large_explosion             ;call the explosion routine

 2716 T:19af  a5 57                              lda cell_below             ;update cell below (as done by other 'standard' handlers)
 2717 T:19b1  a0 81                              ldy #$81
 2718 T:19b3  91 64                              sta (map_address_low),y
 2719 T:19b5  a5 51                              lda cell_above             ;update cell below (as done by other 'standard' handlers)
 2720 T:19b7  a0 01                              ldy #1
 2721 T:19b9  91 64                              sta (map_address_low),y

 2723 T:19bb                           bomb_return 
 2724 T:19bb  60                                 rts 

 2726 T:19bc                                    ; ****************************************************************************************************
 2727 T:19bc                                    ; Let the user select which version of Boulder Dash to play and load the caves file for it
 2728 T:19bc                           select_caves_for_version 

 2730 T:19bc  20 33 ec                           jsr $ec33              ;Hires mode for splash screen

 2732 T:19bf  a0 00                              ldy #0             ;splash screen location
 2733 T:19c1  20 7c 1b                           jsr load_TAP_using_filename                ;loads to $a000 hires screen location, displaying splash screen

 2735 T:19c4                                    ;Set-up interrupt to read keys and play sounds, see keyboard.s
 2736 T:19c4                                    ;Located here for rom 1.0 as interrupts must be running normally for HIRES and TEXT mode commands
 2737 T:19c4  20 5d 1c                           jsr _InitIRQ

 2739 T:19c7  ad 19 06                           lda version_selected+1
 2740 T:19ca                           version_display 
 2741 T:19ca  20 eb 19                           jsr show_version_text
 2742 T:19cd  a2 ff                              ldx #$ff
 2743 T:19cf  20 82 0f                           jsr delay_a_bit

 2745 T:19d2                           version_loop 
 2746 T:19d2  a5 5a                              lda _KeyRowArrows
 2747 T:19d4  c9 01                              cmp #1
 2748 T:19d6  f0 53                              beq end_version_selection

 2750 T:19d8  c9 08                              cmp #8
 2751 T:19da  f0 37                              beq version_down

 2753 T:19dc  c9 40                              cmp #64
 2754 T:19de  f0 3f                              beq version_up

 2756 T:19e0  c9 80                              cmp #128
 2757 T:19e2  f0 3b                              beq version_up

 2759 T:19e4  c9 20                              cmp #32
 2760 T:19e6  f0 2b                              beq version_down

 2762 T:19e8  4c d2 19                           jmp version_loop

 2764 T:19eb                           show_version_text 
 2765 T:19eb  ad 19 06                           lda version_selected+1       ;multiply by 16 (4 x asl)
 2766 T:19ee  0a                                 asl 
 2767 T:19ef  0a                                 asl 
 2768 T:19f0  0a                                 asl 
 2769 T:19f1  0a                                 asl 
 2770 T:19f2  a8                                 tay                    ;version text table location in Y

 2772 T:19f3                                    ;set first line to black ink (is a clear line)
 2773 T:19f3  a9 00                              lda #0
 2774 T:19f5  8d 68 bf                           sta $bf68

 2776 T:19f8                                    ;set version text (all lines are the same length)
 2777 T:19f8  a2 00                              ldx #0
 2778 T:19fa                           version_text_loop 
 2779 T:19fa  bd ea 24                           lda version_option_text,x
 2780 T:19fd  9d 90 bf                           sta $bf68+40,x
 2781 T:1a00  9d b8 bf                           sta $bf68+80,x
 2782 T:1a03  b9 ea 24                           lda version_option_text,y
 2783 T:1a06  9d a4 bf                           sta $bf68+60,x
 2784 T:1a09  9d cc bf                           sta $bf68+100,x
 2785 T:1a0c  c8                                 iny 
 2786 T:1a0d  e8                                 inx 
 2787 T:1a0e  e0 10                              cpx #16
 2788 T:1a10  d0 e8                              bne version_text_loop
 2789 T:1a12  60                                 rts 

 2791 T:1a13                           version_down 
 2792 T:1a13  ac 19 06                           ldy version_selected+1
 2793 T:1a16  b9 83 25                           lda version_selection_cycle_down,y
 2794 T:1a19  8d 19 06                           sta version_selected+1
 2795 T:1a1c  4c ca 19                           jmp version_display

 2797 T:1a1f                           version_up 
 2798 T:1a1f  ac 19 06                           ldy version_selected+1
 2799 T:1a22  b9 7a 25                           lda version_selection_cycle_up,y
 2800 T:1a25  8d 19 06                           sta version_selected+1
 2801 T:1a28  4c ca 19                           jmp version_display

 2803 T:1a2b                           end_version_selection 

 2805 T:1a2b  20 6b 0f                           jsr clear_screen

 2807 T:1a2e                                    ;Exit hires for the splash screen and switch back to text mode for the game
 2808 T:1a2e  a9 1a                              lda #26             ;control character to switch to text mode (50 Hz)
 2809 T:1a30  8d 80 bb                           sta $bb80
 2810 T:1a33  a2 ff                              ldx #$ff
 2811 T:1a35  4c 82 0f                           jmp delay_a_bit

 2813 T:1a38                                    ; ****************************************************************************************************
 2814 T:1a38                                    ; Load cave data
 2815 T:1a38                                    ; Using the cave number, copy the cave data already loaded from CAVES.TAP file into the 
 2816 T:1a38                                    ; cave_parameter_data location used in the program
 2817 T:1a38                           load_cave_data 

 2819 T:1a38  a5 74                              lda cave_number
 2820 T:1a3a                           load_cave_number_stored 
 2821 T:1a3a  c9 ff                              cmp #$ff             ;Check if the cave is already stored, initially cave $ff isn't a valid one, so will always loads cave A
 2822 T:1a3c  f0 25                              beq load_cave_data_return                ;Skip if already loaded

 2824 T:1a3e                                    ;Copy cave from load area into area used in program
 2825 T:1a3e  a5 74                              lda cave_number             ;cave number starts from zero
 2826 T:1a40  8d 3b 1a                           sta load_cave_number_stored+1

 2828 T:1a43  a8                                 tay 
 2829 T:1a44  b9 94 25                           lda cave_addr_low,y
 2830 T:1a47  85 60                              sta screen_addr1_low             ;source low
 2831 T:1a49  b9 a9 25                           lda cave_addr_high,y
 2832 T:1a4c  85 61                              sta screen_addr1_high             ;source high

 2834 T:1a4e  a9 00                              lda #<cave_parameter_data
 2835 T:1a50  85 62                              sta screen_addr2_low             ;target low
 2836 T:1a52  a9 26                              lda #>cave_parameter_data
 2837 T:1a54  85 63                              sta screen_addr2_high             ;target high

 2839 T:1a56                                    ;size is always 448 bytes per cave
 2840 T:1a56  a9 c0                              lda #$c0
 2841 T:1a58  8d ae 0f                           sta copy_size
 2842 T:1a5b  a9 01                              lda #1
 2843 T:1a5d  8d af 0f                           sta copy_size+1

 2845 T:1a60  4c 8b 0f                           jmp copy_memory             ;copy from source to target for given size

 2847 T:1a63                           load_cave_data_return 
 2848 T:1a63  60                                 rts 

 2850 T:1a64                                    ; *************************************************************************************
 2851 T:1a64                                    ; Populate game tile map from cave_map_data loaded from file
 2852 T:1a64                           populate_cave_from_loaded_data 

 2854 T:1a64  a9 26                              lda #>cave_map_data              ; Point to cave address high byte
 2855 T:1a66  8d 7f 1a                           sta plot_cave_tiles_x2+2          ; Store in self-modifying code location
 2856 T:1a69  a9 30                              lda #<cave_map_data              ; Point to cave address low byte
 2857 T:1a6b  8d 7e 1a                           sta plot_cave_tiles_x2+1          ; Store in self-modifying code location

 2859 T:1a6e  a9 14                              lda #$14             ; Set row counter to 20 (excluding steel top and bottom rows)
 2860 T:1a70  8d a6 1a                           sta load_row_counter+1
 2861 T:1a73  a9 40                              lda #<tile_map_row_1           ; Point to start of map (low)
 2862 T:1a75  85 64                              sta map_address_low
 2863 T:1a77  a9 10                              lda #>tile_map_row_1           ; Point to start of map (high)
 2864 T:1a79  85 65                              sta map_address_high

 2866 T:1a7b                           load_plot_cave_row 
 2867 T:1a7b  a0 00                              ldy #$00             ; Set column start to 0
 2868 T:1a7d                           plot_cave_tiles_x2 
 2869 T:1a7d  ad 30 26                           lda cave_map_data                ; The cave_map_data value after LDA is changed in this routine (self-modifying code)
 2870 T:1a80  48                                 pha                    ; Store the byte (equates to 2 tiles) on the stack
 2871 T:1a81  4a                                 lsr                    ; left shift bits x 4 to get the nibble
 2872 T:1a82  4a                                 lsr 
 2873 T:1a83  4a                                 lsr 
 2874 T:1a84  4a                                 lsr 
 2875 T:1a85  91 64                              sta (map_address_low),y            ; Store nibble as tile value to map
 2876 T:1a87  c8                                 iny                    ; Add 1 for next tile position
 2877 T:1a88  68                                 pla                    ; Pull the byte off the stack
 2878 T:1a89  29 0f                              and #$0f             ; Get the second nibble
 2879 T:1a8b  91 64                              sta (map_address_low),y            ; Store nibble as tile value to map
 2880 T:1a8d  c8                                 iny                    ; Add 1 for next tile position
 2881 T:1a8e  ee 7e 1a                           inc plot_cave_tiles_x2+1       ; Move onto the next byte, calculating the high bytes as well
 2882 T:1a91  ad 7e 1a                           lda plot_cave_tiles_x2+1
 2883 T:1a94  d0 03                              bne load_skip_inc_high_byte
 2884 T:1a96  ee 7f 1a                           inc plot_cave_tiles_x2+2
 2885 T:1a99                           load_skip_inc_high_byte 
 2886 T:1a99  c0 28                              cpy #$28             ; Check if 40 tiles plotted
 2887 T:1a9b  d0 e0                              bne plot_cave_tiles_x2             ; Continue if not
 2888 T:1a9d  a9 40                              lda #$40             ; Add 64 to map_address_low
 2889 T:1a9f  20 61 0f                           jsr add_a_to_ptr
 2890 T:1aa2  ce a6 1a                           dec load_row_counter+1          ; Decrease row counter by 1
 2891 T:1aa5                           load_row_counter 
 2892 T:1aa5  a9 00                              lda #0             ;self-mod, see above
 2893 T:1aa7  f0 03                              beq populate_cave_return                ; If no more rows (counter is zero), go to end of routine
 2894 T:1aa9  4c 7b 1a                           jmp load_plot_cave_row             ; Continue to plot the next cave row

 2896 T:1aac                           populate_cave_return 
 2897 T:1aac  60                                 rts 

 2899 T:1aad                                    ; ****************************************************************************************************
 2900 T:1aad                                    ; Populate the cave with tiles using the pseudo-random method
 2901 T:1aad                                    ;   Tiles are applied to the map if the tile already there is a 'null' tile (from populate_cave_from_loaded_data)
 2902 T:1aad                                    ;   These tiles may be the cave default (often dirt) or a tile determined in a pseudo-random fashion
 2903 T:1aad                                    ;   A pseudo-random value is calculated by a function using the seed value for the cave difficulty level
 2904 T:1aad                                    ;   The pseudo-random value is returned in random_seed1
 2905 T:1aad                                    ;   This value is compared with each of the 4 tile probability values for the cave
 2906 T:1aad                                    ;   If random_seed1 is not less than the probability value, the corresponding tile is plotted
 2907 T:1aad                                    ;   For some caves, a second tile may be required below the pseudo-random one
 2908 T:1aad                                    ;   These tiles are held in a 'beneath' row, populated with second tile values from cave parameters
 2909 T:1aad                                    ;   If non-zero, the 'beneath' row tile will override random tiles (when on the next row)
 2910 T:1aad                           populate_cave_tiles_pseudo_random 

 2912 T:1aad  a6 75                              ldx difficulty_level             ; Use difficulty_level (values 1 to 5) for the random seed value to use
 2913 T:1aaf  ca                                 dex 
 2914 T:1ab0  bd 0e 26                           lda param_random_seeds,x              ; Set random_seed2 to cave random seed
 2915 T:1ab3  8d 79 1b                           sta random_seed2
 2916 T:1ab6  a9 00                              lda #$00             ; Set random_seed1 to 0
 2917 T:1ab8  8d 78 1b                           sta random_seed1

 2919 T:1abb  a9 16                              lda #$16             ; Set number of rows to 22 (includes steel top and bottom rows)
 2920 T:1abd  8d 41 1b                           sta populate_row_counter+1
 2921 T:1ac0  a9 40                              lda #<tile_map_row_1           ; Point to start of map (low)
 2922 T:1ac2  85 64                              sta map_address_low
 2923 T:1ac4  a9 10                              lda #>tile_map_row_1           ; Point to start of map (high)
 2924 T:1ac6  85 65                              sta map_address_high
 2925 T:1ac8                           populate_cave_row 
 2926 T:1ac8  a0 00                              ldy #$00             ; Set column start to 0
 2927 T:1aca                           populate_cave_tile 
 2928 T:1aca  b9 80 15                           lda tile_below_store_row,y           ; Needed for BD2 caves G, K, get previously stored tile
 2929 T:1acd  8d 29 1b                           sta check_tile_override+1          ; The override tile might need to replace the random tile

 2931 T:1ad0  ae 0d 26                           ldx param_initial_fill_tile                ; Set cave fill tile
 2932 T:1ad3  20 48 1b                           jsr pseudo_random                ; Call pseudo-random routine returning random_seed1 in the accumulator
 2933 T:1ad6  cd 13 26                           cmp param_tile_probability                ; Compare pseudo-random value with first cave probability parameter
 2934 T:1ad9  b0 09                              bcs check_next_probability1                ; If random_seed1 is not less than cave random compare parameter, don't plot the cave random object, try next one
 2935 T:1adb  ae 17 26                           ldx param_tile_for_probability                ; Set the designated cave random tile
 2936 T:1ade  ad 24 26                           lda param_tile_for_prob_below                ; Needed for BD2 caves G, K, set the tile below current one
 2937 T:1ae1  99 80 15                           sta tile_below_store_row,y           ; to the parameter value for it (this value is 0 for most caves)

 2939 T:1ae4                           check_next_probability1 
 2940 T:1ae4  ad 78 1b                           lda random_seed1
 2941 T:1ae7  cd 14 26                           cmp param_tile_probability+1          ; Compare pseudo-random value with second cave probability parameter
 2942 T:1aea  b0 09                              bcs check_next_probability2                ; If random_seed1 is not less than cave random compare parameter, don't plot the cave random object, try next one
 2943 T:1aec  ae 18 26                           ldx param_tile_for_probability+1          ; Set the designated cave random tile
 2944 T:1aef  ad 25 26                           lda param_tile_for_prob_below+1          ; Needed for BD2 caves G, K, set the tile below current one
 2945 T:1af2  99 80 15                           sta tile_below_store_row,y           ; to the parameter value for it (this value is 0 for most caves)

 2947 T:1af5                           check_next_probability2 
 2948 T:1af5  ad 78 1b                           lda random_seed1
 2949 T:1af8  cd 15 26                           cmp param_tile_probability+2          ; Compare pseudo-random value with third cave probability parameter
 2950 T:1afb  b0 09                              bcs check_next_probability3                ; If random_seed1 is not less than cave random compare parameter, don't plot the cave random object, try next one
 2951 T:1afd  ae 19 26                           ldx param_tile_for_probability+2          ; Set the designated cave random tile
 2952 T:1b00  ad 26 26                           lda param_tile_for_prob_below+2          ; Needed for BD2 caves G, K, set the tile below current one
 2953 T:1b03  99 80 15                           sta tile_below_store_row,y           ; to the parameter value for it (this value is 0 for most caves)

 2955 T:1b06                           check_next_probability3 
 2956 T:1b06  ad 78 1b                           lda random_seed1
 2957 T:1b09  cd 16 26                           cmp param_tile_probability+3          ; Compare pseudo-random value with forth cave probability parameter
 2958 T:1b0c  b0 09                              bcs check_probability_end                ; If random_seed1 is not less than cave random compare parameter, don't plot the cave random object, continue
 2959 T:1b0e  ae 1a 26                           ldx param_tile_for_probability+3          ; Set the designated cave random tile
 2960 T:1b11  ad 27 26                           lda param_tile_for_prob_below+3          ; Needed for BD2 caves G, K, set the tile below current one
 2961 T:1b14  99 80 15                           sta tile_below_store_row,y           ; to the parameter value for it (this value is 0 for most caves)

 2963 T:1b17                           check_probability_end 
 2964 T:1b17  b1 64                              lda (map_address_low),y            ; Get the map tile added when the cave was loaded
 2965 T:1b19  c9 0f                              cmp #$0f             ; Check if a null tile #$0f. This occurs at this late stage to preserve the ongoing random seed calculations
 2966 T:1b1b  f0 08                              beq apply_random_tile_ok                ; Allow replacement with the random tile where is currently null
 2967 T:1b1d  a9 00                              lda #0             ; Needed for BD2 caves G, K, reset the tile below current one
 2968 T:1b1f  99 80 15                           sta tile_below_store_row,y           ; It must not be used later for override
 2969 T:1b22  4c 28 1b                           jmp check_tile_override                ; Now check for a previous override

 2971 T:1b25                           apply_random_tile_ok 
 2972 T:1b25  8a                                 txa                    ; The loaded map tile was a null, so replace with the random tile instead
 2973 T:1b26  91 64                              sta (map_address_low),y

 2975 T:1b28                           check_tile_override 
 2976 T:1b28  a9 00                              lda #0             ;self-mod, see above
 2977 T:1b2a  f0 07                              beq skip_below_tile                ; Needed for BD2 caves G, K, check the override tile is 0
 2978 T:1b2c  91 64                              sta (map_address_low),y            ; If not then apply the override tile
 2979 T:1b2e  a9 00                              lda #0             ; Reset the tile below current one for next time
 2980 T:1b30  99 80 15                           sta tile_below_store_row,y

 2982 T:1b33                           skip_below_tile 
 2983 T:1b33  c8                                 iny                    ; Add 1 to column count
 2984 T:1b34  c0 28                              cpy #$28             ; Check if 40 columns plotted
 2985 T:1b36  d0 92                              bne populate_cave_tile             ; Continue if not
 2986 T:1b38  a9 40                              lda #$40             ; Add 64 to map_address_low
 2987 T:1b3a  20 61 0f                           jsr add_a_to_ptr
 2988 T:1b3d  ce 41 1b                           dec populate_row_counter+1
 2989 T:1b40                           populate_row_counter 
 2990 T:1b40  a9 00                              lda #0             ;Self-mod, see above
 2991 T:1b42  f0 03                              beq tiles_pseudo_return                ; Rows are zero, so end
 2992 T:1b44  4c c8 1a                           jmp populate_cave_row             ; Continue to plot the next cave row
 2993 T:1b47                           tiles_pseudo_return 
 2994 T:1b47  60                                 rts 

 2996 T:1b48                                    ; ****************************************************************************************************
 2997 T:1b48                                    ; Pseudo-random function
 2998 T:1b48                                    ;   Using a seed value, apply various operations to provide a value in random_seed1 used above
 2999 T:1b48                                    ;   This value is not random, for a given seed value, the returned value is always predictable
 3000 T:1b48                           pseudo_random 

 3002 T:1b48  ad 78 1b                           lda random_seed1
 3003 T:1b4b  6a                                 ror 
 3004 T:1b4c  6a                                 ror 
 3005 T:1b4d  29 80                              and #$80
 3006 T:1b4f  8d 7a 1b                           sta seeded_rand_temp1

 3008 T:1b52  ad 79 1b                           lda random_seed2
 3009 T:1b55  6a                                 ror 
 3010 T:1b56  29 7f                              and #$7f
 3011 T:1b58  8d 7b 1b                           sta seeded_rand_temp2

 3013 T:1b5b  ad 79 1b                           lda random_seed2
 3014 T:1b5e  6a                                 ror 
 3015 T:1b5f  6a                                 ror 
 3016 T:1b60  29 80                              and #$80
 3017 T:1b62  18                                 clc 
 3018 T:1b63  6d 79 1b                           adc random_seed2
 3019 T:1b66  69 13                              adc #$13
 3020 T:1b68  8d 79 1b                           sta random_seed2
 3021 T:1b6b  ad 78 1b                           lda random_seed1
 3022 T:1b6e  6d 7a 1b                           adc seeded_rand_temp1
 3023 T:1b71  6d 7b 1b                           adc seeded_rand_temp2
 3024 T:1b74  8d 78 1b                           sta random_seed1
 3025 T:1b77  60                                 rts 

 3027 T:1b78                           random_seed1 
 3028 T:1b78  00                                 .byt 0
 3029 T:1b79                           random_seed2 
 3030 T:1b79  00                                 .byt 0
 3031 T:1b7a                           seeded_rand_temp1 
 3032 T:1b7a  00                                 .byt 0
 3033 T:1b7b                           seeded_rand_temp2 
 3034 T:1b7b  00                                 .byt 0

 3036 T:1b7c                                    ; *************************************************************************************
 3037 T:1b7c                                    ; Load sprites or caves TAP files into memory at the location set in the TAP file header
 3038 T:1b7c                                    ; The Y register is used as input to get the sprites or caves filename needed for loading
 3039 T:1b7c                           load_TAP_using_filename 

 3041 T:1b7c                                    ;Prepare the TAP filename starting in y offset
 3042 T:1b7c  a2 00                              ldx #0
 3043 T:1b7e                           filename_loop 
 3044 T:1b7e  b9 a2 24                           lda TAP_filenames,y

 3048 T:1b81  9d 7f 02                           sta $027f,x            ;Store the filename, $27F - $28E is the filename address, terminated by #00

 3050 T:1b84  c8                                 iny 
 3051 T:1b85  e8                                 inx 
 3052 T:1b86  e0 08                              cpx #8             ;filename is 8 chars max
 3053 T:1b88  d0 f4                              bne filename_loop

 3055 T:1b8a                                    ;Set the tape load flags
 3056 T:1b8a  a9 00                              lda #0

 3060 T:1b8c  8d 4d 02                           sta $024d              ;tape speed (0 = fast, 1 = slow)
 3061 T:1b8f  8d 5b 02                           sta $025b              ;verify flag (0 = load, 1 = verify)

 3064 T:1b92  20 6a e7                           jsr $e76a              ; Prepare VIA for tape reading

 3066 T:1b95  20 ac e4                           jsr $e4ac              ; Read the header

 3068 T:1b98  20 e0 e4                           jsr $e4e0              ; Actual loading of the tape content
 3069 T:1b9b  4c 3d e9                           jmp $e93d              ; Restore the VIA state

 3071 T:1b9e                                    ; *************************************************************************************
 3072 T:1b9e                                    ; Display instruction screens for the game
 3073 T:1b9e                           display_instructions 

 3075 T:1b9e  a0 00                              ldy #0
 3076 T:1ba0  8c b7 1b                           sty current_instruction_page+1
 3077 T:1ba3  20 cd 1b                           jsr display_page_of_instructions

 3079 T:1ba6                           instructions_loop 
 3080 T:1ba6  a5 5a                              lda _KeyRowArrows
 3081 T:1ba8  c9 01                              cmp #1
 3082 T:1baa  f0 07                              beq end_instructions

 3084 T:1bac  c9 40                              cmp #64
 3085 T:1bae  f0 06                              beq current_instruction_page

 3087 T:1bb0  4c a6 1b                           jmp instructions_loop

 3089 T:1bb3                           end_instructions 
 3090 T:1bb3  4c 6b 0f                           jmp clear_screen

 3092 T:1bb6                           current_instruction_page 
 3093 T:1bb6  a0 00                              ldy #0             ;self-mod, see above
 3094 T:1bb8  c8                                 iny 
 3095 T:1bb9  c0 04                              cpy #4             ;4 pages of instructions
 3096 T:1bbb  d0 02                              bne show_instruction_page
 3097 T:1bbd  a0 00                              ldy #0
 3098 T:1bbf                           show_instruction_page 
 3099 T:1bbf  8c b7 1b                           sty current_instruction_page+1
 3100 T:1bc2  20 cd 1b                           jsr display_page_of_instructions

 3102 T:1bc5  a2 ff                              ldx #$ff
 3103 T:1bc7  20 82 0f                           jsr delay_a_bit
 3104 T:1bca  4c a6 1b                           jmp instructions_loop

 3106 T:1bcd                           display_page_of_instructions 
 3107 T:1bcd  b9 8c 25                           lda instruction_page_low,y
 3108 T:1bd0  85 60                              sta screen_addr1_low             ;source low
 3109 T:1bd2  b9 90 25                           lda instruction_page_high,y
 3110 T:1bd5  85 61                              sta screen_addr1_high             ;source high

 3112 T:1bd7  a9 80                              lda #<$bb80
 3113 T:1bd9  85 62                              sta screen_addr2_low             ;target low
 3114 T:1bdb  a9 bb                              lda #>$bb80
 3115 T:1bdd  85 63                              sta screen_addr2_high             ;target high

 3117 T:1bdf                                    ;size is 1120 bytes for display (28 lines of 40 columns)
 3118 T:1bdf  a9 60                              lda #$60
 3119 T:1be1  8d ae 0f                           sta copy_size
 3120 T:1be4  a9 04                              lda #$04
 3121 T:1be6  8d af 0f                           sta copy_size+1

 3123 T:1be9  4c 8b 0f                           jmp copy_memory

 3125 T:1bec                                    ; *************************************************************************************
 3126 T:1bec                                    ; Sound actions called by interrupt routine (see keyboard.s) to play in game sounds or theme tune
 3127 T:1bec                           sound_actions_irq 
 3128 T:1bec  4c ef 1b                           jmp update_sounds                ;self-mod into play_theme_tune or update_sounds

 3130 T:1bef                                    ; *************************************************************************************
 3131 T:1bef                                    ; Plays the short sound given in play_sound_fx (got diamond, boulder moves)
 3132 T:1bef                                    ;   and plays any ambient sound if set (magic wall, amoeba sounds)
 3133 T:1bef                           update_sounds 

 3135 T:1bef  a5 8d                              lda play_sound_fx
 3136 T:1bf1  f0 2a                              beq check_ambient_fx
 3137 T:1bf3                           compare_sound_fx 
 3138 T:1bf3  c9 00                              cmp #0             ;has the sound effect changed (self-mod value check)?
 3139 T:1bf5  f0 05                              beq continue_current_fx                ;if not, continue it
 3140 T:1bf7  a0 00                              ldy #0             ;otherwise, sound effect has changed, clear the note and play the new one
 3141 T:1bf9  8c 00 22                           sty active_sound_duration
 3142 T:1bfc                           continue_current_fx 
 3143 T:1bfc  ac 00 22                           ldy active_sound_duration                ;is the sound effect in progress?
 3144 T:1bff  d0 0e                              bne continue_sound_fx                ;if so, continue it
 3145 T:1c01  8d f4 1b                           sta compare_sound_fx+1       ;update current sound (self-mod value)
 3146 T:1c04  a6 8d                              ldx play_sound_fx             ;this is the low byte of list_of_sounds

 3148 T:1c06  bd 0f 22                           lda list_of_sounds+15,x        ;point to duration byte on the end
 3149 T:1c09  8d 00 22                           sta active_sound_duration
 3150 T:1c0c  4c 58 1c                           jmp play_note_fx
 3151 T:1c0f                           continue_sound_fx 
 3152 T:1c0f  ce 00 22                           dec active_sound_duration
 3153 T:1c12  ac 00 22                           ldy active_sound_duration
 3154 T:1c15  f0 01                              beq clear_sound_fx
 3155 T:1c17  60                                 rts 
 3156 T:1c18                           clear_sound_fx 
 3157 T:1c18  a9 00                              lda #0
 3158 T:1c1a  85 8d                              sta play_sound_fx
 3159 T:1c1c  60                                 rts 

 3161 T:1c1d                           check_ambient_fx 
 3162 T:1c1d  a6 8e                              ldx play_ambient_fx             ;is there an ambient sound effect? x is the low byte of list_of_sounds
 3163 T:1c1f  f0 36                              beq end_sound_fx                ;if not, end
 3164 T:1c21  ac 01 22                           ldy active_ambient_duration                ;is the sound effect in progress?
 3165 T:1c24  d0 24                              bne continue_ambient_fx                ;if so, continue it
 3166 T:1c26  bd 0f 22                           lda list_of_sounds+15,x        ;point to duration byte on the end
 3167 T:1c29  8d 01 22                           sta active_ambient_duration

 3169 T:1c2c  e0 92                              cpx #146
 3170 T:1c2e  d0 0b                              bne amoeba_magic_wall_sound
 3171 T:1c30                                    ; create some 'random' audio pitches to play while revealing/hiding the map
 3172 T:1c30  ad 85 0b                           lda get_next_random_byte+1       ;don't use the get_next_random_byte routine which affects the reveal/hide effect
 3173 T:1c33  05 74                              ora cave_number
 3174 T:1c35  8d 92 22                           sta sound_random_base                ;set the pitch on the A channel (first byte)
 3175 T:1c38  4c 58 1c                           jmp play_note_fx
 3176 T:1c3b                           amoeba_magic_wall_sound 
 3177 T:1c3b                                    ; create some 'random' audio pitches for amoeba, magic wall ambient sound fx
 3178 T:1c3b  20 84 0b                           jsr get_next_random_byte
 3179 T:1c3e  09 c0                              ora #192
 3180 T:1c40  45 74                              eor cave_number
 3181 T:1c42  29 f8                              and #248
 3182 T:1c44  8d 82 22                           sta sound_amoeba_magic_wall                ;set the pitch on the A channel (first byte)
 3183 T:1c47  4c 58 1c                           jmp play_note_fx
 3184 T:1c4a                           continue_ambient_fx 
 3185 T:1c4a  ce 01 22                           dec active_ambient_duration
 3186 T:1c4d  ac 01 22                           ldy active_ambient_duration
 3187 T:1c50  f0 01                              beq clear_ambient_fx
 3188 T:1c52  60                                 rts 
 3189 T:1c53                           clear_ambient_fx 
 3190 T:1c53  a9 00                              lda #0
 3191 T:1c55  85 8e                              sta play_ambient_fx
 3192 T:1c57                           end_sound_fx 
 3193 T:1c57  60                                 rts 

 3195 T:1c58                           play_note_fx 
 3196 T:1c58  a0 22                              ldy #>list_of_sounds              ;y is the high byte of list_of_sounds
 3197 T:1c5a  4c 86 fa                           jmp $fa86              ; Play sound effect

 3199 T:1c5d                                    ;Copied and slightly adapted from: https:
 3200 T:1c5d                                    ;

 3233 T:1c5d                           _InitIRQ  
 3234 T:1c5d                                     .( 
 3235 T:1c5d                                    ;Since we are starting from when the standard irq has already been 
 3236 T:1c5d                                    ;setup, we need not worry about ensuring one irq event and/or right 
 3237 T:1c5d                                    ;timer period, only redirecting irq vector to our own irq handler. 
 3238 T:1c5d  78                                 sei 

 3240 T:1c5e                                    ; Setup DDRA, DDRB and ACR
 3241 T:1c5e  a9 ff                              lda #%11111111
 3242 T:1c60  8d 03 03                           sta $0303
 3243 T:1c63  a9 f7                              lda #%11110111             ; PB0-2 outputs, PB3 input.
 3244 T:1c65  8d 02 03                           sta $0302
 3245 T:1c68  a9 40                              lda #%01000000
 3246 T:1c6a  8d 0b 03                           sta $030b

 3248 T:1c6d                                    ; Since we have only IRQ handler for everything, it is generally
 3249 T:1c6d                                    ; more useful to run at 50Hz, instead of 100 Hz.
 3250 T:1c6d  a9 20                              lda #<20000
 3251 T:1c6f  8d 06 03                           sta $0306
 3252 T:1c72  a9 4e                              lda #>20000
 3253 T:1c74  8d 07 03                           sta $0307

 3255 T:1c77                                    ; Patch IRQ vector
 3256 T:1c77  a9 83                              lda #<irq_routine
 3257 T:1c79  8d 45 02                           sta $0245
 3258 T:1c7c  a9 1c                              lda #>irq_routine
 3259 T:1c7e  8d 46 02                           sta $0246
 3260 T:1c81  58                                 cli 
 3261 T:1c82  60                                 rts 
 3262 T:1c83                                     .) 

 3265 T:1c83                           irq_routine 
 3266 T:1c83                                     .( 
 3267 T:1c83                                    ;Preserve registers 
 3268 T:1c83  85 5b                              sta irq_A
 3269 T:1c85  86 5c                              stx irq_X
 3270 T:1c87  84 5d                              sty irq_Y

 3272 T:1c89                                    ;Clear IRQ event 
 3273 T:1c89  ad 04 03                           lda $0304

 3275 T:1c8c                                    ;Process keyboard 
 3276 T:1c8c  20 a1 1c                           jsr ReadKeyboard

 3278 T:1c8f                                    ;Play in game sounds or theme tune
 3279 T:1c8f  20 ec 1b                           jsr sound_actions_irq

 3281 T:1c92                                    ;Restore Registers 
 3282 T:1c92  a5 5b                              lda irq_A
 3283 T:1c94  a6 5c                              ldx irq_X
 3284 T:1c96  a4 5d                              ldy irq_Y

 3286 T:1c98                                    ;End of IRQ 
 3287 T:1c98  40                                 rti 
 3288 T:1c99                                     .) 

 3291 T:1c99  df 7f f7 bf fe ef fd fb  values_code .byt $df,$7f,$f7,$bf,$fe,$ef,$fd,$fb

 3293 T:1ca1                           ReadKeyboard 
 3294 T:1ca1                                     .( 
 3295 T:1ca1  a9 00                              lda #0
 3296 T:1ca3  85 5a                              sta _KeyRowArrows

 3298 T:1ca5                                    ; Select the bottom row of the keyboard
 3299 T:1ca5  a0 04                              ldy #4
 3300 T:1ca7  8c 00 03                           sty $0300

 3302 T:1caa  a2 07                              ldx #7
 3303 T:1cac                           loop_read 

 3305 T:1cac                                    ; Write Column Register Number to PortA
 3306 T:1cac  a0 0e                              ldy #$0e
 3307 T:1cae  8c 0f 03                           sty $030f

 3309 T:1cb1                                    ; Tell AY this is Register Number
 3310 T:1cb1  a0 ff                              ldy #$ff
 3311 T:1cb3  8c 0c 03                           sty $030c

 3313 T:1cb6                                    ; Clear CB2, as keeping it high hangs on some orics.
 3314 T:1cb6                                    ; Pitty, as all this code could be run only once, otherwise
 3315 T:1cb6  a0 dd                              ldy #$dd
 3316 T:1cb8  8c 0c 03                           sty $030c

 3318 T:1cbb                                    ; Write to Column Register 
 3319 T:1cbb  bd 99 1c                           lda values_code,x
 3320 T:1cbe  8d 0f 03                           sta $030f
 3321 T:1cc1  a9 fd                              lda #$fd
 3322 T:1cc3  8d 0c 03                           sta $030c
 3323 T:1cc6  8c 0c 03                           sty $030c

 3325 T:1cc9  ad 00 03                           lda $0300
 3326 T:1ccc  29 08                              and #8
 3327 T:1cce  f0 09                              beq key_not_pressed

 3329 T:1cd0  bd 99 1c                           lda values_code,x
 3330 T:1cd3  49 ff                              eor #$ff
 3331 T:1cd5  05 5a                              ora _KeyRowArrows
 3332 T:1cd7  85 5a                              sta _KeyRowArrows

 3334 T:1cd9                           key_not_pressed 
 3335 T:1cd9  ca                                 dex 
 3336 T:1cda  10 d0                              bpl loop_read
 3337 T:1cdc  60                                 rts 
 3338 T:1cdd                                     .) 

 3340 T:1cdd                                    ; *************************************************************************************
 3341 T:1cdd                                    ; Remapped characters for each sprite
 3342 T:1cdd                                    ;
 3343 T:1cdd                                    ; IMPORTANT: this table must not go-over a page boundary
 3344 T:1cdd                                    ; The high byte must be the same for all sprite characters for draw_grid_of_sprites
 3345 T:1cdd  00 ff 00 01 00 64 02 ...           .dsb 256-(*&255)    ;Add another page of bytes
 3346 T:1d00                           sprite_addr_all_sprites 

 3348 T:1d00                           sprite_addr_space                  ;all space characters, not remapped
 3349 T:1d00  20 ff 04 00                        .dsb 4," "

 3351 T:1d04                           sprite_addr_earth1 
 3352 T:1d04                           sprite_addr_earth2 
 3353 T:1d04  a1 a3 a2 a4                        .byt "!"+128,"#"+128,34+128,"$"+128

 3355 T:1d08                           sprite_addr_wall1                  ;reuse characters
 3356 T:1d08                           sprite_addr_wall2 
 3357 T:1d08                           sprite_addr_magic_wall2 
 3358 T:1d08                           sprite_addr_magic_wall4 
 3359 T:1d08  a5 ff 04 00                        .dsb 4,"%"+128

 3361 T:1d0c                           sprite_addr_magic_wall1 
 3362 T:1d0c                           sprite_addr_magic_wall3 
 3363 T:1d0c  25 ff 04 00                        .dsb 4,"%"

 3365 T:1d10                           sprite_addr_titanium_wall1                  ;reuse characters
 3366 T:1d10                           sprite_addr_titanium_wall2 
 3367 T:1d10  a6 ff 04 00                        .dsb 4,"&"+128

 3369 T:1d14                           sprite_addr_diamond1 
 3370 T:1d14  27 29 28 2a                        .byt "')(*"
 3371 T:1d18                           sprite_addr_diamond2                  ;reusing a character from diamond 1
 3372 T:1d18  2b 29 2c 2d                        .byt "+),-"
 3373 T:1d1c                           sprite_addr_diamond3 
 3374 T:1d1c  a7 a9 a8 aa                        .byt "'"+128,")"+128,"("+128,"*"+128
 3375 T:1d20                           sprite_addr_diamond4 
 3376 T:1d20  ab a9 ac ad                        .byt "+"+128,")"+128,","+128,"-"+128

 3378 T:1d24                           sprite_addr_boulder1 
 3379 T:1d24  2e 30 2f 31                        .byt ".0/1"
 3380 T:1d28                           sprite_addr_boulder2 
 3381 T:1d28  ae b0 af b1                        .byt 46+128,48+128,47+128,49+128;invert sprite_addr_boulder1

 3383 T:1d2c                           sprite_addr_firefly1 
 3384 T:1d2c                           sprite_addr_firefly2 
 3385 T:1d2c  32 34 33 35                        .byt "2435"
 3386 T:1d30                           sprite_addr_firefly3 
 3387 T:1d30                           sprite_addr_firefly4 
 3388 T:1d30  b2 b4 b3 b5                        .byt 50+128,52+128,51+128,53+128;invert sprite_addr_firefly1

 3390 T:1d34                           sprite_addr_amoeba1 
 3391 T:1d34  36 38 37 39                        .byt "6879"
 3392 T:1d38                           sprite_addr_amoeba2 
 3393 T:1d38  3a 3c 3b 3d                        .byt ":<;="

 3395 T:1d3c                           sprite_addr_box 
 3396 T:1d3c  a0 ff 04 00                        .dsb 4,32+128  ;invert sprite_addr_space

 3398 T:1d40                           sprite_addr_explosion1 
 3399 T:1d40  3e 40 3f 41                        .byt ">@?A"
 3400 T:1d44                           sprite_addr_explosion2 
 3401 T:1d44  42 44 43 45                        .byt "BDCE"
 3402 T:1d48                           sprite_addr_explosion3 
 3403 T:1d48  46 48 47 49                        .byt "FHGI"
 3404 T:1d4c                           sprite_addr_explosion4 
 3405 T:1d4c  4a 4c 4b 4d                        .byt "JLKM"

 3407 T:1d50                           sprite_addr_butterfly1 
 3408 T:1d50  ce d0 cf d1                        .byt "N"+128,"P"+128,"O"+128,"Q"+128
 3409 T:1d54                           sprite_addr_butterfly2 
 3410 T:1d54  d2 d4 d3 d5                        .byt "R"+128,"T"+128,"S"+128,"U"+128
 3411 T:1d58                           sprite_addr_butterfly3 
 3412 T:1d58  d6 d8 d7 d9                        .byt "V"+128,"X"+128,"W"+128,"Y"+128

 3414 T:1d5c                           sprite_addr_bubble 

 3416 T:1d5c  5a 5c 5b 5d                        .byt "Z",92,"[]"   ;92 is 
 3417 T:1d60                           sprite_addr_rockford_blinking1                  ;aka 'normal' Rockford
 3418 T:1d60  5e 60 5f 61                        .byt "^`_a"
 3419 T:1d64                           sprite_addr_rockford_blinking2                  ;eyes blink
 3420 T:1d64  62 60 63 61                        .byt "b`ca"
 3421 T:1d68                           sprite_addr_rockford_blinking3                  ;eyes close
 3422 T:1d68  64 60 65 61                        .byt "d`ea"
 3423 T:1d6c                           sprite_addr_rockford_winking1                  ;right eye blink
 3424 T:1d6c  5e 60 63 61                        .byt "^`ca"
 3425 T:1d70                           sprite_addr_rockford_winking2                  ;right eye close
 3426 T:1d70  5e 60 65 61                        .byt "^`ea"
 3427 T:1d74                           sprite_addr_rockford_moving_down1                  ;aka wait 1 - fold arms
 3428 T:1d74  5e 66 5f 67                        .byt "^f_g"
 3429 T:1d78                           sprite_addr_rockford_moving_down2                  ;aka wait 2 - fold arms, tap foot
 3430 T:1d78  5e 68 5f 67                        .byt "^h_g"
 3431 T:1d7c                           sprite_addr_rockford_moving_down3                  ;aka wait 3 - eyes blink, fold arms
 3432 T:1d7c  62 66 63 67                        .byt "bfcg"
 3433 T:1d80                           sprite_addr_rockford_moving_up1                  ;aka wait 4 - eyes close, tap foot
 3434 T:1d80  64 68 65 67                        .byt "dheg"
 3435 T:1d84                           sprite_addr_rockford_moving_up2                  ;aka wait 5 - eyes close, fold arms
 3436 T:1d84  64 66 65 67                        .byt "dfeg"
 3437 T:1d88                           sprite_addr_rockford_moving_left1                  ;head left, legs full
 3438 T:1d88  69 6b 6a 6c                        .byt "ikjl"
 3439 T:1d8c                           sprite_addr_rockford_moving_left2                  ;head left, legs part
 3440 T:1d8c  69 6d 6a 6e                        .byt "imjn"
 3441 T:1d90                           sprite_addr_rockford_moving_left3                  ;head left, legs part-stand
 3442 T:1d90  69 6f 6a 70                        .byt "iojp"
 3443 T:1d94                           sprite_addr_rockford_moving_left4                  ;head left, legs stand
 3444 T:1d94  69 6f 6a 71                        .byt "iojq"
 3445 T:1d98                           sprite_addr_rockford_moving_right1                  ;head right, legs stand
 3446 T:1d98  72 74 73 75                        .byt "rtsu"
 3447 T:1d9c                           sprite_addr_rockford_moving_right2                  ;head right, legs part-stand
 3448 T:1d9c  72 76 73 75                        .byt "rvsu"
 3449 T:1da0                           sprite_addr_rockford_moving_right3                  ;head right, legs part
 3450 T:1da0  72 77 73 78                        .byt "rwsx"
 3451 T:1da4                           sprite_addr_rockford_moving_right4                  ;head right, legs full
 3452 T:1da4  72 79 73 7a                        .byt "rysz"

 3454 T:1da8                           sprite_addr_bomb 
 3455 T:1da8                           sprite_addr_bomb1 
 3456 T:1da8  7b 7d 7c 7e                        .byt "{}|~"
 3457 T:1dac                           sprite_addr_bomb2 
 3458 T:1dac                           sprite_addr_bomb3 
 3459 T:1dac  fb fd fc fe                        .byt 123+128,125+128,124+128,126+128;invert sprite_addr_bomb

 3461 T:1db0                           sprite_addr_pathway 
 3462 T:1db0  7f ff 04 00                        .dsb 4,127

 3464 T:1db4                                    ; *************************************************************************************
 3465 T:1db4                                    ; sprite addresses
 3466 T:1db4                                    ;
 3467 T:1db4                           sprite_addresses_low 
 3468 T:1db4  00                                 .byt <sprite_addr_space
 3469 T:1db5  24                                 .byt <sprite_addr_boulder1
 3470 T:1db6  5c                                 .byt <sprite_addr_bubble
 3471 T:1db7  14                                 .byt <sprite_addr_diamond1
 3472 T:1db8  18                                 .byt <sprite_addr_diamond2
 3473 T:1db9  1c                                 .byt <sprite_addr_diamond3
 3474 T:1dba  20                                 .byt <sprite_addr_diamond4
 3475 T:1dbb  10                                 .byt <sprite_addr_titanium_wall1
 3476 T:1dbc  10                                 .byt <sprite_addr_titanium_wall2
 3477 T:1dbd  3c                                 .byt <sprite_addr_box
 3478 T:1dbe  08                                 .byt <sprite_addr_wall1
 3479 T:1dbf  08                                 .byt <sprite_addr_wall2
 3480 T:1dc0  40                                 .byt <sprite_addr_explosion1
 3481 T:1dc1  44                                 .byt <sprite_addr_explosion2
 3482 T:1dc2  48                                 .byt <sprite_addr_explosion3
 3483 T:1dc3  4c                                 .byt <sprite_addr_explosion4
 3484 T:1dc4  0c                                 .byt <sprite_addr_magic_wall1
 3485 T:1dc5  08                                 .byt <sprite_addr_magic_wall2
 3486 T:1dc6  0c                                 .byt <sprite_addr_magic_wall3
 3487 T:1dc7  08                                 .byt <sprite_addr_magic_wall4
 3488 T:1dc8  34                                 .byt <sprite_addr_amoeba1
 3489 T:1dc9  38                                 .byt <sprite_addr_amoeba2
 3490 T:1dca  50                                 .byt <sprite_addr_butterfly1
 3491 T:1dcb  54                                 .byt <sprite_addr_butterfly2
 3492 T:1dcc  58                                 .byt <sprite_addr_butterfly3
 3493 T:1dcd  2c                                 .byt <sprite_addr_firefly1
 3494 T:1dce  2c                                 .byt <sprite_addr_firefly2
 3495 T:1dcf  30                                 .byt <sprite_addr_firefly3
 3496 T:1dd0  30                                 .byt <sprite_addr_firefly4
 3497 T:1dd1  04                                 .byt <sprite_addr_earth1
 3498 T:1dd2  04                                 .byt <sprite_addr_earth2
 3499 T:1dd3  b0                                 .byt <sprite_addr_pathway
 3500 T:1dd4  60                                 .byt <sprite_addr_rockford_blinking1
 3501 T:1dd5  64                                 .byt <sprite_addr_rockford_blinking2
 3502 T:1dd6  68                                 .byt <sprite_addr_rockford_blinking3
 3503 T:1dd7  6c                                 .byt <sprite_addr_rockford_winking1
 3504 T:1dd8  70                                 .byt <sprite_addr_rockford_winking2
 3505 T:1dd9  74                                 .byt <sprite_addr_rockford_moving_down1
 3506 T:1dda  78                                 .byt <sprite_addr_rockford_moving_down2
 3507 T:1ddb  7c                                 .byt <sprite_addr_rockford_moving_down3
 3508 T:1ddc  80                                 .byt <sprite_addr_rockford_moving_up1
 3509 T:1ddd  84                                 .byt <sprite_addr_rockford_moving_up2
 3510 T:1dde  88                                 .byt <sprite_addr_rockford_moving_left1
 3511 T:1ddf  8c                                 .byt <sprite_addr_rockford_moving_left2
 3512 T:1de0  90                                 .byt <sprite_addr_rockford_moving_left3
 3513 T:1de1  94                                 .byt <sprite_addr_rockford_moving_left4
 3514 T:1de2  98                                 .byt <sprite_addr_rockford_moving_right1
 3515 T:1de3  9c                                 .byt <sprite_addr_rockford_moving_right2
 3516 T:1de4  a0                                 .byt <sprite_addr_rockford_moving_right3
 3517 T:1de5  a4                                 .byt <sprite_addr_rockford_moving_right4
 3518 T:1de6  a8                                 .byt <sprite_addr_bomb
 3519 T:1de7  ac                                 .byt <sprite_addr_bomb3
 3520 T:1de8  ac                                 .byt <sprite_addr_bomb2
 3521 T:1de9  a8                                 .byt <sprite_addr_bomb1
 3522 T:1dea  28                                 .byt <sprite_addr_boulder2

 3524 T:1deb                           sprite_addresses_high 
 3525 T:1deb  1d                                 .byt >sprite_addr_space
 3526 T:1dec  1d                                 .byt >sprite_addr_boulder1
 3527 T:1ded  1d                                 .byt >sprite_addr_bubble
 3528 T:1dee  1d                                 .byt >sprite_addr_diamond1
 3529 T:1def  1d                                 .byt >sprite_addr_diamond2
 3530 T:1df0  1d                                 .byt >sprite_addr_diamond3
 3531 T:1df1  1d                                 .byt >sprite_addr_diamond4
 3532 T:1df2  1d                                 .byt >sprite_addr_titanium_wall1
 3533 T:1df3  1d                                 .byt >sprite_addr_titanium_wall2
 3534 T:1df4  1d                                 .byt >sprite_addr_box
 3535 T:1df5  1d                                 .byt >sprite_addr_wall1
 3536 T:1df6  1d                                 .byt >sprite_addr_wall2
 3537 T:1df7  1d                                 .byt >sprite_addr_explosion1
 3538 T:1df8  1d                                 .byt >sprite_addr_explosion2
 3539 T:1df9  1d                                 .byt >sprite_addr_explosion3
 3540 T:1dfa  1d                                 .byt >sprite_addr_explosion4
 3541 T:1dfb  1d                                 .byt >sprite_addr_magic_wall1
 3542 T:1dfc  1d                                 .byt >sprite_addr_magic_wall2
 3543 T:1dfd  1d                                 .byt >sprite_addr_magic_wall3
 3544 T:1dfe  1d                                 .byt >sprite_addr_magic_wall4
 3545 T:1dff  1d                                 .byt >sprite_addr_amoeba1
 3546 T:1e00  1d                                 .byt >sprite_addr_amoeba2
 3547 T:1e01  1d                                 .byt >sprite_addr_butterfly1
 3548 T:1e02  1d                                 .byt >sprite_addr_butterfly2
 3549 T:1e03  1d                                 .byt >sprite_addr_butterfly3
 3550 T:1e04  1d                                 .byt >sprite_addr_firefly1
 3551 T:1e05  1d                                 .byt >sprite_addr_firefly2
 3552 T:1e06  1d                                 .byt >sprite_addr_firefly3
 3553 T:1e07  1d                                 .byt >sprite_addr_firefly4
 3554 T:1e08  1d                                 .byt >sprite_addr_earth1
 3555 T:1e09  1d                                 .byt >sprite_addr_earth2
 3556 T:1e0a  1d                                 .byt >sprite_addr_pathway
 3557 T:1e0b  1d                                 .byt >sprite_addr_rockford_blinking1
 3558 T:1e0c  1d                                 .byt >sprite_addr_rockford_blinking2
 3559 T:1e0d  1d                                 .byt >sprite_addr_rockford_blinking3
 3560 T:1e0e  1d                                 .byt >sprite_addr_rockford_winking1
 3561 T:1e0f  1d                                 .byt >sprite_addr_rockford_winking2
 3562 T:1e10  1d                                 .byt >sprite_addr_rockford_moving_down1
 3563 T:1e11  1d                                 .byt >sprite_addr_rockford_moving_down2
 3564 T:1e12  1d                                 .byt >sprite_addr_rockford_moving_down3
 3565 T:1e13  1d                                 .byt >sprite_addr_rockford_moving_up1
 3566 T:1e14  1d                                 .byt >sprite_addr_rockford_moving_up2
 3567 T:1e15  1d                                 .byt >sprite_addr_rockford_moving_left1
 3568 T:1e16  1d                                 .byt >sprite_addr_rockford_moving_left2
 3569 T:1e17  1d                                 .byt >sprite_addr_rockford_moving_left3
 3570 T:1e18  1d                                 .byt >sprite_addr_rockford_moving_left4
 3571 T:1e19  1d                                 .byt >sprite_addr_rockford_moving_right1
 3572 T:1e1a  1d                                 .byt >sprite_addr_rockford_moving_right2
 3573 T:1e1b  1d                                 .byt >sprite_addr_rockford_moving_right3
 3574 T:1e1c  1d                                 .byt >sprite_addr_rockford_moving_right4
 3575 T:1e1d  1d                                 .byt >sprite_addr_bomb
 3576 T:1e1e  1d                                 .byt >sprite_addr_bomb3
 3577 T:1e1f  1d                                 .byt >sprite_addr_bomb2
 3578 T:1e20  1d                                 .byt >sprite_addr_bomb1
 3579 T:1e21  1d                                 .byt >sprite_addr_boulder2

 3581 T:1e22                                    ; *************************************************************************************
 3582 T:1e22                                    ; Sprite handler routine addresses
 3583 T:1e22                                    ;
 3584 T:1e22                           handler_table_low 
 3585 T:1e22  d0                                 .byt <handler_basics
 3586 T:1e23  d0                                 .byt <handler_basics
 3587 T:1e24  d0                                 .byt <handler_basics
 3588 T:1e25  d0                                 .byt <handler_basics
 3589 T:1e26  00                                 .byt 0
 3590 T:1e27  00                                 .byt 0
 3591 T:1e28  f3                                 .byt <handler_firefly_or_butterfly
 3592 T:1e29  db                                 .byt <handler_amoeba
 3593 T:1e2a  de                                 .byt <handler_rockford_intro_or_exit
 3594 T:1e2b  5b                                 .byt <handler_slime
 3595 T:1e2c  de                                 .byt <handler_rockford_intro_or_exit
 3596 T:1e2d  00                                 .byt 0
 3597 T:1e2e                           growing_wall_handler_low 
 3598 T:1e2e  8b                                 .byt <handler_growing_wall
 3599 T:1e2f  a8                                 .byt <handler_magic_wall
 3600 T:1e30  f3                                 .byt <handler_firefly_or_butterfly
 3601 T:1e31                           rockford_handler_low 
 3602 T:1e31  d2                                 .byt <handler_rockford

 3604 T:1e32                           handler_table_high 
 3605 T:1e32  17                                 .byt >handler_basics
 3606 T:1e33  17                                 .byt >handler_basics
 3607 T:1e34  17                                 .byt >handler_basics
 3608 T:1e35  17                                 .byt >handler_basics
 3609 T:1e36  00                                 .byt 0
 3610 T:1e37  00                                 .byt 0
 3611 T:1e38  17                                 .byt >handler_firefly_or_butterfly
 3612 T:1e39  18                                 .byt >handler_amoeba
 3613 T:1e3a  17                                 .byt >handler_rockford_intro_or_exit
 3614 T:1e3b  19                                 .byt >handler_slime
 3615 T:1e3c  17                                 .byt >handler_rockford_intro_or_exit
 3616 T:1e3d  00                                 .byt 0
 3617 T:1e3e                           growing_wall_handler_high 
 3618 T:1e3e  18                                 .byt >handler_growing_wall
 3619 T:1e3f  18                                 .byt >handler_magic_wall
 3620 T:1e40  17                                 .byt >handler_firefly_or_butterfly
 3621 T:1e41                           rockford_handler_high 
 3622 T:1e41  16                                 .byt >handler_rockford

 3624 T:1e42                                    ; *************************************************************************************
 3625 T:1e42                                    ; Mapping table to convert a cell type 0-$7f into a sprite number
 3626 T:1e42                                    ; The sprite number points to the sprite address to use (see above)
 3627 T:1e42                                    ; By changing the entries of this table on the fly, this table allows the sprite to
 3628 T:1e42                                    ; animate without the underlying cell type needing to change.
 3629 T:1e42                                    ;
 3630 T:1e42                           cell_type_to_sprite 
 3631 T:1e42  00                                 .byt 0              ; cell type $00 = map_space
 3632 T:1e43  1e                                 .byt 30              ;dup                                                                 ; cell type $01 = map_earth
 3633 T:1e44  0b                                 .byt 11              ;dup                                                                  ; cell type $02 = map_wall
 3634 T:1e45  08                                 .byt 8              ;dup                                                         ; cell type $03 = map_titanium_wall
 3635 T:1e46  03                                 .byt 3              ; cell type $04 = map_diamond
 3636 T:1e47  01                                 .byt 1              ; cell type $05 = map_rock
 3637 T:1e48  1c                                 .byt 28              ; cell type $06 = map_firefly
 3638 T:1e49                           amoeba_animated_sprite0 
 3639 T:1e49  14                                 .byt 20              ; cell type $07 = map_amoeba
 3640 T:1e4a  08                                 .byt 8              ;dup                                                         ; cell type $03 = map_titanium_wall
 3641 T:1e4b                           slime_animated_sprite0 
 3642 T:1e4b  14                                 .byt 20              ; cell type $09 = map_slime
 3643 T:1e4c  4c                                 .byt $4c              ; cell type $0A = map_explosion
 3644 T:1e4d  32                                 .byt 50              ; cell type $0B = map_bomb
 3645 T:1e4e                           growing_wall_sprite 
 3646 T:1e4e  10                                 .byt 16              ; cell type $0C = map_growing_wall
 3647 T:1e4f  0b                                 .byt 11              ;dup                                                                  ; cell type $0D = map_magic_wall
 3648 T:1e50  16                                 .byt 22              ; cell type $0E = map_butterfly
 3649 T:1e51                           rockford_sprite 
 3650 T:1e51  25                                 .byt 37              ; cell type $0F = map_rockford
 3651 T:1e52  0f                                 .byt 15              ; cell type $10 = map_space | map_anim_state1
 3652 T:1e53  0f                                 .byt 15              ; cell type $11 = map_earth | map_anim_state1
 3653 T:1e54  0f                                 .byt 15              ; cell type $12 = map_wall | map_anim_state1
 3654 T:1e55  0f                                 .byt 15              ; cell type $13 = map_large_explosion_state1
 3655 T:1e56  24                                 .byt 36              ; cell type $14 = map_diamond | map_anim_state1
 3656 T:1e57  02                                 .byt 2              ; cell type $15 = map_rock | map_anim_state1
 3657 T:1e58  1c                                 .byt 28              ; cell type $16 = map_firefly | map_anim_state1
 3658 T:1e59  14                                 .byt 20              ; cell type $17 = map_amoeba | map_anim_state1
 3659 T:1e5a  09                                 .byt 9              ; cell type $18 = map_active_exit
 3660 T:1e5b  14                                 .byt 20              ; cell type $19 = map_slime | map_anim_state1
 3661 T:1e5c  1c                                 .byt 28              ; cell type $1A = map_explosion | map_anim_state1
 3662 T:1e5d  33                                 .byt 51              ; cell type $1B = map_bomb | map_anim_state1
 3663 T:1e5e  10                                 .byt 16              ; cell type $1C = map_growing_wall | map_anim_state1
 3664 T:1e5f  10                                 .byt 16              ; cell type $1D = map_magic_wall | map_anim_state1
 3665 T:1e60  16                                 .byt 22              ; cell type $1E = map_butterfly | map_anim_state1
 3666 T:1e61  2c                                 .byt 44              ; cell type $1F = map_rockford | map_anim_state1
 3667 T:1e62  0e                                 .byt 14              ; cell type $20 = map_space | map_anim_state2
 3668 T:1e63  0e                                 .byt 14              ; cell type $21 = map_earth | map_anim_state2
 3669 T:1e64  0e                                 .byt 14              ; cell type $22 = map_wall | map_anim_state2
 3670 T:1e65  0e                                 .byt 14              ; cell type $23 = map_large_explosion_state2
 3671 T:1e66  04                                 .byt 4              ; cell type $24 = map_diamond | map_anim_state2
 3672 T:1e67  36                                 .byt 54              ; cell type $25 = map_rock | map_anim_state2
 3673 T:1e68  1c                                 .byt 28              ; cell type $26 = map_firefly | map_anim_state2
 3674 T:1e69  15                                 .byt 21              ; cell type $27 = map_amoeba | map_anim_state2
 3675 T:1e6a  1a                                 .byt 26              ; cell type $28 = map_rockford_appearing_or_end_position | map_anim_state2
 3676 T:1e6b  15                                 .byt 21              ; cell type $29 = map_slime | map_anim_state2
 3677 T:1e6c  46                                 .byt $46              ; cell type $2A = map_explosion | map_anim_state2
 3678 T:1e6d  34                                 .byt 52              ; cell type $2B = map_bomb | map_anim_state2
 3679 T:1e6e  10                                 .byt 16              ; cell type $2C = map_growing_wall | map_anim_state2
 3680 T:1e6f  0b                                 .byt 11              ;dup                                                                  ; cell type $2D = map_magic_wall | map_anim_state2
 3681 T:1e70  16                                 .byt 22              ; cell type $2E = map_butterfly | map_anim_state2
 3682 T:1e71  31                                 .byt 49              ; cell type $2F = map_rockford | map_anim_state2
 3683 T:1e72  0d                                 .byt 13              ; cell type $30 = map_space | map_anim_state3
 3684 T:1e73  0d                                 .byt 13              ; cell type $31 = map_earth | map_anim_state3
 3685 T:1e74  0d                                 .byt 13              ; cell type $32 = map_wall | map_anim_state3
 3686 T:1e75  0d                                 .byt 13              ; cell type $33 = map_large_explosion_state3
 3687 T:1e76  04                                 .byt 4              ; cell type $34 = map_diamond | map_anim_state3
 3688 T:1e77  01                                 .byt 1              ; cell type $35 = map_rock | map_anim_state3
 3689 T:1e78  1c                                 .byt 28              ; cell type $36 = map_firefly | map_anim_state3
 3690 T:1e79  15                                 .byt 21              ; cell type $37 = map_amoeba | map_anim_state3
 3691 T:1e7a  1a                                 .byt 26              ; cell type $38 = map_rockford_appearing_or_end_position | map_anim_state3
 3692 T:1e7b  15                                 .byt 21              ; cell type $39 = map_slime | map_anim_state3
 3693 T:1e7c  1c                                 .byt 28              ; cell type $3A = map_explosion | map_anim_state3
 3694 T:1e7d  35                                 .byt 53              ; cell type $3B = map_bomb | map_anim_state3
 3695 T:1e7e  10                                 .byt 16              ; cell type $3C = map_growing_wall | map_anim_state3
 3696 T:1e7f  0b                                 .byt 11              ;dup                                                                  ; cell type $3D = map_magic_wall | map_anim_state3
 3697 T:1e80  16                                 .byt 22              ; cell type $3E = map_butterfly | map_anim_state3
 3698 T:1e81  28                                 .byt 40              ; cell type $3F = map_rockford | map_anim_state3
 3699 T:1e82  0c                                 .byt 12              ; cell type $40 = map_space | map_anim_state4
 3700 T:1e83  0c                                 .byt 12              ; cell type $41 = map_earth | map_anim_state4
 3701 T:1e84  0c                                 .byt 12              ; cell type $42 = map_wall | map_anim_state4
 3702 T:1e85  0c                                 .byt 12              ; cell type $43 = map_titanium_wall | map_anim_state4
 3703 T:1e86  03                                 .byt 3              ; cell type $44 = map_diamond | map_anim_state4
 3704 T:1e87  01                                 .byt 1              ; cell type $45 = map_rock | map_anim_state4
 3705 T:1e88  0c                                 .byt 12              ; cell type $46 = map_start_large_explosion
 3706 T:1e89                           amoeba_animated_sprite4 
 3707 T:1e89  15                                 .byt 21              ; cell type $47 = map_amoeba | map_anim_state4
 3708 T:1e8a  31                                 .byt 49              ; cell type $48 = map_rockford_appearing_or_end_position | map_anim_state4
 3709 T:1e8b                           slime_animated_sprite1 
 3710 T:1e8b  15                                 .byt 21              ; cell type $49 = map_slime | map_anim_state4
 3711 T:1e8c  1c                                 .byt 28              ; cell type $4A = map_explosion | map_anim_state4
 3712 T:1e8d  32                                 .byt 50              ; cell type $4B = map_bomb | map_anim_state4
 3713 T:1e8e  10                                 .byt 16              ; cell type $4D = map_growing_wall | map_anim_state4
 3714 T:1e8f  01                                 .byt 1              ; cell type $4C = map_magic_wall | map_anim_state4
 3715 T:1e90  17                                 .byt 23              ; cell type $4E = map_butterfly | map_anim_state4
 3716 T:1e91  30                                 .byt 48              ; cell type $4F = map_rockford | map_anim_state4
 3717 T:1e92  0d                                 .byt 13              ; cell type $50 = map_space | map_anim_state5
 3718 T:1e93  0d                                 .byt 13              ; cell type $51 = map_earth | map_anim_state5
 3719 T:1e94  0d                                 .byt 13              ; cell type $52 = map_wall | map_anim_state5
 3720 T:1e95  0d                                 .byt 13              ; cell type $53 = map_titanium_wall | map_anim_state5
 3721 T:1e96  24                                 .byt 36              ; cell type $54 = map_diamond | map_anim_state5
 3722 T:1e97  01                                 .byt 1              ; cell type $55 = map_rock | map_anim_state5
 3723 T:1e98  1a                                 .byt 26              ; cell type $56 = map_firefly | map_anim_state5
 3724 T:1e99  14                                 .byt 20              ; cell type $57 = map_amoeba | map_anim_state5
 3725 T:1e9a  31                                 .byt 49              ; cell type $58 = map_rockford_appearing_or_end_position | map_anim_state5
 3726 T:1e9b  14                                 .byt 20              ; cell type $59 = map_slime | map_anim_state5
 3727 T:1e9c  1c                                 .byt 28              ; cell type $5A = map_explosion | map_anim_state5
 3728 T:1e9d  33                                 .byt 51              ; cell type $5B = map_bomb | map_anim_state5
 3729 T:1e9e  10                                 .byt 16              ; cell type $5C = map_growing_wall | map_anim_state5
 3730 T:1e9f  11                                 .byt 17              ; cell type $5D = map_magic_wall | map_anim_state5
 3731 T:1ea0  17                                 .byt 23              ; cell type $5E = map_butterfly | map_anim_state5
 3732 T:1ea1  2b                                 .byt 43              ; cell type $5F = map_rockford | map_anim_state5
 3733 T:1ea2  0e                                 .byt 14              ; cell type $60 = map_space | map_anim_state6
 3734 T:1ea3  0e                                 .byt 14              ; cell type $61 = map_earth | map_anim_state6
 3735 T:1ea4  0e                                 .byt 14              ; cell type $62 = map_wall | map_anim_state6
 3736 T:1ea5  0e                                 .byt 14              ; cell type $63 = map_titanium_wall | map_anim_state6
 3737 T:1ea6  03                                 .byt 3              ; cell type $64 = map_diamond | map_anim_state6
 3738 T:1ea7  01                                 .byt 1              ; cell type $65 = map_rock | map_anim_state6
 3739 T:1ea8  1a                                 .byt 26              ; cell type $66 = map_firefly | map_anim_state6
 3740 T:1ea9  14                                 .byt 20              ; cell type $67 = map_amoeba | map_anim_state6
 3741 T:1eaa  31                                 .byt 49              ; cell type $68 = map_rockford_appearing_or_end_position | map_anim_state6
 3742 T:1eab  14                                 .byt 20              ; cell type $69 = map_slime | map_anim_state6
 3743 T:1eac  1c                                 .byt 28              ; cell type $6A = map_explosion | map_anim_state6
 3744 T:1ead  34                                 .byt 52              ; cell type $6B = map_bomb | map_anim_state6
 3745 T:1eae  10                                 .byt 16              ; cell type $6C = map_growing_wall | map_anim_state6
 3746 T:1eaf  0d                                 .byt 13              ; cell type $6D = map_magic_wall | map_anim_state6
 3747 T:1eb0  17                                 .byt 23              ; cell type $6E = map_butterfly | map_anim_state6
 3748 T:1eb1  28                                 .byt 40              ; cell type $6F = map_rockford | map_anim_state6
 3749 T:1eb2  0f                                 .byt 15              ; cell type $70 = map_space | map_anim_state7
 3750 T:1eb3  0f                                 .byt 15              ; cell type $71 = map_earth | map_anim_state7
 3751 T:1eb4  0f                                 .byt 15              ; cell type $72 = map_wall | map_anim_state7
 3752 T:1eb5  0f                                 .byt 15              ; cell type $73 = map_titanium_wall | map_anim_state7
 3753 T:1eb6  03                                 .byt 3              ; cell type $74 = map_diamond | map_anim_state7
 3754 T:1eb7  01                                 .byt 1              ; cell type $75 = map_rock | map_anim_state7
 3755 T:1eb8  1a                                 .byt 26              ; cell type $76 = map_firefly | map_anim_state7
 3756 T:1eb9  15                                 .byt 21              ; cell type $77 = map_amoeba | map_anim_state7
 3757 T:1eba  31                                 .byt 49              ; cell type $78 = map_rockford_appearing_or_end_position | map_anim_state7
 3758 T:1ebb  15                                 .byt 21              ; cell type $79 = map_slime | map_anim_state7
 3759 T:1ebc  1c                                 .byt 28              ; cell type $7A = map_explosion | map_anim_state7
 3760 T:1ebd  35                                 .byt 53              ; cell type $7B = map_bomb | map_anim_state7
 3761 T:1ebe  10                                 .byt 16              ; cell type $7C = map_growing_wall | map_anim_state7
 3762 T:1ebf  0c                                 .byt 12              ; cell type $7D = map_magic_wall | map_anim_state7
 3763 T:1ec0  17                                 .byt 23              ; cell type $7E = map_butterfly | map_anim_state7
 3764 T:1ec1  0c                                 .byt 12              ; cell type $7F = map_rockford | map_anim_state7

 3766 T:1ec2                                    ; *************************************************************************************
 3767 T:1ec2                                    ; Cell types that animate every tick
 3768 T:1ec2                                    ; These values are pointers into the cell_type_to_sprite table
 3769 T:1ec2                                    ;
 3770 T:1ec2                           cell_types_that_always_animate 
 3771 T:1ec2  04                                 .byt 4
 3772 T:1ec3  44                                 .byt 64|4
 3773 T:1ec4  06                                 .byt 6
 3774 T:1ec5  16                                 .byt 16|6
 3775 T:1ec6  26                                 .byt 32|6
 3776 T:1ec7  36                                 .byt 48|6
 3777 T:1ec8                           exit_cell_type 
 3778 T:1ec8  18                                 .byt 24
 3779 T:1ec9  1d                                 .byt 16|13
 3780 T:1eca  0e                                 .byt 14
 3781 T:1ecb  1e                                 .byt 16|14
 3782 T:1ecc  2e                                 .byt 32|14
 3783 T:1ecd  3e                                 .byt 48|14
 3784 T:1ece  2f                                 .byt 32|15
 3785 T:1ecf  1f                                 .byt 16|15
 3786 T:1ed0  09                                 .byt 9

 3788 T:1ed1                                    ; *************************************************************************************
 3789 T:1ed1                                    ; For animation, points to next sprite to use
 3790 T:1ed1                                    ;
 3791 T:1ed1                           sprite_to_next_sprite 
 3792 T:1ed1  00 00 00                           .byt 0,0,0
 3793 T:1ed4  04 05 06 03                        .byt 4,5,6,3
 3794 T:1ed8  00                                 .byt 0
 3795 T:1ed9  09 08                              .byt 9,8        ;dup
 3796 T:1edb  00 00                              .byt 0,0
 3797 T:1edd  0c 0d 0e                           .byt 12,13,14
 3798 T:1ee0  00                                 .byt 0
 3799 T:1ee1  11 12 13 10                        .byt 17,18,19,16
 3800 T:1ee5  14 15                              .byt 20,21
 3801 T:1ee7  17 18 16                           .byt 23,24,22
 3802 T:1eea  1a 1b 1c 19                        .byt 26,27,28,25
 3803 T:1eee  00 00 00 00 00 00 00 ...           .byt 0,0,0,0,0,0,0,0,0,0,0,0,0
 3804 T:1efb  2b 2c 2d 2a                        .byt 43,44,45,42
 3805 T:1eff  2f 30 31 2e                        .byt 47,48,49,46
 3806 T:1f03  32 32 03 32 32 0a 3a ...           .byt $32,$32,3,$32,$32,$0a,$3a,$34,$34,0,$32,$32,$32,0,$39,$39
 3807 T:1f13  38 36 39 38 00 00 00 ...           .byt $38,$36,$39,$38,0,0,0,0,0,0,0,$33,$3f,0,$35,0
 3808 T:1f23  00 00 00 00 00 3e 33 ...           .byt 0,0,0,0,0,$3e,$33,0,$5a,$5b,$5c,$5d,$5e,$5f,7,$0a
 3809 T:1f33  16 64 2a 66 2e 09 1e ...           .byt $16,$64,$2a,$66,$2e,9,$1e,$69,$6a,$6b,$6c,$6d,$6e,$6f,$70,$71
 3810 T:1f43  72 73 74 75 76 77 78 ...           .byt $72,$73,$74,$75,$76,$77,$78,$79,$7a,$7b,$7c,$7d,$7e,$7f

 3812 T:1f51                                    ; *************************************************************************************
 3813 T:1f51                                    ; Butterfly/firefly animation table
 3814 T:1f51                                    ;
 3815 T:1f51                           firefly_and_butterfly_cell_values 
 3816 T:1f51  b6                                 .byt (128|48)|6
 3817 T:1f52  be                                 .byt (128|48)|14
 3818 T:1f53  86                                 .byt (128|0)|6
 3819 T:1f54  8e                                 .byt (128|0)|14
 3820 T:1f55  96                                 .byt (128|16)|6
 3821 T:1f56  9e                                 .byt (128|16)|14
 3822 T:1f57  a6                                 .byt (128|32)|6
 3823 T:1f58  ae                                 .byt (128|32)|14

 3825 T:1f59                                    ; *************************************************************************************
 3826 T:1f59                                    ; Sprites to use for idle animation of rockford. They are encoded into the nybbles of
 3827 T:1f59                                    ; each byte. First it cycles through the bottom nybbles until near the end of the idle
 3828 T:1f59                                    ; animation, then cycles through through the top nybbles
 3829 T:1f59                                    ;
 3830 T:1f59                           idle_animation_data 
 3831 T:1f59  80                                 .byt 16*(40-32)+32-32
 3832 T:1f5a  70                                 .byt 16*(39-32)+32-32
 3833 T:1f5b  60                                 .byt 16*(38-32)+32-32
 3834 T:1f5c  70                                 .byt 16*(39-32)+32-32
 3835 T:1f5d  81                                 .byt 16*(40-32)+33-32
 3836 T:1f5e  52                                 .byt 16*(37-32)+34-32
 3837 T:1f5f  61                                 .byt 16*(38-32)+33-32
 3838 T:1f60  50                                 .byt 16*(37-32)+32-32
 3839 T:1f61  70                                 .byt 16*(39-32)+32-32
 3840 T:1f62  90                                 .byt 16*(41-32)+32-32
 3841 T:1f63  92                                 .byt 16*(41-32)+34-32
 3842 T:1f64  70                                 .byt 16*(39-32)+32-32
 3843 T:1f65  52                                 .byt 16*(37-32)+34-32
 3844 T:1f66  00                                 .byt 16*(32-32)+32-32
 3845 T:1f67  00                                 .byt 16*(32-32)+32-32
 3846 T:1f68  00                                 .byt 16*(32-32)+32-32
 3847 T:1f69  11                                 .byt 16*(33-32)+33-32
 3848 T:1f6a  22                                 .byt 16*(34-32)+34-32
 3849 T:1f6b  11                                 .byt 16*(33-32)+33-32
 3850 T:1f6c  00                                 .byt 16*(32-32)+32-32
 3851 T:1f6d  00                                 .byt 16*(32-32)+32-32
 3852 T:1f6e  01                                 .byt 16*(32-32)+33-32
 3853 T:1f6f  09                                 .byt 16*(32-32)+41-32
 3854 T:1f70  27                                 .byt 16*(34-32)+39-32
 3855 T:1f71  05                                 .byt 16*(32-32)+37-32
 3856 T:1f72  05                                 .byt 16*(32-32)+37-32
 3857 T:1f73  25                                 .byt 16*(34-32)+37-32
 3858 T:1f74  05                                 .byt 16*(32-32)+37-32
 3859 T:1f75  55                                 .byt 16*(37-32)+37-32
 3860 T:1f76  79                                 .byt 16*(39-32)+41-32
 3861 T:1f77  95                                 .byt 16*(41-32)+37-32
 3862 T:1f78  75                                 .byt 16*(39-32)+37-32
 3863 T:1f79  55                                 .byt 16*(37-32)+37-32
 3864 T:1f7a  28                                 .byt 16*(34-32)+40-32
 3865 T:1f7b  05                                 .byt 16*(32-32)+37-32
 3866 T:1f7c  06                                 .byt 16*(32-32)+38-32
 3867 T:1f7d  27                                 .byt 16*(34-32)+39-32
 3868 T:1f7e  05                                 .byt 16*(32-32)+37-32
 3869 T:1f7f  25                                 .byt 16*(34-32)+37-32
 3870 T:1f80  55                                 .byt 16*(37-32)+37-32
 3871 T:1f81  55                                 .byt 16*(37-32)+37-32
 3872 T:1f82  59                                 .byt 16*(37-32)+41-32
 3873 T:1f83  55                                 .byt 16*(37-32)+37-32
 3874 T:1f84  65                                 .byt 16*(38-32)+37-32
 3875 T:1f85  91                                 .byt 16*(41-32)+33-32
 3876 T:1f86  62                                 .byt 16*(38-32)+34-32
 3877 T:1f87  91                                 .byt 16*(41-32)+33-32
 3878 T:1f88  60                                 .byt 16*(38-32)+32-32
 3879 T:1f89  70                                 .byt 16*(39-32)+32-32
 3880 T:1f8a  25                                 .byt 16*(34-32)+37-32
 3881 T:1f8b  16                                 .byt 16*(33-32)+38-32
 3882 T:1f8c  19                                 .byt 16*(33-32)+41-32
 3883 T:1f8d  08                                 .byt 16*(32-32)+40-32
 3884 T:1f8e  09                                 .byt 16*(32-32)+41-32
 3885 T:1f8f  06                                 .byt 16*(32-32)+38-32
 3886 T:1f90  05                                 .byt 16*(32-32)+37-32
 3887 T:1f91  06                                 .byt 16*(32-32)+38-32
 3888 T:1f92  05                                 .byt 16*(32-32)+37-32
 3889 T:1f93  36                                 .byt 16*(35-32)+38-32
 3890 T:1f94  45                                 .byt 16*(36-32)+37-32
 3891 T:1f95  48                                 .byt 16*(36-32)+40-32
 3892 T:1f96  47                                 .byt 16*(36-32)+39-32
 3893 T:1f97  36                                 .byt 16*(35-32)+38-32
 3894 T:1f98  35                                 .byt 16*(35-32)+37-32

 3896 T:1f99                                    ; *************************************************************************************
 3897 T:1f99                                    ; Determines what the end of an explosion turns into 
 3898 T:1f99                                    ; Also see handler_basics
 3899 T:1f99                                    ;
 3900 T:1f99                           explosion_replacements 
 3901 T:1f99  8f                                 .byt 15|128
 3902 T:1f9a  8f                                 .byt 15|128
 3903 T:1f9b  84                                 .byt 4|128
 3904 T:1f9c  00                                 .byt 0

 3906 T:1f9d                                    ; *************************************************************************************
 3907 T:1f9d                                    ; Given a cell type, decide what Rockford is allowed to do
 3908 T:1f9d                                    ;   $ff means Rockford can move onto the cell freely (e.g. space, earth),
 3909 T:1f9d                                    ;   $0 means no movement possible (e.g. wall), and
 3910 T:1f9d                                    ;   $1 means move with a push (e.g rock)
 3911 T:1f9d                                    ;
 3912 T:1f9d                           obstacle_control 
 3913 T:1f9d  ff                                 .byt $ff              ; map_space
 3914 T:1f9e  ff                                 .byt $ff              ; map_earth
 3915 T:1f9f  00                                 .byt 0              ; map_wall
 3916 T:1fa0  00                                 .byt 0              ; map_titanium_wall
 3917 T:1fa1  ff                                 .byt $ff              ; map_diamond
 3918 T:1fa2  01                                 .byt 1              ; map_rock
 3919 T:1fa3  00                                 .byt 0              ; map_firefly
 3920 T:1fa4  00                                 .byt 0              ; map_amoeba
 3921 T:1fa5  00                                 .byt 0              ; map_rockford_appearing_or_end_position
 3922 T:1fa6  00                                 .byt 0              ; map_slime
 3923 T:1fa7  ff                                 .byt $ff              ; map_explosion
 3924 T:1fa8  00                                 .byt 0              ; map_bomb
 3925 T:1fa9  00                                 .byt 0              ; map_growing_wall
 3926 T:1faa  00                                 .byt 0              ; map_magic_wall
 3927 T:1fab  00                                 .byt 0              ; map_butterfly
 3928 T:1fac  01                                 .byt 1              ; map_rockford

 3930 T:1fad                                    ; *************************************************************************************
 3931 T:1fad                                    ; Given a cell type, decide if a rock/diamond will fall off them
 3932 T:1fad                                    ;   0 = rock/diamond won't fall
 3933 T:1fad                                    ;   1 = rock/diamond will slip off the cell (where this is space to do so)
 3934 T:1fad                                    ;
 3935 T:1fad                           cell_types_that_rocks_or_diamonds_will_fall_off 
 3936 T:1fad  00                                 .byt 0              ; map_space
 3937 T:1fae  00                                 .byt 0              ; map_earth
 3938 T:1faf  01                                 .byt 1              ; map_wall
 3939 T:1fb0  00                                 .byt 0              ; map_titanium_wall
 3940 T:1fb1  01                                 .byt 1              ; map_diamond
 3941 T:1fb2  01                                 .byt 1              ; map_rock
 3942 T:1fb3  00                                 .byt 0              ; map_firefly
 3943 T:1fb4  01                                 .byt 1              ; map_amoeba
 3944 T:1fb5  00                                 .byt 0              ; map_rockford_appearing_or_end_position
 3945 T:1fb6  00                                 .byt 0              ; map_slime
 3946 T:1fb7  00                                 .byt 0              ; map_explosion
 3947 T:1fb8  00                                 .byt 0              ; map_bomb
 3948 T:1fb9  01                                 .byt 1              ; map_growing_wall
 3949 T:1fba  00                                 .byt 0              ; map_magic_wall
 3950 T:1fbb  00                                 .byt 0              ; map_butterfly
 3951 T:1fbc  00                                 .byt 0              ; map_rockford

 3953 T:1fbd                                    ; *************************************************************************************
 3954 T:1fbd                                    ; Given a cell type, decide what it turns into when a rock/diamond falls onto it
 3955 T:1fbd                                    ; 
 3956 T:1fbd                           update_cell_type_when_below_a_falling_rock_or_diamond 
 3957 T:1fbd  00                                 .byt 0              ; map_space
 3958 T:1fbe  00                                 .byt 0              ; map_earth
 3959 T:1fbf  00                                 .byt 0              ; map_wall
 3960 T:1fc0  00                                 .byt 0              ; map_titanium_wall
 3961 T:1fc1  00                                 .byt 0              ; map_diamond
 3962 T:1fc2  00                                 .byt 0              ; map_rock
 3963 T:1fc3  46                                 .byt 70              ; map_firefly
 3964 T:1fc4  00                                 .byt 0              ; map_amoeba
 3965 T:1fc5  00                                 .byt 0              ; map_rockford_appearing_or_end_position
 3966 T:1fc6  00                                 .byt 0              ; map_slime
 3967 T:1fc7  00                                 .byt 0              ; map_explosion
 3968 T:1fc8  46                                 .byt 70              ; map_bomb
 3969 T:1fc9  00                                 .byt 0              ; map_growing_wall
 3970 T:1fca  3d                                 .byt 48|13        ; map_magic_wall
 3971 T:1fcb  4e                                 .byt 64|14        ; map_butterfly
 3972 T:1fcc  7f                                 .byt 112|15        ; map_rockford

 3974 T:1fcd                                    ; *************************************************************************************
 3975 T:1fcd                                    ; Given a cell type, decide what it turns into when affected by an explosion
 3976 T:1fcd                                    ;   0 = not affected
 3977 T:1fcd                                    ;   $ff = Rockford dies
 3978 T:1fcd                                    ; The self-mod code using lookup_table_address_low needs this (see show_large_explosion)
 3979 T:1fcd  00 ff 00 01 00 64 02 ...           .dsb 256-(*&255)    ;Add another page of bytes

 3981 T:2000                           cell_types_that_will_turn_into_large_explosion 
 3982 T:2000  b3                                 .byt 128|51        ; map_space
 3983 T:2001  b3                                 .byt 128|51        ; map_earth
 3984 T:2002  b3                                 .byt 128|51        ; map_wall
 3985 T:2003  00                                 .byt 0              ; map_titanium_wall
 3986 T:2004  b3                                 .byt 128|51        ; map_diamond
 3987 T:2005  b3                                 .byt 128|51        ; map_rock
 3988 T:2006  b3                                 .byt 128|51        ; map_firefly
 3989 T:2007  b3                                 .byt 128|51        ; map_amoeba
 3990 T:2008  00                                 .byt 0              ; map_rockford_appearing_or_end_position
 3991 T:2009  b3                                 .byt 128|51        ; map_slime
 3992 T:200a  00                                 .byt 0              ; map_explosion
 3993 T:200b  b3                                 .byt 128|51        ; map_bomb
 3994 T:200c  b3                                 .byt 128|51        ; map_growing_wall
 3995 T:200d  b3                                 .byt 128|51        ; map_magic_wall
 3996 T:200e  b3                                 .byt 128|51        ; map_butterfly
 3997 T:200f  ff                                 .byt $ff              ; map_rockford

 3999 T:2010                                    ; *************************************************************************************
 4000 T:2010                                    ; Given a cell type, decide what it turns into when affected by an explosion into diamonds
 4001 T:2010                                    ;   0 = not affected
 4002 T:2010                                    ;   $ff = Rockford dies
 4003 T:2010                                    ;
 4004 T:2010                           cell_types_that_will_turn_into_diamonds 
 4005 T:2010  84                                 .byt 128|4        ; map_space
 4006 T:2011  84                                 .byt 128|4        ; map_earth
 4007 T:2012  84                                 .byt 128|4        ; map_wall
 4008 T:2013  00                                 .byt 0              ; map_titanium_wall
 4009 T:2014  84                                 .byt 128|4        ; map_diamond
 4010 T:2015  84                                 .byt 128|4        ; map_rock
 4011 T:2016  84                                 .byt 128|4        ; map_firefly
 4012 T:2017  84                                 .byt 128|4        ; map_amoeba
 4013 T:2018  00                                 .byt 0              ; map_rockford_appearing_or_end_position
 4014 T:2019  84                                 .byt 128|4        ; map_slime
 4015 T:201a  00                                 .byt 0              ; map_explosion
 4016 T:201b  00                                 .byt 0              ; map_bomb
 4017 T:201c  84                                 .byt 128|4        ; map_growing_wall
 4018 T:201d  84                                 .byt 128|4        ; map_magic_wall
 4019 T:201e  84                                 .byt 128|4        ; map_butterfly
 4020 T:201f  ff                                 .byt $ff              ; map_rockford

 4022 T:2020                                    ; *************************************************************************************
 4023 T:2020                                    ; Given a cell type, decide what it turns into when processed by the magic wall
 4024 T:2020                                    ; This just affects rocks/diamonds (rocks become diamonds and visa versa)
 4025 T:2020                                    ;
 4026 T:2020                           items_produced_by_the_magic_wall 
 4027 T:2020  00                                 .byt 0              ; map_space
 4028 T:2021  00                                 .byt 0              ; map_earth
 4029 T:2022  00                                 .byt 0              ; map_wall
 4030 T:2023  00                                 .byt 0              ; map_titanium_wall
 4031 T:2024  85                                 .byt 128|5        ; map_diamond
 4032 T:2025  84                                 .byt 128|4        ; map_rock
 4033 T:2026  00                                 .byt 0              ; map_firefly
 4034 T:2027  00                                 .byt 0              ; map_amoeba
 4035 T:2028  00                                 .byt 0              ; map_rockford_appearing_or_end_position
 4036 T:2029  00                                 .byt 0              ; map_slime
 4037 T:202a  00                                 .byt 0              ; map_explosion
 4038 T:202b  00                                 .byt 0              ; map_bomb
 4039 T:202c  00                                 .byt 0              ; map_growing_wall
 4040 T:202d  00                                 .byt 0              ; map_magic_wall
 4041 T:202e  00                                 .byt 0              ; map_butterfly
 4042 T:202f  00                                 .byt 0              ; map_rockford

 4044 T:2030                                    ; *************************************************************************************
 4045 T:2030                                    ; Given a cell type, decide what happens when landing on slime
 4046 T:2030                                    ; Only rocks/diamonds/bombs are allowed through, they don't change
 4047 T:2030                                    ;
 4048 T:2030                           items_allowed_through_slime 
 4049 T:2030  00                                 .byt 0              ; map_space
 4050 T:2031  00                                 .byt 0              ; map_earth
 4051 T:2032  00                                 .byt 0              ; map_wall
 4052 T:2033  00                                 .byt 0              ; map_titanium_wall
 4053 T:2034  84                                 .byt 128|4        ; map_diamond
 4054 T:2035  85                                 .byt 128|5        ; map_rock
 4055 T:2036  00                                 .byt 0              ; map_firefly
 4056 T:2037  00                                 .byt 0              ; map_amoeba
 4057 T:2038  00                                 .byt 0              ; map_rockford_appearing_or_end_position
 4058 T:2039  00                                 .byt 0              ; map_slime
 4059 T:203a  00                                 .byt 0              ; map_explosion
 4060 T:203b  8b                                 .byt 128|11        ; map_bomb
 4061 T:203c  00                                 .byt 0              ; map_growing_wall
 4062 T:203d  00                                 .byt 0              ; map_magic_wall
 4063 T:203e  00                                 .byt 0              ; map_butterfly
 4064 T:203f  00                                 .byt 0              ; map_rockford

 4066 T:2040                                    ; *************************************************************************************
 4067 T:2040                                    ; Direction handling
 4068 T:2040                                    ;
 4069 T:2040                           rock_push_directions                  ;direction pointer to cell beyond the rock being pushed
 4070 T:2040  43 3f 00 c1                        .byt $43,$3f,0,$c1;right, left, up, down. Up can change in game when gravity is on/off

 4072 T:2044                           rockford_cell_value_for_direction 
 4073 T:2044  af                                 .byt 128|32|15  ;animation for left
 4074 T:2045  9f                                 .byt 128|16|15  ;animation for right
 4075 T:2046  00 00                              .byt 0,0        ;no animation for up/down - remain as normal Rockford

 4077 T:2048                           map_offset_for_direction                  ;direction pointer to cells next to Rockford (in $41)
 4078 T:2048  42 40 01 81                        .byt $42,$40,1,$81;right, left, up, down

 4080 T:204c                           neighbour_cell_pointer_from_direction_index                  ;direction pointer to surrounding cell reference table (Rockford)
 4081 T:204c  05                                 .byt 5              ;points to cell_right
 4082 T:204d  03                                 .byt 3              ;points to cell_left
 4083 T:204e  01                                 .byt 1              ;points to cell_above
 4084 T:204f  07                                 .byt 7              ;points to cell_below

 4086 T:2050                           firefly_neighbour_pointers                  ;direction pointer to surrounding cell reference table (butterfly/firefly)
 4087 T:2050  03                                 .byt 3              ;points to cell_left
 4088 T:2051  05                                 .byt 5              ;points to cell_right
 4089 T:2052  01                                 .byt 1              ;points to cell_above
 4090 T:2053  01                                 .byt 1              ;points to cell_above
 4091 T:2054  05                                 .byt 5              ;points to cell_right
 4092 T:2055  03                                 .byt 3              ;points to cell_left
 4093 T:2056  07                                 .byt 7              ;points to cell_below
 4094 T:2057  07                                 .byt 7              ;points to cell_below

 4096 T:2058                           firefly_and_butterfly_next_direction_table                  ;next direction to consider (butterfly/firefly)
 4097 T:2058  02 03 04 05 06 07 00 01            .byt 2,3,4,5,6,7,0,1

 4099 T:2060                                    ; *************************************************************************************
 4100 T:2060                           cave_play_order 
 4101 T:2060  01 02 03 10                        .byt 1,2,3,16
 4102 T:2064  05 06 07 11                        .byt 5,6,7,17
 4103 T:2068  09 0a 0b 12                        .byt 9,10,11,18
 4104 T:206c  0d 0e 0f 13                        .byt 13,14,15,19
 4105 T:2070  04 08 0c 00                        .byt 4,8,12,0

 4107 T:2074                                    ; *************************************************************************************
 4108 T:2074                                    ; status bar and messages
 4109 T:2074                                    ;
 4110 T:2074                           status_bar_line1 
 4111 T:2074  07 ab ac 20 20 20 20 ...           .byt 7,"+"+128,","+128,"      ",2,"^_","             ",5,"{|",9,6,"  CAVE A1 "
 4112 T:209c                           status_bar_line2 
 4113 T:209c  07 a9 ad 09 20 20 20 ...           .byt 7,")"+128,"-"+128,9,"    ",8,2,"`a",9,"     ",3,"     ",8,5,"}~",9,"    ",6,"      "

 4115 T:20c4                           status_messages 
 4116 T:20c4                           status_message_paused 
 4117 T:20c4  09 06 20 20 20 20 50 ...           .byt 9,6,"    PAUSED      "
 4118 T:20d6                           status_message_got_all_diamonds 
 4119 T:20d6  09 02 47 4f 54 20 41 ...           .byt 9,2,"GOT ALL DIAMONDS"
 4120 T:20e8                           status_message_no_bombs_left 
 4121 T:20e8  09 03 4e 4f 20 42 4f ...           .byt 9,3,"NO BOMBS LEFT   "
 4122 T:20fa                           status_message_hurry 
 4123 T:20fa  09 03 20 20 20 20 48 ...           .byt 9,3,"    HURRY       "
 4124 T:210c                           status_message_out_of_time 
 4125 T:210c  09 01 20 4f 55 54 20 ...           .byt 9,1," OUT OF TIME    "
 4126 T:211e                           status_message_bonus_life 
 4127 T:211e  09 06 20 20 42 4f 4e ...           .byt 9,6,"  BONUS LIFE    "
 4128 T:2130                           status_message_game_over 
 4129 T:2130  09 01 20 20 47 41 4d ...           .byt 9,1,"  GAME OVER     "
 4130 T:2142                           status_message_std_keymap 
 4131 T:2142  09 02 20 53 54 41 4e ...           .byt 9,2," STANDARD KEYS  "
 4132 T:2154                           status_message_alt_keymap 
 4133 T:2154  09 02 20 41 4c 54 45 ...           .byt 9,2," ALTERNATE KEYS "

 4135 T:2166                           game_title 
 4136 T:2166  0b 01 4f 52 49 43 06 ...           .byt 11,1,"ORIC",6,"BOULDER DASH ",8,0

 4138 T:217c                           game_options 
 4139 T:217c                           options_cave_select 
 4140 T:217c  20 20 20 20 20 20 20 ...           .byt "        ","^_",9,6,"CAVE ",7,"A",6," LEFT RIGHT  ",8,7,"     "
 4141 T:21a4                           options_level_select 
 4142 T:21a4  20 20 20 20 20 20 20 ...           .byt "        ","`a",9,6,"LEVEL",7,"1",6," UP DOWN     ",8,7,"     "
 4143 T:21cc                           options_start 
 4144 T:21cc  20 20 20 20 20 20 20 ...           .byt "        ",9,2,"  PRESS SPACE TO START ",8,7,"      "

 4146 T:21f5                                    ; *************************************************************************************
 4147 T:21f5                                    ; List of sounds used in the game
 4148 T:21f5                                    ; Below is needed to point the program counter to the next page (multiple of 256)
 4149 T:21f5  00 ff 00 01 00 64 02 ...           .dsb 256-(*&255)    ;Add another page of bytes

 4151 T:2200                           list_of_sounds                  ;14 bytes + 2 padding bytes for ease of lookup
 4152 T:2200                           active_sound_offset 
 4153 T:2200                           active_sound_duration 
 4154 T:2200  00                                 .byt 0
 4155 T:2201                           active_ambient_duration 
 4156 T:2201  00                                 .byt 0
 4157 T:2202                           sound_rockford_move 
 4158 T:2202  00 00 00 00 00 00 0a ...           .byt 0,0,0,0,0,0,$0a,$77,$10,0,0,$c8,0,$0f,0,4
 4159 T:2212                           sound_got_diamond 
 4160 T:2212  64 00 00 00 00 00 00 ...           .byt $64,0,0,0,0,0,0,$7e,$10,0,0,0,7,9,0,16
 4161 T:2222                           sound_got_all_diamonds 
 4162 T:2222  00 04 64 00 00 04 00 ...           .byt 0,4,$64,0,0,4,0,$78,$10,$10,$10,0,7,9,0,16
 4163 T:2232                           sound_enter_cave 
 4164 T:2232  00 00 00 00 00 00 05 ...           .byt 0,0,0,0,0,0,5,$77,$10,0,0,0,7,9,0,16
 4165 T:2242                           sound_exit_cave 
 4166 T:2242  50 00 00 00 00 00 00 ...           .byt $50,0,0,0,0,0,0,$7e,$10,0,0,0,3,9,0,8
 4167 T:2252                           sound_rock_move 
 4168 T:2252  00 00 a0 0f 00 00 1f ...           .byt 0,0,$a0,$0f,0,0,$1f,$6d,0,$10,0,0,7,9,0,16
 4169 T:2262                           sound_diamond_move 
 4170 T:2262  00 00 30 00 00 00 00 ...           .byt 0,0,$30,0,0,0,0,$7d,0,$10,0,0,7,9,0,16
 4171 T:2272                           sound_explosion 
 4172 T:2272  00 00 00 00 00 00 1f ...           .byt 0,0,0,0,0,0,$1f,$4f,0,$10,$10,0,14,9,0,16
 4173 T:2282                           sound_amoeba_magic_wall 
 4174 T:2282  00 00 00 00 00 00 00 ...           .byt 0,0,0,0,0,0,0,$7e,16,0,0,0,7,15,0,16
 4175 T:2292                           sound_random_base 
 4176 T:2292  07 00 00 00 00 00 00 ...           .byt 7,0,0,0,0,0,0,$7e,16,0,0,0,7,9,0,8

 4178 T:22a2                                    ; *************************************************************************************
 4179 T:22a2                                    ; title screen theme tune
 4180 T:22a2                                    ; The data for each of the two channels is 256 bytes in low byte, high byte sequence
 4181 T:22a2                           theme_voice_1_pitch_low_high 
 4182 T:22a2  65 01 1c 01 ee 00 b2 ...           .byt $65,$01,$1c,$01,$ee,$00,$b2,$00,$3e,$01,$0c,$01,$ee,$00,$9f,$00
 4183 T:22b2  e1 00 c8 00 b2 00 96 ...           .byt $e1,$00,$c8,$00,$b2,$00,$96,$00,$c8,$00,$6a,$00,$bd,$00,$77,$00
 4184 T:22c2  65 01 b2 00 dd 01 3e ...           .byt $65,$01,$b2,$00,$dd,$01,$3e,$01,$91,$01,$9f,$00,$3e,$01,$91,$01
 4185 T:22d2  65 01 b2 00 dd 01 3e ...           .byt $65,$01,$b2,$00,$dd,$01,$3e,$01,$e1,$00,$59,$00,$b2,$00,$e1,$00
 4186 T:22e2  91 01 c8 00 18 02 65 ...           .byt $91,$01,$c8,$00,$18,$02,$65,$01,$fd,$00,$64,$00,$c8,$00,$fd,$00
 4187 T:22f2  dd 01 bd 00 a9 01 b2 ...           .byt $dd,$01,$bd,$00,$a9,$01,$b2,$00,$0c,$01,$0c,$01,$86,$00,$0c,$01
 4188 T:2302  b2 00 b2 00 b2 00 b2 ...           .byt $b2,$00,$b2,$00,$b2,$00,$b2,$00,$b2,$00,$b2,$00,$b2,$00,$b2,$00
 4189 T:2312  b2 00 b2 00 b2 00 b2 ...           .byt $b2,$00,$b2,$00,$b2,$00,$b2,$00,$b2,$00,$b2,$00,$b2,$00,$b2,$00
 4190 T:2322  b2 00 b2 00 b2 00 b2 ...           .byt $b2,$00,$b2,$00,$b2,$00,$b2,$00,$b2,$00,$b2,$00,$b2,$00,$b2,$00
 4191 T:2332  b2 00 b2 00 b2 00 b2 ...           .byt $b2,$00,$b2,$00,$b2,$00,$b2,$00,$c8,$00,$c8,$00,$c8,$00,$c8,$00
 4192 T:2342  b2 00 59 00 b2 00 64 ...           .byt $b2,$00,$59,$00,$b2,$00,$64,$00,$b2,$00,$6a,$00,$b2,$00,$77,$00
 4193 T:2352  c8 00 64 00 c8 00 64 ...           .byt $c8,$00,$64,$00,$c8,$00,$64,$00,$c8,$00,$86,$00,$c8,$00,$64,$00
 4194 T:2362  b2 00 b2 00 b2 00 b2 ...           .byt $b2,$00,$b2,$00,$b2,$00,$b2,$00,$b2,$00,$b2,$00,$b2,$00,$b2,$00
 4195 T:2372  b2 00 b2 00 b2 00 b2 ...           .byt $b2,$00,$b2,$00,$b2,$00,$b2,$00,$c8,$00,$c8,$00,$c8,$00,$c8,$00
 4196 T:2382  8e 00 b2 00 ee 00 1c ...           .byt $8e,$00,$b2,$00,$ee,$00,$1c,$01,$9f,$00,$c8,$00,$0c,$01,$91,$01
 4197 T:2392  8e 00 b2 00 ee 00 1c ...           .byt $8e,$00,$b2,$00,$ee,$00,$1c,$01,$9f,$00,$c8,$00,$0c,$01,$91,$01

 4199 T:23a2                           theme_voice_2_pitch_low_high 
 4200 T:23a2  cb 02 dd 01 65 01 2c ...           .byt $cb,$02,$dd,$01,$65,$01,$2c,$01,$23,$03,$a9,$01,$91,$01,$0c,$01
 4201 T:23b2  85 03 85 03 c2 01 85 ...           .byt $85,$03,$85,$03,$c2,$01,$85,$03,$91,$01,$86,$00,$7b,$01,$96,$00
 4202 T:23c2  cb 02 cb 02 cb 02 cb ...           .byt $cb,$02,$cb,$02,$cb,$02,$cb,$02,$23,$03,$23,$03,$23,$03,$23,$03
 4203 T:23d2  cb 02 cb 02 cb 02 cb ...           .byt $cb,$02,$cb,$02,$cb,$02,$cb,$02,$c2,$01,$c2,$01,$c2,$01,$c2,$01
 4204 T:23e2  23 03 23 03 23 03 23 ...           .byt $23,$03,$23,$03,$23,$03,$23,$03,$fa,$01,$fa,$01,$fa,$01,$fa,$01
 4205 T:23f2  bb 03 ee 00 bb 03 ee ...           .byt $bb,$03,$ee,$00,$bb,$03,$ee,$00,$30,$04,$30,$04,$cb,$02,$cb,$02
 4206 T:2402  cb 02 cb 02 cb 02 cb ...           .byt $cb,$02,$cb,$02,$cb,$02,$cb,$02,$65,$01,$65,$01,$cb,$02,$cb,$02
 4207 T:2412  23 03 23 03 23 03 23 ...           .byt $23,$03,$23,$03,$23,$03,$23,$03,$91,$01,$91,$01,$23,$03,$23,$03
 4208 T:2422  cb 02 8e 00 cb 02 86 ...           .byt $cb,$02,$8e,$00,$cb,$02,$86,$00,$65,$01,$8e,$00,$cb,$02,$86,$00
 4209 T:2432  23 03 8e 00 23 03 86 ...           .byt $23,$03,$8e,$00,$23,$03,$86,$00,$91,$01,$9f,$00,$23,$03,$96,$00
 4210 T:2442  cb 02 cb 02 cb 02 77 ...           .byt $cb,$02,$cb,$02,$cb,$02,$77,$00,$65,$01,$65,$01,$cb,$02,$96,$00
 4211 T:2452  23 03 23 03 23 03 23 ...           .byt $23,$03,$23,$03,$23,$03,$23,$03,$91,$01,$91,$01,$23,$03,$23,$03
 4212 T:2462  cb 02 8e 00 cb 02 86 ...           .byt $cb,$02,$8e,$00,$cb,$02,$86,$00,$65,$01,$8e,$00,$cb,$02,$86,$00
 4213 T:2472  23 03 8e 00 23 03 86 ...           .byt $23,$03,$8e,$00,$23,$03,$86,$00,$91,$01,$9f,$00,$23,$03,$96,$00
 4214 T:2482  b2 00 ee 00 1c 01 65 ...           .byt $b2,$00,$ee,$00,$1c,$01,$65,$01,$c8,$00,$0c,$01,$3e,$01,$23,$03
 4215 T:2492  77 00 8e 00 b2 00 ee ...           .byt $77,$00,$8e,$00,$b2,$00,$ee,$00,$0c,$01,$3e,$01,$91,$01,$23,$03

 4217 T:24a2                                    ; Screen sprite cache used to avoid drawing a sprite if it hasn't changed
 4218 T:24a2                                    ; The cache overwrites version data which is just used once at the start
 4219 T:24a2                           screen_cache_map 

 4221 T:24a2                           TAP_filenames 
 4222 T:24a2  42 53 50 4c 41 53 48 00            .byt "BSPLASH",0
 4223 T:24aa  53 50 52 49 54 45 53 00            .byt "SPRITES",0
 4224 T:24b2  42 31 43 41 56 45 53 00            .byt "B1CAVES",0
 4225 T:24ba  42 32 43 41 56 45 53 00            .byt "B2CAVES",0
 4226 T:24c2  42 33 43 41 56 45 53 00            .byt "B3CAVES",0
 4227 T:24ca  50 31 43 41 56 45 53 00            .byt "P1CAVES",0
 4228 T:24d2  41 31 43 41 56 45 53 00            .byt "A1CAVES",0
 4229 T:24da  41 32 43 41 56 45 53 00            .byt "A2CAVES",0
 4230 T:24e2  42 42 43 41 56 45 53 00            .byt "BBCAVES",0

 4232 T:24ea                           version_option_text 
 4233 T:24ea  0a 07 53 45 4c 45 43 ...           .byt 10,7,"SELECT VERSION"
 4234 T:24fa  00 ff 10 00 00 64 fc ...           .dsb 16
 4235 T:250a  06 42 4f 55 4c 44 45 ...           .byt 6,"BOULDER DASH 1 "
 4236 T:251a  01 42 4f 55 4c 44 45 ...           .byt 1,"BOULDER DASH 2 "
 4237 T:252a  02 42 4f 55 4c 44 45 ...           .byt 2,"BOULDER DASH 3 "
 4238 T:253a  05 42 4f 55 4c 44 45 ...           .byt 5,"BOULDER DASH +1"
 4239 T:254a  03 41 52 4e 4f 20 44 ...           .byt 3,"ARNO DASH 1    "
 4240 T:255a  04 41 52 4e 4f 20 44 ...           .byt 4,"ARNO DASH 2    "
 4241 T:256a  07 42 4f 4e 55 53 20 ...           .byt 7,"BONUS CAVES    "

 4243 T:257a                           version_selection_cycle_up 
 4244 T:257a  00 00 03 04 05 06 07 ...           .byt 0,0,3,4,5,6,7,8,2
 4245 T:2583                           version_selection_cycle_down 
 4246 T:2583  00 00 08 02 03 04 05 ...           .byt 0,0,8,2,3,4,5,6,7

 4248 T:258c                           instruction_page_low 
 4249 T:258c  00 60 c0 20                        .byt <instructions_1,<instructions_2,<instructions_3,<instructions_4
 4250 T:2590                           instruction_page_high 
 4251 T:2590  28 2c 30 35                        .byt >instructions_1,>instructions_2,>instructions_3,>instructions_4

 4253 T:2594                                    ; *************************************************************************************
 4254 T:2594                                    ; cave starting addresses
 4255 T:2594                           cave_load_address 
 4256 T:2594                           cave_addr_low 
 4257 T:2594  00 c0 80 40 00 c0 80 ...           .byt $00,$c0,$80,$40,$00,$c0,$80,$40,$00,$c0,$80,$40,$00,$c0,$80,$40,$00,$c0,$80,$40,$00
 4258 T:25a9                           cave_addr_high 

 4262 T:25a9  29 2a 2c 2e 30 31 33 ...           .byt $29,$2a,$2c,$2e,$30,$31,$33,$35,$37,$38,$3a,$3c,$3e,$3f,$41,$43,$45,$46,$48,$4a,$4c

 4265 T:25be                                    ; *************************************************************************************
 4266 T:25be                                    ; cave parameters and map for one cave
 4267 T:25be                                    ;Below is needed to point the program counter to the next page (multiple of 256)
 4268 T:25be  00 ff 00 01 00 64 02 ...           .dsb 256-(*&255)    ;Add another page of bytes

 4270 T:2600                           cave_parameter_data 
 4271 T:2600                           param_diamond_value 
 4272 T:2600  0a                                 .byt $0a              ; Diamond value
 4273 T:2601                           param_diamond_extra_value 
 4274 T:2601  0f                                 .byt $0f              ; Diamond extra value
 4275 T:2602                           param_diamonds_required 
 4276 T:2602  0c 0c 0c 0c 0c                     .byt $0c,$0c,$0c,$0c,$0c; Diamonds required for each difficulty level x5
 4277 T:2607                           param_cave_time 
 4278 T:2607  96 6e 46 28 1e                     .byt $96,$6e,$46,$28,$1e; Cave time for each difficulty level x5
 4279 T:260c                           param_amoeba_magic_wall_time 
 4280 T:260c  00                                 .byt $00              ; Amoeba or Magic Wall time
 4281 T:260d                           param_initial_fill_tile 
 4282 T:260d  01                                 .byt $01              ; Initial fill tile - usually dirt, sometimes space
 4283 T:260e                           param_random_seeds 
 4284 T:260e  0a 0b 0c 0d 0e                     .byt $0a,$0b,$0c,$0d,$0e; Random seed for pseudo-random routine for each difficulty level x5
 4285 T:2613                           param_tile_probability 
 4286 T:2613  3c 32 09 00                        .byt $3c,$32,$09,$00; Tile probability for up to four tiles / objects x4
 4287 T:2617                           param_tile_for_probability 
 4288 T:2617  00 05 04 00                        .byt $00,$05,$04,$00; Tile / object related to the probability x4
 4289 T:261b                           param_intermission 
 4290 T:261b  00                                 .byt $00              ; Intermission indicator (0 for normal cave, 1 for intermission / bonus cave)
 4291 T:261c                           param_colours 
 4292 T:261c  05 01 07                           .byt $05,$01,$07  ; Not used in the Oric game
 4293 T:261f                           param_rockford_start 
 4294 T:261f  02 03                              .byt $02,$03        ; Rockford start row and column
 4295 T:2621                           param_rockford_end 
 4296 T:2621  10 26                              .byt $10,$26        ; Rockford exit row and column
 4297 T:2623                           param_slime_permeability 
 4298 T:2623  00                                 .byt $00              ; Slime permeability
 4299 T:2624                           param_tile_for_prob_below 
 4300 T:2624  00 00 00 00                        .byt $00,$00,$00,$00; Additional tile below the one generated by pseudo-random routine
 4301 T:2628                           param_bombs                  ; For homebrew bombs element
 4302 T:2628  00                                 .byt $00              ; 0 = no bombs, otherwise number of bombs available
 4303 T:2629                           param_zero_gravity_time                  ; New feature used to control use of gravity (whether rocks/diamonds fall)
 4304 T:2629  00                                 .byt 0              ; 0 = no zero-gravity time (always gravity/normal), 1-$fe = time until gravity back on, $ff = always zero gravity
 4305 T:262a                           param_border_tile                  ; Border tile, for the standard steelwall, set to 3
 4306 T:262a  03                                 .byt $03              ; Is just applied to the top and bottom rows as the side borders are specified in the cave file
 4307 T:262b                           param_future_use 
 4308 T:262b  00 00 00 00 00                     .byt $00,$00,$00,$00,$00; For potential future use (cannot be removed)

 4310 T:2630                           cave_map_data                  ; 20 x 40 empty cave (BD1 cave A), each byte represents 2 tiles (nibble each)
 4311 T:2630  3f ff ff ff ff ff ff ...           .byt $3f,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$f3
 4312 T:2644  3f ff ff ff ff ff ff ...           .byt $3f,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$f3
 4313 T:2658  3f ff ff ff ff ff ff ...           .byt $3f,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$f3
 4314 T:266c  3f ff ff ff ff ff ff ...           .byt $3f,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$f3
 4315 T:2680  3f ff ff ff ff ff ff ...           .byt $3f,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$f3
 4316 T:2694  3f ff ff ff ff 60 00 ...           .byt $3f,$ff,$ff,$ff,$ff,$60,$00,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$f3
 4317 T:26a8  32 22 22 22 22 22 22 ...           .byt $32,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$2f,$ff,$ff,$ff,$f3
 4318 T:26bc  3f ff ff ff ff ff ff ...           .byt $3f,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$f3
 4319 T:26d0  3f ff ff ff ff ff ff ...           .byt $3f,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$f3
 4320 T:26e4  3f ff ff ff ff ff ff ...           .byt $3f,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$f3
 4321 T:26f8  3f ff ff ff ff ff ff ...           .byt $3f,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$f3
 4322 T:270c  3f ff ff ff ff ff ff ...           .byt $3f,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$1f,$ff,$ff,$ff,$ff,$f3
 4323 T:2720  3f ff ff ff ff ff ff ...           .byt $3f,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$f3
 4324 T:2734  3f ff ff ff f2 22 22 ...           .byt $3f,$ff,$ff,$ff,$f2,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$22,$23
 4325 T:2748  3f ff ff ff ff ff ff ...           .byt $3f,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$f3
 4326 T:275c  3f ff ff ff ff ff ff ...           .byt $3f,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$03
 4327 T:2770  3f ff ff ff ff ff ff ...           .byt $3f,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$f3
 4328 T:2784  3f ff ff ff ff ff ff ...           .byt $3f,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$f3
 4329 T:2798  3f ff ff ff ff ff ff ...           .byt $3f,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$f3
 4330 T:27ac  3f ff ff ff ff ff ff ...           .byt $3f,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$f3

 4332 T:27c0                                    ; *************************************************************************************
 4333 T:27c0                                    ; all caves A to T with the Z intro cave on the end are loaded into memory from this point onwards
 4334 T:27c0                                    ; each cave is 448 bytes (48 parameters, 400 map) x 21 caves = 9408 bytes
 4335 T:27c0                                    ;Below is needed to point the program counter to the next page (multiple of 256)
 4336 T:27c0  00 ff 00 01 00 64 02 ...           .dsb 256-(*&255)    ;Add another page of bytes
 4337 T:2800                           all_caves_load_area                  ;This address needs to be cave_load_address (high-low)

 4339 T:2800                                    ; Instructions are held in the cave load area but overwitten after use when version caves are loaded

 4341 T:2800                           instructions_1 
 4342 T:2800  09 06 20 20 20 20 20 ...           .byt 9,6,"      BOULDER DASH INSTRUCTIONS       "
 4343 T:2828  20 ff 28 00 00 64 2c ...           .dsb 40," "
 4344 T:2850  09 07 52 4f 43 4b 46 ...           .byt 9,7,"ROCKFORD MUST GATHER ALL DIAMONDS     "
 4345 T:2878  09 07 4e 45 45 44 45 ...           .byt 9,7,"NEEDED TO COMPLETE EACH CAVE AND      "
 4346 T:28a0  09 07 52 45 41 43 48 ...           .byt 9,7,"REACH THE EXIT BEFORE TIME RUNS OUT   "
 4347 T:28c8  20 ff 28 00 00 64 2c ...           .dsb 40," "
 4348 T:28f0  08 03 20 20 20 20 20 ...           .byt 8,3,"       ^_  ",7,"+"+128,","+128,"  ","+"+128,","+128,"  ","+"+128,","+128,3,12,"&"+128,"&"+128,"            "
 4349 T:2918  08 03 20 20 20 20 20 ...           .byt 8,3,"       `a  ",7,")"+128,"-"+128,"  ",")"+128,"-"+128,"  ",")"+128,"-"+128,3,12,"&"+128,"&"+128,"            "
 4350 T:2940  20 ff 50 00 00 64 2c ...           .dsb 80," "
 4351 T:2990  09 01 41 52 52 4f 57 ...           .byt 9,1,"ARROW KEYS",7,"MOVE ROCKFORD AROUND       "
 4352 T:29b8  20 ff 50 00 00 64 2c ...           .dsb 80," "
 4353 T:2a08  09 01 53 50 41 43 45 ...           .byt 9,1,"SPACE BAR + ARROW KEYS                "
 4354 T:2a30  09 07 43 4c 45 41 52 ...           .byt 9,7,"CLEARS A SPACE, PUSHES A ROCK, ",8,3,"^_ ./"
 4355 T:2a58  09 07 47 52 41 42 53 ...           .byt 9,7,"GRABS A DIAMOND, OR PLANTS A   ",8,3,"`a 01"
 4356 T:2a80  09 07 42 4f 4d 42 20 ...           .byt 9,7,"BOMB WITHOUT ROCKFORD MOVING          "
 4357 T:2aa8  20 ff 28 00 00 64 2c ...           .dsb 40," "
 4358 T:2ad0  08 03 20 20 20 20 20 ...           .byt 8,3,"                                    ./"
 4359 T:2af8  09 01 53 48 49 46 54 ...           .byt 9,1,"SHIFT",7,"KILLS ROCKFORD WHEN TRAPPED ",8,3,"01"
 4360 T:2b20  09 07 4f 52 20 57 48 ...           .byt 9,7,"OR WHEN A CAVE CANNOT BE SOLVED ",8,3,"./^_"
 4361 T:2b48  09 01 20 20 20 20 20 ...           .byt 9,1,"                                ",8,3,"01`a"
 4362 T:2b70  20 ff 28 00 00 64 2c ...           .dsb 40," "
 4363 T:2b98  09 01 3e 07 50 41 55 ...           .byt 9,1,">",7,"PAUSES THE GAME                     "
 4364 T:2bc0  20 ff 78 00 00 64 2c ...           .dsb 120," "
 4365 T:2c38  09 02 44 4f 57 4e 07 ...           .byt 9,2,"DOWN",7,"CONTINUES,",2,"SPACE",7,"STARTS GAME     "

 4367 T:2c60                           instructions_2 
 4368 T:2c60  09 07 4f 4e 20 54 48 ...           .byt 9,7,"ON THE",6,"MENU",7,"SCREEN                    "
 4369 T:2c88  20 ff 28 00 00 64 2c ...           .dsb 40," "
 4370 T:2cb0  09 01 4c 45 46 54 20 ...           .byt 9,1,"LEFT RIGHT",7,"CHANGES THE CAVE TO PLAY   "
 4371 T:2cd8  09 01 55 50 20 44 4f ...           .byt 9,1,"UP DOWN",7,"CHANGES THE DIFFICULTY LEVEL  "
 4372 T:2d00  20 ff 28 00 00 64 2c ...           .dsb 40," "
 4373 T:2d28  09 01 53 48 49 46 54 ...           .byt 9,1,"SHIFT",7,"TOGGLES THE ARROW DIRECTION KEYS"
 4374 T:2d50  09 06 20 20 53 54 41 ...           .byt 9,6,"  STANDARD LAYOUT",1,"LEFT DOWN UP RIGHT  "
 4375 T:2d78  09 06 20 20 41 4c 54 ...           .byt 9,6,"  ALTERNATE LAYOUT",1,"LEFT RIGHT DOWN UP "
 4376 T:2da0  20 ff 28 00 00 64 2c ...           .dsb 40," "
 4377 T:2dc8  09 01 3c 20 3e 07 43 ...           .byt 9,1,"< >",7,"CHANGES THE COLOUR SCHEME         "
 4378 T:2df0  20 ff 50 00 00 64 2c ...           .dsb 80," "
 4379 T:2e40  09 07 45 41 43 48 20 ...           .byt 9,7,"EACH CAVE HAS A DIFFERENT PUZZLE",8,3,"^_  "
 4380 T:2e68  09 07 46 4f 52 20 52 ...           .byt 9,7,"FOR ROCKFORD TO OVERCOME        ",8,3,"`a  "
 4381 T:2e90  20 ff 28 00 00 64 2c ...           .dsb 40," "
 4382 T:2eb8  09 07 57 41 54 43 48 ...           .byt 9,7,"WATCH OUT FOR FALLING ROCKS AND ",8,3,"./  "
 4383 T:2ee0  09 07 44 49 41 4d 4f ...           .byt 9,7,"DIAMONDS WHICH KILL ROCKFORD!   ",8,3,"01  "
 4384 T:2f08  09 07 42 55 54 54 45 ...           .byt 9,7,"BUTTERFLIES AND FIREFLIES     ",8,3,"N"+128,"O"+128,4," 23"
 4385 T:2f30  09 07 41 52 45 20 41 ...           .byt 9,7,"ARE ALSO LETHAL!              ",8,3,"P"+128,"Q"+128,4," 45"
 4386 T:2f58  20 ff 28 00 00 64 2c ...           .dsb 40," "
 4387 T:2f80  09 07 52 4f 43 4b 46 ...           .byt 9,7,"ROCKFORD CAN PUSH ROCKS INTO  ",8,3,"rs ./ "
 4388 T:2fa8  09 07 53 50 41 43 45 ...           .byt 9,7,"SPACES TO GET PAST OBSTACLES, ",8,3,"yz 01 "
 4389 T:2fd0  09 07 44 52 4f 50 20 ...           .byt 9,7,"DROP THEM ONTO FIREFLIES TO   ",8,3,"!"+128,34+128,"!"+128,34+128,"  "
 4390 T:2ff8  09 07 4b 49 4c 4c 20 ...           .byt 9,7,"KILL THEM, OR DROP THEM ONTO  ",8,3,"#"+128,"$"+128,"#"+128,"$"+128,"  "
 4391 T:3020  09 07 42 55 54 54 45 ...           .byt 9,7,"BUTTERFLIES TO CHANGE THEM    ",8,3,"!"+128,34+128,"!"+128,34+128,"N"+128,"O"+128
 4392 T:3048  09 07 49 4e 54 4f 20 ...           .byt 9,7,"INTO DIAMONDS                 ",8,3,"!"+128,34+128,"!"+128,34+128,"P"+128,"Q"+128
 4393 T:3070  20 ff 28 00 00 64 2c ...           .dsb 40," "
 4394 T:3098  09 02 44 4f 57 4e 07 ...           .byt 9,2,"DOWN",7,"CONTINUES,",2,"SPACE",7,"STARTS GAME     "

 4396 T:30c0                           instructions_3 
 4397 T:30c0  09 07 57 41 4c 4c 53 ...           .byt 9,7,"WALLS RESTRICT WHERE ROCKFORD CAN ",8,3,"%"+128,"%"+128
 4398 T:30e8  09 07 47 4f 2e 20 41 ...           .byt 9,7,"GO. AN EXPLOSION FROM A FIREFLY,  ",8,3,"%"+128,"%"+128
 4399 T:3110  09 07 42 55 54 54 45 ...           .byt 9,7,"BUTTERFLY OR BOMB DESTROYS BRICK  ",8,3,"&"+128,"&"+128
 4400 T:3138  09 07 57 41 4c 4c 53 ...           .byt 9,7,"WALLS BUT NOT TITANIUM ONES       ",8,3,"&"+128,"&"+128
 4401 T:3160  20 ff 50 00 00 64 2c ...           .dsb 80," "
 4402 T:31b0  09 07 44 52 4f 50 20 ...           .byt 9,7,"DROP ROCKS ONTO THE MAGIC WALL TO ",8,3,"./"
 4403 T:31d8  09 07 43 48 41 4e 47 ...           .byt 9,7,"CHANGE THEM INTO DIAMONDS. THERE  ",8,3,"01"
 4404 T:3200  09 07 4d 55 53 54 20 ...           .byt 9,7,"MUST BE EMPTY SPACE BELOW THE   ",8,3,"%%%%"
 4405 T:3228  09 07 57 41 4c 4c 20 ...           .byt 9,7,"WALL FOR THE DIAMONDS TO LAND.  ",8,3,"%%%%"
 4406 T:3250  09 07 42 45 57 41 52 ...           .byt 9,7,"BEWARE IT ALSO TURNS DIAMONDS   ",8,7,"+"+128,","+128,"  "
 4407 T:3278  09 07 49 4e 54 4f 20 ...           .byt 9,7,"INTO ROCKS!                     ",8,7,")"+128,"-"+128,"  "
 4408 T:32a0  20 ff 50 00 00 64 2c ...           .dsb 80," "
 4409 T:32f0  09 07 57 41 54 43 48 ...           .byt 9,7,"WATCH OUT FOR THE GROWING WALL",8,3," %%%  "
 4410 T:3318  09 07 57 48 49 43 48 ...           .byt 9,7,"WHICH GROWS INTO EMPTY SPACE  ",8,3,"%%%   "
 4411 T:3340  09 07 4f 4e 20 45 49 ...           .byt 9,7,"ON EITHER SIDE OF IT                  "
 4412 T:3368  20 ff 50 00 00 64 2c ...           .dsb 80," "
 4413 T:33b8  09 07 54 52 41 50 20 ...           .byt 9,7,"TRAP THE GROWING AMOEBA USING   ",8,3,"././"
 4414 T:33e0  09 07 52 4f 43 4b 53 ...           .byt 9,7,"ROCKS TO TURN IT INTO DIAMONDS  ",8,3,"0101"
 4415 T:3408  09 07 42 45 57 41 52 ...           .byt 9,7,"BEWARE IT WILL EVENTUALLY TURN  ",8,7,":;67"
 4416 T:3430  09 07 54 4f 20 52 4f ...           .byt 9,7,"TO ROCK IF IT GROWS TOO LARGE!  ",8,7,"<=89"
 4417 T:3458  09 07 54 48 45 20 41 ...           .byt 9,7,"THE AMOEBA KILLS FIREFLIES AND",8,3,"N"+128,"O"+128,4," 23"
 4418 T:3480  09 07 54 55 52 4e 53 ...           .byt 9,7,"TURNS BUTTERFLIES TO DIAMONDS ",8,3,"P"+128,"Q"+128,4," 45"
 4419 T:34a8  20 ff 50 00 00 64 2c ...           .dsb 80," "
 4420 T:34f8  09 02 44 4f 57 4e 07 ...           .byt 9,2,"DOWN",7,"CONTINUES,",2,"SPACE",7,"STARTS GAME     "

 4422 T:3520                           instructions_4 
 4423 T:3520  09 07 53 4c 49 4d 45 ...           .byt 9,7,"SLIME LOOKS LIKE THE AMOEBA BUT   ",8,3,"./"
 4424 T:3548  09 07 44 4f 45 53 20 ...           .byt 9,7,"DOES NOT GROW. IT SLOWS DOWN ROCKS",8,3,"01"
 4425 T:3570  09 07 41 4e 44 20 44 ...           .byt 9,7,"AND DIAMONDS FROM DROPPING INTO   ",8,7,":;"
 4426 T:3598  09 07 45 4d 50 54 59 ...           .byt 9,7,"EMPTY SPACE BELOW IT              ",8,7,"<="
 4427 T:35c0  20 ff 50 00 00 64 2c ...           .dsb 80," "
 4428 T:3610  09 07 52 4f 43 4b 46 ...           .byt 9,7,"ROCKFORD CAN USE BOMBS IN SOME    ",8,3,"{|"
 4429 T:3638  09 07 43 41 56 45 53 ...           .byt 9,7,"CAVES. THEY EXPLODE AFTER A SHORT ",8,3,"}~"
 4430 T:3660  09 07 44 45 4c 41 59 ...           .byt 9,7,"DELAY AND DESTROY ALMOST ANYTHING     "
 4431 T:3688  20 ff 50 00 00 64 2c ...           .dsb 80," "
 4432 T:36d8  09 07 53 4f 4d 45 20 ...           .byt 9,7,"SOME CAVES HAVE ZERO GRAVITY WHERE",8,3,"Z["
 4433 T:3700  09 07 52 4f 43 4b 53 ...           .byt 9,7,"ROCKS, DIAMONDS AND BOMBS DO NOT  ",8,3,92,"]"
 4434 T:3728  09 07 46 41 4c 4c 2e ...           .byt 9,7,"FALL. ROCKS LOOK LIKE BUBBLES AND     "
 4435 T:3750  09 07 43 41 4e 20 42 ...           .byt 9,7,"CAN BE PUSHED IN ALL DIRECTIONS   ",8,3,"Z["
 4436 T:3778  09 07 42 45 57 41 52 ...           .byt 9,7,"BEWARE ZERO GRAVITY CAN RUN OUT!  ",8,3,92,"]"
 4437 T:37a0  20 ff 50 00 00 64 2c ...           .dsb 80," "

 4439 T:37f0  09 07 53 43 4f 52 45 ...           .byt 9,7,"SCORE POINTS BY GATERING DIAMONDS.    "
 4440 T:3818  09 07 54 48 45 59 20 ...           .byt 9,7,"THEY ARE MORE VALUABLE WHEN FEWER ARE "
 4441 T:3840  09 07 41 56 41 49 4c ...           .byt 9,7,"AVAILABLE, AND WHEN ROCKFORD'S EXIT   "
 4442 T:3868  09 07 49 53 20 4f 50 ...           .byt 9,7,"IS OPEN AND THERE ARE STILL SOME LEFT "
 4443 T:3890  20 ff 28 00 00 64 2c ...           .dsb 40," "
 4444 T:38b8  09 07 45 56 45 52 59 ...           .byt 9,7,"EVERY 500 POINTS, ROCKFORD   ",8,3,"ij",7,127,127,127,127
 4445 T:38e0  09 07 49 53 20 41 57 ...           .byt 9,7,"IS AWARDED A BONUS LIFE!     ",8,3,"mn",7,127,127,127,127
 4446 T:3908  20 ff 50 00 00 64 2c ...           .dsb 80," "
 4447 T:3958  09 02 44 4f 57 4e 07 ...           .byt 9,2,"DOWN",7,"RESTARTS,",2,"SPACE",7,"STARTS GAME      "
