pub enum Opcode {
Show 71 variants Nop, Stop, Halt, StoreImm16(Register16, u16), StoreImm8(Register8, u8), StoreAToHlAddr(bool), LoadAFromHlAddr(bool), StoreATo16(Register16), LoadAFromReg16Addr(Register16), Mov8(Register8, Register8), Jr(Option<Flag>, u8), Jp(Option<Flag>, u16), Inc8(Register8), Dec8(Register8), Inc16(Register16), Dec16(Register16), Push(Register16), Pop(Register16), Add(Register8), Adc(Register8), Sub(Register8), Sbc(Register8), And(Register8), Xor(Register8), Or(Register8), Cp(Register8), Add8(u8), Adc8(u8), Sub8(u8), Sbc8(u8), And8(u8), Xor8(u8), Or8(u8), Cp8(u8), AddSp8(u8), Daa, Scf, Cpl, Ccf, Rlca, Rla, Rrca, Rra, StoreImm16AddrSp(u16), AddHl(Register16), Ret(Option<Flag>), Reti, Di, Ei, Call(Option<Flag>, u16), JpHl, Rst(u8), LdHlSp8(i8), LdSpHl, StoreHA(u8), LoadHA(u8), StoreCA, LoadCA, StoreAAtAddress(u16), LoadAFromAddress(u16), Rlc(Register8), Rrc(Register8), Rr(Register8), Rl(Register8), Sla(Register8), Sra(Register8), Swap(Register8), Srl(Register8), Bit(u8, Register8), Res(u8, Register8), Set(u8, Register8),
}
Expand description

The instructions of the Gameboy.

The naming tends to be of the form: ActionDestSrc when there is ambiguity.

For example, Opcode::StoreImm16AddrSp means that the SP register should be stored at the address specified by the immediate 16 bit value.

These docs don’t intend to include complete explanations of the instructions, though the comments below may provide a basic overview.

Variants§

§

Nop

No operation.

§

Stop

The Gameboy enters a very low-power STOP state, graphics will not continue to draw.

§

Halt

The Gameboy enters a low-power HALT state.

§

StoreImm16(Register16, u16)

Store an immediate value into a 16 bit register.

§

StoreImm8(Register8, u8)

Store an immediate value into an 8 bit register.

§

StoreAToHlAddr(bool)

Store A at (HL) and increment or decrement HL; true means inc

§

LoadAFromHlAddr(bool)

Load A from (HL) and increment or decrement HL; true means inc

§

StoreATo16(Register16)

Store A to the value pointed at by register 16 (must be BC or DE)

§

LoadAFromReg16Addr(Register16)

Loads A from value pointed at by register 16 (must be BC or DE)

§

Mov8(Register8, Register8)

§

Jr(Option<Flag>, u8)

Relative jump based on flag to offset

§

Jp(Option<Flag>, u16)

Jump based on flag to offset

§

Inc8(Register8)

Increment an 8 bit regsiter.

§

Dec8(Register8)

Decrement an 8 bit regsiter.

§

Inc16(Register16)

Increment a 16 bit regsiter.

§

Dec16(Register16)

Decrement a 16 bit regsiter.

§

Push(Register16)

Push the value in the given register onto the stack.

§

Pop(Register16)

Pop a value off the stack and load it into the given register.

§

Add(Register8)

Add the given regsiter to the A.

§

Adc(Register8)

Add the given regsiter to the A with carry.

§

Sub(Register8)

Subtract the given regsiter from the A.

§

Sbc(Register8)

Subtract the given regsiter from the A with carry.

§

And(Register8)

Bitwise AND the given register with the A.

§

Xor(Register8)

Bitwise XOR the given register with the A.

§

Or(Register8)

Bitwise OR the given register with the A.

§

Cp(Register8)

Compare the value of the given register with the A and set flags.

§

Add8(u8)

Add an immediate value to the A.

§

Adc8(u8)

Add an immediate value to the A with carry.

§

Sub8(u8)

Subtract an immediate value from the A.

§

Sbc8(u8)

Subtract an immediate value from the A with carry.

§

And8(u8)

Bitwise AND an immediate value with the A.

§

Xor8(u8)

Bitwise XOR an immediate value with the A.

§

Or8(u8)

Bitwise OR an immediate value with the A.

§

Cp8(u8)

Compare the immediate value with the A and set flags.

§

AddSp8(u8)

Add the immediate value to the Program Counter and load it into SP. TODO: check this explanation

§

Daa

Converts the value in A to its BCD form. TODO: double check this

§

Scf

TODO: document this

§

Cpl

Bitwise negate the value in the A.

§

Ccf

TODO: document this (inverse of SCF?)

§

Rlca

Rotate A left.

§

Rla

Rotate A left through carry.

§

Rrca

Rotate A right.

§

Rra

Rotate A right through carry.

§

StoreImm16AddrSp(u16)

Stores SP at pointer given by immediate 16.

§

AddHl(Register16)

Adds a value to HL.

§

Ret(Option<Flag>)

Conditionally adjusts the program counter and updates the stack pointer.

§

Reti

Non-conditional Ret that also enables interrupts.

§

Di

Disable interrupts.

§

Ei

Enable interrupts.

§

Call(Option<Flag>, u16)

Conditionally update push the program counter onto the stack and adjusts the program counter.

§

JpHl

Gets the value at memory address HL and jumps to it.

§

Rst(u8)

Contains eight possible values: between 0-8. Value should be multplied by 8 to determine the reset location. TODO: consider simplifying this

§

LdHlSp8(i8)

HL = SP + (PC + i8). TODO: double check behavior of relative parameters.

§

LdSpHl

Load the value of HL into SP.

§

StoreHA(u8)

stores A in (u8)

§

LoadHA(u8)

loads A from (u8)

§

StoreCA

stores A in (C)

§

LoadCA

Loads A from (C)

§

StoreAAtAddress(u16)

LD (a16), A

§

LoadAFromAddress(u16)

LD A, (a16)

§

Rlc(Register8)

0xCB instructions

Rotate register left.

§

Rrc(Register8)

Rotate register right.

§

Rr(Register8)

Rotate register right through carry.

§

Rl(Register8)

Rotate register left through carry.

§

Sla(Register8)

Arithmetic left shift on given register.

§

Sra(Register8)

Arithmetic right shift on given register.

§

Swap(Register8)

Swap low and high nibble (4 bits).

§

Srl(Register8)

Logical Right shift on given register.

§

Bit(u8, Register8)

Set flags based on the given bit in register. u8 is number between 0 and 7 (inclusive).

§

Res(u8, Register8)

Reset the given bit in the register. u8 is number between 0 and 7 (inclusive)

§

Set(u8, Register8)

Set the given bit in the register. u8 is number between 0 and 7 (inclusive)

Trait Implementations§

source§

impl Clone for Opcode

source§

fn clone(&self) -> Opcode

Returns a copy 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 Debug for Opcode

source§

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

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

impl Hash for Opcode

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq<Opcode> for Opcode

source§

fn eq(&self, other: &Opcode) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for Opcode

source§

impl Eq for Opcode

source§

impl StructuralEq for Opcode

source§

impl StructuralPartialEq for Opcode

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.