*EDITOR: level editor
Dunjunz, official flippy disc (Bug-Byte, 1987), Master 128 side
Updated 8 Nov 2026
This disassembly
Files
| File | Load | Exec | Length | SHA-256 |
|---|---|---|---|---|
| Editor | &1910 | &23B2 | &158E | b97927871258742ac7a1da946c64aa404042c73cc05b7f50392b972f113266e6 |
Unpack the loaded level into the slotsTurn a loaded level file into the editor's item slots, links and maps, so that it can be drawn and edited. Called once by start_editing, after crypt_level has decrypted the file at &2700 and the Chalice has been taken off the map; it runs at &7B00, copied there by start_editing, in screen memory hidden below the 30 rows shown. Read the tables from the last entry back, putting each item in the next slot down from &4F (unpack_slot): objects 30 to 1 (the exit, 30, first, into slot &4F), skipping any whose x is &80 or more, each given its editor item by item_for_type; then doors 20 to 1, likewise skipping those off the map, each with its key in the slot just below and the pair recorded as a door-key link, from link 19 down (unpack_link); then all eight trapdoors, unchecked. At most 30 + 2 x 20 + 8 = 78 of the 80 slots are filled. Last, copy the file's wall map and object-free map into wall_map and object_free_map. Counts left for show_counts and the save checks: object_count leaves out the exit (it starts at -1), door_count counts the doors and trapdoor_count is set to 8 without looking. A key is taken from the file whether or not it is on the map. pack_level reverses the order on saving, so each load and save reverses the tables.
|
|||||||||
| Load | Exec | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| 1910 | 7B00 | .unpack_level←2Referenced by← 1F4D JSRUsed as index base by← 1EDD STA | |||||||
| LDA #0 ; door_count = 0... | |||||||||
| 1912 | 7B02 | STA door_count ; ...for the count shown | |||||||
| 1914 | 7B04 | STA object_count ; ...and object_count = -1, as the exit is counted... | |||||||
| 1916 | 7B06 | DEC object_count ; ...too, so it ends as the objects besides the exit | |||||||
| 1918 | 7B08 | LDA #8 ; trapdoor_count = 8... | |||||||
| 191A | 7B0A | STA trapdoor_count ; ...as the level file has them all | |||||||
| 191C | 7B0C | LDA #max_slot ; Slots from &4F down... | |||||||
| 191E | 7B0E | STA unpack_slot ; ...the next slot to fill | |||||||
| 1921 | 7B11 | LDA #max_link ; ...links from 19 down | |||||||
| 1923 | 7B13 | STA unpack_link ; ...the next link to fill | |||||||
| ; The objects, the exit first. | |||||||||
| 1926 | 7B16 | LDX #max_object ; For objects 30 to 1... | |||||||
| 1928 | 7B18 | .unpack_object←1← 7B3B BNE | |||||||
| LDA level_object_x,x ; ...its x: on the map? | |||||||||
| 192B | 7B1B | BMI next_object ; &80 or more (&FF): not in this level | |||||||
| 192D | 7B1D | INC object_count ; Yes: count it... | |||||||
| 192F | 7B1F | LDY unpack_slot ; ...and put it in the next slot... | |||||||
| 1932 | 7B22 | STA slot_x,y ; ...the object's x as slot_x... | |||||||
| 1935 | 7B25 | LDA level_object_y,x ; ...then its y... | |||||||
| 1938 | 7B28 | STA slot_y,y ; ...into the slot too | |||||||
| 193B | 7B2B | LDA level_object_type,x ; ...and its type, turned into... | |||||||
| 193E | 7B2E | JSR item_for_type ; ...the editor's item for it (item_types)... | |||||||
| 1941 | 7B31 | LDY unpack_slot ; ...back to the slot being filled... | |||||||
| 1944 | 7B34 | STA slot_item,y ; ...stored with it... | |||||||
| 1947 | 7B37 | DEC unpack_slot ; ...and move to the next slot down | |||||||
| 194A | 7B3A | .next_object←1← 7B1B BMI | |||||||
| DEX ; Next object down... | |||||||||
| 194B | 7B3B | BNE unpack_object ; ...to object 1 | |||||||
| ; The doors, each with its key in the slot below and a ; door-key link. | |||||||||
| 194D | 7B3D | LDX #max_door ; For doors 20 to 1... | |||||||
| 194F | 7B3F | .unpack_door←1← 7B8C BNE | |||||||
| LDA level_door_x,x ; ...its x: on the map? | |||||||||
| 1952 | 7B42 | BMI next_door ; &80 or more (&FF): no door here | |||||||
| 1954 | 7B44 | INC door_count ; Yes: count it... | |||||||
| 1956 | 7B46 | LDA unpack_slot ; ...link it: the door's slot... | |||||||
| 1959 | 7B49 | LDY unpack_link ; ...in this link... | |||||||
| 195C | 7B4C | STA link_door,y ; ...recorded as the link's door... | |||||||
| 195F | 7B4F | SEC ; ...and the key's, the slot below... | |||||||
| 1960 | 7B50 | SBC #1 ; ...door slot - 1... | |||||||
| 1962 | 7B52 | STA link_key,y ; ...is the key's slot... | |||||||
| 1965 | 7B55 | DEC unpack_link ; ...and move to the next link down | |||||||
| 1968 | 7B58 | LDA level_door_x,x ; ...put the door in its slot... | |||||||
| 196B | 7B5B | LDY unpack_slot ; ...in the slot being filled... | |||||||
| 196E | 7B5E | STA slot_x,y ; ...the door's x as slot_x... | |||||||
| 1971 | 7B61 | LDA level_door_y,x ; ...then its y... | |||||||
| 1974 | 7B64 | STA slot_y,y ; ...into the slot too | |||||||
| 1977 | 7B67 | LDA level_door_sprite,x ; ...and its sprite... | |||||||
| 197A | 7B6A | JSR item_for_type ; ...as the editor's door item... | |||||||
| 197D | 7B6D | LDY unpack_slot ; ...back to the slot being filled... | |||||||
| 1980 | 7B70 | STA slot_item,y ; ...stored with it... | |||||||
| 1983 | 7B73 | DEC unpack_slot ; ...and move to the next slot down | |||||||
| 1986 | 7B76 | DEY ; Y = the door's slot - 1: the key's slot | |||||||
| 1987 | 7B77 | LDA level_key_x,x ; ...the key's x, on the map or not... | |||||||
| 198A | 7B7A | STA slot_x,y ; ...into the slot below... | |||||||
| 198D | 7B7D | LDA level_key_y,x ; ...then its y... | |||||||
| 1990 | 7B80 | STA slot_y,y ; ...stored with it, in the slot below... | |||||||
| 1993 | 7B83 | LDA #spr_key ; ...the key item... | |||||||
| 1995 | 7B85 | STA slot_item,y ; ...as the slot's item... | |||||||
| 1998 | 7B88 | DEC unpack_slot ; ...and move to the next slot down | |||||||
| 199B | 7B8B | .next_door←1← 7B42 BMI | |||||||
| DEX ; Next door down... | |||||||||
| 199C | 7B8C | BNE unpack_door ; ...to door 1 | |||||||
| ; The trapdoors. | |||||||||
| 199E | 7B8E | LDX #7 ; For trapdoors 7 to 0, all of them present... | |||||||
| 19A0 | 7B90 | .unpack_trapdoor←1← 7BA8 BPL | |||||||
| LDA level_trapdoor_x,x ; ...put each in the next slot | |||||||||
| 19A3 | 7B93 | LDY unpack_slot ; ...in the slot being filled... | |||||||
| 19A6 | 7B96 | STA slot_x,y ; ...the trapdoor's x as slot_x... | |||||||
| 19A9 | 7B99 | LDA level_trapdoor_y,x ; ...then its y... | |||||||
| 19AC | 7B9C | STA slot_y,y ; ...into the slot too | |||||||
| 19AF | 7B9F | LDA #3 ; ...as the trapdoor item... | |||||||
| 19B1 | 7BA1 | STA slot_item,y ; ...stored with it... | |||||||
| 19B4 | 7BA4 | DEC unpack_slot ; ...and move to the next slot down | |||||||
| 19B7 | 7BA7 | DEX ; ...the next trapdoor down... | |||||||
| 19B8 | 7BA8 | BPL unpack_trapdoor ; ...to trapdoor 0 | |||||||
| ; The wall and object-free maps. | |||||||||
| 19BA | 7BAA | LDX #0 ; Copy the &C9 bytes of each map | |||||||
| 19BC | 7BAC | .unpack_maps←1← 7BBB BNE | |||||||
| LDA level_walls,x ; Wall bits from the level... | |||||||||
| 19BF | 7BAF | STA wall_map,x ; ...into the wall map being edited... | |||||||
| 19C2 | 7BB2 | LDA level_object_free,x ; ...object-free bits from the level... | |||||||
| 19C5 | 7BB5 | STA object_free_map,x ; ...into the map being edited... | |||||||
| 19C8 | 7BB8 | INX ; ...on to the next map byte... | |||||||
| 19C9 | 7BB9 | CPX #map_bytes ; ...for the maps' &C9 bytes... | |||||||
| 19CB | 7BBB | BNE unpack_maps ; ...until both are copied | |||||||
| 19CD | 7BBD | RTS ; Return: the level is in the slots, links and maps | |||||||
Find the editor's item for a level typeunpack_level's lookup from the game's object type (or door sprite, &1C or &1D) to the editor's item, reading item_types the other way from pack_items. Search item_types from entry 1 for the type, keeping it in bit_mask. Nothing bounds the search: a type with no item would be matched against the bytes beyond item_types (the checksums and sprite tables), and with no match at all Y would wrap to 0 and the code would run on into &7BCE, past the copied routine, which nothing copies to after the MODE 2 clear: a zero, a BRK.
|
||||||||||||
| Load | Exec | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 19CE | 7BBE | .item_for_type←2← 7B2E JSR← 7B6A JSR | ||||||||||
| STA bit_mask ; Keep the type to compare with | ||||||||||||
| 19D0 | 7BC0 | LDY #1 ; From item 1 (item 0, the wall, has no type)... | ||||||||||
| 19D2 | 7BC2 | .search_types←1← 7BCC BNE | ||||||||||
| LDA item_types,y ; ...take item Y's level type... | ||||||||||||
| 19D5 | 7BC5 | CMP bit_mask ; ...the type being looked up? | ||||||||||
| 19D7 | 7BC7 | BNE next_type ; No: next type | ||||||||||
| 19D9 | 7BC9 | TYA ; Yes: return the item | ||||||||||
| 19DA | 7BCA | RTS ; ...the item number in A | ||||||||||
| 19DB | 7BCB | .next_type←1← 7BC7 BNE | ||||||||||
| INY ; On to the next item... | ||||||||||||
| 19DC | 7BCC | BNE search_types ; ...trying every item until one matches | ||||||||||
UnusedLeftover bytes after unpack_level's image. |
|
| 19DE | 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 ; Not used |
Mark the cursor's cell as holding an objectClear its bit in the object-free map, so that the game searches its object list when a hero steps there. The byte and bit are found as wall_bit finds them, on object_free_map at &7E00 instead of wall_map. put_item calls it first for every item placed, walls, doors, keys and trapdoors included, and nothing in the editor sets a bit again, so a deleted item leaves its cell clear and the game merely searches in vain there. The map is set to all ones by start_editing and, for a loaded level, replaced by the level's own map. It runs at &7D80, copied there by start_editing, in screen memory below the 30 rows shown (&3000-&7AFF).
|
||||||||||||||||||
| Load | Exec | |||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1A00 | 7D80 | .mark_object_cell←2Referenced by← 2BD7 JSRUsed as index base by← 1EEA STA | ||||||||||||||||
| LDA cursor_y ; Byte = (y AND &F8) x 4 + (y AND 7) + (x AND &F8) | ||||||||||||||||||
| 1A02 | 7D82 | AND #&f8 ; ...the room row, as a multiple of 8... | ||||||||||||||||
| 1A04 | 7D84 | ASL ; ...x 2... | ||||||||||||||||
| 1A05 | 7D85 | ASL ; ...x 4: 32 bytes per row of rooms | ||||||||||||||||
| 1A06 | 7D86 | STA map_ptr ; ...the row of rooms' offset so far | ||||||||||||||||
| 1A08 | 7D88 | LDA cursor_y ; ...+ (y AND 7)... | ||||||||||||||||
| 1A0A | 7D8A | AND #7 ; ...the cell's row within the room | ||||||||||||||||
| 1A0C | 7D8C | CLC ; ...C clear for the addition | ||||||||||||||||
| 1A0D | 7D8D | ADC map_ptr ; ...added to the offset | ||||||||||||||||
| 1A0F | 7D8F | STA map_ptr ; ...the offset so far | ||||||||||||||||
| 1A11 | 7D91 | LDA cursor_x ; ...+ (x AND &F8)... | ||||||||||||||||
| 1A13 | 7D93 | AND #&f8 ; ...the room's column x 8: its 8 bytes | ||||||||||||||||
| 1A15 | 7D95 | CLC ; ...C clear for the addition | ||||||||||||||||
| 1A16 | 7D96 | ADC map_ptr ; ...added to the offset | ||||||||||||||||
| 1A18 | 7D98 | STA map_ptr ; ...map_ptr: the cell's byte | ||||||||||||||||
| 1A1A | 7D9A | LDA #>(object_free_map) ; ...in object_free_map, page-aligned... | ||||||||||||||||
| 1A1C | 7D9C | STA map_ptr_hi ; ...as map_ptr's high byte | ||||||||||||||||
| 1A1E | 7D9E | LDA cursor_x ; Bit 7 - (x AND 7)... | ||||||||||||||||
| 1A20 | 7DA0 | AND #7 ; ...the cell's column within the room... | ||||||||||||||||
| 1A22 | 7DA2 | STA bit_mask ; ...kept to subtract... | ||||||||||||||||
| 1A24 | 7DA4 | LDA #7 ; ...from 7... | ||||||||||||||||
| 1A26 | 7DA6 | SEC ; ...C set for the subtraction | ||||||||||||||||
| 1A27 | 7DA7 | SBC bit_mask ; ...7 - it: the bit, leftmost cell in bit 7 | ||||||||||||||||
| 1A29 | 7DA9 | BEQ mark_bit_0 ; Bit 0: the mask is 1 | ||||||||||||||||
| 1A2B | 7DAB | TAX ; ...the bit number as a count... | ||||||||||||||||
| 1A2C | 7DAC | LDA #1 ; ...from bit 0... | ||||||||||||||||
| 1A2E | 7DAE | .mark_shift_bit←1← 7DB0 BNE | ||||||||||||||||
| ASL ; Shift the mask up a bit... | ||||||||||||||||||
| 1A2F | 7DAF | DEX ; ...one shift fewer to go | ||||||||||||||||
| 1A30 | 7DB0 | BNE mark_shift_bit ; ...until it is in place | ||||||||||||||||
| 1A32 | 7DB2 | BEQ mark_bit_found ; ...(always branches: X reached 0) | ||||||||||||||||
| 1A34 | 7DB4 | .mark_bit_0←1← 7DA9 BEQ | ||||||||||||||||
| LDA #1 ; ...the bit 0 mask | ||||||||||||||||||
| 1A36 | 7DB6 | .mark_bit_found←1← 7DB2 BEQ | ||||||||||||||||
| EOR #&ff ; Invert the mask, to clear the cell's bit... | ||||||||||||||||||
| 1A38 | 7DB8 | STA bit_mask ; ...keeping every other bit | ||||||||||||||||
| 1A3A | 7DBA | LDY #0 ; ...Y = 0 for (map_ptr),Y | ||||||||||||||||
| 1A3C | 7DBC | LDA (map_ptr),y ; ...the cell's map byte... | ||||||||||||||||
| 1A3E | 7DBE | AND bit_mask ; ...with the cell's bit cleared: objects may lie here | ||||||||||||||||
| 1A40 | 7DC0 | STA (map_ptr),y ; ...back in the map | ||||||||||||||||
| 1A42 | 7DC2 | RTS ; Return with the cell marked | ||||||||||||||||
UnusedLeftover bytes, among them the text PAGE. |
|
| 1A43 | EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, ; No &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, ; t &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, ; us &00, &00, &01, &00, &46, &42, &01, &01, &06, &06, ; ed &7C, &60, &02, &02, &00, &01, &00, &FF, &FF, &8A, &B6, &8E, &B6, &0D, &00, &00, &00, &00, &00, &00, &00, &20, &02, &43, &45, &07, &50, &41, &47, &45, &20, &02, &50, &50, &07, &0D, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &FF, &0D, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &8B, &8E, &91, &93, &95, &95, &95, &95, &95, &95, &95, &1B, &2D, &01, &1B, &2D, &00, &1B, &47, &1B, &48, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &FF, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 |
BREAK intercept: start againThe MOS calls the BREAK intercept twice during a reset, first with C clear and then, once the reset is done, with C set. editor_init points the intercept here, so BREAK (or an error, since BRKV is the reset entry) while the questions are being asked returns, on the second call, to editor_init, with the editor still in memory. start_editing disarms the intercept, so BREAK while editing is an ordinary reset; save_level arms its own, break_to_save. |
|
| ; BREAK intercept while choosing a level: on the second call (C ; set) start again. | |
| 1C10 | .break_to_start |
| BCS editor_init ; C set: the reset is done, so ask again | |
| 1C12 | RTS ; C clear: the first call, let the reset go on |
Set up and choose a levelAn editing session runs: editor_start copies the plotter page into place; editor_init (here) asks in MODE 7 whether to edit a level (E) or start a new one (N); for E, choose_filing_system selects disc (and a drive) or tape, ask_filename reads the name and the file is *LOADed at &2700; new_level, for N, prepares an empty level instead; start_editing draws the MODE 2 map, decrypting and unpacking a loaded level with crypt_level and unpack_level; edit_loop then runs until SHIFT+S, which walls the edges (wall_edges), packs the slots back into the level file (pack_level), chooses the wall block (choose_wall_block) and saves (save_level); after the save, A comes back here for another level and Q resets the machine. editor_init itself disables ESCAPE, arms the BREAK intercept with break_to_start and points BRKV at MOS 3.20's reset entry, so that BREAK or any error at the questions (a missing file, a filing system error) resets and comes back here; there is no error message. It clears level_encrypted, as no save has encrypted the level buffer yet. The first time only, it loads Table (the screen row offsets and *FREE) into private RAM, marking table_loaded_flag so that a restart skips it. It sets the map cursor's keys to ',' '.' 'A' 'Z' and last_slot to &4F, sends *TV255 1 (applied by the MODE 7 that follows) and asks the first question, leaving the answer in new_level_flag (0 edit, 1 new) for start_editing. Reached from editor_start, from break_to_start and from save_level when another level is asked for. |
|
| 1C13 | .editor_init←3← 1C10 BCS← 23A7 JMP← 23C6 JMP |
| LDA #osbyte_escape_break_effect ; OSBYTE &C8 with X=1, Y=0: disable ESCAPE | |
| 1C15 | LDX #1 ; X = 1: ESCAPE does nothing while editing |
| 1C17 | LDY #0 ; Y = 0: replace the whole setting |
| 1C19 | JSR osbyte ; Set it, so ESCAPE cannot stop the editor osbyte: escape break effect |
| ; Make BREAK, and any error, come back to editor_init through a ; reset. | |
| 1C1C | LDA #opcode_jmp ; BREAK intercept = JMP break_to_start... |
| 1C1E | STA os_break_intercept ; Arm the intercept with a JMP... |
| 1C21 | LDA #<(break_to_start) ; ...whose target is break_to_start... |
| 1C23 | STA os_break_intercept_lo ; ...its target's low byte... |
| 1C26 | LDA #>(break_to_start) ; ...high byte of the target... |
| 1C28 | STA os_break_intercept_hi ; ...so BREAK at a prompt restarts the editor |
| 1C2B | LDA #<(mos320_reset_entry) ; BRKV = &E364, MOS 3.20's reset entry: an error resets |
| 1C2D | STA brkv ; ...low byte of the error handler... |
| 1C30 | LDA #>(mos320_reset_entry) ; ...high byte of the error handler... |
| 1C32 | STA brkv + 1 ; ...so any error (File not found...) resets |
| 1C35 | LDA #0 ; Not encrypted by a save: save_level need not decrypt |
| 1C37 | STA level_encrypted ; ...so the level at &2700 is plain until saved |
| ; Load Table into private RAM, once per session. | |
| 1C3A | LDA table_loaded_flag ; Table loaded already (a restart)? |
| 1C3D | CMP #table_loaded_mark ; Table's mark there means it is loaded |
| 1C3F | BEQ table_loaded ; Yes: do not load it again |
| 1C41 | LDA #table_loaded_mark ; No: mark it loaded... |
| 1C43 | STA table_loaded_flag ; ...so a restart after BREAK skips the load... |
| 1C46 | LDX #<(load_table_command) ; ...and *L. TABLE (the row offsets and *FREE) |
| 1C48 | LDY #>(load_table_command) ; ...high byte of the command |
| 1C4A | JSR oscli ; Load Table into private RAM |
| ; Settings for the editing to come: the cursor keys and the slot ; count. | |
| 1C4D | .table_loaded←1← 1C3F BEQ |
| LDA #inkey_key_comma ; Map cursor keys for move_cursor: ',' left... | |
| 1C4F | STA key_left ; Comma moves the map cursor left |
| 1C51 | LDA #inkey_key_full_stop ; ...'.' right... |
| 1C53 | STA key_right ; Full stop moves it right |
| 1C55 | LDA #inkey_key_a ; ...'A' up... |
| 1C57 | STA key_up ; A moves it up |
| 1C59 | LDA #inkey_key_z ; ...'Z' down |
| 1C5B | STA key_down ; Z moves it down |
| 1C5D | LDA #max_slot ; 80 item slots, 0-&4F |
| 1C5F | STA last_slot ; Slots are searched from the last, &4F, down |
| ; The MODE 7 question screen: edit or new? | |
| 1C61 | LDX #<(tv_command) ; *TV255 1: shift the picture a line, interlace off |
| 1C63 | LDY #>(tv_command) ; ...high byte of the command |
| 1C65 | JSR oscli ; ...taking effect at the MODE 7 change below |
| 1C68 | LDA #3 ; VDU 3: printer off |
| 1C6A | JSR oswrch ; Stop any printer output |
| 1C6D | LDA #&16 ; VDU 22,7: MODE 7 |
| 1C6F | JSR oswrch ; Send the mode change... |
| 1C72 | LDA #7 ; ...for MODE 7... |
| 1C74 | JSR oswrch ; ...where the questions are asked |
| 1C77 | LDX #<(edit_or_new_prompt) ; Ask: edit (E) or new level (N) |
| 1C79 | LDY #>(edit_or_new_prompt) ; ...high byte of the prompt |
| 1C7B | LDA #&22 ; Internal key &22, E: answer 0, edit... |
| 1C7D | STA scratch ; ...as ask_key's first key |
| 1C7F | LDA #&55 ; Internal key &55, N: answer 1, new level... |
| 1C81 | STA scratch_hi ; ...as ask_key's second key |
| 1C83 | LDA #0 ; A = 0: take one of the two keys |
| 1C85 | JSR ask_key ; Ask, and get 0 for edit or 1 for new |
| 1C88 | STA new_level_flag ; Remember the choice for start_editing: 1 for new |
| 1C8B | BEQ edit_level ; E: edit a level file |
| 1C8D | JMP new_level ; N: start with an empty level |
| ; Edit: choose the filing system, read a filename into ; load_command and *LOAD the level at &2700. | |
| 1C90 | .edit_level←1← 1C8B BEQ |
| JSR new_lines ; Leave a blank line under the question | |
| 1C93 | JSR choose_filing_system ; Choose disc or tape (and the drive) |
| 1C96 | LDA #' ' ; Blank the filename in load_command... |
| 1C98 | LDX #5 ; From the name field at load_command+5... |
| 1C9A | .blank_load_name←1← 1CA0 BNE |
| STA load_command,x ; ...put a space... | |
| 1C9D | INX ; ...in each character... |
| 1C9E | CPX #&0c ; ...up to load_command+11... |
| 1CA0 | BNE blank_load_name ; ...so no longer earlier name is left in it |
| 1CA2 | JSR ask_filename ; Read the filename (L if none is typed) |
| 1CA5 | LDA #&0a ; LF, below the line ask_filename ended |
| 1CA7 | JSR oswrch ; Leave a blank line under the typed name |
| 1CAA | LDA #' ' ; A space at the name's last character... |
| 1CAC | STA load_command + 11 ; ...already blank: the space at +12 ends the name |
| 1CAF | LDX #0 ; Copy the filename typed into load_command... |
| 1CB1 | .copy_load_name←1← 1CBA BNE |
| LDA filename_buffer,x ; Take a character of the typed name... | |
| 1CB4 | STA load_command + 5,x ; ...into the command's name field... |
| 1CB7 | INX ; ...the next character... |
| 1CB8 | CPX scratch ; ...for the name's length, without its CR... |
| 1CBA | BNE copy_load_name ; ...until the name is copied |
| 1CBC | LDX #<(load_command) ; *LOAD name 2700 |
| 1CBE | LDY #>(load_command) ; ...high byte of the command |
| 1CC0 | JSR oscli ; Load the level file at &2700, still encrypted |
| 1CC3 | JMP start_editing ; Edit it: start_editing decrypts and draws it |
Print a prompt and wait for one of its keysThe editor's one-keypress questions: editor_init's edit or new, choose_filing_system's disc or tape and its drive, and save_level's another level or quit. Print the text at XY up to (not including) its '*', flush the input buffer and scan the keyboard with OSBYTE &7A until an answer is held, ignoring every other key. With A=0 the answers are the two keys whose internal numbers are in scratch and scratch_hi, and A returns 0 for the first or 1 for the second, nothing being echoed. Otherwise the answers are the digits 0-3 (their internal numbers in drive_keys), and the digit is echoed and returned as a character, ready for drive_command. The flush runs with X still holding the prompt's low byte, which is non-zero for every prompt, so only the input buffer is flushed. Because the keys are read by scanning, the key pressed is left in the input buffer; ask_filename flushes it before reading a name.
|
|||||||||||||||||
| 1CC6 | .ask_key←4← 1C85 JSR← 2128 JSR← 213D JSR← 23A2 JSR | ||||||||||||||||
| PHA ; Keep the mode: 0 for two answer keys, else digits | |||||||||||||||||
| 1CC7 | STX plot_x ; Point plot_x/plot_y at the prompt... | ||||||||||||||||
| 1CC9 | STY plot_y ; ...high byte: the prompt's address | ||||||||||||||||
| 1CCB | LDY #0 ; Print it up to the '*'... | ||||||||||||||||
| 1CCD | .print_prompt←1← 1CD7 BNE | ||||||||||||||||
| LDA (plot_x),y ; Take a character of the prompt... | |||||||||||||||||
| 1CCF | JSR oswrch ; ...print it on the MODE 7 screen... | ||||||||||||||||
| 1CD2 | INY ; ...move to the next... | ||||||||||||||||
| 1CD3 | LDA (plot_x),y ; ...and look ahead at it: | ||||||||||||||||
| 1CD5 | CMP #'*' ; The '*' ends the prompt... | ||||||||||||||||
| 1CD7 | BNE print_prompt ; ...so print until it | ||||||||||||||||
| 1CD9 | LDA #osbyte_flush_buffer_class ; OSBYTE &0F, X = prompt low byte (non-zero): input | ||||||||||||||||
| 1CDB | JSR osbyte ; Discard keys pressed before the prompt Flush selected class of buffer | ||||||||||||||||
| 1CDE | .scan_keys←2← 1CF2 BMI← 1D04 BNE | ||||||||||||||||
| LDA #osbyte_scan_keyboard_from_16 ; OSBYTE &7A: scan the keyboard from key 16... | |||||||||||||||||
| 1CE0 | JSR osbyte ; ...X = the internal number of a key held, or &FF Scan keyboard from key 16 | ||||||||||||||||
| 1CE3 | PLA ; Mode kept on the stack: two keys or digits? | ||||||||||||||||
| 1CE4 | PHA ; ...keeping the mode for the next pass | ||||||||||||||||
| 1CE5 | BEQ check_two_keys ; A = 0: compare with the two answer keys | ||||||||||||||||
| 1CE7 | LDY #3 ; Digits: is it 0, 1, 2 or 3? | ||||||||||||||||
| 1CE9 | .check_digit←1← 1CF0 BPL | ||||||||||||||||
| TXA ; The internal key number pressed... | |||||||||||||||||
| 1CEA | CMP drive_keys,y ; ...against digit Y's key... | ||||||||||||||||
| 1CED | BEQ digit_pressed ; Match: digit Y was pressed | ||||||||||||||||
| 1CEF | DEY ; No: try the digit below... | ||||||||||||||||
| 1CF0 | BPL check_digit ; ...down to 0 | ||||||||||||||||
| 1CF2 | BMI scan_keys ; Not a drive digit: scan again | ||||||||||||||||
| 1CF4 | .digit_pressed←1← 1CED BEQ | ||||||||||||||||
| PLA ; Drop the kept mode | |||||||||||||||||
| 1CF5 | TYA ; Digit character = '0' + Y, the digit's value... | ||||||||||||||||
| 1CF6 | CLC ; ...C clear for the addition... | ||||||||||||||||
| 1CF7 | ADC #'0' ; ...as its character... | ||||||||||||||||
| 1CF9 | JSR oswrch ; ...echoed after the prompt | ||||||||||||||||
| 1CFC | RTS ; Return the digit's character, for *DRIVE | ||||||||||||||||
| 1CFD | .check_two_keys←1← 1CE5 BEQ | ||||||||||||||||
| TXA ; The first key? | |||||||||||||||||
| 1CFE | CMP scratch ; Is it the first answer's key... | ||||||||||||||||
| 1D00 | BEQ first_key ; Yes: first key | ||||||||||||||||
| 1D02 | CMP scratch_hi ; The second key? | ||||||||||||||||
| 1D04 | BNE scan_keys ; Neither answer: scan again | ||||||||||||||||
| 1D06 | PLA ; Second: drop the kept mode | ||||||||||||||||
| 1D07 | LDA #1 ; The second answer: 1 | ||||||||||||||||
| 1D09 | RTS ; Return the answer in A | ||||||||||||||||
| 1D0A | .first_key←1← 1D00 BEQ | ||||||||||||||||
| PLA ; First: drop the kept mode | |||||||||||||||||
| 1D0B | LDA #0 ; The first answer: 0 | ||||||||||||||||
| 1D0D | RTS ; Return the answer in A | ||||||||||||||||
Prompts and commandsThe MODE 7 questions, the OSWORD 0 buffer and block, and the * commands passed to OSCLI. A prompt for ask_key ends with '*', which is not printed; filename_prompt and level_number_prompt end with a zero, printed by their callers; commands end with CR. load_command and save_command hold a filename field at +5 that editor_init and save_level blank and fill from filename_buffer; drive_command's digit is filled in by choose_filing_system. The filename fields and buffers start out holding leftover text and asterisks. |
|
| 1D0E | .edit_or_new_prompt |
| EQUS "Edit (E) or start new level (N) *" ; editor_init's first question, for ask_key | |
| 1D2F | .disc_or_tape_prompt |
| EQUS "Disc (D) or tape (T) *" ; choose_filing_system's question, for ask_key | |
| 1D45 | .filename_prompt←1Used as index base by← 1E52 LDA |
| EQUS "Filename " ; Printed by ask_filename; the name is typed after it | |
| 1D4E | EQUB &00 ; Zero: the end |
| 1D4F | .drive_prompt |
| EQUS "Which drive *" ; Asked after *DISC; answered with a digit 0-3 | |
| ; *DRIVE n, with the digit at +5. | |
| 1D5C | .drive_command |
| EQUS "DRIVE" | |
| 1D61 | .drive_digit←1← 2140 STA |
| EQUB &20 ; The drive digit, '0'-'3', from ask_key | |
| 1D62 | EQUB &0D ; CR: the end of the command |
| ; OSWORD 0's buffer: a filename (up to 7 characters) or a level ; number's digits. | |
| 1D63 | .filename_buffer←6Referenced by← 1E99 STA← 2298 STA← 22CA LDA← 22D2 LDAUsed as index base by← 1CB1 LDA← 237D LDA |
| EQUB &2A, &2A, &2A, &2A, &2A, &2A, &2A, &2A | |
| ; OSWORD 0 block: buffer address, maximum length, lowest and ; highest character, filled in before each call. | |
| 1D6B | .read_line_block←2← 1E63 STA← 22A0 STA |
| EQUB &2A, &2A, &2A, &2A, &2A | |
| ; *LOAD name 2700, the name at +5. | |
| 1D70 | .load_command←1Used as index base by← 1C9A STA |
| EQUS "LOAD LEVEL11 2700", &0D | |
| 1D82 | .drive_0_command |
| EQUS "DR.0", &0D ; *DRIVE 0: edit_loop's, so Stones loads from drive 0 | |
| 1D87 | .disc_command |
| EQUS "DI.", &0D ; *DISC: choose_filing_system's D, and for Stones | |
| 1D8B | .tv_command |
| EQUS "TV255 1", &0D ; *TV255 1: editor_init's, before its MODE 7 | |
| 1D93 | .load_table_command |
| EQUS "L. TABLE", &0D ; *LOAD TABLE: editor_init's, the first time | |
| 1D9C | .tape_command |
| EQUS "T.", &0D ; *TAPE: choose_filing_system's T answer | |
| 1D9F | .cat_command |
| EQUS ".", &0D ; *CAT: save_level's, when no level is typed | |
| ; VDU 31 and the labels of the three counts: Objs, Mons (the ; trapdoors, where monsters appear) and Dors. | |
| 1DA1 | .count_labels←1Used as index base by← 21AF LDA |
| EQUB &1F, &10, &00 ; VDU 31,16,0: TAB(16,0) | |
| 1DA4 | EQUS "Objs" |
| 1DA8 | EQUB &1F, &10, &04 ; VDU 31,16,4: TAB(16,4) |
| 1DAB | EQUS "Mons" |
| 1DAF | EQUB &1F, &10, &08 ; VDU 31,16,8: TAB(16,8) |
| 1DB2 | EQUS "Dors" |
| 1DB6 | EQUB &0D ; CR: the end |
| ; VDU 23,0,10,32 (no cursor), VDU 23,0,6,30 (30 rows), VDU ; 19,10,1 and VDU 19,9,3. | |
| 1DB7 | .edit_screen_vdu←1Used as index base by← 2155 LDA |
| EQUB &17, &00, &0A, &20, ; VDU 23,0,10,32: 6845 register 10 &00, &00, &00, &00, ; = &20, no cursor &00, &00 | |
| 1DC1 | EQUB &00 ; VDU 0: does nothing |
| 1DC2 | EQUB &17, &00, &06, &1E, ; VDU 23,0,6,30: 6845 register 6 = &00, &00, &00, &00, ; 30 character rows displayed &00, &00 |
| 1DCC | EQUB &13, &0A, &01, ; VDU 19,10,1: logical colour 10 shows &00, &00, &00 ; red |
| 1DD2 | EQUB &13, &09, &03, ; VDU 19,9,3: logical colour 9 shows &00, &00, &00 ; yellow |
UnusedFour asterisks, not sent. |
|
| 1DD8 | .edit_screen_vdu_end |
| EQUB &2A, &2A, &2A, &2A ; Not used | |
| 1DDC | .level_number_prompt←1Used as index base by← 2287 LDA |
| EQUS "Level in the Dunjunz complex ", &00 ; Asked when saving: the level number | |
| ; *SAVE name 2700+2B0, the name at +5. | |
| 1DFA | .save_command←1Used as index base by← 236B STA |
| EQUS "SAVE LEVEL22 2700+2B0", &0D ; *SAVE the &2B0-byte level file from &2700 | |
| 1E10 | .another_prompt |
| EQUS "Another level (A) or quit (Q) *" ; Asked after a save, for ask_key | |
Print a new line and a blank lineCR, LF, LF: ends the current line and leaves a blank one, spacing out the MODE 7 questions. Called by editor_init, ask_filename, choose_filing_system and save_level.
|
||||||||
| 1E2F | .new_lines←6← 1C90 JSR← 1E4D JSR← 2134 JSR← 23E7 JSR← 23ED JSR← 23FA JSR | |||||||
| LDA #&0d ; CR: back to the start of the line... | ||||||||
| 1E31 | JSR oswrch ; ...sent | |||||||
| 1E34 | LDA #&0a ; LF, sent twice... | |||||||
| 1E36 | JSR oswrch ; ...down one line... | |||||||
| 1E39 | JSR oswrch ; ...and another, leaving a blank line | |||||||
| 1E3C | RTS ; Return, the cursor two lines down at the left | |||||||
Ask for a filenameAsk for the name of the level file, for editor_init (to load) and save_level (to save). Pause for 65536 passes of a delay loop, then flush every buffer, so the key that answered ask_key's last question (still in the input buffer) is not taken as the start of the name. Print 'Filename ' and read up to seven characters, space to '~', into filename_buffer with OSWORD 0. If only RETURN is typed, go back up onto the prompt line, print 'L' after the prompt as if it had been typed, and use the one-letter name L. ESCAPE is disabled, so OSWORD 0's ESCAPE exit is not checked.
|
||||||
| 1E3D | .ask_filename←2← 1CA2 JSR← 2373 JSR | |||||
| LDX #0 ; Pause for 256 x 256 loops... | ||||||
| 1E3F | .pause_outer←1← 1E46 BNE | |||||
| LDY #0 ; Each outer pass... | ||||||
| 1E41 | .pause_inner←1← 1E43 BNE | |||||
| NOP ; ...a NOP to waste time... | ||||||
| 1E42 | DEY ; ...counted down from 256... | |||||
| 1E43 | BNE pause_inner ; ...in the inner loop... | |||||
| 1E45 | DEX ; ...for 256 outer passes... | |||||
| 1E46 | BNE pause_outer ; ...a short wait after the last answer | |||||
| 1E48 | LDA #osbyte_flush_buffer_class ; Flush buffers (X = 0: all) | |||||
| 1E4A | JSR osbyte ; Drop the answer key, so it is not read as the name Flush selected class of buffer | |||||
| 1E4D | JSR new_lines ; Leave a blank line before the prompt | |||||
| 1E50 | LDX #0 ; Print the filename prompt, up to and including its zero | |||||
| 1E52 | .print_filename_prompt←1← 1E5B BNE | |||||
| LDA filename_prompt,x ; Take a character of 'Filename '... | ||||||
| 1E55 | JSR oswrch ; ...print it... | |||||
| 1E58 | INX ; ...move to the next... | |||||
| 1E59 | CMP #0 ; ...the zero ends it... | |||||
| 1E5B | BNE print_filename_prompt ; ...and is printed too | |||||
| 1E5D | LDX #<(read_line_block) ; Point XY at read_line_block... | |||||
| 1E5F | LDY #>(read_line_block) ; ...high byte of the block | |||||
| 1E61 | LDA #<(filename_buffer) ; ...and fill it in: the buffer is filename_buffer... | |||||
| 1E63 | STA read_line_block ; ...low byte of the buffer... | |||||
| 1E66 | LDA #>(filename_buffer) ; ...high byte of the buffer... | |||||
| 1E68 | STA read_line_block + 1 ; ...stored at +1 | |||||
| 1E6B | LDA #7 ; ...at most 7 characters... | |||||
| 1E6D | STA read_line_block + 2 ; ...a DFS filename's length | |||||
| 1E70 | LDA #' ' ; ...characters from space (lowest accepted)... | |||||
| 1E72 | STA read_line_block + 3 ; ...lowest character accepted... | |||||
| 1E75 | LDA #'~' ; ...to '~' (highest accepted)... | |||||
| 1E77 | STA read_line_block + 4 ; ...highest character accepted | |||||
| 1E7A | LDA #osword_read_line ; OSWORD 0: read the name | |||||
| 1E7C | JSR osword ; Read the filename the user types Read line from input stream (exits with C=1 if ESCAPE pressed) | |||||
| 1E7F | STY scratch ; Keep its length, not counting the CR | |||||
| 1E81 | CPY #0 ; Length 0, only RETURN typed? | |||||
| 1E83 | BNE filename_read ; A name was typed: return | |||||
| 1E85 | LDA #&0b ; Only RETURN: VDU 11, up a line... | |||||
| 1E87 | JSR oswrch ; ...back onto the prompt line | |||||
| 1E8A | LDA #9 ; ...and VDU 9, right... | |||||
| 1E8C | LDY #9 ; ...nine times, the length of 'Filename '... | |||||
| 1E8E | .move_right←1← 1E92 BNE | |||||
| JSR oswrch ; ...one step right... | ||||||
| 1E91 | DEY ; ...counting the steps... | |||||
| 1E92 | BNE move_right ; ...until the cursor is past 'Filename ' | |||||
| 1E94 | LDA #'L' ; ...then print 'L' there... | |||||
| 1E96 | JSR oswrch ; ...as if typed | |||||
| 1E99 | STA filename_buffer ; ...and use it as the name | |||||
| 1E9C | INY ; Length 1 (Y is 0 after the loop) | |||||
| 1E9D | STY scratch ; ...as the name's length | |||||
| 1E9F | JSR osnewl ; New line, as RETURN gave before | |||||
| 1EA2 | .filename_read←1← 1E83 BNE | |||||
| RTS ; Return the name in filename_buffer, length in scratch | ||||||
Start a new, empty levelReached from editor_init when N is chosen. Fill the level's wall block (&30 bytes at &2980) with &03, then fall into start_editing, which sees new_level_flag set and starts from an empty map. Nothing reads the filler: the editor draws walls with its own sprite, and choose_wall_block always replaces the block with one from Stones before the level is saved. Nothing else of the level file is prepared here; start_editing clears its object, door and key tables, and pack_level packs the slots and maps into it when saving.
|
||||||||
| 1EA3 | .new_level←1← 1C8D JMP | |||||||
| LDA #3 ; Fill level_wall_block with &03... | ||||||||
| 1EA5 | LDX #wall_block_bytes - 1 ; ...for all &30 bytes... | |||||||
| 1EA7 | .fill_wall_block←1← 1EAB BPL | |||||||
| STA level_wall_block,x ; ...a filler, replaced before saving... | ||||||||
| 1EAA | DEX ; ...from the last byte... | |||||||
| 1EAB | BPL fill_wall_block ; ...to the first, then fall into start_editing | |||||||
| fall through ↓ | ||||||||
Set up the editing screen and editTurn the level at &2700 (or nothing, for a new level) into the editor's own form and draw it, ready for edit_loop. Reached from editor_init once a level file is loaded, and from new_level; new_level_flag says which. The editor keeps a level as 80 item slots (slot_x, slot_y, slot_item at &0C00), its own wall_map (&2F00) and object_free_map (&7E00), and the door-key links; the level file is only read here and written by pack_level. First, an empty editor: zero the wall map and every slot (a free slot is item 0, a wall, at (0, 0)), zero cursor_flash and link_index, select MODE 2 and disarm the BREAK intercept. The MODE 2 change clears &3000-&7FFF, so only then are unpack_level and mark_object_cell copied to &7B00 and &7D80 and the object-free map at &7E00 set to &FF (no object anywhere): set_edit_screen shows just 30 character rows, &3000-&7AFF, leaving &7B00-&7FFF as hidden workspace. Free all 20 links, note no door waiting for its key, set GCOL 3,3 (exclusive-OR, so a link line drawn twice is erased), zero the four counts and turn cursor editing off. For a loaded level: decrypt it with crypt_level, take an object of type &73 (the Chalice, which only level 25 has and the editor has no item for) off the map, unpack the tables into the slots and maps with unpack_level, show the labels and counts and plot the item in every one of the 32 x 48 cells that has one. exit_placed is then set without checking that the file's exit was on the map (unpack_level has already set trapdoor_count to 8 the same way). For both: set the level file's objects 1-29, doors and keys to &FF, so that pack_level need write only the items placed; show the labels and counts (a loaded level's for the second time); put the cursor at (11, 11), the top-left of the heroes' four start cells, with the wall as the current item, the slow cursor on and colour_10 at 1 (red, as set_edit_screen set it), and fall into edit_loop. |
|
| 1EAD | .start_editing←1← 1CC3 JMP |
| LDA #0 ; Zero all of &2F00-&2FFF, wall_map and beyond... | |
| 1EAF | TAX ; ...from offset 0... |
| 1EB0 | .clear_walls←1← 1EB4 BNE |
| STA wall_map,x ; ...no walls in this byte... | |
| 1EB3 | DEX ; ...the next byte down... |
| 1EB4 | BNE clear_walls ; ...through all 256 |
| 1EB6 | .clear_slots←1← 1EBA BNE |
| STA slot_x,x ; ...and the item slots (&0C00-&0CFF) | |
| 1EB9 | DEX ; ...one byte of the slot tables... |
| 1EBA | BNE clear_slots ; ...through all 256: every slot free, item 0 |
| 1EBC | LDA #0 ; Cursor flash phase 0... |
| 1EBE | STA cursor_flash ; ...so the first wall pass plots the cursor |
| 1EC1 | LDA #0 ; Door-key link 0... |
| 1EC3 | STA link_index ; ...is the first to be made |
| ; The MODE 2 map screen, which also clears &3000-&7FFF. BREAK ; from here on is an ordinary reset. | |
| 1EC6 | LDA #&16 ; VDU 22,2: MODE 2 |
| 1EC8 | JSR oswrch ; Send the mode change... |
| 1ECB | LDA #2 ; ...for MODE 2... |
| 1ECD | JSR oswrch ; ...the 16-colour screen the map is drawn on |
| 1ED0 | LDA #0 ; Not a JMP: disarm the BREAK intercept... |
| 1ED2 | STA os_break_intercept ; ...so BREAK while editing is an ordinary reset |
| 1ED5 | JSR set_edit_screen ; No cursor, 30 rows, colours 10 and 9 |
| ; Into the hidden screen memory above the 30 rows shown: the two ; routines, then an empty object-free map and door-key links. | |
| 1ED8 | LDX #0 ; Copy unpack_level to &7B00... |
| 1EDA | .copy_unpack←1← 1EE3 BNE |
| LDA unpack_level_image,x ; Take a byte of the stored routine... | |
| 1EDD | STA unpack_level,x ; ...to &7B00, where it runs... |
| 1EE0 | INX ; ...on to the next byte... |
| 1EE1 | CPX #&ce ; ...for unpack_level's &CE bytes... |
| 1EE3 | BNE copy_unpack ; ...until it is all copied |
| 1EE5 | LDX #0 ; ...and mark_object_cell to &7D80 |
| 1EE7 | .copy_mark_object_cell←1← 1EF0 BNE |
| LDA mark_object_cell_image,x ; Take a byte of the stored routine... | |
| 1EEA | STA mark_object_cell,x ; ...to &7D80, where it runs... |
| 1EED | INX ; ...on to the next byte... |
| 1EEE | CPX #&43 ; ...for mark_object_cell's &43 bytes... |
| 1EF0 | BNE copy_mark_object_cell ; ...until it is all copied |
| 1EF2 | LDA #&ff ; Fill &7E00-&7EFF, object_free_map, with &FF... |
| 1EF4 | LDX #0 ; ...from offset 0... |
| 1EF6 | .clear_free_map←1← 1EFA BNE |
| STA object_free_map,x ; ...set every bit: no object anywhere... | |
| 1EF9 | DEX ; ...the next byte down... |
| 1EFA | BNE clear_free_map ; ...through all 256 |
| 1EFC | .clear_links←1← 1F05 BNE |
| STA link_door,x ; ...and &FF: all 20 door-key links unused | |
| 1EFF | STA link_key,x ; ...no key for it... |
| 1F02 | INX ; ...the next link... |
| 1F03 | CPX #max_link + 1 ; ...all 20 of them... |
| 1F05 | BNE clear_links ; ...until every link is free |
| 1F07 | STA pending_door_item ; &FF: no door waiting for its key |
| ; Drawing mode, counts and keys for editing. | |
| 1F0A | LDA #&12 ; VDU 18,3,3: GCOL 3,3 (exclusive-OR, for the link lines) |
| 1F0C | JSR oswrch ; Send VDU 18, GCOL... |
| 1F0F | LDA #3 ; ...mode 3: exclusive-OR, so a line... |
| 1F11 | JSR oswrch ; ...drawn twice is erased... |
| 1F14 | JSR oswrch ; ...in colour 3 |
| 1F17 | LDA #0 ; No trapdoors, objects, exit or doors |
| 1F19 | STA trapdoor_count ; No trapdoors yet |
| 1F1B | STA door_count ; No doors yet |
| 1F1D | STA exit_placed ; No exit yet |
| 1F1F | STA object_count ; No objects yet |
| 1F21 | LDA #osbyte_set_cursor_editing ; OSBYTE 4,1: cursor editing off... |
| 1F23 | LDX #1 ; ...X = 1: the arrow keys give codes &88-&8B |
| 1F25 | JSR osbyte ; Set it; the editor reads the arrow keys by scanning Set cursor editing keys |
| 1F28 | LDA new_level_flag ; new_level_flag: editor_init's answer, 1 for N |
| 1F2B | BEQ unpack_loaded ; 0, a loaded level: decrypt, unpack and draw it |
| 1F2D | LDA #0 ; Yes: link_index = 0... |
| 1F2F | STA link_index ; ...again (it was set above) |
| 1F32 | BEQ clear_level_tables ; ...and clear the level tables (always branches) |
| ; A loaded level: decrypt, drop the Chalice, unpack. | |
| 1F34 | .unpack_loaded←1← 1F2B BEQ |
| JSR crypt_level ; Decrypt the loaded level in place at &2700 | |
| 1F37 | LDX #max_object - 1 ; Find an object of type &73 (the Chalice)... |
| 1F39 | .find_chalice←1← 1F41 BNE |
| LDA level_object_type,x ; This object's type... | |
| 1F3C | CMP #game_chalice_type ; ...is it &73, the Chalice? |
| 1F3E | BEQ drop_chalice ; Yes: take it off the map |
| 1F40 | DEX ; No: the next object down... |
| 1F41 | BNE find_chalice ; ...to object 1 (not the exit, 30) |
| 1F43 | BEQ draw_loaded ; No Chalice: unpack the level as it is |
| 1F45 | .drop_chalice←1← 1F3E BEQ |
| LDA #off_map ; Drop it: x and y &FF | |
| 1F47 | STA level_object_x,x ; ...so unpack_level skips it: the editor... |
| 1F4A | STA level_object_y,x ; ...has no item for the Chalice |
| 1F4D | .draw_loaded←1← 1F43 BEQ |
| JSR unpack_level ; Unpack the level into the slots and maps | |
| 1F50 | JSR show_labels ; Show the labels... |
| 1F53 | JSR show_counts ; ...and the unpacked level's counts |
| ; Plot every cell of the unpacked level. | |
| 1F56 | LDA #0 ; Draw every cell: rows 0-47... |
| 1F58 | STA cursor_y ; ...from the top row |
| 1F5A | .draw_row←1← 1F76 BNE |
| LDA #0 ; ...columns 0-31... | |
| 1F5C | STA cursor_x ; ...from the left column |
| 1F5E | .draw_cell←1← 1F6E BNE |
| JSR item_at_cursor ; ...the item in this cell, if any | |
| 1F61 | CMP #&ff ; &FF: nothing here |
| 1F63 | BEQ next_cell ; Empty: nothing to plot |
| 1F65 | JSR plot_at_cursor ; Plot the item's sprite in the cell |
| 1F68 | .next_cell←1← 1F63 BEQ |
| INC cursor_x ; Step the cursor right a cell | |
| 1F6A | LDA cursor_x ; Which column now? |
| 1F6C | CMP #map_width ; Past the last column? |
| 1F6E | BNE draw_cell ; No: draw the next cell |
| 1F70 | INC cursor_y ; Row done: step the cursor down a row |
| 1F72 | LDA cursor_y ; Which row now? |
| 1F74 | CMP #map_height ; Past the last row? |
| 1F76 | BNE draw_row ; No: draw the next row |
| 1F78 | LDA #1 ; Take a loaded level to have its exit, unchecked... |
| 1F7A | STA exit_placed ; ...which SHIFT+S needs before it saves |
| ; Both: empty the level file's object, door and key tables, for ; pack_level to fill. | |
| 1F7C | .clear_level_tables←1← 1F32 BEQ |
| LDA #off_map ; Clear the level file's object tables... | |
| 1F7E | LDX #max_object - 1 ; ...objects 29 to 1 (the exit is 30)... |
| 1F80 | .clear_object_entries←1← 1F87 BNE |
| STA level_object_x,x ; ...off the map... | |
| 1F83 | STA level_object_y,x ; ...both x and y... |
| 1F86 | DEX ; ...the next object down... |
| 1F87 | BNE clear_object_entries ; ...until all are cleared |
| 1F89 | LDX #max_door ; ...and the door and key tables, for pack_level |
| 1F8B | .clear_door_entries←1← 1F98 BNE |
| STA level_door_x,x ; ...door off the map... | |
| 1F8E | STA level_door_y,x ; ...its y too... |
| 1F91 | STA level_key_x,x ; ...its key off the map... |
| 1F94 | STA level_key_y,x ; ...and its y |
| 1F97 | DEX ; ...the next door down... |
| 1F98 | BNE clear_door_entries ; ...until doors 20 to 1 are cleared |
| ; The side panel, and the cursor's starting state. | |
| 1F9A | JSR show_labels ; Show the labels (again, for a loaded level)... |
| 1F9D | JSR show_counts ; ...and the counts |
| 1FA0 | LDA #&0b ; Cursor at (11, 11)... |
| 1FA2 | STA cursor_x ; ...as cursor_x, column 11... |
| 1FA4 | STA cursor_y ; ...row 11: top-left of the heroes' start |
| 1FA6 | LDA #0 ; Current item 0, so SPACE places walls... |
| 1FA8 | STA current_item ; ...item 0, the wall |
| 1FAA | LDA #1 ; Slow cursor on, colour 10 = 1 |
| 1FAC | STA slow_cursor ; Move the cursor every third frame |
| 1FAF | STA colour_10 ; Logical colour 10 shows red, as set above |
| 1FB2 | LDA #osbyte_set_cursor_editing ; OSBYTE 4,1 again... |
| 1FB4 | LDX #1 ; ...X = 1: cursor editing off... |
| 1FB6 | JSR osbyte ; ...a repeat of the call above Set cursor editing keys |
| fall through ↓ | |
The editing loopThe editor proper: start_editing falls into it with the map drawn, and it loops for good, until SHIFT+S saves the level. Each pass reads the keys in this order:
SPACE with walls, and SPACE refused at the edge, start the next pass at once, skipping TAB and CTRL. |
|
| 1FB9 | .edit_loop←2← 20A4 JMP← 20F4 JMP |
| LDA slow_cursor ; Slow cursor on? | |
| 1FBC | BEQ check_f0 ; No: run the pass at once |
| 1FBE | LDX #3 ; Yes: wait for three frames first |
| 1FC0 | .slow_wait←1← 1FCA BNE |
| TXA ; Keep the frames left to wait... | |
| 1FC1 | PHA ; ...on the stack, as OSBYTE corrupts X |
| 1FC2 | LDA #osbyte_vsync ; OSBYTE &13: wait for the next frame |
| 1FC4 | JSR osbyte ; Slow cursor: a step every fourth frame Wait for vertical sync |
| 1FC7 | PLA ; Recover the frames left to wait... |
| 1FC8 | TAX ; ...into X, the countdown |
| 1FC9 | DEX ; One frame fewer to wait |
| 1FCA | BNE slow_wait ; Wait again until three have passed |
| ; f0: toggle the slow cursor, once per press. | |
| 1FCC | .check_f0←1← 1FBC BEQ |
| LDX #inkey_key_f0 ; Test f0 (INKEY -33)... | |
| 1FCE | JSR key_pressed ; ...is it held? |
| 1FD1 | BNE check_save ; No: on to SHIFT+S |
| 1FD3 | LDA slow_cursor ; Yes: toggle the slow cursor... |
| 1FD6 | EOR #1 ; ...between on (1) and off (0)... |
| 1FD8 | STA slow_cursor ; ...and keep the new setting |
| 1FDB | .wait_f0_released←1← 1FE0 BEQ |
| LDX #inkey_key_f0 ; Wait for f0 to be released... | |
| 1FDD | JSR key_pressed ; ...so one press toggles once |
| 1FE0 | BEQ wait_f0_released ; Still held: keep waiting |
| ; SHIFT+S: save, if the level is complete. | |
| 1FE2 | .check_save←1← 1FD1 BNE |
| LDX #inkey_key_s ; Test S, for SHIFT+S... | |
| 1FE4 | JSR key_pressed ; ...is it held? |
| 1FE7 | BNE edit_keys ; No: on to the editing keys |
| 1FE9 | LDX #inkey_key_shift ; ...then test SHIFT... |
| 1FEB | JSR key_pressed ; ...is it held as well? |
| 1FEE | BNE edit_keys ; No: on to the editing keys |
| 1FF0 | LDA exit_placed ; Yes: is the exit placed? |
| 1FF2 | BEQ edit_keys ; No: cannot save yet |
| 1FF4 | JSR check_door_keys ; Does every door have its key? |
| 1FF7 | BNE edit_keys ; No: cannot save yet |
| 1FF9 | LDA trapdoor_count ; How many trapdoors are placed? |
| 1FFB | CMP #8 ; Exactly 8, the game's number? |
| 1FFD | BNE edit_keys ; No: cannot save yet |
| 1FFF | LDX #<(disc_command) ; Complete: *DISC, as Stones is read from disc... |
| 2001 | LDY #>(disc_command) ; ...(command's high byte) |
| 2003 | JSR oscli ; ...select the disc filing system |
| 2006 | LDX #<(drive_0_command) ; ...then *DRIVE 0... |
| 2008 | LDY #>(drive_0_command) ; ...(command's high byte) |
| 200A | JSR oscli ; ...select drive 0, where Stones is |
| 200D | JSR wall_edges ; Wall in the map's four edges |
| 2010 | JSR pack_level ; Pack the slots and maps into the level file |
| 2013 | JSR choose_wall_block ; Choose its wall block from Stones |
| 2016 | LDA #&16 ; VDU 22,7: MODE 7 for the save prompts... |
| 2018 | JSR oswrch ; ...send VDU 22, select a mode... |
| 201B | LDA #7 ; ...mode 7, the text screen... |
| 201D | JSR oswrch ; ...send the mode number |
| 2020 | JSR save_level ; Save it: ends by restarting the editor or resetting |
| 2023 | RTS ; Not reached: save_level never returns |
| ; Move the cursor; with walls chosen, flash it. | |
| 2024 | .edit_keys←5← 1FE7 BNE← 1FEE BNE← 1FF2 BEQ← 1FF7 BNE← 1FFD BNE |
| JSR move_cursor ; Move the cursor, redrawing the cell it leaves | |
| 2027 | LDA current_item ; Placing walls (item 0)? |
| 2029 | BNE check_cursor_up ; No: the item itself shows as the cursor |
| 202B | LDA cursor_flash ; Yes: flash the cursor sprite over the wall... |
| 202E | EOR #1 ; ...toggling cursor_flash each pass... |
| 2030 | STA cursor_flash ; ...and keeping the new phase |
| 2033 | BEQ check_cursor_up ; Off this pass: move_cursor's wall sprite shows |
| 2035 | LDA #spr_cursor ; On this pass: the cursor sprite... |
| 2037 | JSR plot_at_cursor ; ...over the wall move_cursor drew |
| ; Cursor up and down: step the walls' colour on screen. | |
| 203A | .check_cursor_up←2← 2029 BNE← 2033 BEQ |
| LDX #inkey_key_up ; Cursor up (INKEY -58)? | |
| 203C | JSR key_pressed ; ...(Z set if pressed) |
| 203F | BNE check_cursor_down ; Not pressed: try cursor down |
| 2041 | INC colour_10 ; Yes: walls' colour one up, to at most 7... |
| 2044 | LDA colour_10 ; ...read the new colour... |
| 2047 | CMP #8 ; ...past 7 (white)? |
| 2049 | BNE set_colour_up ; No: show the new colour |
| 204B | DEC colour_10 ; Yes: back to 7, white |
| 204E | .set_colour_up←1← 2049 BNE |
| JSR set_colour_10 ; Show the walls in colour_10's colour | |
| 2051 | .wait_up_released←1← 2056 BEQ |
| LDX #inkey_key_up ; Wait for cursor up to be released... | |
| 2053 | JSR key_pressed ; ...(Z set while held) |
| 2056 | BEQ wait_up_released ; Still held: keep waiting, one step a press |
| 2058 | .check_cursor_down←1← 203F BNE |
| LDX #inkey_key_down ; Cursor down (INKEY -42)? | |
| 205A | JSR key_pressed ; ...(Z set if pressed) |
| 205D | BNE check_item_keys ; Not pressed: on to the item keys |
| 205F | DEC colour_10 ; Yes: walls' colour one down, to at least 1... |
| 2062 | BNE set_colour_down ; Still 1 or more: show the new colour |
| 2064 | INC colour_10 ; Down to 0 (black): back to 1, red |
| 2067 | .set_colour_down←1← 2062 BNE |
| JSR set_colour_10 ; Show the walls in colour_10's colour | |
| 206A | .wait_down_released←1← 206F BEQ |
| LDX #inkey_key_down ; Wait for cursor down to be released... | |
| 206C | JSR key_pressed ; ...(Z set while held) |
| 206F | BEQ wait_down_released ; Still held: keep waiting, one step a press |
| ; '1' and '2': choose the item. | |
| 2071 | .check_item_keys←1← 205D BNE |
| JSR show_cursor_position ; Print the cursor's x and y beside the map | |
| 2074 | LDX #inkey_key_1 ; '1': the previous item? |
| 2076 | JSR key_pressed ; ...(Z set if pressed) |
| 2079 | BNE check_next_item ; Not pressed: try '2' |
| 207B | DEC current_item ; Yes: the previous item, to at least 0 |
| 207D | BPL check_space ; Still 0 or more: on to SPACE |
| 207F | LDA #0 ; Below item 0: stay at item 0... |
| 2081 | STA current_item ; ...the wall, the first item |
| 2083 | BEQ check_space ; On to SPACE (always branches) |
| 2085 | .check_next_item←1← 2079 BNE |
| LDX #inkey_key_2 ; '2': the next item? | |
| 2087 | JSR key_pressed ; ...(Z set if pressed) |
| 208A | BNE check_space ; Not pressed: on to SPACE |
| 208C | INC current_item ; Yes: the next item, to at most &0F |
| 208E | LDA current_item ; ...read the new item... |
| 2090 | CMP #spr_blank ; ...past the last item, the key (&0F)? |
| 2092 | BNE check_space ; No: keep the new item |
| 2094 | DEC current_item ; Yes: back to the key |
| ; SPACE: place the item. | |
| 2096 | .check_space←4← 207D BPL← 2083 BEQ← 208A BNE← 2092 BNE |
| LDX #inkey_key_space ; SPACE: place the item? | |
| 2098 | JSR key_pressed ; ...(Z set if pressed) |
| 209B | BNE check_tab ; Not pressed: try TAB |
| 209D | LDA current_item ; Placing walls (item 0)? |
| 209F | BNE place_not_edge ; No: an item, which may not go on the edge |
| 20A1 | JSR place_item ; Yes: place a wall, anywhere |
| 20A4 | JMP edit_loop ; Next pass: walls repeat while SPACE is held |
| 20A7 | .place_not_edge←1← 209F BNE |
| LDA cursor_x ; Other items: not on the edges, which are walled... | |
| 20A9 | BEQ next_pass ; Column 0: refuse |
| 20AB | CMP #map_width - 1 ; ...the right-hand column? |
| 20AD | BEQ next_pass ; Yes: refuse |
| 20AF | LDA cursor_y ; ...the top row... |
| 20B1 | BEQ next_pass ; Row 0: refuse |
| 20B3 | CMP #map_height - 1 ; ...or the bottom row? |
| 20B5 | BEQ next_pass ; Yes: refuse |
| 20B7 | JSR place_item ; Place the item, within its limits |
| 20BA | JSR show_counts ; Update the counts beside the map |
| 20BD | .wait_space_released←1← 20C6 BNE |
| LDX #inkey_key_space ; Wait for SPACE to be released... | |
| 20BF | JSR key_pressed ; ...(Z set while held) |
| 20C2 | BNE check_tab ; Released: on to TAB |
| 20C4 | LDA current_item ; ...an item, never walls, is chosen here... |
| 20C6 | BNE wait_space_released ; ...so keep waiting: one item per press |
| ; TAB: delete what is under the cursor. | |
| 20C8 | .check_tab←2← 209B BNE← 20C2 BNE |
| LDX #inkey_key_tab ; TAB: delete the cell's contents? | |
| 20CA | JSR key_pressed ; ...(Z set if pressed) |
| 20CD | BNE check_ctrl ; Not pressed: try CTRL |
| 20CF | JSR delete_item ; Yes: delete what is under the cursor... |
| 20D2 | JSR show_counts ; ...and update the counts |
| 20D5 | .wait_b_released←1← 20DE BNE |
| LDX #inkey_key_b ; Wait while B (not TAB) is held, with an item chosen... | |
| 20D7 | JSR key_pressed ; ...(Z set while held) |
| 20DA | BNE check_ctrl ; B not held: on to CTRL |
| 20DC | LDA current_item ; ...is an item chosen? |
| 20DE | BNE wait_b_released ; Yes: keep waiting while B is held |
| ; CTRL: show the door-key links while held. | |
| 20E0 | .check_ctrl←2← 20CD BNE← 20DA BNE |
| LDX #inkey_key_ctrl ; CTRL: show the links? | |
| 20E2 | JSR key_pressed ; ...(Z set if pressed) |
| 20E5 | BNE next_pass ; Not pressed: next pass |
| 20E7 | JSR draw_links ; Yes: draw the door-key links... |
| 20EA | .wait_ctrl_released←1← 20EF BEQ |
| LDX #inkey_key_ctrl ; ...and leave them while CTRL is held... | |
| 20EC | JSR key_pressed ; ...(Z set while held) |
| 20EF | BEQ wait_ctrl_released ; Still held: keep the lines showing |
| 20F1 | JSR draw_links ; ...then draw them again, which erases them |
| 20F4 | .next_pass←5← 20A9 BEQ← 20AD BEQ← 20B1 BEQ← 20B5 BEQ← 20E5 BNE |
| JMP edit_loop ; Next pass of the editing loop | |
Check that every door has its keyOne of the edit loop's three tests before SHIFT+S may save. Count the door-key links in use and compare with door_count. A link is made only when a key is placed for a waiting door, and a door can be linked only once, so equal counts mean that no door lacks its key. A door still waiting for its key is counted in door_count but has no link, so it blocks saving.
|
||||||||||
| 20F7 | .check_door_keys←1← 1FF4 JSR | |||||||||
| LDA #0 ; Count the links in use... | ||||||||||
| 20F9 | STA scratch ; ...in scratch, from 0... | |||||||||
| 20FB | LDX #max_link ; ...over links 19 to 0 | |||||||||
| 20FD | .count_links←1← 2105 BPL | |||||||||
| LDA link_door,x ; This link's door slot... | ||||||||||
| 2100 | BMI next_link ; ...&FF (negative): the link is free | |||||||||
| 2102 | INC scratch ; In use: one more door with its key | |||||||||
| 2104 | .next_link←1← 2100 BMI | |||||||||
| DEX ; Next link down | ||||||||||
| 2105 | BPL count_links ; ...until all 20 are counted | |||||||||
| 2107 | LDA scratch ; Links in use, one per door with a key... | |||||||||
| 2109 | CMP door_count ; ...against the doors placed: Z set if equal | |||||||||
| 210B | RTS ; Return with Z set if every door has its key | |||||||||
Test a keyThe edit loop's key test, for its fixed keys (f0, SHIFT+S, cursor up and down, '1', '2', SPACE, TAB, B and CTRL): OSBYTE &81 with the negative INKEY number in X, which returns X = Y = &FF while the key is held. move_cursor uses the same test in cursor_key_pressed, and the wall-block chooser in chooser_key_pressed.
|
|||||||||||||
| 210C | .key_pressed←16← 1FCE JSR← 1FDD JSR← 1FE4 JSR← 1FEB JSR← 203C JSR← 2053 JSR← 205A JSR← 206C JSR← 2076 JSR← 2087 JSR← 2098 JSR← 20BF JSR← 20CA JSR← 20D7 JSR← 20E2 JSR← 20EC JSR | ||||||||||||
| LDA #osbyte_inkey ; OSBYTE &81: scan the key... | |||||||||||||
| 210E | LDY #&ff ; ...Y = &FF: test the key whose INKEY number is X | ||||||||||||
| 2110 | JSR osbyte ; Scan it: X = Y = &FF if the key is held Test whether the key with negative INKEY number X is pressed | ||||||||||||
| 2113 | CPY #&ff ; Z set if X and Y are both &FF | ||||||||||||
| 2115 | BNE key_pressed_done ; Y not &FF: not pressed (Z clear) | ||||||||||||
| 2117 | CPX #&ff ; ...Z set if X is &FF too: pressed | ||||||||||||
| 2119 | .key_pressed_done←1← 2115 BNE | ||||||||||||
| RTS ; Return with Z set if the key is held | |||||||||||||
Ask for disc or tapeAsk 'Disc or tape' and select the filing system the level file is loaded from or saved to: for disc, *DISC and then *DRIVE with the digit (0-3) typed at the drive prompt; for tape, *TAPE. Called by edit_level before a level is loaded, by save_level before the filename, and by catalogue before *CAT. The edit loop selects *DISC and *DRIVE 0 itself before saving, for Stones, so the choice made here comes after it.
|
||||||||
| 211A | .choose_filing_system←3← 1C93 JSR← 2364 JSR← 23EA JSR | |||||||
| LDX #<(disc_or_tape_prompt) ; Ask: disc (D) or tape (T) | ||||||||
| 211C | LDY #>(disc_or_tape_prompt) ; ...(the prompt's high byte) | |||||||
| 211E | LDA #&32 ; ...first answer: D (internal key &32)... | |||||||
| 2120 | STA scratch ; ...ask_key's first key | |||||||
| 2122 | LDA #&23 ; ...second answer: T (internal key &23) | |||||||
| 2124 | STA scratch_hi ; ...ask_key's second key | |||||||
| 2126 | LDA #0 ; ...A = 0: one of two keys | |||||||
| 2128 | JSR ask_key ; ...ask, A = 0 for D or 1 for T | |||||||
| 212B | BNE choose_tape ; T: tape | |||||||
| 212D | LDX #<(disc_command) ; D: select disc with *DISC... | |||||||
| 212F | LDY #>(disc_command) ; ...(the command's high byte) | |||||||
| 2131 | JSR oscli ; ...select the disc filing system | |||||||
| 2134 | JSR new_lines ; New line under the answer | |||||||
| 2137 | LDX #<(drive_prompt) ; Ask which drive... | |||||||
| 2139 | LDY #>(drive_prompt) ; ...(the prompt's high byte) | |||||||
| 213B | LDA #1 ; ...A = 1: answer with a drive digit | |||||||
| 213D | JSR ask_key ; ...ask, A = the digit typed | |||||||
| 2140 | STA drive_digit ; ...and put the digit in drive_command | |||||||
| 2143 | LDX #<(drive_command) ; *DRIVE n | |||||||
| 2145 | LDY #>(drive_command) ; ...(the command's high byte) | |||||||
| 2147 | JSR oscli ; ...select that drive | |||||||
| 214A | RTS ; Return with the disc and drive selected | |||||||
| 214B | .choose_tape←1← 212B BNE | |||||||
| LDX #<(tape_command) ; T: select tape with *TAPE... | ||||||||
| 214D | LDY #>(tape_command) ; ...(the command's high byte) | |||||||
| 214F | JSR oscli ; ...select the cassette filing system | |||||||
| 2152 | RTS ; Return with the tape selected | |||||||
Set up the editing screenSend edit_screen_vdu's &21 bytes, once start_editing has selected MODE 2: turn the text cursor off (6845 register 10), display 30 character rows (register 6), the map's 48 rows of five pixel rows needing 240, and set logical colours 10 and 9 to red and yellow. Hiding the rows from &7B00 up leaves &7B00-&7FFF free for unpack_level, mark_object_cell and object_free_map.
|
||||||||
| 2153 | .set_edit_screen←1← 1ED5 JSR | |||||||
| LDX #0 ; Send its &21 bytes | ||||||||
| 2155 | .send_edit_screen←1← 215E BNE | |||||||
| LDA edit_screen_vdu,x ; Next byte of the VDU commands... | ||||||||
| 2158 | JSR oswrch ; ...sent to the VDU drivers | |||||||
| 215B | INX ; ...on to the next byte | |||||||
| 215C | CPX #edit_screen_vdu_end - edit_screen_vdu ; ...all &21 sent? | |||||||
| 215E | BNE send_edit_screen ; No: send the next | |||||||
| 2160 | RTS ; Return with the edit screen set up | |||||||
Encrypt or decrypt the level fileExclusive-OR each byte of the level file, &2700-&29AF, with the low byte of its offset, which is that of its address, as the game's decrypt_level does at &6B00. Doing it twice restores the bytes. start_editing calls it to decrypt a level once loaded; save_level calls it to encrypt the level after setting the checksum, first decrypting it when an earlier save in this session left it encrypted (level_encrypted).
|
||||||||
| 2161 | .crypt_level←3← 1F34 JSR← 230C JSR← 235C JSR | |||||||
| LDA #0 ; Point at &2700, X counting the offset... | ||||||||
| 2163 | TAX ; ...X = 0: the offset within the level | |||||||
| 2164 | TAY ; ...Y = 0: scratch itself steps | |||||||
| 2165 | STA scratch ; ...scratch = &2700: page &27's start... | |||||||
| 2167 | LDA #>(level_object_x) ; ...page &27, the level file | |||||||
| 2169 | STA scratch_hi ; ...as scratch's high byte | |||||||
| 216B | .crypt_byte←2← 217E BNE← 2184 BNE | |||||||
| LDA (scratch),y ; Exclusive-OR the byte with the offset's low byte... | ||||||||
| 216D | STX screen_ptr ; ...the offset's low byte, as the key... | |||||||
| 216F | EOR screen_ptr ; ...applied: XOR again undoes it | |||||||
| 2171 | INX ; ...next offset | |||||||
| 2172 | STA (scratch),y ; ...put the byte back | |||||||
| 2174 | INC scratch ; Step scratch to the next byte | |||||||
| 2176 | BNE crypt_check_end ; No page crossed | |||||||
| 2178 | INC scratch_hi ; ...into the next page of the level | |||||||
| 217A | .crypt_check_end←1← 2176 BNE | |||||||
| LDA scratch ; Until &29B0, the level file's end | ||||||||
| 217C | CMP #<(level_file_end) ; ...the low byte of &29B0? | |||||||
| 217E | BNE crypt_byte ; No: next byte | |||||||
| 2180 | LDA scratch_hi ; ...and the high byte? | |||||||
| 2182 | CMP #>(level_file_end) ; ...&29B0's high byte? | |||||||
| 2184 | BNE crypt_byte ; No: next byte | |||||||
| 2186 | RTS ; Return with all &2B0 bytes flipped | |||||||
Show the walls in the chosen colourVDU 19,10,n,0,0,0 with n from colour_10 (1-7). Logical colour 10 is what the wall sprite (all &CC bytes) and the cursor sprite are drawn in, so this changes the walls' colour on the screen, not in the level. The edit loop calls it after cursor up or down changes colour_10.
|
|||||||||||
| 2187 | .set_colour_10←2← 204E JSR← 2067 JSR | ||||||||||
| LDA #&13 ; VDU 19,10,n,0,0,0... | |||||||||||
| 2189 | JSR oswrch ; ...send VDU 19, redefine a logical colour | ||||||||||
| 218C | LDA #&0a ; ...logical colour 10, the walls'... | ||||||||||
| 218E | JSR oswrch ; ...send the logical colour | ||||||||||
| 2191 | LDA colour_10 ; ...physical colour n from colour_10... | ||||||||||
| 2194 | JSR oswrch ; ...send the physical colour | ||||||||||
| 2197 | LDA #0 ; ...then three zeros to end VDU 19 | ||||||||||
| 2199 | JSR oswrch ; ...send the first zero | ||||||||||
| 219C | JSR oswrch ; ...send the second zero | ||||||||||
| 219F | JSR oswrch ; ...send the third zero | ||||||||||
| 21A2 | RTS ; Return with the walls' colour changed | ||||||||||
Print the counts' labelsIn colour 1, at column 16 beside the map, on rows 0, 4 and 8: Objs, Mons (the trapdoors, where monsters appear) and Dors, each above its count. count_labels holds the VDU 31 moves with the text. Leaves colour 7 set for show_counts, which start_editing calls next.
|
||||||||
| 21A3 | .show_labels←2← 1F50 JSR← 1F9A JSR | |||||||
| LDA #&11 ; COLOUR 1, red, for the labels... | ||||||||
| 21A5 | JSR oswrch ; ...send VDU 17, COLOUR | |||||||
| 21A8 | LDA #1 ; ...colour 1, red | |||||||
| 21AA | JSR oswrch ; ...send the colour | |||||||
| 21AD | LDX #0 ; Print count_labels up to its CR | |||||||
| 21AF | .print_labels←1← 21B8 BNE | |||||||
| LDA count_labels,x ; Next label character... | ||||||||
| 21B2 | JSR oswrch ; ...or VDU 31 byte, printed | |||||||
| 21B5 | INX ; ...on to the next byte | |||||||
| 21B6 | CMP #&0d ; ...the CR at the end? | |||||||
| 21B8 | BNE print_labels ; No: print the next | |||||||
| 21BA | LDA #&11 ; COLOUR 7, white, for the counts... | |||||||
| 21BC | JSR oswrch ; ...send VDU 17, COLOUR | |||||||
| 21BF | LDA #7 ; ...colour 7, white | |||||||
| 21C1 | JSR oswrch ; ...send the colour | |||||||
| 21C4 | RTS ; Return with colour 7 set for the counts | |||||||
Print the countsObjects at (17, 2), trapdoors at (17, 6) and doors at (17, 10), each under its label, as two digits in the text colour show_labels left. Called by start_editing and after each SPACE (an item, not a wall) or TAB in the edit loop.
|
||||||||
| 21C5 | .show_counts←4← 1F53 JSR← 1F9D JSR← 20BA JSR← 20D2 JSR | |||||||
| LDX #&11 ; Objects at text column 17... | ||||||||
| 21C7 | LDY #2 ; ...row 2, under Objs | |||||||
| 21C9 | LDA object_count ; ...the number of objects placed | |||||||
| 21CB | JSR print_number ; ...printed as two digits | |||||||
| 21CE | LDX #&11 ; Trapdoors at text column 17... | |||||||
| 21D0 | LDY #6 ; ...row 6, under Mons | |||||||
| 21D2 | LDA trapdoor_count ; ...the number of trapdoors placed | |||||||
| 21D4 | JSR print_number ; ...printed as two digits | |||||||
| 21D7 | LDX #&11 ; Doors at text column 17... | |||||||
| 21D9 | LDY #&0a ; ...row 10, under Dors | |||||||
| 21DB | LDA door_count ; ...the number of doors placed | |||||||
| 21DD | JSR print_number ; ...printed as two digits | |||||||
| 21E0 | RTS ; Return with the three counts shown | |||||||
Print the cursor's cellx at (17, 20) and y at (17, 21), beside the map. The edit loop calls it every pass, after the cursor and colour keys.
|
|||||||||||||
| 21E1 | .show_cursor_position←1← 2071 JSR | ||||||||||||
| LDX #&11 ; The cursor's x at text column 17... | |||||||||||||
| 21E3 | LDY #&14 ; ...row 20 | ||||||||||||
| 21E5 | LDA cursor_x ; ...the cursor's column, 0-31 | ||||||||||||
| 21E7 | JSR print_number ; ...printed as two digits | ||||||||||||
| 21EA | LDX #&11 ; The cursor's y at text column 17... | ||||||||||||
| 21EC | LDY #&15 ; ...row 21 | ||||||||||||
| 21EE | LDA cursor_y ; ...the cursor's row, 0-47 | ||||||||||||
| 21F0 | JSR print_number ; ...printed as two digits | ||||||||||||
| 21F3 | RTS ; Return with the cursor's cell shown | ||||||||||||
Print a two-digit number at a text positionMove the text cursor to (X, Y) with VDU 31 and print A (0-99) as two digits, a leading zero included. The tens are counted by repeated subtraction of 10. show_counts and show_cursor_position use it.
|
|||||||||||||||||
| 21F4 | .print_number←5← 21CB JSR← 21D4 JSR← 21DD JSR← 21E7 JSR← 21F0 JSR | ||||||||||||||||
| STA scratch ; Keep the number in scratch | |||||||||||||||||
| 21F6 | TYA ; Keep the position for VDU 31... | ||||||||||||||||
| 21F7 | PHA ; ...the row pushed first... | ||||||||||||||||
| 21F8 | TXA ; ...then the column... | ||||||||||||||||
| 21F9 | PHA ; ...on top, to be sent first | ||||||||||||||||
| 21FA | LDA scratch ; Tens: count the 10s... | ||||||||||||||||
| 21FC | SEC ; ...C set for the subtractions | ||||||||||||||||
| 21FD | LDX #0 ; ...X counts them | ||||||||||||||||
| 21FF | .count_tens←1← 2204 BNE | ||||||||||||||||
| SBC #&0a ; Take away 10... | |||||||||||||||||
| 2201 | BCC tens_counted ; ...gone below 0: X is the tens digit | ||||||||||||||||
| 2203 | INX ; ...one more ten | ||||||||||||||||
| 2204 | BNE count_tens ; ...and again (always branches) | ||||||||||||||||
| 2206 | .tens_counted←1← 2201 BCC | ||||||||||||||||
| SEC ; Units: add the last 10 back | |||||||||||||||||
| 2207 | SBC #&f6 ; ...(A - &F6 = A + 10) | ||||||||||||||||
| 2209 | TAY ; ...Y = the units | ||||||||||||||||
| 220A | LDA #&1f ; VDU 31, column, row: move the text cursor | ||||||||||||||||
| 220C | JSR oswrch ; ...send VDU 31 | ||||||||||||||||
| 220F | PLA ; ...the column, from the stack | ||||||||||||||||
| 2210 | JSR oswrch ; ...send the column | ||||||||||||||||
| 2213 | PLA ; ...the row, from the stack | ||||||||||||||||
| 2214 | JSR oswrch ; ...send the row | ||||||||||||||||
| 2217 | TXA ; Tens digit from X... | ||||||||||||||||
| 2218 | CLC ; ...C clear for the addition | ||||||||||||||||
| 2219 | ADC #'0' ; ...as an ASCII digit | ||||||||||||||||
| 221B | JSR oswrch ; ...printed, the first digit | ||||||||||||||||
| 221E | TYA ; Units digit (C clear) | ||||||||||||||||
| 221F | ADC #'0' ; ...as an ASCII digit | ||||||||||||||||
| 2221 | JSR oswrch ; ...printed after the tens | ||||||||||||||||
| 2224 | RTS ; Return with both digits printed | ||||||||||||||||
Put walls round the edge of the mapPlace a wall in every cell of columns 0 and 31 and rows 0 and 47, closing the map on every side. The edit loop calls it first when SHIFT+S saves, before pack_level. Each goes through place_item, which leaves a cell that already holds a wall alone and otherwise clears its object-free bit too (put_item). Items cannot be placed on the edge, so every edge cell ends up a wall, except that place_item takes the top-left cell, (0, 0), for a wall already whenever a slot is free (see item_at_cursor), so that cell's wall bit is left to save_level. It leaves cursor_x at &FF, cursor_y at 47 and the current item the wall, which no later code relies on: save_level never returns to the edit loop.
|
||||||||||||||
| 2225 | .wall_edges←1← 200D JSR | |||||||||||||
| LDA #0 ; The wall, item 0... | ||||||||||||||
| 2227 | STA current_item ; ...as the item place_item puts down | |||||||||||||
| 2229 | LDA #map_height - 1 ; First the side columns, for rows 47 to 0... | |||||||||||||
| 222B | STA cursor_y ; ...moving the cursor to each in turn | |||||||||||||
| 222D | .wall_left_right←1← 223D BPL | |||||||||||||
| LDA #0 ; ...in column 0... | ||||||||||||||
| 222F | STA cursor_x ; ...the left edge | |||||||||||||
| 2231 | JSR place_item ; ...walled in | |||||||||||||
| 2234 | LDA #map_width - 1 ; ...and column 31... | |||||||||||||
| 2236 | STA cursor_x ; ...the right edge | |||||||||||||
| 2238 | JSR place_item ; ...walled in | |||||||||||||
| 223B | DEC cursor_y ; ...one row up | |||||||||||||
| 223D | BPL wall_left_right ; ...until row 0 is done | |||||||||||||
| ; Then the top and bottom rows. | ||||||||||||||
| 223F | LDA #map_width - 1 ; For columns 31 to 0... | |||||||||||||
| 2241 | STA cursor_x ; ...moving the cursor to each in turn | |||||||||||||
| 2243 | .wall_top_bottom←1← 2253 BPL | |||||||||||||
| LDA #0 ; ...in row 0... | ||||||||||||||
| 2245 | STA cursor_y ; ...the top edge | |||||||||||||
| 2247 | JSR place_item ; ...walled in | |||||||||||||
| 224A | LDA #map_height - 1 ; ...and row 47... | |||||||||||||
| 224C | STA cursor_y ; ...the bottom edge | |||||||||||||
| 224E | JSR place_item ; ...walled in | |||||||||||||
| 2251 | DEC cursor_x ; ...one column left | |||||||||||||
| 2253 | BPL wall_top_bottom ; ...until column 0 is done | |||||||||||||
| 2255 | RTS ; Return with the map walled in | |||||||||||||
BREAK intercept: back to savingsave_level points the MOS BREAK intercept here, so that BREAK while saving does not lose the level. The MOS calls the intercept twice during a reset; on the second call, with C set, go back to save_level's start, with the packed level still at &2700. level_encrypted says whether it was already encrypted, so save_level decrypts it before summing again. |
|
| ; BREAK intercept while saving: on the second call (C set) go ; back to save_level's prompt. | |
| 2256 | .break_to_save |
| BCS save_level ; Second call (after the reset)? Save again | |
| 2258 | RTS ; First call: return to the MOS's reset |
Save the levelThe last step of SHIFT+S: the edit loop has walled the map in, packed the slots and maps into the level file at &2700 and copied in the chosen wall block, then selected MODE 7. save_level also restarts itself: break_to_save comes back here after BREAK, and a level number out of range asks again from the top. Point the BREAK intercept at break_to_save and BRKV at the reset entry, disable ESCAPE, and ask 'Level in the Dunjunz complex' for a number of up to two digits (RETURN alone: catalogue). Only 1-24 are accepted; level 25 is in Stones. The number only chooses the checksum, from the game's level_checksums: level_number is not read again, and the filename is typed separately, so a level saved under another level's filename fails the game's checksum test when it is loaded. Wall the top-left cell, then set the level's first byte (object entry 0's x, which the game never reads) so that the &2B0 bytes sum to the checksum modulo 256: the sum is taken with that byte 0, and the byte is checksum - sum. Both of the code's branches give that value. Encrypt the level with crypt_level, choose disc or tape, ask for the filename and *SAVE name 2700+2B0, then ask 'Another level (A) or quit (Q)'. It never returns: A restarts the editor at editor_init, and Q disarms the BREAK intercept and resets the machine. |
|
| 2259 | .save_level←5← 2020 JSR← 2256 BCS← 22D7 BEQ← 22EE JMP← 22F5 JMP |
| LDA #opcode_jmp ; BREAK intercept = JMP break_to_save... | |
| 225B | STA os_break_intercept ; ...so BREAK while saving comes back here |
| 225E | LDA #<(break_to_save) ; ...break_to_save's low byte... |
| 2260 | STA os_break_intercept_lo ; ...as the JMP's operand, low... |
| 2263 | LDA #>(break_to_save) ; ...and its high byte... |
| 2265 | STA os_break_intercept_hi ; ...as the JMP's operand, high |
| 2268 | LDA #<(mos320_reset_entry) ; BRKV = MOS 3.20's reset entry |
| 226A | STA brkv ; ...BRKV's low byte |
| 226D | LDA #>(mos320_reset_entry) ; ...the reset entry's high byte... |
| 226F | STA brkv + 1 ; ...high byte: an error resets the machine |
| 2272 | LDA #osbyte_escape_break_effect ; OSBYTE &C8 with X=1, Y=0: disable ESCAPE |
| 2274 | LDX #1 ; ...X = 1: ESCAPE does nothing |
| 2276 | LDY #0 ; ...Y = 0: replace the setting |
| 2278 | JSR osbyte ; Set it, so ESCAPE cannot stop the save osbyte: escape break effect |
| 227B | LDA #&0c ; VDU 12: clear the screen |
| 227D | JSR oswrch ; ...for the save prompts |
| ; Ask for the level number, up to two digits, '0'-'9' only. | |
| 2280 | .ask_level_number←1← 23FD JMP |
| LDA #osbyte_flush_buffer_class ; OSBYTE &0F: flush the buffers... | |
| 2282 | JSR osbyte ; Discard keys pressed before the level prompt Flush selected class of buffer |
| 2285 | LDX #0 ; Print the prompt, level_number_prompt... |
| 2287 | .print_level_prompt←1← 2290 BNE |
| LDA level_number_prompt,x ; Next prompt character... | |
| 228A | JSR oswrch ; ...printed on the screen |
| 228D | INX ; ...on to the next character |
| 228E | CMP #0 ; ...the zero at its end? |
| 2290 | BNE print_level_prompt ; No: print the next |
| 2292 | LDX #<(read_line_block) ; Point XY at read_line_block... |
| 2294 | LDY #>(read_line_block) ; ...(the block's high byte) |
| 2296 | LDA #'0' ; ...digits '0' '0' to start with... |
| 2298 | STA filename_buffer ; ...as the first digit |
| 229B | STA filename_buffer + 1 ; ...and the second |
| 229E | LDA #<(filename_buffer) ; ...line buffer filename_buffer... |
| 22A0 | STA read_line_block ; ...the buffer's low byte in the block |
| 22A3 | LDA #>(filename_buffer) ; ...and its high byte... |
| 22A5 | STA read_line_block + 1 ; ...in the block |
| 22A8 | LDA #2 ; ...at most two characters... |
| 22AA | STA read_line_block + 2 ; ...as the maximum length |
| 22AD | LDA #'0' ; ...characters '0' to '9' only... |
| 22AF | STA read_line_block + 3 ; ...lowest character accepted |
| 22B2 | LDA #'9' ; ...to '9'... |
| 22B4 | STA read_line_block + 4 ; ...highest character accepted |
| 22B7 | LDA #osword_read_line ; OSWORD 0: read a line |
| 22B9 | JSR osword ; Read the level number the user types Read line from input stream (exits with C=1 if ESCAPE pressed) |
| 22BC | CPY #0 ; Anything typed (Y = length)? |
| 22BE | BNE level_typed ; Yes: convert it |
| 22C0 | JMP catalogue ; RETURN alone: catalogue, then ask again |
| ; Convert the one or two digits typed to the level number. | |
| 22C3 | .level_typed←1← 22BE BNE |
| LDA filename_buffer + 1 ; Only one digit typed? | |
| 22C6 | CMP #&0d ; ...the second character a CR? |
| 22C8 | BNE two_digits ; No: two digits |
| 22CA | LDA filename_buffer ; Yes: the level is the digit |
| 22CD | SEC ; ...C set for the subtraction |
| 22CE | SBC #'0' ; ...ASCII to its value |
| 22D0 | BPL check_level_number ; ...(always branches: A is 0-9) |
| 22D2 | .two_digits←1← 22C8 BNE |
| LDA filename_buffer ; Two digits: tens x 10 + units... | |
| 22D5 | CMP #&0d ; ...a CR in the first place? |
| 22D7 | BEQ save_level ; Not taken (Y > 0); it would ask again |
| 22D9 | SEC ; ...C set for the subtraction |
| 22DA | SBC #'0' ; ...the tens digit's value... |
| 22DC | ASL ; ...x 2... |
| 22DD | STA scratch ; ...tens x 2, kept to add... |
| 22DF | ASL ; ...x 4... |
| 22E0 | ASL ; ...x 8... |
| 22E1 | CLC ; ...C clear for the addition |
| 22E2 | ADC scratch ; ...+ x 2: tens x 10 |
| 22E4 | ADC filename_buffer + 1 ; ...plus the units digit's ASCII... |
| 22E7 | SEC ; ...C set for the subtraction |
| 22E8 | SBC #'0' ; ...less the units digit's ASCII bias |
| ; Accept only levels 1 to 24, and take the checksum the game ; holds for that level. | |
| 22EA | .check_level_number←1← 22D0 BPL |
| CMP #0 ; Level 0, which does not exist? | |
| 22EC | BNE level_not_zero ; No: check the top |
| 22EE | JMP save_level ; Yes: ask again |
| 22F1 | .level_not_zero←1← 22EC BNE |
| CMP #max_level + 1 ; Level 25 or more? | |
| 22F3 | BCC level_number_ok ; No: 1-24, a level the game loads from a file |
| 22F5 | JMP save_level ; Yes: ask again |
| 22F8 | .level_number_ok←1← 22F3 BCC |
| STA level_number ; Keep the level number (never read again) | |
| 22FB | TAX ; ...X = level, to index the checksums |
| 22FC | LDA level_checksums - 1,x ; ...the game's checksum for that level... |
| 22FF | STA level_checksum ; ...which the level's bytes must sum to |
| 2302 | LDA #&0a ; Line feed under the number |
| 2304 | JSR oswrch ; ...sent to the screen |
| 2307 | LDA level_encrypted ; Saved already (so encrypted)? |
| 230A | BEQ set_checksum ; No: the level is still plain |
| 230C | JSR crypt_level ; Yes: decrypt it again |
| ; Make the level's bytes sum to its checksum, through the first ; byte, which the game never reads. | |
| 230F | .set_checksum←1← 230A BEQ |
| LDA level_walls ; Wall cell (0, 0), which wall_edges may have missed | |
| 2312 | ORA #&80 ; ...bit 7 of the wall map's first byte... |
| 2314 | STA level_walls ; ...set in the level file |
| 2317 | LDA #0 ; Sum the level's bytes, with the first byte 0... |
| 2319 | TAY ; ...Y = 0: scratch steps through the file |
| 231A | STA level_object_x ; ...first byte 0, so it adds nothing |
| 231D | STA screen_ptr ; ...the sum starts at 0 |
| 231F | STA scratch ; ...scratch at &2700, page-aligned... |
| 2321 | LDA #>(level_object_x) ; ...page &27, the level file |
| 2323 | STA scratch_hi ; ...as scratch's high byte |
| 2325 | .sum_level←2← 2336 BNE← 233C BNE |
| LDA (scratch),y ; Next byte of the level... | |
| 2327 | CLC ; ...C clear for the addition |
| 2328 | ADC screen_ptr ; ...added to the sum... |
| 232A | STA screen_ptr ; ...modulo 256 |
| 232C | INC scratch ; Step scratch to the next byte |
| 232E | BNE sum_check_end ; No page crossed |
| 2330 | INC scratch_hi ; ...into the next page |
| 2332 | .sum_check_end←1← 232E BNE |
| LDA scratch ; ...to &29AF, the file's last byte | |
| 2334 | CMP #<(level_file_end) ; ...the low byte of &29B0? |
| 2336 | BNE sum_level ; No: next byte |
| 2338 | LDA scratch_hi ; ...and the high byte? |
| 233A | CMP #>(level_file_end) ; ...&29B0's high byte? |
| 233C | BNE sum_level ; No: next byte |
| 233E | LDA screen_ptr ; First byte = checksum - sum (modulo 256)... |
| 2340 | CMP level_checksum ; ...compared with the checksum |
| 2343 | BCC sum_below ; Sum below the checksum |
| 2345 | SEC ; ...(sum above the checksum: &FF - sum + checksum + 1)... |
| 2346 | LDA #&ff ; ...starting from &FF... |
| 2348 | SBC screen_ptr ; ...less the sum... |
| 234A | CLC ; ...C clear for the addition |
| 234B | ADC level_checksum ; ...plus the checksum... |
| 234E | ADC #1 ; ...plus 1: checksum - sum + 256 |
| 2350 | JMP store_first_byte ; ...stored as the first byte |
| 2353 | .sum_below←1← 2343 BCC |
| SEC ; ...(otherwise checksum - sum) | |
| 2354 | LDA level_checksum ; ...the level's checksum... |
| 2357 | SBC screen_ptr ; ...less the sum |
| 2359 | .store_first_byte←1← 2350 JMP |
| STA level_object_x ; ...so that the level's sum is its checksum | |
| ; Encrypt the level, then save it under the filename typed. | |
| 235C | JSR crypt_level ; Encrypt the level for the game |
| 235F | LDA #1 ; Mark it encrypted |
| 2361 | STA level_encrypted ; ...so a second save decrypts it first |
| 2364 | JSR choose_filing_system ; Choose disc or tape |
| 2367 | LDA #' ' ; Blank the filename in save_command... |
| 2369 | LDX #5 ; ...offset 5, where the name goes... |
| 236B | .blank_save_name←1← 2371 BNE |
| STA save_command,x ; ...a space in each place... | |
| 236E | INX ; ...on to the next character |
| 236F | CPX #&0c ; ...up to offset 11? |
| 2371 | BNE blank_save_name ; No: blank the next |
| 2373 | JSR ask_filename ; Ask for the filename |
| 2376 | LDA #&0a ; Line feed under the name |
| 2378 | JSR oswrch ; ...sent to the screen |
| 237B | LDX #0 ; Copy it into save_command... |
| 237D | .copy_save_name←1← 2386 BNE |
| LDA filename_buffer,x ; Next filename character... | |
| 2380 | STA save_command + 5,x ; ...into the command |
| 2383 | INX ; ...on to the next character |
| 2384 | CPX scratch ; ...all the characters typed? |
| 2386 | BNE copy_save_name ; No: copy the next |
| 2388 | LDX #<(save_command) ; *SAVE name 2700+2B0 |
| 238A | LDY #>(save_command) ; ...(the command's high byte) |
| 238C | JSR oscli ; ...save the level file |
| 238F | LDA #&0a ; Line feed under *SAVE's output |
| 2391 | JSR oswrch ; ...sent to the screen |
| ; Another level, or quit. | |
| 2394 | LDX #<(another_prompt) ; Ask: another level (A) or quit (Q) |
| 2396 | LDY #>(another_prompt) ; ...(the prompt's high byte) |
| 2398 | LDA #&41 ; ...first answer: A (internal key &41)... |
| 239A | STA scratch ; ...ask_key's first key |
| 239C | LDA #&10 ; ...second answer: Q (internal key &10) |
| 239E | STA scratch_hi ; ...ask_key's second key |
| 23A0 | LDA #0 ; ...A = 0: one of two keys |
| 23A2 | JSR ask_key ; ...ask, A = 0 for A or 1 for Q |
| 23A5 | BNE quit ; Q: quit |
| 23A7 | JMP editor_init ; A: restart the editor for another level |
| 23AA | .quit←1← 23A5 BNE |
| LDA #0 ; Quit: disable the BREAK intercept... | |
| 23AC | STA os_break_intercept ; ...so the reset starts the machine afresh |
| 23AF | JMP (reset_vector) ; ...and reset the machine |
*EDITOR: copy the plotter page and startThe program's entry point, run once by *EDITOR. Copy &2700-&28FF to &0900-&0AFF (the plotter, screen_address, the packed counts, the item types and checksums, and the sprite tables), freeing &2700-&29AF for the level file, then start at editor_init. A restart (BREAK, or another level after saving) goes to editor_init directly, as the copy has been overwritten by then. |
|
| 23B2 | .editor_start |
| LDX #0 ; Copy &2700-&27FF to &0900... | |
| 23B4 | .copy_plotter_lo←1← 23BB BNE |
| LDA plotter_image,x ; Next byte of the stored plotter page... | |
| 23B7 | STA plot_sprite,x ; ...to its run address |
| 23BA | DEX ; ...on to the next byte |
| 23BB | BNE copy_plotter_lo ; ...until all 256 are copied |
| 23BD | .copy_plotter_hi←1← 23C4 BNE |
| LDA plotter_image_page_2,x ; ...and &2800-&28FF to &0A00 | |
| 23C0 | STA sprite_addr_lo,x ; ...to its run address |
| 23C3 | DEX ; ...on to the next byte |
| 23C4 | BNE copy_plotter_hi ; ...until all 256 are copied |
| 23C6 | JMP editor_init ; Set up and ask: edit a level or a new one |
Catalogue the disc or tapeReached from save_level when RETURN is pressed with no level number, so that the user can see which level files exist before choosing one. Show CAT after the prompt, as if it had been typed as the answer, choose disc or tape, *CAT, show the disc's free space with Table's routine, then ask for the level number again at ask_level_number, below the catalogue, without clearing the screen. |
|
| 23C9 | .catalogue←1← 22C0 JMP |
| LDA #&0b ; VDU 11: up a line... | |
| 23CB | JSR oswrch ; ...back onto the prompt's line |
| 23CE | LDA #9 ; ...and VDU 9, right past its 29 characters... |
| 23D0 | LDX #&1d ; ...29 times, counted in X... |
| 23D2 | .move_right_29←1← 23D6 BNE |
| JSR oswrch ; ...one place right... | |
| 23D5 | DEX ; ...one fewer place to move |
| 23D6 | BNE move_right_29 ; ...until all 29 are done |
| 23D8 | LDA #'C' ; ...and show CAT as the answer: 'C'... |
| 23DA | JSR oswrch ; ...'C' printed... |
| 23DD | LDA #'A' ; ...then the 'A'... |
| 23DF | JSR oswrch ; ...'A' printed... |
| 23E2 | LDA #'T' ; ...then the 'T'... |
| 23E4 | JSR oswrch ; ...'T' printed |
| 23E7 | JSR new_lines ; New line under CAT |
| 23EA | JSR choose_filing_system ; Choose disc or tape |
| 23ED | JSR new_lines ; New line under the answer |
| 23F0 | LDX #<(cat_command) ; *CAT, the filing system's catalogue... |
| 23F2 | LDY #>(cat_command) ; ...(the command's high byte) |
| 23F4 | JSR oscli ; ...list the files |
| 23F7 | JSR show_free_space ; Show the free space (Table's *FREE) |
| 23FA | JSR new_lines ; New line under the catalogue |
| 23FD | JMP ask_level_number ; Ask for the level number again |
Choose the level's wall blockLet the user pick the picture the game draws every wall of the level with. Called from the edit loop when SHIFT+S saves, after pack_level and with drive 0 selected; save_level follows. Clear the screen, show only 25 character rows, load Stones (the 24 wall blocks) at &6E80, just below them, draw the blocks in a grid four wide and six high and frame block 0. Then loop: pause for a delay loop of about 25,000 iterations, read the keys (move_chooser: ',' '.' one block, 'A' 'Z' a row) and, when the choice moved, wait for the frame and move the frame round. SPACE copies the chosen block's &30 bytes from Stones into the level file's wall block and returns. The editing screen is not restored, as save_level selects MODE 7 next.
|
||||||||||
| 2400 | .choose_wall_block←1← 2013 JSR | |||||||||
| LDA #&0c ; VDU 12: clear the screen | ||||||||||
| 2402 | JSR oswrch ; ...of the edited map | |||||||||
| 2405 | JSR show_25_rows ; Show 25 rows, hiding &6E80 on, where Stones goes | |||||||||
| 2408 | JSR load_stones ; Load Stones at &6E80 | |||||||||
| 240B | NOP ; NOP: no effect | |||||||||
| 240C | NOP ; NOP: no effect | |||||||||
| 240D | NOP ; NOP: no effect | |||||||||
| 240E | NOP ; NOP: no effect | |||||||||
| 240F | LDA #0 ; Block 0 chosen... | |||||||||
| 2411 | STA chosen_block ; ...to start with | |||||||||
| 2414 | JSR draw_wall_blocks ; Draw the 24 blocks | |||||||||
| 2417 | LDA #spr_chooser_frame ; Frame block 0... | |||||||||
| 2419 | JSR frame_block ; ...drawing the frame round it | |||||||||
| ; Pause, read the keys, and take the block when SPACE is ; pressed. | ||||||||||
| 241C | .chooser_loop←2← 2471 BEQ← 2490 JMP | |||||||||
| LDX #&64 ; Pause for 100 x 255 loops... | ||||||||||
| 241E | .chooser_pause←1← 2424 BNE | |||||||||
| LDY #&ff ; ...255 inner loops each... | ||||||||||
| 2420 | .chooser_pause_inner←1← 2421 BNE | |||||||||
| DEY ; ...one inner loop fewer... | ||||||||||
| 2421 | BNE chooser_pause_inner ; ...until the inner count is 0 | |||||||||
| 2423 | DEX ; ...one outer loop fewer... | |||||||||
| 2424 | BNE chooser_pause ; ...until 0: slow enough to steer | |||||||||
| 2426 | JSR move_chooser ; Read the movement keys | |||||||||
| 2429 | LDX #inkey_key_space ; SPACE: take this block? | |||||||||
| 242B | JSR chooser_key_pressed ; ...(Z set if pressed) | |||||||||
| 242E | BNE chooser_moved ; Not pressed: redraw if the choice moved | |||||||||
| ; SPACE: copy block chosen_block, at &6E80 + block x &30, into ; the level file. | ||||||||||
| 2430 | LDA #0 ; Yes: the block's address, &6E80 + block x &30... | |||||||||
| 2432 | STA plot_y ; ...high byte, in plot_y, starts at 0 | |||||||||
| 2434 | LDA chosen_block ; ...the chosen block number... | |||||||||
| 2437 | ASL ; ...x 2... | |||||||||
| 2438 | ASL ; ...x 4... | |||||||||
| 2439 | ASL ; ...x 8... | |||||||||
| 243A | ASL ; ...x 16, the carry... | |||||||||
| 243B | ROL plot_y ; ...into the high byte | |||||||||
| 243D | STA scratch ; ...block x 16, low byte... | |||||||||
| 243F | LDA plot_y ; ...and block x 16's high byte... | |||||||||
| 2441 | STA scratch_hi ; ...kept in scratch_hi | |||||||||
| 2443 | LDA scratch ; ...block x 16 again... | |||||||||
| 2445 | ASL ; ...x 2: block x 32... | |||||||||
| 2446 | ROL plot_y ; ...carry into the high byte | |||||||||
| 2448 | CLC ; ...C clear for the addition | |||||||||
| 2449 | ADC scratch ; ...+ x 16: block x 48 (&30), low byte... | |||||||||
| 244B | STA plot_x ; ...kept in plot_x | |||||||||
| 244D | LDA plot_y ; ...and its high byte... | |||||||||
| 244F | ADC scratch_hi ; ...plus x 16's high byte, with the carry | |||||||||
| 2451 | STA plot_y ; ...kept in plot_y | |||||||||
| 2453 | CLC ; ...C clear for the addition | |||||||||
| 2454 | LDA plot_x ; ...the offset's low byte... | |||||||||
| 2456 | ADC #<(wall_blocks) ; ...plus where Stones' blocks start... | |||||||||
| 2458 | STA plot_x ; ...the block pointer's low byte | |||||||||
| 245A | LDA plot_y ; ...the offset's high byte... | |||||||||
| 245C | ADC #>(wall_blocks) ; ...plus the start's high byte | |||||||||
| 245E | STA plot_y ; ...the block pointer's high byte | |||||||||
| 2460 | LDY #wall_block_bytes - 1 ; Copy its &30 bytes into level_wall_block | |||||||||
| 2462 | .copy_wall_block←1← 2468 BPL | |||||||||
| LDA (plot_x),y ; Next byte of the chosen block... | ||||||||||
| 2464 | STA level_wall_block,y ; ...into the level file | |||||||||
| 2467 | DEY ; ...down to the first | |||||||||
| 2468 | BPL copy_wall_block ; ...until all &30 are copied | |||||||||
| 246A | RTS ; Return with the wall block in the level | |||||||||
| ; Not SPACE: if the choice moved, move the frame from the old ; block to the new. | ||||||||||
| 246B | .chooser_moved←1← 242E BNE | |||||||||
| LDA previous_block ; Did the keys move the choice? | ||||||||||
| 246E | CMP chosen_block ; ...still the block chosen before? | |||||||||
| 2471 | BEQ chooser_loop ; Not moved: pause and read the keys again | |||||||||
| 2473 | LDA #osbyte_vsync ; Yes: wait for the frame... | |||||||||
| 2475 | JSR osbyte ; Pace the chooser to the display Wait for vertical sync | |||||||||
| 2478 | LDA chosen_block ; ...then erase the old frame... | |||||||||
| 247B | PHA ; ...the new choice kept | |||||||||
| 247C | LDA previous_block ; ...the old one... | |||||||||
| 247F | STA chosen_block ; ...made current for the frame | |||||||||
| 2482 | LDA #spr_chooser_blank ; ...the blank frame sprite... | |||||||||
| 2484 | JSR frame_block ; ...rubbed out round the old block | |||||||||
| 2487 | PLA ; ...the new choice back | |||||||||
| 2488 | STA chosen_block ; ...as the chosen block | |||||||||
| 248B | LDA #spr_chooser_frame ; ...and frame the new block | |||||||||
| 248D | JSR frame_block ; ...drawn round it | |||||||||
| 2490 | JMP chooser_loop ; Pause and read the keys again | |||||||||
Draw the 24 wall blocksPlot sprites &12-&29, whose data the editor's sprite tables point at the blocks in Stones at &6E80, at their places in the grid (block_place). Called once by choose_wall_block, after load_stones.
|
||||||||
| 2493 | .draw_wall_blocks←1← 2414 JSR | |||||||
| LDX #wall_block_count - 1 ; For blocks 23 to 0... | ||||||||
| 2495 | .draw_wall_block←1← 24A6 BPL | |||||||
| TXA ; Keep the block number... | ||||||||
| 2496 | PHA ; ...on the stack, as plot_sprite uses X | |||||||
| 2497 | CLC ; ...sprite &12 + block... | |||||||
| 2498 | ADC #spr_wall_block_0 ; ...its sprite in the editor's tables | |||||||
| 249A | STA sprite_number ; ...for plot_sprite | |||||||
| 249C | TXA ; ...at the block's place in the grid | |||||||
| 249D | JSR block_place ; ...set plot_x, plot_y for it | |||||||
| 24A0 | JSR plot_sprite ; ...plot the block | |||||||
| 24A3 | PLA ; ...the block number back | |||||||
| 24A4 | TAX ; ...into X, the countdown | |||||||
| 24A5 | DEX ; ...the block before | |||||||
| 24A6 | BPL draw_wall_block ; ...until block 0 is drawn | |||||||
| 24A8 | RTS ; Return with all 24 blocks drawn | |||||||
Move the chosen wall block'.' and ',' move one block on or back, 'Z' and 'A' a row of four; a move off the grid is undone, so ',' and '.' wrap from one row's end to the next row but stop at blocks 0 and 23. Only one key is taken each call, '.' first. choose_wall_block calls it once a pause and compares the two blocks afterwards to see whether the frame must be moved.
|
||||||||||||
| 24A9 | .move_chooser←1← 2426 JSR | |||||||||||
| LDA chosen_block ; Remember the block chosen | ||||||||||||
| 24AC | STA previous_block ; ...to compare after moving | |||||||||||
| 24AF | LDX #inkey_key_full_stop ; '.': the next block? | |||||||||||
| 24B1 | JSR chooser_key_pressed ; ...(Z set if pressed) | |||||||||||
| 24B4 | BNE check_back ; Not pressed: try ',' | |||||||||||
| 24B6 | INC chosen_block ; Yes: the next block... | |||||||||||
| 24B9 | LDA chosen_block ; ...read the new block | |||||||||||
| 24BC | CMP #wall_block_count ; ...past the last block? | |||||||||||
| 24BE | BNE chooser_moved_ok ; No: the move stands | |||||||||||
| 24C0 | BEQ undo_move ; Past 23: undo it | |||||||||||
| 24C2 | .check_back←1← 24B4 BNE | |||||||||||
| LDX #inkey_key_comma ; ',': the previous block? | ||||||||||||
| 24C4 | JSR chooser_key_pressed ; ...(Z set if pressed) | |||||||||||
| 24C7 | BNE check_row_on ; Not pressed: try Z | |||||||||||
| 24C9 | DEC chosen_block ; Yes: the previous block... | |||||||||||
| 24CC | BPL chooser_moved_ok ; Still 0 or more: the move stands | |||||||||||
| 24CE | BMI undo_move ; Below 0: undo it | |||||||||||
| 24D0 | .check_row_on←1← 24C7 BNE | |||||||||||
| LDX #inkey_key_z ; 'Z': a row down? | ||||||||||||
| 24D2 | JSR chooser_key_pressed ; ...(Z set if pressed) | |||||||||||
| 24D5 | BNE check_row_back ; Not pressed: try A | |||||||||||
| 24D7 | CLC ; Yes: a row on... | |||||||||||
| 24D8 | LDA chosen_block ; ...the chosen block... | |||||||||||
| 24DB | ADC #4 ; ...4 on, the block below in the grid | |||||||||||
| 24DD | STA chosen_block ; ...as the chosen block | |||||||||||
| 24E0 | CMP #wall_block_count ; ...past the last block? | |||||||||||
| 24E2 | BCC chooser_moved_ok ; Within the 24: the move stands | |||||||||||
| 24E4 | BCS undo_move ; Past 23: undo it | |||||||||||
| 24E6 | .check_row_back←1← 24D5 BNE | |||||||||||
| LDX #inkey_key_a ; 'A': a row up? | ||||||||||||
| 24E8 | JSR chooser_key_pressed ; ...(Z set if pressed) | |||||||||||
| 24EB | BNE chooser_moved_ok ; Not pressed: no move | |||||||||||
| 24ED | SEC ; Yes: a row back... | |||||||||||
| 24EE | LDA chosen_block ; ...the chosen block... | |||||||||||
| 24F1 | SBC #4 ; ...4 back, the block above in the grid | |||||||||||
| 24F3 | STA chosen_block ; ...as the chosen block | |||||||||||
| 24F6 | BPL chooser_moved_ok ; Still 0 or more: the move stands | |||||||||||
| 24F8 | BMI undo_move ; Below 0: undo it | |||||||||||
| 24FA | .chooser_moved_ok←5← 24BE BNE← 24CC BPL← 24E2 BCC← 24EB BNE← 24F6 BPL | |||||||||||
| RTS ; Return with the new choice in chosen_block | ||||||||||||
| 24FB | .undo_move←4← 24C0 BEQ← 24CE BMI← 24E4 BCS← 24F8 BMI | |||||||||||
| LDA previous_block ; Off the grid: undo the move | ||||||||||||
| 24FE | STA chosen_block ; ...restore the block chosen before | |||||||||||
| 2501 | RTS ; Return with the choice unchanged | |||||||||||
Test a keyThe wall-block chooser's copy of key_pressed: OSBYTE &81 with the INKEY number in X, testing X before Y. Used for ',' '.' 'A' 'Z' and SPACE.
|
|||||||||||||
| 2502 | .chooser_key_pressed←5← 242B JSR← 24B1 JSR← 24C4 JSR← 24D2 JSR← 24E8 JSR | ||||||||||||
| LDA #osbyte_inkey ; OSBYTE &81: scan the key... | |||||||||||||
| 2504 | LDY #&ff ; ...Y = &FF: test the key whose INKEY number is X | ||||||||||||
| 2506 | JSR osbyte ; Scan it: X = Y = &FF if the key is held Test for a key pressed | ||||||||||||
| 2509 | CPX #&ff ; Z set if X and Y are both &FF | ||||||||||||
| 250B | BNE chooser_key_done ; X not &FF: not pressed (Z clear) | ||||||||||||
| 250D | CPY #&ff ; ...Z set if Y is &FF too: pressed | ||||||||||||
| 250F | .chooser_key_done←1← 250B BNE | ||||||||||||
| RTS ; Return with Z set if the key is held | |||||||||||||
Find a wall block's place in the gridBlock n is at column n mod 4, row n div 4: plot_x = 8 x column + &1A, plot_y = 24 x row + &14. Each block is 4 bytes by 12 rows, so the grid leaves room for the frame between them.
|
|||||||||||||
| 2510 | .block_place←3← 249D JSR← 252F JSR← 2540 JSR | ||||||||||||
| TAX ; Keep the block number in X | |||||||||||||
| 2511 | AND #3 ; plot_x = (n mod 4) x 8 + &1A | ||||||||||||
| 2513 | ASL ; ...x 2... | ||||||||||||
| 2514 | ASL ; ...x 4... | ||||||||||||
| 2515 | ASL ; ...x 8 bytes across... | ||||||||||||
| 2516 | CLC ; ...C clear for the addition | ||||||||||||
| 2517 | ADC #&1a ; ...from column &1A | ||||||||||||
| 2519 | STA plot_x ; ...as plot_x | ||||||||||||
| 251B | TXA ; plot_y = (n div 4) x 24 + &14 | ||||||||||||
| 251C | AND #&fc ; ...the block's grid row x 4... | ||||||||||||
| 251E | ASL ; ...x 8... | ||||||||||||
| 251F | STA scratch ; ...row x 8, kept to add... | ||||||||||||
| 2521 | ASL ; ...x 16... | ||||||||||||
| 2522 | CLC ; ...C clear for the addition | ||||||||||||
| 2523 | ADC scratch ; ...+ x 8: the row x 24 pixel rows | ||||||||||||
| 2525 | ADC #&14 ; ...from pixel row &14 | ||||||||||||
| 2527 | STA plot_y ; ...as plot_y | ||||||||||||
| 2529 | RTS ; Return with the block's place, C clear | ||||||||||||
Draw or erase the frame round the chosen blockPlot sprite A (&2A the frame, &2B a blank), 6 bytes by 18 rows, one byte left of and three rows above the chosen block, so that it surrounds the 4-byte by 12-row block, then plot the block again inside it, as both sprites cover it. choose_wall_block frames block 0 at the start and, when the choice moves, erases the old frame and draws the new one.
|
|||||||||||||
| 252A | .frame_block←3← 2419 JSR← 2484 JSR← 248D JSR | ||||||||||||
| STA sprite_number ; The frame or blank sprite... | |||||||||||||
| 252C | LDA chosen_block ; ...at the chosen block's place... | ||||||||||||
| 252F | JSR block_place ; ...set plot_x, plot_y | ||||||||||||
| 2532 | DEC plot_x ; ...one byte left... | ||||||||||||
| 2534 | LDA plot_y ; ...and up (C is clear from block_place)... | ||||||||||||
| 2536 | SBC #2 ; ...SBC #2 with C clear: three rows up | ||||||||||||
| 2538 | STA plot_y ; ...as plot_y | ||||||||||||
| 253A | JSR plot_sprite ; Plot the frame, covering the block | ||||||||||||
| 253D | LDA chosen_block ; Then the block itself | ||||||||||||
| 2540 | JSR block_place ; ...set plot_x, plot_y | ||||||||||||
| 2543 | LDA chosen_block ; ...the block number... | ||||||||||||
| 2546 | CLC ; ...C clear for the addition | ||||||||||||
| 2547 | ADC #spr_wall_block_0 ; ...as its sprite | ||||||||||||
| 2549 | STA sprite_number ; ...for plot_sprite | ||||||||||||
| 254B | JSR plot_sprite ; ...plot it inside the frame | ||||||||||||
| 254E | RTS ; Return with the block framed or unframed | ||||||||||||
| ; *LOAD STONES, for load_stones: Stones loads at its own ; address, &6E80. | |||||||||||||
| 254F | .load_stones_command | ||||||||||||
| EQUS "LOAD STONES", &0D ; OSCLI command: *LOAD STONES, at its own address | |||||||||||||
Show 25 rowsSend VDU 23,0,6,25,0,0,0,0,0,0: 6845 register 6, the rows displayed, = 25. Row 25 starts at &6E80, where load_stones puts Stones, so the wall-block chooser does not show it. Called once by choose_wall_block, before load_stones.
|
||||||||
| 255B | .show_25_rows←1← 2405 JSR | |||||||
| LDX #0 ; Send rows_25_vdu's ten bytes | ||||||||
| 255D | .send_25_rows←1← 2566 BNE | |||||||
| LDA rows_25_vdu,x ; Next byte of the VDU command... | ||||||||
| 2560 | JSR oswrch ; ...sent to the VDU drivers | |||||||
| 2563 | INX ; ...on to the next byte | |||||||
| 2564 | CPX #&0a ; ...all ten sent? | |||||||
| 2566 | BNE send_25_rows ; No: send the next | |||||||
| 2568 | RTS ; Return with 25 rows displayed | |||||||
| ; VDU 23,0,6,25,0,0,0,0,0,0: 6845 register 6 = 25 rows ; displayed, sent by show_25_rows. | ||||||||
| 2569 | .rows_25_vdu←1Used as index base by← 255D LDA | |||||||
| EQUB &17, &00, &06, &19, &00, ; VDU 23,0,6,25,0,0,0,0,0,0: &00, &00, &00, &00, &00 ; display 25 rows | ||||||||
UnusedLeftover bytes: a fragment of BBC BASIC assembler. |
|
| 2573 | EQUS "A#255:LDX#0:." |
The chooser's frameSprite &2A: 6 bytes by 18 pixel rows. |
|
| ; Sprite &2A: the frame round the chosen wall block, 6 bytes by ; 18 rows. | |
| 2580 | .frame_sprite |
| EQUB &3F, &3F, &3F, &3F, &3F, &3F, &2A, &00, &00, &00, &00, &15, &2A, &00, &00, &00, &00, &15, &2A, &00, &00, &00, &00, &15, &2A, &00, &00, &00, &00, &15, &2A, &00, &00, &00, &00, &15, &2A, &00, &00, &00, &00, &15, &2A, &00, &00, &00, &00, &15, &2A, &00, &00, &00, &00, &15, &2A, &00, &00, &00, &00, &15, &2A, &00, &00, &00, &00, &15, &2A, &00, &00, &00, &00, &15, &2A, &00, &00, &00, &00, &15, &2A, &00, &00, &00, &00, &15, &2A, &00, &00, &00, &00, &15, &2A, &00, &00, &00, &00, &15, &2A, &00, &00, &00, &00, &15, &3F, &3F, &3F, &3F, &3F, &3F | |
UnusedLeftover bytes. |
|
| 25EC | EQUB &0D, &09, &D8, &2E ; Not used |
VariablesThe editor's settings and state, kept in the program itself: they survive a BREAK, which restarts the editor without reloading it. |
|
| ; 1 if a new, empty level is being made; 0 to edit a loaded one. ; Written by editor_init from the E/N answer, read by ; start_editing. | |
| 25F0 | .new_level_flag←2← 1C88 STA← 1F28 LDA |
| EQUB &00 | |
| ; The level number (1-24) typed when saving. Written by ; save_level and not read: the number only chooses ; level_checksum. | |
| 25F1 | .level_number←1← 22F8 STA |
| EQUB &01 | |
| ; That level's entry in level_checksums, which save_level makes ; the level's bytes sum to (modulo 256). | |
| 25F2 | .level_checksum←4← 22FF STA← 2340 CMP← 234B ADC← 2354 LDA |
| EQUB &62 | |
| ; 1 for the slow cursor (three extra frames a pass), 0 for the ; fast one. start_editing sets it; f0 in the edit loop toggles ; it. | |
| 25F3 | .slow_cursor←4← 1FAC STA← 1FB9 LDA← 1FD3 LDA← 1FD8 STA |
| EQUB &01 | |
| ; The physical colour, 1-7, that logical colour 10 (the walls on ; screen) shows. start_editing sets 1, red; cursor up and down ; step it. | |
| 25F4 | .colour_10←7← 1FAF STA← 2041 INC← 2044 LDA← 204B DEC← 205F DEC← 2064 INC← 2191 LDA |
| EQUB &01 | |
| ; Toggled each edit-loop pass when placing walls; the cursor ; sprite is plotted over the wall when it is 1. | |
| 25F5 | .cursor_flash←3← 1EBE STA← 202B LDA← 2030 STA |
| EQUB &01 | |
| 25F6 | EQUB &00, &00 ; Not referenced |
| ; The wall block chosen, 0-23: row x 4 + column in the chooser's ; grid. | |
| 25F8 | .chosen_block←18← 2411 STA← 2434 LDA← 246E CMP← 2478 LDA← 247F STA← 2488 STA← 24A9 LDA← 24B6 INC← 24B9 LDA← 24C9 DEC← 24D8 LDA← 24DD STA← 24EE LDA← 24F3 STA← 24FE STA← 252C LDA← 253D LDA← 2543 LDA |
| EQUB &00 | |
| ; The wall block chosen before move_chooser's last call, to tell ; whether the frame must move. | |
| 25F9 | .previous_block←4← 246B LDA← 247C LDA← 24AC STA← 24FB LDA |
| EQUB &00 | |
| ; 1 once save_level has encrypted the level at &2700, so that a ; later save (after BREAK) decrypts it first; editor_init clears ; it. | |
| 25FA | .level_encrypted←3← 1C37 STA← 2307 LDA← 2361 STA |
| EQUB &00 | |
| ; Internal key numbers of 0, 1, 2 and 3, the drive digits, ; indexed by the digit: ask_key matches the key pressed against ; them when asked for a drive. | |
| 25FB | .drive_keys←1Used as index base by← 1CEA CMP |
| EQUB &27, &30, &31, ; Internal key numbers of '0' '1' '2' &11 ; '3' | |
| ; &6F once Table has been loaded into private RAM, so that ; editor_init does not load it again on a restart. | |
| 25FF | .table_loaded_flag←2← 1C3A LDA← 1C43 STA |
| EQUB &00 | |
Pack the item slots into the level fileTurn the editor's item slots back into the level file's tables, in the game's types. pack_level calls it when SHIFT+S saves, after wall_edges. Go through the slots from the last (&4F) to the first, so that the tables come out in the reverse of the order unpack_level read them: objects into entries 1 upwards (the exit always into entry 30), trapdoors into entries 0-7, and each door with its linked key into the next door entry. Keys and free slots are skipped. Each item's game type or door sprite comes from item_types, indexed by the editor's item number. Saving needs exactly eight trapdoors and a key for every door, so every trapdoor entry and every placed door's key is written; object and door entries beyond those placed keep the &FF (off the map) that start_editing put there. The counts are left in packed_objects, packed_trapdoors and packed_doors.
|
||||||||
| 2600 | .pack_items←1← 26A9 JSR | |||||||
| LDA #0 ; No objects, trapdoors or doors packed yet | ||||||||
| 2602 | STA packed_objects ; ...no object entries yet... | |||||||
| 2605 | STA packed_trapdoors ; ...no trapdoor entries yet... | |||||||
| 2608 | STA packed_doors ; ...and no door entries yet | |||||||
| 260B | LDX #max_slot ; For slots &4F to 0... | |||||||
| 260D | .pack_slot←1← 2638 BPL | |||||||
| LDA slot_item,x ; ...what is in it? | ||||||||
| 2610 | BEQ pack_next ; Free slot: skip it | |||||||
| 2612 | CMP #1 ; Is it the exit? | |||||||
| 2614 | BEQ pack_exit ; Yes: always object entry 30 | |||||||
| 2616 | CMP #3 ; Is it a trapdoor? | |||||||
| 2618 | BEQ pack_trapdoor ; Yes: the trapdoor table | |||||||
| 261A | CMP #spr_door_vertical ; A door or key? | |||||||
| 261C | BCS pack_door ; Yes: the door tables | |||||||
| ; An object: the next object entry, with its game type. | ||||||||
| 261E | INC packed_objects ; An object: the next entry... | |||||||
| 2621 | TAY ; ...the editor's item number... | |||||||
| 2622 | LDA item_types,y ; ...as the game's object type | |||||||
| 2625 | LDY packed_objects ; ...the entry number | |||||||
| 2628 | STA level_object_type,y ; ...into the level's object types | |||||||
| 262B | LDA slot_x,x ; ...and its x... | |||||||
| 262E | STA level_object_x,y ; ...into the level's object x | |||||||
| 2631 | LDA slot_y,x ; ...and its y... | |||||||
| 2634 | STA level_object_y,y ; ...into the level's object y | |||||||
| 2637 | .pack_next←5← 2610 BEQ← 264E BPL← 2662 BNE← 2666 BEQ← 26A6 JMP | |||||||
| DEX ; Next slot down | ||||||||
| 2638 | BPL pack_slot ; ...until slot 0 is done | |||||||
| 263A | RTS ; Return with every slot packed | |||||||
| ; The exit: always object entry 30. | ||||||||
| 263B | .pack_exit←1← 2614 BEQ | |||||||
| LDA #game_exit_type ; The exit: entry 30, type &51 | ||||||||
| 263D | LDY #max_object ; ...the exit's entry in the object tables | |||||||
| 263F | STA level_object_type,y ; ...its game type, &51 | |||||||
| 2642 | LDA slot_x,x ; ...the exit's x... | |||||||
| 2645 | STA level_object_x,y ; ...as object 30's x | |||||||
| 2648 | LDA slot_y,x ; ...the exit's y... | |||||||
| 264B | STA level_object_y,y ; ...as object 30's y | |||||||
| 264E | BPL pack_next ; Next slot (always branches) | |||||||
| ; A trapdoor: the next trapdoor entry, from 0. | ||||||||
| 2650 | .pack_trapdoor←1← 2618 BEQ | |||||||
| LDY packed_trapdoors ; A trapdoor: the next trapdoor entry | ||||||||
| 2653 | LDA slot_x,x ; ...the trapdoor's x... | |||||||
| 2656 | STA level_trapdoor_x,y ; ...into the level's trapdoor table | |||||||
| 2659 | LDA slot_y,x ; ...the trapdoor's y... | |||||||
| 265C | STA level_trapdoor_y,y ; ...into the level's trapdoor table | |||||||
| 265F | INC packed_trapdoors ; ...one more trapdoor packed | |||||||
| 2662 | BNE pack_next ; Next slot (always branches) | |||||||
| ; A door: the next door entry, with its game sprite, and its ; key's position from the door's link. | ||||||||
| 2664 | .pack_door←1← 261C BCS | |||||||
| CMP #spr_key ; Is it a key? | ||||||||
| 2666 | BEQ pack_next ; Yes: skip it, as it is packed with its door | |||||||
| 2668 | INC packed_doors ; A door: the next door entry... | |||||||
| 266B | TAY ; ...the editor's item number... | |||||||
| 266C | LDA item_types,y ; ...as the game's door sprite | |||||||
| 266F | LDY packed_doors ; ...the entry number | |||||||
| 2672 | STA level_door_sprite,y ; ...into the level's door sprites | |||||||
| 2675 | LDA slot_x,x ; ...and its x... | |||||||
| 2678 | STA level_door_x,y ; ...into the level's door x | |||||||
| 267B | LDA slot_y,x ; ...and its y... | |||||||
| 267E | STA level_door_y,y ; ...into the level's door y | |||||||
| 2681 | STX bit_mask ; Find the link whose door is this slot... | |||||||
| 2683 | LDY #max_link ; ...over links 19 to 0 | |||||||
| 2685 | .find_door_link←1← 268D BPL | |||||||
| LDA link_door,y ; This link's door slot... | ||||||||
| 2688 | CMP bit_mask ; ...the door's slot? | |||||||
| 268A | BEQ pack_key ; Yes: Y is its link | |||||||
| 268C | DEY ; ...next link down | |||||||
| 268D | BPL find_door_link ; ...until all 20 are tried | |||||||
| 268F | .pack_key←1← 268A BEQ | |||||||
| TXA ; ...and put its key's position in the same entry | ||||||||
| 2690 | PHA ; ...keeping the door's slot | |||||||
| 2691 | LDA link_key,y ; ...the key's slot... | |||||||
| 2694 | TAX ; ...into X, to index the slots | |||||||
| 2695 | LDY packed_doors ; ...the door's entry number | |||||||
| 2698 | LDA slot_x,x ; ...the key's x... | |||||||
| 269B | STA level_key_x,y ; ...as the door's key x | |||||||
| 269E | LDA slot_y,x ; ...the key's y... | |||||||
| 26A1 | STA level_key_y,y ; ...as the door's key y | |||||||
| 26A4 | PLA ; ...the door's slot back | |||||||
| 26A5 | TAX ; ...into X, the slot counter | |||||||
| 26A6 | JMP pack_next ; Next slot down | |||||||
Pack the level for savingCalled from the edit loop when SHIFT+S saves, after wall_edges and before choose_wall_block. Pack the item slots into the object, door and trapdoor tables (pack_items), then copy the wall map and the object-free map, &C9 bytes each, into the level file. save_level then sets the checksum and encrypts.
|
||||||||
| 26A9 | .pack_level←1← 2010 JSR | |||||||
| JSR pack_items ; Pack the items into the level's tables | ||||||||
| 26AC | LDX #0 ; Copy the &C9 bytes of each map | |||||||
| 26AE | .copy_maps←1← 26BD BNE | |||||||
| LDA wall_map,x ; Next wall-map byte... | ||||||||
| 26B1 | STA level_walls,x ; ...into the level file | |||||||
| 26B4 | LDA object_free_map,x ; ...and the object-free map byte... | |||||||
| 26B7 | STA level_object_free,x ; ...into the level file | |||||||
| 26BA | INX ; ...on to the next byte | |||||||
| 26BB | CPX #map_bytes ; ...all &C9 copied? | |||||||
| 26BD | BNE copy_maps ; No: copy the next | |||||||
| 26BF | RTS ; Return with the level file complete | |||||||
UnusedZeros. |
|
| 26C0 | EQUB &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00 ; Not used |
Load the wall blocks*LOAD STONES (at its own address, &6E80) with VDU output off. Called by choose_wall_block, after show_25_rows has hidden the screen from &6E80 up, with disc drive 0 already selected by the edit loop. Stones holds the 24 wall blocks (&480 bytes) and then level 25, which the editor does not use. A missing Stones is an error, and BRKV resets the machine.
|
||||||||
| 26D0 | .load_stones←1← 2408 JSR | |||||||
| LDA #&15 ; VDU 21: output off | ||||||||
| 26D2 | JSR oswrch ; ...so the *LOAD message does not show | |||||||
| 26D5 | LDX #<(load_stones_command) ; *LOAD STONES, to &6E80... | |||||||
| 26D7 | LDY #>(load_stones_command) ; ...(the command's high byte) | |||||||
| 26D9 | JSR oscli ; ...load the 24 wall blocks | |||||||
| 26DC | LDA #6 ; VDU 6: output on | |||||||
| 26DE | JSR oswrch ; ...sent to the VDU drivers | |||||||
| 26E1 | RTS ; Return with Stones at &6E80 | |||||||
UnusedZeros. |
|
| 26E2 | 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 ; Not used |
Plot a spriteCopy 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.
|
||||||||||||||||
| Load | Exec | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2700 | 0900 | .plot_sprite←6Referenced by← 24A0 JSR← 253A JSR← 254B JSR← 2B72 JSR← 2CF3 JSRUsed as index base by← 23B7 STA | ||||||||||||||
| LDX sprite_number ; X = sprite number, indexing the four sprite tables | ||||||||||||||||
| 2702 | 0902 | LDA sprite_addr_lo,x ; Point sprite_data_ptr at the editor sprite's data... | ||||||||||||||
| 2705 | 0905 | STA sprite_data_ptr ; ...its low byte from sprite_addr_lo | ||||||||||||||
| 2707 | 0907 | LDA sprite_addr_hi,x ; ...high byte, from the editor's sprite tables... | ||||||||||||||
| 270A | 090A | STA sprite_data_ptr_hi ; ...so sprite_data_ptr walks through the data | ||||||||||||||
| 270C | 090C | LDA sprite_widths,x ; Width in screen bytes, from sprite_widths... | ||||||||||||||
| 270F | 090F | STA scratch ; ...counted across each row | ||||||||||||||
| 2711 | 0911 | LDA sprite_heights,x ; Height in pixel rows, from sprite_heights... | ||||||||||||||
| 2714 | 0914 | STA scratch_hi ; ...counted down the sprite | ||||||||||||||
| 2716 | 0916 | JSR screen_address ; screen_ptr = address of the top-left byte | ||||||||||||||
| 2719 | 0919 | LDY #0 ; Index stays 0: the pointers themselves advance | ||||||||||||||
| 271B | 091B | LDX scratch_hi ; X counts the pixel rows still to plot | ||||||||||||||
| 271D | 091D | .plot_sprite_row←1← 0964 BNE | ||||||||||||||
| .plot_row←1← 0964 BNE | ||||||||||||||||
| LDA screen_ptr ; Remember where this pixel row starts... | ||||||||||||||||
| 271F | 091F | STA row_start_ptr ; ...its low byte... | ||||||||||||||
| 2721 | 0921 | LDA screen_ptr_hi ; ...and its high byte... | ||||||||||||||
| 2723 | 0923 | STA row_start_ptr_hi ; ...in row_start_ptr, to step down from later | ||||||||||||||
| 2725 | 0925 | TXA ; Save the row count | ||||||||||||||
| 2726 | 0926 | PHA ; ...on the stack: X now counts bytes | ||||||||||||||
| 2727 | 0927 | LDX scratch ; X counts the bytes across this row | ||||||||||||||
| 2729 | 0929 | .plot_sprite_byte←1← 093F BNE | ||||||||||||||
| .plot_byte←1← 093F BNE | ||||||||||||||||
| LDA (sprite_data_ptr),y ; Copy one sprite byte... | ||||||||||||||||
| 272B | 092B | STA (screen_ptr),y ; ...to the screen, over whatever was there | ||||||||||||||
| 272D | 092D | CLC ; Step screen_ptr right one byte column: 8 bytes on | ||||||||||||||
| 272E | 092E | LDA screen_ptr ; ...the screen address's low byte... | ||||||||||||||
| 2730 | 0930 | ADC #8 ; ...+ 8, the next byte column... | ||||||||||||||
| 2732 | 0932 | STA screen_ptr ; ...as screen_ptr's new low byte | ||||||||||||||
| 2734 | 0934 | BCC plot_sprite_next_data ; No carry: the high byte stands | ||||||||||||||
| 2736 | 0936 | INC screen_ptr_hi ; ...with carry into the high byte | ||||||||||||||
| 2738 | 0938 | .plot_sprite_next_data←1← 0934 BCC | ||||||||||||||
| .plot_next_data←1← 0934 BCC | ||||||||||||||||
| INC sprite_data_ptr ; Next sprite data byte | ||||||||||||||||
| 273A | 093A | BNE plot_sprite_count_byte ; No carry: the high byte stands | ||||||||||||||
| 273C | 093C | INC sprite_data_ptr_hi ; ...with carry into the high byte | ||||||||||||||
| 273E | 093E | .plot_sprite_count_byte←1← 093A BNE | ||||||||||||||
| .plot_count_byte←1← 093A BNE | ||||||||||||||||
| DEX ; One byte fewer left in this row | ||||||||||||||||
| 273F | 093F | BNE plot_sprite_byte ; More of the row: plot the next byte | ||||||||||||||
| 2741 | 0941 | CLC ; screen_ptr = row start + 1: the next pixel row down | ||||||||||||||
| 2742 | 0942 | LDA row_start_ptr ; The row start's low byte... | ||||||||||||||
| 2744 | 0944 | ADC #1 ; ...+ 1, one pixel row lower... | ||||||||||||||
| 2746 | 0946 | STA screen_ptr ; ...is the new low byte | ||||||||||||||
| 2748 | 0948 | LDA row_start_ptr_hi ; The row start's high byte... | ||||||||||||||
| 274A | 094A | ADC #0 ; ...plus the carry... | ||||||||||||||
| 274C | 094C | STA screen_ptr_hi ; ...is the new high byte | ||||||||||||||
| 274E | 094E | LDA screen_ptr ; Has it crossed into the next character row? | ||||||||||||||
| 2750 | 0950 | AND #7 ; ...(pixel row within the character now 0) | ||||||||||||||
| 2752 | 0952 | BNE plot_sprite_next_row ; No: still within the character row | ||||||||||||||
| 2754 | 0954 | CLC ; Yes: add &278 more, to the top of the character... | ||||||||||||||
| 2755 | 0955 | LDA screen_ptr ; ...row below (row start + 1 + &278 = + 640 - 7) | ||||||||||||||
| 2757 | 0957 | ADC #&78 ; ...low byte + &78 (640 - 8 = &278)... | ||||||||||||||
| 2759 | 0959 | STA screen_ptr ; ...as screen_ptr's low byte | ||||||||||||||
| 275B | 095B | LDA screen_ptr_hi ; ...then the high byte... | ||||||||||||||
| 275D | 095D | ADC #2 ; ...+ 2 and the carry... | ||||||||||||||
| 275F | 095F | STA screen_ptr_hi ; ...as screen_ptr's high byte: the row below | ||||||||||||||
| 2761 | 0961 | .plot_sprite_next_row←1← 0952 BNE | ||||||||||||||
| .plot_next_row←1← 0952 BNE | ||||||||||||||||
| PLA ; Recover the row count | ||||||||||||||||
| 2762 | 0962 | TAX ; ...back into X | ||||||||||||||
| 2763 | 0963 | DEX ; One pixel row fewer to plot | ||||||||||||||
| 2764 | 0964 | BNE plot_sprite_row ; More rows: plot the next | ||||||||||||||
| 2766 | 0966 | RTS ; Return: the sprite is on the screen | ||||||||||||||
Calculate the screen address of plot_x, plot_yThe game's screen_address, reading the screen's row offsets from Table (row_offsets, &C675), which BOOT's *DUNJUNZ or this editor's *L. TABLE puts in private RAM.
|
||||||||||
| Load | Exec | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 2767 | 0967 | .screen_address←1← 0916 JSR | ||||||||
| LDA plot_y ; Table index = 2 x (plot_y DIV 8), the character row... | ||||||||||
| 2769 | 0969 | LSR ; ...plot_y DIV 2... | ||||||||
| 276A | 096A | LSR ; ...plot_y DIV 4: 2 x the character row, + plot_y bit 2... | ||||||||
| 276B | 096B | AND #&fe ; ...bit 0 cleared: the row's pair of table bytes | ||||||||
| 276D | 096D | TAY ; ...as the index into the row table | ||||||||
| 276E | 096E | LDA row_offsets,y ; High byte of row x 640, from Table's copy... | ||||||||
| 2771 | 0971 | CLC ; ...(carry clear for the add) | ||||||||
| 2772 | 0972 | ADC #>(screen_start) ; ...plus &30: the screen starts at &3000 | ||||||||
| 2774 | 0974 | STA screen_ptr_hi ; ...as the screen address high byte | ||||||||
| 2776 | 0976 | LDA row_offsets_lo,y ; Low byte of row x 640 | ||||||||
| 2779 | 0979 | STA screen_ptr ; ...as the low byte | ||||||||
| 277B | 097B | LDA plot_y ; Add the pixel row within the character... | ||||||||
| 277D | 097D | AND #7 ; ...plot_y MOD 8... | ||||||||
| 277F | 097F | ADC screen_ptr ; ...(carry clear: adding &30 to the high byte cannot carry) | ||||||||
| 2781 | 0981 | STA screen_ptr ; ...stored in the low byte | ||||||||
| 2783 | 0983 | CLC ; Add 8 x plot_x: its high byte is plot_x DIV 32... | ||||||||
| 2784 | 0984 | LDA plot_x ; ...taking the byte column... | ||||||||
| 2786 | 0986 | AND #&e0 ; ...bits 7-5 kept... | ||||||||
| 2788 | 0988 | ROL ; ...four ROLs through the carry: bit 7 out... | ||||||||
| 2789 | 0989 | ROL ; ...bit 7 in at bit 0, bit 6 out | ||||||||
| 278A | 098A | ROL ; ...bits 7-6 at bits 1-0, bit 5 out | ||||||||
| 278B | 098B | ROL ; ...bits 7-5 now in bits 2-0 | ||||||||
| 278C | 098C | CLC ; ...(carry clear for the add) | ||||||||
| 278D | 098D | ADC screen_ptr_hi ; ...added to the high byte | ||||||||
| 278F | 098F | STA screen_ptr_hi ; ...as screen_ptr's high byte | ||||||||
| 2791 | 0991 | LDA plot_x ; Low byte + (plot_x x 8) AND &FF: plot_x... | ||||||||
| 2793 | 0993 | ASL ; ...x 2... | ||||||||
| 2794 | 0994 | ASL ; ...x 4... | ||||||||
| 2795 | 0995 | ASL ; ...x 8, its top bits dropping out | ||||||||
| 2796 | 0996 | CLC ; ...(carry clear for the add) | ||||||||
| 2797 | 0997 | ADC screen_ptr ; ...added to the low byte | ||||||||
| 2799 | 0999 | STA screen_ptr ; ...as screen_ptr's low byte | ||||||||
| 279B | 099B | BCC screen_address_done ; No carry: done | ||||||||
| 279D | 099D | INC screen_ptr_hi ; ...with carry into the high byte | ||||||||
| 279F | 099F | .screen_address_done←1← 099B BCC | ||||||||
| RTS ; Return with screen_ptr set | ||||||||||
UnusedLeftover bytes. |
||
| Load | Exec | |
|---|---|---|
| 27A0 | 09A0 | EQUB &20, &20, &20, &20, &44, &20, &20, &20, &20, &20, &20, &20, &44, &20, &20, &20 ; Not used |
| ; pack_items's objects packed so far, besides the exit: ; zeroed, then incremented before each is written, so it ; is the entry just filled (1-29). | ||
| 27B0 | 09B0 | .packed_objects←3← 2602 STA← 261E INC← 2625 LDY |
| EQUB &20 | ||
| ; pack_items's trapdoors packed so far: the next trapdoor ; entry to fill (0-7), incremented after each. | ||
| 27B1 | 09B1 | .packed_trapdoors←3← 2605 STA← 2650 LDY← 265F INC |
| EQUB &20 | ||
| ; pack_items's doors packed so far, each with its key: ; incremented before each is written, so it is the door ; entry just filled (1-20). | ||
| 27B2 | 09B2 | .packed_doors←4← 2608 STA← 2668 INC← 266F LDY← 2695 LDY |
| EQUB &20 | ||
| 27B3 | 09B3 | EQUB &20, &44, &20, &20, &20, &20, &20, &20, &20, &44, &20, &20, &20 ; Not used: leftover spaces and Ds |
Item types and checksumsitem_types, indexed by editor item (0-&0F), translates between the editor's items and the game's object types and door sprites: unpack_level's item_for_type searches it for a type when loading, and pack_items indexes it by item when saving. level_checksums, indexed by level number from &09CF, is a copy of the game's checksum table, which save_level reads so that a saved level passes the game's check. |
||
| Load | Exec | |
|---|---|---|
| ; The level type of each editor item (its sprite number, ; 0-&0F): 1 exit &51; 2 energy drainer &53; 4-&0C treasure ; &28, food &29, teleporter &2B, magic sword &63, magic ; helmet &60, potion &61, weapons &62, Cross &2A, boots ; &5F; &0D and &0E the door sprites &1C and &1D. Entries 0 ; (wall), 3 (trapdoor) and &0F (key) are not used as ; types. | ||
| 27C0 | 09C0 | .item_types←3Used as index base by← 2622 LDA← 266C LDA← 7BC2 LDA |
| EQUB &22, &51, &53, &00, &28, &29, &2B, &63, &60, &61, &62, &2A, &5F, &1C, &1D, &31 | ||
| ; The game's checksum table (level_checksums, &0491): the ; sum, modulo 256, of each level's decrypted bytes. ; Indexed from &09CF by level number. | ||
| 27D0 | 09D0 | .level_checksums |
| EQUB &62, &CD, &0C, &44, &4D, &22, &F6, &42, &21, &7D, &5D, &D8, &A0, &F1, &0F, &CC, &D3, &53, &3B, &83, &71, &B2, &6F, &F3, &F1 | ||
UnusedLeftover bytes. |
||
| Load | Exec | |
|---|---|---|
| 27E9 | 09E9 | EQUB &00, &3A, &20, &20, &20, &3A, &20, &20, &20, &3A, &20, &20, &20, &3A, &20, &20, &20, &3A, &20, &20, &20, &3A, &20 ; Not used |
Sprite tablesEach of the editor's 51 sprites' data address (low and high bytes), width in bytes and height in pixel rows. 0-&0F are the items (two bytes by five rows, at &2A00), &10 is blank (zeros at &7FF0), &11 a door waiting for its key, &12-&29 the 24 wall blocks in Stones (&6E80), &2A the wall-block chooser's frame and &2B a blank part of the screen that erases it, and &2C the cursor. Entries &2D-&32 are not used. |
||
| Load | Exec | |
|---|---|---|
| ; Each sprite's data address, low byte. | ||
| 2800 | 0A00 | .sprite_addr_lo←2Used as index base by← 0902 LDA← 23C0 STA |
| EQUB <(item_sprites), <(item_sprites + 10), <(item_sprites + 20), <(item_sprites + 30), <(item_sprites + 40), <(item_sprites + 50), <(item_sprites + 60), <(item_sprites + 70), <(item_sprites + 80), <(item_sprites + 90), <(item_sprites + 100), <(item_sprites + 110), <(item_sprites + 120), <(item_sprites + 130), <(item_sprites + 140), <(item_sprites + 150), <(blank_sprite), <(waiting_door_sprite), <(wall_blocks), <(wall_blocks + &30), <(wall_blocks + &60), <(wall_blocks + &90), <(wall_blocks + &c0), <(wall_blocks + &f0), <(wall_blocks + &0120), <(wall_blocks + &0150), <(wall_blocks + &0180), <(wall_blocks + &01b0), <(wall_blocks + &01e0), <(wall_blocks + &0210), <(wall_blocks + &0240), <(wall_blocks + &0270), <(wall_blocks + &02a0), <(wall_blocks + &02d0), <(wall_blocks + &0300), <(wall_blocks + &0330), <(wall_blocks + &0360), <(wall_blocks + &0390), <(wall_blocks + &03c0), <(wall_blocks + &03f0), <(wall_blocks + &0420), <(wall_blocks + &0450), <(frame_sprite), <(screen_start + &0200), <(cursor_sprite), &0A, &25, &00, &05, &00, &00 | ||
| ; Each sprite's data address, high byte. | ||
| 2833 | 0A33 | .sprite_addr_hi←1Used as index base by← 0907 LDA |
| EQUB >(item_sprites), >(item_sprites + 10), >(item_sprites + 20), >(item_sprites + 30), >(item_sprites + 40), >(item_sprites + 50), >(item_sprites + 60), >(item_sprites + 70), >(item_sprites + 80), >(item_sprites + 90), >(item_sprites + 100), >(item_sprites + 110), >(item_sprites + 120), >(item_sprites + 130), >(item_sprites + 140), >(item_sprites + 150), >(blank_sprite), >(waiting_door_sprite), >(wall_blocks), >(wall_blocks + &30), >(wall_blocks + &60), >(wall_blocks + &90), >(wall_blocks + &c0), >(wall_blocks + &f0), >(wall_blocks + &0120), >(wall_blocks + &0150), >(wall_blocks + &0180), >(wall_blocks + &01b0), >(wall_blocks + &01e0), >(wall_blocks + &0210), >(wall_blocks + &0240), >(wall_blocks + &0270), >(wall_blocks + &02a0), >(wall_blocks + &02d0), >(wall_blocks + &0300), >(wall_blocks + &0330), >(wall_blocks + &0360), >(wall_blocks + &0390), >(wall_blocks + &03c0), >(wall_blocks + &03f0), >(wall_blocks + &0420), >(wall_blocks + &0450), >(frame_sprite), >(screen_start + &0200), >(cursor_sprite), &00, &00, &00, &00, &00, &00 | ||
| ; Each sprite's width in screen bytes. | ||
| 2866 | 0A66 | .sprite_widths←1Used as index base by← 090C LDA |
| EQUB &02, &02, &02, &02, &02, &02, &02, &02, &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, &06, &06, &02, &00, &9D, &0A, &79, &25, &00 | ||
| ; Each sprite's height in pixel rows. | ||
| 2899 | 0A99 | .sprite_heights←1Used as index base by← 0911 LDA |
| EQUB &05, &05, &05, &05, &05, &05, &05, &05, &05, &05, &05, &05, &05, &05, &05, &05, &05, &05, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &0C, &12, &12, &05, &00, &BF, &21, &D1, &0A, &63 | ||
UnusedLeftover bytes. |
||
| Load | Exec | |
|---|---|---|
| 28CC | 0ACC | EQUB &68, &61, &00, &5A, &22, &D9, &0A, &64, &69, &73, &00, &21, &1E, &00, &00, &61, &64, &64, &00, &90, &22, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &00, &FF ; Not used |
UnusedLeftover bytes, covered by the level file (&2700-&29AF) when one is loaded. |
|
| 2900 | EQUB &FF, &FF, &FF, &BF, &FF, &7F, &FF, &FF, &FE, &FE, ; No &FE, &FE, &FE, &FE, &FE, &F6, &7F, &7F, &3F, &7F, ; t &7F, &7F, &7F, &7F, &FF, &EF, &FF, &FF, &FF, &FF, ; us &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, ; ed &FE, &FE, &7E, &FE, &FE, &FE, &FE, &FE, &7F, &7F, ; : &7F, &7F, &7F, &7F, &7F, &7F, &FF, &FF, &FF, &FF, ; th &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, ; e &FF, &FF, &FE, &FE, &FE, &FE, &FE, &FE, &FE, &FE, ; le &7F, &7F, &7F, &7F, &7F, &7F, &7F, &00, &FF, &FF, ; ve &FF, &FF, &FF, &FF, &FF, &00, &FF, &FF, &FF, &FF, ; l &FF, &FF, &FF, &00, &FE, &FE, &FE, &FE, &FE, &FE, ; fi &FE, &00, &FF, &FF, &FF, &FF, &FF, &FF, &FF, &FF, ; le &FF, &00, &00, &00, &00, &00, &00, &00 ; 's ; & ; am ; p ; ; ; 29 ; 00 ; -& ; am ; p ; ; ; 29 ; AF ; wh ; en ; on ; e ; is ; lo ; ad ; ed |
| ; The level file: the level's wall block (sprite 0 in the game, ; &30 bytes). | |
| 2980 | .level_wall_block←2Used as index base by← 1EA7 STA← 2464 STA |
| EQUB &14, &3C, &3C, &28, &29, &03, &03, &16, ; Not used: &29, &03, &03, &16, &29, &03, &03, &16, ; the level's &29, &03, &03, &16, &14, &3C, &3C, &28, ; wall block &3C, &28, &14, &3C, &03, &16, &29, &03, ; when one is &03, &16, &29, &03, &03, &16, &29, &03, ; loaded &03, &16, &29, &03, &3C, &28, &14, &3C | |
| 29B0 | 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 ; Not used |
SpritesThe cursor (sprite &2C), then the 16 items (sprites 0-&0F) and the door waiting for its key (&11), each two bytes by five pixel rows. |
|
| ; Sprite &2C: the cursor. | |
| 29F6 | .cursor_sprite |
| EQUB &CC, &CC, &88, &44, &88, &44, &88, &44, &CC, &CC | |
| ; Sprites 0-&0F, the editor's items: wall, exit, energy drainer, ; trapdoor, treasure, food, teleporter, magic sword, magic ; helmet, potion, weapons, Cross, boots, the two doors and the ; key. | |
| 2A00 | .item_sprites |
| EQUB &CC, &CC, &CC, &CC, &CC, &CC, &CC, &CC, ; Sprite &00: &CC, &CC ; wall | |
| 2A0A | EQUB &03, &03, &02, &01, &02, &01, &02, &01, ; Sprite &01: &03, &03 ; exit |
| 2A14 | EQUB &33, &33, &62, &BB, &62, &BB, &62, ; Sprite &02: &BB, &33, &33 ; drainer |
| 2A1E | EQUB &3C, &3C, &29, &16, &29, &16, &29, ; Sprite &03: &16, &3C, &3C ; trapdoor |
| 2A28 | EQUB &03, &01, &43, &A9, &53, &A1, &47, ; Sprite &04: &83, &03, &01 ; treasure |
| 2A32 | EQUB &2A, &00, &3F, &0A, &01, &0B, &05, &0B, ; Sprite &05: &00, &02 ; food |
| 2A3C | EQUB &3F, &3F, &3E, &38, &3E, &38, &3E, ; Sprite &06: &38, &30, &30 ; teleporter |
| 2A46 | EQUB &A8, &41, &00, &02, &3F, &03, ; Sprite &07: magic &00, &02, &82, &54 ; sword |
| 2A50 | EQUB &00, &28, &14, &3C, &10, &30, &14, ; Sprite &08: &34, &14, &3C ; helmet |
| 2A5A | EQUB &00, &2A, &00, &0A, &05, &0B, &05, ; Sprite &09: &03, &00, &02 ; potion |
| 2A64 | EQUB &05, &01, &0A, &2B, &00, &2B, &18, ; Sprite &0A: &2B, &08, &2A ; weapons |
| 2A6E | EQUB &00, &0A, &05, &0F, &00, &0A, &00, &0A, ; Sprite &0B: &00, &00 ; cross |
| 2A78 | EQUB &00, &05, &00, &07, &01, &22, &13, &22, ; Sprite &0C: &00, &00 ; boots |
| 2A82 | EQUB &14, &2A, &14, &2A, &14, &2A, ; Sprite &0D: door &14, &2A, &14, &2A ; vertical |
| 2A8C | EQUB &00, &00, &3C, &3C, &3F, &3F, ; Sprite &0E: door &00, &00, &00, &00 ; horizontal |
| 2A96 | EQUB &00, &00, &00, &05, &0F, &0F, &0F, &05, ; Sprite &0F: &00, &00 ; key |
| ; Sprite &11: a door waiting for its key. | |
| 2AA0 | .waiting_door_sprite |
| EQUB &45, &8A, &CF, &CF, &CF, &CF, &CF, &CF, &45, &8A | |
UnusedLeftover bytes. |
|
| 2AAA | 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 ; Not used |
Move the cursorCalled at the start of every edit-loop pass, after the slow cursor's wait. Wait for the frame, rub out the cursor and put back what is under it (item_at_cursor), move with the keys in key_left, key_right, key_up and key_down (',' '.' 'A' 'Z') within the 32 by 48 map, and plot the current item there as the cursor. So the cursor shows what SPACE would place. The keys are read without waiting for release, so a held key repeats every pass. A move right skips the test for left, and a move up the test for down, so with both keys of a pair held '.' and 'A' win; the cursor can still move diagonally.
|
||||||||
| 2B00 | .move_cursor←1← 2024 JSR | |||||||
| LDA #osbyte_vsync ; Wait for the frame | ||||||||
| 2B02 | JSR osbyte ; Pace the cursor's movement to the display Wait for vertical sync | |||||||
| 2B05 | LDA #spr_blank ; Rub out the cursor (the blank sprite) | |||||||
| 2B07 | JSR plot_at_cursor ; ...at the cursor's cell | |||||||
| 2B0A | JSR item_at_cursor ; Anything in the cell under the cursor? | |||||||
| 2B0D | BMI check_right ; Empty: leave the cell blank | |||||||
| 2B0F | JSR plot_at_cursor ; Yes: redraw the wall or item the cursor covered | |||||||
| ; Move with the cursor keys, x then y. | ||||||||
| 2B12 | .check_right←1← 2B0D BMI | |||||||
| LDX key_right ; Right key, '.' (key_right), pressed? | ||||||||
| 2B14 | JSR cursor_key_pressed ; ...(Z set if pressed) | |||||||
| 2B17 | BNE check_left ; Not pressed: try left | |||||||
| 2B19 | INC cursor_x ; Yes: one column right... | |||||||
| 2B1B | BPL check_up ; ...always, skipping left; clamp_cursor limits it | |||||||
| 2B1D | .check_left←1← 2B17 BNE | |||||||
| LDX key_left ; Left key, ',' (key_left), pressed? | ||||||||
| 2B1F | JSR cursor_key_pressed ; ...(Z set if pressed) | |||||||
| 2B22 | BNE check_up ; Not pressed: try up | |||||||
| 2B24 | DEC cursor_x ; Yes: left, to at least 0 | |||||||
| 2B26 | BPL check_up ; Still 0 or more: on to up and down | |||||||
| 2B28 | LDA #0 ; Off the left: back to column 0 | |||||||
| 2B2A | STA cursor_x ; ...as the cursor's column | |||||||
| 2B2C | .check_up←3← 2B1B BPL← 2B22 BNE← 2B26 BPL | |||||||
| LDX key_up ; Up key, 'A' (key_up), pressed? | ||||||||
| 2B2E | JSR cursor_key_pressed ; ...(Z set if pressed) | |||||||
| 2B31 | BNE check_down ; Not pressed: try down | |||||||
| 2B33 | DEC cursor_y ; Yes: up, to at least 0 | |||||||
| 2B35 | BPL clamp_cursor ; Still 0 or more: down is skipped | |||||||
| 2B37 | LDA #0 ; Off the top: back to row 0 | |||||||
| 2B39 | STA cursor_y ; ...as the cursor's row | |||||||
| 2B3B | BEQ clamp_cursor ; ...skipping down (always branches) | |||||||
| 2B3D | .check_down←1← 2B31 BNE | |||||||
| LDX key_down ; Down key, 'Z' (key_down), pressed? | ||||||||
| 2B3F | JSR cursor_key_pressed ; ...(Z set if pressed) | |||||||
| 2B42 | BNE clamp_cursor ; Not pressed: no move in y | |||||||
| 2B44 | INC cursor_y ; Yes: one row down... | |||||||
| 2B46 | BPL clamp_cursor ; ...always branches; clamp_y limits it | |||||||
| ; Keep the cursor on the map, and show the current item there. | ||||||||
| 2B48 | .clamp_cursor←4← 2B35 BPL← 2B3B BEQ← 2B42 BNE← 2B46 BPL | |||||||
| LDA cursor_x ; At most column 31... | ||||||||
| 2B4A | CMP #map_width ; ...one past the right-hand column? | |||||||
| 2B4C | BNE clamp_y ; No: the column stands | |||||||
| 2B4E | LDA #map_width - 1 ; Yes: back to the right-hand column | |||||||
| 2B50 | STA cursor_x ; ...as the cursor's column | |||||||
| 2B52 | .clamp_y←1← 2B4C BNE | |||||||
| LDA cursor_y ; ...and at most row 47 | ||||||||
| 2B54 | CMP #map_height ; ...one past the bottom row? | |||||||
| 2B56 | BNE plot_cursor ; No: the row stands | |||||||
| 2B58 | LDA #map_height - 1 ; Yes: back to the bottom row | |||||||
| 2B5A | STA cursor_y ; ...as the cursor's row | |||||||
| 2B5C | .plot_cursor←1← 2B56 BNE | |||||||
| LDA current_item ; Plot the current item at the cursor... | ||||||||
| 2B5E | JSR plot_at_cursor ; ...as the cursor, over whatever is there | |||||||
| 2B61 | RTS ; Return with the cursor moved and drawn | |||||||
Plot a sprite in the cursor's cellAt screen byte column 2x and pixel row 5y: each map cell is two MODE 2 bytes (four pixels) by five pixel rows, so the 32 by 48 map fills the left 64 bytes and 240 rows of the screen. Used to draw the cursor, the cell under it and, at start-up, every cell of a loaded level.
|
|||||||||||||||
| 2B62 | .plot_at_cursor←5← 1F65 JSR← 2037 JSR← 2B07 JSR← 2B0F JSR← 2B5E JSR | ||||||||||||||
| STA sprite_number ; The sprite for plot_sprite... | |||||||||||||||
| 2B64 | LDA cursor_x ; ...at column 2x... | ||||||||||||||
| 2B66 | ASL ; ...two screen bytes per cell... | ||||||||||||||
| 2B67 | STA plot_x ; ...as plot_x | ||||||||||||||
| 2B69 | LDA cursor_y ; ...and row 5y | ||||||||||||||
| 2B6B | ASL ; ...x 2... | ||||||||||||||
| 2B6C | ASL ; ...x 4... | ||||||||||||||
| 2B6D | CLC ; ...C clear for the addition | ||||||||||||||
| 2B6E | ADC cursor_y ; ...+ y: five pixel rows per cell | ||||||||||||||
| 2B70 | STA plot_y ; ...as plot_y | ||||||||||||||
| 2B72 | JSR plot_sprite ; Plot it in the cell | ||||||||||||||
| 2B75 | RTS ; Return with the sprite drawn | ||||||||||||||
Find what is in the cursor's cellSearch the slots for an item at the cursor; failing that, look at the wall map. A free slot is item 0 at (0, 0) (see free_slot), so whenever a slot is free the top-left cell reports a wall, whatever the wall map holds there. A door is found in its slot before its wall bit is looked at. The editor's one test of a cell's contents: move_cursor, place_item, remove_at_cursor, delete_item and start_editing's drawing all use it.
|
|||||||||||||||||
| 2B76 | .item_at_cursor←5← 1F5E JSR← 2B0A JSR← 2C0D JSR← 2C29 JSR← 2D11 JSR | ||||||||||||||||
| LDX last_slot ; For slots &4F to 0, free ones included... | |||||||||||||||||
| 2B78 | .search_slots←1← 2B8B BPL | ||||||||||||||||
| LDA slot_x,x ; ...the slot's column... | |||||||||||||||||
| 2B7B | CMP cursor_x ; ...the cursor's column? | ||||||||||||||||
| 2B7D | BNE next_slot ; No: next slot | ||||||||||||||||
| 2B7F | LDA slot_y,x ; ...and the slot's row... | ||||||||||||||||
| 2B82 | CMP cursor_y ; ...the cursor's row? | ||||||||||||||||
| 2B84 | BNE next_slot ; No: next slot | ||||||||||||||||
| 2B86 | LDA slot_item,x ; Yes: return its item (0 for a free slot)... | ||||||||||||||||
| 2B89 | RTS ; ...with X its slot | ||||||||||||||||
| 2B8A | .next_slot←2← 2B7D BNE← 2B84 BNE | ||||||||||||||||
| DEX ; Next slot down | |||||||||||||||||
| 2B8B | BPL search_slots ; ...until slot 0 is tried | ||||||||||||||||
| 2B8D | JSR wall_bit ; No item: is there a wall? | ||||||||||||||||
| 2B90 | LDA (map_ptr),y ; ...the cell's wall-map byte... | ||||||||||||||||
| 2B92 | AND bit_mask ; ...its bit for the cell | ||||||||||||||||
| 2B94 | BEQ nothing_here ; Clear: nothing here | ||||||||||||||||
| 2B96 | LDA #0 ; Set: item 0, the wall | ||||||||||||||||
| 2B98 | RTS ; Return 0: a wall (Z set) | ||||||||||||||||
| 2B99 | .nothing_here←1← 2B94 BEQ | ||||||||||||||||
| ORA #&ff ; No wall: &FF | |||||||||||||||||
| 2B9B | RTS ; Return &FF: nothing (N set) | ||||||||||||||||
Find the cursor's bit in the wall mapAs the game lays out its maps: the byte at (y AND &F8) x 4 + (y AND 7) + (x AND &F8), bit 7 - (x AND 7). So each room of 8 by 8 cells is 8 consecutive bytes, one per cell row, with the leftmost cell in bit 7; four rooms make a 32-byte row of rooms, and six rows of rooms the map. Used to test, set and clear walls, a door's included. mark_object_cell repeats the calculation for the object-free map.
|
|||||||||||||||||
| 2B9C | .wall_bit←4← 2B8D JSR← 2BDE JSR← 2C19 JSR← 2C70 JSR | ||||||||||||||||
| LDA cursor_y ; Byte = (y AND &F8) x 4 + (y AND 7) + (x AND &F8) | |||||||||||||||||
| 2B9E | AND #&f8 ; ...the room row, as a multiple of 8... | ||||||||||||||||
| 2BA0 | ASL ; ...x 2... | ||||||||||||||||
| 2BA1 | ASL ; ...x 4: 32 bytes per row of rooms | ||||||||||||||||
| 2BA2 | STA map_ptr ; ...the row of rooms' offset so far | ||||||||||||||||
| 2BA4 | LDA cursor_y ; ...+ (y AND 7)... | ||||||||||||||||
| 2BA6 | AND #7 ; ...the cell's row within the room | ||||||||||||||||
| 2BA8 | CLC ; ...C clear for the addition | ||||||||||||||||
| 2BA9 | ADC map_ptr ; ...added to the offset | ||||||||||||||||
| 2BAB | STA map_ptr ; ...the offset so far | ||||||||||||||||
| 2BAD | LDA cursor_x ; ...+ (x AND &F8)... | ||||||||||||||||
| 2BAF | AND #&f8 ; ...the room's column x 8: its 8 bytes | ||||||||||||||||
| 2BB1 | CLC ; ...C clear for the addition | ||||||||||||||||
| 2BB2 | ADC map_ptr ; ...added to the offset | ||||||||||||||||
| 2BB4 | STA map_ptr ; ...map_ptr: the cell's byte | ||||||||||||||||
| 2BB6 | LDA #>(wall_map) ; ...in wall_map, page-aligned... | ||||||||||||||||
| 2BB8 | STA map_ptr_hi ; ...as map_ptr's high byte | ||||||||||||||||
| 2BBA | LDA cursor_x ; Bit 7 - (x AND 7)... | ||||||||||||||||
| 2BBC | AND #7 ; ...the cell's column within the room... | ||||||||||||||||
| 2BBE | STA bit_mask ; ...kept to subtract... | ||||||||||||||||
| 2BC0 | LDA #7 ; ...from 7... | ||||||||||||||||
| 2BC2 | SEC ; ...C set for the subtraction | ||||||||||||||||
| 2BC3 | SBC bit_mask ; ...7 - it: the bit, leftmost cell in bit 7 | ||||||||||||||||
| 2BC5 | BEQ bit_0 ; Bit 0: the mask is 1 | ||||||||||||||||
| 2BC7 | TAX ; ...the bit number as a count... | ||||||||||||||||
| 2BC8 | LDA #1 ; ...from bit 0... | ||||||||||||||||
| 2BCA | .shift_bit←1← 2BCC BNE | ||||||||||||||||
| ASL ; Shift the mask up a bit... | |||||||||||||||||
| 2BCB | DEX ; ...one shift fewer to go | ||||||||||||||||
| 2BCC | BNE shift_bit ; ...until it is in place | ||||||||||||||||
| 2BCE | BEQ bit_found ; ...(always branches: X reached 0) | ||||||||||||||||
| 2BD0 | .bit_0←1← 2BC5 BEQ | ||||||||||||||||
| LDA #1 ; ...the bit 0 mask | |||||||||||||||||
| 2BD2 | .bit_found←1← 2BCE BEQ | ||||||||||||||||
| STA bit_mask ; ...as bit_mask | |||||||||||||||||
| 2BD4 | LDY #0 ; Y = 0 for (map_ptr),Y | ||||||||||||||||
| 2BD6 | RTS ; Return with the cell's byte and bit | ||||||||||||||||
Put the current item in the cursor's cellplace_item's last step, once the item is allowed. Clear the cell's object-free bit, for every item, walls included; nothing in the editor sets it again, so deleted items leave clear bits. A wall sets the wall map's bit; anything else takes a free slot, and a key is recorded as the key of the link being made.
|
|||||||||||||||||
| 2BD7 | .put_item←1← 2CA0 JMP | ||||||||||||||||
| JSR mark_object_cell ; Clear the cell's object-free bit, whatever the item | |||||||||||||||||
| 2BDA | LDA current_item ; Putting down a wall? | ||||||||||||||||
| 2BDC | BNE put_in_slot ; No: put it in a slot | ||||||||||||||||
| 2BDE | JSR wall_bit ; Yes: set its bit in the wall map | ||||||||||||||||
| 2BE1 | LDA (map_ptr),y ; ...the cell's map byte... | ||||||||||||||||
| 2BE3 | ORA bit_mask ; ...with the cell's bit set... | ||||||||||||||||
| 2BE5 | STA (map_ptr),y ; ...back in the map | ||||||||||||||||
| 2BE7 | RTS ; Return with the wall in the map | ||||||||||||||||
| 2BE8 | .put_in_slot←1← 2BDC BNE | ||||||||||||||||
| LDX last_slot ; Find a free slot, from &4F down... | |||||||||||||||||
| 2BEA | .find_free_slot←1← 2BF0 BPL | ||||||||||||||||
| LDA slot_item,x ; ...is its item 0? | |||||||||||||||||
| 2BED | BEQ free_slot_found ; Yes: use it | ||||||||||||||||
| 2BEF | DEX ; ...next slot down | ||||||||||||||||
| 2BF0 | BPL find_free_slot ; ...until slot 0 is tried | ||||||||||||||||
| 2BF2 | .free_slot_found←1← 2BED BEQ | ||||||||||||||||
| LDA cursor_x ; ...and put the item in it: the cursor's column... | |||||||||||||||||
| 2BF4 | STA slot_x,x ; ...as its column | ||||||||||||||||
| 2BF7 | LDA cursor_y ; ...the cursor's row... | ||||||||||||||||
| 2BF9 | STA slot_y,x ; ...as its row | ||||||||||||||||
| 2BFC | LDA current_item ; ...the current item... | ||||||||||||||||
| 2BFE | STA slot_item,x ; ...as the slot's item | ||||||||||||||||
| 2C01 | CMP #spr_key ; Was it a key? | ||||||||||||||||
| 2C03 | BNE put_item_done ; No: the item is placed | ||||||||||||||||
| 2C05 | TXA ; Yes: this slot is the link's key... | ||||||||||||||||
| 2C06 | LDX link_index ; ...of the link taken for the waiting door | ||||||||||||||||
| 2C09 | STA link_key,x ; ...the key's slot in the link | ||||||||||||||||
| 2C0C | .put_item_done←1← 2C03 BNE | ||||||||||||||||
| RTS ; Return with the item in its slot | |||||||||||||||||
Remove what is in the cursor's celldelete_item's last step, once it has uncounted the item and dealt with any door-key link. Free an item's slot, or clear a wall's bit in the wall map. Freeing a door's slot leaves its wall bit set, so the cell then shows a wall. The cell's object-free bit is not set again. The cell is redrawn by move_cursor on the next pass.
|
|||||||||||||
| 2C0D | .remove_at_cursor←1← 2D65 JMP | ||||||||||||
| JSR item_at_cursor ; What is in the cursor's cell? | |||||||||||||
| 2C10 | BEQ clear_wall ; A wall: clear its bit | ||||||||||||
| 2C12 | BMI remove_done ; Nothing here: nothing to remove | ||||||||||||
| 2C14 | JSR free_slot ; An item: free its slot, X from item_at_cursor | ||||||||||||
| 2C17 | BEQ remove_done ; Return (always branches) | ||||||||||||
Clear the cursor's wallClear its bit in the wall map. remove_at_cursor's path for a wall, and delete_item's for a door deleted through its key, with the cursor moved to the door's cell. |
|
| 2C19 | .clear_wall←2← 2C10 BEQ← 2D9F JSR |
| JSR wall_bit ; Clear the cell's bit in the wall map | |
| 2C1C | LDA bit_mask ; ...the cell's bit... |
| 2C1E | EOR #&ff ; ...inverted: every bit but the cell's... |
| 2C20 | STA bit_mask ; ...as a mask keeping the others |
| 2C22 | LDA (map_ptr),y ; ...the cell's map byte... |
| 2C24 | AND bit_mask ; ...with the cell's bit cleared... |
| 2C26 | STA (map_ptr),y ; ...back in the map |
| 2C28 | .remove_done←2← 2C12 BMI← 2C17 BEQ |
| RTS ; Return with the cell cleared | |
Place the current item at the cursorIn an empty cell, place the current item within the limits: one exit, eight trapdoors, 20 doors (a door is also a wall), 29 objects, and a key only when a door is waiting for one, which links the two. With a key chosen, SPACE on an unlinked door makes it the door waiting for its key (sprite &11), in place of any door waiting before. A door sets its wall bit before its count is checked, so a 21st door is refused but leaves a wall. Called from the edit loop on SPACE and by wall_edges. Apart from a door given back its own sprite, nothing is drawn here: move_cursor redraws the cell on the next pass. Refusals are silent. A door and its key are linked in two steps. With the key chosen, SPACE on the door makes it wait (choose_door), and the next key placed anywhere becomes its key (place_key), taking a free link. A key with no door waiting is refused.
|
|||||||||||||||
| 2C29 | .place_item←6← 20A1 JSR← 20B7 JSR← 2231 JSR← 2238 JSR← 2247 JSR← 224E JSR | ||||||||||||||
| JSR item_at_cursor ; What is in the cursor's cell? | |||||||||||||||
| 2C2C | BMI place_in_empty ; Nothing: place the item | ||||||||||||||
| 2C2E | BEQ place_done ; A wall: nothing more can go here | ||||||||||||||
| 2C30 | CMP #spr_door_vertical ; A vertical door? | ||||||||||||||
| 2C32 | BEQ choose_door ; Yes: perhaps make it wait for a key | ||||||||||||||
| 2C34 | CMP #spr_door_horizontal ; ...or a horizontal door? | ||||||||||||||
| 2C36 | BEQ choose_door ; Yes: perhaps make it wait for a key | ||||||||||||||
| 2C38 | .place_done←1← 2C2E BEQ | ||||||||||||||
| RTS ; Occupied: refuse | |||||||||||||||
| ; An empty cell: place the item, if its limit allows. | |||||||||||||||
| 2C39 | .place_in_empty←1← 2C2C BMI | ||||||||||||||
| LDA current_item ; The current item: a wall? | |||||||||||||||
| 2C3B | BEQ place_put ; Yes: put it in the map | ||||||||||||||
| 2C3D | CMP #1 ; Placing the exit? | ||||||||||||||
| 2C3F | BEQ place_exit ; Yes: only one | ||||||||||||||
| 2C41 | CMP #3 ; Placing a trapdoor? | ||||||||||||||
| 2C43 | BEQ place_trapdoor ; Yes: at most 8 | ||||||||||||||
| 2C45 | CMP #spr_door_vertical ; A vertical door? | ||||||||||||||
| 2C47 | BEQ place_door ; Yes: at most 20 | ||||||||||||||
| 2C49 | CMP #spr_door_horizontal ; ...or a horizontal door? | ||||||||||||||
| 2C4B | BEQ place_door ; Yes: at most 20 | ||||||||||||||
| 2C4D | CMP #spr_key ; Placing a key? | ||||||||||||||
| 2C4F | BEQ place_key ; Yes: only with a door waiting | ||||||||||||||
| 2C51 | INC object_count ; An object: count it... | ||||||||||||||
| 2C53 | LDA object_count ; ...how many now? | ||||||||||||||
| 2C55 | CMP #max_object ; ...30, one too many? | ||||||||||||||
| 2C57 | BNE place_put ; ...and place it if there are now at most 29 | ||||||||||||||
| 2C59 | DEC object_count ; Too many: uncount it | ||||||||||||||
| 2C5B | RTS ; ...and refuse the 30th object | ||||||||||||||
| 2C5C | .place_exit←1← 2C3F BEQ | ||||||||||||||
| LDA exit_placed ; The exit: only one | |||||||||||||||
| 2C5E | BNE place_refused ; Placed already: refuse | ||||||||||||||
| 2C60 | INC exit_placed ; ...it is placed now... | ||||||||||||||
| 2C62 | BNE place_put ; ...put it in (always branches) | ||||||||||||||
| 2C64 | .place_refused←3← 2C5E BNE← 2C87 BMI← 2CA7 BNE | ||||||||||||||
| RTS ; Refuse: nothing placed | |||||||||||||||
| 2C65 | .place_trapdoor←1← 2C43 BEQ | ||||||||||||||
| INC trapdoor_count ; A trapdoor: at most 8 | |||||||||||||||
| 2C67 | LDA trapdoor_count ; ...how many now? | ||||||||||||||
| 2C69 | CMP #9 ; ...9, one too many? | ||||||||||||||
| 2C6B | BNE place_put ; No: put it in | ||||||||||||||
| 2C6D | DEC trapdoor_count ; Yes: uncount it and refuse | ||||||||||||||
| 2C6F | RTS ; ...the ninth trapdoor refused | ||||||||||||||
| 2C70 | .place_door←2← 2C47 BEQ← 2C4B BEQ | ||||||||||||||
| JSR wall_bit ; A door: it is a wall too, set before the count... | |||||||||||||||
| 2C73 | LDA (map_ptr),y ; ...the cell's map byte... | ||||||||||||||
| 2C75 | ORA bit_mask ; ...with its bit set... | ||||||||||||||
| 2C77 | STA (map_ptr),y ; ...back in the map | ||||||||||||||
| 2C79 | INC door_count ; ...at most 20 | ||||||||||||||
| 2C7B | LDA door_count ; ...how many now? | ||||||||||||||
| 2C7D | CMP #max_door + 1 ; ...21, one too many? | ||||||||||||||
| 2C7F | BNE place_put ; No: put it in | ||||||||||||||
| 2C81 | DEC door_count ; Yes: uncount it and refuse... | ||||||||||||||
| 2C83 | RTS ; ...leaving its wall bit set | ||||||||||||||
| ; A key: only for the door waiting for one, which it is linked ; to. | |||||||||||||||
| 2C84 | .place_key←1← 2C4F BEQ | ||||||||||||||
| LDA pending_door_item ; A key: is a door waiting for one? | |||||||||||||||
| 2C87 | BMI place_refused ; No door waiting: refuse | ||||||||||||||
| 2C89 | JSR find_free_link ; Yes: take a free link... | ||||||||||||||
| 2C8C | LDX link_index ; ...for the waiting door... | ||||||||||||||
| 2C8F | LDA pending_door_slot ; ...the waiting door's slot... | ||||||||||||||
| 2C92 | STA link_door,x ; ...as the link's door | ||||||||||||||
| 2C95 | JSR restore_waiting_door ; ...give the door back its own sprite... | ||||||||||||||
| 2C98 | LDA #no_link ; ...and nothing waiting | ||||||||||||||
| 2C9A | STA pending_door_item ; ...no door is waiting now | ||||||||||||||
| 2C9D | JMP place_put ; Place the key, recorded in link_index's link | ||||||||||||||
| 2CA0 | .place_put←6← 2C3B BEQ← 2C57 BNE← 2C62 BNE← 2C6B BNE← 2C7F BNE← 2C9D JMP | ||||||||||||||
| JMP put_item ; Put the item in the wall map or a slot | |||||||||||||||
| ; An occupied door with the key chosen: make it the door waiting ; for its key. | |||||||||||||||
| 2CA3 | .choose_door←2← 2C32 BEQ← 2C36 BEQ | ||||||||||||||
| LDA current_item ; A door with a key chosen? | |||||||||||||||
| 2CA5 | CMP #spr_key ; ...is the key the current item? | ||||||||||||||
| 2CA7 | BNE place_refused ; No: refuse | ||||||||||||||
| 2CA9 | STX bit_mask ; Yes: is the door linked already? | ||||||||||||||
| 2CAB | LDX #max_link ; ...over links 19 to 0 | ||||||||||||||
| 2CAD | .find_linked_door←1← 2CB5 BPL | ||||||||||||||
| LDA link_door,x ; This link's door slot... | |||||||||||||||
| 2CB0 | CMP bit_mask ; ...this door's? | ||||||||||||||
| 2CB2 | BEQ door_linked ; Yes: it is linked | ||||||||||||||
| 2CB4 | DEX ; ...next link | ||||||||||||||
| 2CB5 | BPL find_linked_door ; ...until all 20 are tried | ||||||||||||||
| 2CB7 | BMI door_not_linked ; No: door not linked | ||||||||||||||
| 2CB9 | .door_linked←1← 2CB2 BEQ | ||||||||||||||
| RTS ; Linked already: nothing to do | |||||||||||||||
| 2CBA | .door_not_linked←1← 2CB7 BMI | ||||||||||||||
| LDX bit_mask ; Another door waiting? | |||||||||||||||
| 2CBC | LDA pending_door_item ; ...(the waiting door's sprite) | ||||||||||||||
| 2CBF | BMI door_waits ; None: make this door wait | ||||||||||||||
| 2CC1 | TXA ; Yes: show it as it was | ||||||||||||||
| 2CC2 | PHA ; ...keeping this door's slot | ||||||||||||||
| 2CC3 | JSR restore_waiting_door ; ...put its own sprite back | ||||||||||||||
| 2CC6 | PLA ; ...this door's slot back | ||||||||||||||
| 2CC7 | TAX ; ...into X, to make it wait | ||||||||||||||
| 2CC8 | .door_waits←1← 2CBF BMI | ||||||||||||||
| LDA slot_item,x ; This door is waiting: remember its sprite and slot... | |||||||||||||||
| 2CCB | STA pending_door_item ; ...the sprite kept in pending_door_item... | ||||||||||||||
| 2CCE | STX pending_door_slot ; ...and its slot | ||||||||||||||
| 2CD1 | LDA #spr_waiting_door ; ...and show it as waiting (sprite &11) | ||||||||||||||
| 2CD3 | STA slot_item,x ; ...in place of the door's own | ||||||||||||||
| 2CD6 | RTS ; Return with the door waiting for its key | ||||||||||||||
Show the waiting door as it wasPut the waiting door's own sprite back in its slot and plot it, by falling into plot_slot. Used by place_key when its key is placed, and by choose_door when another door is chosen to wait instead. pending_door_item is left for the caller to clear or replace.
|
|||||||||||||
| 2CD7 | .restore_waiting_door←2← 2C95 JSR← 2CC3 JSR | ||||||||||||
| LDX pending_door_slot ; The waiting door's slot... | |||||||||||||
| 2CDA | LDA pending_door_item ; ...and its own door sprite... | ||||||||||||
| 2CDD | STA slot_item,x ; ...back in the slot, then plotted | ||||||||||||
| fall through ↓ | |||||||||||||
Plot a sprite at a slot's cellAt screen byte column 2x and pixel row 5y of slot X's cell: plot_at_cursor for a cell away from the cursor: a waiting door given back its sprite, and the blank sprite over the key or door deleted with its partner.
|
|||||||||||||
| 2CE0 | .plot_slot←2← 2D58 JSR← 2D8E JSR | ||||||||||||
| STA sprite_number ; The sprite for plot_sprite... | |||||||||||||
| 2CE2 | LDA slot_x,x ; ...at column 2x... | ||||||||||||
| 2CE5 | ASL ; ...x 2: two screen bytes per cell | ||||||||||||
| 2CE6 | STA plot_x ; ...as plot_x | ||||||||||||
| 2CE8 | LDA slot_y,x ; ...and row 5y | ||||||||||||
| 2CEB | ASL ; ...x 2... | ||||||||||||
| 2CEC | ASL ; ...x 4... | ||||||||||||
| 2CED | CLC ; ...C clear for the addition | ||||||||||||
| 2CEE | ADC slot_y,x ; ...+ the row: five pixel rows per cell | ||||||||||||
| 2CF1 | STA plot_y ; ...as plot_y | ||||||||||||
| 2CF3 | JSR plot_sprite ; Plot it in the slot's cell | ||||||||||||
| 2CF6 | RTS ; Return with the sprite drawn | ||||||||||||
Find a free door-key linkThe highest link whose door is &FF, for the key being placed for the waiting door; place_key fills in its door and put_item its key. Were none free, link_index would be &FF, but a door can wait only while fewer than 20 doors are linked, so one should always be free.
|
||||||||
| 2CF7 | .find_free_link←1← 2C89 JSR | |||||||
| LDX #max_link ; For links 19 down... | ||||||||
| 2CF9 | .search_links←1← 2CFF BPL | |||||||
| LDA link_door,x ; ...is this link's door slot... | ||||||||
| 2CFC | BMI free_link_found ; ...&FF (negative)? Free: take it | |||||||
| 2CFE | DEX ; ...next link down | |||||||
| 2CFF | BPL search_links ; ...until all 20 are tried | |||||||
| 2D01 | .free_link_found←1← 2CFC BMI | |||||||
| STX link_index ; The link the waiting door and key will use | ||||||||
| 2D04 | RTS ; Return with the free link in link_index | |||||||
Free a slotZero its item and position. A free slot is therefore item 0 at (0, 0), as start_editing leaves every slot; item_at_cursor reads that as a wall in the top-left cell. Used by remove_at_cursor and by delete_item for the partner of a deleted door or key; nothing is drawn.
|
|||||||||
| 2D05 | .free_slot←3← 2C14 JSR← 2D5D JSR← 2D93 JSR | ||||||||
| LDA #0 ; Zero its item... | |||||||||
| 2D07 | STA slot_item,x ; ...so the slot is free | ||||||||
| 2D0A | STA slot_x,x ; ...and position: column 0... | ||||||||
| 2D0D | STA slot_y,x ; ...and row 0, the top-left cell | ||||||||
| 2D10 | RTS ; Return with A = 0 and Z set | ||||||||
Delete what is in the cursor's cellTAB in the edit loop, which calls show_counts after it. Uncount the item and remove it (remove_at_cursor). Deleting a door frees its link and removes its key too, but leaves the door's wall bit, so a wall shows where the door was; deleting a key frees its link and removes its door and the door's wall, moving the cursor to the door and back to do so. A door waiting for its key cannot be deleted; choosing another door to wait releases it. A wall is cleared. The edit loop repeats the delete each pass while TAB is held (see edit_loop). A key with no link, which the editor never makes, would fall out of the link search into line_x_to_graphics and return with the key still in place.
|
|||||||||||||
| 2D11 | .delete_item←1← 20CF JSR | ||||||||||||
| JSR item_at_cursor ; What is in the cursor's cell? | |||||||||||||
| 2D14 | BMI delete_remove ; Nothing: remove_at_cursor finds nothing either | ||||||||||||
| 2D16 | BEQ delete_remove ; A wall: clear it | ||||||||||||
| 2D18 | CMP #spr_waiting_door ; A waiting door? | ||||||||||||
| 2D1A | BNE delete_item_slot ; No: delete the item | ||||||||||||
| 2D1C | RTS ; Yes: it cannot be deleted | ||||||||||||
| ; Uncount the item, by its kind. | |||||||||||||
| 2D1D | .delete_item_slot←1← 2D1A BNE | ||||||||||||
| STX bit_mask ; Keep the item's slot, to match against links | |||||||||||||
| 2D1F | CMP #1 ; Deleting the exit? | ||||||||||||
| 2D21 | BEQ delete_exit ; Yes: the exit is no longer placed | ||||||||||||
| 2D23 | CMP #3 ; Deleting a trapdoor? | ||||||||||||
| 2D25 | BEQ delete_trapdoor ; Yes: one fewer trapdoor | ||||||||||||
| 2D27 | CMP #spr_door_vertical ; Deleting a vertical door? | ||||||||||||
| 2D29 | BEQ delete_door ; Yes: unlink it and delete its key | ||||||||||||
| 2D2B | CMP #spr_door_horizontal ; ...or a horizontal door? | ||||||||||||
| 2D2D | BEQ delete_door ; Yes: unlink it and delete its key | ||||||||||||
| 2D2F | CMP #spr_key ; Deleting a key? | ||||||||||||
| 2D31 | BEQ delete_key ; Yes: delete its door too | ||||||||||||
| 2D33 | DEC object_count ; An object: one fewer | ||||||||||||
| 2D35 | BPL delete_remove ; ...remove it (always branches) | ||||||||||||
| 2D37 | .delete_exit←1← 2D21 BEQ | ||||||||||||
| LDA #0 ; The exit: none placed | |||||||||||||
| 2D39 | STA exit_placed ; ...exit_placed = 0, so saving waits | ||||||||||||
| 2D3B | BEQ delete_remove ; ...remove it (always branches) | ||||||||||||
| 2D3D | .delete_trapdoor←1← 2D25 BEQ | ||||||||||||
| DEC trapdoor_count ; A trapdoor: one fewer | |||||||||||||
| 2D3F | BPL delete_remove ; ...remove it (always branches) | ||||||||||||
| ; A door: free its link, and rub out and free its key. | |||||||||||||
| 2D41 | .delete_door←2← 2D29 BEQ← 2D2D BEQ | ||||||||||||
| DEC door_count ; A door: uncount it... | |||||||||||||
| 2D43 | LDX #max_link ; ...find its link... | ||||||||||||
| 2D45 | .find_door_link_to_delete←1← 2D63 BPL | ||||||||||||
| LDA link_door,x ; This link's door slot... | |||||||||||||
| 2D48 | CMP bit_mask ; ...this door's? | ||||||||||||
| 2D4A | BNE next_door_link ; No: next link | ||||||||||||
| 2D4C | LDA #no_link ; Yes: free the link... | ||||||||||||
| 2D4E | STA link_door,x ; ...in the link table | ||||||||||||
| 2D51 | LDA link_key,x ; ...rub out its key... | ||||||||||||
| 2D54 | TAX ; ...the key's slot into X... | ||||||||||||
| 2D55 | PHA ; ...and kept on the stack | ||||||||||||
| 2D56 | LDA #spr_blank ; ...the blank sprite... | ||||||||||||
| 2D58 | JSR plot_slot ; ...rub it out in its cell | ||||||||||||
| 2D5B | PLA ; ...the key's slot back... | ||||||||||||
| 2D5C | TAX ; ...into X for free_slot | ||||||||||||
| 2D5D | JSR free_slot ; ...and free the key's slot | ||||||||||||
| 2D60 | BEQ delete_remove ; ...then remove the door (always branches) | ||||||||||||
| 2D62 | .next_door_link←1← 2D4A BNE | ||||||||||||
| DEX ; Next link down | |||||||||||||
| 2D63 | BPL find_door_link_to_delete ; ...until all 20 are tried | ||||||||||||
| 2D65 | .delete_remove←7← 2D14 BMI← 2D16 BEQ← 2D35 BPL← 2D3B BEQ← 2D3F BPL← 2D60 BEQ← 2DAC JMP | ||||||||||||
| JMP remove_at_cursor ; Remove the item itself, or clear the wall | |||||||||||||
| ; A key: free its link, and rub out, free and unwall its door, ; from the door's cell. | |||||||||||||
| 2D68 | .delete_key←1← 2D31 BEQ | ||||||||||||
| LDA cursor_x ; A key: keep its cell, the cursor's... | |||||||||||||
| 2D6A | STA line_x ; ...column in line_x... | ||||||||||||
| 2D6D | LDA cursor_y ; ...and its row... | ||||||||||||
| 2D6F | STA line_y ; ...in line_y, to come back to | ||||||||||||
| 2D72 | LDX #max_link ; Find the key's link... | ||||||||||||
| 2D74 | .find_key_link←1← 2DB0 BPL | ||||||||||||
| LDA link_key,x ; This link's key slot... | |||||||||||||
| 2D77 | CMP bit_mask ; ...this key's? | ||||||||||||
| 2D79 | BNE next_key_link ; No: next link | ||||||||||||
| 2D7B | TXA ; Yes: keep the link number... | ||||||||||||
| 2D7C | PHA ; ...on the stack | ||||||||||||
| 2D7D | LDA link_door,x ; ...take its door's slot... | ||||||||||||
| 2D80 | TAX ; ...into X, to index the slots | ||||||||||||
| 2D81 | PHA ; ...and kept on the stack | ||||||||||||
| 2D82 | LDA slot_x,x ; ...and move the cursor to the door's cell... | ||||||||||||
| 2D85 | STA cursor_x ; ...as the cursor's column... | ||||||||||||
| 2D87 | LDA slot_y,x ; ...the door's row... | ||||||||||||
| 2D8A | STA cursor_y ; ...as the cursor's row | ||||||||||||
| 2D8C | LDA #spr_blank ; ...rub out the door... | ||||||||||||
| 2D8E | JSR plot_slot ; ...in its cell | ||||||||||||
| 2D91 | PLA ; ...free its slot: the slot back... | ||||||||||||
| 2D92 | TAX ; ...into X for free_slot | ||||||||||||
| 2D93 | JSR free_slot ; ...the door's slot freed | ||||||||||||
| 2D96 | PLA ; Pull the link number back... | ||||||||||||
| 2D97 | TAX ; ...into X, to free the link | ||||||||||||
| 2D98 | DEC door_count ; Uncount the door: one fewer | ||||||||||||
| 2D9A | LDA #no_link ; Free the link... | ||||||||||||
| 2D9C | STA link_door,x ; ...in the link table | ||||||||||||
| 2D9F | JSR clear_wall ; Clear the door's wall, at the cursor... | ||||||||||||
| 2DA2 | LDA line_x ; ...and move the cursor back to the key's cell | ||||||||||||
| 2DA5 | STA cursor_x ; ...as the cursor's column | ||||||||||||
| 2DA7 | LDA line_y ; ...the key's row... | ||||||||||||
| 2DAA | STA cursor_y ; ...as the cursor's row | ||||||||||||
| 2DAC | JMP delete_remove ; Remove the key | ||||||||||||
| 2DAF | .next_key_link←1← 2D79 BNE | ||||||||||||
| DEX ; Next link down | |||||||||||||
| 2DB0 | BPL find_key_link ; ...until all 20 are tried; none: fall through | ||||||||||||
| fall through ↓ | |||||||||||||
Convert line_x to graphics xline_gx = line_x x 32: a cell is two screen bytes, four MODE 2 pixels, 32 graphics units wide. (delete_item also falls into it, harmlessly, when a key has no link.)
|
|||||||||||||
| 2DB2 | .line_x_to_graphics←1← 2E0B JSR | ||||||||||||
| LDA #0 ; Clear line_gx, the result... | |||||||||||||
| 2DB4 | STA line_gx ; ...its low byte... | ||||||||||||
| 2DB7 | STA line_gx_hi ; ...and its high byte | ||||||||||||
| 2DBA | LDA line_x ; line_gx = column x 32... | ||||||||||||
| 2DBD | ASL ; ...x 2... | ||||||||||||
| 2DBE | ASL ; ...x 4... | ||||||||||||
| 2DBF | ASL ; ...x 8 (a column is below 32: no carry) | ||||||||||||
| 2DC0 | CLC ; ...C clear (the ASL sets it anyway) | ||||||||||||
| 2DC1 | ASL ; ...x 16... | ||||||||||||
| 2DC2 | ROL line_gx_hi ; ...carry into the high byte | ||||||||||||
| 2DC5 | ASL ; ...x 32, with the carries in the high byte | ||||||||||||
| 2DC6 | ROL line_gx_hi ; ...carry into the high byte | ||||||||||||
| 2DC9 | STA line_gx ; ...the low byte, stored last | ||||||||||||
| 2DCC | RTS ; Return with the column's graphics x | ||||||||||||
Convert line_y to graphics yline_gy = &3FF - line_y x 20: a cell is five pixel rows, 20 graphics units, counted down from the top of the screen.
|
|||||||||||||
| 2DCD | .line_y_to_graphics←1← 2E11 JSR | ||||||||||||
| LDA #0 ; Clear line_gy, the result... | |||||||||||||
| 2DCF | STA line_gy ; ...its low byte... | ||||||||||||
| 2DD2 | STA line_gy_hi ; ...and its high byte | ||||||||||||
| 2DD5 | LDA line_y ; line_gy = &3FF - row x 20: row x 4... | ||||||||||||
| 2DD8 | ASL ; ...x 2... | ||||||||||||
| 2DD9 | ASL ; ...x 4 (a row is below 48: no carry) | ||||||||||||
| 2DDA | STA bit_mask ; ...row x 4, kept in bit_mask to add | ||||||||||||
| 2DDC | CLC ; ...C clear (the ASL sets it anyway) | ||||||||||||
| 2DDD | ASL ; ...x 8... | ||||||||||||
| 2DDE | ROL line_gy_hi ; ...carry into the high byte | ||||||||||||
| 2DE1 | ASL ; ...x 16... | ||||||||||||
| 2DE2 | ROL line_gy_hi ; ...carry into the high byte | ||||||||||||
| 2DE5 | STA line_gy ; ...row x 16's low byte kept | ||||||||||||
| 2DE8 | CLC ; ...plus x 4: x 20 graphics units a row | ||||||||||||
| 2DE9 | ADC bit_mask ; ...row x 4 added... | ||||||||||||
| 2DEB | STA line_gy ; ...row x 20's low byte | ||||||||||||
| 2DEE | LDA line_gy_hi ; ...and the high byte... | ||||||||||||
| 2DF1 | ADC #0 ; ...with the carry | ||||||||||||
| 2DF3 | STA line_gy_hi ; ...row x 20's high byte | ||||||||||||
| 2DF6 | LDA #&ff ; &3FF - row x 20, counting down from the top | ||||||||||||
| 2DF8 | SEC ; ...C set for the subtraction | ||||||||||||
| 2DF9 | SBC line_gy ; ...less row x 20, low byte... | ||||||||||||
| 2DFC | STA line_gy ; ...line_gy's low byte | ||||||||||||
| 2DFF | LDA #3 ; ...&3FF's high byte... | ||||||||||||
| 2E01 | SBC line_gy_hi ; ...less the high byte... | ||||||||||||
| 2E04 | STA line_gy_hi ; ...line_gy's high byte: row 0 at the top | ||||||||||||
| 2E07 | RTS ; Return with the row's graphics y | ||||||||||||
PLOT to a cellVDU 25 with plot code X and the graphics position of (line_x, line_y), the top-left corner of that cell. draw_links calls it twice a link: PLOT 68 to move to the door, PLOT 5 to draw to the key. (The A loaded before each conversion is not used.)
|
|||||||||||||||||
| 2E08 | .plot_line_point←2← 2E4E JSR← 2E66 JSR | ||||||||||||||||
| LDA line_x ; The cell's column (unused: read from line_x)... | |||||||||||||||||
| 2E0B | JSR line_x_to_graphics ; ...converted to graphics x | ||||||||||||||||
| 2E0E | LDA line_y ; ...the cell's row (likewise unused)... | ||||||||||||||||
| 2E11 | JSR line_y_to_graphics ; ...converted to graphics y | ||||||||||||||||
| 2E14 | LDA #&19 ; VDU 25, X, x, y: PLOT there... | ||||||||||||||||
| 2E16 | JSR oswrch ; ...send VDU 25, PLOT | ||||||||||||||||
| 2E19 | TXA ; ...the PLOT code, in X | ||||||||||||||||
| 2E1A | JSR oswrch ; ...send the PLOT code | ||||||||||||||||
| 2E1D | LDA line_gx ; ...graphics x, low byte... | ||||||||||||||||
| 2E20 | JSR oswrch ; ...send the x low byte | ||||||||||||||||
| 2E23 | LDA line_gx_hi ; ...graphics x, high byte... | ||||||||||||||||
| 2E26 | JSR oswrch ; ...send the x high byte | ||||||||||||||||
| 2E29 | LDA line_gy ; ...graphics y, low byte... | ||||||||||||||||
| 2E2C | JSR oswrch ; ...send the y low byte | ||||||||||||||||
| 2E2F | LDA line_gy_hi ; ...graphics y, high byte... | ||||||||||||||||
| 2E32 | JSR oswrch ; ...send the y high byte | ||||||||||||||||
| 2E35 | RTS ; Return with the point plotted | ||||||||||||||||
Draw each door-key link as a lineFor each link in use, move to the door's cell (PLOT 68) and draw a line to its key's (PLOT 5). The lines are exclusive-OR (GCOL 3, set at start-up), so the edit loop draws them when CTRL is pressed and again, rubbing them out, when it is released. Each line runs between the cells' top-left corners.
|
||||||||
| 2E36 | .draw_links←2← 20E7 JSR← 20F1 JSR | |||||||
| LDX #max_link ; For links 19 to 0... | ||||||||
| 2E38 | .draw_link←1← 2E6C BPL | |||||||
| TXA ; Keep the link number... | ||||||||
| 2E39 | PHA ; ...on the stack, as X indexes the slots | |||||||
| 2E3A | LDA link_door,x ; ...is the link in use? | |||||||
| 2E3D | BMI next_drawn_link ; Free: next link | |||||||
| 2E3F | TAX ; Yes: from the door's cell... | |||||||
| 2E40 | LDA slot_x,x ; ...the door's column... | |||||||
| 2E43 | STA line_x ; ...as line_x | |||||||
| 2E46 | LDA slot_y,x ; ...the door's row... | |||||||
| 2E49 | STA line_y ; ...as line_y | |||||||
| 2E4C | LDX #&44 ; ...PLOT 68: move absolute... | |||||||
| 2E4E | JSR plot_line_point ; ...to the door's cell, drawing nothing | |||||||
| 2E51 | PLA ; ...to the key's cell: the link number... | |||||||
| 2E52 | PHA ; ...kept on the stack again | |||||||
| 2E53 | TAX ; ...link number into X | |||||||
| 2E54 | LDA link_key,x ; ...the key's slot... | |||||||
| 2E57 | TAX ; ...into X, to index the slots | |||||||
| 2E58 | LDA slot_x,x ; ...the key's column... | |||||||
| 2E5B | STA line_x ; ...as line_x | |||||||
| 2E5E | LDA slot_y,x ; ...the key's row... | |||||||
| 2E61 | STA line_y ; ...as line_y | |||||||
| 2E64 | LDX #5 ; ...PLOT 5: line to there... | |||||||
| 2E66 | JSR plot_line_point ; ...draw the link, exclusive-OR (GCOL 3) | |||||||
| 2E69 | .next_drawn_link←1← 2E3D BMI | |||||||
| PLA ; Next link: the link number back... | ||||||||
| 2E6A | TAX ; ...into X, the countdown | |||||||
| 2E6B | DEX ; ...the link before | |||||||
| 2E6C | BPL draw_link ; ...until link 0 is done | |||||||
| 2E6E | RTS ; Return with every link drawn (or erased) | |||||||
UnusedLeftover bytes. |
|
| 2E6F | EQUB &F8, &A5, &6A, &60, &20, &A6, &11, &A2, &0B, ; Not &A0, &18, &A9, &94, &85, &0A, &A9, &2E, &85, ; used &0B, &20, &A6, &11, &A2, &08, &A0, &1A, &A9, &A8, &85, &0A, &A9, &2E, &85 |
Test a keymove_cursor's copy of key_pressed: OSBYTE &81 with the INKEY number in X, from key_left, key_right, key_up or key_down.
|
|||||||||||||
| 2E90 | .cursor_key_pressed←4← 2B14 JSR← 2B1F JSR← 2B2E JSR← 2B3F JSR | ||||||||||||
| LDY #&ff ; Y = &FF: test the key whose INKEY number is X... | |||||||||||||
| 2E92 | LDA #osbyte_inkey ; ...with OSBYTE &81, scan the keyboard | ||||||||||||
| 2E94 | JSR osbyte ; Scan it: X = Y = &FF if the key is held Test whether the key with negative INKEY number X is pressed | ||||||||||||
| 2E97 | CPX #&ff ; Z set if X and Y are both &FF | ||||||||||||
| 2E99 | BNE cursor_key_done ; X not &FF: not pressed (Z clear) | ||||||||||||
| 2E9B | CPY #&ff ; ...Z set if Y is &FF too: pressed | ||||||||||||
| 2E9D | .cursor_key_done←1← 2E99 BNE | ||||||||||||
| RTS ; Return with Z set if the key is held | |||||||||||||
