setupgem:
	move.l	#0,ap1resv
	move.l	#0,ap2resv
	move.l	#0,ap3resv
	move.l	#0,ap4resv
	move.w	#10,opcode
	move.w	#0,sintin
	move.w	#1,sintout
	move.w	#0,saddrin
	move.w	#0,saddrout
	move.l	#_aespb,d1
	move.w	#$c8,d0
	trap	#2
	move.w	#77,opcode
	move.w	#0,sintin
	move.w	#5,sintout
	move.w	#0,saddrin
	move.w	#0,saddrout
	move.l	#_aespb,d1
	move.w	#$c8,d0
	trap	#2
	move.w	_intout,grhandle
	move.w	#100,opcode
	move.w	#0,_contrl+2
	move.w	#11,_contrl+6
	move.w	grhandle,_contrl+12
	move.w	#1,_intin
	move.w	#1,_intin+2
	move.w	#1,_intin+4
	move.w	#1,_intin+6
	move.w	#1,_intin+8
	move.w	#1,_intin+10
	move.w	#1,_intin+12
	move.w	#1,_intin+14
	move.w	#1,_intin+16
	move.w	#1,_intin+18
	move.w	#1,_intin+20
	move.l	#_vdipb,d1
	move.w	#$73,d0
	trap	#2
	rts
closegem:
	move.w	#101,opcode		;close vwork
	move.w	#0,_contrl+2
	move.w	#0,_contrl+4
	move.w	#0,_contrl+6
	move.w	#0,_contrl+8
	move.w	grhandle,_contrl+12
	move.l	#_vdipb,d1
	move.w	#$73,d0
	trap	#2
	rts
_aespb:
	dc.l	_contrl,_global,_intin,_intout,_addrin,_addrout
_vdipb:
	dc.l	_contrl,_intin,_ptsin,_intout,_ptsout

_contrl:
opcode:		dc.w	10
sintin:		dc.w	0
sintout:	dc.w	1
saddrin:	dc.w	0
saddrout:	dc.l	0
		dc.w	0,0,0,0,0
_global:
apversion:	dc.w	0
apcount:	dc.w	0
apid:		dc.w	0
apprivate:	dc.l	0
apptree:	dc.l	0
ap1resv:	dc.l	0
ap2resv:	dc.l	0
ap3resv:	dc.l	0
ap4resv:	dc.l	0

_intin:
	ds.w	128
_ptsin:
	ds.w	128
_intout:
	ds.w	128
_ptsout:
	ds.w	128
_addrin:
	ds.w	128
_addrout:
	ds.w	128
grhandle:	dc.w	0
