Prev: C6CC Up: Map Next: C74A
C6EA: Work out and print the percentage of the quest done
Used by the routine at WON.
For the game-over screen (WON). Two rooms seen count one per cent, up to 54 (108 rooms or more); each quest item the bucket has reached counts 4 (QUEST_DONE, four of them: 16); each collectable in its place in room 82 counts 6 (PLACED, five: 30). 54, 16 and 30 make 100. The sum is counted up in BCD into PERCENT -- the hundreds, 0 or 1, then the tens and units -- and printed at pixel row 95, column 144 of the buffer: three digits at 100, otherwise two, with a leading zero.
The count is a DJNZ loop, so a sum of 0 runs it 256 times and prints 56: measured in the simulator, a player who loses all five lives without leaving the room he started in is told 56 per cent. One room seen counts nothing, since the rooms are halved first, and two count 1.
PERCENTAGE C6EA LD HL,ROOMS_SEEN 31 bytes of the rooms-seen map, E counting
C6ED LD C,$1F
C6EF LD E,$00
PERCENTAGE_0 C6F1 LD B,$08 Count the set bits
C6F3 LD A,(HL)
PERCENTAGE_1 C6F4 RRA
C6F5 JR NC,PERCENTAGE_2
C6F7 INC E
PERCENTAGE_2 C6F8 DJNZ PERCENTAGE_1
C6FA INC HL
C6FB DEC C
C6FC JR NZ,PERCENTAGE_0
C6FE SRL E Half the rooms seen, 54 at most
C700 LD A,E
C701 CP $36
C703 JR C,PERCENTAGE_3
C705 LD E,$36
PERCENTAGE_3 C707 LD A,(QUEST_DONE) Plus 4 for each quest item done
C70A ADD A,A
C70B ADD A,A
C70C ADD A,E
C70D LD E,A
C70E LD A,(PLACED) Plus 6 for each collectable placed
C711 ADD A,A
C712 LD D,A
C713 ADD A,A
C714 ADD A,D
C715 ADD A,E
C716 LD B,A
C717 XOR A Count it up in BCD, one at a time
PERCENTAGE_4 C718 ADD A,$01
C71A DAA
C71B DJNZ PERCENTAGE_4
C71D LD ($A74E),A Tens and units; the carry out of the last is the hundreds
C720 LD A,$00
C722 ADC A,$00
C724 LD (PERCENT),A
C727 EX AF,AF' Keep the hundreds
C728 LD BC,$5F90 The place in the buffer to print at
C72B CALL CALC_VIDBUF_ADDR
C72E LD L,C
C72F LD H,B
C730 EX AF,AF' Three digits or two
C731 LD DE,PERCENT
C734 LD B,$01
C736 AND A
C737 JR Z,PERCENTAGE_5
C739 INC B 100: the hundreds digit with the digits' font, then the other two (ADD_SCORE)
C73A PUSH HL
C73B LD HL,FONT
C73E LD (FONT_BASE),HL
C741 POP HL
C742 JP PRINT_BCD_LSD
PERCENTAGE_5 C745 INC HL Under 100: one place along, and the tens and units only
C746 INC DE
C747 JP PRINT_BCD
Prev: C6CC Up: Map Next: C74A