Subversion Repositories Kolibri OS

Rev

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