Prev: BBC7 Up: Map Next: BC66
BC10: Print Percentage Complete
Used by the routine at GameOver.
Works out how much of the quest has been completed and prints the percentage in the screen buffer. Each room that has been visited counts for one point and each charm that has been put in the cauldron counts for two. The most that can be scored is 9C points (80 rooms and 0E charms counted twice), so each point is worth about 0.64 percent. The percentage is worked out as a BCD number and is printed with the hundreds digit only if the quest has been completed in full.
PrintPercentageComplete BC10 LD E,$00 Set the count of rooms to zero.
BC12 LD BC,$0820 Set B to the number of bits in a byte and C to the number of bytes of flags.
BC15 LD HL,$5BE8 Point HL at the flags for the rooms that have been visited, RoomsVisitedBitmap.
PrintPercentageComplete_CountByte BC18 PUSH BC Stash the counters on the stack.
BC19 LD A,(HL) Fetch a byte of flags.
BC1A INC HL Move on to the next byte.
PrintPercentageComplete_CountBit BC1B RRCA Move a flag into the carry flag.
BC1C JR NC,PrintPercentageComplete_NextBit Jump to PrintPercentageComplete_NextBit if the room has not been visited.
BC1E INC E Count the room.
PrintPercentageComplete_NextBit BC1F DJNZ PrintPercentageComplete_CountBit Jump to PrintPercentageComplete_CountBit until the whole byte has been counted.
BC21 POP BC Restore the counters from the stack.
BC22 DEC C Decrease the number of bytes left.
BC23 JR NZ,PrintPercentageComplete_CountByte Jump to PrintPercentageComplete_CountByte until all of the bytes have been counted.
Keep the number of rooms visited for the rating, and work out the number of points.
BC25 LD A,E Fetch the number of rooms visited.
BC26 DEC A Take off one, so that the first room does not count towards the rating.
BC27 LD ($5BC6),A Store it for the rating at RoomsVisited.
BC2A LD A,($5BBB) Fetch the number of charms collected from Charms.
BC2D SLA A Double it.
BC2F ADD A,E Add the number of rooms visited.
BC30 LD E,A Stash the number of points in E.
Add up the percentage as a BCD number. The percentage that each point is worth is the 16-bit fraction A41A (about 0.64 percent).
BC31 LD BC,$A41A Set BC to the percentage that each point is worth.
BC34 LD HL,$0000 Clear the fraction of the percentage.
BC37 XOR A Clear the whole percentage.
PrintPercentageComplete_AddPoint BC38 ADD HL,BC Add the percentage for a point to the fraction.
BC39 ADC A,$00 Carry into the whole percentage.
BC3B DAA Keep the whole percentage as a BCD number.
BC3C DEC E Decrease the number of points left.
BC3D JR NZ,PrintPercentageComplete_AddPoint Jump to PrintPercentageComplete_AddPoint until every point has been added.
BC3F LD BC,$0028 Set BC to the amount that makes up for the rounding. The 24-bit total for all of the points is 63FF in the high word and D8 in the low byte, and this takes it up to 6400 in the high word.
BC42 ADD HL,BC Add it to the fraction.
BC43 ADC A,$00 Carry into the whole percentage.
BC45 DAA Keep the whole percentage as a BCD number.
BC46 LD ($5BCA),A Store the lowest two digits of the percentage.
BC49 LD A,$00 Clear A without changing the carry flag.
BC4B ADC A,$00 Carry into the hundreds digit.
BC4D DAA Keep the hundreds digit as a BCD number.
BC4E LD ($5BC9),A Store the hundreds digit at PercentComplete.
Print the digits.
BC51 LD HL,$E4E6 Point HL at ScreenBuffer_ResultsPercentage.
BC54 LD DE,$5BC9 Point DE at PercentComplete.
BC57 LD B,$01 Set the number of bytes to print to 01.
BC59 LD A,(DE) Fetch the hundreds digit.
BC5A AND A Test whether it is zero.
BC5B JR Z,PrintPercentageComplete_TwoDigits Jump to PrintPercentageComplete_TwoDigits if the quest is not complete.
BC5D INC B Set the number of bytes to print to 02.
BC5E JP PrintBCDNumber_SecondDigit Jump to PrintBCDNumber_SecondDigit to print the hundreds digit and then the rest.
PrintPercentageComplete_TwoDigits BC61 INC HL Move the position past the space for the hundreds digit.
BC62 INC DE Move on to the lowest two digits.
BC63 JP PrintBCDNumber Jump to PrintBCDNumber to print them.
Prev: BBC7 Up: Map Next: BC66