Subversion Repositories Kolibri OS

Rev

Rev 1145 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2. include 'proc32.inc'
  3.  
  4. DLL_ENTRY equ 1
  5. DLL_EXIT  equ -1
  6. REQ_DLL_VER equ 3
  7.  
  8. use32
  9.         db      'MENUET01'
  10.         dd      1
  11.         dd      start
  12.         dd      i_end
  13.         dd      mem
  14.         dd      mem
  15.         dd      0
  16.         dd      0
  17.  
  18. start:
  19.         stdcall load_dll_and_import, dllname, imports
  20.         test    eax, eax
  21.         jz      exit
  22.  
  23. ; check version
  24.         cmp     word [dll_ver], REQ_DLL_VER
  25.         jb      exit
  26.         cmp     word [dll_ver+2], REQ_DLL_VER
  27.         ja      exit
  28.         push    DLL_ENTRY
  29.         call    [dll_start]
  30.  
  31. ; yes! Now do some work (gets() demo in this case).
  32.  
  33.         push    caption
  34.         push    -1
  35.         push    -1
  36.         push    -1
  37.         push    -1
  38.         call    [con_init]
  39.  
  40. ; C-equivalent of the following code:
  41. ; for (;;)
  42. ; {
  43. ;   con_write_asciiz("Enter string (empty for exit): ");
  44. ;   if (!con_gets(s,256)) break;
  45. ;   if (s[0] == '\n') break;
  46. ;   con_write_asciiz("You entered: ");
  47. ;   con_write_asciiz(s);
  48. ; }
  49. mainloop:
  50.         push    str1
  51.         call    [con_write_asciiz]
  52.         push    256
  53.         push    s
  54.         call    [con_gets]
  55.         test    eax, eax
  56.         jz      done
  57.         cmp     [s], 10
  58.         jz      done
  59.         push    str2
  60.         call    [con_write_asciiz]
  61.         push    s
  62.         call    [con_write_asciiz]
  63.         jmp     mainloop
  64. done:
  65.         push    1
  66.         call    [con_exit]
  67. exit:
  68.         or      eax, -1
  69.         int     0x40
  70.  
  71. proc load_dll_and_import stdcall, _dllname:dword, _imports:dword
  72.         pushad
  73. ; load DLL
  74.         push    68
  75.         pop     eax
  76.         push    19
  77.         pop     ebx
  78.         mov     ecx, [_dllname]
  79.         int     0x40
  80.         test    eax, eax
  81.         jz      import_fail
  82.  
  83. ; initialize import
  84.         mov     edi, eax
  85.         mov     esi, [_imports]
  86. import_loop:
  87.         lodsd
  88.         test    eax, eax
  89.         jz      import_done
  90.         mov     edx, edi
  91. import_find:
  92.         mov     ebx, [edx]
  93.         test    ebx, ebx
  94.         jz      import_not_found
  95.         push    eax
  96. @@:
  97.         mov     cl, [eax]
  98.         cmp     cl, [ebx]
  99.         jnz     import_find_next
  100.         test    cl, cl
  101.         jz      import_found
  102.         inc     eax
  103.         inc     ebx
  104.         jmp     @b
  105. import_find_next:
  106.         pop     eax
  107.         add     edx, 8
  108.         jmp     import_find
  109. import_found:
  110.         pop     eax
  111.         mov     eax, [edx+4]
  112.         mov     [esi-4], eax
  113.         jmp     import_loop
  114. import_not_found:
  115. import_fail:
  116.         popad
  117.         xor     eax, eax
  118.         ret
  119. import_done:
  120.         popad
  121.         xor     eax, eax
  122.         inc     eax
  123.         ret
  124. endp
  125.  
  126. align 4
  127.  
  128. imports:
  129. dll_start          dd szStart
  130. dll_ver            dd szVersion
  131. con_init           dd szcon_init
  132. con_write_asciiz   dd szcon_write_asciiz
  133. con_exit           dd szcon_exit
  134. con_gets           dd szcon_gets
  135.                    dd 0
  136.  
  137. szStart            db 'START',0
  138. szVersion          db 'version',0
  139. szcon_init         db 'con_init',0
  140. szcon_write_asciiz db 'con_write_asciiz',0
  141. szcon_exit         db 'con_exit',0
  142. szcon_gets         db 'con_gets',0
  143.  
  144. dllname  db '/sys/lib/console.obj',0
  145.  
  146. caption            db 'Console test - gets()',0
  147. str1               db 'Enter string (empty for exit): ',0
  148. str2               db 'You entered: ',0
  149.  
  150. i_end:
  151.  
  152. s rb 256
  153.  
  154. align 4
  155. rb 2048 ; stack
  156. mem:
  157.