Prev: 46080 Up: Map Next: 46187
46111: Handler: Display Room Image
Used by the routines at LoadFromTape, Handler_ShowNewRoom and Action_Look.
Show the picture for the current room when that room has one.
Input
E 1 If the image should be displayed, 0 if it should be skipped
The game can also load without any graphics at all, so bail if there's nothing needed to do here.
HandlerDisplayRoomImage 46111 LD A,(44790) Jump to HandlerDisplayRoomExits if the picture-room count is set to zero.
46114 OR A
46115 JR Z,HandlerDisplayRoomExits
The version of the game being played DOES have graphics, so continue.
46117 LD A,(44749) Fetch the current room and load it into A.
46120 LD HL,(44760) Fetch the address of the table from the rooms-with-images pointer.
46123 LD BC,(44790) Fetch the count of the number of rooms in the table from the picture-room count.
46127 CPIR Search to see if the current room ID is in the table.
46129 JR NZ,HandlerDisplayRoomExits Jump to HandlerDisplayRoomExits if the current room ID does not appear in the table.
The current room does have an image associated with it.
46131 LD A,(44790) Read the picture-room count into A.
46134 INC C Turn the picture search into this room's image index.
46135 SUB C
46136 LD C,A
The E register is used as a flag to indicate that the room image should not be displayed, e.g. after the player has requested to view their inventory and have seen the room image already when they entered the location.
46137 XOR A Jump to DisplayRoomImage if E was set to 1 (Display the image).
46138 OR E
46139 JR NZ,DisplayRoomImage
The game also maintains a table of "already seen room images" so the player doesn't have to view an image for a room they've already been in.
The player can view it manually by typing "LOOK" (or just "L").
46141 LD HL,44670 Point HL at the room-image-seen flags.
46144 LD A,C Copy the room image index into A.
Only two bytes hold the data for all 12 rooms with images so first - find the correct byte which references this room.
FindAlreadySeenByte_Loop 46145 CP 8 Jump to FoundAlreadySeenByte if the room index is less than 8.
46147 JR C,FoundAlreadySeenByte
46149 SUB 8 Move this room into the next flag byte.
46151 INC HL Increment the "image already seen" table pointer by one.
46152 JR FindAlreadySeenByte_Loop Jump back to FindAlreadySeenByte_Loop until the flag byte for this room is found.
Now the correct byte has been found, check the appropriate bit.
Create a mask with a single bit set corresponding to this rooms position (0-7) in the byte.
FoundAlreadySeenByte 46154 LD B,A Copy the "image already seen" byte into B.
46155 INC B Include a shift for bit 0.
46156 LD D,0 Start with all bits clear in D.
AlreadySeenBitShift_Loop 46158 RL D Slide this room's bit into place.
46160 DJNZ AlreadySeenBitShift_Loop
Test the bit held in D against the room flag.
46162 LD A,(HL) Fetch the current room flag.
46163 AND D If the room image has already been seen ... jump to HandlerDisplayRoomExits.
46164 JR NZ,HandlerDisplayRoomExits
The room image hasn't already been seen, so update the bit to indicate that the player will have viewed it for the next time this routine runs.
46166 LD A,(HL) Merge the set room bit with the room flags and write the result back to the room flag byte.
46167 OR D
46168 LD (HL),A
Finally! Display the room image.
DisplayRoomImage 46169 PUSH BC Call ClearScreen to clear the screen, keeping the location image index in C.
46170 CALL ClearScreen
46173 POP BC
46174 LD IX,(44762) Fetch the address of the table from the room-image jump pointer.
46178 LD E,C Load the location image index into E.
46179 CALL GetTableEntry Call GetTableEntry to look up the table entry.
46182 LD DE,46187 Push HandlerDisplayRoomExits onto the stack so that the next return will go on to show the room exits.
46185 PUSH DE
46186 JP (HL) Jump to the routine pointed to by *HL to display the room image.
View the equivalent code in;
Prev: 46080 Up: Map Next: 46187