; ***********************************************************************
; *									*
; *			      CALL v1.11				*
; *  by Kafka of BARSK, with some help from CaPTein of BARSK.    	*
; *  Usage: call 0582 13574   (instead of space you could use / or -)   *
; *  Uses CIAB timer A for timing the length of the tones.		*
; *									*
; *  Compiled with ASM-One 1.20						*
; *  (YES I HAVE V1.25 but that one wount even compile on my		*
; *   A1200/28MHz/6Mb and V1.20 isn't working very well either...	*
; *   It's a shame that this great concept isn't well coded.)		*
; *									*
; *  You may change this source if you send the changed one to me!	*
; *  And if you are planning to make a commercial or shareware product	*
; *  out of this then contact me so that we can make an agreement.	*
; *									* 
; *  And if someone out there has more, AXE-related or not, tonecodes	*
; *  that you can send then please tell me.				*
; *									* 
; *  Jonas Elfström							*
; *  Smedby								*
; *  694 00  HALLSBERG							*
; *  voice: (SWEDEN) (0)582 13574					*
; *  INTERNET: uka101@suteam.hoe.se					*
; *  NANNYMUD: s,e,e,s,s,w,mail kafka    :-)				*
; *									*
; ***********************************************************************


	incdir	include:
	include	exec/exec_lib.i

	include hardware/custom.i
	include hardware/dmabits.i
	include	hardware/cia.i
	
	SECTION	CALLER,CODE

;************************************************************************
BEGIN
	move.l  a0,arg_pek
	move.w  d0,length
setup	bsr read_args
	cmp.w	#0,d0
	bne.s	.Error
	bsr start
.Error	moveq	#0,d0			;leave without errormessage
	rts
;************************************************************************

;************************************************************************
start	lea	$dff000,a0
	lea	sindata,a1

	lea	nummer(pc),a2
	lea	tonedata(pc),a3
	lea	komb(pc),a4
	
loop
	move.w	#%11111111,ADKCON(a0)	; No modulation

	move.w	(a2),d0
	add.w	d0,d0	;2*d0 foer wordstep
	add.w	d0,d0	;2*d0 foer att det aer 2 data
	move.w	(a4,d0),d1
	move.w	2(a4,d0),d2

	add.w	d1,d1
	add.w	d2,d2

	move.w	(a3,d1),d1
	move.w	(a3,d2),d2			
	cmp.w	#0,d1
	beq.s	tyst

	Move.l	a1,(AUD0+ac_ptr)(a0)
	move.w	#4,(AUD0+ac_len)(a0)
	move.w	#64,(AUD0+ac_vol)(a0)
	move.w	d1,(AUD0+ac_per)(a0)

	Move.l	a1,(AUD1+ac_ptr)(a0)
	move.w	#4,(AUD1+ac_len)(a0)
	move.w	#64,(AUD1+ac_vol)(a0)
	move.w	d2,(AUD1+ac_per)(a0)

	move.w	#(DMAF_SETCLR!DMAF_AUD0!DMAF_AUD1!DMAF_MASTER),DMACON(a0)

tyst	bsr.s	w92ms

	move.w	#0,(AUD0+ac_vol)(a0)
	move.w	#0,(AUD1+ac_vol)(a0)

	bsr.s	w92ms

	addq.l	#2,a2

	cmp.w	#$ffff,(a2)
	bne.w	loop

	move.w	#0,(AUD0+ac_vol)(a0)
	move.w	#0,(AUD1+ac_vol)(a0)
	move.w	#(DMAF_AUD0!DMAF_AUD1),DMACON(a0)	;stop sounddma
	rts	;exit
;************************************************************************

;************************************************************************
w92ms	lea	$bfd000,a5	;CIAB 8520
	move.b	ciacra(a5),d0
	and.b	#%11000000,d0	;Don't trash bits that
	or.b	#%00001000,d0	;we are not using...
	move.b	d0,ciacra(a5)
;	move.b	#%01111111,ciaicr(a5)	;clear all 8520 interupts

	move.b	#$ff,ciatalo(a5)	;write $ffff to lo hi
	move.b	#$ff,ciatahi(a5)	;gives 91.54 ms...

busy_wait
	btst	#0,ciaicr(a5)
	beq.s	busy_wait
	rts
;************************************************************************

	even

nummer	blk.w	256,0
	dc.w	$ffff

tonedata		;antal
	dc.w	636	;0	697 Hz
	dc.w	575	;1	770 Hz
	dc.w	520	;2	852 Hz
	dc.w	471	;3	941 Hz
	dc.w	367	;4	1209 Hz
	dc.w	331	;5	1336 Hz
	dc.w	300	;6	1477 Hz
	dc.w	272	;7	1633 Hz
	dc.w	000	;pause

komb	dc.w	3,5	;0
	dc.w	0,4	;1
	dc.w	0,5	;2
	dc.w	0,6	;3
	dc.w	1,4	;4
	dc.w	1,5	;5
	dc.w	1,6	;6
	dc.w	2,4	;7
	dc.w	2,5	;8
	dc.w	2,6	;9
	dc.w	3,4	;10 *
	dc.w	3,6	;11 #
	dc.w	8,8	;pause (space eller / eller- )

;************************************************************************
arg_pek dc.l	0
length	dc.w	0

Read_args
	move.l	arg_pek(pc),a0
	lea	nummer(pc),a1
	move.w	#0,d2	
	move.w	length,d0
	cmp.w	#1,d0
	beq.s	Noargs
	cmp.w	#255,d0
	bhi.w	Tomany
	subq.w	#1,d0
	moveq	#0,d1
lop	move.w	d1,d2
	add.w	d2,d2
	addq.w	#1,d2
	subi.b	#$30,(a0,d1.w)
	cmp.b	#9,(a0,d1.w)
	bhi.b	fel
	move.b	(a0,d1.w),(a1,d2.w)

vidare	addq.w	#1,d1
	cmp.w	d0,d1
	bne.s	lop	

	add.w	d0,d0
	move.w	#$ffff,(a1,d0)
	moveq	#0,d0	
	rts
Noargs
	bsr.w	no_args
	move.w	#1,d0
	rts		
tomany
	bsr	Dos_open
	Move.l	d0,a6
	jsr	-$3c(a6)	;output
	move.l	d0,d1
	lea	Tomanytxt(pc),a0
	move.l	a0,d2
	move.l	#(Tomanytxtslut-Tomanytxt),d3
	jsr	-$30(a6)	;write	
	move.w	#1,d0
	rts		

fel	
	cmp.b #" "-$30,(a0,d1.w)
	bne.s	inte_space
	move.b	#12,(a1,d2.w)
	bra.s	vidare
inte_space
	cmp.b #"/"-$30,(a0,d1.w)
	bne.s	inte_backslash
	move.b	#12,(a1,d2.w)
	bra.s	vidare
inte_backslash
	cmp.b #"-"-$30,(a0,d1.w)
	bne.s	inte_bindestr
	move.b	#12,(a1,d2.w)
	bra.s	vidare
inte_bindestr
	cmp.b #"*"-$30,(a0,d1.w)
	bne.s	inte_asterisk
	move.b	#10,(a1,d2.w)
	bra.s	vidare
inte_asterisk
	cmp.b #"#"-$30,(a0,d1.w)
	bne.s	inte_hash
	move.b	#11,(a1,d2.w)
	bra.w	vidare
inte_hash
	cmp.b #"?"-$30,(a0,d1.w)
	bne.s	inte_help
	bsr.w	Helptxt
	bra.s	rtsen
inte_help
	add.w	d0,d0
	move.w	#$ffff,(a1,d0)
	bsr.w	inte_bara_siffror
rtsen	move.w	#2,d0
	rts

no_args
	bsr	Dos_open
	Move.l	d0,a6
	jsr	-$3c(a6)	;output
	move.l	d0,d1
	lea	Noargstxt(pc),a0
	move.l	a0,d2
	move.l	#(Noargstxtslut-Noargstxt),d3
	jsr	-$30(a6)	;write	
	rts
inte_bara_siffror
	bsr	Dos_open
	Move.l	d0,a6
	jsr	-$3c(a6)	;output
	move.l	d0,d1
	lea	Badargs(pc),a0
	move.l	a0,d2
	move.l	#(Badargsslut-Badargs),d3
	jsr	-$30(a6)	;write	
	rts
Helptxt
	bsr	Dos_open
	Move.l	d0,a6
	jsr	-$3c(a6)	;output
	move.l	d0,d1
	lea	Htxt(pc),a0
	move.l	a0,d2
	move.l	#(htxtslut-htxt),d3
	jsr	-$30(a6)	;write	
	rts

DOS_OPEN
	LEA.L	doslib(PC),A1
	MOVEQ	#0,D0
	CALLEXEC OpenLibrary

	RTS
	even
doslib:	dc.b	"dos.library",0,0	
	even
		

Noargstxt
	dc.b	"No args! Type 'call ?' for help.",$0d,$0a
Noargstxtslut

Badargs
	dc.b	"Bad args! Type 'call ?' for help.",$0d,$0a
Badargsslut

Tomanytxt
	dc.b	"To many chars in argument string! (max 255)",$0d,$0a
Tomanytxtslut
Htxt
	dc.b	$9b,$33,$32,$6d,$0d,$0a,"Call"
	dc.b	$9b,$33,$31,$6d
	dc.b	" v1.11 (94) by "
	dc.b	$9b,$33,$33,$6d,"Jonas Elfstrom"
	dc.b	$9b,$33,$31,$6d
	dc.b	" 1992",$0d,$0a,$0d,$0a
	dc.b	"Just type 'call 123456' to dial that number!",$0d,$0a
	dc.b	"Use space, backslash or minus for short pause.",$0d,$0a
	dc.b	"For those who got AXE you can also use # and *.",$0d,$0a
	dc.b	"And 'call ?' for this text...",$0d,$0a,$0d,$0a

	dc.b	"WARNING: USES CIAB TIMER A DIRECT"
	dc.b	$0d,$0a
	dc.b	"         DOESN'T CHECK IF AUDIOCHANNELS IS ALLOCATED"
	dc.b	$0d,$0a
	dc.b	"This program may not be used with commercial sofware or",$0d,$0a
	dc.b	"in commercial purposes without permission from the author.",$0d,$0a
	dc.b	"The author is not responsible for any damage of any kind"
	dc.b	$0d,$0a
	dc.b	"that this software might cause."
	dc.b	$0d,$0a
	dc.b	$0d,$0a
	dc.b	"Reach author on INTERNET: uka101@suteam.hoe.se"
	dc.b	$0d,$0a
	dc.b	$0d,$0a
Htxtslut
	dc.b	"$VER: call 1.11 (94-06-08)"

;************************************************************************


	SECTION	Sampling,DATA_C
SINDATA:
	even
	dc.b	0,90,127,90,0,-90,-127,-90

	END
	
