Prev: 8148 Up: Map Next: 81B5
8151: Draw a line
Used by the routine at RUN_PICTURE.
A Bresenham stepper in two mirrored halves, picked by bit 0 of C: one walks x as the major axis, the other y. Bit 1 of C is the y direction and bit 2 the x direction. B counts down to the next minor-axis step and is reloaded from the stack each time it runs out; L counts the pixels.
It already steps the coordinates one at a time, so it knows exactly where the next pixel is -- and then calls PLOT_PIXEL, which throws that away and recomputes the address from the coordinates. Carrying the address and mask along the line instead is where the large win is.
Input
DE The point to start from
C Direction flags: bit 0 major axis, bit 1 y, bit 2 x
B Minor-axis step counter
L Length in pixels
DRAW_LINE 8151 BIT 0,C Which axis is the major one
8153 JR NZ,DRAW_LINE_7
8155 PUSH HL x-major from here
8156 PUSH BC
DRAW_LINE_0 8157 CALL PLOT_PIXEL
815A BIT 2,C
815C JR Z,DRAW_LINE_1
815E CALL DEC_X
8161 JR Z,DRAW_LINE_6
8163 JR DRAW_LINE_2
DRAW_LINE_1 8165 CALL INC_X
8168 JR Z,DRAW_LINE_6
DRAW_LINE_2 816A DEC B
816B JR NZ,DRAW_LINE_5
816D BIT 1,C
816F JR Z,DRAW_LINE_3
8171 CALL DEC_Y
8174 JR Z,DRAW_LINE_6
8176 JR DRAW_LINE_4
DRAW_LINE_3 8178 CALL INC_Y
817B JR Z,DRAW_LINE_6
DRAW_LINE_4 817D POP BC
817E PUSH BC
DRAW_LINE_5 817F DEC L
8180 JR NZ,DRAW_LINE_0
DRAW_LINE_6 8182 POP BC
8183 POP HL
8184 RET
DRAW_LINE_7 8185 PUSH HL y-major from here
8186 PUSH BC
DRAW_LINE_8 8187 CALL PLOT_PIXEL
818A BIT 1,C
818C JR Z,DRAW_LINE_9
818E CALL DEC_Y
8191 JR Z,DRAW_LINE_14
8193 JR DRAW_LINE_10
DRAW_LINE_9 8195 CALL INC_Y
8198 JR Z,DRAW_LINE_14
DRAW_LINE_10 819A DEC B
819B JR NZ,DRAW_LINE_13
819D BIT 2,C
819F JR Z,DRAW_LINE_11
81A1 CALL DEC_X
81A4 JR Z,DRAW_LINE_14
81A6 JR DRAW_LINE_12
DRAW_LINE_11 81A8 CALL INC_X
81AB JR Z,DRAW_LINE_14
DRAW_LINE_12 81AD POP BC
81AE PUSH BC
DRAW_LINE_13 81AF DEC L
81B0 JR NZ,DRAW_LINE_8
DRAW_LINE_14 81B2 POP BC
81B3 POP HL
81B4 RET
Prev: 8148 Up: Map Next: 81B5