Subversion Repositories Kolibri OS

Rev

Rev 741 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. format MS COFF
  9.  
  10.  
  11. include 'proc32.inc'
  12. include 'imports.inc'
  13.  
  14. API_VERSION     equ 0x01000100
  15.  
  16. DEBUG           equ 1
  17. DEBUG_IRQ       equ 0
  18.  
  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
  22.  
  23.  
  24. ;irq 0,1,2,8,12,13 íåäîñòóïíû
  25. ;                   FEDCBA9876543210
  26. VALID_IRQ       equ 1100111011111000b
  27. ATTCH_IRQ       equ 0000111010100000b
  28.  
  29. if USE_COM_IRQ
  30. ATTCH_IRQ       equ 0000111010111000b
  31. end if
  32.  
  33. CPU_FREQ        equ  2600d
  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.  
  68. PCM_4 equ BIT20
  69. PCM_6 equ BIT21
  70.  
  71. VID_INTEL         equ 0x8086
  72. VID_NVIDIA        equ 0x10DE
  73.  
  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
  82.  
  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
  91.  
  92.  
  93. PCM_OUT_BDL       equ  0x10  ; PCM out buffer descriptors list
  94. PCM_OUT_CR_REG    equ  0x1b  ; PCM out Control Register
  95. PCM_OUT_LVI_REG   equ  0x15  ; PCM last valid index
  96. PCM_OUT_SR_REG    equ  0x16  ; PCM out Status register
  97. PCM_OUT_PIV_REG   equ  0x1a
  98. PCM_OUT_CIV_REG   equ  0x14  ; PCM out current index
  99.  
  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
  103.  
  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
  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
  112.  
  113. GLOB_CTRL         equ  0x2C  ;   Global Control
  114. CTRL_STAT         equ  0x30  ;   Global Status
  115. CTRL_CAS          equ  0x34  ;   Codec Access Semiphore
  116.  
  117. CAS_FLAG          equ  0x01  ;   Codec Access Semiphore Bit
  118.  
  119. CTRL_ST_CREADY    equ  BIT8+BIT9+BIT28 ;   Primary Codec Ready
  120.  
  121. CTRL_ST_RCS       equ  0x00008000  ;   Read Completion Status
  122.  
  123. CTRL_CNT_CRIE     equ  BIT4+BIT5+BIT6  ;   Codecs Resume Interrupt Enable
  124. CTRL_CNT_AC_OFF   equ  0x00000008  ;   ACLINK Off
  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
  128.  
  129. CODEC_REG_POWERDOWN   equ 0x26
  130. CODEC_REG_ST          equ 0x26
  131.  
  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
  138. DEV_SET_MASTERVOL     equ  6
  139. DEV_GET_MASTERVOL     equ  7
  140. DEV_GET_INFO          equ  8
  141.  
  142. struc AC_CNTRL              ;AC controller base class
  143. { .bus                dd ?
  144.   .devfn              dd ?
  145.  
  146.   .vendor             dd ?
  147.   .dev_id             dd ?
  148.   .pci_cmd            dd ?
  149.   .pci_stat           dd ?
  150.  
  151.   .codec_io_base      dd ?
  152.   .codec_mem_base     dd ?
  153.  
  154.   .ctrl_io_base       dd ?
  155.   .ctrl_mem_base      dd ?
  156.   .cfg_reg            dd ?
  157.   .int_line           dd ?
  158.  
  159.   .vendor_ids         dd ?    ;vendor id string
  160.   .ctrl_ids           dd ?    ;hub id string
  161.  
  162.   .buffer             dd ?
  163.  
  164.   .notify_pos         dd ?
  165.   .notify_task        dd ?
  166.  
  167.   .lvi_reg            dd ?
  168.   .ctrl_setup         dd ?
  169.   .user_callback      dd ?
  170.   .codec_read16       dd ?
  171.   .codec_write16      dd ?
  172.  
  173.   .ctrl_read8         dd ?
  174.   .ctrl_read16        dd ?
  175.   .ctrl_read32        dd ?
  176.  
  177.   .ctrl_write8        dd ?
  178.   .ctrl_write16       dd ?
  179.   .ctrl_write32       dd ?
  180. }
  181.  
  182. struc CODEC                ;Audio Chip base class
  183. {
  184.   .chip_id            dd ?
  185.   .flags              dd ?
  186.   .status             dd ?
  187.  
  188.   .ac_vendor_ids      dd ?    ;ac vendor id string
  189.   .chip_ids           dd ?    ;chip model string
  190.  
  191.   .shadow_flag        dd ?
  192.                       dd ?
  193.  
  194.   .regs               dw ?     ; codec registers
  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
  201.   .reg_mic_vol        dw ?     ;0x0E
  202.   .reg_line_in_vol    dw ?     ;0x10
  203.   .reg_cd_vol         dw ?     ;0x12
  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
  210.   .reg_gen            dw ?     ;0x20
  211.   .reg_3d_ctrl        dw ?     ;0X22
  212.   .reg_page           dw ?     ;0X24
  213.   .reg_powerdown      dw ?     ;0x26
  214.   .reg_ext_audio      dw ?     ;0x28
  215.   .reg_ext_st         dw ?     ;0x2a
  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
  220.                       dw ?     ;0x34
  221.   .reg_cent_lfe_vol   dw ?     ;0x36
  222.   .reg_surr_vol       dw ?     ;0x38
  223.   .reg_spdif_ctrl     dw ?     ;0x3A
  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
  256.   .reg_vendor_id_1    dw ?     ;0x7C
  257.   .reg_vendor_id_2    dw ?     ;0x7E
  258.  
  259.  
  260.   .reset              dd ?    ;virual
  261.   .set_master_vol     dd ?
  262. }
  263.  
  264. struc CTRL_INFO
  265. {   .pci_cmd          dd ?
  266.     .irq              dd ?
  267.     .glob_cntrl       dd ?
  268.     .glob_sta         dd ?
  269.     .codec_io_base    dd ?
  270.     .ctrl_io_base     dd ?
  271.     .codec_mem_base   dd ?
  272.     .ctrl_mem_base    dd ?
  273.     .codec_id         dd ?
  274. }
  275.  
  276. struc IOCTL
  277. {  .handle            dd ?
  278.    .io_code           dd ?
  279.    .input             dd ?
  280.    .inp_size          dd ?
  281.    .output            dd ?
  282.    .out_size          dd ?
  283. }
  284.  
  285. virtual at 0
  286.   IOCTL IOCTL
  287. end virtual
  288.  
  289. EVENT_NOTIFY    equ 0x00000200
  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.  
  299.            cmp [state], 1
  300.            jne .stop
  301.  
  302.      if DEBUG
  303.            mov esi, msgInit
  304.            call SysMsgBoardStr
  305.      end if
  306.  
  307.            call detect_controller
  308.            test eax, eax
  309.            jz .fail
  310.  
  311.      if DEBUG
  312.            mov esi,[ctrl.vendor_ids]
  313.            call SysMsgBoardStr
  314.            mov esi, [ctrl.ctrl_ids]
  315.            call SysMsgBoardStr
  316.  
  317.      end if
  318.  
  319.            call init_controller
  320.            test eax, eax
  321.            jz .fail
  322.  
  323.            call init_codec
  324.            test eax, eax
  325.            jz .fail
  326.  
  327.            call reset_controller
  328.            call setup_codec
  329.  
  330.            mov esi, msgPrimBuff
  331.            call SysMsgBoardStr
  332.            call create_primary_buff
  333.            mov esi, msgDone
  334.            call SysMsgBoardStr
  335.  
  336.   if IRQ_REMAP
  337.            pushf
  338.            cli
  339.  
  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
  347. .skip
  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
  354.  
  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
  363.   end if
  364.  
  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
  374.  
  375.            stdcall AttachIntHandler, ebx, ac97_irq, dword 0
  376. .reg:
  377.            stdcall RegService, sz_sound_srv, service_proc
  378.            ret
  379. .fail:
  380.      if DEBUG
  381.            mov esi, msgFail
  382.            call SysMsgBoardStr
  383.      end if
  384.            xor eax, eax
  385.            ret
  386. .fail_msg:
  387.            call SysMsgBoardStr
  388.            xor eax, eax
  389.            ret
  390. .stop:
  391.            call stop
  392.            xor eax, eax
  393.            ret
  394. endp
  395.  
  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
  402.  
  403. align 4
  404. proc service_proc stdcall, ioctl:dword
  405.  
  406.            mov edi, [ioctl]
  407.            mov eax, [edi+io_code]
  408.  
  409.            cmp eax, SRV_GETVERSION
  410.            jne @F
  411.  
  412.            mov eax, [edi+output]
  413.            cmp [edi+out_size], 4
  414.            jne .fail
  415.  
  416.            mov [eax], dword API_VERSION
  417.            xor eax, eax
  418.            ret
  419. @@:
  420.            cmp eax, DEV_PLAY
  421.            jne @F
  422.      if DEBUG
  423.            mov esi, msgPlay
  424.            call SysMsgBoardStr
  425.      end if
  426.            call play
  427.            ret
  428. @@:
  429.            cmp eax, DEV_STOP
  430.            jne @F
  431.      if DEBUG
  432.            mov esi, msgStop
  433.            call SysMsgBoardStr
  434.      end if
  435.            call stop
  436.            ret
  437. @@:
  438.            cmp eax, DEV_CALLBACK
  439.            jne @F
  440.            mov ebx, [edi+input]
  441.            stdcall set_callback, [ebx]
  442.            ret
  443. @@:
  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
  450. @@:
  451.            cmp eax, DEV_GET_MASTERVOL
  452.            jne @F
  453.            mov ebx, [edi+output]
  454.            stdcall get_master_vol, ebx
  455.            ret
  456. ;@@:
  457. ;           cmp eax, DEV_GET_INFO
  458. ;           jne @F
  459. ;           mov ebx, [edi+output]
  460. ;           stdcall get_dev_info, ebx
  461. ;           ret
  462. @@:
  463. .fail:
  464.            or eax, -1
  465.            ret
  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.  
  478.      if DEBUG_IRQ
  479.            mov esi, msgIRQ
  480.            call SysMsgBoardStr
  481.      end if
  482.  
  483.            mov edx, PCM_OUT_CR_REG
  484.            mov al, 0x10;               0x10
  485.            call [ctrl.ctrl_write8]
  486.  
  487.            mov ax, 0x1c
  488.            mov edx, PCM_OUT_SR_REG
  489.            call [ctrl.ctrl_write16]
  490.  
  491.            mov edx, PCM_OUT_CIV_REG
  492.            call [ctrl.ctrl_read8]
  493.  
  494.            and eax, 0x1F
  495.            cmp eax, [civ_val]
  496.            je .skip
  497.  
  498.            mov [civ_val], eax
  499.            dec eax
  500.            and eax, 0x1F
  501.            mov [ctrl.lvi_reg], eax
  502.  
  503.            mov edx, PCM_OUT_LVI_REG
  504.            call [ctrl.ctrl_write8]
  505.  
  506.            mov edx, PCM_OUT_CR_REG
  507.            mov ax, 0x11              ;0x1D
  508.            call [ctrl.ctrl_write8]
  509.  
  510.            mov eax, [civ_val]
  511.            add eax, 1
  512.            and eax, 31
  513.            mov ebx, dword [buff_list+eax*4]
  514.  
  515.            cmp [ctrl.user_callback], 0
  516.            je @f
  517.  
  518.            stdcall [ctrl.user_callback], ebx
  519. @@:
  520.            ret
  521.  
  522. .skip:
  523.            mov edx, PCM_OUT_CR_REG
  524.            mov ax, 0x11               ;0x1D
  525.            call [ctrl.ctrl_write8]
  526.            ret
  527. endp
  528.  
  529. align 4
  530. proc create_primary_buff
  531.  
  532.            stdcall KernelAlloc, 0x10000
  533.            mov [ctrl.buffer], eax
  534.  
  535.            mov edi, eax
  536.            mov ecx, 0x10000/4
  537.            xor eax, eax
  538.            cld
  539.            rep stosd
  540.  
  541.            mov eax, [ctrl.buffer]
  542.            call GetPgAddr
  543.  
  544.            mov ebx, 0xC0002000
  545.            mov ecx, 4
  546.            mov edi, pcmout_bdl
  547. @@:
  548.            mov [edi], eax
  549.            mov [edi+4], ebx
  550.  
  551.            mov [edi+32], eax
  552.            mov [edi+4+32], ebx
  553.  
  554.            mov [edi+64], eax
  555.            mov [edi+4+64], ebx
  556.  
  557.            mov [edi+96], eax
  558.            mov [edi+4+96], ebx
  559.  
  560.            mov [edi+128], eax
  561.            mov [edi+4+128], ebx
  562.  
  563.            mov [edi+160], eax
  564.            mov [edi+4+160], ebx
  565.  
  566.            mov [edi+192], eax
  567.            mov [edi+4+192], ebx
  568.  
  569.            mov [edi+224], eax
  570.            mov [edi+4+224], ebx
  571.  
  572.            add eax, 0x4000
  573.            add edi, 8
  574.            loop @B
  575.  
  576.            mov edi, buff_list
  577.            mov eax, [ctrl.buffer]
  578.            mov ecx, 4
  579. @@:
  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
  588.  
  589.            add eax, 0x4000
  590.            add edi, 4
  591.            loop @B
  592.  
  593.            mov eax, pcmout_bdl
  594.            mov ebx, eax
  595.            call GetPgAddr     ;eax
  596.            and ebx, 0xFFF
  597.            add eax, ebx
  598.  
  599.            mov edx, PCM_OUT_BDL
  600.            call [ctrl.ctrl_write32]
  601.  
  602.            mov eax, 16
  603.            mov [ctrl.lvi_reg], eax
  604.            mov edx, PCM_OUT_LVI_REG
  605.            call [ctrl.ctrl_write8]
  606.            ret
  607. endp
  608.  
  609. align 4
  610. proc detect_controller
  611.            locals
  612.              last_bus dd ?
  613.              bus      dd ?
  614.              devfn    dd ?
  615.            endl
  616.  
  617.            xor eax, eax
  618.            mov [bus], eax
  619.            inc eax
  620.            call PciApi
  621.            cmp eax, -1
  622.            je .err
  623.  
  624.            mov [last_bus], eax
  625.  
  626. .next_bus:
  627.            and [devfn], 0
  628. .next_dev:
  629.            stdcall PciRead32, [bus], [devfn], dword 0
  630.            test eax, eax
  631.            jz .next
  632.            cmp eax, -1
  633.            je .next
  634.  
  635.            mov edi, devices
  636. @@:
  637.            mov ebx, [edi]
  638.            test ebx, ebx
  639.            jz .next
  640.  
  641.            cmp eax, ebx
  642.            je .found
  643.            add edi, 12
  644.            jmp @B
  645. .next:
  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
  656. .found:
  657.            mov ebx, [bus]
  658.            mov [ctrl.bus], ebx
  659.  
  660.            mov ecx, [devfn]
  661.            mov [ctrl.devfn], ecx
  662.  
  663.            mov edx, eax
  664.            and edx, 0xFFFF
  665.            mov [ctrl.vendor], edx
  666.            shr eax, 16
  667.            mov [ctrl.dev_id], eax
  668.  
  669.            mov ebx, [edi+4]
  670.            mov [ctrl.ctrl_ids], ebx
  671.            mov esi, [edi+8]
  672.            mov [ctrl.ctrl_setup], esi
  673.  
  674.            cmp edx, VID_INTEL
  675.            jne @F
  676.            mov [ctrl.vendor_ids], msg_Intel
  677.            ret
  678. @@:
  679.            cmp edx, VID_NVIDIA
  680.            jne @F
  681.            mov [ctrl.vendor_ids], msg_NVidia
  682.            ret
  683. @@:
  684. .err:
  685.            xor eax, eax
  686.            mov [ctrl.vendor_ids], eax     ;something  wrong ?
  687.            ret
  688. endp
  689.  
  690. align 4
  691. proc init_controller
  692.  
  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
  699.  
  700.            mov esi, msgPciCmd
  701.            call SysMsgBoardStr
  702.            call dword2str
  703.            call SysMsgBoardStr
  704.  
  705.            mov esi, msgPciStat
  706.            call SysMsgBoardStr
  707.            mov eax, [ctrl.pci_stat]
  708.            call dword2str
  709.            call SysMsgBoardStr
  710.  
  711.            mov esi, msgMixIsaIo
  712.            call SysMsgBoardStr
  713.  
  714.            stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x10
  715.  
  716.            call dword2str
  717.            call SysMsgBoardStr
  718.  
  719.            and eax,0xFFFE
  720.            mov [ctrl.codec_io_base], eax
  721.  
  722.            mov esi, msgCtrlIsaIo
  723.            call SysMsgBoardStr
  724.  
  725.            stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x14
  726.  
  727.            call dword2str
  728.            call SysMsgBoardStr
  729.  
  730.            and eax, 0xFFC0
  731.            mov [ctrl.ctrl_io_base], eax
  732.  
  733.            mov esi, msgMixMMIo
  734.            call SysMsgBoardStr
  735.  
  736.            stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x18
  737.            mov [ctrl.codec_mem_base], eax
  738.  
  739.            call dword2str
  740.            call SysMsgBoardStr
  741.  
  742.            mov esi, msgCtrlMMIo
  743.            call SysMsgBoardStr
  744.  
  745.            stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x1C
  746.            mov [ctrl.ctrl_mem_base], eax
  747.  
  748.            call dword2str
  749.            call SysMsgBoardStr
  750.  
  751. if 0
  752.  
  753. ;;patch for some ugly BIOS  ICH-ICH5 compatible
  754.            cmp [ctrl.vendor], VID_INTEL
  755.            jne .default
  756.  
  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
  767. end if
  768.  
  769. .default:
  770.            stdcall PciRead32, [ctrl.bus], [ctrl.devfn], dword 0x3C
  771.            and eax, 0xFF
  772. @@:
  773.            mov [ctrl.int_line], eax
  774.  
  775.            stdcall PciRead8, [ctrl.bus], [ctrl.devfn], dword 0x41
  776.            and eax, 0xFF
  777.            mov [ctrl.cfg_reg], eax
  778.  
  779.            call [ctrl.ctrl_setup]
  780.            xor eax, eax
  781.            inc eax
  782.            ret
  783. endp
  784.  
  785. align 4
  786. proc set_ICH
  787.            mov [ctrl.codec_read16],  codec_io_r16    ;virtual
  788.            mov [ctrl.codec_write16], codec_io_w16    ;virtual
  789.  
  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
  793.  
  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
  798. endp
  799.  
  800. PG_SW            equ 0x003
  801. PG_NOCACHE       equ 0x018
  802.  
  803. align 4
  804. proc set_ICH4
  805.  
  806.            stdcall MapIoMem,[ctrl.codec_mem_base],0x1000,PG_SW+PG_NOCACHE
  807.            mov [ctrl.codec_mem_base], eax
  808.  
  809.            stdcall MapIoMem,[ctrl.ctrl_mem_base],0x1000,PG_SW+PG_NOCACHE
  810.            mov [ctrl.ctrl_mem_base], eax
  811.  
  812.            mov [ctrl.codec_read16],  codec_mem_r16    ;virtual
  813.            mov [ctrl.codec_write16], codec_mem_w16    ;virtual
  814.  
  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
  818.  
  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
  823. endp
  824.  
  825. align 4
  826. proc reset_controller
  827.  
  828.            xor eax, eax
  829.            mov edx, PCM_IN_CR_REG
  830.            call [ctrl.ctrl_write8]
  831.  
  832.            mov edx, PCM_OUT_CR_REG
  833.            call [ctrl.ctrl_write8]
  834.  
  835.            mov edx, MC_IN_CR_REG
  836.            call [ctrl.ctrl_write8]
  837.  
  838.            mov eax, RR
  839.            mov edx, PCM_IN_CR_REG
  840.            call [ctrl.ctrl_write8]
  841.  
  842.            mov edx, PCM_OUT_CR_REG
  843.            call [ctrl.ctrl_write8]
  844.  
  845.            mov edx, MC_IN_CR_REG
  846.            call [ctrl.ctrl_write8]
  847.            ret
  848. endp
  849.  
  850. align 4
  851. proc init_codec
  852.            locals
  853.              counter dd ?
  854.            endl
  855.  
  856.            mov esi, msgControl
  857.            call SysMsgBoardStr
  858.  
  859.            mov edx, GLOB_CTRL
  860.            call [ctrl.ctrl_read32]
  861.            call dword2str
  862.            call SysMsgBoardStr
  863.  
  864.            mov esi, msgStatus
  865.            call SysMsgBoardStr
  866.  
  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
  875.  
  876.            test eax, CTRL_ST_CREADY
  877.            jnz .ready
  878.  
  879.            call reset_codec
  880.            test eax, eax
  881.            jz .err
  882.  
  883. .ready:
  884.            xor edx, edx     ;ac_reg_0
  885.            call [ctrl.codec_write16]
  886.  
  887.            xor eax, eax
  888.            mov edx, CODEC_REG_POWERDOWN
  889.            call [ctrl.codec_write16]
  890.  
  891.            mov [counter], 200     ; total 200*5 ms = 1s
  892. .wait:
  893.            mov eax, 5000   ; wait 5 ms
  894.            call StallExec
  895.  
  896.            mov edx, CODEC_REG_POWERDOWN
  897.            call [ctrl.codec_read16]
  898.            and eax, 0x0F
  899.            cmp eax, 0x0F
  900.            jz .done
  901.  
  902.            sub [counter] , 1
  903.            jnz .wait
  904. .err:
  905.            xor eax, eax        ; timeout error
  906.            ret
  907. .done:
  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
  913.  
  914.            call detect_codec
  915.  
  916.            xor eax, eax
  917.            inc eax
  918.            ret
  919. endp
  920.  
  921. align 4
  922. proc reset_codec
  923.            mov edx, GLOB_CTRL
  924.            call [ctrl.ctrl_read32]
  925.  
  926.            test eax, 0x02
  927.            jz .cold
  928.  
  929.            call warm_reset
  930.            jnc .ok
  931. .cold:
  932.            call cold_reset
  933.            jnc .ok
  934.  
  935.      if DEBUG
  936.            mov esi, msgCFail
  937.            call SysMsgBoardStr
  938.            end if
  939.            xor eax, eax     ; timeout error
  940.            ret
  941. .ok:
  942.      if DEBUG
  943.            mov esi, msgResetOk
  944.            call SysMsgBoardStr
  945.      end if
  946.  
  947.            xor eax, eax
  948.            inc eax
  949.            ret
  950. endp
  951.  
  952. align 4
  953. proc warm_reset
  954.            locals
  955.              counter dd ?
  956.            endl
  957.  
  958.            mov eax, 0x06
  959.            mov edx, GLOB_CTRL
  960.            call [ctrl.ctrl_write32]
  961.  
  962.      if DEBUG
  963.            mov esi, msgWarm
  964.            call SysMsgBoardStr
  965.      end if
  966.  
  967.            mov [counter], 10    ; total 10*100 ms = 1s
  968. .wait:
  969.            mov eax, 100000    ; wait 100 ms
  970.            call StallExec
  971.  
  972.            mov edx, CTRL_STAT
  973.            call [ctrl.ctrl_read32]
  974.            test eax, CTRL_ST_CREADY
  975.            jnz .ok
  976.  
  977.            dec [counter]
  978.            jnz .wait
  979.  
  980.      if DEBUG
  981.            mov esi, msgWRFail
  982.            call SysMsgBoardStr
  983.      end if
  984. .fail:
  985.            stc
  986.            ret
  987. .ok:
  988.            clc
  989.            ret
  990. endp
  991.  
  992. align 4
  993. proc cold_reset
  994.            locals
  995.              counter dd ?
  996.            endl
  997.  
  998.            mov eax, 0x02
  999.            mov edx, GLOB_CTRL
  1000.            call [ctrl.ctrl_write32]
  1001.  
  1002.      if DEBUG
  1003.            mov esi, msgCold
  1004.            call SysMsgBoardStr
  1005.      end if
  1006.  
  1007.            mov eax, 400000     ; wait 400 ms
  1008.            call StallExec
  1009.  
  1010.            mov [counter], 16    ; total 20*100 ms = 2s
  1011. .wait:
  1012.  
  1013.            mov edx, CTRL_STAT
  1014.            call [ctrl.ctrl_read32]
  1015.            test eax, CTRL_ST_CREADY
  1016.            jnz .ok
  1017.  
  1018.            mov eax, 100000    ; wait 100 ms
  1019.            call StallExec
  1020.  
  1021.            dec [counter]
  1022.            jnz .wait
  1023.  
  1024.      if DEBUG
  1025.            mov esi, msgCRFail
  1026.            call SysMsgBoardStr
  1027.      end if
  1028.  
  1029. .fail:
  1030.            stc
  1031.            ret
  1032. .ok:
  1033.            mov esi, msgControl
  1034.            call SysMsgBoardStr
  1035.  
  1036.            mov edx, GLOB_CTRL
  1037.            call [ctrl.ctrl_read32]
  1038.            call dword2str
  1039.            call SysMsgBoardStr
  1040.  
  1041.            mov esi, msgStatus
  1042.            call SysMsgBoardStr
  1043.  
  1044.            mov edx, CTRL_STAT
  1045.            call [ctrl.ctrl_read32]
  1046.            push eax
  1047.            call dword2str
  1048.            call SysMsgBoardStr
  1049.            pop eax
  1050.  
  1051.            test eax, CTRL_ST_CREADY
  1052.            jz .fail
  1053.            clc
  1054.            ret
  1055. endp
  1056.  
  1057. align 4
  1058. play:
  1059.            mov eax, 16
  1060.            mov [ctrl.lvi_reg], eax
  1061.            mov edx, PCM_OUT_LVI_REG
  1062.            call [ctrl.ctrl_write8]
  1063.  
  1064.            mov edx, PCM_OUT_CR_REG
  1065.            mov ax, 0x1D
  1066.            call [ctrl.ctrl_write8]
  1067.            xor eax, eax
  1068.            ret
  1069.  
  1070. align 4
  1071. stop:
  1072.            mov edx, PCM_OUT_CR_REG
  1073.            mov ax, 0x0
  1074.            call [ctrl.ctrl_write8]
  1075.  
  1076.            mov ax, 0x1c
  1077.            mov edx, PCM_OUT_SR_REG
  1078.            call [ctrl.ctrl_write16]
  1079.            xor eax, eax
  1080.            ret
  1081.  
  1082. align 4
  1083. proc get_dev_info stdcall, p_info:dword
  1084.            virtual at esi
  1085.              CTRL_INFO CTRL_INFO
  1086.            end virtual
  1087.  
  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]
  1094.  
  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
  1100.  
  1101.            mov eax, [codec.chip_id]
  1102.            mov [CTRL_INFO.codec_id], eax
  1103.  
  1104.            mov edx, GLOB_CTRL
  1105.            call [ctrl.ctrl_read32]
  1106.            mov [CTRL_INFO.glob_cntrl], eax
  1107.  
  1108.            mov edx, CTRL_STAT
  1109.            call [ctrl.ctrl_read32]
  1110.            mov [CTRL_INFO.glob_sta], eax
  1111.  
  1112.            mov ebx, [ctrl.pci_cmd]
  1113.            mov [CTRL_INFO.pci_cmd], ebx
  1114.            ret
  1115. endp
  1116.  
  1117. align 4
  1118. proc set_callback stdcall, handler:dword
  1119.            mov eax, [handler]
  1120.            mov [ctrl.user_callback], eax
  1121.            ret
  1122. endp
  1123.  
  1124. align 4
  1125. proc codec_read stdcall, ac_reg:dword      ; reg = edx, reval = eax
  1126.  
  1127.            mov edx, [ac_reg]
  1128.  
  1129.            mov ebx, edx
  1130.            shr ebx, 1
  1131.            bt [codec.shadow_flag], ebx
  1132.            jc .use_shadow
  1133.  
  1134.            call [ctrl.codec_read16]  ;change edx !!!
  1135.            mov ecx, eax
  1136.  
  1137.            mov edx, CTRL_STAT
  1138.            call [ctrl.ctrl_read32]
  1139.            test eax, CTRL_ST_RCS
  1140.            jz .read_ok
  1141.  
  1142.            mov edx, CTRL_STAT
  1143.            call [ctrl.ctrl_write32]
  1144.            xor eax,eax
  1145.            not eax  ;timeout
  1146.            ret
  1147. .read_ok:
  1148.            mov edx, [ac_reg]
  1149.            mov [codec.regs+edx], cx
  1150.            bts [codec.shadow_flag], ebx
  1151.            mov eax, ecx
  1152.            ret
  1153. .use_shadow:
  1154.            movzx eax, word [codec.regs+edx]
  1155.            ret
  1156. endp
  1157.  
  1158. align 4
  1159. proc codec_write stdcall, ac_reg:dword
  1160.            push eax
  1161.            call check_semafore
  1162.            and eax, eax
  1163.            jz .err
  1164.            pop eax
  1165.  
  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
  1173. .err:
  1174.            pop eax
  1175.            ret
  1176. endp
  1177.  
  1178. align 4
  1179. proc codec_check_ready
  1180.  
  1181.            mov edx, CTRL_ST
  1182.            call [ctrl.ctrl_read32]
  1183.            and eax, CTRL_ST_CREADY
  1184.            jz .not_ready
  1185.  
  1186.            xor eax, wax
  1187.            inc eax
  1188.            ret
  1189. .not_ready:
  1190.            xor eax, eax
  1191.            ret
  1192. endp
  1193.  
  1194. align 4
  1195. proc check_semafore
  1196.            local counter:DWORD
  1197.  
  1198.            mov [counter], 100
  1199. .l1:
  1200.            mov edx, CTRL_CAS
  1201.            call [ctrl.ctrl_read8]
  1202.            and eax, CAS_FLAG
  1203.            jz .ok
  1204.  
  1205.            mov eax, 1
  1206.            call StallExec
  1207.            sub [counter], 1
  1208.            jnz .l1
  1209.            xor eax, eax
  1210.            ret
  1211. align 4
  1212. .ok:
  1213.            xor eax,eax
  1214.            inc eax
  1215.            ret
  1216. endp
  1217.  
  1218. align 4
  1219. proc StallExec
  1220.            push ecx
  1221.            push edx
  1222.            push ebx
  1223.            push eax
  1224.  
  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
  1232. @@:
  1233.            rdtsc
  1234.            sub eax, ebx
  1235.            sbb edx, ecx
  1236.            js @B
  1237.  
  1238.            pop eax
  1239.            pop ebx
  1240.            pop edx
  1241.            pop ecx
  1242.            ret
  1243. endp
  1244.  
  1245. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1246. ;          CONTROLLER IO functions
  1247. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1248.  
  1249. align 4
  1250. proc codec_io_r16
  1251.            add edx, [ctrl.codec_io_base]
  1252.            in  ax, dx
  1253.            ret
  1254. endp
  1255.  
  1256. align 4
  1257. proc codec_io_w16
  1258.            add edx, [ctrl.codec_io_base]
  1259.            out dx, ax
  1260.            ret
  1261. endp
  1262.  
  1263. align 4
  1264. proc ctrl_io_r8
  1265.            add edx, [ctrl.ctrl_io_base]
  1266.            in  al, dx
  1267.            ret
  1268. endp
  1269.  
  1270. align 4
  1271. proc ctrl_io_r16
  1272.            add edx, [ctrl.ctrl_io_base]
  1273.            in  ax, dx
  1274.            ret
  1275. endp
  1276.  
  1277. align 4
  1278. proc ctrl_io_r32
  1279.            add edx, [ctrl.ctrl_io_base]
  1280.            in  eax, dx
  1281.            ret
  1282. endp
  1283.  
  1284. align 4
  1285. proc ctrl_io_w8
  1286.            add edx, [ctrl.ctrl_io_base]
  1287.            out dx, al
  1288.            ret
  1289. endp
  1290.  
  1291. align 4
  1292. proc ctrl_io_w16
  1293.            add edx, [ctrl.ctrl_io_base]
  1294.            out dx, ax
  1295.            ret
  1296. endp
  1297.  
  1298. align 4
  1299. proc ctrl_io_w32
  1300.            add edx, [ctrl.ctrl_io_base]
  1301.            out dx, eax
  1302.            ret
  1303. endp
  1304.  
  1305. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1306. ;         MEMORY MAPPED IO    (os depended)
  1307. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1308.  
  1309. align 4
  1310. proc codec_mem_r16
  1311.            add edx, [ctrl.codec_mem_base]
  1312.            mov ax, word [edx]
  1313.            ret
  1314. endp
  1315.  
  1316. align 4
  1317. proc codec_mem_w16
  1318.            add edx, [ctrl.codec_mem_base]
  1319.            mov word [edx], ax
  1320.            ret
  1321. endp
  1322.  
  1323. align 4
  1324. proc ctrl_mem_r8
  1325.            add edx, [ctrl.ctrl_mem_base]
  1326.            mov al, [edx]
  1327.            ret
  1328. endp
  1329.  
  1330. align 4
  1331. proc ctrl_mem_r16
  1332.            add edx, [ctrl.ctrl_mem_base]
  1333.            mov ax, [edx]
  1334.            ret
  1335. endp
  1336.  
  1337. align 4
  1338. proc ctrl_mem_r32
  1339.            add edx, [ctrl.ctrl_mem_base]
  1340.            mov eax, [edx]
  1341.            ret
  1342. endp
  1343.  
  1344. align 4
  1345. proc ctrl_mem_w8
  1346.            add edx, [ctrl.ctrl_mem_base]
  1347.            mov [edx], al
  1348.            ret
  1349. endp
  1350.  
  1351. align 4
  1352. proc ctrl_mem_w16
  1353.            add edx, [ctrl.ctrl_mem_base]
  1354.            mov [edx], ax
  1355.            ret
  1356. endp
  1357.  
  1358. align 4
  1359. proc ctrl_mem_w32
  1360.            add edx, [ctrl.ctrl_mem_base]
  1361.            mov [edx], eax
  1362.            ret
  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
  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
  1394.  
  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
  1403.  
  1404.         dd 0    ;terminator
  1405.  
  1406.  
  1407. version      dd (5 shl 16) or (API_VERSION and 0xFFFF)
  1408.  
  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
  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
  1439. ;msgNotify    db 'call notify',13,10,0
  1440. msgIRQ       db 'AC97 IRQ', 13,10,0
  1441. msgInitCtrl  db 'init controller',13,10,0
  1442. ;msgInitCodec db 'init codec',13,10,0
  1443. msgPrimBuff  db 'create primary buffer ...',0
  1444. msgDone      db 'done',13,10,0
  1445. msgRemap     db 'Remap IRQ',13,10,0
  1446. ;msgReg       db 'set service handler',13,10,0
  1447. msgOk        db 'service installed',13,10,0
  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
  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
  1462. msgIrqMap    db 'AC97 irq map as      ',0
  1463.  
  1464. section '.data' data readable writable align 16
  1465.  
  1466. pcmout_bdl       rq 32
  1467. buff_list        rd 32
  1468.  
  1469. codec CODEC
  1470. ctrl AC_CNTRL
  1471.  
  1472. lpc_bus  rd 1
  1473. civ_val  rd 1
  1474.