Subversion Repositories Kolibri OS

Rev

Rev 577 | Rev 799 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. format MS COFF
  2.  
  3. include "proc32.inc"
  4.  
  5. section '.text' align 16 code readable executable
  6.  
  7. public _InitHeap@4
  8. public _UserAlloc@4
  9. public _UserFree@4
  10.  
  11. public _GetNotify@4
  12. public _CreateThread@8
  13. public _GetMousePos@4
  14.  
  15. public _get_fileinfo@8
  16. public _create_file@4
  17. public _read_file@20
  18. public _write_file@20
  19.  
  20. public _get_key@4
  21. public _remap_key@4
  22. public _get_button_id
  23.  
  24. public _GetScreenSize@8
  25.  
  26. public _DrawWindow@36
  27. public _make_button@24
  28. public _draw_bar@20
  29.  
  30. public _write_text@20
  31. public _debug_out@4
  32. public _debug_out_hex@4
  33. public _create_thread@12
  34.  
  35.  
  36. ;public _memset
  37.  
  38. struc FILEIO
  39. {   .cmd            dd ?
  40.     .offset         dd ?
  41.                     dd ?
  42.     .count          dd ?
  43.     .buff           dd ?
  44.                     db ?
  45.     .name           dd ?
  46. };
  47.  
  48. struc CTRL_INFO
  49. {   .pci_cmd        dd  ?
  50.     .irq            dd  ?
  51.     .glob_cntrl     dd  ?
  52.     .glob_sta       dd  ?
  53.     .codec_io_base  dd  ?
  54.     .ctrl_io_base   dd  ?
  55.     .codec_mem_base dd  ?
  56.     .ctrl_mem_base  dd  ?
  57.     .codec_id       dd  ?
  58. }
  59. CTRL_INFO_SIZE      equ 9*4
  60.  
  61. align 4
  62. _GetScreenSize@8:
  63.            .x equ esp+12
  64.            .y equ esp+16
  65.  
  66.            push ebx
  67.            push ecx
  68.            mov eax, 14
  69.            int 0x40
  70.            mov ebx, [.y]
  71.            movzx ecx, ax
  72.            inc ecx
  73.            mov [ebx], ecx
  74.            mov ebx, [.x]
  75.            shr eax, 16
  76.            inc eax
  77.            mov [ebx], eax
  78.            pop ecx
  79.            pop ebx
  80.            ret 8
  81.  
  82. align 4
  83. _create_thread@12:
  84. .thr_proc    equ esp+4
  85. .param       equ esp+8
  86. .stack_size  equ esp+12
  87.  
  88.            mov eax, 68
  89.            mov ebx, 12
  90.            mov ecx, [.stack_size]
  91.            add ecx, 4095
  92.            and ecx, -4096
  93.            int 0x40
  94.            test eax, eax
  95.            jz .fail
  96.  
  97.            lea edx, [eax+ecx-12]
  98.            mov [edx], dword .exit_point
  99.            mov ebx, [.param]
  100.            mov [edx+4], ebx
  101.            mov [edx+8], ecx
  102.  
  103.            mov eax, 51
  104.            mov ebx, 1
  105.            mov ecx, [.thr_proc]
  106.            int 0x40
  107.            ret 12
  108. .fail:
  109.            not eax
  110.            ret 12
  111. align 4
  112. .exit_point:
  113.            pop ecx
  114.            mov eax, 68
  115.            mov ebx, 13
  116.            int 0x40
  117.            mov eax, -1
  118.            int 0x40
  119.  
  120. restore .thr_proc
  121. restore .param
  122. restore .stack_size
  123.  
  124. align 4
  125. proc _get_button_id
  126.            mov   eax,17
  127.            int   0x40
  128.            test  al,al
  129.            jnz   @F
  130.            shr   eax,8
  131.            ret
  132. @@:
  133.            xor   eax,eax
  134.            dec   eax
  135.            ret
  136. endp
  137.  
  138. align 4
  139. proc _get_fileinfo@8 stdcall, name:dword, info:dword
  140.            push ebx
  141.            push ecx
  142.            push esi
  143.            push edi
  144.            xor eax, eax
  145.            mov ebx, [name]
  146.            mov ecx, [info]
  147.  
  148.            mov [fileio.cmd], 5
  149.            mov [fileio.offset], eax
  150.            mov [fileio.offset+4], eax
  151.            mov [fileio.count], eax
  152.            mov [fileio.buff], ecx
  153.            mov byte [fileio.buff+4], al
  154.            mov [fileio.name], ebx
  155.  
  156.            mov eax, 70
  157.            lea ebx, [fileio]
  158.            int 0x40
  159.            pop edi
  160.            pop esi
  161.            pop ecx
  162.            pop ebx
  163.            ret
  164. endp
  165.  
  166. align 4
  167. proc _create_file@4 stdcall, name:dword
  168.            push ebx
  169.            xor eax, eax
  170.            mov ebx, [name]
  171.  
  172.            mov [fileio.cmd], 2
  173.            mov [fileio.offset], eax
  174.            mov [fileio.offset+4], eax
  175.            mov [fileio.count], eax
  176.            mov [fileio.buff], eax
  177.            mov byte [fileio.buff+4], al
  178.            mov [fileio.name], ebx
  179.  
  180.            mov eax, 70
  181.            lea ebx, [fileio]
  182.            int 0x40
  183.            pop ebx
  184.            ret
  185. endp
  186.  
  187. align 4
  188. proc _read_file@20 stdcall,name:dword, buff:dword, offset:dword,\
  189.                                      count:dword,reads:dword
  190.            push ebx
  191.            push esi
  192.            push edi
  193.            push edx
  194.            xor eax, eax
  195.            mov ebx, [name]
  196.            mov edx, [offset]
  197.            mov esi, [buff]
  198.            mov edi, [count]
  199.  
  200.            mov [fileio.cmd], eax
  201.            mov [fileio.offset], edx
  202.            mov [fileio.offset+4], eax
  203.            mov [fileio.count], edi
  204.            mov [fileio.buff], esi
  205.            mov byte [fileio.buff+4], al
  206.            mov [fileio.name], ebx
  207.  
  208.            mov eax, 70
  209.            lea ebx, [fileio]
  210.            int 0x40
  211.            mov esi, [reads]
  212.            test esi, esi
  213.            jz @f
  214.            mov [esi], ebx
  215. @@:
  216.            pop edx
  217.            pop edi
  218.            pop esi
  219.            pop ebx
  220.            ret
  221. endp
  222.  
  223.  
  224. align 4
  225. proc _write_file@20 stdcall,name:dword, buff:dword, offset:dword,\
  226.                                      count:dword,writes:dword
  227.            push ebx
  228.            push esi
  229.            push edi
  230.            push edx
  231.            xor eax, eax
  232.            mov ebx, [name]
  233.            mov edx, [offset]
  234.            mov esi, [buff]
  235.            mov edi, [count]
  236.  
  237.            mov [fileio.cmd], 3
  238.            mov [fileio.offset], edx
  239.            mov [fileio.offset+4], eax
  240.            mov [fileio.count], edi
  241.            mov [fileio.buff], esi
  242.            mov byte [fileio.buff+4], al
  243.            mov [fileio.name], ebx
  244.  
  245.            mov eax, 70
  246.            lea ebx, [fileio]
  247.            int 0x40
  248.            mov esi, [writes]
  249.            test esi, esi
  250.            jz @f
  251.            mov [esi], ebx
  252. @@:
  253.            pop edx
  254.            pop edi
  255.            pop esi
  256.            pop ebx
  257.            ret
  258. endp
  259.  
  260. align 4
  261. proc _get_key@4 stdcall, key:dword
  262.            push ebx
  263.            push ecx
  264.            mov eax, 2
  265.            int 0x40
  266.            mov ebx, [key]
  267.            mov ecx, eax
  268.            shr ecx, 8
  269.            mov [ebx], ecx
  270.            movzx eax, al
  271.            pop ecx
  272.            pop ebx
  273.            ret
  274. endp
  275.  
  276. align 4
  277. proc _InitHeap@4 stdcall, heap_size:dword
  278.            push ebx
  279.            push ecx
  280.            mov eax, 68
  281.            mov ebx, 11
  282.            mov ecx, [heap_size]
  283.            int 0x40
  284.            pop ecx
  285.            pop ebx
  286.            ret
  287. endp
  288.  
  289. align 4
  290. proc _UserAlloc@4 stdcall, alloc_size:dword
  291.            push ebx
  292.            push ecx
  293.            mov eax, 68
  294.            mov ebx, 12
  295.            mov ecx, [alloc_size]
  296.            int 0x40
  297.            pop ecx
  298.            pop ebx
  299.            ret
  300. endp
  301.  
  302. align 4
  303. proc _UserFree@4 stdcall, pmem:dword
  304.            push ebx
  305.            push ecx
  306.            mov eax, 68
  307.            mov ebx, 13
  308.            mov ecx, [pmem]
  309.            int 0x40
  310.            pop ecx
  311.            pop ebx
  312.            ret
  313. endp          
  314.  
  315. align 4
  316. proc _GetNotify@4 stdcall, p_ev:dword
  317.            push ebx
  318.            push ecx
  319.            mov eax, 68
  320.            mov ebx, 14
  321.            mov ecx, [p_ev]
  322.            int 0x40
  323.            pop ecx
  324.            pop ebx
  325.            ret
  326. endp
  327.  
  328. align 4
  329. proc _CreateThread@8 stdcall, fn:dword, p_stack:dword
  330.               push ebx
  331.               push ecx
  332.               push edx
  333.               mov eax, 51
  334.               mov ebx, 1
  335.               mov ecx, [fn]
  336.               mov edx,[p_stack]
  337.               int 0x40
  338.               pop edx
  339.               pop ecx
  340.               pop ebx
  341.               ret
  342. endp
  343.  
  344. align 4
  345. proc _GetMousePos@4 stdcall,rel_type:dword
  346.            push ebx
  347.            mov eax, 37
  348.            mov ebx, [rel_type]
  349.            int 0x40
  350.            pop ebx
  351.            ret
  352. endp
  353.  
  354. align 4
  355. proc _DrawWindow@36 stdcall, x:dword, y:dword, sx:dword, sy:dword,\
  356.                                workcolor:dword, style:dword, captioncolor:dword,\
  357.                                windowtype:dword, bordercolor:dword
  358.            push ebx
  359.            push ecx
  360.            push edx
  361.            push edi
  362.            push esi
  363.            
  364.            mov ebx, [x]
  365.            mov ecx, [y]
  366.            shl ebx, 16
  367.            shl ecx, 16
  368.            mov bx, word [sx]
  369.            mov cx,  word [sy]
  370.            mov  edx,[style]
  371.            shl  edx,24
  372.            add  edx,[workcolor]
  373.            mov  esi,[windowtype]
  374.            shl  esi,24
  375.            add  esi,[captioncolor]
  376.            mov  edi,[bordercolor]
  377.            xor  eax,eax
  378.            int  0x40
  379.            pop esi
  380.            pop edi
  381.            pop edx
  382.            pop ecx
  383.            pop ebx
  384.            ret
  385. endp
  386.  
  387. align 4
  388. _make_button@24:
  389. ;arg1 - x
  390. ;arg2 - y
  391. ;arg3 - xsize
  392. ;arg4 - ysize
  393. ;arg5 - id
  394. ;arg6 - color
  395.  
  396.   push  ebx
  397.   push  ecx
  398.   push  esi
  399.   mov   ebx,[esp+12]
  400.   shl   ebx,16
  401.   mov   bx,[esp+20]
  402.   mov   ecx,[esp+16]
  403.   shl   ecx,16
  404.   mov   cx,[esp+24]
  405.   mov   edx,[esp+28]
  406.   mov   esi,[esp+32]
  407.   mov   eax,8
  408.   int   0x40
  409.   pop   esi ecx ebx
  410.   ret   24
  411.  
  412. align 4
  413. _draw_bar@20:
  414. ;arg1 - x
  415. ;arg2 - y
  416. ;arg3 - xsize
  417. ;arg4 - ysize
  418. ;arg5 - color
  419.   push  ebx ecx
  420.   mov   eax,13
  421.   mov   ebx,[esp+8]
  422.   shl   ebx,16
  423.   mov   bx,[esp+16]
  424.   mov   ecx,[esp+12]
  425.   shl   ecx,16
  426.   mov   cx,[esp+20]
  427.   mov   edx,[esp+24]
  428.   int   0x40
  429.   pop   ecx ebx
  430.   ret   20
  431.  
  432. _write_text@20:
  433. ;arg1 - x
  434. ;arg2 - y
  435. ;arg3 - color
  436. ;arg4 - text
  437. ;arg5 - len
  438.   push  ebx ecx esi
  439.   mov   eax,4
  440.   mov   ebx,[esp+12]
  441.   shl   ebx,16
  442.   mov   bx,[esp+16]
  443.   mov   ecx,[esp+20]
  444.   mov   edx,[esp+24]
  445.   mov   esi,[esp+28]
  446.   int   0x40
  447.   pop   esi ecx ebx
  448.   ret   20
  449.  
  450. align 4
  451. proc _debug_out@4 stdcall, val:dword
  452.            push ebx
  453.            push ecx
  454.            mov  ecx,[val]
  455.            mov  ebx,1
  456.            mov  eax,63
  457.            int  0x40
  458.            pop ecx
  459.            pop ebx
  460.            ret
  461. endp
  462.  
  463. align 4
  464. proc _debug_out_hex@4 stdcall val:dword
  465.            locals
  466.              count dd ?
  467.            endl
  468.  
  469.            mov [count], 8
  470. .new_char:
  471.            rol [val], 4
  472.            mov ecx, [val]
  473.            and ecx, 0x0f
  474.            mov cl,byte [__hexdigits+ecx]
  475.            mov eax, 63
  476.            mov ebx, 1
  477.            int 0x40
  478.            dec [count]
  479.            jnz .new_char
  480.            ret
  481. endp
  482.  
  483. align 4
  484. proc _remap_key@4 stdcall, key:dword
  485.  
  486.            mov eax, [key]
  487.            and eax, 0x7F
  488.            movzx eax, byte [keymap+eax]
  489.            ret
  490. endp
  491.  
  492. align 4
  493. _memset:
  494.            mov     edx,[esp + 0ch]
  495.            mov     ecx,[esp + 4]
  496.  
  497.            test    edx,edx
  498.            jz      short toend
  499.  
  500.            xor     eax,eax
  501.            mov     al,[esp + 8]
  502.  
  503.            push    edi
  504.            mov     edi,ecx
  505.  
  506.            cmp     edx,4
  507.            jb      tail
  508.  
  509.            neg     ecx
  510.            and     ecx,3
  511.            jz      short dwords
  512.  
  513.            sub     edx,ecx
  514. adjust_loop:
  515.            mov     [edi],al
  516.            add     edi,1
  517.            sub     ecx,1
  518.            jnz     adjust_loop
  519.  
  520. dwords:
  521.         mov     ecx,eax
  522.         shl     eax,8
  523.         add     eax,ecx
  524.         mov     ecx,eax
  525.         shl     eax,10h
  526.         add     eax,ecx
  527.  
  528.         mov     ecx,edx
  529.         and     edx,3
  530.         shr     ecx,2
  531.         jz      tail
  532.  
  533.                 cld
  534.         rep     stosd
  535. main_loop_tail:
  536.         test    edx,edx
  537.         jz      finish
  538.  
  539.  
  540. tail:
  541.         mov     [edi],al
  542.         add     edi,1
  543.  
  544.         sub     edx,1
  545.         jnz     tail
  546.  
  547. finish:
  548.         mov     eax,[esp + 8]
  549.         pop     edi
  550.  
  551.         ret
  552.  
  553. toend:
  554.         mov     eax,[esp + 4]
  555.  
  556.         ret
  557.  
  558. ;public __allmul
  559.  
  560. __allmul:
  561.         mov eax, [esp+8]
  562.         mov ecx, [esp+16]
  563.         or ecx,eax
  564.         mov ecx, [esp+12]
  565.         jnz .hard
  566.         mov eax, [esp+4]
  567.         mul ecx
  568.         ret 16
  569. .hard:
  570.         push ebx
  571.         mul ecx
  572.         mov ebx,eax
  573.         mov eax, [esp+8]
  574.         mul dword [esp+20]
  575.         add ebx,eax
  576.         mov eax,[esp+8]
  577.         mul ecx
  578.         add edx,ebx
  579.         pop ebx
  580.         ret 16
  581.  
  582. ;public __allshr
  583.  
  584. align 4
  585. __allshr:
  586.         cmp cl,64
  587.         jae .sign
  588.  
  589.         cmp cl, 32
  590.         jae .MORE32
  591.         shrd eax,edx,cl
  592.         sar edx,cl
  593.         ret
  594. .MORE32:
  595.         mov     eax,edx
  596.         sar     edx,31
  597.         and     cl,31
  598.         sar     eax,cl
  599.         ret
  600. .sign:
  601.         sar     edx,31
  602.         mov     eax,edx
  603.         ret
  604.  
  605.  
  606. ;public _scalbn
  607.  
  608. align 4
  609. proc _scalbn
  610.                   fild  dword [esp+12]
  611.                   fld   qword [esp+4]
  612.                   fscale
  613.                   fstp  st1
  614.                   ret
  615. endp
  616.  
  617.  
  618. ;public  __alloca_probe_8
  619. ;public  __alloca_probe_16
  620.  
  621. __alloca_probe_16:                       ; 16 byte aligned alloca
  622.  
  623.         push    ecx
  624.         lea     ecx, [esp + 8]          ; TOS before entering this function
  625.         sub     ecx, eax                ; New TOS
  626.         and     ecx, (16 - 1)           ; Distance from 16 bit align (align down)
  627.         add     eax, ecx                ; Increase allocation size
  628.         sbb     ecx, ecx                ; ecx = 0xFFFFFFFF if size wrapped around
  629.         or      eax, ecx                ; cap allocation size on wraparound
  630.         pop     ecx                     ; Restore ecx
  631.         jmp     __chkstk
  632.  
  633. alloca_8:                               ; 8 byte aligned alloca
  634. __alloca_probe_8:
  635.  
  636.         push    ecx
  637.         lea     ecx, [esp+8]          ; TOS before entering this function
  638.         sub     ecx, eax                ; New TOS
  639.         and     ecx, (8 - 1)            ; Distance from 8 bit align (align down)
  640.         add     eax, ecx                ; Increase allocation Size
  641.         sbb     ecx, ecx                ; ecx = 0xFFFFFFFF if size wrapped around
  642.         or      eax, ecx                ; cap allocation size on wraparound
  643.         pop     ecx                     ; Restore ecx
  644.         jmp     __chkstk
  645.  
  646. ;public __chkstk
  647. ;public _alloca_probe
  648.  
  649. align 4
  650. ;_alloca_probe:
  651. __chkstk:
  652.         push    ecx
  653.         lea     ecx, [esp+8-4]          ; TOS before entering function + size for ret value
  654.         sub     ecx, eax                ; new TOS
  655.  
  656. ; Handle allocation size that results in wraparound.
  657. ; Wraparound will result in StackOverflow exception.
  658.  
  659.         sbb     eax, eax                ; 0 if CF==0, ~0 if CF==1
  660.         not     eax                     ; ~0 if TOS did not wrapped around, 0 otherwise
  661.         and     ecx, eax                ; set to 0 if wraparound
  662.  
  663.         mov     eax, esp                ; current TOS
  664.         and     eax, -4096              ; Round down to current page boundary
  665.  
  666. cs10:
  667.         cmp     ecx, eax                ; Is new TOS
  668.         jb      short cs20              ; in probed page?
  669.         mov     eax, ecx                ; yes.
  670.         pop     ecx
  671.         xchg    esp, eax                ; update esp
  672.         mov     eax, [eax]              ; get return address
  673.         mov     [esp], eax              ; and put it at new TOS
  674.         ret
  675.  
  676. ; Find next lower page and probe
  677. cs20:
  678.         sub     eax, 4096               ; decrease by PAGESIZE
  679.         test    [eax],eax     ; probe page.
  680.         jmp     short cs10
  681.  
  682. public __ftol2_sse
  683.  
  684. align 4
  685. __ftol2_sse:
  686.            push ebp
  687.            mov ebp, esp
  688.            sub esp, 20
  689.            and esp, 0xFFFFFFF0
  690.            fld st0
  691.            fst dword [esp+18]
  692.            fistp qword [esp+10]
  693.            fild qword [esp+10]
  694.            mov edx, [esp+18]
  695.            mov eax, [esp+10]
  696.            test eax, eax
  697.            jz .QnaNZ
  698.  
  699. .not_QnaNZ:
  700.            fsubp st1, st0
  701.            test edx, edx
  702.            jns .pos
  703.            fstp dword [esp]
  704.            mov ecx, [esp]
  705.            xor ecx, 0x80000000
  706.            add ecx, 0x7FFFFFFF
  707.            adc eax, 0
  708.            mov edx, [esp+14]
  709.            adc edx, 0
  710.            jmp .exit
  711. .pos:
  712.            fstp dword [esp]
  713.            mov ecx, [esp]
  714.            add ecx, 0x7FFFFFFF
  715.            sbb eax, 0
  716.            jmp .exit
  717. .QnaNZ:
  718.            mov edx, [esp+14]
  719.            test edx, 0x7FFFFFFF
  720.            jne .not_QnaNZ
  721.            fstp dword [esp+18]
  722.            fstp dword [esp+18]
  723. .exit:
  724.            leave
  725.            ret
  726.  
  727. section '.data' align 16 data readable writable
  728.  
  729. align 16
  730. __hexdigits db '0123456789ABCDEF'
  731.  
  732.          ;  0    1    2    3    4    5    6    7
  733.          ;  8    9    a    b    c    d    e    f
  734.  
  735. keymap:
  736.      db      0,  27, '1', '2', '3', '4', '5', '6'   ;00
  737.      db    '7', '8', '9', '0', '-', '=',0x7F, 0x9   ;08
  738.      db    'q', 'w', 'e', 'r', 't', 'y', 'u', 'i'   ;10
  739.      db    'o', 'p', '[', ']',  13,0x9D, 'a', 's'   ;18
  740.      db    'd', 'f', 'g', 'h', 'j', 'k', 'l', ';'   ;20
  741.      db      0, '~',0xB6, '|',0x7A,0x87, 'c', 'v'   ;28
  742.      db    'b', 'n', 'm', ',', '.', '/',0xB6, '*'   ;30
  743.      db   0xB8, ' ',   0,0xBB,0xBC,0xBD,0xBE,0xBF   ;38
  744.      db   0xC0,0xC1,0xC2,0xC3,0xC4,   0,   0,   0   ;40
  745.      db   0xAD,   0,   0,0xAC,   0,0xAE,   0,   0   ;48
  746.      db   0xAF,   0,   0,   0,   0,   0,   0,   0   ;50
  747.      db      0,   0,   0,   0,   0,   0,   0,   0   ;58
  748.      db      0,   0,   0,   0,   0,   0,   0,   0   ;60
  749.      db      0,   0,   0,   0,   0,   0,   0,   0   ;68
  750.      db      0,   0,   0,   0,   0,   0,   0,   0   ;70
  751.      db      0,   0,   0,   0,   0,   0,   0,   0   ;78
  752.  
  753. public ___sse2_available
  754. ___sse2_available dd 0
  755.  
  756. public __fltused
  757. __fltused    dd 0
  758.  
  759. align 4
  760. fileio FILEIO
  761.