Prev: AC21 Up: Map Next: AD13
AC6B: Count Statistics
Used by the routine at GameOver.
Goes through the data for all of the rooms and counts those whose first object is a cryonaut. If the room holds a placed valve (objects 64 to 67) it is counted in ChambersFoundActivated; otherwise it is counted in ChambersNotActivated and its cryonauts are added to CryonautsLost. All of the totals are BCD. They are shown when the game is over.
Clear the totals and start at the first room.
CountStatistics AC6B LD DE,$5B3C Point DE at CryonautsLost.
AC6E LD B,$04 Set a counter of four.
AC70 CALL ClearBytes Call ClearBytes.
AC73 LD HL,$6469 Point HL at RoomData.
CountStatistics_NextRoom AC76 LD C,(HL) Fetch the room number.
AC77 INC HL Move on to the length.
AC78 LD B,(HL) Fetch the length.
Look for the FF that ends the blocks.
CountStatistics_ScanBlocks AC79 LD A,(HL) Fetch a byte of the data.
AC7A INC HL Move on.
AC7B INC A Add one so that FF becomes zero.
AC7C JR Z,CountStatistics_FirstObject Jump to CountStatistics_FirstObject if it was the end of the list.
AC7E DJNZ CountStatistics_ScanBlocks Jump to CountStatistics_ScanBlocks until the length runs out.
CountStatistics_SkipRoom AC80 LD BC,$73C8 Point BC at ObjectTypes.
AC83 AND A Subtract ObjectTypes from HL.
AC84 SBC HL,BC
AC86 RET NC Return if all of the rooms have been done.
AC87 ADD HL,BC Restore the address.
AC88 JR CountStatistics_NextRoom Jump to CountStatistics_NextRoom.
The objects of the room follow. Only the first is looked at.
CountStatistics_FirstObject AC8A DEC B Count the end of the list of blocks.
AC8B LD A,(HL) Fetch the type of the first object.
AC8C AND %11111000 Keep bits 3 to 7.
AC8E CP $A8 Jump to CountStatistics_FindPlacedValve if it is a cryonaut facing east.
AC90 JR Z,CountStatistics_FindPlacedValve
AC92 CP $B0 Jump to CountStatistics_FindPlacedValve if it is a cryonaut facing south.
AC94 JR Z,CountStatistics_FindPlacedValve
CountStatistics_NextRoomFromHere AC96 LD A,B Fetch the remaining length.
AC97 CALL AddAToHL Call AddAToHL.
AC9A JR CountStatistics_SkipRoom Jump to CountStatistics_SkipRoom.
Search SpecialObjects for a valve placed in this room.
CountStatistics_FindPlacedValve AC9C LD IY,$76E3 Point IY at SpecialObjects.
CountStatistics_TestSpecialObject ACA0 LD A,(IY+$08) Fetch the room of the special object.
ACA3 CP C Jump to CountStatistics_TestPlacedValve if it is this room.
ACA4 JR Z,CountStatistics_TestPlacedValve
CountStatistics_NextSpecialObject ACA6 LD DE,$0009 Set DE to 0009.
ACA9 ADD IY,DE Move on to the next special object.
ACAB PUSH HL Stash the room pointer on the stack.
ACAC PUSH IY Copy IY to HL (using the stack).
ACAE POP HL
ACAF LD DE,$7827 Point DE at SpritePointers.
ACB2 AND A Subtract SpritePointers from HL.
ACB3 SBC HL,DE
ACB5 PUSH HL Copy the result to IY (using the stack).
ACB6 POP IY
ACB8 POP HL Restore the room pointer from the stack.
ACB9 JR NC,CountStatistics_CountCryonauts Jump to CountStatistics_CountCryonauts if the table has been searched.
ACBB LD DE,$7827 Point DE at SpritePointers.
ACBE ADD IY,DE Add it back to IY.
ACC0 JR CountStatistics_TestSpecialObject Jump to CountStatistics_TestSpecialObject.
CountStatistics_TestPlacedValve ACC2 LD A,(IY+$00) Fetch the special object number.
ACC5 SUB $64 Subtract 64.
ACC7 CP $04 Jump to CountStatistics_NextSpecialObject unless it is one of the four placed valves.
ACC9 JR NC,CountStatistics_NextSpecialObject
ACCB LD A,($5B3E) Add one to ChambersFoundActivated.
ACCE ADD A,$01
ACD0 DAA
ACD1 LD ($5B3E),A
ACD4 JR CountStatistics_NextRoomFromHere Jump to CountStatistics_NextRoomFromHere.
There is no valve in the room, so its cryonauts are lost.
CountStatistics_CountCryonauts ACD6 LD DE,$5B3D Point HL at CryonautsLost_LowerDigits and DE at the object.
ACD9 EX DE,HL
ACDA LD A,(DE) Fetch the type and number of places.
ACDB AND %00000111 Keep bits 0 to 2.
ACDD INC A Add one.
ACDE ADD A,(HL) Add it to the low two digits.
ACDF DAA
ACE0 LD (HL),A
ACE1 DEC HL Fetch the high two digits.
ACE2 LD A,(HL)
ACE3 ADC A,$00 Add the carry to them.
ACE5 DAA
ACE6 LD (HL),A
ACE7 EX DE,HL Put the object pointer back in HL.
ACE8 LD A,(HL) Fetch the type and number of places.
ACE9 AND %00000111 Keep bits 0 to 2.
ACEB ADD A,$02 Add 02.
ACED LD E,A Keep the length in E.
ACEE CALL AddAToHL Call AddAToHL.
ACF1 LD A,E Fetch the length.
ACF2 NEG Make it negative.
ACF4 ADD A,B Subtract it from the bytes left.
ACF5 LD B,A
ACF6 JR Z,CountStatistics_CountChamberNotActivated Jump to CountStatistics_CountChamberNotActivated if nothing is left.
ACF8 LD A,(HL) Fetch the type of the next object.
ACF9 AND %11111000 Keep bits 3 to 7.
ACFB CP $A8 Jump to CountStatistics_CountCryonauts if it is another cryonaut facing east.
ACFD JR Z,CountStatistics_CountCryonauts
ACFF CP $B0 Jump to CountStatistics_CountCryonauts if it is another cryonaut facing south.
AD01 JR Z,CountStatistics_CountCryonauts
AD03 LD A,B Skip the rest of the room.
AD04 CALL AddAToHL
CountStatistics_CountChamberNotActivated AD07 LD A,($5B3F) Add one to ChambersNotActivated.
AD0A ADD A,$01
AD0C DAA
AD0D LD ($5B3F),A
AD10 JP CountStatistics_SkipRoom Jump to CountStatistics_SkipRoom.
Prev: AC21 Up: Map Next: AD13