Enum gameboy_rom::opcodes::Opcode
source · 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)