Skip to content

Commit

Permalink
Make SPC700 IPL ROM loadable
Browse files Browse the repository at this point in the history
  • Loading branch information
twvd committed Jan 27, 2024
1 parent 3b92ea5 commit 67f1065
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.*.swp
.*.swt
state_*.json
*.rom
11 changes: 10 additions & 1 deletion src/bin/siena/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use std::thread;
use std::time::SystemTime;

use anyhow::Result;
use anyhow::{Context, Result};
use clap::Parser;
use colored::*;
use sdl2::event::Event;
Expand Down Expand Up @@ -114,6 +114,10 @@ struct Args {
/// Co-processor ROM to load (if needed)
#[arg(short, long)]
corom: Option<String>,

/// SPC700 (APU) IPL to load
#[arg(long, default_value = "spc700.rom")]
spc_ipl: String,
}

fn main() -> Result<()> {
Expand Down Expand Up @@ -163,12 +167,17 @@ fn main() -> Result<()> {
Some(fps) => fps,
};

// Load SPC700 IPL ROM
let apu_ipl = fs::read(&args.spc_ipl)
.with_context(|| format!("Failed to load SPC700 IPL ROM from {}", &args.spc_ipl))?;

// Initialize S-CPU bus
let mut bus = Mainbus::<ChannelRenderer>::new(
cartridge,
args.trace_bus,
displaychannel,
joypads,
&apu_ipl,
args.verbose,
fps,
videoformat,
Expand Down
14 changes: 4 additions & 10 deletions src/snes/apu/apu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,17 @@ impl Apu {
const IPL_ENTRYPOINT: SpcAddress = 0xFFC0;
const IPL_SIZE: usize = 64;

const IPL_BIN: [u8; Self::IPL_SIZE] = [
0xCD, 0xEF, 0xBD, 0xE8, 0x00, 0xC6, 0x1D, 0xD0, 0xFC, 0x8F, 0xAA, 0xF4, 0x8F, 0xBB, 0xF5,
0x78, 0xCC, 0xF4, 0xD0, 0xFB, 0x2F, 0x19, 0xEB, 0xF4, 0xD0, 0xFC, 0x7E, 0xF4, 0xD0, 0x0B,
0xE4, 0xF5, 0xCB, 0xF4, 0xD7, 0x00, 0xFC, 0xD0, 0xF3, 0xAB, 0x01, 0x10, 0xEF, 0x7E, 0xF4,
0x10, 0xEB, 0xBA, 0xF6, 0xDA, 0x00, 0xBA, 0xF4, 0xC4, 0xF4, 0xDD, 0x5D, 0xD0, 0xDB, 0x1F,
0x00, 0x00, 0xC0, 0xFF,
];

pub fn new(verbose: bool) -> Self {
pub fn new(ipl: &[u8], verbose: bool) -> Self {
assert_eq!(ipl.len(), Self::IPL_SIZE);

let ports = Arc::new(RwLock::new(InnerApuPorts {
cpu: [0; 4],
apu: [0; 4],
trace: false,
}));
Self {
cpu: CpuSpc700::<Apubus>::new(
Apubus::new(&Self::IPL_BIN, Arc::clone(&ports)),
Apubus::new(ipl, Arc::clone(&ports)),
Self::IPL_ENTRYPOINT,
),
spc_cycles_taken: 0,
Expand Down
4 changes: 3 additions & 1 deletion src/snes/bus/mainbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ where
trace: BusTrace,
renderer: TRenderer,
joypads: [Joypad; JOYPAD_COUNT],
apu_ipl: &[u8],
apu_verbose: bool,
fps: u64,
videoformat: VideoFormat,
Expand All @@ -253,7 +254,7 @@ where
joypads: Some(joypads),

ppu: PPU::<TRenderer>::new(renderer, fps, videoformat),
apu: Arc::new(Mutex::new(Apu::new(apu_verbose))),
apu: Arc::new(Mutex::new(Apu::new(apu_ipl, apu_verbose))),

memsel: 0,
wmadd: Cell::new(0),
Expand Down Expand Up @@ -879,6 +880,7 @@ mod tests {
BusTrace::All,
NullRenderer::new(0, 0).unwrap(),
joypads,
&[0; 64],
false,
0,
VideoFormat::PAL,
Expand Down
1 change: 1 addition & 0 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fn test_display(rom: &[u8], pass_hash: &[u8], time_limit: u128, stable: bool, hi
BusTrace::None,
display,
joypads,
&[0; 64],
false,
0,
VideoFormat::PAL,
Expand Down

0 comments on commit 67f1065

Please sign in to comment.