Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

dsp

Laylecdbb58ce6499
diff --git a/Cargo.lock b/Cargo.lock
index 3dca15c..7797b75 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -384,7 +384,8 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]]
name = "chapa"
version = "0.1.1"
-source = "git+https://github.com/ioncodes/chapa.git#79ae40b94a5823ea59bdcecf0b7a9878cd8accba"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e32c359a2c9fad1bf865975a80e3ffb1384ebae1814268ffd8d657f91af0a0fe"
dependencies = [
"chapa-macros",
]
@@ -392,7 +393,8 @@ dependencies = [
[[package]]
name = "chapa-macros"
version = "0.1.1"
-source = "git+https://github.com/ioncodes/chapa.git#79ae40b94a5823ea59bdcecf0b7a9878cd8accba"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "158582b06b8a70fbe05a0942bb254c07149ffd88d7ddb29ea2c15a6213309f0c"
dependencies = [
"proc-macro2",
"quote",
@@ -401,18 +403,18 @@ dependencies = [
[[package]]
name = "chipi-build"
-version = "0.7.0"
+version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f6adea386dd961a22b3d1243545077aa700c407d522be3c68b3edb4e7ae36cd4"
+checksum = "fa4d92ef9c1c407a60305280f56167c8b27321f2e89a22ad11a211462f5906da"
dependencies = [
"chipi-core",
]
[[package]]
name = "chipi-core"
-version = "0.7.0"
+version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c45f19321253fca12a2d8c0a89b09a3b7f0d06e6d7f44e4848444867ec9c1dca"
+checksum = "0bb9fe17b59d9ccb968f4b245484a465855910673d7e935ed2b19ae5ac710748"
dependencies = [
"serde",
"toml",
diff --git a/crates/debugger/src/debugger.rs b/crates/debugger/src/debugger.rs
index f7cebc2..c0c3654 100644
--- a/crates/debugger/src/debugger.rs
+++ b/crates/debugger/src/debugger.rs
@@ -19,6 +19,7 @@ pub enum EmulatorState {
pub struct DebuggerUi {
pub emulator_state: EmulatorState,
pub show_cpu: bool,
+ pub show_dsp: bool,
pub show_gx_state: bool,
pub show_mmio: bool,
pub show_dvd: bool,
@@ -37,6 +38,7 @@ impl Default for DebuggerUi {
DebuggerUi {
emulator_state: EmulatorState::Paused,
show_cpu: true,
+ show_dsp: false,
show_controls: true,
show_gx_state: false,
show_mmio: false,
diff --git a/crates/debugger/src/render.rs b/crates/debugger/src/render.rs
index 7ee2dac..62e1024 100644
--- a/crates/debugger/src/render.rs
+++ b/crates/debugger/src/render.rs
@@ -255,10 +255,7 @@ impl RenderState {
use egui_phosphor::regular as icons;
if ui
- .add_enabled(
- is_paused,
- egui::Button::new(format!("{} Continue", icons::PLAY)),
- )
+ .add_enabled(is_paused, egui::Button::new(format!("{} Continue", icons::PLAY)))
.clicked()
{
debugger_ui.emulator_state = EmulatorState::Running;
@@ -278,10 +275,7 @@ impl RenderState {
debugger_ui.emulator_state = EmulatorState::Step;
ui.close();
}
- if ui
- .button(format!("{} Run Until VSync", icons::FAST_FORWARD))
- .clicked()
- {
+ if ui.button(format!("{} Run Until VSync", icons::FAST_FORWARD)).clicked() {
debugger_ui.emulator_state = EmulatorState::RunUntilVsync;
ui.close();
}
@@ -289,6 +283,7 @@ impl RenderState {
ui.menu_button("Windows", |ui| {
ui.checkbox(&mut debugger_ui.show_cpu, "CPU");
+ ui.checkbox(&mut debugger_ui.show_dsp, "DSP");
ui.checkbox(&mut debugger_ui.show_gx_state, "GX");
ui.checkbox(&mut debugger_ui.show_mmio, "MMIO");
ui.checkbox(&mut debugger_ui.show_dvd, "DVD");
@@ -302,6 +297,9 @@ impl RenderState {
if debugger_ui.show_cpu {
windows::cpu::show_cpu(&ctx, &mut debugger_ui.show_cpu, cpu, mmio);
}
+ if debugger_ui.show_dsp {
+ windows::dsp::show_dsp(&ctx, &mut debugger_ui.show_dsp, &emulator.dsp);
+ }
if debugger_ui.show_controls {
let mut start_trace = false;
let mut stop_trace = false;
diff --git a/crates/debugger/src/windows.rs b/crates/debugger/src/windows.rs
index ae54615..c5cdb33 100644
--- a/crates/debugger/src/windows.rs
+++ b/crates/debugger/src/windows.rs
@@ -1,5 +1,6 @@
pub mod controls;
pub mod cpu;
+pub mod dsp;
pub mod dvd;
pub mod exi;
pub mod gx;
diff --git a/crates/debugger/src/windows/controls.rs b/crates/debugger/src/windows/controls.rs
index 8148c4e..9dcd662 100644
--- a/crates/debugger/src/windows/controls.rs
+++ b/crates/debugger/src/windows/controls.rs
@@ -71,10 +71,7 @@ pub fn show_controls(
.font(egui::TextStyle::Monospace)
.show(ui);
- if ui
- .add(egui::Button::new(format!("{} Run", icons::PLAY)))
- .clicked()
- {
+ if ui.add(egui::Button::new(format!("{} Run", icons::PLAY))).clicked() {
let s = run_until_addr_input.trim().trim_start_matches("0x");
if let Ok(addr) = u32::from_str_radix(s, 16) {
*state = EmulatorState::RunUntilAddress(addr);
@@ -102,10 +99,7 @@ pub fn show_controls(
if !tracing {
if ui
- .add(
- egui::Button::new(format!("{} Start Trace", icons::RECORD))
- .min_size(btn_size),
- )
+ .add(egui::Button::new(format!("{} Start Trace", icons::RECORD)).min_size(btn_size))
.clicked()
{
*start_trace = true;
diff --git a/crates/debugger/src/windows/dsp.rs b/crates/debugger/src/windows/dsp.rs
new file mode 100644
index 0000000..b2b8df8
--- /dev/null
+++ b/crates/debugger/src/windows/dsp.rs
@@ -0,0 +1,94 @@
+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();
+
+ 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();
+ });
+
+ ui.separator();
+
+ 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;
+ }
+
+ 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)
+ }
+ };
+
+ let is_pc = addr == dsp.pc;
+
+ // PC indicator
+ if is_pc {
+ ui.label(
+ RichText::new(egui_phosphor::regular::PLAY).color(Color32::from_rgb(120, 220, 120)),
+ );
+ } else {
+ ui.label("");
+ }
+
+ // Address
+ ui.monospace(format!("{:#06X}", addr));
+
+ // 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));
+ }
+ }
+ ui.label(
+ RichText::new(raw_str)
+ .monospace()
+ .color(Color32::from_rgb(100, 100, 100)),
+ );
+
+ // Disassembly
+ ui.monospace(&text);
+ ui.end_row();
+
+ if is_pc {
+ ui.scroll_to_cursor(Some(Align::Min));
+ }
+
+ addr += words;
+ }
+ });
+ });
+ });
+}
diff --git a/crates/gecko/Cargo.toml b/crates/gecko/Cargo.toml
index be58fac..f6b9878 100644
--- a/crates/gecko/Cargo.toml
+++ b/crates/gecko/Cargo.toml
@@ -8,9 +8,9 @@ scripting = []
scripting-mut-traps = ["scripting"]
[build-dependencies]
-chipi-build = "0.7.0"
+chipi-build = "0.7.2"
[dependencies]
-chapa = { git = "https://github.com/ioncodes/chapa.git" }
+chapa = "0.1.0"
tracing = { version = "0.1.44", features = ["release_max_level_off"] }
image = { path = "../image" }
diff --git a/crates/gecko/chipi.toml b/crates/gecko/chipi.toml
index 09154ab..30f6582 100644
--- a/crates/gecko/chipi.toml
+++ b/crates/gecko/chipi.toml
@@ -3,7 +3,7 @@ input = "../../submodules/chipi-spec/gamecube/gekko.chipi"
output = "$OUT_DIR/gekko_lut.rs"
handler_mod = "crate::cpu::interpreter"
ctx_type = "crate::gamecube::GameCube"
-instr_type = "crate::cpu::semantics::Instruction"
+instr_type = "crate::cpu::instruction::Instruction"
lut_mod = "crate::cpu::lut"
dispatch = "jump_table"
instr_type_output = "$OUT_DIR/gekko_instr.rs"
@@ -224,3 +224,13 @@ ps_ops = [
"ps_nmsub",
"ps_nmadd",
]
+
+[[lut]]
+input = "../../submodules/chipi-spec/gamecube/dsp.chipi"
+output = "$OUT_DIR/dsp_lut.rs"
+handler_mod = "crate::flipper::dsp::interpreter"
+ctx_type = "crate::gamecube::GameCube"
+instr_type = "crate::flipper::dsp::instruction::Instruction"
+lut_mod = "crate::flipper::dsp::lut"
+dispatch = "jump_table"
+instr_type_output = "$OUT_DIR/dsp_instr.rs"
diff --git a/crates/gecko/src/cpu.rs b/crates/gecko/src/cpu.rs
index f73889e..5cdea6d 100644
--- a/crates/gecko/src/cpu.rs
+++ b/crates/gecko/src/cpu.rs
@@ -1,8 +1,8 @@
pub mod condition;
+pub mod instruction;
pub mod interpreter;
pub mod irq;
pub mod msr;
-pub mod semantics;
pub mod spr;
pub mod sr;
diff --git a/crates/gecko/src/cpu/semantics.rs b/crates/gecko/src/cpu/instruction.rs
similarity index 100%
rename from crates/gecko/src/cpu/semantics.rs
rename to crates/gecko/src/cpu/instruction.rs
diff --git a/crates/gecko/src/cpu/interpreter/alu.rs b/crates/gecko/src/cpu/interpreter/alu.rs
index ff22045..2d3f7d8 100644
--- a/crates/gecko/src/cpu/interpreter/alu.rs
+++ b/crates/gecko/src/cpu/interpreter/alu.rs
@@ -1,5 +1,5 @@
#[inline(always)]
-pub fn alu<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::semantics::Instruction) {
+pub fn alu<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::instruction::Instruction) {
match OP {
crate::cpu::lut::OP_ADDX => {
let res = ctx.cpu.read_gpr(instr.ra()).wrapping_add(ctx.cpu.read_gpr(instr.rb()));
@@ -212,7 +212,7 @@ pub fn alu<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu
}
#[inline(always)]
-pub fn logical<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::semantics::Instruction) {
+pub fn logical<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::instruction::Instruction) {
let rs = ctx.cpu.read_gpr(instr.rs());
let rb = ctx.cpu.read_gpr(instr.rb());
diff --git a/crates/gecko/src/cpu/interpreter/branch.rs b/crates/gecko/src/cpu/interpreter/branch.rs
index d149a62..1d08a22 100644
--- a/crates/gecko/src/cpu/interpreter/branch.rs
+++ b/crates/gecko/src/cpu/interpreter/branch.rs
@@ -1,7 +1,7 @@
use crate::cpu::condition::BranchControl;
#[inline(always)]
-pub fn branch<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::semantics::Instruction) {
+pub fn branch<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::instruction::Instruction) {
// Read LR before potentially overwriting LR with CIA+4 (matters for blrl/bctrl)
let old_lr = ctx.cpu.spr.lr;
diff --git a/crates/gecko/src/cpu/interpreter/compare.rs b/crates/gecko/src/cpu/interpreter/compare.rs
index 080ec07..9305373 100644
--- a/crates/gecko/src/cpu/interpreter/compare.rs
+++ b/crates/gecko/src/cpu/interpreter/compare.rs
@@ -1,7 +1,7 @@
use crate::cpu::condition::ConditionRegister;
#[inline(always)]
-pub fn compare<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::semantics::Instruction) {
+pub fn compare<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::instruction::Instruction) {
let field = match OP {
crate::cpu::lut::OP_CMP => ConditionRegister::field_from_ord(
(ctx.cpu.read_gpr(instr.ra()) as i32).cmp(&(ctx.cpu.read_gpr(instr.rb()) as i32)),
diff --git a/crates/gecko/src/cpu/interpreter/cr_ops.rs b/crates/gecko/src/cpu/interpreter/cr_ops.rs
index 9e207f0..c18dc77 100644
--- a/crates/gecko/src/cpu/interpreter/cr_ops.rs
+++ b/crates/gecko/src/cpu/interpreter/cr_ops.rs
@@ -1,5 +1,5 @@
#[inline(always)]
-pub fn cr_ops<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::semantics::Instruction) {
+pub fn cr_ops<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::instruction::Instruction) {
match OP {
crate::cpu::lut::OP_MTCRF => {
let crm = instr.crm();
diff --git a/crates/gecko/src/cpu/interpreter/fp_ops.rs b/crates/gecko/src/cpu/interpreter/fp_ops.rs
index 35f4d91..621979b 100644
--- a/crates/gecko/src/cpu/interpreter/fp_ops.rs
+++ b/crates/gecko/src/cpu/interpreter/fp_ops.rs
@@ -1,7 +1,7 @@
use crate::cpu::condition::ConditionField;
#[inline(always)]
-pub fn fp_ops<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::semantics::Instruction) {
+pub fn fp_ops<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::instruction::Instruction) {
match OP {
crate::cpu::lut::OP_MTFSFX => {
let fm = instr.fm();
@@ -187,7 +187,7 @@ pub fn fp_ops<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::
/// Write FP result to fD and optionally update CR1
#[inline(always)]
-fn fp_write(ctx: &mut crate::gamecube::GameCube, instr: &crate::cpu::semantics::Instruction, val: f64) {
+fn fp_write(ctx: &mut crate::gamecube::GameCube, instr: &crate::cpu::instruction::Instruction, val: f64) {
ctx.cpu.write_fpr(instr.rd(), val);
if instr.rc() {
ctx.cpu.update_cr1();
@@ -197,7 +197,7 @@ fn fp_write(ctx: &mut crate::gamecube::GameCube, instr: &crate::cpu::semantics::
/// Write single-precision FP result to fD.
/// On Gekko, single-precision instructions duplicate the result into both ps0 and ps1.
#[inline(always)]
-fn fp_write_single(ctx: &mut crate::gamecube::GameCube, instr: &crate::cpu::semantics::Instruction, val: f64) {
+fn fp_write_single(ctx: &mut crate::gamecube::GameCube, instr: &crate::cpu::instruction::Instruction, val: f64) {
ctx.cpu.write_fpr(instr.rd(), val);
ctx.cpu.write_ps1(instr.rd(), val);
if instr.rc() {
diff --git a/crates/gecko/src/cpu/interpreter/ps_ops.rs b/crates/gecko/src/cpu/interpreter/ps_ops.rs
index 4e083f9..bdff258 100644
--- a/crates/gecko/src/cpu/interpreter/ps_ops.rs
+++ b/crates/gecko/src/cpu/interpreter/ps_ops.rs
@@ -1,7 +1,7 @@
use crate::cpu::condition::ConditionField;
#[inline(always)]
-pub fn ps_ops<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::semantics::Instruction) {
+pub fn ps_ops<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::instruction::Instruction) {
match OP {
crate::cpu::lut::OP_PS_ADD => {
let ps0 = (ctx.cpu.read_fpr(instr.ra()) + ctx.cpu.read_fpr(instr.rb())) as f32 as f64;
@@ -162,7 +162,7 @@ pub fn ps_ops<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::
}
#[inline(always)]
-fn ps_write(ctx: &mut crate::gamecube::GameCube, instr: &crate::cpu::semantics::Instruction, ps0: f64, ps1: f64) {
+fn ps_write(ctx: &mut crate::gamecube::GameCube, instr: &crate::cpu::instruction::Instruction, ps0: f64, ps1: f64) {
ctx.cpu.write_fpr(instr.rd(), ps0);
ctx.cpu.write_ps1(instr.rd(), ps1);
if instr.rc() {
diff --git a/crates/gecko/src/cpu/interpreter/psq.rs b/crates/gecko/src/cpu/interpreter/psq.rs
index ab6982d..a005a96 100644
--- a/crates/gecko/src/cpu/interpreter/psq.rs
+++ b/crates/gecko/src/cpu/interpreter/psq.rs
@@ -115,7 +115,7 @@ fn psq_store(ctx: &mut crate::gamecube::GameCube, fs: u8, addr: u32, w: bool, gq
}
#[inline(always)]
-pub fn store_load_psq<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::semantics::Instruction) {
+pub fn store_load_psq<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::instruction::Instruction) {
use crate::cpu::lut::*;
match OP {
diff --git a/crates/gecko/src/cpu/interpreter/rotate.rs b/crates/gecko/src/cpu/interpreter/rotate.rs
index 531fb73..f962f88 100644
--- a/crates/gecko/src/cpu/interpreter/rotate.rs
+++ b/crates/gecko/src/cpu/interpreter/rotate.rs
@@ -6,7 +6,7 @@ fn mask(mb: u32, me: u32) -> u32 {
}
#[inline(always)]
-pub fn rotate<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::semantics::Instruction) {
+pub fn rotate<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::instruction::Instruction) {
let rs = ctx.cpu.read_gpr(instr.rs());
let mb = instr.mb() as u32;
let me = instr.me() as u32;
diff --git a/crates/gecko/src/cpu/interpreter/store_load.rs b/crates/gecko/src/cpu/interpreter/store_load.rs
index 1af0889..446ed94 100644
--- a/crates/gecko/src/cpu/interpreter/store_load.rs
+++ b/crates/gecko/src/cpu/interpreter/store_load.rs
@@ -1,7 +1,7 @@
use crate::cpu::condition::ConditionField;
#[inline(always)]
-pub fn store_load<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::semantics::Instruction) {
+pub fn store_load<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::instruction::Instruction) {
match OP {
crate::cpu::lut::OP_STW | crate::cpu::lut::OP_STWU => {
let addr = ctx.cpu.read_gpr_or_zero(instr.ra()).wrapping_add_signed(instr.disp());
@@ -151,7 +151,7 @@ pub fn store_load<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: cra
}
#[inline(always)]
-pub fn lwarx(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::semantics::Instruction) {
+pub fn lwarx(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::instruction::Instruction) {
let addr = ctx
.cpu
.read_gpr_or_zero(instr.ra())
@@ -162,7 +162,7 @@ pub fn lwarx(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::semantics::
}
#[inline(always)]
-pub fn stwcx_dot(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::semantics::Instruction) {
+pub fn stwcx_dot(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::instruction::Instruction) {
let addr = ctx
.cpu
.read_gpr_or_zero(instr.ra())
@@ -179,7 +179,7 @@ pub fn stwcx_dot(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::semanti
}
#[inline(always)]
-pub fn store_load_fp<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::semantics::Instruction) {
+pub fn store_load_fp<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::instruction::Instruction) {
match OP {
crate::cpu::lut::OP_LFD | crate::cpu::lut::OP_LFDU => {
let addr = ctx.cpu.read_gpr_or_zero(instr.ra()).wrapping_add_signed(instr.disp());
diff --git a/crates/gecko/src/cpu/interpreter/stubs.rs b/crates/gecko/src/cpu/interpreter/stubs.rs
index b0f6821..99cf3e2 100644
--- a/crates/gecko/src/cpu/interpreter/stubs.rs
+++ b/crates/gecko/src/cpu/interpreter/stubs.rs
@@ -5,7 +5,7 @@ macro_rules! stub {
#[inline(always)]
pub fn $name(
_ctx: &mut crate::gamecube::GameCube,
- _instr: crate::cpu::semantics::Instruction,
+ _instr: crate::cpu::instruction::Instruction,
) {
todo!(stringify!($name))
}
diff --git a/crates/gecko/src/cpu/interpreter/system.rs b/crates/gecko/src/cpu/interpreter/system.rs
index 1ddec66..0a715e6 100644
--- a/crates/gecko/src/cpu/interpreter/system.rs
+++ b/crates/gecko/src/cpu/interpreter/system.rs
@@ -1,7 +1,7 @@
use crate::cpu::sr::Sr;
#[inline(always)]
-pub fn msr<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::semantics::Instruction) {
+pub fn msr<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::instruction::Instruction) {
match OP {
crate::cpu::lut::OP_MTMSR => {
ctx.cpu.msr = crate::cpu::msr::Msr::from(ctx.cpu.read_gpr(instr.rs()));
@@ -20,7 +20,7 @@ pub fn msr<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu
}
#[inline(always)]
-pub fn spr<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::semantics::Instruction) {
+pub fn spr<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::instruction::Instruction) {
match OP {
crate::cpu::lut::OP_MTSPR => {
let spr_num = instr.spr_swapped();
@@ -45,7 +45,7 @@ pub fn spr<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu
}
#[inline(always)]
-pub fn segment<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::semantics::Instruction) {
+pub fn segment<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::instruction::Instruction) {
match OP {
crate::cpu::lut::OP_MTSR => {
ctx.cpu.sr[instr.sr() as usize] = Sr::from_raw(ctx.cpu.read_gpr(instr.rs()));
@@ -58,7 +58,7 @@ pub fn segment<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: crate:
}
#[inline(always)]
-pub fn mftb(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::semantics::Instruction) {
+pub fn mftb(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::instruction::Instruction) {
let tbr = instr.spr_swapped();
let val = match tbr {
268 => ctx.scheduler.timebase_lower(),
@@ -69,9 +69,9 @@ pub fn mftb(ctx: &mut crate::gamecube::GameCube, instr: crate::cpu::semantics::I
}
#[inline(always)]
-pub fn nop<const OP: u32>(_ctx: &mut crate::gamecube::GameCube, _instr: crate::cpu::semantics::Instruction) {}
+pub fn nop<const OP: u32>(_ctx: &mut crate::gamecube::GameCube, _instr: crate::cpu::instruction::Instruction) {}
#[inline(always)]
-pub fn sc(ctx: &mut crate::gamecube::GameCube, _instr: crate::cpu::semantics::Instruction) {
+pub fn sc(ctx: &mut crate::gamecube::GameCube, _instr: crate::cpu::instruction::Instruction) {
ctx.cause_syscall_interrupt();
}
diff --git a/crates/gecko/src/dvd.rs b/crates/gecko/src/dvd.rs
index 8ffc377..2cc6ca6 100644
--- a/crates/gecko/src/dvd.rs
+++ b/crates/gecko/src/dvd.rs
@@ -62,10 +62,10 @@ impl DvdInterface {
let sub2 = self.cmdbuf0 & 0xFFFF;
match (cmd, sub1, sub2) {
- (0xA8, _, 0x0000) => Some(Command::ReadSectorData),
- (0xA8, _, 0x0040) => Some(Command::ReadDiskId),
- (0xE4, 0x00, _) => Some(Command::AudioToggle(false)),
- (0xE4, 0x01, _) => Some(Command::AudioToggle(true)),
+ (0xA8, _, 0x0000) => Some(Command::ReadSectorData),
+ (0xA8, _, 0x0040) => Some(Command::ReadDiskId),
+ (0xE4, 0x00, _) => Some(Command::AudioToggle(false)),
+ (0xE4, 0x01, _) => Some(Command::AudioToggle(true)),
_ => {
tracing::error!(
cmd = format!("{cmd:02X}"),
diff --git a/crates/gecko/src/flipper/dsp.rs b/crates/gecko/src/flipper/dsp.rs
index faf876b..2a07aa8 100644
--- a/crates/gecko/src/flipper/dsp.rs
+++ b/crates/gecko/src/flipper/dsp.rs
@@ -1,10 +1,22 @@
+pub mod instruction;
+pub mod interpreter;
pub mod regs;
+#[allow(dead_code, unused_variables, non_upper_case_globals, clippy::all)]
+pub mod lut {
+ include!(concat!(env!("OUT_DIR"), "/dsp_lut.rs"));
+}
+
+use crate::flipper::dsp::instruction::Instruction;
+use crate::gamecube::GameCube;
use crate::mmio::Mmio;
use crate::mmio::constants::DSP_BASE;
use crate::mmio::traits::{MmioAccess, MmioRegister, MmioRw};
pub struct Dsp {
+ // Registers
+ pub pc: u16,
+
// IMEM = IRAM + IROM
pub iram: Box<[u8; 0x1000]>, // 0x0000 - 0x0FFF
pub irom: Box<[u8; 0x1000]>, // 0x8000 - 0x8FFF
@@ -44,6 +56,7 @@ impl Dsp {
let ifx = unsafe { Box::<[u8; 0x100]>::new_zeroed().assume_init() };
Dsp {
+ pc: 0,
iram,
irom,
dram,
@@ -125,6 +138,18 @@ impl Dsp {
}
}
+impl GameCube {
+ pub fn tick_dsp(&mut self) {
+ if self.dsp.csr.reset() || self.dsp.csr.halt() {
+ return;
+ }
+
+ let instr = Instruction::from_be_bytes(&self.dsp.iram[self.dsp.pc as usize..]);
+ crate::flipper::dsp::lut::dispatch(self, instr);
+ self.dsp.pc += crate::flipper::dsp::lut::instr_size(instr) as u16;
+ }
+}
+
impl MmioRw for Dsp {
const BASE: u32 = DSP_BASE;
const NAME: &'static str = "DSP";
diff --git a/crates/gecko/src/flipper/dsp/instruction.rs b/crates/gecko/src/flipper/dsp/instruction.rs
new file mode 100644
index 0000000..0267eb4
--- /dev/null
+++ b/crates/gecko/src/flipper/dsp/instruction.rs
@@ -0,0 +1,3 @@
+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.rs
new file mode 100644
index 0000000..3a440a9
--- /dev/null
+++ b/crates/gecko/src/flipper/dsp/interpreter.rs
@@ -0,0 +1,381 @@
+use crate::flipper::dsp::instruction::Instruction;
+use crate::gamecube::GameCube;
+
+pub fn nop(_gc: &mut GameCube, _instr: Instruction) {
+ todo!("nop")
+}
+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 maddx(_gc: &mut GameCube, _instr: Instruction) {
+ todo!("maddx")
+}
+pub fn msubx(_gc: &mut GameCube, _instr: Instruction) {
+ todo!("msubx")
+}
+pub fn maddc(_gc: &mut GameCube, _instr: Instruction) {
+ todo!("maddc")
+}
+pub fn msubc(_gc: &mut GameCube, _instr: Instruction) {
+ todo!("msubc")
+}
+pub fn lsl16(_gc: &mut GameCube, _instr: Instruction) {
+ todo!("lsl16")
+}
+pub fn madd(_gc: &mut GameCube, _instr: Instruction) {
+ todo!("madd")
+}
+pub fn lsr16(_gc: &mut GameCube, _instr: Instruction) {
+ todo!("lsr16")
+}
+pub fn msub(_gc: &mut GameCube, _instr: Instruction) {
+ todo!("msub")
+}
+pub fn addpaxz(_gc: &mut GameCube, _instr: Instruction) {
+ todo!("addpaxz")
+}
+pub fn clrl(_gc: &mut GameCube, _instr: Instruction) {
+ todo!("clrl")
+}
+pub fn movpz(_gc: &mut GameCube, _instr: Instruction) {
+ todo!("movpz")
+}
diff --git a/crates/gecko/src/gamecube.rs b/crates/gecko/src/gamecube.rs
index cb27521..db81568 100644
--- a/crates/gecko/src/gamecube.rs
+++ b/crates/gecko/src/gamecube.rs
@@ -1,7 +1,7 @@
#[cfg(feature = "scripting")]
use crate::scripting::{HookFlags, ScriptHookFilters, ScriptHookState, ScriptHost};
use crate::{
- cpu::{self, Cpu, IPL_RESET_VECTOR, semantics::Instruction},
+ cpu::{self, Cpu, IPL_RESET_VECTOR, instruction::Instruction},
dvd::DvdInterface,
flipper::{
ai::AudioInterface,
@@ -203,6 +203,9 @@ impl GameCube {
cpu::lut::dispatch(self, instr);
self.scheduler.cycles += 1;
+ // Tick the DSP
+ self.tick_dsp();
+
// CPU post-hook
#[cfg(feature = "scripting")]
if self.script_hook_flags.contains(HookFlags::CPU_POST) {