1 |
|
2 |
SECTION TEXT |
3 |
|
4 |
even |
5 |
|
6 |
; How to use the Microwire/LMC1992: |
7 |
; http://alive.atari.org/alive11/mcrowire.php |
8 |
; http://www.atari-forum.com/wiki/index.php/Atari_STE_FAQ_compiled_by_The_Paranoid_/_Paradox |
9 |
|
10 |
;Master Volume: d d d d d d (all 6 bits used) |
11 |
; 0 0 0 0 0 0 = -80 db volume |
12 |
; 0 1 0 1 0 0 = -40 db volume |
13 |
; 1 0 1 x x x = 0 db volume (max) |
14 |
; Each increment represents 2 db. If the 3 left bit encode "101", |
15 |
; the last 3 bits are being ignored. |
16 |
; |
17 |
; Left channel: x d d d d d (left bit ignored) |
18 |
; 0 0 0 0 0 = -40 db volume |
19 |
; 0 1 0 1 0 = -20 db volume |
20 |
; 1 0 1 x x = 0 db volume (max) |
21 |
; Each increment represents 2 db. If the 3 left bit carry "101", |
22 |
; the last 2 bits are being ignored. |
23 |
; |
24 |
; Right channel: x d d d d d (left bit ignored) |
25 |
; 0 0 0 0 0 = -40 db volume |
26 |
; 0 1 0 1 0 = -20 db volume |
27 |
; 1 0 1 x x = 0 db volume (max) |
28 |
; Each increment represents 2 db. If the left 3 bit are "101", |
29 |
; the last 2 bits are being ignored. |
30 |
|
31 |
|
32 |
; Device adress: |
33 |
; - LMC1992 '10' |
34 |
; |
35 |
; Command: |
36 |
; - Mixer '000' |
37 |
; - Bass '001' |
38 |
; - Treble '010' |
39 |
; - Master volume '011' |
40 |
; - Right volume '100' |
41 |
; - Left volume '101' |
42 |
; |
43 |
|
44 |
LMC_MIXER equ %10000000000 |
45 |
LMC_BASS equ %10001000000 |
46 |
LMC_TREBLE equ %10010000000 |
47 |
LMC_MASTERVOL equ %10011000000 |
48 |
LMC_RIGHTVOL equ %10100000000 |
49 |
LMC_LEFTVOL equ %10101000000 |
50 |
|
51 |
|
52 |
; d0=data to send |
53 |
SetMixer |
54 |
move.w sr,-(sp) |
55 |
move.w #$2700,sr ;interrupts off during start of operation |
56 |
|
57 |
move.w #%11111111111,$ffff8924.w ;set microwiremask |
58 |
move.w d0,$ffff8922.w |
59 |
.waitstart |
60 |
cmpi.w #%11111111111,$ffff8924.w ;wait formicrowire write to start |
61 |
beq.s .waitstart |
62 |
move.w (sp)+,sr ;now microwire write started we can safely re-enable interrupts |
63 |
.waitend |
64 |
cmpi.w #%11111111111,$ffff8924.w ;wait for microwire write to finish |
65 |
bne.s .waitend |
66 |
rts |
67 |
|
68 |
|
69 |
|
70 |
|
71 |
InitMixer |
72 |
move.w #LMC_MIXER+%000001,d0 ; mix DMA+YM equally |
73 |
bsr.s SetMixer |
74 |
move.w #LMC_BASS+%000110,d0 ; +0db bass |
75 |
bsr.s SetMixer |
76 |
move.w #LMC_TREBLE+%000110,d0 ; +0db treble |
77 |
bsr.s SetMixer |
78 |
move.w #LMC_MASTERVOL+%101000,d0 ; -0db master volume |
79 |
bsr.s SetMixer |
80 |
move.w #LMC_RIGHTVOL+%010100,d0 ; -0db right |
81 |
bsr.s SetMixer |
82 |
move.w #LMC_LEFTVOL+%010100,d0 ; -0db left |
83 |
bsr.s SetMixer |
84 |
rts |
85 |
|
86 |
|
87 |
FadeAudioOut |
88 |
move.w #%101000,d1 |
89 |
.loop |
90 |
subq.w #1,d1 |
91 |
move.w d1,d0 |
92 |
add.w #LMC_MASTERVOL,d0 |
93 |
bsr SetMixer |
94 |
bsr WaitVbl |
95 |
bsr WaitVbl |
96 |
bsr WaitVbl |
97 |
tst.w d1 |
98 |
bne.s .loop |
99 |
rts |
100 |
|
101 |
|
102 |
|
103 |
|
104 |
even |
105 |
|
106 |
; Audio DMA issues here: |
107 |
; http://atari-ste.anvil-soft.com/html/devdocu4.htm |
108 |
; a0=sample start |
109 |
; a1=sample end |
110 |
; return d0=approximate duration in VBLs |
111 |
StartReplay |
112 |
movem.l a0/a1/d1,-(sp) |
113 |
|
114 |
move.l a1,d0 |
115 |
sub.l a0,d0 ; Size in bytes |
116 |
lsr.l #8,d0 ; /256 (12517 khz=12517 bytes per second=250.34 bytes per VBL) |
117 |
|
118 |
move.l a0,d1 ; Start adress |
119 |
|
120 |
lea $ffff8900.w,a0 |
121 |
|
122 |
move.b d1,$7(a0) ; $ffff8907.w Dma start adress (low) |
123 |
lsr.l #8,d1 |
124 |
move.b d1,$5(a0) ; $ffff8905.w Dma start adress (mid) |
125 |
lsr.l #8,d1 |
126 |
move.b d1,$3(a0) ; $ffff8903.w Dma start adress (high) |
127 |
|
128 |
move.l a1,d1 ; End adress |
129 |
move.b d1,$13(a0) ; $ffff8913.w Dma end adress (low) |
130 |
lsr.l #8,d1 |
131 |
move.b d1,$11(a0) ; $ffff8911.w Dma end adress (mid) |
132 |
lsr.l #8,d1 |
133 |
move.b d1,$f(a0) ; $ffff890f.w Dma end adress (high) |
134 |
|
135 |
move.b #1+128,$21(a0) ; $ffff8921.w DMA mode (128=mono) (0=6258,1=12517,2=25033,3=50066) |
136 |
move.b #1,$1(a0) ; $ffff8901.w DMA control (0=stop, 1=play once, 2=loop) |
137 |
|
138 |
movem.l (sp)+,a0/a1/d1 |
139 |
rts |
140 |
|
141 |
|
142 |
EndReplay |
143 |
lea $ffff8900.w,a0 |
144 |
move.b #0,1(a0) ; $ffff8901.w DMA Control |
145 |
rts |
146 |
|
147 |
|
148 |
|
149 |
; Xia code |
150 |
|
151 |
dmaplay_numframesperblock equ 5+6+5+6 ; 22 |
152 |
|
153 |
; a0=sequence start |
154 |
; a1=Sample sequence adresses |
155 |
DmaSequencePlayerInit |
156 |
move.l a0,_AdrDmaPlayPosition |
157 |
move.l a0,_AdrDmaPlayStart |
158 |
move.l a1,_AdrDmaAddressTable |
159 |
move.w #0,dmaplay_sequence_index |
160 |
move.w #1,dmaplay_waitcounter |
161 |
rts |
162 |
|
163 |
DmaSequencePlayerVbl |
164 |
;move.w #$777,$ffff8240.w |
165 |
subq.w #1,dmaplay_waitcounter |
166 |
bne.s .exit |
167 |
|
168 |
.next_sequence |
169 |
addq.w #1,dmaplay_sequence_index |
170 |
|
171 |
move.l a6,-(sp) |
172 |
move.l d0,-(sp) |
173 |
|
174 |
move.w #dmaplay_numframesperblock,dmaplay_waitcounter |
175 |
_AdrDmaPlayPosition=*+2 |
176 |
lea $123456,a6 |
177 |
moveq.l #0,d0 ; maybe this could be removed for optimization? |
178 |
move.b (a6),d0 |
179 |
bmi.s .loop |
180 |
|
181 |
.continue |
182 |
lsl.w #2,d0 |
183 |
_AdrDmaAddressTable=*+2 |
184 |
lea $123456,a6 |
185 |
move.l (a6,d0.l),d0 |
186 |
|
187 |
; Stop the sample |
188 |
lea $ffff8901.w,a6 |
189 |
sf.b (a6) ; $ffff8901.w DMA control (0=stop, 1=play once, 2=loop) |
190 |
|
191 |
; Set the new adress |
192 |
movep.l d0,(a6) |
193 |
add.l #11000,d0 |
194 |
movep.l d0,$0d-1(a6) |
195 |
move.b #128+2,$21-1(a6) ; $ffff8921.w DMA mode (128=mono) (0=6258,1=12517,2=25033,3=50066) |
196 |
move.b #1,(a6) ; $ffff8901.w DMA control (0=stop, 1=play once, 2=loop) |
197 |
|
198 |
addq.l #1,_AdrDmaPlayPosition |
199 |
|
200 |
move.l (sp)+,d0 |
201 |
move.l (sp)+,a6 |
202 |
.exit |
203 |
;move.w #$000,$ffff8240.w |
204 |
rts |
205 |
|
206 |
.loop |
207 |
;loop the song |
208 |
_AdrDmaPlayStart=*+2 |
209 |
lea $123456,a6 |
210 |
move.l a6,_AdrDmaPlayPosition |
211 |
move.b (a6),d0 |
212 |
bra.s .continue |
213 |
|
214 |
|
215 |
section DATA |
216 |
|
217 |
even |
218 |
|
219 |
|
220 |
section BSS |
221 |
|
222 |
|
223 |
dmaplay_sequence_index ds.w 1 |
224 |
dmaplay_waitcounter ds.w 1 ; set this to 1 to make the music start playing immediately on execution |