Subversion Repositories Kolibri OS

Rev

Rev 115 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ha 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                                 ;;
3
;;  SB16.INC                                                       ;;
4
;;                                                                 ;;
5
;;  Sound Blaster 16 functions for MenuetOS                        ;;
6
;;                                                                 ;;
7
;;  Copyright 2002 Paolo Minazzi, paolo.minazzi@inwind.it          ;;
8
;;                                                                 ;;
9
;;  See file COPYING for details                                   ;;
10
;;                                                                 ;;
11
;;  - 11.07.2002 8 bit stereo mode - Ville Turjanmaa               ;;
12
;;                                                                 ;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14
 
15
 
16
SB16_load_music  equ   0xc0000000
17
SB16_play_music  equ   0xc0000001
18
DMAPage          equ   0x2A
19
Rate             equ   44100
20
SB16Buffer       equ   0x2A0000
21
SB16_Status      equ   SB16Buffer+65536
22
 
23
iglobal
24
  sound_data_format   dd    0x1
25
  sound_data_length   dd    65536
26
  sound_data_freq     dd    44100
27
endg
28
 
29
sound_interface:
30
 
31
   cmp  eax,0                     ; Load data
32
   jne  no_SB16_load_music
379 serge 33
   mov  edi,[TASK_BASE]
115 poddubny 34
   add  edi,TASKDATA.mem_start
1 ha 35
   add  ebx,[edi]
36
   call code_SB16_load_music
37
   ret
38
 no_SB16_load_music:
39
 
40
   cmp  eax,1                     ; Play data
41
   jne  no_SB16_play_music
42
   call code_SB16_play_music
43
   ret
44
 no_SB16_play_music:
45
 
46
   cmp  eax,2                     ; Set data formats
47
   jne  no_SB16_data_format
48
   cmp  ebx,0                     ; ebx=0 play format
49
   jne  no_sound_format
50
   mov  [sound_data_format],ecx     ; 1=8b mono, 2=8b stereo
51
   ret
52
  no_sound_format:
53
   cmp  ebx,1                     ; ebx=1 data length
54
   jne  no_sound_length
55
   mov  [sound_data_length],ecx     ;
56
   ret
57
 no_sound_length:
58
   cmp  ebx,2                     ; ebx=2 sound data frequency
59
   jne  no_sound_freq
60
   mov  [sound_data_freq],ecx
61
   ret
62
 no_sound_freq:
63
   ret
64
 
65
 no_SB16_data_format:
66
 
67
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
68
   cmp   eax, edi                      ; this is subfunction #55 ?
69
    jne  retFunc55                     ; if no then return.
379 serge 70
   cmp   byte [sound_flag],0
1 ha 71
   jne   retFunc55
72
   movzx eax, byte [countDelayNote]
73
   or    al, al                        ; player is busy ?
74
    jnz  retFunc55                     ; return counter delay Note
379 serge 75
;   mov   eax, [TASK_BASE]
1 ha 76
;   mov   eax, [eax+0x10]               ; address application im memory
77
;   add   eax, edx                      ; add offset Delay-Note string
78
;   mov   [memAdrNote], eax
79
   mov   [memAdrNote],edx
379 serge 80
   mov   eax,[TASK_BASE]
115 poddubny 81
   mov   eax,[eax+TASKDATA.pid]
1 ha 82
   mov   [pidProcessNote],eax
83
   xor   eax, eax                      ; Ok!  EAX = 0
84
 retFunc55:
85
   mov   [esp+36], eax                 ; return value EAX for application
86
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
87
 
88
   ret
89
 
90
 
91
 
92
 
93
code_SB16_play_music:
94
 
95
        cmp  [sound_data_format],1
96
        jne  no_sound_8bm
97
        call sb_play_8b_mono
98
        ret
99
      no_sound_8bm:
100
 
101
        cmp  [sound_data_format],2
102
        jne  no_sound_8bs
103
        call sb_play_8b_stereo
104
        ret
105
      no_sound_8bs:
106
 
107
        ret
108
 
109
 
110
 
111
 
112
 
113
Blaster_command:
114
 
115
  push eax
116
  push ecx
117
  push edx
118
 
119
  mov  dx,word [sb16]
120
  add  dx,0xc
121
  mov  cx,1000
122
 bcl1:
123
  in   al,dx
124
  and  al,128
125
  jz   bcl2
126
  loop bcl1
127
 bcl2:
128
  mov  al,[esp+8]
129
  mov  dx,[esp+0]
130
  add  dx,word [sb16]
131
  out  dx,al
132
 
133
  pop  edx
134
  pop  ecx
135
  pop  eax
136
 
137
  ret
138
 
139
 
140
sb_play_8b_stereo:
141
 
142
  pusha
143
 
144
  call  sb_set_dma
145
 
146
  call  sb_set_stereo
147
 
148
  mov   dx,0xc
149
  mov   al,0xa8
150
  call  Blaster_command
151
 
152
  mov   al,0x40
153
  call  Blaster_command
154
 
155
  mov   al,245
156
  call  Blaster_command
157
 
158
  mov   al,0x48
159
  call  Blaster_command
160
 
161
  mov   al,0xff
162
  call  Blaster_command
163
  call  Blaster_command
164
 
165
  mov   al,0x91
166
  call  Blaster_command
167
 
168
  popa
169
  ret
170
 
171
 
172
 
173
sb_set_stereo:
174
 
175
  push eax
176
  push edx
177
 
178
  call sb_wait
179
 
180
  mov  dx,word [sb16]
181
  add  dx,0x4
182
  mov  al,0xe
183
  out  dx,al
184
  inc  dx
185
  in   al,dx
186
  and  al,253
187
  or   al,2     ; stereo
188
  out  dx,al
189
 
190
  pop  edx
191
  pop  eax
192
  ret
193
 
194
 
195
 
196
code_SB16_load_music:
197
 
198
     cmp byte [SB16_Status],1
199
     je  nol
200
     mov edi,SB16Buffer
201
     mov esi,ebx
202
     mov ecx,65536/4
203
     cld
204
     rep movsd
205
nol: ret
206
 
207
 
208
iglobal
209
  dma_table  db   0x87,0x83,0x81,0x82
210
endg
211
 
212
 
213
 
214
;--------------------------------
215
;        program dma
216
;--------------------------------
217
 
218
sb_set_dma:
219
 
220
         pusha
221
 
222
         mov eax,[sound_dma]
223
         add eax,4
224
         out 0xa,al
225
 
226
         mov al,0
227
         out 0xc,al
228
 
229
         mov eax,[sound_dma]
230
         add eax,0x48
231
         out 0xb,al
232
 
233
         mov edx,[sound_dma]
234
         shl edx,1
235
         mov al,0
236
         out dx,al
237
 
238
         mov al,0
239
         out dx,al
240
 
241
         mov   edx,[sound_dma]
242
         add   edx,dma_table
243
         movzx edx,byte [edx]
244
         mov   al,DMAPage
245
         out   dx,al
246
 
247
         mov edx,[sound_dma]
248
         shl edx,1
249
         inc edx
250
         mov eax,[sound_data_length]
251
         dec eax
252
         and eax,0xff
253
         ; mov al,(DataLength-1) and 0xff
254
         out dx,al
255
 
256
         mov eax,[sound_data_length]
257
         dec eax
258
         shr eax,8
259
         ; mov al,(DataLength-1) shr 8
260
         out dx,al
261
 
262
         mov eax,[sound_dma] ; DMA
263
         out 0xa,al
264
 
265
         popa
266
         ret
267
 
268
 
269
 
270
sb_play_8b_mono:
271
 
272
 
273
        call sb_set_dma
274
 
275
        cmp byte [SB16_Status],1
276
        jne contsb16
277
        jmp retserve
278
      contsb16:
279
 
280
        mov dx,word [sb16]
281
        add dx,4
282
        mov ecx,[sound_dma]
283
        mov ax,0x01
284
        shl ax,cl
285
        shl ax,8
286
        add ax,0x81
287
        out dx,ax
288
 
289
        mov ax,0f280h   ;enable irq5
290
        out dx,ax
291
 
292
 
293
adr1_SB:   mov dx,word [sb16]
294
           add dx,0ch
295
           in al,dx
296
           and al,080h
297
           jnz adr1_SB
298
 
299
           call sb_set_stereo
300
 
301
           mov al,0d1h
302
           out dx,al
303
 
304
 
305
        mov   dx,word [sb16]
306
        add   dx,0ch
307
 
308
        call  sb_wait
309
 
310
        mov   al,40h                              ; Rate
311
        out   dx,al
312
        call  sb_wait
313
        mov   al,256-1000000/Rate
314
        out   dx,al
315
 
316
        call  sb_wait
317
 
318
        mov   al,14h                              ; Datalength
319
        out   dx,al
320
        call  sb_wait
321
 
322
        mov eax,[sound_data_length]
323
        dec eax
324
        and eax,0xff
325
        ;mov   al,(DataLength-1) and 0xff
326
        out   dx,al
327
        call  sb_wait
328
        mov eax,[sound_data_length]
329
        dec eax
330
        shr eax,8
331
        ;mov   al,(DataLength-1) shr 8
332
        out   dx,al
333
 
334
    retserve:
335
 
336
        ret
337
 
338
 
339
sb_wait: in al,dx                                ;wait
340
         and al,080h
341
         jnz sb_wait
342
 
343
         ret
344
 
345
 
346
 
347
 
348
;****************************************
349
; END CODE SB16 by Minazzi Paolo
350
;***************************************