Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;****************************************************************
- ; PWM Sample Program
- ; SH2 Master Main
- ;
- ; Copyright SEGA ENTERPRISES,LTD. 1994
- ;---------------------------------------------------------------*
- ;****************************************************************
- cnop 0,4
- ******************************************
- * Initialize the PWM interupt and driver *
- ******************************************
- initPWM
- move #$20004030,r2
- move #1047,r0 ;1047 set cycle register (22Khz)
- move.w r0,(2,r2)
- move #$0305,r0 ;105 set control register
- move.w r0,(r2)
- move #$20004030,r2 ;fill mono fifo
- move #1,r0
- move.w r0,(8,r2)
- move.w r0,(8,r2)
- move.w r0,(8,r2)
- rts
- nop
- cnop 0,4
- lits
- cnop 0,4
- ************************************************
- * Play an 8 bit sample throught the PWM ciruit *
- ************************************************
- ; input
- ; R1 = Address of sample
- ; R2 = length of sample
- ; R3 = channel number
- ; R4 = step value
- PlayPWM
- move #comport1,r0
- move.w (r0)+,r1 ;get sfx number
- move.w (r0)+,r4 ;get step rate
- move.w (r0)+,r2 ;get volume
- move #sample_table,r0
- shll2 r1
- shll r1
- add r1,r0
- move (r0)+,r2 ;get length
- move (r0)+,r1 ;get address
- move #sfx_chan,r5 ;get channel to play
- move (r5),r0
- add #1,r0
- and #3,r0
- move r0,(r5)
- move r0,r3
- move r2,r0
- shll8 r0
- move #pwmstructs+TH,r2
- shll2 r3
- shll2 r3
- add r3,r2
- move r0,(r2) ;store sample length (bytes)
- cmpeq #0,r0
- bt .done_pwm
- move r4,(PWMSTEP,r2) ;store step rate
- shll8 r1
- move r1,(PWMADDR,r2) ;store sample address
- .done_pwm
- rts
- nop
- cnop 0,4
- sfx_chan dc.l 0
- lits
- *************************
- * PWM interrupt handler *
- *************************
- cnop 0,4
- spwm_irq
- push r0
- push r1
- push r2
- push r3
- push r4
- push r5
- push r6
- move #$20004038,r2
- move.b (r2),r0 ;is pwm fifo full?
- tst #$80,r0
- bf .exit
- push pr
- bsr process_pwm
- nop
- pop pr
- .exit
- move #_FRT,r1 ;tweak FRT
- move.b (_TOCR,r1),r0
- xor #$02,r0
- move.b r0,(_TOCR,r1)
- move #$2000401C,r2 ;clear irq
- move.w r0,(r2)
- move.w (r2),r0
- pop r6
- pop r5
- pop r4
- pop r3
- pop r2
- pop r1
- pop r0
- rts
- nop
- LITS
- cnop 0,4
- NUMCHANNELS equ 4
- PWMSIZE equ 4 ; number of elemts in the PWM structure
- PWMADDR equ 4
- PWMSTEP equ 8
- *****************
- * Fill PWM FIFO *
- *****************
- process_pwm
- move #$20004038,r2
- .loop
- move #pwmstructs+TH,r3
- move #NUMCHANNELS,r4
- move #0,r5
- .channelloop
- move (r3),r0 ;is channel on?
- cmppz r0
- bf/s .skip
- move.w #$80,r1 ;if channel off, use $7f (flat)
- move (PWMSTEP,r3),r6
- sub r6,r0
- move r0,(r3)
- move (PWMADDR,r3),r0 ;get the next pcm byte
- move r0,r1
- add r6,r0
- move r0,(PWMADDR,r3)
- shlr8 r1
- move #samp_base,r0
- move.b (r0,r1),r1
- extu.b r1,r1
- .skip
- add #PWMSIZE*4,r3
- add #1,r1 ;make sure it's not 0
- add r1,r5
- dt r4
- bf .channelloop
- move.w r5,(r2) ;store into mono width
- move.b (r2),r0 ;is pwm fifo full?
- tst #$80,r0
- bt .loop
- rts
- nop
- LITS
- pwmstruct
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement