mirror of
https://github.com/FranLMSP/snes.git
synced 2026-10-03 07:55:17 -04:00
WIP emulator state
This commit is contained in:
@@ -54,7 +54,7 @@ impl Bus {
|
|||||||
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),
|
MemoryMap::PPU => self.ppu.registers.read(address as u16),
|
||||||
_ => todo!("Implement other memory sections"),
|
_ => todo!("Implement other memory sections. Address: {:#08X}", address),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ impl Bus {
|
|||||||
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),
|
MemoryMap::PPU => self.ppu.registers.write(address as u16, value),
|
||||||
_ => todo!("Implement other memory sections"),
|
_ => todo!("Implement other memory sections. Address: {:#08X}", address),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ pub struct Emulator {
|
|||||||
pub cpu: CPU,
|
pub cpu: CPU,
|
||||||
pub bus: Bus,
|
pub bus: Bus,
|
||||||
pub rom: Box<dyn ROM>,
|
pub rom: Box<dyn ROM>,
|
||||||
|
pub is_frame_ending: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Emulator {
|
impl Emulator {
|
||||||
@@ -15,6 +16,7 @@ impl Emulator {
|
|||||||
cpu: CPU::new(),
|
cpu: CPU::new(),
|
||||||
bus: Bus::new(),
|
bus: Bus::new(),
|
||||||
rom: Box::new(LoROM::new()),
|
rom: Box::new(LoROM::new()),
|
||||||
|
is_frame_ending: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,5 +25,7 @@ impl Emulator {
|
|||||||
self.bus.ppu.tick(self.cpu.cycles);
|
self.bus.ppu.tick(self.cpu.cycles);
|
||||||
|
|
||||||
self.cpu.cycles = 0;
|
self.cpu.cycles = 0;
|
||||||
|
|
||||||
|
self.is_frame_ending = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -218,7 +218,9 @@ fn main() {
|
|||||||
.pick_file()
|
.pick_file()
|
||||||
{
|
{
|
||||||
match emulator.rom.load(&String::from(path.to_str().unwrap())) {
|
match emulator.rom.load(&String::from(path.to_str().unwrap())) {
|
||||||
Ok(_) => {},
|
Ok(_) => {
|
||||||
|
state.emulation.is_paused = false;
|
||||||
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
state.error_message.show = true;
|
state.error_message.show = true;
|
||||||
state.error_message.message = format!(
|
state.error_message.message = format!(
|
||||||
@@ -289,6 +291,17 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actually run the emulation
|
||||||
|
if !state.emulation.is_paused {
|
||||||
|
// We want to keep the emulator running
|
||||||
|
// as long as we are not at the end of the frame
|
||||||
|
while !emulator.is_frame_ending {
|
||||||
|
emulator.run()
|
||||||
|
}
|
||||||
|
// Reset the flag because otherwise the emulator will never continue running
|
||||||
|
emulator.is_frame_ending = false
|
||||||
|
}
|
||||||
|
|
||||||
// Render emulator framebuffer
|
// Render emulator framebuffer
|
||||||
{
|
{
|
||||||
let tex = renderer.textures.get_mut(texture_id).unwrap();
|
let tex = renderer.textures.get_mut(texture_id).unwrap();
|
||||||
|
|||||||
@@ -77,10 +77,23 @@ impl PPUDebug {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Emulation {
|
||||||
|
pub is_paused: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Emulation {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
is_paused: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct State {
|
pub struct State {
|
||||||
pub debug_options: DebugOptions,
|
pub debug_options: DebugOptions,
|
||||||
pub error_message: ErrorMessage,
|
pub error_message: ErrorMessage,
|
||||||
pub ppudebug: PPUDebug,
|
pub ppudebug: PPUDebug,
|
||||||
|
pub emulation: Emulation,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
@@ -89,6 +102,7 @@ impl State {
|
|||||||
debug_options: DebugOptions::new(),
|
debug_options: DebugOptions::new(),
|
||||||
error_message: ErrorMessage::new(),
|
error_message: ErrorMessage::new(),
|
||||||
ppudebug: PPUDebug::new(),
|
ppudebug: PPUDebug::new(),
|
||||||
|
emulation: Emulation::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user