A GameCube/Wii emulator and debugger written in Rust.
idk what im doing
Layle876ae66e3333
diff --git a/Cargo.lock b/Cargo.lockindex 8b03c06..3f4531c 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -54,9 +54,9 @@ dependencies = [[[package]]name = "chipi"-version = "0.3.0"+version = "0.4.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "6e160fec8ea8eed2ee3fd2f80599156ec8be09978f1e2744a3669dc08e86ba3f"+checksum = "a0b1c8f88248e1712bda8e8b64ae1359bb01e953abd5f76c53ddabf32be88fa1"[[package]]name = "clap"@@ -132,7 +132,7 @@ dependencies = [name = "gekko"version = "0.1.0"dependencies = [- "disasm",+ "chipi",][[package]]diff --git a/Cargo.toml b/Cargo.tomlindex fe50703..588089a 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -1,3 +1,3 @@[workspace]resolver = "3"-members = ["gctool", "disasm", "gekko", "tinyemu"]+members = ["crates/gctool", "crates/disasm", "crates/gekko", "crates/tinyemu"]diff --git a/disasm/Cargo.toml b/crates/disasm/Cargo.tomlsimilarity index 84%rename from disasm/Cargo.tomlrename to crates/disasm/Cargo.tomlindex 17fb27d..783bcf6 100644--- a/disasm/Cargo.toml+++ b/crates/disasm/Cargo.toml@@ -4,4 +4,4 @@ version = "0.1.0"edition = "2024"[build-dependencies]-chipi = "0.3.0"\ No newline at end of file+chipi = "0.4.0"\ No newline at end of filediff --git a/disasm/build.rs b/crates/disasm/build.rssimilarity index 61%rename from disasm/build.rsrename to crates/disasm/build.rsindex 11b418a..da97c7e 100644--- a/disasm/build.rs+++ b/crates/disasm/build.rs@@ -6,17 +6,17 @@ fn main() {// Generate Gekko (PowerPC) decoderchipi::generate(- "../rsrc/chipi-spec/gamecube/gekko.chipi",+ "../../rsrc/chipi-spec/gamecube/gekko.chipi",out_dir.join("gekko.rs").to_str().unwrap(),).expect("failed to generate gekko decoder");- println!("cargo:rerun-if-changed=../rsrc/chipi-spec/gamecube/gekko.chipi");+ println!("cargo:rerun-if-changed=../../rsrc/chipi-spec/gamecube/gekko.chipi");// Generate DSP decoderchipi::generate(- "../rsrc/chipi-spec/gamecube/dsp.chipi",+ "../../rsrc/chipi-spec/gamecube/dsp.chipi",out_dir.join("dsp.rs").to_str().unwrap(),).expect("failed to generate dsp decoder");- println!("cargo:rerun-if-changed=../rsrc/chipi-spec/gamecube/dsp.chipi");+ println!("cargo:rerun-if-changed=../../rsrc/chipi-spec/gamecube/dsp.chipi");}diff --git a/disasm/src/lib.rs b/crates/disasm/src/lib.rssimilarity index 100%rename from disasm/src/lib.rsrename to crates/disasm/src/lib.rsdiff --git a/disasm/src/tokenizer.rs b/crates/disasm/src/tokenizer.rssimilarity index 100%rename from disasm/src/tokenizer.rsrename to crates/disasm/src/tokenizer.rsdiff --git a/gctool/Cargo.lock b/crates/gctool/Cargo.locksimilarity index 100%rename from gctool/Cargo.lockrename to crates/gctool/Cargo.lockdiff --git a/gctool/Cargo.toml b/crates/gctool/Cargo.tomlsimilarity index 100%rename from gctool/Cargo.tomlrename to crates/gctool/Cargo.tomldiff --git a/gctool/src/main.rs b/crates/gctool/src/main.rssimilarity index 100%rename from gctool/src/main.rsrename to crates/gctool/src/main.rsdiff --git a/gekko/Cargo.toml b/crates/gekko/Cargo.tomlsimilarity index 57%rename from gekko/Cargo.tomlrename to crates/gekko/Cargo.tomlindex 225a4b5..86940b6 100644--- a/gekko/Cargo.toml+++ b/crates/gekko/Cargo.toml@@ -3,5 +3,5 @@ name = "gekko"version = "0.1.0"edition = "2024"-[dependencies]-disasm = { path = "../disasm" }\ No newline at end of file+[build-dependencies]+chipi = "0.4.0"\ No newline at end of filediff --git a/crates/gekko/build.rs b/crates/gekko/build.rsnew file mode 100644index 0000000..ab6e10d--- /dev/null+++ b/crates/gekko/build.rs@@ -0,0 +1,30 @@+use std::env;+use std::path::PathBuf;++fn main() {+ let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());+ let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());+ let spec = "../../rsrc/chipi-spec/gamecube/gekko.chipi";++ let builder = chipi::LutBuilder::new(spec)+ .handler_mod("crate::cpu::interpreter")+ .ctx_type("crate::gekko::Gekko")+ .instr_type("crate::cpu::semantics::Instruction")+ .group("branch", ["bx"])+ .group("alu", ["ori", "addi", "addis"]);++ // Always regenerate the LUT dispatch tables+ builder+ .build_lut(out_dir.join("gekko_lut.rs").to_str().unwrap())+ .expect("failed to generate Gekko LUT");++ // Generate interpreter stubs once+ let stubs = manifest_dir.join("src/cpu/interpreter.rs");+ if !stubs.exists() {+ builder+ .build_stubs(stubs.to_str().unwrap())+ .expect("failed to generate interpreter stubs");+ }++ println!("cargo:rerun-if-changed={spec}");+}diff --git a/gekko/src/cpu.rs b/crates/gekko/src/cpu.rssimilarity index 68%rename from gekko/src/cpu.rsrename to crates/gekko/src/cpu.rsindex 764b0d3..dd18221 100644--- a/gekko/src/cpu.rs+++ b/crates/gekko/src/cpu.rs@@ -1,8 +1,16 @@pub mod interpreter;+pub mod semantics;++#[allow(dead_code, unused_variables, non_upper_case_globals, clippy::all)]+pub mod lut {+ include!(concat!(env!("OUT_DIR"), "/gekko_lut.rs"));+}pub struct Cpu {pub gprs: [u32; 32],pub fprs: [f64; 32],+ pub current_pc: u32,+ pub next_pc: u32,pub pc: u32,}@@ -11,6 +19,8 @@ impl Cpu {Cpu {gprs: [0; 32],fprs: [0.0; 32],+ current_pc: 0x100,+ next_pc: 0x104,pc: 0x100,}}diff --git a/crates/gekko/src/cpu/interpreter.rs b/crates/gekko/src/cpu/interpreter.rsnew file mode 100644index 0000000..491702b--- /dev/null+++ b/crates/gekko/src/cpu/interpreter.rs@@ -0,0 +1,258 @@+pub fn branch<const OP: u32>(ctx: &mut crate::gekko::Gekko, instr: crate::cpu::semantics::Instruction) {+ if instr.lk() {+ ctx.cpu.write_gpr(0, ctx.cpu.current_pc.wrapping_add(4));+ }++ let target = if instr.aa() {+ instr.li() as u32+ } else {+ ctx.cpu.current_pc.wrapping_add_signed(instr.li())+ };+ ctx.cpu.next_pc = target;+}++pub fn alu<const OP: u32>(ctx: &mut crate::gekko::Gekko, instr: crate::cpu::semantics::Instruction) {+ match OP {+ crate::cpu::lut::OP_ADDI => {+ let ra = if instr.ra() == 0 { 0 } else { ctx.cpu.gprs[instr.ra()] };+ ctx.cpu.gprs[instr.rd()] = ra.wrapping_add_signed(instr.simm());+ }+ crate::cpu::lut::OP_ADDIS => {+ let ra = if instr.ra() == 0 { 0 } else { ctx.cpu.gprs[instr.ra()] };+ ctx.cpu.gprs[instr.rd()] = ra.wrapping_add_signed(instr.simm() << 16);+ }+ crate::cpu::lut::OP_ORI => {+ ctx.cpu.gprs[instr.ra()] = ctx.cpu.gprs[instr.rs()] | instr.uimm();+ }+ crate::cpu::lut::OP_ORIS => {+ ctx.cpu.gprs[instr.ra()] = ctx.cpu.gprs[instr.rs()] | (instr.uimm() << 16);+ }+ _ => todo!("ALU instruction with OP = {OP:#x}")+ }+}++pub fn twi(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("twi") }+pub fn ps_cmpu0(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_cmpu0") }+pub fn ps_cmpo0(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_cmpo0") }+pub fn ps_cmpu1(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_cmpu1") }+pub fn ps_cmpo1(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_cmpo1") }+pub fn ps_res(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_res") }+pub fn ps_rsqrte(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_rsqrte") }+pub fn ps_neg(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_neg") }+pub fn ps_mr(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_mr") }+pub fn ps_nabs(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_nabs") }+pub fn ps_abs(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_abs") }+pub fn ps_merge00(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_merge00") }+pub fn ps_merge01(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_merge01") }+pub fn ps_merge10(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_merge10") }+pub fn ps_merge11(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_merge11") }+pub fn psq_lx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("psq_lx") }+pub fn psq_stx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("psq_stx") }+pub fn psq_lux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("psq_lux") }+pub fn psq_stux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("psq_stux") }+pub fn ps_sum0(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_sum0") }+pub fn ps_sum1(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_sum1") }+pub fn ps_muls0(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_muls0") }+pub fn ps_muls1(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_muls1") }+pub fn ps_madds0(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_madds0") }+pub fn ps_madds1(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_madds1") }+pub fn ps_div(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_div") }+pub fn ps_sub(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_sub") }+pub fn ps_add(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_add") }+pub fn ps_sel(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_sel") }+pub fn ps_mul(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_mul") }+pub fn ps_msub(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_msub") }+pub fn ps_madd(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_madd") }+pub fn ps_nmsub(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_nmsub") }+pub fn ps_nmadd(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ps_nmadd") }+pub fn dcbz_l(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("dcbz_l") }+pub fn mulli(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mulli") }+pub fn subfic(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("subfic") }+pub fn cmpli(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("cmpli") }+pub fn cmpi(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("cmpi") }+pub fn addic(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("addic") }+pub fn addic_dot(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("addic_dot") }+pub fn bcx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("bcx") }+pub fn sc(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("sc") }+pub fn mcrf(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mcrf") }+pub fn bclrx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("bclrx") }+pub fn crnor(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("crnor") }+pub fn rfi(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("rfi") }+pub fn crandc(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("crandc") }+pub fn isync(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("isync") }+pub fn crxor(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("crxor") }+pub fn crnand(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("crnand") }+pub fn crand(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("crand") }+pub fn creqv(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("creqv") }+pub fn crorc(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("crorc") }+pub fn cror(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("cror") }+pub fn bcctrx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("bcctrx") }+pub fn rlwimix(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("rlwimix") }+pub fn rlwinmx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("rlwinmx") }+pub fn rlwnmx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("rlwnmx") }+pub fn ori(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ori") }+pub fn oris(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("oris") }+pub fn xori(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("xori") }+pub fn xoris(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("xoris") }+pub fn andi_dot(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("andi_dot") }+pub fn andis_dot(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("andis_dot") }+pub fn cmp(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("cmp") }+pub fn tw(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("tw") }+pub fn subfcx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("subfcx") }+pub fn mulhwux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mulhwux") }+pub fn addcx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("addcx") }+pub fn lwarx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lwarx") }+pub fn lwzx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lwzx") }+pub fn slwx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("slwx") }+pub fn cntlzwx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("cntlzwx") }+pub fn andx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("andx") }+pub fn cmpl(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("cmpl") }+pub fn subfx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("subfx") }+pub fn dcbst(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("dcbst") }+pub fn lwzux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lwzux") }+pub fn andcx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("andcx") }+pub fn mulhwx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mulhwx") }+pub fn mfcr(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mfcr") }+pub fn mfmsr(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mfmsr") }+pub fn dcbf(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("dcbf") }+pub fn lbzx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lbzx") }+pub fn negx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("negx") }+pub fn lbzux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lbzux") }+pub fn norx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("norx") }+pub fn subfex(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("subfex") }+pub fn addex(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("addex") }+pub fn mtcrf(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mtcrf") }+pub fn mtmsr(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mtmsr") }+pub fn stwcx_dot(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stwcx_dot") }+pub fn stwx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stwx") }+pub fn stwux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stwux") }+pub fn subfzex(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("subfzex") }+pub fn addzex(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("addzex") }+pub fn mtsr(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mtsr") }+pub fn stbx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stbx") }+pub fn subfmex(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("subfmex") }+pub fn addmex(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("addmex") }+pub fn mullwx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mullwx") }+pub fn mtsrin(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mtsrin") }+pub fn dcbtst(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("dcbtst") }+pub fn stbux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stbux") }+pub fn addx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("addx") }+pub fn dcbt(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("dcbt") }+pub fn lhzx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lhzx") }+pub fn eqvx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("eqvx") }+pub fn tlbie(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("tlbie") }+pub fn eciwx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("eciwx") }+pub fn lhzux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lhzux") }+pub fn xorx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("xorx") }+pub fn mfspr(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mfspr") }+pub fn lhax(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lhax") }+pub fn tlbia(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("tlbia") }+pub fn mftb(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mftb") }+pub fn lhaux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lhaux") }+pub fn sthx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("sthx") }+pub fn orcx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("orcx") }+pub fn ecowx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("ecowx") }+pub fn sthux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("sthux") }+pub fn orx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("orx") }+pub fn divwux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("divwux") }+pub fn mtspr(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mtspr") }+pub fn dcbi(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("dcbi") }+pub fn nandx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("nandx") }+pub fn divwx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("divwx") }+pub fn mcrxr(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mcrxr") }+pub fn lwbrx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lwbrx") }+pub fn lfsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lfsx") }+pub fn srwx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("srwx") }+pub fn lswx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lswx") }+pub fn tlbsync(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("tlbsync") }+pub fn lfsux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lfsux") }+pub fn mfsr(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mfsr") }+pub fn lswi(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lswi") }+pub fn sync(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("sync") }+pub fn lfdx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lfdx") }+pub fn lfdux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lfdux") }+pub fn mfsrin(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mfsrin") }+pub fn stswx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stswx") }+pub fn stwbrx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stwbrx") }+pub fn stfsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stfsx") }+pub fn stfsux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stfsux") }+pub fn stswi(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stswi") }+pub fn stfdx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stfdx") }+pub fn stfdux(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stfdux") }+pub fn dcba(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("dcba") }+pub fn lhbrx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lhbrx") }+pub fn srawx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("srawx") }+pub fn srawix(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("srawix") }+pub fn eieio(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("eieio") }+pub fn sthbrx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("sthbrx") }+pub fn extshx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("extshx") }+pub fn extsbx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("extsbx") }+pub fn icbi(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("icbi") }+pub fn stfiwx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stfiwx") }+pub fn tlbld(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("tlbld") }+pub fn tlbli(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("tlbli") }+pub fn dcbz(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("dcbz") }+pub fn lwz(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lwz") }+pub fn lwzu(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lwzu") }+pub fn lbz(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lbz") }+pub fn lbzu(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lbzu") }+pub fn stw(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stw") }+pub fn stwu(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stwu") }+pub fn stb(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stb") }+pub fn stbu(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stbu") }+pub fn lhz(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lhz") }+pub fn lhzu(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lhzu") }+pub fn lha(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lha") }+pub fn lhau(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lhau") }+pub fn sth(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("sth") }+pub fn sthu(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("sthu") }+pub fn lmw(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lmw") }+pub fn stmw(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stmw") }+pub fn lfs(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lfs") }+pub fn lfsu(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lfsu") }+pub fn lfd(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lfd") }+pub fn lfdu(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("lfdu") }+pub fn stfs(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stfs") }+pub fn stfsu(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stfsu") }+pub fn stfd(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stfd") }+pub fn stfdu(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("stfdu") }+pub fn psq_l(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("psq_l") }+pub fn psq_lu(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("psq_lu") }+pub fn fdivsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fdivsx") }+pub fn fsubsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fsubsx") }+pub fn faddsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("faddsx") }+pub fn fsqrtsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fsqrtsx") }+pub fn fresx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fresx") }+pub fn fmulsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fmulsx") }+pub fn fmsubsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fmsubsx") }+pub fn fmaddsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fmaddsx") }+pub fn fnmsubsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fnmsubsx") }+pub fn fnmaddsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fnmaddsx") }+pub fn psq_st(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("psq_st") }+pub fn psq_stu(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("psq_stu") }+pub fn fcmpu(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fcmpu") }+pub fn frspx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("frspx") }+pub fn fctiwx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fctiwx") }+pub fn fctiwzx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fctiwzx") }+pub fn fcmpo(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fcmpo") }+pub fn mtfsb1x(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mtfsb1x") }+pub fn fnegx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fnegx") }+pub fn mcrfs(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mcrfs") }+pub fn mtfsb0x(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mtfsb0x") }+pub fn fmrx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fmrx") }+pub fn mtfsfix(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mtfsfix") }+pub fn fnabsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fnabsx") }+pub fn fabsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fabsx") }+pub fn mffsx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mffsx") }+pub fn mtfsfx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("mtfsfx") }+pub fn fdivx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fdivx") }+pub fn fsubx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fsubx") }+pub fn faddx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("faddx") }+pub fn fsqrtx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fsqrtx") }+pub fn fselx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fselx") }+pub fn fmulx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fmulx") }+pub fn frsqrtex(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("frsqrtex") }+pub fn fmsubx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fmsubx") }+pub fn fmaddx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fmaddx") }+pub fn fnmsubx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fnmsubx") }+pub fn fnmaddx(_ctx: &mut crate::gekko::Gekko, _instr: crate::cpu::semantics::Instruction) { todo!("fnmaddx") }diff --git a/crates/gekko/src/cpu/semantics.rs b/crates/gekko/src/cpu/semantics.rsnew file mode 100644index 0000000..36840b6--- /dev/null+++ b/crates/gekko/src/cpu/semantics.rs@@ -0,0 +1,36 @@+pub struct Instruction(pub u32);++#[rustfmt::skip]+impl Instruction {+ #[inline] pub fn primary(&self) -> u32 { self.0 >> 26 }+ #[inline] pub fn xo10(&self) -> u32 { (self.0 >> 1) & 0x3ff }+ #[inline] pub fn xo9(&self) -> u32 { (self.0 >> 1) & 0x1ff }+ #[inline] pub fn xo5(&self) -> u32 { (self.0 >> 1) & 0x1f }++ #[inline] pub fn rd(&self) -> usize { ((self.0 >> 21) & 0x1f) as usize }+ #[inline] pub fn rs(&self) -> usize { ((self.0 >> 21) & 0x1f) as usize }+ #[inline] pub fn fd(&self) -> usize { ((self.0 >> 21) & 0x1f) as usize }+ #[inline] pub fn fs(&self) -> usize { ((self.0 >> 21) & 0x1f) as usize }+ #[inline] pub fn ra(&self) -> usize { ((self.0 >> 16) & 0x1f) as usize }+ #[inline] pub fn rb(&self) -> usize { ((self.0 >> 11) & 0x1f) as usize }+ #[inline] pub fn fc(&self) -> usize { ((self.0 >> 6) & 0x1f) as usize }++ #[inline] pub fn rc(&self) -> bool { self.0 & 1 != 0 }+ #[inline] pub fn lk(&self) -> bool { self.0 & 1 != 0 }+ #[inline] pub fn aa(&self) -> bool { (self.0 >> 1) & 1 != 0 }+ #[inline] pub fn oe(&self) -> bool { (self.0 >> 10) & 1 != 0 }++ #[inline] pub fn simm(&self) -> i32 { (self.0 as i16) as i32 }+ #[inline] pub fn uimm(&self) -> u32 { self.0 & 0xffff }+ #[inline] pub fn sh(&self) -> u32 { (self.0 >> 11) & 0x1f }+ #[inline] pub fn mb(&self) -> u32 { (self.0 >> 6) & 0x1f }+ #[inline] pub fn me(&self) -> u32 { (self.0 >> 1) & 0x1f }++ #[inline] pub fn li(&self) -> i32 { (((self.0 & 0x03ff_fffc) as i32) << 6) >> 6 }+ #[inline] pub fn bd(&self) -> i32 { (((self.0 & 0x0000_fffc) as i32) << 16) >> 16 }++ #[inline] pub fn spr(&self) -> u32 { let raw = (self.0 >> 11) & 0x3ff; (raw >> 5) | ((raw & 0x1f) << 5) }++ #[inline] pub fn bo(&self) -> u32 { (self.0 >> 21) & 0x1f }+ #[inline] pub fn bi(&self) -> u32 { (self.0 >> 16) & 0x1f }+}diff --git a/crates/gekko/src/gekko.rs b/crates/gekko/src/gekko.rsnew file mode 100644index 0000000..bec71cf--- /dev/null+++ b/crates/gekko/src/gekko.rs@@ -0,0 +1,32 @@+use crate::{cpu, mmu, scheduler};++pub struct Gekko {+ pub cpu: cpu::Cpu,+ pub scheduler: scheduler::Scheduler,+ pub mmu: mmu::Mmu,+}++impl Gekko {+ pub fn new(path: &str) -> Self {+ let mut mmu = mmu::Mmu::new();+ let data = std::fs::read(path).expect("failed to read ROM");+ mmu.memory[..data.len()].copy_from_slice(&data);++ Gekko {+ cpu: cpu::Cpu::new(),+ scheduler: scheduler::Scheduler { cycles: 0 },+ mmu,+ }+ }++ pub fn run_until_event(&mut self) {+ self.cpu.current_pc = self.cpu.pc;+ self.cpu.next_pc = self.cpu.current_pc.wrapping_add(4);++ let instr = cpu::semantics::Instruction(self.mmu.read_u32(self.cpu.current_pc));+ cpu::lut::dispatch(self, instr);+ self.scheduler.cycles += 1;++ self.cpu.pc = self.cpu.next_pc;+ }+}diff --git a/gekko/src/lib.rs b/crates/gekko/src/lib.rssimilarity index 100%rename from gekko/src/lib.rsrename to crates/gekko/src/lib.rsdiff --git a/gekko/src/mmu.rs b/crates/gekko/src/mmu.rssimilarity index 69%rename from gekko/src/mmu.rsrename to crates/gekko/src/mmu.rsindex 3a06948..762934b 100644--- a/gekko/src/mmu.rs+++ b/crates/gekko/src/mmu.rs@@ -13,6 +13,11 @@ impl Mmu {self.memory[addr as usize]}+ pub fn read_u32(&self, addr: u32) -> u32 {+ let a = addr as usize;+ u32::from_be_bytes(self.memory[a..a + 4].try_into().unwrap())+ }+pub fn write_u8(&mut self, addr: u32, value: u8) {self.memory[addr as usize] = value;}diff --git a/gekko/src/scheduler.rs b/crates/gekko/src/scheduler.rssimilarity index 100%rename from gekko/src/scheduler.rsrename to crates/gekko/src/scheduler.rsdiff --git a/tinyemu/Cargo.toml b/crates/tinyemu/Cargo.tomlsimilarity index 100%rename from tinyemu/Cargo.tomlrename to crates/tinyemu/Cargo.tomldiff --git a/tinyemu/src/main.rs b/crates/tinyemu/src/main.rssimilarity index 81%rename from tinyemu/src/main.rsrename to crates/tinyemu/src/main.rsindex 1884f3f..b8eed2a 100644--- a/tinyemu/src/main.rs+++ b/crates/tinyemu/src/main.rs@@ -1,19 +1,31 @@use colored::Colorize;+use disasm::gekko::GekkoInstruction;use disasm::tokenizer::{self, AsmToken};fn main() {let path = std::env::args().nth(1).expect("Usage: debugger <path_to_rom>");+ let is_debug = std::env::args().any(|arg| arg == "--debug");+let mut gekko = gekko::gekko::Gekko::new(&path);loop {let addr = gekko.cpu.pc;- let (instr, _) = gekko.execute_instruction().unwrap();+ let instr = GekkoInstruction::decode(&gekko.mmu.memory[addr as usize..])+ .expect("failed to decode instruction")+ .0;++ if is_debug {+ dbg!(&instr);+ }+println!("{}: {}",format!("{:08X}", addr).bold(),colorize_instr(&instr));++ gekko.run_until_event();}}diff --git a/gekko/src/cpu/interpreter.rs b/gekko/src/cpu/interpreter.rsdeleted file mode 100644index 2caee68..0000000--- a/gekko/src/cpu/interpreter.rs+++ /dev/null@@ -1,12 +0,0 @@--pub fn branch<const LINK: bool, const ABSOLUTE: bool>(target: i32, ctx: &mut crate::gekko::Gekko) {- if LINK {- ctx.cpu.write_gpr(31, ctx.cpu.pc + 4);- }-- if ABSOLUTE {- ctx.cpu.pc = target as u32;- } else {- ctx.cpu.pc = ctx.cpu.pc.wrapping_add_signed(target);- }-}\ No newline at end of filediff --git a/gekko/src/gekko.rs b/gekko/src/gekko.rsdeleted file mode 100644index 30c457c..0000000--- a/gekko/src/gekko.rs+++ /dev/null@@ -1,53 +0,0 @@-use disasm::gekko::GekkoInstruction;--use crate::{cpu, mmu, scheduler};--pub struct Gekko {- pub cpu: cpu::Cpu,- pub scheduler: scheduler::Scheduler,- pub mmu: mmu::Mmu,-}--impl Gekko {- pub fn new(path: &str) -> Self {- let mut mmu = mmu::Mmu::new();- let data = std::fs::read(path).expect("failed to read ROM");- mmu.memory[..data.len()].copy_from_slice(&data);-- Gekko {- cpu: cpu::Cpu::new(),- scheduler: scheduler::Scheduler { cycles: 0 },- mmu,- }- }-- pub fn execute_instruction(&mut self) -> Option<(GekkoInstruction, usize)> {- let lol = disasm::gekko::GekkoInstruction::decode(&self.mmu.memory[self.cpu.pc as usize..]);- if let Some((instr, _)) = lol {- self.dispatch_instruction(instr);- }-- self.cpu.pc += 4;- self.scheduler.cycles += 1;-- lol- }-- pub fn dispatch_instruction(&mut self, instr: disasm::gekko::GekkoInstruction) {- match instr {- disasm::gekko::GekkoInstruction::Bx { li, aa: false, lk: false } => {- cpu::interpreter::branch::<false, false>(li, self);- }- disasm::gekko::GekkoInstruction::Bx { li, aa: true, lk: false } => {- cpu::interpreter::branch::<false, true>(li, self);- }- disasm::gekko::GekkoInstruction::Bx { li, aa: false, lk: true } => {- cpu::interpreter::branch::<true, false>(li, self);- }- disasm::gekko::GekkoInstruction::Bx { li, aa: true, lk: true } => {- cpu::interpreter::branch::<true, true>(li, self);- }- _ => unimplemented!("Instruction not implemented: {:?}", instr),- }- }-}\ No newline at end of file