Major refactor
- CPU is now it's own module - Memory object is now shared to support mapper chips - ROM is now stored as `Arc<[u8]>` to support mapper chips
This commit is contained in:
@@ -3,7 +3,7 @@ use std::rc::Rc;
|
||||
use iced::{
|
||||
Element,
|
||||
Length::{self, Fill},
|
||||
Point, Renderer, Size, Theme,
|
||||
Point, Renderer, Size,
|
||||
advanced::{
|
||||
Widget,
|
||||
layout::Node,
|
||||
@@ -18,14 +18,13 @@ use iced::{
|
||||
canvas::{Frame, Program},
|
||||
checkbox, column,
|
||||
container::bordered_box,
|
||||
image, number_input, hex_input, row,
|
||||
hex_input, image, number_input, row,
|
||||
rule::horizontal,
|
||||
scrollable, text,
|
||||
},
|
||||
window::Event,
|
||||
};
|
||||
|
||||
use crate::{CycleResult, NES, PPU};
|
||||
use crate::{CycleResult, NES, PPU, mem::Mapped};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DebuggerState {
|
||||
@@ -117,7 +116,7 @@ impl DebuggerState {
|
||||
labelled("X:", text(format!("{:02X}", nes.cpu.x))),
|
||||
labelled("Y:", text(format!("{:02X}", nes.cpu.y))),
|
||||
labelled("PC:", text(format!("{:04X}", nes.cpu.pc))),
|
||||
labelled("Cycle:", text(format!("{}", nes.cycle))),
|
||||
labelled("Cycle:", text(format!("{}", nes.cpu_cycle()))),
|
||||
labelled("SP:", text(format!("{:02X}", nes.cpu.sp))),
|
||||
]
|
||||
.spacing(5.),
|
||||
@@ -255,7 +254,7 @@ impl DebuggerState {
|
||||
|
||||
fn run_n_clock_cycles(nes: &mut NES, n: usize) {
|
||||
for _ in 0..n {
|
||||
if nes.run_one_clock_cycle().dbg_int || nes.halted {
|
||||
if nes.run_one_clock_cycle().dbg_int || nes.halted() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -269,7 +268,7 @@ impl DebuggerState {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if nes.halted {
|
||||
if nes.halted() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -294,8 +293,10 @@ impl DebuggerState {
|
||||
Self::run_until(nes, |_, n| n.ppu.scanline == self.to_scan_line, 1)
|
||||
}
|
||||
DebuggerMessage::RunFrames => Self::run_n_clock_cycles(nes, self.frames * 341 * 262),
|
||||
DebuggerMessage::RunBreakpoint => Self::run_until(nes, |_, nes| nes.cpu.pc as usize == self.breakpoint, 1),
|
||||
DebuggerMessage::Run => Self::run_until(nes, |_, nes| nes.halted, 1),
|
||||
DebuggerMessage::RunBreakpoint => {
|
||||
Self::run_until(nes, |_, nes| nes.cpu.pc as usize == self.breakpoint, 1)
|
||||
}
|
||||
DebuggerMessage::Run => Self::run_until(nes, |_, nes| nes.halted(), 1),
|
||||
DebuggerMessage::Pause => todo!(),
|
||||
}
|
||||
}
|
||||
@@ -366,9 +367,9 @@ pub fn labelled_box<'a, Message: 'a>(label: &'a str, value: bool) -> Element<'a,
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub enum DbgImage<'a> {
|
||||
NameTable(&'a PPU),
|
||||
PatternTable(&'a PPU),
|
||||
Palette(&'a PPU),
|
||||
NameTable(&'a Mapped, &'a PPU),
|
||||
PatternTable(&'a Mapped, &'a PPU),
|
||||
Palette(&'a Mapped, &'a PPU),
|
||||
}
|
||||
|
||||
impl<Message, T> Program<Message, T> for DbgImage<'_> {
|
||||
@@ -388,9 +389,11 @@ impl<Message, T> Program<Message, T> for DbgImage<'_> {
|
||||
name_table_frame.scale(2.);
|
||||
// println!("Position: {:?}", cursor.position());
|
||||
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),
|
||||
DbgImage::NameTable(mem, ppu) => ppu.render_name_table(mem, &mut name_table_frame),
|
||||
DbgImage::PatternTable(mem, ppu) => {
|
||||
ppu.render_pattern_tables(mem, &mut name_table_frame)
|
||||
}
|
||||
DbgImage::Palette(_, ppu) => ppu.render_palette(&mut name_table_frame),
|
||||
};
|
||||
vec![name_table_frame.into_geometry()]
|
||||
}
|
||||
@@ -399,23 +402,23 @@ impl<Message, T> Program<Message, T> for DbgImage<'_> {
|
||||
impl DbgImage<'_> {
|
||||
fn width(&self) -> Length {
|
||||
match self {
|
||||
DbgImage::NameTable(_) => Length::Fixed(512. * 2.),
|
||||
DbgImage::PatternTable(_) => Length::Fixed(16. * 8. * 2.),
|
||||
DbgImage::Palette(_) => Length::Fixed(40. * 2.),
|
||||
DbgImage::NameTable(_, _) => Length::Fixed(512. * 2.),
|
||||
DbgImage::PatternTable(_, _) => Length::Fixed(16. * 8. * 2.),
|
||||
DbgImage::Palette(_, _) => Length::Fixed(40. * 2.),
|
||||
}
|
||||
}
|
||||
fn height(&self) -> Length {
|
||||
match self {
|
||||
DbgImage::NameTable(_) => Length::Fixed(512. * 2.),
|
||||
DbgImage::PatternTable(_) => Length::Fixed(16. * 8. * 2. * 2.),
|
||||
DbgImage::Palette(_) => Length::Fixed(80. * 2.),
|
||||
DbgImage::NameTable(_, _) => Length::Fixed(512. * 2.),
|
||||
DbgImage::PatternTable(_, _) => Length::Fixed(16. * 8. * 2. * 2.),
|
||||
DbgImage::Palette(_, _) => Length::Fixed(80. * 2.),
|
||||
}
|
||||
}
|
||||
fn help(&self, cursor: Point) -> Option<String> {
|
||||
match self {
|
||||
DbgImage::NameTable(ppu) => ppu.name_cursor_info(cursor),
|
||||
DbgImage::PatternTable(ppu) => ppu.pattern_cursor_info(cursor),
|
||||
DbgImage::Palette(ppu) => ppu.palette_cursor_info(cursor),
|
||||
DbgImage::NameTable(mem, ppu) => ppu.name_cursor_info(mem, cursor),
|
||||
DbgImage::PatternTable(_, ppu) => ppu.pattern_cursor_info(cursor),
|
||||
DbgImage::Palette(_, ppu) => ppu.palette_cursor_info(cursor),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user