aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <ted.sybil@gmail.com>2018-01-22 02:07:02 -0500
committerDeterminant <ted.sybil@gmail.com>2018-01-22 02:07:02 -0500
commitf10e500bcbfe27558af0542b32b4a09d2a643ed4 (patch)
treea520334e1d69d8e91dc864719522762303b459a5
parentc60485cca6ea4984cbf842f42bddfaa97cf6e489 (diff)
...
-rw-r--r--src/bin.rs22
-rw-r--r--src/memory.rs16
-rw-r--r--src/ppu.rs1
3 files changed, 15 insertions, 24 deletions
diff --git a/src/bin.rs b/src/bin.rs
index 4e0a550..83252be 100644
--- a/src/bin.rs
+++ b/src/bin.rs
@@ -45,7 +45,7 @@ const PIX_HEIGHT: u32 = 240;
const FB_PITCH: usize = PIX_WIDTH as usize * 3;
const FB_SIZE: usize = PIX_HEIGHT as usize * FB_PITCH;
const AUDIO_SAMPLES: u16 = 4410;
-const AUDIO_EXTRA_SAMPLES: u16 = 1000;
+const AUDIO_EXTRA_SAMPLES: u16 = AUDIO_SAMPLES;
const AUDIO_ALL_SAMPLES: u16 = AUDIO_SAMPLES + AUDIO_EXTRA_SAMPLES;
pub struct SimpleCart {
@@ -326,7 +326,7 @@ impl<'a> ppu::Screen for SDLWindow<'a> {
}
struct CircularBuffer {
- buffer: [i16; 2 * AUDIO_ALL_SAMPLES as usize],
+ buffer: [i16; (AUDIO_ALL_SAMPLES + 1) as usize],
head: usize,
tail: usize
}
@@ -334,9 +334,9 @@ struct CircularBuffer {
impl CircularBuffer {
fn new() -> Self {
CircularBuffer {
- buffer: [0; 2 * AUDIO_ALL_SAMPLES as usize],
- head: 0,
- tail: AUDIO_ALL_SAMPLES as usize
+ buffer: [0; (AUDIO_ALL_SAMPLES + 1) as usize],
+ head: 1,
+ tail: 0
}
}
@@ -379,9 +379,10 @@ impl<'a> sdl2::audio::AudioCallback for SDLAudioPlayback<'a> {
let mut m = self.0.buffer.lock().unwrap();
{
let b = &mut m.0;
- /*let l1 = (b.tail + b.buffer.len() - b.head) % b.buffer.len();
- print!("{} ", l1); */
-
+ /*
+ let l1 = (b.tail + b.buffer.len() - b.head) % b.buffer.len();
+ print!("{} ", l1);
+ */
for x in out.iter_mut() {
*x = b.deque()
}
@@ -391,8 +392,8 @@ impl<'a> sdl2::audio::AudioCallback for SDLAudioPlayback<'a> {
m.1 -= AUDIO_SAMPLES;
self.0.time_barrier.notify_one();
} else {
+ println!("audio frame skipping {}", m.1);
m.1 = 0;
- println!("audio frame skipping");
}
}
}
@@ -556,8 +557,7 @@ fn main() {
/* audio */
let audio_sync = AudioSync { time_barrier: Condvar::new(),
- buffer: Mutex::new((CircularBuffer::new(),
- AUDIO_ALL_SAMPLES))};
+ buffer: Mutex::new((CircularBuffer::new(), AUDIO_ALL_SAMPLES))};
let mut spkr = SDLAudio(&audio_sync);
let desired_spec = sdl2::audio::AudioSpecDesired {
freq: Some(apu::AUDIO_SAMPLE_FREQ as i32),
diff --git a/src/memory.rs b/src/memory.rs
index 46a9464..78fd716 100644
--- a/src/memory.rs
+++ b/src/memory.rs
@@ -2,7 +2,7 @@
use ppu::PPU;
use apu::APU;
use utils::{Sampler, Read, Write, load_prefix, save_prefix};
-use mos6502::{CPU, CPU_FREQ};
+use mos6502::CPU;
use cartridge::MirrorType;
use mapper::RefMapper;
use controller::Controller;
@@ -22,10 +22,6 @@ pub struct CPUBus<'a> {
cpu_stall: Cell<u32>,
/*-- end state --*/
- /*-- begin sub-state --*/
- ppu_sampler: RefCell<Sampler>,
- /*-- end sub-state --*/
-
cpu: *mut CPU<'a>,
ppu: *mut PPU<'a>,
apu: *mut APU<'a>,
@@ -43,20 +39,17 @@ impl<'a> CPUBus<'a> {
CPUBus {ppu: null_mut(),
cpu: null_mut(),
apu: null_mut(),
- ppu_sampler: RefCell::new(Sampler::new(CPU_FREQ, 60)),
nmi_after_tick: Cell::new(false),
cpu_stall: Cell::new(0)
}
}
pub fn load(&mut self, reader: &mut Read) -> bool {
- load_prefix(self, CPUBUS_IGNORED_SIZE!(), reader) &&
- self.ppu_sampler.borrow_mut().load(reader)
+ load_prefix(self, CPUBUS_IGNORED_SIZE!(), reader)
}
pub fn save(&self, writer: &mut Write) -> bool {
- save_prefix(self, CPUBUS_IGNORED_SIZE!(), writer) &&
- self.ppu_sampler.borrow().save(writer)
+ save_prefix(self, CPUBUS_IGNORED_SIZE!(), writer)
}
pub fn attach(&mut self, cpu: *mut CPU<'a>,
@@ -106,9 +99,6 @@ impl<'a> CPUBus<'a> {
}
self.nmi_after_tick.set(nmi_after_tick);
//println!("tick {} {}", ppu.scanline, ppu.cycle);
- if self.ppu_sampler.borrow_mut().tick() {
- ppu.scr.frame()
- }
}
}
diff --git a/src/ppu.rs b/src/ppu.rs
index 40d0493..3de365d 100644
--- a/src/ppu.rs
+++ b/src/ppu.rs
@@ -591,6 +591,7 @@ impl<'a> PPU<'a> {
self.early_read = false;
self.vblank = true;
self.scr.render();
+ self.scr.frame();
self.cycle = 2;
return self.try_nmi()
}