pub trait Platform {
// Required methods
fn get_time_microseconds(&self) -> u64;
fn capture_keyboard(&mut self);
fn reset_keyboard(&mut self);
fn mini_sleep(&self);
fn is_kb_hit(&mut self) -> i32;
fn read_kb_byte(&mut self) -> i32;
}Expand description
Host platform interface used by the emulator for time, I/O, and sleep.
Every method has a clear contract so implementors know exactly what is expected. The emulator will call these frequently — keep them cheap.
Required Methods§
Sourcefn get_time_microseconds(&self) -> u64
fn get_time_microseconds(&self) -> u64
Current time in microseconds.
The emulator uses this to compute elapsed_us between step calls,
which drives the CLINT timer. The value does not need to be an absolute
epoch; only the difference between two calls matters.
Sourcefn capture_keyboard(&mut self)
fn capture_keyboard(&mut self)
Put the terminal into raw mode (no echo, no line buffering).
Called once at startup so individual keystrokes reach the emulated guest without the host OS buffering them.
Sourcefn reset_keyboard(&mut self)
fn reset_keyboard(&mut self)
Restore the terminal to its original (canonical) mode.
Called when the emulator exits, typically via a Drop guard.
Sourcefn mini_sleep(&self)
fn mini_sleep(&self)
Sleep briefly to avoid burning CPU while the guest is in WFI.
The duration is intentionally short (< 1 ms) — the goal is to yield the host scheduler, not to sleep for a fixed wall-clock period.
Sourcefn read_kb_byte(&mut self) -> i32
fn read_kb_byte(&mut self) -> i32
Read one byte from stdin.
Only call this after is_kb_hit returns 1. Returns the byte as a
positive i32, or -1 on error/EOF.