Enum Instruction

Source
#[non_exhaustive]
pub enum Instruction {
Show 49 variants Halt, Exit(Option<u8>), ScrollUp(u4), ScrollDown(u4), ScrollRight, ScrollLeft, Clear, Return, ToggleLoadStoreQuirk, LoRes, HiRes, CallMachineCode(u12), Jump(u12), Call(u12), SkipIfEqual(Register, Byte), SkipIfNotEqual(Register, Byte), Add(Register, Byte), Set(Register, Byte), Or(Register, Register), And(Register, Register), Xor(Register, Register), Sub(Register, Register), ShiftRight(Register, Register), ShiftLeft(Register, Register), SubReverse(Register, Register), SetIndex(u12), SetIndexLong(u16), JumpRelative(u12), Random(Register, u8), Draw(Register, Register, u4), SkipKey(Register), SkipNotKey(Register), LoadAudio, LoadDelay(Register), BlockKey(Register), SelectPlane(u4), SetPitch(Register), SetDelay(Register), SetSound(Register), AddRegisterToIndex(Register), FontCharacter(Register), BigFontCharacter(Register), Bcd(Register), Store(Register), Load(Register), StoreRange(Register, Register), LoadRange(Register, Register), StoreFlags(Register), LoadFlags(Register),
}
Expand description

CHIP-8 instructions.

This instruction set is mostly based on what Octo supports, which comprises the specifications for CHIP-8, SUPER-CHIP and XO-CHIP.

However, there is also support for some more esoteric instructions, especially where there are no collisions in the opcode space.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Halt

Halt the CHIP-8 interpreter.

Based on Octo’s behavior when encountering 0000.

§

Exit(Option<u8>)

Exit the CHIP-8 interpreter with an optional exit code.

Based on the following opcodes:

  • 00FD: Exit interpreter (from SUPER-CHIP 1.1)
  • 001N: Exit with exit code N (from chip8run)
§

ScrollUp(u4)

Scroll the display up.

Based on the following opcodes:

§

ScrollDown(u4)

Scroll the display down.

Based on the following opcode:

  • 00CN: Scroll down by N pixels
§

ScrollRight

Scroll the display right.

§

ScrollLeft

Scroll the display left.

§

Clear

Clear the display.

§

Return

Return from subroutine.

§

ToggleLoadStoreQuirk

Toggle the behavior of Instruction::Load and Instruction::Store

§

LoRes

Change display to low resolution (“lores”) mode, 64x32 pixels

§

HiRes

Change display to high resolution (“hires”) mode, 128x64 pixels

§

CallMachineCode(u12)

Call machine code routine.

§

Jump(u12)

Jump to memory address

§

Call(u12)

Call subroutine

§

SkipIfEqual(Register, Byte)

Skip the next instruction if

§

SkipIfNotEqual(Register, Byte)

§

Add(Register, Byte)

§

Set(Register, Byte)

§

Or(Register, Register)

§

And(Register, Register)

§

Xor(Register, Register)

§

Sub(Register, Register)

§

ShiftRight(Register, Register)

§

ShiftLeft(Register, Register)

§

SubReverse(Register, Register)

§

SetIndex(u12)

§

SetIndexLong(u16)

§

JumpRelative(u12)

§

Random(Register, u8)

§

Draw(Register, Register, u4)

Draw a sprite on the display.

§

SkipKey(Register)

§

SkipNotKey(Register)

§

LoadAudio

§

LoadDelay(Register)

§

BlockKey(Register)

§

SelectPlane(u4)

§

SetPitch(Register)

§

SetDelay(Register)

§

SetSound(Register)

§

AddRegisterToIndex(Register)

§

FontCharacter(Register)

§

BigFontCharacter(Register)

§

Bcd(Register)

§

Store(Register)

§

Load(Register)

§

StoreRange(Register, Register)

§

LoadRange(Register, Register)

§

StoreFlags(Register)

§

LoadFlags(Register)

Trait Implementations§

Source§

impl Clone for Instruction

Source§

fn clone(&self) -> Instruction

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 Debug for Instruction

Source§

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

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

impl Display for Instruction

Source§

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

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

impl<'_enum> From<&'_enum Instruction> for InstructionDiscriminants

Source§

fn from(val: &'_enum Instruction) -> InstructionDiscriminants

Converts to this type from the input type.
Source§

impl From<Instruction> for InstructionDiscriminants

Source§

fn from(val: Instruction) -> InstructionDiscriminants

Converts to this type from the input type.
Source§

impl From<Instruction> for Opcode

Source§

fn from(instruction: Instruction) -> Opcode

Converts to this type from the input type.
Source§

impl IntoEnumIterator for Instruction

Source§

impl PartialEq for Instruction

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<Opcode> for Instruction

Source§

type Error = DecodeError

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

fn try_from(op: Opcode) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy for Instruction

Source§

impl Eq for Instruction

Source§

impl StructuralPartialEq for Instruction

Auto Trait Implementations§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.