![]() |
Routines |
| Prev: 9B3E | Up: Map | Next: 9D23 |
|
Used by the routine at GameOver_1UP_Messaging.
Works out how much of the jungle the player has explored and prints the result as a percentage on the game over screen.
The number of rooms visited (the bits set in the bitmap at VisitedRooms) plus the number of amulet pieces collected (the bits set in the low four bits of 970D) is converted into a percentage of 0104 (the 0100 rooms plus the four amulet pieces). The result is held as two BCD bytes in Percentage_Hundreds (the hundreds) and PreviousGameOptions (the tens and units) before being printed.
|
||||||||
|
Count the number of rooms which have been visited.
|
||||||||
| PrintRoomsVisited | 9CC6 | LD DE,$0000 | Set the count of rooms visited and amulet pieces collected in DE to 00. | |||||
| 9CC9 | LD BC,$0820 | Set the bit counter in B to 08 and the byte counter in C to 20. | ||||||
| 9CCC | LD HL,$96BF | Point HL at the visited rooms bitmap at VisitedRooms. | ||||||
| PrintRoomsVisited_CountByte | 9CCF | PUSH BC | Stash the counters on the stack. | |||||
| 9CD0 | LD A,(HL) | Fetch the next byte of the visited rooms bitmap. | ||||||
| 9CD1 | INC HL | Move onto the next byte of the bitmap. | ||||||
| PrintRoomsVisited_CountBit | 9CD2 | RRCA | Rotate the bit for the next room into the carry flag. | |||||
| 9CD3 | JR NC,PrintRoomsVisited_NextBit | Jump to PrintRoomsVisited_NextBit if the room has not been visited. | ||||||
| 9CD5 | INC DE | Add the room to the count in DE. | ||||||
| PrintRoomsVisited_NextBit | 9CD6 | DJNZ PrintRoomsVisited_CountBit | Decrease the bit counter by one and loop back to PrintRoomsVisited_CountBit until all eight rooms in the byte have been checked. | |||||
| 9CD8 | POP BC | Restore the counters from the stack. | ||||||
| 9CD9 | DEC C | Decrease the byte counter by one and jump back to PrintRoomsVisited_CountByte until all 20 bytes of the bitmap have been counted. | ||||||
| 9CDA | JR NZ,PrintRoomsVisited_CountByte | |||||||
|
Add the number of amulet pieces which have been collected.
|
||||||||
| 9CDC | LD A,($970D) | Fetch the amulet pieces collected from 970D. | ||||||
| 9CDF | LD B,$04 | Set the amulet piece counter in B to 04. | ||||||
| PrintRoomsVisited_CountPiece | 9CE1 | RRCA | Rotate the flag for the next amulet piece into the carry flag. | |||||
| 9CE2 | JR NC,PrintRoomsVisited_NextPiece | Jump to PrintRoomsVisited_NextPiece if the amulet piece has not been collected. | ||||||
| 9CE4 | INC DE | Add the amulet piece to the count in DE. | ||||||
| PrintRoomsVisited_NextPiece | 9CE5 | DJNZ PrintRoomsVisited_CountPiece | Decrease the amulet piece counter by one and loop back to PrintRoomsVisited_CountPiece until all four pieces have been checked. | |||||
|
Multiply the count by 6276 (10000 * 64 / 0104) by repeated addition. Every time the sum in HL overflows the carry is added to A, which is kept in BCD, so A ends up holding the percentage.
|
||||||||
| 9CE7 | LD BC,$6276 | Set the multiplier in BC to 6276. | ||||||
| 9CEA | LD HL,$0000 | Clear the running total in HL. | ||||||
| 9CED | XOR A | Clear the percentage in A. | ||||||
| PrintRoomsVisited_Multiply | 9CEE | ADD HL,BC | Add the multiplier to the running total. | |||||
| 9CEF | ADC A,$00 | Add any carry to the percentage. | ||||||
| 9CF1 | DAA | Adjust the percentage to be a BCD number. | ||||||
| 9CF2 | DEC DE | Decrease the count of rooms and amulet pieces by one. | ||||||
| 9CF3 | PUSH AF | Stash the percentage so far on the stack. | ||||||
| 9CF4 | LD A,E | Jump to PrintRoomsVisited_Store if the count has run out. | ||||||
| 9CF5 | OR D | |||||||
| 9CF6 | JR Z,PrintRoomsVisited_Store | |||||||
| 9CF8 | POP AF | Restore the percentage so far from the stack. | ||||||
| 9CF9 | JR PrintRoomsVisited_Multiply | Jump back to PrintRoomsVisited_Multiply to keep adding. | ||||||
|
Round the result up and store the percentage as BCD.
|
||||||||
| PrintRoomsVisited_Store | 9CFB | POP AF | Restore the percentage from the stack. | |||||
| 9CFC | LD BC,$0028 | Set the rounding value in BC to 28. | ||||||
| 9CFF | ADD HL,BC | Add the rounding value to the running total. | ||||||
| 9D00 | ADC A,$00 | Add any carry to the percentage. | ||||||
| 9D02 | DAA | Adjust the percentage to be a BCD number. | ||||||
| 9D03 | LD ($96B7),A | Store the tens and units of the percentage in PreviousGameOptions. | ||||||
| 9D06 | LD A,$00 | Set the hundreds in A to 00. | ||||||
| 9D08 | ADC A,$00 | Add the carry flag (the percentage is 0100 if it is set). | ||||||
| 9D0A | DAA | Adjust the hundreds to be a BCD number. | ||||||
| 9D0B | LD ($96B6),A | Store the hundreds of the percentage in Percentage_Hundreds. | ||||||
|
Print the percentage, leaving out the hundreds digit if it is zero.
|
||||||||
| 9D0E | LD HL,$48F8 | Set the print position in HL to 48F8 in the screen buffer. | ||||||
| 9D11 | LD DE,$96B6 | Point DE at the percentage at Percentage_Hundreds. | ||||||
| 9D14 | LD B,$01 | Set the number of bytes to print in B to 01. | ||||||
| 9D16 | LD A,(DE) | Jump to PrintRoomsVisited_SkipHundreds if the hundreds are zero. | ||||||
| 9D17 | AND A | |||||||
| 9D18 | JR Z,PrintRoomsVisited_SkipHundreds | |||||||
| 9D1A | INC B | Print both bytes of the percentage. | ||||||
| 9D1B | JP PrintScore_LowDigit | Jump to PrintScore_LowDigit to print the low digit of the first byte and then the digits of the second byte. | ||||||
| PrintRoomsVisited_SkipHundreds | 9D1E | INC HL | Move the print position on past the unused hundreds digit. | |||||
| 9D1F | INC DE | Move onto the tens and units of the percentage. | ||||||
| 9D20 | JP PrintScore_Loop | Jump to PrintScore_Loop to print both digits of the byte. | ||||||
|
View the equivalent code in;
|
||||||||
| Prev: 9B3E | Up: Map | Next: 9D23 |