Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; example dma sample play
- ; very basic, you can do better
- ;
- ; emook2020 / david saphier v1.0
- ;
- z80dmaport equ 107
- covoxport equ $ffdf
- buffer_size equ 8192
- scaler equ 12
- device ZXSPECTRUM48
- org $8000
- ; macro to make initsample clear
- macro initsample start, length, scalerrepeat
- ld hl,start : ld de,length : ld bc,scalerrepeat
- call initdma
- endm
- start
- ; addr os sample, length of sample and $40 for initial scaler, $00 no loop
- initsample sample,sampleend-sample, $4000
- play:
- ld hl,scalers ; load from start of scale values
- playloop:
- ; get the scaler value and pass into a for playsample
- push hl : ld a, (hl) : cp $ff : jr z,replay : call playsample
- ld b,50 ; small pause
- .wt halt : djnz .wt
- pop hl : inc hl ;get scaler postition and increase to next
- jr playloop
- replay: ; pop hl and reload
- pop hl : jp play
- scalers:
- db scaler,scaler*2,scaler*3,scaler*4,scaler*5
- db scaler*6,scaler*7,scaler*8,scaler*9,scaler*10,scaler*12
- db $ff
- playsample:
- ld bc,$6b : ld hl,$6822 : out (c),h : out (c),l : ld hl,$cf87
- out (c),a : out (c),h : out (c),l
- ret
- initdma:
- ; hl = address de = dmalenght bc = scaler + repeat
- ld (dmaaddress), hl : ld (dmadlength), de
- ld a,b : ld (dmascaler),a : ld a,c
- ; deal with setting repeat flag
- cp 1 : jr z,setrepeaton
- ld a,$82 : jr setrepeaton+2
- setrepeaton:
- ld a,$b2
- ld (dmarepeat),a : ld hl,dma : ld b,dmaend-dma : ld c,z80dmaport
- otir
- ret
- dma:
- defb $c3 ;r6-reset dma
- defb $c7 ;r6-reset port a timing
- defb $ca ;r6-set port b timing same as port a
- defb $7d ;r0-transfer mode, a -> b
- dmaaddress:
- defw $e000 ;r0-port a, start address
- dmadlength:
- defw 8192 ;r0-block length
- defb $54 ; 01010100 ;r1-port a address incrementing, variable timing
- defb $2 ;r1-cycle length port b
- defb $68 ; 01101000 r2-port b address fixed, variable timing
- defb $22 ;r2-cycle length port b 2t with pre-escaler
- dmascaler:
- defb 100 ;r2-port b pre-escaler
- defb $cd ; 11001101 r4-burst mode
- defw covoxport ;r4-port b, start address
- dmarepeat: ; $b2 for short burst $82 for one shot
- defb $82 ;r5-stop on end of block, rdy active low
- defb $bb ; 10111011 read mask follows
- defb %00001000 ;mask - only port a hi byte
- retrig:
- defb $cf ;r6-load
- defb $b3 ;r6-force ready
- defb $87 ;r6-enable dma
- dmaend:
- sample:
- ; this is an mono 8bit unsigned 6800Hz sample
- incbin "clock.wav"
- sampleend:
- savesna "h:\dmasample.snx",start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement