Prev: C6CC Up: Map Next: C74B
C6EA: Print Quest Percentage
Used by the routine at ShowGameOverScreen.
Works out how much of the quest has been done, and prints it to the buffer for the game over screen. The percentage is the number of rooms that have been visited, halved and no more than 36, plus four for each of the objects that have been collected, plus six for each of the stones that have been put on the pentagram. That makes 64 at the most.
The percentage is kept in PercentComplete as binary coded decimal, and it is printed as three digits if it is 64, and otherwise as two.
PrintQuestPercentage C6EA LD HL,$A74F Start at the table of rooms visited, RoomsVisitedBitmap.
C6ED LD C,$1F Set a counter in C of 1F bytes.
C6EF LD E,$00 Set the count of rooms in E to zero.
PrintQuestPercentage_Byte C6F1 LD B,$08 Set a counter in B of eight bits.
C6F3 LD A,(HL) Fetch the byte.
PrintQuestPercentage_Bit C6F4 RRA Move a bit into the carry flag.
C6F5 JR NC,PrintQuestPercentage_Next Count the room if the bit is set.
C6F7 INC E
PrintQuestPercentage_Next C6F8 DJNZ PrintQuestPercentage_Bit Decrease the counter and loop until all eight bits have been counted.
C6FA INC HL Move on to the next byte.
C6FB DEC C Count down the bytes and loop until all of them have been counted.
C6FC JR NZ,PrintQuestPercentage_Byte
Add up the points.
C6FE SRL E Halve the count of rooms.
C700 LD A,E Fetch it.
C701 CP $36 Jump to PrintQuestPercentage_Total if it is below 36.
C703 JR C,PrintQuestPercentage_Total
C705 LD E,$36 Use 36 instead.
PrintQuestPercentage_Total C707 LD A,($A74C) Fetch the number of objects that have been collected.
C70A ADD A,A Multiply it by four.
C70B ADD A,A
C70C ADD A,E Add the points for the rooms.
C70D LD E,A Set the total in E.
C70E LD A,($A74B) Fetch the number of stones that have been placed.
C711 ADD A,A Multiply it by two.
C712 LD D,A Stash twice the number of stones in D.
C713 ADD A,A Multiply it by two again.
C714 ADD A,D Add the earlier value, to make six times the number of stones.
C715 ADD A,E Add the total, to make the number of points.
C716 LD B,A Set the counter in B to the number of points.
Convert the points into decimal.
C717 XOR A Start from zero.
PrintQuestPercentage_Count C718 ADD A,$01 Add one.
C71A DAA Convert the number to decimal.
C71B DJNZ PrintQuestPercentage_Count Decrease the counter and loop until it has been added up.
C71D LD ($A74E),A Set the lower two digits of the percentage.
C720 LD A,$00 Set A to zero.
C722 ADC A,$00 Add the carry flag, which is set if the percentage is 64 or more.
C724 LD ($A74D),A Set the digit that is the hundreds.
C727 EX AF,AF' Keep the digit and the flags.
Print the percentage in the buffer.
C728 LD BC,$5F90 Set the position of the number in BC.
C72B CALL CalculateBufferAddress Call CalculateBufferAddress to get the address in the buffer.
C72E LD L,C Copy it to HL.
C72F LD H,B
C730 EX AF,AF' Restore the digit and the flags.
C731 LD DE,$A74D Take the percentage, PercentComplete.
C734 LD B,$01 Set a counter in B of one byte.
C736 AND A Jump to PrintQuestPercentage_TwoDigits if the percentage is under 64.
C737 JR Z,PrintQuestPercentage_TwoDigits
C739 INC B Set the counter to two bytes.
C73A PUSH HL Stash the buffer address on the stack.
C73B LD HL,$8355 Set FontPointer to Font.
C73E LD ($A732),HL
C741 POP HL Restore the buffer address from the stack.
C742 JP PrintBCDNumber_Lower Jump to PrintBCDNumber_Lower to print the digits, starting from the lower digit of the first byte.
PrintQuestPercentage_TwoDigits C745 INC HL Move on to the next byte and the next place in the buffer.
C746 INC DE
C747 JP PrintBCDNumber Jump to PrintBCDNumber to print the digits.
C74A RET Return, which nothing does.
Prev: C6CC Up: Map Next: C74B