Minor refactors and bug fixes
Some checks failed
Cargo Build & Test / Rust project - latest (stable) (push) Has been cancelled
Some checks failed
Cargo Build & Test / Rust project - latest (stable) (push) Has been cancelled
- Bit instruction now sets Z flag correctly - DMA is no longer handled by cpu.rs
This commit is contained in:
47
src/main.rs
47
src/main.rs
@@ -51,6 +51,7 @@ fn main() -> Result<(), iced::Error> {
|
||||
enum MemoryTy {
|
||||
Cpu,
|
||||
PPU,
|
||||
OAM,
|
||||
}
|
||||
|
||||
impl fmt::Display for MemoryTy {
|
||||
@@ -86,6 +87,7 @@ impl fmt::Display for HeaderButton {
|
||||
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::Memory(MemoryTy::OAM, _)) => write!(f, "Open OAM 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"),
|
||||
@@ -108,11 +110,11 @@ struct Emulator {
|
||||
#[derive(Debug, Clone)]
|
||||
enum Message {
|
||||
OpenRom(NES),
|
||||
Tick(usize),
|
||||
Frame,
|
||||
DMA,
|
||||
CPU,
|
||||
DebugInt,
|
||||
// Tick(usize),
|
||||
// Frame,
|
||||
// DMA,
|
||||
// CPU,
|
||||
// DebugInt,
|
||||
WindowClosed(Id),
|
||||
WindowOpened(Id),
|
||||
Header(HeaderButton),
|
||||
@@ -170,15 +172,15 @@ impl Emulator {
|
||||
|
||||
fn update(&mut self, message: Message) -> Task<Message> {
|
||||
match message {
|
||||
Message::Tick(count) => {
|
||||
for _ in 0..count {
|
||||
self.nes.run_one_clock_cycle();
|
||||
}
|
||||
}
|
||||
Message::Frame => while !self.nes.run_one_clock_cycle().ppu_frame {},
|
||||
Message::DMA => while !self.nes.run_one_clock_cycle().dma {},
|
||||
Message::CPU => while !self.nes.run_one_clock_cycle().cpu_exec {},
|
||||
Message::DebugInt => while !self.nes.run_one_clock_cycle().dbg_int {},
|
||||
// Message::Tick(count) => {
|
||||
// for _ in 0..count {
|
||||
// self.nes.run_one_clock_cycle();
|
||||
// }
|
||||
// }
|
||||
// Message::Frame => while !self.nes.run_one_clock_cycle().ppu_frame {},
|
||||
// Message::DMA => while !self.nes.run_one_clock_cycle().dma {},
|
||||
// Message::CPU => while !self.nes.run_one_clock_cycle().cpu_exec {},
|
||||
// Message::DebugInt => while !self.nes.run_one_clock_cycle().dbg_int {},
|
||||
Message::WindowClosed(id) => {
|
||||
if let Some(WindowType::Main) = self.windows.remove(&id) {
|
||||
return iced::exit();
|
||||
@@ -238,8 +240,13 @@ impl Emulator {
|
||||
}
|
||||
Message::Export(ty) => {
|
||||
let raw: Vec<_> = match ty {
|
||||
MemoryTy::Cpu => (0..=0xFFFF).map(|i| self.nes.mem().peek_cpu(i).unwrap_or(0)).collect(),
|
||||
MemoryTy::PPU => (0..=0xFFFF).map(|i| self.nes.mem().peek_ppu(i).unwrap_or(0)).collect(),
|
||||
MemoryTy::Cpu => (0..=0xFFFF)
|
||||
.map(|i| self.nes.mem().peek_cpu(i).unwrap_or(0))
|
||||
.collect(),
|
||||
MemoryTy::PPU => (0..=0xFFFF)
|
||||
.map(|i| self.nes.mem().peek_ppu(i).unwrap_or(0))
|
||||
.collect(),
|
||||
MemoryTy::OAM => (0..=0xFF).map(|i| self.nes.ppu().peek_oam(i)).collect(),
|
||||
};
|
||||
return Task::future(async move {
|
||||
if let Some(file) = rfd::AsyncFileDialog::new()
|
||||
@@ -290,10 +297,13 @@ impl Emulator {
|
||||
Some(WindowType::Memory(ty, view)) => {
|
||||
let hex = match ty {
|
||||
MemoryTy::Cpu => view
|
||||
.render(self.nes.mem(), false)
|
||||
.render_cpu(self.nes.mem())
|
||||
.map(move |e| Message::Hex(win, e)),
|
||||
MemoryTy::PPU => view
|
||||
.render(self.nes.mem(), true)
|
||||
.render_ppu(self.nes.mem())
|
||||
.map(move |e| Message::Hex(win, e)),
|
||||
MemoryTy::OAM => view
|
||||
.render_oam(self.nes.ppu())
|
||||
.map(move |e| Message::Hex(win, e)),
|
||||
};
|
||||
let content = column![row![header_menu("Export", [*ty], Message::Export)], hex]
|
||||
@@ -338,6 +348,7 @@ impl Emulator {
|
||||
HeaderButton::Open(WindowType::Debugger),
|
||||
HeaderButton::Open(WindowType::Memory(MemoryTy::Cpu, HexView {})),
|
||||
HeaderButton::Open(WindowType::Memory(MemoryTy::PPU, HexView {})),
|
||||
HeaderButton::Open(WindowType::Memory(MemoryTy::OAM, HexView {})),
|
||||
HeaderButton::Open(WindowType::TileMap),
|
||||
HeaderButton::Open(WindowType::TileViewer),
|
||||
HeaderButton::Open(WindowType::Palette),
|
||||
|
||||
Reference in New Issue
Block a user