SGDK
A free and open development kit for the Sega Mega Drive
Loading...
Searching...
No Matches
maths.h File Reference

Mathematical methods. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Vect2D_u16
 2D Vector structure - u16 type. More...
 
struct  Vect2D_s16
 2D Vector structure - s16 type. More...
 
struct  Vect2D_u32
 2D Vector structure - u32 type. More...
 
struct  Vect2D_s32
 2D Vector structure - s32 type. More...
 
struct  Vect2D_f16
 2D Vector structure - f16 (fix16) type. More...
 
struct  Vect2D_f32
 2D Vector structure - f32 (fix32) type. More...
 
struct  Vect2D_ff16
 2D Vector structure - ff16 (fastfix16) type. More...
 
struct  Vect2D_ff32
 2D Vector structure - ff32 (fastfix32) type. More...
 
struct  Mat2D_f16
 2x2 Matrice structure - f16 (fix16) type.
Internally uses 2 2D vectors. More...
 
struct  Mat2D_f32
 2x2 Matrice structure - f32 (fix32) type.
Internally uses 2 2D vectors. More...
 
struct  Mat2D_ff16
 2x2 Matrice structure - ff16 (fastfix16) type.
Internally uses 2 2D vectors. More...
 
struct  Mat2D_ff32
 2x2 Matrice structure - ff32 (fastfix32) type.
Internally uses 2 2D vectors. More...
 

Macros

#define PI   3.14159265358979323846
 PI number (3,1415..)
 
#define FIX16_INT_BITS   10
 
#define FIX16_FRAC_BITS   (16 - FIX16_INT_BITS)
 
#define FIX16_INT_MASK   (((1 << FIX16_INT_BITS) - 1) << FIX16_FRAC_BITS)
 
#define FIX16_FRAC_MASK   ((1 << FIX16_FRAC_BITS) - 1)
 
#define FIX32_INT_BITS   22
 
#define FIX32_FRAC_BITS   (32 - FIX32_INT_BITS)
 
#define FIX32_INT_MASK   (((1 << FIX32_INT_BITS) - 1) << FIX32_FRAC_BITS)
 
#define FIX32_FRAC_MASK   ((1 << FIX32_FRAC_BITS) - 1)
 
#define FASTFIX16_INT_BITS   8
 
#define FASTFIX16_FRAC_BITS   (16 - FASTFIX16_INT_BITS)
 
#define FASTFIX16_INT_MASK   (((1 << FASTFIX16_INT_BITS) - 1) << FASTFIX16_FRAC_BITS)
 
#define FASTFIX16_FRAC_MASK   ((1 << FASTFIX16_FRAC_BITS) - 1)
 
#define FASTFIX32_INT_BITS   16
 
#define FASTFIX32_FRAC_BITS   (32 - FASTFIX32_INT_BITS)
 
#define FASTFIX32_INT_MASK   (((1 << FASTFIX32_INT_BITS) - 1) << FASTFIX32_FRAC_BITS)
 
#define FASTFIX32_FRAC_MASK   ((1 << FASTFIX32_FRAC_BITS) - 1)
 
#define FIX16(value)
 Convert specified value to fix16.
 
#define FIX32(value)
 Convert specified value to fix32.
 
#define FASTFIX16(value)
 Convert specified value to "fast" fix16.
 
#define FASTFIX32(value)
 Convert specified value to "fast" fix32.
 
#define F16(value)
 Convert specified value to fix16 (short version)
 
#define F32(value)
 Convert specified value to fix32 (short version)
 
#define FF16(value)
 Convert specified value to "fast" fix16 (short version)
 
#define FF32(value)
 Convert specified value to "fast" fix32 (short version)
 
#define F16_PI   ((fix16) F16(PI))
 
#define F16_RAD_TO_DEG   F16(57.29577951308232)
 
#define F32_PI   ((fix32) F32(PI))
 
#define min(X, Y)
 Returns the lowest value between X an Y.
 
#define max(X, Y)
 Returns the highest value between X an Y.
 
#define clamp(X, L, H)
 Returns L if X is less than L, H if X is greater than H or X if in between L and H.
 
#define abs(X)
 Returns the absolute value of X.
 
#define distance_approx(dx, dy)
 
#define getApproximatedLog2(value)
 
#define getLog2Int(value)
 
#define intToFix16(a)
 
#define fix16ToInt(a)
 
#define fix16ToFix32(a)
 
#define fix16Frac(a)
 
#define fix16Int(a)
 
#define fix16Round(a)
 
#define fix16ToRoundedInt(a)
 
#define fix16Add(a, b)
 
#define fix16Sub(a, b)
 
#define fix16Neg(a)
 
#define fix16Mul(a, b)
 
#define fix16Div(a, b)
 
#define fix16Avg(a, b)
 
#define fix16Log2(a)
 
#define fix16Log10(a)
 
#define fix16Sqrt(a)
 
#define intToFix32(a)
 
#define fix32ToInt(a)
 
#define fix32ToFix16(a)
 
#define fix32Frac(a)
 
#define fix32Int(a)
 
#define fix32Round(a)
 
#define fix32ToRoundedInt(a)
 
#define fix32Add(a, b)
 
#define fix32Sub(a, b)
 
#define fix32Neg(a)
 
#define fix32Mul(a, b)
 
#define fix32Div(a, b)
 
#define fix32Avg(a, b)
 
#define intToFastFix16(a)
 
#define fastFix16ToInt(a)
 
#define fastFix16Frac(a)
 
#define fastFix16Int(a)
 
#define fastFix16Round(a)
 
#define fastFix16ToRoundedInt(a)
 
#define fastFix16Mul(a, b)
 
#define fastFix16Div(a, b)
 
#define intToFastFix32(a)
 
#define fastFix32ToInt(a)
 
#define fastFix32Frac(a)
 
#define fastFix32Int(a)
 
#define fastFix32Round(a)
 
#define fastFix32ToRoundedInt(a)
 
#define fastFix32Mul(a, b)
 
#define fastFix32Div(a, b)
 
#define getApproximatedDistanceV(dx, dy)
 

Typedefs

typedef Vect2D_u16 V2u16
 alias for Vect2D_u16
 
typedef Vect2D_s16 V2s16
 alias for Vect2D_s16
 
typedef Vect2D_u32 V2u32
 alias for Vect2D_u32
 
typedef Vect2D_s32 V2s32
 alias for Vect2D_s32
 
typedef Vect2D_f16 V2f16
 alias for Vect2D_f16
 
typedef Vect2D_f32 V2f32
 alias for Vect2D_f32
 
typedef Vect2D_ff16 V2ff16
 alias for Vect2D_ff16
 
typedef Vect2D_ff32 V2ff32
 alias for Vect2D_ff32
 
typedef Mat2D_f16 M2f16
 alias for Mat2D_f16
 
typedef Mat2D_f32 M2f32
 alias for Mat2D_f32
 
typedef Mat2D_ff16 M2ff16
 alias for Mat2D_ff16
 
typedef Mat2D_ff32 M2ff32
 alias for Mat2D_ff32
 

Functions

u32 mulu (u16 op1, u16 op2)
 16x16=32 unsigned multiplication. Force GCC to use proper 68000 mulu instruction.
 
s32 muls (s16 op1, s16 op2)
 16x16=32 signed multiplication. Force GCC to use proper 68000 muls instruction.
 
u16 divu (u32 op1, u16 op2)
 Direct divu instruction (unsigned 32/16=16:16) access using inline assembly to process op1/op2 operation.
 
s16 divs (s32 op1, s16 op2)
 Direct divs instruction (signed 32/16=16:16) access using inline assembly to process op1/op2 operation.
 
u16 modu (u32 op1, u16 op2)
 Direct divu instruction (unsigned 32/16=16:16) access using inline assembly.
 
s16 mods (s32 op1, s16 op2)
 Direct divs instruction (signed 32/16=16:16) access using inline assembly.
 
u32 divmodu (u32 op1, u16 op2)
 Direct divu instruction (unsigned 32/16=16:16) access using inline assembly to process op1/op2 operation and op1op2 at same time.
 
s32 divmods (s32 op1, s16 op2)
 Direct divs instruction (signed 32/16=16:16) access using inline assembly to process op1/op2 operation and op1op2 at same time.
 
u32 u16ToBCD (u16 value)
 Convert u16 to BCD.
 
u32 u32ToBCD (u32 value)
 Convert u32 to BCD.
 
u32 getNextPow2 (u32 value)
 Return next pow2 value which is greater than specified 32 bits unsigned value. Ex:
getNextPow2(700) = 1024
getNextPow2(18) = 32

 
u16 getLog2 (u32 value)
 Return integer log2 of specified 32 bits unsigned value. Ex:
getLog2Int(1024) = 10
getLog2Int(12345) = 13

 
u32 getApproximatedDistance (s32 dx, s32 dy)
 Return euclidean distance approximation for specified vector.
The returned distance is not 100% perfect but calculation is fast.
 
u32 getApproximatedDistanceV (V2s32 *v)
 Return euclidean distance approximation for specified vector.
The returned distance is not 100% perfect but calculation is fast.
 
s16 F16_toInt (fix16 value)
 Convert fix16 to integer.
 
fix32 F16_toFix32 (fix16 value)
 Convert specified fix16 value to fix32.
 
fastfix16 F16_toFastFix16 (fix16 value)
 Convert specified fix16 value to fastfix16.
 
fastfix32 F16_toFastFix32 (fix16 value)
 Convert specified fix16 value to fastfix32.
 
fix16 F16_frac (fix16 value)
 Return fractional part of the specified value (fix16).
 
fix16 F16_int (fix16 value)
 Return integer part of the specified value (fix16).
 
fix16 F16_abs (fix16 x)
 Return the absolute value of the specified value (fix16).
 
fix16 F16_round (fix16 value)
 Round the specified value to nearest integer (fix16).
 
s16 F16_toRoundedInt (fix16 value)
 Round and convert the specified fix16 to integer.
 
fix16 F16_mul (fix16 val1, fix16 val2)
 Compute and return the result of the multiplication of val1 and val2 (fix16).
 
fix16 F16_div (fix16 val1, fix16 val2)
 Compute and return the result of the division of val1 by val2 (fix16).
 
fix16 F16_avg (fix16 val1, fix16 val2)
 Compute and return the result of the average of val1 by val2 (fix16).
 
fix16 F16_log2 (fix16 value)
 Compute and return the result of the Log2 of specified value (fix16).
 
fix16 F16_log10 (fix16 value)
 Compute and return the result of the Log10 of specified value (fix16).
 
fix16 F16_sqrt (fix16 value)
 Compute and return the result of the root square of specified value (fix16).
 
fix16 F16_normalizeAngle (fix16 angle)
 Return a normalized form of the input angle degree:
Output value is guaranteed to be in [FIX16(0)..FIX16(360)[ range.
 
fix16 F16_sin (fix16 angle)
 Compute sinus of specified angle (in degree) and return it (fix16).
 
fix16 F16_cos (fix16 angle)
 Compute cosinus of specified angle (in degree) and return it (fix16).
 
fix16 F16_tan (fix16 angle)
 Compute the tangent of specified angle (in degree) and return it (fix16).
 
fix16 F16_atan (fix16 x)
 Compute the arctangent of specified value and return it in degree (fix16).
 
fix16 F16_atan2 (fix16 y, fix16 x)
 Compute the arctangent of y/x. i.e: return the angle (in degree) for the (0,0)-(x,y) vector.
 
fix16 sinFix16 (u16 value)
 Compute sinus of specified value and return it as fix16.
The input value is an integer defined as [0..1024] range corresponding to radian [0..2PI] range.
 
fix16 cosFix16 (u16 value)
 Compute cosinus of specified value and return it as fix16.
The input value is an integer defined as [0..1024] range corresponding to radian [0..2PI] range.
 
fix16 F16_degreeToRadian (fix16 degree)
 Convert degree to radian (fix16)
 
fix16 F16_radianToDegree (fix16 radian)
 Convert radian to degree (fix16)
 
fix16 F16_getAngle (fix16 x1, fix16 y1, fix16 x2, fix16 y2)
 Compute and return the angle in degree between the 2 points defined by (x1,y1) and (x2,y2).
 
void F16_computePosition (fix16 *x2, fix16 *y2, fix16 x1, fix16 y1, fix16 ang, fix16 dist)
 Compute the new position of the point defined by (x1, y1) by moving it by the given 'distance' in the 'angle' direction and store the result in (x2, y2).
 
void F16_computePositionEx (fix16 *x2, fix16 *y2, fix16 x1, fix16 y1, fix16 ang, fix16 dist, fix16 cosAdj, fix16 sinAdj)
 Compute the new position of the point defined by (x1, y1) by moving it by the given 'distance' in the 'angle' direction and store the result in (x2, y2).
 
s32 F32_toInt (fix32 value)
 Convert fix32 to integer.
 
fix16 F32_toFix16 (fix32 value)
 Convert specified fix32 value to fix16.
 
fastfix16 F32_toFastFix16 (fix32 value)
 Convert specified fix32 value to fastfix16.
 
fastfix32 F32_toFastFix32 (fix32 value)
 Convert specified fix32 value to fastfix32.
 
fix32 F32_frac (fix32 value)
 Return fractional part of the specified value (fix32).
 
fix32 F32_int (fix32 value)
 Return integer part of the specified value (fix32).
 
fix32 F32_round (fix32 value)
 Round the specified value to nearest integer (fix32).
 
s32 F32_toRoundedInt (fix32 value)
 Round and convert the specified fix32 value to integer.
 
fix32 F32_mul (fix32 val1, fix32 val2)
 Compute and return the result of the multiplication of val1 and val2 (fix32).
WARNING: result can easily overflow so its recommended to stick with fix16 type for mul and div operations.
 
fix32 F32_div (fix32 val1, fix32 val2)
 Compute and return the result of the division of val1 by val2 (fix32).
WARNING: result can easily overflow so its recommended to stick with fix16 type for mul and div operations.
 
fix32 F32_avg (fix32 val1, fix32 val2)
 Compute and return the result of the average of val1 by val2 (fix32).
 
fix32 F32_sin (fix16 angle)
 Compute sinus of specified angle (in degree) and return it as fix32.
 
fix32 F32_cos (fix16 angle)
 Compute cosinus of specified angle (in degree) and return it as fix32.
 
fix32 sinFix32 (u16 value)
 Compute sinus of specified value and return it as fix32.
The input value is an integer defined as [0..1024] range corresponding to radian [0..2PI] range.
 
fix32 cosFix32 (u16 value)
 Compute cosinus of specified value and return it as fix32.
The input value is an integer defined as [0..1024] range corresponding to radian [0..2PI] range.
 
s16 FF16_toInt (fastfix16 value)
 Convert fastfix16 to integer.
 
fix16 FF16_toFix16 (fastfix16 value)
 Convert fastfix16 to fix16.
 
fix32 FF16_toFix32 (fastfix16 value)
 Convert fastfix16 to fix32.
 
fastfix32 FF16_toFastFix32 (fastfix16 value)
 Convert fastfix16 to fastfix32.
 
fastfix16 FF16_frac (fastfix16 value)
 Return fractional part of the specified value (fastfix16).
 
fastfix16 FF16_int (fastfix16 value)
 Return integer part of the specified value (fastfix16).
 
fastfix16 FF16_round (fastfix16 value)
 Round the specified value to nearest integer (fastfix16).
 
s16 FF16_toRoundedInt (fastfix16 value)
 Round and convert the specified fastfix16 value to integer (fastfix16).
 
fastfix16 FF16_mul (fastfix16 val1, fastfix16 val2)
 Compute and return the result of the multiplication of val1 and val2 (fastfix16).
 
fastfix16 FF16_div (fastfix16 val1, fastfix16 val2)
 Compute and return the result of the division of val1 by val2 (fastfix16).
 
fastfix32 FF32_fromInt (s16 value)
 Convert integer to fastfix32.
 
s16 FF32_toInt (fastfix32 value)
 Convert fastfix32 to integer.
 
fix16 FF32_toFix16 (fastfix32 value)
 Convert fastfix32 to fix16.
 
fix32 FF32_toFix32 (fastfix32 value)
 Convert fastfix32 to fix32.
 
fastfix16 FF32_toFastFix16 (fastfix32 value)
 Convert fastfix32 to fastfix16.
 
fastfix32 FF32_frac (fastfix32 value)
 Return fractional part of the specified value (fastfix32).
 
fastfix32 FF32_int (fastfix32 value)
 Return integer part of the specified value (fastfix32).
 
fastfix32 FF32_round (fastfix32 value)
 Round the specified value to nearest integer (fastfix32).
 
s32 FF32_toRoundedInt (fastfix32 value)
 Round and convert the specified fastfix32 value to integer.
 
fastfix32 FF32_mul (fastfix32 val1, fastfix32 val2)
 Compute and return the result of the multiplication of val1 and val2 (fastfix32).
WARNING: result can easily overflow so its recommended to stick with fix16 type for mul and div operations.
 
fastfix32 FF32_div (fastfix32 val1, fastfix32 val2)
 Compute and return the result of the division of val1 by val2 (fastfix32).
WARNING: result can easily overflow so its recommended to stick with fix16 type for mul and div operations.
 
fastfix32 FF32_getLog2Fast (fastfix32 value)
 Return a not accurate but fast log2 approximation of the specified value (fastfixed32) Ex:
getLog2(FASTFIX32(1)) = 0
getLog2(12345 << 16) = ~9.5 (real value = ~13.6)

 
u32 V2D_S32_getApproximatedDistance (V2s32 *v)
 Return euclidean distance approximation for specified vector.
The returned distance is not 100% perfect but calculation is fast.
 
fix16 V2D_F16_getAngle (V2f16 *pt1, V2f16 *pt2)
 Compute and return the angle in degree (fix16) between the 2 points pt1 and pt2.
 
void V2D_F16_movePoint (V2f16 *pt, fix16 ang, fix16 dist)
 Move the given point by the given 'distance' in the 'angle' direction.
 
void V2D_F16_movePointEx (V2f16 *pt, fix16 ang, fix16 dist, fix16 cosAdj, fix16 sinAdj)
 Compute the new position of the point defined by (x1, y1) by moving it by the given 'distance' in the 'angle' direction and store the resultin (x2, y2).
 

Variables

const fix16 trigtab_f16 [90+1]
 
const fix32 trigtab_f32 [(90 *4)+1]
 
const fix16 log2tab_f16 [0x10000]
 
const fix16 log10tab_f16 [0x10000]
 
const fix16 sqrttab_f16 [0x10000]
 

Detailed Description

Mathematical methods.

Author
Stephane Dallongeville
Date
08/2011

This unit provides basic maths methods.
You can find a tutorial about how use maths with SGDK here.

Macro Definition Documentation

◆ abs

#define abs ( X)
Value:
(((X) < 0)?-(X):(X))

Returns the absolute value of X.

◆ clamp

#define clamp ( X,
L,
H )
Value:
(min(max((X), (L)), (H)))
#define min(X, Y)
Returns the lowest value between X an Y.
Definition maths.h:306
#define max(X, Y)
Returns the highest value between X an Y.
Definition maths.h:312

Returns L if X is less than L, H if X is greater than H or X if in between L and H.

◆ distance_approx

#define distance_approx ( dx,
dy )
Value:
_Pragma("GCC error \"This method is deprecated, use getApproximatedDistance(..) instead.\"")

◆ F16

#define F16 ( value)
Value:
FIX16(value)
#define FIX16(value)
Convert specified value to fix16.
Definition maths.h:62

Convert specified value to fix16 (short version)

See also
FIX16

◆ F32

#define F32 ( value)
Value:
FIX32(value)
#define FIX32(value)
Convert specified value to fix32.
Definition maths.h:70

Convert specified value to fix32 (short version)

See also
FIX32

◆ FASTFIX16

#define FASTFIX16 ( value)
Value:
((fastfix16) ((value) * (1 << FASTFIX16_FRAC_BITS)))
s16 fastfix16
Definition types.h:224

Convert specified value to "fast" fix16.

Ex:
ff16 v = FASTFIX16(-27.12);

◆ fastFix16Div

#define fastFix16Div ( a,
b )
Value:
_Pragma("GCC error \"This method is deprecated, use FF16_div(..) instead.\"")

◆ fastFix16Frac

#define fastFix16Frac ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use FF16_frac(..) instead.\"")

◆ fastFix16Int

#define fastFix16Int ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use FF16_int(..) instead.\"")

◆ fastFix16Mul

#define fastFix16Mul ( a,
b )
Value:
_Pragma("GCC error \"This method is deprecated, use FF16_mul(..) instead.\"")

◆ fastFix16Round

#define fastFix16Round ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use FF16_round(..) instead.\"")

◆ fastFix16ToInt

#define fastFix16ToInt ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use FF16_toInt(..) instead.\"")

◆ fastFix16ToRoundedInt

#define fastFix16ToRoundedInt ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use FF16_toRoundedInt(..) instead.\"")

◆ FASTFIX32

#define FASTFIX32 ( value)
Value:
((fastfix32) ((value) * (1 << FASTFIX32_FRAC_BITS)))
s32 fastfix32
Definition types.h:229

Convert specified value to "fast" fix32.

Ex:
ff32 v = FASTFIX32(34.567);

◆ fastFix32Div

#define fastFix32Div ( a,
b )
Value:
_Pragma("GCC error \"This method is deprecated, use FF32_div(..) instead.\"")

◆ fastFix32Frac

#define fastFix32Frac ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use FF32_frac(..) instead.\"")

◆ fastFix32Int

#define fastFix32Int ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use FF32_int(..) instead.\"")

◆ fastFix32Mul

#define fastFix32Mul ( a,
b )
Value:
_Pragma("GCC error \"This method is deprecated, use FF32_mul(..) instead.\"")

◆ fastFix32Round

#define fastFix32Round ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use FF32_round(..) instead.\"")

◆ fastFix32ToInt

#define fastFix32ToInt ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use FF32_toInt(..) instead.\"")

◆ fastFix32ToRoundedInt

#define fastFix32ToRoundedInt ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use FF32_toRoundedInt(..) instead.\"")

◆ FF16

#define FF16 ( value)
Value:
FASTFIX16(value)
#define FASTFIX16(value)
Convert specified value to "fast" fix16.
Definition maths.h:79

Convert specified value to "fast" fix16 (short version)

See also
FASTFIX16

◆ FF32

#define FF32 ( value)
Value:
FASTFIX32(value)
#define FASTFIX32(value)
Convert specified value to "fast" fix32.
Definition maths.h:87

Convert specified value to "fast" fix32 (short version)

See also
FASTFIX32

◆ FIX16

#define FIX16 ( value)
Value:
((fix16) ((value) * (1 << FIX16_FRAC_BITS)))
s16 fix16
Definition types.h:203

Convert specified value to fix16.

Ex:
f16 v = FIX16(-27.12);

◆ fix16Add

#define fix16Add ( a,
b )
Value:
_Pragma("GCC error \"This method is deprecated, simply use '+' operator to add fix16 values together.\"")

◆ fix16Avg

#define fix16Avg ( a,
b )
Value:
_Pragma("GCC error \"This method is deprecated, use F16_avg(..) instead.\"")

◆ fix16Div

#define fix16Div ( a,
b )
Value:
_Pragma("GCC error \"This method is deprecated, use F16_div(..) instead.\"")

◆ fix16Frac

#define fix16Frac ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use F16_frac(..) instead.\"")

◆ fix16Int

#define fix16Int ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use F16_int(..) instead.\"")

◆ fix16Log10

#define fix16Log10 ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use F16_log10(..) instead.\"")

◆ fix16Log2

#define fix16Log2 ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use F16_log2(..) instead.\"")

◆ fix16Mul

#define fix16Mul ( a,
b )
Value:
_Pragma("GCC error \"This method is deprecated, use F16_mul(..) instead.\"")

◆ fix16Neg

#define fix16Neg ( a)
Value:
_Pragma("GCC error \"This method is deprecated, simply use '0 - value' to get the negative fix16 value.\"")

◆ fix16Round

#define fix16Round ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use F16_round(..) instead.\"")

◆ fix16Sqrt

#define fix16Sqrt ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use F16_sqrt(..) instead.\"")

◆ fix16Sub

#define fix16Sub ( a,
b )
Value:
_Pragma("GCC error \"This method is deprecated, simply use '-' operator to subtract fix16 values.\"")

◆ fix16ToFix32

#define fix16ToFix32 ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use F16_toFix32(..) instead.\"")

◆ fix16ToInt

#define fix16ToInt ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use F16_toInt(..) instead.\"")

◆ fix16ToRoundedInt

#define fix16ToRoundedInt ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use F16_toRoundedInt(..) instead.\"")

◆ FIX32

#define FIX32 ( value)
Value:
((fix32) ((value) * (1 << FIX32_FRAC_BITS)))
s32 fix32
Definition types.h:208

Convert specified value to fix32.

Ex:
f32 v = FIX32(34.567);

◆ fix32Add

#define fix32Add ( a,
b )
Value:
_Pragma("GCC error \"This method is deprecated, simply use '+' operator to add fix32 values together.\"")

◆ fix32Avg

#define fix32Avg ( a,
b )
Value:
_Pragma("GCC error \"This method is deprecated, use F32_avg(..) instead.\"")

◆ fix32Div

#define fix32Div ( a,
b )
Value:
_Pragma("GCC error \"This method is deprecated, use F32_div(..) instead.\"")

◆ fix32Frac

#define fix32Frac ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use F32_frac(..) instead.\"")

◆ fix32Int

#define fix32Int ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use F32_int(..) instead.\"")

◆ fix32Mul

#define fix32Mul ( a,
b )
Value:
_Pragma("GCC error \"This method is deprecated, use F32_mul(..) instead.\"")

◆ fix32Neg

#define fix32Neg ( a)
Value:
_Pragma("GCC error \"This method is deprecated, simply use '0 - value' to get the negative fix32 value.\"")

◆ fix32Round

#define fix32Round ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use F32_round(..) instead.\"")

◆ fix32Sub

#define fix32Sub ( a,
b )
Value:
_Pragma("GCC error \"This method is deprecated, simply use '-' operator to subtract fix32 values.\"")

◆ fix32ToFix16

#define fix32ToFix16 ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use F32_toFix16(..) instead.\"")

◆ fix32ToInt

#define fix32ToInt ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use F32_toInt(..) instead.\"")

◆ fix32ToRoundedInt

#define fix32ToRoundedInt ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use F32_toRoundedInt(..) instead.\"")

◆ getApproximatedDistanceV

#define getApproximatedDistanceV ( dx,
dy )
Value:
_Pragma("GCC error \"This method is deprecated, use V2D_S32_getApproximatedDistance(..) instead.\"")

◆ getApproximatedLog2

#define getApproximatedLog2 ( value)
Value:
_Pragma("GCC error \"This method is deprecated, use FF32_getLog2Fast(..) instead.\"")

◆ getLog2Int

#define getLog2Int ( value)
Value:
_Pragma("GCC error \"This method is deprecated, use getLog2(..) instead.\"")

◆ intToFastFix16

#define intToFastFix16 ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use FASTFIX16(..) instead.\"")

◆ intToFastFix32

#define intToFastFix32 ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use FASTFIX32(..) instead.\"")

◆ intToFix16

#define intToFix16 ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use FIX16(..) instead.\"")

◆ intToFix32

#define intToFix32 ( a)
Value:
_Pragma("GCC error \"This method is deprecated, use FIX32(..) instead.\"")

◆ max

#define max ( X,
Y )
Value:
(((X) > (Y))?(X):(Y))

Returns the highest value between X an Y.

◆ min

#define min ( X,
Y )
Value:
(((X) < (Y))?(X):(Y))

Returns the lowest value between X an Y.

Function Documentation

◆ cosFix16()

fix16 cosFix16 ( u16 value)

Compute cosinus of specified value and return it as fix16.
The input value is an integer defined as [0..1024] range corresponding to radian [0..2PI] range.

◆ cosFix32()

fix32 cosFix32 ( u16 value)

Compute cosinus of specified value and return it as fix32.
The input value is an integer defined as [0..1024] range corresponding to radian [0..2PI] range.

◆ divmods()

s32 divmods ( s32 op1,
s16 op2 )

Direct divs instruction (signed 32/16=16:16) access using inline assembly to process op1/op2 operation and op1op2 at same time.

Parameters
op1first operand - dividende (32 bit)
op2second operand - divisor (16 bit)
Returns
16 bit (signed) result of the division in low 16 bit (0-15) and 16 bit (signed) result of the modulo operation in high 16 bit (16-31)

◆ divmodu()

u32 divmodu ( u32 op1,
u16 op2 )

Direct divu instruction (unsigned 32/16=16:16) access using inline assembly to process op1/op2 operation and op1op2 at same time.

Parameters
op1first operand - dividende (32 bit)
op2second operand - divisor (16 bit)
Returns
16 bit (unsigned) result of the division in low 16 bit (0-15) and 16 bit (unsigned) result of the modulo operation in high 16 bit (16-31)

◆ divs()

s16 divs ( s32 op1,
s16 op2 )

Direct divs instruction (signed 32/16=16:16) access using inline assembly to process op1/op2 operation.

Parameters
op1first operand (32 bit)
op2second operand (16 bit)
Returns
16 bit (signed) result of the division

◆ divu()

u16 divu ( u32 op1,
u16 op2 )

Direct divu instruction (unsigned 32/16=16:16) access using inline assembly to process op1/op2 operation.

Parameters
op1first operand - dividende (32 bit)
op2second operand - divisor (16 bit)
Returns
16 bit (unsigned) result of the division

◆ F16_computePosition()

void F16_computePosition ( fix16 * x2,
fix16 * y2,
fix16 x1,
fix16 y1,
fix16 ang,
fix16 dist )

Compute the new position of the point defined by (x1, y1) by moving it by the given 'distance' in the 'angle' direction and store the result in (x2, y2).

Parameters
x2new X position
y2new Y position
x1current X position
y1current Y position
angangle in degree
distdistance to move

◆ F16_computePositionEx()

void F16_computePositionEx ( fix16 * x2,
fix16 * y2,
fix16 x1,
fix16 y1,
fix16 ang,
fix16 dist,
fix16 cosAdj,
fix16 sinAdj )

Compute the new position of the point defined by (x1, y1) by moving it by the given 'distance' in the 'angle' direction and store the result in (x2, y2).

Parameters
x2new X position
y2new Y position
x1current X position
y1current Y position
angangle in degree
distdistance to move
cosAdjcosine adjustment
sinAdjsine adjustment

◆ FF32_getLog2Fast()

fastfix32 FF32_getLog2Fast ( fastfix32 value)

Return a not accurate but fast log2 approximation of the specified value (fastfixed32) Ex:
getLog2(FASTFIX32(1)) = 0
getLog2(12345 << 16) = ~9.5 (real value = ~13.6)

Parameters
valuefastfixed32 value to return log2 of

◆ getApproximatedDistance()

u32 getApproximatedDistance ( s32 dx,
s32 dy )

Return euclidean distance approximation for specified vector.
The returned distance is not 100% perfect but calculation is fast.

Parameters
dxdelta X.
dydelta Y.

◆ getApproximatedDistanceV()

u32 getApproximatedDistanceV ( V2s32 * v)

Return euclidean distance approximation for specified vector.
The returned distance is not 100% perfect but calculation is fast.

Parameters
v2D vector.

◆ getLog2()

u16 getLog2 ( u32 value)

Return integer log2 of specified 32 bits unsigned value. Ex:
getLog2Int(1024) = 10
getLog2Int(12345) = 13

Parameters
valuevalue to return log2 of

◆ mods()

s16 mods ( s32 op1,
s16 op2 )

Direct divs instruction (signed 32/16=16:16) access using inline assembly.

Parameters
op1first operand (32 bit)
op2second operand (16 bit)
Returns
16 bit (signed) modulo result of the division

◆ modu()

u16 modu ( u32 op1,
u16 op2 )

Direct divu instruction (unsigned 32/16=16:16) access using inline assembly.

Parameters
op1first operand (32 bit)
op2second operand (16 bit)
Returns
16 bit (unsigned) modulo result of the division

◆ muls()

s32 muls ( s16 op1,
s16 op2 )

16x16=32 signed multiplication. Force GCC to use proper 68000 muls instruction.

Parameters
op1first operand
op2second operand
Returns
32 bit (signed) result of multiply

◆ mulu()

u32 mulu ( u16 op1,
u16 op2 )

16x16=32 unsigned multiplication. Force GCC to use proper 68000 mulu instruction.

Parameters
op1first operand
op2second operand
Returns
32 bit (unsigned) result of multiply

◆ sinFix16()

fix16 sinFix16 ( u16 value)

Compute sinus of specified value and return it as fix16.
The input value is an integer defined as [0..1024] range corresponding to radian [0..2PI] range.

◆ sinFix32()

fix32 sinFix32 ( u16 value)

Compute sinus of specified value and return it as fix32.
The input value is an integer defined as [0..1024] range corresponding to radian [0..2PI] range.

◆ u16ToBCD()

u32 u16ToBCD ( u16 value)

Convert u16 to BCD.

Parameters
valueu16 value to convert.

◆ u32ToBCD()

u32 u32ToBCD ( u32 value)

Convert u32 to BCD.

Parameters
valueu32 value to convert.

◆ V2D_F16_movePoint()

void V2D_F16_movePoint ( V2f16 * pt,
fix16 ang,
fix16 dist )

Move the given point by the given 'distance' in the 'angle' direction.

Parameters
ptpoint to move
angangle in degree
distdistance to move

◆ V2D_F16_movePointEx()

void V2D_F16_movePointEx ( V2f16 * pt,
fix16 ang,
fix16 dist,
fix16 cosAdj,
fix16 sinAdj )

Compute the new position of the point defined by (x1, y1) by moving it by the given 'distance' in the 'angle' direction and store the resultin (x2, y2).

Parameters
ptpoint to move
angangle in degree
distdistance to move
cosAdjcosine adjustment
sinAdjsine adjustment

◆ V2D_S32_getApproximatedDistance()

u32 V2D_S32_getApproximatedDistance ( V2s32 * v)

Return euclidean distance approximation for specified vector.
The returned distance is not 100% perfect but calculation is fast.

Parameters
v2D vector.