backup
This commit is contained in:
+12
-6
@@ -12,14 +12,18 @@ pub struct NesBus {
|
||||
cart: Cartridge,
|
||||
ppu: Ppu,
|
||||
openbus: u8, // last byte on the CPU data bus
|
||||
controller: Controller,
|
||||
controller: Controller, // P1 ($4016)
|
||||
controller2: Controller, // P2 ($4017) - no controller plugged in for now
|
||||
}
|
||||
|
||||
impl NesBus {
|
||||
pub fn new(cart: Cartridge) -> Self {
|
||||
Self { ram: [0; 0x800],
|
||||
cart, ppu: Ppu::new(),
|
||||
openbus: 0, controller: Controller::new(Box::new(MaskInput::new())), }
|
||||
Self {
|
||||
ram: [0; 0x800],
|
||||
cart, ppu: Ppu::new(), openbus: 0,
|
||||
controller: Controller::new(Box::new(MaskInput::new())),
|
||||
controller2: Controller::new(Box::new(MaskInput::new())), // reads 0 forever
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tick_ppu(&mut self, cycles: u64) {
|
||||
@@ -48,7 +52,8 @@ impl Bus for NesBus {
|
||||
let result = match address {
|
||||
0x0000..=0x1FFF => self.ram[(address & 0x07FF) as usize], // Zero-Page my beloved
|
||||
0x2000..=0x3FFF => self.ppu.read(&mut self.cart, address, self.openbus),
|
||||
0x4016 | 0x4017 => self.controller.read(),
|
||||
0x4016 => self.controller.read(),
|
||||
0x4017 => self.controller2.read(),
|
||||
0x4000..=0x401F => self.openbus, // APU regs: unmapped reads return bus contents
|
||||
0x4020..=0x5FFF => self.openbus, // expansion: open bus
|
||||
0x6000..=0x7FFF => self.cart.read_prg_ram(address), // SRAM reads from the cartridge
|
||||
@@ -63,7 +68,8 @@ impl Bus for NesBus {
|
||||
0x0000..=0x1FFF => self.ram[(address & 0x07FF) as usize] = value,
|
||||
0x2000..=0x3FFF => self.ppu.write(&mut self.cart, address, value),
|
||||
0x4014 => self.ppu.oam_dma(&self.ram, value),
|
||||
0x4016 | 0x4017 => self.controller.write_strobe(value),
|
||||
0x4016 => self.controller.write_strobe(value),
|
||||
0x4017 => self.controller2.write_strobe(value),
|
||||
0x6000..=0x7FFF => self.cart.write_prg_ram(address, value),
|
||||
0x8000..=0xFFFF => self.cart.write_prg(address, value),
|
||||
_ => {} // Everything else dropped for now
|
||||
|
||||
+4
-3
@@ -122,10 +122,11 @@ impl GuiApp {
|
||||
impl eframe::App for GuiApp {
|
||||
// Non-UI work: emulation runs here, before painting.
|
||||
fn logic(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
self.renderer.poll_input(self.bus.controller_mut()); // keyboard -> $4016/$4017
|
||||
run_one_frame(&mut self.bus, &mut self.cpu); // one emulated frame
|
||||
self.renderer.poll_input(self.bus.controller_mut());
|
||||
run_one_frame(&mut self.bus, &mut self.cpu);
|
||||
self.renderer.present(self.bus.framebuffer(), 256, 240);
|
||||
ctx.request_repaint(); // keep it running at 60fps
|
||||
// cap at 60fps: one emulated frame per 16.67ms, not "as fast as possible"
|
||||
ctx.request_repaint_after(std::time::Duration::from_millis(16));
|
||||
}
|
||||
|
||||
// Painting: draw the framebuffer texture.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::cartridge::Cartridge;
|
||||
use crate::mapper::Mirroring;
|
||||
|
||||
|
||||
// 4-byte OAM entry: Y, tile, attribute, X
|
||||
#[derive(Clone, Copy, Default)]
|
||||
struct Sprite {
|
||||
|
||||
Reference in New Issue
Block a user