Prev: E119 Up: Map Next: E25D
E179: Controls
Used by the routines at Handler_Controls, Animate_Waiting, Event_Landed, EAF6 and EF50.
Output
A Byte representing the intended action
Controls E179 LD A,($D252) Jump to Controls_FetchSet if *Active_MonsterControlType is not set to "computer controlled".
E17C AND A
E17D JR NZ,Controls_FetchSet
Controls_0 E17F CALL RandomNumber Write a random number between 0-31 to *D217.
E182 AND %00011111
E184 LD ($D217),A
E187 LD A,($D248) A=*Flag_MonsterJumping.
E18A RRCA Rotate A right one position, setting the carry flag if bit 0 was set.
E18B JR NC,Controls_1 Jump to Controls_1 if the carry flag is not set.
E18D LD A,$08 Write 08 to *D217.
E18F LD ($D217),A
E192 RET Return.
Controls_1 E193 LD A,($D246) A=*Flag_MonsterClimbing.
E196 RRCA Rotate A right one position, setting the carry flag if bit 0 was set.
E197 JR NC,Controls_2 Jump to Controls_2 if the carry flag is not set.
E199 LD A,($D217) Jump to Controls_0 if *D217 is equal to 10.
E19C CP $10
E19E JR Z,Controls_0
E1A0 RET Return.
Controls_2 E1A1 LD A,($D24E) A=*Active_MonsterYPosition.
E1A4 CP $11 Compare A with 11...
E1A6 LD A,($D217) A=*D217.
E1A9 RET C Return if A was is lower than 11 on line E1A4.
E1AA CP $10 Jump to Controls_0 if A is equal to 10.
E1AC JR Z,Controls_0
E1AE LD A,($D24D) A=*Active_MonsterXPosition.
E1B1 CP $FA Jump to Controls_3 if A is higher than FA.
E1B3 JR NC,Controls_3
E1B5 CP $03 Jump to Controls_3 if A is lower than 03.
E1B7 JR C,Controls_3
E1B9 CP $1B Compare A with 1B...
E1BB LD A,($D217) A=*D217.
E1BE RET C Return if A was lower 1B on line E1B9.
E1BF RES 1,A Reset bit 1 of A.
E1C1 JR Controls_4 Jump to Controls_4.
Controls_3 E1C3 LD A,($D217) A=*D217.
E1C6 RES 0,A Reset bit 0 of A.
Controls_4 E1C8 RES 4,A Reset bit 4 of A.
E1CA LD ($D217),A Write A to *D217.
E1CD RET Return.
Controls_FetchSet E1CE ADD A,A A*=02.
E1CF LD H,$00 Create an offset using HL.
E1D1 LD L,A
E1D2 LD DE,$E24F HL+=JumpTable_Controls.
E1D5 ADD HL,DE
Load the address into HL and jump to it.
E1D6 LD A,(HL) A=*HL.
E1D7 INC HL Increment HL by one.
E1D8 LD H,(HL) H=*HL.
E1D9 LD L,A L=A.
E1DA JP (HL) Jump to the address held by *HL.
E1DB XOR A A=00.
E1DC JP Controls_12 Jump to Controls_12.
E1DF LD A,$F7 A=F7.
E1E1 IN A,($FE)
E1E3 XOR %10111111 Flip bits 0-5 and 7.
E1E5 AND %00011111 Keep only bits 0-4.
E1E7 JP Controls_12 Jump to Controls_12.
E1EA LD A,$EF A=EF.
E1EC IN A,($FE)
E1EE LD B,$C6 B=C6.
E1F0 LD C,A
E1F1 LD A,(BC) A=*BC.
E1F2 RRCA RRCA.
E1F3 RRCA
E1F4 RRCA
E1F5 XOR %10111111 Flip bits 0-5 and 7.
E1F7 AND %00011111 Keep only bits 0-4.
E1F9 JP Controls_12 Jump to Controls_12.
Controls_ReadKempston E1FC IN A,($1F) Read Kempston Joystick input.
E1FE AND %00011111 Keep only bits 0-4.
E200 JP Z,Controls_12 Jump to Controls_12 if the result is zero.
E203 LD B,A B=A.
E204 AND %00000011 Keep only bits 0-1.
E206 LD A,B A=B.
E207 JP Z,Controls_5 Jump to Controls_5 if A is zero.
E20A XOR %00000011 Flip bits 0-1.
Controls_5 E20C OR A Set the bits from A.
E20D JP Controls_12 Jump to Controls_12.
Use user-defined keys set 1.
Controls_Set1 E210 LD HL,$C850 HL=UserDefinedKeys_Set1.
E213 JR Controls_6 Jump to Controls_6.
Use user-defined keys set 2.
Controls_Set2 E215 LD HL,$C85A HL=UserDefinedKeys_Set2.
E218 JR Controls_6 Jump to Controls_6.
Use user-defined keys set 3.
Controls_Set3 E21A LD HL,$C864 HL=UserDefinedKeys_Set3.
Controls_6 E21D LD C,$00 C=00.
E21F CALL Controls_ReadKeyboard Call Controls_ReadKeyboard.
E222 JR NZ,Controls_7 Jump to Controls_7 if {} is not zero.
E224 SET 0,C Set bit 0 of C.
Controls_7 E226 CALL Controls_ReadKeyboard Call Controls_ReadKeyboard.
E229 JR NZ,Controls_8 Jump to Controls_8 if {} is not zero.
E22B SET 1,C Set bit 1 of C.
Controls_8 E22D CALL Controls_ReadKeyboard Call Controls_ReadKeyboard.
E230 JR NZ,Controls_9 Jump to Controls_9 if {} is not zero.
E232 SET 3,C Set bit 3 of C.
Controls_9 E234 CALL Controls_ReadKeyboard Call Controls_ReadKeyboard.
E237 JR NZ,Controls_10 Jump to Controls_10 if {} is not zero.
E239 SET 2,C Set bit 2 of C.
Controls_10 E23B CALL Controls_ReadKeyboard Call Controls_ReadKeyboard.
E23E JR NZ,Controls_11 Jump to Controls_11 if {} is not zero.
E240 SET 4,C Set bit 4 of C.
Controls_11 E242 LD A,C A=C.
Controls_12 E243 AND A Set flags.
E244 LD ($D217),A Write A to *D217.
E247 RET Return.
Controls_ReadKeyboard E248 LD A,(HL) A=*HL.
E249 IN A,($FE) Read from the keyboard.
E24B INC HL Increment HL by one.
E24C AND (HL) Merge the bits from *HL.
E24D INC HL Increment HL by one.
E24E RET Return.
JumpTable_Controls E24F DEFW $E1DB
E251 DEFW $E1DF
E253 DEFW $E1EA
E255 DEFW Controls_ReadKempston
E257 DEFW Controls_Set1
E259 DEFW Controls_Set2
E25B DEFW Controls_Set3
Prev: E119 Up: Map Next: E25D