Prev: 741E Up: Map Next: 7499
7420: 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 7420 LD HL,($7844) HL=*Score.
7423 LD DE,($7846) DE=*HighScore.
7427 AND A Return if the players score is the same as the stored highscore.
7428 SBC HL,DE
742A RET Z
742B ADD HL,DE Restore the original players score value.
This entry point is used by the routine at PrintGameDisplay.
ForceScoreUpdate 742C LD ($7846),HL Update the stored *HighScore value.
742F EXX Switch to the shadow registers.
7430 LD DE,$51C6 Set the screen buffer position for the score display.
7433 EXX Switch back to the normal registers.
This entry point is used by the routines at GameOver and PrintGameDisplay.
ConvertScoreToDigits 7434 LD DE,$784B DE=DisplayedScore.
Convert the binary score to decimal using the repeated subtraction method.
Calculate the tens of thousands digit.
7437 LD BC,$D810 BC=-10,000 (it's technically -10,224 which is probably a mistake).
743A LD A,$FF Set the digit counter in A to -01.
ExtractTenThousands_Loop 743C INC A Increment the digit counter by one.
743D ADD HL,BC Subtract 10,000 from the score.
743E JR C,ExtractTenThousands_Loop Jump back to ExtractTenThousands_Loop if the result is still positive.
7440 SBC HL,BC Restore the valid remainder.
7442 LD (DE),A Store the count to the score buffer in *DE.
7443 INC E Move to the next score digit position.
Calculate the thousands digit.
7444 LD BC,$FC18 BC=-1,000.
7447 LD A,$FF Set the digit counter in A to -01.
ExtractThousands_Loop 7449 INC A Increment the digit counter by one.
744A ADD HL,BC Subtract 1,000 from the score remainder.
744B JR C,ExtractThousands_Loop Jump back to ExtractThousands_Loop if the result is still positive.
744D SBC HL,BC Restore the valid remainder.
744F LD (DE),A Store the count to the score buffer in *DE.
7450 INC E Move to the next score digit position.
Calculate the hundreds digit.
7451 LD BC,$FF9C BC=-100.
7454 LD A,$FF Set the digit counter in A to -01.
ExtractHundreds_Loop 7456 INC A Increment the digit counter by one.
7457 ADD HL,BC Subtract 100 from the score remainder.
7458 JR C,ExtractHundreds_Loop Jump back to ExtractHundreds_Loop if the result is still positive.
745A SBC HL,BC Restore the valid remainder.
745C LD (DE),A Store the count to the score buffer in *DE.
745D INC E Move to the next score digit position.
Calculate the tens digit.
745E LD C,$F6 C=-10.
7460 LD A,$FF Set the digit counter in A to -01.
ExtractTens_Loop 7462 INC A Increment the digit counter by one.
7463 ADD HL,BC Subtract 10 from the score remainder.
7464 JR C,ExtractTens_Loop Jump back to ExtractTens_Loop if the result is still positive.
7466 LD (DE),A Store the count to the score buffer in *DE.
7467 INC E Move to the next score digit position.
Store the units digit.
7468 LD A,L Get the final remainder.
7469 ADD A,$0A Compensate for the last subtraction.
746B LD (DE),A Store the result to the score buffer in *DE.
746C EXX Switch to the shadow registers.
746D LD BC,$784B BC'=DisplayedScore.
Work out the ZX Spectrum ROM location of the number UDG, e.g. "1" would be 3D89.
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 7470 LD A,(BC) Fetch the score digit value.
Calculate the ZX Spectrum ROM font address: 3D00 + (digit * 08) + 01.
7471 ADD A,A L'=81+(A*08).
7472 ADD A,A
7473 ADD A,A
7474 ADD A,$81
7476 LD L,A
7477 LD H,$3D H'=3D.
Copy 06 lines of font character data (skipping top and bottom whitespace).
7479 LD A,(HL) Copy a number UDG byte line from the Spectum ROM (*HL') to the screen buffer (*DE').
747A LD (DE),A
747B INC L Move to the next font line.
747C INC D Move down one row in the screen buffer.
747D LD A,(HL) Copy a number UDG byte line from the Spectum ROM (*HL') to the screen buffer (*DE').
747E LD (DE),A
747F INC L Move to the next font line.
7480 INC D Move down one row in the screen buffer.
7481 LD A,(HL) Copy a number UDG byte line from the Spectum ROM (*HL') to the screen buffer (*DE').
7482 LD (DE),A
7483 INC L Move to the next font line.
7484 INC D Move down one row in the screen buffer.
7485 LD A,(HL) Copy a number UDG byte line from the Spectum ROM (*HL') to the screen buffer (*DE').
7486 LD (DE),A
7487 INC L Move to the next font line.
7488 INC D Move down one row in the screen buffer.
7489 LD A,(HL) Copy a number UDG byte line from the Spectum ROM (*HL') to the screen buffer (*DE').
748A LD (DE),A
748B INC L Move to the next font line.
748C INC D Move down one row in the screen buffer.
748D LD A,(HL) Copy a number UDG byte line from the Spectum ROM (*HL') to the screen buffer (*DE').
748E LD (DE),A
Reset the screen buffer position.
748F LD D,$51 D'=51.
7491 INC E Move right one character block in the screen buffer, ready to print the next number.
7492 INC C Move to the next digit in the score display buffer.
7493 BIT 3,C Jump back to PrintScoreDigit_Loop until all the digits have been printed.
7495 JR NZ,PrintScoreDigit_Loop
7497 EXX Switch back to the normal registers.
7498 RET Return.
Prev: 741E Up: Map Next: 7499