Routines 
Prev: 27352  Up: Map  Next: 27508 
Used by the routine at 27136.


27357  XOR A  Set A to zero  
This entry point is used by the routine at 27352.


27358  LD (27393),A  Prepare to set Magic Knight's xvelocity to A  
27361  LD HL,37087  Point HL at end of table of yvelocities sequence for jumping and falling  
27364  LD (37072),HL  Store current position at 37072  
27367  LD A,(23474)  If Magic Knight's movement flags are reset...  
27370  OR A  ...  
27371  JR Z,27377  ...then skip ahead to 27377  
27373  XOR A  Prepare to set Magic Knight's xvelocity to zero...  
27374  LD (27393),A  ...  
27377  LD HL,(37072)  Load current position in yvelocities table into HL  
27380  LD A,(HL)  Load current yvelocity from table into A  
27381  CP 7  If velocity is 7...  
27383  JR Z,27389  ...then skip ahead to 27389  
27385  DEC HL  Step pointer back one byte in yvelocities table  
27386  LD (37072),HL  Store pointer  
27389  LD (25161),A  Load last yvelocity read from table into Magic Knight's yvelocity  
27392  LD A,0  Set Magic Knight's xvelocity...  
27394  LD (25160),A  ...  
27397  LD A,(25156)  Load A with Magic Knight's current xcoordinate (pixels)  
27400  ADD A,4  Add 4 to xcoordinate  
27402  CALL 28625  Divide xcoordinate by eight, rounding down to nearest integer  
27405  LD C,A  Load result (Magic Knight's xcoordinate in characters) into C, setting B to zero...  
27406  LD B,0  ...  
27408  LD A,(25157)  Load A with Magic Knight's current ycoordinate (pixels)  
27411  AND 7  If ycoordinate is a multiple of eight...  
27413  JR Z,27417  ...then skip ahead to 27417  
ycoordinate is not a multiple of eight


27415  LD B,8  Set B to 8, as we need to look one character block lower due to Magic Knight spanning five, rather than four, characters  
27417  LD A,(25157)  Load A with Magic Knight's current ycoordinate (pixels)  
27420  ADD A,B  Add B to current ycoordinate (i.e. ycoordinate of highest full character block spanned by Magic Knight)  
27421  ADD A,32  Add 32 (as Magic Knight is 32 pixels high, so now ycoordinate of highest full character block not occupied by Magic Knight)  
27423  CALL 28625  Divide A by eight, rounding down to nearest integer  
27426  LD B,A  Load result (ycoordinate in characters) into B  
27427  CALL 54162  Point HL at terrain interaction data for character coordinates x=C, y=B (block that Magic Knight is "falling through")  
27430  LD A,(HL)  If this block, or the one to the right of it cannot be passed vertically (downwards)...  
27431  INC HL  ...(i.e. Magic Knight has landed)...  
27432  OR (HL)  ...  
27433  BIT 7,A  ...  
27435  JR NZ,27476  ...then skip ahead to 27476  
27437  CALL 27508  Kill Magic Knight's xvelocity if he cannot horizontally pass through a block beside him  
27440  LD A,(25160)  Load Magic Knight's xvelocity into B...  
27443  LD B,A  ...  
27444  LD A,(23474)  Load Magic Knight's movement flags into A  
27447  XOR B  Check:  
27448  CP 255  If xvelocity is 2 (left), and Magic Knight can't move left...  
27450  JP Z,27498  ...then jump ahead to 27498  
27453  CP 253  If xvelocity is 2 (left), and Magic Knight can't move left or right...  
27455  JP Z,27498  ...then jump ahead to 27498  
27458  CP 1  If xvelocity is +2 (right), and Magic Knight can't move left or right...  
27460  JP Z,27498  ...then jump ahead to 27498  
27463  OR A  If xvelocity is +2 (right), and Magic Knight can't move right...  
27464  JP Z,27498  ...then jump ahead to 27498  
27467  CALL 53115  Erase Magic Knight from display, advance his current position then redraw  
27470  CALL 28457  Set Magic Knight's velocity to zero, if appropriate move to new room, execute roomspecific routine  
27473  JP 27367  Loop back to 27367  
27476  LD A,(25157)  Load A with Magic Knight's current ycoordinate (pixels)  
27479  AND 7  Retain only pixelwithincharacter component (e.g. 5 pixels down the pair of character blocks)  
27481  NEG  Negate (i.e. 5 pixels)  
27483  AND 7  Retain only pixelwithincharacter component (e.g. 3 pixels up the pair of character blocks, or 3 pixels down to the ground)  
27485  LD (25161),A  Set Magic Knight's yvelocity so that it will take his feet to the ground  
27488  CALL 53115  Erase Magic Knight from display, advance his current position then redraw  
27491  LD HL,0  Set Magic Knight's x and yvelocities to zero...  
27494  LD (25160),HL  ...  
27497  RET  Return (Magic Knight has landed)  
27498  XOR A  Set Magic Knight's xvelocity to zero...  
27499  LD (25160),A  ...  
27502  LD (27393),A  Prepare to set Magic Knight's xvelocity to zero  
27505  JP 27467  Loop back to 27467 
Prev: 27352  Up: Map  Next: 27508 