Prev: 57625 Up: Map Next: 57949
57721: Controls
Output
A Byte representing the intended action
First off, check if the active monster is computer controlled.
Controls 57721 LD A,(53842) Jump to PlayerControlled if *Active_MonsterControlType is not set to "computer controlled".
57724 AND A
57725 JR NZ,PlayerControlled
Handles the monster being computer controlled.
ComputerControlled 57727 CALL RandomNumber Write a random number between 0-31 (00000000-00011111 e.g. Up/ Down/ Left/ Right/ Action) to *Active_MonsterControl.
57730 AND %00011111
57732 LD (53783),A
Check if the currently active monster is jumping.
57735 LD A,(53832) A=*Flag_MonsterJumping.
57738 RRCA Rotate A right one position, setting the carry flag if bit 0 was set.
57739 JR NC,Controls_IsMonsterClimbing Jump to Controls_IsMonsterClimbing if the monster isn't currently jumping.
The active monster is jumping...
57741 LD A,8 Write 00001000 to *Active_MonsterControl.
57743 LD (53783),A
57746 RET Return.
Check if the currently active monster is climbing.
Controls_IsMonsterClimbing 57747 LD A,(53830) A=*Flag_MonsterClimbing.
57750 RRCA Rotate A right one position, setting the carry flag if bit 0 was set.
57751 JR NC,Controls_CheckBoundaries Jump to Controls_CheckBoundaries if the monster isn't currently climbing.
The active monster is climbing...
57753 LD A,(53783) Jump to ComputerControlled if *Active_MonsterControl is equal to 16 (00010000 e.g. "jumping/ punching").
57756 CP 16
57758 JR Z,ComputerControlled
57760 RET Return.
Checks the screen boundaries to ensure the monster can't go off-screen.
Controls_CheckBoundaries 57761 LD A,(53838) A=*Active_MonsterYPosition.
57764 CP 17 Compare A with 17...
57766 LD A,(53783) A=*Active_MonsterControl.
57769 RET C Return if A was is lower than 17 on line 57764.
57770 CP 16 Jump to ComputerControlled if A is equal to 16.
57772 JR Z,ComputerControlled
57774 LD A,(53837) A=*Active_MonsterXPosition.
57777 CP 250 Jump to ComputerUnset_Left if A is higher than 250.
57779 JR NC,ComputerUnset_Left
57781 CP 3 Jump to ComputerUnset_Left if A is lower than 3.
57783 JR C,ComputerUnset_Left
57785 CP 27 Compare A with 27...
57787 LD A,(53783) A=*Active_MonsterControl.
57790 RET C Return if A was lower 27 on line 57785.
Unsets the computer controlled monster "right" option.
57791 RES 1,A Reset bit 1 of A.
57793 JR ComputerUnset_JumpPunch Jump to ComputerUnset_JumpPunch.
Unsets the computer controlled monster "left" option.
ComputerUnset_Left 57795 LD A,(53783) A=*Active_MonsterControl.
57798 RES 0,A Reset bit 0 of A.
Unsets the computer controlled monster "jump/punch" option.
ComputerUnset_JumpPunch 57800 RES 4,A Reset bit 4 of A.
57802 LD (53783),A Write A to *Active_MonsterControl.
57805 RET Return.
The active monster is player controlled so using Active_MonsterControlType fetch the controller routine.
PlayerControlled 57806 ADD A,A Create an offset in HL using A*2.
57807 LD H,0
57809 LD L,A
57810 LD DE,57935 HL+=JumpTable_Controls.
57813 ADD HL,DE
Load the controls address into HL and jump to it.
57814 LD A,(HL) Load the low byte of the controls address from the jump table.
57815 INC HL Increment the controls jump table pointer by one.
57816 LD H,(HL) Set the high byte of the controls address from the jump table.
57817 LD L,A Set low byte of the controls address from A.
57818 JP (HL) Jump to the address held by *HL.
Given the "not zero" check at Controls the 0 option (57935) should never be chosen to end up here.
Controls_ComputerControlled 57819 XOR A A=0.
57820 JP Controls_Return Jump to Controls_Return.
Read the controls from the Sinclair Interface 2 joystick (port 2).
Controls_ReadSinclair2_P2 57823 LD A,247 Read from the keyboard;
Port Number Bit
0 1 2 3 4
247 1 2 3 4 5
57825 IN A,(254)
57827 XOR %10111111 Flip bits 0-5 and 7.
57829 AND %00011111 Keep only bits 0-4.
57831 JP Controls_Return Jump to Controls_Return.
Read the controls from the Sinclair Interface 2 joystick (port 1).
Controls_ReadSinclair2_P1 57834 LD A,239 Read from the keyboard;
Port Number Bit
0 1 2 3 4
239 0 9 8 7 6
57836 IN A,(254)
Converts the input into a table address beginning at PortMappings.
57838 LD B,198 Create an offset using BC - where B=198 and C=A.
57840 LD C,A
57841 LD A,(BC) A=*BC.
57842 RRCA Rotate A right three positions (bits 3 to 7 are now in positions 0 to 4).
57843 RRCA
57844 RRCA
57845 XOR %10111111 Flip bits 0-5 and 7.
57847 AND %00011111 Keep only bits 0-4.
57849 JP Controls_Return Jump to Controls_Return.
Read the controls from the Kempston joystick port.
Controls_ReadKempston 57852 IN A,(31) Read Kempston Joystick input.
57854 AND %00011111 Keep only bits 0-4.
57856 JP Z,Controls_Return Jump to Controls_Return if the result is zero.
57859 LD B,A B=A.
57860 AND %00000011 Keep only bits 0-1.
57862 LD A,B A=B.
57863 JP Z,Controls_0 Jump to Controls_0 if A is zero.
57866 XOR %00000011 Flip bits 0-1.
Controls_0 57868 OR A Set the bits from A.
57869 JP Controls_Return Jump to Controls_Return.
Use user-defined keys set 1.
Controls_Set1 57872 LD HL,51280 HL=UserDefinedKeys_Set1.
57875 JR Controller_ReadKeyboard Jump to Controller_ReadKeyboard.
Use user-defined keys set 2.
Controls_Set2 57877 LD HL,51290 HL=UserDefinedKeys_Set2.
57880 JR Controller_ReadKeyboard Jump to Controller_ReadKeyboard.
Use user-defined keys set 3.
Controls_Set3 57882 LD HL,51300 HL=UserDefinedKeys_Set3.
Read the keyboard set in HL.
Controller_ReadKeyboard 57885 LD C,0 C=0.
Has "left" been pressed?
57887 CALL Controls_ReadKeyboard Call Controls_ReadKeyboard.
57890 JR NZ,Controls_ReadKeyboardRight Jump to Controls_ReadKeyboardRight if "left" is not being pressed.
57892 SET 0,C Set bit 0 of C if "left" is being pressed.
Has "right" been pressed?
Controls_ReadKeyboardRight 57894 CALL Controls_ReadKeyboard Call Controls_ReadKeyboard.
57897 JR NZ,Controls_ReadKeyboardUp Jump to Controls_ReadKeyboardUp if "right" is not being pressed.
57899 SET 1,C Set bit 1 of C if "right" is being pressed.
Has "up" been pressed?
Controls_ReadKeyboardUp 57901 CALL Controls_ReadKeyboard Call Controls_ReadKeyboard.
57904 JR NZ,Controls_ReadKeyboardDown Jump to Controls_ReadKeyboardDown if "up" is not being pressed.
57906 SET 3,C Set bit 3 of C if "up" is being pressed.
Has "down" been pressed?
Controls_ReadKeyboardDown 57908 CALL Controls_ReadKeyboard Call Controls_ReadKeyboard.
57911 JR NZ,Controls_ReadKeyboardJumpPunch Jump to Controls_ReadKeyboardJumpPunch if "down" is not being pressed.
57913 SET 2,C Set bit 2 of C if "down" is being pressed.
Has "jump/punch" been pressed?
Controls_ReadKeyboardJumpPunch 57915 CALL Controls_ReadKeyboard Call Controls_ReadKeyboard.
57918 JR NZ,Controls_ReadKeyboardSet Jump to Controls_ReadKeyboardSet if "jump/punch" is not being pressed.
57920 SET 4,C Set bit 4 of C if "jump/punch" is being pressed.
Controls_ReadKeyboardSet 57922 LD A,C A=C.
Set the "zero" flag if no controls are being pressed.
Controls_Return 57923 AND A Set flags.
57924 LD (53783),A Write A to *Active_MonsterControl.
57927 RET Return.
Using the keyboard set in HL, read the control from the keyboard.
Controls_ReadKeyboard 57928 LD A,(HL) A=*HL.
57929 IN A,(254) Read from the entire keyboard.
57931 INC HL Increment HL by one.
57932 AND (HL) Merge the bits from *HL.
57933 INC HL Increment HL by one.
57934 RET Return.
The monster control type jump table. See Active_MonsterControlType.
JumpTable_Controls 57935 DEFW Controls_ComputerControlled Control type ID: 0.
57937 DEFW Controls_ReadSinclair2_P2 Control type ID: 1.
57939 DEFW Controls_ReadSinclair2_P1 Control type ID: 2.
57941 DEFW Controls_ReadKempston Control type ID: 3.
57943 DEFW Controls_Set1 Control type ID: 4.
57945 DEFW Controls_Set2 Control type ID: 5.
57947 DEFW Controls_Set3 Control type ID: 6.
Prev: 57625 Up: Map Next: 57949