Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;-----------------------------------------------------------------------
- ; SUB-CPU PCM SOUND DRIVER EQUATES
- ;-----------------------------------------------------------------------
- ENVdat equ $0ff0001
- PANdat equ $0ff0003
- FDLdat equ $0ff0005
- FDHdat equ $0ff0007
- LSLdat equ $0ff0009
- LSHdat equ $0ff000b
- STdat equ $0ff000d
- CTRLdat equ $0ff000f
- ONOFFdat equ $0ff0011
- CH1low equ $0ff0021
- CH1hi equ $0ff0023
- CH2low equ $0ff0025
- CH2hi equ $0ff0027
- WAVEdat equ $0ff2001
- PCMREGDELAY EQU 5 ; clock cycle delay for PCM ops
- ;-----------------------------------------------------------------------
- ; PCMWAIT macro
- ;-----------------------------------------------------------------------
- PCMWAIT macro
- movem.l d0,-(a7)
- move.w #PCMREGDELAY,d0
- dbra d0,*
- movem.l (a7)+,d0
- endm
- ; . . .
- ;PCM Test
- lea Packet(pc), a5
- move.l #$60000, 8(a5) ;Destination
- move.l #$FFFF, 4(a5) ;Bytes to transfer
- move.l #0, (BeginOffset) ;Start location from file
- lea TDATA(pc),a0 ;File name
- bsr LoadROM2 ;Load it
- move.l #$FFFF,PCMLeft ;size of loaded data
- move.b #$FF,CacheFilled ;indicate cache has been filled
- lea ($60000).l,a0 ;get pointer to cache
- move.l a0,CachePtr ;beginning of cache buffer
- add.l #$10000,a0 ;get pointer to byte past end of cache
- move.l a0,EndCachePtr
- ;sample rate config
- move.b #1,SampRateH ;set H byte of sample rate
- move.b #$F7,SampRateL ;set L byte of sample rate
- move.b #$44,($40000).l
- move.b #$FF,($40020).l ;channels to stop
- bsr InitPCM ;init PCM audio
- move.b #$EF,($40010).l
- bsr PlayPCM
- bra *
- ; . . .
- InitPCM:
- move.b #0,NextBank ;set next bank to bank 00
- move.b #0,PCMEndSet ;set end set condition to no
- move.b #0,PCMPlay ;set PCMPlay to 00
- move.b #0,PCMError ;set PCMError to 00 (okay)
- move.w #0,PCMRAMPtr ;set to start address in PCM RAM
- ;check CacheFilled to make sure it is set to $FF
- move.b CacheFilled,d0 ;get CacheFilled value
- cmp.b #$FF,d0 ;check if CacheFilled is $FF
- beq do_init ;yes, do init
- move.b #$01,PCMError ;indicate error
- rts ;return
- do_init
- move.b ($40020).l,ONOFFdat ;set all audio channels to OFF
- PCMWAIT
- move.b ($40000).l,CTRLdat ;select to set CH1 parameters
- PCMWAIT
- move.b #$FF,PANdat ;set full L/R channels
- PCMWAIT
- move.b #$00,ENVdat ;set ENV to 00 - 0 volume
- ; (ramp up when play starts)
- PCMWAIT
- move.b #$00,STdat ;set start address to $0000
- PCMWAIT
- move.b #$00,LSHdat ;set loop high address to $00
- PCMWAIT
- move.b #$00,LSLdat ;set loop low address to $00
- PCMWAIT
- move.b SampRateH,FDHdat ;set H byte of sample rate
- PCMWAIT
- move.b SampRateL,FDLdat ;set L byte of sample rate
- PCMWAIT
- ;Pre-load data
- UpdCache:
- move.l PCMLeft,d0 ;number of bytes to move
- move.l #16-1,d1 ;set max number of banks to fill, correct for dbra
- move.l CachePtr,a0 ;get pointer to cache
- fill_bank
- move.b NextBank,d2 ;get next bank to be filled
- or.b #$80,d2 ;1000b - bit 4 = 1 = play on
- ; bit 3 = 0 = select bank
- move.b d2,CTRLdat ;select bank to write into
- PCMWAIT
- move.l #4096,d3 ;set number of bytes to load into bank
- cmp.l #4096,d0 ;check if PCMLeft is less than 4K
- bge upd_d0 ;no, update d0 (PCMLeft)
- move.l d0,d3 ;yes, re-set num bytes to move to actual value
- upd_d0
- sub.l d3,d0 ;subtract number of bytes moved from d0 (PCMLeft)
- add.w d3,PCMRAMPtr ;point to byte past last byte that will be
- ; written into PCM RAM
- sub.l #1,d3 ;correct for dbra
- move.l #WAVEdat,a1 ;get pointer to start of PCM bank
- do_fill
- move.b (a0)+,(a1) ;write byte of PCM data from cache to PCM bank
- add.l #2,a1 ;update pointer in PCM bank
- ; -- +2 is because of interleaved RAM
- dbra d3,do_fill
- add.b #1,NextBank ;add 1 to NextBank value
- cmp.b #16,NextBank ;check if NextBank has gone to 16
- bne chk_done ;no, check if done
- move.b #0,NextBank ;yes, wrap to 0
- chk_done
- cmp.l #0,d0 ;check if d0 (PCMLeft) has gone to 0
- bne cont_load ;no, continue load procedure
- ;yes, make sure last byte in last bank is an $FF
- sub.l #2,a1 ;get position of last byte written
- move.b #$FF,(a1)
- move.w PCMRAMPtr,d4 ;get PCM address of 2nd to last byte
- ; put in PCM RAM
- sub.w #2,d4
- move.b d4,LSLdat ;set loop low address
- PCMWAIT
- lsr.w #8,d4 ;get high order byte
- move.b d4,LSHdat ;set loop high address
- PCMWAIT
- move.b #$FF,PCMEndSet ;indicate end has been set
- bra load_done ;yes, the pre-load is done
- cont_load
- dbra d1,fill_bank ;fill next bank
- ;make sure last byte in last bank is an $FF
- sub.l #2,a1 ;get position of last byte written
- move.b #$FF,(a1)
- load_done
- move.l a0,CachePtr ;update pointer in cache
- move.l d0,PCMLeft ;update PCM left to load into banks
- move.b #00,CacheFilled ;set CacheFilled to show that it was emptied
- rts
- PlayPCM:
- move.b #$80,CTRLdat ;set channel 1 play to start
- PCMWAIT
- move.b ($40010).l,ONOFFdat ;set audio channel 1 to ON ( 0 = on)
- PCMWAIT
- move.b #$FF,PCMPlay ;set flag to show audio is playing
- ;ramp up the audio to full
- move.b #00,d0
- move.l #51-1,d1
- ramp_up
- add.b #$05,d0
- move.b d0,ENVdat
- PCMWAIT
- dbra d1,ramp_up
- rts
- cnop 0,4
- NumSectsLeft dc.l $0 ;number of sectors to load off of disk
- NumSects dc.l $0 ;number of sectors to move this load
- StartSect dc.l $0 ;start sector
- PCMLeft dc.l $0 ;# of bytes of PCM data left to put in PCM RAM
- CachePtr dc.l $0 ;pointer to start of cache
- ; -- and later current read from posn
- EndCachePtr dc.l $0 ;pointer to byte past end of cache
- PCMRAMPtr dc.l $0 ;pointer into PCM RAM
- CacheFilled dc.b $0 ;$FF = yes, $$00 = no
- NextBank dc.b $0 ;next PCM bank to be filled (0 - f)
- PCMEndSet dc.b $0 ;$FF = end set (condx for ending loop)
- ; $00 = end not set
- PCMPlay dc.b $0 ;$FF = audio playing
- ; $00 = not playing/request stop
- PCMError dc.b $0 ;error return $00 = okay
- SampRateH dc.b $0 ;H byte of sample rate
- SampRateL dc.b $0 ;L byte of sample rate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement