Prev: 7D9A Up: Map Next: 7E23
7DC3: Run Main Loop
Used by the routines at DrawRoom and EnterRoom.
Runs the game one entity at a time. Whenever FRAMES has changed since the last time, UpdateFixedEntities runs the handlers of the three fixed entities starting at Player. Each entity from ItemEntities onwards that is in the same room as the player is then given to ProcessAction, and every 16-byte record from CreatureRecords onwards after that. Finally the room items are processed by DrawRoom. If the room has not been drawn yet (bit 0 of GameFlags is clear) the entities are skipped and DrawRoom is run immediately.
MainLoop 7DC3 LD SP,$5E00 Set stack pointer to 5E00.
7DC6 EI Enable interrupts.
7DC7 XOR A Reset the number of creatures in NumCreatures to zero.
7DC8 LD ($5E25),A
7DCB LD IX,$EAA8 Point IX at the first entity after the three fixed entities at ItemEntities.
7DCF LD A,($5E14) Jump to MainLoop_Entities if the entities in the room have already been drawn (bit 0 of GameFlags is set).
7DD2 BIT 0,A
7DD4 JR NZ,MainLoop_Entities
7DD6 LD IX,$EEE0 Point IX at the end of the entity table, so that no entities are processed at RoomItemEntities.
7DDA JR DrawRoom Jump to DrawRoom to draw the room.
Each pass of this loop considers one of the 8-byte entities.
MainLoop_Entities 7DDC LD A,($5C78) Fetch the low byte of FRAMES into C (using A).
7DDF LD C,A
7DE0 LD A,($5E03) Fetch the FRAMES value from the previous pass.
7DE3 CP C Call UpdateFixedEntities if FRAMES has changed since it was last stored in LastFrame.
7DE4 CALL NZ,UpdateFixedEntities
7DE7 LD A,($EA91) Fetch the room of the player.
7DEA CP (IX+$01) Compare it with the room of this entity.
7DED LD HL,$7DF3 Point HL at the address for the handler to return to at MainLoop_NextEntity.
7DF0 JP Z,ProcessAction Process the entity with ProcessAction if it is in the same room as the player.
Move on to the next 8-byte entity.
MainLoop_NextEntity 7DF3 LD DE,$0008 DE=0008 (the size of an entity).
7DF6 ADD IX,DE Move IX on to the next entity.
7DF8 PUSH IX Copy IX to HL (using the stack).
7DFA POP HL
7DFB LD DE,$EE60 Point DE at the end of the 8-byte entities at CreatureRecords.
7DFE AND A Jump back to MainLoop_Entities until IX reaches CreatureRecords.
7DFF SBC HL,DE
7E01 JR C,MainLoop_Entities
Now work through the 16-byte records. These are processed no matter which room the player is in.
MainLoop_Records 7E03 LD A,($5C78) Fetch the low byte of FRAMES into C (using A).
7E06 LD C,A
7E07 LD A,($5E03) Fetch the FRAMES value from the previous pass.
7E0A CP C Call UpdateFixedEntities if FRAMES has changed since it was last stored in LastFrame.
7E0B CALL NZ,UpdateFixedEntities
7E0E LD HL,$7E13 Point HL at the address for the handler to return to at MainLoop_NextRecord.
7E11 JR ProcessAction Jump to ProcessAction to process the record.
MainLoop_NextRecord 7E13 LD DE,$0010 DE=0010 (the size of a record).
7E16 ADD IX,DE Move IX on to the next record.
7E18 PUSH IX Copy IX to HL (using the stack).
7E1A POP HL
7E1B LD DE,$EEE0 Point DE at the end of the entity table at RoomItemEntities.
7E1E AND A Jump back to MainLoop_Records until IX reaches RoomItemEntities.
7E1F SBC HL,DE
7E21 JR C,MainLoop_Records
Prev: 7D9A Up: Map Next: 7E23