Prev: D848 Up: Map Next: D88C
D865: Turn a sprite's stored data to face the way its object wants
Used by the routine at flip_sprite.
Sprites are flipped in place, and the header remembers which way round the data now is: bit 7 of its first byte for upside down, bit 6 for mirrored. Bits 7 and 6 of the object's byte 7 say which way it wants to be drawn. Where they disagree the data is turned and the header bit toggled. An object that keeps facing one way therefore costs nothing after the first frame; two objects that share a sprite but face opposite ways turn it back and forth every time each is drawn.
This part does the vertical flip, swapping whole rows end for end; hflip_sprite_data does the mirror. DE is kept.
Input
DE the sprite's header
IX the object
vflip_sprite_data D865 PUSH DE the header's bit 7 against the object's: the same means no vertical flip
D866 LD A,(DE)
D867 XOR (IX+$07)
D86A AND $80
D86C JR Z,hflip_sprite_data
D86E LD A,(DE) toggle the header's bit
D86F XOR $80
D871 LD (DE),A
D872 RLCA B = bytes per row: the width in bits 0 to 3, times two for the mask and image bytes
D873 AND $1E
D875 LD B,A
D876 INC DE C = the height in rows
D877 LD A,(DE)
D878 LD C,A
D879 INC DE
D87A PUSH DE HL = the data's length; DE = one past the end of the data, and HL its start
D87B LD E,B
D87C LD D,$00
D87E CALL HL_equals_DE_x_A
D881 POP DE
D882 ADD HL,DE
D883 EX DE,HL
D884 LD A,B DE on the last byte of the last row, HL on the last byte of the first
D885 CALL add_HL_A
D888 DEC DE
D889 DEC HL
D88A SRL C swap rows in pairs: half the height
Prev: D848 Up: Map Next: D88C