Prev: 43927 Up: Map Next: 44034
43958: Handler: Display Room Image
Used by the routines at LoadTape, 60176 and Action_Look.
Determines if the current room has an image relating to it, and if it does - it jumps to the routine to display it.
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.
Handler_DisplayRoomImage 43958 LD A,(42988) Jump to Handler_RoomExits if *Count_RoomsWithImages is set to zero.
43961 OR A
43962 JR Z,Handler_RoomExits
The version of the game being played DOES have graphics, so continue.
43964 LD A,(42947) Fetch *CurrentRoom and load it into A.
43967 LD HL,(42958) Fetch the address of the table from *Pointer_RoomsWithImages.
43970 LD BC,(42988) Fetch the count of the number of rooms in the table from *Count_RoomsWithImages.
43974 CPIR Search to see if the current room ID is in the table.
43976 JR NZ,Handler_RoomExits Jump to Handler_RoomExits if the current room ID does not appear in the table.
The current room does have an image associated with it.
43978 LD A,(42988) Calculate the index of the current room in the table.
43981 INC C
43982 SUB C
43983 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.
43984 XOR A Jump to DisplayRoomImage if E was set to 1 (Display the image).
43985 OR E
43986 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").
43988 LD HL,42868 HL=Table_RoomImagesAlreadySeen.
43991 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 43992 CP 8 Jump to FoundAlreadySeenByte if the room index is less than 8.
43994 JR C,FoundAlreadySeenByte
43996 SUB 8 Subtract 8 (number of bits in a byte) from the room index.
43998 INC HL Increment the "image already seen" table pointer by one.
43999 JR FindAlreadySeenByte_Loop Jump back to FindAlreadySeenByte_Loop.
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 44001 LD B,A Copy the "image already seen" byte into B.
44002 INC B Increment B by one to get the correct number of shifts.
44003 LD D,0 Start with all bits clear in D.
AlreadySeenBitShift_Loop 44005 RL D Rotate 1 bit left into position.
44007 DJNZ AlreadySeenBitShift_Loop Decrease the shift counter by one and loop back to AlreadySeenBitShift_Loop until the bit is in the correct position.
Test the bit held in D against the room flag.
44009 LD A,(HL) Fetch the current room flag.
44010 AND D If the room image has already been seen ... jump to Handler_RoomExits.
44011 JR NZ,Handler_RoomExits
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.
44013 LD A,(HL) Merge the set room bit with the room flags and write the result back to the room flag byte.
44014 OR D
44015 LD (HL),A
Finally! Display the room image.
DisplayRoomImage 44016 PUSH BC Temporarily stash BC on the stack.
44017 CALL ClearScreen Call ClearScreen.
44020 POP BC Restore BC from the stack.
44021 LD IX,(42960) Fetch the address of the table from *Pointer_RoomImage.
44025 LD E,C Load the location image index into E.
44026 CALL GetTableEntry Call GetTableEntry.
44029 LD DE,44034 Push Handler_RoomExits onto the stack so that the next return will go on to show the room exits.
44032 PUSH DE
44033 JP (HL) Jump to the routine pointed to by *HL to display the room image.
Prev: 43927 Up: Map Next: 44034