Prev: 40134 Up: Map Next: 40257
40227: Visit Room
Used by the routines at EnterRoomBelow and InitialiseGame.
Marks the room that an actor is in as having been visited, by setting its bit in the bitmap at VisitedRooms (the bitmap holds one bit for each of the 0256 rooms). This uses self-modifying code: the second byte of the "SET n,(HL)" instruction at 40254 is overwritten to select the bit.
Input
IX Actor record
Work out which byte of the bitmap holds the bit for the room.
VisitRoom 40227 LD A,(IX+1) Fetch the room of the actor.
40230 LD C,A Stash the room in C.
40231 RRCA Divide the room by 8 (each byte of the bitmap holds the bits for 8 rooms).
40232 RRCA
40233 RRCA
40234 AND %00011111 Keep only bits 0-4.
40236 LD L,A Use it as the offset into the visited rooms bitmap.
40237 LD H,0
Work out which bit of that byte is needed and modify the instruction.
40239 LD A,C Fetch the room.
40240 RLCA Multiply by 8 so that the low three bits of the room are in bits 3-5.
40241 RLCA
40242 RLCA
40243 AND %00111000 Keep only the bit number (bits 3-5).
40245 OR %11000110 Set bits 1-2, 6-7 (to make the second byte of "SET n,(HL)").
40247 LD (40255),A Write this into the second byte of the instruction at 40254.
Set the bit.
40250 LD BC,38591 Add the start of the visited rooms bitmap at VisitedRooms to the offset.
40253 ADD HL,BC
40254 SET 0,(HL) Set the bit for the room in the bitmap.
40256 RET Return.
View the equivalent code in;
Prev: 40134 Up: Map Next: 40257