[comp.sys.atari.st] PRGTOS --> ACC

to_stdnet@stag.UUCP (04/14/89)

From: stag!thelake!steve@bungia.mn.org (Steve Yelvington)


yz2y@vax5.cit.cornell.edu (Steve Coco) writes...

> 
> 	Since I don't have a lot of programming experience, i'll pose this
> question and see what kind of replies I get. 
> 	What does it take to turn a program into a desk accessory on the ST?
> 
>  					- Steve Coco

First off, you need to replace the normal program startup code with a
special (but simple) desk accessory startup module. If you're using a
commercial C compiler, it should include such a module. If you're using
Sozobon C, I can mail you DASTART.S, which I wrote and released several
months ago.

The second requirement is that the desk accessory (a) register itself with
GEM, then (b) go into an event loop in which it calls evnt_mesag() or
evnt_multi(). This allows your DA to "go to sleep" until it hears from the
GEM AES dispatcher.

Upon receiving a message from the AES, your desk accessory wakes up,
checks to make sure the message is indeed intended for it, and then does
whatever you want it to do -- using GEM and windows as necessary. That's
it.

If the program you wish to convert is not a GEM application, you need to:
	* manually save the top of the screen (the menu bar), 
	* open a GEM window the full size of the work area, 
	* hide the mouse, 
	* throw a VT52 clear-screen code at the console device, 
	* turn on the blinking cursor with another VT52 code,
... then run the bulk of your program. 

After it's finished, you:
	* turn off the VT52 blinking cursor,
	* show the mouse, 
	* manually restore the top of the screen,
	* close the GEM window, which causes the underlying application to
	  redraw the work areas under it,
	* return to the event loop.

Moshe Braner posted a nifty little skeleton program some time ago that
does these things. I may have it here somewhere. 

I believe that there is a requirement that your desk accessory not call
the GEMdos function Malloc(). There may be a couple of other "gotchas"
too. 

Braner has put together a mutant MicroEMACS called GNOME that
includes a desk accessory version. As you may know, MicroEMACS "mallocs
like hell," in the words of a programmer friend. I believe he got around
that problem by writing his own code that mallocs from a statically
allocated internal buffer. Get the code; it's worth staring at.

Here is a little skeleton desk accessory that pops up a file selector (and
does nothing with the results).

     O/  cut here
=====O\==================================================================

/*
 * accskel.c
 * desk accessory skeleton for Sozobon C
 * link dastart.o, then this module, then the GEM bindings, then dlibs.
 */

#define MENU_ID	"File selector"
#define AC_OPEN		30

/* these arrays are not needed for GEMFAST */
int	contrl[12], intin[128], intout[128], ptsin[128], ptsout[128];

main()
{

	int apid, menuid, msgbuf[8];
	apid = appl_init();	/* say hello to the AES */
	menuid = menu_register(apid, MENU_ID);	/* add me to the Desk menu */

	while (1)	/* loop forever */
	{
		evnt_mesag(msgbuf);
		if ( (msgbuf[0] == AC_OPEN) && (msgbuf[3] == menuid) )
			wakeup();
	}

	appl_exit();	/* you'll never get here -- supposedly */
}



wakeup()	/* display the file selector ... or whatever */
{
	char path[128], defult[13] = '\0';
	int button;
	fullpath(path,"*.*");
	fsel_input(path,defult,&button);
}


/*
 * UUCP: {uunet!rosevax,amdahl!bungia,chinet,killer}!orbit!thelake!steve
 * ARPA: crash!orbit!thelake!steve@nosc.mil
 * #member <STdNET> The ST Developers Network
 */