Prev: 40527 Up: Map Next: 40633
40533: Update Battery Bar
Moves the displayed level of the battery bar by one pixel column towards the actual level, which is a number from 0 to 116. The bar is drawn by toggling the pixels of one column, so it is added to or taken away from the end of the bar. This is called every frame.
UpdateBatteryBar_Increase 40533 INC A Add one to the displayed level.
40534 LD B,A Keep the displayed level.
40535 LD HL,37951 Point HL at the position of the column before the first one (which has an X position of 63), so that when the level is added the column that is drawn is the first one that is not yet lit.
40538 JR UpdateBatteryBar_Draw Jump to draw the column.
This entry point is used by the routine at MainLoop.
UpdateBatteryBar 40540 LD A,(38459) Fetch the actual level of the battery.
40543 LD B,A Keep the actual level.
40544 LD A,(38460) Fetch the displayed level of the battery.
40547 CP B Return if the two are the same.
40548 RET Z
40549 JR C,UpdateBatteryBar_Increase Jump if the displayed level is lower than the actual level.
40551 LD B,A Keep the displayed level.
40552 DEC A Take one pixel column off the displayed level.
40553 LD HL,37952 Point HL at the position of the first column, which has an X position of 64 and a Y position of 148.
UpdateBatteryBar_Draw 40556 LD (38460),A Store the new displayed level.
40559 ADD A,L Add the X position to find the X position of the column that is to be drawn...
40560 LD L,A ...and put it in the position.
40561 LD C,A Keep the X position.
40562 CALL ScreenAddress Convert the position into a screen address using ScreenAddress.
40565 LD A,B Fetch the level.
40566 EX AF,AF' Keep the level.
40567 EXX Switch to the shadow registers.
40568 LD HL,40633 Point HL' at BatteryBarPattern.
40571 EXX Switch back to the main registers.
40572 LD A,C Fetch the X position.
40573 CPL Find the number of the bit that the column is in, as a number of pixels from the right...
40574 AND 7 ...limited to a character.
40576 LD B,A Keep the column within the character.
40577 LD C,8 The column has 8 rows.
40579 INC B Add one, as it will be used to shift the pattern.
40580 EX AF,AF' Fetch the level.
40581 CP 5 Jump if the level is at least five, as the column is then not part of the rounded end of the bar.
40583 JR NC,UpdateBatteryBar_Row
40585 LD D,B Save the shift.
40586 PUSH HL Save the screen address.
40587 LD HL,40641 Point HL at the table of the number of rows to skip at the top and the bottom of the column.
40590 CALL AddAToHL Add the level, using AddAToHL.
40593 LD B,(HL) Fetch the number of rows to skip.
40594 POP HL Restore the screen address.
UpdateBatteryBar_SkipRows 40595 DEC C Take off two rows from the end of the column...
40596 DEC C ...for each row that is skipped at the top...
40597 INC H ...and move down one pixel row.
40598 EXX Switch to the shadow registers...
40599 INC HL ...and skip a byte of the pattern...
40600 EXX ...and switch back.
40601 DJNZ UpdateBatteryBar_SkipRows Loop back until the rows have been skipped.
40603 LD B,D Restore the shift.
UpdateBatteryBar_Row 40604 EXX Switch to the shadow registers.
40605 LD A,(HL) Fetch the next byte of the pattern.
40606 INC HL Move on to the next byte of the pattern.
40607 EXX Switch back to the main registers.
40608 EX DE,HL Keep the screen address.
40609 LD L,A Put the byte of the pattern in HL...
40610 LD H,0 ...as a two byte number.
40612 LD A,B Fetch the level...
UpdateBatteryBar_ShiftPattern 40613 ADD HL,HL ...and shift the pattern left by the number of pixels needed to put the pixel in the right place.
40614 DJNZ UpdateBatteryBar_ShiftPattern Restore the shift.
40616 LD B,A Keep the level.
40617 EX DE,HL Restore the screen address and the shifted pattern.
40618 LD A,D Fetch the first byte of the shifted pattern...
40619 XOR (HL) ...toggle it on the screen...
40620 LD (HL),A ...and store it.
40621 INC L Move on to the next byte of the screen.
40622 LD A,E Fetch the second byte of the shifted pattern...
40623 XOR (HL) ...toggle it on the screen...
40624 LD (HL),A ...and store it.
40625 DEC L Move back to the first byte.
40626 CALL NextPixelRow Move down to the next pixel row using NextPixelRow.
40629 DEC C Count down the rows.
40630 JR NZ,UpdateBatteryBar_Row Loop back until the whole column has been drawn.
40632 RET Return.
Prev: 40527 Up: Map Next: 40633