;**************************************************************** ; PWM Sample Program ; SH2 Master Main ; ; Copyright SEGA ENTERPRISES,LTD. 1994 ;---------------------------------------------------------------* ;**************************************************************** cnop 0,4 ; Initialize the PWM interupt and driver initPWM mov.l #$20004030,r2 mov.l #1047,r0 ;1047 set cycle register (22Khz) mov.w r0,@(2,r2) mov.l #$0305,r0 ;105 set control register mov.w r0,@r2 mov.l #$20004030,r2 ;fill mono fifo mov #1,r0 mov.w r0,@(8,r2) mov.w r0,@(8,r2) mov.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 ; PlayPWM: push pr mov r2,r0 shll r0 mov.l #pwmstructs,r2 shll2 r3 shll r3 add r3,r2 mov.l r0,@r2 cmp/eq #0,r0 bt .done_pwm shll r1 mov.l r1,@(4,r2) ;pwm address is doubled (for 11khz playback) .done_pwm pop pr rts nop cnop 0,4 .lits cnop 0,4 pwm_irq: push r0 push r1 push r2 push r3 push r4 push r5 mov.l #$20004038,r2 mov.b @r2,r0 ;is pwm fifo full? tst #$80,r0 bf @exit push pr bsr process_pwm nop pop pr @exit mov.l #_FRT,r1 ;tweak FRT mov.b @(_TOCR,r1),r0 xor #$02,r0 mov.b r0,@(_TOCR,r1) mov.l #$2000401C,r2 ;clear irq mov.w r0,@r2 mov.w @r2,r0 pop r5 pop r4 pop r3 pop r2 pop r1 pop r0 rts nop .LITS cnop 0,4 NUMCHANNELS equ 4 PWMSIZE equ 2 ; number of elemts in the PWM structure PWMADDRESS equ 4 process_pwm: mov.l #$20004038,r2 @loop mov.l #pwmstructs,r3 mov #NUMCHANNELS,r4 mov #0,r5 @channelloop: mov.l @r3,r0 ;is channel on? cmp/eq #0,r0 bf @on mov.l #$7f,r1 ;if channel off, use $7f (flat) bra @skip nop @on: add.l #-1,r0 mov.l r0,@r3 mov.l @(PWMADDRESS,r3),r0 ;get the next pcm byte mov.l r0,r1 add.l #1,r0 mov.l r0,@(PWMADDRESS,r3) shlr r1 mov.b @r1,r1 extu.b r1,r1 @skip: add #8,r3 add.l #1,r1 ;make sure it's not 0 add r1,r5 dt r4 bf @channelloop mov.w r5,@r2 ;store into mono width mov.b @r2,r0 ;is pwm fifo full? tst #$80,r0 bt @loop rts nop .LITS pushs section SH2data pwmstructs ds.l NUMCHANNELS*PWMSIZE pops