Macros

Helper macros

Abs8

Get absolute value of a signed 8-bits integer

Abs16

Get absolute value of a signed 16-bits integer

Abs32

Get absolute value of a signed 32-bits integer

Invert

Invert sign of a signed integer

Merge44

Merge two 4 bits value into a 8 bits integer

Merge88

Merge two 8 bits value into a 16 bits integer

ModuloPow2

Get the power-of-2 modulo of a integer (ie. "MOD_POW2(100, 32)")

Clamp8

Clamp a 8-bits value into a interval

Clamp16

Clamp a 16-bits value into a interval

Max

Find highest value

Min

Find lowest value

Quick math

Quick math routines

Math_Div10
i8 Math_Div10(
i8 val
) __FASTCALL __PRESERVES(a, b, c, iyl, iyh)

8-bits fast 10 times division

Parameters
val
i8

Value to divide by 10

Return

val / 10

Math_Div10_16b
i16 Math_Div10_16b(
i16 val
) __FASTCALL __PRESERVES(b, d, e, iyl, iyh)

16-bits fast 10 times division

Parameters
val
i16

Value to divide by 10

Return

val / 10

Math_Mod10
u8 Math_Mod10(
u8 val
) __PRESERVES(b, c, d, e, iyl, iyh)

8-bits fast modulo-10

Parameters
val
u8

Value to module by 10

Return

val % 10

Math_Mod10_16b
u8 Math_Mod10_16b(
u16 val
) __FASTCALL __PRESERVES(b, c, d, e, iyl, iyh)

16-bits fast modulo-10

Parameters
val
u16

Value to module by 10

Return

val % 10

Math_Flip
u8 Math_Flip(
u8 val
) __PRESERVES(c, d, e, h, l, iyl, iyh)

Bits flip routine

Parameters
val
u8

Value to flip

Return

Bits flipped value

Math_Flip_16b
u16 Math_Flip_16b(
u16 val
) __PRESERVES(c, iyl, iyh)

Bits flip routine

Parameters
val
u16

Value to flip

Return

Bits flipped value

Math_Negative
inline i8 Math_Negative(
i8 val
)

Get the negative (additive inverse) of a 8-bit register

Math_Negative16
i16 Math_Negative16(
i16 val
) __FASTCALL __PRESERVES(b, c, d, e, iyl, iyh)

Get the negative (additive inverse) of a 16-bit register

Math_Swap
u16 Math_Swap(
u16 val
) __PRESERVES(a, b, c, iyl, iyh)

Swap MSB and LSB bytes

Math_SignedDiv2
i8 Math_SignedDiv2(
i8 val
) __naked __PRESERVES(b, c, d, e, h, l, iyl, iyh)

Divide a signed 8-bits integer by 2 using shift

Math_SignedDiv4
i8 Math_SignedDiv4(
i8 val
) __naked __PRESERVES(b, c, d, e, h, l, iyl, iyh)

Divide a signed 8-bits integer by 4 using shift

Math_SignedDiv8
i8 Math_SignedDiv8(
i8 val
) __naked __PRESERVES(b, c, d, e, h, l, iyl, iyh)

Divide a signed 8-bits integer by 8 using shift

Math_SignedDiv16
i8 Math_SignedDiv16(
i8 val
) __naked __PRESERVES(b, c, d, e, h, l, iyl, iyh)

Divide a signed 8-bits integer by 16 using shift

Math_SignedDiv32
i8 Math_SignedDiv32(
i8 val
) __naked __PRESERVES(b, c, d, e, h, l, iyl, iyh)

Divide a signed 8-bits integer by 32 using shift

Math_Abs
inline u8 Math_Abs(
i8 val
)

Get absolute value of a signed 8-bits integer

Math_Abs_16b
inline u16 Math_Abs_16b(
i16 val
)

Get absolute value of a signed 16-bits integer

Math_Abs_32b
inline u32 Math_Abs_32b(
i32 val
)

Get absolute value of a signed 32-bits integer

Random

Random routines

Math_SetRandomSeed8
void Math_SetRandomSeed8(
u8 seed
)

Initialize random generator seed

Parameters
seed
u8

Initial seed value for the generator

Math_GetRandom8
u8 Math_GetRandom8()

Generates 8-bit pseudorandom numbers

Return

A pseudorandom value between 0 and 255.  (Maximum value is 127 for RANDOM_8_REGISTER and RANDOM_8_RACC methods)

Math_GetRandomMax8
inline u8 Math_GetRandomMax8(
u8 max
)

Generates 8-bit pseudorandom numbers between 0 and max-1 value.

Parameters
max
u8

Maximum value of the pseudorandom number (not included in the range).

Return

A pseudorandom value between 0 and max-1.

Math_GetRandomRange8
inline u8 Math_GetRandomRange8(
u8 min,
u8 max
)

Generates 8-bit pseudorandom numbers between min and max-1 value.

Parameters
min
u8

Minimum value of the pseudorandom number.

max
u8

Maximum value of the pseudorandom number (not included in the range).

Return

A pseudorandom value between min and max-1.

Math_SetRandomSeed16
void Math_SetRandomSeed16(
u16 seed
)

Initialize random generator seed

Parameters
seed
u16

Initial seed value for the generator

Math_GetRandom16
u16 Math_GetRandom16() __FASTCALL

Generates 16-bit pseudorandom numbers

Return

A pseudorandom value between 0 and 65535.

Math_GetRandomMax16
inline u16 Math_GetRandomMax16(
u16 max
)

Generates 16-bit pseudorandom numbers between 0 and max-1 value.

Parameters
max
u16

Maximum value of the pseudorandom number (not included in the range).

Return

A pseudorandom value between 0 and max-1.

Math_GetRandomRange16
inline u16 Math_GetRandomRange16(
u16 min,
u16 max
)

Generates 16-bit pseudorandom numbers between min and max-1 value.

Parameters
min
u16

Minimum value of the pseudorandom number.

max
u16

Maximum value of the pseudorandom number (not included in the range).

Return

A pseudorandom value between min and max-1.