Prev: 35771 Up: Map Next: 35902
35841: Draw Gauge
Draw a fuel/level bar at the given screen position, using the gauge value as both length and gradient.
Input
A Gauge value (bits 3-7 whole cells, bits 0-2 gradient)
HL Screen location
Stash the gauge value for later.
DrawGauge 35841 LD C,A Stash the gauge byte.
Stash the screen location for later, as we'll need it to gain the screen buffer address.
35842 PUSH HL Stash HL on the stack.
35843 CALL AttributeAddress Call AttributeAddress.
Restore the gauge value.
35846 LD A,C A=C.
Divide by 8 to leave the number of whole cells.
35847 RRCA Rotate the bits right three times (including the carry).
35848 RRCA
35849 RRCA
35850 AND %00011111 Keep only bits 0-4.
35852 JR Z,DrawGauge_Draw Jump to DrawGauge_Draw if there are no whole cells to fill.
35854 LD B,A B=A.
Copy the INK bits into PAPER as the bar is filled.
DrawGauge_Find 35855 LD A,(HL) Fetch the current attribute byte.
35856 RLCA Rotate the bits left three times (including the carry).
35857 RLCA
35858 RLCA
35859 AND %00111000 Keep only bits 3-5 (the INK bits, now in the PAPER position).
35861 OR (HL) Merge them back into the attribute byte.
35862 LD (HL),A
35863 INC HL Increment HL by one.
35864 DJNZ DrawGauge_Find Decrease the counter by one and jump back to DrawGauge_Find until it is zero.
Fetch the attribute byte for where the gauge ends.
DrawGauge_Draw 35866 LD A,(HL) A=*HL.
Remove the PAPER bits.
35867 AND %11000111 Keep only bits 0-2, 6-7.
35869 LD (HL),A Write A back to *HL.
Store the attribute buffer address in DE.
35870 EX DE,HL Switch the DE and HL registers.
Restore the screen location for the screen buffer address call.
35871 POP HL Restore HL from the stack.
35872 CALL ScreenAddress Call ScreenAddress.
35875 LD A,E A=E.
35876 AND %00011111 Keep only bits 0-4.
35878 LD E,A E=A.
35879 LD A,L A=L.
35880 AND %11100000 Keep only bits 5-7.
35882 OR E Merge in the column bits.
35883 LD L,A
Restore the gauge value.
35884 LD A,C A=C.
The gradient lines are stored in the font at: Font_Gradient.
0 gradient-0
1 gradient-1
2 gradient-2
3 gradient-3
4 gradient-4
5 gradient-5
6 gradient-6
7 gradient-7
There are 8 gradient line images, so keep the index between 0 and 7.
35885 AND %00000111 Keep only bits 0-2.
The first value is 91 which corresponds to "gradient-0" (the smallest gradient).
35887 ADD A,91 A=A+91.
35889 CALL PrintScreen Call PrintScreen.
Restore the gauge value.
35892 LD A,C A=C.
35893 CPL Flip the bits.
35894 AND %00000111 Keep only bits 0-2.
35896 RET NZ Return if the result is not zero.
35897 LD A,32 A=32.
35899 JP PrintScreen Jump to PrintScreen.
Prev: 35771 Up: Map Next: 35902