*      
* Simple irq-based sound fx library
*
* Originally written for Blockhead's
* Revenge
*
* SLJ 5/2002
*

         org $1c00

         do 0
         jsr Init
         lda #$0f
         sta $d418
:wait    jsr $ffe4
         beq :wait
         cmp #'_'
         beq :brk
         sta 1024
         eor #$30
         sta effect
         jmp :wait
:brk     brk
         fin

Init     
         lda $0314
         sta irqjmp+1
         lda $0315
         sta irqjmp+2
         sei
         lda #<Main
         sta $0314
         lda #>Main
         sta $0315
         cli
         rts

effect   dfb $80          ;poke effect here
reset    dfb $80
count    dfb 00
freq     da 00
step     da 00
creg     dfb 00
cmask    dfb 00

Main     
         lda effect
         bmi irqjmp
         ldx reset
         beq :cont
:reset   tay
         asl
         tax
         lda icount,y
         sta count
         lda ifrq,x
         sta freq
         lda ifrq+1,x
         sta freq+1
         lda istep,x
         sta step
         lda istep+1,x
         sta step+1
         lda atdk,y
         sta $d405+14     ;v3
         lda surl,y
         sta $d406+14
         lda icreg,y
         sta creg
         lda imask,y
         sta cmask
         lda #$08
         sta $d404+14
         lda #00
         sta reset
:cont    
         lda count
         beq end
         dec count

         lda freq
         clc
         adc step
         sta freq
         sta $d400+14
         lda freq+1
         adc step+1
         sta freq+1
         sta $d401+14

         lda creg
         eor cmask
         sta creg
         sta $d404+14
irqjmp   jmp $1234


end      ldx effect
         lda endreg,x
         sta $d404+14
         lda #$80
         sta reset
         sta effect
         bne irqjmp

icount   dfb 50
         dfb 40
         dfb 40
         dfb 20
         dfb 60
         dfb 60
         dfb 60
         dfb 60
         dfb 10
         dfb 10
         dfb 10

ifrq     
         da $1000
         da $a000
         da $a000
         da $1000
         da $400
         da $1000
         da $1000
         da $a000
*         da  $3000
         da $6000
         da $3000
         da $6000

istep    
         da $2000
         da -1000
         da -1000
         da -2000
         da $3456
         da $4567
         da $5678
         da -$5678
         da $1000
         da $1000
         da -$1000

atdk     
         dfb $22
         dfb $22
         dfb $22
         dfb $22
         dfb $81
         dfb $85
         dfb $85
         dfb $51
         dfb $51
         dfb $51
         dfb $51

surl     
         dfb $f8
         dfb $f8
         dfb $fa
         dfb $f9
         dfb $f8
         dfb $f8
         dfb $f8
         dfb $f5
         dfb $f5
         dfb $f5
         dfb $f5

icreg    dfb $21
         dfb $11
         dfb $21
         dfb $11
         dfb $11
         dfb $21
         dfb $11
         dfb $11
         dfb $11
         dfb $21
         dfb $11
imask    
         dfb $30
         dfb $90
         dfb $30
         dfb 00
         dfb 00
         dfb $30
         dfb 00
         dfb 00
         dfb 00
         dfb 00
         dfb 00
endreg   
         dfb $10
         dfb $10
         dfb $10
         dfb $10
         dfb $10
         dfb $20
         dfb $10
         dfb $10
         dfb $10
         dfb $20
         dfb $10
