![]() |
Routines |
| Prev: 48869 | Up: Map | Next: 49059 |
|
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 | 48888 | LD A,(41504) | Fetch SpriteHorizontalPosition. | |||||||
| 48891 | AND %00000110 | Keep the shift, which is zero, two, four or six pixels. | ||||||||
|
Draw the sprite unshifted.
|
||||||||||
| 48893 | JP Z,DrawFlippedSprite_Aligned | Jump to DrawFlippedSprite_Aligned if there is no shift. | ||||||||
| 48896 | OR %11110001 | Make the high byte of the address of the table for the shift. | ||||||||
| 48898 | LD H,A | Set H. | ||||||||
| 48899 | LD A,(DE) | Fetch the number of columns of the sprite. | ||||||||
| 48900 | INC DE | Move on to the next byte. | ||||||||
| 48901 | AND %00000111 | Keep the low three bits. | ||||||||
| 48903 | INC A | Add one, as a shifted sprite is one byte wider. | ||||||||
| 48904 | LD B,A | Keep the widened column count in B. | ||||||||
|
Store the number of bytes in a row of the sprite.
|
||||||||||
| 48905 | LD (41506),A | Set SpriteRowBytes. | ||||||||
| 48908 | DEC A | Take one off again. | ||||||||
| 48909 | AND %00000111 | Keep the low three bits. | ||||||||
| 48911 | ADD A,A | Double it. | ||||||||
| 48912 | LD C,A | Keep twice the column count in C. | ||||||||
| 48913 | ADD A,A | Multiply it by eight to make sixteen times the number of columns. | ||||||||
| 48914 | ADD A,A | |||||||||
| 48915 | ADD A,A | |||||||||
| 48916 | ADD A,C | Add the double to make eighteen times. | ||||||||
| 48917 | NEG | Make it negative. | ||||||||
| 48919 | ADD A,93 | Add 93 which gives the distance from DrawFlipped_SpriteJump to the code for the number of columns. Each column has eighteen bytes of code. | ||||||||
| DrawFlippedSprite_SetJump | 48921 | PUSH BC | Stash the number of columns on the stack. | |||||||
| 48922 | PUSH HL | Stash the high byte of the shift table on the stack. | ||||||||
| 48923 | LD H,0 | Clear H. | ||||||||
| 48925 | AND A | Jump to DrawFlippedSprite_SetJumpAddress if the distance is positive. | ||||||||
| 48926 | JP P,DrawFlippedSprite_SetJumpAddress | |||||||||
| 48929 | DEC H | Make HL negative. | ||||||||
| DrawFlippedSprite_SetJumpAddress | 48930 | LD L,A | Put the distance in L. | |||||||
| 48931 | LD BC,49112 | Point BC at DrawFlipped_SpriteJump. | ||||||||
| 48934 | ADD HL,BC | Add the distance to give the address to jump to. | ||||||||
|
Set the address of the jump at SpriteJumpOpcode.
|
||||||||||
| 48935 | LD (41509),HL | Set SpriteJumpAddress. | ||||||||
| 48938 | POP HL | Restore the shift table from the stack. | ||||||||
| 48939 | POP BC | Restore the number of bytes in a row from the stack. | ||||||||
| 48940 | LD A,B | Fetch the number of bytes in a row. | ||||||||
| 48941 | ADD A,23 | Add 23 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.
|
||||||||||
| 48943 | LD (41511),A | Set SpriteRowStep. | ||||||||
| 48946 | EX DE,HL | Swap the address of the sprite data into HL. | ||||||||
| 48947 | LD C,112 | Set the number of rows in the buffer. | ||||||||
|
Fetch the vertical position.
|
||||||||||
| 48949 | LD A,(41505) | Fetch SpriteVerticalPosition. | ||||||||
| 48952 | SUB 72 | Subtract the position of the bottom row of the buffer. | ||||||||
| 48954 | JR C,DrawFlippedSprite_BelowBottom | Jump to DrawFlippedSprite_BelowBottom if the sprite starts below it. | ||||||||
| 48956 | SUB C | Subtract the number of rows in the buffer. | ||||||||
| 48957 | RET NC | Return if the sprite starts above the top. | ||||||||
| 48958 | NEG | Make it positive, which is the number of rows up to the top. | ||||||||
| 48960 | CP (HL) | Compare it with the number of rows in the sprite. | ||||||||
| 48961 | JR C,DrawFlippedSprite_FirstByte | Jump to DrawFlippedSprite_FirstByte if there is room for fewer rows. | ||||||||
| 48963 | LD A,(HL) | Use the number of rows in the sprite. | ||||||||
| DrawFlippedSprite_FirstByte | 48964 | INC HL | Move on to the first byte of data. | |||||||
|
Store the number of rows to draw.
|
||||||||||
| 48965 | LD (41507),A | Set SpriteRowsLeft. | ||||||||
| DrawFlippedSprite_StartRows | 48968 | EX DE,HL | Swap the address of the data into DE. | |||||||
| 48969 | PUSH HL | Stash the high byte of the shift table on the stack. | ||||||||
|
Fetch the pixel position.
|
||||||||||
| 48970 | LD HL,(41504) | Fetch SpriteHorizontalPosition. | ||||||||
|
Fetch the number of bytes in a row.
|
||||||||||
| 48973 | LD A,(41506) | Fetch SpriteRowBytes. | ||||||||
| 48976 | DEC A | Take one off. | ||||||||
| 48977 | ADD A,A | Multiply it by eight to give the pixels in all but one of the columns. | ||||||||
| 48978 | ADD A,A | |||||||||
| 48979 | ADD A,A | |||||||||
| 48980 | ADD A,L | Add it to the horizontal position, to give the right-hand end of the row. | ||||||||
| 48981 | LD L,A | Set it in L. | ||||||||
|
Find the address in the buffer.
|
||||||||||
| 48982 | CALL CalculateBufferAddress | Call CalculateBufferAddress. | ||||||||
| 48985 | LD C,L | Keep the buffer address in BC. | ||||||||
| 48986 | LD B,H | |||||||||
| 48987 | POP HL | Restore the shift table from the stack. | ||||||||
|
Save the stack pointer.
|
||||||||||
| 48988 | LD (41501),SP | Set SavedStackPointer. | ||||||||
| 48992 | EX DE,HL | Point the stack pointer at the sprite data. | ||||||||
| 48993 | LD SP,HL | |||||||||
| 48994 | EX DE,HL | |||||||||
| 48995 | SET 1,(IX+7) | Set the flag which shows that a sprite has been drawn. | ||||||||
|
Fetch the number of rows to draw.
|
||||||||||
| 48999 | LD A,(41507) | Fetch SpriteRowsLeft. | ||||||||
|
Draw the first row.
|
||||||||||
| 49002 | JR DrawFlippedRow | Jump to DrawFlippedRow. | ||||||||
|
The sprite starts below the bottom of the buffer, so skip those rows.
|
||||||||||
| DrawFlippedSprite_BelowBottom | 49004 | NEG | Make the number of rows below the bottom positive. | |||||||
| 49006 | LD C,A | Keep the rows below the bottom of the sprite in C. | ||||||||
| 49007 | LD A,(HL) | Fetch the number of rows in the sprite. | ||||||||
| 49008 | SUB C | Subtract the number below the bottom. | ||||||||
| 49009 | RET M | Return if the sprite is all below the bottom. | ||||||||
| 49010 | RET Z | Return if there is nothing left. | ||||||||
|
Store the number of rows to draw.
|
||||||||||
| 49011 | LD (41507),A | Set SpriteRowsLeft. | ||||||||
| 49014 | LD B,0 | Clear B. | ||||||||
| 49016 | DEC HL | Move back to the first byte of the sprite data. | ||||||||
| 49017 | LD A,(HL) | Fetch the first byte of the sprite. | ||||||||
| 49018 | AND %00111111 | Keep only the number of columns. | ||||||||
| 49020 | INC HL | Move on to the data. | ||||||||
| 49021 | INC HL | |||||||||
| 49022 | SLA C | Double the number of rows to skip. | ||||||||
| 49024 | RL B | |||||||||
| DrawFlippedSprite_SkipRows | 49026 | ADD HL,BC | Skip two bytes for each row below the bottom in each column. | |||||||
| 49027 | DEC A | |||||||||
| 49028 | JR NZ,DrawFlippedSprite_SkipRows | |||||||||
|
Start drawing at the bottom of the buffer.
|
||||||||||
| 49030 | LD A,72 | Set SpriteVerticalPosition to the bottom of the buffer. | ||||||||
| 49032 | LD (41505),A | |||||||||
|
Start the rows.
|
||||||||||
| 49035 | JR DrawFlippedSprite_StartRows | Jump to DrawFlippedSprite_StartRows. | ||||||||
| DrawFlippedSprite_Aligned | 49037 | LD H,249 | Point H at the table which only turns the bits round. | |||||||
| 49039 | LD A,(DE) | Fetch the number of columns of the sprite. | ||||||||
| 49040 | INC DE | Move on to the next byte. | ||||||||
| 49041 | AND %00001111 | Keep the low four bits. | ||||||||
|
Store the number of bytes in a row of the sprite.
|
||||||||||
| 49043 | LD (41506),A | Set SpriteRowBytes. | ||||||||
| 49046 | LD B,A | Keep the bytes in a row in B. | ||||||||
| 49047 | ADD A,A | Multiply it by eight. | ||||||||
| 49048 | ADD A,A | |||||||||
| 49049 | ADD A,A | |||||||||
| 49050 | ADD A,B | Add it twice more to make ten times the number of columns. | ||||||||
| 49051 | ADD A,B | |||||||||
| 49052 | NEG | Make it negative. | ||||||||
| 49054 | SUB 3 | 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.
|
||||||||||
| 49056 | JP DrawFlippedSprite_SetJump | Jump to DrawFlippedSprite_SetJump. | ||||||||
| Prev: 48869 | Up: Map | Next: 49059 |