![]() |
Routines |
| Prev: 9C61 | Up: Map | Next: 9D19 |
|
Used by the routine at DrawRoomFrame.
Draws a line between two points with PlotPixel. The longer of the two distances is the number of steps, and the other changes by a fraction of a pixel at each step, which is worked out with Divide. The flags in LineFlags have bit 0 set if the line goes down, and bit 1 set if it goes right.
|
||||||||||||||||||
| DrawLine | 9C79 | LD H,B | Keep the Y position of the first point in H. | |||||||||||||||
| 9C7A | LD L,C | Keep the X position of the first point in L. | ||||||||||||||||
| 9C7B | LD C,$00 | C=00 (the flags). | ||||||||||||||||
| 9C7D | LD A,H | Fetch the Y position of the first point. | ||||||||||||||||
| 9C7E | SUB D | Subtract the Y position of the second point. | ||||||||||||||||
| 9C7F | JR NC,DrawLine_Width | Jump to DrawLine_Width if the line does not go down. | ||||||||||||||||
| 9C81 | NEG | Negate it, to make the distance positive. | ||||||||||||||||
| 9C83 | SET 0,C | Set bit 0 of the flags. | ||||||||||||||||
| DrawLine_Width | 9C85 | LD B,A | Keep the distance up or down in B. | |||||||||||||||
| 9C86 | LD A,L | Fetch the X position of the first point. | ||||||||||||||||
| 9C87 | SUB E | Subtract the X position of the second point. | ||||||||||||||||
| 9C88 | JR NC,DrawLine_Direction | Jump to DrawLine_Direction if the line does not go right. | ||||||||||||||||
| 9C8A | NEG | Negate it, to make the distance positive. | ||||||||||||||||
| 9C8C | SET 1,C | Set bit 1 of the flags. | ||||||||||||||||
| DrawLine_Direction | 9C8E | CP B | Compare the distance across with the distance up or down. | |||||||||||||||
| 9C8F | EX AF,AF' | Switch to the shadow AF register. | ||||||||||||||||
| 9C90 | LD A,C | Fetch the flags. | ||||||||||||||||
| 9C91 | LD ($5E24),A | Write the flags to LineFlags. | ||||||||||||||||
| 9C94 | EX AF,AF' | Switch back to the main AF register. | ||||||||||||||||
| 9C95 | JP C,DrawLine_Height | Jump to DrawLine_Height if the distance up or down is more. | ||||||||||||||||
|
The distance across is the most, so move one pixel across at each step.
|
||||||||||||||||||
| 9C98 | LD ($5E23),A | Write the distance across to LineDistance. | ||||||||||||||||
| 9C9B | PUSH DE | Stash the second point on the stack. | ||||||||||||||||
| 9C9C | PUSH HL | Stash the first point on the stack. | ||||||||||||||||
| 9C9D | LD E,A | Keep the distance across in E. | ||||||||||||||||
| 9C9E | LD D,$00 | Clear the high byte of the distance. | ||||||||||||||||
| 9CA0 | LD L,D | Clear L. | ||||||||||||||||
| 9CA1 | LD H,B | H=the distance up or down. | ||||||||||||||||
| 9CA2 | CALL Divide | Call Divide to work out the fraction of a pixel to move up or down. | ||||||||||||||||
| 9CA5 | LD A,($5E24) | Fetch the line flags from LineFlags. | ||||||||||||||||
| 9CA8 | BIT 0,A | Jump to DrawLine_StepAcross if the line goes down. | ||||||||||||||||
| 9CAA | JR NZ,DrawLine_StepAcross | |||||||||||||||||
| 9CAC | CALL NegateHL | Call NegateHL to negate the fraction. | ||||||||||||||||
| DrawLine_StepAcross | 9CAF | LD A,($5E24) | Fetch the line flags from LineFlags. | |||||||||||||||
| 9CB2 | BIT 1,A | Test bit 1. | ||||||||||||||||
| 9CB4 | LD C,$01 | C=01 (the step to the right). | ||||||||||||||||
| 9CB6 | JR NZ,DrawLine_Across | Jump to DrawLine_Across if the line goes right. | ||||||||||||||||
| 9CB8 | LD C,$FF | C=FF (the step to the left). | ||||||||||||||||
| DrawLine_Across | 9CBA | EX DE,HL | Switch DE and HL. | |||||||||||||||
| 9CBB | POP HL | Restore the first point from the stack. | ||||||||||||||||
| 9CBC | LD A,($5E23) | Fetch the line distance from LineDistance. | ||||||||||||||||
| 9CBF | INC A | Add one, to get the number of steps. | ||||||||||||||||
| 9CC0 | LD B,A | Keep the number of steps in B. | ||||||||||||||||
| 9CC1 | LD A,E | A=E. | ||||||||||||||||
| 9CC2 | EX AF,AF' | Switch to the shadow AF register. | ||||||||||||||||
| DrawLine_AcrossLoop | 9CC3 | PUSH BC | Stash the number of steps and the step across on the stack. | |||||||||||||||
| 9CC4 | CALL PlotPixel | Call PlotPixel to plot the pixel. | ||||||||||||||||
| 9CC7 | LD A,L | A=L. | ||||||||||||||||
| 9CC8 | EX AF,AF' | Switch A with the shadow A. | ||||||||||||||||
| 9CC9 | LD L,A | L=A. | ||||||||||||||||
| 9CCA | ADD HL,DE | Add the fraction to the position. | ||||||||||||||||
| 9CCB | LD A,L | A=L. | ||||||||||||||||
| 9CCC | EX AF,AF' | Switch A with the shadow A. | ||||||||||||||||
| 9CCD | POP BC | Restore the number of steps and the step across from the stack. | ||||||||||||||||
| 9CCE | ADD A,C | Move to the next pixel across. | ||||||||||||||||
| 9CCF | LD L,A | L=A. | ||||||||||||||||
| 9CD0 | DJNZ DrawLine_AcrossLoop | Decrease the number of steps by one and loop back to DrawLine_AcrossLoop until every pixel of the line has been plotted. | ||||||||||||||||
| 9CD2 | POP HL | Restore the second point from the stack. | ||||||||||||||||
| 9CD3 | JP PlotPixel | Jump to PlotPixel to plot the last pixel. | ||||||||||||||||
|
The distance up or down is the most, so move one pixel up or down at each step.
|
||||||||||||||||||
| DrawLine_Height | 9CD6 | EX AF,AF' | Switch to the shadow AF register. | |||||||||||||||
| 9CD7 | LD A,B | Fetch the distance up or down. | ||||||||||||||||
| 9CD8 | LD ($5E23),A | Write the distance up or down to LineDistance. | ||||||||||||||||
| 9CDB | EX AF,AF' | Switch back to the main AF register. | ||||||||||||||||
| 9CDC | PUSH DE | Stash the second point on the stack. | ||||||||||||||||
| 9CDD | PUSH HL | Stash the first point on the stack. | ||||||||||||||||
| 9CDE | LD E,B | Keep the distance up or down in E. | ||||||||||||||||
| 9CDF | LD D,$00 | Clear the high byte of the distance. | ||||||||||||||||
| 9CE1 | LD L,D | Clear L. | ||||||||||||||||
| 9CE2 | LD H,A | H=the distance across. | ||||||||||||||||
| 9CE3 | CALL Divide | Call Divide to work out the fraction of a pixel to move across. | ||||||||||||||||
| 9CE6 | LD A,($5E24) | Fetch the line flags from LineFlags. | ||||||||||||||||
| 9CE9 | BIT 1,A | Jump to DrawLine_StepDown if the line goes right. | ||||||||||||||||
| 9CEB | JR NZ,DrawLine_StepDown | |||||||||||||||||
| 9CED | CALL NegateHL | Call NegateHL to negate the fraction. | ||||||||||||||||
| DrawLine_StepDown | 9CF0 | LD A,($5E24) | Fetch the line flags from LineFlags. | |||||||||||||||
| 9CF3 | BIT 0,A | Test bit 0. | ||||||||||||||||
| 9CF5 | LD C,$01 | C=01 (the step down). | ||||||||||||||||
| 9CF7 | JR NZ,DrawLine_Down | Jump to DrawLine_Down if the line goes down. | ||||||||||||||||
| 9CF9 | LD C,$FF | C=FF (the step up). | ||||||||||||||||
| DrawLine_Down | 9CFB | EX DE,HL | Switch DE and HL. | |||||||||||||||
| 9CFC | POP HL | Restore the first point from the stack. | ||||||||||||||||
| 9CFD | LD A,($5E23) | Fetch the line distance from LineDistance. | ||||||||||||||||
| 9D00 | INC A | Add one, to get the number of steps. | ||||||||||||||||
| 9D01 | LD B,A | Keep the number of steps in B. | ||||||||||||||||
| 9D02 | LD A,E | A=E. | ||||||||||||||||
| 9D03 | EX AF,AF' | Switch to the shadow AF register. | ||||||||||||||||
| DrawLine_DownLoop | 9D04 | PUSH BC | Stash the number of steps and the step down on the stack. | |||||||||||||||
| 9D05 | CALL PlotPixel | Call PlotPixel to plot the pixel. | ||||||||||||||||
| 9D08 | LD A,H | A=H. | ||||||||||||||||
| 9D09 | EX AF,AF' | Switch A with the shadow A. | ||||||||||||||||
| 9D0A | LD H,L | H=L. | ||||||||||||||||
| 9D0B | LD L,A | L=A. | ||||||||||||||||
| 9D0C | ADD HL,DE | Add the fraction to the position. | ||||||||||||||||
| 9D0D | LD A,L | A=L. | ||||||||||||||||
| 9D0E | LD L,H | L=H. | ||||||||||||||||
| 9D0F | EX AF,AF' | Switch A with the shadow A. | ||||||||||||||||
| 9D10 | POP BC | Restore the number of steps and the step down from the stack. | ||||||||||||||||
| 9D11 | ADD A,C | Move to the next pixel down. | ||||||||||||||||
| 9D12 | LD H,A | H=A. | ||||||||||||||||
| 9D13 | DJNZ DrawLine_DownLoop | Decrease the number of steps by one and loop back to DrawLine_DownLoop until every pixel of the line has been plotted. | ||||||||||||||||
| 9D15 | POP HL | Restore the second point from the stack. | ||||||||||||||||
| 9D16 | JP PlotPixel | Jump to PlotPixel to plot the last pixel. | ||||||||||||||||
| Prev: 9C61 | Up: Map | Next: 9D19 |