;*** Creating a vibrato ***

;Custom chip register

INTENA = $9A ;Interrupt enable register (write)
DMACON = $96 ;DMA control register (write)

;Audio registers

AUD0LC  = $A0 ;Address of audio data list
AUD0LEN = $A4 ;Length der audio data list
AUD0PER = $A6 ;Sampling eriod
AUD0VOL = $A8 ;Volume

AUD1LC  = $B0
AUD1LEN = $B4
AUD1PER = $B6
AUD1VOL = $B8

ADKCON  = $9E ;Control register for modulation

;CIA-A Port register A (mouse button)

CIAAPRA = $bfe001 

;Exec Library Base Offsets

AllocMem = -30-168 ;ByteSize,Requirements/d0,d1
FreeMem  = -30-180 ;MemoryBlock,ByteSize/a1,d0

;Other labels

Execbase = 4
chip     = 2    ;Allocate chip RAM
Vibsize = Vibend - Vibstart ;Length of vibrato table
ALsize = ALend - ALstart ;Length of audio data list
Size = ALsize + Vibsize     ;Total length of both lists

 
;*** Initialization ***
start:

;Allocate memory for data lists

 move.l  Execbase,a6
 move.l  #Size,d0       ;Length of both lists
 moveq   #chip,d1
 jsr     AllocMem(a6)   ;Allocate memory
 beq     Ende

;Copy audio data list in chip RAM

 move.l  d0,a0          ;Address in chip RAM
 move.l  #ALstart,a1    ;Address in program
 move.l  #Size-1,d1     ;Loop counter
Loop:    move.b (a1)+,(a0)+ ;Lists in chip RAM
 dbf     d1,Loop

;*** Main program

;Initialize audio registers

 move.l  d0,d1          ;Audio data list address
 add.l   #ALsize,d1     ;Address of vibrato table
 lea     $DFF000,a5
 move.w  #$000f,dmacon(a5) ;Audio DMA off
 move.l  d1,aud0lc(a5)  ;Set to  vibrato table
 move.w  #Vibsize,aud0len(a5) ;Length of vibrato table
 move.w  #8961,aud0per(a5)      ;Vibrato frequency

 move.l  d0,aud1lc(a5)  ;Channel 1 from audio data list
 move.w  #ALsize,aud1len(a5) ;Length of audio data list
 move.w  #32,aud1vol(a5)       ;Half volume

 move.w  #$00FF,adkcon(a5) ;Disable other modulation
 move.w  #$8010,adkcon(a5) ;Channel 0 modulates period from
;channel 1
;Audio DMA on

 move.w  #$8203,dmacon(a5) ;Channels 0 and 1 on

;Wait for a mouse button

wait:    btst #6,ciaapra
 bne     wait

;Audio DMA off

 move.w  #$0003,dmacon(a5) ;Channels 0 and 1 off

;*** End program  ***

 move.l  d0,a1          ;Address of lists
 move.l  #Size,d0       ;Length
 jsr     FreeMem(a6)    ;Release memory

Ende: clr.l d0
 rts

;Audio data list

ALstart:
 dc.b    0,49
 dc.b    90,117
 dc.b    127,117
 dc.b    90,49
 dc.b    0,-49
 dc.b    -90,-117
 dc.b    -127,-117
 dc.b    -90,-49
ALend:
;Vibrato table

Vibstart:
 dc.w    508,513,518,522,524,525,524,522,518,513
 dc.w    508,503,498,494,492,491,492,494,498,503
Vibend:
;Program end
 end

