Prev: 8BBB Up: Map Next: 8C3E
8C01: 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 8C01 LD C,A Stash the gauge byte.
Stash the screen location for later, as we'll need it to gain the screen buffer address.
8C02 PUSH HL Stash HL on the stack.
8C03 CALL AttributeAddress Call AttributeAddress.
Restore the gauge value.
8C06 LD A,C A=C.
Divide by 08 to leave the number of whole cells.
8C07 RRCA Rotate the bits right three times (including the carry).
8C08 RRCA
8C09 RRCA
8C0A AND %00011111 Keep only bits 0-4.
8C0C JR Z,DrawGauge_Draw Jump to DrawGauge_Draw if there are no whole cells to fill.
8C0E LD B,A B=A.
Copy the INK bits into PAPER as the bar is filled.
DrawGauge_Find 8C0F LD A,(HL) Fetch the current attribute byte.
8C10 RLCA Rotate the bits left three times (including the carry).
8C11 RLCA
8C12 RLCA
8C13 AND %00111000 Keep only bits 3-5 (the INK bits, now in the PAPER position).
8C15 OR (HL) Merge them back into the attribute byte.
8C16 LD (HL),A
8C17 INC HL Increment HL by one.
8C18 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 8C1A LD A,(HL) A=*HL.
Remove the PAPER bits.
8C1B AND %11000111 Keep only bits 0-2, 6-7.
8C1D LD (HL),A Write A back to *HL.
Store the attribute buffer address in DE.
8C1E EX DE,HL Switch the DE and HL registers.
Restore the screen location for the screen buffer address call.
8C1F POP HL Restore HL from the stack.
8C20 CALL ScreenAddress Call ScreenAddress.
8C23 LD A,E A=E.
8C24 AND %00011111 Keep only bits 0-4.
8C26 LD E,A E=A.
8C27 LD A,L A=L.
8C28 AND %11100000 Keep only bits 5-7.
8C2A OR E Merge in the column bits.
8C2B LD L,A
Restore the gauge value.
8C2C LD A,C A=C.
The gradient lines are stored in the font at: Font_Gradient.
00 gradient-0
01 gradient-1
02 gradient-2
03 gradient-3
04 gradient-4
05 gradient-5
06 gradient-6
07 gradient-7
There are 8 gradient line images, so keep the index between 00 and 07.
8C2D AND %00000111 Keep only bits 0-2.
The first value is 5B which corresponds to "gradient-0" (the smallest gradient).
8C2F ADD A,$5B A=A+5B.
8C31 CALL PrintScreen Call PrintScreen.
Restore the gauge value.
8C34 LD A,C A=C.
8C35 CPL Flip the bits.
8C36 AND %00000111 Keep only bits 0-2.
8C38 RET NZ Return if the result is not zero.
8C39 LD A,$20 A=20.
8C3B JP PrintScreen Jump to PrintScreen.
Prev: 8BBB Up: Map Next: 8C3E