.Absolute8Bit BPL aval1 \ If A is positive then it already contains its absolute \ value, so jump to aval1 to return from the subroutine EOR #&FF \ Negate the value in A using two's complement, as the CLC \ following is true when A is negative: ADC #1 \ \ |A| = -A \ = ~A + 1 .aval1 RTS \ Return from the subroutineName: Absolute8Bit [Show more] Type: Subroutine Category: Maths (Arithmetic) Summary: Calculate the absolute value (modulus) of an 8-bit numberContext: See this subroutine in context in the source code References: This subroutine is called as follows: * ApplyElevation (Part 2 of 5) calls Absolute8Bit * ApplyElevation (Part 4 of 5) calls Absolute8Bit * ApplyGrassOrTrack calls Absolute8Bit * ApplyTyreForces calls Absolute8Bit * ApplyWingBalance calls Absolute8Bit * BuildRoadSign calls Absolute8Bit * BuildVisibleCar calls Absolute8Bit * CheckForCrash calls Absolute8Bit * CompareSegments calls Absolute8Bit * GetTrackAndMarkers calls Absolute8Bit * MovePlayerOnTrack calls Absolute8Bit * MultiplyHeight calls Absolute8Bit * ProcessOvertaking (Part 2 of 3) calls Absolute8Bit * SetDriverSpeed calls Absolute8Bit
This routine returns |A|. It can also return A * abs(n), where A is given the sign of n.
Arguments: A The number to make positive N flag Controls the sign to be applied: * If we want to calculate |A|, do an LDA or equivalent before calling the routine * If we want to calculate A * abs(n), do a BIT n before calling the routine * If we want to set the sign of A, then call with: * N flag clear to calculate A * 1 * N flag set to calculate A * -1
[X]
Label aval1 is local to this routine