Prev: 44065 Up: Map Next: 44307
44139: 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 100 to 103) 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 44139 LD DE,23356 Point DE at CryonautsLost.
44142 LD B,4 Set a counter of four.
44144 CALL ClearBytes Call ClearBytes.
44147 LD HL,25705 Point HL at RoomData.
CountStatistics_NextRoom 44150 LD C,(HL) Fetch the room number.
44151 INC HL Move on to the length.
44152 LD B,(HL) Fetch the length.
Look for the 255 that ends the blocks.
CountStatistics_ScanBlocks 44153 LD A,(HL) Fetch a byte of the data.
44154 INC HL Move on.
44155 INC A Add one so that 255 becomes zero.
44156 JR Z,CountStatistics_FirstObject Jump to CountStatistics_FirstObject if it was the end of the list.
44158 DJNZ CountStatistics_ScanBlocks Jump to CountStatistics_ScanBlocks until the length runs out.
CountStatistics_SkipRoom 44160 LD BC,29640 Point BC at ObjectTypes.
44163 AND A Subtract ObjectTypes from HL.
44164 SBC HL,BC
44166 RET NC Return if all of the rooms have been done.
44167 ADD HL,BC Restore the address.
44168 JR CountStatistics_NextRoom Jump to CountStatistics_NextRoom.
The objects of the room follow. Only the first is looked at.
CountStatistics_FirstObject 44170 DEC B Count the end of the list of blocks.
44171 LD A,(HL) Fetch the type of the first object.
44172 AND %11111000 Keep bits 3 to 7.
44174 CP 168 Jump to CountStatistics_FindPlacedValve if it is a cryonaut facing east.
44176 JR Z,CountStatistics_FindPlacedValve
44178 CP 176 Jump to CountStatistics_FindPlacedValve if it is a cryonaut facing south.
44180 JR Z,CountStatistics_FindPlacedValve
CountStatistics_NextRoomFromHere 44182 LD A,B Fetch the remaining length.
44183 CALL AddAToHL Call AddAToHL.
44186 JR CountStatistics_SkipRoom Jump to CountStatistics_SkipRoom.
Search SpecialObjects for a valve placed in this room.
CountStatistics_FindPlacedValve 44188 LD IY,30435 Point IY at SpecialObjects.
CountStatistics_TestSpecialObject 44192 LD A,(IY+8) Fetch the room of the special object.
44195 CP C Jump to CountStatistics_TestPlacedValve if it is this room.
44196 JR Z,CountStatistics_TestPlacedValve
CountStatistics_NextSpecialObject 44198 LD DE,9 Set DE to 0009.
44201 ADD IY,DE Move on to the next special object.
44203 PUSH HL Stash the room pointer on the stack.
44204 PUSH IY Copy IY to HL (using the stack).
44206 POP HL
44207 LD DE,30759 Point DE at SpritePointers.
44210 AND A Subtract SpritePointers from HL.
44211 SBC HL,DE
44213 PUSH HL Copy the result to IY (using the stack).
44214 POP IY
44216 POP HL Restore the room pointer from the stack.
44217 JR NC,CountStatistics_CountCryonauts Jump to CountStatistics_CountCryonauts if the table has been searched.
44219 LD DE,30759 Point DE at SpritePointers.
44222 ADD IY,DE Add it back to IY.
44224 JR CountStatistics_TestSpecialObject Jump to CountStatistics_TestSpecialObject.
CountStatistics_TestPlacedValve 44226 LD A,(IY+0) Fetch the special object number.
44229 SUB 100 Subtract 100.
44231 CP 4 Jump to CountStatistics_NextSpecialObject unless it is one of the four placed valves.
44233 JR NC,CountStatistics_NextSpecialObject
44235 LD A,(23358) Add one to ChambersFoundActivated.
44238 ADD A,1
44240 DAA
44241 LD (23358),A
44244 JR CountStatistics_NextRoomFromHere Jump to CountStatistics_NextRoomFromHere.
There is no valve in the room, so its cryonauts are lost.
CountStatistics_CountCryonauts 44246 LD DE,23357 Point HL at CryonautsLost_LowerDigits and DE at the object.
44249 EX DE,HL
44250 LD A,(DE) Fetch the type and number of places.
44251 AND %00000111 Keep bits 0 to 2.
44253 INC A Add one.
44254 ADD A,(HL) Add it to the low two digits.
44255 DAA
44256 LD (HL),A
44257 DEC HL Fetch the high two digits.
44258 LD A,(HL)
44259 ADC A,0 Add the carry to them.
44261 DAA
44262 LD (HL),A
44263 EX DE,HL Put the object pointer back in HL.
44264 LD A,(HL) Fetch the type and number of places.
44265 AND %00000111 Keep bits 0 to 2.
44267 ADD A,2 Add 2.
44269 LD E,A Keep the length in E.
44270 CALL AddAToHL Call AddAToHL.
44273 LD A,E Fetch the length.
44274 NEG Make it negative.
44276 ADD A,B Subtract it from the bytes left.
44277 LD B,A
44278 JR Z,CountStatistics_CountChamberNotActivated Jump to CountStatistics_CountChamberNotActivated if nothing is left.
44280 LD A,(HL) Fetch the type of the next object.
44281 AND %11111000 Keep bits 3 to 7.
44283 CP 168 Jump to CountStatistics_CountCryonauts if it is another cryonaut facing east.
44285 JR Z,CountStatistics_CountCryonauts
44287 CP 176 Jump to CountStatistics_CountCryonauts if it is another cryonaut facing south.
44289 JR Z,CountStatistics_CountCryonauts
44291 LD A,B Skip the rest of the room.
44292 CALL AddAToHL
CountStatistics_CountChamberNotActivated 44295 LD A,(23359) Add one to ChambersNotActivated.
44298 ADD A,1
44300 DAA
44301 LD (23359),A
44304 JP CountStatistics_SkipRoom Jump to CountStatistics_SkipRoom.
Prev: 44065 Up: Map Next: 44307