home *** CD-ROM | disk | FTP | other *** search
/ ST-Computer Leser-CD 2000 January / LCD_01_2000.iso / games / doom / pmdoom / src / m68k / ataridma.s next >
Encoding:
Text File  |  1999-12-17  |  4.3 KB  |  271 lines

  1. |    Atari DMA sound routine
  2. |
  3. |    Patrice Mandin
  4.  
  5.     .globl    _I_UpdateSound
  6.     .globl    _I_Atari_InitDmaSound
  7.     .globl    _I_Atari_StopDmaSound
  8.  
  9.     .globl    _atari_dmabuffer
  10.     .globl    _atari_sndlength
  11.     .globl    _atari_sndcoef
  12.  
  13.     .globl    _atari_calcbuffer
  14.  
  15.     .globl    _channels        | Position courante dans sample
  16.     .globl    _channelsend        | Fin du sample
  17.     .globl    _channelleftvol_lookup    | pointeur sur table volume
  18.     .globl    _channelrightvol_lookup
  19.     .globl    _channelstep        | Position (16:16) dans les samples
  20.  
  21. | ---------------------------
  22.  
  23.     .text
  24. _I_Atari_InitDmaSound:
  25.     moveml    d0-d1/a0-a1,sp@-
  26.  
  27.     clrw    sndbuf_flag
  28.  
  29.     | Init Timer A interrupt
  30.  
  31.     movew    #0x2700,sr
  32.  
  33.     | Save current Timer A MFP registers
  34.  
  35.     lea    0xfffffa00:w,a0
  36.     lea    sound_mfp,a1
  37.     btst    #5,a0@(0x07)
  38.     sne    a1@+
  39.     btst    #5,a0@(0x13)
  40.     sne    a1@+
  41.     moveb    a0@(0x19),a1@+
  42.     moveb    a0@(0x1f),a1@+
  43.  
  44.     movel    0x134:w,old_timera
  45.  
  46.     | Set sound interrupt
  47.  
  48.     movel    #timer_a,0x134:w
  49.     bset    #5,0xfffffa07:w    | IERA
  50.     bset    #5,0xfffffa13:w    | IMRA
  51.     moveb    #8,0xfffffa19:w    | TACR Event count mode
  52.     moveb    #1,0xfffffa1f:w    | TADR 1 event
  53.  
  54.     movew    #0x2300,sr
  55.  
  56.     | Start sound interrupt
  57.  
  58.     lea    0xffff8900:w,a0
  59.     clrb    a0@(0x01)
  60.  
  61.     movel    _atari_sndlength,d1
  62.     addl    d1,d1
  63.  
  64.     movel    _atari_dmabuffer,d0
  65.     moveb    d0,a0@(0x07)
  66.     rorw    #8,d0
  67.     movel    d0,a0@(0x02)
  68.     rorw    #8,d0
  69.  
  70.     addl    d1,d0
  71.  
  72.     moveb    d0,a0@(0x13)
  73.     rorw    #8,d0
  74.     movel    d0,a0@(0x0e)
  75.     rorw    #8,d0
  76.  
  77.     moveb    #1,a0@(0x21)
  78.     moveb    #3,a0@(0x01)
  79.  
  80.     moveml    sp@+,d0-d1/a0-a1
  81.     rts
  82.  
  83.     .data
  84.  
  85.     .even
  86.     .comm    old_timera,4*1
  87.     .even
  88.     .comm    sound_mfp,4*1
  89.  
  90. | ---------------------------
  91.  
  92.     .text
  93. _I_Atari_StopDmaSound:
  94.     moveml    a0-a1,sp@-
  95.  
  96.     movew    #0x2700,sr
  97.  
  98.     | Stop Dma Replay
  99.  
  100.     clrb    0xffff8901:w
  101.  
  102.     | Restore Timer A Mfp registers
  103.  
  104.     movel    old_timera,0x134:w
  105.  
  106.     lea    sound_mfp,a0
  107.     lea    0xfffffa00:w,a1
  108.  
  109.     bclr    #5,a1@(0x07)
  110.     tstb    a0@+
  111.     beq    sound_restoreiera
  112.     bset    #5,a1@(0x07)
  113. sound_restoreiera:
  114.     bclr    #5,a1@(0x13)
  115.     tstb    a0@+
  116.     beq    sound_restoreimra
  117.     bset    #5,a1@(0x13)
  118. sound_restoreimra:
  119.     moveb    a0@+,a1@(0x19)
  120.     moveb    a0@,a1@(0x1f)
  121.  
  122.     movew    #0x2300,sr
  123.     moveml    sp@+,a0-a1
  124.     rts
  125.  
  126. | -----    Timer A interrupt : update sound
  127.  
  128.     .text
  129. timer_a:
  130.  
  131.     | Swap sound buffer
  132.  
  133.     moveml    d0-d1/a0,sp@-
  134.  
  135.     movel    _atari_dmabuffer,d0
  136.     movel    _atari_sndlength,d1
  137.     addl    d1,d1
  138.     notw    sndbuf_flag
  139.     beq    firstbuf
  140.     addl    d1,d0
  141. firstbuf:
  142.     movel    d0,_atari_calcbuffer
  143.  
  144.     lea    0xffff8900:w,a0
  145.     moveb    d0,a0@(7)
  146.     rorw    #8,d0
  147.     movel    d0,a0@(2)
  148.     rorw    #8,d0
  149.  
  150.     addl    d1,d0
  151.  
  152.     moveb    d0,a0@(0x13)
  153.     rorw    #8,d0
  154.     movel    d0,a0@(0x0e)
  155.  
  156.     moveml    sp@+,d0-d1/a0
  157.  
  158.     bclr    #5,0xfffffa0f:w        | Enable other interrupts
  159.     movew    #0x2300,sr
  160.  
  161.     bsr    _I_UpdateSound
  162.  
  163.     rte
  164.  
  165.     .data
  166.     .even
  167.     .comm    _atari_calcbuffer,1*4
  168.     .even
  169.     .comm    sndbuf_flag,1*2
  170.  
  171. | ---------------------------
  172.  
  173.     .text
  174. _I_UpdateSound:
  175.     moveml    d0-d7/a0-a6,sp@-
  176.  
  177. | ----- Clear calc buffer
  178.  
  179. |    movel    _atari_calcbuffer,a0
  180.     lea    tempbuffer,a0
  181.     movel    _atari_sndlength,d0
  182.     subql    #1,d0
  183. clearbuffer:
  184.     clrl    a0@+
  185.     clrl    a0@+
  186.     dbra    d0,clearbuffer
  187.  
  188. | ----- Calc new sound in tempbuffer
  189.  
  190.     lea    _channels,a1
  191.     lea    _channelstep,a2    
  192.     lea    _channelleftvol_lookup,a3
  193.     lea    _channelrightvol_lookup,a4    
  194.     lea    _channelsend,a6
  195.     moveq    #7,d0    | chan
  196. calcchannel:
  197.     tstl    a1@
  198.     beq    calcnextchannel
  199.  
  200.     moveml    d0/a3-a4,sp@-
  201.     
  202.     clrl    d3
  203.     movel    a1@,a5    | adr depart sample
  204.     movel    a3@,a3    | table volume
  205.     movel    a4@,a4    | table volume
  206.     movemw    a2@,d3-d4    | position actuelle
  207.     movemw    _atari_sndcoef,d6-d7    | coef
  208. |    movel    _atari_calcbuffer,a0
  209.     lea    tempbuffer,a0
  210.     movel    _atari_sndlength,d1
  211.     moveq    #0,d0
  212.     subql    #1,d1
  213. calctemp:
  214.     moveb    a5@(d3:l),d0    | sample
  215.     movel    a3@(d0:l:4),d5    | left
  216.     movel    a4@(d0:l:4),d2    | right
  217.     addw    d7,d4    
  218.     addxw    d6,d3
  219.     addl    d5,a0@+
  220.     addl    d2,a0@+
  221.     dbra    d1,calctemp
  222.  
  223.     moveml    sp@+,d0/a3-a4
  224.  
  225.     | test end of sample
  226.  
  227.     movel    a5,d1
  228.     addl    d3,d1
  229.     cmpl    a6@,d1
  230.     bmi    noendofspl
  231.     clrl    a1@        
  232.     clrl    d3
  233.     clrl    d4
  234. noendofspl:
  235.  
  236.     movemw    d3-d4,a2@    | save cur pos
  237.  
  238.     | next channel
  239. calcnextchannel:
  240.     addql    #4,a1
  241.     addql    #4,a2
  242.     addql    #4,a3
  243.     addql    #4,a4
  244.     addql    #4,a6
  245.  
  246.     dbra    d0,calcchannel
  247.  
  248. | ----- Calc final buffer
  249.  
  250.     lea    tempbuffer,a0
  251.     movel    _atari_calcbuffer,a1
  252.     movel    _atari_sndlength,d0
  253.     subqw    #1,d0
  254. bcl_final:
  255.     movel    a0@+,d1
  256.     movel    a0@+,d2
  257.     asrl    #7,d1
  258.     asrl    #7,d2
  259.     moveb    d1,a1@+
  260.     moveb    d2,a1@+
  261.     dbra    d0,bcl_final
  262.  
  263. | ----- End
  264.  
  265.     moveml    sp@+,d0-d7/a0-a6
  266.     rts
  267.  
  268.     .data
  269.     .even
  270.     .comm    tempbuffer,512*4*2
  271.