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 The stack grows down from StackTop.
Start in the first room with an empty inventory.
5ED4 CALL PrepareGame Call PrepareGame to prepare a new game.
5ED7 XOR A The picture has not been drawn yet.
5ED8 LD ($6185),A
5EDB 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 Write 00 to *RepeatCounter.
5EDF LD ($5D8E),A
5EE2 CALL RunPriorityScripts Call RunPriorityScripts to run the high-priority scripts.
5EE5 LD A,($5B95) Jump to GameLoop_Draw when the room stayed the same.
5EE8 OR A
5EE9 JR Z,GameLoop_Draw
5EEB CALL DescribeLocation Call DescribeLocation to describe the new room.
Draw the illustration once for this room, then either repeat or ask for a command.
GameLoop_Draw 5EEE CALL DrawRoomOnce Call DrawRoomOnce to draw the picture if this room is not already on screen.
5EF1 XOR A Write 00 to *RoomChanged.
5EF2 LD ($5B95),A
5EF5 LD A,($5D8E) Jump to ObeyCommand_Repeat while a script asked for another look.
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 to read the next command from bank 3.
5EFE LD A,($5B7F) Jump to ObeyCommand when a verb was recognised.
5F01 OR A
5F02 JR NZ,ObeyCommand
5F04 LD A,($5B80) Jump to ObeyCommand when a noun was recognised.
5F07 OR A
5F08 JR NZ,ObeyCommand
5F0A LD A,$0B Message 0B: that input contained no recognised words.
5F0C CALL PrintSystemMessage
5F0F XOR A A failed line does not keep a comma continuation.
5F10 LD ($5B85),A
5F13 JR GameLoop_Act Jump to GameLoop_Act for another turn.
Prev: 5ECA Up: Map Next: 5F15