Prev: 27922 Up: Map Next: 28143
28019: Set Speed
Used by the routines at HandlerCanAccelerate and UpdatePlayerCar.
Stores the new speed, draws the speed gauge and moves the car. The direction is split into the quadrant (the top two bits, held in 24081) and the position in that quadrant (the top five bits of Player_Direction). The table at MovementTable is then used to share out the speed between the Y and X directions; the X part uses the table from the other end.
Input
A Speed
HandlerAccelerate 28019 LD (24077),A Write the new speed to Speed.
This entry point is used by the routines at HandlerCanAccelerate and UpdatePlayerCar.
Draw the speed gauge.
HandlerAccelerate_Gauge 28022 LD A,(24077) Fetch the speed of the car (Speed).
28025 LD HL,18914 Set the screen location of the speed gauge, 18914.
28028 CALL DrawGaugeLine Draw the speed gauge using DrawGaugeLine.
Work out the direction.
28031 LD A,(24081) Fetch the quadrant of the direction (24081).
28034 INC A Add one to the quadrant.
28035 LD C,A Keep the quadrant in C.
28036 LD A,(24080) Fetch the direction (Player_Direction).
28039 RRA Shift A right three times.
28040 RRA
28041 RRA
28042 AND %00011111 Keep bits 0-4.
28044 BIT 0,C Jump to HandlerAccelerate_TableIndex if bit 0 of C is set.
28046 JR NZ,HandlerAccelerate_TableIndex
28048 XOR %00011111 Reverse bits 0-4 (the position in the quadrant is measured the other way round).
HandlerAccelerate_TableIndex 28050 LD E,A Use the position in the quadrant as the index into the table.
28051 LD D,0 Clear the high byte of the index.
28053 PUSH DE Stash the index on the stack.
28054 LD HL,32619 Point HL at the table which shares out the speed (MovementTable).
28057 ADD HL,DE Add the index to the start of the table.
28058 LD A,(24077) Fetch the speed of the car (Speed) and keep it in E.
28061 LD E,A
28062 LD D,0 Clear the high byte of the speed.
28064 PUSH DE Stash DE (the speed) on the stack.
28065 LD A,(HL) Fetch the share of the speed from the table.
28066 CALL MultiplyAByDE Call MultiplyAByDE to multiply A by the speed.
Move the car in the Y direction.
28069 LD A,(24073) Fetch the top byte of the Y position of the car (PlayerMapPositionY_Fraction + 2).
28072 LD DE,(24071) DE=PlayerMapPositionY_Fraction.
28076 CALL DivideByThirtyTwo Call DivideByThirtyTwo to divide the result by 32.
28079 BIT 1,C Jump to SubtractY if the car is moving to a lower Y position.
28081 JR NZ,SubtractY
28083 ADD HL,DE Add the result to the Y position.
28084 ADC A,0 Carry any overflow into the top byte.
28086 CP 12 Jump to BounceY if the Y position reached the edge of the map (12).
28088 JR NC,BounceY
This entry point is used by the routine at SubtractY.
HandlerAccelerate_StoreY 28090 LD (24073),A Write the top byte of the Y position.
28093 LD (24071),HL Write the rest of the Y position.
This entry point is used by the routine at BounceY.
Move the car in the X direction.
HandlerAccelerate_MoveX 28096 POP HL Restore the speed from the stack.
28097 POP DE Restore the offset from the stack.
28098 PUSH HL Stash the speed on the stack.
28099 LD HL,32650 Point HL at the end of the table which shares out the speed (MovementTable_Last).
28102 AND A Clear the carry flag.
28103 SBC HL,DE HL=MovementTable_Last - offset (this reads the table from the other end).
28105 LD A,(HL) Fetch the share of the speed from the table.
28106 POP DE Restore the speed from the stack.
28107 CALL MultiplyAByDE Call MultiplyAByDE to multiply A by the speed.
28110 LD A,(24070) Fetch the top byte of the X position of the car (PlayerMapPosition_Fraction + 2).
28113 LD DE,(24068) DE=PlayerMapPosition_Fraction.
28117 CALL DivideByThirtyTwo Call DivideByThirtyTwo to divide the result by 32.
28120 DEC C Decrease C by one.
28121 BIT 1,C Jump to SubtractX if the car is moving to a lower X position.
28123 JR NZ,SubtractX
28125 ADD HL,DE Add the result to the X position.
28126 ADC A,0 Carry any overflow into the top byte.
28128 CP 24 Jump to BounceX if the X position reached the edge of the map (24).
28130 JR NC,BounceX
This entry point is used by the routine at SubtractX.
HandlerAccelerate_StoreX 28132 LD (24068),HL Write the rest of the X position.
28135 LD (24070),A Write the top byte of the X position.
This entry point is used by the routine at BounceX.
HandlerAccelerate_UpdateObject 28138 CALL UpdateCurrentObject Call UpdateCurrentObject.
28141 JR HandlerSteering Jump to HandlerSteering.
Prev: 27922 Up: Map Next: 28143