A GameCube/Wii emulator and debugger written in Rust.
refactor
Laylec12e17b43475
diff --git a/crates/debugger/src/windows/exi.rs b/crates/debugger/src/windows/exi.rsindex ce4edb0..68fe54b 100644--- a/crates/debugger/src/windows/exi.rs+++ b/crates/debugger/src/windows/exi.rs@@ -1,6 +1,6 @@use egui::{Color32, Context, Grid, RichText};use egui_material_icons::icons;-use gekko::exi::Exi;+use gekko::flipper::exi::ExternalInterface;fn flag(ui: &mut egui::Ui, val: bool) {let (icon, color) = if val {@@ -53,8 +53,8 @@ struct ChannelInfo {data_raw: u32,}-fn channel_info(exi: &Exi, ch: usize) -> ChannelInfo {- use gekko::exi::regs::TransferType;+fn channel_info(exi: &ExternalInterface, ch: usize) -> ChannelInfo {+ use gekko::flipper::exi::regs::TransferType;match ch {0 => ChannelInfo {name: "CH0",@@ -238,7 +238,7 @@ fn show_channel(ui: &mut egui::Ui, ch: &ChannelInfo) {});}-pub fn show_exi(ctx: &Context, open: &mut bool, exi: &Exi) {+pub fn show_exi(ctx: &Context, open: &mut bool, exi: &ExternalInterface) {egui::Window::new("EXI").open(open).default_size(egui::vec2(600.0, 400.0))diff --git a/crates/debugger/src/windows/gx.rs b/crates/debugger/src/windows/gx.rsindex 9642ed1..9d7beb2 100644--- a/crates/debugger/src/windows/gx.rs+++ b/crates/debugger/src/windows/gx.rs@@ -1,6 +1,6 @@use egui::{Context, Grid, RichText, ScrollArea};use egui_material_icons::icons;-use gekko::flipper::gx::Gx;+use gekko::flipper::gx::GraphicsProcessor;use gekko::flipper::gx::draw::TextureDescriptor;use gekko::mmio::Mmio;@@ -22,7 +22,7 @@ fn texture_preview(ui: &mut egui::Ui, tex: &TextureDescriptor, ram: &[u8]) {ui.label(format!("Mag: {:?} Min: {:?}", tex.mag_filter, tex.min_filter));}-pub fn show_gx(ctx: &Context, open: &mut bool, gx: &Gx, mmio: &Mmio) {+pub fn show_gx(ctx: &Context, open: &mut bool, gx: &GraphicsProcessor, mmio: &Mmio) {egui::Window::new("GX").open(open).show(ctx, |ui| {let dc = &gx.draw_commands;diff --git a/crates/debugger/src/windows/irq.rs b/crates/debugger/src/windows/irq.rsindex d64c99e..ff07c5d 100644--- a/crates/debugger/src/windows/irq.rs+++ b/crates/debugger/src/windows/irq.rs@@ -1,7 +1,7 @@use egui::{Align, Color32, Context, Grid, Layout, RichText};use egui_material_icons::icons;use gekko::cpu::Cpu;-use gekko::flipper::pi::Pi;+use gekko::flipper::pi::ProcessorInterface;fn centered_icon(ui: &mut egui::Ui, icon: &str, color: Color32) {ui.with_layout(Layout::top_down(Align::Center), |ui| {@@ -34,7 +34,7 @@ fn interrupt_row(ui: &mut egui::Ui, name: &str, pending: bool, masked: bool) {ui.end_row();}-pub fn show_irq(ctx: &Context, open: &mut bool, cpu: &Cpu, pi: &Pi) {+pub fn show_irq(ctx: &Context, open: &mut bool, cpu: &Cpu, pi: &ProcessorInterface) {egui::Window::new("IRQ").open(open).default_size(egui::vec2(380.0, 480.0))diff --git a/crates/gekko/src/di.rs b/crates/gekko/src/di.rsnew file mode 100644index 0000000..e88ab19--- /dev/null+++ b/crates/gekko/src/di.rs@@ -0,0 +1,55 @@+pub mod regs;++use crate::mmio::constants::DI_BASE;+use crate::mmio::traits::{MmioAccess, MmioRegister, MmioRw};++pub struct DvdInterface {+ pub status: regs::DiStatusRegister,+ pub cover: regs::DiCoverRegister,+}++impl DvdInterface {+ pub fn new() -> Self {+ Self {+ status: regs::DiStatusRegister::from_raw(0),+ cover: regs::DiCoverRegister::from_raw(0),+ }+ }++ pub fn interrupt_active(&self) -> bool {+ (self.status.break_complete() && self.status.break_complete_mask())+ || (self.status.device_error() && self.status.device_error_mask())+ || (self.status.transfer_complete() && self.status.transfer_complete_mask())+ || (self.cover.cover_interrupt() && self.cover.cover_interrupt_mask())+ }++}++impl MmioRw for DvdInterface {+ const BASE: u32 = DI_BASE;+ const NAME: &'static str = "DI";++ crate::impl_mmio_dispatch!(regs::DiStatusRegister, regs::DiCoverRegister,);+}++impl crate::gekko::Gekko {+ pub fn check_di_interrupts(&mut self) {+ if self.di.interrupt_active() {+ self.pi.assert_interrupt(crate::flipper::pi::InterruptFlag::Di);+ } else {+ self.pi.clear_interrupt(crate::flipper::pi::InterruptFlag::Di);+ }+ }++ pub fn open_cover(&mut self) {+ tracing::debug!("DVD drive cover opened");+ self.di.cover = self.di.cover.with_cover_interrupt(true).with_cover_status(true);+ self.check_di_interrupts();+ }++ pub fn close_cover(&mut self) {+ tracing::debug!("DVD drive cover closed");+ self.di.cover = self.di.cover.with_cover_status(false);+ self.check_di_interrupts();+ }+}diff --git a/crates/gekko/src/flipper/di/regs.rs b/crates/gekko/src/di/regs.rssimilarity index 85%rename from crates/gekko/src/flipper/di/regs.rsrename to crates/gekko/src/di/regs.rsindex 0fdbbe9..411982f 100644--- a/crates/gekko/src/flipper/di/regs.rs+++ b/crates/gekko/src/di/regs.rs@@ -1,4 +1,4 @@-use super::Di;+use super::DvdInterface;use crate::mmio::traits::MmioAccess;// 0xCC006000 4 R/W DISR - DI Status Register@@ -28,12 +28,12 @@ crate::mmio_register! {}}-impl MmioAccess<Di> for DiStatusRegister {- fn read(di: &Di) -> Self {+impl MmioAccess<DvdInterface> for DiStatusRegister {+ fn read(di: &DvdInterface) -> Self {di.status}- fn write(self, di: &mut Di) {+ fn write(self, di: &mut DvdInterface) {let mut sr = di.status;if self.break_complete() {@@ -75,12 +75,12 @@ crate::mmio_register! {}}-impl MmioAccess<Di> for DiCoverRegister {- fn read(di: &Di) -> Self {+impl MmioAccess<DvdInterface> for DiCoverRegister {+ fn read(di: &DvdInterface) -> Self {di.cover}- fn write(self, di: &mut Di) {+ fn write(self, di: &mut DvdInterface) {let mut cvr = di.cover;if self.cover_interrupt() {diff --git a/crates/gekko/src/flipper.rs b/crates/gekko/src/flipper.rsindex 341ffa1..07ef564 100644--- a/crates/gekko/src/flipper.rs+++ b/crates/gekko/src/flipper.rs@@ -1,7 +1,7 @@pub mod ai;pub mod cp;-pub mod di;pub mod dsp;+pub mod exi;pub mod gx;pub mod mi;pub mod pe;diff --git a/crates/gekko/src/flipper/ai.rs b/crates/gekko/src/flipper/ai.rsindex 7e723c5..30b05ae 100644--- a/crates/gekko/src/flipper/ai.rs+++ b/crates/gekko/src/flipper/ai.rs@@ -1,14 +1,14 @@pub mod regs;use crate::mmio::constants::AI_BASE;-use crate::mmio::traits::{MmioAccess, MmioRegister};+use crate::mmio::traits::{MmioAccess, MmioRegister, MmioRw};/// CPU cycles per AI sample at 32kHz: 486MHz / 32000 = 15187const CYCLES_PER_SAMPLE_32K: u64 = 15187;/// CPU cycles per AI sample at 48kHz: 486MHz / 48000 = 10125const CYCLES_PER_SAMPLE_48K: u64 = 10125;-pub struct Ai {+pub struct AudioInterface {pub control: regs::AiControl,pub volume: regs::AiVolume,pub sample_counter: regs::AiSampleCounter,@@ -17,7 +17,7 @@ pub struct Ai {pub sample_counter_reset_pending: bool,}-impl Ai {+impl AudioInterface {pub fn new() -> Self {Self {control: regs::AiControl::from_raw(0),@@ -62,51 +62,18 @@ impl Ai {}}+}++impl MmioRw for AudioInterface {+ const BASE: u32 = AI_BASE;+ const NAME: &'static str = "AI";+crate::impl_mmio_dispatch!(regs::AiControl,regs::AiVolume,regs::AiInterruptTiming,regs::AiSampleCounter,);-- pub fn mmio_read_u8(&mut self, offset: u32) -> u8 {- self.read_raw(AI_BASE + offset, 1).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled AI read_u8");- 0- }) as u8- }-- pub fn mmio_write_u8(&mut self, offset: u32, val: u8) {- if !self.write_raw(AI_BASE + offset, 1, val as u32) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled AI write_u8");- }- }-- pub fn mmio_read_u16(&mut self, offset: u32) -> u16 {- self.read_raw(AI_BASE + offset, 2).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled AI read_u16");- 0- }) as u16- }-- pub fn mmio_write_u16(&mut self, offset: u32, val: u16) {- if !self.write_raw(AI_BASE + offset, 2, val as u32) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled AI write_u16");- }- }-- pub fn mmio_read_u32(&mut self, offset: u32) -> u32 {- self.read_raw(AI_BASE + offset, 4).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled AI read_u32");- 0- })- }-- pub fn mmio_write_u32(&mut self, offset: u32, val: u32) {- if !self.write_raw(AI_BASE + offset, 4, val) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled AI write_u32");- }- }}impl crate::gekko::Gekko {diff --git a/crates/gekko/src/flipper/ai/regs.rs b/crates/gekko/src/flipper/ai/regs.rsindex f3247ba..765401e 100644--- a/crates/gekko/src/flipper/ai/regs.rs+++ b/crates/gekko/src/flipper/ai/regs.rs@@ -1,4 +1,4 @@-use super::Ai;+use super::AudioInterface;use crate::mmio::traits::MmioAccess;use chapa::BitEnum;@@ -41,12 +41,12 @@ crate::mmio_register! {}}-impl MmioAccess<Ai> for AiControl {- fn read(ai: &Ai) -> Self {+impl MmioAccess<AudioInterface> for AiControl {+ fn read(ai: &AudioInterface) -> Self {ai.control}- fn write(self, ai: &mut Ai) {+ fn write(self, ai: &mut AudioInterface) {let mut cr = ai.control;// AIINT is w1c@@ -74,7 +74,7 @@ impl MmioAccess<Ai> for AiControl {// 0xCC006C04 4 R/W AIVR - Audio Interface Volume Registercrate::mmio_register! {- AiVolume: u32 @ 0xCC006C04 => Ai.volume {+ AiVolume: u32 @ 0xCC006C04 => AudioInterface.volume {#[bits(0..=7)]pub left: u8,@@ -92,19 +92,19 @@ crate::mmio_register! {}}-impl MmioAccess<Ai> for AiSampleCounter {- fn read(ai: &Ai) -> Self {+impl MmioAccess<AudioInterface> for AiSampleCounter {+ fn read(ai: &AudioInterface) -> Self {ai.sample_counter}- fn write(self, _ai: &mut Ai) {+ fn write(self, _ai: &mut AudioInterface) {tracing::warn!("attempted to write to read-only AiSampleCounter");}}// 0xCC006C0C 4 R/W AIIT - Audio Interface Interrupt Timingcrate::mmio_register! {- AiInterruptTiming: u32 @ 0xCC006C0C => Ai.interrupt_timing {+ AiInterruptTiming: u32 @ 0xCC006C0C => AudioInterface.interrupt_timing {#[bits(0..=30)]pub sample_count: u32,}diff --git a/crates/gekko/src/flipper/cp.rs b/crates/gekko/src/flipper/cp.rsindex 907355d..2e78a1b 100644--- a/crates/gekko/src/flipper/cp.rs+++ b/crates/gekko/src/flipper/cp.rs@@ -1,9 +1,9 @@pub mod regs;use crate::mmio::constants::CP_BASE;-use crate::mmio::traits::{MmioAccess, MmioRegister};+use crate::mmio::traits::{MmioAccess, MmioRegister, MmioRw};-pub struct Cp {+pub struct CommandProcessor {pub status: regs::CpStatus,pub control: regs::CpControl,pub fifo_base_lo: regs::FifoBaseLo,@@ -22,7 +22,7 @@ pub struct Cp {pub fifo_read_ptr_hi: regs::FifoReadPtrHi,}-impl Cp {+impl CommandProcessor {pub fn new() -> Self {Self {status: regs::CpStatus::from_raw(0),@@ -50,6 +50,12 @@ impl Cp {|| (self.status.fifo_underflow() && self.control.fifo_underflow_interrupt_enable())}+}++impl MmioRw for CommandProcessor {+ const BASE: u32 = CP_BASE;+ const NAME: &'static str = "CP";+crate::impl_mmio_dispatch!(regs::CpStatus,regs::CpControl,@@ -69,45 +75,6 @@ impl Cp {regs::FifoReadPtrLo,regs::FifoReadPtrHi,);-- pub fn mmio_read_u8(&mut self, offset: u32) -> u8 {- self.read_raw(CP_BASE + offset, 1).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled CP read_u8");- 0- }) as u8- }-- pub fn mmio_write_u8(&mut self, offset: u32, val: u8) {- if !self.write_raw(CP_BASE + offset, 1, val as u32) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled CP write_u8");- }- }-- pub fn mmio_read_u16(&mut self, offset: u32) -> u16 {- self.read_raw(CP_BASE + offset, 2).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled CP read_u16");- 0- }) as u16- }-- pub fn mmio_write_u16(&mut self, offset: u32, val: u16) {- if !self.write_raw(CP_BASE + offset, 2, val as u32) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled CP write_u16");- }- }-- pub fn mmio_read_u32(&mut self, offset: u32) -> u32 {- self.read_raw(CP_BASE + offset, 4).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled CP read_u32");- 0- })- }-- pub fn mmio_write_u32(&mut self, offset: u32, val: u32) {- if !self.write_raw(CP_BASE + offset, 4, val) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled CP write_u32");- }- }}impl crate::gekko::Gekko {diff --git a/crates/gekko/src/flipper/cp/regs.rs b/crates/gekko/src/flipper/cp/regs.rsindex b94ae53..9f105ca 100644--- a/crates/gekko/src/flipper/cp/regs.rs+++ b/crates/gekko/src/flipper/cp/regs.rs@@ -1,10 +1,10 @@-use super::Cp;+use super::CommandProcessor;use crate::mmio::traits::MmioAccess;// 0xCC000000 2 R/W CP_STATUS - CP Status Registercrate::mmio_register! {- CpStatus: u16 @ 0xCC000000 => Cp.status {+ CpStatus: u16 @ 0xCC000000 => CommandProcessor.status {#[bits(0)]pub fifo_overflow: bool,@@ -25,7 +25,7 @@ crate::mmio_register! {// 0xCC000002 2 R/W CP_CTRL - CP Control Registercrate::mmio_register! {- CpControl: u16 @ 0xCC000002 => Cp.control {+ CpControl: u16 @ 0xCC000002 => CommandProcessor.control {#[bits(0)]pub gp_fifo_read_enable: bool,@@ -58,13 +58,13 @@ crate::mmio_register! {}}-impl MmioAccess<Cp> for CpClear {- fn read(_cp: &Cp) -> Self {+impl MmioAccess<CommandProcessor> for CpClear {+ fn read(_cp: &CommandProcessor) -> Self {tracing::warn!("attempted to read from write-only CpClear register");Self::from_raw(0)}- fn write(self, cp: &mut Cp) {+ fn write(self, cp: &mut CommandProcessor) {if self.clear_overflow() {cp.status = cp.status.with_fifo_overflow(false);}@@ -75,17 +75,17 @@ impl MmioAccess<Cp> for CpClear {}}-crate::mmio_register! { FifoBaseLo: u16 @ 0xCC000020 => Cp.fifo_base_lo {} }-crate::mmio_register! { FifoBaseHi: u16 @ 0xCC000022 => Cp.fifo_base_hi {} }-crate::mmio_register! { FifoEndLo: u16 @ 0xCC000024 => Cp.fifo_end_lo {} }-crate::mmio_register! { FifoEndHi: u16 @ 0xCC000026 => Cp.fifo_end_hi {} }-crate::mmio_register! { FifoHiWatermarkLo: u16 @ 0xCC000028 => Cp.fifo_hi_watermark_lo {} }-crate::mmio_register! { FifoHiWatermarkHi: u16 @ 0xCC00002A => Cp.fifo_hi_watermark_hi {} }-crate::mmio_register! { FifoLoWatermarkLo: u16 @ 0xCC00002C => Cp.fifo_lo_watermark_lo {} }-crate::mmio_register! { FifoLoWatermarkHi: u16 @ 0xCC00002E => Cp.fifo_lo_watermark_hi {} }-crate::mmio_register! { FifoRwDistanceLo: u16 @ 0xCC000030 => Cp.fifo_rw_distance_lo {} }-crate::mmio_register! { FifoRwDistanceHi: u16 @ 0xCC000032 => Cp.fifo_rw_distance_hi {} }-crate::mmio_register! { FifoWritePtrLo: u16 @ 0xCC000034 => Cp.fifo_write_ptr_lo {} }-crate::mmio_register! { FifoWritePtrHi: u16 @ 0xCC000036 => Cp.fifo_write_ptr_hi {} }-crate::mmio_register! { FifoReadPtrLo: u16 @ 0xCC000038 => Cp.fifo_read_ptr_lo {} }-crate::mmio_register! { FifoReadPtrHi: u16 @ 0xCC00003A => Cp.fifo_read_ptr_hi {} }+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 {} }diff --git a/crates/gekko/src/flipper/di.rs b/crates/gekko/src/flipper/di.rsdeleted file mode 100644index 64a2789..0000000--- a/crates/gekko/src/flipper/di.rs+++ /dev/null@@ -1,88 +0,0 @@-pub mod regs;--use crate::mmio::constants::DI_BASE;-use crate::mmio::traits::{MmioAccess, MmioRegister};--pub struct Di {- pub status: regs::DiStatusRegister,- pub cover: regs::DiCoverRegister,-}--impl Di {- pub fn new() -> Self {- Self {- status: regs::DiStatusRegister::from_raw(0),- cover: regs::DiCoverRegister::from_raw(0),- }- }-- pub fn interrupt_active(&self) -> bool {- (self.status.break_complete() && self.status.break_complete_mask())- || (self.status.device_error() && self.status.device_error_mask())- || (self.status.transfer_complete() && self.status.transfer_complete_mask())- || (self.cover.cover_interrupt() && self.cover.cover_interrupt_mask())- }-- crate::impl_mmio_dispatch!(regs::DiStatusRegister, regs::DiCoverRegister,);-- pub fn mmio_read_u8(&mut self, offset: u32) -> u8 {- self.read_raw(DI_BASE + offset, 1).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled DI read_u8");- 0- }) as u8- }-- pub fn mmio_write_u8(&mut self, offset: u32, val: u8) {- if !self.write_raw(DI_BASE + offset, 1, val as u32) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled DI write_u8");- }- }-- pub fn mmio_read_u16(&mut self, offset: u32) -> u16 {- self.read_raw(DI_BASE + offset, 2).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled DI read_u16");- 0- }) as u16- }-- pub fn mmio_write_u16(&mut self, offset: u32, val: u16) {- if !self.write_raw(DI_BASE + offset, 2, val as u32) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled DI write_u16");- }- }-- pub fn mmio_read_u32(&mut self, offset: u32) -> u32 {- self.read_raw(DI_BASE + offset, 4).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled DI read_u32");- 0- })- }-- pub fn mmio_write_u32(&mut self, offset: u32, val: u32) {- if !self.write_raw(DI_BASE + offset, 4, val) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled DI write_u32");- }- }-}--impl crate::gekko::Gekko {- pub fn check_di_interrupts(&mut self) {- if self.di.interrupt_active() {- self.pi.assert_interrupt(crate::flipper::pi::InterruptFlag::Di);- } else {- self.pi.clear_interrupt(crate::flipper::pi::InterruptFlag::Di);- }- }-- pub fn open_cover(&mut self) {- tracing::debug!("DVD drive cover opened");- self.di.cover = self.di.cover.with_cover_interrupt(true).with_cover_status(true);- self.check_di_interrupts();- }-- pub fn close_cover(&mut self) {- tracing::debug!("DVD drive cover closed");- self.di.cover = self.di.cover.with_cover_status(false);- self.check_di_interrupts();- }-}diff --git a/crates/gekko/src/flipper/dsp.rs b/crates/gekko/src/flipper/dsp.rsindex 1a1f668..a04e7bc 100644--- a/crates/gekko/src/flipper/dsp.rs+++ b/crates/gekko/src/flipper/dsp.rs@@ -2,7 +2,7 @@ pub mod regs;use crate::mmio::Mmio;use crate::mmio::constants::DSP_BASE;-use crate::mmio::traits::{MmioAccess, MmioRegister};+use crate::mmio::traits::{MmioAccess, MmioRegister, MmioRw};pub struct Dsp {// IMEM = IRAM + IROM@@ -124,6 +124,12 @@ impl Dsp {}}+}++impl MmioRw for Dsp {+ const BASE: u32 = DSP_BASE;+ const NAME: &'static str = "DSP";+crate::impl_mmio_dispatch!(regs::ControlStatus,regs::MailboxToDspHi,@@ -136,46 +142,9 @@ impl Dsp {regs::AramDmaAramAddr,regs::AramDmaControl,);+}- pub fn mmio_read_u8(&mut self, offset: u32) -> u8 {- self.read_raw(DSP_BASE + offset, 1).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled DSP read_u8");- 0- }) as u8- }-- pub fn mmio_write_u8(&mut self, offset: u32, val: u8) {- if !self.write_raw(DSP_BASE + offset, 1, val as u32) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled DSP write_u8");- }- }-- pub fn mmio_read_u16(&mut self, offset: u32) -> u16 {- self.read_raw(DSP_BASE + offset, 2).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled DSP read_u16");- 0- }) as u16- }-- pub fn mmio_write_u16(&mut self, offset: u32, val: u16) {- if !self.write_raw(DSP_BASE + offset, 2, val as u32) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled DSP write_u16");- }- }-- pub fn mmio_read_u32(&mut self, offset: u32) -> u32 {- self.read_raw(DSP_BASE + offset, 4).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled DSP read_u32");- 0- })- }-- pub fn mmio_write_u32(&mut self, offset: u32, val: u32) {- if !self.write_raw(DSP_BASE + offset, 4, val) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled DSP write_u32");- }- }-+impl Dsp {pub fn interrupt_active(&self) -> bool {(self.csr.ai_interrupt() && self.csr.ai_interrupt_mask())|| (self.csr.ar_interrupt() && self.csr.ar_interrupt_mask())diff --git a/crates/gekko/src/exi.rs b/crates/gekko/src/flipper/exi.rssimilarity index 87%rename from crates/gekko/src/exi.rsrename to crates/gekko/src/flipper/exi.rsindex ef90bb9..8a942e8 100644--- a/crates/gekko/src/exi.rs+++ b/crates/gekko/src/flipper/exi.rs@@ -2,12 +2,12 @@ pub mod device;pub mod macronix;pub mod regs;-use crate::exi::regs::TransferType;+use crate::flipper::exi::regs::TransferType;use crate::mmio::Mmio;use crate::mmio::constants::EXI_BASE;-use crate::mmio::traits::{MmioAccess, MmioRegister};+use crate::mmio::traits::{MmioAccess, MmioRegister, MmioRw};-pub struct Exi {+pub struct ExternalInterface {// Channel 0pub ch0_csr: regs::Channel0Status,pub ch0_mar: regs::Channel0DmaAddress,@@ -31,9 +31,9 @@ pub struct Exi {prev_cs: [u8; 3],}-impl Exi {+impl ExternalInterface {pub fn new() -> Self {- Exi {+ ExternalInterface {ch0_csr: regs::Channel0Status::from_raw(0),ch0_mar: regs::Channel0DmaAddress::from_raw(0),ch0_length: regs::Channel0DmaLength::from_raw(0),@@ -285,6 +285,12 @@ impl Exi {}}+}++impl MmioRw for ExternalInterface {+ const BASE: u32 = EXI_BASE;+ const NAME: &'static str = "EXI";+crate::impl_mmio_dispatch!(regs::Channel0Status,regs::Channel0DmaAddress,@@ -302,46 +308,9 @@ impl Exi {regs::Channel2Control,regs::Channel2Data,);+}- pub fn mmio_read_u8(&mut self, offset: u32) -> u8 {- self.read_raw(EXI_BASE + offset, 1).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled EXI read_u8");- 0- }) as u8- }-- pub fn mmio_write_u8(&mut self, offset: u32, val: u8) {- if !self.write_raw(EXI_BASE + offset, 1, val as u32) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled EXI write_u8");- }- }-- pub fn mmio_read_u16(&mut self, offset: u32) -> u16 {- self.read_raw(EXI_BASE + offset, 2).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled EXI read_u16");- 0- }) as u16- }-- pub fn mmio_write_u16(&mut self, offset: u32, val: u16) {- if !self.write_raw(EXI_BASE + offset, 2, val as u32) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled EXI write_u16");- }- }-- pub fn mmio_read_u32(&mut self, offset: u32) -> u32 {- self.read_raw(EXI_BASE + offset, 4).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled EXI read_u32");- 0- })- }-- pub fn mmio_write_u32(&mut self, offset: u32, val: u32) {- if !self.write_raw(EXI_BASE + offset, 4, val) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled EXI write_u32");- }- }-+impl ExternalInterface {pub fn interrupt_active(&self) -> bool {Self::channel_interrupt_active(&self.ch0_csr)|| Self::channel_interrupt_active(&self.ch1_csr)diff --git a/crates/gekko/src/exi/device.rs b/crates/gekko/src/flipper/exi/device.rssimilarity index 100%rename from crates/gekko/src/exi/device.rsrename to crates/gekko/src/flipper/exi/device.rsdiff --git a/crates/gekko/src/exi/macronix.rs b/crates/gekko/src/flipper/exi/macronix.rssimilarity index 100%rename from crates/gekko/src/exi/macronix.rsrename to crates/gekko/src/flipper/exi/macronix.rsdiff --git a/crates/gekko/src/exi/regs.rs b/crates/gekko/src/flipper/exi/regs.rssimilarity index 82%rename from crates/gekko/src/exi/regs.rsrename to crates/gekko/src/flipper/exi/regs.rsindex 920591b..12788be 100644--- a/crates/gekko/src/exi/regs.rs+++ b/crates/gekko/src/flipper/exi/regs.rs@@ -1,6 +1,6 @@use chapa::BitEnum;-use super::Exi;+use super::ExternalInterface;use crate::mmio::traits::{MmioAccess, MmioRegister};pub trait ChannelStatus {@@ -78,11 +78,11 @@ crate::mmio_register! {}}-impl MmioAccess<Exi> for Channel0Status {- fn read(exi: &Exi) -> Self {+impl MmioAccess<ExternalInterface> for Channel0Status {+ fn read(exi: &ExternalInterface) -> Self {exi.ch0_csr}- fn write(self, exi: &mut Exi) {+ fn write(self, exi: &mut ExternalInterface) {write_csr(&mut exi.ch0_csr, self);}}@@ -90,7 +90,7 @@ impl MmioAccess<Exi> for Channel0Status {// 0xCC006804 4 R/W EXI0MAR - EXI Channel 0 DMA Start Addresscrate::mmio_register! {- Channel0DmaAddress: u32 @ 0xCC006804 => Exi.ch0_mar {+ Channel0DmaAddress: u32 @ 0xCC006804 => ExternalInterface.ch0_mar {#[bits(5..=25, alias = "addr")] pub address: u32,}}@@ -98,7 +98,7 @@ crate::mmio_register! {// 0xCC006808 4 R/W EXI0LENGTH - EXI Channel 0 DMA Transfer Lengthcrate::mmio_register! {- Channel0DmaLength: u32 @ 0xCC006808 => Exi.ch0_length {+ Channel0DmaLength: u32 @ 0xCC006808 => ExternalInterface.ch0_length {#[bits(5..=25, alias = "len")] pub length: u32,}}@@ -114,11 +114,11 @@ crate::mmio_register! {}}-impl MmioAccess<Exi> for Channel0Control {- fn read(exi: &Exi) -> Self {+impl MmioAccess<ExternalInterface> for Channel0Control {+ fn read(exi: &ExternalInterface) -> Self {exi.ch0_cr}- fn write(self, exi: &mut Exi) {+ fn write(self, exi: &mut ExternalInterface) {let was_started = exi.ch0_cr.transfer_start();exi.ch0_cr = self;if self.transfer_start() && !was_started && !self.dma_mode() {@@ -130,7 +130,7 @@ impl MmioAccess<Exi> for Channel0Control {// 0xCC006810 4 R/W EXI0DATA - EXI Channel 0 Immediate Datacrate::mmio_register! {- Channel0Data: u32 @ 0xCC006810 => Exi.ch0_data {}+ Channel0Data: u32 @ 0xCC006810 => ExternalInterface.ch0_data {}}// --- Channel 1 ---@@ -151,11 +151,11 @@ crate::mmio_register! {}}-impl MmioAccess<Exi> for Channel1Status {- fn read(exi: &Exi) -> Self {+impl MmioAccess<ExternalInterface> for Channel1Status {+ fn read(exi: &ExternalInterface) -> Self {exi.ch1_csr}- fn write(self, exi: &mut Exi) {+ fn write(self, exi: &mut ExternalInterface) {write_csr(&mut exi.ch1_csr, self);}}@@ -163,7 +163,7 @@ impl MmioAccess<Exi> for Channel1Status {// 0xCC006818 4 R/W EXI1MAR - EXI Channel 1 DMA Start Addresscrate::mmio_register! {- Channel1DmaAddress: u32 @ 0xCC006818 => Exi.ch1_mar {+ Channel1DmaAddress: u32 @ 0xCC006818 => ExternalInterface.ch1_mar {#[bits(5..=25, alias = "addr")] pub address: u32,}}@@ -171,7 +171,7 @@ crate::mmio_register! {// 0xCC00681C 4 R/W EXI1LENGTH - EXI Channel 1 DMA Transfer Lengthcrate::mmio_register! {- Channel1DmaLength: u32 @ 0xCC00681C => Exi.ch1_length {+ Channel1DmaLength: u32 @ 0xCC00681C => ExternalInterface.ch1_length {#[bits(5..=25, alias = "len")] pub length: u32,}}@@ -187,11 +187,11 @@ crate::mmio_register! {}}-impl MmioAccess<Exi> for Channel1Control {- fn read(exi: &Exi) -> Self {+impl MmioAccess<ExternalInterface> for Channel1Control {+ fn read(exi: &ExternalInterface) -> Self {exi.ch1_cr}- fn write(self, exi: &mut Exi) {+ fn write(self, exi: &mut ExternalInterface) {let was_started = exi.ch1_cr.transfer_start();exi.ch1_cr = self;if self.transfer_start() && !was_started && !self.dma_mode() {@@ -203,7 +203,7 @@ impl MmioAccess<Exi> for Channel1Control {// 0xCC006824 4 R/W EXI1DATA - EXI Channel 1 Immediate Datacrate::mmio_register! {- Channel1Data: u32 @ 0xCC006824 => Exi.ch1_data {}+ Channel1Data: u32 @ 0xCC006824 => ExternalInterface.ch1_data {}}// --- Channel 2 ---@@ -224,11 +224,11 @@ crate::mmio_register! {}}-impl MmioAccess<Exi> for Channel2Status {- fn read(exi: &Exi) -> Self {+impl MmioAccess<ExternalInterface> for Channel2Status {+ fn read(exi: &ExternalInterface) -> Self {exi.ch2_csr}- fn write(self, exi: &mut Exi) {+ fn write(self, exi: &mut ExternalInterface) {write_csr(&mut exi.ch2_csr, self);}}@@ -238,7 +238,7 @@ impl_channel_status!(Channel0Status, Channel1Status, Channel2Status);// 0xCC00682C 4 R/W EXI2MAR - EXI Channel 2 DMA Start Addresscrate::mmio_register! {- Channel2DmaAddress: u32 @ 0xCC00682C => Exi.ch2_mar {+ Channel2DmaAddress: u32 @ 0xCC00682C => ExternalInterface.ch2_mar {#[bits(5..=25, alias = "addr")] pub address: u32,}}@@ -246,7 +246,7 @@ crate::mmio_register! {// 0xCC006830 4 R/W EXI2LENGTH - EXI Channel 2 DMA Transfer Lengthcrate::mmio_register! {- Channel2DmaLength: u32 @ 0xCC006830 => Exi.ch2_length {+ Channel2DmaLength: u32 @ 0xCC006830 => ExternalInterface.ch2_length {#[bits(5..=25, alias = "len")] pub length: u32,}}@@ -262,11 +262,11 @@ crate::mmio_register! {}}-impl MmioAccess<Exi> for Channel2Control {- fn read(exi: &Exi) -> Self {+impl MmioAccess<ExternalInterface> for Channel2Control {+ fn read(exi: &ExternalInterface) -> Self {exi.ch2_cr}- fn write(self, exi: &mut Exi) {+ fn write(self, exi: &mut ExternalInterface) {let was_started = exi.ch2_cr.transfer_start();exi.ch2_cr = self;if self.transfer_start() && !was_started && !self.dma_mode() {@@ -278,5 +278,5 @@ impl MmioAccess<Exi> for Channel2Control {// 0xCC006838 4 R/W EXI2DATA - EXI Channel 2 Immediate Datacrate::mmio_register! {- Channel2Data: u32 @ 0xCC006838 => Exi.ch2_data {}+ Channel2Data: u32 @ 0xCC006838 => ExternalInterface.ch2_data {}}diff --git a/crates/gekko/src/flipper/gx.rs b/crates/gekko/src/flipper/gx.rsindex adb0c39..9dc9951 100644--- a/crates/gekko/src/flipper/gx.rs+++ b/crates/gekko/src/flipper/gx.rs@@ -31,7 +31,7 @@ use fifo::FifoCmd;use math::{Vec3, saturating_div, unpack_rgba};use std::io::{Cursor, Read};-pub struct Gx {+pub struct GraphicsProcessor {pub raise_interrupt: bool,pub draw_commands: DrawCommands,bp_regs: Vec<u32>,@@ -55,9 +55,9 @@ pub struct Gx {cur_alpha_compare: AlphaCompare,}-impl Gx {+impl GraphicsProcessor {pub fn new() -> Self {- Gx {+ GraphicsProcessor {raise_interrupt: false,bp_regs: vec![0; BP_REG_SIZE],cp_regs: vec![0; CP_REG_SIZE],diff --git a/crates/gekko/src/flipper/gx/fifo.rs b/crates/gekko/src/flipper/gx/fifo.rsindex 3880c2c..dbee1df 100644--- a/crates/gekko/src/flipper/gx/fifo.rs+++ b/crates/gekko/src/flipper/gx/fifo.rs@@ -1,12 +1,12 @@use super::constants::{BP_CMD, CALL_DL_CMD, CP_CMD, INV_VTX_CACHE_CMD, NOP_CMD, XF_CMD};use crate::flipper::gx::{- Gx,+ GraphicsProcessor,constants::{DRAW_COMMANDS_END, DRAW_COMMANDS_START, VATA_REG, VATB_REG, VATC_REG, VCD_HI_REG, VCD_LO_REG},regs::{AttributeType, VatA, VatB, VatC, VcdHi, VcdLo},};use std::io::{Cursor, Read};-impl Gx {+impl GraphicsProcessor {pub fn push_u8(&mut self, val: u8) {self.fifo.push(val);}diff --git a/crates/gekko/src/flipper/mi.rs b/crates/gekko/src/flipper/mi.rsindex 376092b..5da7384 100644--- a/crates/gekko/src/flipper/mi.rs+++ b/crates/gekko/src/flipper/mi.rs@@ -1,57 +1,24 @@pub mod regs;use crate::mmio::constants::MI_BASE;-use crate::mmio::traits::{MmioAccess, MmioRegister};+use crate::mmio::traits::{MmioAccess, MmioRegister, MmioRw};-pub struct Mi {+pub struct MemoryInterface {pub interrupt_mask: regs::MiInterruptMask,}-impl Mi {+impl MemoryInterface {pub fn new() -> Self {Self {interrupt_mask: regs::MiInterruptMask::from_raw(0),}}- crate::impl_mmio_dispatch!(regs::MiInterruptMask,);-- pub fn mmio_read_u8(&mut self, offset: u32) -> u8 {- self.read_raw(MI_BASE + offset, 1).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled MI read_u8");- 0- }) as u8- }-- pub fn mmio_write_u8(&mut self, offset: u32, val: u8) {- if !self.write_raw(MI_BASE + offset, 1, val as u32) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled MI write_u8");- }- }-- pub fn mmio_read_u16(&mut self, offset: u32) -> u16 {- self.read_raw(MI_BASE + offset, 2).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled MI read_u16");- 0- }) as u16- }-- pub fn mmio_write_u16(&mut self, offset: u32, val: u16) {- if !self.write_raw(MI_BASE + offset, 2, val as u32) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled MI write_u16");- }- }+}- pub fn mmio_read_u32(&mut self, offset: u32) -> u32 {- self.read_raw(MI_BASE + offset, 4).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled MI read_u32");- 0- })- }+impl MmioRw for MemoryInterface {+ const BASE: u32 = MI_BASE;+ const NAME: &'static str = "MI";- pub fn mmio_write_u32(&mut self, offset: u32, val: u32) {- if !self.write_raw(MI_BASE + offset, 4, val) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled MI write_u32");- }- }+ crate::impl_mmio_dispatch!(regs::MiInterruptMask,);}diff --git a/crates/gekko/src/flipper/mi/regs.rs b/crates/gekko/src/flipper/mi/regs.rsindex c0dd3b0..c0b8c3f 100644--- a/crates/gekko/src/flipper/mi/regs.rs+++ b/crates/gekko/src/flipper/mi/regs.rs@@ -1,9 +1,9 @@-use super::Mi;+use super::MemoryInterface;// 0xCC00401C 2 R/W Memory Interface Interrupt Maskcrate::mmio_register! {- MiInterruptMask: u16 @ 0xCC00401C => Mi.interrupt_mask {+ MiInterruptMask: u16 @ 0xCC00401C => MemoryInterface.interrupt_mask {#[bits(0)]pub mem0_enable: bool,diff --git a/crates/gekko/src/flipper/pe.rs b/crates/gekko/src/flipper/pe.rsindex 2ae881d..26069e4 100644--- a/crates/gekko/src/flipper/pe.rs+++ b/crates/gekko/src/flipper/pe.rs@@ -4,11 +4,11 @@ use crate::{gekko::Gekko,mmio::{constants::PE_BASE,- traits::{MmioAccess, MmioRegister},+ traits::{MmioAccess, MmioRegister, MmioRw},},};-pub struct Pe {+pub struct PixelEngine {pub zconf: regs::ZConfig,pub alphaconf: regs::AlphaConfig,pub dst_alphaconf: regs::DstAlphaConfig,@@ -18,7 +18,7 @@ pub struct Pe {pub token: regs::Token,}-impl Pe {+impl PixelEngine {pub fn new() -> Self {Self {zconf: regs::ZConfig::from_raw(0),@@ -48,6 +48,12 @@ impl Pe {self.sr = self.sr.with_pe_token(true);}+}++impl MmioRw for PixelEngine {+ const BASE: u32 = PE_BASE;+ const NAME: &'static str = "PE";+crate::impl_mmio_dispatch!(regs::ZConfig,regs::AlphaConfig,@@ -57,45 +63,6 @@ impl Pe {regs::InterruptStatus,regs::Token,);-- pub fn mmio_read_u8(&mut self, offset: u32) -> u8 {- self.read_raw(PE_BASE + offset, 1).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled PE read_u8");- 0- }) as u8- }-- pub fn mmio_write_u8(&mut self, offset: u32, val: u8) {- if !self.write_raw(PE_BASE + offset, 1, val as u32) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled PE write_u8");- }- }-- pub fn mmio_read_u16(&mut self, offset: u32) -> u16 {- self.read_raw(PE_BASE + offset, 2).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled PE read_u16");- 0- }) as u16- }-- pub fn mmio_write_u16(&mut self, offset: u32, val: u16) {- if !self.write_raw(PE_BASE + offset, 2, val as u32) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled PE write_u16");- }- }-- pub fn mmio_read_u32(&mut self, offset: u32) -> u32 {- self.read_raw(PE_BASE + offset, 4).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled PE read_u32");- 0- })- }-- pub fn mmio_write_u32(&mut self, offset: u32, val: u32) {- if !self.write_raw(PE_BASE + offset, 4, val) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled PE write_u32");- }- }}impl Gekko {diff --git a/crates/gekko/src/flipper/pe/regs.rs b/crates/gekko/src/flipper/pe/regs.rsindex b9aebc9..805dc6f 100644--- a/crates/gekko/src/flipper/pe/regs.rs+++ b/crates/gekko/src/flipper/pe/regs.rs@@ -1,36 +1,36 @@use crate::{- flipper::pe::Pe,+ flipper::pe::PixelEngine,mmio::traits::{MmioAccess, MmioRegister},};// 0xCC001000 2 R/W Z Configurationcrate::mmio_register! {- ZConfig: u16 @ 0xCC001000 => Pe.zconf {}+ ZConfig: u16 @ 0xCC001000 => PixelEngine.zconf {}}// 0xCC001002 2 R/W Alpha Configurationcrate::mmio_register! {- AlphaConfig: u16 @ 0xCC001002 => Pe.alphaconf {}+ AlphaConfig: u16 @ 0xCC001002 => PixelEngine.alphaconf {}}// 0xCC001004 2 R/W Destination Alphacrate::mmio_register! {- DstAlphaConfig: u16 @ 0xCC001004 => Pe.dst_alphaconf {}+ DstAlphaConfig: u16 @ 0xCC001004 => PixelEngine.dst_alphaconf {}}// 0xCC001006 2 R/W Alpha Compare Modecrate::mmio_register! {- AlphaMode: u16 @ 0xCC001006 => Pe.alphamode {}+ AlphaMode: u16 @ 0xCC001006 => PixelEngine.alphamode {}}// 0xCC001008 2 R/W Alpha Read Modecrate::mmio_register! {- AlphaRead: u16 @ 0xCC001008 => Pe.alpharead {}+ AlphaRead: u16 @ 0xCC001008 => PixelEngine.alpharead {}}// 0xCC00100A 2 R/W Interrupt Status@@ -51,16 +51,16 @@ crate::mmio_register! {}}-impl MmioAccess<Pe> for InterruptStatus {- fn read(pe: &Pe) -> Self {+impl MmioAccess<PixelEngine> for InterruptStatus {+ fn read(pe: &PixelEngine) -> Self {pe.sr}- fn write(self, pe: &mut Pe) {+ fn write(self, pe: &mut PixelEngine) {Self::write_at(pe, Self::ADDR, Self::SIZE as u32, self.to_raw());}- fn write_at(pe: &mut Pe, addr: u32, access_size: u32, val: u32) {+ 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);@@ -75,5 +75,5 @@ impl MmioAccess<Pe> for InterruptStatus {}crate::mmio_register! {- Token: u16 @ 0xCC00100E => Pe.token {}+ Token: u16 @ 0xCC00100E => PixelEngine.token {}}diff --git a/crates/gekko/src/flipper/pi.rs b/crates/gekko/src/flipper/pi.rsindex 06e02f3..2eab309 100644--- a/crates/gekko/src/flipper/pi.rs+++ b/crates/gekko/src/flipper/pi.rs@@ -1,14 +1,14 @@pub mod regs;use crate::mmio::constants::PI_BASE;-use crate::mmio::traits::{MmioAccess, MmioRegister};+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 Pi {+pub struct ProcessorInterface {pub intsr: regs::InterruptCause,pub intmr: regs::InterruptMask,pub reset_code: regs::ResetCode,@@ -41,9 +41,9 @@ pub enum InterruptFlag {Hsp = 1 << 13,}-impl Pi {+impl ProcessorInterface {pub fn new() -> Self {- Pi {+ ProcessorInterface {intsr: regs::InterruptCause::default(),intmr: regs::InterruptMask::from_raw(0),reset_code: regs::ResetCode::from_raw(0),@@ -73,6 +73,12 @@ impl Pi {(self.intsr.raw() & self.intmr.raw()) != 0}+}++impl MmioRw for ProcessorInterface {+ const BASE: u32 = PI_BASE;+ const NAME: &'static str = "PI";+crate::impl_mmio_dispatch!(regs::InterruptCause,regs::InterruptMask,@@ -80,40 +86,7 @@ impl Pi {regs::FlipperRev,);- pub fn mmio_read_u8(&mut self, offset: u32) -> u8 {- self.read_raw(PI_BASE + offset, 1).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled PI read_u8");- 0- }) as u8- }-- pub fn mmio_write_u8(&mut self, offset: u32, val: u8) {- if !self.write_raw(PI_BASE + offset, 1, val as u32) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled PI write_u8");- }- }-- pub fn mmio_read_u16(&mut self, offset: u32) -> u16 {- self.read_raw(PI_BASE + offset, 2).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled PI read_u16");- 0- }) as u16- }-- pub fn mmio_write_u16(&mut self, offset: u32, val: u16) {- if !self.write_raw(PI_BASE + offset, 2, val as u32) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled PI write_u16");- }- }-- pub fn mmio_read_u32(&mut self, offset: u32) -> u32 {- self.read_raw(PI_BASE + offset, 4).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled PI read_u32");- 0- })- }-- pub fn mmio_write_u32(&mut self, offset: u32, val: u32) {+ fn mmio_write_u32(&mut self, offset: u32, val: u32) {match offset {PI_FIFO_BASE_OFFSET => {self.fifo_base = val;diff --git a/crates/gekko/src/flipper/pi/regs.rs b/crates/gekko/src/flipper/pi/regs.rsindex 86e3525..9e304c9 100644--- a/crates/gekko/src/flipper/pi/regs.rs+++ b/crates/gekko/src/flipper/pi/regs.rs@@ -1,4 +1,4 @@-use super::Pi;+use super::ProcessorInterface;// 0xCC003000 4 r INTSR - Interrupt Cause@@ -51,12 +51,12 @@ crate::mmio_register! {}}-impl crate::mmio::traits::MmioAccess<Pi> for InterruptCause {- fn read(dev: &Pi) -> Self {+impl crate::mmio::traits::MmioAccess<ProcessorInterface> for InterruptCause {+ fn read(dev: &ProcessorInterface) -> Self {dev.intsr}- fn write(self, dev: &mut Pi) {+ fn write(self, dev: &mut ProcessorInterface) {// yagcd seems to be wrong, we should not// clear everything on read, but just usual w1c insteadconst RSWST_MASK: u32 = 1 << 16;@@ -74,7 +74,7 @@ impl Default for InterruptCause {// 0xCC003004 4 r/w INTMR - Interrupt Maskcrate::mmio_register! {- InterruptMask: u32 @ 0xCC003004 => Pi.intmr {+ InterruptMask: u32 @ 0xCC003004 => ProcessorInterface.intmr {#[bits(0, alias = "error")]pub gp_runtime_error: bool,@@ -125,12 +125,12 @@ crate::mmio_register! {ResetCode: u32 @ 0xCC003024 {}}-impl crate::mmio::traits::MmioAccess<Pi> for ResetCode {- fn read(_pi: &Pi) -> Self {+impl crate::mmio::traits::MmioAccess<ProcessorInterface> for ResetCode {+ fn read(_pi: &ProcessorInterface) -> Self {Self::from_raw(0)}- fn write(self, _pi: &mut Pi) {+ fn write(self, _pi: &mut ProcessorInterface) {tracing::warn!("TODO: reset DVD");}}@@ -144,13 +144,13 @@ crate::mmio_register! {}}-impl crate::mmio::traits::MmioAccess<super::Pi> for FlipperRev {- fn read(_pi: &super::Pi) -> Self {+impl crate::mmio::traits::MmioAccess<super::ProcessorInterface> for FlipperRev {+ fn read(_pi: &super::ProcessorInterface) -> Self {// FLIPPER_REV_C from DolphinSelf::from_raw(0x2465_00B1)}- fn write(self, _pi: &mut super::Pi) {+ fn write(self, _pi: &mut super::ProcessorInterface) {tracing::warn!("writing to FlipperRev???");}}diff --git a/crates/gekko/src/flipper/si.rs b/crates/gekko/src/flipper/si.rsindex 5d68e74..be5fffd 100644--- a/crates/gekko/src/flipper/si.rs+++ b/crates/gekko/src/flipper/si.rs@@ -8,13 +8,13 @@ use pad::{GC_CONTROLLER_ID, PadStatus};const NUM_CHANNELS: usize = 4;#[derive(Clone, Copy, Debug)]-pub struct SiChannel {+pub struct SerialChannel {pub out: u32,pub in_hi: u32,pub in_lo: u32,}-impl Default for SiChannel {+impl Default for SerialChannel {fn default() -> Self {Self {out: 0,@@ -24,8 +24,8 @@ impl Default for SiChannel {}}-pub struct Si {- pub channels: [SiChannel; NUM_CHANNELS],+pub struct SerialInterface {+ pub channels: [SerialChannel; NUM_CHANNELS],pub poll: regs::SiPoll,pub comcsr: regs::SiComcsr,pub status: regs::SiStatusRegister,@@ -34,10 +34,10 @@ pub struct Si {pub pad_state: [PadStatus; NUM_CHANNELS],}-impl Si {+impl SerialInterface {pub fn new() -> Self {Self {- channels: [SiChannel::default(); NUM_CHANNELS],+ channels: [SerialChannel::default(); NUM_CHANNELS],poll: regs::SiPoll::from_raw(0),comcsr: regs::SiComcsr::from_raw(0),status: regs::SiStatusRegister::from_raw(0),diff --git a/crates/gekko/src/flipper/si/regs.rs b/crates/gekko/src/flipper/si/regs.rsindex 738d08d..b0b5ec6 100644--- a/crates/gekko/src/flipper/si/regs.rs+++ b/crates/gekko/src/flipper/si/regs.rs@@ -1,10 +1,10 @@-use super::Si;+use super::SerialInterface;use crate::mmio::traits::MmioAccess;use chapa::BitEnum;// 0xCC006430 4 R/W SIPOLL - SI Poll Registercrate::mmio_register! {- SiPoll: u32 @ 0xCC006430 => Si.poll {+ SiPoll: u32 @ 0xCC006430 => SerialInterface.poll {#[bits(0..=3)]pub vbcpy: u8,@@ -72,12 +72,12 @@ crate::mmio_register! {}}-impl MmioAccess<Si> for SiComcsr {- fn read(si: &Si) -> Self {+impl MmioAccess<SerialInterface> for SiComcsr {+ fn read(si: &SerialInterface) -> Self {si.comcsr}- fn write(self, si: &mut Si) {+ fn write(self, si: &mut SerialInterface) {let mut csr = si.comcsr;if self.tc_interrupt() {@@ -146,12 +146,12 @@ crate::mmio_register! {}}-impl MmioAccess<Si> for SiStatusRegister {- fn read(si: &Si) -> Self {+impl MmioAccess<SerialInterface> for SiStatusRegister {+ fn read(si: &SerialInterface) -> Self {si.status}- fn write(self, si: &mut Si) {+ fn write(self, si: &mut SerialInterface) {let mut status = si.status;if self.norep0() {diff --git a/crates/gekko/src/flipper/vi.rs b/crates/gekko/src/flipper/vi.rsindex 408cdb6..71ba0c0 100644--- a/crates/gekko/src/flipper/vi.rs+++ b/crates/gekko/src/flipper/vi.rs@@ -5,7 +5,7 @@ use crate::{gekko::Gekko,mmio::{constants::VI_BASE,- traits::{MmioAccess, MmioRegister},+ traits::{MmioAccess, MmioRegister, MmioRw},},scheduler::EventKind,};@@ -13,7 +13,7 @@ use crate::{const CPU_CORE_CLOCK: u64 = 486_000_000;const CLOCK_FREQUENCIES: [u64; 2] = [27_000_000, 54_000_000];-pub struct Vi {+pub struct VideoInterface {pub vtr: regs::VerticalTiming,pub htr0: regs::HorizontalTiming0,pub htr1: regs::HorizontalTiming1,@@ -55,9 +55,9 @@ pub struct Vi {pub half_line_scheduled: bool,}-impl Vi {+impl VideoInterface {pub fn new() -> Self {- Vi {+ VideoInterface {vtr: regs::VerticalTiming::from_raw(0),htr0: regs::HorizontalTiming0::from_raw(0),htr1: regs::HorizontalTiming1::from_raw(0),@@ -98,43 +98,6 @@ impl Vi {}}- crate::impl_mmio_dispatch!(- regs::VerticalTiming,- regs::HorizontalTiming0,- regs::HorizontalTiming1,- regs::VerticalTimingOdd,- regs::VerticalTimingEven,- regs::DisplayConfiguration,- regs::BurstBlankingEvenInterval,- regs::BurstBlankingOddInterval,- regs::TopFieldBase,- regs::TopFieldBaseRight,- regs::BottomFieldBase,- regs::BottomFieldBaseRight,- regs::DisplayPositionVertical,- regs::DisplayPositionHorizontal,- regs::DisplayInterrupt0,- regs::DisplayInterrupt1,- regs::DisplayInterrupt2,- regs::DisplayInterrupt3,- regs::DisplayLatch0,- regs::DisplayLatch1,- regs::HorizontalScalingWidth,- regs::HorizontalScalingRegister,- regs::FilterCoefficient0,- regs::FilterCoefficient1,- regs::FilterCoefficient2,- regs::FilterCoefficient3,- regs::FilterCoefficient4,- regs::FilterCoefficient5,- regs::FilterCoefficient6,- regs::ViClockSelect,- regs::ViDtvStatus,- regs::ViUnknown70,- regs::BorderHbe,- regs::BorderHbs,- );-pub fn ticks_per_sample(&self) -> u64 {let clock_idx = self.viclk.clock_select() as usize & 1;2 * CPU_CORE_CLOCK / CLOCK_FREQUENCIES[clock_idx]@@ -236,45 +199,48 @@ impl Vi {self.tfbl.xfb_addr()}}+}- pub fn mmio_read_u8(&mut self, offset: u32) -> u8 {- self.read_raw(VI_BASE + offset, 1).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled VI read_u8");- 0- }) as u8- }-- pub fn mmio_write_u8(&mut self, offset: u32, val: u8) {- if !self.write_raw(VI_BASE + offset, 1, val as u32) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled VI write_u8");- }- }-- pub fn mmio_read_u16(&mut self, offset: u32) -> u16 {- self.read_raw(VI_BASE + offset, 2).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled VI read_u16");- 0- }) as u16- }-- pub fn mmio_write_u16(&mut self, offset: u32, val: u16) {- if !self.write_raw(VI_BASE + offset, 2, val as u32) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled VI write_u16");- }- }-- pub fn mmio_read_u32(&mut self, offset: u32) -> u32 {- self.read_raw(VI_BASE + offset, 4).unwrap_or_else(|| {- tracing::error!(offset = format!("{offset:08X}"), "unhandled VI read_u32");- 0- })- }+impl MmioRw for VideoInterface {+ const BASE: u32 = VI_BASE;+ const NAME: &'static str = "VI";- pub fn mmio_write_u32(&mut self, offset: u32, val: u32) {- if !self.write_raw(VI_BASE + offset, 4, val) {- tracing::error!(offset = format!("{offset:08X}"), "unhandled VI write_u32");- }- }+ crate::impl_mmio_dispatch!(+ regs::VerticalTiming,+ regs::HorizontalTiming0,+ regs::HorizontalTiming1,+ regs::VerticalTimingOdd,+ regs::VerticalTimingEven,+ regs::DisplayConfiguration,+ regs::BurstBlankingEvenInterval,+ regs::BurstBlankingOddInterval,+ regs::TopFieldBase,+ regs::TopFieldBaseRight,+ regs::BottomFieldBase,+ regs::BottomFieldBaseRight,+ regs::DisplayPositionVertical,+ regs::DisplayPositionHorizontal,+ regs::DisplayInterrupt0,+ regs::DisplayInterrupt1,+ regs::DisplayInterrupt2,+ regs::DisplayInterrupt3,+ regs::DisplayLatch0,+ regs::DisplayLatch1,+ regs::HorizontalScalingWidth,+ regs::HorizontalScalingRegister,+ regs::FilterCoefficient0,+ regs::FilterCoefficient1,+ regs::FilterCoefficient2,+ regs::FilterCoefficient3,+ regs::FilterCoefficient4,+ regs::FilterCoefficient5,+ regs::FilterCoefficient6,+ regs::ViClockSelect,+ regs::ViDtvStatus,+ regs::ViUnknown70,+ regs::BorderHbe,+ regs::BorderHbs,+ );}impl Gekko {diff --git a/crates/gekko/src/flipper/vi/regs.rs b/crates/gekko/src/flipper/vi/regs.rsindex 3beb1ff..af2c937 100644--- a/crates/gekko/src/flipper/vi/regs.rs+++ b/crates/gekko/src/flipper/vi/regs.rs@@ -1,11 +1,11 @@-use super::Vi;+use super::VideoInterface;use crate::mmio::traits::{MmioAccess, MmioRegister};use chapa::BitEnum;// 0xCC002000 2 R/W VTR - Vertical Timing Registercrate::mmio_register! {- VerticalTiming: u16 @ 0xCC002000 => Vi.vtr {+ VerticalTiming: u16 @ 0xCC002000 => VideoInterface.vtr {#[bits(0..=3, alias = "equ")] pub equalization_pulse: u8,#[bits(4..=13, alias = "acv")] pub active_video: u16,}@@ -64,12 +64,12 @@ impl DisplayConfiguration {}}-impl MmioAccess<Vi> for DisplayConfiguration {- fn read(vi: &Vi) -> Self {+impl MmioAccess<VideoInterface> for DisplayConfiguration {+ fn read(vi: &VideoInterface) -> Self {vi.dcr}- fn write(self, vi: &mut Vi) {+ fn write(self, vi: &mut VideoInterface) {// TODO: Rising-edge on RST clears the register? Just to test for nowif self.reset() && !vi.dcr.reset() {vi.dcr = <DisplayConfiguration as MmioRegister>::from_raw(0);@@ -82,7 +82,7 @@ impl MmioAccess<Vi> for DisplayConfiguration {// 0xCC002004 4 R/W HTR0 - Horizontal Timing 0crate::mmio_register! {- HorizontalTiming0: u32 @ 0xCC002004 => Vi.htr0 {+ 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,@@ -92,7 +92,7 @@ crate::mmio_register! {// 0xCC002008 4 R/W HTR1 - Horizontal Timing 1crate::mmio_register! {- HorizontalTiming1: u32 @ 0xCC002008 => Vi.htr1 {+ 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,@@ -102,7 +102,7 @@ crate::mmio_register! {// 0xCC00200C 4 R/W VTO - Odd Field Vertical Timing Registercrate::mmio_register! {- VerticalTimingOdd: u32 @ 0xCC00200C => Vi.vto {+ 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,}@@ -111,7 +111,7 @@ crate::mmio_register! {// 0xCC002010 4 R/W VTE - Even Field Vertical Timing Registercrate::mmio_register! {- VerticalTimingEven: u32 @ 0xCC002010 => Vi.vte {+ 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,}@@ -120,7 +120,7 @@ crate::mmio_register! {// 0xCC002014 4 R/W BBEI - Burst Blanking Even Intervalcrate::mmio_register! {- BurstBlankingEvenInterval: u32 @ 0xCC002014 => Vi.bbei {+ 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,@@ -131,7 +131,7 @@ crate::mmio_register! {// 0xCC002018 4 R/W BBOI - Burst Blanking Odd Intervalcrate::mmio_register! {- BurstBlankingOddInterval: u32 @ 0xCC002018 => Vi.bboi {+ 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,@@ -142,7 +142,7 @@ crate::mmio_register! {// 0xCC00201c 4 R/W TFBL - Top Field Base Register (L) (External Framebuffer Half 1)crate::mmio_register! {- TopFieldBase: u32 @ 0xCC00201C => Vi.tfbl {+ TopFieldBase: u32 @ 0xCC00201C => VideoInterface.tfbl {#[bits(0..=23, alias = "fbb")]pub xfb_addr: u32,@@ -158,7 +158,7 @@ crate::mmio_register! {// 0xCC002020 4 R/W TFBR - Top Field Base Register (R)crate::mmio_register! {- TopFieldBaseRight: u32 @ 0xCC002020 => Vi.tfbr {+ TopFieldBaseRight: u32 @ 0xCC002020 => VideoInterface.tfbr {#[bits(0..=23, alias = "fbb")] pub xfb_addr: u32,}}@@ -166,7 +166,7 @@ crate::mmio_register! {// 0xCC002024 4 R/W BFBL - Bottom Field Base Register (L) (External Framebuffer Half 2)crate::mmio_register! {- BottomFieldBase: u32 @ 0xCC002024 => Vi.bfbl {+ BottomFieldBase: u32 @ 0xCC002024 => VideoInterface.bfbl {#[bits(0..=23, alias = "fbb")]pub xfb_addr: u32,@@ -179,7 +179,7 @@ crate::mmio_register! {// 0xCC002028 4 R/W BFBR - Bottom Field Base Register (R)crate::mmio_register! {- BottomFieldBaseRight: u32 @ 0xCC002028 => Vi.bfbr {+ BottomFieldBaseRight: u32 @ 0xCC002028 => VideoInterface.bfbr {#[bits(0..=23, alias = "fbb")] pub xfb_addr: u32,}}@@ -187,7 +187,7 @@ crate::mmio_register! {// 0xCC00202C 2 R DPV - Display Position Verticalcrate::mmio_register! {- DisplayPositionVertical: u16 @ 0xCC00202C => Vi.dpv {+ DisplayPositionVertical: u16 @ 0xCC00202C => VideoInterface.dpv {#[bits(0..=10, alias = "vct")] pub vertical_count: u16,}}@@ -195,7 +195,7 @@ crate::mmio_register! {// 0xCC00202E 2 R DPH - Display Position Horizontalcrate::mmio_register! {- DisplayPositionHorizontal: u16 @ 0xCC00202E => Vi.dph {+ DisplayPositionHorizontal: u16 @ 0xCC00202E => VideoInterface.dph {#[bits(0..=10, alias = "hct")] pub horizontal_count: u16,}}@@ -204,7 +204,7 @@ crate::mmio_register! {// THESE ARE NOT RESET ON WRITE 1!!crate::mmio_register! {- DisplayInterrupt0: u32 @ 0xCC002030 => Vi.di0 {+ 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,@@ -215,7 +215,7 @@ crate::mmio_register! {// 0xCC002034 4 R/W DI1 - Display Interrupt 1crate::mmio_register! {- DisplayInterrupt1: u32 @ 0xCC002034 => Vi.di1 {+ 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,@@ -226,7 +226,7 @@ crate::mmio_register! {// 0xCC002038 4 R/W DI2 - Display Interrupt 2crate::mmio_register! {- DisplayInterrupt2: u32 @ 0xCC002038 => Vi.di2 {+ 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,@@ -237,7 +237,7 @@ crate::mmio_register! {// 0xCC00203C 4 R/W DI3 - Display Interrupt 3crate::mmio_register! {- DisplayInterrupt3: u32 @ 0xCC00203C => Vi.di3 {+ 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,@@ -248,7 +248,7 @@ crate::mmio_register! {// 0xCC002040 4 R/W DL0 - Display Latch 0crate::mmio_register! {- DisplayLatch0: u32 @ 0xCC002040 => Vi.dl0 {+ 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,@@ -258,7 +258,7 @@ crate::mmio_register! {// 0xCC002044 4 R/W DL1 - Display Latch 1crate::mmio_register! {- DisplayLatch1: u32 @ 0xCC002044 => Vi.dl1 {+ 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,@@ -268,7 +268,7 @@ crate::mmio_register! {// 0xCC002048 2 R/W HSW - Horizontal Scaling Widthcrate::mmio_register! {- HorizontalScalingWidth: u16 @ 0xCC002048 => Vi.hsw {+ HorizontalScalingWidth: u16 @ 0xCC002048 => VideoInterface.hsw {#[bits(0..=9, alias = "srcwidth")] pub source_width: u16,}}@@ -276,7 +276,7 @@ crate::mmio_register! {// 0xCC00204A 2 R/W HSR - Horizontal Scaling Registercrate::mmio_register! {- HorizontalScalingRegister: u16 @ 0xCC00204A => Vi.hsr {+ HorizontalScalingRegister: u16 @ 0xCC00204A => VideoInterface.hsr {#[bits(0..=8, alias = "stp")] pub step_size: u16,#[bits(12, alias = "hs_en")] pub horizontal_scaling_enable: bool,}@@ -285,7 +285,7 @@ crate::mmio_register! {// 0xCC00204C 4 R/W FCT0 - Filter Coefficient Table 0crate::mmio_register! {- FilterCoefficient0: u32 @ 0xCC00204C => Vi.fct0 {+ 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,@@ -295,7 +295,7 @@ crate::mmio_register! {// 0xCC002050 4 R/W FCT1 - Filter Coefficient Table 1crate::mmio_register! {- FilterCoefficient1: u32 @ 0xCC002050 => Vi.fct1 {+ 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,@@ -305,7 +305,7 @@ crate::mmio_register! {// 0xCC002054 4 R/W FCT2 - Filter Coefficient Table 2crate::mmio_register! {- FilterCoefficient2: u32 @ 0xCC002054 => Vi.fct2 {+ 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,@@ -315,7 +315,7 @@ crate::mmio_register! {// 0xCC002058 4 R/W FCT3 - Filter Coefficient Table 3crate::mmio_register! {- FilterCoefficient3: u32 @ 0xCC002058 => Vi.fct3 {+ 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,@@ -326,7 +326,7 @@ crate::mmio_register! {// 0xCC00205C 4 R/W FCT4 - Filter Coefficient Table 4crate::mmio_register! {- FilterCoefficient4: u32 @ 0xCC00205C => Vi.fct4 {+ 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,@@ -337,7 +337,7 @@ crate::mmio_register! {// 0xCC002060 4 R/W FCT5 - Filter Coefficient Table 5crate::mmio_register! {- FilterCoefficient5: u32 @ 0xCC002060 => Vi.fct5 {+ 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,@@ -348,7 +348,7 @@ crate::mmio_register! {// 0xCC002064 4 R/W FCT6 - Filter Coefficient Table 6crate::mmio_register! {- FilterCoefficient6: u32 @ 0xCC002064 => Vi.fct6 {+ 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,@@ -359,7 +359,7 @@ crate::mmio_register! {// 0xCC00206C 2 R/W VICLK - VI Clock Selectcrate::mmio_register! {- ViClockSelect: u16 @ 0xCC00206C => Vi.viclk {+ ViClockSelect: u16 @ 0xCC00206C => VideoInterface.viclk {#[bits(0, alias = "clk")] pub clock_select: bool,}}@@ -367,7 +367,7 @@ crate::mmio_register! {// 0xCC00206E 2 R/W VISEL - VI DTV Statuscrate::mmio_register! {- ViDtvStatus: u16 @ 0xCC00206E => Vi.visel {+ ViDtvStatus: u16 @ 0xCC00206E => VideoInterface.visel {#[bits(2, alias = "visel")] pub dtv_status: bool,}}@@ -375,13 +375,13 @@ crate::mmio_register! {// 0xCC002070 2 R/W God knows what this is, log for nowcrate::mmio_register! {- ViUnknown70: u16 @ 0xCC002070 => Vi.unknown_70 {}+ ViUnknown70: u16 @ 0xCC002070 => VideoInterface.unknown_70 {}}// 0xCC002072 2 R/W BorderHBE - Border HBEcrate::mmio_register! {- BorderHbe: u16 @ 0xCC002072 => Vi.border_hbe {+ 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,}@@ -390,7 +390,7 @@ crate::mmio_register! {// 0xCC002074 2 R/W BorderHBS - Border HBScrate::mmio_register! {- BorderHbs: u16 @ 0xCC002074 => Vi.border_hbs {+ BorderHbs: u16 @ 0xCC002074 => VideoInterface.border_hbs {#[bits(0..=9, alias = "hbs656")] pub horizontal_blank_start_656: u16,}}diff --git a/crates/gekko/src/gekko.rs b/crates/gekko/src/gekko.rsindex c515f36..65fc63f 100644--- a/crates/gekko/src/gekko.rs+++ b/crates/gekko/src/gekko.rs@@ -2,18 +2,18 @@use crate::scripting::{HookFlags, ScriptHookFilters, ScriptHookState, ScriptHost};use crate::{cpu::{self, Cpu, IPL_RESET_VECTOR, semantics::Instruction},- exi::{Exi, macronix::ExiMacronix},+ di::DvdInterface,flipper::{- ai::Ai,- cp::Cp,- di::Di,+ ai::AudioInterface,+ cp::CommandProcessor,dsp::Dsp,- gx::Gx,- mi::Mi,- pe::Pe,- pi::Pi,- si::{Si, pad},- vi::Vi,+ exi::{ExternalInterface, macronix::ExiMacronix},+ gx::GraphicsProcessor,+ mi::MemoryInterface,+ pe::PixelEngine,+ pi::ProcessorInterface,+ si::{SerialInterface, pad},+ vi::VideoInterface,},idle::{IDLE_LOOP_MAX_INSTRS, IdleCheck, IdleDetector},mmio::Mmio,@@ -26,17 +26,17 @@ pub struct Gekko {pub cpu: Cpu,pub scheduler: Scheduler,pub mmio: Mmio,- pub vi: Vi,- pub pe: Pe,- pub pi: Pi,+ pub vi: VideoInterface,+ pub pe: PixelEngine,+ pub pi: ProcessorInterface,pub dsp: Dsp,- pub exi: Exi,- pub gx: Gx,- pub cp: Cp,- pub di: Di,- pub si: Si,- pub ai: Ai,- pub mi: Mi,+ pub exi: ExternalInterface,+ pub gx: GraphicsProcessor,+ pub cp: CommandProcessor,+ pub di: DvdInterface,+ pub si: SerialInterface,+ pub ai: AudioInterface,+ pub mi: MemoryInterface,idle: IdleDetector,#[cfg(feature = "scripting")]@@ -75,17 +75,17 @@ impl Gekko {cpu: Cpu::new(entrypoint),scheduler: Scheduler::new(),mmio: Mmio::new(),- vi: Vi::new(),- pe: Pe::new(),- pi: Pi::new(),+ vi: VideoInterface::new(),+ pe: PixelEngine::new(),+ pi: ProcessorInterface::new(),dsp: Dsp::new(),- exi: Exi::dummy(),- gx: Gx::new(),- cp: Cp::new(),- di: Di::new(),- si: Si::new(),- ai: Ai::new(),- mi: Mi::new(),+ exi: ExternalInterface::dummy(),+ gx: GraphicsProcessor::new(),+ cp: CommandProcessor::new(),+ di: DvdInterface::new(),+ si: SerialInterface::new(),+ ai: AudioInterface::new(),+ mi: MemoryInterface::new(),idle: IdleDetector::new(idle_skip),#[cfg(feature = "scripting")]diff --git a/crates/gekko/src/lib.rs b/crates/gekko/src/lib.rsindex a5d3dd9..02574d4 100644--- a/crates/gekko/src/lib.rs+++ b/crates/gekko/src/lib.rs@@ -1,5 +1,5 @@pub mod cpu;-pub mod exi;+pub mod di;pub mod flipper;pub mod gekko;pub mod idle;diff --git a/crates/gekko/src/mmio.rs b/crates/gekko/src/mmio.rsindex 97915ba..7c5e441 100644--- a/crates/gekko/src/mmio.rs+++ b/crates/gekko/src/mmio.rs@@ -7,6 +7,8 @@ pub mod fp;pub mod macros;pub mod traits;+pub use traits::MmioRw;+use constants::*;pub struct Mmio {diff --git a/crates/gekko/src/mmio/bus.rs b/crates/gekko/src/mmio/bus.rsindex 48e2467..2862d96 100644--- a/crates/gekko/src/mmio/bus.rs+++ b/crates/gekko/src/mmio/bus.rs@@ -9,6 +9,7 @@ use crate::{GX_FIFO_END, IPL_BASE, IPL_END, MI_BASE, MI_END, PE_BASE, PE_END, PI_BASE, PI_END, RAM_BASE, RAM_END,SI_BASE, SI_END, VI_BASE, VI_END,},+ MmioRw,},};diff --git a/crates/gekko/src/mmio/traits.rs b/crates/gekko/src/mmio/traits.rsindex 1896c34..52713a2 100644--- a/crates/gekko/src/mmio/traits.rs+++ b/crates/gekko/src/mmio/traits.rs@@ -1,3 +1,77 @@+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"+ );+ }+ }+}+pub trait MmioRegister: Sized {const ADDR: u32;const SIZE: usize;diff --git a/crates/tinyemu/src/dump.rs b/crates/tinyemu/src/dump.rsindex 577f8b6..ffd9731 100644--- a/crates/tinyemu/src/dump.rs+++ b/crates/tinyemu/src/dump.rs@@ -1,5 +1,5 @@use colored::Colorize;-use gekko::exi::regs::TransferType;+use gekko::flipper::exi::regs::TransferType;use crate::snaptshot::CpuSnapshot;@@ -90,7 +90,7 @@ pub fn memory(mmio: &gekko::mmio::Mmio, addr: u32) {}}-pub fn vi(vi: &gekko::flipper::vi::Vi) {+pub fn vi(vi: &gekko::flipper::vi::VideoInterface) {println!("Display Configuration: {:?}", vi.dcr);println!("Bottom Field Base: {:08X?}", vi.bfbl);println!("Top Field Base: {:08X?}", vi.tfbl);@@ -192,7 +192,7 @@ fn exi_channel(ch: &ExiChannelView) {println!(" Immediate Data: 0x{:08X}", ch.immediate_data);}-pub fn exi(exi: &gekko::exi::Exi) {+pub fn exi(exi: &gekko::flipper::exi::ExternalInterface) {println!("EXI:");exi_channel(&ExiChannelView {name: "Channel 0",