![]() |
Routines |
| Prev: CB60 | Up: Map | Next: CC13 |
|
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 | CB86 | LD A,(IX+$06) | Fetch the heading and the time left in a turn. | |||||||||||
| CB89 | AND %00000111 | Keep the time left in a turn. | ||||||||||||
| CB8B | JR Z,TurnSheriff_Choose | Jump to TurnSheriff_Choose if the sheriff is not turning. | ||||||||||||
| CB8D | DEC (IX+$06) | Count down the time. | ||||||||||||
| CB90 | JP SetFacingFlags | Jump to SetFacingFlags. | ||||||||||||
|
Use the keyboard unless a joystick is set to give a direction.
|
||||||||||||||
| TurnSheriff_Choose | CB93 | LD HL,$A21C | Point HL at Options. | |||||||||||
| CB96 | LD A,(HL) | Fetch Options. | ||||||||||||
| CB97 | AND %00000110 | Keep the bits for the controls. | ||||||||||||
| CB99 | JR Z,TurnSheriff_Keyboard | Jump to TurnSheriff_Keyboard if the controls are the keyboard. | ||||||||||||
| CB9B | BIT 3,(HL) | Jump to TurnSheriff_Keyboard if bit 3 of Options is not set. | ||||||||||||
| CB9D | JR Z,TurnSheriff_Keyboard | |||||||||||||
| CB9F | LD A,($A268) | Fetch ViewRotation. | ||||||||||||
| CBA2 | AND %00000001 | Keep the lowest bit. | ||||||||||||
| CBA4 | CALL NZ,SwapControls | Call SwapControls if the view is rotated. | ||||||||||||
|
Turn towards the direction that is pressed.
|
||||||||||||||
| CBA7 | BIT 0,E | Jump to TurnSheriff_Right if left is pressed. | ||||||||||||
| CBA9 | JR NZ,TurnSheriff_Right | |||||||||||||
| CBAB | BIT 2,E | Jump to TurnSheriff_Up if up is pressed. | ||||||||||||
| CBAD | JR NZ,TurnSheriff_Up | |||||||||||||
|
The controls are not for up.
|
||||||||||||||
| TurnSheriff_Right | CBAF | BIT 1,E | Jump to TurnSheriff_ToRight if right is pressed. | |||||||||||
| CBB1 | JR NZ,TurnSheriff_ToRight | |||||||||||||
| CBB3 | BIT 4,E | Jump to TurnSheriff_ToDown if down is pressed. | ||||||||||||
| CBB5 | JR NZ,TurnSheriff_ToDown | |||||||||||||
| CBB7 | BIT 0,E | Jump to TurnSheriff_ToLeft if left is pressed. | ||||||||||||
| CBB9 | JR NZ,TurnSheriff_ToLeft | |||||||||||||
| CBBB | RES 2,E | Clear bit 2 of the controls. | ||||||||||||
| CBBD | JR TurnSheriff_Keyboard | Jump to TurnSheriff_Keyboard. | ||||||||||||
|
The controls are for up.
|
||||||||||||||
| TurnSheriff_Up | CBBF | LD A,(IX+$06) | Fetch the heading. | |||||||||||
|
How far is the heading from the direction that is wanted?
|
||||||||||||||
| TurnSheriff_Difference | CBC2 | AND %11000000 | Keep only the heading. | |||||||||||
| CBC4 | RES 2,E | Clear bit 2 of the controls. | ||||||||||||
| CBC6 | JR Z,TurnSheriff_Facing | Jump to TurnSheriff_Facing if he already faces that way. | ||||||||||||
| CBC8 | CP $40 | Jump to TurnSheriff_Back if he is a quarter turn away. | ||||||||||||
| CBCA | JR Z,TurnSheriff_Back | |||||||||||||
| CBCC | CP $C0 | Jump to TurnSheriff_Forward if he is three quarter turns away. | ||||||||||||
| CBCE | JR Z,TurnSheriff_Forward | |||||||||||||
| CBD0 | LD A,($A218) | Fetch FirstRandomNumber. | ||||||||||||
| CBD3 | CP $80 | Jump to TurnSheriff_Forward if it is less than 80. | ||||||||||||
| CBD5 | JR C,TurnSheriff_Forward | |||||||||||||
|
Turn back a quarter.
|
||||||||||||||
| TurnSheriff_Back | CBD7 | LD A,(IX+$06) | Fetch the heading. | |||||||||||
| CBDA | SUB $40 | Take a quarter turn off it. | ||||||||||||
| CBDC | JR TurnSheriff_Start | Jump to TurnSheriff_Start. | ||||||||||||
|
Turn on a quarter.
|
||||||||||||||
| TurnSheriff_Forward | CBDE | LD A,(IX+$06) | Fetch the heading. | |||||||||||
| CBE1 | ADD A,$40 | Add a quarter turn to it. | ||||||||||||
| CBE3 | JR TurnSheriff_Start | Jump to TurnSheriff_Start. | ||||||||||||
|
The controls are for right.
|
||||||||||||||
| TurnSheriff_ToRight | CBE5 | LD A,(IX+$06) | Fetch the heading. | |||||||||||
| CBE8 | SUB $40 | Take a quarter turn off it. | ||||||||||||
| CBEA | JR TurnSheriff_Difference | Jump to TurnSheriff_Difference. | ||||||||||||
|
The controls are for down.
|
||||||||||||||
| TurnSheriff_ToDown | CBEC | LD A,(IX+$06) | Fetch the heading. | |||||||||||
| CBEF | SUB $80 | Take two quarter turns off it. | ||||||||||||
| CBF1 | JR TurnSheriff_Difference | Jump to TurnSheriff_Difference. | ||||||||||||
|
The controls are for left.
|
||||||||||||||
| TurnSheriff_ToLeft | CBF3 | LD A,(IX+$06) | Fetch the heading. | |||||||||||
| CBF6 | SUB $C0 | Take three quarter turns off it. | ||||||||||||
| CBF8 | JR TurnSheriff_Difference | Jump to TurnSheriff_Difference. | ||||||||||||
|
The sheriff faces the way he was asked to.
|
||||||||||||||
| TurnSheriff_Facing | CBFA | SET 2,E | Set bit 2 of the controls and return. | |||||||||||
| CBFC | RET | |||||||||||||
|
Left and right turn the sheriff a quarter.
|
||||||||||||||
| TurnSheriff_Keyboard | CBFD | LD A,(IX+$06) | Fetch the heading. | |||||||||||
| CC00 | BIT 0,E | Jump to TurnSheriff_KeyboardRight if left is not pressed. | ||||||||||||
| CC02 | JR Z,TurnSheriff_KeyboardRight | |||||||||||||
| CC04 | SUB $40 | Take a quarter turn off the heading. | ||||||||||||
| CC06 | OR %00000001 | Start a turn. | ||||||||||||
|
Right turns him the other way.
|
||||||||||||||
| TurnSheriff_KeyboardRight | CC08 | BIT 1,E | Jump to TurnSheriff_Store if right is not pressed. | |||||||||||
| CC0A | JR Z,TurnSheriff_Store | |||||||||||||
| CC0C | ADD A,$40 | Add a quarter turn to the heading. | ||||||||||||
|
Start a turn and store the heading.
|
||||||||||||||
| TurnSheriff_Start | CC0E | OR %00000001 | Start a turn. | |||||||||||
| TurnSheriff_Store | CC10 | LD (IX+$06),A | Set the heading. | |||||||||||
|
Continue on to SetFacingFlags.
View the equivalent code in;
|
||||||||||||||
| Prev: CB60 | Up: Map | Next: CC13 |