Prev: 38024 Up: Map Next: 38429
38205: Main game loop: Process keyboard input and move Magic Knight or enter menus
Used by the routines at 41578 and 64926.
38205 CALL 38844 Draw Magic Knight's current room, draw objects and characters and initialise room-specific data
This entry point is used by the routine at 38024.
38208 CALL 40008 Set Magic Knight's velocity to zero, if appropriate move to new room, update state of Storm Cloud and execute room-specific routine
38211 CALL 38434 Handle Magic Knight's fall
38214 LD A,127 Reset bit 7 in A to select the keyboard half-row SPACE - B
38216 IN A,(254) Read the keyboard
38218 RRA Reset carry flag if SPACE pressed, else set it
38219 JR C,38232 SPACE was not pressed, so skip ahead to 38232
38221 LD A,254 Reset bit 0 in A to select the keyboard half-row SHIFT - V
38223 IN A,(254) Read the keyboard
38225 RRA Reset carry flag if SHIFT pressed, else set it
38226 LD HL,50809 Point HL at "BREAK KEY PRESSED" text
38229 JP NC,64582 If SHIFT was pressed (i.e. SHIFT-SPACE, or BREAK) jump to "game over" window routine and return to control selection menu
38232 CALL 38585 Kill Magic Knight's x-velocity if he cannot horizontally pass through a block beside him
38235 CALL 64034 Capture keyboard or joystick input loading result into A
38238 BIT 0,A If "left" pressed then...
38240 JR NZ,38272 Skip ahead to "move left" subroutine
38242 BIT 1,A If "right" pressed then...
38244 JR NZ,38312 Skip ahead to "move right" subroutine
38246 BIT 2,A If "up" pressed then...
38248 JP NZ,38329 Skip ahead to "jump" subroutine
38251 BIT 3,A If "down" pressed then...
38253 CALL NZ,64836 ...select Magic Knight's room if cheat / debug mode is enabled
38256 BIT 4,A If "fire" pressed then...
38258 JR NZ,38266 ...skip ahead to 38266
38260 CALL 61816 Wait for interrupt then erase Magic Knight from display, advance his current position then redraw
38263 JP 38208 Loop back for next key / control press
Fire pressed
38266 CALL 47592 Wait for fire button / key to be released
38269 JP 42494 Display and handle main in-game menu
Left pressed
38272 LD HL,23474 If Magic-Knight-can't-move-left flag is set...
38275 BIT 0,(HL) ...
38277 JP NZ,38208 ...then loop back to start of keyboard check routine
38280 EX AF,AF' Switch AF and AF'
38281 LD A,1 Set Magic-Knight-facing-left flag...
38283 LD (23417),A ...
38286 LD A,254 Set Magic Knight's x-velocity to minus 2...
38288 LD (24844),A ...
38291 LD (38360),A Prepare to set Magic Knight's x-velocity to minus 2
38294 EX AF,AF' Switch AF and AF' (A now holds pressed controls bitmap)
38295 BIT 2,A If "up" was also pressed...
38297 JR NZ,38333 ...then skip ahead to 38333 (jumping subroutine)
38299 XOR A Set Magic Knight's current y-velocity to zero...
38300 LD (24845),A ...
38303 CALL 61816 Wait for interrupt then erase Magic Knight from display, advance his current position then redraw
38306 CALL 38434 Handle Magic Knight's fall
38309 JP 38208 Loop back for next key / control press
Right pressed
38312 LD HL,23474 If Magic-Knight-can't-move-right flag is set...
38315 BIT 1,(HL) ...
38317 JP NZ,38208 ...then loop back to start of keyboard check routine
38320 EX AF,AF' Switch AF and AF'
38321 XOR A Reset Magic-Knight-facing-left flag...
38322 LD (23417),A ...
38325 LD A,2 Jump to 38288, setting Magic Knight's x-velocity to 2...
38327 JR 38288 ...
Up pressed
38329 XOR A Prepare to set Magic Knight's x-velocity to zero...
38330 LD (38360),A ...
38333 LD HL,49019 Point HL at start of Magic Knight's y-velocities sequence table
38336 LD (23442),HL Store current position in Magic Knight's y-velocities sequence table at 23442
38339 LD A,(24841) Load A with Magic Knight's current y-coordinate (pixels)
38342 CP 8 If y-coordinate is less than 8...
38344 JP C,38413 ...then jump to 38413 (exit loop as Magic Knight can't get any higher!)
38347 LD HL,(23442) Load HL with current position in Magic Knight's y-velocities sequence table
38350 LD A,(HL) Load the current y-velocity in the sequence into A
38351 NEG Negate (as Magic Knight is jumping upwards)
38353 OR A If A is zero...
38354 JR Z,38413 ...jump to 38413 (exit loop as we have reached the end of the sequence)
38356 LD (24845),A Load A into Magic Knight's y-velocity
The operand of the instruction at 38359 represents the x-velocity value stored previously. This is modified by the instructions at 38291, 38330 and 38423.
38359 LD A,0 Set Magic Knight's x-velocity...
38361 LD (24844),A ...
38364 CALL 38585 Kill Magic Knight's x-velocity if he cannot horizontally pass through a block beside him
38367 LD A,(24844) Load Magic Knight's x-velocity into B...
38370 LD B,A ...
38371 LD A,(23474) Load Magic Knight movement flags into A
38374 XOR B Check:
38375 CP 255 If x-velocity is -2 (left), and Magic Knight can't move left...
38377 JP Z,38419 ...then jump ahead to 38419
38380 CP 253 If x-velocity is -2 (left), and Magic Knight can't move left or right...
38382 JP Z,38419 ...then jump ahead to 38419
38385 CP 1 If x-velocity is +2 (right), and Magic Knight can't move left or right...
38387 JP Z,38419 ...then jump ahead to 38419
38390 OR A If x-velocity is +2 (right), and Magic Knight can't move right...
38391 JP Z,38419 ...then jump ahead to 38419
38394 CALL 38724 Kill Magic Knight's jump if he cannot vertically pass through a block above him
38397 EX AF,AF' Switch AF and AF'
38398 CALL 61816 Wait for interrupt then erase Magic Knight from display, advance his current position then redraw
38401 EX AF,AF' Switch AF and AF'
38402 JR NZ,38413 If Magic Knight's jump was impeded by a block above him then jump to 38413
38404 CALL 40008 Set Magic Knight's velocity to zero, if appropriate move to new room, update state of Storm Cloud and execute room-specific routine
38407 LD HL,(23442) Load HL with current position in Magic Knight's y-velocities sequence table
38410 INC HL Advance to next y-velocity in the sequence
38411 JR 38336 Loop back to 38336
38413 CALL 38429 Handle Magic Knight's fall, preserving x-velocity
38416 JP 38208 Loop back to start of keyboard check routine
38419 XOR A Set Magic Knight's x-velocity to zero...
38420 LD (24844),A ...
38423 LD (38360),A Prepare to set Magic Knight's x-velocity to zero
38426 JP 38394 Jump back to 38394
Prev: 38024 Up: Map Next: 38429