Prev: 37296 Up: Map Next: 37402
37312: Run Game
Used by the routine at Select_Game_Options.
Starts a new game and then runs the main loop forever.
The loop at Main_Loop goes through the object records one at a time. Byte 0 of a record is the type of the object, which is used as an index into the Object_Handler_Table handler table. The handler is run with IX pointing at the record and with Finish_Object_Pass stacked as its return address, so every handler ends by returning to Finish_Object_Pass which moves on to the next record.
Start a new game: empty the room table, clear the workspace and the objects, and clear the screen.
Run_Game 37312 CALL Reset_Room_Table Empty the room visit table.
37315 CALL Clear_Workspace Clear the sprite workspace, the score and the other variables.
37318 CALL Clear_Object_Records Clear all of the object records except the first two.
37321 CALL Clear_Attributes Set every attribute to white ink on black paper.
37324 CALL Clear_Screen Clear the screen.
37327 CALL Clear_Collected_Flags Set up the fifth small object record.
Set up Sabreman and draw the status panel and the room.
37330 CALL Reset_Sabreman Copy the template of Sabreman into his object record.
37333 LD IX,36634 Point at the object record of Sabreman (Sabreman_Record).
37337 CALL Draw_Lives Draw the lives icon and the number of lives.
37340 CALL Print_Status_Panel Print the status panel.
37343 CALL Print_Score_Label Print the word SCORE and the score.
37346 CALL Draw_Room Draw the room. This does not return: it resets the stack and jumps to Main_Loop.
This entry point is used by the routine at Finish_Object_Pass.
This is the main loop. The normal pass starts with Sabreman's record, unless his type is from 9 to 27. Those types are handled with the priority records (see Finish_Object_Pass_Priority_Records), so then the pass starts with the record after his. The first two records are only ever handled as priority records.
Main_Loop 37349 EI Enable interrupts.
37350 LD IX,36634 Point at the object record of Sabreman (Sabreman_Record).
37354 LD A,(36634) Fetch the type of Sabreman.
37357 CP 28 Jump to Run_Game_Spawn_Creatures if the type is greater than or equal to 28.
37359 JR NC,Run_Game_Spawn_Creatures
37361 CP 9 Jump to Run_Game_Spawn_Creatures if the type is less than 9.
37363 JR C,Run_Game_Spawn_Creatures
37365 LD IX,36650 Point at the record after Sabreman's (Rope_Record).
Give the creature spawners a chance to run, then run the handler of the object that IX points at.
Run_Game_Spawn_Creatures 37369 CALL Spawn_Falling_Stalactite Maybe spawn a stalactite.
37372 CALL Spawn_Flying_Creature Maybe spawn a flying creature.
37375 LD A,(43692) Fetch the room flags from Room_Flags.
37378 AND %00010000 Keep only bit 4.
37380 CALL Z,Spawn_Bubble Maybe spawn a bubble if bit 4 is not set.
This entry point is used by the routines at Finish_Object_Pass and Draw_Room.
Run the handler of the object that IX points at.
Run_Object_Handler 37383 LD HL,37977 Point at the return address of the handler (Finish_Object_Pass).
This entry point is used by the routine at Finish_Object_Pass.
Run_Object_Handler_Stash_Return 37386 PUSH HL Stash it on the stack.
37387 LD BC,37402 Point at the handler table (Object_Handler_Table).
37390 LD L,(IX+0) Fetch the type of the object.
This entry point is used by the routine at Finish_Object_Pass.
Run_Object_Handler_Look_Up 37393 LD H,0 Clear H so that HL holds the type.
37395 ADD HL,HL Double the type to get the offset of its handler in the table.
37396 ADD HL,BC Add the address of the table.
37397 LD A,(HL) Fetch the low byte of the handler address.
37398 INC HL Move on to the high byte.
37399 LD H,(HL) Fetch the high byte of the handler address.
37400 LD L,A Copy the low byte of the handler address to L.
37401 JP (HL) Jump to the handler.
Prev: 37296 Up: Map Next: 37402