Prev: 9EB9 Up: Map Next: 9F09
9EC6: Check Battery Low
Used by the routine at MainLoop.
Called every frame. If the battery is almost empty then the message "BATTERY LOW" is queued, once, and the battery bar flashes red and yellow.
Input
C Attribute
CheckBatteryLow 9EC6 LD A,($963B) Fetch the level of the battery.
9EC9 CP $18 Jump if it is at least 18.
9ECB JR NC,CheckBatteryLow_Ok
9ECD LD A,($9650) Fetch the flag that says the message has been queued.
9ED0 AND A Jump if it has.
9ED1 JR NZ,CheckBatteryLow_Flash
9ED3 INC A Set the flag...
9ED4 LD ($9650),A ...and store it.
9ED7 LD DE,$0005 Queue message 05, "BATTERY LOW"...
9EDA CALL QueueMessage ...using QueueMessage.
CheckBatteryLow_Flash 9EDD LD A,($9615) Fetch the frame counter.
9EE0 BIT 0,A Return on every other frame.
9EE2 RET NZ
9EE3 LD C,$42 Use red on black as the attribute.
9EE5 AND $02 Test bit 1 of the frame counter, and jump to use red on black if it is not set.
9EE7 JR Z,SetBatteryAttributes
9EE9 LD C,$46 Otherwise use yellow on black.
This entry point is used by the routines at RechargeBattery and HandleObstacle.
This entry point sets the attribute of the battery bar.
SetBatteryAttributes 9EEB LD HL,$9040 Point HL at the position of the bar, with an X position of 40 and a Y position of 90.
9EEE CALL AttributeAddress Convert it into an address in the attribute file using AttributeAddress.
9EF1 LD E,$02 There are two rows of attributes.
CheckBatteryLow_Row 9EF3 LD B,$0F Each row is 0F characters wide.
9EF5 PUSH HL Save the address of the start of the row.
CheckBatteryLow_Column 9EF6 LD (HL),C Set the attribute of a character.
9EF7 INC L Move on to the next character.
9EF8 DJNZ CheckBatteryLow_Column Loop back until the row is done.
9EFA POP HL Restore the address of the start of the row.
9EFB LD A,$20 Move down to the next row...
9EFD CALL AddAToHL ...using AddAToHL.
9F00 DEC E Count down the rows.
9F01 JR NZ,CheckBatteryLow_Row Loop back until both rows have been done.
9F03 RET Return.
The battery is not low, so the message can be queued again the next time it is.
CheckBatteryLow_Ok 9F04 XOR A Clear the flag...
9F05 LD ($9650),A ...that says the message has been queued.
9F08 RET Return.
Prev: 9EB9 Up: Map Next: 9F09