.Multiply8x16Signed PHP \ Store the N flag on the stack JSR Absolute16Bit \ Set the sign of (A T) to that of the N flag argument STA V \ Set (V T) = (A T) STY U \ Set U = Y JSR Multiply8x16 \ Set (U T) = U * (V T) / 256 \ = Y * (A T) / 256 LDA U \ Set (A T) = (U T) \ = Y * (A T) / 256 PLP \ Retrieve the N flag from the stack JSR Absolute16Bit \ Set the sign of (A T) to that of the N flag argument RTS \ Return from the subroutineName: Multiply8x16Signed [Show more] Type: Subroutine Category: Maths (Arithmetic) Summary: Multiply an 8-bit and a 16-bit number and apply a sign to the resultContext: See this subroutine in context in the source code References: This subroutine is called as follows: * ApplySpinYaw calls Multiply8x16Signed * ScaleTyreForces calls Multiply8x16Signed
This routine calculates: (A T) = (A T) * abs(A) * Y / 256 where A is the last variable to be loaded before the subroutine call. So if the call follows an LDA instruction, for example, the following is calculated if A is positive: (A T) = (A T) * Y / 256 and the following is calculated if A is negative: (A T) = -(A T) * Y / 256
Arguments: (A T) A 16-bit signed number Y An unsigned number N flag Controls the sign to be applied: * N flag clear to calculate (A T) * Y / 256 * N flag set to calculate -(A T) * Y / 256
[X]
Subroutine Absolute16Bit (category: Maths (Arithmetic))
Calculate the absolute value (modulus) of a 16-bit number
[X]
Subroutine Multiply8x16 (category: Maths (Arithmetic))
Multiply an 8-bit and a 16-bit number