Subversion Repositories Kolibri OS

Rev

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

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