Prev: 96AF Up: Map Next: 96EC
96C9: Work out how much of the castle has been seen
Used by the routine at DRAW_SUMMARY.
Counts the bits set in the room map and turns the total into a two-digit BCD figure at $5E54. It is not shown while playing -- DRAW_SUMMARY prints it on the GAME OVER screen, as the last of the three figures under the heading. Every third room seen is worth 2, and 1 is added at the end, so the value is (rooms / 3) * 2 + 1.
Measured by setting the map by hand and running it: 6, 7 and 8 rooms all give $05, 11 gives $07, 144 gives $97, and none at all gives $01.
The map holds 152 bits but the castle does not have 152 rooms. ROOM_TABLE has 151 entries, and of those the last two are black -- colour $00, so nothing they draw can be seen. That leaves 149 real rooms, 0 to 148, and (149 / 3) * 2 + 1 is exactly 99. The figure is scaled so that seeing everything reads 99 and it never has to carry into a third digit, which a single byte of BCD could not hold: setting all 152 bits by hand does overflow it, and $5E54 comes back $01, but no game can get there.
It is a percentage: DRAW_SUMMARY prints it after the font's percent sign (the "$" of PERCENT_LABEL is drawn as %), so every room seen reads 99%.
COUNT_ROOMS_EXPLORED 96C9 LD HL,$5E40 19 bytes, 8 bits each.
96CC LD BC,$0813
96CF LD D,$03
96D1 XOR A
COUNT_ROOMS_EXPLORED_0 96D2 PUSH BC
96D3 LD E,(HL)
96D4 INC HL
COUNT_ROOMS_EXPLORED_1 96D5 RR E Walk the bits of one byte.
96D7 JR NC,COUNT_ROOMS_EXPLORED_2
96D9 DEC D Two per three rooms, in BCD -- hence the DAA.
96DA JR NZ,COUNT_ROOMS_EXPLORED_2
96DC LD D,$03
96DE ADD A,$02
96E0 DAA Keeps the running total in BCD so it can be printed a digit at a time.
COUNT_ROOMS_EXPLORED_2 96E1 DJNZ COUNT_ROOMS_EXPLORED_1
96E3 POP BC
96E4 DEC C
96E5 JR NZ,COUNT_ROOMS_EXPLORED_0
96E7 INC A The finished figure, read back by the status panel.
96E8 LD ($5E54),A
96EB RET
Prev: 96AF Up: Map Next: 96EC