aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2017-11-16 19:22:46 -0500
committerDeterminant <[email protected]>2017-11-16 19:22:46 -0500
commit35061de86daee3ed46f4a6ba14983672424dce56 (patch)
tree107adffbe4fb8cfb5e855cbbabe59a37dc2e4b40
parent904c18222ec50929aa8f6b397ff0b90ec47d97a4 (diff)
...
-rw-r--r--src/controller.rs1
-rw-r--r--src/main.rs27
-rw-r--r--src/memory.rs20
3 files changed, 14 insertions, 34 deletions
diff --git a/src/controller.rs b/src/controller.rs
index cc01d0f..2685cd1 100644
--- a/src/controller.rs
+++ b/src/controller.rs
@@ -1,3 +1,4 @@
+#![allow(dead_code)]
pub trait Controller {
fn read(&self) -> u8;
diff --git a/src/main.rs b/src/main.rs
index 986893e..2b66c55 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -42,25 +42,6 @@ const FB_SIZE: usize = PIX_HEIGHT * FB_PITCH * (PIXEL_SIZE as usize);
const WIN_WIDTH: u32 = PIX_WIDTH as u32 * PIXEL_SIZE;
const WIN_HEIGHT: u32 = PIX_HEIGHT as u32 * PIXEL_SIZE;
-struct DummyWindow {
- buff: RefCell<[[u8; PIX_HEIGHT]; PIX_WIDTH]>
-}
-
-impl ppu::Screen for DummyWindow {
- fn put(&self, x: u8, y: u8, color: u8) {
- self.buff.borrow_mut()[y as usize][x as usize] = color;
- }
- fn render(&self) {
- println!("a frame has been redrawn:");
- for r in self.buff.borrow().iter() {
- for c in r.iter() {
- print!("{:02x}", c);
- }
- println!("");
- }
- }
-}
-
struct SDLWindow<'a> {
canvas: UnsafeCell<sdl2::render::WindowCanvas>,
events: UnsafeCell<sdl2::EventPump>,
@@ -282,14 +263,18 @@ fn main() {
}
*/
let cart = cartridge::Cartridge::new(chr_rom, prg_rom, sram, mirror);
- //let win = Window {buff: RefCell::new([[0; 256]; 240])};
let p1ctl = Joystick::new();
let win = SDLWindow::new(&p1ctl);
- let mapper = mapper::Mapper2::new(&cart);
+ let mapper = match mapper_id {
+ 0 | 2 => mapper::Mapper2::new(&cart),
+ _ => panic!("unsupported mapper {}", mapper_id)
+ };
+
let mut ppu = ppu::PPU::new(memory::PPUMemory::new(&mapper, &cart), &win);
let mut cpu = mos6502::CPU::new(memory::CPUMemory::new(&mut ppu, &mapper, Some(&p1ctl), None));
let ptr = &mut cpu as *mut mos6502::CPU;
cpu.mem.init(ptr);
+
loop {
cpu.step();
while cpu.cycle > 0 {
diff --git a/src/memory.rs b/src/memory.rs
index c302af9..fc8732c 100644
--- a/src/memory.rs
+++ b/src/memory.rs
@@ -21,7 +21,7 @@ pub struct CPUMemory<'a> {
}
impl<'a> CPUMemory<'a> {
- pub fn new(ppu: *mut PPU<'a>,
+ pub fn new(ppu: &mut PPU<'a>,
mapper: &'a VMem,
ctl1: Option<&'a Controller>,
ctl2: Option<&'a Controller>) -> Self {
@@ -50,14 +50,8 @@ impl<'a> VMem for CPUMemory<'a> {
}
} else if addr < 0x4020 {
match addr {
- 0x4016 => match self.ctl1 {
- Some(c) => c.read(),
- None => 0
- },
- 0x4017 => match self.ctl2 {
- Some(c) => c.read(),
- None => 0
- },
+ 0x4016 => if let Some(c) = self.ctl1 { c.read() } else { 0 },
+ 0x4017 => if let Some(c) = self.ctl2 { c.read() } else { 0 },
_ => 0
}
} else if addr < 0x6000 {
@@ -86,10 +80,10 @@ impl<'a> VMem for CPUMemory<'a> {
} else if addr < 0x4020 {
match addr {
0x4014 => ppu.write_oamdma(data, cpu),
- 0x4016 => match self.ctl1 {
- Some(c) => c.write(data),
- None => ()
- },
+ 0x4016 => {
+ if let Some(c) = self.ctl1 { c.write(data) }
+ if let Some(c) = self.ctl2 { c.write(data) }
+ }
_ => ()
}
} else if addr < 0x6000 {