Subversion Repositories Kolibri OS

Rev

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

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