Prev: B2BC Up: Map Next: B48E
B453: Flip Sprite
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.
Input
DE Address of the sprite header
IX Draw list entry
FlipSprite B453 PUSH DE Save the address of the sprite.
B454 LD A,(DE) Fetch the header flags of the sprite.
B455 XOR (IX+$00) Compare bit 7 with bit 7 of the type of the sprite being drawn.
B458 AND $80 Keep only bit 7.
B45A JR Z,FlipSprite_Done Jump to FlipSprite_Done if the sprite is already facing the right way.
B45C LD A,(DE) Fetch the width byte of the header.
B45D XOR $80 Toggle bit 7, as the sprite is being flipped.
B45F LD (DE),A Store it.
B460 AND $0F Keep the width in bytes.
B462 LD B,A Use it as the counter for the pairs in a row, and keep a copy in C.
B463 LD C,A
B464 INC DE Point DE at the height.
B465 LD A,(DE) Fetch the height.
B466 EX AF,AF' Keep the height, to count the rows.
B467 INC DE Point DE at the first row of data.
B468 EX DE,HL Point HL at it.
B469 PUSH HL Take a copy of the address.
B46A EXX Switch to the shadow registers and make HL' the source pointer.
B46B POP HL
B46C LD B,$F0 Set B' to the page of the table of reversed bytes.
B46E EXX Switch back.
FlipSprite_Row B46F EXX Switch to the shadow registers.
B470 LD C,(HL) Fetch the OR byte of the pair.
B471 LD A,(BC) Look up the byte with its bits reversed.
B472 LD E,A Keep the reversed OR byte.
B473 INC HL Move on to the XOR byte.
B474 LD C,(HL) Fetch the XOR byte of the pair.
B475 LD A,(BC) Look up the byte with its bits reversed.
B476 LD D,A Keep the reversed XOR byte.
B477 INC HL Move on to the next pair.
B478 PUSH DE Save the reversed pair on the stack.
B479 EXX Switch back to the main registers.
B47A DJNZ FlipSprite_Row Loop back until every pair in the row has been saved.
B47C LD B,C Set the counter to the number of pairs in a row.
FlipSprite_Write B47D POP DE Take a pair off the stack, so that the last pair of the row comes first.
B47E LD (HL),E Write the reversed OR byte.
B47F INC HL Move on.
B480 LD (HL),D Write the reversed XOR byte.
B481 INC HL Move on to the next pair.
B482 DJNZ FlipSprite_Write Loop back until the row has been written back.
B484 EX AF,AF' Fetch the row counter.
B485 DEC A Decrease it by one.
B486 JR Z,FlipSprite_Done Jump to FlipSprite_Done if every row has been flipped.
B488 EX AF,AF' Store the row counter again.
B489 LD B,C Set the counter to the number of pairs in a row.
B48A JR FlipSprite_Row Jump back to flip the next row.
FlipSprite_Done B48C POP DE Restore the address of the sprite.
B48D RET Return.
Prev: B2BC Up: Map Next: B48E