Advertisement
Guest User

Untitled

a guest
Feb 11th, 2020
427
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; example dma sample play
  2. ; very basic, you can do better
  3. ;
  4. ; emook2020 / david saphier v1.0
  5. ;
  6.  
  7. z80dmaport  equ 107
  8. covoxport   equ $ffdf
  9. buffer_size equ 8192
  10. scaler      equ 12  
  11.  
  12.     device ZXSPECTRUM48
  13.    
  14.     org $8000
  15.    
  16.     ; macro to make initsample clear
  17.     macro initsample start, length, scalerrepeat
  18.         ld hl,start : ld de,length  : ld bc,scalerrepeat
  19.         call initdma
  20.     endm
  21.    
  22. start
  23.     ; addr os sample, length of sample and $40 for initial scaler, $00 no loop
  24.    
  25.     initsample sample,sampleend-sample, $4000
  26.  
  27. play:  
  28.     ld hl,scalers                           ; load from start of scale values
  29.    
  30. playloop:
  31.     ; get the scaler value and pass into a for playsample
  32.     push hl : ld a, (hl) : cp $ff : jr z,replay : call playsample
  33.    
  34.     ld b,50                                 ; small pause
  35. .wt halt : djnz .wt
  36.     pop hl : inc hl                         ;get scaler postition and increase to next
  37.     jr playloop
  38.  
  39. replay:                                     ; pop hl and reload
  40.     pop hl : jp play
  41.  
  42. scalers:
  43.  
  44.     db scaler,scaler*2,scaler*3,scaler*4,scaler*5
  45.     db scaler*6,scaler*7,scaler*8,scaler*9,scaler*10,scaler*12 
  46.     db $ff
  47.  
  48. playsample:
  49.     ld bc,$6b : ld hl,$6822 : out (c),h : out (c),l : ld hl,$cf87
  50.     out (c),a : out (c),h : out (c),l
  51.     ret
  52.  
  53. initdma:
  54.  
  55.     ; hl = address de = dmalenght bc = scaler + repeat
  56.     ld (dmaaddress), hl : ld (dmadlength), de
  57.     ld a,b : ld (dmascaler),a : ld a,c
  58.    
  59.     ; deal with setting repeat flag
  60.     cp 1 : jr z,setrepeaton
  61.     ld a,$82 : jr setrepeaton+2
  62.    
  63. setrepeaton:
  64.     ld a,$b2
  65.     ld (dmarepeat),a : ld hl,dma : ld b,dmaend-dma : ld c,z80dmaport
  66.     otir
  67.     ret
  68.  
  69.  
  70. dma:
  71.     defb $c3            ;r6-reset dma
  72.     defb $c7            ;r6-reset port a timing
  73.     defb $ca            ;r6-set port b timing same as port a
  74.     defb $7d            ;r0-transfer mode, a -> b
  75. dmaaddress:
  76.     defw $e000          ;r0-port a, start address
  77. dmadlength:
  78.     defw 8192           ;r0-block length
  79.     defb $54            ; 01010100 ;r1-port a address incrementing, variable timing
  80.     defb $2             ;r1-cycle length port b
  81.     defb $68            ; 01101000 r2-port b address fixed, variable timing
  82.     defb $22            ;r2-cycle length port b 2t with pre-escaler
  83. dmascaler:
  84.     defb 100            ;r2-port b pre-escaler
  85.     defb $cd            ; 11001101 r4-burst mode
  86.     defw covoxport      ;r4-port b, start address
  87. dmarepeat:              ; $b2 for short burst $82 for one shot
  88.     defb $82            ;r5-stop on end of block, rdy active low
  89.     defb $bb            ; 10111011 read mask follows
  90.     defb %00001000      ;mask - only port a hi byte
  91. retrig:
  92.     defb $cf            ;r6-load
  93.     defb $b3            ;r6-force ready
  94.     defb $87            ;r6-enable dma       
  95. dmaend:
  96.  
  97. sample:
  98.     ; this is an mono 8bit unsigned 6800Hz sample
  99.     incbin "clock.wav"
  100. sampleend: 
  101.  
  102.     savesna "h:\dmasample.snx",start
Advertisement
RAW Paste Data Copied
Advertisement