Skip to main content

Platform

Trait Platform 

Source
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§

Source

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.

Source

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.

Source

fn reset_keyboard(&mut self)

Restore the terminal to its original (canonical) mode.

Called when the emulator exits, typically via a Drop guard.

Source

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.

Source

fn is_kb_hit(&mut self) -> i32

Returns 1 if a key is waiting in stdin, 0 if not, -1 on EOF.

Source

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.

Implementors§