Prev: 50892 Up: Map Next: 51019
50922: 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 54, 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 100 at the most.
The percentage is kept in PercentComplete as binary coded decimal, and it is printed as three digits if it is 100, and otherwise as two.
PrintQuestPercentage 50922 LD HL,42831 Start at the table of rooms visited, RoomsVisitedBitmap.
50925 LD C,31 Set a counter in C of 31 bytes.
50927 LD E,0 Set the count of rooms in E to zero.
PrintQuestPercentage_Byte 50929 LD B,8 Set a counter in B of eight bits.
50931 LD A,(HL) Fetch the byte.
PrintQuestPercentage_Bit 50932 RRA Move a bit into the carry flag.
50933 JR NC,PrintQuestPercentage_Next Count the room if the bit is set.
50935 INC E
PrintQuestPercentage_Next 50936 DJNZ PrintQuestPercentage_Bit Decrease the counter and loop until all eight bits have been counted.
50938 INC HL Move on to the next byte.
50939 DEC C Count down the bytes and loop until all of them have been counted.
50940 JR NZ,PrintQuestPercentage_Byte
Add up the points.
50942 SRL E Halve the count of rooms.
50944 LD A,E Fetch it.
50945 CP 54 Jump to PrintQuestPercentage_Total if it is below 54.
50947 JR C,PrintQuestPercentage_Total
50949 LD E,54 Use 54 instead.
PrintQuestPercentage_Total 50951 LD A,(42828) Fetch the number of objects that have been collected.
50954 ADD A,A Multiply it by four.
50955 ADD A,A
50956 ADD A,E Add the points for the rooms.
50957 LD E,A Set the total in E.
50958 LD A,(42827) Fetch the number of stones that have been placed.
50961 ADD A,A Multiply it by two.
50962 LD D,A Stash twice the number of stones in D.
50963 ADD A,A Multiply it by two again.
50964 ADD A,D Add the earlier value, to make six times the number of stones.
50965 ADD A,E Add the total, to make the number of points.
50966 LD B,A Set the counter in B to the number of points.
Convert the points into decimal.
50967 XOR A Start from zero.
PrintQuestPercentage_Count 50968 ADD A,1 Add one.
50970 DAA Convert the number to decimal.
50971 DJNZ PrintQuestPercentage_Count Decrease the counter and loop until it has been added up.
50973 LD (42830),A Set the lower two digits of the percentage.
50976 LD A,0 Set A to zero.
50978 ADC A,0 Add the carry flag, which is set if the percentage is 100 or more.
50980 LD (42829),A Set the digit that is the hundreds.
50983 EX AF,AF' Keep the digit and the flags.
Print the percentage in the buffer.
50984 LD BC,24464 Set the position of the number in BC.
50987 CALL CalculateBufferAddress Call CalculateBufferAddress to get the address in the buffer.
50990 LD L,C Copy it to HL.
50991 LD H,B
50992 EX AF,AF' Restore the digit and the flags.
50993 LD DE,42829 Take the percentage, PercentComplete.
50996 LD B,1 Set a counter in B of one byte.
50998 AND A Jump to PrintQuestPercentage_TwoDigits if the percentage is under 100.
50999 JR Z,PrintQuestPercentage_TwoDigits
51001 INC B Set the counter to two bytes.
51002 PUSH HL Stash the buffer address on the stack.
51003 LD HL,33621 Set FontPointer to Font.
51006 LD (42802),HL
51009 POP HL Restore the buffer address from the stack.
51010 JP PrintBCDNumber_Lower Jump to PrintBCDNumber_Lower to print the digits, starting from the lower digit of the first byte.
PrintQuestPercentage_TwoDigits 51013 INC HL Move on to the next byte and the next place in the buffer.
51014 INC DE
51015 JP PrintBCDNumber Jump to PrintBCDNumber to print the digits.
51018 RET Return, which nothing does.
Prev: 50892 Up: Map Next: 51019