A GameCube/Wii emulator and debugger written in Rust.
ram view abstraction over MEM1 and MEM2. Wii shows early screen and FF crystal bearers shows logo!!!!!
Laylebf4666926fc5
diff --git a/.dockerignore b/.dockerignoreindex 1ff37e9..111c1bc 100644--- a/.dockerignore+++ b/.dockerignore@@ -2,6 +2,9 @@ submodules/gcwii-resources/submodules/lilyskategc/submodules/gamecube-examples/submodules/solstice/**+submodules/guy/+submodules/beanwii/+submodules/lily-gamecube-roms/.claude/private/target/@@ -28,6 +31,7 @@ perf.*stdout.txtout.txt*.pdb+fs/# IPL HLE binary needed at compile time!submodules/solstice/ipl/diff --git a/crates/backend-wgpu/src/action.rs b/crates/backend-wgpu/src/action.rsindex 62ff103..81192d1 100644--- a/crates/backend-wgpu/src/action.rs+++ b/crates/backend-wgpu/src/action.rs@@ -1,6 +1,5 @@-use crate::GpuVertex;use crate::pipeline::PipelineKey;-use crate::{BindGroupCacheKey, DrawUniforms, FrameUniforms, GxRenderer, SamplerKey, helpers};+use crate::{BindGroupCacheKey, DrawUniforms, FrameUniforms, GpuVertex, GxRenderer, SamplerKey, helpers};use encase::{ShaderType as _, UniformBuffer};use gecko::flipper::gx::regs::{MagFilter, MinFilter, WrapMode};use gecko::host::{DrawData, GxAction};diff --git a/crates/backend-wgpu/src/dump.rs b/crates/backend-wgpu/src/dump.rsindex 4b3208c..26b640e 100644--- a/crates/backend-wgpu/src/dump.rs+++ b/crates/backend-wgpu/src/dump.rs@@ -1,9 +1,8 @@use std::path::{Path, PathBuf};use std::time::{Duration, SystemTime, UNIX_EPOCH};-use crate::GxRenderer;-use crate::align_up;use crate::capture::{self, CapturedFrame};+use crate::{GxRenderer, align_up};impl GxRenderer {pub(crate) fn dump_textures(&mut self, device: &wgpu::Device, queue: &wgpu::Queue, dir: &Path) {diff --git a/crates/backend-wgpu/src/pipeline.rs b/crates/backend-wgpu/src/pipeline.rsindex 2758fb4..ff745c0 100644--- a/crates/backend-wgpu/src/pipeline.rs+++ b/crates/backend-wgpu/src/pipeline.rs@@ -1,5 +1,4 @@-use crate::GpuVertex;-use crate::{GxRenderer, helpers};+use crate::{GpuVertex, GxRenderer, helpers};use gecko::flipper::gx::regs::{BlendFactor, CompareFunc, CullMode};#[derive(Clone, Copy, Hash, PartialEq, Eq)]diff --git a/crates/backend-wgpu/src/render.rs b/crates/backend-wgpu/src/render.rsindex 991a883..51b5814 100644--- a/crates/backend-wgpu/src/render.rs+++ b/crates/backend-wgpu/src/render.rs@@ -1,5 +1,4 @@-use crate::{FrameUniforms, GxRenderer};-use crate::{GpuVertex, align_up};+use crate::{FrameUniforms, GpuVertex, GxRenderer, align_up};use encase::ShaderType as _;use gecko::common::Address;#[cfg(feature = "efb-writeback")]diff --git a/crates/gecko/src/flipper/ai.rs b/crates/gecko/src/flipper/ai.rsindex 30559c2..3b02649 100644--- a/crates/gecko/src/flipper/ai.rs+++ b/crates/gecko/src/flipper/ai.rs@@ -1,9 +1,7 @@pub mod regs;-use crate::{- flipper::dsp,- system::{System, SystemId},-};+use crate::flipper::dsp;+use crate::system::{System, SystemId};const CPU_CORE_CLOCK: u64 = 486_000_000;const AUDIO_DMA_BLOCK_BYTES: u32 = 32;diff --git a/crates/gecko/src/flipper/gx.rs b/crates/gecko/src/flipper/gx.rsindex 729f5d5..41d657b 100644--- a/crates/gecko/src/flipper/gx.rs+++ b/crates/gecko/src/flipper/gx.rs@@ -170,19 +170,33 @@ impl GraphicsProcessor {match cmd {FifoCmd::Cp(data) => self.load_cp(&data),FifoCmd::Xf(data) => self.load_xf(renderer, &data),- FifoCmd::Bp(data) => self.load_bp(renderer, &mut mmio.ram, &data),+ FifoCmd::Bp(data) => {+ let mut view = mmio.ram_view_mut();+ self.load_bp(renderer, &mut view, &data);+ }FifoCmd::LoadIndexedXf {cp_array_index,index,xf_addr,xf_count,} => {- self.load_indexed_xf(renderer, &mmio.ram, cp_array_index, index, xf_addr, xf_count);+ let view = mmio.ram_view();+ self.load_indexed_xf(renderer, &view, cp_array_index, index, xf_addr, xf_count);}FifoCmd::CallDisplayList { phys_addr, nbytes } => {let addr = (phys_addr & 0x3FFFFFFF) as usize;let len = nbytes as usize;- self.execute_display_list(mmio, renderer, &mmio.ram[addr..addr + len].to_vec());+ let view = mmio.ram_view();+ let Some(slice) = view.slice(addr, len) else {+ tracing::warn!(+ addr = format!("{addr:#010X}"),+ len,+ "CallDisplayList: source not mapped to MEM1/MEM2, skipping"+ );+ continue;+ };+ let dl = slice.to_vec();+ self.execute_display_list(mmio, renderer, &dl);}FifoCmd::DrawCall(cmd, data) => self.create_draw_call(mmio, renderer, cmd, data),}diff --git a/crates/gecko/src/flipper/gx/bp.rs b/crates/gecko/src/flipper/gx/bp.rsindex b929b6f..3c19c2e 100644--- a/crates/gecko/src/flipper/gx/bp.rs+++ b/crates/gecko/src/flipper/gx/bp.rs@@ -3,11 +3,12 @@ use super::regs::*;use super::{GraphicsProcessor, draw, texture};use crate::common::Address;use crate::host::{GxAction, RenderSink};+use crate::mmio::{RamView, RamViewMut};#[cfg(feature = "efb-writeback")]use std::time::Duration;impl GraphicsProcessor {- pub fn load_bp(&mut self, renderer: &mut dyn RenderSink, ram: &mut [u8], data: &[u8]) {+ pub fn load_bp(&mut self, renderer: &mut dyn RenderSink, ram: &mut RamViewMut<'_>, data: &[u8]) {let idx = data[0] as usize;let val = u32::from_be_bytes([0, data[1], data[2], data[3]]);self.bp_regs[idx] = val;@@ -29,7 +30,7 @@ impl GraphicsProcessor {};if let Some(slot) = texture_slot {- self.snapshot_texture(renderer, ram, slot, val);+ self.snapshot_texture(renderer, &ram.as_view(), slot, val);}// TX_SETTLUT: per-texture-slot binding of the palette (tmem offset +@@ -46,7 +47,7 @@ impl GraphicsProcessor {};if let Some(slot) = tlut_slot {self.cur_tluts[slot] = draw::TlutRef::from_raw(val);- self.resnapshot_paletted_slot(renderer, ram, slot);+ self.resnapshot_paletted_slot(renderer, &ram.as_view(), slot);}// LOADTLUT: writing TLUT1 triggers a copy from main RAM (address in@@ -56,9 +57,9 @@ impl GraphicsProcessor {// the load, so rescan all bound paletted slots (saw this in Dolphin @// TMEM::InvalidateAll on LOADTLUT1).if idx == BP_LOAD_TLUT1 {- self.load_tlut(ram, val);+ self.load_tlut(&ram.as_view(), val);for slot in 0..self.cur_textures.len() {- self.resnapshot_paletted_slot(renderer, ram, slot);+ self.resnapshot_paletted_slot(renderer, &ram.as_view(), slot);}}@@ -201,7 +202,7 @@ impl GraphicsProcessor {}}- fn snapshot_texture(&mut self, renderer: &mut dyn RenderSink, ram: &[u8], slot: usize, image3_val: u32) {+ fn snapshot_texture(&mut self, renderer: &mut dyn RenderSink, ram: &RamView<'_>, slot: usize, image3_val: u32) {let image0_reg = if slot < 4 {BP_TX_SETIMAGE0_I0 + slot} else {@@ -237,16 +238,26 @@ impl GraphicsProcessor {let tlut = self.cur_tluts[slot];let palette = slot_palette(&self.palette_mem, tlut.tmem_offset);- let changed = self::texture_data_changed(- &mut self.texture_hashes,- ram,- ram_addr,- width,- height,- format,- palette,- tlut,- );+ // Resolve the texture's raw bytes once, against MEM1 or MEM2. If the+ // address doesn't fall in either bank, leave the slot's last binding+ // alone but skip the decode (the renderer will keep its previous+ // texture for this id).+ let raw_size = texture::raw_data_size(width, height, format);+ let tex_slice = ram.slice(ram_addr, raw_size);++ let changed = match tex_slice {+ Some(tex) => {+ self::texture_data_changed(&mut self.texture_hashes, tex, ram_addr as u32, palette, tlut, format)+ }+ None => {+ tracing::warn!(+ addr = format!("{ram_addr:#010X}"),+ raw_size,+ "texture: address not mapped to MEM1/MEM2, skipping decode"+ );+ false+ }+ };if changed {let desc = draw::TextureDescriptor {@@ -264,7 +275,7 @@ impl GraphicsProcessor {width,height,fmt: format,- rgba: texture::decode_to_rgba(ram, &desc, palette, tlut.format),+ rgba: texture::decode_to_rgba(tex_slice.unwrap(), &desc, palette, tlut.format),});}@@ -292,7 +303,7 @@ impl GraphicsProcessor {/// If the slot currently binds a paletted texture, rerun the snapshot/// pipeline so `texture_data_changed` rehashes the (now possibly fresh)/// palette bytes + TLUT format and decodes a new RGBA if anything moved.- fn resnapshot_paletted_slot(&mut self, renderer: &mut dyn RenderSink, ram: &[u8], slot: usize) {+ fn resnapshot_paletted_slot(&mut self, renderer: &mut dyn RenderSink, ram: &RamView<'_>, slot: usize) {let Some(desc) = self.cur_textures[slot] else {return;};@@ -374,7 +385,7 @@ impl GraphicsProcessor {}}- fn efb_copy(&mut self, renderer: &mut dyn RenderSink, ram: &mut [u8], trigger: u32) {+ fn efb_copy(&mut self, renderer: &mut dyn RenderSink, ram: &mut RamViewMut<'_>, trigger: u32) {let src = EfbCopySrc::from_raw(self.bp_regs[BP_PE_COPY_SRC]);let dims = EfbCopyDims::from_raw(self.bp_regs[BP_PE_COPY_DIMS]);let src_x = src.left() as u32;@@ -555,24 +566,18 @@ fn slot_palette(palette_mem: &[u16], tmem_offset: u16) -> &[u16] {palette_mem.get(base..).unwrap_or(&[])}-/// Returns `true` when the raw texture data in RAM differs from the last-/// hash recorded for the given address.+/// Returns `true` when the raw texture data in `tex` differs from the last+/// hash recorded for the given address. `tex` is the already resolved slice+/// for the texture (caller has already mapped MEM1/MEM2).fn texture_data_changed(hashes: &mut rustc_hash::FxHashMap<u32, u64>,- ram: &[u8],- addr: usize,- width: u32,- height: u32,- format: draw::TextureFormat,+ tex: &[u8],+ addr: u32,palette: &[u16],tlut: draw::TlutRef,+ format: draw::TextureFormat,) -> bool {- let size = texture::raw_data_size(width, height, format);- let Some(slice) = ram.get(addr..addr + size) else {- tracing::warn!(addr, size, "texture_changed: RAM slice OOB, assuming changed");- return true;- };- let mut hash = twox_hash::xxhash3_64::Hasher::oneshot(slice);+ let mut hash = twox_hash::xxhash3_64::Hasher::oneshot(tex);if format.is_paletted() {let max_entries = match format {draw::TextureFormat::CI4 => 16,@@ -587,18 +592,19 @@ fn texture_data_changed(// into the hash or a format switch alone wouldn't force a redecode.hash ^= tlut.format as u64;}- let prev = hashes.insert(addr as u32, hash);+ let prev = hashes.insert(addr, hash);prev != Some(hash)}impl GraphicsProcessor {/// Service a write to BP_LOAD_TLUT1: pulls `count * 16` big-endian u16/// palette entries from main RAM (source address is BP_LOAD_TLUT0 << 5)- /// into palette TMEM starting at `tmem_offset * 256`.- fn load_tlut(&mut self, ram: &[u8], load_val: u32) {+ /// into palette TMEM starting at `tmem_offset * 256`. The source address+ /// can fall in either MEM1 or MEM2 on Wii titles.+ fn load_tlut(&mut self, ram: &RamView<'_>, load_val: u32) {let tmem_offset = (load_val & 0x3FF) as usize;let count = ((load_val >> 10) & 0x7FF) as usize;- let ram_base = ((self.bp_regs[BP_LOAD_TLUT0] as usize) << 5) & 0x01FF_FFFF;+ let ram_base = (self.bp_regs[BP_LOAD_TLUT0] as usize) << 5;let entries = count * TLUT_LOAD_ENTRIES_PER_UNIT;let byte_count = entries * 2;let dst_base = tmem_offset * TLUT_ENTRIES_PER_UNIT;@@ -606,14 +612,14 @@ impl GraphicsProcessor {if entries == 0 {return;}- if ram_base.saturating_add(byte_count) > ram.len() {+ let Some(src) = ram.slice(ram_base, byte_count) else {tracing::warn!(ram_base = format!("{ram_base:#010X}"),byte_count,- "LOADTLUT: source RAM range OOB, skipping"+ "LOADTLUT: source address not mapped to MEM1/MEM2, skipping");return;- }+ };if dst_base.saturating_add(entries) > self.palette_mem.len() {tracing::warn!(dst_base,@@ -624,7 +630,6 @@ impl GraphicsProcessor {return;}- let src = &ram[ram_base..ram_base + byte_count];let dst = &mut self.palette_mem[dst_base..dst_base + entries];for (entry, chunk) in dst.iter_mut().zip(src.chunks_exact(2)) {*entry = u16::from_be_bytes([chunk[0], chunk[1]]);diff --git a/crates/gecko/src/flipper/gx/texture.rs b/crates/gecko/src/flipper/gx/texture.rsindex 9428699..3978c71 100644--- a/crates/gecko/src/flipper/gx/texture.rs+++ b/crates/gecko/src/flipper/gx/texture.rs@@ -1,29 +1,33 @@use super::draw::{TextureDescriptor, TextureFormat, TlutFormat};use multiversion::multiversion;-/// Decode a GX-format texture from RAM into RGBA8 pixels.+/// Decode a GX-format texture from a raw RAM slice into RGBA8 pixels.+///+/// `tex` must already point at the texture's raw bytes (i.e. the caller has+/// resolved `desc.ram_addr` against MEM1/MEM2 and produced the slice). The+/// decoders below offset relative to the start of `tex`.////// `palette` is the slice of the palette TMEM starting at the bound TLUT's/// tmem_offset. It is only consulted for paletted (CI*) formats; callers may/// pass `&[]` for non-paletted textures. `tlut_format` specifies how each/// 16-bit palette entry should be expanded to RGBA8.-pub fn decode_to_rgba(ram: &[u8], desc: &TextureDescriptor, palette: &[u16], tlut_format: TlutFormat) -> Vec<u8> {+pub fn decode_to_rgba(tex: &[u8], desc: &TextureDescriptor, palette: &[u16], tlut_format: TlutFormat) -> Vec<u8> {let w = desc.width as usize;let h = desc.height as usize;let mut rgba = vec![0u8; w * h * 4];match desc.format {- TextureFormat::I4 => decode_i4(ram, desc, &mut rgba, w, h),- TextureFormat::I8 => decode_i8(ram, desc, &mut rgba, w, h),- TextureFormat::IA4 => decode_ia4(ram, desc, &mut rgba, w, h),- TextureFormat::IA8 => decode_ia8(ram, desc, &mut rgba, w, h),- TextureFormat::RGB565 => decode_rgb565(ram, desc, &mut rgba, w, h),- TextureFormat::RGB5A3 => decode_rgb5a3(ram, desc, &mut rgba, w, h),- TextureFormat::RGBA8 => decode_rgba8(ram, desc, &mut rgba, w, h),- TextureFormat::CMPR => decode_cmpr(ram, desc, &mut rgba, w, h),- TextureFormat::CI4 => decode_ci4(ram, desc, &mut rgba, w, h, palette, tlut_format),- TextureFormat::CI8 => decode_ci8(ram, desc, &mut rgba, w, h, palette, tlut_format),- TextureFormat::CI14 => decode_ci14(ram, desc, &mut rgba, w, h, palette, tlut_format),+ TextureFormat::I4 => decode_i4(tex, &mut rgba, w, h),+ TextureFormat::I8 => decode_i8(tex, &mut rgba, w, h),+ TextureFormat::IA4 => decode_ia4(tex, &mut rgba, w, h),+ TextureFormat::IA8 => decode_ia8(tex, &mut rgba, w, h),+ TextureFormat::RGB565 => decode_rgb565(tex, &mut rgba, w, h),+ TextureFormat::RGB5A3 => decode_rgb5a3(tex, &mut rgba, w, h),+ TextureFormat::RGBA8 => decode_rgba8(tex, &mut rgba, w, h),+ TextureFormat::CMPR => decode_cmpr(tex, &mut rgba, w, h),+ TextureFormat::CI4 => decode_ci4(tex, &mut rgba, w, h, palette, tlut_format),+ TextureFormat::CI8 => decode_ci8(tex, &mut rgba, w, h, palette, tlut_format),+ TextureFormat::CI14 => decode_ci14(tex, &mut rgba, w, h, palette, tlut_format),}rgba@@ -70,19 +74,19 @@ pub fn raw_data_size(width: u32, height: u32, format: TextureFormat) -> usize {}#[multiversion(targets = "simd")]-fn decode_i4(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usize, h: usize) {+fn decode_i4(tex: &[u8], rgba: &mut [u8], w: usize, h: usize) {const BW: usize = 8;const BH: usize = 8;const BB: usize = 32;let bcx = w.div_ceil(BW);let bcy = h.div_ceil(BH);- if desc.ram_addr + bcx * bcy * BB > ram.len() {- tracing::warn!(addr = desc.ram_addr, w, h, "decode_i4: texture OOB, skipping");+ if bcx * bcy * BB > tex.len() {+ tracing::warn!(w, h, "decode_i4: texture OOB, skipping");return;}- let src = ram.as_ptr();+ let src = tex.as_ptr();let dst = rgba.as_mut_ptr();for by in 0..bcy {@@ -91,7 +95,7 @@ fn decode_i4(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usize, h:for bx in 0..bcx {let base_x = bx * BW;let tw = BW.min(w - base_x);- let blk = desc.ram_addr + (by * bcx + bx) * BB;+ let blk = (by * bcx + bx) * BB;for ty in 0..th {for tx in 0..tw {@@ -111,19 +115,19 @@ fn decode_i4(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usize, h:}#[multiversion(targets = "simd")]-fn decode_i8(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usize, h: usize) {+fn decode_i8(tex: &[u8], rgba: &mut [u8], w: usize, h: usize) {const BW: usize = 8;const BH: usize = 4;const BB: usize = 32;let bcx = w.div_ceil(BW);let bcy = h.div_ceil(BH);- if desc.ram_addr + bcx * bcy * BB > ram.len() {- tracing::warn!(addr = desc.ram_addr, w, h, "decode_i8: texture OOB, skipping");+ if bcx * bcy * BB > tex.len() {+ tracing::warn!(w, h, "decode_i8: texture OOB, skipping");return;}- let src = ram.as_ptr();+ let src = tex.as_ptr();let dst = rgba.as_mut_ptr();for by in 0..bcy {@@ -133,7 +137,7 @@ fn decode_i8(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usize, h:for bx in 0..bcx {let base_x = bx * BW;let tw = BW.min(w - base_x);- let blk = desc.ram_addr + (by * bcx + bx) * BB;+ let blk = (by * bcx + bx) * BB;for ty in 0..th {for tx in 0..tw {@@ -151,19 +155,19 @@ fn decode_i8(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usize, h:}#[multiversion(targets = "simd")]-fn decode_ia4(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usize, h: usize) {+fn decode_ia4(tex: &[u8], rgba: &mut [u8], w: usize, h: usize) {const BW: usize = 8;const BH: usize = 4;const BB: usize = 32;let bcx = w.div_ceil(BW);let bcy = h.div_ceil(BH);- if desc.ram_addr + bcx * bcy * BB > ram.len() {- tracing::warn!(addr = desc.ram_addr, w, h, "decode_ia4: texture OOB, skipping");+ if bcx * bcy * BB > tex.len() {+ tracing::warn!(w, h, "decode_ia4: texture OOB, skipping");return;}- let src = ram.as_ptr();+ let src = tex.as_ptr();let dst = rgba.as_mut_ptr();for by in 0..bcy {@@ -173,7 +177,7 @@ fn decode_ia4(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usize, hfor bx in 0..bcx {let base_x = bx * BW;let tw = BW.min(w - base_x);- let blk = desc.ram_addr + (by * bcx + bx) * BB;+ let blk = (by * bcx + bx) * BB;for ty in 0..th {for tx in 0..tw {@@ -193,7 +197,7 @@ fn decode_ia4(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usize, h}#[multiversion(targets = "simd")]-fn decode_ia8(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usize, h: usize) {+fn decode_ia8(tex: &[u8], rgba: &mut [u8], w: usize, h: usize) {const BW: usize = 4;const BH: usize = 4;const BB: usize = 32;@@ -201,12 +205,12 @@ fn decode_ia8(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usize, hlet bcx = w.div_ceil(BW);let bcy = h.div_ceil(BH);- if desc.ram_addr + bcx * bcy * BB > ram.len() {- tracing::warn!(addr = desc.ram_addr, w, h, "decode_ia8: texture OOB, skipping");+ if bcx * bcy * BB > tex.len() {+ tracing::warn!(w, h, "decode_ia8: texture OOB, skipping");return;}- let src = ram.as_ptr();+ let src = tex.as_ptr();let dst = rgba.as_mut_ptr();for by in 0..bcy {@@ -216,7 +220,7 @@ fn decode_ia8(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usize, hfor bx in 0..bcx {let base_x = bx * BW;let tw = BW.min(w - base_x);- let blk = desc.ram_addr + (by * bcx + bx) * BB;+ let blk = (by * bcx + bx) * BB;for ty in 0..th {for tx in 0..tw {@@ -236,19 +240,19 @@ fn decode_ia8(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usize, h}#[multiversion(targets = "simd")]-fn decode_rgb565(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usize, h: usize) {+fn decode_rgb565(tex: &[u8], rgba: &mut [u8], w: usize, h: usize) {const BW: usize = 4;const BH: usize = 4;const BB: usize = 32;let bcx = w.div_ceil(BW);let bcy = h.div_ceil(BH);- if desc.ram_addr + bcx * bcy * BB > ram.len() {- tracing::warn!(addr = desc.ram_addr, w, h, "decode_rgb565: texture OOB, skipping");+ if bcx * bcy * BB > tex.len() {+ tracing::warn!(w, h, "decode_rgb565: texture OOB, skipping");return;}- let src = ram.as_ptr();+ let src = tex.as_ptr();let dst = rgba.as_mut_ptr();for by in 0..bcy {@@ -258,7 +262,7 @@ fn decode_rgb565(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usizefor bx in 0..bcx {let base_x = bx * BW;let tw = BW.min(w - base_x);- let blk = desc.ram_addr + (by * bcx + bx) * BB;+ let blk = (by * bcx + bx) * BB;for ty in 0..th {for tx in 0..tw {@@ -277,19 +281,19 @@ fn decode_rgb565(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usize}#[multiversion(targets = "simd")]-fn decode_rgb5a3(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usize, h: usize) {+fn decode_rgb5a3(tex: &[u8], rgba: &mut [u8], w: usize, h: usize) {const BW: usize = 4;const BH: usize = 4;const BB: usize = 32;let bcx = w.div_ceil(BW);let bcy = h.div_ceil(BH);- if desc.ram_addr + bcx * bcy * BB > ram.len() {- tracing::warn!(addr = desc.ram_addr, w, h, "decode_rgb5a3: texture OOB, skipping");+ if bcx * bcy * BB > tex.len() {+ tracing::warn!(w, h, "decode_rgb5a3: texture OOB, skipping");return;}- let src = ram.as_ptr();+ let src = tex.as_ptr();let dst = rgba.as_mut_ptr();for by in 0..bcy {@@ -299,7 +303,7 @@ fn decode_rgb5a3(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usizefor bx in 0..bcx {let base_x = bx * BW;let tw = BW.min(w - base_x);- let blk = desc.ram_addr + (by * bcx + bx) * BB;+ let blk = (by * bcx + bx) * BB;for ty in 0..th {for tx in 0..tw {@@ -329,19 +333,19 @@ fn decode_rgb5a3(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usize}#[multiversion(targets = "simd")]-fn decode_rgba8(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usize, h: usize) {+fn decode_rgba8(tex: &[u8], rgba: &mut [u8], w: usize, h: usize) {const BW: usize = 4;const BH: usize = 4;const BB: usize = 64;let bcx = w.div_ceil(BW);let bcy = h.div_ceil(BH);- if desc.ram_addr + bcx * bcy * BB > ram.len() {- tracing::warn!(addr = desc.ram_addr, w, h, "decode_rgba8: texture OOB, skipping");+ if bcx * bcy * BB > tex.len() {+ tracing::warn!(w, h, "decode_rgba8: texture OOB, skipping");return;}- let src = ram.as_ptr();+ let src = tex.as_ptr();let dst = rgba.as_mut_ptr();for by in 0..bcy {@@ -351,7 +355,7 @@ fn decode_rgba8(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usize,for bx in 0..bcx {let base_x = bx * BW;let tw = BW.min(w - base_x);- let blk = desc.ram_addr + (by * bcx + bx) * BB;+ let blk = (by * bcx + bx) * BB;for ty in 0..th {for tx in 0..tw {@@ -375,7 +379,7 @@ fn decode_rgba8(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usize,}#[multiversion(targets = "simd")]-fn decode_cmpr(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usize, h: usize) {+fn decode_cmpr(tex: &[u8], rgba: &mut [u8], w: usize, h: usize) {const MW: usize = 8;const MH: usize = 8;const MB: usize = 32;@@ -383,19 +387,19 @@ fn decode_cmpr(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], w: usize,let bcx = w.div_ceil(MW);let bcy = h.div_ceil(MH);- if desc.ram_addr + bcx * bcy * MB > ram.len() {- tracing::warn!(addr = desc.ram_addr, w, h, "decode_cmpr: texture OOB, skipping");+ if bcx * bcy * MB > tex.len() {+ tracing::warn!(w, h, "decode_cmpr: texture OOB, skipping");return;}- let src = ram.as_ptr();+ let src = tex.as_ptr();let dst = rgba.as_mut_ptr();for by in 0..bcy {let macro_y = by * MH;for bx in 0..bcx {let macro_x = bx * MW;- let macro_off = desc.ram_addr + (by * bcx + bx) * MB;+ let macro_off = (by * bcx + bx) * MB;for si in 0..4usize {let sub_off = macro_off + si * SB;@@ -464,27 +468,19 @@ fn palette_lookup(palette: &[u16], index: usize, format: TlutFormat) -> [u8; 4]}#[multiversion(targets = "simd")]-fn decode_ci4(- ram: &[u8],- desc: &TextureDescriptor,- rgba: &mut [u8],- w: usize,- h: usize,- palette: &[u16],- tlut_format: TlutFormat,-) {+fn decode_ci4(tex: &[u8], rgba: &mut [u8], w: usize, h: usize, palette: &[u16], tlut_format: TlutFormat) {const BW: usize = 8;const BH: usize = 8;const BB: usize = 32;let bcx = w.div_ceil(BW);let bcy = h.div_ceil(BH);- if desc.ram_addr + bcx * bcy * BB > ram.len() {- tracing::warn!(addr = desc.ram_addr, w, h, "decode_ci4: texture OOB, skipping");+ if bcx * bcy * BB > tex.len() {+ tracing::warn!(w, h, "decode_ci4: texture OOB, skipping");return;}- let src = ram.as_ptr();+ let src = tex.as_ptr();let dst = rgba.as_mut_ptr();for by in 0..bcy {@@ -493,7 +489,7 @@ fn decode_ci4(for bx in 0..bcx {let base_x = bx * BW;let tw = BW.min(w - base_x);- let blk = desc.ram_addr + (by * bcx + bx) * BB;+ let blk = (by * bcx + bx) * BB;for ty in 0..th {for tx in 0..tw {@@ -510,27 +506,19 @@ fn decode_ci4(}#[multiversion(targets = "simd")]-fn decode_ci8(- ram: &[u8],- desc: &TextureDescriptor,- rgba: &mut [u8],- w: usize,- h: usize,- palette: &[u16],- tlut_format: TlutFormat,-) {+fn decode_ci8(tex: &[u8], rgba: &mut [u8], w: usize, h: usize, palette: &[u16], tlut_format: TlutFormat) {const BW: usize = 8;const BH: usize = 4;const BB: usize = 32;let bcx = w.div_ceil(BW);let bcy = h.div_ceil(BH);- if desc.ram_addr + bcx * bcy * BB > ram.len() {- tracing::warn!(addr = desc.ram_addr, w, h, "decode_ci8: texture OOB, skipping");+ if bcx * bcy * BB > tex.len() {+ tracing::warn!(w, h, "decode_ci8: texture OOB, skipping");return;}- let src = ram.as_ptr();+ let src = tex.as_ptr();let dst = rgba.as_mut_ptr();for by in 0..bcy {@@ -539,7 +527,7 @@ fn decode_ci8(for bx in 0..bcx {let base_x = bx * BW;let tw = BW.min(w - base_x);- let blk = desc.ram_addr + (by * bcx + bx) * BB;+ let blk = (by * bcx + bx) * BB;for ty in 0..th {for tx in 0..tw {@@ -555,27 +543,19 @@ fn decode_ci8(}#[multiversion(targets = "simd")]-fn decode_ci14(- ram: &[u8],- desc: &TextureDescriptor,- rgba: &mut [u8],- w: usize,- h: usize,- palette: &[u16],- tlut_format: TlutFormat,-) {+fn decode_ci14(tex: &[u8], rgba: &mut [u8], w: usize, h: usize, palette: &[u16], tlut_format: TlutFormat) {const BW: usize = 4;const BH: usize = 4;const BB: usize = 32;let bcx = w.div_ceil(BW);let bcy = h.div_ceil(BH);- if desc.ram_addr + bcx * bcy * BB > ram.len() {- tracing::warn!(addr = desc.ram_addr, w, h, "decode_ci14: texture OOB, skipping");+ if bcx * bcy * BB > tex.len() {+ tracing::warn!(w, h, "decode_ci14: texture OOB, skipping");return;}- let src = ram.as_ptr();+ let src = tex.as_ptr();let dst = rgba.as_mut_ptr();for by in 0..bcy {@@ -584,7 +564,7 @@ fn decode_ci14(for bx in 0..bcx {let base_x = bx * BW;let tw = BW.min(w - base_x);- let blk = desc.ram_addr + (by * bcx + bx) * BB;+ let blk = (by * bcx + bx) * BB;for ty in 0..th {for tx in 0..tw {@@ -754,7 +734,7 @@ pub fn encoded_row_count(h: u32, format: CopyFormat) -> usize {}pub fn write_strided_copy_to_ram(- ram: &mut [u8],+ ram: &mut crate::mmio::RamViewMut<'_>,dest_addr: u32,bytes: &[u8],row_bytes: usize,@@ -793,49 +773,21 @@ pub fn write_strided_copy_to_ram(return false;}- let Ok(base) = usize::try_from(dest_addr) else {- tracing::warn!(- addr = format!("{dest_addr:#010X}"),- "efb writeback destination address invalid"- );- return false;- };+ let base = dest_addr as usize;for row in 0..row_count {- let Some(dst_start) = base.checked_add(row.saturating_mul(dest_stride_bytes)) else {- tracing::warn!(- addr = format!("{dest_addr:#010X}"),- row,- "efb writeback address overflow"- );- return false;- };-- let Some(dst_end) = dst_start.checked_add(row_bytes) else {- tracing::warn!(- addr = format!("{dest_addr:#010X}"),- row,- "efb writeback row end overflow"- );- return false;- };-- if dst_end > ram.len() {+ let src_start = row * row_bytes;+ let dst_start = base + row * dest_stride_bytes;+ let Some(dst) = ram.slice_mut(dst_start, row_bytes) else {tracing::warn!(addr = format!("{dest_addr:#010X}"),row,row_bytes,- ram_len = ram.len(),- "efb writeback OOB, dropping"+ "efb writeback row not mapped to MEM1/MEM2, dropping");return false;- }- }-- for row in 0..row_count {- let src_start = row * row_bytes;- let dst_start = base + row * dest_stride_bytes;- ram[dst_start..dst_start + row_bytes].copy_from_slice(&bytes[src_start..src_start + row_bytes]);+ };+ dst.copy_from_slice(&bytes[src_start..src_start + row_bytes]);}true@@ -1333,129 +1285,3 @@ fn encode_z24x8(depth: &[u32], out: &mut [u8], w: usize, h: usize) {}}}--#[cfg(test)]-mod tests {- use super::*;-- fn rgba_pattern(w: usize, h: usize, f: impl Fn(usize, usize) -> [u8; 4]) -> Vec<u8> {- let mut out = Vec::with_capacity(w * h * 4);- for y in 0..h {- for x in 0..w {- out.extend_from_slice(&f(x, y));- }- }- out- }-- #[test]- fn copy_layout_uses_encoded_block_rows() {- assert_eq!(encoded_row_bytes(9, CopyFormat::I8), 64);- assert_eq!(encoded_row_count(5, CopyFormat::I8), 2);- assert_eq!(encoded_size(9, 5, CopyFormat::I8), 128);-- assert_eq!(encoded_row_bytes(4, CopyFormat::RGBA8), 64);- assert_eq!(encoded_row_count(5, CopyFormat::RGBA8), 2);- assert_eq!(encoded_size(4, 5, CopyFormat::RGBA8), 128);- }-- #[test]- fn strided_writeback_steps_by_destination_stride() {- let mut ram = vec![0xEE; 32];- let bytes = [1, 2, 3, 4, 5, 6, 7, 8];- assert!(write_strided_copy_to_ram(&mut ram, 10, &bytes, 4, 2, 6));-- assert_eq!(&ram[10..14], &[1, 2, 3, 4]);- assert_eq!(&ram[14..16], &[0xEE, 0xEE]);- assert_eq!(&ram[16..20], &[5, 6, 7, 8]);- }-- #[test]- fn strided_writeback_rejects_too_small_stride() {- let mut ram = vec![0xEE; 32];- let bytes = [1, 2, 3, 4, 5, 6, 7, 8];- assert!(!write_strided_copy_to_ram(&mut ram, 10, &bytes, 4, 2, 3));- assert!(ram.iter().all(|&b| b == 0xEE));- }-- #[test]- fn encodes_i4_tile() {- let rgba = rgba_pattern(8, 8, |x, y| {- let i = (((y * 8 + x) & 0x0F) as u8) << 4;- [i, i, i, 255]- });-- let encoded = encode_from_rgba(&rgba, 8, 8, CopyFormat::I4);- assert_eq!(encoded.len(), 32);- assert_eq!(&encoded[..4], &[0x01, 0x23, 0x45, 0x67]);- }-- #[test]- fn encodes_i8_tile() {- let rgba = rgba_pattern(8, 4, |x, y| {- let i = (y * 8 + x) as u8;- [i, i, i, 255]- });-- let encoded = encode_from_rgba(&rgba, 8, 4, CopyFormat::I8);- assert_eq!(encoded.len(), 32);- assert_eq!(&encoded[..8], &[0, 1, 2, 3, 4, 5, 6, 7]);- }-- #[test]- fn encodes_ia4_tile() {- let rgba = rgba_pattern(8, 4, |x, y| {- let i = ((y * 8 + x) as u8) << 4;- let a = 0x80;- [i, i, i, a]- });-- let encoded = encode_from_rgba(&rgba, 8, 4, CopyFormat::IA4);- assert_eq!(encoded.len(), 32);- assert_eq!(&encoded[..4], &[0x80, 0x81, 0x82, 0x83]);- }-- #[test]- fn encodes_ia8_tile() {- let rgba = rgba_pattern(4, 4, |x, y| {- let i = (y * 4 + x) as u8;- [i, i, i, 0xA0 + i]- });-- let encoded = encode_from_rgba(&rgba, 4, 4, CopyFormat::IA8);- assert_eq!(encoded.len(), 32);- assert_eq!(&encoded[..8], &[0xA0, 0, 0xA1, 1, 0xA2, 2, 0xA3, 3]);- }-- #[test]- fn encodes_rgb565_rgb5a3_rgba8_tiles() {- let rgba = rgba_pattern(4, 4, |x, y| {- if x == 0 && y == 0 {- [255, 0, 0, 255]- } else {- [0, 0, 0, 255]- }- });-- let rgb565 = encode_from_rgba(&rgba, 4, 4, CopyFormat::RGB565);- assert_eq!(&rgb565[..2], &[0xF8, 0x00]);-- let rgb5a3 = encode_from_rgba(&rgba, 4, 4, CopyFormat::RGB5A3);- assert_eq!(&rgb5a3[..2], &[0xFC, 0x00]);-- let rgba8 = encode_from_rgba(&rgba, 4, 4, CopyFormat::RGBA8);- assert_eq!(&rgba8[..2], &[0xFF, 0xFF]);- assert_eq!(&rgba8[32..34], &[0x00, 0x00]);- }-- #[test]- fn encodes_z24x8_from_depth_values() {- let mut depth = vec![0; 16];- depth[0] = 0x0012_3456;-- let encoded = encode_from_z24(&depth, 4, 4, CopyFormat::Z24X8);- assert_eq!(encoded.len(), 64);- assert_eq!(&encoded[..2], &[0xFF, 0x12]);- assert_eq!(&encoded[32..34], &[0x34, 0x56]);- }-}diff --git a/crates/gecko/src/flipper/gx/vertex.rs b/crates/gecko/src/flipper/gx/vertex.rsindex 4a7660c..4249591 100644--- a/crates/gecko/src/flipper/gx/vertex.rs+++ b/crates/gecko/src/flipper/gx/vertex.rs@@ -3,7 +3,7 @@ use super::math::{Vec3, unpack_rgba};use super::regs::{self, *};use super::{GraphicsProcessor, draw};use crate::host::{DrawData, DrawVertex, GxAction, LightData, RenderSink};-use crate::mmio::Mmio;+use crate::mmio::{Mmio, RamView};use crate::system::SystemId;use std::io::{Cursor, Read};@@ -65,8 +65,9 @@ impl GraphicsProcessor {let mut vertices: Vec<draw::Vertex> = Vec::with_capacity(vertex_count);let mut cur = Cursor::new(&data);+ let view = mmio.ram_view();for i in 0..vertex_count {- let vertex = self.decode_vertex(&mut cur, &data, &mmio.ram, &vf, i);+ let vertex = self.decode_vertex(&mut cur, &data, &view, &vf, i);vertices.push(vertex);}@@ -339,10 +340,30 @@ impl GraphicsProcessor {&self,cur: &mut Cursor<&Vec<u8>>,data: &[u8],- ram: &[u8],+ ram: &RamView<'_>,vf: &VertexFormat,vertex_idx: usize,) -> draw::Vertex {+ // Resolve an indexed vertex attribute (positions, normals, colors,+ // texcoords) to a slice in whichever bank holds it. If the address+ // falls outside both MEM1 and MEM2, fall back to a zero-filled+ // buffer.+ fn fetch<'a>(view: &'a RamView<'_>, addr: usize, len: usize, scratch: &'a mut [u8]) -> &'a [u8] {+ if let Some(s) = view.slice(addr, len) {+ s+ } else {+ tracing::warn!(+ addr = format!("{addr:#010X}"),+ len,+ "vertex attribute fetch unmapped, using zeros"+ );+ let n = len.min(scratch.len());+ scratch[..n].fill(0);+ &scratch[..n]+ }+ }++ let mut scratch = [0u8; 32];// Read per-vertex position/normal matrix index, or use register defaultlet pos_mtx_idx = if vf.has_pnmtxidx {let mut buf = [0u8; 1];@@ -376,7 +397,7 @@ impl GraphicsProcessor {} else {let pos_index = read_index(cur, vf.pos_attr);let pos_addr = vf.pos_base + pos_index * vf.pos_stride;- decode_position(&ram[pos_addr..pos_addr + vf.pos_data_size], &vf.vat_a)+ decode_position(fetch(ram, pos_addr, vf.pos_data_size, &mut scratch), &vf.vat_a)};// Read normal@@ -394,7 +415,7 @@ impl GraphicsProcessor {cur.set_position(cur.position() + (2 * idx_size) as u64);}let nrm_addr = vf.nrm_base_addr + nrm_index * vf.nrm_stride;- decode_normal(&ram[nrm_addr..nrm_addr + vf.nrm_data_size], &vf.vat_a)+ decode_normal(fetch(ram, nrm_addr, vf.nrm_data_size, &mut scratch), &vf.vat_a)} else {[0.0, 0.0, 1.0]};@@ -414,7 +435,7 @@ impl GraphicsProcessor {let clr0_index = read_index(cur, vf.clr0_attr);let clr0_addr = vf.clr0_base + clr0_index * vf.clr0_stride;decode_color(- &ram[clr0_addr..clr0_addr + vf.clr0_data_size],+ fetch(ram, clr0_addr, vf.clr0_data_size, &mut scratch),vf.vat_a.clr0_fmt(),vf.vat_a.clr0_cnt(),)@@ -435,7 +456,7 @@ impl GraphicsProcessor {let clr1_index = read_index(cur, vf.clr1_attr);let clr1_addr = vf.clr1_base + clr1_index * vf.clr1_stride;decode_color(- &ram[clr1_addr..clr1_addr + vf.clr1_data_size],+ fetch(ram, clr1_addr, vf.clr1_data_size, &mut scratch),vf.vat_a.clr1_fmt(),vf.vat_a.clr1_cnt(),)@@ -462,7 +483,7 @@ impl GraphicsProcessor {let tc_index = read_index(cur, tc_attr);let tc_addr = vf.tex_bases[tc] + tc_index * vf.tex_strides[tc];decode_texcoord(- &ram[tc_addr..tc_addr + tc_data_size],+ fetch(ram, tc_addr, tc_data_size, &mut scratch),vf.tex_fmts[tc],vf.tex_shifts[tc],vf.tex_cnts[tc],diff --git a/crates/gecko/src/flipper/gx/xf.rs b/crates/gecko/src/flipper/gx/xf.rsindex c4f9e87..90764a5 100644--- a/crates/gecko/src/flipper/gx/xf.rs+++ b/crates/gecko/src/flipper/gx/xf.rs@@ -2,6 +2,7 @@ use super::constants::*;use super::math::Vec3;use super::{GraphicsProcessor, draw};use crate::host::{GxAction, RenderSink};+use crate::mmio::RamView;impl GraphicsProcessor {pub fn xf_transform_3x4(&self, base: usize, v: [f32; 3]) -> Vec3 {@@ -136,7 +137,7 @@ impl GraphicsProcessor {pub fn load_indexed_xf(&mut self,renderer: &mut dyn RenderSink,- ram: &[u8],+ ram: &RamView<'_>,cp_array_index: u8,index: u16,xf_addr: u16,@@ -150,14 +151,17 @@ impl GraphicsProcessor {let n = xf_count as usize;let end = dst_addr + n;+ let Some(src) = ram.slice(src_addr, n * 4) else {+ tracing::warn!(+ src_addr = format!("{src_addr:#010X}"),+ bytes = n * 4,+ "load_indexed_xf: source not mapped to MEM1/MEM2, skipping"+ );+ return;+ };for i in 0..n {- let ram_offset = src_addr + i * 4;- let val = u32::from_be_bytes([- ram[ram_offset],- ram[ram_offset + 1],- ram[ram_offset + 2],- ram[ram_offset + 3],- ]);+ let off = i * 4;+ let val = u32::from_be_bytes([src[off], src[off + 1], src[off + 2], src[off + 3]]);let reg = dst_addr + i;if reg < self.xf_mem.len() {self.xf_mem[reg] = val;diff --git a/crates/gecko/src/hollywood/regs.rs b/crates/gecko/src/hollywood/regs.rsindex 74362d7..4c7c917 100644--- a/crates/gecko/src/hollywood/regs.rs+++ b/crates/gecko/src/hollywood/regs.rs@@ -1,7 +1,5 @@-use crate::{- System, SystemId,- mmio::traits::{MmioAccess, WriteMask},-};+use crate::mmio::traits::{MmioAccess, WriteMask};+use crate::{System, SystemId};// 0x0D00_0000 PPCMSG#[chapa::bitfield(u32, order = lsb0)]diff --git a/crates/gecko/src/mmio.rs b/crates/gecko/src/mmio.rsindex b346f93..22b3339 100644--- a/crates/gecko/src/mmio.rs+++ b/crates/gecko/src/mmio.rs@@ -16,6 +16,63 @@ pub struct Mmio<const SYSTEM: SystemId> {pub mem2: Vec<u8>,}+/// Read-only view over MEM1 plus (on Wii) MEM2, addressed by physical+/// address. Lets GP code that doesn't care about the bank just pass the+/// view through and call `.slice(addr, len)` to resolve.+pub struct RamView<'a> {+ pub mem1: &'a [u8],+ pub mem2: &'a [u8],+}++impl<'a> RamView<'a> {+ /// Resolve `[addr..addr+len]` to a slice in whichever bank holds it.+ /// Returns `None` when the range is outside both banks or crosses a+ /// bank boundary.+ #[inline(always)]+ pub fn slice(&self, addr: usize, len: usize) -> Option<&'a [u8]> {+ let end = addr.checked_add(len)?;+ if addr < self.mem1.len() {+ (end <= self.mem1.len()).then(|| &self.mem1[addr..end])+ } else if (MEM2_BASE as usize..).contains(&addr) {+ let off = addr - MEM2_BASE as usize;+ let end_off = off.checked_add(len)?;+ (end_off <= self.mem2.len()).then(|| &self.mem2[off..end_off])+ } else {+ None+ }+ }+}++/// Mutable counterpart of `RamView`. Used by EFB writeback into RAM.+pub struct RamViewMut<'a> {+ pub mem1: &'a mut [u8],+ pub mem2: &'a mut [u8],+}++impl<'a> RamViewMut<'a> {+ #[inline(always)]+ pub fn as_view(&self) -> RamView<'_> {+ RamView {+ mem1: self.mem1,+ mem2: self.mem2,+ }+ }++ #[inline(always)]+ pub fn slice_mut(&mut self, addr: usize, len: usize) -> Option<&mut [u8]> {+ let end = addr.checked_add(len)?;+ if addr < self.mem1.len() {+ (end <= self.mem1.len()).then(|| &mut self.mem1[addr..end])+ } else if (MEM2_BASE as usize..).contains(&addr) {+ let off = addr - MEM2_BASE as usize;+ let end_off = off.checked_add(len)?;+ (end_off <= self.mem2.len()).then(|| &mut self.mem2[off..end_off])+ } else {+ None+ }+ }+}+impl<const SYSTEM: SystemId> Mmio<SYSTEM> {pub fn new() -> Self {Mmio {@@ -177,6 +234,25 @@ impl<const SYSTEM: SystemId> Mmio<SYSTEM> {&mut slice[offset..offset + len]}+ /// Read-only view spanning MEM1 and (on Wii) MEM2. Used by the GP path+ /// so texture / vertex / TLUT reads can resolve addresses in either bank.+ #[inline(always)]+ pub fn ram_view(&self) -> RamView<'_> {+ RamView {+ mem1: &self.ram,+ mem2: &self.mem2,+ }+ }++ /// Mutable counterpart.+ #[inline(always)]+ pub fn ram_view_mut(&mut self) -> RamViewMut<'_> {+ RamViewMut {+ mem1: &mut self.ram,+ mem2: &mut self.mem2,+ }+ }+/// Copy `size_of::<T>()` bytes starting at `addr` into a fresh `T`. The/// caller is responsible for declaring `T` with `#[repr(C)]` and using/// big-endian wrappers (e.g. `zerocopy::byteorder::big_endian::U32`) fordiff --git a/crates/gecko/src/starlet.rs b/crates/gecko/src/starlet.rsindex df61b2f..3c4cbbd 100644--- a/crates/gecko/src/starlet.rs+++ b/crates/gecko/src/starlet.rs@@ -1,8 +1,6 @@+use crate::System;+use crate::hollywood::ipc::{DeviceContext, IosDevice};use crate::system::SystemId;-use crate::{- System,- hollywood::ipc::{DeviceContext, IosDevice},-};use std::collections::{HashMap, VecDeque};use std::path::PathBuf;diff --git a/crates/screenshotter/src/main.rs b/crates/screenshotter/src/main.rsindex faae809..c493cdd 100644--- a/crates/screenshotter/src/main.rs+++ b/crates/screenshotter/src/main.rs@@ -1,5 +1,4 @@-use backend_wgpu::GxRenderer;-use backend_wgpu::capture;+use backend_wgpu::{GxRenderer, capture};use gecko::flipper::si::pad;use gecko::flipper::si::pad::PadStatus;use gecko::flipper::vi::regs::RefreshRate;diff --git a/crates/tinyapp/src/thread.rs b/crates/tinyapp/src/thread.rsindex 19cb11b..b3180f6 100644--- a/crates/tinyapp/src/thread.rs+++ b/crates/tinyapp/src/thread.rs@@ -1,5 +1,6 @@use crossbeam_channel::Sender;-use gecko::flipper::{si::pad::PadStatus, vi::regs::RefreshRate};+use gecko::flipper::si::pad::PadStatus;+use gecko::flipper::vi::regs::RefreshRate;use gecko::system::{System, SystemId};use std::sync::{Arc, Mutex};use winit::event_loop::EventLoopProxy;