A GameCube/Wii emulator and debugger written in Rust.
ready for dsp
Layle7e811afcd282
diff --git a/crates/debugger/src/windows/dsp.rs b/crates/debugger/src/windows/dsp.rsindex b2b8df8..3b8198c 100644--- a/crates/debugger/src/windows/dsp.rs+++ b/crates/debugger/src/windows/dsp.rs@@ -1,94 +1,124 @@use egui::{Align, Color32, Context, Grid, RichText, ScrollArea};use gecko::flipper::dsp::Dsp;-pub fn show_dsp(ctx: &Context, open: &mut bool, dsp: &Dsp) {- egui::Window::new("DSP")- .open(open)- .default_size(egui::vec2(500.0, 600.0))- .show(ctx, |ui| {- Grid::new("dsp_special_regs")- .num_columns(4)- .striped(true)- .show(ui, |ui| {- ui.label("PC");- ui.monospace(format!("{:#06X}", dsp.pc));- ui.label("Halt");- ui.label(if dsp.csr.halt() { "yes" } else { "no" });- ui.end_row();+fn token_color(token: &disasm::tokenizer::AsmToken<'_>) -> Option<Color32> {+ use disasm::tokenizer::AsmToken;+ match token {+ AsmToken::Mnemonic(_) => Some(Color32::from_rgb(100, 180, 255)),+ AsmToken::Gpr(_) | AsmToken::Fpr(_) | AsmToken::CrField(_) | AsmToken::Spr(_) => {+ Some(Color32::from_rgb(255, 200, 100))+ }+ AsmToken::ImmSigned(_) | AsmToken::ImmUnsigned(_) | AsmToken::ImmHex(_) | AsmToken::Displacement(_) => {+ Some(Color32::from_rgb(150, 220, 150))+ }+ AsmToken::BranchTarget(_) => Some(Color32::from_rgb(255, 150, 150)),+ AsmToken::Punct(_) | AsmToken::Text(_) => None,+ }+}- ui.label("Reset");- ui.label(if dsp.csr.reset() { "yes" } else { "no" });- ui.label("CSR");- ui.monospace(format!("{:#06X}", dsp.csr.raw()));- ui.end_row();- });+pub fn show_dsp(ctx: &Context, open: &mut bool, dsp: &Dsp) {+ egui::Window::new("DSP").open(open).show(ctx, |ui| {+ Grid::new("dsp_special_regs")+ .num_columns(4)+ .striped(true)+ .show(ui, |ui| {+ ui.label("PC");+ ui.monospace(format!("{:#06X}", dsp.pc));+ ui.label("Halt");+ ui.label(if dsp.csr.halt() { "yes" } else { "no" });+ ui.end_row();- ui.separator();+ ui.label("Reset");+ ui.label(if dsp.csr.reset() { "yes" } else { "no" });+ ui.label("CSR");+ ui.monospace(format!("{:#06X}", dsp.csr.raw()));+ ui.end_row();- ScrollArea::vertical().id_salt("dsp_disasm_scroll").show(ui, |ui| {- Grid::new("dsp_disasm_grid")- .num_columns(4)- .min_col_width(0.0)- .striped(true)- .show(ui, |ui| {- let mut addr = dsp.pc;- for _ in 0..20 {- let off = addr as usize;- if off + 1 >= dsp.iram.len() {- break;- }+ if ui.button("Dump DSP").clicked() {+ let mut dump = Vec::new();+ dump.extend_from_slice(&dsp.iram[..]);+ dump.extend_from_slice(&dsp.dram[..]);+ std::fs::write("dsp_dump.bin", dump).expect("Failed to write DSP dump");+ }+ ui.end_row();+ });- let (text, words) = match disasm::dsp::GcDspInstruction::decode(&dsp.iram[off..]) {- Some((insn, byte_len)) => (insn.to_string(), (byte_len / 2) as u16),- None => {- let raw = u16::from_be_bytes([dsp.iram[off], dsp.iram[off + 1]]);- (format!(".word {:#06X}", raw), 1)- }- };+ ui.separator();- let is_pc = addr == dsp.pc;+ ScrollArea::vertical().id_salt("dsp_disasm_scroll").show(ui, |ui| {+ Grid::new("dsp_disasm_grid")+ .num_columns(4)+ .min_col_width(0.0)+ .striped(true)+ .show(ui, |ui| {+ let mut addr = dsp.pc;+ for _ in 0..20 {+ let off = (addr as usize) * 2; // word-addressed PC -> byte offset+ if off + 1 >= dsp.iram.len() {+ break;+ }- // PC indicator- if is_pc {- ui.label(- RichText::new(egui_phosphor::regular::PLAY).color(Color32::from_rgb(120, 220, 120)),- );- } else {- ui.label("");+ let (text, words) = match disasm::dsp::GcDspInstruction::decode(&dsp.iram[off..]) {+ Some((insn, byte_len)) => (insn.to_string(), (byte_len / 2) as u16),+ None => {+ let raw = u16::from_be_bytes([dsp.iram[off], dsp.iram[off + 1]]);+ (format!(".word {:#06X}", raw), 1)}+ };- // Address- ui.monospace(format!("{:#06X}", addr));+ let is_pc = addr == dsp.pc;- // Raw bytes- let mut raw_str = String::new();- for i in 0..words {- let w_off = off + i as usize;- if w_off + 1 < dsp.iram.len() {- let w = u16::from_be_bytes([dsp.iram[w_off], dsp.iram[w_off + 1]]);- if !raw_str.is_empty() {- raw_str.push(' ');- }- raw_str.push_str(&format!("{:04X}", w));- }- }+ // PC indicator+ if is_pc {ui.label(- RichText::new(raw_str)- .monospace()- .color(Color32::from_rgb(100, 100, 100)),+ RichText::new(egui_phosphor::regular::PLAY).color(Color32::from_rgb(120, 220, 120)),);+ } else {+ ui.label("");+ }++ // Address+ ui.monospace(format!("{:#06X}", addr));- // Disassembly- ui.monospace(&text);- ui.end_row();+ // Raw bytes+ let mut raw_str = String::new();+ for i in 0..words {+ let w_off = off + (i as usize) * 2;+ if w_off + 1 < dsp.iram.len() {+ let w = u16::from_be_bytes([dsp.iram[w_off], dsp.iram[w_off + 1]]);+ if !raw_str.is_empty() {+ raw_str.push(' ');+ }+ raw_str.push_str(&format!("{:04X}", w));+ }+ }+ ui.label(+ RichText::new(raw_str)+ .monospace()+ .color(Color32::from_rgb(100, 100, 100)),+ );- if is_pc {- ui.scroll_to_cursor(Some(Align::Min));+ // Disassembly+ let tokens = disasm::tokenizer::tokenize(&text);+ ui.horizontal(|ui| {+ ui.spacing_mut().item_spacing.x = 0.0;+ for token in &tokens {+ let mut rt = RichText::new(token.to_string()).monospace();+ if let Some(color) = token_color(token) {+ rt = rt.color(color);+ }+ ui.label(rt);}+ });+ ui.end_row();- addr += words;+ if is_pc {+ ui.scroll_to_cursor(Some(Align::Min));}- });- });++ addr += words;+ }+ });});+ });}diff --git a/crates/gecko/chipi.toml b/crates/gecko/chipi.tomlindex 30f6582..6cfb3e1 100644--- a/crates/gecko/chipi.toml+++ b/crates/gecko/chipi.toml@@ -234,3 +234,34 @@ instr_type = "crate::flipper::dsp::instruction::Instruction"lut_mod = "crate::flipper::dsp::lut"dispatch = "jump_table"instr_type_output = "$OUT_DIR/dsp_instr.rs"++[lut.groups]+control = ["nop", "halt", "ifcc", "jcc", "callcc", "retcc", "rticc", "jrcc", "callrcc"]+loops = ["loop_reg", "bloop", "loopi", "bloopi"]+addr_reg = ["dar", "iar", "subarn", "addarn"]+load_store = [+ "lri", "lr", "sr", "mrr", "si",+ "lrr", "lrrd", "lrri", "lrrn",+ "srr", "srrd", "srri", "srrn",+ "lrs", "srsh", "srs",+ "ilrr", "ilrrd", "ilrri", "ilrrn",+]+imm_alu = ["addi", "xori", "andi", "ori", "cmpi", "andf", "andcf", "addis", "cmpis", "lris"]+add_sub = ["addr", "addax", "add", "addp", "subr", "subax", "sub", "subp", "addaxl", "addpaxz"]+move_ops = ["movr", "movax", "mov", "movp", "movpz", "movnp"]+inc_dec = ["incm", "inc", "decm", "dec", "neg", "abs_ac"]+cmp_test = ["cmp", "cmpaxh", "tst", "tstprod", "tstaxh", "nx_0", "nx_1", "clr", "clrp", "clrl"]+logic = ["xorr", "andr", "orr", "andc", "orc", "xorc", "not_ac"]+shifts = [+ "lsl", "lsr", "asl", "asr",+ "lsl16", "lsr16", "asr16",+ "lsrn", "asrn", "lsrnrx", "asrnrx", "lsrnr", "asrnr",+]+status = ["sbclr", "sbset", "m2", "m0", "clr15", "set15", "set16", "set40"]+mul = [+ "mul", "mulx", "mulc", "mulaxh",+ "mulmv", "mulmvz", "mulac",+ "mulxmv", "mulxmvz", "mulxac",+ "mulcmv", "mulcmvz", "mulcac",+ "madd", "msub", "maddx", "msubx", "maddc", "msubc",+]diff --git a/crates/gecko/src/flipper/dsp/instruction.rs b/crates/gecko/src/flipper/dsp/instruction.rsindex 0267eb4..cb19221 100644--- a/crates/gecko/src/flipper/dsp/instruction.rs+++ b/crates/gecko/src/flipper/dsp/instruction.rs@@ -1,3 +1 @@include!(concat!(env!("OUT_DIR"), "/dsp_instr.rs"));--impl Instruction {}diff --git a/crates/gecko/src/flipper/dsp/interpreter.rs b/crates/gecko/src/flipper/dsp/interpreter.rsindex 3a440a9..feb5f21 100644--- a/crates/gecko/src/flipper/dsp/interpreter.rs+++ b/crates/gecko/src/flipper/dsp/interpreter.rs@@ -1,381 +1,241 @@-use crate::flipper::dsp::instruction::Instruction;-use crate::gamecube::GameCube;+use crate::flipper::dsp::lut::*;-pub fn nop(_gc: &mut GameCube, _instr: Instruction) {- todo!("nop")+pub fn add_sub<const OP: u32>(+ _ctx: &mut crate::gamecube::GameCube,+ _instr: crate::flipper::dsp::instruction::Instruction,+) {+ match OP {+ OP_ADDR => todo!("addr"),+ OP_ADDAX => todo!("addax"),+ OP_ADD => todo!("add"),+ OP_ADDP => todo!("addp"),+ OP_SUBR => todo!("subr"),+ OP_SUBAX => todo!("subax"),+ OP_SUB => todo!("sub"),+ OP_SUBP => todo!("subp"),+ OP_ADDAXL => todo!("addaxl"),+ OP_ADDPAXZ => todo!("addpaxz"),+ _ => unreachable!(),+ }}-pub fn dar(_gc: &mut GameCube, _instr: Instruction) {- todo!("dar")-}-pub fn iar(_gc: &mut GameCube, _instr: Instruction) {- todo!("iar")-}-pub fn subarn(_gc: &mut GameCube, _instr: Instruction) {- todo!("subarn")-}-pub fn addarn(_gc: &mut GameCube, _instr: Instruction) {- todo!("addarn")-}-pub fn halt(_gc: &mut GameCube, _instr: Instruction) {- todo!("halt")-}-pub fn loop_reg(_gc: &mut GameCube, _instr: Instruction) {- todo!("loop_reg")-}-pub fn bloop(_gc: &mut GameCube, _instr: Instruction) {- todo!("bloop")-}-pub fn lri(_gc: &mut GameCube, _instr: Instruction) {- todo!("lri")-}-pub fn lr(_gc: &mut GameCube, _instr: Instruction) {- todo!("lr")-}-pub fn sr(_gc: &mut GameCube, _instr: Instruction) {- todo!("sr")-}-pub fn ifcc(_gc: &mut GameCube, _instr: Instruction) {- todo!("ifcc")-}-pub fn jcc(_gc: &mut GameCube, _instr: Instruction) {- todo!("jcc")-}-pub fn callcc(_gc: &mut GameCube, _instr: Instruction) {- todo!("callcc")-}-pub fn retcc(_gc: &mut GameCube, _instr: Instruction) {- todo!("retcc")-}-pub fn rticc(_gc: &mut GameCube, _instr: Instruction) {- todo!("rticc")-}-pub fn addi(_gc: &mut GameCube, _instr: Instruction) {- todo!("addi")-}-pub fn xori(_gc: &mut GameCube, _instr: Instruction) {- todo!("xori")-}-pub fn andi(_gc: &mut GameCube, _instr: Instruction) {- todo!("andi")-}-pub fn ori(_gc: &mut GameCube, _instr: Instruction) {- todo!("ori")-}-pub fn cmpi(_gc: &mut GameCube, _instr: Instruction) {- todo!("cmpi")-}-pub fn andf(_gc: &mut GameCube, _instr: Instruction) {- todo!("andf")-}-pub fn andcf(_gc: &mut GameCube, _instr: Instruction) {- todo!("andcf")-}-pub fn ilrr(_gc: &mut GameCube, _instr: Instruction) {- todo!("ilrr")-}-pub fn ilrrd(_gc: &mut GameCube, _instr: Instruction) {- todo!("ilrrd")-}-pub fn ilrri(_gc: &mut GameCube, _instr: Instruction) {- todo!("ilrri")-}-pub fn ilrrn(_gc: &mut GameCube, _instr: Instruction) {- todo!("ilrrn")-}-pub fn lsrn(_gc: &mut GameCube, _instr: Instruction) {- todo!("lsrn")-}-pub fn asrn(_gc: &mut GameCube, _instr: Instruction) {- todo!("asrn")-}-pub fn addis(_gc: &mut GameCube, _instr: Instruction) {- todo!("addis")-}-pub fn cmpis(_gc: &mut GameCube, _instr: Instruction) {- todo!("cmpis")-}-pub fn lris(_gc: &mut GameCube, _instr: Instruction) {- todo!("lris")-}-pub fn loopi(_gc: &mut GameCube, _instr: Instruction) {- todo!("loopi")-}-pub fn bloopi(_gc: &mut GameCube, _instr: Instruction) {- todo!("bloopi")-}-pub fn sbclr(_gc: &mut GameCube, _instr: Instruction) {- todo!("sbclr")-}-pub fn sbset(_gc: &mut GameCube, _instr: Instruction) {- todo!("sbset")-}-pub fn lsl(_gc: &mut GameCube, _instr: Instruction) {- todo!("lsl")-}-pub fn lsr(_gc: &mut GameCube, _instr: Instruction) {- todo!("lsr")-}-pub fn asl(_gc: &mut GameCube, _instr: Instruction) {- todo!("asl")-}-pub fn asr(_gc: &mut GameCube, _instr: Instruction) {- todo!("asr")-}-pub fn si(_gc: &mut GameCube, _instr: Instruction) {- todo!("si")-}-pub fn jrcc(_gc: &mut GameCube, _instr: Instruction) {- todo!("jrcc")-}-pub fn callrcc(_gc: &mut GameCube, _instr: Instruction) {- todo!("callrcc")-}-pub fn lrr(_gc: &mut GameCube, _instr: Instruction) {- todo!("lrr")-}-pub fn lrrd(_gc: &mut GameCube, _instr: Instruction) {- todo!("lrrd")-}-pub fn lrri(_gc: &mut GameCube, _instr: Instruction) {- todo!("lrri")-}-pub fn lrrn(_gc: &mut GameCube, _instr: Instruction) {- todo!("lrrn")-}-pub fn srr(_gc: &mut GameCube, _instr: Instruction) {- todo!("srr")-}-pub fn srrd(_gc: &mut GameCube, _instr: Instruction) {- todo!("srrd")-}-pub fn srri(_gc: &mut GameCube, _instr: Instruction) {- todo!("srri")-}-pub fn srrn(_gc: &mut GameCube, _instr: Instruction) {- todo!("srrn")-}-pub fn mrr(_gc: &mut GameCube, _instr: Instruction) {- todo!("mrr")-}-pub fn lrs(_gc: &mut GameCube, _instr: Instruction) {- todo!("lrs")-}-pub fn srsh(_gc: &mut GameCube, _instr: Instruction) {- todo!("srsh")-}-pub fn srs(_gc: &mut GameCube, _instr: Instruction) {- todo!("srs")-}-pub fn xorr(_gc: &mut GameCube, _instr: Instruction) {- todo!("xorr")-}-pub fn andr(_gc: &mut GameCube, _instr: Instruction) {- todo!("andr")-}-pub fn orr(_gc: &mut GameCube, _instr: Instruction) {- todo!("orr")-}-pub fn andc(_gc: &mut GameCube, _instr: Instruction) {- todo!("andc")-}-pub fn orc(_gc: &mut GameCube, _instr: Instruction) {- todo!("orc")-}-pub fn xorc(_gc: &mut GameCube, _instr: Instruction) {- todo!("xorc")-}-pub fn not_ac(_gc: &mut GameCube, _instr: Instruction) {- todo!("not_ac")-}-pub fn lsrnrx(_gc: &mut GameCube, _instr: Instruction) {- todo!("lsrnrx")-}-pub fn asrnrx(_gc: &mut GameCube, _instr: Instruction) {- todo!("asrnrx")-}-pub fn lsrnr(_gc: &mut GameCube, _instr: Instruction) {- todo!("lsrnr")-}-pub fn asrnr(_gc: &mut GameCube, _instr: Instruction) {- todo!("asrnr")-}-pub fn addr(_gc: &mut GameCube, _instr: Instruction) {- todo!("addr")-}-pub fn addax(_gc: &mut GameCube, _instr: Instruction) {- todo!("addax")-}-pub fn add(_gc: &mut GameCube, _instr: Instruction) {- todo!("add")-}-pub fn addp(_gc: &mut GameCube, _instr: Instruction) {- todo!("addp")-}-pub fn subr(_gc: &mut GameCube, _instr: Instruction) {- todo!("subr")-}-pub fn subax(_gc: &mut GameCube, _instr: Instruction) {- todo!("subax")-}-pub fn sub(_gc: &mut GameCube, _instr: Instruction) {- todo!("sub")-}-pub fn subp(_gc: &mut GameCube, _instr: Instruction) {- todo!("subp")-}-pub fn movr(_gc: &mut GameCube, _instr: Instruction) {- todo!("movr")-}-pub fn movax(_gc: &mut GameCube, _instr: Instruction) {- todo!("movax")-}-pub fn mov(_gc: &mut GameCube, _instr: Instruction) {- todo!("mov")-}-pub fn movp(_gc: &mut GameCube, _instr: Instruction) {- todo!("movp")-}-pub fn addaxl(_gc: &mut GameCube, _instr: Instruction) {- todo!("addaxl")-}-pub fn incm(_gc: &mut GameCube, _instr: Instruction) {- todo!("incm")-}-pub fn inc(_gc: &mut GameCube, _instr: Instruction) {- todo!("inc")-}-pub fn decm(_gc: &mut GameCube, _instr: Instruction) {- todo!("decm")-}-pub fn dec(_gc: &mut GameCube, _instr: Instruction) {- todo!("dec")-}-pub fn neg(_gc: &mut GameCube, _instr: Instruction) {- todo!("neg")-}-pub fn movnp(_gc: &mut GameCube, _instr: Instruction) {- todo!("movnp")-}-pub fn nx_0(_gc: &mut GameCube, _instr: Instruction) {- todo!("nx_0")-}-pub fn nx_1(_gc: &mut GameCube, _instr: Instruction) {- todo!("nx_1")-}-pub fn clr(_gc: &mut GameCube, _instr: Instruction) {- todo!("clr")-}-pub fn cmp(_gc: &mut GameCube, _instr: Instruction) {- todo!("cmp")-}-pub fn mulaxh(_gc: &mut GameCube, _instr: Instruction) {- todo!("mulaxh")-}-pub fn clrp(_gc: &mut GameCube, _instr: Instruction) {- todo!("clrp")-}-pub fn tstprod(_gc: &mut GameCube, _instr: Instruction) {- todo!("tstprod")-}-pub fn tstaxh(_gc: &mut GameCube, _instr: Instruction) {- todo!("tstaxh")-}-pub fn m2(_gc: &mut GameCube, _instr: Instruction) {- todo!("m2")-}-pub fn m0(_gc: &mut GameCube, _instr: Instruction) {- todo!("m0")-}-pub fn clr15(_gc: &mut GameCube, _instr: Instruction) {- todo!("clr15")-}-pub fn set15(_gc: &mut GameCube, _instr: Instruction) {- todo!("set15")-}-pub fn set16(_gc: &mut GameCube, _instr: Instruction) {- todo!("set16")-}-pub fn set40(_gc: &mut GameCube, _instr: Instruction) {- todo!("set40")-}-pub fn mul(_gc: &mut GameCube, _instr: Instruction) {- todo!("mul")-}-pub fn asr16(_gc: &mut GameCube, _instr: Instruction) {- todo!("asr16")-}-pub fn mulmvz(_gc: &mut GameCube, _instr: Instruction) {- todo!("mulmvz")-}-pub fn mulac(_gc: &mut GameCube, _instr: Instruction) {- todo!("mulac")-}-pub fn mulmv(_gc: &mut GameCube, _instr: Instruction) {- todo!("mulmv")-}-pub fn mulx(_gc: &mut GameCube, _instr: Instruction) {- todo!("mulx")-}-pub fn abs_ac(_gc: &mut GameCube, _instr: Instruction) {- todo!("abs_ac")-}-pub fn tst(_gc: &mut GameCube, _instr: Instruction) {- todo!("tst")-}-pub fn mulxmvz(_gc: &mut GameCube, _instr: Instruction) {- todo!("mulxmvz")-}-pub fn mulxac(_gc: &mut GameCube, _instr: Instruction) {- todo!("mulxac")-}-pub fn mulxmv(_gc: &mut GameCube, _instr: Instruction) {- todo!("mulxmv")-}-pub fn mulc(_gc: &mut GameCube, _instr: Instruction) {- todo!("mulc")-}-pub fn cmpaxh(_gc: &mut GameCube, _instr: Instruction) {- todo!("cmpaxh")-}-pub fn mulcmvz(_gc: &mut GameCube, _instr: Instruction) {- todo!("mulcmvz")-}-pub fn mulcac(_gc: &mut GameCube, _instr: Instruction) {- todo!("mulcac")-}-pub fn mulcmv(_gc: &mut GameCube, _instr: Instruction) {- todo!("mulcmv")++pub fn addr_reg<const OP: u32>(+ _ctx: &mut crate::gamecube::GameCube,+ _instr: crate::flipper::dsp::instruction::Instruction,+) {+ match OP {+ OP_DAR => todo!("dar"),+ OP_IAR => todo!("iar"),+ OP_SUBARN => todo!("subarn"),+ OP_ADDARN => todo!("addarn"),+ _ => unreachable!(),+ }}-pub fn maddx(_gc: &mut GameCube, _instr: Instruction) {- todo!("maddx")++pub fn cmp_test<const OP: u32>(+ _ctx: &mut crate::gamecube::GameCube,+ _instr: crate::flipper::dsp::instruction::Instruction,+) {+ match OP {+ OP_CMP => todo!("cmp"),+ OP_CMPAXH => todo!("cmpaxh"),+ OP_TST => todo!("tst"),+ OP_TSTPROD => todo!("tstprod"),+ OP_TSTAXH => todo!("tstaxh"),+ OP_NX_0 => todo!("nx_0"),+ OP_NX_1 => todo!("nx_1"),+ OP_CLR => todo!("clr"),+ OP_CLRP => todo!("clrp"),+ OP_CLRL => todo!("clrl"),+ _ => unreachable!(),+ }}-pub fn msubx(_gc: &mut GameCube, _instr: Instruction) {- todo!("msubx")++pub fn control<const OP: u32>(+ _ctx: &mut crate::gamecube::GameCube,+ _instr: crate::flipper::dsp::instruction::Instruction,+) {+ match OP {+ OP_NOP => todo!("nop"),+ OP_HALT => todo!("halt"),+ OP_IFCC => todo!("ifcc"),+ OP_JCC => todo!("jcc"),+ OP_CALLCC => todo!("callcc"),+ OP_RETCC => todo!("retcc"),+ OP_RTICC => todo!("rticc"),+ OP_JRCC => todo!("jrcc"),+ OP_CALLRCC => todo!("callrcc"),+ _ => unreachable!(),+ }}-pub fn maddc(_gc: &mut GameCube, _instr: Instruction) {- todo!("maddc")++pub fn imm_alu<const OP: u32>(+ _ctx: &mut crate::gamecube::GameCube,+ _instr: crate::flipper::dsp::instruction::Instruction,+) {+ match OP {+ OP_ADDI => todo!("addi"),+ OP_XORI => todo!("xori"),+ OP_ANDI => todo!("andi"),+ OP_ORI => todo!("ori"),+ OP_CMPI => todo!("cmpi"),+ OP_ANDF => todo!("andf"),+ OP_ANDCF => todo!("andcf"),+ OP_ADDIS => todo!("addis"),+ OP_CMPIS => todo!("cmpis"),+ OP_LRIS => todo!("lris"),+ _ => unreachable!(),+ }}-pub fn msubc(_gc: &mut GameCube, _instr: Instruction) {- todo!("msubc")++pub fn inc_dec<const OP: u32>(+ _ctx: &mut crate::gamecube::GameCube,+ _instr: crate::flipper::dsp::instruction::Instruction,+) {+ match OP {+ OP_INCM => todo!("incm"),+ OP_INC => todo!("inc"),+ OP_DECM => todo!("decm"),+ OP_DEC => todo!("dec"),+ OP_NEG => todo!("neg"),+ OP_ABS_AC => todo!("abs_ac"),+ _ => unreachable!(),+ }}-pub fn lsl16(_gc: &mut GameCube, _instr: Instruction) {- todo!("lsl16")++pub fn load_store<const OP: u32>(+ _ctx: &mut crate::gamecube::GameCube,+ _instr: crate::flipper::dsp::instruction::Instruction,+) {+ match OP {+ OP_LRI => todo!("lri"),+ OP_LR => todo!("lr"),+ OP_SR => todo!("sr"),+ OP_MRR => todo!("mrr"),+ OP_SI => todo!("si"),+ OP_LRR => todo!("lrr"),+ OP_LRRD => todo!("lrrd"),+ OP_LRRI => todo!("lrri"),+ OP_LRRN => todo!("lrrn"),+ OP_SRR => todo!("srr"),+ OP_SRRD => todo!("srrd"),+ OP_SRRI => todo!("srri"),+ OP_SRRN => todo!("srrn"),+ OP_LRS => todo!("lrs"),+ OP_SRSH => todo!("srsh"),+ OP_SRS => todo!("srs"),+ OP_ILRR => todo!("ilrr"),+ OP_ILRRD => todo!("ilrrd"),+ OP_ILRRI => todo!("ilrri"),+ OP_ILRRN => todo!("ilrrn"),+ _ => unreachable!(),+ }}-pub fn madd(_gc: &mut GameCube, _instr: Instruction) {- todo!("madd")++pub fn logic<const OP: u32>(+ _ctx: &mut crate::gamecube::GameCube,+ _instr: crate::flipper::dsp::instruction::Instruction,+) {+ match OP {+ OP_XORR => todo!("xorr"),+ OP_ANDR => todo!("andr"),+ OP_ORR => todo!("orr"),+ OP_ANDC => todo!("andc"),+ OP_ORC => todo!("orc"),+ OP_XORC => todo!("xorc"),+ OP_NOT_AC => todo!("not_ac"),+ _ => unreachable!(),+ }}-pub fn lsr16(_gc: &mut GameCube, _instr: Instruction) {- todo!("lsr16")++pub fn loops<const OP: u32>(+ _ctx: &mut crate::gamecube::GameCube,+ _instr: crate::flipper::dsp::instruction::Instruction,+) {+ match OP {+ OP_LOOP_REG => todo!("loop_reg"),+ OP_BLOOP => todo!("bloop"),+ OP_LOOPI => todo!("loopi"),+ OP_BLOOPI => todo!("bloopi"),+ _ => unreachable!(),+ }}-pub fn msub(_gc: &mut GameCube, _instr: Instruction) {- todo!("msub")++pub fn move_ops<const OP: u32>(+ _ctx: &mut crate::gamecube::GameCube,+ _instr: crate::flipper::dsp::instruction::Instruction,+) {+ match OP {+ OP_MOVR => todo!("movr"),+ OP_MOVAX => todo!("movax"),+ OP_MOV => todo!("mov"),+ OP_MOVP => todo!("movp"),+ OP_MOVPZ => todo!("movpz"),+ OP_MOVNP => todo!("movnp"),+ _ => unreachable!(),+ }}-pub fn addpaxz(_gc: &mut GameCube, _instr: Instruction) {- todo!("addpaxz")++pub fn mul<const OP: u32>(_ctx: &mut crate::gamecube::GameCube, _instr: crate::flipper::dsp::instruction::Instruction) {+ match OP {+ OP_MUL => todo!("mul"),+ OP_MULX => todo!("mulx"),+ OP_MULC => todo!("mulc"),+ OP_MULAXH => todo!("mulaxh"),+ OP_MULMV => todo!("mulmv"),+ OP_MULMVZ => todo!("mulmvz"),+ OP_MULAC => todo!("mulac"),+ OP_MULXMV => todo!("mulxmv"),+ OP_MULXMVZ => todo!("mulxmvz"),+ OP_MULXAC => todo!("mulxac"),+ OP_MULCMV => todo!("mulcmv"),+ OP_MULCMVZ => todo!("mulcmvz"),+ OP_MULCAC => todo!("mulcac"),+ OP_MADD => todo!("madd"),+ OP_MSUB => todo!("msub"),+ OP_MADDX => todo!("maddx"),+ OP_MSUBX => todo!("msubx"),+ OP_MADDC => todo!("maddc"),+ OP_MSUBC => todo!("msubc"),+ _ => unreachable!(),+ }}-pub fn clrl(_gc: &mut GameCube, _instr: Instruction) {- todo!("clrl")++pub fn shifts<const OP: u32>(+ _ctx: &mut crate::gamecube::GameCube,+ _instr: crate::flipper::dsp::instruction::Instruction,+) {+ match OP {+ OP_LSL => todo!("lsl"),+ OP_LSR => todo!("lsr"),+ OP_ASL => todo!("asl"),+ OP_ASR => todo!("asr"),+ OP_LSL16 => todo!("lsl16"),+ OP_LSR16 => todo!("lsr16"),+ OP_ASR16 => todo!("asr16"),+ OP_LSRN => todo!("lsrn"),+ OP_ASRN => todo!("asrn"),+ OP_LSRNRX => todo!("lsrnrx"),+ OP_ASRNRX => todo!("asrnrx"),+ OP_LSRNR => todo!("lsrnr"),+ OP_ASRNR => todo!("asrnr"),+ _ => unreachable!(),+ }}-pub fn movpz(_gc: &mut GameCube, _instr: Instruction) {- todo!("movpz")++pub fn status<const OP: u32>(+ _ctx: &mut crate::gamecube::GameCube,+ _instr: crate::flipper::dsp::instruction::Instruction,+) {+ match OP {+ OP_SBCLR => todo!("sbclr"),+ OP_SBSET => todo!("sbset"),+ OP_M2 => todo!("m2"),+ OP_M0 => todo!("m0"),+ OP_CLR15 => todo!("clr15"),+ OP_SET15 => todo!("set15"),+ OP_SET16 => todo!("set16"),+ OP_SET40 => todo!("set40"),+ _ => unreachable!(),+ }}diff --git a/crates/gecko/src/mmio/bus.rs b/crates/gecko/src/mmio/bus.rsindex 2a7f580..35df29f 100644--- a/crates/gecko/src/mmio/bus.rs+++ b/crates/gecko/src/mmio/bus.rs@@ -67,13 +67,13 @@ macro_rules! bus_read_hooks {}}- let result = $body;+ let mut result = $body;#[cfg(feature = "scripting")]if $self.script_hook_flags.contains(HookFlags::BUS_READ_POST) {if $self.script_hook_filters.bus_read_post.matches($addr, $phys) {if let Some(mut host) = $self.script_host.take() {- host.on_bus_read_post($self, $addr, $phys, $size, result as u32);+ result = host.on_bus_read_post($self, $addr, $phys, $size, result as u32) as _;$self.sync_pending_script_hook_state(host.as_mut());$self.script_host = Some(host);}diff --git a/crates/gecko/src/scripting.rs b/crates/gecko/src/scripting.rsindex dba8c8a..a7e11a2 100644--- a/crates/gecko/src/scripting.rs+++ b/crates/gecko/src/scripting.rs@@ -117,8 +117,8 @@ pub trait ScriptHost {/// Called before a bus read. Return Some(val) to override the read value.fn on_bus_read_pre(&mut self, emu: &mut GameCube, virt_addr: u32, phys_addr: u32, size: u8) -> Option<u32>;- /// Called after a bus read completes.- fn on_bus_read_post(&mut self, emu: &mut GameCube, virt_addr: u32, phys_addr: u32, size: u8, value: u32);+ /// Called after a bus read completes. Returns the (possibly modified) value.+ fn on_bus_read_post(&mut self, emu: &mut GameCube, virt_addr: u32, phys_addr: u32, size: u8, value: u32) -> u32;/// Called before a bus write. Returns the (possibly modified) value to write.fn on_bus_write_pre(&mut self, emu: &mut GameCube, virt_addr: u32, phys_addr: u32, size: u8, value: u32) -> u32;diff --git a/crates/scripting/src/lib.rs b/crates/scripting/src/lib.rsindex 7e1f163..1895e08 100644--- a/crates/scripting/src/lib.rs+++ b/crates/scripting/src/lib.rs@@ -316,12 +316,12 @@ impl LuaScriptHost {phys_addr: u32,size: u8,value: u32,- ) -> LuaResult<()> {+ ) -> LuaResult<Option<u32>> {self.lua.scope(|scope| {let ud = scope.create_userdata(GameCubeRef(emu as *mut GameCube))?;let func = callback.resolve(&self.lua)?;- func.call::<()>((&ud, virt_addr, phys_addr, size, value))+ func.call::<Option<u32>>((&ud, virt_addr, phys_addr, size, value))}).map_err(|err| annotate_hook_error(hook_name, err))}@@ -521,14 +521,15 @@ impl ScriptHost for LuaScriptHost {}}- fn on_bus_read_post(&mut self, emu: &mut GameCube, virt_addr: u32, phys_addr: u32, size: u8, value: u32) {+ fn on_bus_read_post(&mut self, emu: &mut GameCube, virt_addr: u32, phys_addr: u32, size: u8, value: u32) -> u32 {if let Some(callback) = self.bus_read_post.resolve(virt_addr, phys_addr) {- if let Err(err) =- self.call_bus_read_post_hook("bus_read_post", callback, emu, virt_addr, phys_addr, size, value)- {- log_hook_error("bus_read_post", &err);+ match self.call_bus_read_post_hook("bus_read_post", callback, emu, virt_addr, phys_addr, size, value) {+ Ok(Some(v)) => return v,+ Ok(None) => {}+ Err(err) => log_hook_error("bus_read_post", &err),}}+ value}fn on_bus_write_pre(&mut self, emu: &mut GameCube, virt_addr: u32, phys_addr: u32, size: u8, value: u32) -> u32 {diff --git a/scripts/dsp_busy_toggle.lua b/scripts/dsp_busy_toggle.luanew file mode 100644index 0000000..34d863d--- /dev/null+++ b/scripts/dsp_busy_toggle.lua@@ -0,0 +1,23 @@+toggle = false+local function hack(emu, virt_addr, phys_addr, size, value)+ log(string.format("Toggling DSP busy bit: %s", toggle and "ON" or "OFF"))+ log(string.format("Original DSP read value: %08X", value))+ if toggle then+ value = value | 0x8000+ toggle = false+ else+ value = value & 0x7FFF+ toggle = true+ end+ log(string.format("Modified DSP read value: %08X", value))+ return value+end++traps = {+ bus_read_post = {+ virt = {+ [0xCC005000] = hack,+ [0xCC005004] = hack,+ },+ },+}\ No newline at end of file