Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

better naming and debug logging. final tev config looks good for nehe gx lesson 2

Layle658d533660f1
diff --git a/crates/gekko/src/flipper/gx.rs b/crates/gekko/src/flipper/gx.rs
index 6231d7a..38ee2cb 100644
--- a/crates/gekko/src/flipper/gx.rs
+++ b/crates/gekko/src/flipper/gx.rs
@@ -15,8 +15,8 @@ use crate::{
},
draw::DrawCommands,
regs::{
- AlphaCompare, BlendMode, GenMode, TevColorEnv, TevRegType, TevRegisterH, TevRegisterL, TxSetImage0,
- TxSetImage3, VatA, VcdHi, VcdLo, ZMode,
+ AlphaCompare, BlendMode, GenMode, TevAlphaEnv, TevColorEnv, TevRegType, TevRegisterH, TevRegisterL,
+ TxSetImage0, TxSetImage3, VatA, VcdHi, VcdLo, ZMode,
},
},
gekko::Gekko,
@@ -367,11 +367,6 @@ impl Gx {
});
}
- // PE finish
- if idx == BP_PE_DONE && (val & BP_PE_DONE_FINISH_BIT) != 0 {
- self.raise_interrupt = true;
- }
-
// Forward PE render state to draw commands
match idx {
BP_PE_ZMODE => self.draw_commands.bp_zmode = ZMode::from_raw(val),
@@ -385,9 +380,35 @@ impl Gx {
if idx >= BP_TEV_COLOR_ENV_0 && idx < BP_TEV_COLOR_ENV_0 + 32 {
let stage = (idx - BP_TEV_COLOR_ENV_0) / 2;
if idx % 2 == 0 {
- self.draw_commands.tev_color_env[stage] = TevColorEnv::from_raw(val);
+ let env = TevColorEnv::from_raw(val);
+ tracing::debug!(
+ stage,
+ a = format!("{:?}", env.a()),
+ b = format!("{:?}", env.b()),
+ c = format!("{:?}", env.c()),
+ d = format!("{:?}", env.d()),
+ bias = format!("{:?}", env.bias()),
+ sub = env.sub(),
+ scale = format!("{:?}", env.scale()),
+ dest = format!("{:?}", env.dest()),
+ "TEV color env"
+ );
+ self.draw_commands.tev_color_env[stage] = env;
} else {
- self.draw_commands.tev_alpha_env[stage] = val;
+ let env = TevAlphaEnv::from_raw(val);
+ tracing::debug!(
+ stage,
+ a = format!("{:?}", env.a()),
+ b = format!("{:?}", env.b()),
+ c = format!("{:?}", env.c()),
+ d = format!("{:?}", env.d()),
+ bias = format!("{:?}", env.bias()),
+ sub = env.sub(),
+ scale = format!("{:?}", env.scale()),
+ dest = format!("{:?}", env.dest()),
+ "TEV alpha env"
+ );
+ self.draw_commands.tev_alpha_env[stage] = env;
}
}
@@ -401,12 +422,26 @@ impl Gx {
let reg_idx = (idx - BP_TEV_REGISTERL_0) / 2;
if idx % 2 == 0 {
let reg = TevRegisterL::from_raw(val);
+ tracing::debug!(
+ reg_idx,
+ r = reg.r(),
+ a = reg.a(),
+ reg_type = format!("{:?}", reg.reg_type()),
+ "TEV register lo"
+ );
match reg.reg_type() {
TevRegType::Color => self.draw_commands.tev_color_regs_lo[reg_idx] = reg,
TevRegType::Constant => self.draw_commands.tev_const_regs_lo[reg_idx] = reg,
}
} else {
let reg = TevRegisterH::from_raw(val);
+ tracing::debug!(
+ reg_idx,
+ g = reg.g(),
+ b = reg.b(),
+ reg_type = format!("{:?}", reg.reg_type()),
+ "TEV register hi"
+ );
match reg.reg_type() {
TevRegType::Color => self.draw_commands.tev_color_regs_hi[reg_idx] = reg,
TevRegType::Constant => self.draw_commands.tev_const_regs_hi[reg_idx] = reg,
@@ -417,7 +452,14 @@ impl Gx {
// GEN_MODE, extract num TEV stages
if idx == BP_GEN_MODE {
let gen_mode = GenMode::from_raw(val);
- self.draw_commands.num_tev_stages = gen_mode.num_tev_stages() + 1;
+ let stages = gen_mode.num_tev_stages() + 1;
+ tracing::debug!(num_tev_stages = stages, "GEN_MODE");
+ self.draw_commands.num_tev_stages = stages;
+ }
+
+ // PE finish
+ if idx == BP_PE_DONE && (val & BP_PE_DONE_FINISH_BIT) != 0 {
+ self.raise_interrupt = true;
}
}
diff --git a/crates/gekko/src/flipper/gx/draw.rs b/crates/gekko/src/flipper/gx/draw.rs
index 74ebd66..4366279 100644
--- a/crates/gekko/src/flipper/gx/draw.rs
+++ b/crates/gekko/src/flipper/gx/draw.rs
@@ -1,4 +1,4 @@
-use super::regs::{AlphaCompare, BlendMode, TevColorEnv, TevRegisterH, TevRegisterL, ZMode};
+use super::regs::{AlphaCompare, BlendMode, TevAlphaEnv, TevColorEnv, TevRegisterH, TevRegisterL, ZMode};
use chapa::BitEnum;
#[derive(Debug)]
@@ -102,7 +102,7 @@ pub struct DrawCommands {
// TEV state
pub tev_color_env: [TevColorEnv; 16],
- pub tev_alpha_env: [u32; 16],
+ pub tev_alpha_env: [TevAlphaEnv; 16],
// RGBA for each TEV register
pub tev_color_regs_lo: [TevRegisterL; 4],
diff --git a/crates/gekko/src/flipper/gx/regs.rs b/crates/gekko/src/flipper/gx/regs.rs
index 812c633..dec84f5 100644
--- a/crates/gekko/src/flipper/gx/regs.rs
+++ b/crates/gekko/src/flipper/gx/regs.rs
@@ -314,18 +314,18 @@ impl TxSetImage3 {
// TEV color combiner input select (SELA-SELD)
#[derive(Debug, PartialEq, BitEnum)]
pub enum TevColorIn {
- CPrev = 0x0,
- APrev = 0x1,
- C0 = 0x2,
- A0 = 0x3,
- C1 = 0x4,
- A1 = 0x5,
- C2 = 0x6,
- A2 = 0x7,
- TexC = 0x8,
- TexA = 0x9,
- RasC = 0xA,
- RasA = 0xB,
+ PrevColor = 0x0,
+ PrevAlpha = 0x1,
+ Reg0Color = 0x2,
+ Reg0Alpha = 0x3,
+ Reg1Color = 0x4,
+ Reg1Alpha = 0x5,
+ Reg2Color = 0x6,
+ Reg2Alpha = 0x7,
+ TexColor = 0x8,
+ TexAlpha = 0x9,
+ RasColor = 0xA,
+ RasAlpha = 0xB,
One = 0xC,
Half = 0xD,
Konst = 0xE,
@@ -388,6 +388,51 @@ pub struct TevColorEnv {
pub dest: TevRegId,
}
+// TEV alpha combiner input select (SELA-SELD)
+#[derive(Debug, PartialEq, BitEnum)]
+pub enum TevAlphaIn {
+ PrevAlpha = 0,
+ Reg0Alpha = 1,
+ Reg1Alpha = 2,
+ Reg2Alpha = 3,
+ TexAlpha = 4,
+ RasAlpha = 5,
+ Konst = 6,
+ Zero = 7,
+}
+
+// BP 0xC1+stage*2 TEV
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Debug, Clone, Copy, Default)]
+pub struct TevAlphaEnv {
+ #[bits(4..=6)]
+ pub d: TevAlphaIn,
+
+ #[bits(7..=9)]
+ pub c: TevAlphaIn,
+
+ #[bits(10..=12)]
+ pub b: TevAlphaIn,
+
+ #[bits(13..=15)]
+ pub a: TevAlphaIn,
+
+ #[bits(16..=17)]
+ pub bias: TevBias,
+
+ #[bits(18)]
+ pub sub: bool,
+
+ #[bits(19)]
+ pub clamp: bool,
+
+ #[bits(20..=21)]
+ pub scale: TevScale,
+
+ #[bits(22..=23)]
+ pub dest: TevRegId,
+}
+
// TEV color register type
#[derive(Debug, PartialEq, BitEnum)]
pub enum TevRegType {