Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

formatting

Layleca6690e75887
diff --git a/crates/backend-wgpu/src/lib.rs b/crates/backend-wgpu/src/lib.rs
index b84b11a..1e329db 100644
--- a/crates/backend-wgpu/src/lib.rs
+++ b/crates/backend-wgpu/src/lib.rs
@@ -490,8 +490,7 @@ impl GxRenderer {
let draw_uniform = DrawUniforms { mvp: mvp.0 };
let start = self.scratch_draws.len() * draw_stride;
self.scratch_uniform_bytes.resize(start + draw_stride, 0);
- self.scratch_uniform_bytes[start..start + draw_size]
- .copy_from_slice(bytemuck::bytes_of(&draw_uniform));
+ self.scratch_uniform_bytes[start..start + draw_size].copy_from_slice(bytemuck::bytes_of(&draw_uniform));
let alpha_cmp = dc.bp_alpha_compare;
let frame_uniform = FrameUniforms {
@@ -509,8 +508,7 @@ impl GxRenderer {
};
let fstart = self.scratch_draws.len() * frame_stride;
frame_uniform_bytes.resize(fstart + frame_stride, 0);
- frame_uniform_bytes[fstart..fstart + frame_size]
- .copy_from_slice(bytemuck::bytes_of(&frame_uniform));
+ frame_uniform_bytes[fstart..fstart + frame_size].copy_from_slice(bytemuck::bytes_of(&frame_uniform));
self.scratch_draws.push((prev_len as u32, added as u32));
draw_call_indices.push(dc_idx);
@@ -545,11 +543,7 @@ impl GxRenderer {
queue.write_buffer(&self.frame_uniform_buffer, 0, &frame_uniform_bytes);
queue.write_buffer(&self.draw_uniform_buffer, 0, &self.scratch_uniform_bytes);
- queue.write_buffer(
- &self.vertex_buffer,
- 0,
- bytemuck::cast_slice(&self.scratch_vertices),
- );
+ queue.write_buffer(&self.vertex_buffer, 0, bytemuck::cast_slice(&self.scratch_vertices));
let mut encoder = device.create_command_encoder(&Default::default());
{
@@ -578,9 +572,7 @@ impl GxRenderer {
});
rpass.set_vertex_buffer(0, self.vertex_buffer.slice(..));
- for (index, (first_vertex, vertex_count)) in
- self.scratch_draws.iter().copied().enumerate()
- {
+ for (index, (first_vertex, vertex_count)) in self.scratch_draws.iter().copied().enumerate() {
let dc = &commands.commands[draw_call_indices[index]];
let pipeline_key = PipelineKey::from_draw_call(dc);
let pipeline = &self.pipeline_cache[&pipeline_key];
@@ -588,18 +580,13 @@ impl GxRenderer {
let (tex_view, sampler) = if let Some(desc) = &dc.textures[0] {
let tex_key = (desc.ram_addr, desc.width, desc.height, desc.format);
- let sampler_key =
- (desc.wrap_s, desc.wrap_t, desc.mag_filter, desc.min_filter);
- (
- &self.texture_cache[&tex_key].1,
- &self.sampler_cache[&sampler_key],
- )
+ let sampler_key = (desc.wrap_s, desc.wrap_t, desc.mag_filter, desc.min_filter);
+ (&self.texture_cache[&tex_key].1, &self.sampler_cache[&sampler_key])
} else {
(&self.fallback_view, &self.sampler_cache[&fallback_sampler_key])
};
- let frame_offset =
- (index as u64 * frame_stride as u64) as wgpu::BufferAddress;
+ let frame_offset = (index as u64 * frame_stride as u64) as wgpu::BufferAddress;
let draw_offset = (index as u64 * self.draw_uniform_stride) as u32;
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
@@ -611,9 +598,7 @@ impl GxRenderer {
resource: wgpu::BindingResource::Buffer(wgpu::BufferBinding {
buffer: &self.frame_uniform_buffer,
offset: frame_offset,
- size: wgpu::BufferSize::new(
- std::mem::size_of::<FrameUniforms>() as u64,
- ),
+ size: wgpu::BufferSize::new(std::mem::size_of::<FrameUniforms>() as u64),
}),
},
wgpu::BindGroupEntry {
@@ -621,9 +606,7 @@ impl GxRenderer {
resource: wgpu::BindingResource::Buffer(wgpu::BufferBinding {
buffer: &self.draw_uniform_buffer,
offset: 0,
- size: wgpu::BufferSize::new(
- std::mem::size_of::<DrawUniforms>() as u64,
- ),
+ size: wgpu::BufferSize::new(std::mem::size_of::<DrawUniforms>() as u64),
}),
},
wgpu::BindGroupEntry {
diff --git a/crates/backend-wgpu/src/texture.rs b/crates/backend-wgpu/src/texture.rs
index 71db599..5d026ba 100644
--- a/crates/backend-wgpu/src/texture.rs
+++ b/crates/backend-wgpu/src/texture.rs
@@ -123,7 +123,9 @@ fn decode_i4(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], width: usize
};
let intensity = expand_to_8bit(nibble as u16, 15);
- put_pixel(rgba, width, pixel_x, pixel_y, intensity, intensity, intensity, intensity);
+ put_pixel(
+ rgba, width, pixel_x, pixel_y, intensity, intensity, intensity, intensity,
+ );
}
}
}
@@ -156,7 +158,9 @@ fn decode_i8(ram: &[u8], desc: &TextureDescriptor, rgba: &mut [u8], width: usize
}
let intensity = ram[byte_offset];
- put_pixel(rgba, width, pixel_x, pixel_y, intensity, intensity, intensity, intensity);
+ put_pixel(
+ rgba, width, pixel_x, pixel_y, intensity, intensity, intensity, intensity,
+ );
}
}
}
diff --git a/crates/debugger/src/main.rs b/crates/debugger/src/main.rs
index d22bede..8ebd557 100644
--- a/crates/debugger/src/main.rs
+++ b/crates/debugger/src/main.rs
@@ -135,14 +135,14 @@ fn update_pad(pad: &mut PadStatus, key: KeyCode, pressed: bool) {
KeyCode::ArrowDown => pad.stick_y = if pressed { 0 } else { STICK_CENTER },
KeyCode::ArrowLeft => pad.stick_x = if pressed { 0 } else { STICK_CENTER },
KeyCode::ArrowRight => pad.stick_x = if pressed { 255 } else { STICK_CENTER },
-
+
// Face buttons
KeyCode::KeyX => set_button(&mut pad.buttons, pad::A, pressed),
KeyCode::KeyZ => set_button(&mut pad.buttons, pad::B, pressed),
KeyCode::KeyC => set_button(&mut pad.buttons, pad::X, pressed),
KeyCode::KeyV => set_button(&mut pad.buttons, pad::Y, pressed),
KeyCode::Enter => set_button(&mut pad.buttons, pad::START, pressed),
-
+
// Triggers
KeyCode::KeyA => {
set_button(&mut pad.buttons, pad::L, pressed);
@@ -153,7 +153,7 @@ fn update_pad(pad: &mut PadStatus, key: KeyCode, pressed: bool) {
pad.trigger_right = if pressed { 255 } else { 0 };
}
KeyCode::KeyD => set_button(&mut pad.buttons, pad::Z, pressed),
-
+
// D-pad
KeyCode::KeyI => set_button(&mut pad.buttons, pad::DPAD_UP, pressed),
KeyCode::KeyK => set_button(&mut pad.buttons, pad::DPAD_DOWN, pressed),
diff --git a/crates/debugger/src/windows/gx.rs b/crates/debugger/src/windows/gx.rs
index 475bfc0..9642ed1 100644
--- a/crates/debugger/src/windows/gx.rs
+++ b/crates/debugger/src/windows/gx.rs
@@ -81,10 +81,9 @@ pub fn show_gx(ctx: &Context, open: &mut bool, gx: &Gx, mmio: &Mmio) {
let alpha = call.tev_alpha_env[stage];
ui.collapsing(format!("Stage {stage}"), |ui| {
- Grid::new(format!("tev_{i}_{stage}"))
- .num_columns(2)
- .striped(true)
- .show(ui, |ui| {
+ Grid::new(format!("tev_{i}_{stage}")).num_columns(2).striped(true).show(
+ ui,
+ |ui| {
ui.label("Color A");
ui.monospace(format!("{}", color.a()));
ui.end_row();
@@ -116,7 +115,8 @@ pub fn show_gx(ctx: &Context, open: &mut bool, gx: &Gx, mmio: &Mmio) {
ui.label("Alpha Dest");
ui.monospace(format!("{}", alpha.dest()));
ui.end_row();
- });
+ },
+ );
});
}
});
diff --git a/crates/gekko/src/cpu/interpreter/system.rs b/crates/gekko/src/cpu/interpreter/system.rs
index fd39f5b..050a594 100644
--- a/crates/gekko/src/cpu/interpreter/system.rs
+++ b/crates/gekko/src/cpu/interpreter/system.rs
@@ -1,4 +1,4 @@
-use crate::cpu::{irq, spr::Srr0, sr::Sr};
+use crate::cpu::sr::Sr;
pub fn msr<const OP: u32>(ctx: &mut crate::gekko::Gekko, instr: crate::cpu::semantics::Instruction) {
match OP {
diff --git a/crates/gekko/src/cpu/irq.rs b/crates/gekko/src/cpu/irq.rs
index d57124d..15df39d 100644
--- a/crates/gekko/src/cpu/irq.rs
+++ b/crates/gekko/src/cpu/irq.rs
@@ -51,7 +51,11 @@ impl Gekko {
}
pub fn cause_syscall_interrupt(&mut self) {
- let base: u32 = if self.cpu.msr.exception_prefix() { 0xFFF0_0000 } else { 0 };
+ let base: u32 = if self.cpu.msr.exception_prefix() {
+ 0xFFF0_0000
+ } else {
+ 0
+ };
self.cpu.spr.srr0 = Srr0::from(self.cpu.cia.wrapping_add(4));
self.cpu.spr.srr1 = chapa::extract_bits!(self.cpu.msr; 0, 5..=9, 16..=31).raw();
diff --git a/crates/gekko/src/flipper/gx/draw.rs b/crates/gekko/src/flipper/gx/draw.rs
index eeb40fe..f2b6a90 100644
--- a/crates/gekko/src/flipper/gx/draw.rs
+++ b/crates/gekko/src/flipper/gx/draw.rs
@@ -1,6 +1,4 @@
-use super::regs::{
- AlphaCompare, BlendMode, MagFilter, MinFilter, TevAlphaEnv, TevColorEnv, WrapMode, ZMode,
-};
+use super::regs::{AlphaCompare, BlendMode, MagFilter, MinFilter, TevAlphaEnv, TevColorEnv, WrapMode, ZMode};
use chapa::BitEnum;
#[derive(Debug)]
diff --git a/crates/gekko/src/flipper/gx/regs.rs b/crates/gekko/src/flipper/gx/regs.rs
index a372b42..4c8832a 100644
--- a/crates/gekko/src/flipper/gx/regs.rs
+++ b/crates/gekko/src/flipper/gx/regs.rs
@@ -298,10 +298,18 @@ impl VatA {
AttributeType::None => 0,
AttributeType::Direct => self.nrm_data_size(),
AttributeType::Index8 => {
- if self.nrm_index3() && self.nrm_cnt() == NrmCount::Nbt { 3 } else { 1 }
+ if self.nrm_index3() && self.nrm_cnt() == NrmCount::Nbt {
+ 3
+ } else {
+ 1
+ }
}
AttributeType::Index16 => {
- if self.nrm_index3() && self.nrm_cnt() == NrmCount::Nbt { 6 } else { 2 }
+ if self.nrm_index3() && self.nrm_cnt() == NrmCount::Nbt {
+ 6
+ } else {
+ 2
+ }
}
}
}
diff --git a/crates/gekko/src/flipper/si.rs b/crates/gekko/src/flipper/si.rs
index f0a6db8..4949392 100644
--- a/crates/gekko/src/flipper/si.rs
+++ b/crates/gekko/src/flipper/si.rs
@@ -52,11 +52,7 @@ impl Si {
|| (self.comcsr.rdst_interrupt() && self.comcsr.rdst_interrupt_mask())
}
- crate::impl_mmio_dispatch!(
- regs::SiPoll,
- regs::SiComcsr,
- regs::SiStatusRegister,
- );
+ crate::impl_mmio_dispatch!(regs::SiPoll, regs::SiComcsr, regs::SiStatusRegister,);
pub fn mmio_read_u32(&mut self, offset: u32) -> u32 {
match offset {
@@ -253,10 +249,7 @@ impl Si {
}
// Update RDST interrupt in COMCSR
- let any_rdst = self.status.rdst0()
- || self.status.rdst1()
- || self.status.rdst2()
- || self.status.rdst3();
+ let any_rdst = self.status.rdst0() || self.status.rdst1() || self.status.rdst2() || self.status.rdst3();
self.comcsr = self.comcsr.with_rdst_interrupt(any_rdst);
}
diff --git a/crates/gekko/src/flipper/si/regs.rs b/crates/gekko/src/flipper/si/regs.rs
index feaa874..738d08d 100644
--- a/crates/gekko/src/flipper/si/regs.rs
+++ b/crates/gekko/src/flipper/si/regs.rs
@@ -154,25 +154,57 @@ impl MmioAccess<Si> for SiStatusRegister {
fn write(self, si: &mut Si) {
let mut status = si.status;
- if self.norep0() { status = status.with_norep0(false); }
- if self.coll0() { status = status.with_coll0(false); }
- if self.ovrun0() { status = status.with_ovrun0(false); }
- if self.unrun0() { status = status.with_unrun0(false); }
-
- if self.norep1() { status = status.with_norep1(false); }
- if self.coll1() { status = status.with_coll1(false); }
- if self.ovrun1() { status = status.with_ovrun1(false); }
- if self.unrun1() { status = status.with_unrun1(false); }
-
- if self.norep2() { status = status.with_norep2(false); }
- if self.coll2() { status = status.with_coll2(false); }
- if self.ovrun2() { status = status.with_ovrun2(false); }
- if self.unrun2() { status = status.with_unrun2(false); }
-
- if self.norep3() { status = status.with_norep3(false); }
- if self.coll3() { status = status.with_coll3(false); }
- if self.ovrun3() { status = status.with_ovrun3(false); }
- if self.unrun3() { status = status.with_unrun3(false); }
+ if self.norep0() {
+ status = status.with_norep0(false);
+ }
+ if self.coll0() {
+ status = status.with_coll0(false);
+ }
+ if self.ovrun0() {
+ status = status.with_ovrun0(false);
+ }
+ if self.unrun0() {
+ status = status.with_unrun0(false);
+ }
+
+ if self.norep1() {
+ status = status.with_norep1(false);
+ }
+ if self.coll1() {
+ status = status.with_coll1(false);
+ }
+ if self.ovrun1() {
+ status = status.with_ovrun1(false);
+ }
+ if self.unrun1() {
+ status = status.with_unrun1(false);
+ }
+
+ if self.norep2() {
+ status = status.with_norep2(false);
+ }
+ if self.coll2() {
+ status = status.with_coll2(false);
+ }
+ if self.ovrun2() {
+ status = status.with_ovrun2(false);
+ }
+ if self.unrun2() {
+ status = status.with_unrun2(false);
+ }
+
+ if self.norep3() {
+ status = status.with_norep3(false);
+ }
+ if self.coll3() {
+ status = status.with_coll3(false);
+ }
+ if self.ovrun3() {
+ status = status.with_ovrun3(false);
+ }
+ if self.unrun3() {
+ status = status.with_unrun3(false);
+ }
if self.wr() {
si.status = status;
diff --git a/crates/gekko/src/gekko.rs b/crates/gekko/src/gekko.rs
index cc27e00..1942723 100644
--- a/crates/gekko/src/gekko.rs
+++ b/crates/gekko/src/gekko.rs
@@ -1,7 +1,18 @@
use crate::{
cpu::{self, Cpu, IPL_RESET_VECTOR, semantics::Instruction},
exi::{Exi, macronix::ExiMacronix},
- flipper::{ai::Ai, cp::Cp, di::Di, dsp::Dsp, gx::Gx, mi::Mi, pe::Pe, pi::Pi, si::{Si, pad}, vi::Vi},
+ flipper::{
+ ai::Ai,
+ cp::Cp,
+ di::Di,
+ dsp::Dsp,
+ gx::Gx,
+ mi::Mi,
+ pe::Pe,
+ pi::Pi,
+ si::{Si, pad},
+ vi::Vi,
+ },
idle::{IDLE_LOOP_MAX_INSTRS, IdleCheck, IdleDetector},
mmio::Mmio,
scheduler::{CYCLES_PER_VSYNC, EventKind, Scheduler},
diff --git a/crates/tinyapp/src/main.rs b/crates/tinyapp/src/main.rs
index 7020b90..d1acbe0 100644
--- a/crates/tinyapp/src/main.rs
+++ b/crates/tinyapp/src/main.rs
@@ -544,14 +544,14 @@ fn update_pad(pad: &mut PadStatus, key: KeyCode, pressed: bool) {
KeyCode::ArrowDown => pad.stick_y = if pressed { 0 } else { STICK_CENTER },
KeyCode::ArrowLeft => pad.stick_x = if pressed { 0 } else { STICK_CENTER },
KeyCode::ArrowRight => pad.stick_x = if pressed { 255 } else { STICK_CENTER },
-
+
// Face buttons
KeyCode::KeyX => set_button(&mut pad.buttons, pad::A, pressed),
KeyCode::KeyZ => set_button(&mut pad.buttons, pad::B, pressed),
KeyCode::KeyC => set_button(&mut pad.buttons, pad::X, pressed),
KeyCode::KeyV => set_button(&mut pad.buttons, pad::Y, pressed),
KeyCode::Enter => set_button(&mut pad.buttons, pad::START, pressed),
-
+
// Triggers
KeyCode::KeyA => {
set_button(&mut pad.buttons, pad::L, pressed);
@@ -562,13 +562,13 @@ fn update_pad(pad: &mut PadStatus, key: KeyCode, pressed: bool) {
pad.trigger_right = if pressed { 255 } else { 0 };
}
KeyCode::KeyD => set_button(&mut pad.buttons, pad::Z, pressed),
-
+
// D-pad
KeyCode::KeyI => set_button(&mut pad.buttons, pad::DPAD_UP, pressed),
KeyCode::KeyK => set_button(&mut pad.buttons, pad::DPAD_DOWN, pressed),
KeyCode::KeyJ => set_button(&mut pad.buttons, pad::DPAD_LEFT, pressed),
KeyCode::KeyL => set_button(&mut pad.buttons, pad::DPAD_RIGHT, pressed),
-
+
_ => {}
}
}