Prev: 29726 Up: Map Next: 29849
29728: Update Score Display
Used by the routines at GameOver, Handler_Fuel and Handler_GhostRider.
Convert the 16-bit into a five digit score using two's complement.
UpdateScoreDisplay 29728 LD HL,(30788) HL=*Score.
29731 LD DE,(30790) DE=*HighScore.
29735 AND A Return if the players score is the same as the stored highscore.
29736 SBC HL,DE
29738 RET Z
29739 ADD HL,DE Restore the original players score value.
This entry point is used by the routine at PrintGameDisplay.
ForceScoreUpdate 29740 LD (30790),HL Update the stored *HighScore value.
29743 EXX Switch to the shadow registers.
29744 LD DE,20934 Set the screen buffer position for the score display.
29747 EXX Switch back to the normal registers.
This entry point is used by the routines at GameOver and PrintGameDisplay.
ConvertScoreToDigits 29748 LD DE,30795 DE=DisplayedScore.
Convert the binary score to decimal using the repeated subtraction method.
Calculate the tens of thousands digit.
29751 LD BC,55312 BC=-10,000 (it's technically -10,224 which is probably a mistake).
29754 LD A,255 Set the digit counter in A to -01.
ExtractTenThousands_Loop 29756 INC A Increment the digit counter by one.
29757 ADD HL,BC Subtract 10,000 from the score.
29758 JR C,ExtractTenThousands_Loop Jump back to ExtractTenThousands_Loop if the result is still positive.
29760 SBC HL,BC Restore the valid remainder.
29762 LD (DE),A Store the count to the score buffer in *DE.
29763 INC E Move to the next score digit position.
Calculate the thousands digit.
29764 LD BC,64536 BC=-1,000.
29767 LD A,255 Set the digit counter in A to -01.
ExtractThousands_Loop 29769 INC A Increment the digit counter by one.
29770 ADD HL,BC Subtract 1,000 from the score remainder.
29771 JR C,ExtractThousands_Loop Jump back to ExtractThousands_Loop if the result is still positive.
29773 SBC HL,BC Restore the valid remainder.
29775 LD (DE),A Store the count to the score buffer in *DE.
29776 INC E Move to the next score digit position.
Calculate the hundreds digit.
29777 LD BC,65436 BC=-100.
29780 LD A,255 Set the digit counter in A to -01.
ExtractHundreds_Loop 29782 INC A Increment the digit counter by one.
29783 ADD HL,BC Subtract 100 from the score remainder.
29784 JR C,ExtractHundreds_Loop Jump back to ExtractHundreds_Loop if the result is still positive.
29786 SBC HL,BC Restore the valid remainder.
29788 LD (DE),A Store the count to the score buffer in *DE.
29789 INC E Move to the next score digit position.
Calculate the tens digit.
29790 LD C,246 C=-10.
29792 LD A,255 Set the digit counter in A to -01.
ExtractTens_Loop 29794 INC A Increment the digit counter by one.
29795 ADD HL,BC Subtract 10 from the score remainder.
29796 JR C,ExtractTens_Loop Jump back to ExtractTens_Loop if the result is still positive.
29798 LD (DE),A Store the count to the score buffer in *DE.
29799 INC E Move to the next score digit position.
Store the units digit.
29800 LD A,L Get the final remainder.
29801 ADD A,10 Compensate for the last subtraction.
29803 LD (DE),A Store the result to the score buffer in *DE.
29804 EXX Switch to the shadow registers.
29805 LD BC,30795 BC'=DisplayedScore.
Work out the ZX Spectrum ROM location of the number UDG, e.g. "1" would be 15753.
This calculation avoids the whitespace at the top and bottom of the ROM UDG; in the code below you'll see it only copies six bytes/ lines.
PrintScoreDigit_Loop 29808 LD A,(BC) Fetch the score digit value.
Calculate the ZX Spectrum ROM font address: 15616 + (digit * 8) + 1.
29809 ADD A,A L'=129+(A*8).
29810 ADD A,A
29811 ADD A,A
29812 ADD A,129
29814 LD L,A
29815 LD H,61 H'=61.
Copy 6 lines of font character data (skipping top and bottom whitespace).
29817 LD A,(HL) Copy a number UDG byte line from the Spectum ROM (*HL') to the screen buffer (*DE').
29818 LD (DE),A
29819 INC L Move to the next font line.
29820 INC D Move down one row in the screen buffer.
29821 LD A,(HL) Copy a number UDG byte line from the Spectum ROM (*HL') to the screen buffer (*DE').
29822 LD (DE),A
29823 INC L Move to the next font line.
29824 INC D Move down one row in the screen buffer.
29825 LD A,(HL) Copy a number UDG byte line from the Spectum ROM (*HL') to the screen buffer (*DE').
29826 LD (DE),A
29827 INC L Move to the next font line.
29828 INC D Move down one row in the screen buffer.
29829 LD A,(HL) Copy a number UDG byte line from the Spectum ROM (*HL') to the screen buffer (*DE').
29830 LD (DE),A
29831 INC L Move to the next font line.
29832 INC D Move down one row in the screen buffer.
29833 LD A,(HL) Copy a number UDG byte line from the Spectum ROM (*HL') to the screen buffer (*DE').
29834 LD (DE),A
29835 INC L Move to the next font line.
29836 INC D Move down one row in the screen buffer.
29837 LD A,(HL) Copy a number UDG byte line from the Spectum ROM (*HL') to the screen buffer (*DE').
29838 LD (DE),A
Reset the screen buffer position.
29839 LD D,81 D'=81.
29841 INC E Move right one character block in the screen buffer, ready to print the next number.
29842 INC C Move to the next digit in the score display buffer.
29843 BIT 3,C Jump back to PrintScoreDigit_Loop until all the digits have been printed.
29845 JR NZ,PrintScoreDigit_Loop
29847 EXX Switch back to the normal registers.
29848 RET Return.
Prev: 29726 Up: Map Next: 29849