Skip to main content

Engine

Struct Engine 

Source
pub struct Engine { /* private fields */ }
Expand description

The protocol’s state machine (see the module docs).

Implementations§

Source§

impl Engine

Source

pub fn new(host: &'static str, pacing: Pacing) -> Engine

An engine with no machine yet, for the host called host, paced as pacing says.

Source

pub fn set_answer_recover(&mut self, on: bool)

Whether a cold boot’s “Try To Recover Memory?” (48SX, 48GX, 49G) is answered NO for the user, and the 49G’s “Memory Clear” after it dismissed (recover.rs): a host that keeps the user’s calculator (off by default; key scripts and tests answer it themselves).

Source

pub fn answering_recover(&self) -> bool

An answer to the boot’s question is still pending.

Source

pub fn set_auto_save(&mut self, on: bool)

Whether the host keeps states: then the machine’s state comes out as Output::Save once it changed and settled (off by default).

Source

pub fn auto_saves(&self) -> u64

Saves handed to the host so far.

Source

pub fn save_owed(&self) -> bool

A change is waiting to be saved.

Source

pub fn save_now(&mut self)

Hand out the owed save now, without the delay, if the machine has settled (a computing one is not saved: its last settled state is in the store). A host calls it before a boot, and stores what it gives before it reads or clears the slot: a model switch keeps the machine it leaves, a reboot of the same model restores the newest state, and a fresh start deletes the slot after this save, so the old machine never comes back.

Source

pub fn admit<'a>(&self, msg: &'a Value) -> Result<&'a str>

The protocol version check and the command’s name, refused while a send is typing if its Policy says so: what every command passes first, also those a host serves itself.

Source

pub fn refusal(&self, cmd: &str) -> Option<Error>

Why cmd is refused now, or None (an unknown name never is): the page holds the serial port and it is a write or a question to the server; a send is typing and it is refused_while_typing; a write runs and it uses the serial port.

Source

pub fn command( &mut self, clock: &dyn Clock, msg: &Value, bytes: Option<Vec<u8>>, reply: Option<u64>, )

One protocol message. bytes are its bytes field when the host has them apart from the JSON (the Worker’s rom and state); without them a state field is base64. With a reply tag the reply comes out as Output::Reply after the events the command caused (a send’s when it is done); without one an error comes out as an error event.

Source

pub fn answer( &mut self, clock: &dyn Clock, reply: Option<u64>, result: Result<Value>, )

Answer a command the host served itself: the events so far, then the reply (or, without a reply tag, an error event for an error).

Source

pub fn take_output(&mut self) -> Vec<Output>

The replies and events so far, in order.

Source

pub fn deadline(&self) -> Option<f64>

When Engine::timer is due on the host’s clock; None while only a message can change anything (paused, idle with nothing to watch).

Source

pub fn timer(&mut self, clock: &dyn Clock)

The host’s timer fired: run what is due (a send’s turn, a pass, a wake, a look at the memory).

Source

pub fn input(&mut self, clock: &dyn Clock)

Bytes arrived for the machine from outside (the serial bridge): a sleeping CPU first runs the time that passed, then sees when the UART wakes it.

Source

pub fn serial_open(&self) -> bool

The page holds the serial port (serialOpen).

Source

pub fn transferring(&self) -> bool

A write through the Kermit server runs (a /v1/memory write, a server probe): it owns the calculator’s UART, so a host’s own serial bridge leaves it alone until it ends.

Source

pub fn sending(&self) -> Option<u64>

The tag of the send in progress, if it has one.

Source

pub fn cancel_send(&mut self, clock: &dyn Clock, why: &str)

Stop the send in progress; its reply is the error why.

Source

pub fn status(&self) -> Status

What status says now.

Source

pub fn emulator_mut(&mut self) -> Option<&mut Emulator>

The machine, for what a host does beside the protocol (the serial bridge); None before a boot.

Source

pub fn emulator(&self) -> Result<&Emulator>

The machine, for the commands a host serves itself.

Source

pub fn into_emulator(self) -> Option<Emulator>

The machine, once the host is done with the engine.

Source

pub fn start(&mut self, clock: &dyn Clock, emu: Emulator, rom_name: &str)

Start running emu, a machine the host built (and perhaps ran) from the ROM file rom_name.

Source

pub fn poke( &mut self, clock: &dyn Clock, address: u32, nibbles: &[u8], ) -> Result<()>

Write nibbles from address on as CPU writes would (poke): the display may show it, the user memory may have changed, a sleeping CPU may see it.

Source

pub fn exclusive<T>( &mut self, clock: &dyn Clock, f: impl FnOnce(Machine) -> (Machine, Result<T, RunError>), ) -> Result<T>

Run f on the machine outside the pacing, as fast as the host can (a native key script), with every key released first; then follow the wall clock again from where it left the machine. f gets the machine and gives it back with its result. Refused during a send, as keyScript.

Source

pub fn boot( &mut self, clock: &dyn Clock, model: &str, rom: &[u8], rom_name: &str, ) -> Result<Booted>

Build model (a preference: a ROM that only fits another model boots that one) from rom and run it; the machine before keeps running if this one cannot be built.

Source

pub fn boot_restoring( &mut self, clock: &dyn Clock, model: &str, rom: &[u8], rom_name: &str, kept: Option<&[u8]>, ) -> Result<Booted>

Engine::boot, then restore kept, the state the host kept for this model, before the machine runs a cycle: the calculator is as it was, with no “Try To Recover Memory?”. A state that does not load (another ROM, another model, an older format) leaves the cold boot, and restore_error says why. The machine it replaces is not saved here: the host calls Engine::save_now and stores that save before it reads or clears the slot, so the slot it reads is the newest and a fresh start’s stays empty. An owed save left now is dropped.

Source

pub fn save_state(&self) -> Result<Vec<u8>>

The whole machine state (saveState).

Source

pub fn load_state(&mut self, clock: &dyn Clock, state: &[u8]) -> Result<()>

Restore a saved state of the same model and ROM (loadState); the host’s queued and held keys go with the old machine (Emulator::load_state). A state that does not load changes nothing, the keys held included.

Source

pub fn stats(&self, clock: &dyn Clock) -> Stats

Stats now.

Trait Implementations§

Source§

impl Debug for Engine

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Engine

§

impl !RefUnwindSafe for Engine

§

impl !Sync for Engine

§

impl Forget for Engine

§

impl Move for Engine

§

impl Send for Engine

§

impl Unpin for Engine

§

impl UnsafeUnpin for Engine

§

impl UnwindSafe for Engine

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.