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 (getch() 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
; con_printf(start_string);
8
; C-equivalent of the following code:
41
; int c;
9
; con_printf(start_string);
Line 76... Line 44...
76
done:
44
        jmp     @b
77
        push    1
45
done:
78
        call    [con_exit]
46
        push    1
79
exit:
47
        call    [con_exit]
80
        or      eax, -1
48
exit:
81
        int     0x40
-
 
82
 
-
 
83
proc load_dll_and_import stdcall, _dllname:dword, _imports:dword
-
 
84
        pushad
-
 
85
; load DLL
-
 
86
        push    68
-
 
87
        pop     eax
-
 
88
        push    19
-
 
89
        pop     ebx
-
 
90
        mov     ecx, [_dllname]
-
 
91
        int     0x40
-
 
92
        test    eax, eax
-
 
93
        jz      import_fail
-
 
94
 
-
 
95
; initialize import
-
 
96
        mov     edi, eax
-
 
97
        mov     esi, [_imports]
-
 
98
import_loop:
-
 
99
        lodsd
-
 
100
        test    eax, eax
-
 
101
        jz      import_done
-
 
102
        mov     edx, edi
-
 
103
import_find:
-
 
104
        mov     ebx, [edx]
-
 
105
        test    ebx, ebx
-
 
106
        jz      import_not_found
-
 
107
        push    eax
-
 
108
@@:
-
 
109
        mov     cl, [eax]
-
 
110
        cmp     cl, [ebx]
-
 
111
        jnz     import_find_next
-
 
112
        test    cl, cl
-
 
113
        jz      import_found
-
 
114
        inc     eax
-
 
115
        inc     ebx
-
 
116
        jmp     @b
-
 
117
import_find_next:
-
 
118
        pop     eax
-
 
119
        add     edx, 8
-
 
120
        jmp     import_find
-
 
121
import_found:
-
 
122
        pop     eax
-
 
123
        mov     eax, [edx+4]
-
 
124
        mov     [esi-4], eax
-
 
125
        jmp     import_loop
-
 
126
import_not_found:
-
 
127
import_fail:
-
 
128
        popad
-
 
129
        xor     eax, eax
-
 
130
        ret
49
	xor	eax, eax
131
import_done:
50
	ret
132
        popad
-
 
133
        xor     eax, eax
-
 
134
        inc     eax
-
 
135
        ret
-
 
136
endp
-
 
137
 
-
 
Line 138... Line 51...
138
align 4
51
 
139
 
-
 
140
imports:
52
align 4
141
dll_start          dd szStart
-
 
142
dll_ver            dd szVersion
53
data import
143
con_init           dd szcon_init
-
 
144
con_printf         dd szcon_printf
-
 
145
con_exit           dd szcon_exit
-
 
146
con_getch          dd szcon_getch
-
 
147
                   dd 0
54
library console, 'console.dll'
148
 
-
 
149
szStart            db 'START',0
-
 
150
szVersion          db 'version',0
-
 
151
szcon_init         db 'con_init',0
55
import console, \
152
szcon_printf       db 'con_printf',0
56
        con_set_title, 'con_set_title', \
153
szcon_exit         db 'con_exit',0
57
        con_printf, 'con_printf', \
154
szcon_getch        db 'con_getch',0
58
        con_exit, 'con_exit', \
155
 
59
        con_getch, 'con_getch'
156
dllname  db '/sys/lib/console.obj',0
-
 
Line 157... Line 60...
157
 
60
end data
158
caption            db 'Console test - getch()',0
61
 
159
start_string       db 'Press any key to see its code, or Esc to exit',10,0
62
caption            db 'Console test - getch()',0
160
string_normal      db 'normal character with code %d=0x%02X',10,0
63
start_string       db 'Press any key to see its code, or Esc to exit',10,0
161
string_extended    db 'extended character with code %d=0x%02X',10,0
-
 
162
 
-
 
163
i_end:
-
 
164
 
-
 
165
align 4
-
 
166
rb 2048 ; stack
-