From: charro@ee.ualberta.ca (Dan Charrois)
Subject: ProTracker player problems/C->ASM interfacing
Reply-To: charro@ee.ualberta.ca (Dan Charrois)
Organization: University of Alberta Electrical Engineering
Date: Mon, 27 Jul 1992 16:23:10 GMT

I am appealing to anyone who has used the ProTracker player routine
pt-ciaplay.s contained in the PT2.1 archive (and specifically if you have
interfaced it to C code..)  I am having a rather difficult problem.

First of all, the assembler I am using is A68k.  The player routine needed to
be modified a bit here and ther to make A68K but after some tweaking and
stuff, I managed to get the code generated by simply compiling and linking
the player routine to be identical to that produced by saving modules as an
executable using that capability in PT2.2a (after having added the same code
to display the song info, etc...).  So I suspect A68K isn't totally to blame.

Anyway, I can run the programs created this way and they work just fine.  The
problem comes in my attempts to interface the player to some C code I have.
Since I have never before tried to interface assembly to C on the Amiga before,
I could be missing some crucial step here or there...Basically I put in two
labels in the assembly - _StartSong & _EndSong.  Near the beginning of the code,
I also put a 	xdef _StartSong,_EndSong.  I got rid of the routines to check
for a mouse press in the assembly and instead inserted an RTS where they would
normally be.  _EndSong went in to reference the couple lines of code to
cancel the player.  (As far as I can understand it, nothing could be simpler...)

My C code has
void __asm far StartSong(void);
void __asm far EndSong(void);

up near the top..  I figure I had to use far since the assembly player routine
loads into Chip ram.  (And besides, that was the only way I could appease
Blink... :-)

Now, simple C code such as:
void main(void)
{
  StartSong();
  Delay(1000);
  EndSong();
}

works just fine - playing the song for a short time and then stopping.
However, if I go and insert a "char a" or something near the top so that
the compiler warns against an unreferenced variable (which shouldn't matter
anyway), the code executes fine - and even executes code after the EndSong()
if there is any, but immediately upon exiting, gurus the Amiga.  Suspecting
there was a stack problem somewhere, I changed the interrupt server to save
D0-D7/A0-A6 on the stack instead of D0-D4/A0-A6 as is in the code (and
retrieved the same too of course once it was complete).  Same problem.
Of course, there could be some data left on the stack or removed from the stack
that shouldn't be (a mistake in the code), but every +(A6) seems to have
a corresponding (A6)-... and besides, when checking the memory situation before
and after running the program, I find it to be identical.
It doesn't seem to be related to EndSong() either.  When I put the code in
an introduction sequence I am writing, it goes fine for awhile, then 
gurus (always at the same place) before getting to the EndSong().  Again, I
don't expect it to be the fault of the C code, since it works just fine without
using the ProTracker player.

I'm pulling my hair out with this one!  If anybody can give me some hints on
what may be going wrong, I'd love to hear them.  Who knows - you just may get
mentioned in the credits to my program...:-)

Please address all replies to dcharroi@sol.drao.nrc.ca - I don't read the
nets as often as I should.  Thanks a lot!

Dan
-- 
Dan Charrois - University of Alberta
INTERNET:= dcharroi@sol.drao.nrc.ca       charro@bode.ee.ualberta.ca