Skip to navigation

Scanner/energy row: UpdateIconsScanner

Name: UpdateIconsScanner [Show more] Type: Subroutine Category: Scanner/energy row Summary: Update the icons in the top-left corner of the screen to show the player's current energy level and redraw the scanner box
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * DrainObjectEnergy calls UpdateIconsScanner * MainGameLoop calls UpdateIconsScanner * ProcessGameplay calls UpdateIconsScanner
.UpdateIconsScanner LDA #0 \ Set A = 0 to pass to DrawIcon STA xIconCounter \ Set xIconCounter = 0 so we start drawing from the left \ edge of the screen JSR DrawIcon \ Draw a blank icon into the top part of the screen (via \ the icon screen buffer at iconBuffer) and move along \ to the right, incrementing xIconCounter as we do LDA playerEnergy \ Set a loop counter to count down through the player's STA loopCounter \ energy, so we can reduce it by the maximum possible \ amount each time to work out the minimum number of \ icons that represent that energy level \ \ In other words, loopCounter contains the amount of \ energy that we have yet to draw .ener1 LDA loopCounter \ If loopCounter < 15 then we can't represent it with a CMP #15 \ high-energy robot (as that represents 15 energy BCC ener2 \ units), so jump to ener2 to skip to the next level \ down SBC #15 \ Subtract 15 from the loop counter as we are about to STA loopCounter \ draw a high-energy robot that represents 15 energy \ units (this subtraction works because we just passed \ through a BCC, so the C flag must be set) LDA #6 \ Draw a high-energy robot into the top part of the JSR DrawIcon \ screen (via the icon screen buffer at iconBuffer) and \ move along to the right, incrementing xIconCounter as \ we do LDA #0 \ Draw a blank icon into the top part of the screen (via JSR DrawIcon \ the icon screen buffer at iconBuffer) and move along \ to the right, incrementing xIconCounter as we do JMP ener1 \ Loop back to ener1 to draw another high-energy robot, \ if required .ener2 LDA loopCounter \ If loopCounter < 3 then we can't represent it with a CMP #3 \ blue robot (as that represents three energy units), BCC ener3 \ so jump to ener3 to skip to the next level down SBC #3 \ Subtract 3 from the loop counter as we are about to STA loopCounter \ draw a high-energy robot that represents three energy \ units (this subtraction works because we just passed \ through a BCC, so the C flag must be set) LDA #1 \ Draw a blue robot into the top part of the screen (via JSR DrawIcon \ the icon screen buffer at iconBuffer) and move along \ to the right, incrementing xIconCounter as we do LDA #0 \ Draw a blank icon into the top part of the screen (via JSR DrawIcon \ the icon screen buffer at iconBuffer) and move along \ to the right, incrementing xIconCounter as we do JMP ener2 \ Loop back to ener2 to draw another blue robot, if \ required .ener3 \ If we get here then the value of loopCounter in A must \ be 0, 1 or 2, as otherwise we would still be drawing \ robots CMP #1 \ If A < 1 then A must be zero, so jump to ener4 to move BCC ener4 \ on to the scanner as we have no more energy units to \ draw ASL A \ If we get here then A is 1 or 2, so double it to get \ the correct icon numbers for the left part of the \ two-part tree or boulder icons: \ \ * When A = 1, double it to 2 for the left tree icon \ \ * When A = 2, double it to 4 for the left boulder \ icon JSR DrawIcon \ Draw the correct left icon into the top part of the \ screen (via the icon screen buffer at iconBuffer) and \ move along to the right, incrementing xIconCounter as \ we do CLC \ Increment A to get the correct icon number for the ADC #1 \ right part of the tree or boulder JSR DrawIcon \ Draw the correct right icon into the top part of the \ screen (via the icon screen buffer at iconBuffer) and \ move along to the right, incrementing xIconCounter as \ we do \ We have updated the energy icons, so now we blank the \ rest of the top line of the screen before drawing the \ outline of the scanner .ener4 LDA #0 \ Draw a blank icon into the top part of the screen (via JSR DrawIcon \ the icon screen buffer at iconBuffer) and move along \ to the right, incrementing xIconCounter as we do LDA xIconCounter \ Loop back to keep drawing blank icons until we reach CMP #29 \ column 29, which is where we want to draw the scanner BCC ener4 LDA #7 \ Draw the left edge of the scanner box into the top JSR DrawIcon \ part of the screen (via the icon screen buffer at \ iconBuffer) and move along to the right, incrementing \ xIconCounter as we do .ener5 LDA #8 \ Draw the middle part of the scanner box into the top JSR DrawIcon \ part of the screen (via the icon screen buffer at \ iconBuffer) and move along to the right, incrementing \ xIconCounter as we do LDA xIconCounter \ Loop back to keep drawing the middle part of the CMP #38 \ scanner box until we reach column 38 BCC ener5 LDA #9 \ Draw the right edge of the scanner box into the top JSR DrawIcon \ part of the screen (via the icon screen buffer at \ iconBuffer) and move along to the right, incrementing \ xIconCounter as we do LDA #0 \ Draw a blank icon into the top part of the screen (via JSR DrawIcon \ the icon screen buffer at iconBuffer) and move along \ to the right JMP ShowIconBuffer \ Display the contents of the icon screen buffer by \ copying it into screen memory, returning from the \ subroutine using a tail call