Subversion Repositories Kolibri OS

Rev

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

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