Skip to navigation

Revs on the BBC Micro

Driving model: ApplyDeltas

Name: ApplyDeltas [Show more] Type: Subroutine Category: Driving model Summary: Apply the deltas in the x-axis and z-axis to the player's coordinates Deep dive: The core driving model
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * ApplyDrivingModel calls ApplyDeltas

Calculate the following: xPlayerCoord = xPlayerCoord + xPlayerSpeed * 2 zPlayerCoord = zPlayerCoord + zPlayerSpeed * 2 playerYawAngle = playerYawAngle + spinYawAngle
.ApplyDeltas LDX #1 \ Set X = 1, to act as an axis counter for xPlayerSpeed \ and zPlayerSpeed \ \ The comments below are for when X = 1 LDY #2 \ Set Y = 2, to act as a variable counter in the \ following loop, iterating through values 0 and 2, as \ Y is decremented twice at the end of the loop \ \ The comments below are for when Y = 2 .delt1 LDA #0 \ Set V = 0, to use as the sign bit for (V A T) STA V LDA xPlayerSpeedHi,X \ Set (V A T) = zPlayerSpeed STA T LDA xPlayerSpeedTop,X BPL delt2 \ If A is positive, jump to delt2 to skip the following \ instruction DEC V \ Set V = &FF, so it contains the correct sign bit for \ (V A T) .delt2 ASL T \ Set (U A T) = (V A T) << 1 ROL A ROL V STA U LDA xPlayerCoordLo,Y \ Set zPlayerCoord = zPlayerCoord + (U A T) ADC T \ = zPlayerCoord + zPlayerSpeed * 2 STA xPlayerCoordLo,Y \ \ starting with the low bytes LDA xPlayerCoordHi,Y \ Then the high bytes ADC U STA xPlayerCoordHi,Y LDA xPlayerCoordTop,Y \ And then the top bytes ADC V STA xPlayerCoordTop,Y DEY \ Decrement Y twice so the next iteration adds to the DEY \ xPlayerCoord variable DEX \ Decrement X so the next iteration sets (V A T) to \ xPlayerSpeed BPL delt1 \ Loop back until we have updated both xPlayerCoord and \ zPlayerCoord LDA playerYawAngleLo \ Set playerYawAngle = playerYawAngle + spinYawAngle CLC \ ADC spinYawAngleHi \ starting with the low bytes STA playerYawAngleLo LDA playerYawAngleHi \ And then the high bytes ADC spinYawAngleTop STA playerYawAngleHi RTS \ Return from the subroutine