Maths Assist Unit
Created by: phil, Last modification: Sun 14 of Mar, 2010 (15:20 UTC)
The maths assist unit consists of 3 elements:
- A 256 word table which can hold values such as sine constants
- A 16bit value that is multiplied by the values in the table
- An index byte to select which word in the table to multiply by.
The multiplication is a signed 16 bit x 16 bit operation, but only 16 bits from the resulting 32 bit longword are available to be read, these bits are taken from bit 29 to bit 14. (Therefore care should be taken with the values used in the multiplication operation to a) get correct results for unscaled multiplies and b) prevent overflows.)
This unit can be used for fast scaling of values using just the first entry of the table. For example you could write some value to be scaled into the mult_table(0), set the mult_index at 0 and write the scaling factor from 0 to 16384 into mult_write. The output from mult_read will be mult_table(0) * mult_write/16384
To do an unscaled "multiply by a constant" (using only a single entry in the table) you need to adjust the multiplier and multiplicand to counter the scaling of the output. EG: To multiply $0087 by $0025 you could write $8700 into mult_write - (IE: a simple LSB/MSB byte swap) and $0940 into mult_table(0) (IE: $25 * $40). As the second word needs more processing, this would be your pre-set constant (you could of course fill the rest of the table with other constants.)
To use the maths unit as a simple 256 x 16bit look-up table, write your 16 bit words in the mult_table, 16384 into mult_write and simply select the value by setting mult_index and reading from mult_read.
The maths unit makes sin/cos calculations straightforward: Write the table with 256 sine values (maximum positive amplitude = 16384), set the multiplier word to coordinate x and the index byte to the angle a, the resulting word will be SIN (a) * x
The registers involved in the maths assist are as follows:
mult_write @ $208 / $209 16 bit multiplier: (write only)
The signed word written here is multiplied by a word from the multiply table selected by the index register. 16 bits 29:14 from the resulting 32-bit word are read from mult_read (the set of bits was chosen to provide fast scaling.)
mult_index @ $20A - Maths table index (byte): (write only)
Selects one of the 256 words in the table to multiply by the value written to the mult_write register.
"mult_table" @ $600-$7FF : Data table (write only)
This table holds 256 signed 16 bit words. The entry selected by mult_index is multiplied by the signed word in mult_write and 16 bits 29:14 of the 32 bit result appears in mult_read
mult_read @ $704-705 : Maths unit result (little endian): Bits 29:14 from the longword result of the maths unit operation
