Prev: CA81 Up: Map Next: CBCF
CAE7: Main game loop
Used by the routine at Cashboxes_Completed_0.
CAE7 LD A,$7F Read from the keyboard;
Port Number Bit
0 1 2 3 4
7F SPACE FULL-STOP M N B
CAE9 IN A,($FE)
CAEB RRA Was "SPACE" pressed?
CAEC JR C,$CAFB Jump forward if not.
CAEE LD A,$FE Read from the keyboard;
Port Number Bit
0 1 2 3 4
FE SHIFT Z X C V
CAF0 IN A,($FE)
CAF2 RRA Was "CAPS SHIFT" pressed?
CAF3 JR C,$CAFB Jump forward if not.
CAF5 LD HL,$CBB4 CAPS + SPACE pressed = BREAK. Abort the game.
CAF8 CALL $FD80
The game has not been aborted. Check if it is paused and loop round if so until it is unpaused.
CAFB LD A,$FE Read from the keyboard;
Port Number Bit
0 1 2 3 4
FE SHIFT Z X C V
CAFD IN A,($FE)
CAFF BIT 1,A Was 'Z' pressed? (PAUSE)
CB01 JR NZ,$CB0B Jump forward if not.
CB03 LD A,$FE Read from the keyboard;
Port Number Bit
0 1 2 3 4
FE SHIFT Z X C V
CB05 IN A,($FE)
CB07 BIT 2,A was 'X' pressed? (UNPAUSE)
CB09 JR NZ,$CB03 Loop back round if not.
The game is running.
CB0B CALL Controls Get the keyboard or joystick input from the player.
CB0E LD BC,($CE1C) Get the game speed from CE1C and delay for that amount of time.
CB12 DEC BC
CB13 LD A,B
CB14 OR C
CB15 JR NZ,$CB12
CB17 CALL $D411 Check for closed doors and movement. This routine exits here if all doors are closed and all money is collected.
At this point, the player is not moving and the phase is still in play, so look at the doors.
CB1A CALL $CBA6 Clear the temporary storage from BufferGeneral to 5BFF.
Look at door 1.
CB1D LD IX,$D165 Point to the first door at Door_Flags_01.
CB21 LD (IX+$08),$00 Clear "deposit made" flag on this door.
CB25 LD HL,$CE14 Check the contents of the first door at Door_Routine_01.
CB28 LD A,(HL) If there no character at this door, the door will point to 00 and the zero flag will be set.
CB29 INC HL
CB2A OR (HL)
CB2B PUSH AF Remember the flags.
CB2C CALL Z,Character_Chooser If the door is empty, look at putting a character in.
CB2F POP AF Restore the flags.
CB30 JR Z,$CB3F If the door was empty, skip the next bit.
There's somebody at the door.
CB32 LD HL,($CE14) Get the contents of the first door.
CB35 LD DE,$CB3F Remember a return to CB3F on the stack.
CB38 PUSH DE
CB39 LD A,$01 Looking at the first door.
CB3B LD ($CE1A),A
CB3E JP (HL) Do the action.
Look at door 2.
CB3F LD IX,$D173 Point to the second door at Door_Flags_02.
CB43 LD (IX+$08),$00 Clear "deposit made" flag on this door.
CB47 LD HL,$CE16 Check the contents of the second door at Door_Routine_02.
CB4A LD A,(HL) If there no character at this door, the door will point to 00 and the zero flag will be set.
CB4B INC HL
CB4C OR (HL)
CB4D PUSH AF Remember the flags.
CB4E CALL Z,Character_Chooser If the door is empty, look at putting a character in.
CB51 POP AF Restore the flags.
CB52 JR Z,$CB61 If the door was empty, skip the next bit.
There's somebody at the door.
CB54 LD HL,($CE16) Get the contents of the second door.
CB57 LD DE,$CB61 Remember a return to CB61 on the stack.
CB5A PUSH DE
CB5B LD A,$02 Looking at the second door.
CB5D LD ($CE1A),A
CB60 JP (HL) Do the action.
Look at door 3.
CB61 LD IX,$D181 Point to the thrd door at Door_Flags_03.
CB65 LD (IX+$08),$00 Clear "deposit made" flag on this door.
CB69 LD HL,$CE18 Check the contents of the thrd door at Door_Routine_03.
CB6C LD A,(HL) If there no character at this door, the door will point to 00 and the zero flag will be set.
CB6D INC HL
CB6E OR (HL)
CB6F PUSH AF Remember the flags.
CB70 CALL Z,Character_Chooser If the door is empty, look at putting a character in.
CB73 POP AF Restore the flags.
CB74 JR Z,$CB83 If the door was empty, skip the next bit.
There's somebody at the door.
CB76 LD HL,($CE18) Get the contents of the door.
CB79 LD DE,$CB83 Remember a return to CB83 on the stack.
CB7C PUSH DE
CB7D LD A,$03 Looking at the third door.
CB7F LD ($CE1A),A
CB82 JP (HL) Do the action.
After taking action on all three doors, see if the player made a mistake.
CB83 LD A,($D2FE) If bit 0 of Mistakes is not zero then jump to CD47 and lose a life.
CB86 BIT 0,A
CB88 JP NZ,$CD47
CB8B BIT 1,A Else if bit 1 is not zero, jump to Flash_Lives and flash a life counter.
CB8D JP NZ,Flash_Lives
CB90 CALL Scoring Apply scoring.
CB93 LD HL,$D190 If we got money (set by 01 in D190), collect it.
CB96 LD A,(HL)
CB97 AND A
CB98 LD (HL),$00
CB9A CALL NZ,$CBA0
CB9D JP $CAE7 Go round the main loop again.
This routine plays the "collect" effect and redraws the money boxes.
CBA0 CALL Dollar_Scroll_0 Play the "collect money" effect.
CBA3 JP $CC9B Redraw the cash boxes.
This routine is called each time round the loop, and clears out any temporary storage used when acting on a character.
CBA6 LD HL,$5B00 Blanks FF bytes from BufferGeneral onwards, then returns.
CBA9 LD DE,$5B01
CBAC LD BC,$00FF
CBAF LD (HL),$00
CBB1 LDIR
CBB3 RET
This code and data is copied to Print_TwoToneText_Alias.
Copied_5B80 CBB4 JP Print_TwoToneText
CBB7 JP Life_Images
CBBA DEFW Lives
CBBC LD HL,($CE12)
CBBF JP (HL)
CBC0 JP Scoring_Prep
CBC3 JP Character_Address
CBC6 JP Copy_Routine
CBC9 JP Merge_Shot
CBCC JP Draw_Score
Prev: CA81 Up: Map Next: CBCF