Subversion Repositories Kolibri OS

Rev

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

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