Prev: 44080 Up: Map Next: 44340
44132: Use Action Key
Handles the action key, which picks up a program from the cell that is in front of the robot, drops a program into it, or installs a program in a socket (a cell of type 15). It only works when the robot is at the start of a cell, and the key has to be released between presses. The programs that the robot carries are kept in a queue, which is handled by QueueProgram.
The first part of the code works out the position of the cell in front of the robot. These entry points are used when the robot is heading up, right and left.
UseActionKey_Up 44132 LD A,H Move up one cell, keeping the Y cell within the map.
44133 INC A
44134 AND 63
44136 LD H,A
44137 JR UseActionKey_Cell Jump to use the cell.
UseActionKey_Right 44139 LD A,D Move right one cell, keeping the X cell within the map.
44140 INC A
44141 AND 63
44143 LD D,A
44144 JR UseActionKey_Cell Jump to use the cell.
UseActionKey_Left 44146 LD A,D Move left one cell, keeping the X cell within the map.
44147 DEC A
44148 AND 63
44150 LD D,A
44151 JR UseActionKey_Cell Jump to use the cell.
UseActionKey_Release 44153 XOR A Clear the flag that says that the action key has been used.
44154 LD (38482),A
44157 RET Return.
This entry point is used by the routine at MoveRobotHorizontally.
This is the entry point of the routine.
UseActionKey 44158 CALL GetPosition Fetch the position of the robot.
44161 LD A,L Return if the robot is not at the start of a cell.
44162 OR E
44163 RET NZ
44164 LD A,(38437) Jump to clear the flag if the action key is not being pressed.
44167 AND 64
44169 JR Z,UseActionKey_Release
44171 LD A,(38482) Return if the action key has been used already.
44174 AND A
44175 RET NZ
44176 LD A,1 Set the flag that says that the action key has been used.
44178 LD (38482),A
44181 EXX Start effect 0 (four tones) for PlaySoundStep.
44182 LD HL,4
44185 LD (38536),HL
44188 EXX
44189 LD A,(IX+0) Fetch the type of the robot...
44192 RRA ...and turn it into the direction that it is heading in.
44193 RRA
44194 AND 3 Jump if the robot is heading in direction zero (X decreasing).
44196 JR Z,UseActionKey_Left
44198 DEC A Jump if the robot is heading in direction one (Y increasing).
44199 JR Z,UseActionKey_Up
44201 DEC A Jump if the robot is heading in direction two (X increasing).
44202 JR Z,UseActionKey_Right
44204 LD A,H Otherwise move down one cell, keeping the Y cell within the map.
44205 DEC A
44206 AND 63
44208 LD H,A
UseActionKey_Cell 44209 LD (44479),DE Keep the X position of the cell...
44213 LD (44481),HL ...and the Y position.
44216 CALL FindMapCell Find the cell using FindMapCell.
44219 LD HL,(38446) Fetch the address of the cell.
44222 JR Z,UseActionKey_Queue Jump if the cell is empty.
44224 LD A,(HL) Fetch the contents of the cell...
44225 AND 15 ...and keep the type.
44227 CP 6 Jump if the cell is a program (type 6).
44229 JR Z,UseActionKey_Queue
44231 CP 15 Return if the cell is not a socket (type 15).
44233 RET NZ
44234 XOR A Use zero, as there is no program to pick up.
UseActionKey_Queue 44235 CALL QueueProgram Add the program, or zero, to the queue using QueueProgram.
44238 AND A Jump if a program was pushed out of the queue.
44239 JR NZ,UseActionKey_Drop
44241 LD A,(HL) Fetch the contents of the cell...
44242 LD C,A ...and keep them.
44243 AND 15 Keep the type.
44245 CP 15 Return if the cell is a socket.
44247 RET Z
44248 LD A,C Fetch the contents of the cell...
44249 AND 240 ...clear the type, so that the program has gone...
44251 LD (HL),A ...and store it.
44252 RET Return.
UseActionKey_Drop 44253 LD A,(HL) Fetch the contents of the cell.
44254 AND 15 Keep the type.
44256 CP 15 Test whether it is a socket.
44258 LD A,6 Use type 6, so that the program is dropped on the floor...
44260 JR NZ,UseActionKey_Store ...unless the cell is a socket.
44262 PUSH HL Save the address of the cell.
44263 CALL FindSector Find the sector that the robot is in using FindSector.
44266 LD E,D Put the sector number in E...
44267 LD D,0 ...and clear D.
44269 LD HL,41825 Point HL at SectorEnergy.
44272 ADD HL,DE Add the sector number.
44273 LD A,(HL) Fetch the energy of the sector.
44274 AND A Jump if there is none.
44275 JR Z,UseActionKey_Refuse
44277 LD HL,38491 Point HL at SectorFlags.
44280 ADD HL,DE Add the sector number.
44281 LD A,(HL) Fetch the flag of the sector.
44282 AND A Jump to install the program if the sector has not been activated.
44283 JR Z,UseActionKey_Install
UseActionKey_Refuse 44285 POP HL Restore the address of the cell.
44286 LD IY,39088 Point IY at the first of the two entities that are used for clouds.
44290 LD DE,16 Each entity is 16 bytes long.
44293 LD A,(IY+0) Fetch the type of the entity.
44296 AND A Jump if it is not in use.
44297 JR Z,UseActionKey_Up_StartSmoke
44299 ADD IY,DE Move on to the second entity.
44301 LD A,(IY+0) Fetch the type of the entity.
44304 AND A Return if it is in use as well.
44305 RET NZ
UseActionKey_Up_StartSmoke 44306 LD (IY+0),84 Start a cloud of smoke in the entity (type 84).
44310 LD A,(44480) Fetch the X cell where the program was refused...
44313 LD (IY+2),A ...and use it for the cloud.
44316 LD A,(44482) Fetch the Y cell...
44319 LD (IY+4),A ...and use it for the cloud.
44322 RET Return.
UseActionKey_Install 44323 POP HL Restore the address of the cell...
44324 PUSH HL ...and save it again.
44325 PUSH DE Save the sector number.
44326 CALL InstallProgram Add the program to the sector using InstallProgram.
44329 POP DE Restore the sector number...
44330 POP HL ...and the address of the cell.
44331 LD A,2 Use type 2, which is an installed program.
UseActionKey_Store 44333 LD C,A Keep the new type of the cell.
44334 LD A,(HL) Fetch the contents of the cell...
44335 AND 240 ...keep the initial type...
44337 OR C ...and combine it with the new type.
44338 LD (HL),A Store the contents of the cell.
44339 RET Return.
Prev: 44080 Up: Map Next: 44340