Exile disk protection and supervisor disassembly
================================================
Exile was written by Peter Irvin and Jeremy Smith, and was published by
Superior Software for the BBC Micro in 1988. It is a graphical adventure game
in which the player must retrieve a spaceship's destinator, which has been
stolen by a deranged scientist and hidden deep in a maze of tunnels and
caverns. The game features a procedurally generated landscape and a realistic
physics engine. It is notable for its technical complexity.

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
===============
This disassembly analyses the game's disk protection and supervisor.

A disassembly of the standard version of the game may be found at:
http://www.level7.org.uk/miscellany/exile-standard-disassembly.txt

A disassembly of the enhanced version of the game may be found at:
http://www.level7.org.uk/miscellany/exile-enhanced-disassembly.txt

The disk's catalogue contains one file, !BOOT, but appears to be empty, because
the top bit of the first byte of the filename is set. This uses the sector IDs
of a specially formatted track as a decryption key for a second stage stored on
another track, which in turn intercepts filing system calls to load files from
encrypted sectors using a hidden catalogue. These sectors are arranged so that
the disk can be read using either a forty track or eighty track drive.

A BASIC loader runs the supervisor. The supervisor is decrypted before use.

Disk protection disassembly
===========================
; !BOOT                                                             # First byte of filename has top bit set to hide from catalogue
; FF1F00 FF1F10 000100

; unused
&1f00 00 00 00 00 00 08 20 0a 00 1f 10 1f 00 01 cc 01

; entry_point
; decrypt_payload_outer_loop
&1f10 a2 2c    LDX #&2c
&1f12 ad 10 1f LDA &1f10 ; decrypt_payload_outer_loop
#     actually LDA source_address
; decrypt_payload_inner_loop                                        # Decrypt &1f2c - &1fff using &1f00 - &1fff
&1f15 5d 00 1f EOR &1f00,X
&1f18 9d 00 1f STA &1f00,X
&1f1b e8       INX
&1f1c d0 f7    BNE &1f15 ; decrypt_payload_inner_loop
; move_to_next_source_byte
&1f1e ee 13 1f INC &1f13 ; source_address_low
&1f21 ad 13 1f LDA &1f13 ; source_address_low
&1f24 c9 2c    CMP #&2c                                             # Skip using &1f2c
&1f26 f0 f6    BEQ &1f1e ; move_to_next_source_byte
&1f28 c9 00    CMP #&00
&1f2a d0 e4    BNE &1f10 ; decrypt_payload_outer_loop
; payload
&1f2c 78       SEI
&1f2d ac b6 ff LDY &ffb6 ; os_rom_vector_table_length
&1f30 ad b7 ff LDA &ffb7 ; os_rom_default_vector_table_address_low
&1f33 85 00    STA &00 ; default_vector_table_address_low
&1f35 ad b8 ff LDA &ffb8 ; os_rom_default_vector_table_address_high
&1f38 85 01    STA &01 ; default_vector_table_address_high
; reset_vector_table_loop
&1f3a b1 00    LDA (&00),Y ; default_vector_table_address
&1f3c 99 00 02 STA &0200,Y ; os_vector_table
&1f3f 88       DEY
&1f40 10 f8    BPL &1f3a ; reset_vector_table_loop
&1f42 a9 c8    LDA #&c8 ; Read/Write BREAK/ESCAPE effect
&1f44 a2 03    LDX #&03 ; Clear memory on next RESET
&1f46 a0 00    LDY #&00
&1f48 20 f4 ff JSR &fff4 ; OSBYTE
&1f4b a9 ea    LDA #&ea ; Read/Write Tube present flag 
&1f4d a2 00    LDX #&00
&1f4f a0 ff    LDY #&ff
&1f51 20 f4 ff JSR &fff4 ; OSBYTE                                   # Returns X = &ff if tube present
&1f54 8a       TXA
&1f55 d0 b9    BNE &1f10 ; entry_point                              # Crash if tube present
&1f57 a2 f6    LDX #&f6 ; &1ff6 = disk_command
&1f59 a0 1f    LDY #&1f
&1f5b 20 f7 ff JSR &fff7 ; OSCLI                                    # *DISK
&1f5e a9 77    LDA #&77 ; Close all Spool/Exec files
&1f60 20 f4 ff JSR &fff4 ; OSBYTE
&1f63 a2 00    LDX #&00
; write_initialise_screen_string_loop
&1f65 bd ea 1f LDA &1fea,X ; initialise_screen_string
&1f68 20 ee ff JSR &ffee ; OSWRCH                                   # Change to MODE 7, disable cursor
&1f6b e8       INX
&1f6c e0 0c    CPX #&0c
&1f6e d0 f5    BNE &1f65 ; write_initialise_screen_string_loop
&1f70 a2 df    LDX #&df ; &1fdf = read_ids_block
&1f72 a0 1f    LDY #&1f
&1f74 a9 7f    LDA #&7f ; Floppy disk operation
&1f76 20 f1 ff JSR &fff1 ; OSWORD                                   # Read sector IDs for track 1 to &0700
; infinite_loop_if_ids_not_read
&1f79 ad e9 1f LDA &1fe9 ; read_ids_block + 10 (result)
&1f7c d0 fb    BNE &1f79 ; infinite_loop_if_ids_not_read            # Infinite loop if unable to read
; check_sector_ids
&1f7e ad 14 07 LDA &0714 ; sector_ids + &14
&1f81 c9 57    CMP #&57 ; "W"
&1f83 d0 07    BNE &1f8c ; incorrect_ids
&1f85 ad 15 07 LDA &0715 ; sector_ids + &15
&1f88 c9 65    CMP #&65 ; "e"
&1f8a f0 16    BEQ &1fa2 ; found_second_stage_block
; rotate_sector_ids
&1f8c ad 47 07 LDA &0747 ; sector_ids + &47
&1f8f 48       PHA ; last id
&1f90 a2 46    LDX #&46
; rotate_sector_ids_loop
&1f92 bd 00 07 LDA &0700,X ; sector_ids
&1f95 9d 01 07 STA &0701,X ; sector_ids + 1
&1f98 ca       DEX
&1f99 10 f7    BPL &1f92 ; rotate_sector_ids_loop
&1f9b 68       PLA ; last id
&1f9c 8d 00 07 STA &0700 ; sector_ids
&1f9f 4c 7e 1f JMP &1f7e ; check_sector_ids
; found_second_stage_block
&1fa2 ad 0a 07 LDA &070a ; sector_ids + 10                          # Zero if eighty track drive
&1fa5 85 e3    STA &e3 ; forty_or_eighty_track_drive
; read_second_stage
&1fa7 a2 00    LDX #&00 ; &0700 = read_second_stage_block
&1fa9 a0 07    LDY #&07
&1fab a9 7f    LDA #&7f ; Floppy disk operation
&1fad 20 f1 ff JSR &fff1 ; OSWORD                                   # Read second stage from track 0, sector 2
&1fb0 ad 0a 07 LDA &070a ; read_second_stage_block + 10 (result)
&1fb3 d0 f2    BNE &1fa7 ; read_second_stage
&1fb5 a9 00    LDA #&00
&1fb7 85 00    STA &00 ; target_address_low
&1fb9 a9 78    LDA #&78 ; &7800 = second_stage
&1fbb 85 01    STA &01 ; target_address_high
&1fbd a0 00    LDY #&00
&1fbf a2 14    LDX #&14 ; &0714 = decryption_key
; decrypt_second_stage_loop                                         # Use &0714 - &073b as a key to decrypt &7800 - &7bff
&1fc1 bd 00 07 LDA &0700,X ; sector_ids
&1fc4 51 00    EOR (&00),Y ; target_address
&1fc6 91 00    STA (&00),Y ; target_address
&1fc8 e8       INX
&1fc9 e0 3c    CPX #&3c
&1fcb d0 02    BNE &1fcf ; skip_wraparound
&1fcd a2 14    LDX #&14 ; &0714 = decryption_key
; skip_wraparound
&1fcf e6 00    INC &00 ; target_address_low
&1fd1 d0 ee    BNE &1fc1 ; decrypt_second_stage_loop
&1fd3 e6 01    INC &01 ; target_address_high
&1fd5 a5 01    LDA &01 ; target_address_high
&1fd7 c9 7c    CMP #&7c
&1fd9 d0 e6    BNE &1fc1 ; decrypt_second_stage_loop
&1fdb 58       CLI
&1fdc 6c 01 07 JMP (&0701) ; read_second_stage_block + 1            # &7800 = second_stage_entry_point

; read_ids_block
&1fdf 00          ; drive 0
&1fe0 00 07 ff ff ; address : &0700 = sector_ids
&1fe4 03          ; parameters
&1fe5 5b          ; command : read IDs
&1fe6 01          ; track 1
&1fe7 00          ; zero parameter
&1fe8 12          ; count
&1fe9 00          ; result

; initialise_screen_string
&1fea 16 07                                           ; MODE 7
&1fec 17 01 00 00 00 00 00 00 00 00                   ; disable cursor

; disk_command
&1ff6 44 49 53 4b 0d                                  ; "DISK"

; unused
&1ffc 27 c9 e6 43 1b                                                # Not meaningful encrypted or decrypted


# &0700 - &0747 is read from the sector IDs on track 1 at &1f76

; sector_ids
; read_second_stage_block
&0700 00          ; drive 0
&0701 00 78 ff ff ; address : &7800 = second_stage
&0705 03          ; parameters
&0706 53          ; read data
&0707 00          ; track
&0708 02          ; sector
&0709 28          ; size and count : eight 256 byte sectors
&070a 00          ; result

; unused
&0708 ff ff ff ff ff ff ff ff ff

; decryption_key
&0714 57 65 6c 6c 2c 20 67 6f 6f 64 20 65 76 65 6e 69 ; "Well, good eveni"
&0724 6e 67 2e 20 20 48 6f 70 65 20 79 6f 75 27 72 65 ; "ng.  Hope you're"
&0734 20 68 61 76 69 6e 67 20                         ; " having "

; unused
&073c 66 75 6e 21 0d                                  ; "fun!"
&0741 ff ff ff ff ff ff ff


# &7800 - &7bff is loaded from track 0, sector 2 at &1fad

; second_stage_entry_point
&7800 a9 c8    LDA #&c8 ; Read/Write BREAK/ESCAPE effect
&7802 a2 03    LDX #&03 ; Clear memory on next RESET
&7804 a0 00    LDY #&00
&7806 20 f4 ff JSR &fff4 ; OSBYTE
&7809 a0 00    LDY #&00
; move_7a00_to_7bff_loop                                            # Move &7a00 - &7bff to &0900 - &0aff
&780b b9 00 7a LDA &7a00,Y
&780e 99 00 09 STA &0900,Y
&7811 b9 00 7b LDA &7b00,Y
&7814 99 00 0a STA &0a00,Y
&7817 c8       INY
&7818 d0 f1    BNE &780b ; move_7a00_to_7bff_loop
&781a 78       SEI
&781b ad 12 02 LDA &0212 ; osfile_vector_low
&781e 8d 01 09 STA &0901 ; previous_osfile_vector_low
&7821 ad 13 02 LDA &0213 ; osfile_vector_high
&7824 8d 02 09 STA &0902 ; previous_osfile_vector_high
&7827 ad 1e 02 LDA &021e ; file_system_control_vector_low           # Intercept file loading and running routines
&782a 8d 04 09 STA &0904 ; previous_file_system_control_vector_low
&782d ad 1f 02 LDA &021f ; file_system_control_vector_high
&7830 8d 05 09 STA &0905 ; previous_file_system_control_vector_high
&7833 a9 09    LDA #&09 ; &0909 = file_system_control_handler
&7835 8d 13 02 STA &0213 ; osfile_vector_high
&7838 8d 1e 02 STA &021e ; file_system_control_vector_low
&783b 8d 1f 02 STA &021f ; file_system_control_vector_high
&783e a9 06    LDA #&06 ; &0906 = to_osfile_handler
&7840 8d 12 02 STA &0212 ; osfile_vector_low
&7843 ad 0e 02 LDA &020e ; oswrch_vector_low
&7846 8d 30 02 STA &0230 ; spare_vector_one_low                     # Store previous_oswrch_vector in spare_vector_one
&7849 ad 0f 02 LDA &020f ; oswrch_vector_high
&784c 8d 31 02 STA &0231 ; spare_vector_one_high
&784f a9 60    LDA #&60 ; RTS
&7851 8d 32 02 STA &0232 ; oswrch_handler                           # Use spare_vector_two as null routine
&7854 a9 32    LDA #&32 ; &0232 = oswrch_handler
&7856 8d 0e 02 STA &020e ; oswrch_vector_low                        # Redirect OSWRCH to null routine, i.e. suppress output
&7859 a9 02    LDA #&02
&785b 8d 0f 02 STA &020f ; oswrch_vector_high
&785e a9 12    LDA #&12 ; Reset F-key definitions 
&7860 20 f4 ff JSR &fff4 ; OSBYTE
&7863 a2 81    LDX #&81 ; &7881 = key_zero_command
&7865 a0 78    LDY #&78
&7867 20 f7 ff JSR &fff7 ; OSCLI                                    # *K.0PAGE=&1900|MCH."!B"|M
&786a a9 0f    LDA #&0f ; Flush all buffers
&786c a2 00    LDX #&00
&786e 20 f4 ff JSR &fff4 ; OSBYTE
&7871 a9 8a    LDA #&8a ; Place character into buffer 
&7873 a2 00    LDX #&00 ; input buffer
&7875 a0 80    LDY #&80 ; f0
&7877 20 f4 ff JSR &fff4 ; OSBYTE                                   # Push f0 into input buffer, i.e. CHAIN "!B"
&787a a2 9a    LDX #&9a ; &789a = b_command
&787c a0 78    LDY #&78
&787e 20 f7 ff JSR &fff7 ; OSCLI                                    # *B.

; key_zero_command
&7881 4b 2e 30 50 41 47 45 3d 26 31 39 30 30 7c 4d 43 ; "K.0PAGE=&1900|MCH."!B"|M"
&7891 48 2e 22 21 42 22 7c 4d 0d

; b_command
&789a 42 2e 0d                                        ; "B."

; unused
&789d 65 70    ADC &70
&789f 85 70    STA &70
&78a1 a9 00    LDA #&00
&78a3 65 71    ADC &71
&78a5 85 71    STA &71
&78a7 4c e7 ff JMP &ffe7 ; OSNEWL

; unused
&78aa 09 00    ORA #&00
&78ac 30 09    BMI &78b7
&78ae c9 20    CMP #&20 ; " "
&78b0 b0 02    BCS &78b4
&78b2 a9 23    LDA #&23 ; "#"
&78b4 4c ee ff JMP &ffee ; OSWRCH
&78b7 85 75    STA &75
&78b9 a2 66    LDX #&66
&78bb 86 73    STX &73
&78bd a0 af    LDY #&af
&78bf 84 74    STY &74
&78c1 a0 00    LDY #&00
&78c3 b1 73    LDA (&73),Y
&78c5 c5 75    CMP &75
&78c7 d0 0b    BNE &78d4
&78c9 c8       INY
&78ca b1 73    LDA (&73),Y
&78cc 30 16    BMI &78e4
&78ce 20 ee ff JSR &ffee ; OSWRCH
&78d1 4c c9 92 JMP &92c9
&78d4 c9 8d    CMP #&8d
&78d6 f0 0c    BEQ &78e4
&78d8 e6 73    INC &73
&78da d0 02    BNE &78de
&78dc e6 74    INC &74
&78de b1 73    LDA (&73),Y
&78e0 10 f6    BPL &78d8
&78e2 30 dd    BMI &78c1
&78e4 60       RTS

; unused
&78e5 e6 77    INC &77
&78e7 48       PHA
&78e8 8a       TXA
&78e9 48       PHA
&78ea ba       TSX
&78eb bd 02 01 LDA &0102,X
&78ee a6 77    LDX &77
&78f0 9d 00 0a STA &0a00,X
&78f3 68       PLA
&78f4 aa       TAX
&78f5 68       PLA
&78f6 60       RTS

; unused
&78f7 86 73    STX &73
&78f9 84 74    STY &74
&78fb 20 36 93 JSR &9336
&78fe a0 01    LDY #&01
&7900 b1 70    LDA (&70),Y
&7902 30 0b    BMI &790f
&7904 c5 74    CMP &74
&7906 d0 08    BNE &7910
&7908 c8       INY
&7909 b1 70    LDA (&70),Y
&790b c5 73    CMP &73
&790d d0 01    BNE &7910
&790f 60       RTS
&7910 a0 03    LDY #&03
&7912 b1 70    LDA (&70),Y
&7914 18       CLC
&7915 65 70    ADC &70
&7917 85 70    STA &70
&7919 90 e3    BCC &78fe
&791b e6 71    INC &71
&791d d0 df    BNE &78fe
&791f 20 97 93 JSR &9397
&7922 b0 01    BCS &7925
&7924 60       RTS
&7925 20 01 83 JSR &8301
&7928 00       BRK
&7929 42 61 64 20 70 72 6f 67 72 61 6d                ; "Bad program"
&7934 00
&7935 60       RTS

; unused
&7936 a9 00    LDA #&00
&7938 85 70    STA &70
&793a a5 18    LDA &18
&793c 85 71    STA &71
&793e 60       RTS
&793f a5 70    LDA &70
&7941 38       SEC
&7942 e9 01    SBC #&01
&7944 85 70    STA &70
&7946 b0 02    BCS &794a
&7948 c6 71    DEC &71
&794a 60       RTS
&794b a0 00    LDY #&00
&794d b1 f2    LDA (&f2),Y
&794f c9 20    CMP #&20
&7951 d0 08    BNE &795b
&7953 e6 f2    INC &f2
&7955 d0 f4    BNE &794b
&7957 e6 f3    INC &f3
&7959 d0 f0    BNE &794b
&795b 60       RTS

; unused
&795c a5 70    LDA &70
&795e 85 8c    STA &8c
&7960 a5 71    LDA &71
&7962 85 8d    STA &8d
&7964 20 36 93 JSR &9336
&7967 a5 71    LDA &71
&7969 48       PHA
&796a a5 70    LDA &70
&796c 48       PHA
&796d a0 01    LDY #&01
&796f b1 70    LDA (&70),Y
&7971 30 1d    BMI &7990
&7973 a0 03    LDY #&03
&7975 b1 70    LDA (&70),Y
&7977 c9 03    CMP #&03
&7979 90 aa    BCC &7925
&797b 18       CLC
&797c 65 70    ADC &70
&797e 85 70    STA &70
&7980 90 02    BCC &7984
&7982 e6 71    INC &71
&7984 c5 8c    CMP &8c
&7986 a5 71    LDA &71
&7988 e5 8d    SBC &8d
&798a b0 04    BCS &7990
&798c 68       PLA
&798d 68       PLA
&798e d0 d7    BNE &7967
&7990 68       PLA
&7991 85 70    STA &70
&7993 68       PLA
&7994 85 71    STA &71
&7996 60       RTS

; unused
&7997 20 36 93 JSR &9336
&799a a2 00    LDX #&00
&799c a0 00    LDY #&00
&799e b1 70    LDA (&70),Y
&79a0 c9 0d    CMP #&0d ; CR
&79a2 d0 19    BNE &79bd
&79a4 c8       INY
&79a5 b1 70    LDA (&70),Y
&79a7 30 12    BMI &79bb
&79a9 c8       INY
&79aa c8       INY
&79ab b1 70    LDA (&70),Y
&79ad f0 0e    BEQ &79bd
&79af aa       TAX
&79b0 18       CLC
&79b1 65 70    ADC &70
&79b3 85 70    STA &70
&79b5 90 e5    BCC &799c
&79b7 e6 71    INC &71
&79b9 d0 e1    BNE &799c
&79bb 18       CLC
&79bc 60       RTS
&79bd 38       SEC
&79be 60       RTS

; unused
&79bf 20 87 94 JSR &9487
&79c2 20 1f 93 JSR &931f
&79c5 20 36 93 JSR &9336
&79c8 20 4b 93 JSR &934b
&79cb c9 0d    CMP #&0d ; CR
&79cd d0 17    BNE &79e6
&79cf 20 01 83 JSR &8301
&79d2 dc
&79d3 53 79 6e 74 61 78 3a 20 46 49 4e 44 20 3c 73 74 ; "Syntax: FIND <str>"
&79e3 72 3e
&79e5 00
&79e6 a0 01    LDY #&ff
&79e7 b1 70    LDA (&70),Y
&79ea 30 33    BMI &7a1f
&79ec 20 1f 92 JSR &921f
&79ef a2 ff    LDX #&ff
&79f1 20 5e 88 JSR &885e
&79f4 a0 ff    LDY #&ff
&79f6 8a       TXA
&79f7 48       PHA
&79f8 e8       INX
&79f9 c8       INY
&79fa b1 f2    LDA (&f2),Y
&79fc c9 0d    CMP #&0d ; CR
&79fe f0 15    BEQ &7a15

# &7a00 - &7bff is moved to &0900 - &0aff at &780b

; to_previous_osfile_vector_low
&0900 4c 00 00 JMP &0000
#     actually JMP previous_osfile_vector_low

; to_previous_file_system_control_vector_low
&0903 4c 00 00 JMP &0000
#     actually JMP previous_file_system_control_vector_low

; to_osfile_handler
&0906 4c 1d 09 JMP &091d ; osfile_handler

; file_system_control_handler                                       # Called with XY = address of filename, A = action
&0909 c9 02    CMP #&02                                             # &02 if */
&090b f0 04    BEQ &0911 ; is_run
&090d c9 04    CMP #&04                                             # &04 if *RUN
&090f d0 f2    BNE &0903 ; to_previous_file_system_control_vector_low
; is_run
&0911 20 49 09 JSR &0949 ; get_file_metadata                        # Returns carry set if file not found
&0914 b0 06    BCS &091c ; leave                                    # Leave with carry set it file not found
&0916 20 19 0a JSR &0a19 ; load_data                                # Load and decrypt file
&0919 6c 82 00 JMP (&0082) ; exection_address                       # Run file
; leave
&091c 60       RTS

; osfile_handler                                                    # Called with XY = address of OSFILE block, A = action
&091d c9 ff    CMP #&ff                                             # &ff if loading file
&091f d0 df    BNE &0900 ; to_previous_osfile_vector_low
; is_load
&0921 86 86    STX &86 ; block_address_low
&0923 84 87    STY &87 ; block_address_high
&0925 a0 00    LDY #&00
&0927 b1 86    LDA (&86),Y ; block_address                          # Bytes 0 - 1 of block are address of filename
&0929 aa       TAX
&092a c8       INY
&092b b1 86    LDA (&86),Y ; block_address
&092d a8       TAY
&092e 20 49 09 JSR &0949 ; get_file_metadata                        # Returns carry set if file not found
&0931 b0 e9    BCS &091c ; leave                                    # Leave with carry set if file not found
&0933 a0 06    LDY #&06                                             # Bytes 6 - 9 of block are execution address
&0935 b1 86    LDA (&86),Y ; block_address
&0937 d0 0d    BNE &0946 ; to_run_file_handler
&0939 a0 02    LDY #&02                                             # Bytes 2 - 5 of block are load address
&093b b1 86    LDA (&86),Y ; block_address
&093d 8d e3 0a STA &0ae3 ; read_data_block + 1 (address low)
&0940 c8       INY
&0941 b1 86    LDA (&86),Y ; block_address
&0943 8d e4 0a STA &0ae4 ; read_data_block + 2 (address high)
; to_run_file_handler
&0946 4c 19 0a JMP &0a19 ; load_data                                # Load and decrypt file

; get_file_metadata                                                 # Called with XY = address of filename
&0949 20 bc 09 JSR &09bc ; process_filename
&094c 20 02 0a JSR &0a02 ; read_catalogue
&094f 20 99 09 JSR &0999 ; find_filename_in_catalogue               # Returns carry set if file not found
&0952 b0 c8    BCS &091c ; leave                                    # Leave with carry set to indicate file not found
&0954 e6 85    INC &85 ; catalogue_address_high                     # Second page of catalogue contains file metadata
&0956 a0 00    LDY #&00
&0958 b1 84    LDA (&84),Y ; catalogue_address                      # Bytes 0 - 1 of metadata are load address
&095a 8d e3 0a STA &0ae3 ; read_data_block + 1 (address low)
&095d c8       INY ; 1
&095e b1 84    LDA (&84),Y ; catalogue_address
&0960 8d e4 0a STA &0ae4 ; read_data_block + 2 (address high)
&0963 c8       INY ; 2
&0964 b1 84    LDA (&84),Y ; catalogue_address                      # Bytes 2 - 3 of metadata are execution address
&0966 85 82    STA &82 ; execution_address_low
&0968 c8       INY ; 3
&0969 b1 84    LDA (&84),Y ; catalogue_address
&096b 85 83    STA &83 ; execution_address_high
&096d c8       INY ; 4
&096e b1 84    LDA (&84),Y ; catalogue_address                      # Bytes 4 - 5 of metadata are file length
&0970 08       PHP ; file_length_low
&0971 c8       INY ; 5
&0972 b1 84    LDA (&84),Y ; catalogue_address
&0974 85 80    STA &80 ; pages_to_read
&0976 28       PLP ; file_length_low
&0977 f0 02    BEQ &097b ; skip_extra_page
&0979 e6 80    INC &80 ; pages_to_read                              # Read an extra page if partial number of pages
; skip_extra_page
&097b c8       INY ; 6
&097c b1 84    LDA (&84),Y ; catalogue_address                      # Low two bits of byte 6 and all of byte 7 are start sector
&097e 29 03    AND #&03
&0980 aa       TAX
&0981 c8       INY ; 7
&0982 b1 84    LDA (&84),Y ; catalogue_address
&0984 a0 ff    LDY #&ff
; calculate_track_and_sector_outer_loop
&0986 38       SEC
; calculate_track_and_sector_inner_loop
&0987 c8       INY
&0988 e9 0a    SBC #&0a
&098a b0 fb    BCS &0987 ; calculate_track_and_sector_inner_loop
&098c ca       DEX
&098d 10 f7    BPL &0986 ; calculate_track_and_sector_outer_loop
&098f 69 0a    ADC #&0a
&0991 8d ea 0a STA &0aea ; read_data_block + 8 (sector)             # sector = start_sector MOD 10
&0994 8c e9 0a STY &0ae9 ; read_data_block + 7 (track)              # track  = start_sector DIV 10
&0997 18       CLC
&0998 60       RTS

; find_filename_in_catalogue
&0999 a9 00    LDA #&00 ; &0e00 = catalogue                         # First page of catalogue contains filenames
&099b 85 84    STA &84 ; catalogue_address_low
&099d a9 0e    LDA #&0e
&099f 85 85    STA &85 ; catalogue_address_high
; find_filename_in_catalogue_entry_loop                             # For each entry in the catalogue,
&09a1 18       CLC
&09a2 a5 84    LDA &84 ; catalogue_address_low
&09a4 69 08    ADC #&08
&09a6 85 84    STA &84 ; catalogue_address_low                      # If this is the end of the catalogue,
&09a8 b0 11    BCS &09bb ; leave                                    # Leave with carry set to indicate file not found
&09aa a0 00    LDY #&00
; find_filename_in_catalogue_byte_loop
&09ac b1 84    LDA (&84),Y ; catalogue_address
&09ae 29 5f    AND #&5f                                             # Convert character to uppercase (" " becomes null)
&09b0 d9 88 00 CMP &0088,Y ; filename
&09b3 d0 ec    BNE &09a1 ; find_filename_in_catalogue_entry_loop    # Does the entry match the requested filename?
&09b5 c8       INY
&09b6 c0 08    CPY #&08
&09b8 d0 f2    BNE &09ac ; find_filename_in_catalogue_byte_loop
&09ba 18       CLC                                                  # Leave with carry clear to indicate file found
; leave
&09bb 60       RTS

; process_filename                                                  # Called with XY = address of filename
&09bc 86 84    STX &84 ; filename_address_low
&09be 84 85    STY &85 ; filename_address_high
&09c0 a0 00    LDY #&00
&09c2 b1 84    LDA (&84),Y ; filename_address
&09c4 c9 22    CMP #&22 ; """
&09c6 d0 03    BNE &09cb ; not_quote
&09c8 c8       INY                                                  # Move past any leading quote in filename
&09c9 b1 84    LDA (&84),Y ; filename_address
; not_quote
&09cb 29 5f    AND #&5f                                             # Convert character to uppercase
&09cd 85 8f    STA &8f ; directory_letter
&09cf c8       INY
&09d0 b1 84    LDA (&84),Y ; filename_address
&09d2 c9 2e    CMP #&2e ; "."
&09d4 f0 06    BEQ &09dc ; not_dot                                  # If the filename doesn't start with a directory,
&09d6 88       DEY                                                  # move back to start of filename
&09d7 88       DEY
&09d8 a9 04    LDA #&04
&09da 85 8f    STA &8f ; directory_letter
; not_dot
&09dc a2 00    LDX #&00
; process_filename_loop
&09de c8       INY
&09df b1 84    LDA (&84),Y ; filename_address
&09e1 c9 22    CMP #&22 ; """                                       # Quote, space or CR indicates end of filename
&09e3 f0 11    BEQ &09f6 ; end_of_filename
&09e5 c9 20    CMP #&20 ; " "
&09e7 f0 0d    BEQ &09f6 ; end_of_filename
&09e9 c9 0d    CMP #&0d ; CR
&09eb f0 09    BEQ &09f6 ; end_of_filename
&09ed 29 5f    AND #&5f                                             # Convert character to uppercase
&09ef 95 88    STA &88,X ; filename
&09f1 e8       INX
&09f2 e0 07    CPX #&07
&09f4 d0 e8    BNE &09de ; process_filename_loop
; end_of_filename
; pad_filename_loop
&09f6 e0 07    CPX #&07
&09f8 f0 07    BEQ &0a01 ; leave
&09fa a9 00    LDA #&00
&09fc 95 88    STA &88,X ; filename                                 # Pad remainder of filename with nulls
&09fe e8       INX
&09ff d0 f5    BNE &09f6 ; pad_filename_loop
; leave
&0a01 60       RTS

; read_catalogue
&0a02 a9 00    LDA #&00
&0a04 20 d9 0a JSR &0ad9 ; seek_track
&0a07 a9 00    LDA #&00
&0a09 8d e3 0a STA &0ae3 ; read_data_block + 1 (address low)
&0a0c a9 0e    LDA #&0e ; &0e00 = catalogue
&0a0e 8d e4 0a STA &0ae4 ; read_data_block + 2 (address high)
&0a11 a0 00    LDY #&00
&0a13 a2 00    LDX #&00
&0a15 a9 02    LDA #&02                                             # Read two pages from virtual track 0, sector 0
&0a17 d0 08    BNE &0a21 ; load_data_from_sector_XY                 # as catalogue for intercepted file routines

; load_data
&0a19 ae ea 0a LDX &0aea ; read_data_block + 8 (sector)
&0a1c ac e9 0a LDY &0ae9 ; read_data_block + 7 (track)
&0a1f a5 80    LDA &80 ; pages_to_read
; load_data_from_sector_XY
&0a21 8e ea 0a STX &0aea ; read_data_block + 8 (sector)
&0a24 8c e9 0a STY &0ae9 ; read_data_block + 7 (track)
&0a27 85 81    STA &81 ; pages_remaining
; load_data_loop
&0a29 a5 81    LDA &81 ; sectors_remaining
&0a2b f0 36    BEQ &0a63 ; leave
&0a2d 85 80    STA &80 ; sectors_to_read
&0a2f 18       CLC
&0a30 6d ea 0a ADC &0aea ; read_data_block + 8 (sector)
&0a33 c9 0b    CMP #&0b
&0a35 90 08    BCC &0a3f ; skip_overflow
&0a37 a9 0a    LDA #&0a
&0a39 38       SEC
&0a3a ed ea 0a SBC &0aea ; read_data_block + 8 (sector)
&0a3d 85 80    STA &80 ; sectors_to_read
; skip_overflow
&0a3f a5 81    LDA &81 ; sectors_remaining
&0a41 38       SEC
&0a42 e5 80    SBC &80 ; sectors_to_read
&0a44 85 81    STA &81 ; sectors_remaining
&0a46 a5 80    LDA &80 ; sectors_to_read
&0a48 09 20    ORA #&20 ; 256 byte sectors                          # Use 256 byte sectors
&0a4a 8d eb 0a STA &0aeb ; read_data_block + 9 (size and count)
&0a4d 20 64 0a JSR &0a64 ; read_and_decrypt_data
&0a50 ad e4 0a LDA &0ae4 ; read_data_block + 2 (address high)
&0a53 18       CLC
&0a54 65 80    ADC &80 ; sectors_to_read
&0a56 8d e4 0a STA &0ae4 ; read_data_block + 2 (address high)
&0a59 ee e9 0a INC &0ae9 ; read_data_block + 7 (track)              # Move to start of next virtual track
&0a5c a9 00    LDA #&00
&0a5e 8d ea 0a STA &0aea ; read_data_block + 8 (sector)
&0a61 f0 c6    BEQ &0a29 ; load_data_loop                           # Always branches
; leave
&0a63 60       RTS

; read_and_decrypt_data
&0a64 ad e9 0a LDA &0ae9 ; read_data_block + 7 (track)
&0a67 48       PHA ; virtual track
&0a68 18       CLC
&0a69 69 02    ADC #&02
&0a6b 24 e3    BIT &e3 ; forty_or_eighty_track_drive                # Zero if eighty track drive
&0a6d 30 01    BMI &0a70 ; skip_doubling_track
&0a6f 0a       ASL A
; skip_doubling_track
&0a70 20 d9 0a JSR &0ad9 ; seek_track
&0a73 ad ea 0a LDA &0aea ; read_data_block + 8 (sector)
&0a76 18       CLC
&0a77 69 64    ADC #&64 ; 100                                       # Convert virtual sector and track numbers to actual ones
&0a79 6d e9 0a ADC &0ae9 ; read_data_block + 7 (track)
&0a7c 8d ea 0a STA &0aea ; read_data_block + 8 (sector)
&0a7f a9 c8    LDA #&c8 ; 200
&0a81 38       SEC
&0a82 ed e9 0a SBC &0ae9 ; read_data_block + 7 (track)
&0a85 8d e9 0a STA &0ae9 ; read_data_block + 7 (track)
&0a88 20 cd 0a JSR &0acd ; set_track_register
&0a8b a2 e2    LDX #&e2 ; &0ae2 = read_data_block
&0a8d a0 0a    LDY #&0a
&0a8f 20 d4 0a JSR &0ad4 ; floppy_disc_operation
&0a92 ad f4 0a LDA &0af4 ; seek_track_block + 7 (value)             # Track, set at &0acd
&0a95 20 cd 0a JSR &0acd ; set_track_register
&0a98 68       PLA ; virtual track
&0a99 8d e9 0a STA &0ae9 ; read_data_block + 7 (track)
&0a9c ad e3 0a LDA &0ae3 ; read_data_block + 1 (address low)
&0a9f 85 84    STA &84 ; data_address_low
&0aa1 ad e4 0a LDA &0ae4 ; read_data_block + 2 (address high)
&0aa4 85 85    STA &85 ; data_address_high
; decrypt_data_page_loop
&0aa6 ad eb 0a LDA &0aeb ; read_data_block + 9 (size and count)
&0aa9 c9 20    CMP #&20 ; 256 byte sectors
&0aab f0 17    BEQ &0ac4 ; leave_after_setting_break_effect         # Leave if no more pages to decrypt
&0aad a0 00    LDY #&00
; decrypt_data_byte_loop
&0aaf 98       TYA                                                  # Decrypt data using byte position in page 
&0ab0 4d ea 0a EOR &0aea ; read_data_block + 8 (sector)             # and actual sector number
&0ab3 51 84    EOR (&84),Y ; data_address
&0ab5 91 84    STA (&84),Y ; data_address
&0ab7 c8       INY
&0ab8 d0 f5    BNE &0aaf ; decrypt_data_byte_loop
&0aba ee ea 0a INC &0aea ; read_data_block + 8 (sector)
&0abd e6 85    INC &85 ; data_address_high
&0abf ce eb 0a DEC &0aeb ; read_data_block + 9 (size and count)
&0ac2 d0 e2    BNE &0aa6 ; decrypt_data_page_loop                   # Always branches
; leave_after_setting_break_effect
&0ac4 a9 c8    LDA #&c8 ; Read/Write BREAK/ESCAPE effect
&0ac6 a2 03    LDX #&03 ; Clear memory on next RESET
&0ac8 a0 00    LDY #&00
&0aca 4c f4 ff JMP &fff4 ; OSBYTE

; set_track_register
&0acd 8d fe 0a STA &0afe ; set_track_register_block + 8 (value)
&0ad0 a2 f6    LDX #&f6 ; &0af6 = set_track_register_block
&0ad2 a0 0a    LDY #&0a
; floppy_disc_operation
&0ad4 a9 7f    LDA #&7f ; Floppy disk operation
&0ad6 4c f1 ff JMP &fff1 ; OSWORD

; seek_track
&0ad9 8d f4 0a STA &0af4 ; seek_track_block + 7 (value)
&0adc a2 ed    LDX #&ed ; &0aed = seek_track_block
&0ade a0 0a    LDY #&0a
&0ae0 d0 f2    BNE &0ad4 ; floppy_disc_operation                    # Always branches

; read_data_block
&0ae2 ff          ; drive
&0ae3 ff ff ff ff ; address (value is overwritten)
&0ae7 03          ; parameters
&0ae8 53          ; command
&0ae9 00          ; track (value is overwritten)
&0aea 00          ; sector (value is overwritten)
&0aeb 00          ; size and count (value is overwritten)
&0aec 00          ; result

; seek_track_block
&0aed 00          ; drive 0
&0aee ff ff ff ff ; address
&0af2 01          ; parameters
&0af3 69          ; command : seek
&0af4 00          ; track (value is overwritten)
&0af5 00          ; result

; set_track_register_block
&0af6 ff          ; drive
&0af7 ff ff ff ff ; address
&0afb 02          ; parameters
&0afc 7a          ; command : write special register 
&0afd 12          ; register : track register
&0afe 00          ; value (value is overwritten)
&0aff 00          ; result


BASIC loader
============
; !B
; 000E00 00802B 0000DC

&1900 0d                                                            # Start of BASIC program

&1901 00 0a 08 f4 20 21 42 0d                         ;  10REM !B

&1909 00 14 08 ee 85 20 f9 0d                         ;  20ONERROR RUN

&1911 00 1e 0e 2a 46 58 32 35 34 2c 31 32 38 0d       ;  30*FX254,128

&191f 00 28 26 20 e7 20 3f 26 32 30 46 3d 32 20 3f 26 ;  40 IF ?&20F=2                  # Reset OSWRCH vector
&192f 32 30 45 3d 3f 26 32 33 30 3a 3f 26 32 30 46 3d ;        ?&20E=?&230:?&20F=?&231
&193f 3f 26 32 33 31 0d

&1945 00 32 06 eb 35 0d                               ;  50MODE5

&194b 00 3c 25 ef 32 33 3b 38 32 30 32 3b 30 3b 30 3b ;  60VDU23;8202;0;0;0;            # Disable cursor
&195b 30 3b 31 39 2c 31 2c 35 3b 30 3b 31 39 2c 32 2c ;       19,1,5;0;                 # Set colour 1 to magenta
&196b 34 3b 30 3b 0d                                  ;       19,2,4;0;                 # Set colour 2 to blue

&1970 00 46 12 ef 32 33 2c 30 2c 31 3b 30 3b 30 3b 30 ;  70VDU23,0,1;0;0;0;             # Hide display
&1980 3b 0d

&1982 00 50 0d 2a 4c 4f 2e 45 58 49 4c 45 0d          ;  80*LO.EXILE                    # Load loading screen

&198f 00 5a 14 ef 32 33 2c 30 2c 31 2c 34 30 3b 30 3b ;  90VDU23,0,1,40;0;0;0           # Reveal display
&199f 30 3b 30 0d

&19a3 00 64 10 54 25 3d 91 3a 2a 46 58 31 35 2c 30 0d ; 100T%=TIME:*FX15,0              # Flush all buffers

&19b3 00 6e 19 f5 fd 91 3e 54 25 2b 38 30 30 20 84 a6 ; 110REPEATUNTILTIME>T%+800 ORINKEY(10)<>-1
&19c3 28 31 30 29 3c 3e 2d 31 0d

&19cc 00 78 0f 2a 52 55 4e 20 45 58 49 4c 45 4c 0d    ; 120*RUN EXILEL                  # Run the Supervisor

&19db ff                                                            # End of BASIC program


Supervisor disassembly
======================
; ExileL
; 003000 0075D6 45E3

# &3000 - &75b7 is decrypted at &74b7

# &3000 - &74df is moved to &1500 - &59df at &75dd

# Object types are as per game

; object_types_sprite_table                                         # Sprite used for object by default
;      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
&1500 04 14 04 75 1e 1b 10 10 10 1c 1c 20 70 70 61 52 ; &00
&1510 72 4f 21 08 08 21 21 08 08 21 78 78 13 13 13 5e ; &10
&1520 5e 15 16 16 16 16 04 52 45 64 64 64 64 64 59 59 ; &20
&1530 59 59 6d 63 63 0b 0f 17 14 17 39 17 4a 4b 3c 41 ; &30
&1540 1a 71 2e 5d 17 20 56 57 47 22 60 7b 76 76 58 58 ; &40
&1550 21 4d 4d 4d 4d 20 4d 4d 22 6b 6c 6c 79 6c 04 7a ; &50
&1560 63 7c 7c 79 77                                  ; &60

; object_types_palette_and_pickup_table                             # 8....... set if object can be picked up by player
;      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f               # .4218421 palette
&1565 3e 1b 2e f2 32 32 53 05 0f 14 29 bc 65 65 f7 97 ; &00
&1575 d3 c7 ef 7e 5f 3c 5a 11 2d 34 e1 80 55 1b 4c 59 ; &10
&1585 23 72 2e 7b 77 33 39 8b 44 51 0d 46 2b 53 35 3c ; &20
&1595 02 01 70 9c cf 00 14 10 4b 10 0c 34 6b 6b 42 42 ; &30
&15a5 31 6f 15 2e 12 cb 33 b1 62 00 db 9f 8f cf e5 8e ; &40
&15b5 ef ab ad 95 9c 91 92 a6 91 b1 8e e0 a2 b5 b3 e3 ; &50
&15c5 d5 e3 d7 f0 71                                  ; &60

# Scoring
# =======
# object type                                score                  count
# &1626 &02 ; OBJECT_CREW_MEMBER             &15f8 &f0   2 present (&15ca), -6000 each
# &1627 &03 ; OBJECT_FLUFFY                  &15f9 &c8   1 present (&15cb), -5000
# &1628 &04 ; OBJECT_SMALL_HIVE              &15fa &3c   3 present (&15cc),  1500 each
# &1629 &05 ; OBJECT_LARGE_HIVE              &15fb &28   5 present (&15cd),  1000 each
# &162a &07 ; OBJECT_GREEN_FROGMAN           &15fc &28   2 present (&15ce),  1000 each
# &162b &08 ; OBJECT_INVISIBLE_FROGMAN       &15fd &3c   1 present (&15cf),  1500
# &162c &0a ; OBJECT_GREEN_SLIME             &15fe &3c  11 present (&15d0),  1500
# &162d &0f ; OBJECT_WORM                    &15ff &03  43 present (&15d1),    75 each
# &162e &10 ; OBJECT_PIRANHA                 &1600 &08  20 present (&15d2),   200 each
# &162f &11 ; OBJECT_WASP                    &1601 &08  20 present (&15d3),   200 each
# &1630 &1a ; OBJECT_HOVERING_BALL           &1602 &08  38 present (&15d4),   200 each
# &1631 &1b ; OBJECT_INVISIBLE_HOVERING_BALL &1603 &0c  31 present (&15d5),   300
# &1632 &1c ; OBJECT_MAGENTA_ROLLING_ROBOT   &1604 &18   1 present (&15d6),   600
# &1633 &1d ; OBJECT_RED_ROLLING_ROBOT       &1605 &28   2 present (&15d7),  1000 each
# &1634 &1e ; OBJECT_BLUE_ROLLING_ROBOT      &1606 &3c   1 present (&15d8),  1500
# &1635 &1f ; OBJECT_GREEN_WHITE_TURRET      &1607 &28   5 present (&15d9),  1000 each
# &1636 &20 ; OBJECT_CYAN_RED_TURRET         &1608 &50   6 present (&15da),  2000 each
# &1637 &21 ; OBJECT_HOVERING_ROBOT          &1609 &28   2 present (&15db),  1000 each
# &1638 &27 ; OBJECT_MAGGOT                  &160a &08  44 present (&15dc),   200 each
# &1639 &28 ; OBJECT_GARGOYLE                &160b &78   3 present (&15dd),  3000 each
# &163a &29 ; OBJECT_RED_MAGENTA_IMP         &160c &08   8 present (&15de),   200 each
# &163b &2a ; OBJECT_RED_YELLOW_IMP          &160d &20  25 present (&15df),   800 each
# &163c &2b ; OBJECT_BLUE_CYAN_IMP           &160e &10   4 present (&15e0),   400 each
# &163d &2c ; OBJECT_CYAN_YELLOW_IMP         &160f &14   6 present (&15e1),   500 each
# &163e &2d ; OBJECT_RED_CYAN_IMP            &1610 &1c  16 present (&15e2),   700 each
# &163f &2e ; OBJECT_GREEN_YELLOW_BIRD       &1611 &0c   4 present (&15e3),   300 each
# &1640 &2f ; OBJECT_WHITE_YELLOW_BIRD       &1612 &20  13 present (&15e4),   800 each
# &1641 &30 ; OBJECT_RED_MAGENTA_BIRD        &1613 &50  14 present (&15e5),  2000 each
# &1642 &31 ; OBJECT_INVISIBLE_BIRD          &1614 &30  20 present (&15e6),  1200 each
# &1643 &51 ; OBJECT_CYAN_YELLOW_GREEN_KEY   &1615 &64   1 present (&15e7),  2500
# &1644 &52 ; OBJECT_RED_YELLOW_GREEN_KEY    &1616 &28   1 present (&15e8),  1000
# &1645 &53 ; OBJECT_GREEN_YELLOW_RED_KEY    &1617 &3c   1 present (&15e9),  1500
# &1646 &54 ; OBJECT_YELLOW_WHITE_RED_KEY    &1618 &50   1 present (&15ea),  2000
# &1647 &56 ; OBJECT_RED_MAGENTA_RED_KEY     &1619 &78   1 present (&15eb),  3000
# &1648 &57 ; OBJECT_BLUE_CYAN_GREEN_KEY     &161a &a0   1 present (&15ec),  4000
# &1649 &59 ; OBJECT_JETPACK_BOOSTER         &161b &28   1 present (&15ed),  1000
# &164a &5a ; OBJECT_PISTOL                  &161c &28   1 present (&15ee),  1000
# &164b &5b ; OBJECT_ICER                    &161d &3c   1 present (&15ef),  1500
# &164c &5c ; OBJECT_BLASTER                 &161e &50   1 present (&15f0),  2000
# &164d &5d ; OBJECT_PLASMA_GUN              &161f &50   1 present (&15f1),  2000
# &164e &5e ; OBJECT_PROTECTION_SUIT         &1620 &3c   1 present (&15f2),  1500
# &164f &5f ; OBJECT_FIRE_IMMUNITY_DEVICE    &1621 &3c   1 present (&15f3),  1500
# &1650 &60 ; OBJECT_MUSHROOM_IMMUNITY_PILL  &1622 &3c   1 present (&15f4),  1500
# &1651 &61 ; OBJECT_WHISTLE_ONE             &1623 &3c   1 present (&15f5),  1500
# &1652 &62 ; OBJECT_WHISTLE_TWO             &1624 &3c   1 present (&15f6),  1500
# &1653 &63 ; OBJECT_RADIATION_IMMUNITY_PILL &1625 &50   1 present (&15f7),  2000
#
# Maximum score for destroying / collecting objects: 230525

; objects_to_check_for_scoring_default_counts                       # Will be populated with number of objects in default position
&15ca 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e
&15da 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e
&15ea 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e

; objects_to_check_for_scoring_scores
&15f8 f0 c8 3c 28 28 3c 3c 03 08 08 08 0c 18 28 3c 28
&1608 50 28 08 78 08 20 10 14 1c 0c 20 50 30 64 28 3c
&1618 50 78 a0 28 28 3c 50 50 3c 3c 3c 3c 3c 50

; objects_to_check_for_scoring_types
&1626 02 03 04 05 07 08 0a 0f 10 11 1a 1b 1c 1d 1e 1f
&1636 20 21 27 28 29 2a 2b 2c 2d 2e 2f 30 31 51 52 53
&1646 54 56 57 59 5a 5b 5c 5d 5e 5f 60 61 62 63

# Update routines
# ===============
# Tile update routines are called when the tiles are plotted in the supervisor:
#
# tile type                                   low       high        update routine
# &00 TILE_INVISIBLE_SWITCH                 : &1654 &84 &16cd &20 ; &3ad5 ; update_invisible_switch_tile (null function)
# &01 TILE_TRANSPORTER                      : &1655 &79 &16ce &b0 ; &3aca ; update_transporter_tile
# &02 TILE_SPACE_WITH_OBJECT_FROM_DATA      : &1656 &8e &16cf &90 ; &3adf ; update_tile_with_object_from_data
# &03 TILE_METAL_DOOR                       : &1657 &31 &16d0 &f0 ; &3a82 ; update_metal_door_tile
# &04 TILE_EARTH_DOOR                       : &1658 &2e &16d1 &f0 ; &3a7f ; update_stone_door_tile
# &05 TILE_STONE_HALF_WITH_OBJECT_FROM_TYPE : &1659 &86 &16d2 &b0 ; &3ad7 ; update_tile_with_object_from_type
# &06 TILE_SPACE_WITH_OBJECT_FROM_TYPE      : &165a &86 &16d3 &b0 ; &3ad7 ; update_tile_with_object_from_type
# &07 TILE_GREENERY_WITH_OBJECT_FROM_TYPE   : &165b &86 &16d4 &b0 ; &3ad7 ; update_tile_with_object_from_type
# &08 TILE_SWITCH                           : &165c &9c &16d5 &b0 ; &3aed ; update_switch_tile
# &09 TILE_NEST                             : &165d &00 &16d6 &b0 ; &3a51 ; update_nest_or_pipe_tile
# &0a TILE_PIPE                             : &165e &00 &16d7 &b0 ; &3a51 ; update_nest_or_pipe_tile
# &0b TILE_CONSTANT_WIND                    : &165f &85 &16d8 &30 ; &3ad6 ; update_wind_or_water_tile (null function)
# &0c TILE_ENGINE                           : &1660 &29 &16d9 &90 ; &3a7a ; update_engine_tile (null function)
# &0d TILE_WATER                            : &1661 &85 &16da &30 ; &3ad6 ; update_wind_or_water_tile (null function)
# &0e TILE_VARIABLE_WIND                    : &1662 &85 &16db &30 ; &3ad6 ; update_wind_or_water_tile (null function)
# &0f TILE_MUSHROOMS                        : &1663 &a1 &16dc &30 ; &3af2 ; update_mushroom_tile (null function)
#
# Explosion update routines are not used in the supervisor:
#
# explosion type
# &10 &00 indestructible                    : &1664 &f4 &16dd &00 ; &3b45 ; null_update_one
# &11 &40 explode with loud squeal          : &1665 &f4 &16de &00 ; &3b45 ; null_update_one
# &12 &80 explode with no squeal            : &1666 &f4 &16df &00 ; &3b45 ; null_update_one
# &13 &c0 explode with squeal               : &1667 &f4 &16e0 &00 ; &3b45 ; null_update_one
#
# Object update routines are called when the objects are plotted in the supervisor:
#
# object type                          low       high        update routine
# &00 OBJECT_PLAYER                  : &1668 &01 &16e1 &05 ; &3f52 ; null_update_two
# &01 OBJECT_ACTIVE_CHATTER          : &1669 &f5 &16e2 &00 ; &3b46 ; set_this_object_x_flip_from_data
# &02 OBJECT_CREW_MEMBER             : &166a &f5 &16e3 &80 ; &3b46 ; set_this_object_x_flip_from_data
# &03 OBJECT_FLUFFY                  : &166b &f4 &16e4 &80 ; &3b45 ; null_update_one
# &04 OBJECT_SMALL_HIVE              : &166c &02 &16e5 &c5 ; &3f53 ; null_update_three
# &05 OBJECT_LARGE_HIVE              : &166d &02 &16e6 &c5 ; &3f53 ; null_update_three
# &06 OBJECT_RED_FROGMAN             : &166e &f5 &16e7 &80 ; &3b46 ; set_this_object_x_flip_from_data
# &07 OBJECT_GREEN_FROGMAN           : &166f &f5 &16e8 &80 ; &3b46 ; set_this_object_x_flip_from_data
# &08 OBJECT_INVISIBLE_FROGMAN       : &1670 &f5 &16e9 &80 ; &3b46 ; set_this_object_x_flip_from_data
# &09 OBJECT_RED_SLIME               : &1671 &f5 &16ea &00 ; &3b46 ; set_this_object_x_flip_from_data
# &0a OBJECT_GREEN_SLIME             : &1672 &f4 &16eb &00 ; &3b45 ; null_update_one
# &0b OBJECT_YELLOW_SLIME            : &1673 &f4 &16ec &00 ; &3b45 ; null_update_one
# &0c OBJECT_DENSE_NEST              : &1674 &f5 &16ed &00 ; &3b46 ; set_this_object_x_flip_from_data
# &0d OBJECT_SUCKING_NEST            : &1675 &5a &16ee &05 ; &3fab ; null_update_four
# &0e OBJECT_BIG_FISH                : &1676 &f5 &16ef &80 ; &3b46 ; set_this_object_x_flip_from_data
# &0f OBJECT_WORM                    : &1677 &f4 &16f0 &80 ; &3b45 ; null_update_one
# &10 OBJECT_PIRANHA                 : &1678 &5a &16f1 &c5 ; &3fab ; null_update_four
# &11 OBJECT_WASP                    : &1679 &5a &16f2 &85 ; &3fab ; null_update_four
# &12 OBJECT_ACTIVE_GRENADE          : &167a &f4 &16f3 &c0 ; &3b45 ; null_update_one
# &13 OBJECT_ICER_BULLET             : &167b &f5 &16f4 &c0 ; &3b46 ; set_this_object_x_flip_from_data
# &14 OBJECT_TRACER_BULLET           : &167c &f5 &16f5 &c0 ; &3b46 ; set_this_object_x_flip_from_data
# &15 OBJECT_CANNONBALL              : &167d &f4 &16f6 &c0 ; &3b45 ; null_update_one
# &16 OBJECT_BLUE_DEATH_BALL         : &167e &f4 &16f7 &c0 ; &3b45 ; null_update_one
# &17 OBJECT_RED_BULLET              : &167f &f4 &16f8 &c0 ; &3b45 ; null_update_one
# &18 OBJECT_PISTOL_BULLET           : &1680 &f5 &16f9 &c0 ; &3b46 ; set_this_object_x_flip_from_data
# &19 OBJECT_PLASMA_BALL             : &1681 &01 &16fa &85 ; &3f52 ; null_update_two
# &1a OBJECT_HOVERING_BALL           : &1682 &02 &16fb &45 ; &3f53 ; null_update_three
# &1b OBJECT_INVISIBLE_HOVERING_BALL : &1683 &02 &16fc &45 ; &3f53 ; null_update_three
# &1c OBJECT_MAGENTA_ROLLING_ROBOT   : &1684 &5a &16fd &45 ; &3fab ; null_update_four
# &1d OBJECT_RED_ROLLING_ROBOT       : &1685 &5a &16fe &45 ; &3fab ; null_update_four
# &1e OBJECT_BLUE_ROLLING_ROBOT      : &1686 &5a &16ff &45 ; &3fab ; null_update_four
# &1f OBJECT_GREEN_WHITE_TURRET      : &1687 &5a &1700 &45 ; &3fab ; null_update_four
# &20 OBJECT_CYAN_RED_TURRET         : &1688 &5a &1701 &45 ; &3fab ; null_update_four
# &21 OBJECT_HOVERING_ROBOT          : &1689 &f5 &1702 &40 ; &3b46 ; set_this_object_x_flip_from_data
# &22 OBJECT_MAGENTA_CLAWED_ROBOT    : &168a &f5 &1703 &40 ; &3b46 ; set_this_object_x_flip_from_data
# &23 OBJECT_CYAN_CLAWED_ROBOT       : &168b &f5 &1704 &40 ; &3b46 ; set_this_object_x_flip_from_data
# &24 OBJECT_GREEN_CLAWED_ROBOT      : &168c &f5 &1705 &40 ; &3b46 ; set_this_object_x_flip_from_data
# &25 OBJECT_RED_CLAWED_ROBOT        : &168d &f5 &1706 &40 ; &3b46 ; set_this_object_x_flip_from_data
# &26 OBJECT_TRIAX                   : &168e &f5 &1707 &00 ; &3b46 ; set_this_object_x_flip_from_data
# &27 OBJECT_MAGGOT                  : &168f &5a &1708 &85 ; &3fab ; null_update_four
# &28 OBJECT_GARGOYLE                : &1690 &f4 &1709 &c0 ; &3b45 ; null_update_one
# &29 OBJECT_RED_MAGENTA_IMP         : &1691 &f5 &170a &80 ; &3b46 ; set_this_object_x_flip_from_data
# &2a OBJECT_RED_YELLOW_IMP          : &1692 &f5 &170b &80 ; &3b46 ; set_this_object_x_flip_from_data
# &2b OBJECT_BLUE_CYAN_IMP           : &1693 &f5 &170c &80 ; &3b46 ; set_this_object_x_flip_from_data
# &2c OBJECT_CYAN_YELLOW_IMP         : &1694 &f5 &170d &80 ; &3b46 ; set_this_object_x_flip_from_data
# &2d OBJECT_RED_CYAN_IMP            : &1695 &f5 &170e &80 ; &3b46 ; set_this_object_x_flip_from_data
# &2e OBJECT_GREEN_YELLOW_BIRD       : &1696 &f5 &170f &80 ; &3b46 ; set_this_object_x_flip_from_data
# &2f OBJECT_WHITE_YELLOW_BIRD       : &1697 &f5 &1710 &80 ; &3b46 ; set_this_object_x_flip_from_data
# &30 OBJECT_RED_MAGENTA_BIRD        : &1698 &f5 &1711 &80 ; &3b46 ; set_this_object_x_flip_from_data
# &31 OBJECT_INVISIBLE_BIRD          : &1699 &01 &1712 &85 ; &3f52 ; null_update_two
# &32 OBJECT_LIGHTNING               : &169a &f4 &1713 &00 ; &3b45 ; null_update_one
# &33 OBJECT_RED_MUSHROOM_BALL       : &169b &f5 &1714 &00 ; &3b46 ; set_this_object_x_flip_from_data
# &34 OBJECT_BLUE_MUSHROOM_BALL      : &169c &f5 &1715 &00 ; &3b46 ; set_this_object_x_flip_from_data
# &35 OBJECT_INVISIBLE_DEBRIS        : &169d &f5 &1716 &00 ; &3b46 ; set_this_object_x_flip_from_data
# &36 OBJECT_RED_DROP                : &169e &f5 &1717 &c0 ; &3b46 ; set_this_object_x_flip_from_data
# &37 OBJECT_FIREBALL                : &169f &02 &1718 &05 ; &3f53 ; null_update_three
# &38 OBJECT_INACTIVE_CHATTER        : &16a0 &f5 &1719 &00 ; &3b46 ; set_this_object_x_flip_from_data
# &39 OBJECT_MOVING_FIREBALL         : &16a1 &f4 &171a &00 ; &3b45 ; null_update_one
# &3a OBJECT_GIANT_BLOCK             : &16a2 &f4 &171b &00 ; &3b45 ; null_update_one
# &3b OBJECT_ENGINE_FIRE             : &16a3 &02 &171c &05 ; &3f53 ; null_update_three
# &3c OBJECT_HORIZONTAL_METAL_DOOR   : &16a4 &03 &171d &c5 ; &3f54 ; update_door
# &3d OBJECT_VERTICAL_METAL_DOOR     : &16a5 &03 &171e &c5 ; &3f54 ; update_door
# &3e OBJECT_HORIZONTAL_STONE_DOOR   : &16a6 &03 &171f &c5 ; &3f54 ; update_door
# &3f OBJECT_VERTICAL_STONE_DOOR     : &16a7 &03 &1720 &c5 ; &3f54 ; update_door
# &40 OBJECT_BUSH                    : &16a8 &02 &1721 &05 ; &3f53 ; null_update_three
# &41 OBJECT_TRANSPORTER_BEAM        : &16a9 &3c &1722 &05 ; &3f8d ; update_transporter_beam
# &42 OBJECT_SWITCH                  : &16aa &f5 &1723 &c0 ; &3b46 ; set_this_object_x_flip_from_data
# &43 OBJECT_PIANO                   : &16ab &01 &1724 &05 ; &3f52 ; null_update_two
# &44 OBJECT_EXPLOSION               : &16ac &5b &1725 &05 ; &3fac ; null_update_five
# &45 OBJECT_BOULDER                 : &16ad &01 &1726 &05 ; &3f52 ; null_update_two
# &46 OBJECT_CANNON                  : &16ae &f5 &1727 &00 ; &3b46 ; set_this_object_x_flip_from_data
# &47 OBJECT_ALIEN_WEAPON            : &16af &f4 &1728 &40 ; &3b45 ; null_update_one
# &48 OBJECT_MAGGOT_MACHINE          : &16b0 &f4 &1729 &00 ; &3b45 ; null_update_one
# &49 OBJECT_PLACEHOLDER             : &16b1 &02 &172a &05 ; &3f53 ; null_update_three
# &4a OBJECT_DESTINATOR              : &16b2 &f4 &172b &00 ; &3b45 ; null_update_one
# &4b OBJECT_POWER_POD               : &16b3 &f4 &172c &80 ; &3b45 ; null_update_one
# &4c OBJECT_EMPTY_FLASK             : &16b4 &01 &172d &05 ; &3f52 ; null_update_two
# &4d OBJECT_FULL_FLASK              : &16b5 &02 &172e &05 ; &3f53 ; null_update_three
# &4e OBJECT_REMOTE_CONTROL_DEVICE   : &16b6 &f4 &172f &00 ; &3b45 ; null_update_one
# &4f OBJECT_CANNON_CONTROL_DEVICE   : &16b7 &f4 &1730 &00 ; &3b45 ; null_update_one
# &50 OBJECT_INACTIVE_GRENADE        : &16b8 &f4 &1731 &c0 ; &3b45 ; null_update_one
# &51 OBJECT_CYAN_YELLOW_GREEN_KEY   : &16b9 &f4 &1732 &00 ; &3b45 ; null_update_one
# &52 OBJECT_RED_YELLOW_GREEN_KEY    : &16ba &f4 &1733 &00 ; &3b45 ; null_update_one
# &53 OBJECT_GREEN_YELLOW_RED_KEY    : &16bb &f4 &1734 &00 ; &3b45 ; null_update_one
# &54 OBJECT_YELLOW_WHITE_RED_KEY    : &16bc &f4 &1735 &00 ; &3b45 ; null_update_one
# &55 OBJECT_CORONIUM_BOULDER        : &16bd &f4 &1736 &00 ; &3b45 ; null_update_one
# &56 OBJECT_RED_MAGENTA_RED_KEY     : &16be &f4 &1737 &00 ; &3b45 ; null_update_one
# &57 OBJECT_BLUE_CYAN_GREEN_KEY     : &16bf &f4 &1738 &00 ; &3b45 ; null_update_one
# &58 OBJECT_CORONIUM_CRYSTAL        : &16c0 &f4 &1739 &00 ; &3b45 ; null_update_one
# &59 OBJECT_JETPACK_BOOSTER         : &16c1 &f4 &173a &00 ; &3b45 ; null_update_one
# &5a OBJECT_PISTOL                  : &16c2 &f4 &173b &00 ; &3b45 ; null_update_one
# &5b OBJECT_ICER                    : &16c3 &f4 &173c &00 ; &3b45 ; null_update_one
# &5c OBJECT_BLASTER                 : &16c4 &f4 &173d &00 ; &3b45 ; null_update_one
# &5d OBJECT_PLASMA_GUN              : &16c5 &f4 &173e &00 ; &3b45 ; null_update_one
# &5e OBJECT_PROTECTION_SUIT         : &16c6 &f4 &173f &00 ; &3b45 ; null_update_one
# &5f OBJECT_FIRE_IMMUNITY_DEVICE    : &16c7 &f4 &1740 &00 ; &3b45 ; null_update_one
# &60 OBJECT_MUSHROOM_IMMUNITY_PILL  : &16c8 &f4 &1741 &00 ; &3b45 ; null_update_one
# &61 OBJECT_WHISTLE_ONE             : &16c9 &f4 &1742 &00 ; &3b45 ; null_update_one
# &62 OBJECT_WHISTLE_TWO             : &16ca &f4 &1743 &00 ; &3b45 ; null_update_one
# &63 OBJECT_RADIATION_IMMUNITY_PILL : &16cb &f4 &1744 &00 ; &3b45 ; null_update_one
# &64 OBJECT_INVISIBLE_INERT         : &16cc &01 &1745 &05 ; &3f52 ; null_update_two

; update_routine_addresses_low_table
;      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f               # tiles and explosions
&1654 84 79 8e 31 2e 86 86 86 9c 00 00 85 29 85 85 a1 ; &00
&1664 f4 f4 f4 f4                                     ; &10
;      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f               # objects
&1668 01 f5 f5 f4 02 02 f5 f5 f5 f5 f4 f4 f5 5a f5 f4 ; &00
&1678 5a 5a f4 f5 f5 f4 f4 f4 f5 01 02 02 5a 5a 5a 5a ; &10
&1688 5a f5 f5 f5 f5 f5 f5 5a f4 f5 f5 f5 f5 f5 f5 f5 ; &20
&1698 f5 01 f4 f5 f5 f5 f5 02 f5 f4 f4 02 03 03 03 03 ; &30
&16a8 02 3c f5 01 5b 01 f5 f4 f4 02 f4 f4 01 02 f4 f4 ; &40
&16b8 f4 f4 f4 f4 f4 f4 f4 f4 f4 f4 f4 f4 f4 f4 f4 f4 ; &50
&16c8 f4 f4 f4 f4 01                                  ; &60

; update_routine_addresses_high_table
;      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f               # tiles and explosions
&16cd 20 b0 90 f0 f0 b0 b0 b0 b0 b0 b0 30 90 30 30 30 ; &00
&16dd 00 00 00 00                                     ; &10
;      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f               # objects
&16e1 05 00 80 80 c5 c5 80 80 80 00 00 00 00 05 80 80 ; &00
&16f1 c5 85 c0 c0 c0 c0 c0 c0 c0 85 45 45 45 45 45 45 ; &10
&1701 45 40 40 40 40 40 00 85 c0 80 80 80 80 80 80 80 ; &20
&1711 80 85 00 00 00 00 c0 05 00 00 00 05 c5 c5 c5 c5 ; &30
&1721 05 05 c0 05 05 05 00 40 00 05 00 80 05 05 00 00 ; &40
&1731 c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ; &50
&1741 00 00 00 00 05                                  ; &60

# Tile types are as per game

; tiles_sprite_and_y_flip_table                                     # 8....... if set, flip vertically for collision checking
;      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f               #          i.e. for unflipped tile, obstruction is at top
;                                                                   #          otherwise, for unflipped tile, obstruction is at bottom
&1746 c6 ce c6 c6 c6 bb c6 18 2d 70 6a c6 23 39 c6 62 ; &00         # .4218421 sprite
&1756 c0 8e 39 44 47 26 48 49 df c6 99 9a 25 2b 39 3b ; &10
&1766 3c 55 8e 43 34 35 27 28 29 2a 42 bf 40 3d 38 36 ; &20
&1776 37 3e 33 31 2f 30 2c 24 32 41 45 3a 6a 23 60 cc ; &30

; tiles_y_offset_and_pattern_table                                  # 8421.... start of tile from top of tile, in &10 fractions
;      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f               # ....8421 set of four patterns to use from &05ab
&1786 00 00 00 00 00 00 00 d0 c0 b0 c0 00 00 00 00 c0 ; &00
&1796 b0 a0 00 00 00 00 80 c0 70 00 b0 80 90 00 00 80 ; &10
&17a6 c0 00 a0 00 00 80 00 40 80 c0 00 f0 b0 00 00 00 ; &20
&17b6 80 70 00 c0 c0 00 80 00 80 00 90 30 c0 00 a0 00 ; &30

; tiles_palette_table                                               # &00 - &06 to set palette from function, otherwise value
;      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
&17c6 80 02 91 91 91 00 91 a8 dc b8 8c 80 c9 4a 80 06 ; &00
&17d6 88 05 04 00 02 02 02 02 02 91 03 03 02 02 00 00 ; &10
&17e6 00 bc b1 00 00 00 01 01 01 01 00 04 04 04 04 04 ; &20
&17f6 04 04 02 01 01 01 02 02 02 00 00 00 82 02 64 ee ; &30

; tile_tertiary_object_ranges_table
;      0  1  2  3  4  5  6  7  8  9
&1806 00 1d 39 57 7a 9e bc d8 f6 fe

; tertiary_objects_data_offset
&1810 01 fe fb fa f8 f5 f5 f3 f3 

; tertiary_objects_type_offset
&1819 00 f5 e9 de ce be b1 a1 98

# Tertiary objects are as per game

; tertiary_objects_x
;      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
&1822 ff ff b0 ec 77 64 9a af da c6 36 9f 2e a9 9c 83 ; &00
&1832 88 5f 57 bf 9d 4d 45 81 b3 3f cb 40 4c ca 2f a7 ; &10
&1842 56 34 e3 3b e4 80 e0 64 37 47 9f 9c aa 9b 9a 5e ; &20
&1852 c7 8a 60 9d a2 b2 98 a9 db 28 29 3c 98 63 cb 61 ; &30
&1862 a3 ce e9 80 2e 4f 79 87 b6 97 2d d6 5c a0 74 6a ; &40
&1872 a1 9f 89 85 6b ae 65 e2 ed 80 cd a8 2b ab 9d 62 ; &50
&1882 e5 70 ec 83 c1 c6 67 eb 2d 98 aa cc a5 9e a2 d7 ; &60
&1892 e6 e7 94 7c e3 45 9b 9f c2 71 67 4f cf d2 e2 7a ; &70
&18a2 62 da 76 b2 66 d7 83 84 80 87 9b 50 ae 64 a3 63 ; &80
&18b2 b8 7f 82 e0 9c 61 9d 29 46 9f 9a 74 75 77 b2 e4 ; &90
&18c2 62 63 82 61 d4 d3 77 2e 64 86 a5 a0 d1 b4 7f a3 ; &a0
&18d2 9f 99 80 67 da 89 95 8b ab c4 9d aa bb 47 8a a7 ; &b0
&18e2 61 9e 2e d6 7e da aa ab 45 67 d4 29 b8 6b 69 9d ; &c0
&18f2 94 63 b4 a1 9f a0 57 e1 7f a6 b4 53 61 d4 82 e3 ; &d0
&1902 75 c3 84 9e c6 64 a2 28 29 9d 83 a8 80 aa d5 a0 ; &e0
&1912 9f d6 62 69 2c a5 b8 b9 d9 59 79 39 48 e8 a0    ; &f0

; tertiary_objects_tile_and_flip
;      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
&1921 89 89 89 89 89 8a 46 c6 06 06 46 05 05 00 c3 04 ; &00
&1931 83 84 84 83 88 48 02 02 42 02 7b 22 1e 06 06 c6 ; &10
&1941 06 46 46 85 85 87 89 89 c7 0a 8c 03 84 83 43 84 ; &20
&1951 84 02 01 41 01 01 2e 1e 3b 46 46 06 c6 06 06 06 ; &30
&1961 46 06 09 c9 89 ca 8a 8a 0a 4a 8a 04 44 41 01 c8 ; &40
&1971 48 cc 82 02 02 02 1e 89 09 0a 4a ca 4a 86 46 46 ; &50
&1981 46 86 45 47 00 00 00 00 84 c3 44 43 43 43 44 84 ; &60
&1991 44 04 01 08 08 02 02 82 1e 2d 46 46 45 46 c6 89 ; &70
&19a1 c9 49 89 ca ca 8a 8a 8a 0a 00 00 c4 43 04 43 84 ; &80
&19b1 44 04 44 84 41 01 01 01 c8 42 82 3b 11 3b 89 c9 ; &90
&19c1 ca 8a c6 06 c6 c6 06 06 85 47 4a ca 8a 00 00 44 ; &a0
&19d1 43 c3 44 44 04 41 c8 88 c8 c8 02 8c 49 89 0a 0a ; &b0
&19e1 8a c6 06 06 47 87 cc 41 01 08 08 08 08 c4 84 43 ; &c0
&19f1 43 84 04 83 82 82 0d 0d 46 06 06 06 06 45 45 45 ; &d0
&1a01 06 07 89 09 8a 4a 4a ca ca 4a 00 00 00 48 08 82 ; &e0
&1a11 82 82 02 c4 c4 0b 0b 0b d1 91 d1 d1 91 91 00    ; &f0

# Game state is as per game in default position

; temporary_copy_of_game_state

; rnd_state
&1a20 2e 2e 2e 2e

; player_object_held
&1a24 2e

; player_angle
&1a25 2e

; player_facing
&1a26 2e

; game_time
&1a27 00 00 00 00

; player_deaths
&1a2b 00 00 00

; player_collected
; player_keys_collected
&1a2e 00 ; &00 : OBJECT_CYAN_YELLOW_GREEN_KEY
&1a2f 00 ; &01 : OBJECT_RED_YELLOW_GREEN_KEY
&1a30 00 ; &02 : OBJECT_GREEN_YELLOW_RED_KEY
&1a31 00 ; &03 : OBJECT_YELLOW_WHITE_RED_KEY
&1a32 00 ; &04 : (not collectable)
&1a33 00 ; &05 : OBJECT_RED_MAGENTA_RED_KEY 
&1a34 00 ; &06 : OBJECT_BLUE_CYAN_GREEN_KEY
&1a35 00 ; &07 : (not collectable)
; player_weapons_collected
; player_jetpack_booster_collected
&1a36 00 ; &00 : OBJECT_JETPACK_BOOSTER
&1a37 00 ; &01 : OBJECT_PISTOL
&1a38 00 ; &02 : OBJECT_ICER
&1a39 00 ; &03 : OBJECT_BLASTER
&1a3a 00 ; &04 : OBJECT_PLASMA_GUN
; player_protection_suit_collected
&1a3b 00 ; &05 : OBJECT_PROTECTION_SUIT
; player_fire_immunity_device_collected
&1a3c 00 ; OBJECT_FIRE_IMMUNITY_DEVICE
; player_mushroom_immunity_pill_collected
&1a3d 00 ; OBJECT_MUSHROOM_IMMUNITY_PILL
; player_whistle_one_collected
&1a3e 00 ; OBJECT_WHISTLE_ONE
; player_whistle_two_collected
&1a3f 00 ; OBJECT_WHISTLE_TWO
; player_radiation_immunity_pill_collected
&1a40 00 ; OBJECT_RADIATION_IMMUNITY_PILL

; door_timer
&1a41 00

; player_mushroom_timers
;     r  b
&1a42 00 00

; chatter_energy_reserve
&1a44 00

; explosion_timer
&1a45 00

; flooding_state
&1a46 00

; earthquake_state
&1a47 00

; unused
&1a48 ff

; player_next_teleport
&1a49 00

; player_teleports_remembered
&1a4a 00

; player_teleports_x
&1a4b 32 8e d2 63 99

; player_teleports_y
&1a50 98 c0 c0 c7 3c

; copy_protection_third_byte
&1a55 00

; waterline_x_ranges_y_fraction
&1a56 00 00 00 00

; waterline_x_ranges_y
&1a5a ce df c1 c1

; waterline_x_ranges_desired_y
&1a5e ce df c1 c1

; imp_types_gifts_remaining
;      0  1  2  3  4
&1a62 04 0a 01 01 0a

; clawed_robots_availability
&1a67 80 80 80 80

; clawed_robots_teleporting_energy
&1a6b 00 00 00 00

; player_pockets_used
&1a6f 00

; player_pockets
&1a70 50 ; OBJECT_INACTIVE_GRENADE
&1a71 50 ; OBJECT_INACTIVE_GRENADE
&1a72 50 ; OBJECT_INACTIVE_GRENADE
&1a73 50 ; OBJECT_INACTIVE_GRENADE
&1a74 50 ; OBJECT_INACTIVE_GRENADE

; player_weapon
&1a75 00 ; jetpack

; player_weapons_energy_low
&1a76 00 ; &00 (jetpack)
&1a77 00 ; &01 (pistol)
&1a78 00 ; &02 (icer)
&1a79 00 ; &03 (blaster)
&1a7a 00 ; &04 (plasma gun)
&1a7b 00 ; &05 (protection suit)

; player_weapons_energy_high
&1a7c 30 ; &00 (jetpack)
&1a7d 10 ; &01 (pistol)
&1a7e 10 ; &02 (icer)
&1a7f 01 ; &03 (blaster)
&1a80 08 ; &04 (plasma gun)
&1a81 10 ; &05 (protection suit)

; weapons_energy_cost
&1a82 01 ; &00 (jetpack)
&1a83 06 ; &01 (pistol)
&1a84 10 ; &02 (icer)
&1a85 ff ; &03 (blaster)
&1a86 32 ; &04 (plasma gun)
&1a87 00 ; &05 (protection suit)

; objects_type
&1a88 00 26 60 cc 00 00 00 00 00 00 00 d0 c0 b0 c0 00

; objects_sprite
&1a98 04 04 00 c0 b0 a0 00 00 00 00 80 c0 70 00 b0 80

; objects_x_fraction
&1aa8 c0 64 00 80 c0 00 a0 00 00 80 00 40 80 c0 00 f0 b0

; objects_x
&1ab9 9b 99 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 65 

; objects_y_fraction
&1acb 80 20 02 91 91 91 00 91 a8 dc b8 8c 80 c9 4a 80 06

; objects_y
&1adc 3b 3b 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 dc

; objects_flags
&1aee 81 11 01 01 01 01 01 01 01 01 01 01 01 01 01 01

; objects_palette
&1afe 02 39 01 01 02 02 02 00 00 00 82 02 64 ee ca 34

; objects_velocity_x
&1b0e 00 00 b0 de a1 d9 3c b1 9c f0 d4 75 01 99 8e c0

; objects_velocity_y
&1b1e 00 10 22 59 34 83 82 80 76 68 52 20 55 26 67 0d

; objects_target_object_and_flags
&1b2e 35 00 6f d0 0c 3d 64 69 f6 31 48 18 49 f7 50 97

; objects_tx
&1b3e 47 99 00 16 47 09 34 83 82 80 76 68 52 20 31 42

; objects_energy
&1b4e ff c8 6b 70 43 34 43 3c 75 72 15 3a c4 64 5e ae

; objects_ty
&1b5e 68 3b 32 79 74 64 44 03 22 59 34 83 82 80 0a f1

; objects_touching
&1b6e 9a f4 2c f8 3a c1 36 d0 9b 75 85 88 79 85 38 c9

; objects_timer
&1b7e 87 0e 67 50 16 47 09 34 83 82 80 76 68 52 20 55

; objects_tertiary_data_offset
&1b8e 00 cf e8 83 7d 4b 81 a6 8e 9c 5b 8a 9e 54 86 40

; objects_state
&1b9e f8 ef b9 fc 78 80 76 68 52 20 55 26 67 d0 16 28

; tertiary_objects_data
&1bae 00 7c 60 04 88 88 a0 a6 ae 83 86 82 80 80 ad 81
&1bbe f7 a1 f1 f7 81 8a ac d2 df d4 a3 84 85 ae 80 80
&1bce 88 ac c4 c0 04 a8 c4 bc fd 81 c1 d1 91 f1 f1 da
&1bde f7 f3 d8 88 80 83 83 b0 aa 80 80 87 80 30 08 10
&1bee 7c 04 10 a8 90 04 c1 f1 e1 95 bc b4 fd a1 d6 dd
&1bfe e2 04 0c 04 20 21 a0 b0 ac 83 81 84 80 c4 85 95
&1c0e a3 b5 f1 ad c1 81 89 a0 c1 f1 f1 c1 8c a4 e4 d7
&1c1e 9d e1 a6 81 85 83 83 d0 a8 04 04 d0 88 04 04 04
&1c2e 08 bd 8a f1 d1 f1 b1 f1 c1 c1 c1 c1 e2 e4 dc a0
&1c3e c2 cb b8 a8 10 98 a0 80 83 80 80 80 80 00 c4 40
&1c4e 84 28 75 bc f1 d1 a9 f1 c0 c1 8f 94 c2 ca fa 9c
&1c5e fe 10 14 90 98 04 a4 80 83 c6 c4 fe aa 90 ec dc
&1c6e 9e f4 f7 f1 f1 81 f1 f1 b1 db 9e 84 ac 80 80 80
&1c7e 80 80 80 80 c0 04 08 90 a2 04 04 04 20 bc 53 9d
&1c8e 84 da cb de c5 a5 c1 f1 70 d0 80

; tertiary_objects_type
&1c99 00 0f 27 2e 07 2f 2d 1f 1f 0d 0d 0d 0c 60 2c 00
&1ca9 0d 0d 1f 0d 5c 0d 20 05 04 06 31 05 2a 09 0d 0d
&1cb9 1f 20 55 55 0d 63 0f 2e 0a 1b 37 29 1a 1a 37 37
&1cc9 0a 37 4b 4b 2d 1f 20 0d 0d 28 55 05 80 00 80 80
&1cd9 20 28 0d 0d 28 27 31 0e 08 11 39 37 37 37 2a 80
&1ce9 4a 10 2f 30 30 09 0d 09 09 4f 24 4a 04 1a 39 10
&1cf9 00 4c 0a 2f 29 2c 37 20 3a 0d 05 05 0d 20 0d 0d
&1d09 48 51 0c 55 22 04 2e 2f 2b 2a 21 02 02 1a 80 4b
&1d19 80

; secondary_objects_x
&1d1a 9b a3 98 98 a4 9f a0 c0 48 83 c5 87 97 e1 84 98
&1d2a 99 e7 7c 00 00 00 00 00 00 00 00 00 00 00 00 00 

; secondary_objects_y
&1d3a 39 5d 4d 4d 67 49 49 4e 56 78 60 59 5e 61 5b 80
&1d4a 3c 80 77 00 00 00 00 00 00 00 00 00 00 00 00 00 

; secondary_objects_type
&1d5a 64 43 50 50 59 50 46 50 50 4e 45 53 1d 03 50 50
&1d6a 4a 3a 4c 00 00 00 00 00 00 00 00 00 00 00 00 00

; game_state_checksum_one
&1d7a dc

; secondary_objects_energy_and_x_y_fractions                        # 8421.... energy
&1d7b f0 f3 71 79 fb 42 f5 47 f3 f2 f3 f2 f0 fb f2 40               # ....84.. x fraction
&1d8b fb f0 f1 00 00 00 00 00 00 00 00 00 00 00 00 00               # ......21 y fraction

; secondary_object_update_next_object
&1d9b 00

; secondary_object_update_random_shuffle
&1d9c 00

; game_state_checksum_two
&1d9d 43

; end of game state 

; unused
&1d9e 00

; sprite_foreground_or_background_mask
&1d9f ff

; colours_1_and_2_pixel_values_table
;      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
;     YB GR MR CR WR YG CB MG GG WG bb YC WY YR WM WC               # Right pixel sets colour 1, left pixel sets colour 2
&1da0 ca c9 e3 e9 eb ce f8 e6 cc ee 30 de ef cb fb fe

; screen_size_x_fraction
; screen_size_y_fraction - 2
;     cx px cy py
&1db0 00 ea 00 ea

; screen_size_x
; screen_size_y - 2
;     cx px cy py
&1db4 08 ea 05 ea                                                   # Supervisor screen is eight by five tiles

; fraction_to_pixel_rounding_table
&1db8 f0 f0 f8 f8

; offscreen_flags_to_check_table
&1dbc 05 0a

; to_consider_promoting_secondary_objects_to_primary_objects
&1dbe 4c fa 1d JMP &1dfa ; consider_promoting_secondary_objects_to_primary_objects

# &1dc1 - &2680 is similar to code used in game. Differences are indicated by ***

; promote_secondary_object_to_primary_if_Y_slots_free
&1dc1 bd 3a 1d LDA &1d3a,X ; secondary_objects_y                    # Leave if no secondary object in slot
&1dc4 f0 33    BEQ &1df9 ; leave
&1dc6 bd 5a 1d LDA &1d5a,X ; secondary_objects_type
&1dc9 20 4f 25 JSR &254f ; create_new_object_if_Y_slots_free        # Returns carry clear if object created, X = slot
&1dcc b0 2b    BCS &1df9 ; leave
&1dce bd 1a 1d LDA &1d1a,X ; secondary_objects_x
&1dd1 99 b9 1a STA &1ab9,Y ; objects_x
&1dd4 bd 3a 1d LDA &1d3a,X ; secondary_objects_y
&1dd7 99 dc 1a STA &1adc,Y ; objects_y
&1dda bd 7b 1d LDA &1d7b,X ; secondary_objects_energy_and_x_y_fractions
&1ddd 48       PHA ; energy_and_x_y_fractions
&1dde 09 0f    ORA #&0f                                             # 8421.... energy
&1de0 99 4e 1b STA &1b4e,Y ; objects_energy
&1de3 68       PLA ; energy_and_x_y_fractions
&1de4 0a       ASL A                                                # ....8421 -> 8421....
&1de5 0a       ASL A
&1de6 0a       ASL A
&1de7 0a       ASL A
&1de8 48       PHA ; x_and_y_fractions
&1de9 29 c0    AND #&c0                                             # ....84.. x fraction, accurate to four pixels
&1deb 99 a8 1a STA &1aa8,Y ; objects_x_fraction
&1dee 68       PLA ; x_and_y_fractions
&1def 0a       ASL A                                                # ..21.... -> 21......
&1df0 0a       ASL A
&1df1 99 cb 1a STA &1acb,Y ; objects_y_fraction                     # ......12 y fraction, accurate to eight pixels
&1df4 a9 00    LDA #&00
&1df6 9d 3a 1d STA &1d3a,X ; secondary_objects_y                    # Set to zero to indicate no secondary object in slot
; leave
&1df9 60       RTS
; consider_promoting_secondary_objects_to_primary_objects
&1dfa a2 1f    LDX #&1f                                             # For each secondary object,
; consider_promoting_secondary_objects_to_primary_loop
&1dfc bd 3a 1d LDA &1d3a,X ; secondary_objects_y
&1dff 85 3c    STA &3c ; this_object_y
&1e01 38       SEC                                              ***
&1e02 e5 81    SBC &81 ; screen_start_y                         ***
&1e04 18       CLC                                              ***
&1e05 69 01    ADC #&01                                         ***
&1e07 c9 07    CMP #&07                                         ***
&1e09 b0 14    BCS &1e1f ; consider_next_secondary_object       *** # Is -1 <= relative object y <= 5 ?
&1e0b bd 1a 1d LDA &1d1a,X ; secondary_objects_x                ***
&1e0e 85 3a    STA &3a ; this_object_x                          ***
&1e10 38       SEC                                              ***
&1e11 e5 7f    SBC &7f ; screen_start_x                         ***
&1e13 18       CLC                                              ***
&1e14 69 01    ADC #&01                                         ***
&1e16 c9 0a    CMP #&0a                                         *** # Is -1 <= relative object x <= 9 ?
&1e18 b0 05    BCS &1e1f ; consider_next_secondary_object
&1e1a a0 01    LDY #&01
&1e1c 20 c1 1d JSR &1dc1 ; promote_secondary_object_to_primary_if_Y_slots_free
; consider_next_secondary_object
&1e1f ca       DEX
&1e20 10 da    BPL &1dfc ; consider_promoting_secondary_objects_to_primary_loop
&1e22 60       RTS

; update_object_sprite
&1e23 a9 3f    LDA #&3f                                             # Use background colours, masked by foreground
&1e25 8d 9f 1d STA &1d9f ; sprite_foreground_or_background_mask
&1e28 20 3f 1e JSR &1e3f ; consider_replotting_sprite
&1e2b a6 78    LDX &78 ; this_object
&1e2d 5e ee 1a LSR &1aee,X ; objects_flags                          # Remove previous OBJECT_FLAG_NOT_PLOTTED
&1e30 a5 55    LDA &55 ; offscreen_flags
&1e32 29 05    AND #&05                                             # Non-zero if current sprite is offscreen in x or y
&1e34 c9 01    CMP #&01
&1e36 3e ee 1a ROL &1aee,X ; objects_flags                          # Set OBJECT_FLAG_NOT_PLOTTED if object is offscreen
&1e39 a9 ff    LDA #&ff                                             # Use foreground colours
&1e3b 8d 9f 1d STA &1d9f ; sprite_foreground_or_background_mask
&1e3e 60       RTS



; consider_replotting_sprite
&1e3f a2 03    LDX #&03
&1e41 06 55    ASL &55 ; offscreen_flags                            # If top nibble set, suppress calculating variables if scrolling screen
; calculate_sprite_variables_loop                                   # This code is run four times:
;                                                                   #     X = 3 : previous sprite, y, height, vertical
;                                                                   #         2 : current sprite, y, height, vertical
;                                                                   #         1 : previous sprite, x, width, horizontal
;                                                                   #         0 : current sprite, x, width, horizontal
&1e43 b0 69    BCS &1eae ; set_bit_in_offscreen_flags
&1e45 e0 02    CPX #&02
&1e47 90 2c    BCC &1e75 ; skip_calculating_sizes_and_flips         # For X = 3 and 2, calculate sizes and flips
; calculate_sprite_sizes_and_flips
&1e49 b4 5a    LDY &5a,X ; this_object_sprite - 2
&1e4b b9 ee 54 LDA &54ee,Y ; sprites_height_and_vertical_flip_table
&1e4e 4a       LSR A                                                # Set carry if sprite is vertically flipped
&1e4f b9 00 54 LDA &5400,Y ; sprites_width_and_horizontal_flip_table
&1e52 6a       ROR A                                                # Set carry if sprite if horizontally flipped
&1e53 29 80    AND #&80
&1e55 6a       ROR A                                                # Set &80 if horizontally flipped, &40 if vertically flipped
&1e56 55 56    EOR &56,X ; this_object_flip - 2
&1e58 95 48    STA &48,X ; this_object_sprite_x_flip - 2            # &80 set if horizontally flipped
&1e5a 0a       ASL A
&1e5b 95 4a    STA &4a,X ; this_object_sprite_y_flip - 2            # &80 set if vertically flipped
&1e5d b9 00 54 LDA &5400,Y ; sprites_width_and_horizontal_flip_table
&1e60 29 f0    AND #&f0                                             # 8421.... width of sprite in pixels, minus one
&1e62 95 30    STA &30,X ; this_object_sprite_width - 2
&1e64 b9 ee 54 LDA &54ee,Y ; sprites_height_and_vertical_flip_table
&1e67 29 f8    AND #&f8                                             # 84218... height of sprite in rows, minus one
&1e69 95 32    STA &32,X ; this_object_sprite_height - 2
&1e6b b9 dc 55 LDA &55dc,Y ; sprites_spritesheet_x_table
&1e6e 95 44    STA &44,X ; this_object_sprite_spritesheet_x - 2
&1e70 b9 ca 56 LDA &56ca,Y ; sprites_spritesheet_y_table
&1e73 95 46    STA &46,X ; this_object_sprite_spritesheet_y - 2
;                                                               *** # Supervisors omits changes to teleporting objects
; skip_calculating_sizes_and_flips
&1e75 b5 36    LDA &36,X ; this_object_x_fraction
&1e77 3d b8 1d AND &1db8,X ; fraction_to_pixel_rounding_table       # Round down to the nearest pixel
&1e7a 38       SEC
&1e7b f5 7e    SBC &7e,X ; screen_start_x_fraction
&1e7d 95 3e    STA &3e,X ; this_object_screen_x_fraction            # Calculate object position relative to screen top left
&1e7f b5 3a    LDA &3a,X ; this_object_x
&1e81 f5 7f    SBC &7f,X ; screen_start_x
&1e83 95 42    STA &42,X ; this_object_screen_x
&1e85 b5 3e    LDA &3e,X ; this_object_screen_x_fraction
&1e87 18       CLC
&1e88 75 32    ADC &32,X ; this_object_sprite_width
&1e8a 85 1b    STA &1b ; right_or_bottom_fraction                   # then relative position of right or bottom of sprite
&1e8c b5 42    LDA &42,X ; this_object_screen_x
&1e8e 69 00    ADC #&00
&1e90 85 1c    STA &1c ; right_or_bottom
&1e92 30 55    BMI &1ee9 ; is_offscreen                             # Branch if sprite is beyond left or top of screen
&1e94 b0 3d    BCS &1ed3 ; crop_sprite_to_left_or_top               # Branch if sprite partly beyond left or top of screen
&1e96 a5 1b    LDA &1b ; right_or_bottom_fraction
&1e98 38       SEC
&1e99 fd b0 1d SBC &1db0,X ; screen_size_x_fraction
&1e9c 85 1b    STA &1b ; right_or_bottom_fraction
&1e9e a5 1c    LDA &1c ; right_or_bottom
&1ea0 fd b4 1d SBC &1db4,X ; screen_size_x
&1ea3 85 1c    STA &1c ; right_or_bottom
&1ea5 f0 0f    BEQ &1eb6 ; crop_sprite_to_right_or_bottom
&1ea7 10 05    BPL &1eae ; beyond_right_or_bottom                   # Branch if sprite is beyond right or bottom of screen
; is_onscreen
&1ea9 b5 3e    LDA &3e,X ; this_object_screen_x_fraction
;                                                               *** # Supervisors omits changes for scrolling
; is_onscreen_using_A_as_x_fraction
&1eab 95 3e    STA &3e,X ; this_object_screen_x_fraction
&1ead 18       CLC                                                  # Clear carry to indicate sprite onscreen in x or y
; beyond_right_or_bottom
; set_bit_in_offscreen_flags
&1eae 26 55    ROL &55 ; offscreen_flags                            # Set a bit if sprite entirely beyond edge of screen:
;                                                                   #     8... set if previous sprite offscreen vertically
;                                                                   #     .4.. set if current sprite offscreen vertically
;                                                                   #     ..2. set if previous sprite offscreen horizontally
;                                                                   #     ...1 set if current sprite offscreen horizontally
&1eb0 ca       DEX
&1eb1 30 39    BMI &1eec ; check_if_object_needs_replotting
&1eb3 4c 43 1e JMP &1e43 ; calculate_sprite_variables_loop

; crop_sprite_to_right_or_bottom
&1eb6 a5 1b    LDA &1b ; right_or_bottom_fraction
&1eb8 f5 32    SBC &32,X ; this_object_sprite_width
&1eba b0 f2    BCS &1eae ; set_bit_in_offscreen_flags               # Branch if sprite is beyond right or bottom of screen
&1ebc 5d b8 1d EOR &1db8,X ; fraction_to_pixel_rounding_table
&1ebf 95 32    STA &32,X ; this_object_sprite_width                 # Limit sprite size to accommodate clipping
&1ec1 b5 4a    LDA &4a,X ; this_object_sprite_x_flip                # &80 set if flipped
&1ec3 10 e4    BPL &1ea9 ; is_onscreen
; is_flipped
&1ec5 a5 1b    LDA &1b ; right_or_bottom_fraction
&1ec7 38       SEC
&1ec8 fd b8 1d SBC &1db8,X ; fraction_to_pixel_rounding_table
&1ecb 75 46    ADC &46,X ; this_object_sprite_spritesheet_x
&1ecd 69 00    ADC #&00
&1ecf 95 46    STA &46,X ; this_object_sprite_spritesheet_x         # Fix start on spritesheet to accommodate clipping
&1ed1 90 d6    BCC &1ea9 ; is_onscreen                              # Always branches

; crop_sprite_to_left_or_top
&1ed3 a5 1b    LDA &1b ; right_or_bottom_fraction
&1ed5 95 32    STA &32,X ; this_object_sprite_width                 # Limit sprite size to accommodate clipping
&1ed7 b5 4a    LDA &4a,X ; this_object_sprite_x_flip                # &80 set if flipped
&1ed9 30 08    BMI &1ee3 ; skip_fixing_spritesheet
; is_not_flipped
&1edb b5 46    LDA &46,X ; this_object_sprite_spritesheet_x
&1edd f5 3e    SBC &3e,X ; this_object_screen_x_fraction
&1edf 69 00    ADC #&00
&1ee1 95 46    STA &46,X ; this_object_sprite_spritesheet_x         # Fix start on spritesheet to accommodate clipping
 ; skip_fixing_spritesheet
&1ee3 a9 00    LDA #&00
&1ee5 95 42    STA &42,X ; this_object_screen_x                     # Set sprite to start at edge of screen
&1ee7 f0 c2    BEQ &1eab ; is_onscreen_using_A_as_x_fraction        # Always branches
; is_offscreen
&1ee9 38       SEC                                                  # Set carry to indicate sprite is offscreen
&1eea b0 c2    BCS &1eae ; set_bit_in_offscreen_flags               # Always branches

; check_if_object_needs_replotting
&1eec a5 55    LDA &55 ; offscreen_flags
&1eee 4c f6 1e JMP &1ef6 ; replot_sprite                        *** # Supervisor always plots sprite, omits checking for changes
; unused                                                            # Unused in supervisor
&1ef1 29 05    AND #&05
&1ef3 f0 01    BEQ &1ef6 ; replot_sprite
&1ef5 60       RTS
; replot_sprite
&1ef6 a9 02    LDA #&02
&1ef8 85 7c    STA &7c ; use_previous_variables                     # Will become 1 to use previous variables at &1f02
&1efa a9 00    LDA #&00 ; KK
&1efc 85 00    STA &00 ; colour_0_pixel_value                       # Colour 0 is always black
&1efe 48       PHA ; value not used                                 # Reserve a byte on stack for near padding
&1eff ba       TSX
&1f00 86 51    STX &51 ; stack_pointer_prior_to_pushing_sprite_data
; replot_sprite_loop
&1f02 c6 7c    DEC &7c ; use_previous_variables
&1f04 10 02    BPL &1f08 ; plot_or_unplot_sprite                    # Unplot previous sprite, then plot current sprite
&1f06 68       PLA ; value not used
; leave
&1f07 60       RTS

; plot_or_unplot_sprite
&1f08 a6 7c    LDX &7c ; use_previous_variables                     # 0 if using current, 1 if using previous variables
&1f0a a5 55    LDA &55 ; offscreen_flags
&1f0c 3d bc 1d AND &1dbc,X ; offscreen_flags_to_check_table         # Check if the sprite is offscreen in either x or y
&1f0f d0 f1    BNE &1f02 ; replot_sprite_loop                       # If so, skip unplotting or plotting
&1f11 b5 46    LDA &46,X ; this_object_sprite_spritesheet_x
&1f13 0a       ASL A
&1f14 69 00    ADC #&00                                             # 8421.421 -> 421.4218
&1f16 0a       ASL A
&1f17 69 00    ADC #&00                                             #          -> 21.42184
&1f19 29 1f    AND #&1f                                             #          -> ...42184, i.e. column in sheet DIV 4
&1f1b 85 0a    STA &0a ; sprite_data_offset_low                     # i.e. x byte offset of sprite in four colour data
; convert_palette_to_sixteen_colour_pixel_values                    # Convert palette to sixteen colour pixel values
&1f1d b5 5a    LDA &5a,X ; this_object_palette
&1f1f 4a       LSR A                                                # Top nibble of palette sets colour 3
&1f20 4a       LSR A
&1f21 4a       LSR A
&1f22 4a       LSR A
&1f23 a8       TAY
&1f24 b9 35 25 LDA &2535,Y ; colour_3_pixel_values_table
&1f27 29 55    AND #&55 ; right pixel
&1f29 85 11    STA &11 ; colour_3_right_pixel_value
&1f2b 0a       ASL A                                                # Convert to left pixel
&1f2c 85 22    STA &22 ; colour_3_left_pixel_value
&1f2e b5 5a    LDA &5a,X ; this_object_palette
&1f30 29 0f    AND #&0f                                             # Bottom nibble of palette sets colours 1 and 2
&1f32 a8       TAY
&1f33 b9 a0 1d LDA &1da0,Y ; colours_1_and_2_pixel_values_table
&1f36 2d 9f 1d AND &1d9f ; sprite_foreground_or_background_mask
&1f39 a8       TAY ; colours_1_and_2_pixel_value
&1f3a 29 55    AND #&55 ; right pixel                               # Right pixel of table entry sets colour 1
&1f3c 85 01    STA &01 ; colour_1_right_pixel_value
&1f3e 0a       ASL A                                                # Convert to left pixel
&1f3f 85 02    STA &02 ; colour_1_left_pixel_value
&1f41 98       TYA ; colours_1_and_2_pixel_value
&1f42 29 aa    AND #&aa ; left pixel                                # Left pixel of table entry sets colour 2
&1f44 85 20    STA &20 ; colour_2_left_pixel_value
&1f46 4a       LSR A                                                # Convert to right pixel
&1f47 85 10    STA &10 ; colour_2_right_pixel_value
; determine_pixel_order                                             # Determine whether pixel order needs to be swapped
&1f49 b5 4a    LDA &4a,X ; this_object_sprite_x_flip                # &80 set if flipping horizontally
&1f4b 85 4c    STA &4c ; flip
&1f4d 4a       LSR A                                                # 84...... -> ..84...
&1f4e 4a       LSR A                                                # i.e. &10 set if flipping horizontally
&1f4f 4a       LSR A
&1f50 35 32    AND &32,X ; this_object_sprite_width                 # &10 set if sprite is an odd number of pixels wide
&1f52 55 3e    EOR &3e,X ; this_object_screen_x_fraction            # &10 set if sprite starts on an odd pixel on screen
&1f54 55 46    EOR &46,X ; this_object_sprite_spritesheet_x         # &10 set if sprite starts on an odd pixel in spritesheet
&1f56 29 10    AND #&10
&1f58 f0 18    BEQ &1f72 ; skip_swapping_pixel_values
; swap_pixel_values                                                 # Swap left and right pixel values
&1f5a a5 02    LDA &02 ; colour_1_left_pixel_value
&1f5c a4 01    LDY &01 ; colour_1_right_pixel_value
&1f5e 85 01    STA &01 ; colour_1_right_pixel_value
&1f60 84 02    STY &02 ; colour_1_left_pixel_value
&1f62 a5 20    LDA &20 ; colour_2_left_pixel_value
&1f64 a4 10    LDY &10 ; colour_2_right_pixel_value
&1f66 85 10    STA &10 ; colour_2_right_pixel_value
&1f68 84 20    STY &20 ; colour_2_left_pixel_value
&1f6a a5 22    LDA &22 ; colour_3_left_pixel_value
&1f6c a4 11    LDY &11 ; colour_3_right_pixel_value
&1f6e 85 11    STA &11 ; colour_3_right_pixel_value
&1f70 84 22    STY &22 ; colour_3_left_pixel_value
; skip_swapping_pixel_values
&1f72 a9 20    LDA #&20 ; &0020                                     # Move one row down sprite sheet
&1f74 a0 00    LDY #&00
&1f76 24 4c    BIT &4c ; flip                                       # &40 set if flipping vertically
&1f78 70 03    BVS &1f7d ; set_sprite_data_spritesheet_between_rows
; not_flipping_vertically
&1f7a a9 e0    LDA #&e0 ; &ffe0                                     # Move one row up sprite sheet
&1f7c 88       DEY ; &ff
; set_sprite_data_spritesheet_between_rows
&1f7d 8d 9f 20 STA &209f ; sprite_data_spritesheet_between_rows_low
&1f80 8c a7 20 STY &20a7 ; sprite_data_spritesheet_between_rows_high
; calculate_sprite_data_address                                     # Calculate the address for the bottom of the sprite
&1f83 b5 34    LDA &34,X ; this_object_sprite_height                # 84218... height of sprite in rows, minus one
&1f85 50 02    BVC &1f89 ; not_vertically_flipped                   # &40 set if flipping vertically (at &1f76)
&1f87 a9 00    LDA #&00                                             # Use top of sprite if vertically flipped
; not_vertically_flipped
&1f89 18       CLC
&1f8a 75 48    ADC &48,X ; this_object_sprite_spritesheet_y         # 84218.21
&1f8c 69 00    ADC #&00
&1f8e 0a       ASL A
&1f8f 69 00    ADC #&00                                             # 84218.21 -> 4218.218
&1f91 0a       ASL A
&1f92 69 00    ADC #&00                                             #          -> 218.2184
&1f94 85 0b    STA &0b ; sprite_data_offset_high
&1f96 29 e0    AND #&e0                                             #          -> 218..... i.e. row in sheet MOD 8 * &20
&1f98 05 0a    ORA &0a ; sprite_data_offset_low                     # Add column component to row component
&1f9a 69 e0    ADC #&e0 ; &45e0 = sprite_data
&1f9c 8d 45 20 STA &2045 ; sprite_data_address_low
&1f9f a5 0b    LDA &0b ; sprite_data_offset_high
&1fa1 29 0f    AND #&0f                                             # 218.2184 -> ....2184 i.e. row in sheet DIV 8
&1fa3 69 45    ADC #&45
&1fa5 8d 46 20 STA &2046 ; sprite_data_address_high
; calculate_widths_for_row_plotting
&1fa8 b5 3e    LDA &3e,X ; this_object_screen_x_fraction
&1faa 29 10    AND #&10 ; 1 pixel
&1fac 75 32    ADC &32,X ; this_object_sprite_width
&1fae 85 07    STA &07 ; last_pixel_oddness
&1fb0 6a       ROR A
&1fb1 29 f0    AND #&f0                                             # Round down to number of pixels
&1fb3 4a       LSR A                                                # Convert to number of sixteen colour bytes * 8
&1fb4 85 6e    STA &6e ; column_offset_for_initial_row_offset
&1fb6 b5 46    LDA &46,X ; this_object_sprite_spritesheet_x
&1fb8 29 30    AND #&30                                             # Offset in pixels in four colour byte
&1fba 75 32    ADC &32,X ; this_object_sprite_width
&1fbc 6a       ROR A                                                # 8421.... -> C8421...
&1fbd 4a       LSR A                                                #          -> .C8421..
&1fbe 4a       LSR A                                                #          -> ..C8421.
&1fbf 4a       LSR A                                                #          -> ...C8421
&1fc0 a8       TAY                                                  # Y = number of pixels needed
&1fc1 4a       LSR A                                                #          -> ....C842
&1fc2 4a       LSR A                                                #          -> .....C84
&1fc3 85 50    STA &50 ; sprite_bytes_per_row                       # i.e. number of four colour bytes needed
&1fc5 b5 32    LDA &32,X ; this_object_sprite_width
&1fc7 4a       LSR A                                                # 8421.... -> .8421...
&1fc8 4a       LSR A                                                #          -> ..8421..
&1fc9 4a       LSR A                                                #          -> ...8421.
&1fca 4a       LSR A                                                #          -> ....8421
&1fcb 85 0b    STA &0b ; width_in_four_colour_bytes
&1fcd 98       TYA                                                  # Y = number of pixels needed
&1fce 29 03    AND #&03
&1fd0 18       CLC
&1fd1 65 51    ADC &51 ; stack_pointer_prior_to_pushing_sprite_data
&1fd3 e9 01    SBC #&01
&1fd5 8d 74 20 STA &2074 ; stack_near_padding_address_low           # Set near end of stack pixel data
&1fd8 aa       TAX
&1fd9 e8       INX
&1fda e5 0b    SBC &0b ; width_in_four_colour_bytes
&1fdc e9 02    SBC #&02
&1fde 8d 77 20 STA &2077 ; stack_far_padding_address_low            # Set far end of stack pixel data
&1fe1 a0 ca    LDY #&ca ; DEX
&1fe3 24 4c    BIT &4c ; flip                                       # &80 set if flipping horizontally
&1fe5 10 04    BPL &1feb ; not_flipped_horizontally
&1fe7 aa       TAX
&1fe8 ca       DEX
&1fe9 a0 e8    LDY #&e8 ; INX
; not_flipped_horizontally
&1feb a5 07    LDA &07 ; last_pixel_oddness
&1fed 29 10    AND #&10 ; 1 pixel                                   # Is the last pixel of the sprite byte aligned?
&1fef f0 04    BEQ &1ff5 ; set_initial_stack_offset_and_stack_direction
&1ff1 8c f4 1f STY &1ff4 ; tweak_initial_stack_offset_for_row_opcode
; tweak_initial_stack_offset_for_row_opcode
&1ff4 e8       INX                                                  # If not, add another byte to accommodate it
#     or       DEX if not flipping horizontally
&1ff5 86 52    STX &52 ; initial_stack_offset_for_row
&1ff7 8c 7e 20 STY &207e ; plot_row_of_sprite_from_stack_direction_opcode_one
&1ffa 8c 82 20 STY &2082 ; plot_row_of_sprite_from_stack_direction_opcode_two
&1ffd a6 7c    LDX &7c ; use_previous_variables
&1fff b5 34    LDA &34,X ; this_object_sprite_height
&2001 4a       LSR A                                                # 84218... -> .84218..
&2002 4a       LSR A                                                #          -> ..84218.
&2003 4a       LSR A                                                #          -> ...84218
&2004 85 53    STA &53 ; rows_remaining
; calculate_screen_address
&2006 b5 40    LDA &40,X ; this_object_screen_y_fraction            # 84218...
&2008 18       CLC
&2009 75 34    ADC &34,X ; this_object_sprite_height                # 84218...
&200b 85 1b    STA &1b ; screen_address_low
&200d b5 44    LDA &44,X ; this_object_screen_y
&200f 69 00    ADC #&00
&2011 85 1c    STA &1c ; screen_address_high
;                                                               *** # Supervisor omits changing CRTC start address
&2013 a5 1b    LDA &1b ; screen_address_low
&2015 46 1c    LSR &1c ; screen_address_high                        # 84218... -> h84218..
&2017 6a       ROR A
&2018 46 1c    LSR &1c ; screen_address_high                        #          -> hh84218.
&201a 6a       ROR A
&201b 46 1c    LSR &1c ; screen_address_high                        #          -> hhh84218
&201d 6a       ROR A
&201e a8       TAY
&201f 29 07    AND #&07                                             #          -> .....218 i.e. row in group
&2021 05 6e    ORA &6e ; column_offset_for_initial_row_offset       # Add column component
&2023 85 6f    STA &6f ; initial_screen_offset_for_row              # Set offset for initial row in group
&2025 09 07    ORA #&07
&2027 85 6e    STA &6e ; second_screen_offset_for_row               # Set offset for first row in next group
&2029 b5 3e    LDA &3e,X ; this_object_screen_x_fraction
&202b 29 e0    AND #&e0                                             # Round x to &20 fraction (one byte)
&202d 69 00    ADC #&00; scaled_screen_start_offset_low             # &20 fraction = 8 byte column of two pixels
&202f 85 1b    STA &1b ; screen_address_low                         # so divide by 4 (&20 / 8) to give screen address
&2031 98       TYA
&2032 29 f8    AND #&f8                                             # hhh84218 -> hhh84... i.e. group
&2034 55 42    EOR &42,X ; this_object_screen_x                     # Add column component to group component
&2036 69 00    ADC #&00; scaled_screen_start_offset_high
&2038 6a       ROR A                                                # hhh84... -> Chhh84..
&2039 66 1b    ROR &1b ; screen_address_low
&203b 4a       LSR A                                                #          -> .Chhh84.
&203c 66 1b    ROR &1b ; screen_address_low
&203e 69 58    ADC #&58 ; &5800 = screen_memory                 *** # Supervisor omits preparing for wraparound check
&2040 85 1c    STA &1c ; screen_address_high
; plot_sprite_row_loop                                              # Convert sprite data to sixteen colours and push to stack
&2042 a4 50    LDY &50 ; sprite_bytes_per_row
; plot_row_of_sprite_to_stack_loop                                  # For each byte of four colour sprite data,
&2044 b9 ff ff LDA &ffff,Y
#     actually LDA sprite_data_address,Y                            # Get byte of four colour sprite data
&2047 aa       TAX
&2048 29 11    AND #&11 ; 0003                                      # Get the first pixel from the right
&204a 8d 4e 20 STA &204e ; colour_translation_one
&204d a5 ff    LDA &ff
#     actually LDA colour_translation_one                           # Convert to a sixteen colour pixel
#     i.e.     LDA &00 ; colour_0_pixel_value       if colour 0
#              LDA &01 ; colour_1_right_pixel_value if colour 1
#              LDA &10 ; colour_2_right_pixel_value if colour 2
#              LDA &11 ; colour_3_right_pixel_value if colour 3
&204f 48       PHA ; sixteen colour right pixel                     # Push to stack
&2050 8a       TXA
&2051 29 22    AND #&22 ; 0030                                      # Get the first pixel from the right
&2053 8d 57 20 STA &2057 ; colour_translation_two
&2056 a5 ff    LDA &ff
#     actually LDA colour_translation_two                           # Convert to a sixteen colour pixel
#     i.e.     LDA &00 ; colour_0_pixel_value      if colour 0
#              LDA &02 ; colour_1_left_pixel_value if colour 1
#              LDA &20 ; colour_2_left_pixel_value if colour 2
#              LDA &22 ; colour_3_left_pixel_value if colour 3
&2058 48       PHA ; sixteen colour left pixel                      # Push to stack
&2059 8a       TXA
&205a 4a       LSR A                                                # 84218421 -> ..842184 
&205b 4a       LSR A                                                # i.e. move pixels three and four to one and two
&205c aa       TAX
&205d 29 11    AND #&11 ; 0003                                      # Get the third (now first) pixel from the right
&205f 8d 63 20 STA &2063 ; colour_translation_three
&2062 a5 ff    LDA &ff
#     actually LDA colour_translation_three                         # Convert to a sixteen colour pixel
#     i.e.     LDA &00 ; colour_0_pixel_value       if colour 0
#              LDA &01 ; colour_1_right_pixel_value if colour 1
#              LDA &10 ; colour_2_right_pixel_value if colour 2
#              LDA &11 ; colour_3_right_pixel_value if colour 3
&2064 48       PHA ; sixteen colour right pixel                     # Push to stack
&2065 8a       TXA
&2066 29 22    AND #&22 ; 0030                                      # Get the fourth (now second) pixel from the right
&2068 8d 6c 20 STA &206c ; colour_translation_four
&206b a5 ff    LDA &ff
#     actually LDA colour_translation_four                          # Convert to a sixteen colour pixel
#     i.e.     LDA &00 ; colour_0_pixel_value      if colour 0
#              LDA &02 ; colour_1_left_pixel_value if colour 1
#              LDA &20 ; colour_2_left_pixel_value if colour 2
#              LDA &22 ; colour_3_left_pixel_value if colour 3
&206d 48       PHA ; sixteen colour left pixel                      # Push to stack
&206e 88       DEY
&206f 10 d3    BPL &2044 ; plot_row_of_sprite_to_stack_loop         # i.e. push four bytes of sixteen colour data
&2071 48       PHA                                                  # Reserve a byte on stack for far padding; this isn't
;                                                                   # strictly needed, as stack pointer will be reset
&2072 c8       INY ; 0
&2073 8c ff 01 STY &01ff
#     actually STY stack_near_padding_address                       # Push black pixel at near end of stack
&2076 8c ff 01 STY &01ff
#     actually STY stack_far_padding_address                        # Push black pixel at far end of stack
; plot_row_of_sprite_from_stack                                     # Plot sprite data from stack to screen
&2079 38       SEC
&207a a4 6f    LDY &6f ; initial_screen_offset_for_row              # Starting from the right of the screen,
; plot_row_of_sprite_from_stack_from_Y
&207c a6 52    LDX &52 ; initial_stack_offset_for_row
; plot_row_of_sprite_from_stack_loop                                # For each byte of the row,
; plot_row_of_sprite_from_stack_direction_opcode_one
&207e ca       DEX
#     or       INX if horizontally flipped
&207f bd 00 01 LDA &0100,X                                          # Get byte from stack for right pixel
; plot_row_of_sprite_from_stack_direction_opcode_two
&2082 ca       DEX
#     or       INX if horizontally flipped
&2083 1d 00 01 ORA &0100,X                                          # Merge with byte from stack for left pixel
; plot_sprite_plotting_opcodes
&2086 51 1b    EOR (&1b),Y ; screen_address                         # If plotting background,
&2088 30 02    BMI &208c ; skip_byte                                # don't plot background if foreground present
;                                                                   # If plotting foreground, &2086 - &2089 becomes:
;                                                                   #     &2086 91 1b BMI &208a ; plot_byte
;                                                                   #     &2088 30 02 EOR (&1b),Y ; screen_address 
;                                                                   # The branch is always taken, i.e. overwrite screen
;                                                                   # See toggle_sprite_plotting_mode (&20bf)
; plot_byte
&208a 91 1b    STA (&1b),Y ; screen_address                         # Plot combined left and right pixels to screen
; skip_byte
&208c 98       TYA
&208d e9 08    SBC #&08                                             # Move left two pixels
&208f a8       TAY
&2090 b0 ec    BCS &207e ; plot_row_of_sprite_from_stack_loop
; to_handle_wraparound_row_opcode
&2092 a6 51    LDX &51 ; stack_pointer_prior_to_pushing_sprite_data
; consider_next_row
&2094 9a       TXS                                                  # Restore the stack position
&2095 c6 53    DEC &53 ; rows_remaining
&2097 30 23    BMI &20bc ; finished_plotting                        # If not finished,
; move_to_next_row
&2099 c6 6f    DEC &6f ; screen_offset
&209b ad 45 20 LDA &2045 ; sprite_data_address_low
&209e 69 20    ADC #&20                                             # Move to next row of sprite sheet
#     actually ADC sprite_data_spritesheet_between_rows_low
&20a0 8d 45 20 STA &2045 ; sprite_data_address_low
&20a3 ad 46 20 LDA &2046 ; sprite_data_address_high
&20a6 69 00    ADC #&00
#     actually ADC sprite_data_spritesheet_between_rows_high
&20a8 8d 46 20 STA &2046 ; sprite_data_address_high
&20ab c0 f9    CPY #&f9
&20ad b0 93    BCS &2042 ; plot_sprite_row_loop                     # Branch if not topmost row in group
; next_group
&20af a5 6e    LDA &6e ; second_screen_offset_for_row
&20b1 85 6f    STA &6f ; initial_screen_offset_for_row
&20b3 a5 1c    LDA &1c ; screen_address_high
&20b5 e9 01    SBC #&01                                             # Move up a group
;                                                               *** # Supervisor omits wraparound check
&20b7 85 1c    STA &1c ; screen_address_high
&20b9 4c 42 20 JMP &2042 ; plot_sprite_row_loop
; finished_plotting
&20bc 4c 02 1f JMP &1f02 ; replot_sprite_loop                       # On first pass, X = 1, so previous sprite unplotted
                                                                    # Repeated with X =0 to plot with current variables

; toggle_sprite_plotting_mode
&20bf a2 01    LDX #&01
; toggle_sprite_plotting_mode_loop
&20c1 bd 86 20 LDA &2086,X ; plot_sprite_plotting_opcodes           # Swap order of opcodes to toggle between plotting
&20c4 bc 88 20 LDY &2088,X ; plot_sprite_plotting_opcodes + 2       # foreground and background
&20c7 9d 88 20 STA &2088,X ; plot_sprite_plotting_opcodes + 2
&20ca 98       TYA
&20cb 9d 86 20 STA &2086,X ; plot_sprite_plotting_opcodes
&20ce ca       DEX
&20cf 10 f0    BPL &20c1 ; toggle_sprite_plotting_mode_loop
; leave
&20d1 60       RTS

; get_and_plot_tile                                                 # Unused entry point
&20d2 20 9a 25 JSR &259a ; get_tile_and_set_sprite_variables
; plot_tile                                                         # Unused entry point in supervisor
&20d5 c0 19    CPY #&19 ; TILE_SPACE
&20d7 f0 f8    BEQ &20d1 ; leave                                    # Leave if tile is empty
&20d9 a9 00    LDA #&00
; plot_tile_after_setting_offscreen_flags                           # Entry point in supervisor
&20db 85 55    STA &55 ; offscreen_flags
&20dd a9 00    LDA #&00
&20df 85 56    STA &56 ; this_object_flags                          # Set to zero to indicate tile isn't teleporting!
&20e1 85 57    STA &57 ; this_object_previous_flags
&20e3 4c 3f 1e JMP &1e3f ; consider_replotting_sprite

; earth_tiles_rotation_table
&20e6 19 ; &00 : TILE_SPACE
&20e7 2d ; &01 : TILE_EARTH
&20e8 ed ; &02 : TILE_EARTH | TILE_FLIP_HORIZONTAL | TILE_FLIP_VERTICAL
&20e9 6d ; &03 : TILE_EARTH | TILE_FLIP_VERTICAL
&20ea ad ; &04 : TILE_EARTH | TILE_FLIP_HORIZONTAL
&20eb 2d ; &05 : TILE_EARTH
&20ec ed ; &06 : TILE_EARTH | TILE_FLIP_HORIZONTAL | TILE_FLIP_VERTICAL
&20ed 5e ; &07 : TILE_STONE_TWO | TILE_FLIP_VERTICAL
&20ee 9e ; &08 : TILE_STONE_TWO | TILE_FLIP_HORIZONTAL

; tile_rotations_table
&20ef 00 ; &02 : TILE_FLIP_NONE
&20f0 c0 ; &03 : TILE_FLIP_HORIZONTAL | TILE_FLIP_VERTICAL
&20f1 80 ; &04 : TILE_FLIP_HORIZONTAL
&20f2 40 ; &05 : TILE_FLIP_VERTICAL

; slope_tiles_table
&20f3 2e ; &00 : TILE_EARTH_SLOPE_FORTY_FIVE
&20f4 2f ; &01 : TILE_EARTH_SLOPE_TWENTY_TWO_ONE
&20f5 2e ; &02 : TILE_EARTH_SLOPE_FORTY_FIVE
&20f6 23 ; &03 : TILE_STONE_SLOPE_FORTY_FIVE

; sloping_passage_feature_tiles_table
&20f7 06 ; &11 : TILE_CHECK_TERTIARY_OBJECT_RANGE_SIX
&20f8 04 ; &12 : TILE_CHECK_TERTIARY_OBJECT_RANGE_FOUR
&20f9 06 ; &13 : TILE_CHECK_TERTIARY_OBJECT_RANGE_SIX
&20fa 04 ; &14 : TILE_CHECK_TERTIARY_OBJECT_RANGE_FOUR
&20fb 07 ; &15 : TILE_CHECK_TERTIARY_OBJECT_RANGE_SEVEN
&20fc 05 ; &16 : TILE_CHECK_TERTIARY_OBJECT_RANGE_FIVE
&20fd 05 ; &17 : TILE_CHECK_TERTIARY_OBJECT_RANGE_FIVE
&20fe 06 ; &18 : TILE_CHECK_TERTIARY_OBJECT_RANGE_SIX

; surface_feature_tiles_table
&20ff 19 : &19 : TILE_SPACE
&2100 2c ; &1a : TILE_EARTH_HORIZONTAL_QUARTER_WITH_EDGE
&2101 19 ; &1b : TILE_SPACE
&2102 2b ; &1c : TILE_EARTH_EDGE

; horizontal_passage_feature_tiles_table
&2103 00 ; &1d : TILE_CHECK_TERTIARY_OBJECT_RANGE_ZERO
&2104 01 ; &1e : TILE_CHECK_TERTIARY_OBJECT_RANGE_ONE
&2105 02 ; &1f : TILE_CHECK_TERTIARY_OBJECT_RANGE_TWO
&2106 03 ; &20 : TILE_CHECK_TERTIARY_OBJECT_RANGE_THREE
&2107 1a ; &21 : TILE_SHORT_BUSH
&2108 21 ; &22 : TILE_COLUMN
&2109 09 ; &23 : TILE_NEST
&210a 9b ; &24 : TILE_TALL_BUSH | TILE_FLIP_HORIZONTAL
&210b 12 ; &25 : TILE_STONE_ONE
&210c 10 ; &26 : TILE_GREEN_HORIZONTAL_QUARTER
&210d 60 ; &27 : TILE_STONE_HORIZONTAL_QUARTER | TILE_FLIP_VERTICAL
&210e 2b ; &28 : TILE_EARTH_EDGE
&210f 0f ; &29 : TILE_MUSHROOMS                                     # Red mushrooms on floor
&2110 4f ; &2a : TILE_MUSHROOMS | TILE_FLIP_VERTICAL                # Blue mushroom on ceiling
&2111 04 ; &2b : TILE_CHECK_TERTIARY_OBJECT_RANGE_FOUR
&2112 0a ; &2c : TILE_PIPE

; feature_tiles_table
&2113 1b ; &00 : TILE_TALL_BUSH
&2114 5a ; &01 : TILE_SHORT_BUSH | TILE_FLIP_VERTICAL
&2115 19 ; &02 : TILE_SPACE
&2116 19 ; &03 : TILE_SPACE
&2117 1e ; &04 : TILE_STONE_TWO
&2118 13 ; &05 : TILE_STONE_SLOPE_FORTY_FIVE_FULL
&2119 24 ; &06 : TILE_STONE_SLOPE_TWENTY_TWO_ONE
&211a 2c ; &07 : TILE_EARTH_HORIZONTAL_QUARTER_WITH_EDGE
&211b 19 ; &08 : TILE_SPACE

; strata_palette_table                                              # Stone uses &212b and &211c - &2124
&211c 8d ; ryk
&211d 82 ; rmk
&211e 8b ; cyk
&211f 8f ; cwk
&2120 84 ; rwk
&2121 89 ; gwk
&2122 8d ; ryk
&2123 81 ; rgk
&2124 82 ; rmk
&2125 81 ; rgk                                                      # Earth uses &2125 - &212a
&2126 85 ; gyk
&2127 b2 ; rmy
&2128 cd ; ryb
&2129 90 ; kyr
&212a 95 ; gyr
&212b 81 ; rgk

; bushes_palette_table
&212c b1 ; rgy
&212d 97 ; gmr
&212e fd ; ryw
&212f f3 ; rcw

; palette_register_values_for_mode_two
;      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
;      K  R  G  Y  B  M  C  W  k  r  g  y  b  m  c  w
&2130 07 16 25 34 43 52 61 70 87 96 a5 b4 c3 d2 e1 f0

; palette_register_values_for_mode_six
&2140 37 27 17 07 77 67 57 47 b0 a0 90 80 f0 e0 d0 c0

; unused
&2150 01 00

; plot_screen                                                   ***
&2152 a9 00    LDA #&00                                         ***
&2154 85 7e    STA &7e ; screen_start_x_fraction                ***
&2156 85 80    STA &80 ; screen_start_y_fraction                ***
&2158 a5 1a    LDA &1a ; screen_centre_y                        ***
&215a 38       SEC                                              ***
&215b e9 02    SBC #&02                                         ***
&215d 85 81    STA &81 ; screen_start_y                         ***
&215f a5 18    LDA &18 ; screen_centre_x                        ***
&2161 e9 04    SBC #&04                                         ***
&2163 85 7f    STA &7f ; screen_start_x                         ***
&2165 a9 80    LDA #&80 ; TILE_PROCESSING_FLAG_PLOTTING         *** # Create primary objects for any tertiary objects
&2167 8d 34 25 STA &2534 ; tile_processing_mode                 ***
&216a a5 81    LDA &81 ; screen_start_y                         ***
&216c 85 25    STA &25 ; tile_y                                 ***
&216e a2 05    LDX #&05                                         ***
; plot_screen_row_loop                                          ***
&2170 8a       TXA                                              ***
&2171 48       PHA ; rows remaining                             ***
&2172 a5 7f    LDA &7f ; screen_start_x                         ***
&2174 85 23    STA &23 ; tile_x                                 ***
&2176 a2 08    LDX #&08                                         ***
; plot_screen_column_loop                                       ***
&2178 8a       TXA                                              ***
&2179 48       PHA ; columns remaining                          ***
&217a 20 e3 2d JSR &2de3 ; plot_tile                            ***
&217d e6 23    INC &23 ; tile_x                                 ***
&217f 68       PLA ; columns remaining                          ***
&2180 aa       TAX                                              ***
&2181 ca       DEX                                              ***
&2182 d0 f4    BNE &2178 ; plot_screen_column_loop              ***
&2184 e6 25    INC &25 ; tile_y                                 ***
&2186 68       PLA ; rows remaining                             ***
&2187 aa       TAX                                              ***
&2188 ca       DEX                                              ***
&2189 d0 e5    BNE &2170 ; plot_screen_row_loop                 ***
&218b 60       RTS                                              ***

; f3_tile_xy
&218c 00

; f2_tile_xy
&218d 00

; get_tile_and_check_for_tertiary_objects
&218e a2 00    LDX #&00
&2190 86 04    STX &04 ; this_object_tertiary_data_offset
;                                                               *** # Supervisor omits noting if tile is from map data
&2192 20 06 22 JSR &2206 ; get_tile                                 # Returns A = tile_type_and_flip
&2195 85 0e    STA &0e ; tile_type_and_flip
&2197 29 c0    AND #&c0 ; TILE_FLIP_HORIZONTAL | TILE_FLIP_VERTICAL
&2199 85 0f    STA &0f ; tile_flip
&219b 45 0e    EOR &0e ; tile_type_and_flip
&219d c9 09    CMP #&09 ; TILE_CHECK_TERTIARY_OBJECT_RANGE_EIGHT + 1
&219f b0 48    BCS &21e9 ; skip_checking_tertiary_objects           # Tile type will be replaced at &21d8 if <= &09
; check_for_tertiary_objects
&21a1 85 0b    STA &0b ; tile_type
&21a3 a8       TAY
&21a4 be 07 18 LDX &1807,Y ; tile_tertiary_object_ranges_table + 1  # Get offset of last tertiary object of next type, + 1
&21a7 bd 22 18 LDA &1822,X ; tertiary_objects_x
&21aa 48       PHA ; previous_tertiary_object_x
&21ab a5 23    LDA &23 ; tile_x
&21ad 9d 22 18 STA &1822,X ; tertiary_objects_x                     # Temporarily use its value as a final one to check
&21b0 be 06 18 LDX &1806,Y ; tile_tertiary_object_ranges_table      # Get offset of first tertiary object of this type
&21b3 ca       DEX
; check_for_tertiary_objects_loop                                   # For each tertiary object of this type,
&21b4 e8       INX
&21b5 dd 22 18 CMP &1822,X ; tertiary_objects_x                     # Is its x coordinate the same as the tile?
&21b8 d0 fa    BNE &21b4 ; check_for_tertiary_objects_loop
&21ba 8a       TXA ; tertiary_object_offset_in_range
&21bb d9 07 18 CMP &1807,Y ; tile_tertiary_object_ranges_table + 1  # Was a tertiary object found?
&21be b0 11    BCS &21d1 ; add_feature_tile                         # If not, add a landscape feature
&21c0 79 10 18 ADC &1810,Y ; tertiary_objects_data_offset
&21c3 85 04    STA &04 ; this_object_tertiary_data_offset           # Not all tertiary objects have a data byte
&21c5 18       CLC
&21c6 79 19 18 ADC &1819,Y ; tertiary_objects_type_offset
&21c9 85 05    STA &05 ; this_object_tertiary_type_offset           # Not all tertiary objects have a type byte
&21cb bd 21 19 LDA &1921,X ; tertiary_objects_tile_and_flip
&21ce 4c d8 21 JMP &21d8 ; set_tile_type_and_flip                   # Use tile for tertiary object
; add_feature_tile
&21d1 a6 0b    LDX &0b ; tile_type                                  # Use the tile type to determine a feature to add
&21d3 bd 13 21 LDA &2113,X ; feature_tiles_table
&21d6 45 0f    EOR &0f ; tile_flip                                  # keeping the flip given by the algorithm or map data
; set_tile_type_and_flip
&21d8 85 0e    STA &0e ; tile_type_and_flip
&21da be 07 18 LDX &1807,Y ; tile_tertiary_object_ranges_table + 1
&21dd 68       PLA ; previous_tertiary_object_x
&21de 9d 22 18 STA &1822,X ; tertiary_objects_x                     # Restore previous value of first object of next type
&21e1 a5 0e    LDA &0e ; tile_type_and_flip
&21e3 29 c0    AND #&c0 ; TILE_FLIP_HORIZONTAL | TILE_FLIP_VERTICAL
&21e5 85 0f    STA &0f ; tile_flip
&21e7 45 0e    EOR &0e ; tile_type_and_flip                         # Remove flip flags
; skip_checking_tertiary_objects
&21e9 85 0e    STA &0e ; tile_type_and_flip                         # Tile types are now those that will be used in the game
&21eb c9 10    CMP #&10 ; TILE_MUSHROOMS + 1
&21ed b0 16    BCS &2205 ; leave                                    # Does this tile have an update routine?
&21ef ba       TSX
&21f0 8e 99 25 STX &2599 ; stack_pointer_to_leave_to_if_unable_to_create_primary_object # Unnecessary code; overwritten at &2424
&21f3 aa       TAX ; tile type
&21f4 bd cd 16 LDA &16cd,X ; object_types_update_routine_addresses_high_table
&21f7 2c 34 25 BIT &2534 ; tile_processing_mode                     # Should the tile update routine be called for this function?
&21fa f0 07    BEQ &2203 ; skip_calling_tile_update_routine         # If so, corresponding bit in high nibble will be set
&21fc 29 0f    AND #&0f                                             # Low nibble is high byte of update routine address offset
&21fe a4 04    LDY &04 ; this_object_tertiary_data_offset
&2200 20 23 24 JSR &2423 ; call_tile_update_routine                 # This may convert a tertiary object into a primary one
; skip_calling_tile_update_routine
&2203 a5 0e    LDA &0e ; tile_type_and_flip                         # Leave with A = tile type
&2205 60       RTS

; get_tile
&2206 a5 25    LDA &25 ; tile_y                                     # Calculate a triangular function of x and y, f1
&2208 aa       TAX
&2209 4a       LSR A
&220a 45 23    EOR &23 ; tile_x
&220c 29 f8    AND #&f8
&220e 4a       LSR A
&220f 65 23    ADC &23 ; tile_x
&2211 4a       LSR A
&2212 65 25    ADC &25 ; tile_y
&2214 85 0b    STA &0b ; f1_tile_xy
&2216 8a       TXA ; tile_y                                         # Use f1 and y to determine whether to use mapped data
&2217 c9 79    CMP #&79
&2219 90 06    BCC &2221 ; skip_subtraction
&221b c9 bf    CMP #&bf
&221d 90 54    BCC &2273 ; get_tile_from_algorithm_skipping_check
&221f e9 46    SBC #&46
; skip_subtraction
&2221 c9 48    CMP #&48
&2223 b0 06    BCS &222b ; skip_addition
&2225 c9 3e    CMP #&3e
&2227 b0 4a    BCS &2273 ; get_tile_from_algorithm_skipping_check
&2229 69 0a    ADC #&0a
; skip_addition
&222b 8d 8d 21 STA &218d ; f2_tile_xy                               # Calculate three permuted versions of f1
&222e 29 a8    AND #&a8
&2230 49 6f    EOR #&6f
&2232 4a       LSR A
&2233 65 23    ADC &23 ; tile_x
&2235 49 60    EOR #&60
&2237 69 28    ADC #&28
&2239 8d 8c 21 STA &218c ; f3_tile_xy
&223c 29 38    AND #&38
&223e 49 a4    EOR #&a4
&2240 6d 8d 21 ADC &218d ; f2_tile_xy
&2243 8d 8d 21 STA &218d ; f2_tile_xy
&2246 a8       TAY
&2247 49 2c    EOR #&2c
&2249 6d 8c 21 ADC &218c ; f3_tile_xy                               # A = f4_tile_xy
&224c c0 20    CPY #&20
&224e b0 23    BCS &2273 ; get_tile_from_algorithm_skipping_check   # Use f3 to determine whether to use mapped data
&2250 c9 20    CMP #&20
&2252 b0 1b    BCS &226f ; get_tile_from_algorithm
; get_tile_from_map_data                                            # Use f2 and f4 to determine offset into map data
;                                                               *** # Supervisor omits noting if tile is from map data
&2254 a8       TAY ; f4_tile_xy
&2255 0a       ASL A
&2256 0a       ASL A
&2257 0a       ASL A
&2258 4d 8d 21 EOR &218d ; f2_tile_xy
&225b 85 72    STA &72 ; map_data_address_low
&225d 98       TYA ; f4_tile_xy
&225e 29 03    AND #&03
&2260 69 41    ADC #&41 ; &41e0 = map_data
&2262 85 73    STA &73 ; map_data_address_high
&2264 a0 e0    LDY #&e0
&2266 b1 72    LDA (&72),Y ; map_data_address                       # Get tile type and flip from map data
&2268 60       RTS

; to_get_tile_for_surface
&2269 4c b3 23 JMP &23b3 ; get_tile_for_surface

; to_leave_with_empty_tile
&226c 4c 54 23 JMP &2354 ; leave_with_empty_tile

; get_tile_from_algorithm                                           # A = f4_tile_xy, X = tile_y
&226f c9 3d    CMP #&3d
&2271 90 f9    BCC &226c ; to_leave_with_empty_tile                 # Add irregular caverns near mapped data
; get_tile_from_algorithm_skipping_check
&2273 e0 4e    CPX #&4e                                             # If y < &4e, i.e. above surface, use TILE_SPACE
&2275 90 f5    BCC &226c ; to_leave_with_empty_tile
&2277 f0 f0    BEQ &2269 ; to_get_tile_for_surface
&2279 e0 4f    CPX #&4f
&227b d0 0e    BNE &228b ; is_below_surface
; is_one_below_surface                                              # If y = &4f, i.e. one below surface, use solid layer
&227d a5 23    LDA &23 ; tile_x                                     # except where removed by mapped data or irregular cavern
&227f c9 40    CMP #&40
&2281 f0 05    BEQ &2288 ; leave_with_leaf
&2283 a0 01    LDY #&01                                             # Use TILE_EARTH (earth_tiles_rotation_table + 1)
&2285 4c a3 23 JMP &23a3 ; to_leave_with_tile_from_table
; leave_with_leaf
&2288 a9 62    LDA #&62 ; TILE_LEAF | TILE_FLIP_VERTICAL            # Set (&40, &4f) to be a vertically flipped leaf
&228a 60       RTS                                                  # ((&40, &4e) is set to TILE_LEAF by tertiary object &1b)
; is_below_surface
&228b a4 0b    LDY &0b ; f1_tile_xy
&228d a9 00    LDA #&00                                             # Use earth to fill in the sides and bottom of world
&228f 85 0b    STA &0b ; f1_tile_xy
&2291 a5 23    LDA &23 ; tile_x
&2293 24 25    BIT &25 ; tile_y
&2295 30 07    BMI &229e ; is_bottom_half_of_world
; is_top_half_of_world                                              # If y < &80 (top half of world, top third of ground)
&2297 69 1d    ADC #&1d
&2299 c9 5e    CMP #&5e                                             # Set x = &00 - &40 and &e3 - &ff to be solid
&229b 4c a2 22 JMP &22a2 ; check_if_side_of_world
; is_bottom_half_of_world                                           # If y >= &80,
&229e 69 07    ADC #&07
&22a0 c9 2b    CMP #&2b                                             # Set x = &00 - &23 and &f9 - &ff to be solid
; check_if_side_of_world
&22a2 90 55    BCC &22f9 ; to_leave_with_earth_or_stone             # i.e. fill in different sized sides of the world
&22a4 98       TYA ; f1_tile_xy
&22a5 29 e8    AND #&e8                                             # Using f1 to generate a complicated pattern,
&22a7 c5 25    CMP &25 ; tile_y
&22a9 90 4e    BCC &22f9 ; to_leave_with_earth_or_stone             # set the bottom and other parts of the world to be earth
&22ab 84 0b    STY &0b ; f1_tile_xy                                 # Otherwise, use f1 to determine whether to use earth or stone
&22ad 8a       TXA ; tile_y                                         # Calculate another function of x and y, f5
&22ae 0a       ASL A
&22af 65 25    ADC &25 ; tile_y
&22b1 4a       LSR A
&22b2 65 25    ADC &25 ; tile_y
&22b4 29 e0    AND #&e0
&22b6 65 23    ADC &23 ; tile_x
&22b8 29 e8    AND #&e8
&22ba d0 13    BNE &22cf ; consider_passages_and_caverns            # Use f5 to determine where to add square caverns
; is_square_cavern
&22bc a5 25    LDA &25 ; tile_y
&22be 10 ac    BPL &226c ; to_leave_with_empty_tile
; is_windy_square_cavern                                            # which are windy in the bottom half of the world
&22c0 a5 23    LDA &23 ; tile_x
&22c2 4a       LSR A
&22c3 4a       LSR A
&22c4 4a       LSR A
&22c5 aa       TAX
&22c6 a9 0e    LDA #&0e ; TILE_VARIABLE_WIND
&22c8 e0 0a    CPX #&0a                                             # Is this one of the two square caverns below the
&22ca d0 02    BNE &22ce ; skip_flip                                # west stone door? If so, use a constant downdraft
&22cc a9 8e    LDA #&8e ; TILE_VARIABLE_WIND | TILE_FLIP_HORIZONTAL
; skip_flip
&22ce 60       RTS

; consider_passages_and_caverns                                     # Consider horizontal, vertical and sloping passages
&22cf 98       TYA ; f1_tile_xy                                     # Calculate another permuted version of f1, f6
&22d0 4a       LSR A
&22d1 4a       LSR A
&22d2 29 30    AND #&30
&22d4 4a       LSR A
&22d5 65 23    ADC &23 ; tile_x
&22d7 4a       LSR A
&22d8 45 23    EOR &23 ; tile_x
&22da 4a       LSR A
&22db 45 23    EOR &23 ; tile_x
&22dd 65 23    ADC &23 ; tile_x
&22df 29 fd    AND #&fd
&22e1 45 23    EOR &23 ; tile_x
&22e3 29 07    AND #&07
&22e5 d0 0e    BNE &22f5 ; not_vertical_shaft                       # Use f6 to determine where to add vertical shafts
&22e7 a5 23    LDA &23 ; tile_x
&22e9 30 07    BMI &22f2 ; leave_with_vertical_shaft
&22eb 4a       LSR A
&22ec 65 25    ADC &25 ; tile_y
&22ee 29 30    AND #&30
&22f0 f0 03    BEQ &22f5 ; not_vertical_shaft
; leave_with_vertical_shaft
&22f2 a9 08    LDA #&08 ; TILE_CHECK_TERTIARY_OBJECT_RANGE_EIGHT
&22f4 60       RTS
; not_vertical_shaft
&22f5 e0 52    CPX #&52                                             # Fill in a horizontal passage that would otherwise
&22f7 b0 03    BCS &22fc ; not_close_to_surface                     # appear close to the surface
; to_leave_with_earth_or_stone
&22f9 4c 98 23 JMP &2398 ; leave_with_earth_or_stone
; not_close_to_surface
&22fc 98       TYA ; f1_tile_xy                                     # Calculate another permuted version of f1, f7
&22fd 29 68    AND #&68
&22ff 65 25    ADC &25 ; tile_y
&2301 4a       LSR A
&2302 65 25    ADC &25 ; tile_y
&2304 4a       LSR A
&2305 65 25    ADC &25 ; tile_y
&2307 29 fc    AND #&fc
&2309 45 25    EOR &25 ; tile_y
&230b 29 17    AND #&17
&230d d0 4c    BNE &235b ; consider_sloping_passage                 # Use f7 to determine where to add sloped passages
; consider_horizontal_passage
&230f 98       TYA ; f1_tile_xy                                     # Calculate two permuted version of f1, f8 and f9
&2310 65 23    ADC &23 ; tile_x
&2312 29 50    AND #&50
&2314 f0 3e    BEQ &2354 ; leave_with_empty_tile                    # Use f8 to determine where to add empty horizontal passages
&2316 25 23    AND &23 ; tile_x
&2318 4a       LSR A
&2319 4a       LSR A
&231a 65 25    ADC &25 ; tile_y
&231c 4a       LSR A
&231d 4a       LSR A
&231e 29 0f    AND #&0f
&2320 c9 08    CMP #&08
&2322 90 08    BCC &232c ; is_horizontal_passage_type_one           # Use f9 to determine where to add horizontal passages with features
; is_horizontal_passage_type_two
&2324 24 0b    BIT &0b ; f1_tile_xy
&2326 50 16    BVC &233e ; use_passage_feature
&2328 09 04    ORA #&04
&232a d0 12    BNE &233e ; use_passage_feature                      # Always branches
; is_horizontal_passage_type_one
&232c 85 0a    STA &0a ; special_type
&232e 49 05    EOR #&05                                             # Use f9 to determine type of some special features
&2330 c9 06    CMP #&06
&2332 a5 0a    LDA &0a ; special_type
&2334 b0 08    BCS &233e ; use_passage_feature
&2336 98       TYA ; f1_tile_xy                                     # Calculate another permuted version of f1, f10
&2337 4a       LSR A
&2338 65 25    ADC &25 ; tile_y
&233a 45 23    EOR &23 ; tile_x
&233c 29 07    AND #&07                                             # Use f10 to determine type of some special features
; use_passage_feature
&233e 18       CLC
&233f 69 1d    ADC #&1d ; horizontal_passage_feature_tiles_table - earth_tiles_rotation_table
&2341 48       PHA ; tile offset
&2342 20 c2 23 JSR &23c2 ; calculate_slope_function_for_tile_x_y    # Returns carry clear if passage middle or edge
&2345 68       PLA ; tile offset
&2346 90 0c    BCC &2354 ; leave_with_empty_tile                    # Don't add features where crossed by sloping passage
&2348 a8       TAY
&2349 b9 e6 20 LDA &20e6,Y ; horizontal_passage_feature_tiles_table - &1d
&234c a4 25    LDY &25 ; tile_y
&234e c0 e0    CPY #&e0
&2350 d0 02    BNE &2354 ; skip_flip
&2352 49 40    EOR #&40 ; TILE_FLIP_VERTICAL                        # Flip mushrooms in flooded passage at bottom right of world
; skip_flip
;                                                               *** # Bug: supervisor omits RTS here, removing some features
; leave_with_empty_tile
&2354 a0 00    LDY #&00                                             # Use TILE_SPACE (earth_tiles_rotation_table + 0)
; leave_with_tile_from_table
&2356 38       SEC
&2357 b9 e6 20 LDA &20e6,Y ; earth_tiles_rotation_table
&235a 60       RTS

; consider_sloping_passage
&235b 20 c2 23 JSR &23c2 ; calculate_slope_function_for_tile_x_y    # Returns carry clear if passage, Y = slope type
&235e b0 38    BCS &2398 ; leave_with_earth_or_stone
&2360 c0 00    CPY #&00                                             # Y = 0 if empty centre of sloping passage
&2362 f0 f2    BEQ &2356 ; leave_with_tile_from_table               # Leave with TILE_SPACE
; is_sloping_passage_edge
&2364 a5 0b    LDA &0b ; f1_tile_xy                                 # Calculate another permuted version of f1, f11
&2366 48       PHA ; f1_tile_xy
&2367 84 0a    STY &0a ; slope_type
&2369 2a       ROL A                                                # 84218421 -> 8 4218421.
&236a 2a       ROL A                                                #          -> 4 218421.8
&236b 2a       ROL A                                                #          -> 2 18421.84
&236c 29 01    AND #&01                                             #          ->   .......4
&236e 2a       ROL A                                                #          ->   ......4.
&236f a8       TAY                                                  # Y = 0 or 2, depending on &40 of f1
&2370 68       PLA ; f1_tile_xy
&2371 65 23    ADC &23 ; tile_x
&2373 2a       ROL A
&2374 45 25    EOR &25 ; tile_y
&2376 29 1a    AND #&1a
&2378 d0 15    BNE &238f ; use_slope                                # Use f11 to determine where to add sloping passage features
; use_sloping_passage_feature
&237a 98       TYA
&237b a4 0a    LDY &0a ; slope_type
&237d 59 ed 20 EOR &20ed,Y ; tile_rotations_table - 2
&2380 29 7f    AND #&7f
&2382 c9 40    CMP #&40                                             # Set carry if TILE_FLIP_VERTICAL
&2384 2a       ROL A                                                # Set &01 if TILE_FLIP_VERTICAL
&2385 29 07    AND #&07
&2387 aa       TAX                                                  # X = (slope_type * 2) + (1 if TILE_FLIP_VERTICAL)
&2388 bd f7 20 LDA &20f7,X ; sloping_passage_feature_tiles_table
&238b 59 ed 20 EOR &20ed,Y ; tile_rotations_table - 2               # Apply rotation to slope
&238e 60       RTS
; use_slope
&238f b9 f3 20 LDA &20f3,Y ; slope_tiles_table
&2392 a4 0a    LDY &0a ; slope_type
&2394 59 ed 20 EOR &20ed,Y ; tile_rotations_table - 2               # Apply rotation to slope
&2397 60       RTS

; leave_with_earth_or_stone
&2398 a5 0b    LDA &0b ; f1_tile_xy                                 # Zero if filling sides or bottom or world
&239a 4a       LSR A                                                # 84218421 -> .8421842
&239b 4a       LSR A                                                #          -> ..842184
&239c 4a       LSR A                                                #          -> ...84218
&239d 29 0e    AND #&0e                                             #          -> ....421.
&239f 4a       LSR A                                                #          -> .....421
&23a0 69 01    ADC #&01                                             # i.e. convert f1 into an offset between &01 and &08
&23a2 a8       TAY
; to_leave_with_tile_from_table
&23a3 4c 56 23 JMP &2356 ; leave_with_tile_from_table

; consider_adding_surface_feature
&23a6 65 23    ADC &23 ; tile_x                                     # Use a function of x to determine which surface feature to add
&23a8 2a       ROL A                                                # 84218421 -> 8 4218421.
&23a9 2a       ROL A                                                #          -> 4 218421.8
&23aa 2a       ROL A                                                #          -> 2 18421.84
&23ab 29 02    AND #&02                                             #          -> 2 ......8.
&23ad 69 19    ADC #&19 ; surface_feature_tiles_table - earth_tiles_rotation_table
&23af a8       TAY
&23b0 4c 56 23 JMP &2356 ; leave_with_tile_from_table

; get_tile_for_surface
&23b3 a0 19    LDY #&19                                             # Use TILE_SPACE (earth_tiles_rotation_table + &19)
&23b5 a5 23    LDA &23 ; tile_x
&23b7 4a       LSR A
&23b8 65 23    ADC &23 ; tile_x
&23ba 29 17    AND #&17
&23bc d0 e8    BNE &23a6 ; consider_adding_surface_feature          # Use a function of x to determine where to add surface features
&23be 66 0b    ROR &0b ; f1_tile_xy
&23c0 6a       ROR A                                                # Set &80 (TILE_HORIZONTAL_FLIP) depending on f1
&23c1 60       RTS

; calculate_slope_function_for_tile_x_y
&23c2 8a       TXA ; tile_y
&23c3 4a       LSR A
&23c4 45 25    EOR &25 ; tile_y
&23c6 29 06    AND #&06
&23c8 d0 23    BNE &23ed ; skip_sloping_cavern
; consider_adding_sloping_cavern
&23ca 98       TYA ; f1_tile_xy                                     # Use f1 to determine function
&23cb a0 02    LDY #&02
&23cd 29 20    AND #&20                                             # 84218421 -> ..2....
&23cf 0a       ASL A                                                #          -> .4.....
&23d0 0a       ASL A                                                #          -> 8......
&23d1 49 e5    EOR #&e5 ; SBC                                       # i.e. either &65 (ADC) or &e5 (SBC)
&23d3 8d dd 23 STA &23dd ; sloping_cavern_function_opcode
&23d6 30 02    BMI &23da ; skip_flip
&23d8 a0 04    LDY #&04
; skip_flip
&23da 8a       TXA ; tile_y                                         # Use a function of X and Y to determine where to add sloping caverns
&23db 69 16    ADC #&16
; sloping_cavern_function_opcode
&23dd 65 23    ADC &23 ; tile_x
#     or       SBC &23 ; tile_x
&23df 29 5f    AND #&5f
&23e1 aa       TAX
&23e2 ca       DEX
&23e3 e0 0c    CPX #&0c
&23e5 90 38    BCC &241f ; leave_with_zero_Y                        # Leave with zero to indicate middle of sloping cavern
&23e7 f0 38    BEQ &2421 ; leave_with_carry_clear                   # Leave with Y non-zero to indicate edge of sloping cavern
&23e9 c8       INY
&23ea e8       INX
&23eb f0 34    BEQ &2421 ; leave_with_carry_clear                   # Leave with Y non-zero to indicate edge of sloping cavern
; skip_sloping_cavern
&23ed a5 23    LDA &23 ; tile_x
&23ef 4a       LSR A                                                # 84218421 -> .8421842 1
&23f0 4a       LSR A                                                #          -> ..842184 2
&23f1 4a       LSR A                                                #          -> ...84218 4
&23f2 4a       LSR A                                                #          -> ....8421 8
&23f3 b0 29    BCS &241e ; leave                                    # Break sloping passages every eight tiles
&23f5 a9 01    LDA #&01                                             # Use a function of x and y to determine where to add / sloping passages
&23f7 65 23    ADC &23 ; tile_x
&23f9 65 25    ADC &25 ; tile_y
&23fb 29 8f    AND #&8f
&23fd c9 01    CMP #&01
&23ff f0 1e    BEQ &241f ; leave_with_zero_Y                        # Leave with Y zero to indicate middle of passage
&2401 aa       TAX                                                  # Use a function of x and y to determine where to add \ sloping passages
&2402 38       SEC
&2403 a5 25    LDA &25 ; tile_y
&2405 e5 23    SBC &23 ; tile_x
&2407 29 2f    AND #&2f
&2409 c9 01    CMP #&01
&240b f0 12    BEQ &241f ; leave_with_zero_Y                        # Leave with Y zero to indicate middle of passage
&240d a0 02    LDY #&02
&240f c9 02    CMP #&02
&2411 f0 0e    BEQ &2421 ; leave_with_carry_clear                   # Leave with Y non-zero to indicate edge of passage
&2413 c8       INY ; 3
&2414 90 0b    BCC &2421 ; leave_with_carry_clear                   # Leave with Y non-zero to indicate edge of passage
&2416 c8       INY ; 4
&2417 e0 02    CPX #&02
&2419 f0 06    BEQ &2421 ; leave_with_carry_clear                   # Leave with Y non-zero to indicate edge of passage
&241b c8       INY ; 5
&241c 90 03    BCC &2421 ; leave_with_carry_clear                   # Leave with Y non-zero to indicate edge of passage
; leave                                                             # Leave with carry set to indicate solid tile
&241e 60       RTS
; leave_with_zero_Y
&241f a0 00    LDY #&00                                             # Leave with zero to indicate empty tile
; leave_with_carry_clear
&2421 18       CLC                                                  # Leave with carry clear to indicate empty or sloping tile
&2422 60       RTS

; call_tile_update_routine                                          # Called with A = high byte of update routine address offset
&2423 ba       TSX
&2424 8e 99 25 STX &2599 ; stack_pointer_to_leave_to_if_unable_to_create_primary_object # Leave call_tile_update_routine if so
&2427 a6 0e    LDX &0e ; tile_type_and_flip
&2429 10 04    BPL &242f ; call_update_routine                      # Always branches

; call_object_update_routine                                        # Called with A = object type + &14
&242b aa       TAX                                                  #             Y = this_object_touching
&242c bd cd 16 LDA &16cd,X ; update_routine_addresses_high_table
; call_update_routine                                               # Called with X = routine number
&242f 48       PHA ; update_routine_address_high
&2430 bd 54 16 LDA &1654,X ; update_routine_addresses_low_table
&2433 18       CLC
&2434 69 50    ADC #&50 ; &3a50 = update_routines_base - 1
&2436 aa       TAX
&2437 68       PLA ; update_routine_address_high
&2438 29 3f    AND #&3f                                             # Lowest six bits is high byte of update routine address offset
&243a 69 3a    ADC #&3a
&243c 48       PHA ; update_routine_address_high                    # Push address of update routine to stack
&243d 8a       TXA
&243e 48       PHA ; update_routine_address_low
&243f a6 03    LDX &03 ; this_object_data
&2441 8a       TXA
&2442 c0 00    CPY #&00
&2444 60       RTS                                                  # Leave via update routine
                                                                    # Call with A = X = this_object_data
                                                                    #      Y = this_object_touching
                                                                    #      negative set if not touching other object

; update_objects
&2445 a2 00    LDX #&00
; update_objects_loop                                               # For each primary object,
&2447 86 78    STX &78 ; this_object
&2449 bd dc 1a LDA &1adc,X ; objects_y                              # Non-zero if object in slot
&244c d0 03    BNE &2451 ; update_object
&244e 4c 2b 25 JMP &252b ; consider_next_object
; update_object
&2451 bd dc 1a LDA &1adc,X ; objects_y                          *** # Unnecessary code
&2454 85 3c    STA &3c ; this_object_y
&2456 85 3d    STA &3d ; this_object_previous_y
&2458 bd ee 1a LDA &1aee,X ; objects_flags
&245b 85 56    STA &56 ; this_object_flags
&245d 85 57    STA &57 ; this_object_previous_flags
&245f 85 27    STA &27 ; this_object_x_flip                         # Set &80 if object is horizontally flipped
&2461 0a       ASL A
&2462 85 29    STA &29 ; this_object_y_flip                         # Set &80 if object is vertically flipped
&2464 bd b9 1a LDA &1ab9,X ; objects_x
&2467 85 3a    STA &3a ; this_object_x
&2469 85 3b    STA &3b ; this_object_previous_x
&246b bd a8 1a LDA &1aa8,X ; objects_x_fraction
&246e 85 36    STA &36 ; this_object_x_fraction
&2470 85 37    STA &37 ; this_object_previous_x_fraction
;                                                               *** # Supervisor omits velocities
&2472 bd cb 1a LDA &1acb,X ; objects_y_fraction
&2475 85 38    STA &38 ; this_object_y_fraction
&2477 85 39    STA &39 ; this_object_previous_y_fraction
&2479 bd 98 1a LDA &1a98,X ; objects_sprite
&247c 85 5c    STA &5c ; this_object_sprite
&247e 85 5d    STA &5d ; this_object_previous_sprite
&2480 bd fe 1a LDA &1afe,X ; objects_palette
&2483 85 5a    STA &5a ; this_object_palette
&2485 85 5b    STA &5b ; this_object_previous_palette
&2487 bd 88 1a LDA &1a88,X ; objects_type
&248a 85 1f    STA &1f ; this_object_type
&248c bd 8e 1b LDA &1b8e,X ; objects_tertiary_data_offset
&248f 85 2b    STA &2b ; this_object_tertiary_data_offset
;                                                               *** # Supervisor omits target_object_and_flags
&2491 bd 3e 1b LDA &1b3e,X ; objects_tx
&2494 85 2f    STA &2f ; this_object_tx
;                                                               *** # Supervisor omits energy
&2496 bd 5e 1b LDA &1b5e,X ; objects_ty
&2499 85 31    STA &31 ; this_object_ty
;                                                               *** # Supervisor omits touching
&249b bd 9e 1b LDA &1b9e,X ; objects_state
&249e 85 28    STA &28 ; this_object_state
;                                                               *** # Supervisor omits timer and frame counters
&24a0 a6 5c    LDX &5c ; this_object_sprite
&24a2 bd 00 54 LDA &5400,X ; sprites_width_and_horizontal_flip_table
&24a5 29 f0    AND #&f0                                             # 8421.... width in pixels, minus one
&24a7 85 2a    STA &2a ; this_object_width
&24a9 bd ee 54 LDA &54ee,X ; sprites_height_and_vertical_flip_table
&24ac 29 f8    AND #&f8                                             # 84218... height in rows, minus one
&24ae 85 2c    STA &2c ; this_object_height
;                                                               *** # Supervisor omits physics
&24b0 a6 2b    LDX &2b ; this_object_tertiary_data_offset
&24b2 bd ae 1b LDA &1bae,X ; tertiary_objects_data
&24b5 85 03    STA &03 ; this_object_data
&24b7 a5 1f    LDA &1f ; this_object_type
&24b9 18       CLC
&24ba 69 14    ADC #&14                                             # Object routines follow tile and explosion routines
&24bc a0 ff    LDY #&ff; this_object_touching
&24be 20 2b 24 JSR &242b ; call_object_update_routine               # Update object depending on type
;                                                               *** # Supervisor omits physics
&24c1 18       CLC                                              *** # Clear carry to indicate object is visible in supervisor
; is_visible
&24c2 a5 57    LDA &57 ; this_object_previous_flags
&24c4 6a       ROR A                                                # 84218421 -> C8421842 1
&24c5 6a       ROR A                                                #          -> 1C842184 2
&24c6 29 c0    AND #&c0                                             #          -> 1C...... ; &01 = OBJECT_FLAG_NOT_PLOTTED
&24c8 85 0a    STA &0a ; invisibility_and_not_plotted
&24ca 4a       LSR A                                                #          -> .1C.....
&24cb 4a       LSR A                                                #          -> ..1C....
&24cc 05 0a    ORA &0a ; invisibility_and_not_plotted               #          -> 1C1C....
&24ce 85 55    STA &55 ; offscreen_flags                            # Flags will be rotated left when considering replotting
;                                                                   # If OBJECT_FLAG_NOT_PLOTTED was set, skip unplotting
;                                                                   # If object was invisible or removed, skip plotting
&24d0 a5 27    LDA &27 ; this_object_x_flip
&24d2 0a       ASL A                                                # Set what will become &80 if horizontally flipped
&24d3 a5 29    LDA &29 ; this_object_y_flip
&24d5 6a       ROR A                                                # Set what will become &40 if vertically flipped
&24d6 29 c0    AND #&c0
&24d8 85 58    STA &58 ; this_object_flip
&24da a5 56    LDA &56 ; this_object_flags
&24dc 29 c0    AND #&c0 ; OBJECT_FLAG_FLIP_HORIZONTAL | OBJECT_FLAG_FLIP_VERTICAL
&24de 85 59    STA &59 ; this_object_previous_flip
&24e0 45 56    EOR &56 ; this_object_flags
&24e2 45 58    EOR &58 ; this_object_flip
&24e4 29 f7    AND #&f7 ; !(OBJECT_FLAG_NEWLY_CREATED | OBJECT_FLAG_WAS_DAMAGED)
&24e6 85 56    STA &56 ; this_object_flags
&24e8 a6 78    LDX &78 ; this_object                            ***
&24ea a5 3c    LDA &3c ; this_object_y
&24ec 9d dc 1a STA &1adc,X ; objects_y
&24ef a5 3a    LDA &3a ; this_object_x
&24f1 9d b9 1a STA &1ab9,X ; objects_x
&24f4 a5 36    LDA &36 ; this_object_x_fraction
&24f6 9d a8 1a STA &1aa8,X ; objects_x_fraction
;                                                               *** # Supervisor omits velocities
&24f9 a5 56    LDA &56 ; this_object_flags
&24fb 9d ee 1a STA &1aee,X ; objects_flags
&24fe a5 38    LDA &38 ; this_object_y_fraction
&2500 9d cb 1a STA &1acb,X ; objects_y_fraction
&2503 a5 5c    LDA &5c ; this_object_sprite
&2505 9d 98 1a STA &1a98,X ; objects_sprite
&2508 a5 5a    LDA &5a ; this_object_palette
&250a 9d fe 1a STA &1afe,X ; objects_palette
&250d a5 1f    LDA &1f ; this_object_type
&250f 9d 88 1a STA &1a88,X ; objects_type
&2512 a5 2b    LDA &2b ; this_object_tertiary_data_offset
&2514 9d 8e 1b STA &1b8e,X ; objects_tertiary_data_offset
;                                                               *** # Supervisor omits target_object_and_flags
&2517 a5 2f    LDA &2f ; this_object_tx
&2519 9d 3e 1b STA &1b3e,X ; objects_tx
;                                                               *** # Supervisor omits energy
&251c a5 31    LDA &31 ; this_object_ty
&251e 9d 5e 1b STA &1b5e,X ; objects_ty
;                                                               *** # Supervisor omits touching
&2521 a5 28    LDA &28 ; this_object_state
&2523 9d 9e 1b STA &1b9e,X ; objects_state
;                                                               *** # Supervisor omits timer
&2526 20 23 1e JSR &1e23 ; update_object_sprite
&2529 a6 78    LDX &78 ; this_object
; consider_next_object
&252b e8       INX
&252c e0 10    CPX #&10
&252e b0 03    BCS &2533 ; leave
&2530 4c 47 24 JMP &2447 ; update_objects_loop
; leave
&2533 60       RTS

; tile_processing_mode
&2534 00

; colour_3_pixel_values_table
&2535 00 03 0c 0f 30 33 3c 3f c0 c3 cc cf f0 f3 fc ff

; unused
&2545 00 00

; create_new_object_even_if_no_slots_free                           # Unused entry point in supervisor
&2547 a0 00    LDY #&00
&2549 2c a0 01 BIT &01a0 ; (nop)
; create_new_object_if_one_slot_free                                # Unused entry point in supervisor
#1e5d          LDY #&01
&254c 2c a0 04 BIT &04a0 ; (nop)
; create_new_object_if_four_slots_free                              # Unused entry point in supervisor
#1e60          LDY #&04
; create_new_object_if_Y_slots_free                                 # Called with Y = number of slots that must be free
&254f 85 0a    STA &0ac5 ; new_object_type                          #             A = new object type
&2551 86 09    STX &09ff ; tmp_x
&2553 a0 ff    LDY #&ff                                         *** # Supervisor omits checking for most distant object
; find_free_object_slot_loop
&2555 c8       INY
&2556 c0 10    CPY #&10
&2558 b0 3c    BCS &2596 ; leave_after_restoring_X                  # Leave with carry set to indicate no object created
&255a b9 dc 1a LDA &1adc,Y ; objects_y                              # Zero if no object in slot
&255d d0 f6    BNE &2555 ; find_free_object_slot_loop
;                                                               *** # Supervisor omits checking number of free slots
; create_new_object_in_slot_Y
&255f a6 0a    LDX &0a ; object_type                            ***
&2561 bd 65 15 LDA &1565,X ; object_types_palette_and_pickup_table
&2564 29 7f    AND #&7f                                             # .4218421 palette
&2566 99 fe 1a STA &1afe,Y ; objects_palette
&2569 bd 00 15 LDA &1500,X ; object_types_sprite_table
&256c 99 98 1a STA &1a98,Y ; objects_sprite                         # Use sprite for type by default
&256f a9 01    LDA #&01 ; OBJECT_FLAG_NEWLY_CREATED | OBJECT_FLAG_NOT_PLOTTED
&2571 99 ee 1a STA &1aee,Y ; objects_flags
&2574 a9 ff    LDA #&ff
&2576 99 6e 1b STA &1b6e,Y ; objects_touching                       # Set to negative to indicate not touching other object
&2579 98       TYA
&257a 99 2e 1b STA &1b2e,Y ; objects_target_object_and_flags        # Set to new object to indicate not targeting other object
&257d a9 00    LDA #&00
&257f 99 8e 1b STA &1b8e,Y ; objects_tertiary_data_offset           # Set to zero to indicate no tertiary data
&2582 99 9e 1b STA &1b9e,Y ; objects_state
&2585 99 7e 1b STA &1b7e,Y ; objects_timer
&2588 99 0e 1b STA &1b0e,Y ; objects_velocity_x
&258b 99 1e 1b STA &1b1e,Y ; objects_velocity_y
&258e 8a       TXA
&258f 99 88 1a STA &1a88,Y ; objects_type
;                                                               *** # Supervisor omits setting energy
&2592 20 5d 26 JSR &265d ; set_object_x_y_from_this_object_x_y
&2595 18       CLC                                                  # Leave with carry clear to indicate object created
;                                                                   #            Y = slot
; leave_after_restoring_X
&2596 a6 09    LDX &09 ; tmp_x
&2598 60       RTS

; stack_pointer_to_leave_to_if_unable_to_create_primary_object
&2599 00

; get_tile_and_set_sprite_variables
&259a 20 8e 21 JSR &218e ; get_tile_and_check_for_tertiary_objects  # Returns A = tile type
; set_sprite_variables_for_tile
&259d a8       TAY
; calculate_palette_for_tile
&259e b9 c6 17 LDA &17c6,Y ; tiles_palette_table                    # Get entry in tile palette table for tile type
&25a1 d0 0d    BNE &25b0 ; not_stone
; is_stone                                                          # &00 to use stone colour scheme
&25a3 a5 25    LDA &25 ; tile_y
&25a5 38       SEC
&25a6 e9 54    SBC #&54                                             # Stone doesn't appear above y = &50
&25a8 4a       LSR A                                                # 8421.... -> ....8421
&25a9 4a       LSR A
&25aa 4a       LSR A
&25ab 4a       LSR A
&25ac aa       TAX
&25ad bd 1c 21 LDA &211c,X ; strata_palette_table                   # Colour of stones changes every 16 tile rows
; not_stone
&25b0 c9 03    CMP #&03                                             # &01 or &02 to use spaceship colour schemes
&25b2 b0 09    BCS &25bd ; not_spacecraft_part
; is_spacecraft_part
&25b4 69 b1    ADC #&b1 ; &01 -> &b2 (rmy), &02 -> &b3 (rcy)        # Colour of spaceships and base in top half of world
&25b6 24 25    BIT &25 ; tile_y
&25b8 10 54    BPL &260e ; set_tile_palette                         # is different from
&25ba 0a       ASL A 
&25bb 69 90    ADC #&90 ; &01 -> &f5 (gyw), &02 -> &f7 (gmw)        # colour of Triax's machinery in bottom half of world
; not_spacecraft_part
&25bd c9 03    CMP #&03                                             # &03 to use bush colour scheme
&25bf d0 11    BNE &25d2 ; not_bush
; is_bush
&25c1 a5 0f    LDA &0f ; tile_flip
&25c3 2a       ROL A
&25c4 2a       ROL A
&25c5 2a       ROL A
&25c6 e5 25    SBC &25 ; tile_y
&25c8 6a       ROR A
&25c9 18       CLC
&25ca 65 23    ADC &23 ; tile_x
&25cc 29 03    AND #&03
&25ce aa       TAX
&25cf bd 2c 21 LDA &212c,X ; bushes_palette_table                   # Colour of bushes depends on position and flip
; not_bush
&25d2 c9 04    CMP #&04                                             # &04 to use stone colour scheme
&25d4 d0 0c    BNE &25e2 ; not_earth
; is_earth
&25d6 a5 25    LDA &25 ; tile_y                                     # Earth doesn't appear above Y = &4e
&25d8 2a       ROL A                                                # 842..... -> .....842
&25d9 2a       ROL A
&25da 2a       ROL A
&25db 2a       ROL A
&25dc 29 07    AND #&07
&25de aa       TAX
&25df bd 23 21 LDA &2123,X ; strata_palette_table + 7               # Colour of earths changes every 32 tile rows
; not_four
&25e2 c9 05    CMP #&05                                             # &05 to use leaf colour scheme for TILE_POSSIBLE_LEAF
&25e4 d0 1c    BNE &2602 ; not_leaf
; is_leaf
&25e6 a5 25    LDA &25 ; tile_y
&25e8 6a       ROR A                                                # 84218421 -> 1 .8421842
&25e9 6a       ROR A                                                #          -> 2 1.842184
&25ea 45 25    EOR &25 ; tile_y                                     #                        &04 gets EORed with &01
&25ec 6a       ROR A                                                #          -> 4 21.84218
&25ed 90 02    BCC &25f1 ; skip_removing_leaf
&25ef a0 19    LDY #&19 ; TILE_SPACE                                # Remove leaf if (y & 4) and (y & 1) not same
; skip_removing_leaf
&25f1 6a       ROR A                                                #          -> 8 421.8421
&25f2 e5 25    SBC &25 ; tile_y
&25f4 29 40    AND #&40 ; TILE_FLIP_VERTICAL                        # Flip some leaves vertically
&25f6 45 0f    EOR &0f ; tile_flip
&25f8 24 0f    BIT &0f ; tile_flip                                  # &40 set if tile was previously flipped vertically,
&25fa 85 0f    STA &0f ; tile_flip                                  # which depends on the tertiary object for the shaft
&25fc a9 b1    LDA #&b1 ; rgy                                       # If not, leaves are green
&25fe 50 0e    BVC &260e ; set_tile_palette
&2600 69 0a    ADC #&0a ; &bb (cyy) or &bc (ywy)                    # Otherwise, leaves are yellow or white
; not_leaf
&2602 c9 06    CMP #&06                                             # &06 to use mushroom colour scheme
&2604 d0 08    BNE &260e ; set_tile_palette                         # Otherwise use table entry as palette
; is_mushroom
&2606 a9 9c    LDA #&9c ; ywr                                       # Unflipped mushrooms (on floor) are red
&2608 24 0f    BIT &0f ; tile_flip                                  # &40 set if flipped vertically
&260a 50 02    BVC &260e ; set_tile_palette                         # Colour of mushrooms depends on vertical flip
&260c a9 cf    LDA #&cf ; cwb                                       # Flipped mushrooms (on ceiling) are blue
; set_tile_palette
&260e 85 5a    STA &5a ; this_object_palette
&2610 85 5b    STA &5b ; this_object_previous_palette
&2612 a5 0f    LDA &0f ; tile_flip
&2614 85 58    STA &58 ; this_object_flip
&2616 85 59    STA &59 ; this_object_previous_flip
&2618 b9 46 17 LDA &1746,Y ; tiles_sprite_and_y_flip_table          # .4218421 sprite
&261b 29 7f    AND #&7f
&261d aa       TAX
&261e 85 5c    STA &5c ; this_object_sprite
&2620 85 5d    STA &5d ; this_object_previous_sprite
&2622 b9 86 17 LDA &1786,Y ; tiles_y_offset_and_pattern_table       # 8421.... start of tile from top of tile, in &10 fractions
&2625 29 f0    AND #&f0
&2627 24 0f    BIT &0f ; tile_flip                                  # &40 set if flipped vertically
&2629 50 07    BVC &2632 ; not_flipped_vertically
&262b 7d ee 54 ADC &54ee,X ; sprites_height_and_vertical_flip_table
&262e 09 07    ORA #&07                                             # Round down to pixel vertically
&2630 49 ff    EOR #&ff
; not_flipped_vertically
&2632 85 38    STA &38 ; this_object_y_fraction
&2634 85 39    STA &39 ; this_object_previous_y_fraction
&2636 a9 00    LDA #&00
&2638 24 0f    BIT &0f ; tile_flip                                  # &80 set if flipped horizontally
&263a 10 05    BPL &2641 ; not_flipped_horizontally
&263c a9 f2    LDA #&f2                                             # &f0 + 1 for carry + 1 for flip flag
&263e fd 00 54 SBC &5400,X ; sprites_width_and_horizontal_flip_table
; not_flipped_horizontally
&2641 85 36    STA &36 ; this_object_x_fraction
&2643 85 37    STA &37 ; this_object_previous_x_fraction
&2645 a5 23    LDA &23 ; tile_x
&2647 85 3a    STA &3a ; this_object_x
&2649 85 3b    STA &3b ; this_object_previous_x
&264b a5 25    LDA &25 ; tile_y
&264d 85 3c    STA &3c ; this_object_y
&264f 85 3d    STA &3d ; this_object_previous_y
&2651 60       RTS

; set_object_x_y_from_tile_x_y
&2652 a5 23    LDA &23 ; tile_x
&2654 99 b9 1a STA &1ab9,Y ; objects_x
&2657 a5 25    LDA &25 ; tile_y
&2659 99 dc 1a STA &1adc,Y ; objects_y
&265c 60       RTS

; set_object_x_y_from_this_object_x_y
&265d a5 3a    LDA &3a ; this_object_x
&265f 99 b9 1a STA &1ab9,Y ; objects_x
&2662 a5 3c    LDA &3c ; this_object_y
&2664 99 dc 1a STA &1adc,Y ; objects_y
&2667 60       RTS

; this_object_crosses_tile_in_x                                     # Unused in supervisor
; this_object_crosses_tile_in_y - 2
;      x     y
&2668 00 ea 00

; collision_pixel_rounding_table                                    # Unused in supervisor
;      x     y
&266b 0f ea 07

; collision_pixel_rounding_mask_table                               # Unused in supervisor
;      x     y
&266e f0 ea f8

; smallest_overlap_collision_flags_table                            # Unused in supervisor
;      0     2     4     6
;     x+    y+    x-    y-
&2671 20 ea 80 ea 10 ea 40

; unused
&2678 ff

; invert_if_positive
&2679 18       CLC
&267a 30 04    BMI &2680 ; leave                                    # Not necessarily the sign of A
&267c 49 ff    EOR #&ff
&267e 69 01    ADC #&01
; leave
&2680 60       RTS

# Supervisor specific code

; check_for_sideways_ram_after_sei
&2681 78       SEI
&2682 20 87 26 JSR &2687 ; check_for_sideways_ram_after_sei
&2685 58       CLI
&2686 60       RTS

; check_for_sideways_ram
&2687 a2 0f    LDX #&0f
; check_for_sideways_ram_slot_loop                                  # For each slot, starting with the highest,
&2689 a9 0f    LDA #&0f
&268b 8d 62 fe STA &fe62 ; User VIA data direction register B
&268e 8e 60 fe STX &fe60 ; User VIA port B input/output register
&2691 8e 32 fe STX &fe32 ; Solidisk RAM access register
&2694 8e 30 fe STX &fe30 ; Paged ROM latch
&2697 a0 00    LDY #&00
&2699 84 1b    STY &1b ; test_address_low
&269b a9 80    LDA #&80 ; &8000
&269d 85 1c    STA &1c ; test_address_high
; check_for_sideways_ram_byte_loop                                  # Check each byte from &8000 - &bfff
&269f b1 1b    LDA (&1b),Y ; test_address
&26a1 85 0b    STA &0b ; byte
&26a3 a9 aa    LDA #&aa ; 10101010
&26a5 91 1b    STA (&1b),Y ; test_address
&26a7 d1 1b    CMP (&1b),Y ; test_address
&26a9 d0 18    BNE &26c3 ; consider_next_slot
&26ab a9 55    LDA #&55 ; 01010101
&26ad 91 1b    STA (&1b),Y ; test_address
&26af d1 1b    CMP (&1b),Y ; test_address
&26b1 d0 10    BNE &26c3 ; consider_next_slot
&26b3 a5 0b    LDA &0b ; byte
&26b5 91 1b    STA (&1b),Y ; test_address
&26b7 c8       INY
&26b8 d0 e5    BNE &269f ; check_for_sideways_ram_byte_loop
&26ba e6 1c    INC &1c ; test_address_high
&26bc a5 1c    LDA &1c ; test_address_high
&26be c9 c0    CMP #&c0
&26c0 90 dd    BCC &269f ; check_for_sideways_ram_byte_loop
&26c2 60       RTS                                                  # Leave with carry set to indicate sideways RAM found
; consider_next_slot
&26c3 ca       DEX
&26c4 10 c3    BPL &2689 ; check_for_sideways_ram_slot_loop
&26c6 18       CLC                                                  # Leave with carry clear to indicate no sideways RAM found
&26c7 60       RTS

; score_elements
&26c8 00 00 00 00 ; &00 : kills +
&26cc 00 00 00 00 ; &04 : kills -
&26d0 00 00 00 00 ; &08 : bonuses +
; score_time_penalty
&26d4 00 00 00 00 ; &0c : time -
; score_deaths_penalty
&26d8 00 00 00 00 ; &10 : deaths - 
; score_total
&26dc 00 00 00 00 ; &14 : total

; multiply_score_deaths_penalty_by_two
&26e0 0e d8 26 ASL &26d8 ; score_deaths_penalty
&26e3 2e d9 26 ROL &26d9 ; score_deaths_penalty + 1
&26e6 2e da 26 ROL &26da ; score_deaths_penalty + 2
&26e9 2e db 26 ROL &26db ; score_deaths_penalty + 3
&26ec 60       RTS

; calculate_score
&26ed 20 80 2f JSR &2f80 ; decrypt_temporary_copy_of_game_state
&26f0 a2 18    LDX #&18
&26f2 a9 00    LDA #&00
; wipe_score_elements_loop
&26f4 9d c7 26 STA &26c7,X ; score_elements - 1                     # Wipe &26c8 - &26df
&26f7 ca       DEX
&26f8 d0 fa    BNE &26f4 ; wipe_score_elements_loop
&26fa a0 03    LDY #&03
; copy_player_deaths_into_score_deaths_penalty_loop
&26fc b9 2a 1a LDA &1a2a,Y ; player_deaths - 1
&26ff 99 d7 26 STA &26d7,Y ; score_deaths_penalty - 1
&2702 88       DEY
&2703 d0 f7    BNE &26fc ; copy_player_deaths_into_score_deaths_penalty_loop
&2705 8c db 26 STY &26db ; score_deaths_penalty + 3
&2708 a2 02    LDX #&02
; multiply_player_deaths_by_one_hundred                             # Score -100 for each player death
&270a a0 03    LDY #&03
; push_score_deaths_penalty_to_stack_loop
&270c b9 d8 26 LDA &26d8,Y ; score_deaths_penalty
&270f 48       PHA ; number byte
&2710 88       DEY
&2711 10 f9    BPL &270c ; push_score_deaths_penalty_to_stack_loop
&2713 20 e0 26 JSR &26e0 ; multiply_score_deaths_penalty_by_two     # * 4
&2716 20 e0 26 JSR &26e0 ; multiply_score_deaths_penalty_by_two
&2719 18       CLC
&271a a0 fc    LDY #&fc ; -4
; add_to_score_deaths_penalty_loop                                  # + 1
&271c 68       PLA ; number byte
&271d 79 dc 25 ADC &25dc,Y ; score_deaths_penalty - &fc
&2720 99 dc 25 STA &25dc,Y ; score_deaths_penalty - &fc
&2723 c8       INY
&2724 d0 f6    BNE &271c ; add_to_score_deaths_penalty_loop
&2726 20 e0 26 JSR &26e0 ; multiply_score_deaths_penalty_by_two     # * 2, i.e. * 10
&2729 ca       DEX
&272a d0 de    BNE &270a ; multiply_player_deaths_by_one_hundred
&272c 20 08 2c JSR &2c08 ; use_game_time_as_number_after_dividing_by_fifty
&272f a0 04    LDY #&04                                             # Score -1 for each second of game time
; copy_game_time_divided_by_fifty_into_score_time_penalty_loop
&2731 b9 5d 00 LDA &005d,Y ; number - 1
&2734 99 d3 26 STA &26d3,Y ; score_time_penalty - 1
&2737 88       DEY
&2738 d0 f7    BNE &2731 ; copy_game_time_divided_by_fifty_into_score_time_penalty_loop
; check_clawed_robots
&273a a2 04    LDX #&04
&273c a0 00    LDY #&00
; consider_next_clawed_robot
&273e ca       DEX
&273f 30 1e    BMI &275f ; finished_checking_clawed_robots
&2741 bd 67 1a LDA &1a67,X ; clawed_robots_availability
&2744 f0 f8    BEQ &273e ; consider_next_clawed_robot               # Zero if clawed robot has teleported away
&2746 30 f6    BMI &273e ; consider_next_clawed_robot               # Negative if clawed robot is dormant
&2748 98       TYA                                                  # Otherwise clawed robot is primary or destroyed
&2749 48       PHA ; tmp_y
&274a 8a       TXA
&274b 48       PHA ; tmp_x
&274c 18       CLC
&274d 69 22    ADC #&22 ; OBJECT_CLAWED_ROBOT_MAGENTA
&274f 20 89 29 JSR &2989 ; count_number_of_primary_objects_of_type_A
&2752 84 0b    STY &0b ; count
&2754 68       PLA ; tmp_x
&2755 aa       TAX
&2756 68       PLA ; tmp_y
&2757 a8       TAY
&2758 a5 0b    LDA &0b ; count
&275a d0 e2    BNE &273e ; consider_next_clawed_robot               # Zero if clawed robot has been destroyed
&275c c8       INY ; number of clawed robots destroyed
&275d d0 df    BNE &273e ; consider_next_clawed_robot
; finished_checking_clawed_robots
&275f 98       TYA ; number of clawed robots destroyed
&2760 aa       TAX
&2761 f0 0a    BEQ &276d ; skip_scoring_for_destroying_clawed_robots
; score_for_destroying_clawed_robots_loop
&2763 a9 88    LDA #&88 ; 5000
&2765 a0 13    LDY #&13
&2767 20 6e 28 JSR &286e ; add_AY_to_score_kills_bonus              # Score 5000 for each clawed robot destroying
&276a ca       DEX
&276b d0 f6    BNE &2763 ; score_for_destroying_clawed_robots_loop
; skip_scoring_for_destroying_clawed_robots
&276d ad 31 1c LDA &1c31 ; tertiary_objects_data + &83              # Tertiary object &8b, TILE_STONE_DOOR at (&50, &60)
&2770 29 08    AND #&08 ; DOOR_FLAG_SLOW_OR_DESTROYED
&2772 f0 07    BEQ &277b ; skip_scoring_for_destroying_west_stone_door
&2774 a9 28    LDA #&28 ; 9000
&2776 a0 23    LDY #&23
&2778 20 7a 28 JSR &287a ; add_AY_to_score_bonuses_bonus            # Score 9000 for destroying west stone door
; skip_scoring_for_destroying_west_stone_door
&277b a9 02    LDA #&02 ; OBJECT_CREW_MEMBER
&277d 20 c8 28 JSR &28c8 ; count_number_of_objects_of_type_A
&2780 ae c7 28 LDX &28c7 ; object_count_in_top_spaceship
&2783 f0 0a    BEQ &278f ; skip_scoring_for_rescuing_crew_members
; score_for_rescuing_crew_members_loop
&2785 a9 20    LDA #&20 ; 20000
&2787 a0 4e    LDY #&4e
&2789 20 7a 28 JSR &287a ; add_AY_to_score_bonuses_bonus            # Score 20000 for each crew member rescued
&278c ca       DEX
&278d d0 f6    BNE &2785 ; score_for_rescuing_crew_members_loop
; skip_counting 
&278f ad d6 1b LDA &1bd6 ; tertiary_objects_data + &28              # Tertiary object &2a, TILE_ENGINE at (&9f, &3a)
&2792 6a       ROR A                                                # &01 cleared if invisible switch at (&9b, &3b) triggered
&2793 b0 07    BCS &279c ; skip_scoring_for_returning_destinator    # i.e. if destinator has been returned to player's ship
&2795 a9 20    LDA #&20 ; 20000
&2797 a0 4e    LDY #&4e
&2799 20 7a 28 JSR &287a ; add_AY_to_score_bonuses_bonus            # Score 20000 for returning destinator to player's ship
; skip_scoring_for_returning_destinator
&279c ad 5f 1a LDA &1a5f ; waterline_x_ranges_desired_y + 1 (Triax's lab)
&279f 30 07    BMI &27a8 ; skip_scoring_for_flooding_world
&27a1 a9 20    LDA #&20 ; 20000
&27a3 a0 4e    LDY #&4e
&27a5 20 7a 28 JSR &287a ; add_AY_to_score_bonuses_bonus            # Score 20000 for flooding bottom half of world
; skip_scoring_for_flooding_world
; score_for_objects
&27a8 a2 00    LDX #&00
; score_for_objects_loop                                            # For each object type that can be collected or destroyed,
&27aa 8a       TXA
&27ab 48       PHA ; offset
&27ac bd 26 16 LDA &1626,X ; objects_to_check_for_scoring_types
&27af 20 c8 28 JSR &28c8 ; count_number_of_objects_of_type_A
&27b2 68       PLA ; offset
&27b3 aa       TAX
&27b4 bd ca 15 LDA &15ca,X ; objects_to_check_for_scoring_default_counts
&27b7 38       SEC
&27b8 ed c6 28 SBC &28c6 ; object_count
&27bb 90 3d    BCC &27fa ; consider_next_object_type
&27bd 85 0b    STA &0b ; multiplier
&27bf bd f8 15 LDA &15f8,X ; objects_to_check_for_scoring_scores
&27c2 20 4a 28 JSR &284a ; multiply_A_by_multiplier
&27c5 a0 02    LDY #&02
; multiply_result_by_twenty_five_loop                               # Each round multiplies result by five
&27c7 a5 1e    LDA &1e ; result + 3
&27c9 48       PHA
&27ca a5 1d    LDA &1d ; result + 2
&27cc 06 1d    ASL &1d ; result + 2
&27ce 26 1e    ROL &1e ; result + 3
&27d0 06 1d    ASL &1d ; result + 2
&27d2 26 1e    ROL &1e ; result + 3
&27d4 65 1d    ADC &1d ; result + 2
&27d6 85 1d    STA &1d ; result + 2
&27d8 68       PLA
&27d9 65 1e    ADC &1e ; result + 3
&27db 85 1e    STA &1e ; result + 3
&27dd 88       DEY
&27de d0 e7    BNE &27c7 ; multiply_result_by_twenty_five_loop
&27e0 bd 26 16 LDA &1626,X ; objects_to_check_for_scoring_types
&27e3 86 0b    STX &0b ; tmp_x                                      # Used at &28aa when leaving add_AY_to_score_element_X
&27e5 a2 00    LDX #&00 ; kills +                                   # Gain points for killing enemies
&27e7 c9 04    CMP #&04 ; OBJECT_FLUFFY + 1
&27e9 b0 02    BCS &27ed ; not_kills_minus
&27eb a2 04    LDX #&04 ; kills -                                   # Lose points for killing allies
; not_kills_minus
&27ed c9 4a    CMP #&4a ; OBJECT_DESTINATOR
&27ef 90 02    BCC &27f3 ; not_bonuses_plus
&27f1 a2 08    LDX #&08 ; bonuses +                                 # Gain points for collecting items
; not_bonuses_plus
&27f3 a5 1d    LDA &1d ; bonus_low
&27f5 a4 1e    LDY &1e ; bonus_high
&27f7 20 8c 28 JSR &288c ; add_AY_to_score_element_X
; consider_next_object_type
&27fa e8       INX
&27fb e0 2e    CPX #&2e
&27fd d0 ab    BNE &27aa ; score_for_objects_loop
&27ff a2 00    LDX #&00 ; kills +
&2801 20 28 28 JSR &2828 ; add_score_element_X_to_score_total
&2804 a2 04    LDX #&04 ; kills -
&2806 20 39 28 JSR &2839 ; subtract_score_element_X_from_score_total
&2809 a2 08    LDX #&08 ; bonuses +
&280b 20 28 28 JSR &2828 ; add_score_element_X_to_score_total
&280e a2 0c    LDX #&0c ; time -
&2810 20 39 28 JSR &2839 ; subtract_score_element_X_from_score_total
&2813 a2 10    LDX #&10 ; deaths -
&2815 20 39 28 JSR &2839 ; subtract_score_element_X_from_score_total
&2818 ad df 26 LDA &26df ; score_total + 3
&281b 10 0a    BPL &2827 ; leave                                    # If total score is negative, set to zero
&281d a2 04    LDX #&04
&281f a9 00    LDA #&00
; wipe_score_total_loop
&2821 9d db 26 STA &26db,X ; score_total
&2824 ca       DEX
&2825 d0 fa    BNE &2821 ; wipe_score_total_loop
; leave
&2827 60       RTS

; add_score_element_X_to_score_total
&2828 18       CLC
&2829 a0 fc    LDY #&fc ; -4
; add_score_element_X_to_score_total_loop
&282b b9 e0 25 LDA &25e0,Y ; score_total - &fc
&282e 7d c8 26 ADC &26c8,X ; score_elements
&2831 99 e0 25 STA &25e0,Y ; score_total - &fc
&2834 e8       INX
&2835 c8       INY
&2836 d0 f3    BNE &282b ; add_score_element_X_to_score_total_loop
&2838 60       RTS

; subtract_score_element_X_from_score_total
&2839 38       SEC
&283a a0 fc    LDY #&fc ; -4
; subtract_score_element_X_from_score_total_loop
&283c b9 e0 25 LDA &25e0,Y ; score_total - &fc
&283f fd c8 26 SBC &26c8,X ; score_elements
&2842 99 e0 25 STA &25e0,Y ; score_total - &fc
&2845 e8       INX
&2846 c8       INY
&2847 d0 f3    BNE &283c ; subtract_score_element_X_from_score_total_loop
&2849 60       RTS

; multiply_A_by_multiplier
&284a 85 1b    STA &1b ; result
&284c a9 00    LDA #&00
&284e 85 1c    STA &1c ; result + 1
&2850 85 1d    STA &1d ; result + 2
&2852 85 1e    STA &1e ; result + 3
; multiply_A_by_multiplier_loop
&2854 46 0b    LSR &0b ; multiplier
&2856 90 0d    BCC &2865 ; skip_addition
&2858 18       CLC
&2859 a5 1b    LDA &1b ; result
&285b 65 1d    ADC &1d ; result + 2
&285d 85 1d    STA &1d ; result + 2
&285f a5 1c    LDA &1c ; result + 1
&2861 65 1e    ADC &1e ; result + 3
&2863 85 1e    STA &1e ; result + 3
; skip_addition
&2865 06 1b    ASL &1b ; result
&2867 26 1c    ROL &1c ; result + 1
&2869 a5 0b    LDA &0b ; multiplier
&286b d0 e7    BNE &2854 ; multiply_A_by_multiplier_loop
&286d 60       RTS

; add_AY_to_score_kills_bonus
&286e 86 0b    STX &0b ; tmp_x
&2870 a2 00    LDX #&00 ; kills +
&2872 10 18    BPL &288c ; add_AY_to_score_element_X                # Always branches

; add_AY_to_score_kills_penalty                                     # Unused code
&2874 86 0b    STX &0b ; tmp_x
&2876 a2 04    LDX #&04 ; kills -
&2878 10 12    BPL &288c ; add_AY_to_score_element_X                # Always branches

; add_AY_to_score_bonuses_bonus
&287a 86 0b    STX &0b ; tmp_x
&287c a2 08    LDX #&08 ; bonuses +
&287e 10 0c    BPL &288c ; add_AY_to_score_element_X                # Always branches

; add_AY_to_score_time_penalty                                      # Unused code
&2880 86 0b    STX &0b ; tmp_x
&2882 a2 0c    LDX #&0c ; time -
&2884 10 06    BPL &288c ; add_AY_to_score_element_X                # Always branches

; add_AY_to_score_deaths_penalty                                    # Unused code
&2886 86 0b    STX &0b ; tmp_x
&2888 a2 10    LDX #&10 ; deaths -
&288a 10 00    BPL &288c ; add_AY_to_score_element_X                # Always branches

; add_AY_to_score_element_X
&288c 18       CLC
&288d 7d c8 26 ADC &26c8,X ; score_elements
&2890 9d c8 26 STA &26c8,X ; score_elements
&2893 98       TYA
&2894 7d c9 26 ADC &26c9,X ; score_elements + 1
&2897 9d c9 26 STA &26c9,X ; score_elements + 1
&289a a9 00    LDA #&00
&289c 7d ca 26 ADC &26ca,X ; score_elements + 2
&289f 9d ca 26 STA &26ca,X ; score_elements + 2
&28a2 a9 00    LDA #&00
&28a4 7d cb 26 ADC &26cb,X ; score_elements + 3
&28a7 9d cb 26 STA &26cb,X ; score_elements + 3
&28aa a6 0b    LDX &0b ; tmp_x
&28ac 60       RTS

; count_objects_to_check_for_scoring
&28ad a2 00    LDX #&00
; count_objects_to_check_for_scoring_loop
&28af 8a       TXA
&28b0 48       PHA ; offset
&28b1 bd 26 16 LDA &1626,X ; objects_to_check_for_scoring_types
&28b4 20 c8 28 JSR &28c8 ; count_number_of_objects_of_type_A
&28b7 68       PLA ; offset
&28b8 aa       TAX
&28b9 ad c6 28 LDA &28c6 ; object_count
&28bc 9d ca 15 STA &15ca,X ; objects_to_check_for_scoring_default_counts
&28bf e8       INX
&28c0 e0 2e    CPX #&2e
&28c2 d0 eb    BNE &28af ; count_objects_to_check_for_scoring_loop
&28c4 60       RTS

; object_type_to_check
&28c5 00

; object_count
&28c6 00

; object_count_in_top_spaceship
&28c7 00

; count_number_of_objects_of_type_A
&28c8 8d c5 28 STA &28c5 ; object_type_to_check
&28cb a0 00    LDY #&00
&28cd 8c c7 28 STY &28c7 ; object_count_in_top_spaceship
&28d0 20 89 29 JSR &2989 ; count_number_of_primary_objects_of_type_A
&28d3 8c c6 28 STY &28c6 ; object_count
&28d6 ad c5 28 LDA &28c5 ; object_type_to_check
&28d9 20 6e 29 JSR &296e ; count_number_of_secondary_objects_of_type_A
&28dc ad c5 28 LDA &28c5 ; object_type_to_check
&28df 20 e3 28 JSR &28e3 ; count_number_of_tertiary_objects_of_type_A
&28e2 60       RTS

; count_number_of_tertiary_objects_of_type_A
&28e3 a0 00    LDY #&00
&28e5 be 06 18 LDX &1806,Y ; tile_tertiary_object_ranges_table
; count_number_of_tertiary_objects_of_type_A_loop                   # For each range, then each object in that range,
&28e8 98       TYA
&28e9 48       PHA ; tmp_y
&28ea 8a       TXA
&28eb 48       PHA ; tmp_x
&28ec 18       CLC
&28ed 79 10 18 ADC &1810,Y ; tertiary_objects_data_offset
&28f0 85 04    STA &04 ; this_object_tertiary_data_offset
&28f2 18       CLC
&28f3 79 19 18 ADC &1819,Y ; tertiary_objects_type_offset
&28f6 85 05    STA &05 ; this_object_tertiary_type_offset
&28f8 bd 21 19 LDA &1921,X ; tertiary_objects_tile_and_flip
&28fb 29 3f    AND #&3f
&28fd c9 09    CMP #&09 ; TILE_NEST
&28ff f0 25    BEQ &2926 ; count_number_of_tertiary_objects_in_nest_or_pipe
&2901 c9 0a    CMP #&0a ; TILE_PIPE
&2903 f0 21    BEQ &2926 ; count_number_of_tertiary_objects_in_nest_or_pipe
&2905 c9 06    CMP #&06 ; TILE_SPACE_WITH_OBJECT_FROM_TYPE
&2907 f0 3a    BEQ &2943 ; count_number_of_tertiary_objects_in_tile_with_object_from_type
&2909 c9 05    CMP #&05 ; TILE_STONE_HALF_WITH_OBJECT_FROM_TYPE
&290b f0 36    BEQ &2943 ; count_number_of_tertiary_objects_in_tile_with_object_from_type
&290d c9 07    CMP #&07 ; TILE_GREENERY_WITH_OBJECT_FROM_TYPE
&290f f0 32    BEQ &2943 ; count_number_of_tertiary_objects_in_tile_with_object_from_type
&2911 c9 02    CMP #&02 ; TILE_SPACE_WITH_OBJECT_FROM_DATA
&2913 f0 45    BEQ &295a ; count_number_of_tertiary_objects_in_tile_with_object_from_data
; consider_next_tertiary_object
&2915 68       PLA ; tmp_x
&2916 aa       TAX
&2917 68       PLA ; tmp_y
&2918 a8       TAY
&2919 e8       INX
&291a 8a       TXA
&291b d9 07 18 CMP &1807,Y ; tile_tertiary_object_ranges_table + 1
&291e d0 c8    BNE &28e8 ; count_number_of_tertiary_objects_of_type_A_loop
&2920 c8       INY
&2921 c0 09    CPY #&09
&2923 d0 c3    BNE &28e8 ; count_number_of_tertiary_objects_of_type_A_loop
&2925 60       RTS

; count_number_of_tertiary_objects_in_nest_or_pipe
&2926 a6 05    LDX &05 ; this_object_tertiary_type_offset
&2928 bd 99 1c LDA &1c99,X ; tertiary_objects_type
&292b cd c5 28 CMP &28c5 ; object_type_to_check
&292e d0 e5    BNE &2915 ; consider_next_tertiary_object
&2930 a6 04    LDX &04 ; this_object_tertiary_data_offset
&2932 bd ae 1b LDA &1bae,X ; tertiary_objects_data
&2935 4a       LSR A                                                # .42184.. number of creatures in nest or pipe
&2936 4a       LSR A
&2937 29 1f    AND #&1f
&2939 18       CLC
&293a 6d c6 28 ADC &28c6 ; object_count
&293d 8d c6 28 STA &28c6 ; object_count
&2940 4c 15 29 JMP &2915 ; consider_next_tertiary_object

; count_number_of_tertiary_objects_in_tile_with_object_from_type
&2943 a6 05    LDX &05 ; this_object_tertiary_type_offset
&2945 bd 99 1c LDA &1c99,X ; tertiary_objects_type
&2948 cd c5 28 CMP &28c5 ; object_type_to_check
&294b d0 c8    BNE &2915 ; consider_next_tertiary_object
&294d a6 04    LDX &04 ; this_object_tertiary_data_offset
&294f bd ae 1b LDA &1bae,X ; tertiary_objects_data                  # 8....... if set, object needs primary object creating
&2952 10 c1    BPL &2915 ; consider_next_tertiary_object
&2954 ee c6 28 INC &28c6 ; object_count
&2957 4c 15 29 JMP &2915 ; consider_next_tertiary_object

; count_number_of_tertiary_objects_in_tile_with_object_from_data
&295a a6 04    LDX &04 ; this_object_tertiary_data_offset
&295c bd ae 1b LDA &1bae,X ; tertiary_objects_data                  # 8....... if set, object is tertiary object
&295f 10 b4    BPL &2915 ; consider_next_tertiary_object
&2961 29 7f    AND #&7f
&2963 cd c5 28 CMP &28c5 ; object_type_to_check
&2966 d0 ad    BNE &2915 ; consider_next_tertiary_object
&2968 ee c6 28 INC &28c6 ; object_count
&296b 4c 15 29 JMP &2915 ; consider_next_tertiary_object

; count_number_of_secondary_objects_of_type_A
&296e a2 20    LDX #&20
; count_number_of_secondary_objects_of_type_A_loop
&2970 bc 39 1d LDY &1d39,X ; secondary_objects_y - 1                # Zero if no object in slot
&2973 f0 10    BEQ &2985 ; consider_next_secondary_object
&2975 dd 59 1d CMP &1d59,X ; secondary_objects_type - 1
&2978 d0 0b    BNE &2985 ; consider_next_secondary_object
&297a ee c6 28 INC &28c6 ; object_count
&297d 48       PHA
&297e bd 39 1d LDA &1d39,X ; secondary_objects_y - 1
&2981 20 b4 29 JSR &29b4 ; check_if_in_top_spaceship
&2984 68       PLA
; consider_next_secondary_object
&2985 ca       DEX
&2986 d0 e8    BNE &2970 ; count_number_of_secondary_objects_of_type_A_loop
&2988 60       RTS

; count_number_of_primary_objects_of_type_A
&2989 a2 0f    LDX #&0f
&298b a0 00    LDY #&00
&298d 85 0b    STA &0b ; object_type
; count_number_of_primary_objects_of_type_A_loop
&298f bd dc 1a LDA &1adc,X ; objects_y
&2992 f0 1c    BEQ &29b0 ; consider_next_object
&2994 bd 88 1a LDA &1a88,X ; objects_type
&2997 c9 49    CMP #&49 ; OBJECT_PLACEHOLDER
&2999 d0 0a    BNE &29a5 ; not_placeholder
&299b 84 0a    STY &0a ; tmp_y
&299d bc 8e 1b LDY &1b8e,X ; objects_tertiary_data_offset
&29a0 b9 ae 1b LDA &1bae,Y ; tertiary_objects_data
&29a3 a4 0a    LDY &0a ; tmp_y
; not_placeholder
&29a5 c5 0b    CMP &0b ; object_type
&29a7 d0 07    BNE &29b0 ; consider_next_object
&29a9 c8       INY
&29aa bd dc 1a LDA &1adc,X ; objects_y
&29ad 20 b4 29 JSR &29b4 ; check_if_in_top_spaceship
; consider_next_object
&29b0 ca       DEX
&29b1 10 dc    BPL &298f ; count_number_of_primary_objects_of_type_A_loop
&29b3 60       RTS

; check_if_in_top_spaceship
&29b4 38       SEC
&29b5 e9 3a    SBC #&3a ; &3e - 4
&29b7 c9 04    CMP #&04
&29b9 b0 03    BCS &29be ; leave
&29bb ee c7 28 INC &28c7 ; object_count_in_top_spaceship
; leave
&29be 60       RTS

; suppress_updating_screen                                          # Unused in supervisor
&29bf ff

; scrolling_offsets_x_fraction_table                                # Eight tiles minus one &20 fraction horizontal section
;      -  +                                                         # Unused in supervisor
&29c0 00 e0

; scrolling_offsets_x_table                                         # Unused in supervisor
;      -  +
&29c2 00 07

; scrolling_offsets_y_fraction_table                                # Five tiles minus one &40 fraction vertical section
;      -  +                                                         # Unused in supervisor
&29c4 00 c0

; scrolling_offsets_y_table                                         # Unused in supervisor
;      -  +
&29c6 00 04

; screen_wipe_offsets_high_table                                    # Offset in pages from top to bottom of screen
;      0 -2 -4 -6                                                   # Unused in supervisor
&29c8 00 26 24 22

; null_filing_system_function                                       # Called prior to cataloguing, loading and saving
&29cc 60       RTS

; unused
&29cd 60       RTS

; get_drive
&29ce 20 88 32 JSR &3288 ; set_return_after_error_and_escape_to_options_screen
&29d1 a2 18    LDX #&18 ; &2a18 = drive_string
&29d3 a0 2a    LDY #&2a
&29d5 20 fa 32 JSR &32fa ; write_string_at_XY
&29d8 a9 ff    LDA #&ff
&29da 8d 51 32 STA &3251 ; use_font_cursor                          # Set to negative to use cursor
&29dd 20 70 2f JSR &2f70 ; plot_text_cursor
; get_drive_number
&29e0 20 69 32 JSR &3269 ; get_keypress
&29e3 c9 0d    CMP #&0d ; CR
&29e5 f0 17    BEQ &29fe ; leave_after_writing_character
&29e7 38       SEC
&29e8 e9 30    SBC #&30 ; "0"
&29ea c9 04    CMP #&04
&29ec b0 f2    BCS &29e0 ; get_drive_number
&29ee 69 30    ADC #&30 ; "0"
&29f0 8d 58 32 STA &3258 ; filename + 1                             # Set drive number in filename
&29f3 8d 0d 3a STA &3a0d ; cat_command + 4                          # Set drive number in *CAT command
&29f6 20 ee ff JSR &ffee ; OSWRCH
&29f9 a9 0d    LDA #&0d ; CR
&29fb 20 ee ff JSR &ffee ; OSWRCH
; leave_after_writing_character
&29fe 20 ee ff JSR &ffee ; OSWRCH
&2a01 60       RTS

; catalogue_screen
&2a02 20 52 2e JSR &2e52 ; reset_screen_and_text
&2a05 20 cc 29 JSR &29cc ; null_filing_system_function
&2a08 20 ce 29 JSR &29ce ; get_drive
&2a0b 20 fb 2d JSR &2dfb ; initialise_mode_six_screen
&2a0e a2 09    LDX #&09 ; &3a09 = cat_command
&2a10 a0 3a    LDY #&3a
&2a12 20 f7 ff JSR &fff7 ; OSCLI                                    # *CAT [drive]
&2a15 4c 7a 37 JMP &377a ; options_screen_after_keypress

; drive_string
&2a18 11 21                                           ; Set palette to &21 (rgG), green text, red shadow
&2a1a 0d 0a
&2a1c 44 72 69 76 65 3f                               ; "Drive?"
&2a22 11 77                                           ; Set palette to &77 (gmW), white text, green shadow
&2a24 00

; use_next_teleport_position
&2a25 ce 63 2a DEC &2a63 ; player_teleports_remembered_for_see_position_screen
&2a28 10 07    BPL &2a31 ; skip_default_teleport
&2a2a ee 63 2a INC &2a63 ; player_teleports_remembered_for_see_position_screen
&2a2d a0 04    LDY #&04
&2a2f d0 0c    BNE &2a3d ; use_teleport_position
; skip_default_teleport
&2a31 ce 64 2a DEC &2a64 ; player_next_teleport_for_see_position_screen
&2a34 ad 64 2a LDA &2a64 ; player_next_teleport_for_see_position_screen
&2a37 29 03    AND #&03
&2a39 8d 64 2a STA &2a64 ; player_next_teleport_for_see_position_screen
&2a3c a8       TAY
; use_teleport_position
&2a3d b9 4b 1a LDA &1a4b,Y ; player_teleports_x
&2a40 8d b9 1a STA &1ab9 ; objects_x + 0 (player)
&2a43 b9 50 1a LDA &1a50,Y ; player_teleports_y
&2a46 8d dc 1a STA &1adc ; objects_y + 0 (player)
&2a49 ae 98 1a LDX &1a98 ; objects_sprite + 0 (player)
&2a4c bd 00 54 LDA &5400,X ; sprites_width_and_horizontal_flip_table
&2a4f 4a       LSR A
&2a50 49 ff    EOR #&ff
&2a52 69 80    ADC #&80                                             # Centre player in tile horizontally
&2a54 8d a8 1a STA &1aa8 ; objects_x_fraction
&2a57 bd ee 54 LDA &54ee,X ; sprites_height_and_vertical_flip_table
&2a5a 4a       LSR A
&2a5b 49 ff    EOR #&ff
&2a5d 69 80    ADC #&80                                             # Centre player in tile vertically
&2a5f 8d cb 1a STA &1acb ; objects_y_fraction
&2a62 60       RTS

; player_teleports_remembered_for_see_position_screen
&2a63 00

; player_next_teleport_for_see_position_screen
&2a64 00

; save_position_screen
&2a65 20 85 32 JSR &3285 ; reset_screen_then_set_return_after_error_and_escape_to_options_screen
&2a68 20 cc 29 JSR &29cc ; null_filing_system_function
&2a6b a2 31    LDX #&31 ; &2b31 = save_filename_string
&2a6d a0 2b    LDY #&2b
&2a6f 20 fa 32 JSR &32fa ; write_string_at_XY
&2a72 20 14 32 JSR &3214 ; get_filename
&2a75 20 0e 2b JSR &2b0e ; copy_save_file_block
&2a78 20 ce 29 JSR &29ce ; get_drive
&2a7b a9 00    LDA #&00 ; save file
&2a7d a2 48    LDX #&48 ; &2b48 = file_block
&2a7f a0 2b    LDY #&2b
&2a81 20 dd ff JSR &ffdd ; OSFILE
&2a84 a9 03    LDA #&03 ; POSITION_STATE_SAVED
&2a86 8d 1f 33 STA &331f ; position_state
&2a89 20 7e 2b JSR &2b7e ; set_current_filename
&2a8c 4c 85 37 JMP &3785 ; options_screen

; load_position_screen
&2a8f 20 85 32 JSR &3285 ; reset_screen_then_set_return_after_error_and_escape_to_options_screen
&2a92 20 cc 29 JSR &29cc ; null_filing_system_function
&2a95 a2 1a    LDX #&1a ; &2b1a = load_filename_string
&2a97 a0 2b    LDY #&2b
&2a99 20 fa 32 JSR &32fa ; write_string_at_XY
&2a9c 20 14 32 JSR &3214 ; get_filename
&2a9f 20 02 2b JSR &2b02 ; copy_load_file_block
&2aa2 20 ce 29 JSR &29ce ; get_drive
&2aa5 a9 05    LDA #&05 ; read information
&2aa7 a2 48    LDX #&48 ; &2b48 = file_block
&2aa9 a0 2b    LDY #&2b
&2aab 20 dd ff JSR &ffdd ; OSFILE                                   # Returns A = &01 if file found
&2aae c9 01    CMP #&01
&2ab0 d0 1c    BNE &2ace ; not_found                                # If not, leave with "Not found" error
&2ab2 38       SEC
&2ab3 ad 53 2b LDA &2b53 ; file_block + 11                          # Is the length of the file &00000400 ?
&2ab6 49 04    EOR #&04
&2ab8 0d 52 2b ORA &2b52 ; file_block + 10
&2abb 0d 54 2b ORA &2b54 ; file_block + 11
&2abe 0d 55 2b ORA &2b55 ; file_block + 12
&2ac1 f0 17    BEQ &2ada ; good_file
; bad_file
&2ac3 00       BRK                                                  # If not, leave with "Bad file" error
&2ac4 00
&2ac5 42 61 64 20 66 69 6c 65 00                      ; "Bad file"
; not_found
&2ace 00       BRK
&2acf 00
&2ad0 4e 6f 74 20 66 6f 75 6e 64 00                   ; "Not found"
; good_file
&2ada 20 02 2b JSR &2b02 ; copy_load_file_block
&2add a9 ff    LDA #&ff ; load file
&2adf a2 48    LDX #&48 ; &2b48 = file_block
&2ae1 a0 2b    LDY #&2b
&2ae3 20 dd ff JSR &ffdd ; OSFILE
&2ae6 a9 04    LDA #&04 ; &0400 = encrypted_game_state               # Unnecessary code
&2ae8 85 1c    STA &1c ; source_address_high
&2aea a9 00    LDA #&00
&2aec 85 1b    STA &1b ; source_address_low
&2aee a9 02    LDA #&02 ; POSITION_STATE_LOADED
&2af0 8d 1f 33 STA &331f ; position_state
&2af3 20 7e 2b JSR &2b7e ; set_current_filename
; close_all_files_then_options_screen
&2af6 20 ed 26 JSR &26ed ; calculate_score
&2af9 a9 00    LDA #&00 ; close all files
&2afb a8       TAY
&2afc 20 ce ff JSR &ffce ; OSFIND
&2aff 4c 85 37 JMP &3785 ; options_screen

; copy_load_file_block
&2b02 a2 12    LDX #&12
; copy_load_file_block_loop
&2b04 bd 59 2b LDA &2b59,X ; load_file_block - 1
&2b07 9d 47 2b STA &2b47,X ; file_block - 1
&2b0a ca       DEX
&2b0b d0 f7    BNE &2b04 ; copy_load_file_block_loop
&2b0d 60       RTS

; copy_save_file_block
&2b0e a2 12    LDX #&12
; copy_save_file_block_loop
&2b10 bd 6b 2b LDA &2b6b,X ; save_file_block - 1
&2b13 9d 47 2b STA &2b47,X ; file_block - 1
&2b16 ca       DEX
&2b17 d0 f7    BNE &2b10 ; copy_save_file_block_loop
&2b19 60       RTS

; load_filename_string
&2b1a 11 21                                           ; Set palette to &21 (rgG), green text, red shadow
&2b1c 0a
&2b1d 4c 6f 61 64 20 46 69 6c 65 6e 61 6d 65 3f 20    ; "Load Filename? "
&2b2c 0d 0a
&2b2e 0a
&2b2f 3f                                              ; "?"
&2b30 00

; save_filename_string
&2b31 11 21                                           ; Set palette to &21 (rgG), green text, red shadow
&2b33 0a
&2b34 53 61 76 65 20 46 69 6c 65 6e 61 6d 65 3f 20    ; "Save Filename? "
&2b43 0d 0a
&2b45 0a
&2b46 3f                                              ; "?"
&2b47 00

; file_block                                                        # Values are overwritten
&2b48 57 32       ; filename          : &3257 = filename
&2b4a 00 04 ff ff ; load address      : &ffff0400
&2b4e 00 00 00 00 ; execution address : &00000000
&2b52 00 00 00 00 ; start address     : &00000000
&2b56 00 00 00 00 ; end address       : &00000000

; load_file_block
&2b5a 57 32       ; filename          : &3257 = filename
&2b5c 00 04 ff ff ; load address      : &ffff0400
&2b60 00 00 00 00 ; execution address : &00000000
&2b64 00 00 00 00 ; start address     : &00000000
&2b68 00 00 00 00 ; end address       : &00000000

; save_file_block
&2b6c 57 32       ; filename          : &3257 = filename
&2b6e 00 2c ff ff ; load address      : &ffff2c00
&2b72 00 00 00 00 ; execution address : &00000000
&2b76 00 04 ff ff ; start address     : &ffff0400
&2b7a 00 08 ff ff ; end address       : &ffff0800

; set_current_filename
&2b7e a2 ff    LDX #&ff
&2b80 a0 00    LDY #&00
; set_current_filename_loop
&2b82 e8       INX
&2b83 bd 5a 32 LDA &325a,X ; filename + 3
&2b86 c9 20    CMP #&20 ; " "
&2b88 f0 f8    BEQ &2b82 ; set_current_filename_loop
&2b8a c9 0d    CMP #&0d
&2b8c f0 08    BEQ &2b96 ; end_of_filename
&2b8e 99 6c 39 STA &396c,Y ; current_filename
&2b91 c8       INY
&2b92 c0 0e    CPY #&0e
&2b94 d0 ec    BNE &2b82 ; set_current_filename_loop
; end_of_filename
&2b96 a9 22    LDA #&22 ; """ 
&2b98 99 6c 39 STA &396c,Y ; current_filename
&2b9b a9 00    LDA #&00
&2b9d 99 6d 39 STA &396d,Y ; current_filename + 1
&2ba0 60       RTS

; plot_game_time
&2ba1 20 08 2c JSR &2c08 ; use_game_time_as_number_after_dividing_by_fifty
&2ba4 a9 3c    LDA #&3c ; 60
&2ba6 20 c5 2c JSR &2cc5 ; divide_number_by_A
&2ba9 48       PHA ; seconds
&2baa a9 3c    LDA #&3c ; 60
&2bac 20 c5 2c JSR &2cc5 ; divide_number_by_A
&2baf 48       PHA ; minutes
&2bb0 a9 18    LDA #&18 ; 24
&2bb2 20 c5 2c JSR &2cc5 ; divide_number_by_A
&2bb5 48       PHA ; hours
&2bb6 a9 64    LDA #&64 ; 100
&2bb8 20 c5 2c JSR &2cc5 ; divide_number_by_A
&2bbb 48       PHA ; days
&2bbc a9 1b    LDA #&1b ; x
&2bbe 20 1c 2c JSR &2c1c ; prepare_time_part_header
&2bc1 a9 83    LDA #&83 ; CHARACTER_DAYS
&2bc3 20 ee ff JSR &ffee ; OSWRCH                                   # Plot "days"
&2bc6 20 2c 2c JSR &2c2c ; prepare_time_part
&2bc9 a5 5e    LDA &5e ; number
&2bcb 18       CLC
&2bcc 69 30    ADC #&30 ; "0"
&2bce 20 ee ff JSR &ffee ; OSWRCH                                   # Plot hundreds of days
&2bd1 68       PLA ; days
&2bd2 20 34 2d JSR &2d34 ; write_A_as_two_digit_number_then_dot     # Plot tens and ones of days
&2bd5 a9 30    LDA #&30 ; x
&2bd7 20 1c 2c JSR &2c1c ; prepare_time_part_header
&2bda a9 82    LDA #&82 ; CHARACTER_HOURS
&2bdc 20 ee ff JSR &ffee ; OSWRCH                                   # Plot "hrs"
&2bdf 20 2c 2c JSR &2c2c ; prepare_time_part
&2be2 68       PLA ; hours
&2be3 20 34 2d JSR &2d34 ; write_A_as_two_digit_number_then_dot     # Plot number of hours
&2be6 a9 3f    LDA #&3f ; x
&2be8 20 1c 2c JSR &2c1c ; prepare_time_part_header
&2beb a9 81    LDA #&81 ; CHARACTER_MINUTES
&2bed 20 ee ff JSR &ffee ; OSWRCH                                   # Plot "min"
&2bf0 20 2c 2c JSR &2c2c ; prepare_time_part
&2bf3 68       PLA ; minutes
&2bf4 20 34 2d JSR &2d34 ; write_A_as_two_digit_number_then_dot     # Plot number of minutes
&2bf7 a9 4e    LDA #&4e ; x
&2bf9 20 1c 2c JSR &2c1c ; prepare_time_part_header
&2bfc a9 80    LDA #&80 ; CHARACTER_SECONDS
&2bfe 20 ee ff JSR &ffee ; OSWRCH                                   # Plot "secs"
&2c01 20 2c 2c JSR &2c2c ; prepare_time_part
&2c04 68       PLA ; seconds
&2c05 4c 1b 2d JMP &2d1b ; write_A_as_two_digit_number              # Plot number of seconds

; use_game_time_as_number_after_dividing_by_fifty
&2c08 a9 00    LDA #&00
&2c0a 85 62    STA &62 ; number + 4
; use_game_time_as_number_after_dividing_by_fifty_loop
&2c0c a0 04    LDY #&04
&2c0e b9 26 1a LDA &1a26,Y ; game_time - 1
&2c11 99 5d 00 STA &005d,Y ; number - 1
&2c14 88       DEY
&2c15 d0 f7    BNE &2c0e ; use_game_time_as_number_after_dividing_by_fifty_loop
&2c17 a9 32    LDA #&32 ; 50
&2c19 4c c5 2c JMP &2cc5 ; divide_number_by_A

; prepare_time_part_header
&2c1c 8d 3c 2c STA &2c3c ; time_x
&2c1f 20 a9 31 JSR &31a9 ; set_text_x
&2c22 a9 19    LDA #&19
&2c24 20 c7 31 JSR &31c7 ; set_text_y
&2c27 a9 11    LDA #&11 ; rgR                                       # Red text
&2c29 85 86    STA &86 ; text_palette
&2c2b 60       RTS

; prepare_time_part
&2c2c a9 20    LDA #&20
&2c2e 20 c7 31 JSR &31c7 ; set_text_y
&2c31 ad 3c 2c LDA &2c3c ; time_x
&2c34 20 a9 31 JSR &31a9 ; set_text_x
&2c37 a9 7e    LDA #&7e ; mwW                                       # White text, magenta shadow
&2c39 85 86    STA &86 ; text_palette
&2c3b 60       RTS

; time_x
&2c3c 00       BRK

; plot_score
&2c3d a9 2c    LDA #&2c
&2c3f 20 c7 31 JSR &31c7 ; set_text_y
&2c42 a2 ab    LDX #&ab ; &2cab = score_string
&2c44 a0 2c    LDY #&2c
&2c46 20 0b 33 JSR &330b ; move_to_right_of_string_at_XY            # Get width of string
&2c49 a9 00    LDA #&00
&2c4b 85 62    STA &62 ; number + 4
&2c4d a0 04    LDY #&04
; copy_score_loop
&2c4f b9 db 26 LDA &26db,Y ; score - 1
&2c52 99 5d 00 STA &005d,Y ; number - 1
&2c55 88       DEY
&2c56 d0 f7    BNE &2c4f ; copy_score_loop
&2c58 20 79 2c JSR &2c79 ; convert_score_to_string
&2c5b 46 83    LSR &83 ; text_x
&2c5d 66 82    ROR &82 ; text_x_fraction
&2c5f a9 b0    LDA #&b0
&2c61 e5 82    SBC &82 ; text_x_fraction
&2c63 85 82    STA &82 ; text_x_fraction
&2c65 a9 83    LDA #&83
&2c67 e5 83    SBC &83 ; text_x
&2c69 85 83    STA &83 ; text_x
&2c6b a2 ab    LDX #&ab ; &2cab = score_string
&2c6d a0 2c    LDY #&2c
&2c6f 20 fa 32 JSR &32fa ; write_string_at_XY                       # Write "Score : ", right aligned
&2c72 a2 b9    LDX #&b9 ; &2cb9 = score_value_string
&2c74 a0 2c    LDY #&2c
&2c76 4c fa 32 JMP &32fa ; write_string_at_XY                       # Write score

; convert_score_to_string
&2c79 a0 00    LDY #&00
; convert_score_to_digits_loop
&2c7b 98       TYA
&2c7c 48       PHA ; count
&2c7d a9 0a    LDA #&0a ; 10
&2c7f 20 c5 2c JSR &2cc5 ; divide_number_by_A
&2c82 85 0b    STA &0b ; digit
&2c84 68       PLA ; count
&2c85 a8       TAY
&2c86 a5 0b    LDA &0b ; digit
&2c88 18       CLC
&2c89 69 30    ADC #&30 ; "0"
&2c8b 48       PHA ; digit
&2c8c c8       INY
&2c8d a9 00    LDA #&00
&2c8f a2 04    LDX #&04
; check_for_zero_loop
&2c91 15 5d    ORA &5d,X ; number - 1
&2c93 d0 e6    BNE &2c7b ; convert_score_to_digits_loop
&2c95 ca       DEX
&2c96 d0 f9    BNE &2c91 ; check_for_zero_loop
; set_score_value_string_loop
&2c98 68       PLA ; digit
&2c99 9d b9 2c STA &2cb9,X ; score_value_string
&2c9c e8       INX
&2c9d 88       DEY
&2c9e d0 f8    BNE &2c98 ; set_score_value_string_loop
&2ca0 98       TYA
&2ca1 9d b9 2c STA &2cb9,X ; score_value_string
&2ca4 a2 b9    LDX #&b9 ; &2cb9 = score_value_string
&2ca6 a0 2c    LDY #&2c
&2ca8 4c 11 33 JMP &3311 ; move_right_by_length_of_string_at_XY

; score_string
&2cab 11 31                                           ; Set palette to &31 (rgY), yellow text, red shadow
&2cad 53 63 6f 72 65 20 3a 20 20                      ; "Score :  "
&2cb6 11 2c                                           ; Set palette to &2c (ywG), green text, yellow shadow
&2cb8 00

; score_value_string
&2cb9 20 20 20 20 20 20 20 20 20 20 20 20             ; "            "

; divide_number_by_A
&2cc5 85 6b    STA &6b ; divisor + 4
&2cc7 a9 00    LDA #&00
&2cc9 85 67    STA &67 ; divisor
&2ccb 85 68    STA &68 ; divisor + 1
&2ccd 85 69    STA &69 ; divisor + 2
&2ccf 85 6a    STA &6a ; divisor + 3
&2cd1 85 62    STA &62 ; number + 4
&2cd3 a2 20    LDX #&20 ; rounds
; divide_number_loop
&2cd5 46 6b    LSR &6b ; divisor + 4
&2cd7 66 6a    ROR &6a ; divisor + 3
&2cd9 66 69    ROR &69 ; divisor + 2
&2cdb 66 68    ROR &68 ; divisor + 1
&2cdd 66 67    ROR &67 ; divisor
&2cdf 38       SEC
&2ce0 a0 fb    LDY #&fb ; -5
; check_if_greater_than_divisor_loop
&2ce2 b9 63 ff LDA &ff63,Y ; number - &fb
&2ce5 f9 6c ff SBC &ff6c,Y ; divisor - &fb
&2ce8 c8       INY
&2ce9 d0 f7    BNE &2ce2 ; check_if_greater_than_divisor_loop
&2ceb 90 0e    BCC &2cfb ; skip_subtracting_divisor
&2ced a0 fb    LDY #&fb ; -5
; subtract_divisor_loop
&2cef b9 63 ff LDA &ff63,Y ; number - &fb
&2cf2 f9 6c ff SBC &ff6c,Y ; divisor - &fb
&2cf5 99 63 ff STA &ff63,Y ; number - &fb
&2cf8 c8       INY
&2cf9 d0 f4    BNE &2cef ; subtract_divisor_loop
; skip_subtracting_divisor
&2cfb 26 63    ROL &63 ; result
&2cfd 26 64    ROL &64 ; result + 1
&2cff 26 65    ROL &65 ; result + 2
&2d01 26 66    ROL &66 ; result + 3
&2d03 ca       DEX ; rounds
&2d04 d0 cf    BNE &2cd5 ; divide_number_loop
&2d06 a5 5e    LDA &5e ; number
&2d08 48       PHA ; modulus
&2d09 a5 63    LDA &63 ; result
&2d0b 85 5e    STA &5e ; number
&2d0d a5 64    LDA &64 ; result + 1
&2d0f 85 5f    STA &5f ; number + 1
&2d11 a5 65    LDA &65 ; result + 2
&2d13 85 60    STA &60 ; number + 2
&2d15 a5 66    LDA &66 ; result + 3
&2d17 85 61    STA &61 ; number + 3
&2d19 68       PLA ; modulus
&2d1a 60       RTS                                                  # Leave with A = number MOD divisor, number = number DIV divisor

; write_A_as_two_digit_number
&2d1b a2 ff    LDX #&ff
&2d1d 38       SEC
; calculate_ones_loop
&2d1e e9 0a    SBC #&0a ; 10
&2d20 e8       INX
&2d21 b0 fb    BCS &2d1e ; calculate_ones_loop
&2d23 69 0a    ADC #&0a ; 10
&2d25 48       PHA ; ones
&2d26 8a       TXA
&2d27 18       CLC
&2d28 69 30    ADC #&30 ; "0"
&2d2a 20 ee ff JSR &ffee ; OSWRCH
&2d2d 68       PLA ; ones
&2d2e 18       CLC
&2d2f 69 30    ADC #&30 ; "0"
&2d31 4c ee ff JMP &ffee ; OSWRCH

; write_A_as_two_digit_number_then_dot
&2d34 20 1b 2d JSR &2d1b ; write_A_as_two_digit_number
&2d37 a9 2e    LDA #&2e ; "."
&2d39 4c ee ff JMP &ffee ; OSWRCH

; plot_competition_code
&2d3c 20 80 2f JSR &2f80 ; decrypt_temporary_copy_of_game_state
&2d3f a9 02    LDA #&02 ; OBJECT_CREW_MEMBER
&2d41 20 c8 28 JSR &28c8 ; count_number_of_objects_of_type_A
&2d44 20 08 2c JSR &2c08 ; use_game_time_as_number_after_dividing_by_fifty
&2d47 18       CLC
&2d48 a9 37    LDA #&37
&2d4a 20 c5 2d JSR &2dc5 ; permute_number
&2d4d 20 c5 2d JSR &2dc5 ; permute_number
&2d50 65 61    ADC &61 ; number + 3
&2d52 6d dc 26 ADC &26dc ; score_total
&2d55 85 61    STA &61 ; number + 3
&2d57 6d 31 1a ADC &1a31 ; player_keys_collected + 3 (OBJECT_YELLOW_WHITE_RED_KEY)
&2d5a 18       CLC
&2d5b 65 60    ADC &60 ; number + 2
&2d5d 6d dd 26 ADC &26dd ; score_total + 1
&2d60 85 60    STA &60 ; number + 2
&2d62 65 5f    ADC &5f ; number + 2
&2d64 6d de 26 ADC &26de ; score_total + 1
&2d67 85 5f    STA &5f ; number + 1
&2d69 65 5e    ADC &5e ; number
&2d6b 6d df 26 ADC &26df ; score_total + 3
&2d6e 85 5e    STA &5e ; number
&2d70 6d 32 1a ADC &1a32 ; player_keys_collected + 4 (not collectable)
&2d73 20 c5 2d JSR &2dc5 ; permute_number
&2d76 ad 31 1c LDA &1c31 ; tertiary_objects_data + &83              # Tertiary object &8b, TILE_STONE_DOOR at (&50, &60)
;                                                                   # West stone door state
&2d79 29 7f    AND #&7f
&2d7b 20 c5 2d JSR &2dc5 ; permute_number
&2d7e ad 5f 1a LDA &1a5f ; waterline_x_ranges_desired_y + 1 (Triax's lab)
&2d81 29 80    AND #&80
&2d83 20 c5 2d JSR &2dc5 ; permute_number
&2d86 6d c7 28 ADC &28c7 ; object_count_in_top_spaceship            # Number of crew members rescued
&2d89 20 c5 2d JSR &2dc5 ; permute_number
&2d8c ad d6 1b LDA &1bd6 ; tertiary_objects_data + &28              # Tertiary object &2a, TILE_ENGINE at (&9f, &3a)
;                                                                   # Player's ship engine state 
&2d8f 29 7f    AND #&7f
&2d91 20 c5 2d JSR &2dc5 ; permute_number
&2d94 a9 10    LDA #&10
&2d96 20 a9 31 JSR &31a9 ; set_text_x
&2d99 a9 38    LDA #&38
&2d9b 20 c7 31 JSR &31c7 ; set_text_y
&2d9e a2 b7    LDX #&b7 ; &2db7 = comp_string
&2da0 a0 2d    LDY #&2d
&2da2 20 fa 32 JSR &32fa ; write_string_at_XY                       # Plot "Comp. :  "
&2da5 a2 04    LDX #&04
; plot_competition_code_loop
&2da7 8a       TXA
&2da8 48       PHA ; count
&2da9 a9 61    LDA #&61 ; 97
&2dab 20 c5 2c JSR &2cc5 ; divide_number_by_A
&2dae 20 1b 2d JSR &2d1b ; write_A_as_two_digit_number              # Plot competition code
&2db1 68       PLA ; count
&2db2 aa       TAX
&2db3 ca       DEX
&2db4 d0 f1    BNE &2da7 ; plot_competition_code_loop
&2db6 60       RTS

; comp_string
&2db7 11 31                                           ; Set palette to &31 (rgY), yellow text, red shadow
&2db9 43 6f 6d 70 2e 20 3a 20 20                      ; "Comp. :  "
&2dc2 11 1c                                           ; Set palette to &1c (ywR), red text, yellow shadow
&2dc4 00

; permute_number
&2dc5 65 61    ADC &61 ; number + 3
&2dc7 65 5f    ADC &5f ; number + 1
&2dc9 85 5f    STA &5f ; number + 1
&2dcb 65 60    ADC &60 ; number + 2
&2dcd 85 60    STA &60 ; number + 2
&2dcf 65 61    ADC &61 ; number + 3
&2dd1 85 61    STA &61 ; number + 3
&2dd3 65 5e    ADC &5e ; number
&2dd5 85 5e    STA &5e ; number
&2dd7 60       RTS

; wipe_objects
&2dd8 a2 0f    LDX #&0f
&2dda a9 00    LDA #&00
; wipe_objects_loop
&2ddc 9d dc 1a STA &1adc,X ; objects_y                              # Set to zero to indicate no object in slot
&2ddf ca       DEX
&2de0 10 fa    BPL &2ddc ; wipe_objects_loop
&2de2 60       RTS

; plot_tile
&2de3 20 9a 25 JSR &259a ; get_tile_and_set_sprite_variables
&2de6 20 bf 20 JSR &20bf ; toggle_sprite_plotting_mode
&2de9 a9 a0    LDA #&a0 ; 10100000                                  # Set bits to suppress calculating variables for previous sprite
&2deb 20 db 20 JSR &20db ; plot_tile_after_setting_offscreen_flags
&2dee 4c bf 20 JMP &20bf ; toggle_sprite_plotting_mode

; unused                                                            # Unused code; doesn't correspond with anything in game
&2df1 ad 88 20 LDA &2088 ; plot_sprite_plotting_opcodes + 2
&2df4 49 14    EOR #&14                                             # Would convert BMI &208c into BIT &02 ; (nop)
&2df6 8d 88 20 STA &2088 ; plot_sprite_plotting_opcodes + 2
&2df9 60       RTS

; allow_sprite_font
&2dfa 00

; initialise_mode_six_screen
&2dfb 20 e5 2e JSR &2ee5 ; write_cls
&2dfe a9 0d    LDA #&0d ; move cursor to start of current line
&2e00 20 cb ff JSR &ffcb ; non-vectored OSWRCH
&2e03 20 26 2e JSR &2e26 ; enable_cursor
&2e06 4e fa 2d LSR &2dfa ; allow_sprite_font                        # Set to positive to not use sprite font
&2e09 a2 15    LDX #&15                                             # Use custom two-colour mode based on MODE 6
&2e0b 20 94 2e JSR &2e94 ; set_video_ula_and_register_values
&2e0e 20 c3 2e JSR &2ec3 ; use_palette_for_mode_six
&2e11 a9 0c    LDA #&0c ; R12: Displayed screen start address register (high)
&2e13 a0 0c    LDY #&0c                                             # Set screen start address to &6000
&2e15 8d 00 fe STA &fe00 ; video register number
&2e18 8c 01 fe STY &fe01 ; video register value
&2e1b a9 0d    LDA #&0d ; R13: Displayed screen start address register (low)
&2e1d a0 00    LDY #&00
&2e1f 8d 00 fe STA &fe00 ; video register number
&2e22 8c 01 fe STY &fe01 ; video register value
&2e25 60       RTS

; enable_cursor
&2e26 a2 01    LDX #&01                                             # Enable cursor
&2e28 4c 2d 2e JMP &2e2d ; enable_or_disable_cursor
; disable_cursor                                                    # Unused entry point
&2e2b a2 00    LDX #&00                                             # Disable cursor
; enable_or_disable_cursor
&2e2d a9 17    LDA #&17
&2e2f 20 cb ff JSR &ffcb ; non-vectored OSWRCH
&2e32 a9 01    LDA #&01
&2e34 20 cb ff JSR &ffcb ; non-vectored OSWRCH
&2e37 8a       TXA
&2e38 20 cb ff JSR &ffcb ; non-vectored OSWRCH
&2e3b a9 00    LDA #&00
&2e3d 20 cb ff JSR &ffcb ; non-vectored OSWRCH
&2e40 20 cb ff JSR &ffcb ; non-vectored OSWRCH
&2e43 20 cb ff JSR &ffcb ; non-vectored OSWRCH
&2e46 20 cb ff JSR &ffcb ; non-vectored OSWRCH
&2e49 20 cb ff JSR &ffcb ; non-vectored OSWRCH
&2e4c 20 cb ff JSR &ffcb ; non-vectored OSWRCH
&2e4f 4c cb ff JMP &ffcb ; non-vectored OSWRCH

; reset_screen_and_text
&2e52 a9 00    LDA #&00
&2e54 85 7e    STA &7e ; screen_start_x_fraction
&2e56 85 80    STA &80 ; screen_start_y_fraction
&2e58 85 82    STA &82 ; text_x_fraction
&2e5a 85 84    STA &84 ; text_y_fraction
&2e5c 85 83    STA &83 ; text_x
&2e5e a9 80    LDA #&80
&2e60 85 7f    STA &7f ; screen_start_x
&2e62 85 83    STA &83 ; text_x
&2e64 a9 80    LDA #&80
&2e66 85 81    STA &81 ; screen_start_y
&2e68 85 85    STA &85 ; text_y
&2e6a a9 ff    LDA #&ff
&2e6c 8d fa 2d STA &2dfa ; allow_sprite_font                        # Set to negative to use sprite font
&2e6f 20 ea 2e JSR &2eea ; set_all_objects_as_unplotted_and_wipe_screen
&2e72 a9 13    LDA #&13 ; Wait for vertical retrace
&2e74 20 f4 ff JSR &fff4 ; OSBYTE
&2e77 20 b7 2e JSR &2eb7 ; use_palette_for_mode_two
&2e7a a9 31    LDA #&31 ; rgY                                       # Yellow text, red shadow
&2e7c 85 86    STA &86 ; text_palette
&2e7e a9 0c    LDA #&0c ; R12: Displayed screen start address register (high)
&2e80 a0 0b    LDY #&0b                                             # Set screen start address to &5800
&2e82 8d 00 fe STA &fe00 ; video register number
&2e85 8c 01 fe STY &fe01 ; video register value
&2e88 a9 0d    LDA #&0d ; R13: Displayed screen start address register (low)
&2e8a a0 00    LDY #&00
&2e8c 8d 00 fe STA &fe00 ; video register number
&2e8f 8c 01 fe STY &fe01 ; video register value
&2e92 a2 0a    LDX #&0a                                             # Use custom sixteen-colour mode based on MODE 2
; set_video_ula_and_register_values
&2e94 8a       TXA
&2e95 48       PHA ; offset for ula and register values
&2e96 a9 13    LDA #&13 ; Wait for vertical retrace
&2e98 20 f4 ff JSR &fff4 ; OSBYTE
&2e9b 68       PLA ; offset for ula and register values
&2e9c aa       TAX
&2e9d a0 09    LDY #&09
; set_video_registers_loop
&2e9f bd cf 2e LDA &2ecf,X ; video_ula_and_register_values
&2ea2 8c 00 fe STY &fe00 ; video register number
&2ea5 8d 01 fe STA &fe01 ; video register value
&2ea8 ca       DEX
&2ea9 88       DEY
&2eaa 10 f3    BPL &2e9f ; set_video_registers_loop
&2eac bd cf 2e LDA &2ecf,X ; video_ula_and_register_values
&2eaf aa       TAX
&2eb0 a0 00    LDY #&00
&2eb2 a9 9a    LDA #&9a ; Write to Video ULA control register and RAM copy
&2eb4 20 f4 ff JSR &fff4 ; OSBYTE
; use_palette_for_mode_two
&2eb7 a0 10    LDY #&10
; use_palette_for_mode_two_loop
&2eb9 b9 2f 21 LDA &212f,Y ; palette_register_values_for_mode_two - 1
&2ebc 8d 21 fe STA &fe21 ; video ULA palette register
&2ebf 88       DEY
&2ec0 d0 f7    BNE &2eb9 ; use_palette_for_mode_two_loop
&2ec2 60       RTS

; use_palette_for_mode_six
&2ec3 a0 10    LDY #&10
; use_palette_for_mode_six_loop
&2ec5 b9 3f 21 LDA &213f,Y ; palette_register_values_for_mode_six - 1
&2ec8 8d 21 fe STA &fe21 ; video ULA palette register
&2ecb 88       DEY
&2ecc d0 f7    BNE &2ec5 ; use_palette_for_mode_six_loop
&2ece 60       RTS

; video_ula_and_register_values                                     # &00 - &0a
&2ecf 14 ; video ULA control register                               # Use MODE 2, disable cursor
&2ed0 7f ; R0: Horizontal total register
&2ed1 40 ; R1: Number of characters per line
&2ed2 5b ; R2: Horizontal sync position register
&2ed3 28 ; R3: Sync width register
&2ed4 26 ; R4: Vertical total register
&2ed5 00 ; R5: Vertical total adjust register
&2ed6 14 ; R6: Vertical displayed register
&2ed7 1d ; R7: Vertical sync position
&2ed8 00 ; R8: Interlace and delay register
&2ed9 07 ; R9: Scan lines per character register
;                                                                   # &0b - &15
&2eda 88 ; video ULA control register                               # Use MODE 6
&2edb 3f ; R0: Horizontal total register
&2edc 28 ; R1: Number of characters per line
&2edd 31 ; R2: Horizontal sync position register
&2ede 24 ; R3: Sync width register
&2edf 26 ; R4: Vertical total register
&2ee0 00 ; R5: Vertical total adjust register
&2ee1 19 ; R6: Vertical displayed register
&2ee2 20 ; R7: Vertical sync position
&2ee3 00 ; R8: Interlace and delay register
&2ee4 07 ; R9: Scan lines per character register

; write_cls
&2ee5 a9 0c    LDA #&0c
&2ee7 4c cb ff JMP &ffcb ; non-vectored OSWRCH

; set_all_objects_as_unplotted_and_wipe_screen
&2eea a2 0f    LDX #&0f
; set_all_objects_as_unplotted_loop
&2eec bd ee 1a LDA &1aee,X ; objects_flags
&2eef 09 01    ORA #&01 ; OBJECT_FLAG_NOT_PLOTTED
&2ef1 9d ee 1a STA &1aee,X ; objects_flags
&2ef4 ca       DEX
&2ef5 10 f5    BPL &2eec ; set_all_objects_as_unplotted_loop
&2ef7 a9 58    LDA #&58 ; &5800 = screen_memory
&2ef9 85 1c    STA &1c ; wipe_address_high
&2efb a9 00    LDA #&00
&2efd 85 1b    STA &1b ; wipe_address_low
&2eff a8       TAY
; wipe_screen_loop                                                  # Wipe &5800 - &7fff
&2f00 91 1b    STA (&1b),Y ; wipe_address
&2f02 c8       INY
&2f03 d0 fb    BNE &2f00 ; wipe_address_high
&2f05 e6 1c    INC &1c ; wipe_address_high
&2f07 10 f7    BPL &2f00 ; wipe_screen_loop
&2f09 4c b7 2e JMP &2eb7 ; use_palette_for_mode_two

; oswrch_handler
&2f0c 85 0b    STA &0b ; character
&2f0e 48       PHA ; tmp_a
&2f0f 8a       TXA
&2f10 48       PHA ; tmp_x
&2f11 98       TYA
&2f12 48       PHA ; tmp_y
&2f13 a5 0b    LDA &0b ; character
&2f15 2c 51 32 BIT &3251 ; use_font_cursor                          # Negative if using cursor
&2f18 30 06    BMI &2f20 ; check_for_control_codes
&2f1a 20 48 2f JSR &2f48 ; write_or_plot_character
&2f1d 4c 42 2f JMP &2f42 ; leave_after_restoring_registers
; check_for_control_codes
&2f20 c9 0d    CMP #&0d ; CR
&2f22 f0 16    BEQ &2f3a ; write_or_plot_newline
&2f24 c9 07    CMP #&07 ; BEL
&2f26 f0 0c    BEQ &2f34 ; to_write_or_plot_character
&2f28 c9 15    CMP #&15 ; NAK disable VDU drivers
&2f2a f0 08    BEQ &2f34 ; to_write_or_plot_character
&2f2c c9 20    CMP #&20 ; " "
&2f2e 90 12    BCC &2f42 ; leave_after_restoring_registers
&2f30 c9 00    CMP #&00
&2f32 30 0e    BMI &2f42 ; leave_after_restoring_registers          # Allow &07, &15 and &20 - &7f
; to_write_or_plot_character
&2f34 20 48 2f JSR &2f48 ; write_or_plot_character
&2f37 4c 42 2f JMP &2f42 ; leave_after_restoring_registers
; write_or_plot_newline
&2f3a 20 48 2f JSR &2f48 ; write_or_plot_character
&2f3d a9 0a    LDA #&0a ; LF
&2f3f 20 48 2f JSR &2f48 ; write_or_plot_character
; leave_after_restoring_registers
&2f42 68       PLA ; tmp_y
&2f43 a8       TAY
&2f44 68       PLA ; tmp_x
&2f45 aa       TAX
&2f46 68       PLA ; tmp_a
&2f47 60       RTS

; write_or_plot_character
&2f48 2c fa 2d BIT &2dfa ; allow_sprite_font                        # Negative if using sprite font
&2f4b 30 03    BMI &2f50 ; plot_character_with_cursor
; write_character
&2f4d 4c cb ff JMP &ffcb ; non-vectored OSWRCH

; plot_character_with_cursor
&2f50 2c 51 32 BIT &3251 ; use_font_cursor                          # Negative if using cursor
&2f53 10 18    BPL &2f6d ; to_plot_character_raw
&2f55 48       PHA ; character
&2f56 a9 7f    LDA #&7f ; DELETE
&2f58 20 01 30 JSR &3001 ; plot_character
&2f5b 68       PLA ; character
&2f5c 20 01 30 JSR &3001 ; plot_character
&2f5f c9 0d    CMP #&0d ; CR
&2f61 d0 04    BNE &2f67 ; not_cr
&2f63 4e 51 32 LSR &3251 ; use_font_cursor                          # Set to positive to suppress cursor
&2f66 60       RTS
; not_cr
&2f67 48       PHA ; tmp_a
&2f68 20 70 2f JSR &2f70 ; plot_text_cursor
&2f6b 68       PLA ; tmp_a
&2f6c 60       RTS
; to_plot_character_raw
&2f6d 4c 01 30 JMP &3001 ; plot_character

; plot_text_cursor
&2f70 a5 86    LDA &86 ; text_palette
&2f72 48       PHA
&2f73 a9 6a    LDA #&6a ; BBC                                       # Cyan text, blue shadow
&2f75 85 86    STA &86 ; text_palette
&2f77 a9 5f    LDA #&5f ; "_"
&2f79 20 01 30 JSR &3001 ; plot_character
&2f7c 68       PLA
&2f7d 85 86    STA &86 ; text_palette
&2f7f 60       RTS

; decrypt_temporary_copy_of_game_state
&2f80 a9 82    LDA #&82 ; &fc82 = &10000 - &37e
&2f82 85 1b    STA &1b ; size_low
&2f84 a9 fc    LDA #&fc
&2f86 85 1c    STA &1c ; size_high
&2f88 a9 04    LDA #&04
&2f8a 8d a4 2f STA &2fa4 ; source_address_high
&2f8d a9 1a    LDA #&1a
&2f8f 8d a7 2f STA &2fa7 ; target_address_high
&2f92 38       SEC
&2f93 f8       SED
&2f94 a0 00    LDY #&00
&2f96 a9 6e    LDA #&6e
&2f98 85 0b    STA &0b ; key
&2f9a a9 92    LDA #&92
; decrypt_temporary_copy_of_game_state_loop                         # Decrypt &0400 - &077d to &1a20 - &1d9d
&2f9c 65 0b    ADC &0b ; key
&2f9e 69 15    ADC #&15
&2fa0 85 0b    STA &0b ; key
&2fa2 59 00 04 EOR &0400,Y ; encrypted_game_state
#     actually EOR source_address,Y
&2fa5 99 20 1a STA &1a20,Y ; temporary_copy_of_game_state
#     actually STA target_address,Y
&2fa8 45 0b    EOR &0b ; key
&2faa c8       INY
&2fab d0 06    BNE &2fb3 ; skip_page
&2fad ee a4 2f INC &2fa4 ; source_address_high
&2fb0 ee a7 2f INC &2fa7 ; target_address_high
; skip_page
&2fb3 e6 1b    INC &1b ; size_low
&2fb5 d0 e5    BNE &2f9c ; decrypt_temporary_copy_of_game_state_loop
&2fb7 e6 1c    INC &1c ; size_high
&2fb9 d0 e1    BNE &2f9c ; decrypt_temporary_copy_of_game_state_loop
&2fbb d8       CLD
&2fbc ad 4f 1a LDA &1a4f ; player_teleports_x + 4
&2fbf c9 99    CMP #&99                                             # Is the fallback teleport position as expected?
&2fc1 d0 2d    BNE &2ff0 ; bad_position                             # If not, the position is bad
&2fc3 ad 54 1a LDA &1a54 ; player_teleports_y + 4
&2fc6 c9 3c    CMP #&3c
&2fc8 d0 26    BNE &2ff0 ; bad_position
&2fca a2 a6    LDX #&a6 ; &fca6 = &10000 - &35a
&2fcc a0 fc    LDY #&fc
&2fce a9 20    LDA #&20 ; &1a20 = temporary_copy_of_game_state
&2fd0 8d db 2f STA &2fdb ; checksum_address_low
&2fd3 a9 1a    LDA #&1a
&2fd5 8d dc 2f STA &2fdc ; checksum_address_high
&2fd8 a9 dc    LDA #&dc
; calculate_game_state_checksum_loop                                # Checksum &1a20 - &1d79 (game_state_checksum_one - 1)
&2fda 4d 20 1a EOR &1a20 ; temporary_copy_of_game_state
#     actually EOR checksum_address
&2fdd ee db 2f INC &2fdb ; checksum_address_low
&2fe0 d0 03    BNE &2fe5 ; skip_page
&2fe2 ee dc 2f INC &2fdc ; checksum_address_high
; skip_page
&2fe5 e8       INX
&2fe6 d0 f2    BNE &2fda ; calculate_game_state_checksum_loop
&2fe8 c8       INY
&2fe9 d0 ef    BNE &2fda ; calculate_game_state_checksum_loop
&2feb cd 7a 1d CMP &1d7a ; game_state_checksum_one                  # Is the checksum as expected?
&2fee f0 06    BEQ &2ff6 ; good_position                            # If not, the position is bad
; bad_position
&2ff0 20 ed 31 JSR &31ed ; copy_default_position
&2ff3 4c 80 2f JMP &2f80 ; decrypt_temporary_copy_of_game_state
; good_position
&2ff6 ad 1f 33 LDA &331f ; position_state                           # Zero if POSITION_STATE_DEFAULT
&2ff9 d0 03    BNE &2ffe ; leave
&2ffb 8d dd 1a STA &1add ; objects_y + 1                            # Set to zero to remove object one (Triax) from display
; leave
&2ffe 60       RTS

; previous_character_to_plot
&2fff 00

; character_to_plot
&3000 00

; plot_character
&3001 48       PHA ; tmp_a
&3002 8d 00 30 STA &3000 ; character_to_plot
&3005 98       TYA
&3006 48       PHA ; tmp_y
&3007 8a       TXA
&3008 48       PHA ; tmp_x
&3009 ad ff 2f LDA &2fff ; previous_character_to_plot
&300c c9 11    CMP #&11                                             # &11 sets palette
&300e d0 0d    BNE &301d ; not_setting_palette
; set_text_palette
&3010 ad 00 30 LDA &3000 ; character_to_plot
&3013 85 86    STA &86 ; text_palette
&3015 a9 00    LDA #&00
&3017 8d ff 2f STA &2fff ; previous_character_to_plot               # Set to zero to use next character as character
&301a 4c c6 30 JMP &30c6 ; leave_after_restoring_registers
; not_setting_palette
&301d ad 00 30 LDA &3000 ; character_to_plot
&3020 c9 20    CMP #&20 ; " "
&3022 b0 42    BCS &3066 ; not_control_code
&3024 c9 0d    CMP #&0d ; CR
&3026 d0 0b    BNE &3033 ; not_cr
; is_cr
&3028 a9 00    LDA #&00
&302a 85 82    STA &82 ; text_x_fraction
&302c a9 80    LDA #&80
&302e 85 83    STA &83 ; text_x
&3030 4c c6 30 JMP &30c6 ; leave_after_restoring_registers
; not_cr
&3033 c9 0a    CMP #&0a ; LF
&3035 d0 25    BNE &305c ; not_lf
&3037 18       CLC
&3038 a5 84    LDA &84 ; text_y_fraction
&303a 69 50    ADC #&50 ; 10 * &08                                  # Move down ten pixels
&303c 85 84    STA &84 ; text_y_fraction
&303e a5 85    LDA &85 ; text_y
&3040 69 00    ADC #&00
&3042 85 85    STA &85 ; text_y
&3044 c9 85    CMP #&85                                             # Is this the bottom of the screen?
&3046 90 11    BCC &3059 ; to_leave_after_restoring_registers
; wait_for_shift_or_ctrl_release
&3048 a2 ff    LDX #&ff ; SHIFT
&304a 20 9f 31 JSR &319f ; check_for_keypress
&304d 10 07    BPL &3056 ; shift_not_pressed
&304f a2 fe    LDX #&fe ; CTRL
&3051 20 9f 31 JSR &319f ; check_for_keypress
&3054 30 f2    BMI &3048 ; wait_for_shift_or_ctrl_release
; shift_not_pressed
&3056 20 52 2e JSR &2e52 ; reset_screen_and_text
; to_leave_after_restoring_registers
&3059 4c c6 30 JMP &30c6 ; leave_after_restoring_registers
; not_lf
&305c c9 11    CMP #&11
&305e d0 03    BNE &3063 ; to_leave_after_restoring_registers
&3060 8d ff 2f STA &2fff ; previous_character_to_plot               # Set to &11 to use next character as palette
; to_leave_after_restoring_registers
&3063 4c c6 30 JMP &30c6 ; leave_after_restoring_registers
; not_control_code
&3066 c9 7f    CMP #&7f ; DELETE
&3068 f0 21    BEQ &308b ; is_delete
; is_regular_character
&306a 18       CLC
&306b 69 5d    ADC #&5d ; SPRITE_CHARACTER_20 - &20
&306d 48       PHA ; sprite
&306e ac 5e 31 LDY &315e ; line_position
&3071 99 5f 31 STA &315f,Y ; line_characters                        # Store character for unplotting if deleting
&3074 a5 86    LDA &86 ; text_palette
&3076 99 7f 31 STA &317f,Y ; line_palettes
&3079 c8       INY
&307a 98       TYA
&307b 29 1f    AND #&1f
&307d 8d 5e 31 STA &315e ; line_position
&3080 a5 86    LDA &86 ; text_palette
&3082 85 5a    STA &5a ; this_object_palette
&3084 68       PLA ; sprite
&3085 20 de 30 JSR &30de ; plot_sprite_at_text_position             # Plot character
&3088 4c c6 30 JMP &30c6 ; leave_after_restoring_registers
; is_delete
&308b ac 5e 31 LDY &315e ; line_position
&308e 88       DEY
&308f 98       TYA
&3090 29 1f    AND #&1f
&3092 a8       TAY
&3093 8d 5e 31 STA &315e ; line_position
&3096 be 5f 31 LDX &315f,Y ; line_characters
&3099 18       CLC
&309a bd 00 54 LDA &5400,X ; sprites_width_and_horizontal_flip_table
&309d 29 f0    AND #&f0
&309f 69 20    ADC #&20 ; 2 pixels                                  # One pixel gap between characters (see &314b)
&30a1 85 0b    STA &0b ; width
&30a3 38       SEC
&30a4 a5 82    LDA &82 ; text_x_fraction
&30a6 e5 0b    SBC &0b ; width
&30a8 85 82    STA &82 ; text_x_fraction
&30aa 48       PHA ; text_x_fraction
&30ab a5 83    LDA &83 ; text_x
&30ad e9 00    SBC #&00
&30af 85 83    STA &83 ; text_x
&30b1 48       PHA ; text_x
&30b2 b9 7f 31 LDA &317f,Y ; line_palettes
&30b5 85 5a    STA &5a ; this_object_palette
&30b7 b9 5f 31 LDA &315f,Y ; line_characters
&30ba 20 de 30 JSR &30de ; plot_sprite_at_text_position             # Unplot character
&30bd 68       PLA ; text_x
&30be 85 83    STA &83 ; text_x
&30c0 68       PLA ; text_x_fraction
&30c1 85 82    STA &82 ; text_x_fraction
&30c3 4c c6 30 JMP &30c6 ; leave_after_restoring_registers          # Unnecessary code
; leave_after_restoring_registers
&30c6 68       PLA ; tmp_x
&30c7 aa       TAX
&30c8 68       PLA ; tmp_y
&30c9 a8       TAY
&30ca 68       PLA ; tmp_a
&30cb 60       RTS

; use_text_position
&30cc a5 82    LDA &82 ; text_x_fraction
&30ce 85 36    STA &36 ; this_object_x_fraction
&30d0 a5 83    LDA &83 ; text_x
&30d2 85 3a    STA &3a ; this_object_x
&30d4 a5 84    LDA &84 ; text_y_fraction
&30d6 85 38    STA &38 ; this_object_y_fraction
&30d8 a5 85    LDA &85 ; text_y
&30da 85 3c    STA &3c ; this_object_y
&30dc 60       RTS

; allow_plotting_sprites
&30dd ff

; plot_sprite_at_text_position 
&30de 85 5c    STA &5c ; this_object_sprite
&30e0 2c dd 30 BIT &30dd ; allow_plotting_sprites                   # Negative to plot sprite, positive to move by width
&30e3 10 5c    BPL &3141 ; skip_plotting_sprite
&30e5 20 cc 30 JSR &30cc ; use_text_position
&30e8 a2 00    LDX #&00
&30ea a5 5c    LDA &5c ; this_object_sprite
&30ec 38       SEC
&30ed e9 be    SBC #&be
&30ef c9 1a    CMP #&1a
&30f1 b0 02    BCS &30f5 ; set_y_offset
&30f3 a2 08    LDX #&08                                             # Offset sprites &be - &d7 (lowercase letters) vertically
; set_y_offset
&30f5 86 0b    STX &0b ; y_offset
&30f7 a9 80    LDA #&80                                             # Left of screen
&30f9 85 7f    STA &7f ; screen_start_x
&30fb a9 80    LDA #&80                                             # Top of screen
&30fd 85 81    STA &81 ; screen_start_y
&30ff a9 00    LDA #&00
&3101 85 7e    STA &7e ; screen_start_x_fraction
&3103 85 80    STA &80 ; screen_start_y_fraction
&3105 a2 0f    LDX #&0f
&3107 a9 00    LDA #&00
; remove_objects_loop
&3109 9d dc 1a STA &1adc,X ; objects_y                              # Set to zero to indicate no object in slot
&310c ca       DEX
&310d 10 fa    BPL &3109 ; remove_objects_loop
&310f a5 3a    LDA &3a ; this_object_x                              # Use object slot 0 for sprite to be plotted
&3111 8d b9 1a STA &1ab9 ; objects_x
&3114 a5 36    LDA &36 ; this_object_x_fraction
&3116 8d a8 1a STA &1aa8 ; objects_x_fraction
&3119 18       CLC
&311a a5 38    LDA &38 ; this_object_y_fraction
&311c 65 0b    ADC &0b ; y_offset
&311e 8d cb 1a STA &1acb ; objects_y_fraction
&3121 a5 3c    LDA &3c ; this_object_y
&3123 69 00    ADC #&00
&3125 8d dc 1a STA &1adc ; objects_y
&3128 a5 5a    LDA &5a ; this_object_palette
&312a 8d fe 1a STA &1afe ; objects_palette
&312d a9 01    LDA #&01 ; OBJECT_FLAG_NOT_PLOTTED
&312f 8d ee 1a STA &1aee ; objects_flags
&3132 a9 49    LDA #&49 ; OBJECT_PLACEHOLDER
&3134 8d 88 1a STA &1a88 ; objects_type
&3137 a5 5c    LDA &5c ; this_object_sprite
&3139 8d 98 1a STA &1a98 ; objects_sprite
&313c 48       PHA ; sprite
&313d 20 45 24 JSR &2445 ; update_objects                           # Plot the sprite
&3140 68       PLA ; sprite
; skip_plotting_sprite 
&3141 aa       TAX
&3142 38       SEC
&3143 e9 7d    SBC #&7d
&3145 c9 5f    CMP #&5f                                             # Set carry for sprites &00 - &7c and &dc - &ed
&3147 a9 10    LDA #&10 ; 1 pixel                                   # Widths are minus one pixel
&3149 b0 02    BCS &314d ; skip_padding
&314b a9 20    LDA #&20 ; 2 pixel                                   # Add one pixel gap between characters
; skip_padding
&314d 18       CLC
&314e 7d 00 54 ADC &5400,X ; sprites_width_and_horizontal_flip_table
&3151 29 f0    AND #&f0
&3153 65 82    ADC &82 ; text_x_fraction
&3155 85 82    STA &82 ; text_x_fraction
&3157 a5 83    LDA &83 ; text_x
&3159 69 00    ADC #&00
&315b 85 83    STA &83 ; text_x
&315d 60       RTS

; line_position
&315e 00      

; line_characters
&315f 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e
&316f 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e

; line_palettes
&317f 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e
&318f 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e

; check_for_keypress
&319f a0 ff    LDY #&ff
&31a1 a9 81    LDA #&81 ; Scan for a particular key
&31a3 20 f4 ff JSR &fff4 ; OSBYTE                                   # Returns X = &ff if key pressed, &00 if not
&31a6 e0 00    CPX #&00
&31a8 60       RTS

; set_text_x
&31a9 85 82    STA &82 ; text_x_fraction
&31ab a9 00    LDA #&00
&31ad 85 83    STA &83 ; text_x
&31af 06 82    ASL &82 ; text_x_fraction                            # * 16 to convert pixels into fractions
&31b1 26 83    ROL &83 ; text_x
&31b3 06 82    ASL &82 ; text_x_fraction
&31b5 26 83    ROL &83 ; text_x
&31b7 06 82    ASL &82 ; text_x_fraction
&31b9 26 83    ROL &83 ; text_x
&31bb 06 82    ASL &82 ; text_x_fraction
&31bd 26 83    ROL &83 ; text_x
&31bf a9 80    LDA #&80                                             # Relative to left of screen
&31c1 18       CLC
&31c2 65 83    ADC &83 ; text_x
&31c4 85 83    STA &83 ; text_x
&31c6 60       RTS

; set_text_y
&31c7 85 84    STA &84 ; text_y_fraction
&31c9 a9 00    LDA #&00
&31cb 85 85    STA &85 ; text_y
&31cd 06 84    ASL &84 ; text_y_fraction                            # * 8 to convert pixels into fractions
&31cf 26 85    ROL &85 ; text_y
&31d1 06 84    ASL &84 ; text_y_fraction
&31d3 26 85    ROL &85 ; text_y
&31d5 06 84    ASL &84 ; text_y_fraction
&31d7 26 85    ROL &85 ; text_y
&31d9 a9 80    LDA #&80                                             # Relative to top of screen
&31db 18       CLC
&31dc 65 85    ADC &85 ; text_y
&31de 85 85    STA &85 ; text_y
&31e0 60       RTS

; default_position_screen
&31e1 20 52 2e JSR &2e52 ; reset_screen_and_text
&31e4 20 ed 31 JSR &31ed ; copy_default_position
&31e7 20 ed 26 JSR &26ed ; calculate_score
&31ea 4c 85 37 JMP &3785 ; options_screen

; copy_default_position
&31ed a9 52    LDA #&52 ; &3b52 = encrypted_default_game_state
&31ef 85 1b    STA &1b ; source_address_low
&31f1 a9 3b    LDA #&3b
&31f3 85 1c    STA &1c ; source_address_high
&31f5 a9 04    LDA #&04
&31f7 8d 02 32 STA &3202 ; target_address_high
&31fa a2 04    LDX #&04
; copy_default_position_page_loop
&31fc a0 00    LDY #&00
; copy_default_position_byte_loop
&31fe b1 1b    LDA (&1b),Y ; source_address
&3200 99 00 04 STA &0400,Y ; encrypted_game_state
#     actually STA target_address,Y
&3203 88       DEY
&3204 d0 f8    BNE &31fe ; copy_default_position_byte_loop
&3206 e6 1c    INC &1c ; source_address_high
&3208 ee 02 32 INC &3202 ; target_address_high
&320b ca       DEX
&320c d0 ee    BNE &31fc ; copy_default_position_page_loop
&320e a9 00    LDA #&00 ; POSITION_STATE_DEFAULT
&3210 8d 1f 33 STA &331f ; position_state
&3213 60       RTS

; get_filename
&3214 a9 04    LDA #&04 ; Define action of cursor editing keys
&3216 a2 00    LDX #&00 ; Cursor keys have editing effect
&3218 a0 00    LDY #&00
&321a 20 f4 ff JSR &fff4 ; OSBYTE
&321d 2c fa 2d BIT &2dfa ; allow_sprite_font                        # Negative if using sprite font
&3220 10 0c    BPL &322e ; skip_plotting_sprite_cursor
&3222 20 70 2f JSR &2f70 ; plot_text_cursor
&3225 a9 04    LDA #&04 ; Define action of cursor editing keys 
&3227 a2 01    LDX #&01 ; Cursor keys return ASCII values 135-139
&3229 a0 00    LDY #&00
&322b 20 f4 ff JSR &fff4 ; OSBYTE
; skip_plotting_sprite_cursor
&322e a9 ff    LDA #&ff
&3230 8d 51 32 STA &3251 ; use_font_cursor                          # Set to negative to use cursor
&3233 a5 86    LDA &86 ; text_palette
&3235 48       PHA ; text_palette
&3236 a9 77    LDA #&77 ; gmW                                       # White text, green shadow
&3238 85 86    STA &86 ; text_palette
&323a a2 52    LDX #&52 ; &3252 = input_block
&323c a0 32    LDY #&32
&323e a9 00    LDA #&00 ; Input line of text
&3240 20 f1 ff JSR &fff1 ; OSWORD                                   # Returns carry set if ESCAPE pressed
&3243 68       PLA ; text_palette
&3244 85 86    STA &86 ; text_palette
&3246 a9 00    LDA #&00
&3248 8d 51 32 STA &3251 ; use_font_cursor                          # Set to positive to suppress cursor
&324b 90 03    BCC &3250 ; leave
&324d 4c d0 32 JMP &32d0 ; generate_escape_error
; leave
&3250 60       RTS

; use_font_cursor
&3251 00

; input_block
&3252 5a 32 ; &325a = filename + 3
&3254 0e    ; length
&3255 20 7f ; accept " " to DELETE

; filename                                                          # Drive number is modified
&3257 3a 30 2e                                        ; ":0."
&325a 0d 0d 0d 0d 0d 0d 0d 0d 0d 0d 0d 0d 0d 0d 0d

; get_keypress
&3269 20 e0 ff JSR &ffe0 ; OSRDCH                                   # Returns carry set if ESCAPE pressed
&326c 90 07    BCC &3275 ; leave_with_carry_clear
&326e c9 1b    CMP #&1b ; ESCAPE
&3270 d0 03    BNE &3275 ; leave_with_carry_clear
&3272 4c d0 32 JMP &32d0 ; generate_escape_error
; leave_with_carry_clear
&3275 18       CLC                                                  # Leave with carry clear to indicate ESCAPE not pressed
&3276 60       RTS

; set_return_after_error_address
&3277 8e cc 32 STX &32cc ; return_after_error_address_low
&327a 8c cd 32 STY &32cd ; return_after_error_address_after
&327d 60       RTS

; set_return_after_escape_address
&327e 8e ce 32 STX &32ce ; return_after_escape_address_low
&3281 8c cf 32 STY &32cf ; return_after_escape_address_high
&3284 60       RTS

; reset_screen_then_set_return_after_error_and_escape_to_options_screen
&3285 20 52 2e JSR &2e52 ; reset_screen_and_text
; set_return_after_error_and_escape_to_options_screen
&3288 a2 7a    LDX #&7a ; &377a = options_screen_after_keypress
&328a a0 37    LDY #&37
&328c 20 77 32 JSR &3277 ; set_return_after_error_address
&328f a2 85    LDX #&85 ; &3785 = options_screen
&3291 a0 37    LDY #&37
&3293 4c 7e 32 JMP &327e ; set_return_after_escape_address

; set_return_after_error_and_escape_to_close_all_files_then_options_screen # Unused code
&3296 a2 f6    LDX #&f6 ; &2af6 = close_all_files_then_options_screen
&3298 a0 2a    LDY #&2a
&329a 20 77 32 JSR &3277 ; set_return_after_error_address
&329d 4c 7e 32 JMP &327e ; set_return_after_escape_address

; brk_handler
&32a0 20 20 33 JSR &3320 ; initialise_oswrch_handler
&32a3 a9 71    LDA #&71 ; rgW                                       # White text, red shadow
&32a5 85 86    STA &86 ; text_palette
&32a7 4e 51 32 LSR &3251 ; use_font_cursor                          # Set to positive to suppress cursor
&32aa a9 0f    LDA #&0f ; Flush all buffers
&32ac a2 00    LDX #&00 ; all buffers
&32ae a0 00    LDY #&00
&32b0 20 f4 ff JSR &fff4 ; OSBYTE
&32b3 a5 ff    LDA &ff ; os_escape_flag
&32b5 48       PHA ; os_escape_flag
&32b6 10 08    BPL &32c0 ; not_escape
&32b8 a9 7c    LDA #&7c ; Clear ESCAPE condition
&32ba 20 f4 ff JSR &fff4 ; OSBYTE
&32bd 4c c3 32 JMP &32c3 ; skip_writing_error_message
; not_escape
&32c0 20 de 32 JSR &32de ; write_error_message
; skip_writing_error_message
&32c3 68       PLA ; os_escape_flag
&32c4 30 03    BMI &32c9 ; to_return_after_escape_address
&32c6 6c cc 32 JMP (&32cc) ; return_after_error_address
; to_return_after_escape_address
&32c9 6c ce 32 JMP (&32ce) ; return_after_escape_address

; return_after_error_address
&32cc 85 37 ; &3785 = options_screen

; return_after_escape_address
&32ce 85 37 ; &3785 = options_screen

; generate_escape_error
&32d0 a9 7d    LDA #&7d ; Set ESCAPE condition
&32d2 20 f4 ff JSR &fff4 ; OSBYTE
&32d5 00       BRK
&32d6 00
&32d7 45 73 63 61 70 65 00                            ; "Escape"
; write_error_message
&32de 20 f0 32 JSR &32f0 ; write_newline_and_carriage_return
&32e1 a0 01    LDY #&01
; write_error_message_loop
&32e3 b1 fd    LDA (&fd),Y ; os_error_message_address
&32e5 f0 06    BEQ &32ed ; end_of_error_message
&32e7 20 ee ff JSR &ffee ; OSWRCH
&32ea c8       INY
&32eb d0 f6    BNE &32e3 ; write_error_message_loop
; end_of_error_message
&32ed 4c f0 32 JMP &32f0 ; write_newline_and_carriage_return        # Unnecessary code
; write_newline_and_carriage_return
&32f0 a9 0a    LDA #&0a ; LF
&32f2 20 ee ff JSR &ffee ; OSWRCH
&32f5 a9 0d    LDA #&0d ; CR
&32f7 4c ee ff JMP &ffee ; OSWRCH

; write_string_at_XY
&32fa 86 1d    STX &1d ; string_address_low
&32fc 84 1e    STY &1e ; string_address_high
&32fe a0 00    LDY #&00
; write_string_at_XY_loop
&3300 b1 1d    LDA (&1d),Y ; string_address
&3302 f0 06    BEQ &330a ; leave
&3304 20 ee ff JSR &ffee ; OSWRCH
&3307 c8       INY
&3308 d0 f6    BNE &3300 ; write_string_at_XY_loop
; leave
&330a 60       RTS

; move_to_right_of_string_at_XY
&330b a9 00    LDA #&00
&330d 85 82    STA &82 ; text_x_fraction
&330f 85 83    STA &83 ; text_x
; move_right_by_length_of_string_at_XY
&3311 a9 00    LDA #&00
&3313 8d dd 30 STA &30dd ; allow_plotting_sprites                   # Set to positive to suppress plotting sprites
&3316 20 fa 32 JSR &32fa ; write_string_at_XY
&3319 a9 ff    LDA #&ff
&331b 8d dd 30 STA &30dd ; allow_plotting_sprites                   # Set to negative to allow plotting sprites
&331e 60       RTS

; position_state
&331f 00 ; POSITION_STATE_DEFAULT

; initialise_oswrch_handler
&3320 a9 0c    LDA #&0c ; &2f0c = oswrch_handler
&3322 8d 0e 02 STA &020e ; oswrch_vector_low
&3325 a9 2f    LDA #&2f
&3327 8d 0f 02 STA &020f ; oswrch_vector_high
&332a 60       RTS

; previous_osfile_vector_low
&332b 00
; previous_osfile_vector_high
&332c 00

; previous_file_system_control_vector_low
&332d 00
; previous_file_system_control_vector_high
&332e 00

; entry_point_after_relocation
&332f a9 a0    LDA #&a0 ; &32a0 = brk_handler
&3331 8d 02 02 STA &0202 ; brk_vector_low
&3334 a9 32    LDA #&32
&3336 8d 03 02 STA &0203 ; brk_vector_high
&3339 a9 c8    LDA #&c8 ; Read/Write BREAK/ESCAPE effect
&333b a2 02    LDX #&02 ; Clear memory on next RESET
&333d a0 00    LDY #&00
&333f 20 f4 ff JSR &fff4 ; OSBYTE
&3342 ad 12 02 LDA &0212 ; osfile_vector_low
&3345 8d 2b 33 STA &332b ; previous_osfile_vector_low
&3348 ad 13 02 LDA &0213 ; osfile_vector_high
&334b 8d 2c 33 STA &332c ; previous_osfile_vector_high
&334e ad 1e 02 LDA &021e ; file_system_control_vector_low
&3351 8d 2d 33 STA &332d ; previous_file_system_control_vector_low
&3354 ad 1f 02 LDA &021f ; file_system_control_vector_high
&3357 8d 2e 33 STA &332e ; previous_file_system_control_vector_high
&335a 20 20 33 JSR &3320 ; initialise_oswrch_handler
&335d a2 14    LDX #&14 ; &3a14 = tape_command
&335f a0 3a    LDY #&3a
&3361 20 f7 ff JSR &fff7 ; OSCLI                                    # *TAPE
&3364 a2 0f    LDX #&0f ; &3a0f = disc_command
&3366 a0 3a    LDY #&3a
&3368 20 f7 ff JSR &fff7 ; OSCLI                                    # *DISC
&336b 20 ad 28 JSR &28ad ; count_objects_to_check_for_scoring       # Count objects in default position
&336e a9 16    LDA #&16                                             # Change to MODE 6
&3370 20 cb ff JSR &ffcb ; non-vectored OSWRCH
&3373 a9 06    LDA #&06
&3375 20 cb ff JSR &ffcb ; non-vectored OSWRCH
&3378 20 52 2e JSR &2e52 ; reset_screen_and_text
&337b 20 ed 26 JSR &26ed ; calculate_score
&337e 4c 85 37 JMP &3785 ; options_screen

; see_position_screen
&3381 20 52 2e JSR &2e52 ; reset_screen_and_text
&3384 20 80 2f JSR &2f80 ; decrypt_temporary_copy_of_game_state
&3387 ad b9 1a LDA &1ab9 ; objects_x + 0 (player)
&338a 8d 7c 39 STA &397c ; player_x
&338d ad dc 1a LDA &1adc ; objects_y + 0 (player)
&3390 8d 7d 39 STA &397d ; player_y
&3393 ad 4a 1a LDA &1a4a ; player_teleports_remembered
&3396 8d 63 2a STA &2a63 ; player_teleports_remembered_for_see_position_screen
&3399 ad 49 1a LDA &1a49 ; player_next_teleport
&339c 8d 64 2a STA &2a64 ; player_next_teleport_for_see_position_screen
&339f a2 ff    LDX #&ff
&33a1 9a       TXS
&33a2 a2 85    LDX #&85 ; &3785 = options_screen
&33a4 a0 37    LDY #&37
&33a6 20 77 32 JSR &3277 ; set_return_after_error_address
&33a9 20 7e 32 JSR &327e ; set_return_after_escape_address
&33ac 20 80 2f JSR &2f80 ; decrypt_temporary_copy_of_game_state
&33af 20 ea 2e JSR &2eea ; set_all_objects_as_unplotted_and_wipe_screen
; see_position_screen_position_loop
&33b2 ad 7c 39 LDA &397c ; player_x
&33b5 85 18    STA &18 ; screen_centre_x
&33b7 ad 7d 39 LDA &397d ; player_y
&33ba 85 1a    STA &1a ; screen_centre_y
&33bc 20 52 21 JSR &2152 ; plot_screen                              # Plot tiles and tertiary objects
&33bf 20 be 1d JSR &1dbe ; to_consider_promoting_secondary_objects_to_primary_objects
&33c2 20 45 24 JSR &2445 ; update_objects                           # Plot primary objects
; see_position_screen_loop
&33c5 20 69 32 JSR &3269 ; get_keypress                             # Returns carry set if ESCAPE pressed
&33c8 b0 fb    BCS &33c5 ; see_position_screen_loop
&33ca c9 20    CMP #&20 ; " "
&33cc d0 03    BNE &33d1 ; space_not_pressed
&33ce 4c 85 37 JMP &3785 ; options_screen
; space_not_pressed
&33d1 09 20    ORA #&20                                             # Convert to lower case
&33d3 c9 74    CMP #&74 ; "t"
&33d5 d0 ee    BNE &33c5 ; see_position_screen_loop
&33d7 20 80 2f JSR &2f80 ; decrypt_temporary_copy_of_game_state
&33da 20 ea 2e JSR &2eea ; set_all_objects_as_unplotted_and_wipe_screen
&33dd 20 25 2a JSR &2a25 ; use_next_teleport_position               # Move to next teleport position
&33e0 ad b9 1a LDA &1ab9 ; objects_x + 0 (player)
&33e3 8d 7c 39 STA &397c ; player_x
&33e6 ad dc 1a LDA &1adc ; objects_y + 0 (player)
&33e9 8d 7d 39 STA &397d ; player_y
&33ec 4c b2 33 JMP &33b2 ; see_position_screen_position_loop

; score_breakdown_screen
&33ef a2 7a    LDX #&7a ; &377a = options_screen_after_keypress
&33f1 a0 37    LDY #&37
&33f3 20 77 32 JSR &3277 ; set_return_after_error_address
&33f6 a2 85    LDX #&85 ; &3785 = options_screen
&33f8 a0 37    LDY #&37
&33fa 20 7e 32 JSR &327e ; set_return_after_escape_address
&33fd 20 52 2e JSR &2e52 ; reset_screen_and_text
&3400 20 68 38 JSR &3868 ; plot_title_bar
&3403 a9 1c    LDA #&1c
&3405 20 c7 31 JSR &31c7 ; set_text_y
&3408 a9 0f    LDA #&0f
&340a 20 a9 31 JSR &31a9 ; set_text_x
&340d a2 8d    LDX #&8d ; &348d = score_breakdown_string
&340f a0 34    LDY #&34
&3411 20 fa 32 JSR &32fa ; write_string_at_XY                       # Plot "Score Breakdown:"
&3414 a9 32    LDA #&32
&3416 8d e5 36 STA &36e5 ; score_y
&3419 a9 00    LDA #&00
&341b 8d e6 36 STA &36e6 ; score_offset
; plot_scores_loop                                                  # For each score element,
&341e ad e5 36 LDA &36e5 ; score_y
&3421 20 c7 31 JSR &31c7 ; set_text_y
&3424 ad e6 36 LDA &36e6 ; score_offset
&3427 0a       ASL A
&3428 a8       TAY
&3429 b9 a0 34 LDA &34a0,Y ; score_string_addresses_table
&342c 48       PHA ; string_address_low
&342d aa       TAX
&342e b9 a1 34 LDA &34a1,Y ; score_string_addresses_table + 1
&3431 48       PHA ; string_address_high
&3432 a8       TAY
&3433 20 0b 33 JSR &330b ; move_to_right_of_string_at_XY            # Get width of string
&3436 a9 ce    LDA #&ce
&3438 e5 82    SBC &82 ; text_x_fraction
&343a 85 82    STA &82 ; text_x_fraction
&343c a9 83    LDA #&83
&343e e5 83    SBC &83 ; text_x
&3440 85 83    STA &83 ; text_x
&3442 68       PLA ; string_address_high
&3443 a8       TAY
&3444 68       PLA ; string_address_low
&3445 aa       TAX
&3446 20 fa 32 JSR &32fa ; write_string_at_XY                       # Plot score description, right aligned
&3449 a9 00    LDA #&00
&344b 85 82    STA &82 ; text_x_fraction
&344d 85 83    STA &83 ; text_x
&344f ad e6 36 LDA &36e6 ; score_offset
&3452 0a       ASL A
&3453 0a       ASL A
&3454 aa       TAX
&3455 a0 fc    LDY #&fc ; -4
; copy_score_element_into_number_loop
&3457 bd c8 26 LDA &26c8,X ; score_elements
&345a 99 62 ff STA &ff62,Y ; number - &fc
&345d e8       INX
&345e c8       INY
&345f d0 f6    BNE &3457 ; copy_score_element_into_number_loop
&3461 20 79 2c JSR &2c79 ; convert_score_to_string
&3464 a9 c8    LDA #&c8
&3466 e5 82    SBC &82 ; text_x_fraction
&3468 85 82    STA &82 ; text_x_fraction
&346a a9 86    LDA #&86
&346c e5 83    SBC &83 ; text_x
&346e 85 83    STA &83 ; text_x
&3470 a2 b9    LDX #&b9 ; &2cb9 = score_value_string
&3472 a0 2c    LDY #&2c
&3474 20 fa 32 JSR &32fa ; write_string_at_XY                       # Plot score value, right aligned
&3477 ad e5 36 LDA &36e5 ; score_y
&347a 18       CLC
&347b 69 0c    ADC #&0c                                             # Move down 12 pixels
&347d 8d e5 36 STA &36e5 ; score_y
&3480 ee e6 36 INC &36e6 ; score_offset
&3483 ad e6 36 LDA &36e6 ; score_offset
&3486 c9 06    CMP #&06
&3488 d0 94    BNE &341e ; plot_scores_loop
&348a 4c 7a 37 JMP &377a ; options_screen_after_keypress

; score_breakdown_string
&348d 11 61                                           ; Set palette to &61 (rgC); cyan text, red shadow
&348f 53 63 6f 72 65 20 42 72 65 61 6b 64 6f 77 6e 3a ; "Score Breakdown:"
&349f 00

; score_string_addresses_table
&34a0 ac 34 ; &34ac = kills_plus_string
&34a2 b7 34 ; &34b7 = kills_minus_string
&34a4 c2 34 ; &34c2 = bonuses_plus_string
&34a6 cf 34 ; &34cf = time_minus_string
&34a8 d9 34 ; &34d9 = deaths_minus_string
&34aa e3 34 ; &34e3 = total_string

; kills_plus_string
&34ac 11 31                                           ; Set palette to &31 (rgY), yellow text, red shadow
&34ae 4b 69 6c 6c 73 20 20 2b                         ; "Kills  +"
&34b6 00

; kills_minus_string
&34b7 11 1c                                           ; Set palette to &1c (ywR), red text, yellow shadow
&34b9 4b 69 6c 6c 73 20 20 2d                         ; "Kills  -"
&34c1 00

; bonuses_plus_string
&34c2 11 31                                           ; Set palette to &31 (rgY), yellow text, red shadow
&34c4 42 6f 6e 75 73 65 73 20 20 2b                   ; "Bonuses  +"
&34ce 00

; time_minus_string
&34cf 11 1c                                           ; Set palette to &1c (ywR), red text, yellow shadow
&34d1 54 69 6d 65 20 20 2d                            ; "Time  -"
&34d8 00

; deaths_minus_string
&34d9 44 65 61 74 68 73 20 20 2d                      ; "Deaths  -"
&34e2 00

; total_string
&34e3 0a
&34e4 11 77                                           ; Set palette to &77 (gmW), white text, green shadow
&34e6 54 6f 74 61 6c 20 20 20 20 20 20                ; "Total      "
&34f1 00

; status_screen
&34f2 a2 85    LDX #&85 ; &3785 = options_screen
&34f4 a0 37    LDY #&37
&34f6 20 77 32 JSR &3277 ; set_return_after_error_address
&34f9 20 7e 32 JSR &327e ; set_return_after_escape_address
&34fc 20 80 2f JSR &2f80 ; decrypt_temporary_copy_of_game_state
&34ff 20 52 2e JSR &2e52 ; reset_screen_and_text
&3502 20 68 38 JSR &3868 ; plot_title_bar
&3505 20 a1 2b JSR &2ba1 ; plot_game_time
&3508 20 3d 2c JSR &2c3d ; plot_score
&350b 20 3c 2d JSR &2d3c ; plot_competition_code
&350e a9 04    LDA #&04
&3510 20 a9 31 JSR &31a9 ; set_text_x
&3513 a9 48    LDA #&48
&3515 20 c7 31 JSR &31c7 ; set_text_y
&3518 a2 97    LDX #&97 ; &3697 = fuel_string
&351a a0 36    LDY #&36
&351c 20 fa 32 JSR &32fa ; write_string_at_XY                       # Plot "Fuel"
&351f a9 1a    LDA #&1a
&3521 20 a9 31 JSR &31a9 ; set_text_x
&3524 a9 45    LDA #&45
&3526 8d e5 36 STA &36e5 ; weapon_y
&3529 20 c7 31 JSR &31c7 ; set_text_y
&352c a9 21    LDA #&21 ; rgG                                       # Green bar, red border
&352e 8d e7 36 STA &36e7 ; energy_bar_palette
&3531 ad 7c 1a LDA &1a7c ; player_weapons_energy_high
&3534 20 eb 36 JSR &36eb ; plot_energy_bar                          # Plot energy bar for jetpack
&3537 a9 00    LDA #&00
&3539 8d e6 36 STA &36e6 ; weapon_offset
; plot_weapons_loop                                                 # For each weapon,
&353c ad e5 36 LDA &36e5 ; weapon_y
&353f 18       CLC
&3540 69 0f    ADC #&0f                                             # Move down 15 pixels
&3542 8d e5 36 STA &36e5 ; weapon_y
&3545 ee e6 36 INC &36e6 ; weapon_offset
&3548 ae e6 36 LDX &36e6 ; weapon_offset
&354b e0 06    CPX #&06
&354d f0 6a    BEQ &35b9 ; finished_plotting_weapons
&354f bd 36 1a LDA &1a36,X ; player_weapons_collected               # Negative if weapon has been collected
&3552 08       PHP ; weapon collected
&3553 a9 00    LDA #&00
&3555 28       PLP ; weapon collected
&3556 10 4e    BPL &35a6 ; skip_plotting_weapon
&3558 8a       TXA
&3559 18       CLC
&355a 69 59    ADC #&59 ; OBJECT_JETPACK_BOOSTER
&355c aa       TAX
&355d bd 65 15 LDA &1565,X ; object_types_palette_and_pickup_table
&3560 29 7f    AND #&7f
&3562 85 5a    STA &5a ; this_object_palette
&3564 bd 00 15 LDA &1500,X ; object_types_sprite_table
&3567 48       PHA ; weapon sprite
&3568 a8       TAY
&3569 b9 ee 54 LDA &54ee,Y ; sprites_height_and_vertical_flip_table
&356c 4a       LSR A
&356d 4a       LSR A
&356e 4a       LSR A
&356f 4a       LSR A
&3570 49 ff    EOR #&ff
&3572 69 04    ADC #&04                                             # Centre weapon sprite vertically
&3574 6d e5 36 ADC &36e5 ; weapon_y
&3577 20 c7 31 JSR &31c7 ; set_text_y
&357a a9 11    LDA #&11
&357c 20 a9 31 JSR &31a9 ; set_text_x
&357f ad e6 36 LDA &36e6 ; weapon_offset
&3582 c9 05    CMP #&05
&3584 d0 05    BNE &358b ; not_protection_suit
&3586 a9 09    LDA #&09                                             # Offset protection suit
&3588 20 a9 31 JSR &31a9 ; set_text_x
; not_protection_suit
&358b 68       PLA ; weapon sprite
&358c 20 de 30 JSR &30de ; plot_sprite_at_text_position             # Plot sprite for weapon
&358f a9 1a    LDA #&1a
&3591 20 a9 31 JSR &31a9 ; set_text_x
&3594 ad e5 36 LDA &36e5 ; weapon_y
&3597 20 c7 31 JSR &31c7 ; set_text_y
&359a ae e6 36 LDX &36e6 ; weapon_offset
&359d bd df 36 LDA &36df,X ; weapons_energy_bar_palette_table
&35a0 8d e7 36 STA &36e7 ; energy_bar_palette
&35a3 bd 7c 1a LDA &1a7c,X ; player_weapons_energy_high
; skip_plotting_weapon
&35a6 48       PHA ; weapon energy
&35a7 a9 1a    LDA #&1a
&35a9 20 a9 31 JSR &31a9 ; set_text_x
&35ac ad e5 36 LDA &36e5 ; weapon_y
&35af 20 c7 31 JSR &31c7 ; set_text_y
&35b2 68       PLA ; weapon energy
&35b3 20 eb 36 JSR &36eb ; plot_energy_bar                          # Plot energy bar for weapon
&35b6 4c 3c 35 JMP &353c ; plot_weapons_loop
; finished_plotting_weapons
&35b9 a9 4e    LDA #&4e
&35bb 20 a9 31 JSR &31a9 ; set_text_x
&35be a9 49    LDA #&49
&35c0 20 c7 31 JSR &31c7 ; set_text_y
&35c3 a2 9e    LDX #&9e ; &369e = pockets_string
&35c5 a0 36    LDY #&36
&35c7 20 fa 32 JSR &32fa ; write_string_at_XY                       # Plot "Pockets"
&35ca a9 49    LDA #&49
&35cc 20 a9 31 JSR &31a9 ; set_text_x
&35cf a9 54    LDA #&54
&35d1 20 c7 31 JSR &31c7 ; set_text_y
&35d4 a2 be    LDX #&be ; &36be = pocket_bar_string
&35d6 a0 36    LDY #&36
&35d8 20 fa 32 JSR &32fa ; write_string_at_XY                       # Plot pocket bar
&35db a9 51    LDA #&51
&35dd 8d de 36 STA &36de ; pocket_x
; plot_pockets_loop                                                 # For each pocket,
&35e0 ae 6f 1a LDX &1a6f ; player_pockets_used
&35e3 f0 52    BEQ &3637 ; finished_plotting_pockets
&35e5 bd 6f 1a LDA &1a6f,X ; player_pockets - 1
&35e8 aa       TAX
&35e9 bd 65 15 LDA &1565,X ; object_types_palette_and_pickup_table
&35ec 29 7f    AND #&7f
&35ee 85 5a    STA &5a ; this_object_palette
&35f0 bd 00 15 LDA &1500,X ; object_types_sprite_table
&35f3 48       PHA ; pocket sprite
&35f4 a8       TAY
&35f5 ad de 36 LDA &36de ; pocket_x
&35f8 20 a9 31 JSR &31a9 ; set_text_x
&35fb b9 00 54 LDA &5400,Y ; sprites_width_and_horizontal_flip_table
&35fe 4a       LSR A
&35ff 69 08    ADC #&08
&3601 85 0b    STA &0b ; x_offset
&3603 a5 82    LDA &82 ; text_x_fraction
&3605 e5 0b    SBC &0b ; x_offset
&3607 85 82    STA &82 ; text_x_fraction
&3609 b0 02    BCS &360d ; skip_underflow_x
&360b c6 83    DEC &83 ; text_x
; skip_underflow_x
&360d a9 5b    LDA #&5b
&360f 20 c7 31 JSR &31c7 ; set_text_y
&3612 b9 ee 54 LDA &54ee,Y ; sprites_height_and_vertical_flip_table
&3615 4a       LSR A
&3616 69 04    ADC #&04
&3618 85 0b    STA &0b ; y_offset
&361a a5 84    LDA &84 ; text_y_fraction
&361c e5 0b    SBC &0b ; y_offset
&361e 85 84    STA &84 ; text_y_fraction
&3620 b0 02    BCS &3624 ; skip_underflow_y
&3622 c6 85    DEC &85 ; text_y
; skip_underflow_y
&3624 68       PLA ; pocket sprite
&3625 20 de 30 JSR &30de ; plot_sprite_at_text_position             # Plot content of pocket
&3628 18       CLC
&3629 ad de 36 LDA &36de ; pocket_x
&362c 69 0b    ADC #&0b                                             # Move right 11 pixels
&362e 8d de 36 STA &36de ; pocket_x
&3631 ce 6f 1a DEC &1a6f ; player_pockets_used
&3634 4c e0 35 JMP &35e0 ; plot_pockets_loop
; finished_plotting_pockets
&3637 a9 55    LDA #&55
&3639 20 a9 31 JSR &31a9 ; set_text_x
&363c a9 76    LDA #&76
&363e 20 c7 31 JSR &31c7 ; set_text_y
&3641 a2 a8    LDX #&a8 ; &36a8 = keys_string
&3643 a0 36    LDY #&36
&3645 20 fa 32 JSR &32fa ; write_string_at_XY                       # Plot "Keys"
&3648 a9 49    LDA #&49
&364a 20 a9 31 JSR &31a9 ; set_text_x
&364d a9 81    LDA #&81
&364f 20 c7 31 JSR &31c7 ; set_text_y
&3652 a2 af    LDX #&af ; &36af = key_bar_string
&3654 a0 36    LDY #&36
&3656 20 fa 32 JSR &32fa ; write_string_at_XY                       # Plot key bar
&3659 a9 4d    LDA #&4d
&365b 20 a9 31 JSR &31a9 ; set_text_x
&365e a9 84    LDA #&84
&3660 20 c7 31 JSR &31c7 ; set_text_y
&3663 a9 ff    LDA #&ff
&3665 8d 96 36 STA &3696 ; key_offset
; plot_keys_loop                                                    # For each key,
&3668 ee 96 36 INC &3696 ; key_offset
&366b ae 96 36 LDX &3696 ; key_offset
&366e e0 08    CPX #&08
&3670 f0 21    BEQ &3693 ; to_options_screen_after_keypress
&3672 bd 2e 1a LDA &1a2e,X ; player_keys_collected                  # Negative if key has been collected
&3675 10 f1    BPL &3668 ; plot_keys_loop
&3677 bd b6 15 LDA &15b6,X ; object_types_palette_and_pickup_table + &51 (OBJECT_FIRST_KEY)
&367a 29 7f    AND #&7f
&367c 85 5a    STA &5a ; this_object_palette
&367e a9 4d    LDA #&4d ; SPRITE_KEY
&3680 20 de 30 JSR &30de ; plot_sprite_at_text_position             # Plot key
&3683 18       CLC
&3684 a5 82    LDA &82 ; text_x_fraction
&3686 69 10    ADC #&10                                             # Move right 16 pixels
&3688 85 82    STA &82 ; text_x_fraction
&368a a5 83    LDA &83 ; text_x
&368c 69 00    ADC #&00
&368e 85 83    STA &83 ; text_x
&3690 4c 68 36 JMP &3668 ; plot_keys_loop
; to_options_screen_after_keypress
&3693 4c 7a 37 JMP &377a ; options_screen_after_keypress

; key_offset
&3696 00

; fuel_string
&3697 11 6a                                           ; Set palette to &6a (BBC), cyan text, blue shadow
&3699 46 75 65 6c                                     ; "Fuel"
&369d 00

; pockets_string
&369e 11 5a                                           ; Set palette to &5a (BBM), magenta text, blue shadow
&36a0 50 6f 63 6b 65 74 73                            ; "Pockets"
&36a7 00

; keys_string
&36a8 11 5a                                           ; Set palette to &5a (BBM), magenta text, blue shadow
&36aa 4b 65 79 73                                     ; "Keys"
&36ae 00

; key_bar_string
&36af 11 31                                           ; Set palette to &31 (rgY)
&36b1 84                                              ; CHARACTER_ENERGY_BAR_LEFT
&36b2 11 01                                           ; Set palette to &01 (rgK)
&36b4 89                                              ; CHARACTER_ENERGY_BAR_EIGHT
&36b5 89                                              ; CHARACTER_ENERGY_BAR_EIGHT
&36b6 89                                              ; CHARACTER_ENERGY_BAR_EIGHT
&36b7 89                                              ; CHARACTER_ENERGY_BAR_EIGHT
&36b8 89                                              ; CHARACTER_ENERGY_BAR_EIGHT
&36b9 87                                              ; CHARACTER_ENERGY_BAR_TWO
&36ba 11 31                                           ; Set palette to &31 (rgY)
&36bc 85                                              ; CHARACTER_ENERGY_BAR_RIGHT
&36bd 00

; pocket_bar_string
&36be 11 31                                           ; Set palette to &31 (rgY)
&36c0 84                                              ; CHARACTER_ENERGY_BAR_LEFT
&36c1 11 01                                           ; Set palette to &01 (rgK)
&36c3 89                                              ; CHARACTER_ENERGY_BAR_EIGHT
&36c4 86                                              ; CHARACTER_ENERGY_BAR_ONE
&36c5 11 11                                           ; Set palette to &11 (rgR)
&36c7 87                                              ; CHARACTER_ENERGY_BAR_TWO
&36c8 11 01                                           ; Set palette to &01 (rgK)
&36ca 89                                              ; CHARACTER_ENERGY_BAR_EIGHT
&36cb 86                                              ; CHARACTER_ENERGY_BAR_ONE
&36cc 11 11                                           ; Set palette to &11 (rgR)
&36ce 87                                              ; CHARACTER_ENERGY_BAR_TWO
&36cf 11 01                                           ; Set palette to &01 (rgK)
&36d1 89                                              ; CHARACTER_ENERGY_BAR_EIGHT
&36d2 86                                              ; CHARACTER_ENERGY_BAR_ONE
&36d3 11 11                                           ; Set palette to &11 (rgR)
&36d5 87                                              ; CHARACTER_ENERGY_BAR_TWO
&36d6 11 01                                           ; Set palette to &01 (rgK)
&36d8 89                                              ; CHARACTER_ENERGY_BAR_EIGHT
&36d9 86                                              ; CHARACTER_ENERGY_BAR_ONE
&36da 11 31                                           ; Set palette to &31 (rgY)
&36dc 85                                              ; CHARACTER_ENERGY_BAR_RIGHT
&36dd 00

; pocket_x
&36de 00

; weapons_energy_bar_palette_table
&36df 21 ; &00 (jetpack)         : rgG                              # Green bar
&36e0 51 ; &01 (pistol)          : rgM                              # Magenta bar
&36e1 61 ; &02 (icer)            : rgC                              # Cyan bar
&36e2 31 ; &03 (blaster)         : rgY                              # Yellow bar
&36e3 11 ; &04 (plasma gun)      : rgR                              # Red bar
&36e4 71 ; &05 (protection suit) : rgW                              # White bar

; score_y
; weapon_y
&36e5 00

; score_offset
; weapon_offset
&36e6 00

; energy_bar_palette
&36e7 00

; energy_to_plot
&36e8 00

; empty_energy_to_plot
&36e9 00

; energy_remaining_to_plot
&36ea 00

; plot_energy_bar                                                    # Called with A = amount of energy in slot
&36eb c9 00    CMP #&00
&36ed 10 02    BPL &36f1 ; skip_ceiling
&36ef a9 7f    LDA #&7f
; skip_ceiling
&36f1 4a       LSR A
&36f2 4a       LSR A
&36f3 8d e8 36 STA &36e8 ; energy_to_plot
&36f6 49 1f    EOR #&1f
&36f8 8d e9 36 STA &36e9 ; empty_energy_to_plot
&36fb a9 31    LDA #&31 ; rgY
&36fd 85 86    STA &86 ; text_palette
&36ff a9 84    LDA #&84 ; CHARACTER_ENERGY_BAR_LEFT
&3701 20 ee ff JSR &ffee ; OSWRCH                                   # Plot left of energy bar
&3704 a9 01    LDA #&01 ; rgK
&3706 85 86    STA &86 ; text_palette
&3708 a9 86    LDA #&86 ; CHARACTER_ENERGY_BAR_ONE
&370a 20 ee ff JSR &ffee ; OSWRCH                                   # Plot spacer
&370d ad e7 36 LDA &36e7 ; energy_bar_palette
&3710 85 86    STA &86 ; text_palette
&3712 ad e8 36 LDA &36e8 ; energy_to_plot
&3715 20 2b 37 JSR &372b ; plot_energy_bar_middle                   # Plot energy
&3718 a9 01    LDA #&01 ; rgK
&371a 85 86    STA &86 ; text_palette
&371c ad e9 36 LDA &36e9 ; empty_energy_to_plot
&371f 20 2b 37 JSR &372b ; plot_energy_bar_middle                   # Plot empty energy
&3722 a9 31    LDA #&31 ; rgY
&3724 85 86    STA &86 ; text_palette
&3726 a9 85    LDA #&85 ; CHARACTER_ENERGY_BAR_RIGHT
&3728 4c ee ff JMP &ffee ; OSWRCH                                   # Plot right of energy bar

; plot_energy_bar_middle
&372b 8d ea 36 STA &36ea ; energy_remaining_to_plot
; plot_energy_bar_middle_loop
&372e ad ea 36 LDA &36ea ; energy_remaining_to_plot
&3731 f0 45    BEQ &3778 ; leave
&3733 c9 08    CMP #&08
&3735 90 10    BCC &3747 ; less_than_eight_remaining_to_plot
; plot_eight
&3737 ad ea 36 LDA &36ea ; energy_remaining_to_plot
&373a e9 08    SBC #&08
&373c 8d ea 36 STA &36ea ; energy_remaining_to_plot
&373f a9 89    LDA #&89 ; CHARACTER_ENERGY_BAR_EIGHT
&3741 20 ee ff JSR &ffee ; OSWRCH
&3744 4c 2e 37 JMP &372e ; plot_energy_bar_middle_loop
; less_than_eight_remaining_to_plot
&3747 c9 04    CMP #&04
&3749 90 10    BCC &375b ; less_than_four_remaining_to_plot
; plot_four
&374b ad ea 36 LDA &36ea ; energy_remaining_to_plot
&374e e9 04    SBC #&04
&3750 8d ea 36 STA &36ea ; energy_remaining_to_plot
&3753 a9 88    LDA #&88 ; CHARACTER_ENERGY_BAR_FOUR
&3755 20 ee ff JSR &ffee ; OSWRCH
&3758 4c 2e 37 JMP &372e ; plot_energy_bar_middle_loop
; less_than_four_remaining_to_plot
&375b c9 02    CMP #&02
&375d 90 0e    BCC &376d ; plot_one
; plot_two
&375f ce ea 36 DEC &36ea ; energy_remaining_to_plot
&3762 ce ea 36 DEC &36ea ; energy_remaining_to_plot
&3765 a9 87    LDA #&87 ; CHARACTER_ENERGY_BAR_TWO
&3767 20 ee ff JSR &ffee ; OSWRCH
&376a 4c 2e 37 JMP &372e ; plot_energy_bar_middle_loop
; plot_one
&376d ce ea 36 DEC &36ea ; energy_remaining_to_plot
&3770 a9 86    LDA #&86 ; CHARACTER_ENERGY_BAR_ONE
&3772 20 ee ff JSR &ffee ; OSWRCH
&3775 4c 2e 37 JMP &372e ; plot_energy_bar_middle_loop
; leave
&3778 60       RTS

; number_of_options
&3779 00

; options_screen_after_keypress
&377a 20 69 32 JSR &3269 ; get_keypress
&377d c9 0d    CMP #&0d ; CR
&377f f0 04    BEQ &3785 ; options_screen
&3781 c9 20    CMP #&20 ; " "
&3783 d0 f5    BNE &377a ; options_screen_after_keypress            # Wait for RETURN or SPACE to be pressed
; options_screen
&3785 a2 ff    LDX #&ff
&3787 9a       TXS
&3788 a2 85    LDX #&85 ; &3785 = options_screen
&378a a0 37    LDY #&37
&378c 20 77 32 JSR &3277 ; set_return_after_error_address
&378f 20 7e 32 JSR &327e ; set_return_after_escape_address
&3792 a9 04    LDA #&04 ; Define action of cursor editing keys
&3794 a2 01    LDX #&01 ; Cursor keys return ASCII values 135-139
&3796 a0 00    LDY #&00
&3798 20 f4 ff JSR &fff4 ; OSBYTE
&379b a9 e1    LDA #&e1 ; Read/Write Interpretation of F-Keys
&379d a2 30    LDX #&30 ; add "0" as base value
&379f a0 00    LDY #&00
&37a1 20 f4 ff JSR &fff4 ; OSBYTE
&37a4 a9 e2    LDA #&e2 ; Read/Write Interpretation of Shift-F-Keys
&37a6 a2 00    LDX #&00 ; ignore
&37a8 a0 00    LDY #&00
&37aa 20 f4 ff JSR &fff4 ; OSBYTE
&37ad a9 e3    LDA #&e3 ; Read/Write Interpretation of Ctrl-F-Keys
&37af a2 00    LDX #&00 ; ignore
&37b1 a0 00    LDY #&00
&37b3 20 f4 ff JSR &fff4 ; OSBYTE
&37b6 a9 e4    LDA #&e4 ; Read/Write Interpretation of Ctrl-Shift-F-keys
&37b8 a2 00    LDX #&00 ; ignore
&37ba a0 00    LDY #&00
&37bc 20 f4 ff JSR &fff4 ; OSBYTE
&37bf 20 52 2e JSR &2e52 ; reset_screen_and_text
&37c2 20 68 38 JSR &3868 ; plot_title_bar
&37c5 a9 1e    LDA #&1e
&37c7 20 c7 31 JSR &31c7 ; set_text_y
&37ca a9 00    LDA #&00
&37cc 8d 79 37 STA &3779 ; number_of_options
; plot_options_loop                                                 # For each option in the list,
&37cf a2 ad    LDX #&ad ; &38ad = option_start_string
&37d1 a0 38    LDY #&38
&37d3 20 fa 32 JSR &32fa ; write_string_at_XY                       # Plot leading "F"
&37d6 ad 79 37 LDA &3779 ; number_of_options
&37d9 18       CLC
&37da 69 30    ADC #&30 ; "0"
&37dc 20 ee ff JSR &ffee ; OSWRCH                                   # Plot option number
&37df a9 26    LDA #&26
&37e1 20 a9 31 JSR &31a9 ; set_text_x
&37e4 ad 79 37 LDA &3779 ; number_of_options
&37e7 0a       ASL A
&37e8 0a       ASL A
&37e9 aa       TAX
&37ea bd be 38 LDA &38be,X ; options_routine_and_string_addresses + 3
&37ed a8       TAY
&37ee bd bd 38 LDA &38bd,X ; options_routine_and_string_addresses + 2
&37f1 aa       TAX
&37f2 20 fa 32 JSR &32fa ; write_string_at_XY                       # Plot option text
&37f5 a9 0d    LDA #&0d ; CR
&37f7 20 ee ff JSR &ffee ; OSWRCH
&37fa a9 0a    LDA #&0a ; LF
&37fc 20 ee ff JSR &ffee ; OSWRCH                                   # Move down a line
&37ff ee 79 37 INC &3779 ; number_of_options
&3802 ad 79 37 LDA &3779 ; number_of_options
&3805 0a       ASL A
&3806 0a       ASL A
&3807 aa       TAX
&3808 bd bc 38 LDA &38bc,X ; options_routine_and_string_addresses   # Negative indicates end of list
&380b 10 c2    BPL &37cf ; plot_options_loop                        # Continue until end of options list
&380d a2 41    LDX #&41 ; &3941 = newline_string
&380f a0 39    LDY #&39
&3811 20 fa 32 JSR &32fa ; write_string_at_XY
&3814 ad 1f 33 LDA &331f ; position_state                           # Zero if POSITION_STATE_DEFAULT
&3817 d0 0a    BNE &3823 ; not_default_position
; is_default_position
&3819 a2 44    LDX #&44 ; &3944 = default_string
&381b a0 39    LDY #&39
&381d 20 fa 32 JSR &32fa ; write_string_at_XY                       # Write "Default" if default position
&3820 4c 4d 38 JMP &384d ; options_screen_loop
; not_default_position
&3823 c9 01    CMP #&01 ; POSITION_STATE_UNSAVED
&3825 d0 0a    BNE &3831 ; not_unsaved
; is_unsaved
&3827 a2 4e    LDX #&4e ; &394e = unsaved_string
&3829 a0 39    LDY #&39
&382b 20 fa 32 JSR &32fa ; write_string_at_XY                       # or "Unsaved" if position hasn't been saved
&382e 4c 4d 38 JMP &384d ; options_screen_loop
; not_unsaved
&3831 c9 02    CMP #&02 ; POSITION_STATE_LOADED
&3833 d0 0a    BNE &383f ; is_state_two
; is_recently_loaded
&3835 a2 58    LDX #&58 ; &3958 = recently_loaded_file_string
&3837 a0 39    LDY #&39
&3839 20 fa 32 JSR &32fa ; write_string_at_XY                       # or "File :"" if position was recently loaded
&383c 4c 46 38 JMP &3846 ; write_current_filename
; is_recently_saved                                                 # &03 if POSITION_STATE_SAVED
&383f a2 62    LDX #&62 ; &3962 = recently_saved_file_string
&3841 a0 39    LDY #&39
&3843 20 fa 32 JSR &32fa ; write_string_at_XY                       # or "File :"" if position was recently saved
; write_current_filename
&3846 a2 6c    LDX #&6c ; &396c = current_filename
&3848 a0 39    LDY #&39
&384a 20 fa 32 JSR &32fa ; write_string_at_XY
; options_screen_loop
&384d 20 69 32 JSR &3269 ; get_keypress
&3850 38       SEC
&3851 e9 30    SBC #&30 ; "0"
&3853 cd 79 37 CMP &3779 ; number_of_options
&3856 b0 f5    BCS &384d ; options_screen_loop
&3858 0a       ASL A
&3859 0a       ASL A
&385a aa       TAX
&385b bd bb 38 LDA &38bb,X ; options_routine_and_string_addresses
&385e 85 1b    STA &1b ; option_routine_address_low
&3860 bd bc 38 LDA &38bc,X ; options_routine_and_string_addresses + 1
&3863 85 1c    STA &1c ; option_routine_address_high
&3865 6c 1b 00 JMP (&001b) ; option_routine_address

; plot_title_bar
&3868 a9 06    LDA #&06
&386a 20 a9 31 JSR &31a9 ; set_text_x
&386d a9 07    LDA #&07
&386f 20 c7 31 JSR &31c7 ; set_text_y
&3872 a2 91    LDX #&91 ; &3891 = title_bar_left_string
&3874 a0 38    LDY #&38
&3876 20 fa 32 JSR &32fa ; write_string_at_XY
&3879 a9 00    LDA #&00
&387b 20 c7 31 JSR &31c7 ; set_text_y
&387e a2 9c    LDX #&9c ; &389c = title_bar_middle_string
&3880 a0 38    LDY #&38
&3882 20 fa 32 JSR &32fa ; write_string_at_XY
&3885 a9 07    LDA #&07
&3887 20 c7 31 JSR &31c7 ; set_text_y
&388a a2 a1    LDX #&a1 ; &38a1 = title_bar_right_string
&388c a0 38    LDY #&38
&388e 4c fa 32 JMP &32fa ; write_string_at_XY

; title_bar_left_string
&3891 11 53                                           ; Set palette to &53 (rcM)
&3893 8b                                              ; CHARACTER_TITLE_BAR_LEFT_LEFT
&3894 11 1e                                           ; Set palette to &1e (mwR)
&3896 8a                                              ; CHARACTER_TITLE_BAR_MIDDLE
&3897 8a                                              ; CHARACTER_TITLE_BAR_MIDDLE
&3898 8a                                              ; CHARACTER_TITLE_BAR_MIDDLE
&3899 8a                                              ; CHARACTER_TITLE_BAR_MIDDLE
&389a 8c                                              ; CHARACTER_TITLE_BAR_LEFT_RIGHT
&389b 00

; title_bar_middle_string
&389c 11 33                                           ; Set palette to &33 (rcY)
&389e 8f                                              ; CHARACTER_LOGO_LEFT
&389f 90                                              ; CHARACTER_LOGO_RIGHT
&38a0 00

; title_bar_right_string
&38a1 11 1e                                           ; Set palette to &1e (mwR)
&38a3 8d                                              ; CHARACTER_TITLE_BAR_RIGHT_LEFT
&38a4 8a                                              ; CHARACTER_TITLE_BAR_MIDDLE
&38a5 8a                                              ; CHARACTER_TITLE_BAR_MIDDLE
&38a6 8a                                              ; CHARACTER_TITLE_BAR_MIDDLE
&38a7 8a                                              ; CHARACTER_TITLE_BAR_MIDDLE
&38a8 11 53                                           ; Set palette to &53 (rcM)
&38aa 8e                                              ; CHARACTER_TITLE_BAR_RIGHT_RIGHT
&38ab 0d
&38ac 00

; option_start_string
&38ad 11 31                                           ; Set palette to &31 (rgY), yellow text, red shadow
&38af 20 20 20 20 20 20 20 20 20 20 46                ; "          F"
&38ba 00

; options_routine_and_string_addresses
&38bb 7e 39 dd 38 ; &397e = run_game_screen         &38dd = run_game_string
&38bf f2 34 e6 38 ; &34f2 = status_screen           &38e6 = status_string
&38c3 81 33 2a 39 ; &3381 = see_position_screen     &392a = see_position_string
&38c7 02 2a 37 39 ; &2a02 = catalogue_screen        &3937 = catalogue_string
&38cb 8f 2a fd 38 ; &2a8f = load_position_screen    &38fd = load_position_string
&38cf 65 2a 0b 39 ; &2a65 = save_position_screen    &390b = save_position_string
&38d3 ef 33 ed 38 ; &33ef = score_breakdown_screen  &38ed = score_breakdown_string
&38d7 e1 31 19 39 ; &31e1 = default_position_screen &3919 = default_position_string
&38db ff ff       ; (end of list)

; run_game_string
&38dd 52 75 6e 20 47 61 6d 65                         ; "Run Game"
&38e5 00

; status_string
&38e6 53 74 61 74 75 73                               ; "Status"
&38ec 00

; score_breakdown_string
&38ed 53 63 6f 72 65 20 42 72 65 61 6b 64 6f 77 6e    ; "Score Breakdown"
&38fc 00

; load_position_string
&38fd 4c 6f 61 64 20 70 6f 73 69 74 69 6f 6e          ; "Load position"
&390a 00

; save_position_string
&390b 53 61 76 65 20 70 6f 73 69 74 69 6f 6e          ; "Save position"
&3918 00

; default_position_string
&3919 44 65 66 61 75 6c 74 20 70 6f 73 69 74 69 6f 6e ; "Default position"
&3929 00

; see_position_string
&392a 53 65 65 20 70 6f 73 69 74 69 6f 6e             ; "See position"
&3936 00

; catalogue_string
&3937 43 61 74 61 6c 6f 67 75 65                      ; "Catalogue"
&3940 00

; newline_string
&3941 0d 0a
&3943 00

; default_string
&3944 11 17                                           ; Set palette to &17 (gmR), red text, green shadow
&3946 44 65 66 61 75 6c 74                            ; "Default"
&394d 00

; unsaved_string
&394e 11 6a                                           ; Set palette to &6a (BBC), cyan text, blue shadow
&3950 55 6e 73 61 76 65 64                            ; "Unsaved"
&3957 00

; recently_loaded_file_string
&3958 11 21                                           ; Set palette to &21 (rgG), green text, red shadow
&395a 46 69 6c 65 3a 20 22                            ; "File: ""
&3961 00

; recently_saved_file_string
&3962 11 21                                           ; Set palette to &21 (rgG), green text, red shadow
&3964 46 69 6c 65 3a 20 22                            ; "File: ""
&396b 00 

; current_filename
&396c 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e 2e

; player_x
&397c 9c

; player_y
&397d 3b

; run_game_screen
&397e a9 c8    LDA #&c8 ; Read/Write BREAK/ESCAPE effect
&3980 a2 03    LDX #&03 ; Clear memory on next RESET
&3982 a0 00    LDY #&00
&3984 20 f4 ff JSR &fff4 ; OSBYTE
&3987 20 52 2e JSR &2e52 ; reset_screen_and_text
&398a ad 2b 33 LDA &332b ; previous_osfile_vector_low
&398d 8d 12 02 STA &0212 ; osfile_vector_low
&3990 ad 2c 33 LDA &332c ; previous_osfile_vector_high
&3993 8d 13 02 STA &0213 ; osfile_vector_high
&3996 ad 2d 33 LDA &332d ; previous_file_system_control_vector_low
&3999 8d 1e 02 STA &021e ; file_system_control_vector_low
&399c ad 2e 33 LDA &332e ; previous_file_system_control_vector_high
&399f 8d 1f 02 STA &021f ; file_system_control_vector_high
&39a2 20 81 26 JSR &2681 ; check_for_sideways_ram_after_sei         # Returns carry set if sideways RAM found, X = bank
&39a5 90 1a    BCC &39c1 ; use_standard_version
&39a7 8e 50 3a STX &3a50 ; sideways_ram_bank                        # Unused variable
&39aa a2 26    LDX #&26 ; &3a26 = may_i_use_your_sideways_ram_string
&39ac a0 3a    LDY #&3a
&39ae 20 fa 32 JSR &32fa ; write_string_at_XY
; get_y_or_n
&39b1 20 69 32 JSR &3269 ; get_keypress
&39b4 09 20    ORA #&20                                             # Convert to lowercase
&39b6 c9 79    CMP #&79 ; "y"
&39b8 f0 0e    BEQ &39c8 ; use_enhanced_version
&39ba c9 6e    CMP #&6e ; "n"
&39bc d0 f3    BNE &39b1 ; get_y_or_n
&39be 20 ee ff JSR &ffee ; OSWRCH
; use_standard_version
&39c1 a2 01    LDX #&01 ; &3a01 = run_exileb_command                # Run ExileB for standard version
&39c3 a0 3a    LDY #&3a
&39c5 4c cf 39 JMP &39cf ; run_game
; use_enhanced_version
&39c8 20 ee ff JSR &ffee ; OSWRCH
&39cb a2 f8    LDX #&f8
&39cd a0 39    LDY #&39 ; &39f8 = run_exilesr_command               # Run ExileSR for enhanced version
; run_game
&39cf 8a       TXA
&39d0 48       PHA ; command_addess_low
&39d1 98       TYA
&39d2 48       PHA ; command_address_high
&39d3 a9 16    LDA #&16                                             # Change to MODE 7
&39d5 20 cb ff JSR &ffcb ; non-vectored OSWRCH
&39d8 a9 07    LDA #&07
&39da 20 cb ff JSR &ffcb ; non-vectored OSWRCH
&39dd a9 cb    LDA #&cb ; &ffcb = non-vectored OSWRCH
&39df 8d 0e 02 STA &020e ; oswrch_vector_low                        # Remove OSWRCH handler
&39e2 a9 ff    LDA #&ff
&39e4 8d 0f 02 STA &020f ; oswrch_vector_high
&39e7 a9 01    LDA #&01 ;  R1: Number of characters per line
&39e9 8d 00 fe STA &fe00 ; video register number
&39ec a9 00    LDA #&00                                             # Hide screen
&39ee 8d 01 fe STA &fe01 ; video register value
&39f1 68       PLA ; command_address_high
&39f2 a8       TAY
&39f3 68       PLA ; command_addess_low
&39f4 aa       TAX
&39f5 4c f7 ff JMP &fff7 ; OSCLI                                    # Run game

; run_exilesr_command
&39f8 2f 45 78 69 6c 65 53 52 0d                      ; "/ExileSR"

; run_exileb_command
&3a01 2f 45 78 69 6c 65 42 0d                         ; "/ExileB"

; cat_command                                                       # Drive number is modified
&3a09 43 41 54 20 30 0d                               ; "CAT 0"

; disc_command
&3a0f 44 49 53 43 0d                                  ; "DISC"

; tape_command
&3a14 54 41 50 45 0d                                  ; "TAPE"

; unused
&3a19 00 48 2b 00 00 00 00 00 00 00 00 00 00

; may_i_use_your_sideways_ram_string
&3a26 11 31                                           ; Set palette to &31 (rgY), yellow text, red shadow
&3a28 4d 61 79 20 49 20 75 73 65 20 79 6f 75 72 20 53 ; "May I use your Sideways";
&3a38 69 64 65 77 61 79 73
&3a3f 0d 0a 0a
&3a42 52 61 6d 20 3f 20 28 79 2f 6e 29                ; "Ram ? (y/n)"
&3a4d 11 75                                           ; Set palette to &75 (gyW), white text, green shadow
&3a4f 00

; sideways_ram_bank
&3a50 00

; update_routines_base

# &3a51 - &3b50 is similar to code used in game. Differences are indicated by ***

; update_nest_or_pipe_tile                                          # Called with Y = this_object_tertiary_data_offset
&3a51 f0 1a    BEQ &3a6d ; leave_with_carry_set                     # Leave if Y = 0, i.e. no tertiary object for tile
&3a53 ad 34 25 LDA &2534 ; tile_processing_mode
&3a56 29 90    AND #&90 ; TILE_PROCESSING_FLAG_PLOTTING | TILE_PROCESSING_FLAG_EVENTS
&3a58 f0 13    BEQ &3a6d ; leave_with_carry_set                     # Never branches in supervisor
; is_plotting_tile                                              *** # Supervisor assumes plotting tiles
&3a5a a5 0f    LDA &0f ; tile_flip
&3a5c 0a       ASL A                                                # Unnecessary code in supervisor
&3a5d b9 ae 1b LDA &1bae,Y ; tertiary_objects_data                  # &80 clear if object has already become primary
&3a60 10 0b    BPL &3a6d ; leave_with_carry_set
&3a62 a9 40    LDA #&40 ; OBJECT_BUSH
&3a64 20 f3 3a JSR &3af3 ; create_primary_object_from_tertiary      # Create bush object if it doesn't already exist
&3a67 a9 40    LDA #&40
&3a69 99 cb 1a STA &1acb,Y ; objects_y_fraction
;                                                               *** # Supervisor omits setting x_fraction
&3a6c 60       RTS
; leave_with_carry_set
&3a6d 38       SEC                                              *** # Supervisor omits spawning creatures
&3a6e 60       RTS

; unused                                                            # Unused code; doesn't correspond with anything in game
&3a6f a9 05    LDA #&05 ; OBJECT_LARGE_HIVE
&3a71 24 0f    BIT &0f ; tile_flip
&3a73 70 02    BVS &3a77 ; to_create_primary_object_from_tertiary
&3a75 a9 04    LDA #&04 ; OBJECT_SMALL_HIVE
; to_create_primary_object_from_tertiary
&3a77 4c f3 3a JMP &3af3 ; create_primary_object_from_tertiary

; update_engine_tile                                            *** # Null function in supervisor
&3a7a 60       RTS

; door_tiles_table                                                  # Tiles that are equivalent in obstruction
&3a7b 17 ; &00 (closed horizontal door) : TILE_SPACESHIP_WALL_HORIZONTAL_QUARTER
&3a7c 19 ; &01 (open horizontal door)   : TILE_SPACE
&3a7d 2a ; &02 (closed vertical door)   : TILE_STONE_SLOPE_SEVENTY_EIGHT
&3a7e 19 ; &03 (open vertical door)     : TILE_SPACE

; update_stone_door_tile                                            # Called with Y = this_object_tertiary_data_offset
&3a7f a9 3e    LDA #&3e ; OBJECT_HORIZONTAL_STONE_DOOR
&3a81 2c       BIT &85a9 ; (nop)
; update_metal_door_tile                                            # Called with Y = this_object_tertiary_data_offset
#3a82          LDA #&3c ; OBJECT_HORIZONTAL_METAL_DOOR
&3a84 85 0a    STA &0a ; door_type
;                                                               *** # Supervisor omits suppressing doors in obstruction check
&3a86 a5 0f    LDA &0f ; tile_flip                                  # &80 set if flipped horizontally, &40 if vertically
&3a88 0a       ASL A                                                # 84...... -> 8 4.......
&3a89 2a       ROL A                                                #          -> 4 .......8
&3a8a 69 00    ADC #&00
&3a8c 29 01    AND #&01                                             # 0 if neither or both set, horizontal door
&3a8e 48       PHA ; door orientation                               # 1 if one set, vertical door
&3a8f b9 ae 1b LDA &1bae,Y ; tertiary_objects_data
&3a92 30 01    BMI &3a95 ; is_tertiary
&3a94 4a       LSR A                                                # If not tertiary, use &04 DOOR_FLAG_MOVING instead
; is_tertiary
&3a95 29 02    AND #&02 ; DOOR_FLAG_OPENING                         # &02 set if door is open (&04 set if door is moving)
&3a97 4a       LSR A                                                # ......2. -> ......2
&3a98 e9 00    SBC #&00                                             #          -> &ff if unset, &00 if set
&3a9a 85 71    STA &71 ; door_open_fraction
&3a9c ad 34 25 LDA &2534 ; tile_processing_mode                     # Negative if TILE_PROCESSING_FLAG_PLOTTING set
&3a9f 30 09    BMI &3aaa ; skip_setting_tile                        # If not plotting tiles,
&3aa1 68       PLA ; door orientation
&3aa2 48       PHA ; door orientation
&3aa3 2a       ROL A                                                # Carry set if door is open
&3aa4 aa       TAX                                                  # 0: h closed, 1: h open, 2: v closed, 3: v open
&3aa5 bd 7b 3a LDA &3a7b,X ; door_tiles_table                       # Use tile that is equivalent in obstruction to door
&3aa8 85 0e    STA &0e ; tile_type_and_flip
; skip_setting_tile
&3aaa 68       PLA ; door orientation
&3aab 2c 34 25 BIT &2534 ; tile_processing_mode
&3aae 70 19    BVS &3ac9 ; leave                                    # &40 set if TILE_PROCESSING_FLAG_OBSTRUCTION
; create_door                                                       # If not considering obstructions, create door object
&3ab0 48       PHA ; door orientation                               # 0 if horizontal door, 1 if vertical door
&3ab1 18       CLC
&3ab2 65 0a    ADC &0a ; door_type
&3ab4 20 f3 3a JSR &3af3 ; create_primary_object_from_tertiary      # Create door object if it doesn't already exist
&3ab7 68       PLA ; door orientation
&3ab8 0a       ASL A
&3ab9 99 5e 1b STA &1b5e,Y ; objects_ty (door orientation)          # 0 for horizontal door, 2 for vertical door
&3abc aa       TAX
&3abd b5 23    LDA &23,X ; tile_x
&3abf e9 00    SBC #&00
&3ac1 99 9e 1b STA &1b9e,Y ; objects_state (door tile x or y)
&3ac4 a5 71    LDA &71 ; door_open_fraction
&3ac6 99 3e 1b STA &1b3e,Y ; objects_tx (door open fraction)
; leave
&3ac9 60       RTS

; update_transporter_tile
&3aca a9 41    LDA #&41 ; OBJECT_TRANSPORTER_BEAM
&3acc 20 f3 3a JSR &3af3 ; create_primary_object_from_tertiary      # Create beam object if it doesn't already exist
&3acf a9 40    LDA #&40
&3ad1 99 a8 1a STA &1aa8,Y ; objects_x_fraction
&3ad4 60       RTS

; update_invisible_switch_tile                                  *** # Null function in supervisor
&3ad5 60       RTS

; update_wind_or_water_tile                                     *** # Null function in supervisor
&3ad6 60       RTS

; update_tile_with_object_from_type
&3ad7 a6 05    LDX &05 ; this_object_tertiary_type_offset
&3ad9 bd 99 1c LDA &1c99,X ; tertiary_objects_type
&3adc 4c f3 3a JMP &3af3 ; create_primary_object_from_tertiary

; update_tile_with_object_from_data
&3adf b9 ae 1b LDA &1bae,Y ; tertiary_objects_data
&3ae2 29 7f    AND #&7f
&3ae4 20 f3 3a JSR &3af3 ; create_primary_object_from_tertiary
&3ae7 a9 49    LDA #&49 ; OBJECT_PLACEHOLDER
&3ae9 99 88 1a STA &1a88,Y ; objects_type
&3aec 60       RTS

; update_switch_tile
&3aed a9 42    LDA #&42 ; OBJECT_SWITCH
&3aef 4c f3 3a JMP &3af3 ; create_primary_object_from_tertiary      # Create switch object if it doesn't already exist

; update_mushroom_tile                                          *** # Null function in supervisor
&3af2 60       RTS

; create_primary_object_from_tertiary                               # Called with A = object type
&3af3 a0 00    LDY #&00                                          
&3af5 2c a0 08 BIT &08a0 ; (nop)
; create_primary_object_from_tertiary_if_eight_slots_free           # Unused entry point
#4045          LDY #&08 ; free slots needed
&3af8 85 70    STA &70 ; new_object_type
&3afa a6 04    LDX &04 ; this_object_tertiary_data_offset           # Zero if not a tertiary object that has a data byte
&3afc f0 07    BEQ &3b05 ; create_primary_object_from_tertiary_if_Y_slots_free
&3afe bd ae 1b LDA &1bae,X ; tertiary_objects_data                  # &80 clear if object has already become primary
&3b01 10 3c    BPL &3b3f ; leave_calling_routine
&3b03 a5 70    LDA &70 ; new_object_type
; create_primary_object_from_tertiary_if_Y_slots_free
&3b05 20 4f 25 JSR &254f ; create_new_object_if_Y_slots_free        # Returns carry clear if object created, X = slot
&3b08 b0 35    BCS &3b3f ; leave_tile_update_routine
&3b0a 20 52 26 JSR &2652 ; set_object_x_y_and_tx_ty_from_tile_x_y
&3b0d a6 70    LDX &70 ; new_object_type
&3b0f bd 00 15 LDA &1500,X ; object_types_sprite_table
&3b12 aa       TAX
&3b13 a5 0f    LDA &0f ; tile_flip
&3b15 09 01    ORA #&01 ; OBJECT_FLAG_NEWLY_CREATED | OBJECT_FLAG_NOT_PLOTTED
&3b17 99 ee 1a STA &1aee,Y ; objects_flags                          # Give object same flip as tile
;                                                                   # This sets other properties for some types of object
&3b1a a9 00    LDA #&00
&3b1c 24 0f    BIT &0f ; tile_flip                                  # &80 set if flipped horizontally
&3b1e 10 03    BPL &3b23 ; set_new_object_x_fraction
&3b20 fd 00 54 SBC &5400,X ; sprites_width_and_horizontal_flip_table
; set_new_object_x_fraction
&3b23 99 a8 1a STA &1aa8,Y ; objects_x_fraction
&3b26 a9 00    LDA #&00
&3b28 24 0f    BIT &0f ; tile_flip                                  # &40 set if flipped vertically
&3b2a 70 03    BVS &3b2f ; set_new_object_y_fraction
&3b2c fd ee 54 SBC &54ee,X ; sprites_height_and_vertical_flip_table
; set_new_object_y_fraction
&3b2f 99 cb 1a STA &1acb,Y ; objects_y_fraction
&3b32 a5 04    LDA &04 ; this_object_tertiary_data_offset
&3b34 99 8e 1b STA &1b8e,Y ; objects_tertiary_data_offset
&3b37 aa       TAX
&3b38 bd ae 1b LDA &1bae,X ; tertiary_objects_data
&3b3b 29 7f    AND #&7f                                             # Would clear &80 to indicate object is now primary
;                                                               *** # Supervisor doesn't set tertiary_objects_data
&3b3d 18       CLC                                               
&3b3e 60       RTS
; leave_calling_routine
&3b3f ae 99 25 LDX &2599 ; stack_pointer_to_leave_to_if_unable_to_create_primary_object
&3b42 9a       TXS
&3b43 38       SEC                                                  # Set carry to indicate object couldn't be created
&3b44 60       RTS

; null_update_one                                               *** # Most objects have no update in supervisor
&3b45 60       RTS

; set_this_object_x_flip_from_data                                  # This is part of update_switch in game
;                                                                   # Called in supervisor for various other objects
&3b46 a5 03    LDA &03 ; this_object_data                           # If &01 set, switch is on
&3b48 4a       LSR A
&3b49 66 27    ROR &27 ; this_object_x_flip                         # If so, set top bit to flip switch horizontally
&3b4b 60       RTS                                              ***

; unused                                                            # Corresponds to &49d6 - &49da in standard game
&3b4c 2a       ROL A
&3b4d 49 01    EOR #&01
&3b4f 6a       ROR A
&3b50 60       RTS

; unused                                                            # Unused code
&3b51 60       RTS

; encrypted_default_game_state
&3b52 f9 1c b3 58 66 41 38 86 93 02 20 55 26 67 50 16
&3b62 47 09 34 83 82 80 76 68 52 20 55 26 67 50 16 47
&3b72 09 34 83 82 80 76 68 52 df 81 78 40 a6 82 2b 0d
&3b82 bb a0 b6 cf 66 1e 83 82 7a 76 a8 4f a0 b6 c7 b1
&3b92 41 f6 0d 32 84 84 8f 16 a8 d2 80 96 08 32 79 74
&3ba2 34 43 22 59 d4 34 84 84 84 84 84 84 b4 04 24 72
&3bb2 69 56 19 54 32 96 b3 10 36 a1 4e 10 ce 1e de 9f
&3bc2 bc 5e ac 2c 5e 07 5b 78 3c 91 62 f7 77 65 0a 77
&3bd2 65 04 65 30 65 7d 18 cf f6 6d 18 32 5a 73 61 03
&3be2 1b 57 6d 77 70 89 2e 7f 0b 0c bc fa a2 58 32 79
&3bf2 74 64 44 03 bd fe dc 9c 85 98 51 50 56 98 52 7c
&3c02 42 db 3d da 29 4d 0e 90 51 a5 84 20 1b 6d 79 79
&3c12 35 85 86 88 92 00 16 7d 7d 7e 78 05 5b ea 01 09
&3c22 41 99 15 44 05 24 65 44 05 a5 86 48 11 b8 4c 79
&3c32 6e 54 15 22 17 e1 24 e4 ca 98 12 55 3b 4c 35 85
&3c42 86 88 cb 7c b4 fb 73 03 6e 43 01 18 51 18 50 07
&3c52 38 93 7b e2 2c 7e 7e 7e 7e 05 24 65 44 05 95 36
&3c62 85 8b 24 84 84 84 85 86 09 69 4b 1e 5d 3d 92 01
&3c72 16 4d 1e dc 96 e8 44 cf 1c a7 fe 0f 8d 7e 7e 49
&3c82 b9 7e 10 c2 8d 93 a6 40 84 be 7e 7e 7e 7e d1 13
&3c92 07 29 6d 58 cc 7e 7f 3e 05 2c 58 0c 64 44 85 8c
&3ca2 ed 7d 09 07 20 6b 59 ec 9f eb 7d 7e 7e 7e 4f 5f
&3cb2 33 81 77 ba 02 34 71 63 03 58 32 79 74 64 44 06
&3cc2 25 65 4b 1f 5e 3e 91 94 04 01 09 7c 4e 38 90 9b
&3cd2 13 42 94 04 24 6d 91 aa 56 63 40 96 93 83 17 35
&3ce2 f9 70 e9 ae f7 96 ed 91 a6 c0 f8 d2 ac 31 81 d2
&3cf2 d0 9f 08 18 ea c0 96 b5 31 bd fd f9 b3 e3 aa e5
&3d02 d4 a1 7c de f2 b9 3c 99 d2 b3 00 f7 71 bd f1 87
&3d12 af 80 84 87 84 b7 eb 88 92 a6 c3 b2 18 54 6f 00
&3d22 30 cd 84 10 81 c6 98 06 a8 8d 35 39 85 89 bb 92
&3d32 08 2c 55 67 89 84 98 cb 14 a1 c2 44 c5 14 b3 f5
&3d42 e0 c5 c8 d5 8c b3 82 b0 96 b8 9f 91 a6 b3 0e c2
&3d52 c7 85 80 82 1a e5 3e 52 20 89 ec 36 80 84 88 39
&3d62 b3 99 52 a0 d6 e8 45 84 84 84 a7 8c aa a2 e3 4b
&3d72 ff 80 35 ed e4 85 85 87 90 97 b0 56 ec d6 cc bf
&3d82 4d bb b4 a4 3c a2 b1 59 fc c5 51 aa 7c 18 e6 90
&3d92 92 04 8b 25 c5 82 83 5f be e4 2b b8 8e ae 9c d5
&3da2 85 82 80 e6 d8 75 c4 ce f8 c4 2d b0 d6 88 92 a1
&3db2 b8 f2 80 33 8d 04 b1 45 05 26 43 9e 11 f5 bd a3
&3dc2 53 b9 c7 e3 c4 b7 09 d3 d3 02 2f 57 6d 35 ad 3c
&3dd2 76 7e 6c 44 05 25 09 bf 34 89 84 96 0c 75 2d 48
&3de2 37 80 86 b3 14 6b 21 69 44 17 61 4d d3 38 ea 5a
&3df2 1c 63 53 20 7b 53 02 02 65 39 b0 58 cc 18 76 41
&3e02 15 45 20 11 75 e1 18 d2 80 b6 00 49 05 01 62 12
&3e12 5e 38 92 a8 22 64 04 78 c6 c2 36 57 61 18 68 48
&3e22 01 2c 3d 15 2b 03 3c ba 09 44 4f 7e 5b 78 69 07
&3e32 72 7a 3b 97 00 2c 48 3f 9f 5b c1 2b 21 32 5c 18
&3e42 46 1a 4c 15 66 44 1f c6 c3 a7 ca 34 df 90 b0 de
&3e52 a1 d9 3c b1 9c f0 d4 75 01 99 8e c0 1f 03 22 59
&3e62 34 83 82 80 76 68 52 20 55 26 67 0d 35 64 6f d0
&3e72 0c 3d 64 69 f6 31 48 18 49 f7 50 97 47 92 00 16
&3e82 47 09 34 83 82 80 76 68 52 20 31 42 09 d3 6b 70
&3e92 43 34 43 3c 75 72 15 3a c4 64 5e ae 68 08 32 79
&3ea2 74 64 44 03 22 59 34 83 82 80 0a f1 9a f4 2c f8
&3eb2 3a c1 36 d0 9b 75 85 88 79 85 38 c9 87 71 67 50
&3ec2 16 47 09 34 83 82 80 76 68 52 20 55 26 cf e8 83
&3ed2 7d 4b 81 a6 8e 9c 5b 8a 9e 54 86 40 f8 ef b9 fc
&3ee2 78 80 76 68 52 20 55 26 67 d0 16 28 71 cf 9e 12
&3ef2 6f 48 11 38 91 90 0c 3a 8f 68 72 88 8c 87 8f 96
&3f02 08 97 06 ff a1 6d f1 64 98 e0 7a 08 28 d3 8c 17
&3f12 66 bf be 80 01 45 01 d2 8f fa cc 48 46 2e 79 0a
&3f22 f9 ed 28 76 22 28 79 1b 80 53 bd 4c 02 33 b0 a3
&3f32 3d b1 b5 73 dc a3 ff 18 12 e6 12 2c 15 ee 8f 68
&3f42 be 44 99 37 01 56 75 04 12 cf 5b 64 98 8a 64 98

; null_update_two
&3f52 60       RTS

; null_update_three
&3f53 60       RTS

# &3f54 - &3fa9 is similar to code used in game. Differences are indicated by ***

; update_door                                                   *** # Supervisor omits code for touching and moving
&3f54 46 29    LSR &29 ; this_object_y_flip                         # Clear top bit to prevent door being flipped vertically
&3f56 a5 03    LDA &03 ; this_object_data
&3f58 09 04    ORA #&04 ; DOOR_FLAG_MOVING                          # Not meaningful in supervisor
&3f5a 4a       LSR A                                                # 84218421 -> .8421842 1
&3f5b 6a       ROR A                                                #          -> 1.842184 2
&3f5c 6a       ROR A                                                #          -> 21.84218 4 ; &80 set if &02 was set
&3f5d 85 6d    STA &6d ; door_opening_and_locked_flags              #                        ; &40 set if &01 was set
&3f5f 4a       LSR A                                                # 21.84218 -> 421.8421 8 ; carry set if &08 was set
&3f60 29 07    AND #&07                                             #          -> .....421 door colour
&3f62 85 6c    STA &6c ; door_colour
&3f64 a5 2f    LDA &2f ; this_object_tx (door open fraction)
&3f66 a6 31    LDX &31 ; this_object_ty (door orientation)
&3f68 18       CLC
&3f69 69 10    ADC #&10 ; 1 pixel                                   # Offset door by one pixel horizontally
&3f6b 95 36    STA &36,X ; this_object_x_fraction
&3f6d a5 28    LDA &28 ; this_object_state (door tile x or y)
&3f6f 69 00    ADC #&00
&3f71 95 3a    STA &3a,X ; this_object_x
&3f73 a6 6c    LDX &6c ; door_colour
&3f75 bd 81 3f LDA &3f81,X ; doors_palette_table
&3f78 24 6d    BIT &6d ; door_opening_and_locked_flags              # &40 set if DOOR_FLAG_LOCKED (&01) was set
&3f7a 70 02    BVS &3f7e ; set_door_palette
; is_unlocked
&3f7c 29 0f    AND #&0f                                             # Set colour three of door to black if unlocked
; set_door_palette
&3f7e 85 5a    STA &5a ; this_object_palette
&3f80 60       RTS

; doors_palette_table
&3f81 2b ; &00 : cyG (becomes &0b, cyK)                             # Cyan frame, yellow highlights, green lock (metal)
&3f82 2d ; &01 : ryG (becomes &0d, ryK)                             # Red frame, yellow highlights, green lock (metal)
&3f83 15 ; &02 : gyR (becomes &05, gyK)                             # Green frame, yellow highlights, red lock (metal)
&3f84 1c ; &03 : ywR (becomes &0c, ywK)                             # Yellow frame, white highlights, red lock (metal)
&3f85 42 ; &04 : rmB (becomes &02, rmK)                             # Red frame, magenta highlights, blue lock (stone)
&3f86 12 ; &05 : rmR (becomes &02, rmK)                             # Red frame, magenta highlights, red lock (metal)
&3f87 26 ; &06 : bcG (becomes &06, bcK)                             # Blue frame, cyan highlights, green lock (unused)
&3f88 4e ; &07 : mwB (becomes &0e, mwK)                             # Magenta frame, white highlights, blue lock (metal or stone)

; transporter_beams_palette_table
&3f89 52 ; rmM
&3f8a 63 ; rcC
&3f8b 35 ; gyB
&3f8c 21 ; rgG

; update_transporter_beam
&3f8d 4a       LSR A                                                # Set carry if transporter is inactive
;                                                               *** # Supervisor omits touching and movement code
&3f8e a9 b0    LDA #&b0                                         *** # Position beam in base if transporter is inactive
&3f90 b0 02    BCS &3f94 ; not_active                           ***
&3f92 a9 80    LDA #&80                                         *** # Position beam in middle of tile if transporter active
; not_active
&3f94 24 29    BIT &29 ; this_object_y_flip
&3f96 20 79 26 JSR &2679 ; invert_if_positive
&3f99 85 38    STA &38 ; this_object_y_fraction
&3f9b c6 38    DEC &38 ; this_object_y_fraction
&3f9d a5 3a    LDA &3a ; this_object_x                          *** # Set colour of beam depending on tile location
&3f9f 65 3c    ADC &3c ; this_object_y                          ***
&3fa1 29 03    AND #&03
&3fa3 aa       TAX
&3fa4 bd 89 3f LDA &3f89,X ; teleport_beams_palette_table
&3fa7 85 5a    STA &5a ; this_object_palette
&3fa9 60       RTS

; unused
&3faa 60       RTS

; null_update_four
&3fab 60       RTS

; null_update_five
&3fac 60       RTS

; unused                                                            # &3fad - &400b is a copy of &3ef3 - &3f51
&3fad 48 11 38 91 90 0c 3a 8f 68 72 88 8c 87 8f 96 08
&3fbd 97 06 ff a1 6d f1 64 98 e0 7a 08 28 d3 8c 17 66
&3fcd bf be 80 01 45 01 d2 8f fa cc 48 46 2e 79 0a f9
&3fdd ed 28 76 22 28 79 1b 80 53 bd 4c 02 33 b0 a3 3d
&3fed b1 b5 73 dc a3 ff 18 12 e6 12 2c 15 ee 8f 68 be
&3ffd 44 99 37 01 56 75 04 12 cf 5b 64 98 8a 64 98 

; unused                                                            # &400c - &41df is a copy of &372b - &38fe
&400c 8d ea 36 ad ea 36 f0 45 c9 08 90 10 ad ea 36 e9
&401c 08 8d ea 36 a9 89 20 ee ff 4c 2e 37 c9 04 90 10
&402c ad ea 36 e9 04 8d ea 36 a9 88 20 ee ff 4c 2e 37
&403c c9 02 90 0e ce ea 36 ce ea 36 a9 87 20 ee ff 4c
&404c 2e 37 ce ea 36 a9 86 20 ee ff 4c 2e 37 60 00 20
&405c 69 32 c9 0d f0 04 c9 20 d0 f5 a2 ff 9a a2 85 a0
&406c 37 20 77 32 20 7e 32 a9 04 a2 01 a0 00 20 f4 ff
&407c a9 e1 a2 30 a0 00 20 f4 ff a9 e2 a2 00 a0 00 20
&408c f4 ff a9 e3 a2 00 a0 00 20 f4 ff a9 e4 a2 00 a0
&409c 00 20 f4 ff 20 52 2e 20 68 38 a9 1e 20 c7 31 a9
&40ac 00 8d 79 37 a2 ad a0 38 20 fa 32 ad 79 37 18 69
&40bc 30 20 ee ff a9 26 20 a9 31 ad 79 37 0a 0a aa bd
&40cc be 38 a8 bd bd 38 aa 20 fa 32 a9 0d 20 ee ff a9
&40dc 0a 20 ee ff ee 79 37 ad 79 37 0a 0a aa bd bc 38
&40ec 10 c2 a2 41 a0 39 20 fa 32 ad 1f 33 d0 0a a2 44
&40fc a0 39 20 fa 32 4c 4d 38 c9 01 d0 0a a2 4e a0 39
&410c 20 fa 32 4c 4d 38 c9 02 d0 0a a2 58 a0 39 20 fa
&411c 32 4c 46 38 a2 62 a0 39 20 fa 32 a2 6c a0 39 20
&412c fa 32 20 69 32 38 e9 30 cd 79 37 b0 f5 0a 0a aa
&413c bd bb 38 85 1b bd bc 38 85 1c 6c 1b 00 a9 06 20
&414c a9 31 a9 07 20 c7 31 a2 91 a0 38 20 fa 32 a9 00
&415c 20 c7 31 a2 9c a0 38 20 fa 32 a9 07 20 c7 31 a2
&416c a1 a0 38 4c fa 32 11 53 8b 11 1e 8a 8a 8a 8a 8c
&417c 00 11 33 8f 90 00 11 1e 8d 8a 8a 8a 8a 11 53 8e
&418c 0d 00 11 31 20 20 20 20 20 20 20 20 20 20 46 00
&419c 7e 39 dd 38 f2 34 e6 38 81 33 2a 39 02 2a 37 39
&41ac 8f 2a fd 38 65 2a 0b 39 ef 33 ed 38 e1 31 19 39
&41bc ff ff 52 75 6e 20 47 61 6d 65 00 53 74 61 74 75
&41cc 73 00 53 63 6f 72 65 20 42 72 65 61 6b 64 6f 77
&41dc 6e 00 4c 6f

; map_data
&41e0 95 b6 19 ef 6f 6e 70 5e d4 a9 a9 57 6d 06 6e ed
&41f0 2d 6e 6e 06 ca 70 ad 07 5e 5e 53 62 53 9b 35 9e
&4200 15 16 e9 22 57 97 0c cc 8c 78 3f bd 05 ed e2 0a
&4210 f0 05 2d 6e d3 07 e4 24 63 a1 a5 64 53 07 a4 63
&4220 66 7e 3e dc 8c 72 e8 bc 06 19 22 6d de d3 19 71
&4230 f1 7e 29 f4 39 a9 d3 06 53 a1 e4 07 d4 a9 d3 1a
&4240 c1 77 d7 41 6f a1 6d 53 f5 d3 21 19 a1 53 06 e5
&4250 ee 19 97 d3 13 ea 75 02 d3 9b 53 ea 5f 85 72 21
&4260 6e 2c 2d 07 ad ed b1 25 19 2f 53 3b 9e e2 d3 62
&4270 02 f0 2d 06 a4 d3 19 21 53 21 ed 30 d3 6a 59 a4
&4280 6d 70 6f 04 a4 64 a2 a2 1e 04 d3 01 4a 3b 64 63
&4290 f0 2d 17 ed f4 2f 12 30 d3 21 fa a2 a1 e2 8d 2e
&42a0 64 6e 02 ee 04 05 13 ee 4a 6a 2d 05 9b 2d 25 65
&42b0 ed fe 31 6f f0 14 ee bf df 8d d3 6a de 53 8b 1e
&42c0 ee ad 70 7a 24 a1 22 6d 22 d3 21 93 df 01 02 dc
&42d0 ae 7c 06 af df b2 07 29 03 5e cd ea 53 cd 07 8f
&42e0 fc 94 66 69 30 07 62 35 d6 9d bf 2f 9d 62 62 1f
&42f0 53 21 d3 43 fe 45 93 74 9e f0 91 ae a1 62 02 07
&4300 6a cc d9 3d e2 ed ed b0 b4 15 e6 19 57 17 9d 4c
&4310 ed a2 93 65 03 21 9e 05 b4 b0 06 ee 5e a1 5e 25
&4320 49 f9 07 7c de de ea 07 67 04 bd 68 53 cc 26 a8
&4330 7a 21 de e2 9e 06 53 a1 1e e2 04 e8 9e 04 64 06
&4340 b9 06 da 13 e3 4a 21 f8 05 c2 32 97 07 62 ed 70
&4350 ef ea d3 6a e4 19 c6 f3 03 19 a8 1e 28 9e f5 29
&4360 07 04 70 21 1e 1e 06 fa ee 2c 2d f0 13 53 bb f0
&4370 56 21 ed a1 aa c0 c4 53 62 ef 2f f0 70 5e a1 19
&4380 6f de 1e a1 24 02 5f 62 6d 06 71 19 13 71 b0 af
&4390 56 ea de a5 21 e5 4b 8d 03 2f 29 2d 57 38 6e 07
&43a0 d3 19 2a e3 b5 6e 49 e5 70 62 b0 12 53 d3 22 6d
&43b0 df 8d 53 a1 d4 df 21 1e 2d f0 22 70 6e 35 12 e2
&43c0 9a 23 a1 61 68 05 a5 d3 04 2e 06 19 07 d3 e1 2e
&43d0 24 9b 53 cd 07 cd ca 0f 52 ed e2 2e 05 34 78 04
&43e0 3a 7b 04 ad 53 e1 b1 07 df 21 13 fa 7e 19 5e 7b
&43f0 05 96 3f bd 54 dd 19 b1 32 bc 69 2b 21 6f ee 19
&4400 b8 b2 2d 2d 64 20 53 03 53 a1 3e fe d3 07 53 fb
&4410 a8 b7 29 2b e8 bc 68 dd 19 39 a2 b1 f0 53 1e ad
&4420 70 3b 03 d6 53 1e 7a a5 07 1b 53 de 1e 9e d3 21
&4430 d6 19 68 fd 02 6a 34 66 b0 9e 04 ef 04 de ed f1
&4440 ed 18 a4 69 17 53 53 e2 ed 30 de ea 9e 19 19 47
&4450 ef 06 8c 72 ef 19 2f f0 ed b9 99 b1 de 23 a3 78
&4460 a2 2f 30 ef 04 b5 e4 a1 d3 19 7a a1 cd da 1b d3
&4470 6d 06 ed 71 b1 6e 04 6d ee af 4a d1 5e 1e 53 7c
&4480 ef 18 f0 2d 02 b8 7f 62 7c 8d 12 de c6 e4 8b ae
&4490 0d ed ad 0f e2 df b1 6e e4 04 64 07 25 f0 e4 19
&44a0 2e ef 19 b0 4f 32 75 07 e4 8d 5f 21 d4 cd cb 53
&44b0 8f ae af ed 4a 21 a1 79 23 ea 07 13 54 f5 62 24
&44c0 6f 4a ee 11 13 93 1e a9 25 5f a1 7a 24 a5 5e 0f
&44d0 a4 1e ee 19 a0 53 e1 a1 93 93 d3 e1 32 97 93 53
&44e0 d3 19 21 1e f9 19 a5 03 6b 21 ae 12 7c 6a fa 2d
&44f0 38 72 bf b0 21 ef 11 b5 56 36 02 3d 68 01 8c 30
&4500 d3 21 64 7e 64 a1 7c 21 54 fe f2 6e e4 29 5f 04
&4510 19 19 2a af 2d e2 6a 6f a7 69 f7 e9 32 a8 fc 28
&4520 fa 07 d3 6a 64 32 53 05 4a 62 04 56 d3 6a 54 a4
&4530 6d 53 e2 ed 69 14 1e ef 37 00 40 28 d3 05 2d 74
&4540 ed 05 ef 5e 53 e3 19 a5 30 05 17 a1 a8 5f 21 05
&4550 22 ed e2 b1 62 02 64 65 6d 2c 12 cc 6d e2 04 d3
&4560 53 a1 19 ab a2 cd 8b 13 01 af 21 ed 51 94 f5 29
&4570 39 2e f0 1a 5e 02 1e 7a ad ed 39 70 b1 ee 03 b4
&4580 d6 8d 53 21 c2 de 8b 2d ed 19 2f 2f 01 af ff 3f
&4590 53 00 ed 25 06 ef 24 e2 2d ed ed de 5e 7b 31 07
&45a0 13 cd d3 1b d4 cd 07 06 a2 6f a2 31 f0 06 f8 62
&45b0 a1 53 aa 00 64 05 00 25 0f 6d 53 ed d3 19 13 93
&45c0 22 d3 22 e1 05 64 65 2d 70 19 62 06 22 63 63 bb
&45d0 64 63 53 04 22 72 63 7e 64 63 64 05 22 65 5b a1

; sprite_data                                                       # 128 x 113 pixel sprite sheet, 32 bytes per row
&45e0 c0 00 00 00 32 11 80 10 00 00 00 20 06 08 00 00
&45f0 01 8c 00 66 80 00 00 00 01 02 08 64 90 80 00 66
&4600 8c 00 00 00 56 a3 c0 ca 00 00 00 07 2d 66 00 00
&4610 00 00 00 60 c0 00 00 00 01 0b 88 42 f0 3e 64 4c
&4620 3c 00 00 00 03 01 19 68 00 00 13 21 2d 00 00 00
&4630 0b 8d 00 40 68 00 00 00 02 ab 00 cb f8 18 90 4c
&4640 df 00 00 00 46 23 00 1c 00 00 37 07 06 00 00 00
&4650 ca 35 04 42 fc 80 00 00 13 19 0a e8 74 99 83 1e
&4660 3c c0 00 00 46 23 00 0a 00 00 1f 21 00 00 00 00
&4670 cb bd c5 63 4f c0 00 00 15 9f 0b e2 33 00 87 78
&4680 ff 0c 00 00 07 83 59 0e 00 01 3f 07 00 00 03 0f
&4690 4b ad f5 7b 6f e0 00 00 47 ff 26 c0 65 01 96 c0
&46a0 c7 f4 00 00 04 02 11 08 00 03 1f 07 00 00 0f 0f
&46b0 4a 25 b5 db ff ac 00 00 4f ff 4e 80 61 0b 1e 00
&46c0 ff ef 00 00 06 13 11 5c 00 21 3f 21 00 01 0f 0f
&46d0 4b ad a5 4b 7a 9e 80 00 37 fb ce 80 f8 01 96 e0
&46e0 79 79 c0 00 06 13 11 1e 00 07 1f 21 00 03 1f 2f
&46f0 4b ad 85 43 6f 7c c0 00 13 f9 8c 40 e0 00 87 3c
&4700 2f 3d cc 00 26 03 00 8c 00 21 3f 07 00 03 0e 0d
&4710 4a 25 04 42 df 4f ca 00 13 f0 8c 10 80 11 87 1e
&4720 ff ff 3c 00 04 03 28 24 00 07 3f 07 00 07 0f 0f
&4730 0b 8d 00 40 bd ef 9e 00 0d f0 8f 00 0c 10 80 84
&4740 96 c7 f7 00 04 06 68 30 00 21 1f 21 00 06 0b 0d
&4750 00 00 00 40 9f 3e 5e 80 15 f1 ae 00 cc 32 32 00
&4760 ff ff de 80 40 40 40 10 00 07 3f 21 00 11 44 22
&4770 03 0e 00 42 ff a7 fc 84 37 eb cc 01 0e 00 12 08
&4780 b6 1e 8f 68 60 60 00 03 00 21 3f 07 01 0f 0f 0f
&4790 0e 0b 08 41 a7 bf 9f 68 6f ef 0f 11 ca 00 25 0c
&47a0 ff ff ff 8e 00 00 00 ca 00 07 1f 07 01 0f 0f 0f
&47b0 88 88 88 62 6f 9f 3f f8 07 bf 0d 03 2d 00 48 44
&47c0 69 c7 78 be 00 11 91 06 00 21 3f 07 00 80 00 90
&47d0 00 12 c0 71 cf ff ef fe 11 9b 88 33 ed 00 4b 0e
&47e0 6d 6f 3d 8f 00 23 c0 0c 00 21 3f 21 30 e8 30 b9
&47f0 0c 25 e0 50 6f 8f d6 af 01 8a 08 07 0f 08 00 00
&4800 ff ff ff ff 00 01 19 1a 11 07 1f 21 73 fc 73 bb
&4810 ce 25 c0 66 ed af cf cb 00 0b 8c ff 8f 1d ff ff
&4820 3c 9e c7 3c 00 23 11 2a 13 07 3f 07 74 f2 74 b0
&4830 ce 00 31 06 cf ff 9f df 01 09 00 07 0f 08 dc e0
&4840 ff ff ff ff 00 03 59 08 04 21 3f 07 64 b2 64 90
&4850 ed ff e2 ff 7f bf df 7f 22 00 88 33 6f 11 dd ff
&4860 e3 3d 0f e3 00 01 11 4c 17 21 1f 07 64 32 32 07
&4870 ed ff 80 06 7b 3e 7f 1f 74 11 c0 03 07 00 dc e0
&4880 ff ff ff ff 00 02 11 7e 0c 07 3f 07 64 77 b0 27
&4890 eb ff ee ff 2f e7 3f bf 40 10 00 11 46 11 dd ff
&48a0 3c 8f 79 2d 00 07 00 3c 97 07 3f 21 64 72 80 05
&48b0 eb 00 33 06 7f 3f 7e ef 60 10 80 01 0e 00 cc 00
&48c0 ff ff ff ff 00 27 00 0c 0c 21 1f 21 fe 00 20 07
&48d0 e7 25 c0 66 df ff cf 4f 70 10 c0 00 cc 00 11 cc
&48e0 cb 6b d6 c7 08 0d 00 40 97 21 1f 07 f4 20 20 27
&48f0 6f 25 e0 05 9e cf c7 6d dc 33 40 11 00 00 d1 88
&4900 87 e7 1e de 18 81 00 60 0c 07 3f 07 00 32 64 05
&4910 69 00 00 05 8f 4f 5f ef 8e 23 08 c1 60 00 00 00
&4920 ff ff ff ff 98 10 00 00 0c 07 3f 07 64 32 32 06
&4930 6f 88 40 20 df fe ff b7 0d 03 04 61 c0 8e 30 80
&4940 a7 1e c7 4b 90 10 80 00 97 07 1f 07 64 77 b0 00
&4950 6f 08 90 22 f7 3f ef 3f 8c 23 04 01 11 4a 07 0c
&4960 ff ff ff ff 88 22 00 00 1f 21 1f 21 64 72 80 20
&4970 6f 98 b0 64 5f b7 2f ef 8f ab 08 11 11 ed f0 f7
&4980 9e c7 79 1e 08 74 00 88 0c 21 3f 21 e0 00 30 e2
&4990 6f 78 70 bc 5f af 7b 8f 8b ab 2e 9f 01 bd 00 00
&49a0 ff ff ff ff 88 40 11 c0 84 07 3f 07 e8 20 73 ee
&49b0 6f 7c a0 06 cf ff 6f ed cc 22 3f 99 99 2f 73 ee
&49c0 7b 5a 8f c7 80 60 10 00 1f 07 1f 07 c0 3a 30 e0
&49d0 6f 3c 04 9c 8f 7d cf f7 37 11 11 ff 99 0f 30 c4
&49e0 e3 0f 1e e7 08 70 10 80 00 11 ee 0f 01 3a 04 20
&49f0 6f d8 a0 0e ff c7 ef 5f 07 09 dd 99 88 9f 00 00
&4a00 ff ff ff ff 88 dc 10 c0 00 11 ee 0f 1b 3a 06 0e
&4a10 6f 1c c0 04 d7 6f 7f 4f 07 0d 0c 9f 00 ee 73 ee
&4a20 3c 9e e3 1e 0c 8e 33 40 00 01 0e 44 0a 3a 04 0e
&4a30 6f bc 80 2a 1f ff fd cf 07 0d 08 00 00 5c 30 cc
&4a40 ff ff ff ff cc 0d 23 08 00 11 ee 0b 0b 3a 02 4e
&4a50 6f e8 80 9f bf bd 9f ff 0e 81 08 00 00 2c 30 c4
&4a60 4f 79 0f e3 c0 8d 03 04 00 05 0e 0f 1b 3a 06 0a
&4a70 6f 5f 48 03 ef 0f 9f 7b 0c c5 08 00 00 6e 30 cc
&4a80 ff ff ff ff 8c 8e 23 00 00 04 00 0f 0a 2a 0e 0e
&4a90 6f 1f 0c 06 7b 2f ff 2f 80 c1 00 00 00 2c 00 00
&4aa0 3d bc 79 0f 88 8f ab 2e 00 1d ee 78 09 09 4e 4e
&4ab0 6f ef 4e 40 1f ff eb 2f c4 10 00 00 00 5c 33 cc
&4ac0 3c 8f 7d 3c c8 8b aa 2e 00 0d 0e 08 0c 03 0a 0a
&4ad0 6f 8f df 60 ff bd 3f 6f c0 10 88 00 00 00 30 cc
&4ae0 ff ff ff ff cc 44 33 00 01 08 00 0f 0e 07 0e 0e
&4af0 f0 f0 f0 c0 bd 1f 1f ff 00 10 80 00 00 00 30 cc
&4b00 e3 1e 8f e3 48 37 01 cc 01 5d ee 78 2f 27 4e 4e
&4b10 6f ff ef ec 9f 7f df 3d 00 88 00 00 00 00 30 cc
&4b20 ff ff ff ff 88 07 01 0e 03 01 0e 08 0d 05 0a 0a
&4b30 6f ff ef ec df de ff 8f 22 91 40 40 00 00 30 c4
&4b40 0f c7 79 2d c4 03 01 0e 03 c4 01 0f 0f 07 0e 0e
&4b50 6f ff ef de 7f 4f cb ef 20 54 40 41 00 00 30 cc
&4b60 ff ff ff ff ce cb 63 0e 06 00 03 f0 0a 02 0a 0a
&4b70 6f ff ef de 6f 6f 8f bf 45 42 61 c3 ac 85 30 cc
&4b80 6b 79 0f c7 4a c3 61 20 16 d5 8f 00 55 55 55 55
&4b90 6f ff ef be ff a7 ff bd 61 00 a9 81 7f ce 30 cc
&4ba0 7f ff ff ff cc 90 40 31 0e 01 0f 0f 0f 0f 0f 0f
&4bb0 6f ff ef be 3d bf df 9f 20 b8 01 03 88 07 30 cc
&4bc0 cf c7 b5 3c c6 10 88 30 0f 0f 0f 0f 0f 0f 0f 0f
&4bd0 f0 f0 f0 7e 8f ef 4f ff 89 a4 99 00 cc ce 30 c4
&4be0 f7 ff ff ce 00 10 80 00 0f 0f 0f 0f 0f 07 0e 0f
&4bf0 00 30 00 02 f0 f2 f3 f4 a0 90 80 00 77 cd 30 cc
&4c00 b5 0f e3 68 00 00 00 10 0f 0f 0f 0f 0f 07 19 1e
&4c10 00 31 00 55 60 f0 70 e0 51 40 11 22 0f 0f 30 cc
&4c20 79 ad 7b 0c 00 00 00 10 0c 03 00 00 0e 02 47 69
&4c30 00 20 11 20 40 a0 20 40 12 39 32 31 f0 6f 30 c4
&4c40 ff ff 8f c0 00 00 00 30 3c c3 f0 f0 19 55 1e 83
&4c50 00 02 00 e0 00 2b 04 00 22 c6 31 3e 00 f6 30 cc
&4c60 2f 6b df 88 00 00 00 21 0f 0f 0f 0f 47 0f 69 4f
&4c70 00 06 01 51 00 22 09 44 10 50 33 3f 06 6f 30 cc
&4c80 ef 6b 5a 80 00 00 00 61 00 06 00 00 0f 1e 87 0f
&4c90 00 0e c0 c0 11 7f 26 44 00 28 33 33 60 0f 30 cc
&4ca0 7f ff cf 00 00 00 00 43 f0 96 f0 f0 0f 69 0f 0e
&4cb0 01 0d ea 82 15 55 67 4c 10 0c 11 22 00 44 30 c4
&4cc0 96 c7 78 00 00 00 00 43 0f 0f 0f 0f 1e 83 0f 1b
&4cd0 67 0b 50 c0 33 df ef ee 00 08 00 00 0f cd 30 cc
&4ce0 ff ff ca 00 00 00 00 a5 00 0c 00 03 69 4f 0e 4d
&4cf0 46 00 10 22 aa 9d aa aa 00 08 55 00 09 f0 30 cc
&4d00 2d 3c e8 00 00 00 10 87 f0 3c f0 c3 87 0f 1b 07
&4d10 4d 2e 10 80 ef 17 23 bf 65 11 60 00 69 49 30 cc
&4d20 ef 1e 0c 00 00 00 10 d7 0f 0f 0f 0f 0f 0e 4d 0c
&4d30 8f 2e 30 44 46 0e 37 99 33 8a b0 88 69 6e 00 00
&4d40 7b cf c0 00 00 00 30 7f 0f 0f 0f 0f 0f 1b 07 00
&4d50 8f 00 20 00 0f 07 1b 06 55 9d 55 02 0f 08 70 ee
&4d60 ef 6f 88 00 00 00 30 7b 0a 0d 0a 0d 0e 4d 0c 00
&4d70 ce 00 00 44 0b 06 1f 0b 66 0a fa 27 09 01 00 ac
&4d80 2d 5e 80 00 00 00 21 2f 55 22 55 22 1b 07 00 00
&4d90 20 00 00 22 30 01 08 11 33 8c a0 fd 09 21 91 3d
&4da0 f3 ef 00 00 00 00 53 a7 0f 0f 0f 0f 4d 0c 00 00
&4db0 e0 00 00 22 43 0b 0c 32 80 19 50 27 69 25 91 0f
&4dc0 ef 3c 00 00 00 00 53 af 0f 0f 0f 0f 07 00 00 00
&4dd0 c0 00 00 01 04 82 44 20 00 04 55 02 6f 3d 80 0e
&4de0 b4 2e 00 00 00 00 a7 ef 05 0f 0f 0a 0c 00 00 00
&4df0 80 00 00 88 06 03 00 30 00 24 24 24 6f 2c 91 8c
&4e00 ff 68 00 00 00 10 a5 7f 84 aa 55 12 08 10 4c 00
&4e10 e8 00 11 c0 07 0b 0c 30 80 24 ff 24 69 37 3a 0c
&4e20 6b 4c 00 00 00 01 0f ff 84 00 00 12 08 32 2e 00
&4e30 44 00 10 00 00 00 00 66 80 00 f6 24 09 33 47 07
&4e40 ff c0 00 00 00 10 6f 8f 85 0f 0f 1a 2e 03 2e 00
&4e50 00 00 10 80 71 9a 0c 47 00 fb 64 99 09 22 47 09
&4e60 a5 08 00 00 00 30 7f df 87 0b 0d 1e 17 01 0c 00
&4e70 00 00 10 c0 a7 12 28 06 19 fd 80 f6 0f 02 47 2e
&4e80 5e 80 00 00 00 30 7b f5 83 49 29 1c 21 88 6e c1
&4e90 00 00 33 40 aa 52 70 46 18 ff 88 64 0f 22 23 a6
&4ea0 9f 00 00 00 00 53 3f 7f c9 6c 63 39 47 88 6a ac
&4eb0 08 00 27 00 ff 12 c0 47 00 fa 00 00 09 22 11 0c
&4ec0 78 00 00 00 00 c3 2f 4f 64 3f cf 62 df 03 1f ba
&4ed0 04 00 cf 09 af 9a d0 47 4c 66 00 00 69 22 00 0a
&4ee0 ce 00 00 00 00 d3 6f e7 33 04 02 cc 8e 02 1f 9f
&4ef0 82 00 8f 09 aa ce 60 45 4c 00 00 44 69 33 00 0e
&4f00 68 00 00 00 00 97 7f 3f f0 0f 0f 0f 8f 04 17 99
&4f10 c8 00 4f 19 ff cf 08 22 00 00 00 e8 0f 08 01 0f
&4f20 8c 00 00 00 10 0f ff ff c3 87 0f 0f 8f 1d 2e 8f
&4f30 ec 01 4e 1d af 8d 0c 13 88 00 df 80 f0 0f 0f f0
&4f40 48 00 00 00 10 7a 6d bf f0 0f 0f 0f 65 23 e6 88
&4f50 ee cb 2e 2e aa ee 00 03 08 02 ff c0 00 1c 83 00
&4f60 88 00 00 00 30 3f 4f af 77 ff ff ee 23 23 08 f0
&4f70 f0 c3 0c 26 77 bb cc c5 1d 85 4f e0 06 1d 8b 06
&4f80 80 00 00 00 61 ff df ef 70 a5 0f 0e 03 19 0c ff
&4f90 ff 83 00 01 00 00 00 80 0c 03 4f 28 60 1d 8b 60
&4fa0 ff ff 00 04 52 cf ff 3f 70 c3 0f 0e 47 0c 04 00
&4fb0 00 44 08 01 70 91 08 e3 1d 87 4f 0c 00 1c 83 00
&4fc0 ff ff 2d 2a d3 ef cf f7 70 2d 0f 0e 47 c4 0c 31
&4fd0 00 61 08 00 87 59 0c 61 18 87 46 1f 0f 0f 0f 0f
&4fe0 00 00 22 11 97 2f 6f cf 70 87 0f 0e 23 80 0c 31
&4ff0 00 41 00 00 0f 1d cc 40 10 06 00 17 f0 80 10 f0
&5000 00 00 00 00 66 00 11 cc 00 00 00 00 55 00 00 ff
&5010 88 77 77 22 00 33 99 bb 33 00 ee 00 00 77 88 44
&5020 77 77 77 dd ee ee cd 3f 66 77 dd ff dd 33 dd 8f
&5030 cc df bf 22 00 67 ff ff 33 11 bf 00 00 57 88 ff
&5040 df df df dd ff bf 9d ff bf cf dd 9f dd 33 7f bb
&5050 cc 1d bb 77 00 66 3f 6f 33 11 bb 00 00 77 99 8f
&5060 1d ff dd ff 7f 1b 19 ff 0b 6e 5d 3b 0d 33 77 ab
&5070 cc 77 3b 77 00 ff 03 06 ff ef ef 33 cc 17 89 ee
&5080 dd cf 7f cf 77 bb 99 ff 00 37 77 67 00 33 77 bb
&5090 8c 67 33 df 88 6f 00 00 3f 1f ae 03 0c 11 ee 3f
&50a0 7f 7f 17 dd ef ef dd ff 00 ef 27 77 88 ff df 8b
&50b0 08 06 33 dd 88 66 00 00 33 11 bb 77 ff 99 bf ef
&50c0 07 07 77 7f 0e 0e 3f 0f 00 0e 02 07 08 ff 0d ff
&50d0 cc 66 77 0d 7f ff cc 00 33 01 df 88 00 11 ef 4e
&50e0 00 00 07 07 00 00 03 00 00 00 00 00 00 0f 00 0f
&50f0 0c 06 07 00 07 0f 0c 00 03 00 0d 2f af 89 0e 04
&5100 00 03 00 ff bb bb 00 11 88 00 00 00 22 00 00 00
&5110 11 cc 77 bb 66 22 33 00 ff 00 00 00 00 00 00 00
&5120 0d 3f 00 cf 6f ff 77 77 ee ff bb 88 ee 33 bb 66
&5130 11 cc 77 ff ff aa df 99 88 00 00 57 5f 08 00 00
&5140 dd ff 00 ff 06 ff df df bf bf bb 88 ff 8b ff ff
&5150 ef 0c ff bf 6f ff 9d bb 6e 00 00 00 00 00 00 00
&5160 df bb 00 1f 99 cf dd dd bb bb bb aa ef 3b ef bf
&5170 0e 00 df bb 66 7f 09 ef 00 00 00 07 0f 08 00 00
&5180 ff bb 00 11 89 ff dd dd bb bb bb ff ee ef ee 3b
&5190 ff ff dd bb 66 ff 99 bf 44 00 00 77 8a ff 00 00
&51a0 dd 88 00 dd 88 ff 7f 7f bb bb ef df bf bf ee 33
&51b0 1f ff 8d 7f ff af dd 9b 88 00 00 f8 07 70 88 00
&51c0 dd 88 00 7f 08 ff 07 07 0b 0b 0e 0d 0b 0b 0e 03
&51d0 01 5f 99 bf 6f 2a 3f 09 88 00 11 80 0d 08 c4 00
&51e0 df 88 00 07 00 0f 00 00 00 00 00 00 00 00 00 00
&51f0 00 05 09 0b 06 02 03 00 08 00 10 07 0a 0f 40 00
&5200 77 77 77 33 33 11 bb 77 ee cc ff ee ee ee ee ff
&5210 88 00 00 00 00 88 00 00 cc 00 fe 00 07 00 73 88
&5220 df df df ff 33 11 bb df bf cc df bf bf bf bf cf
&5230 88 00 00 00 33 bb aa bb cc 00 f0 06 0d 0b 70 80
&5240 cd 1d dd bf 33 11 ef dd bb 7f 9d 8b 3b bb 8b 1d
&5250 88 00 00 00 22 88 aa aa cc 11 80 00 00 00 00 c4
&5260 ff 77 7f bb 33 55 ce dd bb 37 3b cc 33 bb 88 33
&5270 08 00 00 00 22 bb bb 99 cc 10 b3 cc 55 55 ee c0
&5280 df cf 17 bb 33 ff ee 7f ef 33 13 8c 33 bb bb 67
&5290 00 03 0f 0e 33 bb 88 bb cc 32 23 6e dd 45 8e 62
&52a0 dd dd dd bb 33 bf bf 17 bf 33 11 99 bb bb 9b 66
&52b0 00 06 00 00 00 00 11 88 dd b8 77 37 9d 44 ee 60
&52c0 7f 7f 7f 7f bb 1b bb 11 bb 33 11 ef ef ef ef 66
&52d0 00 1f ff ee 00 00 88 00 ff ec 47 13 19 44 4e 31
&52e0 07 07 07 07 0b 01 0b 01 0b 03 01 0e 0e 0e 0e 06
&52f0 00 5f ff ee 11 44 33 00 0f 68 ff 33 99 77 77 b8
&5300 11 dd bb cc 66 66 ff 77 33 bb bb ff 66 ee cc 77
&5310 ff 1b ff ee 22 aa aa 88 00 40 0f 67 cd 07 07 18
&5320 11 dd ef ee ee 66 df df ef ef df bf 77 bf cc 77
&5330 3f 1f ff ee 22 aa aa 88 00 51 ff ce 7f ff ff dc
&5340 11 dd ee ff ff 66 dd dd ee ee 1d bb 67 3b 6e cf
&5350 77 1f ff ee 22 aa aa 88 00 41 0f 0c 07 0f 0f 1c
&5360 11 dd bf df 7f ff dd dd bf bf 11 bb 66 ef 37 8c
&5370 ef 5f ff ee 22 00 00 00 00 40 00 00 00 00 00 10
&5380 11 dd ef cd 67 ef dd dd ef ef 11 9b 57 8e 67 dd
&5390 ce 1b ff ee 33 bb bb 66 dd f8 e0 08 00 00 38 f0
&53a0 dd dd ee cc 66 6e dd dd 6e ee dd 99 dd 88 ce 7f
&53b0 8c 1f ff ee 22 aa 22 66 99 70 e0 0f 0a 0f 38 f0
&53c0 7f 7f 3f cc 66 66 ff 6f bf bf 9d 89 9d ff cc 77
&53d0 ff 06 00 00 22 aa 11 44 88 88 70 07 0a 0f 70 00
&53e0 07 07 03 0c 06 06 0f 06 0b 0b 09 08 09 0f 0c 07
&53f0 0f 03 0f 0e 22 aa 33 66 dd 88 30 83 07 06 e0 00

# Sprites
# =======
# Sprites are as per game, plus:
#
# sprite                                            width     height    size    sheet x   sheet y   position  flip
# &7d SPRITE_CHARACTER_20 (" ")                   : &547d &00 &556b &38  1 x  8 &5659 &d5 &5747 &2b ( 93,101)     
# &7e SPRITE_CHARACTER_21 ("!")                   : &547e &10 &556c &38  2 x  8 &565a &b4 &5748 &ca ( 75, 89)     
# &7f SPRITE_CHARACTER_22 (""")                   : &547f &20 &556d &38  3 x  8 &565b &13 &5749 &8a ( 49, 81)     
# &80 SPRITE_CHARACTER_23 ("#")                   : &5480 &60 &556e &38  7 x  8 &565c &d4 &574a &ca ( 77, 89)     
# &81 SPRITE_CHARACTER_24 ("$")                   : &5481 &40 &556f &38  5 x  8 &565d &b7 &574b &8a (123, 81)     
# &82 SPRITE_CHARACTER_25 ("%")                   : &5482 &50 &5570 &38  6 x  8 &565e &57 &574c &8a (117, 81)     
# &83 SPRITE_CHARACTER_26 ("&")                   : &5483 &50 &5571 &38  6 x  8 &565f &76 &574d &8a (103, 81)     
# &84 SPRITE_CHARACTER_27 ("'")                   : &5484 &00 &5572 &38  1 x  8 &5660 &33 &574e &8a ( 51, 81)     
# &85 SPRITE_CHARACTER_28 ("(")                   : &5485 &20 &5573 &38  3 x  8 &5661 &b3 &574f &8a ( 59, 81)     
# &86 SPRITE_CHARACTER_29 (")")                   : &5486 &21 &5574 &38  3 x  8 &5662 &b3 &5750 &8a ( 59, 81) h   
# &87 SPRITE_CHARACTER_2a ("*")                   : &5487 &60 &5575 &38  7 x  8 &5663 &35 &5751 &ca ( 83, 89)     
# &88 SPRITE_CHARACTER_2b ("+")                   : &5488 &50 &5576 &38  6 x  8 &5664 &06 &5752 &8a ( 96, 81)     
# &89 SPRITE_CHARACTER_2c (",")                   : &5489 &10 &5577 &38  2 x  8 &5665 &64 &5753 &ca ( 70, 89)     
# &8a SPRITE_CHARACTER_2d ("-")                   : &548a &50 &5578 &20  6 x  5 &5666 &d6 &5754 &8a (109, 81)     
# &8b SPRITE_CHARACTER_2e (".")                   : &548b &10 &5579 &38  2 x  8 &5667 &43 &5755 &8a ( 52, 81)     
# &8c SPRITE_CHARACTER_2f ("/")                   : &548c &30 &557a &38  4 x  8 &5668 &74 &5756 &ca ( 71, 89)     
# &8d SPRITE_CHARACTER_30 ("0")                   : &548d &40 &557b &38  5 x  8 &5669 &33 &5757 &0b ( 51, 97)     
# &8e SPRITE_CHARACTER_31 ("1")                   : &548e &30 &557c &38  4 x  8 &566a &d0 &5758 &0b ( 13, 97)     
# &8f SPRITE_CHARACTER_32 ("2")                   : &548f &40 &557d &38  5 x  8 &566b &33 &5759 &4b ( 51,105)     
# &90 SPRITE_CHARACTER_33 ("3")                   : &5490 &41 &557e &38  5 x  8 &566c &52 &575a &4b ( 37,105) h   
# &91 SPRITE_CHARACTER_34 ("4")                   : &5491 &40 &557f &39  5 x  8 &566d &30 &575b &ca (  3, 89)   v 
# &92 SPRITE_CHARACTER_35 ("5")                   : &5492 &40 &5580 &38  5 x  8 &566e &c0 &575c &ca ( 12, 89)     
# &93 SPRITE_CHARACTER_36 ("6")                   : &5493 &40 &5581 &38  5 x  8 &566f &00 &575d &0b (  0, 97)     
# &94 SPRITE_CHARACTER_37 ("7")                   : &5494 &40 &5582 &38  5 x  8 &5670 &c3 &575e &0b ( 60, 97)     
# &95 SPRITE_CHARACTER_38 ("8")                   : &5495 &40 &5583 &38  5 x  8 &5671 &12 &575f &4b ( 33,105)     
# &96 SPRITE_CHARACTER_39 ("9")                   : &5496 &40 &5584 &38  5 x  8 &5672 &80 &5760 &0b (  8, 97)     
# &97 SPRITE_CHARACTER_3a (":")                   : &5497 &10 &5585 &38  2 x  8 &5673 &34 &5761 &c2 ( 67, 88)     
# &98 SPRITE_CHARACTER_3b (";")                   : &5498 &10 &5586 &38  2 x  8 &5674 &44 &5762 &ca ( 68, 89)     
# &99 SPRITE_CHARACTER_3c ("<")                   : &5499 &30 &5587 &38  4 x  8 &5675 &d5 &5763 &ca ( 93, 89)     
# &9a SPRITE_CHARACTER_3d ("=")                   : &549a &20 &5588 &38  3 x  8 &5676 &04 &5764 &ca ( 64, 89)     
# &9b SPRITE_CHARACTER_3e (">")                   : &549b &31 &5589 &38  4 x  8 &5677 &d5 &5765 &ca ( 93, 89) h   
# &9c SPRITE_CHARACTER_3f ("?")                   : &549c &40 &558a &38  5 x  8 &5678 &44 &5766 &8a ( 68, 81)     
# &9d SPRITE_CHARACTER_40 ("@")                   : &549d &60 &558b &38  7 x  8 &5679 &b3 &5767 &8a ( 59, 81)     
# &9e SPRITE_CHARACTER_41 ("A")                   : &549e &40 &558c &39  5 x  8 &567a &00 &5768 &d2 (  0, 90)   v 
# &9f SPRITE_CHARACTER_42 ("B")                   : &549f &41 &558d &38  5 x  8 &567b &90 &5769 &4b (  9,105) h   
# &a0 SPRITE_CHARACTER_43 ("C")                   : &54a0 &41 &558e &38  5 x  8 &567c &f2 &576a &0b ( 47, 97) h   
# &a1 SPRITE_CHARACTER_44 ("D")                   : &54a1 &40 &558f &38  5 x  8 &567d &81 &576b &4b ( 24,105)     
# &a2 SPRITE_CHARACTER_45 ("E")                   : &54a2 &30 &5590 &38  4 x  8 &567e &b2 &576c &0b ( 43, 97)     
# &a3 SPRITE_CHARACTER_46 ("F")                   : &54a3 &31 &5591 &38  4 x  8 &567f &92 &576d &0b ( 41, 97) h   
# &a4 SPRITE_CHARACTER_47 ("G")                   : &54a4 &40 &5592 &38  5 x  8 &5680 &73 &576e &0b ( 55, 97)     
# &a5 SPRITE_CHARACTER_48 ("H")                   : &54a5 &40 &5593 &38  5 x  8 &5681 &51 &576f &4b ( 21,105)     
# &a6 SPRITE_CHARACTER_49 ("I")                   : &54a6 &10 &5594 &38  2 x  8 &5682 &51 &5770 &4b ( 21,105)     
# &a7 SPRITE_CHARACTER_4a ("J")                   : &54a7 &40 &5595 &38  5 x  8 &5683 &00 &5771 &4b (  0,105)     
# &a8 SPRITE_CHARACTER_4b ("K")                   : &54a8 &40 &5596 &38  5 x  8 &5684 &71 &5772 &0b ( 23, 97)     
# &a9 SPRITE_CHARACTER_4c ("L")                   : &54a9 &40 &5597 &38  5 x  8 &5685 &06 &5773 &0b ( 96, 97)     
# &aa SPRITE_CHARACTER_4d ("M")                   : &54aa &60 &5598 &38  7 x  8 &5686 &c0 &5774 &4b ( 12,105)     
# &ab SPRITE_CHARACTER_4e ("N")                   : &54ab &50 &5599 &38  6 x  8 &5687 &11 &5775 &4b ( 17,105)     
# &ac SPRITE_CHARACTER_4f ("O")                   : &54ac &40 &559a &38  5 x  8 &5688 &33 &5776 &0b ( 51, 97)     
# &ad SPRITE_CHARACTER_50 ("P")                   : &54ad &41 &559b &38  5 x  8 &5689 &c1 &5777 &0b ( 28, 97) h   
# &ae SPRITE_CHARACTER_51 ("Q")                   : &54ae &40 &559c &38  5 x  8 &568a &c1 &5778 &4b ( 28,105)     
# &af SPRITE_CHARACTER_52 ("R")                   : &54af &40 &559d &38  5 x  8 &568b &f1 &5779 &0b ( 31, 97)     
# &b0 SPRITE_CHARACTER_53 ("S")                   : &54b0 &41 &559e &38  5 x  8 &568c &40 &577a &0b (  4, 97) h   
# &b1 SPRITE_CHARACTER_54 ("T")                   : &54b1 &30 &559f &38  4 x  8 &568d &a2 &577b &4b ( 42,105)     
# &b2 SPRITE_CHARACTER_55 ("U")                   : &54b2 &40 &55a0 &38  5 x  8 &568e &40 &577c &4b (  4,105)     
# &b3 SPRITE_CHARACTER_56 ("V")                   : &54b3 &40 &55a1 &38  5 x  8 &568f &e2 &577d &4b ( 46,105)     
# &b4 SPRITE_CHARACTER_57 ("W")                   : &54b4 &60 &55a2 &38  7 x  8 &5690 &21 &577e &0b ( 18, 97)     
# &b5 SPRITE_CHARACTER_58 ("X")                   : &54b5 &60 &55a3 &38  7 x  8 &5691 &83 &577f &4b ( 56,105)     
# &b6 SPRITE_CHARACTER_59 ("Y")                   : &54b6 &50 &55a4 &38  6 x  8 &5692 &42 &5780 &0b ( 36, 97)     
# &b7 SPRITE_CHARACTER_5a ("Z")                   : &54b7 &50 &55a5 &38  6 x  8 &5693 &e3 &5781 &4b ( 62,105)     
# &b8 SPRITE_CHARACTER_5b ("[")                   : &54b8 &21 &55a6 &38  3 x  8 &5694 &94 &5782 &8a ( 73, 81) h   
# &b9 SPRITE_CHARACTER_5c ("\")                   : &54b9 &31 &55a7 &38  4 x  8 &5695 &74 &5783 &ca ( 71, 89) h   
# &ba SPRITE_CHARACTER_5d ("]")                   : &54ba &20 &55a8 &38  3 x  8 &5696 &94 &5784 &8a ( 73, 81)     
# &bb SPRITE_CHARACTER_5e ("^")                   : &54bb &40 &55a9 &38  5 x  8 &5697 &c4 &5785 &8a ( 76, 81)     
# &bc SPRITE_CHARACTER_5f ("_")                   : &54bc &20 &55aa &38  3 x  8 &5698 &15 &5786 &8a ( 81, 81)     
# &bd SPRITE_CHARACTER_60 ("`")                   : &54bd &50 &55ab &38  6 x  8 &5699 &45 &5787 &8a ( 84, 81)     
# &be SPRITE_CHARACTER_61 ("a")                   : &54be &40 &55ac &38  5 x  8 &569a &53 &5788 &ca ( 53, 89)     
# &bf SPRITE_CHARACTER_62 ("b")                   : &54bf &41 &55ad &38  5 x  8 &569b &c1 &5789 &ca ( 28, 89) h   
# &c0 SPRITE_CHARACTER_63 ("c")                   : &54c0 &41 &55ae &38  5 x  8 &569c &00 &578a &8a (  0, 81) h   
# &c1 SPRITE_CHARACTER_64 ("d")                   : &54c1 &40 &55af &38  5 x  8 &569d &c1 &578b &ca ( 28, 89)     
# &c2 SPRITE_CHARACTER_65 ("e")                   : &54c2 &40 &55b0 &38  5 x  8 &569e &40 &578c &8a (  4, 81)     
# &c3 SPRITE_CHARACTER_66 ("f")                   : &54c3 &41 &55b1 &38  5 x  8 &569f &11 &578d &ca ( 17, 89) h   
# &c4 SPRITE_CHARACTER_67 ("g")                   : &54c4 &40 &55b2 &38  5 x  8 &56a0 &80 &578e &8a (  8, 81)     
# &c5 SPRITE_CHARACTER_68 ("h")                   : &54c5 &40 &55b3 &38  5 x  8 &56a1 &f1 &578f &ca ( 31, 89)     
# &c6 SPRITE_CHARACTER_69 ("i")                   : &54c6 &10 &55b4 &38  2 x  8 &56a2 &c1 &5790 &8a ( 28, 81)     
# &c7 SPRITE_CHARACTER_6a ("j")                   : &54c7 &20 &55b5 &38  3 x  8 &56a3 &a1 &5791 &8a ( 26, 81)     
# &c8 SPRITE_CHARACTER_6b ("k")                   : &54c8 &40 &55b6 &38  5 x  8 &56a4 &11 &5792 &8a ( 17, 81)     
# &c9 SPRITE_CHARACTER_6c ("l")                   : &54c9 &10 &55b7 &38  2 x  8 &56a5 &11 &5793 &8a ( 17, 81)     
# &ca SPRITE_CHARACTER_6d ("m")                   : &54ca &60 &55b8 &38  7 x  8 &56a6 &93 &5794 &ca ( 57, 89)     
# &cb SPRITE_CHARACTER_6e ("n")                   : &54cb &41 &55b9 &38  5 x  8 &56a7 &32 &5795 &ca ( 35, 89) h   
# &cc SPRITE_CHARACTER_6f ("o")                   : &54cc &40 &55ba &38  5 x  8 &56a8 &81 &5796 &ca ( 24, 89)     
# &cd SPRITE_CHARACTER_70 ("p")                   : &54cd &40 &55bb &38  5 x  8 &56a9 &63 &5797 &8a ( 54, 81)     
# &ce SPRITE_CHARACTER_71 ("q")                   : &54ce &41 &55bc &38  5 x  8 &56aa &63 &5798 &8a ( 54, 81) h   
# &cf SPRITE_CHARACTER_72 ("r")                   : &54cf &50 &55bd &38  6 x  8 &56ab &e1 &5799 &8a ( 30, 81)     
# &d0 SPRITE_CHARACTER_73 ("s")                   : &54d0 &30 &55be &38  4 x  8 &56ac &42 &579a &8a ( 36, 81)     
# &d1 SPRITE_CHARACTER_74 ("t")                   : &54d1 &40 &55bf &38  5 x  8 &56ad &13 &579b &ca ( 49, 89)     
# &d2 SPRITE_CHARACTER_75 ("u")                   : &54d2 &41 &55c0 &38  5 x  8 &56ae &72 &579c &ca ( 39, 89) h   
# &d3 SPRITE_CHARACTER_76 ("v")                   : &54d3 &40 &55c1 &38  5 x  8 &56af &82 &579d &8a ( 40, 81)     
# &d4 SPRITE_CHARACTER_77 ("w")                   : &54d4 &60 &55c2 &38  7 x  8 &56b0 &b2 &579e &ca ( 43, 89)     
# &d5 SPRITE_CHARACTER_78 ("x")                   : &54d5 &40 &55c3 &38  5 x  8 &56b1 &51 &579f &8a ( 21, 81)     
# &d6 SPRITE_CHARACTER_79 ("y")                   : &54d6 &41 &55c4 &38  5 x  8 &56b2 &c0 &57a0 &8a ( 12, 81) h   
# &d7 SPRITE_CHARACTER_7a ("z")                   : &54d7 &30 &55c5 &38  4 x  8 &56b3 &d2 &57a1 &8a ( 45, 81)     
# &d8 SPRITE_CHARACTER_7b ("{")                   : &54d8 &31 &55c6 &38  4 x  8 &56b4 &a5 &57a2 &ca ( 90, 89) h   
# &d9 SPRITE_CHARACTER_7c ("|")                   : &54d9 &10 &55c7 &38  2 x  8 &56b5 &61 &57a3 &ca ( 22, 89)     
# &da SPRITE_CHARACTER_7d ("}")                   : &54da &30 &55c8 &38  4 x  8 &56b6 &a5 &57a4 &ca ( 90, 89)     
# &db SPRITE_CHARACTER_7e ("~")                   : &54db &50 &55c9 &38  6 x  8 &56b7 &a5 &57a5 &8a ( 90, 81)     
# &dc SPRITE_CHARACTER_7f (DELETE)                : &54dc &30 &55ca &38  4 x  8 &56b8 &a4 &57a6 &3b ( 74,103)     
# &dd SPRITE_SECONDS                              : &54dd &a0 &55cb &20 11 x  5 &56b9 &a5 &57a7 &63 ( 90,108)     
# &de SPRITE_MINUTES                              : &54de &a0 &55cc &20 11 x  5 &56ba &25 &57a8 &3b ( 82,103)     
# &df SPRITE_HOURS                                : &54df &90 &55cd &20 10 x  5 &56bb &25 &57a9 &63 ( 82,108)     
# &e0 SPRITE_DAYS                                 : &54e0 &d0 &55ce &28 14 x  6 &56bc &25 &57aa &0b ( 82, 97)     
# &e1 SPRITE_ENERGY_BAR_LEFT                      : &54e1 &20 &55cf &58  3 x 12 &56bd &44 &57ab &2b ( 68,101)     
# &e2 SPRITE_ENERGY_BAR_RIGHT                     : &54e2 &21 &55d0 &58  3 x 12 &56be &44 &57ac &2b ( 68,101) h   
# &e3 SPRITE_ENERGY_BAR_ONE                       : &54e3 &00 &55d1 &58  1 x 12 &56bf &74 &57ad &2b ( 71,101)     
# &e4 SPRITE_ENERGY_BAR_TWO                       : &54e4 &10 &55d2 &58  2 x 12 &56c0 &74 &57ae &2b ( 71,101)     
# &e5 SPRITE_ENERGY_BAR_FOUR                      : &54e5 &30 &55d3 &58  4 x 12 &56c1 &74 &57af &2b ( 71,101)     
# &e6 SPRITE_ENERGY_BAR_EIGHT                     : &54e6 &70 &55d4 &58  8 x 12 &56c2 &74 &57b0 &2b ( 71,101)     
# &e7 SPRITE_TITLE_BAR_MIDDLE                     : &54e7 &70 &55d5 &30  8 x  7 &56c3 &d6 &57b1 &b2 (109, 86)     
# &e8 SPRITE_TITLE_BAR_LEFT_LEFT                  : &54e8 &21 &55d6 &31  3 x  7 &56c4 &16 &57b2 &ca ( 97, 89) h v 
# &e9 SPRITE_TITLE_BAR_LEFT_RIGHT                 : &54e9 &20 &55d7 &30  3 x  7 &56c5 &16 &57b3 &ca ( 97, 89)     
# &ea SPRITE_TITLE_BAR_RIGHT_LEFT                 : &54ea &21 &55d8 &30  3 x  7 &56c6 &16 &57b4 &ca ( 97, 89) h   
# &eb SPRITE_TITLE_BAR_RIGHT_RIGHT                : &54eb &20 &55d9 &31  3 x  7 &56c7 &16 &57b5 &ca ( 97, 89)   v 
# &ec SPRITE_LOGO_LEFT                            : &54ec &b0 &55da &98 12 x 20 &56c8 &56 &57b6 &ea (101, 93)     
# &ed SPRITE_LOGO_RIGHT                           : &54ed &e0 &55db &98 15 x 20 &56c9 &17 &57b7 &ea (113, 93)     

; sprites_width_and_horizontal_flip_table                           # 8421.... width of sprite in pixels
;      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f               # .......1 flip sprite horizontally if set
&5400 c0 a0 50 90 40 50 60 40 21 20 20 21 11 11 50 30 ; &00         #
&5410 60 51 50 50 80 50 50 b0 b0 80 80 50 90 70 50 30 ; &10         # Also width of sprite in fractions
&5420 40 20 10 f1 f1 71 30 f0 f0 f0 f0 f1 f0 30 60 30 ; &20
&5430 30 f0 f0 f1 f0 f0 f0 f0 f1 f0 f0 f0 f0 f0 f0 f0 ; &30
&5440 f0 30 60 f0 f0 70 00 f0 f0 f0 f0 30 31 41 f0 20 ; &40
&5450 40 20 50 50 30 70 c0 40 40 20 60 60 40 f0 70 20 ; &50
&5460 70 90 c0 30 40 50 60 40 40 30 f0 20 30 31 70 b1 ; &60
&5470 f0 70 51 41 50 51 30 80 30 30 50 50 40 00 10 20 ; &70
&5480 60 40 50 50 00 20 21 60 50 10 50 10 30 40 30 40 ; &80
&5490 41 40 40 40 40 40 40 10 10 30 20 31 40 60 40 41 ; &90
&54a0 41 40 30 31 40 40 10 40 40 40 60 50 40 41 40 40 ; &a0
&54b0 41 30 40 40 60 60 50 50 21 31 20 40 20 50 40 41 ; &b0
&54c0 41 40 40 41 40 40 10 20 40 10 60 41 40 40 41 50 ; &c0
&54d0 30 40 41 40 60 40 41 30 31 10 30 50 30 a0 a0 90 ; &d0
&54e0 d0 20 21 00 10 30 70 70 21 20 21 20 b0 e0       ; &e0

; sprites_height_and_vertical_flip_table                            # 84218... height of sprite in rows, minus one
;      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f               # .......1 flip sprite vertically if set
&54ee 40 80 98 91 a8 a0 a0 a0 09 08 10 19 19 18 58 18 ; &00         #
&54fe 60 78 81 98 78 70 98 90 28 48 78 69 20 28 38 48 ; &10         # Also height of sprite in fractions
&550e 38 20 08 f8 f8 68 f9 f9 b9 79 39 f8 78 38 38 38 ; &20
&551e f8 38 78 f8 f8 78 f8 78 f8 f8 c9 78 38 f8 89 09 ; &30
&552e 49 f8 f8 f9 f9 68 00 f8 78 38 39 f9 f9 28 48 18 ; &40
&553e 11 19 20 29 41 f8 70 30 20 20 19 18 28 60 48 80 ; &50
&554e 58 58 39 19 68 68 68 58 68 58 38 38 28 48 48 48 ; &60
&555e 48 08 30 20 28 39 70 38 30 20 20 20 20 38 38 38 ; &70
&556e 38 38 38 38 38 38 38 38 38 38 20 38 38 38 38 38 ; &80
&557e 38 39 38 38 38 38 38 38 38 38 38 38 38 38 39 38 ; &90
&558e 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 ; &a0
&559e 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 ; &b0
&55ae 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 ; &c0
&55be 38 38 38 38 38 38 38 38 38 38 38 38 38 20 20 20 ; &d0
&55ce 28 58 58 58 58 58 58 30 31 30 30 31 98 98       ; &e0

; sprites_spritesheet_x_table                                       # Left of sprite in spritesheet, in pixel columns
;      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f               #
&55dc 36 44 c5 04 66 06 91 41 60 43 d0 d4 e4 e4 a4 03 ; &00         # 8421.... -> ....8421 +1x
&55ec 97 63 03 05 77 97 65 06 06 06 06 e6 c6 d6 e6 f6 ; &10         # .....421 -> .421.... +16x
&55fc 37 d6 65 02 03 12 c2 03 03 03 03 02 02 04 96 c4 ; &20
&560c 04 04 43 43 00 00 05 05 01 00 00 00 00 05 05 05 ; &30
&561c 05 00 c0 00 00 44 c0 03 03 03 07 07 53 17 02 d4 ; &40
&562c 80 d4 07 f6 c6 87 04 84 47 67 c6 c6 96 02 44 d4 ; &50
&563c c3 67 36 86 01 51 31 b1 b1 c4 02 67 47 15 55 35 ; &60
&564c 05 00 16 37 e6 76 04 b6 c4 47 84 b6 a4 d5 b4 13 ; &70
&565c d4 b7 57 76 33 b3 b3 35 06 64 d6 43 74 33 d0 33 ; &80
&566c 52 30 c0 00 c3 12 80 34 44 d5 04 d5 44 b3 00 90 ; &90
&567c f2 81 b2 92 73 51 51 00 71 06 c0 11 33 c1 c1 f1 ; &a0
&568c 40 a2 40 e2 21 83 42 e3 94 74 94 c4 15 45 53 c1 ; &b0
&569c 00 c1 40 11 80 f1 c1 a1 11 11 93 32 81 63 63 e1 ; &c0
&56ac 42 13 72 82 b2 51 c0 d2 a5 61 a5 a5 a4 a5 25 25 ; &d0
&56bc 25 44 44 74 74 74 74 d6 16 16 16 16 56 17       ; &e0

; sprites_spritesheet_y_table                                       # Top of sprite in spritesheet, in rows
;      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f               #
&56ca 42 02 e9 81 98 98 e0 e0 7a 00 72 e1 5a 3a 81 00 ; &00         # 84218... -> ...84218 +1y
&56da e1 0a 02 e9 60 68 e9 00 00 49 49 50 68 68 58 50 ; &10         # ......21 -> .21..... +32y
&56ea d0 d9 a0 00 28 01 01 09 49 89 c9 01 81 41 81 41 ; &20
&56fa 80 41 80 20 00 00 00 00 89 80 80 80 31 80 09 89 ; &30
&570a 49 80 80 71 01 d0 00 80 01 41 4a 89 a8 e9 f9 c0 ; &40
&571a 72 c0 00 20 00 e0 00 18 11 e1 c0 c8 51 b1 78 00 ; &50
&572a 2a 00 02 02 00 00 70 00 60 e0 4a 0a b1 99 99 99 ; &60
&573a 99 72 c9 61 59 c1 d0 11 88 89 90 e8 90 2b ca 8a ; &70
&574a ca 8a 8a 8a 8a 8a 8a ca 8a ca 8a 8a ca 0b 0b 4b ; &80
&575a 4b ca ca 0b 0b 4b 0b c2 ca ca ca ca 8a 8a d2 4b ; &90
&576a 0b 4b 0b 0b 0b 4b 4b 4b 0b 0b 4b 4b 0b 0b 4b 0b ; &a0
&577a 0b 4b 4b 4b 0b 4b 0b 4b 8a ca 8a 8a 8a 8a ca ca ; &b0
&578a 8a ca 8a ca 8a ca 8a 8a 8a 8a ca ca ca 8a 8a 8a ; &c0
&579a 8a ca ca 8a ca 8a 8a 8a ca ca ca 8a 3b 63 3b 63 ; &d0
&57aa 0b 2b 2b 2b 2b 2b 2b b2 ca ca ca ca ea ea       ; &e0

; unused
&57b8 16 16 16 16 16 16 16 16 06 06 06 06 06 06 06 17
&57c8 16 16 16 19 1e 23 16 17 09 06 06 13 17 17 17 17
&57d8 06 13 06 2d 16 16 06 06 06 06 06 16 16 1f 06 06
&57e8 06 06 16 16 07 07 06 06 06 07 07 07 13 06 06 0c
&57f8 06 06 06 07 13 07 03 06 06 06 1e 1e 37 2d 16 1f
&5808 1f 1e 06 06 06 3f 16 06 0d 1f 1f 1f 1f 37 19 29
&5818 16 06 1f 1f 06 06 06 06 06 06 1f 0e 06 06 06 06
&5828 06 3c 16 16 16 06 3d 06 06 06 06 06 06 06 06 06
&5838 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06
&5848 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06
&5858 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06
&5868 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06
&5878 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06 06
&5888 06 06 06 06 06 06 06 06 06 06 06 06 06 03 03 03
&5898 03 06 06 06 06 06 06 06 06 06 06 06 06 06 05 05
&58a8 05 05 05 05 05 05 05 05 05 05 05 05 05 01 11 11
&58b8 11 05 01 15 05 05 01 00 00 05 01 01 01 01 05 11
&58c8 05 10 05 05 05 05 05 05 05 05 05 11 05 05 05 05
&58d8 05 05 15 15 05 05 11 00 00 00 00 05 05 04 05 05
&58e8 05 00 00 00 01 05 05 05 14 14 14 01 05 14 14 15
&58f8 05 05 05 05 05 05 14 04 04 04 04 04 05 05 05 05
&5908 01 01 11 11 11 11 05 05 00 01 05 05 05 05 05 14
&5918 11 11 11 05 10 05 05 05 05 05 05 05 05 05 05 05
&5928 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05
&5938 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05
&5948 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05
&5958 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05
&5968 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05
&5978 05 05 05 05 05 05 05 05 05 05 05 01 01 01 01 05
&5988 05 05 05 05 05 05 05 05 05 05 05 05 

; unused
&5994 6d 61 6e 4c 49 0d                               ; "manLI"
&599a 6d 61 6e 4c 46 0d                               ; "manLF"
&59a0 6d 61 6e 4b 4e 0d                               ; "manKN"
&59a6 6d 61 6e 4c 42 0d                               ; "manLB"
&59ac 6d 61 6e 53 54 0d                               ; "manST"
&59b2 6d 61 6e 52 55 31 0d                            ; "manRU1"
&59b9 6d 61 6e 52 55 32 0d                            ; "manRU2"
&59c0 6d 61 6e 52 55 33 0d                            ; "manRU3"
&59c7 6c 69 6e 65 31 0d                               ; "line1"
&59cd 6c 69 6e 65 32 0d                               ; "line2"
&59d3 6c 69 6e 65 33 0d                               ; "line3"
&59d9 6c 69 6e 65 34 0d                               ; "line4"
&59df 6c                                              ; "l"

; relocate_binary_and_saved_position
&74e0 d8       CLD
&74e1 78       SEI
&74e2 ad b7 ff LDA &ffb7 ; os_rom_default_vector_table_address_low
&74e5 85 1b    STA &1b ; default_vector_table_address_low
&74e7 ad b8 ff LDA &ffb8 ; os_rom_default_vector_table_address_high
&74ea 85 1c    STA &1c ; default_vector_table_address_high
&74ec a0 00    LDY #&00
; reset_vector_table_loop
&74ee b1 1b    LDA (&1b),Y ; default_vector_table_address
&74f0 99 00 02 STA &0200,Y ; os_vector_table
&74f3 c8       INY
&74f4 c0 12    CPY #&12
&74f6 d0 f6    BNE &74ee ; reset_vector_table_loop
&74f8 58       CLI
&74f9 a9 c8    LDA #&c8 ; Read/Write BREAK/ESCAPE effect
&74fb a2 03    LDX #&03 ; Clear memory on next RESET
&74fd a0 00    LDY #&00
&74ff 20 f4 ff JSR &fff4 ; OSBYTE
&7502 a9 8f    LDA #&8f ; Issue paged ROM service request
&7504 a2 0c    LDX #&0c ; NMI claim
&7506 a0 ff    LDY #&ff
&7508 20 f4 ff JSR &fff4 ; OSBYTE
&750b a9 ea    LDA #&ea ; Read/Write Tube present flag
&750d a2 00    LDX #&00 ; disable tube
&750f a0 00    LDY #&00
&7511 20 f4 ff JSR &fff4 ; OSBYTE
&7514 a9 14    LDA #&14 ; Implode user defined font
&7516 a2 00    LDX #&00
&7518 20 f4 ff JSR &fff4 ; OSBYTE
&751b a9 00    LDA #&00 ; &2c00
&751d 85 1b    STA &1b ; source_address_low
&751f a9 2c    LDA #&2c
&7521 85 1c    STA &1c ; source_address_high
&7523 20 8d 75 JSR &758d ; move_encrypted_game_state                # Move &2c00 - &2fff to &0400 - &07ff
&7526 a9 01    LDA #&01 ; POSITION_STATE_UNSAVED
&7528 8d 1f 4e STA &4e1f ; position_state + &1b00                   # Will be relocated at &755d
; decrypt_saved_game_state                                          # Unnecessary code; will be overwritten at &755d
&752b a9 82    LDA #&82 ; &fc82 = &10000 - &37e
&752d 85 1b    STA &1b ; size_low
&752f a9 fc    LDA #&fc
&7531 85 1c    STA &1c ; size_high
&7533 a0 00    LDY #&00
&7535 a9 6e    LDA #&6e
&7537 85 00    STA &00 ; key
&7539 a9 92    LDA #&92
&753b 38       SEC
&753c f8       SED
; decrypt_saved_game_state_loop                                     # Decrypt &2c00 - &2f7d
&753d 65 00    ADC &00 ; key
&753f 69 15    ADC #&15
&7541 85 00    STA &00 ; key
&7543 59 00 2c EOR &2c00,Y
#     actually EOR source_address,Y
&7546 99 00 2c STA &2c00,Y
#     actually STA target_address,Y
&7549 45 00    EOR &00 ; key
&754b c8       INY
&754c d0 06    BNE &7554 ; skip_page
&754e ee 45 75 INC &7545 ; source_address_high
&7551 ee 48 75 INC &7548 ; target_address_high
; skip_page
&7554 e6 1b    INC &1b ; size_low
&7556 d0 e5    BNE &753d ; decrypt_saved_game_state_loop
&7558 e6 1c    INC &1c ; size_high
&755a d0 e1    BNE &753d ; decrypt_saved_game_state_loop
&755c d8       CLD
; move_3000_to_74df_loop                                            # Move &3000 - &74df to &1500 - &59df
&755d ad 00 30 LDA &3000
#     actually LDA source_address
&7560 8d 00 15 STA &1500
#     actually STA target_address
&7563 ee 5e 75 INC &755e ; source_address_low
&7566 d0 03    BNE &756b ; skip_source_page
&7568 ee 5f 75 INC &755f ; source_address_high
; skip_source_page
&756b ee 61 75 INC &7561 ; target_address_high
&756e d0 03    BNE &7573 ; skip_target_page
&7570 ee 62 75 INC &7562 ; target_address_low
; skip_target_page
&7573 ad 5e 75 LDA &755e ; source_address_low
&7576 c9 e0    CMP #&e0
&7578 d0 e3    BNE &755d ; move_loop
&757a ad 5f 75 LDA &755f ; source_address_high
&757d c9 74    CMP #&74
&757f d0 dc    BNE &755d ; move_loop
&7581 a9 00    LDA #&00
&7583 a2 8f    LDX #&8f
; wipe_0001_to_008f_loop                                            # Wipe &0001 - &008f
&7585 95 00    STA &00,X
&7587 ca       DEX
&7588 d0 fb    BNE &7585 ; wipe_0001_to_008f_loop
&758a 4c 2f 33 JMP &332f ; entry_point_after_relocation

; move_encrypted_game_state
&758d a9 04    LDA #&04 ; &0400 = encrypted_game_state
&758f 8d 9a 75 STA &759a ; target_address
&7592 a0 00    LDY #&00
&7594 a2 04    LDX #&04
; move_encrypted_game_state_loop
&7596 b1 1b    LDA (&1b),Y ; source_address
&7598 99 00 04 STA &0400,Y ; encrypted_game_state
#     actually STA target_address,Y
&759b c8       INY
&759c d0 f8    BNE &7596 ; move_memory_loop
&759e e6 1c    INC &1c ; source_address_high
&75a0 ee 9a 75 INC &759a ; target_address_high
&75a3 ca       DEX
&75a4 d0 f0    BNE &7596 ; move_encrypted_game_state_loop
&75a6 60       RTS

; unused
&75a7 4c 00 30 JMP &3000

; unused
&75aa 2c

; leave_to_relocate_binary_and_saved_position
&75ab 68       PLA
&75ac aa       TAX
&75ad 68       PLA
&75ae 49 01    EOR #&01 ; &010c = &75d3 ^ &74df
&75b0 48       PHA
&75b1 8a       TXA
&75b2 49 0c    EOR #&0c
&75b4 48       PHA
&75b5 60       RTS                                                  # Leaves to &74e0 ; relocate_binary_and_saved_position

; unused
&75b6 0b

; decrypt_byte
&75b7 49 f2    EOR #&f2
#     becomes  BNE &75ab ; leave_to_relocate_binary_and_saved_position when &75b7 is decrypted
&75b9 65 70    ADC &70 ; eor
&75bb 69 97    ADC #&97
&75bd 85 70    STA &70 ; eor
&75bf 59 00 30 EOR &3000,Y
#     actually EOR source_address,Y
&75c2 99 00 30 STA &3000,Y
#     actually STA target_address,Y
&75c5 45 70    EOR &70 ; eor
&75c7 c8       INY
&75c8 d0 07    BNE &75d1 ; next_byte
&75ca ee c1 75 INC &75c1 ; source_address_high
&75cd ee c4 75 INC &75c4 ; target_address_high
&75d0 60       RTS
; next_byte
&75d1 20 b7 75 JSR &75b7 ; decrypt_byte
&75d4 d0 e1    BNE &75b7 ; decrypt_byte

; entry_point
&75d6 a9 23    LDA #&23
&75d8 85 70    STA &70 ; eor
&75da a9 78    LDA #&78
&75dc a0 00    LDY #&00
&75de 38       SEC
&75df 78       SEI
&75e0 4c b7 75 JMP &75b7 ; decrypt_byte

