Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

use videoformat for resolution

Layle436e9686494c
diff --git a/crates/gekko/src/vi.rs b/crates/gekko/src/vi.rs
index 470c406..1cc8f03 100644
--- a/crates/gekko/src/vi.rs
+++ b/crates/gekko/src/vi.rs
@@ -163,13 +163,14 @@ impl Vi {
}
}
-pub const XFB_WIDTH: usize = 640;
-pub const XFB_HEIGHT: usize = 574;
-
impl Gekko {
#[rustfmt::skip]
pub fn render_xfb(&self) -> Vec<u32> {
- let mut pixels = vec![0u32; XFB_WIDTH * XFB_HEIGHT];
+ let video_format = self.vi.dcr.video_format();
+ let width = video_format.columns();
+ let height = video_format.lines();
+
+ let mut pixels = vec![0u32; width * height];
let xfb_addr = self.vi.xfb_addr();
// XFB is YUY2 (YCbCr 4:2:2): each 32-bit word = [Y0][Cb][Y1][Cr] (big-endian)
@@ -181,7 +182,7 @@ impl Gekko {
((r as u32) << 16) | ((g as u32) << 8) | (b as u32)
};
- for i in 0..(XFB_WIDTH * XFB_HEIGHT / 2) {
+ for i in 0..(width * height / 2) {
let word = self.mmio.phys_read_u32(xfb_addr + (i as u32) * 4);
let y0 = ((word >> 24) & 0xFF) as f32 - 16.0;
let cb = ((word >> 16) & 0xFF) as f32 - 128.0;
diff --git a/crates/gekko/src/vi/regs.rs b/crates/gekko/src/vi/regs.rs
index b2f9f42..c246f45 100644
--- a/crates/gekko/src/vi/regs.rs
+++ b/crates/gekko/src/vi/regs.rs
@@ -13,6 +13,11 @@ crate::mmio_register! {
// 0xCC002002 2 R/W DCR - Display Configuration Register
+pub enum RefreshRate {
+ Hz60,
+ Hz50,
+}
+
#[derive(Debug, BitEnum)]
pub enum VideoFormat {
Ntsc = 0,
@@ -21,6 +26,26 @@ pub enum VideoFormat {
Debug = 3,
}
+impl VideoFormat {
+ pub fn refresh_rate(&self) -> RefreshRate {
+ match self {
+ VideoFormat::Ntsc | VideoFormat::Mpal => RefreshRate::Hz60,
+ VideoFormat::Pal | VideoFormat::Debug => RefreshRate::Hz50,
+ }
+ }
+
+ pub fn lines(&self) -> usize {
+ match self {
+ VideoFormat::Ntsc | VideoFormat::Mpal => 480,
+ VideoFormat::Pal | VideoFormat::Debug => 574,
+ }
+ }
+
+ pub fn columns(&self) -> usize {
+ 640
+ }
+}
+
crate::mmio_register! {
DisplayConfiguration: u16 @ 0xCC002002 {
#[bits(0, alias = "enb")] pub enable: bool,
diff --git a/crates/tinyemu/src/main.rs b/crates/tinyemu/src/main.rs
index 97d6a23..c1dcd5e 100644
--- a/crates/tinyemu/src/main.rs
+++ b/crates/tinyemu/src/main.rs
@@ -4,7 +4,6 @@ mod snaptshot;
use base64::Engine as _;
use colored::Colorize;
use disasm::gekko::GekkoInstruction;
-use gekko::vi;
use snaptshot::CpuSnapshot;
fn main() {
@@ -98,7 +97,8 @@ fn main() {
println!("Render current XFB:");
let pixels = gekko.render_xfb();
- render_kitty(&pixels, vi::XFB_WIDTH, vi::XFB_HEIGHT);
+ let video_format = gekko.vi.dcr.video_format();
+ render_kitty(&pixels, video_format.columns(), video_format.lines());
}
fn dump_registers(curr: &CpuSnapshot, prev: &CpuSnapshot) {