pub struct VM {
Show 14 fields pub registers: [u8; 9], pub pc: u16, pub memory: [u8; 65536], pub ram_banks: Vec<[u8; 4200]>, pub code_banks: Vec<[u8; 4200]>, pub save_banks: Vec<[u8; 4096]>, pub controller_graphics_banks: Vec<[u8; 88]>, pub save_dirty_flag: [bool; 16], pub atlas_banks: Vec<[u8; 4000]>, pub error: Option<String>, pub halted: bool, pub op_executed: usize, pub cycles_executed: usize, pub sound: Sound, /* private fields */
}

Fields

registers: [u8; 9]

Order is AH, AL, BH, BL, CH, CL, DH, DL, FLG Extended registers (AX, BX, etc) are made of H+L, i.e. AX is [AH,AL]

pc: u16

Program Counter, address/index of byte currently being executed

memory: [u8; 65536]

All changes MUST go through debug_set_mem or debug_set_mem_range otherwise banks won’t change, etc

ram_banks: Vec<[u8; 4200]>code_banks: Vec<[u8; 4200]>save_banks: Vec<[u8; 4096]>controller_graphics_banks: Vec<[u8; 88]>save_dirty_flag: [bool; 16]

if a flag is true, then the matching data in save_banks should be written to disk and the flag set to false (also, if memory[SAVE_CONTROL] & AUTO_SAVE is 0, then memory[SAVE_CONTROL] should set to 0)

atlas_banks: Vec<[u8; 4000]>error: Option<String>

error message from EHALT

halted: bool

if true the VM has stopped (EoF or error) and can’t continue

op_executed: usize

Count of operations executed this session

cycles_executed: usize

Count of cycles executed this session

sound: Sound

Implementations

Word memory access

Get number in memory at address Returns the value and cycles used

Byte memory access

Get number in memory at address Returns the value and cycles used

Word register access

Get number in word reg, ignoring any addressing Returns the value and cycles used

Write number in word reg, ignoring any addressing Returns the cycles used

Get number from word reg, either if direct, the value in the reg if indirect, the value in memory at the address in the reg Returns the value and cycles used

Write to register, either if direct, the value in the reg if indirect, the value in memory at the address in the reg Returns the cycles used

Byte register access

Get number in word reg, ignoring any addressing Returns the value and cycles used

Write number in word reg, ignoring any addressing Returns the cycles used

Get number from word reg, either if direct, the value in the reg if indirect, the value in memory at the address in the reg Returns the value and cycles used

Write to register, either if direct, the value in the reg if indirect, the value in memory at the address in the reg Returns the cycles used

ADDR WORD

ADDR BYTE

REG, NUM BYTE

REG, NUM WORD

REG, REG BYTE

REG, REG WORD

Execute op with params Returns true if op has adjusted PC (and so VM shouldn’t automatically advance) and cycles

Jump based on flag state If flag state matches required then jump

Jump based on flag state If flag state matches required then jump

Jump based on flag state If flag state matches required then jump

Jump based on flag state If flag state matches required then jump

Run Pre Inc/Dec on register Also check and read bytes for index addressing Returns address offset and cycle cost

Create a new VM Requires an AudioPlayer, as an example see maikor-interface

Create an instance with a dummy audio player for testing

Load game This only copies data to banks, it doesn’t reset PC, registers, etc Call VM::init() once before any VM::step() calls

Loads initial banks and setup sound This should be called after load_game() and any needed changes are made Once this has been called the banks and memory shouldn’t be changed by the host (except for setting flags, interrupts, etc)

Public interface to VM

Advance VM one operation

If this fails (invalid register, etc) then VM::halted will be set to true

returns number of cycles used

Attempt to trigger the interrupt that matches interrupt_id VM will halt if the id is invalid

Run arbitrary op, does not advance PC automatically (JMP, etc ops still work) This works by writing the bytes to a section of reserved and setting the PC to there

Writes registers to String

Set one byte in memory This will trigger interrupts, bank switching, etc

Set bytes in memory This will trigger interrupts, bank switching, etc

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.