Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

final non-gx refactor

Layle9009038a1c8b
diff --git a/crates/gecko/src/dvd.rs b/crates/gecko/src/dvd.rs
index ef83367..2f91253 100644
--- a/crates/gecko/src/dvd.rs
+++ b/crates/gecko/src/dvd.rs
@@ -41,6 +41,7 @@ impl DvdInterface {
}
}
+ #[inline(always)]
pub fn interrupt_active(&self) -> bool {
(self.status.break_complete() && self.status.break_complete_mask())
|| (self.status.device_error() && self.status.device_error_mask())
diff --git a/crates/gecko/src/dvd/regs.rs b/crates/gecko/src/dvd/regs.rs
index 5d1c886..2b8e881 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::{MmioHandler, WriteMask};
+use crate::mmio::traits::{MmioAccess, WriteMask};
use chapa::BitEnum;
// 0xCC006000 4 R/W DISR - DI Status Register
@@ -31,7 +31,7 @@ pub struct DiStatusRegister {
}
crate::mmio_reg!(DiStatusRegister: u32 @ 0xCC006000);
-impl MmioHandler<GameCube> for DiStatusRegister {
+impl MmioAccess<GameCube> for DiStatusRegister {
fn read(gc: &mut GameCube) -> Self {
gc.di.status
}
@@ -80,7 +80,7 @@ pub struct DiCoverRegister {
}
crate::mmio_reg!(DiCoverRegister: u32 @ 0xCC006004);
-impl MmioHandler<GameCube> for DiCoverRegister {
+impl MmioAccess<GameCube> for DiCoverRegister {
fn read(gc: &mut GameCube) -> Self {
gc.di.cover
}
@@ -111,7 +111,7 @@ pub struct DiCommandBuf0 {
}
crate::mmio_reg!(DiCommandBuf0: u32 @ 0xCC006008);
-impl MmioHandler<GameCube> for DiCommandBuf0 {
+impl MmioAccess<GameCube> for DiCommandBuf0 {
fn read(gc: &mut GameCube) -> Self {
DiCommandBuf0::from_raw(gc.di.cmdbuf0)
}
@@ -136,7 +136,7 @@ pub struct DiCommandBuf1 {
}
crate::mmio_reg!(DiCommandBuf1: u32 @ 0xCC00600C);
-impl MmioHandler<GameCube> for DiCommandBuf1 {
+impl MmioAccess<GameCube> for DiCommandBuf1 {
fn read(gc: &mut GameCube) -> Self {
DiCommandBuf1::from_raw(gc.di.cmdbuf1)
}
@@ -155,7 +155,7 @@ pub struct DiCommandBuf2 {
}
crate::mmio_reg!(DiCommandBuf2: u32 @ 0xCC006010);
-impl MmioHandler<GameCube> for DiCommandBuf2 {
+impl MmioAccess<GameCube> for DiCommandBuf2 {
fn read(gc: &mut GameCube) -> Self {
DiCommandBuf2::from_raw(gc.di.cmdbuf2)
}
@@ -216,7 +216,7 @@ pub struct DiControlRegister {
}
crate::mmio_reg!(DiControlRegister: u32 @ 0xCC00601C);
-impl MmioHandler<GameCube> for DiControlRegister {
+impl MmioAccess<GameCube> for DiControlRegister {
fn read(gc: &mut GameCube) -> Self {
gc.di.control
}
@@ -245,7 +245,7 @@ pub struct DiImmBuf {
}
crate::mmio_reg!(DiImmBuf: u32 @ 0xCC006020);
-impl MmioHandler<GameCube> for DiImmBuf {
+impl MmioAccess<GameCube> for DiImmBuf {
fn read(gc: &mut GameCube) -> Self {
DiImmBuf::from_raw(gc.di.immbuf)
}
@@ -271,7 +271,7 @@ impl Default for DiConfigurationRegister {
}
}
-impl MmioHandler<GameCube> for DiConfigurationRegister {
+impl MmioAccess<GameCube> for DiConfigurationRegister {
fn read(gc: &mut GameCube) -> Self {
gc.di.config
}
diff --git a/crates/gecko/src/flipper/ai.rs b/crates/gecko/src/flipper/ai.rs
index 0f1b9e2..660d512 100644
--- a/crates/gecko/src/flipper/ai.rs
+++ b/crates/gecko/src/flipper/ai.rs
@@ -26,11 +26,13 @@ impl AudioInterface {
}
}
+ #[inline(always)]
pub fn interrupt_active(&self) -> bool {
self.control.interrupt() && self.control.interrupt_mask()
}
/// Compute the current sample counter based on elapsed cycles
+ #[inline(always)]
pub fn sample_count(&self, current_cycles: u64) -> u32 {
if self.control.playback_status() != regs::Status::Play {
return 0;
diff --git a/crates/gecko/src/flipper/ai/regs.rs b/crates/gecko/src/flipper/ai/regs.rs
index ab0838e..294392b 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::{MmioHandler, WriteMask};
+use crate::mmio::traits::{MmioAccess, WriteMask};
use chapa::BitEnum;
// 0xCC006C00 4 R/W AICR - Audio Interface Control Register
@@ -43,7 +43,7 @@ pub struct AiControl {
}
crate::mmio_reg!(AiControl: u32 @ 0xCC006C00);
-impl MmioHandler<GameCube> for AiControl {
+impl MmioAccess<GameCube> for AiControl {
fn read(gc: &mut GameCube) -> Self {
gc.ai.control
}
@@ -98,7 +98,7 @@ pub struct AiSampleCounter {
}
crate::mmio_reg!(AiSampleCounter: u32 @ 0xCC006C08);
-impl MmioHandler<GameCube> for AiSampleCounter {
+impl MmioAccess<GameCube> for AiSampleCounter {
fn read(gc: &mut GameCube) -> Self {
let count = gc.ai.sample_count(gc.scheduler.cycles);
AiSampleCounter::from_raw(count)
@@ -118,7 +118,7 @@ pub struct AiInterruptTiming {
}
crate::mmio_reg!(AiInterruptTiming: u32 @ 0xCC006C0C);
-impl MmioHandler<GameCube> for AiInterruptTiming {
+impl MmioAccess<GameCube> for AiInterruptTiming {
fn read(gc: &mut GameCube) -> Self {
gc.ai.interrupt_timing
}
diff --git a/crates/gecko/src/flipper/cp.rs b/crates/gecko/src/flipper/cp.rs
index c8c6077..6edc551 100644
--- a/crates/gecko/src/flipper/cp.rs
+++ b/crates/gecko/src/flipper/cp.rs
@@ -1,7 +1,6 @@
pub mod regs;
-use crate::mmio::constants::CP_BASE;
-use crate::mmio::traits::{MmioAccess, MmioRegister, MmioRw};
+use crate::gamecube::GameCube;
pub struct CommandProcessor {
pub status: regs::CpStatus,
@@ -44,6 +43,7 @@ impl CommandProcessor {
}
}
+ #[inline(always)]
pub fn interrupt_active(&self) -> bool {
(self.status.bp_interrupt() && self.control.bp_interrupt_enable())
|| (self.status.fifo_overflow() && self.control.fifo_overflow_interrupt_enable())
@@ -51,11 +51,10 @@ impl CommandProcessor {
}
}
-impl MmioRw for CommandProcessor {
- const BASE: u32 = CP_BASE;
- const NAME: &'static str = "CP";
-
- crate::impl_mmio_dispatch!(
+crate::mmio_device_dispatch! {
+ read = cp_read,
+ write = cp_write,
+ registers = [
regs::CpStatus,
regs::CpControl,
regs::CpClear,
@@ -73,15 +72,16 @@ impl MmioRw for CommandProcessor {
regs::FifoWritePtrHi,
regs::FifoReadPtrLo,
regs::FifoReadPtrHi,
- );
+ ],
}
-impl crate::gamecube::GameCube {
- pub fn check_cp_interrupts(&mut self) {
- if self.cp.interrupt_active() {
- self.pi.assert_interrupt(crate::flipper::pi::InterruptFlag::Cp);
- } else {
- self.pi.clear_interrupt(crate::flipper::pi::InterruptFlag::Cp);
- }
+#[inline(always)]
+pub fn refresh_interrupts(gc: &mut GameCube) {
+ use crate::flipper::pi::InterruptFlag;
+
+ if gc.cp.interrupt_active() {
+ gc.pi.assert_interrupt(InterruptFlag::Cp);
+ } else {
+ gc.pi.clear_interrupt(InterruptFlag::Cp);
}
}
diff --git a/crates/gecko/src/flipper/cp/regs.rs b/crates/gecko/src/flipper/cp/regs.rs
index 9f105ca..005dff6 100644
--- a/crates/gecko/src/flipper/cp/regs.rs
+++ b/crates/gecko/src/flipper/cp/regs.rs
@@ -1,91 +1,188 @@
-use super::CommandProcessor;
-use crate::mmio::traits::MmioAccess;
+use crate::flipper::cp;
+use crate::gamecube::GameCube;
+use crate::mmio::traits::{MmioAccess, WriteMask};
-// 0xCC000000 2 R/W CP_STATUS - CP Status Register
+// 0xCC000000 2 R/W CP_STATUS (CP Status Register)
-crate::mmio_register! {
- CpStatus: u16 @ 0xCC000000 => CommandProcessor.status {
- #[bits(0)]
- pub fifo_overflow: bool,
+#[chapa::bitfield(u16, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct CpStatus {
+ #[bits(0)]
+ pub fifo_overflow: bool,
- #[bits(1)]
- pub fifo_underflow: bool,
+ #[bits(1)]
+ pub fifo_underflow: bool,
- #[bits(2)]
- pub read_idle: bool,
+ #[bits(2)]
+ pub read_idle: bool,
- #[bits(3)]
- pub cmd_idle: bool,
+ #[bits(3)]
+ pub cmd_idle: bool,
- #[bits(4)]
- pub bp_interrupt: bool,
+ #[bits(4)]
+ pub bp_interrupt: bool,
+}
+crate::mmio_reg!(CpStatus: u16 @ 0xCC000000);
+
+impl MmioAccess<GameCube> for CpStatus {
+ fn read(gc: &mut GameCube) -> Self {
+ gc.cp.status
+ }
+
+ fn write(self, gc: &mut GameCube, _: WriteMask) {
+ gc.cp.status = self;
+ cp::refresh_interrupts(gc);
}
}
-// 0xCC000002 2 R/W CP_CTRL - CP Control Register
+// 0xCC000002 2 R/W CP_CTRL (CP Control Register)
+
+#[chapa::bitfield(u16, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct CpControl {
+ #[bits(0)]
+ pub gp_fifo_read_enable: bool,
-crate::mmio_register! {
- CpControl: u16 @ 0xCC000002 => CommandProcessor.control {
- #[bits(0)]
- pub gp_fifo_read_enable: bool,
+ #[bits(1)]
+ pub cp_interrupt_enable: bool,
- #[bits(1)]
- pub cp_interrupt_enable: bool,
+ #[bits(2)]
+ pub fifo_overflow_interrupt_enable: bool,
- #[bits(2)]
- pub fifo_overflow_interrupt_enable: bool,
+ #[bits(3)]
+ pub fifo_underflow_interrupt_enable: bool,
- #[bits(3)]
- pub fifo_underflow_interrupt_enable: bool,
+ #[bits(4)]
+ pub gp_link_enable: bool,
- #[bits(4)]
- pub gp_link_enable: bool,
+ #[bits(5)]
+ pub bp_interrupt_enable: bool,
+}
+crate::mmio_reg!(CpControl: u16 @ 0xCC000002);
+
+impl MmioAccess<GameCube> for CpControl {
+ fn read(gc: &mut GameCube) -> Self {
+ gc.cp.control
+ }
- #[bits(5)]
- pub bp_interrupt_enable: bool,
+ fn write(self, gc: &mut GameCube, _: WriteMask) {
+ gc.cp.control = self;
+ cp::refresh_interrupts(gc);
}
}
// 0xCC000004 2 W Clear Register
-crate::mmio_register! {
- CpClear: u16 @ 0xCC000004 {
- #[bits(0)]
- pub clear_overflow: bool,
+#[chapa::bitfield(u16, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct CpClear {
+ #[bits(0)]
+ pub clear_overflow: bool,
- #[bits(1)]
- pub clear_underflow: bool,
- }
+ #[bits(1)]
+ pub clear_underflow: bool,
}
+crate::mmio_reg!(CpClear: u16 @ 0xCC000004);
-impl MmioAccess<CommandProcessor> for CpClear {
- fn read(_cp: &CommandProcessor) -> Self {
- tracing::warn!("attempted to read from write-only CpClear register");
+impl MmioAccess<GameCube> for CpClear {
+ fn read(_gc: &mut GameCube) -> Self {
+ tracing::warn!("attempted to read from write only CpClear register");
Self::from_raw(0)
}
- fn write(self, cp: &mut CommandProcessor) {
+ fn write(self, gc: &mut GameCube, _: WriteMask) {
if self.clear_overflow() {
- cp.status = cp.status.with_fifo_overflow(false);
+ gc.cp.status = gc.cp.status.with_fifo_overflow(false);
}
-
if self.clear_underflow() {
- cp.status = cp.status.with_fifo_underflow(false);
+ gc.cp.status = gc.cp.status.with_fifo_underflow(false);
}
+ cp::refresh_interrupts(gc);
}
}
-crate::mmio_register! { FifoBaseLo: u16 @ 0xCC000020 => CommandProcessor.fifo_base_lo {} }
-crate::mmio_register! { FifoBaseHi: u16 @ 0xCC000022 => CommandProcessor.fifo_base_hi {} }
-crate::mmio_register! { FifoEndLo: u16 @ 0xCC000024 => CommandProcessor.fifo_end_lo {} }
-crate::mmio_register! { FifoEndHi: u16 @ 0xCC000026 => CommandProcessor.fifo_end_hi {} }
-crate::mmio_register! { FifoHiWatermarkLo: u16 @ 0xCC000028 => CommandProcessor.fifo_hi_watermark_lo {} }
-crate::mmio_register! { FifoHiWatermarkHi: u16 @ 0xCC00002A => CommandProcessor.fifo_hi_watermark_hi {} }
-crate::mmio_register! { FifoLoWatermarkLo: u16 @ 0xCC00002C => CommandProcessor.fifo_lo_watermark_lo {} }
-crate::mmio_register! { FifoLoWatermarkHi: u16 @ 0xCC00002E => CommandProcessor.fifo_lo_watermark_hi {} }
-crate::mmio_register! { FifoRwDistanceLo: u16 @ 0xCC000030 => CommandProcessor.fifo_rw_distance_lo {} }
-crate::mmio_register! { FifoRwDistanceHi: u16 @ 0xCC000032 => CommandProcessor.fifo_rw_distance_hi {} }
-crate::mmio_register! { FifoWritePtrLo: u16 @ 0xCC000034 => CommandProcessor.fifo_write_ptr_lo {} }
-crate::mmio_register! { FifoWritePtrHi: u16 @ 0xCC000036 => CommandProcessor.fifo_write_ptr_hi {} }
-crate::mmio_register! { FifoReadPtrLo: u16 @ 0xCC000038 => CommandProcessor.fifo_read_ptr_lo {} }
-crate::mmio_register! { FifoReadPtrHi: u16 @ 0xCC00003A => CommandProcessor.fifo_read_ptr_hi {} }
+// 0xCC000020..=0xCC00003B: FIFO pointer registers. All plain 16 bit storage.
+
+#[chapa::bitfield(u16, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct FifoBaseLo {}
+crate::mmio_reg!(FifoBaseLo: u16 @ 0xCC000020);
+crate::mmio_default_access!(FifoBaseLo => GameCube.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);
+
+#[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);
+
+#[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);
+
+#[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);
+
+#[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);
+
+#[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);
+
+#[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);
+
+#[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);
+
+#[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);
+
+#[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);
+
+#[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);
+
+#[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);
+
+#[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);
diff --git a/crates/gecko/src/flipper/dsp/regs.rs b/crates/gecko/src/flipper/dsp/regs.rs
index e446067..435b69a 100644
--- a/crates/gecko/src/flipper/dsp/regs.rs
+++ b/crates/gecko/src/flipper/dsp/regs.rs
@@ -1,6 +1,6 @@
use crate::flipper::dsp;
use crate::gamecube::GameCube;
-use crate::mmio::traits::{MmioHandler, WriteMask};
+use crate::mmio::traits::{MmioAccess, WriteMask};
use chapa::BitEnum;
// 0xCC00500A 2 [R/W] CSR - DSP Control/Status Register
@@ -64,7 +64,7 @@ impl Default for ControlStatus {
}
}
-impl MmioHandler<GameCube> for ControlStatus {
+impl MmioAccess<GameCube> for ControlStatus {
fn read(gc: &mut GameCube) -> Self {
gc.dsp.csr
}
@@ -133,7 +133,7 @@ pub struct MailboxToDspHi {
}
crate::mmio_reg!(MailboxToDspHi: u16 @ 0xCC005000);
-impl MmioHandler<GameCube> for MailboxToDspHi {
+impl MmioAccess<GameCube> for MailboxToDspHi {
fn read(gc: &mut GameCube) -> Self {
gc.dsp.mailbox_to_dsp_hi
}
@@ -152,7 +152,7 @@ impl MmioHandler<GameCube> for MailboxToDspHi {
pub struct MailboxToDspLo {}
crate::mmio_reg!(MailboxToDspLo: u16 @ 0xCC005002);
-impl MmioHandler<GameCube> for MailboxToDspLo {
+impl MmioAccess<GameCube> for MailboxToDspLo {
fn read(gc: &mut GameCube) -> Self {
gc.dsp.mailbox_to_dsp_lo
}
@@ -181,7 +181,7 @@ pub struct MailboxToCpuHi {
}
crate::mmio_reg!(MailboxToCpuHi: u16 @ 0xCC005004);
-impl MmioHandler<GameCube> for MailboxToCpuHi {
+impl MmioAccess<GameCube> for MailboxToCpuHi {
fn read(gc: &mut GameCube) -> Self {
gc.dsp.mailbox_to_cpu_hi
}
@@ -199,7 +199,7 @@ impl MmioHandler<GameCube> for MailboxToCpuHi {
pub struct MailboxToCpuLo {}
crate::mmio_reg!(MailboxToCpuLo: u16 @ 0xCC005006);
-impl MmioHandler<GameCube> for MailboxToCpuLo {
+impl MmioAccess<GameCube> for MailboxToCpuLo {
fn read(gc: &mut GameCube) -> Self {
let val = gc.dsp.mailbox_to_cpu_lo;
// Reading DMBL clears DMBH.M (bit 15), signaling the CPU has consumed the mail
@@ -230,7 +230,7 @@ pub struct AramMode {
}
crate::mmio_reg!(AramMode: u16 @ 0xCC005016);
-impl MmioHandler<GameCube> for AramMode {
+impl MmioAccess<GameCube> for AramMode {
fn read(gc: &mut GameCube) -> Self {
gc.dsp.aram_mode.with_status(true)
}
@@ -285,7 +285,7 @@ pub struct AudioDmaControl {
}
crate::mmio_reg!(AudioDmaControl: u16 @ 0xCC005036);
-impl MmioHandler<GameCube> for AudioDmaControl {
+impl MmioAccess<GameCube> for AudioDmaControl {
fn read(gc: &mut GameCube) -> Self {
gc.dsp.audio_dma_control
}
@@ -316,7 +316,7 @@ pub struct AramDmaControl {
}
crate::mmio_reg!(AramDmaControl: u32 @ 0xCC005028);
-impl MmioHandler<GameCube> for AramDmaControl {
+impl MmioAccess<GameCube> for AramDmaControl {
fn read(gc: &mut GameCube) -> Self {
gc.dsp.aram_dma_control
}
diff --git a/crates/gecko/src/flipper/exi.rs b/crates/gecko/src/flipper/exi.rs
index 2efdf0e..43c6e83 100644
--- a/crates/gecko/src/flipper/exi.rs
+++ b/crates/gecko/src/flipper/exi.rs
@@ -76,18 +76,21 @@ impl ExternalInterface {
}
}
+ #[inline(always)]
pub fn interrupt_active(&self) -> bool {
Self::channel_interrupt_active(&self.ch0_csr)
|| Self::channel_interrupt_active(&self.ch1_csr)
|| Self::channel_interrupt_active(&self.ch2_csr)
}
+ #[inline(always)]
fn channel_interrupt_active(csr: &impl regs::ChannelStatus) -> bool {
(csr.exi_interrupt() && csr.exi_interrupt_mask())
|| (csr.tc_interrupt() && csr.tc_interrupt_mask())
|| (csr.ext_interrupt() && csr.ext_interrupt_mask())
}
+ #[inline(always)]
pub fn start_immediate_transfer<const CHANNEL: usize>(&mut self) {
let (transfer_type, transfer_length, chip_select, mut bytes) = match CHANNEL {
0 => (
@@ -141,6 +144,7 @@ impl ExternalInterface {
self.finish_transfer::<CHANNEL>();
}
+ #[inline(always)]
fn set_data<const CHANNEL: usize>(&mut self, val: u32) {
match CHANNEL {
0 => self.ch0_data = regs::Channel0Data::from_raw(val),
@@ -150,6 +154,7 @@ impl ExternalInterface {
}
}
+ #[inline(always)]
fn finish_transfer<const CHANNEL: usize>(&mut self) {
match CHANNEL {
0 => {
@@ -215,6 +220,7 @@ pub fn on_chip_select_written<const CHANNEL: usize>(gc: &mut GameCube, new_cs: u
gc.exi.prev_cs[CHANNEL] = new_cs;
}
+#[inline(always)]
pub fn run_dma<const CHANNEL: usize>(gc: &mut GameCube) {
let (cs, transfer_type, address, length) = match CHANNEL {
0 => (
diff --git a/crates/gecko/src/flipper/exi/regs.rs b/crates/gecko/src/flipper/exi/regs.rs
index 817de11..7afb9a5 100644
--- a/crates/gecko/src/flipper/exi/regs.rs
+++ b/crates/gecko/src/flipper/exi/regs.rs
@@ -2,7 +2,7 @@ use chapa::BitEnum;
use crate::flipper::exi;
use crate::gamecube::GameCube;
-use crate::mmio::traits::{MmioHandler, MmioRegister, WriteMask};
+use crate::mmio::traits::{MmioAccess, MmioRegister, WriteMask};
pub trait ChannelStatus {
fn exi_interrupt(&self) -> bool;
@@ -90,7 +90,7 @@ pub struct Channel0Status {
}
crate::mmio_reg!(Channel0Status: u32 @ 0xCC006800);
-impl MmioHandler<GameCube> for Channel0Status {
+impl MmioAccess<GameCube> for Channel0Status {
fn read(gc: &mut GameCube) -> Self {
gc.exi.ch0_csr
}
@@ -139,7 +139,7 @@ pub struct Channel0Control {
}
crate::mmio_reg!(Channel0Control: u32 @ 0xCC00680C);
-impl MmioHandler<GameCube> for Channel0Control {
+impl MmioAccess<GameCube> for Channel0Control {
fn read(gc: &mut GameCube) -> Self {
gc.exi.ch0_cr
}
@@ -193,7 +193,7 @@ pub struct Channel1Status {
}
crate::mmio_reg!(Channel1Status: u32 @ 0xCC006814);
-impl MmioHandler<GameCube> for Channel1Status {
+impl MmioAccess<GameCube> for Channel1Status {
fn read(gc: &mut GameCube) -> Self {
gc.exi.ch1_csr
}
@@ -242,7 +242,7 @@ pub struct Channel1Control {
}
crate::mmio_reg!(Channel1Control: u32 @ 0xCC006820);
-impl MmioHandler<GameCube> for Channel1Control {
+impl MmioAccess<GameCube> for Channel1Control {
fn read(gc: &mut GameCube) -> Self {
gc.exi.ch1_cr
}
@@ -296,7 +296,7 @@ pub struct Channel2Status {
}
crate::mmio_reg!(Channel2Status: u32 @ 0xCC006828);
-impl MmioHandler<GameCube> for Channel2Status {
+impl MmioAccess<GameCube> for Channel2Status {
fn read(gc: &mut GameCube) -> Self {
gc.exi.ch2_csr
}
@@ -347,7 +347,7 @@ pub struct Channel2Control {
}
crate::mmio_reg!(Channel2Control: u32 @ 0xCC006834);
-impl MmioHandler<GameCube> for Channel2Control {
+impl MmioAccess<GameCube> for Channel2Control {
fn read(gc: &mut GameCube) -> Self {
gc.exi.ch2_cr
}
diff --git a/crates/gecko/src/flipper/gx.rs b/crates/gecko/src/flipper/gx.rs
index d7ae71c..a7e595e 100644
--- a/crates/gecko/src/flipper/gx.rs
+++ b/crates/gecko/src/flipper/gx.rs
@@ -128,6 +128,6 @@ impl GameCube {
}
}
- self.check_pe_interrupts();
+ crate::flipper::pe::refresh_interrupts(self);
}
}
diff --git a/crates/gecko/src/flipper/mi.rs b/crates/gecko/src/flipper/mi.rs
index 15fe153..741e25d 100644
--- a/crates/gecko/src/flipper/mi.rs
+++ b/crates/gecko/src/flipper/mi.rs
@@ -1,8 +1,5 @@
pub mod regs;
-use crate::mmio::constants::MI_BASE;
-use crate::mmio::traits::{MmioAccess, MmioRegister, MmioRw};
-
pub struct MemoryInterface {
pub interrupt_mask: regs::MiInterruptMask,
}
@@ -15,9 +12,10 @@ impl MemoryInterface {
}
}
-impl MmioRw for MemoryInterface {
- const BASE: u32 = MI_BASE;
- const NAME: &'static str = "MI";
-
- crate::impl_mmio_dispatch!(regs::MiInterruptMask,);
+crate::mmio_device_dispatch! {
+ read = mi_read,
+ write = mi_write,
+ registers = [
+ regs::MiInterruptMask,
+ ],
}
diff --git a/crates/gecko/src/flipper/mi/regs.rs b/crates/gecko/src/flipper/mi/regs.rs
index c0b8c3f..a1eb4aa 100644
--- a/crates/gecko/src/flipper/mi/regs.rs
+++ b/crates/gecko/src/flipper/mi/regs.rs
@@ -1,22 +1,22 @@
-use super::MemoryInterface;
-
// 0xCC00401C 2 R/W Memory Interface Interrupt Mask
-crate::mmio_register! {
- MiInterruptMask: u16 @ 0xCC00401C => MemoryInterface.interrupt_mask {
- #[bits(0)]
- pub mem0_enable: bool,
+#[chapa::bitfield(u16, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct MiInterruptMask {
+ #[bits(0)]
+ pub mem0_enable: bool,
- #[bits(1)]
- pub mem1_enable: bool,
+ #[bits(1)]
+ pub mem1_enable: bool,
- #[bits(2)]
- pub mem2_enable: bool,
+ #[bits(2)]
+ pub mem2_enable: bool,
- #[bits(3)]
- pub mem3_enable: bool,
+ #[bits(3)]
+ pub mem3_enable: bool,
- #[bits(4)]
- pub master_enable: bool,
- }
+ #[bits(4)]
+ pub master_enable: bool,
}
+crate::mmio_reg!(MiInterruptMask: u16 @ 0xCC00401C);
+crate::mmio_default_access!(MiInterruptMask => GameCube.mi.interrupt_mask);
diff --git a/crates/gecko/src/flipper/pe.rs b/crates/gecko/src/flipper/pe.rs
index 3008b85..948a8f0 100644
--- a/crates/gecko/src/flipper/pe.rs
+++ b/crates/gecko/src/flipper/pe.rs
@@ -1,8 +1,7 @@
pub mod regs;
+
use crate::flipper::pi::InterruptFlag;
use crate::gamecube::GameCube;
-use crate::mmio::constants::PE_BASE;
-use crate::mmio::traits::{MmioAccess, MmioRegister, MmioRw};
pub struct PixelEngine {
pub zconf: regs::ZConfig,
@@ -27,10 +26,12 @@ impl PixelEngine {
}
}
+ #[inline(always)]
pub fn finish_interrupt_active(&self) -> bool {
self.sr.pe_finish_enable() && self.sr.pe_finish()
}
+ #[inline(always)]
pub fn token_interrupt_active(&self) -> bool {
self.sr.pe_token_enable() && self.sr.pe_token()
}
@@ -49,11 +50,10 @@ impl PixelEngine {
}
}
-impl MmioRw for PixelEngine {
- const BASE: u32 = PE_BASE;
- const NAME: &'static str = "PE";
-
- crate::impl_mmio_dispatch!(
+crate::mmio_device_dispatch! {
+ read = pe_read,
+ write = pe_write,
+ registers = [
regs::ZConfig,
regs::AlphaConfig,
regs::DstAlphaConfig,
@@ -61,21 +61,20 @@ impl MmioRw for PixelEngine {
regs::AlphaRead,
regs::InterruptStatus,
regs::Token,
- );
+ ],
}
-impl GameCube {
- pub fn check_pe_interrupts(&mut self) {
- if self.pe.token_interrupt_active() {
- self.pi.assert_interrupt(InterruptFlag::PeToken);
- } else {
- self.pi.clear_interrupt(InterruptFlag::PeToken);
- }
+#[inline(always)]
+pub fn refresh_interrupts(gc: &mut GameCube) {
+ if gc.pe.token_interrupt_active() {
+ gc.pi.assert_interrupt(InterruptFlag::PeToken);
+ } else {
+ gc.pi.clear_interrupt(InterruptFlag::PeToken);
+ }
- if self.pe.finish_interrupt_active() {
- self.pi.assert_interrupt(InterruptFlag::PeFinish);
- } else {
- self.pi.clear_interrupt(InterruptFlag::PeFinish);
- }
+ if gc.pe.finish_interrupt_active() {
+ gc.pi.assert_interrupt(InterruptFlag::PeFinish);
+ } else {
+ gc.pi.clear_interrupt(InterruptFlag::PeFinish);
}
}
diff --git a/crates/gecko/src/flipper/pe/regs.rs b/crates/gecko/src/flipper/pe/regs.rs
index 3cabb2d..7ce0239 100644
--- a/crates/gecko/src/flipper/pe/regs.rs
+++ b/crates/gecko/src/flipper/pe/regs.rs
@@ -1,78 +1,96 @@
-use crate::flipper::pe::PixelEngine;
-use crate::mmio::traits::{MmioAccess, MmioRegister};
+use crate::flipper::pe;
+use crate::gamecube::GameCube;
+use crate::mmio::traits::{MmioAccess, WriteMask};
// 0xCC001000 2 R/W Z Configuration
-crate::mmio_register! {
- ZConfig: u16 @ 0xCC001000 => PixelEngine.zconf {}
-}
+#[chapa::bitfield(u16, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct ZConfig {}
+crate::mmio_reg!(ZConfig: u16 @ 0xCC001000);
+crate::mmio_default_access!(ZConfig => GameCube.pe.zconf);
// 0xCC001002 2 R/W Alpha Configuration
-crate::mmio_register! {
- AlphaConfig: u16 @ 0xCC001002 => PixelEngine.alphaconf {}
-}
+#[chapa::bitfield(u16, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct AlphaConfig {}
+crate::mmio_reg!(AlphaConfig: u16 @ 0xCC001002);
+crate::mmio_default_access!(AlphaConfig => GameCube.pe.alphaconf);
// 0xCC001004 2 R/W Destination Alpha
-crate::mmio_register! {
- DstAlphaConfig: u16 @ 0xCC001004 => PixelEngine.dst_alphaconf {}
-}
+#[chapa::bitfield(u16, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct DstAlphaConfig {}
+crate::mmio_reg!(DstAlphaConfig: u16 @ 0xCC001004);
+crate::mmio_default_access!(DstAlphaConfig => GameCube.pe.dst_alphaconf);
// 0xCC001006 2 R/W Alpha Compare Mode
-crate::mmio_register! {
- AlphaMode: u16 @ 0xCC001006 => PixelEngine.alphamode {}
-}
+#[chapa::bitfield(u16, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct AlphaMode {}
+crate::mmio_reg!(AlphaMode: u16 @ 0xCC001006);
+crate::mmio_default_access!(AlphaMode => GameCube.pe.alphamode);
// 0xCC001008 2 R/W Alpha Read Mode
-crate::mmio_register! {
- AlphaRead: u16 @ 0xCC001008 => PixelEngine.alpharead {}
-}
+#[chapa::bitfield(u16, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct AlphaRead {}
+crate::mmio_reg!(AlphaRead: u16 @ 0xCC001008);
+crate::mmio_default_access!(AlphaRead => GameCube.pe.alpharead);
// 0xCC00100A 2 R/W Interrupt Status
-crate::mmio_register! {
- InterruptStatus: u16 @ 0xCC00100A {
- #[bits(0)]
- pub pe_token_enable: bool,
+#[chapa::bitfield(u16, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct InterruptStatus {
+ #[bits(0)]
+ pub pe_token_enable: bool,
- #[bits(1)]
- pub pe_finish_enable: bool,
+ #[bits(1)]
+ pub pe_finish_enable: bool,
- #[bits(2)]
- pub pe_token: bool,
+ #[bits(2)]
+ pub pe_token: bool,
- #[bits(3)]
- pub pe_finish: bool,
- }
+ #[bits(3)]
+ pub pe_finish: bool,
}
+crate::mmio_reg!(InterruptStatus: u16 @ 0xCC00100A);
-impl MmioAccess<PixelEngine> for InterruptStatus {
- fn read(pe: &PixelEngine) -> Self {
- // status bits (token/finish) always read back as zero
- pe.sr.with_pe_token(false).with_pe_finish(false)
+impl MmioAccess<GameCube> for InterruptStatus {
+ fn read(gc: &mut GameCube) -> Self {
+ // Status bits (token/finish) always read back as zero.
+ gc.pe.sr.with_pe_token(false).with_pe_finish(false)
}
- fn write(self, pe: &mut PixelEngine) {
- Self::write_at(pe, Self::ADDR, Self::SIZE as u32, self.to_raw());
- }
-
- fn write_at(pe: &mut PixelEngine, addr: u32, access_size: u32, val: u32) {
- const ENABLE_MASK: u32 = (1 << 0) | (1 << 1);
- const STATUS_MASK: u32 = (1 << 2) | (1 << 3);
-
- let current = pe.sr.to_raw();
- let merged = Self::write_sub(current, addr, access_size, val);
- let written_bits = Self::write_sub(0, addr, access_size, val);
- let next_status = (current & STATUS_MASK) & !(written_bits & STATUS_MASK);
- let next = (merged & ENABLE_MASK) | next_status;
-
- pe.sr = <Self as MmioRegister>::from_raw(next);
+ fn write(self, gc: &mut GameCube, mask: WriteMask) {
+ if !mask.byte(1) {
+ return;
+ }
+
+ let mut sr = gc.pe.sr;
+ sr = sr
+ .with_pe_token_enable(self.pe_token_enable())
+ .with_pe_finish_enable(self.pe_finish_enable());
+ if self.pe_token() {
+ sr = sr.with_pe_token(false);
+ }
+ if self.pe_finish() {
+ sr = sr.with_pe_finish(false);
+ }
+ gc.pe.sr = sr;
+ pe::refresh_interrupts(gc);
}
}
-crate::mmio_register! {
- Token: u16 @ 0xCC00100E => PixelEngine.token {}
-}
+// 0xCC00100E 2 R/W Token
+
+#[chapa::bitfield(u16, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct Token {}
+crate::mmio_reg!(Token: u16 @ 0xCC00100E);
+crate::mmio_default_access!(Token => GameCube.pe.token);
diff --git a/crates/gecko/src/flipper/pi.rs b/crates/gecko/src/flipper/pi.rs
index 936c083..7db2b32 100644
--- a/crates/gecko/src/flipper/pi.rs
+++ b/crates/gecko/src/flipper/pi.rs
@@ -1,13 +1,5 @@
pub mod regs;
-use crate::mmio::constants::PI_BASE;
-use crate::mmio::traits::{MmioAccess, MmioRegister, MmioRw};
-
-// PI FIFO register offsets (from PI_BASE 0xCC003000)
-const PI_FIFO_BASE_OFFSET: u32 = 0x0C;
-const PI_FIFO_END_OFFSET: u32 = 0x10;
-const PI_FIFO_WPTR_OFFSET: u32 = 0x14;
-
pub struct ProcessorInterface {
pub intsr: regs::InterruptCause,
pub intmr: regs::InterruptMask,
@@ -16,7 +8,7 @@ pub struct ProcessorInterface {
pub fifo_base: u32,
/// CPU FIFO end address in physical memory
pub fifo_end: u32,
- /// CPU FIFO write pointer (32-byte aligned)
+ /// CPU FIFO write pointer (32 byte aligned)
pub fifo_wptr: u32,
}
@@ -73,33 +65,16 @@ impl ProcessorInterface {
}
}
-impl MmioRw for ProcessorInterface {
- const BASE: u32 = PI_BASE;
- const NAME: &'static str = "PI";
-
- crate::impl_mmio_dispatch!(
+crate::mmio_device_dispatch! {
+ read = pi_read,
+ write = pi_write,
+ registers = [
regs::InterruptCause,
regs::InterruptMask,
+ regs::FifoBase,
+ regs::FifoEnd,
+ regs::FifoWritePtr,
regs::ResetCode,
regs::FlipperRev,
- );
-
- fn mmio_write_u32(&mut self, offset: u32, val: u32) {
- match offset {
- PI_FIFO_BASE_OFFSET => {
- self.fifo_base = val;
- }
- PI_FIFO_END_OFFSET => {
- self.fifo_end = val;
- }
- PI_FIFO_WPTR_OFFSET => {
- self.fifo_wptr = val & 0x1FFF_FFE0; // 32-byte aligned
- }
- _ => {
- if !self.write_raw(PI_BASE + offset, 4, val) {
- tracing::error!(offset = format!("{offset:08X}"), "unhandled PI write_u32");
- }
- }
- }
- }
+ ],
}
diff --git a/crates/gecko/src/flipper/pi/regs.rs b/crates/gecko/src/flipper/pi/regs.rs
index 9e304c9..941fe6b 100644
--- a/crates/gecko/src/flipper/pi/regs.rs
+++ b/crates/gecko/src/flipper/pi/regs.rs
@@ -1,156 +1,218 @@
-use super::ProcessorInterface;
+use crate::gamecube::GameCube;
+use crate::mmio::traits::{MmioAccess, WriteMask};
-// 0xCC003000 4 r INTSR - Interrupt Cause
+// 0xCC003000 4 r INTSR (Interrupt Cause)
-crate::mmio_register! {
- InterruptCause: u32 @ 0xCC003000 {
- #[bits(0, alias = "error")]
- pub gp_runtime_error: bool,
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct InterruptCause {
+ #[bits(0, alias = "error")]
+ pub gp_runtime_error: bool,
- #[bits(1, alias = "rsw")]
- pub reset_switch: bool,
+ #[bits(1, alias = "rsw")]
+ pub reset_switch: bool,
- #[bits(2, alias = "di")]
- pub dvd: bool,
+ #[bits(2, alias = "di")]
+ pub dvd: bool,
- #[bits(3, alias = "si")]
- pub serial: bool,
+ #[bits(3, alias = "si")]
+ pub serial: bool,
- #[bits(4)]
- pub exi: bool,
+ #[bits(4)]
+ pub exi: bool,
- #[bits(5, alias = "ai")]
- pub streaming: bool,
+ #[bits(5, alias = "ai")]
+ pub streaming: bool,
- #[bits(6)]
- pub dsp: bool,
+ #[bits(6)]
+ pub dsp: bool,
- #[bits(7, alias = "mem")]
- pub memory: bool,
+ #[bits(7, alias = "mem")]
+ pub memory: bool,
- #[bits(8, alias = "vi")]
- pub video: bool,
+ #[bits(8, alias = "vi")]
+ pub video: bool,
- #[bits(9, alias = "pe_token")]
- pub token_assertion_in_cmd_list: bool,
+ #[bits(9, alias = "pe_token")]
+ pub token_assertion_in_cmd_list: bool,
- #[bits(10, alias = "pe_finish")]
- pub frame_is_ready: bool,
+ #[bits(10, alias = "pe_finish")]
+ pub frame_is_ready: bool,
- #[bits(11, alias = "cp")]
- pub command_fifo: bool,
+ #[bits(11, alias = "cp")]
+ pub command_fifo: bool,
- #[bits(12)]
- pub debug: bool,
+ #[bits(12)]
+ pub debug: bool,
- #[bits(13, alias = "hsp")]
- pub highspeed_port: bool,
+ #[bits(13, alias = "hsp")]
+ pub highspeed_port: bool,
- #[bits(16)]
- pub rswst: bool,
+ #[bits(16)]
+ pub rswst: bool,
+}
+crate::mmio_reg!(InterruptCause: u32 @ 0xCC003000);
+
+impl Default for InterruptCause {
+ fn default() -> Self {
+ // RSWST needs to be set.
+ Self::from_raw(0).with_rswst(true)
}
}
-impl crate::mmio::traits::MmioAccess<ProcessorInterface> for InterruptCause {
- fn read(dev: &ProcessorInterface) -> Self {
- dev.intsr
+impl MmioAccess<GameCube> for InterruptCause {
+ fn read(gc: &mut GameCube) -> Self {
+ gc.pi.intsr
}
- fn write(self, dev: &mut ProcessorInterface) {
- // yagcd seems to be wrong, we should not
- // clear everything on read, but just usual w1c instead
+ fn write(self, gc: &mut GameCube, _: 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;
- let cleared = dev.intsr.raw() & !self.raw();
- dev.intsr = InterruptCause::from_raw(cleared | (dev.intsr.raw() & RSWST_MASK));
+ let cleared = gc.pi.intsr.raw() & !self.raw();
+ gc.pi.intsr = InterruptCause::from_raw(cleared | (gc.pi.intsr.raw() & RSWST_MASK));
}
}
-impl Default for InterruptCause {
- fn default() -> Self {
- // RSWST needs to be set
- Self::from_raw(0).with_rswst(true)
- }
-}
+// 0xCC003004 4 r/w INTMR (Interrupt Mask)
+
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct InterruptMask {
+ #[bits(0, alias = "error")]
+ pub gp_runtime_error: bool,
+
+ #[bits(1, alias = "rsw")]
+ pub reset_switch: bool,
+
+ #[bits(2, alias = "di")]
+ pub dvd: bool,
-// 0xCC003004 4 r/w INTMR - Interrupt Mask
-crate::mmio_register! {
- InterruptMask: u32 @ 0xCC003004 => ProcessorInterface.intmr {
- #[bits(0, alias = "error")]
- pub gp_runtime_error: bool,
+ #[bits(3, alias = "si")]
+ pub serial: bool,
- #[bits(1, alias = "rsw")]
- pub reset_switch: bool,
+ #[bits(4)]
+ pub exi: bool,
- #[bits(2, alias = "di")]
- pub dvd: bool,
+ #[bits(5, alias = "ai")]
+ pub streaming: bool,
- #[bits(3, alias = "si")]
- pub serial: bool,
+ #[bits(6)]
+ pub dsp: bool,
- #[bits(4)]
- pub exi: bool,
+ #[bits(7, alias = "mem")]
+ pub memory: bool,
- #[bits(5, alias = "ai")]
- pub streaming: bool,
+ #[bits(8, alias = "vi")]
+ pub video: bool,
- #[bits(6)]
- pub dsp: bool,
+ #[bits(9, alias = "pe_token")]
+ pub token_assertion_in_cmd_list: bool,
- #[bits(7, alias = "mem")]
- pub memory: bool,
+ #[bits(10, alias = "pe_finish")]
+ pub frame_is_ready: bool,
- #[bits(8, alias = "vi")]
- pub video: bool,
+ #[bits(11, alias = "cp")]
+ pub command_fifo: bool,
- #[bits(9, alias = "pe_token")]
- pub token_assertion_in_cmd_list: bool,
+ #[bits(12)]
+ pub debug: bool,
- #[bits(10, alias = "pe_finish")]
- pub frame_is_ready: bool,
+ #[bits(13, alias = "hsp")]
+ pub highspeed_port: bool,
+}
+crate::mmio_reg!(InterruptMask: u32 @ 0xCC003004);
+crate::mmio_default_access!(InterruptMask => GameCube.pi.intmr);
- #[bits(11, alias = "cp")]
- pub command_fifo: bool,
+// 0xCC00300C 4 r/w PI_FIFO_BASE - CPU FIFO Base Address
- #[bits(12)]
- pub debug: bool,
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct FifoBase {
+ #[bits(0..=31)]
+ pub value: u32,
+}
+crate::mmio_reg!(FifoBase: u32 @ 0xCC00300C);
- #[bits(13, alias = "hsp")]
- pub highspeed_port: bool,
+impl MmioAccess<GameCube> for FifoBase {
+ fn read(gc: &mut GameCube) -> Self {
+ FifoBase::from_raw(gc.pi.fifo_base)
+ }
+ fn write(self, gc: &mut GameCube, _: WriteMask) {
+ gc.pi.fifo_base = self.raw();
}
}
-// 0xCC003024 4 r/w Console Reset Code
+// 0xCC003010 4 r/w PI_FIFO_END - CPU FIFO End Address
-crate::mmio_register! {
- ResetCode: u32 @ 0xCC003024 {}
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct FifoEnd {
+ #[bits(0..=31)]
+ pub value: u32,
}
+crate::mmio_reg!(FifoEnd: u32 @ 0xCC003010);
-impl crate::mmio::traits::MmioAccess<ProcessorInterface> for ResetCode {
- fn read(_pi: &ProcessorInterface) -> Self {
- Self::from_raw(0)
+impl MmioAccess<GameCube> for FifoEnd {
+ fn read(gc: &mut GameCube) -> Self {
+ FifoEnd::from_raw(gc.pi.fifo_end)
+ }
+ fn write(self, gc: &mut GameCube, _: WriteMask) {
+ gc.pi.fifo_end = self.raw();
}
+}
- fn write(self, _pi: &mut ProcessorInterface) {
- tracing::warn!("TODO: reset DVD");
+// 0xCC003014 4 r/w PI_FIFO_WPTR - CPU FIFO Write Pointer
+
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct FifoWritePtr {
+ #[bits(0..=31)]
+ pub value: u32,
+}
+crate::mmio_reg!(FifoWritePtr: u32 @ 0xCC003014);
+
+impl MmioAccess<GameCube> for FifoWritePtr {
+ fn read(gc: &mut GameCube) -> Self {
+ FifoWritePtr::from_raw(gc.pi.fifo_wptr)
+ }
+ fn write(self, gc: &mut GameCube, _: WriteMask) {
+ gc.pi.fifo_wptr = self.raw() & 0x1FFF_FFE0;
}
}
-// 0xCC00302C 4 r PI_FLIPPER_REV - Flipper Chip Revision
+// 0xCC003024 4 r/w Console Reset Code
-crate::mmio_register! {
- FlipperRev: u32 @ 0xCC00302C {
- #[bits(28..=31)]
- pub revision: u8,
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct ResetCode {}
+crate::mmio_reg!(ResetCode: u32 @ 0xCC003024);
+
+impl MmioAccess<GameCube> for ResetCode {
+ fn read(_gc: &mut GameCube) -> Self {
+ Self::from_raw(0)
+ }
+ fn write(self, _gc: &mut GameCube, _: WriteMask) {
+ tracing::warn!("TODO: reset DVD");
}
}
-impl crate::mmio::traits::MmioAccess<super::ProcessorInterface> for FlipperRev {
- fn read(_pi: &super::ProcessorInterface) -> Self {
- // FLIPPER_REV_C from Dolphin
+// 0xCC00302C 4 r PI_FLIPPER_REV (Flipper Chip Revision)
+
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct FlipperRev {
+ #[bits(28..=31)]
+ pub revision: u8,
+}
+crate::mmio_reg!(FlipperRev: u32 @ 0xCC00302C);
+
+impl MmioAccess<GameCube> for FlipperRev {
+ fn read(_gc: &mut GameCube) -> Self {
+ // FLIPPER_REV_C from Dolphin.
Self::from_raw(0x2465_00B1)
}
-
- fn write(self, _pi: &mut super::ProcessorInterface) {
+ fn write(self, _gc: &mut GameCube, _: WriteMask) {
tracing::warn!("writing to FlipperRev???");
}
}
diff --git a/crates/gecko/src/flipper/si.rs b/crates/gecko/src/flipper/si.rs
index 7ee2abf..948e228 100644
--- a/crates/gecko/src/flipper/si.rs
+++ b/crates/gecko/src/flipper/si.rs
@@ -47,11 +47,13 @@ impl SerialInterface {
}
}
+ #[inline(always)]
pub fn interrupt_active(&self) -> bool {
(self.comcsr.tc_interrupt() && self.comcsr.tc_interrupt_mask())
|| (self.comcsr.rdst_interrupt() && self.comcsr.rdst_interrupt_mask())
}
+ #[inline(always)]
fn read_channel_reg(&mut self, offset: u32) -> u32 {
let ch = (offset / 0x0C) as usize;
match offset % 0x0C {
@@ -68,6 +70,7 @@ impl SerialInterface {
}
}
+ #[inline(always)]
fn write_channel_reg(&mut self, offset: u32, val: u32) {
let ch = (offset / 0x0C) as usize;
match offset % 0x0C {
@@ -78,6 +81,7 @@ impl SerialInterface {
}
}
+ #[inline(always)]
fn channel_reg_raw(&self, aligned_offset: u32) -> u32 {
let ch = (aligned_offset / 0x0C) as usize;
match aligned_offset % 0x0C {
@@ -88,6 +92,7 @@ impl SerialInterface {
}
}
+ #[inline(always)]
fn clear_rdst(&mut self, ch: usize) {
match ch {
0 => self.status = self.status.with_rdst0(false),
@@ -98,6 +103,7 @@ impl SerialInterface {
}
}
+ #[inline(always)]
fn set_rdst(&mut self, ch: usize) {
match ch {
0 => self.status = self.status.with_rdst0(true),
diff --git a/crates/gecko/src/flipper/si/regs.rs b/crates/gecko/src/flipper/si/regs.rs
index 42550b1..35e98f3 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::{MmioHandler, WriteMask};
+use crate::mmio::traits::{MmioAccess, WriteMask};
use chapa::BitEnum;
// 0xCC006430 4 R/W SIPOLL (SI Poll Register)
@@ -77,7 +77,7 @@ pub struct SiComcsr {
}
crate::mmio_reg!(SiComcsr: u32 @ 0xCC006434);
-impl MmioHandler<GameCube> for SiComcsr {
+impl MmioAccess<GameCube> for SiComcsr {
fn read(gc: &mut GameCube) -> Self {
gc.si.comcsr
}
@@ -180,7 +180,7 @@ pub struct SiStatusRegister {
}
crate::mmio_reg!(SiStatusRegister: u32 @ 0xCC006438);
-impl MmioHandler<GameCube> for SiStatusRegister {
+impl MmioAccess<GameCube> for SiStatusRegister {
fn read(gc: &mut GameCube) -> Self {
gc.si.status
}
diff --git a/crates/gecko/src/flipper/vi.rs b/crates/gecko/src/flipper/vi.rs
index e2852b1..0fb4264 100644
--- a/crates/gecko/src/flipper/vi.rs
+++ b/crates/gecko/src/flipper/vi.rs
@@ -1,9 +1,6 @@
pub mod regs;
-use crate::flipper::pi::InterruptFlag;
use crate::gamecube::GameCube;
-use crate::mmio::constants::VI_BASE;
-use crate::mmio::traits::{MmioAccess, MmioRegister, MmioRw};
const CPU_CORE_CLOCK: u64 = 486_000_000;
const CLOCK_FREQUENCIES: [u64; 2] = [27_000_000, 54_000_000];
@@ -123,6 +120,7 @@ impl VideoInterface {
}
/// Returns true if any DI register has both IR_INT and IR_MASK set.
+ #[inline(always)]
pub fn vi_interrupt_active(&self) -> bool {
(self.di0.interrupt() && self.di0.enable())
|| (self.di1.interrupt() && self.di1.enable())
@@ -196,11 +194,10 @@ impl VideoInterface {
}
}
-impl MmioRw for VideoInterface {
- const BASE: u32 = VI_BASE;
- const NAME: &'static str = "VI";
-
- crate::impl_mmio_dispatch!(
+crate::mmio_device_dispatch! {
+ read = vi_read,
+ write = vi_write,
+ registers = [
regs::VerticalTiming,
regs::HorizontalTiming0,
regs::HorizontalTiming1,
@@ -215,6 +212,7 @@ impl MmioRw for VideoInterface {
regs::BottomFieldBaseRight,
regs::DisplayPositionVertical,
regs::DisplayPositionHorizontal,
+ regs::DisplayPositionCombined,
regs::DisplayInterrupt0,
regs::DisplayInterrupt1,
regs::DisplayInterrupt2,
@@ -235,35 +233,34 @@ impl MmioRw for VideoInterface {
regs::ViUnknown70,
regs::BorderHbe,
regs::BorderHbs,
- );
+ ],
}
-impl GameCube {
- pub fn maybe_schedule_vi_half_line(&mut self) {
- if !self.vi.half_line_scheduled {
- let ticks_per_hl = self.vi.ticks_per_half_line();
- if ticks_per_hl > 0 {
- self.vi.half_line_scheduled = true;
- self.scheduler.schedule_in(ticks_per_hl, vi_half_line_handler);
- }
- }
- }
-
- pub fn check_vi_interrupts(&mut self) {
- if self.vi.vi_interrupt_active() {
- self.pi.assert_interrupt(InterruptFlag::Vi);
- } else {
- self.pi.clear_interrupt(InterruptFlag::Vi);
+#[inline(always)]
+pub fn ensure_half_line_scheduled(gc: &mut GameCube) {
+ if !gc.vi.half_line_scheduled {
+ let ticks_per_hl = gc.vi.ticks_per_half_line();
+ if ticks_per_hl > 0 {
+ gc.vi.half_line_scheduled = true;
+ gc.scheduler.schedule_in(ticks_per_hl, |gc| {
+ gc.vi.on_half_line(gc.scheduler.cycles);
+ gc.vi.half_line_scheduled = false;
+ self::ensure_half_line_scheduled(gc);
+ self::refresh_interrupts(gc);
+ });
}
}
}
-/// Scheduler handler: VI half-line. Reschedules the next half-line and refreshes interrupts.
-pub fn vi_half_line_handler(gc: &mut GameCube) {
- gc.vi.on_half_line(gc.scheduler.cycles);
- gc.vi.half_line_scheduled = false;
- gc.maybe_schedule_vi_half_line();
- gc.check_vi_interrupts();
+#[inline(always)]
+pub fn refresh_interrupts(gc: &mut GameCube) {
+ use crate::flipper::pi::InterruptFlag;
+
+ if gc.vi.vi_interrupt_active() {
+ gc.pi.assert_interrupt(InterruptFlag::Vi);
+ } else {
+ gc.pi.clear_interrupt(InterruptFlag::Vi);
+ }
}
impl GameCube {
@@ -276,8 +273,8 @@ impl GameCube {
let mut pixels = vec![0u32; width * height];
let xfb_addr = self.vi.xfb_addr();
- // XFB is YUY2 (YCbCr 4:2:2): each 32-bit word = [Y0][Cb][Y1][Cr] (big-endian)
- // One word -> two adjacent pixels sharing Cb and Cr.
+ // XFB is YUY2 (YCbCr 4:2:2): each 32 bit word = [Y0][Cb][Y1][Cr] (big endian).
+ // One word covers two adjacent pixels sharing Cb and Cr.
let ycbcr_to_rgb = |y: f32, cb: f32, cr: f32| -> u32 {
let r = (1.164 * y + 1.596 * cr).clamp(0.0, 255.0) as u8;
let g = (1.164 * y - 0.813 * cr - 0.391 * cb).clamp(0.0, 255.0) as u8;
diff --git a/crates/gecko/src/flipper/vi/regs.rs b/crates/gecko/src/flipper/vi/regs.rs
index af2c937..06ebba9 100644
--- a/crates/gecko/src/flipper/vi/regs.rs
+++ b/crates/gecko/src/flipper/vi/regs.rs
@@ -1,17 +1,27 @@
-use super::VideoInterface;
-use crate::mmio::traits::{MmioAccess, MmioRegister};
+use crate::flipper::vi;
+use crate::gamecube::GameCube;
+use crate::mmio::traits::{MmioAccess, MmioRegister, WriteMask};
use chapa::BitEnum;
-// 0xCC002000 2 R/W VTR - Vertical Timing Register
+// 0xCC002000 2 R/W VTR (Vertical Timing Register)
-crate::mmio_register! {
- VerticalTiming: u16 @ 0xCC002000 => VideoInterface.vtr {
- #[bits(0..=3, alias = "equ")] pub equalization_pulse: u8,
- #[bits(4..=13, alias = "acv")] pub active_video: u16,
+#[chapa::bitfield(u16, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct VerticalTiming {
+ #[bits(0..=3, alias = "equ")] pub equalization_pulse: u8,
+ #[bits(4..=13, alias = "acv")] pub active_video: u16,
+}
+crate::mmio_reg!(VerticalTiming: u16 @ 0xCC002000);
+
+impl MmioAccess<GameCube> for VerticalTiming {
+ fn read(gc: &mut GameCube) -> Self { gc.vi.vtr }
+ fn write(self, gc: &mut GameCube, _: WriteMask) {
+ gc.vi.vtr = self;
+ vi::ensure_half_line_scheduled(gc);
}
}
-// 0xCC002002 2 R/W DCR - Display Configuration Register
+// 0xCC002002 2 R/W DCR (Display Configuration Register)
pub enum RefreshRate {
Hz60,
@@ -46,17 +56,18 @@ impl VideoFormat {
}
}
-crate::mmio_register! {
- DisplayConfiguration: u16 @ 0xCC002002 {
- #[bits(0, alias = "enb")] pub enable: bool,
- #[bits(1, alias = "rst")] pub reset: bool,
- #[bits(2, alias = "nin")] pub interlace_selector: bool,
- #[bits(3, alias = "dlr")] pub display_mode_3d: bool,
- #[bits(4..=5, alias = "le0")] pub display_latch0: u8,
- #[bits(6..=7, alias = "le1")] pub display_latch1: u8,
- #[bits(8..=9, alias = "fmt")] pub video_format: VideoFormat,
- }
+#[chapa::bitfield(u16, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct DisplayConfiguration {
+ #[bits(0, alias = "enb")] pub enable: bool,
+ #[bits(1, alias = "rst")] pub reset: bool,
+ #[bits(2, alias = "nin")] pub interlace_selector: bool,
+ #[bits(3, alias = "dlr")] pub display_mode_3d: bool,
+ #[bits(4..=5, alias = "le0")] pub display_latch0: u8,
+ #[bits(6..=7, alias = "le1")] pub display_latch1: u8,
+ #[bits(8..=9, alias = "fmt")] pub video_format: VideoFormat,
}
+crate::mmio_reg!(DisplayConfiguration: u16 @ 0xCC002002);
impl DisplayConfiguration {
pub fn interlaced(&self) -> bool {
@@ -64,333 +75,490 @@ impl DisplayConfiguration {
}
}
-impl MmioAccess<VideoInterface> for DisplayConfiguration {
- fn read(vi: &VideoInterface) -> Self {
- vi.dcr
- }
+impl MmioAccess<GameCube> for DisplayConfiguration {
+ fn read(gc: &mut GameCube) -> Self { gc.vi.dcr }
- fn write(self, vi: &mut VideoInterface) {
- // TODO: Rising-edge on RST clears the register? Just to test for now
- if self.reset() && !vi.dcr.reset() {
- vi.dcr = <DisplayConfiguration as MmioRegister>::from_raw(0);
+ fn write(self, gc: &mut GameCube, _: 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 as MmioRegister>::from_raw(0);
} else {
- vi.dcr = self;
+ gc.vi.dcr = self;
}
+ vi::ensure_half_line_scheduled(gc);
}
}
-// 0xCC002004 4 R/W HTR0 - Horizontal Timing 0
+// 0xCC002004 4 R/W HTR0 (Horizontal Timing 0)
-crate::mmio_register! {
- HorizontalTiming0: u32 @ 0xCC002004 => VideoInterface.htr0 {
- #[bits(0..=8, alias = "hlw")] pub halfline_width: u16,
- #[bits(16..=22, alias = "hce")] pub horizontal_sync_end: u8,
- #[bits(24..=30, alias = "hcs")] pub horizontal_sync_start: u8,
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct HorizontalTiming0 {
+ #[bits(0..=8, alias = "hlw")] pub halfline_width: u16,
+ #[bits(16..=22, alias = "hce")] pub horizontal_sync_end: u8,
+ #[bits(24..=30, alias = "hcs")] pub horizontal_sync_start: u8,
+}
+crate::mmio_reg!(HorizontalTiming0: u32 @ 0xCC002004);
+
+impl MmioAccess<GameCube> for HorizontalTiming0 {
+ fn read(gc: &mut GameCube) -> Self { gc.vi.htr0 }
+ fn write(self, gc: &mut GameCube, _: WriteMask) {
+ gc.vi.htr0 = self;
+ vi::ensure_half_line_scheduled(gc);
}
}
-// 0xCC002008 4 R/W HTR1 - Horizontal Timing 1
+// 0xCC002008 4 R/W HTR1 (Horizontal Timing 1)
-crate::mmio_register! {
- HorizontalTiming1: u32 @ 0xCC002008 => VideoInterface.htr1 {
- #[bits(0..=6, alias = "hsy")] pub horizontal_sync_width: u8,
- #[bits(7..=16, alias = "hbe")] pub horizontal_blank_end: u16,
- #[bits(17..=26, alias = "hbs")] pub horizontal_blank_start: u16,
- }
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct HorizontalTiming1 {
+ #[bits(0..=6, alias = "hsy")] pub horizontal_sync_width: u8,
+ #[bits(7..=16, alias = "hbe")] pub horizontal_blank_end: u16,
+ #[bits(17..=26, alias = "hbs")] pub horizontal_blank_start: u16,
}
+crate::mmio_reg!(HorizontalTiming1: u32 @ 0xCC002008);
+crate::mmio_default_access!(HorizontalTiming1 => GameCube.vi.htr1);
-// 0xCC00200C 4 R/W VTO - Odd Field Vertical Timing Register
+// 0xCC00200C 4 R/W VTO (Odd Field Vertical Timing Register)
-crate::mmio_register! {
- VerticalTimingOdd: u32 @ 0xCC00200C => VideoInterface.vto {
- #[bits(0..=9, alias = "prb")] pub pre_blanking_in_half_lines: u16,
- #[bits(16..=25, alias = "psb")] pub post_blanking_in_half_lines: u16,
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct VerticalTimingOdd {
+ #[bits(0..=9, alias = "prb")] pub pre_blanking_in_half_lines: u16,
+ #[bits(16..=25, alias = "psb")] pub post_blanking_in_half_lines: u16,
+}
+crate::mmio_reg!(VerticalTimingOdd: u32 @ 0xCC00200C);
+
+impl MmioAccess<GameCube> for VerticalTimingOdd {
+ fn read(gc: &mut GameCube) -> Self { gc.vi.vto }
+ fn write(self, gc: &mut GameCube, _: WriteMask) {
+ gc.vi.vto = self;
+ vi::ensure_half_line_scheduled(gc);
}
}
-// 0xCC002010 4 R/W VTE - Even Field Vertical Timing Register
+// 0xCC002010 4 R/W VTE (Even Field Vertical Timing Register)
+
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct VerticalTimingEven {
+ #[bits(0..=9, alias = "prb")] pub pre_blanking_in_half_lines: u16,
+ #[bits(16..=25, alias = "psb")] pub post_blanking_in_half_lines: u16,
+}
+crate::mmio_reg!(VerticalTimingEven: u32 @ 0xCC002010);
-crate::mmio_register! {
- VerticalTimingEven: u32 @ 0xCC002010 => VideoInterface.vte {
- #[bits(0..=9, alias = "prb")] pub pre_blanking_in_half_lines: u16,
- #[bits(16..=25, alias = "psb")] pub post_blanking_in_half_lines: u16,
+impl MmioAccess<GameCube> for VerticalTimingEven {
+ fn read(gc: &mut GameCube) -> Self { gc.vi.vte }
+ fn write(self, gc: &mut GameCube, _: WriteMask) {
+ gc.vi.vte = self;
+ vi::ensure_half_line_scheduled(gc);
}
}
-// 0xCC002014 4 R/W BBEI - Burst Blanking Even Interval
+// 0xCC002014 4 R/W BBEI (Burst Blanking Even Interval)
-crate::mmio_register! {
- BurstBlankingEvenInterval: u32 @ 0xCC002014 => VideoInterface.bbei {
- #[bits(0..=4, alias = "bs1")] pub burst_start_1: u8,
- #[bits(5..=15, alias = "be1")] pub burst_end_1: u16,
- #[bits(16..=20, alias = "bs3")] pub burst_start_3: u8,
- #[bits(21..=31, alias = "be3")] pub burst_end_3: u16,
- }
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct BurstBlankingEvenInterval {
+ #[bits(0..=4, alias = "bs1")] pub burst_start_1: u8,
+ #[bits(5..=15, alias = "be1")] pub burst_end_1: u16,
+ #[bits(16..=20, alias = "bs3")] pub burst_start_3: u8,
+ #[bits(21..=31, alias = "be3")] pub burst_end_3: u16,
}
+crate::mmio_reg!(BurstBlankingEvenInterval: u32 @ 0xCC002014);
+crate::mmio_default_access!(BurstBlankingEvenInterval => GameCube.vi.bbei);
-// 0xCC002018 4 R/W BBOI - Burst Blanking Odd Interval
+// 0xCC002018 4 R/W BBOI (Burst Blanking Odd Interval)
-crate::mmio_register! {
- BurstBlankingOddInterval: u32 @ 0xCC002018 => VideoInterface.bboi {
- #[bits(0..=4, alias = "bs2")] pub burst_start_2: u8,
- #[bits(5..=15, alias = "be2")] pub burst_end_2: u16,
- #[bits(16..=20, alias = "bs4")] pub burst_start_4: u8,
- #[bits(21..=31, alias = "be4")] pub burst_end_4: u16,
- }
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct BurstBlankingOddInterval {
+ #[bits(0..=4, alias = "bs2")] pub burst_start_2: u8,
+ #[bits(5..=15, alias = "be2")] pub burst_end_2: u16,
+ #[bits(16..=20, alias = "bs4")] pub burst_start_4: u8,
+ #[bits(21..=31, alias = "be4")] pub burst_end_4: u16,
}
+crate::mmio_reg!(BurstBlankingOddInterval: u32 @ 0xCC002018);
+crate::mmio_default_access!(BurstBlankingOddInterval => GameCube.vi.bboi);
-// 0xCC00201c 4 R/W TFBL - Top Field Base Register (L) (External Framebuffer Half 1)
+// 0xCC00201c 4 R/W TFBL (Top Field Base Register L, External Framebuffer Half 1)
-crate::mmio_register! {
- TopFieldBase: u32 @ 0xCC00201C => VideoInterface.tfbl {
- #[bits(0..=23, alias = "fbb")]
- pub xfb_addr: u32,
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct TopFieldBase {
+ #[bits(0..=23, alias = "fbb")]
+ pub xfb_addr: u32,
- #[bits(24..=27, alias = "xof")]
- pub horizontal_offset: u8,
+ #[bits(24..=27, alias = "xof")]
+ pub horizontal_offset: u8,
- #[bits(28)]
- pub page_offset: bool,
- // TODO: 29-31 y always zero (maybe some write only control register stuff?, setting bit 31 clears bits 31-28 (?))
- }
+ #[bits(28)]
+ pub page_offset: bool,
+ // 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);
-// 0xCC002020 4 R/W TFBR - Top Field Base Register (R)
+// 0xCC002020 4 R/W TFBR (Top Field Base Register R)
-crate::mmio_register! {
- TopFieldBaseRight: u32 @ 0xCC002020 => VideoInterface.tfbr {
- #[bits(0..=23, alias = "fbb")] pub xfb_addr: u32,
- }
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct TopFieldBaseRight {
+ #[bits(0..=23, alias = "fbb")] pub xfb_addr: u32,
}
+crate::mmio_reg!(TopFieldBaseRight: u32 @ 0xCC002020);
+crate::mmio_default_access!(TopFieldBaseRight => GameCube.vi.tfbr);
-// 0xCC002024 4 R/W BFBL - Bottom Field Base Register (L) (External Framebuffer Half 2)
+// 0xCC002024 4 R/W BFBL (Bottom Field Base Register L, External Framebuffer Half 2)
-crate::mmio_register! {
- BottomFieldBase: u32 @ 0xCC002024 => VideoInterface.bfbl {
- #[bits(0..=23, alias = "fbb")]
- pub xfb_addr: u32,
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct BottomFieldBase {
+ #[bits(0..=23, alias = "fbb")]
+ pub xfb_addr: u32,
- #[bits(28)]
- pub page_offset: bool,
- // TODO: y always zero (maybe some write-only control register stuff?)
- }
+ #[bits(28)]
+ pub page_offset: bool,
}
+crate::mmio_reg!(BottomFieldBase: u32 @ 0xCC002024);
+crate::mmio_default_access!(BottomFieldBase => GameCube.vi.bfbl);
-// 0xCC002028 4 R/W BFBR - Bottom Field Base Register (R)
+// 0xCC002028 4 R/W BFBR (Bottom Field Base Register R)
-crate::mmio_register! {
- BottomFieldBaseRight: u32 @ 0xCC002028 => VideoInterface.bfbr {
- #[bits(0..=23, alias = "fbb")] pub xfb_addr: u32,
- }
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct BottomFieldBaseRight {
+ #[bits(0..=23, alias = "fbb")] pub xfb_addr: u32,
}
+crate::mmio_reg!(BottomFieldBaseRight: u32 @ 0xCC002028);
+crate::mmio_default_access!(BottomFieldBaseRight => GameCube.vi.bfbr);
-// 0xCC00202C 2 R DPV - Display Position Vertical
+// 0xCC00202C 2 R DPV (Display Position Vertical)
-crate::mmio_register! {
- DisplayPositionVertical: u16 @ 0xCC00202C => VideoInterface.dpv {
- #[bits(0..=10, alias = "vct")] pub vertical_count: u16,
- }
+#[chapa::bitfield(u16, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct DisplayPositionVertical {
+ #[bits(0..=10, alias = "vct")] pub vertical_count: u16,
}
+crate::mmio_reg!(DisplayPositionVertical: u16 @ 0xCC00202C);
+crate::mmio_default_access!(DisplayPositionVertical => GameCube.vi.dpv);
-// 0xCC00202E 2 R DPH - Display Position Horizontal
+// 0xCC00202E 2 R DPH (Display Position Horizontal)
+//
+// Read returns a live value computed from the current cycle delta inside the
+// half line. Writes are ignored.
-crate::mmio_register! {
- DisplayPositionHorizontal: u16 @ 0xCC00202E => VideoInterface.dph {
- #[bits(0..=10, alias = "hct")] pub horizontal_count: u16,
- }
+#[chapa::bitfield(u16, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct DisplayPositionHorizontal {
+ #[bits(0..=10, alias = "hct")] pub horizontal_count: u16,
}
+crate::mmio_reg!(DisplayPositionHorizontal: u16 @ 0xCC00202E);
-// 0xCC002030 4 R/W DI0 - Display Interrupt 0
-// THESE ARE NOT RESET ON WRITE 1!!
+impl MmioAccess<GameCube> for DisplayPositionHorizontal {
+ fn read(gc: &mut GameCube) -> Self {
+ let cycles = gc.scheduler.cycles;
+ DisplayPositionHorizontal::from_raw(gc.vi.dph_value(cycles))
+ }
-crate::mmio_register! {
- DisplayInterrupt0: u32 @ 0xCC002030 => VideoInterface.di0 {
- #[bits(0..=9, alias = "hct")] pub horizontal_count: u16,
- #[bits(16..=25, alias = "vct")] pub vertical_count: u16,
- #[bits(28, alias = "enb")] pub enable: bool,
- #[bits(31, alias = "int")] pub interrupt: bool,
+ fn write(self, _gc: &mut GameCube, _: WriteMask) {
+ // Read only.
}
}
-// 0xCC002034 4 R/W DI1 - Display Interrupt 1
+// 0xCC00202C 4 R DPV/DPH combined access slot. Exists to service u32 reads
+// that span both 16 bit position registers; neither one individually fits a
+// u32 access at 0x2C, so we add a dedicated combined slot at u32 width. Writes
+// land here on full u32 stores, which are ignored because both underlying
+// regs are read only.
+
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct DisplayPositionCombined {}
+crate::mmio_reg!(DisplayPositionCombined: u32 @ 0xCC00202C);
+
+impl MmioAccess<GameCube> for DisplayPositionCombined {
+ fn read(gc: &mut GameCube) -> 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)
+ }
-crate::mmio_register! {
- DisplayInterrupt1: u32 @ 0xCC002034 => VideoInterface.di1 {
- #[bits(0..=9, alias = "hct")] pub horizontal_count: u16,
- #[bits(16..=25, alias = "vct")] pub vertical_count: u16,
- #[bits(28, alias = "enb")] pub enable: bool,
- #[bits(31, alias = "int")] pub interrupt: bool,
+ fn write(self, _gc: &mut GameCube, _: WriteMask) {
+ // Read only.
}
}
-// 0xCC002038 4 R/W DI2 - Display Interrupt 2
+// 0xCC002030 4 R/W DI0 (Display Interrupt 0)
+// NOT write 1 to clear. The interrupt bit is a normal R/W flag.
+//
+// DI0..=DI3 each trigger a PI interrupt when their enable + interrupt bits
+// are both set. Writes to these registers must refresh the VI->PI line.
+
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct DisplayInterrupt0 {
+ #[bits(0..=9, alias = "hct")] pub horizontal_count: u16,
+ #[bits(16..=25, alias = "vct")] pub vertical_count: u16,
+ #[bits(28, alias = "enb")] pub enable: bool,
+ #[bits(31, alias = "int")] pub interrupt: bool,
+}
+crate::mmio_reg!(DisplayInterrupt0: u32 @ 0xCC002030);
-crate::mmio_register! {
- DisplayInterrupt2: u32 @ 0xCC002038 => VideoInterface.di2 {
- #[bits(0..=9, alias = "hct")] pub horizontal_count: u16,
- #[bits(16..=25, alias = "vct")] pub vertical_count: u16,
- #[bits(28, alias = "enb")] pub enable: bool,
- #[bits(31, alias = "int")] pub interrupt: bool,
+impl MmioAccess<GameCube> for DisplayInterrupt0 {
+ fn read(gc: &mut GameCube) -> Self { gc.vi.di0 }
+ fn write(self, gc: &mut GameCube, _: WriteMask) {
+ gc.vi.di0 = self;
+ vi::refresh_interrupts(gc);
}
}
-// 0xCC00203C 4 R/W DI3 - Display Interrupt 3
+// 0xCC002034 4 R/W DI1 (Display Interrupt 1)
-crate::mmio_register! {
- DisplayInterrupt3: u32 @ 0xCC00203C => VideoInterface.di3 {
- #[bits(0..=9, alias = "hct")] pub horizontal_count: u16,
- #[bits(16..=25, alias = "vct")] pub vertical_count: u16,
- #[bits(28, alias = "enb")] pub enable: bool,
- #[bits(31, alias = "int")] pub interrupt: bool,
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct DisplayInterrupt1 {
+ #[bits(0..=9, alias = "hct")] pub horizontal_count: u16,
+ #[bits(16..=25, alias = "vct")] pub vertical_count: u16,
+ #[bits(28, alias = "enb")] pub enable: bool,
+ #[bits(31, alias = "int")] pub interrupt: bool,
+}
+crate::mmio_reg!(DisplayInterrupt1: u32 @ 0xCC002034);
+
+impl MmioAccess<GameCube> for DisplayInterrupt1 {
+ fn read(gc: &mut GameCube) -> Self { gc.vi.di1 }
+ fn write(self, gc: &mut GameCube, _: WriteMask) {
+ gc.vi.di1 = self;
+ vi::refresh_interrupts(gc);
}
}
-// 0xCC002040 4 R/W DL0 - Display Latch 0
+// 0xCC002038 4 R/W DI2 (Display Interrupt 2)
+
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct DisplayInterrupt2 {
+ #[bits(0..=9, alias = "hct")] pub horizontal_count: u16,
+ #[bits(16..=25, alias = "vct")] pub vertical_count: u16,
+ #[bits(28, alias = "enb")] pub enable: bool,
+ #[bits(31, alias = "int")] pub interrupt: bool,
+}
+crate::mmio_reg!(DisplayInterrupt2: u32 @ 0xCC002038);
-crate::mmio_register! {
- DisplayLatch0: u32 @ 0xCC002040 => VideoInterface.dl0 {
- #[bits(0..=10, alias = "hct")] pub horizontal_count: u16,
- #[bits(16..=26, alias = "vct")] pub vertical_count: u16,
- #[bits(31, alias = "trg")] pub trigger: bool,
+impl MmioAccess<GameCube> for DisplayInterrupt2 {
+ fn read(gc: &mut GameCube) -> Self { gc.vi.di2 }
+ fn write(self, gc: &mut GameCube, _: WriteMask) {
+ gc.vi.di2 = self;
+ vi::refresh_interrupts(gc);
}
}
-// 0xCC002044 4 R/W DL1 - Display Latch 1
+// 0xCC00203C 4 R/W DI3 (Display Interrupt 3)
-crate::mmio_register! {
- DisplayLatch1: u32 @ 0xCC002044 => VideoInterface.dl1 {
- #[bits(0..=10, alias = "hct")] pub horizontal_count: u16,
- #[bits(16..=26, alias = "vct")] pub vertical_count: u16,
- #[bits(31, alias = "trg")] pub trigger: bool,
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct DisplayInterrupt3 {
+ #[bits(0..=9, alias = "hct")] pub horizontal_count: u16,
+ #[bits(16..=25, alias = "vct")] pub vertical_count: u16,
+ #[bits(28, alias = "enb")] pub enable: bool,
+ #[bits(31, alias = "int")] pub interrupt: bool,
+}
+crate::mmio_reg!(DisplayInterrupt3: u32 @ 0xCC00203C);
+
+impl MmioAccess<GameCube> for DisplayInterrupt3 {
+ fn read(gc: &mut GameCube) -> Self { gc.vi.di3 }
+ fn write(self, gc: &mut GameCube, _: WriteMask) {
+ gc.vi.di3 = self;
+ vi::refresh_interrupts(gc);
}
}
-// 0xCC002048 2 R/W HSW - Horizontal Scaling Width
+// 0xCC002040 4 R/W DL0 (Display Latch 0)
-crate::mmio_register! {
- HorizontalScalingWidth: u16 @ 0xCC002048 => VideoInterface.hsw {
- #[bits(0..=9, alias = "srcwidth")] pub source_width: u16,
- }
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct DisplayLatch0 {
+ #[bits(0..=10, alias = "hct")] pub horizontal_count: u16,
+ #[bits(16..=26, alias = "vct")] pub vertical_count: u16,
+ #[bits(31, alias = "trg")] pub trigger: bool,
}
+crate::mmio_reg!(DisplayLatch0: u32 @ 0xCC002040);
+crate::mmio_default_access!(DisplayLatch0 => GameCube.vi.dl0);
-// 0xCC00204A 2 R/W HSR - Horizontal Scaling Register
+// 0xCC002044 4 R/W DL1 (Display Latch 1)
-crate::mmio_register! {
- HorizontalScalingRegister: u16 @ 0xCC00204A => VideoInterface.hsr {
- #[bits(0..=8, alias = "stp")] pub step_size: u16,
- #[bits(12, alias = "hs_en")] pub horizontal_scaling_enable: bool,
- }
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct DisplayLatch1 {
+ #[bits(0..=10, alias = "hct")] pub horizontal_count: u16,
+ #[bits(16..=26, alias = "vct")] pub vertical_count: u16,
+ #[bits(31, alias = "trg")] pub trigger: bool,
}
+crate::mmio_reg!(DisplayLatch1: u32 @ 0xCC002044);
+crate::mmio_default_access!(DisplayLatch1 => GameCube.vi.dl1);
-// 0xCC00204C 4 R/W FCT0 - Filter Coefficient Table 0
+// 0xCC002048 2 R/W HSW (Horizontal Scaling Width)
-crate::mmio_register! {
- FilterCoefficient0: u32 @ 0xCC00204C => VideoInterface.fct0 {
- #[bits(0..=9, alias = "t0")] pub tap0: u16,
- #[bits(10..=19, alias = "t1")] pub tap1: u16,
- #[bits(20..=29, alias = "t2")] pub tap2: u16,
- }
+#[chapa::bitfield(u16, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct HorizontalScalingWidth {
+ #[bits(0..=9, alias = "srcwidth")] pub source_width: u16,
}
+crate::mmio_reg!(HorizontalScalingWidth: u16 @ 0xCC002048);
+crate::mmio_default_access!(HorizontalScalingWidth => GameCube.vi.hsw);
-// 0xCC002050 4 R/W FCT1 - Filter Coefficient Table 1
+// 0xCC00204A 2 R/W HSR (Horizontal Scaling Register)
-crate::mmio_register! {
- FilterCoefficient1: u32 @ 0xCC002050 => VideoInterface.fct1 {
- #[bits(0..=9, alias = "t3")] pub tap3: u16,
- #[bits(10..=19, alias = "t4")] pub tap4: u16,
- #[bits(20..=29, alias = "t5")] pub tap5: u16,
- }
+#[chapa::bitfield(u16, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct HorizontalScalingRegister {
+ #[bits(0..=8, alias = "stp")] pub step_size: u16,
+ #[bits(12, alias = "hs_en")] pub horizontal_scaling_enable: bool,
}
+crate::mmio_reg!(HorizontalScalingRegister: u16 @ 0xCC00204A);
+crate::mmio_default_access!(HorizontalScalingRegister => GameCube.vi.hsr);
-// 0xCC002054 4 R/W FCT2 - Filter Coefficient Table 2
+// 0xCC00204C 4 R/W FCT0 (Filter Coefficient Table 0)
-crate::mmio_register! {
- FilterCoefficient2: u32 @ 0xCC002054 => VideoInterface.fct2 {
- #[bits(0..=9, alias = "t6")] pub tap6: u16,
- #[bits(10..=19, alias = "t7")] pub tap7: u16,
- #[bits(20..=29, alias = "t8")] pub tap8: u16,
- }
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct FilterCoefficient0 {
+ #[bits(0..=9, alias = "t0")] pub tap0: u16,
+ #[bits(10..=19, alias = "t1")] pub tap1: u16,
+ #[bits(20..=29, alias = "t2")] pub tap2: u16,
}
+crate::mmio_reg!(FilterCoefficient0: u32 @ 0xCC00204C);
+crate::mmio_default_access!(FilterCoefficient0 => GameCube.vi.fct0);
-// 0xCC002058 4 R/W FCT3 - Filter Coefficient Table 3
+// 0xCC002050 4 R/W FCT1 (Filter Coefficient Table 1)
-crate::mmio_register! {
- FilterCoefficient3: u32 @ 0xCC002058 => VideoInterface.fct3 {
- #[bits(0..=7, alias = "t9")] pub tap9: u8,
- #[bits(8..=15, alias = "t10")] pub tap10: u8,
- #[bits(16..=23, alias = "t11")] pub tap11: u8,
- #[bits(24..=31, alias = "t12")] pub tap12: u8,
- }
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct FilterCoefficient1 {
+ #[bits(0..=9, alias = "t3")] pub tap3: u16,
+ #[bits(10..=19, alias = "t4")] pub tap4: u16,
+ #[bits(20..=29, alias = "t5")] pub tap5: u16,
}
+crate::mmio_reg!(FilterCoefficient1: u32 @ 0xCC002050);
+crate::mmio_default_access!(FilterCoefficient1 => GameCube.vi.fct1);
-// 0xCC00205C 4 R/W FCT4 - Filter Coefficient Table 4
+// 0xCC002054 4 R/W FCT2 (Filter Coefficient Table 2)
-crate::mmio_register! {
- FilterCoefficient4: u32 @ 0xCC00205C => VideoInterface.fct4 {
- #[bits(0..=7, alias = "t13")] pub tap13: u8,
- #[bits(8..=15, alias = "t14")] pub tap14: u8,
- #[bits(16..=23, alias = "t15")] pub tap15: u8,
- #[bits(24..=31, alias = "t16")] pub tap16: u8,
- }
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct FilterCoefficient2 {
+ #[bits(0..=9, alias = "t6")] pub tap6: u16,
+ #[bits(10..=19, alias = "t7")] pub tap7: u16,
+ #[bits(20..=29, alias = "t8")] pub tap8: u16,
}
+crate::mmio_reg!(FilterCoefficient2: u32 @ 0xCC002054);
+crate::mmio_default_access!(FilterCoefficient2 => GameCube.vi.fct2);
-// 0xCC002060 4 R/W FCT5 - Filter Coefficient Table 5
+// 0xCC002058 4 R/W FCT3 (Filter Coefficient Table 3)
-crate::mmio_register! {
- FilterCoefficient5: u32 @ 0xCC002060 => VideoInterface.fct5 {
- #[bits(0..=7, alias = "t17")] pub tap17: u8,
- #[bits(8..=15, alias = "t18")] pub tap18: u8,
- #[bits(16..=23, alias = "t19")] pub tap19: u8,
- #[bits(24..=31, alias = "t20")] pub tap20: u8,
- }
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct FilterCoefficient3 {
+ #[bits(0..=7, alias = "t9")] pub tap9: u8,
+ #[bits(8..=15, alias = "t10")] pub tap10: u8,
+ #[bits(16..=23, alias = "t11")] pub tap11: u8,
+ #[bits(24..=31, alias = "t12")] pub tap12: u8,
}
+crate::mmio_reg!(FilterCoefficient3: u32 @ 0xCC002058);
+crate::mmio_default_access!(FilterCoefficient3 => GameCube.vi.fct3);
-// 0xCC002064 4 R/W FCT6 - Filter Coefficient Table 6
+// 0xCC00205C 4 R/W FCT4 (Filter Coefficient Table 4)
-crate::mmio_register! {
- FilterCoefficient6: u32 @ 0xCC002064 => VideoInterface.fct6 {
- #[bits(0..=7, alias = "t21")] pub tap21: u8,
- #[bits(8..=15, alias = "t22")] pub tap22: u8,
- #[bits(16..=23, alias = "t23")] pub tap23: u8,
- #[bits(24..=31, alias = "t24")] pub tap24: u8,
- }
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct FilterCoefficient4 {
+ #[bits(0..=7, alias = "t13")] pub tap13: u8,
+ #[bits(8..=15, alias = "t14")] pub tap14: u8,
+ #[bits(16..=23, alias = "t15")] pub tap15: u8,
+ #[bits(24..=31, alias = "t16")] pub tap16: u8,
}
+crate::mmio_reg!(FilterCoefficient4: u32 @ 0xCC00205C);
+crate::mmio_default_access!(FilterCoefficient4 => GameCube.vi.fct4);
-// 0xCC00206C 2 R/W VICLK - VI Clock Select
+// 0xCC002060 4 R/W FCT5 (Filter Coefficient Table 5)
-crate::mmio_register! {
- ViClockSelect: u16 @ 0xCC00206C => VideoInterface.viclk {
- #[bits(0, alias = "clk")] pub clock_select: bool,
- }
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct FilterCoefficient5 {
+ #[bits(0..=7, alias = "t17")] pub tap17: u8,
+ #[bits(8..=15, alias = "t18")] pub tap18: u8,
+ #[bits(16..=23, alias = "t19")] pub tap19: u8,
+ #[bits(24..=31, alias = "t20")] pub tap20: u8,
+}
+crate::mmio_reg!(FilterCoefficient5: u32 @ 0xCC002060);
+crate::mmio_default_access!(FilterCoefficient5 => GameCube.vi.fct5);
+
+// 0xCC002064 4 R/W FCT6 (Filter Coefficient Table 6)
+
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct FilterCoefficient6 {
+ #[bits(0..=7, alias = "t21")] pub tap21: u8,
+ #[bits(8..=15, alias = "t22")] pub tap22: u8,
+ #[bits(16..=23, alias = "t23")] pub tap23: u8,
+ #[bits(24..=31, alias = "t24")] pub tap24: u8,
}
+crate::mmio_reg!(FilterCoefficient6: u32 @ 0xCC002064);
+crate::mmio_default_access!(FilterCoefficient6 => GameCube.vi.fct6);
-// 0xCC00206E 2 R/W VISEL - VI DTV Status
+// 0xCC00206C 2 R/W VICLK (VI Clock Select)
-crate::mmio_register! {
- ViDtvStatus: u16 @ 0xCC00206E => VideoInterface.visel {
- #[bits(2, alias = "visel")] pub dtv_status: bool,
+#[chapa::bitfield(u16, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct ViClockSelect {
+ #[bits(0, alias = "clk")] pub clock_select: bool,
+}
+crate::mmio_reg!(ViClockSelect: u16 @ 0xCC00206C);
+
+impl MmioAccess<GameCube> for ViClockSelect {
+ fn read(gc: &mut GameCube) -> Self { gc.vi.viclk }
+ fn write(self, gc: &mut GameCube, _: WriteMask) {
+ gc.vi.viclk = self;
+ vi::ensure_half_line_scheduled(gc);
}
}
-// 0xCC002070 2 R/W God knows what this is, log for now
+// 0xCC00206E 2 R/W VISEL (VI DTV Status)
-crate::mmio_register! {
- ViUnknown70: u16 @ 0xCC002070 => VideoInterface.unknown_70 {}
+#[chapa::bitfield(u16, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct ViDtvStatus {
+ #[bits(2, alias = "visel")] pub dtv_status: bool,
}
+crate::mmio_reg!(ViDtvStatus: u16 @ 0xCC00206E);
+crate::mmio_default_access!(ViDtvStatus => GameCube.vi.visel);
-// 0xCC002072 2 R/W BorderHBE - Border HBE
+// 0xCC002070 2 R/W Unknown. Log for now.
-crate::mmio_register! {
- BorderHbe: u16 @ 0xCC002072 => VideoInterface.border_hbe {
- #[bits(0..=9, alias = "hbe656")] pub horizontal_blank_end_656: u16,
- #[bits(15, alias = "brdr_en")] pub border_enable: bool,
- }
+#[chapa::bitfield(u16, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct ViUnknown70 {}
+crate::mmio_reg!(ViUnknown70: u16 @ 0xCC002070);
+crate::mmio_default_access!(ViUnknown70 => GameCube.vi.unknown_70);
+
+// 0xCC002072 2 R/W BorderHBE (Border HBE)
+
+#[chapa::bitfield(u16, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct BorderHbe {
+ #[bits(0..=9, alias = "hbe656")] pub horizontal_blank_end_656: u16,
+ #[bits(15, alias = "brdr_en")] pub border_enable: bool,
}
+crate::mmio_reg!(BorderHbe: u16 @ 0xCC002072);
+crate::mmio_default_access!(BorderHbe => GameCube.vi.border_hbe);
-// 0xCC002074 2 R/W BorderHBS - Border HBS
+// 0xCC002074 2 R/W BorderHBS (Border HBS)
-crate::mmio_register! {
- BorderHbs: u16 @ 0xCC002074 => VideoInterface.border_hbs {
- #[bits(0..=9, alias = "hbs656")] pub horizontal_blank_start_656: u16,
- }
+#[chapa::bitfield(u16, order = lsb0)]
+#[derive(Copy, Clone, Debug)]
+pub struct BorderHbs {
+ #[bits(0..=9, alias = "hbs656")] pub horizontal_blank_start_656: u16,
}
+crate::mmio_reg!(BorderHbs: u16 @ 0xCC002074);
+crate::mmio_default_access!(BorderHbs => GameCube.vi.border_hbs);
diff --git a/crates/gecko/src/mmio.rs b/crates/gecko/src/mmio.rs
index 2218cec..3ae732a 100644
--- a/crates/gecko/src/mmio.rs
+++ b/crates/gecko/src/mmio.rs
@@ -4,7 +4,6 @@ pub mod fp;
pub mod macros;
pub mod traits;
-pub use traits::MmioRw;
use constants::*;
diff --git a/crates/gecko/src/mmio/bus.rs b/crates/gecko/src/mmio/bus.rs
index dc28cfc..3dcd189 100644
--- a/crates/gecko/src/mmio/bus.rs
+++ b/crates/gecko/src/mmio/bus.rs
@@ -1,48 +1,11 @@
use crate::gamecube::GameCube;
#[cfg(feature = "hooks")]
use crate::hooks::HookFlags;
-use crate::mmio::MmioRw;
use crate::mmio::constants::{
AI_BASE, AI_END, CP_BASE, CP_END, DI_BASE, DI_END, DSP_BASE, DSP_END, EXI_BASE, EXI_END, GX_FIFO_BASE, GX_FIFO_END,
- IPL_BASE, IPL_END, MI_BASE, MI_END, PE_BASE, PE_END, PI_BASE, PI_END, RAM_END, SI_BASE, SI_END, VI_BASE, VI_END,
+ MI_BASE, MI_END, PE_BASE, PE_END, PI_BASE, PI_END, RAM_END, SI_BASE, SI_END, VI_BASE, VI_END,
};
-enum BusTarget {
- Cp,
- Vi,
- Pe,
- Pi,
- Mi,
- Dsp,
- Di,
- Si,
- Exi,
- Ai,
- Gx,
- Ipl,
- Fallback,
-}
-
-#[rustfmt::skip]
-#[inline(always)]
-fn route_mmio(phys: u32) -> (BusTarget, u32) {
- match phys {
- CP_BASE..=CP_END => (BusTarget::Cp, phys - CP_BASE),
- PE_BASE..=PE_END => (BusTarget::Pe, phys - PE_BASE),
- VI_BASE..=VI_END => (BusTarget::Vi, phys - VI_BASE),
- PI_BASE..=PI_END => (BusTarget::Pi, phys - PI_BASE),
- MI_BASE..=MI_END => (BusTarget::Mi, phys - MI_BASE),
- DSP_BASE..=DSP_END => (BusTarget::Dsp, phys - DSP_BASE),
- DI_BASE..=DI_END => (BusTarget::Di, phys - DI_BASE),
- SI_BASE..=SI_END => (BusTarget::Si, phys - SI_BASE),
- EXI_BASE..=EXI_END => (BusTarget::Exi, phys - EXI_BASE),
- AI_BASE..=AI_END => (BusTarget::Ai, phys - AI_BASE),
- IPL_BASE..=IPL_END => (BusTarget::Ipl, phys),
- GX_FIFO_BASE..=GX_FIFO_END => (BusTarget::Gx, phys - GX_FIFO_BASE),
- _ => (BusTarget::Fallback, phys),
- }
-}
-
macro_rules! bus_read_hooks {
($self:ident, $addr:ident, $phys:ident, $size:literal, $body:expr) => {{
#[cfg(feature = "hooks")]
@@ -233,126 +196,103 @@ impl GameCube {
// Slow path for MMIO
- #[rustfmt::skip]
#[inline(never)]
fn read_u8_mmio(&mut self, phys: u32, addr: u32) -> u8 {
- let (target, offset) = route_mmio(phys);
- match target {
- BusTarget::Cp => self.cp.mmio_read_u8(offset),
- BusTarget::Vi => {
- if offset == 0x2E {
- return (self.vi.dph_value(self.scheduler.cycles) >> 8) as u8;
- }
- if offset == 0x2F {
- return self.vi.dph_value(self.scheduler.cycles) as u8;
- }
- self.vi.mmio_read_u8(offset)
- }
- BusTarget::Pe => self.pe.mmio_read_u8(offset),
- BusTarget::Pi => self.pi.mmio_read_u8(offset),
- BusTarget::Mi => self.mi.mmio_read_u8(offset),
- BusTarget::Dsp => crate::flipper::dsp::dsp_read(self, phys, 1).unwrap_or(0) as u8,
- BusTarget::Di => crate::dvd::di_read(self, phys, 1).unwrap_or(0) as u8,
- BusTarget::Si => crate::flipper::si::si_read(self, phys, 1).unwrap_or(0) as u8,
- BusTarget::Exi => crate::flipper::exi::exi_read(self, phys, 1).unwrap_or(0) as u8,
- BusTarget::Ai => crate::flipper::ai::ai_read(self, phys, 1).unwrap_or(0) as u8,
- BusTarget::Gx => {
+ match phys {
+ CP_BASE..=CP_END => crate::flipper::cp::cp_read(self, phys, 1).unwrap_or(0) as u8,
+ PE_BASE..=PE_END => crate::flipper::pe::pe_read(self, phys, 1).unwrap_or(0) as u8,
+ VI_BASE..=VI_END => crate::flipper::vi::vi_read(self, phys, 1).unwrap_or(0) as u8,
+ PI_BASE..=PI_END => crate::flipper::pi::pi_read(self, phys, 1).unwrap_or(0) as u8,
+ MI_BASE..=MI_END => crate::flipper::mi::mi_read(self, phys, 1).unwrap_or(0) as u8,
+ DSP_BASE..=DSP_END => crate::flipper::dsp::dsp_read(self, phys, 1).unwrap_or(0) as u8,
+ DI_BASE..=DI_END => crate::dvd::di_read(self, phys, 1).unwrap_or(0) as u8,
+ SI_BASE..=SI_END => crate::flipper::si::si_read(self, phys, 1).unwrap_or(0) as u8,
+ EXI_BASE..=EXI_END => crate::flipper::exi::exi_read(self, phys, 1).unwrap_or(0) as u8,
+ AI_BASE..=AI_END => crate::flipper::ai::ai_read(self, phys, 1).unwrap_or(0) as u8,
+ GX_FIFO_BASE..=GX_FIFO_END => {
tracing::error!(addr = format!("{:08X}", addr), "Invalid GX FIFO read");
0
}
- BusTarget::Ipl => self.mmio.phys_read_u8(phys),
- BusTarget::Fallback => self.mmio.phys_read_u8(phys),
+ _ => self.mmio.phys_read_u8(phys),
}
}
- #[rustfmt::skip]
#[inline(never)]
fn read_u16_mmio(&mut self, phys: u32, addr: u32) -> u16 {
- let (target, offset) = route_mmio(phys);
- match target {
- BusTarget::Cp => self.cp.mmio_read_u16(offset),
- BusTarget::Vi => {
- if offset == 0x2E {
- return self.vi.dph_value(self.scheduler.cycles);
- }
- self.vi.mmio_read_u16(offset)
- }
- BusTarget::Pe => self.pe.mmio_read_u16(offset),
- BusTarget::Pi => self.pi.mmio_read_u16(offset),
- BusTarget::Mi => self.mi.mmio_read_u16(offset),
- BusTarget::Dsp => crate::flipper::dsp::dsp_read(self, phys, 2).unwrap_or(0) as u16,
- BusTarget::Di => crate::dvd::di_read(self, phys, 2).unwrap_or(0) as u16,
- BusTarget::Si => crate::flipper::si::si_read(self, phys, 2).unwrap_or(0) as u16,
- BusTarget::Exi => crate::flipper::exi::exi_read(self, phys, 2).unwrap_or(0) as u16,
- BusTarget::Ai => crate::flipper::ai::ai_read(self, phys, 2).unwrap_or(0) as u16,
- BusTarget::Gx => {
+ match phys {
+ CP_BASE..=CP_END => crate::flipper::cp::cp_read(self, phys, 2).unwrap_or(0) as u16,
+ PE_BASE..=PE_END => crate::flipper::pe::pe_read(self, phys, 2).unwrap_or(0) as u16,
+ VI_BASE..=VI_END => crate::flipper::vi::vi_read(self, phys, 2).unwrap_or(0) as u16,
+ PI_BASE..=PI_END => crate::flipper::pi::pi_read(self, phys, 2).unwrap_or(0) as u16,
+ MI_BASE..=MI_END => crate::flipper::mi::mi_read(self, phys, 2).unwrap_or(0) as u16,
+ DSP_BASE..=DSP_END => crate::flipper::dsp::dsp_read(self, phys, 2).unwrap_or(0) as u16,
+ DI_BASE..=DI_END => crate::dvd::di_read(self, phys, 2).unwrap_or(0) as u16,
+ SI_BASE..=SI_END => crate::flipper::si::si_read(self, phys, 2).unwrap_or(0) as u16,
+ EXI_BASE..=EXI_END => crate::flipper::exi::exi_read(self, phys, 2).unwrap_or(0) as u16,
+ AI_BASE..=AI_END => crate::flipper::ai::ai_read(self, phys, 2).unwrap_or(0) as u16,
+ GX_FIFO_BASE..=GX_FIFO_END => {
tracing::error!(addr = format!("{:08X}", addr), "Invalid GX FIFO read");
0
}
- BusTarget::Ipl => self.mmio.phys_read_u16(phys),
- BusTarget::Fallback => self.mmio.phys_read_u16(phys),
+ _ => self.mmio.phys_read_u16(phys),
}
}
- #[rustfmt::skip]
#[inline(never)]
fn read_u32_mmio(&mut self, phys: u32, addr: u32) -> u32 {
- let (target, offset) = route_mmio(phys);
- match target {
- BusTarget::Cp => self.cp.mmio_read_u32(offset),
- BusTarget::Vi => {
- if offset == 0x2C {
- let dpv = self.vi.mmio_read_u16(0x2C) as u32;
- let dph = self.vi.dph_value(self.scheduler.cycles) as u32;
- return (dpv << 16) | dph;
- }
- self.vi.mmio_read_u32(offset)
- }
- BusTarget::Pe => self.pe.mmio_read_u32(offset),
- BusTarget::Pi => self.pi.mmio_read_u32(offset),
- BusTarget::Mi => self.mi.mmio_read_u32(offset),
- BusTarget::Dsp => crate::flipper::dsp::dsp_read(self, phys, 4).unwrap_or(0),
- BusTarget::Di => crate::dvd::di_read(self, phys, 4).unwrap_or(0),
- BusTarget::Si => crate::flipper::si::si_read(self, phys, 4).unwrap_or(0),
- BusTarget::Exi => crate::flipper::exi::exi_read(self, phys, 4).unwrap_or(0),
- BusTarget::Ai => crate::flipper::ai::ai_read(self, phys, 4).unwrap_or(0),
- BusTarget::Gx => {
+ match phys {
+ CP_BASE..=CP_END => crate::flipper::cp::cp_read(self, phys, 4).unwrap_or(0),
+ PE_BASE..=PE_END => crate::flipper::pe::pe_read(self, phys, 4).unwrap_or(0),
+ VI_BASE..=VI_END => crate::flipper::vi::vi_read(self, phys, 4).unwrap_or(0),
+ PI_BASE..=PI_END => crate::flipper::pi::pi_read(self, phys, 4).unwrap_or(0),
+ MI_BASE..=MI_END => crate::flipper::mi::mi_read(self, phys, 4).unwrap_or(0),
+ DSP_BASE..=DSP_END => crate::flipper::dsp::dsp_read(self, phys, 4).unwrap_or(0),
+ DI_BASE..=DI_END => crate::dvd::di_read(self, phys, 4).unwrap_or(0),
+ SI_BASE..=SI_END => crate::flipper::si::si_read(self, phys, 4).unwrap_or(0),
+ EXI_BASE..=EXI_END => crate::flipper::exi::exi_read(self, phys, 4).unwrap_or(0),
+ AI_BASE..=AI_END => crate::flipper::ai::ai_read(self, phys, 4).unwrap_or(0),
+ GX_FIFO_BASE..=GX_FIFO_END => {
tracing::error!(addr = format!("{:08X}", addr), "Invalid GX FIFO read");
0
}
- BusTarget::Ipl => self.mmio.phys_read_u32(phys),
- BusTarget::Fallback => self.mmio.phys_read_u32(phys),
+ _ => self.mmio.phys_read_u32(phys),
}
}
- #[rustfmt::skip]
#[inline(never)]
fn write_u8_mmio(&mut self, phys: u32, val: u8) {
- let (target, offset) = route_mmio(phys);
- match target {
- BusTarget::Cp => {
- self.cp.mmio_write_u8(offset, val);
- self.check_cp_interrupts();
- }
- BusTarget::Vi => {
- self.vi.mmio_write_u8(offset, val);
- self.maybe_schedule_vi_half_line();
- if (0x30..=0x3F).contains(&offset) {
- self.check_vi_interrupts();
- }
+ match phys {
+ CP_BASE..=CP_END => {
+ crate::flipper::cp::cp_write(self, phys, 1, val as u32);
}
- BusTarget::Pe => {
- self.pe.mmio_write_u8(offset, val);
- self.check_pe_interrupts();
- }
- BusTarget::Pi => self.pi.mmio_write_u8(offset, val),
- BusTarget::Mi => self.mi.mmio_write_u8(offset, val),
- BusTarget::Dsp => { crate::flipper::dsp::dsp_write(self, phys, 1, val as u32); }
- BusTarget::Di => { crate::dvd::di_write(self, phys, 1, val as u32); }
- BusTarget::Si => { crate::flipper::si::si_write(self, phys, 1, val as u32); }
- BusTarget::Exi => { crate::flipper::exi::exi_write(self, phys, 1, val as u32); }
- BusTarget::Ai => { crate::flipper::ai::ai_write(self, phys, 1, val as u32); }
- BusTarget::Gx => {
+ PE_BASE..=PE_END => {
+ crate::flipper::pe::pe_write(self, phys, 1, val as u32);
+ }
+ VI_BASE..=VI_END => {
+ crate::flipper::vi::vi_write(self, phys, 1, val as u32);
+ }
+ PI_BASE..=PI_END => {
+ crate::flipper::pi::pi_write(self, phys, 1, val as u32);
+ }
+ MI_BASE..=MI_END => {
+ crate::flipper::mi::mi_write(self, phys, 1, val as u32);
+ }
+ DSP_BASE..=DSP_END => {
+ crate::flipper::dsp::dsp_write(self, phys, 1, val as u32);
+ }
+ DI_BASE..=DI_END => {
+ crate::dvd::di_write(self, phys, 1, val as u32);
+ }
+ SI_BASE..=SI_END => {
+ crate::flipper::si::si_write(self, phys, 1, val as u32);
+ }
+ EXI_BASE..=EXI_END => {
+ crate::flipper::exi::exi_write(self, phys, 1, val as u32);
+ }
+ AI_BASE..=AI_END => {
+ crate::flipper::ai::ai_write(self, phys, 1, val as u32);
+ }
+ GX_FIFO_BASE..=GX_FIFO_END => {
let wptr = self.pi.fifo_wptr as usize;
self.mmio.ram[wptr] = val;
self.pi.advance_fifo_wptr(1);
@@ -361,39 +301,44 @@ impl GameCube {
self.check_gx_pe_interrupts();
}
}
- BusTarget::Ipl => self.mmio.phys_write_u8(phys, val),
- BusTarget::Fallback => self.mmio.phys_write_u8(phys, val),
+ _ => self.mmio.phys_write_u8(phys, val),
}
}
- #[rustfmt::skip]
#[inline(never)]
fn write_u16_mmio(&mut self, phys: u32, val: u16) {
- let (target, offset) = route_mmio(phys);
- match target {
- BusTarget::Cp => {
- self.cp.mmio_write_u16(offset, val);
- self.check_cp_interrupts();
- }
- BusTarget::Vi => {
- self.vi.mmio_write_u16(offset, val);
- self.maybe_schedule_vi_half_line();
- if (0x30..=0x3F).contains(&offset) {
- self.check_vi_interrupts();
- }
+ match phys {
+ CP_BASE..=CP_END => {
+ crate::flipper::cp::cp_write(self, phys, 2, val as u32);
}
- BusTarget::Pe => {
- self.pe.mmio_write_u16(offset, val);
- self.check_pe_interrupts();
- }
- BusTarget::Pi => self.pi.mmio_write_u16(offset, val),
- BusTarget::Mi => self.mi.mmio_write_u16(offset, val),
- BusTarget::Dsp => { crate::flipper::dsp::dsp_write(self, phys, 2, val as u32); }
- BusTarget::Di => { crate::dvd::di_write(self, phys, 2, val as u32); }
- BusTarget::Si => { crate::flipper::si::si_write(self, phys, 2, val as u32); }
- BusTarget::Exi => { crate::flipper::exi::exi_write(self, phys, 2, val as u32); }
- BusTarget::Ai => { crate::flipper::ai::ai_write(self, phys, 2, val as u32); }
- BusTarget::Gx => {
+ PE_BASE..=PE_END => {
+ crate::flipper::pe::pe_write(self, phys, 2, val as u32);
+ }
+ VI_BASE..=VI_END => {
+ crate::flipper::vi::vi_write(self, phys, 2, val as u32);
+ }
+ PI_BASE..=PI_END => {
+ crate::flipper::pi::pi_write(self, phys, 2, val as u32);
+ }
+ MI_BASE..=MI_END => {
+ crate::flipper::mi::mi_write(self, phys, 2, val as u32);
+ }
+ DSP_BASE..=DSP_END => {
+ crate::flipper::dsp::dsp_write(self, phys, 2, val as u32);
+ }
+ DI_BASE..=DI_END => {
+ crate::dvd::di_write(self, phys, 2, val as u32);
+ }
+ SI_BASE..=SI_END => {
+ crate::flipper::si::si_write(self, phys, 2, val as u32);
+ }
+ EXI_BASE..=EXI_END => {
+ crate::flipper::exi::exi_write(self, phys, 2, val as u32);
+ }
+ AI_BASE..=AI_END => {
+ crate::flipper::ai::ai_write(self, phys, 2, val as u32);
+ }
+ GX_FIFO_BASE..=GX_FIFO_END => {
let wptr = self.pi.fifo_wptr as usize;
let bytes = val.to_be_bytes();
self.mmio.ram[wptr..wptr + 2].copy_from_slice(&bytes);
@@ -403,39 +348,44 @@ impl GameCube {
self.check_gx_pe_interrupts();
}
}
- BusTarget::Ipl => self.mmio.phys_write_u16(phys, val),
- BusTarget::Fallback => self.mmio.phys_write_u16(phys, val),
+ _ => self.mmio.phys_write_u16(phys, val),
}
}
- #[rustfmt::skip]
#[inline(never)]
fn write_u32_mmio(&mut self, phys: u32, val: u32) {
- let (target, offset) = route_mmio(phys);
- match target {
- BusTarget::Cp => {
- self.cp.mmio_write_u32(offset, val);
- self.check_cp_interrupts();
- }
- BusTarget::Vi => {
- self.vi.mmio_write_u32(offset, val);
- self.maybe_schedule_vi_half_line();
- if (0x30..=0x3F).contains(&offset) {
- self.check_vi_interrupts();
- }
+ match phys {
+ CP_BASE..=CP_END => {
+ crate::flipper::cp::cp_write(self, phys, 4, val);
+ }
+ PE_BASE..=PE_END => {
+ crate::flipper::pe::pe_write(self, phys, 4, val);
+ }
+ VI_BASE..=VI_END => {
+ crate::flipper::vi::vi_write(self, phys, 4, val);
+ }
+ PI_BASE..=PI_END => {
+ crate::flipper::pi::pi_write(self, phys, 4, val);
+ }
+ MI_BASE..=MI_END => {
+ crate::flipper::mi::mi_write(self, phys, 4, val);
+ }
+ DSP_BASE..=DSP_END => {
+ crate::flipper::dsp::dsp_write(self, phys, 4, val);
+ }
+ DI_BASE..=DI_END => {
+ crate::dvd::di_write(self, phys, 4, val);
+ }
+ SI_BASE..=SI_END => {
+ crate::flipper::si::si_write(self, phys, 4, val);
+ }
+ EXI_BASE..=EXI_END => {
+ crate::flipper::exi::exi_write(self, phys, 4, val);
+ }
+ AI_BASE..=AI_END => {
+ crate::flipper::ai::ai_write(self, phys, 4, val);
}
- BusTarget::Pe => {
- self.pe.mmio_write_u32(offset, val);
- self.check_pe_interrupts();
- }
- BusTarget::Pi => self.pi.mmio_write_u32(offset, val),
- BusTarget::Mi => self.mi.mmio_write_u32(offset, val),
- BusTarget::Dsp => { crate::flipper::dsp::dsp_write(self, phys, 4, val); }
- BusTarget::Di => { crate::dvd::di_write(self, phys, 4, val); }
- BusTarget::Si => { crate::flipper::si::si_write(self, phys, 4, val); }
- BusTarget::Exi => { crate::flipper::exi::exi_write(self, phys, 4, val); }
- BusTarget::Ai => { crate::flipper::ai::ai_write(self, phys, 4, val); }
- BusTarget::Gx => {
+ GX_FIFO_BASE..=GX_FIFO_END => {
let wptr = self.pi.fifo_wptr as usize;
let bytes = val.to_be_bytes();
self.mmio.ram[wptr..wptr + 4].copy_from_slice(&bytes);
@@ -445,8 +395,7 @@ impl GameCube {
self.check_gx_pe_interrupts();
}
}
- BusTarget::Ipl => self.mmio.phys_write_u32(phys, val),
- BusTarget::Fallback => self.mmio.phys_write_u32(phys, val),
+ _ => self.mmio.phys_write_u32(phys, val),
}
}
}
diff --git a/crates/gecko/src/mmio/macros.rs b/crates/gecko/src/mmio/macros.rs
index f298814..f53f525 100644
--- a/crates/gecko/src/mmio/macros.rs
+++ b/crates/gecko/src/mmio/macros.rs
@@ -5,7 +5,7 @@ macro_rules! mmio_device_dispatch {
write = $write_fn:ident,
registers = [ $($reg:ty),* $(,)? ] $(,)?
) => {
- #[inline]
+ #[inline(always)]
pub fn $read_fn(
gc: &mut $crate::gamecube::GameCube,
addr: u32,
@@ -14,7 +14,7 @@ macro_rules! mmio_device_dispatch {
$(
if <$reg as $crate::mmio::traits::MmioRegister>::fits(addr, size) {
return Some(
- <$reg as $crate::mmio::traits::MmioHandler<$crate::gamecube::GameCube>>
+ <$reg as $crate::mmio::traits::MmioAccess<$crate::gamecube::GameCube>>
::read_at(gc, addr, size),
);
}
@@ -22,7 +22,7 @@ macro_rules! mmio_device_dispatch {
None
}
- #[inline]
+ #[inline(always)]
pub fn $write_fn(
gc: &mut $crate::gamecube::GameCube,
addr: u32,
@@ -38,7 +38,7 @@ macro_rules! mmio_device_dispatch {
size,
"MMIO write"
);
- <$reg as $crate::mmio::traits::MmioHandler<$crate::gamecube::GameCube>>
+ <$reg as $crate::mmio::traits::MmioAccess<$crate::gamecube::GameCube>>
::write_at(gc, addr, size, val);
return true;
}
@@ -69,7 +69,7 @@ macro_rules! mmio_reg {
#[macro_export]
macro_rules! mmio_default_access {
($reg:ty => GameCube . $($field:ident).+) => {
- impl $crate::mmio::traits::MmioHandler<$crate::gamecube::GameCube> for $reg {
+ impl $crate::mmio::traits::MmioAccess<$crate::gamecube::GameCube> for $reg {
#[inline(always)]
fn read(gc: &mut $crate::gamecube::GameCube) -> Self {
gc . $($field).+
@@ -85,109 +85,3 @@ macro_rules! mmio_default_access {
}
};
}
-
-/// Generate `read_raw` and `write_raw` dispatch methods for a list of MMIO register types
-/// Inserts two methods into the enclosing `impl` block that iterate over the provided
-/// register types and delegate reads/writes to the appropriate `MmioAccess` impl
-#[macro_export]
-macro_rules! impl_mmio_dispatch {
- ($($reg:ty),* $(,)?) => {
- #[inline]
- fn read_raw(&mut self, addr: u32, access_size: u32) -> Option<u32> {
- $(if <$reg>::fits(addr, access_size) {
- return Some(<$reg>::read_at(self, addr, access_size));
- })*
- None
- }
-
- #[inline]
- fn write_raw(&mut self, addr: u32, access_size: u32, val: u32) -> bool {
- $(if <$reg>::fits(addr, access_size) {
- tracing::debug!(
- reg = stringify!($reg),
- addr = format!("{addr:08X}"),
- val = format!("{val:08X}"),
- size = access_size,
- "MMIO write"
- );
- <$reg>::write_at(self, addr, access_size, val);
- return true;
- })*
- false
- }
- };
-}
-
-/// Define a bitfield register struct, implement `MmioRegister`, and optionally
-/// implement `MmioAccess`
-///
-/// ```ignore
-/// mmio_register! {
-/// MyReg: u16 @ 0xCC001234 => MyDevice.my_field {
-/// #[bits(0..=7, alias = "val")] pub value: u8,
-/// }
-/// }
-/// ```
-///
-/// or
-///
-/// ```ignore
-/// mmio_register! {
-/// MyReg: u16 @ 0xCC001234 {
-/// #[bits(0..=7, alias = "val")] pub value: u8,
-/// }
-/// }
-///
-/// impl MmioAccess<MyDevice> for MyReg { ... }
-/// ```
-#[macro_export]
-macro_rules! mmio_register {
- // Auto MmioAccess: Name: raw @ addr => Owner.field { ... }
- (
- $(#[$attr:meta])*
- $name:ident : $raw:tt @ $addr:tt => $owner:tt . $field:ident {
- $($body:tt)*
- }
- ) => {
- #[chapa::bitfield($raw, order = lsb0)]
- #[derive(Copy, Clone, Debug)]
- $(#[$attr])*
- pub struct $name {
- $($body)*
- }
-
- impl $crate::mmio::traits::MmioRegister for $name {
- const ADDR: u32 = $crate::mmio::Mmio::virt_to_phys($addr);
- const SIZE: usize = ::core::mem::size_of::<$raw>();
- fn from_raw(raw: u32) -> Self { (raw as $raw).into() }
- fn to_raw(self) -> u32 { self.raw() as u32 }
- }
-
- impl $crate::mmio::traits::MmioAccess<$owner> for $name {
- fn read(dev: &$owner) -> Self { dev.$field }
- fn write(self, dev: &mut $owner) { dev.$field = self; }
- }
- };
-
- // Manual MmioAccess: Name: raw @ addr { ... }
- (
- $(#[$attr:meta])*
- $name:ident : $raw:tt @ $addr:tt {
- $($body:tt)*
- }
- ) => {
- #[chapa::bitfield($raw, order = lsb0)]
- #[derive(Copy, Clone, Debug)]
- $(#[$attr])*
- pub struct $name {
- $($body)*
- }
-
- impl $crate::mmio::traits::MmioRegister for $name {
- const ADDR: u32 = $crate::mmio::Mmio::virt_to_phys($addr);
- const SIZE: usize = ::core::mem::size_of::<$raw>();
- fn from_raw(raw: u32) -> Self { (raw as $raw).into() }
- fn to_raw(self) -> u32 { self.raw() as u32 }
- }
- };
-}
diff --git a/crates/gecko/src/mmio/traits.rs b/crates/gecko/src/mmio/traits.rs
index 7267708..d68782d 100644
--- a/crates/gecko/src/mmio/traits.rs
+++ b/crates/gecko/src/mmio/traits.rs
@@ -1,77 +1,3 @@
-pub trait MmioRw {
- const BASE: u32;
- const NAME: &'static str;
-
- fn read_raw(&mut self, addr: u32, access_size: u32) -> Option<u32>;
- fn write_raw(&mut self, addr: u32, access_size: u32, val: u32) -> bool;
-
- fn mmio_read_u8(&mut self, offset: u32) -> u8 {
- self.read_raw(Self::BASE + offset, 1).unwrap_or_else(|| {
- tracing::error!(
- peripheral = Self::NAME,
- offset = format!("{offset:08X}"),
- "unhandled mmio read_u8"
- );
- 0
- }) as u8
- }
-
- fn mmio_write_u8(&mut self, offset: u32, val: u8) {
- if !self.write_raw(Self::BASE + offset, 1, val as u32) {
- tracing::error!(
- peripheral = Self::NAME,
- offset = format!("{offset:08X}"),
- value = format!("{val:02X}"),
- "unhandled mmio write_u8"
- );
- }
- }
-
- fn mmio_read_u16(&mut self, offset: u32) -> u16 {
- self.read_raw(Self::BASE + offset, 2).unwrap_or_else(|| {
- tracing::error!(
- peripheral = Self::NAME,
- offset = format!("{offset:08X}"),
- "unhandled mmio read_u16"
- );
- 0
- }) as u16
- }
-
- fn mmio_write_u16(&mut self, offset: u32, val: u16) {
- if !self.write_raw(Self::BASE + offset, 2, val as u32) {
- tracing::error!(
- peripheral = Self::NAME,
- offset = format!("{offset:08X}"),
- value = format!("{val:04X}"),
- "unhandled mmio write_u16"
- );
- }
- }
-
- fn mmio_read_u32(&mut self, offset: u32) -> u32 {
- self.read_raw(Self::BASE + offset, 4).unwrap_or_else(|| {
- tracing::error!(
- peripheral = Self::NAME,
- offset = format!("{offset:08X}"),
- "unhandled mmio read_u32"
- );
- 0
- })
- }
-
- fn mmio_write_u32(&mut self, offset: u32, val: u32) {
- if !self.write_raw(Self::BASE + offset, 4, val) {
- tracing::error!(
- peripheral = Self::NAME,
- offset = format!("{offset:08X}"),
- value = format!("{val:08X}"),
- "unhandled mmio write_u32"
- );
- }
- }
-}
-
#[inline(always)]
pub const fn read_be_subword(word: u32, sub_offset: u32, size: u32) -> u32 {
let shift = (4 - sub_offset - size) * 8;
@@ -101,7 +27,6 @@ pub trait MmioRegister: Sized {
addr >= Self::ADDR && addr + access_size <= Self::ADDR + Self::SIZE as u32
}
- /// Extract `access_size` bytes at `addr` from `raw` (big-endian register of `SIZE` bytes)
fn read_sub(raw: u32, addr: u32, access_size: u32) -> u32 {
let sub_offset = addr - Self::ADDR;
let shift = (Self::SIZE as u32 - sub_offset - access_size) * 8;
@@ -109,7 +34,6 @@ pub trait MmioRegister: Sized {
(raw >> shift) & mask
}
- /// Return `full` with `access_size` bytes at `addr` replaced by `val` (big-endian)
fn write_sub(full: u32, addr: u32, access_size: u32, val: u32) -> u32 {
let sub_offset = addr - Self::ADDR;
let shift = (Self::SIZE as u32 - sub_offset - access_size) * 8;
@@ -118,23 +42,6 @@ pub trait MmioRegister: Sized {
}
}
-pub trait MmioAccess<C>: MmioRegister {
- fn read(component: &C) -> Self;
- fn write(self, component: &mut C);
-
- /// Read `access_size` bytes from this register in `component` at physical address `addr`
- fn read_at(component: &mut C, addr: u32, access_size: u32) -> u32 {
- Self::read_sub(Self::read(component).to_raw(), addr, access_size)
- }
-
- /// Write `access_size` bytes at `addr` into this register in `component`
- /// Unaffected bytes in the register are preserved
- fn write_at(component: &mut C, addr: u32, access_size: u32, val: u32) {
- let merged = Self::write_sub(Self::read(component).to_raw(), addr, access_size, val);
- Self::from_raw(merged).write(component);
- }
-}
-
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct WriteMask(u8);
@@ -143,7 +50,8 @@ impl WriteMask {
pub const FULL_U16: Self = Self(0b0011);
pub const FULL_U32: Self = Self(0b1111);
- /// Build a mask from the byte offset within the register and the access size in bytes.
+ /// Build a mask from the byte offset within the register and the access
+ /// size in bytes.
#[inline(always)]
pub const fn from_offset_size(sub_offset: u32, access_size: u32) -> Self {
Self((((1u32 << access_size) - 1) << sub_offset) as u8)
@@ -155,7 +63,7 @@ impl WriteMask {
(self.0 >> idx) & 1 != 0
}
- /// Did this write touch any byte in `[start, end]`?
+ /// Did this write touch any byte in `[start, end)`?
#[inline(always)]
pub const fn any(self, start: u32, end: u32) -> bool {
let m = (((1u32 << (end - start)) - 1) << start) as u8;
@@ -168,7 +76,7 @@ impl WriteMask {
}
}
-pub trait MmioHandler<C>: MmioRegister {
+pub trait MmioAccess<C>: MmioRegister {
fn read(c: &mut C) -> Self;
fn write(self, c: &mut C, mask: WriteMask);