Skip to content

Commit

Permalink
add tick
Browse files Browse the repository at this point in the history
  • Loading branch information
commonkestrel committed Dec 20, 2023
1 parent 251a550 commit 5f0bb8d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions fateful_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ pub fn peripheral(attr: TokenStream, item: TokenStream) -> TokenStream {
<#ident as fateful_peripheral::Peripheral>::write(&mut boxed, n, data);
}

#[no_mangle]
pub unsafe extern "C" fn stateful_tick(state: *mut ::std::ffi::c_void) {
let mut boxed = ::std::mem::ManuallyDrop::new(::std::boxed::Box::from_raw(state as *mut #ident));
<#ident as fateful_peripheral::Peripheral>::tick(&mut boxed);
}

#[no_mangle]
pub unsafe extern "C" fn stateful_drop(state: *mut ::std::ffi::c_void) {
let boxed = ::std::boxed::Box::from_raw(state as *mut #ident);
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ pub trait Peripheral: Sized {
/// where `ports` is the `ports` argument in [`init`](Peripheral::init)
fn write(&mut self, port: u8, data: u8) {}

/// Called every time the CPU clock ticks (falling-edge).
fn tick(&mut self) {}

/// Called whenever the CPU in the emulator is reset.
///
/// Implementors should make sure that the peripheral state
Expand Down

0 comments on commit 5f0bb8d

Please sign in to comment.