Prev: D780 Up: Map Next: D811
D7AA: Draw Lines
Used by the routine at PrintSprite.
Draws the lines of a sprite one after the other. For each line the code jumps into the unrolled code, at a place that depends on the width of the sprite, and that is set by the jump that is changed by PrintSprite. The code for a sprite that is not on a byte boundary takes a pair of bytes off the stack, which are the mask and the data, shifts them across the two bytes of the buffer that they fall into with the table of shifted bytes in H, and keeps what is left of the second byte to go with the next pair.
DrawLines D7AA EX AF,AF' Stash the number of lines left.
D7AB LD A,(BC) Fetch the first byte of the buffer.
DrawLines_Jump D7AC JR DrawLines_Jump Jump into the unrolled code. The jump is changed to go to the right place.
The first pair of a sprite that has five.
D7AE POP DE Take the mask and the data of the pair off the stack.
D7AF LD L,E Combine the byte that is carried with the first part of the shifted mask and data.
D7B0 AND (HL)
D7B1 LD L,D
D7B2 XOR (HL)
D7B3 CPL
D7B4 LD (BC),A Store the byte in the buffer and move on to the next one.
D7B5 INC BC
D7B6 INC H Switch to the table of the part that spills over into the next byte.
D7B7 LD L,E
D7B8 LD A,(BC) Fetch the next byte of the buffer.
D7B9 AND (HL) Combine it with the second part of the shifted mask and data.
D7BA LD L,D
D7BB XOR (HL)
D7BC CPL
D7BD DEC H Switch back to the first table.
The second pair of a sprite that has four or five.
D7BE POP DE Take the mask and the data of the pair off the stack.
D7BF LD L,E Combine the byte that is carried with the first part of the shifted mask and data.
D7C0 AND (HL)
D7C1 LD L,D
D7C2 XOR (HL)
D7C3 CPL
D7C4 LD (BC),A Store the byte in the buffer and move on to the next one.
D7C5 INC BC
D7C6 INC H Switch to the table of the part that spills over into the next byte.
D7C7 LD L,E
D7C8 LD A,(BC) Fetch the next byte of the buffer.
D7C9 AND (HL) Combine it with the second part of the shifted mask and data.
D7CA LD L,D
D7CB XOR (HL)
D7CC CPL
D7CD DEC H Switch back to the first table.
The third pair of a sprite that has three or more.
D7CE POP DE Take the mask and the data of the pair off the stack.
D7CF LD L,E Combine the byte that is carried with the first part of the shifted mask and data.
D7D0 AND (HL)
D7D1 LD L,D
D7D2 XOR (HL)
D7D3 CPL
D7D4 LD (BC),A Store the byte in the buffer and move on to the next one.
D7D5 INC BC
D7D6 INC H Switch to the table of the part that spills over into the next byte.
D7D7 LD L,E
D7D8 LD A,(BC) Fetch the next byte of the buffer.
D7D9 AND (HL) Combine it with the second part of the shifted mask and data.
D7DA LD L,D
D7DB XOR (HL)
D7DC CPL
D7DD DEC H Switch back to the first table.
The fourth pair of a sprite that has two or more.
D7DE POP DE Take the mask and the data of the pair off the stack.
D7DF LD L,E Combine the byte that is carried with the first part of the shifted mask and data.
D7E0 AND (HL)
D7E1 LD L,D
D7E2 XOR (HL)
D7E3 CPL
D7E4 LD (BC),A Store the byte in the buffer and move on to the next one.
D7E5 INC BC
D7E6 INC H Switch to the table of the part that spills over into the next byte.
D7E7 LD L,E
D7E8 LD A,(BC) Fetch the next byte of the buffer.
D7E9 AND (HL) Combine it with the second part of the shifted mask and data.
D7EA LD L,D
D7EB XOR (HL)
D7EC CPL
D7ED DEC H Switch back to the first table.
The last pair.
D7EE POP DE Take the mask and the data of the pair off the stack.
D7EF LD L,E Combine the byte that is carried with the first part of the shifted mask and data.
D7F0 AND (HL)
D7F1 LD L,D
D7F2 XOR (HL)
D7F3 CPL
D7F4 LD (BC),A Store the byte in the buffer and move on to the next one.
D7F5 INC BC
D7F6 INC H Switch to the table of the part that spills over into the next byte.
D7F7 LD L,E
D7F8 LD A,(BC) Fetch the next byte of the buffer.
D7F9 AND (HL) Combine it with the second part of the shifted mask and data.
D7FA LD L,D
D7FB XOR (HL)
D7FC CPL
D7FD DEC H Switch back to the first table.
D7FE LD (BC),A Store the last byte of the line.
This entry point is used by the routine at DrawAlignedColumns.
DrawLines_Next D7FF LD A,C Fetch the low byte of the address in the buffer.
D800 ADD A,$00 Add the step to the start of the next line, which is changed for the width of the sprite.
D802 LD C,A Store it.
D803 LD A,B Fetch the high byte of the address in the buffer.
D804 ADC A,$00 Add the carry, as the step is a single byte.
D806 LD B,A Store it.
D807 EX AF,AF' Restore the number of lines left.
D808 DEC A Count down the lines.
D809 JP NZ,DrawLines Jump to DrawLines until all of the lines are drawn.
D80C LD SP,($5BA9) Restore the stack pointer from SavedStackPointer.
D810 RET Return.
View the equivalent code in;
Prev: D780 Up: Map Next: D811