Prev: 32154 Up: Map Next: 32291
32195: 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 32195 LD SP,24064 Set stack pointer to 24064.
32198 EI Enable interrupts.
32199 XOR A Reset the number of creatures in NumCreatures to zero.
32200 LD (24101),A
32203 LD IX,60072 Point IX at the first entity after the three fixed entities at ItemEntities.
32207 LD A,(24084) Jump to MainLoop_Entities if the entities in the room have already been drawn (bit 0 of GameFlags is set).
32210 BIT 0,A
32212 JR NZ,MainLoop_Entities
32214 LD IX,61152 Point IX at the end of the entity table, so that no entities are processed at RoomItemEntities.
32218 JR DrawRoom Jump to DrawRoom to draw the room.
Each pass of this loop considers one of the 8-byte entities.
MainLoop_Entities 32220 LD A,(23672) Fetch the low byte of FRAMES into C (using A).
32223 LD C,A
32224 LD A,(24067) Fetch the FRAMES value from the previous pass.
32227 CP C Call UpdateFixedEntities if FRAMES has changed since it was last stored in LastFrame.
32228 CALL NZ,UpdateFixedEntities
32231 LD A,(60049) Fetch the room of the player.
32234 CP (IX+1) Compare it with the room of this entity.
32237 LD HL,32243 Point HL at the address for the handler to return to at MainLoop_NextEntity.
32240 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 32243 LD DE,8 DE=0008 (the size of an entity).
32246 ADD IX,DE Move IX on to the next entity.
32248 PUSH IX Copy IX to HL (using the stack).
32250 POP HL
32251 LD DE,61024 Point DE at the end of the 8-byte entities at CreatureRecords.
32254 AND A Jump back to MainLoop_Entities until IX reaches CreatureRecords.
32255 SBC HL,DE
32257 JR C,MainLoop_Entities
Now work through the 16-byte records. These are processed no matter which room the player is in.
MainLoop_Records 32259 LD A,(23672) Fetch the low byte of FRAMES into C (using A).
32262 LD C,A
32263 LD A,(24067) Fetch the FRAMES value from the previous pass.
32266 CP C Call UpdateFixedEntities if FRAMES has changed since it was last stored in LastFrame.
32267 CALL NZ,UpdateFixedEntities
32270 LD HL,32275 Point HL at the address for the handler to return to at MainLoop_NextRecord.
32273 JR ProcessAction Jump to ProcessAction to process the record.
MainLoop_NextRecord 32275 LD DE,16 DE=0016 (the size of a record).
32278 ADD IX,DE Move IX on to the next record.
32280 PUSH IX Copy IX to HL (using the stack).
32282 POP HL
32283 LD DE,61152 Point DE at the end of the entity table at RoomItemEntities.
32286 AND A Jump back to MainLoop_Records until IX reaches RoomItemEntities.
32287 SBC HL,DE
32289 JR C,MainLoop_Records
Prev: 32154 Up: Map Next: 32291