Prev: A6EB Up: Map Next: A7C0
A724: Draw Direction Gauge
Used by the routines at UpdateDirectionGauge, StartGame and DrawPanel.
Draws a direction gauge, which shows the heading in ScratchValue by a needle with a ball at its tip. The picture of the dial is copied into the buffer at F517 the needle is drawn into it, and the buffer is then copied to the screen. The picture is seven bytes wide and 1C pixel lines high.
DrawDirectionGauge A724 LD DE,$F517 Point DE at the buffer.
A727 LD HL,$822D Point HL at DialPicture_Row10.
A72A LD BC,$00C4 Set the number of bytes to C4.
A72D LDIR Copy the picture into the buffer.
A72F LD A,($5CD8) Fetch the heading.
A732 CALL GetDirectionVector_Heading Call A6F1 to find the components of the heading.
A735 PUSH HL Save the second component.
A736 PUSH BC Save the first component.
A737 POP HL Retrieve the first component in HL...
A738 POP BC ...and the second in BC.
A739 PUSH HL Save the first component.
A73A PUSH BC Save the second component.
A73B PUSH HL Save the first component again.
A73C LD L,C Copy the low byte of the second component into L...
A73D LD H,B ...and the high byte into H.
A73E EXX Switch to the alternate registers.
A73F POP DE Retrieve the first component in DE.
A740 LD B,$18 Set the length of the needle to 18.
A742 CALL DrawLine Call DrawLine to draw the needle.
A745 POP HL Retrieve the second component.
A746 LD A,H Fetch the sign byte of the component.
A747 LD H,$00 Clear H.
A749 ADD HL,HL Multiply the component by two...
A74A ADD HL,HL ...four...
A74B ADD HL,HL ...and eight.
A74C LD C,L Copy it into BC.
A74D LD B,H
A74E ADD HL,HL Multiply it by sixteen...
A74F ADD HL,BC ...and add the eight times value to make twenty-four times.
A750 AND A Test the sign byte.
A751 LD A,H Fetch the high byte of the result, which is the offset in pixels.
A752 JR Z,DrawDirectionGauge_Offset Jump to DrawDirectionGauge_Offset if the component was positive.
A754 NEG Make the offset negative.
DrawDirectionGauge_Offset A756 INC A Add one.
A757 LD ($5CDC),A Store the offset in DrawingPosition.
A75A SRA A Divide the offset by two...
A75C SRA A ...four...
A75E SRA A ...and eight to find the byte.
A760 ADD A,$8A Add the offset of the needle in the buffer.
A762 LD E,A Keep the column in E.
A763 POP HL Retrieve the first component.
A764 LD A,H Fetch the sign byte of the component.
A765 LD H,$00 Clear H.
A767 ADD HL,HL Multiply the component by two...
A768 ADD HL,HL ...and four.
A769 LD C,L Copy it into BC.
A76A LD B,H
A76B ADD HL,HL Multiply it by eight...
A76C ADD HL,BC ...and add the four times value to make twelve times.
A76D AND A Test the sign byte.
A76E LD A,H Fetch the high byte of the result, which is the offset in pixel lines.
A76F JR NZ,DrawDirectionGauge_Row Jump to DrawDirectionGauge_Row if the component was negative.
A771 NEG Make the offset negative.
DrawDirectionGauge_Row A773 LD B,A Keep the offset in B.
A774 ADD A,A Multiply it by two...
A775 ADD A,A ...four...
A776 ADD A,A ...and eight.
A777 SUB B Subtract the offset to make seven times the offset.
A778 ADD A,E Add the column.
A779 LD L,A Set the low byte of the address in the buffer.
A77A LD H,$F5 Set the high byte of the address in the buffer.
A77C CALL DrawNeedleTip Call DrawNeedleTip to draw the ball at the tip of the needle.
Copy the buffer to the screen.
A77F LD ($5CDA),SP Save the stack pointer.
A783 LD SP,$F517 Point the stack at the buffer.
A786 LD HL,$55A2 Point HL at the bottom left of the position on the screen.
A789 LD A,$00 Load the offset of the gauge on the screen (this is set at A78A).
A78B ADD A,L Add it to the address.
A78C LD L,A Set the low byte of the address.
A78D LD B,$1C Set the number of pixel lines to 1C.
DrawDirectionGauge_Line A78F LD C,L Remember the start of the line.
A790 POP DE Fetch the first two bytes of the line.
A791 LD (HL),E Store the first byte.
A792 INC L Move onto the next byte of the line.
A793 LD (HL),D Store the second byte.
A794 INC L Move onto the next byte of the line.
A795 POP DE Fetch the third and fourth bytes of the line.
A796 LD (HL),E Store the third byte.
A797 INC L Move onto the next byte of the line.
A798 LD (HL),D Store the fourth byte.
A799 INC L Move onto the next byte of the line.
A79A POP DE Fetch the fifth and sixth bytes of the line.
A79B LD (HL),E Store the fifth byte.
A79C INC L Move onto the next byte of the line.
A79D LD (HL),D Store the sixth byte.
A79E INC L Move onto the next byte of the line.
A79F POP DE Fetch the seventh byte and the first byte of the next line.
A7A0 DEC SP Step back over the byte of the next line.
A7A1 LD (HL),E Store the seventh byte.
A7A2 DEC B Decrease the number of lines by one.
A7A3 JR Z,DrawDirectionGauge_Done Jump to DrawDirectionGauge_Done if all of the lines have been copied.
A7A5 LD L,C Go back to the start of the line.
A7A6 LD A,H Fetch the high byte of the address.
A7A7 DEC H Move up a pixel line.
A7A8 AND %00000111 Keep the number of the pixel line which the line was in.
A7AA JP NZ,DrawDirectionGauge_Line Jump back to copy the next line unless that was the top pixel line of a character row.
A7AD LD A,L Fetch the low byte of the address.
A7AE SUB $20 Move up a character row.
A7B0 LD L,A Store it.
A7B1 JP C,DrawDirectionGauge_Line Jump back to copy the next line if the row was at the top of a screen section.
A7B4 LD A,H Fetch the high byte of the address.
A7B5 ADD A,$08 Move to the bottom pixel line of the character row.
A7B7 LD H,A Store it.
A7B8 JP DrawDirectionGauge_Line Jump back to copy the next line.
DrawDirectionGauge_Done A7BB LD SP,($5CDA) Restore the stack pointer.
A7BF RET Return.
Prev: A6EB Up: Map Next: A7C0