Fast math operations, and some 16-bit fixed point path. More...
#include "textio.c"
Macros | |
#define | FX(R) (int)((R) > 0 ? (R)*256 : 0xFFFF-((-(R)) *256) ) |
Inline compile time fixed point number. | |
Functions | |
char | FX_floor_int (int f) __naked |
Fixed point number to char number. | |
int | FX_floor (int f) __naked |
Round fixed point number. | |
char | sqrt_rounded (int x) __naked |
Gets the square root of a 16-bit intager to a 8 bit char. | |
long | mul_int (int x, int y) __naked |
Multiple two 16-bit ints together. | |
int | div_int (int x, int y) __naked |
Divide two 16-bit ints together. | |
int | FX_mul (int x, int y) __naked |
Multiple two 16-bit fixed point numbers. | |
int | FX_div (int x, int y) __naked |
Divide two 16-bit fixed point numbers. | |
int | FX_sqrt (int x) __naked |
Take the sqrt of a fixed point number. | |
int | FX_abs (int x) __naked |
Take the abs of a fixed point number. | |
void | FX_number (int x) __naked |
Print a fixed point number to the screen. | |
void | __fast_16_bit_sqrt_asm () __naked |
Assembly 16-bit Square Root routine | |
void | __mult_de_bc () __naked |
Assembly 16-bit multiplication routine | |
void | __div_32_by_16 () __naked |
Assembly 32-bit by 16-bit division routine | |
void | __div_ac_de () __naked |
Assembly 16-bit division routine | |
Fixed point trig functions (requires #define FX_TRIG) | |
const int | FX_sine_lookup [] = {4, 13, 22, 31, 40, 48, 57, 66, 74, 83, 91, 100, 108, 116, 124, 131, 139, 146, 154, 161, 167, 174, 181, 187, 193, 198, 204, 209, 214, 219, 223, 228, 232, 235, 238, 242, 244, 247, 249, 251, 252, 254, 255, 255, 255, 255, 255, 255, 254, 252, 251, 249, 247, 244, 242, 238, 235, 232, 228, 223, 219, 214, 209, 204, 198, 193, 187, 181, 174, 167, 161, 154, 146, 139, 131, 124, 116, 108, 100, 91, 83, 74, 66, 57, 48, 40, 31, 22, 13, 4, -4, -13, -22, -31, -40, -48, -57, -66, -74, -83, -91, -100, -108, -116, -124, -131, -139, -146, -154, -161, -167, -174, -181, -187, -193, -198, -204, -209, -214, -219, -223, -228, -232, -235, -238, -242, -244, -247, -249, -251, -252, -254, -255, -255, -255, -255, -255, -255, -254, -252, -251, -249, -247, -244, -242, -238, -235, -232, -228, -223, -219, -214, -209, -204, -198, -193, -187, -181, -174, -167, -161, -154, -146, -139, -131, -124, -116, -108, -100, -91, -83, -74, -66, -57, -48, -40, -31, -22, -13, -4} |
Fixed point sine lookup table. Takes up 360 bytes | |
int | FX_sine (int deg) |
Fixed point sine operation. | |
int | FX_cos (int deg) |
Fixed point cosine operation. | |
int | FX_tan (int deg) |
Fixed point tangent operation. | |
Fast math operations, and some 16-bit fixed point path.
Faster then fixedpoint.c but more complex and less precise. Uses 16 bit (int) for fixed point math (8 for decimal and 8 for fraction). It should be noted that if you are worried about the size of your program, this is quite a large file.
Mostly sourced from https://wikiti.brandonw.net/index.php?title=Category:Z80_Routines
#define FX | ( | R | ) | (int)((R) > 0 ? (R)*256 : 0xFFFF-((-(R)) *256) ) |
Inline compile time fixed point number.
[R] | Number to be converted |
This is used to create a fixed point number at compile time, highly NOT recommended to use at run time, or with anything other than a literal.
void __div_32_by_16 | ( | ) |
Assembly 32-bit by 16-bit division routine
IN: ACIX=dividend, DE=divisor OUT: ACIX=quotient, DE=divisor, HL=remainder, B=0
void __div_ac_de | ( | ) |
Assembly 16-bit division routine
This assembly routine divides ac by de and places the quotient in ac and the remainder in hl
void __fast_16_bit_sqrt_asm | ( | ) |
Assembly 16-bit Square Root routine
la is the 16-bit operand and D is the 8-bit result.
void __mult_de_bc | ( | ) |
Assembly 16-bit multiplication routine
bc by de and places the result in dehl.
int div_int | ( | int | x, |
int | y ) |
Divide two 16-bit ints together.
[x] | A 16-bit int (NOT fixed point number) |
[y] | Another 16-bit int (NOT fixed point number) |
int FX_abs | ( | int | x | ) |
Take the abs of a fixed point number.
[x] | A 16-bit fixed point number |
Taken from https://learn.cemetech.net/index.php?title=Z80:Math_Routines#absHL
int FX_cos | ( | int | deg | ) |
Fixed point cosine operation.
[deg] | A degree as an INTEGER |
int FX_div | ( | int | x, |
int | y ) |
Divide two 16-bit fixed point numbers.
[x] | A 16-bit fixed point number |
[y] | Another 16-bit fixed point number |
Takes about 1800 t-states (+-500)
int FX_floor | ( | int | f | ) |
Round fixed point number.
[f] | Number to be rounded |
char FX_floor_int | ( | int | f | ) |
Fixed point number to char number.
[f] | Number to be converted |
int FX_mul | ( | int | x, |
int | y ) |
Multiple two 16-bit fixed point numbers.
[x] | A 16-bit fixed point number |
[y] | Another 16-bit fixed point number |
void FX_number | ( | int | x | ) |
Print a fixed point number to the screen.
[x] | A 16-bit fixed point number |
int FX_sine | ( | int | deg | ) |
Fixed point sine operation.
[deg] | A degree as an INTEGER |
int FX_sqrt | ( | int | x | ) |
Take the sqrt of a fixed point number.
[x] | A 16-bit fixed point number |
int FX_tan | ( | int | deg | ) |
Fixed point tangent operation.
[deg] | A degree as an INTEGER |
long mul_int | ( | int | x, |
int | y ) |
Multiple two 16-bit ints together.
[x] | A 16-bit int (NOT fixed point number) |
[y] | Another 16-bit int (NOT fixed point number) |
char sqrt_rounded | ( | int | x | ) |
Gets the square root of a 16-bit intager to a 8 bit char.
[x] | A 16-bit INTEGER (NOT fixed point number) |