![]() |
Routines |
| Prev: 679C | Up: Map | Next: 6811 |
|
Used by the routines at Position_Worm_In_Beak, LevelCompleteSoundStep, Handler_RedBird, Handle_Butterfly, CheckCarEggCollision, HandlerFrog01_CheckEggCollision and Check_Hazard_Collision.
Converts a binary score value in A into three decimal digits and adds them to the current score. The digits are stored in the score buffer at CurrentScore. The updated score is then printed to the screen.
|
||||||||
|
Convert the binary value in A into three decimal digits (hundreds, tens, units) stored at 682B-6831.
Extract the hundreds digit.
|
||||||||
| AddToScore | 67B2 | LD HL,$6831 | Point HL at 6831 (the end of ScoreBuffer). | |||||
| 67B5 | LD E,$00 | Initialise E to 00 to count "hundreds". | ||||||
| AddToScore_Hundreds_Loop | 67B7 | CP $64 | Jump to AddToScore_Tens if the score to add is less than a hundred. | |||||
| 67B9 | JR C,AddToScore_Tens | |||||||
| 67BB | SUB $64 | Subtract one hundred from the score to add. | ||||||
| 67BD | INC E | Increment the hundreds digit. | ||||||
| 67BE | JR AddToScore_Hundreds_Loop | Jump back to AddToScore_Hundreds_Loop. | ||||||
|
Store the hundreds digit and extract the tens digit.
|
||||||||
| AddToScore_Tens | 67C0 | LD (HL),E | Write the hundreds digit to the hundreds digit of the score buffer. | |||||
| 67C1 | LD E,$00 | Reset E back to 00 to now count "tens". | ||||||
| 67C3 | DEC HL | Move to the tens digit position. | ||||||
| AddToScore_Tens_Loop | 67C4 | CP $0A | Jump to AddToScore_Units if the score to add is less than ten. | |||||
| 67C6 | JR C,AddToScore_Units | |||||||
| 67C8 | SUB $0A | Subtract ten from the score to add. | ||||||
| 67CA | INC E | Increment the tens digit. | ||||||
| 67CB | JR AddToScore_Tens_Loop | Jump back to AddToScore_Tens_Loop. | ||||||
|
Store the tens digit and extract the units digit.
|
||||||||
| AddToScore_Units | 67CD | LD (HL),E | Write the tens digit to the tens digit of the score buffer. | |||||
| 67CE | LD E,$00 | Reset E back to 00 to now count "units". | ||||||
| 67D0 | DEC HL | Move to the units digit position. | ||||||
| AddToScore_Units_Loop | 67D1 | OR A | Jump to AddToScore_StoreUnits if the score to add is now zero. | |||||
| 67D2 | JR Z,AddToScore_StoreUnits | |||||||
| 67D4 | INC E | Increment the units digit. | ||||||
| 67D5 | DEC A | Decrement the score to add by one. | ||||||
| 67D6 | JR AddToScore_Units_Loop | Jump back to AddToScore_Units_Loop. | ||||||
|
Store the units digit.
|
||||||||
| AddToScore_StoreUnits | 67D8 | LD (HL),E | Write the units digit to *HL. | |||||
|
Add the three expanded digits to the current score stored at CurrentScore.
|
||||||||
| 67D9 | LD DE,$6825 | DE=CurrentScore. | ||||||
| 67DC | LD B,$03 | Set a counter in B for 03 digits to add. | ||||||
| AddToScore_AddLoop | 67DE | LD A,(DE) | Fetch the current score digit. | |||||
| 67DF | ADD A,(HL) | Add the converted digit from *HL. | ||||||
| 67E0 | CP $0A | Is the result 0A or greater/ is there any decimal carry? | ||||||
| 67E2 | PUSH DE | Stash the score and conversion pointers on the stack. | ||||||
| 67E3 | PUSH HL | |||||||
| 67E4 | JR NC,AddToScore_Carry | Jump to AddToScore_Carry if a decimal carry is needed. | ||||||
|
There is no carry so store the result and move to the next digit.
|
||||||||
| 67E6 | POP HL | Restore the score and conversion pointers from the stack. | ||||||
| 67E7 | POP DE | |||||||
| 67E8 | LD (DE),A | Write the updated digit back to the current score. | ||||||
| AddToScore_NextDigit | 67E9 | INC DE | Advance both pointers to the next digit. | |||||
| 67EA | INC HL | |||||||
| 67EB | DJNZ AddToScore_AddLoop | Decrease the counter by one and loop back to AddToScore_AddLoop until all 03 digits are added. | ||||||
| 67ED | JR AddToScore_Print | Jump to AddToScore_Print. | ||||||
|
Handle decimal carry so subtract 0A from the current digit and propagate the carry to higher digits.
|
||||||||
| AddToScore_Carry | 67EF | EX DE,HL | Exchange DE and HL so HL points to the score digit. | |||||
| 67F0 | SUB $0A | Subtract 0A from the digit. | ||||||
| 67F2 | LD (HL),A | Store the wrapped digit. | ||||||
| AddToScore_CarryPropagate | 67F3 | INC HL | Move to the next higher score digit. | |||||
| 67F4 | INC (HL) | Increment it by one. | ||||||
| 67F5 | LD A,(HL) | A=the incremented digit. | ||||||
| 67F6 | CP $0A | Has this digit also reached 0A? | ||||||
| 67F8 | JR NZ,AddToScore_CarryDone | Jump to AddToScore_CarryDone if no further carry is needed. | ||||||
|
This digit also overflowed so wrap it to 00 and continue propagating.
|
||||||||
| 67FA | LD (HL),$00 | Write 00 to *HL. | ||||||
| 67FC | JR AddToScore_CarryPropagate | Jump to AddToScore_CarryPropagate to propagate carry to the next digit. | ||||||
| AddToScore_CarryDone | 67FE | POP HL | Restore the conversion and score pointers from the stack. | |||||
| 67FF | POP DE | |||||||
| 6800 | JR AddToScore_NextDigit | Jump to AddToScore_NextDigit to continue with the next digit. | ||||||
|
Print the updated score to the screen.
|
||||||||
| AddToScore_Print | 6802 | LD HL,$50FD | HL=50FD (screen buffer location). | |||||
| 6805 | PUSH IX | Stash IX on the stack temporarily. | ||||||
| 6807 | LD IX,$6825 | IX=CurrentScore. | ||||||
| 680B | CALL PrintScore | Call PrintScore. | ||||||
| 680E | POP IX | Restore IX from the stack. | ||||||
| 6810 | RET | Return. | ||||||
| Prev: 679C | Up: Map | Next: 6811 |