mirror of
https://github.com/FranLMSP/snes.git
synced 2026-01-01 07:21:35 -05:00
h/v counters
This commit is contained in:
@@ -46,7 +46,7 @@ impl CPU {
|
||||
}
|
||||
|
||||
fn push_emulation_interrupt(&mut self, bus: &mut Bus) {
|
||||
if ! self.registers.emulation_mode {
|
||||
if !self.registers.emulation_mode {
|
||||
self.phk(bus);
|
||||
}
|
||||
self.do_push(bus, &[
|
||||
|
||||
@@ -2,6 +2,8 @@ use super::registers::PPURegisters;
|
||||
|
||||
pub struct PPU {
|
||||
framebuffer: Vec<u8>,
|
||||
h_count: u16,
|
||||
v_count: u16,
|
||||
pub registers: PPURegisters,
|
||||
}
|
||||
|
||||
@@ -9,21 +11,58 @@ impl PPU {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
framebuffer: vec![],
|
||||
h_count: 0,
|
||||
v_count: 0,
|
||||
registers: PPURegisters::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tick(&mut self, cpu_cycles: usize) {
|
||||
for _ in 0..cpu_cycles {
|
||||
self.do_cycle();
|
||||
for _ in 0..(cpu_cycles * 2) {
|
||||
self.dot_cycle();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn do_cycle(&mut self) {
|
||||
pub fn dot_cycle(&mut self) {
|
||||
self.increment_hv_count();
|
||||
}
|
||||
|
||||
fn increment_hv_count(&mut self) {
|
||||
self.h_count += 1;
|
||||
if self.h_count > 339 {
|
||||
self.h_count = 0;
|
||||
self.v_count += 1;
|
||||
if self.v_count > 261 {
|
||||
self.v_count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn framebuffer(&self) -> &Vec<u8> {
|
||||
&self.framebuffer
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod ppu_general_test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_increment_hv_count() {
|
||||
let mut ppu = PPU::new();
|
||||
ppu.increment_hv_count();
|
||||
assert_eq!(ppu.h_count, 1);
|
||||
|
||||
ppu.h_count = 339;
|
||||
ppu.increment_hv_count();
|
||||
assert_eq!(ppu.h_count, 0);
|
||||
assert_eq!(ppu.v_count, 1);
|
||||
|
||||
ppu.h_count = 339;
|
||||
ppu.v_count = 261;
|
||||
ppu.increment_hv_count();
|
||||
assert_eq!(ppu.h_count, 0);
|
||||
assert_eq!(ppu.v_count, 0);
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,8 @@ pub const WOBJLOG: u16 = 0x212B; // Window 2 Mask Logic (W)
|
||||
pub const TMW: u16 = 0x212E; // Window Area Main Screen Disable (W)
|
||||
pub const TSW: u16 = 0x212F; // Window Area Sub Screen Disable (W)
|
||||
|
||||
// PPU Interrupts
|
||||
pub const RDNMI: u16 = 0x4210; // V-Blank NMI Flag
|
||||
|
||||
pub const MAX_BG_WIDTH: usize = 16 * 64;
|
||||
pub const MAX_BG_HEIGHT: usize = 16 * 64;
|
||||
|
||||
Reference in New Issue
Block a user