![]() |
Routines |
| Prev: BEE5 | Up: Map | Next: BFA3 |
|
Used by the routine at DrawSprite.
Draws a sprite which is flipped, so that it faces the other way. It works in the same way as DrawSprite, but it draws from the right-hand end of each row to the left, and the tables turn the bits of each byte round as well as shifting them.
|
||||||||||
|
Fetch the horizontal pixel position.
|
||||||||||
| DrawFlippedSprite | BEF8 | LD A,($A220) | Fetch SpriteHorizontalPosition. | |||||||
| BEFB | AND %00000110 | Keep the shift, which is zero, two, four or six pixels. | ||||||||
|
Draw the sprite unshifted.
|
||||||||||
| BEFD | JP Z,DrawFlippedSprite_Aligned | Jump to DrawFlippedSprite_Aligned if there is no shift. | ||||||||
| BF00 | OR %11110001 | Make the high byte of the address of the table for the shift. | ||||||||
| BF02 | LD H,A | Set H. | ||||||||
| BF03 | LD A,(DE) | Fetch the number of columns of the sprite. | ||||||||
| BF04 | INC DE | Move on to the next byte. | ||||||||
| BF05 | AND %00000111 | Keep the low three bits. | ||||||||
| BF07 | INC A | Add one, as a shifted sprite is one byte wider. | ||||||||
| BF08 | LD B,A | Keep the widened column count in B. | ||||||||
|
Store the number of bytes in a row of the sprite.
|
||||||||||
| BF09 | LD ($A222),A | Set SpriteRowBytes. | ||||||||
| BF0C | DEC A | Take one off again. | ||||||||
| BF0D | AND %00000111 | Keep the low three bits. | ||||||||
| BF0F | ADD A,A | Double it. | ||||||||
| BF10 | LD C,A | Keep twice the column count in C. | ||||||||
| BF11 | ADD A,A | Multiply it by eight to make sixteen times the number of columns. | ||||||||
| BF12 | ADD A,A | |||||||||
| BF13 | ADD A,A | |||||||||
| BF14 | ADD A,C | Add the double to make eighteen times. | ||||||||
| BF15 | NEG | Make it negative. | ||||||||
| BF17 | ADD A,$5D | Add 5D which gives the distance from DrawFlipped_SpriteJump to the code for the number of columns. Each column has eighteen bytes of code. | ||||||||
| DrawFlippedSprite_SetJump | BF19 | PUSH BC | Stash the number of columns on the stack. | |||||||
| BF1A | PUSH HL | Stash the high byte of the shift table on the stack. | ||||||||
| BF1B | LD H,$00 | Clear H. | ||||||||
| BF1D | AND A | Jump to DrawFlippedSprite_SetJumpAddress if the distance is positive. | ||||||||
| BF1E | JP P,DrawFlippedSprite_SetJumpAddress | |||||||||
| BF21 | DEC H | Make HL negative. | ||||||||
| DrawFlippedSprite_SetJumpAddress | BF22 | LD L,A | Put the distance in L. | |||||||
| BF23 | LD BC,$BFD8 | Point BC at DrawFlipped_SpriteJump. | ||||||||
| BF26 | ADD HL,BC | Add the distance to give the address to jump to. | ||||||||
|
Set the address of the jump at SpriteJumpOpcode.
|
||||||||||
| BF27 | LD ($A225),HL | Set SpriteJumpAddress. | ||||||||
| BF2A | POP HL | Restore the shift table from the stack. | ||||||||
| BF2B | POP BC | Restore the number of bytes in a row from the stack. | ||||||||
| BF2C | LD A,B | Fetch the number of bytes in a row. | ||||||||
| BF2D | ADD A,$17 | Add 17 to give twenty three more than the number of bytes. | ||||||||
|
Store the distance from the end of a row to the start of the next.
|
||||||||||
| BF2F | LD ($A227),A | Set SpriteRowStep. | ||||||||
| BF32 | EX DE,HL | Swap the address of the sprite data into HL. | ||||||||
| BF33 | LD C,$70 | Set the number of rows in the buffer. | ||||||||
|
Fetch the vertical position.
|
||||||||||
| BF35 | LD A,($A221) | Fetch SpriteVerticalPosition. | ||||||||
| BF38 | SUB $48 | Subtract the position of the bottom row of the buffer. | ||||||||
| BF3A | JR C,DrawFlippedSprite_BelowBottom | Jump to DrawFlippedSprite_BelowBottom if the sprite starts below it. | ||||||||
| BF3C | SUB C | Subtract the number of rows in the buffer. | ||||||||
| BF3D | RET NC | Return if the sprite starts above the top. | ||||||||
| BF3E | NEG | Make it positive, which is the number of rows up to the top. | ||||||||
| BF40 | CP (HL) | Compare it with the number of rows in the sprite. | ||||||||
| BF41 | JR C,DrawFlippedSprite_FirstByte | Jump to DrawFlippedSprite_FirstByte if there is room for fewer rows. | ||||||||
| BF43 | LD A,(HL) | Use the number of rows in the sprite. | ||||||||
| DrawFlippedSprite_FirstByte | BF44 | INC HL | Move on to the first byte of data. | |||||||
|
Store the number of rows to draw.
|
||||||||||
| BF45 | LD ($A223),A | Set SpriteRowsLeft. | ||||||||
| DrawFlippedSprite_StartRows | BF48 | EX DE,HL | Swap the address of the data into DE. | |||||||
| BF49 | PUSH HL | Stash the high byte of the shift table on the stack. | ||||||||
|
Fetch the pixel position.
|
||||||||||
| BF4A | LD HL,($A220) | Fetch SpriteHorizontalPosition. | ||||||||
|
Fetch the number of bytes in a row.
|
||||||||||
| BF4D | LD A,($A222) | Fetch SpriteRowBytes. | ||||||||
| BF50 | DEC A | Take one off. | ||||||||
| BF51 | ADD A,A | Multiply it by eight to give the pixels in all but one of the columns. | ||||||||
| BF52 | ADD A,A | |||||||||
| BF53 | ADD A,A | |||||||||
| BF54 | ADD A,L | Add it to the horizontal position, to give the right-hand end of the row. | ||||||||
| BF55 | LD L,A | Set it in L. | ||||||||
|
Find the address in the buffer.
|
||||||||||
| BF56 | CALL CalculateBufferAddress | Call CalculateBufferAddress. | ||||||||
| BF59 | LD C,L | Keep the buffer address in BC. | ||||||||
| BF5A | LD B,H | |||||||||
| BF5B | POP HL | Restore the shift table from the stack. | ||||||||
|
Save the stack pointer.
|
||||||||||
| BF5C | LD ($A21D),SP | Set SavedStackPointer. | ||||||||
| BF60 | EX DE,HL | Point the stack pointer at the sprite data. | ||||||||
| BF61 | LD SP,HL | |||||||||
| BF62 | EX DE,HL | |||||||||
| BF63 | SET 1,(IX+$07) | Set the flag which shows that a sprite has been drawn. | ||||||||
|
Fetch the number of rows to draw.
|
||||||||||
| BF67 | LD A,($A223) | Fetch SpriteRowsLeft. | ||||||||
|
Draw the first row.
|
||||||||||
| BF6A | JR DrawFlippedRow | Jump to DrawFlippedRow. | ||||||||
|
The sprite starts below the bottom of the buffer, so skip those rows.
|
||||||||||
| DrawFlippedSprite_BelowBottom | BF6C | NEG | Make the number of rows below the bottom positive. | |||||||
| BF6E | LD C,A | Keep the rows below the bottom of the sprite in C. | ||||||||
| BF6F | LD A,(HL) | Fetch the number of rows in the sprite. | ||||||||
| BF70 | SUB C | Subtract the number below the bottom. | ||||||||
| BF71 | RET M | Return if the sprite is all below the bottom. | ||||||||
| BF72 | RET Z | Return if there is nothing left. | ||||||||
|
Store the number of rows to draw.
|
||||||||||
| BF73 | LD ($A223),A | Set SpriteRowsLeft. | ||||||||
| BF76 | LD B,$00 | Clear B. | ||||||||
| BF78 | DEC HL | Move back to the first byte of the sprite data. | ||||||||
| BF79 | LD A,(HL) | Fetch the first byte of the sprite. | ||||||||
| BF7A | AND %00111111 | Keep only the number of columns. | ||||||||
| BF7C | INC HL | Move on to the data. | ||||||||
| BF7D | INC HL | |||||||||
| BF7E | SLA C | Double the number of rows to skip. | ||||||||
| BF80 | RL B | |||||||||
| DrawFlippedSprite_SkipRows | BF82 | ADD HL,BC | Skip two bytes for each row below the bottom in each column. | |||||||
| BF83 | DEC A | |||||||||
| BF84 | JR NZ,DrawFlippedSprite_SkipRows | |||||||||
|
Start drawing at the bottom of the buffer.
|
||||||||||
| BF86 | LD A,$48 | Set SpriteVerticalPosition to the bottom of the buffer. | ||||||||
| BF88 | LD ($A221),A | |||||||||
|
Start the rows.
|
||||||||||
| BF8B | JR DrawFlippedSprite_StartRows | Jump to DrawFlippedSprite_StartRows. | ||||||||
| DrawFlippedSprite_Aligned | BF8D | LD H,$F9 | Point H at the table which only turns the bits round. | |||||||
| BF8F | LD A,(DE) | Fetch the number of columns of the sprite. | ||||||||
| BF90 | INC DE | Move on to the next byte. | ||||||||
| BF91 | AND %00001111 | Keep the low four bits. | ||||||||
|
Store the number of bytes in a row of the sprite.
|
||||||||||
| BF93 | LD ($A222),A | Set SpriteRowBytes. | ||||||||
| BF96 | LD B,A | Keep the bytes in a row in B. | ||||||||
| BF97 | ADD A,A | Multiply it by eight. | ||||||||
| BF98 | ADD A,A | |||||||||
| BF99 | ADD A,A | |||||||||
| BF9A | ADD A,B | Add it twice more to make ten times the number of columns. | ||||||||
| BF9B | ADD A,B | |||||||||
| BF9C | NEG | Make it negative. | ||||||||
| BF9E | SUB $03 | Subtract three, which gives the distance from DrawFlipped_SpriteJump to the code for the number of columns. Each column has ten bytes of code. | ||||||||
|
Set the address of the jump.
|
||||||||||
| BFA0 | JP DrawFlippedSprite_SetJump | Jump to DrawFlippedSprite_SetJump. | ||||||||
| Prev: BEE5 | Up: Map | Next: BFA3 |