Prev: 44186 Up: Map Next: 44290
44203: Set Up Line
Used by the routine at Draw_Line.
Works out what is needed to draw a line that goes up the screen from the first point (the start) to the second point, one pixel row at a time. The number of steps is the difference between the y positions, and the amount that the x position changes for each step is the difference between the x positions multiplied by 256 and divided by the number of steps (see Divide).
The step count is stored in Line_Step_Count and the direction flags in Line_Direction_Flags (see there). The slope is made negative when the line goes to the left, and it is halved once for each room that the rope is long (the high byte of the length multiplied by two), which scales it to the length of the rope.
Input
HL Start of the line (x position in L, y position in H)
DE End of the line (E is the x position and D is the y position)
Output
A Low byte of the slope
B Number of steps
C Direction of the y position (1 or 255)
DE Slope (x position change per step, multiplied by 256)
HL Start of the line
Find the difference between the y positions (in B) and between the x positions, and the direction flags.
Set_Up_Line 44203 LD C,0 Clear the direction flags.
44205 LD A,H Fetch the y position of the start.
44206 SUB D Jump to Set_Up_Line_Store_Y_Difference if the difference is positive.
44207 JR NC,Set_Up_Line_Store_Y_Difference
44209 NEG Make the difference positive.
44211 SET 0,C Set bit 0 of the direction flags.
Set_Up_Line_Store_Y_Difference 44213 LD B,A Copy the difference to B.
44214 LD A,L Fetch the x position of the start.
44215 SUB E Jump to Set_Up_Line_Store_X_Difference if the difference is positive.
44216 JR NC,Set_Up_Line_Store_X_Difference
44218 NEG Make the difference positive.
44220 SET 1,C Set bit 1 of the direction flags.
Set_Up_Line_Store_X_Difference 44222 EX AF,AF' Stash the difference between the x positions in AF'.
44223 LD A,C Fetch the direction flags.
44224 LD (43668),A Store the direction flags.
44227 LD A,B Fetch the difference between the y positions.
44228 LD (43667),A Store the number of steps.
44231 EX AF,AF' Restore the difference between the x positions from AF'.
Divide the difference between the x positions by the number of steps.
44232 PUSH HL Stash the start of the line on the stack.
44233 LD E,B Copy the number of steps to E.
44234 LD D,0 Make D zero.
44236 LD L,D Clear L.
44237 LD H,A Copy the difference between the x positions to H.
44238 CALL Divide Divide the difference by the number of steps (the result is the slope).
44241 LD A,(43668) Fetch the direction flags.
44244 BIT 1,A Jump to Set_Up_Line_Check_Vertical_Direction if bit 1 is set (the line goes to the right).
44246 JR NZ,Set_Up_Line_Check_Vertical_Direction
44248 CALL NegateHL Make the slope negative.
Set_Up_Line_Check_Vertical_Direction 44251 LD A,(43668) Fetch the direction flags.
44254 BIT 0,A Test bit 0 of the direction flags.
44256 LD C,1 Set the vertical step of the line to 1.
44258 JR NZ,Set_Up_Line_Store_Slope Jump to Set_Up_Line_Store_Slope if bit 0 is set.
44260 LD C,255 Set the vertical step of the line to 255.
Set_Up_Line_Store_Slope 44262 EX DE,HL Move the slope to DE and the remainder to HL.
44263 POP HL Restore the start of the line from the stack.
44264 LD A,(43667) Fetch the number of steps.
44267 LD B,A Copy it to B.
44268 PUSH BC Stash the number of steps and the direction on the stack.
Halve the slope once for each room that the rope is long.
44269 LD BC,(43685) Fetch the length of the rope.
44273 RL C Double the length.
44275 RL B
44277 LD A,B Copy the high byte to A.
44278 AND A Jump to Set_Up_Line_Finish if the rope is not longer than a room.
44279 JR Z,Set_Up_Line_Finish
Set_Up_Line_Halve_Slope_Loop 44281 SRA D Halve the slope.
44283 RR E
44285 DJNZ Set_Up_Line_Halve_Slope_Loop Decrease the room counter and loop back until the slope has been halved for each room.
Set_Up_Line_Finish 44287 POP BC Restore the number of steps and the direction from the stack.
44288 LD A,E Copy the low byte of the slope to A.
44289 RET Return.
Prev: 44186 Up: Map Next: 44290