Skip to navigation

Maths (Arithmetic): MultiplyCoords

Name: MultiplyCoords [Show more] Type: Subroutine Category: Maths (Arithmetic) Summary: Multiply a 16-bit signed number and a 16-bit sign-magnitude value
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * GetVectorForAngles calls MultiplyCoords

This routine multiplies two 16-bit values and stores the result according to the arguments, as follows. When Y = 0, it calculates: cosVectorPitch(Hi Lo) * sinAngle(Hi Lo) i.e. cosVectorPitch * sinAngle When Y = 1, it calculates: cosVectorPitch(Hi Lo) * cosAngle(Hi Lo) i.e. cosVectorPitch * cosAngle When X = 0, store the result in xVector(Lo Bot). When X = 2, store the result in zVector(Lo Bot).
Arguments: cosVectorPitchHi The 16-bit signed number to multiply (high byte) cosVectorPitchLo The 16-bit signed number to multiply (low byte) Y Offset of the 16-bit sign-magnitude value to multiply: * 0 = sinAngle * 1 = cosAngle X Offset of the variable to store the result in: * 0 = xVector(Lo Bot) * 2 = zVector(Lo Bot)
.MultiplyCoords LDA #0 \ Set H to sign to apply to the result of Multiply16x16 STA H \ (in bit 7), so setting H 0 ensures that that the \ result is positive LDA cosVectorPitchLo \ Set (QQ PP) = cosVectorPitch(Hi Lo) STA PP \ LDA cosVectorPitchHi \ where (QQ PP) is a 16-bit signed number STA QQ LDA sinAngleLo,Y \ Set (SS RR) to the 16-bit sign-magnitude number STA RR \ pointed to by Y LDA sinAngleHi,Y STA SS JSR Multiply16x16 \ Set (A T) = (QQ PP) * (SS RR) \ \ And apply the sign from bit 7 of H to ensure the \ result is positive STA xVectorLo,X \ Store the result in: LDA T \ STA xVectorBot,X \ * xVector(Lo Bot) when X = 0 \ \ * zVector(Lo Bot) when X = 2 RTS \ Return from the subroutine