MATH COPROCESSOR FORMAT REGISTER

Controls the format of each of the math coprocessor's registers

u8 in RAM at 0xE180 called MATHCO_RAM_FORMAT

76543210
RxBBBAAA

A: RW A Register's format (see MCF_...)
B: RW B Register's format (see MCF_...)
R: RW R Register's format (see MCF_..., U32 and S32 only!)

MATH COPROCESSOR OPCODE REGISTER

Specify the operation that the math coprocessor is executing.
NOTE: This coprocessor is continually evaluating the specified opcode. Thus, you must be careful when transfering the value of the R register back into the A or B registers. The moment you write either part of the A or B registers, the coprocessor begins to see a new value, and will update the value of the R register. i.e. you will affect the other byte of the R register. The safe way to transfer the value, is to either use a transfer opcode, or read both parts of R before writing anything to A or B.

u8 in RAM at 0xE181 called MATHCO_RAM_OPCODE

76543210
xxxOOOOO

O: RW The opcode to execute (see MCO_...)

MATH COPROCESSOR STATUS REGISTER

Discover additional details regarding the current result

u8 in RAM at 0xE182 called MATHCO_RAM_STATUS

76543210
xxxxxxNZ

N: R. Negative flag (R<0)
Z: R. Zero flag (R==0)

MATH COPROCESSOR A, B, and R REGISTERS

The bytes of the A, B, and R Registers. NOTE: You only need to set the bytes that are meaningful, given the format that you have assigned to the register.

u8 in RAM at 0xE183 called MATHCO_RAM_A0

76543210
VVVVVVVV

V: RW 8 bits of the value

u8 in RAM at 0xE184 called MATHCO_RAM_A1

u8 in RAM at 0xE185 called MATHCO_RAM_A2

u8 in RAM at 0xE186 called MATHCO_RAM_A3

u8 in RAM at 0xE187 called MATHCO_RAM_B0

u8 in RAM at 0xE188 called MATHCO_RAM_B1

u8 in RAM at 0xE189 called MATHCO_RAM_B2_C0

u8 in RAM at 0xE18A called MATHCO_RAM_B3_C1

u8 in RAM at 0xE18B called MATHCO_RAM_R0

u8 in RAM at 0xE18C called MATHCO_RAM_R1

u8 in RAM at 0xE18D called MATHCO_RAM_R2

u8 in RAM at 0xE18E called MATHCO_RAM_R3

u8 in RAM at 0xE18F called MATHCO_RAM_RS

The various formats that the A, B, and R registers can use

enum MathCoFormat

NameValueComment
MCF_U32032bit unsigned number (A, B, R)
MCF_S32132bit signed number (A, B, R)
MCF_U24224bit unsigned number (A, B, -)
MCF_S24324bit signed number (A, B, -)
MCF_U16416bit unsigned number (A, B, -)
MCF_S16516bit signed number (A, B, -)
MCF_U8 68bit unsigned number (A, B, -)
MCF_S8 78bit signed number (A, B, -)

The various operations that the Math Coprocessor may execute.

enum MathCoOpcode

NameValueComment
MCO_AplusB 0R = A + B
MCO_AtimesB 1R = A * B
MCO_AminusB 2R = A - B
MCO_BminusA 3R = B - A
MCO_AdividedByB 4R = A / B
MCO_BdividedByA 5R = B / A
MCO_AmodB 6R = A % B
MCO_BmodA 7R = B % A
MCO_Assign_RtoA 8A = R
MCO_Assign_RtoB 9B = R
MCO_Assign_AtoR 10R = A
MCO_Assign_BtoR 11R = B
MCO_AlsrB 12R = A LSR B (Logical Shift Right)
MCO_AlslB 13R = A LSL B (Logical Shift Left)
MCO_ArorB 14R = A ROR B (Roll Right)
MCO_ArolB 15R = A ROL B (Roll Left)
MCO_AasrB 16R = A ASR B (Arithmetic Shift Right)
MCO_AtimesA 17R = A * A
MCO_AtimesAplusB 18R = A * A + B
MCO_AtimesAminusB 19R = A * A - B
MCO_AdividedByBplusC 20R = A / B + C

Macro/Inline

// Create a format specifier for the A, B, and R registers all in one macro.
#define MATHCO_FORMAT(a,b,r) ( ((r)<<4) | ((b)<<2) | (a) )

A mirror of all math coprocessor registers, in the IO address space. See the other mirror, in the VideoRegisters, for full documentation.

u8 in IO at 0x90 called MATHCO_IO_FORMAT

u8 in IO at 0x91 called MATHCO_IO_OPCODE

u8 in IO at 0x92 called MATHCO_IO_STATUS

u8 in IO at 0x93 called MATHCO_IO_A0

u8 in IO at 0x94 called MATHCO_IO_A1

u8 in IO at 0x95 called MATHCO_IO_A2

u8 in IO at 0x96 called MATHCO_IO_A3

u8 in IO at 0x97 called MATHCO_IO_B0

u8 in IO at 0x98 called MATHCO_IO_B1

u8 in IO at 0x99 called MATHCO_IO_B2_C0

u8 in IO at 0x9A called MATHCO_IO_B3_C1

u8 in IO at 0x9B called MATHCO_IO_R0

u8 in IO at 0x9C called MATHCO_IO_R1

u8 in IO at 0x9D called MATHCO_IO_R2

u8 in IO at 0x9E called MATHCO_IO_R3

u8 in IO at 0x9F called MATHCO_IO_RS

const A_U32


A_U32 = 0

const A_S32


A_S32 = 1

const A_U24


A_U24 = 2

const A_S24


A_S24 = 3

const A_U16


A_U16 = 4

const A_S16


A_S16 = 5

const A_U8


A_U8 = 6

const A_S8


A_S8 = 7

const B_U32


B_U32 = 0

const B_S32


B_S32 = 8

const B_U24


B_U24 = 16

const B_S24


B_S24 = 24

const B_U16


B_U16 = 32

const B_S16


B_S16 = 40

const B_U8


B_U8 = 48

const B_S8


B_S8 = 56

const R_U32


R_U32 = 0

const R_S32


R_S32 = 128