Subversion Repositories Kolibri OS

Rev

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