[comp.sys.atari.st] TRAPs inside TRAPs

braner@batcomputer.tn.cornell.edu (braner) (11/10/86)

[]

In a recent posting I wrote:

> If you want to use OS calls (traps) inside an interrupt handler
> (something that is necessary but officially verboten), make sure
> the interrupted routine was not in supervisor mode.  This will
> ensure that, in particular, you are not calling a TRAP within a TRAP.
> (Thanks to whoever posted "WATCHER" here recently - that is where I
> took this idea from.)  The way to check that is to examine the CPU
> status which was saved on the stack as part of the exception processing.

That method works but is a bit restrictive, since sometimes it is OK
and desired to call the routine from a program that is in superviser
mode (e.g. from the desktop, or any interactive program that spends
most of its time inside OS calls waiting for user input).

Also, in the particular example of a custom screen dump routine, you'd
also want it to work when called via the XBIOS call Scrdmp().  In that
case the routine pointed to by the vector at $502 is again called via
two levels of subroutine calls, but the registers (EXCLUDING D0-D2/A0-A2,
but also the PC and status word - 46 bytes in all) are first saved NOT
on the stack but in a special area in low RAM (from $93A DOWN, like a
stack but limited in size - to 3 sets of those 46 bytes, I think.
A pointer to this stack is stored at $4A2).  So in this case the
BTST #5,68(SP) will NOT work!  Here is a modification that solves both
problems, albeit in a rather dirty way:

WARNING: The following (and preceding) info is unofficial and will
         probably change in future versions of the TOS ROMs.  Do NOT
         use this info in a program you expect others to use after
         such revisions.

	CMPI.L	#0xFC0786,4(SP)	/* Scrdmp xbios call?		*/
	BEQ.S	doit
	MOVE.L	0x04A2,A0	/* read SAVPTR system variable	*/
	CMPA	#0x093A,A0	/* no slots used in savptr?	*/
	BEQ.S	doit
	CMPA	#0x090C,A0	/* one slot used in savptr?	*/
	BNE	exit
	BTST	#5,68(SP)	/* user mode?			*/
	BNE	exit
doit:
	MOVE.W	#1,0x4EE	/* don't interrupt me again!	*/
	...			/* your screen dump code here	*/
exit:
	RTS

I now have a pair of programs, one that dumps the screen (upon
Alt-Help) into a file, in a format that is both compressed and
printable (mailable), the other decodes files like that, shows
them on the screen, and can print a hardcopy and/or save the
decoded picture in DEGAS or N-Vision format.  These programs
seem ideal for easy mailing of ST graphics between users.
The .tos files are rather short (about 3 and 6 Kbytes) but due
to the opposition to postings of binaries I will refrain for
the time being.

- Moshe Braner