Re: [cc65] Playing a PSID file

From: Marc 'BlackJack' Rintsch <>
Date: 2011-11-05 09:27:14
Hi Payton,

> I've done some initial googling and haven't found anything, so I want
> to pose a general question "What's the best way to play a PSID file
> from cc65" and to expand on what I believe the steps to be and the
> issues that I need to understand.
> 1) Assume I have a PSID that has loads at $1000 through $1900.  It
> inits at $1000 and plays at $1003.
> 2) I need to load that PSID into memory.  I'm assuming I can simply
> put the bytes of the data into an ASM file and it will get linked
> into the program at $1000.  However, I do need to understand if
> there will need to be any custom memory mappings for this and
> exactly what syntax to use in the ASM file to accomplish setting the
> bytes at a specific memory location.

Including the data can be done with the ``.incbin`` command in the 
assembler file.  Use the offset argument to skip the PSID header.

Placing the data at a specific memory location requires a little more 
than just assembler syntax.  What ends up where is decided by the linker 
and the linker configuration you have to write.  The memory from $1000 
upwards is part of the memory where cc65 and the runtime can put code, 
data, and stack, so you have to write a memory configuration to protect 
the space for your music and define a segment to place it there.

So the assembler file might look like this:

  .export _music_init, _music_play
  .segment MUSIC_SEGMENT
      _music_init = *
      _music_play = _music_init + 3
      .incbin "music.sid", $7c	; $7c = offset of data in PSIDv2 format

Here is the header file to use it from C:

  #ifndef MUSIC_H
  #define MUSIC_H

  #include <stdint.h>

  void __fastcall__ music_init(uint8_t song_number);
  void music_play(void);


	Marc 'BlackJack' Rintsch
“Programmers should be paid by the amount of code
 that they avoid writing.”  -- Michael P. Soulier

To unsubscribe from the list send mail to with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Sat Nov 5 09:44:44 2011

This archive was generated by hypermail 2.1.8 : 2011-11-05 09:44:48 CET