Rev 741 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
431 | serge | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3 | ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;; |
||
4 | ;; Distributed under terms of the GNU General Public License ;; |
||
5 | ;; ;; |
||
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
351 | diamond | 7 | |
8 | format MS COFF |
||
9 | |||
10 | |||
11 | include 'proc32.inc' |
||
12 | include 'imports.inc' |
||
13 | |||
774 | Rus | 14 | API_VERSION equ 0x01000100 |
465 | serge | 15 | |
774 | Rus | 16 | DEBUG equ 1 |
17 | DEBUG_IRQ equ 0 |
||
351 | diamond | 18 | |
774 | Rus | 19 | USE_COM_IRQ equ 0 ;make irq 3 and irq 4 available for PCI devices |
20 | IRQ_REMAP equ 0 |
||
21 | IRQ_LINE equ 0 |
||
351 | diamond | 22 | |
566 | serge | 23 | |
351 | diamond | 24 | ;irq 0,1,2,8,12,13 недоступны |
566 | serge | 25 | ; FEDCBA9876543210 |
774 | Rus | 26 | VALID_IRQ equ 1100111011111000b |
27 | ATTCH_IRQ equ 0000111010100000b |
||
351 | diamond | 28 | |
566 | serge | 29 | if USE_COM_IRQ |
774 | Rus | 30 | ATTCH_IRQ equ 0000111010111000b |
566 | serge | 31 | end if |
351 | diamond | 32 | |
774 | Rus | 33 | CPU_FREQ equ 2600d |
351 | diamond | 34 | |
35 | BIT0 EQU 0x00000001 |
||
36 | BIT1 EQU 0x00000002 |
||
37 | BIT2 EQU 0x00000004 |
||
38 | BIT3 EQU 0x00000008 |
||
39 | BIT4 EQU 0x00000010 |
||
40 | BIT5 EQU 0x00000020 |
||
41 | BIT6 EQU 0x00000040 |
||
42 | BIT7 EQU 0x00000080 |
||
43 | BIT8 EQU 0x00000100 |
||
44 | BIT9 EQU 0x00000200 |
||
45 | BIT10 EQU 0x00000400 |
||
46 | BIT11 EQU 0x00000800 |
||
47 | BIT12 EQU 0x00001000 |
||
48 | BIT13 EQU 0x00002000 |
||
49 | BIT14 EQU 0x00004000 |
||
50 | BIT15 EQU 0x00008000 |
||
51 | BIT16 EQU 0x00010000 |
||
52 | BIT17 EQU 0x00020000 |
||
53 | BIT18 EQU 0x00040000 |
||
54 | BIT19 EQU 0x00080000 |
||
55 | BIT20 EQU 0x00100000 |
||
56 | BIT21 EQU 0x00200000 |
||
57 | BIT22 EQU 0x00400000 |
||
58 | BIT23 EQU 0x00800000 |
||
59 | BIT24 EQU 0x00100000 |
||
60 | BIT25 EQU 0x02000000 |
||
61 | BIT26 EQU 0x04000000 |
||
62 | BIT27 EQU 0x08000000 |
||
63 | BIT28 EQU 0x10000000 |
||
64 | BIT29 EQU 0x20000000 |
||
65 | BIT30 EQU 0x40000000 |
||
66 | BIT31 EQU 0x80000000 |
||
67 | |||
465 | serge | 68 | PCM_4 equ BIT20 |
69 | PCM_6 equ BIT21 |
||
70 | |||
774 | Rus | 71 | VID_INTEL equ 0x8086 |
72 | VID_NVIDIA equ 0x10DE |
||
351 | diamond | 73 | |
774 | Rus | 74 | CTRL_ICH equ 0x2415 |
75 | CTRL_ICH0 equ 0x2425 |
||
76 | CTRL_ICH2 equ 0x2435 |
||
77 | CTRL_ICH3 equ 0x2445 |
||
78 | CTRL_ICH4 equ 0x24C5 |
||
79 | CTRL_ICH5 equ 0x24D5 |
||
80 | CTRL_ICH6 equ 0x266E |
||
81 | CTRL_ICH7 equ 0x27DE |
||
351 | diamond | 82 | |
774 | Rus | 83 | CTRL_NFORCE equ 0x01B1 |
84 | CTRL_NFORCE2 equ 0x006A |
||
85 | CTRL_NFORCE3 equ 0x00DA |
||
86 | CTRL_MCP04 equ 0x003A |
||
87 | CTRL_CK804 equ 0x0059 |
||
88 | CTRL_CK8 equ 0x008A |
||
89 | CTRL_CK8S equ 0x00EA |
||
90 | CTRL_MCP51 equ 0x026B |
||
351 | diamond | 91 | |
92 | |||
774 | Rus | 93 | PCM_OUT_BDL equ 0x10 ; PCM out buffer descriptors list |
94 | PCM_OUT_CR_REG equ 0x1b ; PCM out Control Register |
||
562 | serge | 95 | PCM_OUT_LVI_REG equ 0x15 ; PCM last valid index |
774 | Rus | 96 | PCM_OUT_SR_REG equ 0x16 ; PCM out Status register |
562 | serge | 97 | PCM_OUT_PIV_REG equ 0x1a |
98 | PCM_OUT_CIV_REG equ 0x14 ; PCM out current index |
||
351 | diamond | 99 | |
774 | Rus | 100 | PCM_IN_CR_REG equ 0x0b ; PCM in Control Register |
101 | MC_IN_CR_REG equ 0x2b ; MIC in Control Register |
||
102 | RR equ BIT1 ; reset registers. Nukes all regs |
||
351 | diamond | 103 | |
774 | Rus | 104 | CODEC_MASTER_VOL_REG equ 0x02 |
105 | CODEC_AUX_VOL equ 0x04 ; |
||
106 | CODEC_PCM_OUT_REG equ 0x18 ; PCM output volume |
||
107 | CODEC_EXT_AUDIO_REG equ 0x28 ; extended audio |
||
465 | serge | 108 | CODEC_EXT_AUDIO_CTRL_REG equ 0x2a ; extended audio control |
109 | CODEC_PCM_FRONT_DACRATE_REG equ 0x2c ; PCM out sample rate |
||
110 | CODEC_PCM_SURND_DACRATE_REG equ 0x2e ; surround sound sample rate |
||
111 | CODEC_PCM_LFE_DACRATE_REG equ 0x30 ; LFE sample rate |
||
351 | diamond | 112 | |
774 | Rus | 113 | GLOB_CTRL equ 0x2C ; Global Control |
114 | CTRL_STAT equ 0x30 ; Global Status |
||
115 | CTRL_CAS equ 0x34 ; Codec Access Semiphore |
||
351 | diamond | 116 | |
774 | Rus | 117 | CAS_FLAG equ 0x01 ; Codec Access Semiphore Bit |
351 | diamond | 118 | |
774 | Rus | 119 | CTRL_ST_CREADY equ BIT8+BIT9+BIT28 ; Primary Codec Ready |
351 | diamond | 120 | |
774 | Rus | 121 | CTRL_ST_RCS equ 0x00008000 ; Read Completion Status |
351 | diamond | 122 | |
774 | Rus | 123 | CTRL_CNT_CRIE equ BIT4+BIT5+BIT6 ; Codecs Resume Interrupt Enable |
562 | serge | 124 | CTRL_CNT_AC_OFF equ 0x00000008 ; ACLINK Off |
774 | Rus | 125 | CTRL_CNT_WARM equ 0x00000004 ; AC97 Warm Reset |
126 | CTRL_CNT_COLD equ 0x00000002 ; AC97 Cold Reset |
||
127 | CTRL_CNT_GIE equ 0x00000001 ; GPI Interrupt Enable |
||
351 | diamond | 128 | |
129 | CODEC_REG_POWERDOWN equ 0x26 |
||
774 | Rus | 130 | CODEC_REG_ST equ 0x26 |
351 | diamond | 131 | |
774 | Rus | 132 | SRV_GETVERSION equ 0 |
133 | DEV_PLAY equ 1 |
||
134 | DEV_STOP equ 2 |
||
135 | DEV_CALLBACK equ 3 |
||
136 | DEV_SET_BUFF equ 4 |
||
137 | DEV_NOTIFY equ 5 |
||
351 | diamond | 138 | DEV_SET_MASTERVOL equ 6 |
139 | DEV_GET_MASTERVOL equ 7 |
||
774 | Rus | 140 | DEV_GET_INFO equ 8 |
351 | diamond | 141 | |
142 | struc AC_CNTRL ;AC controller base class |
||
774 | Rus | 143 | { .bus dd ? |
144 | .devfn dd ? |
||
351 | diamond | 145 | |
774 | Rus | 146 | .vendor dd ? |
147 | .dev_id dd ? |
||
148 | .pci_cmd dd ? |
||
149 | .pci_stat dd ? |
||
351 | diamond | 150 | |
151 | .codec_io_base dd ? |
||
152 | .codec_mem_base dd ? |
||
153 | |||
154 | .ctrl_io_base dd ? |
||
155 | .ctrl_mem_base dd ? |
||
774 | Rus | 156 | .cfg_reg dd ? |
157 | .int_line dd ? |
||
351 | diamond | 158 | |
774 | Rus | 159 | .vendor_ids dd ? ;vendor id string |
160 | .ctrl_ids dd ? ;hub id string |
||
351 | diamond | 161 | |
774 | Rus | 162 | .buffer dd ? |
351 | diamond | 163 | |
774 | Rus | 164 | .notify_pos dd ? |
165 | .notify_task dd ? |
||
351 | diamond | 166 | |
774 | Rus | 167 | .lvi_reg dd ? |
168 | .ctrl_setup dd ? |
||
351 | diamond | 169 | .user_callback dd ? |
170 | .codec_read16 dd ? |
||
171 | .codec_write16 dd ? |
||
172 | |||
774 | Rus | 173 | .ctrl_read8 dd ? |
174 | .ctrl_read16 dd ? |
||
175 | .ctrl_read32 dd ? |
||
351 | diamond | 176 | |
774 | Rus | 177 | .ctrl_write8 dd ? |
351 | diamond | 178 | .ctrl_write16 dd ? |
179 | .ctrl_write32 dd ? |
||
180 | } |
||
181 | |||
182 | struc CODEC ;Audio Chip base class |
||
183 | { |
||
774 | Rus | 184 | .chip_id dd ? |
185 | .flags dd ? |
||
186 | .status dd ? |
||
351 | diamond | 187 | |
188 | .ac_vendor_ids dd ? ;ac vendor id string |
||
774 | Rus | 189 | .chip_ids dd ? ;chip model string |
351 | diamond | 190 | |
774 | Rus | 191 | .shadow_flag dd ? |
192 | dd ? |
||
351 | diamond | 193 | |
774 | Rus | 194 | .regs dw ? ; codec registers |
351 | diamond | 195 | .reg_master_vol dw ? ;0x02 |
196 | .reg_aux_out_vol dw ? ;0x04 |
||
197 | .reg_mone_vol dw ? ;0x06 |
||
198 | .reg_master_tone dw ? ;0x08 |
||
199 | .reg_beep_vol dw ? ;0x0A |
||
200 | .reg_phone_vol dw ? ;0x0C |
||
774 | Rus | 201 | .reg_mic_vol dw ? ;0x0E |
351 | diamond | 202 | .reg_line_in_vol dw ? ;0x10 |
774 | Rus | 203 | .reg_cd_vol dw ? ;0x12 |
351 | diamond | 204 | .reg_video_vol dw ? ;0x14 |
205 | .reg_aux_in_vol dw ? ;0x16 |
||
206 | .reg_pcm_out_vol dw ? ;0x18 |
||
207 | .reg_rec_select dw ? ;0x1A |
||
208 | .reg_rec_gain dw ? ;0x1C |
||
209 | .reg_rec_gain_mic dw ? ;0x1E |
||
774 | Rus | 210 | .reg_gen dw ? ;0x20 |
211 | .reg_3d_ctrl dw ? ;0X22 |
||
212 | .reg_page dw ? ;0X24 |
||
351 | diamond | 213 | .reg_powerdown dw ? ;0x26 |
214 | .reg_ext_audio dw ? ;0x28 |
||
774 | Rus | 215 | .reg_ext_st dw ? ;0x2a |
351 | diamond | 216 | .reg_pcm_front_rate dw ? ;0x2c |
217 | .reg_pcm_surr_rate dw ? ;0x2e |
||
218 | .reg_lfe_rate dw ? ;0x30 |
||
219 | .reg_pcm_in_rate dw ? ;0x32 |
||
774 | Rus | 220 | dw ? ;0x34 |
351 | diamond | 221 | .reg_cent_lfe_vol dw ? ;0x36 |
222 | .reg_surr_vol dw ? ;0x38 |
||
223 | .reg_spdif_ctrl dw ? ;0x3A |
||
774 | Rus | 224 | dw ? ;0x3C |
225 | dw ? ;0x3E |
||
226 | dw ? ;0x40 |
||
227 | dw ? ;0x42 |
||
228 | dw ? ;0x44 |
||
229 | dw ? ;0x46 |
||
230 | dw ? ;0x48 |
||
231 | dw ? ;0x4A |
||
232 | dw ? ;0x4C |
||
233 | dw ? ;0x4E |
||
234 | dw ? ;0x50 |
||
235 | dw ? ;0x52 |
||
236 | dw ? ;0x54 |
||
237 | dw ? ;0x56 |
||
238 | dw ? ;0x58 |
||
239 | dw ? ;0x5A |
||
240 | dw ? ;0x5C |
||
241 | dw ? ;0x5E |
||
242 | .reg_page_0 dw ? ;0x60 |
||
243 | .reg_page_1 dw ? ;0x62 |
||
244 | .reg_page_2 dw ? ;0x64 |
||
245 | .reg_page_3 dw ? ;0x66 |
||
246 | .reg_page_4 dw ? ;0x68 |
||
247 | .reg_page_5 dw ? ;0x6A |
||
248 | .reg_page_6 dw ? ;0x6C |
||
249 | .reg_page_7 dw ? ;0x6E |
||
250 | dw ? ;0x70 |
||
251 | dw ? ;0x72 |
||
252 | dw ? ;0x74 |
||
253 | dw ? ;0x76 |
||
254 | dw ? ;0x78 |
||
255 | dw ? ;0x7A |
||
351 | diamond | 256 | .reg_vendor_id_1 dw ? ;0x7C |
257 | .reg_vendor_id_2 dw ? ;0x7E |
||
258 | |||
259 | |||
774 | Rus | 260 | .reset dd ? ;virual |
351 | diamond | 261 | .set_master_vol dd ? |
262 | } |
||
263 | |||
264 | struc CTRL_INFO |
||
774 | Rus | 265 | { .pci_cmd dd ? |
266 | .irq dd ? |
||
465 | serge | 267 | .glob_cntrl dd ? |
774 | Rus | 268 | .glob_sta dd ? |
465 | serge | 269 | .codec_io_base dd ? |
270 | .ctrl_io_base dd ? |
||
271 | .codec_mem_base dd ? |
||
272 | .ctrl_mem_base dd ? |
||
774 | Rus | 273 | .codec_id dd ? |
351 | diamond | 274 | } |
275 | |||
276 | struc IOCTL |
||
774 | Rus | 277 | { .handle dd ? |
278 | .io_code dd ? |
||
279 | .input dd ? |
||
280 | .inp_size dd ? |
||
281 | .output dd ? |
||
282 | .out_size dd ? |
||
351 | diamond | 283 | } |
284 | |||
285 | virtual at 0 |
||
286 | IOCTL IOCTL |
||
287 | end virtual |
||
288 | |||
774 | Rus | 289 | EVENT_NOTIFY equ 0x00000200 |
351 | diamond | 290 | |
291 | public START |
||
292 | public service_proc |
||
293 | public version |
||
294 | |||
295 | section '.flat' code readable align 16 |
||
296 | |||
297 | proc START stdcall, state:dword |
||
298 | |||
774 | Rus | 299 | cmp [state], 1 |
300 | jne .stop |
||
351 | diamond | 301 | |
302 | if DEBUG |
||
774 | Rus | 303 | mov esi, msgInit |
304 | call SysMsgBoardStr |
||
351 | diamond | 305 | end if |
306 | |||
774 | Rus | 307 | call detect_controller |
308 | test eax, eax |
||
309 | jz .fail |
||
351 | diamond | 310 | |
311 | if DEBUG |
||
774 | Rus | 312 | mov esi,[ctrl.vendor_ids] |
313 | call SysMsgBoardStr |
||
314 | mov esi, [ctrl.ctrl_ids] |
||
315 | call SysMsgBoardStr |
||
351 | diamond | 316 | |
317 | end if |
||
318 | |||
774 | Rus | 319 | call init_controller |
320 | test eax, eax |
||
321 | jz .fail |
||
351 | diamond | 322 | |
774 | Rus | 323 | call init_codec |
324 | test eax, eax |
||
325 | jz .fail |
||
351 | diamond | 326 | |
774 | Rus | 327 | call reset_controller |
328 | call setup_codec |
||
351 | diamond | 329 | |
774 | Rus | 330 | mov esi, msgPrimBuff |
331 | call SysMsgBoardStr |
||
332 | call create_primary_buff |
||
333 | mov esi, msgDone |
||
334 | call SysMsgBoardStr |
||
351 | diamond | 335 | |
566 | serge | 336 | if IRQ_REMAP |
774 | Rus | 337 | pushf |
338 | cli |
||
351 | diamond | 339 | |
774 | Rus | 340 | mov ebx, [ctrl.int_line] |
341 | in al, 0xA1 |
||
342 | mov ah, al |
||
343 | in al, 0x21 |
||
344 | test ebx, ebx |
||
345 | jz .skip |
||
346 | bts ax, bx ;mask old line |
||
566 | serge | 347 | .skip |
774 | Rus | 348 | bts ax, IRQ_LINE ;mask new ine |
349 | out 0x21, al |
||
350 | mov al, ah |
||
351 | out 0xA1, al |
||
352 | ;remap IRQ |
||
353 | stdcall PciWrite8, 0, 0xF8, 0x61, IRQ_LINE |
||
566 | serge | 354 | |
774 | Rus | 355 | mov dx, 0x4d0 ;8259 ELCR1 |
356 | in al, dx |
||
357 | bts ax, IRQ_LINE |
||
358 | out dx, al ;set level-triggered mode |
||
359 | mov [ctrl.int_line], IRQ_LINE |
||
360 | popf |
||
361 | mov esi, msgRemap |
||
362 | call SysMsgBoardStr |
||
566 | serge | 363 | end if |
364 | |||
774 | Rus | 365 | mov eax, VALID_IRQ |
366 | mov ebx, [ctrl.int_line] |
||
367 | mov esi, msgInvIRQ |
||
368 | bt eax, ebx |
||
369 | jnc .fail_msg |
||
370 | mov eax, ATTCH_IRQ |
||
371 | mov esi, msgAttchIRQ |
||
372 | bt eax, ebx |
||
373 | jnc .fail_msg |
||
351 | diamond | 374 | |
774 | Rus | 375 | stdcall AttachIntHandler, ebx, ac97_irq, dword 0 |
465 | serge | 376 | .reg: |
774 | Rus | 377 | stdcall RegService, sz_sound_srv, service_proc |
378 | ret |
||
351 | diamond | 379 | .fail: |
380 | if DEBUG |
||
774 | Rus | 381 | mov esi, msgFail |
382 | call SysMsgBoardStr |
||
351 | diamond | 383 | end if |
774 | Rus | 384 | xor eax, eax |
385 | ret |
||
563 | serge | 386 | .fail_msg: |
774 | Rus | 387 | call SysMsgBoardStr |
388 | xor eax, eax |
||
389 | ret |
||
351 | diamond | 390 | .stop: |
774 | Rus | 391 | call stop |
392 | xor eax, eax |
||
393 | ret |
||
351 | diamond | 394 | endp |
395 | |||
774 | Rus | 396 | handle equ IOCTL.handle |
397 | io_code equ IOCTL.io_code |
||
398 | input equ IOCTL.input |
||
399 | inp_size equ IOCTL.inp_size |
||
400 | output equ IOCTL.output |
||
401 | out_size equ IOCTL.out_size |
||
351 | diamond | 402 | |
403 | align 4 |
||
404 | proc service_proc stdcall, ioctl:dword |
||
405 | |||
774 | Rus | 406 | mov edi, [ioctl] |
407 | mov eax, [edi+io_code] |
||
465 | serge | 408 | |
774 | Rus | 409 | cmp eax, SRV_GETVERSION |
410 | jne @F |
||
465 | serge | 411 | |
774 | Rus | 412 | mov eax, [edi+output] |
413 | cmp [edi+out_size], 4 |
||
414 | jne .fail |
||
465 | serge | 415 | |
774 | Rus | 416 | mov [eax], dword API_VERSION |
417 | xor eax, eax |
||
418 | ret |
||
465 | serge | 419 | @@: |
774 | Rus | 420 | cmp eax, DEV_PLAY |
421 | jne @F |
||
351 | diamond | 422 | if DEBUG |
774 | Rus | 423 | mov esi, msgPlay |
424 | call SysMsgBoardStr |
||
351 | diamond | 425 | end if |
774 | Rus | 426 | call play |
427 | ret |
||
351 | diamond | 428 | @@: |
774 | Rus | 429 | cmp eax, DEV_STOP |
430 | jne @F |
||
351 | diamond | 431 | if DEBUG |
774 | Rus | 432 | mov esi, msgStop |
433 | call SysMsgBoardStr |
||
351 | diamond | 434 | end if |
774 | Rus | 435 | call stop |
436 | ret |
||
351 | diamond | 437 | @@: |
774 | Rus | 438 | cmp eax, DEV_CALLBACK |
439 | jne @F |
||
440 | mov ebx, [edi+input] |
||
441 | stdcall set_callback, [ebx] |
||
442 | ret |
||
351 | diamond | 443 | @@: |
774 | Rus | 444 | cmp eax, DEV_SET_MASTERVOL |
445 | jne @F |
||
446 | mov eax, [edi+input] |
||
447 | mov eax, [eax] |
||
448 | call set_master_vol ;eax= vol |
||
449 | ret |
||
351 | diamond | 450 | @@: |
774 | Rus | 451 | cmp eax, DEV_GET_MASTERVOL |
452 | jne @F |
||
453 | mov ebx, [edi+output] |
||
454 | stdcall get_master_vol, ebx |
||
455 | ret |
||
378 | serge | 456 | ;@@: |
457 | ; cmp eax, DEV_GET_INFO |
||
458 | ; jne @F |
||
459 | ; mov ebx, [edi+output] |
||
460 | ; stdcall get_dev_info, ebx |
||
461 | ; ret |
||
351 | diamond | 462 | @@: |
463 | .fail: |
||
774 | Rus | 464 | or eax, -1 |
465 | ret |
||
351 | diamond | 466 | endp |
467 | |||
468 | restore handle |
||
469 | restore io_code |
||
470 | restore input |
||
471 | restore inp_size |
||
472 | restore output |
||
473 | restore out_size |
||
474 | |||
475 | align 4 |
||
476 | proc ac97_irq |
||
477 | |||
566 | serge | 478 | if DEBUG_IRQ |
774 | Rus | 479 | mov esi, msgIRQ |
480 | call SysMsgBoardStr |
||
566 | serge | 481 | end if |
351 | diamond | 482 | |
774 | Rus | 483 | mov edx, PCM_OUT_CR_REG |
484 | mov al, 0x10; 0x10 |
||
485 | call [ctrl.ctrl_write8] |
||
351 | diamond | 486 | |
774 | Rus | 487 | mov ax, 0x1c |
488 | mov edx, PCM_OUT_SR_REG |
||
489 | call [ctrl.ctrl_write16] |
||
351 | diamond | 490 | |
774 | Rus | 491 | mov edx, PCM_OUT_CIV_REG |
492 | call [ctrl.ctrl_read8] |
||
351 | diamond | 493 | |
774 | Rus | 494 | and eax, 0x1F |
495 | cmp eax, [civ_val] |
||
496 | je .skip |
||
351 | diamond | 497 | |
774 | Rus | 498 | mov [civ_val], eax |
499 | dec eax |
||
500 | and eax, 0x1F |
||
501 | mov [ctrl.lvi_reg], eax |
||
351 | diamond | 502 | |
774 | Rus | 503 | mov edx, PCM_OUT_LVI_REG |
504 | call [ctrl.ctrl_write8] |
||
351 | diamond | 505 | |
774 | Rus | 506 | mov edx, PCM_OUT_CR_REG |
507 | mov ax, 0x11 ;0x1D |
||
508 | call [ctrl.ctrl_write8] |
||
351 | diamond | 509 | |
774 | Rus | 510 | mov eax, [civ_val] |
511 | add eax, 1 |
||
512 | and eax, 31 |
||
513 | mov ebx, dword [buff_list+eax*4] |
||
351 | diamond | 514 | |
774 | Rus | 515 | cmp [ctrl.user_callback], 0 |
516 | je @f |
||
351 | diamond | 517 | |
774 | Rus | 518 | stdcall [ctrl.user_callback], ebx |
351 | diamond | 519 | @@: |
774 | Rus | 520 | ret |
351 | diamond | 521 | |
522 | .skip: |
||
774 | Rus | 523 | mov edx, PCM_OUT_CR_REG |
524 | mov ax, 0x11 ;0x1D |
||
525 | call [ctrl.ctrl_write8] |
||
526 | ret |
||
351 | diamond | 527 | endp |
528 | |||
529 | align 4 |
||
530 | proc create_primary_buff |
||
531 | |||
774 | Rus | 532 | stdcall KernelAlloc, 0x10000 |
533 | mov [ctrl.buffer], eax |
||
351 | diamond | 534 | |
774 | Rus | 535 | mov edi, eax |
536 | mov ecx, 0x10000/4 |
||
537 | xor eax, eax |
||
538 | cld |
||
539 | rep stosd |
||
351 | diamond | 540 | |
774 | Rus | 541 | mov eax, [ctrl.buffer] |
542 | call GetPgAddr |
||
351 | diamond | 543 | |
774 | Rus | 544 | mov ebx, 0xC0002000 |
545 | mov ecx, 4 |
||
546 | mov edi, pcmout_bdl |
||
351 | diamond | 547 | @@: |
774 | Rus | 548 | mov [edi], eax |
549 | mov [edi+4], ebx |
||
351 | diamond | 550 | |
774 | Rus | 551 | mov [edi+32], eax |
552 | mov [edi+4+32], ebx |
||
351 | diamond | 553 | |
774 | Rus | 554 | mov [edi+64], eax |
555 | mov [edi+4+64], ebx |
||
351 | diamond | 556 | |
774 | Rus | 557 | mov [edi+96], eax |
558 | mov [edi+4+96], ebx |
||
351 | diamond | 559 | |
774 | Rus | 560 | mov [edi+128], eax |
561 | mov [edi+4+128], ebx |
||
351 | diamond | 562 | |
774 | Rus | 563 | mov [edi+160], eax |
564 | mov [edi+4+160], ebx |
||
351 | diamond | 565 | |
774 | Rus | 566 | mov [edi+192], eax |
567 | mov [edi+4+192], ebx |
||
351 | diamond | 568 | |
774 | Rus | 569 | mov [edi+224], eax |
570 | mov [edi+4+224], ebx |
||
351 | diamond | 571 | |
774 | Rus | 572 | add eax, 0x4000 |
573 | add edi, 8 |
||
574 | loop @B |
||
351 | diamond | 575 | |
774 | Rus | 576 | mov edi, buff_list |
577 | mov eax, [ctrl.buffer] |
||
578 | mov ecx, 4 |
||
351 | diamond | 579 | @@: |
774 | Rus | 580 | mov [edi], eax |
581 | mov [edi+16], eax |
||
582 | mov [edi+32], eax |
||
583 | mov [edi+48], eax |
||
584 | mov [edi+64], eax |
||
585 | mov [edi+80], eax |
||
586 | mov [edi+96], eax |
||
587 | mov [edi+112], eax |
||
351 | diamond | 588 | |
774 | Rus | 589 | add eax, 0x4000 |
590 | add edi, 4 |
||
591 | loop @B |
||
351 | diamond | 592 | |
774 | Rus | 593 | mov eax, pcmout_bdl |
594 | mov ebx, eax |
||
595 | call GetPgAddr ;eax |
||
596 | and ebx, 0xFFF |
||
597 | add eax, ebx |
||
351 | diamond | 598 | |
774 | Rus | 599 | mov edx, PCM_OUT_BDL |
600 | call [ctrl.ctrl_write32] |
||
351 | diamond | 601 | |
774 | Rus | 602 | mov eax, 16 |
603 | mov [ctrl.lvi_reg], eax |
||
604 | mov edx, PCM_OUT_LVI_REG |
||
605 | call [ctrl.ctrl_write8] |
||
606 | ret |
||
351 | diamond | 607 | endp |
608 | |||
609 | align 4 |
||
610 | proc detect_controller |
||
774 | Rus | 611 | locals |
612 | last_bus dd ? |
||
613 | bus dd ? |
||
614 | devfn dd ? |
||
615 | endl |
||
351 | diamond | 616 | |
774 | Rus | 617 | xor eax, eax |
618 | mov [bus], eax |
||
619 | inc eax |
||
620 | call PciApi |
||
621 | cmp eax, -1 |
||
622 | je .err |
||
351 | diamond | 623 | |
774 | Rus | 624 | mov [last_bus], eax |
351 | diamond | 625 | |
626 | .next_bus: |
||
774 | Rus | 627 | and [devfn], 0 |
351 | diamond | 628 | .next_dev: |
774 | Rus | 629 | stdcall PciRead32, [bus], [devfn], dword 0 |
630 | test eax, eax |
||
631 | jz .next |
||
632 | cmp eax, -1 |
||
633 | je .next |
||
351 | diamond | 634 | |
774 | Rus | 635 | mov edi, devices |
351 | diamond | 636 | @@: |
774 | Rus | 637 | mov ebx, [edi] |
638 | test ebx, ebx |
||
639 | jz .next |
||
351 | diamond | 640 | |
774 | Rus | 641 | cmp eax, ebx |
642 | je .found |
||
643 | add edi, 12 |
||
644 | jmp @B |
||
351 | diamond | 645 | .next: |
774 | Rus | 646 | inc [devfn] |
647 | cmp [devfn], 256 |
||
648 | jb .next_dev |
||
649 | mov eax, [bus] |
||
650 | inc eax |
||
651 | mov [bus], eax |
||
652 | cmp eax, [last_bus] |
||
653 | jna .next_bus |
||
654 | xor eax, eax |
||
655 | ret |
||
351 | diamond | 656 | .found: |
774 | Rus | 657 | mov ebx, [bus] |
658 | mov [ctrl.bus], ebx |
||
351 | diamond | 659 | |
774 | Rus | 660 | mov ecx, [devfn] |
661 | mov [ctrl.devfn], ecx |
||
351 | diamond | 662 | |
774 | Rus | 663 | mov edx, eax |
664 | and edx, 0xFFFF |
||
665 | mov [ctrl.vendor], edx |
||
666 | shr eax, 16 |
||
667 | mov [ctrl.dev_id], eax |
||
351 | diamond | 668 | |
774 | Rus | 669 | mov ebx, [edi+4] |
670 | mov [ctrl.ctrl_ids], ebx |
||
671 | mov esi, [edi+8] |
||
672 | mov [ctrl.ctrl_setup], esi |
||
351 | diamond | 673 | |
774 | Rus | 674 | cmp edx, VID_INTEL |
675 | jne @F |
||
676 | mov [ctrl.vendor_ids], msg_Intel |
||
677 | ret |
||
351 | diamond | 678 | @@: |
774 | Rus | 679 | cmp edx, VID_NVIDIA |
680 | jne @F |
||
681 | mov [ctrl.vendor_ids], msg_NVidia |
||
682 | ret |
||
351 | diamond | 683 | @@: |
684 | .err: |
||
774 | Rus | 685 | xor eax, eax |
686 | mov [ctrl.vendor_ids], eax ;something wrong ? |
||
687 | ret |
||
351 | diamond | 688 | endp |
689 | |||
690 | align 4 |
||
691 | proc init_controller |
||
692 | |||
774 | Rus | 693 | stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 4 |
694 | mov ebx, eax |
||
695 | and eax, 0xFFFF |
||
696 | mov [ctrl.pci_cmd], eax |
||
697 | shr ebx, 16 |
||
698 | mov [ctrl.pci_stat], ebx |
||
351 | diamond | 699 | |
774 | Rus | 700 | mov esi, msgPciCmd |
701 | call SysMsgBoardStr |
||
702 | call dword2str |
||
703 | call SysMsgBoardStr |
||
562 | serge | 704 | |
774 | Rus | 705 | mov esi, msgPciStat |
706 | call SysMsgBoardStr |
||
707 | mov eax, [ctrl.pci_stat] |
||
708 | call dword2str |
||
709 | call SysMsgBoardStr |
||
562 | serge | 710 | |
774 | Rus | 711 | mov esi, msgMixIsaIo |
712 | call SysMsgBoardStr |
||
562 | serge | 713 | |
774 | Rus | 714 | stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x10 |
562 | serge | 715 | |
774 | Rus | 716 | call dword2str |
717 | call SysMsgBoardStr |
||
562 | serge | 718 | |
774 | Rus | 719 | and eax,0xFFFE |
720 | mov [ctrl.codec_io_base], eax |
||
351 | diamond | 721 | |
774 | Rus | 722 | mov esi, msgCtrlIsaIo |
723 | call SysMsgBoardStr |
||
562 | serge | 724 | |
774 | Rus | 725 | stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x14 |
562 | serge | 726 | |
774 | Rus | 727 | call dword2str |
728 | call SysMsgBoardStr |
||
562 | serge | 729 | |
774 | Rus | 730 | and eax, 0xFFC0 |
731 | mov [ctrl.ctrl_io_base], eax |
||
351 | diamond | 732 | |
774 | Rus | 733 | mov esi, msgMixMMIo |
734 | call SysMsgBoardStr |
||
562 | serge | 735 | |
774 | Rus | 736 | stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x18 |
737 | mov [ctrl.codec_mem_base], eax |
||
351 | diamond | 738 | |
774 | Rus | 739 | call dword2str |
740 | call SysMsgBoardStr |
||
562 | serge | 741 | |
774 | Rus | 742 | mov esi, msgCtrlMMIo |
743 | call SysMsgBoardStr |
||
562 | serge | 744 | |
774 | Rus | 745 | stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x1C |
746 | mov [ctrl.ctrl_mem_base], eax |
||
351 | diamond | 747 | |
774 | Rus | 748 | call dword2str |
749 | call SysMsgBoardStr |
||
562 | serge | 750 | |
567 | serge | 751 | if 0 |
752 | |||
568 | serge | 753 | ;;patch for some ugly BIOS ICH-ICH5 compatible |
774 | Rus | 754 | cmp [ctrl.vendor], VID_INTEL |
755 | jne .default |
||
566 | serge | 756 | |
774 | Rus | 757 | mov esi, msgIrqMap |
758 | call SysMsgBoardStr |
||
759 | stdcall PciRead8, 0, 0xF8, 0x61 |
||
760 | and eax, 0xFF |
||
761 | call dword2str |
||
762 | call SysMsgBoardStr |
||
763 | btr eax, 7 ;when bit 7 set remap disabled |
||
764 | jnc @F |
||
765 | xor eax, eax |
||
766 | jmp @F |
||
567 | serge | 767 | end if |
768 | |||
566 | serge | 769 | .default: |
774 | Rus | 770 | stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x3C |
771 | and eax, 0xFF |
||
566 | serge | 772 | @@: |
774 | Rus | 773 | mov [ctrl.int_line], eax |
351 | diamond | 774 | |
774 | Rus | 775 | stdcall PciRead8, [ctrl.bus], [ctrl.devfn], dword 0x41 |
776 | and eax, 0xFF |
||
777 | mov [ctrl.cfg_reg], eax |
||
351 | diamond | 778 | |
774 | Rus | 779 | call [ctrl.ctrl_setup] |
780 | xor eax, eax |
||
781 | inc eax |
||
782 | ret |
||
351 | diamond | 783 | endp |
784 | |||
785 | align 4 |
||
786 | proc set_ICH |
||
774 | Rus | 787 | mov [ctrl.codec_read16], codec_io_r16 ;virtual |
788 | mov [ctrl.codec_write16], codec_io_w16 ;virtual |
||
351 | diamond | 789 | |
774 | Rus | 790 | mov [ctrl.ctrl_read8 ], ctrl_io_r8 ;virtual |
791 | mov [ctrl.ctrl_read16], ctrl_io_r16 ;virtual |
||
792 | mov [ctrl.ctrl_read32], ctrl_io_r32 ;virtual |
||
351 | diamond | 793 | |
774 | Rus | 794 | mov [ctrl.ctrl_write8 ], ctrl_io_w8 ;virtual |
795 | mov [ctrl.ctrl_write16], ctrl_io_w16 ;virtual |
||
796 | mov [ctrl.ctrl_write32], ctrl_io_w32 ;virtual |
||
797 | ret |
||
351 | diamond | 798 | endp |
799 | |||
774 | Rus | 800 | PG_SW equ 0x003 |
801 | PG_NOCACHE equ 0x018 |
||
351 | diamond | 802 | |
803 | align 4 |
||
804 | proc set_ICH4 |
||
805 | |||
774 | Rus | 806 | stdcall MapIoMem,[ctrl.codec_mem_base],0x1000,PG_SW+PG_NOCACHE |
807 | mov [ctrl.codec_mem_base], eax |
||
563 | serge | 808 | |
774 | Rus | 809 | stdcall MapIoMem,[ctrl.ctrl_mem_base],0x1000,PG_SW+PG_NOCACHE |
810 | mov [ctrl.ctrl_mem_base], eax |
||
741 | serge | 811 | |
774 | Rus | 812 | mov [ctrl.codec_read16], codec_mem_r16 ;virtual |
813 | mov [ctrl.codec_write16], codec_mem_w16 ;virtual |
||
351 | diamond | 814 | |
774 | Rus | 815 | mov [ctrl.ctrl_read8 ], ctrl_mem_r8 ;virtual |
816 | mov [ctrl.ctrl_read16], ctrl_mem_r16 ;virtual |
||
817 | mov [ctrl.ctrl_read32], ctrl_mem_r32 ;virtual |
||
351 | diamond | 818 | |
774 | Rus | 819 | mov [ctrl.ctrl_write8 ], ctrl_mem_w8 ;virtual |
820 | mov [ctrl.ctrl_write16], ctrl_mem_w16 ;virtual |
||
821 | mov [ctrl.ctrl_write32], ctrl_mem_w32 ;virtual |
||
822 | ret |
||
351 | diamond | 823 | endp |
824 | |||
825 | align 4 |
||
826 | proc reset_controller |
||
827 | |||
774 | Rus | 828 | xor eax, eax |
829 | mov edx, PCM_IN_CR_REG |
||
830 | call [ctrl.ctrl_write8] |
||
351 | diamond | 831 | |
774 | Rus | 832 | mov edx, PCM_OUT_CR_REG |
833 | call [ctrl.ctrl_write8] |
||
351 | diamond | 834 | |
774 | Rus | 835 | mov edx, MC_IN_CR_REG |
836 | call [ctrl.ctrl_write8] |
||
351 | diamond | 837 | |
774 | Rus | 838 | mov eax, RR |
839 | mov edx, PCM_IN_CR_REG |
||
840 | call [ctrl.ctrl_write8] |
||
351 | diamond | 841 | |
774 | Rus | 842 | mov edx, PCM_OUT_CR_REG |
843 | call [ctrl.ctrl_write8] |
||
351 | diamond | 844 | |
774 | Rus | 845 | mov edx, MC_IN_CR_REG |
846 | call [ctrl.ctrl_write8] |
||
847 | ret |
||
351 | diamond | 848 | endp |
849 | |||
850 | align 4 |
||
851 | proc init_codec |
||
774 | Rus | 852 | locals |
853 | counter dd ? |
||
854 | endl |
||
351 | diamond | 855 | |
774 | Rus | 856 | mov esi, msgControl |
857 | call SysMsgBoardStr |
||
351 | diamond | 858 | |
774 | Rus | 859 | mov edx, GLOB_CTRL |
860 | call [ctrl.ctrl_read32] |
||
861 | call dword2str |
||
862 | call SysMsgBoardStr |
||
351 | diamond | 863 | |
774 | Rus | 864 | mov esi, msgStatus |
865 | call SysMsgBoardStr |
||
351 | diamond | 866 | |
774 | Rus | 867 | mov edx, CTRL_STAT |
868 | call [ctrl.ctrl_read32] |
||
869 | push eax |
||
870 | call dword2str |
||
871 | call SysMsgBoardStr |
||
872 | pop eax |
||
873 | cmp eax, 0xFFFFFFFF |
||
874 | je .err |
||
351 | diamond | 875 | |
774 | Rus | 876 | test eax, CTRL_ST_CREADY |
877 | jnz .ready |
||
351 | diamond | 878 | |
774 | Rus | 879 | call reset_codec |
880 | test eax, eax |
||
881 | jz .err |
||
351 | diamond | 882 | |
562 | serge | 883 | .ready: |
774 | Rus | 884 | xor edx, edx ;ac_reg_0 |
885 | call [ctrl.codec_write16] |
||
351 | diamond | 886 | |
774 | Rus | 887 | xor eax, eax |
888 | mov edx, CODEC_REG_POWERDOWN |
||
889 | call [ctrl.codec_write16] |
||
351 | diamond | 890 | |
774 | Rus | 891 | mov [counter], 200 ; total 200*5 ms = 1s |
351 | diamond | 892 | .wait: |
774 | Rus | 893 | mov eax, 5000 ; wait 5 ms |
894 | call StallExec |
||
562 | serge | 895 | |
774 | Rus | 896 | mov edx, CODEC_REG_POWERDOWN |
897 | call [ctrl.codec_read16] |
||
898 | and eax, 0x0F |
||
899 | cmp eax, 0x0F |
||
900 | jz .done |
||
351 | diamond | 901 | |
774 | Rus | 902 | sub [counter] , 1 |
903 | jnz .wait |
||
351 | diamond | 904 | .err: |
774 | Rus | 905 | xor eax, eax ; timeout error |
906 | ret |
||
562 | serge | 907 | .done: |
774 | Rus | 908 | mov eax, 2 ;force set 16-bit 2-channel PCM |
909 | mov edx, GLOB_CTRL |
||
910 | call [ctrl.ctrl_write32] |
||
911 | mov eax, 5000 ; wait 5 ms |
||
912 | call StallExec |
||
465 | serge | 913 | |
774 | Rus | 914 | call detect_codec |
351 | diamond | 915 | |
774 | Rus | 916 | xor eax, eax |
917 | inc eax |
||
918 | ret |
||
351 | diamond | 919 | endp |
920 | |||
921 | align 4 |
||
922 | proc reset_codec |
||
774 | Rus | 923 | mov edx, GLOB_CTRL |
924 | call [ctrl.ctrl_read32] |
||
351 | diamond | 925 | |
774 | Rus | 926 | test eax, 0x02 |
927 | jz .cold |
||
351 | diamond | 928 | |
774 | Rus | 929 | call warm_reset |
930 | jnc .ok |
||
351 | diamond | 931 | .cold: |
774 | Rus | 932 | call cold_reset |
933 | jnc .ok |
||
351 | diamond | 934 | |
935 | if DEBUG |
||
774 | Rus | 936 | mov esi, msgCFail |
937 | call SysMsgBoardStr |
||
938 | end if |
||
939 | xor eax, eax ; timeout error |
||
940 | ret |
||
351 | diamond | 941 | .ok: |
942 | if DEBUG |
||
774 | Rus | 943 | mov esi, msgResetOk |
944 | call SysMsgBoardStr |
||
351 | diamond | 945 | end if |
946 | |||
774 | Rus | 947 | xor eax, eax |
948 | inc eax |
||
949 | ret |
||
351 | diamond | 950 | endp |
951 | |||
952 | align 4 |
||
953 | proc warm_reset |
||
774 | Rus | 954 | locals |
955 | counter dd ? |
||
956 | endl |
||
351 | diamond | 957 | |
774 | Rus | 958 | mov eax, 0x06 |
959 | mov edx, GLOB_CTRL |
||
960 | call [ctrl.ctrl_write32] |
||
351 | diamond | 961 | |
962 | if DEBUG |
||
774 | Rus | 963 | mov esi, msgWarm |
964 | call SysMsgBoardStr |
||
351 | diamond | 965 | end if |
966 | |||
774 | Rus | 967 | mov [counter], 10 ; total 10*100 ms = 1s |
351 | diamond | 968 | .wait: |
774 | Rus | 969 | mov eax, 100000 ; wait 100 ms |
970 | call StallExec |
||
351 | diamond | 971 | |
774 | Rus | 972 | mov edx, CTRL_STAT |
973 | call [ctrl.ctrl_read32] |
||
974 | test eax, CTRL_ST_CREADY |
||
975 | jnz .ok |
||
562 | serge | 976 | |
774 | Rus | 977 | dec [counter] |
978 | jnz .wait |
||
351 | diamond | 979 | |
980 | if DEBUG |
||
774 | Rus | 981 | mov esi, msgWRFail |
982 | call SysMsgBoardStr |
||
351 | diamond | 983 | end if |
562 | serge | 984 | .fail: |
774 | Rus | 985 | stc |
986 | ret |
||
351 | diamond | 987 | .ok: |
774 | Rus | 988 | clc |
989 | ret |
||
351 | diamond | 990 | endp |
991 | |||
992 | align 4 |
||
993 | proc cold_reset |
||
774 | Rus | 994 | locals |
995 | counter dd ? |
||
996 | endl |
||
351 | diamond | 997 | |
774 | Rus | 998 | mov eax, 0x02 |
999 | mov edx, GLOB_CTRL |
||
1000 | call [ctrl.ctrl_write32] |
||
351 | diamond | 1001 | |
1002 | if DEBUG |
||
774 | Rus | 1003 | mov esi, msgCold |
1004 | call SysMsgBoardStr |
||
351 | diamond | 1005 | end if |
1006 | |||
774 | Rus | 1007 | mov eax, 400000 ; wait 400 ms |
1008 | call StallExec |
||
351 | diamond | 1009 | |
774 | Rus | 1010 | mov [counter], 16 ; total 20*100 ms = 2s |
562 | serge | 1011 | .wait: |
351 | diamond | 1012 | |
774 | Rus | 1013 | mov edx, CTRL_STAT |
1014 | call [ctrl.ctrl_read32] |
||
1015 | test eax, CTRL_ST_CREADY |
||
1016 | jnz .ok |
||
562 | serge | 1017 | |
774 | Rus | 1018 | mov eax, 100000 ; wait 100 ms |
1019 | call StallExec |
||
351 | diamond | 1020 | |
774 | Rus | 1021 | dec [counter] |
1022 | jnz .wait |
||
351 | diamond | 1023 | |
1024 | if DEBUG |
||
774 | Rus | 1025 | mov esi, msgCRFail |
1026 | call SysMsgBoardStr |
||
351 | diamond | 1027 | end if |
562 | serge | 1028 | |
1029 | .fail: |
||
774 | Rus | 1030 | stc |
1031 | ret |
||
351 | diamond | 1032 | .ok: |
774 | Rus | 1033 | mov esi, msgControl |
1034 | call SysMsgBoardStr |
||
562 | serge | 1035 | |
774 | Rus | 1036 | mov edx, GLOB_CTRL |
1037 | call [ctrl.ctrl_read32] |
||
1038 | call dword2str |
||
1039 | call SysMsgBoardStr |
||
562 | serge | 1040 | |
774 | Rus | 1041 | mov esi, msgStatus |
1042 | call SysMsgBoardStr |
||
562 | serge | 1043 | |
774 | Rus | 1044 | mov edx, CTRL_STAT |
1045 | call [ctrl.ctrl_read32] |
||
1046 | push eax |
||
1047 | call dword2str |
||
1048 | call SysMsgBoardStr |
||
1049 | pop eax |
||
562 | serge | 1050 | |
774 | Rus | 1051 | test eax, CTRL_ST_CREADY |
1052 | jz .fail |
||
1053 | clc |
||
1054 | ret |
||
351 | diamond | 1055 | endp |
1056 | |||
1057 | align 4 |
||
378 | serge | 1058 | play: |
774 | Rus | 1059 | mov eax, 16 |
1060 | mov [ctrl.lvi_reg], eax |
||
1061 | mov edx, PCM_OUT_LVI_REG |
||
1062 | call [ctrl.ctrl_write8] |
||
351 | diamond | 1063 | |
774 | Rus | 1064 | mov edx, PCM_OUT_CR_REG |
1065 | mov ax, 0x1D |
||
1066 | call [ctrl.ctrl_write8] |
||
1067 | xor eax, eax |
||
1068 | ret |
||
351 | diamond | 1069 | |
1070 | align 4 |
||
378 | serge | 1071 | stop: |
774 | Rus | 1072 | mov edx, PCM_OUT_CR_REG |
1073 | mov ax, 0x0 |
||
1074 | call [ctrl.ctrl_write8] |
||
351 | diamond | 1075 | |
774 | Rus | 1076 | mov ax, 0x1c |
1077 | mov edx, PCM_OUT_SR_REG |
||
1078 | call [ctrl.ctrl_write16] |
||
1079 | xor eax, eax |
||
1080 | ret |
||
351 | diamond | 1081 | |
1082 | align 4 |
||
1083 | proc get_dev_info stdcall, p_info:dword |
||
774 | Rus | 1084 | virtual at esi |
1085 | CTRL_INFO CTRL_INFO |
||
1086 | end virtual |
||
351 | diamond | 1087 | |
774 | Rus | 1088 | mov esi, [p_info] |
1089 | mov eax, [ctrl.int_line] |
||
1090 | mov ebx, [ctrl.codec_io_base] |
||
1091 | mov ecx, [ctrl.ctrl_io_base] |
||
1092 | mov edx, [ctrl.codec_mem_base] |
||
1093 | mov edi, [ctrl.ctrl_mem_base] |
||
351 | diamond | 1094 | |
774 | Rus | 1095 | mov [CTRL_INFO.irq], eax |
1096 | mov [CTRL_INFO.codec_io_base], ebx |
||
1097 | mov [CTRL_INFO.ctrl_io_base], ecx |
||
1098 | mov [CTRL_INFO.codec_mem_base], edx |
||
1099 | mov [CTRL_INFO.ctrl_mem_base], edi |
||
351 | diamond | 1100 | |
774 | Rus | 1101 | mov eax, [codec.chip_id] |
1102 | mov [CTRL_INFO.codec_id], eax |
||
351 | diamond | 1103 | |
774 | Rus | 1104 | mov edx, GLOB_CTRL |
1105 | call [ctrl.ctrl_read32] |
||
1106 | mov [CTRL_INFO.glob_cntrl], eax |
||
351 | diamond | 1107 | |
774 | Rus | 1108 | mov edx, CTRL_STAT |
1109 | call [ctrl.ctrl_read32] |
||
1110 | mov [CTRL_INFO.glob_sta], eax |
||
351 | diamond | 1111 | |
774 | Rus | 1112 | mov ebx, [ctrl.pci_cmd] |
1113 | mov [CTRL_INFO.pci_cmd], ebx |
||
1114 | ret |
||
351 | diamond | 1115 | endp |
1116 | |||
1117 | align 4 |
||
1118 | proc set_callback stdcall, handler:dword |
||
774 | Rus | 1119 | mov eax, [handler] |
1120 | mov [ctrl.user_callback], eax |
||
1121 | ret |
||
351 | diamond | 1122 | endp |
1123 | |||
1124 | align 4 |
||
1125 | proc codec_read stdcall, ac_reg:dword ; reg = edx, reval = eax |
||
1126 | |||
774 | Rus | 1127 | mov edx, [ac_reg] |
351 | diamond | 1128 | |
774 | Rus | 1129 | mov ebx, edx |
1130 | shr ebx, 1 |
||
1131 | bt [codec.shadow_flag], ebx |
||
1132 | jc .use_shadow |
||
351 | diamond | 1133 | |
774 | Rus | 1134 | call [ctrl.codec_read16] ;change edx !!! |
1135 | mov ecx, eax |
||
351 | diamond | 1136 | |
774 | Rus | 1137 | mov edx, CTRL_STAT |
1138 | call [ctrl.ctrl_read32] |
||
1139 | test eax, CTRL_ST_RCS |
||
1140 | jz .read_ok |
||
351 | diamond | 1141 | |
774 | Rus | 1142 | mov edx, CTRL_STAT |
1143 | call [ctrl.ctrl_write32] |
||
1144 | xor eax,eax |
||
1145 | not eax ;timeout |
||
1146 | ret |
||
351 | diamond | 1147 | .read_ok: |
774 | Rus | 1148 | mov edx, [ac_reg] |
1149 | mov [codec.regs+edx], cx |
||
1150 | bts [codec.shadow_flag], ebx |
||
1151 | mov eax, ecx |
||
1152 | ret |
||
351 | diamond | 1153 | .use_shadow: |
774 | Rus | 1154 | movzx eax, word [codec.regs+edx] |
1155 | ret |
||
351 | diamond | 1156 | endp |
1157 | |||
1158 | align 4 |
||
1159 | proc codec_write stdcall, ac_reg:dword |
||
774 | Rus | 1160 | push eax |
1161 | call check_semafore |
||
1162 | and eax, eax |
||
1163 | jz .err |
||
1164 | pop eax |
||
351 | diamond | 1165 | |
774 | Rus | 1166 | mov esi, [ac_reg] |
1167 | mov edx, esi |
||
1168 | call [ctrl.codec_write16] |
||
1169 | mov [codec.regs+esi], ax |
||
1170 | shr esi, 1 |
||
1171 | bts [codec.shadow_flag], esi |
||
1172 | ret |
||
351 | diamond | 1173 | .err: |
774 | Rus | 1174 | pop eax |
1175 | ret |
||
351 | diamond | 1176 | endp |
1177 | |||
1178 | align 4 |
||
1179 | proc codec_check_ready |
||
1180 | |||
774 | Rus | 1181 | mov edx, CTRL_ST |
1182 | call [ctrl.ctrl_read32] |
||
1183 | and eax, CTRL_ST_CREADY |
||
1184 | jz .not_ready |
||
351 | diamond | 1185 | |
774 | Rus | 1186 | xor eax, wax |
1187 | inc eax |
||
1188 | ret |
||
351 | diamond | 1189 | .not_ready: |
774 | Rus | 1190 | xor eax, eax |
1191 | ret |
||
351 | diamond | 1192 | endp |
1193 | |||
1194 | align 4 |
||
1195 | proc check_semafore |
||
774 | Rus | 1196 | local counter:DWORD |
351 | diamond | 1197 | |
774 | Rus | 1198 | mov [counter], 100 |
351 | diamond | 1199 | .l1: |
774 | Rus | 1200 | mov edx, CTRL_CAS |
1201 | call [ctrl.ctrl_read8] |
||
1202 | and eax, CAS_FLAG |
||
1203 | jz .ok |
||
351 | diamond | 1204 | |
774 | Rus | 1205 | mov eax, 1 |
1206 | call StallExec |
||
1207 | sub [counter], 1 |
||
1208 | jnz .l1 |
||
1209 | xor eax, eax |
||
1210 | ret |
||
351 | diamond | 1211 | align 4 |
1212 | .ok: |
||
774 | Rus | 1213 | xor eax,eax |
1214 | inc eax |
||
1215 | ret |
||
351 | diamond | 1216 | endp |
1217 | |||
1218 | align 4 |
||
1219 | proc StallExec |
||
774 | Rus | 1220 | push ecx |
1221 | push edx |
||
1222 | push ebx |
||
1223 | push eax |
||
351 | diamond | 1224 | |
774 | Rus | 1225 | mov ecx, CPU_FREQ |
1226 | mul ecx |
||
1227 | mov ebx, eax ;low |
||
1228 | mov ecx, edx ;high |
||
1229 | rdtsc |
||
1230 | add ebx, eax |
||
1231 | adc ecx,edx |
||
351 | diamond | 1232 | @@: |
774 | Rus | 1233 | rdtsc |
1234 | sub eax, ebx |
||
1235 | sbb edx, ecx |
||
1236 | js @B |
||
351 | diamond | 1237 | |
774 | Rus | 1238 | pop eax |
1239 | pop ebx |
||
1240 | pop edx |
||
1241 | pop ecx |
||
1242 | ret |
||
351 | diamond | 1243 | endp |
1244 | |||
1245 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1246 | ; CONTROLLER IO functions |
||
1247 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1248 | |||
1249 | align 4 |
||
1250 | proc codec_io_r16 |
||
774 | Rus | 1251 | add edx, [ctrl.codec_io_base] |
1252 | in ax, dx |
||
1253 | ret |
||
351 | diamond | 1254 | endp |
1255 | |||
1256 | align 4 |
||
1257 | proc codec_io_w16 |
||
774 | Rus | 1258 | add edx, [ctrl.codec_io_base] |
1259 | out dx, ax |
||
1260 | ret |
||
351 | diamond | 1261 | endp |
1262 | |||
1263 | align 4 |
||
1264 | proc ctrl_io_r8 |
||
774 | Rus | 1265 | add edx, [ctrl.ctrl_io_base] |
1266 | in al, dx |
||
1267 | ret |
||
351 | diamond | 1268 | endp |
1269 | |||
1270 | align 4 |
||
1271 | proc ctrl_io_r16 |
||
774 | Rus | 1272 | add edx, [ctrl.ctrl_io_base] |
1273 | in ax, dx |
||
1274 | ret |
||
351 | diamond | 1275 | endp |
1276 | |||
1277 | align 4 |
||
1278 | proc ctrl_io_r32 |
||
774 | Rus | 1279 | add edx, [ctrl.ctrl_io_base] |
1280 | in eax, dx |
||
1281 | ret |
||
351 | diamond | 1282 | endp |
1283 | |||
1284 | align 4 |
||
1285 | proc ctrl_io_w8 |
||
774 | Rus | 1286 | add edx, [ctrl.ctrl_io_base] |
1287 | out dx, al |
||
1288 | ret |
||
351 | diamond | 1289 | endp |
1290 | |||
1291 | align 4 |
||
1292 | proc ctrl_io_w16 |
||
774 | Rus | 1293 | add edx, [ctrl.ctrl_io_base] |
1294 | out dx, ax |
||
1295 | ret |
||
351 | diamond | 1296 | endp |
1297 | |||
1298 | align 4 |
||
1299 | proc ctrl_io_w32 |
||
774 | Rus | 1300 | add edx, [ctrl.ctrl_io_base] |
1301 | out dx, eax |
||
1302 | ret |
||
351 | diamond | 1303 | endp |
1304 | |||
1305 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1306 | ; MEMORY MAPPED IO (os depended) |
||
1307 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
1308 | |||
1309 | align 4 |
||
1310 | proc codec_mem_r16 |
||
774 | Rus | 1311 | add edx, [ctrl.codec_mem_base] |
1312 | mov ax, word [edx] |
||
1313 | ret |
||
351 | diamond | 1314 | endp |
1315 | |||
1316 | align 4 |
||
1317 | proc codec_mem_w16 |
||
774 | Rus | 1318 | add edx, [ctrl.codec_mem_base] |
1319 | mov word [edx], ax |
||
1320 | ret |
||
351 | diamond | 1321 | endp |
1322 | |||
1323 | align 4 |
||
1324 | proc ctrl_mem_r8 |
||
774 | Rus | 1325 | add edx, [ctrl.ctrl_mem_base] |
1326 | mov al, [edx] |
||
1327 | ret |
||
351 | diamond | 1328 | endp |
1329 | |||
1330 | align 4 |
||
1331 | proc ctrl_mem_r16 |
||
774 | Rus | 1332 | add edx, [ctrl.ctrl_mem_base] |
1333 | mov ax, [edx] |
||
1334 | ret |
||
351 | diamond | 1335 | endp |
1336 | |||
1337 | align 4 |
||
1338 | proc ctrl_mem_r32 |
||
774 | Rus | 1339 | add edx, [ctrl.ctrl_mem_base] |
1340 | mov eax, [edx] |
||
1341 | ret |
||
351 | diamond | 1342 | endp |
1343 | |||
1344 | align 4 |
||
1345 | proc ctrl_mem_w8 |
||
774 | Rus | 1346 | add edx, [ctrl.ctrl_mem_base] |
1347 | mov [edx], al |
||
1348 | ret |
||
351 | diamond | 1349 | endp |
1350 | |||
1351 | align 4 |
||
1352 | proc ctrl_mem_w16 |
||
774 | Rus | 1353 | add edx, [ctrl.ctrl_mem_base] |
1354 | mov [edx], ax |
||
1355 | ret |
||
351 | diamond | 1356 | endp |
1357 | |||
1358 | align 4 |
||
1359 | proc ctrl_mem_w32 |
||
774 | Rus | 1360 | add edx, [ctrl.ctrl_mem_base] |
1361 | mov [edx], eax |
||
1362 | ret |
||
351 | diamond | 1363 | endp |
1364 | |||
1365 | align 4 |
||
1366 | dword2str: |
||
1367 | mov esi, hex_buff |
||
1368 | mov ecx, -8 |
||
1369 | @@: |
||
1370 | rol eax, 4 |
||
1371 | mov ebx, eax |
||
1372 | and ebx, 0x0F |
||
1373 | mov bl, [ebx+hexletters] |
||
1374 | mov [8+esi+ecx], bl |
||
1375 | inc ecx |
||
1376 | jnz @B |
||
1377 | ret |
||
1378 | |||
1379 | hexletters db '0123456789ABCDEF' |
||
1380 | hex_buff db 8 dup(0),13,10,0 |
||
1381 | |||
1382 | |||
1383 | include "codec.inc" |
||
1384 | |||
1385 | align 4 |
||
1386 | devices dd (CTRL_ICH shl 16)+VID_INTEL,msg_ICH, set_ICH |
||
774 | Rus | 1387 | dd (CTRL_ICH0 shl 16)+VID_INTEL,msg_ICH0,set_ICH |
1388 | dd (CTRL_ICH2 shl 16)+VID_INTEL,msg_ICH2,set_ICH |
||
1389 | dd (CTRL_ICH3 shl 16)+VID_INTEL,msg_ICH3,set_ICH |
||
1390 | dd (CTRL_ICH4 shl 16)+VID_INTEL,msg_ICH4,set_ICH4 |
||
1391 | dd (CTRL_ICH5 shl 16)+VID_INTEL,msg_ICH5,set_ICH4 |
||
1392 | dd (CTRL_ICH6 shl 16)+VID_INTEL,msg_ICH6,set_ICH4 |
||
1393 | dd (CTRL_ICH7 shl 16)+VID_INTEL,msg_ICH7,set_ICH4 |
||
351 | diamond | 1394 | |
774 | Rus | 1395 | dd (CTRL_NFORCE shl 16)+VID_NVIDIA,msg_NForce, set_ICH |
1396 | dd (CTRL_NFORCE2 shl 16)+VID_NVIDIA,msg_NForce2,set_ICH |
||
1397 | dd (CTRL_NFORCE3 shl 16)+VID_NVIDIA,msg_NForce3,set_ICH |
||
1398 | dd (CTRL_MCP04 shl 16)+VID_NVIDIA,msg_MCP04,set_ICH |
||
1399 | dd (CTRL_CK804 shl 16)+VID_NVIDIA,msg_CK804,set_ICH |
||
1400 | dd (CTRL_CK8 shl 16)+VID_NVIDIA,msg_CK8,set_ICH |
||
1401 | dd (CTRL_CK8S shl 16)+VID_NVIDIA,msg_CK8S,set_ICH |
||
1402 | dd (CTRL_MCP51 shl 16)+VID_NVIDIA,msg_MCP51,set_ICH |
||
351 | diamond | 1403 | |
774 | Rus | 1404 | dd 0 ;terminator |
351 | diamond | 1405 | |
1406 | |||
465 | serge | 1407 | version dd (5 shl 16) or (API_VERSION and 0xFFFF) |
1408 | |||
562 | serge | 1409 | msg_ICH db '802801AA (ICH)', 13,10, 0 |
1410 | msg_ICH0 db '802801AB (ICH0)', 13,10, 0 |
||
1411 | msg_ICH2 db '802801BA (ICH2)', 13,10, 0 |
||
1412 | msg_ICH3 db '802801CA (ICH3)', 13,10, 0 |
||
1413 | msg_ICH4 db '802801DB (ICH4)', 13,10, 0 |
||
1414 | msg_ICH5 db '802801EB (ICH5)', 13,10, 0 |
||
1415 | msg_ICH6 db '802801FB (ICH6)', 13,10, 0 |
||
1416 | msg_ICH7 db '802801GB (ICH7)', 13,10, 0 |
||
1417 | msg_Intel db 'Intel ', 0 |
||
351 | diamond | 1418 | |
1419 | msg_NForce db 'NForce', 13,10, 0 |
||
1420 | msg_NForce2 db 'NForce 2', 13,10, 0 |
||
1421 | msg_NForce3 db 'NForce 3', 13,10, 0 |
||
1422 | msg_MCP04 db 'NForce MCP04',13,10, 0 |
||
1423 | msg_CK804 db 'NForce CK804',13,10, 0 |
||
1424 | msg_CK8 db 'NForce CK8', 13,10, 0 |
||
1425 | msg_CK8S db 'NForce CK8S', 13,10, 0 |
||
1426 | msg_MCP51 db 'NForce MCP51',13,10, 0 |
||
1427 | |||
1428 | msg_NVidia db 'NVidia', 0 |
||
1429 | |||
1430 | szKernel db 'KERNEL', 0 |
||
1431 | sz_sound_srv db 'SOUND',0 |
||
1432 | |||
1433 | msgInit db 'detect hardware...',13,10,0 |
||
1434 | msgFail db 'device not found',13,10,0 |
||
1435 | msgAttchIRQ db 'IRQ line not supported', 13,10, 0 |
||
1436 | msgInvIRQ db 'IRQ line not assigned or invalid', 13,10, 0 |
||
1437 | msgPlay db 'start play', 13,10,0 |
||
1438 | msgStop db 'stop play', 13,10,0 |
||
562 | serge | 1439 | ;msgNotify db 'call notify',13,10,0 |
774 | Rus | 1440 | msgIRQ db 'AC97 IRQ', 13,10,0 |
351 | diamond | 1441 | msgInitCtrl db 'init controller',13,10,0 |
562 | serge | 1442 | ;msgInitCodec db 'init codec',13,10,0 |
566 | serge | 1443 | msgPrimBuff db 'create primary buffer ...',0 |
1444 | msgDone db 'done',13,10,0 |
||
1445 | msgRemap db 'Remap IRQ',13,10,0 |
||
562 | serge | 1446 | ;msgReg db 'set service handler',13,10,0 |
774 | Rus | 1447 | msgOk db 'service installed',13,10,0 |
351 | diamond | 1448 | msgCold db 'cold reset',13,10,0 |
1449 | msgWarm db 'warm reset',13,10,0 |
||
1450 | msgWRFail db 'warm reset failed',13,10,0 |
||
1451 | msgCRFail db 'cold reset failed',13,10,0 |
||
1452 | msgCFail db 'codec not ready',13,10,0 |
||
1453 | msgResetOk db 'reset complete',13,10,0 |
||
1454 | msgStatus db 'global status ',0 |
||
1455 | msgControl db 'global control ',0 |
||
562 | serge | 1456 | msgPciCmd db 'PCI command ',0 |
1457 | msgPciStat db 'PCI status ',0 |
||
1458 | msgCtrlIsaIo db 'controller io base ',0 |
||
1459 | msgMixIsaIo db 'codec io base ',0 |
||
1460 | msgCtrlMMIo db 'controller mmio base ',0 |
||
1461 | msgMixMMIo db 'codec mmio base ',0 |
||
567 | serge | 1462 | msgIrqMap db 'AC97 irq map as ',0 |
351 | diamond | 1463 | |
1464 | section '.data' data readable writable align 16 |
||
1465 | |||
774 | Rus | 1466 | pcmout_bdl rq 32 |
1467 | buff_list rd 32 |
||
351 | diamond | 1468 | |
1469 | codec CODEC |
||
1470 | ctrl AC_CNTRL |
||
1471 | |||
1472 | lpc_bus rd 1 |
||
1473 | civ_val rd 1 |