cleanup
This commit is contained in:
parent
6eaca33523
commit
e6e36d9391
|
@ -105,7 +105,6 @@ impl Apu {
|
|||
}
|
||||
|
||||
pub fn write_reg(&mut self, address: usize, value: u8) {
|
||||
// println!("writing 0b{:08b} to 0x{:X}", value, address);
|
||||
match address {
|
||||
0x4000 => self.square1.write_duty(value),
|
||||
0x4001 => self.square1.write_sweep(value),
|
||||
|
|
|
@ -10,8 +10,6 @@ pub struct Mmc1 {
|
|||
prg_ram_bank: Vec<u8>, // CPU $6000-$7FFF
|
||||
prg_ram_enabled: bool,
|
||||
|
||||
prg_low_bank: usize, // CPU $8000-$BFFF
|
||||
prg_high_bank: usize, // CPU $C000-$FFFF
|
||||
prg_bank_mode: u8,
|
||||
prg_bank_select: usize, // selects among the PRG-RAM chunks in the cartridge
|
||||
|
||||
|
@ -32,9 +30,7 @@ impl Mmc1 {
|
|||
control: 0,
|
||||
prg_ram_bank: vec![0; 0x2000],
|
||||
prg_ram_enabled: false,
|
||||
prg_low_bank: 0,
|
||||
prg_high_bank: 0,
|
||||
prg_bank_mode: 3,
|
||||
prg_bank_mode: 0,
|
||||
prg_bank_select: 0,
|
||||
chr_ram_bank: vec![0; 0x2000],
|
||||
chr_low_bank: 0,
|
||||
|
@ -56,7 +52,6 @@ impl Mmc1 {
|
|||
self.shift_register >>= 1;
|
||||
self.shift_register |= (value & 1) << 7;
|
||||
if self.step == 4 {
|
||||
// println!("writing 0x{:X} to 0x{:04X}", self.shift_register, address);
|
||||
// shift register values will be in top 5 bits, so cut it down to size before moving on to where it's used
|
||||
self.shift_register >>= 3;
|
||||
match address {
|
||||
|
|
|
@ -22,11 +22,6 @@ pub enum Mirror {
|
|||
Vertical,
|
||||
}
|
||||
|
||||
// To avoid separate read and write functions for every mapper, the mapper functions returns a reference to the CPU or PPU's own
|
||||
// byte of memory, which the calling method can dereference to read or set the value.
|
||||
pub type CpuMapperFunc = fn(&mut crate::cpu::Cpu, usize, bool) -> Option<&mut u8>;
|
||||
pub type PpuMapperFunc = fn(&mut crate::ppu::Ppu, usize, bool) -> Option<&mut u8>;
|
||||
|
||||
pub fn get_mapper() -> Rc<RefCell<dyn Mapper>> {
|
||||
let cart = Cartridge::new();
|
||||
let num = cart.mapper_num;
|
||||
|
|
|
@ -2,14 +2,12 @@ use super::{Cartridge, Mapper, Mirror};
|
|||
|
||||
pub struct Nrom {
|
||||
cart: Cartridge,
|
||||
// mirroring: Mirror,
|
||||
}
|
||||
|
||||
impl Nrom {
|
||||
pub fn new(cart: Cartridge) -> Self {
|
||||
Nrom{
|
||||
cart: cart,
|
||||
// mirroring: cart.mirroring,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,12 +11,10 @@ mod audio;
|
|||
use cpu::Cpu;
|
||||
use ppu::Ppu;
|
||||
use apu::Apu;
|
||||
use cartridge::{get_mapper, Cartridge, Mapper};
|
||||
use cartridge::get_mapper;
|
||||
use input::poll_buttons;
|
||||
use screen::{init_window, draw_pixel, draw_to_window};
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use sdl2::keyboard::Keycode;
|
||||
use sdl2::event::Event;
|
||||
use sdl2::pixels::PixelFormatEnum;
|
||||
|
@ -110,11 +108,11 @@ fn main() -> Result<(), String> {
|
|||
// calculate fps
|
||||
let now = Instant::now();
|
||||
if now > fps_timer + Duration::from_secs(1) {
|
||||
// println!("fps: {}", fps);
|
||||
println!("fps: {}", fps);
|
||||
fps = 0;
|
||||
fps_timer = now;
|
||||
|
||||
// println!("samples per second: {}", sps);
|
||||
println!("samples per second: {}", sps);
|
||||
sps = 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
use std::rc::Rc;
|
||||
use std::cell::RefCell;
|
||||
|
||||
fn main() {
|
||||
let mapper = Rc::new(RefCell::new(Box::new(Mmc1{a:32})));
|
||||
|
||||
let ppu = Ppu{mapper: mapper.clone()};
|
||||
let cpu = Cpu{mapper: mapper.clone()};
|
||||
println!("{}", cpu.mapper.borrow_mut().doit());
|
||||
println!("{}", ppu.mapper.borrow_mut().doit());
|
||||
}
|
||||
|
||||
struct Mmc1 {
|
||||
a: u8,
|
||||
}
|
||||
|
||||
trait Mapper {
|
||||
fn doit(&mut self) -> u8;
|
||||
}
|
||||
|
||||
impl Mapper for Mmc1 {
|
||||
fn doit(&mut self) -> u8 {
|
||||
self.a += 1;
|
||||
self.a
|
||||
}
|
||||
}
|
||||
|
||||
struct Ppu {
|
||||
mapper: Rc<RefCell<dyn Mapper>>,
|
||||
}
|
||||
|
||||
struct Cpu {
|
||||
mapper: Rc<RefCell<dyn Mapper>>,
|
||||
}
|
Loading…
Reference in New Issue