Prev: 40633 Up: Map Next: 40713
40646: 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 40646 LD A,(38459) Fetch the level of the battery.
40649 CP 24 Jump if it is at least 24.
40651 JR NC,CheckBatteryLow_Ok
40653 LD A,(38480) Fetch the flag that says the message has been queued.
40656 AND A Jump if it has.
40657 JR NZ,CheckBatteryLow_Flash
40659 INC A Set the flag...
40660 LD (38480),A ...and store it.
40663 LD DE,5 Queue message 5, "BATTERY LOW"...
40666 CALL QueueMessage ...using QueueMessage.
CheckBatteryLow_Flash 40669 LD A,(38421) Fetch the frame counter.
40672 BIT 0,A Return on every other frame.
40674 RET NZ
40675 LD C,66 Use red on black as the attribute.
40677 AND 2 Test bit 1 of the frame counter, and jump to use red on black if it is not set.
40679 JR Z,SetBatteryAttributes
40681 LD C,70 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 40683 LD HL,36928 Point HL at the position of the bar, with an X position of 64 and a Y position of 144.
40686 CALL AttributeAddress Convert it into an address in the attribute file using AttributeAddress.
40689 LD E,2 There are two rows of attributes.
CheckBatteryLow_Row 40691 LD B,15 Each row is 15 characters wide.
40693 PUSH HL Save the address of the start of the row.
CheckBatteryLow_Column 40694 LD (HL),C Set the attribute of a character.
40695 INC L Move on to the next character.
40696 DJNZ CheckBatteryLow_Column Loop back until the row is done.
40698 POP HL Restore the address of the start of the row.
40699 LD A,32 Move down to the next row...
40701 CALL AddAToHL ...using AddAToHL.
40704 DEC E Count down the rows.
40705 JR NZ,CheckBatteryLow_Row Loop back until both rows have been done.
40707 RET Return.
The battery is not low, so the message can be queued again the next time it is.
CheckBatteryLow_Ok 40708 XOR A Clear the flag...
40709 LD (38480),A ...that says the message has been queued.
40712 RET Return.
Prev: 40633 Up: Map Next: 40713