Prev: 7DC3 Up: Map Next: 7E7E
7E23: Draw Room
Used by the routine at MainLoop.
Reached at the end of every pass of MainLoop. Looks up the list of items for the current room in RoomTable and runs the handler of each one through ProcessRoomItem. Each entry in a list is the address of an item record in the initial entity data at Initialisation_Player. Once the list is finished the counter at CounterLow is incremented and, on the first pass, DrawRoomEntities draws all of the entities in the room and bit 0 of GameFlags is set. The random number seed at RandomSeed is then stirred, the pick-up key, the pause keys and the food are dealt with and the main loop is restarted, unless the player is in room 8E which ends the game with GameComplete.
Before After
draw-room-before draw-room-after
DrawRoom 7E23 LD A,($EA91) Fetch the room of the player.
7E26 LD L,A Double the room number to create an offset in HL.
7E27 LD H,$00
7E29 ADD HL,HL
7E2A LD BC,$757D Find the entry for the room in the table of item lists at RoomTable.
7E2D ADD HL,BC
7E2E LD A,(HL) Fetch the address of the list of items for the room.
7E2F INC HL
7E30 LD H,(HL)
7E31 LD L,A
7E32 LD ($5E1B),HL Update the room pointer in CurrentRoom.
Each pass of this loop reads one item from the list.
Decor_Loop 7E35 LD HL,($5E1B) Fetch the pointer to the next entry in the list of items.
7E38 LD A,(HL) Fetch the low byte of the item address.
7E39 INC HL Move on to the next entry in the list and write the pointer to CurrentRoom.
7E3A INC HL
7E3B LD ($5E1B),HL
7E3E DEC HL Fetch the address of the item.
7E3F LD H,(HL)
7E40 LD L,A
7E41 OR H Jump to ProcessRoomItem to process the item if the list has not ended (the item address is not zero).
7E42 JR NZ,ProcessRoomItem
The list is finished (it is terminated by an address of 00).
7E44 LD HL,($5E12) Increment the counter held in CounterLow by one.
7E47 INC HL
7E48 LD ($5E12),HL
7E4B LD HL,$5E14 Jump to DrawRoom_Finish if bit 0 of GameFlags is set (the entities are drawn).
7E4E BIT 0,(HL)
7E50 JR NZ,DrawRoom_Finish
7E52 CALL DrawRoomEntities Call DrawRoomEntities to draw the entities in this room.
DrawRoom_Finish 7E55 LD HL,$5E14 Set bit 0 of GameFlags.
7E58 SET 0,(HL)
Stir the random number seed with FRAMES and the counter.
7E5A LD HL,($5E05) Fetch the random seed.
7E5D LD DE,($5C78) Fetch FRAMES.
7E61 ADD HL,DE Add FRAMES to the random seed.
7E62 LD A,($5E12) Fetch the low byte of the counter.
7E65 ADD A,L Add the counter to the random seed.
7E66 LD L,A
7E67 LD ($5E05),HL Store the new random seed.
Read the pick-up key, check for the game being paused and spawn food.
7E6A CALL ReadPickupKey Call ReadPickupKey to read the key to pick up an item.
7E6D CALL PauseGame Call PauseGame to check whether the game is paused.
7E70 CALL SpawnFood Call SpawnFood to spawn the food.
Finish the game if the player has reached the final room.
7E73 LD A,($EA91) Fetch the room of the player.
7E76 CP $8E Jump to GameComplete if the player is in room 8E.
7E78 JP Z,GameComplete
7E7B JP MainLoop Jump back to MainLoop to run the next pass of the main loop.
Prev: 7DC3 Up: Map Next: 7E7E