Rev 1145 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6699 | clevermous | 1 | format PE GUI 0.8 ; initialize console ourselves |
852 | diamond | 2 | include 'proc32.inc' |
6699 | clevermous | 3 | include '../../../../import.inc' |
852 | diamond | 4 | |
5 | start: |
||
6 | push caption |
||
853 | diamond | 7 | push 25 |
8 | push 80 |
||
9 | push 25 |
||
10 | push 80 |
||
852 | diamond | 11 | call [con_init] |
12 | |||
13 | ; C-equivalent of the following code: |
||
14 | ; for (;;) |
||
15 | ; { |
||
16 | ; con_write_asciiz("Enter string (empty for exit): "); |
||
1145 | diamond | 17 | ; if (!con_gets2(mycallback,s,256)) break; |
852 | diamond | 18 | ; if (s[0] == '\n') break; |
19 | ; con_write_asciiz("You entered: "); |
||
20 | ; con_write_asciiz(s); |
||
21 | ; } |
||
22 | mainloop: |
||
23 | push str1 |
||
24 | call [con_write_asciiz] |
||
25 | push 256 |
||
26 | push s |
||
27 | push mycallback |
||
28 | call [con_gets2] |
||
1145 | diamond | 29 | test eax, eax |
30 | jz done |
||
852 | diamond | 31 | cmp [s], 10 |
32 | jz done |
||
33 | push str2 |
||
34 | call [con_write_asciiz] |
||
35 | push s |
||
36 | call [con_write_asciiz] |
||
37 | jmp mainloop |
||
38 | done: |
||
39 | push 1 |
||
40 | call [con_exit] |
||
41 | exit: |
||
6699 | clevermous | 42 | xor eax, eax |
43 | ret |
||
852 | diamond | 44 | |
45 | proc mycallback stdcall, keycode:dword, pstr:dword, pn:dword, ppos:dword |
||
46 | mov eax, [keycode] |
||
47 | cmp al, 0x0F |
||
48 | jz .tab |
||
49 | cmp al, 0x3B |
||
50 | jz .f1 |
||
51 | cmp al, 0x48 |
||
52 | jz .up |
||
53 | cmp al, 0x50 |
||
54 | jz .down |
||
55 | xor eax, eax |
||
56 | ret |
||
57 | .tab: |
||
58 | ; Tab pressed - insert "[autocomplete]" to current position |
||
59 | push esi edi |
||
60 | mov eax, [ppos] |
||
61 | mov eax, [eax] |
||
62 | mov ecx, [pn] |
||
63 | mov ecx, [ecx] |
||
64 | mov esi, [pstr] |
||
65 | mov esi, [esi] |
||
66 | add ecx, esi |
||
67 | add esi, eax |
||
68 | mov edx, esi |
||
69 | @@: |
||
70 | lodsb |
||
71 | test al, al |
||
72 | jnz @b |
||
73 | lea edi, [esi+str3.len] |
||
74 | cmp edi, ecx |
||
75 | jbe @f |
||
76 | mov edi, ecx |
||
77 | lea esi, [edi-str3.len] |
||
78 | @@: |
||
79 | cmp esi, edx |
||
80 | jbe @f |
||
81 | dec esi |
||
82 | dec edi |
||
83 | mov al, [esi] |
||
84 | mov [edi], al |
||
85 | jmp @b |
||
86 | @@: |
||
87 | cmp edi, ecx |
||
88 | jb @f |
||
89 | dec edi |
||
90 | @@: |
||
91 | mov ecx, edi |
||
92 | sub ecx, edx |
||
93 | mov edi, edx |
||
94 | mov esi, str3 |
||
95 | rep movsb |
||
96 | mov eax, [pstr] |
||
97 | sub edi, [eax] |
||
98 | mov eax, [ppos] |
||
99 | mov [eax], edi |
||
100 | pop edi esi |
||
101 | xor eax, eax |
||
102 | inc eax |
||
103 | ret |
||
104 | .f1: |
||
105 | ; F1 pressed - say message |
||
106 | push str4 |
||
107 | call [con_write_asciiz] |
||
108 | push str1 |
||
109 | call [con_write_asciiz] |
||
110 | push 2 |
||
111 | pop eax |
||
112 | ret |
||
113 | .up: |
||
114 | push esi |
||
115 | mov esi, str5 |
||
116 | mov ecx, str5.len |
||
117 | jmp @f |
||
118 | .down: |
||
119 | push esi |
||
120 | mov esi, str6 |
||
121 | mov ecx, str6.len |
||
122 | @@: |
||
123 | push edi |
||
124 | mov edi, [pstr] |
||
125 | mov edi, [edi] |
||
126 | mov eax, [ppos] |
||
127 | mov [eax], ecx |
||
128 | rep movsb |
||
129 | xor eax, eax |
||
130 | stosb |
||
131 | pop edi esi |
||
132 | inc eax |
||
133 | ret |
||
134 | endp |
||
135 | |||
136 | |||
137 | align 4 |
||
6699 | clevermous | 138 | data import |
139 | library console, 'console.dll' |
||
140 | import console, \ |
||
141 | con_init, 'con_init', \ |
||
142 | con_write_asciiz, 'con_write_asciiz', \ |
||
143 | con_exit, 'con_exit', \ |
||
144 | con_gets2, 'con_gets2' |
||
145 | end data |
||
852 | diamond | 146 | |
147 | caption db 'Console test - gets2()',0 |
||
148 | str1 db 'Enter string (empty for exit): ',0 |
||
149 | str2 db 'You entered: ',0 |
||
150 | str3 db '[autocomplete]' |
||
151 | str3.len = $ - str3 |
||
152 | str4 db 13,10,'Help? What help do you need?',13,10,0 |
||
153 | str5 db 'previous line in the history' |
||
154 | str5.len = $ - str5 |
||
155 | str6 db 'next line in the history' |
||
156 | str6.len = $ - str6 |
||
157 | |||
158 | s rb 256 |