37 lines
723 B
Rust
37 lines
723 B
Rust
|
|
||
|
#[repr(C)]
|
||
|
struct VB { _data: [u8; 0] }
|
||
|
|
||
|
#[link(name = "vb")]
|
||
|
extern "C" {
|
||
|
#[link_name = "vbInit"]
|
||
|
fn vb_init(sim: *mut VB) -> *mut VB;
|
||
|
|
||
|
#[link_name = "vbSizeOf"]
|
||
|
fn vb_size_of() -> usize;
|
||
|
|
||
|
#[link_name = "vbGetKeys"]
|
||
|
fn vb_get_keys(sim: *mut VB) -> u16;
|
||
|
}
|
||
|
|
||
|
pub struct CoreVB {
|
||
|
sim: *mut VB,
|
||
|
_data: Box<[u8]>,
|
||
|
}
|
||
|
|
||
|
impl CoreVB {
|
||
|
pub fn new() -> Self {
|
||
|
let size = unsafe { vb_size_of() };
|
||
|
let mut data = vec![0; size].into_boxed_slice();
|
||
|
let sim = data.as_mut_ptr() as *mut VB;
|
||
|
unsafe { vb_init(sim) };
|
||
|
CoreVB {
|
||
|
sim,
|
||
|
_data: data
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn keys(&self) -> u16 {
|
||
|
unsafe { vb_get_keys(self.sim) }
|
||
|
}
|
||
|
}
|