Subversion Repositories Kolibri OS

Rev

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

Rev 109 Rev 139
1
;---------------------------------------------------------------------
1
;---------------------------------------------------------------------
2
;
2
;
3
;   MenuetOS AC97 WAV Player
3
;   MenuetOS AC97 WAV Player
4
;
4
;
5
;    0.03  November 10, 2004  doesn't halt if file not found
5
;    0.03  November 10, 2004  doesn't halt if file not found
6
;    0.04  November 11, 2004  better positioning (with mouse)
6
;    0.04  November 11, 2004  better positioning (with mouse)
7
;    0.05  November 14, 2004  internals clean up
7
;    0.05  November 14, 2004  internals clean up
8
;                             fixed cutting sound at the edges
8
;                             fixed cutting sound at the edges
9
;    0.06  November 17, 2004  fixed many bugs
9
;    0.06  November 17, 2004  fixed many bugs
10
;    0.07  Nov      20, 2004  deactivates text box when 'play' pressed
10
;    0.07  Nov      20, 2004  deactivates text box when 'play' pressed
11
;                             stops playing before closing a window
11
;                             stops playing before closing a window
12
;    0.08  Nov      24, 2004  added support for 8bit and mono modes
12
;    0.08  Nov      24, 2004  added support for 8bit and mono modes
13
;                             +variable rate for some chipsets
13
;                             +variable rate for some chipsets
-
 
14
;    0.09  August   26, 2006  modified to use function 70
14
;
15
;
15
;   Use [flat assembler 1.56] to compile.
16
;   Use [flat assembler 1.64] to compile.
16
;
17
;
17
;---------------------------------------------------------------------
18
;---------------------------------------------------------------------
18
 
19
 
19
  use32 	 ; turn on 32 bit mode
20
  use32 	 ; turn on 32 bit mode
20
  org	  0x0	      ; the program is placed at 0 offset
21
  org	  0x0	      ; the program is placed at 0 offset
21
 
22
 
22
  db	 'MENUET01'	; 8-byte identifier of MenuetOS application
23
  db	 'MENUET01'	; 8-byte identifier of MenuetOS application
23
  dd	 0x01	      ; header version (always 1)
24
  dd	 0x01	      ; header version (always 1)
24
  dd	 START	       ; address of the beginning of the code
25
  dd	 START	       ; address of the beginning of the code
25
  dd	 IMAGE_END     ; size of the program's image
26
  dd	 IMAGE_END     ; size of the program's image
26
  dd	 MEMORY_END	; how much memory does it need
27
  dd	 MEMORY_END	; how much memory does it need
27
  dd	 STACK_P     ; a pointer to the top of the stack
28
  dd	 STACK_P     ; a pointer to the top of the stack
28
  dd	 textbox_string
29
  dd	 textbox_string
29
;  dd     0x0             ; address of buffer for parameters (not used)
30
;  dd     0x0             ; address of buffer for parameters (not used)
30
  dd	 0x0	     ; reserved
31
  dd	 0x0	     ; reserved
31
 
32
 
32
;---------------------------------------------------------------------
33
;---------------------------------------------------------------------
33
 
-
 
34
include "lang.inc"
34
 
35
include "macros.inc"	 ; standart macros & constants
35
include "macros.inc"	 ; standart macros & constants
36
include "meosfunc.inc"	   ; MenuetOS API functions names
36
include "meosfunc.inc"	   ; MenuetOS API functions names
37
include "debug.inc"	; printing to debug board
37
include "debug.inc"	; printing to debug board
38
include "constant.inc"	   ; BIT?? constants
38
include "constant.inc"	   ; BIT?? constants
39
include "ac97.inc"     ; AC'97 constants
39
include "ac97.inc"     ; AC'97 constants
40
include "pci.inc"     ; PCI interface
40
include "pci.inc"     ; PCI interface
41
include "codec.inc"	; functions for configuring codec
41
include "codec.inc"	; functions for configuring codec
42
include "frontend.inc"	   ; main window
42
include "frontend.inc"	   ; main window
43
 
43
 
44
;---------------------------------------------------------------------
44
;---------------------------------------------------------------------
45
 
45
 
46
;  Uncomment these strings if you don't want to receive debug messages:
46
;  Uncomment these strings if you don't want to receive debug messages:
47
 
47
 
48
;  macro dps str   {}    ; dps prints a string without CRLF
48
;  macro dps str   {}    ; dps prints a string without CRLF
49
;  macro dpd num   {}    ; prints unsigned decimal number
49
;  macro dpd num   {}    ; prints unsigned decimal number
50
;  macro pregs     {}    ; outputs EAX, EBX, ECX, EDX
50
;  macro pregs     {}    ; outputs EAX, EBX, ECX, EDX
51
;  macro newline   {}    ; CRLF
51
;  macro newline   {}    ; CRLF
52
;  macro print str {}    ; output a string with CRLF
52
;  macro print str {}    ; output a string with CRLF
53
;  macro dph arg   {}    ; print hex number
53
;  macro dph arg   {}    ; print hex number
54
 
54
 
55
;---------------------------------------------------------------------
55
;---------------------------------------------------------------------
56
 
56
 
57
;macro device id, addr { dd id, addr }
57
;macro device id, addr { dd id, addr }
58
macro devices [id, str]
58
macro devices [id, str]
59
{
59
{
60
  common
60
  common
61
    label supported_devices dword
61
    label supported_devices dword
62
  forward
62
  forward
63
    local string
63
    local string
64
    dd id
64
    dd id
65
    dd string
65
    dd string
66
  forward
66
  forward
67
    string db str
67
    string db str
68
    db 0
68
    db 0
69
}
69
}
70
 
70
 
71
 
71
 
72
devices \
72
devices \
73
  (ICH_DID shl 16) + INTEL_VID,      "ICH"    ,\
73
  (ICH_DID shl 16) + INTEL_VID,      "ICH"    ,\
74
  (ICH0_DID shl 16) + INTEL_VID,     "ICH0"   ,\
74
  (ICH0_DID shl 16) + INTEL_VID,     "ICH0"   ,\
75
  (ICH2_DID shl 16) + INTEL_VID,     "ICH2"   ,\
75
  (ICH2_DID shl 16) + INTEL_VID,     "ICH2"   ,\
76
  (ICH3_DID shl 16) + INTEL_VID,     "ICH2"   ,\
76
  (ICH3_DID shl 16) + INTEL_VID,     "ICH2"   ,\
77
  (ICH4_DID shl 16) + INTEL_VID,     "ICH4"   ,\
77
  (ICH4_DID shl 16) + INTEL_VID,     "ICH4"   ,\
78
  (ICH5_DID shl 16) + INTEL_VID,     "ICH5"   ,\
78
  (ICH5_DID shl 16) + INTEL_VID,     "ICH5"   ,\
79
  (MX440_DID shl 16) + INTEL_VID,    "440MX"  ,\
79
  (MX440_DID shl 16) + INTEL_VID,    "440MX"  ,\
80
  (SI7012_DID shl 16) + SIS_VID,     "SI7012" ,\
80
  (SI7012_DID shl 16) + SIS_VID,     "SI7012" ,\
81
  (NFORCE_DID shl 16) + NVIDIA_VID,  "NForce" ,\
81
  (NFORCE_DID shl 16) + NVIDIA_VID,  "NForce" ,\
82
  (NFORCE2_DID shl 16) + NVIDIA_VID, "NForce2",\
82
  (NFORCE2_DID shl 16) + NVIDIA_VID, "NForce2",\
83
  (AMD8111_DID shl 16) + AMD_VID,    "AMD8111",\
83
  (AMD8111_DID shl 16) + AMD_VID,    "AMD8111",\
84
  (AMD768_DID shl 16) + AMD_VID,     "AMD768"
84
  (AMD768_DID shl 16) + AMD_VID,     "AMD768"
85
dd    0
85
dd    0
86
 
86
 
87
 
87
 
88
;---------------------------------------------------------------------
88
;---------------------------------------------------------------------
89
;---  MAIN PROGRAM  --------------------------------------------------
89
;---  MAIN PROGRAM  --------------------------------------------------
90
;---------------------------------------------------------------------
90
;---------------------------------------------------------------------
91
 
91
 
92
START:
92
START:
93
 
93
 
94
; Print PCI version (for example, 2.16)
94
; Print PCI version (for example, 2.16)
95
;        mcall   MF_PCI, 0
95
;        mcall   MF_PCI, 0
96
;        mov     bl, al
96
;        mov     bl, al
97
;        movzx   eax, ah
97
;        movzx   eax, ah
98
;        dps    "PCI version: "
98
;        dps    "PCI version: "
99
;        dpd     eax
99
;        dpd     eax
100
;        movzx   eax, bl
100
;        movzx   eax, bl
101
;        dpd     eax
101
;        dpd     eax
102
;        newline
102
;        newline
103
 
103
 
104
; Check PCI access mechanism (must be 1 or 2)
104
; Check PCI access mechanism (must be 1 or 2)
105
    mcall    MF_PCI, 2
105
    mcall    MF_PCI, 2
106
    dec    al
106
    dec    al
107
    cmp    al, 1
107
    cmp    al, 1
108
    jna    @f
108
    jna    @f
109
    print    "Error: cannot access PCI bus."
109
    print    "Error: cannot access PCI bus."
110
    jmp    exit
110
    jmp    exit
111
;        dps     "PCI returned "
111
;        dps     "PCI returned "
112
;        movzx   eax, al
112
;        movzx   eax, al
113
;        dpd     eax
113
;        dpd     eax
114
;        newline
114
;        newline
115
     @@:
115
     @@:
116
 
116
 
117
 
117
 
118
; Get last bus & then check all buses & devices
118
; Get last bus & then check all buses & devices
119
    mcall    MF_PCI, 1
119
    mcall    MF_PCI, 1
120
    mov    [lastbus], al
120
    mov    [lastbus], al
121
 
121
 
122
     ; looking for a compatible device
122
     ; looking for a compatible device
123
    mov    [bus], -1
123
    mov    [bus], -1
124
  .next_bus:
124
  .next_bus:
125
    inc    [bus]
125
    inc    [bus]
126
 
126
 
127
    mov    al, [lastbus]
127
    mov    al, [lastbus]
128
    cmp    al, [bus]
128
    cmp    al, [bus]
129
    jb	  .device_not_found
129
    jb	  .device_not_found
130
 
130
 
131
    mov    [devfn], 0
131
    mov    [devfn], 0
132
  .next_devfn:
132
  .next_devfn:
133
 
133
 
134
    mov    cl, 0
134
    mov    cl, 0
135
    call    pciRegRead32
135
    call    pciRegRead32
136
 
136
 
137
    mov    edi, supported_devices
137
    mov    edi, supported_devices
138
      @@:
138
      @@:
139
    mov    ebx, [edi]
139
    mov    ebx, [edi]
140
    test    ebx, ebx
140
    test    ebx, ebx
141
    jz	  @f
141
    jz	  @f
142
    cmp    eax, ebx
142
    cmp    eax, ebx
143
    jnz    .skip
143
    jnz    .skip
144
    add    edi, 4
144
    add    edi, 4
145
    mov    [device_id], eax
145
    mov    [device_id], eax
146
    mov    edx, [edi]
146
    mov    edx, [edi]
147
    call    debug_outstr
147
    call    debug_outstr
148
    jmp    proceed
148
    jmp    proceed
149
       .skip:
149
       .skip:
150
    add    edi, 8
150
    add    edi, 8
151
    jmp    @b
151
    jmp    @b
152
      @@:
152
      @@:
153
 
153
 
154
    inc    [devfn]
154
    inc    [devfn]
155
    cmp    [devfn], 255
155
    cmp    [devfn], 255
156
    jb	  .next_devfn
156
    jb	  .next_devfn
157
 
157
 
158
    jmp    .next_bus
158
    jmp    .next_bus
159
 
159
 
160
 
160
 
161
  .device_not_found:
161
  .device_not_found:
162
    print    "Could not find Intel AC'97 compatible codec!"
162
    print    "Could not find Intel AC'97 compatible codec!"
163
    print    "1) Check if it's enabled in BIOS."
163
    print    "1) Check if it's enabled in BIOS."
164
    print    "2) Check if your device is included in the device list."
164
    print    "2) Check if your device is included in the device list."
165
    jmp    exit
165
    jmp    exit
166
 
166
 
167
 
167
 
168
 proceed:
168
 proceed:
169
    print    " integrated AC97 audio codec detected."
169
    print    " integrated AC97 audio codec detected."
170
    mov    eax, [device_id]
170
    mov    eax, [device_id]
171
    cmp    eax, (ICH4_DID shl 16) + INTEL_VID
171
    cmp    eax, (ICH4_DID shl 16) + INTEL_VID
172
    je	  .newich
172
    je	  .newich
173
    cmp    eax, (ICH5_DID shl 16) + INTEL_VID
173
    cmp    eax, (ICH5_DID shl 16) + INTEL_VID
174
    jne    .nonewich
174
    jne    .nonewich
175
      .newich:
175
      .newich:
176
    mov    [AC97ICH4], 1
176
    mov    [AC97ICH4], 1
177
      .nonewich:
177
      .nonewich:
178
 
178
 
179
    cmp    eax, (SI7012_DID shl 16) + SIS_VID
179
    cmp    eax, (SI7012_DID shl 16) + SIS_VID
180
    jne    @f
180
    jne    @f
181
    mov    [SI7012], 1
181
    mov    [SI7012], 1
182
      @@:
182
      @@:
183
 
183
 
184
;---------------------------------------------------------------------
184
;---------------------------------------------------------------------
185
 
185
 
186
; Get NAMBAR register base port address & save it
186
; Get NAMBAR register base port address & save it
187
    mov    cl, NAMBAR_REG
187
    mov    cl, NAMBAR_REG
188
    call    pciRegRead16
188
    call    pciRegRead16
189
 
189
 
190
    and    eax, 0xFFFE
190
    and    eax, 0xFFFE
191
    mov    [NAMBAR], ax
191
    mov    [NAMBAR], ax
192
    test    eax, eax
192
    test    eax, eax
193
    jnz    .mixer_base_ok
193
    jnz    .mixer_base_ok
194
 
194
 
195
    print    "Error: Intel ICH based AC97 audio codec disabled in BIOS!"
195
    print    "Error: Intel ICH based AC97 audio codec disabled in BIOS!"
196
    jmp    exit
196
    jmp    exit
197
 
197
 
198
 .mixer_base_ok:
198
 .mixer_base_ok:
199
    dps    "NAMBAR: "
199
    dps    "NAMBAR: "
200
    dph    eax
200
    dph    eax
201
 
201
 
202
; Get NABMBAR & save it
202
; Get NABMBAR & save it
203
    mov    cl, NABMBAR_REG
203
    mov    cl, NABMBAR_REG
204
    call    pciRegRead16
204
    call    pciRegRead16
205
    and    eax, 0xFFC0
205
    and    eax, 0xFFC0
206
    mov    [NABMBAR], ax
206
    mov    [NABMBAR], ax
207
    test    eax, eax
207
    test    eax, eax
208
    jnz    .bm_base_ok
208
    jnz    .bm_base_ok
209
 
209
 
210
    print    "Error: Intel ICH based AC97 audio codec disabled in BIOS!"
210
    print    "Error: Intel ICH based AC97 audio codec disabled in BIOS!"
211
    jmp    exit
211
    jmp    exit
212
 
212
 
213
 .bm_base_ok:
213
 .bm_base_ok:
214
    dps    " NABMBAR: "
214
    dps    " NABMBAR: "
215
    dph    eax
215
    dph    eax
216
    newline
216
    newline
217
 
217
 
218
;---------------------------------------------------------------------
218
;---------------------------------------------------------------------
219
 
219
 
220
; Get IRQ (not used)
220
; Get IRQ (not used)
221
    mov    cl, IRQ_REG
221
    mov    cl, IRQ_REG
222
    call    pciRegRead8
222
    call    pciRegRead8
223
    mov    [AC97IRQ], al
223
    mov    [AC97IRQ], al
224
 
224
 
225
; Get Interrupt pin (not used)
225
; Get Interrupt pin (not used)
226
    mov    cl, INT_REG
226
    mov    cl, INT_REG
227
    call    pciRegRead8
227
    call    pciRegRead8
228
    mov    [AC97INT], al
228
    mov    [AC97INT], al
229
 
229
 
230
; AC97ICH4 should work then...
230
; AC97ICH4 should work then...
231
    cmp    [AC97ICH4], 1
231
    cmp    [AC97ICH4], 1
232
    jne    .skip_ich4_init
232
    jne    .skip_ich4_init
233
 
233
 
234
    mov    cl, ICH4_CFG_REG  ; 0x41
234
    mov    cl, ICH4_CFG_REG  ; 0x41
235
    call    pciRegRead8
235
    call    pciRegRead8
236
    or	  al, 0x1
236
    or	  al, 0x1
237
    mov    dl, al
237
    mov    dl, al
238
    call    pciRegWrite8
238
    call    pciRegWrite8
239
 
239
 
240
    mov    cl, 0x54
240
    mov    cl, 0x54
241
    call    pciRegRead16
241
    call    pciRegRead16
242
    and    eax, 0xFFFF
242
    and    eax, 0xFFFF
243
    dps    "Power Control & Status: "
243
    dps    "Power Control & Status: "
244
    dph    eax
244
    dph    eax
245
    newline
245
    newline
246
 .skip_ich4_init:
246
 .skip_ich4_init:
247
 
247
 
248
;---------------------------------------------------------------------
248
;---------------------------------------------------------------------
249
 
249
 
250
    mov    cl, PCI_CMD_REG
250
    mov    cl, PCI_CMD_REG
251
    call    pciRegRead16	   ; read PCI command register
251
    call    pciRegRead16	   ; read PCI command register
252
    mov    dx, ax
252
    mov    dx, ax
253
    or	  dx, IO_ENA+BM_ENA+BIT10    ; enable IO and bus master + disable
253
    or	  dx, IO_ENA+BM_ENA+BIT10    ; enable IO and bus master + disable
254
		       ;  interrupts
254
		       ;  interrupts
255
    call    pciRegWrite16
255
    call    pciRegWrite16
256
 
256
 
257
;---------------------------------------------------------------------
257
;---------------------------------------------------------------------
258
 
258
 
259
    print    "Enabling access to ports..."
259
    print    "Enabling access to ports..."
260
 
260
 
261
    movzx    ecx, [NAMBAR]
261
    movzx    ecx, [NAMBAR]
262
    mov    edx, ecx
262
    mov    edx, ecx
263
    add    edx, NAM_SIZE
263
    add    edx, NAM_SIZE
264
    mcall    MF_PORTS, PRT_RESERVE
264
    mcall    MF_PORTS, PRT_RESERVE
265
    test    eax, eax
265
    test    eax, eax
266
    jz	  @f
266
    jz	  @f
267
    print    "Error: couldn't enable access to ports"
267
    print    "Error: couldn't enable access to ports"
268
    jmp    exit
268
    jmp    exit
269
     @@:
269
     @@:
270
 
270
 
271
    movzx    ecx, [NABMBAR]
271
    movzx    ecx, [NABMBAR]
272
    mov    edx, ecx
272
    mov    edx, ecx
273
    add    edx, NABM_SIZE
273
    add    edx, NABM_SIZE
274
    mcall    MF_PORTS, PRT_RESERVE
274
    mcall    MF_PORTS, PRT_RESERVE
275
    test    eax, eax
275
    test    eax, eax
276
    jz	  @f
276
    jz	  @f
277
    print    "Error: couldn't enable access to ports"
277
    print    "Error: couldn't enable access to ports"
278
    jmp    exit
278
    jmp    exit
279
     @@:
279
     @@:
280
 
280
 
281
;---------------------------------------------------------------------
281
;---------------------------------------------------------------------
282
 
282
 
283
; setup the Codec
283
; setup the Codec
284
    mov    eax, 48000
284
    mov    eax, 48000
285
    call    codecConfig 	 ; unmute codec, set rates.
285
    call    codecConfig 	 ; unmute codec, set rates.
286
    test    eax, eax
286
    test    eax, eax
287
    jnz    @f
287
    jnz    @f
288
    print    "Error: cannot initialize AC97 device."
288
    print    "Error: cannot initialize AC97 device."
289
    jmp    fpexit
289
    jmp    fpexit
290
       @@:
290
       @@:
291
 
291
 
292
    print    "Congrutalations! Your device has been initialized properly!"
292
    print    "Congrutalations! Your device has been initialized properly!"
293
    call    print_info
293
    call    print_info
294
 
294
 
295
;---------------------------------------------------------------------
295
;---------------------------------------------------------------------
296
 
296
 
297
; register reset the DMA engine.
297
; register reset the DMA engine.
298
    mov    edx, PO_CR_REG    ; PCM out control register
298
    mov    edx, PO_CR_REG    ; PCM out control register
299
    mov    al, RR	 ; reset
299
    mov    al, RR	 ; reset
300
    call    NABMBAR_write_byte
300
    call    NABMBAR_write_byte
301
    
301
    
302
;start fix for MM (1)
302
;start fix for MM (1)
303
    mcall  MF_INTERNAL_SERVICES,ALLOC_PHYS_MEM,120*1024
303
    mcall  MF_INTERNAL_SERVICES,ALLOC_PHYS_MEM,120*1024
304
    test   eax,eax
304
    test   eax,eax
305
    jz     no_phys_buffers             ;not enough memory
305
    jz     no_phys_buffers             ;not enough memory
306
    mov    [phys_wav_buffer1],eax
306
    mov    [phys_wav_buffer1],eax
307
    add    eax,60*1024
307
    add    eax,60*1024
308
    mov    [phys_wav_buffer2],eax
308
    mov    [phys_wav_buffer2],eax
309
    mcall  MF_INTERNAL_SERVICES,ALLOC_PHYS_MEM,32*8
309
    mcall  MF_INTERNAL_SERVICES,ALLOC_PHYS_MEM,32*8
310
    test   eax,eax
310
    test   eax,eax
311
    jnz    @f
311
    jnz    @f
312
    mcall  MF_INTERNAL_SERVICES,FREE_PHYS_MEM,[phys_wav_buffer1]
312
    mcall  MF_INTERNAL_SERVICES,FREE_PHYS_MEM,[phys_wav_buffer1]
313
    jmp    no_phys_buffers
313
    jmp    no_phys_buffers
314
@@:
314
@@:
315
    mov    [phys_bdl_buffer],eax
315
    mov    [phys_bdl_buffer],eax
316
;end fix for MM (1)
316
;end fix for MM (1)
317
 
317
 
318
; create Buffer Descriptors List
318
; create Buffer Descriptors List
319
    call    prepare_BDL
319
    call    prepare_BDL
320
 
320
 
321
; open player's window
321
; open player's window
322
    mcall    MF_THREAD, THR_CREATE, thread, thread_stack
322
    mcall    MF_THREAD, THR_CREATE, thread, thread_stack
323
 
323
 
324
; wait for command
324
; wait for command
325
  .new_check:
325
  .new_check:
326
    cmp    [status], ST_PLAY
326
    cmp    [status], ST_PLAY
327
    jne    @f
327
    jne    @f
328
    call    play
328
    call    play
329
      @@:
329
      @@:
330
    cmp    [status], ST_STOP
330
    cmp    [status], ST_STOP
331
    jne    @f
331
    jne    @f
332
    call    stop
332
    call    stop
333
      @@:
333
      @@:
334
    cmp    [status], ST_EXIT
334
    cmp    [status], ST_EXIT
335
    je	  stopexit
335
    je	  stopexit
336
 
336
 
337
    mcall    MF_DELAY, 10
337
    mcall    MF_DELAY, 10
338
    jmp    .new_check
338
    jmp    .new_check
339
 
339
 
340
stopexit:
340
stopexit:
341
    call    stop
341
    call    stop
342
 
342
 
343
fpexit:
343
fpexit:
344
 
344
 
345
; free ports
345
; free ports
346
    movzx    ecx, [NAMBAR]
346
    movzx    ecx, [NAMBAR]
347
    mov    edx, ecx
347
    mov    edx, ecx
348
    add    edx, NAM_SIZE
348
    add    edx, NAM_SIZE
349
    mcall    MF_PORTS, PRT_FREE
349
    mcall    MF_PORTS, PRT_FREE
350
 
350
 
351
    movzx    ecx, [NABMBAR]
351
    movzx    ecx, [NABMBAR]
352
    mov    edx, ecx
352
    mov    edx, ecx
353
    add    edx, NABM_SIZE
353
    add    edx, NABM_SIZE
354
    mcall    MF_PORTS, PRT_FREE
354
    mcall    MF_PORTS, PRT_FREE
355
 
355
 
356
;---------------------------------------------------------------------
356
;---------------------------------------------------------------------
357
;start fix for MM (2)
357
;start fix for MM (2)
358
    mcall  MF_INTERNAL_SERVICES,FREE_PHYS_MEM,[phys_bdl_buffer]
358
    mcall  MF_INTERNAL_SERVICES,FREE_PHYS_MEM,[phys_bdl_buffer]
359
    mcall  MF_INTERNAL_SERVICES,FREE_PHYS_MEM,[phys_wav_buffer1]
359
    mcall  MF_INTERNAL_SERVICES,FREE_PHYS_MEM,[phys_wav_buffer1]
360
;end fix for MM (2)
360
;end fix for MM (2)
361
exit:
361
exit:
362
    mcall    MF_EXIT
362
    mcall    MF_EXIT
363
no_phys_buffers:
363
no_phys_buffers:
364
    print  "allocation of physical buffers failed"
364
    print  "allocation of physical buffers failed"
365
    jmp    exit
365
    jmp    exit
366
 
366
 
367
;---------------------------------------------------------------------
367
;---------------------------------------------------------------------
368
;---  FUNCTIONS  -----------------------------------------------------
368
;---  FUNCTIONS  -----------------------------------------------------
369
;---------------------------------------------------------------------
369
;---------------------------------------------------------------------
370
 
370
 
371
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
371
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
372
;; prepare_BDL - initializes BUFFER DESCRIPTORS LIST
372
;; prepare_BDL - initializes BUFFER DESCRIPTORS LIST
373
prepare_BDL:
373
prepare_BDL:
374
    mov    ecx, 32 / 2	  ; make 32 entries in BDL
374
    mov    ecx, 32 / 2	  ; make 32 entries in BDL
375
    mov    edi, BDL_BUFFER
375
    mov    edi, BDL_BUFFER
376
;    call   get_my_address
376
;    call   get_my_address
377
    mov    ebx, 30*1024
377
    mov    ebx, 30*1024
378
    cmp    [SI7012], 1
378
    cmp    [SI7012], 1
379
    jne    @f
379
    jne    @f
380
    add    ebx, ebx
380
    add    ebx, ebx
381
@@:
381
@@:
382
    ; set buf. desc. 0 to start of data file in memory
382
    ; set buf. desc. 0 to start of data file in memory
383
    push   eax
383
    push   eax
384
;    add    eax, WAV_BUFFER1
384
;    add    eax, WAV_BUFFER1
385
;start fix for MM (6)
385
;start fix for MM (6)
386
    mov    eax,[phys_wav_buffer1]
386
    mov    eax,[phys_wav_buffer1]
387
;end fix for MM (6)    
387
;end fix for MM (6)    
388
    stosd
388
    stosd
389
    ; set length to 60k samples. 1 sample is 16 bit or 2 bytes.
389
    ; set length to 60k samples. 1 sample is 16 bit or 2 bytes.
390
    mov    eax, ebx ;60*1024   ; number of samples
390
    mov    eax, ebx ;60*1024   ; number of samples
391
    or	   eax, BUP
391
    or	   eax, BUP
392
    stosd
392
    stosd
393
 
393
 
394
    mov    eax, [esp]
394
    mov    eax, [esp]
395
;    add    eax, WAV_BUFFER2
395
;    add    eax, WAV_BUFFER2
396
;start fix for MM (7)
396
;start fix for MM (7)
397
    mov    eax,[phys_wav_buffer2]
397
    mov    eax,[phys_wav_buffer2]
398
;end fix for MM (7)
398
;end fix for MM (7)
399
    stosd
399
    stosd
400
    mov    eax, ebx ;60*1024
400
    mov    eax, ebx ;60*1024
401
    or	   eax, BUP
401
    or	   eax, BUP
402
    stosd
402
    stosd
403
 
403
 
404
    pop    eax
404
    pop    eax
405
    loop   @b
405
    loop   @b
406
        
406
        
407
 
407
 
408
    ; tell the DMA engine where to find our list of Buffer Descriptors.
408
    ; tell the DMA engine where to find our list of Buffer Descriptors.
409
    ; eax = base addr!
409
    ; eax = base addr!
410
;start fix for MM (3)
410
;start fix for MM (3)
411
  ;copy to physical memory
411
  ;copy to physical memory
412
    mcall  MF_INTERNAL_SERVICES,SET_PHYS_BUFFER,[phys_bdl_buffer],BDL_BUFFER,32*8 
412
    mcall  MF_INTERNAL_SERVICES,SET_PHYS_BUFFER,[phys_bdl_buffer],BDL_BUFFER,32*8 
413
  ;physical address of bdl    
413
  ;physical address of bdl    
414
    mov    eax,[phys_bdl_buffer]                                
414
    mov    eax,[phys_bdl_buffer]                                
415
;end fix for MM (3)    
415
;end fix for MM (3)    
416
    mov    edx, PO_BDBAR_REG
416
    mov    edx, PO_BDBAR_REG
417
;    add    eax, BDL_BUFFER
417
;    add    eax, BDL_BUFFER
418
    call   NABMBAR_write_dword
418
    call   NABMBAR_write_dword
419
 
419
 
420
ret
420
ret
421
 
421
 
422
 
422
 
423
;---------------------------------------------------------------------
423
;---------------------------------------------------------------------
424
 
424
 
425
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
425
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
426
;; stop - stops current music
426
;; stop - stops current music
427
;; in:  nothing
427
;; in:  nothing
428
;; out: nothing
428
;; out: nothing
429
stop:
429
stop:
430
;        print   "STOP!"
430
;        print   "STOP!"
431
    push    eax edx
431
    push    eax edx
432
 
432
 
433
    mcall    MF_DELAY, 10
433
    mcall    MF_DELAY, 10
434
    mov    edx, PO_CR_REG
434
    mov    edx, PO_CR_REG
435
    mov    al, 0
435
    mov    al, 0
436
    call    NABMBAR_write_byte
436
    call    NABMBAR_write_byte
437
    cmp    [status], ST_STOP
437
    cmp    [status], ST_STOP
438
    jne    .exit
438
    jne    .exit
439
    mov    [status], ST_DONE
439
    mov    [status], ST_DONE
440
      .exit:
440
      .exit:
441
 
441
 
442
    pop    edx eax
442
    pop    edx eax
443
ret
443
ret
444
 
444
 
445
;---------------------------------------------------------------------
445
;---------------------------------------------------------------------
446
 
446
 
447
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
447
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
448
;; play - plays wav file!
448
;; play - plays wav file!
449
;; in:  nothing
449
;; in:  nothing
450
;; out: nothing (but sound :)   !corrupts registers!
450
;; out: nothing (but sound :)   !corrupts registers!
451
play:
451
play:
452
    ; at first, reset file
452
    ; at first, reset file and get file size
-
 
453
        mcall   MF_SYSTREE, attrinfo
-
 
454
        test    eax, eax
-
 
455
        jnz     .notfound
-
 
456
        mov     eax, [fileattr+32]
-
 
457
        mov     [file_size], eax
453
    mov    [fileinfo.first_block], 0
458
    mov    [fileinfo.first_byte], 0
454
    mcall    MF_SYSTREE, fileinfo ; load a block, returns error code in eax
459
    mcall    MF_SYSTREE, fileinfo ; load a block, returns error code in eax
455
		     ;   and size of the file in ebx
460
		     ;   and size of the file in ebx
456
    test    eax, eax	     ; 0 - successful
461
    test    eax, eax	     ; 0 - successful
457
    jz	  @f
462
    jz	  @f
-
 
463
        cmp     eax, 6          ; 6 = eof - successful too
-
 
464
        jz      @f
-
 
465
.notfound:
458
    print    "AC97: File not found!"
466
    print    "AC97: File not found!"
459
    mov    [status], ST_STOP
467
    mov    [status], ST_STOP
460
    jmp    .exit
468
    jmp    .exit
461
     @@:
469
     @@:
462
    shr    ebx, 9	      ; size_of_file / 512 = number_of_blocks
-
 
463
    mov    [file_size], ebx
-
 
464
 
-
 
465
 
470
 
466
    mov    al, [LOAD_BUFFER+32] ; bytes per sample
471
    mov    al, [LOAD_BUFFER+32] ; bytes per sample
467
    dec    al
472
    dec    al
468
    jz	  @f
473
    jz	  @f
469
    cmp    al, 3
474
    cmp    al, 3
470
    je	  @f
475
    je	  @f
471
    sub    al, [LOAD_BUFFER+22] ; channels
476
    sub    al, [LOAD_BUFFER+22] ; channels
472
    add    al, 2
477
    add    al, 2
473
      @@:
478
      @@:
474
    mov    [wav_mode], al
479
    mov    [wav_mode], al
475
 
480
 
476
    pusha
481
    pusha
477
    movzx    ebx,word [LOAD_BUFFER+24]
482
    movzx    ebx,word [LOAD_BUFFER+24]
478
    mov   eax,48000
483
    mov   eax,48000
479
    xor   edx,edx
484
    xor   edx,edx
480
    div   ebx
485
    div   ebx
481
    mov   [difference_of_frequency],al
486
    mov   [difference_of_frequency],al
482
;        dph   eax
487
;        dph   eax
483
    mov   ecx,edx
488
    mov   ecx,edx
484
    imul  eax,ecx,10
489
    imul  eax,ecx,10
485
    xor   edx,edx
490
    xor   edx,edx
486
    div   ebx
491
    div   ebx
487
    mov   ecx,edx
492
    mov   ecx,edx
488
    imul  ecx,10
493
    imul  ecx,10
489
    push  eax
494
    push  eax
490
    mov   eax,ecx
495
    mov   eax,ecx
491
    xor   edx,edx
496
    xor   edx,edx
492
    div   ebx
497
    div   ebx
493
;        dph   eax
498
;        dph   eax
494
    cmp   eax,5
499
    cmp   eax,5
495
    jl	  .temp_15
500
    jl	  .temp_15
496
    pop   eax
501
    pop   eax
497
;        dph   eax
502
;        dph   eax
498
 
503
 
499
    inc   eax
504
    inc   eax
500
    jmp   .temp_16
505
    jmp   .temp_16
501
     .temp_15:
506
     .temp_15:
502
    pop   eax
507
    pop   eax
503
     .temp_16:
508
     .temp_16:
504
    mov   [difference_of_frequency_1],al
509
    mov   [difference_of_frequency_1],al
505
;        dph   eax
510
;        dph   eax
506
    xor   edx,edx
511
    xor   edx,edx
507
    movzx  ebx,[difference_of_frequency]
512
    movzx  ebx,[difference_of_frequency]
508
    imul   ebx,10
513
    imul   ebx,10
509
    add    bl,[difference_of_frequency_1]
514
    add    bl,[difference_of_frequency_1]
510
    mov   [difference_of_frequency_2],bl
515
    mov   [difference_of_frequency_2],bl
511
;        dph   ebx
516
;        dph   ebx
512
    popa
517
    popa
513
 
518
 
514
    movzx    eax, word [LOAD_BUFFER+24]
519
    movzx    eax, word [LOAD_BUFFER+24]
515
    ;dps "Freq: "
520
    ;dps "Freq: "
516
    ;dpd eax
521
    ;dpd eax
517
    ;newline
522
    ;newline
518
    call    set_sample_rate
523
    call    set_sample_rate
519
 
524
 
520
 
525
 
521
    ; change the last_valid_index to the (current_index-1)
526
    ; change the last_valid_index to the (current_index-1)
522
    ; the LVI register tells the DMA engine where to stop playing
527
    ; the LVI register tells the DMA engine where to stop playing
523
    call    updateLVI
528
    call    updateLVI
524
 
529
 
525
    ; if current index is odd, load buffer 1 then 0, jump to tuneLoop
530
    ; if current index is odd, load buffer 1 then 0, jump to tuneLoop
526
    ; if it is even, buffers 0 then 1; tuneLoop1
531
    ; if it is even, buffers 0 then 1; tuneLoop1
527
    call    getCurrentIndex
532
    call    getCurrentIndex
528
    and    eax, BIT0
533
    and    eax, BIT0
529
 
534
 
530
    mov    esi, eax
535
    mov    esi, eax
531
    push    eax
536
    push    eax
532
    call    update_next_buffer
537
    call    update_next_buffer
533
    pop    eax
538
    pop    eax
534
    xor    eax, 1
539
    xor    eax, 1
535
    call    update_next_buffer
540
    call    update_next_buffer
536
 
541
 
537
    ; start playing!
542
    ; start playing!
538
    mov    edx, PO_CR_REG
543
    mov    edx, PO_CR_REG
539
    mov    al, RPBM
544
    mov    al, RPBM
540
    call    NABMBAR_write_byte
545
    call    NABMBAR_write_byte
541
 
546
 
542
    jmp    [jumpto+esi*4]
547
    jmp    [jumpto+esi*4]
543
 
548
 
544
 
549
 
545
   .tuneLoop:
550
   .tuneLoop:
546
    ; wait while the current_index is even
551
    ; wait while the current_index is even
547
    @@:
552
    @@:
548
;        dps     "a"
553
;        dps     "a"
549
    mcall    MF_DELAY, 7
554
    mcall    MF_DELAY, 7
550
    call    getCurrentIndex
555
    call    getCurrentIndex
551
    test    al, BIT0
556
    test    al, BIT0
552
    jz	  @b	   ; loop if not ready yet
557
    jz	  @b	   ; loop if not ready yet
553
;        print   "fa"
558
;        print   "fa"
554
 
559
 
555
    call    updateLVI
560
    call    updateLVI
556
 
561
 
557
    mov    eax, 0
562
    mov    eax, 0
558
    call    update_next_buffer
563
    call    update_next_buffer
559
    test    al, al
564
    test    al, al
560
    jnz    .exit_wait
565
    jnz    .exit_wait
561
 
566
 
562
    cmp    [status], ST_PLAY
567
    cmp    [status], ST_PLAY
563
    jne    .exit
568
    jne    .exit
564
 
569
 
565
    test    [volume], 0x10000000 ; test volume_changed bit
570
    test    [volume], 0x10000000 ; test volume_changed bit
566
    je	  @f
571
    je	  @f
567
    mov    al, byte [volume]
572
    mov    al, byte [volume]
568
    call    setVolume
573
    call    setVolume
569
    and    [volume], 0x0FFFFFFF ; clear vloume_changed bit
574
    and    [volume], 0x0FFFFFFF ; clear vloume_changed bit
570
     @@:
575
     @@:
571
 
576
 
572
     .tuneLoop1:
577
     .tuneLoop1:
573
     @@:
578
     @@:
574
;        dps     "b"
579
;        dps     "b"
575
    mcall    MF_DELAY, 7
580
    mcall    MF_DELAY, 7
576
    call    getCurrentIndex
581
    call    getCurrentIndex
577
    test    al, BIT0
582
    test    al, BIT0
578
    jnz    @b	    ; loop if not ready yet
583
    jnz    @b	    ; loop if not ready yet
579
;        print   "fb"
584
;        print   "fb"
580
 
585
 
581
    cmp    [status], ST_PLAY
586
    cmp    [status], ST_PLAY
582
    jne    .exit
587
    jne    .exit
583
 
588
 
584
    call    updateLVI
589
    call    updateLVI
585
 
590
 
586
    mov    eax, 1
591
    mov    eax, 1
587
    call    update_next_buffer
592
    call    update_next_buffer
588
    test    al, al
593
    test    al, al
589
    jnz    .exit_wait
594
    jnz    .exit_wait
590
 
595
 
591
    jmp    .tuneLoop
596
    jmp    .tuneLoop
592
   .exit_wait:
597
   .exit_wait:
593
    mcall    MF_DELAY, 30 ; a little pause - let the player finish
598
    mcall    MF_DELAY, 30 ; a little pause - let the player finish
594
   .exit:
599
   .exit:
595
ret
600
ret
596
attempts db 0
601
attempts db 0
597
 
602
 
598
buffers dd WAV_BUFFER1, WAV_BUFFER2
603
buffers dd WAV_BUFFER1, WAV_BUFFER2
599
jumpto	  dd play.tuneLoop, play.tuneLoop1
604
jumpto	  dd play.tuneLoop, play.tuneLoop1
600
 
605
 
601
 
606
 
602
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
607
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
603
;; update_first_buffer - load a chunk into the first buffer, increments offset
608
;; update_first_buffer - load a chunk into the first buffer, increments offset
604
;; in:  eax = number - 0 or 1
609
;; in:  eax = number - 0 or 1
605
;; out: error code, 0 - successful
610
;; out: error code, 0 - successful
606
update_next_buffer:
611
update_next_buffer:
607
    push   esi edi
612
    push   esi edi
608
 
613
 
609
    movzx  edx, byte [wav_mode]
614
    movzx  edx, byte [wav_mode]
610
    mov    ecx, [blocks + edx * 4]
615
    mov    ecx, [blocks + edx * 4]
611
    mov    [fileinfo.blocks], ecx
616
    mov    [fileinfo.bytes], ecx
612
 
617
 
613
    mov    esi, LOAD_BUFFER
618
    mov    esi, LOAD_BUFFER
614
    mov    edi, [buffers+eax*4]
619
    mov    edi, [buffers+eax*4]
615
    push   eax              ;save buffer index
620
    push   eax              ;save buffer index
616
  start_attempts:
621
  start_attempts:
617
    mcall  MF_SYSTREE, fileinfo
622
    mcall  MF_SYSTREE, fileinfo
618
    test eax, eax
623
    test eax, eax
619
    jz @f
624
    jz @f
-
 
625
        cmp     eax, 6
-
 
626
        jz      @f
620
    cmp   [attempts],100
627
    cmp   [attempts],100
621
    je	 @f
628
    je	 @f
622
    inc   [attempts]
629
    inc   [attempts]
623
    jmp   start_attempts
630
    jmp   start_attempts
624
    dpd eax
631
;    dpd eax
625
    newline
632
;    newline
626
    dpd [fileinfo.first_block]
633
;    dpd [fileinfo.first_block]
627
    newline
634
;    newline
628
       @@:
635
       @@:
629
;        print  " loaded!"
636
;        print  " loaded!"
630
 
637
 
631
    push   eax ebx edx
638
    push   eax ebx edx
632
    mov    eax,ecx
639
    mov    eax,ecx
633
    xor    edx,edx
640
    xor    edx,edx
634
    imul   eax,10
641
    imul   eax,10
635
    movzx     ebx,[difference_of_frequency_2]
642
    movzx     ebx,[difference_of_frequency_2]
636
 
643
 
637
    div    ebx
644
    div    ebx
638
    mov    ecx,eax
645
    mov    ecx,eax
639
 
646
 
640
;    mov   ebx,10
647
;    mov   ebx,10
641
;    mov   eax,edx
648
;    mov   eax,edx
642
;    xor   edx,edx
649
;    xor   edx,edx
643
;    div   ebx
650
;    div   ebx
644
;   cmp   edx,5
651
;   cmp   edx,5
645
;    jb   temp_12_7
652
;    jb   temp_12_7
646
;    inc   ecx
653
;    inc   ecx
647
;  temp_12_7:
654
;  temp_12_7:
648
   cmp	 edx,0
655
   cmp	 edx,0
649
    je	 temp_12_7
656
    je	 temp_12_7
650
    inc   ecx
657
    inc   ecx
651
  temp_12_7:
658
  temp_12_7:
652
 
659
 
653
    pop    edx ebx 
660
    pop    edx ebx 
654
    mov    eax,[esp+4]            ;restore buffer index
661
    mov    eax,[esp+4]            ;restore buffer index
655
    add    [fileinfo.first_block], ecx ; +60Kb
662
    add    [fileinfo.first_byte], ecx ; +60Kb
656
    call   [convert + edx * 4]
663
    call   [convert + edx * 4]
657
;start fix for MM (4)    
664
;start fix for MM (4)    
658
    mov    eax,[esp+4]            ;restore buffer index
665
    mov    eax,[esp+4]            ;restore buffer index
659
    test   eax,not 1
666
    test   eax,not 1
660
    jz     .ok
667
    jz     .ok
661
    print  "buffer index out of range"
668
    print  "buffer index out of range"
662
    dpd    eax
669
    dpd    eax
663
    jmp    .ret
670
    jmp    .ret
664
  .ok:
671
  .ok:
665
    push   ebp
672
    push   ebp
666
    mov    ebp,[phys_wav_buffer1+eax*4]
673
    mov    ebp,[phys_wav_buffer1+eax*4]
667
    mov    edi,[buffers+eax*4]
674
    mov    edi,[buffers+eax*4]
668
    mcall  MF_INTERNAL_SERVICES,SET_PHYS_BUFFER,ebp,edi,60*1024
675
    mcall  MF_INTERNAL_SERVICES,SET_PHYS_BUFFER,ebp,edi,60*1024
669
    pop    ebp
676
    pop    ebp
670
.ret:
677
.ret:
671
    pop    eax
678
    pop    eax
672
    add    esp,4                  ;pop buffer index    
679
    add    esp,4                  ;pop buffer index    
673
;end fix for MM (4)    
680
;end fix for MM (4)    
674
 
681
 
675
    pop    edi esi
682
    pop    edi esi
676
ret
683
ret
677
 
684
 
678
c8mono:
685
c8mono:
679
    mov   [type_of_conversion],1
686
    mov   [type_of_conversion],1
680
    jmp   for_all_type
687
    jmp   for_all_type
681
 
688
 
682
c8mono_1:
689
c8mono_1:
683
    lodsb
690
    lodsb
684
    call  c8mono_2
691
    call  c8mono_2
685
    push  ax
692
    push  ax
686
    shl   eax,16
693
    shl   eax,16
687
    pop   ax
694
    pop   ax
688
    push  eax
695
    push  eax
689
    mov al,[esi]
696
    mov al,[esi]
690
    call  c8mono_2
697
    call  c8mono_2
691
    push  ax
698
    push  ax
692
    shl   eax,16
699
    shl   eax,16
693
    pop   ax
700
    pop   ax
694
    mov  ebx,eax
701
    mov  ebx,eax
695
    pop  eax
702
    pop  eax
696
    jmp  for_all_type_1
703
    jmp  for_all_type_1
697
 
704
 
698
c8mono_2:
705
c8mono_2:
699
    sub    al, 0x80
706
    sub    al, 0x80
700
    cbw
707
    cbw
701
    imul   ax, 255
708
    imul   ax, 255
702
    ret
709
    ret
703
 
710
 
704
c8stereo:
711
c8stereo:
705
    mov   [type_of_conversion],2
712
    mov   [type_of_conversion],2
706
    jmp   for_all_type
713
    jmp   for_all_type
707
 
714
 
708
c8stereo_1:
715
c8stereo_1:
709
    lodsb
716
    lodsb
710
    call  c8stereo_2
717
    call  c8stereo_2
711
    shl eax,16
718
    shl eax,16
712
    lodsb
719
    lodsb
713
    call  c8stereo_2
720
    call  c8stereo_2
714
    push  eax
721
    push  eax
715
    mov al,[esi]
722
    mov al,[esi]
716
    call  c8stereo_2
723
    call  c8stereo_2
717
    shl eax,16
724
    shl eax,16
718
    mov al,[esi+1]
725
    mov al,[esi+1]
719
    call  c8stereo_2
726
    call  c8stereo_2
720
    mov   ebx,eax
727
    mov   ebx,eax
721
    pop  eax
728
    pop  eax
722
    jmp   for_all_type_1
729
    jmp   for_all_type_1
723
 
730
 
724
c8stereo_2:
731
c8stereo_2:
725
    sub    al, 0x80
732
    sub    al, 0x80
726
    cbw
733
    cbw
727
    imul   ax, 255
734
    imul   ax, 255
728
    ret
735
    ret
729
 
736
 
730
c16mono:
737
c16mono:
731
    mov   [type_of_conversion],3
738
    mov   [type_of_conversion],3
732
    jmp   for_all_type
739
    jmp   for_all_type
733
 
740
 
734
c16mono_1:
741
c16mono_1:
735
	lodsw
742
	lodsw
736
	push  ax
743
	push  ax
737
	shl eax,16
744
	shl eax,16
738
	pop   ax
745
	pop   ax
739
	mov bx,[esi]
746
	mov bx,[esi]
740
	shl ebx,16
747
	shl ebx,16
741
	mov bx,[esi]
748
	mov bx,[esi]
742
	jmp  for_all_type_1
749
	jmp  for_all_type_1
743
 
750
 
744
c16stereo:
751
c16stereo:
745
 for_all_type:
752
 for_all_type:
746
    xor   edx,edx
753
    xor   edx,edx
747
    mov    eax, 15*1024*10
754
    mov    eax, 15*1024*10
748
    movzx     ebx,[difference_of_frequency_2]
755
    movzx     ebx,[difference_of_frequency_2]
749
    xor    edx,edx
756
    xor    edx,edx
750
    div    ebx
757
    div    ebx
751
    mov    ecx,eax
758
    mov    ecx,eax
752
 
759
 
753
;    mov   ebx,10
760
;    mov   ebx,10
754
;    mov   eax,edx
761
;    mov   eax,edx
755
;    xor   edx,edx
762
;    xor   edx,edx
756
;    div   ebx
763
;    div   ebx
757
;    cmp   edx,5
764
;    cmp   edx,5
758
;    jb   temp_12_6
765
;    jb   temp_12_6
759
;    inc   ecx
766
;    inc   ecx
760
;  temp_12_6:
767
;  temp_12_6:
761
   cmp	 edx,0
768
   cmp	 edx,0
762
    je	 temp_12_6
769
    je	 temp_12_6
763
    inc   ecx
770
    inc   ecx
764
  temp_12_6:
771
  temp_12_6:
765
 
772
 
766
  c16stereo_1:
773
  c16stereo_1:
767
    mov  [znak],0
774
    mov  [znak],0
768
 
775
 
769
    cmp  [type_of_conversion],1
776
    cmp  [type_of_conversion],1
770
    je	 c8mono_1
777
    je	 c8mono_1
771
    cmp  [type_of_conversion],2
778
    cmp  [type_of_conversion],2
772
    je	 c8stereo_1
779
    je	 c8stereo_1
773
    cmp  [type_of_conversion],3
780
    cmp  [type_of_conversion],3
774
    je	 c16mono_1
781
    je	 c16mono_1
775
    lodsd
782
    lodsd
776
 
783
 
777
    mov ebx,[esi]
784
    mov ebx,[esi]
778
for_all_type_1:
785
for_all_type_1:
779
    cmp eax,ebx
786
    cmp eax,ebx
780
    jne  c16stereo_2
787
    jne  c16stereo_2
781
    inc  [znak]
788
    inc  [znak]
782
    c16stereo_2:
789
    c16stereo_2:
783
    push eax
790
    push eax
784
    push ecx
791
    push ecx
785
    sub  eax,ebx
792
    sub  eax,ebx
786
    push eax
793
    push eax
787
    shl  eax,16
794
    shl  eax,16
788
    movzx  ebx,[difference_of_frequency]
795
    movzx  ebx,[difference_of_frequency]
789
    inc   ebx
796
    inc   ebx
790
    xor  edx,edx
797
    xor  edx,edx
791
    div  ebx
798
    div  ebx
792
    shr  eax,16
799
    shr  eax,16
793
    mov  ecx,eax
800
    mov  ecx,eax
794
    pop  eax
801
    pop  eax
795
    xor  ax,ax
802
    xor  ax,ax
796
    xor  edx,edx
803
    xor  edx,edx
797
    div  ebx
804
    div  ebx
798
    shl  eax,16
805
    shl  eax,16
799
    mov  cx,ax
806
    mov  cx,ax
800
    mov  ebx,ecx
807
    mov  ebx,ecx
801
    pop  ecx
808
    pop  ecx
802
    pop   eax
809
    pop   eax
803
    mov    dl,[difference_of_frequency]
810
    mov    dl,[difference_of_frequency]
804
    inc   dl
811
    inc   dl
805
    @@:
812
    @@:
806
temp_12:
813
temp_12:
807
    cmp   [difference_of_frequency_1],0
814
    cmp   [difference_of_frequency_1],0
808
    je	  temp_12_3
815
    je	  temp_12_3
809
    cmp   [difference_of_frequency_1],5
816
    cmp   [difference_of_frequency_1],5
810
    jne   temp_12_4
817
    jne   temp_12_4
811
    cmp  [difference_of_frequency_4],2
818
    cmp  [difference_of_frequency_4],2
812
    jne  temp_12_3
819
    jne  temp_12_3
813
    jmp  temp_12_5
820
    jmp  temp_12_5
814
 temp_12_4:
821
 temp_12_4:
815
    cmp  [difference_of_frequency_4],10
822
    cmp  [difference_of_frequency_4],10
816
    jne  temp_12_3
823
    jne  temp_12_3
817
 
824
 
818
 temp_12_5:
825
 temp_12_5:
819
 
826
 
820
    cmp  [znak],0
827
    cmp  [znak],0
821
    jne   temp_12_5_1
828
    jne   temp_12_5_1
822
    sub  eax,ebx
829
    sub  eax,ebx
823
    jmp  temp_12_5_2
830
    jmp  temp_12_5_2
824
 temp_12_5_1:
831
 temp_12_5_1:
825
    add  eax,ebx
832
    add  eax,ebx
826
 temp_12_5_2:
833
 temp_12_5_2:
827
 
834
 
828
 
835
 
829
    stosd
836
    stosd
830
    inc  [schetchik]
837
    inc  [schetchik]
831
    mov    [difference_of_frequency_4],0
838
    mov    [difference_of_frequency_4],0
832
 temp_12_3:
839
 temp_12_3:
833
    cmp  [znak],0
840
    cmp  [znak],0
834
    jne   temp_13
841
    jne   temp_13
835
    sub  eax,ebx
842
    sub  eax,ebx
836
    jmp  temp_14
843
    jmp  temp_14
837
 temp_13:
844
 temp_13:
838
    add  eax,ebx
845
    add  eax,ebx
839
 
846
 
840
 temp_14:
847
 temp_14:
841
    cld
848
    cld
842
    dec    dl
849
    dec    dl
843
    jz	  temp_14_1
850
    jz	  temp_14_1
844
    stosd
851
    stosd
845
    inc   [schetchik]
852
    inc   [schetchik]
846
    inc   [difference_of_frequency_4]
853
    inc   [difference_of_frequency_4]
847
    jmp   temp_12
854
    jmp   temp_12
848
 temp_14_1:
855
 temp_14_1:
849
    dec    ecx
856
    dec    ecx
850
    cmp   ecx,0
857
    cmp   ecx,0
851
;    jnz    c16stereo_1
858
;    jnz    c16stereo_1
852
    jg	  c16stereo_1
859
    jg	  c16stereo_1
853
    newline
860
    newline
854
    dph [schetchik]
861
    dph [schetchik]
855
 temp_14_2:
862
 temp_14_2:
856
    cmp   [schetchik],15360
863
    cmp   [schetchik],15360
857
    jge   temp_14_3
864
    jge   temp_14_3
858
    stosd
865
    stosd
859
    inc  [schetchik]
866
    inc  [schetchik]
860
    jmp  temp_14_2
867
    jmp  temp_14_2
861
 
868
 
862
  temp_14_3:
869
  temp_14_3:
863
    newline
870
    newline
864
    dph [schetchik]
871
    dph [schetchik]
865
    cmp   [schetchik],15360
872
    cmp   [schetchik],15360
866
    je	  temp_14_4
873
    je	  temp_14_4
867
;    mov  [edi-4],dword 0
874
;    mov  [edi-4],dword 0
868
    sub   edi,4
875
    sub   edi,4
869
;    sub   esi,4
876
;    sub   esi,4
870
 temp_14_4:
877
 temp_14_4:
871
    mov   [schetchik],0
878
    mov   [schetchik],0
872
    ret
879
    ret
873
 
880
 
874
 
881
 
875
difference_of_frequency db 0
882
difference_of_frequency db 0
876
difference_of_frequency_1 db 0
883
difference_of_frequency_1 db 0
877
difference_of_frequency_2 db 0
884
difference_of_frequency_2 db 0
878
difference_of_frequency_4 db 0
885
difference_of_frequency_4 db 0
879
schetchik dd 0
886
schetchik dd 0
880
znak db 0
887
znak db 0
881
type_of_conversion db 0
888
type_of_conversion db 0
882
 
889
 
883
convert dd c8mono, c8stereo, c16mono, c16stereo
890
convert dd c8mono, c8stereo, c16mono, c16stereo
884
blocks	  dd 30, 60, 60, 120
891
blocks	  dd 30*512, 60*512, 60*512, 120*512
885
 
892
 
886
 
893
 
887
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
894
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
888
;; get_my_address - get base address of the program in physical memory
895
;; get_my_address - get base address of the program in physical memory
889
;;   in:  nothing
896
;;   in:  nothing
890
;;   out: eax = address
897
;;   out: eax = address
891
;start fix for MM (8)
898
;start fix for MM (8)
892
;function shouldn't used.
899
;function shouldn't used.
893
;get_my_address:
900
;get_my_address:
894
;    pushad
901
;    pushad
895
;    mcall    MF_PROCINFO, procinfo, PN_MYSELF
902
;    mcall    MF_PROCINFO, procinfo, PN_MYSELF
896
;    popad
903
;    popad
897
;    mov    eax, [procinfo.memory_start]
904
;    mov    eax, [procinfo.memory_start]
898
;ret
905
;ret
899
;end fix for MM (8)
906
;end fix for MM (8)
900
 
907
 
901
 
908
 
902
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
909
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
903
;; set the last valid index to something other than we're currently playing
910
;; set the last valid index to something other than we're currently playing
904
;; so that we never end
911
;; so that we never end
905
;;
912
;;
906
;; this routine just sets the last valid index to 1 less than the index
913
;; this routine just sets the last valid index to 1 less than the index
907
;; that we're currently playing, thus keeping it in and endless loop
914
;; that we're currently playing, thus keeping it in and endless loop
908
;; input:  none
915
;; input:  none
909
;; output: none
916
;; output: none
910
updateLVI:
917
updateLVI:
911
    push    eax
918
    push    eax
912
    call    getCurrentIndex
919
    call    getCurrentIndex
913
     ; dps "index "
920
     ; dps "index "
914
     ; dpd eax
921
     ; dpd eax
915
     ; newline
922
     ; newline
916
    dec    al
923
    dec    al
917
    and    al, INDEX_MASK
924
    and    al, INDEX_MASK
918
    call    setLastValidIndex
925
    call    setLastValidIndex
919
    pop    eax
926
    pop    eax
920
ret
927
ret
921
 
928
 
922
;---------------------------------------------------------------------
929
;---------------------------------------------------------------------
923
 
930
 
924
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
931
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
925
;; returns AL = current index value
932
;; returns AL = current index value
926
getCurrentIndex:
933
getCurrentIndex:
927
    push    edx
934
    push    edx
928
    mov    edx, PO_CIV_REG
935
    mov    edx, PO_CIV_REG
929
    call    NABMBAR_read_byte
936
    call    NABMBAR_read_byte
930
    pop    edx
937
    pop    edx
931
ret
938
ret
932
 
939
 
933
;---------------------------------------------------------------------
940
;---------------------------------------------------------------------
934
 
941
 
935
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
942
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
936
;; input AL = index # to stop on
943
;; input AL = index # to stop on
937
setLastValidIndex:
944
setLastValidIndex:
938
    push    edx
945
    push    edx
939
    mov    edx, PO_LVI_REG
946
    mov    edx, PO_LVI_REG
940
    call    NABMBAR_write_byte
947
    call    NABMBAR_write_byte
941
    pop    edx
948
    pop    edx
942
ret
949
ret
943
 
950
 
944
;---------------------------------------------------------------------
951
;---------------------------------------------------------------------
945
 
952
 
946
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
953
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
947
;; print_info - outputs debug information
954
;; print_info - outputs debug information
948
;;  in:  nothing
955
;;  in:  nothing
949
;;  out: nothing
956
;;  out: nothing
950
print_info:
957
print_info:
951
    dps    "BUS: "
958
    dps    "BUS: "
952
    movzx    eax, [bus]
959
    movzx    eax, [bus]
953
    dph    eax
960
    dph    eax
954
 
961
 
955
    dps    " DEVFN: "
962
    dps    " DEVFN: "
956
    movzx    eax, [devfn]
963
    movzx    eax, [devfn]
957
    dph    eax
964
    dph    eax
958
 
965
 
959
    dps    " IRQ: "
966
    dps    " IRQ: "
960
    movzx    eax, [AC97IRQ]
967
    movzx    eax, [AC97IRQ]
961
    dpd    eax
968
    dpd    eax
962
    newline
969
    newline
963
 
970
 
964
 
971
 
965
    dps    "CODEC_POWER_CTRL: "
972
    dps    "CODEC_POWER_CTRL: "
966
    mov    edx, CODEC_POWER_CTRL_REG
973
    mov    edx, CODEC_POWER_CTRL_REG
967
    call    NAMBAR_read_word
974
    call    NAMBAR_read_word
968
    dph    eax
975
    dph    eax
969
    dps    " (bits 0-3 should be set)"
976
    dps    " (bits 0-3 should be set)"
970
    newline
977
    newline
971
 
978
 
972
    mov    edx, 0x28
979
    mov    edx, 0x28
973
    call    NAMBAR_read_word
980
    call    NAMBAR_read_word
974
    dph    eax
981
    dph    eax
975
    dps    " - supported features"
982
    dps    " - supported features"
976
    newline
983
    newline
977
    mov    edx, 0x2A
984
    mov    edx, 0x2A
978
    call    NAMBAR_read_word
985
    call    NAMBAR_read_word
979
    dph    eax
986
    dph    eax
980
    dps    " - config"
987
    dps    " - config"
981
    newline
988
    newline
982
    mov    edx, 0x2C
989
    mov    edx, 0x2C
983
    call    NAMBAR_read_word
990
    call    NAMBAR_read_word
984
    dph    eax
991
    dph    eax
985
    dps    " - PCM rate"
992
    dps    " - PCM rate"
986
 
993
 
987
    newline
994
    newline
988
ret
995
ret
989
 
996
 
990
 
997
 
991
;---------------------------------------------------------------------
998
;---------------------------------------------------------------------
992
;---  DATA OF PROGRAM  -----------------------------------------------
999
;---  DATA OF PROGRAM  -----------------------------------------------
993
;---------------------------------------------------------------------
1000
;---------------------------------------------------------------------
994
volume		 dd  15
1001
volume		 dd  15
-
 
1002
 
-
 
1003
attrinfo:
-
 
1004
        dd      5
-
 
1005
        dd      0
-
 
1006
        dd      0
-
 
1007
        dd      0
-
 
1008
        dd      fileattr
-
 
1009
        db      0
-
 
1010
        dd      textbox_string
995
 
1011
 
996
fileinfo:
1012
fileinfo:
997
 .mode		 dd  0		 ; READ
1013
 .mode          dd      0		 ; READ
-
 
1014
 .first_byte    dd      0
998
 .first_block  dd  0
1015
                dd      0
999
 .blocks       dd  120		 ; 120 Kb
1016
 .bytes         dd      60*1024		 ; 60 Kb
1000
 .dest		 dd  LOAD_BUFFER ;file_data
-
 
1001
 .work		 dd  work_area
1017
 .dest		 dd  LOAD_BUFFER ;file_data
1002
	 ;  db  "/HD/1/WINDOWS/MEDIA/WICEB7~1.WAV",0
1018
	 ;  db  "/HD/1/WINDOWS/MEDIA/WICEB7~1.WAV",0
1003
;sz textbox_string, "/hd/1/testmuz/menuet11.wav",0
-
 
1004
sz textbox_string, "                                                        ",0
1019
;sz textbox_string, "/hd/1/testmuz/menuet11.wav",0
1005
;   rb 256
1020
textbox_string:
1006
;---------------------------------------------------------------------
1021
;---------------------------------------------------------------------
1007
 
1022
 
1008
IMAGE_END:		 ; end of program's image
1023
IMAGE_END:		 ; end of program's image
-
 
1024
   rb 257
1009
   rb 100-textbox_string.size
1025
;   rb 257-textbox_string.size
1010
;     textbox_string.size
1026
;     textbox_string.size
1011
 
1027
 
1012
;---------------------------------------------------------------------
1028
;---------------------------------------------------------------------
1013
 
1029
 
1014
device_id dd ?	  ; (device_id << 16) + vendor_id
1030
device_id dd ?	  ; (device_id << 16) + vendor_id
1015
lastbus   db ?	  ; pci coordinates
1031
lastbus   db ?	  ; pci coordinates
1016
bus	 db ?
1032
bus	 db ?
1017
devfn	   db ?
1033
devfn	   db ?
1018
 
1034
 
1019
AC97ICH4  db ?	  ; Intel ICH4 codec flag
1035
AC97ICH4  db ?	  ; Intel ICH4 codec flag
1020
SI7012	    db ?    ; SiS SI7012 codec flag
1036
SI7012	    db ?    ; SiS SI7012 codec flag
1021
NAMBAR	    dw ?    ; Audio Mixers Registers (base)
1037
NAMBAR	    dw ?    ; Audio Mixers Registers (base)
1022
NABMBAR   dw ?	  ; Bus Master Registers   (base)
1038
NABMBAR   dw ?	  ; Bus Master Registers   (base)
1023
 
1039
 
1024
AC97IRQ   db ?	  ; Interrupt request
1040
AC97IRQ   db ?	  ; Interrupt request
1025
AC97INT   db ?	  ; Interrupt pin
1041
AC97INT   db ?	  ; Interrupt pin
1026
 
1042
 
1027
wav_mode  db ?	  ; bits per sample & channels
1043
wav_mode  db ?	  ; bits per sample & channels
1028
 
1044
 
1029
;---------------------------------------------------------------------
1045
;---------------------------------------------------------------------
1030
 
1046
 
1031
ST_DONE = 0x0	 ; for interacting with player's window
1047
ST_DONE = 0x0	 ; for interacting with player's window
1032
ST_PLAY = 0x1
1048
ST_PLAY = 0x1
1033
ST_EXIT = 0x2
1049
ST_EXIT = 0x2
1034
ST_STOP = 0x4
1050
ST_STOP = 0x4
1035
 
1051
 
1036
status	    db ?
1052
status	    db ?
-
 
1053
 
-
 
1054
fileattr: rb 40
1037
 
1055
 
1038
;---------------------------------------------------------------------
1056
;---------------------------------------------------------------------
1039
phys_bdl_buffer rd 1
1057
phys_bdl_buffer rd 1
1040
phys_wav_buffer1 rd 1
1058
phys_wav_buffer1 rd 1
1041
phys_wav_buffer2 rd 1
1059
phys_wav_buffer2 rd 1
1042
align 32
1060
align 32
1043
 
1061
 
1044
 
1062
 
1045
; Buffer Descriptors List
1063
; Buffer Descriptors List
1046
;  ___________________________
1064
;  ___________________________
1047
;  |     physical address    | dword
1065
;  |     physical address    | dword
1048
;  |_________________________|
1066
;  |_________________________|
1049
;  | attr       |   length   | dword     max. length = 65535 samples
1067
;  | attr       |   length   | dword     max. length = 65535 samples
1050
;  |_________________________|
1068
;  |_________________________|
1051
 
1069
 
1052
BDL_BUFFER:
1070
BDL_BUFFER:
1053
 rb 32*8     ; 32 descriptors, 8 bytes each
1071
 rb 32*8     ; 32 descriptors, 8 bytes each
1054
 
1072
 
1055
 
1073
 
1056
;---------------------------------------------------------------------
1074
;---------------------------------------------------------------------
1057
 
1075
 
1058
file_data:
1076
file_data:
1059
 
1077
 
1060
WAV_BUFFER1:
1078
WAV_BUFFER1:
1061
 rb 60 * 1024  ; 60 Kb
1079
 rb 60 * 1024  ; 60 Kb
1062
 
1080
 
1063
WAV_BUFFER2:
1081
WAV_BUFFER2:
1064
 rb 60 * 1024
1082
 rb 60 * 1024
1065
 
1083
 
1066
LOAD_BUFFER:
1084
LOAD_BUFFER:
1067
 rb 60 * 1024
1085
 rb 60 * 1024
1068
 
1086
 
1069
;---------------------------------------------------------------------
1087
;---------------------------------------------------------------------
1070
 
1088
 
1071
procinfo process_information
1089
procinfo process_information
1072
 
1090
 
1073
work_area:
1091
work_area:
1074
 rb 0x10000
1092
 rb 0x10000
1075
 
1093
 
1076
;---------------------------------------------------------------------
1094
;---------------------------------------------------------------------
1077
 
1095
 
1078
rb 0x800
1096
rb 0x800
1079
thread_stack:
1097
thread_stack:
1080
 
1098
 
1081
rb 0x1000 ; for stack
1099
rb 0x1000 ; for stack
1082
STACK_P:
1100
STACK_P:
1083
 
1101
 
1084
MEMORY_END:
1102
MEMORY_END: