Subversion Repositories Kolibri OS

Rev

Rev 1145 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1145 Rev 6699
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
 
-
 
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]
-
 
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);
42
; while ((c=con_getch())!=27) // Esc=exit
10
; int c;
43
; {
11
; while ((c=con_getch())!=27) // Esc=exit
44
;   if (c)
12
; {
45
;     con_printf("normal character with code %d=0x%02X\n",c,c);
13
;   if (c)
46
;   else
14
;     con_printf("normal character with code %d=0x%02X\n",c,c);
47
;   {
15
;   else
48
;     c=con_getch();
16
;   {
49
;     con_printf("extended character with code %d=0x%02X\n",c,c);
17
;     c=con_getch();
50
;   }
18
;     con_printf("extended character with code %d=0x%02X\n",c,c);
51
; }
19
;   }
52
        push    start_string
20
; }
53
        call    [con_printf]
21
        push    start_string
54
        pop     ecx
22
        call    [con_printf]
55
mainloop:
23
        pop     ecx
56
        call    [con_getch]
24
mainloop:
57
        cmp     al, 27
25
        call    [con_getch]
58
        jz      done
26
        cmp     al, 27
59
        test    eax, eax
27
        jz      done
60
        jz      extended
28
        test    eax, eax
61
        push    eax
29
        jz      extended
62
        push    eax
30
        push    eax
63
        push    string_normal
31
        push    eax
64
@@:
32
        push    string_normal
65
        call    [con_printf]
33
@@:
66
        add     esp, 12
34
        call    [con_printf]
67
        jmp     mainloop
35
        add     esp, 12
68
extended:
36
        jmp     mainloop
69
        call    [con_getch]
37
extended:
70
        test    eax, eax
38
        call    [con_getch]
71
        jz      done
39
        test    eax, eax
72
        push    eax
40
        jz      done
73
        push    eax
41
        push    eax
74
        push    string_extended
42
        push    eax
75
        jmp     @b
43
        push    string_extended
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
 
-
 
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
-
 
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
64
string_normal      db 'normal character with code %d=0x%02X',10,0
162
 
65
string_extended    db 'extended character with code %d=0x%02X',10,0
163
i_end:
-
 
164
 
-
 
165
align 4
-
 
166
rb 2048 ; stack
-
 
167
mem:
-
 
168
-