Advertisement
Guest User

Code

a guest
Oct 6th, 2012
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;-----------------------------------------------------------------------
  2. ; SUB-CPU PCM SOUND DRIVER EQUATES
  3. ;-----------------------------------------------------------------------
  4. ENVdat    equ     $0ff0001
  5. PANdat    equ     $0ff0003
  6. FDLdat    equ     $0ff0005
  7. FDHdat    equ     $0ff0007
  8. LSLdat    equ     $0ff0009
  9. LSHdat    equ     $0ff000b
  10. STdat     equ     $0ff000d
  11. CTRLdat   equ     $0ff000f
  12. ONOFFdat  equ     $0ff0011
  13. CH1low    equ     $0ff0021
  14. CH1hi     equ     $0ff0023
  15. CH2low    equ     $0ff0025
  16. CH2hi     equ     $0ff0027
  17. WAVEdat   equ     $0ff2001
  18. PCMREGDELAY       EQU   5         ; clock cycle delay for PCM ops
  19. ;-----------------------------------------------------------------------
  20. ;       PCMWAIT macro
  21. ;-----------------------------------------------------------------------
  22. PCMWAIT macro
  23.      movem.l    d0,-(a7)
  24.      move.w  #PCMREGDELAY,d0
  25.      dbra    d0,*
  26.      movem.l (a7)+,d0
  27.      endm
  28.  
  29.         ; . . .
  30.  
  31. ;PCM Test
  32.         lea Packet(pc), a5
  33.         move.l  #$60000, 8(a5)      ;Destination
  34.         move.l  #$FFFF, 4(a5)       ;Bytes to transfer
  35.         move.l  #0, (BeginOffset)   ;Start location from file
  36.         lea TDATA(pc),a0        ;File name
  37.         bsr LoadROM2        ;Load it
  38.    
  39.         move.l  #$FFFF,PCMLeft      ;size of loaded data
  40.         move.b  #$FF,CacheFilled    ;indicate cache has been filled
  41.         lea ($60000).l,a0       ;get pointer to cache
  42.         move.l  a0,CachePtr     ;beginning of cache buffer
  43.         add.l   #$10000,a0      ;get pointer to byte past end of cache
  44.         move.l  a0,EndCachePtr
  45.  
  46.         ;sample rate config
  47.         move.b  #1,SampRateH        ;set H byte of sample rate
  48.         move.b  #$F7,SampRateL      ;set L byte of sample rate
  49.  
  50.         move.b  #$44,($40000).l
  51.         move.b  #$FF,($40020).l     ;channels to stop
  52.         bsr InitPCM         ;init PCM audio
  53.  
  54.         move.b  #$EF,($40010).l
  55.         bsr PlayPCM
  56.         bra *
  57.  
  58.         ; . . .
  59.  
  60. InitPCM:
  61.     move.b  #0,NextBank      ;set next bank to bank 00
  62.     move.b  #0,PCMEndSet     ;set end set condition to no
  63.     move.b  #0,PCMPlay       ;set PCMPlay to 00
  64.     move.b  #0,PCMError      ;set PCMError to 00 (okay)
  65.     move.w  #0,PCMRAMPtr     ;set to start address in PCM RAM
  66.  
  67.     ;check CacheFilled to make sure it is set to $FF
  68.     move.b  CacheFilled,d0   ;get CacheFilled value
  69.     cmp.b   #$FF,d0          ;check if CacheFilled is $FF
  70.     beq     do_init          ;yes, do init
  71.     move.b  #$01,PCMError    ;indicate error
  72.     rts                      ;return
  73.  
  74. do_init
  75.     move.b  ($40020).l,ONOFFdat    ;set all audio channels to OFF
  76.     PCMWAIT
  77.     move.b  ($40000).l,CTRLdat     ;select to set CH1 parameters
  78.     PCMWAIT
  79.     move.b  #$FF,PANdat      ;set full L/R channels
  80.     PCMWAIT
  81.     move.b  #$00,ENVdat      ;set ENV to 00 - 0 volume
  82.                              ; (ramp up when play starts)
  83.     PCMWAIT
  84.     move.b  #$00,STdat       ;set start address to $0000
  85.     PCMWAIT
  86.     move.b  #$00,LSHdat      ;set loop high address to $00
  87.     PCMWAIT
  88.     move.b  #$00,LSLdat      ;set loop low address to $00
  89.     PCMWAIT
  90.     move.b  SampRateH,FDHdat ;set H byte of sample rate
  91.     PCMWAIT
  92.     move.b  SampRateL,FDLdat ;set L byte of sample rate
  93.     PCMWAIT
  94.  
  95. ;Pre-load data
  96. UpdCache:
  97.     move.l PCMLeft,d0       ;number of bytes to move
  98.     move.l #16-1,d1         ;set max number of banks to fill, correct for dbra
  99.     move.l CachePtr,a0      ;get pointer to cache
  100.  
  101. fill_bank
  102.     move.b NextBank,d2      ;get next bank to be filled
  103.     or.b   #$80,d2          ;1000b - bit 4 = 1 = play on
  104.                             ; bit 3 = 0 = select bank
  105.     move.b d2,CTRLdat       ;select bank to write into
  106.     PCMWAIT
  107.     move.l #4096,d3         ;set number of bytes to load into bank
  108.     cmp.l  #4096,d0         ;check if PCMLeft is less than 4K
  109.     bge    upd_d0           ;no, update d0 (PCMLeft)
  110.     move.l d0,d3            ;yes, re-set num bytes to move to actual value
  111. upd_d0
  112.     sub.l  d3,d0            ;subtract number of bytes moved from d0 (PCMLeft)
  113.     add.w  d3,PCMRAMPtr     ;point to byte past last byte that will be
  114.                             ; written into PCM RAM
  115.     sub.l  #1,d3            ;correct for dbra
  116.     move.l #WAVEdat,a1      ;get pointer to start of PCM bank
  117.  
  118. do_fill
  119.     move.b (a0)+,(a1)       ;write byte of PCM data from cache to PCM bank
  120.     add.l  #2,a1            ;update pointer in PCM bank
  121.                             ; -- +2 is because of interleaved RAM
  122.     dbra   d3,do_fill
  123.  
  124.     add.b  #1,NextBank      ;add 1 to NextBank value
  125.     cmp.b  #16,NextBank     ;check if NextBank has gone to 16
  126.     bne    chk_done         ;no, check if done
  127.     move.b #0,NextBank      ;yes, wrap to 0
  128. chk_done
  129.     cmp.l  #0,d0            ;check if d0 (PCMLeft) has gone to 0
  130.     bne    cont_load        ;no, continue load procedure
  131.                             ;yes, make sure last byte in last bank is an $FF
  132.     sub.l  #2,a1            ;get position of last byte written
  133.     move.b #$FF,(a1)
  134.     move.w PCMRAMPtr,d4     ;get PCM address of 2nd to last byte
  135.                             ; put in PCM RAM
  136.     sub.w  #2,d4
  137.     move.b  d4,LSLdat       ;set loop low address
  138.     PCMWAIT
  139.     lsr.w   #8,d4           ;get high order byte
  140.     move.b  d4,LSHdat       ;set loop high address
  141.     PCMWAIT
  142.     move.b  #$FF,PCMEndSet  ;indicate end has been set
  143.     bra    load_done        ;yes, the pre-load is done
  144.  
  145. cont_load
  146.     dbra   d1,fill_bank     ;fill next bank
  147.     ;make sure last byte in last bank is an $FF
  148.     sub.l  #2,a1            ;get position of last byte written
  149.     move.b #$FF,(a1)
  150.  
  151. load_done
  152.     move.l a0,CachePtr      ;update pointer in cache
  153.     move.l d0,PCMLeft       ;update PCM left to load into banks
  154.     move.b #00,CacheFilled  ;set CacheFilled to show that it was emptied
  155.  
  156.     rts
  157.  
  158. PlayPCM:
  159.  
  160.     move.b  #$80,CTRLdat     ;set channel 1 play to start
  161.     PCMWAIT
  162.     move.b  ($40010).l,ONOFFdat    ;set audio channel 1 to ON ( 0 = on)
  163.     PCMWAIT
  164.     move.b  #$FF,PCMPlay     ;set flag to show audio is playing
  165.  
  166. ;ramp up the audio to full
  167.     move.b  #00,d0
  168.     move.l  #51-1,d1
  169. ramp_up
  170.     add.b   #$05,d0
  171.     move.b  d0,ENVdat
  172.     PCMWAIT
  173.     dbra    d1,ramp_up
  174.  
  175.     rts
  176.  
  177.   cnop 0,4
  178.  
  179. NumSectsLeft    dc.l    $0    ;number of sectors to load off of disk
  180. NumSects        dc.l    $0    ;number of sectors to move this load
  181. StartSect       dc.l    $0    ;start sector
  182.  
  183. PCMLeft         dc.l    $0   ;# of bytes of PCM data left to put in PCM RAM
  184. CachePtr        dc.l    $0   ;pointer to start of cache
  185.                              ; -- and later current read from posn
  186. EndCachePtr     dc.l    $0   ;pointer to byte past end of cache
  187. PCMRAMPtr       dc.l    $0   ;pointer into PCM RAM
  188. CacheFilled     dc.b    $0   ;$FF = yes, $$00 = no
  189. NextBank        dc.b    $0   ;next PCM bank to be filled (0 - f)
  190. PCMEndSet       dc.b    $0   ;$FF = end set (condx for ending loop)
  191.                              ; $00 = end not set
  192. PCMPlay         dc.b    $0   ;$FF = audio playing
  193.                              ; $00 =  not playing/request stop
  194. PCMError        dc.b    $0   ;error return $00 = okay
  195. SampRateH       dc.b    $0   ;H byte of sample rate
  196. SampRateL       dc.b    $0   ;L byte of sample rate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement