MYMPlayer in CC65

Since we do not have native C compilers on the Oric, this forum will be mostly be used by people using CC65 or the OSDK. But any general C related post will be welcome !
Post Reply
User avatar
xahmol
Flying Officer
Posts: 179
Joined: Sun Jun 28, 2020 7:32 pm
Location: Utrecht, The Netherlands
Contact:

MYMPlayer in CC65

Post by xahmol »

TL;DR:
Has anyone gotten MYMPlayer to work with CC65 and has sample code how to do so?

For start: sorry for the maybe n00b questions, I am a real beginner in C and certainly in dynamic memory allocation.

What I did so far:
- changed the MYMPlayer.s source to remove the fixed base address of the machine code and replace it with _startmusic and _endmusic externals and made a MYMPlayerlib.h file declaring functions for those externals.
- converted the MYMPlayer.s to a format that CC65 can use with xa -v -cc -R followed by co65 as explained in this thread ( https://forum.defence-force.org/viewtop ... f=3&t=1729 ).
- load the music data with the loadfile C code for Sedoric as made by ISS.
- start the music with the defined startmusic() function

This appears to work, but erratically. It appears the C runtime does not leave the player data alone in the memory area from $7600 and therefore changes the music data so the music becomes corrupted.
Code and variables in the compiler mapping is coming nowhere close to $7600, so guess it is the C runtime screwing up this memory area?

For my own routines for Windows and savegames I had the same issue storing these to a fixed memory location. This worked perfectly in my BASIC version of the program, but in C the data was getting corrupted. So changed to store the data at dynamically allocated locations using malloc().
Tried to do the same for the MYMPlayer routine, but I quickly encountered my limited knowledge of how to do this in the assembly part. Every attempt I did is ending in the startmusic routine immediately crashing, so what I tried to do obviously does not work. I think I even understand why, as just replacing the #define for the music data and buffer addresses to external declarations does not work probably without rewriting the assembly code itself as well. But that is a task that is not easy to do with my present knowledge of assembly.

So before I either skip music in the C version altogether or have to first really upgrade my grasp of assembly programming, anybody here that has already done this for MYMPlayer with sources I can reuse?
Thanks!

User avatar
Dbug
Site Admin
Posts: 3575
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: MYMPlayer in CC65

Post by Dbug »

Maybe check the zero page variables, it's possible that the MYM player uses things that are used by CC65.
The variables I'm using are compatible with the OSDK, but I've no idea what CC65 uses for its book keeping

User avatar
xahmol
Flying Officer
Posts: 179
Joined: Sun Jun 28, 2020 7:32 pm
Location: Utrecht, The Netherlands
Contact:

Re: MYMPlayer in CC65

Post by xahmol »

Dbug wrote:
Fri Feb 05, 2021 1:38 pm
Maybe check the zero page variables
First: sorry, pressed wrong button, not quote, so by accident reported the message instead of replying. Assume you are the admin here, so please ignore that report ;-)

As far as I can see, in the mymplayer.s source, all ZP declarations are not done absolutely but with variables aren't they? So should in that case not the CC65 linker do the bookkeeping of available ZP addresses in such a way that it only asigns addresses that it is not using itself, or otherwise report an error if it has to few places left?

Besides: in that case it is weird that the music routine is working at all. It plays flawlessly at first, but the music gets corrupted if running longer.

User avatar
xahmol
Flying Officer
Posts: 179
Joined: Sun Jun 28, 2020 7:32 pm
Location: Utrecht, The Netherlands
Contact:

Re: MYMPlayer in CC65

Post by xahmol »

Thought of one thing: 8 Bit Unity SDK is written for use in CC65 isn't it? So will check what is in that library for playing music on the Oric.

EDIT: Found it. See https://github.com/8bit-Dude/8bit-Unity ... oric/MYM.s

See 8 Bit Unity SDK actually uses the same mymplayer.s from OSDK as base, with similar adaptations as I made, but at a much higher base address for the music:

Code: Select all

_MusicData 		 =	$8800		
_PlayerBuffer 	 =	$9000		; .dsb 256*14 (About 3.5 kilobytes)
_PlayerBufferEnd =	$9fff
Will give that a try. At least has the advantage that a) is already in a format that CC65 can use b) should work as it does work in the 8 Bit Unity demos.
Downside is only that if this much higher addresses are indeed needed, only 2k of music data is available apparently..... ($8800-$9000). Which pretty much rules out any of the tracks I was using now.

Post Reply