Compare commits
1 Commits
70e0b5868d
...
0f8ee3990c
Author | SHA1 | Date |
---|---|---|
Rekai Nyangadzayi Musuka | 0f8ee3990c |
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Event<()>> = 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);
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -1,79 +0,0 @@
|
|||
use crate::Cycle;
|
||||
use std::collections::BinaryHeap;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct Scheduler {
|
||||
timestamp: Cycle,
|
||||
queue: BinaryHeap<Event>,
|
||||
}
|
||||
|
||||
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<std::cmp::Ordering> {
|
||||
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,
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue