Prev: AC30 Up: Map Next: AD34
AC64: 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 0F). 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 AC64 LD A,H Move up one cell, keeping the Y cell within the map.
AC65 INC A
AC66 AND $3F
AC68 LD H,A
AC69 JR UseActionKey_Cell Jump to use the cell.
UseActionKey_Right AC6B LD A,D Move right one cell, keeping the X cell within the map.
AC6C INC A
AC6D AND $3F
AC6F LD D,A
AC70 JR UseActionKey_Cell Jump to use the cell.
UseActionKey_Left AC72 LD A,D Move left one cell, keeping the X cell within the map.
AC73 DEC A
AC74 AND $3F
AC76 LD D,A
AC77 JR UseActionKey_Cell Jump to use the cell.
UseActionKey_Release AC79 XOR A Clear the flag that says that the action key has been used.
AC7A LD ($9652),A
AC7D RET Return.
This entry point is used by the routine at MoveRobotHorizontally.
This is the entry point of the routine.
UseActionKey AC7E CALL GetPosition Fetch the position of the robot.
AC81 LD A,L Return if the robot is not at the start of a cell.
AC82 OR E
AC83 RET NZ
AC84 LD A,($9625) Jump to clear the flag if the action key is not being pressed.
AC87 AND $40
AC89 JR Z,UseActionKey_Release
AC8B LD A,($9652) Return if the action key has been used already.
AC8E AND A
AC8F RET NZ
AC90 LD A,$01 Set the flag that says that the action key has been used.
AC92 LD ($9652),A
AC95 EXX Start effect 00 (four tones) for PlaySoundStep.
AC96 LD HL,$0004
AC99 LD ($9688),HL
AC9C EXX
AC9D LD A,(IX+$00) Fetch the type of the robot...
ACA0 RRA ...and turn it into the direction that it is heading in.
ACA1 RRA
ACA2 AND $03 Jump if the robot is heading in direction zero (X decreasing).
ACA4 JR Z,UseActionKey_Left
ACA6 DEC A Jump if the robot is heading in direction one (Y increasing).
ACA7 JR Z,UseActionKey_Up
ACA9 DEC A Jump if the robot is heading in direction two (X increasing).
ACAA JR Z,UseActionKey_Right
ACAC LD A,H Otherwise move down one cell, keeping the Y cell within the map.
ACAD DEC A
ACAE AND $3F
ACB0 LD H,A
UseActionKey_Cell ACB1 LD ($ADBF),DE Keep the X position of the cell...
ACB5 LD ($ADC1),HL ...and the Y position.
ACB8 CALL FindMapCell Find the cell using FindMapCell.
ACBB LD HL,($962E) Fetch the address of the cell.
ACBE JR Z,UseActionKey_Queue Jump if the cell is empty.
ACC0 LD A,(HL) Fetch the contents of the cell...
ACC1 AND $0F ...and keep the type.
ACC3 CP $06 Jump if the cell is a program (type 06).
ACC5 JR Z,UseActionKey_Queue
ACC7 CP $0F Return if the cell is not a socket (type 0F).
ACC9 RET NZ
ACCA XOR A Use zero, as there is no program to pick up.
UseActionKey_Queue ACCB CALL QueueProgram Add the program, or zero, to the queue using QueueProgram.
ACCE AND A Jump if a program was pushed out of the queue.
ACCF JR NZ,UseActionKey_Drop
ACD1 LD A,(HL) Fetch the contents of the cell...
ACD2 LD C,A ...and keep them.
ACD3 AND $0F Keep the type.
ACD5 CP $0F Return if the cell is a socket.
ACD7 RET Z
ACD8 LD A,C Fetch the contents of the cell...
ACD9 AND $F0 ...clear the type, so that the program has gone...
ACDB LD (HL),A ...and store it.
ACDC RET Return.
UseActionKey_Drop ACDD LD A,(HL) Fetch the contents of the cell.
ACDE AND $0F Keep the type.
ACE0 CP $0F Test whether it is a socket.
ACE2 LD A,$06 Use type 06, so that the program is dropped on the floor...
ACE4 JR NZ,UseActionKey_Store ...unless the cell is a socket.
ACE6 PUSH HL Save the address of the cell.
ACE7 CALL FindSector Find the sector that the robot is in using FindSector.
ACEA LD E,D Put the sector number in E...
ACEB LD D,$00 ...and clear D.
ACED LD HL,$A361 Point HL at SectorEnergy.
ACF0 ADD HL,DE Add the sector number.
ACF1 LD A,(HL) Fetch the energy of the sector.
ACF2 AND A Jump if there is none.
ACF3 JR Z,UseActionKey_Refuse
ACF5 LD HL,$965B Point HL at SectorFlags.
ACF8 ADD HL,DE Add the sector number.
ACF9 LD A,(HL) Fetch the flag of the sector.
ACFA AND A Jump to install the program if the sector has not been activated.
ACFB JR Z,UseActionKey_Install
UseActionKey_Refuse ACFD POP HL Restore the address of the cell.
ACFE LD IY,$98B0 Point IY at the first of the two entities that are used for clouds.
AD02 LD DE,$0010 Each entity is 10 bytes long.
AD05 LD A,(IY+$00) Fetch the type of the entity.
AD08 AND A Jump if it is not in use.
AD09 JR Z,UseActionKey_Up_StartSmoke
AD0B ADD IY,DE Move on to the second entity.
AD0D LD A,(IY+$00) Fetch the type of the entity.
AD10 AND A Return if it is in use as well.
AD11 RET NZ
UseActionKey_Up_StartSmoke AD12 LD (IY+$00),$54 Start a cloud of smoke in the entity (type 54).
AD16 LD A,($ADC0) Fetch the X cell where the program was refused...
AD19 LD (IY+$02),A ...and use it for the cloud.
AD1C LD A,($ADC2) Fetch the Y cell...
AD1F LD (IY+$04),A ...and use it for the cloud.
AD22 RET Return.
UseActionKey_Install AD23 POP HL Restore the address of the cell...
AD24 PUSH HL ...and save it again.
AD25 PUSH DE Save the sector number.
AD26 CALL InstallProgram Add the program to the sector using InstallProgram.
AD29 POP DE Restore the sector number...
AD2A POP HL ...and the address of the cell.
AD2B LD A,$02 Use type 02, which is an installed program.
UseActionKey_Store AD2D LD C,A Keep the new type of the cell.
AD2E LD A,(HL) Fetch the contents of the cell...
AD2F AND $F0 ...keep the initial type...
AD31 OR C ...and combine it with the new type.
AD32 LD (HL),A Store the contents of the cell.
AD33 RET Return.
Prev: AC30 Up: Map Next: AD34