Advertisement
vladikcomper

Mega PCM v.1.1 - PCM Playback Loop

Sep 8th, 2014
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; ---------------------------------------------------------------
  2. ; PCM Playback Loop
  3. ; ---------------------------------------------------------------
  4.  
  5. Process_PCM:
  6.  
  7.     ; Read sample's byte and send it to DAC with pitching
  8.     ld  a,(hl)          ; 7 ; get PCM byte
  9.     ld  b,c         ; 4 ; b = Pitch
  10.     djnz    $           ; 8/13+ ; wait until pitch zero
  11.     ld  (YM_Port0_Data),a   ; 13    ; write to DAC
  12.     ; Cycles: 32*
  13.  
  14.     ; Increment PCM byte pointer and switch the bank if necessary
  15.     inc hl          ; 6 ; next PCM byte
  16.     bit 7,h         ; 8 ; has the bank warped?
  17.     jr  z,++            ; 7/12  ; if yes, switch the bank
  18.     ; Cycles: 21
  19.  
  20.     ; Check if sample playback is finished
  21.     exx             ; 4 ;
  22.     ld  a,c         ; 4 ; load last bank no.
  23.     sub b           ; 4 ; compare to current bank no.
  24.     jr  nz,+            ; 7/12  ; if last bank isn't reached, branch
  25.     dec hl          ; 6 ; decrease number of bytes to play in last bank
  26.     or  h           ; 4 ; is hl positive?
  27.     jp  p,+++           ; 10    ; if yes, quit playback loop
  28.     exx             ; 4 ;
  29.     ; Cycles: 43
  30.  
  31.     ; Check if we should play a new sample
  32. -   ld  a,(DAC_Number)      ; 13    ; load DAC number
  33.     or  a           ; 4 ; test it
  34.     jp  z,Process_PCM       ; 10    ; if zero, go on playing
  35.     jp  Event_Interrupt     ;   ; otherwise, interrupt playback
  36.     ; Cycles: 27
  37.  
  38.     ; Synchronization loop (20 cycles)
  39. +   exx             ; 4
  40.     nop             ; 4
  41.     jr  -           ; 12
  42.  
  43.     ; Switch to next bank
  44. +   ld  h,80h           ; restore base addr
  45.     call    LoadNextBank
  46.     jp  -
  47.  
  48.     ; Quit playback loop
  49. +   exx
  50.     jp  Event_EndPlayback
  51.  
  52. ; ---------------------------------------------------------------
  53. ; Best cycles per loop: 123*
  54. ; Max Possible rate:    3,550 kHz / 123 = 29 kHz (PAL)
  55. ; ---------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement