Subversion Repositories Kolibri OS

Rev

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