merge
This commit is contained in:
commit
5f54f10b3c
|
@ -1,7 +1,6 @@
|
|||
# nestur
|
||||
|
||||
Nestur is an NES emulator. There are plenty of full-featured emulators out there; this is primarily an educational project but it is usable. There may still be many bugs, but I'm probably not aware of them so please submit issues.
|
||||
- SDL2 is the only dependency
|
||||
- no use of `unsafe`
|
||||
- NTSC timing
|
||||
- supports mappers 0-4 which cover ~85% of [games](http://tuxnes.sourceforge.net/nesmapper.txt)
|
||||
|
@ -23,7 +22,7 @@ ___________________
|
|||
-------------------
|
||||
Save state: F5
|
||||
Load state: F9
|
||||
(Only one save state at a time supported currently: saving a second time overwrites the first.)
|
||||
(Saving state a second time overwrites the first unless you copy/rename the `.dat` file. You can drag and drop any `.dat` file onto the window to load it.)
|
||||
```
|
||||
The code aims to follow the explanations from the [NES dev wiki](https://wiki.nesdev.com/w/index.php/NES_reference_guide) where possible, especially in the PPU, and the comments quote from it often. Thanks to everyone who contributes to that wiki/forum, and to Michael Fogleman's [NES](https://github.com/fogleman/nes) and Scott Ferguson's [Fergulator](https://github.com/scottferg/Fergulator) for getting me unstuck at several points.
|
||||
|
||||
|
@ -47,9 +46,9 @@ The code aims to follow the explanations from the [NES dev wiki](https://wiki.ne
|
|||
|
||||
- DMC audio channel, high- and low-pass filters
|
||||
|
||||
- Better GUI and distributable solution
|
||||
- Better GUI
|
||||
|
||||
- Save states
|
||||
- Better save state handling
|
||||
|
||||
- Player 2 controller?
|
||||
|
||||
|
|
|
@ -2,8 +2,7 @@ pub type ApuData = super::Apu;
|
|||
|
||||
impl super::Apu{
|
||||
pub fn save_state(&self) -> ApuData {
|
||||
let x: ApuData = self.clone();
|
||||
x
|
||||
self.clone()
|
||||
}
|
||||
|
||||
pub fn load_state(&mut self, data: ApuData) {
|
||||
|
|
|
@ -21,6 +21,7 @@ use sdl2::keyboard::Keycode;
|
|||
use sdl2::EventPump;
|
||||
use sdl2::event::Event;
|
||||
use sdl2::pixels::PixelFormatEnum;
|
||||
use std::path::Path;
|
||||
|
||||
// use cpuprofiler::PROFILER;
|
||||
|
||||
|
|
18
src/state.rs
18
src/state.rs
|
@ -4,7 +4,7 @@ use super::apu;
|
|||
|
||||
use std::fs::File;
|
||||
use std::io::{Read, Write};
|
||||
use std::path::Path;
|
||||
use std::path::{Path, PathBuf};
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
|
@ -14,7 +14,7 @@ struct SaveState {
|
|||
apu: apu::serialize::ApuData,
|
||||
}
|
||||
|
||||
pub fn save_state(cpu: &cpu::Cpu, filename: &str) -> Result<(), String> {
|
||||
pub fn save_state(cpu: &cpu::Cpu, save_file: PathBuf) -> Result<(), String> {
|
||||
let data = SaveState{
|
||||
cpu: cpu.save_state(),
|
||||
ppu: cpu.ppu.save_state(),
|
||||
|
@ -30,19 +30,7 @@ pub fn save_state(cpu: &cpu::Cpu, filename: &str) -> Result<(), String> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn load_state(cpu: &mut cpu::Cpu, filename: &str) -> Result<(), String> {
|
||||
// load file, deserialize to cpudata, set cpu fields to data fields
|
||||
let path = match Path::new(&filename).parent() {
|
||||
Some(p) => p,
|
||||
None => return Err("couldn't convert filename to path".to_string()),
|
||||
};
|
||||
let stem = match Path::new(&filename).file_stem() {
|
||||
Some(s) => s,
|
||||
None => return Err("couldn't get file stem".to_string()),
|
||||
};
|
||||
let mut save_file = path.join(stem);
|
||||
save_file.set_extension("dat");
|
||||
|
||||
pub fn load_state(cpu: &mut cpu::Cpu, save_file: PathBuf) -> Result<(), String> {
|
||||
if Path::new(&save_file).exists() {
|
||||
let mut f = File::open(save_file.clone())
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
|
Loading…
Reference in New Issue