Subversion Repositories Kolibri OS

Rev

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

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