Rev 3686 | Rev 3690 | 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 |
||
3686 | hidnplayr | 848 | je @f |
849 | xor eax, eax |
||
3688 | hidnplayr | 850 | mov [con.cur_x], eax |
851 | mov [con.cur_y], eax |
||
852 | jmp .j_get_data |
||
3686 | hidnplayr | 853 | @@: |
853 | diamond | 854 | mov eax, [con_esc_attrs] |
855 | cmp eax, [con.scr_width] |
||
856 | jae @f |
||
857 | mov [con.cur_x], eax |
||
858 | @@: |
||
859 | mov eax, [con_esc_attrs+4] |
||
860 | cmp eax, [con.scr_height+4] |
||
861 | jae @f |
||
862 | mov [con.cur_y], eax |
||
863 | .j_get_data: |
||
864 | jmp con.get_data_ptr |
||
865 | .cursor_up: |
||
866 | cmp [con_esc_attr_n], 1 |
||
867 | jnz .nosetcursor |
||
868 | mov eax, [con.cur_y] |
||
869 | sub eax, [con_esc_attrs] |
||
870 | jnc @f |
||
871 | xor eax, eax |
||
872 | @@: |
||
873 | mov [con.cur_y], eax |
||
874 | jmp .j_get_data |
||
875 | .cursor_down: |
||
876 | cmp [con_esc_attr_n], 1 |
||
877 | jnz .nosetcursor |
||
878 | mov eax, [con.cur_y] |
||
879 | add eax, [con_esc_attrs] |
||
880 | cmp eax, [con.scr_height] |
||
881 | jb @f |
||
882 | mov eax, [con.scr_height] |
||
883 | dec eax |
||
884 | @@: |
||
885 | mov [con.cur_y], eax |
||
886 | jmp .j_get_data |
||
887 | .cursor_right: |
||
888 | cmp [con_esc_attr_n], 1 |
||
889 | jnz .nosetcursor |
||
890 | mov eax, [con.cur_x] |
||
891 | add eax, [con_esc_attrs] |
||
892 | cmp eax, [con.scr_width] |
||
893 | jb @f |
||
894 | mov eax, [con.scr_width] |
||
895 | dec eax |
||
896 | @@: |
||
897 | mov [con.cur_x], eax |
||
898 | jmp .j_get_data |
||
899 | .cursor_left: |
||
900 | cmp [con_esc_attr_n], 1 |
||
901 | jnz .nosetcursor |
||
902 | mov eax, [con.cur_x] |
||
903 | sub eax, [con_esc_attrs] |
||
904 | jnc @f |
||
905 | xor eax, eax |
||
906 | @@: |
||
907 | mov [con.cur_x], eax |
||
908 | jmp .j_get_data |
||
836 | diamond | 909 | .set_attr: |
910 | push eax ecx edx |
||
911 | xor ecx, ecx |
||
912 | .set_one_attr: |
||
913 | mov eax, [con_esc_attrs+ecx*4] |
||
914 | cmp al, 0 |
||
915 | jz .attr_normal |
||
916 | cmp al, 1 |
||
917 | jz .attr_bold |
||
918 | cmp al, 5 |
||
919 | jz .attr_bgr_bold |
||
920 | cmp al, 7 |
||
921 | jz .attr_reversed |
||
922 | xor edx, edx |
||
923 | cmp al, 30 |
||
924 | jz .attr_color |
||
925 | mov dl, 4 |
||
926 | cmp al, 31 |
||
927 | jz .attr_color |
||
928 | mov dl, 2 |
||
929 | cmp al, 32 |
||
930 | jz .attr_color |
||
931 | mov dl, 6 |
||
932 | cmp al, 33 |
||
933 | jz .attr_color |
||
934 | mov dl, 1 |
||
935 | cmp al, 34 |
||
936 | jz .attr_color |
||
937 | mov dl, 5 |
||
938 | cmp al, 35 |
||
939 | jz .attr_color |
||
940 | mov dl, 3 |
||
941 | cmp al, 36 |
||
942 | jz .attr_color |
||
943 | mov dl, 7 |
||
944 | cmp al, 37 |
||
945 | jz .attr_color |
||
946 | xor edx, edx |
||
947 | cmp al, 40 |
||
948 | jz .attr_bgr_color |
||
949 | mov dl, 0x40 |
||
950 | cmp al, 41 |
||
951 | jz .attr_bgr_color |
||
952 | mov dl, 0x20 |
||
953 | cmp al, 42 |
||
954 | jz .attr_bgr_color |
||
955 | mov dl, 0x60 |
||
956 | cmp al, 43 |
||
957 | jz .attr_bgr_color |
||
958 | mov dl, 0x10 |
||
959 | cmp al, 44 |
||
960 | jz .attr_bgr_color |
||
961 | mov dl, 0x50 |
||
962 | cmp al, 45 |
||
963 | jz .attr_bgr_color |
||
964 | mov dl, 0x30 |
||
965 | cmp al, 46 |
||
966 | jz .attr_bgr_color |
||
967 | mov dl, 0x70 |
||
968 | cmp al, 47 |
||
969 | jnz .attr_continue |
||
970 | .attr_bgr_color: |
||
971 | mov eax, [con_flags] |
||
972 | and al, 0x8F |
||
973 | or al, dl |
||
974 | mov [con_flags], eax |
||
975 | jmp .attr_continue |
||
976 | .attr_color: |
||
977 | mov eax, [con_flags] |
||
978 | and al, 0xF8 |
||
979 | or al, dl |
||
980 | mov [con_flags], eax |
||
981 | jmp .attr_continue |
||
982 | .attr_normal: |
||
983 | mov byte [con_flags], 7 |
||
984 | jmp .attr_continue |
||
985 | .attr_reversed: |
||
986 | mov byte [con_flags], 0x70 |
||
987 | jmp .attr_continue |
||
988 | .attr_bold: |
||
989 | or byte [con_flags], 8 |
||
990 | jmp .attr_continue |
||
991 | .attr_bgr_bold: |
||
992 | or byte [con_flags], 0x80 |
||
993 | .attr_continue: |
||
994 | inc ecx |
||
995 | cmp ecx, [con_esc_attr_n] |
||
996 | jb .set_one_attr |
||
997 | pop edx ecx eax |
||
998 | ret |
||
999 | |||
1000 | con.newline: |
||
1001 | mov eax, [con.cur_y] |
||
1002 | inc eax |
||
1003 | mov [con.cur_y], eax |
||
1004 | cmp eax, [con.scr_height] |
||
1005 | jb @f |
||
1006 | call con.scr_scroll_up |
||
1007 | @@: |
||
1008 | call con.get_data_ptr |
||
1009 | ret |
||
1010 | |||
1011 | con.scr_scroll_up: |
||
1012 | pushad |
||
1013 | mov edi, [con.data] |
||
1014 | mov esi, edi |
||
1015 | add esi, [con.scr_width] |
||
1016 | add esi, [con.scr_width] |
||
1017 | dec [con.cur_y] |
||
1018 | mov ecx, [con.scr_height] |
||
1019 | dec ecx |
||
1020 | imul ecx, [con.scr_width] |
||
1021 | shr ecx, 1 |
||
1022 | rep movsd |
||
1023 | adc ecx, ecx |
||
1024 | rep movsw |
||
1025 | mov ax, 0x0720 |
||
1026 | mov ecx, [con.scr_width] |
||
1027 | rep stosw |
||
1028 | popad |
||
1029 | ret |
||
1030 | |||
1031 | con.data2image: |
||
1032 | pushad |
||
1033 | mov edi, [con.image] |
||
1034 | mov esi, [con.data] |
||
1035 | mov eax, [con.wnd_ypos] |
||
1036 | mul [con.scr_width] |
||
1037 | add eax, [con.wnd_xpos] |
||
1038 | lea esi, [esi+eax*2] |
||
1039 | mov ecx, [con.wnd_height] |
||
1040 | .lh: |
||
1041 | push ecx |
||
1042 | mov ecx, [con.wnd_width] |
||
1043 | .lw: |
||
1044 | push ecx edi |
||
1045 | xor eax, eax |
||
1046 | mov al, [esi+1] |
||
1047 | push eax |
||
1048 | and al, 0xF |
||
1049 | mov ebx, eax ; цвет текста |
||
1050 | pop eax |
||
1051 | shr al, 4 |
||
1052 | mov ebp, eax ; цвет фона |
||
1053 | sub ebx, ebp |
||
1054 | lodsb |
||
1055 | inc esi |
||
1056 | if font_width > 8 |
||
1057 | lea edx, [eax+eax+font] |
||
1058 | else |
||
1059 | lea edx, [eax+font] |
||
1060 | end if |
||
1061 | .sh: |
||
1062 | mov ecx, [edx] |
||
1063 | repeat font_width |
||
1064 | shr ecx, 1 |
||
1065 | sbb eax, eax |
||
1066 | and eax, ebx |
||
1067 | add eax, ebp |
||
1068 | mov [edi+%-1], al |
||
1069 | end repeat |
||
1070 | mov eax, [con.wnd_width] |
||
1071 | ; imul eax, font_width |
||
1072 | ; add edi, eax |
||
1073 | if font_width = 6 |
||
1074 | lea eax, [eax*2+eax] |
||
1075 | lea edi, [edi+eax*2] |
||
1076 | else if font_width = 7 |
||
1077 | lea edi, [edi+eax*8] |
||
1078 | sub edi, eax |
||
1079 | else if font_width = 8 |
||
1080 | lea edi, [edi+eax*8] |
||
1081 | else if font_width = 9 |
||
1082 | lea edi, [edi+eax*8] |
||
1083 | add edi, eax |
||
1084 | else if font_width = 10 |
||
1085 | lea eax, [eax*4+eax] |
||
1086 | lea edi, [edi+eax*2] |
||
1087 | else |
||
1088 | Unknown font_width value! |
||
1089 | end if |
||
1090 | if font_width > 8 |
||
1091 | add edx, 256*2 |
||
1092 | cmp edx, font+256*2*font_height |
||
1093 | else |
||
1094 | add edx, 256 |
||
1095 | cmp edx, font+256*font_height |
||
1096 | end if |
||
1097 | jb .sh |
||
1098 | pop edi ecx |
||
1099 | add edi, font_width |
||
1100 | sub ecx, 1 |
||
1101 | jnz .lw |
||
1102 | mov eax, [con.wnd_width] |
||
1103 | imul eax, (font_height-1)*font_width |
||
1104 | add edi, eax |
||
1105 | pop ecx |
||
1106 | mov eax, [con.scr_width] |
||
1107 | sub eax, [con.wnd_width] |
||
1108 | lea esi, [esi+eax*2] |
||
1109 | dec ecx |
||
1110 | jnz .lh |
||
1111 | mov eax, [con.cur_y] |
||
1112 | sub eax, [con.wnd_ypos] |
||
1113 | jb .nocursor |
||
1114 | cmp eax, [con.wnd_height] |
||
1115 | jae .nocursor |
||
1116 | inc eax |
||
1117 | mul [con.wnd_width] |
||
1118 | imul eax, font_height*font_width |
||
1119 | mov edx, [con.cur_x] |
||
1120 | sub edx, [con.wnd_xpos] |
||
1121 | jb .nocursor |
||
1122 | cmp edx, [con.wnd_width] |
||
1123 | jae .nocursor |
||
1124 | inc edx |
||
1125 | imul edx, font_width |
||
1126 | add eax, edx |
||
1127 | add eax, [con.image] |
||
1128 | mov edx, [con.wnd_width] |
||
1129 | imul edx, font_width |
||
1130 | neg edx |
||
1131 | mov ecx, [con.cursor_height] |
||
1132 | jecxz .nocursor |
||
1133 | .cursor_loop: |
||
1134 | push ecx |
||
1135 | mov ecx, font_width |
||
1136 | add eax, edx |
||
1137 | push eax |
||
1138 | @@: |
||
1139 | xor byte [eax-1], 7 |
||
1140 | dec eax |
||
1141 | loop @b |
||
1142 | pop eax |
||
1143 | pop ecx |
||
1144 | loop .cursor_loop |
||
1145 | .nocursor: |
||
1146 | popad |
||
1147 | ret |
||
1148 | |||
1149 | con_exit: |
||
1150 | cmp byte [esp+4], 0 |
||
1151 | jz .noexit |
||
1152 | mov [con.thread_op], 1 |
||
1153 | call con.wake |
||
1154 | ret 4 |
||
1155 | .noexit: |
||
1156 | push esi |
||
1157 | mov esi, [con.title] |
||
1158 | mov edx, con.finished_title |
||
1159 | mov ecx, 255 |
||
1160 | call .strcpy |
||
1161 | mov esi, con.aFinished |
||
1162 | call .strcpy |
||
1163 | mov byte [edx], 0 |
||
1164 | pop esi |
||
1165 | and [con.cursor_height], 0 |
||
1166 | push con.finished_title |
||
1167 | call con_set_title |
||
1168 | ret 4 |
||
1169 | .strcpy: |
||
1170 | jecxz .ret |
||
1171 | @@: |
||
1172 | lodsb |
||
1173 | test al, al |
||
1174 | jz .ret |
||
1175 | mov [edx], al |
||
1176 | inc edx |
||
1177 | loop @b |
||
1178 | .ret: |
||
1179 | ret |
||
1180 | |||
1181 | con_set_title: |
||
1182 | mov eax, [esp+4] |
||
1183 | mov [con.title], eax |
||
1184 | mov [con.thread_op], 2 |
||
1185 | call con.wake |
||
1186 | ret 4 |
||
1187 | |||
1188 | ; int __stdcall con_kbhit(void); |
||
1189 | con_kbhit: |
||
1133 | diamond | 1190 | test byte [con_flags+1], 2 |
1191 | jnz @f |
||
836 | diamond | 1192 | mov eax, [con.input_start] |
1193 | cmp eax, [con.input_end] |
||
1133 | diamond | 1194 | @@: |
836 | diamond | 1195 | setnz al |
1196 | movzx eax, al |
||
1197 | ret |
||
1198 | |||
1199 | con.force_entered_char: |
||
1200 | cmp [con.entered_char], -1 |
||
1201 | jnz .ret |
||
1202 | mov [con.thread_op], 4 |
||
1203 | call con.wake |
||
1133 | diamond | 1204 | test byte [con_flags+1], 2 |
1205 | jnz .ret |
||
836 | diamond | 1206 | ; wait for response |
1207 | push ebx |
||
1208 | push 5 |
||
1209 | pop eax |
||
1210 | push 2 |
||
1211 | pop ebx |
||
1212 | @@: |
||
1213 | int 0x40 |
||
1214 | cmp [con.entered_char], -1 |
||
1215 | jz @b |
||
1216 | pop ebx |
||
1217 | .ret: |
||
1218 | ret |
||
1219 | |||
1220 | ; int __stdcall con_getch(void); |
||
1221 | con_getch: |
||
1222 | call con.force_entered_char |
||
1133 | diamond | 1223 | test byte [con_flags+1], 2 |
1224 | jnz con_getch_closed |
||
836 | diamond | 1225 | movzx eax, byte [con.entered_char] |
1226 | sar [con.entered_char], 8 |
||
1227 | mov byte [con.entered_char+1], 0xFF |
||
1228 | test al, al |
||
1229 | jz @f |
||
1230 | mov byte [con.entered_char], 0xFF |
||
1231 | @@: |
||
1232 | ret |
||
1233 | |||
1133 | diamond | 1234 | con_getch_closed: |
1145 | diamond | 1235 | xor eax, eax |
1133 | diamond | 1236 | ret |
1237 | |||
836 | diamond | 1238 | ; int __stdcall con_getch2(void); |
1239 | con_getch2: |
||
1240 | call con.force_entered_char |
||
1133 | diamond | 1241 | test byte [con_flags+1], 2 |
1242 | jnz con_getch_closed |
||
836 | diamond | 1243 | mov eax, 0xFFFF |
1244 | xchg ax, [con.entered_char] |
||
1245 | ret |
||
1246 | |||
1133 | diamond | 1247 | ; char* __stdcall con_gets(char* str, int n); |
836 | diamond | 1248 | con_gets: |
852 | diamond | 1249 | pop eax |
1250 | push 0 |
||
1251 | push eax |
||
1133 | diamond | 1252 | ; char* __stdcall con_gets2(con_gets2_callback callback, char* str, int n); |
852 | diamond | 1253 | con_gets2: |
1133 | diamond | 1254 | mov eax, [esp+8] ; str |
836 | diamond | 1255 | pushad |
1133 | diamond | 1256 | mov esi, eax ; str |
852 | diamond | 1257 | mov ebx, [esp+20h+12] ; n |
836 | diamond | 1258 | sub ebx, 1 |
1259 | jle .ret |
||
1260 | mov byte [esi], 0 |
||
1261 | xor ecx, ecx ; длина уже введённой строки |
||
1262 | call con.get_data_ptr |
||
1263 | .loop: |
||
852 | diamond | 1264 | call con_getch2 |
836 | diamond | 1265 | test al, al |
1266 | jz .extended |
||
1267 | cmp al, 8 |
||
1268 | jz .backspace |
||
1269 | cmp al, 27 |
||
1270 | jz .esc |
||
1271 | cmp al, 13 |
||
1272 | jz .enter |
||
852 | diamond | 1273 | cmp al, 9 |
1274 | jz .tab |
||
836 | diamond | 1275 | inc ecx |
1276 | mov dl, al |
||
1277 | call con.write_char_ex |
||
1278 | push [con.cur_x] |
||
1279 | push [con.cur_y] |
||
1280 | push edi |
||
1281 | push esi |
||
1282 | @@: |
||
1283 | lodsb |
||
1284 | mov [esi-1], dl |
||
1285 | mov dl, al |
||
1286 | test al, al |
||
1287 | jz @f |
||
1288 | call con.write_char_ex |
||
1289 | jmp @b |
||
1290 | @@: |
||
1291 | mov [esi], dl |
||
1292 | pop esi |
||
1293 | inc esi |
||
1294 | pop edi |
||
1295 | pop [con.cur_y] |
||
1296 | pop [con.cur_x] |
||
1297 | .update_screen_and_loop: |
||
1298 | call con.update_screen |
||
1299 | cmp ecx, ebx |
||
1300 | jb .loop |
||
852 | diamond | 1301 | .ret_us: |
836 | diamond | 1302 | mov edx, [con.cur_x] |
1303 | @@: |
||
1304 | lodsb |
||
1305 | test al, al |
||
1306 | jz @f |
||
1307 | inc edx |
||
1308 | cmp edx, [con.scr_width] |
||
1309 | jb @b |
||
1310 | xor edx, edx |
||
1311 | call con.newline |
||
1312 | jmp @b |
||
1313 | @@: |
||
1314 | mov [con.cur_x], edx |
||
1315 | call con.get_data_ptr |
||
1316 | call con.update_screen |
||
1317 | jmp .ret |
||
1318 | .esc: |
||
1319 | mov edx, [con.cur_x] |
||
1320 | @@: |
||
1321 | lodsb |
||
1322 | test al, al |
||
1323 | jz @f |
||
1324 | inc edx |
||
1325 | cmp edx, [con.scr_width] |
||
1326 | jb @b |
||
1327 | xor edx, edx |
||
1328 | call con.newline |
||
1329 | jmp @b |
||
1330 | @@: |
||
1331 | mov [con.cur_x], edx |
||
1332 | call con.get_data_ptr |
||
1333 | dec esi |
||
1334 | xor ecx, ecx |
||
1335 | @@: |
||
1336 | mov byte [esi], 0 |
||
852 | diamond | 1337 | cmp esi, [esp+20h+8] |
836 | diamond | 1338 | jbe .update_screen_and_loop |
1339 | mov al, 8 |
||
1340 | call con.write_special_char |
||
1341 | mov al, ' ' |
||
1342 | call con.write_char |
||
1343 | mov al, 8 |
||
1344 | call con.write_special_char |
||
1345 | dec esi |
||
1346 | jmp @b |
||
1347 | .delete: |
||
1348 | cmp byte [esi], 0 |
||
1349 | jz .loop |
||
1350 | lodsb |
||
1351 | call con.write_char_ex |
||
1352 | .backspace: |
||
852 | diamond | 1353 | cmp esi, [esp+20h+8] |
836 | diamond | 1354 | jbe .loop |
1355 | push esi |
||
1356 | mov edx, [con.cur_x] |
||
1357 | @@: |
||
1358 | lodsb |
||
1359 | test al, al |
||
1360 | jz @f |
||
1361 | inc edx |
||
1362 | cmp edx, [con.scr_width] |
||
1363 | jb @b |
||
1364 | xor edx, edx |
||
1365 | call con.newline |
||
1366 | jmp @b |
||
1367 | @@: |
||
1368 | mov [con.cur_x], edx |
||
1369 | call con.get_data_ptr |
||
1370 | dec esi |
||
1371 | mov al, 8 |
||
1372 | call con.write_special_char |
||
1373 | mov al, ' ' |
||
1374 | call con.write_char |
||
1375 | mov al, 8 |
||
1376 | call con.write_special_char |
||
1377 | mov dl, 0 |
||
1378 | @@: |
||
1379 | cmp esi, [esp] |
||
1380 | jbe @f |
||
1381 | mov al, 8 |
||
1382 | call con.write_special_char |
||
1383 | dec esi |
||
1384 | xchg dl, [esi] |
||
1385 | mov al, dl |
||
1386 | call con.write_char |
||
1387 | mov al, 8 |
||
1388 | call con.write_special_char |
||
1389 | jmp @b |
||
1390 | @@: |
||
1391 | pop esi |
||
1392 | dec esi |
||
1393 | mov [esi], dl |
||
1394 | dec ecx |
||
1395 | jmp .update_screen_and_loop |
||
1396 | .enter: |
||
1397 | mov edx, [con.cur_x] |
||
1398 | @@: |
||
1399 | lodsb |
||
1400 | test al, al |
||
1401 | jz @f |
||
1402 | inc edx |
||
1403 | cmp edx, [con.scr_width] |
||
1404 | jb @b |
||
1405 | xor edx, edx |
||
1406 | call con.newline |
||
1407 | jmp @b |
||
1408 | @@: |
||
1409 | mov [con.cur_x], edx |
||
1410 | call con.get_data_ptr |
||
1411 | mov al, 10 |
||
1412 | mov [esi-1], al |
||
1413 | mov byte [esi], 0 |
||
1414 | call con.write_special_char |
||
1415 | call con.update_screen |
||
1416 | jmp .ret |
||
852 | diamond | 1417 | .tab: |
1418 | mov al, 0 |
||
1419 | mov ah, 0xF |
||
836 | diamond | 1420 | .extended: |
1145 | diamond | 1421 | test ah, ah |
1422 | jz .closed |
||
852 | diamond | 1423 | xchg al, ah |
836 | diamond | 1424 | cmp al, 0x4B |
1425 | jz .left |
||
1426 | cmp al, 0x4D |
||
1427 | jz .right |
||
1428 | cmp al, 0x47 |
||
1429 | jz .home |
||
1430 | cmp al, 0x4F |
||
1431 | jz .end |
||
1432 | cmp al, 0x53 |
||
1433 | jz .delete |
||
852 | diamond | 1434 | ; give control to callback function |
1435 | cmp dword [esp+20h+4], 0 |
||
1436 | jz .loop |
||
1437 | ; remember length of text before and length of text after |
||
1438 | ; and advance cursor to the end of line |
||
1439 | push ecx |
||
1440 | push eax |
||
1441 | lea edx, [esi+1] |
||
1442 | @@: |
||
1443 | lodsb |
||
1444 | test al, al |
||
1445 | jz @f |
||
1446 | call con.write_char_ex |
||
1447 | jmp @b |
||
1448 | @@: |
||
1449 | sub esi, edx |
||
1450 | pop eax |
||
1451 | push esi |
||
1452 | dec edx |
||
1453 | sub edx, [esp+28h+8] |
||
1454 | push edx |
||
1455 | push esp ; ppos |
||
1456 | mov ecx, [esp+30h+4] |
||
1457 | lea edx, [esp+30h+12] |
||
1458 | push edx ; pn |
||
1459 | lea edx, [esp+34h+8] |
||
1460 | push edx ; pstr |
||
1461 | push eax ; keycode |
||
1462 | call ecx |
||
1463 | call con.get_data_ptr |
||
1464 | dec eax |
||
1465 | js .callback_nochange |
||
1466 | jz .callback_del |
||
1467 | dec eax |
||
1468 | jz .callback_output |
||
1469 | ; callback returned 2 - exit |
||
1470 | add esp, 12 |
||
1471 | jmp .ret |
||
1472 | .callback_nochange: |
||
1473 | ; callback returned 0 - string was not changed, only restore cursor position |
||
1474 | pop esi |
||
1475 | pop ecx |
||
1476 | test ecx, ecx |
||
1477 | jz .cncs |
||
1478 | @@: |
||
1479 | mov al, 8 |
||
1480 | call con.write_special_char |
||
1481 | loop @b |
||
1482 | .cncs: |
||
1483 | pop ecx |
||
1484 | add esi, [esp+20h+8] |
||
1485 | jmp .callback_done |
||
1486 | .callback_del: |
||
1487 | ; callback returned 1 - string was changed, delete old string and output new |
||
1488 | mov ecx, [esp+8] |
||
1489 | test ecx, ecx |
||
1490 | jz .cds |
||
1491 | @@: |
||
1492 | mov al, 8 |
||
1493 | call con.write_special_char |
||
1494 | mov al, ' ' |
||
1495 | call con.write_char_ex |
||
1496 | mov al, 8 |
||
1497 | call con.write_special_char |
||
1498 | loop @b |
||
1499 | .cds: |
||
1500 | .callback_output: |
||
1501 | ; callback returned 2 - string was changed, output new string |
||
1502 | pop edx |
||
1503 | pop esi |
||
1504 | pop ecx |
||
1505 | mov esi, [esp+20h+8] |
||
1506 | xor ecx, ecx |
||
1507 | @@: |
||
1508 | lodsb |
||
1509 | test al, al |
||
1510 | jz @f |
||
1511 | call con.write_char_ex |
||
1512 | inc ecx |
||
1513 | jmp @b |
||
1514 | @@: |
||
1515 | dec esi |
||
1516 | push ecx |
||
1517 | sub ecx, edx |
||
1518 | jz .cos |
||
1519 | @@: |
||
1520 | mov al, 8 |
||
1521 | call con.write_special_char |
||
1522 | dec esi |
||
1523 | loop @b |
||
1524 | .cos: |
||
1525 | pop ecx |
||
1526 | .callback_done: |
||
1527 | call con.update_screen |
||
1528 | mov ebx, [esp+20h+12] |
||
1529 | dec ebx |
||
1530 | cmp ecx, ebx |
||
1531 | jae .ret_us |
||
836 | diamond | 1532 | jmp .loop |
1533 | .left: |
||
852 | diamond | 1534 | cmp esi, [esp+20h+8] |
836 | diamond | 1535 | jbe .loop |
1536 | dec esi |
||
1537 | mov al, 8 |
||
1538 | call con.write_special_char |
||
1539 | jmp .update_screen_and_loop |
||
1540 | .right: |
||
1541 | cmp byte [esi], 0 |
||
1542 | jz .loop |
||
1543 | lodsb |
||
1544 | call con.write_char_ex |
||
1545 | jmp .update_screen_and_loop |
||
1546 | .home: |
||
852 | diamond | 1547 | cmp esi, [esp+20h+8] |
836 | diamond | 1548 | jz .update_screen_and_loop |
1549 | dec esi |
||
1550 | mov al, 8 |
||
1551 | call con.write_special_char |
||
1552 | jmp .home |
||
1553 | .end: |
||
1554 | lodsb |
||
1555 | test al, al |
||
1556 | jz @f |
||
1557 | call con.write_char_ex |
||
1558 | jmp .end |
||
1559 | @@: |
||
1560 | dec esi |
||
1561 | jmp .update_screen_and_loop |
||
1133 | diamond | 1562 | .closed: |
1563 | and dword [esp+1Ch], 0 |
||
836 | diamond | 1564 | .ret: |
1565 | popad |
||
852 | diamond | 1566 | ret 12 |
836 | diamond | 1567 | |
853 | diamond | 1568 | ; void __stdcall con_cls(); |
1569 | con_cls: |
||
1570 | push edi |
||
1571 | call con.write_special_char.cls |
||
1572 | pop edi |
||
1573 | call con.update_screen |
||
1574 | ret |
||
1575 | |||
1576 | ; void __stdcall con_get_cursor_pos(int* px, int* py); |
||
1577 | con_get_cursor_pos: |
||
1578 | push eax ecx |
||
1579 | mov eax, [esp+12] |
||
1580 | mov ecx, [con.cur_x] |
||
1581 | mov [eax], ecx |
||
1582 | mov eax, [esp+16] |
||
1583 | mov ecx, [con.cur_y] |
||
1584 | mov [eax], ecx |
||
1585 | pop ecx eax |
||
1586 | ret 8 |
||
1587 | |||
1588 | ; void __stdcall con_set_cursor_pos(int px, int py); |
||
1589 | con_set_cursor_pos: |
||
1590 | push eax |
||
1591 | mov eax, [esp+8] |
||
1592 | cmp eax, [con.scr_width] |
||
1593 | jae @f |
||
1594 | mov [con.cur_x], eax |
||
1595 | @@: |
||
1596 | mov eax, [esp+12] |
||
1597 | cmp eax, [con.scr_height] |
||
1598 | jae @f |
||
1599 | mov [con.cur_y], eax |
||
1600 | @@: |
||
1601 | pop eax |
||
1602 | call con.update_screen |
||
1603 | ret 8 |
||
1604 | |||
836 | diamond | 1605 | con.update_screen: |
1606 | push eax |
||
1607 | mov eax, [con.cur_y] |
||
1608 | sub eax, [con.wnd_ypos] |
||
1609 | jb .up |
||
1610 | cmp eax, [con.wnd_height] |
||
1611 | jb .done |
||
1612 | mov eax, [con.cur_y] |
||
1613 | sub eax, [con.wnd_height] |
||
1614 | inc eax |
||
1615 | jmp .set |
||
1616 | .up: |
||
1617 | mov eax, [con.cur_y] |
||
1618 | .set: |
||
1619 | mov [con.wnd_ypos], eax |
||
1620 | .done: |
||
1621 | pop eax |
||
1622 | mov [con.thread_op], 3 |
||
1623 | |||
1624 | con.wake: |
||
1625 | pushad |
||
1626 | mov al, [con.thread_op] |
||
1627 | cmp al, byte [con.ipc_buf+0x10] |
||
1628 | jz .ret |
||
1629 | @@: |
||
1630 | push 60 |
||
1631 | pop eax |
||
1632 | push 2 |
||
1633 | pop ebx |
||
1634 | mov ecx, [con.console_tid] |
||
1133 | diamond | 1635 | jecxz .ret |
836 | diamond | 1636 | mov edx, con.thread_op |
1637 | push 1 |
||
1638 | pop esi |
||
1639 | int 0x40 |
||
1640 | test eax, eax |
||
1641 | jz @f |
||
1642 | push 5 |
||
1643 | pop eax |
||
1644 | mov bl, 1 |
||
1645 | int 0x40 |
||
1646 | jmp @b |
||
1647 | @@: |
||
1648 | .ret: |
||
1649 | popad |
||
1650 | ret |
||
1651 | |||
1652 | ; Поток окна консоли. Обрабатывает ввод и вывод. |
||
1653 | con.thread: |
||
1654 | ; Поток реагирует на IPC, которое используется только для того, чтобы его можно было "разбудить" |
||
1655 | push 40 |
||
1656 | pop eax |
||
1657 | push 0x67 |
||
1658 | pop ebx |
||
1659 | int 0x40 |
||
1660 | mov al, 60 |
||
1661 | mov bl, 1 |
||
1662 | mov ecx, con.ipc_buf |
||
1663 | push 0x11 |
||
1664 | pop edx |
||
1665 | int 0x40 |
||
1666 | mov al, 66 |
||
1667 | mov bl, 1 |
||
1668 | mov ecx, ebx |
||
1669 | int 0x40 |
||
1670 | con.redraw: |
||
1671 | call con.draw_window |
||
1672 | con.msg_loop: |
||
1673 | cmp dword [con.bUpPressed], 0 |
||
1674 | jnz .wait_timeout |
||
1675 | push 10 |
||
1676 | pop eax |
||
1677 | jmp @f |
||
1678 | .wait_timeout: |
||
1679 | push 23 |
||
1680 | pop eax |
||
1681 | push 5 |
||
1682 | pop ebx |
||
1683 | @@: |
||
1684 | int 0x40 |
||
1685 | dec eax |
||
1686 | jz con.redraw |
||
1687 | dec eax |
||
1688 | jz con.key |
||
1689 | dec eax |
||
1690 | jz con.button |
||
1691 | cmp al, 4 |
||
1692 | jz con.ipc |
||
1693 | jmp con.mouse |
||
1694 | con.button: |
||
1695 | ; we have only one button, close |
||
1696 | con.thread_exit: |
||
1133 | diamond | 1697 | or byte [con_flags+1], 2 |
1698 | and [con.console_tid], 0 |
||
1134 | diamond | 1699 | and [con.entered_char], 0 |
836 | diamond | 1700 | or eax, -1 |
1701 | int 0x40 |
||
1702 | con.key: |
||
1703 | mov al, 2 |
||
1704 | int 0x40 |
||
1705 | ; ah = scancode |
||
1706 | cmp ah, 0xE0 |
||
1707 | jnz @f |
||
1708 | mov [con.bWasE0], 1 |
||
1709 | jmp con.msg_loop |
||
1710 | @@: |
||
1711 | shr eax, 8 |
||
1712 | xchg ah, [con.bWasE0] |
||
1713 | test al, al |
||
1714 | jle con.msg_loop |
||
1715 | cmp al, 0x1D |
||
1716 | jz con.msg_loop |
||
1717 | cmp al, 0x2A |
||
1718 | jz con.msg_loop |
||
1719 | cmp al, 0x36 |
||
1720 | jz con.msg_loop |
||
1721 | cmp al, 0x38 |
||
1722 | jz con.msg_loop |
||
1723 | cmp al, 0x3A |
||
1724 | jz con.msg_loop |
||
1725 | cmp al, 0x45 |
||
1726 | jz con.msg_loop |
||
1727 | cmp al, 0x46 |
||
1728 | jz con.msg_loop |
||
1729 | mov edx, eax |
||
1730 | push 66 |
||
1731 | pop eax |
||
1732 | push 3 |
||
1733 | pop ebx |
||
1734 | int 0x40 ; eax = control key state |
||
1735 | test dh, dh |
||
1736 | jnz .extended |
||
1737 | bt [scan_has_ascii], edx |
||
1738 | jnc .extended |
||
1739 | test al, 0x30 |
||
1740 | jnz .extended |
||
1741 | ; key has ASCII code |
||
1742 | push eax edx |
||
1743 | push 2 |
||
1744 | pop ecx |
||
1745 | test al, 3 |
||
1746 | jnz @f |
||
1747 | dec ecx |
||
1748 | @@: |
||
1749 | push 26 |
||
1750 | pop eax |
||
1751 | mov bl, 2 |
||
1752 | mov edx, con.kbd_layout |
||
1753 | int 0x40 |
||
1754 | pop edx eax |
||
1755 | mov dh, [con.kbd_layout+edx] |
||
1756 | test al, 0xC |
||
1757 | jz @f |
||
1758 | sub dh, 0x60 |
||
1759 | jmp @f |
||
1760 | .extended: |
||
1761 | mov dh, 0 ; no ASCII code |
||
1762 | @@: |
||
1763 | ; dh contains ASCII-code; now convert scancode to extended key code |
||
1764 | mov ecx, con.extended_alt |
||
1765 | test al, 0x30 |
||
1766 | jnz .xlat |
||
1767 | mov ecx, con.extended_shift |
||
1768 | test al, 3 |
||
1769 | jnz .xlat |
||
1770 | mov ecx, con.extended_ctrl |
||
1771 | test al, 0xC |
||
1772 | jnz .xlat |
||
1773 | xchg dl, dh |
||
1774 | cmp dh, 0x57 |
||
1775 | jz @f |
||
1776 | cmp dh, 0x58 |
||
1777 | jnz .gotcode |
||
1778 | @@: |
||
1779 | add dh, 0x85-0x57 |
||
1780 | jmp .gotcode |
||
1781 | .xlat: |
||
1782 | movzx eax, dl |
||
1783 | mov dl, dh |
||
1784 | mov dh, [eax+ecx] |
||
1785 | .gotcode: |
||
1786 | test dh, dh |
||
1787 | jz con.msg_loop |
||
1788 | cmp dh, 0x94 |
||
1789 | jnz @f |
||
1790 | mov dl, 0 |
||
1791 | @@: |
||
1792 | ; dx contains full keycode |
||
1793 | cmp [con.bGetchRequested], 0 |
||
1794 | jz @f |
||
1795 | mov [con.entered_char], dx |
||
1796 | jmp con.msg_loop |
||
1797 | @@: |
||
1798 | mov eax, [con.input_end] |
||
1799 | mov ecx, eax |
||
1800 | add eax, 2 |
||
1801 | cmp eax, con.input_buffer_end |
||
1802 | jnz @f |
||
1803 | mov eax, con.input_buffer |
||
1804 | @@: |
||
1805 | cmp eax, [con.input_start] |
||
1806 | jnz @f |
||
1807 | ; buffer overflow, make beep and continue |
||
1808 | push 55 |
||
1809 | pop eax |
||
1810 | mov ebx, eax |
||
1811 | mov esi, con.beep |
||
1812 | int 0x40 |
||
1813 | jmp con.msg_loop |
||
1814 | @@: |
||
1815 | mov [ecx], dx |
||
1816 | mov [con.input_end], eax |
||
1817 | jmp con.msg_loop |
||
1818 | con.ipc: |
||
1819 | movzx eax, byte [con.ipc_buf+0x10] |
||
1820 | mov byte [con.ipc_buf+4], 8 |
||
1821 | mov byte [con.ipc_buf+0x10], 0 |
||
1822 | dec eax |
||
1823 | jz con.thread_exit |
||
1824 | dec eax |
||
1825 | jz con.set_title |
||
1826 | dec eax |
||
1827 | jz con.redraw_image |
||
1828 | dec eax |
||
1829 | jz con.getch |
||
1830 | jmp con.msg_loop |
||
1831 | con.set_title: |
||
1832 | push 71 |
||
1833 | pop eax |
||
1834 | push 1 |
||
1835 | pop ebx |
||
1836 | mov ecx, [con.title] |
||
1837 | int 0x40 |
||
1838 | jmp con.msg_loop |
||
1839 | con.redraw_image: |
||
1840 | call con.data2image |
||
1841 | call con.draw_image |
||
1842 | jmp con.msg_loop |
||
1843 | con.getch: |
||
1844 | mov eax, [con.input_start] |
||
1845 | cmp eax, [con.input_end] |
||
1846 | jz .noinput |
||
1847 | mov ecx, [eax] |
||
1848 | mov [con.entered_char], cx |
||
1849 | inc eax |
||
1850 | inc eax |
||
1851 | cmp eax, con.input_buffer_end |
||
1852 | jnz @f |
||
1853 | mov eax, con.input_buffer |
||
1854 | @@: |
||
1855 | mov [con.input_start], eax |
||
1856 | jmp con.msg_loop |
||
1857 | .noinput: |
||
1858 | mov [con.bGetchRequested], 1 |
||
1859 | jmp con.msg_loop |
||
1860 | con.mouse: |
||
1861 | xor eax, eax |
||
1862 | xchg eax, dword [con.bUpPressed] |
||
1863 | mov dword [con.bUpPressed_saved], eax |
||
1864 | push 37 |
||
1865 | pop eax |
||
1866 | push 2 |
||
1867 | pop ebx |
||
1868 | int 0x40 |
||
1869 | test al, 1 |
||
1870 | jnz @f |
||
1871 | cmp [con.vscroll_pt], -1 |
||
1872 | jz .redraw_if_needed |
||
1873 | or [con.vscroll_pt], -1 |
||
1874 | .redraw_if_needed: |
||
1875 | cmp dword [con.bUpPressed_saved], 0 |
||
1876 | jnz con.redraw_image |
||
1877 | jmp con.msg_loop |
||
1878 | @@: |
||
1879 | mov al, 37 |
||
1880 | dec ebx |
||
1881 | int 0x40 |
||
1882 | movsx ebx, ax |
||
1883 | sar eax, 16 |
||
1884 | cmp [con.vscroll_pt], -1 |
||
1885 | jnz .vscrolling |
||
1886 | test ebx, ebx |
||
1887 | js .redraw_if_needed |
||
1888 | sub ax, [con.data_width] |
||
1889 | jb .redraw_if_needed |
||
1890 | cmp eax, con.vscroll_width |
||
1891 | jae .redraw_if_needed |
||
1892 | cmp ebx, con.vscroll_btn_height |
||
1893 | jb .up |
||
1894 | sub bx, [con.data_height] |
||
1895 | jae .redraw_if_needed |
||
1896 | cmp bx, -con.vscroll_btn_height |
||
1897 | jge .down |
||
1898 | add bx, [con.data_height] |
||
1899 | sub bx, word [con.vscrollbar_pos] |
||
1900 | jl .vscroll_up |
||
1901 | cmp bx, word [con.vscrollbar_size] |
||
1902 | jl .vscroll |
||
1903 | .vscroll_down: |
||
1904 | cmp [con.bScrollingDown_saved], 0 |
||
1905 | jz .vscroll_down_first |
||
1906 | cmp [con.bScrollingDown_saved], 1 |
||
1907 | jz .vscroll_down_wasfirst |
||
1908 | mov [con.bScrollingDown], 2 |
||
1909 | .vscroll_down_do: |
||
1910 | mov eax, [con.wnd_ypos] |
||
1911 | add eax, [con.wnd_height] |
||
1912 | dec eax |
||
1913 | mov ebx, [con.scr_height] |
||
1914 | sub ebx, [con.wnd_height] |
||
1915 | cmp eax, ebx |
||
1916 | jb @f |
||
1917 | mov eax, ebx |
||
1918 | @@: |
||
1919 | mov [con.wnd_ypos], eax |
||
1920 | jmp con.redraw_image |
||
1921 | .vscroll_down_first: |
||
1922 | push 26 |
||
1923 | pop eax |
||
1924 | push 9 |
||
1925 | pop ebx |
||
1926 | int 0x40 |
||
1927 | mov [con.scroll_down_first_time], eax |
||
1928 | mov [con.bScrollingDown], 1 |
||
1929 | jmp .vscroll_down_do |
||
1930 | .vscroll_down_wasfirst: |
||
1931 | push 26 |
||
1932 | pop eax |
||
1933 | push 9 |
||
1934 | pop ebx |
||
1935 | int 0x40 |
||
1936 | sub eax, [con.scroll_down_first_time] |
||
1937 | cmp eax, 25 |
||
1938 | jb @f |
||
1939 | mov [con.bScrollingDown], 2 |
||
1940 | jmp .vscroll_down_do |
||
1941 | @@: |
||
1942 | mov [con.bScrollingDown], 1 |
||
1943 | jmp con.msg_loop |
||
1944 | .vscroll_up: |
||
1945 | cmp [con.bScrollingUp_saved], 0 |
||
1946 | jz .vscroll_up_first |
||
1947 | cmp [con.bScrollingUp_saved], 1 |
||
1948 | jz .vscroll_up_wasfirst |
||
1949 | mov [con.bScrollingUp], 2 |
||
1950 | .vscroll_up_do: |
||
1951 | mov eax, [con.wnd_ypos] |
||
1952 | inc eax |
||
1953 | sub eax, [con.wnd_height] |
||
1954 | jns @f |
||
1955 | xor eax, eax |
||
1956 | @@: |
||
1957 | mov [con.wnd_ypos], eax |
||
1958 | jmp con.redraw_image |
||
1959 | .vscroll_up_first: |
||
1960 | push 26 |
||
1961 | pop eax |
||
1962 | push 9 |
||
1963 | pop ebx |
||
1964 | int 0x40 |
||
1965 | mov [con.scroll_up_first_time], eax |
||
1966 | mov [con.bScrollingUp], 1 |
||
1967 | jmp .vscroll_up_do |
||
1968 | .vscroll_up_wasfirst: |
||
1969 | push 26 |
||
1970 | pop eax |
||
1971 | push 9 |
||
1972 | pop ebx |
||
1973 | int 0x40 |
||
1974 | sub eax, [con.scroll_up_first_time] |
||
1975 | cmp eax, 25 |
||
1976 | jb @f |
||
1977 | mov [con.bScrollingUp], 2 |
||
1978 | jmp .vscroll_up_do |
||
1979 | @@: |
||
1980 | mov [con.bScrollingUp], 1 |
||
1981 | jmp con.msg_loop |
||
1982 | .up: |
||
1983 | cmp [con.bUpPressed_saved], 0 |
||
1984 | jz .up_first |
||
1985 | cmp [con.bUpPressed_saved], 1 |
||
1986 | jz .up_wasfirst |
||
1987 | mov [con.bUpPressed], 2 |
||
1988 | .up_do: |
||
1989 | mov eax, [con.wnd_ypos] |
||
1990 | dec eax |
||
1991 | js @f |
||
1992 | mov [con.wnd_ypos], eax |
||
1993 | @@: |
||
1994 | jmp con.redraw_image |
||
1995 | .up_first: |
||
1996 | push 26 |
||
1997 | pop eax |
||
1998 | push 9 |
||
1999 | pop ebx |
||
2000 | int 0x40 |
||
2001 | mov [con.up_first_time], eax |
||
2002 | mov [con.bUpPressed], 1 |
||
2003 | jmp .up_do |
||
2004 | .up_wasfirst: |
||
2005 | push 26 |
||
2006 | pop eax |
||
2007 | push 9 |
||
2008 | pop ebx |
||
2009 | int 0x40 |
||
2010 | sub eax, [con.up_first_time] |
||
2011 | cmp eax, 25 |
||
2012 | jb @f |
||
2013 | mov [con.bUpPressed], 2 |
||
2014 | jmp .up_do |
||
2015 | @@: |
||
2016 | mov [con.bUpPressed], 1 |
||
2017 | jmp con.msg_loop |
||
2018 | .down: |
||
2019 | cmp [con.bDownPressed_saved], 0 |
||
2020 | jz .down_first |
||
2021 | cmp [con.bDownPressed_saved], 1 |
||
2022 | jz .down_wasfirst |
||
2023 | mov [con.bDownPressed], 2 |
||
2024 | .down_do: |
||
2025 | mov eax, [con.scr_height] |
||
2026 | sub eax, [con.wnd_height] |
||
2027 | jbe con.redraw_image |
||
2028 | cmp [con.wnd_ypos], eax |
||
2029 | jae con.redraw_image |
||
2030 | inc [con.wnd_ypos] |
||
2031 | jmp con.redraw_image |
||
2032 | .down_first: |
||
2033 | push 26 |
||
2034 | pop eax |
||
2035 | push 9 |
||
2036 | pop ebx |
||
2037 | int 0x40 |
||
2038 | mov [con.down_first_time], eax |
||
2039 | mov [con.bDownPressed], 1 |
||
2040 | jmp .down_do |
||
2041 | .down_wasfirst: |
||
2042 | push 26 |
||
2043 | pop eax |
||
2044 | push 9 |
||
2045 | pop ebx |
||
2046 | int 0x40 |
||
2047 | sub eax, [con.down_first_time] |
||
2048 | cmp eax, 25 |
||
2049 | jb @f |
||
2050 | mov [con.bDownPressed], 2 |
||
2051 | jmp .down_do |
||
2052 | @@: |
||
2053 | mov [con.bDownPressed], 1 |
||
2054 | jmp con.msg_loop |
||
2055 | .vscroll: |
||
2056 | mov [con.vscroll_pt], ebx |
||
2057 | call con.draw_image |
||
2058 | jmp con.msg_loop |
||
2059 | .vscrolling: |
||
2060 | sub ebx, [con.vscroll_pt] |
||
2061 | sub ebx, con.vscroll_btn_height |
||
2062 | jge @f |
||
2063 | xor ebx, ebx |
||
2064 | @@: |
||
2065 | movzx eax, [con.data_height] |
||
2066 | sub eax, 2*con.vscroll_btn_height |
||
2067 | sub eax, [con.vscrollbar_size] |
||
2068 | cmp ebx, eax |
||
2069 | jb @f |
||
2070 | lea ebx, [eax-1] |
||
2071 | @@: |
||
2072 | xchg eax, ebx |
||
2073 | mov edx, [con.scr_height] |
||
2074 | sub edx, [con.wnd_height] |
||
2075 | inc edx |
||
2076 | mul edx |
||
2077 | div ebx |
||
2078 | cmp [con.wnd_ypos], eax |
||
2079 | jz con.msg_loop |
||
2080 | mov [con.wnd_ypos], eax |
||
2081 | jmp con.redraw_image |
||
2082 | |||
2083 | con.draw_window: |
||
2084 | push 12 |
||
2085 | pop eax |
||
2086 | xor ebx, ebx |
||
2087 | inc ebx |
||
2088 | int 0x40 |
||
2089 | mov al, 48 |
||
2090 | mov bl, 4 |
||
2091 | int 0x40 |
||
2092 | mov ebx, [con.def_wnd_x-2] |
||
2093 | mov bx, word [con.wnd_width] |
||
2094 | imul bx, font_width |
||
2095 | add bx, 5+5-1 |
||
2096 | mov ecx, [con.def_wnd_y-2] |
||
2097 | mov cx, word [con.wnd_height] |
||
2098 | imul cx, font_height |
||
2099 | lea ecx, [ecx+eax+5-1] |
||
2530 | leency | 2100 | mov edx, 0x74000000 |
836 | diamond | 2101 | mov edi, [con.title] |
2102 | ; place for scrollbar |
||
2103 | mov eax, [con.wnd_height] |
||
2104 | cmp eax, [con.scr_height] |
||
2105 | jae @f |
||
2106 | add ebx, con.vscroll_width |
||
2107 | @@: |
||
2108 | xor eax, eax |
||
2109 | int 0x40 |
||
3034 | leency | 2110 | ;Leency{ |
2111 | mov eax,9 |
||
2112 | mov ebx,process_info_buffer |
||
2113 | mov ecx,-1 |
||
2114 | int 0x40 |
||
2115 | mov eax,[ebx+70] |
||
2116 | mov [window_status],eax |
||
3686 | hidnplayr | 2117 | test [window_status],100b ; window is rolled up |
3034 | leency | 2118 | jnz .exit |
2119 | test [window_status],10b ; window is minimized to panel |
||
2120 | jnz .exit |
||
2121 | ;}Leency - I'm in diamond code... |
||
836 | diamond | 2122 | call con.draw_image |
3034 | leency | 2123 | |
2124 | .exit: |
||
836 | diamond | 2125 | push 12 |
2126 | pop eax |
||
2127 | push 2 |
||
2128 | pop ebx |
||
2129 | int 0x40 |
||
3686 | hidnplayr | 2130 | |
836 | diamond | 2131 | ret |
2132 | |||
2133 | con.draw_image: |
||
2134 | xor edx, edx |
||
2135 | mov ecx, [con.wnd_width] |
||
2136 | imul ecx, font_width |
||
2137 | mov [con.data_width], cx |
||
2138 | shl ecx, 16 |
||
2139 | mov cx, word [con.wnd_height] |
||
2140 | imul cx, font_height |
||
2141 | mov [con.data_height], cx |
||
2142 | mov ebx, [con.image] |
||
2143 | push 65 |
||
2144 | pop eax |
||
2145 | xor ebp, ebp |
||
2146 | mov edi, con.colors |
||
2147 | push 8 |
||
2148 | pop esi |
||
2149 | int 0x40 |
||
2150 | mov al, 7 |
||
2151 | mov edx, [con.wnd_height] |
||
2152 | cmp edx, [con.scr_height] |
||
2153 | jae .skip_vscroll |
||
2154 | push ecx |
||
2155 | mov edx, ecx |
||
2156 | xor dx, dx |
||
2157 | mov ebx, con.vscroll_btn3 |
||
2158 | cmp [con.bUpPressed], 0 |
||
2159 | jnz @f |
||
2160 | mov ebx, con.vscroll_btn1 |
||
2161 | @@: |
||
2162 | mov ecx, con.vscroll_width*65536 + con.vscroll_btn_height |
||
2163 | int 0x40 |
||
2164 | pop edx |
||
2165 | sub dx, con.vscroll_btn_height |
||
2166 | mov ebx, con.vscroll_btn4 |
||
2167 | cmp [con.bDownPressed], 0 |
||
2168 | jnz @f |
||
2169 | mov ebx, con.vscroll_btn2 |
||
2170 | @@: |
||
2171 | int 0x40 |
||
2172 | push edx |
||
2173 | ; Вычисляем высоту бегунка |
||
2174 | mov ax, dx |
||
2175 | sub eax, con.vscroll_btn_height |
||
2176 | mov ecx, eax |
||
2177 | mul [con.wnd_height] |
||
2178 | div [con.scr_height] |
||
2179 | cmp eax, 5 |
||
2180 | jae @f |
||
2181 | mov al, 5 |
||
2182 | @@: |
||
2183 | ; eax = высота бегунка. Вычисляем положение бегунка |
||
2184 | mov [con.vscrollbar_size], eax |
||
2185 | xchg eax, ecx |
||
2186 | sub eax, ecx |
||
2187 | mul [con.wnd_ypos] |
||
2188 | mov ebx, [con.scr_height] |
||
2189 | sub ebx, [con.wnd_height] |
||
2190 | div ebx |
||
2191 | pop edx |
||
2192 | push edx |
||
2193 | ; ecx = высота бегунка, eax = положение |
||
2194 | add eax, con.vscroll_btn_height |
||
2195 | mov [con.vscrollbar_pos], eax |
||
2196 | mov ebx, con.vscroll_bgr2 |
||
2197 | cmp [con.bScrollingUp], 0 |
||
2198 | jnz @f |
||
2199 | mov ebx, con.vscroll_bgr1 |
||
2200 | @@: |
||
2201 | mov ecx, con.vscroll_width*65536 + con.vscroll_bgr_height |
||
2202 | push eax |
||
2203 | push 7 |
||
2204 | pop eax |
||
2205 | mov dx, con.vscroll_btn_height |
||
2206 | call .vpattern |
||
2207 | mov dx, word [con.vscrollbar_pos] |
||
2208 | add dx, word [con.vscrollbar_size] |
||
2209 | mov cx, con.vscroll_bgr_height |
||
2210 | mov ebx, con.vscroll_bgr2 |
||
2211 | cmp [con.bScrollingDown], 0 |
||
2212 | jnz @f |
||
2213 | mov ebx, con.vscroll_bgr1 |
||
2214 | @@: |
||
2215 | call .vpattern |
||
2216 | mov ecx, [con.vscrollbar_pos] |
||
2217 | mov dx, cx |
||
2218 | add ecx, [con.vscrollbar_size] |
||
2219 | sub ecx, con.vscroll_bar_height3 |
||
2220 | push ecx |
||
2221 | mov ebx, con.vscroll_bar1 |
||
2222 | mov ecx, con.vscroll_width*65536 + con.vscroll_bar_height1 |
||
2223 | int 0x40 |
||
2224 | add dx, cx |
||
2225 | mov cx, con.vscroll_bar_height2 |
||
2226 | mov ebx, con.vscroll_bar2 |
||
2227 | call .vpattern |
||
2228 | mov ebx, con.vscroll_bar3 |
||
2229 | mov cx, con.vscroll_bar_height3 |
||
2230 | int 0x40 |
||
2231 | .skip_vscroll: |
||
2232 | ret |
||
2233 | |||
2234 | .vpattern: |
||
2235 | push edx |
||
2236 | add dx, cx |
||
2237 | cmp dx, [esp+8] |
||
2238 | pop edx |
||
2239 | jbe @f |
||
2240 | mov cx, [esp+4] |
||
2241 | sub cx, dx |
||
2242 | jz .ret |
||
2243 | @@: |
||
2244 | int 0x40 |
||
2245 | add dx, cx |
||
2246 | cmp dx, [esp+4] |
||
2247 | jb .vpattern |
||
2248 | .ret: |
||
2249 | ret 4 |
||
2250 | |||
2251 | align 4 |
||
2252 | con.colors dd 0x000000, 0x000080, 0x008000, 0x008080 |
||
2253 | dd 0x800000, 0x800080, 0x808000, 0xC0C0C0 |
||
2254 | dd 0x808080, 0x0000FF, 0x00FF00, 0x00FFFF |
||
2255 | dd 0xFF0000, 0xFF00FF, 0xFFFF00, 0xFFFFFF |
||
2256 | |||
2257 | scan_has_ascii: |
||
2258 | dd 11011111111111111111111111111110b |
||
2259 | dd 00000010001111111111101111111111b |
||
2260 | dd 00000000000000000000000000000000b |
||
2261 | dd 0 |
||
2262 | |||
2263 | con.extended_alt: |
||
2264 | db 00h,01h,78h,79h,7Ah,7Bh,7Ch,7Dh,7Eh,7Fh,80h,81h,82h,83h,0Eh,0A5h |
||
2265 | db 10h,11h,12h,13h,14h,15h,16h,17h,18h,19h,1Ah,1Bh,1Ch,00h,1Eh,1Fh |
||
2266 | db 20h,21h,22h,23h,24h,25h,26h,27h,28h,29h,00h,2Bh,2Ch,2Dh,2Eh,2Fh |
||
2267 | db 30h,31h,32h,33h,34h,35h,00h,37h,00h,39h,00h,68h,69h,6Ah,6Bh,6Ch |
||
2268 | db 6Dh,6Eh,6Fh,70h,71h,00h,00h,97h,98h,99h,4Ah,9Bh,9Ch,9Dh,4Eh,9Fh |
||
2269 | db 0A0h,0A1h,0A2h,0A3h,00h,00h,00h,8Bh,8Ch,00h,00h,00h,00h,00h,00h,00h |
||
2270 | times 20h db 0 |
||
2271 | con.extended_ctrl: |
||
2272 | times 0Fh db %-1 |
||
2273 | db 0x94 |
||
2274 | times 2Bh db %-1 |
||
2275 | db 5Eh,5Fh,60h,61h,62h,63h,64h,65h,66h,67h,00h,00h |
||
2276 | db 77h,8Dh,84h,8Eh,73h,8Fh,74h,90h,75h,91h,76h,92h,93h,00h,00h,00h,89h,8Ah |
||
2277 | times 0x80-0x59 db 0 |
||
2278 | con.extended_shift: |
||
2279 | times 3Bh db %-1 |
||
2280 | db 54h,55h,56h,57h,58h,59h,5Ah,5Bh,5Ch,5Dh,00h,00h |
||
2281 | db 47h,48h,49h,4Ah,4Bh,4Ch,4Dh,4Eh,4Fh,50h,51h,52h,53h,00h,00h,00h,87h,88h |
||
2282 | times 0x80-0x59 db 0 |
||
2283 | |||
2284 | ; В текущей реализации значения по умолчанию таковы. |
||
2285 | ; В будущем они, возможно, будут считываться как параметры из ini-файла console.ini. |
||
2286 | con.def_wnd_width dd 80 |
||
2287 | con.def_wnd_height dd 25 |
||
2288 | con.def_scr_width dd 80 |
||
2289 | con.def_scr_height dd 300 |
||
2290 | con.def_wnd_x dd 200 |
||
2291 | con.def_wnd_y dd 50 |
||
2292 | |||
3034 | leency | 2293 | |
2294 | struc process_info |
||
2295 | { |
||
2296 | cpu_usage dd ? ; +0 |
||
2297 | window_stack_position dw ? ; +4 |
||
2298 | window_stack_value dw ? ; +6 |
||
2299 | dw ? ; +8 |
||
2300 | process_name rb 12 ; +10 |
||
2301 | memory_start dd ? ; +22 |
||
2302 | used_memory dd ? ; +26 |
||
2303 | PID dd ? ; +30 |
||
2304 | box.x dd ? ; +34 |
||
2305 | box.y dd ? ; +38 |
||
2306 | box.width dd ? ; +42 |
||
2307 | box.height dd ? ; +46 |
||
2308 | slot_state dw ? ; +50 |
||
2309 | dw ? ; +52 |
||
2310 | client_box.x dd ? ; +54 |
||
2311 | client_box.y dd ? ; +58 |
||
2312 | client_box.width dd ? ; +62 |
||
2313 | client_box.height dd ? ; +66 |
||
2314 | wnd_state db ? ; +70 |
||
2315 | rb (1024-71) |
||
2316 | } |
||
2317 | process_info_buffer process_info |
||
3686 | hidnplayr | 2318 | window_status rd 1 |
3034 | leency | 2319 | |
836 | diamond | 2320 | con.vscroll_pt dd -1 |
2321 | |||
2322 | align 16 |
||
2323 | EXPORTS: |
||
2324 | dd szStart, START |
||
1145 | diamond | 2325 | dd szVersion, 0x00020007 |
836 | diamond | 2326 | dd szcon_init, con_init |
2327 | dd szcon_write_asciiz, con_write_asciiz |
||
3686 | hidnplayr | 2328 | dd szcon_write_string, con_write_length |
836 | diamond | 2329 | dd szcon_printf, con_printf |
2330 | dd szcon_exit, con_exit |
||
2331 | dd szcon_get_flags, con_get_flags |
||
2332 | dd szcon_set_flags, con_set_flags |
||
2333 | dd szcon_kbhit, con_kbhit |
||
2334 | dd szcon_getch, con_getch |
||
2335 | dd szcon_getch2, con_getch2 |
||
2336 | dd szcon_gets, con_gets |
||
852 | diamond | 2337 | dd szcon_gets2, con_gets2 |
836 | diamond | 2338 | dd szcon_get_font_height, con_get_font_height |
2339 | dd szcon_get_cursor_height,con_get_cursor_height |
||
2340 | dd szcon_set_cursor_height,con_set_cursor_height |
||
853 | diamond | 2341 | dd szcon_cls, con_cls |
2342 | dd szcon_get_cursor_pos, con_get_cursor_pos |
||
2343 | dd szcon_set_cursor_pos, con_set_cursor_pos |
||
836 | diamond | 2344 | dd 0 |
2345 | |||
2346 | con_flags dd 7 |
||
2347 | con.cursor_height dd (15*font_height+50)/100 |
||
2348 | con.input_start dd con.input_buffer |
||
2349 | con.input_end dd con.input_buffer |
||
2350 | |||
2351 | con_esc_attr_n dd 0 |
||
2352 | con_esc_attrs dd 0,0,0,0 |
||
2353 | con_esc db 0 |
||
2354 | con_sci db 0 |
||
2355 | |||
2356 | con.entered_char dw -1 |
||
2357 | con.bGetchRequested db 0 |
||
2358 | con.bWasE0 db 0 |
||
2359 | |||
2360 | szStart db 'START',0 |
||
2361 | |||
2362 | szcon_init db 'con_init',0 |
||
2363 | szcon_write_asciiz db 'con_write_asciiz',0 |
||
3686 | hidnplayr | 2364 | szcon_write_string db 'con_write_string',0 |
836 | diamond | 2365 | szcon_printf db 'con_printf',0 |
2366 | szcon_exit db 'con_exit',0 |
||
2367 | szVersion db 'version',0 |
||
2368 | szcon_get_flags db 'con_get_flags',0 |
||
2369 | szcon_set_flags db 'con_set_flags',0 |
||
2370 | szcon_kbhit db 'con_kbhit',0 |
||
2371 | szcon_getch db 'con_getch',0 |
||
2372 | szcon_getch2 db 'con_getch2',0 |
||
2373 | szcon_gets db 'con_gets',0 |
||
852 | diamond | 2374 | szcon_gets2 db 'con_gets2',0 |
836 | diamond | 2375 | szcon_get_font_height db 'con_get_font_height',0 |
2376 | szcon_get_cursor_height db 'con_get_cursor_height',0 |
||
2377 | szcon_set_cursor_height db 'con_set_cursor_height',0 |
||
853 | diamond | 2378 | szcon_cls db 'con_cls',0 |
2379 | szcon_get_cursor_pos db 'con_get_cursor_pos',0 |
||
2380 | szcon_set_cursor_pos db 'con_set_cursor_pos',0 |
||
836 | diamond | 2381 | |
2382 | con.thread_err db 'Cannot create console thread!',13,10,0 |
||
2383 | con.nomem_err db 'Not enough memory!',13,10,0 |
||
2384 | con.aFinished db ' [Finished]',0 |
||
2385 | con.aNull db '(null)',0 |
||
2386 | con.beep db 0x90, 0x3C, 0x00 |
||
2387 | con.ipc_buf dd 0,8,0,0 |
||
2388 | db 0 |
||
2389 | |||
2390 | section '.data' data readable writable align 16 |
||
2391 | |||
2392 | con.finished_title rb 256 |
||
2393 | |||
2394 | con.cur_x rd 1 |
||
2395 | con.cur_y rd 1 |
||
2396 | con.wnd_xpos rd 1 |
||
2397 | con.wnd_ypos rd 1 |
||
2398 | |||
2399 | con.wnd_width rd 1 |
||
2400 | con.wnd_height rd 1 |
||
2401 | con.scr_width rd 1 |
||
2402 | con.scr_height rd 1 |
||
2403 | con.title rd 1 |
||
2404 | con.data rd 1 |
||
2405 | con.image rd 1 |
||
2406 | con.console_tid rd 1 |
||
2407 | con.data_width rw 1 |
||
2408 | con.data_height rw 1 |
||
2409 | con.vscrollbar_size rd 1 |
||
2410 | con.vscrollbar_pos rd 1 |
||
2411 | con.up_first_time rd 1 |
||
2412 | con.down_first_time rd 1 |
||
2413 | con.scroll_up_first_time rd 1 |
||
2414 | con.scroll_down_first_time rd 1 |
||
2415 | con.bUpPressed_saved rb 1 |
||
2416 | con.bDownPressed_saved rb 1 |
||
2417 | con.bScrollingUp_saved rb 1 |
||
2418 | con.bScrollingDown_saved rb 1 |
||
2419 | |||
2420 | con.input_buffer rw 128 |
||
2421 | con.input_buffer_end = $ |
||
2422 | |||
2423 | con.kbd_layout rb 128 |
||
2424 | |||
2425 | ; 1 = exit, 2 = set title, 3 = redraw, 4 = getch |
||
2426 | con.thread_op rb 1 |
||
2427 | con.bUpPressed rb 1 |
||
2428 | con.bDownPressed rb 1 |
||
2429 | con.bScrollingUp rb 1 |
||
2430 | con.bScrollingDown rb 1 |
||
2431 | |||
2432 | con.stack rb 1024 |
||
2433 | con.stack_top = $ |