pub trait SidTune {
const BYTES: &'static [u8];
const HAS_BASIC_LOAD_ADDRESS: bool = _;
const DATA_OFFSET: usize = _;
const DATA_LEN: usize = _;
const INIT_ADDRESS: u16 = _;
const INIT_PTR: *const unsafe extern "C" fn() = _;
const PLAY_ADDRESS: u16 = _;
const PLAY_PTR: *const unsafe extern "C" fn() = _;
const NUM_SONGS: usize = _;
const LOAD_ADDRESS: u16 = _;
// Provided methods
fn num_songs(&self) -> usize { ... }
fn init(&self, song: u8) { ... }
fn play(&self) { ... }
unsafe fn to_memory(&self)
where [(); Self::DATA_LEN]: { ... }
}Expand description
Trait for loading and parsing a PSID file at compile time
The PSID file format is described
here.
Since arrays in rust cannot be larger than isize, songs larger than
32 kb cannot be loaded.
§Examples
use mos_hardware::sid::SidTune;
struct Music;
impl SidTune for Music {
const BYTES: &'static [u8] = core::include_bytes!("last_hero.sid");
}
let music = Music;
unsafe {
music.to_memory(); // copy data to found load address (danger!)
}
music.init(0); // call song initialisation routine
music.play(); // call this at every frameRequired Associated Constants§
Provided Associated Constants§
Sourceconst HAS_BASIC_LOAD_ADDRESS: bool = _
const HAS_BASIC_LOAD_ADDRESS: bool = _
True if data has an optional 2-byte header stating the load address (C64 style)
Sourceconst DATA_OFFSET: usize = _
const DATA_OFFSET: usize = _
Offset where data begins, excluding any optional 2-byte load address
Sourceconst INIT_ADDRESS: u16 = _
const INIT_ADDRESS: u16 = _
Address of init routine
Sourceconst PLAY_ADDRESS: u16 = _
const PLAY_ADDRESS: u16 = _
Address of play routine
Sourceconst LOAD_ADDRESS: u16 = _
const LOAD_ADDRESS: u16 = _
Load address found either in PSID header or in data part
Provided Methods§
fn num_songs(&self) -> usize
Sourcefn init(&self, song: u8)
fn init(&self, song: u8)
Call song initialisation routine
Before calling the init routine found in the the PSID file, the
accumulator (A) is set to the song number. This is done by placing
6502 wrapper code at the end of the SID file.
§Todo
It would be nice to let the compiler decide where to place the
wrapper code (address), but so far no luck.
Sourceunsafe fn to_memory(&self)where
[(); Self::DATA_LEN]:,
unsafe fn to_memory(&self)where
[(); Self::DATA_LEN]:,
Copies data into memory at load address specified in PSID file.
§Safety
Unsafe, as this will perform copy into hard-coded memory pool that may clash with stack or allocated heap memory.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.