Prev: 48071 Up: Map Next: 48230
48144: 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 156 points (128 rooms and 14 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 48144 LD E,0 Set the count of rooms to zero.
48146 LD BC,2080 Set B to the number of bits in a byte and C to the number of bytes of flags.
48149 LD HL,23528 Point HL at the flags for the rooms that have been visited, RoomsVisitedBitmap.
PrintPercentageComplete_CountByte 48152 PUSH BC Stash the counters on the stack.
48153 LD A,(HL) Fetch a byte of flags.
48154 INC HL Move on to the next byte.
PrintPercentageComplete_CountBit 48155 RRCA Move a flag into the carry flag.
48156 JR NC,PrintPercentageComplete_NextBit Jump to PrintPercentageComplete_NextBit if the room has not been visited.
48158 INC E Count the room.
PrintPercentageComplete_NextBit 48159 DJNZ PrintPercentageComplete_CountBit Jump to PrintPercentageComplete_CountBit until the whole byte has been counted.
48161 POP BC Restore the counters from the stack.
48162 DEC C Decrease the number of bytes left.
48163 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.
48165 LD A,E Fetch the number of rooms visited.
48166 DEC A Take off one, so that the first room does not count towards the rating.
48167 LD (23494),A Store it for the rating at RoomsVisited.
48170 LD A,(23483) Fetch the number of charms collected from Charms.
48173 SLA A Double it.
48175 ADD A,E Add the number of rooms visited.
48176 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 42010 (about 0.64 percent).
48177 LD BC,42010 Set BC to the percentage that each point is worth.
48180 LD HL,0 Clear the fraction of the percentage.
48183 XOR A Clear the whole percentage.
PrintPercentageComplete_AddPoint 48184 ADD HL,BC Add the percentage for a point to the fraction.
48185 ADC A,0 Carry into the whole percentage.
48187 DAA Keep the whole percentage as a BCD number.
48188 DEC E Decrease the number of points left.
48189 JR NZ,PrintPercentageComplete_AddPoint Jump to PrintPercentageComplete_AddPoint until every point has been added.
48191 LD BC,40 Set BC to the amount that makes up for the rounding. The 24-bit total for all of the points is 25599 in the high word and 216 in the low byte, and this takes it up to 25600 in the high word.
48194 ADD HL,BC Add it to the fraction.
48195 ADC A,0 Carry into the whole percentage.
48197 DAA Keep the whole percentage as a BCD number.
48198 LD (23498),A Store the lowest two digits of the percentage.
48201 LD A,0 Clear A without changing the carry flag.
48203 ADC A,0 Carry into the hundreds digit.
48205 DAA Keep the hundreds digit as a BCD number.
48206 LD (23497),A Store the hundreds digit at PercentComplete.
Print the digits.
48209 LD HL,58598 Point HL at ScreenBuffer_ResultsPercentage.
48212 LD DE,23497 Point DE at PercentComplete.
48215 LD B,1 Set the number of bytes to print to 1.
48217 LD A,(DE) Fetch the hundreds digit.
48218 AND A Test whether it is zero.
48219 JR Z,PrintPercentageComplete_TwoDigits Jump to PrintPercentageComplete_TwoDigits if the quest is not complete.
48221 INC B Set the number of bytes to print to 2.
48222 JP PrintBCDNumber_SecondDigit Jump to PrintBCDNumber_SecondDigit to print the hundreds digit and then the rest.
PrintPercentageComplete_TwoDigits 48225 INC HL Move the position past the space for the hundreds digit.
48226 INC DE Move on to the lowest two digits.
48227 JP PrintBCDNumber Jump to PrintBCDNumber to print them.
Prev: 48071 Up: Map Next: 48230