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