Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

vi regs

Laylecf452aecab44
diff --git a/crates/gekko/src/lib.rs b/crates/gekko/src/lib.rs
index 32b1cd7..c426e49 100644
--- a/crates/gekko/src/lib.rs
+++ b/crates/gekko/src/lib.rs
@@ -4,25 +4,3 @@ pub mod gekko;
pub mod mmio;
pub mod vi;
-/// Generate `read_raw` and `write_raw` dispatch methods for a list of MMIO register types
-#[macro_export]
-macro_rules! impl_mmio_dispatch {
- ($($reg:ty),* $(,)?) => {
- #[inline]
- fn read_raw(&self, addr: u32, access_size: u32) -> Option<u32> {
- $(if <$reg>::fits(addr, access_size) {
- return Some(<$reg>::read_at(self, addr, access_size));
- })*
- None
- }
-
- #[inline]
- fn write_raw(&mut self, addr: u32, access_size: u32, val: u32) -> bool {
- $(if <$reg>::fits(addr, access_size) {
- <$reg>::write_at(self, addr, access_size, val);
- return true;
- })*
- false
- }
- };
-}
\ No newline at end of file
diff --git a/crates/gekko/src/mmio.rs b/crates/gekko/src/mmio.rs
index 08be590..ac1b939 100644
--- a/crates/gekko/src/mmio.rs
+++ b/crates/gekko/src/mmio.rs
@@ -2,6 +2,7 @@
mod tests;
pub mod constants;
+pub mod macros;
pub mod traits;
pub mod bus;
diff --git a/crates/gekko/src/mmio/macros.rs b/crates/gekko/src/mmio/macros.rs
new file mode 100644
index 0000000..7514525
--- /dev/null
+++ b/crates/gekko/src/mmio/macros.rs
@@ -0,0 +1,100 @@
+/// Generate `read_raw` and `write_raw` dispatch methods for a list of MMIO register types
+/// Inserts two methods into the enclosing `impl` block that iterate over the provided
+/// register types and delegate reads/writes to the appropriate `MmioAccess` impl
+#[macro_export]
+macro_rules! impl_mmio_dispatch {
+ ($($reg:ty),* $(,)?) => {
+ #[inline]
+ fn read_raw(&self, addr: u32, access_size: u32) -> Option<u32> {
+ $(if <$reg>::fits(addr, access_size) {
+ return Some(<$reg>::read_at(self, addr, access_size));
+ })*
+ None
+ }
+
+ #[inline]
+ fn write_raw(&mut self, addr: u32, access_size: u32, val: u32) -> bool {
+ $(if <$reg>::fits(addr, access_size) {
+ <$reg>::write_at(self, addr, access_size, val);
+ return true;
+ })*
+ false
+ }
+ };
+}
+
+/// Define a bitfield register struct, implement `MmioRegister`, and optionally
+/// implement `MmioAccess`
+///
+/// ```ignore
+/// mmio_register! {
+/// MyReg: u16 @ 0xCC001234 => MyDevice.my_field {
+/// #[bits(0..=7, alias = "val")] pub value: u8,
+/// }
+/// }
+/// ```
+///
+/// or
+///
+/// ```ignore
+/// mmio_register! {
+/// MyReg: u16 @ 0xCC001234 {
+/// #[bits(0..=7, alias = "val")] pub value: u8,
+/// }
+/// }
+///
+/// impl MmioAccess<MyDevice> for MyReg { ... }
+/// ```
+#[macro_export]
+macro_rules! mmio_register {
+ // Auto MmioAccess: Name: raw @ addr => Owner.field { ... }
+ (
+ $(#[$attr:meta])*
+ $name:ident : $raw:tt @ $addr:tt => $owner:tt . $field:ident {
+ $($body:tt)*
+ }
+ ) => {
+ #[rustfmt::skip]
+ #[chapa::bitfield($raw, order = lsb0)]
+ #[derive(Copy, Clone, Debug)]
+ $(#[$attr])*
+ pub struct $name {
+ $($body)*
+ }
+
+ impl $crate::mmio::traits::MmioRegister for $name {
+ const ADDR: u32 = $crate::mmio::Mmio::virt_to_phys($addr);
+ const SIZE: usize = ::core::mem::size_of::<$raw>();
+ fn from_raw(raw: u32) -> Self { (raw as $raw).into() }
+ fn to_raw(self) -> u32 { self.raw() as u32 }
+ }
+
+ impl $crate::mmio::traits::MmioAccess<$owner> for $name {
+ fn read(dev: &$owner) -> Self { dev.$field }
+ fn write(self, dev: &mut $owner) { dev.$field = self; }
+ }
+ };
+
+ // Manual MmioAccess: Name: raw @ addr { ... }
+ (
+ $(#[$attr:meta])*
+ $name:ident : $raw:tt @ $addr:tt {
+ $($body:tt)*
+ }
+ ) => {
+ #[rustfmt::skip]
+ #[chapa::bitfield($raw, order = lsb0)]
+ #[derive(Copy, Clone, Debug)]
+ $(#[$attr])*
+ pub struct $name {
+ $($body)*
+ }
+
+ impl $crate::mmio::traits::MmioRegister for $name {
+ const ADDR: u32 = $crate::mmio::Mmio::virt_to_phys($addr);
+ const SIZE: usize = ::core::mem::size_of::<$raw>();
+ fn from_raw(raw: u32) -> Self { (raw as $raw).into() }
+ fn to_raw(self) -> u32 { self.raw() as u32 }
+ }
+ };
+}
diff --git a/crates/gekko/src/vi.rs b/crates/gekko/src/vi.rs
index 5edc40a..470c406 100644
--- a/crates/gekko/src/vi.rs
+++ b/crates/gekko/src/vi.rs
@@ -1,6 +1,5 @@
#[cfg(test)]
mod tests;
-
pub mod regs;
use crate::{
@@ -10,67 +9,156 @@ use crate::{
};
pub struct Vi {
+ pub vtr: regs::VerticalTiming,
+ pub htr0: regs::HorizontalTiming0,
+ pub htr1: regs::HorizontalTiming1,
+ pub vto: regs::VerticalTimingOdd,
+ pub vte: regs::VerticalTimingEven,
pub dcr: regs::DisplayConfiguration,
- pub top_field_base: regs::TopFieldBase,
- pub bottom_field_base: regs::BottomFieldBase,
+ pub bbei: regs::BurstBlankingEvenInterval,
+ pub bboi: regs::BurstBlankingOddInterval,
+ pub tfbl: regs::TopFieldBase,
+ pub tfbr: regs::TopFieldBaseRight,
+ pub bfbl: regs::BottomFieldBase,
+ pub bfbr: regs::BottomFieldBaseRight,
+ pub dpv: regs::DisplayPositionVertical,
+ pub dph: regs::DisplayPositionHorizontal,
+ pub di0: regs::DisplayInterrupt0,
+ pub di1: regs::DisplayInterrupt1,
+ pub di2: regs::DisplayInterrupt2,
+ pub di3: regs::DisplayInterrupt3,
+ pub dl0: regs::DisplayLatch0,
+ pub dl1: regs::DisplayLatch1,
+ pub hsw: regs::HorizontalScalingWidth,
+ pub hsr: regs::HorizontalScalingRegister,
+ pub fct0: regs::FilterCoefficient0,
+ pub fct1: regs::FilterCoefficient1,
+ pub fct2: regs::FilterCoefficient2,
+ pub fct3: regs::FilterCoefficient3,
+ pub fct4: regs::FilterCoefficient4,
+ pub fct5: regs::FilterCoefficient5,
+ pub fct6: regs::FilterCoefficient6,
+ pub viclk: regs::ViClockSelect,
+ pub visel: regs::ViDtvStatus,
+ pub border_hbe: regs::BorderHbe,
+ pub border_hbs: regs::BorderHbs,
}
impl Vi {
pub fn new() -> Self {
Vi {
+ vtr: regs::VerticalTiming::from_raw(0),
+ htr0: regs::HorizontalTiming0::from_raw(0),
+ htr1: regs::HorizontalTiming1::from_raw(0),
+ vto: regs::VerticalTimingOdd::from_raw(0),
+ vte: regs::VerticalTimingEven::from_raw(0),
dcr: regs::DisplayConfiguration::from_raw(0),
- top_field_base: regs::TopFieldBase::from_raw(0),
- bottom_field_base: regs::BottomFieldBase::from_raw(0),
+ bbei: regs::BurstBlankingEvenInterval::from_raw(0),
+ bboi: regs::BurstBlankingOddInterval::from_raw(0),
+ tfbl: regs::TopFieldBase::from_raw(0),
+ tfbr: regs::TopFieldBaseRight::from_raw(0),
+ bfbl: regs::BottomFieldBase::from_raw(0),
+ bfbr: regs::BottomFieldBaseRight::from_raw(0),
+ dpv: regs::DisplayPositionVertical::from_raw(0),
+ dph: regs::DisplayPositionHorizontal::from_raw(0),
+ di0: regs::DisplayInterrupt0::from_raw(0),
+ di1: regs::DisplayInterrupt1::from_raw(0),
+ di2: regs::DisplayInterrupt2::from_raw(0),
+ di3: regs::DisplayInterrupt3::from_raw(0),
+ dl0: regs::DisplayLatch0::from_raw(0),
+ dl1: regs::DisplayLatch1::from_raw(0),
+ hsw: regs::HorizontalScalingWidth::from_raw(0),
+ hsr: regs::HorizontalScalingRegister::from_raw(0),
+ fct0: regs::FilterCoefficient0::from_raw(0),
+ fct1: regs::FilterCoefficient1::from_raw(0),
+ fct2: regs::FilterCoefficient2::from_raw(0),
+ fct3: regs::FilterCoefficient3::from_raw(0),
+ fct4: regs::FilterCoefficient4::from_raw(0),
+ fct5: regs::FilterCoefficient5::from_raw(0),
+ fct6: regs::FilterCoefficient6::from_raw(0),
+ viclk: regs::ViClockSelect::from_raw(0),
+ visel: regs::ViDtvStatus::from_raw(0),
+ border_hbe: regs::BorderHbe::from_raw(0),
+ border_hbs: regs::BorderHbs::from_raw(0),
}
}
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::BorderHbe,
+ regs::BorderHbs,
);
pub fn xfb_addr(&self) -> u32 {
- let top = self.top_field_base;
- (top.xfb_addr() << 9) | ((top.page_offset() as u32) << 24)
+ (self.tfbl.xfb_addr() << 9) | ((self.tfbl.page_offset() as u32) << 24)
}
pub fn mmio_read_u8(&self, offset: u32) -> u8 {
self.read_raw(VI_BASE + offset, 1).unwrap_or_else(|| {
- tracing::warn!(offset = format!("{offset:08X}"), "unhandled VI read_u8");
+ 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::warn!(offset = format!("{offset:#08X}"), "unhandled VI write_u8");
+ tracing::error!(offset = format!("{offset:#08X}"), "unhandled VI write_u8");
}
}
pub fn mmio_read_u16(&self, offset: u32) -> u16 {
self.read_raw(VI_BASE + offset, 2).unwrap_or_else(|| {
- tracing::warn!(offset = format!("{offset:#08X}"), "unhandled VI read_u16");
+ 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::warn!(offset = format!("{offset:#08X}"), "unhandled VI write_u16");
+ tracing::error!(offset = format!("{offset:#08X}"), "unhandled VI write_u16");
}
}
pub fn mmio_read_u32(&self, offset: u32) -> u32 {
self.read_raw(VI_BASE + offset, 4).unwrap_or_else(|| {
- tracing::warn!(offset = format!("{offset:#08X}"), "unhandled VI read_u32");
+ tracing::error!(offset = format!("{offset:#08X}"), "unhandled VI read_u32");
0
})
}
pub fn mmio_write_u32(&mut self, offset: u32, val: u32) {
if !self.write_raw(VI_BASE + offset, 4, val) {
- tracing::warn!(offset = format!("{offset:#08X}"), "unhandled VI write_u32");
+ tracing::error!(offset = format!("{offset:#08X}"), "unhandled VI write_u32");
}
}
}
diff --git a/crates/gekko/src/vi/regs.rs b/crates/gekko/src/vi/regs.rs
index be19c96..b2f9f42 100644
--- a/crates/gekko/src/vi/regs.rs
+++ b/crates/gekko/src/vi/regs.rs
@@ -1,10 +1,18 @@
use super::Vi;
-use crate::mmio::{
- Mmio,
- traits::{MmioAccess, MmioRegister},
-};
+use crate::mmio::traits::{MmioAccess, MmioRegister};
use chapa::BitEnum;
+// 0xCC002000 2 R/W VTR - Vertical Timing Register
+
+crate::mmio_register! {
+ VerticalTiming: u16 @ 0xCC002000 => Vi.vtr {
+ #[bits(0..=3, alias = "equ")] pub equalization_pulse: u8,
+ #[bits(4..=13, alias = "acv")] pub active_video: u16,
+ }
+}
+
+// 0xCC002002 2 R/W DCR - Display Configuration Register
+
#[derive(Debug, BitEnum)]
pub enum VideoFormat {
Ntsc = 0,
@@ -13,17 +21,16 @@ pub enum VideoFormat {
Debug = 3,
}
-#[rustfmt::skip]
-#[chapa::bitfield(u16, order = lsb0)]
-#[derive(Copy, Clone, Debug)]
-pub struct DisplayConfiguration {
- #[bits(0, alias = "enb")] pub enable: bool,
- #[bits(1, alias = "rst")] pub reset: bool,
- #[bits(2, alias = "nin")] pub interlace_selector: bool,
- #[bits(3, alias = "dlr")] pub display_mode_3d: bool,
- #[bits(4..=5, alias = "le0")] pub display_latch0: u8,
- #[bits(6..=7, alias = "le1")] pub display_latch1: u8,
- #[bits(8..=9, alias = "fmt")] pub video_format: VideoFormat,
+crate::mmio_register! {
+ DisplayConfiguration: u16 @ 0xCC002002 {
+ #[bits(0, alias = "enb")] pub enable: bool,
+ #[bits(1, alias = "rst")] pub reset: bool,
+ #[bits(2, alias = "nin")] pub interlace_selector: bool,
+ #[bits(3, alias = "dlr")] pub display_mode_3d: bool,
+ #[bits(4..=5, alias = "le0")] pub display_latch0: u8,
+ #[bits(6..=7, alias = "le1")] pub display_latch1: u8,
+ #[bits(8..=9, alias = "fmt")] pub video_format: VideoFormat,
+ }
}
impl MmioAccess<Vi> for DisplayConfiguration {
@@ -41,63 +48,311 @@ impl MmioAccess<Vi> for DisplayConfiguration {
}
}
-#[chapa::bitfield(u32, order = lsb0)]
-#[derive(Copy, Clone, Debug)]
-pub struct TopFieldBase {
- #[bits(9..=23, alias = "fbb")]
- pub xfb_addr: u32,
+// 0xCC002004 4 R/W HTR0 - Horizontal Timing 0
- #[bits(24..=27, alias = "xof")]
- pub horizontal_offset: u8,
+crate::mmio_register! {
+ HorizontalTiming0: u32 @ 0xCC002004 => Vi.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,
+ }
+}
- #[bits(28)]
- pub page_offset: bool,
- // TODO: 29-31 y always zero (maybe some write only control register stuff?, setting bit 31 clears bits 31-28 (?))
+// 0xCC002008 4 R/W HTR1 - Horizontal Timing 1
+
+crate::mmio_register! {
+ HorizontalTiming1: u32 @ 0xCC002008 => Vi.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,
+ }
}
-#[chapa::bitfield(u32, order = lsb0)]
-#[derive(Copy, Clone, Debug)]
-pub struct BottomFieldBase {
- #[bits(9..=23, alias = "fbb")]
- pub xfb_addr: u32,
+// 0xCC00200C 4 R/W VTO - Odd Field Vertical Timing Register
- #[bits(28)]
- pub page_offset: bool,
- // TODO: y always zero (maybe some write-only control register stuff?)
+crate::mmio_register! {
+ VerticalTimingOdd: u32 @ 0xCC00200C => Vi.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,
+ }
}
-#[rustfmt::skip]
-macro_rules! impl_mmio_access {
- ($reg:ty, $owner:ty, $field:ident) => {
- impl MmioAccess<$owner> for $reg {
- fn read(dev: &$owner) -> Self { dev.$field }
- fn write(self, dev: &mut $owner) { dev.$field = self; }
- }
- };
+// 0xCC002010 4 R/W VTE - Even Field Vertical Timing Register
+
+crate::mmio_register! {
+ VerticalTimingEven: u32 @ 0xCC002010 => Vi.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,
+ }
+}
+
+// 0xCC002014 4 R/W BBEI - Burst Blanking Even Interval
+
+crate::mmio_register! {
+ BurstBlankingEvenInterval: u32 @ 0xCC002014 => Vi.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,
+ #[bits(21..=31, alias = "be3")] pub burst_end_3: u16,
+ }
}
-#[rustfmt::skip]
-macro_rules! size_to_raw_type {
- (1, $raw:expr) => { $raw as u8 };
- (2, $raw:expr) => { $raw as u16 };
- (4, $raw:expr) => { $raw };
+// 0xCC002018 4 R/W BBOI - Burst Blanking Odd Interval
+
+crate::mmio_register! {
+ BurstBlankingOddInterval: u32 @ 0xCC002018 => Vi.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,
+ #[bits(21..=31, alias = "be4")] pub burst_end_4: u16,
+ }
}
-#[rustfmt::skip]
-macro_rules! impl_mmio_register {
- ($reg:ty, $addr:expr, $size:tt) => {
- impl MmioRegister for $reg {
- const ADDR: u32 = Mmio::virt_to_phys($addr);
- const SIZE: usize = $size;
- fn from_raw(raw: u32) -> Self { size_to_raw_type!($size, raw).into() }
- fn to_raw(self) -> u32 { self.raw() as u32 }
- }
- };
+// 0xCC00201c 4 R/W TFBL - Top Field Base Register (L) (External Framebuffer Half 1)
+
+crate::mmio_register! {
+ TopFieldBase: u32 @ 0xCC00201C => Vi.tfbl {
+ #[bits(9..=23, alias = "fbb")]
+ pub xfb_addr: u32,
+
+ #[bits(24..=27, alias = "xof")]
+ pub horizontal_offset: u8,
+
+ #[bits(28)]
+ pub page_offset: bool,
+ // TODO: 29-31 y always zero (maybe some write only control register stuff?, setting bit 31 clears bits 31-28 (?))
+ }
+}
+
+// 0xCC002020 4 R/W TFBR - Top Field Base Register (R)
+
+crate::mmio_register! {
+ TopFieldBaseRight: u32 @ 0xCC002020 => Vi.tfbr {
+ #[bits(9..=23, alias = "fbb")] pub xfb_addr: u32,
+ }
+}
+
+// 0xCC002024 4 R/W BFBL - Bottom Field Base Register (L) (External Framebuffer Half 2)
+
+crate::mmio_register! {
+ BottomFieldBase: u32 @ 0xCC002024 => Vi.bfbl {
+ #[bits(9..=23, alias = "fbb")]
+ pub xfb_addr: u32,
+
+ #[bits(28)]
+ pub page_offset: bool,
+ // TODO: y always zero (maybe some write-only control register stuff?)
+ }
+}
+
+// 0xCC002028 4 R/W BFBR - Bottom Field Base Register (R)
+
+crate::mmio_register! {
+ BottomFieldBaseRight: u32 @ 0xCC002028 => Vi.bfbr {
+ #[bits(9..=23, alias = "fbb")] pub xfb_addr: u32,
+ }
+}
+
+// 0xCC00202C 2 R DPV - Display Position Vertical
+
+crate::mmio_register! {
+ DisplayPositionVertical: u16 @ 0xCC00202C => Vi.dpv {
+ #[bits(0..=10, alias = "vct")] pub vertical_count: u16,
+ }
+}
+
+// 0xCC00202E 2 R DPH - Display Position Horizontal
+
+crate::mmio_register! {
+ DisplayPositionHorizontal: u16 @ 0xCC00202E => Vi.dph {
+ #[bits(0..=10, alias = "hct")] pub horizontal_count: u16,
+ }
+}
+
+// 0xCC002030 4 R/W DI0 - Display Interrupt 0
+
+crate::mmio_register! {
+ DisplayInterrupt0: u32 @ 0xCC002030 => Vi.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,
+ #[bits(31, alias = "int")] pub interrupt: bool,
+ }
+}
+
+// 0xCC002034 4 R/W DI1 - Display Interrupt 1
+
+crate::mmio_register! {
+ DisplayInterrupt1: u32 @ 0xCC002034 => Vi.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,
+ #[bits(31, alias = "int")] pub interrupt: bool,
+ }
+}
+
+// 0xCC002038 4 R/W DI2 - Display Interrupt 2
+
+crate::mmio_register! {
+ DisplayInterrupt2: u32 @ 0xCC002038 => Vi.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,
+ #[bits(31, alias = "int")] pub interrupt: bool,
+ }
+}
+
+// 0xCC00203C 4 R/W DI3 - Display Interrupt 3
+
+crate::mmio_register! {
+ DisplayInterrupt3: u32 @ 0xCC00203C => Vi.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,
+ #[bits(31, alias = "int")] pub interrupt: bool,
+ }
+}
+
+// 0xCC002040 4 R/W DL0 - Display Latch 0
+
+crate::mmio_register! {
+ DisplayLatch0: u32 @ 0xCC002040 => Vi.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,
+ }
+}
+
+// 0xCC002044 4 R/W DL1 - Display Latch 1
+
+crate::mmio_register! {
+ DisplayLatch1: u32 @ 0xCC002044 => Vi.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,
+ }
+}
+
+// 0xCC002048 2 R/W HSW - Horizontal Scaling Width
+
+crate::mmio_register! {
+ HorizontalScalingWidth: u16 @ 0xCC002048 => Vi.hsw {
+ #[bits(0..=9, alias = "srcwidth")] pub source_width: u16,
+ }
+}
+
+// 0xCC00204A 2 R/W HSR - Horizontal Scaling Register
+
+crate::mmio_register! {
+ HorizontalScalingRegister: u16 @ 0xCC00204A => Vi.hsr {
+ #[bits(0..=8, alias = "stp")] pub step_size: u16,
+ #[bits(12, alias = "hs_en")] pub horizontal_scaling_enable: bool,
+ }
+}
+
+// 0xCC00204C 4 R/W FCT0 - Filter Coefficient Table 0
+
+crate::mmio_register! {
+ FilterCoefficient0: u32 @ 0xCC00204C => Vi.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,
+ }
+}
+
+// 0xCC002050 4 R/W FCT1 - Filter Coefficient Table 1
+
+crate::mmio_register! {
+ FilterCoefficient1: u32 @ 0xCC002050 => Vi.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,
+ }
+}
+
+// 0xCC002054 4 R/W FCT2 - Filter Coefficient Table 2
+
+crate::mmio_register! {
+ FilterCoefficient2: u32 @ 0xCC002054 => Vi.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,
+ }
}
-impl_mmio_register!(DisplayConfiguration, 0xCC002002, 2);
-impl_mmio_register!(TopFieldBase, 0xCC00201C, 4);
-impl_mmio_register!(BottomFieldBase, 0xCC002024, 4);
+// 0xCC002058 4 R/W FCT3 - Filter Coefficient Table 3
-impl_mmio_access!(TopFieldBase, Vi, top_field_base);
-impl_mmio_access!(BottomFieldBase, Vi, bottom_field_base);
+crate::mmio_register! {
+ FilterCoefficient3: u32 @ 0xCC002058 => Vi.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,
+ #[bits(24..=31, alias = "t12")] pub tap12: u8,
+ }
+}
+
+// 0xCC00205C 4 R/W FCT4 - Filter Coefficient Table 4
+
+crate::mmio_register! {
+ FilterCoefficient4: u32 @ 0xCC00205C => Vi.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,
+ #[bits(24..=31, alias = "t16")] pub tap16: u8,
+ }
+}
+
+// 0xCC002060 4 R/W FCT5 - Filter Coefficient Table 5
+
+crate::mmio_register! {
+ FilterCoefficient5: u32 @ 0xCC002060 => Vi.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,
+ #[bits(24..=31, alias = "t20")] pub tap20: u8,
+ }
+}
+
+// 0xCC002064 4 R/W FCT6 - Filter Coefficient Table 6
+
+crate::mmio_register! {
+ FilterCoefficient6: u32 @ 0xCC002064 => Vi.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,
+ #[bits(24..=31, alias = "t24")] pub tap24: u8,
+ }
+}
+
+// 0xCC00206C 2 R/W VICLK - VI Clock Select
+
+crate::mmio_register! {
+ ViClockSelect: u16 @ 0xCC00206C => Vi.viclk {
+ #[bits(0, alias = "clk")] pub clock_select: bool,
+ }
+}
+
+// 0xCC00206E 2 R/W VISEL - VI DTV Status
+
+crate::mmio_register! {
+ ViDtvStatus: u16 @ 0xCC00206E => Vi.visel {
+ #[bits(2, alias = "visel")] pub dtv_status: bool,
+ }
+}
+
+// 0xCC002072 2 R/W BorderHBE - Border HBE
+
+crate::mmio_register! {
+ BorderHbe: u16 @ 0xCC002072 => Vi.border_hbe {
+ #[bits(0..=9, alias = "hbe656")] pub horizontal_blank_end_656: u16,
+ #[bits(15, alias = "brdr_en")] pub border_enable: bool,
+ }
+}
+
+// 0xCC002074 2 R/W BorderHBS - Border HBS
+
+crate::mmio_register! {
+ BorderHbs: u16 @ 0xCC002074 => Vi.border_hbs {
+ #[bits(0..=9, alias = "hbs656")] pub horizontal_blank_start_656: u16,
+ }
+}
diff --git a/crates/gekko/src/vi/tests.rs b/crates/gekko/src/vi/tests.rs
index 613a111..6115055 100644
--- a/crates/gekko/src/vi/tests.rs
+++ b/crates/gekko/src/vi/tests.rs
@@ -3,7 +3,7 @@ use crate::mmio::traits::MmioRegister;
fn vi_with_top(raw: u32) -> Vi {
let mut vi = Vi::new();
- vi.top_field_base = regs::TopFieldBase::from_raw(raw);
+ vi.tfbl = regs::TopFieldBase::from_raw(raw);
vi
}
@@ -20,14 +20,14 @@ const DCR_OFF: u32 = regs::DisplayConfiguration::ADDR - VI_BASE;
fn u16_write_upper_half_of_u32_register() {
let mut vi = vi_with_top(0xAABBCCDD);
vi.mmio_write_u16(TOP_OFF, 0x1234);
- assert_eq!(vi.top_field_base.to_raw(), 0x1234CCDD);
+ assert_eq!(vi.tfbl.to_raw(), 0x1234CCDD);
}
#[test]
fn u16_write_lower_half_of_u32_register() {
let mut vi = vi_with_top(0xAABBCCDD);
vi.mmio_write_u16(TOP_OFF + 2, 0x5678);
- assert_eq!(vi.top_field_base.to_raw(), 0xAABB5678);
+ assert_eq!(vi.tfbl.to_raw(), 0xAABB5678);
}
#[test]
@@ -49,14 +49,14 @@ fn u8_write_each_byte_of_u32_register() {
vi.mmio_write_u8(TOP_OFF + 1, 0xBB);
vi.mmio_write_u8(TOP_OFF + 2, 0xCC);
vi.mmio_write_u8(TOP_OFF + 3, 0xDD);
- assert_eq!(vi.top_field_base.to_raw(), 0xAABBCCDD);
+ assert_eq!(vi.tfbl.to_raw(), 0xAABBCCDD);
}
#[test]
fn u8_write_does_not_disturb_other_bytes_in_u32() {
let mut vi = vi_with_top(0xAABBCCDD);
vi.mmio_write_u8(TOP_OFF + 1, 0xFF);
- assert_eq!(vi.top_field_base.to_raw(), 0xAAFFCCDD);
+ assert_eq!(vi.tfbl.to_raw(), 0xAAFFCCDD);
}
#[test]
diff --git a/crates/tinyemu/src/main.rs b/crates/tinyemu/src/main.rs
index 62ae6a2..97d6a23 100644
--- a/crates/tinyemu/src/main.rs
+++ b/crates/tinyemu/src/main.rs
@@ -191,8 +191,8 @@ fn dump_memory(mmio: &gekko::mmio::Mmio, addr: u32) {
fn dump_mmio(vi: &gekko::vi::Vi) {
println!("Display Configuration: {:?}", vi.dcr);
- println!("Bottom Field Base: {:08X?}", vi.bottom_field_base);
- println!("Top Field Base: {:08X?}", vi.top_field_base);
+ println!("Bottom Field Base: {:08X?}", vi.bfbl);
+ println!("Top Field Base: {:08X?}", vi.tfbl);
println!("XFB Address: {:08X}", vi.xfb_addr());
}