Subversion Repositories Kolibri OS

Rev

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