![]() |
Routines |
| Prev: 38575 | Up: Map | Next: 38636 |
|
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 2 to the percentage, and then 1 is added at the end.
|
||||
| CalculateRoomsVisited | 38601 | LD HL,24128 | Point HL at the table of visited rooms at VisitedRooms. | |
| 38604 | LD BC,2067 | B=8 (the number of bits in each byte) and C=19 (the number of bytes). | ||
| 38607 | LD D,3 | D=3 (the number of rooms that are left before the next increase). | ||
| 38609 | XOR A | A=0 (the percentage so far). | ||
| CalculateRoomsVisited_Byte | 38610 | PUSH BC | Stash the counters on the stack. | |
| 38611 | LD E,(HL) | Fetch the next byte of the table. | ||
| 38612 | INC HL | Move on to the next byte. | ||
| CalculateRoomsVisited_Bit | 38613 | RR E | Rotate the next bit into the carry flag. | |
| 38615 | JR NC,CalculateRoomsVisited_Next | Jump to CalculateRoomsVisited_Next if the room has not been visited. | ||
| 38617 | DEC D | Jump to CalculateRoomsVisited_Next if there are more rooms before the next increase. | ||
| 38618 | JR NZ,CalculateRoomsVisited_Next | |||
| 38620 | LD D,3 | D=3. | ||
| 38622 | ADD A,2 | Add 2 to the percentage. | ||
| 38624 | DAA | Convert the result to BCD. | ||
| CalculateRoomsVisited_Next | 38625 | DJNZ CalculateRoomsVisited_Bit | Decrease the bit counter by one and loop back to CalculateRoomsVisited_Bit until the byte is done. | |
| 38627 | POP BC | Restore the counters from the stack. | ||
| 38628 | DEC C | Decrease the byte counter by one and loop back to CalculateRoomsVisited_Byte until all of the bytes are done. | ||
| 38629 | JR NZ,CalculateRoomsVisited_Byte | |||
| 38631 | INC A | Add one to the percentage. | ||
| 38632 | LD (24148),A | Write the percentage to VisitedPercentage. | ||
| 38635 | RET | Return. | ||
|
View the equivalent code in;
|
||||
| Prev: 38575 | Up: Map | Next: 38636 |