Subversion Repositories Kolibri OS

Rev

Go to most recent revision | 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 2
  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 (show color strings in this case).
  32.  
  33.         push    caption
  34.         push    -1
  35.         push    -1
  36.         push    -1
  37.         push    -1
  38.         call    [con_init]
  39. ; C-equivalent of the following code:
  40. ; for (ebx=0;ebx<0x100;ebx++)
  41. ; {
  42. ;   con_printf(t1,ebx);
  43. ;   eax = con_set_flags(ebx);
  44. ;   con_write_asciiz(text);
  45. ;   con_set_flags(eax);
  46. ; }
  47. ; N.B. For efficiency result of first con_set_flags is not saved
  48. ;      in register, but is pushed beforehand to the stack
  49. ;      for second con_set_flags.
  50. ;      Note that such code cannot be generated by stdcall macros.
  51.         xor     ebx, ebx
  52. @@:
  53.         push    ebx
  54.         push    t1
  55.         call    [con_printf]
  56.         add     esp, 8
  57.         push    ebx
  58.         call    [con_set_flags]
  59.         push    eax
  60.         push    text
  61.         call    [con_write_asciiz]
  62.         call    [con_set_flags]
  63.         inc     bl
  64.         jnz     @b
  65.         push    text2
  66.         call    [con_write_asciiz]
  67.         push    0
  68.         call    [con_exit]
  69. exit:
  70.         or      eax, -1
  71.         int     0x40
  72.  
  73. proc load_dll_and_import stdcall, _dllname:dword, _imports:dword
  74.         pushad
  75. ; load DLL
  76.         push    68
  77.         pop     eax
  78.         push    19
  79.         pop     ebx
  80.         mov     ecx, [_dllname]
  81.         int     0x40
  82.         test    eax, eax
  83.         jz      import_fail
  84.  
  85. ; initialize import
  86.         mov     edi, eax
  87.         mov     esi, [_imports]
  88. import_loop:
  89.         lodsd
  90.         test    eax, eax
  91.         jz      import_done
  92.         mov     edx, edi
  93. import_find:
  94.         mov     ebx, [edx]
  95.         test    ebx, ebx
  96.         jz      import_not_found
  97.         push    eax
  98. @@:
  99.         mov     cl, [eax]
  100.         cmp     cl, [ebx]
  101.         jnz     import_find_next
  102.         test    cl, cl
  103.         jz      import_found
  104.         inc     eax
  105.         inc     ebx
  106.         jmp     @b
  107. import_find_next:
  108.         pop     eax
  109.         add     edx, 8
  110.         jmp     import_find
  111. import_found:
  112.         pop     eax
  113.         mov     eax, [edx+4]
  114.         mov     [esi-4], eax
  115.         jmp     import_loop
  116. import_not_found:
  117. import_fail:
  118.         popad
  119.         xor     eax, eax
  120.         ret
  121. import_done:
  122.         popad
  123.         xor     eax, eax
  124.         inc     eax
  125.         ret
  126. endp
  127.  
  128. align 4
  129.  
  130. imports:
  131. dll_start          dd szStart
  132. dll_ver            dd szVersion
  133. con_init           dd szcon_init
  134. con_write_asciiz   dd szcon_write_asciiz
  135. con_printf         dd szcon_printf
  136. con_set_flags      dd szcon_set_flags
  137. con_exit           dd szcon_exit
  138.                    dd 0
  139.  
  140. szStart            db 'START',0
  141. szVersion          db 'version',0
  142. szcon_init         db 'con_init',0
  143. szcon_write_asciiz db 'con_write_asciiz',0
  144. szcon_printf       db 'con_printf',0
  145. szcon_set_flags    db 'con_set_flags',0
  146. szcon_exit         db 'con_exit',0
  147.  
  148. dllname  db '/sys/lib/console.obj',0
  149.  
  150. caption            db 'Console test - colors',0
  151. t1                 db 'Color 0x%02X: ',0
  152. text               db 'This is sample text.',10,0
  153. text2           db      27,'[7mAnd this is an example of '
  154.                 db      27,'[1;36;41mEsc'
  155.                 db      27,'[7m-sequences.',10,0
  156.  
  157. i_end:
  158.  
  159. align 4
  160. rb 2048 ; stack
  161. mem:
  162.