Rev 1145 | Rev 2190 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
836 | diamond | 1 | ; Функции работы с консолью для программ КолибриОС |
852 | diamond | 2 | ; diamond, 2006-2008 |
836 | diamond | 3 | |
4 | |||
5 | format MS COFF |
||
6 | |||
7 | public EXPORTS |
||
8 | |||
9 | section '.flat' code readable align 16 |
||
10 | |||
11 | include 'font.inc' |
||
12 | include 'conscrl.inc' |
||
13 | |||
14 | ;void __stdcall START(dword state); |
||
15 | START: |
||
16 | ; N.B. The current kernel implementation does not require |
||
17 | ; evident heap initialization, because if DLL is loaded, heap is already initialized |
||
18 | ; (if heap was not initialized, loader does this implicitly). |
||
19 | ; So this action does nothing useful, but nothing harmful. |
||
20 | push 68 |
||
21 | pop eax |
||
22 | push 11 |
||
23 | pop ebx |
||
24 | int 0x40 |
||
25 | or eax, -1 |
||
26 | ret 4 |
||
27 | |||
28 | ; Инициализация консоли |
||
29 | ; void __stdcall con_init(dword wnd_width, dword wnd_height, |
||
30 | ; dword scr_width, dword scr_height, const char* title); |
||
31 | |||
32 | align 4 |
||
33 | con_init: |
||
34 | pop eax |
||
35 | pop [con.wnd_width] |
||
36 | pop [con.wnd_height] |
||
37 | pop [con.scr_width] |
||
38 | pop [con.scr_height] |
||
39 | pop [con.title] |
||
40 | push eax |
||
2170 | serge | 41 | |
42 | push ebx |
||
43 | |||
836 | diamond | 44 | mov ecx, 4 |
45 | mov eax, con.wnd_width |
||
2170 | serge | 46 | mov edx, con.def_wnd_width |
836 | diamond | 47 | .1: |
48 | cmp dword [eax], -1 |
||
49 | jnz @f |
||
2170 | serge | 50 | mov ebx, [edx] |
836 | diamond | 51 | mov [eax], ebx |
52 | @@: |
||
53 | add eax, 4 |
||
2170 | serge | 54 | add edx, 4 |
836 | diamond | 55 | loop .1 |
56 | ; allocate memory for console data & bitmap data |
||
57 | mov eax, [con.scr_width] |
||
58 | mul [con.scr_height] |
||
59 | lea ecx, [eax+eax] |
||
60 | mov eax, [con.wnd_width] |
||
61 | mul [con.wnd_height] |
||
62 | imul eax, font_width*font_height |
||
63 | mov ebx, eax |
||
64 | push ebx ecx |
||
65 | add ecx, eax |
||
66 | push 68 |
||
67 | pop eax |
||
68 | push 12 |
||
69 | pop ebx |
||
70 | int 0x40 |
||
71 | pop ecx ebx |
||
72 | mov edx, con.nomem_err |
||
73 | test eax, eax |
||
74 | jz con.fatal |
||
75 | mov [con.data], eax |
||
76 | push edi |
||
77 | mov edi, eax |
||
78 | shr ecx, 1 |
||
79 | mov ax, 0x0720 |
||
80 | rep stosw |
||
81 | mov ecx, ebx |
||
82 | mov [con.image], edi |
||
83 | xor eax, eax |
||
84 | rep stosb |
||
85 | pop edi |
||
1133 | diamond | 86 | and byte [con_flags+1], not 2 |
836 | diamond | 87 | ; create console thread |
88 | push 51 |
||
89 | pop eax |
||
90 | xor ebx, ebx |
||
91 | inc ebx |
||
92 | mov ecx, con.thread |
||
93 | mov edx, con.stack_top |
||
94 | int 0x40 |
||
95 | mov edx, con.thread_err |
||
96 | test eax, eax |
||
97 | js con.fatal |
||
98 | mov [con.console_tid], eax |
||
99 | pop ebx |
||
100 | ret |
||
101 | con.fatal: |
||
102 | ; output string to debug board and die |
||
103 | mov cl, [edx] |
||
104 | test cl, cl |
||
105 | jz @f |
||
106 | push 63 |
||
107 | pop eax |
||
108 | xor ebx, ebx |
||
109 | inc ebx |
||
110 | int 0x40 |
||
111 | inc edx |
||
112 | jmp con.fatal |
||
113 | @@: |
||
114 | or eax, -1 |
||
115 | int 0x40 |
||
116 | |||
117 | ; dword __stdcall con_get_flags(void); |
||
118 | con_get_flags: |
||
119 | mov eax, [con_flags] |
||
120 | ret |
||
121 | |||
122 | ; dword __stdcall con_set_flags(dword flags); |
||
123 | con_set_flags: |
||
124 | mov eax, [esp+4] |
||
1133 | diamond | 125 | and ah, not 2 |
836 | diamond | 126 | xchg eax, [con_flags] |
127 | ret 4 |
||
128 | |||
129 | ; dword __stdcall con_get_font_height(void); |
||
130 | con_get_font_height: |
||
131 | mov eax, font_height |
||
132 | ret |
||
133 | |||
134 | ; int __stdcall con_get_cursor_height(void); |
||
135 | con_get_cursor_height: |
||
136 | mov eax, [con.cursor_height] |
||
137 | ret |
||
138 | |||
139 | ; int __stdcall con_set_cursor_height(int new_height); |
||
140 | con_set_cursor_height: |
||
141 | mov eax, [esp+4] |
||
142 | cmp eax, font_height |
||
143 | jae @f |
||
144 | xchg eax, [con.cursor_height] |
||
145 | ret 4 |
||
146 | @@: |
||
147 | mov eax, [con.cursor_height] |
||
148 | ret 4 |
||
149 | |||
150 | ; void __stdcall con_write_asciiz(const char* string); |
||
151 | con_write_asciiz: |
||
152 | push ebx esi |
||
153 | or ebx, -1 |
||
154 | mov esi, [esp+12] |
||
155 | call con.write |
||
156 | pop esi ebx |
||
157 | ret 4 |
||
158 | |||
159 | ; void __stdcall con_write_string(const char* string, dword length); |
||
160 | con_write_length: |
||
161 | push ebx esi |
||
162 | mov esi, [esp+12] |
||
163 | mov ebx, [esp+16] |
||
164 | call con.write |
||
165 | pop esi ebx |
||
166 | ret 8 |
||
167 | |||
168 | ; Каждый символ классифицируется как один из |
||
169 | con.printfc.normal = 0 ; нормальный символ |
||
170 | con.printfc.percent = 1 ; '%' |
||
171 | con.printfc.dot = 2 ; '.' |
||
172 | con.printfc.asterisk = 3 ; '*' |
||
173 | con.printfc.zero = 4 ; '0' |
||
174 | con.printfc.digit = 5 ; ненулевая цифра |
||
175 | con.printfc.plus = 6 ; '+' |
||
176 | con.printfc.minus = 7 ; '-' |
||
177 | con.printfc.sharp = 8 ; '#' |
||
178 | con.printfc.space = 9 ; ' ' |
||
179 | con.printfc.long = 10 ; 'l' for 'long' |
||
180 | con.printfc.short = 11 ; 'h' for 'short' |
||
181 | con.printfc.dec = 12 ; 'd' = print decimal |
||
182 | con.printfc.oct = 13 ; 'o' = print octal |
||
183 | con.printfc.unsigned = 14 ; 'u' = print unsigned decimal |
||
184 | con.printfc.hex = 15 ; 'x' = print hexadecimal |
||
185 | con.printfc.pointer = 16 ; 'p' = print pointer |
||
186 | con.printfc.char = 17 ; 'c' = print char |
||
187 | con.printfc.string = 18 ; 's' = print string |
||
188 | |||
189 | macro set char,type |
||
190 | {store byte con.printfc.#type at con.charcodes + char - ' '} |
||
191 | |||
192 | con.charcodes: |
||
193 | times 'x'-' '+1 db con.printfc.normal |
||
194 | set '%', percent |
||
195 | set '.', dot |
||
196 | set '*', asterisk |
||
197 | set '0', zero |
||
198 | set '1', digit |
||
199 | set '2', digit |
||
200 | set '3', digit |
||
201 | set '4', digit |
||
202 | set '5', digit |
||
203 | set '6', digit |
||
204 | set '7', digit |
||
205 | set '8', digit |
||
206 | set '9', digit |
||
207 | set ' ', space |
||
208 | set '#', sharp |
||
209 | set '+', plus |
||
210 | set '-', minus |
||
211 | set 'X', hex |
||
212 | set 'x', hex |
||
213 | set 'c', char |
||
214 | set 'd', dec |
||
215 | set 'h', short |
||
216 | set 'i', dec |
||
217 | set 'l', long |
||
218 | set 'o', oct |
||
219 | set 'p', pointer |
||
220 | set 's', string |
||
221 | set 'u', unsigned |
||
222 | purge set |
||
223 | align 4 |
||
224 | con.charjump dd con_printf.normal |
||
225 | dd con_printf.percent |
||
226 | dd con_printf.dot |
||
227 | dd con_printf.asterisk |
||
228 | dd con_printf.zero |
||
229 | dd con_printf.digit |
||
230 | dd con_printf.plus |
||
231 | dd con_printf.minus |
||
232 | dd con_printf.sharp |
||
233 | dd con_printf.space |
||
234 | dd con_printf.long |
||
235 | dd con_printf.short |
||
236 | dd con_printf.dec |
||
237 | dd con_printf.oct |
||
238 | dd con_printf.unsigned |
||
239 | dd con_printf.hex |
||
240 | dd con_printf.pointer |
||
241 | dd con_printf.char |
||
242 | dd con_printf.string |
||
243 | |||
244 | ; int __cdecl con_printf(const char* format, ...) |
||
245 | con_printf: |
||
246 | xor eax, eax |
||
247 | pushad |
||
248 | call con.get_data_ptr |
||
249 | lea ebp, [esp+20h+8] |
||
250 | mov esi, [ebp-4] |
||
251 | sub esp, 64 ; reserve space for buffer |
||
252 | .loop: |
||
253 | xor eax, eax |
||
254 | lodsb |
||
255 | test al, al |
||
256 | jz .done |
||
257 | cmp al, '%' |
||
258 | jz .spec_begin |
||
259 | .normal: |
||
260 | call con.write_char_ex |
||
261 | inc dword [esp+64+28] |
||
262 | jmp .loop |
||
263 | .errspec: |
||
264 | .percent: |
||
265 | add esp, 12 |
||
266 | jmp .normal |
||
267 | .spec_begin: |
||
268 | xor ebx, ebx |
||
269 | ; bl = тип позиции: |
||
270 | ; 0 = начало |
||
271 | ; 1 = прочитан ведущий 0 в спецификации формата |
||
272 | ; 2 = читаем поле ширины |
||
273 | ; 3 = читаем поле точности |
||
274 | ; 4 = прочитано поле размера аргумента |
||
275 | ; 5 = читаем поле типа |
||
276 | ; bh = флаги: |
||
277 | ; 1 = флаг '#', выводить 0/0x/0X |
||
278 | ; 2 = флаг '-', выравнивание влево |
||
279 | ; 4 = флаг '0', дополнение нулями |
||
280 | ; 8 = флаг 'h', короткий аргумент |
||
281 | push -1 |
||
282 | ; dword [esp+8] = precision |
||
283 | push -1 |
||
284 | ; dword [esp+4] = width |
||
285 | push 0 |
||
286 | ; byte [esp] = флаг 0/'+'/' ' |
||
287 | .spec: |
||
288 | xor eax, eax |
||
289 | lodsb |
||
290 | test al, al |
||
291 | jz .done |
||
292 | cmp al, ' ' |
||
293 | jb .normal |
||
294 | cmp al, 'x' |
||
295 | ja .normal |
||
296 | movzx ecx, byte [con.charcodes + eax - ' '] |
||
297 | jmp [con.charjump + ecx*4] |
||
298 | |||
299 | .sharp: |
||
300 | test bl, bl |
||
301 | jnz .errspec |
||
302 | or bh, 1 |
||
303 | jmp .spec |
||
304 | .minus: |
||
305 | test bl, bl |
||
306 | jnz .errspec |
||
307 | or bh, 2 |
||
308 | jmp .spec |
||
309 | .plus: |
||
310 | .space: |
||
311 | test bl, bl |
||
312 | jnz .errspec |
||
313 | cmp byte [esp], '+' |
||
314 | jz .spec |
||
315 | mov byte [esp], al |
||
316 | jmp .spec |
||
317 | .zero: |
||
318 | test bl, bl |
||
319 | jnz .digit |
||
320 | test bh, 2 |
||
321 | jnz .spec |
||
322 | or bh, 4 |
||
323 | inc ebx |
||
324 | jmp .spec |
||
325 | .digit: |
||
326 | sub al, '0' |
||
327 | cmp bl, 2 |
||
328 | ja .precision |
||
329 | mov bl, 2 |
||
330 | xchg eax, [esp+4] |
||
331 | test eax, eax |
||
332 | js .spec |
||
333 | lea eax, [eax*5] |
||
334 | add eax, eax |
||
335 | add [esp+4], eax |
||
336 | jmp .spec |
||
337 | .precision: |
||
338 | cmp bl, 3 |
||
339 | jnz .errspec |
||
340 | xchg eax, [esp+8] |
||
341 | lea eax, [eax*5] |
||
342 | add eax, eax |
||
343 | add [esp+8], eax |
||
344 | jmp .spec |
||
345 | .asterisk: |
||
346 | mov eax, [ebp] |
||
347 | add ebp, 4 |
||
348 | cmp bl, 2 |
||
349 | ja .asterisk_precision |
||
350 | test eax, eax |
||
351 | jns @f |
||
352 | neg eax |
||
353 | or bh, 2 |
||
354 | @@: |
||
355 | mov [esp+4], eax |
||
356 | mov bl, 3 |
||
357 | jmp .spec |
||
358 | .asterisk_precision: |
||
359 | cmp bl, 3 |
||
360 | jnz .errspec |
||
361 | mov [esp+8], eax |
||
362 | inc ebx |
||
363 | jmp .spec |
||
364 | .dot: |
||
365 | cmp bl, 2 |
||
366 | ja .errspec |
||
367 | mov bl, 3 |
||
368 | and dword [esp+8], 0 |
||
369 | jmp .spec |
||
370 | .long: |
||
371 | cmp bl, 3 |
||
372 | ja .errspec |
||
373 | mov bl, 4 |
||
374 | jmp .spec |
||
375 | .short: |
||
376 | cmp bl, 3 |
||
377 | ja .errspec |
||
378 | mov bl, 4 |
||
379 | or bh, 8 |
||
380 | jmp .spec |
||
381 | .unsigned: |
||
382 | .dec: |
||
383 | push 10 |
||
384 | jmp .write_number |
||
385 | .pointer: |
||
386 | mov dword [esp+12], 8 |
||
387 | or bh, 4 |
||
388 | and bh, not 8 |
||
389 | .hex: |
||
390 | push 16 |
||
391 | jmp @f |
||
392 | .oct: |
||
393 | push 8 |
||
394 | @@: |
||
395 | mov byte [esp+4], 0 |
||
396 | .write_number: |
||
397 | pop ecx |
||
398 | push edi |
||
399 | lea edi, [esp+16+64-1] ; edi -> end of buffer |
||
400 | mov byte [edi], 0 |
||
401 | push edx |
||
402 | push eax |
||
403 | mov eax, [ebp] |
||
404 | add ebp, 4 |
||
405 | test bh, 8 |
||
406 | jz @f |
||
407 | movzx eax, ax |
||
408 | cmp byte [esp], 'd' |
||
409 | jnz @f |
||
410 | movsx eax, ax |
||
411 | @@: |
||
412 | xor edx, edx |
||
413 | test eax, eax |
||
414 | jns @f |
||
415 | cmp byte [esp], 'd' |
||
416 | jnz @f |
||
417 | inc edx |
||
418 | neg eax |
||
419 | @@: |
||
420 | push edx |
||
421 | xor edx, edx |
||
422 | ; число в eax, основание системы счисления в ecx |
||
423 | @@: |
||
424 | cmp dword [esp+16+8], 0 |
||
425 | jnz .print_num |
||
426 | test eax, eax |
||
427 | jz .zeronum |
||
428 | .print_num: |
||
429 | div ecx |
||
430 | xchg eax, edx |
||
431 | cmp al, 10 |
||
432 | sbb al, 69h |
||
433 | das |
||
434 | cmp byte [esp+4], 'x' |
||
435 | jnz @f |
||
436 | or al, 20h |
||
437 | @@: |
||
438 | dec edi |
||
439 | mov [edi], al |
||
440 | xor eax, eax |
||
441 | xchg eax, edx |
||
442 | test eax, eax |
||
443 | jnz .print_num |
||
444 | .zeronum: |
||
445 | push 0 |
||
446 | mov edx, [esp+12] |
||
447 | lea eax, [esp+32+64-1] |
||
448 | sub eax, edi |
||
449 | cmp dword [esp+20+8], -1 |
||
450 | jz .noprec1 |
||
451 | cmp eax, [esp+20+8] |
||
452 | jae .len_found1 |
||
453 | mov eax, [esp+20+8] |
||
454 | jmp .len_found1 |
||
455 | .noprec1: |
||
456 | test bh, 4 |
||
457 | jnz .do_print_num |
||
458 | .len_found1: |
||
459 | test bh, 2 |
||
460 | jnz .do_print_num |
||
461 | cmp byte [esp+20], 0 |
||
462 | jz @f |
||
463 | inc eax |
||
464 | @@: |
||
465 | cmp byte [esp+20], 0 |
||
466 | jnz @f |
||
467 | cmp byte [esp+4], 0 |
||
468 | jz @f |
||
469 | inc eax |
||
470 | @@: |
||
471 | test bh, 1 |
||
472 | jz .nosharp1 |
||
473 | cmp cl, 8 |
||
474 | jnz @f |
||
475 | inc eax |
||
476 | jmp .nosharp1 |
||
477 | @@: |
||
478 | cmp cl, 16 |
||
479 | jnz .nosharp1 |
||
480 | inc eax |
||
481 | inc eax |
||
482 | .nosharp1: |
||
483 | cmp dword [esp+20+4], -1 |
||
484 | jz .do_print_num |
||
485 | sub eax, [esp+20+4] |
||
486 | jae .do_print_num |
||
487 | push ecx |
||
488 | mov ecx, eax |
||
489 | mov al, ' ' |
||
490 | @@: |
||
491 | xchg edi, [esp+20] |
||
492 | call con.write_char_ex |
||
493 | inc dword [esp+24+12+64+28] |
||
494 | xchg edi, [esp+20] |
||
495 | inc dword [esp+4] |
||
496 | inc ecx |
||
497 | jnz @b |
||
498 | pop ecx |
||
499 | .do_print_num: |
||
500 | mov al, '-' |
||
501 | cmp byte [esp+4], 0 |
||
502 | jnz .write_sign |
||
503 | mov al, [esp+20] |
||
504 | test al, al |
||
505 | jz .sign_written |
||
506 | .write_sign: |
||
507 | call .num_write_char |
||
508 | .sign_written: |
||
509 | test bh, 1 |
||
510 | jz .nosharp2 |
||
511 | mov al, '0' |
||
512 | cmp cl, 8 |
||
513 | jz @f |
||
514 | cmp cl, 16 |
||
515 | jnz .nosharp2 |
||
516 | call .num_write_char |
||
517 | mov al, [esp+8] |
||
518 | @@: |
||
519 | call .num_write_char |
||
520 | .nosharp2: |
||
521 | lea ecx, [esp+32+64-1] |
||
522 | sub ecx, edi |
||
523 | cmp dword [esp+20+8], -1 |
||
524 | jz .noprec2 |
||
525 | sub ecx, [esp+20+8] |
||
526 | jmp .lead_zeroes |
||
527 | .noprec2: |
||
528 | test bh, 4 |
||
529 | jz .do_print_num2 |
||
530 | add ecx, [esp] |
||
531 | sub ecx, [esp+20+4] |
||
532 | .lead_zeroes: |
||
533 | jae .do_print_num2 |
||
534 | @@: |
||
535 | mov al, '0' |
||
536 | call .num_write_char |
||
537 | inc ecx |
||
538 | jnz @b |
||
539 | .do_print_num2: |
||
540 | mov al, [edi] |
||
541 | test al, al |
||
542 | jz .num_written |
||
543 | call .num_write_char |
||
544 | inc edi |
||
545 | jmp .do_print_num2 |
||
546 | .num_written: |
||
547 | pop ecx |
||
548 | mov edi, [esp+12] |
||
549 | cmp dword [esp+16+4], -1 |
||
550 | jz .num_written2 |
||
551 | @@: |
||
552 | cmp ecx, [esp+16+4] |
||
553 | jae .num_written2 |
||
554 | mov al, ' ' |
||
555 | call con.write_char |
||
556 | inc ecx |
||
557 | jmp @b |
||
558 | .num_written2: |
||
559 | add esp, 16 |
||
560 | .spec_done: |
||
561 | add esp, 12 |
||
562 | jmp .loop |
||
563 | .char: |
||
564 | mov ecx, [esp+4] |
||
565 | cmp ecx, -1 |
||
566 | jnz @f |
||
567 | inc ecx |
||
568 | @@: |
||
569 | test ecx, ecx |
||
570 | jnz @f |
||
571 | inc ecx |
||
572 | @@: |
||
573 | test bh, 2 |
||
574 | jnz .char_left_pad |
||
575 | mov al, ' ' |
||
576 | dec ecx |
||
577 | jz .nowidth |
||
578 | add [esp+12+64+28], ecx |
||
579 | @@: |
||
580 | call con.write_char |
||
581 | loop @b |
||
582 | .nowidth: |
||
583 | mov al, [ebp] |
||
584 | add ebp, 4 |
||
585 | jmp .percent |
||
586 | .char_left_pad: |
||
587 | mov al, [ebp] |
||
588 | add ebp, 4 |
||
589 | call con.write_char_ex |
||
590 | add [esp+12+64+28], ecx |
||
591 | dec ecx |
||
592 | jz .nowidth2 |
||
593 | mov al, ' ' |
||
594 | @@: |
||
595 | call con.write_char |
||
596 | loop @b |
||
597 | .nowidth2: |
||
598 | jmp .spec_done |
||
599 | .string: |
||
600 | push esi |
||
601 | mov esi, [ebp] |
||
602 | test esi, esi |
||
603 | jnz @f |
||
604 | mov esi, con.aNull |
||
605 | @@: |
||
606 | add ebp, 4 |
||
607 | or ecx, -1 |
||
608 | @@: |
||
609 | inc ecx |
||
610 | cmp byte [esi+ecx], 0 |
||
611 | jnz @b |
||
612 | cmp ecx, [esp+12] |
||
613 | jb @f |
||
614 | mov ecx, [esp+12] |
||
615 | @@: |
||
616 | test bh, 2 |
||
617 | jnz .write_string |
||
618 | cmp dword [esp+8], -1 |
||
619 | jz .write_string |
||
620 | push ecx |
||
621 | sub ecx, [esp+12] |
||
622 | jae .nospace |
||
623 | mov al, ' ' |
||
624 | @@: |
||
625 | call con.write_char |
||
626 | inc dword [esp+20+64+28] |
||
627 | inc ecx |
||
628 | jnz @b |
||
629 | .nospace: |
||
630 | pop ecx |
||
631 | .write_string: |
||
632 | jecxz .string_written |
||
633 | add dword [esp+16+64+28], ecx |
||
634 | push ecx |
||
635 | @@: |
||
636 | lodsb |
||
637 | call con.write_char_ex |
||
638 | loop @b |
||
639 | pop ecx |
||
640 | .string_written: |
||
641 | pop esi |
||
642 | test bh, 2 |
||
643 | jz .spec_done |
||
644 | cmp dword [esp+4], -1 |
||
645 | jz .spec_done |
||
646 | sub ecx, [esp+4] |
||
647 | jae .spec_done |
||
648 | mov al, ' ' |
||
649 | @@: |
||
650 | call con.write_char |
||
651 | inc dword [esp+12+64+28] |
||
652 | inc ecx |
||
653 | jnz @b |
||
654 | jmp .spec_done |
||
655 | .done: |
||
656 | add esp, 64 |
||
657 | popad |
||
658 | jmp con.update_screen |
||
659 | .num_write_char: |
||
660 | xchg edi, [esp+20] |
||
661 | call con.write_char_ex |
||
662 | inc dword [esp+24+12+64+28] |
||
663 | xchg edi, [esp+20] |
||
664 | inc dword [esp+4] |
||
665 | ret |
||
666 | |||
667 | con.write: |
||
668 | ; esi = string, ebx = length (ebx=-1 for ASCIIZ strings) |
||
669 | push edi |
||
670 | call con.get_data_ptr |
||
671 | test ebx, ebx |
||
672 | jz .done |
||
673 | .loop: |
||
674 | lodsb |
||
675 | cmp ebx, -1 |
||
676 | jnz @f |
||
677 | test al, al |
||
678 | jz .done |
||
679 | @@: |
||
680 | call con.write_char_ex |
||
681 | .next: |
||
682 | cmp ebx, -1 |
||
683 | jz .loop |
||
684 | dec ebx |
||
685 | jnz .loop |
||
686 | .done: |
||
687 | pop edi |
||
688 | jmp con.update_screen |
||
689 | |||
690 | con.get_data_ptr: |
||
691 | mov edi, [con.cur_y] |
||
692 | imul edi, [con.scr_width] |
||
693 | add edi, [con.cur_x] |
||
694 | add edi, edi |
||
695 | add edi, [con.data] |
||
696 | ret |
||
697 | |||
698 | con.write_char_ex: |
||
699 | test byte [con_flags+1], 1 |
||
700 | jz con.write_special_char |
||
701 | |||
702 | con.write_char: |
||
703 | push eax |
||
704 | stosb |
||
705 | mov al, byte [con_flags] |
||
706 | stosb |
||
707 | mov eax, [con.cur_x] |
||
708 | inc eax |
||
709 | mov [con.cur_x], eax |
||
710 | cmp eax, [con.scr_width] |
||
711 | jb @f |
||
712 | and [con.cur_x], 0 |
||
713 | call con.newline |
||
714 | @@: |
||
715 | pop eax |
||
716 | ret |
||
717 | |||
718 | con.write_special_char: |
||
719 | cmp [con_esc], 0 |
||
720 | jnz .esc_mode |
||
721 | .normal_mode: |
||
722 | cmp al, 10 |
||
723 | jz .write_lf |
||
724 | cmp al, 13 |
||
725 | jz .write_cr |
||
726 | cmp al, 27 |
||
727 | jz .write_esc |
||
728 | cmp al, 8 |
||
729 | jz .write_bs |
||
730 | cmp al, 9 |
||
731 | jnz con.write_char |
||
732 | .write_tab: |
||
733 | mov al, ' ' |
||
734 | call con.write_char |
||
735 | test [con.cur_x], 7 |
||
736 | jnz .write_tab |
||
737 | ret |
||
738 | .write_cr: |
||
739 | and [con.cur_x], 0 |
||
740 | jmp con.get_data_ptr |
||
741 | .write_lf: |
||
742 | and [con.cur_x], 0 |
||
743 | jmp con.newline |
||
744 | .write_bs: |
||
745 | cmp [con.cur_x], 0 |
||
746 | jz @f |
||
747 | dec [con.cur_x] |
||
748 | dec edi |
||
749 | dec edi |
||
750 | ret |
||
751 | @@: |
||
752 | push eax |
||
753 | mov eax, [con.cur_y] |
||
754 | dec eax |
||
755 | js @f |
||
756 | mov [con.cur_y], eax |
||
757 | mov eax, [con.scr_width] |
||
758 | dec eax |
||
759 | mov [con.cur_x], eax |
||
760 | dec edi |
||
761 | dec edi |
||
762 | @@: |
||
763 | pop eax |
||
764 | ret |
||
765 | .write_esc: |
||
766 | mov [con_esc], 1 |
||
767 | mov [con_esc_attr_n], 1 |
||
768 | and [con_esc_attrs], 0 |
||
769 | ret |
||
770 | .esc_mode: |
||
771 | cmp [con_sci], 0 |
||
772 | jnz .esc_sci |
||
773 | cmp al, '[' |
||
774 | jnz @f |
||
775 | mov [con_sci], 1 |
||
776 | ret |
||
777 | @@: |
||
778 | push eax |
||
779 | mov al, 27 |
||
780 | call con.write_char |
||
781 | pop eax |
||
782 | jmp con.write_char |
||
783 | .esc_sci: |
||
784 | ; this is real Esc sequence |
||
785 | cmp al, ';' |
||
786 | jz .next_arg |
||
787 | cmp al, '0' |
||
788 | jb .not_digit |
||
789 | cmp al, '9' |
||
790 | ja .not_digit |
||
791 | push eax ecx edx |
||
792 | sub al, '0' |
||
793 | movzx eax, al |
||
794 | mov ecx, [con_esc_attr_n] |
||
795 | mov edx, [con_esc_attrs+(ecx-1)*4] |
||
796 | lea edx, [edx*5] |
||
797 | lea edx, [edx*2+eax] |
||
798 | mov [con_esc_attrs+(ecx-1)*4], edx |
||
799 | pop edx ecx eax |
||
800 | ret |
||
801 | .next_arg: |
||
802 | push eax |
||
803 | mov eax, [con_esc_attr_n] |
||
804 | inc eax |
||
805 | cmp al, 4 |
||
806 | jbe @f |
||
807 | dec eax |
||
808 | @@: |
||
809 | mov [con_esc_attr_n], eax |
||
810 | and [con_esc_attrs+(eax-1)*4], 0 |
||
811 | pop eax |
||
812 | ret |
||
813 | .not_digit: |
||
814 | mov [con_esc], 0 |
||
815 | mov [con_sci], 0 ; in any case, leave Esc mode |
||
853 | diamond | 816 | cmp al, 'J' |
817 | jz .cls |
||
818 | cmp al, 'H' |
||
819 | jz .setcursor |
||
820 | cmp al, 'f' |
||
821 | jz .setcursor |
||
836 | diamond | 822 | cmp al, 'm' |
823 | jz .set_attr |
||
853 | diamond | 824 | cmp al, 'A' |
825 | jz .cursor_up |
||
826 | cmp al, 'B' |
||
827 | jz .cursor_down |
||
828 | cmp al, 'C' |
||
829 | jz .cursor_right |
||
830 | cmp al, 'D' |
||
831 | jz .cursor_left |
||
836 | diamond | 832 | ret ; simply skip unknown sequences |
853 | diamond | 833 | .cls: |
834 | push ecx |
||
835 | and [con.cur_x], 0 |
||
836 | and [con.cur_y], 0 |
||
837 | mov edi, [con.data] |
||
838 | push edi |
||
839 | mov ecx, [con.scr_width] |
||
840 | imul ecx, [con.scr_height] |
||
841 | mov ax, 0720h |
||
842 | rep stosw |
||
843 | pop edi ecx |
||
844 | .nosetcursor: |
||
845 | ret |
||
846 | .setcursor: |
||
847 | cmp [con_esc_attr_n], 2 |
||
848 | jnz .nosetcursor |
||
849 | mov eax, [con_esc_attrs] |
||
850 | cmp eax, [con.scr_width] |
||
851 | jae @f |
||
852 | mov [con.cur_x], eax |
||
853 | @@: |
||
854 | mov eax, [con_esc_attrs+4] |
||
855 | cmp eax, [con.scr_height+4] |
||
856 | jae @f |
||
857 | mov [con.cur_y], eax |
||
858 | .j_get_data: |
||
859 | jmp con.get_data_ptr |
||
860 | .cursor_up: |
||
861 | cmp [con_esc_attr_n], 1 |
||
862 | jnz .nosetcursor |
||
863 | mov eax, [con.cur_y] |
||
864 | sub eax, [con_esc_attrs] |
||
865 | jnc @f |
||
866 | xor eax, eax |
||
867 | @@: |
||
868 | mov [con.cur_y], eax |
||
869 | jmp .j_get_data |
||
870 | .cursor_down: |
||
871 | cmp [con_esc_attr_n], 1 |
||
872 | jnz .nosetcursor |
||
873 | mov eax, [con.cur_y] |
||
874 | add eax, [con_esc_attrs] |
||
875 | cmp eax, [con.scr_height] |
||
876 | jb @f |
||
877 | mov eax, [con.scr_height] |
||
878 | dec eax |
||
879 | @@: |
||
880 | mov [con.cur_y], eax |
||
881 | jmp .j_get_data |
||
882 | .cursor_right: |
||
883 | cmp [con_esc_attr_n], 1 |
||
884 | jnz .nosetcursor |
||
885 | mov eax, [con.cur_x] |
||
886 | add eax, [con_esc_attrs] |
||
887 | cmp eax, [con.scr_width] |
||
888 | jb @f |
||
889 | mov eax, [con.scr_width] |
||
890 | dec eax |
||
891 | @@: |
||
892 | mov [con.cur_x], eax |
||
893 | jmp .j_get_data |
||
894 | .cursor_left: |
||
895 | cmp [con_esc_attr_n], 1 |
||
896 | jnz .nosetcursor |
||
897 | mov eax, [con.cur_x] |
||
898 | sub eax, [con_esc_attrs] |
||
899 | jnc @f |
||
900 | xor eax, eax |
||
901 | @@: |
||
902 | mov [con.cur_x], eax |
||
903 | jmp .j_get_data |
||
836 | diamond | 904 | .set_attr: |
905 | push eax ecx edx |
||
906 | xor ecx, ecx |
||
907 | .set_one_attr: |
||
908 | mov eax, [con_esc_attrs+ecx*4] |
||
909 | cmp al, 0 |
||
910 | jz .attr_normal |
||
911 | cmp al, 1 |
||
912 | jz .attr_bold |
||
913 | cmp al, 5 |
||
914 | jz .attr_bgr_bold |
||
915 | cmp al, 7 |
||
916 | jz .attr_reversed |
||
917 | xor edx, edx |
||
918 | cmp al, 30 |
||
919 | jz .attr_color |
||
920 | mov dl, 4 |
||
921 | cmp al, 31 |
||
922 | jz .attr_color |
||
923 | mov dl, 2 |
||
924 | cmp al, 32 |
||
925 | jz .attr_color |
||
926 | mov dl, 6 |
||
927 | cmp al, 33 |
||
928 | jz .attr_color |
||
929 | mov dl, 1 |
||
930 | cmp al, 34 |
||
931 | jz .attr_color |
||
932 | mov dl, 5 |
||
933 | cmp al, 35 |
||
934 | jz .attr_color |
||
935 | mov dl, 3 |
||
936 | cmp al, 36 |
||
937 | jz .attr_color |
||
938 | mov dl, 7 |
||
939 | cmp al, 37 |
||
940 | jz .attr_color |
||
941 | xor edx, edx |
||
942 | cmp al, 40 |
||
943 | jz .attr_bgr_color |
||
944 | mov dl, 0x40 |
||
945 | cmp al, 41 |
||
946 | jz .attr_bgr_color |
||
947 | mov dl, 0x20 |
||
948 | cmp al, 42 |
||
949 | jz .attr_bgr_color |
||
950 | mov dl, 0x60 |
||
951 | cmp al, 43 |
||
952 | jz .attr_bgr_color |
||
953 | mov dl, 0x10 |
||
954 | cmp al, 44 |
||
955 | jz .attr_bgr_color |
||
956 | mov dl, 0x50 |
||
957 | cmp al, 45 |
||
958 | jz .attr_bgr_color |
||
959 | mov dl, 0x30 |
||
960 | cmp al, 46 |
||
961 | jz .attr_bgr_color |
||
962 | mov dl, 0x70 |
||
963 | cmp al, 47 |
||
964 | jnz .attr_continue |
||
965 | .attr_bgr_color: |
||
966 | mov eax, [con_flags] |
||
967 | and al, 0x8F |
||
968 | or al, dl |
||
969 | mov [con_flags], eax |
||
970 | jmp .attr_continue |
||
971 | .attr_color: |
||
972 | mov eax, [con_flags] |
||
973 | and al, 0xF8 |
||
974 | or al, dl |
||
975 | mov [con_flags], eax |
||
976 | jmp .attr_continue |
||
977 | .attr_normal: |
||
978 | mov byte [con_flags], 7 |
||
979 | jmp .attr_continue |
||
980 | .attr_reversed: |
||
981 | mov byte [con_flags], 0x70 |
||
982 | jmp .attr_continue |
||
983 | .attr_bold: |
||
984 | or byte [con_flags], 8 |
||
985 | jmp .attr_continue |
||
986 | .attr_bgr_bold: |
||
987 | or byte [con_flags], 0x80 |
||
988 | .attr_continue: |
||
989 | inc ecx |
||
990 | cmp ecx, [con_esc_attr_n] |
||
991 | jb .set_one_attr |
||
992 | pop edx ecx eax |
||
993 | ret |
||
994 | |||
995 | con.newline: |
||
996 | mov eax, [con.cur_y] |
||
997 | inc eax |
||
998 | mov [con.cur_y], eax |
||
999 | cmp eax, [con.scr_height] |
||
1000 | jb @f |
||
1001 | call con.scr_scroll_up |
||
1002 | @@: |
||
1003 | call con.get_data_ptr |
||
1004 | ret |
||
1005 | |||
1006 | con.scr_scroll_up: |
||
1007 | pushad |
||
1008 | mov edi, [con.data] |
||
1009 | mov esi, edi |
||
1010 | add esi, [con.scr_width] |
||
1011 | add esi, [con.scr_width] |
||
1012 | dec [con.cur_y] |
||
1013 | mov ecx, [con.scr_height] |
||
1014 | dec ecx |
||
1015 | imul ecx, [con.scr_width] |
||
1016 | shr ecx, 1 |
||
1017 | rep movsd |
||
1018 | adc ecx, ecx |
||
1019 | rep movsw |
||
1020 | mov ax, 0x0720 |
||
1021 | mov ecx, [con.scr_width] |
||
1022 | rep stosw |
||
1023 | popad |
||
1024 | ret |
||
1025 | |||
1026 | con.data2image: |
||
1027 | pushad |
||
1028 | mov edi, [con.image] |
||
1029 | mov esi, [con.data] |
||
1030 | mov eax, [con.wnd_ypos] |
||
1031 | mul [con.scr_width] |
||
1032 | add eax, [con.wnd_xpos] |
||
1033 | lea esi, [esi+eax*2] |
||
1034 | mov ecx, [con.wnd_height] |
||
1035 | .lh: |
||
1036 | push ecx |
||
1037 | mov ecx, [con.wnd_width] |
||
1038 | .lw: |
||
1039 | push ecx edi |
||
1040 | xor eax, eax |
||
1041 | mov al, [esi+1] |
||
1042 | push eax |
||
1043 | and al, 0xF |
||
1044 | mov ebx, eax ; цвет текста |
||
1045 | pop eax |
||
1046 | shr al, 4 |
||
1047 | mov ebp, eax ; цвет фона |
||
1048 | sub ebx, ebp |
||
1049 | lodsb |
||
1050 | inc esi |
||
1051 | if font_width > 8 |
||
1052 | lea edx, [eax+eax+font] |
||
1053 | else |
||
1054 | lea edx, [eax+font] |
||
1055 | end if |
||
1056 | .sh: |
||
1057 | mov ecx, [edx] |
||
1058 | repeat font_width |
||
1059 | shr ecx, 1 |
||
1060 | sbb eax, eax |
||
1061 | and eax, ebx |
||
1062 | add eax, ebp |
||
1063 | mov [edi+%-1], al |
||
1064 | end repeat |
||
1065 | mov eax, [con.wnd_width] |
||
1066 | ; imul eax, font_width |
||
1067 | ; add edi, eax |
||
1068 | if font_width = 6 |
||
1069 | lea eax, [eax*2+eax] |
||
1070 | lea edi, [edi+eax*2] |
||
1071 | else if font_width = 7 |
||
1072 | lea edi, [edi+eax*8] |
||
1073 | sub edi, eax |
||
1074 | else if font_width = 8 |
||
1075 | lea edi, [edi+eax*8] |
||
1076 | else if font_width = 9 |
||
1077 | lea edi, [edi+eax*8] |
||
1078 | add edi, eax |
||
1079 | else if font_width = 10 |
||
1080 | lea eax, [eax*4+eax] |
||
1081 | lea edi, [edi+eax*2] |
||
1082 | else |
||
1083 | Unknown font_width value! |
||
1084 | end if |
||
1085 | if font_width > 8 |
||
1086 | add edx, 256*2 |
||
1087 | cmp edx, font+256*2*font_height |
||
1088 | else |
||
1089 | add edx, 256 |
||
1090 | cmp edx, font+256*font_height |
||
1091 | end if |
||
1092 | jb .sh |
||
1093 | pop edi ecx |
||
1094 | add edi, font_width |
||
1095 | sub ecx, 1 |
||
1096 | jnz .lw |
||
1097 | mov eax, [con.wnd_width] |
||
1098 | imul eax, (font_height-1)*font_width |
||
1099 | add edi, eax |
||
1100 | pop ecx |
||
1101 | mov eax, [con.scr_width] |
||
1102 | sub eax, [con.wnd_width] |
||
1103 | lea esi, [esi+eax*2] |
||
1104 | dec ecx |
||
1105 | jnz .lh |
||
1106 | mov eax, [con.cur_y] |
||
1107 | sub eax, [con.wnd_ypos] |
||
1108 | jb .nocursor |
||
1109 | cmp eax, [con.wnd_height] |
||
1110 | jae .nocursor |
||
1111 | inc eax |
||
1112 | mul [con.wnd_width] |
||
1113 | imul eax, font_height*font_width |
||
1114 | mov edx, [con.cur_x] |
||
1115 | sub edx, [con.wnd_xpos] |
||
1116 | jb .nocursor |
||
1117 | cmp edx, [con.wnd_width] |
||
1118 | jae .nocursor |
||
1119 | inc edx |
||
1120 | imul edx, font_width |
||
1121 | add eax, edx |
||
1122 | add eax, [con.image] |
||
1123 | mov edx, [con.wnd_width] |
||
1124 | imul edx, font_width |
||
1125 | neg edx |
||
1126 | mov ecx, [con.cursor_height] |
||
1127 | jecxz .nocursor |
||
1128 | .cursor_loop: |
||
1129 | push ecx |
||
1130 | mov ecx, font_width |
||
1131 | add eax, edx |
||
1132 | push eax |
||
1133 | @@: |
||
1134 | xor byte [eax-1], 7 |
||
1135 | dec eax |
||
1136 | loop @b |
||
1137 | pop eax |
||
1138 | pop ecx |
||
1139 | loop .cursor_loop |
||
1140 | .nocursor: |
||
1141 | popad |
||
1142 | ret |
||
1143 | |||
1144 | con_exit: |
||
1145 | cmp byte [esp+4], 0 |
||
1146 | jz .noexit |
||
1147 | mov [con.thread_op], 1 |
||
1148 | call con.wake |
||
1149 | ret 4 |
||
1150 | .noexit: |
||
1151 | push esi |
||
1152 | mov esi, [con.title] |
||
1153 | mov edx, con.finished_title |
||
1154 | mov ecx, 255 |
||
1155 | call .strcpy |
||
1156 | mov esi, con.aFinished |
||
1157 | call .strcpy |
||
1158 | mov byte [edx], 0 |
||
1159 | pop esi |
||
1160 | and [con.cursor_height], 0 |
||
1161 | push con.finished_title |
||
1162 | call con_set_title |
||
1163 | ret 4 |
||
1164 | .strcpy: |
||
1165 | jecxz .ret |
||
1166 | @@: |
||
1167 | lodsb |
||
1168 | test al, al |
||
1169 | jz .ret |
||
1170 | mov [edx], al |
||
1171 | inc edx |
||
1172 | loop @b |
||
1173 | .ret: |
||
1174 | ret |
||
1175 | |||
1176 | con_set_title: |
||
1177 | mov eax, [esp+4] |
||
1178 | mov [con.title], eax |
||
1179 | mov [con.thread_op], 2 |
||
1180 | call con.wake |
||
1181 | ret 4 |
||
1182 | |||
1183 | ; int __stdcall con_kbhit(void); |
||
1184 | con_kbhit: |
||
1133 | diamond | 1185 | test byte [con_flags+1], 2 |
1186 | jnz @f |
||
836 | diamond | 1187 | mov eax, [con.input_start] |
1188 | cmp eax, [con.input_end] |
||
1133 | diamond | 1189 | @@: |
836 | diamond | 1190 | setnz al |
1191 | movzx eax, al |
||
1192 | ret |
||
1193 | |||
1194 | con.force_entered_char: |
||
1195 | cmp [con.entered_char], -1 |
||
1196 | jnz .ret |
||
1197 | mov [con.thread_op], 4 |
||
1198 | call con.wake |
||
1133 | diamond | 1199 | test byte [con_flags+1], 2 |
1200 | jnz .ret |
||
836 | diamond | 1201 | ; wait for response |
1202 | push ebx |
||
1203 | push 5 |
||
1204 | pop eax |
||
1205 | push 2 |
||
1206 | pop ebx |
||
1207 | @@: |
||
1208 | int 0x40 |
||
1209 | cmp [con.entered_char], -1 |
||
1210 | jz @b |
||
1211 | pop ebx |
||
1212 | .ret: |
||
1213 | ret |
||
1214 | |||
1215 | ; int __stdcall con_getch(void); |
||
1216 | con_getch: |
||
1217 | call con.force_entered_char |
||
1133 | diamond | 1218 | test byte [con_flags+1], 2 |
1219 | jnz con_getch_closed |
||
836 | diamond | 1220 | movzx eax, byte [con.entered_char] |
1221 | sar [con.entered_char], 8 |
||
1222 | mov byte [con.entered_char+1], 0xFF |
||
1223 | test al, al |
||
1224 | jz @f |
||
1225 | mov byte [con.entered_char], 0xFF |
||
1226 | @@: |
||
1227 | ret |
||
1228 | |||
1133 | diamond | 1229 | con_getch_closed: |
1145 | diamond | 1230 | xor eax, eax |
1133 | diamond | 1231 | ret |
1232 | |||
836 | diamond | 1233 | ; int __stdcall con_getch2(void); |
1234 | con_getch2: |
||
1235 | call con.force_entered_char |
||
1133 | diamond | 1236 | test byte [con_flags+1], 2 |
1237 | jnz con_getch_closed |
||
836 | diamond | 1238 | mov eax, 0xFFFF |
1239 | xchg ax, [con.entered_char] |
||
1240 | ret |
||
1241 | |||
1133 | diamond | 1242 | ; char* __stdcall con_gets(char* str, int n); |
836 | diamond | 1243 | con_gets: |
852 | diamond | 1244 | pop eax |
1245 | push 0 |
||
1246 | push eax |
||
1133 | diamond | 1247 | ; char* __stdcall con_gets2(con_gets2_callback callback, char* str, int n); |
852 | diamond | 1248 | con_gets2: |
1133 | diamond | 1249 | mov eax, [esp+8] ; str |
836 | diamond | 1250 | pushad |
1133 | diamond | 1251 | mov esi, eax ; str |
852 | diamond | 1252 | mov ebx, [esp+20h+12] ; n |
836 | diamond | 1253 | sub ebx, 1 |
1254 | jle .ret |
||
1255 | mov byte [esi], 0 |
||
1256 | xor ecx, ecx ; длина уже введённой строки |
||
1257 | call con.get_data_ptr |
||
1258 | .loop: |
||
852 | diamond | 1259 | call con_getch2 |
836 | diamond | 1260 | test al, al |
1261 | jz .extended |
||
1262 | cmp al, 8 |
||
1263 | jz .backspace |
||
1264 | cmp al, 27 |
||
1265 | jz .esc |
||
1266 | cmp al, 13 |
||
1267 | jz .enter |
||
852 | diamond | 1268 | cmp al, 9 |
1269 | jz .tab |
||
836 | diamond | 1270 | inc ecx |
1271 | mov dl, al |
||
1272 | call con.write_char_ex |
||
1273 | push [con.cur_x] |
||
1274 | push [con.cur_y] |
||
1275 | push edi |
||
1276 | push esi |
||
1277 | @@: |
||
1278 | lodsb |
||
1279 | mov [esi-1], dl |
||
1280 | mov dl, al |
||
1281 | test al, al |
||
1282 | jz @f |
||
1283 | call con.write_char_ex |
||
1284 | jmp @b |
||
1285 | @@: |
||
1286 | mov [esi], dl |
||
1287 | pop esi |
||
1288 | inc esi |
||
1289 | pop edi |
||
1290 | pop [con.cur_y] |
||
1291 | pop [con.cur_x] |
||
1292 | .update_screen_and_loop: |
||
1293 | call con.update_screen |
||
1294 | cmp ecx, ebx |
||
1295 | jb .loop |
||
852 | diamond | 1296 | .ret_us: |
836 | diamond | 1297 | mov edx, [con.cur_x] |
1298 | @@: |
||
1299 | lodsb |
||
1300 | test al, al |
||
1301 | jz @f |
||
1302 | inc edx |
||
1303 | cmp edx, [con.scr_width] |
||
1304 | jb @b |
||
1305 | xor edx, edx |
||
1306 | call con.newline |
||
1307 | jmp @b |
||
1308 | @@: |
||
1309 | mov [con.cur_x], edx |
||
1310 | call con.get_data_ptr |
||
1311 | call con.update_screen |
||
1312 | jmp .ret |
||
1313 | .esc: |
||
1314 | mov edx, [con.cur_x] |
||
1315 | @@: |
||
1316 | lodsb |
||
1317 | test al, al |
||
1318 | jz @f |
||
1319 | inc edx |
||
1320 | cmp edx, [con.scr_width] |
||
1321 | jb @b |
||
1322 | xor edx, edx |
||
1323 | call con.newline |
||
1324 | jmp @b |
||
1325 | @@: |
||
1326 | mov [con.cur_x], edx |
||
1327 | call con.get_data_ptr |
||
1328 | dec esi |
||
1329 | xor ecx, ecx |
||
1330 | @@: |
||
1331 | mov byte [esi], 0 |
||
852 | diamond | 1332 | cmp esi, [esp+20h+8] |
836 | diamond | 1333 | jbe .update_screen_and_loop |
1334 | mov al, 8 |
||
1335 | call con.write_special_char |
||
1336 | mov al, ' ' |
||
1337 | call con.write_char |
||
1338 | mov al, 8 |
||
1339 | call con.write_special_char |
||
1340 | dec esi |
||
1341 | jmp @b |
||
1342 | .delete: |
||
1343 | cmp byte [esi], 0 |
||
1344 | jz .loop |
||
1345 | lodsb |
||
1346 | call con.write_char_ex |
||
1347 | .backspace: |
||
852 | diamond | 1348 | cmp esi, [esp+20h+8] |
836 | diamond | 1349 | jbe .loop |
1350 | push esi |
||
1351 | mov edx, [con.cur_x] |
||
1352 | @@: |
||
1353 | lodsb |
||
1354 | test al, al |
||
1355 | jz @f |
||
1356 | inc edx |
||
1357 | cmp edx, [con.scr_width] |
||
1358 | jb @b |
||
1359 | xor edx, edx |
||
1360 | call con.newline |
||
1361 | jmp @b |
||
1362 | @@: |
||
1363 | mov [con.cur_x], edx |
||
1364 | call con.get_data_ptr |
||
1365 | dec esi |
||
1366 | mov al, 8 |
||
1367 | call con.write_special_char |
||
1368 | mov al, ' ' |
||
1369 | call con.write_char |
||
1370 | mov al, 8 |
||
1371 | call con.write_special_char |
||
1372 | mov dl, 0 |
||
1373 | @@: |
||
1374 | cmp esi, [esp] |
||
1375 | jbe @f |
||
1376 | mov al, 8 |
||
1377 | call con.write_special_char |
||
1378 | dec esi |
||
1379 | xchg dl, [esi] |
||
1380 | mov al, dl |
||
1381 | call con.write_char |
||
1382 | mov al, 8 |
||
1383 | call con.write_special_char |
||
1384 | jmp @b |
||
1385 | @@: |
||
1386 | pop esi |
||
1387 | dec esi |
||
1388 | mov [esi], dl |
||
1389 | dec ecx |
||
1390 | jmp .update_screen_and_loop |
||
1391 | .enter: |
||
1392 | mov edx, [con.cur_x] |
||
1393 | @@: |
||
1394 | lodsb |
||
1395 | test al, al |
||
1396 | jz @f |
||
1397 | inc edx |
||
1398 | cmp edx, [con.scr_width] |
||
1399 | jb @b |
||
1400 | xor edx, edx |
||
1401 | call con.newline |
||
1402 | jmp @b |
||
1403 | @@: |
||
1404 | mov [con.cur_x], edx |
||
1405 | call con.get_data_ptr |
||
1406 | mov al, 10 |
||
1407 | mov [esi-1], al |
||
1408 | mov byte [esi], 0 |
||
1409 | call con.write_special_char |
||
1410 | call con.update_screen |
||
1411 | jmp .ret |
||
852 | diamond | 1412 | .tab: |
1413 | mov al, 0 |
||
1414 | mov ah, 0xF |
||
836 | diamond | 1415 | .extended: |
1145 | diamond | 1416 | test ah, ah |
1417 | jz .closed |
||
852 | diamond | 1418 | xchg al, ah |
836 | diamond | 1419 | cmp al, 0x4B |
1420 | jz .left |
||
1421 | cmp al, 0x4D |
||
1422 | jz .right |
||
1423 | cmp al, 0x47 |
||
1424 | jz .home |
||
1425 | cmp al, 0x4F |
||
1426 | jz .end |
||
1427 | cmp al, 0x53 |
||
1428 | jz .delete |
||
852 | diamond | 1429 | ; give control to callback function |
1430 | cmp dword [esp+20h+4], 0 |
||
1431 | jz .loop |
||
1432 | ; remember length of text before and length of text after |
||
1433 | ; and advance cursor to the end of line |
||
1434 | push ecx |
||
1435 | push eax |
||
1436 | lea edx, [esi+1] |
||
1437 | @@: |
||
1438 | lodsb |
||
1439 | test al, al |
||
1440 | jz @f |
||
1441 | call con.write_char_ex |
||
1442 | jmp @b |
||
1443 | @@: |
||
1444 | sub esi, edx |
||
1445 | pop eax |
||
1446 | push esi |
||
1447 | dec edx |
||
1448 | sub edx, [esp+28h+8] |
||
1449 | push edx |
||
1450 | push esp ; ppos |
||
1451 | mov ecx, [esp+30h+4] |
||
1452 | lea edx, [esp+30h+12] |
||
1453 | push edx ; pn |
||
1454 | lea edx, [esp+34h+8] |
||
1455 | push edx ; pstr |
||
1456 | push eax ; keycode |
||
1457 | call ecx |
||
1458 | call con.get_data_ptr |
||
1459 | dec eax |
||
1460 | js .callback_nochange |
||
1461 | jz .callback_del |
||
1462 | dec eax |
||
1463 | jz .callback_output |
||
1464 | ; callback returned 2 - exit |
||
1465 | add esp, 12 |
||
1466 | jmp .ret |
||
1467 | .callback_nochange: |
||
1468 | ; callback returned 0 - string was not changed, only restore cursor position |
||
1469 | pop esi |
||
1470 | pop ecx |
||
1471 | test ecx, ecx |
||
1472 | jz .cncs |
||
1473 | @@: |
||
1474 | mov al, 8 |
||
1475 | call con.write_special_char |
||
1476 | loop @b |
||
1477 | .cncs: |
||
1478 | pop ecx |
||
1479 | add esi, [esp+20h+8] |
||
1480 | jmp .callback_done |
||
1481 | .callback_del: |
||
1482 | ; callback returned 1 - string was changed, delete old string and output new |
||
1483 | mov ecx, [esp+8] |
||
1484 | test ecx, ecx |
||
1485 | jz .cds |
||
1486 | @@: |
||
1487 | mov al, 8 |
||
1488 | call con.write_special_char |
||
1489 | mov al, ' ' |
||
1490 | call con.write_char_ex |
||
1491 | mov al, 8 |
||
1492 | call con.write_special_char |
||
1493 | loop @b |
||
1494 | .cds: |
||
1495 | .callback_output: |
||
1496 | ; callback returned 2 - string was changed, output new string |
||
1497 | pop edx |
||
1498 | pop esi |
||
1499 | pop ecx |
||
1500 | mov esi, [esp+20h+8] |
||
1501 | xor ecx, ecx |
||
1502 | @@: |
||
1503 | lodsb |
||
1504 | test al, al |
||
1505 | jz @f |
||
1506 | call con.write_char_ex |
||
1507 | inc ecx |
||
1508 | jmp @b |
||
1509 | @@: |
||
1510 | dec esi |
||
1511 | push ecx |
||
1512 | sub ecx, edx |
||
1513 | jz .cos |
||
1514 | @@: |
||
1515 | mov al, 8 |
||
1516 | call con.write_special_char |
||
1517 | dec esi |
||
1518 | loop @b |
||
1519 | .cos: |
||
1520 | pop ecx |
||
1521 | .callback_done: |
||
1522 | call con.update_screen |
||
1523 | mov ebx, [esp+20h+12] |
||
1524 | dec ebx |
||
1525 | cmp ecx, ebx |
||
1526 | jae .ret_us |
||
836 | diamond | 1527 | jmp .loop |
1528 | .left: |
||
852 | diamond | 1529 | cmp esi, [esp+20h+8] |
836 | diamond | 1530 | jbe .loop |
1531 | dec esi |
||
1532 | mov al, 8 |
||
1533 | call con.write_special_char |
||
1534 | jmp .update_screen_and_loop |
||
1535 | .right: |
||
1536 | cmp byte [esi], 0 |
||
1537 | jz .loop |
||
1538 | lodsb |
||
1539 | call con.write_char_ex |
||
1540 | jmp .update_screen_and_loop |
||
1541 | .home: |
||
852 | diamond | 1542 | cmp esi, [esp+20h+8] |
836 | diamond | 1543 | jz .update_screen_and_loop |
1544 | dec esi |
||
1545 | mov al, 8 |
||
1546 | call con.write_special_char |
||
1547 | jmp .home |
||
1548 | .end: |
||
1549 | lodsb |
||
1550 | test al, al |
||
1551 | jz @f |
||
1552 | call con.write_char_ex |
||
1553 | jmp .end |
||
1554 | @@: |
||
1555 | dec esi |
||
1556 | jmp .update_screen_and_loop |
||
1133 | diamond | 1557 | .closed: |
1558 | and dword [esp+1Ch], 0 |
||
836 | diamond | 1559 | .ret: |
1560 | popad |
||
852 | diamond | 1561 | ret 12 |
836 | diamond | 1562 | |
853 | diamond | 1563 | ; void __stdcall con_cls(); |
1564 | con_cls: |
||
1565 | push edi |
||
1566 | call con.write_special_char.cls |
||
1567 | pop edi |
||
1568 | call con.update_screen |
||
1569 | ret |
||
1570 | |||
1571 | ; void __stdcall con_get_cursor_pos(int* px, int* py); |
||
1572 | con_get_cursor_pos: |
||
1573 | push eax ecx |
||
1574 | mov eax, [esp+12] |
||
1575 | mov ecx, [con.cur_x] |
||
1576 | mov [eax], ecx |
||
1577 | mov eax, [esp+16] |
||
1578 | mov ecx, [con.cur_y] |
||
1579 | mov [eax], ecx |
||
1580 | pop ecx eax |
||
1581 | ret 8 |
||
1582 | |||
1583 | ; void __stdcall con_set_cursor_pos(int px, int py); |
||
1584 | con_set_cursor_pos: |
||
1585 | push eax |
||
1586 | mov eax, [esp+8] |
||
1587 | cmp eax, [con.scr_width] |
||
1588 | jae @f |
||
1589 | mov [con.cur_x], eax |
||
1590 | @@: |
||
1591 | mov eax, [esp+12] |
||
1592 | cmp eax, [con.scr_height] |
||
1593 | jae @f |
||
1594 | mov [con.cur_y], eax |
||
1595 | @@: |
||
1596 | pop eax |
||
1597 | call con.update_screen |
||
1598 | ret 8 |
||
1599 | |||
836 | diamond | 1600 | con.update_screen: |
1601 | push eax |
||
1602 | mov eax, [con.cur_y] |
||
1603 | sub eax, [con.wnd_ypos] |
||
1604 | jb .up |
||
1605 | cmp eax, [con.wnd_height] |
||
1606 | jb .done |
||
1607 | mov eax, [con.cur_y] |
||
1608 | sub eax, [con.wnd_height] |
||
1609 | inc eax |
||
1610 | jmp .set |
||
1611 | .up: |
||
1612 | mov eax, [con.cur_y] |
||
1613 | .set: |
||
1614 | mov [con.wnd_ypos], eax |
||
1615 | .done: |
||
1616 | pop eax |
||
1617 | mov [con.thread_op], 3 |
||
1618 | |||
1619 | con.wake: |
||
1620 | pushad |
||
1621 | mov al, [con.thread_op] |
||
1622 | cmp al, byte [con.ipc_buf+0x10] |
||
1623 | jz .ret |
||
1624 | @@: |
||
1625 | push 60 |
||
1626 | pop eax |
||
1627 | push 2 |
||
1628 | pop ebx |
||
1629 | mov ecx, [con.console_tid] |
||
1133 | diamond | 1630 | jecxz .ret |
836 | diamond | 1631 | mov edx, con.thread_op |
1632 | push 1 |
||
1633 | pop esi |
||
1634 | int 0x40 |
||
1635 | test eax, eax |
||
1636 | jz @f |
||
1637 | push 5 |
||
1638 | pop eax |
||
1639 | mov bl, 1 |
||
1640 | int 0x40 |
||
1641 | jmp @b |
||
1642 | @@: |
||
1643 | .ret: |
||
1644 | popad |
||
1645 | ret |
||
1646 | |||
1647 | ; Поток окна консоли. Обрабатывает ввод и вывод. |
||
1648 | con.thread: |
||
1649 | ; Поток реагирует на IPC, которое используется только для того, чтобы его можно было "разбудить" |
||
1650 | push 40 |
||
1651 | pop eax |
||
1652 | push 0x67 |
||
1653 | pop ebx |
||
1654 | int 0x40 |
||
1655 | mov al, 60 |
||
1656 | mov bl, 1 |
||
1657 | mov ecx, con.ipc_buf |
||
1658 | push 0x11 |
||
1659 | pop edx |
||
1660 | int 0x40 |
||
1661 | mov al, 66 |
||
1662 | mov bl, 1 |
||
1663 | mov ecx, ebx |
||
1664 | int 0x40 |
||
1665 | con.redraw: |
||
1666 | call con.draw_window |
||
1667 | con.msg_loop: |
||
1668 | cmp dword [con.bUpPressed], 0 |
||
1669 | jnz .wait_timeout |
||
1670 | push 10 |
||
1671 | pop eax |
||
1672 | jmp @f |
||
1673 | .wait_timeout: |
||
1674 | push 23 |
||
1675 | pop eax |
||
1676 | push 5 |
||
1677 | pop ebx |
||
1678 | @@: |
||
1679 | int 0x40 |
||
1680 | dec eax |
||
1681 | jz con.redraw |
||
1682 | dec eax |
||
1683 | jz con.key |
||
1684 | dec eax |
||
1685 | jz con.button |
||
1686 | cmp al, 4 |
||
1687 | jz con.ipc |
||
1688 | jmp con.mouse |
||
1689 | con.button: |
||
1690 | ; we have only one button, close |
||
1691 | con.thread_exit: |
||
1133 | diamond | 1692 | or byte [con_flags+1], 2 |
1693 | and [con.console_tid], 0 |
||
1134 | diamond | 1694 | and [con.entered_char], 0 |
836 | diamond | 1695 | or eax, -1 |
1696 | int 0x40 |
||
1697 | con.key: |
||
1698 | mov al, 2 |
||
1699 | int 0x40 |
||
1700 | ; ah = scancode |
||
1701 | cmp ah, 0xE0 |
||
1702 | jnz @f |
||
1703 | mov [con.bWasE0], 1 |
||
1704 | jmp con.msg_loop |
||
1705 | @@: |
||
1706 | shr eax, 8 |
||
1707 | xchg ah, [con.bWasE0] |
||
1708 | test al, al |
||
1709 | jle con.msg_loop |
||
1710 | cmp al, 0x1D |
||
1711 | jz con.msg_loop |
||
1712 | cmp al, 0x2A |
||
1713 | jz con.msg_loop |
||
1714 | cmp al, 0x36 |
||
1715 | jz con.msg_loop |
||
1716 | cmp al, 0x38 |
||
1717 | jz con.msg_loop |
||
1718 | cmp al, 0x3A |
||
1719 | jz con.msg_loop |
||
1720 | cmp al, 0x45 |
||
1721 | jz con.msg_loop |
||
1722 | cmp al, 0x46 |
||
1723 | jz con.msg_loop |
||
1724 | mov edx, eax |
||
1725 | push 66 |
||
1726 | pop eax |
||
1727 | push 3 |
||
1728 | pop ebx |
||
1729 | int 0x40 ; eax = control key state |
||
1730 | test dh, dh |
||
1731 | jnz .extended |
||
1732 | bt [scan_has_ascii], edx |
||
1733 | jnc .extended |
||
1734 | test al, 0x30 |
||
1735 | jnz .extended |
||
1736 | ; key has ASCII code |
||
1737 | push eax edx |
||
1738 | push 2 |
||
1739 | pop ecx |
||
1740 | test al, 3 |
||
1741 | jnz @f |
||
1742 | dec ecx |
||
1743 | @@: |
||
1744 | push 26 |
||
1745 | pop eax |
||
1746 | mov bl, 2 |
||
1747 | mov edx, con.kbd_layout |
||
1748 | int 0x40 |
||
1749 | pop edx eax |
||
1750 | mov dh, [con.kbd_layout+edx] |
||
1751 | test al, 0xC |
||
1752 | jz @f |
||
1753 | sub dh, 0x60 |
||
1754 | jmp @f |
||
1755 | .extended: |
||
1756 | mov dh, 0 ; no ASCII code |
||
1757 | @@: |
||
1758 | ; dh contains ASCII-code; now convert scancode to extended key code |
||
1759 | mov ecx, con.extended_alt |
||
1760 | test al, 0x30 |
||
1761 | jnz .xlat |
||
1762 | mov ecx, con.extended_shift |
||
1763 | test al, 3 |
||
1764 | jnz .xlat |
||
1765 | mov ecx, con.extended_ctrl |
||
1766 | test al, 0xC |
||
1767 | jnz .xlat |
||
1768 | xchg dl, dh |
||
1769 | cmp dh, 0x57 |
||
1770 | jz @f |
||
1771 | cmp dh, 0x58 |
||
1772 | jnz .gotcode |
||
1773 | @@: |
||
1774 | add dh, 0x85-0x57 |
||
1775 | jmp .gotcode |
||
1776 | .xlat: |
||
1777 | movzx eax, dl |
||
1778 | mov dl, dh |
||
1779 | mov dh, [eax+ecx] |
||
1780 | .gotcode: |
||
1781 | test dh, dh |
||
1782 | jz con.msg_loop |
||
1783 | cmp dh, 0x94 |
||
1784 | jnz @f |
||
1785 | mov dl, 0 |
||
1786 | @@: |
||
1787 | ; dx contains full keycode |
||
1788 | cmp [con.bGetchRequested], 0 |
||
1789 | jz @f |
||
1790 | mov [con.entered_char], dx |
||
1791 | jmp con.msg_loop |
||
1792 | @@: |
||
1793 | mov eax, [con.input_end] |
||
1794 | mov ecx, eax |
||
1795 | add eax, 2 |
||
1796 | cmp eax, con.input_buffer_end |
||
1797 | jnz @f |
||
1798 | mov eax, con.input_buffer |
||
1799 | @@: |
||
1800 | cmp eax, [con.input_start] |
||
1801 | jnz @f |
||
1802 | ; buffer overflow, make beep and continue |
||
1803 | push 55 |
||
1804 | pop eax |
||
1805 | mov ebx, eax |
||
1806 | mov esi, con.beep |
||
1807 | int 0x40 |
||
1808 | jmp con.msg_loop |
||
1809 | @@: |
||
1810 | mov [ecx], dx |
||
1811 | mov [con.input_end], eax |
||
1812 | jmp con.msg_loop |
||
1813 | con.ipc: |
||
1814 | movzx eax, byte [con.ipc_buf+0x10] |
||
1815 | mov byte [con.ipc_buf+4], 8 |
||
1816 | mov byte [con.ipc_buf+0x10], 0 |
||
1817 | dec eax |
||
1818 | jz con.thread_exit |
||
1819 | dec eax |
||
1820 | jz con.set_title |
||
1821 | dec eax |
||
1822 | jz con.redraw_image |
||
1823 | dec eax |
||
1824 | jz con.getch |
||
1825 | jmp con.msg_loop |
||
1826 | con.set_title: |
||
1827 | push 71 |
||
1828 | pop eax |
||
1829 | push 1 |
||
1830 | pop ebx |
||
1831 | mov ecx, [con.title] |
||
1832 | int 0x40 |
||
1833 | jmp con.msg_loop |
||
1834 | con.redraw_image: |
||
1835 | call con.data2image |
||
1836 | call con.draw_image |
||
1837 | jmp con.msg_loop |
||
1838 | con.getch: |
||
1839 | mov eax, [con.input_start] |
||
1840 | cmp eax, [con.input_end] |
||
1841 | jz .noinput |
||
1842 | mov ecx, [eax] |
||
1843 | mov [con.entered_char], cx |
||
1844 | inc eax |
||
1845 | inc eax |
||
1846 | cmp eax, con.input_buffer_end |
||
1847 | jnz @f |
||
1848 | mov eax, con.input_buffer |
||
1849 | @@: |
||
1850 | mov [con.input_start], eax |
||
1851 | jmp con.msg_loop |
||
1852 | .noinput: |
||
1853 | mov [con.bGetchRequested], 1 |
||
1854 | jmp con.msg_loop |
||
1855 | con.mouse: |
||
1856 | xor eax, eax |
||
1857 | xchg eax, dword [con.bUpPressed] |
||
1858 | mov dword [con.bUpPressed_saved], eax |
||
1859 | push 37 |
||
1860 | pop eax |
||
1861 | push 2 |
||
1862 | pop ebx |
||
1863 | int 0x40 |
||
1864 | test al, 1 |
||
1865 | jnz @f |
||
1866 | cmp [con.vscroll_pt], -1 |
||
1867 | jz .redraw_if_needed |
||
1868 | or [con.vscroll_pt], -1 |
||
1869 | .redraw_if_needed: |
||
1870 | cmp dword [con.bUpPressed_saved], 0 |
||
1871 | jnz con.redraw_image |
||
1872 | jmp con.msg_loop |
||
1873 | @@: |
||
1874 | mov al, 37 |
||
1875 | dec ebx |
||
1876 | int 0x40 |
||
1877 | movsx ebx, ax |
||
1878 | sar eax, 16 |
||
1879 | cmp [con.vscroll_pt], -1 |
||
1880 | jnz .vscrolling |
||
1881 | test ebx, ebx |
||
1882 | js .redraw_if_needed |
||
1883 | sub ax, [con.data_width] |
||
1884 | jb .redraw_if_needed |
||
1885 | cmp eax, con.vscroll_width |
||
1886 | jae .redraw_if_needed |
||
1887 | cmp ebx, con.vscroll_btn_height |
||
1888 | jb .up |
||
1889 | sub bx, [con.data_height] |
||
1890 | jae .redraw_if_needed |
||
1891 | cmp bx, -con.vscroll_btn_height |
||
1892 | jge .down |
||
1893 | add bx, [con.data_height] |
||
1894 | sub bx, word [con.vscrollbar_pos] |
||
1895 | jl .vscroll_up |
||
1896 | cmp bx, word [con.vscrollbar_size] |
||
1897 | jl .vscroll |
||
1898 | .vscroll_down: |
||
1899 | cmp [con.bScrollingDown_saved], 0 |
||
1900 | jz .vscroll_down_first |
||
1901 | cmp [con.bScrollingDown_saved], 1 |
||
1902 | jz .vscroll_down_wasfirst |
||
1903 | mov [con.bScrollingDown], 2 |
||
1904 | .vscroll_down_do: |
||
1905 | mov eax, [con.wnd_ypos] |
||
1906 | add eax, [con.wnd_height] |
||
1907 | dec eax |
||
1908 | mov ebx, [con.scr_height] |
||
1909 | sub ebx, [con.wnd_height] |
||
1910 | cmp eax, ebx |
||
1911 | jb @f |
||
1912 | mov eax, ebx |
||
1913 | @@: |
||
1914 | mov [con.wnd_ypos], eax |
||
1915 | jmp con.redraw_image |
||
1916 | .vscroll_down_first: |
||
1917 | push 26 |
||
1918 | pop eax |
||
1919 | push 9 |
||
1920 | pop ebx |
||
1921 | int 0x40 |
||
1922 | mov [con.scroll_down_first_time], eax |
||
1923 | mov [con.bScrollingDown], 1 |
||
1924 | jmp .vscroll_down_do |
||
1925 | .vscroll_down_wasfirst: |
||
1926 | push 26 |
||
1927 | pop eax |
||
1928 | push 9 |
||
1929 | pop ebx |
||
1930 | int 0x40 |
||
1931 | sub eax, [con.scroll_down_first_time] |
||
1932 | cmp eax, 25 |
||
1933 | jb @f |
||
1934 | mov [con.bScrollingDown], 2 |
||
1935 | jmp .vscroll_down_do |
||
1936 | @@: |
||
1937 | mov [con.bScrollingDown], 1 |
||
1938 | jmp con.msg_loop |
||
1939 | .vscroll_up: |
||
1940 | cmp [con.bScrollingUp_saved], 0 |
||
1941 | jz .vscroll_up_first |
||
1942 | cmp [con.bScrollingUp_saved], 1 |
||
1943 | jz .vscroll_up_wasfirst |
||
1944 | mov [con.bScrollingUp], 2 |
||
1945 | .vscroll_up_do: |
||
1946 | mov eax, [con.wnd_ypos] |
||
1947 | inc eax |
||
1948 | sub eax, [con.wnd_height] |
||
1949 | jns @f |
||
1950 | xor eax, eax |
||
1951 | @@: |
||
1952 | mov [con.wnd_ypos], eax |
||
1953 | jmp con.redraw_image |
||
1954 | .vscroll_up_first: |
||
1955 | push 26 |
||
1956 | pop eax |
||
1957 | push 9 |
||
1958 | pop ebx |
||
1959 | int 0x40 |
||
1960 | mov [con.scroll_up_first_time], eax |
||
1961 | mov [con.bScrollingUp], 1 |
||
1962 | jmp .vscroll_up_do |
||
1963 | .vscroll_up_wasfirst: |
||
1964 | push 26 |
||
1965 | pop eax |
||
1966 | push 9 |
||
1967 | pop ebx |
||
1968 | int 0x40 |
||
1969 | sub eax, [con.scroll_up_first_time] |
||
1970 | cmp eax, 25 |
||
1971 | jb @f |
||
1972 | mov [con.bScrollingUp], 2 |
||
1973 | jmp .vscroll_up_do |
||
1974 | @@: |
||
1975 | mov [con.bScrollingUp], 1 |
||
1976 | jmp con.msg_loop |
||
1977 | .up: |
||
1978 | cmp [con.bUpPressed_saved], 0 |
||
1979 | jz .up_first |
||
1980 | cmp [con.bUpPressed_saved], 1 |
||
1981 | jz .up_wasfirst |
||
1982 | mov [con.bUpPressed], 2 |
||
1983 | .up_do: |
||
1984 | mov eax, [con.wnd_ypos] |
||
1985 | dec eax |
||
1986 | js @f |
||
1987 | mov [con.wnd_ypos], eax |
||
1988 | @@: |
||
1989 | jmp con.redraw_image |
||
1990 | .up_first: |
||
1991 | push 26 |
||
1992 | pop eax |
||
1993 | push 9 |
||
1994 | pop ebx |
||
1995 | int 0x40 |
||
1996 | mov [con.up_first_time], eax |
||
1997 | mov [con.bUpPressed], 1 |
||
1998 | jmp .up_do |
||
1999 | .up_wasfirst: |
||
2000 | push 26 |
||
2001 | pop eax |
||
2002 | push 9 |
||
2003 | pop ebx |
||
2004 | int 0x40 |
||
2005 | sub eax, [con.up_first_time] |
||
2006 | cmp eax, 25 |
||
2007 | jb @f |
||
2008 | mov [con.bUpPressed], 2 |
||
2009 | jmp .up_do |
||
2010 | @@: |
||
2011 | mov [con.bUpPressed], 1 |
||
2012 | jmp con.msg_loop |
||
2013 | .down: |
||
2014 | cmp [con.bDownPressed_saved], 0 |
||
2015 | jz .down_first |
||
2016 | cmp [con.bDownPressed_saved], 1 |
||
2017 | jz .down_wasfirst |
||
2018 | mov [con.bDownPressed], 2 |
||
2019 | .down_do: |
||
2020 | mov eax, [con.scr_height] |
||
2021 | sub eax, [con.wnd_height] |
||
2022 | jbe con.redraw_image |
||
2023 | cmp [con.wnd_ypos], eax |
||
2024 | jae con.redraw_image |
||
2025 | inc [con.wnd_ypos] |
||
2026 | jmp con.redraw_image |
||
2027 | .down_first: |
||
2028 | push 26 |
||
2029 | pop eax |
||
2030 | push 9 |
||
2031 | pop ebx |
||
2032 | int 0x40 |
||
2033 | mov [con.down_first_time], eax |
||
2034 | mov [con.bDownPressed], 1 |
||
2035 | jmp .down_do |
||
2036 | .down_wasfirst: |
||
2037 | push 26 |
||
2038 | pop eax |
||
2039 | push 9 |
||
2040 | pop ebx |
||
2041 | int 0x40 |
||
2042 | sub eax, [con.down_first_time] |
||
2043 | cmp eax, 25 |
||
2044 | jb @f |
||
2045 | mov [con.bDownPressed], 2 |
||
2046 | jmp .down_do |
||
2047 | @@: |
||
2048 | mov [con.bDownPressed], 1 |
||
2049 | jmp con.msg_loop |
||
2050 | .vscroll: |
||
2051 | mov [con.vscroll_pt], ebx |
||
2052 | call con.draw_image |
||
2053 | jmp con.msg_loop |
||
2054 | .vscrolling: |
||
2055 | sub ebx, [con.vscroll_pt] |
||
2056 | sub ebx, con.vscroll_btn_height |
||
2057 | jge @f |
||
2058 | xor ebx, ebx |
||
2059 | @@: |
||
2060 | movzx eax, [con.data_height] |
||
2061 | sub eax, 2*con.vscroll_btn_height |
||
2062 | sub eax, [con.vscrollbar_size] |
||
2063 | cmp ebx, eax |
||
2064 | jb @f |
||
2065 | lea ebx, [eax-1] |
||
2066 | @@: |
||
2067 | xchg eax, ebx |
||
2068 | mov edx, [con.scr_height] |
||
2069 | sub edx, [con.wnd_height] |
||
2070 | inc edx |
||
2071 | mul edx |
||
2072 | div ebx |
||
2073 | cmp [con.wnd_ypos], eax |
||
2074 | jz con.msg_loop |
||
2075 | mov [con.wnd_ypos], eax |
||
2076 | jmp con.redraw_image |
||
2077 | |||
2078 | con.draw_window: |
||
2079 | push 12 |
||
2080 | pop eax |
||
2081 | xor ebx, ebx |
||
2082 | inc ebx |
||
2083 | int 0x40 |
||
2084 | mov al, 48 |
||
2085 | mov bl, 4 |
||
2086 | int 0x40 |
||
2087 | mov ebx, [con.def_wnd_x-2] |
||
2088 | mov bx, word [con.wnd_width] |
||
2089 | imul bx, font_width |
||
2090 | add bx, 5+5-1 |
||
2091 | mov ecx, [con.def_wnd_y-2] |
||
2092 | mov cx, word [con.wnd_height] |
||
2093 | imul cx, font_height |
||
2094 | lea ecx, [ecx+eax+5-1] |
||
2095 | mov edx, 0x33000000 |
||
2096 | mov edi, [con.title] |
||
2097 | ; place for scrollbar |
||
2098 | mov eax, [con.wnd_height] |
||
2099 | cmp eax, [con.scr_height] |
||
2100 | jae @f |
||
2101 | add ebx, con.vscroll_width |
||
2102 | @@: |
||
2103 | xor eax, eax |
||
2104 | int 0x40 |
||
2105 | call con.draw_image |
||
2106 | push 12 |
||
2107 | pop eax |
||
2108 | push 2 |
||
2109 | pop ebx |
||
2110 | int 0x40 |
||
2111 | ret |
||
2112 | |||
2113 | con.draw_image: |
||
2114 | xor edx, edx |
||
2115 | mov ecx, [con.wnd_width] |
||
2116 | imul ecx, font_width |
||
2117 | mov [con.data_width], cx |
||
2118 | shl ecx, 16 |
||
2119 | mov cx, word [con.wnd_height] |
||
2120 | imul cx, font_height |
||
2121 | mov [con.data_height], cx |
||
2122 | mov ebx, [con.image] |
||
2123 | push 65 |
||
2124 | pop eax |
||
2125 | xor ebp, ebp |
||
2126 | mov edi, con.colors |
||
2127 | push 8 |
||
2128 | pop esi |
||
2129 | int 0x40 |
||
2130 | mov al, 7 |
||
2131 | mov edx, [con.wnd_height] |
||
2132 | cmp edx, [con.scr_height] |
||
2133 | jae .skip_vscroll |
||
2134 | push ecx |
||
2135 | mov edx, ecx |
||
2136 | xor dx, dx |
||
2137 | mov ebx, con.vscroll_btn3 |
||
2138 | cmp [con.bUpPressed], 0 |
||
2139 | jnz @f |
||
2140 | mov ebx, con.vscroll_btn1 |
||
2141 | @@: |
||
2142 | mov ecx, con.vscroll_width*65536 + con.vscroll_btn_height |
||
2143 | int 0x40 |
||
2144 | pop edx |
||
2145 | sub dx, con.vscroll_btn_height |
||
2146 | mov ebx, con.vscroll_btn4 |
||
2147 | cmp [con.bDownPressed], 0 |
||
2148 | jnz @f |
||
2149 | mov ebx, con.vscroll_btn2 |
||
2150 | @@: |
||
2151 | int 0x40 |
||
2152 | push edx |
||
2153 | ; Вычисляем высоту бегунка |
||
2154 | mov ax, dx |
||
2155 | sub eax, con.vscroll_btn_height |
||
2156 | mov ecx, eax |
||
2157 | mul [con.wnd_height] |
||
2158 | div [con.scr_height] |
||
2159 | cmp eax, 5 |
||
2160 | jae @f |
||
2161 | mov al, 5 |
||
2162 | @@: |
||
2163 | ; eax = высота бегунка. Вычисляем положение бегунка |
||
2164 | mov [con.vscrollbar_size], eax |
||
2165 | xchg eax, ecx |
||
2166 | sub eax, ecx |
||
2167 | mul [con.wnd_ypos] |
||
2168 | mov ebx, [con.scr_height] |
||
2169 | sub ebx, [con.wnd_height] |
||
2170 | div ebx |
||
2171 | pop edx |
||
2172 | push edx |
||
2173 | ; ecx = высота бегунка, eax = положение |
||
2174 | add eax, con.vscroll_btn_height |
||
2175 | mov [con.vscrollbar_pos], eax |
||
2176 | mov ebx, con.vscroll_bgr2 |
||
2177 | cmp [con.bScrollingUp], 0 |
||
2178 | jnz @f |
||
2179 | mov ebx, con.vscroll_bgr1 |
||
2180 | @@: |
||
2181 | mov ecx, con.vscroll_width*65536 + con.vscroll_bgr_height |
||
2182 | push eax |
||
2183 | push 7 |
||
2184 | pop eax |
||
2185 | mov dx, con.vscroll_btn_height |
||
2186 | call .vpattern |
||
2187 | mov dx, word [con.vscrollbar_pos] |
||
2188 | add dx, word [con.vscrollbar_size] |
||
2189 | mov cx, con.vscroll_bgr_height |
||
2190 | mov ebx, con.vscroll_bgr2 |
||
2191 | cmp [con.bScrollingDown], 0 |
||
2192 | jnz @f |
||
2193 | mov ebx, con.vscroll_bgr1 |
||
2194 | @@: |
||
2195 | call .vpattern |
||
2196 | mov ecx, [con.vscrollbar_pos] |
||
2197 | mov dx, cx |
||
2198 | add ecx, [con.vscrollbar_size] |
||
2199 | sub ecx, con.vscroll_bar_height3 |
||
2200 | push ecx |
||
2201 | mov ebx, con.vscroll_bar1 |
||
2202 | mov ecx, con.vscroll_width*65536 + con.vscroll_bar_height1 |
||
2203 | int 0x40 |
||
2204 | add dx, cx |
||
2205 | mov cx, con.vscroll_bar_height2 |
||
2206 | mov ebx, con.vscroll_bar2 |
||
2207 | call .vpattern |
||
2208 | mov ebx, con.vscroll_bar3 |
||
2209 | mov cx, con.vscroll_bar_height3 |
||
2210 | int 0x40 |
||
2211 | .skip_vscroll: |
||
2212 | ret |
||
2213 | |||
2214 | .vpattern: |
||
2215 | push edx |
||
2216 | add dx, cx |
||
2217 | cmp dx, [esp+8] |
||
2218 | pop edx |
||
2219 | jbe @f |
||
2220 | mov cx, [esp+4] |
||
2221 | sub cx, dx |
||
2222 | jz .ret |
||
2223 | @@: |
||
2224 | int 0x40 |
||
2225 | add dx, cx |
||
2226 | cmp dx, [esp+4] |
||
2227 | jb .vpattern |
||
2228 | .ret: |
||
2229 | ret 4 |
||
2230 | |||
2231 | align 4 |
||
2232 | con.colors dd 0x000000, 0x000080, 0x008000, 0x008080 |
||
2233 | dd 0x800000, 0x800080, 0x808000, 0xC0C0C0 |
||
2234 | dd 0x808080, 0x0000FF, 0x00FF00, 0x00FFFF |
||
2235 | dd 0xFF0000, 0xFF00FF, 0xFFFF00, 0xFFFFFF |
||
2236 | |||
2237 | scan_has_ascii: |
||
2238 | dd 11011111111111111111111111111110b |
||
2239 | dd 00000010001111111111101111111111b |
||
2240 | dd 00000000000000000000000000000000b |
||
2241 | dd 0 |
||
2242 | |||
2243 | con.extended_alt: |
||
2244 | db 00h,01h,78h,79h,7Ah,7Bh,7Ch,7Dh,7Eh,7Fh,80h,81h,82h,83h,0Eh,0A5h |
||
2245 | db 10h,11h,12h,13h,14h,15h,16h,17h,18h,19h,1Ah,1Bh,1Ch,00h,1Eh,1Fh |
||
2246 | db 20h,21h,22h,23h,24h,25h,26h,27h,28h,29h,00h,2Bh,2Ch,2Dh,2Eh,2Fh |
||
2247 | db 30h,31h,32h,33h,34h,35h,00h,37h,00h,39h,00h,68h,69h,6Ah,6Bh,6Ch |
||
2248 | db 6Dh,6Eh,6Fh,70h,71h,00h,00h,97h,98h,99h,4Ah,9Bh,9Ch,9Dh,4Eh,9Fh |
||
2249 | db 0A0h,0A1h,0A2h,0A3h,00h,00h,00h,8Bh,8Ch,00h,00h,00h,00h,00h,00h,00h |
||
2250 | times 20h db 0 |
||
2251 | con.extended_ctrl: |
||
2252 | times 0Fh db %-1 |
||
2253 | db 0x94 |
||
2254 | times 2Bh db %-1 |
||
2255 | db 5Eh,5Fh,60h,61h,62h,63h,64h,65h,66h,67h,00h,00h |
||
2256 | db 77h,8Dh,84h,8Eh,73h,8Fh,74h,90h,75h,91h,76h,92h,93h,00h,00h,00h,89h,8Ah |
||
2257 | times 0x80-0x59 db 0 |
||
2258 | con.extended_shift: |
||
2259 | times 3Bh db %-1 |
||
2260 | db 54h,55h,56h,57h,58h,59h,5Ah,5Bh,5Ch,5Dh,00h,00h |
||
2261 | db 47h,48h,49h,4Ah,4Bh,4Ch,4Dh,4Eh,4Fh,50h,51h,52h,53h,00h,00h,00h,87h,88h |
||
2262 | times 0x80-0x59 db 0 |
||
2263 | |||
2264 | ; В текущей реализации значения по умолчанию таковы. |
||
2265 | ; В будущем они, возможно, будут считываться как параметры из ini-файла console.ini. |
||
2266 | con.def_wnd_width dd 80 |
||
2267 | con.def_wnd_height dd 25 |
||
2268 | con.def_scr_width dd 80 |
||
2269 | con.def_scr_height dd 300 |
||
2270 | con.def_wnd_x dd 200 |
||
2271 | con.def_wnd_y dd 50 |
||
2272 | |||
2273 | con.vscroll_pt dd -1 |
||
2274 | |||
2275 | align 16 |
||
2276 | EXPORTS: |
||
2277 | dd szStart, START |
||
1145 | diamond | 2278 | dd szVersion, 0x00020007 |
836 | diamond | 2279 | dd szcon_init, con_init |
2280 | dd szcon_write_asciiz, con_write_asciiz |
||
2281 | dd szcon_printf, con_printf |
||
2282 | dd szcon_exit, con_exit |
||
2283 | dd szcon_get_flags, con_get_flags |
||
2284 | dd szcon_set_flags, con_set_flags |
||
2285 | dd szcon_kbhit, con_kbhit |
||
2286 | dd szcon_getch, con_getch |
||
2287 | dd szcon_getch2, con_getch2 |
||
2288 | dd szcon_gets, con_gets |
||
852 | diamond | 2289 | dd szcon_gets2, con_gets2 |
836 | diamond | 2290 | dd szcon_get_font_height, con_get_font_height |
2291 | dd szcon_get_cursor_height,con_get_cursor_height |
||
2292 | dd szcon_set_cursor_height,con_set_cursor_height |
||
853 | diamond | 2293 | dd szcon_cls, con_cls |
2294 | dd szcon_get_cursor_pos, con_get_cursor_pos |
||
2295 | dd szcon_set_cursor_pos, con_set_cursor_pos |
||
836 | diamond | 2296 | dd 0 |
2297 | |||
2298 | con_flags dd 7 |
||
2299 | con.cursor_height dd (15*font_height+50)/100 |
||
2300 | con.input_start dd con.input_buffer |
||
2301 | con.input_end dd con.input_buffer |
||
2302 | |||
2303 | con_esc_attr_n dd 0 |
||
2304 | con_esc_attrs dd 0,0,0,0 |
||
2305 | con_esc db 0 |
||
2306 | con_sci db 0 |
||
2307 | |||
2308 | con.entered_char dw -1 |
||
2309 | con.bGetchRequested db 0 |
||
2310 | con.bWasE0 db 0 |
||
2311 | |||
2312 | szStart db 'START',0 |
||
2313 | |||
2314 | szcon_init db 'con_init',0 |
||
2315 | szcon_write_asciiz db 'con_write_asciiz',0 |
||
2316 | szcon_printf db 'con_printf',0 |
||
2317 | szcon_exit db 'con_exit',0 |
||
2318 | szVersion db 'version',0 |
||
2319 | szcon_get_flags db 'con_get_flags',0 |
||
2320 | szcon_set_flags db 'con_set_flags',0 |
||
2321 | szcon_kbhit db 'con_kbhit',0 |
||
2322 | szcon_getch db 'con_getch',0 |
||
2323 | szcon_getch2 db 'con_getch2',0 |
||
2324 | szcon_gets db 'con_gets',0 |
||
852 | diamond | 2325 | szcon_gets2 db 'con_gets2',0 |
836 | diamond | 2326 | szcon_get_font_height db 'con_get_font_height',0 |
2327 | szcon_get_cursor_height db 'con_get_cursor_height',0 |
||
2328 | szcon_set_cursor_height db 'con_set_cursor_height',0 |
||
853 | diamond | 2329 | szcon_cls db 'con_cls',0 |
2330 | szcon_get_cursor_pos db 'con_get_cursor_pos',0 |
||
2331 | szcon_set_cursor_pos db 'con_set_cursor_pos',0 |
||
836 | diamond | 2332 | |
2333 | con.thread_err db 'Cannot create console thread!',13,10,0 |
||
2334 | con.nomem_err db 'Not enough memory!',13,10,0 |
||
2335 | con.aFinished db ' [Finished]',0 |
||
2336 | con.aNull db '(null)',0 |
||
2337 | con.beep db 0x90, 0x3C, 0x00 |
||
2338 | con.ipc_buf dd 0,8,0,0 |
||
2339 | db 0 |
||
2340 | |||
2341 | section '.data' data readable writable align 16 |
||
2342 | |||
2343 | con.finished_title rb 256 |
||
2344 | |||
2345 | con.cur_x rd 1 |
||
2346 | con.cur_y rd 1 |
||
2347 | con.wnd_xpos rd 1 |
||
2348 | con.wnd_ypos rd 1 |
||
2349 | |||
2350 | con.wnd_width rd 1 |
||
2351 | con.wnd_height rd 1 |
||
2352 | con.scr_width rd 1 |
||
2353 | con.scr_height rd 1 |
||
2354 | con.title rd 1 |
||
2355 | con.data rd 1 |
||
2356 | con.image rd 1 |
||
2357 | con.console_tid rd 1 |
||
2358 | con.data_width rw 1 |
||
2359 | con.data_height rw 1 |
||
2360 | con.vscrollbar_size rd 1 |
||
2361 | con.vscrollbar_pos rd 1 |
||
2362 | con.up_first_time rd 1 |
||
2363 | con.down_first_time rd 1 |
||
2364 | con.scroll_up_first_time rd 1 |
||
2365 | con.scroll_down_first_time rd 1 |
||
2366 | con.bUpPressed_saved rb 1 |
||
2367 | con.bDownPressed_saved rb 1 |
||
2368 | con.bScrollingUp_saved rb 1 |
||
2369 | con.bScrollingDown_saved rb 1 |
||
2370 | |||
2371 | con.input_buffer rw 128 |
||
2372 | con.input_buffer_end = $ |
||
2373 | |||
2374 | con.kbd_layout rb 128 |
||
2375 | |||
2376 | ; 1 = exit, 2 = set title, 3 = redraw, 4 = getch |
||
2377 | con.thread_op rb 1 |
||
2378 | con.bUpPressed rb 1 |
||
2379 | con.bDownPressed rb 1 |
||
2380 | con.bScrollingUp rb 1 |
||
2381 | con.bScrollingDown rb 1 |
||
2382 | |||
2383 | con.stack rb 1024 |
||
2384 | con.stack_top = $ |