![]() |
Routines |
| Prev: 52064 | Up: Map | Next: 52243 |
|
Used by the routine at HandleSheriff.
Turns the sheriff to face the way the controls say. Bits 6 and 7 are the heading, and bits 0 to 2 count down a turn. Left and right turn him a quarter when the controls are the keyboard or bit 3 of Options is clear. Otherwise he turns a quarter at a time towards the direction that is pressed, and bit 2 is set when he faces it.
|
||||||||||||||
|
Jump to SetFacingFlags while a turn is still counting.
|
||||||||||||||
| TurnSheriff | 52102 | LD A,(IX+6) | Fetch the heading and the time left in a turn. | |||||||||||
| 52105 | AND %00000111 | Keep the time left in a turn. | ||||||||||||
| 52107 | JR Z,TurnSheriff_Choose | Jump to TurnSheriff_Choose if the sheriff is not turning. | ||||||||||||
| 52109 | DEC (IX+6) | Count down the time. | ||||||||||||
| 52112 | JP SetFacingFlags | Jump to SetFacingFlags. | ||||||||||||
|
Use the keyboard unless a joystick is set to give a direction.
|
||||||||||||||
| TurnSheriff_Choose | 52115 | LD HL,41500 | Point HL at Options. | |||||||||||
| 52118 | LD A,(HL) | Fetch Options. | ||||||||||||
| 52119 | AND %00000110 | Keep the bits for the controls. | ||||||||||||
| 52121 | JR Z,TurnSheriff_Keyboard | Jump to TurnSheriff_Keyboard if the controls are the keyboard. | ||||||||||||
| 52123 | BIT 3,(HL) | Jump to TurnSheriff_Keyboard if bit 3 of Options is not set. | ||||||||||||
| 52125 | JR Z,TurnSheriff_Keyboard | |||||||||||||
| 52127 | LD A,(41576) | Fetch ViewRotation. | ||||||||||||
| 52130 | AND %00000001 | Keep the lowest bit. | ||||||||||||
| 52132 | CALL NZ,SwapControls | Call SwapControls if the view is rotated. | ||||||||||||
|
Turn towards the direction that is pressed.
|
||||||||||||||
| 52135 | BIT 0,E | Jump to TurnSheriff_Right if left is pressed. | ||||||||||||
| 52137 | JR NZ,TurnSheriff_Right | |||||||||||||
| 52139 | BIT 2,E | Jump to TurnSheriff_Up if up is pressed. | ||||||||||||
| 52141 | JR NZ,TurnSheriff_Up | |||||||||||||
|
The controls are not for up.
|
||||||||||||||
| TurnSheriff_Right | 52143 | BIT 1,E | Jump to TurnSheriff_ToRight if right is pressed. | |||||||||||
| 52145 | JR NZ,TurnSheriff_ToRight | |||||||||||||
| 52147 | BIT 4,E | Jump to TurnSheriff_ToDown if down is pressed. | ||||||||||||
| 52149 | JR NZ,TurnSheriff_ToDown | |||||||||||||
| 52151 | BIT 0,E | Jump to TurnSheriff_ToLeft if left is pressed. | ||||||||||||
| 52153 | JR NZ,TurnSheriff_ToLeft | |||||||||||||
| 52155 | RES 2,E | Clear bit 2 of the controls. | ||||||||||||
| 52157 | JR TurnSheriff_Keyboard | Jump to TurnSheriff_Keyboard. | ||||||||||||
|
The controls are for up.
|
||||||||||||||
| TurnSheriff_Up | 52159 | LD A,(IX+6) | Fetch the heading. | |||||||||||
|
How far is the heading from the direction that is wanted?
|
||||||||||||||
| TurnSheriff_Difference | 52162 | AND %11000000 | Keep only the heading. | |||||||||||
| 52164 | RES 2,E | Clear bit 2 of the controls. | ||||||||||||
| 52166 | JR Z,TurnSheriff_Facing | Jump to TurnSheriff_Facing if he already faces that way. | ||||||||||||
| 52168 | CP 64 | Jump to TurnSheriff_Back if he is a quarter turn away. | ||||||||||||
| 52170 | JR Z,TurnSheriff_Back | |||||||||||||
| 52172 | CP 192 | Jump to TurnSheriff_Forward if he is three quarter turns away. | ||||||||||||
| 52174 | JR Z,TurnSheriff_Forward | |||||||||||||
| 52176 | LD A,(41496) | Fetch FirstRandomNumber. | ||||||||||||
| 52179 | CP 128 | Jump to TurnSheriff_Forward if it is less than 128. | ||||||||||||
| 52181 | JR C,TurnSheriff_Forward | |||||||||||||
|
Turn back a quarter.
|
||||||||||||||
| TurnSheriff_Back | 52183 | LD A,(IX+6) | Fetch the heading. | |||||||||||
| 52186 | SUB 64 | Take a quarter turn off it. | ||||||||||||
| 52188 | JR TurnSheriff_Start | Jump to TurnSheriff_Start. | ||||||||||||
|
Turn on a quarter.
|
||||||||||||||
| TurnSheriff_Forward | 52190 | LD A,(IX+6) | Fetch the heading. | |||||||||||
| 52193 | ADD A,64 | Add a quarter turn to it. | ||||||||||||
| 52195 | JR TurnSheriff_Start | Jump to TurnSheriff_Start. | ||||||||||||
|
The controls are for right.
|
||||||||||||||
| TurnSheriff_ToRight | 52197 | LD A,(IX+6) | Fetch the heading. | |||||||||||
| 52200 | SUB 64 | Take a quarter turn off it. | ||||||||||||
| 52202 | JR TurnSheriff_Difference | Jump to TurnSheriff_Difference. | ||||||||||||
|
The controls are for down.
|
||||||||||||||
| TurnSheriff_ToDown | 52204 | LD A,(IX+6) | Fetch the heading. | |||||||||||
| 52207 | SUB 128 | Take two quarter turns off it. | ||||||||||||
| 52209 | JR TurnSheriff_Difference | Jump to TurnSheriff_Difference. | ||||||||||||
|
The controls are for left.
|
||||||||||||||
| TurnSheriff_ToLeft | 52211 | LD A,(IX+6) | Fetch the heading. | |||||||||||
| 52214 | SUB 192 | Take three quarter turns off it. | ||||||||||||
| 52216 | JR TurnSheriff_Difference | Jump to TurnSheriff_Difference. | ||||||||||||
|
The sheriff faces the way he was asked to.
|
||||||||||||||
| TurnSheriff_Facing | 52218 | SET 2,E | Set bit 2 of the controls and return. | |||||||||||
| 52220 | RET | |||||||||||||
|
Left and right turn the sheriff a quarter.
|
||||||||||||||
| TurnSheriff_Keyboard | 52221 | LD A,(IX+6) | Fetch the heading. | |||||||||||
| 52224 | BIT 0,E | Jump to TurnSheriff_KeyboardRight if left is not pressed. | ||||||||||||
| 52226 | JR Z,TurnSheriff_KeyboardRight | |||||||||||||
| 52228 | SUB 64 | Take a quarter turn off the heading. | ||||||||||||
| 52230 | OR %00000001 | Start a turn. | ||||||||||||
|
Right turns him the other way.
|
||||||||||||||
| TurnSheriff_KeyboardRight | 52232 | BIT 1,E | Jump to TurnSheriff_Store if right is not pressed. | |||||||||||
| 52234 | JR Z,TurnSheriff_Store | |||||||||||||
| 52236 | ADD A,64 | Add a quarter turn to the heading. | ||||||||||||
|
Start a turn and store the heading.
|
||||||||||||||
| TurnSheriff_Start | 52238 | OR %00000001 | Start a turn. | |||||||||||
| TurnSheriff_Store | 52240 | LD (IX+6),A | Set the heading. | |||||||||||
|
Continue on to SetFacingFlags.
View the equivalent code in;
|
||||||||||||||
| Prev: 52064 | Up: Map | Next: 52243 |