
; ***********************************************************
; *                                                         *
; *    P L A T I N U M - H E A R - R E P L A C E M E N T    *
; *                                                         *
; *                        V 1.00                           *
; *                                                         *
; ***********************************************************
; *                                                         *
; *          Assembler-Source / Assembler: Devpac II        *
; *                                                         *
; *                    (C)April 1991 by                     *
; *                                                         *
; *                    Joerg Schliesser                     *
; *                  Platinum-Softwareline                  *
; *                   Rotenwaldstrasse 20                   *
; *                   D-7000 Stuttgart 1                    *
; *                         Germany                         *
; *                                                         *
; ***********************************************************

; *** Amiga OS-Routinen ***

	; Exec-Library
AllocMem	=	-198
FreeMem		=	-210
FindTask	=	-294
GetMsg		=	-372
ReplyMsg	=	-378
WaitPort	=	-384
CloseLibrary	=	-414
OpenLibrary	=	-552

	; Dos-Library
Open		=	-30
Close		=	-36
Read		=	-42
Lock		=	-84
UnLock		=	-90
DupLock		=	-96
Examine		=	-102
CurrentDir	=	-126
Delay		=	-198

	; Intuition-Library
AddGadget	=	-42
ClearPointer	=	-60
CloseWindow	=	-72
OpenWindow	=	-204
PrintIText	=	-216
RefreshGadgets	=	-222
RemoveGadget	=	-228
SetPointer	=	-270

	; Graphics-Library
RectFill	=	-306
SetAPen		=	-342
ScrollRaster	=	-396

	; Hardware-register

dmacon = $dff096	; DMA
cialed = $bfe001	; low-pass-filter on/off
audxadr	= $DFF0A0	; base-adress of 1st channel
audxlch	= $0		; offset for adress of sample-data
audxlen	= $4		; offset for length of sample
audxper	= $6		; offset for sampleperiod
audxvol	= $8		; offset for volume
aud0vol = $dff0a8
aud1vol = $dff0b8	; registers for volumes of
aud2vol = $dff0c8	; the four voices
aud3vol = $dff0d8

; assembler-options

	section	programm,code	;1st section, code, public_mem

; check WB- or CLI-start and get  WB-startup-message

start:
	move.l	sp,startsp	;save stackpointer 
	move.l	a0,memo1	;cli textpointer
	move.w	d0,memo2	;cli textlength
	move.l	4,a6
	suba.l	a1,a1		;get adress of PLTHear-Task
	jsr	FindTask(a6)
	move.l	d0,thistask

	lea	dosname,a1
	moveq	#0,d0
	jsr	OpenLibrary(a6)	;open dos_lib
	move.l	d0,dosbase
	beq	quitplthear

	lea	graphname,a1
	moveq	#0,d0
	jsr	OpenLibrary(a6)	;open graph_lib
	move.l	d0,graphbase
	beq	quitplthear

	lea	intuiname,a1
	moveq	#0,d0
	jsr	OpenLibrary(a6)	;open intui_lib
	move.l	d0,intuibase
	beq	quitplthear

	move.l	#1024,d0
	move.l	#$10003,d1
	jsr	AllocMem(a6)	;get infomem (for fileinfos)
	move.l	d0,infomem
	beq	quitplthear

	move.l	thistask,a4	;pointer to task struct
	tst.l	$ac(a4)		;started from CLI ?
	beq	wbstart

; get filename if started from CLI

	move.l	memo1,a0	;text-pointer
	move.w	memo2,d0	;text-length
	subq.w  #1,d0		;no text ?
	beq	nofile		;well then ... waiting
lforname:
	cmpi.b	#$20,(a0)+	;look for 'space'
	bne	foundname	;no space ... got beginning of filename
	dbra	d0,lforname
	bra	nofile		;no space ... no filename !
foundname:
	subq.l	#1,a0		;got filename
getfilename:
	lea	filename1,a1	;adress of memory for filename
	cmp.b	#34,(a0)	;drop " - char at the beginning
	beq	dropfirst
	cmp.b	#39,(a0)	;drop ' - char at the beginning
	bne	copyname
dropfirst:
	adda.l	#1,a0
copyname:			;copy filename
	move.b	(a0)+,d1
	beq	eofname		;zero => end
	cmp.b	#10,d1
	beq	eofname		;linefeed => end
	cmp.b	#13,d1
	beq	eofname		;carriag return => end
	move.b	d1,(a1)+
	bra	copyname
eofname:
	clr.b	(a1)		;zero-byte to end filename
	move.l	a1,a0		;keep end of filename
	cmp.b	#34,-(a1)	;drop " - char at the end
	beq	droplast
	cmp.b	#39,(a1)	;drop ' - char at the end
	bne	lookparam
droplast:
	clr.b	(a1)
lookparam:
	suba.l	#4,a0 
	cmp.b	#44,(a0)	;look for ','
	beq	gotparam
	adda.l	#1,a0
	cmp.b	#44,(a0)
	bne	gotfilename	;no ',' ... no parameter
gotparam:
	move.b	1(a0),d0	;get type of parameter
	move.b	2(a0),d1	;get one digit of parameter
	move.b	3(a0),d2	;get onother digit of the parameter
	clr.b	(a0)+
	clr.b	(a0)+		;delete paramter from filename
	clr.b	(a0)+
	clr.b	(a0)
	cmp.b	#35,d0		;look for '#' to indicate repeat-parameter
	beq	gotrepeatparam
	cmp.b	#38,d0		;look for '&' to indicate time-parameter
	bne	gotfilename
gotrepeatparam:
	move.b	d0,param
	tst.b	d2		;is there only one digit ?
	bne	twodigits
	sub.b	#48,d1
	move.b	d1,time		;get value of parameter and save it
	bra	gotfilename
twodigits:
	moveq	#0,d3
	sub.b	#48,d1
	sub.b	#48,d2		;get value of two-digit parameter
	mulu	#10,d1
	move.b	d1,d3
	add.b	d2,d3		;and save it
	move.b	d3,time
	bra	gotfilename

; get parameters if programm is started from wb

wbstart:
	lea	$5c(a4),a0	;pointer to task's message-port 
	jsr	Waitport(a6)	;wait for wb-start-message
	lea	$5c(a4),a0
	jsr	GetMsg(a6)	;get wb-start-message
	move.l	d0,startmsg
	beq	nofile		;no message ? ... strange !
	move.l	d0,a0
	cmp.l	#1,$1c(a0)	;number of arguments < 1 ... nofilename
	bls	nofile
	move.l	$24(a0),a2	;pointer to list of segments (picked icons)
	beq	nofile		;... very strange !
	move.l	8(a2),d1	;pointer to directory of text(?)-icon
	beq	noselectdir
	move.l	dosbase,a6
	jsr	CurrentDir(a6)	;actual dir => new dir
	move.l	d0,d1
	beq	noselectdir
	jsr	UnLock(a6)
noselectdir:
	move.l	12(a2),d0	;pointer to filename
	beq	nofile		;... no filename !
	move.l	d0,a0
	tst.b	(a0)		;get first character of filename
	beq	nofile		;... still very strange !
	bra	getfilename	;well then get the filename

; well ... now we open the window !

nofile:
	bset	#0,pltflag
gotfilename:
	move.l	intuibase,a6
	lea	wplt,a0		;open display-window
	jsr	OpenWindow(a6)
	move.l	d0,wdwhandle	;keep wdwhandle
	beq	quitplthear
	move.l	d0,a0
	move.l	50(a0),wdwrast	;keep rastport
	bsr	dowindow	;draw the wonderful plthear-window
	btst	#0,pltflag
	bne	waitmessage	;did we get one file to start ?

; now we load our sound (?) - file

gotloadfile:
	bsr	pltworkon	;turn on sleeping-pointer
	move.l	4,a6
	lea	mem,a2		;get base of memory-pointer-table
	lea	long,a3		;get base of memery-lengths-table
	moveq	#0,d2		;get number of channel to load
	move.b	playflag,d2	;sound-data for
	asl.w	#2,d2
	move.l	0(a2,d2),a1	;get pointer to corresponding
	move.l	0(a3,d2),d0	;memory pointer
	beq	nooldsongmem
	jsr	FreeMem(a6)	;free old data memory
	clr.l	0(a2,d2)
	clr.l	0(a3,d2)
nooldsongmem:
	lea	filename1,a0	;get filename-pointer
	tst.b	playflag
	beq	gotlfn
	lea	filename2,a0	;for voice to load
	cmp.b	#1,playflag
	beq	gotlfn
	lea	filename3,a0
	cmp.b	#2,playflag
	beq	gotlfn
	lea	filename4,a0
gotlfn:
	move.l	#$10003,d0	;type of memory: chip/clear
	bsr	loadfile	;one file-load-routine
	move.l	d0,0(a3,d2)	;keep length of data
	beq	loadferror	;data length = 0 ... really very strange !
	move.l	a0,0(a2,d2)	;data-adress-pointer
	move.l	#"RAW ",d3
	clr.b	d3
	moveq	#3,d4		;indicate oneshot-possibility
	moveq	#3,d5		;indicate repeat-possibility
	cmp.l	#"8SVX",8(a0)	;look if this is a IFF-8SVX-file
	beq	iffsoundl
	move.l	#8363,d7	;if not, the set sample-rate and display
	bra	setperiod	;for raw-sample
iffsoundl:
	lsr.l	#1,d0
lookvhdrl:
	cmp.l	#"VHDR",(a0)	;look for voice-header-chunk
	beq	foundvhdrl
	adda.l	#2,a0
	subq.l	#1,d0
	bne	lookvhdrl
	move.l	#8363,d7	;no voice-header-chunk ...
	bra	setperiod	;that means: one RAW-Sample
foundvhdrl:
	moveq	#0,d7		;get 8SVX-sample-rate
	move.w	20(a0),d7
	move.l	#"IFF ",d3	;indicate IFF
	clr.b	d3
	tst.l	8(a0)		;look if there's a oneshot-part
	bne	onceshow
	moveq	#2,d4
onceshow:
	tst.l	12(a0)		;look if there's a repeat-part
	bne	setperiod
	moveq	#2,d5
setperiod:
	tst.b	playflag	;request for voice 1 ?
	bne	nov1lo
	move.l	d3,typ1		;indicate type of sound (RAW/IFF)
	move.w	d4,ofi1+8	;indicate oneshot-possibility
	move.w	d5,cofi1+8	;indicate repeat-possibility
	lea	gdgper1,a3
	lea	period1t,a5	;get pointers for period-gadgets
	lea	period1,a4
	bra	dosetperiod	;and redisplay the window
nov1lo:
	cmp.b	#1,playflag	;request for voice 2 ?
	bne	nov2lo
	move.l	d3,typ2
	move.w	d4,ofi2+8
	move.w	d5,cofi2+8	;... see above
	lea	gdgper2,a3
	lea	period2t,a5
	lea	period2,a4
	bra	dosetperiod
nov2lo:
	cmp.b	#2,playflag	;request for voice 3 ?
	bne	nov3lo
	move.l	d3,typ3
	move.w	d4,ofi3+8
	move.w	d5,cofi3+8	;... see above
	lea	gdgper3,a3
	lea	period3t,a5
	lea	period3,a4
	bra	dosetperiod
nov3lo:
	cmp.b	#3,playflag	;request for voice 4 ?
	bne	waitmessage
	move.l	d3,typ4
	move.w	d4,ofi4+8
	move.w	d5,cofi4+8	;... see above
	lea	gdgper4,a3
	lea	period4t,a5
	lea	period4,a4
dosetperiod:
	bsr	modifyperiod	;modify the period-gadget
	bsr	dowindow	;the PLTHear-Window
	bsr	pltworkoff
	btst	#0,pltflag
	bne	waitmessage	;if there's no sound we have to wait
	bset	#0,pltflag
	bra	repeat1		;if there's a sound... play it !

; modify and redraw a period-gadget

modifyperiod:
	move.l	intuibase,a6
	move.l	wdwhandle,a0
	move.l	a3,a1		;remove the gadget
	jsr	RemoveGadget(a6)
	move.l	d7,(a4)
	move.l	a5,a0
	move.l	d7,d0
	bsr	getascii	;get ascii-code out of integer
	move.l	wdwhandle,a0
	move.l	a3,a1
	moveq	#-1,d0
	jsr	AddGadget(a6)	;add the gadget
	lea	gdgquit,a0
	move.l	wdwhandle,a1
	move.l	#0,a2		;and redraw it
	jsr	RefreshGadgets(a6)
	rts

; waiting for user-action

loadferror:
	bsr	pltworkoff
waitmessage:
	tst.b	time
	beq	noparadrive	;look if there was a parameter
	move.l	dosbase,a6
	cmp.b	#38,param	;if the 'time' was given go on the
	beq	straighttime	;easy way
	moveq	#0,d0
	moveq	#0,d1
	moveq	#0,d2		;if the 'number of repeats' was
	move.w	slength,d2
	asl.w	#1,d2
	move.l	period1,d3	;requested, try to calculate
	divu	#50,d3
	and.l	#$0000ffff,d3
	move.b	time,d0		;the right time for the requested
	mulu	d2,d0	
	divu	d3,d0
	move.w	d0,d1		;repeats
	bra	repeattime		
straighttime:
	moveq	#0,d1
	move.b	time,d1		;delivered, when the programm was
	mulu	#50,d1
repeattime:
	jsr	Delay(a6)	;started
	bra	quitplthear
noparadrive:
	move.l	4,a6
	move.l	wdwhandle,a0
	move.l	86(a0),a0	;window-user-port
	jsr	WaitPort(a6)	;waiting for intuimessage
	move.l	wdwhandle,a0
	move.l	86(a0),a0	;window user-port
	jsr	GetMsg(a6)	;get intuimessage
	tst.l	d0
	beq	waitmessage	;there wasn't one ... stra...
	move.l	d0,a1
	move.l	20(a1),d6	;get idcmp-code of event
	move.l	28(a1),a3	;get (possibly) adress of gadget
	move.w	24(a1),d5	;get (possibly) raw-key-code	
	move.w	26(a1),d4	;get (possibly) qualifier
	jsr	ReplyMsg(a6)	;and reply message
	cmp.l	#$8,d6		;button-messages only are necessary
	beq	waitmessage	;for repeating a selected gadget
	cmp.l	#$20,d6
	beq	downgadget	;immediate-gadget selected ?
	cmp.l	#$40,d6
	bne	noupgadgetmsg	;wasn't any gadget at all
	cmpa.l	#gdgquit,a3
	beq	quitplthear	;quit this wonderfull program ?
	cmpa.l	#gdgstop1,a3
	bne	nostop1		;stop playing voice 1 ?
stopt1:
	bsr	stop1
	bra	waitmessage
stop1:
	move.w	#0,lofi1+8	;clear 'playing'-indication
	bsr	dowindow	;redraw the window
	move.w	#0,aud0vol	;and stop dma for channel 1
	move.w	#1,dmacon
	rts
nostop1:
	cmpa.l	#gdgstop2,a3	;stop playing voice 2 ?
	bne	nostop2
stopt2:
	bsr	stop2
	bra	waitmessage
stop2:
	move.w	#0,lofi2+8
	bsr	dowindow	;... see above
	move.w	#0,aud1vol
	move.w	#2,dmacon
	rts
nostop2:
	cmpa.l	#gdgstop3,a3	;stop playing voice 3 ?
	bne	nostop3
stopt3:
	bsr	stop3
	bra	waitmessage
stop3:
	move.w	#0,lofi3+8
	bsr	dowindow	;... see above
	move.w	#0,aud2vol
	move.w	#4,dmacon
	rts
nostop3:
	cmpa.l	#gdgstop4,a3	;stop playing voice 4 ?
	bne	nostop4
stopt4:
	bsr	stop4
	bra	waitmessage
stop4:
	move.w	#0,lofi4+8
	bsr	dowindow	;... see above
	move.w	#0,aud3vol
	move.w	#8,dmacon
	rts
nostop4:
	cmpa.l	#gdgrep1,a3	;repeat-request voice 1 ?
	beq	repeat1
	cmpa.l	#gdgrep2,a3	;... voice 2
	beq	repeat2
	cmpa.l	#gdgrep3,a3	;... voice 3
	beq	repeat3
	cmpa.l	#gdgrep4,a3	;... voice 4
	beq	repeat4
	cmpa.l	#gdgonce1,a3	;once-request voice 1 ?
	beq	playt1
	cmpa.l	#gdgonce2,a3	;... voice 2
	beq	playt2
	cmpa.l	#gdgonce3,a3	;... voice 3
	beq	playt3
	cmpa.l	#gdgonce4,a3	;... voice 4
	beq	playt4
	cmpa.l	#gdgload1,a3	;load-request voice 1 ?
	beq	load1
	cmpa.l	#gdgload2,a3	;... voice 2
	beq	load2
	cmpa.l	#gdgload3,a3	;... voice 3
	beq	load3
	cmpa.l	#gdgload4,a3	;... voice 4
	beq	load4
	cmpa.l	#gdgfon,a3	;low-pass-filter on ?
	beq	filton
	cmpa.l	#gdgfoff,a3	;low-pass-filter off ?
	beq	filtoff
	cmpa.l	#gdghelp,a3	;request for help-window ?
	bne	waitmessage
	bsr	plthelp		;draw the help-window
	bra	waitmessage

; do the play-requests

repeat1:
	move.w	#3,lofi1+8	;indicate repeating voice 1
	bsr	dowindow	;display window
	moveq	#1,d6		;set flag for repeat
	bra	play1		;play the sound
repeat2:
	move.w	#3,lofi2+8	;repeating voice 2
	bsr	dowindow
	moveq	#1,d6
	bra	play2
repeat3:
	move.w	#3,lofi3+8	;repeating voice 3
	bsr	dowindow
	moveq	#1,d6
	bra	play3
repeat4:
	move.w	#3,lofi4+8	;repeating voice 4
	bsr	dowindow
	moveq	#1,d6
	bra	play4
playt1:
	moveq	#0,d6		;once playing voice 1
play1:
	clr.b	playflag
	move.l	period1,doper
	bra	playrequest
playt2:
	moveq	#0,d6		;once playing voice 2
play2:
	move.b	#1,playflag
	move.l	period2,doper
	bra	playrequest
playt3:
	moveq	#0,d6		;once playing voice 3
play3:
	move.b	#2,playflag
	move.l	period3,doper
	bra	playrequest
playt4:
	moveq	#0,d6		;once playing voice 4
play4:
	move.b	#3,playflag
	move.l	period4,doper
playrequest:			;d6=0=>once, d6=1=>repeat
	moveq	#1,d3		;d3=0=>IFF, d3=1=>RAW
	moveq	#0,d4
	move.b	playflag,d4
	asl.w	#4,d4
	move.l	#$dff0a0,a4	;get base-adress of requested voice
	adda.l	d4,a4
	moveq	#0,d0
	move.b	playflag,d0
	moveq	#0,d1
	bset	d0,d1
	move.w	d1,dmacon	;turn off dma for requested voice
	move.w	#0,audxvol(a4)	;and clear volume
	move.w	#256,d0
dropwait:			;waiting, so that dma and volume are
	dbra	d0,dropwait	;really reseted
	moveq	#0,d7
	move.b	playflag,d7
	asl.w	#2,d7
	lea	mem,a0
	lea	long,a1
	move.l	0(a0,d7),a2	;get adress and length of
	move.l	0(a1,d7),d2	;requested sound
	cmp.l	#"8SVX",8(a2)
	bne	doonce		;if it is a RAW-Sound go to play it
	lsr.l	#1,d2
lookbodyo:
	cmp.l	#"BODY",(a2)	;look for BODY-chunk
	beq	foundbodyo
	adda.l	#2,a2
	subq.l	#1,d2
	bne	lookbodyo
	move.l	0(a0,d7),a2	;if there is no bodychunk play
	move.l	0(a1,d7),d2	;sound as a raw-sample
	bra	doonce
foundbodyo:
	adda.l	#8,a2		;got begin of oneshot-part 
	move.l	0(a0,d7),a5
	move.l	0(a1,d7),d2
	lsr.l	#1,d2
lookvhdro:
	cmp.l	#"VHDR",(a5)	;look for VHDR-chunk
	beq	foundvhdro
	adda.l	#2,a5
	subq.l	#1,d2
	bne	lookvhdro
	move.l	0(a0,d7),a2	;if there is no bodychunk play
	move.l	0(a1,d7),d2	;sound as a raw-sample
	bra	doonce
foundvhdro:
	moveq	#0,d3		;set flag for IFF-Sound
	move.l	8(a5),d2	;get length of oneshot-part
	add.l	12(a5),d2	;get length of repeat-part
doonce:
	moveq	#0,d4
	move.b	playflag,d4
	asl.w	#4,d4
	move.l	#$dff0a0,a4	;get base-adress of requested voice
	adda.l	d4,a4
	move.l	a2,audxlch(a4)	;write begin of sound
	lsr.l	#1,d2
	move.w	d2,audxlen(a4)	;write length of sound
	move.w	d2,slength
	move.l	#3579546,d0
	move.l	doper,d1
	divu	d1,d0
	move.w	d0,audxper(a4)	;write playperiod
	moveq	#0,d0
	move.b	playflag,d0
	move.w	#$8200,d1	;turn on dma
	bset	d0,d1
	move.w	d1,dmacon
	move.w	#64,audxvol(a4)	;write volume
	move.w	#256,d0
launchwait:			;wait for dma to be really
	dbra	d0,launchwait	;started
	tst.b	d6
	beq	oncerequest	;is there a repeat part to play ?
	tst.b	d3		;if it is a raw-sample, repeat all
	bne	waitmessage
	move.l	8(a5),d2	;get oneshot-length
	add.l	d2,a2		;get adress of repeat-part
	move.l	12(a5),d2	;get length of repeat-part
	beq	waitmessage
	move.l	a2,audxlch(a4)	;write adress of repeat-part
	lsr.l	#1,d2
	move.w	d2,audxlen(a4)	;write length for repeat-part
	move.w	d2,slength
	bra	waitmessage
oncerequest:
	move.l	#notone,audxlch(a4)	;write adress of 'quiet'-sound
	move.w	#2,audxlen(a4)	;write length of 'quiet'-sound
	bra	waitmessage

; load a requested sound

load1:
	bsr	stop1		;turn off voice 1 and
	clr.b	playflag	;load sound
	bra	gotloadfile
load2:
	bsr	stop2		;load for voice 2
	move.b	#1,playflag
	bra	gotloadfile
load3:
	bsr	stop3		;load for voice 3
	move.b	#2,playflag
	bra	gotloadfile
load4:
	bsr	stop4		;load for voice 4
	move.b	#3,playflag
	bra	gotloadfile

; turn on/off hardware low-pass-filter

filton:
	bclr	#1,cialed
	bra	waitmessage
filtoff:
	bset	#1,cialed
	bra	waitmessage

; if the user pressed a key ...

noupgadgetmsg:
	btst	#0,d4
	bne	shifted		;was any shift-key pressed too ?
	btst	#1,d4
	bne	shifted
	cmp.w	#$50,d5		;'F1' - play once voice 1
	beq	playt1
	cmp.w	#$51,d5		;'F2' - play once voice 2
	beq	playt2
	cmp.w	#$52,d5		;'F3' - play once voice 3
	beq	playt3
	cmp.w	#$53,d5		;'F4' - play once voice 4
	beq	playt4
	cmp.w	#$1,d5		;'1' - repeat voice 1
	beq	repeat1	
	cmp.w	#$2,d5		;'2' - repeat voice 2
	beq	repeat2	
	cmp.w	#$3,d5		;'3' - repeat voice 3
	beq	repeat3	
	cmp.w	#$4,d5		;'4' - repeat voice 4
	beq	repeat4	
	cmp.w	#$3a,d5		;'-' - turn off filter
	beq	filtoff
	cmp.w	#$0b,d5		;'-' (US-Keyb) - turn off filter
	beq	filtoff
	cmp.w	#$1b,d5		;'+' - turn on filter
	beq	filton
	cmp.w	#$0c,d5		;'+' (US-Keyb) - turn on filter
	beq	filton
	cmp.w	#$45,d5
	beq	quitplthear	;'esc' - quit programm ?
	cmp.w	#$5f,d5
	bne	waitmessage
	bsr	plthelp		;'Help' - show help window
	bra	waitmessage
shifted:
	cmp.w	#$50,d5		;'F1' - load sound for voice 1
	beq	load1
	cmp.w	#$51,d5		;'F2' - load sound for voice 2
	beq	load2
	cmp.w	#$52,d5		;'F3' - load sound for voice 3
	beq	load3
	cmp.w	#$53,d5		;'F4' - load sound for voice 4
	beq	load4
	cmp.w	#$1,d5		;'1' - turn off voice 1
	beq	stopt1	
	cmp.w	#$2,d5		;'2' - turn off voice 2
	beq	stopt2	
	cmp.w	#$3,d5		;'3' - turn off voice 3
	beq	stopt3	
	cmp.w	#$4,d5		;'4' - turn off voice 4
	beq	stopt4	
	bra	waitmessage

; if the user selected a 'immediate'-gadget

downgadget:
	move.l	a3,memo1	;keep the adress of the gadget
waitdown:
	move.l	memo1,a3
	cmpa.l	#gdgup1,a3	;increase period of voice 1
	beq	perup1
	cmpa.l	#gdgdn1,a3	;decrease period of voice 1
	beq	perdn1
	cmpa.l	#gdgup2,a3	;increase period of voice 2
	beq	perup2
	cmpa.l	#gdgdn2,a3	;and so on...
	beq	perdn2
	cmpa.l	#gdgup3,a3
	beq	perup3
	cmpa.l	#gdgdn3,a3
	beq	perdn3
	cmpa.l	#gdgup4,a3
	beq	perup4
	cmpa.l	#gdgdn4,a3
	beq	perdn4
	bra	waitmessage

; increasing and decreasing the sampleperiod of a voice

perup1:
	clr.b	playflag
	move.l	period1,d7
	cmp.l	#32768,d7
	bge	waitmessage
	add.l	#32,d7		;increase period of voice 1
	bra	modifper1
perdn1:
	clr.b	playflag
	move.l	period1,d7
	cmp.l	#256,d7
	bls	waitmessage
	sub.l	#32,d7		;decrease period of voice 1
modifper1:
	bsr	playperiod	;play new period
	lea	gdgper1,a3
	lea	period1t,a5
	lea	period1,a4
	bsr	modifyperiod	;display new period
	bra	waitbutton
perup2:
	move.b	#1,playflag
	move.l	period2,d7
	cmp.l	#32768,d7
	bge	waitmessage
	add.l	#32,d7		;increase period of voice 2
	bra	modifper2
perdn2:
	move.b	#1,playflag
	move.l	period2,d7
	cmp.l	#256,d7
	bls	waitmessage
	sub.l	#32,d7		;decrease period of voice 2
modifper2:
	bsr	playperiod
	lea	gdgper2,a3
	lea	period2t,a5
	lea	period2,a4
	bsr	modifyperiod	;and so on...
	bra	waitbutton
perup3:
	move.b	#2,playflag
	move.l	period3,d7
	cmp.l	#32768,d7
	bge	waitmessage
	add.l	#32,d7
	bra	modifper3
perdn3:
	move.b	#2,playflag
	move.l	period3,d7
	cmp.l	#256,d7
	bls	waitmessage
	sub.l	#32,d7
modifper3:
	bsr	playperiod
	lea	gdgper3,a3
	lea	period3t,a5
	lea	period3,a4
	bsr	modifyperiod
	bra	waitbutton
perup4:
	move.b	#3,playflag
	move.l	period4,d7
	cmp.l	#32768,d7
	bge	waitmessage
	add.l	#32,d7
	bra	modifper4
perdn4:
	move.b	#3,playflag
	move.l	period4,d7
	cmp.l	#256,d7
	bls	waitmessage
	sub.l	#32,d7
modifper4:
	bsr	playperiod
	lea	gdgper4,a3
	lea	period4t,a5
	lea	period4,a4
	bsr	modifyperiod

; increaseing/decreasing period until the mousebutton is released

waitbutton:
	move.l	4,a6
	move.l	wdwhandle,a0
	move.l	86(a0),a0	;window user-port
	jsr	GetMsg(a6)	;get intuimessage
	tst.l	d0
	beq	waitdown	;no message... go on changeing the period
	move.l	d0,a1
	move.l	20(a1),d6	;get idcmp-code of event
	jsr	ReplyMsg(a6)	;and reply message
	cmp.l	#$8,d6
	beq	waitmessage	;if the button was released, we are ready
	bra	waitdown

; set period for requested voice

playperiod:
	moveq	#0,d4
	move.b	playflag,d4
	asl.w	#4,d4
	move.l	#$dff0a0,a4
	adda.l	d4,a4
	move.l	#3579546,d0
	move.l	d7,d1
	divu	d1,d0
	move.w	d0,audxper(a4)
	rts

; quit this wonderfull program ...

quitplthear:
	move.w	#0,aud0vol
	move.w	#0,aud1vol	;clear all volumes and
	move.w	#0,aud2vol
	move.w	#0,aud3vol
	move.w	#15,dmacon	;stop all audio-dma
	move.l	intuibase,a6
	tst.l	wdwhandle
	beq	nowdwclose	;close the PLTHear-window
	move.l	wdwhandle,a0
	jsr	CloseWindow(a6)
nowdwclose:	
	move.l	4,a6
	lea	mem,a2		;pointer to memory-handles
	lea	long,a3		;pointer to sound-lengths
	moveq	#3,d3		;4 sounds to drop
dropsmems:
	move.l	(a2)+,a1	;read next adress
	move.l	(a3)+,d0	;read next length
	beq	dropnextmem	;length = 0 ... no memory
	jsr	FreeMem(a6)	;free memory
dropnextmem:
	dbra	d3,dropsmems	;go on freeing memory
	tst.l	dosbase
	beq	nodropdos
	move.l	dosbase,a1
	jsr	CloseLibrary(a6)	;close dos_lib
nodropdos:
	tst.l	graphbase
	beq	nodropgraph
	move.l	graphbase,a1
	jsr	CloseLibrary(a6)	;close graph_lib
nodropgraph:
	tst.l	intuibase
	beq	nodropintui
	move.l	intuibase,a1
	jsr	CloseLibrary(a6)	;close intui_lib
nodropintui:
	tst.l	infomem
	beq	nodropinfomem
	move.l	#1024,d0
	move.l	infomem,a1
	jsr	FreeMem(a6)	;drop infomem
nodropinfomem:
	tst.l	startmsg
	beq	quitplthearprog
	move.l	startmsg,a1	;reply wb-start-message
	jsr	ReplyMsg(a6)
quitplthearprog:
	moveq	#0,d0
	moveq	#0,d1
	move.l	startsp,sp
	rts			;and ... that's the end of plthear

; loadfile-routine, gets length of file, allocates mem and finally loads it

loadfile:
	movem.l	d1-d7/a1-a6,-(sp)
	move.l	a0,a5		;keep pointer to filename
	move.l	d0,d5		;keep mem-type
	move.l	dosbase,a6
	move.l	a5,d1
	moveq	#-2,d2		;lock-mode = -2 ... read !
	jsr	Lock(a6)	;get filelock
	move.l	d0,d7		;keep pointer to filelock
	beq	lerror1		;no lock ... error !
	move.l	dosbase,a6
	move.l	d7,d1		;filelock
	move.l	infomem,d2	;info-memory
	jsr	Examine(a6)	;examine file-info-data
	tst.l	d0		;d0 = 0 ? ... Error !
	beq	lerror1
	move.l	d7,d1		;drop filelock
	jsr	UnLock(a6)
	move.l	infomem,a3
	move.l	124(a3),d0	;get length of file
	addq.l	#2,d0		;we want some zero-bytes at the end
	move.l	4,a6
	move.l	d5,d1		;get requested mem-type
	jsr	AllocMem(a6)	;allocate memory
	move.l	d0,a2		;keep memory-pointer
	tst.l	d0		;no memory ... error !
	beq	lerror1
	move.l	a5,d1		;filename-pointer
	move.l	#1005,d2	;open-mode: old
	move.l	dosbase,a6
	jsr	Open(a6)	;open file
	move.l	d0,d4		;keep filehandle
	beq	lerror1		;filehandle = 0 ? ... error !
	move.l	d0,d1
	move.l	a2,d2		;memory-pointer
	move.l	124(a3),d3	;length of file
	jsr	Read(a6)	;read file
	move.l	d4,d1
	jsr	Close(a6)	;close file
	move.l	124(a3),d4	;keep length of file
	addq.l	#2,d4		;we still want some zero-bytes at the end
	move.l	a2,a0		;data-pointer in a0
	move.l	d4,d0		;length of data in d0
exitloadfile:
	movem.l	(sp)+,d1-d7/a1-a6
	rts			;we are ready !
lerror1:
	moveq	#0,d0		;d0 = 0 ... that means one error
	bra	exitloadfile	;and we are ready too !

; get ascii out of integer (textpointer => a0, inter => d0)

getascii:
	moveq	#16,d1
	divu	#10000,d0
	addi.b	#48,d0
	move.b	d0,(a0)
	lsr.l	d1,d0		;into ASCII-text
	divu	#1000,d0
	addi.b	#48,d0
	move.b	d0,1(a0)
	lsr.l	d1,d0
	divu	#100,d0
	addi.b	#48,d0
	move.b	d0,2(a0)
	lsr.l	d1,d0
	divu	#10,d0
	addi.b	#48,d0
	move.b	d0,3(a0)
	lsr.l	d1,d0
	addi.b	#48,d0
	move.b	d0,4(a0)
	rts

; display the wonderfull plthear-help-window

plthelp:
	move.l	intuibase,a6
	lea	wabout,a0	;open help-window
	jsr	OpenWindow(a6)
	move.l	d0,d7		;keep wdwhandle
	beq	quitplthelp	;no window ! ... that's unbeliveable
	move.l	graphbase,a6
	move.l	d7,a1
	move.l	50(a1),a1
	moveq	#2,d0		;set pen to color 2
	jsr	SetAPen(a6)
	move.l	d7,a1
	move.l	50(a1),a1
	moveq	#2,d0		;rect allmost the whole window
	moveq	#1,d1
	move.w	#537,d2
	move.w	#188,d3
	jsr	RectFill(a6)
	move.l	intuibase,a6
	moveq	#5,d3		;y-pos of first line
	lea	helptx,a5	;pointer to help-lines
	moveq	#19,d5		;20 lines to print
plthelploop1:
	lea	texttext,a4	;memory for text-line
	moveq	#-1,d6		;counter for length to pre-zero
plthelploop2:
	addq.w	#1,d6		;count one more character
	move.b	(a5)+,(a4)+	;copy it
	bne	plthelploop2	;not zero ... go on copying
	asl.w	#3,d6		;8 points per char 
	move.w	#540,d0		;width of window
	sub.w	d6,d0		;sub width of text
	lsr.w	#1,d0		;and divide through 2 to center
	move.l	d7,a0
	move.l	50(a0),a0	;window-rastport
	lea	textline,a1	;text-struct
	move.b	#2,1(a1)	;set background-color to color 2
	move.l	d3,d1		;get y-pos
	jsr	PrintIText(a6)	;and print the line
	add.w	#9,d3		;add 9 to y-pos
	dbra	d5,plthelploop1	;and go on printing
	lea	textline,a1	;as the same text-struct is used to display
	clr.b	1(a1)		;the 'real' text reset back-col to 0
	bclr	#2,pltflag	;clear flag (see below for the sense of it)
plthelpwait:
	move.l	4,a6
	move.l	d7,a0
	move.l	86(a0),a0	;window-user-port
	jsr	WaitPort(a6)	;wait for message ... task is sleeping
	move.l	d7,a0
	move.l	86(a0),a0
	jsr	GetMsg(a6)	;now ... there's one user-request !
	tst.l	d0
	beq	plthelpwait	;no ...there's none ... (...strange!)
	move.l	d0,a1
	move.l	20(a1),d6	;get idcmp of message-cause
	jsr	ReplyMsg(a6)	;and send message back
	cmp.l	#$8,d6		;did the user (got bless him/her)
	beq	helpmousepick	;press one mouse-button ?
	btst	#2,pltflag	;drop the first key, which possibly opened
	bne	helpmousepick	;the window (a strange way to avoid that
	bset	#2,pltflag	;the window is closed at once if it was
	bra	plthelpwait	;called with the help-key)
helpmousepick:
	move.l	intuibase,a6
	move.l	d7,a0
	jsr	CloseWindow(a6)
quitplthelp:
	rts

; display the wonderfull plthear-window

dowindow:
	lea	fields,a5	;table of rects
	moveq	#40,d7		;number of rects -1
	move.l	wdwrast,dorast
	bsr	dofields
	lea	texte,a5	;table of texts
	moveq	#17,d7		;number of texts -1
	bsr	dotexts
	move.l	intuibase,a6
	lea	gdgquit,a0
	move.l	wdwhandle,a1
	move.l	#0,a2		;now we redraw the (text-) gadgets
	jsr	RefreshGadgets(a6)
	rts

; variables, texts, names, flags, handles, pointers and so on ...

dosname:	dc.b	"dos.library",0
		even
intuiname:	dc.b	"intuition.library",0
		even
graphname:	dc.b	"graphics.library",0
		even
dosbase:	dc.l	0
intuibase:	dc.l	0
graphbase:	dc.l	0
infomem:	dc.l	0
wdwhandle:	dc.l	0	;windowhandle
wdwrast:	dc.l	0	;windowrastport
dorast:		dc.l	0
thistask:	dc.l	0	;pointer to task struct
startsp:	dc.l	0	;stackpointer when programm is started
startmsg:	dc.l	0	;wb-startup-message-handle
mem:		ds.l	4	;adresses of the sounds
long:		ds.l	4	;lengths of the sounds
memo1:		dc.l	0	;one longword to keep s.th. in
memo2:		dc.w	0	;one word to keep s.th. in
doper:		dc.l	0
slength:	dc.w	0
fieldheight:	dc.w	0	;height of rect to draw
pltflag:	dc.b	0	;one byte to keep s.th. in
playflag:	dc.b	0
time:		dc.b	0
param:		dc.b	0
		even

;table of dimensions of the rectangles that make the window-look

fields:	dc.w	2,10,636,95,2
lofi1:	dc.w	71,14,167,10,0
lofi2:	dc.w	71,34,167,10,0
lofi3:	dc.w	71,54,167,10,0
lofi4:	dc.w	71,74,167,10,0
	dc.w	250,14,43,10,2
	dc.w	250,34,43,10,2
	dc.w	250,54,43,10,2
	dc.w	250,74,43,10,2
ofi1:	dc.w	299,14,43,10,2
ofi2:	dc.w	299,34,43,10,2
ofi3:	dc.w	299,54,43,10,2
ofi4:	dc.w	299,74,43,10,2
cofi1:	dc.w	347,14,43,10,2
cofi2:	dc.w	347,34,43,10,2
cofi3:	dc.w	347,54,43,10,2
cofi4:	dc.w	347,74,43,10,2
	dc.w	395,14,43,10,2
	dc.w	395,34,43,10,2
	dc.w	395,54,43,10,2
	dc.w	395,74,43,10,2
	dc.w	443,14,43,10,2
	dc.w	443,34,43,10,2
	dc.w	443,54,43,10,2
	dc.w	443,74,43,10,2
	dc.w	491,14,59,10,0
	dc.w	491,34,59,10,0
	dc.w	491,54,59,10,0
	dc.w	491,74,59,10,0
	dc.w	469,93,43,10,2
	dc.w	518,93,43,10,2
	dc.w	554,14,21,10,2
	dc.w	554,34,21,10,2
	dc.w	554,54,21,10,2
	dc.w	554,74,21,10,2
	dc.w	578,14,21,10,2
	dc.w	578,34,21,10,2
	dc.w	578,54,21,10,2
	dc.w	578,74,21,10,2
	dc.w	71,93,24,10,2
	dc.w	103,93,32,10,2

;table of texts and their positions that make the window-look

texte:	dc.w	12,16
	dc.l	tx1
	dc.w	12,36
	dc.l	tx2
	dc.w	12,56
	dc.l	tx3
	dc.w	12,76
	dc.l	tx4
	dc.w	256,16
	dc.l	tx5
	dc.w	256,36
	dc.l	tx5
	dc.w	256,56
	dc.l	tx5
	dc.w	256,76
	dc.l	tx5
	dc.w	476,95
	dc.l	tx6
	dc.w	557,16
	dc.l	tx7
	dc.w	557,36
	dc.l	tx7
	dc.w	557,56
	dc.l	tx7
	dc.w	557,76
	dc.l	tx7
	dc.w	11,95
	dc.l	tx8
	dc.w	604,16
	dc.l	typ1
	dc.w	604,36
	dc.l	typ2
	dc.w	604,56
	dc.l	typ3
	dc.w	604,76
	dc.l	typ4

tx1:	dc.b	"VOICE 1",0
	even
tx2:	dc.b	"VOICE 2",0
	even
tx3:	dc.b	"VOICE 3",0
	even
tx4:	dc.b	"VOICE 4",0
	even
tx5:	dc.b	"LOAD  ONCE  CONT  STOP  RATE",0
	even
tx6:	dc.b	"HELP  QUIT",0
	even
tx7:	dc.b	"UP DN",0
	even
tx8:	dc.b	"FILTER  ON  OFF",0
	even
typ1:	dc.l	0
typ2:	dc.l	0
typ3:	dc.l	0
typ4:	dc.l	0

;help-message

helptx:
 dc.b	"-----===== Platinum-Hear-Replacement - PLTHear =====-----",0
 dc.b	" ",0
 dc.b	"© 1991 by Joerg Schliesser / Platinum Softwareline",0
 dc.b	"Rotenwaldstrasse 20 / D-7000 Stuttgart 1 / Germany",0
 dc.b	"PLTHear is freely distributable. (Only on disks,",0
 dc.b	"distributed in a non-commercial sense) Refer to PLTTools.doc.",0
 dc.b	"As long as this text remains unchanged",0
 dc.b	" ",0
 dc.b	"PLTHear keyboard command summary:",0
 dc.b	"Load voice 1 .... Shift & F1   Load voice 2 .... Shift & F2",0
 dc.b	"Load voice 3 .... Shift & F3   Load voice 4 .... Shift & F4",0
 dc.b	"Play voice 1 ............ F1   Play voice 2 ............ F2",0
 dc.b	"Play voice 3 ............ F3   Play voice 4 ............ F4",0
 dc.b	"Repeat voice 1 ........... 1   Repeat voice 2 ........... 2",0
 dc.b	"Repeat voice 3 ........... 3   Repeat voice 4 ........... 4",0
 dc.b	"Stop voice 1 ..... Shift & 1   Stop voice 2 ..... Shift & 2",0
 dc.b	"Stop voice 3 ..... Shift & 3   Stop voice 4 ..... Shift & 4",0
 dc.b	"Hardware-Filter On ....... +   Hardware-Filter Off ...... -",0
 dc.b	"Quit PLTHear .......................................... Esc",0
 dc.b	"To close this window press any key or mouse button",0
	even

textline:
	dc.b    1,0,1
	even
	dc.l	0,0,texttext,0
texttext:	ds.b	80

txtext:		dc.b	1,0,0
		even
		dc.l	0,0
txtextpoint:	dc.l	0,0

;window-structs

wplt:
	dc.w	0,24,640,107	;x,y,w,h
	dc.b	2,1		;colors
	dc.l	$468		;idcmp,rawkey,upgadget,dngadget,mousebutton
	dc.l	$2011006	;activ,rmbtrap,front/back,drag
	dc.l	gdgquit,0,wplttitle,0,0
	dc.w	0,0,0,0
	dc.w	1
wplttitle:
 dc.b "PLTHear V1.0 © 1991 by Joerg Schliesser / Platinum Softwareline",0
	even

wabout:
	dc.w	49,5,540,190	;x,y,w,h
	dc.b	2,1		;colors
	dc.l	$408		;idcmp,rawkey,mousebuttons
	dc.l	$2011000	;activ,rmbtrap,borderless
	dc.l	0,0,0,0,0,0,0
	dc.w	1

; gadget structs

gdgquit:
	dc.l	gdghelp
	dc.w	518,93,44,11,0,1,1
	dc.l	0,0,0,0,0
	dc.w	1
	dc.l	0
gdghelp:
	dc.l	gdgload1
	dc.w	469,93,44,11,0,1,1
	dc.l	0,0,0,0,0
	dc.w	2
	dc.l	0
gdgload1:
	dc.l	gdgload2
	dc.w	250,14,44,11,0,1,1
	dc.l	0,0,0,0,0
	dc.w	3
	dc.l	0
gdgload2:
	dc.l	gdgload3
	dc.w	250,34,44,11,0,1,1
	dc.l	0,0,0,0,0
	dc.w	4
	dc.l	0
gdgload3:
	dc.l	gdgload4
	dc.w	250,54,44,11,0,1,1
	dc.l	0,0,0,0,0
	dc.w	5
	dc.l	0
gdgload4:
	dc.l	gdgonce1
	dc.w	250,74,44,11,0,1,1
	dc.l	0,0,0,0,0
	dc.w	6
	dc.l	0
gdgonce1:
	dc.l	gdgonce2
	dc.w	299,14,44,11,0,1,1
	dc.l	0,0,0,0,0
	dc.w	7
	dc.l	0
gdgonce2:
	dc.l	gdgonce3
	dc.w	299,34,44,11,0,1,1
	dc.l	0,0,0,0,0
	dc.w	8
	dc.l	0
gdgonce3:
	dc.l	gdgonce4
	dc.w	299,54,44,11,0,1,1
	dc.l	0,0,0,0,0
	dc.w	9
	dc.l	0
gdgonce4:
	dc.l	gdgrep1
	dc.w	299,74,44,11,0,1,1
	dc.l	0,0,0,0,0
	dc.w	10
	dc.l	0
gdgrep1:
	dc.l	gdgrep2
	dc.w	347,14,44,11,0,1,1
	dc.l	0,0,0,0,0
	dc.w	11
	dc.l	0
gdgrep2:
	dc.l	gdgrep3
	dc.w	347,34,44,11,0,1,1
	dc.l	0,0,0,0,0
	dc.w	12
	dc.l	0
gdgrep3:
	dc.l	gdgrep4
	dc.w	347,54,44,11,0,1,1
	dc.l	0,0,0,0,0
	dc.w	13
	dc.l	0
gdgrep4:
	dc.l	gdgstop1
	dc.w	347,74,44,11,0,1,1
	dc.l	0,0,0,0,0
	dc.w	14
	dc.l	0
gdgstop1:
	dc.l	gdgstop2
	dc.w	395,14,44,11,0,1,1
	dc.l	0,0,0,0,0
	dc.w	15
	dc.l	0
gdgstop2:
	dc.l	gdgstop3
	dc.w	395,34,44,11,0,1,1
	dc.l	0,0,0,0,0
	dc.w	16
	dc.l	0
gdgstop3:
	dc.l	gdgstop4
	dc.w	395,54,44,11,0,1,1
	dc.l	0,0,0,0,0
	dc.w	17
	dc.l	0
gdgstop4:
	dc.l	gdgper1
	dc.w	395,74,44,11,0,1,1
	dc.l	0,0,0,0,0
	dc.w	18
	dc.l	0
gdgper1:
	dc.l	gdgper2
	dc.w	494,16,48,8,0,$802,4
	dc.l	0,0,0,0,per1info
	dc.w	19
	dc.l	0
per1info:
	dc.l	period1t,0
	dc.w	0,6,0,0,0,0,0,0
	dc.l	0
period1:	dc.l	8363,0
period1t:
	dc.b	"08363",0,0,0
gdgper2:
	dc.l	gdgper3
	dc.w	494,36,48,8,0,$802,4
	dc.l	0,0,0,0,per2info
	dc.w	20
	dc.l	0
per2info:
	dc.l	period2t,0
	dc.w	0,6,0,0,0,0,0,0
	dc.l	0
period2:	dc.l	8363,0
period2t:
	dc.b	"08363",0,0,0
gdgper3:
	dc.l	gdgper4
	dc.w	494,56,48,8,0,$802,4
	dc.l	0,0,0,0,per3info
	dc.w	21
	dc.l	0
per3info:
	dc.l	period3t,0
	dc.w	0,6,0,0,0,0,0,0
	dc.l	0
period3:	dc.l	8363,0
period3t:
	dc.b	"08363",0,0,0
gdgper4:
	dc.l	gdgup1
	dc.w	494,76,48,8,0,$802,4
	dc.l	0,0,0,0,per4info
	dc.w	22
	dc.l	0
per4info:
	dc.l	period4t,0
	dc.w	0,6,0,0,0,0,0,0
	dc.l	0
period4:	dc.l	8363,0
period4t:
	dc.b	"08363",0,0,0
gdgup1:
	dc.l	gdgup2
	dc.w	554,14,22,11,0,2,1
	dc.l	0,0,0,0,0
	dc.w	23
	dc.l	0
gdgup2:
	dc.l	gdgup3
	dc.w	554,34,22,11,0,2,1
	dc.l	0,0,0,0,0
	dc.w	24
	dc.l	0
gdgup3:
	dc.l	gdgup4
	dc.w	554,54,22,11,0,2,1
	dc.l	0,0,0,0,0
	dc.w	25
	dc.l	0
gdgup4:
	dc.l	gdgdn1
	dc.w	554,74,22,11,0,2,1
	dc.l	0,0,0,0,0
	dc.w	26
	dc.l	0
gdgdn1:
	dc.l	gdgdn2
	dc.w	578,14,22,11,0,2,1
	dc.l	0,0,0,0,0
	dc.w	27
	dc.l	0
gdgdn2:
	dc.l	gdgdn3
	dc.w	578,34,22,11,0,2,1
	dc.l	0,0,0,0,0
	dc.w	28
	dc.l	0
gdgdn3:
	dc.l	gdgdn4
	dc.w	578,54,22,11,0,2,1
	dc.l	0,0,0,0,0
	dc.w	29
	dc.l	0
gdgdn4:
	dc.l	gdgfon
	dc.w	578,74,22,11,0,2,1
	dc.l	0,0,0,0,0
	dc.w	30
	dc.l	0
gdgfon:
	dc.l	gdgfoff
	dc.w	71,93,25,11,0,1,1
	dc.l	0,0,0,0,0
	dc.w	31
	dc.l	0
gdgfoff:
	dc.l	filename1gdg
	dc.w	103,93,33,11,0,1,1
	dc.l	0,0,0,0,0
	dc.w	32
	dc.l	0
filename1gdg:
	dc.l	filename2gdg
	dc.w	75,16,160,8,0,2,4
	dc.l	0,0,0,0,filename1gdginfo
	dc.w	33
	dc.l	0
filename1gdginfo:
	dc.l	filename1,0
	dc.w	0,80,0,0,0,0,0,0
	dc.l	0,0,0
filename1:
	ds.b	82
filename2gdg:
	dc.l	filename3gdg
	dc.w	75,36,160,8,0,2,4
	dc.l	0,0,0,0,filename2gdginfo
	dc.w	34
	dc.l	0
filename2gdginfo:
	dc.l	filename2,0
	dc.w	0,80,0,0,0,0,0,0
	dc.l	0,0,0
filename2:
	ds.b	82
filename3gdg:
	dc.l	filename4gdg
	dc.w	75,56,160,8,0,2,4
	dc.l	0,0,0,0,filename3gdginfo
	dc.w	35
	dc.l	0
filename3gdginfo:
	dc.l	filename3,0
	dc.w	0,80,0,0,0,0,0,0
	dc.l	0,0,0
filename3:
	ds.b	82
filename4gdg:
	dc.l	0
	dc.w	75,76,160,8,0,2,4
	dc.l	0,0,0,0,filename4gdginfo
	dc.w	36
	dc.l	0
filename4gdginfo:
	dc.l	filename4,0
	dc.w	0,80,0,0,0,0,0,0
	dc.l	0,0,0
filename4:
	ds.b	82

; display rendered fields (field-table => a5, number of fields => d7)

dofields:
	move.l	graphbase,a6
fielding:
	move.w	(a5)+,d4	;x-pos
	move.w	(a5)+,d5	;y-pos
	move.w	(a5)+,d6	;width of field
	move.w	(a5)+,fieldheight	;height of field
	move.l	dorast,a1	;get rastport
	moveq	#1,d0
	jsr	SetAPen(a6)	;set color for outline
	move.l	dorast,a1
	move.w	d4,d0
	move.w	d5,d1
	move.w	d4,d2
	move.w	d5,d3
	add.w	d6,d2
	add.w	fieldheight,d3
	jsr	RectFill(a6)	;draw outline of field
	move.l	dorast,a1
	move.w	(a5)+,d0
	jsr	SetAPen(a6)	;set color for field
	move.l	dorast,a1
	move.w	d4,d0
	move.w	d5,d1
	move.w	d4,d2
	move.w	d5,d3
	add.w	#2,d0
	add.w	#1,d1
	add.w	d6,d2
	add.w	fieldheight,d3
	sub.w	#2,d2
	sub.w	#1,d3		;draw field
	jsr	RectFill(a6)
	dbra	d7,fielding	;go on...
	rts			

; print some texts (table of texts => a5, number of texts => d7)

dotexts:
	move.l	intuibase,a6
texting:
	move.l	dorast,a0	;get rastport
	lea	txtext,a1
	move.w	(a5)+,d0	;get x-pos
	move.w	(a5)+,d1	;get y-pos
	move.l	(a5)+,txtextpoint	;pointer to ascii-text
	jsr	PrintIText(a6)	;print it ...
	dbra	d7,texting
	rts

;change window-pointer to sleeping

pltworkon:
	move.l	wdwhandle,a0
	move.l	intuibase,a6
	lea	sleeppoint,a1
	moveq	#16,d1
	moveq	#9,d0
	moveq	#0,d2
	moveq	#0,d3
	jsr	SetPointer(a6)
	rts

;change window-pointer to normal pointer

pltworkoff:
	move.l	wdwhandle,a0
	move.l	intuibase,a6
	jsr	ClearPointer(a6)
	rts

	section	pltdaten,data_c		;section 2, daten, chipmem

sleeppoint:
	dc.l	0
	dc.l	%00000000000000000001000100010000
	dc.l	%00010001000100000010101010101000
	dc.l	%00100010001000000101010101010000
	dc.l	%01000100010000001010101010100000
	dc.l	%11101110111000000001000100010000
	dc.l	%01000100010000001011101110100000
	dc.l	%01000100010000001010101010110101
	dc.l	%01000100010101011010101010101010
	dc.l	%00000000000000000100010001010101
	dc.l	0

notone:	dc.l	0

 END

