![]() |
Routines |
| Prev: 45756 | Up: Map | Next: 46222 |
|
Used by the routine at DrawSprite.
Flips a sprite in place, so that it is stored facing the other way, if the way it is stored does not match the direction of the entity being drawn. Each row of the sprite has its pairs of bytes put in the opposite order and each byte is reversed using the table at ReversedBytes.
|
||||||||||
| FlipSprite | 46163 | PUSH DE | Save the address of the sprite. | |||||||
| 46164 | LD A,(DE) | Fetch the header flags of the sprite. | ||||||||
| 46165 | XOR (IX+0) | Compare bit 7 with bit 7 of the type of the sprite being drawn. | ||||||||
| 46168 | AND 128 | Keep only bit 7. | ||||||||
| 46170 | JR Z,FlipSprite_Done | Jump to FlipSprite_Done if the sprite is already facing the right way. | ||||||||
| 46172 | LD A,(DE) | Fetch the width byte of the header. | ||||||||
| 46173 | XOR 128 | Toggle bit 7, as the sprite is being flipped. | ||||||||
| 46175 | LD (DE),A | Store it. | ||||||||
| 46176 | AND 15 | Keep the width in bytes. | ||||||||
| 46178 | LD B,A | Use it as the counter for the pairs in a row, and keep a copy in C. | ||||||||
| 46179 | LD C,A | |||||||||
| 46180 | INC DE | Point DE at the height. | ||||||||
| 46181 | LD A,(DE) | Fetch the height. | ||||||||
| 46182 | EX AF,AF' | Keep the height, to count the rows. | ||||||||
| 46183 | INC DE | Point DE at the first row of data. | ||||||||
| 46184 | EX DE,HL | Point HL at it. | ||||||||
| 46185 | PUSH HL | Take a copy of the address. | ||||||||
| 46186 | EXX | Switch to the shadow registers and make HL' the source pointer. | ||||||||
| 46187 | POP HL | |||||||||
| 46188 | LD B,240 | Set B' to the page of the table of reversed bytes. | ||||||||
| 46190 | EXX | Switch back. | ||||||||
| FlipSprite_Row | 46191 | EXX | Switch to the shadow registers. | |||||||
| 46192 | LD C,(HL) | Fetch the OR byte of the pair. | ||||||||
| 46193 | LD A,(BC) | Look up the byte with its bits reversed. | ||||||||
| 46194 | LD E,A | Keep the reversed OR byte. | ||||||||
| 46195 | INC HL | Move on to the XOR byte. | ||||||||
| 46196 | LD C,(HL) | Fetch the XOR byte of the pair. | ||||||||
| 46197 | LD A,(BC) | Look up the byte with its bits reversed. | ||||||||
| 46198 | LD D,A | Keep the reversed XOR byte. | ||||||||
| 46199 | INC HL | Move on to the next pair. | ||||||||
| 46200 | PUSH DE | Save the reversed pair on the stack. | ||||||||
| 46201 | EXX | Switch back to the main registers. | ||||||||
| 46202 | DJNZ FlipSprite_Row | Loop back until every pair in the row has been saved. | ||||||||
| 46204 | LD B,C | Set the counter to the number of pairs in a row. | ||||||||
| FlipSprite_Write | 46205 | POP DE | Take a pair off the stack, so that the last pair of the row comes first. | |||||||
| 46206 | LD (HL),E | Write the reversed OR byte. | ||||||||
| 46207 | INC HL | Move on. | ||||||||
| 46208 | LD (HL),D | Write the reversed XOR byte. | ||||||||
| 46209 | INC HL | Move on to the next pair. | ||||||||
| 46210 | DJNZ FlipSprite_Write | Loop back until the row has been written back. | ||||||||
| 46212 | EX AF,AF' | Fetch the row counter. | ||||||||
| 46213 | DEC A | Decrease it by one. | ||||||||
| 46214 | JR Z,FlipSprite_Done | Jump to FlipSprite_Done if every row has been flipped. | ||||||||
| 46216 | EX AF,AF' | Store the row counter again. | ||||||||
| 46217 | LD B,C | Set the counter to the number of pairs in a row. | ||||||||
| 46218 | JR FlipSprite_Row | Jump back to flip the next row. | ||||||||
| FlipSprite_Done | 46220 | POP DE | Restore the address of the sprite. | |||||||
| 46221 | RET | Return. | ||||||||
| Prev: 45756 | Up: Map | Next: 46222 |