Prev: B44F Up: Map Next: B4E0
B479: Draw Lines
Used by the routine at DrawObject.
Draws the rows of a sprite, which is shifted if its x co-ordinate is not a multiple of eight. Both ways of drawing a sprite arrive here with the number of rows to draw in A.
The shifted code has one unit for each byte column, and the jump at DrawLines_Jump is patched with a displacement that enters the run at the first unit that is needed. Each unit takes a pair of sprite bytes, and uses the shift tables built by BuildLookupTables to split each into the part that goes into the byte of the buffer, and the part that goes into the next byte. The table for the high part is in the page in H, and the table for the low part is in the next page.
For the aligned rows, the displacement jumps into the run of units of DrawAlignedColumns instead.
Input
A Number of rows to draw
BC Address in the buffer of the first byte of the bottom row
H Page of the shift table for the high part of the sprite bytes
DrawLines B479 EX AF,AF' Stash the number of rows in AF'.
B47A LD A,(BC) Fetch the first byte of the buffer row.
DrawLines_Jump B47B JR DrawLines_Jump Jump into the run of units. The displacement is patched at B47C.
The first unit of the run, which is used by sprites of five bytes wide.
DrawLines_FirstUnit B47D POP DE Fetch the mask byte into E and the pixel byte into D.
B47E LD L,E Look up the mask byte.
B47F AND (HL) Clear the buffer bits under the high part of the mask.
B480 LD L,D Merge in the high part of the pixel byte.
B481 XOR (HL)
B482 CPL
B483 LD (BC),A Write the byte to the buffer.
B484 INC BC Move on to the next byte of the buffer.
B485 INC H Switch to the page of the low parts.
B486 LD L,E Fetch the next byte of the buffer, and look up the mask byte again.
B487 LD A,(BC)
B488 AND (HL) Clear the buffer bits under the low part of the mask.
B489 LD L,D Merge in the low part of the pixel byte.
B48A XOR (HL)
B48B CPL
B48C DEC H Switch back to the page of the high parts.
The second unit, which is used by sprites of four bytes wide.
B48D POP DE Draw the second byte column.
B48E LD L,E
B48F AND (HL)
B490 LD L,D
B491 XOR (HL)
B492 CPL
B493 LD (BC),A
B494 INC BC
B495 INC H
B496 LD L,E
B497 LD A,(BC)
B498 AND (HL)
B499 LD L,D
B49A XOR (HL)
B49B CPL
B49C DEC H
The third unit, which is used by sprites of three bytes wide.
B49D POP DE Draw the third byte column.
B49E LD L,E
B49F AND (HL)
B4A0 LD L,D
B4A1 XOR (HL)
B4A2 CPL
B4A3 LD (BC),A
B4A4 INC BC
B4A5 INC H
B4A6 LD L,E
B4A7 LD A,(BC)
B4A8 AND (HL)
B4A9 LD L,D
B4AA XOR (HL)
B4AB CPL
B4AC DEC H
The fourth unit, which is used by sprites of two bytes wide.
B4AD POP DE Draw the fourth byte column.
B4AE LD L,E
B4AF AND (HL)
B4B0 LD L,D
B4B1 XOR (HL)
B4B2 CPL
B4B3 LD (BC),A
B4B4 INC BC
B4B5 INC H
B4B6 LD L,E
B4B7 LD A,(BC)
B4B8 AND (HL)
B4B9 LD L,D
B4BA XOR (HL)
B4BB CPL
B4BC DEC H
The last unit, which is used by sprites of one byte wide.
B4BD POP DE Draw the last byte column.
B4BE LD L,E
B4BF AND (HL)
B4C0 LD L,D
B4C1 XOR (HL)
B4C2 CPL
B4C3 LD (BC),A
B4C4 INC BC
B4C5 INC H
B4C6 LD L,E
B4C7 LD A,(BC)
B4C8 AND (HL)
B4C9 LD L,D
B4CA XOR (HL)
B4CB CPL
B4CC DEC H
Write the last byte of the row and move to the next row.
B4CD LD (BC),A Write the last byte to the buffer.
This entry point is used by the routine at DrawAlignedColumns.
DrawLines_FinishRow B4CE LD A,C Fetch the low byte of the buffer address.
B4CF ADD A,$00 Add the amount that takes the address to the start of the next row. This is patched at B4D0.
B4D1 LD C,A Set the low byte of the buffer address.
B4D2 LD A,B Fetch the high byte of the buffer address.
B4D3 ADC A,$00 Add the carry.
B4D5 LD B,A Set the high byte of the buffer address.
B4D6 EX AF,AF' Fetch the row counter.
B4D7 DEC A Count down the rows and jump to DrawLines until they are drawn.
B4D8 JP NZ,DrawLines
B4DB LD SP,($A717) Restore the stack pointer from SavedStackPointer.
B4DF RET Return.
View the equivalent code in;
Prev: B44F Up: Map Next: B4E0