	opt o+,l+

*  Sorry no comments - I threw this program together in about an hour,
*  so it isn't exactly the best code ever!!
*
*  This should be fairly obvious if you want to get the info for the
*  Microwire interface (Mode/Tone control) from it, but the programmers
*  docs should be available by now anyway.

	include 'c:\assembly\gemmacro.s'

AUDIO    	equ 0	* form/dialog 
BEEPYES  	equ 9	* BUTTON in tree AUDIO 
BEEPNO   	equ 10	* BUTTON in tree AUDIO 
SAVE       	equ 12	* BUTTON in tree AUDIO 
EXIT   	equ 13	* BUTTON in tree AUDIO 
TEST     	equ 26	* BUTTON in tree AUDIO 
MVCOVER  	equ 27	* IBOX in tree AUDIO 
MVBOX    	equ 28	* IBOX in tree AUDIO 
MVSLIDER 	equ 29	* BOXTEXT in tree AUDIO 
LVCOVER  	equ 30	* IBOX in tree AUDIO
LVBOX    	equ 31	* IBOX in tree AUDIO
LVSLIDER 	equ 32	* BOXTEXT in tree AUDIO
RVCOVER  	equ 33	* IBOX in tree AUDIO
RVBOX    	equ 34	* IBOX in tree AUDIO
RVSLIDER 	equ 35	* BOXTEXT in tree AUDIO
TCOVER   	equ 36	* IBOX in tree AUDIO
TBOX     	equ 37	* IBOX in tree AUDIO
TSLIDER  	equ 38	* BOXTEXT in tree AUDIO
BCOVER   	equ 39	* IBOX in tree AUDIO
BBOX     	equ 40	* IBOX in tree AUDIO
BSLIDER  	equ 41	* BOXTEXT in tree AUDIO

	clr.l -(sp)
	move.w #32,-(sp)
	trap #1
	addq #6,sp
	move.w #$07ff,$ff8924
	move.l d0,-(sp)
	move.w #32,-(sp)
	trap #1
	addq #6,sp
	clr.w -(sp)
	pea.l SetupFile
	move.w #61,-(sp)
	trap #1
	addq #8,sp
	tst.l d0
	bmi NoFile
	move.w d0,-(sp)
	pea.l LeftVolume
	pea.l 6
	move.w d0,-(sp)
	move.w #63,-(sp)
	trap #1
	lea.l 12(sp),sp
	move.w #62,-(sp)
	trap #1
	addq #2,sp
NoFile:	clr.w -(sp)
	pea.l SampleFile
	move.w #61,-(sp)
	trap #1
	addq #8,sp
	tst.l d0
	bmi NoSamp
	move.w d0,-(sp)
	pea.l Buffer
	pea.l $400000
	move.w d0,-(sp)
	move.w #63,-(sp)
	trap #1
	lea.l 12(sp),sp
	move.l d0,SampleLen
	move.w #62,-(sp)
	trap #1
	addq #2,sp
	lea.l Buffer,a0
	move.l SampleLen,d0
ConvertSample:	eor.b #$80,(a0)+
	sub.l #1,d0
	bne ConvertSample
NoSamp:	appl_init
	graf_mouse #0,#0

	clr.w d7
InitLoop:	rsrc_obfix #Audio,d7
	addq.w #1,d7
	cmp.w #rsrc_length,d7
	ble InitLoop

	move.b MasterVolume,d0
	bsr SetMV
	move.b LeftVolume,d0
	bsr SetLV
	move.b RightVolume,d0
	bsr SetRV
	move.b Treble,d0
	bsr SetT
	move.b Bass,d0
	bsr SetB
	bsr SetBeeper
	move.b BeeperFlag,d0
	move.b d0,BeepYesFlag
	eor.b #1,d0
	move.b d0,BeepNoFlag
	form_center #Audio
	move.w int_out+2,WinX
	move.w int_out+4,WinY
	move.w int_out+6,WinW
	move.w int_out+8,WinH
	form_dial #0,WinX,WinY,WinW,WinH,WinX,WinY,WinW,WinH
	objc_draw #Audio,#0,#50,WinX,WinY,WinW,WinH
	clr.b TestFlag
	clr.b OKFlag
	clr.b CancelFlag
ReDo:	form_do #Audio,#0
	move.w int_out,d0
	cmp.w #SAVE,d0
	beq FiniSave
	cmp.w #EXIT,d0
	beq FiniExit
	cmp.w #TEST,d0
	beq MakeNoise
	cmp.w #MVSLIDER,d0
	beq MVSlide
	cmp.w #LVSLIDER,d0
	beq LVSlide
	cmp.w #RVSLIDER,d0
	beq RVSlide
	cmp.w #TSLIDER,d0
	beq TSlide
	cmp.w #BSLIDER,d0
	beq BSlide
	cmp.w #BEEPYES,d0
	beq BeeperOn
	cmp.w #BEEPNO,d0
	beq BeeperOff
	bra ReDo
MVSlide:	graf_slidebox #Audio,#MVBOX,#MVSLIDER,#0
	clr.l d0
	move.w int_out,d0
	divu #25,d0		*  0..40
	bsr SetMV
	objc_draw #Audio,#MVCOVER,#3,WinX,WinY,WinW,WinH
	bra ReDo
LVSlide:	graf_slidebox #Audio,#LVBOX,#LVSLIDER,#0
	clr.l d0
	move.w int_out,d0
	divu #50,d0		*  0..20
	bsr SetLV
	objc_draw #Audio,#LVCOVER,#3,WinX,WinY,WinW,WinH
	bra ReDo
RVSlide:	graf_slidebox #Audio,#RVBOX,#RVSLIDER,#0
	clr.l d0
	move.w int_out,d0
	divu #50,d0		*  0..20
	bsr SetRV
	objc_draw #Audio,#RVCOVER,#3,WinX,WinY,WinW,WinH
	bra ReDo
TSlide:	graf_slidebox #Audio,#TBOX,#TSLIDER,#0
	clr.l d0
	move.w int_out,d0
	divu #83,d0		*  0..12
	bsr SetT
	objc_draw #Audio,#TCOVER,#3,WinX,WinY,WinW,WinH
	bra ReDo
BSlide:	graf_slidebox #Audio,#BBOX,#BSLIDER,#0
	clr.l d0
	move.w int_out,d0
	divu #83,d0		*  0..12
	bsr SetB
	objc_draw #Audio,#BCOVER,#3,WinX,WinY,WinW,WinH
	bra ReDo
BeeperOn:	move.b #1,BeeperFlag
	bsr SetBeeper
	bra ReDo
BeeperOff:	clr.b BeeperFlag
	bsr SetBeeper
	bra ReDo

MakeNoise:	objc_change #Audio,#TEST,WinX,WinY,WinW,WinH,#0,#1
	clr.l -(sp)
	move.w #32,-(sp)
	trap #1
	addq #2,sp
	move.l d0,(sp)

	move.b #0,$ff8901	*  Sound off
	move.l #Buffer,BufferPtr	
	move.b BufferPtr+1,$ff8903
	move.b BufferPtr+2,$ff8905
	move.b BufferPtr+3,$ff8907
	move.l SampleLen,d0
	add.l d0,BufferPtr
	move.b BufferPtr+1,$ff890f
	move.b BufferPtr+2,$ff8911
	move.b BufferPtr+3,$ff8913
	move.b #$81,$ff8921	*  12Khz, Mono
	move.b #1,$ff8901	*  Sound On, once
	
	move.w #32,-(sp)
	trap #1
	addq #6,sp
	
	bra ReDo

FiniSave:	clr.w -(sp)
	pea.l SetupFile
	move.w #60,-(sp)
	trap #1
	addq #8,sp
	tst.l d0
	bmi ReDo
	move.w d0,-(sp)
	pea.l LeftVolume
	pea.l 6
	move.w d0,-(sp)
	move.w #64,-(sp)
	trap #1
	lea.l 12(sp),sp
	move.w #62,-(sp)
	trap #1
	addq #2,sp
	
FiniExit:	form_dial #3,WinX,WinY,WinW,WinH,WinX,WinY,WinW,WinH
	appl_exit
	clr.w -(sp)
	trap #1
	
MakeNumber:	move.b #'+',d1
	btst.l #7,d0
	beq MakeNum2
	move.b #'-',d1
	neg.b d0
MakeNum2:	move.b d1,(a0)+
	clr.l d1
	move.b d0,d1
	divu #10,d1
	tst.b d1
	beq MakeNum3
	add.b #$30,d1
	move.b d1,(a0)+
MakeNum3:	swap.w d1
	add.b #$30,d1
	move.b d1,(a0)+
	tst.b (a0)
	beq MakeNum4
	move.b #$20,(a0)+
MakeNum4:	rts

SetMV:	move.b d0,MasterVolume
	move.w #%10011000000,d1
	bsr HardSet
	sub.b #40,d0
	lsl.b #1,d0
	lea.l text27,a0
	bsr MakeNumber
	clr.l d0
	move.b MasterVolume,d0
	mulu MVWidth,d0
	divu #44,d0
	move.w d0,MVSliderPos
	rts
SetLV:	move.b d0,LeftVolume
	move.w #%10101000000,d1
	bsr HardSet
	sub.b #20,d0
	lsl.b #1,d0
	lea.l text28,a0
	bsr MakeNumber
	clr.l d0
	move.b LeftVolume,d0
	mulu LVWidth,d0
	divu #22,d0
	move.w d0,LVSliderPos
	rts
SetRV:	move.b d0,RightVolume
	move.w #%10100000000,d1
	bsr HardSet
	sub.b #20,d0
	lsl.b #1,d0
	lea.l text29,a0
	bsr MakeNumber
	clr.l d0
	move.b RightVolume,d0
	mulu RVWidth,d0
	divu #22,d0
	move.w d0,RVSliderPos
	rts
SetT:	move.b d0,Treble
	move.w #%10010000000,d1
	bsr HardSet
	sub.b #6,d0
	lea.l text30,a0
	lsl.b #1,d0
	bsr MakeNumber
	clr.l d0
	move.b Treble,d0
	mulu TWidth,d0
	divu #13,d0
	move.w d0,TSliderPos
	rts
SetB:	move.b d0,Bass
	move.w #%10001000000,d1
	bsr HardSet
	sub.b #6,d0
	lsl.b #1,d0
	lea.l text31,a0
	bsr MakeNumber
	clr.l d0
	move.b Bass,d0
	mulu BWidth,d0
	divu #13,d0
	move.w d0,BSliderPos
	rts
SetBeeper:	move.b BeeperFlag,d0
	eor.b #1,d0
	move.w #%10000000001,d1
	bsr HardSet
	rts

HardSet:	move.w d0,-(sp)
	ext.w d0
	add.w d0,d1
	move.w d1,d7
	clr.l -(sp)
	move.w #32,-(sp)
	trap #1
	addq #6,sp
MWWrite:	cmp.w #$07ff,$ff8924
	bne MWWrite
	move.w d7,$ff8922
	move.l d0,-(sp)
	move.w #32,-(sp)
	trap #1
	addq #6,sp
	move.w (sp)+,d0
	rts

	section data

rsrc_length:	equ 41

Audio:	dc.w	-1,1,39
	dc.w	20,0,16		*0*
	dc.l	$21101
	dc.w	2,0,48,18

	dc.w	2,-1,-1
	dc.w	21,0,0		*1*
	dc.l	ted1
	dc.w	1,1,13,1

	dc.w	3,-1,-1
	dc.w	21,0,0		*2*
	dc.l	ted2
	dc.w	12,$302,$202,1

	dc.w	4,-1,-1
	dc.w	21,0,0		*3*
	dc.l	ted4
	dc.w	22,$302,3,1

	dc.w	5,-1,-1
	dc.w	21,0,0		*4*
	dc.l	ted3
	dc.w	33,$302,$600,1

	dc.w	6,-1,-1
	dc.w	21,0,0		*5*
	dc.l	ted5
	dc.w	1,4,11,1

	dc.w	7,-1,-1
	dc.w	21,0,0		*6*
	dc.l	ted6
	dc.w	1,7,12,1

	dc.w	8,-1,-1
	dc.w	21,0,0		*7*
	dc.l	ted7
	dc.w	1,10,6,1

	dc.w	9,-1,-1
	dc.w	21,0,0		*8*
	dc.l	ted8
	dc.w	1,13,3,1

	dc.w	10,-1,-1
	dc.w	26,81
	dc.b	0
BeepYesFlag:	dc.b	0		*9*
	dc.l	text1
	dc.w	12,16,4,1

	dc.w	11,-1,-1
	dc.w	26,81
	dc.b	0
BeepNoFlag:	dc.b	0		*10*
	dc.l	text2
	dc.w	16,16,4,1

	dc.w	12,-1,-1
	dc.w	21,0,0		*11*
	dc.l	ted9
	dc.w	1,16,$407,1

	dc.w	13,-1,-1
	dc.w	26,7
	dc.b	0
OKFlag:	dc.b	0		*12*
	dc.l	text3
	dc.w	37,12,8,1

	dc.w	14,-1,-1
	dc.w	26,5
	dc.b	0
CancelFlag:	dc.b	0		*13*
	dc.l	text4
	dc.w	37,15,8,1

	dc.w	15,-1,-1
	dc.w	21,0,0		*14*
	dc.l	ted10
	dc.w	12,$305,$202,1

	dc.w	16,-1,-1
	dc.w	21,0,0		*15*
	dc.l	ted11
	dc.w	22,$305,$202,1

	dc.w	17,-1,-1
	dc.w	21,0,0		*16*
	dc.l	ted12
	dc.w	33,$305,1,1

	dc.w	18,-1,-1
	dc.w	21,0,0		*17*
	dc.l	ted13
	dc.w	12,$308,$202,1

	dc.w	19,-1,-1
	dc.w	21,0,0		*18*
	dc.l	ted14
	dc.w	22,$308,$202,1

	dc.w	20,-1,-1
	dc.w	21,0,0		*19*
	dc.l	ted15
	dc.w	33,$308,1,1

	dc.w	21,-1,-1
	dc.w	21,0,0		*20*
	dc.l	ted16
	dc.w	12,$30B,$202,1

	dc.w	22,-1,-1
	dc.w	21,0,0		*21*
	dc.l	ted17
	dc.w	23,$30B,$600,1

	dc.w	23,-1,-1
	dc.w	21,0,0		*22*
	dc.l	ted18
	dc.w	32,$30B,$202,1

	dc.w	24,-1,-1
	dc.w	21,0,0		*23*
	dc.l	ted19
	dc.w	12,$30E,$202,1

	dc.w	25,-1,-1
	dc.w	21,0,0		*24*
	dc.l	ted20
	dc.w	23,$30E,1,1

	dc.w	26,-1,-1
	dc.w	21,0,0		*25*
	dc.l	ted21
	dc.w	32,$30E,$202,1

	dc.w	27,-1,-1
	dc.w	26,65
	dc.b	0
TestFlag:	dc.b	0		*26*
	dc.l	text5
	dc.w	37,6,8,2

	dc.w	30,28,28
	dc.w	20,0,0		*27*
	dc.l	$1180
	dc.w	11,$400,$118,$601

	dc.w	27,29,29
	dc.w	25,0,0		*28*
	dc.l	$11100
	dc.w	1,$400
MVWidth:	dc.w	22,1

	dc.w	28,-1,-1
	dc.w	22,64,0		*29*
	dc.l	ted22
MVSliderPos:	dc.w	5,0,$202,1

	dc.w	33,31,31
	dc.w	20,0,0		*30*
	dc.l	$1180
	dc.w	$10B,$403,$118,$601

	dc.w	30,32,32
	dc.w	25,0,0		*31*
	dc.l	$11100
	dc.w	$700,$400
LVWidth:	dc.w	22,1

	dc.w	31,-1,-1
	dc.w	22,64,0		*32*
	dc.l	ted23
LVSliderPos:	dc.w	15,0,$202,1

	dc.w	36,34,34
	dc.w	20,0,0		*33*
	dc.l	$1180
	dc.w	$20B,$606,$118,$601

	dc.w	33,35,35
	dc.w	25,0,0		*34*
	dc.l	$11100
	dc.w	$600,$200
RVWidth:	dc.w	22,1

	dc.w	34,-1,-1
	dc.w	22,64,0		*35*
	dc.l	ted24
RVSliderPos:	dc.w	15,0,$202,1

	dc.w	39,37,37
	dc.w	20,0,0		*36*
	dc.l	$1180
	dc.w	11,$509,$118,$601

	dc.w	36,38,38
	dc.w	25,0,0		*37*
	dc.l	$11100
	dc.w	1,$300
TWidth:	dc.w 	22,1

	dc.w	37,-1,-1
	dc.w	22,64,0		*38*
	dc.l	ted25
TSliderPos:	dc.w	3,0,$202,1

	dc.w	0,40,40
	dc.w	20,0,0		*39*
	dc.l	$1180
	dc.w	$20B,$50C,$118,$601

	dc.w	39,41,41
	dc.w	25,0,0		*40*
	dc.l	$11100
	dc.w	$600,$300
BWidth:	dc.w	22,1

	dc.w	40,-1,-1
	dc.w	22,96,0		*41*
	dc.l	ted26
BSliderPos:	dc.w	17,0,$202,1

		* Tedinfo blocks *

ted1	dc.l	text6,null,null
	dc.w	5,6,0,$1180
	dc.w	0,-1,14,1

ted2	dc.l	text7,null,null
	dc.w	5,6,0,$1180
	dc.w	0,-1,4,1

ted3	dc.l	text8,null,null
	dc.w	5,6,0,$1180
	dc.w	0,-1,2,1

ted4	dc.l	text9,null,null
	dc.w	5,6,0,$1180
	dc.w	0,-1,4,1

ted5	dc.l	text10,null,null
	dc.w	5,6,0,$1180
	dc.w	0,-1,12,1

ted6	dc.l	text11,null,null
	dc.w	5,6,0,$1180
	dc.w	0,-1,13,1

ted7	dc.l	text12,null,null
	dc.w	5,6,0,$1180
	dc.w	0,-1,7,1

ted8	dc.l	text13,null,null
	dc.w	5,6,0,$1180
	dc.w	0,-1,5,1

ted9	dc.l	text14,null,null
	dc.w	5,6,2,$1180
	dc.w	0,-1,11,1

ted10	dc.l	text15,null,null
	dc.w	5,6,0,$1180
	dc.w	0,-1,4,1

ted11	dc.l	text16,null,null
	dc.w	5,6,0,$1180
	dc.w	0,-1,4,1

ted12	dc.l	text17,null,null
	dc.w	5,6,0,$1180
	dc.w	0,-1,2,1

ted13	dc.l	text18,null,null
	dc.w	5,6,0,$1180
	dc.w	0,-1,4,1

ted14	dc.l	text19,null,null
	dc.w	5,6,0,$1180
	dc.w	0,-1,4,1

ted15	dc.l	text20,null,null
	dc.w	5,6,0,$1180
	dc.w	0,-1,2,1

ted16	dc.l	text21,null,null
	dc.w	5,6,0,$1180
	dc.w	0,-1,4,1

ted17	dc.l	text22,null,null
	dc.w	5,6,0,$1180
	dc.w	0,-1,2,1

ted18	dc.l	text23,null,null
	dc.w	5,6,0,$1180
	dc.w	0,-1,4,1

ted19	dc.l	text24,null,null
	dc.w	5,6,0,$1180
	dc.w	0,-1,4,1

ted20	dc.l	text25,null,null
	dc.w	5,6,0,$1180
	dc.w	0,-1,2,1

ted21	dc.l	text26,null,null
	dc.w	5,6,0,$1180
	dc.w	0,-1,4,1

ted22	dc.l	text27,null,null
	dc.w	5,6,2,$3180
	dc.w	0,65534,4,1

ted23	dc.l	text28,null,null
	dc.w	5,6,0,$3180
	dc.w	0,65534,4,1

ted24	dc.l	text29,null,null
	dc.w	5,6,0,$3180
	dc.w	0,65534,4,1

ted25	dc.l	text30,null,null
	dc.w	5,6,0,$3180
	dc.w	0,65534,4,1

ted26	dc.l	text31,null,null
	dc.w	5,6,0,$3180
	dc.w	0,65534,4,1

		* Text data *

text1	dc.b	'Yes',0
text2	dc.b	'No',0
text3	dc.b	'Save',0
text4	dc.b	'Exit',0
text5	dc.b	'Hear',0
text6	dc.b	'Master Volume',0
text7	dc.b	'-80',0
text8	dc.b	'0',0
text9	dc.b	'-40',0
text10	dc.b	'Left Volume',0
text11	dc.b	'Right Volume',0
text12	dc.b	'Treble',0
text13	dc.b	'Bass',0
text14	dc.b	'Use Beeper',0
text15	dc.b	'-40',0
text16	dc.b	'-20',0
text17	dc.b	'0',0
text18	dc.b	'-40',0
text19	dc.b	'-20',0
text20	dc.b	'0',0
text21	dc.b	'-12',0
text22	dc.b	'0',0
text23	dc.b	'+12',0
text24	dc.b	'-12',0
text25	dc.b	'0',0
text26	dc.b	'+12',0
text27	dc.b	'-50',0
text28	dc.b	'-15',0
text29	dc.b	'-15',0
text30	dc.b	'-10',0
text31	dc.b	'+10',0
null	dc.b	0,0

LeftVolume:	dc.b 20
RightVolume:	dc.b 20
MasterVolume:	dc.b 40
Treble:	dc.b 6
Bass:	dc.b 6
BeeperFlag:	dc.b 1

SetupFile:	dc.b 'SOUND.SET',0
SampleFile:	dc.b 'STECTRL.SAM',0

	section bss
	
	even
	
WinX:	ds.w 1
WinY:	ds.w 1
WinW:	ds.w 1
WinH:	ds.w 1
SampleLen:	ds.l 1
BufferPtr:	ds.l 1

	even
	
Buffer:	equ *