Prev: F127 Up: Map Next: F199
F157: Mirror a run of sprite planes in place, if they face the other way
Used by the routine at MITRO.
The author's MW. Nothing is done if bit 5 of the record's +$0E, the way the sprites face now, already matches bit 5 of E. Otherwise every row of every plane is turned end for end: each byte's bits reversed into E and pushed, and then popped back over the row, which reverses the bytes' order too.
Input
E The new facing
C The width in bytes
HL The first plane
IX The record
C' The number of planes
MW F157 LD A,(IX+OBJ_STATE) Already that way round: nothing to do
F15A BIT 5,E
F15C JR NZ,MW0
F15E XOR $20
MW0 F160 BIT 5,A
F162 RET NZ
F163 EXX MIR0: each plane, its height in rows (in the alternate B)
MIR0 F164 LD B,(IX+OBJ_ROWS)
MIR1 F167 EXX MIR1: each row, its width in bytes
F168 LD B,C
MIR2 F169 LD A,(HL) MIR2: each byte's bits reversed, and pushed
F16A INC HL
F16B RRA
F16C RL E
F16E RRA
F16F RL E
F171 RRA
F172 RL E
F174 RRA
F175 RL E
F177 RRA
F178 RL E
F17A RRA
F17B RL E
F17D RRA
F17E RL E
F180 RRA
F181 RL E
F183 PUSH DE
F184 DJNZ MIR2
F186 LD E,C Back to the row's start
F187 LD D,$00
F189 LD B,E
F18A AND A
F18B SBC HL,DE
MIR3 F18D POP DE MIR3: the bytes written back, last first
F18E LD (HL),E
F18F INC HL
F190 DJNZ MIR3
F192 EXX The next row; the next plane
F193 DJNZ MIR1
F195 DEC C
F196 JR NZ,MIR0
F198 RET
Prev: F127 Up: Map Next: F199