Subversion Repositories Kolibri OS

Rev

Rev 853 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 853 Rev 1145
1
include 'proc32.inc'
1
include 'proc32.inc'
2
 
2
 
3
DLL_ENTRY equ 1
3
DLL_ENTRY equ 1
4
DLL_EXIT  equ -1
4
DLL_EXIT  equ -1
5
REQ_DLL_VER equ 4
5
REQ_DLL_VER equ 4
6
 
6
 
7
use32
7
use32
8
        db      'MENUET01'
8
        db      'MENUET01'
9
        dd      1
9
        dd      1
10
        dd      start
10
        dd      start
11
        dd      i_end
11
        dd      i_end
12
        dd      mem
12
        dd      mem
13
        dd      mem
13
        dd      mem
14
        dd      0
14
        dd      0
15
        dd      0
15
        dd      0
16
 
16
 
17
start:
17
start:
18
        stdcall load_dll_and_import, dllname, imports
18
        stdcall load_dll_and_import, dllname, imports
19
        test    eax, eax
19
        test    eax, eax
20
        jz      exit
20
        jz      exit
21
 
21
 
22
; check version
22
; check version
23
        cmp     word [dll_ver], REQ_DLL_VER
23
        cmp     word [dll_ver], REQ_DLL_VER
24
        jb      exit
24
        jb      exit
25
        cmp     word [dll_ver+2], REQ_DLL_VER
25
        cmp     word [dll_ver+2], REQ_DLL_VER
26
        ja      exit
26
        ja      exit
27
        push    DLL_ENTRY
27
        push    DLL_ENTRY
28
        call    [dll_start]
28
        call    [dll_start]
29
 
29
 
30
; yes! Now do some work (gets2() demo in this case).
30
; yes! Now do some work (gets2() demo in this case).
31
 
31
 
32
        push    caption
32
        push    caption
33
        push    25
33
        push    25
34
        push    80
34
        push    80
35
        push    25
35
        push    25
36
        push    80
36
        push    80
37
        call    [con_init]
37
        call    [con_init]
38
 
38
 
39
; C-equivalent of the following code:
39
; C-equivalent of the following code:
40
; for (;;)
40
; for (;;)
41
; {
41
; {
42
;   con_write_asciiz("Enter string (empty for exit): ");
42
;   con_write_asciiz("Enter string (empty for exit): ");
43
;   con_gets2(mycallback,s,256);
43
;   if (!con_gets2(mycallback,s,256)) break;
44
;   if (s[0] == '\n') break;
44
;   if (s[0] == '\n') break;
45
;   con_write_asciiz("You entered: ");
45
;   con_write_asciiz("You entered: ");
46
;   con_write_asciiz(s);
46
;   con_write_asciiz(s);
47
; }
47
; }
48
mainloop:
48
mainloop:
49
        push    str1
49
        push    str1
50
        call    [con_write_asciiz]
50
        call    [con_write_asciiz]
51
        push    256
51
        push    256
52
        push    s
52
        push    s
53
        push    mycallback
53
        push    mycallback
54
        call    [con_gets2]
54
        call    [con_gets2]
55
        cmp     [s], 10
55
        test    eax, eax
-
 
56
        jz      done
-
 
57
        cmp     [s], 10
56
        jz      done
58
        jz      done
57
        push    str2
59
        push    str2
58
        call    [con_write_asciiz]
60
        call    [con_write_asciiz]
59
        push    s
61
        push    s
60
        call    [con_write_asciiz]
62
        call    [con_write_asciiz]
61
        jmp     mainloop
63
        jmp     mainloop
62
done:
64
done:
63
        push    1
65
        push    1
64
        call    [con_exit]
66
        call    [con_exit]
65
exit:
67
exit:
66
        or      eax, -1
68
        or      eax, -1
67
        int     0x40
69
        int     0x40
68
 
70
 
69
proc mycallback stdcall, keycode:dword, pstr:dword, pn:dword, ppos:dword
71
proc mycallback stdcall, keycode:dword, pstr:dword, pn:dword, ppos:dword
70
        mov     eax, [keycode]
72
        mov     eax, [keycode]
71
        cmp     al, 0x0F
73
        cmp     al, 0x0F
72
        jz      .tab
74
        jz      .tab
73
        cmp     al, 0x3B
75
        cmp     al, 0x3B
74
        jz      .f1
76
        jz      .f1
75
        cmp     al, 0x48
77
        cmp     al, 0x48
76
        jz      .up
78
        jz      .up
77
        cmp     al, 0x50
79
        cmp     al, 0x50
78
        jz      .down
80
        jz      .down
79
        xor     eax, eax
81
        xor     eax, eax
80
        ret
82
        ret
81
.tab:
83
.tab:
82
; Tab pressed - insert "[autocomplete]" to current position
84
; Tab pressed - insert "[autocomplete]" to current position
83
        push    esi edi
85
        push    esi edi
84
        mov     eax, [ppos]
86
        mov     eax, [ppos]
85
        mov     eax, [eax]
87
        mov     eax, [eax]
86
        mov     ecx, [pn]
88
        mov     ecx, [pn]
87
        mov     ecx, [ecx]
89
        mov     ecx, [ecx]
88
        mov     esi, [pstr]
90
        mov     esi, [pstr]
89
        mov     esi, [esi]
91
        mov     esi, [esi]
90
        add     ecx, esi
92
        add     ecx, esi
91
        add     esi, eax
93
        add     esi, eax
92
        mov     edx, esi
94
        mov     edx, esi
93
@@:
95
@@:
94
        lodsb
96
        lodsb
95
        test    al, al
97
        test    al, al
96
        jnz     @b
98
        jnz     @b
97
        lea     edi, [esi+str3.len]
99
        lea     edi, [esi+str3.len]
98
        cmp     edi, ecx
100
        cmp     edi, ecx
99
        jbe     @f
101
        jbe     @f
100
        mov     edi, ecx
102
        mov     edi, ecx
101
        lea     esi, [edi-str3.len]
103
        lea     esi, [edi-str3.len]
102
@@:
104
@@:
103
        cmp     esi, edx
105
        cmp     esi, edx
104
        jbe     @f
106
        jbe     @f
105
        dec     esi
107
        dec     esi
106
        dec     edi
108
        dec     edi
107
        mov     al, [esi]
109
        mov     al, [esi]
108
        mov     [edi], al
110
        mov     [edi], al
109
        jmp     @b
111
        jmp     @b
110
@@:
112
@@:
111
        cmp     edi, ecx
113
        cmp     edi, ecx
112
        jb      @f
114
        jb      @f
113
        dec     edi
115
        dec     edi
114
@@:
116
@@:
115
        mov     ecx, edi
117
        mov     ecx, edi
116
        sub     ecx, edx
118
        sub     ecx, edx
117
        mov     edi, edx
119
        mov     edi, edx
118
        mov     esi, str3
120
        mov     esi, str3
119
        rep     movsb
121
        rep     movsb
120
        mov     eax, [pstr]
122
        mov     eax, [pstr]
121
        sub     edi, [eax]
123
        sub     edi, [eax]
122
        mov     eax, [ppos]
124
        mov     eax, [ppos]
123
        mov     [eax], edi
125
        mov     [eax], edi
124
        pop     edi esi
126
        pop     edi esi
125
        xor     eax, eax
127
        xor     eax, eax
126
        inc     eax
128
        inc     eax
127
        ret
129
        ret
128
.f1:
130
.f1:
129
; F1 pressed - say message
131
; F1 pressed - say message
130
        push    str4
132
        push    str4
131
        call    [con_write_asciiz]
133
        call    [con_write_asciiz]
132
        push    str1
134
        push    str1
133
        call    [con_write_asciiz]
135
        call    [con_write_asciiz]
134
        push    2
136
        push    2
135
        pop     eax
137
        pop     eax
136
        ret
138
        ret
137
.up:
139
.up:
138
        push    esi
140
        push    esi
139
        mov     esi, str5
141
        mov     esi, str5
140
        mov     ecx, str5.len
142
        mov     ecx, str5.len
141
        jmp     @f
143
        jmp     @f
142
.down:
144
.down:
143
        push    esi
145
        push    esi
144
        mov     esi, str6
146
        mov     esi, str6
145
        mov     ecx, str6.len
147
        mov     ecx, str6.len
146
@@:
148
@@:
147
        push    edi
149
        push    edi
148
        mov     edi, [pstr]
150
        mov     edi, [pstr]
149
        mov     edi, [edi]
151
        mov     edi, [edi]
150
        mov     eax, [ppos]
152
        mov     eax, [ppos]
151
        mov     [eax], ecx
153
        mov     [eax], ecx
152
        rep     movsb
154
        rep     movsb
153
        xor     eax, eax
155
        xor     eax, eax
154
        stosb
156
        stosb
155
        pop     edi esi
157
        pop     edi esi
156
        inc     eax
158
        inc     eax
157
        ret
159
        ret
158
endp
160
endp
159
 
161
 
160
proc load_dll_and_import stdcall, _dllname:dword, _imports:dword
162
proc load_dll_and_import stdcall, _dllname:dword, _imports:dword
161
        pushad
163
        pushad
162
; load DLL
164
; load DLL
163
        push    68
165
        push    68
164
        pop     eax
166
        pop     eax
165
        push    19
167
        push    19
166
        pop     ebx
168
        pop     ebx
167
        mov     ecx, [_dllname]
169
        mov     ecx, [_dllname]
168
        int     0x40
170
        int     0x40
169
        test    eax, eax
171
        test    eax, eax
170
        jz      import_fail
172
        jz      import_fail
171
 
173
 
172
; initialize import
174
; initialize import
173
        mov     edi, eax
175
        mov     edi, eax
174
        mov     esi, [_imports]
176
        mov     esi, [_imports]
175
import_loop:
177
import_loop:
176
        lodsd
178
        lodsd
177
        test    eax, eax
179
        test    eax, eax
178
        jz      import_done
180
        jz      import_done
179
        mov     edx, edi
181
        mov     edx, edi
180
import_find:
182
import_find:
181
        mov     ebx, [edx]
183
        mov     ebx, [edx]
182
        test    ebx, ebx
184
        test    ebx, ebx
183
        jz      import_not_found
185
        jz      import_not_found
184
        push    eax
186
        push    eax
185
@@:
187
@@:
186
        mov     cl, [eax]
188
        mov     cl, [eax]
187
        cmp     cl, [ebx]
189
        cmp     cl, [ebx]
188
        jnz     import_find_next
190
        jnz     import_find_next
189
        test    cl, cl
191
        test    cl, cl
190
        jz      import_found
192
        jz      import_found
191
        inc     eax
193
        inc     eax
192
        inc     ebx
194
        inc     ebx
193
        jmp     @b
195
        jmp     @b
194
import_find_next:
196
import_find_next:
195
        pop     eax
197
        pop     eax
196
        add     edx, 8
198
        add     edx, 8
197
        jmp     import_find
199
        jmp     import_find
198
import_found:
200
import_found:
199
        pop     eax
201
        pop     eax
200
        mov     eax, [edx+4]
202
        mov     eax, [edx+4]
201
        mov     [esi-4], eax
203
        mov     [esi-4], eax
202
        jmp     import_loop
204
        jmp     import_loop
203
import_not_found:
205
import_not_found:
204
import_fail:
206
import_fail:
205
        popad
207
        popad
206
        xor     eax, eax
208
        xor     eax, eax
207
        ret
209
        ret
208
import_done:
210
import_done:
209
        popad
211
        popad
210
        xor     eax, eax
212
        xor     eax, eax
211
        inc     eax
213
        inc     eax
212
        ret
214
        ret
213
endp
215
endp
214
 
216
 
215
align 4
217
align 4
216
 
218
 
217
imports:
219
imports:
218
dll_start          dd szStart
220
dll_start          dd szStart
219
dll_ver            dd szVersion
221
dll_ver            dd szVersion
220
con_init           dd szcon_init
222
con_init           dd szcon_init
221
con_write_asciiz   dd szcon_write_asciiz
223
con_write_asciiz   dd szcon_write_asciiz
222
con_exit           dd szcon_exit
224
con_exit           dd szcon_exit
223
con_gets2          dd szcon_gets2
225
con_gets2          dd szcon_gets2
224
                   dd 0
226
                   dd 0
225
 
227
 
226
szStart            db 'START',0
228
szStart            db 'START',0
227
szVersion          db 'version',0
229
szVersion          db 'version',0
228
szcon_init         db 'con_init',0
230
szcon_init         db 'con_init',0
229
szcon_write_asciiz db 'con_write_asciiz',0
231
szcon_write_asciiz db 'con_write_asciiz',0
230
szcon_exit         db 'con_exit',0
232
szcon_exit         db 'con_exit',0
231
szcon_gets2        db 'con_gets2',0
233
szcon_gets2        db 'con_gets2',0
232
 
234
 
233
dllname  db '/sys/lib/console.obj',0
235
dllname  db '/sys/lib/console.obj',0
234
 
236
 
235
caption            db 'Console test - gets2()',0
237
caption            db 'Console test - gets2()',0
236
str1               db 'Enter string (empty for exit): ',0
238
str1               db 'Enter string (empty for exit): ',0
237
str2               db 'You entered: ',0
239
str2               db 'You entered: ',0
238
str3               db '[autocomplete]'
240
str3               db '[autocomplete]'
239
str3.len = $ - str3
241
str3.len = $ - str3
240
str4               db 13,10,'Help? What help do you need?',13,10,0
242
str4               db 13,10,'Help? What help do you need?',13,10,0
241
str5               db 'previous line in the history'
243
str5               db 'previous line in the history'
242
str5.len = $ - str5
244
str5.len = $ - str5
243
str6               db 'next line in the history'
245
str6               db 'next line in the history'
244
str6.len = $ - str6
246
str6.len = $ - str6
245
 
247
 
246
i_end:
248
i_end:
247
 
249
 
248
s rb 256
250
s rb 256
249
 
251
 
250
align 4
252
align 4
251
rb 2048 ; stack
253
rb 2048 ; stack
252
mem:
254
mem: