aboutsummaryrefslogtreecommitdiff
path: root/lib/xixanta/src/opcodes.rs
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2024-07-16 11:12:26 +0200
committerMiquel Sabaté Solà <mikisabate@gmail.com>2024-12-12 07:32:52 +0100
commit7822c00e8689c99ded0a360026f4e7ace1f2c87f (patch)
treee2bc22aeea0a172ee7aee5e4a2a4b603a495b9b8 /lib/xixanta/src/opcodes.rs
parentc6c9aa4e5f3e5a01fcb9ccabf6dbd2f6da277650 (diff)
downloadtools.nes-7822c00e8689c99ded0a360026f4e7ace1f2c87f.tar.gz
tools.nes-7822c00e8689c99ded0a360026f4e7ace1f2c87f.zip
Add support for branching
This is a bare bones implementation of it, and there's a lot of nuance that it's being missed, but at least the fundamentals have been implemented already. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib/xixanta/src/opcodes.rs')
-rw-r--r--lib/xixanta/src/opcodes.rs75
1 files changed, 58 insertions, 17 deletions
diff --git a/lib/xixanta/src/opcodes.rs b/lib/xixanta/src/opcodes.rs
index bca8104..a716545 100644
--- a/lib/xixanta/src/opcodes.rs
+++ b/lib/xixanta/src/opcodes.rs
@@ -20,7 +20,6 @@ pub struct Entry {
}
lazy_static! {
- // TODO
pub static ref INSTRUCTIONS: HashMap<String, HashMap<AddressingMode, ShortEntry>> = {
let mut instrs = HashMap::new();
@@ -57,9 +56,20 @@ lazy_static! {
asl.insert(AddressingMode::IndexedX, ShortEntry{ cycles: 7, size: 3, opcode: 0x1E, affected_on_page: false });
instrs.insert(String::from("asl"), asl);
- // BCC: TODO
- // BCS: TODO
- // BEQ: TODO
+ // bcc
+ let mut bcc = HashMap::new();
+ bcc.insert(AddressingMode::RelativeOrZeropage, ShortEntry{ cycles: 2, size: 2, opcode: 0x90, affected_on_page: true });
+ instrs.insert(String::from("bcc"), bcc);
+
+ // bcs
+ let mut bcs = HashMap::new();
+ bcs.insert(AddressingMode::RelativeOrZeropage, ShortEntry{ cycles: 2, size: 2, opcode: 0xB0, affected_on_page: true });
+ instrs.insert(String::from("bcs"), bcs);
+
+ // beq
+ let mut beq = HashMap::new();
+ beq.insert(AddressingMode::RelativeOrZeropage, ShortEntry{ cycles: 2, size: 2, opcode: 0xF0, affected_on_page: true });
+ instrs.insert(String::from("beq"), beq);
// bit
let mut bit = HashMap::new();
@@ -67,17 +77,35 @@ lazy_static! {
bit.insert(AddressingMode::Absolute, ShortEntry{ cycles: 4, size: 3, opcode: 0x2C, affected_on_page: false });
instrs.insert(String::from("bit"), bit);
- // BMI: TODO
- // BNE: TODO
- // BPL: TODO
+ // bmi
+ let mut bmi = HashMap::new();
+ bmi.insert(AddressingMode::RelativeOrZeropage, ShortEntry{ cycles: 2, size: 2, opcode: 0x30, affected_on_page: true });
+ instrs.insert(String::from("bmi"), bmi);
+
+ // bne
+ let mut bne = HashMap::new();
+ bne.insert(AddressingMode::RelativeOrZeropage, ShortEntry{ cycles: 2, size: 2, opcode: 0xD0, affected_on_page: true });
+ instrs.insert(String::from("bne"), bne);
+
+ // bpl
+ let mut bpl = HashMap::new();
+ bpl.insert(AddressingMode::RelativeOrZeropage, ShortEntry{ cycles: 2, size: 2, opcode: 0x10, affected_on_page: true });
+ instrs.insert(String::from("bpl"), bpl);
// brk
let mut brk = HashMap::new();
brk.insert(AddressingMode::Implied, ShortEntry{ cycles: 7, size: 1, opcode: 0x00, affected_on_page: false });
instrs.insert(String::from("brk"), brk);
- // BVC: TODO
- // BVS: TODO
+ // bvc
+ let mut bvc = HashMap::new();
+ bvc.insert(AddressingMode::RelativeOrZeropage, ShortEntry{ cycles: 2, size: 2, opcode: 0x50, affected_on_page: true });
+ instrs.insert(String::from("bvc"), bvc);
+
+ // bvs
+ let mut bvs = HashMap::new();
+ bvs.insert(AddressingMode::RelativeOrZeropage, ShortEntry{ cycles: 2, size: 2, opcode: 0x70, affected_on_page: true });
+ instrs.insert(String::from("bvs"), bvs);
// clc
let mut clc = HashMap::new();
@@ -403,23 +431,36 @@ lazy_static! {
opcodes.insert(0x0E, Entry { mode: AddressingMode::Absolute, mnemonic: String::from("asl"), cycles: 6, size: 3, opcode: 0x0E, affected_on_page: false });
opcodes.insert(0x1E, Entry { mode: AddressingMode::IndexedX, mnemonic: String::from("asl"), cycles: 7, size: 3, opcode: 0x1E, affected_on_page: false });
- // BCC
- // BCS
- // BEQ
+ // bcc
+ opcodes.insert(0x90, Entry { mode: AddressingMode::RelativeOrZeropage, mnemonic: String::from("bcc"), cycles: 2, size: 2, opcode: 0x90, affected_on_page: false });
+
+ // bcs
+ opcodes.insert(0xB0, Entry { mode: AddressingMode::RelativeOrZeropage, mnemonic: String::from("bcs"), cycles: 2, size: 2, opcode: 0xB0, affected_on_page: false });
+
+ // beq
+ opcodes.insert(0xF0, Entry { mode: AddressingMode::RelativeOrZeropage, mnemonic: String::from("beq"), cycles: 2, size: 2, opcode: 0xF0, affected_on_page: true });
// bit
opcodes.insert(0x24, Entry { mode: AddressingMode::RelativeOrZeropage, mnemonic: String::from("bit"), cycles: 3, size: 2, opcode: 0x24, affected_on_page: false });
opcodes.insert(0x2C, Entry { mode: AddressingMode::Absolute, mnemonic: String::from("bit"), cycles: 4, size: 3, opcode: 0x2C, affected_on_page: false });
- // BMI
- // BNE
- // BPL
+ // bmi
+ opcodes.insert(0x30, Entry { mode: AddressingMode::RelativeOrZeropage, mnemonic: String::from("bmi"), cycles: 2, size: 2, opcode: 0x30, affected_on_page: false });
+
+ // bne
+ opcodes.insert(0xD0, Entry { mode: AddressingMode::RelativeOrZeropage, mnemonic: String::from("bne"), cycles: 2, size: 2, opcode: 0xD0, affected_on_page: false });
+
+ // bpl
+ opcodes.insert(0x10, Entry { mode: AddressingMode::RelativeOrZeropage, mnemonic: String::from("bpl"), cycles: 2, size: 2, opcode: 0x10, affected_on_page: false });
// brk
opcodes.insert(0x00, Entry { mode: AddressingMode::Implied, mnemonic: String::from("brk"), cycles: 7, size: 1, opcode: 0x00, affected_on_page: false });
- // BVC
- // BVS
+ // bvc
+ opcodes.insert(0x50, Entry { mode: AddressingMode::RelativeOrZeropage, mnemonic: String::from("bvc"), cycles: 2, size: 2, opcode: 0x50, affected_on_page: false });
+
+ // bvs
+ opcodes.insert(0x70, Entry { mode: AddressingMode::RelativeOrZeropage, mnemonic: String::from("bvs"), cycles: 2, size: 2, opcode: 0x70, affected_on_page: false });
// clc
opcodes.insert(0x18, Entry { mode: AddressingMode::Implied, mnemonic: String::from("clc"), cycles: 2, size: 1, opcode: 0x18, affected_on_page: false });