Subversion Repositories Kolibri OS

Rev

Rev 1145 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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