Subversion Repositories Kolibri OS

Rev

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

  1. ; ------------------------------------------------------------- ;
  2. ; KWINE is a fork of program PELoad written by 0CodErr
  3. ; author - rgimad
  4. ; ------------------------------------------------------------- ;
  5. GLOBAL EXPORTS
  6. section '.exprt' align 16
  7. ;**********************************************************************************
  8. EXPORTS: ;/////////////////////////////////////////////////////////////////////////
  9. ;**********************************************************************************
  10. dd sz__getch,     _getch
  11. dd sz__kbhit,     _kbhit
  12. dd sz_printf,     printf
  13. dd sz_puts,       puts
  14. dd sz_gets,       gets
  15. dd sz_strlen,     strlen
  16. dd 0
  17. sz__getch         db "_getch",0
  18. sz__kbhit         db "_kbhit",0
  19. sz_printf         db "printf",0
  20. sz_puts           db "puts",0
  21. sz_gets           db "gets",0
  22. sz_strlen         db "strlen",0
  23.  
  24. section '.code' align 16
  25. align 16
  26. ;**********************************************************************************
  27. _getch: ;//////////////////////////////////////////////////////////////////////////
  28. ;**********************************************************************************
  29.         push   ebx
  30.         push   esi
  31.         push   edi
  32.  
  33.         call   load_console_lib
  34.         pop ecx
  35.         call   [con_getch]
  36.         push ecx
  37.  
  38.         pop    edi
  39.         pop    esi
  40.         pop    ebx
  41.         ret
  42. align 16                               
  43. ;**********************************************************************************
  44. _kbhit: ;//////////////////////////////////////////////////////////////////////////
  45. ;**********************************************************************************
  46.         push   ebx
  47.         push   esi
  48.         push   edi
  49.  
  50.         call   load_console_lib
  51.         pop ecx
  52.         call   [con_kbhit]
  53.         push ecx
  54.  
  55.         pop    edi
  56.         pop    esi
  57.         pop    ebx
  58.         ret
  59. align 16
  60. ;**********************************************************************************
  61. printf: ;//////////////////////////////////////////////////////////////////////////
  62. ;**********************************************************************************
  63.         ;pushad
  64.         ;push   ebx
  65.         ;push   esi
  66.         ;push   edi
  67.         call   load_console_lib
  68.             ;popad
  69.         pop ecx
  70.         call   [con_printf]
  71.         push ecx
  72.  
  73.         ;pop    edi
  74.         ;pop    esi
  75.         ;pop    ebx
  76.                                
  77.         ret
  78. align 16
  79. ;**********************************************************************************
  80. puts: ;////////////////////////////////////////////////////////////////////////// cdecl
  81. ;**********************************************************************************
  82.         ;push   ebx
  83.         ;push   esi
  84.         ;push   edi
  85.  
  86.         call   load_console_lib
  87.         pop ecx ; pop return address
  88.         call   [con_write_asciiz]
  89.         push ecx ; push return address again
  90.  
  91.         ;pop    edi
  92.         ;pop    esi
  93.         ;pop    ebx
  94.         ret
  95. align 16
  96. ;**********************************************************************************
  97. gets: ;////////////////////////////////////////////////////////////////////////// cdecl
  98. ;**********************************************************************************
  99.         ;push   ebx
  100.         ;push   esi
  101.         ;push   edi
  102.  
  103.         call   load_console_lib
  104.         pop ecx
  105.         pop edx
  106.         push   25 ;; second arg of con_gets assume by default
  107.         push edx
  108.         call   [con_gets]
  109.         push ecx
  110.  
  111.         ;pop    edi
  112.         ;pop    esi
  113.         ;pop    ebx
  114.         ret
  115. align 16
  116. ;**********************************************************************************
  117. strlen: ;//////////////////////////////////////////////////////////////////////////
  118. ;**********************************************************************************
  119.         push   ebx
  120.         push   esi
  121.         push   edi
  122.  
  123.         call   load_console_lib
  124.         xor eax,eax
  125.         mov edi, dword [esp + 4 + 4 + 4 + 4]
  126.         .while1:
  127.             inc eax
  128.             cmp byte [eax + edi], 0
  129.             jnz .while1
  130.  
  131.         pop    edi
  132.         pop    esi
  133.         pop    ebx
  134.         ret
  135.  
  136.                                
  137. load_console_lib: ;; stdcall ?
  138. ; if already loaded then do nothing
  139.         cmp    [console], dword 0
  140.         jne    .do_nothing
  141.         push   sz_console
  142.         call   load.library
  143.         mov    [console], eax
  144.         mov    ecx, eax
  145.         mov    ebx, getprocaddress
  146.         ;;
  147.         push   ecx
  148.         push   sz_con_init
  149.         call   ebx
  150.         mov    [con_init], eax
  151.         ;;
  152.         push   ecx
  153.         push   sz_con_getch
  154.         call   ebx
  155.         mov    [con_getch], eax
  156.         ;;
  157.         push   ecx
  158.         push   sz_con_kbhit
  159.         call   ebx
  160.         mov    [con_kbhit], eax
  161.         ;;
  162.         push   ecx
  163.         push   sz_con_printf
  164.         call   ebx
  165.         mov    [con_printf], eax
  166.         ;;
  167.         push ecx
  168.         push sz_con_write_asciiz
  169.         call ebx
  170.         mov [con_write_asciiz], eax
  171.         ;;
  172.         push   ecx
  173.         push   sz_con_gets
  174.         call   ebx
  175.         mov    [con_gets], eax
  176.                                
  177.         push   ecx
  178.         push   sz_con_init
  179.         call   ebx
  180.         mov    [con_init], eax
  181.         push   con_caption
  182.         push   -1
  183.         push   -1
  184.         push   -1
  185.         push   -1
  186.         call   [con_init]
  187.                                
  188.                                
  189. .do_nothing:
  190.         ret
  191.  
  192. ; ------------------------------------------------------------- ; stdcall
  193. load.library:
  194.         mov    eax, 68
  195.         mov    ebx, 19
  196.         mov    ecx, [esp + 4]
  197.         int    64
  198.         ret    4
  199. ; ------------------------------------------------------------- ;
  200. getprocaddress:
  201.         mov    edx, [esp + 8]
  202.         xor    eax, eax
  203.         test   edx, edx
  204.         jz     .end
  205. .next:
  206.         xor    eax, eax
  207.         cmp    [edx], dword 0
  208.         jz     .end
  209.         mov    esi, [edx]
  210.         mov    edi, [esp + 4]
  211. .next_:
  212.         lodsb
  213.         scasb
  214.         jne    .fail
  215.         or     al, al
  216.         jnz    .next_
  217.         jmp    .ok
  218. .fail:
  219.         add    edx, 8
  220.         jmp    .next
  221. .ok:
  222.         mov    eax, [edx + 4]
  223. .end:
  224.         ret    8
  225. ; ------------------------------------------------------------- ;
  226.  
  227. section '.data' align 16
  228.  
  229. con_caption         db "test!",0
  230. con_init            dd 0
  231. con_getch           dd 0
  232. con_kbhit           dd 0
  233. con_printf          dd 0
  234. con_write_asciiz dd 0
  235. con_gets            dd 0
  236. console             dd 0
  237. sz_con_init         db "con_init",0
  238. sz_con_getch        db "con_getch",0
  239. sz_con_kbhit        db "con_kbhit",0
  240. sz_con_printf       db "con_printf",0
  241. sz_con_write_asciiz db "con_write_asciiz",0
  242. sz_con_gets         db "con_gets",0
  243. sz_console          db "/sys/lib/console.obj",0