Prev: 40711 Up: Map Next: 40993
40867: Print Completion Percentage
Used by the routine at Show_Game_Over.
Prints YOU HAVE COMPLETED, the percentage of the Underwurlde that has been explored, and OF THE UNDERWURLDE.
The percentage comes from the room visit table at Room_Visit_Table. The first byte of each of the first 576 pairs of bytes is non-zero if the room has been visited, and the number of those is the count. The count is multiplied by 32 and has 128 added, so that its high byte is the count divided by eight and rounded. The division routine at Divide then divides that by 192 after multiplying it by 256 which makes the result about one sixth of the count. The result is held as two BCD digits in Completion_Percentage.
The count and the result are also stored at 24064 24066 and 24068 which nothing reads.
With 576 entries the result can not be more than 96, so the text 100 is never printed.
Print_Completion_Percentage 40867 LD DE,40840 Point at the text YOU HAVE COMPLETED (Ending_Text_You_Have_Completed).
40870 LD HL,18488 Set the x position to 56 and the y position to 72 (18488).
40873 CALL MenuWriteText Print the text.
40876 LD DE,40864 Point at the text OF (Ending_Text_Of).
40879 LD HL,30840 Set the x position to 120 and the y position to 120 (30840).
40882 CALL MenuWriteText Print the text.
40885 LD DE,40801 Point at the text THE UNDERWURLDE (Ending_Text_The_Underwurlde).
40888 LD HL,36936 Set the x position to 72 and the y position to 144 (36936).
40891 CALL MenuWriteText Print the text.
Count the rooms that have been visited.
40894 LD HL,24576 Point at the room visit table (Room_Visit_Table).
40897 LD DE,0 Set the count to 0.
40900 LD BC,16387 BC=16387 (B is 64 and C is 3 which gives 64 passes of the loop and then 256 twice).
Count_Visited_Rooms 40903 LD A,(HL) Fetch the first byte of an entry.
40904 INC HL Move on to the second byte of the entry.
40905 INC HL Move on to the next entry.
40906 AND A Jump to Print_Completion_Percentage_Next_Room if the room has not been visited.
40907 JR Z,Print_Completion_Percentage_Next_Room
40909 INC DE Add one to the count.
Print_Completion_Percentage_Next_Room 40910 DJNZ Count_Visited_Rooms Decrease the inner room counter and loop back until it is zero.
40912 DEC C Decrease the outer room counter and loop back until every entry of the room visit table has been checked.
40913 JR NZ,Count_Visited_Rooms
Work out the percentage.
40915 LD (24064),DE Store the count (nothing reads it).
40919 LD HL,192 Set the divisor to 192.
40922 EX DE,HL Exchange the registers so that DE holds the divisor and HL the count.
40923 ADD HL,HL Multiply the count by 32.
40924 ADD HL,HL
40925 ADD HL,HL
40926 ADD HL,HL
40927 ADD HL,HL
40928 LD BC,128 Set the amount to add for rounding to 128.
40931 ADD HL,BC Add 128 to round the result.
40932 CALL Divide Divide the high byte by DE (see above).
40935 LD (24066),HL Store the result (nothing reads it).
40938 LD A,L Fetch the result.
40939 CP 100 Jump to Print_Completion_Percentage_Print_100 if the result is 100 (100) or more.
40941 JR NC,Print_Completion_Percentage_Print_100
40943 XOR A Set the percentage counter to the result and clear the BCD percentage.
40944 LD B,L
40945 INC B Add one to the loop counter, as the loop is entered at the end.
40946 JR Print_Completion_Percentage_Convert_Check Jump to Print_Completion_Percentage_Convert_Check to start the loop.
Print_Completion_Percentage_Convert_Loop 40948 ADD A,1 Add one.
40950 DAA Adjust the result to a BCD value.
Print_Completion_Percentage_Convert_Check 40951 DJNZ Print_Completion_Percentage_Convert_Loop Decrease the percentage counter and loop back until the percentage has been converted to BCD.
40953 LD (36600),A Store the percentage.
40956 LD (24068),A Store the percentage again (nothing reads it).
40959 LD HL,24688 Set the x position to 112 and the y position to 96 (24688).
40962 CALL ScreenAddress Convert the position into a screen address.
40965 LD DE,36600 Point at the percentage (Completion_Percentage).
40968 LD B,1 Set the number of digits to print to 1.
40970 CALL Print_Status_Panel_Digits Print the digits.
Print_Percent_Sign 40973 LD DE,40859 Point at the percent sign (Ending_Text_Percent_Sign).
40976 LD HL,24712 Set the x position to 136 and the y position to 96 (24712).
40979 JP MenuWriteText Jump to MenuWriteText to print the percent sign.
Print_Completion_Percentage_Print_100 40982 LD DE,40860 Point at the text 100 (Ending_Text_One_Hundred).
40985 LD HL,24680 Set the x position to 104 and the y position to 96 (24680).
40988 CALL MenuWriteText Print the text.
40991 JR Print_Percent_Sign Jump to Print_Percent_Sign to print the percent sign.
Prev: 40711 Up: Map Next: 40993