Skip to navigation


3D geometry: SetMatrixEntry

Name: SetMatrixEntry [Show more] Type: Subroutine Category: 3D geometry Summary: Calculate a matrix entry
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * SetMatrices calls SetMatrixEntry * SetMatrices calls via SetMatrixEntry2 * SetMatrices calls via SetMatrixEntry3

This routine reads one of the projected coordinate values that we calculated in ProjectAxisAngle (in mx1 to mz2), performs a multiplication, and writes the result to the specified entry in matrix 1. If mRead is the matrix entry in X (from mx1 to mz2) and mWrite is the matrix entry in Y (from m0 to m8), then it calculates the following: mWrite = (J I) * mRead >> 16
Arguments: X The matrix entry to read (mRead): * 0 = mx1 * 1 = my1 * 2 = mz1 * 3 = mx2 * 4 = my2 * 5 = mz2 Y The matrix entry to write (mWrite) in matrix 1: * 0 = m0 * 1 = m1 * 2 = m2 ... * 7 = m7 * 8 = m8 matrixNumber The routine is only ever called with matrixNumber = 0, so it only ever writes to matrix 1, but calling the routine with a different value would allow us to write to a different matrix matrixAxis The routine is only ever called with matrixAxis = 0, which has no effect on the calculation, but calling the routine with a non-zero value of matrixAxis would allow different mRead values to be used, i.e. matrixAxis+X
Returns: mWrite Set to (J I) * mRead >> 16 (S R) The value of mRead (H G) The value written to mWrite
Other entry points: SetMatrixEntry2 Set mWrite = (S R) * mRead >> 16 and (J I) = mRead SetMatrixEntry3 Set mWrite = (J I) * -mRead >> 16 and (S R) = -mRead
.SetMatrixEntry TXA \ Set X = matrixAxis + X CLC \ ADC matrixAxis \ This has no effect when matrixAxis = 0, which is the TAX \ only value that this routine is called with LDA mx1Lo,X \ Set R = the low byte from the matrix entry to read STA R .smen1 LDA mx1Hi,X \ Set (S R) = the matrix entry to read STA S JMP smen2 \ Jump down to smen2 to do the calculation .SetMatrixEntry3 TXA \ Set X = matrixAxis + X CLC \ ADC matrixAxis \ This has no effect when matrixAxis = 0, which is the TAX \ only value that this routine is called with LDA mx1Lo,X \ Set R = the low byte from the matrix entry to read, EOR #1 \ with the sign in bit 0 flipped STA R JMP smen1 \ Jump up to smen1 to set the high byte .SetMatrixEntry2 TXA \ Set X = matrixAxis + X CLC \ ADC matrixAxis \ This has no effect when matrixAxis = 0, which is the TAX \ only value that this routine is called with LDA mx1Lo,X \ Set (J I) = the matrix entry to read STA I LDA mx1Hi,X STA J .smen2 TYA \ Set N = Y + matrixNumber CLC \ ADC matrixNumber \ This sets N = Y when matrixNumber = 0, which is the STA N \ only value that this routine is called with JSR Multiply16x16Bit0 \ Set (H G) = (J I) * (S R) >> 16 LDY N \ Fetch the index of the matrix entry to write that we \ stored in N above LDA G \ Store (H G) in the matrix entry to write STA matrix1Lo,Y LDA H STA matrix1Hi,Y RTS \ Return from the subroutine