Major work
Some checks failed
Cargo Build & Test / Rust project - latest (stable) (push) Failing after 10s

This commit is contained in:
2026-01-19 01:36:58 -06:00
parent c535e4e76d
commit cd3de5e361
34 changed files with 1750 additions and 606 deletions

View File

@@ -3,17 +3,17 @@ use std::{collections::HashMap, fmt, time::Duration};
use iced::{
Color, Element, Font,
Length::{Fill, Shrink},
Point, Renderer, Size, Subscription, Task, Theme, mouse,
Point, Rectangle, Renderer, Size, Subscription, Task, Theme, mouse,
widget::{
Canvas, button,
Action, Canvas, button,
canvas::{Frame, Program},
column, container, row, text,
column, container, mouse_area, row, text,
},
window::{self, Id, Settings},
};
use nes_emu::{
NES, PPU,
debugger::{DebuggerMessage, DebuggerState},
debugger::{DbgImage, DebuggerMessage, DebuggerState, dbg_image},
header_menu::header_menu,
hex_view::{HexEvent, HexView},
resize_watcher::resize_watcher,
@@ -22,8 +22,12 @@ use tokio::runtime::Runtime;
use tracing_subscriber::EnvFilter;
// const ROM_FILE: &str = concat!(env!("ROM_DIR"), "/", "even_odd.nes");
const ROM_FILE: &str = concat!(env!("ROM_DIR"), "/", "crc_check.nes");
// const ROM_FILE: &str = "./Super Mario Bros. (World).nes";
// const ROM_FILE: &str = concat!(env!("ROM_DIR"), "/", "crc_check.nes");
// const ROM_FILE: &str = concat!(env!("ROM_DIR"), "/", "ppu_fill_red.nes");
// const ROM_FILE: &str = concat!(env!("ROM_DIR"), "/", "ppu_fill_name_table.nes");
// const ROM_FILE: &str = concat!(env!("ROM_DIR"), "/", "int_nmi_exit_timing.nes");
const ROM_FILE: &str = "./Super Mario Bros. (World).nes";
// const ROM_FILE: &str = "./cpu_timing_test.nes";
extern crate nes_emu;
@@ -43,6 +47,7 @@ fn main() -> Result<(), iced::Error> {
#[derive(Debug, Clone, PartialEq, Eq)]
enum MemoryTy {
Cpu,
PPU,
}
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -70,6 +75,7 @@ impl fmt::Display for HeaderButton {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Open(WindowType::Memory(MemoryTy::Cpu, _)) => write!(f, "Open Memory Viewer"),
Self::Open(WindowType::Memory(MemoryTy::PPU, _)) => write!(f, "Open PPU Memory Viewer"),
Self::Open(WindowType::TileMap) => write!(f, "Open TileMap Viewer"),
Self::Open(WindowType::TileViewer) => write!(f, "Open Tile Viewer"),
Self::Open(WindowType::Debugger) => write!(f, "Open Debugger"),
@@ -96,6 +102,7 @@ enum Message {
CPU,
DebugInt,
WindowClosed(Id),
WindowOpened(Id),
Header(HeaderButton),
Hex(Id, HexEvent),
Debugger(DebuggerMessage),
@@ -106,6 +113,16 @@ impl Emulator {
fn new() -> (Self, Task<Message>) {
let mut nes = nes_emu::NES::load_nes_file(ROM_FILE).expect("Failed to load nes file");
nes.reset();
// TODO: remove
// let mut count = 10;
// while !nes.halted() {
// if nes.run_one_clock_cycle().ppu_frame {
// count -= 1;
// if count <= 0 {
// break;
// }
// }
// }
let (win, task) = iced::window::open(Settings {
min_size: None,
..Settings::default()
@@ -154,6 +171,12 @@ impl Emulator {
return iced::exit();
}
}
Message::WindowOpened(_id) => {
// if let Some(WindowType::Main) = self.windows.get(&id) {
// // println!("Running resize");
// return iced::window::resize(id, self.main_win_size);
// }
}
Message::Header(HeaderButton::Open(w)) => {
return self.open(w);
}
@@ -188,8 +211,7 @@ impl Emulator {
fn subscriptions(&self) -> Subscription<Message> {
Subscription::batch([
window::close_events().map(Message::WindowClosed),
// window::events().map(Message::Window),
// window::resize_events().map(Message::WindowResized),
window::open_events().map(Message::WindowOpened),
])
}
@@ -214,26 +236,18 @@ impl Emulator {
MemoryTy::Cpu => view
.render(self.nes.cpu_mem())
.map(move |e| Message::Hex(win, e)),
MemoryTy::PPU => view
.render(self.nes.ppu().mem())
.map(move |e| Message::Hex(win, e)),
};
let content = column![hex].width(Fill).height(Fill);
container(content).width(Fill).height(Fill).into()
}
Some(WindowType::TileMap) => {
container(Canvas::new(DbgImage::NameTable(self.nes.ppu())))
.width(Fill)
.height(Fill)
.into()
}
Some(WindowType::TileMap) => dbg_image(DbgImage::NameTable(self.nes.ppu())).into(),
Some(WindowType::TileViewer) => {
container(Canvas::new(DbgImage::PatternTable(self.nes.ppu())))
.width(Fill)
.height(Fill)
.into()
dbg_image(DbgImage::PatternTable(self.nes.ppu())).into()
}
Some(WindowType::Palette) => container(Canvas::new(DbgImage::Palette(self.nes.ppu())))
.width(Fill)
.height(Fill)
.into(),
Some(WindowType::Palette) => dbg_image(DbgImage::Palette(self.nes.ppu())).into(),
Some(WindowType::Debugger) => {
container(self.debugger.view(&self.nes).map(Message::Debugger))
.width(Fill)
@@ -257,6 +271,7 @@ impl Emulator {
[
HeaderButton::Open(WindowType::Debugger),
HeaderButton::Open(WindowType::Memory(MemoryTy::Cpu, HexView {})),
HeaderButton::Open(WindowType::Memory(MemoryTy::PPU, HexView {})),
HeaderButton::Open(WindowType::TileMap),
HeaderButton::Open(WindowType::TileViewer),
HeaderButton::Open(WindowType::Palette),
@@ -302,33 +317,3 @@ impl Program<Message> for Emulator {
vec![frame.into_geometry()]
}
}
enum DbgImage<'a> {
NameTable(&'a PPU),
PatternTable(&'a PPU),
Palette(&'a PPU),
}
impl Program<Message> for DbgImage<'_> {
type State = ();
fn draw(
&self,
_state: &Self::State,
renderer: &Renderer,
_theme: &Theme,
_bounds: iced::Rectangle,
_cursor: mouse::Cursor,
) -> Vec<iced::widget::canvas::Geometry<Renderer>> {
// const SIZE: f32 = 2.;
let mut name_table_frame =
Frame::new(renderer, Size::new(256. * 4. + 260. * 2., 256. * 4.));
name_table_frame.scale(2.);
match self {
DbgImage::NameTable(ppu) => ppu.render_name_table(&mut name_table_frame),
DbgImage::PatternTable(ppu) => ppu.render_pattern_tables(&mut name_table_frame),
DbgImage::Palette(ppu) => ppu.render_palette(&mut name_table_frame),
}
vec![name_table_frame.into_geometry()]
}
}