mirror of
https://github.com/FranLMSP/snes.git
synced 2026-10-03 16:05:18 -04:00
WIP PPU structure
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
|
use crate::ppu::PPU;
|
||||||
|
|
||||||
pub struct Bus {
|
pub struct Bus {
|
||||||
wram: [u8; 0x10000],
|
wram: [u8; 0x10000],
|
||||||
|
pub ppu: PPU,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
@@ -15,6 +18,7 @@ impl Bus {
|
|||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
wram: [0; 0x10000],
|
wram: [0; 0x10000],
|
||||||
|
ppu: PPU::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,6 +53,7 @@ impl Bus {
|
|||||||
let section = Bus::map_address(address);
|
let section = Bus::map_address(address);
|
||||||
match section {
|
match section {
|
||||||
MemoryMap::WRAM => self.read_wram(address),
|
MemoryMap::WRAM => self.read_wram(address),
|
||||||
|
MemoryMap::PPU => self.ppu.registers.read(address as u16),
|
||||||
_ => todo!("Implement other memory sections"),
|
_ => todo!("Implement other memory sections"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,6 +62,7 @@ impl Bus {
|
|||||||
let section = Bus::map_address(address);
|
let section = Bus::map_address(address);
|
||||||
match section {
|
match section {
|
||||||
MemoryMap::WRAM => self.write_wram(address, value),
|
MemoryMap::WRAM => self.write_wram(address, value),
|
||||||
|
MemoryMap::PPU => self.ppu.registers.write(address as u16, value),
|
||||||
_ => todo!("Implement other memory sections"),
|
_ => todo!("Implement other memory sections"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,5 +20,8 @@ impl Emulator {
|
|||||||
|
|
||||||
pub fn run(&mut self) {
|
pub fn run(&mut self) {
|
||||||
self.cpu.run(&mut self.bus);
|
self.cpu.run(&mut self.bus);
|
||||||
|
self.bus.ppu.tick(self.cpu.cycles);
|
||||||
|
|
||||||
|
self.cpu.cycles = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
pub mod cpu;
|
pub mod cpu;
|
||||||
|
pub mod ppu;
|
||||||
pub mod rom;
|
pub mod rom;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
pub mod common;
|
pub mod common;
|
||||||
|
|||||||
@@ -2,19 +2,19 @@ use super::registers::PPURegisters;
|
|||||||
|
|
||||||
pub struct PPU {
|
pub struct PPU {
|
||||||
framebuffer: Vec<u8>,
|
framebuffer: Vec<u8>,
|
||||||
registers: PPURegisters,
|
pub registers: PPURegisters,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PPU {
|
impl PPU {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
framebuffer: vec![],
|
framebuffer: vec![],
|
||||||
registers: PPURegisters,
|
registers: PPURegisters::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tick(&mut self, cycles: usize) {
|
pub fn tick(&mut self, cpu_cycles: usize) {
|
||||||
for _ in 0..cycles {
|
for _ in 0..cpu_cycles {
|
||||||
self.do_cycle();
|
self.do_cycle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,10 +61,21 @@ pub const TMW: u16 = 0x212E; // Window Area Main Screen Disable (W)
|
|||||||
pub const TSW: u16 = 0x212F; // Window Area Sub Screen Disable (W)
|
pub const TSW: u16 = 0x212F; // Window Area Sub Screen Disable (W)
|
||||||
|
|
||||||
pub struct PPURegisters {
|
pub struct PPURegisters {
|
||||||
|
data: [u8; 256],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PPURegisters {
|
impl PPURegisters {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
data: [0x00; 256],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read(&self, address: u16) -> u8 {
|
||||||
|
self.data[(address as usize) - 0x2100]
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn write(&mut self, address: u16, value: u8) {
|
||||||
|
self.data[(address as usize) - 0x2100] = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user