* resource file indicies for QUIKSTRT 
MAINMENU= 0	; menu tree 
DESK=     3	; TITLE in tree MAINMENU 
OPTIONS=  4	; TITLE in tree MAINMENU 
DSKABOUT= 7	; STRING in tree MAINMENU 
COLOR=    16	; STRING in tree MAINMENU 
PITCH=    17	; STRING in tree MAINMENU 
FONT=     18	; STRING in tree MAINMENU 
MACRO=    19	; STRING in tree MAINMENU 
QUIT=     20	; STRING in tree MAINMENU 

COLORFRM= 1	; form/dialog 
BLACK=    1	; BUTTON in tree COLORFRM 
RED=      2	; BUTTON in tree COLORFRM 
BLUE=     3	; BUTTON in tree COLORFRM 
ORANGE=   4	; BUTTON in tree COLORFRM 
YELLOW=   5	; BUTTON in tree COLORFRM 
VIOLET=   6	; BUTTON in tree COLORFRM 
GREEN=    7	; BUTTON in tree COLORFRM 

PITCHFRM= 2	; form/dialog 
CPI10=    1	; BUTTON in tree PITCHFRM 
HS12CPI=  2	; BUTTON in tree PITCHFRM 
HD12CPI=  3	; BUTTON in tree PITCHFRM 
CPI20=    4	; BUTTON in tree PITCHFRM 
CPI17=    5	; BUTTON in tree PITCHFRM 
CPI15=    6	; BUTTON in tree PITCHFRM 
PROPORT=  7	; BUTTON in tree PITCHFRM 

FONTFRM=  3	; form/dialog 
LQSANS=   1	; BUTTON in tree FONTFRM 
LQROMAN=  2	; BUTTON in tree FONTFRM 
LQCOUR=   3	; BUTTON in tree FONTFRM 
LQPREST=  4	; BUTTON in tree FONTFRM 
DRAFT=    5	; BUTTON in tree FONTFRM 

MACROFRM= 4	; form/dialog 
MACRO1=   3	; BUTTON in tree MACROFRM 
MACRO2=   4	; BUTTON in tree MACROFRM 
MACRO3=   5	; BUTTON in tree MACROFRM 
MACRO4=   6	; BUTTON in tree MACROFRM 

ABOUTFRM= 5	; form/dialog */
ABOUTOK1= 6	; BUTTON in tree ABOUTFRM */

BACKDROP=6	; form/dialog */

start:
	move.l	a7,stacksave
	move.l	4(a7),a3      ;basepage
	move.l	$C(a3),d0     ;text length
	add.l 	$14(a3),d0    ;data length
	add.l 	$1C(a3),d0    ;BSS length
	add.l 	#500,d0     ;any additional memory
	add.l 	#$100,d0      ;basepage length
*	move.l	#mystack,a7   ;before shrinking
	move.l	d0,-(a7)
	move.l	a3,-(a7)
	clr.w 	-(a7)
	move.w	#$4a,-(a7)
	trap	#1		;do the shrink
	lea	12(sp),sp     

	bsr	setupgem
	bsr	loadrsc
	tst.w	intout
	ble	leave
	move.w	#mainmenu,d0	;intin+2
	bsr	dorscgaddr
	move.l	a0,menuaddress
	bsr	changemouse
	bsr	dobackdrop
*	bsr	preset
	bsr	menubar
	bra	skipchange
mainloop:
	bsr	menutnormal
skipchange:
	bsr	dobackdrop
	bsr	eventmsg
	lea	msgpipe,a0	;where the message is
	cmpi.w	#10,(a0)	;is it menu selected
	bne.s	mainloop
	move.w	8(a0),d0	;object index for entry
	move.w	6(a0),menuchange
	cmpi.w	#dskabout,d0
	beq	doabout
	cmpi.w	#color,d0
	beq	docolor
	cmpi.w	#pitch,d0
	beq	dopitch
	cmpi.w	#font,d0
	beq	dofont
	cmpi.w	#macro,d0
	beq	domacro
	cmpi.w	#quit,d0
	beq	doquit
	bra.s	mainloop

dofont:
	move.w	#fontfrm,d0	;intin+2
	bsr	dorscgaddr
	move.l	a0,saveadr	
	move.w	#-1,deselect	;deselect the chosen button
	bsr	doform
dof0:
	cmpi.w	#lqsans,return
	bne.s	dof1
	lea	lqsansstring,a3
	bra	sendfont
dof1:
	cmpi.w	#lqroman,return
	bne.s	dof2
	lea	lqromanstring,a3
	bra	sendfont
dof2:
	cmpi.w	#lqcour,return
	bne.s	dof3
	lea	lqcourstring,a3
	bra	sendfont
dof3:
	cmpi.w	#lqprest,return
	bne.s	dof4
	lea	lqpreststring,a3
	bra	sendfont
dof4:
	cmpi.w	#draft,return
	bne.s	dof5
	lea	draftstring,a3
	moveq	#3,d2
	bra	sendfont2
dof5:
	bra	mainloop
sendfont:
	moveq	#6,d2
sendfont2:
	bsr	printit
	bra	mainloop

lqsansstring:
	dc.b	27,'x','1',27,'k',1
lqromanstring:
	dc.b	27,'x','1',27,'k',0
lqcourstring:
	dc.b	27,'x','1',27,'k',2
lqpreststring:
	dc.b	27,'x','1',27,'k',3
draftstring:
	dc.b	27,'x','0'

even
domacro:
	move.w	#macrofrm,d0	;intin+2
	bsr	dorscgaddr
	move.l	a0,saveadr	
	move.w	#-1,deselect	;deselect the chosen button
	bsr	doform
dm1:
	cmpi.w	#macro1,return
	bne	dm2
	lea	macro1string,a3
	bra	sendmacro
dm2:
	cmpi.w	#macro2,return
	bne	dm3
	lea	macro2string,a3
	bra	sendmacro
dm3:
	cmpi.w	#macro3,return
	bne	dm4
	lea	macro3string,a3
	bra	sendmacro
dm4:
	cmpi.w	#macro4,return
	bne	dm5
	lea	macro4string,a3
	bra	sendmacro
dm5:
	bra	mainloop

sendmacro:
*	move.l	a6,a3
	moveq	#11,d2
	bsr	printit
	bra	mainloop

macro1string:
	dc.b	27,126,65,27,48,49,0,27,48,48,0
macro2string:
	dc.b	27,126,65,27,48,49,1,27,48,48,0
macro3string:
	dc.b	27,126,65,27,48,49,2,27,48,48,0
macro4string:
	dc.b	27,126,65,27,48,49,3,27,48,48,0


dopitch:
	move.w	#pitchfrm,d0	;intin+2
	bsr	dorscgaddr
	move.l	a0,saveadr	
	move.w	#-1,deselect	;deselect the chosen button
	bsr	doform
dop0:
	cmpi.w	#cpi10,return
	bne.s	dop1
	lea	cpi10string,a3
	bra	sendpitch
dop1:
	cmpi.w	#hs12cpi,return
	bne.s	dop2
	lea	hs12cpistring,a3
	bra	sendpitch3
dop2:
	cmpi.w	#hd12cpi,return
	bne.s	dop3
	lea	hd12cpistring,a3
	bra	sendpitch3
dop3:
	cmpi.w	#cpi20,return
	bne.s	dop4
	lea	cpi20string,a3
	bra	sendpitch
dop4:
	cmpi.w	#cpi17,return
	bne.s	dop5
	lea	cpi17string,a3
	bra	sendpitch
dop5:
	cmpi.w	#cpi15,return
	bne.s	dop6
	lea	cpi15string,a3
	bra	sendpitch
dop6:
	cmpi.w	#proport,return
	bne.s	dop7
	lea	proportstring,a3
	moveq	#3,d2
	bra	sendpitch2
dop7:
	bra	mainloop

sendpitch:
	move.l	a3,a0
	lea	proportoff,a3
	moveq	#3,d2
	bsr	printit
	move.l	a0,a3
	moveq	#4,d2
sendpitch2:
	bsr	printit
	bra	mainloop

sendpitch3:
	move.l	a3,a0
	lea	proportoff,a3
	moveq	#3,d2
	bsr	printit
	lea	eliteon,a3
	moveq	#4,d2
	bsr	printit
	move.l	a0,a3
	moveq	#4,d2
	bsr	printit
	bra	mainloop

eliteon:
	dc.b	27,'~','3','1'
cpi10string:
	dc.b	27,'~','3','0'
hs12cpistring:
	dc.b	27,'~','B',0
hd12cpistring:
	dc.b	27,'~','B',1
cpi20string:
	dc.b	27,'~','3','7'
cpi17string:
	dc.b	27,'~','3','2'
cpi15string:
	dc.b	27,'~','3','6'
proportstring:
	dc.b	27,'p','1'
proportoff:
	dc.b	27,'p','0'

even
docolor:
	move.w	#colorfrm,d0	;intin+2
	bsr	dorscgaddr
	move.l	a0,saveadr	
	move.w	#-1,deselect	;deselect the chosen button
	bsr	doform
	lea	colorbyte,a0
doc0:
	cmpi.w	#black,return
	bne.s	doc1
	move.b	#0,(a0)
	bra.s	sendcolor
doc1:
	cmpi.w	#red,return
	bne.s	doc2
	move.b	#1,(a0)
	bra.s	sendcolor
doc2:
	cmpi.w	#blue,return
	bne.s	doc3
	move.b	#2,(a0)
	bra.s	sendcolor
doc3:
	cmpi.w	#orange,return
	bne.s	doc4
	move.b	#5,(a0)
	bra.s	sendcolor
doc4:
	cmpi.w	#yellow,return
	bne.s	doc5
	move.b	#4,(a0)
	bra.s	sendcolor
doc5:
	cmpi.w	#violet,return
	bne.s	doc6
	move.b	#3,(a0)
	bra.s	sendcolor
doc6:
	cmpi.w	#green,return
	bne.s	doc7
	move.b	#6,(a0)
	bra.s	sendcolor
doc7:
	bra	leave
sendcolor:
	lea	colorstring,a3
	moveq	#3,d2
	bsr	printit
	bra	mainloop
	
colorstring:
	dc.b	27,'r'
colorbyte:
	dc.b	0		;filled in later
even
doabout:
	move.w	#aboutfrm,d0	;intin+2
	bsr	dorscgaddr
	move.l	a0,saveadr	
	move.w	#1,deselect	;deselect the chosen button
	bsr	doform
	bra.L	mainloop
dobackdrop:
	move.w	#backdrop,d0	;intin+2
	bsr	dorscgaddr
	move.l	a0,saveadr	
	move.w	#-1,deselect	;deselect the chosen button
	bsr	drawob
	rts

leave:
	move.l	stacksave,sp
	clr.l	-(sp)
	trap	#1

preset:
	lea	reset,a3
	moveq	#2,d2			;it's 2 bytes
	bsr	printit			;reset printer!
	rts				;and exit!

reset:
	dc.b	27,'@'
****************************
* print string to printer  *
*--------------------------*
* input:                   *
* d2.L # of bytes to print *
* a3: address of 1st byte  *
* returns:                 *
* d0 = -1: error!          *
* d0 =  0: OK!             *
****************************

printit:
	move.l	#270000,d1	;timeout count (works out to +/- 30 secs.)

statloop:
				;save registers on stack
	movem.l	a0-a2/d1-d2,-(sp)
				;Request printer
	clr.w	-(sp)		;output status
	move.w	#8,-(sp)
	trap	#13
	addq.l	#4,sp
	movem.l	(sp)+,a0-a2/d1-d2
	tst.l	d0		;printer ready?
	bmi	prtrdy		;yes!
	subq.l	#1,d1		;decrement timeout counter
	bpl	statloop		;and try again
	bsr	doalert1

	move.w	#-1,d0		;printer error!
	rts

prtrdy:
	movem.l	a0-a2/d1-d2,-(sp)
	move.b	(a3),d0		;get byte to print
	andi.w	#$00FF,d0	;mask off to be safe
	move.w	d0,-(sp)		;put on stack
	clr.w	-(sp)		;device #0 (printer)
	move.w	#3,-(sp)		;conout
	trap	#13		;send to printer!
	addq.l	#6,sp
	movem.l	(sp)+,a0-a2/d1-d2
	addq.l	#1,a3		;point to next byte
	subq.w	#1,d2		;decrement counter
	bne	printit		;loop if more bytes
	clr.w	d0		;OK!
	rts

********************************
changemouse:
	move.w	#78,opcode
	move.w	#1,contrl+2
	move.w	#1,contrl+4
	move.w	#1,contrl+6
	move.w	#0,contrl+8
	move.w	#0,intin		;choose the arrow
	move.l	#0,addrin
	move.l	#aespb,d1
	move.w	#$c8,d0
	trap	#2
	rts
menutnormal:
	move.w	#33,opcode		;menu tnormal
	move.w	#2,contrl+2
	move.w	#1,contrl+4
	move.w	#1,contrl+6
	move.w	#0,contrl+8
	move.w	menuchange,intin
	move.w	#1,intin+2
	move.l	menuaddress,addrin
	move.l	#aespb,d1
	move.w	#$c8,d0
	trap	#2
	rts


drawob:
	move.w	#54,opcode	;form centre
	move.w	#0,contrl+2
	move.w	#5,contrl+4
	move.w	#1,contrl+6
	move.w	#0,contrl+8
	move.l	a0,addrin
	move.l	#aespb,d1
	move.w	#$c8,d0
	trap	#2
	move.w	intout+2,obx
	move.w	intout+4,oby
	move.w	intout+6,obw
	move.w	intout+8,obh
	move.w	#42,opcode	;objdraw
	move.w	#6,contrl+2
	move.w	#1,contrl+4
	move.w	#1,contrl+6
	move.w	#0,contrl+8
	move.w	#0,intin		;start obj ?
	move.w	#3,intin+2		;level ?
	move.w	obx,intin+4
	move.w	oby,intin+6
	move.w	obw,intin+8
	move.w	obh,intin+10
	move.l	saveadr,addrin
	move.l	#aespb,d1
	move.w	#$c8,d0
	trap	#2
	rts

doform:
	move.w	#54,opcode	;form centre
	move.w	#0,contrl+2
	move.w	#5,contrl+4
	move.w	#1,contrl+6
	move.w	#0,contrl+8
	move.l	a0,addrin
	move.l	#aespb,d1
	move.w	#$c8,d0
	trap	#2
	move.w	intout+2,obx
	move.w	intout+4,oby
	move.w	intout+6,obw
	move.w	intout+8,obh

	move.w	#51,opcode	;form dial
	move.w	#9,contrl+2
	move.w	#1,contrl+4
	move.w	#1,contrl+6
	move.w	#0,contrl+8
	move.w	#0,intin	;reserve
	move.w	#0,intin+2
	move.w	#0,intin+4
	move.w	#0,intin+6
	move.w	#0,intin+8
	move.w	obx,intin+10
	move.w	oby,intin+12
	move.w	obw,intin+14
	move.w	obh,intin+16
	move.l	#aespb,d1
	move.w	#$c8,d0
	trap	#2

	move.w	#42,opcode	;objdraw
	move.w	#6,contrl+2
	move.w	#1,contrl+4
	move.w	#1,contrl+6
	move.w	#0,contrl+8
	move.w	#0,intin		;start obj ?
	move.w	#3,intin+2		;level ?
	move.w	obx,intin+4
	move.w	oby,intin+6
	move.w	obw,intin+8
	move.w	obh,intin+10
	move.l	saveadr,addrin
	move.l	#aespb,d1
	move.w	#$c8,d0
	trap	#2

	move.w	#50,opcode	;form do
	move.w	#1,contrl+2
	move.w	#2,contrl+4
	move.w	#1,contrl+6
	move.w	#0,contrl+8
	move.w	#0,intin		;start obj ?
	move.l	saveadr,addrin
	move.l	#aespb,d1
	move.w	#$c8,d0
	trap	#2
	move.w	intout,return

	tst.w	deselect
	bmi	skipdeselect
	move.l	saveadr,a0
	move.w	return,d0
	mulu	#24,d0
	add.l	d0,a0
	move.w	#0,10(a0)

skipdeselect:
	move.w	#51,opcode	;form dial
	move.w	#9,contrl+2
	move.w	#1,contrl+4
	move.w	#1,contrl+6
	move.w	#0,contrl+8
	move.w	#3,intin	;free
	move.w	#0,intin+2
	move.w	#0,intin+4
	move.w	#0,intin+6
	move.w	#0,intin+8
	move.w	obx,intin+10
	move.w	oby,intin+12
	move.w	obw,intin+14
	move.w	obh,intin+16
	move.l	#aespb,d1
	move.w	#$c8,d0
	trap	#2
	rts

**********************************
doquit:
	lea	alerttext1,a0
	bsr	doalert
	cmpi.w	#2,intout
	beq	leave
	bra	mainloop
doalert1:
	lea	alerttext2,a0
	bsr	doalert
	cmpi.w	#2,intout
	beq	leavea
	rts
leavea:
	addq.l	#8,sp
	bra	mainloop

doalert:
	move.w	#52,opcode
	move.w	#1,contrl+2
	move.w	#1,contrl+4
	move.w	#1,contrl+6
	move.w	#0,contrl+8
	move.w	#1,intin
	move.l	a0,addrin
	move.l	#aespb,d1
	move.w	#$c8,d0
	trap	#2
	rts

alerttext1:
	dc.b	'[2][Do you really|'
	dc.b	'want to quit ?]'
	dc.b	'[NO|YES]',0,0
alerttext2:
	dc.b	'[1][PRINTER TROUBLE|'
	dc.b	'please check that the printer|'
	dc.b	'is online.]'
	dc.b	'[CONTINUE|QUIT]',0,0
even
loadrsc:
	move.w	#110,opcode		;load the resource
	move.w	#0,contrl+2
	move.w	#1,contrl+4
	move.w	#1,contrl+6
	move.w	#0,contrl+8
	move.l	#myresource,addrin
	move.l	#aespb,d1
	move.w	#$c8,d0
	trap	#2
	rts

dorscgaddr:
	move.w	#112,opcode		;rsrc_gaddr
	move.w	#2,contrl+2
	move.w	#1,contrl+4
	move.w	#0,contrl+6
	move.w	#1,contrl+8
	move.w	#0,intin		;gtype always tree
	move.w	d0,intin+2		;gindex
	move.l	#aespb,d1
	move.w	#$c8,d0
	trap	#2
	move.l	addrout,a0		;returned address
	rts

menubar:
	move.w	#30,opcode		;draw the menu
	move.w	#1,contrl+2
	move.w	#1,contrl+4
	move.w	#1,contrl+6
	move.w	#0,contrl+8
	move.w	#1,intin		;draw the menu bar
	move.l	menuaddress,addrin
	move.l	#aespb,d1
	move.w	#$c8,d0
	trap	#2
	rts
eventmsg:
	move.w	#23,opcode		;draw the menu
	move.w	#0,contrl+2
	move.w	#1,contrl+4
	move.w	#1,contrl+6
	move.w	#0,contrl+8
	move.l	#msgpipe,addrin
	move.l	#aespb,d1
	move.w	#$c8,d0
	trap	#2
	rts


myresource:
	dc.b	'QUIKMENU.RSC',0,0
even
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


aespb:
	dc.l	contrl,global,intin,intout,addrin,addrout
contrl:
opcode:	dc.w	10
sintin:	dc.w	0
sintout:dc.w	1
saddrin:dc.w	0
saddrout:dc.l	0
	blk.w	5,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:
	blk.w	128,0
ptsin:
	blk.w	128,0
intout:
	blk.w	128,0
ptsout:
	blk.w	128,0
addrin:
	blk.w	128,0
addrout:
	blk.w	128,0
vdipb:
	dc.l	contrl,intin,ptsin,intout,ptsout
grhandle:	dc.w	0
stacksave:	dc.l	0
menuaddress:	dc.l	0
msgpipe:	blk.b	16,0
saveadr:	dc.l	0
obx:		dc.w	0
oby:		dc.w	0
obh:		dc.w	0
obw:		dc.w	0
return:		dc.w	0
deselect:	dc.w	-1
menuchange:	dc.w	0
