Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

forgot to commit refactor

Layle321d8c1b9c3d
diff --git a/crates/gekko/src/flipper/gx/regs.rs b/crates/gekko/src/flipper/gx/regs.rs
index bcf547b..18641b1 100644
--- a/crates/gekko/src/flipper/gx/regs.rs
+++ b/crates/gekko/src/flipper/gx/regs.rs
@@ -1,24 +1,21 @@
-// CP 0x70
-#[chapa::bitfield(u32, order = lsb0)]
-#[derive(Debug, Clone, Copy)]
-pub struct VatA {
- #[bits(0)]
- pub pos_cnt: u8,
-
- #[bits(1..=3)]
- pub pos_fmt: u8,
-
- #[bits(4..=8)]
- pub pos_shift: u8,
-}
+use chapa::BitEnum;
-#[derive(Debug, Clone, Copy)]
+#[derive(Debug, PartialEq, BitEnum)]
pub enum PosCount {
Xy,
Xyz,
}
-#[derive(Debug, Clone, Copy)]
+impl PosCount {
+ pub fn components(&self) -> usize {
+ match self {
+ PosCount::Xy => 2,
+ PosCount::Xyz => 3,
+ }
+ }
+}
+
+#[derive(Debug, PartialEq, BitEnum)]
pub enum ComponentFormat {
U8,
S8,
@@ -37,72 +34,37 @@ impl ComponentFormat {
}
}
-impl VatA {
- pub fn pos_count(&self) -> PosCount {
- match self.pos_cnt() {
- 0 => PosCount::Xy,
- 1 => PosCount::Xyz,
- _ => unreachable!(),
- }
- }
-
- pub fn pos_format(&self) -> ComponentFormat {
- match self.pos_fmt() {
- 0 => ComponentFormat::U8,
- 1 => ComponentFormat::S8,
- 2 => ComponentFormat::U16,
- 3 => ComponentFormat::S16,
- 4 => ComponentFormat::F32,
- _ => unreachable!(),
- }
- }
-
- pub fn pos_components(&self) -> usize {
- match self.pos_count() {
- PosCount::Xy => 2,
- PosCount::Xyz => 3,
- }
- }
-
- pub fn pos_data_size(&self) -> usize {
- self.pos_components() * self.pos_format().size()
- }
+#[derive(Debug, PartialEq, BitEnum)]
+pub enum ColorCount {
+ Rgb,
+ Rgba,
}
-// CP 0x50
-#[chapa::bitfield(u32, order = lsb0)]
-#[derive(Debug, Clone, Copy)]
-pub struct VcdLo {
- #[bits(9..=10)]
- pub position: u8,
-
- #[bits(13..=14)]
- pub color0: u8,
+#[derive(Debug, PartialEq, BitEnum)]
+pub enum ColorFormat {
+ Rgb565,
+ Rgb8,
+ Rgbx8,
+ Rgba4,
+ Rgba6,
+ Rgba8,
}
-impl VcdLo {
- pub fn pos_attr(&self) -> AttributeType {
- match self.position() {
- 0 => AttributeType::None,
- 1 => AttributeType::Direct,
- 2 => AttributeType::Index8,
- 3 => AttributeType::Index16,
- _ => unreachable!(),
- }
- }
-
- pub fn color0_attr(&self) -> AttributeType {
- match self.color0() {
- 0 => AttributeType::None,
- 1 => AttributeType::Direct,
- 2 => AttributeType::Index8,
- 3 => AttributeType::Index16,
- _ => unreachable!(),
+impl ColorFormat {
+ pub fn data_size(&self, count: ColorCount) -> usize {
+ match (self, count) {
+ (ColorFormat::Rgb565, _) => 2,
+ (ColorFormat::Rgb8, _) => 3,
+ (ColorFormat::Rgbx8, _) => 4,
+ (ColorFormat::Rgba4, _) => 2,
+ (ColorFormat::Rgba6, _) => 3,
+ (ColorFormat::Rgba8, ColorCount::Rgb) => 3,
+ (ColorFormat::Rgba8, ColorCount::Rgba) => 4,
}
}
}
-#[derive(Debug)]
+#[derive(Debug, PartialEq, BitEnum)]
pub enum AttributeType {
None,
Direct,
@@ -120,3 +82,44 @@ impl AttributeType {
}
}
}
+
+// CP 0x70-0x77 (one per vertex format)
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Debug, Clone, Copy)]
+pub struct VatA {
+ #[bits(0)]
+ pub pos_cnt: PosCount,
+
+ #[bits(1..=3)]
+ pub pos_fmt: ComponentFormat,
+
+ #[bits(4..=8)]
+ pub pos_shift: u8,
+
+ #[bits(13)]
+ pub clr0_cnt: ColorCount,
+
+ #[bits(14..=16)]
+ pub clr0_fmt: ColorFormat,
+}
+
+impl VatA {
+ pub fn pos_data_size(&self) -> usize {
+ self.pos_cnt().components() * self.pos_fmt().size()
+ }
+
+ pub fn clr0_data_size(&self) -> usize {
+ self.clr0_fmt().data_size(self.clr0_cnt())
+ }
+}
+
+// CP 0x50
+#[chapa::bitfield(u32, order = lsb0)]
+#[derive(Debug, Clone, Copy)]
+pub struct VcdLo {
+ #[bits(9..=10)]
+ pub position: AttributeType,
+
+ #[bits(13..=14)]
+ pub color0: AttributeType,
+}
\ No newline at end of file