diff --git a/src/apu.rs b/src/apu.rs index c7c977f..58394c0 100644 --- a/src/apu.rs +++ b/src/apu.rs @@ -587,7 +587,7 @@ impl Channel1 { pub(crate) struct Channel2 { /// 0xFF16 | NR21 - Channel 2 Sound length / Wave Pattern Duty duty: SoundDuty, - /// 0xFF17 | NR22 - Channel 2 Volume ENvelope + /// 0xFF17 | NR22 - Channel 2 Volume Envelope envelope: VolumeEnvelope, /// 0xFF18 | NR23 - Channel 2 Frequency low (lower 8 bits only) freq_lo: u8, @@ -619,12 +619,12 @@ impl Channel2 { self.length_counter = 64 - self.duty.sound_length() as u16; } - /// 0xFF17 | NR22 - Channel 2 Volume ENvelope + /// 0xFF17 | NR22 - Channel 2 Volume Envelope pub(crate) fn envelope(&self) -> u8 { u8::from(self.envelope) } - /// 0xFF17 | NR22 - Channel 2 Volume ENvelope + /// 0xFF17 | NR22 - Channel 2 Volume Envelope pub(crate) fn set_envelope(&mut self, byte: u8) { self.envelope = byte.into(); diff --git a/src/high_ram.rs b/src/high_ram.rs index 7d1b84b..b5fb733 100644 --- a/src/high_ram.rs +++ b/src/high_ram.rs @@ -17,11 +17,11 @@ impl Default for HighRam { } impl BusIo for HighRam { - fn write_byte(&mut self, addr: u16, byte: u8) { - self.buf[addr as usize - HIGH_RAM_START_ADDRESS] = byte; - } - fn read_byte(&self, addr: u16) -> u8 { self.buf[addr as usize - HIGH_RAM_START_ADDRESS] } + + fn write_byte(&mut self, addr: u16, byte: u8) { + self.buf[addr as usize - HIGH_RAM_START_ADDRESS] = byte; + } } diff --git a/src/main.rs b/src/main.rs index 1497d38..8c54ffa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,7 +45,7 @@ fn main() { .with_env_filter(EnvFilter::from_default_env()) .init(); - // --Here lies a lot of Winit + WGPU Boilerplate-- + // --Here lies a lot of winit + wgpu Boilerplate-- let event_loop: EventLoop> = EventLoop::with_user_event(); let window = gb::gui::build_window(&event_loop).expect("build window"); @@ -74,7 +74,7 @@ fn main() { } }; - // Set up the WGPU (and then EGUI) texture we'll be working with. + // Set up the wgpu (and then EGUI) texture we'll be working with. let texture_size = gb::gui::texture_size(); let texture = gb::gui::create_texture(&device, texture_size); gb::gui::write_to_texture(&queue, &texture, gb::emu::pixel_buf(&cpu), texture_size); diff --git a/src/ppu.rs b/src/ppu.rs index 39d81e0..e4d450e 100644 --- a/src/ppu.rs +++ b/src/ppu.rs @@ -265,7 +265,7 @@ impl Ppu { TileLowB => { let obj_size = self.ctrl.obj_size(); - let addr = PixelFetcher::get_obj_addr(attr, &self.pos, obj_size); + let addr = PixelFetcher::obj_addr(attr, &self.pos, obj_size); let byte = self.read_byte(addr); self.fetch.obj.tile.with_low(byte); @@ -276,7 +276,7 @@ impl Ppu { TileHighB => { let obj_size = self.ctrl.obj_size(); - let addr = PixelFetcher::get_obj_addr(attr, &self.pos, obj_size); + let addr = PixelFetcher::obj_addr(attr, &self.pos, obj_size); let byte = self.read_byte(addr + 1); self.fetch.obj.tile.with_high(byte); @@ -441,7 +441,7 @@ impl Ppu { fn obj_pixel(&self, obj: ObjPixelProperty) -> GrayShade { use ObjectPaletteKind::*; - assert!(obj.shade_id != 0); + assert_ne!(obj.shade_id, 0); let p0 = &self.monochrome.obj_palette_0; let p1 = &self.monochrome.obj_palette_1; @@ -683,7 +683,7 @@ impl PixelFetcher { Ok(()) } - fn get_obj_addr(attr: &ObjectAttr, pos: &ScreenPosition, size: ObjectSize) -> u16 { + fn obj_addr(attr: &ObjectAttr, pos: &ScreenPosition, size: ObjectSize) -> u16 { let line_y = pos.line_y; // TODO: Why is the offset 14 and 30 respectively? diff --git a/src/scheduler.rs b/src/scheduler.rs deleted file mode 100644 index e7bd37e..0000000 --- a/src/scheduler.rs +++ /dev/null @@ -1,79 +0,0 @@ -use crate::Cycle; -use std::collections::BinaryHeap; - -#[derive(Debug)] -pub(crate) struct Scheduler { - timestamp: Cycle, - queue: BinaryHeap, -} - -impl Scheduler { - pub(crate) fn init() -> Self { - let mut scheduler = Self { - timestamp: Default::default(), - queue: Default::default(), - }; - - scheduler.push(Event { - kind: EventKind::TimestampOverflow, - timestamp: Cycle::MAX, - cb: |_delay| panic!("Reached Cycle::MAX"), - }); - - scheduler - } - - pub(crate) fn push(&mut self, event: Event) { - self.queue.push(event); - } - - pub(crate) fn step(&mut self, cycles: Cycle) { - self.timestamp += cycles; - - loop { - let should_pop = match self.queue.peek() { - Some(event) => self.timestamp >= event.timestamp, - None => false, - }; - - if !should_pop { - break; - } - - let event = self.queue.pop().expect("Pop Event from Scheduler Queue"); - - (event.cb)(self.timestamp - event.timestamp); - } - } -} - -#[derive(Debug)] -pub(crate) struct Event { - kind: EventKind, - cb: fn(Cycle), - pub(crate) timestamp: Cycle, -} - -impl Eq for Event {} -impl PartialEq for Event { - fn eq(&self, other: &Self) -> bool { - self.kind == other.kind && self.timestamp == other.timestamp - } -} - -impl PartialOrd for Event { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} - -impl Ord for Event { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { - self.timestamp.cmp(&other.timestamp) - } -} - -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub(crate) enum EventKind { - TimestampOverflow, -} diff --git a/src/work_ram.rs b/src/work_ram.rs index f553a63..efb2937 100644 --- a/src/work_ram.rs +++ b/src/work_ram.rs @@ -11,13 +11,13 @@ pub(crate) struct WorkRam { } impl BusIo for WorkRam { - fn write_byte(&mut self, addr: u16, byte: u8) { - self.bank[addr as usize - WORK_RAM_START_ADDRESS] = byte; - } - fn read_byte(&self, addr: u16) -> u8 { self.bank[addr as usize - WORK_RAM_START_ADDRESS] } + + fn write_byte(&mut self, addr: u16, byte: u8) { + self.bank[addr as usize - WORK_RAM_START_ADDRESS] = byte; + } } impl Default for WorkRam { @@ -42,11 +42,11 @@ impl Default for VariableWorkRam { } impl BusIo for VariableWorkRam { - fn write_byte(&mut self, addr: u16, byte: u8) { - self.buf[addr as usize - VARIABLE_WORK_RAM_START_ADDRESS] = byte; - } - fn read_byte(&self, addr: u16) -> u8 { self.buf[addr as usize - VARIABLE_WORK_RAM_START_ADDRESS] } + + fn write_byte(&mut self, addr: u16, byte: u8) { + self.buf[addr as usize - VARIABLE_WORK_RAM_START_ADDRESS] = byte; + } }