Subversion Repositories Kolibri OS

Rev

Rev 431 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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