Advertisement
Nightseeker

Soul Star X (32X) PWM Sample Program fragment

Mar 10th, 2020
966
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;****************************************************************
  2. ;   PWM Sample Program
  3. ;                   SH2 Master Main
  4. ;
  5. ;   Copyright SEGA ENTERPRISES,LTD. 1994
  6. ;---------------------------------------------------------------*
  7. ;****************************************************************
  8.    
  9.     cnop    0,4
  10.  
  11. ******************************************
  12. * Initialize the PWM interupt and driver *
  13. ******************************************
  14.  
  15. initPWM
  16.     move    #$20004030,r2
  17.     move    #1047,r0            ;1047 set cycle register (22Khz)
  18.     move.w  r0,(2,r2)
  19.  
  20.     move    #$0305,r0           ;105 set control register
  21.     move.w  r0,(r2)
  22.  
  23.     move    #$20004030,r2                   ;fill mono fifo
  24.     move    #1,r0
  25.     move.w  r0,(8,r2)
  26.     move.w  r0,(8,r2)
  27.     move.w  r0,(8,r2)
  28.  
  29.     rts
  30.     nop
  31.  
  32.     cnop    0,4
  33.  
  34.     lits
  35.  
  36.     cnop    0,4
  37.  
  38. ************************************************
  39. * Play an 8 bit sample throught the PWM ciruit *
  40. ************************************************
  41. ; input
  42. ;   R1 = Address of sample
  43. ;   R2 = length of sample
  44. ;   R3 = channel number
  45. ;   R4 = step value
  46.  
  47. PlayPWM
  48.     move    #comport1,r0
  49.     move.w  (r0)+,r1        ;get sfx number
  50.     move.w  (r0)+,r4        ;get step rate
  51.     move.w  (r0)+,r2        ;get volume
  52.  
  53.     move    #sample_table,r0
  54.     shll2   r1
  55.     shll    r1
  56.     add r1,r0
  57.     move    (r0)+,r2        ;get length
  58.     move    (r0)+,r1        ;get address
  59.  
  60.     move    #sfx_chan,r5        ;get channel to play
  61.     move    (r5),r0
  62.     add #1,r0
  63.     and #3,r0
  64.     move    r0,(r5)
  65.     move    r0,r3
  66.  
  67.     move    r2,r0
  68.     shll8   r0
  69.     move    #pwmstructs+TH,r2
  70.     shll2   r3
  71.     shll2   r3
  72.     add r3,r2
  73.     move    r0,(r2)         ;store sample length (bytes)
  74.  
  75.     cmpeq   #0,r0
  76.     bt  .done_pwm
  77.  
  78.     move    r4,(PWMSTEP,r2)     ;store step rate
  79.     shll8   r1
  80.     move    r1,(PWMADDR,r2)     ;store sample address
  81.  
  82. .done_pwm
  83.     rts
  84.     nop
  85.  
  86.     cnop    0,4
  87.  
  88. sfx_chan dc.l   0
  89.  
  90.     lits
  91.  
  92. *************************
  93. * PWM interrupt handler *
  94. *************************
  95.  
  96.     cnop    0,4
  97. spwm_irq
  98.     push    r0
  99.     push    r1
  100.     push    r2
  101.     push    r3
  102.     push    r4
  103.     push    r5
  104.     push    r6
  105.  
  106.     move    #$20004038,r2
  107.     move.b  (r2),r0         ;is pwm fifo full?
  108.     tst #$80,r0
  109.     bf  .exit
  110.  
  111.     push    pr
  112.     bsr process_pwm
  113.     nop
  114.     pop pr
  115. .exit
  116.     move    #_FRT,r1            ;tweak FRT
  117.     move.b  (_TOCR,r1),r0
  118.     xor #$02,r0
  119.     move.b  r0,(_TOCR,r1)
  120.  
  121.     move    #$2000401C,r2       ;clear irq
  122.     move.w  r0,(r2)
  123.     move.w  (r2),r0
  124.  
  125.     pop r6
  126.     pop r5
  127.     pop r4
  128.     pop r3
  129.     pop r2
  130.     pop r1
  131.     pop r0
  132.  
  133.     rts
  134.     nop
  135.    
  136.     LITS
  137.  
  138.     cnop    0,4
  139.  
  140. NUMCHANNELS equ 4
  141. PWMSIZE     equ 4   ; number of elemts in the PWM structure
  142.  
  143. PWMADDR     equ 4
  144. PWMSTEP     equ 8
  145.  
  146. *****************
  147. * Fill PWM FIFO *
  148. *****************
  149.  
  150. process_pwm
  151.     move    #$20004038,r2
  152. .loop
  153.     move    #pwmstructs+TH,r3
  154.     move    #NUMCHANNELS,r4
  155.     move    #0,r5
  156.  
  157. .channelloop
  158.     move    (r3),r0             ;is channel on?
  159.     cmppz   r0
  160.     bf/s    .skip
  161.     move.w  #$80,r1             ;if channel off, use $7f (flat)
  162.  
  163.     move    (PWMSTEP,r3),r6
  164.     sub r6,r0
  165.     move    r0,(r3)
  166.  
  167.     move    (PWMADDR,r3),r0         ;get the next pcm byte
  168.     move    r0,r1
  169.     add r6,r0
  170.     move    r0,(PWMADDR,r3)
  171.     shlr8   r1
  172.     move    #samp_base,r0
  173.     move.b  (r0,r1),r1
  174.     extu.b  r1,r1
  175. .skip
  176.     add #PWMSIZE*4,r3
  177.  
  178.     add #1,r1               ;make sure it's not 0
  179.     add r1,r5
  180.  
  181.     dt  r4
  182.     bf  .channelloop
  183.  
  184.     move.w  r5,(r2)             ;store into mono width
  185.  
  186.     move.b  (r2),r0             ;is pwm fifo full?
  187.     tst #$80,r0
  188.     bt  .loop
  189.  
  190.     rts
  191.     nop
  192.  
  193.     LITS
  194.  
  195. pwmstruct
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement