Module baby_emulator::core

source ·
Expand description

Contains the core models and emulation functionality.

Core emulation utilities

This module contains the emulator itself, this is in the form of BabyModel has fields corresponding to each register and memory location as what was on the original Manc Baby, this also has several methods for running a debugging the model.


The baby model has a new class that instantiates a completely blank model with all of its fields set to zero, if this was run, it would continuously perform jump instructions back to memory address 0.

use baby_emulator::core::BabyModel;
let model = BabyModel::new();

There are 2 ways to make a real runnable instances of the model, the baby model upon creation will load the first instruction as from the supplied memory (or the main store) and will continue fetching instructions from here, so you can instiantiate a model with a memory loaded with your own program code.

You can use BabyInstruction and BabyInstruction::to_numbers to more easily generate a [u32, 32] program stack.

use baby_emulator::core::BabyModel;
use baby_emulator::core::instructions::BabyInstruction;
let instrs = vec![
let main_store = BabyInstruction::to_numbers(instrs);
let model = BabyModel::new_with_program(main_store);

The other way is for quick demonstrations and that is to use BabyModel::new_example_program.


There are 2 methods used to run a model, each will execute one instruction at a time, calculate how the instruction will modify the models fields (including fetching the next instruction to the instruction register), and use this to generate and return a new model.

You can manually dispatch an instruction to the model by using one of the following methods, this is useful to see what each command does to the model:

You can also use BabyModel::execute this will execute the next instruction loaded from the memory, automatically getting the operand and calling the correct instruction method on the model.

Returning InstrResult that will either be the new model, or a BabyErrors detailing the error encountered (this can be simply encountering a stop command).

use baby_emulator::core::BabyModel;
use baby_emulator::core::errors::BabyError;
let model = BabyModel::new_example_program();
match model.execute() {
    Ok(m) => println!("{}", m.core_dump()),
    Err(e) => println!("Error {}", e.get_descriptor())

To run a model continuously until an error is encountered, you can use BabyModel::run_loop, this will call execute on each sucessive generated model until either an error is encountered (such as BabyErrors::Stop) or the specified iterations limmit is hit.

Returns a tuple of the last model state and the error encountered.

use baby_emulator::core::BabyModel;
use baby_emulator::core::errors::BabyErrors;
use baby_emulator::core::errors::BabyError;
let model = BabyModel::new_example_program();
match model.run_loop(100) {
    (model, BabyErrors::Stop(_)) => println!("{}", model.core_dump()),
    (_, err) => println!("{}", err.get_descriptor())


  • Contains potential errors thrown during emulation.
  • Contains models and functionality for decoding instructions.


  • The model containing the data in all the registers and memory to be operated upon.


  • The number of words in the memory used globally.

Type Aliases