[comp.sys.atari.st] Autostarting programs after GEM has initialized

ron@oscvax.UUCP (12/16/86)

This is a little kludge that we whipped up at the Science Centre
to autostart a program after the ST has fully initialized. It isn't
pretty but it was sufficient for our purposes.

Ron Janzen
Ontario Science Centre, Toronto
...!{allegra,ihnp4,decvax,pyramid}!utzoo!oscvax!ron

---------cut here-----------cut here------------cut here--------
: This is a shar archieve.  Extract with sh, not csh.
: Extraction terminated by end of archive message.
: The rest of this file will extract:
: README dc.c vbl.s dc.uue
echo x - README
sed 's/^X//' > README << '/*EOF'
XAs many of us probably know (by experience or word of mouth) programs
Xthat are located in the AUTO folder are executed before the ST is fully
Xinitialized.  This means that some programs that work perfectly from the
Xdesktop will not work if they are put into the AUTO folder.  Since we
Xare in a museum environment, the exhibit application has to start
Xautomatically every morning when the power is turned on to all the
Xexhibits.  Since one program that we had written didn't work when it was
Xput into the AUTO folder we had to come up with another method.  This is
Xwhat I came up with.  It is an amusing kludge but it is the only thing
Xthat worked reasonably well.  Basically what happens is that we fool the
XGEM desktop into thinking there was a double click from the mouse.  If
Xthe cursor happens to be over an application at the time, that
Xapplication will start up.  This is implemented as a desk accessory. 
X
XHow to create a floppy that will automatically start a program from the desktop:
X1) Create a bootable floppy with the application you want to autostart.
X2) Copy DC.ACC onto the floppy and rename it to DC.PRG (you will see why later)
X3) Set up your desktop so that the application is under the bootup cursor
X   position (the cursor is in the middle of the screen when the GEM desktop
X   starts).
X4) Save the desktop.
X5) Reboot the ST with this floppy to verify that the cursor is over the
X   application after the desktop has booted. If it is not, go back to
X   step 3 and make any required adjustments (I told you it was kludgy).
X6) Rename DC.PRG back to DC.ACC
X7) Now when you boot off this floppy the application should automatically
X   start from the desktop. 
X
XRon Janzen (ron@oscvax.UUCP)
XOntario Science Centre, Toronto
/*EOF
echo x - dc.c
sed 's/^X//' > dc.c << '/*EOF'
X/*
X * A desk accessory that inserts a vbl routine to delay for a while and
X * then fake a double click of the mouse.  This can be used to autostart
X * programs that expect the ST to be fully initialized (unlike the state
X * the ST is in when starting programs from the AUTO folder).  I tried this
X * as a program that I put in the AUTO folder but it didn't work. 
X *
X * Ron Janzen (ron@oscvax.UUCP)
X * Ontario Science Centre
X *
X * Link: accstart,dc,vbl,osbind,aesbind
X */
X
X#include <portab.h>
X#include <osbind.h>     
X
X#ifdef VOID
X#undef VOID
X#endif
X#define VOID	int
X
Xtypedef struct KbdVectors {
X    LONG midivec;	/* MIDI input */
X    LONG vkbderr;	/* keyboard error */
X    LONG vmiderr;	/* MIDI error */
X    LONG statvec;	/* ikbd status packet */
X    LONG mousevec;	/* mouse packet */
X    LONG clockvec;	/* clock packet */
X    LONG joyvec;	/* joystick packet */
X    LONG midisys;	/* system MIDI vector */
X    LONG ikbdsys;	/* system IKBD vector */
X} KbdVectors;
X
X#define NVBLS		*(WORD *)0x454
X#define VBLQUEUE	*(LONG *)0x456
X
XWORD VblEntry;		/* save the VBL entry that we used */
XLONG *MouseVec;		/* address of vec->mousevec */
X
Xmain()
X{ 
X    extern VOID insertVbl();
X    extern VOID _Absorb();	/* absorb real mouse interrupts */
X    extern LONG MousIntVec;	/* original mouse interrupt routine */
X
X    KbdVectors *vec;		/* pointer to interrupt vectors */
X
X    appl_init();
X
X    /*
X     * save the mouse interrupt vector so we can feed fake interrupts
X     * into it. Also set it up so that real mouse interrupts are
X     * ignored.
X     */
X    vec = (KbdVectors *)Kbdvbase();
X    MousIntVec = vec->mousevec;
X    MouseVec = &vec->mousevec;
X    vec->mousevec = (LONG)_Absorb;
X
X    /*
X     * insert the routine that will generate the fake double click
X     * into the vbl queue
X     */
X    Supexec( (LONG)insertVbl );
X
X    /*
X     * since desk accessories never die we have to do something
X     */
X    for (;;)
X	evnt_timer( 30000, 0 );	/* wait 30 sec */
X}
X
XinsertVbl()
X{
X    WORD vblIndex;
X    LONG *vblQ;
X
X    extern VOID _Vbl_int();	/* vbl routine to add */
X
X    for ( vblIndex = 0, vblQ = VBLQUEUE; vblIndex < NVBLS; vblIndex++, vblQ++ )
X	if ( *vblQ == 0L ) {
X	    *vblQ = (LONG)_Vbl_int;
X	    VblEntry = vblIndex;
X	    break;
X	}
X}
X
X/*
X * this routine is called from the VBL interrupt routine
X */
XextractVbl()
X{
X    LONG *vblQ;
X
X    extern LONG MousIntVec;
X
X    vblQ = VBLQUEUE;
X    vblQ[VblEntry] = 0L;
X
X    *MouseVec = MousIntVec;	/* restore mouse interrupt vector */
X}
/*EOF
echo x - vbl.s
sed 's/^X//' > vbl.s << '/*EOF'
X*
X* The VBL routine which waits for a while and then fakes a double
X* click of the mouse.
X*
X* Ron Janzen (ron@oscvax.UUCP)
X* Ontario Science Centre
X*
X* Register Usage:
X* d0 - used to hold ClickCount
X* d1 - used to hold DelayCount
X* a0 - pointer to mouse packet as expected by mouse interrupt routine
X* a1 - pointer to mouse interrupt vector
X*
X
XINIT_DELAY	equ	2*60	; initial delay
XDOWNTIME	equ	5	; amt of time to hold button down
XCLICKTIME	equ	5	; amt of time between clicks
X
X	.globl	__Vbl_int
X	.globl	__Absorb	; absorb real mouse interrupts
X	.globl	_MousIntVec	; mouse interrupt vector
X
X	.text
X
X__Vbl_int:
X	move.b	_ClickCount, d0
X	bgt.s	delay
X*
X* if we have done the double click, extract ourselves from
X* the VBL queue
X*
X	jmp	_extractVbl	; _extractVbl will do the reqd rts
X
Xdelay:
X	move.w	_DelayCount, d1
X	beq.s	sendclick
X	subq.w	#1, d1
X	move.w	d1, _DelayCount
X__Absorb:
X	rts
X
Xsendclick:
X	lea	_MPacket, a0
X	btst.l	#0, d0		; is button going down or up
X	beq.s	butDown
X	move.b	#$f8, (a0)	; load mouse button up event
X	move.w	#CLICKTIME, _DelayCount
X	bra.s	sendit
XbutDown:
X	move.b	#$fa, (a0)	; load mouse button down event
X	move.w	#DOWNTIME, _DelayCount
Xsendit:
X	subq.b	#1, d0
X	move.b	d0, _ClickCount
X	move.l	_MousIntVec, a1	; get mouse interrupt vector
X	jmp	(a1)		; and jump there
X
X	.data
X	.even
X
X_MousIntVec:	ds.l	1		; the mouse interrupt vector
X_DelayCount:	dc.w	INIT_DELAY	; time to delay before fake outs
X_ClickCount:	dc.b	4		; the number of up and down clicks
X_MPacket:	dc.b	0,0,0		; the fake mouse packet
/*EOF
echo x - dc.uue
sed 's/^X//' > dc.uue << '/*EOF'
Xbegin 644 dc.acc
XM8!H   *"   !9@  !)                   "Y\   '[$ZY    ("Z\    
XM $Y!(B\ !# \ ,A.0DYU3E;_^$ZY   ![#Z\ ").N0   5(M0/_\(&[__"/H
XM !    />("[__-"\    $"/    (8B!N__PA?    1H $"Z\    AC\\ "9.
XMN0   5)4CT)7/SQU,$ZY   "8%2/8/!.7DYU3E;_]D)N__XM>0  !%;_^F D
XM(&[_^DJ09A0@;O_Z(+P   #\,^[__@  ""I@%%)N__Y8KO_Z,#D   14L&[_
XM_F[03EY.=4Y6__@M>0  !%;__#!Y   (*M'(T<C1[O_\(+P     ('D   AB
XM(+D   />3EY.=1 Y   #Y&X&3OD   #,,CD   /B9PI303/!   #XDYU0?D 
XM  /E"    &<.$+P ^#/\  4   /B8 P0O #Z,_P !0   ^)3 !/    #Y")Y
XM   #WD[1(]\   ?P3DXO.0  !_!.=2/?   '\$Y-+SD   ?P3G4CWP  !_!.
XM02\Y   '\$YU3E;_]C/N  @   @L,"X "-!\__;!_  #2,#0O    H(M0/_Z
XM/7P  ?_^8!X@;O_Z$!!(@#)N__[3R=/\   (+#* 4J[_^E)N__X,;@ $__YM
XMVBZY   (9DZY    %$) ,#D   A43EY.=4Y6__HC_   ""P   ?T(_P   @,
XM   '^"/\   (-   !_PC_   "%0   @ (_P   AL   (!"/\   (=   " @C
XM_   !_0   AF/KP "F$ _T8S^0  "%0   AJ< %.7DYU3E;__#Z\ !-A /\J
XM< %.7DYU3E;__#/N  @   @T,^X "@  "#8^O  83KD   &"3EY.=0 !  (!
XM 0(! 0 ! 0(! 0$! 0             !   !  ,%  4%   ! 0(! ! ' 0(!
XM              $! 0(! 0(! 0(! 0$! @$! 0                (! 0$!
XM 08! 00! 0$# 0(! 00" 0@! 0        $! 0D! 0$! 0$!   % 0      
XM                                                      0#  @#
XM  8!  @!  @!  0! 0,! 0 %  $! 0 %   ! 0 ! 0                  
XM               " @                                    4!  4!
XM  $!  $!  (%  8!  (!  $!  8%       ! 0 !  (!  (! 0$! 0      
XM               ! @,! @$! 0$! 0 ! 0 ! @      > 0        "!AX*
XM$! *" H.+ @L% 8*" 8*"!(." 8(" @(" @.%" 8!@@.! 8$!@0&! 8$!@0&
X'! X$) @*  @L
X 
Xend
/*EOF
echo end of archive
exit 0
-- 
Ron Janzen
Ontario Science Centre, Toronto
...!{allegra,ihnp4,decvax,pyramid}!utzoo!oscvax!ron