The game

Dunjunz, official flippy disc (Bug-Byte, 1987), Model B side

Updated 8 Nov 2026

← All Dunjunz versions

FileLoadExecLengthSHA-256
Dun1&2000&2000&60005f40fe371da5d4a388d6abfd0cda3c683992b363c425fb90746e02f505c77f31
Coder&5000&5000&09B02809c2aca27673963f795033190d0668c59789161483f173b331a8b468ae1775
2000 ADC #1 ; ...+1: their first sprite...
2002 TAY ; ...in Y, for the height loop...
2003 TAX ; ...and in X, for the width loop
2004 ADC #7 ; ...+7: stop before base + 8, left frame 1
2006 STA scratch ; ...kept as the end
2009 .shrink_hero_width←1← 2010 BNE
DEC sprite_widths,x ; One byte (two pixels) narrower
200C INX ; Next of the hero's seven sprites
200D CPX scratch ; Reached the end?
2010 BNE shrink_hero_width ; No: narrow the next
2012 TYA ; Three rows shorter...
2013 TAX ; ...from the first sprite again
2014 .shrink_hero_height←1← 2021 BNE
SEC ; ...set carry to subtract
2015 LDA sprite_heights,x ; This sprite's height...
2018 SBC #3 ; ...less three rows...
201A STA sprite_heights,x ; ...stored back in sprite_heights
201D INX ; Next of the hero's seven sprites
201E CPX scratch ; Reached the end?
2021 BNE shrink_hero_height ; No: shorten the next
2023 JMP play_level ; ...three rows shorter. Next frame
; The hero has gone: put the exit back.
2026 .restore_exit←1← 1FFA BEQ
LDA exit_saved_x ; Put the exit back where it was...
2029 STA exit_x ; ...exit_saved_x back as its x...
202C LDA exit_saved_y ; ...and its saved y...
202F STA exit_y ; ...as its y, so the next hero can use it
2032 LDA #0 ; ...and end the animation
2034 STA exit_busy ; ...exit no longer busy
2037 JMP play_level ; Next frame: the descent is over

Start a hero going down the exit

Start hero X's descent: the hero spins on the exit for four turns, shrinking after each of the first three. Called by play_level's check_exit for a hero who has just stepped onto the exit, after drop_key, and after the hero has been taken out of play and the exit hidden off the map.

queue_exit_marker plays the exit sound and puts a nobody_returns marker in returning_hero_queue, as remove_absent_heroes does for a hero nobody plays. Any hero shrunk on an earlier descent (shrunk_hero) gets their full-size sprites back, as the sprites are shared with no copy. Then exit_busy is set, exiting_hero and shrunk_hero become X, exit_spin starts at -1 (the first frame's +2 gives the up-facing sprite) and exit_shrinks_left at 4; play_level's redraw_exit runs the spin from the next frame.

It ends by jumping to play_level rather than returning, so its return address (into check_exit at &1F8E) stays on the stack until the level ends; see play_level.

On EntryXhero number (0-3)
203A .hero_enters_exit←1← 1F8B JSR
STX scratch2 ; Keep the hero number
203D JSR queue_exit_marker ; Sound the exit; mark the hero queue
2040 LDA #4 ; exit_offsets_x entry 0 = 4...
2042 STA exit_offsets_x ; ...never read: shrinks run from 4 down to 1
2045 LDX shrunk_hero ; Restore the sprites of any hero shrunk before
2048 BMI start_hero_animation ; None (&FF): go straight on
204A JSR restore_hero_sprites ; Give that hero back their full-size sprites
204D JMP start_hero_animation ; ...then start this hero's spin

Restore a hero's sprite sizes

Give hero X back their full-size sprites after the exit animation has shrunk them. The descent narrows sprites base + 1 to base + 7 (base from hero_sprites) by a byte and shortens them by three rows after each of three turns, in sprite_widths and sprite_heights themselves. This sets the seven back to a whole cell, 4 bytes wide and 12 rows high, which is what every hero's walking sprites measure. Called by hero_enters_exit, before the next hero's descent shrinks their own sprites, and by play_level when the level ends, each time for shrunk_hero.

On EntryXhero number (0-3)
On ExitA12
Xbase + 1
Ybase + 8
2050 .restore_hero_sprites←2← 1F32 JSR← 204A JSR
CLC ; The hero's sprites base + 1 to base + 7
2051 LDA hero_sprites,x ; ...the hero's sprite base...
2054 ADC #1 ; ...+1: their first sprite...
2056 TAX ; ...in X, kept to restart Y for the heights...
2057 TAY ; ...and in Y, to walk the widths
2058 ADC #7 ; ...+7: stop before base + 8, left frame 1
205A STA scratch ; ...kept as the end
205D LDA #4 ; Widths back to 4 bytes, a whole cell...
205F .restore_sprite_widths←1← 2066 BNE
STA sprite_widths,y ; Sprite Y back to 4 bytes wide
2062 INY ; Next of the seven, base + 1 to base + 7
2063 CPY scratch ; Reached the end?
2066 BNE restore_sprite_widths ; No: widen the next
2068 TXA ; ...from the first sprite again...
2069 TAY ; ...in Y, to walk the heights
206A LDA #&0c ; ...heights back to 12 rows, a whole cell
206C .restore_sprite_heights←1← 2073 BNE
STA sprite_heights,y ; Sprite Y back to 12 rows high
206F INY ; Next of the seven
2070 CPY scratch ; Reached the end?
2073 BNE restore_sprite_heights ; No: restore the next
2075 RTS ; Return with the hero's sprites full size again
; Set up the descent for the hero kept in scratch2.
2076 .start_hero_animation←2← 2048 BMI← 204D JMP
LDA #1 ; Start the animation for this hero...
2078 STA exit_busy ; ...the exit is busy...
207B LDA scratch2 ; ...the hero kept by hero_enters_exit...
207E STA exiting_hero ; ...is the one going down...
2081 STA shrunk_hero ; ...and the one whose sprites will shrink
2084 LDA #&ff ; ...turning from the start...
2086 STA exit_spin ; ...-1, so the first frame's +2 gives 1
2089 LDA #4 ; ...for four turns, shrinking after the first three
208B STA exit_shrinks_left ; ...in exit_shrinks_left, counting turns 4 to 1
208E JMP play_level ; Back to play_level, leaving the JSR's return address

Drop the key a hero carries

Leave hero X's key behind beside the exit, so the heroes still playing can use it. Called by play_level's check_exit as the hero steps onto the exit, before they are taken out of play.

find_open_neighbour picks the first wall-free cell of those above, right of and below the hero, or else the cell to the left whatever it holds; another key or an object may already lie there. The key's key_x/key_y are set to that cell, so update_game's draw_keys shows it from the next frame; hero_key is cleared and the key icon erased from the hero's panel section. A hero with no key moves key entry 0, which is never drawn or picked up.

On EntryXhero number (0-3)
On ExitXpreserved
2091 .drop_key←1← 1F48 JSR
LDA hero_x,x ; From the hero's cell (the exit)...
2094 STA cell_x ; ...is where the search starts: x...
2097 LDA hero_y,x ; ...and the hero's y...
209A STA cell_y ; ...and y
209D TXA ; ...find a wall-free cell next to it
209E PHA ; Keep the hero number...
209F JSR find_open_neighbour ; ...on the stack across the search
20A2 PLA ; Recover the hero number...
20A3 TAX ; ...into X, to find the key they carry
20A4 LDY hero_key,x ; Put the hero's key there (entry 0 if none)
20A7 LDA cell_x ; ...the free cell's x...
20AA STA key_x,y ; ...as the key's x...
20AD LDA cell_y ; ...and its y...
20B0 STA key_y,y ; ...as the key's y
20B3 LDA #0 ; The hero carries no key
20B5 STA hero_key,x ; ...in the hero's key slot
20B8 LDA #spr_blank_key_icon ; Erase the key icon from the hero's panel
20BA STA sprite_number ; ...as the sprite to plot
20BC LDA hero_panel_y,x ; ...from the hero's panel row...
20BF SEC ; ...set carry to subtract
20C0 SBC #&0d ; ...less 13: the key icon's row...
20C2 STA plot_y ; ...as plot_y, the icon's screen row
20C4 LDA #panel_left + 5 ; ...in panel column panel_left + 5...
20C6 STA plot_x ; ...as plot_x, the icon's column
20C8 TXA ; Keep the hero number...
20C9 PHA ; ...on the stack across plot_sprite
20CA JSR plot_sprite ; Plot the blank icon over the key icon
20CD PLA ; Recover the hero number...
20CE TAX ; ...into X, preserved for check_exit
20CF RTS ; Return with the key on the floor beside the exit

Find a free cell next to a cell

Find where drop_key, its only caller, can put down a key next to the exit. Starting from cell_x, cell_y, try the cells above, to the right and below, in that order, through test_wall, and leave cell_x, cell_y on the first without a wall; failing all three, leave them on the cell to the left without testing it, so a key can land in a wall there. Only walls are tested, not keys, objects or creatures. map_ptr is left pointing at the room of the last cell tested.

On EntryCELL_Xcell x
CELL_Ycell y
On ExitCELL_Xx of the first free neighbour, trying above, right and below; otherwise the cell to the left, unchecked
CELL_Yits y
Y0 if a free neighbour was found
Acorrupted
Xcorrupted
20D0 .find_open_neighbour←1← 209F JSR
DEC cell_y ; Try the cell above first
20D3 JSR test_wall ; ...is there a wall in it?
20D6 CPY #0 ; Y = 0 if no wall there
20D8 BNE try_cell_right ; Wall: try the cell to the right
20DA RTS ; No wall: leave cell_x, cell_y on it
20DB .try_cell_right←1← 20D8 BNE
INC cell_y ; Then the cell to the right
20DE INC cell_x ; ...x + 1 (y back to the starting row)
20E1 JSR test_wall ; ...is there a wall in it?
20E4 CPY #0 ; Y = 0 if no wall there
20E6 BNE try_cell_below ; Wall: try the cell below
20E8 RTS ; No wall: leave cell_x, cell_y on it
20E9 .try_cell_below←1← 20E6 BNE
DEC cell_x ; Then the cell below
20EC INC cell_y ; ...y + 1 (x back to the starting column)
20EF JSR test_wall ; ...is there a wall in it?
20F2 CPY #0 ; Y = 0 if no wall there
20F4 BNE try_cell_left ; Wall: fall back on the cell to the left
20F6 RTS ; No wall: leave cell_x, cell_y on it
20F7 .try_cell_left←1← 20F4 BNE
DEC cell_y ; Otherwise the cell to the left
20FA DEC cell_x ; ...x - 1: unchecked, the last resort
20FD RTS ; Return, Y non-zero
20FE EQUB &01, &3F ; Not referenced
; Map of the cells that cannot hold an object, in the same ; layout as room_walls, from the level file: a bit is clear ; where an object lies (and on a few other cells), so the object ; list need only be searched when a hero steps onto a clear bit.
2100 .object_free_map←1Used as index base by← 156D STA
EQUB &00, &02, &07, &07, &1F, &3F, ; Not read: unpack_level &7D, &7F, &00, &30, &78, &FD, ; copies each level's &7F, &FF, &80, &00 ; object-free map here
2110 EQUB &00, &60, &E0, &C0, &DF, &C0, &1F, &0F, &00, &58, &58, &58, &D8, &18, &F8, &80 ; ...entries 16-31, not read
2120 EQUB &76, &3E, &5F, &6E, &7E, &00, &7F, &7F, &00, &66, &66, &7E, &7E, &66, &66, &00 ; ...entries 32-47, not read
2130 EQUB &1F, &1F, &03, &03, &FF, &03, &03, &03, &80, &80, &80, &80, &80, &F6, &FE, &F6 ; ...entries 48-63, not read
2140 EQUB &7F, &00, &3F, &2F, &37, &37, &2F, &37, &C0, &03, &C4, &86, &40, &00, &80, &C1 ; ...entries 64-79, not read
2150 EQUB &03, &E3, &E0, &E1, &41, &41, &00, &FF, &FE, &FE, &00, &00, &00, &00, &00, &8A ; ...entries 80-95, not read
2160 EQUB &00, &00, &00, &00, &7E, &7F, &7E, &00, &01, &01, &01, &3F, &3F, &BF, &3F, &3F ; ...entries 96-111, not read
2170 EQUB &F7, &FF, &C1, &F7, &C1, &FF, &F7, &BF, &8E, &9E, &DE, &9C, &9E, &8E, &8E, &80 ; ...entries 112-127, not read
2180 EQUB &7E, &3E, &7E, &00, &7C, &7A, &7E, &00, &2F, &1F, &00, &00, &00, &CE, &AE, &5E ; ...entries 128-143, not read
2190 EQUB &1F, &1F, &1F, &1B, &17, &1F, &00, &01, &80, &80, &80, &80, &80, &80, &02, &02 ; ...entries 144-159, not read
21A0 EQUB &7E, &7A, &7E, &00, &7E, &3E, &7F, &00, &BE, &0E, &0E, &0F, &0E, &0E, &BE, &00 ; ...entries 160-175, not read
21B0 EQUB &01, &01, &0F, &DF, &07, &03, &01, &00, &08, &08, &5A, &FE, &FE, &FC, &B8, &00 ; ...entries 176-191, not read
21C0 EQUB &00, &00, &00, &00, &00, ; ...entries 192-200, not &00, &00, &00, &00 ; read
21C9 EQUB &08, &2A, &00, &00, &00, &00, &00 ; Not referenced
; Data of sprite &53, &54, &55, &56, &57, &58, &59, &5A, &5B, ; &5C, &5D, &5E: 4 bytes x 12 rows.
21D0 .sprite_drainer
EQUB &11, &33, &33, &22, &33, &33, &33, &33, &33, &FF, &C0, &33, &33, &FF, &C0, &33, &33, &FF, &C0, &33, &33, &FF, &C0, &33, &33, &FF, &C0, &33, &33, &FF, &C0, &33, &33, &FF, &C0, &33, &33, &FF, &C0, &33, &33, &33, &33, &33, &11, &33, &33, &22
; Map x of each door (entries 1-20).
2200 .door_x←4Used as index base by← 152C STA← 1CD8 LDA← 1D8B STA← 77FE LDA
EQUB &FF, &FF, &FF, &04, &FF, &FF, ; Not read: unpack_level &06, &FF, &11, &FF, &FF, &FF, ; copies each level's &1A, &03, &03, &0B ; doors here
2210 EQUB &FF, &03, &09, &12, &FF ; ...entries 16-20, not read
2215 EQUB &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, ; Not &FF, &FF, &FF ; referenced
; Map y of each door.
2220 .door_y←4Used as index base by← 1532 STA← 1CE3 LDA← 1D8E STA← 7804 LDA
EQUB &FF, &FF, &FF, &0D, &FF, &FF, ; Not read: unpack_level &11, &FF, &16, &FF, &FF, &FF, ; copies each level's &1A, &23, &27, &25 ; doors here
2230 EQUB &FF, &2B, &2E, &2B, &FF ; ...entries 16-20, not read
2235 EQUB &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, ; Not &FF, &FF, &FF ; referenced
; Sprite of each door.
2240 .door_sprite←2Used as index base by← 1538 STA← 7810 LDA
EQUB &FF, &1C, &1C, &1D, &1C, &1C, ; Not read: unpack_level &1D, &1D, &1D, &1D, &1D, &1C, ; copies each level's &1C, &1D, &1D, &1C ; door sprites here
2250 EQUB &1D, &1D, &1C, &1C, &FF ; ...entries 16-20, not read
2255 EQUB &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, ; Not &FF, &FF, &FF ; referenced
; Map x of each key lying on the floor (entries 1-20); key n ; opens door n.
2260 .key_x←7Used as index base by← 1543 STA← 1DCE LDA← 1E00 STA← 1E45 LDA← 1E8C STA← 1EA1 STA← 20AA STA
EQUB &13, &FF, &FF, &1B, &FF, &FF, ; Not read: unpack_level &17, &FF, &1C, &FF, &FF, &FF, ; copies each level's &02, &15, &04, &09 ; keys here
2270 EQUB &FF, &04, &19, &17, &FF ; ...entries 16-20, not read
2275 EQUB &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, ; Not &FF, &FF, &FF ; referenced
; Map y of each key on the floor.
2280 .key_y←7Used as index base by← 1549 STA← 1DD4 LDA← 1E06 STA← 1E4D LDA← 1E92 STA← 1EA4 STA← 20B0 STA
EQUB &25, &FF, &FF, &06, &FF, &FF, ; Not read: unpack_level &09, &FF, &18, &FF, &FF, &FF, ; copies each level's &29, &04, &0C, &14 ; keys here
2290 EQUB &FF, &0F, &03, &04, &FF ; ...entries 16-20, not read
2295 EQUB &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, ; Not &FF, &FF, &FF ; referenced
; Data of sprite &51: 4 bytes x 12 rows.
22A0 .sprite_exit
EQUB &03, &03, &03, &03, &02, &00, &00, &01, &02, &00, &00, &01, &02, &00, &00, &01, &02, &00, &00, &01, &02, &00, &00, &01, &02, &00, &00, &01, &02, &00, &00, &01, &02, &00, &00, &01, &02, &00, &00, &01, &02, &00, &00, &01, &03, &03, &03, &03
; Data of sprite &52: 2 bytes x 3 rows.
22D0 .sprite_key_icon
EQUB &00, &05, &0F, &0F, &0F, &05
fall through ↓

Unused

Zero bytes, which nothing reads.

LoadExec
22D6 EQUB &00, &00, &00, &00, &00, ; Zeros &00, &00, &00, &00, &00
; Number of the key each hero carries, or 0.
22E0 .hero_key←10Used as index base by← 159F STA← 1CF2 CMP← 1D95 STA← 1DEB LDA← 1DFA LDY← 1E0B STA← 1E86 LDX← 1E97 STA← 20A4 LDY← 20B5 STA
EQUB &00, &00, &00, &00, &00
; Set when the hero has just swapped keys, so the key ; dropped is not picked straight back up.
22E5 .hero_key_dropped←4Used as index base by← 15A2 STA← 1E28 LDA← 1E2F STA← 1E9C STA
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
; Hero map x, kept for the door and key checks.
22F0 .hero_door_x←4Used as index base by← 1079 LDA← 15A5 STA← 1CC8 LDA← 6F9B STA
EQUB &1A, &09, &00, &16, &00
; Hero map y, kept for the door and key checks.
22F5 .hero_door_y←4Used as index base by← 108A LDA← 15A8 STA← 1CCE LDA← 6FA1 STA
EQUB &06, &1D, &00, &09, &00, &00, &00, &00, &00, &00, &00
; Data of sprite &2D: 4 bytes x 12 rows.
2300 .sprite_magic_user_up_0
EQUB &01, &0A, &00, &00, &03, &0A, &0B, &00, &03, &00, &0B, &02, &03, &00, &00, &03, &03, &00, &0A, &03, &03, &10, &1A, &01, &01, &27, &0F, &23, &01, &33, &33, &23, &01, &13, &33, &00, &03, &13, &33, &00, &03, &03, &22, &00, &03, &03, &00, &00
; Data of sprite &2E: 4 bytes x 12 rows.
2330 .sprite_magic_user_up_1
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &0F, &00, &00, &0F, &03, &00, &0A, &03, &03, &10, &1A, &01, &01, &27, &0F, &23, &01, &33, &33, &23, &01, &13, &33, &03, &00, &13, &33, &03, &00, &03, &23, &03, &00, &01, &01, &03
; Data of sprite &2F: 4 bytes x 12 rows.
2360 .sprite_magic_user_right_0
EQUB &03, &00, &03, &00, &03, &03, &03, &02, &03, &13, &00, &0F, &03, &27, &00, &00, &13, &32, &00, &00, &13, &27, &0A, &00, &13, &27, &0A, &00, &13, &32, &00, &00, &01, &27, &00, &0A, &00, &13, &01, &0A, &00, &03, &03, &0A, &00, &01, &03, &00
; Data of sprite &30: 4 bytes x 12 rows.
2390 .sprite_magic_user_right_1
EQUB &00, &00, &00, &00, &00, &01, &03, &0A, &00, &13, &07, &00, &01, &27, &00, &00, &11, &32, &00, &00, &11, &27, &0A, &00, &13, &27, &0A, &00, &13, &32, &00, &00, &03, &27, &05, &00, &03, &13, &07, &00, &03, &03, &07, &00, &03, &01, &02, &00
; Data of sprite &31: 4 bytes x 12 rows.
23C0 .sprite_magic_user_down_0
EQUB &00, &00, &03, &03, &00, &11, &03, &03, &00, &33, &23, &03, &00, &33, &23, &02, &13, &33, &33, &02, &13, &0F, &1B, &02, &02, &25, &20, &03, &03, &05, &00, &03, &03, &00, &00, &03, &01, &07, &00, &03, &00, &07, &05, &03, &00, &00, &05, &02
; Data of sprite &32: 4 bytes x 12 rows.
23F0 .sprite_magic_user_down_1
EQUB &03, &02, &02, &00, &03, &13, &03, &00, &03, &33, &23, &00, &03, &33, &23, &02, &13, &33, &33, &02, &13, &0F, &1B, &02, &02, &25, &20, &03, &03, &05, &00, &03, &0F, &00, &00, &0F, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
; Data of sprite &33: 4 bytes x 12 rows.
2420 .sprite_magic_user_left_0
EQUB &00, &03, &02, &00, &05, &03, &03, &00, &05, &02, &23, &00, &05, &00, &1B, &02, &00, &00, &31, &23, &00, &05, &1B, &23, &00, &05, &1B, &23, &00, &00, &31, &23, &00, &00, &1B, &03, &0F, &00, &23, &03, &01, &03, &03, &03, &00, &03, &00, &03
; Data of sprite &34: 4 bytes x 12 rows.
2450 .sprite_magic_user_left_1
EQUB &00, &01, &02, &03, &00, &0B, &03, &03, &00, &0B, &23, &03, &00, &0A, &1B, &03, &00, &00, &31, &23, &00, &05, &1B, &23, &00, &05, &1B, &22, &00, &00, &31, &22, &00, &00, &1B, &02, &00, &0B, &23, &00, &05, &03, &02, &00, &00, &00, &00, &00
; Data of sprite &35: 4 bytes x 12 rows.
2480 .sprite_barbarian_up_0
EQUB &00, &00, &3F, &3F, &00, &0F, &05, &0A, &01, &0F, &2D, &1E, &01, &0F, &05, &0A, &0B, &02, &00, &03, &0F, &1A, &20, &0F, &0F, &34, &38, &0F, &0F, &30, &30, &0F, &0F, &34, &38, &0F, &0B, &1A, &25, &07, &05, &03, &0B, &0A, &00, &0B, &07, &00
; Data of sprite &36: 4 bytes x 12 rows.
24B0 .sprite_barbarian_up_1
EQUB &00, &15, &3F, &2A, &05, &0A, &0F, &00, &07, &1E, &0F, &28, &07, &0A, &0F, &00, &03, &02, &01, &02, &0F, &10, &25, &0A, &0F, &34, &38, &0F, &0F, &30, &30, &0F, &0F, &34, &38, &0F, &0F, &12, &21, &0F, &01, &0B, &07, &02, &00, &07, &03, &00
; Data of sprite &37: 4 bytes x 12 rows.
24E0 .sprite_barbarian_right_0
EQUB &00, &0F, &02, &00, &05, &0B, &0F, &0A, &05, &0B, &0F, &0A, &0B, &1A, &05, &0A, &07, &34, &20, &28, &0B, &34, &20, &28, &03, &34, &20, &28, &07, &34, &20, &3D, &0B, &12, &05, &1F, &01, &0F, &07, &1F, &05, &0F, &07, &1F, &00, &0F, &03, &3D
; Data of sprite &38: 4 bytes x 12 rows.
2510 .sprite_barbarian_right_1
EQUB &00, &0F, &02, &28, &05, &0B, &0F, &0A, &05, &0B, &0F, &0A, &03, &1A, &05, &0A, &0B, &34, &20, &28, &03, &34, &20, &3D, &0B, &34, &25, &1F, &07, &34, &25, &1F, &0B, &1A, &07, &1F, &05, &0F, &07, &15, &05, &0F, &03, &00, &00, &0F, &00, &00
; Data of sprite &39: 4 bytes x 12 rows.
2540 .sprite_barbarian_down_0
EQUB &00, &0B, &07, &00, &05, &07, &03, &0A, &0B, &1A, &25, &07, &0F, &34, &38, &0F, &0F, &30, &30, &0F, &0F, &34, &38, &0F, &0F, &10, &25, &0F, &03, &00, &01, &07, &05, &0A, &0F, &02, &2D, &1E, &0F, &02, &05, &0A, &0F, &00, &3F, &3F, &00, &00
; Data of sprite &3A: 4 bytes x 12 rows.
2570 .sprite_barbarian_down_1
EQUB &00, &03, &0B, &00, &01, &0B, &07, &02, &0F, &12, &21, &0F, &0F, &34, &38, &0F, &0F, &30, &30, &0F, &0F, &34, &38, &0F, &05, &1A, &20, &0F, &01, &02, &01, &03, &00, &0F, &05, &0B, &14, &0F, &2D, &0B, &00, &0F, &05, &0A, &15, &3F, &2A, &00
; Data of sprite &3B: 4 bytes x 12 rows.
25A0 .sprite_barbarian_left_0
EQUB &3E, &03, &0F, &00, &2F, &0B, &0F, &0A, &2F, &0B, &0F, &02, &2F, &0A, &21, &07, &3E, &10, &38, &0B, &14, &10, &38, &03, &14, &10, &38, &07, &14, &10, &38, &0B, &05, &0A, &25, &07, &05, &0F, &07, &0A, &05, &0F, &07, &0A, &00, &01, &0F, &00
; Data of sprite &3C: 4 bytes x 12 rows.
25D0 .sprite_barbarian_left_1
EQUB &00, &00, &0F, &00, &00, &03, &0F, &0A, &2A, &0B, &0F, &0A, &2F, &0B, &25, &07, &2F, &1A, &38, &0B, &2F, &1A, &38, &07, &3E, &10, &38, &03, &14, &10, &38, &07, &05, &0A, &25, &03, &05, &0F, &07, &0A, &05, &0F, &07, &0A, &14, &01, &0F, &00
; Data of sprite &3D: 4 bytes x 12 rows.
2600 .sprite_fighter_up_0
EQUB &00, &15, &00, &00, &00, &00, &2A, &00, &28, &0A, &15, &00, &2D, &0E, &00, &2B, &39, &0E, &00, &03, &39, &26, &0A, &33, &39, &23, &0B, &33, &39, &27, &0F, &33, &00, &36, &3C, &22, &00, &3E, &3C, &2A, &15, &00, &0C, &15, &00, &00, &0C, &00
; Data of sprite &3E: 4 bytes x 12 rows.
2630 .sprite_fighter_up_1
EQUB &00, &28, &00, &15, &00, &28, &00, &15, &14, &00, &00, &15, &14, &27, &04, &1D, &39, &27, &04, &1D, &39, &22, &0E, &1D, &11, &32, &1A, &03, &00, &27, &0F, &33, &00, &36, &3C, &33, &00, &3E, &3C, &2A, &15, &04, &08, &15, &00, &04, &08, &00
; Data of sprite &3F: 4 bytes x 12 rows.
2660 .sprite_fighter_right_0
EQUB &00, &3C, &3C, &28, &00, &11, &22, &00, &2A, &33, &27, &0A, &15, &39, &05, &00, &14, &06, &08, &00, &14, &0F, &08, &00, &14, &0F, &00, &00, &1C, &02, &00, &15, &1D, &28, &00, &2A, &3B, &33, &17, &00, &00, &33, &0A, &00, &00, &01, &0A, &00
; Data of sprite &40: 4 bytes x 12 rows.
2690 .sprite_fighter_right_1
EQUB &00, &00, &28, &00, &2A, &33, &36, &00, &15, &39, &33, &28, &1C, &02, &11, &1E, &1C, &0F, &00, &0A, &14, &0F, &00, &00, &14, &02, &00, &00, &15, &2C, &08, &00, &3B, &26, &08, &00, &11, &23, &00, &00, &11, &23, &3F, &3F, &00, &00, &00, &00
; Data of sprite &41: 4 bytes x 12 rows.
26C0 .sprite_fighter_down_0
EQUB &00, &0C, &00, &00, &2A, &0C, &00, &2A, &15, &3C, &3D, &00, &11, &3C, &39, &00, &33, &0F, &1B, &36, &33, &07, &13, &36, &33, &05, &19, &36, &03, &00, &0D, &36, &17, &00, &0D, &1E, &00, &2A, &05, &14, &00, &15, &00, &00, &00, &00, &2A, &00
; Data of sprite &42: 4 bytes x 12 rows.
26F0 .sprite_fighter_down_1
EQUB &00, &04, &08, &00, &2A, &04, &08, &2A, &15, &3C, &3D, &00, &33, &3C, &39, &00, &33, &0F, &1B, &00, &03, &25, &31, &22, &2E, &0D, &11, &36, &2E, &08, &1B, &36, &2E, &08, &1B, &28, &2A, &00, &00, &28, &2A, &00, &14, &00, &2A, &00, &14, &00
; Data of sprite &43: 4 bytes x 12 rows.
2720 .sprite_fighter_left_0
EQUB &00, &05, &02, &00, &00, &05, &33, &00, &00, &2B, &33, &37, &15, &00, &14, &2E, &2A, &00, &01, &2C, &00, &00, &0F, &28, &00, &04, &0F, &28, &00, &04, &09, &28, &00, &0A, &36, &2A, &05, &1B, &33, &15, &00, &11, &22, &00, &14, &3C, &3C, &00
; Data of sprite &44: 4 bytes x 12 rows.
2750 .sprite_fighter_left_1
EQUB &3F, &3F, &13, &22, &00, &00, &13, &22, &00, &04, &19, &37, &00, &04, &1C, &2A, &00, &00, &01, &28, &00, &00, &0F, &28, &05, &00, &0F, &2C, &2D, &22, &01, &2C, &14, &33, &36, &2A, &00, &39, &33, &15, &00, &14, &00, &00, &00, &00, &00, &00
; Data of sprite &45: 4 bytes x 12 rows.
2780 .sprite_fireball_up
EQUB &00, &00, &0A, &00, &00, &01, &03, &00, &00, &05, &07, &00, &00, &01, &0B, &00, &00, &05, &07, &00, &00, &05, &07, &00, &00, &05, &0F, &00, &00, &00, &0A, &00, &00, &00, &0A, &00, &00, &00, &0A, &00, &00, &00, &0A, &00, &00, &00, &0A, &00
; Data of sprite &46: 4 bytes x 12 rows.
27B0 .sprite_fireball_right
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &05, &0A, &00, &0F, &0B, &07, &0F, &0B, &07, &07, &00, &0F, &0B, &07, &00, &00, &05, &0A, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
; Data of sprite &47: 4 bytes x 12 rows.
27E0 .sprite_fireball_down
EQUB &00, &00, &0A, &00, &00, &00, &0A, &00, &00, &00, &0A, &00, &00, &00, &0A, &00, &00, &00, &0A, &00, &00, &05, &0F, &00, &00, &05, &07, &00, &00, &05, &07, &00, &00, &01, &0B, &00, &00, &05, &07, &00, &00, &01, &03, &00, &00, &00, &0A, &00
; Data of sprite &48: 4 bytes x 12 rows.
2810 .sprite_fireball_left
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &05, &0A, &00, &00, &0B, &07, &0F, &00, &0B, &0B, &07, &0F, &0B, &07, &0F, &00, &05, &0A, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
; Data of sprite &4D: 4 bytes x 12 rows.
2840 .sprite_axe_up
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &15, &2A, &00, &00, &3F, &3F, &00, &00, &15, &2A, &14, &3C, &3C, &3C, &00, &00, &15, &2A, &00, &00, &3F, &3F, &00, &00, &15, &2A, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
; Data of sprite &4E: 4 bytes x 12 rows.
2870 .sprite_axe_right
EQUB &00, &00, &00, &00, &00, &14, &00, &00, &00, &14, &00, &00, &00, &14, &00, &00, &00, &14, &00, &00, &15, &14, &15, &00, &15, &3E, &3F, &00, &15, &3E, &3F, &00, &15, &3E, &3F, &00, &15, &14, &15, &00, &00, &00, &00, &00, &00, &00, &00, &00
; Data of sprite &4F: 4 bytes x 12 rows.
28A0 .sprite_axe_down
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &15, &2A, &00, &00, &3F, &3F, &00, &00, &15, &2A, &00, &00, &3C, &3C, &3C, &28, &15, &2A, &00, &00, &3F, &3F, &00, &00, &15, &2A, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
; Data of sprite &50: 4 bytes x 12 rows.
28D0 .sprite_axe_left
EQUB &00, &00, &00, &00, &00, &2A, &28, &2A, &00, &3F, &3D, &2A, &00, &3F, &3D, &2A, &00, &3F, &3D, &2A, &00, &2A, &28, &2A, &00, &00, &28, &00, &00, &00, &28, &00, &00, &00, &28, &00, &00, &00, &28, &00, &00, &00, &00, &00, &00, &00, &00, &00
; Data of sprite &1B: 4 bytes x 12 rows.
2900 .sprite_key
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &0A, &00, &00, &05, &05, &00, &00, &05, &05, &0F, &0F, &0F, &05, &0A, &0A, &05, &05, &0A, &0A, &05, &05, &0A, &0A, &00, &0A, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
; Data of sprite &28: 4 bytes x 12 rows.
2930 .sprite_treasure
EQUB &03, &03, &02, &02, &13, &50, &02, &02, &02, &24, &17, &03, &47, &00, &02, &03, &12, &0D, &02, &03, &02, &4F, &02, &03, &06, &32, &02, &03, &47, &02, &02, &03, &12, &A5, &02, &03, &07, &08, &17, &03, &06, &B0, &02, &02, &03, &03, &02, &02
; Data of sprite &29: 4 bytes x 12 rows.
2960 .sprite_food
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &2A, &00, &00, &00, &2A, &00, &00, &00, &15, &00, &00, &00, &2F, &2A, &0F, &00, &2F, &0F, &0F, &0A, &00, &0F, &03, &0B, &00, &05, &0F, &03, &00, &05, &07, &02, &00, &00, &03, &02, &00, &00, &03, &00
2990 EQUB &05, &0F, &0F, &00, &0A, &0F, &0F, &0A, ; Not &0A, &00, &05, &00, &05, &30, &20, &0A, ; refere &05, &00, &00, &0A, &00, &1A, &30, &05, ; nced &00, &0A, &00, &05, &0F, &1A, &30, &25, &0F, &00, &00, &0A, &0A, &30, &30, &0A, &05, &00, &00, &0A, &00, &0F, &0F, &00
; Data of sprite &2B: 4 bytes x 12 rows.
29C0 .sprite_teleporter
EQUB &3F, &3F, &3F, &3F, &3E, &3C, &3C, &38, &3E, &3C, &3C, &38, &3E, &3F, &3F, &38, &3E, &3E, &38, &38, &3E, &3E, &38, &38, &3E, &3E, &38, &38, &3E, &3E, &38, &38, &3E, &30, &30, &38, &3E, &3C, &3C, &38, &3E, &3C, &3C, &38, &30, &30, &30, &30
29F0 EQUB &00, &2C, &00, &00, &00, &2C, &08, &00, &00, &0C, &08, &00, &04, &0F, &0E, &00 ; Not referenced
; Data of sprite &1E: 2 bytes x 10 rows.
2A00 .sprite_digit_0
EQUB &04, &08, &08, &0C, &08, &0C, &08, &0C, &08, &0C, &0C, &04, &0C, &04, &0C, &04, &0C, &04, &04, &08
; Data of sprite &1F: 2 bytes x 10 rows.
2A14 .sprite_digit_1
EQUB &04, &00, &0C, &00, &04, &00, &04, &00, &04, &00, &04, &00, &04, &00, &04, &00, &04, &00, &0C, &00
; Data of sprite &20: 2 bytes x 10 rows.
2A28 .sprite_digit_2
EQUB &04, &08, &08, &04, &08, &04, &00, &04, &00, &08, &04, &00, &08, &00, &08, &04, &08, &08, &0C, &0C
; Data of sprite &21: 2 bytes x 10 rows.
2A3C .sprite_digit_3
EQUB &04, &08, &08, &04, &00, &04, &00, &04, &04, &08, &04, &08, &00, &04, &00, &04, &0C, &04, &04, &08
; Data of sprite &22: 2 bytes x 10 rows.
2A50 .sprite_digit_4
EQUB &00, &08, &04, &08, &04, &08, &08, &08, &08, &0C, &0C, &08, &00, &0C, &00, &08, &00, &08, &04, &08
; Data of sprite &23: 2 bytes x 10 rows.
2A64 .sprite_digit_5
EQUB &0C, &0C, &08, &04, &08, &00, &08, &00, &04, &00, &00, &08, &00, &04, &04, &04, &08, &04, &04, &08
; Data of sprite &24: 2 bytes x 10 rows.
2A78 .sprite_digit_6
EQUB &00, &04, &00, &08, &04, &00, &04, &00, &04, &08, &08, &04, &08, &04, &08, &04, &08, &04, &04, &08
; Data of sprite &25: 2 bytes x 10 rows.
2A8C .sprite_digit_7
EQUB &0C, &0C, &00, &04, &00, &08, &00, &08, &00, &08, &04, &00, &04, &00, &04, &00, &04, &00, &0C, &08
; Data of sprite &26: 2 bytes x 10 rows.
2AA0 .sprite_digit_8
EQUB &04, &08, &08, &04, &08, &04, &08, &04, &04, &08, &08, &04, &08, &04, &08, &04, &08, &04, &04, &08
; Data of sprite &27: 2 bytes x 10 rows.
2AB4 .sprite_digit_9
EQUB &04, &08, &08, &04, &08, &04, &08, &04, &08, &04, &04, &08, &00, &08, &00, &08, &04, &00, &08, &00
; Data of sprite &1D: 4 bytes x 12 rows.
2AC8 .sprite_door_horizontal
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &3F, &3F, &3F, &3F, &3E, &3C, &3C, &38, &3E, &3C, &3C, &38, &3E, &3C, &3C, &38, &3E, &3C, &3C, &38, &30, &30, &30, &30, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
2AF8 EQUB &0F, &1A, &30, &20, &00, &00, &00, ; Not &25 ; referenced
; Data of sprite &16: 4 bytes x 12 rows.
2B00 .sprite_sparkle_0
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &15, &2A, &00, &00, &3F, &3F, &00, &00, &3F, &3F, &00, &00, &15, &2A, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
; Data of sprite &17: 4 bytes x 12 rows.
2B30 .sprite_sparkle_1
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &3F, &3F, &00, &00, &00, &00, &00, &15, &15, &2A, &2A, &15, &00, &00, &2A, &15, &00, &00, &2A, &15, &15, &2A, &2A, &00, &00, &00, &00, &00, &3F, &3F, &00, &00, &00, &00, &00, &00, &00, &00, &00
; Data of sprite &18: 4 bytes x 12 rows.
2B60 .sprite_sparkle_2
EQUB &00, &00, &00, &00, &15, &3F, &3F, &2A, &00, &3F, &3F, &00, &2A, &00, &00, &15, &3F, &00, &00, &3F, &3F, &15, &2A, &3F, &3F, &15, &2A, &3F, &3F, &00, &00, &3F, &2A, &00, &00, &15, &00, &3F, &3F, &00, &15, &3F, &3F, &2A, &00, &00, &00, &00
; Data of sprite &19: 4 bytes x 12 rows.
2B90 .sprite_sparkle_3
EQUB &3F, &00, &00, &3F, &3F, &2A, &15, &3F, &2A, &2A, &15, &15, &2A, &00, &00, &15, &3F, &15, &2A, &3F, &15, &2A, &15, &2A, &15, &2A, &15, &2A, &3F, &15, &2A, &3F, &2A, &00, &00, &15, &2A, &2A, &15, &15, &3F, &2A, &15, &3F, &3F, &00, &00, &3F
; Data of sprite &2C: 4 bytes x 12 rows.
2BC0 .sprite_trapdoor
EQUB &3C, &3C, &3C, &3C, &29, &03, &03, &16, &3F, &12, &03, &16, &3F, &03, &03, &34, &29, &03, &21, &16, &29, &03, &03, &16, &29, &21, &21, &16, &29, &03, &03, &34, &3F, &03, &21, &16, &3F, &03, &03, &16, &29, &21, &12, &16, &3C, &3C, &3C, &3C
2BF0 EQUB &00, &00, &00, &00, &04, &00, &00, &00, &20, &00, &00, &00, &FD, &14, &93, &00 ; Not referenced
; Data of sprite &11: 4 bytes x 12 rows.
2C00 .sprite_arrow_up
EQUB &00, &00, &00, &00, &00, &15, &00, &00, &00, &15, &00, &00, &00, &05, &00, &00, &00, &05, &00, &00, &00, &05, &00, &00, &00, &05, &00, &00, &00, &05, &00, &00, &00, &05, &00, &00, &00, &0C, &08, &00, &00, &08, &08, &00, &00, &00, &00, &00
; Data of sprite &12: 4 bytes x 12 rows.
2C30 .sprite_arrow_right
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &0C, &00, &00, &00, &04, &0F, &0F, &2A, &0C, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
; Data of sprite &13: 4 bytes x 12 rows.
2C60 .sprite_arrow_down
EQUB &00, &00, &00, &00, &00, &04, &04, &00, &00, &04, &0C, &00, &00, &00, &0A, &00, &00, &00, &0A, &00, &00, &00, &0A, &00, &00, &00, &0A, &00, &00, &00, &0A, &00, &00, &00, &0A, &00, &00, &00, &2A, &00, &00, &00, &2A, &00, &00, &00, &00, &00
; Data of sprite &14: 4 bytes x 12 rows.
2C90 .sprite_arrow_left
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &0C, &15, &0F, &0F, &08, &00, &00, &00, &0C, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
; Data of sprite &1C: 4 bytes x 12 rows.
2CC0 .sprite_door_vertical
EQUB &00, &3F, &3A, &00, &00, &3E, &38, &00, &00, &3E, &38, &00, &00, &3E, &38, &00, &00, &3E, &38, &00, &00, &3E, &38, &00, &00, &3E, &38, &00, &00, &3E, &38, &00, &00, &3E, &38, &00, &00, &3E, &38, &00, &00, &3E, &38, &00, &00, &30, &30, &00
2CF0 EQUB &01, &00, &00, &00, &17, &00, &00, &90, &17, &00, &00, &00, &00, &00, &00, &00 ; Not referenced
; Data of sprite 0, the wall block (4 bytes x 12 rows), ; replaced by each level's own from the level file.
2D00 .wall_sprite←1Used as index base by← 157A STA
EQUB &0F, &0B, &0F, &07, &03, &0F, &0F, &0F, &0F, &1F, &2F, &0B, &0F, &2F, &0B, &0F, &1F, &0F, &0F, &07, &1F, &1F, &0F, &07, &17, &0F, &07, &07, &1F, &0F, &0F, &07, &0F, &2F, &0B, &0F, &07, &0B, &07, &0F, &0F, &0F, &0F, &03, &0B, &0F, &0F, &0F
; Data of sprite &01: 4 bytes x 12 rows.
2D30 .sprite_ranger_up_0
EQUB &00, &03, &0B, &00, &01, &00, &0A, &02, &02, &00, &04, &01, &01, &02, &04, &00, &0B, &02, &00, &08, &0B, &07, &00, &08, &1C, &25, &34, &08, &1C, &0F, &1E, &08, &04, &3C, &29, &08, &04, &3C, &0C, &00, &00, &0C, &09, &00, &00, &00, &03, &00
; Data of sprite &02: 4 bytes x 12 rows.
2D60 .sprite_ranger_up_1
EQUB &00, &03, &02, &00, &00, &00, &01, &00, &00, &00, &00, &0A, &05, &00, &03, &0A, &05, &00, &03, &09, &04, &05, &03, &09, &0C, &25, &34, &09, &1C, &0F, &1E, &09, &04, &3C, &28, &08, &04, &3C, &0C, &00, &01, &0C, &08, &00, &01, &02, &00, &00
; Data of sprite &03: 4 bytes x 12 rows.
2D90 .sprite_ranger_right_0
EQUB &00, &04, &0B, &00, &00, &0C, &0B, &00, &04, &09, &02, &02, &04, &3C, &02, &03, &14, &1A, &02, &01, &3C, &0F, &0A, &01, &3C, &0F, &0A, &0D, &16, &1A, &04, &0D, &03, &3C, &0C, &03, &03, &06, &08, &02, &00, &00, &01, &00, &00, &00, &01, &00
; Data of sprite &04: 4 bytes x 12 rows.
2DC0 .sprite_ranger_right_1
EQUB &00, &00, &08, &00, &00, &0C, &0D, &00, &06, &0C, &05, &00, &06, &3C, &00, &00, &16, &1A, &00, &01, &3C, &0F, &0A, &01, &3C, &0F, &0A, &01, &14, &1A, &03, &01, &00, &3C, &09, &03, &00, &0C, &0D, &02, &00, &04, &07, &02, &00, &03, &02, &00
; Data of sprite &05: 4 bytes x 12 rows.
2DF0 .sprite_ranger_down_0
EQUB &00, &03, &00, &00, &00, &06, &0C, &00, &00, &0C, &3C, &08, &04, &16, &3C, &08, &04, &2D, &0F, &2C, &04, &38, &1A, &2C, &04, &00, &0B, &07, &04, &00, &01, &07, &00, &08, &01, &02, &02, &08, &00, &01, &01, &05, &00, &02, &00, &07, &03, &00
; Data of sprite &06: 4 bytes x 12 rows.
2E20 .sprite_ranger_down_1
EQUB &00, &00, &01, &02, &00, &04, &0C, &02, &00, &0C, &3C, &08, &04, &14, &3C, &08, &06, &2D, &0F, &2C, &06, &38, &1A, &0C, &06, &03, &0A, &08, &06, &03, &00, &0A, &05, &03, &00, &0A, &05, &00, &00, &00, &00, &02, &00, &00, &00, &01, &03, &00
; Data of sprite &07: 4 bytes x 12 rows.
2E50 .sprite_ranger_left_0
EQUB &00, &02, &00, &00, &00, &02, &00, &00, &01, &04, &09, &03, &03, &0C, &3C, &03, &0E, &08, &25, &29, &0E, &05, &0F, &3C, &02, &05, &0F, &3C, &02, &01, &25, &28, &03, &01, &3C, &08, &01, &01, &06, &08, &00, &07, &0C, &00, &00, &07, &08, &00
; Data of sprite &09: 4 bytes x 12 rows.
2E80 .sprite_monster_up_0
EQUB &00, &00, &00, &02, &00, &00, &01, &13, &04, &08, &01, &13, &45, &30, &8B, &13, &10, &30, &20, &02, &1A, &30, &20, &02, &1A, &30, &25, &07, &1E, &30, &2D, &0F, &3C, &3C, &2D, &0A, &14, &3C, &2C, &00, &00, &00, &0C, &00, &00, &00, &0C, &00
; Data of sprite &0A: 4 bytes x 12 rows.
2EB0 .sprite_monster_up_1
EQUB &00, &04, &08, &00, &00, &04, &08, &02, &45, &30, &8B, &13, &10, &30, &21, &13, &10, &30, &21, &13, &1A, &30, &20, &02, &0F, &30, &00, &02, &1E, &3C, &2D, &07, &1E, &3C, &2D, &0F, &14, &3C, &2D, &0A, &04, &08, &00, &00, &04, &08, &00, &00
; Data of sprite &0B: 4 bytes x 12 rows.
2EE0 .sprite_monster_right_0
EQUB &00, &2D, &0A, &00, &14, &2D, &00, &00, &14, &38, &8E, &08, &14, &30, &24, &08, &14, &30, &24, &08, &14, &30, &20, &00, &1C, &30, &20, &00, &1C, &38, &8A, &00, &0C, &28, &00, &00, &00, &3C, &01, &02, &00, &0F, &03, &03, &00, &0F, &11, &22
; Data of sprite &0C: 4 bytes x 12 rows.
2F10 .sprite_monster_right_1
EQUB &00, &2D, &0A, &00, &14, &2D, &00, &00, &1C, &38, &8A, &00, &1C, &30, &20, &00, &1C, &30, &20, &00, &14, &30, &24, &08, &3C, &30, &24, &08, &3C, &10, &8E, &08, &0F, &00, &00, &00, &0F, &01, &02, &00, &0B, &03, &03, &00, &00, &11, &22, &00
; Data of sprite &0D: 4 bytes x 12 rows.
2F40 .sprite_monster_down_0
EQUB &00, &0C, &00, &00, &00, &0C, &00, &00, &00, &1C, &3C, &28, &05, &1E, &3C, &3C, &0F, &1E, &30, &2D, &0B, &1A, &30, &25, &01, &10, &30, &25, &01, &10, &30, &20, &23, &47, &30, &8A, &23, &02, &04, &08, &23, &02, &00, &00, &01, &00, &00, &00
; Data of sprite &0E: 4 bytes x 12 rows.
2F70 .sprite_monster_down_1
EQUB &00, &00, &04, &08, &00, &00, &04, &08, &05, &1E, &3C, &28, &0F, &1E, &3C, &2D, &0B, &1E, &3C, &2D, &01, &00, &30, &0F, &01, &10, &30, &25, &23, &12, &30, &20, &23, &12, &30, &20, &23, &47, &30, &8A, &01, &04, &08, &00, &00, &04, &08, &00
; Data of sprite &0F: 4 bytes x 12 rows.
2FA0 .sprite_monster_left_0
EQUB &11, &22, &0F, &00, &03, &03, &0F, &00, &01, &02, &3C, &00, &00, &00, &14, &0C, &00, &45, &34, &2C, &00, &10, &30, &2C, &00, &10, &30, &28, &04, &18, &30, &28, &04, &18, &30, &28, &04, &4D, &34, &28, &00, &00, &1E, &28, &00, &05, &1E, &00
; Data of sprite &10: 4 bytes x 12 rows.
2FD0 .sprite_monster_left_1
EQUB &00, &11, &22, &00, &00, &03, &03, &07, &00, &01, &02, &0F, &00, &00, &00, &0F, &04, &4D, &20, &3C, &04, &18, &30, &3C, &04, &18, &30, &28, &00, &10, &30, &2C, &00, &10, &30, &2C, &00, &45, &34, &2C, &00, &00, &1E, &28, &00, &05, &1E, &00
3000 08C0 EQUB &80, &05, &05, &05, &05, &05, &05, &80, &00, &00, &F6, &80, &80, &00, &00, &00, &01, &F6, &F6, &F6, &03, &03, &03, &64, &FD, &00, &F9, &80, &14, &00, &00, &00, &80, &00, &00, &00, &01, &1E, &1E, &80, &00, &00, &FE, &80, &80, &00, &00, &00, &01, &14, &0A, &05, &02, &02, &02, &01, &00, &00, &FF, &80, &80, &00, &00, &00 ; Not referenced

Plot a sprite

Copy sprite sprite_number to the screen with its top-left corner at byte column plot_x, pixel row plot_y.

The four sprite tables, indexed by sprite number, give the address of its data and its size: sprite_width bytes across (two MODE 2 pixels to a byte) by sprite_height pixel rows. The data is stored row by row and is written over the screen contents without masking, so a sprite's black pixels erase what was there, and there is no clipping. The screen is laid out like MODE 2 with 640-byte character rows from &3000, so successive bytes of a sprite row are 8 bytes apart, and each pixel row starts one byte below the last, or 640-7 bytes on when it crosses into the next character row. screen_ptr walks across each row, row_start_ptr remembers where the row began, and sprite_data_ptr walks through the data; Y stays 0. sprite_width and sprite_height are left holding the sprite's size.

On EntryPLOT_Xscreen byte column (0-79)
PLOT_Ypixel row
SPRITE_NUMBERsprite to plot
On ExitAcorrupted
X0
Y0
LoadExec
3040 0900 .plot_sprite←22← 042E JSR (low_joystick)← 042E JSR (low_keyboard)← 043D JSR (low_joystick)← 043D JSR (low_keyboard)← 0F79 JSR← 1DAA JSR← 1E20 JSR← 1E7D JSR← 20CA JSR← 7276 JSR← 7286 JSR← 72CF JSR← 72DF JSR← 72EF JSR← 72FF JSR← 7613 JSR← 7838 JSR← 7842 JSR← 78AA JSR← 78C4 JSR← 78DE JSR← 78F8 JSR
LDX sprite_number ; X = sprite number, indexing the four sprite tables
3042 0902 LDA sprite_addr_lo,x ; Point sprite_data_ptr at the sprite's data...
3045 0905 STA sprite_data_ptr ; ...its low byte from sprite_addr_lo
3047 0907 LDA sprite_addr_hi,x ; ...high byte from its own table
304A 090A STA sprite_data_ptr_hi ; ...so sprite_data_ptr walks through the data
304C 090C LDA sprite_widths,x ; Bytes in each sprite row...
304F 090F STA sprite_width ; ...counted across each row
3051 0911 LDA sprite_heights,x ; Pixel rows in the sprite...
3054 0914 STA sprite_height ; ...counted down the sprite
3056 0916 JSR screen_address ; screen_ptr = address of the top-left byte
3059 0919 LDY #0 ; Index stays 0: the pointers themselves advance
305B 091B LDX sprite_height ; X counts the pixel rows still to plot
305D 091D .plot_sprite_row←1← 0964 BNE
LDA screen_ptr ; Remember where this pixel row starts...
305F 091F STA row_start_ptr ; ...its low byte...
3061 0921 LDA screen_ptr_hi ; ...and its high byte...
3063 0923 STA row_start_ptr_hi ; ...in row_start_ptr, to step down from later
3065 0925 TXA ; Save the row count
3066 0926 PHA ; ...on the stack: X now counts bytes
3067 0927 LDX sprite_width ; X counts the bytes across this row
3069 0929 .plot_sprite_byte←1← 093F BNE
LDA (sprite_data_ptr),y ; Copy one sprite byte...
306B 092B STA (screen_ptr),y ; ...to the screen, over whatever was there
306D 092D CLC ; Step screen_ptr right one byte column: 8 bytes on
306E 092E LDA screen_ptr ; ...the screen address's low byte...
3070 0930 ADC #8 ; ...+ 8, the next byte column...
3072 0932 STA screen_ptr ; ...as screen_ptr's new low byte
3074 0934 BCC plot_sprite_next_data ; No carry: the high byte stands
3076 0936 INC screen_ptr_hi ; ...with carry into the high byte
3078 0938 .plot_sprite_next_data←1← 0934 BCC
INC sprite_data_ptr ; Next sprite data byte
307A 093A BNE plot_sprite_count_byte ; No carry: the high byte stands
307C 093C INC sprite_data_ptr_hi ; ...with carry into the high byte
307E 093E .plot_sprite_count_byte←1← 093A BNE
DEX ; One byte fewer left in this row
307F 093F BNE plot_sprite_byte ; More of the row: plot the next byte
3081 0941 CLC ; screen_ptr = row start + 1: the next pixel row down
3082 0942 LDA row_start_ptr ; The row start's low byte...
3084 0944 ADC #1 ; ...+ 1, one pixel row lower...
3086 0946 STA screen_ptr ; ...is the new low byte
3088 0948 LDA row_start_ptr_hi ; The row start's high byte...
308A 094A ADC #0 ; ...plus the carry...
308C 094C STA screen_ptr_hi ; ...is the new high byte
308E 094E LDA screen_ptr ; Has it crossed into the next character row?
3090 0950 AND #7 ; ...(pixel row within the character now 0)
3092 0952 BNE plot_sprite_next_row ; No: still within the character row
3094 0954 CLC ; Yes: add &278 more, to the top of the character...
3095 0955 LDA screen_ptr ; ...row below (row start + 1 + &278 = + 640 - 7)
3097 0957 ADC #&78 ; ...low byte + &78 (640 - 8 = &278)...
3099 0959 STA screen_ptr ; ...as screen_ptr's low byte
309B 095B LDA screen_ptr_hi ; ...then the high byte...
309D 095D ADC #2 ; ...+ 2 and the carry...
309F 095F STA screen_ptr_hi ; ...as screen_ptr's high byte: the row below
30A1 0961 .plot_sprite_next_row←1← 0952 BNE
PLA ; Recover the row count
30A2 0962 TAX ; ...back into X
30A3 0963 DEX ; One pixel row fewer to plot
30A4 0964 BNE plot_sprite_row ; More rows: plot the next
30A6 0966 RTS ; Return: the sprite is on the screen

Calculate a screen address

Set screen_ptr to the screen address of byte column plot_x on pixel row plot_y: &3000 + 640 x (plot_y DIV 8) + (plot_y MOD 8) + 8 x plot_x. plot_sprite calls it once per sprite, for the top-left byte. The multiplication by 640 is done with a table inside MOS 1.20 (mos_row_offsets, two bytes per character row, high byte first), so this only works with that MOS. The high byte of 8 x plot_x is plot_x DIV 32, taken from plot_x's top three bits with four ROLs.

On EntryPLOT_Xscreen byte column (0-79)
PLOT_Ypixel row
On ExitSCREEN_PTRscreen address
Acorrupted
Ycorrupted
Xpreserved
LoadExec
30A7 0967 .screen_address←1← 0916 JSR
LDA plot_y ; Table index = 2 x (plot_y DIV 8), the character row...
30A9 0969 LSR ; ...plot_y DIV 2...
30AA 096A LSR ; ...plot_y DIV 4: 2 x the character row, + plot_y bit 2...
30AB 096B AND #&fe ; ...bit 0 cleared: the row's pair of table bytes
30AD 096D TAY ; ...as the index into the row table
30AE 096E LDA mos_row_offsets,y ; High byte of row x 640, from the MOS table...
30B1 0971 CLC ; ...(carry clear for the add)
30B2 0972 ADC #>(screen_start) ; ...plus &30: the screen starts at &3000
30B4 0974 STA screen_ptr_hi ; ...as the screen address high byte
30B6 0976 LDA mos_row_offsets_lo,y ; Low byte of row x 640
30B9 0979 STA screen_ptr ; ...as the low byte
30BB 097B LDA plot_y ; Add the pixel row within the character...
30BD 097D AND #7 ; ...plot_y MOD 8...
30BF 097F ADC screen_ptr ; ...(carry clear: adding &30 to the high byte cannot carry)
30C1 0981 STA screen_ptr ; ...stored in the low byte
30C3 0983 CLC ; Add 8 x plot_x: its high byte is plot_x DIV 32...
30C4 0984 LDA plot_x ; ...taking the byte column...
30C6 0986 AND #&e0 ; ...bits 7-5 kept...
30C8 0988 ROL ; ...four ROLs through the carry: bit 7 out...
30C9 0989 ROL ; ...bit 7 in at bit 0, bit 6 out
30CA 098A ROL ; ...bits 7-6 at bits 1-0, bit 5 out
30CB 098B ROL ; ...bits 7-5 now in bits 2-0
30CC 098C CLC ; ...(carry clear for the add)
30CD 098D ADC screen_ptr_hi ; ...added to the high byte
30CF 098F STA screen_ptr_hi ; ...as screen_ptr's high byte
30D1 0991 LDA plot_x ; Low byte + (plot_x x 8) AND &FF: plot_x...
30D3 0993 ASL ; ...x 2...
30D4 0994 ASL ; ...x 4...
30D5 0995 ASL ; ...x 8, its top bits dropping out
30D6 0996 CLC ; ...(carry clear for the add)
30D7 0997 ADC screen_ptr ; ...added to the low byte
30D9 0999 STA screen_ptr ; ...as screen_ptr's low byte
30DB 099B BCC screen_address_done ; No carry: done
30DD 099D INC screen_ptr_hi ; ...with carry into the high byte
30DF 099F .screen_address_done←1← 099B BCC
RTS ; Return with screen_ptr set
30E0 09A0 EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, ; N &00, &00, &00, &00, &00, &00, &00, &00, &00, ; o &00, &00, &00, &00, &00, &00, &00, &00, &00, ; t &00, &00, &00, &00, &00, &FF, &FF, &00, &00, ; r &00, &00, &00, &00, &00, &00, &00, &00, &00, ; e &00, &00, &00, &00, &00, &00, &00, &00, &00, ; f &00, &00, &00, &00, &00, &00, &00, &00, &00, ; e &00, &00, &00, &00, &00, &00, &00, &00, &00, ; r &00, &00, &00, &00, &00, &00, &00, &00 ; e ; n ; c ; e ; d
; The exit's map x, kept while a hero goes down it.
3130 09F0 .exit_saved_x←4← 1F7A STA← 1FA7 LDA← 1FD3 LDA← 2026 LDA
EQUB &04
; The exit's map y, kept while a hero goes down it.
3131 09F1 .exit_saved_y←4← 1F80 STA← 1FAD LDA← 1FD9 LDA← 202C LDA
EQUB &2C
; Non-zero while a hero is going down the exit.
3132 09F2 .exit_busy←5← 14AD STA← 1F10 LDA← 1F96 LDA← 2034 STA← 2078 STA
EQUB &00
; Direction (1, 3, 5, 7) of the hero spinning on the exit.
3133 09F3 .exit_spin←5← 1FBE LDA← 1FC3 STA← 1FCE ADC← 1FF4 STA← 2086 STA
EQUB &FF
; Spins left before the hero has gone (4 to 1).
3134 09F4 .exit_shrinks_left←3← 1FDF LDX← 1FF7 DEC← 208B STA
EQUB &00
; The hero going down the exit.
3135 09F5 .exiting_hero←3← 1F9E LDX← 1FBA LDX← 207E STA
EQUB &03
3136 09F6 .exit_offsets_x←2Referenced by← 2042 STAUsed as index base by← 1FE2 LDA
EQUB &04
; exit_offsets_x entry 1.
3137 09F7 .exit_offset_x_1←1← 14BE STA
EQUB &01
; exit_offsets_x entry 2.
3138 09F8 .exit_offset_x_2←1← 14C1 STA
EQUB &01
; exit_offsets_x entry 3.
3139 09F9 .exit_offset_x_3←1← 14B0 STA
EQUB &00
; Vertical offset of the shrinking hero, in pixel rows, ; entries 1-4 by exit_shrinks_left (at exit_offsets_y+1 to ; +4). Also entry 4 of exit_offsets_x.
313A 09FA .exit_offsets_y←2Referenced by← 14B3 STAUsed as index base by← 1FE7 LDA
EQUB &00
; exit_offsets_y entry 1.
313B 09FB .exit_offset_y_1←1← 14CE STA
EQUB &05
; exit_offsets_y entry 2.
313C 09FC .exit_offset_y_2←1← 14D3 STA
EQUB &03
; exit_offsets_y entry 3.
313D 09FD .exit_offset_y_3←1← 14C4 STA
EQUB &01
; exit_offsets_y entry 4.
313E 09FE .exit_offset_y_4←1← 14B6 STA
EQUB &00
; The hero whose sprites are shrunk, or &FF.
313F 09FF .shrunk_hero←4← 14C9 STA← 1F2D LDX← 2045 LDX← 2081 STA
EQUB &FF
; Data of sprite &5F: 4 bytes x 12 rows.
3140 0A00 .sprite_boots
EQUB &00, &00, &00, &00, &00, &00, &00, &15, &00, &00, &00, &3F, &00, &00, &00, &3F, &00, &01, &13, &2A, &00, &01, &13, &2A, &00, &01, &13, &00, &00, &03, &13, &00, &03, &03, &33, &00, &03, &03, &33, &00, &03, &03, &33, &00, &00, &00, &00, &00
; Data of sprite &60: 4 bytes x 12 rows.
3170 0A30 .sprite_helmet
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &2A, &3C, &22, &2A, &2A, &3C, &22, &2A, &2A, &3C, &22, &2A, &14, &14, &11, &00, &14, &00, &11, &00, &14, &28, &39, &00, &14, &3C, &33, &00, &14, &3C, &33, &00, &00, &00, &00, &00, &00, &00, &00, &00
; Data of sprite &61: 4 bytes x 12 rows.
31A0 0A60 .sprite_potion
EQUB &00, &00, &00, &00, &00, &01, &02, &00, &00, &15, &2A, &00, &00, &05, &02, &00, &00, &05, &02, &00, &00, &05, &02, &00, &00, &05, &02, &00, &00, &0F, &03, &00, &05, &0F, &0B, &02, &05, &0F, &0B, &02, &05, &0F, &03, &02, &00, &0F, &03, &00
; Data of sprite &63: 4 bytes x 12 rows.
31D0 0A90 .sprite_magic_sword
EQUB &00, &00, &00, &00, &00, &54, &00, &54, &00, &00, &00, &00, &54, &00, &04, &00, &00, &00, &04, &00, &3F, &3F, &2E, &0C, &15, &3F, &2E, &00, &00, &00, &04, &54, &A8, &00, &00, &00, &00, &54, &00, &00, &00, &00, &00, &A8, &00, &00, &00, &00
; Data of sprite &62: 4 bytes x 12 rows.
3200 0AC0 .sprite_weapons
EQUB &2A, &00, &00, &02, &05, &00, &00, &02, &00, &0A, &15, &01, &00, &04, &1D, &01, &01, &04, &15, &01, &05, &00, &15, &01, &05, &00, &15, &02, &05, &00, &15, &02, &00, &15, &15, &00, &02, &2A, &33, &22, &01, &00, &11, &00, &02, &02, &11, &00
; Data of sprite &2A: 4 bytes x 12 rows.
3230 0AF0 .sprite_cross
EQUB &00, &0F, &02, &00, &00, &0F, &02, &00, &00, &1F, &02, &00, &3F, &1F, &0F, &02, &0F, &1F, &0F, &02, &0F, &1F, &0F, &02, &00, &0F, &02, &00, &00, &0F, &02, &00, &00, &2F, &02, &00, &00, &2F, &02, &00, &00, &0F, &02, &00, &00, &0F, &02, &00
; Number of missiles each hero may have in flight at once, ; 1-3 (raised by a pile of weapons).
3260 0B20 .hero_max_missiles←9Used as index base by← 0ED2 STA← 0F2B LDA← 0F30 ADC← 6F22 ADC← 751A INC← 751D LDA← 7526 STA← 75C5 LDA← 75CA ADC
EQUB &03, &02, &01, &03
; INKEY key numbers of the magic keys of heroes 0 and 1, ; the only heroes with magic.
3264 0B24 .hero_magic_key←1Used as index base by← 7624 LDA
EQUB &FE, &B6
; Frames until heroes 0 and 1 next check their magic key.
3266 0B26 .hero_magic_delay←3Used as index base by← 7619 DEC← 7621 STA← 7644 STA
EQUB &01, &01
; Monsters killed by the magic being cast, each worth a ; point.
3268 0B28 .magic_kill_count←3← 765E STA← 768F INC← 7699 LDY
EQUB &00, &10
; Queue of heroes waiting to come back: each entry is a ; hero number plus 1, or &64 for a slot that brings nobody ; back; 0 ends the queue. A Cross of Resurrection takes ; the first entry.
326A 0B2A .returning_hero_queue←10Referenced by← 7421 LDA← 742B LDX← 7432 STAUsed as index base by← 06EC STA (low_joystick)← 06EC STA (low_keyboard)← 159C STA← 16B4 LDA← 16BB STA← 7256 LDA← 725F STA
EQUB &03
326B 0B2B EQUB &02 ; Queue entry 1
326C 0B2C EQUB &01 ; Queue entry 2
326D 0B2D EQUB &04 ; Queue entry 3
326E 0B2E EQUB &10 ; Queue entry 4
; Index (0-7) of the trapdoor from which the next monster ; emerges.
326F 0B2F .next_trapdoor←5← 14B9 STA← 7CB3 INC← 7CB6 LDA← 7CBF STA← 7CC2 LDY
EQUB &04
; Sprites of a hero dying, in order (sparkles &16-&19, ; then skulls &64-&68, ending as the skull left where the ; hero fell), or returning, in reverse.
3270 0B30 .hero_appearance_sprites←1Used as index base by← 76F2 LDA
EQUB &16, &17, &18, &19
3274 0B34 EQUS "defgh"
3279 0B39 EQUB &10, &10, &10, &10, ; Not referenced &10, &10, &10
; Hit points left for each monster (entries 1-30); a hit ; subtracts the missile's damage.
3280 0B40 .monster_hit_points←4Used as index base by← 1592 STA← 758D LDA← 759E STA← 75A6 STA
EQUB &10, &08, &08, &08, &08, &08, &08, &08, &08, &08, &08, &08, &08, &08, &08, &05, &08, &08, &08, &08, &08, &08, &08, &08, &08, &08, &08, &08, &08, &08, &08, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10
; Damage each hero's missiles do, 1-9 (raised by a magic ; sword).
32B0 0B70 .hero_missile_damage←7Used as index base by← 0ED8 STA← 0F50 LDA← 6F4A LDA← 756B INC← 756E LDA← 7577 STA← 75EE LDA
EQUB &02, &03, &09, &03, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10
; Damage each missile in flight will do (12 slots, three ; per hero).
32C0 0B80 .missile_damage←3Used as index base by← 6F4D STA← 71F0 LDA← 7591 SBC
EQUB &02, &02, &02, &03, &03, &04, &09, &09, &10, &03, &03, &03, &10, &10, &10
32CF 0B8F EQUB &10 ; Not referenced
; Map x of the level's eight trapdoors, from the level ; file.
32D0 0B90 .trapdoor_x←2Used as index base by← 1554 STA← 7CC5 LDA
EQUB &0B
32D1 0B91 EQUB &15 ; Trapdoor 2's x
32D2 0B92 EQUB &17 ; Trapdoor 3's x
32D3 0B93 EQUB &10 ; Trapdoor 4's x
32D4 0B94 EQUB &03 ; Trapdoor 5's x
32D5 0B95 EQUB &17 ; Trapdoor 6's x
32D6 0B96 EQUB &0D ; Trapdoor 7's x
32D7 0B97 EQUB &1A ; Trapdoor 8's x
; Map y of the level's eight trapdoors, from the level ; file.
32D8 0B98 .trapdoor_y←2Used as index base by← 155A STA← 7CCB LDA
EQUB &04
32D9 0B99 EQUB &0C ; Trapdoor 2's y
32DA 0B9A EQUB &14 ; Trapdoor 3's y
32DB 0B9B EQUB &1D ; Trapdoor 4's y
32DC 0B9C EQUB &25 ; Trapdoor 5's y
32DD 0B9D EQUB &20 ; Trapdoor 6's y
32DE 0B9E EQUB &28 ; Trapdoor 7's y
32DF 0B9F EQUB &2C ; Trapdoor 8's y
; Score hundreds digit, as a digit sprite (&1E-&27 for ; 0-9).
32E0 0BA0 .hero_score_hundreds←5Used as index base by← 0EE6 STA← 72AA INC← 72AD LDA← 72B6 STA← 72D4 LDA
EQUB &1E, &1E, &1E, &1E
; Score tens digit, as a digit sprite.
32E4 0BA4 .hero_score_tens←5Used as index base by← 0EE9 STA← 729B INC← 729E LDA← 72A7 STA← 72E4 LDA
EQUB &1E, &1E, &1E, &1E
; Score units digit, as a digit sprite.
32E8 0BA8 .hero_score_units←8Used as index base by← 06E2 DEC (low_joystick)← 06E2 DEC (low_keyboard)← 0EEE STA← 728C INC← 728F LDA← 7298 STA← 72F4 LDA← 74CF LDA
EQUB &1D, &1D, &1D, &1D
; Score thousands digit, as a digit sprite.
32EC 0BAC .hero_score_thousands←8Used as index base by← 0400 INC (low_joystick)← 0400 INC (low_keyboard)← 0403 LDA (low_joystick)← 0403 LDA (low_keyboard)← 040C STA (low_joystick)← 040C STA (low_keyboard)← 0EE3 STA← 72C8 LDA
EQUB &1E, &1E, &1E, &1E, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10, &10
; OSWORD 7 (SOUND) parameter block for teleporting.
3330 0BF0 .teleport_sound
EQUW &13, &04, ; SOUND channel 3 (flush), envelope 4, 100, 30 ; pitch 100, duration 30
; OSWORD 7 (SOUND) parameter block for eating food, and ; (with its pitch changed) opening a door.
3338 0BF8 .food_sound
EQUW &13, &02, ; SOUND channel 3 (flush), envelope 2, 200, 2 ; pitch 200, duration 2
; The level's wall map, from the level file: eight bytes ; per room, one per row of cells, one bit per cell (bit 7 ; at the left). Rooms are 8x8 cells and run four to a row ; of the map. The first eight bytes are also the MOS 1.20 ; definition of character 128, which the WRCHV handler ; overwrites with each glyph it prints; the level is ; unpacked only after the level number has been printed.
3340 0C00 .room_walls←3Used as index base by← 1567 STA← 7FC8 STA← 7FEB STA
EQUB &54, &49, &4B, &50, &24, ; Not read: &55, &54, &48, &4F, &5B, ; unpack_level copies &4B, &46, &2C, &44, &5D, ; each level's wall map &2F ; here
3350 0C10 EQUB &44, &59, &57, &33, &43, &5A, &44, ; ...entries &5C, &38, &56, &5C, &3B, &56, &48, ; 16-31, not &52, &56 ; read
3360 0C20 EQUB &61, &6F, &02, &62, &72, &6C, &75, ; ...entries &07, &00, &6A, &03, &0B, &1D, &14, ; 32-47, not &16, &19 ; read
3370 0C30 EQUB &10, &70, &67, &74, &61, &66, &62, ; ...entries &19, &71, &19, &72, &7A, &6A, &78, ; 48-63, not &1E, &78 ; read
3380 0C40 EQUB &09, &17, &07, &0D, &64, &0B, &09, ; ...entries &05, &07, &0D, &13, &6B, &1C, &08, ; 64-79, not &1C, &02 ; read
3390 0C50 EQUB &19, &02, &01, &1A, &1B, &1B, &76, ; ...entries &03, &17, &79, &17, &1A, &0E, &16, ; 80-95, not &1B, &0B ; read
33A0 0C60 EQUB &40, &35, &2A, &2A, &37, &45, &21, ; ...entries &26, &25, &2C, &4A, &32, &29, &39, ; 96-111, not &4E, &2E ; read
33B0 0C70 EQUB &3E, &35, &52, &32, &3A, &2C, ; ...entries &56, &38, &36, &3C, &5A, &29, ; 112-127, not &39, &3C, &3A, &36 ; read
33C0 0C80 EQUB &CE, &C6, &A2, &D7, &CC, &CC, ; ...entries &D5, &A7, &C1, &DA, &AA, &CA, ; 128-143, not &AC, &CB, &A4, &A5 ; read
33D0 0C90 EQUB &BA, &BB, &B8, &D4, &B4, &D7, ; ...entries &BC, &BD, &B2, &B3, &B0, &DF, ; 144-159, not &BC, &D4, &D8, &BF ; read
33E0 0CA0 EQUB &F4, &E9, &E7, &FA, &84, &E4, ; ...entries &F4, &E2, &88, &EA, &E5, &E5, ; 160-175, not &FF, &E4, &EA, &EA ; read
33F0 0CB0 EQUB &E2, &F8, &FC, &F4, &94, &F0, ; ...entries &E4, &F6, &EB, &F0, &F4, &FC, ; 176-191, not &9C, &E9, &F6, &F6 ; read
3400 0CC0 EQUB &93, &E1, &8F, &86, &97, ; ...entries 192-200, &96, &87, &80, &8D ; not read
3409 0CC9 EQUB &E7, &9E, &83, &8D, ; Not referenced &83, &85, &90
; Health each hero loses when a monster touches it, 3-9 ; (lowered by a magic helmet). The status panel shows 10 ; minus this as the armour rating.
3410 0CD0 .hero_damage_taken←7Used as index base by← 0EDE STA← 0F1E SBC← 74EF DEC← 74F2 LDA← 74F9 INC← 75BD SBC← 79A7 LDY
EQUB &89, &9E, &87, &F3, &95, &9B, &92, &F7, &90, &98, &8A, &8B, &85, &FD, &9A, &8A, &AE, &A6, &A7, &AC, &AA, &AC, &A8, &A0, &C9, &00, &00, &00, &00, &00, &00, &00
; OSWORD 7 (SOUND) parameter block for a monster hit, and ; (louder) touching an energy drainer.
3430 0CF0 .hit_sound
EQUW &10, &01, 6, ; SOUND channel 0 (flush), envelope 6 ; 1, pitch 6, duration 6
3438 0CF8 EQUB &12, &00, &03, &00, &C8, &00, &0A, ; Not &00 ; referenced
; General-purpose scratch byte.
3440 0D00 .scratch←50Referenced by← 1CC5 STX← 1D00 LDX← 1D4E STA← 1D52 ADC← 1D55 ADC← 1D58 ADC← 1D77 STA← 1D82 AND← 2006 STA← 200D CPX← 201E CPX← 205A STA← 2063 CPY← 2070 CPY← 6F19 STA← 6F1E ADC← 6F25 STA← 6F71 CPY← 6FD7 STA← 7002 STX← 7007 CPY← 713C STA← 74B6 STA← 74C3 LDA← 74D8 LDA← 77E6 STA← 782C LDA← 7857 STA← 785B ADC← 785E ADC← 7861 ADC← 7886 STA← 788B ADC← 7901 STA← 7905 ADC← 7908 ADC← 790B ADC← 7926 STA← 7931 AND← 793D STA← 7941 ADC← 7944 ADC← 7947 ADC← 7962 STA← 796D AND← 7976 CPX← 7990 LDA← 7A89 STA← 7CE3 STXUsed as index base by← 14A5 STA
EQUB &A9
; Second scratch byte.
3441 0D01 .scratch2←8← 203A STX← 207B LDA← 74D2 STA← 7503 LDA← 7509 INC← 750C LDA← 7829 STA← 782F AND
EQUB &30
; Map x of the cell being drawn, tested or moved to. ; plot_at_cell replaces it with the pixel offset within ; the room.
3442 0D02 .cell_x←59← 119C STA← 11F4 STA← 1CCB STA← 1CDB CMP← 1D26 LDA← 1D3C STA← 1D5D LDA← 1D6C LDA← 1DD1 STA← 1E38 STA← 1E48 CMP← 1F58 STA← 1FAA STA← 1FD6 STA← 2094 STA← 20A7 LDA← 20DE INC← 20E9 DEC← 20FA DEC← 6FA7 STA← 700F CMP← 707C STA← 70AA STA← 70EE STA← 7120 STA← 715B STA← 7176 CMP← 71E3 CMP← 7310 STA← 732C STA← 733A CMP← 73F0 STA← 752F STA← 766A STA← 777D STA← 779B STA← 77AD STA← 77BF STA← 77D1 STA← 7801 STA← 7820 LDA← 7867 LDA← 7872 LDA← 787C STA← 789E ADC← 78B8 ADC← 78D2 ADC← 78EC ADC← 7910 LDA← 791D LDA← 794C LDA← 7959 LDA← 797B LDA← 7997 LDA← 79D0 STA← 79EA STA← 7A48 STA← 7B07 STA← 7B44 STA
EQUB &8D
; Map y of the cell being drawn, tested or moved to. ; plot_at_cell replaces it with the pixel offset within ; the room.
3443 0D03 .cell_y←55← 11A1 STA← 11F9 STA← 1CD1 STA← 1CE6 CMP← 1D20 LDA← 1D42 STA← 1D49 LDA← 1D7A LDA← 1DD7 STA← 1E3E STA← 1E50 CMP← 1F5E STA← 1FB0 STA← 1FDC STA← 209A STA← 20AD LDA← 20D0 DEC← 20DB INC← 20EC INC← 20F7 DEC← 6FAD STA← 7017 CMP← 7082 STA← 70B0 STA← 70F4 STA← 7126 STA← 7161 STA← 717E CMP← 71EB CMP← 7316 STA← 7332 STA← 7345 CMP← 73FC STA← 7535 STA← 7670 STA← 7783 STA← 7807 STA← 7852 LDA← 787F LDA← 7890 STA← 78A5 ADC← 78BF ADC← 78D9 ADC← 78F3 ADC← 78FC LDA← 7929 LDA← 7938 LDA← 7965 LDA← 7983 LDA← 799F LDA← 79D6 STA← 79F3 STA← 7A4E STA← 7B0D STA← 7B4A STA
EQUB &BD
; Room of the cell being drawn, as an offset into ; room_walls.
3444 0D04 .cell_room←7← 7864 STA← 786C ADC← 786F STA← 7896 CMP← 78B0 CMP← 78CA CMP← 78E4 CMP
EQUB &08, &A9
; Map x of the creature being moved, before the move.
3446 0D06 .previous_x←11← 6E9A STA← 6F56 LDA← 6FBB LDA← 6FE5 LDA← 7021 LDA← 7069 LDA← 7079 LDA← 79ED STA← 7A58 LDA← 7A95 LDA← 7AF8 LDA
EQUB &20
; Map y of the creature being moved, before the move.
3447 0D07 .previous_y←11← 6EA0 STA← 6F5C LDA← 6FC1 LDA← 6FEB LDA← 7027 LDA← 706F LDA← 707F LDA← 79F6 STA← 7A5E LDA← 7A9B LDA← 7AFE LDA
EQUB &8D
; Pixel offset of the hero being moved, before the move.
3448 0D08 .previous_offset_x←2← 6EA6 STA← 7085 LDA
EQUB &BE
; Pixel offset of the hero being moved, before the move.
3449 0D09 .previous_offset_y←2← 6EAC STA← 708A LDA
EQUB &08, &A9, &00, &8D, &BC, &08, &EA
; Map x of each hero.
3450 0D10 .hero_x←30Used as index base by← 06E7 STA (low_joystick)← 06E7 STA (low_keyboard)← 1DFD LDA← 1E35 LDA← 1E89 LDA← 1F38 LDA← 1F55 LDA← 1F74 STA← 2091 LDA← 6E97 LDA← 6F39 LDA← 6F59 STA← 6F87 INC← 6F95 DEC← 6F98 LDA← 6FA4 LDA← 6FBE STA← 6FE8 STA← 700C LDA← 7024 STA← 706C STA← 70A7 LDA← 71E0 LDA← 7329 LDA← 73ED STA← 752C LDA← 777A LDA← 799A CMP← 7BBD INC← 7BCB DEC
EQUB &4C, &10, &0D, &0D, &A2
; Map y of each hero.
3455 0D15 .hero_y←27Used as index base by← 1E03 LDA← 1E3B LDA← 1E8F LDA← 1F40 LDA← 1F5B LDA← 2097 LDA← 6E9D LDA← 6F3F LDA← 6F5F STA← 6F80 DEC← 6F8E INC← 6F9E LDA← 6FAA LDA← 6FC4 STA← 6FEE STA← 7014 LDA← 702A STA← 7072 STA← 70AD LDA← 71E8 LDA← 732F LDA← 73F9 STA← 7532 LDA← 7780 LDA← 79A2 CMP← 7BB6 DEC← 7BC4 INC
EQUB &80, &A0, &0D, &A9
3459 0D19 EQUB &00 ; Not read: page &0D is refreshed from workspace_template
; Direction each hero faces: 1 up, 3 right, 5 down, 7 ; left; 0 when the hero is not in play.
345A 0D1A .hero_direction←19Used as index base by← 06D0 STA (low_joystick)← 06D0 STA (low_keyboard)← 1DE6 LDA← 1F52 STA← 6E82 LDA← 6ECB STA← 6EDE STA← 6EF1 STA← 6F04 STA← 6F2D LDA← 6F79 LDA← 701C LDA← 7097 LDA← 7221 LDA← 7249 STA← 7452 STA← 7711 STA← 7B67 LDA← 7BAF LDA
EQUB &8D
345B 0D1B EQUB &84 ; Hero 1's direction
345C 0D1C EQUB &0D ; Hero 2's direction
345D 0D1D EQUB &8D, &85 ; Hero 3's direction
345F 0D1F EQUB &0D ; Not read: page &0D is refreshed from workspace_template
; Animation frame of each hero (0 or 1), added to its ; sprite.
3460 0D20 .hero_frame←15Referenced by← 774E LDA← 7753 STAUsed as index base by← 06DA STA (low_joystick)← 06DA STA (low_keyboard)← 1DF3 LDA← 6F62 LDA← 6F67 STA← 709C ADC← 7457 STA← 76EE LDA← 76FF LDA← 771F STA← 772E STA← 7BA2 LDA← 7BA7 STA
EQUB &AD
3461 0D21 EQUB &12 ; Hero 1's frame
3462 0D22 EQUB &02 ; Hero 2's frame
3463 0D23 EQUB &8D, &2F ; Hero 3's frame
; Frames left in each hero's step between cells.
3465 0D25 .hero_step←13Used as index base by← 06D5 STA (low_joystick)← 06D5 STA (low_keyboard)← 1F4D STA← 6E87 LDA← 6EAF LDA← 6FC9 STA← 6FF3 STA← 702F STA← 7063 STA← 7401 STA← 7716 STA← 7B64 STA← 7BAA DEC
EQUB &0D, &AD, &13, &02, &8D
; Each hero's horizontal pixel offset while between cells.
346A 0D2A .hero_offset_x←19Used as index base by← 6EA3 LDA← 6FCC STA← 6FF6 STA← 7032 STA← 705D STA← 724E STA← 7404 STA← 745C STA← 7702 ADC← 7719 STA← 7735 LDA← 7B70 STA← 7B84 STA← 7B8E STA← 7B9E STA← 7BD0 STA← 7BD7 LDA← 7BDA ADC← 7BDD STA
EQUB &30, &0D, &A9, &06, &20, &EE
; Each hero's vertical pixel offset while between cells.
3470 0D30 .hero_offset_y←20Used as index base by← 6EA9 LDA← 6FCF STA← 6FF9 STA← 7035 STA← 7060 STA← 7251 STA← 7407 STA← 7461 STA← 76DA DEC← 76E2 STA← 771C STA← 773A LDA← 7B75 STA← 7B7F STA← 7B93 STA← 7B99 STA← 7BD3 STA← 7BE1 LDA← 7BE4 ADC← 7BE7 STA
EQUB &FF

Start the game

The game's entry point, where the release's loader jumps once the game is in memory. It prepares the two MOS services the game leans on:

First the bell (the BEL character's channel, envelope, pitch and duration, through OSBYTEs &D3-&D6): the bell is what sounds when a hero fires, and the victory sequence raises its pitch.

Then the text: save the MOS's WRCHV in saved_wrchv, for draw_view_frames to put back while it sends the view frames' PLOT commands, and point WRCHV at wrch_handler, so that all the game's text is printed in its own font.

This code lives in the per-level workspace: from &0D40 its bytes are the missile tables and other workspace in page &0D, which reset_workspace overwrites from workspace_template at the start of every level, so it can run only before the first level after the game is loaded. It does not return; what follows &0D6A, starting the game, is the release's own.

LoadExec
3471 0D31 .game_entry←1← 5149 JMP
LDA #osbyte_bell_channel ; OSBYTE &D3: bell channel...
3473 0D33 LDX #&11 ; ...&11: channel 1, with SOUND's flush bit set
3475 0D35 LDY #0 ; Y = 0: replace the setting with X
3477 0D37 JSR osbyte ; Set it: the firing bell sounds on channel 1 osbyte: bell channel
347A 0D3A LDA #osbyte_bell_envelope ; OSBYTE &D4: bell envelope...
347C 0D3C LDX #0 ; ...0, a fixed amplitude
347E 0D3E LDY #0 ; Y = 0: replace the setting with X
; Map x of each missile (12 slots, three per hero).
3480 0D40 .missile_x←6Used as index base by← 6F3C STA← 70EB LDA← 710C INC← 711A DEC← 711D LDA← 7158 LDA
JSR osbyte ; Set it: BEL plays at a fixed amplitude osbyte: bell envelope
3483 0D43 LDA #osbyte_bell_frequency ; OSBYTE &D5: bell pitch...
3485 0D45 LDX #&64 ; ...&64, SOUND pitch 100
3487 0D47 LDY #0 ; Y = 0: replace the setting with X
3489 0D49 JSR osbyte ; Set it: BEL plays at pitch &64 osbyte: bell frequency
; Map y of each missile.
348C 0D4C .missile_y←6Used as index base by← 6F42 STA← 70F1 LDA← 7105 DEC← 7113 INC← 7123 LDA← 715E LDA
LDA #osbyte_bell_duration ; OSBYTE &D6: bell duration...
348E 0D4E LDX #1 ; ...1, in twentieths of a second
3490 0D50 LDY #0 ; Y = 0: replace the setting with X
3492 0D52 JSR osbyte ; Set it: BEL lasts a twentieth of a second osbyte: bell duration
3495 0D55 LDA wrchv ; Save the MOS's WRCHV...
; Direction of each missile: 1 up, 2 right, 3 down, 4 ; left; bit 7 set for a missile just fired; 0 for an empty ; slot.
3498 0D58 .missile_direction←12Used as index base by← 6F28 LDA← 6F36 STA← 70D2 LDA← 70DE STA← 70FE LDA← 7134 STA← 71A5 LDA← 71AE STA← 71BA STA← 71C6 STA← 71CE STA← 720C ADC
STA saved_wrchv ; ...its low byte into saved_wrchv...
349B 0D5B LDA wrchv + 1 ; ...and its high byte...
349E 0D5E STA saved_wrchv + 1 ; ...in saved_wrchv, for drawing the view frames
34A1 0D61 LDA #<(wrch_handler) ; Point WRCHV at wrch_handler, the game's font...
; Sprite base of each missile, to which its direction is ; added; also identifies the hero who fired it.
34A3 0D63 .set_wrchv_low
STA wrchv ; ...into WRCHV's low byte...
34A6 0D66 LDA #>(wrch_handler) ; ...and wrch_handler's high byte...
34A8 0D68 STA wrchv + 1 ; ...into WRCHV's: text now goes through it
; Take the level number from Coder, and start a new game ; on the first level, or go straight to the level on later ; ones, the heroes having carried over in &08C0-&0CFF.
34AB 0D6B LDA level_count_copy ; levels_started, which Coder left in &8E...
34AD 0D6D STA level_number ; ...is level_number, 1-25, for the checksum and Chalice
; INKEY key number of each hero's up key.
34B0 0D70 .hero_key_up←1Used as index base by← 6EC1 LDA
LDA victory_pitch ; Copy &8F, which Coder does not set...
; INKEY key number of each hero's down key.
34B2 0D72 .store_level_bcd
STA level_bcd ; ...into level_bcd, which nothing here reads
34B5 0D75 LDA levels_started ; First level of a game?
; INKEY key number of each hero's right key.
34B8 0D78 .hero_key_right←1Used as index base by← 6EE7 LDA
CMP #1 ; ...levels_started 1, the first level of a game?
34BA 0D7A BEQ start_new_game ; Yes: reset the heroes and run the hero menu
; INKEY key number of each hero's left key.
34BC 0D7C .hero_key_left←1Used as index base by← 6EFA LDA
JMP level_loop ; No: the heroes carry over; straight to the level
; INKEY key number of each hero's fire key.
34BF 0D7F .start_new_game←1← 0D7A BEQ
LDA #0 ; A = 0, for new_game_reset_heroes' first hero
34C1 0D81 JMP new_game_reset_heroes ; ...past the stores that zero the level counts
34C4 0D84 EQUS "eon5"
34C8 0D88 EQUB &0D, &18, &BD, &04, ; Not referenced &0D, &69, &03
34CF 0D8F EQUB &9D ; Not referenced
; Health tens digit, as a digit sprite (&1E-&27); &1D when ; the hero is dead.
34D0 0D90 .hero_health_tens←11Used as index base by← 06DF STA (low_joystick)← 06DF STA (low_keyboard)← 0E6D LDA← 7236 DEC← 7239 LDA← 726F LDA← 738E INC← 7391 LDA← 739A STA← 7506 STA← 7724 STA
EQUB &1D
34D1 0D91 EQUB &1D ; Hero 1's health tens
34D2 0D92 EQUB &1D ; Hero 2's health tens
34D3 0D93 EQUB &1D, &D0 ; Hero 3's health tens
; Health units digit, as a digit sprite.
34D5 0D95 .hero_health_units←7Used as index base by← 7227 DEC← 722A LDA← 7233 STA← 727B LDA← 739D STA← 750F STA← 7727 STA
EQUS "''''"
34D9 0D99 EQUB &18, &BD, &08, &0D, ; Not referenced &6D, &40, &0D
; The room each hero's view shows: a pointer into ; room_walls, low byte then high byte, for each hero in ; turn (hero x at view_room + 2x).
34E0 0DA0 .view_room←5Referenced by← 779E LDA← 7893 LDAUsed as index base by← 7043 LDA← 7544 STA← 767C LDA
EQUB &18
34E1 0DA1 EQUB &0C ; Hero 0's view room, high byte
34E2 0DA2 EQUB &68 ; Hero 1's view room, low byte
34E3 0DA3 EQUB &0C ; Hero 1's view room, high byte
34E4 0DA4 EQUB &28 ; Hero 2's view room, low byte
34E5 0DA5 EQUB &0C ; Hero 2's view room, high byte
34E6 0DA6 EQUB &30 ; Hero 3's view room, low byte
34E7 0DA7 EQUB &0C, &00, &00, &BD, &04, ; Hero 3's view room, &0D, &85, &71, &8A ; high byte
; Sprite base of each hero's missiles: arrows, fireballs, ; axes, swords.
34F0 0DB0 .hero_missile_sprites←1Used as index base by← 6F50 LDA
EQUB &10
34F1 0DB1 EQUS "DLHh"
; Sprite base of each hero, to which direction and frame ; are added.
34F5 0DB5 .hero_sprites←4Used as index base by← 1FCB LDA← 1FFD LDA← 2051 LDA← 709F ADC
EQUB &00
34F6 0DB6 EQUS ",4<"
34F9 0DB9 EQUB &00, &0D, &D9 ; Not referenced
; Non-zero while the hero wears Boots of Speed.
34FC 0DBC .hero_has_boots←3Used as index base by← 7056 LDA← 7351 STA← 74E7 STA
EQUB &00, &00, &00, &00
; Bit masks for the cells of a room row, left to right: ; &80, &40 ... &01.
3500 0DC0 .bit_masks←3Used as index base by← 1D72 LDA← 7923 LDA← 795F LDA
EQUB &80, &40, &20, &10, &08, &04, &02, &01, &B9, &30, &0D, &9D, &08, &0D, &4C, &D4
; Pixel row of each hero's section of the status panel.
3510 0DD0 .hero_panel_y←10Used as index base by← 1D9C LDA← 1E12 LDA← 1E6D LDA← 20BC LDA← 7266 LDA← 72BD LDA← 75AF LDA← 75CF ADC← 75E7 LDA← 75FE LDA
EQUB &0E, &3C, &6A, &98, &E8, &E0, &04, &D0, &0A, &A2, &00, &AD, &40, &0D, &49, &01, &8D, &40, &0D, &8E, &FF, &0D, &68, &A8, &68, &AA
352A 0DEA EQUS "h(`"
352D 0DED EQUB &DE, &DD, &DF, &F0, &F2, &F1, &F3, &F8, &FA, &F9, &FB, &F4, &F6, &F5, &F7, &FC ; Not referenced
; Index of the last object to search when looking ; backwards for a teleporter (&1E, from ; workspace_template).
353D 0DFD .teleport_last←1← 73D3 LDY
EQUB &1E, &FD
; Written by draw_victory_ring; not read.
353F 0DFF .victory_sprite_copy←1← 1160 STA
EQUB &00, &A9, &00, &8D, &9F, &16, &8D, &FF, &16
3548 0E08 .new_game_reset_heroes←1← 0D81 JMP
TAX ; Give each hero their starting attributes and score
3549 0E09 .reset_each_hero←1← 0E0F BNE
JSR reset_hero ; Reset hero X: starting attributes, score 0000
354C 0E0C INX ; Next hero, 0-3
354D 0E0D CPX #4 ; All four done?
354F 0E0F BNE reset_each_hero ; No: reset the next
3551 0E11 JSR hero_menu ; Then the players choose heroes and sound
; The level loop: Coder has already loaded this level, so ; set the monsters' strength and start it. The leftover ; code after the JMP, which would count the level and ; build a filename, is never run.
3554 0E14 .level_loop←1← 0D7C JMP
LDA levels_started ; Monster hit points = 6 + 2 x levels started...
3557 0E17 ASL ; ...2 x levels started...
3558 0E18 CLC ; ...ready to add...
3559 0E19 ADC #6 ; ...+ 6: 8 on level 1, 56 on level 25
355B 0E1B STA monster_start_hit_points ; ...for every monster on this level
355E 0E1E JMP play_this_level ; Start the level Coder has loaded
3561 0E21 EQUB &FF, &16, &69, &01, &8D, &FF, &16, &D8, &AD, &9F, &16, &C9, &09, &B0, &04, &A2, &00, &F0, &02, &A2, &01, &AD, &FF, &16, &29, &0F, &18, &69, '0', &9D, &D5, &16, &E0, &00, &F0, &0D ; Not referenced
3585 0E45 .to_next_level←1← 0E84 BNE
JMP next_level_by_reset ; A hero survived: reset the machine and run Coder
3588 0E48 EQUS "JJJJ"
358C 0E4C EQUB &18, &69, '0', &8D, &D5, &16, &A9, &0D, &9D, &D6, &16 ; Not referenced
; Set the level up on the screen and play it: the level ; itself, the status panel, the absent heroes taken out, ; then play_level until no hero is left in play.
3597 0E57 .play_this_level←1← 0E1E JMP
JSR start_level ; Load and draw the level
359A 0E5A JSR draw_status_panel ; Draw every hero's panel section
359D 0E5D JSR remove_absent_heroes ; Take out the heroes nobody plays
35A0 0E60 LDA #1 ; Vsync count 1: play_level's first wait is two vsyncs
35A2 0E62 STA os_vsync_counter ; ...counted down at each vertical sync
35A5 0E65 JSR play_level ; Play until no hero is left in play
; The level is over. Reset every hero who died, and end ; the game if all four did.
35A8 0E68 LDX #0 ; Count the dead, giving each their starting attributes
35AA 0E6A STX count ; ...none dead so far
35AD 0E6D .check_hero_dead←1← 0E7D BNE
LDA hero_health_tens,x ; Dead (heroes nobody plays count as dead)?
35B0 0E70 CMP #spr_digit_0 - 1 ; ...health tens one below 0?
35B2 0E72 BNE next_hero_dead ; No: survived, so not reset
35B4 0E74 JSR reset_hero ; Yes: start them afresh on the next level
35B7 0E77 INC count ; ...and count them
35BA 0E7A .next_hero_dead←1← 0E72 BNE
INX ; Next hero, 0-3
35BB 0E7B CPX #4 ; All four checked?
35BD 0E7D BNE check_hero_dead ; No: next hero
35BF 0E7F LDA count ; Any hero survived?
35C2 0E82 CMP #4 ; ...fewer than four dead?
35C4 0E84 BNE to_next_level ; Yes: on to the next level
; Every hero is dead: print the game-over message over the ; views, then wait for a key, or for the time limit, ; before starting again. The MOS goes on counting the ; vsync counter down at every vertical sync, so if it has ; passed 0 by the time the message is printed, the wait ; for it to reach 0 lasts until it comes round, up to 256 ; vsyncs (about 5 s), and only then are keys flushed and ; read.
35C6 0E86 LDA #&1c ; All dead: VDU 28,0,24,16,0, a window over the views...
35C8 0E88 JSR oswrch ; Send VDU 28
35CB 0E8B LDA #0 ; Left column 0
35CD 0E8D JSR oswrch ; Send the left column
35D0 0E90 LDA #&18 ; Bottom row 24
35D2 0E92 JSR oswrch ; Send the bottom row
35D5 0E95 LDA #&10 ; Right column 16, short of the status panel
35D7 0E97 JSR oswrch ; Send the right column
35DA 0E9A LDA #0 ; Top row 0
35DC 0E9C JSR oswrch ; Send the top row
35DF 0E9F LDA #&0c ; ...VDU 12 to clear it
35E1 0EA1 JSR oswrch ; Send VDU 12: clear the window
35E4 0EA4 LDX #4 ; Spaces over &0FF1-&0FF4, two of them the counters
35E6 0EA6 LDA #&20 ; ...the space to write
35E8 0EA8 .restore_message_spaces←1← 0EAC BNE
STA panel_hero - 1,x ; ...into each (&0FF1 held YOU ALL's full stop)
35EB 0EAB DEX ; Next byte down
35EC 0EAC BNE restore_message_spaces ; Until all four are spaces
35EE 0EAE .print_game_over←1← 0EB7 BNE
LDA game_over_message,x ; Print game_over_message from its start (X = 0)...
35F1 0EB1 JSR osasci ; ...through OSASCI, so each CR starts a new line
35F4 0EB4 INX ; Step to the message's next character
35F5 0EB5 CMP #0 ; ...up to its zero byte
35F7 0EB7 BNE print_game_over ; Not the end: next
35F9 0EB9 .wait_vsync_game_over←1← 0EBC BNE
LDA os_vsync_counter ; Wait for the vsync counter, still running, to reach 0
35FC 0EBC BNE wait_vsync_game_over ; Not yet: keep waiting
35FE 0EBE LDA #osbyte_flush_buffer_class ; Flush the input buffers
3600 0EC0 JSR osbyte ; Discard keys pressed during play Flush selected class of buffer
3603 0EC3 LDX #&46 ; Game over: wait up to &246 cs (5.8 s) for a key...
3605 0EC5 LDY #2 ; ...Y = &02: the time limit's high byte
3607 0EC7 LDA #osbyte_inkey ; ...OSBYTE &81: INKEY with a time limit
3609 0EC9 JSR osbyte ; Read a key, waiting up to 582 centiseconds
360C 0ECC JMP restart_by_reset ; ...then reset and reload the game with *DUNJUNZ

Give a hero their starting attributes

Undo everything hero X has gained: set their missile limit, missile damage and health lost per hit (hero_max_missiles, hero_missile_damage, hero_damage_taken) from the starting tables at &0F80, and their score to 0000 with no ten-thousands digit. It is called for every hero when a game starts, and by level_loop for each hero who died (or was not playing) when a level ends, so a dead hero comes back on the next level as new, while survivors keep their scores and the gains from objects. Health and position are not set here: reset_workspace restores those for every hero at each level. The units digit is set one below 0 because draw_status_panel draws the score by adding a point.

On EntryXhero number (0-3)
On ExitXpreserved
LoadExec
360F 0ECF .reset_hero←2← 0E09 JSR← 0E74 JSR
LDA hero_start_max_missiles,x ; Starting missile limit...
3612 0ED2 STA hero_max_missiles,x ; ...as hero X's missile limit
3615 0ED5 LDA hero_start_missile_damage,x ; Starting missile damage...
3618 0ED8 STA hero_missile_damage,x ; ...as their missile damage
361B 0EDB LDA hero_start_damage_taken,x ; Starting health lost per hit (armour)...
361E 0EDE STA hero_damage_taken,x ; ...as their health lost per hit
3621 0EE1 LDA #spr_digit_0 ; Score 0000: digit sprite 0...
3623 0EE3 STA hero_score_thousands,x ; ...as the thousands digit...
3626 0EE6 STA hero_score_hundreds,x ; ...the hundreds digit...
3629 0EE9 STA hero_score_tens,x ; ...and the tens digit
362C 0EEC LDA #spr_digit_0 - 1 ; ...units one below 0: draw_status_panel adds a point
362E 0EEE STA hero_score_units,x ; ...as the units digit
3631 0EF1 LDA #spr_small_digit_1 - 1 ; No ten-thousands digit (&69, one below small 1)
3633 0EF3 STA hero_score_ten_thousands,x ; ...as the ten-thousands digit
3636 0EF6 RTS ; Return, X still the hero

Draw the status panel

Draw each hero's section of the status panel, the column to the right of the views, Ranger at the top to Fighter at the bottom. level_loop calls it once per level, after start_level has drawn the fresh screen and before remove_absent_heroes.

The health and score are drawn by the routines play uses to change them: lose_health_point takes a point from the template's health of 99 + 1, so every hero starts every level on 99, and add_point adds one to the score, which a hero just reset has one below 0000. So a hero who survived the last level, and kept their score, gains a point here at every new level. Then, through plot_panel_sprite, which places each sprite relative to the hero's panel row (hero_panel_y): the face and the shield on the section's top row, with the armour rating (10 - health lost per hit) as a small digit on the shield; the missile damage as a small digit; and one missile icon per missile allowed in flight, three rows apart, beside the health. The keys, the boots icon and the ten-thousands digit are drawn elsewhere. panel_hero is the hero being drawn; count holds the icons' end row.

On ExitAcorrupted
Xcorrupted
Ycorrupted
LoadExec
3637 0EF7 .draw_status_panel←1← 0E5A JSR
LDA #0 ; For each hero's section...
3639 0EF9 STA panel_hero ; ...starting with the Ranger's, at the top
; Health and score first, drawn by the routines that ; change them in play.
363C 0EFC .draw_panel_hero←1← 0F65 BNE
LDX panel_hero ; X = this hero
363F 0EFF JSR lose_health_point ; Take a point from the template's 99 + 1: draws 99
3642 0F02 JSR add_point ; Add a point: draws the score (0000 if just reset)
; The section's top row: the hero's face and the shield, ; with the armour rating on the shield.
3645 0F05 LDA hero_faces,x ; The hero's face (their facing-down sprite)...
3648 0F08 LDX #panel_left ; ...at column &45, the panel's left...
364A 0F0A LDY #0 ; ...on the section's top row...
364C 0F0C JSR plot_panel_sprite ; ...plotted at the section's top left
364F 0F0F LDX #panel_left + 8 ; Shield at column &4D, the section's top right
3651 0F11 LDY #0 ; ...on the top row...
3653 0F13 LDA #spr_shield ; ...the shield sprite...
3655 0F15 JSR plot_panel_sprite ; ...plotted, for the armour rating to go on
3658 0F18 LDX panel_hero ; Armour rating on the shield: 10 - health lost per hit
365B 0F1B SEC ; ...(no borrow into the subtract)
365C 0F1C LDA #spr_small_digit_1 + 9 ; ...from &73, small digit 1 + 9...
365E 0F1E SBC hero_damage_taken,x ; ...less the damage per hit
3661 0F21 LDX #panel_left + 9 ; ...at column &4E...
3663 0F23 LDY #2 ; ...2 rows down the section...
3665 0F25 JSR plot_panel_sprite ; ...plotted on the shield
; One missile icon per missile the hero may have in ; flight, three rows apart from row &10.
3668 0F28 LDX panel_hero ; Icon rows run from &10 to &10 + 3 x missile limit...
366B 0F2B LDA hero_max_missiles,x ; ...the hero's missile limit, 1-3 at the start...
366E 0F2E ASL ; ...x 2...
366F 0F2F CLC ; ...(carry clear for the add)
3670 0F30 ADC hero_max_missiles,x ; ...+ limit: 3 rows per icon...
3673 0F33 ADC #&10 ; ...+ &10: the row after the last icon
3675 0F35 STA count ; ...(end row in count)
3678 0F38 LDY #&10 ; ...first icon at row &10, beside the health
367A 0F3A .draw_missile_icons←1← 0F4B BCC
TYA ; Keep the row...
367B 0F3B PHA ; ...on the stack
367C 0F3C LDX #panel_left + 6 ; ...at column &4B
367E 0F3E LDA #spr_missile_icon ; ...the missile icon...
3680 0F40 JSR plot_panel_sprite ; ...plotted at row Y
3683 0F43 PLA ; Recover the row...
3684 0F44 CLC ; ...(carry clear for the add)
3685 0F45 ADC #3 ; ...3 rows down...
3687 0F47 TAY ; ...for the next icon
3688 0F48 CPY count ; Past the last icon's row?
368B 0F4B BCC draw_missile_icons ; No: plot another
; The damage the hero's missiles do, then on to the next ; hero's section.
368D 0F4D LDX panel_hero ; Missile damage as a small digit, above the icons
3690 0F50 LDA hero_missile_damage,x ; ...the hero's missile damage...
3693 0F53 CLC ; ...(carry clear for the add)
3694 0F54 ADC #spr_small_digit_1 - 1 ; ...+ &69: small digit 1 for damage 1
3696 0F56 LDX #panel_left + 7 ; ...at column &4C...
3698 0F58 LDY #&0a ; ...&0A rows down, four above the health...
369A 0F5A JSR plot_panel_sprite ; ...plotted: the damage each missile does
369D 0F5D INC panel_hero ; Next hero's section
36A0 0F60 LDA panel_hero ; All four heroes drawn?
36A3 0F63 CMP #4 ; ...(four of them)
36A5 0F65 BNE draw_panel_hero ; No: the next hero
36A7 0F67 RTS ; Return: all four sections drawn

Plot a sprite in a hero's panel section

Plot sprite A at byte column X and pixel row Y + hero_panel_y - 14 for the hero panel_hero, the one draw_status_panel is drawing. Row 0 of a section is thus 14 rows above the health digits, which sit at the panel row itself. The panel row is read from workspace_template, whose copy in page &0D, made by reset_workspace, is hero_panel_y.

On EntryAsprite number
Xbyte column
Yrow within the hero's panel section
PANEL_HEROhero whose section it is (0-3)
On ExitAcorrupted
X0
Y0
LoadExec
36A8 0F68 .plot_panel_sprite←5← 0F0C JSR← 0F15 JSR← 0F25 JSR← 0F40 JSR← 0F5A JSR
STX plot_x ; Byte column from X
36AA 0F6A STA sprite_number ; Sprite from A
36AC 0F6C TYA ; Row = Y + this hero's panel row - 14...
36AD 0F6D LDX panel_hero ; ...for the hero being drawn...
36B0 0F70 CLC ; ...(carry clear for the add)
36B1 0F71 ADC workspace_template + 208,x ; ...(read from workspace_template, which page &0D copies)
36B4 0F74 SEC ; ...(no borrow into the subtract)
36B5 0F75 SBC #&0e ; ...less 14: row 0 is 14 above the health
36B7 0F77 STA plot_y ; ...is the plot row
36B9 0F79 JSR plot_sprite ; Plot the sprite in the hero's section
36BC 0F7C RTS ; Return; plot_sprite leaves X and Y 0
36BD 0F7D EQUB &00, &09, &60 ; Not referenced

Heroes' starting attributes

Four tables of one byte per hero (Ranger, Magic-User, Barbarian, Fighter): missiles in flight, missile damage, health lost per hit, and the face sprite for the panel.

LoadExec
; Starting hero_max_missiles for each hero: 3, 2, 1, 2.
36C0 0F80 .hero_start_max_missiles←1Used as index base by← 0ECF LDA
EQUB &03, &02, &01, &02
; Starting hero_missile_damage for each hero: 2, 3, 9, 5.
36C4 0F84 .hero_start_missile_damage←1Used as index base by← 0ED5 LDA
EQUB &02, &03, &09, &05
; Starting hero_damage_taken for each hero: 7, 9, 6, 4 ; (armour ratings 3, 1, 4, 6).
36C8 0F88 .hero_start_damage_taken←1Used as index base by← 0EDB LDA
EQUB &07, &09, &06, &04
; Sprite shown for each hero at the top left of their ; status panel section, plotted by draw_status_panel: &05, ; &31, &39, &41.
36CC 0F8C .hero_faces←1Used as index base by← 0F05 LDA
EQUB &05, &31, &39, &41

Game-over message

Eleven lines of seventeen characters, each ended by a carriage return, then a line feed and a last line ended by a zero byte. Two bytes of it (&0FF1, &0FF2) double as counters, and are overwritten with spaces before printing, so the full stop after "YOU ALL" never appears.

LoadExec
; The message printed when every hero has died, terminated ; by a zero byte.
36D0 0F90 .game_over_message←1Used as index base by← 0EAE LDA
EQUS "FAREWELL! ", &0D
36E2 0FA2 EQUS "THE QUEST HAS ", &0D
36F4 0FB4 EQUS "FAILED AND THE ", &0D
3706 0FC6 EQUS "GODS ARE IN NO ", &0D
3718 0FD8 EQUS "MOOD TO RESURRECT", &0D
; The "YOU ALL." line of game_over_message, whose bytes ; after the text double as panel_hero and count.
; Hero counter for draw_status_panel. It is the full stop ; of game_over_message's "YOU ALL.", which is overwritten ; with a space before the message is printed.
; Counter, used for the dead heroes at the end of a level ; and the rows of missile icons. It is a byte of ; game_over_message.
372A 0FEA .game_over_you_all
EQUS "YOU ALL. ", &0D
373C 0FFC EQUS "NEW ADVENTURERS ", &0D
374E 100E EQUS "MUST TAKE YOUR ", &0D
3760 1020 EQUS "PLACE,BEGINNING ", &0D
3772 1032 EQUS "BACK ON THE UPPER", &0D
3784 1044 EQUS "MOST LEVEL. ", &0D
3796 1056 EQUB &0A ; Line feed: a blank line
3797 1057 EQUS "FIND THE CHALICE!", &00

Unused

Leftover bytes: "ND!" and a zero, the end of an earlier message, then "&C2".

LoadExec
37A9 1069 EQUB &4E, &44, &21, &00, ; Not referenced &26, &43, &32

Check whether the Chalice has been found

End the game in victory when a hero reaches the Chalice. Called by play_level first in every frame, before update_game. On levels other than 25 return at once. On level 25, test each hero's hero_door_x, hero_door_y, the cell move_heroes recorded as the one they last stepped or tried to step into (kept even when a wall stops them, so walking into the Chalice is enough). If it is one of the Chalice's four cells, x &1A-&1B and y 4-5, the game is won: play victory_sequence, set a text window over the views (columns 0-16, rows 0-24, leaving the status panel), clear it, print the ending text, flush the keyboard buffer, wait for a key and call the MOS's reset code through the RESET vector, so this never returns.

The ending text is not part of the program: it is the 140 bytes at room_walls + &3A followed by the zero-terminated string at object_free_map + &3A, which on level 25 hold text instead of map data. Both lie clear of &0C00-&0C07, the definition of character 128 that wrch_handler rewrites for every letter or digit it prints. The Chalice's cells are fixed here, not read from the level's objects.

On ExitAcorrupted
Xcorrupted
Ypreserved
LoadExec
37B0 1070 .check_for_victory←1← 1F0A JSR
LDA level_number ; Which level is this?
37B3 1073 CMP #last_level ; The Chalice lies only on level 25
37B5 1075 BNE no_victory ; Another level: no Chalice to find
37B7 1077 LDX #0 ; Has a hero reached a Chalice cell, x &1A-&1B, y 4-5?
37B9 1079 .check_door_x←1← 1087 BNE
LDA hero_door_x,x ; The cell hero X last stepped or bumped into...
37BC 107C CMP #chalice_x ; ...in the Chalice's left column?
37BE 107E BEQ check_door_y ; Yes: check the row
37C0 1080 CMP #chalice_x + 1 ; ...or its right column?
37C2 1082 BEQ check_door_y ; Yes: check the row
37C4 1084 .next_hero_victory←1← 1095 BNE
INX ; Not at the Chalice: on to the next hero
37C5 1085 CPX #4 ; Past hero 3?
37C7 1087 BNE check_door_x ; No: check the next hero
37C9 1089 .no_victory←1← 1075 BNE
RTS ; No hero at the Chalice: on with the frame
37CA 108A .check_door_y←2← 107E BEQ← 1082 BEQ
LDA hero_door_y,x ; ...and that cell's row...
37CD 108D CMP #chalice_y ; ...in the Chalice's top row?
37CF 108F BEQ start_victory ; Yes: the Chalice is found
37D1 1091 CMP #chalice_y + 1 ; ...or its bottom row?
37D3 1093 BEQ start_victory ; Yes: the Chalice is found
37D5 1095 BNE next_hero_victory ; No: next hero
37D7 1097 .start_victory←2← 108F BEQ← 1093 BEQ
JSR victory_sequence ; Sparkles, rising tone, the Chalice dissolves
; The game is won. Over the views, print the ending text ; that level 25's maps hold, wait for a key, and reset.
37DA 109A LDA #&1c ; VDU 28,0,24,16,0: a window over the four views...
37DC 109C JSR oswrch ; Send VDU 28
37DF 109F LDA #0 ; Left column 0
37E1 10A1 JSR oswrch ; Send the left column
37E4 10A4 LDA #&18 ; Bottom row 24, the last on show
37E6 10A6 JSR oswrch ; Send the bottom row
37E9 10A9 LDA #&10 ; Right column 16: the status panel stays
37EB 10AB JSR oswrch ; Send the right column
37EE 10AE LDA #0 ; Top row 0
37F0 10B0 JSR oswrch ; Send the top row
37F3 10B3 LDA #&0c ; ...VDU 12 to clear it
37F5 10B5 JSR oswrch ; Clear the views for the ending text
; Print the ending text: 140 bytes of level 25's wall map, ; then its object-free map up to a zero.
37F8 10B8 LDX #0 ; The ending text: 140 bytes from room_walls + &3A...
37FA 10BA .print_victory_text←1← 10C3 BNE
LDA room_walls + 58,x ; Next byte of level 25's wall map, which is text
37FD 10BD JSR osasci ; Print it in the game's font
3800 10C0 INX ; On through the 140 bytes
3801 10C1 CPX #&8c ; All 140 printed?
3803 10C3 BNE print_victory_text ; No: print the next
3805 10C5 LDX #0 ; ...then the ending message, at object_free_map + &3A
3807 10C7 .print_ending_message←1← 10D0 BNE
LDA object_free_map + 58,x ; Next character of the ending message
380A 10CA JSR osasci ; Print it, the zero included
380D 10CD INX ; On along the message (X stays non-zero)
380E 10CE CMP #0 ; The zero that ends the message?
3810 10D0 BNE print_ending_message ; No: print the next
; Wait for a fresh key press, then reset the machine ; through the RESET vector.
3812 10D2 LDA #osbyte_flush_buffer_class ; OSBYTE &0F, X non-zero: flush the input buffer...
3814 10D4 JSR osbyte ; ...so keys pressed in the sequence cannot skip the text Flush selected class of buffer
3817 10D7 JSR osrdch ; Wait for a key once the ending text has been read
381A 10DA LDA reset_vector ; Aim the JSR below at the MOS's reset code...
381D 10DD STA reset_call_address ; ...the RESET vector's low byte as its operand's...
3820 10E0 LDA reset_vector + 1 ; ...and the vector's high byte...
3823 10E3 STA reset_call_address + 1 ; ...as its high: no MOS address built in
; Operand of the JSR at reset_call, set from the RESET ; vector.
3826 10E6 .reset_call
JSR &00 ; ...and call it: the game ends with a reset
fall through ↓

Play the victory sequence

Sparkles circle the Chalice to a rising, quickening bell tone, and the Chalice dissolves into black. Called by check_for_victory once a hero reaches the Chalice; play is frozen meanwhile, as nothing else runs.

Each pass sounds the bell, draws the ring of sparkles round the Chalice (draw_victory_ring), and waits. The bell's pitch climbs by a step each pass and wraps past 255, and each time it wraps the step grows by 1, so the tone repeats as ever faster sweeps: about 256 x (1 + 1/2 + ... + 1/50), some 1,150 passes in all. The wait starts at &E6 units of about 1,280 cycles each and shortens by one a pass down to 1, reached on pass 229, near the end of the first sweep; from then on each pass also calls dissolve_chalice, which clears a random byte of the Chalice when its random value is below &C0. After the 50th wrap (erase_victory_ring), erase the ring, clear whatever is left of the Chalice's sprite, replot it black, and wait 255 vertical syncs, about five seconds. The Chalice's sprite data stays cleared, as the game resets next.

OSBYTEs &D4 and &D5 set (old AND Y) EOR X, and Y is never set for them: the bell's envelope byte takes Y left over from the frame, and the first pitch takes the Y that OSBYTE &D4 returns; later passes have Y = 0 from the wait loop, so the pitch is exactly victory_pitch.

On ExitA0
Xcorrupted
Ycorrupted
LoadExec
3829 10E9 .victory_sequence←1← 1097 JSR
LDA #osbyte_bell_envelope ; OSBYTE &D4: the bell's envelope byte...
382B 10EB LDX #8 ; ...EOR 8; Y, not set, is the AND mask
382D 10ED JSR osbyte ; Set the bell's envelope for the victory tone osbyte: bell envelope
; Set up the sequence: no pixel offsets, the first ; sparkle, pitch 0 rising by 1, a wait of &E6, 50 sweeps.
3830 10F0 LDA #0 ; Plot the ring and Chalice square on their cells:
3832 10F2 STA plot_offset_x ; ...no x offset...
3834 10F4 STA plot_offset_y ; ...and no y offset
3836 10F6 LDA #spr_sparkle_0 ; The ring starts with the first sparkle
3838 10F8 STA victory_sprite ; ...as the ring's sprite
383A 10FA LDA #0 ; Tone starts at pitch 0...
383C 10FC STA victory_pitch ; ...for the bell
383E 10FE LDA #&e6 ; ...with the passes &E6 wait units apart...
3840 1100 STA victory_delay ; ...the delay loop's outer count
3842 1102 LDA #&32 ; ...for &32 (50) sweeps of the pitch...
3844 1104 STA victory_steps_left ; ...counted down as the pitch wraps
3846 1106 LDA #1 ; ...rising by 1 a pass in the first sweep
3848 1108 STA victory_pitch_step ; ...the pitch's first step
; One pass of the sequence: raise the pitch, shorten the ; wait, sound the bell, draw the ring, dissolve a byte of ; the Chalice once at full speed, and wait.
384A 110A .raise_victory_pitch←1← 1146 JMP
CLC ; Pitch = (pitch + step) mod 256, C set on a wrap...
384B 110B LDA victory_pitch ; ...the bell's current pitch...
384D 110D ADC victory_pitch_step ; ...plus this sweep's step...
384F 110F STA victory_pitch ; ...stored as the pitch for this pass
3851 1111 BCC shorten_victory_delay ; No wrap: the sweep goes on
3853 1113 INC victory_pitch_step ; Wrapped: the next sweep climbs one step faster...
3855 1115 DEC victory_steps_left ; ...and one fewer sweep is left
3857 1117 BNE shorten_victory_delay ; Sweeps left: go on
3859 1119 JMP erase_victory_ring ; 50 sweeps done: erase the ring and the Chalice
385C 111C .shorten_victory_delay←2← 1111 BCC← 1117 BNE
DEC victory_delay ; Shorten the wait: the passes come faster...
385E 111E BNE sound_victory_bell ; Not yet zero: keep it
3860 1120 LDA #1 ; ...but never below 1...
3862 1122 STA victory_delay ; ...the full speed the rest of the sequence runs at
3864 1124 .sound_victory_bell←1← 111E BNE
LDX victory_pitch ; OSBYTE &D5: the bell's pitch...
3866 1126 LDA #osbyte_bell_frequency ; ...set it from victory_pitch
3868 1128 JSR osbyte ; Set it: the bell now sounds at that pitch osbyte: bell frequency
386B 112B LDA #7 ; ...and sound the bell
386D 112D JSR oswrch ; Send BEL: the bell sounds at the new pitch
3870 1130 JSR draw_victory_ring ; Draw the ring, the sparkles one side further round
3873 1133 LDA victory_delay ; At full speed, dissolve the Chalice a byte at a time
3875 1135 CMP #1 ; Delay down to 1: the sequence is at full speed
3877 1137 BNE victory_delay_loop ; Not yet: just wait
3879 1139 JSR dissolve_chalice ; Full speed: clear one more byte of the Chalice
387C 113C .victory_delay_loop←1← 1137 BNE
LDX victory_delay ; Wait victory_delay units before the next pass
387E 113E .victory_delay_outer←1← 1144 BNE
LDY #&ff ; Each unit is 255 inner loops, about 1,280 cycles
3880 1140 .victory_delay_inner←1← 1141 BNE
DEY ; Count down the inner loop
3881 1141 BNE victory_delay_inner ; Until it reaches zero
3883 1143 DEX ; Count down the delay units
3884 1144 BNE victory_delay_outer ; Until the delay is spent (Y = 0 for the next OSBYTE)
3886 1146 JMP raise_victory_pitch ; Next pass: raise the pitch again

Draw the ring of sprites round the Chalice

Draw one frame of the sparkling ring. Called by victory_sequence once a pass, and once more with the blank sprite to erase the ring. Plot victory_sprite at the twelve cells round the Chalice's 2 x 2 block (x &19-&1C, y 3-6, all in the Chalice's room), from x &1C, y 3 leftwards along the top, down the left side, along the bottom and up the right side, three cells to a side, each corner starting a side. The sprite moves on to the next sparkle (next_victory_sprite) after each of the first three sides and is left at the fourth side's, so the next ring starts with it and the sparkles move one side round the ring each pass. With the blank sprite, it erases the ring.

On EntryVICTORY_SPRITEthe sprite for the top side
On ExitVICTORY_SPRITEthe sprite of the right side
Acorrupted
Xcorrupted
Ycorrupted
LoadExec
3889 1149 .draw_victory_ring←2← 1130 JSR← 11D7 JSR
LDA #chalice_x + 2 ; Start at x &1C, y 3: the ring runs round the Chalice's four cells
388B 114B STA ring_x ; ...as the ring's x...
388D 114D LDA #chalice_y - 1 ; ...one row above the Chalice...
388F 114F STA ring_y ; ...as the ring's y
3891 1151 JSR plot_victory_sprite ; Plot the top-right corner, first of the top side
3894 1154 DEC ring_x ; Left to x &1B, above the Chalice's right column
3896 1156 JSR plot_victory_sprite ; Plot the top side's second cell
3899 1159 DEC ring_x ; Left to x &1A, above its left column
389B 115B JSR plot_victory_sprite ; Plot the last of the top side's three
389E 115E LDA victory_sprite ; Keep the sprite...
38A0 1160 STA victory_sprite_copy ; ...in victory_sprite_copy, which nothing reads
38A3 1163 JSR next_victory_sprite ; ...and move to the next sparkle for the left side
38A6 1166 DEC ring_x ; Left to x &19: the top-left corner
38A8 1168 JSR plot_victory_sprite ; Plot it, first of the left side
38AB 116B INC ring_y ; Down to y 4, beside the Chalice's top row
38AD 116D JSR plot_victory_sprite ; Plot the left side's second cell
38B0 1170 INC ring_y ; Down to y 5, beside its bottom row
38B2 1172 JSR plot_victory_sprite ; Plot the left side's third cell
38B5 1175 JSR next_victory_sprite ; Next sparkle for the bottom side
38B8 1178 INC ring_y ; Down to y 6: the bottom-left corner
38BA 117A JSR plot_victory_sprite ; Plot it, first of the bottom side
38BD 117D INC ring_x ; Right to x &1A, below the Chalice's left column
38BF 117F JSR plot_victory_sprite ; Plot the bottom side's second cell
38C2 1182 INC ring_x ; Right to x &1B, below its right column
38C4 1184 JSR plot_victory_sprite ; Plot the bottom side's third cell
38C7 1187 JSR next_victory_sprite ; Next sparkle for the right side, kept for the next ring
38CA 118A INC ring_x ; Right to x &1C: the bottom-right corner
38CC 118C JSR plot_victory_sprite ; Plot it, first of the right side
38CF 118F DEC ring_y ; Up to y 5, beside the Chalice's bottom row
38D1 1191 JSR plot_victory_sprite ; Plot the right side's second cell
38D4 1194 DEC ring_y ; Up to y 4, beside its top row
38D6 1196 JSR plot_victory_sprite ; Plot the right side's third, closing the ring
38D9 1199 RTS ; Return, victory_sprite at the right side's sparkle

Plot a victory sprite at a cell

Plot victory_sprite at the cell ring_x, ring_y in every view showing it, with the pixel offsets victory_sequence cleared. Called by draw_victory_ring for each of the ring's twelve cells; ring_x and ring_y are left as they were, for the next step.

On EntryRING_Xcell x
RING_Ycell y
VICTORY_SPRITEthe sprite
On ExitAcorrupted
Xcorrupted
Ycorrupted
LoadExec
38DA 119A .plot_victory_sprite←12← 1151 JSR← 1156 JSR← 115B JSR← 1168 JSR← 116D JSR← 1172 JSR← 117A JSR← 117F JSR← 1184 JSR← 118C JSR← 1191 JSR← 1196 JSR
LDA ring_x ; Plot the victory sprite at the ring cell
38DC 119C STA cell_x ; ...as the cell's x
38DF 119F LDA ring_y ; ...and its y...
38E1 11A1 STA cell_y ; ...as the cell's y
38E4 11A4 LDA victory_sprite ; ...with the ring's current sprite...
38E6 11A6 STA sprite_number ; ...as the sprite to plot
38E8 11A8 JSR plot_at_cell ; ...in every view that shows the cell
38EB 11AB RTS ; Return to draw_victory_ring for the next cell

Choose the next victory sprite

Step victory_sprite through the four sparkles, &16-&19, wrapping back to &16. Called by draw_victory_ring between the ring's sides, so each side shows a different sparkle. The blank sprite, &15, used to erase the ring, is left alone, so an erasing ring stays blank all the way round.

On EntryVICTORY_SPRITEthe current sprite
On ExitVICTORY_SPRITEthe next sparkle, &16-&19 in turn; &15 (erasing) is kept
Avictory_sprite
Xpreserved
Ypreserved
LoadExec
38EC 11AC .next_victory_sprite←3← 1163 JSR← 1175 JSR← 1187 JSR
LDA victory_sprite ; Erasing (sprite &15)? Keep it
38EE 11AE CMP #spr_blank ; ...the blank sprite?
38F0 11B0 BEQ store_victory_sprite ; Yes: keep erasing
38F2 11B2 CLC ; Next sparkle, &16-&19 in turn
38F3 11B3 ADC #1 ; ...the next sparkle sprite
38F5 11B5 CMP #spr_sparkle_3 + 1 ; Past the last sparkle?
38F7 11B7 BNE store_victory_sprite ; No: use it
38F9 11B9 LDA #spr_sparkle_0 ; Yes: back to the first sparkle
38FB 11BB .store_victory_sprite←2← 11B0 BEQ← 11B7 BNE
STA victory_sprite ; Make it the ring's sprite
38FD 11BD RTS ; Return with A = victory_sprite

Clear a random byte of the Chalice

Eat one more hole in the Chalice. Called by victory_sequence on every pass once its wait is down to 1. Make a random number from the System VIA's timer 1 low byte mixed with two bytes of MOS workspace (&FC and &FA). If it is below &C0, the size of the Chalice's 8 x 24-byte sprite, zero that byte of sprite_chalice and replot the Chalice, so it dissolves into black a pixel pair at a time; otherwise do nothing this pass. A byte already clear may be chosen again, so some survive until erase_victory_ring clears the rest.

On ExitAcorrupted
Xcorrupted
Ycorrupted
LoadExec
38FE 11BE .dissolve_chalice←1← 1139 JSR
LDA system_via_t1c_l ; Pick a byte of the Chalice: System VIA timer 1...
3901 11C1 EOR os_irq_a ; ...mixed with the MOS's last interrupt A...
3903 11C3 EOR os_zp_fa ; ...and more MOS workspace, for randomness
3905 11C5 CMP #&c0 ; Within the Chalice's &C0 bytes?
3907 11C7 BCS dissolve_done ; No: nothing dissolves this pass
3909 11C9 TAX ; X = the chosen byte's offset in the sprite...
390A 11CA LDA #0 ; ...cleared to zero, a black pair of pixels...
390C 11CC STA sprite_chalice,x ; ...in the Chalice's sprite data
390F 11CF JSR plot_chalice ; ...and replot the Chalice with the hole in it
3912 11D2 .dissolve_done←1← 11C7 BCS
RTS ; Return to victory_sequence's wait
; The 50th sweep is done: erase the ring, clear the rest ; of the Chalice, and hold the scene for 255 vsyncs.
3913 11D3 .erase_victory_ring←1← 1119 JMP
LDA #spr_blank ; Erase the ring
3915 11D5 STA victory_sprite ; ...by making the blank the ring's sprite...
3917 11D7 JSR draw_victory_ring ; ...and drawing the ring with it
391A 11DA LDX #&c1 ; Clear what is left of the Chalice...
391C 11DC LDA #0 ; ...to zeros, black pixels
391E 11DE .clear_chalice_sprite←1← 11E2 BNE
STA sprite_chalice - 1,x ; Clear a byte of the Chalice's sprite data
3921 11E1 DEX ; Next byte down
3922 11E2 BNE clear_chalice_sprite ; &C1 bytes: the &C0 and the unused byte after
3924 11E4 JSR plot_chalice ; ...and replot it, now black: the Chalice is gone
3927 11E7 LDA #&ff ; Pause 255 vertical syncs (about five seconds)
3929 11E9 STA os_vsync_counter ; ...which the MOS counts down at each vsync
392C 11EC .wait_vsync_chalice←1← 11EF BNE
LDA os_vsync_counter ; Read the count
392F 11EF BNE wait_vsync_chalice ; Until it reaches zero
3931 11F1 RTS ; Return to check_for_victory for the ending text

Plot the Chalice

Plot sprite &73, the Chalice, at its top-left cell (x &1A, y 4) in every view showing it, as its sprite data now stands. Called by dissolve_chalice after each byte it clears, and at the end of victory_sequence to show it gone. The sprite is two cells wide and two high, so it covers the four cells check_for_victory tests. The pixel offsets are those victory_sequence cleared.

On ExitAcorrupted
Xcorrupted
Ycorrupted
LoadExec
3932 11F2 .plot_chalice←2← 11CF JSR← 11E4 JSR
LDA #chalice_x ; The Chalice's top-left cell, x &1A, y 4...
3934 11F4 STA cell_x ; ...as the cell's x
3937 11F7 LDA #chalice_y ; ...and y 4...
3939 11F9 STA cell_y ; ...as the cell's y
393C 11FC LDA #spr_chalice ; ...sprite &73, 2 x 2 cells...
393E 11FE STA sprite_number ; ...as the sprite to plot...
3940 1200 JSR plot_at_cell ; ...plotted in every view showing it
3943 1203 RTS ; Return with the Chalice drawn as its data stands

Unused

Leftover bytes, never read: &52 &78 &60 repeat the end of plot_chalice (JSR plot_at_cell's operand, then RTS), and the rest reads as a fragment of BASIC text, "(&1900+F".

LoadExec
3944 1204 EQUS "Rx`(&1900+F"
394F 120F EQUB &25 ; Not referenced

The Chalice sprite

Sprite &73: 8 bytes by 24 rows, two cells by two, plotted at x &1A, y 4 by plot_chalice. In the victory sequence dissolve_chalice zeros random bytes of it and erase_victory_ring zeros all of it (and the byte after); the game then ends in a reset.

LoadExec
; Data of sprite &73: 8 bytes x 24 rows.
3950 1210 .sprite_chalice←1Used as index base by← 11CC STA
EQUB &00, &00, &05, &0F, &0F, &0A, &00, &00, &00, &00, &0F, &07, &0B, &0F, &00, &00, &00, &05, &0B, &03, &03, &07, &0A, &00, &00, &0F, &07, &5A, &A5, &0B, &0F, &00, &00, &0F, &07, &0F, &0F, &0B, &0F, &00, &05, &0B, &0F, &00, &00, &0F, &07, &0A, &05, &0B, &0A, &00, &00, &05, &07, &0A, &0F, &07, &0E, &00, &00, &0D, &0B, &0F, &0F, &07, &04, &08, &04, &08, &0B, &0F, &0B, &07, &45, &0C, &0C, &8A, &0B, &07, &0F, &07, &00, &0C, &0C, &00, &0B, &0F, &5A, &07, &0C, &4D, &8E, &0C, &0B, &A5, &5A, &07, &0C, &4D, &8E, &0C, &0B, &A5, &0F, &07, &00, &0C, &0C, &00, &0B, &0F, &0B, &07, &45, &0C, &0C, &8A, &0B, &07, &0F, &07, &04, &08, &04, &08, &0B, &0F, &0F, &07, &0E, &00, &00, &0D, &0B, &0F, &05, &0B, &0A, &00, &00, &05, &07, &0A, &05, &0B, &0F, &00, &00, &0F, &07, &0A, &00, &0F, &07, &0F, &0F, &0B, &0F, &00, &00, &0F, &07, &5A, &A5, &0B, &0F, &00, &00, &05, &0B, &03, &03, &07, &0A, &00, &00, &00, &0F, &07, &0B, &0F, &00, &00, &00, &00, &05, &0F, &0F, &0A, &00, &00
3A10 12D0 EQUB &3D ; Written only by erase_victory_ring, whose clear of sprite_chalice runs one byte past its end
3A11 12D1 EQUB &26, &00 ; Not referenced
; The WRCHV contents found at start-up, restored while the ; game uses the MOS's own text output.
3A13 12D3 .saved_wrchv←2← 0D58 STA← 14D7 LDA
EQUB &A4 ; WRCHV as saved at start-up, low byte (&A4 as loaded)
3A14 12D4 EQUB &E0 ; ...and high byte (&E0 as loaded)
3A15 12D5 EQUB &00, &73 ; Not referenced

Font: letters A-Z

Eight bytes per letter, copied into the definition of character 128 by the WRCHV handler.

LoadExec
; The game's font for the letters A-Z: eight bytes per ; letter, one per pixel row, in MOS character-definition ; format.
3A17 12D7 .font_letters←1Used as index base by← 7FC5 LDA
EQUB %00111100 ; 'A'
3A18 12D8 EQUB %01000010
3A19 12D9 EQUB %01000010
3A1A 12DA EQUB %10001110
3A1B 12DB EQUB %11110010
3A1C 12DC EQUB %10000010
3A1D 12DD EQUB %11000110
3A1E 12DE EQUB %00000000
3A1F 12DF EQUB %01111000 ; 'B'
3A20 12E0 EQUB %01000100
3A21 12E1 EQUB %01000010
3A22 12E2 EQUB %10111100
3A23 12E3 EQUB %10000010
3A24 12E4 EQUB %10000010
3A25 12E5 EQUB %11111100
3A26 12E6 EQUB %00000000
3A27 12E7 EQUB %00111100 ; 'C'
3A28 12E8 EQUB %01000010
3A29 12E9 EQUB %01000000
3A2A 12EA EQUB %10000000
3A2B 12EB EQUB %10000000
3A2C 12EC EQUB %10000010
3A2D 12ED EQUB %01111100
3A2E 12EE EQUB %00000000
3A2F 12EF EQUB %01111100 ; 'D'
3A30 12F0 EQUB %10000010
3A31 12F1 EQUB %10000010
3A32 12F2 EQUB %10000010
3A33 12F3 EQUB %10000100
3A34 12F4 EQUB %10000100
3A35 12F5 EQUB %11111000
3A36 12F6 EQUB %00000000
3A37 12F7 EQUB %00001110 ; 'E'
3A38 12F8 EQUB %01110000
3A39 12F9 EQUB %01000000
3A3A 12FA EQUB %11001110
3A3B 12FB EQUB %11110000
3A3C 12FC EQUB %10000000
3A3D 12FD EQUB %11111110
3A3E 12FE EQUB %00000000
3A3F 12FF EQUB %00011110 ; 'F'
3A40 1300 EQUB %11100000
3A41 1301 EQUB %10000000
3A42 1302 EQUB %10001110
3A43 1303 EQUB %11110000
3A44 1304 EQUB %10000000
3A45 1305 EQUB %11000000
3A46 1306 EQUB %00000000
3A47 1307 EQUB %00111100 ; 'G'
3A48 1308 EQUB %01000010
3A49 1309 EQUB %01000010
3A4A 130A EQUB %10000000
3A4B 130B EQUB %10011110
3A4C 130C EQUB %10000010
3A4D 130D EQUB %01111110
3A4E 130E EQUB %00000000
3A4F 130F EQUB %01100010 ; 'H'
3A50 1310 EQUB %01000010
3A51 1311 EQUB %01000010
3A52 1312 EQUB %10011110
3A53 1313 EQUB %11100010
3A54 1314 EQUB %10000010
3A55 1315 EQUB %11000110
3A56 1316 EQUB %00000000
3A57 1317 EQUB %00011110 ; 'I'
3A58 1318 EQUB %00001000
3A59 1319 EQUB %00001000
3A5A 131A EQUB %00010000
3A5B 131B EQUB %00010000
3A5C 131C EQUB %00010000
3A5D 131D EQUB %01111100
3A5E 131E EQUB %00000000
3A5F 131F EQUB %11111110 ; 'J'
3A60 1320 EQUB %00000010
3A61 1321 EQUB %00000010
3A62 1322 EQUB %00000100
3A63 1323 EQUB %11000100
3A64 1324 EQUB %10000100
3A65 1325 EQUB %01111000
3A66 1326 EQUB %00000000
3A67 1327 EQUB %01000000 ; 'K'
3A68 1328 EQUB %01001110
3A69 1329 EQUB %01110000
3A6A 132A EQUB %10001000
3A6B 132B EQUB %10001000
3A6C 132C EQUB %10000100
3A6D 132D EQUB %11000010
3A6E 132E EQUB %00000000
3A6F 132F EQUB %01100000 ; 'L'
3A70 1330 EQUB %01000000
3A71 1331 EQUB %01000000
3A72 1332 EQUB %10000000
3A73 1333 EQUB %10000000
3A74 1334 EQUB %10000010
3A75 1335 EQUB %11111110
3A76 1336 EQUB %00000000
3A77 1337 EQUB %01000110 ; 'M'
3A78 1338 EQUB %01101110
3A79 1339 EQUB %01101010
3A7A 133A EQUB %11011010
3A7B 133B EQUB %10010010
3A7C 133C EQUB %10000010
3A7D 133D EQUB %11000110
3A7E 133E EQUB %00000000
3A7F 133F EQUB %01100110 ; 'N'
3A80 1340 EQUB %01010010
3A81 1341 EQUB %01010010
3A82 1342 EQUB %10001010
3A83 1343 EQUB %10001010
3A84 1344 EQUB %10001010
3A85 1345 EQUB %11000110
3A86 1346 EQUB %00000000
3A87 1347 EQUB %00111100 ; 'O'
3A88 1348 EQUB %01000010
3A89 1349 EQUB %01000010
3A8A 134A EQUB %10000010
3A8B 134B EQUB %10000010
3A8C 134C EQUB %10000010
3A8D 134D EQUB %01111100
3A8E 134E EQUB %00000000
3A8F 134F EQUB %01111100 ; 'P'
3A90 1350 EQUB %01000010
3A91 1351 EQUB %01000010
3A92 1352 EQUB %10111100
3A93 1353 EQUB %10000000
3A94 1354 EQUB %10000000
3A95 1355 EQUB %11000000
3A96 1356 EQUB %00000000
3A97 1357 EQUB %00111100 ; 'Q'
3A98 1358 EQUB %01000010
3A99 1359 EQUB %01000010
3A9A 135A EQUB %10011010
3A9B 135B EQUB %10001010
3A9C 135C EQUB %10000110
3A9D 135D EQUB %01111110
3A9E 135E EQUB %00000000
3A9F 135F EQUB %01111100 ; 'R'
3AA0 1360 EQUB %01000010
3AA1 1361 EQUB %01000010
3AA2 1362 EQUB %10111100
3AA3 1363 EQUB %10001000
3AA4 1364 EQUB %10000100
3AA5 1365 EQUB %11000010
3AA6 1366 EQUB %00000000
3AA7 1367 EQUB %00011110 ; 'S'
3AA8 1368 EQUB %00100010
3AA9 1369 EQUB %01000000
3AAA 136A EQUB %00111100
3AAB 136B EQUB %00000010
3AAC 136C EQUB %10000010
3AAD 136D EQUB %11111100
3AAE 136E EQUB %00000000
3AAF 136F EQUB %11111110 ; 'T'
3AB0 1370 EQUB %10010010
3AB1 1371 EQUB %00010000
3AB2 1372 EQUB %00100000
3AB3 1373 EQUB %00100000
3AB4 1374 EQUB %00100000
3AB5 1375 EQUB %01110000
3AB6 1376 EQUB %00000000
3AB7 1377 EQUB %01100110 ; 'U'
3AB8 1378 EQUB %01000010
3AB9 1379 EQUB %01000010
3ABA 137A EQUB %10000010
3ABB 137B EQUB %10000010
3ABC 137C EQUB %10000010
3ABD 137D EQUB %01111100
3ABE 137E EQUB %00000000
3ABF 137F EQUB %11000110 ; 'V'
3AC0 1380 EQUB %01000010
3AC1 1381 EQUB %01000010
3AC2 1382 EQUB %10000010
3AC3 1383 EQUB %10000100
3AC4 1384 EQUB %01001000
3AC5 1385 EQUB %00110000
3AC6 1386 EQUB %00000000
3AC7 1387 EQUB %01100110 ; 'W'
3AC8 1388 EQUB %01000010
3AC9 1389 EQUB %01000010
3ACA 138A EQUB %10010010
3ACB 138B EQUB %10101010
3ACC 138C EQUB %01001010
3ACD 138D EQUB %01000100
3ACE 138E EQUB %00000000
3ACF 138F EQUB %01100110 ; 'X'
3AD0 1390 EQUB %00100010
3AD1 1391 EQUB %00100100
3AD2 1392 EQUB %00011000
3AD3 1393 EQUB %00011000
3AD4 1394 EQUB %00100100
3AD5 1395 EQUB %11000110
3AD6 1396 EQUB %00000000
3AD7 1397 EQUB %10000110 ; 'Y'
3AD8 1398 EQUB %01000010
3AD9 1399 EQUB %00110010
3ADA 139A EQUB %00001100
3ADB 139B EQUB %00001000
3ADC 139C EQUB %00010000
3ADD 139D EQUB %01110000
3ADE 139E EQUB %00000000
3ADF 139F EQUB %01111110 ; 'Z'
3AE0 13A0 EQUB %00000010
3AE1 13A1 EQUB %00000100
3AE2 13A2 EQUB %00011000
3AE3 13A3 EQUB %00100000
3AE4 13A4 EQUB %01000010
3AE5 13A5 EQUB %11111110
3AE6 13A6 EQUB %00000000

Font: digits 0-9

Eight bytes per digit, copied into the definition of character 128 by the WRCHV handler.

LoadExec
; The game's font for the digits 0-9, in the same format ; as font_letters.
3AE7 13A7 .font_digits←1Used as index base by← 7FE8 LDA
EQUB %00111100 ; '0'
3AE8 13A8 EQUB %01000110
3AE9 13A9 EQUB %01001010
3AEA 13AA EQUB %10010010
3AEB 13AB EQUB %10100010
3AEC 13AC EQUB %11000100
3AED 13AD EQUB %01111000
3AEE 13AE EQUB %00000000
3AEF 13AF EQUB %00001000 ; '1'
3AF0 13B0 EQUB %00011000
3AF1 13B1 EQUB %00001000
3AF2 13B2 EQUB %00010000
3AF3 13B3 EQUB %00010000
3AF4 13B4 EQUB %00010000
3AF5 13B5 EQUB %00111100
3AF6 13B6 EQUB %00000000
3AF7 13B7 EQUB %00111100 ; '2'
3AF8 13B8 EQUB %01000010
3AF9 13B9 EQUB %00000010
3AFA 13BA EQUB %00001100
3AFB 13BB EQUB %00110000
3AFC 13BC EQUB %01000010
3AFD 13BD EQUB %11111100
3AFE 13BE EQUB %00000000
3AFF 13BF EQUB %01111110 ; '3'
3B00 13C0 EQUB %00000010
3B01 13C1 EQUB %00000100
3B02 13C2 EQUB %00011000
3B03 13C3 EQUB %00000110
3B04 13C4 EQUB %10000010
3B05 13C5 EQUB %01111100
3B06 13C6 EQUB %00000000
3B07 13C7 EQUB %00011000 ; '4'
3B08 13C8 EQUB %00101000
3B09 13C9 EQUB %01001000
3B0A 13CA EQUB %10010000
3B0B 13CB EQUB %11111100
3B0C 13CC EQUB %00010000
3B0D 13CD EQUB %00111000
3B0E 13CE EQUB %00000000
3B0F 13CF EQUB %00011111 ; '5'
3B10 13D0 EQUB %00100000
3B11 13D1 EQUB %00100000
3B12 13D2 EQUB %00011000
3B13 13D3 EQUB %00000100
3B14 13D4 EQUB %10000010
3B15 13D5 EQUB %01111100
3B16 13D6 EQUB %00000000
3B17 13D7 EQUB %00001110 ; '6'
3B18 13D8 EQUB %00010000
3B19 13D9 EQUB %00100000
3B1A 13DA EQUB %01111100
3B1B 13DB EQUB %10000010
3B1C 13DC EQUB %10000010
3B1D 13DD EQUB %01111100
3B1E 13DE EQUB %00000000
3B1F 13DF EQUB %01111110 ; '7'
3B20 13E0 EQUB %00000010
3B21 13E1 EQUB %00000010
3B22 13E2 EQUB %00000100
3B23 13E3 EQUB %00001000
3B24 13E4 EQUB %00010000
3B25 13E5 EQUB %01111000
3B26 13E6 EQUB %00000000
3B27 13E7 EQUB %00011100 ; '8'
3B28 13E8 EQUB %00100010
3B29 13E9 EQUB %00100010
3B2A 13EA EQUB %01111100
3B2B 13EB EQUB %10000010
3B2C 13EC EQUB %10000010
3B2D 13ED EQUB %01111100
3B2E 13EE EQUB %00000000
3B2F 13EF EQUB %00111100 ; '9'
3B30 13F0 EQUB %01000010
3B31 13F1 EQUB %01000010
3B32 13F2 EQUB %00111110
3B33 13F3 EQUB %00000010
3B34 13F4 EQUB %00000100
3B35 13F5 EQUB %00011000
3B36 13F6 EQUB %00000000

Unused

Leftover bytes, never read: a second copy of the digit 9's eight glyph rows, then &74.

LoadExec
3B37 13F7 EQUS "<BB>"
3B3B 13FB EQUB &02, &04, &18, &00, &74 ; Not referenced

Set up and draw a new level

Turn the next level's file into a fresh play screen. Called from the level loop (&0E57) at the start of every level; the loop then draws the status panel and plays the level.

In order: prepare the text area (the first call, which differs between releases), get the level file at &6B00 decrypted and checked, unpack it into the game's tables (unpack_level), put the heroes, missiles and views back to the start (reset_workspace), start the monsters dead and the heroes without keys (reset_monsters), then clear the screen, set the 6845 to show all 25 character rows the play screen uses, and draw the view frames and the four views (draw_view_frames). The order matters: any text printed before loading rewrites character 128's definition at &0C00, the start of room_walls, so the level is unpacked after it; and the level file lies in screen rows 23-24, so the screen is cleared only once the file is unpacked.

On ExitAcorrupted
Xcorrupted
Ycorrupted
LoadExec
3B40 1400 .start_level←1← 0E57 JSR
JSR clear_text_for_level ; Prepare the text area for the new level
3B43 1403 JSR check_level ; Get the level file at &6B00 decrypted and checked
3B46 1406 JSR unpack_level ; Copy its objects, doors, keys and maps into play
3B49 1409 JSR reset_workspace ; Put the heroes, missiles and views back to the start
3B4C 140C JSR reset_monsters ; Monsters to the trapdoors; heroes carry no keys
; Show the play screen: clear the text area, display all ; 25 character rows, then draw the frames and the views.
3B4F 140F JSR clear_text_area ; Clear the screen, LEVEL and all, for the play screen
3B52 1412 LDA #&17 ; VDU 23,0,6,25,0,0,0,0,0,0: set 6845 register 6...
3B54 1414 JSR oswrch ; Send VDU 23
3B57 1417 LDA #0 ; 0: a 6845 register setting follows
3B59 1419 JSR oswrch ; Send the 0
3B5C 141C LDA #6 ; Register 6: character rows displayed
3B5E 141E JSR oswrch ; Send the register number
3B61 1421 LDA #&19 ; ...to 25: the views and panel fill rows 0-24
3B63 1423 JSR oswrch ; Send it: show all 25 rows for play
3B66 1426 LDA #0 ; Six zero bytes complete the VDU 23
3B68 1428 JSR oswrch ; Send the first zero
3B6B 142B JSR oswrch ; Send the second zero
3B6E 142E JSR oswrch ; Send the third zero
3B71 1431 JSR oswrch ; Send the fourth zero
3B74 1434 JSR oswrch ; Send the fifth zero
3B77 1437 JSR oswrch ; Send the sixth zero
3B7A 143A LDA #<(view_frame_plots) ; (plot_x) points at the frames' PLOT commands...
3B7C 143C STA plot_x ; ...low byte in plot_x...
3B7E 143E LDA #>(view_frame_plots) ; ...and view_frame_plots' high byte...
3B80 1440 STA plot_y ; ...in plot_y, as draw_view_frames expects
3B82 1442 JSR draw_view_frames ; Draw the four frames, then the room in each view
3B85 1445 RTS ; Return to the level loop to draw the panel and play

Check the level and set the text window

Make the level Coder loaded ready for unpack_level. Called by start_level after clear_text_for_level: Coder has already put the file at &6B00-&6DAF. Decrypt it and check its checksum (decrypt_level resets the machine on a mismatch).

Then set the bottom row of clear_text_area's text window from 22 to 24. Dun1 stores it as 22, so that clear_text_for_level's clear stops at row 22, above the level file in rows 23-24; from here on the whole screen is cleared. Coder reloads Dun1 for each level, so the window is 22 again at the next level's start.

On ExitAcorrupted
Xcorrupted
Ycorrupted
LoadExec
3B86 1446 .check_level←1← 1403 JSR
JSR decrypt_level ; Decrypt and check the level Coder loaded at &6B00
3B89 1449 LDA #&18 ; Bottom row 24 for clear_text_area's window...
3B8B 144B STA text_window_bottom ; ...over the &16 in its VDU 28: the full 25 rows
3B8E 144E RTS ; Return to start_level: the level is ready to unpack

Restart the game by resetting the machine

End the game after all four heroes have died. Reached from level_loop's end once the game-over message has been shown for up to 5.8 seconds. Arm the BREAK intercept with a JMP to restart_intercept and branch to reset_machine, so that the reset runs *DUNJUNZ, which resets page &08, shows the title screen and runs Coder for a new game. Never returns.

LoadExec
3B8F 144F .restart_by_reset←1← 0ECC JMP
LDA #<(restart_intercept) ; Arm the BREAK intercept: JMP restart_intercept...
3B91 1451 STA os_break_intercept + 1 ; ...address low byte into &0288...
3B94 1454 LDA #>(restart_intercept) ; ...then the routine's page...
3B96 1456 STA os_break_intercept + 2 ; ...into &0289, the JMP's high byte
3B99 1459 LDA #&4c ; ...then the JMP opcode...
3B9B 145B STA os_break_intercept ; ...into &0287, which arms the intercept
3B9E 145E BNE reset_machine ; ...and reset (always taken: A = &4C)
fall through ↓

Move on to the next level by resetting the machine

End a level that at least one hero survived, by having the machine reset itself into Coder. Reached through to_next_level, after level_loop's end has given the dead heroes their starting attributes back. Arm the MOS BREAK intercept (&0287-&0289) with a JMP to next_level_intercept and jump to the MOS 1.20 reset entry at &D9CD; the MOS calls the intercept during the reset, and its second call runs *CODER, which reloads the game and the next level. Page &08 (levels_started, level_digits and the menu's tables) and &08C0-&0CFF (the heroes' attributes and scores) survive the reset and Coder's copy. Never returns.

LoadExec
3BA0 1460 .next_level_by_reset←1← 0E45 JMP
LDA #&4c ; Arm the BREAK intercept: a JMP opcode...
3BA2 1462 STA os_break_intercept ; ...into &0287, the intercept's first byte...
3BA5 1465 LDA #<(next_level_intercept) ; ...JMP to next_level_intercept: low byte...
3BA7 1467 STA os_break_intercept + 1 ; ...into &0288, the JMP's low byte
3BAA 146A LDA #>(next_level_intercept) ; ...then the routine's page...
3BAC 146C STA os_break_intercept + 2 ; ...into &0289: the intercept is armed
3BAF 146F .reset_machine←1← 145E BNE
JMP mos_reset_entry ; Reset: the MOS calls the intercept on the way

BREAK intercept: reload the game

Called twice by the MOS during the reset that restart_by_reset makes. The first call (carry clear) comes before the filing system is initialised and does nothing. On the second, clear the screen of the game-over message, select the disc filing system and *DUNJUNZ, which takes over and never returns.

On EntryCset on the second call, after the filing system is initialised
LoadExec
3BB2 1472 .restart_intercept
BCC restart_intercept_done ; First call (before the filing system): nothing to do
3BB4 1474 LDA #&0c ; VDU 12: clear the screen...
3BB6 1476 JSR oswrch ; ...of the game-over message
3BB9 1479 LDX #&89 ; *DISC: X, Y = &1489, the "DISC" after the C...
3BBB 147B LDY #&14 ; ...high byte of the command
3BBD 147D JSR oscli ; ...so that *DUNJUNZ comes from the disc
3BC0 1480 LDX #&8e ; *DUNJUNZ (at &148E): load the game afresh...
3BC2 1482 LDY #&14 ; ...high byte of the command
3BC4 1484 JSR oscli ; ...which takes over and never returns
3BC7 1487 .restart_intercept_done←1← 1472 BCC
RTS ; Return to the MOS

restart_intercept's commands

The *DISC and *DUNJUNZ command lines, read from &1489 and &148E (the C before DISC is not read). After them come stale bytes: STA &149C, LDA #&FF, JSR &3000, JMP &0450, the end of a level loader that calls FILEV's routine through a patched JSR.

LoadExec
3BC8 1488 EQUS "CDISC" ; "C" (not read), then "DISC" from &1489: *DISC
3BCD 148D EQUB &0D ; ...the CR ending *DISC
3BCE 148E EQUS "DUNJUNZ" ; "DUNJUNZ": *DUNJUNZ, for restart_intercept
3BD5 1495 EQUB &0D, &9C, &14, ; CR ending *DUNJUNZ; then stale &A9, &FF, &20, ; STA &149C, LDA #&FF... &00
3BDC 149C EQUS "0LP" ; ...JSR &3000, JMP &0450: never run
3BDF 149F EQUB &04 ; ...the JMP's high byte; not referenced

Reset the game workspace for a new level

Put the heroes, missiles and views back where every level starts. Called by start_level once a level, after unpack_level and before reset_monsters. Copy the 256 bytes of workspace_template (&7D00) over page &0D, the per-level workspace, then reset the exit animation's state, which lives in page &09: no hero going down the exit (exit_busy 0) or left shrunk (shrunk_hero &FF), the shrinking hero's pixel offsets (x 1, 1, 0, 0 and y 5, 3, 1, 0 for exit_shrinks_left 1-4), and trapdoor 0 as the next one a monster comes out of (next_trapdoor). Nothing here touches the heroes' health or scores, which carry over from level to level.

On ExitAcorrupted
Xcorrupted
Ypreserved
LoadExec
3BE0 14A0 .reset_workspace←1← 1409 JSR
LDX #0 ; Copy workspace_template to page &0D
3BE2 14A2 .copy_workspace_template←1← 14A9 BNE
LDA workspace_template,x ; Byte of the starting values...
3BE5 14A5 STA scratch,x ; ...becomes page &0D's byte
3BE8 14A8 INX ; Next of page &0D's 256 bytes
3BE9 14A9 BNE copy_workspace_template ; Until all 256 are copied: heroes back at the start
3BEB 14AB LDA #0 ; Reset the exit animation and the trapdoor turn
3BED 14AD STA exit_busy ; No hero is going down the exit
3BF0 14B0 STA exit_offset_x_3 ; Shrinking hero's x offset at shrink 3: 0...
3BF3 14B3 STA exit_offsets_y ; ...at shrink 4 (exit_offsets_y doubles as x 4)...
3BF6 14B6 STA exit_offset_y_4 ; ...and the y offset at shrink 4
3BF9 14B9 STA next_trapdoor ; First monster emerges from trapdoor 0
3BFC 14BC LDA #1 ; Offsets of 1 for the exit animation
3BFE 14BE STA exit_offset_x_1 ; ...x offset at shrink 1...
3C01 14C1 STA exit_offset_x_2 ; ...x offset at shrink 2...
3C04 14C4 STA exit_offset_y_3 ; ...and y offset at shrink 3
3C07 14C7 LDA #&ff ; &FF: no hero is shrunk
3C09 14C9 STA shrunk_hero ; ...so no hero's sprites need restoring
3C0C 14CC LDA #5 ; Shrinking hero's y offset at shrink 1: 5...
3C0E 14CE STA exit_offset_y_1 ; ...for y offset 1
3C11 14D1 LDA #3 ; ...and at shrink 2: 3
3C13 14D3 STA exit_offset_y_2 ; ...for y offset 2
3C16 14D6 RTS ; Return to start_level

Draw the frames round the four views

Draw the play screen's four view frames and the room in each view. Called last by start_level, with (plot_x) at view_frame_plots. WRCHV is first pointed back at the MOS's own routine (saved_wrchv), because wrch_handler swaps the code of any letter or digit for character 128, which would corrupt any PLOT coordinate byte that happens to be one. Then send the twenty five-byte commands as VDU 25s, call draw_all_views to draw the room each hero's view shows, and point WRCHV at wrch_handler again, so text that follows is in the game's font.

On EntryPLOT_Xaddress of view_frame_plots, low byte
PLOT_Yaddress of view_frame_plots, high byte
On ExitPLOT_Xadvanced by 100
Acorrupted
Xcorrupted
Ycorrupted
LoadExec
3C17 14D7 .draw_view_frames←1← 1442 JSR
LDA saved_wrchv ; Restore the MOS's own WRCHV for the PLOT commands...
3C1A 14DA STA wrchv ; ...saved_wrchv's low byte into WRCHV...
3C1D 14DD LDA saved_wrchv + 1 ; ...and its high byte...
3C20 14E0 STA wrchv + 1 ; ...so the PLOTs draw lines, not the game's font
3C23 14E3 LDX #&14 ; Twenty PLOT commands: five for each view's frame
3C25 14E5 .draw_view_frame←1← 1500 BNE
LDA #&19 ; Start a PLOT command: VDU 25...
3C27 14E7 JSR oswrch ; Send VDU 25: a PLOT command follows
3C2A 14EA LDY #0 ; ...then the five bytes of the command
3C2C 14EC .send_frame_vdu←1← 14F4 BNE
LDA (plot_x),y ; Next byte of this PLOT: K, then X and Y
3C2E 14EE JSR oswrch ; Send it to the VDU drivers
3C31 14F1 INY ; On to the command's next byte
3C32 14F2 CPY #5 ; All five sent?
3C34 14F4 BNE send_frame_vdu ; No: send the next
3C36 14F6 CLC ; Step (plot_x) on to the next command...
3C37 14F7 LDA plot_x ; ...its low byte...
3C39 14F9 ADC #5 ; ...plus five...
3C3B 14FB STA plot_x ; ...to the next PLOT (the table is all in one page)
3C3D 14FD LDY #0 ; Start the next PLOT at its first byte
3C3F 14FF DEX ; Count the PLOT done
3C40 1500 BNE draw_view_frame ; Until all twenty are drawn
3C42 1502 JSR draw_all_views ; Draw each hero's room inside their frame
3C45 1505 LDA #<(wrch_handler) ; Point WRCHV back at wrch_handler...
3C47 1507 STA wrchv ; ...its low byte into WRCHV...
3C4A 150A LDA #>(wrch_handler) ; ...and its high byte...
3C4C 150C STA wrchv + 1 ; ...so text is drawn in the game's font again
3C4F 150F RTS ; Return to start_level: frames and views drawn

Copy the loaded level into the game's tables

Bring the level just loaded into play. Called by start_level once the level file at &6B00 has been decrypted and checked, before reset_workspace. Copy objects 1-30 (position and type; the type is also the sprite), doors 1-20 (position and sprite), keys 1-20, trapdoors 0-7, &C9 bytes each of the wall map (into room_walls, read by test_wall) and object-free map (into object_free_map, read by test_object_free), and the level's 4 x 12 wall block into wall_sprite, sprite 0, the wall in every room. Entry 0 of the object, door and key tables is not touched. room_walls is also character 128's definition, which the game's text output overwrites, so this must follow the printing of the level number. The file itself lies in screen rows 23-24 and is wiped by start_level's clear_text_area once unpacked.

On ExitAcorrupted
Xcorrupted
Ypreserved
LoadExec
3C50 1510 .unpack_level←1← 1406 JSR
LDX #max_object ; Objects 30 to 1: position and type
3C52 1512 .unpack_objects←1← 1525 BNE
LDA level_object_x,x ; Object's x in the level file...
3C55 1515 STA object_x,x ; ...becomes its map x
3C58 1518 LDA level_object_y,x ; The object's y in the file...
3C5B 151B STA object_y,x ; ...becomes its map y
3C5E 151E LDA level_object_type,x ; Its type, which is also its sprite...
3C61 1521 STA object_type,x ; ...becomes its object type
3C64 1524 DEX ; Next object down
3C65 1525 BNE unpack_objects ; Until object 1 is done (entry 0 is unused)
3C67 1527 LDX #max_door ; Doors 20 to 1: position and sprite
3C69 1529 .unpack_doors←1← 153C BNE
LDA level_door_x,x ; Door's x in the level file...
3C6C 152C STA door_x,x ; ...becomes its map x
3C6F 152F LDA level_door_y,x ; The door's y in the file...
3C72 1532 STA door_y,x ; ...becomes its map y
3C75 1535 LDA level_door_sprite,x ; Its sprite, upright or across...
3C78 1538 STA door_sprite,x ; ...becomes its sprite
3C7B 153B DEX ; Next door down
3C7C 153C BNE unpack_doors ; Until door 1 is done
3C7E 153E LDX #max_key ; Keys 20 to 1: position
3C80 1540 .unpack_keys←1← 154D BNE
LDA level_key_x,x ; Key's x in the level file...
3C83 1543 STA key_x,x ; ...becomes its map x
3C86 1546 LDA level_key_y,x ; The key's y in the file...
3C89 1549 STA key_y,x ; ...becomes its map y
3C8C 154C DEX ; Next key down
3C8D 154D BNE unpack_keys ; Until key 1 is done
3C8F 154F LDX #0 ; Trapdoors 0 to 7: where dead monsters come back
3C91 1551 .unpack_trapdoors←1← 1560 BNE
LDA level_trapdoor_x,x ; Trapdoor's x in the level file...
3C94 1554 STA trapdoor_x,x ; ...becomes its map x
3C97 1557 LDA level_trapdoor_y,x ; The trapdoor's y in the file...
3C9A 155A STA trapdoor_y,x ; ...becomes its map y
3C9D 155D INX ; Next trapdoor up, 0 to 7
3C9E 155E CPX #8 ; All eight done?
3CA0 1560 BNE unpack_trapdoors ; No: copy the next
3CA2 1562 LDX #0 ; Wall map and object-free map, &C9 bytes each
3CA4 1564 .unpack_walls←1← 1573 BNE
LDA level_walls,x ; Byte of the level's wall map...
3CA7 1567 STA room_walls,x ; ...into room_walls, which test_wall reads
3CAA 156A LDA level_object_free_map,x ; Byte of the level's object-free map...
3CAD 156D STA object_free_map,x ; ...into object_free_map, which test_object_free reads
3CB0 1570 INX ; Next byte of both maps
3CB1 1571 CPX #map_bytes ; Both maps copied?
3CB3 1573 BNE unpack_walls ; No: copy the next
3CB5 1575 LDX #0 ; The level's own wall block, &30 bytes
3CB7 1577 .unpack_wall_sprite←1← 1580 BNE
LDA level_wall_sprite,x ; Byte of the level's wall block...
3CBA 157A STA wall_sprite,x ; ...becomes sprite 0, the wall in every room
3CBD 157D INX ; Next byte of the wall block
3CBE 157E CPX #&30 ; All 4 x 12 bytes copied?
3CC0 1580 BNE unpack_wall_sprite ; No: copy the next
3CC2 1582 RTS ; Return to start_level with the level unpacked

Clear the monsters for a new level

Start every monster dead and every hero empty-handed. Called by start_level after reset_workspace. Give monsters 1-30 the blank sprite (the first stage of dying) and an x off the map, so update_monsters brings each out of a trapdoor in turn, with monster_start_hit_points, the hit points level_loop set for this level. Then, for each of the four heroes, clear their returning_hero_queue entry, the key they carry (hero_key) and the swap flag (hero_key_dropped), and the cell kept for the door and Chalice checks (hero_door_x, hero_door_y), so nothing from the last level opens a door or wins the game. remove_absent_heroes refills the queue later for heroes nobody plays.

On ExitA0
X4
Ypreserved
LoadExec
3CC3 1583 .reset_monsters←1← 140C JSR
LDX #max_monster ; Monsters 30 to 1...
3CC5 1585 .reset_each_monster←1← 1596 BNE
LDA #spr_blank ; ...dying, so that they emerge from the trapdoors...
3CC7 1587 STA monster_sprite,x ; ...as monster X's sprite...
3CCA 158A LDA #off_map ; ...off the map...
3CCC 158C STA monster_x,x ; ...as monster X's x...
3CCF 158F LDA monster_start_hit_points ; ...with this level's hit points
3CD2 1592 STA monster_hit_points,x ; ...as monster X's hit points
3CD5 1595 DEX ; Next monster down
3CD6 1596 BNE reset_each_monster ; Until monster 1 is done
3CD8 1598 LDX #0 ; Each hero: clear queue place, key carried, door cell
3CDA 159A LDA #0 ; Zero for every entry cleared
3CDC 159C .clear_hero_carrying←1← 15AE BNE
STA returning_hero_queue,x ; Queue entry X empty: nobody waits to return
3CDF 159F STA hero_key,x ; Hero X carries no key
3CE2 15A2 STA hero_key_dropped,x ; ...and has swapped none
3CE5 15A5 STA hero_door_x,x ; No door-check cell...
3CE8 15A8 STA hero_door_y,x ; ...in x or y
3CEB 15AB INX ; Next hero, 0 to 3
3CEC 15AC CPX #4 ; All four done?
3CEE 15AE BNE clear_hero_carrying ; No: clear the next
3CF0 15B0 RTS ; Return to start_level, monsters and heroes reset

Clear the text area before a level

start_level's first call. Only clears the screen: no level number is shown, and level_number is not counted here (game_entry sets it from levels_started). At this point clear_text_area's window still ends at row 22, as Dun1 stores it, so the level file Coder loaded into rows 23-24 is kept for check_level; Dun1's other stored bytes in rows 0-22 are wiped.

On ExitAcorrupted
LoadExec
3CF1 15B1 .clear_text_for_level←1← 1400 JSR
JSR clear_text_area ; Clear rows 0-22: the level file in rows 23-24 is kept
3CF4 15B4 RTS ; Return to start_level, which checks the level next

BREAK intercept: run Coder for the next level

Called twice by the MOS during the reset that next_level_by_reset makes. The first call (carry clear) comes before the filing system is initialised and does nothing. On the second, select MODE 2, the disc filing system and *RUN CODER, which loads the next level and never returns. *DUNJUNZ also points the intercept at &15B5 while *CODER loads, so a BREAK then lands here too, but &15B5 holds this routine only if Coder has copied the game core there since power-on.

On EntryCset on the second call, after the filing system is initialised
LoadExec
3CF5 15B5 .next_level_intercept
BCC next_level_intercept_done ; First call (before the filing system): nothing to do
3CF7 15B7 LDA #&16 ; MODE 2, the game's mode, for Coder...
3CF9 15B9 JSR oswrch ; ...send VDU 22, select a mode...
3CFC 15BC LDA #2 ; ...then the mode number, 2...
3CFE 15BE JSR oswrch ; ...sent: MODE 2 is selected
3D01 15C1 LDX #&e0 ; *DISC: X, Y = &15E0, "DISC"...
3D03 15C3 LDY #&15 ; ...high byte of the command
3D05 15C5 JSR oscli ; ...so that Coder comes from the disc
3D08 15C8 LDX #&e5 ; *RUN CODER (at &15E5): the game and next level...
3D0A 15CA LDY #&15 ; ...high byte of the command
3D0C 15CC JSR oscli ; ...which never returns
3D0F 15CF .next_level_intercept_done←1← 15B5 BCC
RTS ; Return to the MOS

Unused, then next_level_intercept's commands

Stale bytes, never run: &15D2-&15D8 repeat next_level_intercept's LDX #&E5, LDY #&15, JSR OSCLI, and an RTS and "ODER" follow. Then the *DISC and *RUN CODER command lines read from &15E0 and &15E5, and more unused bytes.

LoadExec
3D10 15D0 EQUB &F7, &FF, &A2, &E5, &A0, ; Not referenced: stale &15, &20, &F7, &FF ; code
3D19 15D9 EQUS "`ODER" ; Not referenced: RTS, then "ODER"
3D1E 15DE EQUB &0D, &AD ; Not referenced
3D20 15E0 EQUS "DISC" ; "DISC": *DISC, for next_level_intercept
3D24 15E4 EQUB &0D ; ...the CR ending *DISC
3D25 15E5 EQUS "RUN CODER" ; "RUN CODER": *RUN CODER, for next_level_intercept
3D2E 15EE EQUB &0D, &0F, ; CR ending *RUN CODER; then two bytes &18 ; not referenced
3D31 15F1 EQUS "i0 " ; Not referenced
3D34 15F4 EQUB &EE, &FF, &A9, &1C, &20, &EE, &FF, &A9, ; Not &01, &20, &EE, &FF, &A9, &16, &20, &EE, ; refere &FF, &A9, &0E, &20, &EE, &FF, &A9, &11, ; nced &20, &EE, &FF, &A9, &11, &20, &EE, &FF, &A9, &02, &20, &EE, &FF, &60

Clear the screen

Clear the screen above the game code. Called twice for each level: by the routine start_level calls first, before the level is loaded, and by start_level itself before the play screen is drawn. Set a text window the full 20 columns wide from row 0 to the bottom row (24 in play), and clear it with VDU 12. The window never reaches below row 24 because MODE 2's rows 25-31, &6E80-&7FFF, hold game code. The window is left set, so later text and clears stay inside it.

On ExitAcorrupted
Xpreserved
Ypreserved
LoadExec
3D5A 161A .clear_text_area←2← 140F JSR← 15B1 JSR
LDA #&1c ; VDU 28: a text window over the whole screen...
3D5C 161C JSR oswrch ; Send VDU 28
3D5F 161F LDA #0 ; Left column 0
3D61 1621 JSR oswrch ; Send the left column
; The bottom row of clear_text_area's text window, an ; operand that check_level sets to &18.
3D64 1624 .set_text_window_bottom
LDA #&16 ; Bottom row of the window (24 in play)
3D66 1626 JSR oswrch ; Send the bottom row
3D69 1629 LDA #&13 ; Right column 19: the full MODE 2 width
3D6B 162B JSR oswrch ; Send the right column
3D6E 162E LDA #0 ; Top row 0
3D70 1630 JSR oswrch ; Send the top row
3D73 1633 LDA #&0c ; ...VDU 12 to clear it
3D75 1635 JSR oswrch ; Send it: the window clears to the background
3D78 1638 RTS ; Return with the window left set
3D79 1639 EQUB &60 ; Not referenced

View frame PLOT commands

Twenty five-byte VDU 25 commands (plot code, then x and y as 16-bit words) sent by draw_view_frames, five for each view's frame: PLOT 4 moves to the top-left corner, three PLOT 1s draw relative lines down 388, right 520 and up 388, and PLOT 5 draws back to the corner. The corners are (8,1022), (552,1022), (8,614) and (552,614); the second frame's first line is 389 long.

LoadExec
; Twenty VDU 25 (PLOT) commands, five bytes each (plot ; code, then x and y as 16-bit words), that draw the ; frames round the four views; read by draw_view_frames ; through (plot_x).
3D7A 163A .view_frame_plots
EQUB &04, &08, &00, &FE, &03, &01, &00, &00, &7C, &FE, &01, &08, &02, &00, &00, &01, &00, &00, &84, &01, &05, &08, &00, &FE, &03, &04, &28, &02, &FE, &03, &01, &00, &00, &7B, &FE, &01, &08, &02, &00, &00, &01, &00, &00, &84, &01, &05, &28, &02, &FE, &03, &04, &08, &00, &66, &02, &01, &00, &00, &7C, &FE, &01, &08, &02, &00, &00, &01, &00, &00, &84, &01, &05, &08, &00, &66, &02, &04, &28, &02, &66, &02, &01, &00, &00, &7C, &FE, &01, &08, &02, &00, &00, &01, &00, &00, &84, &01, &05, &28, &02, &66, &02
3DDE 169E EQUB &08 ; Not referenced
; The current level, 1-25, in binary. Set to 0 for a new ; game and counted up as each level starts. Read for the ; monsters' hit points (8 + 2 per level already played), ; for the level file's checksum entry (decrypt_level), and ; by check_for_victory, which looks for the Chalice only ; on level 25.
3DDF 169F .level_number←5← 0477 LDX (low_joystick)← 0477 LDX (low_keyboard)← 0D6D STA← 1070 LDA← 507A STA
EQUB &01

Sound the exit and add a queue marker

Play the exit's falling tone and queue a marker for the hero leaving. Called first by hero_enters_exit, when a hero steps onto the exit. Define envelope 3 from exit_envelope and play exit_sound with it (channel 2, pitch 250). Then put a &64 (nobody_returns) entry in the first empty (zero) entry of returning_hero_queue, behind any dead heroes waiting, as remove_absent_heroes does for each hero nobody plays. A Cross of Resurrection passes such markers to the back of the queue, so a hero who took the exit is never brought back by one. At most four of the queue's five entries are ever in use, so an empty one is always found; X is not bounded.

On ExitAcorrupted
Xcorrupted
Ycorrupted
LoadExec
3DE0 16A0 .queue_exit_marker←1← 203D JSR
LDX #<(exit_envelope) ; Envelope 3 for the exit: X = exit_envelope low...
3DE2 16A2 LDY #>(exit_envelope) ; ...Y = its high byte...
3DE4 16A4 LDA #osword_envelope ; ...OSWORD 8: ENVELOPE...
3DE6 16A6 JSR osword ; Define envelope 3: a falling pitch ENVELOPE command
3DE9 16A9 LDX #<(exit_sound) ; Play the exit sound: X = exit_sound low...
3DEB 16AB LDY #>(exit_sound) ; ...Y = its high byte...
3DED 16AD LDA #osword_sound ; ...OSWORD 7: SOUND...
3DEF 16AF JSR osword ; Sound channel 2 with envelope 3 SOUND command
3DF2 16B2 LDX #0 ; Append a marker to returning_hero_queue...
3DF4 16B4 .find_queue_end←1← 16C0 BNE
LDA returning_hero_queue,x ; Entry X of the queue
3DF7 16B7 BNE next_queue_entry ; In use: try the next
3DF9 16B9 LDA #nobody_returns ; Empty: add a &64 marker there
3DFB 16BB STA returning_hero_queue,x ; ...in the first empty entry, behind those waiting
3DFE 16BE RTS ; Return to hero_enters_exit
3DFF 16BF .next_queue_entry←1← 16B7 BNE
INX ; Next entry along the queue
3E00 16C0 BNE find_queue_end ; Keep looking (at most four entries are in use)
3E02 16C2 EQUB &02, &02, &00, &00, &83, &00, &00, &00, &00, &00, &00, &31, &00, &8D ; Not referenced
3E10 16D0 EQUS "LEVEL"
3E15 16D5 .level_filename_digits
EQUB &31
3E16 16D6 EQUB &0D, &0D, &70, &00, &8D, &35, &F8, &00, &00, &00, &00 ; Not referenced
3E21 16E1 EQUS "code"
3E25 16E5 EQUB &00, &54, &12, &03, &17, &74, &00, &8C, &50, &00, &00, &00, &FA, &16, &78, &00, &8C, &50, &20, &00, &00, &02, &00, &79, &00, &8C ; Not referenced
; The current level in binary-coded decimal (&01-&25), ; counted up with decimal arithmetic as each level starts, ; for printing the level number and for the digits of the ; level's filename.
3E3F 16FF .level_bcd←1← 0D72 STA
EQUB &01
fall through ↓

Sword sprites

Sprites &49-&4C, the Fighter's missile flying up, right, down and left: 4 bytes by 12 rows each.

LoadExec
; Data of sprite &49: 4 bytes x 12 rows.
3E40 1700 .sprite_sword_up
EQUB &00, &00, &00, &00, &00, &15, &00, &00, &00, &15, &00, &00, &00, &15, &00, &00, &00, &15, &00, &00, &00, &15, &00, &00, &00, &15, &00, &00, &00, &15, &00, &00, &00, &03, &02, &00, &00, &01, &00, &00, &00, &01, &00, &00, &00, &00, &00, &00
; Data of sprite &4A: 4 bytes x 12 rows.
3E70 1730 .sprite_sword_right
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &01, &00, &00, &01, &03, &3F, &3F, &00, &01, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
; Data of sprite &4B: 4 bytes x 12 rows.
3EA0 1760 .sprite_sword_down
EQUB &00, &00, &00, &00, &00, &00, &02, &00, &00, &00, &02, &00, &00, &01, &03, &00, &00, &00, &2A, &00, &00, &00, &2A, &00, &00, &00, &2A, &00, &00, &00, &2A, &00, &00, &00, &2A, &00, &00, &00, &2A, &00, &00, &00, &2A, &00, &00, &00, &00, &00
; Data of sprite &4C: 4 bytes x 12 rows.
3ED0 1790 .sprite_sword_left
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &02, &00, &3F, &3F, &03, &02, &00, &00, &02, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00

Unused

Leftover bytes, never read, including fragments of BASIC text ("?&A66=(rx%-lx%)", "sprite%?&A99=by%-ty%+1").

LoadExec
3F00 17C0 EQUB &80, &00, &00, &32, &00 ; Not referenced
3F05 17C5 EQUS "eco"
3F08 17C8 EQUB &00, &8E, &0B, &94, &00, &00 ; Not referenced
3F0E 17CE EQUS "?&A66=(rx%-lx%)"
3F1D 17DD EQUB &81 ; Not referenced
3F1E 17DE EQUS "2+1:sprite%?&A99=by%-ty%+1"
3F38 17F8 EQUB &0D, &03, &D4, &1D, &20, &D4, &31, ; Not &2C ; referenced

Panel sprites: the shield and the small digits

Sprite &69, the shield beside each hero's face in the status panel (3 bytes by 12 rows), then sprites &6A-&72, the small digits 1-9 (1 byte by 5 rows), which show the armour rating on the shield and the missile damage.

LoadExec
; Data of sprite &69: 3 bytes x 12 rows.
3F40 1800 .sprite_shield
EQUB &3F, &3F, &3E, &2A, &00, &14, &2A, &00, &14, &2A, &00, &14, &2A, &00, &14, &2A, &00, &14, &2A, &00, &14, &2A, &00, &14, &15, &00, &28, &15, &00, &28, &00, &3E, &00, &00, &3E, &00
; Data of sprite &6A: 1 bytes x 5 rows.
3F64 1824 .sprite_small_digit_1
EQUB &01, &01, &01, &01, &01
; Data of sprite &6B: 1 bytes x 5 rows.
3F69 1829 .sprite_small_digit_2
EQUB &03, &01, &03, &02, &03
; Data of sprite &6C: 1 bytes x 5 rows.
3F6E 182E .sprite_small_digit_3
EQUB &03, &01, &03, &01, &03
; Data of sprite &6D: 1 bytes x 5 rows.
3F73 1833 .sprite_small_digit_4
EQUB &02, &02, &03, &03, &01
; Data of sprite &6E: 1 bytes x 5 rows.
3F78 1838 .sprite_small_digit_5
EQUB &03, &02, &03, &01, &03
; Data of sprite &6F: 1 bytes x 5 rows.
3F7D 183D .sprite_small_digit_6
EQUB &02, &02, &03, &03, &03
; Data of sprite &70: 1 bytes x 5 rows.
3F82 1842 .sprite_small_digit_7
EQUB &03, &01, &01, &01, &01
; Data of sprite &71: 1 bytes x 5 rows.
3F87 1847 .sprite_small_digit_8
EQUB &03, &03, &03, &03, &03
; Data of sprite &72: 1 bytes x 5 rows.
3F8C 184C .sprite_small_digit_9
EQUB &03, &03, &03, &01, &01
3F91 1851 EQUB &0A, &00, &05, &00, &00, &00, &0A, &00, &05, &00, &00, &00, &0A, &00, &05 ; Not referenced

Panel sprites: the missile and boots icons

Sprite &74, the missile icon, one per missile a hero may have in flight (4 bytes by 3 rows), and sprite &75, the boots icon shown while a hero wears the Boots of Speed (2 bytes by 6 rows).

LoadExec
; Data of sprite &74: 4 bytes x 3 rows.
3FA0 1860 .sprite_missile_icon
EQUB &00, &00, &01, &00, &3F, &3F, &2B, &03, &00, &00, &01, &00
; Data of sprite &75: 2 bytes x 6 rows.
3FAC 186C .sprite_boots_icon
EQUB &00, &05, &00, &0A, &05, &00, &00, &0A, &05, &00, &0A, &00

The word LEVEL

Sprite &76, the word LEVEL for the level-number display: 12 bytes by 8 rows.

LoadExec
; Data of sprite &76: 12 bytes x 8 rows.
3FB8 1878 .sprite_level_word
EQUB &3C, &00, &14, &3C, &28, &28, &14, &14, &3C, &28, &3C, &00, &3C, &00, &14, &00, &00, &28, &14, &14, &00, &00, &3C, &00, &3C, &00, &14, &3C, &28, &3C, &3C, &14, &3C, &28, &3C, &00, &3C, &3C, &14, &00, &00, &3C, &3C, &14, &00, &00, &3C, &3C, &3C, &3C, &14, &3C, &28, &3C, &3C, &14, &3C, &28, &3C, &3C, &3C, &3C, &14, &3C, &28, &14, &28, &14, &3C, &28, &3C, &3C, &3C, &3C, &14, &3C, &28, &14, &28, &14, &3C, &28, &3C, &3C, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
4018 18D8 EQUB &08, &00, &04, &00, &00, &00, &08, &04, ; Not &00, &00, &08, &00, &0C, &0C, &04, &0C, ; refere &08, &00, &08, &04, &0C, &08, &0C, &0C, ; nced &1A, &35, &03, &8F, &7D, &9A, &82, &03, &00, &00, &00, &6D, &19, &00, &00, &00
; OSWORD 8 (ENVELOPE) parameter block for casting magic.
4040 1900 .magic_envelope
EQUB &03 ; Envelope 3
4041 1901 EQUB &01 ; Step length 1 centisecond
4042 1902 EQUB &0A, &0A, ; Pitch change per step in sections &EC ; 1-3: 10, 10, -20
4045 1905 EQUB &03, &03, ; Steps in pitch sections 1-3: 3, 3, 3 &03
4048 1908 EQUB &80, &00, ; Amplitude change per step in attack, &00, &FF ; decay, sustain, release: -128, 0, 0, ; -1
404C 190C EQUB &80, ; Target levels at the end of attack and &80 ; decay: 128, 128
; OSWORD 7 (SOUND) parameter block for casting magic.
404E 190E .magic_sound
EQUW &12, &03, 0, ; SOUND channel 2 (flush), envelope 2 ; 3, pitch 0, duration 2
; OSWORD 8 (ENVELOPE) parameter block for collecting ; treasure.
4056 1916 .treasure_envelope
EQUB &03 ; Envelope 3
4057 1917 EQUB &02 ; Step length 2 centiseconds
4058 1918 EQUB &01, &01, ; Pitch change per step in sections &01 ; 1-3: 1, 1, 1
405B 191B EQUB &01, &01, ; Steps in pitch sections 1-3: 1, 1, 1 &01
405E 191E EQUB &80, &00, ; Amplitude change per step in attack, &00, &F8 ; decay, sustain, release: -128, 0, 0, ; -8
4062 1922 EQUB &80, ; Target levels at the end of attack and &80 ; decay: 128, 128
; OSWORD 7 (SOUND) parameter block for collecting ; treasure.
4064 1924 .treasure_sound
EQUW &12, &03, ; SOUND channel 2 (flush), envelope 3, 200, 5 ; pitch 200, duration 5
; OSWORD 8 (ENVELOPE) parameter block for collecting an ; item.
406C 192C .pickup_envelope
EQUB &03 ; Envelope 3
406D 192D EQUB &80 ; Step length 0 centiseconds, no auto-repeat
406E 192E EQUB &00, &00, ; Pitch change per step in sections &00 ; 1-3: 0, 0, 0
4071 1931 EQUB &0A, &0A, ; Steps in pitch sections 1-3: 10, 10, &0A ; 10
4074 1934 EQUB &0A, &00, ; Amplitude change per step in attack, &00, &FD ; decay, sustain, release: 10, 0, 0, ; -3
4078 1938 EQUB &80, ; Target levels at the end of attack and &80 ; decay: 128, 128
; OSWORD 7 (SOUND) parameter block for collecting an item.
407A 193A .pickup_sound
EQUW &10, &03, 10, ; SOUND channel 0 (flush), 5 ; envelope 3, pitch 10, duration 5
; OSWORD 8 (ENVELOPE) parameter block for picking up a ; key.
4082 1942 .key_envelope
EQUB &03 ; Envelope 3
4083 1943 EQUB &80 ; Step length 0 centiseconds, no auto-repeat
4084 1944 EQUB &00, &00, ; Pitch change per step in sections &00 ; 1-3: 0, 0, 0
4087 1947 EQUB &01, &1E, ; Steps in pitch sections 1-3: 1, 30, &1E ; 30
408A 194A EQUB &80, &00, ; Amplitude change per step in attack, &00, &FE ; decay, sustain, release: -128, 0, 0, ; -2
408E 194E EQUB &80, ; Target levels at the end of attack and &80 ; decay: 128, 128
; OSWORD 7 (SOUND) parameter block for picking up a key.
4090 1950 .key_sound
EQUW &12, &03, ; SOUND channel 2 (flush), envelope 3, 240, 1 ; pitch 240, duration 1
; OSWORD 8 (ENVELOPE) parameter block for a hero going ; down the exit.
4098 1958 .exit_envelope
EQUB &03 ; Envelope 3
4099 1959 EQUB &82 ; Step length 2 centiseconds, no auto-repeat
409A 195A EQUB &FF, &FF, ; Pitch change per step in sections &FE ; 1-3: -1, -1, -2
409D 195D EQUB &01, &01, ; Steps in pitch sections 1-3: 1, 1, &80 ; 128
40A0 1960 EQUB &80, &00, ; Amplitude change per step in attack, &00, &FF ; decay, sustain, release: -128, 0, 0, ; -1
40A4 1964 EQUB &80, ; Target levels at the end of attack and &80 ; decay: 128, 128
; OSWORD 7 (SOUND) parameter block for a hero going down ; the exit.
40A6 1966 .exit_sound
EQUW &12, &03, ; SOUND channel 2 (flush), envelope 3, 250, 1 ; pitch 250, duration 1
40AE 196E EQUB &00, &00, &00, &00, &04 ; Not referenced
40B3 1973 EQUS "50:50:$"
40BA 197A EQUB &0C, &0C, &08, &00, &00, &00, &00, &00, &00, &00, &00, &00, &0A, &00, &00, &00, &00, &14, &34, &38, &03, &03 ; Not referenced
40D0 1990 EQUS "4<:%"
40D4 1994 EQUB &0F, &0F, &0F, &1E, ; Not referenced &31, &38, &03
40DB 199B EQUS "48<"
40DE 199E EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &04 ; Not referenced
40EB 19AB EQUS "5?:"
40EE 19AE EQUB &18, &3F, &3A, &0C, &0C, &08, &00, &00, &00, ; N &00, &00, &00, &00, &00, &00, &00, &35, &00 ; o ; t ; r ; e ; f ; e ; r ; e ; n ; c ; e ; d

Hero and death sprites

Sprite &08, the Ranger facing left (second frame), then sprites &64-&68, the skulls of a hero's death animation, the last of which is left where the hero fell; 4 bytes by 12 rows each.

LoadExec
; Data of sprite &08: 4 bytes x 12 rows.
4100 19C0 .sprite_ranger_left_1
EQUB &00, &01, &03, &00, &01, &0B, &08, &00, &01, &0E, &0C, &00, &03, &06, &3C, &00, &02, &03, &25, &28, &02, &05, &0F, &3C, &02, &05, &0F, &3C, &02, &00, &25, &29, &00, &00, &3C, &09, &00, &0A, &0C, &09, &00, &0E, &0C, &00, &00, &04, &00, &00
; Data of sprite &64: 4 bytes x 12 rows.
4130 19F0 .sprite_skull_0
EQUB &00, &00, &00, &00, &00, &3F, &00, &00, &00, &00, &00, &00, &15, &15, &2A, &2A, &2A, &3F, &3F, &15, &2A, &3F, &3F, &15, &2A, &35, &3A, &15, &2A, &15, &2A, &15, &2A, &00, &00, &2A, &2A, &00, &3F, &2A, &15, &00, &00, &2A, &15, &00, &00, &00
; Data of sprite &65: 4 bytes x 12 rows.
4160 1A20 .sprite_skull_1
EQUB &15, &2A, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &15, &15, &2A, &2A, &2A, &3F, &3F, &2A, &2A, &35, &3A, &15, &2A, &35, &3A, &15, &2A, &3F, &3F, &15, &00, &00, &00, &00, &00, &00, &00, &2A, &2A, &00, &00, &2A, &15, &15, &2A, &2A
; Data of sprite &66: 4 bytes x 12 rows.
4190 1A50 .sprite_skull_2
EQUB &00, &00, &00, &00, &00, &2A, &00, &00, &15, &00, &00, &00, &2A, &3F, &3F, &00, &00, &35, &35, &00, &15, &35, &35, &00, &15, &3F, &3F, &00, &15, &3A, &20, &15, &15, &00, &00, &15, &00, &2A, &00, &3F, &2A, &15, &15, &15, &15, &00, &2A, &00
; Data of sprite &67: 4 bytes x 12 rows.
41C0 1A80 .sprite_skull_3
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &15, &00, &00, &00, &3F, &2A, &00, &00, &35, &20, &00, &15, &35, &20, &2A, &3F, &3F, &3F, &00, &15, &3A, &2A, &15, &15, &00, &00, &2A, &15, &2A, &15, &00, &15, &3F, &2A, &00, &2A, &15, &3F, &2A
; Data of sprite &68: 4 bytes x 12 rows.
41F0 1AB0 .sprite_skull_4
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &15, &3F, &00, &00, &10, &3A, &00, &00, &10, &3A, &00, &00, &15, &3F, &15, &2A, &3F, &35, &2A, &15, &2A, &2A, &00, &00, &3F, &3F, &2A, &3F, &15, &2A, &15

Sprite tables

Four tables of 120 entries, indexed by sprite number: data address low bytes, high bytes, widths in bytes and heights in rows. Sprites may share data: the twelve energy-drainer sprites all point at sprite_drainer, and sprites &15, &1A and &77 at sprite_blank, zeros in page &04.

LoadExec
; Low bytes of the sprite data addresses, indexed by ; sprite number (120 entries).
4220 1AE0 .sprite_addr_lo←1Used as index base by← 0902 LDA
EQUB <(wall_sprite), <(sprite_ranger_up_0), <(sprite_ranger_up_1), <(sprite_ranger_right_0), <(sprite_ranger_right_1), <(sprite_ranger_down_0), <(sprite_ranger_down_1), <(sprite_ranger_left_0), <(sprite_ranger_left_1), <(sprite_monster_up_0), <(sprite_monster_up_1), <(sprite_monster_right_0), <(sprite_monster_right_1), <(sprite_monster_down_0), <(sprite_monster_down_1), <(sprite_monster_left_0), <(sprite_monster_left_1), <(sprite_arrow_up), <(sprite_arrow_right), <(sprite_arrow_down), <(sprite_arrow_left), <(sprite_blank), <(sprite_sparkle_0), <(sprite_sparkle_1), <(sprite_sparkle_2), <(sprite_sparkle_3), <(sprite_blank), <(sprite_key), <(sprite_door_vertical), <(sprite_door_horizontal), <(sprite_digit_0), <(sprite_digit_1), <(sprite_digit_2), <(sprite_digit_3), <(sprite_digit_4), <(sprite_digit_5), <(sprite_digit_6), <(sprite_digit_7), <(sprite_digit_8), <(sprite_digit_9), <(sprite_treasure), <(sprite_food), <(sprite_cross), <(sprite_teleporter), <(sprite_trapdoor), <(sprite_magic_user_up_0), <(sprite_magic_user_up_1), <(sprite_magic_user_right_0), <(sprite_magic_user_right_1), <(sprite_magic_user_down_0), <(sprite_magic_user_down_1), <(sprite_magic_user_left_0), <(sprite_magic_user_left_1), <(sprite_barbarian_up_0), <(sprite_barbarian_up_1), <(sprite_barbarian_right_0), <(sprite_barbarian_right_1), <(sprite_barbarian_down_0), <(sprite_barbarian_down_1), <(sprite_barbarian_left_0), <(sprite_barbarian_left_1), <(sprite_fighter_up_0), <(sprite_fighter_up_1), <(sprite_fighter_right_0), <(sprite_fighter_right_1), <(sprite_fighter_down_0), <(sprite_fighter_down_1), <(sprite_fighter_left_0), <(sprite_fighter_left_1), <(sprite_fireball_up), <(sprite_fireball_right), <(sprite_fireball_down), <(sprite_fireball_left), <(sprite_sword_up), <(sprite_sword_right), <(sprite_sword_down), <(sprite_sword_left), <(sprite_axe_up), <(sprite_axe_right), <(sprite_axe_down), <(sprite_axe_left), <(sprite_exit), <(sprite_key_icon), <(sprite_drainer), <(sprite_drainer), <(sprite_drainer), <(sprite_drainer), <(sprite_drainer), <(sprite_drainer), <(sprite_drainer), <(sprite_drainer), <(sprite_drainer), <(sprite_drainer), <(sprite_drainer), <(sprite_drainer), <(sprite_boots), <(sprite_helmet), <(sprite_potion), <(sprite_weapons), <(sprite_magic_sword), <(sprite_skull_0), <(sprite_skull_1), <(sprite_skull_2), <(sprite_skull_3), <(sprite_skull_4), <(sprite_shield), <(sprite_small_digit_1), <(sprite_small_digit_2), <(sprite_small_digit_3), <(sprite_small_digit_4), <(sprite_small_digit_5), <(sprite_small_digit_6), <(sprite_small_digit_7), <(sprite_small_digit_8), <(sprite_small_digit_9), <(sprite_chalice), <(sprite_missile_icon), <(sprite_boots_icon), <(sprite_level_word), <(sprite_blank)
; High bytes of the sprite data addresses, indexed by ; sprite number.
4298 1B58 .sprite_addr_hi←1Used as index base by← 0907 LDA
EQUB >(wall_sprite), >(sprite_ranger_up_0), >(sprite_ranger_up_1), >(sprite_ranger_right_0), >(sprite_ranger_right_1), >(sprite_ranger_down_0), >(sprite_ranger_down_1), >(sprite_ranger_left_0), >(sprite_ranger_left_1), >(sprite_monster_up_0), >(sprite_monster_up_1), >(sprite_monster_right_0), >(sprite_monster_right_1), >(sprite_monster_down_0), >(sprite_monster_down_1), >(sprite_monster_left_0), >(sprite_monster_left_1), >(sprite_arrow_up), >(sprite_arrow_right), >(sprite_arrow_down), >(sprite_arrow_left), >(sprite_blank), >(sprite_sparkle_0), >(sprite_sparkle_1), >(sprite_sparkle_2), >(sprite_sparkle_3), >(sprite_blank), >(sprite_key), >(sprite_door_vertical), >(sprite_door_horizontal), >(sprite_digit_0), >(sprite_digit_1), >(sprite_digit_2), >(sprite_digit_3), >(sprite_digit_4), >(sprite_digit_5), >(sprite_digit_6), >(sprite_digit_7), >(sprite_digit_8), >(sprite_digit_9), >(sprite_treasure), >(sprite_food), >(sprite_cross), >(sprite_teleporter), >(sprite_trapdoor), >(sprite_magic_user_up_0), >(sprite_magic_user_up_1), >(sprite_magic_user_right_0), >(sprite_magic_user_right_1), >(sprite_magic_user_down_0), >(sprite_magic_user_down_1), >(sprite_magic_user_left_0), >(sprite_magic_user_left_1), >(sprite_barbarian_up_0), >(sprite_barbarian_up_1), >(sprite_barbarian_right_0), >(sprite_barbarian_right_1), >(sprite_barbarian_down_0), >(sprite_barbarian_down_1), >(sprite_barbarian_left_0), >(sprite_barbarian_left_1), >(sprite_fighter_up_0), >(sprite_fighter_up_1), >(sprite_fighter_right_0), >(sprite_fighter_right_1), >(sprite_fighter_down_0), >(sprite_fighter_down_1), >(sprite_fighter_left_0), >(sprite_fighter_left_1), >(sprite_fireball_up), >(sprite_fireball_right), >(sprite_fireball_down), >(sprite_fireball_left), >(sprite_sword_up), >(sprite_sword_right), >(sprite_sword_down), >(sprite_sword_left), >(sprite_axe_up), >(sprite_axe_right), >(sprite_axe_down), >(sprite_axe_left), >(sprite_exit), >(sprite_key_icon), >(sprite_drainer), >(sprite_drainer), >(sprite_drainer), >(sprite_drainer), >(sprite_drainer), >(sprite_drainer), >(sprite_drainer), >(sprite_drainer), >(sprite_drainer), >(sprite_drainer), >(sprite_drainer), >(sprite_drainer), >(sprite_boots), >(sprite_helmet), >(sprite_potion), >(sprite_weapons), >(sprite_magic_sword), >(sprite_skull_0), >(sprite_skull_1), >(sprite_skull_2), >(sprite_skull_3), >(sprite_skull_4), >(sprite_shield), >(sprite_small_digit_1), >(sprite_small_digit_2), >(sprite_small_digit_3), >(sprite_small_digit_4), >(sprite_small_digit_5), >(sprite_small_digit_6), >(sprite_small_digit_7), >(sprite_small_digit_8), >(sprite_small_digit_9), >(sprite_chalice), >(sprite_missile_icon), >(sprite_boots_icon), >(sprite_level_word), >(sprite_blank)
; Sprite widths in screen bytes, indexed by sprite number.
4310 1BD0 .sprite_widths←3Used as index base by← 090C LDA← 2009 DEC← 205F STA
EQUB &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &02, &04, &04, &04, &02, &02, &02, &02, &02, &02, &02, &02, &02, &02, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &02, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &04, &03, &01, &01, &01, &01, &01, &01, &01, &01, &01, &08, &04, &02, &0C, &02
; Sprite heights in pixel rows, indexed by sprite number.
4388 1C48 .sprite_heights←4Used as index base by← 0911 LDA← 2015 LDA← 201A STA← 206C STA
EQUB &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &03, &0C, &0C, &0C, &0A, &0A, &0A, &0A, &0A, &0A, &0A, &0A, &0A, &0A, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &03, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &05, &05, &05, &05, &05, &05, &05, &05, &05, &18, &03, &06, &08, &06

Run one frame of play

Do all of a frame's play apart from the exit. Called by play_level once a frame, after check_for_victory; play_level deals with the exit when this returns. The work, in order:

  1. move_heroes: each hero in play walks, fires or casts magic, is redrawn, and picks up any object in their cell. It records in hero_door_x/y the cell each hero stepped or tried to step into.

  2. Doors (check_doors): for each hero in turn, doors 20 to 1 are compared with that cell. If one is there and the hero carries its key (key n opens door n; hero_key 0 means none, and there is no door 0), the door opens: the hero scores 7 points, the door sound plays (food_sound at a lower pitch), the door is erased from every view, its wall bit in room_walls is cleared, its entry in door_x/door_y is moved off the map, and the key is used up and its panel icon erased. At most one door opens per hero per frame. Every hero is tested, in play or not.

  3. Keys (draw_keys): every key on the floor is redrawn, then each hero is checked. A dead hero whose death animation has finished drops their key where they fell. A hero in play, or still dying, who stands on a key picks it up and leaves the key they carried, if any, in its place; hero_key_dropped makes them skip the next frame, so one who stays on the cell swaps back on the frame after.

  4. draw_objects: the objects are replotted, repairing any cell a moving sprite has crossed.

  5. move_missiles: each missile in flight moves one cell and hits what it meets.

  6. update_monsters: the trapdoors are redrawn and the monsters move.

  7. The pause key: if it is held, the game freezes here until it is pressed again. OSBYTE &7A reports only the lowest-numbered key held, so a held movement key can hide it.

On ExitAcorrupted
Xcorrupted
Ycorrupted
LoadExec
4400 1CC0 .update_game←1← 1F0D JSR
JSR move_heroes ; Move the heroes: steps, shots, magic, pick-ups
; Doors: for each hero, find a door at the cell they last ; stepped or tried to step into, and open it if they carry ; its key.
4403 1CC3 LDX #0 ; For each hero, 0-3...
4405 1CC5 .check_doors←1← 1DBF JMP
STX scratch ; ...hero number in scratch, for the door's points
4408 1CC8 LDA hero_door_x,x ; The cell hero X last stepped or bumped into...
440B 1CCB STA cell_x ; ...is the cell to test
440E 1CCE LDA hero_door_y,x ; ...and its y...
4411 1CD1 STA cell_y ; ...is the cell's y
4414 1CD4 TXA ; Keep the hero's number...
4415 1CD5 PHA ; ...on the stack for the key check
4416 1CD6 LDX #max_door ; Doors 20 to 1: is one in that cell?
4418 1CD8 .check_door←1← 1DB5 JMP
LDA door_x,x ; This door's x (&FF once opened)...
441B 1CDB CMP cell_x ; ...the cell being tested?
441E 1CDE BEQ check_door_cell_y ; Yes: check its y
4420 1CE0 JMP next_door ; No: next door
4423 1CE3 .check_door_cell_y←1← 1CDE BEQ
LDA door_y,x ; This door's y (&FF once opened)...
4426 1CE6 CMP cell_y ; ...the cell being tested?
4429 1CE9 BEQ check_door_key ; Yes: the hero has walked into this door
442B 1CEB JMP next_door ; No: next door
442E 1CEE .check_door_key←1← 1CE9 BEQ
PLA ; Does the hero carry this door's key?
442F 1CEF TAY ; Y = the hero's number...
4430 1CF0 PHA ; ...kept on the stack
4431 1CF1 TXA ; A = the door's number: key n opens door n
4432 1CF2 CMP hero_key,y ; Is it the number of the key the hero carries?
4435 1CF5 BEQ open_door ; Yes: open door
4437 1CF7 JMP next_door ; No key, or the wrong one: the door stays shut
; The hero has the key: score 7, sound the door, erase it, ; clear its wall bit, and use up the key.
443A 1CFA .open_door←1← 1CF5 BEQ
TXA ; Open the door: 7 points...
443B 1CFB PHA ; Keep the door's number...
443C 1CFC TYA ; ...and the hero's...
443D 1CFD PHA ; ...on the stack
443E 1CFE LDY #7 ; Seven points, one per add_point call
4440 1D00 LDX scratch ; ...X = the hero who opened the door, for add_point
4443 1D03 .door_points_loop←1← 1D0B BNE
TYA ; Keep the count of points still to give
4444 1D04 PHA ; ...on the stack, as add_point uses Y
4445 1D05 JSR add_point ; One point to the hero's score, redrawn
4448 1D08 PLA ; Recover the count of points to give
4449 1D09 TAY ; ...back into Y
444A 1D0A DEY ; One fewer to give
444B 1D0B BNE door_points_loop ; More to give: add the next point
; The door sound: food_sound played at a lower pitch.
444D 1D0D LDA #&96 ; The door sound is the food sound, lower...
444F 1D0F STA food_sound + 4 ; ...pitch 150 instead of food's 200
4452 1D12 LDX #<(food_sound) ; SOUND food_sound: block address low...
4454 1D14 LDY #>(food_sound) ; ...and high: the door sound's block
4456 1D16 LDA #osword_sound ; OSWORD 7: SOUND
4458 1D18 JSR osword ; Sound the door opening SOUND command
445B 1D1B LDA #&c8 ; ...then put food's pitch back...
445D 1D1D STA food_sound + 4 ; ...to 200, for the next food eaten
; Erase the door from every view showing it, keeping its ; cell in monster_x + 35 and monster_y + 35 across ; plot_at_cell, which overwrites cell_x and cell_y.
4460 1D20 LDA cell_y ; Save the door's cell; plot_at_cell changes cell_x/y...
4463 1D23 STA monster_y + 35 ; ...y into the spare byte at monster_y + 35...
4466 1D26 LDA cell_x ; ...then the door's x...
4469 1D29 STA monster_x + 35 ; ...into the spare byte at monster_x + 35
446C 1D2C LDA #spr_blank ; Erase the door from the screen...
446E 1D2E STA sprite_number ; ...the blank as the sprite to plot
4470 1D30 LDA #0 ; ...squarely on the door's cell...
4472 1D32 STA plot_offset_x ; ...no shift across (plot_offset_x 0)...
4474 1D34 STA plot_offset_y ; ...or down (plot_offset_y 0)
4476 1D36 JSR plot_at_cell ; Blank the door in every view showing its room
4479 1D39 LDA monster_x + 35 ; ...and recover its cell
447C 1D3C STA cell_x ; ...back into cell_x...
447F 1D3F LDA monster_y + 35 ; ...then the door's y...
4482 1D42 STA cell_y ; ...back into cell_y
4485 1D45 PLA ; Recover the hero number pushed at open_door...
4486 1D46 TAY ; ...into Y, unused: Y is the wall row index below
4487 1D47 PLA ; Recover the door number...
4488 1D48 TAX ; ...into X, to remove its entry once the wall is gone
; Clear the door's bit in room_walls, so test_wall no ; longer stops heroes, monsters or missiles there.
4489 1D49 LDA cell_y ; Door's room: (y AND &F8) x 4 + (x AND &F8)...
448C 1D4C AND #&f8 ; ...y AND &F8: the room's top row, 8 rows a room...
448E 1D4E STA scratch ; ...kept in scratch to add three more times
4491 1D51 CLC ; ...clear carry for the adds
4492 1D52 ADC scratch ; ...x 2...
4495 1D55 ADC scratch ; ...x 3...
4498 1D58 ADC scratch ; ...x 4: 32 bytes per row of four rooms
449B 1D5B STA map_ptr ; ...kept in map_ptr
449D 1D5D LDA cell_x ; ...plus the room column...
44A0 1D60 AND #&f8 ; ...x AND &F8: 8 bytes per room...
44A2 1D62 ADC map_ptr ; ...added to the row of rooms' offset...
44A4 1D64 STA map_ptr ; ...giving the room's offset in room_walls
44A6 1D66 LDA #>(room_walls) ; ...plus room_walls' page...
44A8 1D68 STA map_ptr_hi ; ...in map_ptr_hi: map_ptr points at the room
44AA 1D6A TXA ; Keep the door number...
44AB 1D6B PHA ; ...on the stack while X is used for the bit
44AC 1D6C LDA cell_x ; ...mask for the column...
44AF 1D6F AND #7 ; ...x AND 7, the cell's column in the room...
44B1 1D71 TAX ; ...as the index into bit_masks...
44B2 1D72 LDA bit_masks,x ; ...for the cell's bit in its row byte...
44B5 1D75 EOR #&ff ; ...inverted, to keep every other wall...
44B7 1D77 STA scratch ; ...as the mask to clear it with
44BA 1D7A LDA cell_y ; ...byte for the row...
44BD 1D7D AND #7 ; ...y AND 7, the cell's row in the room...
44BF 1D7F TAY ; ...indexes the room's eight row bytes
44C0 1D80 LDA (map_ptr),y ; ...the row of walls holding the door...
44C2 1D82 AND scratch ; ...knock out the door's bit...
44C5 1D85 STA (map_ptr),y ; ...so the doorway no longer blocks anyone
44C7 1D87 PLA ; Recover the door number...
44C8 1D88 TAX ; ...into X, to index door_x and door_y
; Remove the door from door_x/door_y and use up the key, ; erasing its icon from the hero's panel.
44C9 1D89 LDA #off_map ; Take the door out of the level...
44CB 1D8B STA door_x,x ; ...x off the map: no hero matches it again...
44CE 1D8E STA door_y,x ; ...and y off the map
44D1 1D91 PLA ; Recover the hero number pushed at check_doors...
44D2 1D92 TAX ; ...into X, for their key slot and panel
44D3 1D93 LDA #0 ; The key is used up: the hero carries none
44D5 1D95 STA hero_key,x ; ...in the hero's key slot
44D8 1D98 LDA #spr_blank_key_icon ; Erase the key icon from the hero's panel
44DA 1D9A STA sprite_number ; ...as the sprite to plot
44DC 1D9C LDA hero_panel_y,x ; ...from the hero's panel row...
44DF 1D9F SEC ; ...set carry to subtract
44E0 1DA0 SBC #&0d ; ...less 13: the key icon's row...
44E2 1DA2 STA plot_y ; ...as plot_y, the icon's screen row
44E4 1DA4 LDA #panel_left + 5 ; ...in panel column panel_left + 5...
44E6 1DA6 STA plot_x ; ...as plot_x, the icon's column
44E8 1DA8 TXA ; Keep the hero number...
44E9 1DA9 PHA ; ...on the stack across plot_sprite
44EA 1DAA JSR plot_sprite ; Plot the blank icon over the key icon
44ED 1DAD PLA ; Recover the hero number...
44EE 1DAE TAX ; ...into X, for next_hero_doors
44EF 1DAF JMP next_hero_doors ; One door a frame per hero: on to the next hero
44F2 1DB2 .next_door←3← 1CE0 JMP← 1CEB JMP← 1CF7 JMP
DEX ; Next door down, 20 to 1
44F3 1DB3 BEQ doors_done ; Doors all checked: this hero is done
44F5 1DB5 JMP check_door ; Otherwise check the next door
44F8 1DB8 .doors_done←1← 1DB3 BEQ
PLA ; Recover the hero number pushed at check_doors...
44F9 1DB9 TAX ; ...into X, to move on from this hero
44FA 1DBA .next_hero_doors←1← 1DAF JMP
INX ; Next hero, 0 to 3
44FB 1DBB CPX #4 ; All four heroes done?
44FD 1DBD BEQ draw_keys ; Yes: on to the keys
44FF 1DBF JMP check_doors ; No: check this hero against the doors
; Keys. Redraw the keys on the floor, then for each hero: ; drop a dead hero's key where they fell, or pick up the ; key at the hero's cell, leaving any key carried in its ; place. The swap flag only skips the frame after a swap, ; so a hero who stays on the cell swaps back on the frame ; after that. The heroes were drawn earlier in the frame, ; so a key under a hero is drawn over them.
4502 1DC2 .draw_keys←1← 1DBD BEQ
LDA #0 ; Redraw every key lying on the floor, 20 to 1
4504 1DC4 STA plot_offset_x ; ...on their cells: no pixel offset...
4506 1DC6 STA plot_offset_y ; ...across or down: keys sit squarely in cells
4508 1DC8 LDA #spr_key ; ...in the key sprite...
450A 1DCA STA sprite_number ; ...as the sprite to plot
450C 1DCC LDX #max_key ; ...counting keys down from 20; entry 0 is never drawn
450E 1DCE .draw_each_key←1← 1DE2 BNE
LDA key_x,x ; The key's x...
4511 1DD1 STA cell_x ; ...is the column to plot at...
4514 1DD4 LDA key_y,x ; ...and y (off the map if it is carried)...
4517 1DD7 STA cell_y ; ...the row: plot_at_cell needs both each time
451A 1DDA TXA ; Keep the key number...
451B 1DDB PHA ; ...on the stack across plot_at_cell
451C 1DDC JSR plot_at_cell ; Plot it in every view showing its cell
451F 1DDF PLA ; Recover the key number...
4520 1DE0 TAX ; ...into X, counting down the keys
4521 1DE1 DEX ; Next key down
4522 1DE2 BNE draw_each_key ; More keys: draw the next
4524 1DE4 LDX #0 ; For each hero, from hero 0...
4526 1DE6 .check_hero_keys←1← 1ECB JMP
LDA hero_direction,x ; Still in play (a direction set)?
4529 1DE9 BNE check_key_swap ; Yes: look for a key to pick up
452B 1DEB LDA hero_key,x ; Out of play: dead, dying or gone. Holding a key?
452E 1DEE BNE check_death_finished ; Yes: see whether the death has played out
4530 1DF0 JMP next_hero_keys ; No key: nothing to do for this hero
4533 1DF3 .check_death_finished←1← 1DEE BNE
LDA hero_frame,x ; Has the death animation reached its end?
4536 1DF6 CMP #8 ; ...frame 8 is the last of the death
4538 1DF8 BNE check_key_swap ; Still dying: key checks go on as if in play
; A dead hero's death animation has ended: leave their key ; on the cell where they fell and erase its icon.
453A 1DFA LDY hero_key,x ; Yes: drop the key where the hero fell
453D 1DFD LDA hero_x,x ; ...at the hero's x...
4540 1E00 STA key_x,y ; ...as the key's x...
4543 1E03 LDA hero_y,x ; ...and the hero's y...
4546 1E06 STA key_y,y ; ...as the key's y
4549 1E09 LDA #0 ; The dead hero carries no key now...
454B 1E0B STA hero_key,x ; ...so this is done only once
454E 1E0E LDA #spr_blank_key_icon ; Erase the key icon from the hero's panel
4550 1E10 STA sprite_number ; ...as the sprite to plot
4552 1E12 LDA hero_panel_y,x ; ...using the hero's panel row...
4555 1E15 SEC ; ...set carry to subtract
4556 1E16 SBC #&0d ; ...less 13: the key icon's row...
4558 1E18 STA plot_y ; ...as plot_y, the icon's screen row
455A 1E1A LDA #panel_left + 5 ; ...in panel column panel_left + 5...
455C 1E1C STA plot_x ; ...as plot_x, the icon's column
455E 1E1E TXA ; Keep the hero number...
455F 1E1F PHA ; ...on the stack across plot_sprite
4560 1E20 JSR plot_sprite ; Plot the blank icon over the key icon
4563 1E23 PLA ; Recover the hero number...
4564 1E24 TAX ; ...into X, for next_hero_keys
4565 1E25 JMP next_hero_keys ; Key dropped: on to the next hero
4568 1E28 .check_key_swap←2← 1DE9 BNE← 1DF8 BNE
LDA hero_key_dropped,x ; Swapped keys on the last frame?
456B 1E2B BEQ check_key_cell ; No: look for a key at the hero's cell
456D 1E2D LDA #0 ; Yes: skip this frame, clearing the flag
456F 1E2F STA hero_key_dropped,x ; ...so next frame's check may swap again
4572 1E32 JMP next_hero_keys ; ...and move on to the next hero
; Look for a key at the hero's cell, keys 20 to 1; the ; first found is picked up.
4575 1E35 .check_key_cell←1← 1E2B BEQ
LDA hero_x,x ; Is there a key at the hero's cell? Its x...
4578 1E38 STA cell_x ; ...in cell_x, for each key's x to match...
457B 1E3B LDA hero_y,x ; ...and the hero's y...
457E 1E3E STA cell_y ; ...in cell_y, for each key's y
4581 1E41 TXA ; Keep the hero number...
4582 1E42 PHA ; ...on the stack while X counts the keys
4583 1E43 LDX #max_key ; ...keys 20 to 1; entry 0 is never picked up
4585 1E45 .check_key←1← 1EC1 JMP
LDA key_x,x ; This key's x...
4588 1E48 CMP cell_x ; ...at the hero's x?
458B 1E4B BNE next_key ; No: try the next key
458D 1E4D LDA key_y,x ; ...and its y...
4590 1E50 CMP cell_y ; ...at the hero's y?
4593 1E53 BNE next_key ; No: try the next key
4595 1E55 LDA #spr_blank ; Yes: pick it up, erasing it from the floor
4597 1E57 STA sprite_number ; ...as the sprite to plot...
4599 1E59 LDA #0 ; ...squarely on the key's cell...
459B 1E5B STA plot_offset_x ; ...no shift across (plot_offset_x 0)...
459D 1E5D STA plot_offset_y ; ...or down (plot_offset_y 0)
459F 1E5F TXA ; Keep the key number...
45A0 1E60 PHA ; ...on the stack across plot_at_cell
45A1 1E61 JSR plot_at_cell ; Blank the key in every view showing it
45A4 1E64 PLA ; Recover the key number...
45A5 1E65 TAX ; ...into X: the key being picked up
45A6 1E66 PLA ; Show the key icon in the hero's panel: hero...
45A7 1E67 TAY ; ...into Y, to index hero_panel_y...
45A8 1E68 PHA ; ...and back on the stack for later
45A9 1E69 LDA #spr_key_icon ; ...in the key icon sprite...
45AB 1E6B STA sprite_number ; ...as the sprite to plot
45AD 1E6D LDA hero_panel_y,y ; ...from the hero's panel row...
45B0 1E70 SEC ; ...set carry to subtract
45B1 1E71 SBC #&0d ; ...less 13: the key icon's row...
45B3 1E73 STA plot_y ; ...as plot_y, the icon's screen row
45B5 1E75 LDA #panel_left + 5 ; ...in panel column panel_left + 5...
45B7 1E77 STA plot_x ; ...as plot_x, the icon's column
45B9 1E79 TYA ; Keep the hero number...
45BA 1E7A PHA ; ...on the stack...
45BB 1E7B TXA ; ...and the key number...
45BC 1E7C PHA ; ...both kept across plot_sprite
45BD 1E7D JSR plot_sprite ; Plot the key icon
45C0 1E80 PLA ; Recover the key number...
45C1 1E81 TAX ; ...into X: the key to carry...
45C2 1E82 PLA ; ...and the hero number...
45C3 1E83 TAY ; ...into Y: the hero picking it up
; The swap: the key carried (or unused entry 0) goes on ; the floor here, the new one is carried and taken off the ; map, and hero_key_dropped makes the next frame pass this ; hero by.
45C4 1E84 TXA ; Drop the key carried (if any) in this cell...
45C5 1E85 PHA ; ...keeping the new key's number on the stack...
45C6 1E86 LDX hero_key,y ; ...the old key, or unseen entry 0 if none...
45C9 1E89 LDA hero_x,y ; ...goes to the hero's x...
45CC 1E8C STA key_x,x ; ...as its x...
45CF 1E8F LDA hero_y,y ; ...and the hero's y...
45D2 1E92 STA key_y,x ; ...as its y
45D5 1E95 PLA ; Recover the new key's number...
45D6 1E96 TAX ; ...into X, and in A to carry
45D7 1E97 STA hero_key,y ; ...and carry the new one
45DA 1E9A LDA #1 ; Mark the swap
45DC 1E9C STA hero_key_dropped,y ; ...so the dropped key is left alone next frame
45DF 1E9F LDA #off_map ; Take the new key off the floor
45E1 1EA1 STA key_x,x ; ...x off the map, so draw_keys skips it...
45E4 1EA4 STA key_y,x ; ...and y off the map
45E7 1EA7 LDX #<(key_envelope) ; Sound the pickup: ENVELOPE key_envelope low...
45E9 1EA9 LDY #>(key_envelope) ; ...and high: the pickup's envelope block
45EB 1EAB LDA #osword_envelope ; OSWORD 8: ENVELOPE
45ED 1EAD JSR osword ; Define the key pickup envelope ENVELOPE command
45F0 1EB0 LDX #<(key_sound) ; SOUND key_sound: block address low...
45F2 1EB2 LDY #>(key_sound) ; ...and high: the pickup's sound block
45F4 1EB4 LDA #osword_sound ; OSWORD 7: SOUND
45F6 1EB6 JSR osword ; Play the key pickup sound SOUND command
45F9 1EB9 PLA ; Recover the hero number...
45FA 1EBA TAX ; ...into X, for next_hero_keys
45FB 1EBB JMP next_hero_keys ; One key a frame per hero: next hero
45FE 1EBE .next_key←2← 1E4B BNE← 1E53 BNE
DEX ; Next key down, 20 to 1
45FF 1EBF BEQ keys_done ; Keys all checked: this hero is done
4601 1EC1 JMP check_key ; Otherwise check the next key
4604 1EC4 .keys_done←1← 1EBF BEQ
PLA ; Recover the hero number pushed at check_key_cell...
4605 1EC5 TAX ; ...into X, to move on from this hero
4606 1EC6 .next_hero_keys←4← 1DF0 JMP← 1E25 JMP← 1E32 JMP← 1EBB JMP
INX ; Next hero, 0 to 3
4607 1EC7 CPX #4 ; All four heroes done?
4609 1EC9 BEQ update_rest ; Yes: on with the rest of the frame
460B 1ECB JMP check_hero_keys ; No: check this hero's keys
; The rest of the frame: objects, missiles, monsters, then ; the pause key.
460E 1ECE .update_rest←1← 1EC9 BEQ
JSR draw_objects ; Draw the objects over the floor
4611 1ED1 JSR move_missiles ; Move the missiles a cell each
4614 1ED4 JSR update_monsters ; Move the monsters
; The pause key, last in each frame's update. OSBYTE &7A ; reports a single key, so P is seen only when the scan ; finds it rather than another key held with it. Play ; resumes as soon as P is pressed again; if it is still ; held at the next frame's check, the game pauses again.
4617 1ED7 LDA #osbyte_scan_keyboard_from_16 ; OSBYTE &7A: which key is held, if any?
4619 1ED9 JSR osbyte ; Scan keyboard from key 16
461C 1EDC CPX #&37 ; P (internal key &37)?
461E 1EDE BNE not_paused ; No: on with play
4620 1EE0 .wait_pause_release←1← 1EE5 BEQ
JSR osbyte ; Paused: wait for P to be released... Scan keyboard from key 16
4623 1EE3 CPX #&37 ; ...is P still the key held?
4625 1EE5 BEQ wait_pause_release ; Yes: keep waiting
4627 1EE7 .wait_pause_press←1← 1EEC BNE
JSR osbyte ; ...then pressed again Scan keyboard from key 16
462A 1EEA CPX #&37 ; ...is P held again yet?
462C 1EEC BNE wait_pause_press ; No: stay paused
462E 1EEE LDA #&10 ; Next frame in 17 vsyncs, not the usual 3...
4630 1EF0 STA os_vsync_counter ; ...about a third of a second before play resumes
4633 1EF3 .not_paused←1← 1EDE BNE
RTS ; Return to play_level: this frame's update is done
4634 1EF4 EQUB &F9, &60 ; Not referenced

Unused

Zero bytes, which nothing reads.

LoadExec
4636 1EF6 EQUB &00, &00, &00, &00, &00, &00 ; Zeros

Unused

Four &3C bytes, "<<<<", which nothing reads.

LoadExec
463C 1EFC EQUS "<<<<" ; Not referenced

Play a level until it ends

The game's frame loop: play the current level until it is over. Called once per level by new_game's level loop, after the level is drawn, the status panel set up and absent heroes removed; when it returns, new_game gives each dead hero their starting attributes back, ending the game if all four died.

A frame, in order:

  1. Wait for os_vsync_counter, which the MOS counts down at every vertical sync, to go negative, then set it to 2. Frames start three vsyncs apart (about 17 a second), or at once if a frame's work took longer.

  2. check_for_victory: on level 25, a hero at the Chalice wins the game, and it never returns.

  3. update_game: heroes, doors, keys, objects, missiles, monsters and the pause key, in that order (see its banner).

  4. The level-end test, skipped while a hero is going down the exit (exit_busy). The level is over when every hero is out of play (direction 0) and no dead hero's death animation is still short of frame 8; heroes who went down the exit, or whom nobody plays, count as out of play. shrunk_hero's sprites are then restored and the loop returns.

  5. check_exit: the first hero found standing on the exit drops their key beside it (drop_key), is taken out of play, erased and moved off the map (hero_x &FF), and the exit itself is moved off the map, its cell kept in exit_saved_x/y, so no other hero can enter it meanwhile. hero_enters_exit then starts the descent and jumps back to the top of the loop.

  6. While exit_busy is set, redraw_exit draws one step of the descent: the exit sprite on its cell, then the hero on it turned a quarter, through up, right, down and left. On the fifth frame of each turn only the exit is drawn and the hero's sprites shrink by a byte and three rows (shrink_hero_width/height), drawn from then on with exit_offsets_x/y to keep them near the cell's centre. After four turns, 20 frames in all, restore_exit puts the exit back and clears exit_busy, so another hero can use it.

How the level ends: hero_enters_exit is entered with JSR but leaves with a JMP to play_level, so each descent leaves a return address (into check_exit at &1F8E) on the stack. The RTS at the level's end therefore returns into check_exit once for each hero who left by the exit; each such return runs one more full frame before the next RTS, and only the last returns to new_game.

On ExitAcorrupted
Xcorrupted
Ycorrupted
LoadExec
; Pace the game: start a frame every three vsyncs.
4640 1F00 .play_level←7← 0E65 JSR← 1F03 BPL← 1F9B JMP← 1FEF JMP← 2023 JMP← 2037 JMP← 208E JMP
LDA os_vsync_counter ; Wait for the vertical sync counter to pass zero...
4643 1F03 BPL play_level ; Not yet negative: keep waiting
4645 1F05 LDA #2 ; ...and set it for three syncs from now
4647 1F07 STA os_vsync_counter ; ...in the MOS's vertical sync counter
; This frame's play: the Chalice on level 25, then all but ; the exit (update_game).
464A 1F0A JSR check_for_victory ; On level 25: has a hero reached the Chalice?
464D 1F0D JSR update_game ; Run a frame: heroes, keys, objects, monsters
; Is the level over? Never while a hero is going down the ; exit; otherwise when every hero is out of play and no ; death animation is still running.
4650 1F10 LDA exit_busy ; A hero going down the exit?
4653 1F13 BNE check_exit ; Yes: the level goes on
4655 1F15 LDX #4 ; Is any hero in play, or still dying? Heroes 3 to 0
4657 1F17 .count_heroes_in_play←1← 1F2B BNE
LDA hero_direction - 1,x ; In play (a direction set)?
465A 1F1A BNE check_exit ; Yes: the level goes on
465C 1F1C LDA hero_health_tens - 1,x ; Out of play: dead...
465F 1F1F CMP #spr_digit_0 - 1 ; ...(health tens digit below 0)...
4661 1F21 BNE next_hero_in_play ; No: alive but out of play; next hero
4663 1F23 LDA hero_frame - 1,x ; ...with the death animation unfinished?
4666 1F26 CMP #8 ; ...frame 8 is the last of the death
4668 1F28 BCC check_exit ; Yes: the level goes on
466A 1F2A .next_hero_in_play←1← 1F21 BNE
DEX ; Next hero down (X is the hero + 1)
466B 1F2B BNE count_heroes_in_play ; More heroes: check the next
466D 1F2D LDX shrunk_hero ; The level is over: restore the last exiting hero's sprites
4670 1F30 BMI play_level_done ; None (&FF): nothing to restore
4672 1F32 JSR restore_hero_sprites ; Give them back their full-size sprites
4675 1F35 .play_level_done←1← 1F30 BMI
RTS ; Return, perhaps into this loop at &1F8E
; Look for a hero on the exit. The first found leaves ; their key beside it, leaves play and the map, and starts ; down; the exit is hidden off the map until they have ; gone.
4676 1F36 .check_exit←3← 1F13 BNE← 1F1A BNE← 1F28 BCC
LDX #0 ; Is a hero on the exit? From hero 0
4678 1F38 .check_hero_on_exit←1← 1F94 BNE
LDA hero_x,x ; The hero's x...
467B 1F3B CMP exit_x ; ...at the exit's x?
467E 1F3E BNE next_hero_exit ; No: next hero
4680 1F40 LDA hero_y,x ; ...and the hero's y...
4683 1F43 CMP exit_y ; ...at the exit's y?
4686 1F46 BNE next_hero_exit ; No: next hero
4688 1F48 JSR drop_key ; Yes: drop their key beside it
468B 1F4B LDA #step_out_of_play ; Take them out of play for the rest of the level
468D 1F4D STA hero_step,x ; ...so they are never animated...
4690 1F50 LDA #0 ; ...and no direction...
4692 1F52 STA hero_direction,x ; ...so move_heroes skips them
4695 1F55 LDA hero_x,x ; Erase them from the exit's cell
4698 1F58 STA cell_x ; ...is the cell to blank: x...
469B 1F5B LDA hero_y,x ; ...and the hero's y...
469E 1F5E STA cell_y ; ...and y...
46A1 1F61 LDA #0 ; ...squarely on the cell...
46A3 1F63 STA plot_offset_x ; ...no shift across (plot_offset_x 0)...
46A5 1F65 STA plot_offset_y ; ...or down (plot_offset_y 0)...
46A7 1F67 LDA #spr_blank ; ...with the blank sprite
46A9 1F69 STA sprite_number ; ...as the sprite to plot
46AB 1F6B TXA ; Keep the hero number...
46AC 1F6C PHA ; ...on the stack across plot_at_cell
46AD 1F6D JSR plot_at_cell ; Plot the blank in every view showing them
46B0 1F70 PLA ; Recover the hero number...
46B1 1F71 TAX ; ...into X, to move them off the map
46B2 1F72 LDA #off_map ; Move them off the map
46B4 1F74 STA hero_x,x ; ...x off the map, so nothing meets them
46B7 1F77 LDA exit_x ; Hide the exit while they go down it, keeping its position
46BA 1F7A STA exit_saved_x ; ...x in exit_saved_x, for redraw_exit...
46BD 1F7D LDA exit_y ; ...and its y...
46C0 1F80 STA exit_saved_y ; ...in exit_saved_y, for restore_exit too
46C3 1F83 LDA #off_map ; ...then put the exit off the map...
46C5 1F85 STA exit_x ; ...x &FF...
46C8 1F88 STA exit_y ; ...and y &FF, so no other hero can enter it
46CB 1F8B JSR hero_enters_exit ; Start the exit animation (which jumps back to play_level)
46CE 1F8E JMP check_exit_busy ; Reached by the RTS at the end of the level: one more frame
46D1 1F91 .next_hero_exit←2← 1F3E BNE← 1F46 BNE
INX ; Next hero, 0 to 3
46D2 1F92 CPX #4 ; All four heroes checked?
46D4 1F94 BNE check_hero_on_exit ; No: check the next
; The descent, one step a frame while exit_busy is set: ; redraw the exit, then the hero on it a quarter turn on, ; at the size and offsets for this turn.
46D6 1F96 .check_exit_busy←1← 1F8E JMP
LDA exit_busy ; A hero going down the exit?
46D9 1F99 BNE redraw_exit ; Yes: draw this frame of the descent
46DB 1F9B JMP play_level ; No: next frame
46DE 1F9E .redraw_exit←1← 1F99 BNE
LDX exiting_hero ; Redraw the exit under the spinning hero
46E1 1FA1 LDA #0 ; ...squarely on its cell...
46E3 1FA3 STA plot_offset_x ; ...no shift across (plot_offset_x 0)...
46E5 1FA5 STA plot_offset_y ; ...or down (plot_offset_y 0)...
46E7 1FA7 LDA exit_saved_x ; ...at exit_saved_x...
46EA 1FAA STA cell_x ; ...(exit_x itself is off the map)...
46ED 1FAD LDA exit_saved_y ; ...and exit_saved_y...
46F0 1FB0 STA cell_y ; ...as the cell to plot...
46F3 1FB3 LDA #spr_exit ; ...with the exit sprite...
46F5 1FB5 STA sprite_number ; ...as the sprite to plot
46F7 1FB7 JSR plot_at_cell ; Plot it in every view showing it
46FA 1FBA LDX exiting_hero ; Turn the hero a quarter: up, right, down, left
46FD 1FBD CLC ; ...clear carry for the add
46FE 1FBE LDA exit_spin ; ...from the current direction...
4701 1FC1 ADC #2 ; ...two sprites on: the next direction...
4703 1FC3 STA exit_spin ; ...kept for the next frame
4706 1FC6 CMP #9 ; Past left (9): a full turn?
4708 1FC8 BEQ next_turn ; Yes: shrink the hero, showing just the exit
470A 1FCA CLC ; Plot the hero on the exit, centred for its current size
470B 1FCB LDA hero_sprites,x ; ...the hero's sprite base...
470E 1FCE ADC exit_spin ; ...plus the direction's frame...
4711 1FD1 STA sprite_number ; ...as the sprite to plot
4713 1FD3 LDA exit_saved_x ; ...on the exit's cell: its x...
4716 1FD6 STA cell_x ; ...set again, as plot_at_cell changed cell_x...
4719 1FD9 LDA exit_saved_y ; ...and its y...
471C 1FDC STA cell_y ; ...and cell_y
471F 1FDF LDX exit_shrinks_left ; ...with offsets for its size, by turns left...
4722 1FE2 LDA exit_offsets_x,x ; ...byte columns right, from exit_offsets_x...
4725 1FE5 STA plot_offset_x ; ...as plot_offset_x, centring the narrower sprite...
4727 1FE7 LDA exit_offsets_y,x ; ...pixel rows down, from exit_offsets_y...
472A 1FEA STA plot_offset_y ; ...as plot_offset_y, centring the shorter one
472C 1FEC JSR plot_at_cell ; Plot the hero in every view showing the exit
472F 1FEF JMP play_level ; Next frame: the next quarter turn
; A full turn is done. After the fourth the hero has gone; ; after each of the first three, sprites base + 1 to base ; + 7 shrink by a byte and three rows.
4732 1FF2 .next_turn←1← 1FC8 BEQ
LDA #&ff ; Start the next turn from facing up
4734 1FF4 STA exit_spin ; ...-1, so the next frame's +2 gives 1
4737 1FF7 DEC exit_shrinks_left ; Fourth turn done?
473A 1FFA BEQ restore_exit ; Yes: the hero has gone; bring the exit back
473C 1FFC CLC ; Shrink sprites base + 1 to + 7: a byte narrower...
473D 1FFD LDA hero_sprites,x ; ...the hero's sprite base...

Unused

Zeros between the stored game core (&3000-&473F) and Coder (&5000).

4740 EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; Not referenced

Coder: load the game and the next level

Build the game afresh from disc for the next level and start it. Run once per level as *CODER: for the first level by *DUNJUNZ, and for each later one by next_level_intercept during the reset that ends the level before. It never returns.

Count the level: levels_started and level_digits, the filename's number ("1 " to "25"), live in page &08, which the reset leaves alone and *DUNJUNZ resets for a new game. Blank the display (6845 register 1 = 0) and silence the VDU, then *LOAD DUN1, which holds this code, so the bytes being run are rewritten with identical ones; the reload also restores level_command, so the digits go into it only afterwards. Load the level file to &6B00, which is screen memory: LEVELnn, or for level 25 STONES at &6680, whose last &2B0 bytes are level 25.

Copy one of the two &0400-&07FF images into place: the one with joystick_bytev only if ADC channel 1 reads with a high byte of exactly &80. The channel is read again to decide whether to point BYTEV at &0780, so if the two reads disagree the image and the vector do not match: the joystick image with the MOS's BYTEV, or BYTEV at the keyboard image's &0780, which holds zeros (BRK). Show 80 columns and 23 rows again (the level file's rows 23-24 stay hidden), then copy the game core: all of &3000-&473F to &08C0-&1FFF for the first level, but only from &3440, to &0D00-&1FFF, for later ones, so that the heroes' scores and attributes in &08C0-&0CFF carry over. Leave levels_started in &8E for game_entry, and jump to it.

Coder uses the game's zero page &70-&73 and &80-&81 for its pointers; nothing there is needed until game_entry.

; Set up the machine: ESCAPE off, VDU output on to the screen ; only, and the BREAK intercept cancelled.
5000 .coder_start
LDA #osbyte_escape_break_effect ; Disable ESCAPE for the whole game...
5002 LDX #1 ; ...X = 1: ESCAPE disabled, BREAK as normal
5004 LDY #0 ; ...Y = 0: X replaces the old setting
5006 JSR osbyte ; osbyte: escape break effect
5009 LDA #6 ; VDU 6, 3: text to the screen, none to a printer
500B JSR oswrch ; ...VDU 6 undoes the VDU 21 *DUNJUNZ sends...
500E LDA #3 ; ...then 3 (VDU 3: printer off)...
5010 JSR oswrch ; ...keeps output off any printer
5013 LDA #0 ; Cancel the BREAK intercept *DUNJUNZ armed...
5015 STA os_break_intercept ; ...so a BREAK now resets plainly until a level ends
; Count the level and advance its filename digits in page &08: ; "0 " to "9 " step by the single digit, then "10" on in two.
5018 INC levels_started ; One more level started (1 for the first)
501B LDA level_digits + 1 ; Advance level_digits, the filename's level number...
501E CMP #&20 ; Second digit a space (levels 1-9)?
5020 BEQ advance_single_digit ; Yes: advance the single digit
5022 CLC ; No: advance the units digit...
5023 ADC #1 ; ...+1, the next units digit
5025 STA level_digits + 1 ; ...back into level_digits
5028 CMP #&3a ; ...past '9': does it carry?
502A BCC set_up_6845_for_loading ; No: the number is ready
502C LDA #&30 ; Yes: units '0' and carry into the tens
502E STA level_digits + 1 ; ...units digit back to '0'...
5031 INC level_digits ; ...and one more tens
5034 BNE set_up_6845_for_loading ; Always taken: the number is ready
5036 .advance_single_digit←1← 5020 BEQ
INC level_digits ; Advance the single digit ('0 ' becomes '1 ')...
5039 LDA level_digits ; ...to check it
503C CMP #&3a ; ...past '9': level 10, two digits now?
503E BCC set_up_6845_for_loading ; No: levels 1-9 are ready
5040 LDA #&31 ; Yes: level 10, "10"
5042 STA level_digits ; ...'1' as the tens digit...
5045 LDA #&30 ; ...and '0' as the units digit...
5047 STA level_digits + 1 ; ...in place of the space
; Blank the display and silence the VDU, then reload Dun1 and ; the level file.
504A .set_up_6845_for_loading←3← 502A BCC← 5034 BNE← 503E BCC
LDX #0 ; Blank the display while the files load
504C .send_loading_vdu←1← 5055 BNE
LDA loading_vdu,x ; ...the next byte of loading_vdu...
504F JSR oswrch ; ...to the VDU
5052 INX ; ...on to the next
5053 CPX #play_vdu - loading_vdu ; ...until all 21 are sent
5055 BNE send_loading_vdu ; More to send
5057 LDA #&15 ; VDU 21: stop all VDU output...
5059 JSR oswrch ; ...so the *LOADs print nothing
505C LDX #<(dun1_command) ; Reload Dun1: a fresh game, and this code over itself
505E LDY #>(dun1_command) ; ...high byte of the command
5060 JSR oscli ; ...*LOAD DUN1 to &2000-&7FFF
5063 LDA level_digits ; Copy the level's digits into level_command
5066 STA level_command_digits ; ...the tens digit, or the only one...
5069 LDA level_digits + 1 ; ...second digit, or a space...
506C STA level_command_digits + 1 ; ...at level_command+10
506F LDA levels_started ; Hand levels_started to game_entry in &8E...
5072 STA level_count_copy ; ...which game_entry makes level_number
5074 LDA levels_started ; A = levels started - 1, to pick the level's file
5077 SEC ; ...minus 1 (carry set for the subtract)...
5078 SBC #1 ; ...24 for level 25
507A STA level_number ; ...in level_number (the core copy overwrites it)
507D CMP #&18 ; Levels started 25: the last level?
507F BNE load_level_file ; Not level 25: load its LEVELnn file
5081 LDX #<(stones_command) ; Yes: *LOAD STONES 6680, whose end is level 25...
5083 LDY #>(stones_command) ; ...high byte of the command
5085 JSR oscli ; ...putting level 25 at &6B00
5088 JMP level_loaded ; ...and skip the LEVELnn load
508B .load_level_file←1← 507F BNE
LDX #<(level_command) ; No: *LOAD LEVELnn 6B00
508D LDY #>(level_command) ; ...high byte of the command
508F JSR oscli ; ...to &6B00, where check_level decrypts it
; Turn the VDU back on and copy the keyboard or joystick image ; of &0400-&07FF into place.
5092 .level_loaded←1← 5088 JMP
LDA #6 ; VDU 6: VDU output on again
5094 JSR oswrch ; ...so the game's text can appear
5097 LDA #<(low_image_start) ; Copy one &0400-&07FF image into place...
5099 STA coder_dest ; ...destination pointer in coder_dest...
509B LDA #>(low_image_start) ; ...high byte &04, the image's first page...
509D STA coder_dest + 1 ; ...destination &0400 complete
509F LDA #<(keyboard_image_stored) ; ...source low byte &B0, for &51B0 or &55B0
50A1 STA coder_source ; ...source pointer in coder_source
50A3 LDA #osbyte_read_adc_or_get_buffer_status ; Is a joystick there? Read ADC channel 1...
50A5 LDX #1 ; ...channel 1: the joystick's left-right axis
50A7 JSR osbyte ; Read ADC channel X or buffer status
50AA CPY #&80 ; ...high byte exactly &80?
50AC BNE use_keyboard_image ; Not &80: use the keyboard-only image
50AE LDA #>(joystick_image_stored) ; Yes: the image with the joystick handler, &55B0
50B0 STA coder_source + 1 ; ...source page &55: copy from &55B0
50B2 BNE copy_low_image ; Always taken: copy it
50B4 .use_keyboard_image←1← 50AC BNE
LDA #>(keyboard_image_stored) ; No: the keyboard-only image, &51B0
50B6 STA coder_source + 1 ; ...source page &51: copy from &51B0
50B8 .copy_low_image←1← 50B2 BNE
LDY #0 ; Copy a kilobyte, up to &0800...
50BA .copy_low_byte←1← 50CE BNE
LDA (coder_source),y ; ...take the next byte...
50BC STA (coder_dest),y ; ...into the game's &0400-&07FF
50BE INC coder_dest ; Step the destination...
50C0 BNE copy_low_next_source ; ...within the page
50C2 INC coder_dest + 1 ; ...or on to the next page
50C4 .copy_low_next_source←1← 50C0 BNE
INC coder_source ; Step the source...
50C6 BNE copy_low_check_end ; ...within the page
50C8 INC coder_source + 1 ; ...or on to the next page
50CA .copy_low_check_end←1← 50C6 BNE
LDA coder_dest + 1 ; Stop when the destination reaches &0800...
50CC CMP #>(low_image_end) ; ...page &08: past the image's end?
50CE BNE copy_low_byte ; No: copy more
; Point BYTEV at the joystick handler if channel 1 still reads ; &80.
50D0 LDA #osbyte_read_adc_or_get_buffer_status ; Read channel 1 again: install the handler?
50D2 LDX #1 ; ...channel 1 again
50D4 JSR osbyte ; Read ADC channel X or buffer status
50D7 CPY #&80 ; ...high byte exactly &80?
50D9 BNE set_up_screen_for_play ; No: keep the MOS's BYTEV
50DB LDA #<(joystick_bytev) ; Yes: point BYTEV at joystick_bytev (&0780)
50DD STA bytev ; ...the handler's low byte into BYTEV...
50E0 LDA #>(joystick_bytev) ; ...and its page, &07...
50E2 STA bytev + 1 ; ...so the Barbarian's key scans read the joystick
; Set the text colour and show the display, 23 rows.
50E5 .set_up_screen_for_play←1← 50D9 BNE
LDA #&11 ; COLOUR 2: VDU 17, then the colour...
50E7 JSR oswrch ; ...send VDU 17, set the text colour...
50EA LDA #2 ; ...text colour 2...
50EC JSR oswrch ; ...for the game's messages
50EF LDX #0 ; Show the display again, 23 rows, for play
50F1 .send_play_vdu←1← 50FA BNE
LDA play_vdu,x ; ...the next byte of play_vdu...
50F4 JSR oswrch ; ...to the VDU
50F7 INX ; ...on to the next
50F8 CPX #coder_leftovers - play_vdu ; ...until all 20 are sent
50FA BNE send_play_vdu ; More to send
; Copy the game core down, keeping &08C0-&0CFF after the first ; level, and start the game.
50FC LDA levels_started ; First level of a game?
50FF CMP #2 ; ...fewer than 2 levels started?
5101 BCS keep_heroes ; No: keep the heroes
5103 LDA #0 ; Yes: copy all of &3000-&473F to &08C0-&1FFF
5105 STA core_offset ; ...offset &0000: low byte...
5107 STA core_offset + 1 ; ...and high byte: no offset
5109 BEQ copy_game_core ; Always taken: copy from the start
510B .keep_heroes←1← 5101 BCS
LDA #&40 ; No: copy &3440-&473F to &0D00, keeping the heroes' state
510D STA core_offset ; ...offset &0440: low byte...
510F LDA #4 ; ...high byte &04...
5111 STA core_offset + 1 ; ...so &08C0-&0CFF is left as it is
5113 .copy_game_core←1← 5109 BEQ
LDA core_offset ; Source = &3000 + offset...
5115 STA coder_source ; ...source low byte
5117 LDA #>(game_core_stored) ; ...page &30, where Dun1 stores the core...
5119 CLC ; ...(carry clear for the add)...
511A ADC core_offset + 1 ; ...plus the offset's high byte...
511C STA coder_source + 1 ; ...source high byte
511E LDA #<(game_core_start) ; ...destination = &08C0 + offset
5120 CLC ; ...(carry clear for the add)...
5121 ADC core_offset ; ...the offset's low byte...
5123 STA coder_dest ; ...destination low byte
5125 LDA #>(game_core_start) ; ...page &08, where the core runs...
5127 ADC core_offset + 1 ; ...plus the offset's high byte and carry...
5129 STA coder_dest + 1 ; ...destination high byte
512B LDY #0 ; Copy bytes up to &4740
512D .copy_core_byte←2← 5141 BNE← 5147 BNE
LDA (coder_source),y ; ...take the next byte...
512F STA (coder_dest),y ; ...into the running game
5131 INC coder_source ; Step the source...
5133 BNE copy_core_next_dest ; ...within the page
5135 INC coder_source + 1 ; ...or on to the next page
5137 .copy_core_next_dest←1← 5133 BNE
INC coder_dest ; Step the destination...
5139 BNE copy_core_check_end ; ...within the page
513B INC coder_dest + 1 ; ...or on to the next page
513D .copy_core_check_end←1← 5139 BNE
LDA coder_source ; Stop at the core's end, &4740: source low byte...
513F CMP #<(game_core_stored_end) ; ...&40, the end's low byte?
5141 BNE copy_core_byte ; No: copy more
5143 LDA coder_source + 1 ; ...then the source's page...
5145 CMP #>(game_core_stored_end) ; ...&47: the source at &4740, the core's end?
5147 BNE copy_core_byte ; No: copy more
5149 JMP game_entry ; Enter the game at game_entry

Coder's commands

Three OSCLI command lines, each ended by a CR.

514C .stones_command
EQUS "LOAD STONES 6680", &0D ; *LOAD STONES 6680, for level 25
515D .dun1_command
EQUS "LOAD DUN1", &0D ; *LOAD DUN1
5167 .level_command
EQUS "LOAD LEVEL 6B00", &0D ; *LOAD LEVELnn 6B00, the digits at +10

Coder's VDU tables

6845 set-ups sent with VDU 23,0: one while loading, one for play.

5179 .loading_vdu
EQUB &17, &00, &01, &00, ; VDU 23,0,1,0: 6845 register 1 = &00, &00, &00, &00, ; 0, no characters displayed &00, &00
5183 EQUB &17, &00, &0A, &20, ; VDU 23,0,10,&20: 6845 register &00, &00, &00, &00, ; 10 = &20, no cursor &00, &00
518D EQUB &00 ; A further 0, sent too (21 bytes are sent)
518E .play_vdu
EQUB &17, &00, &01, &50, ; VDU 23,0,1,80: 6845 register 1 = &00, &00, &00, &00, ; 80 characters displayed &00, &00
5198 EQUB &17, &00, &06, &17, ; VDU 23,0,6,23: 6845 register 6 = &00, &00, &00, &00, ; 23 character rows displayed &00, &00

Unused

Leftover bytes: stale code from an earlier assembly.

51A2 .coder_leftovers
EQUB &85, &70, &BD, &D0, &7D, &18, &69, &18, &85, &71, &8A, &48, &20, &00

Add 1000 to a hero's score

Carry a point into the thousands of hero X's score. add_ten_points calls it whenever the hundreds digit passes 9, and on return its draw_score redraws the four large digits (thousands to units) in the hero's panel section. The panel has room for only those four, so when the thousands digit passes 9 it goes back to 0 and the ten-thousands digit (hero_score_ten_thousands, a small digit sprite) goes up. That digit sticks at 9, so beyond 99,999 the large digits wrap while the small one stays at 9. Each change of the ten-thousands digit is drawn at draw_ten_thousands: the small digit &18 rows below the hero's panel row, under the score, followed by four of sprite &71. Sprite &71, the small 8, is a solid bar two pixels wide, the same shape a small 0 would have, so the line reads as a small N0000. remove_absent_heroes enters at draw_ten_thousands with the digit in A, to redraw the line on the fresh screen of each level. Uses plot_x, plot_y and sprite_number.

On EntryXhero number (0-3)
On ExitXpreserved
LoadExec
51B0 0400 .add_thousand_points←1← 72B9 JSR
INC hero_score_thousands,x ; One more thousand: the hundreds digit carried
51B3 0403 LDA hero_score_thousands,x ; ...and check the new digit
51B6 0406 CMP #spr_digit_9 + 1 ; Past 9: another ten thousand?
51B8 0408 BNE add_thousand_points_done ; No: return; draw_score shows the new digit
51BA 040A LDA #spr_digit_0 ; Yes: thousands 0...
51BC 040C STA hero_score_thousands,x ; ...stored for this hero
51BF 040F INC page6_score_ten_thousands,x ; ...and carry into the small ten-thousands digit
51C2 0412 LDA page6_score_ten_thousands,x ; ...and check the new digit
51C5 0415 CMP #spr_small_digit_9 + 1 ; Past small 9: a score of 100,000?
51C7 0417 BNE draw_ten_thousands ; No: draw it under the score
51C9 0419 LDA #spr_small_digit_9 ; Yes: it sticks at 9
51CB 041B STA page6_score_ten_thousands,x ; ...stored for this hero
51CE 041E .draw_ten_thousands←2← 0417 BNE← 06C2 JSR
STA sprite_number ; Plot the ten-thousands digit under the score...
51D0 0420 LDA #panel_left ; ...at the panel's left column
51D2 0422 STA plot_x ; ...as the plot column
51D4 0424 LDA workspace_template + 208,x ; ...hero_panel_y, read from workspace_template
51D7 0427 CLC ; ...(carry clear for the add)
51D8 0428 ADC #&18 ; ...+ &18: below the score's rows, &0C-&15
51DA 042A STA plot_y ; ...as the plot row
51DC 042C TXA ; Keep the hero number...
51DD 042D PHA ; ...on the stack while plotting
51DE 042E JSR plot_sprite ; Plot the ten-thousands digit
51E1 0431 LDA #spr_small_digit_8 ; ...then four small 0s after it: sprite &71...
51E3 0433 STA sprite_number ; ...(small 8, a solid bar, the shape of a small 0)
51E5 0435 LDY #4 ; ...four of them, for the 0000
51E7 0437 .draw_ten_thousands_loop←1← 0443 BNE
TYA ; Keep the count...
51E8 0438 PHA ; ...on the stack while plotting
51E9 0439 INC plot_x ; Two byte columns right...
51EB 043B INC plot_x ; ...a small digit's width on
51ED 043D JSR plot_sprite ; Plot a 0 there
51F0 0440 PLA ; Recover the count...
51F1 0441 TAY ; ...of 0s still to plot, in Y
51F2 0442 DEY ; One fewer 0 to plot
51F3 0443 BNE draw_ten_thousands_loop ; More 0s: loop
51F5 0445 PLA ; Recover the hero number...
51F6 0446 TAX ; ...in X again, as on entry
51F7 0447 .add_thousand_points_done←1← 0408 BNE
RTS ; Return to draw_score (or remove_absent_heroes)

Unused

Zero bytes, which nothing reads.

LoadExec
51F8 0448 EQUB &00, &00, &00, &00, &00, &00, &00, &00 ; Zeros

Decrypt and check the level just loaded

Decrypt the level at &6B00-&6DAF in place, XORing each byte with the low byte of its own address, and sum the decrypted bytes. If the sum does not match the level's entry in level_checksums, call &D9CD, the reset entry of MOS 1.20, so a damaged or altered level file is never played. It runs once per level, as soon as the level file is in memory and before unpack_level copies it into the game's tables; it returns only if the level is intact, leaving it decrypted at &6B00. The pointer and the sum borrow the plotter's zero-page workspace (plot_x and plot_y, sprite_width), which nothing is using while a level loads.

On EntryLEVEL_NUMBERlevel loaded (1-25)
LoadExec
5200 0450 .decrypt_level←1← 1446 JSR
LDY #0 ; Point at &6B00, the start of the level...
5202 0452 STY plot_x ; ...low byte 0, in plot_x (the pointer's low half)
5204 0454 STY sprite_width ; Checksum 0, kept in sprite_width
5206 0456 LDA #>(level_object_x) ; High byte &6B: the level buffer's page
5208 0458 STA plot_y ; ...in plot_y (the pointer's high half)
520A 045A .decrypt_level_loop←2← 046F BNE← 0475 BNE
LDA (plot_x),y ; Fetch a level byte...
520C 045C EOR plot_x ; ...XOR it with the low byte of its address...
520E 045E STA (plot_x),y ; ...and store it back decrypted
5210 0460 CLC ; Add the decrypted byte to the checksum...
5211 0461 ADC sprite_width ; ...plus the sum so far
5213 0463 STA sprite_width ; ...as the new sum, modulo 256
5215 0465 INC plot_x ; Advance the pointer to the next level byte...
5217 0467 BNE decrypt_level_next ; No carry: same page
5219 0469 INC plot_y ; ...with carry into the high byte
521B 046B .decrypt_level_next←1← 0467 BNE
LDA plot_x ; Stop at &6DB0, the end of the level...
521D 046D CMP #<(level_file_end) ; ...low byte &B0?
521F 046F BNE decrypt_level_loop ; No: decrypt the next byte
5221 0471 LDA plot_y ; ...and high byte &6D?
5223 0473 CMP #>(level_file_end) ; ...(the end page)
5225 0475 BNE decrypt_level_loop ; No: decrypt the next byte
5227 0477 LDX level_number ; X = the level just loaded (1-25)
522A 047A LDA sprite_width ; Compare the checksum...
522C 047C CMP level_checksums,x ; ...with this level's entry in the table
522F 047F BEQ decrypt_level_done ; Match: the level is intact; return
5231 0481 JSR mos_reset_entry ; No match: reset the machine (a MOS 1.20 address)
5234 0484 .decrypt_level_done←1← 047F BEQ
RTS ; Return: the level at &6B00 is decrypted and intact

Unused

Zero bytes, which nothing reads.

LoadExec
5235 0485 EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; Zeros
5240 0490 .level_checksums←2Used as index base by← 047C CMP (low_joystick)← 047C CMP (low_keyboard)
EQUB &00 ; Entry 0: there is no level 0, so never read

Level checksums

One byte per level, 1-25, indexed by level_number from level_checksums (whose entry 0 is unused): the sum, modulo 256, of the level's &2B0 decrypted bytes, which decrypt_level checks before the level is played.

LoadExec
5241 0491 EQUB &62, &CD, &0C, &44, &4D, &22, &F6, ; Levels &42, &21, &7D, &5D, &D8, &A0, &F1, ; 1-25, five &0F, &CC, &D3, &53, &3B, &83, &71, ; to a row &B2, &6F, &F3, &F1

Unused

Zero bytes, which nothing reads.

LoadExec
525A 04AA EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; Zeros
526A 04BA EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; Zeros
527A 04CA EQUB &00, &00, &00, &00, &00 ; Zeros
; Data of sprite &15, &1A, &77: 4 bytes x 12 rows.
527F 04CF .sprite_blank
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
52AF 04FF EQUB &00 ; Not referenced

Choose the heroes and the sound

The screen before each game where the players choose who plays. It is called once per game, when a new game starts, after reset_hero has given every hero their starting attributes and before the first level. Set a text window the full width of the screen (MODE 2's 20 columns) and clear it, print the menu (print_menu) and read keys until SPACE. Keys 1-4 toggle a hero between YES and NO by flipping their hero_absent flag and rewriting the menu entry; 5 and 6 switch the sound on and off with OSBYTE &D2. After each change the whole menu is reprinted. SPACE returns, so the game starts, only if at least one hero is playing. Before each key is read, the keyboard buffer is flushed and CAPS LOCK is forced on with SHIFT LOCK off.

Neither hero_absent nor the menu text is set up here: the menu opens with whatever they held, which after a game over in the same load is the last game's choices. The ON/OFF entry shows only what was last chosen on the menu, not the sound suppression actually in force. hero_absent is read by remove_absent_heroes at each level.

On ExitAcorrupted
Xcorrupted
Ycorrupted
LoadExec
52B0 0500 .hero_menu←1← 0E11 JSR
LDA #&1c ; VDU 28: the menu's window, the screen's full width...
52B2 0502 JSR oswrch ; Send VDU 28
52B5 0505 LDA #0 ; Left column 0
52B7 0507 JSR oswrch ; Send the left column
52BA 050A LDA #&16 ; Bottom row of the window
52BC 050C JSR oswrch ; Send the bottom row
52BF 050F LDA #&13 ; Right column 19, MODE 2's last
52C1 0511 JSR oswrch ; Send the right column
52C4 0514 LDA #0 ; Top row 0
52C6 0516 JSR oswrch ; Send the top row
52C9 0519 LDA #&0c ; ...VDU 12 to clear it
52CB 051B JSR oswrch ; Send VDU 12: clear the window
52CE 051E JSR print_menu ; Print the menu
52D1 0521 JMP menu_key_loop ; Read keys until the players start the game

Print the menu text

Print the sixteen positioned strings of menu_text, in their current state, through print_menu_string: fifteen in a loop and the sixteenth by falling into print_menu_string, whose return is this routine's. Called by hero_menu to show the menu and after every change.

On ExitAcorrupted
Xcorrupted
Ycorrupted
LoadExec
52D4 0524 .print_menu←3← 051E JSR← 05C3 JSR← 05F0 JSR
LDX #&0f ; Fifteen strings, then one more by falling through
52D6 0526 LDY #0 ; Y walks through menu_text from its start
52D8 0528 .print_menu_loop←1← 052C BNE
JSR print_menu_string ; Print one menu string
52DB 052B DEX ; One fewer to print
52DC 052C BNE print_menu_loop ; More to print: loop
fall through ↓

Print one menu string

Move the text cursor to the column and row in the two bytes at menu_text+Y, then print the following characters up to and including a carriage return.

On EntryYoffset of the string in menu_text
On ExitYoffset of the next string
LoadExec
52DE 052E .print_menu_string←1← 0528 JSR
LDA #&1f ; VDU 31: move the text cursor...
52E0 0530 JSR oswrch ; Send VDU 31
52E3 0533 LDA menu_text,y ; ...to the string's column...
52E6 0536 JSR oswrch ; Send the column
52E9 0539 INY ; Step to the row byte
52EA 053A LDA menu_text,y ; ...and the string's row...
52ED 053D JSR oswrch ; Send the row
52F0 0540 .print_menu_string_loop←1← 0549 BNE
INY ; Print the characters...
52F1 0541 LDA menu_text,y ; ...the next character...
52F4 0544 JSR oswrch ; ...sent to the screen...
52F7 0547 CMP #&0d ; ...up to and including the carriage return
52F9 0549 BNE print_menu_string_loop ; Not the CR yet: next character
52FB 054B INY ; Point at the next string
52FC 054C RTS ; Return with Y at the next string's column byte

Change a menu entry to NO

Write "NO " over a hero's YES/NO entry at menu_text+Y, when hero_menu switches the hero off. print_menu then shows it.

On EntryYoffset of the entry
LoadExec
52FD 054D .set_menu_no←1← 05C0 JSR
LDA #'N' ; "NO ": N first...
52FF 054F STA menu_text,y ; ...into the entry's first letter
5302 0552 LDA #'O' ; ...then O...
5304 0554 STA menu_text + 1,y ; ...into the second letter
5307 0557 LDA #' ' ; A space third, over YES's S...
5309 0559 STA menu_text + 2,y ; ...into the third letter
530C 055C RTS ; Return: the entry reads NO

Change a menu entry to YES

Write "YES" over a hero's YES/NO entry at menu_text+Y, when hero_menu switches the hero on. print_menu then shows it.

On EntryYoffset of the entry
LoadExec
530D 055D .set_menu_yes←1← 05BA JSR
LDA #'Y' ; "YES": Y first...
530F 055F STA menu_text,y ; ...into the entry's first letter
5312 0562 LDA #'E' ; ...then E...
5314 0564 STA menu_text + 1,y ; ...into the second letter
5317 0567 LDA #'S' ; ...then S...
5319 0569 STA menu_text + 2,y ; ...into the third letter
531C 056C RTS ; Return: the entry reads YES

Change the sound entry to OFF

Write "FF" at menu_text+Y, after the sound entry's "O", when key 6 turns the sound off.

On EntryYoffset of the entry's second character
LoadExec
531D 056D .set_menu_off←1← 05E4 JSR
LDA #'F' ; "FF" after the O
531F 056F STA menu_text,y ; ...over the N of ON...
5322 0572 STA menu_text + 1,y ; ...and the space after it
5325 0575 RTS ; Return: the entry reads OFF

Change the sound entry to ON

Write "N " at menu_text+Y, after the sound entry's "O", when key 5 turns the sound on.

On EntryYoffset of the entry's second character
LoadExec
5326 0576 .set_menu_on←1← 05DD JSR
LDA #'N' ; "N " after the O
5328 0578 STA menu_text,y ; ...over OFF's first F
532B 057B LDA #' ' ; ...then a space...
532D 057D STA menu_text + 1,y ; ...over OFF's second F
5330 0580 RTS ; Return: the entry reads ON
; Read one key and act on it, then come back for the next, ; until SPACE starts the game.
5331 0581 .menu_key_loop←6← 0521 JMP← 0598 BCC← 059C BCS← 05C6 JMP← 05D3 JMP← 05F3 JMP
LDA #osbyte_flush_buffer_class ; Flush the input buffers
5333 0583 JSR osbyte ; Discard any keys already waiting Flush selected class of buffer
5336 0586 LDA #osbyte_kbd_status ; OSBYTE &CA: set the keyboard lock states...
5338 0588 LDX #&20 ; X = &20: CAPS LOCK on, SHIFT LOCK off
533A 058A LDY #0 ; Y = 0: replace the status with X
533C 058C JSR osbyte ; Set it, whatever the Ranger's lock keys left osbyte: kbd status
533F 058F JSR osrdch ; Wait for a key
5342 0592 CMP #' ' ; SPACE, to start the game?
5344 0594 BEQ menu_space ; Yes: start, if anyone is playing
5346 0596 CMP #'1' ; Ignore anything but 1-6
5348 0598 BCC menu_key_loop ; Below '1': ignore it
534A 059A CMP #'7' ; ...or above '6' (at or past '7')?
534C 059C BCS menu_key_loop ; Yes: ignore it
534E 059E SEC ; Key number 0-5 = key - '1'...
534F 059F SBC #'1' ; ...so keys '1'-'6' become 0-5...
5351 05A1 TAX ; ...in X: a hero 0-3, or 4-5 for the sound
5352 05A2 CMP #4 ; Key 5 or 6?
5354 05A4 BCS menu_sound_key ; Yes: the sound switch
; Keys 1-4: switch hero X between playing and absent, and ; show it as YES or NO.
5356 05A6 ASL ; 1-4: Y = offset of the hero's YES/NO, 6 x X + &51...
5357 05A7 STA plot_x ; Keep 2 x the hero number
5359 05A9 ASL ; 4 x the hero number...
535A 05AA CLC ; ...(carry clear for the add)
535B 05AB ADC plot_x ; ...+ 2 x: 6 x the hero number
535D 05AD ADC #&51 ; ...+ &51: this hero's YES/NO text
535F 05AF TAY ; Y = its offset in menu_text
5360 05B0 LDA hero_absent,x ; Toggle the hero between playing and absent...
5363 05B3 EOR #1 ; ...by flipping the absent flag
5365 05B5 STA hero_absent,x ; ...the hero's new absent flag
5368 05B8 BNE menu_hero_off ; Now absent (flag 1)?
536A 05BA JSR set_menu_yes ; No: playing, so the entry reads YES
536D 05BD JMP menu_reprint ; ...and reprint the menu
5370 05C0 .menu_hero_off←1← 05B8 BNE
JSR set_menu_no ; Absent: the entry reads NO
5373 05C3 .menu_reprint←1← 05BD JMP
JSR print_menu ; Reprint the menu with the change
5376 05C6 JMP menu_key_loop ; Wait for the next key
; SPACE: return, so the game starts, if at least one hero ; is playing; otherwise ignore it.
5379 05C9 .menu_space←1← 0594 BEQ
LDX #3 ; SPACE: is any hero playing?
537B 05CB .menu_space_check_hero←1← 05D1 BPL
LDA hero_absent,x ; Is this hero playing (absent flag 0)?
537E 05CE BEQ menu_done ; Yes: return, and the game starts
5380 05D0 DEX ; Absent: try the previous hero
5381 05D1 BPL menu_space_check_hero ; Heroes left to check: loop
5383 05D3 JMP menu_key_loop ; Nobody playing: ignore SPACE
5386 05D6 .menu_done←1← 05CE BEQ
RTS ; Return: the game goes on to its first level
; Keys 5 and 6: sound on or off, through OSBYTE &D2, and ; the menu's entry to match.
5387 05D7 .menu_sound_key←1← 05A4 BCS
LDY #&99 ; Sound: Y = offset of the second letter of ON/OFF
5389 05D9 CMP #5 ; Key 6 (A = key - "1")?
538B 05DB BEQ menu_sound_off ; Yes: sound off
538D 05DD JSR set_menu_on ; Key 5: ON...
5390 05E0 LDX #0 ; ...with X = 0 to enable the sound
5392 05E2 BEQ menu_set_sound ; Always: set the sound
5394 05E4 .menu_sound_off←1← 05DB BEQ
JSR set_menu_off ; Key 6: OFF...
5397 05E7 LDX #1 ; ...with X = 1 to suppress it
5399 05E9 .menu_set_sound←1← 05E2 BEQ
LDA #osbyte_sound_suppression ; OSBYTE &D2: sound suppression
539B 05EB LDY #0 ; Y = 0: replace the setting with X
539D 05ED JSR osbyte ; Turn the sound on or off as chosen osbyte: sound suppression
53A0 05F0 JSR print_menu ; Reprint the menu with the change
53A3 05F3 JMP menu_key_loop ; Wait for the next key
53A6 05F6 EQUB &00, &00, &00, &00, &00, &00, &00, ; Not &00, &00, &4F ; referenced

Hero menu text

Sixteen entries of: column, row, text, carriage return; printed in order by print_menu, each at its own text position. The four heroes' YES/NO entries (text at menu_text + &51 + 6 x hero) are rewritten by set_menu_yes and set_menu_no, and the sound entry's ON/OFF (second letter at menu_text + &99) by set_menu_on and set_menu_off, so the table holds the players' choices as well as showing them.

LoadExec
; The hero menu: sixteen strings, each a text column and ; row followed by the characters and a carriage return. ; The YES/NO and ON/OFF entries are rewritten as the ; players toggle them.
53B0 0600 .menu_text←7Used as index base by← 0533 LDA← 053A LDA← 0541 LDA← 054F STA← 055F STA← 056F STA← 0578 STA
EQUB &06, &00 ; Column 6, row 0
53B2 0602 EQUS "DUNJUNZ", &0D
53BA 060A EQUB &00, &02 ; Column 0, row 2
53BC 060C EQUS "HERO", &0D
53C1 0611 EQUB &0C, &02 ; Column 12, row 2
53C3 0613 EQUS "PLAYING", &0D
53CB 061B EQUB &00, &04 ; Column 0, row 4
53CD 061D EQUS "1 RANGER", &0D
53D6 0626 EQUB &00, &05 ; Column 0, row 5
53D8 0628 EQUS "2 MAGIC-USER", &0D
53E5 0635 EQUB &00, &06 ; Column 0, row 6
53E7 0637 EQUS "3 BARBARIAN", &0D
53F3 0643 EQUB &00, &07 ; Column 0, row 7
53F5 0645 EQUS "4 FIGHTER", &0D
53FF 064F EQUB &0E, &04 ; Column 14, row 4
5401 0651 EQUS "YES", &0D
5405 0655 EQUB &0E, &05 ; Column 14, row 5
5407 0657 EQUS "YES", &0D
540B 065B EQUB &0E, &06 ; Column 14, row 6
540D 065D EQUS "YES", &0D
5411 0661 EQUB &0E, &07 ; Column 14, row 7
5413 0663 EQUS "YES", &0D
5417 0667 EQUB &00, &09 ; Column 0, row 9
5419 0669 EQUS "TYPE NUMBER", &0D
5425 0675 EQUB &00, &0A ; Column 0, row 10
5427 0677 EQUS "TO TOGGLE", &0D
5431 0681 EQUB &00, &0D ; Column 0, row 13
5433 0683 EQUS "SOUND ON(5) OFF(6)", &0D
5446 0696 EQUB &07, &0F ; Column 7, row 15
5448 0698 EQUS "ON ", &0D
544C 069C EQUB &03, &14 ; Column 3, row 20
544E 069E EQUS "SPACE TO PLAY", &0D
545C 06AC EQUB &00, &0D, &A9, &63 ; Not referenced

Take the heroes nobody plays out of the level

The last step of setting up each level, called by level_loop after draw_status_panel and just before play_level. For each hero in turn:

First redraw the small ten-thousands line under the score, if it has one (through draw_ten_thousands), since start_level cleared the screen and draw_status_panel draws only the four large digits.

Then, if the hero was switched off on the menu (hero_absent), take them out of play, since reset_workspace has just given every hero their starting state: direction 0; step_out_of_play, so move_heroes passes over them; frame 8 and dead health, so that play_level treats them as dead with their death animation over, and level_loop counts them among the dead (and resets them) when the level ends; map x &1F; and a nobody_returns entry in returning_hero_queue, which reset_monsters has just emptied. The absent heroes' entries go at the front of the queue, in hero order; a Cross of Resurrection sends such an entry to the back and takes the next. Their panel section keeps the health and score just drawn.

On ExitAcorrupted
Xcorrupted
Ycorrupted
LoadExec
5460 06B0 .remove_absent_heroes←1← 0E5D JSR
LDX #0 ; Hero 0 first...
5462 06B2 LDY #0 ; ...Y = the queue entry for the next absent hero
5464 06B4 .remove_absent_heroes_loop←1← 06F3 BNE
LDA hero_score_ten_thousands,x ; Score of 10000 or more?
5467 06B7 CMP #spr_small_digit_1 ; ...ten-thousands sprite small 1 or above?
5469 06B9 BCC remove_absent_heroes_check ; No: nothing under the score; check absence
546B 06BB TXA ; Yes: redraw it, lost when the screen was cleared
546C 06BC PHA ; Keep the hero number...
546D 06BD TYA ; ...and the queue entry...
546E 06BE PHA ; ...on the stack
546F 06BF LDA hero_score_ten_thousands,x ; The digit's sprite...
5472 06C2 JSR draw_ten_thousands ; ...drawn under the score with its 0000
5475 06C5 PLA ; Recover the queue entry...
5476 06C6 TAY ; ...for the next absent hero, in Y
5477 06C7 PLA ; Recover the hero number...
5478 06C8 TAX ; ...in X again
; Take the hero out of play if nobody is playing them, so ; that they count as dead, and a Cross of Resurrection ; passes over their queue entry.
5479 06C9 .remove_absent_heroes_check←1← 06B9 BCC
LDA hero_absent,x ; Switched off on the menu?
547C 06CC BEQ remove_absent_heroes_next ; No: playing; next hero
547E 06CE LDA #0 ; Yes: take them out of play...
5480 06D0 STA hero_direction,x ; ...direction 0: not in play
5483 06D3 LDA #step_out_of_play ; ...step &63, so move_heroes passes them over...
5485 06D5 STA hero_step,x ; ...as the hero's step count
5488 06D8 LDA #8 ; ...frame 8: their death animation is over...
548A 06DA STA hero_frame,x ; ...as the hero's frame
548D 06DD LDA #spr_digit_0 - 1 ; ...health tens below 0: dead...
548F 06DF STA hero_health_tens,x ; ...as the health tens digit
5492 06E2 DEC hero_score_units,x ; ...units back below 0, undoing the panel's point
5495 06E5 LDA #&1f ; ...map x &1F, the dungeon's last column...
5497 06E7 STA hero_x,x ; ...as the hero's map x
549A 06EA LDA #nobody_returns ; ...and a nobody_returns entry in the queue...
549C 06EC STA returning_hero_queue,y ; ...which a Cross of Resurrection skips
549F 06EF INY ; The next absent hero takes the next entry
54A0 06F0 .remove_absent_heroes_next←1← 06CC BEQ
INX ; Next hero, 0-3
54A1 06F1 CPX #4 ; All four heroes done?
54A3 06F3 BNE remove_absent_heroes_loop ; No: next hero
54A5 06F5 RTS ; Return to level_loop: the level is ready to play

Unused

Zero bytes, which nothing reads.

LoadExec
54A6 06F6 EQUB &00, &00 ; Zeros
; Each hero's score ten-thousands digit where ; add_thousand_points still keeps it, at its cassette ; address. Every other routine uses ; hero_score_ten_thousands at &08B0, and Coder reloads ; this page for every level, so the digit is lost between ; levels.
54A8 06F8 .page6_score_ten_thousands←3Used as index base by← 040F INC← 0412 LDA← 041B STA
EQUS "iiii"
54AC 06FC EQUB &00, &00, &00, &00 ; Not referenced

Leftovers in the line-input buffer

Not used by the game. &0700 is the MOS 1.20 line-input buffer, and these bytes are what it held when this image was saved: the command *SA. DANK 400+3FF 740, then a fragment of BBC BASIC assembler (label+2:LDA#255:.label JSR&30).

LoadExec
; Leftover contents of the MOS 1.20 line-input buffer ; (&0700) from the machine the image was saved on.
54B0 0700 .line_buffer_leftovers
EQUS "*SA. DANK 400+3FF 740"
54C5 0715 EQUB &0D, &0D ; Not referenced
54C7 0717 EQUS "740"
54CA 071A EQUB &0D ; Not referenced
54CB 071B EQUB &0D, &54, &50, &0D, ; Not referenced &0D, &50, &0D
54D2 0722 EQUS "Alabel+2:LDA#255:.label JSR&30"

Load the game file and run it (not used)

Build an OSFILE control block at &6B00 naming boot_filename with load address &2000, call the filing system's FILEV handler to load the file, and jump to &2000. &0740 is the execution address in the *SAVE command left at &0700, so this is the image's own entry point when it is *RUN, but nothing in this release reaches it.

LoadExec
54F0 0740 .boot_loader
LDX #<(boot_osfile_block) ; X/Y = &6B00, the control block...
54F2 0742 LDY #>(boot_osfile_block) ; ...Y = &6B, its page
54F4 0744 LDA #<(boot_filename) ; Filename address: boot_filename...
54F6 0746 STA boot_osfile_block ; ...into the block's filename pointer, low byte
54F9 0749 LDA #>(boot_filename) ; ...boot_filename's high byte
54FB 074B STA boot_osfile_block + 1 ; ...into the filename pointer's high byte
54FE 074E LDA #0 ; Load address &00002000...
5500 0750 STA boot_osfile_block + 2 ; ...load address byte 0 = 0
5503 0753 STA boot_osfile_block + 4 ; ...byte 2 = 0
5506 0756 STA boot_osfile_block + 5 ; ...byte 3 = 0
5509 0759 LDA #&20 ; ...byte 1 = &20
550B 075B STA boot_osfile_block + 3 ; ...so the file loads at &00002000
550E 075E LDA filev ; Copy FILEV into the JSR below...
5511 0761 STA boot_load_call + 1 ; ...FILEV low byte into the JSR's operand
5514 0764 LDA filev + 1 ; ...FILEV high byte
5517 0767 STA boot_load_call + 2 ; ...so the JSR calls the filing system directly
551A 076A LDA #&ff ; OSFILE &FF: load the file at the block's address
551C 076C .boot_load_call
JSR &3000 ; Call FILEV (operand patched above)
551F 076F JMP &2000 ; Enter the loaded game at &2000
5522 0772 EQUB &00, &00, &00, &00 ; Not referenced
5526 0776 EQUB &00 ; Not referenced
5527 0777 EQUB &00 ; Not referenced
5528 0778 EQUB &00, &00, &00, &00, &00, &00, &00, ; Not &00 ; referenced
5530 0780 EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, ; N &00, &00, &00, &00, &00, &00, &00, &00, &00, ; o &00, &00, &00, &00, &00, &00, &00, &00, &00 ; t ; r ; e ; f ; e ; r ; e ; n ; c ; e ; d
554B 079B EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; Not referenced
5559 07A9 EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; Not referenced
5568 07B8 EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; Not referenced
5576 07C6 EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; Not referenced
5585 07D5 EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, ; N &00, &00, &00, &00, &00, &00, &00, &00 ; o ; t ; r ; e ; f ; e ; r ; e ; n ; c ; e ; d
5596 07E6 EQUB &00, &00, &00 ; Not referenced
5599 07E9 EQUB &00, &00, &00, &00, ; Not referenced &00, &00, &00

Name of the file boot_loader loads

LoadExec
55A0 07F0 .boot_filename
EQUS "Dun1"
55A4 07F4 EQUB &0D, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; Not referenced

Add 1000 to a hero's score

Carry a point into the thousands of hero X's score. add_ten_points calls it whenever the hundreds digit passes 9, and on return its draw_score redraws the four large digits (thousands to units) in the hero's panel section. The panel has room for only those four, so when the thousands digit passes 9 it goes back to 0 and the ten-thousands digit (hero_score_ten_thousands, a small digit sprite) goes up. That digit sticks at 9, so beyond 99,999 the large digits wrap while the small one stays at 9. Each change of the ten-thousands digit is drawn at draw_ten_thousands: the small digit &18 rows below the hero's panel row, under the score, followed by four of sprite &71. Sprite &71, the small 8, is a solid bar two pixels wide, the same shape a small 0 would have, so the line reads as a small N0000. remove_absent_heroes enters at draw_ten_thousands with the digit in A, to redraw the line on the fresh screen of each level. Uses plot_x, plot_y and sprite_number.

On EntryXhero number (0-3)
On ExitXpreserved
LoadExec
55B0 0400 .add_thousand_points_joystick←1← 72B9 JSR
INC hero_score_thousands,x ; One more thousand: the hundreds digit carried
55B3 0403 LDA hero_score_thousands,x ; ...and check the new digit
55B6 0406 CMP #spr_digit_9 + 1 ; Past 9: another ten thousand?
55B8 0408 BNE add_thousand_points_done_joystick ; No: return; draw_score shows the new digit
55BA 040A LDA #spr_digit_0 ; Yes: thousands 0...
55BC 040C STA hero_score_thousands,x ; ...stored for this hero
55BF 040F INC page6_score_ten_thousands_joystick,x ; ...and carry into the small ten- thousands digit
55C2 0412 LDA page6_score_ten_thousands_joystick,x ; ...and check the new digit
55C5 0415 CMP #spr_small_digit_9 + 1 ; Past small 9: a score of 100,000?
55C7 0417 BNE draw_ten_thousands_joystick ; No: draw it under the score
55C9 0419 LDA #spr_small_digit_9 ; Yes: it sticks at 9
55CB 041B STA page6_score_ten_thousands_joystick,x ; ...stored for this hero
55CE 041E .draw_ten_thousands_joystick←2← 0417 BNE← 06C2 JSR
STA sprite_number ; Plot the ten-thousands digit under the score...
55D0 0420 LDA #panel_left ; ...at the panel's left column
55D2 0422 STA plot_x ; ...as the plot column
55D4 0424 LDA workspace_template + 208,x ; ...hero_panel_y, read from workspace_template
55D7 0427 CLC ; ...(carry clear for the add)
55D8 0428 ADC #&18 ; ...+ &18: below the score's rows, &0C-&15
55DA 042A STA plot_y ; ...as the plot row
55DC 042C TXA ; Keep the hero number...
55DD 042D PHA ; ...on the stack while plotting
55DE 042E JSR plot_sprite ; Plot the ten-thousands digit
55E1 0431 LDA #spr_small_digit_8 ; ...then four small 0s after it: sprite &71...
55E3 0433 STA sprite_number ; ...(small 8, a solid bar, the shape of a small 0)
55E5 0435 LDY #4 ; ...four of them, for the 0000
55E7 0437 .draw_ten_thousands_loop_joystick←1← 0443 BNE
TYA ; Keep the count...
55E8 0438 PHA ; ...on the stack while plotting
55E9 0439 INC plot_x ; Two byte columns right...
55EB 043B INC plot_x ; ...a small digit's width on
55ED 043D JSR plot_sprite ; Plot a 0 there
55F0 0440 PLA ; Recover the count...
55F1 0441 TAY ; ...of 0s still to plot, in Y
55F2 0442 DEY ; One fewer 0 to plot
55F3 0443 BNE draw_ten_thousands_loop_joystick ; More 0s: loop
55F5 0445 PLA ; Recover the hero number...
55F6 0446 TAX ; ...in X again, as on entry
55F7 0447 .add_thousand_points_done_joystick←1← 0408 BNE
RTS ; Return to draw_score (or remove_absent_heroes)

Unused

Zero bytes, which nothing reads.

LoadExec
55F8 0448 EQUB &00, &00, &00, &00, &00, &00, &00, &00 ; Zeros

Decrypt and check the level just loaded

Decrypt the level at &6B00-&6DAF in place, XORing each byte with the low byte of its own address, and sum the decrypted bytes. If the sum does not match the level's entry in level_checksums, call &D9CD, the reset entry of MOS 1.20, so a damaged or altered level file is never played. It runs once per level, as soon as the level file is in memory and before unpack_level copies it into the game's tables; it returns only if the level is intact, leaving it decrypted at &6B00. The pointer and the sum borrow the plotter's zero-page workspace (plot_x and plot_y, sprite_width), which nothing is using while a level loads.

On EntryLEVEL_NUMBERlevel loaded (1-25)
LoadExec
5600 0450 .decrypt_level_joystick←1← 1446 JSR
LDY #0 ; Point at &6B00, the start of the level...
5602 0452 STY plot_x ; ...low byte 0, in plot_x (the pointer's low half)
5604 0454 STY sprite_width ; Checksum 0, kept in sprite_width
5606 0456 LDA #>(level_object_x) ; High byte &6B: the level buffer's page
5608 0458 STA plot_y ; ...in plot_y (the pointer's high half)
560A 045A .decrypt_level_loop_joystick←2← 046F BNE← 0475 BNE
LDA (plot_x),y ; Fetch a level byte...
560C 045C EOR plot_x ; ...XOR it with the low byte of its address...
560E 045E STA (plot_x),y ; ...and store it back decrypted
5610 0460 CLC ; Add the decrypted byte to the checksum...
5611 0461 ADC sprite_width ; ...plus the sum so far
5613 0463 STA sprite_width ; ...as the new sum, modulo 256
5615 0465 INC plot_x ; Advance the pointer to the next level byte...
5617 0467 BNE decrypt_level_next_joystick ; No carry: same page
5619 0469 INC plot_y ; ...with carry into the high byte
561B 046B .decrypt_level_next_joystick←1← 0467 BNE
LDA plot_x ; Stop at &6DB0, the end of the level...
561D 046D CMP #<(level_file_end) ; ...low byte &B0?
561F 046F BNE decrypt_level_loop_joystick ; No: decrypt the next byte
5621 0471 LDA plot_y ; ...and high byte &6D?
5623 0473 CMP #>(level_file_end) ; ...(the end page)
5625 0475 BNE decrypt_level_loop_joystick ; No: decrypt the next byte
5627 0477 LDX level_number ; X = the level just loaded (1-25)
562A 047A LDA sprite_width ; Compare the checksum...
562C 047C CMP level_checksums,x ; ...with this level's entry in the table
562F 047F BEQ decrypt_level_done_joystick ; Match: the level is intact; return
5631 0481 JSR mos_reset_entry ; No match: reset the machine (a MOS 1.20 address)
5634 0484 .decrypt_level_done_joystick←1← 047F BEQ
RTS ; Return: the level at &6B00 is decrypted and intact

Unused

Zero bytes, which nothing reads.

LoadExec
5635 0485 EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; Zeros
5640 0490 .level_checksums←2Used as index base by← 047C CMP (low_joystick)← 047C CMP (low_keyboard)
EQUB &00 ; Entry 0: there is no level 0, so never read

Level checksums

One byte per level, 1-25, indexed by level_number from level_checksums (whose entry 0 is unused): the sum, modulo 256, of the level's &2B0 decrypted bytes, which decrypt_level checks before the level is played.

LoadExec
5641 0491 EQUB &62, &CD, &0C, &44, &4D, &22, &F6, ; Levels &42, &21, &7D, &5D, &D8, &A0, &F1, ; 1-25, five &0F, &CC, &D3, &53, &3B, &83, &71, ; to a row &B2, &6F, &F3, &F1

Unused

Zero bytes, which nothing reads.

LoadExec
565A 04AA EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; Zeros
566A 04BA EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; Zeros
567A 04CA EQUB &00, &00, &00, &00, &00 ; Zeros
; Data of sprite &15, &1A, &77: 4 bytes x 12 rows.
567F 04CF .sprite_blank_joystick
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
56AF 04FF EQUB &00 ; Not referenced

Choose the heroes and the sound

The screen before each game where the players choose who plays. It is called once per game, when a new game starts, after reset_hero has given every hero their starting attributes and before the first level. Set a text window the full width of the screen (MODE 2's 20 columns) and clear it, print the menu (print_menu) and read keys until SPACE. Keys 1-4 toggle a hero between YES and NO by flipping their hero_absent flag and rewriting the menu entry; 5 and 6 switch the sound on and off with OSBYTE &D2. After each change the whole menu is reprinted. SPACE returns, so the game starts, only if at least one hero is playing. Before each key is read, the keyboard buffer is flushed and CAPS LOCK is forced on with SHIFT LOCK off.

Neither hero_absent nor the menu text is set up here: the menu opens with whatever they held, which after a game over in the same load is the last game's choices. The ON/OFF entry shows only what was last chosen on the menu, not the sound suppression actually in force. hero_absent is read by remove_absent_heroes at each level.

On ExitAcorrupted
Xcorrupted
Ycorrupted
LoadExec
56B0 0500 .hero_menu_joystick←1← 0E11 JSR
LDA #&1c ; VDU 28: the menu's window, the screen's full width...
56B2 0502 JSR oswrch ; Send VDU 28
56B5 0505 LDA #0 ; Left column 0
56B7 0507 JSR oswrch ; Send the left column
56BA 050A LDA #&16 ; Bottom row of the window
56BC 050C JSR oswrch ; Send the bottom row
56BF 050F LDA #&13 ; Right column 19, MODE 2's last
56C1 0511 JSR oswrch ; Send the right column
56C4 0514 LDA #0 ; Top row 0
56C6 0516 JSR oswrch ; Send the top row
56C9 0519 LDA #&0c ; ...VDU 12 to clear it
56CB 051B JSR oswrch ; Send VDU 12: clear the window
56CE 051E JSR print_menu_joystick ; Print the menu
56D1 0521 JMP menu_key_loop_joystick ; Read keys until the players start the game

Print the menu text

Print the sixteen positioned strings of menu_text, in their current state, through print_menu_string: fifteen in a loop and the sixteenth by falling into print_menu_string, whose return is this routine's. Called by hero_menu to show the menu and after every change.

On ExitAcorrupted
Xcorrupted
Ycorrupted
LoadExec
56D4 0524 .print_menu_joystick←3← 051E JSR← 05C3 JSR← 05F0 JSR
LDX #&0f ; Fifteen strings, then one more by falling through
56D6 0526 LDY #0 ; Y walks through menu_text from its start
56D8 0528 .print_menu_loop_joystick←1← 052C BNE
JSR print_menu_string_joystick ; Print one menu string
56DB 052B DEX ; One fewer to print
56DC 052C BNE print_menu_loop_joystick ; More to print: loop
fall through ↓

Print one menu string

Move the text cursor to the column and row in the two bytes at menu_text+Y, then print the following characters up to and including a carriage return.

On EntryYoffset of the string in menu_text
On ExitYoffset of the next string
LoadExec
56DE 052E .print_menu_string_joystick←1← 0528 JSR
LDA #&1f ; VDU 31: move the text cursor...
56E0 0530 JSR oswrch ; Send VDU 31
56E3 0533 LDA menu_text_joystick,y ; ...to the string's column...
56E6 0536 JSR oswrch ; Send the column
56E9 0539 INY ; Step to the row byte
56EA 053A LDA menu_text_joystick,y ; ...and the string's row...
56ED 053D JSR oswrch ; Send the row
56F0 0540 .print_menu_string_loop_joystick←1← 0549 BNE
INY ; Print the characters...
56F1 0541 LDA menu_text_joystick,y ; ...the next character...
56F4 0544 JSR oswrch ; ...sent to the screen...
56F7 0547 CMP #&0d ; ...up to and including the carriage return
56F9 0549 BNE print_menu_string_loop_joystick ; Not the CR yet: next character
56FB 054B INY ; Point at the next string
56FC 054C RTS ; Return with Y at the next string's column byte

Change a menu entry to NO

Write "NO " over a hero's YES/NO entry at menu_text+Y, when hero_menu switches the hero off. print_menu then shows it.

On EntryYoffset of the entry
LoadExec
56FD 054D .set_menu_no_joystick←1← 05C0 JSR
LDA #'N' ; "NO ": N first...
56FF 054F STA menu_text_joystick,y ; ...into the entry's first letter
5702 0552 LDA #'O' ; ...then O...
5704 0554 STA menu_text_joystick + 1,y ; ...into the second letter
5707 0557 LDA #' ' ; A space third, over YES's S...
5709 0559 STA menu_text_joystick + 2,y ; ...into the third letter
570C 055C RTS ; Return: the entry reads NO

Change a menu entry to YES

Write "YES" over a hero's YES/NO entry at menu_text+Y, when hero_menu switches the hero on. print_menu then shows it.

On EntryYoffset of the entry
LoadExec
570D 055D .set_menu_yes_joystick←1← 05BA JSR
LDA #'Y' ; "YES": Y first...
570F 055F STA menu_text_joystick,y ; ...into the entry's first letter
5712 0562 LDA #'E' ; ...then E...
5714 0564 STA menu_text_joystick + 1,y ; ...into the second letter
5717 0567 LDA #'S' ; ...then S...
5719 0569 STA menu_text_joystick + 2,y ; ...into the third letter
571C 056C RTS ; Return: the entry reads YES

Change the sound entry to OFF

Write "FF" at menu_text+Y, after the sound entry's "O", when key 6 turns the sound off.

On EntryYoffset of the entry's second character
LoadExec
571D 056D .set_menu_off_joystick←1← 05E4 JSR
LDA #'F' ; "FF" after the O
571F 056F STA menu_text_joystick,y ; ...over the N of ON...
5722 0572 STA menu_text_joystick + 1,y ; ...and the space after it
5725 0575 RTS ; Return: the entry reads OFF

Change the sound entry to ON

Write "N " at menu_text+Y, after the sound entry's "O", when key 5 turns the sound on.

On EntryYoffset of the entry's second character
LoadExec
5726 0576 .set_menu_on_joystick←1← 05DD JSR
LDA #'N' ; "N " after the O
5728 0578 STA menu_text_joystick,y ; ...over OFF's first F
572B 057B LDA #' ' ; ...then a space...
572D 057D STA menu_text_joystick + 1,y ; ...over OFF's second F
5730 0580 RTS ; Return: the entry reads ON
; Read one key and act on it, then come back for the next, ; until SPACE starts the game.
5731 0581 .menu_key_loop_joystick←6← 0521 JMP← 0598 BCC← 059C BCS← 05C6 JMP← 05D3 JMP← 05F3 JMP
LDA #osbyte_flush_buffer_class ; Flush the input buffers
5733 0583 JSR osbyte ; Discard any keys already waiting Flush selected class of buffer
5736 0586 LDA #osbyte_kbd_status ; OSBYTE &CA: set the keyboard lock states...
5738 0588 LDX #&20 ; X = &20: CAPS LOCK on, SHIFT LOCK off
573A 058A LDY #0 ; Y = 0: replace the status with X
573C 058C JSR osbyte ; Set it, whatever the Ranger's lock keys left osbyte: kbd status
573F 058F JSR osrdch ; Wait for a key
5742 0592 CMP #' ' ; SPACE, to start the game?
5744 0594 BEQ menu_space_joystick ; Yes: start, if anyone is playing
5746 0596 CMP #'1' ; Ignore anything but 1-6
5748 0598 BCC menu_key_loop_joystick ; Below '1': ignore it
574A 059A CMP #'7' ; ...or above '6' (at or past '7')?
574C 059C BCS menu_key_loop_joystick ; Yes: ignore it
574E 059E SEC ; Key number 0-5 = key - '1'...
574F 059F SBC #'1' ; ...so keys '1'-'6' become 0-5...
5751 05A1 TAX ; ...in X: a hero 0-3, or 4-5 for the sound
5752 05A2 CMP #4 ; Key 5 or 6?
5754 05A4 BCS menu_sound_key_joystick ; Yes: the sound switch
; Keys 1-4: switch hero X between playing and absent, and ; show it as YES or NO.
5756 05A6 ASL ; 1-4: Y = offset of the hero's YES/NO, 6 x X + &51...
5757 05A7 STA plot_x ; Keep 2 x the hero number
5759 05A9 ASL ; 4 x the hero number...
575A 05AA CLC ; ...(carry clear for the add)
575B 05AB ADC plot_x ; ...+ 2 x: 6 x the hero number
575D 05AD ADC #&51 ; ...+ &51: this hero's YES/NO text
575F 05AF TAY ; Y = its offset in menu_text
5760 05B0 LDA hero_absent,x ; Toggle the hero between playing and absent...
5763 05B3 EOR #1 ; ...by flipping the absent flag
5765 05B5 STA hero_absent,x ; ...the hero's new absent flag
5768 05B8 BNE menu_hero_off_joystick ; Now absent (flag 1)?
576A 05BA JSR set_menu_yes_joystick ; No: playing, so the entry reads YES
576D 05BD JMP menu_reprint_joystick ; ...and reprint the menu
5770 05C0 .menu_hero_off_joystick←1← 05B8 BNE
JSR set_menu_no_joystick ; Absent: the entry reads NO
5773 05C3 .menu_reprint_joystick←1← 05BD JMP
JSR print_menu_joystick ; Reprint the menu with the change
5776 05C6 JMP menu_key_loop_joystick ; Wait for the next key
; SPACE: return, so the game starts, if at least one hero ; is playing; otherwise ignore it.
5779 05C9 .menu_space_joystick←1← 0594 BEQ
LDX #3 ; SPACE: is any hero playing?
577B 05CB .menu_space_check_hero_joystick←1← 05D1 BPL
LDA hero_absent,x ; Is this hero playing (absent flag 0)?
577E 05CE BEQ menu_done_joystick ; Yes: return, and the game starts
5780 05D0 DEX ; Absent: try the previous hero
5781 05D1 BPL menu_space_check_hero_joystick ; Heroes left to check: loop
5783 05D3 JMP menu_key_loop_joystick ; Nobody playing: ignore SPACE
5786 05D6 .menu_done_joystick←1← 05CE BEQ
RTS ; Return: the game goes on to its first level
; Keys 5 and 6: sound on or off, through OSBYTE &D2, and ; the menu's entry to match.
5787 05D7 .menu_sound_key_joystick←1← 05A4 BCS
LDY #&99 ; Sound: Y = offset of the second letter of ON/OFF
5789 05D9 CMP #5 ; Key 6 (A = key - "1")?
578B 05DB BEQ menu_sound_off_joystick ; Yes: sound off
578D 05DD JSR set_menu_on_joystick ; Key 5: ON...
5790 05E0 LDX #0 ; ...with X = 0 to enable the sound
5792 05E2 BEQ menu_set_sound_joystick ; Always: set the sound
5794 05E4 .menu_sound_off_joystick←1← 05DB BEQ
JSR set_menu_off_joystick ; Key 6: OFF...
5797 05E7 LDX #1 ; ...with X = 1 to suppress it
5799 05E9 .menu_set_sound_joystick←1← 05E2 BEQ
LDA #osbyte_sound_suppression ; OSBYTE &D2: sound suppression
579B 05EB LDY #0 ; Y = 0: replace the setting with X
579D 05ED JSR osbyte ; Turn the sound on or off as chosen osbyte: sound suppression
57A0 05F0 JSR print_menu_joystick ; Reprint the menu with the change
57A3 05F3 JMP menu_key_loop_joystick ; Wait for the next key
57A6 05F6 EQUB &00, &00, &00, &00, &00, &00, &00, ; Not &00, &00, &4F ; referenced

Hero menu text

Sixteen entries of: column, row, text, carriage return; printed in order by print_menu, each at its own text position. The four heroes' YES/NO entries (text at menu_text + &51 + 6 x hero) are rewritten by set_menu_yes and set_menu_no, and the sound entry's ON/OFF (second letter at menu_text + &99) by set_menu_on and set_menu_off, so the table holds the players' choices as well as showing them.

LoadExec
; The hero menu: sixteen strings, each a text column and ; row followed by the characters and a carriage return. ; The YES/NO and ON/OFF entries are rewritten as the ; players toggle them.
57B0 0600 .menu_text_joystick←7Used as index base by← 0533 LDA← 053A LDA← 0541 LDA← 054F STA← 055F STA← 056F STA← 0578 STA
EQUB &06, &00 ; Column 6, row 0
57B2 0602 EQUS "DUNJUNZ", &0D
57BA 060A EQUB &00, &02 ; Column 0, row 2
57BC 060C EQUS "HERO", &0D
57C1 0611 EQUB &0C, &02 ; Column 12, row 2
57C3 0613 EQUS "PLAYING", &0D
57CB 061B EQUB &00, &04 ; Column 0, row 4
57CD 061D EQUS "1 RANGER", &0D
57D6 0626 EQUB &00, &05 ; Column 0, row 5
57D8 0628 EQUS "2 MAGIC-USER", &0D
57E5 0635 EQUB &00, &06 ; Column 0, row 6
57E7 0637 EQUS "3 BARBARIAN", &0D
57F3 0643 EQUB &00, &07 ; Column 0, row 7
57F5 0645 EQUS "4 FIGHTER", &0D
57FF 064F EQUB &0E, &04 ; Column 14, row 4
5801 0651 EQUS "YES", &0D
5805 0655 EQUB &0E, &05 ; Column 14, row 5
5807 0657 EQUS "YES", &0D
580B 065B EQUB &0E, &06 ; Column 14, row 6
580D 065D EQUS "YES", &0D
5811 0661 EQUB &0E, &07 ; Column 14, row 7
5813 0663 EQUS "YES", &0D
5817 0667 EQUB &00, &09 ; Column 0, row 9
5819 0669 EQUS "TYPE NUMBER", &0D
5825 0675 EQUB &00, &0A ; Column 0, row 10
5827 0677 EQUS "TO TOGGLE", &0D
5831 0681 EQUB &00, &0D ; Column 0, row 13
5833 0683 EQUS "SOUND ON(5) OFF(6)", &0D
5846 0696 EQUB &07, &0F ; Column 7, row 15
5848 0698 EQUS "ON ", &0D
584C 069C EQUB &03, &14 ; Column 3, row 20
584E 069E EQUS "SPACE TO PLAY", &0D
585C 06AC EQUB &00, &0D, &A9, &63 ; Not referenced

Take the heroes nobody plays out of the level

The last step of setting up each level, called by level_loop after draw_status_panel and just before play_level. For each hero in turn:

First redraw the small ten-thousands line under the score, if it has one (through draw_ten_thousands), since start_level cleared the screen and draw_status_panel draws only the four large digits.

Then, if the hero was switched off on the menu (hero_absent), take them out of play, since reset_workspace has just given every hero their starting state: direction 0; step_out_of_play, so move_heroes passes over them; frame 8 and dead health, so that play_level treats them as dead with their death animation over, and level_loop counts them among the dead (and resets them) when the level ends; map x &1F; and a nobody_returns entry in returning_hero_queue, which reset_monsters has just emptied. The absent heroes' entries go at the front of the queue, in hero order; a Cross of Resurrection sends such an entry to the back and takes the next. Their panel section keeps the health and score just drawn.

On ExitAcorrupted
Xcorrupted
Ycorrupted
LoadExec
5860 06B0 .remove_absent_heroes_joystick←1← 0E5D JSR
LDX #0 ; Hero 0 first...
5862 06B2 LDY #0 ; ...Y = the queue entry for the next absent hero
5864 06B4 .remove_absent_heroes_loop_joystick←1← 06F3 BNE
LDA hero_score_ten_thousands,x ; Score of 10000 or more?
5867 06B7 CMP #spr_small_digit_1 ; ...ten- thousands sprite small 1 or above?
5869 06B9 BCC remove_absent_heroes_check_joystick ; No: nothing under the score; check absence
586B 06BB TXA ; Yes: redraw it, lost when the screen was cleared
586C 06BC PHA ; Keep the hero number...
586D 06BD TYA ; ...and the queue entry...
586E 06BE PHA ; ...on the stack
586F 06BF LDA hero_score_ten_thousands,x ; The digit's sprite...
5872 06C2 JSR draw_ten_thousands_joystick ; ...drawn under the score with its 0000
5875 06C5 PLA ; Recover the queue entry...
5876 06C6 TAY ; ...for the next absent hero, in Y
5877 06C7 PLA ; Recover the hero number...
5878 06C8 TAX ; ...in X again
; Take the hero out of play if nobody is playing them, so ; that they count as dead, and a Cross of Resurrection ; passes over their queue entry.
5879 06C9 .remove_absent_heroes_check_joystick←1← 06B9 BCC
LDA hero_absent,x ; Switched off on the menu?
587C 06CC BEQ remove_absent_heroes_next_joystick ; No: playing; next hero
587E 06CE LDA #0 ; Yes: take them out of play...
5880 06D0 STA hero_direction,x ; ...direction 0: not in play
5883 06D3 LDA #step_out_of_play ; ...step &63, so move_heroes passes them over...
5885 06D5 STA hero_step,x ; ...as the hero's step count
5888 06D8 LDA #8 ; ...frame 8: their death animation is over...
588A 06DA STA hero_frame,x ; ...as the hero's frame
588D 06DD LDA #spr_digit_0 - 1 ; ...health tens below 0: dead...
588F 06DF STA hero_health_tens,x ; ...as the health tens digit
5892 06E2 DEC hero_score_units,x ; ...units back below 0, undoing the panel's point
5895 06E5 LDA #&1f ; ...map x &1F, the dungeon's last column...
5897 06E7 STA hero_x,x ; ...as the hero's map x
589A 06EA LDA #nobody_returns ; ...and a nobody_ returns entry in the queue...
589C 06EC STA returning_hero_queue,y ; ...which a Cross of Resurrection skips
589F 06EF INY ; The next absent hero takes the next entry
58A0 06F0 .remove_absent_heroes_next_joystick←1← 06CC BEQ
INX ; Next hero, 0-3
58A1 06F1 CPX #4 ; All four heroes done?
58A3 06F3 BNE remove_absent_heroes_loop_joystick ; No: next hero
58A5 06F5 RTS ; Return to level_loop: the level is ready to play

Unused

Zero bytes, which nothing reads.

LoadExec
58A6 06F6 EQUB &00, &00 ; Zeros
; Each hero's score ten-thousands digit where ; add_thousand_points still keeps it, at its cassette ; address. Every other routine uses ; hero_score_ten_thousands at &08B0, and Coder reloads ; this page for every level, so the digit is lost between ; levels.
58A8 06F8 .page6_score_ten_thousands_joystick←3Used as index base by← 040F INC← 0412 LDA← 041B STA
EQUS "iiii"
58AC 06FC EQUB &00, &00, &00, &00 ; Not referenced

Leftovers in the line-input buffer

Not used by the game. &0700 is the MOS 1.20 line-input buffer, and these bytes are what it held when this image was saved: the command *SA. Control 400+3FF, then a fragment of BBC BASIC assembler (label+2:LDA#255:.label JSR&30).

LoadExec
; Leftover contents of the MOS 1.20 line-input buffer ; (&0700) from the machine the image was saved on.
58B0 0700 .line_buffer_leftovers_joystick
EQUS "*SA. Control 400+3FF"
58C4 0714 EQUB &0D, &0D, &0D ; Not referenced
58C7 0717 EQUS "740"
58CA 071A EQUB &0D ; Not referenced
58CB 071B EQUB &0D, &54, &50, &0D, ; Not referenced &0D, &50, &0D
58D2 0722 EQUS "Alabel+2:LDA#255:.label JSR&30"

Load the game file and run it (not used)

Point BYTEV at joystick_bytev (&0780), then build an OSFILE control block at &6B00 naming boot_filename with load address &2000, call the filing system's FILEV handler to load the file, and jump to &2000. &0740 is the execution address in the *SAVE command left at &0700, so this is the image's own entry point when it is *RUN, but nothing in this release reaches it.

LoadExec
58F0 0740 .boot_loader_joystick
LDA #<(joystick_bytev) ; BYTEV = &0780, joystick_bytev...
58F2 0742 STA bytev ; ...joystick_bytev's low byte into BYTEV
58F5 0745 LDA #>(joystick_bytev) ; ...its high byte
58F7 0747 STA bytev + 1 ; ...so INKEY scans reach the joystick handler
58FA 074A LDX #<(boot_osfile_block) ; X/Y = &6B00, the control block...
58FC 074C LDY #>(boot_osfile_block) ; ...Y = &6B, its page
58FE 074E LDA #<(boot_filename) ; Filename address: boot_filename...
5900 0750 STA boot_osfile_block ; ...into the block's filename pointer, low byte
5903 0753 LDA #>(boot_filename) ; ...boot_filename's high byte
5905 0755 STA boot_osfile_block + 1 ; ...into the filename pointer's high byte
5908 0758 LDA #0 ; Load address &00002000...
590A 075A STA boot_osfile_block + 2 ; ...load address byte 0 = 0
590D 075D STA boot_osfile_block + 4 ; ...byte 2 = 0
5910 0760 STA boot_osfile_block + 5 ; ...byte 3 = 0
5913 0763 LDA #&20 ; ...byte 1 = &20
5915 0765 STA boot_osfile_block + 3 ; ...so the file loads at &00002000
5918 0768 LDA filev ; Copy FILEV into the JSR below...
591B 076B STA boot_load_call_joystick + 1 ; ...FILEV low byte into the JSR's operand
591E 076E LDA filev + 1 ; ...FILEV high byte
5921 0771 STA boot_load_call_joystick + 2 ; ...so the JSR calls the filing system directly
5924 0774 LDA #&ff ; OSFILE &FF: load the file at the block's address
5926 0776 .boot_load_call_joystick
JSR &3000 ; Call FILEV (operand patched above)
5929 0779 JMP &2000 ; Enter the loaded game at &2000
592C 077C EQUB &00, &00, &00, &00 ; Not referenced

BYTEV handler: read a joystick for the Barbarian's keys

Installed on BYTEV by Coder, in the joystick image of &0400-&07FF only. Answers test_key's OSBYTE &81 scans of the Barbarian's (hero 2's) keys from the analogue port, so that a joystick plays the Barbarian: left (. &98) and right (/ &97) from channel 1, up (K &B9) and down (, &99) from channel 2, and fire (SPACE &9D) from either fire button. A direction counts only at the stick's extreme, when the channel's high byte is &FF or 0, so the stick works as a switch. Every other call goes to the MOS 1.20 OSBYTE routine at &E772 directly, skipping any other BYTEV claimant. The handler's own OSBYTE &80 reads come back through BYTEV into it and are passed on the same way. The Barbarian's five keys are never scanned while it is installed, so that hero can be played only with the joystick. test_key counts a key as held only when X and Y both come back &FF, so a not-pressed answer needs only X = 0.

On EntryAOSBYTE number
XOSBYTE X
On ExitX&FF if the key is pressed, 0 if not
Y&FF if the key is pressed
LoadExec
5930 0780 .joystick_bytev
CMP #&81 ; OSBYTE &81 (INKEY)?
5932 0782 BNE joystick_pass_on ; No: let the MOS handle it
5934 0784 CPX #inkey_key_full_stop ; The Barbarian's left key (.)?
5936 0786 BEQ joystick_left ; Yes: read the stick for left
5938 0788 CPX #inkey_key_comma ; The Barbarian's down key (,)?
593A 078A BEQ joystick_down ; Yes: read the stick for down
593C 078C CPX #inkey_key_k ; The Barbarian's up key (K)?
593E 078E BEQ joystick_up ; Yes: read the stick for up
5940 0790 CPX #inkey_key_slash ; The Barbarian's right key (/)?
5942 0792 BEQ joystick_right ; Yes: read the stick for right
5944 0794 CPX #inkey_key_space ; The Barbarian's fire key (SPACE)?
5946 0796 BEQ joystick_fire ; Yes: read the fire buttons
5948 0798 JMP mos_osbyte_default ; Any other key: scan the keyboard as usual
594B 079B .joystick_left←1← 0786 BEQ
LDX #1 ; Left: channel 1 high byte &FF?
594D 079D LDA #osbyte_read_adc_or_get_buffer_status ; ...with OSBYTE &80, reading the ADC
594F 079F JSR osbyte ; Read ADC channel X or buffer status
5952 07A2 CPY #&ff ; ...high byte &FF: pushed fully left?
5954 07A4 BNE joystick_not_pressed ; No: not pressed
5956 07A6 LDX #&ff ; Yes: pressed (Y is already &FF)
5958 07A8 RTS ; Return X = Y = &FF: left is pressed
5959 07A9 .joystick_right←1← 0792 BEQ
LDX #1 ; Right: channel 1 high byte 0?
595B 07AB LDA #osbyte_read_adc_or_get_buffer_status ; ...with OSBYTE &80, reading the ADC
595D 07AD JSR osbyte ; Read ADC channel X or buffer status
5960 07B0 CPY #0 ; ...high byte 0: pushed fully right?
5962 07B2 BNE joystick_not_pressed ; No: not pressed
5964 07B4 DEY ; Yes: pressed (Y = &FF)
5965 07B5 LDX #&ff ; ...X = Y = &FF, as INKEY reports a key held
5967 07B7 RTS ; Return X = Y = &FF: right is pressed
5968 07B8 .joystick_up←1← 078E BEQ
LDX #2 ; Up: channel 2 high byte &FF?
596A 07BA LDA #osbyte_read_adc_or_get_buffer_status ; ...with OSBYTE &80, reading the ADC
596C 07BC JSR osbyte ; Read ADC channel X or buffer status
596F 07BF CPY #&ff ; ...high byte &FF: pushed fully up?
5971 07C1 BNE joystick_not_pressed ; No: not pressed
5973 07C3 LDX #&ff ; Yes: pressed (Y is already &FF)
5975 07C5 RTS ; Return X = Y = &FF: up is pressed
5976 07C6 .joystick_down←1← 078A BEQ
LDX #2 ; Down: channel 2 high byte 0?
5978 07C8 LDA #osbyte_read_adc_or_get_buffer_status ; ...with OSBYTE &80, reading the ADC
597A 07CA JSR osbyte ; Read ADC channel X or buffer status
597D 07CD CPY #0 ; ...high byte 0: pushed fully down?
597F 07CF BNE joystick_not_pressed ; No: not pressed
5981 07D1 DEY ; Yes: pressed (Y = &FF)
5982 07D2 LDX #&ff ; ...X = Y = &FF, as INKEY reports a key held
5984 07D4 RTS ; Return X = Y = &FF: down is pressed
5985 07D5 .joystick_fire←1← 0796 BEQ
LDX #0 ; Fire: either fire button?
5987 07D7 LDA #osbyte_read_adc_or_get_buffer_status ; ...OSBYTE &80, X = 0: the fire buttons in X
5989 07D9 JSR osbyte ; Read ADC channel X or buffer status
598C 07DC TXA ; ...the button bits...
598D 07DD AND #3 ; ...bits 0-1: either button held?
598F 07DF BEQ joystick_not_pressed ; No: not pressed
5991 07E1 LDX #&ff ; Yes: X = &FF, fire pressed...
5993 07E3 LDY #&ff ; ...X = Y = &FF, as INKEY reports a key held
5995 07E5 RTS ; Return X = Y = &FF: fire is pressed
5996 07E6 .joystick_not_pressed←5← 07A4 BNE← 07B2 BNE← 07C1 BNE← 07CF BNE← 07DF BEQ
LDX #0 ; Not pressed: X = 0, which test_key reads as not held
5998 07E8 RTS ; Return X = 0: the key is not pressed
5999 07E9 .joystick_pass_on←1← 0782 BNE
JMP mos_osbyte_default ; Not INKEY: on to the MOS 1.20 OSBYTE routine
599C 07EC EQUB &00, &00, &00, &00 ; Not referenced

Name of the file boot_loader loads

LoadExec
59A0 07F0 .boot_filename_joystick
EQUS "Dun1"
59A4 07F4 EQUB &0D, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; Not referenced
59B0 EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; Not referenced
6B00 .level_object_x←1Used as index base by← 1512 LDA
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
6B20 .level_object_y←1Used as index base by← 1518 LDA
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
6B40 .level_object_type←1Used as index base by← 151E LDA
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
6B60 .level_door_x←1Used as index base by← 1529 LDA
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
6B75 .level_door_y←1Used as index base by← 152F LDA
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
6B8A .level_door_sprite←1Used as index base by← 1535 LDA
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
6BA0 .level_key_x←1Used as index base by← 1540 LDA
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
6BB5 .level_key_y←1Used as index base by← 1546 LDA
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
6BD0 .level_trapdoor_x←1Used as index base by← 1551 LDA
EQUB &00, &00, &00, &00, &00, &00, &00, &00
6BD8 .level_trapdoor_y←1Used as index base by← 1557 LDA
EQUB &00, &00, &00, &00, &00, &00, &00, &00
6BE0 .level_walls←1Used as index base by← 1564 LDA
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
6CB0 .level_object_free_map←1Used as index base by← 156A LDA
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
6D80 .level_wall_sprite←1Used as index base by← 1577 LDA
EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00

Move the heroes

Let each of the four heroes, in turn from the Ranger, walk, fire or cast magic for this frame, redraw them, and let them pick up what lies in their cell. update_game calls this first in every frame, before the door and key tests (which use the cells it records in hero_door_x/y), draw_objects, move_missiles and update_monsters.

A hero out of play is passed over if nobody plays them (step &63), or handed to animate_absent_hero if dying or returning through a Cross. A hero half way through a step (step 1) finishes it through continue_hero_step and reads no keys. Otherwise heroes 0 and 1 first go through check_magic, which comes back to read_hero_keys, or after a cast to draw_moved_hero with no move; then the first held of up, down, right, left and fire decides. A direction turns the hero that way (directions 1, 3, 5, 7) and tries the next cell, which is recorded in hero_door_x/y whatever is there, so a hero pushing on a door opens it. A wall or closed door, a monster (alive or dying, found by find_creature) or another hero in play refuses the move; walking into a monster also costs one health point, whatever the hero's armour. A move into another room is made at once and switches the hero's view (show_hero_room); within a room the Boots of Speed make it at once too, and without them the hero stays in the old cell, drawn half a cell along, and arrives on the next frame. Fire puts a missile in the first of the hero's free slots (3 x hero up to hero_max_missiles of them), in the hero's own cell, with bit 7 of its direction set so move_missiles does not erase it off the hero; the bell (VDU 7) sounds and the hero's frame flips. With no slot free, or no key held, the hero stands still.

A hero who moved or was refused is erased from where they were drawn, using previous_x/y and previous_offset_x/y; every hero still in play is then drawn, and collect_objects runs whenever object_free_map lets their cell hold an object, every frame they are there and not only on arrival. check_magic's delay returns from move_heroes itself, so after a cast the later heroes are not moved for three frames. The bytes at &6F6D are never executed.

On ExitAcorrupted
Xcorrupted
Ycorrupted
6E80 .move_heroes←1← 1CC0 JSR
LDX #0 ; Hero 0, the Ranger, first
; For hero X: one out of play is not moved or drawn here, only ; animated if dying or returning.
6E82 .move_hero←1← 70C6 JMP
LDA hero_direction,x ; A direction (1, 3, 5, 7) means the hero is in play
6E85 BNE remember_hero_position ; In play: remember where they are, then move them
6E87 LDA hero_step,x ; Out of play: why? The step says
6E8A CMP #step_out_of_play ; Step &63 marks a hero nobody plays
6E8C BNE animate_absent ; Not &63: the hero is dying or returning
6E8E JMP next_hero ; Nobody plays them: nothing to move or draw
6E91 .animate_absent←1← 6E8C BNE
JSR animate_absent_hero ; Step the skull or resurrection animation
6E94 JMP next_hero ; Then on to the next hero
; In play: keep the cell and offsets now drawn, to erase the ; hero there and to put them back if blocked.
6E97 .remember_hero_position←1← 6E85 BNE
LDA hero_x,x ; Remember the hero's cell and offsets before moving
6E9A STA previous_x ; previous_x: where to put the hero back if blocked
6E9D LDA hero_y,x ; The cell's y...
6EA0 STA previous_y ; ...in previous_y, for the same
6EA3 LDA hero_offset_x,x ; The horizontal pixel offset now drawn...
6EA6 STA previous_offset_x ; ...so erase_hero blanks the image where it is
6EA9 LDA hero_offset_y,x ; And the vertical pixel offset...
6EAC STA previous_offset_y ; ...for the same erase
; A hero half way through a step arrives this frame and reads no ; keys; only a standing hero acts.
6EAF LDA hero_step,x ; Half way between cells (step 1)?
6EB2 BEQ check_magic_key ; No: standing in a cell, so read the keys
6EB4 JSR continue_hero_step ; Yes: arrive in the next cell; no keys this frame
6EB7 JMP erase_hero ; Erase the half-way image, draw the arrival
6EBA .check_magic_key←1← 6EB2 BEQ
CPX #2 ; Hero 0 or 1 (the two with magic)?
6EBC BCS read_hero_keys ; Barbarian or Fighter: no magic, straight to the keys
6EBE JMP check_magic ; Ranger or Magic-User: magic key, then back
; Standing in a cell: the first held key of up, down, right, ; left and fire decides what the hero does.
6EC1 .read_hero_keys←2← 6EBC BCS← 76AB JMP
LDA hero_key_up,x ; Up key held? (directions beat fire, up first)
6EC4 JSR test_key ; Z set if held
6EC7 BNE check_key_down ; Not held: try down
6EC9 LDA #1 ; Held: face up...
6ECB STA hero_direction,x ; ...direction 1: drawn as sprite base + 1 or + 2
6ECE JSR start_hero_step ; ...set the half-cell offsets for the step...
6ED1 JMP step_hero ; ...and try the cell above
6ED4 .check_key_down←1← 6EC7 BNE
LDA hero_key_down,x ; Down key held?
6ED7 JSR test_key ; Z set if held
6EDA BNE check_key_right ; Not held: try right
6EDC LDA #5 ; Held: face down...
6EDE STA hero_direction,x ; ...direction 5: drawn as sprite base + 5 or + 6
6EE1 JSR start_hero_step ; ...set the half-cell offsets for the step...
6EE4 JMP step_hero ; ...and try the cell below
6EE7 .check_key_right←1← 6EDA BNE
LDA hero_key_right,x ; Right key held?
6EEA JSR test_key ; Z set if held
6EED BNE check_key_left ; Not held: try left
6EEF LDA #3 ; Held: face right...
6EF1 STA hero_direction,x ; ...direction 3: drawn as sprite base + 3 or + 4
6EF4 JSR start_hero_step ; ...set the half-cell offsets for the step...
6EF7 JMP step_hero ; ...and try the cell to the right
6EFA .check_key_left←1← 6EED BNE
LDA hero_key_left,x ; Left key held?
6EFD JSR test_key ; Z set if held
6F00 BNE check_key_fire ; Not held: try fire
6F02 LDA #7 ; Held: face left...
6F04 STA hero_direction,x ; ...direction 7: drawn as sprite base + 7 or + 8
6F07 JSR start_hero_step ; ...set the half-cell offsets for the step...
6F0A JMP step_hero ; ...and try the cell to the left
6F0D .check_key_fire←1← 6F00 BNE
LDA hero_key_fire,x ; Fire key held? (only when no direction is)
6F10 JSR test_key ; Z set if held
6F13 BEQ fire_missile ; Held: launch a missile the way the hero faces
6F15 JMP draw_moved_hero ; No key: the hero stands still, drawn in place
; Fire: put a missile in the hero's first free slot, in the ; hero's cell, flying the way the hero faces.
6F18 .fire_missile←1← 6F13 BEQ
TXA ; Slots 3 x hero to 3 x hero + hero_max_missiles - 1
6F19 STA scratch ; Hero number kept to add...
6F1C ASL ; ...doubled: 2 x hero...
6F1D CLC ; ...(no carry in)...
6F1E ADC scratch ; ...+ hero: 3 x hero, the hero's first slot
6F21 TAY ; Y walks the hero's slots
6F22 ADC hero_max_missiles,x ; + how many missiles the hero may have in flight...
6F25 STA scratch ; ...the first slot past the hero's own
6F28 .find_missile_slot←1← 6F74 BNE
LDA missile_direction,y ; This slot's missile still flying?
6F2B BNE next_missile_slot ; Yes: look at the hero's next slot
6F2D LDA hero_direction,x ; Free: missile direction = (hero direction + 1) / 2
6F30 CLC ; Hero direction 1, 3, 5 or 7...
6F31 ADC #1 ; ...+ 1: 2, 4, 6 or 8...
6F33 LSR ; ...halved: 1-4, up, right, down, left
6F34 ORA #&80 ; Bit 7: just fired, so not erased off the hero
6F36 STA missile_direction,y ; The slot is now in flight
6F39 LDA hero_x,x ; It starts in the hero's cell; move_missiles moves it on
6F3C STA missile_x,y ; ...missile x = hero x...
6F3F LDA hero_y,x ; ...and the hero's y...
6F42 STA missile_y,y ; ...as missile y
6F45 LDA #7 ; The firing sound: VDU 7, the bell...
6F47 JSR oswrch ; ...through OSWRCH, the same for every hero
6F4A LDA hero_missile_damage,x ; The hero's current missile damage...
6F4D STA missile_damage,y ; ...goes with this missile, for whatever it hits
6F50 LDA hero_missile_sprites,x ; The hero's weapon sprites (arrow, fireball, axe, sword)...
6F53 STA missile_sprite_base,y ; ...so it is drawn, and its owner known, by these
6F56 LDA previous_x ; Put back the cell remembered at the start...
6F59 STA hero_x,x ; ...the same cell: nothing has moved the hero here
6F5C LDA previous_y ; And the y...
6F5F STA hero_y,x ; ...is put back the same way
6F62 LDA hero_frame,x ; Next animation frame...
6F65 EOR #1 ; ...0 and 1 alternate...
6F67 STA hero_frame,x ; ...so the hero is seen to throw
6F6A JMP draw_moved_hero ; Draw the hero where they stand; no erase needed
; Unreachable after the JMP: DEY and BNE find_missile_slot.
6F6D EQUB &88, &D0, &B8 ; Not referenced
; Slot taken: try the hero's next one, up to the limit worked ; out above.
6F70 .next_missile_slot←1← 6F2B BNE
INY ; The hero's next slot
6F71 CPY scratch ; Past the hero's last slot?
6F74 BNE find_missile_slot ; No: is that one free?
6F76 JMP draw_moved_hero ; All the hero's missiles in flight: no shot
; Move: try the next cell the way the hero faces. A wall or ; closed door, a monster, or another hero in play refuses it. ; The hero has already turned, so a refused move still changes ; the way they face.
6F79 .step_hero←4← 6ED1 JMP← 6EE4 JMP← 6EF7 JMP← 6F0A JMP
LDA hero_direction,x ; Move the hero's cell in the direction faced: up...
6F7C CMP #1 ; Direction 1, facing up?
6F7E BNE step_right ; No: try right
6F80 DEC hero_y,x ; Up: one row up the map
6F83 .step_right←1← 6F7E BNE
CMP #3 ; Direction 3, facing right? (A still holds it)
6F85 BNE step_down ; No: try down
6F87 INC hero_x,x ; Right: one column along
6F8A .step_down←1← 6F85 BNE
CMP #5 ; Direction 5, facing down?
6F8C BNE step_left ; No: try left
6F8E INC hero_y,x ; Down: one row down the map
6F91 .step_left←1← 6F8C BNE
CMP #7 ; Direction 7, facing left?
6F93 BNE note_new_cell ; No: the cell is moved
6F95 DEC hero_x,x ; Left: one column back
6F98 .note_new_cell←1← 6F93 BNE
LDA hero_x,x ; Record the cell tried, wall or not...
6F9B STA hero_door_x,x ; ...so update_game finds a door the hero walks into
6F9E LDA hero_y,x ; And the y tried...
6FA1 STA hero_door_y,x ; ...in hero_door_y, for the same door test
6FA4 LDA hero_x,x ; Is the cell tried a wall (or a closed door)?
6FA7 STA cell_x ; cell_x: the cell for test_wall
6FAA LDA hero_y,x ; And the y tried...
6FAD STA cell_y ; ...in cell_y, also used by the hero test
6FB0 TXA ; Keep the hero number...
6FB1 PHA ; ...on the stack across test_wall
6FB2 JSR test_wall ; Y = the cell's wall bit; map_ptr = its room
6FB5 PLA ; Recover the hero number...
6FB6 TAX ; ...into X, which test_wall used for the bit
6FB7 CPY #0 ; Wall bit clear?
6FB9 BEQ check_monster_in_cell ; Clear: is a monster in the way?
; Refused by a wall or closed door: back to the old cell, ; standing whole. The door test in update_game may still open ; it.
6FBB LDA previous_x ; A wall: the hero stays in the old cell...
6FBE STA hero_x,x ; ...hero_x put back from previous_x...
6FC1 LDA previous_y ; ...and y back...
6FC4 STA hero_y,x ; ...so the hero does not enter the wall
6FC7 .cancel_hero_step←1← 7050 JMP
LDA #0 ; The move is over: the hero stands in a whole cell
6FC9 STA hero_step,x ; No step under way...
6FCC STA hero_offset_x,x ; ...no horizontal offset...
6FCF STA hero_offset_y,x ; ...and no vertical offset
6FD2 JMP erase_hero ; Erase the old image, draw the hero in their cell
; No wall. A monster in the cell, alive or dying, refuses the ; move and costs the hero one health point.
6FD5 .check_monster_in_cell←1← 6FB9 BEQ
LDA #0 ; Is a monster in the cell tried?
6FD7 STA scratch ; scratch 0: look for monsters only, not heroes
6FDA TXA ; Keep the hero number...
6FDB PHA ; ...on the stack across find_creature
6FDC JSR find_creature ; Y non-zero if a monster is in the cell
6FDF PLA ; Recover the hero number...
6FE0 TAX ; ...into X, which find_creature used for monsters
6FE1 CPY #0 ; A monster there?
6FE3 BEQ check_hero_in_cell ; No: is another hero in the way?
6FE5 LDA previous_x ; Yes: the hero stays in the old cell...
6FE8 STA hero_x,x ; ...hero_x put back from previous_x...
6FEB LDA previous_y ; ...and y back...
6FEE STA hero_y,x ; ...so the hero stays out of the monster's cell
6FF1 LDA #0 ; The move is over: the hero stands in a whole cell...
6FF3 STA hero_step,x ; ...no step under way...
6FF6 STA hero_offset_x,x ; ...no horizontal offset...
6FF9 STA hero_offset_y,x ; ...and no vertical offset
6FFC JSR lose_health_point ; ...and pays a health point for walking into it
6FFF JMP erase_hero ; Erase the old image, draw the hero in their cell
; Nor a monster. Another hero in play there refuses the move at ; no cost; a hero out of play (a skull) does not.
7002 .check_hero_in_cell←1← 6FE3 BEQ
STX scratch ; Is another hero in play in the cell tried?
7005 LDY #0 ; From hero 0
7007 .check_other_hero←1← 703E BNE
CPY scratch ; The moving hero itself?
700A BEQ next_other_hero ; Yes: skip it
700C LDA hero_x,y ; Other hero's x...
700F CMP cell_x ; ...the cell tried's x?
7012 BNE next_other_hero ; No: not in the way
7014 LDA hero_y,y ; Other hero's y...
7017 CMP cell_y ; ...the cell tried's y?
701A BNE next_other_hero ; No: not in the way
701C LDA hero_direction,y ; There, but in play?
701F BEQ next_other_hero ; No (a skull, say): not in the way
7021 LDA previous_x ; In play there: the hero stays in the old cell...
7024 STA hero_x,x ; ...hero_x put back from previous_x...
7027 LDA previous_y ; ...and y back...
702A STA hero_y,x ; ...so heroes in play never share a cell
702D LDA #0 ; The move is over: the hero stands in a whole cell...
702F STA hero_step,x ; ...no step under way...
7032 STA hero_offset_x,x ; ...no horizontal offset...
7035 STA hero_offset_y,x ; ...and no vertical offset
7038 JMP erase_hero ; Erase the old image, draw the hero in their cell
703B .next_other_hero←4← 700A BEQ← 7012 BNE← 701A BNE← 701F BEQ
INY ; Next hero to compare with the cell tried
703C CPY #4 ; Checked all four?
703E BNE check_other_hero ; No: check that one
; The cell is free. A move into another room is made at once, as ; is one with the Boots of Speed; otherwise the hero is drawn ; half way and arrives on the next frame.
7040 TXA ; The way is clear. Is the cell tried in another room?
7041 ASL ; Two bytes per view_room entry...
7042 TAX ; ...so X = 2 x hero indexes the hero's view
7043 LDA view_room,x ; The low byte of the room the hero's view shows...
7046 CMP map_ptr ; ...against the cell's room, left by test_wall
7048 BEQ check_boots ; Same room: the boots decide the pace
704A TXA ; New room: the hero arrives at once...
704B LSR ; Halve the index...
704C TAX ; ...back to the hero number
704D JSR show_hero_room ; Switch the hero's view to the new room and draw it
7050 JMP cancel_hero_step ; ...and the move ends in the new cell, no half step
7053 .check_boots←1← 7048 BEQ
TXA ; Wearing the Boots of Speed?
7054 LSR ; Halve the view index...
7055 TAX ; ...back to the hero number
7056 LDA hero_has_boots,x ; Non-zero while the hero wears the boots
7059 BEQ stay_in_old_cell ; No: a half step this frame
705B LDA #0 ; Yes: arrive in the cell at once, with no step
705D STA hero_offset_x,x ; No horizontal offset...
7060 STA hero_offset_y,x ; ...no vertical offset...
7063 STA hero_step,x ; ...and no step: one cell a frame, twice the pace
7066 JMP erase_hero ; Erase the old position and draw the new
7069 .stay_in_old_cell←1← 7059 BEQ
LDA previous_x ; No boots: hero stays in the old cell, drawn half way
706C STA hero_x,x ; ...by start_hero_step's offsets; next frame it arrives
706F LDA previous_y ; And the old y...
7072 STA hero_y,x ; ...so others still meet the hero in the old cell
; Erase the hero's image from where it was drawn last.
7075 .erase_hero←5← 6EB7 JMP← 6FD2 JMP← 6FFF JMP← 7038 JMP← 7066 JMP
LDA #spr_blank ; Erase the hero's image as it was before this frame
7077 STA sprite_number ; The blank sprite...
7079 LDA previous_x ; ...at the hero's old cell...
707C STA cell_x ; ...as the cell to plot at
707F LDA previous_y ; And the old y...
7082 STA cell_y ; ...in cell_y: where the hero was last drawn
7085 LDA previous_offset_x ; With the old pixel offsets too...
7088 STA plot_offset_x ; ...the old horizontal offset...
708A LDA previous_offset_y ; ...and the old vertical offset...
708D STA plot_offset_y ; ...so a half-way image is blanked where it was
708F TXA ; Keep the hero number...
7090 PHA ; ...on the stack across plot_at_cell
7091 JSR plot_at_cell ; Blank the hero in every view showing that cell
7094 PLA ; Recover the hero number...
7095 TAX ; ...into X, to draw the same hero
; Draw the hero, then pick up any object in their cell. A hero ; comes here on every frame they are moved, standing still or ; not, so a hero standing on an energy drainer loses 10 health a ; frame.
7096 .draw_moved_hero←4← 6F15 JMP← 6F6A JMP← 6F76 JMP← 76AE JMP
CLC ; Clear carry for the sprite sum
7097 LDA hero_direction,x ; Still in play? A bump or magic's cost may have killed
709A BEQ next_hero ; Direction 0: out of play, not drawn
709C ADC hero_frame,x ; Sprite = direction + frame (0 or 1)...
709F ADC hero_sprites,x ; ...+ the hero's base: Ranger, Magic-User, and so on
70A2 STA sprite_number ; The sprite to draw
70A4 JSR draw_hero ; Draw them in every view showing their cell
70A7 LDA hero_x,x ; Can the hero's cell hold an object?
70AA STA cell_x ; The hero's cell, to test for an object...
70AD LDA hero_y,x ; And the hero's y...
70B0 STA cell_y ; ...in cell_y, where they now stand
70B3 TXA ; Keep the hero number...
70B4 PHA ; ...on the stack across test_object_free
70B5 JSR test_object_free ; Y zero if an object may lie in the cell
70B8 PLA ; Recover the hero number...
70B9 TAX ; ...into X, for collect_objects
70BA CPY #0 ; Can an object lie there?
70BC BNE next_hero ; No: nothing to pick up; next hero
70BE JSR collect_objects ; Yes: pick up whatever is there
; On to the next hero, until all four have had their turn.
70C1 .next_hero←4← 6E8E JMP← 6E94 JMP← 709A BEQ← 70BC BNE
INX ; Next hero, in the order Ranger to Fighter
70C2 CPX #4 ; All four heroes moved?
70C4 BEQ move_heroes_done ; Yes: every hero has had this frame's turn
70C6 JMP move_hero ; No: move the next hero
70C9 .move_heroes_done←1← 70C4 BEQ
RTS ; Return to update_game, all four heroes moved and drawn

Move the missiles

Fly every missile in flight one cell and settle what it hits. update_game calls this each frame, after move_heroes (which fires them) and draw_objects, and before update_monsters, which plays out the deaths it causes.

Each of the twelve slots (three per hero, from 3 x hero) with a non-zero missile_direction is in flight. It is erased from its cell, unless fired this frame (bit 7 set) and so still on its hero, whose frame flip_firer_frame then flips back. It moves one cell in its direction (1-4: up, right, down, left), a cell a frame with no pixel offset, and the new cell is tried in turn, with the slot kept on the stack throughout. A wall spends the missile. A live monster takes its damage through monster_hit, which spends the missile and, for a kill, gives the firer a point; a monster already sparkling lets it through. The test for live is a sprite below the first sparkle, so a monster killed earlier in the frame (sprite blank until update_monsters runs) can be hit again. An energy drainer is worn down a stage, and removed after its last; the firer scores a point and the missile is turned round in the drainer's cell, so it can fly back into its firer. Any hero in the cell, the firer included and whether in play or not (a skull stops it), spends the missile, and lose_health_point takes missile_damage points, one at a time, from a hero in play. Otherwise the missile is drawn in its new cell as missile_sprite_base + direction, the weapon pointing the way it flies. A spent missile is not drawn, and its direction 0 frees the slot for its hero's next shot. Missiles pass through one another and through objects other than drainers.

On ExitAcorrupted
Xcorrupted
Ycorrupted
70CA .move_missiles←1← 1ED1 JSR
LDA #0 ; Missiles move a whole cell a frame...
70CC STA plot_offset_x ; ...so they are plotted with no horizontal offset...
70CE STA plot_offset_y ; ...and no vertical offset
70D0 LDX #0 ; Slot 0 first: the Ranger's first missile
; For missile slot X: an empty slot (direction 0) is passed ; over. One fired this frame shares its hero's cell and is moved ; without being erased.
70D2 .move_missile←1← 721D JMP
LDA missile_direction,x ; A direction means this slot's missile is flying
70D5 BNE check_just_fired ; Flying: erase and move it
70D7 JMP next_missile ; Empty slot: nothing to move
70DA .check_just_fired←1← 70D5 BNE
BPL erase_missile ; Bit 7 clear: flying since an earlier frame
70DC AND #&7f ; Fired this frame: drop the just-fired bit...
70DE STA missile_direction,x ; ...leaving direction 1-4
70E1 JSR flip_firer_frame ; ...flip the firer's animation frame again...
70E4 JMP step_missile ; ...and move it unerased: its cell is the hero's
; Erase the missile and move it one cell.
70E7 .erase_missile←1← 70DA BPL
LDA #spr_blank ; Erase the missile from the cell it flew to last frame
70E9 STA sprite_number ; The blank sprite
70EB LDA missile_x,x ; The missile's x...
70EE STA cell_x ; ...as the cell to plot at
70F1 LDA missile_y,x ; And its y...
70F4 STA cell_y ; ...in cell_y: where it was drawn last frame
70F7 TXA ; Keep the missile slot...
70F8 PHA ; ...on the stack across plot_at_cell
70F9 JSR plot_at_cell ; Blank it in every view showing that cell
70FC PLA ; Recover the missile slot...
70FD TAX ; ...into X, to move the same missile
70FE .step_missile←1← 70E4 JMP
LDA missile_direction,x ; Move it one cell the way it flies: up...
7101 CMP #1 ; Direction 1: up
7103 BNE missile_right ; No: try right
7105 DEC missile_y,x ; Up: one row up the map
7108 .missile_right←1← 7103 BNE
CMP #2 ; Direction 2: right? (A still holds it)
710A BNE missile_down ; No: try down
710C INC missile_x,x ; Right: one column along
710F .missile_down←1← 710A BNE
CMP #3 ; Direction 3: down?
7111 BNE missile_left ; No: try left
7113 INC missile_y,x ; Down: one row down the map
7116 .missile_left←1← 7111 BNE
CMP #4 ; Direction 4: left?
7118 BNE check_missile_wall ; No: the cell is moved
711A DEC missile_x,x ; Left: one column back
; Try the new cell: wall, monster, energy drainer, then hero. ; The slot stays on the stack through the tests.
711D .check_missile_wall←1← 7118 BNE
LDA missile_x,x ; Does the missile's new cell hold a wall or door?
7120 STA cell_x ; ...as the cell to test
7123 LDA missile_y,x ; And its y...
7126 STA cell_y ; ...in cell_y, kept for every test below
7129 TXA ; Keep the missile slot...
712A PHA ; ...on the stack across the tests
712B JSR test_wall ; Z set if the cell is clear of walls
712E BEQ check_missile_monster ; Clear: is a monster there?
; Spent: the missile stops where it is, undrawn, and its slot is ; free for its hero's next shot.
7130 .missile_spent_pop←2← 71FE JMP← 75AB JMP
PLA ; A wall: the missile stops, never drawn there
7131 TAX ; Recover the missile slot
7132 .missile_spent←1← 7153 JMP
LDA #0 ; The missile is spent: free its slot...
7134 STA missile_direction,x ; ...direction 0, so the hero may fire again
7137 JMP next_missile ; On to the next slot
; No wall. A live monster takes the hit; a sparkling (dying) one ; lets the missile through.
713A .check_missile_monster←1← 712E BEQ
LDA #0 ; Is a monster in the new cell?
713C STA scratch ; scratch 0: look for monsters only, not heroes
713F JSR find_creature ; Z clear, X = the monster, if one is in the cell
7142 BEQ check_missile_object ; None: an object or a hero?
7144 LDA monster_sprite,x ; One there: is it still alive?
7147 CMP #spr_sparkle_0 ; Sparkles on: dying; the blank (just killed) is live
7149 BCS check_missile_object ; Dying: the missile flies through it
714B PLA ; Alive: hit it, with the slot off the stack...
714C TAY ; ...in Y, for monster_hit
714D JMP monster_hit ; Hit sound, damage; it spends the missile
; monster_hit jumps back here, slot in X, when its hit kills the ; monster.
7150 .monster_killed←1← 75A3 JMP
JSR credit_missile_owner ; monster_hit's kill: a point to the firer...
7153 JMP missile_spent ; ...and the missile is spent
; No live monster there. If the cell can hold an object, look ; for an energy drainer there.
7156 .check_missile_object←2← 7142 BEQ← 7149 BCS
PLA ; Could the new cell hold an object (a drainer)?
7157 TAX ; Recover the missile slot
7158 LDA missile_x,x ; The missile's x...
715B STA cell_x ; ...as the cell to test
715E LDA missile_y,x ; And its y...
7161 STA cell_y ; ...in cell_y (find_creature left it intact)
7164 TXA ; Keep the missile slot...
7165 PHA ; ...on the stack across test_object_free
7166 JSR test_object_free ; Y zero if an object may lie in the cell
7169 PLA ; Recover the missile slot...
716A TAX ; ...into X, which test_object_free used for the bit
716B CPY #0 ; Can an object lie there?
716D BNE check_missile_hero ; No: no drainer; is a hero there?
; A missile hitting an energy drainer wears it down, scores for ; the firer and turns round in its cell.
716F TXA ; Look for an energy drainer at the cell...
7170 PHA ; Keep the missile slot while X runs over objects
7171 LDX #max_object ; ...objects 30 to 1
7173 .check_object_drainer←1← 71D5 BNE
LDA object_x,x ; This object's x...
7176 CMP cell_x ; ...the missile's cell?
7179 BNE next_object_drainer ; No: the next object
717B LDA object_y,x ; This object's y...
717E CMP cell_y ; ...the missile's cell too?
7181 BNE next_object_drainer ; No: the next object
7183 LDA object_type,x ; The object in the cell: a drainer (&53-&5E)?
7186 CMP #spr_drainer_0 ; Below the drainer sprites?
7188 BCC no_drainer ; Yes: some other object; stop looking
718A CMP #spr_drainer_11 + 1 ; Past the last drainer stage?
718C BCS no_drainer ; Yes: some other object; stop looking
718E INC object_type,x ; A drainer: the hit wears it down a stage
7191 LDA object_type,x ; Its new stage...
7194 CMP #spr_drainer_11 + 1 ; Past the last (12 hits from the first stage)?
7196 BNE credit_drainer_hit ; No: it survives; score and bounce
7198 LDA #off_map ; Worn away: take it out of the level
719A STA object_x,x ; Off the map in x...
719D STA object_y,x ; ...and y, so it is never drawn or met again
71A0 .credit_drainer_hit←1← 7196 BNE
PLA ; A point to the hero who fired, for every hit
71A1 TAX ; Recover the missile slot
71A2 JSR credit_missile_owner ; The missile's sprites say whose it is
71A5 LDA missile_direction,x ; Turn the missile round, still in the drainer's cell
71A8 CMP #1 ; Direction 1, flying up?
71AA BNE reverse_right ; No: try right
71AC LDA #3 ; Up turns to down...
71AE STA missile_direction,x ; ...back the way it came
71B1 JMP check_missile_hero ; Is a hero in the drainer's cell?
71B4 .reverse_right←1← 71AA BNE
CMP #2 ; Direction 2, flying right?
71B6 BNE reverse_down ; No: try down
71B8 LDA #4 ; Right turns to left...
71BA STA missile_direction,x ; ...back the way it came
71BD JMP check_missile_hero ; Is a hero in the drainer's cell?
71C0 .reverse_down←1← 71B6 BNE
CMP #3 ; Direction 3, flying down?
71C2 BNE reverse_left ; No: it was flying left
71C4 LDA #1 ; Down turns to up...
71C6 STA missile_direction,x ; ...back the way it came
71C9 JMP check_missile_hero ; Is a hero in the drainer's cell?
71CC .reverse_left←1← 71C2 BNE
LDA #2 ; Left turns to right...
71CE STA missile_direction,x ; ...back the way it came
71D1 JMP check_missile_hero ; Is a hero in the drainer's cell?
71D4 .next_object_drainer←2← 7179 BNE← 7181 BNE
DEX ; Next object down, looking for one in the cell
71D5 BNE check_object_drainer ; Until all 30 are checked
71D7 .no_drainer←2← 7188 BCC← 718C BCS
PLA ; No drainer in the cell: drop the saved slot...
71D8 TAX ; ...back into X
; The first hero in the cell, in play or not, stops the missile.
71D9 .check_missile_hero←5← 716D BNE← 71B1 JMP← 71BD JMP← 71C9 JMP← 71D1 JMP
TXA ; Is a hero in the new cell? Any hero, even the firer
71DA PHA ; Keep the missile slot while X runs over heroes
71DB LDX #0 ; From hero 0
71DD .check_hero_hit←1← 7204 BNE
PLA ; Fetch the missile slot...
71DE TAY ; ...into Y, to read its damage if this hero is hit...
71DF PHA ; ...leaving it on the stack
71E0 LDA hero_x,x ; This hero's x...
71E3 CMP cell_x ; ...the missile's cell?
71E6 BNE next_hero_hit ; No: the next hero
71E8 LDA hero_y,x ; This hero's y...
71EB CMP cell_y ; ...the missile's cell too?
71EE BNE next_hero_hit ; No: the next hero
71F0 LDA missile_damage,y ; Hit: the hero loses the missile's damage...
71F3 TAY ; ...Y health points, one at a time
71F4 .take_missile_damage←1← 71FC BNE
TYA ; Keep the count...
71F5 PHA ; ...on the stack across the call
71F6 JSR lose_health_point ; One point (none if out of play, as a skull)
71F9 PLA ; Recover the count...
71FA TAY ; ...of damage points still to take, into Y
71FB DEY ; One fewer to take
71FC BNE take_missile_damage ; More to take: take the next
71FE JMP missile_spent_pop ; The missile is spent, slot still on the stack
7201 .next_hero_hit←2← 71E6 BNE← 71EE BNE
INX ; Next hero to test against the missile's cell
7202 CPX #4 ; All four heroes checked?
7204 BNE check_hero_hit ; No: check the next hero against the missile's cell
; No wall, live monster or hero in the new cell: draw the ; missile there, pointing the way it flies (a drainer will have ; turned it round), then go on to the next slot.
7206 PLA ; Nothing hit: the missile flies on, drawn in its new cell
7207 TAX ; Missile slot back in X
7208 CLC ; Sprite = the missile's base...
7209 LDA missile_sprite_base,x ; ...(its hero's weapon, the sprite before its up sprite)...
720C ADC missile_direction,x ; ...plus its direction, 1-4: the weapon pointing that way
720F STA sprite_number ; ...is the sprite to plot
7211 TXA ; Keep the missile slot...
7212 PHA ; ...across the plot
7213 JSR plot_at_cell ; Plot the missile in every view showing its cell
7216 PLA ; Recover the missile slot...
7217 TAX ; ...into X, for the slot loop
7218 .next_missile←2← 70D7 JMP← 7137 JMP
INX ; Next missile slot
7219 CPX #&0c ; Past the twelfth slot (three per hero)?
721B BEQ move_missiles_done ; Yes: every missile moved this frame
721D JMP move_missile ; No: move this slot's missile
7220 .move_missiles_done←1← 721B BEQ
RTS ; Return to update_game: all twelve slots done

Take one health point from a hero

If hero X is in play, take one point from their health and redraw it in the status panel; if that point was their last, kill them.

Every kind of harm is paid through here, one call per point: a hero walking into a monster (move_heroes, 1 point), a monster stepping onto a hero (hero_damage_taken points), a missile (its damage), an energy drainer (10, from collect_objects) and the cost of magic (6 for the Ranger, 3 for the Magic-User). Three callers use it only to draw a health they have set one point high: draw_status_panel (99 + 1 at each level), the potion, and a returning hero (33, drawn as 32).

Health is two digit sprites, hero_health_tens and hero_health_units (&1E-&27 for 0-9), so the units digit wraps from 0 to 9 with a borrow from the tens. Health 00 is still alive; the hero dies when a point is taken from 00, which leaves the tens at &1D, one below the 0 sprite: the play loop tests that to count the dead. On death the hero's sprite is erased from every view, they leave play (direction 0), the death animation is started (frame step +1, counter 1, run by move_heroes) and their number + 1 is put in the first free entry of returning_hero_queue, for a Cross of Resurrection to bring back. The health is not redrawn on death. A hero out of play (dying, returning, or not playing) loses nothing, so a skull is safe to touch.

On EntryXhero number (0-3)
On ExitXpreserved
7221 .lose_health_point←8← 0EFF JSR← 6FFC JSR← 71F6 JSR← 749A JSR← 7512 JSR← 7654 JSR← 772A JSR← 79AC JSR
LDA hero_direction,x ; Direction 0: out of play, dying or returning
7224 BNE take_health_unit ; In play: they can be hurt
7226 RTS ; Out of play: nothing to lose
7227 .take_health_unit←1← 7224 BNE
DEC hero_health_units,x ; Health down one: the units digit sprite
722A LDA hero_health_units,x ; ...and look at the new units digit
722D CMP #spr_digit_0 - 1 ; Gone below the 0 sprite?
722F BNE draw_health ; No: the tens are untouched, redraw the health
7231 LDA #spr_digit_9 ; Yes: units back to 9...
7233 STA hero_health_units,x ; ...so 30 becomes 29
7236 DEC hero_health_tens,x ; ...and borrow from the tens
7239 LDA hero_health_tens,x ; ...and look at the new tens digit
723C CMP #spr_digit_0 - 1 ; Below 0? The point was taken from 00
723E BNE draw_health ; No: still alive, redraw the health
; The point was taken from health 00: the hero dies. The tens ; digit is left at &1D, below the 0 sprite, which marks the hero ; as dead to the play loop.
7240 LDA #spr_blank ; The hero has died: erase them...
7242 STA sprite_number ; ...with the blank sprite...
7244 JSR draw_hero ; ...at their cell in every view showing it
7247 LDA #0 ; ...take them out of play...
7249 STA hero_direction,x ; ...so they neither move nor take more harm
724C LDA #1 ; ...and start the death animation:
724E STA hero_offset_x,x ; ...frame step +1: forwards to the skull...
7251 STA hero_offset_y,x ; ...frame counter 1: the first step comes next frame
; Put the hero in the first free (zero) entry of ; returning_hero_queue, as hero + 1, to wait for a Cross. The ; search has no limit; a free entry is always there, as the ; queue holds at most one entry per hero.
7254 LDY #0 ; Queue them for a Cross: from the queue's front...
7256 .find_queue_slot←1← 7264 BNE
LDA returning_hero_queue,y ; ...look at this queue entry
7259 BNE next_queue_slot ; Taken: try the next entry
725B TXA ; Free: entry = hero number + 1...
725C CLC ; ...(carry clear for the add)...
725D ADC #1 ; ...(entries are hero + 1, so 0 can mean free)...
725F STA returning_hero_queue,y ; ...queued behind those already waiting
7262 RTS ; Return, health not redrawn
7263 .next_queue_slot←1← 7259 BNE
INY ; Next queue entry
7264 BNE find_queue_slot ; Keep looking (an empty entry is always found)
; Draw hero X's health, two digit sprites on the top row of ; their panel section, tens at panel_left and units three byte ; columns right. lose_health_point falls through to here and ; food calls it; plot_sprite corrupts X, so the hero is kept on ; the stack.
7266 .draw_health←3← 722F BNE← 723E BNE← 73A2 JSR
LDA hero_panel_y,x ; Health on the top row of the hero's panel section...
7269 STA plot_y ; ...as the plotting row
726B LDA #panel_left ; Tens in the panel's left column...
726D STA plot_x ; ...as the plotting column
726F LDA hero_health_tens,x ; The tens digit sprite...
7272 STA sprite_number ; ...as the sprite to plot
7274 TXA ; Keep the hero number...
7275 PHA ; ...across the plot
7276 JSR plot_sprite ; Plot the health's tens digit
7279 PLA ; Recover the hero number...
727A TAX ; ...into X, for the units digit
727B LDA hero_health_units,x ; The units digit sprite...
727E STA sprite_number ; ...as the sprite to plot
7280 LDA #panel_left + 3 ; ...three byte columns right of the tens...
7282 STA plot_x ; ...on the same row
7284 TXA ; Keep the hero number...
7285 PHA ; ...across the plot
7286 JSR plot_sprite ; Plot the health's units digit
7289 PLA ; Recover the hero number...
728A TAX ; ...into X, as the caller had it
728B RTS ; Return with the health drawn and X the hero

Add one point to a hero's score

Add one to hero X's score and redraw it in the status panel. Points come one at a time from here: a monster killed by a missile or by magic, a hit on an energy drainer, food (five calls) and a door opened (seven); draw_status_panel calls it at each level just to draw the score, which adds a point. Bigger rewards go through add_ten_points.

The score is kept as digit sprites, one table per digit (hero_score_thousands, _hundreds, _tens, _units; &1E-&27 for 0-9), so it can be plotted as it stands. A units digit past 9 is set back to 0 and the carry made by falling into add_ten_points, which goes on into the hundreds and, through add_thousand_points, the thousands and the small ten-thousands digit. draw_score then plots all four main digits.

On EntryXhero number (0-3)
On ExitXpreserved
728C .add_point←5← 0F02 JSR← 1D05 JSR← 73A9 JSR← 76A2 JSR← 76D4 JSR
INC hero_score_units,x ; Score up one: the units digit sprite
728F LDA hero_score_units,x ; ...and look at the new units digit
7292 CMP #spr_digit_9 + 1 ; Past the 9 sprite?
7294 BNE draw_score ; No: nothing to carry, redraw the score
7296 LDA #spr_digit_0 ; Yes: units back to 0...
7298 STA hero_score_units,x ; ...and carry by falling into add_ten_points
fall through ↓

Add ten points to a hero's score

Add ten to hero X's score, carrying into the hundreds and through add_thousand_points, and redraw the score. collect_objects calls it for treasure (twice: 20 points), the Cross of Resurrection and every magic item; add_point falls into it to carry from the units. The units digit is not touched, which the potion relies on: it reads the units digit before calling this.

On EntryXhero number (0-3)
On ExitXpreserved
729B .add_ten_points←4← 737F JSR← 7382 JSR← 7419 JSR← 74D5 JSR
INC hero_score_tens,x ; Score up ten: the tens digit sprite
729E LDA hero_score_tens,x ; ...and look at the new tens digit
72A1 CMP #spr_digit_9 + 1 ; Past the 9 sprite?
72A3 BNE draw_score ; No: nothing to carry, redraw the score
72A5 LDA #spr_digit_0 ; Yes: tens back to 0...
72A7 STA hero_score_tens,x ; ...stored for this hero
72AA INC hero_score_hundreds,x ; ...and carry into the hundreds
72AD LDA hero_score_hundreds,x ; ...and look at the new hundreds digit
72B0 CMP #spr_digit_9 + 1 ; Past the 9 sprite?
72B2 BNE draw_score ; No: redraw the score
72B4 LDA #spr_digit_0 ; Yes: hundreds back to 0...
72B6 STA hero_score_hundreds,x ; ...stored for this hero
72B9 JSR add_thousand_points ; ...and carry into the thousands and beyond
; Draw hero X's score, four digit sprites (thousands, hundreds, ; tens, units, three byte columns apart from panel_left) twelve ; rows below the health. The ten-thousands digit is drawn by ; add_thousand_points when it changes.
72BC .draw_score←3← 7294 BNE← 72A3 BNE← 72B2 BNE
CLC ; Score: all four digits, twelve rows below the health
72BD LDA hero_panel_y,x ; Row: the hero's panel section...
72C0 ADC #&0c ; ...twelve rows down, below the health
72C2 STA plot_y ; ...as the plotting row
72C4 LDA #panel_left ; Thousands digit in the panel's left column
72C6 STA plot_x ; ...as the plotting column
72C8 LDA hero_score_thousands,x ; The thousands digit sprite...
72CB STA sprite_number ; ...as the sprite to plot
72CD TXA ; Keep the hero number...
72CE PHA ; ...across the plot
72CF JSR plot_sprite ; Plot the thousands digit
72D2 PLA ; Recover the hero number...
72D3 TAX ; ...into X, for the hundreds digit
72D4 LDA hero_score_hundreds,x ; The hundreds digit sprite...
72D7 STA sprite_number ; ...as the sprite to plot
72D9 LDA #panel_left + 3 ; ...three byte columns right (&48)...
72DB STA plot_x ; ...as the plotting column
72DD TXA ; Keep the hero number...
72DE PHA ; ...across the plot
72DF JSR plot_sprite ; Plot the hundreds digit
72E2 PLA ; Recover the hero number...
72E3 TAX ; ...into X, for the tens digit
72E4 LDA hero_score_tens,x ; The tens digit sprite...
72E7 STA sprite_number ; ...as the sprite to plot
72E9 LDA #panel_left + 6 ; ...six byte columns right (&4B)...
72EB STA plot_x ; ...as the plotting column
72ED TXA ; Keep the hero number...
72EE PHA ; ...across the plot
72EF JSR plot_sprite ; Plot the tens digit
72F2 PLA ; Recover the hero number...
72F3 TAX ; ...into X, for the units digit
72F4 LDA hero_score_units,x ; The units digit sprite...
72F7 STA sprite_number ; ...as the sprite to plot
72F9 LDA #panel_left + 9 ; ...nine byte columns right (&4E)...
72FB STA plot_x ; ...as the plotting column
72FD TXA ; Keep the hero number...
72FE PHA ; ...across the plot
72FF JSR plot_sprite ; Plot the units digit
7302 PLA ; Recover the hero number...
7303 TAX ; ...into X, as the caller had it
7304 RTS ; Return with the score drawn and X the hero

Draw the level's objects

Draw every object still on the level (treasure, food, teleporters, drainers, magic items, the exit) in whichever views show it. update_game calls this every frame, after move_heroes and the door and key checks and before move_missiles and update_monsters, so an object that a hero has just walked off or a monster has crossed is put back before the next sprites are drawn over it.

Objects 30 (the exit) down to 1 are plotted with plot_at_cell, their type being their sprite, squarely in their cells (no pixel offset). Object 0 is not drawn. A collected or worn-away object has map x and y &FF (off_map), which plot_at_cell works out to a room offset (&DB) that no view shows, so it is not drawn.

On ExitAcorrupted
X0
Ycorrupted
7305 .draw_objects←1← 1ECE JSR
LDA #0 ; No pixel offsets
7307 STA plot_offset_x ; ...across the cell horizontally...
7309 STA plot_offset_y ; ...and vertically: objects sit squarely in their cells
730B LDX #max_object ; Objects 30 to 1: plot each at its cell
730D .draw_each_object←1← 7326 BNE
LDA object_x,x ; This object's map x...
7310 STA cell_x ; ...is the cell to plot at...
7313 LDA object_y,x ; ...and its map y...
7316 STA cell_y ; ...the cell's row
7319 LDA object_type,x ; Its type, which is also its sprite...
731C STA sprite_number ; ...as the sprite to plot
731E TXA ; Keep the object number...
731F PHA ; ...across the plot
7320 JSR plot_at_cell ; Plot it in every view showing its cell
7323 PLA ; Recover the object number...
7324 TAX ; ...into X, to count down
7325 DEX ; Next object down
7326 BNE draw_each_object ; Until object 1 is drawn (object 0 is not drawn)
7328 RTS ; Return to update_game, X = 0

Pick up the object in a hero's cell

Give hero X whatever lies in the cell they have just stepped into: pick up treasure, food, the Cross or a magic item, ride a teleporter, or suffer an energy drainer. move_heroes calls this every frame for each hero in play, after drawing them (draw_moved_hero), whether they moved, stood still or fired, and only when object_free_map says the hero's cell can hold an object. A pickup is removed at once, so it acts once; a drainer stays and acts on every frame the hero's cell is its cell: the frame of arrival, each frame standing on it, and the half-step frame of leaving it (the hero's cell changes only on arrival), so walking across one within a room costs at least 20 health.

Objects 30 down to 1 are compared with the hero's cell and the first match is acted on. Finding any object at all takes off the hero's Boots of Speed and erases the bolt from the panel, before the type is looked at, so the boots are lost to a teleporter, a drainer or the exit as well as to a pickup. Then, by type (object_type, which is also the sprite):

&28 treasure: 20 points and the treasure sound; removed.

&29 food: 10 health (to at most 99), 5 points and the food sound; removed.

&2B teleporter: the hero is moved to the cell above the previous teleporter in the object list, searching back and wrapping from object 0 to 29, so each leads to the one before it and the first to the last; the cell is not tested for walls or creatures, and a lone teleporter leads to itself. The teleport sound plays and show_hero_room redraws the view. The teleporter stays.

&2A Cross of Resurrection: 10 points and the pickup sound; removed, and the first hero in returning_hero_queue starts to materialise where they fell. With nobody waiting it is wasted.

&51 the exit: passed over (update_game's check_hero_on_exit deals with it) and the search goes on.

&5F and up, magic items: removed, the pickup sound and 10 points, then &5F Boots of Speed (bolt icon, a whole cell per step), &60 helmet (one less health lost per monster blow, to at least 3, and the armour rating redrawn), &61 potion (health set to the score's units digit twice over, e.g. 77), &62 pile of weapons (one more missile in flight, to at most 3, and its icon) and anything else, &63, the magic sword (one more missile damage, to at most 9, redrawn).

Anything else (&53-&5E, an energy drainer at one of its stages): hit_sound at pitch &32 and 10 health lost, one point at a time, which can kill. The drainer stays.

Treasure, food, the Cross and magic items are removed by setting their map x and y to &FF (off_map), so they are neither drawn nor found again.

On EntryXhero number (0-3)
7329 .collect_objects←1← 70BE JSR
LDA hero_x,x ; The hero's cell: map x...
732C STA cell_x ; ...as the cell to search
732F LDA hero_y,x ; ...and map y...
7332 STA cell_y ; ...as cell_y, for the comparisons
7335 LDY #max_object ; Search from object 30, the exit, down to 1
7337 .check_object←1← 7473 JMP
LDA object_x,y ; Object Y's map x...
733A CMP cell_x ; ...the hero's column?
733D BEQ check_object_y ; Yes: compare the row
733F JMP next_object ; No: try the next object
7342 .check_object_y←1← 733D BEQ
LDA object_y,y ; Object Y's map y...
7345 CMP cell_y ; ...the hero's row?
7348 BEQ object_found ; Yes: the hero is on object Y
734A JMP next_object ; No: try the next object
; Object Y is in the hero's cell. Whatever it is, the hero loses ; the Boots of Speed and their bolt icon first.
734D .object_found←1← 7348 BEQ
TYA ; Found: any object at all costs the Boots of Speed
734E PHA ; Keep the object number...
734F LDA #0 ; ...take the boots off...
7351 STA hero_has_boots,x ; ...this hero: back to normal speed
7354 JSR point_at_boots_icon ; Point at the hero's bolt in the panel...
7357 JSR erase_boots_icon ; ...and erase it
735A PLA ; Recover the object number...
735B TAY ; ...into Y, to read its type
735C LDA object_type,y ; The object's type, which is its sprite
735F CMP #spr_treasure ; Treasure (20 points)?
7361 BNE check_food ; No: try food
; Treasure: define envelope 3 and play the treasure sound with ; it, score 20 and remove it.
7363 TXA ; Treasure: its sound, keeping hero and object
7364 PHA ; Keep the hero...
7365 TYA ; ...and the object...
7366 PHA ; ...across the OSWORD calls
7367 LDX #<(treasure_envelope) ; XY = treasure_envelope, defining envelope 3...
7369 LDY #>(treasure_envelope) ; ...the block in page &19...
736B LDA #osword_envelope ; ...OSWORD 8, ENVELOPE
736D JSR osword ; Define the treasure envelope: ENVELOPE command
7370 LDX #<(treasure_sound) ; ...then XY = treasure_sound, with envelope 3...
7372 LDY #>(treasure_sound) ; ...the next block in page &19...
7374 LDA #osword_sound ; ...OSWORD 7, SOUND
7376 JSR osword ; Play the treasure sound: SOUND command
7379 PLA ; Recover the object...
737A TAY ; ...into Y, to be removed...
737B PLA ; ...and the hero...
737C TAX ; ...into X, to be scored
737D TYA ; Treasure is worth 20 points:
737E PHA ; ...keeping the object number
737F JSR add_ten_points ; Ten points, the score redrawn...
7382 JSR add_ten_points ; ...and ten more
7385 PLA ; Recover the object number...
7386 TAY ; ...into Y, for remove_object
7387 JMP remove_object ; Take the treasure off the level
738A .check_food←1← 7361 BNE
CMP #spr_food ; Food (10 health, 5 points)?
738C BNE check_teleporter ; No: try a teleporter
; Food: add 10 health (to at most 99), redraw it, score 5, play ; the food sound and remove it.
738E INC hero_health_tens,x ; Food: +10 health, one on the tens digit...
7391 LDA hero_health_tens,x ; ...and look at the new tens digit
7394 CMP #spr_digit_9 + 1 ; Past the 9 sprite?
7396 BNE redraw_health ; No: health is up by 10
7398 LDA #spr_digit_9 ; Yes: health is capped at 99...
739A STA hero_health_tens,x ; ...tens digit 9...
739D STA hero_health_units,x ; ...units digit 9, whatever it was
73A0 .redraw_health←1← 7396 BNE
TYA ; Show the new health and score 5 points:
73A1 PHA ; Keep the object number
73A2 JSR draw_health ; Redraw the health in the panel
73A5 LDY #5 ; Food is worth 5 points
73A7 .add_food_points←1← 73AF BNE
TYA ; Keep the count of points to add...
73A8 PHA ; ...on the stack across add_point and its plots
73A9 JSR add_point ; One point, the score redrawn
73AC PLA ; Recover the count...
73AD TAY ; ...into Y, to count down
73AE DEY ; One fewer to add
73AF BNE add_food_points ; Until all five are added
73B1 TXA ; The food sound, keeping the hero
73B2 PHA ; Keep the hero across the OSWORD call
73B3 LDX #<(food_sound) ; XY = food_sound...
73B5 LDY #>(food_sound) ; ...the block in page &0B...
73B7 LDA #osword_sound ; ...OSWORD 7, SOUND
73B9 JSR osword ; Play the food sound: SOUND command
73BC PLA ; Recover the hero...
73BD TAX ; ...into X, as move_heroes had it
73BE PLA ; Recover the object number...
73BF TAY ; ...into Y, for remove_object
73C0 JMP remove_object ; Take the food off the level
73C3 .check_teleporter←1← 738C BNE
CMP #spr_teleporter ; Teleporter (moves the hero)?
73C5 BNE check_cross ; No: try the Cross
; Teleporter: find its partner, the nearest teleporter before it ; in the object list, wrapping round to 29 after object 0 (whose ; type, never set by unpack_level, is 0 and never matches). A ; lone teleporter finds itself.
73C7 .find_previous_teleporter←2← 73D1 BNE← 73D6 JMP
DEY ; Teleporter: search back from it for the previous...
73C8 LDA object_type,y ; ...object's type...
73CB CMP #spr_teleporter ; ...a teleporter too?
73CD BEQ teleport ; Yes: it is the destination
73CF CPY #0 ; Searched down to object 0?
73D1 BNE find_previous_teleporter ; No: keep looking backwards
73D3 LDY teleport_last ; Yes: wrap round to 30, so the search goes on at 29
73D6 JMP find_previous_teleporter ; ...(the one found may be this teleporter itself)
; Y is the destination teleporter. The hero arrives standing on ; the cell above it, whatever is there, and their view is moved ; to that cell's room.
73D9 .teleport←1← 73CD BEQ
TXA ; The teleport sound, keeping hero and destination
73DA PHA ; Keep the hero...
73DB TYA ; ...and the destination teleporter...
73DC PHA ; ...across the OSWORD call
73DD LDX #<(teleport_sound) ; XY = teleport_sound...
73DF LDY #>(teleport_sound) ; ...the block in page &0B...
73E1 LDA #osword_sound ; ...OSWORD 7, SOUND
73E3 JSR osword ; Play the teleport sound: SOUND command
73E6 PLA ; Recover the destination...
73E7 TAY ; ...into Y, to read its cell...
73E8 PLA ; ...and the hero...
73E9 TAX ; ...into X, the hero to move
73EA LDA object_x,y ; Move the hero to the cell above the destination...
73ED STA hero_x,x ; ...the destination's column...
73F0 STA cell_x ; ...and cell_x (show_hero_room sets it again)
73F3 LDA object_y,y ; ...and its row...
73F6 SEC ; ...less one: the row above it...
73F7 SBC #1 ; ...so the hero does not stand on it and teleport back
73F9 STA hero_y,x ; ...as the hero's row (wall or not: it is not tested)
73FC STA cell_y ; ...and cell_y, likewise
73FF LDA #0 ; Arrive standing still:
7401 STA hero_step,x ; ...not part way through a step
7404 STA hero_offset_x,x ; ...and no pixel offsets...
7407 STA hero_offset_y,x ; ...in either direction
740A JMP show_hero_room ; Point the hero's view at the room arrived in
740D .check_cross←1← 73C5 BNE
CMP #spr_cross ; Cross of Resurrection?
740F BNE check_magic_item ; No: try the exit, drainers and magic items
; Cross of Resurrection: remove it and score 10 whether or not ; anyone is waiting to return, play the pickup sound, then look ; at the front of returning_hero_queue.
7411 LDA #off_map ; Cross: take it off the level...
7413 STA object_x,y ; ...off the map in x...
7416 STA object_y,y ; ...and y, even if nobody comes back
7419 JSR add_ten_points ; The Cross is worth 10 points
741C TXA ; Keep the hero...
741D PHA ; ...across the sound and the queue
741E JSR play_pickup_sound ; Play the pickup sound
7421 LDA returning_hero_queue ; First queue entry used (a hero or a &64 marker)?
7424 BNE take_returning_hero ; Yes: bring back the first hero waiting
7426 PLA ; No: wasted. Recover the hero...
7427 TAX ; ...into X...
7428 RTS ; ...and return, the Cross spent on nobody
; Bring back the first hero waiting in returning_hero_queue. ; Each pass takes the front entry and shifts the four entries up ; one; &64 markers, which stand for heroes left out on the menu, ; are put back at the end and the next entry taken. A hero found ; is started materialising (the death animation run backwards, ; by animate_absent_hero) in the cell where they fell.
7429 .take_returning_hero←1← 7424 BNE
LDY #0 ; Take the first entry off the queue, appending 0...
742B .shift_returning_queue←1← 744A BNE
LDX returning_hero_queue ; First entry: a hero number + 1, the &64 marker or 0...
742E DEX ; ...minus 1: the hero, &63 for the marker, &FF for none
742F LDA returning_hero_queue + 1 ; Shift the queue up one: the second entry...
7432 STA returning_hero_queue ; ...becomes the first...
7435 LDA returning_hero_queue + 2 ; ...the third entry...
7438 STA returning_hero_queue + 1 ; ...becomes the second...
743B LDA returning_hero_queue + 3 ; ...the fourth entry...
743E STA returning_hero_queue + 2 ; ...becomes the third...
7441 STY returning_hero_queue + 3 ; ...and Y fills the last (0, or the marker sent back)
7444 CPX #nobody_returns - 1 ; A &64 marker (a hero absent from the menu)?
7446 BNE check_queue_empty ; No: a hero, or nobody
7448 LDY #nobody_returns ; Yes: send it to the back and take the next entry
744A BNE shift_returning_queue ; ...(always taken: Y is &64)
744C .check_queue_empty←1← 7446 BNE
CPX #&ff ; &FF: the front entry was 0, nobody left waiting?
744E BEQ cross_done ; Yes: nobody returns
7450 LDA #0 ; Start hero X materialising: out of play...
7452 STA hero_direction,x ; ...direction 0: not in play while the sprites run
7455 LDA #8 ; ...from the skull back...
7457 STA hero_frame,x ; ...frame 8, the last of hero_appearance_sprites
745A LDA #&ff ; ...stepping backwards through the sprites...
745C STA hero_offset_x,x ; ...frame step -1
745F LDA #1 ; ...the first step next frame
7461 STA hero_offset_y,x ; ...the frame counter
7464 .cross_done←1← 744E BEQ
PLA ; Recover the hero who picked up the Cross...
7465 TAX ; ...into X, for move_heroes
7466 RTS ; Return to move_heroes
; Shared tail for treasure and food: take object Y off the map.
7467 .remove_object←2← 7387 JMP← 73C0 JMP
LDA #off_map ; Take object Y off the level:
7469 STA object_x,y ; ...off the map in x...
746C STA object_y,y ; ...and y, so it is neither drawn nor found again
746F RTS ; Return to move_heroes: the object is gone
; The object is not in the hero's cell, or is the exit: try the ; next one down.
7470 .next_object←3← 733F JMP← 734A JMP← 747D BEQ
DEY ; Next object down
7471 BEQ collect_objects_done ; Past object 1: nothing in the cell
7473 JMP check_object ; Check this object
7476 .collect_objects_done←1← 7471 BEQ
RTS ; Return: nothing to act on in the hero's cell
; Not treasure, food, a teleporter or the Cross: the exit, an ; energy drainer or a magic item, told apart by type ranges ; alone.
7477 .check_magic_item←1← 740F BNE
CMP #spr_boots ; Type &5F or above: a magic item?
7479 BCS magic_item ; Yes: collect the magic item
747B CMP #spr_exit ; The exit? The main loop deals with it...
747D BEQ next_object ; ...so search on for another object in the cell
; An energy drainer (&53-&5E): sound it by playing hit_sound ; with its pitch changed to &32 for the call, then take 10 ; health one point at a time. The drainer stays, and acts again ; on every frame the hero's cell is its cell.
747F LDA #&32 ; Any other type is an energy drainer: pitch &32...
7481 STA hit_sound + 4 ; ...instead of 6 in hit_sound, the drainer's noise
7484 TXA ; Keep the hero...
7485 PHA ; ...across the OSWORD call
7486 LDX #<(hit_sound) ; XY = hit_sound, now at the drainer's pitch...
7488 LDY #>(hit_sound) ; ...the block in page &0C...
748A LDA #osword_sound ; ...OSWORD 7, SOUND
748C JSR osword ; The drainer's noise: SOUND command
748F LDA #6 ; ...then pitch 6 again...
7491 STA hit_sound + 4 ; ...for monster_hit's blow
7494 PLA ; Recover the hero...
7495 TAX ; ...into X, for lose_health_point
7496 LDY #&0a ; The drainer takes 10 health and stays
7498 .take_ten_health←1← 74A0 BNE
TYA ; Keep the count...
7499 PHA ; ...on the stack: lose_health_point corrupts Y
749A JSR lose_health_point ; One point of the hero's health
749D PLA ; Recover the count...
749E TAY ; ...into Y, to count down
749F DEY ; One fewer to take
74A0 BNE take_ten_health ; Until all ten are taken
74A2 RTS ; Return: the drainer stays, to act again next frame

Play the pickup sound

Play the sound of a Cross or magic item being picked up. collect_objects calls it for both. Envelope 3 is defined as the pickup envelope and the pickup sound played with it on the noise channel, from the OSWORD parameter blocks pickup_envelope and pickup_sound. Envelope 3 is shared with the treasure, key and exit sounds, which define their own, so it is defined again each time.

On ExitAcorrupted
Xcorrupted
Ycorrupted
74A3 .play_pickup_sound←2← 741E JSR← 74CA JSR
LDX #<(pickup_envelope) ; XY = pickup_envelope, defining envelope 3...
74A5 LDY #>(pickup_envelope) ; ...the block in page &19...
74A7 LDA #osword_envelope ; ...OSWORD 8, ENVELOPE
74A9 JSR osword ; Define it: ENVELOPE command
74AC LDX #<(pickup_sound) ; ...then XY = pickup_sound, with envelope 3...
74AE LDY #>(pickup_sound) ; ...the next block in page &19...
74B0 LDA #osword_sound ; ...OSWORD 7, SOUND
74B2 JSR osword ; Play it: SOUND command
74B5 RTS ; Return, A, X and Y corrupted by the OSWORDs
; A magic item, type &5F or above: removed, the pickup sound, ; and 10 points for every kind. The type then picks boots, ; helmet, potion or weapons, and any other type counts as a ; magic sword.
74B6 .magic_item←1← 7479 BCS
STA scratch ; A magic item: keep its type for the tests below
74B9 LDA #off_map ; Take it off the level...
74BB STA object_x,y ; ...off the map in x...
74BE STA object_y,y ; ...and y, so it is neither drawn nor found again
74C1 TXA ; The pickup sound, keeping the hero
74C2 PHA ; Keep the hero across the sound
74C3 LDA scratch ; A = (type AND 7) x 4: unused, as play_pickup_sound...
74C6 AND #7 ; ...sets its own registers...
74C8 ASL ; ...x 2...
74C9 ASL ; ...x 4, then lost to the OSWORD calls
74CA JSR play_pickup_sound ; Play the pickup sound
74CD PLA ; Recover the hero...
74CE TAX ; ...into X, to be scored
74CF LDA hero_score_units,x ; The score's units digit sprite...
74D2 STA scratch2 ; ...kept for a potion (add_ten_points leaves it)
74D5 JSR add_ten_points ; Every magic item is worth 10 points
74D8 LDA scratch ; The item's type...
74DB CMP #spr_boots ; ...Boots of Speed?
74DD BNE check_helmet ; No: try the helmet
; Boots of Speed: show the bolt and let the hero step a whole ; cell a frame, until they next find an object.
74DF JSR point_at_boots_icon ; Boots: point at the hero's bolt in the panel...
74E2 JSR plot_boots_icon ; ...and show it
74E5 LDA #1 ; ...and wear them...
74E7 STA hero_has_boots,x ; ...so the hero moves a whole cell per step
74EA RTS ; Return to move_heroes, the boots on
74EB .check_helmet←1← 74DD BNE
CMP #spr_helmet ; Magic helmet (better armour)?
74ED BNE check_potion ; No: try the potion
; Magic helmet: lower hero_damage_taken, the health a monster's ; blow takes, by one to at least 3, and redraw the armour rating ; (10 - hero_damage_taken, so at most 7).
74EF DEC hero_damage_taken,x ; Helmet: one less health lost per hit...
74F2 LDA hero_damage_taken,x ; ...and look at it
74F5 CMP #3 ; ...below 3 (armour 7, the best)?
74F7 BCS redraw_armour ; No: keep it
74F9 INC hero_damage_taken,x ; Yes: back to 3
74FC .redraw_armour←1← 74F7 BCS
JMP draw_armour_rating ; Redraw the armour rating on the shield
74FF .check_potion←1← 74ED BNE
CMP #spr_potion ; Potion of healing?
7501 BNE check_weapons ; No: try the weapons
; Potion of healing: health is set from the score's units digit ; d, read before the 10 points were added, as tens d and units d ; + 1, then lose_health_point takes a point and draws it: health ; dd, from 00 to 99.
7503 LDA scratch2 ; Potion: health = the score's last digit twice...
7506 STA hero_health_tens,x ; ...as the tens (so a score ending in 0 gives 00)
7509 INC scratch2 ; ...and the units one higher...
750C LDA scratch2 ; ...the sprite after it...
750F STA hero_health_units,x ; ...as the health's units
7512 JSR lose_health_point ; ...less a point, which also draws the health
7515 RTS ; Return to move_heroes with the new health drawn
7516 .check_weapons←1← 7501 BNE
CMP #spr_weapons ; Pile of weapons?
7518 BNE magic_sword ; No: anything else is taken as a magic sword
; Pile of weapons: one more missile allowed in flight, to at ; most 3 (the hero's three missile slots), and its icon added.
751A INC hero_max_missiles,x ; Weapons: one more missile in flight at once...
751D LDA hero_max_missiles,x ; ...and look at it
7520 CMP #4 ; ...past 3, the hero's missile slots?
7522 BNE draw_missile_icon ; No: add its icon to the panel
7524 LDA #3 ; Yes: back to 3...
7526 STA hero_max_missiles,x ; ...as the missiles allowed
7529 .draw_missile_icon←1← 7522 BNE
JMP draw_new_missile_icon ; Draw the newest missile icon

Show the room a hero has moved into

Make hero X's view show the room they are now in, and redraw that view's walls and doors. move_heroes calls this when a hero steps into another room, and a teleporter jumps here after moving the hero.

Each hero has a fixed view (0 top left to 3 bottom right). test_wall is called on the hero's cell only for the room offset it leaves in map_ptr; that becomes the low byte of the view's view_room entry (view_room + 2 x hero), the pointer into room_walls that draw_view_0 to draw_view_3 and plot_at_cell read; the high byte never changes. The matching draw_view_n then draws the room's walls and doors. Creatures and objects appear in the new view as they are next plotted.

On EntryXhero number (0-3)
On ExitXpreserved
752C .show_hero_room←2← 704D JSR← 740A JMP
LDA hero_x,x ; The hero's cell, for test_wall to find its room
752F STA cell_x ; ...as cell_x for test_wall...
7532 LDA hero_y,x ; ...and its map y...
7535 STA cell_y ; ...as cell_y for test_wall
7538 TXA ; Keep the hero...
7539 PHA ; ...on the stack: test_wall corrupts X
753A JSR test_wall ; Only for map_ptr: the offset of the cell's room
753D PLA ; Recover the hero...
753E TAX ; ...into X, to pick their view
753F PHA ; Keep the hero number across the view draw
7540 ASL ; Hero x 2: their view's entry in view_room...
7541 TAY ; ...two bytes, a pointer into room_walls
7542 LDA map_ptr ; The room's offset that test_wall left...
7544 STA view_room,y ; ...becomes the view's room
; Redraw the hero's own view, which is fixed by hero number.
7547 CPX #0 ; Redraw this hero's own view: hero 0's?
7549 BNE check_view_1 ; No: try hero 1
754B JSR draw_view_0 ; Hero 0: redraw the top-left view
754E PLA ; Recover the hero...
754F TAX ; ...into X, as the caller had it
7550 RTS ; Return with the Ranger's view redrawn
7551 .check_view_1←1← 7549 BNE
CPX #1 ; Hero 1, the top-right view?
7553 BNE check_view_2 ; No: try hero 2
7555 JSR draw_view_1 ; Yes: redraw it
7558 PLA ; Recover the hero...
7559 TAX ; ...into X, as the caller had it
755A RTS ; Return with the Magic-User's view redrawn
755B .check_view_2←1← 7553 BNE
CPX #2 ; Hero 2, the bottom-left view?
755D BNE show_view_3 ; No: hero 3
755F JSR draw_view_2 ; Yes: redraw it
7562 PLA ; Recover the hero...
7563 TAX ; ...into X, as the caller had it
7564 RTS ; Return with the Barbarian's view redrawn
7565 .show_view_3←1← 755D BNE
JSR draw_view_3 ; Hero 3: redraw the bottom-right view
7568 PLA ; Recover the hero...
7569 TAX ; ...into X, as the caller had it
756A RTS ; Return with the Fighter's view redrawn
; Magic sword: one more damage for each missile the hero fires ; from now on, to at most 9, and the panel's damage digit ; redrawn. Missiles already in flight keep their damage.
756B .magic_sword←1← 7518 BNE
INC hero_missile_damage,x ; Magic sword: one more damage per missile...
756E LDA hero_missile_damage,x ; ...and look at it
7571 CMP #&0a ; ...past 9, the most?
7573 BNE draw_missile_damage ; No: draw the new damage in the panel
7575 LDA #9 ; Yes: back to 9...
7577 STA hero_missile_damage,x ; ...as the missile damage
757A BNE draw_missile_damage ; ...and draw it (always taken)
; A missile has hit a live monster: X is the monster, Y the ; missile slot. Reached by JMP from move_missiles, and leaves by ; jumping back into it. Every hit makes the hit sound. The ; missile's damage is taken from the monster's hit points; below ; 0 kills it (0 survives), and the kill is scored by ; monster_killed. Either way the missile is spent.
757C .monster_hit←1← 714D JMP
TXA ; Hit: sound the blow
757D PHA ; Keep the monster...
757E TYA ; ...and the missile slot...
757F PHA ; ...across the OSWORD call
7580 LDX #<(hit_sound) ; XY = hit_sound, at pitch 6...
7582 LDY #>(hit_sound) ; ...the block in page &0C...
7584 LDA #osword_sound ; ...OSWORD 7, SOUND
7586 JSR osword ; Sound the blow: SOUND command
7589 PLA ; Recover the missile slot...
758A TAY ; ...into Y, for its damage...
758B PLA ; ...and the monster...
758C TAX ; ...into X, for its hit points
758D LDA monster_hit_points,x ; The monster's hit points...
7590 SEC ; ...set the carry for the subtraction...
7591 SBC missile_damage,y ; ...less this missile's damage
7594 BPL store_monster_health ; 0 or more: alive (0 hit points survives a hit)
; Killed: the monster's sprite becomes the blank, from which ; update_monsters runs the sparkles, and its slot is given this ; level's starting hit points for when it comes back at a ; trapdoor.
7596 LDA #spr_blank ; Below 0: killed. Start it dying...
7598 STA monster_sprite,x ; ...from the blank sprite through the sparkles
759B LDA monster_start_hit_points ; ...and give the slot this level's hit points...
759E STA monster_hit_points,x ; ...ready for when it comes back at a trapdoor
75A1 TYA ; Missile slot back in X...
75A2 TAX ; ...as monster_killed expects
75A3 JMP monster_killed ; ...a point to its hero, and the missile is spent
75A6 .store_monster_health←1← 7594 BPL
STA monster_hit_points,x ; Alive: store the hit points left
75A9 TYA ; Push the missile slot, as missile_spent_pop...
75AA PHA ; ...expects to find it on the stack
75AB JMP missile_spent_pop ; The missile is spent: one hit per missile
; Redraw hero X's armour rating after a magic helmet: the small ; digit 10 - hero_damage_taken (at most 7) on the shield in ; their panel section, twelve rows above the health. Jumped to ; from collect_objects; returns to its caller with X kept.
75AE .draw_armour_rating←1← 74FC JMP
SEC ; Armour rating = 10 - health lost per hit, drawn...
75AF LDA hero_panel_y,x ; ...on the shield: the hero's panel row...
75B2 SBC #&0c ; ...less twelve pixel rows...
75B4 STA plot_y ; ...as the plotting row
75B6 LDA #panel_left + 9 ; ...byte column &4E, nine right of the panel's left...
75B8 STA plot_x ; ...as the plotting column
75BA LDA #spr_small_digit_1 + 9 ; Small digit 10...
75BC SEC ; ...set the carry for the subtraction...
75BD SBC hero_damage_taken,x ; ...less the health lost per hit: 1 to 7
75C0 STA sprite_number ; ...as the sprite to plot
75C2 JMP plot_keeping_x ; Plot it, keeping X, and return
; Add the icon for hero X's newest missile after a pile of ; weapons, at the row draw_status_panel would give it (icon n at ; its row &0D + 3n, which plot_panel_sprite offsets by the panel ; row - &0E). Icons are only added: with 3 already allowed the ; third is drawn again. Jumped to from collect_objects; returns ; with X kept.
75C5 .draw_new_missile_icon←1← 7529 JMP
LDA hero_max_missiles,x ; Icon for the newest missile allowed: missiles x 2...
75C8 ASL ; ...(x 2)...
75C9 CLC ; ...clear the carry for the addition...
75CA ADC hero_max_missiles,x ; ...+ missiles again: 3 rows per icon...
75CD ADC #&0d ; ...+ &0D, as in draw_status_panel's icon rows...
75CF ADC hero_panel_y,x ; ...+ the hero's panel row...
75D2 SEC ; ...set the carry for the subtraction...
75D3 SBC #&0e ; ...- &0E, plot_panel_sprite's bias: the same row
75D5 STA plot_y ; ...as the plotting row
75D7 LDA #panel_left + 6 ; ...byte column &4B, the icons' column...
75D9 STA plot_x ; ...as the plotting column
75DB LDA #spr_missile_icon ; The missile icon...
75DD STA sprite_number ; ...as the sprite to plot
75DF JMP plot_keeping_x ; Plot it, keeping X, and return
; Redraw hero X's missile damage after a magic sword, as a small ; digit (1-9) four rows above their panel row. Jumped to from ; collect_objects; returns with X kept.
75E2 .draw_missile_damage←2← 7573 BNE← 757A BNE
LDA #panel_left + 7 ; Missile damage: byte column &4C...
75E4 STA plot_x ; ...as the plotting column
75E6 SEC ; ...set the carry for the subtraction...
75E7 LDA hero_panel_y,x ; ...the hero's panel row...
75EA SBC #4 ; ...less four pixel rows...
75EC STA plot_y ; ...as the plotting row
75EE LDA hero_missile_damage,x ; The damage, 1-9...
75F1 CLC ; ...clear the carry for the addition...
75F2 ADC #spr_small_digit_1 - 1 ; ...+ one before small digit 1: its small digit
75F4 STA sprite_number ; ...as the sprite to plot
75F6 JMP plot_keeping_x ; Plot it, keeping X, and return

Set the position of a hero's boots icon

Set plot_x to the panel's column &4A and plot_y to eight pixel rows above hero X's panel row (hero_panel_y), where the lightning bolt shows that the hero wears Boots of Speed. collect_objects calls it before plot_boots_icon, when boots are picked up, and before erase_boots_icon, when any object is found under the hero.

On EntryXhero number (0-3)
On ExitPLOT_X&4A
PLOT_Yhero_panel_y - 8
Xpreserved
75F9 .point_at_boots_icon←2← 7354 JSR← 74DF JSR
LDA #panel_left + 5 ; The bolt's byte column, &4A...
75FB STA plot_x ; ...as the plotting column
75FD SEC ; ...set the carry for the subtraction...
75FE LDA hero_panel_y,x ; ...the hero's panel row...
7601 SBC #8 ; ...8 rows above the hero's panel section
7603 STA plot_y ; ...as the icon's pixel row
7605 RTS ; Return with plot_x, plot_y at the hero's boots icon

Show a hero's boots icon

Plot the lightning bolt at plot_x, plot_y, where point_at_boots_icon has just pointed, to show that hero X now wears Boots of Speed. Called when the boots are picked up. The plot goes through plot_keeping_x, which keeps the hero number across plot_sprite (which leaves X = 0).

On EntryXhero number (0-3)
PLOT_Xthe icon's byte column
PLOT_Ythe icon's pixel row
On ExitXpreserved
7606 .plot_boots_icon←1← 74E2 JSR
LDA #spr_boots_icon ; The lightning bolt: the hero has Boots of Speed...
7608 STA sprite_number ; ...as the sprite to plot
760A JMP plot_keeping_x ; ...plotted where point_at_boots_icon pointed

Remove a hero's boots icon

Plot the blank boots sprite over the lightning bolt at plot_x, plot_y, where point_at_boots_icon has just pointed. collect_objects calls this whenever a hero finds any object, since every find takes the boots off. Falls into plot_keeping_x.

On EntryXhero number (0-3)
PLOT_Xthe icon's byte column
PLOT_Ythe icon's pixel row
On ExitXpreserved
760D .erase_boots_icon←1← 7357 JSR
LDA #spr_blank_boots_icon ; The blank: the boots are lost...
760F STA sprite_number ; ...as the sprite to plot
7611 .plot_keeping_x←4← 75C2 JMP← 75DF JMP← 75F6 JMP← 760A JMP
TXA ; Keep the hero number...
7612 PHA ; ...on the stack: plot_sprite leaves X = 0
7613 JSR plot_sprite ; Plot the icon in the hero's panel section
7616 PLA ; Recover the hero number...
7617 TAX ; ...in X again for the caller
7618 RTS ; Return with X = the hero again

Cast a hero's magic if their key is held

Let the Ranger or the Magic-User cast magic, which kills every live monster in the room they are in. move_heroes jumps here (JMP, not JSR) for heroes 0 and 1 when they stand in a cell, before reading their other keys.

hero_magic_delay is counted down first. It normally stands at 1, so the magic key (hero_magic_key) is scanned every frame; while it is not yet zero the RTS here returns from move_heroes itself, so neither this hero nor those after it move that frame. Without the key held, play goes on to read_hero_keys. With it held, the magic sound plays, the delay is set to 4 (three frozen frames follow) and the cost is taken one health point at a time: 6 for the Ranger, 3 for the Magic-User, which can kill the caster. Then every monster whose cell lies in the room the caster's view shows, and whose sprite is below the blank (alive), is given the blank sprite, the first frame of a death that update_monsters plays out, and the caster scores a point for each, through add_point, even if the cost has just killed them. Unlike a missile's kill, the magic does not reset the monster's hit points, so a monster wounded before comes back from its trapdoor still wounded. The caster does not move that frame: play goes on at draw_moved_hero, which draws them if still in play.

On EntryXhero number (0 or 1)
7619 .check_magic←1← 6EBE JMP
DEC hero_magic_delay,x ; Count down this hero's magic key delay
761C BEQ read_magic_key ; Zero: time to look at the magic key
761E RTS ; Not yet: RTS ends move_heroes; later heroes wait too
761F .read_magic_key←1← 761C BEQ
LDA #1 ; Delay 1: the key is read every frame from now on
7621 STA hero_magic_delay,x ; ...so the next press is seen at once
7624 LDA hero_magic_key,x ; This hero's magic key, an INKEY number...
7627 JSR test_key ; ...scanned: Z set if held
762A BNE no_magic ; Not held: read the movement and fire keys
; Cast the magic: play its sound, take the caster's health, then ; kill every live monster in the room the caster's view shows, a ; point each.
762C TXA ; Held: cast. Keep the hero number...
762D PHA ; ...on the stack: X carries the OSWORD blocks
762E LDX #<(magic_envelope) ; XY = magic_envelope, an OSWORD 8 block...
7630 LDY #>(magic_envelope) ; ...and its page
7632 LDA #osword_envelope ; OSWORD 8: define the magic envelope
7634 JSR osword ; ENVELOPE command
7637 LDX #<(magic_sound) ; XY = magic_sound, an OSWORD 7 block...
7639 LDY #>(magic_sound) ; ...and its page
763B LDA #osword_sound ; OSWORD 7: make the magic sound
763D JSR osword ; SOUND command
7640 PLA ; Recover the hero number...
7641 TAX ; ...the caster, in X again
; Hold off the key for three frames, then take the cost, 6 ; health for the Ranger and 3 for the Magic-User, a point at a ; time through lose_health_point. The caster may die of it; the ; spell still goes on.
7642 LDA #4 ; Ignore the key for the next three frames
7644 STA hero_magic_delay,x ; ...so one press casts only once
7647 CPX #1 ; Health cost: 3 for the Magic-User...
7649 BEQ magic_user_cost ; Magic-User (hero 1): the cheaper rate
764B LDY #6 ; ...6 for the Ranger
764D JMP take_magic_cost ; Ranger: go and take 6 points
7650 .magic_user_cost←1← 7649 BEQ
LDY #3 ; Magic-User: 3 points
7652 .take_magic_cost←2← 764D JMP← 765A BNE
TYA ; Pay the cost one health point at a time
7653 PHA ; ...the points left on the stack
7654 JSR lose_health_point ; One point off the caster, redrawn (it can kill them)
7657 PLA ; Recover the points left...
7658 TAY ; ...back in Y
7659 DEY ; One point fewer to take
765A BNE take_magic_cost ; Until the whole cost is paid
765C LDA #0 ; No monsters killed yet:
765E STA magic_kill_count ; ...magic_kill_count counts this cast's kills
7661 TXA ; The caster's view_room index, 2 x hero...
7662 ASL ; ...x 2: view_room holds two bytes per hero
7663 STA sprite_number ; ...kept in sprite_number, free as scratch here
; Kill every live monster in the caster's room. A monster parked ; off the map (&FF) is in no room and survives. The kill only ; sets the first death frame; hit points are left as they are.
7665 LDX #max_monster ; For each monster, 30 to 1...
7667 .check_magic_monster←1← 7693 BNE
LDA monster_x,x ; ...find its room from its cell: map x...
766A STA cell_x ; ...as cell_x for test_wall...
766D LDA monster_y,x ; ...and map y...
7670 STA cell_y ; ...as cell_y; the wall bit is not wanted
7673 TXA ; Keep the monster number...
7674 PHA ; ...on the stack across test_wall
7675 JSR test_wall ; test_wall leaves the monster's room in map_ptr
7678 PLA ; Recover the monster number...
7679 TAX ; ...back in X
767A LDY sprite_number ; Y = the caster's view_room index
767C LDA view_room,y ; The room the caster's view shows...
767F CMP map_ptr ; ...is it the monster's room?
7681 BNE next_monster_magic ; Another room: the monster is spared
7683 LDA monster_sprite,x ; Alive? (dying ones are sprite &15 up)
7686 CMP #spr_blank ; Below the first death frame: alive
7688 BCS next_monster_magic ; Already dying: not counted again
768A LDA #spr_blank ; Alive: the first death frame, &15...
768C STA monster_sprite,x ; ...and update_monsters plays out its death
768F INC magic_kill_count ; ...a kill to score
7692 .next_monster_magic←2← 7681 BNE← 7688 BCS
DEX ; Next monster down
7693 BNE check_magic_monster ; Until monster 1 is done
; Score a point for each kill, to the caster, through add_point.
7695 LDA sprite_number ; One point for each monster killed
7697 LSR ; ...halve the view_room index back to the hero
7698 TAX ; ...X = the caster, who scores the points
7699 LDY magic_kill_count ; ...Y = the monsters killed
769C .score_magic_kills←1← 76A8 JMP
CPY #0 ; Any kills left to score?
769E BEQ magic_cast ; None left: redraw the caster
76A0 TYA ; Keep the kills left...
76A1 PHA ; ...on the stack across add_point
76A2 JSR add_point ; One point to the caster
76A5 PLA ; Recover the kills left...
76A6 TAY ; ...back in Y
76A7 DEY ; One kill fewer to score
76A8 JMP score_magic_kills ; Score the next
76AB .no_magic←1← 762A BNE
JMP read_hero_keys ; No cast: read the movement and fire keys
76AE .magic_cast←1← 769E BEQ
JMP draw_moved_hero ; Cast: no move this frame; redraw the caster

Give a point to the hero who fired a missile

Score one point for the hero whose missile is in slot X. move_missiles calls this when a missile kills a monster (through monster_killed) and when it wears down an energy drainer. The firer is told by the missile's sprite base, as in flip_firer_frame: arrows the Ranger, fireballs the Magic-User, axes the Barbarian, and anything else the Fighter. add_point adds the point and redraws the score, whether or not the firer is still in play.

On EntryXmissile slot (0-11)
On ExitAcorrupted
Xpreserved
Ycorrupted
76B1 .credit_missile_owner←2← 7150 JSR← 71A2 JSR
LDY missile_sprite_base,x ; Which hero fired it? Its sprite base says
76B4 TXA ; Keep the missile slot...
76B5 PHA ; ...on the stack: X becomes the hero
76B6 TYA ; The sprite base, to compare
76B7 CMP #spr_arrow_up - 1 ; ...the arrows' base, one below the up arrow?
76B9 BNE owner_fireball ; Not arrows: try fireballs
76BB LDX #0 ; Arrows: the Ranger, hero 0
76BD JMP credit_owner ; Credit the Ranger
76C0 .owner_fireball←1← 76B9 BNE
CMP #spr_fireball_up - 1 ; ...the fireballs' base?
76C2 BNE owner_axe ; Not fireballs: try axes
76C4 LDX #1 ; Fireballs: the Magic-User, hero 1
76C6 JMP credit_owner ; Credit the Magic-User
76C9 .owner_axe←1← 76C2 BNE
CMP #spr_axe_up - 1 ; ...the axes' base?
76CB BNE owner_sword ; Not axes: so it must be swords
76CD LDX #2 ; Axes: the Barbarian, hero 2
76CF JMP credit_owner ; Credit the Barbarian
76D2 .owner_sword←1← 76CB BNE
LDX #3 ; Otherwise swords: the Fighter, hero 3
76D4 .credit_owner←3← 76BD JMP← 76C6 JMP← 76CF JMP
JSR add_point ; One point to the firer's score
76D7 PLA ; Recover the missile slot...
76D8 TAX ; ...in X again for move_missiles
76D9 RTS ; Return with X = the missile slot again

Animate a hero who is out of play

Play a dying hero's sparkles and skull, or a returning hero's skull and sparkles in reverse, at the cell where they fell. move_heroes calls this each frame, in the hero's turn, for a hero out of play (direction 0) unless nobody plays them (step &63). While out of play the hero's offset bytes are reused: hero_offset_y is a two-frame timer and hero_offset_x the step through the sequence (+1 or -1), both set by lose_health_point for a death and by collect_objects for a Cross of Resurrection.

Every other frame, plot hero_appearance_sprites entry hero_frame at the hero's cell, with no pixel offset, then step hero_frame by hero_offset_x: forwards (+1) for a hero dying, stopping at the skull (entry 8), which is then redrawn every other frame until a Cross brings the hero back; backwards (-1) for a hero returning through a Cross of Resurrection, from entry 8. A dying hero starts from their walking frame (0 or 1), which lose_health_point does not reset, so the first sparkle may be skipped. A returning hero is put back in play as hero_frame reaches 0, so entry 0 is never shown on the way back: they come back in the cell where they fell, facing down, standing squarely in it, with health 32 (set to 33 and drawn by taking a point). move_heroes draws them on their next turn.

On EntryXhero number (0-3)
On ExitAcorrupted
Xpreserved
Ycorrupted
76DA .animate_absent_hero←1← 6E91 JSR
DEC hero_offset_y,x ; Every other frame: count down the timer...
76DD BEQ absent_frame_due ; Timer run out: show the next sprite
76DF RTS ; Not yet: nothing to draw this frame
; Due: plot the sprite for the hero's place in the sequence at ; their cell.
76E0 .absent_frame_due←1← 76DD BEQ
LDA #2 ; Restart the two-frame timer...
76E2 STA hero_offset_y,x ; ...which an absent hero keeps in hero_offset_y
76E5 JSR get_hero_cell ; Plot the current appearance sprite at the hero's cell
76E8 LDA #0 ; No pixel offsets (those bytes hold timer and step)...
76EA STA plot_offset_x ; ...none across...
76EC STA plot_offset_y ; ...and none down
76EE LDA hero_frame,x ; The hero's place in the appearance sequence...
76F1 TAY ; ...as an index...
76F2 LDA hero_appearance_sprites,y ; ...picks the sparkle or skull to show
76F5 STA sprite_number ; ...as the sprite to plot
76F7 TXA ; Keep the hero number...
76F8 PHA ; ...on the stack: plot_at_cell changes X
76F9 JSR plot_at_cell ; Plot it in every view that shows the hero
76FC PLA ; Recover the hero number...
76FD TAX ; ...back in X
; Step to the next place, holding a dying hero at the skull ; (place 8).
76FE CLC ; Step to the next (+1 dying, -1 returning), stopping at 8
76FF LDA hero_frame,x ; Current place in the sequence...
7702 ADC hero_offset_x,x ; ...plus the step kept in hero_offset_x
7705 CMP #9 ; Past the skull (place 8)?
7707 BCC check_hero_returned ; No: keep the new place
7709 LDA #8 ; Yes: a dead hero stays on the skull
770B .check_hero_returned←1← 7707 BCC
CMP #0 ; Place 0? Only a returning hero gets there
770D BNE store_hero_frame ; No: store the new place for the next plot
; A returning hero has reached place 0: put them back in play, ; facing down, squarely in their cell, with 32 health.
770F LDA #5 ; Yes: back in play before place 0 is shown...
7711 STA hero_direction,x ; ...facing down (direction 5)
7714 LDA #0 ; ...with no step or offsets...
7716 STA hero_step,x ; ...not mid-step...
7719 STA hero_offset_x,x ; ...no horizontal offset...
771C STA hero_offset_y,x ; ...no vertical offset...
771F STA hero_frame,x ; ...and animation frame 0
7722 LDA #spr_digit_3 ; ...and health 33, drawn by taking a point
7724 STA hero_health_tens,x ; ...tens digit 3...
7727 STA hero_health_units,x ; ...units digit 3...
772A JSR lose_health_point ; ...less a point, which also draws it: 32
772D RTS ; Return with the hero back in play
772E .store_hero_frame←1← 770D BNE
STA hero_frame,x ; Store the new place, to show in two frames
7731 RTS ; Return; the hero stays out of play

Draw a hero

Plot sprite_number at hero X's cell, shifted by their pixel offsets (half a cell along while a step is under way), in every view that shows it. move_heroes calls it each frame for every hero in play, at draw_moved_hero, with the hero's sprite for their direction and frame; lose_health_point calls it with the blank to erase a hero who has just died. cell_x and cell_y are left as plot_at_cell leaves them, as positions within the view, so callers needing the map cell load it again.

On EntryXhero number (0-3)
SPRITE_NUMBERsprite to plot
On ExitAcorrupted
Xpreserved
Ycorrupted
7732 .draw_hero←2← 70A4 JSR← 7244 JSR
JSR get_hero_cell ; The hero's map cell...
7735 LDA hero_offset_x,x ; ...and the pixel offsets of a step in progress
7738 STA plot_offset_x ; ...the column offset (0 or +-2) as plot_offset_x...
773A LDA hero_offset_y,x ; ...and the row offset (0 or +-6)...
773D STA plot_offset_y ; ...as plot_offset_y
773F TXA ; Keep the hero number...
7740 PHA ; ...on the stack: each plot leaves X = 0
7741 JSR plot_at_cell ; Plot the hero in every view showing it
7744 PLA ; Recover the hero number...
7745 TAX ; ...in X again for the caller
7746 RTS ; Return with X = the hero again

Animate the hero who fired a missile

Toggle the animation frame (0 or 1) of the hero whose missile is in slot X, so the hero's sprite changes as they throw. move_missiles calls this on a missile's first move, while bit 7 of its direction still marks it as just fired; move_heroes flipped the frame when it fired, so this flips it back, and the throw shows for one frame. The firer is told by the missile's sprite base (one less than its up sprite): arrows the Ranger, fireballs the Magic-User, axes the Barbarian, and anything else the Fighter. The hero is not redrawn here; the new frame shows when move_heroes next draws them.

On EntryXmissile slot (0-11)
On ExitAcorrupted
Xpreserved
7747 .flip_firer_frame←1← 70E1 JSR
LDA missile_sprite_base,x ; Which hero fired it? Its sprite base says
774A CMP #spr_arrow_up - 1 ; ...the arrows' base, one below the up arrow?
774C BNE firer_fireball ; Not arrows: try fireballs
774E LDA hero_frame ; The Ranger's animation frame...
7751 EOR #1 ; ...flipped between 0 and 1...
7753 STA hero_frame ; ...so the Ranger's sprite changes as they fire
7756 RTS ; Return; X is still the missile slot
7757 .firer_fireball←1← 774C BNE
CMP #spr_fireball_up - 1 ; ...the fireballs' base?
7759 BNE firer_axe ; Not fireballs: try axes
775B LDA hero_frame + 1 ; The Magic-User's animation frame...
775E EOR #1 ; ...flipped between 0 and 1...
7760 STA hero_frame + 1 ; ...so the Magic-User's sprite changes as they cast
7763 RTS ; Return; X is still the missile slot
7764 .firer_axe←1← 7759 BNE
CMP #spr_axe_up - 1 ; ...the axes' base?
7766 BNE firer_sword ; Not axes: so it must be swords
7768 LDA hero_frame + 2 ; The Barbarian's animation frame...
776B EOR #1 ; ...flipped between 0 and 1...
776D STA hero_frame + 2 ; ...so the Barbarian's sprite changes as they throw
7770 RTS ; Return; X is still the missile slot
7771 .firer_sword←1← 7766 BNE
LDA hero_frame + 3 ; Otherwise swords: the Fighter's frame...
7774 EOR #1 ; ...flipped between 0 and 1...
7776 STA hero_frame + 3 ; ...so the Fighter's sprite changes as they throw
7779 RTS ; Return; X is still the missile slot

Copy a hero's position to cell_x, cell_y

Load hero X's map cell into cell_x and cell_y, ready for plot_at_cell. Used by draw_hero and animate_absent_hero.

On EntryXhero number (0-3)
On ExitCELL_Xhero_x
CELL_Yhero_y
Ahero_y
Xpreserved
777A .get_hero_cell←2← 76E5 JSR← 7732 JSR
LDA hero_x,x ; The hero's map x...
777D STA cell_x ; ...as cell_x, for plot_at_cell
7780 LDA hero_y,x ; ...and map y...
7783 STA cell_y ; ...as cell_y
7786 RTS ; Return with the hero's cell in cell_x, cell_y
7787 EQUB &73 ; Not referenced

Draw all four views

Draw the walls and doors of the room in each hero's view: the Ranger's top left, the Magic-User's top right, the Barbarian's bottom left and the Fighter's bottom right. draw_view_frames calls it once as each level starts, after drawing the frames round the views, when every view_room entry holds the heroes' starting room. A view is drawn even for a hero nobody plays. Since each draw_room plots every door in every view showing its room, the doors of a room shared by several views are drawn several times over. Heroes, monsters and objects appear as the first frame of play plots them.

On ExitAcorrupted
X0
Ycorrupted
7788 .draw_all_views←1← 1502 JSR
JSR draw_view_0 ; The Ranger's view, top left
778B JSR draw_view_1 ; The Magic-User's view, top right
778E JSR draw_view_2 ; The Barbarian's view, bottom left
7791 JSR draw_view_3 ; The Fighter's view, bottom right
7794 RTS ; Return with all four rooms drawn

Draw the top-left view

Draw the walls and doors of the room in hero 0's view, the Ranger's, whose top-left cell starts at byte column 1, pixel row 1 (see plot_at_cell for the view coordinates). draw_all_views calls this as a level starts, and show_hero_room when hero 0 enters another room. The view's corner is passed to draw_room in plot_y and, for want of a spare variable, in cell_x; only the low byte of view_room is passed, in map_ptr, as draw_room supplies page &0C.

On EntryVIEW_ROOMthe room hero 0 is in
On ExitAcorrupted
Xcorrupted
Ycorrupted
7795 .draw_view_0←2← 754B JSR← 7788 JSR
LDA #1 ; Top-left view: pixel row 1...
7797 STA plot_y ; ...as the view's top pixel row
7799 LDA #1 ; ...byte column 1...
779B STA cell_x ; ...in cell_x, as draw_room expects
779E LDA view_room ; ...the room the Ranger's view shows
77A1 STA map_ptr ; ...whose walls draw_room reads
77A3 JSR draw_room ; Draw its walls and doors
77A6 RTS ; Return with the top-left view redrawn

Draw the top-right view

Draw the room in hero 1's view, the Magic-User's, whose top-left is byte column &23, pixel row 1. Called as draw_view_0 is.

On EntryVIEW_ROOM + 2the room hero 1 is in
On ExitAcorrupted
Xcorrupted
Ycorrupted
77A7 .draw_view_1←2← 7555 JSR← 778B JSR
LDA #1 ; Top-right view: pixel row 1...
77A9 STA plot_y ; ...as the view's top pixel row
77AB LDA #view_right_column ; ...byte column &23...
77AD STA cell_x ; ...as the view's left screen column
77B0 LDA view_room + 2 ; ...the room the Magic-User's view shows
77B3 STA map_ptr ; ...whose walls draw_room reads
77B5 JSR draw_room ; Draw its walls and doors
77B8 RTS ; Return with the top-right view redrawn

Draw the bottom-left view

Draw the room in hero 2's view, the Barbarian's, whose top-left is byte column 1, pixel row &67. Called as draw_view_0 is.

On EntryVIEW_ROOM + 4the room hero 2 is in
On ExitAcorrupted
Xcorrupted
Ycorrupted
77B9 .draw_view_2←2← 755F JSR← 778E JSR
LDA #view_bottom_row ; Bottom-left view: pixel row &67...
77BB STA plot_y ; ...as the view's top pixel row
77BD LDA #1 ; ...byte column 1...
77BF STA cell_x ; ...as the view's left screen column
77C2 LDA view_room + 4 ; ...the room the Barbarian's view shows
77C5 STA map_ptr ; ...whose walls draw_room reads
77C7 JSR draw_room ; Draw its walls and doors
77CA RTS ; Return with the bottom-left view redrawn

Draw the bottom-right view

Draw the room in hero 3's view, the Fighter's, whose top-left is byte column &23, pixel row &67. Called as draw_view_0 is.

On EntryVIEW_ROOM + 6the room hero 3 is in
On ExitAcorrupted
Xcorrupted
Ycorrupted
77CB .draw_view_3←2← 7565 JSR← 7791 JSR
LDA #view_bottom_row ; Bottom-right view: pixel row &67...
77CD STA plot_y ; ...as the view's top pixel row
77CF LDA #view_right_column ; ...byte column &23...
77D1 STA cell_x ; ...as the view's left screen column
77D4 LDA view_room + 6 ; ...the room the Fighter's view shows
77D7 STA map_ptr ; ...whose walls draw_room reads
77D9 JSR draw_room ; Draw its walls and doors
77DC RTS ; Return with the bottom-right view redrawn
77DD EQUB &60 ; Not referenced

Draw a room

Repaint one view with the walls of its room and the level's doors, wiping whatever the view showed before. Called by draw_view_0 to draw_view_3, so as a level starts and whenever a hero changes room.

The room's eight wall bytes (see test_wall for the map layout) are read through map_ptr, whose high byte is set here to page &0C (room_walls). Each byte is one row of cells: draw_room_row plots a wall block or a blank in each of its eight cells, and plot_y moves down twelve pixel rows for the next. Every cell is painted, so this also wipes the previous room's creatures and objects; they reappear as they are next plotted. Then each of doors 20 to 1 is plotted at its map cell through plot_at_cell, which draws it only in views whose room holds it, and in every such view, not just this one. A closed door's cell is also a wall in room_walls, so it is first drawn as a wall block and then covered by the door; an opened door has its wall bit cleared and its position set to off_map, so it is drawn nowhere.

On EntryMAP_PTRthe room's offset in room_walls (the low byte)
CELL_Xthe view's left byte column
PLOT_Ythe view's top pixel row
On ExitAcorrupted
X0
Ycorrupted
CELL_Xcorrupted
CELL_Ycorrupted
77DE .draw_room←4← 77A3 JSR← 77B5 JSR← 77C7 JSR← 77D9 JSR
LDA #>(room_walls) ; The room's walls are in page &0C
77E0 STA map_ptr_hi ; ...so map_ptr points at the room's wall bytes
; Walls: paint each of the room's eight rows of cells, wall or ; blank, from its wall byte, twelve pixel rows apart.
77E2 LDY #0 ; For each of the room's eight rows of cells...
77E4 .draw_room_walls←1← 77FA BNE
LDA (map_ptr),y ; ...take its eight wall bits...
77E6 STA scratch ; ...in scratch for draw_room_row
77E9 TYA ; Keep the row number...
77EA PHA ; ...on the stack across the row
77EB JSR draw_room_row ; ...and draw the row's walls and blanks
77EE CLC ; Twelve pixel rows down
77EF LDA plot_y ; Down to the next row of cells...
77F1 ADC #&0c ; ...each 12 pixel rows tall
77F3 STA plot_y ; ...ready for the next row
77F5 PLA ; Recover the row number...
77F6 TAY ; ...back in Y
77F7 INY ; Next row of the room down
77F8 CPY #8 ; All eight rows done?
77FA BNE draw_room_walls ; No: draw the next row
; Doors: plot every door on the level through plot_at_cell, ; which shows only those in rooms on view, in every such view.
77FC LDX #max_door ; Then doors 20 to 1, wherever they are on the map
77FE .draw_room_doors←1← 781D BNE
LDA door_x,x ; This door's map x...
7801 STA cell_x ; ...as the cell to plot
7804 LDA door_y,x ; ...and its map y (off_map once opened)...
7807 STA cell_y ; ...as cell_y
780A LDA #0 ; Doors sit squarely in their cells:
780C STA plot_offset_x ; ...no horizontal offset...
780E STA plot_offset_y ; ...and no vertical offset
7810 LDA door_sprite,x ; Its sprite, vertical or horizontal...
7813 STA sprite_number ; ...as the sprite to plot
7815 TXA ; Keep the door number...
7816 PHA ; ...on the stack: plot_at_cell changes X
7817 JSR plot_at_cell ; Plot it in every view showing its cell
781A PLA ; Recover the door number...
781B TAX ; ...in X for the count
781C DEX ; Next door down
781D BNE draw_room_doors ; Until door 1 is drawn
781F RTS ; Return with the room and its doors drawn

Draw one row of a room

Plot a wall block or a blank in each of the eight cells of one row of a view, from bit 7 of scratch (the leftmost cell) to bit 0, four byte columns apart, starting at byte column cell_x. Called by draw_room for each row. The cells are plotted with plot_sprite directly, in this view only.

On EntrySCRATCHthe row's eight wall bits, the leftmost cell in bit 7
CELL_Xthe view's left byte column
PLOT_Ythe row's top pixel row
On ExitA0
X0
Ycorrupted
PLOT_Xcell_x + 32, just right of the view
7820 .draw_room_row←1← 77EB JSR
LDA cell_x ; Start at the view's left edge
7823 STA plot_x ; ...as the first cell's screen column
7825 LDX #&80 ; Bit mask, starting with the leftmost cell
7827 .draw_room_cell←1← 784F BNE
TXA ; Keep this cell's bit mask...
7828 PHA ; ...on the stack: plot_sprite leaves X = 0...
7829 STA scratch2 ; ...and in scratch2 for the test
782C LDA scratch ; Wall in this cell?
782F AND scratch2 ; ...against the row's wall bits
7832 BEQ plot_blank ; No: an open cell, blanked
7834 LDA #spr_wall ; Yes: plot the wall block (sprite 0)
7836 STA sprite_number ; ...as the sprite to plot
7838 JSR plot_sprite ; Draw the wall block in this cell
783B JMP next_room_cell ; On to the next cell
783E .plot_blank←1← 7832 BEQ
LDA #spr_blank ; Plot the blank (sprite &15)
7840 STA sprite_number ; ...as the sprite to plot
7842 JSR plot_sprite ; Clear whatever the view showed there
7845 .next_room_cell←1← 783B JMP
CLC ; Four byte columns right
7846 LDA plot_x ; Next cell's screen column...
7848 ADC #4 ; ...four bytes, one cell's width, along
784A STA plot_x ; ...stored for the next plot
784C PLA ; This cell's mask back from the stack...
784D LSR ; ...shifted to the next cell right
784E TAX ; ...into X; zero once the eighth cell is done
784F BNE draw_room_cell ; ...until all eight are done
7851 RTS ; Return with the row drawn, X = 0

Plot a sprite at a map cell in every view

Draw (or, with the blank sprite, erase) sprite_number at a map cell, in every view that is showing the cell's room. Heroes, skulls, monsters, sparkles, missiles, objects, keys, doors, trapdoors and the Chalice are all drawn and erased through here; only the walls (draw_room_row) and the status panel are plotted directly. So a cell in a room that two heroes share is drawn in both views, and one in a room that no view shows is not drawn at all.

Map coordinates. The dungeon is a grid of cells, x across from 0 at the left, y down from 0 at the top, divided into rooms of 8x8 cells, four rooms across (x 0-31) and six down (y 0-47). A room is named by its offset in room_walls, 32 x its row of rooms + 8 x its column of rooms, which is (y AND &F8) x 4 + (x AND &F8): always a multiple of 8, from 0 to &B8 (test_wall describes the map's bytes). The cell's place within its room is x AND 7, y AND 7.

View coordinates. plot_sprite takes a byte column (plot_x, 0-79 across the screen, two MODE 2 pixels each) and a pixel row (plot_y, from 0 at the top). Each view shows one room, 8 cells of 4 byte columns by 8 cells of 12 pixel rows (32 x 96), with its top-left at column 1 or view_right_column (&23) and row 1 or view_bottom_row (&67): hero 0's view top left, 1 top right, 2 bottom left, 3 bottom right. view_room + 2 x hero holds the offset of the room each view shows. A cell's sprite goes at the view's corner + ((x AND 7) x 4 + plot_offset_x, (y AND 7) x 12 + plot_offset_y). The offsets are signed (&FA is 6 rows up) and place a sprite part way between cells while it steps.

The room offset is worked out once and compared with the low byte of each view_room entry, views 0 to 3 in turn. A cell at off_map (&FF, &FF), where collected objects, opened doors and parked monsters are put, comes out as &DB, through the carries of the sum: not a multiple of 8, so no view shows it and it is never drawn. There is no clipping, but no hero's or monster's step crosses a room edge, so a stepping sprite stays inside its view.

cell_x and cell_y are overwritten with the position within the room, so a caller that needs the map cell again sets them again; code that reads them afterwards without doing so sees these view positions.

On EntryCELL_Xmap x
CELL_Ymap y
SPRITE_NUMBERsprite to plot
PLOT_OFFSET_Xbyte columns to shift right
PLOT_OFFSET_Ypixel rows to shift down
On ExitCELL_Xbyte column within the room
CELL_Ypixel row within the room
CELL_ROOMthe cell's room, as an offset into room_walls
; Which room is the cell in? Its offset in room_walls, the same ; number view_room holds for each view.
7852 .plot_at_cell←19← 11A8 JSR← 1200 JSR← 1D36 JSR← 1DDC JSR← 1E61 JSR← 1F6D JSR← 1FB7 JSR← 1FEC JSR← 7091 JSR← 70F9 JSR← 7213 JSR← 7320 JSR← 76F9 JSR← 7741 JSR← 7817 JSR← 79DB JSR← 7A07 JSR← 7B25 JSR← 7B5C JSR
LDA cell_y ; Room = (cell_y AND &F8) x 4 + (cell_x AND &F8)...
7855 AND #&f8 ; ...y AND &F8 = 8 x the cell's row of rooms...
7857 STA scratch ; ...kept in scratch, to add up four times...
785A CLC ; ...(y < 64 on the map: no carry, so clear it once)
785B ADC scratch ; ...doubled: 16 bytes per row of rooms so far...
785E ADC scratch ; ...tripled: 24...
7861 ADC scratch ; ...x 4: 32 bytes, four rooms, per row of rooms
7864 STA cell_room ; ...the offset of the cell's row of rooms
7867 LDA cell_x ; Add the room's column in that row...
786A AND #&f8 ; ...x AND &F8 = 8 x the column: 8 bytes per room
786C ADC cell_room ; ...giving the room's offset in room_walls (0-&B8)
786F STA cell_room ; ...in cell_room, to compare with each view_room
; Where in a view does the cell go? Its column and row within ; the room, scaled to bytes and pixel rows, plus the sprite's ; offsets.
7872 LDA cell_x ; Byte column in a view = (x AND 7) x 4 + offset_x
7875 AND #7 ; ...the cell's column within its room, 0-7...
7877 ASL ; ...x 2...
7878 ASL ; ...x 4: each cell is 4 byte columns wide
7879 CLC ; ...clear the carry for the offset
787A ADC plot_offset_x ; ...plus the sprite's signed offset in byte columns
787C STA cell_x ; ...cell_x is now the column within the view
787F LDA cell_y ; Pixel row in a view = (y AND 7) x 12 + offset_y
7882 AND #7 ; ...the cell's row within its room, 0-7...
7884 ASL ; ...x 2...
7885 ASL ; ...x 4...
7886 STA scratch ; ...row x 4 kept in scratch, for the sum...
7889 ASL ; ...x 8...
788A CLC ; ...clear the carry (at most 56 + 28)
788B ADC scratch ; ...x 8 + x 4 = x 12: each cell is 12 rows tall
788E ADC plot_offset_y ; ...plus the sprite's signed offset in pixel rows
7890 STA cell_y ; ...cell_y is now the row within the view
; Plot it in each view showing that room, at the view's top-left ; corner plus the position within the room.
7893 LDA view_room ; The Ranger's view (top left): this room?
7896 CMP cell_room ; ...the room the cell is in?
7899 BNE check_view_1_room ; Not shown there: try the top-right view
789B CLC ; Shown: screen position = view corner (1, 1) + cell's
789C LDA #1 ; ...the view's left byte column, 1...
789E ADC cell_x ; ...plus the column within the view
78A1 STA plot_x ; ...as plot_x
78A3 LDA #1 ; ...the view's top pixel row, 1...
78A5 ADC cell_y ; ...plus the row within the view
78A8 STA plot_y ; ...as plot_y
78AA JSR plot_sprite ; Draw it in the top-left view
78AD .check_view_1_room←1← 7899 BNE
LDA view_room + 2 ; The Magic-User's view (top right): this room?
78B0 CMP cell_room ; ...the room the cell is in?
78B3 BNE check_view_2_room ; Not shown there: try the bottom-left view
78B5 CLC ; Shown: view corner (&23, 1) + cell's position
78B6 LDA #view_right_column ; ...the view's left byte column...
78B8 ADC cell_x ; ...plus the column within the view
78BB STA plot_x ; ...as plot_x
78BD LDA #1 ; ...the view's top pixel row, 1...
78BF ADC cell_y ; ...plus the row within the view
78C2 STA plot_y ; ...as plot_y
78C4 JSR plot_sprite ; Draw it in the top-right view
78C7 .check_view_2_room←1← 78B3 BNE
LDA view_room + 4 ; The Barbarian's view (bottom left): this room?
78CA CMP cell_room ; ...the room the cell is in?
78CD BNE check_view_3_room ; Not shown there: try the bottom-right view
78CF CLC ; Shown: view corner (1, &67) + cell's position
78D0 LDA #1 ; ...the view's left byte column, 1...
78D2 ADC cell_x ; ...plus the column within the view
78D5 STA plot_x ; ...as plot_x
78D7 LDA #view_bottom_row ; ...the view's top pixel row...
78D9 ADC cell_y ; ...plus the row within the view
78DC STA plot_y ; ...as plot_y
78DE JSR plot_sprite ; Draw it in the bottom-left view
78E1 .check_view_3_room←1← 78CD BNE
LDA view_room + 6 ; The Fighter's view (bottom right): this room?
78E4 CMP cell_room ; ...the room the cell is in?
78E7 BNE plot_at_cell_done ; Not shown there: done
78E9 CLC ; Shown: view corner (&23, &67) + cell's position
78EA LDA #view_right_column ; ...the view's left byte column...
78EC ADC cell_x ; ...plus the column within the view
78EF STA plot_x ; ...as plot_x
78F1 LDA #view_bottom_row ; ...the view's top pixel row...
78F3 ADC cell_y ; ...plus the row within the view
78F6 STA plot_y ; ...as plot_y
78F8 JSR plot_sprite ; Draw it in the bottom-right view
78FB .plot_at_cell_done←1← 78E7 BNE
RTS ; Return; cell_x, cell_y now hold the view position

Test for a wall at a map cell

Say whether a map cell is solid: a wall, or a door not yet opened. Heroes (move_heroes), missiles (move_missiles) and monsters (update_monsters) test here the cell they are about to enter, and find_open_neighbour the cells next to the exit where drop_key can put a key down. check_magic and show_hero_room call it only for the room pointer it leaves in map_ptr.

The wall map. room_walls (&0C00) holds eight bytes per room, one per row of cells from the top, and one bit per cell, bit 7 for the leftmost (x AND 7 = 0) to bit 0 for the rightmost; a set bit is solid. Rooms are stored in rows of four, left to right, so a room's eight bytes start at (y AND &F8) x 4 + (x AND &F8) (see plot_at_cell for the coordinates), and the cell is bit bit_masks[x AND 7] of byte y AND 7 there. object_free_map at &2100 has the same layout (test_object_free). The level file supplies both; opening a door clears its bit.

The bit is returned in A and Y, with Z set for an open cell; callers that have pulled X from the stack test Y. map_ptr is left pointing at the room's bytes, its low byte being the room offset that view_room uses. Coordinates off the map are not checked: off_map (&FF, &FF) reads a byte beyond the wall map. The bit is also stored in &8F (victory_pitch), which the victory sequence sets before it reads it, so the copy is never used.

On EntryCELL_Xmap x
CELL_Ymap y
On ExitAwall bit
Ywall bit
Zset if no wall
Xcorrupted (the column within the room)
MAP_PTRthe cell's room in room_walls
; Point map_ptr at the cell's room in room_walls.
78FC .test_wall←8← 20D3 JSR← 20E1 JSR← 20EF JSR← 6FB2 JSR← 712B JSR← 753A JSR← 7675 JSR← 7A51 JSR
LDA cell_y ; Room offset = (cell_y AND &F8) x 4 + (cell_x AND &F8)...
78FF AND #&f8 ; ...y AND &F8 = 8 x the cell's row of rooms...
7901 STA scratch ; ...kept in scratch, to add up four times...
7904 CLC ; ...(y < 64 on the map: no carry, so clear it once)
7905 ADC scratch ; ...doubled: 16 bytes per row of rooms so far...
7908 ADC scratch ; ...tripled: 24...
790B ADC scratch ; ...x 4: 32 bytes, four rooms, per row of rooms
790E STA map_ptr ; ...the start of its row of rooms, in map_ptr
7910 LDA cell_x ; Add the room's column in that row...
7913 AND #&f8 ; ...x AND &F8 = 8 x the column: 8 bytes per room
7915 ADC map_ptr ; ...to the row's offset...
7917 STA map_ptr ; ...map_ptr low = the room's offset (0-&B8)...
7919 LDA #>(room_walls) ; ...in page &0C, room_walls...
791B STA map_ptr_hi ; ...as map_ptr's high byte: map_ptr = the room's bytes
; Pick out the cell's bit: bit_masks for the column, the room's ; byte for the row.
791D LDA cell_x ; Mask for the cell's column within the room...
7920 AND #7 ; ...x AND 7, 0 at the left...
7922 TAX ; ...in X, to look up its bit...
7923 LDA bit_masks,x ; ...&80 for column 0 down to &01 for column 7
7926 STA scratch ; ...kept in scratch to test the row byte with
7929 LDA cell_y ; The row byte: y AND 7...
792C AND #7 ; ...the cell's row within the room, 0-7...
792E TAY ; ...in Y, indexing the room's eight bytes
792F LDA (map_ptr),y ; The row's walls, one bit per cell...
7931 AND scratch ; ...masked to this cell: non-zero if solid
7934 STA victory_pitch ; ...copied to &8F, which is never read for it...
7936 TAY ; ...and to Y: callers pull X, then test Y
7937 RTS ; Return with Z set if the cell is open

Test whether a map cell can hold an object

Say whether an object might lie in a map cell, so that the object list need be searched only there. move_heroes calls it for a hero who has moved, before collect_objects, and move_missiles for a missile's new cell, before looking for an energy drainer.

The same calculation as test_wall, on object_free_map at &2100 instead of room_walls: eight bytes per room, a bit per cell, bit 7 at the left. A clear bit means an object may lie there; the map comes from the level file and is not changed when an object is collected, so a cleared cell goes on costing a search that finds nothing. The bit is returned in A and Y, with Z set if an object may lie there, and also stored in &8F (victory_pitch), where nothing reads it. map_ptr is left pointing into object_free_map.

On EntryCELL_Xmap x
CELL_Ymap y
On ExitAmap bit
Ymap bit
Zset if an object may lie there
Xcorrupted (the column within the room)
; Point map_ptr at the cell's room in object_free_map.
7938 .test_object_free←2← 70B5 JSR← 7166 JSR
LDA cell_y ; Room offset = (cell_y AND &F8) x 4 + (cell_x AND &F8)...
793B AND #&f8 ; ...y AND &F8 = 8 x the cell's row of rooms...
793D STA scratch ; ...kept in scratch, to add up four times...
7940 CLC ; ...(y < 64 on the map: no carry, so clear it once)
7941 ADC scratch ; ...doubled: 16 bytes per row of rooms so far...
7944 ADC scratch ; ...tripled: 24...
7947 ADC scratch ; ...x 4: 32 bytes, laid out as room_walls
794A STA map_ptr ; ...the start of its row of rooms, in map_ptr
794C LDA cell_x ; Add the room's column in that row...
794F AND #&f8 ; ...x AND &F8 = 8 x the column: 8 bytes per room
7951 ADC map_ptr ; ...to the row's offset...
7953 STA map_ptr ; ...map_ptr low = the room's offset (0-&B8)...
7955 LDA #>(object_free_map) ; ...in page &21, object_free_map...
7957 STA map_ptr_hi ; ...as map_ptr's high byte: map_ptr = the room's bytes
; Pick out the cell's bit, as test_wall does.
7959 LDA cell_x ; Mask for the cell's column within the room...
795C AND #7 ; ...x AND 7, 0 at the left...
795E TAX ; ...in X, to look up its bit...
795F LDA bit_masks,x ; ...&80 for column 0 down to &01 for column 7
7962 STA scratch ; ...kept in scratch to test the row byte with
7965 LDA cell_y ; The row byte: y AND 7...
7968 AND #7 ; ...the cell's row within the room, 0-7...
796A TAY ; ...in Y, indexing the room's eight bytes
796B LDA (map_ptr),y ; The row's bits, one per cell...
796D AND scratch ; ...masked to this cell: zero if an object may lie
7970 STA victory_pitch ; ...copied to &8F, which is never read for it...
7972 TAY ; ...and to Y: callers pull X, then test Y
7973 RTS ; Return with Z set if an object may lie here

Look for a monster or hero at a cell

Say whether a creature stands in a map cell, and if a monster has walked into a hero, hurt the hero. Called by move_heroes and move_missiles for the cell a hero or missile is entering, and by update_monsters for the cell a monster steps into and for the trapdoor a dead monster comes back at (monster_reappears).

Monsters 30 to 1 are compared first, skipping monster number scratch; the first whose cell matches is returned. If none matches and scratch is non-zero (a monster is asking), heroes 0 to 3 are compared too, and the first one found loses hero_damage_taken points of health, one at a time through lose_health_point. A hero or missile passes scratch = 0, so only monsters are looked for (they test heroes their own way); a monster passes its own number, so it skips itself and is blocked by, and hurts, a hero in its way, every frame it tries.

Neither search looks at state: a dying monster still fills its cell, and a hero out of play (a skull) blocks a monster too, though lose_health_point takes nothing from them. A found monster is reported with A = Y = cell_y, so one in map row 0 would read as nothing found. monster_reappears calls this without loading the trapdoor's cell, so it tests the view position plot_at_cell left in cell_x, cell_y; a hero who happens to stand at that cell is hurt.

On EntrySCRATCHthe monster moving (1-30), or 0
CELL_Xmap x
CELL_Ymap y
On ExitAcell_y if a monster was found, 1 if a hero, else 0
Ycell_y if a monster was found, else 0
Zclear if a creature was found (cell_y non-zero)
Xthe monster or hero found; else 0, or 4 after the hero search
; Monsters first: any but the asker, alive or dying, in the ; cell?
7974 .find_creature←4← 6FDC JSR← 713F JSR← 7A8C JSR← 7CE6 JSR
LDX #max_monster ; Monsters 30 to 1, alive or dying...
7976 .check_monster←1← 798E BNE
CPX scratch ; ...except monster number scratch, the one asking
7979 BEQ next_monster_find ; The asker itself: skip it
797B LDA cell_x ; Is this monster in the cell? cell_x...
797E CMP monster_x,x ; ...against the monster's x
7981 BNE next_monster_find ; Another column: not this monster
7983 LDA cell_y ; ...and cell_y...
7986 CMP monster_y,x ; ...against the monster's y
7989 BNE next_monster_find ; Another row: not this monster
798B TAY ; Found: A = Y = cell_y, X = the monster
798C RTS ; Return, Z clear unless the cell is in row 0
798D .next_monster_find←3← 7979 BEQ← 7981 BNE← 7989 BNE
DEX ; Next monster down
798E BNE check_monster ; Until monster 1 is done
; Then, only for a monster asking, heroes: the first in the ; cell, in play or not, is hurt and blocks the move.
7990 LDA scratch ; No monster there. Is a monster asking (scratch > 0)?
7993 BEQ nothing_found ; No (a hero or missile): heroes are not looked for
7995 LDX #0 ; Yes: a hero blocks it too. Heroes 0 to 3...
7997 .check_hero←1← 79BA BNE
LDA cell_x ; ...is this hero in the cell? cell_x...
799A CMP hero_x,x ; ...against the hero's x
799D BNE next_hero_find ; Another column: not this hero
799F LDA cell_y ; ...and cell_y...
79A2 CMP hero_y,x ; ...against the hero's y
79A5 BNE next_hero_find ; Another row: not this hero
79A7 LDY hero_damage_taken,x ; Found, in play or not: health a blow costs them
79AA .take_hero_damage←1← 79B2 BNE
TYA ; Take it a point at a time: keep the points left...
79AB PHA ; ...on the stack across lose_health_point
79AC JSR lose_health_point ; One point off the hero (none if out of play)
79AF PLA ; Recover the points still to take...
79B0 TAY ; ...back in Y
79B1 DEY ; One point fewer to take
79B2 BNE take_hero_damage ; Until the hero has taken them all
79B4 LDA #1 ; Return A = 1, Z clear (Y = 0): a hero was there
79B6 RTS ; ...so the monster is blocked (or parked)
79B7 .next_hero_find←2← 799D BNE← 79A5 BNE
INX ; Next hero up
79B8 CPX #4 ; All four heroes checked?
79BA BNE check_hero ; No: check the next
79BC .nothing_found←1← 7993 BEQ
LDA #0 ; Nothing there: return A = Y = 0...
79BE LDY #0 ; ...the cell is free of creatures
79C0 RTS ; Return with Z set: nothing in the cell

Draw the trapdoors and move the monsters

Move every monster on by one frame of its life, and redraw the trapdoors they come out of. update_game calls it once a frame, after draw_objects and move_missiles, so a monster killed by a missile or magic this frame starts its death here.

The eight trapdoors are drawn first, because erasing a creature or missile that crossed one has blanked its cell. They are drawn over whatever stands on them, so a hero or missile on a trapdoor is overdrawn by it every frame. Then each monster, 30 down to 1, is erased where it was drawn last frame and moved on according to its state.

Moving: a monster mid-step slides a quarter cell further (continue_monster_step). One that is not stepping tries the next cell the way it faces. If that cell is open and holds no creature, it starts a step: monster_x and monster_y keep the old cell while the offsets carry the sprite across, so an interior cell takes four frames (a quarter, a half, three quarters, then square in the new cell). A cell in a room's edge row or column, in the direction of travel, is entered at once, so no sprite is drawn between two rooms and a monster crosses from one room into the next in two frames.

Blocked: a wall, a closed door or a creature in the cell keeps the monster where it is. It turns a random way, each of the four equally likely, from the System VIA's timer 1, and tries that way next frame. A monster does not chase anyone: it walks straight on until blocked. find_creature takes hero_damage_taken points from a hero it finds in the cell, so a monster hurts a hero each time it tries to step into them.

Dying: a monster killed by a missile or by magic is given sprite &15 (the blank) there. Each frame here advances it through the sparkles &16-&19, drawn where it died.

Reappearing: after the last sparkle monster_reappears puts it on the next trapdoor in turn, facing up, to be drawn next frame.

reset_monsters starts every monster at the blank with x &FF, so at the start of a level all 30 sparkle off the map together and emerge on the same frame, shared out round the eight trapdoors in turn. Only the target cell is ever tested for a creature: during a slide the monster is still recorded in the cell it is leaving, and the arrival is not checked again, so two monsters, or a monster and a hero, can end a step in the same cell. The creature test made as a monster reappears looks at the wrong cell (see monster_reappears).

On ExitAcorrupted
Xcorrupted
Ycorrupted
79C1 .update_monsters←1← 1ED4 JSR
LDX #8 ; Redraw trapdoors 8 to 1 (sprite &2C)...
79C3 LDA #0 ; Trapdoors sit squarely in their cells:
79C5 STA plot_offset_x ; ...no horizontal offset...
79C7 STA plot_offset_y ; ...and no vertical offset
79C9 LDA #spr_trapdoor ; The trapdoor sprite...
79CB STA sprite_number ; ...the same for all eight
79CD .draw_trapdoor←1← 79E1 BNE
LDA trapdoor_x - 1,x ; This trapdoor's map x...
79D0 STA cell_x ; ...as the cell to plot
79D3 LDA trapdoor_y - 1,x ; ...and its map y
79D6 STA cell_y ; ...as cell_y
79D9 TXA ; Keep the trapdoor number...
79DA PHA ; ...on the stack: plot_at_cell changes X
79DB JSR plot_at_cell ; Draw it in every view showing its cell
79DE PLA ; Recover the trapdoor number...
79DF TAX ; ...back in X
79E0 DEX ; Next trapdoor down
79E1 BNE draw_trapdoor ; Until trapdoor 1 is drawn
79E3 LDX #max_monster ; Then each monster, 30 to 1...
; Each monster in turn, 30 down to 1. It is first rubbed out ; where it was drawn last frame, its cell and offsets plotted ; with the blank sprite, and its cell is kept in previous_x and ; previous_y. Then its state decides what happens: a dying ; monster (sprite &15 and up) shows its next sparkle, one part ; way through a step slides on, and any other tries a new step. ; The monster number stays on the stack until monster_done.
79E5 .next_monster_update←1← 7B2D JMP
TXA ; Keep the monster number...
79E6 PHA ; ...on the stack while it moves
79E7 LDA monster_x,x ; Erase it at its cell and offsets, remembering the cell
79EA STA cell_x ; ...as the cell to erase...
79ED STA previous_x ; ...and as where it came from
79F0 LDA monster_y,x ; ...and its map y...
79F3 STA cell_y ; ...as the cell to erase...
79F6 STA previous_y ; ...and as where it came from
79F9 LDA #spr_blank ; The blank sprite...
79FB STA sprite_number ; ...to rub it out
79FD LDA monster_offset_x,x ; Its horizontal offset...
7A00 STA plot_offset_x ; ...for the erase
7A02 LDA monster_offset_y,x ; ...and its vertical offset...
7A05 STA plot_offset_y ; ...so the blank covers it where it was drawn
7A07 JSR plot_at_cell ; Rub the monster out in every view showing it
7A0A PLA ; The monster number back from the stack...
7A0B PHA ; ...left there for monster_done
7A0C TAX ; ...in X again
7A0D LDA monster_sprite,x ; Is the monster dying?
7A10 CMP #spr_blank ; Sprite &15 (the blank) and up: killed
7A12 BCC check_monster_step ; Below &15: alive, so it moves
7A14 JMP advance_dying_monster ; Killed: show its next sparkle
7A17 .check_monster_step←1← 7A12 BCC
LDA monster_step,x ; Part way through a step?
7A1A BEQ start_monster_move ; No: try a step to the next cell
7A1C JSR continue_monster_step ; Yes: slide it a quarter cell further
7A1F PLA ; Drop the stacked number (X still has it)...
7A20 JMP draw_monster ; ...as draw_monster pushes it again
; A monster that is not stepping tries the next cell the way it ; faces. Its cell is moved there provisionally and the step's ; first offsets are set, then the cell is tested: first for a ; wall or closed door, then for a creature.
7A23 .start_monster_move←1← 7A1A BEQ
LDA monster_sprite,x ; Step into the next cell in the way it faces: up...
7A26 CMP #spr_monster_up_0 ; Sprite 9, facing up?
7A28 BNE monster_right ; No: try right
7A2A DEC monster_y,x ; Yes: one row up
7A2D .monster_right←1← 7A28 BNE
CMP #spr_monster_right_0 ; Sprite &0B, facing right?
7A2F BNE monster_down ; No: try down
7A31 INC monster_x,x ; Yes: one column right
7A34 .monster_down←1← 7A2F BNE
CMP #spr_monster_down_0 ; Sprite &0D, facing down?
7A36 BNE monster_left ; No: try left
7A38 INC monster_y,x ; Yes: one row down
7A3B .monster_left←1← 7A36 BNE
CMP #spr_monster_left_0 ; Sprite &0F, facing left?
7A3D BNE set_monster_step ; No: it does not move
7A3F DEC monster_x,x ; Yes: one column left
7A42 .set_monster_step←1← 7A3D BNE
JSR start_monster_step ; First quarter-cell offsets of the step
7A45 LDA monster_x,x ; Is the new cell a wall (or a closed door)?
7A48 STA cell_x ; ...the new x as cell_x
7A4B LDA monster_y,x ; The new y...
7A4E STA cell_y ; ...as cell_y: the cell to test
7A51 JSR test_wall ; Z set if the cell is open
7A54 BEQ check_monster_blocked ; Open: is a creature in the way?
; Blocked by a wall: the monster goes back to the cell it was ; in, with no step under way, and faces a random way. A random ; 0-7 + 8 gives a sprite &08-&0F; an even one is rounded up to ; the facing above it, so up, right, down and left are each ; chosen 2 times in 8. It tries that way on the next frame.
7A56 PLA ; Wall: the monster stays where it is...
7A57 TAX ; ...its number back in X, which test_wall changed
7A58 LDA previous_x ; The cell it was in...
7A5B STA monster_x,x ; ...back in monster_x
7A5E LDA previous_y ; ...and its row...
7A61 STA monster_y,x ; ...back in monster_y
7A64 LDA #0 ; No step under way:
7A66 STA monster_step,x ; ...step count 0
7A69 STA monster_offset_x,x ; ...no horizontal offset
7A6C STA monster_offset_y,x ; ...no vertical offset
7A6F LDA system_via_t1c_l ; Turn a random way, from the System VIA's timer
7A72 AND #7 ; A random 0-7...
7A74 CLC ; ...+ 8, the first monster sprite...
7A75 ADC #8 ; ...a sprite &08-&0F
7A77 STA monster_sprite,x ; Face the monster that way
7A7A AND #1 ; Odd sprites (9, &0B, &0D, &0F) are the facings
7A7C BEQ turn_monster ; Even: round it up to the next facing
7A7E JMP draw_monster ; Odd: draw it; it tries the new way next frame
7A81 .turn_monster←1← 7A7C BEQ
INC monster_sprite,x ; Round up: each way is equally likely, 2 in 8
7A84 JMP draw_monster ; Draw it; it tries the new way next frame
; The cell is open: is a monster or hero standing in it? ; find_creature skips this monster and, because scratch is ; non-zero, takes hero_damage_taken points from a hero it finds ; there. A monster mid-slide is still recorded in the cell it is ; leaving, so it does not block the cell it is entering.
7A87 .check_monster_blocked←1← 7A54 BEQ
PLA ; Monster or hero in the new cell? (a hero there is hurt)
7A88 PHA ; ...left stacked for later
7A89 STA scratch ; Non-zero scratch: skip this monster, check heroes
7A8C JSR find_creature ; A = 0 if no creature is at cell_x, cell_y
7A8F CMP #0 ; Non-zero: a monster or hero is in the cell
7A91 BEQ monster_vertical ; No: the cell is free, so the step goes ahead
; Blocked by a creature: as for a wall, the monster stays where ; it was, with no step, and turns a random way.
7A93 PLA ; Yes: stay put, with no step, and turn a random way
7A94 TAX ; ...its number back in X, which find_creature changed
7A95 LDA previous_x ; The cell it was in...
7A98 STA monster_x,x ; ...back in monster_x
7A9B LDA previous_y ; ...and its row...
7A9E STA monster_y,x ; ...back in monster_y
7AA1 LDA #0 ; No step under way:
7AA3 STA monster_step,x ; ...step count 0
7AA6 STA monster_offset_x,x ; ...no horizontal offset
7AA9 STA monster_offset_y,x ; ...no vertical offset
7AAC LDA system_via_t1c_l ; Turn a random way, from the System VIA's timer
7AAF AND #7 ; A random 0-7...
7AB1 CLC ; ...+ 8, the first monster sprite...
7AB2 ADC #8 ; ...a sprite &08-&0F
7AB4 STA monster_sprite,x ; Face the monster that way
7AB7 AND #1 ; Odd sprites (9, &0B, &0D, &0F) are the facings
7AB9 BNE draw_monster ; Odd: draw it; it tries the new way next frame
7ABB INC monster_sprite,x ; Even: round it up to the next facing
7ABE JMP draw_monster ; Draw it; it tries the new way next frame
; The step goes ahead. A step into a cell on a room's edge row ; (moving up or down) or edge column (moving across) is made at ; once, with no slide, so the sprite is never drawn part way ; between two rooms. Any other step keeps the old cell in ; monster_x and monster_y and lets the offsets carry the sprite ; across over four frames.
7AC1 .monster_vertical←1← 7A91 BEQ
PLA ; The step goes ahead...
7AC2 TAX ; ...its number back in X, which find_creature changed
7AC3 LDA monster_sprite,x ; Which way is it going?
7AC6 CMP #spr_monster_up_0 ; Moving up, so the new row decides?
7AC8 BEQ check_room_edge ; Yes: check the new row
7ACA CMP #spr_monster_down_0 ; Moving down, likewise?
7ACC BEQ check_room_edge ; Yes: check the new row
7ACE LDA monster_x,x ; Across: is the new cell in a room's edge column?
7AD1 AND #7 ; Column within its eight-cell room
7AD3 BEQ monster_at_edge ; Column 0: the left edge
7AD5 CMP #7 ; Column 7, the right edge?
7AD7 BEQ monster_at_edge ; Yes: an edge
7AD9 JMP monster_move_on ; No: slide there over the coming frames
7ADC .check_room_edge←2← 7AC8 BEQ← 7ACC BEQ
LDA monster_y,x ; Up or down: is the new cell in a room's edge row?
7ADF AND #7 ; Row within its eight-cell room
7AE1 BEQ monster_at_edge ; Row 0: the top edge
7AE3 CMP #7 ; Row 7, the bottom edge?
7AE5 BEQ monster_at_edge ; Yes: an edge
7AE7 JMP monster_move_on ; No: slide there over the coming frames
7AEA .monster_at_edge←4← 7AD3 BEQ← 7AD7 BEQ← 7AE1 BEQ← 7AE5 BEQ
LDA #0 ; Edge: jump straight in, so no slide crosses rooms
7AEC STA monster_step,x ; ...step count 0
7AEF STA monster_offset_x,x ; ...no horizontal offset
7AF2 STA monster_offset_y,x ; ...no vertical offset
7AF5 JMP draw_monster ; Draw it squarely in the new cell
7AF8 .monster_move_on←2← 7AD9 JMP← 7AE7 JMP
LDA previous_x ; Slide: keep the old cell until the step ends...
7AFB STA monster_x,x ; ...back in monster_x
7AFE LDA previous_y ; ...and its row...
7B01 STA monster_y,x ; ...back in monster_y: drawn offset from there
; Draw the monster at its recorded cell, displaced by its ; offsets, as its facing sprite plus its walking frame, in every ; view that shows the room. The dying and reappearing paths join ; at monster_done, which pulls the monster number and moves on ; to the next.
7B04 .draw_monster←6← 7A20 JMP← 7A7E JMP← 7A84 JMP← 7AB9 BNE← 7ABE JMP← 7AF5 JMP
LDA monster_x,x ; Draw it: its cell, facing + frame, offsets
7B07 STA cell_x ; ...as cell_x for plot_at_cell
7B0A LDA monster_y,x ; Its map y...
7B0D STA cell_y ; ...as cell_y for plot_at_cell
7B10 CLC ; Ready to add the frame
7B11 LDA monster_sprite,x ; Its facing sprite...
7B14 ADC monster_frame,x ; ...plus walking frame 0 or 1...
7B17 STA sprite_number ; ...is the sprite to plot
7B19 LDA monster_offset_x,x ; How far it has slid across...
7B1C STA plot_offset_x ; ...as the horizontal offset
7B1E LDA monster_offset_y,x ; How far it has slid down...
7B21 STA plot_offset_y ; ...as the vertical offset
7B23 TXA ; Keep the monster number...
7B24 PHA ; ...across the plot, which changes X
7B25 JSR plot_at_cell ; Draw it in every view whose room shows it
7B28 .monster_done←3← 7B5F JMP← 7CF8 JMP← 7CFB JMP
PLA ; The monster number back from the stack...
7B29 TAX ; ...in X, to count on down
7B2A DEX ; Next monster down
7B2B BEQ update_monsters_done ; Past monster 1: all 30 updated
7B2D JMP next_monster_update ; Otherwise update the next one
7B30 .update_monsters_done←1← 7B2B BEQ
RTS ; Return: every monster moved and drawn
; A killed monster is set to sprite &15 (the blank). Each frame ; the sprite advances, showing the sparkles &16-&19 at the cell ; and offsets it died at; after the last the monster reappears. ; Its step counter is left as it was, since a dying monster is ; dispatched before the step is looked at.
7B31 .advance_dying_monster←1← 7A14 JMP
PLA ; Drop the stacked number (X still has it)
7B32 INC monster_sprite,x ; Next death frame: &16-&19 are the sparkles
7B35 LDA monster_sprite,x ; Which frame now?
7B38 CMP #spr_sparkle_3 + 1 ; Past the last sparkle (&19)?
7B3A BNE draw_monster_death ; No: draw this sparkle
7B3C JMP monster_reappears ; Yes: bring it back at a trapdoor
7B3F .draw_monster_death←1← 7B3A BNE
TXA ; Draw the sparkle where the monster died...
7B40 PHA ; ...keeping the monster number across the plot
7B41 LDA monster_x,x ; Its map x, where it died...
7B44 STA cell_x ; ...as cell_x for plot_at_cell
7B47 LDA monster_y,x ; ...and its map y...
7B4A STA cell_y ; ...as cell_y for plot_at_cell
7B4D LDA monster_sprite,x ; The sparkle sprite, with no walking frame...
7B50 STA sprite_number ; ...is the sprite to plot
7B52 LDA monster_offset_x,x ; Offsets frozen at the moment it died...
7B55 STA plot_offset_x ; ...across, as plot_offset_x
7B57 LDA monster_offset_y,x ; ...and how far down it had slid...
7B5A STA plot_offset_y ; ...so it sparkles exactly where it died
7B5C JSR plot_at_cell ; Draw the sparkle in every view showing it
7B5F JMP monster_done ; Pull the monster number and on to the next

Start a hero's step between cells

Called by move_heroes when a direction key starts a move within a room and the hero has no Boots of Speed. Set hero X's step counter to 1 and their pixel offsets to half a cell in the direction they face (hero_direction 1, 3, 5 or 7: up, right, down, left): 6 rows up or down, or 2 byte columns left or right. move_heroes then draws the hero there, half way to the next cell, for one frame, still recorded in the old cell; continue_hero_step completes the move on the next frame.

On EntryXhero number (0-3)
On ExitAcorrupted
Xpreserved
7B62 .start_hero_step←4← 6ECE JSR← 6EE1 JSR← 6EF4 JSR← 6F07 JSR
LDA #1 ; One frame to go before the hero is in the new cell
7B64 STA hero_step,x ; ...as hero_step: continue_hero_step ends it
7B67 LDA hero_direction,x ; Draw the hero half a cell along the way they face
7B6A CMP #1 ; Direction 1, facing up?
7B6C BNE hero_step_right ; No: try right
7B6E LDA #0 ; Up: not across...
7B70 STA hero_offset_x,x ; ...no horizontal offset
7B73 LDA #&fa ; -6: half a 12-row cell up...
7B75 STA hero_offset_y,x ; ...as the vertical offset
7B78 RTS ; Return: drawn half a cell up
7B79 .hero_step_right←1← 7B6C BNE
CMP #3 ; Direction 3, facing right?
7B7B BNE hero_step_down ; No: try down
7B7D LDA #0 ; Right: not up or down...
7B7F STA hero_offset_y,x ; ...no vertical offset
7B82 LDA #2 ; +2: half a 4-byte cell right...
7B84 STA hero_offset_x,x ; ...as the horizontal offset
7B87 RTS ; Return: drawn half a cell right
7B88 .hero_step_down←1← 7B7B BNE
CMP #5 ; Direction 5, facing down?
7B8A BNE hero_step_left ; No: they face left
7B8C LDA #0 ; Down: not across...
7B8E STA hero_offset_x,x ; ...no horizontal offset
7B91 LDA #6 ; +6: half a cell down...
7B93 STA hero_offset_y,x ; ...as the vertical offset
7B96 RTS ; Return: drawn half a cell down
7B97 .hero_step_left←1← 7B8A BNE
LDA #0 ; Left: not up or down...
7B99 STA hero_offset_y,x ; ...no vertical offset
7B9C LDA #&fe ; -2: half a cell left...
7B9E STA hero_offset_x,x ; ...as the horizontal offset
7BA1 RTS ; Return: drawn half a cell left

Continue a hero's step between cells

Called by move_heroes, in place of reading the hero's keys, on the frame after a step starts. Toggle hero X's walking frame and count down their step. When it ends, move the hero one cell in the direction they face and clear the pixel offsets, so a step takes two frames. The offsets are then doubled. Since start_hero_step sets the counter to 1 and nothing else gives an in-play hero a non-zero step, the step always ends here, so the doubling only ever doubles zero offsets.

On EntryXhero number (0-3)
On ExitAcorrupted
Xpreserved
7BA2 .continue_hero_step←1← 6EB4 JSR
LDA hero_frame,x ; Swap the hero's walking frame...
7BA5 EOR #1 ; ...0 to 1 or 1 to 0...
7BA7 STA hero_frame,x ; ...so their legs move
7BAA DEC hero_step,x ; One frame fewer to the new cell
7BAD BNE double_offsets ; Not there yet (never taken: the step is 1)
7BAF LDA hero_direction,x ; Arrived: move their cell on the way they face: up...
7BB2 CMP #1 ; Direction 1, facing up?
7BB4 BNE continue_right ; No: try right
7BB6 DEC hero_y,x ; Yes: one row up
7BB9 .continue_right←1← 7BB4 BNE
CMP #3 ; Direction 3, facing right?
7BBB BNE continue_down ; No: try down
7BBD INC hero_x,x ; Yes: one column right
7BC0 .continue_down←1← 7BBB BNE
CMP #5 ; Direction 5, facing down?
7BC2 BNE continue_left ; No: try left
7BC4 INC hero_y,x ; Yes: one row down
7BC7 .continue_left←1← 7BC2 BNE
CMP #7 ; Direction 7, facing left?
7BC9 BNE hero_no_offsets ; No: no move
7BCB DEC hero_x,x ; Yes: one column left
7BCE .hero_no_offsets←1← 7BC9 BNE
LDA #0 ; Drawn squarely in the new cell:
7BD0 STA hero_offset_x,x ; ...no horizontal offset
7BD3 STA hero_offset_y,x ; ...no vertical offset
7BD6 .double_offsets←1← 7BAD BNE
CLC ; Double the offsets, which are always zero by now
7BD7 LDA hero_offset_x,x ; Horizontal offset x 2: the offset...
7BDA ADC hero_offset_x,x ; ...added to itself...
7BDD STA hero_offset_x,x ; ...stored back, still 0
7BE0 CLC ; Ready for the vertical offset
7BE1 LDA hero_offset_y,x ; Vertical offset x 2: the offset...
7BE4 ADC hero_offset_y,x ; ...added to itself...
7BE7 STA hero_offset_y,x ; ...stored back, still 0
7BEA RTS ; Return: the hero is squarely in the new cell

Start a monster's step between cells

Called by update_monsters when a monster that is not stepping tries the next cell, before that cell is tested. Set monster X's step counter to 3 and its offsets to the first quarter of a cell in the direction it faces: 3 rows up or down, or one byte column left or right. If the cell turns out to be blocked, or on a room's edge, update_monsters clears all three again; otherwise the monster is drawn this frame a quarter of the way there, and continue_monster_step takes over on the next.

On EntryXmonster number (1-30)
On ExitAcorrupted
Xpreserved
7BEB .start_monster_step←1← 7A42 JSR
LDA #3 ; Three more frames to reach the new cell...
7BED STA monster_step,x ; ...as the step count
7BF0 LDA monster_sprite,x ; Draw it a quarter cell along the way it faces: up...
7BF3 CMP #spr_monster_up_0 ; Sprite 9, facing up?
7BF5 BNE monster_step_right ; No: try right
7BF7 LDA #0 ; Up: not across...
7BF9 STA monster_offset_x,x ; ...no horizontal offset
7BFC LDA #&fd ; -3: a quarter of a 12-row cell up...
7BFE STA monster_offset_y,x ; ...as the vertical offset
7C01 RTS ; Return: drawn a quarter cell up
7C02 .monster_step_right←1← 7BF5 BNE
CMP #spr_monster_right_0 ; Sprite &0B, facing right?
7C04 BNE monster_step_down ; No: try down
7C06 LDA #0 ; Right: not up or down...
7C08 STA monster_offset_y,x ; ...no vertical offset
7C0B LDA #1 ; +1: a quarter of a 4-byte cell right...
7C0D STA monster_offset_x,x ; ...as the horizontal offset
7C10 RTS ; Return: drawn a quarter cell right
7C11 .monster_step_down←1← 7C04 BNE
CMP #spr_monster_down_0 ; Sprite &0D, facing down?
7C13 BNE monster_step_left ; No: it faces left
7C15 LDA #0 ; Down: not across...
7C17 STA monster_offset_x,x ; ...no horizontal offset
7C1A LDA #3 ; +3: a quarter of a cell down...
7C1C STA monster_offset_y,x ; ...as the vertical offset
7C1F RTS ; Return: drawn a quarter cell down
7C20 .monster_step_left←1← 7C13 BNE
LDA #0 ; Left: not up or down...
7C22 STA monster_offset_y,x ; ...no vertical offset
7C25 LDA #&ff ; -1: a quarter of a cell left...
7C27 STA monster_offset_x,x ; ...as the horizontal offset
7C2A RTS ; Return: drawn a quarter cell left

Continue a monster's step between cells

Called by update_monsters each frame while monster X's step is under way (monster_step non-zero). Toggle its walking frame, so its legs move, and count down its step. On the first two calls the offsets grow by another quarter of a cell (a byte column or three rows), to a half and then three quarters. On the third the step ends: monster_x or monster_y moves one cell on the way it faces and the offsets are cleared, so it is drawn squarely in the new cell. With the frame start_monster_step began, a monster crosses an interior cell in four frames. Nothing tests the new cell again on arrival.

On EntryXmonster number (1-30)
On ExitAcorrupted
Xpreserved
7C2B .continue_monster_step←1← 7A1C JSR
LDA monster_frame,x ; Swap the monster's walking frame...
7C2E EOR #1 ; ...0 to 1 or 1 to 0...
7C30 STA monster_frame,x ; ...so its legs move as it slides
7C33 DEC monster_step,x ; One frame fewer to the new cell
7C36 BNE grow_offset_x ; Not there yet: slide a quarter cell further
7C38 LDA monster_sprite,x ; Arrived: move its cell on the way it faces: up...
7C3B CMP #spr_monster_up_0 ; Sprite 9, facing up?
7C3D BNE monster_continue_right ; No: try right
7C3F DEC monster_y,x ; Yes: one row up
7C42 .monster_continue_right←1← 7C3D BNE
CMP #spr_monster_right_0 ; Sprite &0B, facing right?
7C44 BNE monster_continue_down ; No: try down
7C46 INC monster_x,x ; Yes: one column right
7C49 .monster_continue_down←1← 7C44 BNE
CMP #spr_monster_down_0 ; Sprite &0D, facing down?
7C4B BNE monster_continue_left ; No: try left
7C4D INC monster_y,x ; Yes: one row down
7C50 .monster_continue_left←1← 7C4B BNE
CMP #spr_monster_left_0 ; Sprite &0F, facing left?
7C52 BNE monster_no_offsets ; No: no move
7C54 DEC monster_x,x ; Yes: one column left
7C57 .monster_no_offsets←1← 7C52 BNE
LDA #0 ; Drawn squarely in the new cell:
7C59 STA monster_offset_x,x ; ...no horizontal offset
7C5C STA monster_offset_y,x ; ...no vertical offset (zeros don't grow)
7C5F .grow_offset_x←1← 7C36 BNE
LDA monster_offset_x,x ; Slide across a further quarter cell (a byte column)
7C62 BEQ grow_offset_y ; Zero: moving up or down, or arrived
7C64 BPL grow_offset_x_right ; Positive: moving right
7C66 DEC monster_offset_x,x ; Negative: one more column left
7C69 JMP grow_offset_y ; Now the vertical offset
7C6C .grow_offset_x_right←1← 7C64 BPL
INC monster_offset_x,x ; One more column right
7C6F .grow_offset_y←2← 7C62 BEQ← 7C69 JMP
LDA monster_offset_y,x ; Slide down or up a further quarter cell (3 rows)
7C72 BEQ monster_step_done ; Zero: moving across, or arrived
7C74 BPL grow_offset_y_down ; Positive: moving down
7C76 SEC ; Moving up: three more rows up...
7C77 LDA monster_offset_y,x ; ...from the vertical offset...
7C7A SBC #3 ; ...three rows further up...
7C7C STA monster_offset_y,x ; ...to -6 or -9
7C7F JMP monster_step_done ; Offsets grown: return
7C82 .grow_offset_y_down←1← 7C74 BPL
CLC ; Moving down: three more rows down...
7C83 LDA monster_offset_y,x ; ...from the vertical offset...
7C86 ADC #3 ; ...three rows further down...
7C88 STA monster_offset_y,x ; ...to 6 or 9
7C8B .monster_step_done←2← 7C72 BEQ← 7C7F JMP
RTS ; Return: offsets grown, or the step ended
7C8C EQUB &DE, &35, &0D, &BD, &35, &0D, &D0, &00, ; Not &60 ; referenced

Test whether a key is pressed

Report whether one key is held down at this moment. read_hero_keys calls it for each hero's direction and fire keys, from the hero_key tables, and check_magic for the Ranger's and Magic-User's magic keys. The key is scanned with OSBYTE &81 and a negative INKEY number (Y = &FF), which returns X = Y = &FF if it is held; the caller's X, the hero number, is kept on the stack across the call.

On EntryAINKEY key number (negative, as a byte)
On ExitA0 if the key is pressed, 1 if not
Zset if the key is pressed
Xpreserved
Ycorrupted
7C95 .test_key←6← 6EC4 JSR← 6ED7 JSR← 6EEA JSR← 6EFD JSR← 6F10 JSR← 7627 JSR
TAY ; Park the INKEY number in Y for a moment
7C96 TXA ; Keep the caller's X (the hero number)...
7C97 PHA ; ...on the stack, as OSBYTE returns in X
7C98 TYA ; The INKEY number...
7C99 TAX ; ...in X, as OSBYTE &81 wants it
7C9A LDA #osbyte_inkey ; OSBYTE &81 with Y = &FF: scan the key
7C9C LDY #&ff ; Y = &FF: scan the one key, not wait
7C9E JSR osbyte ; Scan it: X = Y = &FF if the key is held. Test whether the key with negative INKEY number X is pressed
7CA1 CPY #&ff ; Held only if both Y and X come back &FF
7CA3 BNE key_not_pressed ; Y not &FF: the key is up
7CA5 CPX #&ff ; X = &FF too?
7CA7 BNE key_not_pressed ; No: the key is up
7CA9 PLA ; Held: the caller's X back from the stack...
7CAA TAX ; ...the hero number again
7CAB LDA #0 ; A = 0, Z set: the key is held
7CAD RTS ; Return with Z set: the key is held
7CAE .key_not_pressed←2← 7CA3 BNE← 7CA7 BNE
PLA ; Up: the caller's X back from the stack...
7CAF TAX ; ...the hero number again
7CB0 LDA #1 ; A = 1, Z clear: the key is up
7CB2 RTS ; Return with Z clear: the key is up
; The monster comes back facing up on the next trapdoor in turn, ; with the hit points the kill gave it back. It is not drawn ; until next frame. The creature test that follows reads cell_x ; and cell_y, which still hold the dying monster's position ; within its view, as the erase's plot_at_cell left them, not ; the trapdoor's cell. So a creature already on the trapdoor ; does not stop the monster emerging; one that happens to stand ; at the unrelated cell the leftovers name parks the monster at ; &FF,&FF, still alive, where nothing returns it to a trapdoor ; (and a hero there is hurt).
7CB3 .monster_reappears←1← 7B3C JMP
INC next_trapdoor ; Each reappearance uses the next trapdoor in turn
7CB6 LDA next_trapdoor ; Which trapdoor now?
7CB9 CMP #8 ; Past the eighth (7)?
7CBB BNE emerge_at_trapdoor ; No: emerge there
7CBD LDA #0 ; Yes: wrap round to trapdoor 0...
7CBF STA next_trapdoor ; ...for this monster and the next
7CC2 .emerge_at_trapdoor←1← 7CBB BNE
LDY next_trapdoor ; Y = the trapdoor to emerge from
7CC5 LDA trapdoor_x,y ; Put the monster on it, facing up, with no step
7CC8 STA monster_x,x ; ...the trapdoor's x as the monster's
7CCB LDA trapdoor_y,y ; The trapdoor's y...
7CCE STA monster_y,x ; ...as the monster's
7CD1 LDA #spr_monster_up_0 ; Facing up (sprite 9)...
7CD3 STA monster_sprite,x ; ...ends the death: alive again, drawn next frame
7CD6 LDA #0 ; No step under way:
7CD8 STA monster_step,x ; ...step count 0
7CDB STA monster_offset_x,x ; ...no horizontal offset
7CDE STA monster_offset_y,x ; ...no vertical offset
7CE1 TXA ; Test for a creature at cell_x, cell_y...
7CE2 PHA ; ...stacking the number for monster_done
7CE3 STX scratch ; Non-zero scratch: skip this monster, check heroes
7CE6 JSR find_creature ; cell_x/y: plot_at_cell's leftovers, not the trapdoor
7CE9 CMP #0 ; A = 0 if nothing is at that cell
7CEB BEQ emerge_done ; Nothing there: the monster stays on the trapdoor
7CED PLA ; Something there: park it off the map, still alive
7CEE PHA ; ...keeping it stacked for monster_done
7CEF TAX ; ...its number in X, which find_creature changed
7CF0 LDA #off_map ; Off the map...
7CF2 STA monster_x,x ; ...as its x
7CF5 STA monster_y,x ; ...and its y: no trapdoor will take it back
7CF8 JMP monster_done ; Pull the monster number and on to the next
7CFB .emerge_done←1← 7CEB BEQ
JMP monster_done ; Pull the monster number and on to the next
7CFE EQUB &00 ; Not referenced
; Hit points a monster starts with on this level: 6 + 2 x the ; level number (8 on level 1).
7CFF .monster_start_hit_points←3← 0E1B STA← 158F LDA← 759B LDA
EQUB &08

Workspace template

The starting contents of page &0D, the heroes' and missiles' workspace, which reset_workspace copies there whole at the start of every level. Byte +n becomes &0D00 + n. It sets the heroes in the four cells of the start, facing four ways and not stepping; every missile slot empty; each hero's direction and fire keys (hero_key_up etc. at +&70, as negative INKEY numbers for test_key); health digits 9 and 9 + 1 (+&90, +&95), which read 99 once draw_status_panel has taken a point; every view on the start room (+&A0); the heroes' and missiles' sprite bases (+&B0, +&B5); the bit masks test_wall and test_object_free use (+&C0); and the panel rows (+&D0). The bytes between variables are copied with the rest.

; Initial contents of page &0D, copied there at the start of ; every level.
7D00 .workspace_template←1Used as index base by← 14A2 LDA
EQUB &00 ; scratch: working byte
7D01 EQUB &00 ; scratch2: working byte
7D02 EQUB &1F ; cell_x: set before use
7D03 EQUB &1F ; cell_y: set before use
7D04 EQUB &D2 ; cell_room: set before use
7D05 EQUB &D2 ; Copied to &0D05: no variable starts here
7D06 EQUB &CC ; previous_x: set before use
7D07 EQUB &B1 ; previous_y: set before use
7D08 EQUB &07 ; previous_offset_x: set before use
7D09 EQUB &07 ; previous_offset_y: set before use
7D0A EQUB &01, &01, &00, ; Copied to &0D0A: no variable starts &2C, &34, &3C ; here
7D10 EQUB &0B, &0B, ; hero_x: the heroes start at x 11, 11, 12, &0C, &0C ; 12...
7D14 EQUB &2F ; Copied to &0D14: no variable starts here
7D15 EQUB &0B, &0C, ; hero_y: ...and y 11, 12, 11, 12, the four &0B, &0C ; cells of the start
7D19 EQUB &26 ; Copied to &0D19: no variable starts here
7D1A EQUB &01, &03, ; hero_direction: facing up, right, down and &05, &07 ; left
7D1E EQUB &2D, &2F ; Copied to &0D1E: no variable starts here
7D20 EQUB &01, &01, &01, ; hero_frame: walking frame 1 for every &01 ; hero
7D24 EQUB &5D ; Copied to &0D24: no variable starts here
7D25 EQUB &00, &00, &00, &00 ; hero_step: not stepping
7D29 EQUB &16 ; Copied to &0D29: no variable starts here
7D2A EQUB &00, &00, &00, &00 ; hero_offset_x: no offset
7D2E EQUB &1D, &1F ; Copied to &0D2E: no variable starts here
7D30 EQUB &00, &00, &00, &00 ; hero_offset_y: no offset
7D34 EQUB &03, &05, &07, &05, &07, &36, &35, &37, &3C, &3E, &3D, &3F ; Copied to &0D34: no variable starts here
7D40 EQUB &01, &82, &81, &83, &88, &8A, &89, &8B, &84, &86, &85, &87 ; missile_x: unused while the slots are empty
7D4C EQUB &8C, &8E, &8D, &8F, &08, &48, &8A, &48, &98, &48, &AE, &FF ; missile_y: unused while the slots are empty
7D58 EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; missile_direction: every slot empty
7D64 EQUB &15, &85, &7A, &8A, &48, &20, &00, &09, &68, &AA, &BD, &08 ; missile_sprite_base: set when a missile is fired
7D70 EQUB &BF, &86, ; hero_key_up: heroes 0-3, read through &B9, &AC ; test_key
7D74 EQUB &AF, &C6, ; hero_key_down: likewise, one per hero &99, &9B
7D78 EQUB &9E, &96, &97, &DA ; hero_key_right: likewise
7D7C EQUB &FF, &A6, &98, &CA ; hero_key_left: likewise
7D80 EQUB &9F, &D6, &9D, &C9 ; hero_key_fire: likewise
7D84 EQUB &0D, &C9, &05, &D0, &09, &18, &BD, &04, &0D, &69, &03, &9D ; Copied to &0D84: no variable starts here
7D90 EQUB spr_digit_9, ; hero_health_tens: the 9 digit sprite... spr_digit_9, spr_digit_9, spr_digit_9
7D94 EQUB &D0 ; Copied to &0D94: no variable starts here
7D95 EQUB spr_digit_9 + 1, ; hero_health_units: ...9 + 1: health spr_digit_9 + 1, ; 99 once a point is taken spr_digit_9 + 1, spr_digit_9 + 1
7D99 EQUB &18, &BD, &08, &0D, ; Copied to &0D99: no variable &6D, &40, &0D ; starts here
7DA0 EQUB <(room_walls + &28), ; view_room: every view starts on >(room_walls + &28), ; the heroes' room, &0C28 <(room_walls + &28), >(room_walls + &28), <(room_walls + &28), >(room_walls + &28), <(room_walls + &28), >(room_walls + &28)
7DA8 EQUB &00, &00, &BD, &04, ; Copied to &0DA8: no variable &0D, &85, &71, &8A ; starts here
7DB0 EQUB spr_arrow_up - 1, ; hero_missile_sprites: arrows, spr_fireball_up - 1, ; fireballs, axes, swords spr_axe_up - 1, spr_sword_up - 1
7DB4 EQUB &68 ; Copied to &0DB4: no variable starts here
7DB5 EQUB spr_ranger_up_0 - 1, ; hero_sprites: Ranger, spr_magic_user_up_0 - 1, ; Magic-User, Barbarian, spr_barbarian_up_0 - 1, ; Fighter spr_fighter_up_0 - 1
7DB9 EQUB &00, &0D, ; Copied to &0DB9: no variable starts here &D9
7DBC EQUB &00, &00, &00, &00 ; hero_has_boots: none
7DC0 EQUB &80, &40, &20, &10, &08, &04, ; bit_masks: &80 down to &02, &01 ; &01
7DC8 EQUB &B9, &30, &0D, &9D, ; Copied to &0DC8: no variable &08, &0D, &4C, &D4 ; starts here
7DD0 EQUB &18, &46, ; hero_panel_y: the four sections of the &74, &A2 ; status panel
7DD4 EQUB &E8, &E0, &04, &D0, &0A, &A2, &00, &AD, ; Copied to &40, &0D, &49, &01, &8D, &40, &0D, &8E, ; &0DD4: no &FF, &0D, &68, &A8, &68, &AA, &68, &28, ; variable &60, &DE, &DD, &DF, &F0, &F2, &F1, &F3, ; starts here &F8, &FA, &F9, &FB, &F4, &F6, &F5, &F7, &FC
7DFD EQUB &1E ; teleport_last: object &1E, the last
7DFE EQUB &FD ; Copied to &0DFE: no variable starts here
7DFF EQUB &00 ; victory_sprite_copy: set before use
; Map x of each monster (entries 1-30; entry 0 unused, and ; entries 31-40 spare, of which open_door uses entry 35). During ; a step it stays the cell the monster is leaving until the step ; ends, so find_creature, the missiles and the magic all meet ; the monster there. &FF (off_map) after reset_monsters, and for ; a monster monster_reappears has parked. Written by ; update_monsters, continue_monster_step and monster_reappears.
7E00 .monster_x←17Used as index base by← 158C STA← 7667 LDA← 797E CMP← 79E7 LDA← 7A31 INC← 7A3F DEC← 7A45 LDA← 7A5B STA← 7A98 STA← 7ACE LDA← 7AFB STA← 7B04 LDA← 7B41 LDA← 7C46 INC← 7C54 DEC← 7CC8 STA← 7CF2 STA
EQUB &00, &04, &0B, &09, &1D, ; Not read: reset_monsters &08, &01, &06, &07, &0A, ; and the trapdoors set the &01, &0B, &1A, &06, &0B, ; monsters &16
7E10 EQUB &15, &0D, &1B, &14, &1A, &09, &1C, &0F, &1E, &02, &1A, &0B, &1C, &0E, &16, &00 ; ...entries 16-31, not read
7E20 EQUB &00, &00, &00, &1A, &00, &00, ; ...entries 32-40, not &00, &00, &00 ; read
; Map y of each monster, kept like monster_x (entries 1-30; ; entry 35 holds the cell open_door is erasing a door from).
7E29 .monster_y←16Used as index base by← 766D LDA← 7986 CMP← 79F0 LDA← 7A2A DEC← 7A38 INC← 7A4B LDA← 7A61 STA← 7A9E STA← 7ADC LDA← 7B01 STA← 7B0A LDA← 7B47 LDA← 7C3F DEC← 7C4D INC← 7CCE STA← 7CF5 STA
EQUB &00, &24, &17, &25, &20, ; Not read: reset_monsters &24, &22, &14, &27, &0D, ; and the trapdoors set the &20, &01, &26, &0A, &01, ; monsters &12
7E39 EQUB &05, &20, &29, &0D, &26, &27, &08, &06, &1A, &14, &03, &1D, &07, &0D, &17, &00 ; ...entries 16-31, not read
7E49 EQUB &00, &00, &00, &1B, &00, &00, ; ...entries 32-40, not &00, &00, &00 ; read
; Each monster's state as a sprite number: 9, &0B, &0D or &0F ; facing up, right, down or left; &15 (the blank) when just ; killed, then &16-&19, the sparkles of its death, one a frame. ; It reaches &1A only for the moment before monster_reappears ; resets it to 9.
7E52 .monster_sprite←19Used as index base by← 1587 STA← 7144 LDA← 7598 STA← 7683 LDA← 768C STA← 7A0D LDA← 7A23 LDA← 7A77 STA← 7A81 INC← 7AB4 STA← 7ABB INC← 7AC3 LDA← 7B11 LDA← 7B32 INC← 7B35 LDA← 7B4D LDA← 7BF0 LDA← 7C38 LDA← 7CD3 STA
EQUB &00, &09, &0D, &0B, &0B, &0B, &09, &0F, &0F, &0B, &0D, &0B, &0B, &0F, &0D, &0D, &09, &0F, &0B, &0F, &0B, &0B, &0F, &09, &0D, &0F, &0B, &09, &0D, &0B, &09, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
; Each monster's animation frame (0 or 1), added to its facing ; sprite; toggled on each frame of a step. Entries 1-30 are ; used. Nothing sets it at the start of a level, so each monster ; starts on whatever frame the table holds.
7E7B .monster_frame←3Used as index base by← 7B14 ADC← 7C2B LDA← 7C30 STA
EQUB &00, &00, &01, &00, &00, &01, &01, &00, &01, &01, &00, &01, &01, &01, &00, &01, &00, &01, &00, &01, &01, &00, &00, &01, &01, &00, &00, &00, &01, &01, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
; How far each monster is drawn across from its cell during a ; step, in byte columns: 0, or +/-1 to 3.
7EA4 .monster_offset_x←15Used as index base by← 79FD LDA← 7A69 STA← 7AA6 STA← 7AEF STA← 7B19 LDA← 7B52 LDA← 7BF9 STA← 7C0D STA← 7C17 STA← 7C27 STA← 7C59 STA← 7C5F LDA← 7C66 DEC← 7C6C INC← 7CDB STA
EQUB &00, &00, &00, &02, &02, &02, &00, &FD, &FE, &01, &00, &02, &03, &00, &00, &00, &00, &FE, &00, &00, &01, &00, &00, &00, &00, &00, &03, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
; How far each monster is drawn down from its cell during a ; step, in pixel rows: 0, or +/-3, 6 or 9.
7ECD .monster_offset_y←17Used as index base by← 7A02 LDA← 7A6C STA← 7AA9 STA← 7AF2 STA← 7B1E LDA← 7B57 LDA← 7BFE STA← 7C08 STA← 7C1C STA← 7C22 STA← 7C5C STA← 7C6F LDA← 7C77 LDA← 7C7C STA← 7C83 LDA← 7C88 STA← 7CDE STA
EQUB &00, &FD, &00, &00, &00, &00, &FA, &00, &00, &00, &03, &00, &00, &00, &06, &03, &FD, &00, &00, &00, &00, &00, &00, &00, &06, &00, &00, &F7, &00, &00, &F7, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
; Frames left in each monster's step between cells: 3 when the ; step starts, counted down by continue_monster_step, 0 when the ; monster is not stepping. Not looked at while a monster is ; dying; monster_reappears clears it.
7EF6 .monster_step←7Used as index base by← 7A17 LDA← 7A66 STA← 7AA3 STA← 7AEC STA← 7BED STA← 7C33 DEC← 7CD8 STA
EQUB &00, &03, &00, &02, &02, &02, &02, &01, &02, &03, &03, &02, &01, &00, &02, &03, &03, &02, &00, &00, &03, &00, &00, &00, &02, &00, &01, &01, &00, &00, &01, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00
; Map x of each object on the level (entries 1-30), from the ; level file; &FF once collected. Entry 30 is the exit.
7F20 .object_x←9Used as index base by← 1515 STA← 7173 LDA← 719A STA← 730D LDA← 7337 LDA← 73EA LDA← 7413 STA← 7469 STA← 74BB STA
EQUB &00, &FF, &FF, &FF, &FF, &FF, ; Not read: unpack_level &18, &04, &04, &05, &FF, &FF, ; copies each level's &FF, &FF, &FF, &FF ; objects here
7F30 EQUB &FF, &FF, &FF, &FF, &FF, &01, &07, &04, &04, &FF, &FF, &FF, &FF, &FF ; ...entries 16-29, not read
; Map x of the exit (object 30).
7F3E .exit_x←4← 1F3B CMP← 1F77 LDA← 1F85 STA← 2029 STA
EQUB &04 ; ...the exit's entry
; Map y of each object.
7F3F .object_y←9Used as index base by← 151B STA← 717B LDA← 719D STA← 7313 LDA← 7342 LDA← 73F3 LDA← 7416 STA← 746C STA← 74BE STA
EQUB &00, &FF, &FF, &FF, &FF, &FF, ; Not read: unpack_level &15, &18, &19, &19, &FF, &FF, ; copies each level's &FF, &FF, &FF, &FF ; objects here
7F4F EQUB &FF, &FF, &FF, &FF, &FF, &2A, &2A, &2B, &2E, &FF, &FF, &FF, &FF, &FF ; ...entries 16-29, not read
; Map y of the exit (object 30).
7F5D .exit_y←4← 1F43 CMP← 1F7D LDA← 1F88 STA← 202F STA
EQUB &2C ; ...the exit's entry
; Each object's type, which is also its sprite: &28 treasure, ; &29 food, &2A Cross of Resurrection, &2B teleporter, &51 exit, ; &53-&5E energy drainer (advancing with each hit), &5F Boots of ; Speed, &60 magic helmet, &61 potion of healing, &62 pile of ; weapons, &63 magic sword.
7F5E .object_type←7Used as index base by← 1521 STA← 7183 LDA← 718E INC← 7191 LDA← 7319 LDA← 735C LDA← 73C8 LDA
EQUB &00, &5F, &5F, &5F, &29, &63, ; Not read: unpack_level &5F, &53, &2B, &53, &28, &28, ; copies each level's &60, &60, &28, &2A ; objects here
7F6E EQUB &62, &28, &28, &29, &28, &2B, &2B, &2B, &2B, &29, &28, &28, &29, &28 ; ...entries 16-29, not read
7F7C EQUB &51 ; ...the exit's entry
7F7D EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; Not referenced

WRCHV handler: print letters and digits in the game font

Installed on WRCHV while the game runs. A letter (either case) or a digit is printed in the game's own font: its eight-byte glyph is copied over the definition of character 128 (user_char_128) and character 128 is printed instead. Every other character is printed unchanged. Both paths finish in the MOS 1.20 OSWRCH routine at mos_oswrch_default, jumped to directly rather than through the WRCHV value saved at start-up. Lower-case letters share the capitals' glyphs. The handler keeps the character in plot_x, the sprite plotter's zero-page column, and it looks at every byte alone, with no notion of a VDU sequence: a VDU parameter byte that falls in '0'-'9', 'A'-'Z' or 'a'-'z' is sent as &80 too, so VDU sequences with such parameters go out with the MOS's own WRCHV: draw_view_frames puts it back around its PLOT commands. VDU 23,0,6,25 in start_level passes unharmed (25 is a control code). The glyph goes to &0C00 because MOS 1.20 keeps character 128's definition there, so room_walls must stay at &0C00 too.

On EntryAcharacter to print
On ExitAcorrupted
Xpreserved
Ypreserved
PLOT_Xcorrupted
7F8F .wrch_handler
STA plot_x ; Keep the character in plot_x, borrowed as scratch
7F91 TXA ; Save the caller's X...
7F92 PHA ; ...on the stack
7F93 TYA ; ...and the caller's Y
7F94 PHA ; ...on the stack: OSWRCH must preserve both
7F95 LDA plot_x ; Classify the character by range
7F97 CMP #'0' ; Below '0': a control code, space or punctuation?
7F99 BCC pass_character ; Controls, space, punctuation: the MOS font
7F9B CMP #':' ; Below ':', so a digit '0'-'9'?
7F9D BCC digit_glyph ; A digit: use the game's digit glyph
7F9F CMP #'A' ; Below 'A', so ':' to '@'?
7FA1 BCC pass_character ; Punctuation: the MOS font
7FA3 CMP #'[' ; Below '[', so a capital 'A'-'Z'?
7FA5 BCC capital_letter ; A capital: use the game's letter glyph
7FA7 CMP #'a' ; Below 'a', so '[' to '`'?
7FA9 BCC pass_character ; Punctuation: the MOS font
7FAB CMP #'{' ; '{' or above, past the lower-case letters?
7FAD BCS pass_character ; '{' and above: the MOS font
7FAF SEC ; Lower case: letter number 0-25...
7FB0 SBC #'a' ; ...so it is drawn with the capital's glyph
7FB2 JMP glyph_offset ; Join the capitals' path
7FB5 .capital_letter←1← 7FA5 BCC
SEC ; Capital: letter number 0-25...
7FB6 SBC #'A' ; ...0 for 'A'
7FB8 .glyph_offset←1← 7FB2 JMP
ASL ; Glyph offset = letter x 8 in font_letters: x 2...
7FB9 ASL ; ...x 4 (8 bytes a glyph)...
7FBA ASL ; ...x 8: the glyph's offset (at most 200)
7FBB BNE copy_glyph ; Branch to the next instruction either way
7FBD .copy_glyph←1← 7FBB BNE
TAX ; X indexes the glyph in font_letters
7FBE CLC ; End offset = start + 8...
7FBF ADC #8 ; ...one glyph's eight rows...
7FC1 STA plot_x ; ...in plot_x, the character no longer needed
7FC3 LDY #0 ; Y indexes character 128's definition at &0C00
7FC5 .copy_letter_glyph←1← 7FCF BNE
LDA font_letters,x ; Copy a row of the letter's glyph...
7FC8 STA room_walls,y ; ...over character 128's definition
7FCB INY ; Next row of character 128
7FCC INX ; Next row of the glyph
7FCD CPX plot_x ; All eight rows copied?
7FCF BNE copy_letter_glyph ; No: copy the next row
7FD1 .restore_registers←1← 7FF4 BEQ
PLA ; Restore the caller's Y...
7FD2 TAY ; ...from the stack
7FD3 PLA ; ...and the caller's X
7FD4 TAX ; ...from the stack
7FD5 LDA #&80 ; Character 128, which now looks like the glyph...
7FD7 JMP mos_oswrch_default ; ...printed by the MOS 1.20 OSWRCH routine itself
7FDA .digit_glyph←1← 7F9D BCC
SEC ; Digit: digit number 0-9...
7FDB SBC #'0' ; ...0 for '0'
7FDD ASL ; Glyph offset = digit x 8 in font_digits: x 2...
7FDE ASL ; ...x 4 (8 bytes a glyph)...
7FDF ASL ; ...x 8: the glyph's offset
7FE0 TAX ; X indexes the glyph in font_digits
7FE1 CLC ; End offset = start + 8...
7FE2 ADC #8 ; ...one glyph's eight rows...
7FE4 STA plot_x ; ...in plot_x, the character no longer needed
7FE6 LDY #0 ; Y indexes character 128's definition at &0C00
7FE8 .copy_digit_glyph←1← 7FF2 BNE
LDA font_digits,x ; Copy a row of the digit's glyph...
7FEB STA room_walls,y ; ...over character 128's definition
7FEE INY ; Next row of character 128
7FEF INX ; Next row of the glyph
7FF0 CPX plot_x ; All eight rows copied?
7FF2 BNE copy_digit_glyph ; No: copy the next row
7FF4 BEQ restore_registers ; Done (always taken): print character 128
7FF6 .pass_character←4← 7F99 BCC← 7FA1 BCC← 7FA9 BCC← 7FAD BCS
PLA ; Not a letter or digit: restore the caller's Y...
7FF7 TAY ; ...from the stack
7FF8 PLA ; ...and the caller's X
7FF9 TAX ; ...from the stack
7FFA LDA plot_x ; The character, unchanged, from plot_x...
7FFC JMP mos_oswrch_default ; ...printed by the MOS 1.20 OSWRCH routine itself
7FFF EQUB &00 ; Not referenced