Jump to content

Coming soon: Zsound support in C for cc65

Recommended Posts

During my recent project working with @Wavicle on making a test application for the YM2151, I got some good experience doing hybrid C/ASM. It turned out to be pretty easy to handle the __fastcall__ conventions, so I decided to throw together the C wrapper module for Zsound and see if it works or not. I've done the music player, and the "hello world" music player worked right away.


That's how easy it is to get background music playing in cc65 now!

I haven't merged this into the main branch, as there's still testing to be done, especially with the callback routine - just to make sure it doesn't crash stuff.

Plus, the documentation needs to be updated, etc - but it's coming soon!


  • Like 4
Link to comment
Share on other sites

I'm hijacking this topic for this one post (sorry!!!!)  but with ZeroByte's help we just got the player running in Prog8 as well!   This is amazing!!


%import textio
%import cx16diskio
%zeropage basicsafe
%zpreserved $22,$28     ; zsound lib uses this region

main $0830 {
; TODO: don't like to have *main* at a set start address, but otherwise the compiler puts it at the front, overwriting another module that we wanted there

    ; this has to be the first statement to make sure it loads at the specified module address $0830
    %asmbinary "zsmplayer-0830.bin"

    ; note: jump table is offset by 2 from the load address (prg header)
    romsub $0832 = zsm_init() clobbers(A)
    romsub $0835 = zsm_play() clobbers(A, X, Y)
    romsub $0838 = zsm_playIRQ() clobbers(A, X, Y)
    romsub $083b = zsm_start(ubyte bank @A, uword song_address @XY) clobbers(A, X, Y) -> ubyte @Pc
    romsub $083e = zsm_stop()
    romsub $0841 = zsm_setspeed(uword hz @XY) clobbers(A, X, Y)
    romsub $0844 = zsm_setloop(ubyte count @A)
    romsub $0847 = zsm_forceloop(ubyte count @A)
    romsub $084a = zsm_noloop()
    romsub $084d = zsm_setcallback(uword address @XY)
    romsub $0850 = zsm_clearcallback() clobbers(A)
    romsub $0853 = zsm_get_music_speed() clobbers(A) -> uword @XY

    const ubyte song_bank = 1
    const uword song_address = $a000

    sub start() {
        txt.print("zsound demo program!\n")

        if not cx16diskio.load_raw(8, "colony.zsm", song_bank, song_address) {
            txt.print("?can't load song\n")
        cx16.rambank(1)  ; ram bank to default

        if zsm_start(song_bank, song_address)==0 {
            txt.print("music speed: ")
            txt.print(" hz\nplaying song! hit enter to stop.\n")
            while cx16.joystick_get2(0)==$ffff {
        } else {
            txt.print("?song start error\n")

        ; TODO set Vera back to sane state?

    sub end_of_song_cb() {
        txt.print("end of song!\n")
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

Please review our Terms of Use