diff options
author | Determinant <[email protected]> | 2017-11-15 12:38:11 -0500 |
---|---|---|
committer | Determinant <[email protected]> | 2017-11-15 12:38:11 -0500 |
commit | 7ced09699636956fe1c0e4bc9748d482c1b40239 (patch) | |
tree | 577bfdcdb92348c6d7e1d1f20498e033d22eab15 | |
parent | 5e09a190d48a28055bc7a0989940b43bb10d295d (diff) |
...
-rw-r--r-- | src/main.rs | 9 | ||||
-rw-r--r-- | src/memory.rs | 9 | ||||
-rw-r--r-- | src/mos6502.rs | 8 | ||||
-rw-r--r-- | src/ppu.rs | 4 |
4 files changed, 14 insertions, 16 deletions
diff --git a/src/main.rs b/src/main.rs index 57af3e4..c53068b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -214,11 +214,10 @@ fn main() { //let win = Window {buff: RefCell::new([[0; 256]; 240])}; let win = SDLWindow::new(); let mapper = mapper::Mapper2::new(&cart); - let pmem = memory::PPUMemory::new(&mapper, &cart); - let mem = memory::CPUMemory::new(&mapper); - let mut ppu = ppu::PPU::new(&pmem, &win); - let mut cpu = mos6502::CPU::new(&mem); - mem.init(&mut cpu, &mut ppu); + let mut ppu = ppu::PPU::new(memory::PPUMemory::new(&mapper, &cart), &win); + let mut cpu = mos6502::CPU::new(memory::CPUMemory::new(&mut ppu, &mapper)); + let ptr = &mut cpu as *mut mos6502::CPU; + cpu.mem.init(ptr); let mut cnt = 0; use ppu::Screen; const CYC_PER_FRAME: u32 = mos6502::CPU_FREQ / 60; diff --git a/src/memory.rs b/src/memory.rs index d2c9e52..6b960ec 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -18,18 +18,15 @@ pub struct CPUMemory<'a> { } impl<'a> CPUMemory<'a> { - pub fn new(mapper: &'a VMem) -> Self { + pub fn new(ppu: *mut PPU<'a>, mapper: &'a VMem) -> Self { CPUMemory{sram: UnsafeCell::new([0; 2048]), cpu: Cell::new(null_mut()), - ppu: Cell::new(null_mut()), + ppu: Cell::new(ppu), mapper} } - pub fn init(&self, - cpu: *mut CPU<'a>, - ppu: *mut PPU<'a>) { + pub fn init(&self, cpu: *mut CPU<'a>) { self.cpu.set(cpu); - self.ppu.set(ppu); } } diff --git a/src/mos6502.rs b/src/mos6502.rs index 7b39de4..fdce0ab 100644 --- a/src/mos6502.rs +++ b/src/mos6502.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use memory::VMem; +use memory::{CPUMemory, VMem}; pub const CPU_FREQ: u32 = 1789773; macro_rules! make_optable { ($x:ident, $t: ty) => (pub const $x: [$t; 0x100] = [ @@ -233,6 +233,7 @@ macro_rules! read16 { } mod ops { + use memory::VMem; use mos6502::*; make_optable!(OPS, fn (&mut CPU)); @@ -595,6 +596,7 @@ mod ops { } mod addr { + use memory::VMem; use mos6502::{CPU}; make_addrtable!(ADDR_MODES, fn (&mut CPU) -> u8); @@ -686,7 +688,7 @@ pub struct CPU<'a> { imm_val: u8, pub cycle: u32, int: Option<IntType>, - pub mem: &'a VMem + pub mem: CPUMemory<'a> } macro_rules! make_int { @@ -712,7 +714,7 @@ impl<'a> CPU<'a> { #[inline(always)] pub fn get_over(&self) -> u8 { (self.status >> 6) & 1 } #[inline(always)] pub fn get_neg(&self) -> u8 { (self.status >> 7) & 1 } - pub fn new(mem: &'a VMem) -> Self { + pub fn new(mem: CPUMemory<'a>) -> Self { let pc = read16!(mem, RESET_VECTOR as u16); /* nes power up state */ let a = 0; @@ -51,7 +51,7 @@ pub struct PPU<'a> { buffered_read: u8, early_read: bool, /* IO */ - mem: &'a PPUMemory<'a>, + mem: PPUMemory<'a>, scr: &'a Screen, } @@ -441,7 +441,7 @@ impl<'a> PPU<'a> { })); } - pub fn new(mem: &'a PPUMemory<'a>, scr: &'a Screen) -> Self { + pub fn new(mem: PPUMemory<'a>, scr: &'a Screen) -> Self { let ppuctl = 0x00; let ppumask = 0x00; let ppustatus = 0xa0; |