Subversion Repositories Kolibri OS

Rev

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