Prev: 41947 Up: Map Next: 42215
41982: Collect Bottle
Used by the routine at TestGroupObjects.
Handles the player collecting a bottle, if the flag at BottleFlag is set. The score is increased, the bottle is shown as an empty cup, and the number of bottles left is decreased. If there are none left then the exit is opened.
CollectBottle 41982 LD A,(57084) Fetch the flag from BottleFlag.
41985 AND A Test it.
41986 RET Z Return if it is not set.
41987 XOR A Clear the flag...
41988 LD (57084),A ...and store it.
41991 LD BC,512 Set the amount to add to the score.
41994 CALL AddScore Call AddScore to add it to the score.
41997 LD HL,24576 Set the value of 24576.
42000 LD (42399),HL Store it in 42399, which sets the target of the first gauge.
42003 LD HL,26632 Set the position of the picture.
42006 LD DE,25788 Point DE at EmptyCupPicture.
42009 CALL DrawPicture Call DrawPicture to draw the picture.
42012 LD A,4 Set the value 4...
42014 LD (43901),A ...in 43901.
42017 LD A,(46428) Fetch the byte of the player entity at 46428.
42020 AND %11110000 Keep the upper four bits.
42022 OR %00000100 Add the value 4.
42024 LD (46428),A Store it again.
42027 LD A,(57056) Fetch the number of bottles left from BottlesLeft.
42030 DEC A Decrease it by one.
42031 LD (57056),A Store it.
42034 JR NZ,CollectBottle_Count Jump to CollectBottle_Count if there are some left.
42036 LD (57782),A Set the units digit of the count on the panel to zero.
42039 LD C,A Set C to zero, so that the player is not placed.
42040 CALL StartLevel_FindData Call 34555 to find the data of the level.
42043 CALL ShowExitMessage Call ShowExitMessage to show that the exit is open.
42046 JR CollectBottle_Print Jump to CollectBottle_Print.
CollectBottle_Count 42048 LD B,A Copy the number of bottles left into B.
42049 XOR A Set A to zero.
CollectBottle_Convert 42050 ADD A,1 Add one.
42052 DAA Convert it to binary coded decimal.
42053 DJNZ CollectBottle_Convert Jump back until the number has been converted.
42055 LD B,A Keep the result in B.
42056 AND %00001111 Keep the units.
42058 LD (57782),A Store it as the units digit of the count on the panel.
42061 LD A,B Fetch the result.
42062 RRA Move the tens digit...
42063 RRA ...down...
42064 RRA ...to the lower...
42065 RRA ...four bits.
42066 AND %00001111 Keep the tens.
42068 LD (57781),A Store it as the tens digit of the count on the panel.
CollectBottle_Print 42071 LD DE,57777 Point DE at the text of the count on the panel.
42074 CALL PrintText Call PrintText to print it.
42077 RES 0,(IX+1) Reset bit 0 of the type of the object in IX.
42081 SET 1,(IX+1) Set bit 1 of the type of the object in IX.
42085 LD (49468),IX Store the address of the object at 49468.
42089 LD (42133),IX Store the address of the object at 42133 the operand of the instruction at 42132.
42093 LD IY,57057 Point IY at BottleStates.
42097 LD IX,(23806) Fetch the address of the level data from LevelHeaderAddress.
42101 LD B,(IX-1) Fetch the number of entries in the list of the level.
CollectBottle_NextEntry 42104 PUSH BC Save the count of entries.
42105 PUSH IX Save the address of the entry.
42107 CALL FindGroupObjects Call FindGroupObjects to find the objects in the group of the entry.
42110 LD A,B Fetch the number of objects.
42111 AND A Test it.
42112 JR Z,CollectBottle_NextGroup Jump to CollectBottle_NextGroup if there are no objects.
CollectBottle_NextObject 42114 LD A,(IX+1) Fetch the type of the next object.
42117 AND %10001111 Keep bit 7 and bits 0-3.
42119 CP 129 Jump to CollectBottle_Match if it is a bottle of type 1.
42121 JR Z,CollectBottle_Match
42123 CP 130 Jump to CollectBottle_Skip unless it is a bottle of type 2.
42125 JR NZ,CollectBottle_Skip
CollectBottle_Match 42127 INC IY Move onto the saved state of the next bottle.
42129 PUSH IX Copy the address of the object into DE (using the stack).
42131 POP DE
42132 LD HL,0 Set HL to the address of the bottle that was collected.
42135 AND A Clear the carry flag.
42136 SBC HL,DE Compare the two addresses.
42138 JR NZ,CollectBottle_Skip Jump to CollectBottle_Skip if this is not the bottle that was collected.
42140 LD (IY-1),130 Set the saved state of the bottle to 130.
42144 POP IX Discard the address of the entry.
42146 POP BC Discard the count of entries.
42147 JR CollectBottle_Finish Jump to CollectBottle_Finish.
CollectBottle_Skip 42149 INC IX Move onto the next object...
42151 INC IX ...which is three bytes...
42153 INC IX ...along.
42155 DJNZ CollectBottle_NextObject Jump back until all of the objects have been looked at.
CollectBottle_NextGroup 42157 POP IX Restore the address of the entry.
42159 INC IX Move onto the next entry...
42161 INC IX ...which is two bytes along.
42163 POP BC Restore the count of entries.
42164 DJNZ CollectBottle_NextEntry Jump back until all of the entries have been looked at.
CollectBottle_Finish 42166 LD A,1 A is 1.
42168 LD (45490),A Store it in the byte at 45490.
42171 LD (50771),A Store it in the byte at 50771.
42174 LD A,(23792) Fetch the value from DrawingFlags.
42177 AND %00000111 Use bits 0-2.
42179 LD (50781),A Store it in the byte at 50781.
42182 LD HL,32528 Set the value 32528.
42185 LD (45491),HL Store it at 45491.
42188 LD HL,32928 Set the value 32928.
42191 LD (45493),HL Store it at 45493.
42194 LD DE,50758 Point DE at DrawOverlappedBlock.
42197 LD HL,49467 Point HL at DrawChosenObject.
42200 CALL DrawLevelObjects_Start Call DrawLevelObjects_Start.
42203 LD A,8 A is 8.
42205 LD (51092),A Store it in the byte at 51092.
42208 LD (51110),A Store it in the byte at 51110.
42211 CALL PlayBuzzSweep Call PlayBuzzSweep to play a sound.
42214 RET Return.
Prev: 41947 Up: Map Next: 42215