Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

ghetto refactor

Laylec63ff0d05ea0
diff --git a/crates/dsptestrunner/src/bin/hazel.rs b/crates/dsptestrunner/src/bin/hazel.rs
index 9e39334..28eb201 100644
--- a/crates/dsptestrunner/src/bin/hazel.rs
+++ b/crates/dsptestrunner/src/bin/hazel.rs
@@ -52,7 +52,7 @@ impl DspTestHarness {
}
#[rustfmt::skip]
-impl Host for DspTestHarness {
+impl Host<{ gecko::system::GC }> for DspTestHarness {
fn hook_state(&self) -> HookState { self.hook_state.clone() }
fn on_cpu_pre(&mut self, _emu: &mut GameCube) {}
diff --git a/crates/gecko/src/cpu.rs b/crates/gecko/src/cpu.rs
index 99fe0c6..d98c171 100644
--- a/crates/gecko/src/cpu.rs
+++ b/crates/gecko/src/cpu.rs
@@ -162,3 +162,16 @@ impl Cpu {
self.spr.xer = self.spr.xer.with_carry(ca);
}
}
+
+#[inline(always)]
+pub fn dispatch<const SYSTEM: crate::system::SystemId>(
+ ctx: &mut crate::system::System<SYSTEM>,
+ instr: instruction::Instruction,
+) {
+ if SYSTEM == crate::system::GC {
+ let ctx: &mut crate::system::System<{ crate::system::GC }> = unsafe { core::mem::transmute(ctx) };
+ self::lut::dispatch(ctx, instr);
+ } else {
+ todo!()
+ }
+}
diff --git a/crates/gecko/src/cpu/dec.rs b/crates/gecko/src/cpu/dec.rs
index 26242af..0a868af 100644
--- a/crates/gecko/src/cpu/dec.rs
+++ b/crates/gecko/src/cpu/dec.rs
@@ -1,5 +1,5 @@
-use crate::gamecube::GameCube;
use crate::scheduler::TIMEBASE_DIVISOR;
+use crate::system::{System, SystemId};
const DEC_INTERRUPT_BIT: u32 = 0x8000_0000;
@@ -54,7 +54,7 @@ pub fn cycles_until_underflow(value: u32) -> u64 {
value as u64 * TIMEBASE_DIVISOR
}
-pub fn underflow_handler(gc: &mut GameCube) {
+pub fn underflow_handler<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>) {
gc.cpu.dec.underflow(gc.scheduler.cycles);
gc.cpu.spr.dec = u32::MAX;
gc.scheduler
diff --git a/crates/gecko/src/cpu/irq.rs b/crates/gecko/src/cpu/irq.rs
index 1a61558..0e3c19d 100644
--- a/crates/gecko/src/cpu/irq.rs
+++ b/crates/gecko/src/cpu/irq.rs
@@ -1,6 +1,6 @@
use crate::cpu::spr::Srr0;
-use crate::gamecube::GameCube;
use crate::mmio::Mmio;
+use crate::system::{System, SystemId};
// Exception vectors
#[rustfmt::skip] pub const IRQ_SYSTEM_RESET: u32 = Mmio::virt_to_phys(0x8000_0100);
@@ -18,7 +18,7 @@ use crate::mmio::Mmio;
#[rustfmt::skip] pub const IRQ_IABR: u32 = Mmio::virt_to_phys(0x8000_1300);
#[rustfmt::skip] pub const IRQ_THERMAL: u32 = Mmio::virt_to_phys(0x8000_1400);
-impl GameCube {
+impl<const SYSTEM: SystemId> System<SYSTEM> {
pub fn cause_external_interrupt(&mut self) {
let base: u32 = if self.cpu.msr.exception_prefix() {
0xFFF0_0000
diff --git a/crates/gecko/src/dvd.rs b/crates/gecko/src/dvd.rs
index 2e0404b..e982398 100644
--- a/crates/gecko/src/dvd.rs
+++ b/crates/gecko/src/dvd.rs
@@ -1,6 +1,6 @@
pub mod regs;
-use crate::gamecube::GameCube;
+use crate::system::{System, SystemId};
pub enum Command {
DriveInfo,
@@ -93,7 +93,7 @@ crate::mmio_device_dispatch! {
}
#[inline(always)]
-pub fn refresh_interrupts(gc: &mut GameCube) {
+pub fn refresh_interrupts<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>) {
use crate::flipper::pi::InterruptFlag;
if gc.di.interrupt_active() {
@@ -103,7 +103,7 @@ pub fn refresh_interrupts(gc: &mut GameCube) {
}
}
-pub fn start_transfer(gc: &mut GameCube) {
+pub fn start_transfer<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>) {
let Some(dvd) = gc.di.dvd.take() else {
// TODO: Setting this causes unrecoverable error when there is no DVD
//gc.di.status.set_device_error(true);
@@ -138,7 +138,7 @@ pub fn start_transfer(gc: &mut GameCube) {
}
#[inline(always)]
-fn process_dvd_command(gc: &mut GameCube, cmd: Command, dvd: &dyn image::Dvd) {
+fn process_dvd_command<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>, cmd: Command, dvd: &dyn image::Dvd) {
match cmd {
Command::DriveInfo => {
let dst = gc.di.dma_address.address();
@@ -183,7 +183,7 @@ fn process_dvd_command(gc: &mut GameCube, cmd: Command, dvd: &dyn image::Dvd) {
}
}
-impl GameCube {
+impl<const SYSTEM: SystemId> System<SYSTEM> {
pub fn insert_dvd(&mut self, dvd: Box<dyn image::Dvd>) {
let name = String::from_utf8_lossy(&dvd.header().game_name);
let name = name.trim_end_matches('\0');
diff --git a/crates/gecko/src/dvd/regs.rs b/crates/gecko/src/dvd/regs.rs
index 2b8e881..5692c6f 100644
--- a/crates/gecko/src/dvd/regs.rs
+++ b/crates/gecko/src/dvd/regs.rs
@@ -1,6 +1,6 @@
use crate::dvd;
-use crate::gamecube::GameCube;
use crate::mmio::traits::{MmioAccess, WriteMask};
+use crate::system::{System, SystemId};
use chapa::BitEnum;
// 0xCC006000 4 R/W DISR - DI Status Register
@@ -31,12 +31,12 @@ pub struct DiStatusRegister {
}
crate::mmio_reg!(DiStatusRegister: u32 @ 0xCC006000);
-impl MmioAccess<GameCube> for DiStatusRegister {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for DiStatusRegister {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.di.status
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
let mut sr = gc.di.status;
if self.break_complete() {
@@ -80,12 +80,12 @@ pub struct DiCoverRegister {
}
crate::mmio_reg!(DiCoverRegister: u32 @ 0xCC006004);
-impl MmioAccess<GameCube> for DiCoverRegister {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for DiCoverRegister {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.di.cover
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
let mut cvr = gc.di.cover;
if self.cover_interrupt() {
@@ -111,12 +111,12 @@ pub struct DiCommandBuf0 {
}
crate::mmio_reg!(DiCommandBuf0: u32 @ 0xCC006008);
-impl MmioAccess<GameCube> for DiCommandBuf0 {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for DiCommandBuf0 {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
DiCommandBuf0::from_raw(gc.di.cmdbuf0)
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
gc.di.cmdbuf0 = self.raw();
let val = self.raw();
tracing::debug!(
@@ -136,12 +136,12 @@ pub struct DiCommandBuf1 {
}
crate::mmio_reg!(DiCommandBuf1: u32 @ 0xCC00600C);
-impl MmioAccess<GameCube> for DiCommandBuf1 {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for DiCommandBuf1 {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
DiCommandBuf1::from_raw(gc.di.cmdbuf1)
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
gc.di.cmdbuf1 = self.raw();
tracing::debug!(val = format!("{:08X}", self.raw()), "DICMDBUF1 write");
}
@@ -155,12 +155,12 @@ pub struct DiCommandBuf2 {
}
crate::mmio_reg!(DiCommandBuf2: u32 @ 0xCC006010);
-impl MmioAccess<GameCube> for DiCommandBuf2 {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for DiCommandBuf2 {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
DiCommandBuf2::from_raw(gc.di.cmdbuf2)
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
gc.di.cmdbuf2 = self.raw();
tracing::debug!(val = format!("{:08X}", self.raw()), "DICMDBUF2 write");
}
@@ -175,7 +175,7 @@ pub struct DiDmaAddressRegister {
pub address: u32,
}
crate::mmio_reg!(DiDmaAddressRegister: u32 @ 0xCC006014);
-crate::mmio_default_access!(DiDmaAddressRegister => GameCube.di.dma_address);
+crate::mmio_default_access!(DiDmaAddressRegister => System.di.dma_address);
// 0xCC006018 4 R/W DILENGTH - DI DMA Transfer Length Register
@@ -186,7 +186,7 @@ pub struct DiDmaLengthRegister {
pub length: u32,
}
crate::mmio_reg!(DiDmaLengthRegister: u32 @ 0xCC006018);
-crate::mmio_default_access!(DiDmaLengthRegister => GameCube.di.dma_length);
+crate::mmio_default_access!(DiDmaLengthRegister => System.di.dma_length);
// 0xCC00601C 4 R/W DICR - DI Control Register
@@ -216,12 +216,12 @@ pub struct DiControlRegister {
}
crate::mmio_reg!(DiControlRegister: u32 @ 0xCC00601C);
-impl MmioAccess<GameCube> for DiControlRegister {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for DiControlRegister {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.di.control
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
gc.di.control = self;
// tstart latches a transfer: resolve the command and run it now.
@@ -245,12 +245,12 @@ pub struct DiImmBuf {
}
crate::mmio_reg!(DiImmBuf: u32 @ 0xCC006020);
-impl MmioAccess<GameCube> for DiImmBuf {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for DiImmBuf {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
DiImmBuf::from_raw(gc.di.immbuf)
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
gc.di.immbuf = self.raw();
}
}
@@ -271,12 +271,12 @@ impl Default for DiConfigurationRegister {
}
}
-impl MmioAccess<GameCube> for DiConfigurationRegister {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for DiConfigurationRegister {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.di.config
}
- fn write(self, _gc: &mut GameCube, _: WriteMask) {
+ fn write(self, _gc: &mut System<SYSTEM>, _: WriteMask) {
// Read-only
}
}
diff --git a/crates/gecko/src/flipper/ai.rs b/crates/gecko/src/flipper/ai.rs
index 77544a2..30559c2 100644
--- a/crates/gecko/src/flipper/ai.rs
+++ b/crates/gecko/src/flipper/ai.rs
@@ -1,6 +1,9 @@
pub mod regs;
-use crate::{flipper::dsp, gamecube::GameCube};
+use crate::{
+ flipper::dsp,
+ system::{System, SystemId},
+};
const CPU_CORE_CLOCK: u64 = 486_000_000;
const AUDIO_DMA_BLOCK_BYTES: u32 = 32;
@@ -60,7 +63,7 @@ crate::mmio_device_dispatch! {
}
#[inline(always)]
-pub fn start_audio_dma(gc: &mut GameCube) {
+pub fn start_audio_dma<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>) {
if !gc.dsp.audio_dma_control.play() {
return;
}
@@ -86,14 +89,14 @@ pub fn start_audio_dma(gc: &mut GameCube) {
}
#[inline(always)]
-pub fn stop_audio_dma(gc: &mut GameCube) {
+pub fn stop_audio_dma<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>) {
gc.scheduler.cancel(self::audio_dma_block_handler);
gc.ai.audio_dma_remaining_blocks = 0;
gc.dsp.csr.set_dma_status(false);
}
#[inline(always)]
-pub fn audio_dma_block_handler(gc: &mut GameCube) {
+pub fn audio_dma_block_handler<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>) {
if !gc.dsp.audio_dma_control.play() {
stop_audio_dma(gc);
return;
@@ -135,7 +138,7 @@ pub fn audio_dma_block_handler(gc: &mut GameCube) {
}
#[inline(always)]
-fn cycles_per_audio_dma_block(gc: &GameCube) -> u64 {
+fn cycles_per_audio_dma_block<const SYSTEM: SystemId>(gc: &System<SYSTEM>) -> u64 {
let sample_rate = if gc.ai.control.dsp_sample_rate() {
32_000
} else {
@@ -146,7 +149,7 @@ fn cycles_per_audio_dma_block(gc: &GameCube) -> u64 {
}
#[inline(always)]
-pub fn refresh_interrupts(gc: &mut GameCube) {
+pub fn refresh_interrupts<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>) {
use crate::flipper::pi::InterruptFlag;
let threshold = gc.ai.interrupt_timing.sample_count();
diff --git a/crates/gecko/src/flipper/ai/regs.rs b/crates/gecko/src/flipper/ai/regs.rs
index 294392b..f867898 100644
--- a/crates/gecko/src/flipper/ai/regs.rs
+++ b/crates/gecko/src/flipper/ai/regs.rs
@@ -1,6 +1,6 @@
use crate::flipper::ai;
-use crate::gamecube::GameCube;
use crate::mmio::traits::{MmioAccess, WriteMask};
+use crate::system::{System, SystemId};
use chapa::BitEnum;
// 0xCC006C00 4 R/W AICR - Audio Interface Control Register
@@ -43,12 +43,12 @@ pub struct AiControl {
}
crate::mmio_reg!(AiControl: u32 @ 0xCC006C00);
-impl MmioAccess<GameCube> for AiControl {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for AiControl {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.ai.control
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
let mut cr = gc.ai.control;
// AIINT is w1c
@@ -86,7 +86,7 @@ pub struct AiVolume {
pub right: u8,
}
crate::mmio_reg!(AiVolume: u32 @ 0xCC006C04);
-crate::mmio_default_access!(AiVolume => GameCube.ai.volume);
+crate::mmio_default_access!(AiVolume => System.ai.volume);
// 0xCC006C08 4 R AISCNT - Audio Interface Sample Counter
@@ -98,13 +98,13 @@ pub struct AiSampleCounter {
}
crate::mmio_reg!(AiSampleCounter: u32 @ 0xCC006C08);
-impl MmioAccess<GameCube> for AiSampleCounter {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for AiSampleCounter {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
let count = gc.ai.sample_count(gc.scheduler.cycles);
AiSampleCounter::from_raw(count)
}
- fn write(self, _gc: &mut GameCube, _: WriteMask) {
+ fn write(self, _gc: &mut System<SYSTEM>, _: WriteMask) {
tracing::warn!("attempted to write to read-only AiSampleCounter");
}
}
@@ -118,12 +118,12 @@ pub struct AiInterruptTiming {
}
crate::mmio_reg!(AiInterruptTiming: u32 @ 0xCC006C0C);
-impl MmioAccess<GameCube> for AiInterruptTiming {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for AiInterruptTiming {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.ai.interrupt_timing
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
gc.ai.interrupt_timing = self;
ai::refresh_interrupts(gc);
}
diff --git a/crates/gecko/src/flipper/cp.rs b/crates/gecko/src/flipper/cp.rs
index 6edc551..615421f 100644
--- a/crates/gecko/src/flipper/cp.rs
+++ b/crates/gecko/src/flipper/cp.rs
@@ -1,6 +1,6 @@
pub mod regs;
-use crate::gamecube::GameCube;
+use crate::system::{System, SystemId};
pub struct CommandProcessor {
pub status: regs::CpStatus,
@@ -76,7 +76,7 @@ crate::mmio_device_dispatch! {
}
#[inline(always)]
-pub fn refresh_interrupts(gc: &mut GameCube) {
+pub fn refresh_interrupts<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>) {
use crate::flipper::pi::InterruptFlag;
if gc.cp.interrupt_active() {
diff --git a/crates/gecko/src/flipper/cp/regs.rs b/crates/gecko/src/flipper/cp/regs.rs
index 005dff6..014f80c 100644
--- a/crates/gecko/src/flipper/cp/regs.rs
+++ b/crates/gecko/src/flipper/cp/regs.rs
@@ -1,6 +1,6 @@
use crate::flipper::cp;
-use crate::gamecube::GameCube;
use crate::mmio::traits::{MmioAccess, WriteMask};
+use crate::system::{System, SystemId};
// 0xCC000000 2 R/W CP_STATUS (CP Status Register)
@@ -24,12 +24,12 @@ pub struct CpStatus {
}
crate::mmio_reg!(CpStatus: u16 @ 0xCC000000);
-impl MmioAccess<GameCube> for CpStatus {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for CpStatus {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.cp.status
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
gc.cp.status = self;
cp::refresh_interrupts(gc);
}
@@ -60,12 +60,12 @@ pub struct CpControl {
}
crate::mmio_reg!(CpControl: u16 @ 0xCC000002);
-impl MmioAccess<GameCube> for CpControl {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for CpControl {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.cp.control
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
gc.cp.control = self;
cp::refresh_interrupts(gc);
}
@@ -84,13 +84,13 @@ pub struct CpClear {
}
crate::mmio_reg!(CpClear: u16 @ 0xCC000004);
-impl MmioAccess<GameCube> for CpClear {
- fn read(_gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for CpClear {
+ fn read(_gc: &mut System<SYSTEM>) -> Self {
tracing::warn!("attempted to read from write only CpClear register");
Self::from_raw(0)
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
if self.clear_overflow() {
gc.cp.status = gc.cp.status.with_fifo_overflow(false);
}
@@ -107,82 +107,82 @@ impl MmioAccess<GameCube> for CpClear {
#[derive(Copy, Clone, Debug)]
pub struct FifoBaseLo {}
crate::mmio_reg!(FifoBaseLo: u16 @ 0xCC000020);
-crate::mmio_default_access!(FifoBaseLo => GameCube.cp.fifo_base_lo);
+crate::mmio_default_access!(FifoBaseLo => System.cp.fifo_base_lo);
#[chapa::bitfield(u16, order = lsb0)]
#[derive(Copy, Clone, Debug)]
pub struct FifoBaseHi {}
crate::mmio_reg!(FifoBaseHi: u16 @ 0xCC000022);
-crate::mmio_default_access!(FifoBaseHi => GameCube.cp.fifo_base_hi);
+crate::mmio_default_access!(FifoBaseHi => System.cp.fifo_base_hi);
#[chapa::bitfield(u16, order = lsb0)]
#[derive(Copy, Clone, Debug)]
pub struct FifoEndLo {}
crate::mmio_reg!(FifoEndLo: u16 @ 0xCC000024);
-crate::mmio_default_access!(FifoEndLo => GameCube.cp.fifo_end_lo);
+crate::mmio_default_access!(FifoEndLo => System.cp.fifo_end_lo);
#[chapa::bitfield(u16, order = lsb0)]
#[derive(Copy, Clone, Debug)]
pub struct FifoEndHi {}
crate::mmio_reg!(FifoEndHi: u16 @ 0xCC000026);
-crate::mmio_default_access!(FifoEndHi => GameCube.cp.fifo_end_hi);
+crate::mmio_default_access!(FifoEndHi => System.cp.fifo_end_hi);
#[chapa::bitfield(u16, order = lsb0)]
#[derive(Copy, Clone, Debug)]
pub struct FifoHiWatermarkLo {}
crate::mmio_reg!(FifoHiWatermarkLo: u16 @ 0xCC000028);
-crate::mmio_default_access!(FifoHiWatermarkLo => GameCube.cp.fifo_hi_watermark_lo);
+crate::mmio_default_access!(FifoHiWatermarkLo => System.cp.fifo_hi_watermark_lo);
#[chapa::bitfield(u16, order = lsb0)]
#[derive(Copy, Clone, Debug)]
pub struct FifoHiWatermarkHi {}
crate::mmio_reg!(FifoHiWatermarkHi: u16 @ 0xCC00002A);
-crate::mmio_default_access!(FifoHiWatermarkHi => GameCube.cp.fifo_hi_watermark_hi);
+crate::mmio_default_access!(FifoHiWatermarkHi => System.cp.fifo_hi_watermark_hi);
#[chapa::bitfield(u16, order = lsb0)]
#[derive(Copy, Clone, Debug)]
pub struct FifoLoWatermarkLo {}
crate::mmio_reg!(FifoLoWatermarkLo: u16 @ 0xCC00002C);
-crate::mmio_default_access!(FifoLoWatermarkLo => GameCube.cp.fifo_lo_watermark_lo);
+crate::mmio_default_access!(FifoLoWatermarkLo => System.cp.fifo_lo_watermark_lo);
#[chapa::bitfield(u16, order = lsb0)]
#[derive(Copy, Clone, Debug)]
pub struct FifoLoWatermarkHi {}
crate::mmio_reg!(FifoLoWatermarkHi: u16 @ 0xCC00002E);
-crate::mmio_default_access!(FifoLoWatermarkHi => GameCube.cp.fifo_lo_watermark_hi);
+crate::mmio_default_access!(FifoLoWatermarkHi => System.cp.fifo_lo_watermark_hi);
#[chapa::bitfield(u16, order = lsb0)]
#[derive(Copy, Clone, Debug)]
pub struct FifoRwDistanceLo {}
crate::mmio_reg!(FifoRwDistanceLo: u16 @ 0xCC000030);
-crate::mmio_default_access!(FifoRwDistanceLo => GameCube.cp.fifo_rw_distance_lo);
+crate::mmio_default_access!(FifoRwDistanceLo => System.cp.fifo_rw_distance_lo);
#[chapa::bitfield(u16, order = lsb0)]
#[derive(Copy, Clone, Debug)]
pub struct FifoRwDistanceHi {}
crate::mmio_reg!(FifoRwDistanceHi: u16 @ 0xCC000032);
-crate::mmio_default_access!(FifoRwDistanceHi => GameCube.cp.fifo_rw_distance_hi);
+crate::mmio_default_access!(FifoRwDistanceHi => System.cp.fifo_rw_distance_hi);
#[chapa::bitfield(u16, order = lsb0)]
#[derive(Copy, Clone, Debug)]
pub struct FifoWritePtrLo {}
crate::mmio_reg!(FifoWritePtrLo: u16 @ 0xCC000034);
-crate::mmio_default_access!(FifoWritePtrLo => GameCube.cp.fifo_write_ptr_lo);
+crate::mmio_default_access!(FifoWritePtrLo => System.cp.fifo_write_ptr_lo);
#[chapa::bitfield(u16, order = lsb0)]
#[derive(Copy, Clone, Debug)]
pub struct FifoWritePtrHi {}
crate::mmio_reg!(FifoWritePtrHi: u16 @ 0xCC000036);
-crate::mmio_default_access!(FifoWritePtrHi => GameCube.cp.fifo_write_ptr_hi);
+crate::mmio_default_access!(FifoWritePtrHi => System.cp.fifo_write_ptr_hi);
#[chapa::bitfield(u16, order = lsb0)]
#[derive(Copy, Clone, Debug)]
pub struct FifoReadPtrLo {}
crate::mmio_reg!(FifoReadPtrLo: u16 @ 0xCC000038);
-crate::mmio_default_access!(FifoReadPtrLo => GameCube.cp.fifo_read_ptr_lo);
+crate::mmio_default_access!(FifoReadPtrLo => System.cp.fifo_read_ptr_lo);
#[chapa::bitfield(u16, order = lsb0)]
#[derive(Copy, Clone, Debug)]
pub struct FifoReadPtrHi {}
crate::mmio_reg!(FifoReadPtrHi: u16 @ 0xCC00003A);
-crate::mmio_default_access!(FifoReadPtrHi => GameCube.cp.fifo_read_ptr_hi);
+crate::mmio_default_access!(FifoReadPtrHi => System.cp.fifo_read_ptr_hi);
diff --git a/crates/gecko/src/flipper/dsp.rs b/crates/gecko/src/flipper/dsp.rs
index 0e8d891..04f820a 100644
--- a/crates/gecko/src/flipper/dsp.rs
+++ b/crates/gecko/src/flipper/dsp.rs
@@ -12,8 +12,8 @@ pub mod lut {
}
use crate::flipper::dsp::instruction::Instruction;
-use crate::gamecube::GameCube;
use crate::mmio::Mmio;
+use crate::system::{GC, System, SystemId};
pub struct Dsp {
// Registers
@@ -174,7 +174,7 @@ impl Dsp {
}
}
-impl GameCube {
+impl<const SYSTEM: SystemId> System<SYSTEM> {
/// Execute a single DSP instruction. Returns `false` if the DSP is halted or
/// in reset (no instruction was executed).
#[inline(always)]
@@ -206,10 +206,10 @@ impl GameCube {
self.dsp.registers.cache_ext_ac();
}
- lut::dispatch(self, instr);
+ self::dispatch(self, instr);
if let Some(ext) = ext_op {
- lut::dispatch_gc_dsp_ext(self, instruction::GcDspExt(ext));
+ self::dispatch_gc_dsp_ext(self, instruction::GcDspExt(ext));
}
// Check if we've reached the end of a loop.
@@ -290,7 +290,7 @@ impl Dsp {
}
#[inline(always)]
-pub fn refresh_interrupts(gc: &mut GameCube) {
+pub fn refresh_interrupts<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>) {
use crate::flipper::pi::InterruptFlag;
if gc.dsp.interrupt_active() {
@@ -301,7 +301,7 @@ pub fn refresh_interrupts(gc: &mut GameCube) {
}
#[inline(always)]
-pub fn read_dmem(gc: &mut GameCube, addr: u16) -> u16 {
+pub fn read_dmem<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>, addr: u16) -> u16 {
match addr {
0x0000..0x1000 => read_word(&*gc.dsp.dram, addr),
0x1000..0x2000 => read_word(&*gc.dsp.coef, addr - 0x1000),
@@ -311,7 +311,7 @@ pub fn read_dmem(gc: &mut GameCube, addr: u16) -> u16 {
}
#[inline(always)]
-pub fn write_dmem(gc: &mut GameCube, addr: u16, value: u16) {
+pub fn write_dmem<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>, addr: u16, value: u16) {
match addr {
0x0000..0x1000 => write_word(&mut *gc.dsp.dram, addr, value),
0xFF00..=0xFFFF => write_ifx(gc, addr, value),
@@ -320,7 +320,7 @@ pub fn write_dmem(gc: &mut GameCube, addr: u16, value: u16) {
}
#[inline(always)]
-fn read_ifx(gc: &mut GameCube, addr: u16) -> u16 {
+fn read_ifx<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>, addr: u16) -> u16 {
match addr {
// CMBH (CPU Mailbox High): reading returns data + M bit.
// M is only cleared when CMBL is read.
@@ -348,7 +348,7 @@ fn read_ifx(gc: &mut GameCube, addr: u16) -> u16 {
}
#[inline(always)]
-fn write_ifx(gc: &mut GameCube, addr: u16, value: u16) {
+fn write_ifx<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>, addr: u16, value: u16) {
match addr {
// DMBH (DSP Mailbox High): store data bits (14:0), busy is preserved
addr::IFX_DMBH => {
@@ -402,3 +402,23 @@ fn write_word(mem: &mut [u8], word_addr: u16, value: u16) {
let off = word_addr as usize * 2;
mem[off..off + 2].copy_from_slice(&value.to_be_bytes());
}
+
+#[inline(always)]
+pub fn dispatch<const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: Instruction) {
+ if SYSTEM == GC {
+ let ctx: &mut System<{ GC }> = unsafe { ::core::mem::transmute(ctx) };
+ self::lut::dispatch(ctx, instr);
+ } else {
+ todo!()
+ }
+}
+
+#[inline(always)]
+pub fn dispatch_gc_dsp_ext<const SYSTEM: SystemId>(ctx: &mut System<SYSTEM>, instr: instruction::GcDspExt) {
+ if SYSTEM == GC {
+ let ctx: &mut System<{ GC }> = unsafe { ::core::mem::transmute(ctx) };
+ self::lut::dispatch_gc_dsp_ext(ctx, instr);
+ } else {
+ todo!()
+ }
+}
\ No newline at end of file
diff --git a/crates/gecko/src/flipper/dsp/interpreter.rs b/crates/gecko/src/flipper/dsp/interpreter.rs
index 8e64596..262fb21 100644
--- a/crates/gecko/src/flipper/dsp/interpreter.rs
+++ b/crates/gecko/src/flipper/dsp/interpreter.rs
@@ -4,7 +4,6 @@ use crate::flipper::dsp::core::regs::{SignExtensionMode, StatusRegister};
use crate::flipper::dsp::core::{Registers, reg};
use crate::flipper::dsp::instruction::Instruction;
use crate::flipper::dsp::lut::*;
-use crate::gamecube::GameCube;
#[inline(always)]
fn multiply(regs: &mut Registers, a: i16, b: i16) {
@@ -85,7 +84,7 @@ fn apply_combined_add_product_oc(regs: &mut Registers, pc: bool, po: bool, os_be
}
#[inline(always)]
-fn move_prod_to_ac(ctx: &mut GameCube, r: u8) {
+fn move_prod_to_ac(ctx: &mut crate::gamecube::GameCube, r: u8) {
let prod = ctx.dsp.registers.product();
let (carry, overflow) = ctx.dsp.registers.product_flags();
ctx.dsp.registers.set_ac(r, prod);
@@ -94,7 +93,7 @@ fn move_prod_to_ac(ctx: &mut GameCube, r: u8) {
}
#[inline(always)]
-fn move_prod_to_ac_zero(ctx: &mut GameCube, r: u8) {
+fn move_prod_to_ac_zero(ctx: &mut crate::gamecube::GameCube, r: u8) {
let (carry, overflow) = ctx.dsp.registers.product_flags();
let raw = ctx.dsp.registers.product();
let (prod, rounding_carry) = round_half_to_even(raw);
@@ -104,7 +103,7 @@ fn move_prod_to_ac_zero(ctx: &mut GameCube, r: u8) {
}
#[inline(always)]
-fn add_prod_to_ac(ctx: &mut GameCube, r: u8) {
+fn add_prod_to_ac(ctx: &mut crate::gamecube::GameCube, r: u8) {
let a = ctx.dsp.registers.ac(r);
let (pc, po) = ctx.dsp.registers.product_flags();
let b = ctx.dsp.registers.product();
@@ -181,7 +180,7 @@ fn mulc_operands(regs: &Registers, s: u8, t: u8) -> (i16, i16) {
}
#[inline(always)]
-pub fn add_sub<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
+pub fn add_sub<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
match OP {
OP_ADDR => {
let ss = instr.ss() as usize;
@@ -292,7 +291,7 @@ pub fn add_sub<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
}
#[inline(always)]
-pub fn addr_reg<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
+pub fn addr_reg<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
match OP {
OP_DAR => {
let d = instr.d_14_15() as usize;
@@ -318,7 +317,7 @@ pub fn addr_reg<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
}
#[inline(always)]
-pub fn cmp_test<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
+pub fn cmp_test<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
match OP {
OP_CMP => {
let a = ctx.dsp.registers.ac(0);
@@ -390,7 +389,7 @@ pub fn cmp_test<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
}
#[inline(always)]
-pub fn control<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
+pub fn control<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
match OP {
OP_JCC => {
let branch_control = BranchControl::from(instr.cond());
@@ -446,7 +445,7 @@ pub fn control<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
}
#[inline(always)]
-pub fn imm_alu<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
+pub fn imm_alu<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
match OP {
OP_ADDI => {
let d = instr.d_7_7();
@@ -525,7 +524,7 @@ pub fn imm_alu<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
}
#[inline(always)]
-pub fn inc_dec<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
+pub fn inc_dec<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
match OP {
OP_INCM => {
let d = instr.d_7_7();
@@ -583,7 +582,7 @@ pub fn inc_dec<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
}
#[inline(always)]
-pub fn load_store<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
+pub fn load_store<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
match OP {
OP_LRI => {
ctx.dsp.registers.write::<true>(instr.d_11_15(), instr.imm_16_31());
@@ -688,7 +687,7 @@ pub fn load_store<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
}
#[inline(always)]
-pub fn logic<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
+pub fn logic<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
match OP {
OP_XORR => {
let s = instr.s_6_6() as usize;
@@ -761,7 +760,7 @@ pub fn logic<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
}
#[inline(always)]
-pub fn loops<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
+pub fn loops<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
match OP {
OP_LOOP_REG | OP_LOOPI => {
let counter = match OP {
@@ -798,7 +797,7 @@ pub fn loops<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
}
#[inline(always)]
-pub fn move_ops<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
+pub fn move_ops<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
match OP {
OP_MOVR => {
let ss = instr.ss();
@@ -853,7 +852,7 @@ pub fn move_ops<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
}
#[inline(always)]
-pub fn mul<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
+pub fn mul<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
match OP {
OP_MUL => {
let s = instr.r_4_4() as usize;
@@ -950,7 +949,7 @@ pub fn mul<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
}
#[inline(always)]
-pub fn shifts<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
+pub fn shifts<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
match OP {
OP_LSL | OP_ASL => {
let r = instr.r_7_7();
@@ -1048,7 +1047,7 @@ pub fn shifts<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
}
#[inline(always)]
-pub fn status<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
+pub fn status<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: Instruction) {
match OP {
OP_SBCLR => {
let idx = 6 + instr.bit();
@@ -1088,10 +1087,10 @@ pub fn status<const OP: u32>(ctx: &mut GameCube, instr: Instruction) {
use dsp::instruction::GcDspExt;
#[inline(always)]
-pub fn ext_nop(_ctx: &mut GameCube, _instr: GcDspExt) {}
+pub fn ext_nop(_ctx: &mut crate::gamecube::GameCube, _instr: GcDspExt) {}
#[inline(always)]
-pub fn ext_addr<const OP: u32>(ctx: &mut GameCube, instr: GcDspExt) {
+pub fn ext_addr<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: GcDspExt) {
let r = instr.r_6_7() as usize;
match OP {
OP_EXT_DR => ctx.dsp.registers.ar[r] = ctx.dsp.registers.decrement_ar(r),
@@ -1105,7 +1104,7 @@ pub fn ext_addr<const OP: u32>(ctx: &mut GameCube, instr: GcDspExt) {
}
#[inline(always)]
-pub fn ext_mv(ctx: &mut GameCube, instr: GcDspExt) {
+pub fn ext_mv(ctx: &mut crate::gamecube::GameCube, instr: GcDspExt) {
let d = instr.d_4_5();
let s = instr.s_6_7();
let value = ctx.dsp.registers.ext_ac_cache[s as usize];
@@ -1113,7 +1112,7 @@ pub fn ext_mv(ctx: &mut GameCube, instr: GcDspExt) {
}
#[inline(always)]
-pub fn ext_store<const OP: u32>(ctx: &mut GameCube, instr: GcDspExt) {
+pub fn ext_store<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: GcDspExt) {
let d = instr.d_6_7() as usize;
let s = instr.s_3_4();
let value = ctx.dsp.registers.ext_ac_cache[s as usize];
@@ -1132,7 +1131,7 @@ pub fn ext_store<const OP: u32>(ctx: &mut GameCube, instr: GcDspExt) {
}
#[inline(always)]
-pub fn ext_load<const OP: u32>(ctx: &mut GameCube, instr: GcDspExt) {
+pub fn ext_load<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: GcDspExt) {
let d = instr.d_2_4();
let s = instr.s_6_7() as usize;
let addr = ctx.dsp.registers.ar[s];
@@ -1151,7 +1150,7 @@ pub fn ext_load<const OP: u32>(ctx: &mut GameCube, instr: GcDspExt) {
}
#[inline(always)]
-pub fn ext_load_store<const OP: u32>(ctx: &mut GameCube, instr: GcDspExt) {
+pub fn ext_load_store<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: GcDspExt) {
let s = instr.s_7_7() as usize;
let d = instr.d_2_3();
@@ -1206,7 +1205,7 @@ pub fn ext_load_store<const OP: u32>(ctx: &mut GameCube, instr: GcDspExt) {
}
#[inline(always)]
-pub fn ext_ld<const OP: u32>(ctx: &mut GameCube, instr: GcDspExt) {
+pub fn ext_ld<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: GcDspExt) {
let d = instr.d_2_2();
let r = instr.r_3_3();
let s = instr.s_6_7() as usize;
@@ -1249,7 +1248,7 @@ pub fn ext_ld<const OP: u32>(ctx: &mut GameCube, instr: GcDspExt) {
}
#[inline(always)]
-pub fn ext_ldax<const OP: u32>(ctx: &mut GameCube, instr: GcDspExt) {
+pub fn ext_ldax<const OP: u32>(ctx: &mut crate::gamecube::GameCube, instr: GcDspExt) {
let s = instr.d_2_2() as usize;
let r = instr.r_3_3() as usize;
diff --git a/crates/gecko/src/flipper/dsp/regs.rs b/crates/gecko/src/flipper/dsp/regs.rs
index 41a7e3c..5392e9b 100644
--- a/crates/gecko/src/flipper/dsp/regs.rs
+++ b/crates/gecko/src/flipper/dsp/regs.rs
@@ -1,6 +1,6 @@
use crate::flipper::{ai, dsp};
-use crate::gamecube::GameCube;
use crate::mmio::traits::{MmioAccess, WriteMask};
+use crate::system::{System, SystemId};
use chapa::BitEnum;
// 0xCC00500A 2 [R/W] CSR - DSP Control/Status Register
@@ -64,12 +64,12 @@ impl Default for ControlStatus {
}
}
-impl MmioAccess<GameCube> for ControlStatus {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for ControlStatus {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.dsp.csr
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
tracing::trace!("CSR write: {:016b} (prev: {:016b})", self.raw(), gc.dsp.csr.raw());
let mut csr = gc.dsp.csr;
@@ -133,12 +133,12 @@ pub struct MailboxToDspHi {
}
crate::mmio_reg!(MailboxToDspHi: u16 @ 0xCC005000);
-impl MmioAccess<GameCube> for MailboxToDspHi {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for MailboxToDspHi {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.dsp.mailbox_to_dsp_hi
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
// CPU writing CMBH sets data bits (14:0), busy is preserved
gc.dsp.mailbox_to_dsp_hi = self.with_busy(gc.dsp.mailbox_to_dsp_hi.busy());
}
@@ -152,12 +152,12 @@ impl MmioAccess<GameCube> for MailboxToDspHi {
pub struct MailboxToDspLo {}
crate::mmio_reg!(MailboxToDspLo: u16 @ 0xCC005002);
-impl MmioAccess<GameCube> for MailboxToDspLo {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for MailboxToDspLo {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.dsp.mailbox_to_dsp_lo
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
gc.dsp.mailbox_to_dsp_lo = self;
gc.dsp.mailbox_to_dsp_hi = gc.dsp.mailbox_to_dsp_hi.with_busy(true);
tracing::debug!(
@@ -181,12 +181,12 @@ pub struct MailboxToCpuHi {
}
crate::mmio_reg!(MailboxToCpuHi: u16 @ 0xCC005004);
-impl MmioAccess<GameCube> for MailboxToCpuHi {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for MailboxToCpuHi {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.dsp.mailbox_to_cpu_hi
}
- fn write(self, _gc: &mut GameCube, _: WriteMask) {
+ fn write(self, _gc: &mut System<SYSTEM>, _: WriteMask) {
// Read-only from CPU side
}
}
@@ -199,15 +199,15 @@ impl MmioAccess<GameCube> for MailboxToCpuHi {
pub struct MailboxToCpuLo {}
crate::mmio_reg!(MailboxToCpuLo: u16 @ 0xCC005006);
-impl MmioAccess<GameCube> for MailboxToCpuLo {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for MailboxToCpuLo {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
let val = gc.dsp.mailbox_to_cpu_lo;
// Reading DMBL clears DMBH.M (bit 15), signaling the CPU has consumed the mail
gc.dsp.mailbox_to_cpu_hi.set_busy(false);
val
}
- fn write(self, _gc: &mut GameCube, _: WriteMask) {
+ fn write(self, _gc: &mut System<SYSTEM>, _: WriteMask) {
// Read-only from CPU side
}
}
@@ -218,7 +218,7 @@ impl MmioAccess<GameCube> for MailboxToCpuLo {
#[derive(Copy, Clone, Debug)]
pub struct AramInfo {}
crate::mmio_reg!(AramInfo: u16 @ 0xCC005012);
-crate::mmio_default_access!(AramInfo => GameCube.dsp.aram_info);
+crate::mmio_default_access!(AramInfo => System.dsp.aram_info);
// 0xCC005016 2 [R/W] AR_MODE - ARAM Mode
@@ -230,12 +230,12 @@ pub struct AramMode {
}
crate::mmio_reg!(AramMode: u16 @ 0xCC005016);
-impl MmioAccess<GameCube> for AramMode {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for AramMode {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.dsp.aram_mode.with_status(true)
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
gc.dsp.aram_mode = self;
}
}
@@ -246,7 +246,7 @@ impl MmioAccess<GameCube> for AramMode {
#[derive(Copy, Clone, Debug)]
pub struct AramRefresh {}
crate::mmio_reg!(AramRefresh: u16 @ 0xCC00501A);
-crate::mmio_default_access!(AramRefresh => GameCube.dsp.aram_refresh);
+crate::mmio_default_access!(AramRefresh => System.dsp.aram_refresh);
// 0xCC005020 4 [R/W] ARAM DMA MMIO Address
@@ -254,7 +254,7 @@ crate::mmio_default_access!(AramRefresh => GameCube.dsp.aram_refresh);
#[derive(Copy, Clone, Debug)]
pub struct AramDmaMmioAddr {}
crate::mmio_reg!(AramDmaMmioAddr: u32 @ 0xCC005020);
-crate::mmio_default_access!(AramDmaMmioAddr => GameCube.dsp.aram_dma_mmio_addr);
+crate::mmio_default_access!(AramDmaMmioAddr => System.dsp.aram_dma_mmio_addr);
// 0xCC005024 4 [R/W] ARAM DMA ARAM Address
@@ -262,7 +262,7 @@ crate::mmio_default_access!(AramDmaMmioAddr => GameCube.dsp.aram_dma_mmio_addr);
#[derive(Copy, Clone, Debug)]
pub struct AramDmaAramAddr {}
crate::mmio_reg!(AramDmaAramAddr: u32 @ 0xCC005024);
-crate::mmio_default_access!(AramDmaAramAddr => GameCube.dsp.aram_dma_aram_addr);
+crate::mmio_default_access!(AramDmaAramAddr => System.dsp.aram_dma_aram_addr);
// 0xCC005030 4 [W] Audio DMA Start Address (High + Low)
@@ -270,7 +270,7 @@ crate::mmio_default_access!(AramDmaAramAddr => GameCube.dsp.aram_dma_aram_addr);
#[derive(Copy, Clone, Debug)]
pub struct AudioDmaStartAddr {}
crate::mmio_reg!(AudioDmaStartAddr: u32 @ 0xCC005030);
-crate::mmio_default_access!(AudioDmaStartAddr => GameCube.dsp.audio_dma_start_addr);
+crate::mmio_default_access!(AudioDmaStartAddr => System.dsp.audio_dma_start_addr);
// 0xCC005036 2 [W] Audio DMA Control/Length
@@ -285,12 +285,12 @@ pub struct AudioDmaControl {
}
crate::mmio_reg!(AudioDmaControl: u16 @ 0xCC005036);
-impl MmioAccess<GameCube> for AudioDmaControl {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for AudioDmaControl {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.dsp.audio_dma_control
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
let was_playing = gc.dsp.audio_dma_control.play();
gc.dsp.audio_dma_control = self;
match (was_playing, self.play()) {
@@ -321,12 +321,12 @@ pub struct AramDmaControl {
}
crate::mmio_reg!(AramDmaControl: u32 @ 0xCC005028);
-impl MmioAccess<GameCube> for AramDmaControl {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for AramDmaControl {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.dsp.aram_dma_control
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
gc.dsp.aram_dma_control = self;
const ARAM_DMA_DELAY: u64 = 10_000;
diff --git a/crates/gecko/src/flipper/exi.rs b/crates/gecko/src/flipper/exi.rs
index 43c6e83..0ed0dbc 100644
--- a/crates/gecko/src/flipper/exi.rs
+++ b/crates/gecko/src/flipper/exi.rs
@@ -3,7 +3,7 @@ pub mod macronix;
pub mod regs;
use crate::flipper::exi::regs::TransferType;
-use crate::gamecube::GameCube;
+use crate::system::{System, SystemId};
pub struct ExternalInterface {
// Channel 0
@@ -197,7 +197,7 @@ crate::mmio_device_dispatch! {
}
#[inline(always)]
-pub fn refresh_interrupts(gc: &mut GameCube) {
+pub fn refresh_interrupts<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>) {
use crate::flipper::pi::InterruptFlag;
if gc.exi.interrupt_active() {
@@ -208,7 +208,7 @@ pub fn refresh_interrupts(gc: &mut GameCube) {
}
#[inline(always)]
-pub fn on_chip_select_written<const CHANNEL: usize>(gc: &mut GameCube, new_cs: u8) {
+pub fn on_chip_select_written<const CHANNEL: usize, const SYSTEM: SystemId>(gc: &mut System<SYSTEM>, new_cs: u8) {
let prev = gc.exi.prev_cs[CHANNEL];
if new_cs != prev && new_cs != 0 {
if let Some(slot) = ExternalInterface::cs_to_slot(new_cs)
@@ -221,7 +221,7 @@ pub fn on_chip_select_written<const CHANNEL: usize>(gc: &mut GameCube, new_cs: u
}
#[inline(always)]
-pub fn run_dma<const CHANNEL: usize>(gc: &mut GameCube) {
+pub fn run_dma<const CHANNEL: usize, const SYSTEM: SystemId>(gc: &mut System<SYSTEM>) {
let (cs, transfer_type, address, length) = match CHANNEL {
0 => (
gc.exi.ch0_csr.chip_select(),
diff --git a/crates/gecko/src/flipper/exi/regs.rs b/crates/gecko/src/flipper/exi/regs.rs
index 7afb9a5..6faca94 100644
--- a/crates/gecko/src/flipper/exi/regs.rs
+++ b/crates/gecko/src/flipper/exi/regs.rs
@@ -1,8 +1,8 @@
use chapa::BitEnum;
use crate::flipper::exi;
-use crate::gamecube::GameCube;
use crate::mmio::traits::{MmioAccess, MmioRegister, WriteMask};
+use crate::system::{System, SystemId};
pub trait ChannelStatus {
fn exi_interrupt(&self) -> bool;
@@ -90,13 +90,13 @@ pub struct Channel0Status {
}
crate::mmio_reg!(Channel0Status: u32 @ 0xCC006800);
-impl MmioAccess<GameCube> for Channel0Status {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for Channel0Status {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.exi.ch0_csr
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
write_csr(&mut gc.exi.ch0_csr, self);
- exi::on_chip_select_written::<0>(gc, self.chip_select());
+ exi::on_chip_select_written::<0, SYSTEM>(gc, self.chip_select());
exi::refresh_interrupts(gc);
}
}
@@ -110,7 +110,7 @@ pub struct Channel0DmaAddress {
pub address: u32,
}
crate::mmio_reg!(Channel0DmaAddress: u32 @ 0xCC006804);
-crate::mmio_default_access!(Channel0DmaAddress => GameCube.exi.ch0_mar);
+crate::mmio_default_access!(Channel0DmaAddress => System.exi.ch0_mar);
// 0xCC006808 4 R/W EXI0LENGTH - EXI Channel 0 DMA Transfer Length
@@ -121,7 +121,7 @@ pub struct Channel0DmaLength {
pub length: u32,
}
crate::mmio_reg!(Channel0DmaLength: u32 @ 0xCC006808);
-crate::mmio_default_access!(Channel0DmaLength => GameCube.exi.ch0_length);
+crate::mmio_default_access!(Channel0DmaLength => System.exi.ch0_length);
// 0xCC00680C 4 R/W EXI0CR - EXI Channel 0 Control Register
@@ -139,16 +139,16 @@ pub struct Channel0Control {
}
crate::mmio_reg!(Channel0Control: u32 @ 0xCC00680C);
-impl MmioAccess<GameCube> for Channel0Control {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for Channel0Control {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.exi.ch0_cr
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
let was_started = gc.exi.ch0_cr.transfer_start();
gc.exi.ch0_cr = self;
if self.transfer_start() && !was_started {
if self.dma_mode() {
- exi::run_dma::<0>(gc);
+ exi::run_dma::<0, SYSTEM>(gc);
} else {
gc.exi.start_immediate_transfer::<0>();
}
@@ -163,7 +163,7 @@ impl MmioAccess<GameCube> for Channel0Control {
#[derive(Copy, Clone, Debug)]
pub struct Channel0Data {}
crate::mmio_reg!(Channel0Data: u32 @ 0xCC006810);
-crate::mmio_default_access!(Channel0Data => GameCube.exi.ch0_data);
+crate::mmio_default_access!(Channel0Data => System.exi.ch0_data);
// --- Channel 1 ---
@@ -193,13 +193,13 @@ pub struct Channel1Status {
}
crate::mmio_reg!(Channel1Status: u32 @ 0xCC006814);
-impl MmioAccess<GameCube> for Channel1Status {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for Channel1Status {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.exi.ch1_csr
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
write_csr(&mut gc.exi.ch1_csr, self);
- exi::on_chip_select_written::<1>(gc, self.chip_select());
+ exi::on_chip_select_written::<1, SYSTEM>(gc, self.chip_select());
exi::refresh_interrupts(gc);
}
}
@@ -213,7 +213,7 @@ pub struct Channel1DmaAddress {
pub address: u32,
}
crate::mmio_reg!(Channel1DmaAddress: u32 @ 0xCC006818);
-crate::mmio_default_access!(Channel1DmaAddress => GameCube.exi.ch1_mar);
+crate::mmio_default_access!(Channel1DmaAddress => System.exi.ch1_mar);
// 0xCC00681C 4 R/W EXI1LENGTH - EXI Channel 1 DMA Transfer Length
@@ -224,7 +224,7 @@ pub struct Channel1DmaLength {
pub length: u32,
}
crate::mmio_reg!(Channel1DmaLength: u32 @ 0xCC00681C);
-crate::mmio_default_access!(Channel1DmaLength => GameCube.exi.ch1_length);
+crate::mmio_default_access!(Channel1DmaLength => System.exi.ch1_length);
// 0xCC006820 4 R/W EXI1CR - EXI Channel 1 Control Register
@@ -242,16 +242,16 @@ pub struct Channel1Control {
}
crate::mmio_reg!(Channel1Control: u32 @ 0xCC006820);
-impl MmioAccess<GameCube> for Channel1Control {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for Channel1Control {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.exi.ch1_cr
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
let was_started = gc.exi.ch1_cr.transfer_start();
gc.exi.ch1_cr = self;
if self.transfer_start() && !was_started {
if self.dma_mode() {
- exi::run_dma::<1>(gc);
+ exi::run_dma::<1, SYSTEM>(gc);
} else {
gc.exi.start_immediate_transfer::<1>();
}
@@ -266,7 +266,7 @@ impl MmioAccess<GameCube> for Channel1Control {
#[derive(Copy, Clone, Debug)]
pub struct Channel1Data {}
crate::mmio_reg!(Channel1Data: u32 @ 0xCC006824);
-crate::mmio_default_access!(Channel1Data => GameCube.exi.ch1_data);
+crate::mmio_default_access!(Channel1Data => System.exi.ch1_data);
// --- Channel 2 ---
@@ -296,13 +296,13 @@ pub struct Channel2Status {
}
crate::mmio_reg!(Channel2Status: u32 @ 0xCC006828);
-impl MmioAccess<GameCube> for Channel2Status {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for Channel2Status {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.exi.ch2_csr
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
write_csr(&mut gc.exi.ch2_csr, self);
- exi::on_chip_select_written::<2>(gc, self.chip_select());
+ exi::on_chip_select_written::<2, SYSTEM>(gc, self.chip_select());
exi::refresh_interrupts(gc);
}
}
@@ -318,7 +318,7 @@ pub struct Channel2DmaAddress {
pub address: u32,
}
crate::mmio_reg!(Channel2DmaAddress: u32 @ 0xCC00682C);
-crate::mmio_default_access!(Channel2DmaAddress => GameCube.exi.ch2_mar);
+crate::mmio_default_access!(Channel2DmaAddress => System.exi.ch2_mar);
// 0xCC006830 4 R/W EXI2LENGTH - EXI Channel 2 DMA Transfer Length
@@ -329,7 +329,7 @@ pub struct Channel2DmaLength {
pub length: u32,
}
crate::mmio_reg!(Channel2DmaLength: u32 @ 0xCC006830);
-crate::mmio_default_access!(Channel2DmaLength => GameCube.exi.ch2_length);
+crate::mmio_default_access!(Channel2DmaLength => System.exi.ch2_length);
// 0xCC006834 4 R/W EXI2CR - EXI Channel 2 Control Register
@@ -347,16 +347,16 @@ pub struct Channel2Control {
}
crate::mmio_reg!(Channel2Control: u32 @ 0xCC006834);
-impl MmioAccess<GameCube> for Channel2Control {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for Channel2Control {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.exi.ch2_cr
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
let was_started = gc.exi.ch2_cr.transfer_start();
gc.exi.ch2_cr = self;
if self.transfer_start() && !was_started {
if self.dma_mode() {
- exi::run_dma::<2>(gc);
+ exi::run_dma::<2, SYSTEM>(gc);
} else {
gc.exi.start_immediate_transfer::<2>();
}
@@ -371,4 +371,4 @@ impl MmioAccess<GameCube> for Channel2Control {
#[derive(Copy, Clone, Debug)]
pub struct Channel2Data {}
crate::mmio_reg!(Channel2Data: u32 @ 0xCC006838);
-crate::mmio_default_access!(Channel2Data => GameCube.exi.ch2_data);
+crate::mmio_default_access!(Channel2Data => System.exi.ch2_data);
diff --git a/crates/gecko/src/flipper/gx.rs b/crates/gecko/src/flipper/gx.rs
index 96b5711..8c41ada 100644
--- a/crates/gecko/src/flipper/gx.rs
+++ b/crates/gecko/src/flipper/gx.rs
@@ -13,11 +13,11 @@ mod xf;
use crate::flipper::gx::constants::{BP_REG_SIZE, CP_REG_SIZE, TLUT_MEM_ENTRIES, XF_MEM_SIZE};
use crate::flipper::gx::draw::Matrix4;
use crate::flipper::gx::regs::{AlphaCompare, BlendMode, TevAlphaEnv, TevColorEnv, TevRegisterH, TevRegisterL, ZMode};
-use crate::gamecube::GameCube;
#[cfg(feature = "efb-writeback")]
use crate::host::EfbWriteback;
use crate::host::{GxAction, RenderSink, XfbPart};
use crate::mmio::Mmio;
+use crate::system::{System, SystemId};
use fifo::FifoCmd;
use rustc_hash::FxHashMap;
@@ -182,7 +182,7 @@ impl GraphicsProcessor {
}
}
-pub fn present_xfb(gc: &mut GameCube) {
+pub fn present_xfb<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>) {
if gc.gx.xfb_copies.is_empty() {
return;
}
@@ -253,7 +253,7 @@ pub fn present_xfb(gc: &mut GameCube) {
gc.gx.xfb_copies.clear();
}
-impl GameCube {
+impl<const SYSTEM: SystemId> System<SYSTEM> {
/// Check if the GX stub detected a finish or token command and signal PE
pub fn check_gx_pe_interrupts(&mut self) {
if self.gx.raise_interrupt {
diff --git a/crates/gecko/src/flipper/mi/regs.rs b/crates/gecko/src/flipper/mi/regs.rs
index a1eb4aa..9acfe46 100644
--- a/crates/gecko/src/flipper/mi/regs.rs
+++ b/crates/gecko/src/flipper/mi/regs.rs
@@ -19,4 +19,4 @@ pub struct MiInterruptMask {
pub master_enable: bool,
}
crate::mmio_reg!(MiInterruptMask: u16 @ 0xCC00401C);
-crate::mmio_default_access!(MiInterruptMask => GameCube.mi.interrupt_mask);
+crate::mmio_default_access!(MiInterruptMask => System.mi.interrupt_mask);
diff --git a/crates/gecko/src/flipper/pe.rs b/crates/gecko/src/flipper/pe.rs
index 948a8f0..13d8979 100644
--- a/crates/gecko/src/flipper/pe.rs
+++ b/crates/gecko/src/flipper/pe.rs
@@ -1,7 +1,7 @@
pub mod regs;
use crate::flipper::pi::InterruptFlag;
-use crate::gamecube::GameCube;
+use crate::system::{System, SystemId};
pub struct PixelEngine {
pub zconf: regs::ZConfig,
@@ -65,7 +65,7 @@ crate::mmio_device_dispatch! {
}
#[inline(always)]
-pub fn refresh_interrupts(gc: &mut GameCube) {
+pub fn refresh_interrupts<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>) {
if gc.pe.token_interrupt_active() {
gc.pi.assert_interrupt(InterruptFlag::PeToken);
} else {
diff --git a/crates/gecko/src/flipper/pe/regs.rs b/crates/gecko/src/flipper/pe/regs.rs
index 7ce0239..b4aa231 100644
--- a/crates/gecko/src/flipper/pe/regs.rs
+++ b/crates/gecko/src/flipper/pe/regs.rs
@@ -1,6 +1,6 @@
use crate::flipper::pe;
-use crate::gamecube::GameCube;
use crate::mmio::traits::{MmioAccess, WriteMask};
+use crate::system::{System, SystemId};
// 0xCC001000 2 R/W Z Configuration
@@ -8,7 +8,7 @@ use crate::mmio::traits::{MmioAccess, WriteMask};
#[derive(Copy, Clone, Debug)]
pub struct ZConfig {}
crate::mmio_reg!(ZConfig: u16 @ 0xCC001000);
-crate::mmio_default_access!(ZConfig => GameCube.pe.zconf);
+crate::mmio_default_access!(ZConfig => System.pe.zconf);
// 0xCC001002 2 R/W Alpha Configuration
@@ -16,7 +16,7 @@ crate::mmio_default_access!(ZConfig => GameCube.pe.zconf);
#[derive(Copy, Clone, Debug)]
pub struct AlphaConfig {}
crate::mmio_reg!(AlphaConfig: u16 @ 0xCC001002);
-crate::mmio_default_access!(AlphaConfig => GameCube.pe.alphaconf);
+crate::mmio_default_access!(AlphaConfig => System.pe.alphaconf);
// 0xCC001004 2 R/W Destination Alpha
@@ -24,7 +24,7 @@ crate::mmio_default_access!(AlphaConfig => GameCube.pe.alphaconf);
#[derive(Copy, Clone, Debug)]
pub struct DstAlphaConfig {}
crate::mmio_reg!(DstAlphaConfig: u16 @ 0xCC001004);
-crate::mmio_default_access!(DstAlphaConfig => GameCube.pe.dst_alphaconf);
+crate::mmio_default_access!(DstAlphaConfig => System.pe.dst_alphaconf);
// 0xCC001006 2 R/W Alpha Compare Mode
@@ -32,7 +32,7 @@ crate::mmio_default_access!(DstAlphaConfig => GameCube.pe.dst_alphaconf);
#[derive(Copy, Clone, Debug)]
pub struct AlphaMode {}
crate::mmio_reg!(AlphaMode: u16 @ 0xCC001006);
-crate::mmio_default_access!(AlphaMode => GameCube.pe.alphamode);
+crate::mmio_default_access!(AlphaMode => System.pe.alphamode);
// 0xCC001008 2 R/W Alpha Read Mode
@@ -40,7 +40,7 @@ crate::mmio_default_access!(AlphaMode => GameCube.pe.alphamode);
#[derive(Copy, Clone, Debug)]
pub struct AlphaRead {}
crate::mmio_reg!(AlphaRead: u16 @ 0xCC001008);
-crate::mmio_default_access!(AlphaRead => GameCube.pe.alpharead);
+crate::mmio_default_access!(AlphaRead => System.pe.alpharead);
// 0xCC00100A 2 R/W Interrupt Status
@@ -61,13 +61,13 @@ pub struct InterruptStatus {
}
crate::mmio_reg!(InterruptStatus: u16 @ 0xCC00100A);
-impl MmioAccess<GameCube> for InterruptStatus {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for InterruptStatus {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
// Status bits (token/finish) always read back as zero.
gc.pe.sr.with_pe_token(false).with_pe_finish(false)
}
- fn write(self, gc: &mut GameCube, mask: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, mask: WriteMask) {
if !mask.byte(1) {
return;
}
@@ -93,4 +93,4 @@ impl MmioAccess<GameCube> for InterruptStatus {
#[derive(Copy, Clone, Debug)]
pub struct Token {}
crate::mmio_reg!(Token: u16 @ 0xCC00100E);
-crate::mmio_default_access!(Token => GameCube.pe.token);
+crate::mmio_default_access!(Token => System.pe.token);
diff --git a/crates/gecko/src/flipper/pi/regs.rs b/crates/gecko/src/flipper/pi/regs.rs
index 941fe6b..d1eabd0 100644
--- a/crates/gecko/src/flipper/pi/regs.rs
+++ b/crates/gecko/src/flipper/pi/regs.rs
@@ -1,5 +1,5 @@
-use crate::gamecube::GameCube;
use crate::mmio::traits::{MmioAccess, WriteMask};
+use crate::system::{System, SystemId};
// 0xCC003000 4 r INTSR (Interrupt Cause)
@@ -60,12 +60,12 @@ impl Default for InterruptCause {
}
}
-impl MmioAccess<GameCube> for InterruptCause {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for InterruptCause {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.pi.intsr
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
// yagcd seems to be wrong, we should not clear everything on read,
// but just do the usual w1c instead.
const RSWST_MASK: u32 = 1 << 16;
@@ -122,7 +122,7 @@ pub struct InterruptMask {
pub highspeed_port: bool,
}
crate::mmio_reg!(InterruptMask: u32 @ 0xCC003004);
-crate::mmio_default_access!(InterruptMask => GameCube.pi.intmr);
+crate::mmio_default_access!(InterruptMask => System.pi.intmr);
// 0xCC00300C 4 r/w PI_FIFO_BASE - CPU FIFO Base Address
@@ -134,11 +134,11 @@ pub struct FifoBase {
}
crate::mmio_reg!(FifoBase: u32 @ 0xCC00300C);
-impl MmioAccess<GameCube> for FifoBase {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for FifoBase {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
FifoBase::from_raw(gc.pi.fifo_base)
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
gc.pi.fifo_base = self.raw();
}
}
@@ -153,11 +153,11 @@ pub struct FifoEnd {
}
crate::mmio_reg!(FifoEnd: u32 @ 0xCC003010);
-impl MmioAccess<GameCube> for FifoEnd {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for FifoEnd {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
FifoEnd::from_raw(gc.pi.fifo_end)
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
gc.pi.fifo_end = self.raw();
}
}
@@ -172,11 +172,11 @@ pub struct FifoWritePtr {
}
crate::mmio_reg!(FifoWritePtr: u32 @ 0xCC003014);
-impl MmioAccess<GameCube> for FifoWritePtr {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for FifoWritePtr {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
FifoWritePtr::from_raw(gc.pi.fifo_wptr)
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
gc.pi.fifo_wptr = self.raw() & 0x1FFF_FFE0;
}
}
@@ -188,11 +188,11 @@ impl MmioAccess<GameCube> for FifoWritePtr {
pub struct ResetCode {}
crate::mmio_reg!(ResetCode: u32 @ 0xCC003024);
-impl MmioAccess<GameCube> for ResetCode {
- fn read(_gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for ResetCode {
+ fn read(_gc: &mut System<SYSTEM>) -> Self {
Self::from_raw(0)
}
- fn write(self, _gc: &mut GameCube, _: WriteMask) {
+ fn write(self, _gc: &mut System<SYSTEM>, _: WriteMask) {
tracing::warn!("TODO: reset DVD");
}
}
@@ -207,12 +207,12 @@ pub struct FlipperRev {
}
crate::mmio_reg!(FlipperRev: u32 @ 0xCC00302C);
-impl MmioAccess<GameCube> for FlipperRev {
- fn read(_gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for FlipperRev {
+ fn read(_gc: &mut System<SYSTEM>) -> Self {
// FLIPPER_REV_C from Dolphin.
Self::from_raw(0x2465_00B1)
}
- fn write(self, _gc: &mut GameCube, _: WriteMask) {
+ fn write(self, _gc: &mut System<SYSTEM>, _: WriteMask) {
tracing::warn!("writing to FlipperRev???");
}
}
diff --git a/crates/gecko/src/flipper/si.rs b/crates/gecko/src/flipper/si.rs
index 948e228..0a65325 100644
--- a/crates/gecko/src/flipper/si.rs
+++ b/crates/gecko/src/flipper/si.rs
@@ -1,8 +1,8 @@
pub mod pad;
pub mod regs;
-use crate::gamecube::GameCube;
use crate::mmio::constants::SI_BASE;
+use crate::system::{System, SystemId};
use pad::{GC_CONTROLLER_ID, PadStatus};
const NUM_CHANNELS: usize = 4;
@@ -202,7 +202,7 @@ crate::mmio_device_dispatch! {
}
#[inline(always)]
-pub fn si_read(gc: &mut GameCube, phys: u32, size: u32) -> Option<u32> {
+pub fn si_read<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>, phys: u32, size: u32) -> Option<u32> {
let offset = phys - SI_BASE;
if (0x80..=0xFF).contains(&offset) {
@@ -234,7 +234,7 @@ pub fn si_read(gc: &mut GameCube, phys: u32, size: u32) -> Option<u32> {
}
#[inline(always)]
-pub fn si_write(gc: &mut GameCube, phys: u32, size: u32, val: u32) -> bool {
+pub fn si_write<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>, phys: u32, size: u32, val: u32) -> bool {
let offset = phys - SI_BASE;
if (0x80..=0xFF).contains(&offset) {
@@ -272,7 +272,7 @@ pub fn si_write(gc: &mut GameCube, phys: u32, size: u32, val: u32) -> bool {
}
#[inline(always)]
-pub fn refresh_interrupts(gc: &mut GameCube) {
+pub fn refresh_interrupts<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>) {
use crate::flipper::pi::InterruptFlag;
if gc.si.interrupt_active() {
diff --git a/crates/gecko/src/flipper/si/regs.rs b/crates/gecko/src/flipper/si/regs.rs
index 35e98f3..99066c5 100644
--- a/crates/gecko/src/flipper/si/regs.rs
+++ b/crates/gecko/src/flipper/si/regs.rs
@@ -1,6 +1,6 @@
use crate::flipper::si;
-use crate::gamecube::GameCube;
use crate::mmio::traits::{MmioAccess, WriteMask};
+use crate::system::{System, SystemId};
use chapa::BitEnum;
// 0xCC006430 4 R/W SIPOLL (SI Poll Register)
@@ -21,7 +21,7 @@ pub struct SiPoll {
pub x_lines: u16,
}
crate::mmio_reg!(SiPoll: u32 @ 0xCC006430);
-crate::mmio_default_access!(SiPoll => GameCube.si.poll);
+crate::mmio_default_access!(SiPoll => System.si.poll);
// 0xCC006434 4 R/W SICOMCSR (SI Communication Control Status Register)
@@ -77,12 +77,12 @@ pub struct SiComcsr {
}
crate::mmio_reg!(SiComcsr: u32 @ 0xCC006434);
-impl MmioAccess<GameCube> for SiComcsr {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for SiComcsr {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.si.comcsr
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
let mut csr = gc.si.comcsr;
if self.tc_interrupt() {
@@ -180,12 +180,12 @@ pub struct SiStatusRegister {
}
crate::mmio_reg!(SiStatusRegister: u32 @ 0xCC006438);
-impl MmioAccess<GameCube> for SiStatusRegister {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for SiStatusRegister {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.si.status
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
let mut status = gc.si.status;
if self.norep0() {
diff --git a/crates/gecko/src/flipper/vi.rs b/crates/gecko/src/flipper/vi.rs
index b56f351..3cb3047 100644
--- a/crates/gecko/src/flipper/vi.rs
+++ b/crates/gecko/src/flipper/vi.rs
@@ -1,6 +1,6 @@
pub mod regs;
-use crate::gamecube::GameCube;
+use crate::system::{System, SystemId};
const CPU_CORE_CLOCK: u64 = 486_000_000;
const CLOCK_FREQUENCIES: [u64; 2] = [27_000_000, 54_000_000];
@@ -265,7 +265,7 @@ crate::mmio_device_dispatch! {
}
#[inline(always)]
-pub fn ensure_half_line_scheduled(gc: &mut GameCube) {
+pub fn ensure_half_line_scheduled<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>) {
if !gc.vi.half_line_scheduled {
let ticks_per_hl = gc.vi.ticks_per_half_line();
if ticks_per_hl > 0 {
@@ -291,7 +291,7 @@ pub fn ensure_half_line_scheduled(gc: &mut GameCube) {
}
#[inline(always)]
-pub fn refresh_interrupts(gc: &mut GameCube) {
+pub fn refresh_interrupts<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>) {
use crate::flipper::pi::InterruptFlag;
if gc.vi.vi_interrupt_active() {
@@ -301,7 +301,7 @@ pub fn refresh_interrupts(gc: &mut GameCube) {
}
}
-impl GameCube {
+impl<const SYSTEM: SystemId> System<SYSTEM> {
#[rustfmt::skip]
pub fn render_xfb(&self) -> Vec<u32> {
let video_format = self.vi.dcr.video_format();
diff --git a/crates/gecko/src/flipper/vi/regs.rs b/crates/gecko/src/flipper/vi/regs.rs
index edfbaea..29f8df8 100644
--- a/crates/gecko/src/flipper/vi/regs.rs
+++ b/crates/gecko/src/flipper/vi/regs.rs
@@ -1,6 +1,6 @@
use crate::flipper::vi;
-use crate::gamecube::GameCube;
use crate::mmio::traits::{MmioAccess, WriteMask};
+use crate::system::{System, SystemId};
use chapa::BitEnum;
// 0xCC002000 2 R/W VTR (Vertical Timing Register)
@@ -15,11 +15,11 @@ pub struct VerticalTiming {
}
crate::mmio_reg!(VerticalTiming: u16 @ 0xCC002000);
-impl MmioAccess<GameCube> for VerticalTiming {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for VerticalTiming {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.vi.vtr
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
gc.vi.vtr = self;
vi::ensure_half_line_scheduled(gc);
}
@@ -97,12 +97,12 @@ impl DisplayConfiguration {
}
}
-impl MmioAccess<GameCube> for DisplayConfiguration {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for DisplayConfiguration {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.vi.dcr
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
// TODO: Rising edge on RST clears the register. Just a test for now.
if self.reset() && !gc.vi.dcr.reset() {
gc.vi.dcr = DisplayConfiguration::from_raw(0);
@@ -128,11 +128,11 @@ pub struct HorizontalTiming0 {
}
crate::mmio_reg!(HorizontalTiming0: u32 @ 0xCC002004);
-impl MmioAccess<GameCube> for HorizontalTiming0 {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for HorizontalTiming0 {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.vi.htr0
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
gc.vi.htr0 = self;
vi::ensure_half_line_scheduled(gc);
}
@@ -151,7 +151,7 @@ pub struct HorizontalTiming1 {
pub horizontal_blank_start: u16,
}
crate::mmio_reg!(HorizontalTiming1: u32 @ 0xCC002008);
-crate::mmio_default_access!(HorizontalTiming1 => GameCube.vi.htr1);
+crate::mmio_default_access!(HorizontalTiming1 => System.vi.htr1);
// 0xCC00200C 4 R/W VTO (Odd Field Vertical Timing Register)
@@ -165,11 +165,11 @@ pub struct VerticalTimingOdd {
}
crate::mmio_reg!(VerticalTimingOdd: u32 @ 0xCC00200C);
-impl MmioAccess<GameCube> for VerticalTimingOdd {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for VerticalTimingOdd {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.vi.vto
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
gc.vi.vto = self;
vi::ensure_half_line_scheduled(gc);
}
@@ -187,11 +187,11 @@ pub struct VerticalTimingEven {
}
crate::mmio_reg!(VerticalTimingEven: u32 @ 0xCC002010);
-impl MmioAccess<GameCube> for VerticalTimingEven {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for VerticalTimingEven {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.vi.vte
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
gc.vi.vte = self;
vi::ensure_half_line_scheduled(gc);
}
@@ -212,7 +212,7 @@ pub struct BurstBlankingEvenInterval {
pub burst_end_3: u16,
}
crate::mmio_reg!(BurstBlankingEvenInterval: u32 @ 0xCC002014);
-crate::mmio_default_access!(BurstBlankingEvenInterval => GameCube.vi.bbei);
+crate::mmio_default_access!(BurstBlankingEvenInterval => System.vi.bbei);
// 0xCC002018 4 R/W BBOI (Burst Blanking Odd Interval)
@@ -229,7 +229,7 @@ pub struct BurstBlankingOddInterval {
pub burst_end_4: u16,
}
crate::mmio_reg!(BurstBlankingOddInterval: u32 @ 0xCC002018);
-crate::mmio_default_access!(BurstBlankingOddInterval => GameCube.vi.bboi);
+crate::mmio_default_access!(BurstBlankingOddInterval => System.vi.bboi);
// 0xCC00201c 4 R/W TFBL (Top Field Base Register L, External Framebuffer Half 1)
@@ -247,7 +247,7 @@ pub struct TopFieldBase {
// TODO: 29..=31 y always zero (maybe some write only control register stuff, setting bit 31 clears bits 31..=28).
}
crate::mmio_reg!(TopFieldBase: u32 @ 0xCC00201C);
-crate::mmio_default_access!(TopFieldBase => GameCube.vi.tfbl);
+crate::mmio_default_access!(TopFieldBase => System.vi.tfbl);
// 0xCC002020 4 R/W TFBR (Top Field Base Register R)
@@ -258,7 +258,7 @@ pub struct TopFieldBaseRight {
pub xfb_addr: u32,
}
crate::mmio_reg!(TopFieldBaseRight: u32 @ 0xCC002020);
-crate::mmio_default_access!(TopFieldBaseRight => GameCube.vi.tfbr);
+crate::mmio_default_access!(TopFieldBaseRight => System.vi.tfbr);
// 0xCC002024 4 R/W BFBL (Bottom Field Base Register L, External Framebuffer Half 2)
@@ -272,7 +272,7 @@ pub struct BottomFieldBase {
pub page_offset: bool,
}
crate::mmio_reg!(BottomFieldBase: u32 @ 0xCC002024);
-crate::mmio_default_access!(BottomFieldBase => GameCube.vi.bfbl);
+crate::mmio_default_access!(BottomFieldBase => System.vi.bfbl);
// 0xCC002028 4 R/W BFBR (Bottom Field Base Register R)
@@ -283,7 +283,7 @@ pub struct BottomFieldBaseRight {
pub xfb_addr: u32,
}
crate::mmio_reg!(BottomFieldBaseRight: u32 @ 0xCC002028);
-crate::mmio_default_access!(BottomFieldBaseRight => GameCube.vi.bfbr);
+crate::mmio_default_access!(BottomFieldBaseRight => System.vi.bfbr);
// 0xCC00202C 2 R DPV (Display Position Vertical)
@@ -294,7 +294,7 @@ pub struct DisplayPositionVertical {
pub vertical_count: u16,
}
crate::mmio_reg!(DisplayPositionVertical: u16 @ 0xCC00202C);
-crate::mmio_default_access!(DisplayPositionVertical => GameCube.vi.dpv);
+crate::mmio_default_access!(DisplayPositionVertical => System.vi.dpv);
// 0xCC00202E 2 R DPH (Display Position Horizontal)
//
@@ -309,13 +309,13 @@ pub struct DisplayPositionHorizontal {
}
crate::mmio_reg!(DisplayPositionHorizontal: u16 @ 0xCC00202E);
-impl MmioAccess<GameCube> for DisplayPositionHorizontal {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for DisplayPositionHorizontal {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
let cycles = gc.scheduler.cycles;
DisplayPositionHorizontal::from_raw(gc.vi.dph_value(cycles))
}
- fn write(self, _gc: &mut GameCube, _: WriteMask) {
+ fn write(self, _gc: &mut System<SYSTEM>, _: WriteMask) {
// Read only.
}
}
@@ -331,14 +331,14 @@ impl MmioAccess<GameCube> for DisplayPositionHorizontal {
pub struct DisplayPositionCombined {}
crate::mmio_reg!(DisplayPositionCombined: u32 @ 0xCC00202C);
-impl MmioAccess<GameCube> for DisplayPositionCombined {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for DisplayPositionCombined {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
let dpv = gc.vi.dpv.raw() as u32;
let dph = gc.vi.dph_value(gc.scheduler.cycles) as u32;
DisplayPositionCombined::from_raw((dpv << 16) | dph)
}
- fn write(self, _gc: &mut GameCube, _: WriteMask) {
+ fn write(self, _gc: &mut System<SYSTEM>, _: WriteMask) {
// Read only.
}
}
@@ -363,11 +363,11 @@ pub struct DisplayInterrupt0 {
}
crate::mmio_reg!(DisplayInterrupt0: u32 @ 0xCC002030);
-impl MmioAccess<GameCube> for DisplayInterrupt0 {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for DisplayInterrupt0 {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.vi.di0
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
gc.vi.di0 = self;
vi::refresh_interrupts(gc);
}
@@ -389,11 +389,11 @@ pub struct DisplayInterrupt1 {
}
crate::mmio_reg!(DisplayInterrupt1: u32 @ 0xCC002034);
-impl MmioAccess<GameCube> for DisplayInterrupt1 {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for DisplayInterrupt1 {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.vi.di1
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
gc.vi.di1 = self;
vi::refresh_interrupts(gc);
}
@@ -415,11 +415,11 @@ pub struct DisplayInterrupt2 {
}
crate::mmio_reg!(DisplayInterrupt2: u32 @ 0xCC002038);
-impl MmioAccess<GameCube> for DisplayInterrupt2 {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for DisplayInterrupt2 {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.vi.di2
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
gc.vi.di2 = self;
vi::refresh_interrupts(gc);
}
@@ -441,11 +441,11 @@ pub struct DisplayInterrupt3 {
}
crate::mmio_reg!(DisplayInterrupt3: u32 @ 0xCC00203C);
-impl MmioAccess<GameCube> for DisplayInterrupt3 {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for DisplayInterrupt3 {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.vi.di3
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
gc.vi.di3 = self;
vi::refresh_interrupts(gc);
}
@@ -464,7 +464,7 @@ pub struct DisplayLatch0 {
pub trigger: bool,
}
crate::mmio_reg!(DisplayLatch0: u32 @ 0xCC002040);
-crate::mmio_default_access!(DisplayLatch0 => GameCube.vi.dl0);
+crate::mmio_default_access!(DisplayLatch0 => System.vi.dl0);
// 0xCC002044 4 R/W DL1 (Display Latch 1)
@@ -479,7 +479,7 @@ pub struct DisplayLatch1 {
pub trigger: bool,
}
crate::mmio_reg!(DisplayLatch1: u32 @ 0xCC002044);
-crate::mmio_default_access!(DisplayLatch1 => GameCube.vi.dl1);
+crate::mmio_default_access!(DisplayLatch1 => System.vi.dl1);
// 0xCC002048 2 R/W HSW (Horizontal Scaling Width)
@@ -490,7 +490,7 @@ pub struct HorizontalScalingWidth {
pub source_width: u16,
}
crate::mmio_reg!(HorizontalScalingWidth: u16 @ 0xCC002048);
-crate::mmio_default_access!(HorizontalScalingWidth => GameCube.vi.hsw);
+crate::mmio_default_access!(HorizontalScalingWidth => System.vi.hsw);
// 0xCC00204A 2 R/W HSR (Horizontal Scaling Register)
@@ -503,7 +503,7 @@ pub struct HorizontalScalingRegister {
pub horizontal_scaling_enable: bool,
}
crate::mmio_reg!(HorizontalScalingRegister: u16 @ 0xCC00204A);
-crate::mmio_default_access!(HorizontalScalingRegister => GameCube.vi.hsr);
+crate::mmio_default_access!(HorizontalScalingRegister => System.vi.hsr);
// 0xCC00204C 4 R/W FCT0 (Filter Coefficient Table 0)
@@ -518,7 +518,7 @@ pub struct FilterCoefficient0 {
pub tap2: u16,
}
crate::mmio_reg!(FilterCoefficient0: u32 @ 0xCC00204C);
-crate::mmio_default_access!(FilterCoefficient0 => GameCube.vi.fct0);
+crate::mmio_default_access!(FilterCoefficient0 => System.vi.fct0);
// 0xCC002050 4 R/W FCT1 (Filter Coefficient Table 1)
@@ -533,7 +533,7 @@ pub struct FilterCoefficient1 {
pub tap5: u16,
}
crate::mmio_reg!(FilterCoefficient1: u32 @ 0xCC002050);
-crate::mmio_default_access!(FilterCoefficient1 => GameCube.vi.fct1);
+crate::mmio_default_access!(FilterCoefficient1 => System.vi.fct1);
// 0xCC002054 4 R/W FCT2 (Filter Coefficient Table 2)
@@ -548,7 +548,7 @@ pub struct FilterCoefficient2 {
pub tap8: u16,
}
crate::mmio_reg!(FilterCoefficient2: u32 @ 0xCC002054);
-crate::mmio_default_access!(FilterCoefficient2 => GameCube.vi.fct2);
+crate::mmio_default_access!(FilterCoefficient2 => System.vi.fct2);
// 0xCC002058 4 R/W FCT3 (Filter Coefficient Table 3)
@@ -565,7 +565,7 @@ pub struct FilterCoefficient3 {
pub tap12: u8,
}
crate::mmio_reg!(FilterCoefficient3: u32 @ 0xCC002058);
-crate::mmio_default_access!(FilterCoefficient3 => GameCube.vi.fct3);
+crate::mmio_default_access!(FilterCoefficient3 => System.vi.fct3);
// 0xCC00205C 4 R/W FCT4 (Filter Coefficient Table 4)
@@ -582,7 +582,7 @@ pub struct FilterCoefficient4 {
pub tap16: u8,
}
crate::mmio_reg!(FilterCoefficient4: u32 @ 0xCC00205C);
-crate::mmio_default_access!(FilterCoefficient4 => GameCube.vi.fct4);
+crate::mmio_default_access!(FilterCoefficient4 => System.vi.fct4);
// 0xCC002060 4 R/W FCT5 (Filter Coefficient Table 5)
@@ -599,7 +599,7 @@ pub struct FilterCoefficient5 {
pub tap20: u8,
}
crate::mmio_reg!(FilterCoefficient5: u32 @ 0xCC002060);
-crate::mmio_default_access!(FilterCoefficient5 => GameCube.vi.fct5);
+crate::mmio_default_access!(FilterCoefficient5 => System.vi.fct5);
// 0xCC002064 4 R/W FCT6 (Filter Coefficient Table 6)
@@ -616,7 +616,7 @@ pub struct FilterCoefficient6 {
pub tap24: u8,
}
crate::mmio_reg!(FilterCoefficient6: u32 @ 0xCC002064);
-crate::mmio_default_access!(FilterCoefficient6 => GameCube.vi.fct6);
+crate::mmio_default_access!(FilterCoefficient6 => System.vi.fct6);
// 0xCC00206C 2 R/W VICLK (VI Clock Select)
@@ -628,11 +628,11 @@ pub struct ViClockSelect {
}
crate::mmio_reg!(ViClockSelect: u16 @ 0xCC00206C);
-impl MmioAccess<GameCube> for ViClockSelect {
- fn read(gc: &mut GameCube) -> Self {
+impl<const SYSTEM: SystemId> MmioAccess<System<SYSTEM>> for ViClockSelect {
+ fn read(gc: &mut System<SYSTEM>) -> Self {
gc.vi.viclk
}
- fn write(self, gc: &mut GameCube, _: WriteMask) {
+ fn write(self, gc: &mut System<SYSTEM>, _: WriteMask) {
gc.vi.viclk = self;
vi::ensure_half_line_scheduled(gc);
}
@@ -647,7 +647,7 @@ pub struct ViDtvStatus {
pub dtv_status: bool,
}
crate::mmio_reg!(ViDtvStatus: u16 @ 0xCC00206E);
-crate::mmio_default_access!(ViDtvStatus => GameCube.vi.visel);
+crate::mmio_default_access!(ViDtvStatus => System.vi.visel);
// 0xCC002070 2 R/W Unknown. Log for now.
@@ -655,7 +655,7 @@ crate::mmio_default_access!(ViDtvStatus => GameCube.vi.visel);
#[derive(Copy, Clone, Debug)]
pub struct ViUnknown70 {}
crate::mmio_reg!(ViUnknown70: u16 @ 0xCC002070);
-crate::mmio_default_access!(ViUnknown70 => GameCube.vi.unknown_70);
+crate::mmio_default_access!(ViUnknown70 => System.vi.unknown_70);
// 0xCC002072 2 R/W BorderHBE (Border HBE)
@@ -668,7 +668,7 @@ pub struct BorderHbe {
pub border_enable: bool,
}
crate::mmio_reg!(BorderHbe: u16 @ 0xCC002072);
-crate::mmio_default_access!(BorderHbe => GameCube.vi.border_hbe);
+crate::mmio_default_access!(BorderHbe => System.vi.border_hbe);
// 0xCC002074 2 R/W BorderHBS (Border HBS)
@@ -679,4 +679,4 @@ pub struct BorderHbs {
pub horizontal_blank_start_656: u16,
}
crate::mmio_reg!(BorderHbs: u16 @ 0xCC002074);
-crate::mmio_default_access!(BorderHbs => GameCube.vi.border_hbs);
+crate::mmio_default_access!(BorderHbs => System.vi.border_hbs);
diff --git a/crates/gecko/src/gamecube.rs b/crates/gecko/src/gamecube.rs
index b481fc4..291107d 100644
--- a/crates/gecko/src/gamecube.rs
+++ b/crates/gecko/src/gamecube.rs
@@ -7,7 +7,7 @@ use crate::hooks::HookFlags;
use crate::idle::{IDLE_LOOP_MAX_INSTRS, IdleCheck};
use crate::ipl::IPL_HLE;
use crate::scheduler::Scheduler;
-use crate::system::{GC, System};
+use crate::system::{GC, System, SystemId};
use image::Executable;
pub type GameCube = System<{ GC }>;
@@ -131,7 +131,9 @@ impl GameCube {
emulator.open_cover();
emulator
}
+}
+impl<const SYSTEM: SystemId> System<SYSTEM> {
#[inline(always)]
pub fn step_cpu(&mut self) {
if self.cpu.msr.external_interrupt_enable() {
@@ -166,7 +168,7 @@ impl GameCube {
self.cpu.cia = self.cpu.pc;
self.cpu.nia = self.cpu.cia.wrapping_add(4);
let instr = Instruction(self.mmio.fetch_instruction(self.cpu.cia));
- cpu::lut::dispatch(self, instr);
+ cpu::dispatch(self, instr);
self.scheduler.cycles += 2; // TODO: Track properly?
// CPU post-hook
diff --git a/crates/gecko/src/hooks.rs b/crates/gecko/src/hooks.rs
index 3e38b65..e461a5f 100644
--- a/crates/gecko/src/hooks.rs
+++ b/crates/gecko/src/hooks.rs
@@ -1,4 +1,4 @@
-use crate::gamecube::GameCube;
+use crate::system::{System, SystemId};
#[derive(Clone, Copy, Default)]
pub struct HookFlags(u16);
@@ -92,7 +92,7 @@ pub struct HookState {
pub filters: HookFilters,
}
-pub trait Host {
+pub trait Host<const SYSTEM: SystemId> {
/// Current cached hook state for the host.
fn hook_state(&self) -> HookState;
@@ -114,20 +114,34 @@ pub trait Host {
}
/// Called before each CPU instruction executes.
- fn on_cpu_pre(&mut self, emu: &mut GameCube);
+ fn on_cpu_pre(&mut self, emu: &mut System<SYSTEM>);
/// Called after each CPU instruction executes.
- fn on_cpu_post(&mut self, emu: &mut GameCube);
+ fn on_cpu_post(&mut self, emu: &mut System<SYSTEM>);
/// 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>;
+ fn on_bus_read_pre(&mut self, emu: &mut System<SYSTEM>, virt_addr: u32, phys_addr: u32, size: u8) -> Option<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;
+ fn on_bus_read_post(
+ &mut self,
+ emu: &mut System<SYSTEM>,
+ 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;
+ fn on_bus_write_pre(
+ &mut self,
+ emu: &mut System<SYSTEM>,
+ virt_addr: u32,
+ phys_addr: u32,
+ size: u8,
+ value: u32,
+ ) -> u32;
/// Called after a bus write completes.
- fn on_bus_write_post(&mut self, emu: &mut GameCube, virt_addr: u32, phys_addr: u32, size: u8, value: u32);
+ fn on_bus_write_post(&mut self, emu: &mut System<SYSTEM>, virt_addr: u32, phys_addr: u32, size: u8, value: u32);
}
diff --git a/crates/gecko/src/lib.rs b/crates/gecko/src/lib.rs
index 09e2c97..f96625d 100644
--- a/crates/gecko/src/lib.rs
+++ b/crates/gecko/src/lib.rs
@@ -12,6 +12,7 @@ pub mod system;
pub mod wii;
pub use gamecube::GameCube;
+pub use system::{GC, System, SystemId, WII};
pub use wii::Wii;
#[cfg(feature = "hooks")]
diff --git a/crates/gecko/src/mmio/bus.rs b/crates/gecko/src/mmio/bus.rs
index 3eb8eb7..22e414d 100644
--- a/crates/gecko/src/mmio/bus.rs
+++ b/crates/gecko/src/mmio/bus.rs
@@ -1,4 +1,3 @@
-use crate::gamecube::GameCube;
#[cfg(feature = "hooks")]
use crate::hooks::HookFlags;
use crate::mmio::constants::{
@@ -6,6 +5,7 @@ use crate::mmio::constants::{
HW_REG_BASE, HW_REG_END, MI_BASE, MI_END, PE_BASE, PE_END, PI_BASE, PI_END, RAM_END, SI_BASE, SI_END, VI_BASE,
VI_END,
};
+use crate::system::{System, SystemId};
macro_rules! bus_read_hooks {
($self:ident, $addr:ident, $phys:ident, $size:literal, $body:expr) => {{
@@ -77,7 +77,7 @@ macro_rules! bus_write_hooks {
}};
}
-impl GameCube {
+impl<const SYSTEM: SystemId> System<SYSTEM> {
/// Translate a virtual address to physical using DBAT registers.
/// Falls back to simple masking if no BAT matches.
#[inline(always)]
diff --git a/crates/gecko/src/mmio/fp.rs b/crates/gecko/src/mmio/fp.rs
index 486dfc1..8bde6b3 100644
--- a/crates/gecko/src/mmio/fp.rs
+++ b/crates/gecko/src/mmio/fp.rs
@@ -1,8 +1,8 @@
-use crate::gamecube::GameCube;
use crate::mmio::Mmio;
use crate::mmio::constants::RAM_END;
+use crate::system::{System, SystemId};
-impl GameCube {
+impl<const SYSTEM: SystemId> System<SYSTEM> {
// Load a 64-bit double from memory
#[inline]
pub fn read_f64(&mut self, addr: u32) -> f64 {
diff --git a/crates/gecko/src/mmio/macros.rs b/crates/gecko/src/mmio/macros.rs
index f53f525..ef11199 100644
--- a/crates/gecko/src/mmio/macros.rs
+++ b/crates/gecko/src/mmio/macros.rs
@@ -6,16 +6,16 @@ macro_rules! mmio_device_dispatch {
registers = [ $($reg:ty),* $(,)? ] $(,)?
) => {
#[inline(always)]
- pub fn $read_fn(
- gc: &mut $crate::gamecube::GameCube,
+ pub fn $read_fn<const SYSTEM: $crate::system::SystemId>(
+ sys: &mut $crate::system::System<SYSTEM>,
addr: u32,
size: u32,
) -> Option<u32> {
$(
if <$reg as $crate::mmio::traits::MmioRegister>::fits(addr, size) {
return Some(
- <$reg as $crate::mmio::traits::MmioAccess<$crate::gamecube::GameCube>>
- ::read_at(gc, addr, size),
+ <$reg as $crate::mmio::traits::MmioAccess<$crate::system::System<SYSTEM>>>
+ ::read_at(sys, addr, size),
);
}
)*
@@ -23,8 +23,8 @@ macro_rules! mmio_device_dispatch {
}
#[inline(always)]
- pub fn $write_fn(
- gc: &mut $crate::gamecube::GameCube,
+ pub fn $write_fn<const SYSTEM: $crate::system::SystemId>(
+ sys: &mut $crate::system::System<SYSTEM>,
addr: u32,
size: u32,
val: u32,
@@ -38,8 +38,8 @@ macro_rules! mmio_device_dispatch {
size,
"MMIO write"
);
- <$reg as $crate::mmio::traits::MmioAccess<$crate::gamecube::GameCube>>
- ::write_at(gc, addr, size, val);
+ <$reg as $crate::mmio::traits::MmioAccess<$crate::system::System<SYSTEM>>>
+ ::write_at(sys, addr, size, val);
return true;
}
)*
@@ -68,19 +68,21 @@ macro_rules! mmio_reg {
#[macro_export]
macro_rules! mmio_default_access {
- ($reg:ty => GameCube . $($field:ident).+) => {
- impl $crate::mmio::traits::MmioAccess<$crate::gamecube::GameCube> for $reg {
+ ($reg:ty => System . $($field:ident).+) => {
+ impl<const SYSTEM: $crate::system::SystemId>
+ $crate::mmio::traits::MmioAccess<$crate::system::System<SYSTEM>> for $reg
+ {
#[inline(always)]
- fn read(gc: &mut $crate::gamecube::GameCube) -> Self {
- gc . $($field).+
+ fn read(sys: &mut $crate::system::System<SYSTEM>) -> Self {
+ sys . $($field).+
}
#[inline(always)]
fn write(
self,
- gc: &mut $crate::gamecube::GameCube,
+ sys: &mut $crate::system::System<SYSTEM>,
_: $crate::mmio::traits::WriteMask,
) {
- gc . $($field).+ = self;
+ sys . $($field).+ = self;
}
}
};
diff --git a/crates/gecko/src/scheduler.rs b/crates/gecko/src/scheduler.rs
index 1afe4f9..9f03eeb 100644
--- a/crates/gecko/src/scheduler.rs
+++ b/crates/gecko/src/scheduler.rs
@@ -98,30 +98,46 @@ impl<const SYSTEM: SystemId> Scheduler<SYSTEM> {
impl Scheduler<{ GC }> {
pub fn new_gamecube() -> Self {
+ Self::with_default_events()
+ }
+}
+
+impl Scheduler<{ crate::system::WII }> {
+ pub fn new_wii() -> Self {
+ Self::with_default_events()
+ }
+}
+
+impl<const SYSTEM: SystemId> Scheduler<SYSTEM> {
+ fn with_default_events() -> Self {
let mut s = Self::empty();
let initial_refresh_rate = RefreshRate::Hz60; // TODO: Detect IPL and schedule accordingly
- s.schedule_at(initial_refresh_rate.cycles_per_frame(), self::vsync_handler);
- s.schedule_at(CPU_CYCLES_PER_DSP_TICK * DSP_BATCH_SIZE, self::dsp_batch_handler);
+ s.schedule_at(initial_refresh_rate.cycles_per_frame(), self::vsync_handler::<SYSTEM>);
+ s.schedule_at(
+ CPU_CYCLES_PER_DSP_TICK * DSP_BATCH_SIZE,
+ self::dsp_batch_handler::<SYSTEM>,
+ );
s.schedule_at(
crate::cpu::dec::cycles_until_underflow(u32::MAX),
- crate::cpu::dec::underflow_handler,
+ crate::cpu::dec::underflow_handler::<SYSTEM>,
);
s
}
}
/// Reschedules itself every frame.
-pub fn vsync_handler(gc: &mut System<{ GC }>) {
+pub fn vsync_handler<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>) {
gc.vsync_pending = true;
let rate = gc.vi.dcr.video_format().refresh_rate();
- gc.scheduler.schedule_in(rate.cycles_per_frame(), self::vsync_handler);
+ gc.scheduler
+ .schedule_in(rate.cycles_per_frame(), self::vsync_handler::<SYSTEM>);
}
/// Reschedules itself every DSP batch.
-pub fn dsp_batch_handler(gc: &mut System<{ GC }>) {
+pub fn dsp_batch_handler<const SYSTEM: SystemId>(gc: &mut System<SYSTEM>) {
gc.execute_dsp_batch();
gc.scheduler.schedule_in(
self::CPU_CYCLES_PER_DSP_TICK * self::DSP_BATCH_SIZE,
- self::dsp_batch_handler,
+ self::dsp_batch_handler::<SYSTEM>,
);
}
diff --git a/crates/gecko/src/system.rs b/crates/gecko/src/system.rs
index 6ee1724..66ea589 100644
--- a/crates/gecko/src/system.rs
+++ b/crates/gecko/src/system.rs
@@ -48,7 +48,7 @@ pub struct System<const SYSTEM: SystemId> {
pub(crate) idle: IdleDetector,
#[cfg(feature = "hooks")]
- pub hook_host: Option<Box<dyn Host + Send>>,
+ pub hook_host: Option<Box<dyn Host<SYSTEM> + Send>>,
#[cfg(feature = "hooks")]
pub hook_flags: HookFlags,
#[cfg(feature = "hooks")]
@@ -154,7 +154,7 @@ impl<const SYSTEM: SystemId> System<SYSTEM> {
#[cfg(feature = "hooks")]
#[inline(always)]
- pub fn sync_pending_hook_state(&mut self, host: &mut dyn Host) {
+ pub fn sync_pending_hook_state(&mut self, host: &mut dyn Host<SYSTEM>) {
#[cfg(feature = "hooks-mut-traps")]
match host.take_pending_hook_state() {
Ok(Some(state)) => self.apply_hook_state(state),
@@ -167,7 +167,7 @@ impl<const SYSTEM: SystemId> System<SYSTEM> {
}
#[cfg(feature = "hooks")]
- pub fn set_hook_host(&mut self, host: Box<dyn Host + Send>) {
+ pub fn set_hook_host(&mut self, host: Box<dyn Host<SYSTEM> + Send>) {
self.apply_hook_state(host.hook_state());
self.hook_host = Some(host);
}
diff --git a/crates/gecko/src/wii.rs b/crates/gecko/src/wii.rs
index 2ac30b7..edfa7e1 100644
--- a/crates/gecko/src/wii.rs
+++ b/crates/gecko/src/wii.rs
@@ -3,9 +3,8 @@ use crate::system::{System, WII};
pub type Wii = System<{ WII }>;
-
impl Wii {
pub fn new(entrypoint: u32) -> Self {
- Self::with_scheduler(entrypoint, Scheduler::empty())
+ Self::with_scheduler(entrypoint, Scheduler::new_wii())
}
}
diff --git a/crates/scripting/src/lib.rs b/crates/scripting/src/lib.rs
index e45916f..1631d8a 100644
--- a/crates/scripting/src/lib.rs
+++ b/crates/scripting/src/lib.rs
@@ -461,7 +461,7 @@ impl std::ops::DerefMut for GameCubeRef {
}
}
-impl Host for LuaHost {
+impl Host<{ gecko::system::GC }> for LuaHost {
fn hook_state(&self) -> HookState {
HookState {
flags: self.flags,