SidTune

Trait SidTune 

Source
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 frame

Required Associated Constants§

Source

const BYTES: &'static [u8]

Full SID file as const byte array. Typically you would set this with core::include_bytes!.

Provided Associated Constants§

Source

const HAS_BASIC_LOAD_ADDRESS: bool = _

True if data has an optional 2-byte header stating the load address (C64 style)

Source

const DATA_OFFSET: usize = _

Offset where data begins, excluding any optional 2-byte load address

Source

const DATA_LEN: usize = _

Length of data part (exludes the optional 2-byte load address)

Source

const INIT_ADDRESS: u16 = _

Address of init routine

Source

const INIT_PTR: *const unsafe extern "C" fn() = _

Function pointer to init routine

Source

const PLAY_ADDRESS: u16 = _

Address of play routine

Source

const PLAY_PTR: *const unsafe extern "C" fn() = _

Function pointer to play routine

Source

const NUM_SONGS: usize = _

Number of subsongs

Source

const LOAD_ADDRESS: u16 = _

Load address found either in PSID header or in data part

Provided Methods§

Source

fn num_songs(&self) -> usize

Source

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.

Source

fn play(&self)

Call song play routine

Source

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.

Implementors§