Star Wars disassembly ===================== Star Wars was converted to the BBC Micro from the Atari arcade game by Daniel Gallagher, and was published by Domark in 1987. It uses vector graphics to simulate three scenes from the 1977 film of the same name. The player must first battle TIE fighters in space, then fly through surface defence towers, before finally following a trench to fire at the Death Star's exhaust port. The following disassembly was created by reverse engineering binary images, without access to any source code. It is nevertheless reasonably complete, allowing the technical approaches used to be understood. The author of this disassembly imposes no additional copyright restrictions beyond those already present on the game itself. It is provided for educational purposes only, and it is hoped that the original authors will accept it in the good faith it was intended - as a tribute to their skills. Technical notes =============== The game uses double buffering. The first BASIC loader stores the player's choice of keys in &70 - &74, then loads and runs the second BASIC loader at &0900. Interesting pokes ================= &2386 = &ad infinite shields Loader disassembly ================== ; STARW2 ; FFFF2000 FFFF2000 0100 &0900 0d # Start of BASIC program &0901 00 0a 1e f4 20 2e 2e 4d 61 69 6e 20 53 74 61 72 ; 10REM ..Main Starwars loader.. &0911 77 61 72 73 20 6c 6f 61 64 65 72 2e 2e 0d &091f 00 14 0c 2a 54 56 32 35 32 20 31 0d ; 20*TV252 1 &092b 00 1e 09 2a 4f 50 54 31 0d ; 30*OPT1 &0934 00 28 44 ef 32 32 2c 35 2c 32 33 3b 38 32 30 32 ; 40VDU22,5, # Change to MODE 5 &0944 3b 30 3b 30 3b 30 3b 32 38 2c 30 2c 33 31 2c 31 ; 23;8202;0;0;0; # Disable cursor &0954 39 2c 32 30 2c 31 32 2c 31 39 2c 31 2c 36 3b 30 ; 28,0,31,19,20, # Define text window x:(0, 19), y:(20, 31) &0964 3b 31 39 2c 32 2c 31 3b 30 3b 31 39 2c 33 2c 32 ; 12, # Clear text area &0974 3b 30 3b 0d ; 19,1,6;0; # Set colour 1 to cyan ; 19,2,1;0; # Set colour 2 to red ; 19,3,2;0; # Set colour 2 to green &0978 00 32 3f 3f 26 46 45 30 30 3d 31 32 3a 3f 26 46 ; 50?&FE00=12:?&FE01=&E: # R12: Displayed screen start address register (high) &0988 45 30 31 3d 26 45 3a 3f 26 46 45 30 30 3d 31 33 ?&FE00=13:?&FE01=&20: # R13: Displayed screen start address register (low) &0998 3a 3f 26 46 45 30 31 3d 26 32 30 3a 3f 26 46 45 ?&FE00=6:?&FE01=12 # (set screen start address to &7100) &09a8 30 30 3d 36 3a 3f 26 46 45 30 31 3d 31 32 0d ?&FE00=6:?&FE01=12 # R6: Vertical displayed register &09b7 00 3c 19 2a 4c 4f 41 44 20 53 57 63 6f 64 65 20 ; 60*LOAD SWcode FFFF2000 &09c7 46 46 46 46 32 30 30 30 0d &09d0 00 46 09 2a 54 41 50 45 0d ; 70*TAPE &09d9 00 50 0a d6 26 36 43 30 30 0d ; 80CALL&6C00 # Call entry_point &09e3 ff # End of BASIC program ; unused &09e4 00 01 01 01 00 00 00 00 00 03 00 00 00 00 00 00 &09f4 00 03 00 00 00 00 00 14 00 03 00 00 Game disassembly ================ ; SWCODE ; FFFF2000 FFFF2000 4D00 # &2000 - &23ff is moved to &0400 - &07ff at &6c12 ; title_screen_after_wiping_buffers &0400 20 f6 2b JSR &2bf6 ; wipe_buffer_one &0403 20 90 2c JSR &2c90 ; wipe_buffer_two &0406 20 5a 2b JSR &2b5a ; use_other_buffer_and_wipe ; title_screen &0409 a9 40 LDA #&40 &040b 8d 13 03 STA &0313 ; player_x &040e a9 58 LDA #&58 &0410 8d 14 03 STA &0314 ; player_y &0413 a9 b1 LDA #&b1 ; &39b1 = star_wars_string &0415 85 18 STA &18 ; text_address_low &0417 a9 39 LDA #&39 &0419 85 19 STA &19 ; text_address_high &041b 20 6c 2e JSR &2e6c ; use_other_buffer &041e a2 01 LDX #&01 &0420 20 7a 2d JSR &2d7a ; plot_strings # Plot "STAR WARS" and "SELECT STARTING WAVE:1,3 OR 5" &0423 20 6c 2e JSR &2e6c ; use_other_buffer ; title_screen_loop &0426 a9 01 LDA #&01 &0428 85 5f STA &5f ; starting_wave &042a a2 cf LDX #&cf ; 1 &042c 20 8d 39 JSR &398d ; check_for_keypress &042f f0 18 BEQ &0449 ; start_game &0431 a9 03 LDA #&03 &0433 85 5f STA &5f ; starting_wave &0435 a2 ee LDX #&ee ; 3 &0437 20 8d 39 JSR &398d ; check_for_keypress &043a f0 0d BEQ &0449 ; start_game &043c a9 05 LDA #&05 &043e 85 5f STA &5f ; starting_wave &0440 a2 ec LDX #&ec ; 5 &0442 20 8d 39 JSR &398d ; check_for_keypress &0445 f0 02 BEQ &0449 ; start_game &0447 d0 dd BNE &0426 ; title_screen_loop # Always branches ; start_game &0449 a5 5f LDA &5f ; starting_wave &044b 8d 8a 08 STA &088a ; wave_as_bcd &044e 8d 8b 08 STA &088b ; wave &0451 8d 89 08 STA &0889 ; wave_started_on &0454 a9 1d LDA #&1d # Used for pseudo-random catwalks on wave 11 and after &0456 8d a4 08 STA &08a4 ; saved_rnd_state &0459 a9 f3 LDA #&f3 &045b 8d a5 08 STA &08a5 ; saved_rnd_state + 1 &045e a9 37 LDA #&37 &0460 8d a6 08 STA &08a6 ; saved_rnd_state + 2 &0463 a9 89 LDA #&89 &0465 8d a7 08 STA &08a7 ; saved_rnd_state + 3 &0468 a2 1f LDX #&1f ; reset_game_state_loop &046a bd ce 07 LDA &07ce,X ; initial_game_state &046d 9d 82 03 STA &0382,X ; game_state &0470 ca DEX &0471 10 f7 BPL &046a ; reset_game_state_loop &0473 20 a8 2b JSR &2ba8 ; plot_status &0476 20 f6 2b JSR &2bf6 ; wipe_buffer_one &0479 20 90 2c JSR &2c90 ; wipe_buffer_two ; start_space_stage &047c a9 ff LDA #&ff &047e 8d fc 4f STA &4ffc ; player_hit_cooldown # Set to negative to allow player to be hit &0481 8d ab 08 STA &08ab ; vader_tie_fighter_hit_cooldown # Set to negative to indicate not recently hit &0484 8d fb 4f STA &4ffb ; space_stage_following_cooldown &0487 20 8a 23 JSR &238a ; wipe_tower_count_area_and_message_area # Returns A = 0 &048a 8d 8d 08 STA &088d ; recent_score_cooldown &048d 8d 06 07 STA &0706 ; fireballs_x_high # Set to zero to plot fireballs &0490 8d 00 03 STA &0300 ; player_is_firing # Set to positive to indicate player is not firing &0493 8d bb 08 STA &08bb ; player_rotation_about_z &0496 8d af 08 STA &08af ; stage # Set to 0 to indicate space stage &0499 8d b1 08 STA &08b1 ; frame_counter_high &049c 8d b0 08 STA &08b0 ; frame_counter # Used as timer for space stage &049f a9 80 LDA #&80 &04a1 8d 62 3a STA &3a62 ; maximum_z_high_for_plotting_model &04a4 ad 8a 08 LDA &088a ; wave_as_bcd &04a7 38 SEC &04a8 e9 01 SBC #&01 &04aa c9 07 CMP #&07 &04ac 90 02 BCC &04b0 ; skip_ceiling &04ae a9 07 LDA #&07 # Number of fireballs increases per wave until maximum of 8 ; skip_ceiling &04b0 8d fd 4f STA &4ffd ; maximum_fireballs &04b3 a2 02 LDX #&02 ; initialise_tie_fighters_loop # For each of three TIE fighters, &04b5 a9 05 LDA #&05 ; MODEL_TIE_FIGHTER &04b7 9d f1 15 STA &15f1,X ; tie_fighters_state &04ba 20 ff 37 JSR &37ff ; rnd &04bd 29 0f AND #&0f &04bf 38 SEC &04c0 e9 08 SBC #&08 # -8 to 7 &04c2 9d d5 15 STA &15d5,X ; tie_fighters_x_high # Set random x position for TIE fighter &04c5 20 ff 37 JSR &37ff ; rnd &04c8 29 0f AND #&0f &04ca 18 CLC &04cb 69 08 ADC #&08 # -8 to 7 &04cd 9d dd 15 STA &15dd,X ; tie_fighters_y_high # Set random y position for TIE fighter &04d0 20 ff 37 JSR &37ff ; rnd &04d3 29 0c AND #&0c &04d5 18 CLC &04d6 69 04 ADC #&04 # 4, 8, 12 or 16 &04d8 9d e5 15 STA &15e5,X ; tie_fighters_z_high # Set random z position for TIE fighter &04db 20 ff 37 JSR &37ff ; rnd &04de 29 03 AND #&03 &04e0 38 SEC &04e1 e9 02 SBC #&02 # -2 to 1 &04e3 9d ed 15 STA &15ed,X ; tie_fighters_rotation_velocity # Set random rotation velocity for TIE fighter &04e6 20 ff 37 JSR &37ff ; rnd &04e9 9d e9 15 STA &15e9,X ; tie_fighters_rotation # Set random rotation for TIE fighter &04ec 20 ff 37 JSR &37ff ; rnd &04ef 29 03 AND #&03 &04f1 8d aa 23 STA &23aa ; tie_fighter_to_follow &04f4 38 SEC &04f5 e9 02 SBC #&02 # -2 to 1 &04f7 9d f5 15 STA &15f5,X ; tie_fighters_xy_velocity # Set random xy velocity for TIE fighter &04fa 20 ff 37 JSR &37ff ; rnd &04fd 29 08 AND #&08 &04ff 38 SEC &0500 e9 04 SBC #&04 # -4 or 4 &0502 9d fd 15 STA &15fd,X ; tie_fighters_z_velocity # Set random z velocity for TIE fighter &0505 ca DEX &0506 10 ad BPL &04b5 ; initialise_tie_fighters_loop &0508 a9 06 LDA #&06 ; MODEL_TIE_FIGHTER_VADER &050a 8d f1 15 STA &15f1 ; tie_fighters_state # Set the last TIE fighter to be Darth Vader's ; initialise_space_stars &050d a2 0f LDX #&0f ; initialise_space_stars_loop # For each of sixteen stars, &050f 20 ff 37 JSR &37ff ; rnd &0512 29 7f AND #&7f &0514 9d a0 03 STA &03a0,X ; stars_screen_x # Set random x position for star &0517 20 ff 37 JSR &37ff ; rnd &051a c9 a0 CMP #&a0 &051c 90 03 BCC &0521 ; skip_wraparound &051e 38 SEC &051f e9 a0 SBC #&a0 ; skip_wraparound &0521 9d c0 03 STA &03c0,X ; stars_screen_y # Set random y position for star &0524 ca DEX &0525 10 e8 BPL &050f ; initialise_stars_loop &0527 20 a7 2e JSR &2ea7 ; reset_fireballs &052a a9 e4 LDA #&e4 ; &48e4 = shoot_tie_fighters_string &052c 8d 1b 16 STA &161b ; stage_message_address_low &052f a9 48 LDA #&48 &0531 8d 1f 16 STA &161f ; stage_message_address_high ; space_stage_main_loop &0534 ad 12 03 LDA &0312 ; fireball_rotation &0537 18 CLC &0538 69 08 ADC #&08 # Rotate fireballs clockwise &053a 8d 12 03 STA &0312 ; fireball_rotation &053d a9 00 LDA #&00 &053f 8d a0 08 STA &08a0 ; player_x_velocity &0542 8d a1 08 STA &08a1 ; player_x_velocity_high &0545 8d a2 08 STA &08a2 ; player_y_velocity &0548 8d a3 08 STA &08a3 ; player_y_velocity_high &054b 20 56 14 JSR &1456 ; check_for_player_movement &054e ad b1 08 LDA &08b1 ; frame_counter_high &0551 c9 02 CMP #&02 &0553 b0 03 BCS &0558 ; skip_plotting_stage_message # Branch at end of space stage &0555 20 01 16 JSR &1601 ; consider_plotting_stage_message ; skip_plotting_stage_message &0558 ad b0 08 LDA &08b0 ; frame_counter &055b 29 0f AND #&0f &055d d0 08 BNE &0567 ; skip_changing_tie_fighter_to_follow # Every 16 frames, &055f 20 ff 37 JSR &37ff ; rnd &0562 29 03 AND #&03 &0564 8d aa 23 STA &23aa ; tie_fighter_to_follow # pick a new TIE fighter to follow ; skip_changing_tie_fighter_to_follow &0567 ad fb 4f LDA &4ffb ; space_stage_following_cooldown &056a 10 5e BPL &05ca ; skip_changing_following ; follow_tie_fighter &056c ae aa 23 LDX &23aa ; tie_fighter_to_follow &056f bd 08 01 LDA &0108,X ; tie_fighters_target_x_high &0572 30 11 BMI &0585 ; follow_tie_fighter_left &0574 f0 02 BEQ &0578 ; check_x_low &0576 10 14 BPL &058c ; follow_tie_fighter_right # Always branches ; check_x_low &0578 bd 00 01 LDA &0100,X ; tie_fighters_target_x &057b c9 20 CMP #&20 &057d 90 06 BCC &0585 ; follow_tie_fighter_left &057f c9 60 CMP #&60 &0581 b0 09 BCS &058c ; follow_tie_fighter_right &0583 90 11 BCC &0596 ; skip_following_horizontally # Always branches ; follow_tie_fighter_left &0585 a9 04 LDA #&04 &0587 8d a0 08 STA &08a0 ; player_x_velocity &058a d0 0a BNE &0596 ; skip_following_horizontally # Always branches ; follow_tie_fighter_right &058c a9 fc LDA #&fc &058e 8d a0 08 STA &08a0 ; player_x_velocity &0591 a9 ff LDA #&ff &0593 8d a1 08 STA &08a1 ; player_x_velocity_high ; skip_following_horizontally &0596 bd 18 01 LDA &0118,X ; tie_fighters_target_y_high &0599 30 11 BMI &05ac ; follow_tie_fighter_down &059b f0 02 BEQ &059f ; check_y_low &059d 10 14 BPL &05b3 ; follow_tie_fighter_up # Always branches ; check_y_low &059f bd 10 01 LDA &0110,X ; tie_fighters_target_y &05a2 c9 20 CMP #&20 &05a4 90 06 BCC &05ac ; follow_tie_fighter_down &05a6 c9 88 CMP #&88 &05a8 b0 09 BCS &05b3 ; follow_tie_fighter_up &05aa 90 11 BCC &05bd ; skip_following_vertically # Always branches ; follow_tie_fighter_down &05ac a9 04 LDA #&04 &05ae 8d a2 08 STA &08a2 ; player_y_velocity &05b1 d0 0a BNE &05bd ; skip_following_vertically # Always branches ; follow_tie_fighter_up &05b3 a9 fc LDA #&fc &05b5 8d a2 08 STA &08a2 ; player_y_velocity &05b8 a9 ff LDA #&ff &05ba 8d a3 08 STA &08a3 ; player_y_velocity_high ; skip_following_vertically &05bd ad a0 08 LDA &08a0 ; player_x_velocity &05c0 0d a2 08 ORA &08a2 ; player_y_velocity &05c3 d0 05 BNE &05ca ; skip_resetting_cooldown &05c5 a9 03 LDA #&03 &05c7 8d fb 4f STA &4ffb ; space_stage_following_cooldown ; skip_resetting_cooldown ; skip_changing_following &05ca ad fb 4f LDA &4ffb ; space_stage_following_cooldown &05cd 30 03 BMI &05d2 ; skip_reducing_cooldown &05cf ce fb 4f DEC &4ffb ; space_stage_following_cooldown ; skip_reducing_cooldown &05d2 20 44 22 JSR &2244 ; update_space_stars &05d5 20 cc 3c JSR &3ccc ; apply_player_velocity_to_tie_fighters &05d8 20 7f 3f JSR &3f7f ; update_tie_fighters &05db ad b0 08 LDA &08b0 ; frame_counter &05de 18 CLC &05df 69 01 ADC #&01 &05e1 8d b0 08 STA &08b0 ; frame_counter &05e4 ad b1 08 LDA &08b1 ; frame_counter_high &05e7 69 00 ADC #&00 &05e9 8d b1 08 STA &08b1 ; frame_counter_high &05ec c9 02 CMP #&02 &05ee 90 18 BCC &0608 ; not_end_of_space_stage # Branch if not end of space stage ; at_end_of_space_stage &05f0 a2 02 LDX #&02 ; check_for_tie_fighters_loop &05f2 bd f1 15 LDA &15f1,X ; tie_fighters_state &05f5 10 11 BPL &0608 ; not_end_of_space_stage # Continue space stage until all TIE fighters destroyed &05f7 ca DEX &05f8 10 f8 BPL &05f2 ; check_for_tie_fighters_loop &05fa ae fd 4f LDX &4ffd ; maximum_fireballs ; check_for_fireballs_loop &05fd bd e7 30 LDA &30e7,X ; fireballs_state &0600 10 06 BPL &0608 ; not_end_of_space_stage # Continue space stage until all fireballs destroyed &0602 ca DEX &0603 10 f8 BPL &05fd ; check_for_fireballs_loop &0605 4c 29 06 JMP &0629 ; start_descent_stage # Then start descent stage ; not_end_of_space_stage &0608 20 b3 16 JSR &16b3 ; consider_wiping_recent_score &060b a2 8f LDX #&8f ; ESCAPE &060d 20 8d 39 JSR &398d ; check_for_keypress &0610 f0 14 BEQ &0626 ; to_game_over_screen &0612 20 41 3d JSR &3d41 ; consider_firing &0615 20 1c 2f JSR &2f1c ; update_space_fireballs &0618 ad 8d 03 LDA &038d ; shields &061b 30 09 BMI &0626 ; to_game_over_screen &061d 20 26 16 JSR &1626 ; update_player_hit_cooldown &0620 20 5a 2b JSR &2b5a ; use_other_buffer_and_wipe &0623 4c 34 05 JMP &0534 ; space_stage_main_loop ; to_game_over_screen &0626 4c ac 3c JMP &3cac ; game_over_screen ; start_descent_stage &0629 a9 01 LDA #&01 &062b 8d af 08 STA &08af ; stage # Set to 1 to indicate surface stage &062e a9 03 LDA #&03 &0630 8d 06 07 STA &0706 ; fireballs_x_high # Set to non-zero to suppress plotting fireballs &0633 a9 08 LDA #&08 ; maximum state &0635 a0 0c LDY #&0c ; target size # Short towers are easier to hit on wave 2 &0637 ae 8a 08 LDX &088a ; wave_as_bcd &063a e0 02 CPX #&02 &063c f0 04 BEQ &0642 ; set_maximum_exploding_towers_state_and_tower_target_size &063e a9 0c LDA #&0c ; maximum state &0640 a0 06 LDY #&06 ; target size ; set_maximum_exploding_towers_state_and_tower_target_size &0642 8d 60 31 STA &3160 ; maximum_exploding_towers_state_for_updating &0645 8d 1a 43 STA &431a ; maximum_exploding_towers_state_for_adding &0648 8c 50 15 STY &1550 ; tower_target_size &064b a2 03 LDX #&03 ; reset_exploding_towers_loop &064d 9d fc 03 STA &03fc,X ; exploding_towers_state &0650 ca DEX &0651 10 fa BPL &064d ; reset_exploding_towers_loop &0653 a9 0e LDA #&0e &0655 8d 2f 15 STA &152f ; tower_y_high # Set height of regular towers &0658 a9 7a LDA #&7a &065a 8d 62 3a STA &3a62 ; maximum_z_high_for_plotting_model &065d ad 8b 08 LDA &088b ; wave &0660 38 SEC &0661 e9 03 SBC #&03 &0663 29 07 AND #&07 &0665 0a ASL A # Four bytes of tower pattern data per wave &0666 0a ASL A &0667 18 CLC &0668 69 80 ADC #&80 ; &4f80 = tower_patterns_data &066a 8d 76 0b STA &0b76 ; tower_patterns_data_address_low &066d a9 00 LDA #&00 &066f 8d a0 08 STA &08a0 ; player_x_velocity &0672 8d a1 08 STA &08a1 ; player_x_velocity_high &0675 8d a2 08 STA &08a2 ; player_y_velocity &0678 8d a3 08 STA &08a3 ; player_y_velocity_high &067b 69 4f ADC #&4f &067d 8d 77 0b STA &0b77 ; tower_patterns_data_address_high &0680 20 a7 2e JSR &2ea7 ; reset_fireballs &0683 a9 b4 LDA #&b4 &0685 85 47 STA &47 ; descent_timer &0687 20 5a 2b JSR &2b5a ; use_other_buffer_and_wipe ; descent_stage_main_loop &068a 20 b3 16 JSR &16b3 ; consider_wiping_recent_score &068d 20 12 1f JSR &1f12 ; plot_death_star &0690 20 44 22 JSR &2244 ; update_space_stars &0693 a5 47 LDA &47 ; descent_timer &0695 38 SEC &0696 e9 04 SBC #&04 &0698 85 47 STA &47 ; descent_timer &069a 20 b3 16 JSR &16b3 ; consider_wiping_recent_score &069d 20 56 14 JSR &1456 ; check_for_player_movement &06a0 20 5a 2b JSR &2b5a ; use_other_buffer_and_wipe &06a3 a5 47 LDA &47 ; descent_timer &06a5 d0 e3 BNE &068a ; descent_stage_main_loop &06a7 20 5a 2b JSR &2b5a ; use_other_buffer_and_wipe ; initialise_surface_stars &06aa a2 0f LDX #&0f ; initialise_surface_stars_loop # For each of sixteen stars, &06ac 20 ff 37 JSR &37ff ; rnd &06af 9d a0 03 STA &03a0,X ; stars_x # Surface stars use x and z, not screen x and screen y &06b2 20 ff 37 JSR &37ff ; rnd &06b5 29 3f AND #&3f &06b7 38 SEC &06b8 e9 20 SBC #&20 # -32 to 31 &06ba 9d b0 03 STA &03b0,X ; stars_x_high # Set random x position for star &06bd 20 ff 37 JSR &37ff ; rnd &06c0 9d c0 03 STA &03c0,X ; stars_z &06c3 20 ff 37 JSR &37ff ; rnd &06c6 29 7f AND #&7f &06c8 9d d0 03 STA &03d0,X ; stars_z_high # Set random z position for star &06cb ca DEX &06cc 10 de BPL &06ac ; initialise_surface_stars_loop &06ce 8e fc 4f STX &4ffc ; player_hit_cooldown # Set to negative to allow player to be hit &06d1 a9 06 LDA #&06 &06d3 8d b3 08 STA &08b3 ; player_z_velocity &06d6 a9 78 LDA #&78 &06d8 8d b5 08 STA &08b5 ; player_x_high &06db a9 40 LDA #&40 &06dd 8d b6 08 STA &08b6 ; player_y &06e0 a9 01 LDA #&01 &06e2 8d b7 08 STA &08b7 ; player_y_high &06e5 a9 00 LDA #&00 &06e7 8d bb 08 STA &08bb ; player_rotation_about_z &06ea 8d b4 08 STA &08b4 ; player_x &06ed 8d b8 08 STA &08b8 ; player_z &06f0 8d b9 08 STA &08b9 ; player_z_high &06f3 8d ba 08 STA &08ba ; player_z_highest &06f6 4c 00 09 JMP &0900 ; start_surface_stage ; plot_fireball &06f9 a6 1c LDX &1c ; centre_x &06fb a4 1e LDY &1e ; centre_y &06fd a9 02 LDA #&02 ; R &06ff 20 ab 23 JSR &23ab ; set_colour &0702 20 4c 07 JSR &074c ; plot_fireball_part # Plot centre of fireball &0705 a9 00 LDA #&00 # actually LDA fireballs_x_high &0707 85 41 STA &41 ; point_x_high &0709 85 46 STA &46 ; point_z &070b a9 e0 LDA #&e0 &070d 85 40 STA &40 ; point_x &070f a5 55 LDA &55 ; origin_z_high &0711 85 47 STA &47 ; point_z_high &0713 20 75 39 JSR &3975 ; divide_point_x_by_point_z_times_two # Scale fireball by distance &0716 a5 79 LDA &79 ; result &0718 85 03 STA &03 ; radius_y_high &071a 4a LSR A &071b 85 05 STA &05 ; radius_x_high &071d a5 78 LDA &78 ; result_fraction &071f 85 02 STA &02 ; radius_y &0721 6a ROR A &0722 85 04 STA &04 ; radius_x &0724 a9 01 LDA #&01 ; C &0726 20 ab 23 JSR &23ab ; set_colour &0729 a2 00 LDX #&00 ; plot_fireball_ring_loop &072b 8a TXA &072c 48 PHA ; angle &072d 18 CLC &072e 6d 12 03 ADC &0312 ; fireball_rotation &0731 aa TAX &0732 20 d6 36 JSR &36d6 ; rotate_around_centre &0735 a5 67 LDA &67 ; line_end_x_high &0737 05 69 ORA &69 ; line_end_y_high &0739 d0 07 BNE &0742 ; skip_plotting_fireball_part # Don't plot fireball part if offscreen &073b a6 66 LDX &66 ; line_end_x &073d a4 68 LDY &68 ; line_end_y &073f 20 4c 07 JSR &074c ; plot_fireball_part # Plot outer ring of fireball ; skip_plotting_fireball_part &0742 68 PLA ; angle &0743 18 CLC &0744 69 2b ADC #&2b ; 43 &0746 aa TAX &0747 e0 02 CPX #&02 # 6 * 43 = 256 + 2 &0749 d0 e0 BNE &072b ; plot_fireball_ring_loop ; leave &074b 60 RTS ; plot_fireball_part # Called with X = x, Y = y of centre of part &074c a5 1d LDA &1d ; centre_x_high &074e 05 1f ORA &1f ; centre_y_high &0750 d0 f9 BNE &074b ; leave &0752 a5 55 LDA &55 ; origin_z_high &0754 c9 60 CMP #&60 &0756 b0 5d BCS &07b5 ; plot_fireball_part_size_one &0758 c9 30 CMP #&30 &075a b0 55 BCS &07b1 ; plot_fireball_part_size_two &075c c9 10 CMP #&10 &075e b0 3b BCS &079b ; plot_fireball_part_size_three ; plot_fireball_part_size_four &0760 ca DEX &0761 ca DEX &0762 20 23 29 JSR &2923 ; plot_pixel &0765 e8 INX &0766 20 23 29 JSR &2923 ; plot_pixel &0769 e8 INX &076a 20 23 29 JSR &2923 ; plot_pixel &076d e8 INX &076e 20 23 29 JSR &2923 ; plot_pixel &0771 e8 INX &0772 20 23 29 JSR &2923 ; plot_pixel &0775 ca DEX &0776 c8 INY &0777 20 23 29 JSR &2923 ; plot_pixel &077a ca DEX &077b 20 23 29 JSR &2923 ; plot_pixel &077e ca DEX &077f 20 23 29 JSR &2923 ; plot_pixel &0782 e8 INX &0783 c8 INY &0784 20 23 29 JSR &2923 ; plot_pixel &0787 88 DEY &0788 88 DEY &0789 88 DEY &078a 88 DEY &078b 20 23 29 JSR &2923 ; plot_pixel &078e ca DEX &078f c8 INY &0790 20 23 29 JSR &2923 ; plot_pixel &0793 e8 INX &0794 20 23 29 JSR &2923 ; plot_pixel &0797 e8 INX &0798 4c 23 29 JMP &2923 ; plot_pixel ; plot_fireball_part_size_three &079b ca DEX &079c 20 23 29 JSR &2923 ; plot_pixel &079f e8 INX &07a0 20 23 29 JSR &2923 ; plot_pixel &07a3 e8 INX &07a4 20 23 29 JSR &2923 ; plot_pixel &07a7 ca DEX &07a8 c8 INY &07a9 20 23 29 JSR &2923 ; plot_pixel &07ac 88 DEY &07ad 88 DEY &07ae 4c 23 29 JMP &2923 ; plot_pixel ; plot_fireball_part_size_two &07b1 20 23 29 JSR &2923 ; plot_pixel &07b4 88 DEY ; plot_fireball_part_size_one &07b5 4c 23 29 JMP &2923 ; plot_pixel ; avoid_catwalks_string &07b8 38 03 f0 12 ; at + &0338, colour &f0 (R), length &12 &07bc 3c 3c 41 56 4f 49 44 3c 43 41 54 57 41 4c 4b 53 ; "< &0c &0cf8 a9 12 LDA #&12 &0cfa 8d b7 08 STA &08b7 ; player_y_high &0cfd a9 3c LDA #&3c &0cff 8d b9 08 STA &08b9 ; player_z_high &0d02 a9 03 LDA #&03 # Unnecessary code; values never change &0d04 8d a2 12 STA &12a2 ; catwalk_offset_addition # &0d07 a9 c0 LDA #&c0 # &0d09 8d bc 12 STA &12bc ; catwalk_relative_z_high_addition # &0d0c ad 8a 08 LDA &088a ; wave_as_bcd # &0d0f c9 04 CMP #&04 # &0d11 90 0a BCC &0d1d ; not_wave_four_or_greater # ; is_wave_four_or_greater # &0d13 a9 03 LDA #&03 # &0d15 8d a2 12 STA &12a2 ; catwalk_offset_addition # &0d18 a9 c0 LDA #&c0 # &0d1a 8d bc 12 STA &12bc ; catwalk_relative_z_high_addition # ; not_wave_four_or_greater &0d1d a9 03 LDA #&03 ; G &0d1f 20 ab 23 JSR &23ab ; set_colour &0d22 a9 80 LDA #&80 &0d24 8d bb 08 STA &08bb ; player_rotation_about_z ; trench_stage_rotation_loop &0d27 a2 00 LDX #&00 ; plot_trench_vanishing_point_lines_loop &0d29 8a TXA &0d2a 48 PHA ; line offset &0d2b a9 00 LDA #&00 &0d2d 85 50 STA &50 ; origin_x &0d2f 85 52 STA &52 ; origin_y &0d31 85 54 STA &54 ; origin_z &0d33 bd a8 4f LDA &4fa8,X ; trench_vanishing_point_lines_x_table &0d36 85 51 STA &51 ; origin_x_high &0d38 bd b6 4f LDA &4fb6,X ; trench_vanishing_point_lines_y_table &0d3b 85 53 STA &53 ; origin_y_high &0d3d bd c4 4f LDA &4fc4,X ; trench_vanishing_point_lines_z_table &0d40 18 CLC &0d41 6d b9 08 ADC &08b9 ; player_z_high &0d44 85 55 STA &55 ; origin_z_high &0d46 20 9e 3d JSR &3d9e ; calculate_origin_relative_to_player &0d49 20 0a 32 JSR &320a ; apply_player_rotation_to_origin &0d4c 20 34 38 JSR &3834 ; calculate_screen_position_for_origin # Sets line_end to origin &0d4f 68 PLA ; line offset &0d50 48 PHA ; line offset &0d51 aa TAX &0d52 bd c0 48 LDA &48c0,X ; trench_vanishing_point_lines_type_table &0d55 d0 06 BNE &0d5d ; is_line &0d57 20 0f 29 JSR &290f ; set_line_start_to_line_end &0d5a 4c 60 0d JMP &0d60 ; skip_plotting_line ; is_line &0d5d 20 db 23 JSR &23db ; plot_line # Plot trench vanishing point lines ; skip_plotting_line &0d60 68 PLA ; line offset &0d61 aa TAX &0d62 e8 INX &0d63 e0 0e CPX #&0e &0d65 d0 c2 BNE &0d29 ; plot_trench_vanishing_point_lines_loop &0d67 ad b9 08 LDA &08b9 ; player_z_high &0d6a 29 c0 AND #&c0 &0d6c 18 CLC &0d6d 69 04 ADC #&04 &0d6f 85 57 STA &57 ; trench_origin_z_high &0d71 a9 f2 LDA #&f2 &0d73 85 58 STA &58 ; trench_origin_x_high &0d75 a0 01 LDY #&01 ; plot_trench_vertical_lines_side_loop &0d77 98 TYA &0d78 48 PHA ; side &0d79 a2 02 LDX #&02 ; plot_trench_vertical_lines_loop &0d7b 8a TXA &0d7c 48 PHA ; line &0d7d a9 00 LDA #&00 &0d7f 85 50 STA &50 ; origin_x &0d81 85 52 STA &52 ; origin_y &0d83 85 54 STA &54 ; origin_z &0d85 a5 58 LDA &58 ; trench_origin_x_high &0d87 85 51 STA &51 ; origin_x_high &0d89 a9 22 LDA #&22 &0d8b 85 53 STA &53 ; origin_y_high &0d8d a5 57 LDA &57 ; trench_origin_z_high &0d8f 85 55 STA &55 ; origin_z_high &0d91 20 9e 3d JSR &3d9e ; calculate_origin_relative_to_player &0d94 20 0a 32 JSR &320a ; apply_player_rotation_to_origin &0d97 20 34 38 JSR &3834 ; calculate_screen_position_for_origin # Sets line_end to origin &0d9a 20 0f 29 JSR &290f ; set_line_start_to_line_end &0d9d a9 00 LDA #&00 &0d9f 8d b0 08 STA &08b0 ; frame_counter &0da2 85 50 STA &50 ; origin_x &0da4 85 52 STA &52 ; origin_y &0da6 85 53 STA &53 ; origin_y_high &0da8 85 54 STA &54 ; origin_z &0daa a5 58 LDA &58 ; trench_origin_x_high &0dac 85 51 STA &51 ; origin_x_high &0dae a5 57 LDA &57 ; trench_origin_z_high &0db0 85 55 STA &55 ; origin_z_high &0db2 18 CLC &0db3 69 40 ADC #&40 &0db5 85 57 STA &57 ; trench_origin_z_high &0db7 20 9e 3d JSR &3d9e ; calculate_origin_relative_to_player &0dba 20 0a 32 JSR &320a ; apply_player_rotation_to_origin &0dbd 20 34 38 JSR &3834 ; calculate_screen_position_for_origin # Sets line_end to origin &0dc0 20 db 23 JSR &23db ; plot_line # Plot trench vertical line &0dc3 68 PLA ; line &0dc4 aa TAX &0dc5 ca DEX &0dc6 10 b3 BPL &0d7b ; plot_trench_vertical_lines_loop &0dc8 a9 0e LDA #&0e &0dca 85 58 STA &58 ; trench_origin_x_high &0dcc 68 PLA ; side &0dcd a8 TAY &0dce 88 DEY &0dcf 10 a6 BPL &0d77 ; plot_trench_vertical_lines_side_loop &0dd1 ad b9 08 LDA &08b9 ; player_z_high &0dd4 18 CLC &0dd5 6d b3 08 ADC &08b3 ; player_z_velocity &0dd8 8d b9 08 STA &08b9 ; player_z_high &0ddb a9 78 LDA #&78 ; &4878 = use_the_force_string &0ddd 85 18 STA &18 ; text_address_low &0ddf a9 48 LDA #&48 &0de1 85 19 STA &19 ; text_address_high &0de3 20 9d 2d JSR &2d9d ; plot_string_to_buffer # Plot "USE THE FORCE" &0de6 20 5a 2b JSR &2b5a ; use_other_buffer_and_wipe &0de9 ad bb 08 LDA &08bb ; player_rotation_about_z &0dec f0 09 BEQ &0df7 ; finished_rotating_trench &0dee 38 SEC &0def e9 08 SBC #&08 &0df1 8d bb 08 STA &08bb ; player_rotation_about_z &0df4 4c 27 0d JMP &0d27 ; trench_stage_rotation_loop ; finished_rotating_trench &0df7 ad b7 08 LDA &08b7 ; player_y_high &0dfa 29 fc AND #&fc &0dfc 8d b7 08 STA &08b7 ; player_y_high &0dff a9 b8 LDA #&b8 ; &07b8 = avoid_catwalks_string &0e01 8d 1b 16 STA &161b ; stage_message_address_low &0e04 a9 07 LDA #&07 &0e06 8d 1f 16 STA &161f ; stage_message_address_high ; trench_stage_main_loop &0e09 ad 12 03 LDA &0312 ; fireball_rotation &0e0c 18 CLC &0e0d 69 08 ADC #&08 # Rotate fireballs clockwise &0e0f 8d 12 03 STA &0312 ; fireball_rotation &0e12 20 56 14 JSR &1456 ; check_for_player_movement &0e15 20 ff 37 JSR &37ff ; rnd &0e18 29 01 AND #&01 &0e1a d0 03 BNE &0e1f ; skip_adding_trench_fireball &0e1c 20 b0 30 JSR &30b0 ; add_trench_fireball ; skip_adding_trench_fireball &0e1f 20 01 16 JSR &1601 ; consider_plotting_stage_message &0e22 ad 8c 08 LDA &088c ; player_movement &0e25 29 01 AND #&01 ; MOVING_LEFT &0e27 f0 10 BEQ &0e39 ; not_moving_left &0e29 ad b5 08 LDA &08b5 ; player_x_high &0e2c c9 f7 CMP #&f7 &0e2e f0 09 BEQ &0e39 ; not_moving_left &0e30 ce b5 08 DEC &08b5 ; player_x_high &0e33 ce b5 08 DEC &08b5 ; player_x_high &0e36 ce b5 08 DEC &08b5 ; player_x_high ; not_moving_left &0e39 ad 8c 08 LDA &088c ; player_movement &0e3c 29 02 AND #&02 ; MOVING_RIGHT &0e3e f0 10 BEQ &0e50 ; not_moving_right &0e40 ad b5 08 LDA &08b5 ; player_x_high &0e43 c9 09 CMP #&09 &0e45 f0 09 BEQ &0e50 ; not_moving_right &0e47 ee b5 08 INC &08b5 ; player_x_high &0e4a ee b5 08 INC &08b5 ; player_x_high &0e4d ee b5 08 INC &08b5 ; player_x_high ; not_moving_right &0e50 ad 8c 08 LDA &088c ; player_movement &0e53 29 04 AND #&04 ; MOVING_DOWN &0e55 f0 0f BEQ &0e66 ; not_moving_down &0e57 ad b7 08 LDA &08b7 ; player_y_high &0e5a c9 08 CMP #&08 &0e5c 90 08 BCC &0e66 ; not_moving_down &0e5e ad b7 08 LDA &08b7 ; player_y_high &0e61 e9 04 SBC #&04 &0e63 8d b7 08 STA &08b7 ; player_y_high ; not_moving_down &0e66 ad 8c 08 LDA &088c ; player_movement &0e69 29 08 AND #&08 ; MOVING_UP &0e6b f0 0f BEQ &0e7c ; not_moving_up &0e6d ad b7 08 LDA &08b7 ; player_y_high &0e70 c9 20 CMP #&20 &0e72 b0 08 BCS &0e7c ; not_moving_up &0e74 ad b7 08 LDA &08b7 ; player_y_high &0e77 69 04 ADC #&04 &0e79 8d b7 08 STA &08b7 ; player_y_high ; not_moving_up &0e7c ad 8a 08 LDA &088a ; wave_as_bcd &0e7f c9 01 CMP #&01 &0e81 d0 76 BNE &0ef9 ; not_wave_one ; is_wave_one # On wave one, there are side ports, not catwalks &0e83 ad b9 08 LDA &08b9 ; player_z_high &0e86 85 57 STA &57 ; tmp &0e88 ad ba 08 LDA &08ba ; player_z_highest &0e8b 06 57 ASL &57 ; tmp &0e8d 2a ROL A &0e8e 06 57 ASL &57 ; tmp &0e90 2a ROL A &0e91 aa TAX &0e92 18 CLC &0e93 69 04 ADC #&04 &0e95 85 ce STA &ce ; last_side_port_offset &0e97 ad b9 08 LDA &08b9 ; player_z_high &0e9a 29 c0 AND #&c0 &0e9c 18 CLC &0e9d 69 20 ADC #&20 &0e9f 8d 85 08 STA &0885 ; side_ports_z_high &0ea2 ad ba 08 LDA &08ba ; player_z_highest &0ea5 69 00 ADC #&00 &0ea7 8d 86 08 STA &0886 ; side_ports_z_highest ; plot_wave_one_side_ports_loop &0eaa 8a TXA &0eab 48 PHA ; side port offset &0eac a0 03 LDY #&03 ; G &0eae a9 50 LDA #&50 # Score 50 for hitting green side ports on wave one &0eb0 8d 80 03 STA &0380 ; side_port_score_low &0eb3 a9 00 LDA #&00 &0eb5 8d 81 03 STA &0381 ; side_port_score_high &0eb8 8a TXA &0eb9 29 01 AND #&01 &0ebb f0 0c BEQ &0ec9 ; set_side_port_colour &0ebd a0 02 LDY #&02 ; R &0ebf a9 00 LDA #&00 # Score 100 for hitting red side ports on wave one &0ec1 8d 80 03 STA &0380 ; side_port_score_low &0ec4 a9 01 LDA #&01 &0ec6 8d 81 03 STA &0381 ; side_port_score_high ; set_side_port_colour &0ec9 98 TYA &0eca 20 ab 23 JSR &23ab ; set_colour &0ecd bd 00 01 LDA &0100,X ; wave_side_ports_state &0ed0 8d 9c 08 STA &089c ; side_ports_bitmap &0ed3 20 01 20 JSR &2001 ; plot_set_of_side_ports # Plot side ports &0ed6 85 5f STA &5f ; bitmap &0ed8 68 PLA ; side port offset &0ed9 aa TAX &0eda a5 5f LDA &5f ; bitmap &0edc 9d 00 01 STA &0100,X ; wave_side_ports_state &0edf ad 85 08 LDA &0885 ; side_ports_z_high &0ee2 18 CLC &0ee3 69 40 ADC #&40 &0ee5 8d 85 08 STA &0885 ; side_ports_z_high &0ee8 ad 86 08 LDA &0886 ; side_ports_z_highest &0eeb 69 00 ADC #&00 &0eed 8d 86 08 STA &0886 ; side_ports_z_highest &0ef0 e8 INX &0ef1 e0 40 CPX #&40 &0ef3 b0 04 BCS &0ef9 ; finished_plotting_wave_one_side_ports &0ef5 e4 ce CPX &ce ; last_side_port_offset &0ef7 d0 b1 BNE &0eaa ; plot_wave_one_side_ports_loop ; finished_plotting_wave_one_side_ports ; not_wave_one &0ef9 a9 fc LDA #&fc &0efb 85 47 STA &47 ; point_z_high &0efd ad ba 08 LDA &08ba ; player_z_highest &0f00 c9 10 CMP #&10 &0f02 d0 08 BNE &0f0c ; not_near_end_of_trench # If the player is near the end of the trench, &0f04 a9 fc LDA #&fc &0f06 38 SEC &0f07 ed b9 08 SBC &08b9 ; player_z_high &0f0a 85 47 STA &47 ; point_z_high # the end of the trench becomes nearer, relatively ; not_near_end_of_trench &0f0c a5 47 LDA &47 ; point_z_high &0f0e 8d a9 08 STA &08a9 ; trench_end_relative_z_high &0f11 a2 00 LDX #&00 ; start (far) &0f13 20 e9 16 JSR &16e9 ; calculate_trench_point_screen_position &0f16 20 58 17 JSR &1758 ; plot_trench_far_end # Plot left, right and bottom of far end of trench &0f19 ad ba 08 LDA &08ba ; player_z_highest &0f1c c9 10 CMP #&10 &0f1e d0 17 BNE &0f37 ; skip_plotting_top # If the player is near the end of the trench, &0f20 bd c0 4b LDA &4bc0,X ; trench_points_left_screen_x + 0 (far) &0f23 85 66 STA &66 ; line_end_x &0f25 bd c1 4b LDA &4bc1,X ; trench_points_left_screen_x_high + 0 (far) &0f28 85 67 STA &67 ; line_end_x_high &0f2a bd c0 4c LDA &4cc0,X ; trench_points_top_screen_y + 0 (far) &0f2d 85 68 STA &68 ; line_end_y &0f2f bd c1 4c LDA &4cc1,X ; trench_points_top_screen_y_high + 0 (far) &0f32 85 69 STA &69 ; line_end_y_high &0f34 20 6c 2a JSR &2a6c ; plot_horizontal_line # Plot top of far end of trench ; skip_plotting_top &0f37 a2 04 LDX #&04 ; end (near) &0f39 a9 0a LDA #&0a &0f3b 85 47 STA &47 ; point_z_high &0f3d 20 e9 16 JSR &16e9 ; calculate_trench_point_screen_position &0f40 ad c0 4b LDA &4bc0 ; trench_points_left_screen_x + 0 (far) &0f43 85 62 STA &62 ; line_start_x &0f45 ad c1 4b LDA &4bc1 ; trench_points_left_screen_x_high + 0 (far) &0f48 85 63 STA &63 ; line_start_x_high &0f4a ad c0 4c LDA &4cc0 ; trench_points_top_screen_y + 0 (far) &0f4d 85 64 STA &64 ; line_start_y &0f4f ad c1 4c LDA &4cc1 ; trench_points_top_screen_y_high + 0 (far) &0f52 85 65 STA &65 ; line_start_y_high &0f54 ad c4 4b LDA &4bc4 ; trench_points_left_screen_x + 4 (near) &0f57 85 66 STA &66 ; line_end_x &0f59 ad c5 4b LDA &4bc5 ; trench_points_left_screen_x_high + 4 (near) &0f5c 85 67 STA &67 ; line_end_x_high &0f5e ad c4 4c LDA &4cc4 ; trench_points_top_screen_y + 4 (near) &0f61 85 68 STA &68 ; line_end_y &0f63 ad c5 4c LDA &4cc5 ; trench_points_top_screen_y_high + 4 (near) &0f66 85 69 STA &69 ; line_end_y_high &0f68 20 db 23 JSR &23db ; plot_line # Plot top left diagonal of trench &0f6b ad c0 4b LDA &4bc0 ; trench_points_left_screen_x + 0 (far) &0f6e 85 62 STA &62 ; line_start_x &0f70 ad c1 4b LDA &4bc1 ; trench_points_left_screen_x_high + 0 (far) &0f73 85 63 STA &63 ; line_start_x_high &0f75 ad c2 4c LDA &4cc2 ; trench_points_bottom_screen_y + 0 (far) &0f78 85 64 STA &64 ; line_start_y &0f7a ad c3 4c LDA &4cc3 ; trench_points_bottom_screen_y_high + 0 (far) &0f7d 85 65 STA &65 ; line_start_y_high &0f7f ad c4 4b LDA &4bc4 ; trench_points_left_screen_x + 4 (near) &0f82 85 66 STA &66 ; line_end_x &0f84 ad c5 4b LDA &4bc5 ; trench_points_left_screen_x_high + 4 (near) &0f87 85 67 STA &67 ; line_end_x_high &0f89 ad c6 4c LDA &4cc6 ; trench_points_bottom_screen_y + 4 (near) &0f8c 85 68 STA &68 ; line_end_y &0f8e ad c7 4c LDA &4cc7 ; trench_points_bottom_screen_y_high + 4 (near) &0f91 85 69 STA &69 ; line_end_y_high &0f93 20 db 23 JSR &23db ; plot_line # Plot bottom left diagonal of trench &0f96 ad c2 4b LDA &4bc2 ; trench_points_right_screen_x + 0 (far) &0f99 85 62 STA &62 ; line_start_x &0f9b ad c3 4b LDA &4bc3 ; trench_points_right_screen_x_high + 0 (far) &0f9e 85 63 STA &63 ; line_start_x_high &0fa0 ad c0 4c LDA &4cc0 ; trench_points_top_screen_y + 0 (far) &0fa3 85 64 STA &64 ; line_start_y &0fa5 ad c1 4c LDA &4cc1 ; trench_points_top_screen_y_high + 0 (far) &0fa8 85 65 STA &65 ; line_start_y_high &0faa ad c6 4b LDA &4bc6 ; trench_points_right_screen_x + 4 (near) &0fad 85 66 STA &66 ; line_end_x &0faf ad c7 4b LDA &4bc7 ; trench_points_right_screen_x_high + 4 (near) &0fb2 85 67 STA &67 ; line_end_x_high &0fb4 ad c4 4c LDA &4cc4 ; trench_points_left_screen_x + 4 (near) &0fb7 85 68 STA &68 ; line_end_y &0fb9 ad c5 4c LDA &4cc5 ; trench_points_left_screen_x_high + 4 (near) &0fbc 85 69 STA &69 ; line_end_y_high &0fbe 20 db 23 JSR &23db ; plot_line # Plot top right diagonal of trench &0fc1 ad c2 4b LDA &4bc2 ; trench_points_right_screen_x + 0 (far) &0fc4 85 62 STA &62 ; line_start_x &0fc6 ad c3 4b LDA &4bc3 ; trench_points_right_screen_x_high + 0 (far) &0fc9 85 63 STA &63 ; line_start_x_high &0fcb ad c2 4c LDA &4cc2 ; trench_points_bottom_screen_y + 0 (far) &0fce 85 64 STA &64 ; line_start_y &0fd0 ad c3 4c LDA &4cc3 ; trench_points_bottom_screen_y_high + 0 (far) &0fd3 85 65 STA &65 ; line_start_y_high &0fd5 ad c6 4b LDA &4bc6 ; trench_points_right_screen_x + 4 (near) &0fd8 85 66 STA &66 ; line_end_x &0fda ad c7 4b LDA &4bc7 ; trench_points_right_screen_x_high + 4 (near) &0fdd 85 67 STA &67 ; line_end_x_high &0fdf ad c6 4c LDA &4cc6 ; trench_points_bottom_screen_y + 4 (near) &0fe2 85 68 STA &68 ; line_end_y &0fe4 ad c7 4c LDA &4cc7 ; trench_points_bottom_screen_y_high + 4 (near) &0fe7 85 69 STA &69 ; line_end_y_high &0fe9 20 db 23 JSR &23db ; plot_line # Plot bottom right diagonal of trench &0fec ad a9 08 LDA &08a9 ; trench_end_relative_z_high &0fef 85 47 STA &47 ; point_z_high &0ff1 a9 00 LDA #&00 &0ff3 38 SEC &0ff4 ed b7 08 SBC &08b7 ; player_y_high &0ff7 85 44 STA &44 ; point_y_high &0ff9 a9 f8 LDA #&f8 &0ffb 38 SEC &0ffc ed b5 08 SBC &08b5 ; player_x_high &0fff 85 41 STA &41 ; point_x_high &1001 20 df 38 JSR &38df ; calculate_screen_x_for_point &1004 a5 66 LDA &66 ; screen_x &1006 8d e0 4b STA &4be0 ; trench_points_inner_left_screen_x (far) &1009 a5 67 LDA &67 ; screen_x_high &100b 8d e1 4b STA &4be1 ; trench_points_inner_left_screen_x_high (far) &100e a9 08 LDA #&08 &1010 38 SEC &1011 ed b5 08 SBC &08b5 ; player_x_high &1014 85 41 STA &41 ; point_x_high &1016 20 df 38 JSR &38df ; calculate_screen_x_for_point &1019 a5 66 LDA &66 ; screen_x &101b 8d e2 4b STA &4be2 ; trench_points_inner_right_screen_x + 0 (far) &101e a5 67 LDA &67 ; screen_x_high &1020 8d e3 4b STA &4be3 ; trench_points_inner_right_screen_x_high + 0 (far) &1023 a9 0a LDA #&0a &1025 85 47 STA &47 ; point_z_high &1027 20 df 38 JSR &38df ; calculate_screen_x_for_point &102a a5 66 LDA &66 ; screen_x &102c 8d e6 4b STA &4be6 ; trench_points_inner_right_screen_x + 4 (near) &102f a5 67 LDA &67 ; screen_x_high &1031 8d e7 4b STA &4be7 ; trench_points_inner_right_screen_x_high + 4 (near) &1034 a9 f8 LDA #&f8 &1036 38 SEC &1037 ed b5 08 SBC &08b5 ; player_x_high &103a 85 41 STA &41 ; point_x_high &103c 20 df 38 JSR &38df ; calculate_screen_x_for_point &103f ad c6 4c LDA &4cc6 ; trench_points_bottom_screen_y + 4 (near) &1042 85 68 STA &68 ; line_end_y &1044 ad c7 4c LDA &4cc7 ; trench_points_bottom_screen_y_high + 4 (near) &1047 85 69 STA &69 ; line_end_y_high &1049 20 0f 29 JSR &290f ; set_line_start_to_line_end &104c ad e0 4b LDA &4be0 ; trench_points_inner_left_screen_x (far) &104f 85 66 STA &66 ; line_end_x &1051 ad e1 4b LDA &4be1 ; trench_points_inner_left_screen_x_high (far) &1054 85 67 STA &67 ; line_end_x_high &1056 ad c2 4c LDA &4cc2 ; trench_points_bottom_screen_y + 0 (far) &1059 85 68 STA &68 ; line_end_y &105b ad c3 4c LDA &4cc3 ; trench_points_bottom_screen_y_high + 0 (far) &105e 85 69 STA &69 ; line_end_y_high &1060 20 db 23 JSR &23db ; plot_line # Plot bottom left inner diagonal of trench &1063 ad e2 4b LDA &4be2 ; trench_points_inner_right_screen_x + 0 (far) &1066 85 62 STA &62 ; line_start_x &1068 ad e3 4b LDA &4be3 ; trench_points_inner_right_screen_x_high + 0 (far) &106b 85 63 STA &63 ; line_start_x_high &106d ad e6 4b LDA &4be6 ; trench_points_inner_right_screen_x + 4 (near) &1070 85 66 STA &66 ; line_end_x &1072 ad e7 4b LDA &4be7 ; trench_points_inner_right_screen_x_high + 4 (near) &1075 85 67 STA &67 ; line_end_x_high &1077 ad c6 4c LDA &4cc6 ; trench_points_bottom_screen_y + 4 (near) &107a 85 68 STA &68 ; line_end_y &107c ad c7 4c LDA &4cc7 ; trench_points_bottom_screen_y_high + 4 (near) &107f 85 69 STA &69 ; line_end_y_high &1081 20 db 23 JSR &23db ; plot_line # Plot bottom right inner diagonal of trench &1084 ad b9 08 LDA &08b9 ; player_z_high &1087 29 c0 AND #&c0 &1089 18 CLC &108a 69 04 ADC #&04 &108c 8d 0f 03 STA &030f ; section_z_high &108f ad ba 08 LDA &08ba ; player_z_highest &1092 8d 10 03 STA &0310 ; section_z_highest &1095 a2 02 LDX #&02 ; plot_trench_vertical_sections_loop &1097 ad 0f 03 LDA &030f ; section_z_high &109a 18 CLC &109b 69 40 ADC #&40 # Move towards far end of trench &109d 8d 0f 03 STA &030f ; section_z_high &10a0 08 PHP ; carry &10a1 38 SEC &10a2 ed b9 08 SBC &08b9 ; player_z_high &10a5 85 47 STA &47 ; point_z_high &10a7 28 PLP ; carry &10a8 ad 10 03 LDA &0310 ; section_z_highest &10ab 69 00 ADC #&00 &10ad 8d 10 03 STA &0310 ; section_z_highest &10b0 c9 11 CMP #&11 &10b2 b0 06 BCS &10ba ; skip_vertical_section # Don't plot vertical sections beyond far end of trench &10b4 20 e9 16 JSR &16e9 ; calculate_trench_point_screen_position &10b7 20 5f 17 JSR &175f ; plot_trench_section ; skip_vertical_section &10ba ca DEX &10bb 10 da BPL &1097 ; plot_trench_vertical_sections_loop &10bd ad ba 08 LDA &08ba ; player_z_highest &10c0 c9 10 CMP #&10 &10c2 d0 14 BNE &10d8 ; to_skip_plotting_exhaust_port # If the player is near the end of the trench, &10c4 a9 e0 LDA #&e0 &10c6 38 SEC &10c7 ed b9 08 SBC &08b9 ; player_z_high &10ca 8d 0f 03 STA &030f ; exhaust_port_relative_z_high &10cd c9 c0 CMP #&c0 &10cf b0 07 BCS &10d8 ; to_skip_plotting_exhaust_port &10d1 c9 10 CMP #&10 &10d3 90 03 BCC &10d8 ; to_skip_plotting_exhaust_port &10d5 4c db 10 JMP &10db ; plot_exhaust_port ; to_skip_plotting_exhaust_port &10d8 4c 75 12 JMP &1275 ; skip_plotting_exhaust_port ; plot_exhaust_port # Plot the exhaust port &10db a9 00 LDA #&00 &10dd 38 SEC &10de ed b7 08 SBC &08b7 ; player_y_high &10e1 8d 0d 03 STA &030d ; exhaust_port_relative_y_high &10e4 8a TXA &10e5 48 PHA &10e6 a9 f8 LDA #&f8 &10e8 38 SEC &10e9 ed b5 08 SBC &08b5 ; player_x_high &10ec 8d 0b 03 STA &030b ; exhaust_port_relative_x_high &10ef a9 10 LDA #&10 &10f1 8d b2 08 STA &08b2 ; exhaust_port_size &10f4 a2 02 LDX #&02 ; plot_exhaust_port_loop # For each section of the exhaust port, &10f6 8a TXA &10f7 0a ASL A &10f8 0a ASL A &10f9 a8 TAY &10fa bd c9 23 LDA &23c9,X ; colours_pixel_value_table + 1 &10fd 85 1a STA &1a ; colour_pixel_value &10ff bd cd 23 LDA &23cd,X ; colours_table + 1 &1102 20 ab 23 JSR &23ab ; set_colour &1105 8a TXA &1106 0a ASL A &1107 aa TAX &1108 ad 0b 03 LDA &030b ; exhaust_port_relative_x_high &110b 85 41 STA &41 ; point_x_high &110d ad 0d 03 LDA &030d ; exhaust_port_relative_y_high &1110 85 44 STA &44 ; point_y_high &1112 ad 0f 03 LDA &030f ; exhaust_port_relative_z_high &1115 85 47 STA &47 ; point_z_high &1117 a9 00 LDA #&00 &1119 85 40 STA &40 ; point_x &111b 85 43 STA &43 ; point_y &111d 85 46 STA &46 ; point_z &111f 20 4c 38 JSR &384c ; calculate_screen_position_for_point &1122 a5 66 LDA &66 ; screen_x &1124 99 c0 4b STA &4bc0,Y ; exhaust_port_points_screen_x + 0 (far left) &1127 a5 67 LDA &67 ; screen_x_high &1129 99 e0 4b STA &4be0,Y ; exhaust_port_points_screen_x_high + 0 (far left) &112c a5 68 LDA &68 ; screen_y &112e 9d c0 4c STA &4cc0,X ; exhaust_port_points_screen_y + 0 (far) &1131 a5 69 LDA &69 ; screen_y_high &1133 9d e0 4c STA &4ce0,X ; exhaust_port_points_screen_y_high + 0 (far) &1136 20 0f 29 JSR &290f ; set_line_start_to_line_end # Use screen_* for line start &1139 ad 0b 03 LDA &030b ; exhaust_port_relative_x_high &113c 18 CLC &113d 6d b2 08 ADC &08b2 ; exhaust_port_size &1140 85 41 STA &41 ; point_x_high &1142 20 df 38 JSR &38df ; calculate_screen_x_for_point &1145 a5 66 LDA &66 ; screen_x &1147 99 c1 4b STA &4bc1,Y ; exhaust_port_points_screen_x + 1 (far right) &114a a5 67 LDA &67 ; screen_x_high &114c 99 e1 4b STA &4be1,Y ; exhaust_port_points_screen_x_high + 1 (far right) &114f 20 6c 2a JSR &2a6c ; plot_horizontal_line # Plot far edge of exhaust port &1152 ad 0b 03 LDA &030b ; exhaust_port_relative_x_high &1155 18 CLC &1156 6d b2 08 ADC &08b2 ; exhaust_port_size &1159 85 41 STA &41 ; point_x_high &115b ad 0d 03 LDA &030d ; exhaust_port_relative_y_high &115e 85 44 STA &44 ; point_y_high &1160 ad 0f 03 LDA &030f ; exhaust_port_relative_z_high &1163 38 SEC &1164 ed b2 08 SBC &08b2 ; exhaust_port_size &1167 85 47 STA &47 ; point_z_high &1169 a9 00 LDA #&00 &116b 85 40 STA &40 ; point_x &116d 85 43 STA &43 ; point_y &116f 85 46 STA &46 ; point_z &1171 20 4c 38 JSR &384c ; calculate_screen_position_for_point &1174 a5 66 LDA &66 ; screen_x &1176 99 c2 4b STA &4bc2,Y ; exhaust_port_points_screen_x + 2 (near left) &1179 a5 67 LDA &67 ; screen_x_high &117b 99 e2 4b STA &4be2,Y ; exhaust_port_points_screen_x_high + 2 (near left) &117e a5 68 LDA &68 ; screen_y &1180 9d c1 4c STA &4cc1,X ; exhaust_port_points_screen_y + 1 (near) &1183 a5 69 LDA &69 ; screen_y_high &1185 9d e1 4c STA &4ce1,X ; exhaust_port_points_screen_y_high + 1 (near) &1188 e0 04 CPX #&04 &118a d0 06 BNE &1192 ; plot_right_edge_of_exhaust_port &118c 20 0f 29 JSR &290f ; set_line_start_to_line_end # Use screen_* for line start &118f 4c 95 11 JMP &1195 ; skip_plotting_right_edge_of_exhaust_port ; plot_right_edge_of_exhaust_port &1192 20 db 23 JSR &23db ; plot_line # Plot right edge of exhaust port ; skip_plotting_right_edge_of_exhaust_port &1195 a5 64 LDA &64 ; line_start_y &1197 85 68 STA &68 ; line_end_y &1199 a5 65 LDA &65 ; line_start_y_high &119b 85 69 STA &69 ; line_end_y_high &119d ad 0b 03 LDA &030b ; exhaust_port_relative_x_high &11a0 85 41 STA &41 ; point_x_high &11a2 20 df 38 JSR &38df ; calculate_screen_x_for_point &11a5 a5 66 LDA &66 ; line_end_x &11a7 99 c3 4b STA &4bc3,Y ; exhaust_port_points_screen_x + 3 (near right) &11aa a5 67 LDA &67 ; line_end_x_high &11ac 99 e3 4b STA &4be3,Y ; exhaust_port_points_screen_x_high + 3 (near right) &11af 20 6c 2a JSR &2a6c ; plot_horizontal_line # Plot near edge of exhaust port &11b2 b9 c0 4b LDA &4bc0,Y ; exhaust_port_points_screen_x + 0 (far left) &11b5 85 66 STA &66 ; line_end_x &11b7 b9 e0 4b LDA &4be0,Y ; exhaust_port_points_screen_x_high + 0 (far left) &11ba 85 67 STA &67 ; line_end_x_high &11bc bd c0 4c LDA &4cc0,X ; exhaust_port_points_screen_y + 0 (far) &11bf 85 68 STA &68 ; line_end_y &11c1 bd e0 4c LDA &4ce0,X ; exhaust_port_points_screen_y_high + 0 (far) &11c4 85 69 STA &69 ; line_end_y_high &11c6 e0 04 CPX #&04 &11c8 d0 06 BNE &11d0 ; plot_exhaust_port_left_edge &11ca 20 0f 29 JSR &290f ; set_line_start_to_line_end &11cd 4c d3 11 JMP &11d3 ; skip_plotting_exhaust_port_left_edge ; plot_exhaust_port_left_edge &11d0 20 db 23 JSR &23db ; plot_line # Plot left edge of exhaust port ; skip_plotting_exhaust_port_left_edge &11d3 ad b2 08 LDA &08b2 ; exhaust_port_size &11d6 38 SEC &11d7 e9 06 SBC #&06 &11d9 8d b2 08 STA &08b2 ; exhaust_port_size &11dc ad 0b 03 LDA &030b ; exhaust_port_relative_x_high &11df 18 CLC &11e0 69 03 ADC #&03 &11e2 8d 0b 03 STA &030b ; exhaust_port_relative_x_high &11e5 ad 0f 03 LDA &030f ; exhaust_port_relative_z_high &11e8 38 SEC &11e9 e9 03 SBC #&03 &11eb 8d 0f 03 STA &030f ; exhaust_port_relative_z_high &11ee 8a TXA &11ef 4a LSR A &11f0 aa TAX &11f1 ca DEX &11f2 30 03 BMI &11f7 ; finished_plotting_exhaust_port &11f4 4c f6 10 JMP &10f6 ; plot_exhaust_port_loop ; finished_plotting_exhaust_port &11f7 a9 03 LDA #&03 ; G &11f9 20 ab 23 JSR &23ab ; set_colour &11fc a0 07 LDY #&07 ; plot_exhaust_port_diagonals_loop &11fe 98 TYA &11ff 4a LSR A &1200 aa TAX &1201 18 CLC &1202 69 01 ADC #&01 &1204 20 ab 23 JSR &23ab ; set_colour &1207 b9 c0 4b LDA &4bc0,Y ; exhaust_port_points_screen_x + 0 &120a 85 62 STA &62 ; line_start_x &120c b9 e0 4b LDA &4be0,Y ; exhaust_port_points_screen_x_high + 0 &120f 85 63 STA &63 ; line_start_x_high &1211 bd c0 4c LDA &4cc0,X ; exhaust_port_points_screen_y &1214 85 64 STA &64 ; line_start_y &1216 bd e0 4c LDA &4ce0,X ; exhaust_port_points_screen_y_high &1219 85 65 STA &65 ; line_start_y_high &121b b9 c4 4b LDA &4bc4,Y ; exhaust_port_points_screen_x + 4 &121e 85 66 STA &66 ; line_end_x &1220 b9 e4 4b LDA &4be4,Y ; exhaust_port_points_screen_x_high + 4 &1223 85 67 STA &67 ; line_end_x_high &1225 bd c2 4c LDA &4cc2,X ; exhaust_port_points_screen_y + 2 &1228 85 68 STA &68 ; line_end_y &122a bd e2 4c LDA &4ce2,X ; exhaust_port_points_screen_y_high + 2 &122d 85 69 STA &69 ; line_end_y_high &122f 20 db 23 JSR &23db ; plot_line # Plot exhaust port diagonal &1232 88 DEY &1233 10 c9 BPL &11fe ; plot_exhaust_port_diagonals_loop ; check_for_hitting_exhaust_port &1235 a9 00 LDA #&00 &1237 85 40 STA &40 ; point_x &1239 85 43 STA &43 ; point_y &123b 85 46 STA &46 ; point_z &123d ad 0b 03 LDA &030b ; exhaust_port_relative_x_high &1240 38 SEC &1241 e9 01 SBC #&01 &1243 85 41 STA &41 ; point_x_high &1245 ad 0d 03 LDA &030d ; exhaust_port_relative_y_high &1248 85 44 STA &44 ; point_y_high &124a ad 0f 03 LDA &030f ; exhaust_port_relative_z_high &124d 18 CLC &124e 69 01 ADC #&01 &1250 85 47 STA &47 ; point_z_high &1252 85 55 STA &55 ; origin_z_high &1254 20 4c 38 JSR &384c ; calculate_screen_position_for_point &1257 a5 66 LDA &66 ; screen_x &1259 8d 02 03 STA &0302 ; target_x &125c a5 67 LDA &67 ; screen_x_high &125e 8d 03 03 STA &0303 ; target_x_high &1261 a5 68 LDA &68 ; screen_y &1263 8d 04 03 STA &0304 ; target_y &1266 a5 69 LDA &69 ; screen_y_high &1268 8d 05 03 STA &0305 ; target_y_high &126b a9 08 LDA #&08 &126d 20 5d 42 JSR &425d ; check_for_player_hitting_target # Returns negative if player hit target &1270 10 03 BPL &1275 ; no_hit &1272 20 de 33 JSR &33de ; hit_exhaust_port ; no_hit ; skip_plotting_exhaust_port &1275 a9 00 LDA #&00 &1277 8d 90 08 STA &0890 ; collided_with_catwalk &127a ad 8a 08 LDA &088a ; wave_as_bcd &127d c9 01 CMP #&01 &127f d0 03 BNE &1284 ; plot_catwalks &1281 4c 0a 13 JMP &130a ; skip_plotting_catwalks ; plot_catwalks # On wave two and after, there are catwalks &1284 ad ba 08 LDA &08ba ; player_z_highest &1287 85 5f STA &5f ; tmp &1289 ad b9 08 LDA &08b9 ; player_z_high &128c 29 e0 AND #&e0 &128e 46 5f LSR &5f ; tmp &1290 6a ROR A &1291 46 5f LSR &5f ; tmp &1293 6a ROR A &1294 46 5f LSR &5f ; tmp &1296 6a ROR A &1297 46 5f LSR &5f ; tmp &1299 6a ROR A &129a 4a LSR A &129b 4a LSR A &129c aa TAX &129d ca DEX &129e 86 57 STX &57 ; last_catwalk_offset &12a0 18 CLC &12a1 69 03 ADC #&03 # actually ADC catwalk_offset_addition # Always &03 &12a3 aa TAX ; catwalk offset &12a4 ad b9 08 LDA &08b9 ; player_z_high &12a7 29 c0 AND #&c0 &12a9 18 CLC &12aa 69 14 ADC #&14 &12ac 8d 0f 03 STA &030f ; catwalk_relative_z_high &12af ad ba 08 LDA &08ba ; player_z_highest &12b2 69 00 ADC #&00 &12b4 8d 10 03 STA &0310 ; catwalk_relative_z_highest &12b7 ad 0f 03 LDA &030f ; catwalk_relative_z_high &12ba 18 CLC &12bb 69 c0 ADC #&c0 # actually ADC catwalk_relative_z_high_addition # Always &c0 &12bd 8d 0f 03 STA &030f ; catwalk_relative_z_high &12c0 ad 10 03 LDA &0310 ; catwalk_relative_z_highest &12c3 69 00 ADC #&00 &12c5 8d 10 03 STA &0310 ; catwalk_relative_z_highest ; plot_catwalks_loop &12c8 bd 00 01 LDA &0100,X ; wave_catwalks_state &12cb 8d 8f 08 STA &088f ; catwalks_bitmap &12ce 8a TXA &12cf 48 PHA ; catwalk offset &12d0 29 03 AND #&03 &12d2 a8 TAY &12d3 b9 c8 23 LDA &23c8,Y ; colours_pixel_value_table &12d6 85 1a STA &1a ; colour_pixel_value &12d8 b9 cc 23 LDA &23cc,Y ; colours_table &12db 20 ab 23 JSR &23ab ; set_colour &12de ad 0f 03 LDA &030f ; catwalk_relative_z_high &12e1 38 SEC &12e2 ed b9 08 SBC &08b9 ; player_z_high &12e5 85 47 STA &47 ; point_z_high &12e7 ad 0f 03 LDA &030f ; catwalk_relative_z_high &12ea 38 SEC &12eb e9 40 SBC #&40 &12ed 8d 0f 03 STA &030f ; catwalk_relative_z_high &12f0 ad 10 03 LDA &0310 ; catwalk_relative_z_highest &12f3 e9 00 SBC #&00 &12f5 8d 10 03 STA &0310 ; catwalk_relative_z_highest &12f8 c9 10 CMP #&10 &12fa b0 07 BCS &1303 ; skip_plotting_catwalk &12fc e0 40 CPX #&40 &12fe b0 03 BCS &1303 ; skip_plotting_catwalk &1300 20 c2 17 JSR &17c2 ; plot_set_of_catwalks # Plot catwalks ; skip_plotting_catwalk &1303 68 PLA ; catwalk offset &1304 aa TAX &1305 ca DEX &1306 e4 57 CPX &57 ; last_catwalk_offset &1308 d0 be BNE &12c8 ; plot_catwalks_loop ; skip_plotting_catwalks &130a ad 90 08 LDA &0890 ; collided_with_catwalk # Negative if player hit catwalk &130d 10 0b BPL &131a ; no_collision &130f 20 72 23 JSR &2372 ; lose_shield # Lose shield for hitting catwalk &1312 10 03 BPL &1317 ; not_end_of_game &1314 4c 53 14 JMP &1453 ; to_game_over_screen ; not_end_of_game &1317 20 4c 3e JSR &3e4c ; plot_shields ; no_collision &131a a9 50 LDA #&50 # Score 50 for hitting side ports at end of trench &131c 8d 80 03 STA &0380 ; side_port_score_low &131f a9 00 LDA #&00 &1321 8d 81 03 STA &0381 ; side_port_score_high &1324 a9 03 LDA #&03 ; G &1326 20 ab 23 JSR &23ab ; set_colour &1329 a9 10 LDA #&10 &132b 8d 86 08 STA &0886 ; side_ports_z_highest &132e ad 82 08 LDA &0882 ; first_far_side_ports_bitmap &1331 8d 9c 08 STA &089c ; side_ports_bitmap &1334 a9 90 LDA #&90 &1336 8d 85 08 STA &0885 ; side_ports_z_high &1339 20 01 20 JSR &2001 ; plot_set_of_side_ports # Plot first set of side ports at end of trench &133c 8d 82 08 STA &0882 ; first_far_side_ports_bitmap &133f ad 83 08 LDA &0883 ; second_far_side_ports_bitmap &1342 8d 9c 08 STA &089c ; side_ports_bitmap &1345 a9 d0 LDA #&d0 &1347 8d 85 08 STA &0885 ; side_ports_z_high &134a 20 01 20 JSR &2001 ; plot_set_of_side_ports # Plot second set of side ports at end of trench &134d 8d 83 08 STA &0883 ; second_far_side_ports_bitmap &1350 ad ba 08 LDA &08ba ; player_z_highest &1353 c9 10 CMP #&10 &1355 90 5c BCC &13b3 ; skip_plotting_exhaust_port_ahead &1357 a9 89 LDA #&89 ; &4889 = exhaust_port_ahead_string &1359 85 18 STA &18 ; text_address_low &135b a9 48 LDA #&48 &135d 85 19 STA &19 ; text_address_high &135f 20 9d 2d JSR &2d9d ; plot_string_to_buffer # Plot "EXHAUST PORT AHEAD" &1362 ad e8 46 LDA &46e8 ; player_used_the_force &1365 d0 4c BNE &13b3 ; skip_scoring_for_using_the_force &1367 a9 0f LDA #&0f ; CC &1369 85 1a STA &1a ; colour_pixel_value &136b a9 18 LDA #&18 &136d 85 16 STA &16 ; text_screen_offset_low &136f a9 05 LDA #&05 &1371 85 17 STA &17 ; text_screen_offset_high &1373 ae 8a 08 LDX &088a ; wave_as_bcd &1376 e0 05 CPX #&05 &1378 90 02 BCC &137c ; skip_ceiling &137a a2 05 LDX #&05 ; skip_ceiling &137c ca DEX &137d bd d9 46 LDA &46d9,X ; points_for_using_the_force_hundred_thousands &1380 20 2a 2d JSR &2d2a ; plot_character &1383 bd de 46 LDA &46de,X ; points_for_using_the_force_ten_thousands &1386 20 2a 2d JSR &2d2a ; plot_character &1389 bd e3 46 LDA &46e3,X ; points_for_using_the_force_thousands &138c 20 2a 2d JSR &2d2a ; plot_character &138f a9 da LDA #&da ; &07da = for_using_the_force_string &1391 85 18 STA &18 ; text_address_low &1393 a9 07 LDA #&07 &1395 85 19 STA &19 ; text_address_high &1397 20 9d 2d JSR &2d9d ; plot_string_to_buffer &139a ad b9 08 LDA &08b9 ; player_z_high &139d cd b3 08 CMP &08b3 ; player_z_velocity # Always &0c here &13a0 b0 11 BCS &13b3 ; skip_scoring_for_using_the_force &13a2 ad e9 46 LDA &46e9 ; using_the_force_score &13a5 85 71 STA &71 ; number + 1 &13a7 ad ea 46 LDA &46ea ; using_the_force_score + 1 &13aa 85 72 STA &72 ; number + 2 &13ac a9 00 LDA #&00 &13ae 85 70 STA &70 ; number &13b0 20 2f 16 JSR &162f ; add_to_score # Score depending on wave for using the force ; skip_scoring_for_using_the_force ; skip_plotting_exhaust_port_ahead &13b3 ad b9 08 LDA &08b9 ; player_z_high &13b6 18 CLC &13b7 6d b3 08 ADC &08b3 ; player_z_velocity # Move player forward &13ba 8d b9 08 STA &08b9 ; player_z_high &13bd ad ba 08 LDA &08ba ; player_z_highest &13c0 69 00 ADC #&00 &13c2 c9 11 CMP #&11 &13c4 90 1d BCC &13e3 ; not_end_of_trench ; at_end_of_trench &13c6 20 1c 23 JSR &231c ; reset_side_ports &13c9 a9 20 LDA #&20 &13cb 8d b7 08 STA &08b7 ; player_y_high &13ce 8d e8 46 STA &46e8 ; player_used_the_force # Set to non-zero to indicate player didn't use the force &13d1 a9 20 LDA #&20 &13d3 8d 87 08 STA &0887 ; exhaust_port_missed_cooldown &13d6 20 72 23 JSR &2372 ; lose_shield # Lose shield for missing exhaust port &13d9 30 78 BMI &1453 ; to_game_over_screen &13db 20 4c 3e JSR &3e4c ; plot_shields &13de a9 00 LDA #&00 &13e0 8d b5 08 STA &08b5 ; player_x_high ; not_end_of_trench &13e3 8d ba 08 STA &08ba ; player_z_highest &13e6 ad ba 08 LDA &08ba ; player_z_highest &13e9 c9 10 CMP #&10 &13eb b0 09 BCS &13f6 ; skip_losing_force &13ed ad e8 46 LDA &46e8 ; player_used_the_force &13f0 0d 00 03 ORA &0300 ; player_is_firing # Non-zero if player is firing &13f3 8d e8 46 STA &46e8 ; player_used_the_force # Lose using force if player fired before end of trench ; skip_losing_force &13f6 ad 87 08 LDA &0887 ; exhaust_port_missed_cooldown &13f9 30 0e BMI &1409 ; skip_plotting_exhaust_port_missed &13fb a9 9f LDA #&9f ; &489f = exhaust_port_missed_string &13fd 85 18 STA &18 ; text_address_low &13ff a9 48 LDA #&48 &1401 85 19 STA &19 ; text_address_high &1403 20 9d 2d JSR &2d9d ; plot_string_to_buffer # Plot "EXHAUST PORT MISSED" &1406 ce 87 08 DEC &0887 ; exhaust_port_missed_cooldown ; skip_plotting_exhaust_port_missed &1409 a2 8f LDX #&8f ; ESCAPE &140b 20 8d 39 JSR &398d ; check_for_keypress &140e f0 43 BEQ &1453 ; to_game_over_screen &1410 20 41 3d JSR &3d41 ; consider_firing &1413 ee b0 08 INC &08b0 ; frame_counter &1416 ad ff 48 LDA &48ff ; exhaust_port_hit # Negative if exhaust port hit &1419 10 0a BPL &1425 ; not_completed &141b ad b9 08 LDA &08b9 ; player_z_high &141e c9 d0 CMP #&d0 &1420 90 03 BCC &1425 ; not_completed &1422 4c 5c 32 JMP &325c ; wave_completion_screen ; not_completed &1425 20 0e 34 JSR &340e ; update_exhaust_port_torpedoes &1428 20 3e 30 JSR &303e ; update_trench_fireballs &142b ad e8 46 LDA &46e8 ; player_used_the_force &142e d0 12 BNE &1442 ; skip_plotting_use_the_force &1430 ad ba 08 LDA &08ba ; player_z_highest &1433 c9 10 CMP #&10 &1435 b0 0b BCS &1442 ; skip_plotting_use_the_force &1437 a9 78 LDA #&78 ; &4878 = use_the_force_string &1439 85 18 STA &18 ; text_address_low &143b a9 48 LDA #&48 &143d 85 19 STA &19 ; text_address_high &143f 20 9d 2d JSR &2d9d ; plot_string_to_buffer # Plot "USE THE FORCE" ; skip_plotting_use_the_force &1442 20 26 16 JSR &1626 ; update_player_hit_cooldown &1445 20 5a 2b JSR &2b5a ; use_other_buffer_and_wipe &1448 20 b3 16 JSR &16b3 ; consider_wiping_recent_score &144b ad 8d 03 LDA &038d ; shields &144e 30 03 BMI &1453 ; to_game_over_screen &1450 4c 09 0e JMP &0e09 ; trench_stage_main_loop ; to_game_over_screen &1453 4c ac 3c JMP &3cac ; game_over_screen ; check_for_player_movement &1456 a9 00 LDA #&00 &1458 8d 8c 08 STA &088c ; player_movement &145b ae 97 39 LDX &3997 ; key_left &145e 20 8d 39 JSR &398d ; check_for_keypress &1461 d0 15 BNE &1478 ; not_moving_left &1463 a9 01 LDA #&01 ; MOVING_LEFT &1465 8d 8c 08 STA &088c ; player_movement &1468 ad 13 03 LDA &0313 ; player_x &146b c9 10 CMP #&10 &146d f0 09 BEQ &1478 ; not_moving_left &146f ad 13 03 LDA &0313 ; player_x &1472 38 SEC &1473 e9 08 SBC #&08 &1475 8d 13 03 STA &0313 ; player_x ; not_moving_left &1478 ae 98 39 LDX &3998 ; key_right &147b 20 8d 39 JSR &398d ; check_for_keypress &147e d0 18 BNE &1498 ; not_moving_right &1480 ad 8c 08 LDA &088c ; player_movement &1483 09 02 ORA #&02 ; MOVING_RIGHT &1485 8d 8c 08 STA &088c ; player_movement &1488 ad 13 03 LDA &0313 ; player_x &148b c9 70 CMP #&70 &148d f0 09 BEQ &1498 ; not_moving_right &148f ad 13 03 LDA &0313 ; player_x &1492 18 CLC &1493 69 08 ADC #&08 &1495 8d 13 03 STA &0313 ; player_x ; not_moving_right &1498 ae 99 39 LDX &3999 ; key_down &149b 20 8d 39 JSR &398d ; check_for_keypress &149e d0 18 BNE &14b8 ; not_moving_down &14a0 ad 8c 08 LDA &088c ; player_movement &14a3 09 04 ORA #&04 ; MOVING_DOWN &14a5 8d 8c 08 STA &088c ; player_movement &14a8 ad 14 03 LDA &0314 ; player_y &14ab c9 18 CMP #&18 &14ad f0 09 BEQ &14b8 ; not_moving_down &14af ad 14 03 LDA &0314 ; player_y &14b2 38 SEC &14b3 e9 08 SBC #&08 &14b5 8d 14 03 STA &0314 ; player_y ; not_moving_down &14b8 ae 9a 39 LDX &399a ; key_up &14bb 20 8d 39 JSR &398d ; check_for_keypress &14be d0 18 BNE &14d8 ; not_moving_up &14c0 ad 8c 08 LDA &088c ; player_movement &14c3 09 08 ORA #&08 ; MOVING_UP &14c5 8d 8c 08 STA &088c ; player_movement &14c8 ad 14 03 LDA &0314 ; player_y &14cb c9 98 CMP #&98 &14cd f0 09 BEQ &14d8 ; not_moving_up &14cf ad 14 03 LDA &0314 ; player_y &14d2 18 CLC &14d3 69 08 ADC #&08 &14d5 8d 14 03 STA &0314 ; player_y ; not_moving_up &14d8 ad 8c 08 LDA &088c ; player_movement &14db d0 2f BNE &150c ; leave &14dd ad 00 03 LDA &0300 ; player_is_firing # Non-zero if player is firing; otherwise, centre player &14e0 d0 2a BNE &150c ; leave &14e2 ad 13 03 LDA &0313 ; player_x &14e5 c9 40 CMP #&40 &14e7 f0 0e BEQ &14f7 ; skip_centring_in_x &14e9 b0 06 BCS &14f1 ; move_left_towards_centre ; move_right_towards_centre &14eb 18 CLC &14ec 69 08 ADC #&08 &14ee 4c f4 14 JMP &14f4 ; set_player_x ; move_left_towards_centre &14f1 38 SEC &14f2 e9 08 SBC #&08 ; set_player_x &14f4 8d 13 03 STA &0313 ; player_x ; skip_centring_in_x &14f7 ad 14 03 LDA &0314 ; player_y &14fa c9 50 CMP #&50 &14fc f0 0e BEQ &150c ; skip_centring_in_y &14fe b0 06 BCS &1506 ; move_down_towards_centre ; move_up_towards_centre &1500 18 CLC &1501 69 08 ADC #&08 &1503 4c 09 15 JMP &1509 ; set_player_y ; move_down_towards_centre &1506 38 SEC &1507 e9 08 SBC #&08 ; set_player_y &1509 8d 14 03 STA &0314 ; player_y ; skip_centring_in_y ; leave &150c 60 RTS ; update_tower &150d a2 0f LDX #&0f # Include top of tower by default &150f b1 24 LDA (&24),Y ; left_towers_state_address # Non-zero if tower has been destroyed # actually LDA (towers_state_address_one),Y &1511 f0 02 BEQ &1515 ; not_destroyed &1513 a2 09 LDX #&09 # Remove top of tower ; not_destroyed &1515 8e 11 4e STX &4e11 ; models_number_of_lines_table + 1 (MODEL_TOWER) &1518 ad 8a 08 LDA &088a ; wave_as_bcd &151b c9 02 CMP #&02 &151d d0 07 BNE &1526 ; plot_tower # On wave two, &151f e0 09 CPX #&09 &1521 d0 03 BNE &1526 ; plot_tower # if the tower has been destroyed, there is nothing to plot &1523 4c d0 15 JMP &15d0 ; leave ; plot_tower &1526 a9 00 LDA #&00 &1528 85 50 STA &50 ; origin_x &152a 85 52 STA &52 ; origin_y &152c 85 54 STA &54 ; origin_z &152e a9 0e LDA #&0e # actually LDA tower_y_high &1530 85 53 STA &53 ; origin_y_high &1532 a5 5a LDA &5a ; tower_z_high &1534 85 55 STA &55 ; origin_z_high &1536 ad 11 4e LDA &4e11 ; models_number_of_lines_table + 1 (MODEL_TOWER) &1539 c9 09 CMP #&09 &153b f0 03 BEQ &1540 ; skip_adding_fireballs # If the tower has been destroyed, it doesn't fire &153d 20 75 2f JSR &2f75 ; add_surface_fireball ; skip_adding_fireballs &1540 20 3d 3a JSR &3a3d ; plot_model_relative_to_player # Plot tower, returns negative if behind player &1543 10 03 BPL &1548 ; consider_checking_for_hit &1545 4c d0 15 JMP &15d0 ; leave ; consider_checking_for_hit &1548 ac fa 4f LDY &4ffa ; tower_to_update &154b b1 24 LDA (&24),Y ; left_towers_state_address # Non-zero if tower has been hit # actually LDA (towers_state_address_two),Y &154d d0 4e BNE &159d ; skip_checking_for_hit # If so, can't be hit again &154f a9 08 LDA #&08 # actually LDA tower_target_size &1551 20 5d 42 JSR &425d ; check_for_player_hitting_target # Returns negative if player hit target &1554 10 47 BPL &159d ; skip_checking_for_hit ; destroy_tower &1556 ad 2f 15 LDA &152f ; tower_y_high &1559 85 53 STA &53 ; origin_y_high &155b ad f9 4f LDA &4ff9 ; tower_x_high &155e 85 51 STA &51 ; origin_x_high &1560 a5 5a LDA &5a ; tower_z_high &1562 85 55 STA &55 ; origin_z_high &1564 20 14 43 JSR &4314 ; add_exploding_tower &1567 a9 00 LDA #&00 &1569 20 de 44 JSR &44de ; play_sound # Play sound for destroying tower &156c a9 08 LDA #&08 &156e 20 de 44 JSR &44de ; play_sound # Play sound for destroying tower &1571 a9 01 LDA #&01 &1573 91 24 STA (&24),Y ; left_towers_state_address # Set to non-zero to indicate tower destroyed # actually STA (towers_state_address_three),Y &1575 20 c8 1f JSR &1fc8 ; update_towers_remaining &1578 a9 00 LDA #&00 &157a 85 70 STA &70 ; number &157c 85 72 STA &72 ; number + 2 &157e 85 73 STA &73 ; number + 3 &1580 ad ac 08 LDA &08ac ; points_next_tower &1583 85 71 STA &71 ; number + 1 &1585 ad 8a 08 LDA &088a ; wave_as_bcd &1588 c9 02 CMP #&02 &158a f0 0e BEQ &159a ; skip_plotting_points_next_tower &158c f8 SED &158d ad ac 08 LDA &08ac ; points_next_tower &1590 18 CLC &1591 69 02 ADC #&02 &1593 8d ac 08 STA &08ac ; points_next_tower &1596 d8 CLD &1597 20 8e 1f JSR &1f8e ; plot_points_next_tower ; skip_plotting_points_next_tower &159a 20 2f 16 JSR &162f ; add_to_score # Score for destroying tower ; skip_checking_for_hit &159d ad 11 03 LDA &0311 ; model_origin_x_high &15a0 18 CLC &15a1 69 05 ADC #&05 &15a3 c9 0a CMP #&0a &15a5 b0 29 BCS &15d0 ; skip_hitting_tower &15a7 a5 55 LDA &55 ; origin_z_high &15a9 c9 08 CMP #&08 &15ab b0 23 BCS &15d0 ; skip_hitting_tower &15ad ad 8a 08 LDA &088a ; wave_as_bcd &15b0 c9 02 CMP #&02 &15b2 d0 05 BNE &15b9 ; crashed_into_tower &15b4 ad b7 08 LDA &08b7 ; player_y_high &15b7 d0 17 BNE &15d0 ; skip_hitting_tower ; crashed_into_tower &15b9 20 72 23 JSR &2372 ; lose_shield &15bc a9 09 LDA #&09 &15be 85 cc STA &cc ; player_tower_crash_cooldown &15c0 ad 11 03 LDA &0311 ; move_left_out_of_crash &15c3 30 04 BMI &15c9 ; set_right ; move_left_out_of_crash &15c5 a9 01 LDA #&01 ; MOVING_LEFT &15c7 d0 02 BNE &15cb ; set_player_tower_crash_movement # Always branches ; move_right_out_of_crash &15c9 a9 02 LDA #&02 ; MOVING_RIGHT ; set_player_tower_crash_movement &15cb 85 cd STA &cd ; player_tower_crash_movement &15cd 20 4c 3e JSR &3e4c ; plot_shields ; skip_hitting_tower ; leave &15d0 60 RTS # &15d1 - &1600 is a copy of &31d1 - &3200; values are overwritten ; tie_fighters_x &15d1 02 85 cf 20 ; tie_fighters_x_high &15d5 ec 31 68 aa ; tie_fighters_y &15d9 fe fc 03 bd ; tie_fighters_y_high &15dd e0 03 18 69 ; tie_fighters_z &15e1 08 9d e0 03 ; tie_fighters_z_high &15e5 ca 30 03 4c ; tie_fighters_rotation &15e9 5a 31 60 bd ; tie_fighters_rotation_velocity &15ed ec 03 18 79 ; tie_fighters_state &15f1 42 43 85 52 ; tie_fighters_xy_velocity &15f5 bd f0 03 79 ; unused &15f9 4e 43 85 53 ; tie_fighters_z_velocity &15fd bd f4 03 85 ; consider_plotting_stage_message &1601 ad b0 08 LDA &08b0 ; frame_counter &1604 29 1f AND #&1f &1606 d0 0e BNE &1616 ; skip_plotting_shoot_fireballs &1608 a9 ce LDA #&ce ; &48ce = shoot_fireballs_string &160a 85 18 STA &18 ; text_address_low &160c a9 48 LDA #&48 &160e 85 19 STA &19 ; text_address_high &1610 20 88 2d JSR &2d88 ; plot_string # Plot "SHOOT FIREBALLS" &1613 4c 25 16 JMP &1625 ; skip_plotting_shoot_tie_fighters ; skip_plotting_shoot_fireballs &1616 c9 10 CMP #&10 &1618 d0 0b BNE &1625 ; skip_plotting_shoot_tie_fighters &161a a9 e4 LDA #&e4 ; &48e4 = shoot_tie_fighters_string # actually LDA stage_message_address_low &161c 85 18 STA &18 ; text_address_low &161e a9 48 LDA #&48 # actually LDA stage_message_address_high &1620 85 19 STA &19 ; text_address_high &1622 20 88 2d JSR &2d88 ; plot_string # Plot "SHOOT TIE FIGHTERS" ; skip_plotting_shoot_tie_fighters &1625 60 RTS ; update_player_hit_cooldown &1626 ad fc 4f LDA &4ffc ; player_hit_cooldown &1629 30 03 BMI &162e ; leave &162b ce fc 4f DEC &4ffc ; player_hit_cooldown ; leave &162e 60 RTS ; add_to_score &162f f8 SED &1630 ad 88 03 LDA &0388 ; score &1633 18 CLC &1634 65 70 ADC &70 ; number &1636 8d 88 03 STA &0388 ; score &1639 ad 89 03 LDA &0389 ; score + 1 &163c 65 71 ADC &71 ; number + 1 &163e 8d 89 03 STA &0389 ; score + 1 &1641 ad 8a 03 LDA &038a ; score + 2 &1644 65 72 ADC &72 ; number + 2 &1646 8d 8a 03 STA &038a ; score + 2 &1649 a9 00 LDA #&00 &164b a0 3f LDY #&3f ; wipe_recent_score_loop &164d 99 00 52 STA &5200,Y ; buffer_one + &100 * 2 # Wipe left of status area, line three &1650 99 00 6a STA &6a00,Y ; buffer_two + &100 * 2 &1653 88 DEY &1654 10 f7 BPL &164d ; wipe_recent_score_loop &1656 85 73 STA &73 ; number + 3 &1658 6d 8b 03 ADC &038b ; score + 3 &165b 8d 8b 03 STA &038b ; score + 3 &165e d8 CLD &165f a2 01 LDX #&01 ; plot_recent_score_to_buffers_loop &1661 8a TXA &1662 48 PHA ; buffer &1663 a9 0f LDA #&0f ; CC &1665 85 1a STA &1a ; colour_pixel_value &1667 a9 00 LDA #&00 &1669 85 16 STA &16 ; text_screen_offset_low &166b a9 02 LDA #&02 &166d 85 17 STA &17 ; text_screen_offset_high &166f a9 00 LDA #&00 &1671 85 73 STA &73 ; number + 3 &1673 20 f4 2d JSR &2df4 ; plot_number_without_leading_zeros # Plot recent score &1676 20 6c 2e JSR &2e6c ; use_other_buffer &1679 68 PLA ; buffer &167a aa TAX &167b ca DEX &167c 10 e3 BPL &1661 ; plot_recent_score_to_buffers_loop ; plot_score &167e a2 01 LDX #&01 ; plot_score_to_buffers_loop &1680 8a TXA &1681 48 PHA ; buffer &1682 20 6c 2e JSR &2e6c ; use_other_buffer &1685 a9 00 LDA #&00 &1687 85 16 STA &16 ; text_screen_offset_low &1689 a9 01 LDA #&01 &168b 85 17 STA &17 ; text_screen_offset_high &168d a9 ff LDA #&ff ; GG &168f 85 1a STA &1a ; colour_pixel_value &1691 ad 88 03 LDA &0388 ; score &1694 85 70 STA &70 ; number &1696 ad 89 03 LDA &0389 ; score + 1 &1699 85 71 STA &71 ; number + 1 &169b ad 8a 03 LDA &038a ; score + 2 &169e 85 72 STA &72 ; number + 2 &16a0 ad 8b 03 LDA &038b ; score + 3 &16a3 85 73 STA &73 ; number + 3 &16a5 20 1f 2e JSR &2e1f ; plot_number # Plot score &16a8 68 PLA ; buffer &16a9 aa TAX &16aa ca DEX &16ab 10 d3 BPL &1680 ; plot_score_to_buffers_loop &16ad a9 07 LDA #&07 &16af 8d 8d 08 STA &088d ; recent_score_cooldown &16b2 60 RTS ; consider_wiping_recent_score &16b3 ae 8d 08 LDX &088d ; recent_score_cooldown &16b6 30 11 BMI &16c9 ; leave &16b8 d0 0c BNE &16c6 ; skip_wiping_recent_score &16ba 8a TXA &16bb a0 3f LDY #&3f ; wipe_recent_score_loop &16bd 99 00 52 STA &5200,Y ; buffer_one + &100 * 2 # Wipe left of status area, line three &16c0 99 00 6a STA &6a00,Y ; buffer_two + &100 * 2 &16c3 88 DEY &16c4 10 f7 BPL &16bd ; wipe_recent_score_loop ; skip_wiping_recent_score &16c6 ce 8d 08 DEC &088d ; recent_score_cooldown ; leave &16c9 60 RTS ; plot_wave &16ca a2 01 LDX #&01 ; plot_wave_to_buffers_loop &16cc 8a TXA &16cd 48 PHA ; buffer &16ce 20 6c 2e JSR &2e6c ; use_other_buffer &16d1 a9 c8 LDA #&c8 &16d3 85 16 STA &16 ; text_screen_offset_low &16d5 a9 00 LDA #&00 &16d7 85 17 STA &17 ; text_screen_offset_high &16d9 a9 ff LDA #&ff ; GG &16db 85 1a STA &1a ; colour_pixel_value &16dd ad 8a 08 LDA &088a ; wave_as_bcd &16e0 20 30 2e JSR &2e30 ; plot_two_digit_number &16e3 68 PLA ; buffer &16e4 aa TAX &16e5 ca DEX &16e6 10 e4 BPL &16cc ; plot_wave_to_buffers_loop &16e8 60 RTS ; calculate_trench_point_screen_position # Called with X = 0 for far, X = 4 for near &16e9 a9 03 LDA #&03 ; G &16eb 20 ab 23 JSR &23ab ; set_colour &16ee a9 00 LDA #&00 &16f0 85 46 STA &46 ; point_z &16f2 38 SEC &16f3 ed b4 08 SBC &08b4 ; player_x &16f6 85 40 STA &40 ; point_x &16f8 a9 f2 LDA #&f2 &16fa ed b5 08 SBC &08b5 ; player_x_high &16fd 85 41 STA &41 ; point_x_high &16ff a9 00 LDA #&00 &1701 38 SEC &1702 ed b6 08 SBC &08b6 ; player_y &1705 85 43 STA &43 ; point_y &1707 a9 22 LDA #&22 &1709 ed b7 08 SBC &08b7 ; player_y_high &170c 85 44 STA &44 ; point_y_high &170e 08 PHP ; carry &170f 20 4c 38 JSR &384c ; calculate_screen_position_for_point &1712 a5 66 LDA &66 ; screen_x &1714 9d c0 4b STA &4bc0,X ; trench_points_left_screen_x &1717 a5 67 LDA &67 ; screen_x_high &1719 9d c1 4b STA &4bc1,X ; trench_points_left_screen_x_high &171c a5 68 LDA &68 ; screen_y &171e 9d c0 4c STA &4cc0,X ; trench_points_top_screen_y &1721 a5 69 LDA &69 ; screen_y_high &1723 9d c1 4c STA &4cc1,X ; trench_points_top_screen_y_high &1726 28 PLP ; carry &1727 a9 00 LDA #&00 &1729 ed b7 08 SBC &08b7 ; player_y_high &172c 85 44 STA &44 ; point_y_high &172e 20 2c 39 JSR &392c ; calculate_screen_y_for_point &1731 a5 68 LDA &68 ; screen_y &1733 9d c2 4c STA &4cc2,X ; trench_points_bottom_screen_y &1736 a5 69 LDA &69 ; screen_y_high &1738 9d c3 4c STA &4cc3,X ; trench_points_bottom_screen_y_high &173b a9 00 LDA #&00 &173d 38 SEC &173e ed b4 08 SBC &08b4 ; player_x &1741 85 40 STA &40 ; point_x &1743 a9 0e LDA #&0e &1745 ed b5 08 SBC &08b5 ; player_x_high &1748 85 41 STA &41 ; point_x_high &174a 20 df 38 JSR &38df ; calculate_screen_x_for_point &174d a5 66 LDA &66 ; screen_x &174f 9d c2 4b STA &4bc2,X ; trench_points_right_screen_x &1752 a5 67 LDA &67 ; screen_x_high &1754 9d c3 4b STA &4bc3,X ; trench_points_right_screen_x_high &1757 60 RTS ; plot_trench_far_end &1758 a9 00 LDA #&00 &175a 8d 8e 08 STA &088e ; far_end &175d f0 05 BEQ &1764 ; plot_left_section_line # Always branches ; plot_trench_section &175f a9 ff LDA #&ff &1761 8d 8e 08 STA &088e ; far_end ; plot_left_section_line &1764 bd c0 4b LDA &4bc0,X ; trench_points_left_screen_x &1767 85 62 STA &62 ; line_start_x &1769 85 66 STA &66 ; line_end_x &176b bd c1 4b LDA &4bc1,X ; trench_points_left_screen_x_high &176e 85 63 STA &63 ; line_start_x_high &1770 85 67 STA &67 ; line_end_x_high &1772 bd c0 4c LDA &4cc0,X ; trench_points_top_screen_y &1775 85 64 STA &64 ; line_start_y &1777 bd c1 4c LDA &4cc1,X ; trench_points_top_screen_y_high &177a 85 65 STA &65 ; line_start_y_high &177c bd c2 4c LDA &4cc2,X ; trench_points_bottom_screen_y &177f 85 68 STA &68 ; line_end_y &1781 bd c3 4c LDA &4cc3,X ; trench_points_bottom_screen_y_high &1784 85 69 STA &69 ; line_end_y_high &1786 20 4f 29 JSR &294f ; plot_vertical_line # Plot left vertical line of section or trench end &1789 a5 64 LDA &64 ; line_start_y &178b 85 68 STA &68 ; line_end_y &178d a5 65 LDA &65 ; line_start_y_high &178f 85 69 STA &69 ; line_end_y_high &1791 bd c2 4b LDA &4bc2,X ; trench_points_right_screen_x &1794 85 66 STA &66 ; line_end_x &1796 bd c3 4b LDA &4bc3,X ; trench_points_right_screen_x_high &1799 85 67 STA &67 ; line_end_x_high &179b a9 ff LDA #&ff ; GG &179d 85 1a STA &1a ; colour_pixel_value &179f ad 8e 08 LDA &088e ; far_end # Positive if far end, negative if vertical sections &17a2 30 06 BMI &17aa ; skip_joining_vertical_lines &17a4 20 6c 2a JSR &2a6c ; plot_horizontal_line # Plot bottom of trench end &17a7 4c ad 17 JMP &17ad ; plot_right_section_end ; skip_joining_vertical_lines &17aa 20 0f 29 JSR &290f ; set_line_start_to_line_end ; plot_right_section_line &17ad a5 62 LDA &62 ; line_start_x &17af 85 66 STA &66 ; line_end_x &17b1 a5 63 LDA &63 ; line_start_x_high &17b3 85 67 STA &67 ; line_end_x_high &17b5 bd c0 4c LDA &4cc0,X ; trench_points_top_screen_y &17b8 85 68 STA &68 ; line_end_y &17ba bd c1 4c LDA &4cc1,X ; trench_points_top_screen_y_high &17bd 85 69 STA &69 ; line_end_y_high &17bf 4c 4f 29 JMP &294f ; plot_vertical_line # Plot right vertical line of section or trench end # Catwalks and side ports are stored as a bitmap: # # 8421.... left # ....8421 right # # 8...8... highest # .4...4.. # ..2...2. # ...1...1 lowest ; plot_set_of_catwalks &17c2 a5 47 LDA &47 ; point_z_high &17c4 c9 c0 CMP #&c0 &17c6 90 01 BCC &17c9 ; not_too_far &17c8 60 RTS ; not_too_far &17c9 c9 06 CMP #&06 &17cb b0 01 BCS &17ce ; not_too_near &17cd 60 RTS ; not_too_near &17ce 18 CLC &17cf 69 06 ADC #&06 &17d1 85 47 STA &47 ; point_z_high &17d3 a9 00 LDA #&00 &17d5 85 40 STA &40 ; point_x &17d7 85 43 STA &43 ; point_y &17d9 85 46 STA &46 ; point_z &17db 8d 92 08 STA &0892 ; level_one_catwalk_left_points # Set to zero to use left of trench for left edge &17de 8d 93 08 STA &0893 ; level_two_catwalk_left_points # Set to zero to use left of trench for left edge &17e1 8d 94 08 STA &0894 ; level_three_catwalk_left_points # Set to zero to use left of trench for left edge &17e4 8d 95 08 STA &0895 ; level_four_catwalk_left_points # Set to zero to use left of trench for left edge &17e7 8d 96 08 STA &0896 ; level_one_catwalk_right_points # Set to zero to use right of trench for right edge &17ea 8d 97 08 STA &0897 ; level_two_catwalk_right_points # Set to zero to use right of trench for right edge &17ed 8d 98 08 STA &0898 ; level_three_catwalk_right_points # Set to zero to use right of trench for right edge &17f0 8d 99 08 STA &0899 ; level_four_catwalk_right_points # Set to zero to use right of trench for right edge &17f3 a9 ff LDA #&ff &17f5 8d 91 08 STA &0891 ; player_catwalk_bitmap # Set to &ff to collide with left and right catwalks &17f8 ad b5 08 LDA &08b5 ; player_x_high &17fb 10 0b BPL &1808 ; is_right_of_centre &17fd c9 fb CMP #&fb &17ff b0 07 BCS &1808 ; check_if_right &1801 a9 f0 LDA #&f0 &1803 8d 91 08 STA &0891 ; player_catwalk_bitmap # Set to &f0 to only collide with left catwalks &1806 d0 0d BNE &1815 ; consider_level_one_catwalk # Always branches ; check_if_right &1808 30 0b BMI &1815 ; consider_level_one_catwalk &180a c9 06 CMP #&06 &180c 90 07 BCC &1815 ; consider_level_one_catwalk &180e a9 0f LDA #&0f &1810 8d 91 08 STA &0891 ; player_catwalk_bitmap # Set to &0f to only collide with right catwalks &1813 85 59 STA &59 ; unused # Unused variable ; consider_level_one_catwalk &1815 ad 8f 08 LDA &088f ; catwalks_bitmap &1818 29 11 AND #&11 &181a c9 11 CMP #&11 &181c f0 14 BEQ &1832 ; not_partial_level_one_catwalk &181e c9 10 CMP #&10 &1820 d0 07 BNE &1829 ; not_left_level_one_catwalk ; is_left_level_one_catwalk &1822 a9 04 LDA #&04 &1824 8d 96 08 STA &0896 ; level_one_catwalk_right_points # Set to &04 to use middle of trench for right edge &1827 d0 09 BNE &1832 ; not_partial_level_one_catwalk # Always branches ; not_left_level_one_catwalk &1829 c9 01 CMP #&01 &182b d0 05 BNE &1832 ; not_partial_level_one_catwalk ; is_right_level_one_catwalk &182d a9 08 LDA #&08 &182f 8d 92 08 STA &0892 ; level_one_catwalk_left_points # Set to &08 to use middle of trench for left edge ; not_partial_level_one_catwalk ; consider_level_two_catwalk &1832 ad 8f 08 LDA &088f ; catwalks_bitmap &1835 29 22 AND #&22 &1837 c9 22 CMP #&22 &1839 f0 14 BEQ &184f ; not_partial_level_two_catwalk &183b c9 20 CMP #&20 &183d d0 07 BNE &1846 ; not_left_level_two_catwalk ; is_left_level_two_catwalk &183f a9 04 LDA #&04 &1841 8d 97 08 STA &0897 ; level_two_catwalk_right_points # Set to &04 to use middle of trench for right edge &1844 d0 09 BNE &184f ; not_partial_level_two_catwalk # Always branches ; not_left_level_two_catwalk &1846 c9 02 CMP #&02 &1848 d0 05 BNE &184f ; not_partial_level_two_catwalk ; is_right_level_two_catwalk &184a a9 08 LDA #&08 &184c 8d 93 08 STA &0893 ; level_two_catwalk_left_points # Set to &08 to use middle of trench for left edge ; not_partial_level_two_catwalk ; consider_level_three_catwalk &184f ad 8f 08 LDA &088f ; catwalks_bitmap &1852 29 44 AND #&44 &1854 c9 44 CMP #&44 &1856 f0 14 BEQ &186c ; not_partial_level_three_catwalk &1858 c9 40 CMP #&40 &185a d0 07 BNE &1863 ; not_left_level_three_catwalk ; is_left_level_three_catwalk &185c a9 04 LDA #&04 &185e 8d 98 08 STA &0898 ; level_three_catwalk_right_points # Set to &04 to use middle of trench for right edge &1861 d0 09 BNE &186c ; not_partial_level_three_catwalk # Always branches ; not_left_level_three_catwalk &1863 c9 04 CMP #&04 &1865 d0 05 BNE &186c ; not_partial_level_three_catwalk ; is_right_level_three_catwalk &1867 a9 08 LDA #&08 &1869 8d 94 08 STA &0894 ; level_three_catwalk_left_points # Set to &08 to use middle of trench for left edge ; not_partial_level_three_catwalk ; consider_level_four_catwalk &186c ad 8f 08 LDA &088f ; catwalks_bitmap &186f 29 88 AND #&88 &1871 c9 88 CMP #&88 &1873 f0 14 BEQ &1889 ; not_partial_level_four_catwalk &1875 c9 80 CMP #&80 &1877 d0 07 BNE &1880 ; not_left_level_four_catwalk ; is_left_level_four_catwalk &1879 a9 04 LDA #&04 &187b 8d 99 08 STA &0899 ; level_four_catwalk_right_points # Set to &04 to use middle of trench for right edge &187e d0 09 BNE &1889 ; not_partial_level_four_catwalk # Always branches ; not_left_level_four_catwalk &1880 c9 08 CMP #&08 &1882 d0 05 BNE &1889 ; not_partial_level_four_catwalk ; is_right_level_four_catwalk &1884 a9 08 LDA #&08 &1886 8d 95 08 STA &0895 ; level_four_catwalk_left_points # Set to &08 to use middle of trench for left edge ; not_partial_level_four_catwalk &1889 a9 f2 LDA #&f2 &188b 85 58 STA &58 ; catwalk_left_x &188d 38 SEC &188e ed b5 08 SBC &08b5 ; player_x_high &1891 85 41 STA &41 ; point_x_high &1893 a9 00 LDA #&00 &1895 38 SEC &1896 ed b7 08 SBC &08b7 ; player_y_high &1899 85 44 STA &44 ; point_y_high &189b 20 df 38 JSR &38df ; calculate_screen_x_for_point # Calculate screen x for left of vertical edges &189e a5 66 LDA &66 ; screen_x &18a0 8d c0 4b STA &4bc0 ; catwalk_points_edge_left_screen_x &18a3 a5 67 LDA &67 ; screen_x_high &18a5 8d c1 4b STA &4bc1 ; catwalk_points_edge_left_screen_x_high &18a8 ad 8f 08 LDA &088f ; catwalks_bitmap &18ab 4a LSR A &18ac 4a LSR A &18ad 4a LSR A &18ae 4a LSR A &18af 85 5f STA &5f ; left_catwalk &18b1 ad 8f 08 LDA &088f ; catwalks_bitmap &18b4 29 0f AND #&0f &18b6 c5 5f CMP &5f ; left_catwalk &18b8 f0 17 BEQ &18d1 ; skip_calculating_catwalk_centre # Branch if all catwalks are full width &18ba a9 00 LDA #&00 &18bc 85 58 STA &58 ; catwalk_left_x &18be 38 SEC &18bf ed b5 08 SBC &08b5 ; player_x_high &18c2 85 41 STA &41 ; point_x_high &18c4 20 df 38 JSR &38df ; calculate_screen_x_for_point # Calculate screen x for middle of vertical edges &18c7 a5 66 LDA &66 ; screen_x &18c9 8d c8 4b STA &4bc8 ; catwalk_points_edge_left_screen_x + 8, catwalk_points_edge_right_screen_x + 4 &18cc a5 67 LDA &67 ; screen_x_high &18ce 8d c9 4b STA &4bc9 ; catwalk_points_edge_left_screen_x_high + 8, catwalk_points_edge_right_screen_x_high + 4 ; skip_calculating_catwalk_centre &18d1 ad 8f 08 LDA &088f ; catwalks_bitmap &18d4 29 11 AND #&11 &18d6 f0 15 BEQ &18ed ; skip_calculating_catwalk_level_zero # Branch if no catwalk at level one &18d8 a9 00 LDA #&00 &18da 38 SEC &18db ed b7 08 SBC &08b7 ; player_y_high &18de 85 44 STA &44 ; point_y_high &18e0 20 2c 39 JSR &392c ; calculate_screen_y_for_point # Calculate screen y for bottom of level one catwalk &18e3 a5 68 LDA &68 ; screen_y &18e5 8d c0 4c STA &4cc0 ; catwalk_points_vertical_edge_zero_screen_y &18e8 a5 69 LDA &69 ; screen_y_high &18ea 8d c1 4c STA &4cc1 ; catwalk_points_vertical_edge_zero_screen_y_high ; skip_calculating_catwalk_level_zero &18ed ad 8f 08 LDA &088f ; catwalks_bitmap &18f0 29 33 AND #&33 &18f2 f0 15 BEQ &1909 ; skip_calculating_catwalk_level_one # Branch if no catwalk at level one or two &18f4 a9 08 LDA #&08 &18f6 38 SEC &18f7 ed b7 08 SBC &08b7 ; player_y_high &18fa 85 44 STA &44 ; point_y_high &18fc 20 2c 39 JSR &392c ; calculate_screen_y_for_point # Calculate screen y for bottom of level two catwalk &18ff a5 68 LDA &68 ; screen_y # and top of level one catwalk &1901 8d c4 4c STA &4cc4 ; catwalk_points_vertical_edge_one_screen_y &1904 a5 69 LDA &69 ; screen_y_high &1906 8d c5 4c STA &4cc5 ; catwalk_points_vertical_edge_one_screen_y_high ; skip_calculating_catwalk_level_one &1909 ad 8f 08 LDA &088f ; catwalks_bitmap &190c 29 66 AND #&66 &190e f0 15 BEQ &1925 ; skip_calculating_catwalk_level_two # Branch if no catwalk at level two or three &1910 a9 10 LDA #&10 &1912 38 SEC &1913 ed b7 08 SBC &08b7 ; player_y_high &1916 85 44 STA &44 ; point_y_high &1918 20 2c 39 JSR &392c ; calculate_screen_y_for_point # Calculate screen y for bottom of level three catwalk &191b a5 68 LDA &68 ; screen_y # and top of level two catwalk &191d 8d c8 4c STA &4cc8 ; catwalk_points_vertical_edge_two_screen_y &1920 a5 69 LDA &69 ; screen_y_high &1922 8d c9 4c STA &4cc9 ; catwalk_points_vertical_edge_two_screen_y_high ; skip_calculating_catwalk_level_two &1925 ad 8f 08 LDA &088f ; catwalks_bitmap &1928 29 cc AND #&cc &192a f0 15 BEQ &1941 ; skip_calculating_catwalk_level_three # Branch if no catwalk at level three or four &192c a9 18 LDA #&18 &192e 38 SEC &192f ed b7 08 SBC &08b7 ; player_y_high &1932 85 44 STA &44 ; point_y_high &1934 20 2c 39 JSR &392c ; calculate_screen_y_for_point # Calculate screen y for bottom of level four catwalk &1937 a5 68 LDA &68 ; screen_y # and top of level three catwalk &1939 8d cc 4c STA &4ccc ; catwalk_points_vertical_edge_three_screen_y &193c a5 69 LDA &69 ; screen_y_high &193e 8d cd 4c STA &4ccd ; catwalk_points_vertical_edge_three_screen_y_high ; skip_calculating_catwalk_level_three &1941 ad 8f 08 LDA &088f ; catwalks_bitmap &1944 29 cc AND #&cc # Bug: this should be AND #&88 to check level four only &1946 f0 15 BEQ &195d ; skip_calculating_catwalk_level_four # Branch if no catwalk at level three or four &1948 a9 20 LDA #&20 &194a 38 SEC &194b ed b7 08 SBC &08b7 ; player_y_high &194e 85 44 STA &44 ; point_y_high &1950 20 2c 39 JSR &392c ; calculate_screen_y_for_point # Calculate screen y for top of level four catwalk &1953 a5 68 LDA &68 ; screen_y &1955 8d d0 4c STA &4cd0 ; catwalk_points_vertical_edge_four_screen_y &1958 a5 69 LDA &69 ; screen_y_high &195a 8d d1 4c STA &4cd1 ; catwalk_points_vertical_edge_four_screen_y_high ; skip_calculating_catwalk_level_four &195d a9 0e LDA #&0e &195f 38 SEC &1960 ed b5 08 SBC &08b5 ; player_x_high &1963 85 41 STA &41 ; point_x_high &1965 20 df 38 JSR &38df ; calculate_screen_x_for_point # Calculate screen x for right of vertical edges &1968 a5 66 LDA &66 ; screen_x &196a 8d c4 4b STA &4bc4 ; catwalk_points_edge_right_screen_x &196d a5 67 LDA &67 ; screen_x_high &196f 8d c5 4b STA &4bc5 ; catwalk_points_edge_right_screen_x_high &1972 a9 f2 LDA #&f2 &1974 38 SEC &1975 ed b5 08 SBC &08b5 ; player_x_high &1978 85 41 STA &41 ; point_x_high &197a a5 47 LDA &47 ; point_z_high &197c 38 SEC &197d e9 0c SBC #&0c &197f 85 47 STA &47 ; point_z_high &1981 20 df 38 JSR &38df ; calculate_screen_x_for_point # Calculate screen x for left of catwalk centres &1984 a5 66 LDA &66 ; screen_x &1986 8d c2 4b STA &4bc2 ; catwalk_points_centre_left_screen_x &1989 a5 67 LDA &67 ; screen_x_high &198b 8d c3 4b STA &4bc3 ; catwalk_points_centre_left_screen_x_high &198e a5 58 LDA &58 ; catwalk_left_x &1990 30 15 BMI &19a7 ; skip_calculating_catwalk_middle &1992 a9 00 LDA #&00 &1994 38 SEC &1995 ed b5 08 SBC &08b5 ; player_x_high &1998 85 41 STA &41 ; point_x_high &199a 20 df 38 JSR &38df ; calculate_screen_x_for_point # Calculate screen x for middle of catwalk centres &199d a5 66 LDA &66 ; screen_x &199f 8d ca 4b STA &4bca ; catwalk_points_centre_left_screen_x + 8, catwalk_points_centre_right_screen_x + 4 &19a2 a5 67 LDA &67 ; screen_x_high &19a4 8d cb 4b STA &4bcb ; catwalk_points_centre_left_screen_x_high, catwalk_points_centre_right_screen_x_high + 4 ; skip_calculating_catwalk_middle &19a7 ad 8f 08 LDA &088f ; catwalks_bitmap &19aa 29 11 AND #&11 &19ac f0 15 BEQ &19c3 ; skip_calculating_catwalk_centre_one # Branch if no catwalk at level one &19ae a9 04 LDA #&04 &19b0 38 SEC &19b1 ed b7 08 SBC &08b7 ; player_y_high &19b4 85 44 STA &44 ; point_y_high &19b6 20 2c 39 JSR &392c ; calculate_screen_y_for_point # Calculate screen y for centre of level one catwalk &19b9 a5 68 LDA &68 ; screen_y &19bb 8d c2 4c STA &4cc2 ; catwalk_points_centre_one_screen_y &19be a5 69 LDA &69 ; screen_y_high &19c0 8d c3 4c STA &4cc3 ; catwalk_points_centre_one_screen_y_high ; skip_calculating_catwalk_centre_one &19c3 ad 8f 08 LDA &088f ; catwalks_bitmap &19c6 29 22 AND #&22 &19c8 f0 15 BEQ &19df ; skip_calculating_catwalk_centre_two # Branch if no catwalk at level two &19ca a9 0c LDA #&0c &19cc 38 SEC &19cd ed b7 08 SBC &08b7 ; player_y_high &19d0 85 44 STA &44 ; point_y_high &19d2 20 2c 39 JSR &392c ; calculate_screen_y_for_point # Calculate screen y for centre of level two catwalk &19d5 a5 68 LDA &68 ; screen_y &19d7 8d c6 4c STA &4cc6 ; catwalk_points_centre_two_screen_y &19da a5 69 LDA &69 ; screen_y_high &19dc 8d c7 4c STA &4cc7 ; catwalk_points_centre_two_screen_y_high ; skip_calculating_catwalk_centre_two &19df ad 8f 08 LDA &088f ; catwalks_bitmap &19e2 29 44 AND #&44 &19e4 f0 15 BEQ &19fb ; skip_calculating_catwalk_centre_three # Branch if no catwalk at level three &19e6 a9 14 LDA #&14 &19e8 38 SEC &19e9 ed b7 08 SBC &08b7 ; player_y_high &19ec 85 44 STA &44 ; point_y_high &19ee 20 2c 39 JSR &392c ; calculate_screen_y_for_point # Calculate screen y for centre of level three catwalk &19f1 a5 68 LDA &68 ; screen_y &19f3 8d ca 4c STA &4cca ; catwalk_points_centre_three_screen_y &19f6 a5 69 LDA &69 ; screen_y_high &19f8 8d cb 4c STA &4ccb ; catwalk_points_centre_three_screen_y_high ; skip_calculating_catwalk_centre_three &19fb ad 8f 08 LDA &088f ; catwalks_bitmap &19fe 29 88 AND #&88 &1a00 f0 15 BEQ &1a17 ; skip_calculating_catwalk_centre_four # Branch if no catwalk at level four &1a02 a9 1c LDA #&1c &1a04 38 SEC &1a05 ed b7 08 SBC &08b7 ; player_y_high &1a08 85 44 STA &44 ; point_y_high &1a0a 20 2c 39 JSR &392c ; calculate_screen_y_for_point # Calculate screen y for centre of level four catwalk &1a0d a5 68 LDA &68 ; screen_y &1a0f 8d ce 4c STA &4cce ; catwalk_points_centre_four_screen_y &1a12 a5 69 LDA &69 ; screen_y_high &1a14 8d cf 4c STA &4ccf ; catwalk_points_centre_four_screen_y_high ; skip_calculating_catwalk_centre_four &1a17 a9 0e LDA #&0e &1a19 38 SEC &1a1a ed b5 08 SBC &08b5 ; player_x_high &1a1d 85 41 STA &41 ; point_x_high &1a1f 20 df 38 JSR &38df ; calculate_screen_x_for_point # Calculate screen x for right of catwalk centres &1a22 a5 66 LDA &66 ; screen_x &1a24 8d c6 4b STA &4bc6 ; catwalk_points_centre_right_screen_x &1a27 a5 67 LDA &67 ; screen_x_high &1a29 8d c7 4b STA &4bc7 ; catwalk_points_centre_right_screen_x_high ; consider_plotting_level_one_catwalk &1a2c ad 8f 08 LDA &088f ; catwalks_bitmap &1a2f 29 11 AND #&11 &1a31 d0 03 BNE &1a36 ; plot_level_one_catwalk # Branch if any catwalk at level one &1a33 4c 58 1b JMP &1b58 ; consider_plotting_level_two_catwalk ; plot_level_one_catwalk &1a36 85 5a STA &5a ; this_catwalk_bitmap &1a38 ae 92 08 LDX &0892 ; level_one_catwalk_left_points &1a3b ac 96 08 LDY &0896 ; level_one_catwalk_right_points &1a3e ad b7 08 LDA &08b7 ; player_y_high &1a41 c9 0c CMP #&0c &1a43 b0 12 BCS &1a57 ; no_collision_with_level_one_catwalk &1a45 a5 47 LDA &47 ; point_z_high &1a47 c9 0c CMP #&0c &1a49 b0 0c BCS &1a57 ; no_collision_with_level_one_catwalk &1a4b a5 5a LDA &5a ; this_catwalk_bitmap &1a4d 2d 91 08 AND &0891 ; player_catwalk_bitmap &1a50 f0 05 BEQ &1a57 ; no_collision_with_level_one_catwalk &1a52 a9 ff LDA #&ff &1a54 8d 90 08 STA &0890 ; collided_with_catwalk # Set to negative to indicate collision with catwalk ; no_collision_with_level_one_catwalk &1a57 bd c0 4b LDA &4bc0,X ; catwalk_points_edge_left_screen_x &1a5a 85 62 STA &62 ; line_start_x &1a5c bd c1 4b LDA &4bc1,X ; catwalk_points_edge_left_screen_x_high &1a5f 85 63 STA &63 ; line_start_x_high &1a61 ad c4 4c LDA &4cc4 ; catwalk_points_vertical_edge_one_screen_y &1a64 85 64 STA &64 ; line_start_y &1a66 ad c5 4c LDA &4cc5 ; catwalk_points_vertical_edge_one_screen_y_high &1a69 85 65 STA &65 ; line_start_y_high &1a6b a5 47 LDA &47 ; point_z_high &1a6d c9 60 CMP #&60 &1a6f b0 31 BCS &1aa2 ; plot_simple_left_of_level_one_catwalk ; plot_detailed_left_of_level_one_catwalk &1a71 bd c2 4b LDA &4bc2,X ; catwalk_points_centre_left_screen_x &1a74 85 66 STA &66 ; line_end_x &1a76 bd c3 4b LDA &4bc3,X ; catwalk_points_centre_left_screen_x_high &1a79 85 67 STA &67 ; line_end_x_high &1a7b ad c2 4c LDA &4cc2 ; catwalk_points_centre_one_screen_y &1a7e 85 68 STA &68 ; line_end_y &1a80 ad c3 4c LDA &4cc3 ; catwalk_points_centre_one_screen_y_high &1a83 85 69 STA &69 ; line_end_y_high &1a85 20 db 23 JSR &23db ; plot_line # Plot top left of level one catwalk &1a88 bd c0 4b LDA &4bc0,X ; catwalk_points_edge_left_screen_x &1a8b 85 66 STA &66 ; line_end_x &1a8d bd c1 4b LDA &4bc1,X ; catwalk_points_edge_left_screen_x_high &1a90 85 67 STA &67 ; line_end_x_high &1a92 ad c0 4c LDA &4cc0 ; catwalk_points_vertical_edge_zero_screen_y &1a95 85 68 STA &68 ; line_end_y &1a97 ad c1 4c LDA &4cc1 ; catwalk_points_vertical_edge_zero_screen_y_high &1a9a 85 69 STA &69 ; line_end_y_high &1a9c 20 db 23 JSR &23db ; plot_line # Plot bottom left of level one catwalk &1a9f 4c b9 1a JMP &1ab9 ; plot_bottom_of_level_one_catwalk ; plot_simple_left_of_level_one_catwalk &1aa2 bd c0 4b LDA &4bc0,X ; catwalk_points_edge_left_screen_x &1aa5 85 66 STA &66 ; line_end_x &1aa7 bd c1 4b LDA &4bc1,X ; catwalk_points_edge_left_screen_x_high &1aaa 85 67 STA &67 ; line_end_x_high &1aac ad c0 4c LDA &4cc0 ; catwalk_points_vertical_edge_zero_screen_y &1aaf 85 68 STA &68 ; line_end_y &1ab1 ad c1 4c LDA &4cc1 ; catwalk_points_vertical_edge_zero_screen_y_high &1ab4 85 69 STA &69 ; line_end_y_high &1ab6 20 4f 29 JSR &294f ; plot_vertical_line # Plot left of level one catwalk ; plot_bottom_of_level_one_catwalk &1ab9 ad c0 4c LDA &4cc0 ; catwalk_points_vertical_edge_zero_screen_y &1abc 85 68 STA &68 ; line_end_y &1abe ad c1 4c LDA &4cc1 ; catwalk_points_vertical_edge_zero_screen_y_high &1ac1 85 69 STA &69 ; line_end_y_high &1ac3 b9 c4 4b LDA &4bc4,Y ; catwalk_points_edge_right_screen_x &1ac6 85 66 STA &66 ; line_end_x &1ac8 b9 c5 4b LDA &4bc5,Y ; catwalk_points_edge_right_screen_x_high &1acb 85 67 STA &67 ; line_end_x_high &1acd 20 6c 2a JSR &2a6c ; plot_horizontal_line # Plot bottom of level one catwalk &1ad0 a5 47 LDA &47 ; point_z_high &1ad2 c9 60 CMP #&60 &1ad4 b0 31 BCS &1b07 ; plot_simple_right_of_level_one_catwalk ; plot_detailed_right_of_level_one_catwalk &1ad6 b9 c6 4b LDA &4bc6,Y ; catwalk_points_centre_right_screen_x &1ad9 85 66 STA &66 ; line_end_x &1adb b9 c7 4b LDA &4bc7,Y ; catwalk_points_centre_right_screen_x_high &1ade 85 67 STA &67 ; line_end_x_high &1ae0 ad c2 4c LDA &4cc2 ; catwalk_points_centre_one_screen_y &1ae3 85 68 STA &68 ; line_end_y &1ae5 ad c3 4c LDA &4cc3 ; catwalk_points_centre_one_screen_y_high &1ae8 85 69 STA &69 ; line_end_y_high &1aea 20 db 23 JSR &23db ; plot_line # Plot bottom right of level one catwalk &1aed b9 c4 4b LDA &4bc4,Y ; catwalk_points_edge_right_screen_x &1af0 85 66 STA &66 ; line_end_x &1af2 b9 c5 4b LDA &4bc5,Y ; catwalk_points_edge_right_screen_x_high &1af5 85 67 STA &67 ; line_end_x_high &1af7 ad c4 4c LDA &4cc4 ; catwalk_points_vertical_edge_one_screen_y &1afa 85 68 STA &68 ; line_end_y &1afc ad c5 4c LDA &4cc5 ; catwalk_points_vertical_edge_one_screen_y_high &1aff 85 69 STA &69 ; line_end_y_high &1b01 20 db 23 JSR &23db ; plot_line # Plot top right of level one catwalk &1b04 4c 1e 1b JMP &1b1e ; plot_top_of_level_one_catwalk ; plot_simple_right_of_level_one_catwalk &1b07 b9 c4 4b LDA &4bc4,Y ; catwalk_points_edge_right_screen_x &1b0a 85 66 STA &66 ; line_end_x &1b0c b9 c5 4b LDA &4bc5,Y ; catwalk_points_edge_right_screen_x_high &1b0f 85 67 STA &67 ; line_end_x_high &1b11 ad c4 4c LDA &4cc4 ; catwalk_points_vertical_edge_one_screen_y &1b14 85 68 STA &68 ; line_end_y &1b16 ad c5 4c LDA &4cc5 ; catwalk_points_vertical_edge_one_screen_y_high &1b19 85 69 STA &69 ; line_end_y_high &1b1b 20 4f 29 JSR &294f ; plot_vertical_line # Plot right of level one catwalk ; plot_top_of_level_one_catwalk &1b1e bd c0 4b LDA &4bc0,X ; catwalk_points_edge_left_screen_x &1b21 85 66 STA &66 ; line_end_x &1b23 bd c1 4b LDA &4bc1,X ; catwalk_points_edge_left_screen_x_high &1b26 85 67 STA &67 ; line_end_x_high &1b28 a5 64 LDA &64 ; line_start_y &1b2a 85 68 STA &68 ; line_end_y &1b2c a5 65 LDA &65 ; line_start_y_high &1b2e 85 69 STA &69 ; line_end_y_high &1b30 20 6c 2a JSR &2a6c ; plot_horizontal_line # Plot top of level one catwalk &1b33 bd c2 4b LDA &4bc2,X ; catwalk_points_centre_left_screen_x &1b36 85 62 STA &62 ; line_start_x &1b38 bd c3 4b LDA &4bc3,X ; catwalk_points_centre_left_screen_x_high &1b3b 85 63 STA &63 ; line_start_x_high &1b3d ad c2 4c LDA &4cc2 ; catwalk_points_centre_one_screen_y &1b40 85 64 STA &64 ; line_start_y &1b42 85 68 STA &68 ; line_end_y &1b44 ad c3 4c LDA &4cc3 ; catwalk_points_centre_one_screen_y_high &1b47 85 65 STA &65 ; line_start_y_high &1b49 85 69 STA &69 ; line_end_y_high &1b4b b9 c6 4b LDA &4bc6,Y ; catwalk_points_centre_right_screen_x &1b4e 85 66 STA &66 ; line_end_x &1b50 b9 c7 4b LDA &4bc7,Y ; catwalk_points_centre_right_screen_x_high &1b53 85 67 STA &67 ; line_end_x_high &1b55 20 6c 2a JSR &2a6c ; plot_horizontal_line # Plot centre of level one catwalk ; consider_plotting_level_two_catwalk &1b58 ad 8f 08 LDA &088f ; catwalks_bitmap &1b5b 29 22 AND #&22 &1b5d d0 03 BNE &1b62 ; plot_level_two_catwalk # Branch if any catwalk at level two &1b5f 4c 97 1c JMP &1c97 ; consider_plotting_level_three_catwalk ; plot_level_two_catwalk &1b62 85 5a STA &5a ; this_catwalk_bitmap &1b64 ae 93 08 LDX &0893 ; level_two_catwalk_left_points &1b67 ac 97 08 LDY &0897 ; level_two_catwalk_right_points &1b6a ad b7 08 LDA &08b7 ; player_y_high &1b6d c9 08 CMP #&08 &1b6f 90 16 BCC &1b87 ; no_collision_with_level_two_catwalk &1b71 c9 14 CMP #&14 &1b73 b0 12 BCS &1b87 ; no_collision_with_level_two_catwalk &1b75 a5 47 LDA &47 ; point_z_high &1b77 c9 0c CMP #&0c &1b79 b0 0c BCS &1b87 ; no_collision_with_level_two_catwalk &1b7b a5 5a LDA &5a ; this_catwalk_bitmap &1b7d 2d 91 08 AND &0891 ; player_catwalk_bitmap &1b80 f0 05 BEQ &1b87 ; no_collision_with_level_two_catwalk &1b82 a9 ff LDA #&ff &1b84 8d 90 08 STA &0890 ; collided_with_catwalk # Set to negative to indicate collision with catwalk ; no_collision_with_level_two_catwalk &1b87 bd c0 4b LDA &4bc0,X ; catwalk_points_edge_left_screen_x &1b8a 85 62 STA &62 ; line_start_x &1b8c bd c1 4b LDA &4bc1,X ; catwalk_points_edge_left_screen_x_high &1b8f 85 63 STA &63 ; line_start_x_high &1b91 ad c8 4c LDA &4cc8 ; catwalk_points_vertical_edge_two_screen_y &1b94 85 64 STA &64 ; line_start_y &1b96 ad c9 4c LDA &4cc9 ; catwalk_points_vertical_edge_two_screen_y_high &1b99 85 65 STA &65 ; line_start_y_high &1b9b a5 47 LDA &47 ; point_z_high &1b9d c9 60 CMP #&60 &1b9f b0 31 BCS &1bd2 ; plot_simple_left_of_level_two_catwalk ; plot_detailed_left_of_level_two_catwalk &1ba1 bd c2 4b LDA &4bc2,X ; catwalk_points_centre_left_screen_x &1ba4 85 66 STA &66 ; line_end_x &1ba6 bd c3 4b LDA &4bc3,X ; catwalk_points_centre_left_screen_x_high &1ba9 85 67 STA &67 ; line_end_x_high &1bab ad c6 4c LDA &4cc6 ; catwalk_points_centre_two_screen_y &1bae 85 68 STA &68 ; line_end_y &1bb0 ad c7 4c LDA &4cc7 ; catwalk_points_centre_two_screen_y_high &1bb3 85 69 STA &69 ; line_end_y_high &1bb5 20 db 23 JSR &23db ; plot_line # Plot top left of level two catwalk &1bb8 bd c0 4b LDA &4bc0,X ; catwalk_points_edge_left_screen_x &1bbb 85 66 STA &66 ; line_end_x &1bbd bd c1 4b LDA &4bc1,X ; catwalk_points_edge_left_screen_x_high &1bc0 85 67 STA &67 ; line_end_x_high &1bc2 ad c4 4c LDA &4cc4 ; catwalk_points_vertical_edge_one_screen_y &1bc5 85 68 STA &68 ; line_end_y &1bc7 ad c5 4c LDA &4cc5 ; catwalk_points_vertical_edge_one_screen_y_high &1bca 85 69 STA &69 ; line_end_y_high &1bcc 20 db 23 JSR &23db ; plot_line # Plot bottom left of level two catwalk &1bcf 4c e9 1b JMP &1be9 ; plot_bottom_of_level_two_catwalk ; plot_simple_left_of_level_two_catwalk &1bd2 bd c0 4b LDA &4bc0,X ; catwalk_points_edge_left_screen_x &1bd5 85 66 STA &66 ; line_end_x &1bd7 bd c1 4b LDA &4bc1,X ; catwalk_points_edge_left_screen_x_high &1bda 85 67 STA &67 ; line_end_x_high &1bdc ad c4 4c LDA &4cc4 ; catwalk_points_vertical_edge_one_screen_y &1bdf 85 68 STA &68 ; line_end_y &1be1 ad c5 4c LDA &4cc5 ; catwalk_points_vertical_edge_one_screen_y_high &1be4 85 69 STA &69 ; line_end_y_high &1be6 20 4f 29 JSR &294f ; plot_vertical_line # Plot left of level two catwalk ; plot_bottom_of_level_two_catwalk &1be9 ad c4 4c LDA &4cc4 ; catwalk_points_vertical_edge_one_screen_y &1bec 85 68 STA &68 ; line_end_y &1bee ad c5 4c LDA &4cc5 ; catwalk_points_vertical_edge_one_screen_y_high &1bf1 85 69 STA &69 ; line_end_y_high &1bf3 b9 c4 4b LDA &4bc4,Y ; catwalk_points_edge_right_screen_x &1bf6 85 66 STA &66 ; line_end_x &1bf8 b9 c5 4b LDA &4bc5,Y ; catwalk_points_edge_right_screen_x_high &1bfb 85 67 STA &67 ; line_end_x_high &1bfd ad 8f 08 LDA &088f ; catwalks_bitmap &1c00 29 11 AND #&11 &1c02 c9 11 CMP #&11 # If it wasn't already plotted in the level one catwalk, &1c04 f0 06 BEQ &1c0c ; skip_plotting_bottom_of_level_two_catwalk &1c06 20 6c 2a JSR &2a6c ; plot_horizontal_line # Plot bottom of level two catwalk &1c09 4c 0f 1c JMP &1c0f ; plot_right_of_level_two_catwalk ; skip_plotting_bottom_of_level_two_catwalk &1c0c 20 0f 29 JSR &290f ; set_line_start_to_line_end ; plot_right_of_level_two_catwalk &1c0f a5 47 LDA &47 ; point_z_high &1c11 c9 60 CMP #&60 &1c13 b0 31 BCS &1c46 ; plot_simple_right_of_level_two_catwalk ; plot_detailed_right_of_level_two_catwalk &1c15 b9 c6 4b LDA &4bc6,Y ; catwalk_points_centre_right_screen_x &1c18 85 66 STA &66 ; line_end_x &1c1a b9 c7 4b LDA &4bc7,Y ; catwalk_points_centre_right_screen_x_high &1c1d 85 67 STA &67 ; line_end_x_high &1c1f ad c6 4c LDA &4cc6 ; catwalk_points_centre_two_screen_y &1c22 85 68 STA &68 ; line_end_y &1c24 ad c7 4c LDA &4cc7 ; catwalk_points_centre_two_screen_y_high &1c27 85 69 STA &69 ; line_end_y_high &1c29 20 db 23 JSR &23db ; plot_line # Plot bottom right of level two catwalk &1c2c b9 c4 4b LDA &4bc4,Y ; catwalk_points_edge_right_screen_x &1c2f 85 66 STA &66 ; line_end_x &1c31 b9 c5 4b LDA &4bc5,Y ; catwalk_points_edge_right_screen_x_high &1c34 85 67 STA &67 ; line_end_x_high &1c36 ad c8 4c LDA &4cc8 ; catwalk_points_vertical_edge_two_screen_y &1c39 85 68 STA &68 ; line_end_y &1c3b ad c9 4c LDA &4cc9 ; catwalk_points_vertical_edge_two_screen_y_high &1c3e 85 69 STA &69 ; line_end_y_high &1c40 20 db 23 JSR &23db ; plot_line # Plot top right of level two catwalk &1c43 4c 5d 1c JMP &1c5d ; plot_top_of_level_two_catwalk ; plot_simple_right_of_level_two_catwalk &1c46 b9 c4 4b LDA &4bc4,Y ; catwalk_points_edge_right_screen_x &1c49 85 66 STA &66 ; line_end_x &1c4b b9 c5 4b LDA &4bc5,Y ; catwalk_points_edge_right_screen_x_high &1c4e 85 67 STA &67 ; line_end_x_high &1c50 ad c8 4c LDA &4cc8 ; catwalk_points_vertical_edge_two_screen_y &1c53 85 68 STA &68 ; line_end_y &1c55 ad c9 4c LDA &4cc9 ; catwalk_points_vertical_edge_two_screen_y_high &1c58 85 69 STA &69 ; line_end_y_high &1c5a 20 4f 29 JSR &294f ; plot_vertical_line # Plot right of level two catwalk ; plot_top_of_level_two_catwalk &1c5d bd c0 4b LDA &4bc0,X ; catwalk_points_edge_left_screen_x &1c60 85 66 STA &66 ; line_end_x &1c62 bd c1 4b LDA &4bc1,X ; catwalk_points_edge_left_screen_x_high &1c65 85 67 STA &67 ; line_end_x_high &1c67 a5 64 LDA &64 ; line_start_y &1c69 85 68 STA &68 ; line_end_y &1c6b a5 65 LDA &65 ; line_start_y_high &1c6d 85 69 STA &69 ; line_end_y_high &1c6f 20 6c 2a JSR &2a6c ; plot_horizontal_line # Plot top of level two catwalk &1c72 bd c2 4b LDA &4bc2,X ; catwalk_points_centre_left_screen_x &1c75 85 62 STA &62 ; line_start_x &1c77 bd c3 4b LDA &4bc3,X ; catwalk_points_centre_left_screen_x_high &1c7a 85 63 STA &63 ; line_start_x_high &1c7c ad c6 4c LDA &4cc6 ; catwalk_points_centre_two_screen_y &1c7f 85 64 STA &64 ; line_start_y &1c81 85 68 STA &68 ; line_end_y &1c83 ad c7 4c LDA &4cc7 ; catwalk_points_centre_two_screen_y_high &1c86 85 65 STA &65 ; line_start_y_high &1c88 85 69 STA &69 ; line_end_y_high &1c8a b9 c6 4b LDA &4bc6,Y ; catwalk_points_centre_right_screen_x &1c8d 85 66 STA &66 ; line_end_x &1c8f b9 c7 4b LDA &4bc7,Y ; catwalk_points_centre_right_screen_x_high &1c92 85 67 STA &67 ; line_end_x_high &1c94 20 6c 2a JSR &2a6c ; plot_horizontal_line # Plot centre of level two catwalk ; consider_plotting_level_three_catwalk &1c97 ad 8f 08 LDA &088f ; catwalks_bitmap &1c9a 29 44 AND #&44 &1c9c d0 03 BNE &1ca1 ; plot_level_three_catwalk # Branch if any catwalk at level three &1c9e 4c d6 1d JMP &1dd6 ; consider_plotting_level_four_catwalk ; plot_level_three_catwalk &1ca1 85 5a STA &5a ; this_catwalk_bitmap &1ca3 ae 94 08 LDX &0894 ; level_three_catwalk_left_points &1ca6 ac 98 08 LDY &0898 ; level_three_catwalk_right_points &1ca9 ad b7 08 LDA &08b7 ; player_y_high &1cac c9 10 CMP #&10 &1cae 90 16 BCC &1cc6 ; no_collision_with_level_three_catwalk &1cb0 c9 1c CMP #&1c &1cb2 b0 12 BCS &1cc6 ; no_collision_with_level_three_catwalk &1cb4 a5 47 LDA &47 ; point_z_high &1cb6 c9 0c CMP #&0c &1cb8 b0 0c BCS &1cc6 ; no_collision_with_level_three_catwalk &1cba a5 5a LDA &5a ; this_catwalk_bitmap &1cbc 2d 91 08 AND &0891 ; player_catwalk_bitmap &1cbf f0 05 BEQ &1cc6 ; no_collision_with_level_three_catwalk &1cc1 a9 ff LDA #&ff &1cc3 8d 90 08 STA &0890 ; collided_with_catwalk # Set to negative to indicate collision with catwalk ; no_collision_with_level_three_catwalk &1cc6 bd c0 4b LDA &4bc0,X ; catwalk_points_edge_left_screen_x &1cc9 85 62 STA &62 ; line_start_x &1ccb bd c1 4b LDA &4bc1,X ; catwalk_points_edge_left_screen_x_high &1cce 85 63 STA &63 ; line_start_x_high &1cd0 ad cc 4c LDA &4ccc ; catwalk_points_vertical_edge_three_screen_y &1cd3 85 64 STA &64 ; line_start_y &1cd5 ad cd 4c LDA &4ccd ; catwalk_points_vertical_edge_three_screen_y_high &1cd8 85 65 STA &65 ; line_start_y_high &1cda a5 47 LDA &47 ; point_z_high &1cdc c9 60 CMP #&60 &1cde b0 31 BCS &1d11 ; plot_simple_left_of_level_three_catwalk ; plot_detailed_left_of_level_three_catwalk &1ce0 bd c2 4b LDA &4bc2,X ; catwalk_points_centre_left_screen_x &1ce3 85 66 STA &66 ; line_end_x &1ce5 bd c3 4b LDA &4bc3,X ; catwalk_points_centre_left_screen_x_high &1ce8 85 67 STA &67 ; line_end_x_high &1cea ad ca 4c LDA &4cca ; catwalk_points_centre_three_screen_y &1ced 85 68 STA &68 ; line_end_y &1cef ad cb 4c LDA &4ccb ; catwalk_points_centre_three_screen_y_high &1cf2 85 69 STA &69 ; line_end_y_high &1cf4 20 db 23 JSR &23db ; plot_line # Plot top left of level three catwalk &1cf7 bd c0 4b LDA &4bc0,X ; catwalk_points_edge_left_screen_x &1cfa 85 66 STA &66 ; line_end_x &1cfc bd c1 4b LDA &4bc1,X ; catwalk_points_edge_left_screen_x_high &1cff 85 67 STA &67 ; line_end_x_high &1d01 ad c8 4c LDA &4cc8 ; catwalk_points_vertical_edge_two_screen_y &1d04 85 68 STA &68 ; line_end_y &1d06 ad c9 4c LDA &4cc9 ; catwalk_points_vertical_edge_two_screen_y_high &1d09 85 69 STA &69 ; line_end_y_high &1d0b 20 db 23 JSR &23db ; plot_line # Plot bottom left of level three catwalk &1d0e 4c 28 1d JMP &1d28 ; plot_bottom_of_level_three_catwalk ; plot_simple_left_of_level_three_catwalk &1d11 bd c0 4b LDA &4bc0,X ; catwalk_points_edge_left_screen_x &1d14 85 66 STA &66 ; line_end_x &1d16 bd c1 4b LDA &4bc1,X ; catwalk_points_edge_left_screen_x_high &1d19 85 67 STA &67 ; line_end_x_high &1d1b ad c8 4c LDA &4cc8 ; catwalk_points_vertical_edge_two_screen_y &1d1e 85 68 STA &68 ; line_end_y &1d20 ad c9 4c LDA &4cc9 ; catwalk_points_vertical_edge_two_screen_y_high &1d23 85 69 STA &69 ; line_end_y_high &1d25 20 4f 29 JSR &294f ; plot_vertical_line # Plot left of level three catwalk ; plot_bottom_of_level_three_catwalk &1d28 ad c8 4c LDA &4cc8 ; catwalk_points_vertical_edge_two_screen_y &1d2b 85 68 STA &68 ; line_end_y &1d2d ad c9 4c LDA &4cc9 ; catwalk_points_vertical_edge_two_screen_y_high &1d30 85 69 STA &69 ; line_end_y_high &1d32 b9 c4 4b LDA &4bc4,Y ; catwalk_points_edge_right_screen_x &1d35 85 66 STA &66 ; line_end_x &1d37 b9 c5 4b LDA &4bc5,Y ; catwalk_points_edge_right_screen_x_high &1d3a 85 67 STA &67 ; line_end_x_high &1d3c ad 8f 08 LDA &088f ; catwalks_bitmap &1d3f 29 22 AND #&22 &1d41 c9 22 CMP #&22 # If it wasn't already plotted in the level two catwalk, &1d43 f0 06 BEQ &1d4b ; skip_plotting_bottom_of_level_three_catwalk &1d45 20 6c 2a JSR &2a6c ; plot_horizontal_line # Plot bottom of level three catwalk &1d48 4c 4e 1d JMP &1d4e ; plot_right_of_level_three_catwalk ; skip_plotting_bottom_of_level_three_catwalk &1d4b 20 0f 29 JSR &290f ; set_line_start_to_line_end ; plot_right_of_level_three_catwalk &1d4e a5 47 LDA &47 ; point_z_high &1d50 c9 60 CMP #&60 &1d52 b0 31 BCS &1d85 ; plot_simple_right_of_level_three_catwalk ; plot_detailed_right_of_level_three_catwalk &1d54 b9 c6 4b LDA &4bc6,Y ; catwalk_points_centre_right_screen_x &1d57 85 66 STA &66 ; line_end_x &1d59 b9 c7 4b LDA &4bc7,Y ; catwalk_points_centre_right_screen_x_high &1d5c 85 67 STA &67 ; line_end_x_high &1d5e ad ca 4c LDA &4cca ; catwalk_points_centre_three_screen_y &1d61 85 68 STA &68 ; line_end_y &1d63 ad cb 4c LDA &4ccb ; catwalk_points_centre_three_screen_y_high &1d66 85 69 STA &69 ; line_end_y_high &1d68 20 db 23 JSR &23db ; plot_line # Plot bottom right of level three catwalk &1d6b b9 c4 4b LDA &4bc4,Y ; catwalk_points_edge_right_screen_x &1d6e 85 66 STA &66 ; line_end_x &1d70 b9 c5 4b LDA &4bc5,Y ; catwalk_points_edge_right_screen_x_high &1d73 85 67 STA &67 ; line_end_x_high &1d75 ad cc 4c LDA &4ccc ; catwalk_points_vertical_edge_three_screen_y &1d78 85 68 STA &68 ; line_end_y &1d7a ad cd 4c LDA &4ccd ; catwalk_points_vertical_edge_three_screen_y_high &1d7d 85 69 STA &69 ; line_end_y_high &1d7f 20 db 23 JSR &23db ; plot_line # Plot top right of level three catwalk &1d82 4c 9c 1d JMP &1d9c ; plot_top_of_level_three_catwalk ; plot_simple_right_of_level_three_catwalk &1d85 b9 c4 4b LDA &4bc4,Y ; catwalk_points_edge_right_screen_x &1d88 85 66 STA &66 ; line_end_x &1d8a b9 c5 4b LDA &4bc5,Y ; catwalk_points_edge_right_screen_x_high &1d8d 85 67 STA &67 ; line_end_x_high &1d8f ad cc 4c LDA &4ccc ; catwalk_points_vertical_edge_three_screen_y &1d92 85 68 STA &68 ; line_end_y &1d94 ad cd 4c LDA &4ccd ; catwalk_points_vertical_edge_three_screen_y_high &1d97 85 69 STA &69 ; line_end_y_high &1d99 20 4f 29 JSR &294f ; plot_vertical_line # Plot right of level three catwalk ; plot_top_of_level_three_catwalk &1d9c bd c0 4b LDA &4bc0,X ; catwalk_points_edge_left_screen_x &1d9f 85 66 STA &66 ; line_end_x &1da1 bd c1 4b LDA &4bc1,X ; catwalk_points_edge_left_screen_x_high &1da4 85 67 STA &67 ; line_end_x_high &1da6 a5 64 LDA &64 ; line_start_y &1da8 85 68 STA &68 ; line_end_y &1daa a5 65 LDA &65 ; line_start_y_high &1dac 85 69 STA &69 ; line_end_y_high &1dae 20 6c 2a JSR &2a6c ; plot_horizontal_line # Plot top of level three catwalk &1db1 bd c2 4b LDA &4bc2,X ; catwalk_points_centre_left_screen_x &1db4 85 62 STA &62 ; line_start_x &1db6 bd c3 4b LDA &4bc3,X ; catwalk_points_centre_left_screen_x_high &1db9 85 63 STA &63 ; line_start_x_high &1dbb ad ca 4c LDA &4cca ; catwalk_points_centre_three_screen_y &1dbe 85 64 STA &64 ; line_start_y &1dc0 85 68 STA &68 ; line_end_y &1dc2 ad cb 4c LDA &4ccb ; catwalk_points_centre_three_screen_y_high &1dc5 85 65 STA &65 ; line_start_y_high &1dc7 85 69 STA &69 ; line_end_y_high &1dc9 b9 c6 4b LDA &4bc6,Y ; catwalk_points_centre_right_screen_x &1dcc 85 66 STA &66 ; line_end_x &1dce b9 c7 4b LDA &4bc7,Y ; catwalk_points_centre_right_screen_x_high &1dd1 85 67 STA &67 ; line_end_x_high &1dd3 20 6c 2a JSR &2a6c ; plot_horizontal_line # Plot centre of level three catwalk ; consider_plotting_level_four_catwalk &1dd6 ad 8f 08 LDA &088f ; catwalks_bitmap &1dd9 29 88 AND #&88 &1ddb d0 03 BNE &1de0 ; plot_level_four_catwalk # Branch if any catwalk at level four &1ddd 4c 11 1f JMP &1f11 ; leave ; plot_level_four_catwalk &1de0 85 5a STA &5a ; this_catwalk_bitmap &1de2 ae 95 08 LDX &0895 ; level_four_catwalk_left_points &1de5 ac 99 08 LDY &0899 ; level_four_catwalk_right_points &1de8 ad b7 08 LDA &08b7 ; player_y_high &1deb c9 18 CMP #&18 &1ded 90 12 BCC &1e01 ; no_collision_with_level_four_catwalk &1def a5 47 LDA &47 ; point_z_high &1df1 c9 0c CMP #&0c &1df3 b0 0c BCS &1e01 ; no_collision_with_level_four_catwalk &1df5 a5 5a LDA &5a ; this_catwalk_bitmap &1df7 2d 91 08 AND &0891 ; player_catwalk_bitmap &1dfa f0 05 BEQ &1e01 ; no_collision_with_level_four_catwalk &1dfc a9 ff LDA #&ff &1dfe 8d 90 08 STA &0890 ; collided_with_catwalk # Set to negative to indicate collision with catwalk ; no_collision_with_level_four_catwalk &1e01 bd c0 4b LDA &4bc0,X ; catwalk_points_edge_left_screen_x &1e04 85 62 STA &62 ; line_start_x &1e06 bd c1 4b LDA &4bc1,X ; catwalk_points_edge_left_screen_x_high &1e09 85 63 STA &63 ; line_start_x_high &1e0b ad d0 4c LDA &4cd0 ; catwalk_points_vertical_edge_four_screen_y &1e0e 85 64 STA &64 ; line_start_y &1e10 ad d1 4c LDA &4cd1 ; catwalk_points_vertical_edge_four_screen_y_high &1e13 85 65 STA &65 ; line_start_y_high &1e15 a5 47 LDA &47 ; point_z_high &1e17 c9 60 CMP #&60 &1e19 b0 31 BCS &1e4c ; plot_simple_left_of_level_four_catwalk ; plot_detailed_left_of_level_four_catwalk &1e1b bd c2 4b LDA &4bc2,X ; catwalk_points_centre_left_screen_x &1e1e 85 66 STA &66 ; line_end_x &1e20 bd c3 4b LDA &4bc3,X ; catwalk_points_centre_left_screen_x_high &1e23 85 67 STA &67 ; line_end_x_high &1e25 ad ce 4c LDA &4cce ; catwalk_points_centre_four_screen_y &1e28 85 68 STA &68 ; line_end_y &1e2a ad cf 4c LDA &4ccf ; catwalk_points_centre_four_screen_y_high &1e2d 85 69 STA &69 ; line_end_y_high &1e2f 20 db 23 JSR &23db ; plot_line # Plot top left of level four catwalk &1e32 bd c0 4b LDA &4bc0,X ; catwalk_points_edge_left_screen_x &1e35 85 66 STA &66 ; line_end_x &1e37 bd c1 4b LDA &4bc1,X ; catwalk_points_edge_left_screen_x_high &1e3a 85 67 STA &67 ; line_end_x_high &1e3c ad cc 4c LDA &4ccc ; catwalk_points_vertical_edge_three_screen_y &1e3f 85 68 STA &68 ; line_end_y &1e41 ad cd 4c LDA &4ccd ; catwalk_points_vertical_edge_three_screen_y_high &1e44 85 69 STA &69 ; line_end_y_high &1e46 20 db 23 JSR &23db ; plot_line # Plot bottom left of level four catwalk &1e49 4c 63 1e JMP &1e63 ; plot_bottom_of_level_four_catwalk ; plot_simple_left_of_level_four_catwalk &1e4c bd c0 4b LDA &4bc0,X ; catwalk_points_edge_left_screen_x &1e4f 85 66 STA &66 ; line_end_x &1e51 bd c1 4b LDA &4bc1,X ; catwalk_points_edge_left_screen_x_high &1e54 85 67 STA &67 ; line_end_x_high &1e56 ad cc 4c LDA &4ccc ; catwalk_points_vertical_edge_three_screen_y &1e59 85 68 STA &68 ; line_end_y &1e5b ad cd 4c LDA &4ccd ; catwalk_points_vertical_edge_three_screen_y_high &1e5e 85 69 STA &69 ; line_end_y_high &1e60 20 4f 29 JSR &294f ; plot_vertical_line # Plot left of level four catwalk ; plot_bottom_of_level_four_catwalk &1e63 ad cc 4c LDA &4ccc ; catwalk_points_vertical_edge_three_screen_y &1e66 85 68 STA &68 ; line_end_y &1e68 ad cd 4c LDA &4ccd ; catwalk_points_vertical_edge_three_screen_y_high &1e6b 85 69 STA &69 ; line_end_y_high &1e6d b9 c4 4b LDA &4bc4,Y ; catwalk_points_edge_right_screen_x &1e70 85 66 STA &66 ; line_end_x &1e72 b9 c5 4b LDA &4bc5,Y ; catwalk_points_edge_right_screen_x_high &1e75 85 67 STA &67 ; line_end_x_high &1e77 ad 8f 08 LDA &088f ; catwalks_bitmap &1e7a 29 44 AND #&44 &1e7c c9 44 CMP #&44 # If it wasn't already plotted in the level three catwalk, &1e7e f0 06 BEQ &1e86 ; skip_plotting_bottom_of_level_four_catwalk &1e80 20 6c 2a JSR &2a6c ; plot_horizontal_line # Plot bottom of level four catwalk &1e83 4c 89 1e JMP &1e89 ; plot_right_of_level_four_catwalk ; skip_plotting_bottom_of_level_four_catwalk &1e86 20 0f 29 JSR &290f ; set_line_start_to_line_end ; plot_right_of_level_four_catwalk &1e89 a5 47 LDA &47 ; point_z_high &1e8b c9 60 CMP #&60 &1e8d b0 31 BCS &1ec0 ; plot_simple_right_of_level_four_catwalk ; plot_detailed_right_of_level_four_catwalk &1e8f b9 c6 4b LDA &4bc6,Y ; catwalk_points_centre_right_screen_x &1e92 85 66 STA &66 ; line_end_x &1e94 b9 c7 4b LDA &4bc7,Y ; catwalk_points_centre_right_screen_x_high &1e97 85 67 STA &67 ; line_end_x_high &1e99 ad ce 4c LDA &4cce ; catwalk_points_centre_four_screen_y &1e9c 85 68 STA &68 ; line_end_y &1e9e ad cf 4c LDA &4ccf ; catwalk_points_centre_four_screen_y_high &1ea1 85 69 STA &69 ; line_end_y_high &1ea3 20 db 23 JSR &23db ; plot_line # Plot bottom right of level four catwalk &1ea6 b9 c4 4b LDA &4bc4,Y ; catwalk_points_edge_right_screen_x &1ea9 85 66 STA &66 ; line_end_x &1eab b9 c5 4b LDA &4bc5,Y ; catwalk_points_edge_right_screen_x_high &1eae 85 67 STA &67 ; line_end_x_high &1eb0 ad d0 4c LDA &4cd0 ; catwalk_points_vertical_edge_four_screen_y &1eb3 85 68 STA &68 ; line_end_y &1eb5 ad d1 4c LDA &4cd1 ; catwalk_points_vertical_edge_four_screen_y_high &1eb8 85 69 STA &69 ; line_end_y_high &1eba 20 db 23 JSR &23db ; plot_line # Plot top right of level four catwalk &1ebd 4c d7 1e JMP &1ed7 ; plot_top_of_level_four_catwalk ; plot_simple_right_of_level_four_catwalk &1ec0 b9 c4 4b LDA &4bc4,Y ; catwalk_points_edge_right_screen_x &1ec3 85 66 STA &66 ; line_end_x &1ec5 b9 c5 4b LDA &4bc5,Y ; catwalk_points_edge_right_screen_x_high &1ec8 85 67 STA &67 ; line_end_x_high &1eca ad d0 4c LDA &4cd0 ; catwalk_points_vertical_edge_four_screen_y &1ecd 85 68 STA &68 ; line_end_y &1ecf ad d1 4c LDA &4cd1 ; catwalk_points_vertical_edge_four_screen_y_high &1ed2 85 69 STA &69 ; line_end_y_high &1ed4 20 4f 29 JSR &294f ; plot_vertical_line # Plot right of level four catwalk ; plot_top_of_level_four_catwalk &1ed7 bd c0 4b LDA &4bc0,X ; catwalk_points_edge_left_screen_x &1eda 85 66 STA &66 ; line_end_x &1edc bd c1 4b LDA &4bc1,X ; catwalk_points_edge_left_screen_x_high &1edf 85 67 STA &67 ; line_end_x_high &1ee1 a5 64 LDA &64 ; line_start_y &1ee3 85 68 STA &68 ; line_end_y &1ee5 a5 65 LDA &65 ; line_start_y_high &1ee7 85 69 STA &69 ; line_end_y_high &1ee9 20 6c 2a JSR &2a6c ; plot_horizontal_line # Plot top of level four catwalk &1eec bd c2 4b LDA &4bc2,X ; catwalk_points_centre_left_screen_x &1eef 85 62 STA &62 ; line_start_x &1ef1 bd c3 4b LDA &4bc3,X ; catwalk_points_centre_left_screen_x_high &1ef4 85 63 STA &63 ; line_start_x_high &1ef6 ad ce 4c LDA &4cce ; catwalk_points_centre_four_screen_y &1ef9 85 64 STA &64 ; line_start_y &1efb 85 68 STA &68 ; line_end_y &1efd ad cf 4c LDA &4ccf ; catwalk_points_centre_four_screen_y_high &1f00 85 69 STA &69 ; line_end_y_high &1f02 85 69 STA &69 ; line_end_y_high &1f04 b9 c6 4b LDA &4bc6,Y ; catwalk_points_centre_right_screen_x &1f07 85 66 STA &66 ; line_end_x &1f09 b9 c7 4b LDA &4bc7,Y ; catwalk_points_centre_right_screen_x_high &1f0c 85 67 STA &67 ; line_end_x_high &1f0e 20 6c 2a JSR &2a6c ; plot_horizontal_line # Plot centre of level four catwalk ; leave &1f11 60 RTS ; plot_death_star &1f12 a9 80 LDA #&80 &1f14 85 40 STA &40 ; point_x &1f16 a9 08 LDA #&08 &1f18 85 41 STA &41 ; point_x_high &1f1a a9 00 LDA #&00 &1f1c 85 46 STA &46 ; point_z &1f1e 85 1d STA &1d ; centre_x_high &1f20 85 1f STA &1f ; centre_y_high &1f22 a9 40 LDA #&40 &1f24 85 1c STA &1c ; centre_x &1f26 a9 54 LDA #&54 &1f28 85 1e STA &1e ; centre_y &1f2a 20 75 39 JSR &3975 ; divide_point_x_by_point_z_times_two # Scale death star by distance &1f2d a5 78 LDA &78 ; result_fraction &1f2f 85 7d STA &7d ; radius &1f31 a5 79 LDA &79 ; result &1f33 85 7e STA &7e ; radius_high &1f35 a9 03 LDA #&03 ; G &1f37 20 ab 23 JSR &23ab ; set_colour &1f3a 20 ae 36 JSR &36ae ; plot_circle # Plot outline &1f3d a2 b8 LDX #&b8 &1f3f 20 d6 36 JSR &36d6 ; rotate_around_centre &1f42 20 0f 29 JSR &290f ; set_line_start_to_line_end &1f45 a2 38 LDX #&38 &1f47 20 d6 36 JSR &36d6 ; rotate_around_centre &1f4a a9 01 LDA #&01 ; C &1f4c 20 ab 23 JSR &23ab ; set_colour &1f4f 20 db 23 JSR &23db ; plot_line # Plot equator &1f52 a5 1e LDA &1e ; centre_y &1f54 18 CLC &1f55 65 04 ADC &04 ; radius_x &1f57 85 1e STA &1e ; centre_y &1f59 46 04 LSR &04 ; radius_x &1f5b a5 1c LDA &1c ; centre_x &1f5d 18 CLC &1f5e 65 04 ADC &04 ; radius_x &1f60 85 1c STA &1c ; centre_x &1f62 a5 04 LDA &04 ; radius_x &1f64 85 7d STA &7d ; radius &1f66 a9 02 LDA #&02 ; R &1f68 20 ab 23 JSR &23ab ; set_colour &1f6b 20 ae 36 JSR &36ae ; plot_circle # Plot dish outline &1f6e a2 60 LDX #&60 ; plot_death_star_dish_loop &1f70 a5 1c LDA &1c ; centre_x &1f72 85 62 STA &62 ; line_start_x &1f74 a5 1d LDA &1d ; centre_x_high &1f76 85 63 STA &63 ; line_start_x_high &1f78 a5 1e LDA &1e ; centre_y &1f7a 85 64 STA &64 ; line_start_y &1f7c a5 1f LDA &1f ; centre_y_high &1f7e 85 65 STA &65 ; line_start_y_high &1f80 20 d6 36 JSR &36d6 ; rotate_around_centre &1f83 20 db 23 JSR &23db ; plot_line # Plot dish spoke &1f86 8a TXA &1f87 18 CLC &1f88 69 10 ADC #&10 &1f8a aa TAX &1f8b d0 e3 BNE &1f70 ; plot_death_star_dish_loop &1f8d 60 RTS ; plot_points_next_tower &1f8e ad 8a 08 LDA &088a ; wave_as_bcd &1f91 c9 03 CMP #&03 &1f93 b0 01 BCS &1f96 ; is_wave_three_or_after &1f95 60 RTS ; is_wave_three_or_after &1f96 20 9d 23 JSR &239d ; wipe_message_area &1f99 a2 01 LDX #&01 ; plot_points_next_tower_to_buffers_loop &1f9b 8a TXA &1f9c 48 PHA ; buffer &1f9d a9 dd LDA #&dd ; &42dd = points_next_tower_string &1f9f 85 18 STA &18 ; text_address_low &1fa1 a9 42 LDA #&42 &1fa3 85 19 STA &19 ; text_address_high &1fa5 20 9d 2d JSR &2d9d ; plot_string_to_buffer # Plot "POINTS NEXT TOWER" &1fa8 a9 28 LDA #&28 &1faa 85 16 STA &16 ; text_screen_offset_low &1fac a9 03 LDA #&03 &1fae 85 17 STA &17 ; text_screen_offset_high &1fb0 a9 ff LDA #&ff ; GG &1fb2 85 1a STA &1a ; colour_pixel_value &1fb4 ad ac 08 LDA &08ac ; points_next_tower &1fb7 20 30 2e JSR &2e30 ; plot_two_digit_number # Plot number of points next tower &1fba a9 00 LDA #&00 &1fbc 20 30 2e JSR &2e30 ; plot_two_digit_number &1fbf 20 6c 2e JSR &2e6c ; use_other_buffer &1fc2 68 PLA ; buffer &1fc3 aa TAX &1fc4 ca DEX &1fc5 10 d4 BPL &1f9b ; plot_points_next_tower_to_buffers_loop &1fc7 60 RTS ; update_towers_remaining &1fc8 ad 8a 08 LDA &088a ; wave_as_bcd &1fcb c9 03 CMP #&03 &1fcd b0 01 BCS &1fd0 ; is_wave_three_or_after ; leave &1fcf 60 RTS ; is_wave_three_or_after &1fd0 ad 01 03 LDA &0301 ; towers_remaining_as_bcd &1fd3 f0 fa BEQ &1fcf ; leave &1fd5 30 f8 BMI &1fcf ; leave &1fd7 f8 SED &1fd8 ad 01 03 LDA &0301 ; towers_remaining_as_bcd &1fdb 38 SEC &1fdc e9 01 SBC #&01 &1fde 8d 01 03 STA &0301 ; towers_remaining_as_bcd &1fe1 d8 CLD &1fe2 a9 ff LDA #&ff ; GG &1fe4 85 1a STA &1a ; colour_pixel_value &1fe6 a2 01 LDX #&01 ; plot_towers_remaining_to_buffers_loop &1fe8 8a TXA &1fe9 48 PHA ; buffer &1fea a9 e0 LDA #&e0 &1fec 85 16 STA &16 ; text_screen_offset_low &1fee a9 02 LDA #&02 &1ff0 85 17 STA &17 ; text_screen_offset_high &1ff2 ad 01 03 LDA &0301 ; towers_remaining_as_bcd &1ff5 20 30 2e JSR &2e30 ; plot_two_digit_number &1ff8 20 6c 2e JSR &2e6c ; use_other_buffer &1ffb 68 PLA ; buffer &1ffc aa TAX &1ffd ca DEX &1ffe 10 e8 BPL &1fe8 ; plot_towers_remaining_to_buffers_loop &2000 60 RTS ; plot_set_of_side_ports &2001 ad 85 08 LDA &0885 ; side_ports_z_high &2004 38 SEC &2005 ed b9 08 SBC &08b9 ; player_z_high &2008 8d 0f 03 STA &030f ; side_ports_relative_z_high &200b f0 09 BEQ &2016 ; leave_with_bitmap &200d 08 PHP ; carry &200e c9 f0 CMP #&f0 &2010 90 08 BCC &201a ; is_visible &2012 ad 9c 08 LDA &089c ; side_ports_bitmap &2015 28 PLP ; carry ; leave_with_bitmap &2016 ad 9c 08 LDA &089c ; side_ports_bitmap &2019 60 RTS ; is_visible &201a 28 PLP ; carry &201b ad 86 08 LDA &0886 ; side_ports_z_highest &201e ed ba 08 SBC &08ba ; player_z_highest &2021 d0 f3 BNE &2016 ; leave_with_bitmap &2023 a9 00 LDA #&00 &2025 85 40 STA &40 ; point_x &2027 85 43 STA &43 ; point_y &2029 85 46 STA &46 ; point_z &202b a9 0e LDA #&0e # Consider right set of side ports (X = 2) first &202d 38 SEC &202e ed b5 08 SBC &08b5 ; player_x_high &2031 8d 0b 03 STA &030b ; side_ports_relative_x_high &2034 a9 20 LDA #&20 &2036 38 SEC &2037 ed b7 08 SBC &08b7 ; player_y_high &203a 8d 0d 03 STA &030d ; side_ports_relative_y_high &203d a2 02 LDX #&02 ; calculate_side_port_points_loop &203f ad 0b 03 LDA &030b ; side_ports_relative_x_high &2042 85 41 STA &41 ; point_x_high &2044 ad 0f 03 LDA &030f ; side_ports_relative_z_high &2047 85 47 STA &47 ; point_z_high &2049 20 df 38 JSR &38df ; calculate_screen_x_for_point # Calculate screen x of near edge of side port &204c a5 66 LDA &66 ; screen_x &204e 9d c0 4b STA &4bc0,X ; side_port_points_near_screen_x &2051 a5 67 LDA &67 ; screen_x_high &2053 9d e0 4b STA &4be0,X ; side_port_points_near_screen_x_high &2056 ad 0f 03 LDA &030f ; side_ports_relative_z_high &2059 18 CLC &205a 69 0a ADC #&0a &205c 85 47 STA &47 ; point_z_high &205e f0 b6 BEQ &2016 ; leave_with_bitmap # Leave if side port would only have far edge visible &2060 ad 0b 03 LDA &030b ; side_ports_relative_x_high &2063 85 41 STA &41 ; point_x_high &2065 ad 0d 03 LDA &030d ; side_ports_relative_y_high &2068 85 44 STA &44 ; point_y_high &206a 20 df 38 JSR &38df ; calculate_screen_x_for_point # Calculate screen x of far edge of side port &206d a5 66 LDA &66 ; screen_x &206f 9d c1 4b STA &4bc1,X ; side_port_points_far_screen_x &2072 a5 67 LDA &67 ; screen_x_high &2074 9d e1 4b STA &4be1,X ; side_port_points_far_screen_x_high &2077 a9 00 LDA #&00 &2079 85 40 STA &40 ; point_x &207b 85 43 STA &43 ; point_y &207d 85 46 STA &46 ; point_z &207f ad 0b 03 LDA &030b ; side_ports_relative_x_high &2082 85 41 STA &41 ; point_x_high &2084 ad 0d 03 LDA &030d ; side_ports_relative_y_high &2087 38 SEC &2088 e9 03 SBC #&03 &208a 85 44 STA &44 ; point_y_high &208c ad 0f 03 LDA &030f ; side_ports_relative_z_high &208f 18 CLC &2090 69 05 ADC #&05 &2092 85 47 STA &47 ; point_z_high &2094 20 4c 38 JSR &384c ; calculate_screen_position_for_point # Calculate screen x and y of centre of side port &2097 a5 66 LDA &66 ; screen_x &2099 9d f0 4b STA &4bf0,X ; side_port_points_target_x &209c a5 67 LDA &67 ; screen_x_high &209e 9d f1 4b STA &4bf1,X ; side_port_points_target_x_high &20a1 a5 68 LDA &68 ; screen_y &20a3 9d f0 4c STA &4cf0,X ; side_port_points_target_y &20a6 a5 69 LDA &69 ; screen_y_high &20a8 9d f1 4c STA &4cf1,X ; side_port_points_target_y_high &20ab ca DEX &20ac ca DEX &20ad 30 0b BMI &20ba ; finished_calculating_side_port_points &20af ad 0b 03 LDA &030b ; side_ports_relative_x_high # Repeat for left set of side ports (X = 0) &20b2 38 SEC &20b3 e9 1c SBC #&1c &20b5 8d 0b 03 STA &030b ; side_ports_relative_x_high &20b8 30 85 BMI &203f ; calculate_side_port_points_loop ; finished_calculating_side_port_points &20ba ad 9c 08 LDA &089c ; side_ports_bitmap &20bd 29 0f AND #&0f &20bf 8d 9d 08 STA &089d ; side_port_side_bitmaps + 0 (left) &20c2 ad 9c 08 LDA &089c ; side_ports_bitmap &20c5 29 f0 AND #&f0 &20c7 4a LSR A &20c8 4a LSR A &20c9 4a LSR A &20ca 4a LSR A &20cb 8d 9f 08 STA &089f ; side_port_side_bitmaps + 2 (right) &20ce a9 00 LDA #&00 &20d0 8d 9b 08 STA &089b ; side_ports_processed ; plot_set_of_side_ports_loop &20d3 ad 9f 08 LDA &089f ; side_port_side_bitmaps + 2 (right) &20d6 29 0f AND #&0f &20d8 d0 2f BNE &2109 ; plot_side_ports_pair &20da ad 9f 08 LDA &089f ; side_port_side_bitmaps + 2 (right) &20dd 29 0f AND #&0f &20df d0 28 BNE &2109 ; plot_side_ports_pair &20e1 ad 9b 08 LDA &089b ; side_ports_processed &20e4 c9 04 CMP #&04 &20e6 f0 10 BEQ &20f8 ; finished_plotting_side_ports ; rotate_bitmaps_loop &20e8 4e 9d 08 LSR &089d ; side_port_side_bitmaps + 0 (left) &20eb 4e 9f 08 LSR &089f ; side_port_side_bitmaps + 2 (right) &20ee ee 9b 08 INC &089b ; side_ports_processed &20f1 ad 9b 08 LDA &089b ; side_ports_processed &20f4 c9 04 CMP #&04 &20f6 90 f0 BCC &20e8 ; rotate_bitmaps_loop ; finished_plotting_side_ports &20f8 ad 9d 08 LDA &089d ; side_port_side_bitmaps + 0 (left) &20fb 4a LSR A &20fc 4a LSR A &20fd 4a LSR A &20fe 4a LSR A &20ff 85 5f STA &5f ; left_bitmap &2101 ad 9f 08 LDA &089f ; side_port_side_bitmaps + 2 (right) &2104 29 f0 AND #&f0 &2106 05 5f ORA &5f ; left_bitmap &2108 60 RTS ; plot_side_ports_pair &2109 ee 9b 08 INC &089b ; side_ports_processed &210c ad 0d 03 LDA &030d ; side_ports_relative_y_high &210f 85 44 STA &44 ; point_y_high &2111 ad 0f 03 LDA &030f ; side_ports_relative_z_high &2114 85 47 STA &47 ; point_z_high &2116 20 2c 39 JSR &392c ; calculate_screen_y_for_point # Calculate screen y for near top of side port &2119 a5 68 LDA &68 ; screen_y &211b 8d c0 4c STA &4cc0 ; side_port_points_near_top_screen_y &211e a5 69 LDA &69 ; screen_y_high &2120 8d e0 4c STA &4ce0 ; side_port_points_near_top_screen_y_high &2123 ad 0d 03 LDA &030d ; side_ports_relative_y_high &2126 85 44 STA &44 ; point_y_high &2128 ad 0f 03 LDA &030f ; side_ports_relative_z_high &212b 18 CLC &212c 69 0a ADC #&0a &212e 85 47 STA &47 ; point_z_high &2130 20 2c 39 JSR &392c ; calculate_screen_y_for_point # Calculate screen y for far top of side port &2133 a5 68 LDA &68 ; screen_y &2135 8d c1 4c STA &4cc1 ; side_port_points_far_top_screen_y &2138 a5 69 LDA &69 ; screen_y_high &213a 8d e1 4c STA &4ce1 ; side_port_points_far_top_screen_y_high &213d ad 0f 03 LDA &030f ; side_ports_relative_z_high &2140 85 47 STA &47 ; point_z_high &2142 ad 0d 03 LDA &030d ; side_ports_relative_y_high &2145 38 SEC &2146 e9 06 SBC #&06 &2148 85 44 STA &44 ; point_y_high &214a 20 2c 39 JSR &392c ; calculate_screen_y_for_point # Calculate screen y for near bottom of side port &214d a5 68 LDA &68 ; screen_y &214f 8d c2 4c STA &4cc2 ; side_port_points_near_bottom_screen_y &2152 a5 69 LDA &69 ; screen_y_high &2154 8d e2 4c STA &4ce2 ; side_port_points_near_bottom_screen_y_high &2157 ad 0d 03 LDA &030d ; side_ports_relative_y_high &215a 38 SEC &215b e9 06 SBC #&06 &215d 85 44 STA &44 ; point_y_high &215f ad 0f 03 LDA &030f ; side_ports_relative_z_high &2162 18 CLC &2163 69 0a ADC #&0a &2165 85 47 STA &47 ; point_z_high &2167 20 2c 39 JSR &392c ; calculate_screen_y_for_point # Calculate screen y for far bottom of side port &216a a5 68 LDA &68 ; screen_y &216c 8d c3 4c STA &4cc3 ; side_port_points_far_bottom_screen_y &216f a5 69 LDA &69 ; screen_y_high &2171 8d e3 4c STA &4ce3 ; side_port_points_far_bottom_screen_y_high &2174 a2 02 LDX #&02 ; plot_side_ports_pair_loop &2176 5e 9d 08 LSR &089d,X ; side_port_side_bitmaps &2179 b0 03 BCS &217e ; plot_side_port &217b 4c 31 22 JMP &2231 ; consider_next_side_port ; plot_side_port &217e bd c1 4b LDA &4bc1,X ; side_port_points_far_screen_x &2181 85 62 STA &62 ; line_start_x &2183 bd e1 4b LDA &4be1,X ; side_port_points_far_screen_x_high &2186 85 63 STA &63 ; line_start_x_high &2188 ad c3 4c LDA &4cc3 ; side_port_points_far_bottom_screen_y &218b 85 64 STA &64 ; line_start_y &218d ad e3 4c LDA &4ce3 ; side_port_points_far_bottom_screen_y_high &2190 85 65 STA &65 ; line_start_y_high &2192 bd c0 4b LDA &4bc0,X ; side_port_points_near_screen_x &2195 85 66 STA &66 ; line_end_x &2197 bd e0 4b LDA &4be0,X ; side_port_points_near_screen_x_high &219a 85 67 STA &67 ; line_end_x_high &219c ad c2 4c LDA &4cc2 ; side_port_points_near_bottom_screen_y &219f 85 68 STA &68 ; line_end_y &21a1 ad e2 4c LDA &4ce2 ; side_port_points_near_bottom_screen_y_high &21a4 85 69 STA &69 ; line_end_y_high &21a6 20 db 23 JSR &23db ; plot_line # Plot bottom edge of side port &21a9 a5 62 LDA &62 ; line_start_x &21ab 85 66 STA &66 ; line_end_x &21ad a5 63 LDA &63 ; line_start_x_high &21af 85 67 STA &67 ; line_end_x_high &21b1 ad c0 4c LDA &4cc0 ; side_port_points_near_top_screen_y &21b4 85 68 STA &68 ; line_end_y &21b6 ad e0 4c LDA &4ce0 ; side_port_points_near_top_screen_y_high &21b9 85 69 STA &69 ; line_end_y_high &21bb 20 4f 29 JSR &294f ; plot_vertical_line # Plot near edge of side port &21be bd c1 4b LDA &4bc1,X ; side_port_points_far_screen_x &21c1 85 66 STA &66 ; line_end_x &21c3 bd e1 4b LDA &4be1,X ; side_port_points_far_screen_x_high &21c6 85 67 STA &67 ; line_end_x_high &21c8 ad c1 4c LDA &4cc1 ; side_port_points_far_top_screen_y &21cb 85 68 STA &68 ; line_end_y &21cd ad e1 4c LDA &4ce1 ; side_port_points_far_top_screen_y_high &21d0 85 69 STA &69 ; line_end_y_high &21d2 20 db 23 JSR &23db ; plot_line # Plot top edge of side port &21d5 a5 62 LDA &62 ; line_start_x &21d7 85 66 STA &66 ; line_end_x &21d9 a5 63 LDA &63 ; line_start_x_high &21db 85 67 STA &67 ; line_end_x_high &21dd ad c3 4c LDA &4cc3 ; side_port_points_far_bottom_screen_y &21e0 85 68 STA &68 ; line_end_y &21e2 ad e3 4c LDA &4ce3 ; side_port_points_far_bottom_screen_y_high &21e5 85 69 STA &69 ; line_end_y_high &21e7 20 4f 29 JSR &294f ; plot_vertical_line # Plot far edge of side port ; check_for_hitting_side_port &21ea bd f0 4b LDA &4bf0,X ; side_port_points_target_x &21ed 8d 02 03 STA &0302 ; target_x &21f0 bd f1 4b LDA &4bf1,X ; side_port_points_target_x_high &21f3 8d 03 03 STA &0303 ; target_x_high &21f6 bd f0 4c LDA &4cf0,X ; side_port_points_target_y &21f9 8d 04 03 STA &0304 ; target_y &21fc bd f1 4c LDA &4cf1,X ; side_port_points_target_y_high &21ff 8d 05 03 STA &0305 ; target_y_high &2202 ad 0f 03 LDA &030f ; side_ports_relative_z_high &2205 18 CLC &2206 69 05 ADC #&05 &2208 85 55 STA &55 ; origin_z_high &220a a9 18 LDA #&18 &220c 20 5d 42 JSR &425d ; check_for_player_hitting_target # Returns negative if player hit target &220f 10 18 BPL &2229 ; no_hit ; hit_side_port &2211 ad 80 03 LDA &0380 ; side_port_score_low &2214 85 70 STA &70 ; number &2216 ad 81 03 LDA &0381 ; side_port_score_high &2219 85 71 STA &71 ; number + 1 &221b a9 00 LDA #&00 &221d 85 72 STA &72 ; number + 2 &221f 8a TXA &2220 48 PHA ; tmp_x &2221 20 2f 16 JSR &162f ; add_to_score # Score for hitting side_ports opening &2224 68 PLA ; tmp_x &2225 aa TAX &2226 4c 31 22 JMP &2231 ; consider_next_side_port ; no_hit &2229 bd 9d 08 LDA &089d,X ; side_port_side_bitmaps &222c 09 80 ORA #&80 # Set top bit to indicate side port still present &222e 9d 9d 08 STA &089d,X ; side_port_side_bitmaps ; consider_next_side_port &2231 ca DEX &2232 ca DEX &2233 30 03 BMI &2238 ; finished_plotting_pair &2235 4c 76 21 JMP &2176 ; plot_side_ports_pair_loop ; finished_plotting_pair &2238 ad 0d 03 LDA &030d ; side_ports_relative_y_high &223b 38 SEC &223c e9 08 SBC #&08 &223e 8d 0d 03 STA &030d ; side_ports_relative_y_high &2241 4c d3 20 JMP &20d3 ; plot_set_of_side_ports_loop ; update_space_stars &2244 a9 01 LDA #&01 ; C &2246 20 ab 23 JSR &23ab ; set_colour &2249 a2 0f LDX #&0f ; update_space_stars_loop &224b 8a TXA &224c 48 PHA ; star offset &224d bd c0 03 LDA &03c0,X ; stars_screen_y &2250 18 CLC &2251 6d a2 08 ADC &08a2 ; player_y_velocity # Apply player velocity to star &2254 9d c0 03 STA &03c0,X ; stars_screen_y &2257 bd a0 03 LDA &03a0,X ; stars_screen_x &225a 18 CLC &225b 6d a0 08 ADC &08a0 ; player_x_velocity &225e 9d a0 03 STA &03a0,X ; stars_screen_x &2261 38 SEC &2262 e9 40 SBC #&40 &2264 10 22 BPL &2288 ; is_right_half_of_screen ; is_left_half_of_screen # If star is in left half of screen, &2266 85 5f STA &5f ; x_velocity &2268 a9 00 LDA #&00 &226a 38 SEC &226b e5 5f SBC &5f ; x_velocity &226d 4a LSR A &226e 4a LSR A &226f 4a LSR A &2270 85 5f STA &5f ; x_velocity &2272 bd a0 03 LDA &03a0,X ; stars_screen_x &2275 38 SEC &2276 e5 5f SBC &5f ; x_velocity # Move star left, faster further from centre &2278 9d a0 03 STA &03a0,X ; stars_screen_x &227b 10 21 BPL &229e ; update_star_vertically ; is_off_left_of_screen &227d 20 ff 37 JSR &37ff ; rnd &2280 29 7f AND #&7f &2282 9d a0 03 STA &03a0,X ; stars_screen_x &2285 4c 9e 22 JMP &229e ; update_star_vertically ; is_right_half_of_screen # If star is in right half of screen, &2288 4a LSR A &2289 4a LSR A &228a 4a LSR A &228b 85 5f STA &5f ; x_velocity # Unnecessary code &228d 18 CLC &228e 7d a0 03 ADC &03a0,X ; stars_screen_x # Move star right, faster further from centre &2291 9d a0 03 STA &03a0,X ; stars_screen_x &2294 10 08 BPL &229e ; update_star_vertically ; is_off_right_of_screen &2296 20 ff 37 JSR &37ff ; rnd &2299 29 7f AND #&7f &229b 9d a0 03 STA &03a0,X ; stars_screen_x ; update_star_vertically &229e bd c0 03 LDA &03c0,X ; stars_screen_y &22a1 38 SEC &22a2 e9 50 SBC #&50 &22a4 10 25 BPL &22cb ; is_top_half_of_screen ; is_bottom_half_of_screen # If star is in bottom half of screen, &22a6 85 5f STA &5f ; y_velocity &22a8 a9 00 LDA #&00 &22aa 38 SEC &22ab e5 5f SBC &5f ; y_velocity &22ad 4a LSR A &22ae 4a LSR A &22af 4a LSR A &22b0 85 5f STA &5f ; y_velocity &22b2 bd c0 03 LDA &03c0,X ; stars_screen_y &22b5 38 SEC &22b6 e5 5f SBC &5f ; y_velocity # Move star down, faster further from centre &22b8 9d c0 03 STA &03c0,X ; stars_screen_y &22bb c9 a0 CMP #&a0 &22bd 90 26 BCC &22e5 ; not_off_top_or_bottom_of_screen ; is_off_bottom_of_screen &22bf 20 ff 37 JSR &37ff ; rnd &22c2 c9 a0 CMP #&a0 &22c4 90 02 BCC &22c8 ; skip_wraparound &22c6 e9 a0 SBC #&a0 ; skip_wraparound &22c8 9d c0 03 STA &03c0,X ; stars_screen_y ; is_top_half_of_screen # If star is in top half of screen, &22cb 4a LSR A &22cc 4a LSR A &22cd 4a LSR A &22ce 18 CLC &22cf 7d c0 03 ADC &03c0,X ; stars_screen_y # Move star up, faster further from centre &22d2 9d c0 03 STA &03c0,X ; stars_screen_y &22d5 c9 a0 CMP #&a0 &22d7 90 0c BCC &22e5 ; not_off_top_or_bottom_of_screen ; is_off_top_of_screen &22d9 20 ff 37 JSR &37ff ; rnd &22dc c9 a0 CMP #&a0 &22de 90 02 BCC &22e2 ; skip_wraparound &22e0 e9 a0 SBC #&a0 ; skip_wraparound &22e2 9d c0 03 STA &03c0,X ; stars_screen_y ; not_off_top_or_bottom_of_screen &22e5 ad a0 08 LDA &08a0 ; player_x_velocity &22e8 d0 0d BNE &22f7 ; skip_moving_from_centre_horizontally &22ea bd a0 03 LDA &03a0,X ; stars_screen_x &22ed 38 SEC &22ee e9 46 SBC #&46 &22f0 c9 14 CMP #&14 &22f2 b0 03 BCS &22f7 ; skip_moving_from_centre_horizontally # Branch unless &45 < x < &5a &22f4 9d a0 03 STA &03a0,X ; stars_screen_x # Move star from centre of screen horizontally ; skip_moving_from_centre_horizontally &22f7 ad a2 08 LDA &08a2 ; player_y_velocity &22fa d0 0d BNE &2309 ; skip_moving_from_centre_vertically &22fc bd c0 03 LDA &03c0,X ; stars_screen_y &22ff 38 SEC &2300 e9 46 SBC #&46 &2302 c9 14 CMP #&14 &2304 b0 03 BCS &2309 ; skip_moving_from_centre_vertically # Branch unless &45 < x < &5a &2306 9d c0 03 STA &03c0,X ; stars_screen_y # Move star from centre of screen vertically ; skip_moving_from_centre_vertically &2309 bc c0 03 LDY &03c0,X ; stars_screen_y &230c bd a0 03 LDA &03a0,X ; stars_screen_x &230f aa TAX &2310 20 23 29 JSR &2923 ; plot_pixel # Plot star &2313 68 PLA ; star offset &2314 aa TAX &2315 ca DEX &2316 30 03 BMI &231b ; leave &2318 4c 4b 22 JMP &224b ; update_space_stars_loop ; leave &231b 60 RTS ; reset_side_ports &231c a9 ff LDA #&ff # Side ports at all four heights, both sides &231e 8d 82 08 STA &0882 ; first_far_side_ports_bitmap &2321 a9 cc LDA #&cc # Side ports at top two heights, both sides &2323 8d 83 08 STA &0883 ; second_far_side_ports_bitmap &2326 ad 8a 08 LDA &088a ; wave_as_bcd &2329 c9 02 CMP #&02 &232b b0 0b BCS &2338 ; leave ; is_wave_one &232d a2 3f LDX #&3f ; reset_side_ports_state_loop &232f bd 0c 3e LDA &3e0c,X ; wave_one_side_ports_data &2332 9d 00 01 STA &0100,X ; wave_side_ports_state &2335 ca DEX &2336 10 f7 BPL &232f ; reset_side_ports_state_loop ; leave &2338 60 RTS ; swap_rnd_state_to_saved_rnd_state &2339 ad 30 38 LDA &3830 ; rnd_state &233c 48 PHA ; rnd_state &233d ad a4 08 LDA &08a4 ; saved_rnd_state &2340 8d 30 38 STA &3830 ; rnd_state &2343 68 PLA ; rnd_state &2344 8d a4 08 STA &08a4 ; saved_rnd_state &2347 ad 31 38 LDA &3831 ; rnd_state + 1 &234a 48 PHA ; rnd_state + 1 &234b ad a5 08 LDA &08a5 ; saved_rnd_state + 1 &234e 8d 31 38 STA &3831 ; rnd_state + 1 &2351 68 PLA ; rnd_state + 1 &2352 8d a5 08 STA &08a5 ; saved_rnd_state + 1 &2355 ad 32 38 LDA &3832 ; rnd_state + 2 &2358 48 PHA ; rnd_state + 2 &2359 ad a6 08 LDA &08a6 ; saved_rnd_state + 2 &235c 8d 32 38 STA &3832 ; rnd_state + 2 &235f 68 PLA ; rnd_state + 2 &2360 8d a6 08 STA &08a6 ; saved_rnd_state + 2 &2363 ad 33 38 LDA &3833 ; rnd_state + 3 &2366 48 PHA ; rnd_state + 3 &2367 ad a7 08 LDA &08a7 ; saved_rnd_state + 3 &236a 8d 33 38 STA &3833 ; rnd_state + 3 &236d 68 PLA ; rnd_state + 3 &236e 8d a7 08 STA &08a7 ; saved_rnd_state + 3 &2371 60 RTS ; lose_shield &2372 ad fc 4f LDA &4ffc ; player_hit_cooldown # Positive if player has recently been hit &2375 10 12 BPL &2389 ; leave &2377 a9 10 LDA #&10 &2379 20 de 44 JSR &44de ; play_sound # Play sound for player being hit &237c a2 07 LDX #&07 ; W &237e 20 8e 2e JSR &2e8e ; set_colour_zero_to_X # Flash background to white &2381 a9 03 LDA #&03 &2383 8d fc 4f STA &4ffc ; player_hit_cooldown &2386 ce 8d 03 DEC &038d ; shields ; leave &2389 60 RTS ; wipe_tower_count_area_and_message_area &238a a2 3f LDX #&3f ; wipe_tower_count_area_and_message_area_loop &238c a9 00 LDA #&00 &238e 9d c0 51 STA &51c0,X ; buffer_one + &100 * 1 + &c0 # Wipe right of status area, line two &2391 9d c0 69 STA &69c0,X ; buffer_two + &100 * 1 + &c0 &2394 9d c0 52 STA &52c0,X ; buffer_one + &100 * 2 + &c0 # Wipe right of status area, line three &2397 9d c0 6a STA &6ac0,X ; buffer_two + &100 * 2 + &c0 &239a ca DEX &239b 10 ef BPL &238c ; wipe_tower_count_area_and_message_area_loop ; wipe_message_area &239d a9 00 LDA #&00 &239f aa TAX ; wipe_message_area_loop &23a0 9d 00 53 STA &5300,X ; buffer_one + &100 * 3 # Wipe status area, line four &23a3 9d 00 6b STA &6b00,X ; buffer_two + &100 * 3 &23a6 e8 INX &23a7 d0 f7 BNE &23a0 ; wipe_message_area_loop &23a9 60 RTS ; tie_fighter_to_follow &23aa 28 ; set_colour &23ab 29 03 AND #&03 &23ad 85 5f STA &5f ; colour &23af 8a TXA &23b0 48 PHA ; tmp_x &23b1 a6 5f LDX &5f ; colour &23b3 bd c8 23 LDA &23c8,X ; colours_pixel_value_table &23b6 8d 10 26 STA &2610 ; shallow_line_colour &23b9 8d 9d 26 STA &269d ; steep_line_colour &23bc 8d 23 27 STA &2723 ; diagonal_line_colour &23bf 8d 44 29 STA &2944 ; pixel_colour &23c2 8d c3 29 STA &29c3 ; vertical_line_colour &23c5 68 PLA ; tmp_x &23c6 aa TAX &23c7 60 RTS ; colours_pixel_value_table ; 0 1 2 3 &23c8 ff 0f f0 ff ; colours_table &23cc 03 01 02 03 ; maximum_row &23d0 9f ; plot_onscreen_line &23d1 a9 00 LDA #&00 &23d3 85 63 STA &63 ; line_start_x_high # Set to zero to indicate start of line is onscreen &23d5 85 65 STA &65 ; line_start_y_high &23d7 85 67 STA &67 ; line_end_x_high # Set to zero to indicate end of line is onscreen &23d9 85 69 STA &69 ; line_end_y_high ; plot_line &23db ad d0 23 LDA &23d0 ; maximum_row &23de 8d 1a 26 STA &261a ; shallow_maximum_row &23e1 8d b3 26 STA &26b3 ; steep_maximum_row &23e4 8d 31 27 STA &2731 ; diagonal_maximum_row &23e7 a9 00 LDA #&00 &23e9 85 4e STA &4e ; line_start_offscreen_flags # Set to zero to indicate onscreen by default &23eb 85 4f STA &4f ; line_end_offscreen_flags # Set to zero to indicate onscreen by default &23ed a5 63 LDA &63 ; line_start_x_high &23ef f0 0e BEQ &23ff ; is_zero_start_x &23f1 10 06 BPL &23f9 ; is_offscreen_start_x_plus ; is_offscreen_start_x_minus &23f3 a9 01 LDA #&01 ; OFFSCREEN_X_MINUS &23f5 85 4e STA &4e ; line_start_offscreen_flags &23f7 d0 0e BNE &2407 ; skip_setting_flag_for_start_x # Always branches ; is_offscreen_start_x_plus &23f9 a9 02 LDA #&02 ; OFFSCREEN_X_PLUS &23fb 85 4e STA &4e ; line_start_offscreen_flags &23fd d0 08 BNE &2407 ; skip_setting_flag_for_start_x # Always branches ; is_zero_start_x &23ff a5 62 LDA &62 ; line_start_x &2401 10 04 BPL &2407 ; skip_setting_flag_for_start_x &2403 a9 02 LDA #&02 ; OFFSCREEN_X_PLUS &2405 85 4e STA &4e ; line_start_offscreen_flags ; skip_setting_flag_for_start_x &2407 a5 65 LDA &65 ; line_start_y_high &2409 f0 12 BEQ &241d ; is_zero_y &240b 10 08 BPL &2415 ; is_offscreen_start_y_plus ; is_offscreen_start_y_minus &240d a5 4e LDA &4e ; line_start_offscreen_flags &240f 09 04 ORA #&04 ; OFFSCREEN_Y_MINUS &2411 85 4e STA &4e ; line_start_offscreen_flags &2413 d0 15 BNE &242a ; skip_setting_flag_for_start_y # Always branches ; is_offscreen_y_plus &2415 a5 4e LDA &4e ; line_start_offscreen_flags &2417 09 08 ORA #&08 ; OFFSCREEN_Y_PLUS &2419 85 4e STA &4e ; line_start_offscreen_flags &241b d0 0d BNE &242a ; skip_setting_flag_for_start_y # Always branches ; is_zero_y &241d a5 64 LDA &64 ; line_start_y &241f cd d0 23 CMP &23d0 ; maximum_row &2422 90 06 BCC &242a ; skip_setting_flag_for_start_y &2424 a5 4e LDA &4e ; line_start_offscreen_flags &2426 09 08 ORA #&08 ; OFFSCREEN_Y_PLUS &2428 85 4e STA &4e ; line_start_offscreen_flags ; skip_setting_flag_for_start_y &242a a5 67 LDA &67 ; line_end_x_high &242c f0 0e BEQ &243c ; is_zero_end_x &242e 10 06 BPL &2436 ; is_offscreen_end_x_plus ; is_offscreen_end_x_minus &2430 a9 01 LDA #&01 ; OFFSCREEN_X_MINUS &2432 85 4f STA &4f ; line_end_offscreen_flags &2434 d0 0e BNE &2444 ; skip_setting_flag_for_end_x # Always branches ; is_offscreen_end_x_plus &2436 a9 02 LDA #&02 ; OFFSCREEN_X_PLUS &2438 85 4f STA &4f ; line_end_offscreen_flags &243a d0 08 BNE &2444 ; skip_setting_flag_for_end_x # Always branches ; is_zero_end_x &243c a5 66 LDA &66 ; line_end_x &243e 10 04 BPL &2444 ; skip_setting_flag_for_end_x &2440 a9 02 LDA #&02 ; OFFSCREEN_X_PLUS &2442 85 4f STA &4f ; line_end_offscreen_flags ; skip_setting_flag_for_end_x &2444 a5 69 LDA &69 ; line_end_y_high &2446 f0 12 BEQ &245a ; is_zero_end_y &2448 10 08 BPL &2452 ; is_offscreen_end_y_plus ; is_offscreen_end_y_minus &244a a5 4f LDA &4f ; line_end_offscreen_flags &244c 09 04 ORA #&04 ; OFFSCREEN_Y_MINUS &244e 85 4f STA &4f ; line_end_offscreen_flags &2450 d0 15 BNE &2467 ; skip_setting_flag_for_end_y # Always branches ; is_offscreen_end_y_plus &2452 a5 4f LDA &4f ; line_end_offscreen_flags &2454 09 08 ORA #&08 ; OFFSCREEN_Y_PLUS &2456 85 4f STA &4f ; line_end_offscreen_flags &2458 d0 0d BNE &2467 ; skip_setting_flag_for_end_y # Always branches ; is_zero_end_y &245a a5 68 LDA &68 ; line_end_y &245c cd d0 23 CMP &23d0 ; maximum_row &245f 90 06 BCC &2467 ; skip_setting_flag_for_end_y &2461 a5 4f LDA &4f ; line_end_offscreen_flags &2463 09 08 ORA #&08 ; OFFSCREEN_Y_PLUS &2465 85 4f STA &4f ; line_end_offscreen_flags ; skip_setting_flag_for_end_y &2467 a5 4e LDA &4e ; line_start_offscreen_flags # If the start &2469 25 4f AND &4f ; line_end_offscreen_flags # and end of the line share a flag, &246b f0 03 BEQ &2470 ; not_offscreen &246d 4c 0f 29 JMP &290f ; set_line_start_to_line_end # then the line is entirely offscreen; nothing to plot ; not_offscreen &2470 8a TXA &2471 48 PHA ; tmp_x &2472 98 TYA &2473 48 PHA ; tmp_y &2474 a5 67 LDA &67 ; line_end_x_high &2476 d0 1e BNE &2496 ; not_pixel &2478 c5 63 CMP &63 ; line_start_x_high &247a d0 1a BNE &2496 ; not_pixel &247c a5 69 LDA &69 ; line_end_y_high &247e d0 16 BNE &2496 ; not_pixel &2480 c5 65 CMP &65 ; line_start_y_high &2482 d0 12 BNE &2496 ; not_pixel &2484 a4 68 LDY &68 ; line_end_y &2486 c4 64 CPY &64 ; line_start_y &2488 d0 0c BNE &2496 ; not_pixel &248a a6 62 LDX &62 ; line_start_x &248c e4 66 CPX &66 ; line_end_x &248e d0 06 BNE &2496 ; not_pixel &2490 20 23 29 JSR &2923 ; plot_pixel # Plot single pixel where line start = line end &2493 4c 38 27 JMP &2738 ; leave_after_restoring_registers ; not_pixel &2496 a9 00 LDA #&00 &2498 85 0f STA &0f ; line_was_reversed # Set to positive to indicate not reversed by default &249a 85 10 STA &10 ; negative_x # Set to positive to indicate positive delta x by default &249c 85 11 STA &11 ; negative_y # Set to positive to indicate positive delta y by default &249e a5 63 LDA &63 ; line_start_x_high # Is the start of the line onscreen? &24a0 d0 11 BNE &24b3 ; check_end &24a2 a5 62 LDA &62 ; line_start_x &24a4 30 0d BMI &24b3 ; check_end &24a6 a5 65 LDA &65 ; line_start_y_high &24a8 d0 09 BNE &24b3 ; check_end &24aa a5 64 LDA &64 ; line_start_y &24ac cd d0 23 CMP &23d0 ; maximum_row &24af b0 02 BCS &24b3 ; check_end &24b1 90 1a BCC &24cd ; skip_reversing_line # If so, the start can be used as the start for plotting ; check_end &24b3 a5 67 LDA &67 ; line_end_x_high # Is the end of the line onscreen? &24b5 d0 16 BNE &24cd ; skip_reversing_line &24b7 a5 66 LDA &66 ; line_end_x &24b9 30 12 BMI &24cd ; skip_reversing_line &24bb a5 69 LDA &69 ; line_end_y_high &24bd d0 0e BNE &24cd ; skip_reversing_line &24bf a5 68 LDA &68 ; line_end_y &24c1 cd d0 23 CMP &23d0 ; maximum_row &24c4 b0 07 BCS &24cd ; skip_reversing_line &24c6 a9 ff LDA #&ff # If the end is onscreen, but the start is offscreen, &24c8 85 0f STA &0f ; line_was_reversed # Set to negative to indicate line was reversed &24ca 20 40 27 JSR &2740 ; swap_line_start_and_end # Use the end as the start for plotting ; skip_reversing_line &24cd a9 e8 LDA #&e8 ; INX &24cf 8d 1e 26 STA &261e ; move_along_shallow_line_horizontally_opcode &24d2 8d 2a 27 STA &272a ; move_along_diagonal_line_horizontally_opcode &24d5 a9 c8 LDA #&c8 ; DEY &24d7 8d b1 26 STA &26b1 ; move_along_steep_line_vertically_opcode &24da 8d 2f 27 STA &272f ; move_along_diagonal_line_vertically_opcode ; calculate_delta_x &24dd a5 66 LDA &66 ; line_end_x &24df 38 SEC &24e0 e5 62 SBC &62 ; line_start_x &24e2 85 0a STA &0a ; line_delta_x &24e4 a5 67 LDA &67 ; line_end_x_high &24e6 e5 63 SBC &63 ; line_start_x_high &24e8 85 0b STA &0b ; line_delta_x_high &24ea 10 0a BPL &24f6 ; calculate_delta_y ; is_negative_delta_x &24ec 85 10 STA &10 ; negative_x # Set to negative to indicate line has negative delta x &24ee a9 ca LDA #&ca ; DEX &24f0 8d 1e 26 STA &261e ; move_along_shallow_line_horizontally_opcode &24f3 8d 2a 27 STA &272a ; move_along_diagonal_line_horizontally_opcode ; calculate_delta_y &24f6 a5 68 LDA &68 ; line_end_y &24f8 38 SEC &24f9 e5 64 SBC &64 ; line_start_y &24fb 85 0c STA &0c ; line_delta_y &24fd a5 69 LDA &69 ; line_end_y_high &24ff e5 65 SBC &65 ; line_start_y_high &2501 85 0d STA &0d ; line_delta_y_high &2503 10 0a BPL &250f ; reset_row_or_column_fraction ; is_negative_delta_y &2505 85 11 STA &11 ; negative_y # Set to negative to indicate line has negative delta y &2507 a9 88 LDA #&88 ; DEY &2509 8d b1 26 STA &26b1 ; move_along_steep_line_vertically_opcode &250c 8d 2f 27 STA &272f ; move_along_diagonal_line_vertically_opcode ; reset_row_or_column_fraction &250f a9 00 LDA #&00 &2511 85 4c STA &4c ; row_fraction, column_fraction &2513 a5 69 LDA &69 ; line_end_y_high &2515 30 0b BMI &2522 ; use_unlimited_line_maximum_y &2517 d0 0d BNE &2526 ; use_maximum_row_as_line_maximum_y &2519 a5 68 LDA &68 ; line_end_y &251b cd d0 23 CMP &23d0 ; maximum_row &251e b0 02 BCS &2522 ; use_unlimited_line_maximum_y &2520 90 07 BCC &2529 ; set_line_maximum_y # If end on screen vertically, use as maximum y ; use_unlimited_line_maximum_y &2522 a9 ff LDA #&ff &2524 30 03 BMI &2529 ; set_line_maximum_y # Always branches ; use_maximum_row_as_line_maximum_y &2526 ad d0 23 LDA &23d0 ; maximum_row ; set_line_maximum_y &2529 8d b7 26 STA &26b7 ; steep_line_maximum_y &252c a5 67 LDA &67 ; line_end_x_high &252e 30 08 BMI &2538 ; use_unlimited_line_maximum_x &2530 d0 0a BNE &253c ; use_maximum_column_as_line_maximum_x &2532 a5 66 LDA &66 ; line_end_x &2534 30 02 BMI &2538 ; use_unlimited_line_maximum_x &2536 90 06 BCC &253e ; set_line_maximum_x # If end on screen horizontally, use as maximum x ; use_unlimited_line_maximum_x &2538 a9 ff LDA #&ff &253a 30 02 BMI &253e ; set_line_maximum_x ; use_maximum_column_as_line_maximum_x &253c a9 80 LDA #&80 ; set_line_maximum_x &253e 8d 22 26 STA &2622 ; shallow_line_maximum_x &2541 8d 35 27 STA &2735 ; diagonal_line_maximum_x &2544 a6 62 LDX &62 ; line_start_x # Used in plot_*_line as start x and y &2546 a4 64 LDY &64 ; line_start_y &2548 a5 67 LDA &67 ; line_end_x_high &254a d0 08 BNE &2554 ; skip_setting_maximum_x &254c a5 66 LDA &66 ; line_end_x # If end on screen horizontally, use as maximum x &254e 8d 22 26 STA &2622 ; shallow_line_maximum_x &2551 8d 35 27 STA &2735 ; diagonal_line_maximum_x ; skip_setting_maximum_x &2554 a5 69 LDA &69 ; line_end_y_high &2556 d0 05 BNE &255d ; skip_setting_maximum_y &2558 a5 68 LDA &68 ; line_end_y # If end on screen vertically, use as maximum y &255a 8d b7 26 STA &26b7 ; steep_line_maximum_y ; skip_setting_maximum_y &255d a5 10 LDA &10 ; negative_x # Negative if delta x is negative &255f 10 0d BPL &256e ; skip_inverting_delta_x &2561 a9 00 LDA #&00 # If so, make delta x positive &2563 38 SEC &2564 e5 0a SBC &0a ; line_delta_x &2566 85 0a STA &0a ; line_delta_x &2568 a9 00 LDA #&00 &256a e5 0b SBC &0b ; line_delta_x_high &256c 85 0b STA &0b ; line_delta_x_high ; skip_inverting_delta_x &256e a5 11 LDA &11 ; negative_y # Negative if delta y is negative &2570 10 0d BPL &257f ; skip_inverting_delta_y &2572 a9 00 LDA #&00 # If so, make delta y positive &2574 38 SEC &2575 e5 0c SBC &0c ; line_delta_y &2577 85 0c STA &0c ; line_delta_y &2579 a9 00 LDA #&00 &257b e5 0d SBC &0d ; line_delta_y_high &257d 85 0d STA &0d ; line_delta_y_high ; skip_inverting_delta_y &257f a5 0d LDA &0d ; line_delta_y_high &2581 c5 0b CMP &0b ; line_delta_x_high &2583 90 13 BCC &2598 ; plot_shallow_line # Plot shallow line if delta y < delta x &2585 f0 03 BEQ &258a ; check_low &2587 4c 28 26 JMP &2628 ; plot_steep_line ; check_low &258a a5 0c LDA &0c ; line_delta_y &258c c5 0a CMP &0a ; line_delta_x &258e 90 08 BCC &2598 ; plot_shallow_line &2590 f0 03 BEQ &2595 ; to_plot_diagonal_line &2592 4c 28 26 JMP &2628 ; plot_steep_line # Plot steep line if delta y > delta x ; to_plot_diagonal_line &2595 4c bd 26 JMP &26bd ; plot_diagonal_line # Plot diagonal line if delta y = delta x ; plot_shallow_line # Called with X = line start x, Y = line start y &2598 a5 0c LDA &0c ; line_delta_y &259a 85 2c STA &2c ; delta_one &259c a5 0d LDA &0d ; line_delta_y_high &259e 85 2d STA &2d ; delta_one_high &25a0 a5 0a LDA &0a ; line_delta_x &25a2 85 2e STA &2e ; delta_two &25a4 a5 0b LDA &0b ; line_delta_x_high &25a6 85 2f STA &2f ; delta_two_high &25a8 20 08 36 JSR &3608 ; calculate_line_slope # result = delta_y / delta_x &25ab a5 11 LDA &11 ; negative_y # Negative if delta y is negative &25ad 10 0d BPL &25bc ; skip_inverting_result &25af a9 00 LDA #&00 # If so, make line slope negative &25b1 38 SEC &25b2 e5 78 SBC &78 ; result_fraction &25b4 85 78 STA &78 ; result_fraction &25b6 a9 00 LDA #&00 &25b8 e5 79 SBC &79 ; result &25ba 85 79 STA &79 ; result ; skip_inverting_result &25bc a5 78 LDA &78 ; result_fraction &25be 8d 05 26 STA &2605 ; shallow_line_slope_fraction &25c1 8d 08 03 STA &0308 ; slope_for_x_clipping_fraction &25c4 a5 79 LDA &79 ; result &25c6 8d 18 26 STA &2618 ; shallow_line_slope &25c9 8d 09 03 STA &0309 ; slope_for_x_clipping &25cc 20 a5 27 JSR &27a5 ; consider_clipping_line_start_x &25cf 20 12 28 JSR &2812 ; consider_clipping_line_start_y_shallow &25d2 20 c3 28 JSR &28c3 ; check_if_line_start_is_onscreen # Returns positive if line start is onscreen &25d5 10 03 BPL &25da ; check_start_x &25d7 4c 38 27 JMP &2738 ; leave_after_restoring_registers ; check_start_x &25da a5 62 LDA &62 ; line_start_x &25dc 30 04 BMI &25e2 ; is_offscreen_in_x &25de a5 63 LDA &63 ; line_start_x_high &25e0 f0 03 BEQ &25e5 ; check_start_y ; is_offscreen_in_x &25e2 4c 38 27 JMP &2738 ; leave_after_restoring_registers ; check_start_y &25e5 a5 64 LDA &64 ; line_start_y &25e7 cd d0 23 CMP &23d0 ; maximum_row &25ea b0 04 BCS &25f0 ; is_offscreen_in_y &25ec a5 65 LDA &65 ; line_start_y_high &25ee f0 03 BEQ &25f3 ; plot_shallow_line_loop ; is_offscreen_in_y &25f0 4c 38 27 JMP &2738 ; leave_after_restoring_registers ; plot_shallow_line_loop &25f3 b9 40 4a LDA &4a40,Y ; buffer_row_addresses_low_table # Calculate screen address for pixel &25f6 18 CLC &25f7 7d 00 4d ADC &4d00,X ; column_addresses_low_table &25fa 85 5e STA &5e ; screen_address_low &25fc b9 00 4b LDA &4b00,Y ; buffer_one_row_addresses_high_table # actually LDA shallow_buffer_row_addresses_high_table &25ff 85 5f STA &5f ; screen_address_high &2601 a5 4c LDA &4c ; row_fraction &2603 18 CLC &2604 69 ff ADC #&ff # Move along shallow line vertically # actually ADC shallow_line_slope_fraction &2606 85 4c STA &4c ; row_fraction # Carry from addition is used at &2617 &2608 84 6b STY &6b ; row &260a a0 00 LDY #&00 &260c bd 80 4d LDA &4d80,X ; column_pixel_masks_table &260f 29 ff AND #&ff # actually AND shallow_line_colour ; plot_shallow_line_opcode &2611 11 5e ORA (&5e),Y ; screen_address # Plot pixel in shallow line # or EOR (&5e),Y ; screen_address if exploding death star &2613 91 5e STA (&5e),Y ; screen_address &2615 a5 6b LDA &6b ; row &2617 69 00 ADC #&00 # actually ADC shallow_line_slope &2619 c9 9f CMP #&9f # actually CMP shallow_maximum_row &261b b0 08 BCS &2625 ; to_leave_after_restoring_registers &261d a8 TAY ; row ; move_along_shallow_line_horizontally_opcode &261e e8 INX if end x > start x # Move along shallow line horizontally # or DEX if start x > end x &261f 30 04 BMI &2625 ; to_leave_after_restoring_registers &2621 e0 ff CPX #&ff # Stop at end of line # actually CPX shallow_line_maximum_x &2623 d0 ce BNE &25f3 ; plot_shallow_line_loop ; to_leave_after_restoring_registers &2625 4c 38 27 JMP &2738 ; leave_after_restoring_registers ; plot_steep_line # Called with X = line start x, Y = line start y &2628 a5 0a LDA &0a ; line_delta_x &262a 85 2c STA &2c ; delta_one &262c a5 0b LDA &0b ; line_delta_x_high &262e 85 2d STA &2d ; delta_one_high &2630 a5 0c LDA &0c ; line_delta_y &2632 85 2e STA &2e ; delta_two &2634 a5 0d LDA &0d ; line_delta_y_high &2636 85 2f STA &2f ; delta_two_high &2638 20 08 36 JSR &3608 ; calculate_line_slope # result = delta_x / delta_y &263b a5 10 LDA &10 ; negative_x # Negative if delta x is negative &263d 10 0d BPL &264c ; skip_inverting_result &263f a9 00 LDA #&00 # If so, make line slope negative &2641 38 SEC &2642 e5 78 SBC &78 ; result_fraction &2644 85 78 STA &78 ; result_fraction &2646 a9 00 LDA #&00 &2648 e5 79 SBC &79 ; result &264a 85 79 STA &79 ; result ; skip_inverting_result &264c a5 78 LDA &78 ; result_fraction &264e 8d a8 26 STA &26a8 ; steep_line_slope_fraction &2651 8d 06 03 STA &0306 ; slope_for_y_clipping_fraction &2654 a5 79 LDA &79 ; result &2656 8d ad 26 STA &26ad ; steep_line_slope &2659 8d 07 03 STA &0307 ; slope_for_y_clipping &265c 20 51 28 JSR &2851 ; consider_clipping_line_start_y &265f 20 69 27 JSR &2769 ; consider_clipping_line_start_x_steep &2662 20 c3 28 JSR &28c3 ; check_if_line_start_is_onscreen # Returns positive if line start is onscreen &2665 10 03 BPL &266a ; check_start_x &2667 4c 38 27 JMP &2738 ; leave_after_restoring_registers ; check_start_x &266a a5 62 LDA &62 ; line_start_x &266c 30 04 BMI &2672 ; is_offscreen_in_x &266e a5 63 LDA &63 ; line_start_x_high &2670 f0 03 BEQ &2675 ; check_start_y ; is_offscreen_in_x &2672 4c 38 27 JMP &2738 ; leave_after_restoring_registers ; check_start_y &2675 a5 64 LDA &64 ; line_start_y &2677 cd d0 23 CMP &23d0 ; maximum_row &267a b0 04 BCS &2680 ; is_offscreen_in_y &267c a5 65 LDA &65 ; line_start_y_high &267e f0 03 BEQ &2683 ; plot_steep_line_loop ; is_offscreen_in_y &2680 4c 38 27 JMP &2738 ; leave_after_restoring_registers ; plot_steep_line_loop &2683 b9 40 4a LDA &4a40,Y ; buffer_row_addresses_low_table # Calculate screen address for pixel &2686 18 CLC &2687 7d 00 4d ADC &4d00,X ; column_addresses_low_table &268a 8d 9f 26 STA &269f ; steep_line_screen_address_one_low &268d 8d a2 26 STA &26a2 ; steep_line_screen_address_two_low &2690 b9 00 4b LDA &4b00,Y ; buffer_one_row_addresses_high_table # actually LDA steep_buffer_row_addresses_high_table,Y &2693 8d a0 26 STA &26a0 ; steep_line_screen_address_one_high &2696 8d a3 26 STA &26a3 ; steep_line_screen_address_two_high &2699 bd 80 4d LDA &4d80,X ; column_pixel_masks_table &269c 29 ff AND #&ff # actually AND steep_line_colour ; plot_steep_line_opcode &269e 0d ff ff ORA &ffff # Plot pixel in steep line # actually ORA steep_line_screen_address_one # or EOR steep_line_screen_address_one if exploding death star &26a1 8d ff ff STA &ffff # actually STA steep_line_screen_address_two &26a4 a5 4c LDA &4c ; column_fraction &26a6 18 CLC &26a7 69 ff ADC #&ff &26a9 85 4c STA &4c ; column_fraction &26ab 8a TXA &26ac 69 00 ADC #&00 # Move along steep line horizontally # actually ADC steep_line_slope &26ae 30 0a BMI &26ba ; to_leave_after_restoring_registers &26b0 aa TAX ; move_along_steep_line_vertically_opcode &26b1 c8 INY if end y > start y # Move along steep line vertically # or DEY if start y > end y &26b2 c0 9f CPY #&9f # Stop at end of line # actually CPY steep_maximum_row &26b4 b0 04 BCS &26ba ; to_leave_after_restoring_registers &26b6 c0 7f CPY #&7f # Stop at top of screen # actually CPY steep_line_maximum_y &26b8 d0 c9 BNE &2683 ; plot_steep_line_loop ; to_leave_after_restoring_registers &26ba 4c 38 27 JMP &2738 ; leave_after_restoring_registers ; plot_diagonal_line # Called with X = line start x, Y = line start y &26bd a9 00 LDA #&00 &26bf 8d 06 03 STA &0306 ; slope_for_y_clipping_fraction &26c2 8d 08 03 STA &0308 ; slope_for_x_clipping_fraction &26c5 a5 10 LDA &10 ; negative_x # Negative if delta x is negative &26c7 10 07 BPL &26d0 ; is_positive_delta_y ; is_negative_delta_x &26c9 a9 ff LDA #&ff # If so, use negative slope for y clipping &26cb 8d 07 03 STA &0307 ; slope_for_y_clipping &26ce 30 05 BMI &26d5 ; consider_delta_y # Always branches ; is_positive_delta_x &26d0 a9 01 LDA #&01 # Otherwise, use positive slope for y clipping &26d2 8d 07 03 STA &0307 ; slope_for_y_clipping ; consider_delta_y &26d5 a5 11 LDA &11 ; negative_y # Negative if delta y is negative &26d7 10 07 BPL &26e0 ; is_positive_delta_y ; is_negative_delta_y &26d9 a9 ff LDA #&ff # If so, use negative slope for x clipping &26db 8d 09 03 STA &0309 ; slope_for_x_clipping &26de 30 05 BMI &26e5 ; consider_clipping_diagonal_line # Always branches ; is_positive_delta_y &26e0 a9 01 LDA #&01 # Otherwise, use positive slope for x clipping &26e2 8d 09 03 STA &0309 ; slope_for_x_clipping ; consider_clipping_diagonal_line &26e5 20 a5 27 JSR &27a5 ; consider_clipping_line_start_x &26e8 20 51 28 JSR &2851 ; consider_clipping_line_start_y &26eb 20 c3 28 JSR &28c3 ; check_if_line_start_is_onscreen # Returns positive if line start is onscreen &26ee 30 48 BMI &2738 ; leave_after_restoring_registers ; check_start_x &26f0 a5 62 LDA &62 ; line_start_x &26f2 30 04 BMI &26f8 ; is_offscreen_in_x &26f4 a5 63 LDA &63 ; line_start_x_high &26f6 f0 03 BEQ &26fb ; check_start_y ; is_offscreen_in_x &26f8 4c 38 27 JMP &2738 ; leave_after_restoring_registers ; check_start_y &26fb a5 64 LDA &64 ; line_start_y &26fd cd d0 23 CMP &23d0 ; maximum_row &2700 b0 04 BCS &2706 ; is_offscreen_in_y &2702 a5 65 LDA &65 ; line_start_y_high &2704 f0 03 BEQ &2709 ; plot_diagonal_line_loop ; is_offscreen_in_y &2706 4c 38 27 JMP &2738 ; leave_after_restoring_registers ; plot_diagonal_line_loop &2709 b9 40 4a LDA &4a40,Y ; buffer_row_addresses_low_table # Calculate screen address for pixel &270c 18 CLC &270d 7d 00 4d ADC &4d00,X ; column_addresses_low_table &2710 8d 25 27 STA &2725 ; diagonal_line_screen_address_one_low &2713 8d 28 27 STA &2728 ; diagonal_line_screen_address_two_low &2716 b9 00 4b LDA &4b00,Y ; buffer_one_row_addresses_high_table # actually LDA diagonal_buffer_row_addresses_high_table,Y &2719 8d 26 27 STA &2726 ; diagonal_line_screen_address_one_high &271c 8d 29 27 STA &2729 ; diagonal_line_screen_address_two_high &271f bd 80 4d LDA &4d80,X ; column_pixel_masks_table &2722 29 ff AND #&ff # actually AND diagonal_line_colour ; plot_diagonal_line_opcode &2724 0d ff ff ORA &ffff # Plot pixel in diagonal line # actually ORA diagonal_line_screen_address_one # or EOR diagonal_line_screen_address_one if exploding death star &2727 8d ff ff STA &ffff # actually STA diagonal_line_screen_address_two ; move_along_diagonal_line_horizontally_opcode &272a e8 INX if end x > start x # Move along diagonal line horizontally # or DEX if start x > end x &272b f0 0b BEQ &2738 ; leave_after_restoring_registers # Stop at horizontal end of screen &272d 30 09 BMI &2738 ; leave_after_restoring_registers ; move_along_diagonal_line_vertically_opcode &272f c8 INY if end y > start y # Move along diagonal line vertically # or DEY if start y > end y &2730 c0 9f CPY #&9f # Stop at vertical end of line # actually CPY diagonal_maximum_row &2732 b0 04 BCS &2738 ; leave_after_restoring_registers &2734 e0 ff CPX #&ff # Stop at horizontal end of line # actually CPX diagonal_line_maximum_x &2736 d0 d1 BNE &2709 ; plot_diagonal_line_loop ; leave_after_restoring_registers &2738 68 PLA ; tmp_y &2739 a8 TAY &273a 68 PLA ; tmp_x &273b aa TAX &273c a5 0f LDA &0f ; line_was_reversed # Negative if line was reversed &273e 30 28 BMI &2768 ; skip_swapping_line_start_and_end ; swap_line_start_and_end &2740 a5 62 LDA &62 ; line_start_x # If so, swap start and end back again &2742 48 PHA ; line_start_x &2743 a5 66 LDA &66 ; line_end_x &2745 85 62 STA &62 ; line_start_x &2747 68 PLA ; line_start_x &2748 85 66 STA &66 ; line_end_x &274a a5 64 LDA &64 ; line_start_y &274c 48 PHA ; line_start_y &274d a5 68 LDA &68 ; line_end_y &274f 85 64 STA &64 ; line_start_y &2751 68 PLA ; line_start_y &2752 85 68 STA &68 ; line_end_y &2754 a5 63 LDA &63 ; line_start_x_high &2756 48 PHA ; line_start_x_high &2757 a5 67 LDA &67 ; line_end_x_high &2759 85 63 STA &63 ; line_start_x_high &275b 68 PLA ; line_start_x_high &275c 85 67 STA &67 ; line_end_x_high &275e a5 65 LDA &65 ; line_start_y_high &2760 48 PHA ; line_start_y_high &2761 a5 69 LDA &69 ; line_end_y_high &2763 85 65 STA &65 ; line_start_y_high &2765 68 PLA ; line_start_y_high &2766 85 69 STA &69 ; line_end_y_high ; skip_swapping_line_start_and_end &2768 60 RTS ; consider_clipping_line_start_x_steep # Called for steep lines &2769 a5 63 LDA &63 ; line_start_x_high &276b d0 06 BNE &2773 ; start_is_offscreen_horizontally &276d a5 62 LDA &62 ; line_start_x &276f 30 02 BMI &2773 ; start_is_offscreen_horizontally &2771 90 32 BCC &27a5 ; consider_clipping_line_start_x # Bug: should always branch, but this depends on whether ; start_is_offscreen_horizontally # carry is left clear by consider_clipping_line_start_y &2773 a5 0c LDA &0c ; line_delta_y &2775 85 2c STA &2c ; delta_one &2777 a5 0d LDA &0d ; line_delta_y_high &2779 85 2d STA &2d ; delta_one_high &277b a5 0a LDA &0a ; line_delta_x &277d 85 2e STA &2e ; delta_two &277f a5 0b LDA &0b ; line_delta_x_high &2781 85 2f STA &2f ; delta_two_high &2783 20 08 36 JSR &3608 ; calculate_line_slope # result = delta_y / delta_x &2786 a5 78 LDA &78 ; result_fraction &2788 8d 08 03 STA &0308 ; slope_for_x_clipping_fraction &278b a5 79 LDA &79 ; result &278d 8d 09 03 STA &0309 ; slope_for_x_clipping &2790 a5 11 LDA &11 ; negative_y # Negative if delta y is negative &2792 10 11 BPL &27a5 ; skip_inverting_slope_for_x_clipping &2794 a9 00 LDA #&00 &2796 38 SEC &2797 ed 08 03 SBC &0308 ; slope_for_x_clipping_fraction # If so, make slope_for_x_clipping negative &279a 8d 08 03 STA &0308 ; slope_for_x_clipping_fraction &279d a9 00 LDA #&00 &279f ed 09 03 SBC &0309 ; slope_for_x_clipping &27a2 8d 09 03 STA &0309 ; slope_for_x_clipping ; skip_inverting_slope_for_x_clipping ; consider_clipping_line_start_x # Called for shallow or diagonal lines &27a5 a5 63 LDA &63 ; line_start_x_high &27a7 30 09 BMI &27b2 ; start_is_offscreen_to_right &27a9 f0 02 BEQ &27ad ; check_start_x_low &27ab 10 34 BPL &27e1 ; start_is_offscreen_to_left ; check_start_x_low &27ad a5 62 LDA &62 ; line_start_x &27af 30 30 BMI &27e1 ; start_is_offscreen_to_left &27b1 60 RTS ; start_is_offscreen_to_right &27b2 a9 00 LDA #&00 &27b4 38 SEC &27b5 e5 62 SBC &62 ; line_start_x &27b7 85 70 STA &70 ; distance &27b9 a9 00 LDA #&00 &27bb e5 63 SBC &63 ; line_start_x_high &27bd 85 71 STA &71 ; distance_high &27bf ad 08 03 LDA &0308 ; slope_for_x_clipping_fraction &27c2 85 72 STA &72 ; slope &27c4 ad 09 03 LDA &0309 ; slope_for_x_clipping &27c7 85 73 STA &73 ; slope_high &27c9 20 28 35 JSR &3528 ; calculate_distance_times_slope # Returns result = distance * slope &27cc a5 64 LDA &64 ; line_start_y &27ce 18 CLC &27cf 65 79 ADC &79 ; result &27d1 85 64 STA &64 ; line_start_y &27d3 a8 TAY &27d4 a5 65 LDA &65 ; line_start_y_high &27d6 65 7a ADC &7a ; result_high &27d8 85 65 STA &65 ; line_start_y_high &27da a2 00 LDX #&00 # Clipped line starts at left of screen &27dc 86 62 STX &62 ; line_start_x &27de 86 63 STX &63 ; line_start_x_high &27e0 60 RTS ; start_is_offscreen_to_left &27e1 a5 62 LDA &62 ; line_start_x &27e3 38 SEC &27e4 e9 80 SBC #&80 &27e6 85 70 STA &70 ; distance &27e8 a5 63 LDA &63 ; line_start_x_high &27ea e9 00 SBC #&00 &27ec 85 71 STA &71 ; distance_high &27ee ad 08 03 LDA &0308 ; slope_for_x_clipping_fraction &27f1 85 72 STA &72 ; slope &27f3 ad 09 03 LDA &0309 ; slope_for_x_clipping &27f6 85 73 STA &73 ; slope_high &27f8 20 28 35 JSR &3528 ; calculate_distance_times_slope # Returns result = distance * slope &27fb a5 64 LDA &64 ; line_start_y &27fd 18 CLC &27fe 65 79 ADC &79 ; result &2800 85 64 STA &64 ; line_start_y &2802 a8 TAY &2803 a5 65 LDA &65 ; line_start_y_high &2805 65 7a ADC &7a ; result_high &2807 85 65 STA &65 ; line_start_y_high &2809 a2 7f LDX #&7f # Clipped line starts at right of screen &280b 86 62 STX &62 ; line_start_x &280d a9 00 LDA #&00 &280f 85 63 STA &63 ; line_start_x_high &2811 60 RTS ; consider_clipping_line_start_y_shallow # Called for shallow lines &2812 a5 65 LDA &65 ; line_start_y_high &2814 d0 09 BNE &281f ; start_is_offscreen_vertically &2816 a5 64 LDA &64 ; line_start_y &2818 cd d0 23 CMP &23d0 ; maximum_row &281b b0 02 BCS &281f ; start_is_offscreen_vertically &281d 90 32 BCC &2851 ; consider_clipping_line_start_y # Always branches ; start_is_offscreen_vertically &281f a5 0a LDA &0a ; line_delta_x &2821 85 2c STA &2c ; delta_one &2823 a5 0b LDA &0b ; line_delta_x_high &2825 85 2d STA &2d ; delta_one_high &2827 a5 0c LDA &0c ; line_delta_y &2829 85 2e STA &2e ; delta_two &282b a5 0d LDA &0d ; line_delta_y_high &282d 85 2f STA &2f ; delta_two_high &282f 20 08 36 JSR &3608 ; calculate_line_slope # result = delta_x / delta_y &2832 a5 78 LDA &78 ; result_fraction &2834 8d 06 03 STA &0306 ; slope_for_y_clipping_fraction &2837 a5 79 LDA &79 ; result &2839 8d 07 03 STA &0307 ; slope_for_y_clipping &283c a5 10 LDA &10 ; negative_x # Negative if delta x is negative &283e 10 11 BPL &2851 ; consider_clipping_line_start_y &2840 a9 00 LDA #&00 &2842 38 SEC &2843 ed 06 03 SBC &0306 ; slope_for_y_clipping_fraction # If so, make horizontal delta negative &2846 8d 06 03 STA &0306 ; slope_for_y_clipping_fraction &2849 a9 00 LDA #&00 &284b ed 07 03 SBC &0307 ; slope_for_y_clipping &284e 8d 07 03 STA &0307 ; slope_for_y_clipping ; consider_clipping_line_start_y # Called for steep or diagonal lines &2851 a5 65 LDA &65 ; line_start_y_high &2853 30 0c BMI &2861 ; start_is_offscreen_to_bottom &2855 f0 02 BEQ &2859 ; check_start_y_low &2857 10 37 BPL &2890 ; start_is_offscreen_to_top ; check_start_y_low &2859 a5 64 LDA &64 ; line_start_y &285b cd d0 23 CMP &23d0 ; maximum_row &285e b0 30 BCS &2890 ; start_is_offscreen_to_top &2860 60 RTS ; start_is_offscreen_to_bottom &2861 a9 00 LDA #&00 &2863 38 SEC &2864 e5 64 SBC &64 ; line_start_y &2866 85 70 STA &70 ; distance &2868 a9 00 LDA #&00 &286a e5 65 SBC &65 ; line_start_y_high &286c 85 71 STA &71 ; distance_high &286e ad 06 03 LDA &0306 ; slope_for_y_clipping_fraction &2871 85 72 STA &72 ; slope &2873 ad 07 03 LDA &0307 ; slope_for_y_clipping &2876 85 73 STA &73 ; slope_high &2878 20 28 35 JSR &3528 ; calculate_distance_times_slope # Returns result = distance * slope &287b a5 62 LDA &62 ; line_start_x &287d 18 CLC &287e 65 79 ADC &79 ; result &2880 85 62 STA &62 ; line_start_x &2882 aa TAX &2883 a5 63 LDA &63 ; line_start_x_high &2885 65 7a ADC &7a ; result_high &2887 85 63 STA &63 ; line_start_x_high &2889 a0 00 LDY #&00 # Clipped line starts at bottom of screen &288b 84 64 STY &64 ; line_start_y &288d 84 65 STY &65 ; line_start_y_high &288f 60 RTS ; start_is_offscreen_to_top &2890 a5 64 LDA &64 ; line_start_y &2892 38 SEC &2893 ed d0 23 SBC &23d0 ; maximum_row &2896 85 70 STA &70 ; distance &2898 a5 65 LDA &65 ; line_start_y_high &289a e9 00 SBC #&00 &289c 85 71 STA &71 ; distance_high &289e ad 06 03 LDA &0306 ; slope_for_y_clipping_fraction &28a1 85 72 STA &72 ; slope &28a3 ad 07 03 LDA &0307 ; slope_for_y_clipping &28a6 85 73 STA &73 ; slope_high &28a8 20 28 35 JSR &3528 ; calculate_distance_times_slope # Returns result = distance * slope &28ab a5 62 LDA &62 ; line_start_x &28ad 18 CLC &28ae 65 79 ADC &79 ; result &28b0 85 62 STA &62 ; line_start_x &28b2 aa TAX &28b3 a5 63 LDA &63 ; line_start_x_high &28b5 65 7a ADC &7a ; result_high &28b7 85 63 STA &63 ; line_start_x_high &28b9 ac d0 23 LDY &23d0 ; maximum_row # Clipped line starts at top of screen &28bc 84 64 STY &64 ; line_start_y &28be a9 00 LDA #&00 &28c0 85 65 STA &65 ; line_start_y_high &28c2 60 RTS ; check_if_line_start_is_onscreen &28c3 a5 0f LDA &0f ; line_was_reversed # Negative if line was reversed &28c5 30 45 BMI &290c ; leave_with_zero # If so, leave with positive to indicate start onscreen &28c7 a5 4e LDA &4e ; line_start_offscreen_flags &28c9 c9 01 CMP #&01 ; OFFSCREEN_X_MINUS &28cb d0 09 BNE &28d6 ; not_offscreen_x_minus &28cd a5 62 LDA &62 ; line_start_x &28cf 05 63 ORA &63 ; line_start_x_high &28d1 f0 16 BEQ &28e9 ; not_offscreen_x_minus ; is_offscreen_x_minus &28d3 a9 ff LDA #&ff # Leave with negative to indicate start offscreen &28d5 60 RTS ; not_offscreen_x_minus &28d6 a5 4e LDA &4e ; line_start_offscreen_flags &28d8 c9 02 CMP #&02 ; OFFSCREEN_X_PLUS &28da d0 0d BNE &28e9 ; not_offscreen_x_plus &28dc a5 63 LDA &63 ; line_start_x_high &28de d0 06 BNE &28e6 ; is_offscreen_x_plus &28e0 a5 62 LDA &62 ; line_start_x &28e2 c9 7f CMP #&7f &28e4 f0 03 BEQ &28e9 ; not_offscreen_x_plus ; is_offscreen_x_plus &28e6 a9 ff LDA #&ff # Leave with negative to indicate start offscreen &28e8 60 RTS ; not_offscreen_x_plus &28e9 a5 4e LDA &4e ; line_start_offscreen_flags &28eb c9 04 CMP #&04 ; OFFSCREEN_Y_MINUS &28ed d0 09 BNE &28f8 ; not_offscreen_y_minus &28ef a5 64 LDA &64 ; line_start_y &28f1 05 65 ORA &65 ; line_start_y_high &28f3 f0 17 BEQ &290c ; leave_with_zero ; is_offscreen_y_minus &28f5 a9 ff LDA #&ff # Leave with negative to indicate start offscreen &28f7 60 RTS ; not_offscreen_y_minus &28f8 a5 4e LDA &4e ; line_start_offscreen_flags &28fa c9 08 CMP #&08 ; OFFSCREEN_Y_PLUS &28fc d0 0e BNE &290c ; leave_with_zero &28fe a5 65 LDA &65 ; line_start_y_high &2900 d0 07 BNE &2909 ; is_offscreen_y_plus &2902 a5 64 LDA &64 ; line_start_y &2904 cd d0 23 CMP &23d0 ; maximum_row &2907 f0 03 BEQ &290c ; leave_with_zero ; is_offscreen_y_plus &2909 a9 ff LDA #&ff # Leave with negative to indicate start offscreen &290b 60 RTS ; leave_with_zero &290c a9 00 LDA #&00 # Leave with positive to indicate start of line onscreen &290e 60 RTS ; set_line_start_to_line_end &290f a5 66 LDA &66 ; line_end_x &2911 85 62 STA &62 ; line_start_x &2913 a5 67 LDA &67 ; line_end_x_high &2915 85 63 STA &63 ; line_start_x_high &2917 a5 68 LDA &68 ; line_end_y &2919 85 64 STA &64 ; line_start_y &291b a5 69 LDA &69 ; line_end_y_high &291d 85 65 STA &65 ; line_start_y_high &291f 60 RTS ; plot_pixel_without_maximum_row_check # Unused code &2920 18 CLC &2921 90 08 BCC &292b ; plot_pixel_with_carry_clear # Always branches ; plot_pixel # Called with X = x, Y = y &2923 8a TXA &2924 30 25 BMI &294b ; leave &2926 cc d0 23 CPY &23d0 ; maximum_row &2929 b0 20 BCS &294b ; leave ; plot_pixel_with_carry_clear &292b b9 40 4a LDA &4a40,Y ; buffer_row_addresses_low_table # Calculate screen address for pixel &292e 7d 00 4d ADC &4d00,X ; column_addresses_low_table &2931 8d 46 29 STA &2946 ; pixel_screen_address_one_low &2934 8d 49 29 STA &2949 ; pixel_screen_address_two_low &2937 b9 00 4b LDA &4b00,Y ; buffer_one_row_addresses_high_table # actually LDA pixel_buffer_row_addresses_high_table,Y &293a 8d 47 29 STA &2947 ; pixel_screen_address_one_high &293d 8d 4a 29 STA &294a ; pixel_screen_address_two_high &2940 bd 80 4d LDA &4d80,X ; column_pixel_masks_table &2943 29 ff AND #&ff # actually AND pixel_colour &2945 0d ff ff ORA &ffff # Plot pixel # actually ORA pixel_screen_address_one &2948 8d ff ff STA &ffff # actually STA pixel_screen_address_two ; leave &294b 60 RTS ; to_set_line_start_to_line_end &294c 4c 0f 29 JMP &290f ; set_line_start_to_line_end ; plot_vertical_line &294f a5 63 LDA &63 ; line_start_x_high &2951 d0 f9 BNE &294c ; to_set_line_start_to_line_end # Nothing to plot if start of line is offscreen &2953 a5 62 LDA &62 ; line_start_x &2955 30 f5 BMI &294c ; to_set_line_start_to_line_end &2957 86 6a STX &6a ; tmp_x &2959 84 6b STY &6b ; tmp_y &295b a6 62 LDX &62 ; line_start_x &295d a5 64 LDA &64 ; line_start_y &295f 85 6d STA &6d ; start_row &2961 a5 68 LDA &68 ; line_end_y &2963 85 6f STA &6f ; end_row ; consider_clipping_end &2965 a5 69 LDA &69 ; line_end_y_high &2967 10 06 BPL &296f ; not_end_offscreen_y_minus # If end of line is below bottom of screen, &2969 a9 00 LDA #&00 &296b 85 6f STA &6f ; end_row # Clip end of line to bottom of screen &296d f0 12 BEQ &2981 ; consider_clipping_start # Always branches ; not_end_offscreen_y_minus &296f f0 06 BEQ &2977 ; check_end_y_low # If end of line is above top of screen, &2971 a9 9f LDA #&9f &2973 85 6f STA &6f ; end_row # Clip end of line to top of screen &2975 d0 0a BNE &2981 ; consider_clipping_start # Always branches ; check_end_y_low &2977 a5 68 LDA &68 ; line_end_y &2979 c9 a0 CMP #&a0 &297b 90 04 BCC &2981 ; consider_clipping_start # If end of line is above top of screen, &297d a9 9f LDA #&9f &297f 85 6f STA &6f ; end_row # Clip end of line to top of screen ; consider_clipping_start &2981 a5 65 LDA &65 ; line_start_y_high &2983 10 06 BPL &298b ; not_start_offscreen_y_minus # If start of line is below bottom of screen, &2985 a9 00 LDA #&00 &2987 85 6d STA &6d ; start_row # Clip start of line to bottom of screen &2989 f0 12 BEQ &299d ; consider_swapping_start_and_end # Always branches ; not_start_offscreen_y_minus &298b f0 06 BEQ &2993 ; check_start_y_low # If start of line is above top of screen, &298d a9 9f LDA #&9f &298f 85 6d STA &6d ; start_row # Clip start of line to top of screen &2991 d0 0a BNE &299d ; consider_swapping_start_and_end # Always branches ; check_start_y_low &2993 a5 64 LDA &64 ; line_start_y &2995 c9 a0 CMP #&a0 &2997 90 04 BCC &299d ; consider_swapping_start_and_end # If start of line is above top of screen, &2999 a9 9f LDA #&9f &299b 85 6d STA &6d ; start_row # Clip start of line to top of screen ; consider_swapping_start_and_end &299d a5 6d LDA &6d ; start_row &299f c5 6f CMP &6f ; end_row &29a1 b0 0a BCS &29ad ; skip_swapping_start_and_end # If start > end &29a3 a5 6d LDA &6d ; start_row &29a5 48 PHA ; start_row &29a6 a5 6f LDA &6f ; end_row # swap start and end &29a8 85 6d STA &6d ; start_row &29aa 68 PLA ; start_row &29ab 85 6f STA &6f ; end_row ; skip_swapping_start_and_end &29ad a5 6d LDA &6d ; start_row # If start = end, &29af c5 6f CMP &6f ; end_row &29b1 d0 0c BNE &29bf ; not_pixel ; is_pixel &29b3 a4 6d LDY &6d ; start_row &29b5 f0 03 BEQ &29ba ; skip_plotting_pixel # and not clipped to bottom of screen, &29b7 20 23 29 JSR &2923 ; plot_pixel # plot pixel ; skip_plotting_pixel &29ba a6 6a LDX &6a ; tmp_x &29bc a4 6b LDY &6b ; tmp_y &29be 60 RTS ; not_pixel &29bf bd 80 4d LDA &4d80,X ; column_pixel_masks_table &29c2 29 ff AND #&ff # actually AND vertical_line_colour &29c4 85 60 STA &60 ; vertical_line_pixel_value &29c6 a5 6d LDA &6d ; start_row &29c8 29 f8 AND #&f8 &29ca a8 TAY &29cb a5 6f LDA &6f ; end_row &29cd 29 f8 AND #&f8 &29cf 18 CLC &29d0 69 08 ADC #&08 &29d2 85 5f STA &5f ; end_group &29d4 b9 40 4a LDA &4a40,Y ; buffer_row_addresses_low_table # Calculate screen address for start of line &29d7 18 CLC &29d8 7d 00 4d ADC &4d00,X ; column_addresses_low_table &29db 29 f8 AND #&f8 &29dd 8d 0c 2a STA &2a0c ; vertical_line_screen_address_one_low &29e0 8d 0f 2a STA &2a0f ; vertical_line_screen_address_two_low &29e3 8d 21 2a STA &2a21 ; vertical_line_screen_address_three_low &29e6 8d 24 2a STA &2a24 ; vertical_line_screen_address_four_low &29e9 b9 00 4b LDA &4b00,Y ; buffer_one_row_addresses_high_table # actually LDA vertical_buffer_row_addresses_high_table,Y &29ec 8d 0d 2a STA &2a0d ; vertical_line_screen_address_one_high &29ef 8d 10 2a STA &2a10 ; vertical_line_screen_address_two_high &29f2 18 CLC &29f3 69 01 ADC #&01 # Move down a group &29f5 8d 22 2a STA &2a22 ; vertical_line_screen_address_three_high &29f8 8d 25 2a STA &2a25 ; vertical_line_screen_address_four_high &29fb a5 6d LDA &6d ; start_row &29fd 29 07 AND #&07 &29ff f0 15 BEQ &2a16 ; skip_top &2a01 85 6c STA &6c ; start_row_in_group &2a03 a9 07 LDA #&07 &2a05 38 SEC &2a06 e5 6c SBC &6c ; start_row_in_group &2a08 aa TAX ; plot_vertical_line_top_loop &2a09 a5 60 LDA &60 ; vertical_line_pixel_value &2a0b 1d ff ff ORA &ffff,X # Plot pixel in partial top group of vertical line # actually ORA vertical_line_screen_address_one,X &2a0e 9d ff ff STA &ffff,X # actually STA vertical_line_screen_address_two,X &2a11 e8 INX &2a12 e0 08 CPX #&08 &2a14 d0 f3 BNE &2a09 ; plot_vertical_line_top_loop ; skip_top &2a16 c4 5f CPY &5f ; end_group &2a18 90 1e BCC &2a38 ; skip_middle &2a1a f0 1c BEQ &2a38 ; skip_middle ; plot_vertical_line_middle_group_loop &2a1c a2 07 LDX #&07 ; plot_vertical_line_middle_byte_loop &2a1e a5 60 LDA &60 ; vertical_line_pixel_value &2a20 1d ff ff ORA &ffff,X # Plot pixel in full groups of vertical line # actually ORA vertical_line_screen_address_three,X &2a23 9d ff ff STA &ffff,X # actually STA vertical_line_screen_address_four,X &2a26 ca DEX &2a27 10 f5 BPL &2a1e ; plot_vertical_line_middle_byte_loop &2a29 ee 22 2a INC &2a22 ; vertical_line_screen_address_three_high # Move down a group &2a2c ee 25 2a INC &2a25 ; vertical_line_screen_address_four_high # Move down a group &2a2f 98 TYA &2a30 38 SEC &2a31 e9 08 SBC #&08 &2a33 a8 TAY &2a34 c4 5f CPY &5f ; end_group &2a36 d0 e4 BNE &2a1c ; plot_vertical_line_middle_group_loop ; skip_middle &2a38 a5 6f LDA &6f ; end_row &2a3a 29 07 AND #&07 &2a3c 85 5f STA &5f ; end_row_in_group &2a3e ad 21 2a LDA &2a21 ; vertical_line_screen_address_three_low &2a41 8d 5d 2a STA &2a5d ; vertical_line_screen_address_five_low &2a44 8d 60 2a STA &2a60 ; vertical_line_screen_address_six_low &2a47 ad 22 2a LDA &2a22 ; vertical_line_screen_address_three_high &2a4a c9 68 CMP #&68 &2a4c f0 17 BEQ &2a65 ; skip_bottom &2a4e 8d 5e 2a STA &2a5e ; vertical_line_screen_address_five_high &2a51 8d 61 2a STA &2a61 ; vertical_line_screen_address_six_high &2a54 a9 07 LDA #&07 &2a56 38 SEC &2a57 e5 5f SBC &5f ; end_row_in_group &2a59 aa TAX ; plot_vertical_line_bottom_loop &2a5a a5 60 LDA &60 ; vertical_line_pixel_value &2a5c 1d ff ff ORA &ffff,X # Plot pixel in partial bottom group of vertical line # actually ORA vertical_line_screen_address_five,X &2a5f 9d ff ff STA &ffff,X # actually STA vertical_line_screen_address_six,X &2a62 ca DEX &2a63 10 f5 BPL &2a5a ; plot_vertical_line_bottom_loop ; skip_bottom &2a65 a6 6a LDX &6a ; tmp_x &2a67 a4 6b LDY &6b ; tmp_y ; to_set_line_start_to_line_end &2a69 4c 0f 29 JMP &290f ; set_line_start_to_line_end ; plot_horizontal_line &2a6c a5 69 LDA &69 ; line_end_y_high &2a6e d0 f9 BNE &2a69 ; to_set_line_start_to_line_end # Nothing to plot if line is offscreen &2a70 a5 68 LDA &68 ; line_end_y &2a72 cd d0 23 CMP &23d0 ; maximum_row &2a75 b0 f2 BCS &2a69 ; to_set_line_start_to_line_end &2a77 a5 62 LDA &62 ; line_start_x &2a79 c5 66 CMP &66 ; line_end_x &2a7b d0 1a BNE &2a97 ; not_pixel &2a7d a5 63 LDA &63 ; line_start_x_high &2a7f c5 67 CMP &67 ; line_end_x_high &2a81 d0 14 BNE &2a97 ; not_pixel &2a83 a5 63 LDA &63 ; line_start_x_high &2a85 d0 e2 BNE &2a69 ; to_set_line_start_to_line_end # If start = end, ; is_pixel &2a87 86 6a STX &6a ; tmp_x &2a89 84 6b STY &6b ; tmp_y &2a8b a6 62 LDX &62 ; line_start_x &2a8d a4 64 LDY &64 ; line_start_y &2a8f 20 23 29 JSR &2923 ; plot_pixel # plot pixel &2a92 a6 6a LDX &6a ; tmp_x &2a94 a4 6b LDY &6b ; tmp_y &2a96 60 RTS ; not_pixel &2a97 a9 00 LDA #&00 &2a99 85 11 STA &11 ; negative_y &2a9b a5 66 LDA &66 ; line_end_x &2a9d 38 SEC &2a9e e5 62 SBC &62 ; line_start_x &2aa0 a5 67 LDA &67 ; line_end_x_high &2aa2 e5 63 SBC &63 ; line_start_x_high &2aa4 10 05 BPL &2aab ; skip_inversion # If start > end, &2aa6 85 11 STA &11 ; negative_y # Set to negative to indicate line has negative delta x &2aa8 20 40 27 JSR &2740 ; swap_line_start_and_end # swap start and end ; skip_inversion &2aab a5 62 LDA &62 ; line_start_x &2aad 48 PHA ; line_start_x &2aae a5 66 LDA &66 ; line_end_x &2ab0 48 PHA ; line_end_x &2ab1 a5 63 LDA &63 ; line_start_x_high &2ab3 10 0d BPL &2ac2 ; check_low &2ab5 a9 00 LDA #&00 &2ab7 85 62 STA &62 ; line_start_x &2ab9 a5 67 LDA &67 ; line_end_x_high &2abb 10 05 BPL &2ac2 ; check_low &2abd 68 PLA ; line_end_x &2abe 68 PLA ; line_start_x &2abf 4c 0f 29 JMP &290f ; set_line_start_to_line_end # Nothing to plot if line is offscreen ; check_low &2ac2 a5 66 LDA &66 ; line_end_x &2ac4 38 SEC &2ac5 e9 80 SBC #&80 &2ac7 a5 67 LDA &67 ; line_end_x_high &2ac9 e9 00 SBC #&00 &2acb 30 14 BMI &2ae1 ; is_onscreen &2acd a9 7f LDA #&7f &2acf 85 66 STA &66 ; line_end_x &2ad1 a5 62 LDA &62 ; line_start_x &2ad3 38 SEC &2ad4 e9 80 SBC #&80 &2ad6 a5 63 LDA &63 ; line_start_x_high &2ad8 e9 00 SBC #&00 &2ada 30 05 BMI &2ae1 ; is_onscreen &2adc 68 PLA ; line_end_x &2add 68 PLA ; line_start_x &2ade 4c 0f 29 JMP &290f ; set_line_start_to_line_end # Nothing to plot if line is offscreen ; is_onscreen &2ae1 86 6a STX &6a ; tmp_x &2ae3 84 6b STY &6b ; tmp_y &2ae5 a5 62 LDA &62 ; line_start_x &2ae7 29 fc AND #&fc &2ae9 aa TAX &2aea 18 CLC &2aeb 69 04 ADC #&04 &2aed 85 38 STA &38 ; line_start_x_byte &2aef a5 66 LDA &66 ; line_end_x &2af1 29 fc AND #&fc &2af3 85 30 STA &30 ; line_end_x_byte &2af5 38 SEC &2af6 e5 38 SBC &38 ; line_start_x_byte &2af8 4a LSR A &2af9 4a LSR A &2afa 85 38 STA &38 ; line_length_in_bytes &2afc c6 38 DEC &38 ; line_length_in_bytes &2afe a4 68 LDY &68 ; line_end_y &2b00 b9 40 4a LDA &4a40,Y ; buffer_row_addresses_low_table # Calculate screen address for start of line &2b03 18 CLC &2b04 7d 00 4d ADC &4d00,X ; column_addresses_low_table &2b07 85 3a STA &3a ; screen_address_low &2b09 b9 00 4b LDA &4b00,Y ; buffer_one_row_addresses_high_table # actually LDA horizontal_buffer_row_addresses_high_table,Y &2b0c 85 3b STA &3b ; screen_address_high &2b0e a0 00 LDY #&00 &2b10 a5 62 LDA &62 ; line_start_x &2b12 29 03 AND #&03 &2b14 aa TAX &2b15 bd f5 07 LDA &07f5,X ; right_pixels_masks_table &2b18 25 1a AND &1a ; colour_pixel_value &2b1a 11 3a ORA (&3a),Y ; screen_address &2b1c 91 3a STA (&3a),Y ; screen_address # Plot left of horizontal line &2b1e a0 08 LDY #&08 &2b20 a6 38 LDX &38 ; line_length_in_bytes &2b22 e0 42 CPX #&42 &2b24 f0 12 BEQ &2b38 ; skip_plotting_middle &2b26 e0 3e CPX #&3e &2b28 f0 1e BEQ &2b48 ; skip_plotting_right &2b2a 18 CLC ; plot_horizontal_line_loop &2b2b a5 1a LDA &1a ; colour_pixel_value &2b2d 91 3a STA (&3a),Y ; screen_address # Plot middle of horizontal line &2b2f a5 3a LDA &3a ; screen_address_low &2b31 69 08 ADC #&08 &2b33 85 3a STA &3a ; screen_address_low &2b35 ca DEX &2b36 10 f3 BPL &2b2b ; plot_horizontal_line_loop ; skip_plotting_middle &2b38 a5 66 LDA &66 ; line_end_x &2b3a 29 03 AND #&03 &2b3c f0 0a BEQ &2b48 ; skip_plotting_right &2b3e aa TAX &2b3f bd f9 07 LDA &07f9,X ; left_pixels_masks_table &2b42 25 1a AND &1a ; colour_pixel_value &2b44 11 3a ORA (&3a),Y ; screen_address &2b46 91 3a STA (&3a),Y ; screen_address # Plot right of horizontal line ; skip_plotting_right &2b48 a6 6a LDX &6a ; tmp_x &2b4a a4 6b LDY &6b ; tmp_y &2b4c 68 PLA ; line_end_x &2b4d 85 66 STA &66 ; line_end_x &2b4f 68 PLA ; line_start_x &2b50 85 62 STA &62 ; line_start_x &2b52 a5 11 LDA &11 ; negative_y # Negative if line had negative delta x &2b54 30 03 BMI &2b59 ; leave # If so, ends were swapped, and start is already end &2b56 4c 0f 29 JMP &290f ; set_line_start_to_line_end ; leave &2b59 60 RTS ; use_other_buffer_and_wipe &2b5a 20 df 39 JSR &39df ; plot_player &2b5d a9 13 LDA #&13 ; Wait for vertical retrace &2b5f 20 f4 ff JSR &fff4 ; OSBYTE &2b62 ae fe 25 LDX &25fe ; shallow_buffer_row_addresses_high_table_high &2b65 e8 INX # Swap between &4b00 ; buffer_one_row_addresses_high_table &2b66 e0 4d CPX #&4d # and &4c00 ; buffer_two_row_addresses_high_table &2b68 d0 02 BNE &2b6c ; skip_wraparound &2b6a a2 4b LDX #&4b ; &4b00 = buffer_one_row_addresses_high_table ; skip_wraparound &2b6c 8e fe 25 STX &25fe ; shallow_buffer_row_addresses_high_table_high &2b6f 8e 92 26 STX &2692 ; steep_buffer_row_addresses_high_table_high &2b72 8e 18 27 STX &2718 ; diagonal_buffer_row_addresses_high_table_high &2b75 8e 39 29 STX &2939 ; pixel_buffer_row_addresses_high_table_high &2b78 8e eb 29 STX &29eb ; vertical_buffer_row_addresses_high_table_high &2b7b 8e 0b 2b STX &2b0b ; horizontal_buffer_row_addresses_high_table_high &2b7e 8e fc 39 STX &39fc ; player_buffer_row_addresses_high_table_high &2b81 e0 4b CPX #&4b ; &4b00 = buffer_one_row_addresses_high_table &2b83 f0 04 BEQ &2b89 ; display_buffer_two ; display_buffer_one &2b85 a0 0a LDY #&0a # Set screen start address to &5000 (buffer_one) &2b87 d0 02 BNE &2b8b ; display_buffer # Always branches ; display_buffer_two &2b89 a0 0d LDY #&0d # Set screen start address to &6800 (buffer_two) ; display_buffer &2b8b a9 0c LDA #&0c ; R12: Displayed screen start address register (high) &2b8d 8d 00 fe STA &fe00 ; video register number &2b90 8c 01 fe STY &fe01 ; video register value &2b93 ad fe 25 LDA &25fe ; shallow_buffer_row_addresses_high_table_high &2b96 c9 4b CMP #&4b ; &4b00 = buffer_one_row_addresses_high_table &2b98 f0 06 BEQ &2ba0 ; to_wipe_buffer_one ; to_wipe_buffer_two &2b9a 20 90 2c JSR &2c90 ; wipe_buffer_two &2b9d 4c a3 2b JMP &2ba3 ; set_colour_zero_to_black ; to_wipe_buffer_one &2ba0 20 f6 2b JSR &2bf6 ; wipe_buffer_one ; set_colour_zero_to_black &2ba3 a2 00 LDX #&00 ; K &2ba5 4c 8e 2e JMP &2e8e ; set_colour_zero_to_X # Restore background to black ; plot_status &2ba8 a9 00 LDA #&00 &2baa aa TAX ; wipe_status_area_loop &2bab 9d 00 50 STA &5000,X ; buffer_one # Wipe status area, line one &2bae 9d 00 68 STA &6800,X ; buffer_two &2bb1 9d 00 51 STA &5100,X ; buffer_one + &100 * 1 # Wipe status area, line two &2bb4 9d 00 69 STA &6900,X ; buffer_two + &100 * 1 &2bb7 9d 00 52 STA &5200,X ; buffer_one + &100 * 2 # Wipe status area, line three &2bba 9d 00 6a STA &6a00,X ; buffer_two + &100 * 2 &2bbd 9d 00 53 STA &5300,X ; buffer_one + &100 * 3 # Wipe status area, line four &2bc0 9d 00 6b STA &6b00,X ; buffer_two + &100 * 3 &2bc3 e8 INX &2bc4 d0 e5 BNE &2bab ; wipe_status_area_loop &2bc6 20 4c 3e JSR &3e4c ; plot_shields &2bc9 a9 e5 LDA #&e5 ; &2be5 = score_string &2bcb 85 18 STA &18 ; text_address_low &2bcd a9 2b LDA #&2b &2bcf 85 19 STA &19 ; text_address_high &2bd1 20 88 2d JSR &2d88 ; plot_string # Plot "SCORE" &2bd4 a9 ee LDA #&ee ; &2bee = wave_string &2bd6 85 18 STA &18 ; text_address_low &2bd8 a9 2b LDA #&2b &2bda 85 19 STA &19 ; text_address_high &2bdc 20 88 2d JSR &2d88 ; plot_string # Plot "WAVE" &2bdf 20 7e 16 JSR &167e ; plot_score &2be2 4c ca 16 JMP &16ca ; plot_wave ; score_string &2be5 00 00 f0 05 ; at + &0000, colour &f0 (R), length &05 &2be9 53 43 4f 52 45 ; "SCORE" ; wave_string &2bee e0 00 f0 04 ; at + &00e0, colour &f0 (R), length &04 &2bf2 57 41 56 45 ; "WAVE" ; wipe_buffer_one &2bf6 a9 00 LDA #&00 &2bf8 aa TAX ; wipe_buffer_one_loop &2bf9 9d 00 54 STA &5400,X ; buffer_one + &100 * 4 &2bfc 9d 00 55 STA &5500,X ; buffer_one + &100 * 5 &2bff 9d 00 56 STA &5600,X ; buffer_one + &100 * 6 &2c02 9d 00 57 STA &5700,X ; buffer_one + &100 * 7 &2c05 9d 00 58 STA &5800,X ; buffer_one + &100 * 8 &2c08 9d 00 59 STA &5900,X ; buffer_one + &100 * 9 &2c0b 9d 00 5a STA &5a00,X ; buffer_one + &100 * 10 &2c0e 9d 00 5b STA &5b00,X ; buffer_one + &100 * 11 &2c11 9d 00 5c STA &5c00,X ; buffer_one + &100 * 12 &2c14 9d 00 5d STA &5d00,X ; buffer_one + &100 * 13 &2c17 9d 00 5e STA &5e00,X ; buffer_one + &100 * 14 &2c1a 9d 00 5f STA &5f00,X ; buffer_one + &100 * 15 &2c1d 9d 00 60 STA &6000,X ; buffer_one + &100 * 16 &2c20 9d 00 61 STA &6100,X ; buffer_one + &100 * 17 &2c23 9d 00 62 STA &6200,X ; buffer_one + &100 * 18 &2c26 9d 00 63 STA &6300,X ; buffer_one + &100 * 19 &2c29 9d 00 64 STA &6400,X ; buffer_one + &100 * 20 &2c2c 9d 00 65 STA &6500,X ; buffer_one + &100 * 21 &2c2f 9d 00 66 STA &6600,X ; buffer_one + &100 * 22 &2c32 9d 00 67 STA &6700,X ; buffer_one + &100 * 23 &2c35 e8 INX &2c36 d0 c1 BNE &2bf9 ; wipe_buffer_one_loop &2c38 a2 1f LDX #&1f ; plot_player_middle_top_to_buffer_one_loop &2c3a bd ee 43 LDA &43ee,X ; player_middle_top_sprite &2c3d 9d 70 66 STA &6670,X ; buffer_one + &100 * 22 + &70 &2c40 ca DEX &2c41 10 f7 BPL &2c3a ; plot_player_middle_to_buffer_one_loop &2c43 a2 2f LDX #&2f ; plot_player_middle_bottom_to_buffer_one_loop &2c45 bd 0e 44 LDA &440e,X ; player_middle_bottom_sprite &2c48 9d 68 67 STA &6768,X ; buffer_one + &100 * 23 + &68 &2c4b ca DEX &2c4c 10 f7 BPL &2c45 ; plot_player_middle_bottom_to_buffer_one_loop &2c4e a2 0f LDX #&0f ; plot_player_sides_to_buffer_one_loop &2c50 bd 3e 44 LDA &443e,X ; player_left_top_sprite &2c53 9d 00 5d STA &5d00,X ; buffer_one + &100 * 13 &2c56 bd 4e 44 LDA &444e,X ; player_left_top_sprite + &10 &2c59 9d 00 5e STA &5e00,X ; buffer_one + &100 * 14 &2c5c bd 5e 44 LDA &445e,X ; player_left_top_sprite + &20 &2c5f 9d 00 5f STA &5f00,X ; buffer_one + &100 * 15 &2c62 bd 6e 44 LDA &446e,X ; player_left_bottom_sprite &2c65 9d 00 66 STA &6600,X ; buffer_one + &100 * 22 &2c68 bd 7e 44 LDA &447e,X ; player_left_bottom_sprite + &10 &2c6b 9d 00 67 STA &6700,X ; buffer_one + &100 * 23 &2c6e bd 8e 44 LDA &448e,X ; player_right_top_sprite &2c71 9d f0 5d STA &5df0,X ; buffer_one + &100 * 13 + &f0 &2c74 bd 9e 44 LDA &449e,X ; player_right_top_sprite + &10 &2c77 9d f0 5e STA &5ef0,X ; buffer_one + &100 * 14 + &f0 &2c7a bd ae 44 LDA &44ae,X ; player_right_top_sprite + &20 &2c7d 9d f0 5f STA &5ff0,X ; buffer_one + &100 * 15 + &f0 &2c80 bd be 44 LDA &44be,X ; player_right_bottom_sprite &2c83 9d f0 66 STA &66f0,X ; buffer_one + &100 * 22 + &f0 &2c86 bd ce 44 LDA &44ce,X ; player_right_bottom_sprite + &10 &2c89 9d f0 67 STA &67f0,X ; buffer_one + &100 * 23 + &f0 &2c8c ca DEX &2c8d 10 c1 BPL &2c50 ; plot_player_sides_to_buffer_one_loop &2c8f 60 RTS ; wipe_buffer_two &2c90 a9 00 LDA #&00 &2c92 aa TAX ; wipe_buffer_two_loop &2c93 9d 00 6c STA &6c00,X ; buffer_two + &100 * 4 &2c96 9d 00 6d STA &6d00,X ; buffer_two + &100 * 5 &2c99 9d 00 6e STA &6e00,X ; buffer_two + &100 * 6 &2c9c 9d 00 6f STA &6f00,X ; buffer_two + &100 * 7 &2c9f 9d 00 70 STA &7000,X ; buffer_two + &100 * 8 &2ca2 9d 00 71 STA &7100,X ; buffer_two + &100 * 9 &2ca5 9d 00 72 STA &7200,X ; buffer_two + &100 * 10 &2ca8 9d 00 73 STA &7300,X ; buffer_two + &100 * 11 &2cab 9d 00 74 STA &7400,X ; buffer_two + &100 * 12 &2cae 9d 00 75 STA &7500,X ; buffer_two + &100 * 13 &2cb1 9d 00 76 STA &7600,X ; buffer_two + &100 * 14 &2cb4 9d 00 77 STA &7700,X ; buffer_two + &100 * 15 &2cb7 9d 00 78 STA &7800,X ; buffer_two + &100 * 16 &2cba 9d 00 79 STA &7900,X ; buffer_two + &100 * 17 &2cbd 9d 00 7a STA &7a00,X ; buffer_two + &100 * 18 &2cc0 9d 00 7b STA &7b00,X ; buffer_two + &100 * 19 &2cc3 9d 00 7c STA &7c00,X ; buffer_two + &100 * 20 &2cc6 9d 00 7d STA &7d00,X ; buffer_two + &100 * 21 &2cc9 9d 00 7e STA &7e00,X ; buffer_two + &100 * 22 &2ccc 9d 00 7f STA &7f00,X ; buffer_two + &100 * 23 &2ccf e8 INX &2cd0 d0 c1 BNE &2c93 ; wipe_buffer_two_loop &2cd2 a2 1f LDX #&1f ; plot_player_middle_top_to_buffer_two_loop &2cd4 bd ee 43 LDA &43ee,X ; player_middle_top_sprite &2cd7 9d 70 7e STA &7e70,X ; buffer_two + &100 * 22 + &70 &2cda ca DEX &2cdb 10 f7 BPL &2cd4 ; plot_player_middle_to_buffer_two_loop &2cdd a2 2f LDX #&2f ; plot_player_middle_bottom_to_buffer_two_loop &2cdf bd 0e 44 LDA &440e,X ; player_middle_bottom_sprite &2ce2 9d 68 7f STA &7f68,X ; buffer_two + &100 * 23 + &68 &2ce5 ca DEX &2ce6 10 f7 BPL &2cdf ; plot_player_middle_bottom_to_buffer_two_loop &2ce8 a2 0f LDX #&0f ; plot_player_sides_to_buffer_two_loop &2cea bd 3e 44 LDA &443e,X ; player_left_top_sprite &2ced 9d 00 75 STA &7500,X ; buffer_two + &100 * 13 &2cf0 bd 4e 44 LDA &444e,X ; player_left_top_sprite + &10 &2cf3 9d 00 76 STA &7600,X ; buffer_two + &100 * 14 &2cf6 bd 5e 44 LDA &445e,X ; player_left_top_sprite + &20 &2cf9 9d 00 77 STA &7700,X ; buffer_two + &100 * 15 &2cfc bd 6e 44 LDA &446e,X ; player_left_bottom_sprite &2cff 9d 00 7e STA &7e00,X ; buffer_two + &100 * 22 &2d02 bd 7e 44 LDA &447e,X ; player_left_bottom_sprite + &10 &2d05 9d 00 7f STA &7f00,X ; buffer_two + &100 * 23 &2d08 bd 8e 44 LDA &448e,X ; player_right_top_sprite &2d0b 9d f0 75 STA &75f0,X ; buffer_two + &100 * 13 + &f0 &2d0e bd 9e 44 LDA &449e,X ; player_right_top_sprite + &10 &2d11 9d f0 76 STA &76f0,X ; buffer_two + &100 * 14 + &f0 &2d14 bd ae 44 LDA &44ae,X ; player_right_top_sprite + &20 &2d17 9d f0 77 STA &77f0,X ; buffer_two + &100 * 15 + &f0 &2d1a bd be 44 LDA &44be,X ; player_right_bottom_sprite &2d1d 9d f0 7e STA &7ef0,X ; buffer_two + &100 * 22 + &f0 &2d20 bd ce 44 LDA &44ce,X ; player_right_bottom_sprite + &10 &2d23 9d f0 7f STA &7ff0,X ; buffer_two + &100 * 23 + &f0 &2d26 ca DEX &2d27 10 c1 BPL &2cea ; plot_player_sides_to_buffer_two_loop &2d29 60 RTS ; plot_character &2d2a 85 15 STA &15 ; character &2d2c a9 00 LDA #&00 &2d2e 85 30 STA &30 ; screen_address_low &2d30 ad fe 25 LDA &25fe ; shallow_buffer_row_addresses_high_table_high &2d33 c9 4b CMP #&4b ; &4b00 = buffer_one_row_addresses_high_table &2d35 f0 06 BEQ &2d3d ; is_buffer_one ; is_buffer_two &2d37 a9 68 LDA #&68 ; &6800 = buffer_two &2d39 85 31 STA &31 ; screen_address_high &2d3b d0 04 BNE &2d41 ; add_text_offset # Always branches ; is_buffer_one &2d3d a9 50 LDA #&50 ; &5000 = buffer_one &2d3f 85 31 STA &31 ; screen_address_high ; add_text_offset &2d41 a5 30 LDA &30 ; screen_address_low &2d43 18 CLC &2d44 65 16 ADC &16 ; text_screen_offset_low &2d46 85 30 STA &30 ; screen_address_low &2d48 a5 31 LDA &31 ; screen_address_high &2d4a 65 17 ADC &17 ; text_screen_offset_high &2d4c 85 31 STA &31 ; screen_address_high &2d4e a9 00 LDA #&00 &2d50 85 33 STA &33 ; font_address_high &2d52 a5 15 LDA &15 ; character &2d54 38 SEC &2d55 e9 2c SBC #&2c ; "," &2d57 0a ASL A &2d58 0a ASL A &2d59 26 33 ROL &33 ; font_address_high &2d5b 0a ASL A &2d5c 26 33 ROL &33 ; font_address_high &2d5e 85 32 STA &32 ; font_address_low &2d60 a5 33 LDA &33 ; font_address_high &2d62 18 CLC &2d63 69 47 ADC #&47 ; &4700 = font_data &2d65 85 33 STA &33 ; font_address_high &2d67 a0 07 LDY #&07 ; plot_character_loop &2d69 b1 32 LDA (&32),Y ; font_address &2d6b 25 1a AND &1a ; colour_pixel_value &2d6d 91 30 STA (&30),Y ; screen_address &2d6f 88 DEY &2d70 10 f7 BPL &2d69 ; plot_character_loop &2d72 a5 16 LDA &16 ; text_screen_offset_low &2d74 18 CLC &2d75 69 08 ADC #&08 # Move right four pixels &2d77 85 16 STA &16 ; text_screen_offset_low &2d79 60 RTS ; plot_strings ; plot_strings_loop &2d7a 8a TXA &2d7b 48 PHA ; strings remaining &2d7c 20 9d 2d JSR &2d9d ; plot_string_to_buffer &2d7f 20 e6 2d JSR &2de6 ; move_to_end_of_string &2d82 68 PLA ; strings remaining &2d83 aa TAX &2d84 ca DEX &2d85 10 f3 BPL &2d7a ; plot_strings_loop &2d87 60 RTS ; plot_string &2d88 a5 18 LDA &18 ; text_address_low &2d8a 48 PHA ; text_address_low &2d8b a5 19 LDA &19 ; text_address_high &2d8d 48 PHA ; text_address_high &2d8e 20 6c 2e JSR &2e6c ; use_other_buffer &2d91 20 9d 2d JSR &2d9d ; plot_string_to_buffer &2d94 20 6c 2e JSR &2e6c ; use_other_buffer &2d97 68 PLA ; text_address_high &2d98 85 19 STA &19 ; text_address_high &2d9a 68 PLA ; text_address_low &2d9b 85 18 STA &18 ; text_address_low ; plot_string_to_buffer &2d9d a0 00 LDY #&00 &2d9f b1 18 LDA (&18),Y ; text_address # First two bytes specify screen offset &2da1 85 16 STA &16 ; text_screen_offset_low &2da3 c8 INY &2da4 b1 18 LDA (&18),Y ; text_address &2da6 85 17 STA &17 ; text_screen_offset_high &2da8 c8 INY &2da9 b1 18 LDA (&18),Y ; text_address # Third byte specifies colour &2dab 85 1a STA &1a ; colour_pixel_value &2dad c8 INY &2dae b1 18 LDA (&18),Y ; text_address # Four byte specifies length of string &2db0 48 PHA ; text length &2db1 a5 18 LDA &18 ; text_address_low &2db3 18 CLC &2db4 69 04 ADC #&04 # Move to start of characters &2db6 85 18 STA &18 ; text_address_low &2db8 a5 19 LDA &19 ; text_address_high &2dba 69 00 ADC #&00 &2dbc 85 19 STA &19 ; text_address_high &2dbe 68 PLA ; text length ; plot_string_from_variables &2dbf 85 34 STA &34 ; text_length &2dc1 a0 00 LDY #&00 ; plot_string_loop &2dc3 98 TYA &2dc4 48 PHA ; offset &2dc5 b1 18 LDA (&18),Y ; text_address &2dc7 c9 20 CMP #&20 ; " " &2dc9 d0 10 BNE &2ddb ; not_space ; is_space &2dcb a5 16 LDA &16 ; text_screen_offset_low &2dcd 18 CLC &2dce 69 08 ADC #&08 # Move right four pixels &2dd0 85 16 STA &16 ; text_screen_offset_low &2dd2 a5 17 LDA &17 ; text_screen_offset_high &2dd4 69 00 ADC #&00 &2dd6 85 17 STA &17 ; text_screen_offset_high &2dd8 4c de 2d JMP &2dde ; skip_plotting_character ; not_space &2ddb 20 2a 2d JSR &2d2a ; plot_character ; skip_plotting_character &2dde 68 PLA ; offset &2ddf a8 TAY &2de0 c8 INY &2de1 c4 34 CPY &34 ; text_length &2de3 d0 de BNE &2dc3 ; plot_string_loop &2de5 60 RTS ; move_to_end_of_string &2de6 a5 18 LDA &18 ; text_address_low &2de8 18 CLC &2de9 65 34 ADC &34 ; text_length &2deb 85 18 STA &18 ; text_address_low &2ded a5 19 LDA &19 ; text_address_high &2def 69 00 ADC #&00 &2df1 85 19 STA &19 ; text_address_high &2df3 60 RTS ; plot_number_without_leading_zeros &2df4 a9 00 LDA #&00 &2df6 85 57 STA &57 ; leading_zeros # Set to zero to suppress leading zeros &2df8 a2 03 LDX #&03 ; plot_number_without_leading_zeros_loop &2dfa 8a TXA &2dfb 48 PHA ; pairs remaining &2dfc b5 70 LDA &70,X ; number &2dfe 05 57 ORA &57 ; leading_zeros &2e00 d0 10 BNE &2e12 ; plot_digit_pair &2e02 a5 16 LDA &16 ; text_screen_offset_low &2e04 18 CLC &2e05 69 10 ADC #&10 &2e07 85 16 STA &16 ; text_screen_offset_low &2e09 a5 17 LDA &17 ; text_screen_offset_high &2e0b 69 00 ADC #&00 &2e0d 85 17 STA &17 ; text_screen_offset_high &2e0f 4c 19 2e JMP &2e19 ; plot_digit_pair ; plot_digit_pair &2e12 85 57 STA &57 ; leading_zeros &2e14 b5 70 LDA &70,X ; number &2e16 20 30 2e JSR &2e30 ; plot_two_digit_number ; skip_digit_pair &2e19 68 PLA ; pairs remaining &2e1a aa TAX &2e1b ca DEX &2e1c 10 dc BPL &2dfa ; plot_number_without_leading_zeros_loop &2e1e 60 RTS ; plot_number &2e1f a5 73 LDA &73 ; number + 3 &2e21 20 30 2e JSR &2e30 ; plot_two_digit_number &2e24 a5 72 LDA &72 ; number + 2 &2e26 20 30 2e JSR &2e30 ; plot_two_digit_number &2e29 a5 71 LDA &71 ; number + 1 &2e2b 20 30 2e JSR &2e30 ; plot_two_digit_number &2e2e a5 70 LDA &70 ; number ; plot_two_digit_number &2e30 85 60 STA &60 ; ones &2e32 4a LSR A &2e33 4a LSR A &2e34 4a LSR A &2e35 4a LSR A &2e36 85 5f STA &5f ; tens &2e38 a5 60 LDA &60 ; ones &2e3a 29 0f AND #&0f &2e3c 85 60 STA &60 ; ones &2e3e a5 5f LDA &5f ; tens &2e40 18 CLC &2e41 69 30 ADC #&30 ; "0" &2e43 20 2a 2d JSR &2d2a ; plot_character &2e46 a5 60 LDA &60 ; ones &2e48 18 CLC &2e49 69 30 ADC #&30 ; "0" &2e4b 4c 2a 2d JMP &2d2a ; plot_character ; unused # &2e4e - &2e6b is a copy of &2e30 - &2e4d &2e4e 85 60 STA &60 ; ones &2e50 4a LSR A &2e51 4a LSR A &2e52 4a LSR A &2e53 4a LSR A &2e54 85 5f STA &5f ; tens &2e56 a5 60 LDA &60 ; ones &2e58 29 0f AND #&0f &2e5a 85 60 STA &60 ; ones &2e5c a5 5f LDA &5f ; tens &2e5e 18 CLC &2e5f 69 30 ADC #&30 ; "0" &2e61 20 2a 2d JSR &2d2a ; plot_character &2e64 a5 60 LDA &60 ; ones &2e66 18 CLC &2e67 69 30 ADC #&30 ; "0" &2e69 4c 2a 2d JMP &2d2a ; plot_character ; use_other_buffer &2e6c ad fe 25 LDA &25fe ; shallow_buffer_row_addresses_high_table_high &2e6f 18 CLC &2e70 69 01 ADC #&01 # Swap between &4b00 ; buffer_one_row_addresses_high_table &2e72 c9 4d CMP #&4d # and &4c00 ; buffer_two_row_addresses_high_table &2e74 d0 02 BNE &2e78 ; skip_wraparound &2e76 a9 4b LDA #&4b ; &4b00 = buffer_one_row_addresses_high_table ; skip_wraparound &2e78 8d fe 25 STA &25fe ; shallow_buffer_row_addresses_high_table_high &2e7b 8d 92 26 STA &2692 ; steep_buffer_row_addresses_high_table_high &2e7e 8d 18 27 STA &2718 ; diagonal_buffer_row_addresses_high_table_high &2e81 8d 39 29 STA &2939 ; pixel_buffer_row_addresses_high_table_high &2e84 8d eb 29 STA &29eb ; vertical_buffer_row_addresses_high_table_high &2e87 8d 0b 2b STA &2b0b ; horizontal_buffer_row_addresses_high_table_high &2e8a 8d fc 39 STA &39fc ; player_buffer_row_addresses_high_table_high &2e8d 60 RTS ; set_colour_zero_to_X &2e8e a9 13 LDA #&13 &2e90 20 ee ff JSR &ffee ; OSWRCH &2e93 a9 00 LDA #&00 &2e95 20 ee ff JSR &ffee ; OSWRCH &2e98 8a TXA &2e99 20 ee ff JSR &ffee ; OSWRCH &2e9c a9 00 LDA #&00 &2e9e 20 ee ff JSR &ffee ; OSWRCH &2ea1 20 ee ff JSR &ffee ; OSWRCH &2ea4 4c ee ff JMP &ffee ; OSWRCH ; reset_fireballs &2ea7 a2 07 LDX #&07 ; reset_fireballs_loop &2ea9 a9 ff LDA #&ff &2eab 9d e7 30 STA &30e7,X ; fireballs_state # Set to negative to indicate no fireball in slot &2eae a9 00 LDA #&00 &2eb0 9d ef 30 STA &30ef,X ; fireballs_x &2eb3 9d f7 30 STA &30f7,X ; fireballs_x_high &2eb6 9d ff 30 STA &30ff,X ; fireballs_y &2eb9 9d 07 31 STA &3107,X ; fireballs_y_high &2ebc 9d 0f 31 STA &310f,X ; fireballs_z_high &2ebf ca DEX &2ec0 10 e7 BPL &2ea9 ; reset_fireballs_loop &2ec2 60 RTS ; add_space_fireball &2ec3 ad fd 4f LDA &4ffd ; maximum_fireballs &2ec6 c9 05 CMP #&05 &2ec8 90 02 BCC &2ecc ; skip_ceiling &2eca a9 04 LDA #&04 ; skip_ceiling &2ecc 8d d8 2e STA &2ed8 ; last_slot &2ecf a5 55 LDA &55 ; origin_z_high &2ed1 30 48 BMI &2f1b ; leave # Don't add fireball if TIE fighter behind player &2ed3 c9 20 CMP #&20 &2ed5 90 44 BCC &2f1b ; leave # Don't add fireball if TIE fighter too near &2ed7 a2 04 LDX #&04 # actually LDX last_slot ; find_slot_for_space_fireball_loop &2ed9 bd e7 30 LDA &30e7,X ; fireballs_state # Negative if no fireball in slot &2edc 10 3a BPL &2f18 ; consider_next_slot ; found_slot &2ede 20 34 38 JSR &3834 ; calculate_screen_position_for_origin &2ee1 a5 67 LDA &67 ; screen_x_high &2ee3 05 69 ORA &69 ; screen_y_high &2ee5 d0 34 BNE &2f1b ; leave # Don't add fireball if TIE fighter offscreen &2ee7 a5 66 LDA &66 ; screen_x &2ee9 38 SEC &2eea e9 10 SBC #&10 &2eec c9 60 CMP #&60 &2eee b0 2b BCS &2f1b ; leave # Leave unless &10 <= x < &70 &2ef0 a5 68 LDA &68 ; screen_y &2ef2 38 SEC &2ef3 e9 10 SBC #&10 &2ef5 30 24 BMI &2f1b ; leave # Leave unless &10 <= y < &90 &2ef7 a5 66 LDA &66 ; screen_x &2ef9 9d ef 30 STA &30ef,X ; fireballs_x &2efc a5 67 LDA &67 ; screen_x_high &2efe 9d f7 30 STA &30f7,X ; fireballs_x_high &2f01 a5 68 LDA &68 ; screen_y &2f03 9d ff 30 STA &30ff,X ; fireballs_y &2f06 a5 69 LDA &69 ; screen_y_high &2f08 9d 07 31 STA &3107,X ; fireballs_y_high &2f0b a5 55 LDA &55 ; origin_z_high &2f0d 9d 0f 31 STA &310f,X ; fireballs_z_high &2f10 a9 00 LDA #&00 &2f12 9d e7 30 STA &30e7,X ; fireballs_state # Set to positive to indicate fireball in slot &2f15 4c 1b 2f JMP &2f1b ; leave ; consider_next_slot &2f18 ca DEX &2f19 10 be BPL &2ed9 ; find_slot_for_space_fireball_loop ; leave &2f1b 60 RTS ; update_space_fireballs &2f1c ae fd 4f LDX &4ffd ; maximum_fireballs ; update_space_fireballs_loop &2f1f 8a TXA &2f20 48 PHA ; fireball offset &2f21 bd e7 30 LDA &30e7,X ; fireballs_state # Positive if fireball in slot &2f24 30 49 BMI &2f6f ; consider_next_fireball ; update_space_fireball &2f26 bd ef 30 LDA &30ef,X ; fireballs_x &2f29 8d 02 03 STA &0302 ; target_x &2f2c 85 1c STA &1c ; centre_x &2f2e bd f7 30 LDA &30f7,X ; fireballs_x_high &2f31 8d 03 03 STA &0303 ; target_x_high &2f34 85 1d STA &1d ; centre_x_high &2f36 bd ff 30 LDA &30ff,X ; fireballs_y &2f39 8d 04 03 STA &0304 ; target_y &2f3c 85 1e STA &1e ; centre_y_high &2f3e bd 07 31 LDA &3107,X ; fireballs_y_high &2f41 8d 05 03 STA &0305 ; target_y_high &2f44 85 1f STA &1f ; fireball_y &2f46 bd 0f 31 LDA &310f,X ; fireballs_z_high &2f49 38 SEC &2f4a e9 02 SBC #&02 # Move fireball nearer to player &2f4c 9d 0f 31 STA &310f,X ; fireballs_z_high &2f4f 85 55 STA &55 ; origin_z_high &2f51 10 0c BPL &2f5f ; skip_removing_fireball &2f53 9d e7 30 STA &30e7,X ; fireballs_state # Set to negative to indicate no fireball in slot &2f56 20 72 23 JSR &2372 ; lose_shield # Lose shield for fireball reaching player &2f59 20 4c 3e JSR &3e4c ; plot_shields &2f5c 4c 6f 2f JMP &2f6f ; consider_next_fireball ; skip_removing_fireball &2f5f 20 f9 06 JSR &06f9 ; plot_fireball &2f62 a9 02 LDA #&02 &2f64 20 5d 42 JSR &425d ; check_for_player_hitting_target # Returns negative if player hit target &2f67 10 06 BPL &2f6f ; consider_next_fireball &2f69 68 PLA ; fireball offset &2f6a 48 PHA ; fireball offset &2f6b aa TAX &2f6c 20 27 31 JSR &3127 ; destroy_fireball_if_not_too_near ; consider_next_fireball &2f6f 68 PLA ; fireball offset &2f70 aa TAX &2f71 ca DEX &2f72 10 ab BPL &2f1f ; update_space_fireballs_loop &2f74 60 RTS ; add_surface_fireball &2f75 ae fd 4f LDX &4ffd ; maximum_fireballs ; find_slot_for_surface_fireball_loop &2f78 bd e7 30 LDA &30e7,X ; fireballs_state # Negative if no fireball in slot &2f7b 10 2c BPL &2fa9 ; consider_next_slot ; found_slot &2f7d a5 50 LDA &50 ; origin_x &2f7f 9d ef 30 STA &30ef,X ; fireballs_x &2f82 a5 51 LDA &51 ; origin_x_high &2f84 9d f7 30 STA &30f7,X ; fireballs_x_high &2f87 a5 52 LDA &52 ; origin_y &2f89 9d ff 30 STA &30ff,X ; fireballs_y &2f8c a5 53 LDA &53 ; origin_y_high &2f8e 9d 07 31 STA &3107,X ; fireballs_y_high &2f91 a5 55 LDA &55 ; origin_z_high &2f93 9d 0f 31 STA &310f,X ; fireballs_z_high &2f96 ad b5 08 LDA &08b5 ; player_x_high &2f99 9d 17 31 STA &3117,X ; fireballs_target_x_high &2f9c ad b7 08 LDA &08b7 ; player_y_high &2f9f 9d 1f 31 STA &311f,X ; fireballs_target_y_high &2fa2 a9 00 LDA #&00 &2fa4 9d e7 30 STA &30e7,X ; fireballs_state # Set to positive to indicate fireball in slot &2fa7 f0 03 BEQ &2fac ; leave # Always branches ; consider_next_slot &2fa9 ca DEX &2faa 10 cc BPL &2f78 ; find_slot_for_surface_fireball_loop ; leave &2fac 60 RTS ; update_surface_fireballs &2fad ae fd 4f LDX &4ffd ; maximum_fireballs ; update_surface_fireballs_loop &2fb0 8a TXA &2fb1 48 PHA ; fireball offset &2fb2 bd e7 30 LDA &30e7,X ; fireballs_state # Positive if fireball in slot &2fb5 30 7e BMI &3035 ; consider_next_fireball &2fb7 bd f7 30 LDA &30f7,X ; fireballs_x_high &2fba dd 17 31 CMP &3117,X ; fireballs_target_x_high &2fbd f0 0c BEQ &2fcb ; skip_moving_fireball_in_x # Move fireball towards target in x &2fbf b0 05 BCS &2fc6 ; move_fireball_left ; move_fireball_right &2fc1 69 01 ADC #&01 &2fc3 4c c8 2f JMP &2fc8 ; set_fireball_x ; move_fireball_left &2fc6 e9 01 SBC #&01 ; set_fireball_x &2fc8 9d f7 30 STA &30f7,X ; fireballs_x_high ; skip_moving_fireball_in_x &2fcb 85 51 STA &51 ; origin_x_high &2fcd bd 07 31 LDA &3107,X ; fireballs_y_high &2fd0 dd 1f 31 CMP &311f,X ; fireballs_target_y_high &2fd3 f0 0e BEQ &2fe3 ; skip_moving_fireball_in_y # Move fireball towards target in y &2fd5 10 06 BPL &2fdd ; move_fireball_down ; move_fireball_up &2fd7 18 CLC &2fd8 69 01 ADC #&01 &2fda 4c e0 2f JMP &2fe0 ; set_fireball_y ; move_fireball_down &2fdd 38 SEC &2fde e9 01 SBC #&01 ; set_fireball_y &2fe0 9d 07 31 STA &3107,X ; fireballs_y_high ; skip_moving_fireball_in_y &2fe3 85 53 STA &53 ; origin_y_high &2fe5 bd 0f 31 LDA &310f,X ; fireballs_z_high &2fe8 38 SEC &2fe9 e9 02 SBC #&02 # Move fireball towards player in z &2feb 9d 0f 31 STA &310f,X ; fireballs_z_high &2fee 85 55 STA &55 ; origin_z_high &2ff0 a9 00 LDA #&00 &2ff2 85 50 STA &50 ; origin_x &2ff4 85 52 STA &52 ; origin_y &2ff6 85 54 STA &54 ; origin_z &2ff8 20 9e 3d JSR &3d9e ; calculate_origin_relative_to_player &2ffb a5 55 LDA &55 ; origin_z_high &2ffd 10 09 BPL &3008 ; skip_removing_fireball &2fff 9d e7 30 STA &30e7,X ; fireballs_state # Set to negative to indicate no fireball in slot &3002 20 3f 31 JSR &313f ; check_if_surface_or_trench_fireball_hit_player &3005 4c 35 30 JMP &3035 ; consider_next_fireball ; skip_removing_fireball &3008 20 0a 32 JSR &320a ; apply_player_rotation_to_origin &300b 68 PLA ; fireball offset &300c 48 PHA ; fireball offset &300d aa TAX &300e 20 8e 30 JSR &308e ; plot_surface_or_trench_fireball # Returns fireball screen x and y in &1c - &1f &3011 68 PLA ; fireball offset &3012 48 PHA ; fireball offset &3013 aa TAX &3014 a5 1c LDA &1c ; centre_x &3016 30 0c BMI &3024 ; remove_fireball # Remove fireball if offscreen &3018 a5 1e LDA &1e ; centre_y &301a c9 a0 CMP #&a0 &301c b0 06 BCS &3024 ; remove_fireball # Remove fireball if offscreen &301e a5 1d LDA &1d ; centre_x_high &3020 05 1f ORA &1f ; centre_y_high &3022 f0 07 BEQ &302b ; check_for_hit ; remove_fireball &3024 a9 ff LDA #&ff &3026 9d e7 30 STA &30e7,X ; fireballs_state # Set to negative to indicate no fireball in slot &3029 30 0a BMI &3035 ; consider_next_fireball # Always branches ; check_for_hit &302b a9 08 LDA #&08 &302d 20 5d 42 JSR &425d ; check_for_player_hitting_target # Returns negative if player hit target &3030 10 03 BPL &3035 ; consider_next_fireball &3032 20 27 31 JSR &3127 ; destroy_fireball_if_not_too_near ; consider_next_fireball &3035 68 PLA ; fireball offset &3036 aa TAX &3037 ca DEX &3038 30 03 BMI &303d ; leave &303a 4c b0 2f JMP &2fb0 ; update_surface_fireballs_loop ; leave &303d 60 RTS ; update_trench_fireballs &303e ae fd 4f LDX &4ffd ; maximum_fireballs ; update_trench_fireballs_loop &3041 8a TXA &3042 48 PHA ; fireball offset &3043 bd e7 30 LDA &30e7,X ; fireballs_state # Positive if fireball in slot &3046 30 40 BMI &3088 ; consider_next_fireball ; update_trench_fireball &3048 a9 00 LDA #&00 &304a 85 50 STA &50 ; origin_x &304c 85 52 STA &52 ; origin_y &304e 85 54 STA &54 ; origin_z &3050 bd f7 30 LDA &30f7,X ; fireballs_x_high &3053 85 51 STA &51 ; origin_x_high &3055 bd 07 31 LDA &3107,X ; fireballs_y_high &3058 85 53 STA &53 ; origin_y_high &305a 20 9e 3d JSR &3d9e ; calculate_origin_relative_to_player &305d bd 0f 31 LDA &310f,X ; fireballs_z_high &3060 38 SEC &3061 e9 04 SBC #&04 &3063 9d 0f 31 STA &310f,X ; fireballs_z_high &3066 85 55 STA &55 ; origin_z_high &3068 cd b3 08 CMP &08b3 ; player_z_velocity &306b b0 0b BCS &3078 ; skip_removing_fireball &306d a9 ff LDA #&ff &306f 9d e7 30 STA &30e7,X ; fireballs_state # Set to negative to indicate no fireball in slot &3072 20 3f 31 JSR &313f ; check_if_surface_or_trench_fireball_hit_player &3075 4c 88 30 JMP &3088 ; consider_next_fireball ; skip_removing_fireball &3078 20 8e 30 JSR &308e ; plot_surface_or_trench_fireball &307b a9 08 LDA #&08 &307d 20 5d 42 JSR &425d ; check_for_player_hitting_target i # Returns negative if player hit target &3080 10 06 BPL &3088 ; consider_next_fireball &3082 68 PLA ; fireball offset &3083 48 PHA ; fireball offset &3084 aa TAX &3085 20 27 31 JSR &3127 ; destroy_fireball_if_not_too_near &3088 68 PLA ; fireball offset &3089 aa TAX &308a ca DEX &308b 10 b4 BPL &3041 ; update_trench_fireballs_loop &308d 60 RTS ; plot_surface_or_trench_fireball &308e 20 34 38 JSR &3834 ; calculate_screen_position_for_origin &3091 a5 66 LDA &66 ; screen_x &3093 8d 02 03 STA &0302 ; target_x &3096 85 1c STA &1c ; centre_x &3098 a5 67 LDA &67 ; screen_x_high &309a 8d 03 03 STA &0303 ; target_x_high &309d 85 1d STA &1d ; centre_x_high &309f a5 68 LDA &68 ; screen_y &30a1 8d 04 03 STA &0304 ; target_y &30a4 85 1e STA &1e ; centre_y &30a6 a5 69 LDA &69 ; screen_y_high &30a8 8d 05 03 STA &0305 ; target_y_high &30ab 85 1f STA &1f ; centre_y_high &30ad 4c f9 06 JMP &06f9 ; plot_fireball ; add_trench_fireball &30b0 ad ff 48 LDA &48ff ; exhaust_port_hit # Negative if exhaust port hit &30b3 30 31 BMI &30e6 ; leave &30b5 ae fd 4f LDX &4ffd ; maximum_fireballs ; find_slot_for_space_fireball_loop &30b8 bd e7 30 LDA &30e7,X ; fireballs_state # Negative if no fireball in slot &30bb 10 26 BPL &30e3 ; consider_next_slot &30bd 20 ff 37 JSR &37ff ; rnd &30c0 29 01 AND #&01 &30c2 d0 04 BNE &30c8 ; add_fireball_to_right ; add_fireball_to_left &30c4 a9 fb LDA #&fb &30c6 d0 02 BNE &30ca ; set_fireball_x_high # Always branches ; add_fireball_to_right &30c8 a9 05 LDA #&05 ; set_fireball_x_high &30ca 9d f7 30 STA &30f7,X ; fireballs_x_high &30cd 20 ff 37 JSR &37ff ; rnd &30d0 29 18 AND #&18 &30d2 18 CLC &30d3 69 04 ADC #&04 &30d5 9d 07 31 STA &3107,X ; fireballs_y_high &30d8 9d e7 30 STA &30e7,X ; fireballs_state # Set to positive to indicate fireball in slot &30db a9 60 LDA #&60 &30dd 9d 0f 31 STA &310f,X ; fireballs_z_high &30e0 4c e6 30 JMP &30e6 ; leave ; consider_next_slot &30e3 ca DEX &30e4 10 d2 BPL &30b8 ; find_slot_for_space_fireball_loop ; leave &30e6 60 RTS ; fireballs_state &30e7 00 00 00 00 00 00 00 00 ; fireballs_x &30ef 00 00 00 00 00 00 00 00 ; fireballs_x_high &30f7 00 00 00 00 00 00 00 00 ; fireballs_y &30ff 00 00 00 00 00 08 08 08 ; fireballs_y_high &3107 08 10 10 10 10 18 18 18 ; fireballs_z_high &310f 18 20 20 20 20 28 28 28 ; fireballs_target_x_high &3117 28 30 30 30 30 38 38 38 ; fireballs_target_y_high &311f 38 40 40 40 40 48 48 48 ; destroy_fireball_if_not_too_near &3127 a5 55 LDA &55 ; origin_z_high &3129 c9 03 CMP #&03 &312b 90 b9 BCC &30e6 ; leave # Don't destroy fireball if too near &312d a9 ff LDA #&ff &312f 9d e7 30 STA &30e7,X ; fireballs_state # Set to negative to indicate no fireball in slot &3132 a9 33 LDA #&33 &3134 85 70 STA &70 ; number &3136 a9 00 LDA #&00 &3138 85 71 STA &71 ; number + 1 &313a 85 72 STA &72 ; number + 2 &313c 4c 2f 16 JMP &162f ; add_to_score # Score 33 for destroying fireball ; check_if_surface_or_trench_fireball_hit_player &313f a5 51 LDA &51 ; origin_x_high # Relative to player &3141 18 CLC &3142 69 05 ADC #&05 &3144 c9 0a CMP #&0a &3146 b0 0f BCS &3157 ; leave &3148 a5 53 LDA &53 ; origin_y_high &314a 18 CLC &314b 69 04 ADC #&04 &314d c9 08 CMP #&08 &314f b0 06 BCS &3157 ; leave &3151 20 72 23 JSR &2372 ; lose_shield # Lose a shield for fireball hitting player &3154 20 4c 3e JSR &3e4c ; plot_shields ; leave &3157 60 RTS ; update_exploding_towers &3158 a2 03 LDX #&03 ; update_exploding_towers_loop &315a 8a TXA &315b 48 PHA ; exploding tower offset &315c bd fc 03 LDA &03fc,X ; exploding_towers_state &315f c9 08 CMP #&08 # actually CMP maximum_exploding_towers_state_for_updating # 8 frames on wave 2, 12 frames on wave 3 and after &3161 d0 04 BNE &3167 ; update_exploding_tower &3163 68 PLA ; exploding tower offset &3164 4c e5 31 JMP &31e5 ; consider_next_exploding_tower ; update_exploding_tower &3167 a9 03 LDA #&03 ; MODEL_EXPLODING_TOWER_PART_TRIANGLE &3169 85 cf STA &cf ; model &316b a9 00 LDA #&00 &316d 8d 80 08 STA &0880 ; exploding_tower_x_offset &3170 bd e0 03 LDA &03e0,X ; exploding_towers_rotation_about_z &3173 85 ca STA &ca ; model_rotation_about_z &3175 bd fc 03 LDA &03fc,X ; exploding_towers_state &3178 a8 TAY &3179 4a LSR A &317a 6e 80 08 ROR &0880 ; exploding_tower_x_offset &317d 8d 81 08 STA &0881 ; exploding_tower_x_offset_high &3180 ee 81 08 INC &0881 ; exploding_tower_x_offset_high &3183 bd e4 03 LDA &03e4,X ; exploding_towers_x &3186 18 CLC &3187 6d 80 08 ADC &0880 ; exploding_tower_x_offset &318a 85 50 STA &50 ; origin_x &318c bd e8 03 LDA &03e8,X ; exploding_towers_x_high &318f 18 CLC &3190 6d 81 08 ADC &0881 ; exploding_tower_x_offset_high &3193 85 51 STA &51 ; origin_x_high &3195 20 ec 31 JSR &31ec ; plot_exploding_tower_part # Plot right triangle of exploding tower &3198 68 PLA ; exploding tower offset &3199 48 PHA ; exploding tower offset &319a aa TAX &319b a9 00 LDA #&00 &319d 38 SEC &319e fd e0 03 SBC &03e0,X ; exploding_towers_rotation_about_z &31a1 85 ca STA &ca ; model_rotation_about_z &31a3 bd fc 03 LDA &03fc,X ; exploding_towers_state &31a6 a8 TAY &31a7 bd e4 03 LDA &03e4,X ; exploding_towers_x &31aa 38 SEC &31ab ed 80 08 SBC &0880 ; exploding_tower_x_offset &31ae 85 50 STA &50 ; origin_x &31b0 bd e8 03 LDA &03e8,X ; exploding_towers_x_high &31b3 ed 81 08 SBC &0881 ; exploding_tower_x_offset_high &31b6 85 51 STA &51 ; origin_x_high &31b8 20 ec 31 JSR &31ec ; plot_exploding_tower_part # Plot left triangle of exploding tower &31bb 68 PLA ; exploding tower offset &31bc 48 PHA ; exploding tower offset &31bd aa TAX &31be a9 00 LDA #&00 &31c0 85 ca STA &ca ; model_rotation_about_z &31c2 bd fc 03 LDA &03fc,X ; exploding_towers_state &31c5 a8 TAY &31c6 bd e4 03 LDA &03e4,X ; exploding_towers_x &31c9 85 50 STA &50 ; origin_x &31cb bd e8 03 LDA &03e8,X ; exploding_towers_x_high &31ce 85 51 STA &51 ; origin_x_high &31d0 a9 02 LDA #&02 ; MODEL_EXPLODING_TOWER_PART_SQUARE &31d2 85 cf STA &cf ; model &31d4 20 ec 31 JSR &31ec ; plot_exploding_tower_part # Plot square of exploding tower &31d7 68 PLA ; exploding tower offset &31d8 aa TAX &31d9 fe fc 03 INC &03fc,X ; exploding_towers_state &31dc bd e0 03 LDA &03e0,X ; exploding_towers_rotation_about_z &31df 18 CLC &31e0 69 08 ADC #&08 &31e2 9d e0 03 STA &03e0,X ; exploding_towers_rotation_about_z ; consider_next_exploding_tower &31e5 ca DEX &31e6 30 03 BMI &31eb ; leave &31e8 4c 5a 31 JMP &315a ; update_exploding_towers_loop ; leave &31eb 60 RTS ; plot_exploding_tower_part &31ec bd ec 03 LDA &03ec,X ; exploding_towers_y &31ef 18 CLC &31f0 79 42 43 ADC &4342,Y ; exploding_tower_y_offsets_table &31f3 85 52 STA &52 ; origin_y &31f5 bd f0 03 LDA &03f0,X ; exploding_towers_y_high &31f8 79 4e 43 ADC &434e,Y ; exploding_tower_y_offsets_high_table &31fb 85 53 STA &53 ; origin_y_high &31fd bd f4 03 LDA &03f4,X ; exploding_towers_z &3200 85 54 STA &54 ; origin_z &3202 bd f8 03 LDA &03f8,X ; exploding_towers_z_high &3205 85 55 STA &55 ; origin_z_high &3207 4c 3d 3a JMP &3a3d ; plot_model_relative_to_player ; apply_player_rotation_to_origin &320a ae bb 08 LDX &08bb ; player_rotation_about_z &320d a5 50 LDA &50 ; origin_x &320f 85 7d STA &7d ; value_low &3211 a5 51 LDA &51 ; origin_x_high &3213 85 7e STA &7e ; value_high &3215 20 ac 37 JSR &37ac ; calculate_sixteen_bit_value_times_cosine_X # cosine_result = origin_x * cos(X) &3218 a5 52 LDA &52 ; origin_y &321a 85 7d STA &7d ; value_low &321c a5 53 LDA &53 ; origin_y_high &321e 85 7e STA &7e ; value_high &3220 20 88 37 JSR &3788 ; calculate_sixteen_bit_value_times_sine_X # sine_result = origin_y * sin(X) &3223 a5 68 LDA &68 ; cosine_result &3225 38 SEC &3226 e5 66 SBC &66 ; sine_result &3228 85 30 STA &30 ; rotated_x # rotated_x = origin_x * cos(X) - origin_y * sin(X) &322a a5 69 LDA &69 ; line_end_y_high &322c e5 67 SBC &67 ; cosine_result_high &322e 85 31 STA &31 ; rotated_x_high &3230 a5 50 LDA &50 ; origin_x &3232 85 7d STA &7d ; value_low &3234 a5 51 LDA &51 ; origin_x_high &3236 85 7e STA &7e ; value_high &3238 20 88 37 JSR &3788 ; calculate_sixteen_bit_value_times_sine_X # sine_result = origin_x * sin(X) &323b a5 52 LDA &52 ; origin_y &323d 85 7d STA &7d ; value_low &323f a5 53 LDA &53 ; origin_y_high &3241 85 7e STA &7e ; value_high &3243 20 ac 37 JSR &37ac ; calculate_sixteen_bit_value_times_cosine_X # cosine_result = origin_y * cos(X) &3246 a5 66 LDA &66 ; sine_result &3248 18 CLC &3249 65 68 ADC &68 ; cosine_result &324b 85 52 STA &52 ; origin_y # rotated_y = origin_x * sin(X) + origin_y * cos(X) &324d a5 67 LDA &67 ; sine_result_high &324f 65 69 ADC &69 ; cosine_result_high &3251 85 53 STA &53 ; origin_y_high &3253 a5 30 LDA &30 ; rotated_x &3255 85 50 STA &50 ; origin_x &3257 a5 31 LDA &31 ; rotated_x_high &3259 85 51 STA &51 ; origin_x_high &325b 60 RTS ; wave_completion_screen &325c 20 8a 23 JSR &238a ; wipe_tower_count_area_and_message_area &325f a9 00 LDA #&00 &3261 85 47 STA &47 ; point_z_high ; wave_completion_prelude_loop &3263 20 12 1f JSR &1f12 ; plot_death_star &3266 20 b3 16 JSR &16b3 ; consider_wiping_recent_score &3269 20 5a 2b JSR &2b5a ; use_other_buffer_and_wipe &326c a5 47 LDA &47 ; point_z_high &326e 18 CLC &326f 69 04 ADC #&04 # Move away from death star &3271 85 47 STA &47 ; point_z_high &3273 c9 70 CMP #&70 &3275 d0 ec BNE &3263 ; wave_completion_prelude_loop &3277 a9 40 LDA #&40 &3279 85 1c STA &1c ; centre_x &327b a9 54 LDA #&54 &327d 85 1e STA &1e ; centre_y &327f 20 5a 2b JSR &2b5a ; use_other_buffer_and_wipe &3282 20 6c 2e JSR &2e6c ; use_other_buffer &3285 a9 51 LDA #&51 ; EOR (&5e),Y &3287 8d 11 26 STA &2611 ; plot_shallow_line_opcode &328a a9 4d LDA #&4d ; EOR &ffff &328c 8d 9e 26 STA &269e ; plot_steep_line_opcode &328f 8d 24 27 STA &2724 ; plot_diagonal_line_opcode &3292 a9 00 LDA #&00 &3294 20 de 44 JSR &44de ; play_sound # Play sound for destroying death star &3297 a9 08 LDA #&08 &3299 20 de 44 JSR &44de ; play_sound # Play sound for destroying death star &329c a0 01 LDY #&01 ; explode_death_star_plot_and_unplot_loop &329e 98 TYA &329f 48 PHA ; plot or unplot count &32a0 a9 70 LDA #&70 &32a2 85 47 STA &47 ; point_z_high ; explode_death_star_loop &32a4 20 75 39 JSR &3975 ; divide_point_x_by_point_z_times_two &32a7 a5 78 LDA &78 ; result_fraction &32a9 85 7d STA &7d ; radius &32ab a5 79 LDA &79 ; result &32ad 85 7e STA &7e ; radius_high &32af a5 47 LDA &47 ; point_z_high &32b1 29 04 AND #&04 &32b3 4a LSR A &32b4 4a LSR A &32b5 18 CLC &32b6 69 01 ADC #&01 &32b8 20 ab 23 JSR &23ab ; set_colour &32bb 20 ae 36 JSR &36ae ; plot_circle # Plot or unplot death star explosion &32be a5 47 LDA &47 ; point_z_high &32c0 38 SEC &32c1 e9 04 SBC #&04 &32c3 85 47 STA &47 ; point_z_high &32c5 d0 dd BNE &32a4 ; explode_death_star_loop &32c7 68 PLA ; plot or unplot count &32c8 a8 TAY &32c9 88 DEY &32ca 10 d2 BPL &329e ; explode_death_star_plot_and_unplot_loop &32cc 20 90 2c JSR &2c90 ; wipe_buffer_two &32cf 20 f6 2b JSR &2bf6 ; wipe_buffer_one &32d2 a9 11 LDA #&11 ; ORA (&5e),Y &32d4 8d 11 26 STA &2611 ; plot_shallow_line_opcode &32d7 a9 0d LDA #&0d ; ORA &ffff &32d9 8d 9e 26 STA &269e ; plot_steep_line_opcode &32dc 8d 24 27 STA &2724 ; plot_diagonal_line_opcode &32df ad 8d 03 LDA &038d ; shields &32e2 18 CLC &32e3 69 30 ADC #&30 ; "0" &32e5 8d 9c 43 STA &439c ; five_thousand_times_string + 11 # Set number of shields in string &32e8 a9 00 LDA #&00 &32ea 85 70 STA &70 ; number &32ec 85 71 STA &71 ; number + 1 &32ee 85 72 STA &72 ; number + 2 &32f0 85 73 STA &73 ; number + 3 &32f2 ad 8d 03 LDA &038d ; shields &32f5 f0 1d BEQ &3314 ; skip_calculating_score_for_remaining_shields ; calculate_score_for_remaining_shields &32f7 f8 SED &32f8 a2 00 LDX #&00 ; calculate_score_for_remaining_shields_loop &32fa a5 71 LDA &71 ; number + 1 &32fc 18 CLC &32fd 69 50 ADC #&50 # Score 5000 for each remaining shield &32ff 85 71 STA &71 ; number + 1 &3301 a5 72 LDA &72 ; number + 2 &3303 69 00 ADC #&00 &3305 85 72 STA &72 ; number + 2 &3307 a5 73 LDA &73 ; number + 3 &3309 69 00 ADC #&00 &330b 85 73 STA &73 ; number + 3 &330d e8 INX &330e ec 8d 03 CPX &038d ; shields &3311 d0 e7 BNE &32fa ; calculate_score_for_remaining_shields_loop &3313 d8 CLD ; skip_calculating_score_for_remaining_shields &3314 a9 ff LDA #&ff &3316 8d ae 08 STA &08ae ; player_has_full_shields # Set to negative to indicate not full shields &3319 ad 8d 03 LDA &038d ; shields &331c 18 CLC &331d 69 02 ADC #&02 &331f c9 06 CMP #&06 &3321 90 05 BCC &3328 ; skip_ceiling &3323 a9 06 LDA #&06 &3325 8d ae 08 STA &08ae ; player_has_full_shields # Set to positive to indicate full shields ; skip_ceiling &3328 8d 8d 03 STA &038d ; shields &332b a9 5a LDA #&5a ; &435a = deathstar_destroyed_string &332d 85 18 STA &18 ; text_address_low &332f a9 43 LDA #&43 &3331 85 19 STA &19 ; text_address_high &3333 a9 02 LDA #&02 ; R &3335 20 ab 23 JSR &23ab ; set_colour &3338 a2 00 LDX #&00 ; deathstar_destroyed_loop &333a 8a TXA &333b 48 PHA ; count &333c 29 1f AND #&1f &333e d0 06 BNE &3346 ; skip_plotting_string &3340 20 9d 2d JSR &2d9d ; plot_string_to_buffer # Plot "DEATHSTAR DESTROYED" &3343 20 e6 2d JSR &2de6 ; move_to_end_of_string # then "BONUS FOR REMAINING SHIELDS" ; skip_plotting_string # then "5000 X " and shields remaining &3346 68 PLA ; count &3347 48 PHA ; count &3348 c9 60 CMP #&60 &334a d0 0b BNE &3357 ; skip_flashing_shields &334c 20 4c 3e JSR &3e4c ; plot_shields &334f a9 02 LDA #&02 ; R &3351 20 ab 23 JSR &23ab ; set_colour &3354 4c 70 33 JMP &3370 ; skip_bonus_for_remaining_shields ; skip_flashing_shields &3357 c9 40 CMP #&40 &3359 d0 15 BNE &3370 ; skip_bonus_for_remaining_shields &335b 20 2f 16 JSR &162f ; add_to_score &335e ad ae 08 LDA &08ae ; player_has_full_shields # Positive if player has full shields &3361 10 0d BPL &3370 ; skip_skipping_shields_at_full_strength &3363 a5 18 LDA &18 ; text_address_low &3365 18 CLC &3366 69 1c ADC #&1c ; &001c = add_two_to_deflector_shields_string - shields_at_full_strength_string &3368 85 18 STA &18 ; text_address_low # Plot "ADD 2 TO DEFLECTOR SHIELDS" &336a a5 19 LDA &19 ; text_address_high &336c 69 00 ADC #&00 &336e 85 19 STA &19 ; text_address_high ; skip_skipping_shields_at_full_strength # or "SHIELDS AT FULL STRENGTH" &3370 20 b3 16 JSR &16b3 ; consider_wiping_recent_score &3373 a9 10 LDA #&10 &3375 20 f5 44 JSR &44f5 ; delay_for_A &3378 68 PLA ; count &3379 aa TAX &337a e8 INX &337b 10 bd BPL &333a ; deathstar_destroyed_loop &337d a9 00 LDA #&00 &337f 85 70 STA &70 ; number &3381 85 71 STA &71 ; number + 1 &3383 85 73 STA &73 ; number + 3 &3385 a9 40 LDA #&40 # Score 400000 for starting on wave 3 &3387 85 72 STA &72 ; number + 2 &3389 ad 8a 08 LDA &088a ; wave_as_bcd &338c c9 03 CMP #&03 &338e f0 08 BEQ &3398 ; add_starting_wave_bonus &3390 c9 05 CMP #&05 &3392 d0 2b BNE &33bf ; skip_starting_wave_bonus &3394 a9 80 LDA #&80 # Score 800000 for starting on wave 5 &3396 85 72 STA &72 ; number + 2 ; add_starting_wave_bonus &3398 ad 8a 08 LDA &088a ; wave_as_bcd &339b 4d 89 08 EOR &0889 ; wave_started_on &339e d0 1f BNE &33bf ; skip_starting_wave_bonus &33a0 a9 d7 LDA #&d7 ; &43d7 = starting_wave_bonus_string &33a2 85 18 STA &18 ; text_address_low &33a4 a9 43 LDA #&43 &33a6 85 19 STA &19 ; text_address_high &33a8 20 9d 2d JSR &2d9d ; plot_string_to_buffer # Plot "STARTING WAVE BONUS" &33ab 20 2f 16 JSR &162f ; add_to_score &33ae a2 3f LDX #&3f &33b0 8a TXA ; starting_wave_bonus_loop &33b1 48 PHA ; count &33b2 a9 0c LDA #&0c &33b4 20 f5 44 JSR &44f5 ; delay_for_A &33b7 20 b3 16 JSR &16b3 ; consider_wiping_recent_score &33ba 68 PLA ; count &33bb aa TAX &33bc ca DEX &33bd 10 f1 BPL &33b0 ; starting_wave_bonus_loop ; skip_starting_wave_bonus &33bf f8 SED &33c0 ad 8a 08 LDA &088a ; wave_as_bcd &33c3 18 CLC &33c4 69 01 ADC #&01 # Move to next wave &33c6 8d 8a 08 STA &088a ; wave_as_bcd &33c9 d8 CLD &33ca ee 8b 08 INC &088b ; wave &33cd ad 8a 08 LDA &088a ; wave_as_bcd &33d0 d0 03 BNE &33d5 ; skip_wraparound # Wraparound to wave 0 after wave 99 &33d2 8d 8b 08 STA &088b ; wave ; skip_wraparound &33d5 20 a8 2b JSR &2ba8 ; plot_status &33d8 20 5a 2b JSR &2b5a ; use_other_buffer_and_wipe &33db 4c 7c 04 JMP &047c ; start_space_stage ; hit_exhaust_port &33de ad ff 48 LDA &48ff ; exhaust_port_hit # Negative if exhaust port hit &33e1 30 2a BMI &340d ; leave &33e3 a9 ff LDA #&ff &33e5 8d ff 48 STA &48ff ; exhaust_port_hit # Set to negative to indicate exhaust port hit &33e8 a2 05 LDX #&05 ; remove_fireballs_loop &33ea 9d e7 30 STA &30e7,X ; fireballs_state # Set to negative to indicate no fireball in slot &33ed ca DEX &33ee 10 fa BPL &33ea ; remove_fireballs_loop &33f0 a9 00 LDA #&00 &33f2 8d fa 48 STA &48fa ; torpedoes_x &33f5 8d fc 48 STA &48fc ; torpedoes_y &33f8 ad b5 08 LDA &08b5 ; player_x_high &33fb 8d fb 48 STA &48fb ; torpedoes_x_high &33fe ad b7 08 LDA &08b7 ; player_y_high &3401 8d fd 48 STA &48fd ; torpedoes_y_high &3404 ad b9 08 LDA &08b9 ; player_z_high &3407 18 CLC &3408 69 10 ADC #&10 &340a 8d fe 48 STA &48fe ; torpedoes_z_high ; leave &340d 60 RTS ; update_exhaust_port_torpedoes &340e ad ff 48 LDA &48ff ; exhaust_port_hit # Negative if exhaust port hit &3411 10 fa BPL &340d ; leave &3413 ad fa 48 LDA &48fa ; torpedoes_x &3416 85 50 STA &50 ; offset_x &3418 ad fb 48 LDA &48fb ; torpedoes_x_high &341b 85 51 STA &51 ; offset_x_high &341d 30 0a BMI &3429 ; is_negative ; is_positive # If torpedoes_x > 0, &341f 46 51 LSR &51 ; offset_x_high &3421 66 50 ROR &50 ; offset_x &3423 20 1a 35 JSR &351a ; invert_offset_x # move torpedoes left, i.e. towards centre &3426 4c 30 34 JMP &3430 ; add_offset ; is_negative # If torpedoes_x < 0, &3429 20 1a 35 JSR &351a ; invert_offset_x &342c 46 51 LSR &51 ; offset_x_high &342e 66 50 ROR &50 ; offset_x # move torpedoes right, i.e. towards centre ; add_offset &3430 ad fa 48 LDA &48fa ; torpedoes_x &3433 18 CLC &3434 65 50 ADC &50 ; offset_x &3436 8d fa 48 STA &48fa ; torpedoes_x &3439 ad fb 48 LDA &48fb ; torpedoes_x_high &343c 65 51 ADC &51 ; offset_x_high &343e 8d fb 48 STA &48fb ; torpedoes_x_high &3441 a9 01 LDA #&01 ; C &3443 20 ab 23 JSR &23ab ; set_colour &3446 a9 00 LDA #&00 &3448 85 41 STA &41 ; point_x_high &344a 85 46 STA &46 ; point_z &344c 85 41 STA &41 ; point_x_high &344e ad fe 48 LDA &48fe ; torpedoes_z_high &3451 c9 c0 CMP #&c0 &3453 b0 09 BCS &345e ; set_torpedoes_falling_into_port ; move_torpedoes_towards_port &3455 18 CLC &3456 69 10 ADC #&10 &3458 8d fe 48 STA &48fe ; torpedoes_z_high &345b 4c 64 34 JMP &3464 ; plot_exhaust_port_torpedoes ; set_torpedoes_falling_into_port &345e ce fd 48 DEC &48fd ; torpedoes_y_high &3461 ad fe 48 LDA &48fe ; torpedoes_z_high ; plot_exhaust_port_torpedoes &3464 38 SEC &3465 ed b9 08 SBC &08b9 ; player_z_high &3468 85 47 STA &47 ; point_z_high &346a 48 PHA ; z_high &346b a9 00 LDA #&00 &346d 85 40 STA &40 ; point_x &346f a9 02 LDA #&02 &3471 85 41 STA &41 ; point_x_high &3473 20 75 39 JSR &3975 ; divide_point_x_by_point_z_times_two # Scale torpedos by distance &3476 a9 00 LDA #&00 &3478 85 46 STA &46 ; point_z &347a 68 PLA ; z_high &347b 85 47 STA &47 ; point_z_high &347d a5 78 LDA &78 ; result_fraction &347f 85 7d STA &7d ; radius &3481 a5 79 LDA &79 ; result &3483 85 7e STA &7e ; radius_high &3485 ad fa 48 LDA &48fa ; torpedoes_x &3488 85 40 STA &40 ; point_x &348a ad fb 48 LDA &48fb ; torpedoes_x_high &348d 38 SEC &348e e9 02 SBC #&02 &3490 38 SEC &3491 ed b5 08 SBC &08b5 ; player_x_high &3494 85 41 STA &41 ; point_x_high &3496 ad fc 48 LDA &48fc ; torpedoes_y &3499 85 43 STA &43 ; point_y &349b ad fd 48 LDA &48fd ; torpedoes_y_high &349e 38 SEC &349f ed b7 08 SBC &08b7 ; player_y_high &34a2 85 44 STA &44 ; point_y_high &34a4 20 4c 38 JSR &384c ; calculate_screen_position_for_point # Calculate screen position for centre of left torpedo &34a7 a5 66 LDA &66 ; screen_x &34a9 85 1c STA &1c ; centre_x &34ab a5 67 LDA &67 ; screen_x_high &34ad 85 1d STA &1d ; centre_x_high &34af a5 68 LDA &68 ; screen_y &34b1 85 1e STA &1e ; centre_y &34b3 a5 69 LDA &69 ; screen_y_high &34b5 85 1f STA &1f ; centre_y_high &34b7 ad fa 48 LDA &48fa ; torpedoes_x &34ba 85 40 STA &40 ; point_x &34bc ad fb 48 LDA &48fb ; torpedoes_x_high &34bf 18 CLC &34c0 69 02 ADC #&02 &34c2 38 SEC &34c3 ed b5 08 SBC &08b5 ; player_x_high &34c6 85 41 STA &41 ; point_x_high &34c8 20 df 38 JSR &38df ; calculate_screen_x_for_point # Calculate screen x for centre of right torpedo &34cb a5 66 LDA &66 ; screen_x &34cd 85 54 STA &54 ; right_torpedo_screen_x &34cf a5 67 LDA &67 ; screen_x_high &34d1 85 55 STA &55 ; right_torpedo_screen_x_high &34d3 a5 7e LDA &7e ; radius &34d5 85 03 STA &03 ; radius_y_high &34d7 4a LSR A &34d8 85 05 STA &05 ; radius_x_high &34da a5 7d LDA &7d ; radius_high &34dc 85 02 STA &02 ; radius_y &34de 6a ROR A &34df 85 04 STA &04 ; radius_x &34e1 a0 01 LDY #&01 ; plot_exhaust_port_torpedoes_loop &34e3 98 TYA &34e4 48 PHA &34e5 a0 07 LDY #&07 ; plot_exhaust_port_torpedo_loop &34e7 20 ff 37 JSR &37ff ; rnd &34ea aa TAX &34eb 29 01 AND #&01 &34ed 18 CLC &34ee 69 01 ADC #&01 &34f0 20 ab 23 JSR &23ab ; set_colour &34f3 20 d6 36 JSR &36d6 ; rotate_around_centre &34f6 a5 1c LDA &1c ; centre_x &34f8 85 62 STA &62 ; line_start_x &34fa a5 1d LDA &1d ; centre_x_high &34fc 85 63 STA &63 ; line_start_x_high &34fe a5 1e LDA &1e ; centre_y &3500 85 64 STA &64 ; line_start_y &3502 a5 1f LDA &1f ; centre_y_high &3504 85 65 STA &65 ; line_start_y_high &3506 20 db 23 JSR &23db ; plot_line &3509 88 DEY &350a 10 db BPL &34e7 ; plot_exhaust_port_torpedo_loop &350c a5 54 LDA &54 ; right_torpedo_screen_x # Repeat for right torpedo &350e 85 1c STA &1c ; centre_x &3510 a5 55 LDA &55 ; right_torpedo_screen_x_high &3512 85 1d STA &1d ; centre_x_high &3514 68 PLA &3515 a8 TAY &3516 88 DEY &3517 10 ca BPL &34e3 ; plot_exhaust_port_torpedoes_loop &3519 60 RTS ; invert_offset_x &351a a9 00 LDA #&00 &351c 38 SEC &351d e5 50 SBC &50 ; offset_x &351f 85 50 STA &50 ; offset_x &3521 a9 00 LDA #&00 &3523 e5 51 SBC &51 ; offset_x_high &3525 85 51 STA &51 ; offset_x_high &3527 60 RTS ; calculate_distance_times_slope &3528 a9 00 LDA #&00 &352a 85 76 STA &76 ; multiplicand_highest &352c 85 77 STA &77 ; negative_result &352e 85 78 STA &78 ; result_fraction &3530 85 79 STA &79 ; result &3532 85 7a STA &7a ; result_high &3534 a5 70 LDA &70 ; distance &3536 05 71 ORA &71 ; distance_high &3538 f0 06 BEQ &3540 ; leave # Leave with result = 0 if distance = 0 &353a a5 72 LDA &72 ; slope &353c 05 73 ORA &73 ; slope_high &353e d0 01 BNE &3541 ; not_zero_slope # Leave with result = 0 if slope = 0 ; leave &3540 60 RTS ; not_zero_slope &3541 a5 71 LDA &71 ; distance_high &3543 10 0f BPL &3554 ; skip_inverting_distance &3545 85 77 STA &77 ; negative_result # Set to negative to indicate distance is negative &3547 a9 00 LDA #&00 &3549 38 SEC &354a e5 70 SBC &70 ; distance # Make distance positive &354c 85 70 STA &70 ; distance &354e a9 00 LDA #&00 &3550 e5 71 SBC &71 ; distance_high &3552 85 71 STA &71 ; distance_high ; skip_inverting_distance &3554 a5 73 LDA &73 ; slope_high &3556 10 13 BPL &356b ; skip_inverting_slope &3558 a5 77 LDA &77 ; negative_result &355a 49 80 EOR #&80 # Set to negative if distance * slope is be negative &355c 85 77 STA &77 ; negative_result &355e a9 00 LDA #&00 &3560 38 SEC &3561 e5 72 SBC &72 ; slope # Make slope positive &3563 85 72 STA &72 ; slope &3565 a9 00 LDA #&00 &3567 e5 73 SBC &73 ; slope_high &3569 85 73 STA &73 ; slope_high ; skip_inverting_slope &356b a5 73 LDA &73 ; slope_high &356d c5 71 CMP &71 ; distance_high &356f 90 1c BCC &358d ; skip_swapping_distance_and_slope # If distance < slope, &3571 d0 06 BNE &3579 ; swap_distance_and_slope &3573 a5 72 LDA &72 ; slope &3575 c5 70 CMP &70 ; distance &3577 90 14 BCC &358d ; skip_swapping_distance_and_slope ; swap_distance_and_slope # swap distance and slope &3579 a5 70 LDA &70 ; distance &357b 48 PHA ; distance &357c a5 72 LDA &72 ; slope &357e 85 70 STA &70 ; distance &3580 68 PLA ; distance &3581 85 72 STA &72 ; slope &3583 a5 71 LDA &71 ; distance_high &3585 48 PHA ; distance_high &3586 a5 73 LDA &73 ; slope_high &3588 85 71 STA &71 ; distance_high &358a 68 PLA ; distance_high &358b 85 73 STA &73 ; slope_high ; skip_swapping_distance_and_slope &358d a5 72 LDA &72 ; slope # Multiply distance by slope &358f 85 74 STA &74 ; multiplicand &3591 a5 73 LDA &73 ; slope_high &3593 85 75 STA &75 ; multiplicand_high ; multiplication_loop &3595 46 71 LSR &71 ; distance_high &3597 66 70 ROR &70 ; distance &3599 90 13 BCC &35ae ; skip_addition &359b a5 78 LDA &78 ; result_fraction &359d 18 CLC &359e 65 74 ADC &74 ; multiplicand &35a0 85 78 STA &78 ; result_fraction &35a2 a5 79 LDA &79 ; result &35a4 65 75 ADC &75 ; multiplicand_high &35a6 85 79 STA &79 ; result &35a8 a5 7a LDA &7a ; result_high &35aa 65 76 ADC &76 ; multiplicand_highest &35ac 85 7a STA &7a ; result_high ; skip_addition &35ae 06 74 ASL &74 ; multiplicand &35b0 26 75 ROL &75 ; multiplicand_high &35b2 26 76 ROL &76 ; multiplicand_highest &35b4 a5 70 LDA &70 ; distance &35b6 05 71 ORA &71 ; distance_high &35b8 d0 db BNE &3595 ; multiplication_loop &35ba a5 77 LDA &77 ; negative_result &35bc 10 13 BPL &35d1 ; skip_inverting_result # If distance * slope was negative, &35be a9 00 LDA #&00 &35c0 38 SEC &35c1 e5 78 SBC &78 ; result_fraction # Make result negative &35c3 85 78 STA &78 ; result_fraction &35c5 a9 00 LDA #&00 &35c7 e5 79 SBC &79 ; result &35c9 85 79 STA &79 ; result &35cb a9 00 LDA #&00 &35cd e5 7a SBC &7a ; result_high &35cf 85 7a STA &7a ; result_high ; skip_inverting_result &35d1 60 RTS # Leave with result = distance * slope ; multiply_sixteen_bits_by_eight_bits &35d2 a9 00 LDA #&00 &35d4 85 78 STA &78 ; result_fraction &35d6 85 79 STA &79 ; result &35d8 85 7a STA &7a ; result_high &35da 85 74 STA &74 ; multiplicand_highest &35dc a5 70 LDA &70 ; multiplicand &35de 05 71 ORA &71 ; multiplicand_high &35e0 f0 25 BEQ &3607 ; leave &35e2 a5 73 LDA &73 ; multiplier &35e4 f0 21 BEQ &3607 ; leave ; multiplication_loop &35e6 46 73 LSR &73 ; multiplier &35e8 90 13 BCC &35fd ; skip_addition &35ea a5 78 LDA &78 ; result_fraction &35ec 18 CLC &35ed 65 70 ADC &70 ; multiplicand &35ef 85 78 STA &78 ; result_fraction &35f1 a5 79 LDA &79 ; result &35f3 65 71 ADC &71 ; multiplicand_high &35f5 85 79 STA &79 ; result &35f7 a5 7a LDA &7a ; result_high &35f9 65 74 ADC &74 ; multiplicand_highest &35fb 85 7a STA &7a ; result_high ; skip_addition &35fd 06 70 ASL &70 ; multiplicand &35ff 26 71 ROL &71 ; multiplicand_high &3601 26 74 ROL &74 ; multiplicand_highest &3603 a5 73 LDA &73 ; multiplier &3605 d0 df BNE &35e6 ; multiplication_loop &3607 60 RTS ; calculate_line_slope &3608 a5 2e LDA &2e ; delta_two &360a 05 2f ORA &2f ; delta_two_high &360c f0 50 BEQ &365e ; division_by_zero &360e 86 6a STX &6a ; tmp_x &3610 84 6b STY &6b ; tmp_y &3612 a2 08 LDX #&08 &3614 a5 2f LDA &2f ; delta_two_high &3616 30 07 BMI &361f ; skip_scaling ; scaling_loop &3618 e8 INX &3619 06 2e ASL &2e ; delta_two &361b 26 2f ROL &2f ; delta_two_high &361d 10 f9 BPL &3618 ; scaling_loop ; skip_scaling &361f 86 74 STX &74 ; scaling_power &3621 a0 00 LDY #&00 &3623 84 75 STY &75 ; delta_two_fraction &3625 84 78 STY &78 ; result_fraction &3627 a6 2c LDX &2c ; delta_one &3629 a5 2d LDA &2d ; delta_one_high ; division_loop # Calculate delta_one / delta_two &362b c5 2f CMP &2f ; delta_two_high &362d 90 1c BCC &364b ; skip_subtraction &362f d0 0a BNE &363b ; is_greater &3631 e4 2e CPX &2e ; delta_two &3633 90 16 BCC &364b ; skip_subtraction &3635 d0 04 BNE &363b ; is_greater &3637 c4 75 CPY &75 ; delta_two_fraction &3639 90 10 BCC &364b ; skip_subtraction ; is_greater &363b 98 TYA &363c 38 SEC &363d e5 75 SBC &75 ; delta_two_fraction &363f a8 TAY &3640 8a TXA &3641 e5 2e SBC &2e ; delta_two &3643 aa TAX &3644 a5 2d LDA &2d ; delta_one_high &3646 e5 2f SBC &2f ; delta_two_high &3648 85 2d STA &2d ; delta_one_high &364a 38 SEC ; skip_subtraction &364b 26 78 ROL &78 ; result_fraction &364d 26 79 ROL &79 ; result &364f 46 2f LSR &2f ; delta_two_high &3651 66 2e ROR &2e ; delta_two &3653 66 75 ROR &75 ; delta_two_fraction &3655 c6 74 DEC &74 ; scaling_power &3657 10 d2 BPL &362b ; division_loop &3659 a6 6a LDX &6a ; tmp_x &365b a4 6b LDY &6b ; tmp_y &365d 60 RTS ; division_by_zero &365e a9 7f LDA #&7f &3660 85 7a STA &7a ; result_high &3662 a9 ff LDA #&ff &3664 85 78 STA &78 ; result_fraction &3666 85 79 STA &79 ; result &3668 60 RTS ; divide_dividend_by_divisor &3669 a5 2e LDA &2e ; divisor &366b 05 2f ORA &2f ; divisor_high &366d f0 ef BEQ &365e ; division_by_zero &366f 86 6a STX &6a ; tmp_x &3671 84 6b STY &6b ; tmp_y &3673 a2 08 LDX #&08 &3675 a5 2f LDA &2f ; divisor_high &3677 30 07 BMI &3680 ; skip_scaling ; scaling_loop &3679 e8 INX &367a 06 2e ASL &2e ; divisor &367c 26 2f ROL &2f ; divisor_high &367e 10 f9 BPL &3679 ; scaling_loop ; skip_scaling &3680 86 74 STX &74 ; rounds &3682 a0 00 LDY #&00 &3684 84 78 STY &78 ; result_fraction &3686 a6 2c LDX &2c ; dividend &3688 a4 2d LDY &2d ; dividend_high ; division_loop &368a c4 2f CPY &2f ; divisor_high &368c 90 0f BCC &369d ; skip_subtraction &368e d0 04 BNE &3694 ; perform_subtraction &3690 e4 2e CPX &2e ; divisor &3692 90 09 BCC &369d ; skip_subtraction ; perform_subtraction &3694 8a TXA &3695 e5 2e SBC &2e ; divisor &3697 aa TAX &3698 98 TYA &3699 e5 2f SBC &2f ; divisor_high &369b a8 TAY &369c 38 SEC ; skip_subtraction &369d 26 78 ROL &78 ; result_fraction &369f 26 79 ROL &79 ; result &36a1 46 2f LSR &2f ; divisor_high &36a3 66 2e ROR &2e ; divisor &36a5 c6 74 DEC &74 ; rounds &36a7 10 e1 BPL &368a ; division_loop &36a9 a6 6a LDX &6a ; tmp_x &36ab a4 6b LDY &6b ; tmp_y &36ad 60 RTS # Leave with result = dividend / divisor ; plot_circle &36ae a5 7e LDA &7e ; radius_high &36b0 85 03 STA &03 ; radius_y_high &36b2 4a LSR A &36b3 85 05 STA &05 ; radius_x_high &36b5 a5 7d LDA &7d ; radius &36b7 85 02 STA &02 ; radius_y &36b9 6a ROR A &36ba 85 04 STA &04 ; radius_x &36bc a2 00 LDX #&00 &36be 20 d6 36 JSR &36d6 ; rotate_around_centre &36c1 20 0f 29 JSR &290f ; set_line_start_to_line_end &36c4 a2 08 LDX #&08 ; plot_circle_loop # Actually a 32-sided polygon &36c6 20 d6 36 JSR &36d6 ; rotate_around_centre &36c9 20 db 23 JSR &23db ; plot_line &36cc 8a TXA &36cd 18 CLC &36ce 69 08 ADC #&08 &36d0 aa TAX &36d1 e0 08 CPX #&08 &36d3 d0 f1 BNE &36c6 ; plot_circle_loop &36d5 60 RTS ; rotate_around_centre # Called with X = angle &36d6 a5 04 LDA &04 ; radius_x &36d8 85 7d STA &7d ; value &36da a5 05 LDA &05 ; radius_x_high &36dc 85 7e STA &7e ; value_high &36de 20 88 37 JSR &3788 ; calculate_sixteen_bit_value_times_sine_X &36e1 a5 02 LDA &02 ; radius_y &36e3 85 7d STA &7d ; value &36e5 a5 03 LDA &03 ; radius_y_high &36e7 85 7e STA &7e ; value_high &36e9 20 ac 37 JSR &37ac ; calculate_sixteen_bit_value_times_cosine_X &36ec a5 1c LDA &1c ; centre_x &36ee 18 CLC &36ef 65 66 ADC &66 ; sine_result &36f1 85 66 STA &66 ; line_end_x &36f3 a5 1d LDA &1d ; centre_x_high &36f5 65 67 ADC &67 ; sine_result_high &36f7 85 67 STA &67 ; line_end_x_high &36f9 a5 1e LDA &1e ; centre_y &36fb 18 CLC &36fc 65 68 ADC &68 ; cosine_result &36fe 85 68 STA &68 ; line_end_y &3700 a5 1f LDA &1f ; centre_y_high &3702 65 69 ADC &69 ; cosine_result_high &3704 85 69 STA &69 ; line_end_y_high &3706 60 RTS ; multiply_eight_bit_value_by_sine_or_cosine # Called with A = sine or cosine value from table &3707 48 PHA ; sign or cosine &3708 29 01 AND #&01 # Lowest bit set if negative &370a 85 7f STA &7f ; sign_of_sine_or_cosine &370c 68 PLA ; sign or cosine &370d 29 fe AND #&fe &370f 85 70 STA &70 ; multiplicand &3711 a5 7e LDA &7e ; value &3713 85 72 STA &72 ; multiplier &3715 4c 9c 39 JMP &399c ; multiply_eight_bits_by_eight_bits # Returns result = multiplicand * multiplier ; calculate_eight_bit_value_times_sine_X # Called with X = angle &3718 20 6a 37 JSR &376a ; set_value_sign_and_make_absolute &371b a9 00 LDA #&00 &371d 85 7f STA &7f ; sign_of_sine_or_cosine # Unnecessary code; set at &370a &371f bd 00 49 LDA &4900,X ; sine_table &3722 20 07 37 JSR &3707 ; multiply_eight_bit_value_by_sine_or_cosine &3725 a5 7f LDA &7f ; sign_of_sine_or_cosine &3727 f0 08 BEQ &3731 ; is_positive_sign ; is_negative_sine &3729 a9 00 LDA #&00 &372b 38 SEC &372c e5 79 SBC &79 ; result &372e 4c 33 37 JMP &3733 ; set_sine_result ; is_positive_sign &3731 a5 79 LDA &79 ; result ; set_sine_result &3733 85 66 STA &66 ; sine_result &3735 a5 7d LDA &7d ; value_sign &3737 f0 07 BEQ &3740 ; skip_inversion &3739 a9 00 LDA #&00 &373b 38 SEC &373c e5 66 SBC &66 ; sine_result &373e 85 66 STA &66 ; sine_result ; skip_inversion &3740 60 RTS ; calculate_eight_bit_value_times_cosine_X # Called with X = angle &3741 20 6a 37 JSR &376a ; set_value_sign_and_make_absolute &3744 a9 00 LDA #&00 &3746 85 7f STA &7f ; sign_of_sine_or_cosine # Unnecessary code; set at &370a &3748 bd 40 49 LDA &4940,X ; cosine_table &374b 20 07 37 JSR &3707 ; multiply_eight_bit_value_by_sine_or_cosine &374e a5 7f LDA &7f ; sign_of_sine_or_cosine &3750 f0 08 BEQ &375a ; is_positive_cosine ; is_negative_cosine &3752 a9 00 LDA #&00 &3754 38 SEC &3755 e5 79 SBC &79 ; result &3757 4c 5c 37 JMP &375c ; set_cosine_result ; is_positive_cosine &375a a5 79 LDA &79 ; result ; set_cosine_result &375c 85 68 STA &68 ; cosine_result &375e a5 7d LDA &7d ; value_sign &3760 f0 07 BEQ &3769 ; skip_inversion &3762 a9 00 LDA #&00 &3764 38 SEC &3765 e5 68 SBC &68 ; cosine_result &3767 85 68 STA &68 ; cosine_result ; skip_inversion &3769 60 RTS ; set_value_sign_and_make_absolute &376a a9 00 LDA #&00 &376c 85 7d STA &7d ; value_sign &376e a5 7e LDA &7e ; value &3770 10 15 BPL &3787 ; is_positive_value ; is_negative_value &3772 e6 7d INC &7d ; value_sign &3774 a9 00 LDA #&00 &3776 38 SEC &3777 e5 7e SBC &7e ; value &3779 85 7e STA &7e ; value &377b a5 79 LDA &79 ; result # Unnecessary code &377d 85 66 STA &66 ; sine_result # &377f a5 7a LDA &7a ; result_high # &3781 85 67 STA &67 ; sine_result_high # &3783 a5 7b LDA &7b ; unused # &3785 85 0a STA &0a ; line_delta_x # ; is_positive_value &3787 60 RTS ; calculate_sixteen_bit_value_times_sine_X &3788 20 eb 37 JSR &37eb ; set_sign_from_value_and_make_absolute &378b bd 00 49 LDA &4900,X ; sine_table &378e 20 d0 37 JSR &37d0 ; multiply_sixteen_bit_value_by_sine_or_cosine &3791 a5 7c LDA &7c ; sign &3793 10 0e BPL &37a3 ; is_positive_sine ; is_negative_sine &3795 a9 00 LDA #&00 &3797 38 SEC &3798 e5 79 SBC &79 ; result &379a 85 66 STA &66 ; sine_result &379c a9 00 LDA #&00 &379e e5 7a SBC &7a ; result_high &37a0 85 67 STA &67 ; sine_result_high &37a2 60 RTS ; is_positive_sine &37a3 a5 79 LDA &79 ; result &37a5 85 66 STA &66 ; sine_result &37a7 a5 7a LDA &7a ; result_high &37a9 85 67 STA &67 ; sine_result_high &37ab 60 RTS ; calculate_sixteen_bit_value_times_cosine_X &37ac 20 eb 37 JSR &37eb ; set_sign_from_value_and_make_absolute &37af bd 40 49 LDA &4940,X ; cosine_table &37b2 20 d0 37 JSR &37d0 ; multiply_sixteen_bit_value_by_sine_or_cosine &37b5 a5 7c LDA &7c ; sign &37b7 10 0e BPL &37c7 ; is_positive_cosine ; is_negative_cosine &37b9 a9 00 LDA #&00 &37bb 38 SEC &37bc e5 79 SBC &79 ; result &37be 85 68 STA &68 ; cosine_result &37c0 a9 00 LDA #&00 &37c2 e5 7a SBC &7a ; result_high &37c4 85 69 STA &69 ; cosine_result_high &37c6 60 RTS ; is_positive_cosine &37c7 a5 79 LDA &79 ; result &37c9 85 68 STA &68 ; cosine_result &37cb a5 7a LDA &7a ; result_high &37cd 85 69 STA &69 ; cosine_result_high &37cf 60 RTS ; multiply_sixteen_bit_value_by_sine_or_cosine # Called with A = sine or cosine value from table &37d0 48 PHA ; sine or cosine &37d1 29 01 AND #&01 # Lowest bit set if negative &37d3 f0 06 BEQ &37db ; skip_inversion &37d5 a5 7c LDA &7c ; sign &37d7 49 80 EOR #&80 &37d9 85 7c STA &7c ; sign ; skip_inversion &37db a5 7d LDA &7d ; value_low &37dd 85 70 STA &70 ; multiplicand &37df a5 7e LDA &7e ; value_high &37e1 85 71 STA &71 ; multiplicand_high &37e3 68 PLA ; sine or cosine &37e4 29 fe AND #&fe &37e6 85 73 STA &73 ; multiplier &37e8 4c d2 35 JMP &35d2 ; multiply_sixteen_bits_by_eight_bits ; set_sign_from_value_and_make_absolute &37eb a5 7e LDA &7e ; value_high &37ed 85 7c STA &7c ; sign &37ef 10 0d BPL &37fe ; is_positive ; is_negative &37f1 a9 00 LDA #&00 &37f3 38 SEC &37f4 e5 7d SBC &7d ; value_low &37f6 85 7d STA &7d ; value_low &37f8 a9 00 LDA #&00 &37fa e5 7e SBC &7e ; value_high &37fc 85 7e STA &7e ; value_high ; is_positive &37fe 60 RTS ; rnd &37ff 86 5c STX &5c ; tmp_x &3801 84 5d STY &5d ; tmp_y &3803 a0 04 LDY #&04 ; rotate_rnd_state_loop &3805 18 CLC &3806 ad 33 38 LDA &3833 ; rnd_state + 3 &3809 10 0e BPL &3819 ; skip_perturbing_rnd_state &380b a2 02 LDX #&02 ; perturb_rnd_state_loop &380d bd 30 38 LDA &3830,X ; rnd_state &3810 49 53 EOR #&53 &3812 9d 30 38 STA &3830,X ; rnd_state &3815 ca DEX &3816 10 f5 BPL &380d ; perturb_rnd_state_loop &3818 38 SEC ; skip_perturbing_rnd_state &3819 2e 30 38 ROL &3830 ; rnd_state &381c 2e 31 38 ROL &3831 ; rnd_state + 1 &381f 2e 32 38 ROL &3832 ; rnd_state + 2 &3822 2e 33 38 ROL &3833 ; rnd_state + 3 &3825 88 DEY &3826 d0 dd BNE &3805 ; rotate_rnd_state_loop &3828 a6 5c LDX &5c ; tmp_x &382a a4 5d LDY &5d ; tmp_y &382c ad 33 38 LDA &3833 ; rnd_state + 3 &382f 60 RTS ; rnd_state &3830 1f 45 82 e3 ; calculate_screen_position_for_origin &3834 a5 50 LDA &50 ; origin_x &3836 85 40 STA &40 ; point_x &3838 a5 51 LDA &51 ; origin_x_high &383a 85 41 STA &41 ; point_x_high &383c a5 52 LDA &52 ; origin_y &383e 85 43 STA &43 ; point_y &3840 a5 53 LDA &53 ; origin_y_high &3842 85 44 STA &44 ; point_y_high &3844 a5 54 LDA &54 ; origin_z &3846 85 46 STA &46 ; point_z &3848 a5 55 LDA &55 ; origin_z_high &384a 85 47 STA &47 ; point_z_high ; calculate_screen_position_for_point &384c a9 00 LDA #&00 &384e 85 10 STA &10 ; negative_x &3850 85 11 STA &11 ; negative_y &3852 a5 41 LDA &41 ; point_x_high &3854 10 0f BPL &3865 ; skip_inverting_x &3856 85 10 STA &10 ; negative_x # Set to negative to indicate point_x was negative &3858 a9 00 LDA #&00 &385a 38 SEC &385b e5 40 SBC &40 ; point_x # Make point_x temporarily positive &385d 85 40 STA &40 ; point_x &385f a9 00 LDA #&00 &3861 e5 41 SBC &41 ; point_x_high &3863 85 41 STA &41 ; point_x_high ; skip_inverting_x &3865 a5 44 LDA &44 ; point_y_high &3867 10 0f BPL &3878 ; skip_inverting_y &3869 85 11 STA &11 ; negative_y # Set to negative to indicate point_y was negative &386b a9 00 LDA #&00 &386d 38 SEC &386e e5 43 SBC &43 ; point_y # Make point_y temporarily positive &3870 85 43 STA &43 ; point_y &3872 a9 00 LDA #&00 &3874 e5 44 SBC &44 ; point_y_high &3876 85 44 STA &44 ; point_y_high ; skip_inverting_y &3878 a5 46 LDA &46 ; point_z &387a 85 2e STA &2e ; divisor &387c a5 47 LDA &47 ; point_z_high &387e 85 2f STA &2f ; divisor_high &3880 a5 41 LDA &41 ; point_x_high &3882 85 2d STA &2d ; dividend_high &3884 a5 40 LDA &40 ; point_x &3886 85 2c STA &2c ; dividend &3888 20 69 36 JSR &3669 ; divide_dividend_by_divisor # result = point_x / point_z &388b 46 79 LSR &79 ; result &388d 66 78 ROR &78 ; result_fraction &388f a5 10 LDA &10 ; negative_x &3891 10 0d BPL &38a0 ; skip_inverting_x_result # Negative if point_x was negative &3893 a9 00 LDA #&00 &3895 38 SEC &3896 e5 78 SBC &78 ; result_fraction # If so, restore original sign &3898 85 78 STA &78 ; result_fraction &389a a9 00 LDA #&00 &389c e5 79 SBC &79 ; result &389e 85 79 STA &79 ; result ; skip_inverting_x_result &38a0 a5 78 LDA &78 ; result_fraction &38a2 18 CLC &38a3 69 40 ADC #&40 &38a5 85 66 STA &66 ; screen_x # screen_x = ((point_x / point_z) / 2) + &40 &38a7 a5 79 LDA &79 ; result &38a9 69 00 ADC #&00 &38ab 85 67 STA &67 ; screen_x_high &38ad a5 44 LDA &44 ; point_y_high &38af 85 2d STA &2d ; dividend_high &38b1 a5 43 LDA &43 ; point_y &38b3 85 2c STA &2c ; dividend &38b5 a5 46 LDA &46 ; point_z &38b7 85 2e STA &2e ; divisor &38b9 a5 47 LDA &47 ; point_z_high &38bb 85 2f STA &2f ; divisor_high &38bd 20 69 36 JSR &3669 ; divide_dividend_by_divisor # result = point_y / point_z &38c0 a5 11 LDA &11 ; negative_y &38c2 10 0d BPL &38d1 ; skip_inverting_y_result # Negative if point_y was negative &38c4 a9 00 LDA #&00 &38c6 38 SEC &38c7 e5 78 SBC &78 ; result_fraction # If so, restore original sign &38c9 85 78 STA &78 ; result_fraction &38cb a9 00 LDA #&00 &38cd e5 79 SBC &79 ; result &38cf 85 79 STA &79 ; result ; skip_inverting_y_result &38d1 a5 78 LDA &78 ; result_fraction &38d3 18 CLC &38d4 69 50 ADC #&50 &38d6 85 68 STA &68 ; screen_y # screen_y = ((point_y / point_z) / 2) + &50 &38d8 a5 79 LDA &79 ; result &38da 69 00 ADC #&00 &38dc 85 69 STA &69 ; screen_y_high &38de 60 RTS ; calculate_screen_x_for_point &38df a9 00 LDA #&00 &38e1 85 10 STA &10 ; negative_x &38e3 a5 41 LDA &41 ; point_x_high &38e5 10 0f BPL &38f6 ; skip_inverting_x &38e7 85 10 STA &10 ; negative_x &38e9 a9 00 LDA #&00 &38eb 38 SEC &38ec e5 40 SBC &40 ; point_x &38ee 85 40 STA &40 ; point_x &38f0 a9 00 LDA #&00 &38f2 e5 41 SBC &41 ; point_x_high &38f4 85 41 STA &41 ; point_x_high ; skip_inverting_x &38f6 a5 46 LDA &46 ; point_z &38f8 85 2e STA &2e ; divisor &38fa a5 47 LDA &47 ; point_z_high &38fc 85 2f STA &2f ; divisor_high &38fe a5 41 LDA &41 ; point_x_high &3900 85 2d STA &2d ; dividend_high &3902 a5 40 LDA &40 ; point_x &3904 85 2c STA &2c ; dividend &3906 20 69 36 JSR &3669 ; divide_dividend_by_divisor &3909 46 79 LSR &79 ; result &390b 66 78 ROR &78 ; result_fraction &390d a5 10 LDA &10 ; negative_x &390f 10 0d BPL &391e ; skip_inverting_result &3911 a9 00 LDA #&00 &3913 38 SEC &3914 e5 78 SBC &78 ; result_fraction &3916 85 78 STA &78 ; result_fraction &3918 a9 00 LDA #&00 &391a e5 79 SBC &79 ; result &391c 85 79 STA &79 ; result ; skip_inverting_result &391e a5 78 LDA &78 ; result_fraction &3920 18 CLC &3921 69 40 ADC #&40 &3923 85 66 STA &66 ; screen_x &3925 a5 79 LDA &79 ; result &3927 69 00 ADC #&00 &3929 85 67 STA &67 ; screen_x_high &392b 60 RTS ; calculate_screen_y_for_point &392c a9 00 LDA #&00 &392e 85 11 STA &11 ; negative_y &3930 a5 44 LDA &44 ; point_y_high &3932 10 0f BPL &3943 ; skip_inverting_y &3934 85 11 STA &11 ; negative_y &3936 a9 00 LDA #&00 &3938 38 SEC &3939 e5 43 SBC &43 ; point_y &393b 85 43 STA &43 ; point_y &393d a9 00 LDA #&00 &393f e5 44 SBC &44 ; point_y_high &3941 85 44 STA &44 ; point_y_high ; skip_inverting_y &3943 a5 46 LDA &46 ; point_z &3945 85 2e STA &2e ; divisor &3947 a5 47 LDA &47 ; point_z_high &3949 85 2f STA &2f ; divisor_high &394b a5 44 LDA &44 ; point_y_high &394d 85 2d STA &2d ; dividend_high &394f a5 43 LDA &43 ; point_y &3951 85 2c STA &2c ; dividend &3953 20 69 36 JSR &3669 ; divide_dividend_by_divisor &3956 a5 11 LDA &11 ; negative_y &3958 10 0d BPL &3967 ; skip_inverting_result &395a a9 00 LDA #&00 &395c 38 SEC &395d e5 78 SBC &78 ; result_fraction &395f 85 78 STA &78 ; result_fraction &3961 a9 00 LDA #&00 &3963 e5 79 SBC &79 ; result &3965 85 79 STA &79 ; result ; skip_inverting_result &3967 a5 78 LDA &78 ; result_fraction &3969 18 CLC &396a 69 50 ADC #&50 &396c 85 68 STA &68 ; screen_y &396e a5 79 LDA &79 ; result &3970 69 00 ADC #&00 &3972 85 69 STA &69 ; screen_y_high &3974 60 RTS ; divide_point_x_by_point_z_times_two &3975 a5 46 LDA &46 ; point_z &3977 85 2e STA &2e ; divisor &3979 a5 47 LDA &47 ; point_z_high &397b 85 2f STA &2f ; divisor_high &397d a5 41 LDA &41 ; point_x_high &397f 85 2d STA &2d ; dividend_high &3981 a5 40 LDA &40 ; point_x &3983 85 2c STA &2c ; dividend &3985 20 69 36 JSR &3669 ; divide_dividend_by_divisor &3988 46 79 LSR &79 ; result &398a 66 78 ROR &78 ; result_fraction &398c 60 RTS ; check_for_keypress &398d a9 81 LDA #&81 ; Scan for a particular key &398f a0 ff LDY #&ff &3991 20 f4 ff JSR &fff4 ; OSBYTE &3994 c0 ff CPY #&ff &3996 60 RTS ; keys # Values are overwritten ; key_left &3997 99 ; < ; key_right &3998 98 ; > ; key_down &3999 ae ; S ; key_up &399a bd ; X ; key_fire &399b be ; A ; multiply_eight_bits_by_eight_bits &399c 84 5f STY &5f ; tmp_y &399e a0 07 LDY #&07 &39a0 a9 00 LDA #&00 ; multiply_eight_bits_by_eight_bits_loop &39a2 66 72 ROR &72 ; multiplier &39a4 90 02 BCC &39a8 ; skip_addition &39a6 65 70 ADC &70 ; multiplicand ; skip_addition &39a8 6a ROR A &39a9 88 DEY &39aa 10 f6 BPL &39a2 ; multiply_eight_bits_by_eight_bits_loop &39ac a4 5f LDY &5f ; tmp_y &39ae 85 79 STA &79 ; result &39b0 60 RTS ; star_wars_string &39b1 60 09 0f 09 ; at + &0960, colour &0f (C), length &09 &39b5 53 54 41 52 20 57 41 52 53 ; "STAR WARS" ; select_starting_wave_string &39be 08 0b 0f 1d ; at + &0b08, colour &0f (C), length &1d &39c2 53 45 4c 45 43 54 20 53 54 41 52 54 49 4e 47 20 ; "SELECT STARTING WAVE:1,3 OR 5" &39d2 57 41 56 45 3a 31 2c 33 20 4f 52 20 35 ; plot_player &39df ad 13 03 LDA &0313 ; player_x &39e2 38 SEC &39e3 e9 08 SBC #&08 &39e5 aa TAX &39e6 ad 14 03 LDA &0314 ; player_y &39e9 18 CLC &39ea 69 07 ADC #&07 &39ec a8 TAY &39ed b9 40 4a LDA &4a40,Y ; buffer_row_addresses_low_table # Calculate screen address for player &39f0 18 CLC &39f1 7d 00 4d ADC &4d00,X ; column_addresses_low_table &39f4 8d 17 3a STA &3a17 ; player_screen_address_one_low &39f7 8d 1a 3a STA &3a1a ; player_screen_address_two_low &39fa b9 00 4b LDA &4b00,Y ; buffer_one_row_addresses_high_table # actually LDA player_buffer_row_addresses_high_table,Y &39fd 8d 18 3a STA &3a18 ; player_screen_address_one_high &3a00 8d 1b 3a STA &3a1b ; player_screen_address_two_high &3a03 a9 cc LDA #&cc ; &3dcc = player_sprite &3a05 8d 12 3a STA &3a12 ; player_sprite_address_low &3a08 a9 3d LDA #&3d &3a0a 8d 13 3a STA &3a13 ; player_sprite_address_high &3a0d a0 01 LDY #&01 ; plot_player_group_loop &3a0f a2 1f LDX #&1f ; plot_player_byte_loop &3a11 bd cc 3d LDA &3dcc,X ; player_sprite # actually LDA player_sprite_address,X &3a14 29 0f AND #&0f &3a16 1d ff ff ORA &ffff,X # actually ORA player_screen_address_one,X &3a19 9d ff ff STA &ffff,X # actually STA player_screen_address_two,X &3a1c ca DEX &3a1d 10 f2 BPL &3a11 ; plot_player_byte_loop &3a1f ee 18 3a INC &3a18 ; player_screen_address_one_high &3a22 ee 1b 3a INC &3a1b ; player_screen_address_two_high &3a25 ad 12 3a LDA &3a12 ; player_sprite_address_low &3a28 18 CLC &3a29 69 20 ADC #&20 &3a2b 8d 12 3a STA &3a12 ; player_sprite_address_low &3a2e ad 13 3a LDA &3a13 ; player_sprite_address_high &3a31 69 00 ADC #&00 &3a33 8d 13 3a STA &3a13 ; player_sprite_address_high &3a36 88 DEY &3a37 10 d6 BPL &3a0f ; plot_player_group_loop &3a39 60 RTS ; leave_with_negative &3a3a a9 ff LDA #&ff # Leave with negative to indicate model behind player &3a3c 60 RTS ; plot_model_relative_to_player &3a3d 20 9e 3d JSR &3d9e ; calculate_origin_relative_to_player &3a40 a5 51 LDA &51 ; origin_x_high &3a42 8d 11 03 STA &0311 ; model_origin_x_high &3a45 ad af 08 LDA &08af ; stage &3a48 c9 02 CMP #&02 &3a4a d0 09 BNE &3a55 ; not_trench_stage ; is_trench_stage # Unnecessary code; no models plotted in trench stage &3a4c a5 51 LDA &51 ; origin_x_high &3a4e 18 CLC &3a4f 69 10 ADC #&10 &3a51 c9 20 CMP #&20 &3a53 b0 e5 BCS &3a3a ; leave_with_negative # Leave unless -&10 <= x < &0f ; not_trench_stage &3a55 a5 55 LDA &55 ; origin_z_high &3a57 cd 62 3a CMP &3a62 ; maximum_z_high_for_plotting_model &3a5a b0 de BCS &3a3a ; leave_with_negative # Leave with negative if origin is behind player &3a5c 20 0a 32 JSR &320a ; apply_player_rotation_to_origin ; plot_model &3a5f a5 55 LDA &55 ; origin_z_high &3a61 c9 80 CMP #&80 # actually CMP maximum_z_high_for_plotting_model &3a63 b0 d5 BCS &3a3a ; leave_with_negative # Leave with negative if origin is behind player &3a65 a5 51 LDA &51 ; origin_x_high &3a67 49 80 EOR #&80 &3a69 18 CLC &3a6a 69 10 ADC #&10 &3a6c c9 20 CMP #&20 &3a6e 90 ca BCC &3a3a ; leave_with_negative # Leave if &70 <= x_high < &8f &3a70 a5 53 LDA &53 ; origin_y_high &3a72 49 80 EOR #&80 &3a74 18 CLC &3a75 69 10 ADC #&10 &3a77 c9 20 CMP #&20 &3a79 90 bf BCC &3a3a ; leave_with_negative # Leave if &70 <= y_high < &8f &3a7b 20 34 38 JSR &3834 ; calculate_screen_position_for_origin &3a7e a5 66 LDA &66 ; screen_x &3a80 8d 02 03 STA &0302 ; target_x &3a83 a5 67 LDA &67 ; screen_x_high &3a85 8d 03 03 STA &0303 ; target_x_high &3a88 a5 68 LDA &68 ; screen_y &3a8a 8d 04 03 STA &0304 ; target_y &3a8d a5 69 LDA &69 ; screen_y_high &3a8f 8d 05 03 STA &0305 ; target_y_high &3a92 a5 67 LDA &67 ; screen_x_high &3a94 d0 1f BNE &3ab5 ; leave_with_negative &3a96 ad af 08 LDA &08af ; stage &3a99 c9 01 CMP #&01 &3a9b f0 1b BEQ &3ab8 ; is_onscreen # Branch if surface stage ; not_surface_stage &3a9d a5 68 LDA &68 ; screen_y &3a9f 18 CLC &3aa0 69 80 ADC #&80 &3aa2 48 PHA ; screen_y + &80 &3aa3 a5 69 LDA &69 ; screen_y_high &3aa5 69 00 ADC #&00 &3aa7 85 5f STA &5f ; y_high &3aa9 68 PLA ; screen_y + &80 &3aaa 38 SEC &3aab e9 80 SBC #&80 &3aad a5 5f LDA &5f ; y_high &3aaf e9 01 SBC #&01 &3ab1 10 02 BPL &3ab5 ; leave_with_negative # Otherwise, check model is onscreen vertically &3ab3 30 03 BMI &3ab8 ; is_onscreen # Always branches ; leave_with_negative &3ab5 a9 ff LDA #&ff # Leave with negative to indicate model offscreen vertically &3ab7 60 RTS ; is_onscreen &3ab8 a5 cf LDA &cf ; model &3aba 29 0f AND #&0f &3abc aa TAX &3abd bd 20 4e LDA &4e20,X ; models_vertex_data_offset_table &3ac0 18 CLC &3ac1 69 40 ADC #&40 ; &4e40 = vertices_xy_angle_data &3ac3 8d e0 3a STA &3ae0 ; vertices_xy_angle_data_address_low &3ac6 69 40 ADC #&40 ; &4e80 = vertices_xy_distance_data &3ac8 8d eb 3a STA &3aeb ; vertices_xy_distance_data_address_low &3acb 69 40 ADC #&40 ; &4ec0 = vertices_z_data &3acd 8d 8a 3b STA &3b8a ; vertices_z_data_address_low &3ad0 bd 30 4e LDA &4e30,X ; models_line_data_offset_table &3ad3 8d 36 3c STA &3c36 ; model_line_vertex_data_address_low &3ad6 bd 00 4e LDA &4e00,X ; models_number_of_vertices_table &3ad9 29 1f AND #&1f &3adb 85 ce STA &ce ; number_of_vertices &3add a0 00 LDY #&00 ; calculate_vertex_positions_loop # For each vertex used in the model, &3adf b9 40 4e LDA &4e40,Y ; vertices_xy_angle_data # actually LDA vertices_xy_angle_data_address,Y &3ae2 18 CLC &3ae3 65 ca ADC &ca ; model_rotation_about_z # Apply model rotation to angle &3ae5 38 SEC &3ae6 ed bb 08 SBC &08bb ; player_rotation_about_z # Apply player rotation to angle &3ae9 aa TAX &3aea b9 80 4e LDA &4e80,Y ; vertices_xy_distance_data # actually LDA vertices_xy_distance_data_address,Y &3aed 85 7e STA &7e ; value &3aef 20 18 37 JSR &3718 ; calculate_eight_bit_value_times_sine_X # Calculate distance * sin(angle) &3af2 20 41 37 JSR &3741 ; calculate_eight_bit_value_times_cosine_X # Calculate distance * cos(angle) &3af5 a9 00 LDA #&00 &3af7 85 30 STA &30 ; relative_x_high &3af9 85 31 STA &31 ; relative_y_high &3afb 85 32 STA &32 ; relative_z_high &3afd a5 66 LDA &66 ; sine_result &3aff 85 b8 STA &b8 ; relative_x &3b01 10 2a BPL &3b2d ; is_positive_x ; is_negative_x &3b03 a9 00 LDA #&00 # relative_x *= -16 &3b05 38 SEC &3b06 e5 b8 SBC &b8 ; relative_x &3b08 0a ASL A &3b09 26 30 ROL &30 ; relative_x_high &3b0b 0a ASL A &3b0c 26 30 ROL &30 ; relative_x_high &3b0e 0a ASL A &3b0f 26 30 ROL &30 ; relative_x_high &3b11 0a ASL A &3b12 26 30 ROL &30 ; relative_x_high &3b14 ae af 08 LDX &08af ; stage &3b17 f0 03 BEQ &3b1c ; skip_doubling_negative_x # Branch if space stage &3b19 0a ASL A &3b1a 26 30 ROL &30 ; relative_x_high # relative_x *= 2 if not space stage ; skip_doubling_negative_x &3b1c 85 b8 STA &b8 ; relative_x &3b1e a9 00 LDA #&00 &3b20 38 SEC &3b21 e5 b8 SBC &b8 ; relative_x &3b23 85 b8 STA &b8 ; relative_x &3b25 a9 00 LDA #&00 &3b27 e5 30 SBC &30 ; relative_x_high &3b29 85 30 STA &30 ; relative_x_high &3b2b 30 16 BMI &3b43 ; consider_y # Always branches ; is_positive_x &3b2d 0a ASL A # relative_x *= 16 &3b2e 26 30 ROL &30 ; relative_x_high &3b30 0a ASL A &3b31 26 30 ROL &30 ; relative_x_high &3b33 0a ASL A &3b34 26 30 ROL &30 ; relative_x_high &3b36 0a ASL A &3b37 26 30 ROL &30 ; relative_x_high &3b39 ae af 08 LDX &08af ; stage &3b3c f0 03 BEQ &3b41 ; skip_doubling_positive_x # Branch if space stage &3b3e 0a ASL A &3b3f 26 30 ROL &30 ; relative_x_high # relative_x *= 2 if not space stage ; skip_doubling_positive_x &3b41 85 b8 STA &b8 ; relative_x ; consider_y &3b43 a5 68 LDA &68 ; cosine_result &3b45 85 b9 STA &b9 ; relative_y &3b47 10 2a BPL &3b73 ; is_positive_y ; is_negative_y &3b49 a9 00 LDA #&00 # relative_y *= -16 &3b4b 38 SEC &3b4c e5 b9 SBC &b9 ; relative_y &3b4e 0a ASL A &3b4f 26 31 ROL &31 ; relative_y_high &3b51 0a ASL A &3b52 26 31 ROL &31 ; relative_y_high &3b54 0a ASL A &3b55 26 31 ROL &31 ; relative_y_high &3b57 0a ASL A &3b58 26 31 ROL &31 ; relative_y_high &3b5a ae af 08 LDX &08af ; stage &3b5d f0 03 BEQ &3b62 ; skip_doubling_negative_y # Branch if space stage &3b5f 0a ASL A &3b60 26 31 ROL &31 ; relative_y_high # relative_y *= 2 if not space stage ; skip_doubling_negative_y &3b62 85 b9 STA &b9 ; relative_y &3b64 a9 00 LDA #&00 &3b66 38 SEC &3b67 e5 b9 SBC &b9 ; relative_y &3b69 85 b9 STA &b9 ; relative_y &3b6b a9 00 LDA #&00 &3b6d e5 31 SBC &31 ; relative_y_high &3b6f 85 31 STA &31 ; relative_y_high &3b71 30 16 BMI &3b89 ; consider_z # Always branches ; is_positive_y &3b73 0a ASL A # relative_y *= 16 &3b74 26 31 ROL &31 ; relative_y_high &3b76 0a ASL A &3b77 26 31 ROL &31 ; relative_y_high &3b79 0a ASL A &3b7a 26 31 ROL &31 ; relative_y_high &3b7c 0a ASL A &3b7d 26 31 ROL &31 ; relative_y_high &3b7f ae af 08 LDX &08af ; stage &3b82 f0 03 BEQ &3b87 ; skip_doubling_positive_y # Branch if space stage &3b84 0a ASL A &3b85 26 31 ROL &31 ; relative_y_high # relative_y *= 2 if not space stage ; skip_doubling_positive_y &3b87 85 b9 STA &b9 ; relative_y ; consider_z &3b89 b9 c0 4e LDA &4ec0,Y ; vertices_z_data # actually LDA vertices_z_data_address_low,Y &3b8c 85 ba STA &ba ; relative_z &3b8e 10 2a BPL &3bba ; is_negative_z ; is_negative_z &3b90 a9 00 LDA #&00 # relative_z *= -16 &3b92 38 SEC &3b93 e5 ba SBC &ba ; relative_z &3b95 0a ASL A &3b96 26 32 ROL &32 ; relative_z_high &3b98 0a ASL A &3b99 26 32 ROL &32 ; relative_z_high &3b9b 0a ASL A &3b9c 26 32 ROL &32 ; relative_z_high &3b9e 0a ASL A &3b9f 26 32 ROL &32 ; relative_z_high &3ba1 ae af 08 LDX &08af ; stage &3ba4 f0 03 BEQ &3ba9 ; skip_doubling_negative_z # Branch if space stage &3ba6 0a ASL A &3ba7 26 32 ROL &32 ; relative_z_high # relative_z *= 2 if not space stage ; skip_doubling_negative_z &3ba9 85 ba STA &ba ; relative_z &3bab a9 00 LDA #&00 &3bad 38 SEC &3bae e5 ba SBC &ba ; relative_z &3bb0 85 ba STA &ba ; relative_z &3bb2 a9 00 LDA #&00 &3bb4 e5 32 SBC &32 ; relative_z_high &3bb6 85 32 STA &32 ; relative_z_high &3bb8 30 16 BMI &3bd0 ; calculate_vertex_absolute_position # Always branches ; is_positive_z &3bba 0a ASL A # relative_z *= 16 &3bbb 26 32 ROL &32 ; relative_z_high &3bbd 0a ASL A &3bbe 26 32 ROL &32 ; relative_z_high &3bc0 0a ASL A &3bc1 26 32 ROL &32 ; relative_z_high &3bc3 0a ASL A &3bc4 26 32 ROL &32 ; relative_z_high &3bc6 ae af 08 LDX &08af ; stage &3bc9 f0 03 BEQ &3bce ; skip_doubling_positive_z # Branch if space stage &3bcb 0a ASL A &3bcc 26 32 ROL &32 ; relative_z_high # relative_z *= 2 if not space stage ; skip_doubling_positive_z &3bce 85 ba STA &ba ; relative_z ; calculate_vertex_absolute_position &3bd0 a5 b8 LDA &b8 ; relative_x # Add relative position of vertex to model origin &3bd2 18 CLC &3bd3 65 50 ADC &50 ; origin_x &3bd5 85 40 STA &40 ; point_x &3bd7 a5 30 LDA &30 ; relative_x_high &3bd9 65 51 ADC &51 ; origin_x_high &3bdb 85 41 STA &41 ; point_x_high &3bdd a5 b9 LDA &b9 ; relative_y &3bdf 18 CLC &3be0 65 52 ADC &52 ; origin_y &3be2 85 43 STA &43 ; point_y &3be4 a5 31 LDA &31 ; relative_y_high &3be6 65 53 ADC &53 ; origin_y_high &3be8 85 44 STA &44 ; point_y_high &3bea a5 ba LDA &ba ; relative_z &3bec 18 CLC &3bed 65 54 ADC &54 ; origin_z &3bef 85 46 STA &46 ; point_z &3bf1 a5 32 LDA &32 ; relative_z_high &3bf3 65 55 ADC &55 ; origin_z_high &3bf5 85 47 STA &47 ; point_z_high &3bf7 10 0a BPL &3c03 ; is_in_front_of_player ; is_behind_player &3bf9 a9 80 LDA #&80 &3bfb 99 e0 4b STA &4be0,Y ; vertices_screen_x_high # Set to &80 to indicate vertex is behind player &3bfe 99 e0 4c STA &4ce0,Y ; vertices_screen_y_high # Set to &80 to indicate vertex is behind player &3c01 30 17 BMI &3c1a ; skip_calculating_screen_position # Always branches ; is_in_front_of_player &3c03 20 4c 38 JSR &384c ; calculate_screen_position_for_point # Calculate and store screen position for vertex &3c06 a5 66 LDA &66 ; screen_x &3c08 99 c0 4b STA &4bc0,Y ; vertices_screen_x &3c0b a5 67 LDA &67 ; screen_x_high &3c0d 99 e0 4b STA &4be0,Y ; vertices_screen_x_high &3c10 a5 68 LDA &68 ; screen_y &3c12 99 c0 4c STA &4cc0,Y ; vertices_screen_y &3c15 a5 69 LDA &69 ; screen_y_high &3c17 99 e0 4c STA &4ce0,Y ; vertices_screen_y_high ; skip_calculating_screen_position &3c1a c8 INY &3c1b c4 ce CPY &ce ; number_of_vertices &3c1d f0 03 BEQ &3c22 ; finished_calculating_vertices &3c1f 4c df 3a JMP &3adf ; calculate_vertex_positions_loop ; finished_calculating_vertices &3c22 a5 cf LDA &cf ; model &3c24 29 0f AND #&0f &3c26 aa TAX &3c27 bd 10 4e LDA &4e10,X ; models_number_of_lines_table &3c2a 29 3f AND #&3f &3c2c 85 ce STA &ce ; number_of_lines &3c2e a9 7f LDA #&7f &3c30 8d 88 08 STA &0888 ; line_goes_behind_player # Set to positive to indicate line doesn't go behind player &3c33 a0 00 LDY #&00 ; plot_model_loop # For each line in the model, &3c35 b9 00 4f LDA &4f00,Y ; line_vertex_data # actually LDA model_line_vertex_data_address,Y &3c38 48 PHA ; vertex data byte &3c39 29 1f AND #&1f # ...18421 vertex number &3c3b aa TAX &3c3c bd c0 4b LDA &4bc0,X ; vertices_screen_x &3c3f 85 66 STA &66 ; line_end_x &3c41 bd e0 4b LDA &4be0,X ; vertices_screen_x_high &3c44 85 67 STA &67 ; line_end_x_high &3c46 bd c0 4c LDA &4cc0,X ; vertices_screen_y &3c49 85 68 STA &68 ; line_end_y &3c4b bd e0 4c LDA &4ce0,X ; vertices_screen_y_high &3c4e 85 69 STA &69 ; line_end_y_high &3c50 a5 67 LDA &67 ; line_end_x_high # &80 if vertex is behind player &3c52 c9 80 CMP #&80 &3c54 d0 0b BNE &3c61 ; vertex_not_behind_player &3c56 a5 69 LDA &69 ; line_end_y_high # &80 if vertex is behind player &3c58 c9 80 CMP #&80 &3c5a d0 05 BNE &3c61 ; vertex_not_behind_player &3c5c a9 81 LDA #&81 &3c5e 8d 88 08 STA &0888 ; line_goes_behind_player # Set to negative to indicate line goes behind player ; vertex_not_behind_player &3c61 ad 88 08 LDA &0888 ; line_goes_behind_player &3c64 10 0a BPL &3c70 ; line_doesn't_go_behind_player &3c66 ce 88 08 DEC &0888 ; line_goes_behind_player # Keep negative if either vertex of line is behind player &3c69 68 PLA ; vertex data byte &3c6a 20 0f 29 JSR &290f ; set_line_start_to_line_end &3c6d 4c a4 3c JMP &3ca4 ; consider_next_line ; line_doesn't_go_behind_player &3c70 68 PLA ; vertex data byte &3c71 29 e0 AND #&e0 # 842..... line colour and detail flag &3c73 d0 06 BNE &3c7b ; consider_drawing_line &3c75 20 0f 29 JSR &290f ; set_line_start_to_line_end # If zero, don't draw a line, but move to next vertex &3c78 4c a4 3c JMP &3ca4 ; consider_next_line ; consider_drawing_line &3c7b 85 5f STA &5f ; line_colour_and_detail_flag &3c7d a5 cf LDA &cf ; model &3c7f 29 07 AND #&07 &3c81 c9 06 CMP #&06 ; MODEL_TIE_FIGHTER_VADER &3c83 f0 1c BEQ &3ca1 ; draw_line_in_current_colour # Draw all lines in Darth Vader's TIE fighter in current colour &3c85 a5 5f LDA &5f ; line_colour_and_detail_flag &3c87 10 0c BPL &3c95 ; draw_line # 8....... detail flag &3c89 a5 55 LDA &55 ; origin_z_high &3c8b c9 60 CMP #&60 &3c8d 90 06 BCC &3c95 ; draw_line # If set, only draw if near &3c8f 20 0f 29 JSR &290f ; set_line_start_to_line_end &3c92 4c a4 3c JMP &3ca4 ; consider_next_line ; draw_line &3c95 a5 5f LDA &5f ; line_colour_and_detail_flag &3c97 29 60 AND #&60 # .42..... line colour &3c99 4a LSR A # .42..... -> ......42 &3c9a 4a LSR A &3c9b 4a LSR A &3c9c 4a LSR A &3c9d 4a LSR A &3c9e 20 ab 23 JSR &23ab ; set_colour ; draw_line_in_current_colour &3ca1 20 db 23 JSR &23db ; plot_line ; consider_next_line &3ca4 c8 INY &3ca5 c4 ce CPY &ce ; number_of_lines &3ca7 d0 8c BNE &3c35 ; plot_model_loop &3ca9 a9 00 LDA #&00 # Leave with positive to indicate model not behind player &3cab 60 RTS ; game_over_screen &3cac a9 bf LDA #&bf ; game_over_string &3cae 85 18 STA &18 ; text_address_low &3cb0 a9 3c LDA #&3c &3cb2 85 19 STA &19 ; text_address_high &3cb4 20 88 2d JSR &2d88 ; plot_string # Plot "GAME OVER" &3cb7 a2 00 LDX #&00 ; K &3cb9 20 8e 2e JSR &2e8e ; set_colour_zero_to_X # Restore background to black &3cbc 4c 09 04 JMP &0409 ; title_screen ; game_over_string &3cbf 60 07 f0 09 ; at + &0760, colour &f0 (R), length &09 &3cc3 47 41 4d 45 20 4f 56 45 52 ; "GAME OVER" ; apply_player_velocity_to_tie_fighters &3ccc a2 02 LDX #&02 ; apply_player_velocity_to_tie_fighters_loop # For each TIE fighter, &3cce a9 10 LDA #&10 &3cd0 85 73 STA &73 ; multiplier &3cd2 bd e1 15 LDA &15e1,X ; tie_fighters_z &3cd5 85 70 STA &70 ; multiplicand &3cd7 bc e5 15 LDY &15e5,X ; tie_fighters_z_high &3cda 84 71 STY &71 ; multiplicand_high &3cdc 20 d2 35 JSR &35d2 ; multiply_sixteen_bits_by_eight_bits # Returns result = tie_fighters_z * 16 &3cdf ad a1 08 LDA &08a1 ; player_x_velocity_high &3ce2 0d a0 08 ORA &08a0 ; player_x_velocity &3ce5 f0 27 BEQ &3d0e ; skip_moving_in_x &3ce7 10 14 BPL &3cfd ; move_tie_fighters_right ; move_tie_fighters_left &3ce9 bd d1 15 LDA &15d1,X ; tie_fighters_x &3cec 38 SEC &3ced e5 79 SBC &79 ; result &3cef 9d d1 15 STA &15d1,X ; tie_fighters_x &3cf2 bd d5 15 LDA &15d5,X ; tie_fighters_x_high &3cf5 e5 7a SBC &7a ; result_high &3cf7 9d d5 15 STA &15d5,X ; tie_fighters_x_high &3cfa 4c 0e 3d JMP &3d0e ; skip_moving_in_x ; move_tie_fighters_right &3cfd bd d1 15 LDA &15d1,X ; tie_fighters_x &3d00 18 CLC &3d01 65 79 ADC &79 ; result &3d03 9d d1 15 STA &15d1,X ; tie_fighters_x &3d06 bd d5 15 LDA &15d5,X ; tie_fighters_x_high &3d09 65 7a ADC &7a ; result_high &3d0b 9d d5 15 STA &15d5,X ; tie_fighters_x_high ; skip_moving_in_x &3d0e ad a3 08 LDA &08a3 ; player_y_velocity_high &3d11 0d a2 08 ORA &08a2 ; player_y_velocity &3d14 f0 27 BEQ &3d3d ; skip_moving_in_y &3d16 10 14 BPL &3d2c ; move_tie_fighters_up ; move_tie_fighters_down &3d18 bd d9 15 LDA &15d9,X ; tie_fighters_y &3d1b 38 SEC &3d1c e5 79 SBC &79 ; result &3d1e 9d d9 15 STA &15d9,X ; tie_fighters_y &3d21 bd dd 15 LDA &15dd,X ; tie_fighters_y_high &3d24 e5 7a SBC &7a ; result_high &3d26 9d dd 15 STA &15dd,X ; tie_fighters_y_high &3d29 4c 3d 3d JMP &3d3d ; skip_moving_in_y ; move_tie_fighters_up &3d2c bd d9 15 LDA &15d9,X ; tie_fighters_y &3d2f 18 CLC &3d30 65 79 ADC &79 ; result &3d32 9d d9 15 STA &15d9,X ; tie_fighters_y &3d35 bd dd 15 LDA &15dd,X ; tie_fighters_y_high &3d38 65 7a ADC &7a ; result_high &3d3a 9d dd 15 STA &15dd,X ; tie_fighters_y_high ; skip_moving_in_y &3d3d ca DEX &3d3e 10 8e BPL &3cce ; apply_player_velocity_to_tie_fighters &3d40 60 RTS ; consider_firing &3d41 a9 00 LDA #&00 &3d43 8d 00 03 STA &0300 ; player_is_firing # Set to zero to indicate player is not firing &3d46 ae 9b 39 LDX &399b ; key_fire &3d49 20 8d 39 JSR &398d ; check_for_keypress &3d4c d0 39 BNE &3d87 ; leave &3d4e a9 18 LDA #&18 &3d50 20 de 44 JSR &44de ; play_sound # Play sound for firing &3d53 a9 ff LDA #&ff &3d55 8d 00 03 STA &0300 ; player_is_firing # Set to negative non-zero to indicate player is firing &3d58 a9 01 LDA #&01 ; C &3d5a 20 ab 23 JSR &23ab ; set_colour &3d5d ad 13 03 LDA &0313 ; player_x &3d60 85 66 STA &66 ; line_end_x &3d62 ad 14 03 LDA &0314 ; player_y &3d65 85 68 STA &68 ; line_end_y &3d67 ad ad 08 LDA &08ad ; player_firing_side &3d6a 49 80 EOR #&80 # Alternate which side the player fires from &3d6c 8d ad 08 STA &08ad ; player_firing_side &3d6f 10 17 BPL &3d88 ; fire_from_right ; fire_from_left &3d71 a9 08 LDA #&08 &3d73 85 62 STA &62 ; line_start_x &3d75 a9 4d LDA #&4d &3d77 85 64 STA &64 ; line_start_y &3d79 20 d1 23 JSR &23d1 ; plot_onscreen_line # Plot top left firing line &3d7c a9 08 LDA #&08 &3d7e 85 66 STA &66 ; line_end_x &3d80 a9 0a LDA #&0a &3d82 85 68 STA &68 ; line_end_y &3d84 20 d1 23 JSR &23d1 ; plot_onscreen_line # Plot bottom left firing line ; leave &3d87 60 RTS ; fire_from_right &3d88 a9 77 LDA #&77 &3d8a 85 62 STA &62 ; line_start_x &3d8c a9 4d LDA #&4d &3d8e 85 64 STA &64 ; line_start_y &3d90 20 d1 23 JSR &23d1 ; plot_onscreen_line # Plot top right firing line &3d93 a9 78 LDA #&78 &3d95 85 66 STA &66 ; line_end_x &3d97 a9 0a LDA #&0a &3d99 85 68 STA &68 ; line_end_y &3d9b 4c d1 23 JMP &23d1 ; plot_onscreen_line # Plot bottom right firing line ; calculate_origin_relative_to_player &3d9e a5 50 LDA &50 ; origin_x &3da0 38 SEC &3da1 ed b4 08 SBC &08b4 ; player_x &3da4 85 50 STA &50 ; origin_x &3da6 a5 51 LDA &51 ; origin_x_high &3da8 ed b5 08 SBC &08b5 ; player_x_high &3dab 85 51 STA &51 ; origin_x_high &3dad a5 52 LDA &52 ; origin_y &3daf 38 SEC &3db0 ed b6 08 SBC &08b6 ; player_y &3db3 85 52 STA &52 ; origin_y &3db5 a5 53 LDA &53 ; origin_y_high &3db7 ed b7 08 SBC &08b7 ; player_y_high &3dba 85 53 STA &53 ; origin_y_high &3dbc a5 54 LDA &54 ; origin_z &3dbe 38 SEC &3dbf ed b8 08 SBC &08b8 ; player_z &3dc2 85 54 STA &54 ; origin_z &3dc4 a5 55 LDA &55 ; origin_z_high &3dc6 ed b9 08 SBC &08b9 ; player_z_high &3dc9 85 55 STA &55 ; origin_z_high &3dcb 60 RTS ; player_sprite &3dcc 11 22 22 44 44 ff 00 00 00 88 88 44 44 22 ee 00 &3ddc 00 11 11 22 22 44 77 00 88 44 44 22 22 ff 00 00 &3dec 00 00 ff 44 44 22 22 11 00 ee 22 44 44 88 88 00 &3dfc 00 77 44 22 22 11 11 00 00 00 ff 22 22 44 44 88 ; wave_one_side_ports_data &3e0c 00 00 00 00 00 00 00 00 22 22 11 22 88 11 11 11 &3e1c 22 22 22 44 88 00 88 88 44 00 44 22 22 11 11 00 &3e2c 22 22 22 44 22 44 00 00 88 00 33 00 33 00 33 00 &3e3c 00 00 88 00 33 00 66 00 cc 00 11 00 00 77 00 00 ; plot_shields &3e4c ad 8d 03 LDA &038d ; shields &3e4f 10 01 BPL &3e52 ; has_shields &3e51 60 RTS ; has_shields &3e52 8a TXA &3e53 48 PHA ; tmp_x &3e54 a9 00 LDA #&00 &3e56 aa TAX ; wipe_shields_loop &3e57 9d 40 50 STA &5040,X ; buffer_one + &100 * 0 + &40 &3e5a 9d 40 51 STA &5140,X ; buffer_one + &100 * 1 + &40 &3e5d 9d 40 52 STA &5240,X ; buffer_one + &100 * 2 + &40 &3e60 9d 40 68 STA &6840,X ; buffer_two + &100 * 0 + &40 &3e63 9d 40 69 STA &6940,X ; buffer_two + &100 * 1 + &40 &3e66 9d 40 6a STA &6a40,X ; buffer_two + &100 * 2 + &40 &3e69 e8 INX &3e6a 10 eb BPL &3e57 ; wipe_shields_loop &3e6c ad 8d 03 LDA &038d ; shields &3e6f d0 03 BNE &3e74 ; has_shields &3e71 4c 61 3f JMP &3f61 ; plot_shields_gone ; has_shields &3e74 aa TAX &3e75 bd f2 4f LDA &4ff2,X ; shields_y &3e78 85 57 STA &57 ; shield_y &3e7a bd 70 4f LDA &4f70,X ; shields_colours &3e7d 20 ab 23 JSR &23ab ; set_colour &3e80 bd 77 4f LDA &4f77,X ; shields_pixel_values &3e83 85 1a STA &1a ; colour_pixel_value &3e85 a9 bf LDA #&bf &3e87 8d d0 23 STA &23d0 ; maximum_row # Allow plotting in status area &3e8a a2 01 LDX #&01 ; plot_shields_buffer_loop &3e8c 8a TXA &3e8d 48 PHA ; buffer &3e8e ad 8d 03 LDA &038d ; shields &3e91 0a ASL A &3e92 0a ASL A &3e93 85 5f STA &5f ; width &3e95 a9 40 LDA #&40 &3e97 38 SEC &3e98 e5 5f SBC &5f ; width &3e9a 85 62 STA &62 ; line_start_x &3e9c 85 58 STA &58 ; left_shield_x &3e9e 48 PHA &3e9f a9 40 LDA #&40 &3ea1 18 CLC &3ea2 65 5f ADC &5f ; width &3ea4 85 66 STA &66 ; line_end_x &3ea6 85 59 STA &59 ; right_shield_x &3ea8 a9 be LDA #&be &3eaa 85 64 STA &64 ; line_start_y &3eac 85 68 STA &68 ; line_end_y &3eae 20 d1 23 JSR &23d1 ; plot_onscreen_line # Plot horizontal line from left to right &3eb1 a5 62 LDA &62 ; line_start_x &3eb3 85 66 STA &66 ; line_end_x &3eb5 a5 57 LDA &57 ; shield_y &3eb7 85 68 STA &68 ; line_end_y &3eb9 20 d1 23 JSR &23d1 ; plot_onscreen_line # Plot right vertical line &3ebc a9 40 LDA #&40 &3ebe 85 66 STA &66 ; line_end_x &3ec0 a9 be LDA #&be &3ec2 85 68 STA &68 ; line_end_y &3ec4 20 d1 23 JSR &23d1 ; plot_onscreen_line # Plot right diagonal line &3ec7 68 PLA &3ec8 85 66 STA &66 ; line_end_x &3eca a5 57 LDA &57 ; shield_y &3ecc 85 68 STA &68 ; line_end_y &3ece 20 d1 23 JSR &23d1 ; plot_onscreen_line # Plot left diagonal line &3ed1 a5 62 LDA &62 ; line_start_x &3ed3 85 66 STA &66 ; line_end_x &3ed5 a9 be LDA #&be &3ed7 85 68 STA &68 ; line_end_y &3ed9 20 d1 23 JSR &23d1 ; plot_onscreen_line # Plot left vertical line &3edc ad 8d 03 LDA &038d ; shields &3edf c9 04 CMP #&04 &3ee1 90 1f BCC &3f02 ; has_less_than_four_shields ; has_four_or_more_shields &3ee3 a9 be LDA #&be &3ee5 85 64 STA &64 ; line_start_y &3ee7 a9 34 LDA #&34 &3ee9 85 62 STA &62 ; line_start_x &3eeb 85 66 STA &66 ; line_end_x &3eed ad f5 4f LDA &4ff5 ; shields_y + 3 &3ef0 85 68 STA &68 ; line_end_y &3ef2 20 d1 23 JSR &23d1 ; plot_onscreen_line # Plot right vertical line at four shields &3ef5 a9 4c LDA #&4c &3ef7 85 62 STA &62 ; line_start_x &3ef9 85 66 STA &66 ; line_end_x &3efb a9 be LDA #&be &3efd 85 68 STA &68 ; line_end_y &3eff 20 d1 23 JSR &23d1 ; plot_onscreen_line # Plot left vertical line at four shields ; has_less_than_four_shields &3f02 a9 60 LDA #&60 &3f04 85 16 STA &16 ; text_screen_offset_low &3f06 a9 02 LDA #&02 &3f08 85 17 STA &17 ; text_screen_offset_high &3f0a a9 73 LDA #&73 ; &3f73 = shields_string &3f0c 85 18 STA &18 ; text_address_low &3f0e a9 3f LDA #&3f &3f10 85 19 STA &19 ; text_address_high &3f12 a9 07 LDA #&07 &3f14 20 bf 2d JSR &2dbf ; plot_string_from_variables # Plot "SHIELDS" &3f17 a9 78 LDA #&78 &3f19 85 16 STA &16 ; text_screen_offset_low &3f1b a9 01 LDA #&01 &3f1d 85 17 STA &17 ; text_screen_offset_high &3f1f ad 8d 03 LDA &038d ; shields &3f22 20 30 2e JSR &2e30 ; plot_two_digit_number # Plot number of shields remaining &3f25 a6 58 LDX &58 ; left_shield_x ; plot_shields_shield_loop &3f27 8a TXA &3f28 48 PHA ; left_shield_x &3f29 a6 59 LDX &59 ; right_shield_x &3f2b a0 bd LDY #&bd &3f2d 20 23 29 JSR &2923 ; plot_pixel # Plot right shield notch &3f30 88 DEY &3f31 20 23 29 JSR &2923 ; plot_pixel &3f34 8a TXA &3f35 38 SEC &3f36 e9 04 SBC #&04 &3f38 85 59 STA &59 ; right_shield_x &3f3a 68 PLA ; left_shield_x &3f3b aa TAX &3f3c a0 bd LDY #&bd &3f3e 20 23 29 JSR &2923 ; plot_pixel # Plot left shield notch &3f41 88 DEY &3f42 20 23 29 JSR &2923 ; plot_pixel &3f45 8a TXA &3f46 18 CLC &3f47 69 04 ADC #&04 &3f49 aa TAX &3f4a e0 40 CPX #&40 &3f4c d0 d9 BNE &3f27 ; plot_shields_shield_loop &3f4e 20 6c 2e JSR &2e6c ; use_other_buffer &3f51 68 PLA ; buffer &3f52 aa TAX &3f53 ca DEX &3f54 30 03 BMI &3f59 ; finished_plotting_shields &3f56 4c 8c 3e JMP &3e8c ; plot_shields_buffer_loop ; finished_plotting_shields &3f59 a9 9f LDA #&9f &3f5b 8d d0 23 STA &23d0 ; maximum_row # Prevent plotting in status area &3f5e 68 PLA ; tmp_x &3f5f aa TAX &3f60 60 RTS ; plot_shields_gone &3f61 a9 6f LDA #&6f ; &3f6f = shields_gone_string &3f63 85 18 STA &18 ; text_address_low &3f65 a9 3f LDA #&3f &3f67 85 19 STA &19 ; text_address_high &3f69 20 88 2d JSR &2d88 ; plot_string # Plot "SHIELDS GONE" &3f6c 68 PLA ; tmp_x &3f6d aa TAX &3f6e 60 RTS ; shields_gone_string &3f6f 50 01 f0 0c ; at + &0150, colour &f0 (R), length &0c ; shields_string &4f73 53 48 49 45 4c 44 53 20 47 4f 4e 45 ; "SHIELDS GONE" ; update_tie_fighters &3f7f a9 03 LDA #&03 ; G # Plot TIE fighters in green by default &3f81 8d b1 41 STA &41b1 ; tie_fighter_colour &3f84 ad ab 08 LDA &08ab ; vader_tie_fighter_hit_cooldown # Positive if Darth Vader's TIE fighter recently hit &3f87 30 08 BMI &3f91 ; skip_changing_colour &3f89 a9 01 LDA #&01 ; C &3f8b 8d b1 41 STA &41b1 ; tie_fighter_colour # If so, plot in cyan &3f8e ce ab 08 DEC &08ab ; vader_tie_fighter_hit_cooldown ; skip_changing_colour &3f91 a2 02 LDX #&02 ; update_tie_fighters_loop # For each TIE fighter, &3f93 8a TXA &3f94 48 PHA ; tie fighter offset &3f95 bd f1 15 LDA &15f1,X ; tie_fighters_state # Negative if TIE fighter is exploding &3f98 30 03 BMI &3f9d ; update_exploding_tie_fighter &3f9a 4c a9 40 JMP &40a9 ; update_tie_fighter ; update_exploding_tie_fighter # If the TIE fighter is exploding, &3f9d bd f1 15 LDA &15f1,X ; tie_fighters_state &3fa0 c9 f8 CMP #&f8 &3fa2 d0 32 BNE &3fd6 ; not_end_of_explosion ; is_end_of_explosion &3fa4 ad b1 08 LDA &08b1 ; frame_count_high &3fa7 c9 02 CMP #&02 &3fa9 b0 28 BCS &3fd3 ; to_consider_next_tie_fighter # Don't replace TIE fighters at end of stage ; replace_tie_fighter &3fab 20 ff 37 JSR &37ff ; rnd &3fae 29 0f AND #&0f &3fb0 38 SEC &3fb1 e9 08 SBC #&08 # -8 to 7 &3fb3 9d d5 15 STA &15d5,X ; tie_fighters_x_high # Set random y position for new TIE fighter &3fb6 20 ff 37 JSR &37ff ; rnd &3fb9 29 0f AND #&0f &3fbb 38 SEC &3fbc e9 08 SBC #&08 # -8 to 7 &3fbe 9d dd 15 STA &15dd,X ; tie_fighters_y_high # Set random x position for new TIE fighter &3fc1 a9 fc LDA #&fc &3fc3 9d e5 15 STA &15e5,X ; tie_fighters_z_high # Put new TIE fighter behind player &3fc6 a9 05 LDA #&05 ; MODEL_TIE_FIGHTER &3fc8 9d f1 15 STA &15f1,X ; tie_fighters_state &3fcb a9 04 LDA #&04 &3fcd 9d fd 15 STA &15fd,X ; tie_fighters_z_velocity # New TIE fighter moves into distance &3fd0 20 46 42 JSR &4246 ; jitter_tie_fighter_velocities ; to_consider_next_tie_fighter &3fd3 4c 3d 42 JMP &423d ; consider_next_tie_fighter ; not_end_of_explosion &3fd6 a9 00 LDA #&00 &3fd8 85 7d STA &7d ; value_low &3fda 38 SEC &3fdb fd f1 15 SBC &15f1,X ; tie_fighters_state # Distance of part depends on state of explosion &3fde 0a ASL A &3fdf 85 7e STA &7e ; value_high &3fe1 de f1 15 DEC &15f1,X ; tie_fighters_state &3fe4 bd e9 15 LDA &15e9,X ; tie_fighters_rotation &3fe7 18 CLC &3fe8 69 40 ADC #&40 &3fea aa TAX &3feb 20 88 37 JSR &3788 ; calculate_sixteen_bit_value_times_sine_X &3fee 20 ac 37 JSR &37ac ; calculate_sixteen_bit_value_times_cosine_X &3ff1 a5 66 LDA &66 ; sine_result &3ff3 85 57 STA &57 ; explosion_offset_x &3ff5 a5 67 LDA &67 ; sine_result_high &3ff7 85 58 STA &58 ; explosion_offset_x_high &3ff9 a5 68 LDA &68 ; cosine_result &3ffb 85 59 STA &59 ; explosion_offset_y &3ffd a5 69 LDA &69 ; cosine_result_high &3fff 85 5a STA &5a ; explosion_offset_y_high &4001 68 PLA ; tie fighter offset &4002 48 PHA ; tie fighter offset &4003 aa TAX &4004 bd d1 15 LDA &15d1,X ; tie_fighters_x &4007 18 CLC &4008 65 66 ADC &66 ; sine_result &400a 85 50 STA &50 ; origin_x &400c bd d5 15 LDA &15d5,X ; tie_fighters_x_high &400f 65 67 ADC &67 ; sine_result_high &4011 85 51 STA &51 ; origin_x_high &4013 bd d9 15 LDA &15d9,X ; tie_fighters_y &4016 18 CLC &4017 65 68 ADC &68 ; cosine_result &4019 85 52 STA &52 ; origin_y &401b bd dd 15 LDA &15dd,X ; tie_fighters_y_high &401e 65 69 ADC &69 ; cosine_result_high &4020 85 53 STA &53 ; origin_y_high &4022 bd e1 15 LDA &15e1,X ; tie_fighters_z &4025 85 54 STA &54 ; origin_z &4027 bd e5 15 LDA &15e5,X ; tie_fighters_z_high &402a 85 55 STA &55 ; origin_z_high &402c a9 07 LDA #&07 ; MODEL_EXPLODING_TIE_FIGHTER_WING &402e 85 cf STA &cf ; model &4030 bd ed 15 LDA &15ed,X ; tie_fighters_rotation_velocity &4033 18 CLC &4034 69 08 ADC #&08 &4036 9d ed 15 STA &15ed,X ; tie_fighters_rotation_velocity &4039 18 CLC &403a 7d e9 15 ADC &15e9,X ; tie_fighters_rotation &403d 85 ca STA &ca ; model_rotation_about_z &403f 20 5f 3a JSR &3a5f ; plot_model # Plot wing of exploding TIE fighter &4042 30 00 BMI &4044 ; skip_nothing # Unnecessary code ; skip_nothing &4044 68 PLA ; tie fighter offset &4045 48 PHA ; tie fighter offset &4046 aa TAX &4047 bd d1 15 LDA &15d1,X ; tie_fighters_x &404a 38 SEC &404b e5 57 SBC &57 ; explosion_offset_x &404d 85 50 STA &50 ; origin_x &404f bd d5 15 LDA &15d5,X ; tie_fighters_x_high &4052 e5 58 SBC &58 ; explosion_offset_x_high &4054 85 51 STA &51 ; origin_x_high &4056 bd d9 15 LDA &15d9,X ; tie_fighters_y &4059 38 SEC &405a e5 59 SBC &59 ; explosion_offset_y &405c 85 52 STA &52 ; origin_y &405e bd dd 15 LDA &15dd,X ; tie_fighters_y_high &4061 e5 5a SBC &5a ; explosion_offset_y_high &4063 85 53 STA &53 ; origin_y_high &4065 bd e1 15 LDA &15e1,X ; tie_fighters_z &4068 85 54 STA &54 ; origin_z &406a bd e5 15 LDA &15e5,X ; tie_fighters_z_high &406d 85 55 STA &55 ; origin_z_high &406f 20 5f 3a JSR &3a5f ; plot_model # Plot wing of exploding TIE fighter &4072 68 PLA ; tie fighter offset &4073 48 PHA ; tie fighter offset &4074 aa TAX &4075 bd d1 15 LDA &15d1,X ; tie_fighters_x &4078 85 50 STA &50 ; origin_x &407a bd d5 15 LDA &15d5,X ; tie_fighters_x_high &407d 85 51 STA &51 ; origin_x_high &407f bd d9 15 LDA &15d9,X ; tie_fighters_y &4082 85 52 STA &52 ; origin_y &4084 bd dd 15 LDA &15dd,X ; tie_fighters_y_high &4087 85 53 STA &53 ; origin_y_high &4089 bd e1 15 LDA &15e1,X ; tie_fighters_z &408c 85 54 STA &54 ; origin_z &408e a9 00 LDA #&00 &4090 38 SEC &4091 fd f1 15 SBC &15f1,X ; tie_fighters_state &4094 18 CLC &4095 7d e5 15 ADC &15e5,X ; tie_fighters_z_high &4098 85 55 STA &55 ; origin_z_high &409a a9 08 LDA #&08 ; MODEL_EXPLODING_TIE_FIGHTER_BODY &409c 85 cf STA &cf ; model &409e bd e9 15 LDA &15e9,X ; tie_fighters_rotation &40a1 85 ca STA &ca ; model_rotation_about_z &40a3 20 5f 3a JSR &3a5f ; plot_model # Plot middle of exploding TIE fighter &40a6 4c 3d 42 JMP &423d ; consider_next_tie_fighter ; update_tie_fighter # If the TIE fighter isn't exploding, &40a9 8a TXA ; tie fighter offset &40aa 0a ASL A &40ab 0a ASL A &40ac 29 0f AND #&0f &40ae d0 03 BNE &40b3 ; skip_jittering_velocities &40b0 20 46 42 JSR &4246 ; jitter_tie_fighter_velocities # Jitter velocities of first TIE fighter ; skip_jittering_velocities &40b3 bd f1 15 LDA &15f1,X ; tie_fighters_state &40b6 29 07 AND #&07 &40b8 c9 06 CMP #&06 ; MODEL_TIE_FIGHTER_VADER &40ba d0 23 BNE &40df ; is_regular_tie_fighter ; is_vader &40bc ad ab 08 LDA &08ab ; vader_tie_fighter_hit_cooldown # Positive if Darth Vader's TIE fighter recently hit &40bf 30 1e BMI &40df ; is_regular_tie_fighter &40c1 bd d5 15 LDA &15d5,X ; tie_fighters_x_high # x += 3 &40c4 18 CLC &40c5 69 03 ADC #&03 &40c7 9d d5 15 STA &15d5,X ; tie_fighters_x_high &40ca bd dd 15 LDA &15dd,X ; tie_fighters_y_high # y += 3 &40cd 18 CLC &40ce 69 03 ADC #&03 &40d0 9d dd 15 STA &15dd,X ; tie_fighters_y_high &40d3 bd e9 15 LDA &15e9,X ; tie_fighters_rotation # rotation += 8 &40d6 18 CLC &40d7 69 08 ADC #&08 &40d9 9d e9 15 STA &15e9,X ; tie_fighters_rotation &40dc 4c 1e 41 JMP &411e ; skip_moving_tie_fighter_in_xy ; is_regular_tie_fighter &40df a9 00 LDA #&00 &40e1 85 7d STA &7d ; value_low &40e3 bd f5 15 LDA &15f5,X ; tie_fighters_xy_velocity &40e6 85 7e STA &7e ; value_high &40e8 bd e9 15 LDA &15e9,X ; tie_fighters_rotation # rotation += rotation_velocity &40eb 18 CLC &40ec 7d ed 15 ADC &15ed,X ; tie_fighters_rotation_velocity &40ef 9d e9 15 STA &15e9,X ; tie_fighters_rotation &40f2 aa TAX &40f3 20 88 37 JSR &3788 ; calculate_sixteen_bit_value_times_sine_X &40f6 20 ac 37 JSR &37ac ; calculate_sixteen_bit_value_times_cosine_X &40f9 68 PLA ; tie fighter offset &40fa 48 PHA ; tie fighter offset &40fb aa TAX &40fc bd d1 15 LDA &15d1,X ; tie_fighters_x # x += velocity * sin(rotation) &40ff 18 CLC &4100 65 66 ADC &66 ; sine_result &4102 9d d1 15 STA &15d1,X ; tie_fighters_x &4105 bd d5 15 LDA &15d5,X ; tie_fighters_x_high &4108 65 67 ADC &67 ; sine_result_high &410a 9d d5 15 STA &15d5,X ; tie_fighters_x_high &410d bd d9 15 LDA &15d9,X ; tie_fighters_y # y += velocity * cos(rotation) &4110 18 CLC &4111 65 68 ADC &68 ; cosine_result &4113 9d d9 15 STA &15d9,X ; tie_fighters_y &4116 bd dd 15 LDA &15dd,X ; tie_fighters_y_high &4119 65 69 ADC &69 ; cosine_result_high &411b 9d dd 15 STA &15dd,X ; tie_fighters_y_high ; skip_moving_tie_fighter_in_xy &411e bd e1 15 LDA &15e1,X ; tie_fighters_z &4121 85 54 STA &54 ; origin_z &4123 bd e5 15 LDA &15e5,X ; tie_fighters_z_high # z += z_velocity &4126 18 CLC &4127 7d fd 15 ADC &15fd,X ; tie_fighters_z_velocity &412a 9d e5 15 STA &15e5,X ; tie_fighters_z_high &412d 85 55 STA &55 ; origin_z_high &412f c9 40 CMP #&40 &4131 90 07 BCC &413a ; not_at_far_point ; at_far_point &4133 a9 fc LDA #&fc &4135 9d fd 15 STA &15fd,X ; tie_fighters_z_velocity # Set TIE fighter moving back towards player &4138 30 09 BMI &4143 ; not_at_near_point # Always branches ; not_at_far_point &413a a5 55 LDA &55 ; origin_z_high &413c d0 05 BNE &4143 ; not_at_near_point &413e a9 04 LDA #&04 &4140 9d fd 15 STA &15fd,X ; tie_fighters_z_velocity # Set TIE fighter moving into distance ; not_at_near_point &4143 bd d5 15 LDA &15d5,X ; tie_fighters_x_high &4146 10 10 BPL &4158 ; not_at_left_limit &4148 c9 e0 CMP #&e0 &414a b0 1a BCS &4166 ; not_at_right_limit &414c a9 e0 LDA #&e0 &414e 9d d5 15 STA &15d5,X ; tie_fighters_x_high # Stop TIE fighter moving too far left &4151 a9 00 LDA #&00 &4153 9d d1 15 STA &15d1,X ; tie_fighters_x &4156 f0 0e BEQ &4166 ; not_at_right_limit # Always branches ; not_at_left_limit &4158 c9 20 CMP #&20 &415a 90 0a BCC &4166 ; not_at_right_limit &415c a9 20 LDA #&20 &415e 9d d5 15 STA &15d5,X ; tie_fighters_x_high # Stop TIE fighter moving too far right &4161 a9 00 LDA #&00 &4163 9d d1 15 STA &15d1,X ; tie_fighters_x ; not_at_right_limit &4166 bd dd 15 LDA &15dd,X ; tie_fighters_y_high &4169 10 10 BPL &417b ; not_at_bottom_limit &416b c9 e0 CMP #&e0 &416d b0 1a BCS &4189 ; not_at_top_limit &416f a9 e0 LDA #&e0 &4171 9d dd 15 STA &15dd,X ; tie_fighters_y_high # Stop TIE fighter moving too far down &4174 a9 00 LDA #&00 &4176 9d d9 15 STA &15d9,X ; tie_fighters_y &4179 f0 0e BEQ &4189 ; not_at_top_limit # Always branches ; not_at_bottom_limit &417b c9 20 CMP #&20 &417d 90 0a BCC &4189 ; not_at_top_limit &417f a9 20 LDA #&20 &4181 9d dd 15 STA &15dd,X ; tie_fighters_y_high # Stop TIE fighter moving too far up &4184 a9 00 LDA #&00 &4186 9d d9 15 STA &15d9,X ; tie_fighters_y ; not_at_top_limit &4189 bd d1 15 LDA &15d1,X ; tie_fighters_x &418c 85 50 STA &50 ; origin_x &418e bd d5 15 LDA &15d5,X ; tie_fighters_x_high &4191 85 51 STA &51 ; origin_x_high &4193 bd d9 15 LDA &15d9,X ; tie_fighters_y &4196 85 52 STA &52 ; origin_y &4198 bd dd 15 LDA &15dd,X ; tie_fighters_y_high &419b 85 53 STA &53 ; origin_y_high &419d bd f1 15 LDA &15f1,X ; tie_fighters_state &41a0 29 07 AND #&07 &41a2 85 cf STA &cf ; model &41a4 bd e9 15 LDA &15e9,X ; tie_fighters_rotation # rotation += rotation_velocity again &41a7 18 CLC &41a8 7d ed 15 ADC &15ed,X ; tie_fighters_rotation_velocity &41ab 9d e9 15 STA &15e9,X ; tie_fighters_rotation &41ae 85 ca STA &ca ; model_rotation_about_z &41b0 a9 03 LDA #&03 ; G # actually LDA tie_fighter_colour &41b2 20 ab 23 JSR &23ab ; set_colour &41b5 20 5f 3a JSR &3a5f ; plot_model # Plot TIE fighter; returns negative if behind player &41b8 30 0d BMI &41c7 ; remove_tie_fighter_behind_player &41ba ad b1 08 LDA &08b1 ; frame_count_high &41bd c9 02 CMP #&02 &41bf b0 06 BCS &41c7 ; skip_adding_fireball # Don't add fireballs at end of stage &41c1 20 c3 2e JSR &2ec3 ; add_space_fireball &41c4 4c d8 41 JMP &41d8 ; skip_removing_tie_fighter ; remove_tie_fighter_behind_player &41c7 ad b1 08 LDA &08b1 ; frame_count_high # Unnecessary code &41ce 68 PLA ; tie fighter offset &41cf 48 PHA ; tie fighter offset &41d0 aa TAX &41d1 a9 f8 LDA #&f8 &41d3 9d f1 15 STA &15f1,X ; tie_fighters_state # Set to &f8 to remove TIE fighter without explosion &41d6 30 65 BMI &423d ; consider_next_tie_fighter # Always branches ; skip_removing_tie_fighter &41d8 68 PLA ; tie fighter offset &41d9 48 PHA ; tie fighter offset &41da aa TAX &41db ad 02 03 LDA &0302 ; target_x &41de 9d 00 01 STA &0100,X ; tie_fighters_target_x &41e1 ad 03 03 LDA &0303 ; target_x_high &41e4 9d 08 01 STA &0108,X ; tie_fighters_target_x_high &41e7 ad 04 03 LDA &0304 ; target_y &41ea 9d 10 01 STA &0110,X ; tie_fighters_target_y &41ed ad 05 03 LDA &0305 ; target_y_high &41f0 9d 18 01 STA &0118,X ; tie_fighters_target_y_high &41f3 a9 0a LDA #&0a &41f5 20 5d 42 JSR &425d ; check_for_player_hitting_target # Returns negative if player hit target &41f8 10 43 BPL &423d ; consider_next_tie_fighter ; player_hit_tie_fighter &41fa a9 00 LDA #&00 &41fc 20 de 44 JSR &44de ; play_sound # Play sound for hitting TIE fighter &41ff a9 08 LDA #&08 &4201 20 de 44 JSR &44de ; play_sound # Play sound for hitting TIE fighter &4204 68 PLA ; tie fighter offset &4205 48 PHA ; tie fighter offset &4206 aa TAX &4207 8e aa 23 STX &23aa ; tie_fighter_to_follow # Follow TIE fighter hit &420a a5 cf LDA &cf ; model &420c 29 07 AND #&07 &420e c9 06 CMP #&06 ; MODEL_TIE_FIGHTER_VADER &4210 d0 12 BNE &4224 ; is_regular_tie_fighter ; is_vader &4212 ad ab 08 LDA &08ab ; vader_tie_fighter_hit_cooldown # Positive if Darth Vader's TIE fighter recently hit &4215 10 26 BPL &423d ; consider_next_tie_fighter &4217 a9 07 LDA #&07 &4219 8d ab 08 STA &08ab ; vader_tie_fighter_hit_cooldown &421c a9 20 LDA #&20 # Score 2000 for hitting Darth Vader's TIE fighter &421e 8d 37 42 STA &4237 ; tie_fighter_score &4221 4c 2e 42 JMP &422e ; skip_exploding_tie_fighter ; is_regular_tie_fighter &4224 a9 10 LDA #&10 # Score 1000 for destroying regular TIE fighter &4226 8d 37 42 STA &4237 ; tie_fighter_score &4229 a9 ff LDA #&ff &422b 9d f1 15 STA &15f1,X ; tie_fighters_state # Set to negative to indicate TIE fighter exploding ; skip_exploding_tie_fighter &422e a9 00 LDA #&00 &4230 85 70 STA &70 ; number &4232 85 72 STA &72 ; number + 2 &4234 85 73 STA &73 ; number + 3 &4236 a9 10 LDA #&10 # actually LDA tie_fighter_score &4238 85 71 STA &71 ; number + 1 &423a 20 2f 16 JSR &162f ; add_to_score ; consider_next_tie_fighter &423d 68 PLA ; tie fighter offset &423e aa TAX &423f ca DEX &4240 30 03 BMI &4245 ; leave &4242 4c 93 3f JMP &3f93 ; update_tie_fighters_loop ; leave &4245 60 RTS ; jitter_tie_fighter_velocities &4246 20 ff 37 JSR &37ff ; rnd &4249 29 03 AND #&03 &424b 38 SEC &424c e9 02 SBC #&02 # Add -2 to 1 to rotation_velocity &424e 9d ed 15 STA &15ed,X ; tie_fighters_rotation_velocity &4251 20 ff 37 JSR &37ff ; rnd &4254 29 03 AND #&03 &4256 38 SEC &4257 e9 02 SBC #&02 # Add -2 to 1 to xy_velocity &4259 9d f5 15 STA &15f5,X ; tie_fighters_xy_velocity &425c 60 RTS ; check_for_player_hitting_target # Called with A = size of target &425d 85 41 STA &41 ; point_x_high &425f ad 00 03 LDA &0300 ; player_is_firing # Negative if player is firing &4262 10 76 BPL &42da ; leave_with_zero &4264 ad 03 03 LDA &0303 ; target_x_high &4267 0d 05 03 ORA &0305 ; target_y_high &426a d0 6e BNE &42da ; leave_with_zero &426c ad 02 03 LDA &0302 ; target_x &426f 30 69 BMI &42da ; leave_with_zero &4271 ad 04 03 LDA &0304 ; target_y &4274 c9 a0 CMP #&a0 &4276 b0 62 BCS &42da ; leave_with_zero # No hit if target is offscreen &4278 a9 00 LDA #&00 &427a 85 40 STA &40 ; point_x &427c a5 54 LDA &54 ; origin_z &427e 85 46 STA &46 ; point_z &4280 a5 55 LDA &55 ; origin_z_high &4282 85 47 STA &47 ; point_z_high &4284 20 75 39 JSR &3975 ; divide_point_x_by_point_z_times_two # Scale target by distance &4287 ad 02 03 LDA &0302 ; target_x &428a 38 SEC &428b ed 13 03 SBC &0313 ; player_x &428e 85 30 STA &30 ; target_relative_x &4290 ad 03 03 LDA &0303 ; target_x_high &4293 e9 00 SBC #&00 &4295 85 31 STA &31 ; target_relative_x_high &4297 a5 79 LDA &79 ; result &4299 4a LSR A &429a 85 60 STA &60 ; half_result &429c a5 78 LDA &78 ; result_fraction &429e 6a ROR A &429f 85 5f STA &5f ; half_result_fraction &42a1 a5 30 LDA &30 ; target_relative_x &42a3 18 CLC &42a4 65 5f ADC &5f ; half_result_fraction &42a6 85 30 STA &30 ; target_relative_x &42a8 a5 31 LDA &31 ; target_relative_x_high &42aa 65 60 ADC &60 ; half_result &42ac 30 2c BMI &42da ; leave_with_zero &42ae a5 30 LDA &30 ; target_relative_x &42b0 c5 78 CMP &78 ; result_fraction &42b2 b0 26 BCS &42da ; leave_with_zero &42b4 ad 04 03 LDA &0304 ; target_y &42b7 38 SEC &42b8 ed 14 03 SBC &0314 ; player_y &42bb 85 32 STA &32 ; target_relative_y &42bd ad 05 03 LDA &0305 ; target_y_high &42c0 e9 00 SBC #&00 &42c2 85 33 STA &33 ; target_relative_y_high &42c4 a5 32 LDA &32 ; target_relative_y &42c6 18 CLC &42c7 65 5f ADC &5f ; half_result_fraction &42c9 85 32 STA &32 ; target_relative_y &42cb a5 33 LDA &33 ; target_relative_y_high &42cd 65 60 ADC &60 ; half_result &42cf 30 09 BMI &42da ; leave_with_zero &42d1 a5 32 LDA &32 ; target_relative_y &42d3 c5 78 CMP &78 ; result_fraction &42d5 b0 03 BCS &42da ; leave_with_zero &42d7 a9 ff LDA #&ff # Leave with negative to indicate hit &42d9 60 RTS ; leave_with_zero &42da a9 00 LDA #&00 # Leave with positive to indicate not hit &42dc 60 RTS ; points_next_tower_string &42dd 48 03 0f 12 ; at + &0348, colour &0f (C), length &12 &42e1 3c 50 4f 49 4e 54 53 3c 4e 45 58 54 3c 54 4f 57 ; "" (actually " ", unused) &4798 00 00 00 00 00 00 00 00; "?" (actually " ", unused) &47a0 00 00 00 00 00 00 00 00; "@" (actually " ", unused) &47a8 77 55 55 77 55 55 55 00; "A &47b0 66 55 55 66 55 55 66 00; "B" &47b8 77 44 44 44 44 44 77 00; "C" &47c0 66 55 55 55 55 55 66 00; "D" &47c8 77 44 44 77 44 44 77 00; "E" &47d0 77 44 44 77 44 44 44 00; "F" &47d8 77 44 44 44 55 55 77 00; "G" &47e0 55 55 55 77 55 55 55 00; "H" &47e8 77 22 22 22 22 22 77 00; "I" &47f0 77 22 22 22 22 22 66 00; "J" &47f8 55 55 55 66 55 55 55 00; "K" &4800 44 44 44 44 44 44 77 00; "L" &4808 55 77 55 55 55 55 55 00; "M" &4810 77 55 55 55 55 55 55 00; "N" &4818 77 55 55 55 55 55 77 00; "O" &4820 77 55 55 77 44 44 44 00; "P" &4828 77 55 55 55 55 77 11 00; "Q" &4830 77 55 77 66 55 55 55 00; "R" &4838 77 44 44 77 11 11 77 00; "S" &4840 77 22 22 22 22 22 22 00; "T" &4848 55 55 55 55 55 55 77 00; "U" &4850 55 55 55 55 55 55 22 00; "V" &4858 55 55 55 55 55 77 55 00; "W" &4860 55 55 55 22 55 55 55 00; "X" &4868 55 55 55 77 22 22 22 00; "Y" &4870 77 11 22 22 44 44 77 00; "Z" ; use_the_force_string &4878 48 06 f0 0d ; at + &0648, colour &f0 (R), length &0d &487c 55 53 45 20 54 48 45 20 46 4f 52 43 45 ; "USE THE FORCE" ; exhaust_port_ahead_string &4889 38 06 f0 12 ; at + &0638, colour &f0 (R), length &12 &488d 45 58 48 41 55 53 54 20 50 4f 52 54 20 41 48 45 ; "EXHAUST PORT AHEAD" &489d 41 44 ; exhaust_port_missed_string &489f 30 06 0f 13 ; at + &0630, colour &0f (C), length &13 &48a3 45 58 48 41 55 53 54 20 50 4f 52 54 20 4d 49 53 ; "EXHAUST PORT MISSED" &48b3 53 45 44 ; towers_string &48b6 d0 01 f0 06 ; at + &01d0, colour &f0 (R), length &06 &48ba 54 4f 57 45 52 53 ; "TOWERS" ; trench_vanishing_point_lines_type_table &48c0 00 01 01 01 00 01 01 00 01 01 00 01 00 01 ; shoot_fireballs_string &48ce 38 03 0f 12 ; at + &0338, colour &0f (C), length &12 &48d2 3c 53 48 4f 4f 54 3c 46 49 52 45 42 41 4c 4c 53 ; "