Prev: 5ECA Up: Map Next: 5F15
5ECB: Game Loop
Used by the routines at OfferAnotherGame, Restored and StartGame.
Runs the adventure. It prepares a new game, describes the room, runs the location scripts, draws the picture, then reads a command and obeys it. A ROM error returns with the stack at ErrorStack.
Install the word at ErrorStack as the ROM error handler and give the game its own stack.
GameLoop 5ECB LD HL,$6B41 Store ErrorStack in ERR_SP.
5ECE LD ($5C3D),HL
5ED1 LD SP,$5D84 SP=StackTop.
Start in the first room with an empty inventory.
5ED4 CALL PrepareGame Call PrepareGame.
5ED7 XOR A Clear *PictureDrawn.
5ED8 LD ($6185),A
Describe the first room.
5EDB CALL DescribeLocation Call DescribeLocation.
This entry point is used by the routines at ObeyCommand and RefuseCommand.
Run the high-priority scripts, and describe the room again if they moved the player.
GameLoop_Act 5EDE XOR A Clear *RepeatCounter.
5EDF LD ($5D8E),A
5EE2 CALL RunPriorityScripts Call RunPriorityScripts.
5EE5 LD A,($5B95) Jump to GameLoop_Draw if *RoomChanged is unset.
5EE8 OR A
5EE9 JR Z,GameLoop_Draw
Describe the new room.
5EEB CALL DescribeLocation Call DescribeLocation.
Draw the illustration once for this room, then either repeat or ask for a command.
GameLoop_Draw 5EEE CALL DrawRoomOnce Call DrawRoomOnce.
5EF1 XOR A Clear *RoomChanged.
5EF2 LD ($5B95),A
5EF5 LD A,($5D8E) Jump to ObeyCommand_Repeat if *RepeatCounter is set.
5EF8 OR A
5EF9 JR NZ,ObeyCommand_Repeat
Read a command. An empty line is a complaint, not an action.
5EFB CALL ReadCommand Call ReadCommand.
5EFE LD A,($5B7F) Jump to ObeyCommand if *Verb is set.
5F01 OR A
5F02 JR NZ,ObeyCommand
5F04 LD A,($5B80) Jump to ObeyCommand if *Noun is set.
5F07 OR A
5F08 JR NZ,ObeyCommand
Print "that input contained no recognised words.".
5F0A LD A,$0B Print SystemMessage_0B using PrintSystemMessage.
5F0C CALL PrintSystemMessage
5F0F XOR A Clear *Continuation. After ShapeIfPresent this can instead write 00 at CommandBuffer plus the last pictured object.
5F10 LD ($5B85),A
Start another turn.
5F13 JR GameLoop_Act Jump to GameLoop_Act.
Prev: 5ECA Up: Map Next: 5F15