Prev: 967F Up: Map Next: 96C9
96AF: Mark a room as seen, by writing the instruction that does it
Used by the routine at ENTER_ROOM.
Sets one bit in the 19-byte map at $5E40, one bit per room, 152 rooms in all. The bit number is not known until run time, and rather than shift a mask into place the routine assembles the instruction it needs and stores it over the one below.
SET b,(HL) is $CB followed by $C6 + b * 8, so ORing the room's low three bits (already shifted up by the three RLCAs) with $C6 gives exactly the operand byte required, and it is written into SET_BIT_OP+1 -- the second byte of the SET at SET_BIT_OP.
Checked by calling it directly with a series of room numbers and reading both the map and the patched bytes back: $2A set bit 42 and left SET 2,(HL) in place, $07 set bit 7 as SET 7, $08 set bit 8 as SET 0, $4B set bit 75 as SET 3, and $97 set bit 151 as SET 7 -- the last bit the map has room for.
Input
A The room number
MARK_ROOM_VISITED 96AF LD C,A Room / 8 -- which byte of the map.
96B0 SRL C
96B2 SRL C
96B4 SRL C
96B6 LD B,$00
96B8 LD HL,$5E40 The map itself. It sits below ENTRY, so it is not part of this disassembly.
96BB ADD HL,BC
96BC RLCA Room AND 7, shifted into the bit-number field of a SET opcode.
96BD RLCA
96BE RLCA
96BF AND $38
96C1 OR $C6
96C3 LD ($96C7),A Overwrite the operand of the instruction on the next line.
SET_BIT_OP 96C6 SET 0,(HL) Reads as SET 0 here, but by the time it runs it is SET (room AND 7).
96C8 RET
Prev: 967F Up: Map Next: 96C9