Subversion Repositories Kolibri OS

Rev

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

  1. ;
  2. ;   This file is part of the AC97 mp3 player.
  3. ;   (C) copyright Serge 2006
  4. ;   email: infinity_sound@mail.ru
  5. ;
  6. ;   This program is free software; you can redistribute it and/or modify
  7. ;   it under the terms of the GNU General Public License as published by
  8. ;   the Free Software Foundation; either version 2 of the License, or
  9. ;   (at your option) any later version.
  10. ;
  11. ;   This program is distributed in the hope that it will be useful,
  12. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;   GNU General Public License for more details.
  15.  
  16.  
  17. format MS COFF
  18.  
  19. include "proc32.inc"
  20.  
  21. section '.text' code readable executable
  22.  
  23. public _GetService@4
  24. public _GetDevInfo@8
  25. public _GetMasterVol@8
  26. public _SetMasterVol@8
  27. public _CreateBuffer@8
  28. public _DestroyBuffer@8
  29. public _SetBuffer@20
  30. public _PlayBuffer@8
  31. public _StopBuffer@8
  32.  
  33. public _InitHeap@4
  34. public _UserAlloc@4
  35. public _GetNotify@4
  36. public _CreateThread@8
  37. public _GetMousePos@4
  38. public _get_fileinfo@8
  39. public _read_file@20
  40. public _get_key
  41. public _get_button_id
  42. public _DrawWindow@36
  43. public _make_button@24
  44. public _draw_bar@20
  45. public _write_text@20
  46. public _debug_out@4
  47. public _debug_out_hex@4
  48.  
  49. public _memset
  50.  
  51. struc FILEIO
  52. {   .cmd            dd ?
  53.     .offset         dd ?
  54.                     dd ?
  55.     .count          dd ?
  56.     .buff           dd ?
  57.                     db ?
  58.     .name           dd ?
  59. };
  60.  
  61. struc CTRL_INFO
  62. {   .pci_cmd        dd  ?
  63.     .irq            dd  ?
  64.     .glob_cntrl     dd  ?
  65.     .glob_sta       dd  ?
  66.     .codec_io_base  dd  ?
  67.     .ctrl_io_base   dd  ?
  68.     .codec_mem_base dd  ?
  69.     .ctrl_mem_base  dd  ?
  70.     .codec_id       dd  ?
  71. }
  72. CTRL_INFO_SIZE      equ 9*4
  73.  
  74.  
  75. SND_CREATE_DEV     equ  1
  76. SND_CREATE_BUFF    equ  2
  77. SND_PLAY           equ  3
  78. SND_STOP           equ  4
  79. SND_SETBUFF        equ  5
  80. SND_DESTROY_BUFF   equ  6
  81.  
  82. DEV_SET_BUFF       equ  4
  83. DEV_NOTIFY         equ  5
  84. DEV_SET_MASTERVOL  equ  6
  85. DEV_GET_MASTERVOL  equ  7
  86. DEV_GET_INFO       equ  8
  87.  
  88.  
  89. align 4
  90. proc _get_button_id
  91.            mov   eax,17
  92.            int   0x40
  93.            test  al,al
  94.            jnz   @F
  95.            shr   eax,8
  96.            ret
  97. @@:
  98.            xor   eax,eax
  99.            dec   eax
  100.            ret
  101. endp
  102.  
  103. align 4
  104. proc _get_fileinfo@8 stdcall, name:dword, info:dword
  105.            push ebx
  106.            push esi
  107.            push edi
  108.            xor eax, eax
  109.            mov ebx, [name]
  110.            mov ecx, [info]
  111.  
  112.            mov [fileio.cmd], 5
  113.            mov [fileio.offset], eax
  114.            mov [fileio.offset+4], eax
  115.            mov [fileio.count], eax
  116.            mov [fileio.buff], ecx
  117.            mov byte [fileio.buff+4], al
  118.            mov [fileio.name], ebx
  119.  
  120.            mov eax, 70
  121.            lea ebx, [fileio]
  122.            int 0x40
  123.            pop edi
  124.            pop esi
  125.            pop ebx
  126.            ret
  127. endp
  128.  
  129. align 4
  130. proc _read_file@20 stdcall,name:dword, buff:dword, offset:dword,\
  131.                                      count:dword,reads:dword
  132.            push ebx
  133.            push esi
  134.            push edi
  135.            xor eax, eax
  136.            mov ebx, [name]
  137.            mov edx, [offset]
  138.            mov esi, [buff]
  139.            mov edi, [count]
  140.  
  141.            mov [fileio.cmd], eax
  142.            mov [fileio.offset], edx
  143.            mov [fileio.offset+4], eax
  144.            mov [fileio.count], edi
  145.            mov [fileio.buff], esi
  146.            mov byte [fileio.buff+4], al
  147.            mov [fileio.name], ebx
  148.  
  149.            mov eax, 70
  150.            lea ebx, [fileio]
  151.            int 0x40
  152.            mov esi, [reads]
  153.            test esi, esi
  154.            jz @f
  155.            mov [esi], ebx
  156. @@:
  157.            pop edi
  158.            pop esi
  159.            pop ebx
  160.            ret
  161. endp
  162.  
  163. align 4
  164. proc _get_key
  165.            mov eax, 2
  166.            int 0x40
  167.            shr eax, 8
  168.            ret
  169. endp
  170.  
  171. align 4
  172. proc _InitHeap@4 stdcall, heap_size:dword
  173.                   push ebx
  174.                   mov eax, 68
  175.                   mov ebx, 11
  176.               mov ecx, [heap_size]
  177.                   int 0x40
  178.                   pop ebx
  179.                   ret
  180. endp
  181.  
  182. align 4
  183. proc _UserAlloc@4 stdcall, alloc_size:dword
  184.                   push ebx
  185.                   mov eax, 68
  186.                   mov ebx, 12
  187.               mov ecx, [alloc_size]
  188.                   int 0x40
  189.                   pop ebx
  190.                   ret
  191. endp
  192.  
  193. align 4
  194. proc _GetNotify@4 stdcall, p_ev:dword
  195.                   push ebx
  196.                   mov eax, 68
  197.                   mov ebx, 14
  198.               mov ecx, [p_ev]
  199.                   int 0x40
  200.                   pop ebx
  201.                   ret
  202. endp
  203.  
  204. align 4
  205. proc _CreateThread@8 stdcall, fn:dword, p_stack:dword
  206.               push ebx
  207.               mov eax, 51
  208.               mov ebx, 1
  209.               mov ecx, [fn]
  210.               mov edx,[p_stack]
  211.                   int 0x40
  212.                   pop ebx
  213.                   ret
  214. endp
  215.  
  216. align 4
  217. proc _GetMousePos@4 stdcall,rel_type:dword
  218.            push ebx  
  219.            mov eax, 37
  220.            mov ebx, [rel_type]
  221.                int 0x40
  222.                pop ebx
  223.                ret
  224. endp
  225.  
  226. align 4
  227. proc CallServiceEx stdcall, ioctl:dword
  228.               push ebx
  229.               mov eax, 68
  230.               mov ebx, 17
  231.           mov ecx, [ioctl]
  232.               int 0x40
  233.               pop ebx
  234.               ret
  235. endp
  236.  
  237. align 4
  238. proc _GetService@4 stdcall, name:dword
  239.            push ebx
  240.            mov eax, 68
  241.                mov ebx, 16
  242.            mov ecx, [name]
  243.                int 0x40
  244.                pop ebx
  245.                ret
  246. endp
  247.  
  248. align 4
  249. proc _GetDevInfo@8 stdcall, hSrv:dword, p_info:dword
  250.            locals
  251.              handle     dd ?
  252.              io_code    dd ?
  253.              input      dd ?
  254.              inp_size   dd ?
  255.              output     dd ?
  256.              out_size   dd ?
  257.            endl
  258.            
  259.            push ebx
  260.            mov eax, [hSrv]
  261.            xor ebx, ebx
  262.            mov ecx, [p_info]
  263.  
  264.            mov [handle], eax
  265.            mov [io_code], DEV_GET_INFO
  266.            mov [input], ebx
  267.            mov [inp_size], ebx
  268.            mov [output], ecx
  269.            mov [out_size], CTRL_INFO_SIZE
  270.  
  271.            lea eax, [handle]
  272.            stdcall CallServiceEx, eax
  273.            pop ebx
  274.                ret
  275. endp
  276.  
  277. align 4
  278. proc _GetMasterVol@8 stdcall, hSrv:dword,pvol:dword
  279.            locals
  280.              handle     dd ?
  281.              io_code    dd ?
  282.              input      dd ?
  283.              inp_size   dd ?
  284.              output     dd ?
  285.              out_size   dd ?
  286.            endl
  287.            
  288.            push ebx
  289.            mov eax, [hSrv]
  290.            mov ecx, [pvol]
  291.            xor ebx, ebx
  292.            mov [handle], eax
  293.            mov [io_code], DEV_GET_MASTERVOL
  294.            mov [input], ebx
  295.            mov [inp_size], ebx
  296.            mov [output], ecx
  297.            mov [out_size], 4
  298.  
  299.            lea eax, [handle]
  300.            stdcall CallServiceEx, eax
  301.            pop ebx
  302.                ret
  303. endp
  304.  
  305. align 4
  306. proc _SetMasterVol@8 stdcall,hSrv:dword,vol:dword
  307.            locals
  308.              handle     dd ?
  309.              io_code    dd ?
  310.              input      dd ?
  311.              inp_size   dd ?
  312.              output     dd ?
  313.              out_size   dd ?
  314.            endl
  315.            
  316.            push ebx
  317.            mov eax, [hSrv]
  318.            lea ecx, [vol]
  319.            xor ebx, ebx
  320.  
  321.            mov [handle], eax
  322.            mov [io_code], DEV_SET_MASTERVOL
  323.            mov [input], ecx
  324.            mov [inp_size], 4
  325.            mov [output], ebx
  326.            mov [out_size], 0
  327.  
  328.            lea eax, [handle]
  329.            stdcall CallServiceEx, eax
  330.            pop ebx
  331.                ret
  332. endp
  333.  
  334. align 4
  335. proc _CreateBuffer@8 stdcall, hSound:dword,format:dword
  336.            locals
  337.              handle     dd ?
  338.              io_code    dd ?
  339.              input      dd ?
  340.              inp_size   dd ?
  341.              output     dd ?
  342.              out_size   dd ?
  343.            endl
  344.  
  345.            push ebx
  346.            mov eax, [hSound]
  347.            lea ecx, [format]
  348.            xor ebx, ebx
  349.  
  350.            mov [handle], eax
  351.            mov [io_code], SND_CREATE_BUFF
  352.            mov [input], ecx
  353.            mov [inp_size], 4
  354.            mov [output], ebx
  355.            mov [out_size], 0
  356.  
  357.            lea eax, [handle]
  358.            stdcall CallServiceEx, eax
  359.            pop ebx
  360.                ret
  361. endp
  362.  
  363. align 4
  364. proc _DestroyBuffer@8 stdcall, hSound:dword, str:dword
  365.            locals
  366.              handle     dd ?
  367.              io_code    dd ?
  368.              input      dd ?
  369.              inp_size   dd ?
  370.              output     dd ?
  371.              out_size   dd ?
  372.            endl
  373.  
  374.            push ebx
  375.            mov eax, [hSound]
  376.            lea ecx, [str]
  377.            xor ebx, ebx
  378.  
  379.            mov [handle], eax
  380.            mov [io_code], SND_DESTROY_BUFF
  381.            mov [input], ecx
  382.            mov [inp_size], 4
  383.            mov [output], ebx
  384.            mov [out_size], 0
  385.  
  386.            lea eax, [handle]
  387.            stdcall CallServiceEx, eax
  388.            pop ebx
  389.                ret
  390. endp
  391.  
  392. align 4
  393. proc _SetBuffer@20 stdcall,hSound:dword, str:dword, src:dword, offs:dword, size:dword
  394.            locals
  395.              handle     dd ?
  396.              io_code    dd ?
  397.              input      dd ?
  398.              inp_size   dd ?
  399.              output     dd ?
  400.              out_size   dd ?
  401.            endl
  402.  
  403.            push ebx
  404.            mov eax, [hSound]
  405.            lea ecx, [str]
  406.            xor ebx, ebx
  407.  
  408.            mov [handle], eax
  409.            mov [io_code], SND_SETBUFF
  410.            mov [input], ecx
  411.            mov [inp_size], 16
  412.            mov [output], ebx
  413.            mov [out_size], 0
  414.  
  415.            lea eax, [handle]
  416.            stdcall CallServiceEx, eax
  417.            pop ebx
  418.                ret
  419. endp
  420.  
  421. align 4
  422. proc _PlayBuffer@8 stdcall, hSound:dword, str:dword
  423.            locals
  424.              handle     dd ?
  425.              io_code    dd ?
  426.              input      dd ?
  427.              inp_size   dd ?
  428.              output     dd ?
  429.              out_size   dd ?
  430.            endl
  431.  
  432.            push ebx
  433.            mov eax, [hSound]
  434.            lea ecx, [str]
  435.            xor ebx, ebx
  436.  
  437.            mov [handle], eax
  438.            mov [io_code], SND_PLAY
  439.            mov [input], ecx
  440.            mov [inp_size], 4
  441.            mov [output], ebx
  442.            mov [out_size], 0
  443.  
  444.            lea eax, [handle]
  445.            stdcall CallServiceEx, eax
  446.            pop ebx
  447.                ret
  448. endp
  449.  
  450. align 4
  451. proc _StopBuffer@8 stdcall, hSound:dword, str:dword
  452.            locals
  453.              handle     dd ?
  454.              io_code    dd ?
  455.              input      dd ?
  456.              inp_size   dd ?
  457.              output     dd ?
  458.              out_size   dd ?
  459.            endl
  460.  
  461.            push ebx
  462.            mov eax, [hSound]
  463.            lea ecx, [str]
  464.            xor ebx, ebx
  465.  
  466.            mov [handle], eax
  467.            mov [io_code], SND_STOP
  468.            mov [input], ecx
  469.            mov [inp_size], 4
  470.            mov [output], ebx
  471.            mov [out_size], 0
  472.  
  473.            lea eax, [handle]
  474.            stdcall CallServiceEx, eax
  475.            pop ebx
  476.            ret
  477. endp
  478.  
  479. align 4
  480. proc _DrawWindow@36 stdcall, x:dword, y:dword, sx:dword, sy:dword,\
  481.                                workcolor:dword, style:dword, captioncolor:dword,\
  482.                                windowtype:dword, bordercolor:dword  
  483.            push ebx edi esi
  484.            mov ebx, [x]
  485.            mov ecx, [y]
  486.            shl ebx, 16
  487.            shl ecx, 16
  488.            mov bx, word [sx]
  489.            mov cx,  word [sy]
  490.            mov  edx,[style]
  491.            shl  edx,24
  492.            add  edx,[workcolor]
  493.            mov  esi,[windowtype]
  494.            shl  esi,24
  495.            add  esi,[captioncolor]
  496.            mov  edi,[bordercolor]
  497.            xor  eax,eax
  498.            int  0x40
  499.            pop esi edi ebx
  500.            ret
  501. endp
  502.  
  503. align 4
  504. _make_button@24:
  505. ;arg1 - x
  506. ;arg2 - y
  507. ;arg3 - xsize
  508. ;arg4 - ysize
  509. ;arg5 - id
  510. ;arg6 - color
  511.      
  512.   push  ebx esi
  513.   mov   ebx,[esp+12]
  514.   shl   ebx,16
  515.   mov   bx,[esp+20]
  516.   mov   ecx,[esp+16]
  517.   shl   ecx,16
  518.   mov   cx,[esp+24]
  519.   mov   edx,[esp+28]
  520.   mov   esi,[esp+32]
  521.   mov   eax,8
  522.   int   0x40
  523.   pop   esi ebx
  524.   ret   24
  525.  
  526. align 4
  527. _draw_bar@20:
  528. ;arg1 - x
  529. ;arg2 - y
  530. ;arg3 - xsize
  531. ;arg4 - ysize
  532. ;arg5 - color
  533.   push  ebx
  534.   mov   eax,13
  535.   mov   ebx,[esp+8]
  536.   shl   ebx,16
  537.   mov   bx,[esp+16]
  538.   mov   ecx,[esp+12]
  539.   shl   ecx,16
  540.   mov   cx,[esp+20]
  541.   mov   edx,[esp+24]
  542.   int   0x40
  543.   pop   ebx
  544.   ret   20
  545.  
  546. _write_text@20:
  547. ;arg1 - x
  548. ;arg2 - y
  549. ;arg3 - color
  550. ;arg4 - text
  551. ;arg5 - len
  552.   push  ebx esi
  553.   mov   eax,4
  554.   mov   ebx,[esp+12]
  555.   shl   ebx,16
  556.   mov   bx,[esp+16]
  557.   mov   ecx,[esp+20]
  558.   mov   edx,[esp+24]
  559.   mov   esi,[esp+28]
  560.   int   0x40
  561.   pop   esi ebx
  562.   ret   20
  563.  
  564. align 4
  565. proc _debug_out@4 stdcall, val:dword
  566.            push ebx
  567.            mov  ecx,[val]
  568.            mov  ebx,1
  569.            mov  eax,63
  570.            int  0x40
  571.            pop ebx
  572.            ret
  573. endp          
  574.  
  575. align 4
  576. proc _debug_out_hex@4 stdcall val:dword
  577.            locals
  578.              count dd ?
  579.            endl
  580.  
  581.            mov [count], 8
  582. .new_char:
  583.            rol [val], 4
  584.            mov ecx, [val]
  585.            and ecx, 0x0f
  586.            mov cl,byte [__hexdigits+ecx]
  587.            mov eax, 63
  588.            mov ebx, 1
  589.            int 0x40
  590.            dec [count]
  591.            jnz .new_char
  592.            ret
  593. endp
  594.                    
  595. align 4
  596. _memset:
  597.            mov     edx,[esp + 0ch]
  598.            mov     ecx,[esp + 4]
  599.  
  600.            test    edx,edx        
  601.            jz      short toend    
  602.        
  603.            xor     eax,eax
  604.            mov     al,[esp + 8]
  605.  
  606.            push    edi            
  607.            mov     edi,ecx      
  608.  
  609.            cmp     edx,4
  610.            jb      tail    
  611.            
  612.            neg     ecx
  613.            and     ecx,3          
  614.            jz      short dwords  
  615.            
  616.            sub     edx,ecx  
  617. adjust_loop:
  618.            mov     [edi],al
  619.            add     edi,1
  620.            sub     ecx,1
  621.            jnz     adjust_loop
  622.  
  623. dwords:
  624.         mov     ecx,eax        
  625.         shl     eax,8          
  626.         add     eax,ecx        
  627.         mov     ecx,eax        
  628.         shl     eax,10h        
  629.         add     eax,ecx        
  630.        
  631.         mov     ecx,edx        
  632.         and     edx,3          
  633.         shr     ecx,2          
  634.         jz      tail        
  635.  
  636.                 cld    
  637.         rep     stosd
  638. main_loop_tail:
  639.         test    edx,edx    
  640.         jz      finish        
  641.  
  642.  
  643. tail:
  644.         mov     [edi],al      
  645.         add     edi,1
  646.  
  647.         sub     edx,1        
  648.         jnz     tail            
  649.  
  650. finish:
  651.         mov     eax,[esp + 8]
  652.         pop     edi            
  653.  
  654.         ret
  655.  
  656. toend:
  657.         mov     eax,[esp + 4]
  658.  
  659.         ret
  660.  
  661. public __ftol2_sse
  662.  
  663. align 4
  664. __ftol2_sse:
  665.            push ebp
  666.            mov ebp, esp
  667.            sub esp, 20
  668.            and esp, 0xFFFFFFF0
  669.            fld st0
  670.            fst dword [esp+18]
  671.            fistp qword [esp+10]
  672.            fild qword [esp+10]
  673.            mov edx, [esp+18]
  674.            mov eax, [esp+10]
  675.            test eax, eax
  676.            jz .QnaNZ
  677.            
  678. .not_QnaNZ:
  679.            fsubp st1, st0
  680.            test edx, edx
  681.            jns .pos
  682.            fstp dword [esp]
  683.            mov ecx, [esp]
  684.            xor ecx, 0x80000000
  685.            add ecx, 0x7FFFFFFF
  686.            adc eax, 0
  687.            mov edx, [esp+14]
  688.            adc edx, 0
  689.            jmp .exit
  690. .pos:
  691.            fstp dword [esp]
  692.            mov ecx, [esp]
  693.            add ecx, 0x7FFFFFFF
  694.            sbb eax, 0
  695.            jmp .exit
  696. .QnaNZ:
  697.            mov edx, [esp+14]
  698.            test edx, 0x7FFFFFFF
  699.            jne .not_QnaNZ
  700.            fstp dword [esp+18]
  701.            fstp dword [esp+18]
  702. .exit:          
  703.            leave
  704.            ret
  705.  
  706. public __fltused
  707. __fltused    dd 0
  708.            
  709. align 4
  710. __hexdigits db '0123456789ABCDEF'
  711.  
  712. align 4
  713. fileio FILEIO
  714.  
  715.