Gb

Struct Gb 

Source
pub struct Gb<E: Executor = DirectExecutor> {
    pub cpustate: Gbz80State,
    pub mmu: Box<GbMmu>,
    pub button_states: ButtonStates,
    pub serial: SerialState,
    pub timer: TimerState,
    pub apu: ApuState,
    pub ppu: PpuState,
    /* private fields */
}
Expand description

Represents a “real” gameboy, by explicitly using the GbMmu for memory.

Fields§

§cpustate: Gbz80State

State of the CPU in the system.

§mmu: Box<GbMmu>

MMU for the system.

§button_states: ButtonStates

Joypad button states

§serial: SerialState

State of serial data transfer.

§timer: TimerState

State of timer updates

§apu: ApuState

State of audio rendering

§ppu: PpuState

State of video rendering

Implementations§

Source§

impl Gb

Source

pub fn new(bios: BiosRom, cart: Cartridge) -> Self

Create a Gb with the given bios and cartridge, using the default executor.

Source§

impl Gb<MicrocodeExecutor>

Source

pub fn new_microcode(bios: BiosRom, cart: Cartridge) -> Self

Create a Gb with the given bios and cartridge, using the microcode executor

Source§

impl Gb<DirectExecutorV2>

Source

pub fn new_v2(bios: BiosRom, cart: Cartridge) -> Self

Create a Gb with the given bios and cartridge, using the V2 direct executor.

Source§

impl Gb<SteppingExecutor>

Source

pub fn new_stepping(bios: BiosRom, cart: Cartridge) -> Self

Create a Gb with the given bios and cartridge, using the stepping executor

Source§

impl<E> Gb<E>
where E: Executor, E::State: Default,

Source

pub fn for_executor(bios: BiosRom, cart: Cartridge) -> Self

Create a Gb with the given bios and cartridge, using the executor specified by this type. Works for executors with state types that implement Default.

Source§

impl<E: Executor> Gb<E>

Source

pub fn for_config<C>(bios: BiosRom, cart: Cartridge, config: &C) -> Self
where C: ExecutorConfig<Executor = E>,

Create a Gb with the given bios and cartridge, using the provided config to create the initial state of the executor.

Source

pub fn tick(&mut self)

Tick forward by one instruction, executing background and graphics processing operations as needed.

Source

pub fn set_sample_rate(&mut self, sample_rate: u32)

Set the sample rate for the APU.

Source

pub fn display_ready(&self) -> bool

Returns true if the PPU finished a frame this tick and the display is ready to be sent out.

Source

pub fn get_ready_frame(&self) -> Option<&[(u8, u8, u8)]>

If the display is ready, get a reference to the PPU frame buffer.

Source

pub fn elapsed_mcycles(&self) -> u64

Get the total number of mcycles elapsed since emulator start.

Source

pub fn elapsed_time(&self) -> Duration

Get the total duration since the emulator started (based on the number of m-cycles elapsed.

Trait Implementations§

Source§

impl<E: Executor> ApuContext for Gb<E>

Source§

fn apu(&self) -> &ApuState

Source§

fn apu_mut(&mut self) -> &mut ApuState

Source§

fn apu_regs(&self) -> &ApuRegs

Source§

fn apu_regs_mut(&mut self) -> &mut ApuRegs

Source§

impl<E: Clone + Executor> Clone for Gb<E>
where E::State: Clone,

Source§

fn clone(&self) -> Gb<E>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<E: Executor> CpuContext for Gb<E>

Source§

fn cpu(&self) -> &Gbz80State

Gets the CPU state.
Source§

fn cpu_mut(&mut self) -> &mut Gbz80State

Gets a mutable reference to the CPU state.
Source§

impl<E: Debug + Executor> Debug for Gb<E>
where E::State: Debug,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<E: Executor> ExecutorContext for Gb<E>

Source§

type State = <E as Executor>::State

Source§

fn executor(&self) -> &E::State

Get the state of the executor.
Source§

fn executor_mut(&mut self) -> &mut E::State

Mutably gets the state of the executor.
Source§

fn yield1m(&mut self)

Yields from CPU execution for 1 M clock cycle (4 T). This callback should step the clock forward and perform any work that needs to happen faster than instructions execute. Warning: It is undefined behavior to call tick again during a context yield.
Source§

impl<E: Executor> InputContext for Gb<E>

Source§

fn button_states(&self) -> ButtonStates

get the button state
Source§

fn set_button_states(&mut self, button_states: ButtonStates)

set the button state
Source§

fn button_reg(&self) -> ButtonRegister

Get the value of the button register.
Source§

fn set_button_reg(&mut self, buttons: ButtonRegister)

Set the value of the button register.
Source§

impl<E: Executor> InterruptContext for Gb<E>

Source§

type Interrupts = <GbMmu as InterruptContext>::Interrupts

The type which provides access to the interrupts.
Source§

fn interrupts(&self) -> &Self::Interrupts

Provides read access to the interrupt flags.
Source§

fn interrupts_mut(&mut self) -> &mut Self::Interrupts

Provides write-access to the interrupt flags.
Source§

impl<E: Executor> MemContext for Gb<E>

Source§

type Mem = GbMmu

Type of MemDevice in this context.
Source§

fn mem(&self) -> &Self::Mem

Gets the memory.
Source§

fn mem_mut(&mut self) -> &mut Self::Mem

Get a mutable reference to the memory.
Source§

impl<E: Executor> PpuContext for Gb<E>

Source§

fn ppu(&self) -> &PpuState

Get the ppu state.
Source§

fn ppu_mut(&mut self) -> &mut PpuState

Get mutable access to the ppu state.
Source§

fn ppu_regs(&self) -> &PpuRegs

Source§

fn ppu_regs_mut(&mut self) -> &mut PpuRegs

Source§

fn vram(&self) -> &Vram

Source§

fn vram_mut(&mut self) -> &mut Vram

Source§

fn oam(&self) -> &Oam

Source§

fn oam_mut(&mut self) -> &mut Oam

Source§

fn display_ready(&mut self)

Source§

impl<E: Executor> SaveData for Gb<E>

Source§

fn write_save_data(&self, writer: impl Write) -> Result<(), Error>

Source§

fn load_save_data(&mut self, reader: impl Read) -> Result<(), Error>

Source§

fn has_save_data(&self) -> bool

Source§

impl<E: Executor> SerialContext for Gb<E>

Source§

fn serial(&self) -> &SerialState

Get the serial state.
Source§

fn serial_mut(&mut self) -> &mut SerialState

Get mutable access to the serial state.
Source§

fn serial_regs(&self) -> &SerialRegs

Source§

fn serial_regs_mut(&mut self) -> &mut SerialRegs

Source§

impl<E: Executor> TimerContext for Gb<E>

Source§

fn timer(&self) -> &TimerState

Get the timer state.
Source§

fn timer_mut(&mut self) -> &mut TimerState

Get mutable access to the timer state.
Source§

fn timer_regs(&self) -> &TimerRegs

Source§

fn timer_regs_mut(&mut self) -> &mut TimerRegs

Auto Trait Implementations§

§

impl<E> Freeze for Gb<E>
where <E as Executor>::State: Freeze,

§

impl<E> RefUnwindSafe for Gb<E>
where <E as Executor>::State: RefUnwindSafe,

§

impl<E> Send for Gb<E>
where <E as Executor>::State: Send,

§

impl<E> Sync for Gb<E>
where <E as Executor>::State: Sync,

§

impl<E> Unpin for Gb<E>
where <E as Executor>::State: Unpin,

§

impl<E> UnwindSafe for Gb<E>
where <E as Executor>::State: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.