Prev: 96AF Up: Map Next: 96EC
96C9: Calculate Rooms Visited
Used by the routine at GameStats.
Works out the percentage of the rooms that have been visited, from the bits that are set in the table at VisitedRooms, and writes it to VisitedPercentage as BCD. Every third room that has been visited adds 02 to the percentage, and then 01 is added at the end.
CalculateRoomsVisited 96C9 LD HL,$5E40 Point HL at the table of visited rooms at VisitedRooms.
96CC LD BC,$0813 B=08 (the number of bits in each byte) and C=13 (the number of bytes).
96CF LD D,$03 D=03 (the number of rooms that are left before the next increase).
96D1 XOR A A=00 (the percentage so far).
CalculateRoomsVisited_Byte 96D2 PUSH BC Stash the counters on the stack.
96D3 LD E,(HL) Fetch the next byte of the table.
96D4 INC HL Move on to the next byte.
CalculateRoomsVisited_Bit 96D5 RR E Rotate the next bit into the carry flag.
96D7 JR NC,CalculateRoomsVisited_Next Jump to CalculateRoomsVisited_Next if the room has not been visited.
96D9 DEC D Jump to CalculateRoomsVisited_Next if there are more rooms before the next increase.
96DA JR NZ,CalculateRoomsVisited_Next
96DC LD D,$03 D=03.
96DE ADD A,$02 Add 02 to the percentage.
96E0 DAA Convert the result to BCD.
CalculateRoomsVisited_Next 96E1 DJNZ CalculateRoomsVisited_Bit Decrease the bit counter by one and loop back to CalculateRoomsVisited_Bit until the byte is done.
96E3 POP BC Restore the counters from the stack.
96E4 DEC C Decrease the byte counter by one and loop back to CalculateRoomsVisited_Byte until all of the bytes are done.
96E5 JR NZ,CalculateRoomsVisited_Byte
96E7 INC A Add one to the percentage.
96E8 LD ($5E54),A Write the percentage to VisitedPercentage.
96EB RET Return.
View the equivalent code in;
Prev: 96AF Up: Map Next: 96EC