home *** CD-ROM | disk | FTP | other *** search
- | Atari DMA sound routine
- |
- | Patrice Mandin
-
- .globl _I_UpdateSound
- .globl _I_Atari_InitDmaSound
- .globl _I_Atari_StopDmaSound
-
- .globl _atari_dmabuffer
- .globl _atari_sndlength
- .globl _atari_sndcoef
-
- .globl _atari_calcbuffer
-
- .globl _channels | Position courante dans sample
- .globl _channelsend | Fin du sample
- .globl _channelleftvol_lookup | pointeur sur table volume
- .globl _channelrightvol_lookup
- .globl _channelstep | Position (16:16) dans les samples
-
- | ---------------------------
-
- .text
- _I_Atari_InitDmaSound:
- moveml d0-d1/a0-a1,sp@-
-
- clrw sndbuf_flag
-
- | Init Timer A interrupt
-
- movew #0x2700,sr
-
- | Save current Timer A MFP registers
-
- lea 0xfffffa00:w,a0
- lea sound_mfp,a1
- btst #5,a0@(0x07)
- sne a1@+
- btst #5,a0@(0x13)
- sne a1@+
- moveb a0@(0x19),a1@+
- moveb a0@(0x1f),a1@+
-
- movel 0x134:w,old_timera
-
- | Set sound interrupt
-
- movel #timer_a,0x134:w
- bset #5,0xfffffa07:w | IERA
- bset #5,0xfffffa13:w | IMRA
- moveb #8,0xfffffa19:w | TACR Event count mode
- moveb #1,0xfffffa1f:w | TADR 1 event
-
- movew #0x2300,sr
-
- | Start sound interrupt
-
- lea 0xffff8900:w,a0
- clrb a0@(0x01)
-
- movel _atari_sndlength,d1
- addl d1,d1
-
- movel _atari_dmabuffer,d0
- moveb d0,a0@(0x07)
- rorw #8,d0
- movel d0,a0@(0x02)
- rorw #8,d0
-
- addl d1,d0
-
- moveb d0,a0@(0x13)
- rorw #8,d0
- movel d0,a0@(0x0e)
- rorw #8,d0
-
- moveb #1,a0@(0x21)
- moveb #3,a0@(0x01)
-
- moveml sp@+,d0-d1/a0-a1
- rts
-
- .data
-
- .even
- .comm old_timera,4*1
- .even
- .comm sound_mfp,4*1
-
- | ---------------------------
-
- .text
- _I_Atari_StopDmaSound:
- moveml a0-a1,sp@-
-
- movew #0x2700,sr
-
- | Stop Dma Replay
-
- clrb 0xffff8901:w
-
- | Restore Timer A Mfp registers
-
- movel old_timera,0x134:w
-
- lea sound_mfp,a0
- lea 0xfffffa00:w,a1
-
- bclr #5,a1@(0x07)
- tstb a0@+
- beq sound_restoreiera
- bset #5,a1@(0x07)
- sound_restoreiera:
- bclr #5,a1@(0x13)
- tstb a0@+
- beq sound_restoreimra
- bset #5,a1@(0x13)
- sound_restoreimra:
- moveb a0@+,a1@(0x19)
- moveb a0@,a1@(0x1f)
-
- movew #0x2300,sr
- moveml sp@+,a0-a1
- rts
-
- | ----- Timer A interrupt : update sound
-
- .text
- timer_a:
-
- | Swap sound buffer
-
- moveml d0-d1/a0,sp@-
-
- movel _atari_dmabuffer,d0
- movel _atari_sndlength,d1
- addl d1,d1
- notw sndbuf_flag
- beq firstbuf
- addl d1,d0
- firstbuf:
- movel d0,_atari_calcbuffer
-
- lea 0xffff8900:w,a0
- moveb d0,a0@(7)
- rorw #8,d0
- movel d0,a0@(2)
- rorw #8,d0
-
- addl d1,d0
-
- moveb d0,a0@(0x13)
- rorw #8,d0
- movel d0,a0@(0x0e)
-
- moveml sp@+,d0-d1/a0
-
- bclr #5,0xfffffa0f:w | Enable other interrupts
- movew #0x2300,sr
-
- bsr _I_UpdateSound
-
- rte
-
- .data
- .even
- .comm _atari_calcbuffer,1*4
- .even
- .comm sndbuf_flag,1*2
-
- | ---------------------------
-
- .text
- _I_UpdateSound:
- moveml d0-d7/a0-a6,sp@-
-
- | ----- Clear calc buffer
-
- | movel _atari_calcbuffer,a0
- lea tempbuffer,a0
- movel _atari_sndlength,d0
- subql #1,d0
- clearbuffer:
- clrl a0@+
- clrl a0@+
- dbra d0,clearbuffer
-
- | ----- Calc new sound in tempbuffer
-
- lea _channels,a1
- lea _channelstep,a2
- lea _channelleftvol_lookup,a3
- lea _channelrightvol_lookup,a4
- lea _channelsend,a6
- moveq #7,d0 | chan
- calcchannel:
- tstl a1@
- beq calcnextchannel
-
- moveml d0/a3-a4,sp@-
-
- clrl d3
- movel a1@,a5 | adr depart sample
- movel a3@,a3 | table volume
- movel a4@,a4 | table volume
- movemw a2@,d3-d4 | position actuelle
- movemw _atari_sndcoef,d6-d7 | coef
- | movel _atari_calcbuffer,a0
- lea tempbuffer,a0
- movel _atari_sndlength,d1
- moveq #0,d0
- subql #1,d1
- calctemp:
- moveb a5@(d3:l),d0 | sample
- movel a3@(d0:l:4),d5 | left
- movel a4@(d0:l:4),d2 | right
- addw d7,d4
- addxw d6,d3
- addl d5,a0@+
- addl d2,a0@+
- dbra d1,calctemp
-
- moveml sp@+,d0/a3-a4
-
- | test end of sample
-
- movel a5,d1
- addl d3,d1
- cmpl a6@,d1
- bmi noendofspl
- clrl a1@
- clrl d3
- clrl d4
- noendofspl:
-
- movemw d3-d4,a2@ | save cur pos
-
- | next channel
- calcnextchannel:
- addql #4,a1
- addql #4,a2
- addql #4,a3
- addql #4,a4
- addql #4,a6
-
- dbra d0,calcchannel
-
- | ----- Calc final buffer
-
- lea tempbuffer,a0
- movel _atari_calcbuffer,a1
- movel _atari_sndlength,d0
- subqw #1,d0
- bcl_final:
- movel a0@+,d1
- movel a0@+,d2
- asrl #7,d1
- asrl #7,d2
- moveb d1,a1@+
- moveb d2,a1@+
- dbra d0,bcl_final
-
- | ----- End
-
- moveml sp@+,d0-d7/a0-a6
- rts
-
- .data
- .even
- .comm tempbuffer,512*4*2
-