Prev: 27157 Up: Map Next: 27251
27193: Draw Player
Used by the routine at HandlerPlayer.
Draws the car in the centre of the play area, using the frame from PlayerSpriteTable which matches the current direction.
Before After DrawPlayer After ColouriseSprite_Block
draw-player-before draw-player-drawn draw-player-coloured
DrawPlayer 27193 LD HL,(24080) Fetch the direction the car is facing (Player_Direction).
27196 LD BC,32 BC=0032 (half of a step between two of the 16 directions, so the direction is rounded to the nearest).
27199 ADD HL,BC HL=HL + BC.
27200 LD A,H A=H.
27201 AND %00000011 Keep only bits 0-1.
Shift the top two bits of L into the bottom of A to make a direction between 0 and 15.
27203 RL L Rotate L left and shift its top bit into A.
27205 RLA
27206 RL L
27208 RLA
27209 SLA A Double A to use it as an index into a table of words.
27211 LD HL,32548 Point HL at the table of player sprites (PlayerSpriteTable).
27214 LD C,A Create an offset in BC.
27215 LD B,0
27217 ADD HL,BC HL=PlayerSpriteTable + offset.
27218 LD E,(HL) Fetch the pointer to the sprite of the player for this direction into DE.
27219 INC HL
27220 LD D,(HL)
The player is drawn statically in the centre of the play area.
27221 LD HL,20371 Set the screen address to draw the player at, the centre of the play area (20371).
The player sprite is 2 bytes in width.
27224 LD A,2 Write 2 to WidthCounter.
27226 LD (24108),A
27229 LD A,(DE) Fetch the height of the sprite.
27230 INC DE Increment DE by one to point to the sprite data.
27231 LD C,A Keep the height of the sprite in C as the row counter.
DrawPlayer_NextRow 27232 LD A,(24108) Set the byte counter to the width of the sprite (WidthCounter).
27235 LD B,A
27236 PUSH HL Stash the screen address of the start of the row on the stack.
DrawPlayer_NextCol 27237 LD A,(DE) Copy a byte from DE (the player sprite data) to HL (the screen position).
27238 LD (HL),A
27239 INC DE Move on to the next byte of sprite data.
27240 INC L Move on to the next screen byte.
27241 DJNZ DrawPlayer_NextCol Decrease the byte counter by one and loop back to DrawPlayer_NextCol until the row has been drawn.
27243 POP HL Restore the screen address of the start of the row from the stack.
27244 CALL ScreenPosition1PixelAbove Call ScreenPosition1PixelAbove to move up one pixel line.
27247 DEC C Decrease the row counter by one and jump to DrawPlayer_NextRow until all of the rows have been drawn.
27248 JR NZ,DrawPlayer_NextRow
27250 RET Return.
Prev: 27157 Up: Map Next: 27251