[comp.sys.atari.st] interrupt handling with Megamax C

sablone@dalcsug.UUCP (Aurelio Sablone) (06/25/87)

I'm using the Megamax C compiler and I would like to write an interrupt
handler for Timer A of the MFP 68901 chip.  I have tried many different
variations using Megamax's inline assembly, but I've repeatedly run into
compiler errors.  Some of which are quite confusing and irritating since
Megamax does not seem to recognize standard 68000 assembly mneumonics
such as bclr.b  #5, $fffffa0f.   Has anyone had any success or knows
anything about writing interrupt handlers with Megamax?  Any help will
be greatly appreciated.  Thanks in advance.....


						Aurelio.




	UUCP: ...! {seismo, utai, watmath} !dalcs!dalcsug!sablone

peter@megamax.UUCP (Peter Taliancich) (06/30/87)

Hello,

	The problem you are having with the Megamax inline asm{} is that you are
attempting to use a '$' for hex when in the compiler hex is '0x'.  Below is
a listing that should help you on your way with using the interrupt routine
with Megamax C.

<<-- Cut Here -->>

#include <osbind.h>


#define MyApp	0  /*  my application  		   */
#define Control	7  /*  divide by 200 prescale  */
#define Data	0  /*  Countdown from	       */
#define Off		0
#define NULL	0L


extern  dispatcher();	/* labels in in-line assembly must be declared. */
extern  saveA4();
extern  set_timer();
extern  unset_timer();


long ticks;			/* local tick counter.					*/


/*
	This routine is called by the interrupt handler to increment the 
	local tick counter.
*/
ticker()
{
	ticks++;
}


main()
{
	set_timer();		/* turn on timer */

	/*
		Keep on ticking...
	*/
	while(ticks < 500)
		printf("ticks == %ld\n", ticks);

	unset_timer();		/* turn off timer */
}




/* 
	This is the interrupt dispatcher routine.
*/
asm {
saveA4:
			dc.l	0			/* reserve space for saving the A4 register */

dispatcher:
			move.l	A4, -(A7)   /* save registers used in interrupt routine */
			move.l	saveA4, A4

			jsr		ticker		/* our function								*/

			move.l	(A7)+, A4   /* restore register state 					*/
			bclr.b	#5,0xfffa0f /* Tell MFP the interrupt has been serviced	*/
			rte		 			/* return from exception					*/
}


/*
	This function is callled by the main() function to set up the
	application the 68901.
*/
set_timer()
{
	register	char	*globals;


	/*
		Save the Globals register A4 so that it can be restored during
		the timer interrupt.
	*/
	asm {
			lea		saveA4, globals
			move.l	A4, (globals)
	}

	/*
		Tell the timer chip to call the dispatcher routine for the interrupt.
	*/
	Xbtimer(MyApp, Control, Data, dispatcher);
}


/*
	Turn off the timer and reset the terminate vector.
*/
unset_timer()
{
	/*
		Turn off the application timer.
	*/
	Xbtimer(MyApp, Off, Off, NULL);
}
-- 
peter@megamax

uucp:	{texsun,killer,infotel}!pollux!megamax!peter
voice:	(214) 987-4931