summary refs log tree commit diff
path: root/src/instruction.rs
diff options
context:
space:
mode:
authorSophie Forrest <57433227+sophieforrest@users.noreply.github.com>2024-01-13 19:17:57 +1300
committerSophie Forrest <57433227+sophieforrest@users.noreply.github.com>2024-01-13 19:17:57 +1300
commit13becb31e8b669dd6254c68b3aae110e7711d9db (patch)
treef4320bc6c0e86064291ac29f4dfaddb8fbb3f376 /src/instruction.rs
chore: init project
Diffstat (limited to '')
-rw-r--r--src/instruction.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/instruction.rs b/src/instruction.rs
new file mode 100644
index 0000000..2744048
--- /dev/null
+++ b/src/instruction.rs
@@ -0,0 +1,51 @@
+//! Implementation of instructions for MOS 6502.
+
+/// List of all instructions for MOS 6502.
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+pub enum Instruction {
+	/// Load accumulator.
+	Lda,
+}
+
+/// Addressing modes for MOS 6502.
+#[derive(Clone, Copy, Debug)]
+pub enum AddressingMode {
+	/// Immediate mode
+	Immediate,
+
+	/// Zero Page mode
+	ZeroPage,
+
+	/// ZeroPage.X mode
+	ZeroPageX,
+}
+
+/// Operation retrieved from decoding an opcode.
+pub struct Operation {
+	/// [`AddressingMode`]
+	pub addressing_mode: AddressingMode,
+
+	/// [`Instruction`]
+	pub instruction: Instruction,
+}
+
+impl Operation {
+	/// Creates a new operation from the `instruction` and `addressing_mode`.
+	pub const fn new(instruction: Instruction, addressing_mode: AddressingMode) -> Self {
+		Self {
+			addressing_mode,
+			instruction,
+		}
+	}
+}
+
+/// Gets the operation from the passed in opcode. Returns [`None`] if no
+/// operation exists.
+pub const fn get_operation(opcode: u8) -> Option<Operation> {
+	match opcode {
+		0xA5 => Some(Operation::new(Instruction::Lda, AddressingMode::ZeroPage)),
+		0xA9 => Some(Operation::new(Instruction::Lda, AddressingMode::Immediate)),
+		0xB5 => Some(Operation::new(Instruction::Lda, AddressingMode::ZeroPageX)),
+		_ => None,
+	}
+}