Prev: 52307 Up: Map Next: 52362
52315: Slow Player Down
Works out the speed when the sheriff is not walking, from the distance to the next multiple of eight. Headings zero and two use the vertical position, one and three the horizontal. The speed is four, two or one. If he is already at a multiple of eight he stops.
Input
IX The address of the sheriff
Heading zero.
SlowPlayerDown 52315 LD A,(IX+3) Fetch the vertical position.
Find the distance to the next multiple of eight.
SlowPlayerDown_Distance 52318 AND %00000111 Keep the lowest three bits.
52320 JR Z,SlowPlayerDown_Stop Jump to SlowPlayerDown_Stop if the position is a multiple of eight.
52322 NEG Find the distance to the next multiple of eight.
52324 ADD A,8
52326 LD C,4 Set a speed of four.
52328 CP C Jump to SlowPlayerDown_Speed if the distance is four or more.
52329 JR NC,SlowPlayerDown_Speed
52331 SRL C Halve the speed.
52333 CP C Jump to SlowPlayerDown_Speed if the distance is two or more.
52334 JR NC,SlowPlayerDown_Speed
52336 LD C,A Use the distance.
Move the sheriff at this speed.
SlowPlayerDown_Speed 52337 LD A,C Jump to MovePlayerForward.
52338 JR MovePlayerForward
Heading one.
SlowPlayerDown_One 52340 LD A,(IX+1) Fetch the horizontal position.
52343 JR SlowPlayerDown_Distance Jump to SlowPlayerDown_Distance.
Heading two.
SlowPlayerDown_Two 52345 LD A,(IX+3) Fetch the vertical position.
Heading two or three.
SlowPlayerDown_Negate 52348 NEG Make it negative.
52350 JR SlowPlayerDown_Distance Jump to SlowPlayerDown_Distance.
Heading three.
SlowPlayerDown_Three 52352 LD A,(IX+1) Fetch the horizontal position.
52355 JR SlowPlayerDown_Negate Jump to SlowPlayerDown_Negate.
The sheriff is at a multiple of eight, so he stops.
SlowPlayerDown_Stop 52357 LD (IX+5),0 Set the speed to zero and return.
52361 RET
View the equivalent code in;
Prev: 52307 Up: Map Next: 52362