use core::cmp::Ordering;
use crate::pac::kernal::{AllTerms, OddTerms, Polynomial, F40};
extern "C" {
fn basic_facinx() -> i16;
fn basic_givayf(value: i16);
fn basic_fadd(addr: *const u8);
fn basic_faddt();
fn basic_movfm(addr: *const u8);
fn basic_movmf(addr: *mut u8);
fn basic_movaf() -> u8;
fn basic_movfa() -> u8;
fn basic_fcomp(addr: *const u8) -> i8;
fn basic_qint();
fn basic_fout() -> *const i8;
fn basic_negop();
}
pub const IDENTIFIER: *const [u8; 8] = 0xa004 as *const _;
pub const LOG_CONSTANTS: *const LogConstants = 0xb9bc as *const _;
#[repr(C, packed)]
pub struct LogConstants {
pub one: F40,
pub logcn2: Polynomial<OddTerms, 4>,
pub root_2_over_2: F40,
pub root_2: F40,
pub neg_0_point_5: F40,
}
pub const EXP_CONSTANTS: *const ExpConstants = 0xbfbf as *const _;
#[repr(C, packed)]
pub struct ExpConstants {
pub one_over_ln_2: F40,
pub two_pow_x: Polynomial<AllTerms, 8>,
}
#[inline]
pub unsafe fn facinx() -> i16 {
unsafe { basic_facinx() }
}
#[inline]
pub unsafe fn givayf(value: i16) {
unsafe { basic_givayf(value) }
}
#[inline]
pub unsafe fn fadd(value: *const F40) {
unsafe { basic_fadd(value as _) }
}
#[inline]
pub unsafe fn faddt() {
unsafe { basic_faddt() }
}
#[inline]
pub unsafe fn movfm(value: *const F40) {
unsafe { basic_movfm(value as _) }
}
#[inline]
pub unsafe fn movmf(value: *mut F40) {
unsafe { basic_movmf(value as _) }
}
#[inline]
pub unsafe fn movaf() -> u8 {
unsafe { basic_movaf() }
}
#[inline]
pub unsafe fn movfa() -> u8 {
unsafe { basic_movfa() }
}
#[inline]
pub unsafe fn fcomp(value: *const F40) -> Ordering {
let ret = unsafe { basic_fcomp(value as _) };
match ret {
1 => Ordering::Greater,
0 => Ordering::Equal,
-1 => Ordering::Less,
_ => unreachable!(),
}
}
#[inline]
pub unsafe fn qint() {
unsafe { basic_qint() }
}
#[inline]
pub unsafe fn fout() -> *const i8 {
unsafe { basic_fout() }
}
#[inline]
pub unsafe fn negop() {
unsafe { basic_negop() }
}