Rev 6026 | Rev 6596 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4060 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
6023 | hidnplayr | 3 | ;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;; |
4060 | hidnplayr | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
4143 | hidnplayr | 6 | ;; Written by hidnplayr@kolibrios.org ;; |
4060 | hidnplayr | 7 | ;; ;; |
8 | ;; GNU GENERAL PUBLIC LICENSE ;; |
||
9 | ;; Version 2, June 1991 ;; |
||
10 | ;; ;; |
||
11 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
12 | |||
13 | |||
6026 | hidnplayr | 14 | text_insert_newlines: ; esi = ASCIIZ string |
4143 | hidnplayr | 15 | |
6023 | hidnplayr | 16 | xor edx, edx ; number of lines of text |
17 | cmp byte[esi], 0 |
||
18 | je .done |
||
4143 | hidnplayr | 19 | .next_line: |
6023 | hidnplayr | 20 | xor ebx, ebx |
21 | mov ecx, [textbox_width] |
||
22 | inc ecx |
||
4143 | hidnplayr | 23 | .more: |
6023 | hidnplayr | 24 | dec ecx |
25 | jz .end_of_line |
||
26 | lodsb ; get one character of the string |
||
6026 | hidnplayr | 27 | test al, 0x80 |
28 | jnz .multiball! |
||
6023 | hidnplayr | 29 | test al, al ; end of string? |
30 | jz .almost_done |
||
31 | cmp al, ' ' ; it's a space! remember its position |
||
32 | je .space |
||
33 | cmp al, 13 ; we already inserted a newline once, make it a space again |
||
34 | je .soft_nl |
||
35 | cmp al, 10 ; it's a newline, continue onto the next line |
||
36 | jne .more |
||
37 | inc edx |
||
38 | jmp .next_line |
||
4143 | hidnplayr | 39 | .soft_nl: |
6023 | hidnplayr | 40 | mov byte[esi-1], ' ' |
4143 | hidnplayr | 41 | .space: |
6023 | hidnplayr | 42 | mov ebx, esi ; last detected space |
43 | jmp .more |
||
4143 | hidnplayr | 44 | .end_of_line: |
6023 | hidnplayr | 45 | inc edx |
46 | test ebx, ebx ; did we detect any spaces on this line? |
||
47 | jz .next_line ; no: just continue onto the next line |
||
48 | mov byte[ebx-1], 13 ; yes: replace last space on line with a soft newline |
||
49 | mov esi, ebx ; and continue parsing just after last space |
||
50 | jmp .next_line ; |
||
4143 | hidnplayr | 51 | .almost_done: |
6023 | hidnplayr | 52 | dec esi |
4143 | hidnplayr | 53 | .done: |
54 | |||
6023 | hidnplayr | 55 | ret |
4143 | hidnplayr | 56 | |
6026 | hidnplayr | 57 | .multiball!: |
58 | add esi, 4 |
||
59 | and al, 11111000b |
||
60 | cmp al, 11110000b |
||
61 | je .more |
||
62 | dec esi |
||
63 | and al, 11110000b |
||
64 | cmp al, 11100000b |
||
65 | je .more |
||
66 | dec esi |
||
67 | jmp .more |
||
68 | |||
69 | |||
70 | |||
4623 | hidnplayr | 71 | ;---------------------------------- |
72 | ; scan untill next line is reached |
||
73 | ; |
||
4143 | hidnplayr | 74 | ; When you set the direction flag before calling, you can also scan for previous line! |
4623 | hidnplayr | 75 | ; IN: esi |
76 | ; OUT: esi |
||
77 | ;---------------------------------- |
||
4143 | hidnplayr | 78 | text_nextline: |
79 | |||
6023 | hidnplayr | 80 | mov ecx, [textbox_width] |
4143 | hidnplayr | 81 | .loop: |
6023 | hidnplayr | 82 | lodsb |
83 | test al, al |
||
84 | jz .done |
||
85 | cmp al, 10 |
||
86 | je .done |
||
87 | cmp al, 13 |
||
88 | je .done |
||
89 | dec ecx |
||
90 | jnz .loop |
||
4143 | hidnplayr | 91 | .done: |
92 | |||
6023 | hidnplayr | 93 | ret |
4143 | hidnplayr | 94 | |
95 | |||
4623 | hidnplayr | 96 | ;---------------------------------- |
97 | ; print string |
||
98 | ; |
||
99 | ; IN: esi = ptr to string |
||
100 | ; bl = char which marks end of string |
||
101 | ; OUT: esi = ptr to end of str |
||
102 | ;---------------------------------- |
||
103 | print_string: |
||
4060 | hidnplayr | 104 | |
6023 | hidnplayr | 105 | push eax |
4623 | hidnplayr | 106 | .loop: |
6023 | hidnplayr | 107 | lodsb |
108 | cmp al, bl |
||
109 | je .done |
||
110 | cmp al, 13 |
||
111 | je .loop |
||
112 | test al, al |
||
113 | jz .done |
||
114 | call print_char |
||
115 | jmp .loop |
||
4060 | hidnplayr | 116 | .done: |
6023 | hidnplayr | 117 | pop eax |
4143 | hidnplayr | 118 | |
6023 | hidnplayr | 119 | ret |
4060 | hidnplayr | 120 | |
121 | |||
4623 | hidnplayr | 122 | ;---------------------------------- |
123 | ; print ASCIIZ string |
||
124 | ; |
||
125 | ; IN: esi = ptr to ASCIIZ string |
||
126 | ; OUT: esi = ptr to end of str |
||
127 | ;---------------------------------- |
||
128 | print_asciiz: |
||
4060 | hidnplayr | 129 | |
6023 | hidnplayr | 130 | push eax |
4060 | hidnplayr | 131 | .loop: |
6023 | hidnplayr | 132 | lodsb |
133 | test al, al |
||
134 | jz .done |
||
135 | call print_char |
||
136 | jmp .loop |
||
4060 | hidnplayr | 137 | .done: |
6023 | hidnplayr | 138 | pop eax |
4143 | hidnplayr | 139 | |
6023 | hidnplayr | 140 | ret |
4060 | hidnplayr | 141 | |
142 | |||
4623 | hidnplayr | 143 | ;---------------------------------- |
144 | ; print character |
||
145 | ; |
||
146 | ; IN: al = char to print |
||
147 | ; OUT: / |
||
148 | ;---------------------------------- |
||
149 | print_char: |
||
4060 | hidnplayr | 150 | |
6023 | hidnplayr | 151 | push esi edi |
152 | mov esi, [window_print] |
||
153 | mov edi, [esi + window.text_write] |
||
154 | stosb |
||
155 | cmp edi, [esi + window.text_end] |
||
156 | jae .uh_ow |
||
157 | mov [esi + window.text_write], edi |
||
4143 | hidnplayr | 158 | .continue: |
6023 | hidnplayr | 159 | or [esi + window.flags], FLAG_UPDATED |
160 | pop edi esi |
||
4143 | hidnplayr | 161 | |
6023 | hidnplayr | 162 | ret |
4143 | hidnplayr | 163 | |
164 | .uh_ow: |
||
6023 | hidnplayr | 165 | pusha |
166 | mov edi, [esi + window.text_start] |
||
167 | mov [esi + window.text_print], edi |
||
168 | lea esi, [edi + TEXT_BUFFERSIZE/2] |
||
169 | call text_nextline |
||
170 | mov ecx, TEXT_BUFFERSIZE/8 |
||
171 | rep movsd |
||
172 | mov esi, edi |
||
173 | call text_insert_newlines |
||
4060 | hidnplayr | 174 | |
6023 | hidnplayr | 175 | mov ebx, [window_print] |
176 | mov [ebx + window.text_lines], edx |
||
177 | mov [ebx + window.text_scanned], esi |
||
178 | mov [ebx + window.text_write], esi |
||
179 | mov [ebx + window.text_line_print], 0 |
||
180 | popa |
||
4060 | hidnplayr | 181 | |
6023 | hidnplayr | 182 | jmp .continue |
4060 | hidnplayr | 183 | |
184 | |||
185 | |||
4143 | hidnplayr | 186 | draw_channel_text: |
4060 | hidnplayr | 187 | |
6023 | hidnplayr | 188 | mov edi, [window_active] |
189 | and [edi + window.flags], not FLAG_UPDATED ; clear the 'window is updated' flag |
||
4060 | hidnplayr | 190 | |
4143 | hidnplayr | 191 | ; Scan new text for newlines |
6023 | hidnplayr | 192 | mov esi, [edi + window.text_scanned] |
193 | call text_insert_newlines |
||
194 | add [edi + window.text_lines], edx |
||
195 | mov [edi + window.text_scanned], esi |
||
4060 | hidnplayr | 196 | |
4621 | hidnplayr | 197 | ; Is scrollbar at lowest position? |
6023 | hidnplayr | 198 | test [edi + window.flags], FLAG_SCROLL_LOW |
6026 | hidnplayr | 199 | jnz .yesscroll ; Yes |
200 | cmp [scroll2.all_redraw], 1 ; No |
||
6023 | hidnplayr | 201 | jnz .noscroll |
202 | mov edx, [textbox_height] |
||
203 | add edx, [edi + window.text_line_print] |
||
4827 | gtament | 204 | cmp edx, [edi + window.text_lines] |
6023 | hidnplayr | 205 | jl .noscroll |
4621 | hidnplayr | 206 | .yesscroll: |
207 | ; Scrollbar was at lowest position, scroll down automatically when new text arrived. |
||
6023 | hidnplayr | 208 | mov edx, [edi + window.text_lines] |
209 | sub edx, [textbox_height] |
||
6097 | hidnplayr | 210 | jg @f |
211 | mov [edi + window.text_line_print], 0 |
||
212 | jmp .noscroll ; There are less lines of text than fit into the window, dont scroll.. |
||
213 | @@: |
||
6023 | hidnplayr | 214 | sub edx, [edi + window.text_line_print] |
215 | je .noscroll ; We are already at the bottom pos, dont scroll.. |
||
216 | .scroll_to_pos: ; edx = number of lines to go up/down (flags must indicate direction) |
||
217 | pushf |
||
218 | add [edi + window.text_line_print], edx |
||
219 | mov esi, [edi + window.text_print] |
||
220 | popf |
||
6097 | hidnplayr | 221 | jg .loop_forward |
6023 | hidnplayr | 222 | std ; set direction flag so we can scan backwards |
223 | dec esi |
||
224 | dec esi ; move our cursor just in front of newline, for scanning backwards |
||
4143 | hidnplayr | 225 | .loop_backward: |
6023 | hidnplayr | 226 | call text_nextline |
227 | inc edx |
||
228 | jnz .loop_backward |
||
229 | inc esi |
||
230 | inc esi ; move the cursor just after last newline |
||
231 | cld |
||
232 | jmp .ok |
||
4060 | hidnplayr | 233 | |
4143 | hidnplayr | 234 | .loop_forward: |
6023 | hidnplayr | 235 | call text_nextline |
236 | dec edx |
||
237 | jnz .loop_forward |
||
4143 | hidnplayr | 238 | .ok: |
6023 | hidnplayr | 239 | mov [edi + window.text_print], esi |
4143 | hidnplayr | 240 | .noscroll: |
4060 | hidnplayr | 241 | |
4622 | hidnplayr | 242 | ; Update and draw scrollbar when nescessary |
6023 | hidnplayr | 243 | mov edx, [edi + window.text_lines] |
244 | cmp edx, [textbox_height] |
||
245 | jbe .scroll_done |
||
4622 | hidnplayr | 246 | |
6023 | hidnplayr | 247 | mov [scroll2.max_area], edx |
248 | mov eax, [edi + window.text_line_print] |
||
249 | mov [scroll2.position], eax |
||
4622 | hidnplayr | 250 | |
6023 | hidnplayr | 251 | push dword scroll2 ; redraw scrollbar |
252 | call [scrollbar_draw] |
||
253 | mov [scroll2.all_redraw], 0 ; next time, dont redraw it completely |
||
4622 | hidnplayr | 254 | .scroll_done: |
255 | |||
4621 | hidnplayr | 256 | ; Calculate start offset coordinates (align text to bottom) |
6023 | hidnplayr | 257 | mov ebx, [textbox_height] |
258 | sub ebx, [edi + window.text_lines] |
||
259 | jb .no_offset |
||
260 | imul ebx, FONT_HEIGHT |
||
261 | push [edi + window.text_start] |
||
262 | pop [edi + window.text_print] |
||
263 | jmp .draw_text |
||
4621 | hidnplayr | 264 | .no_offset: |
6023 | hidnplayr | 265 | xor ebx, ebx |
4621 | hidnplayr | 266 | .draw_text: |
6026 | hidnplayr | 267 | |
4143 | hidnplayr | 268 | ; Prepare to actually draw some text |
6026 | hidnplayr | 269 | add ebx, TEXT_X shl 16 + TEXT_Y ; text coordinates |
270 | mov ecx, [colors.work_text] ; default text color |
||
271 | or ecx, 0x30000000 |
||
272 | mov edx, [edi + window.text_print] ; start of text to print |
||
273 | |||
274 | ; Scan backwards on line for color escape codes |
||
275 | mov esi, edx |
||
276 | push edx |
||
277 | std |
||
278 | @@: |
||
279 | lodsb |
||
280 | cmp al, 0 ; end of text |
||
281 | je @f |
||
282 | cmp al, 10 ; hard newline |
||
283 | je @f |
||
284 | cmp al, 3 ; mIRC escape code |
||
285 | jne @b |
||
286 | |||
287 | cld |
||
288 | lea edx, [esi+2] |
||
289 | call dec_to_esi |
||
290 | jz @f |
||
291 | mov ecx, [irc_colors + 4*esi] |
||
292 | or ecx, 0x30000000 ; UTF-8 text |
||
293 | |||
294 | cmp byte[edx], ',' ; background color? |
||
295 | jne @f |
||
296 | inc edx |
||
297 | call dec_to_esi |
||
298 | jz @f |
||
299 | mov edi, [irc_colors + 4*esi] |
||
300 | or ecx, 0x40000000 ; enable background color |
||
301 | @@: |
||
302 | cld |
||
303 | |||
304 | pop edx |
||
305 | mov eax, [textbox_height] ; max number of lines to draw |
||
4143 | hidnplayr | 306 | .drawloop: |
6023 | hidnplayr | 307 | cmp byte[edx], 0 |
308 | je .end_of_text |
||
4060 | hidnplayr | 309 | |
4143 | hidnplayr | 310 | ; Clear one row of characters |
6023 | hidnplayr | 311 | pusha |
312 | mov cx, bx |
||
313 | shl ecx, 16 |
||
314 | mov cx, FONT_HEIGHT |
||
315 | mov ebx, TEXT_X shl 16 |
||
316 | mov bx, word[textbox_width] |
||
317 | imul bx, FONT_WIDTH |
||
318 | mov edx, [colors.work] |
||
6026 | hidnplayr | 319 | mcall 13 ; draw rectangle |
6023 | hidnplayr | 320 | popa |
4060 | hidnplayr | 321 | |
6026 | hidnplayr | 322 | push eax |
323 | mov esi, [textbox_width] |
||
4143 | hidnplayr | 324 | .line: |
6023 | hidnplayr | 325 | cmp byte[edx], 0 |
326 | je .end_of_text |
||
327 | cmp byte[edx], 13 |
||
328 | je .newline_soft |
||
329 | cmp byte[edx], 10 |
||
330 | je .newline_hard |
||
4143 | hidnplayr | 331 | |
6026 | hidnplayr | 332 | push esi |
333 | cmp byte[edx], 3 ; escape code for mIRC colors |
||
6023 | hidnplayr | 334 | jne .no_colors |
335 | inc edx |
||
336 | call dec_to_esi |
||
337 | jz .no_colors |
||
338 | mov ecx, [irc_colors + 4*esi] |
||
6026 | hidnplayr | 339 | or ecx, 0x30000000 |
4143 | hidnplayr | 340 | |
6026 | hidnplayr | 341 | cmp byte[edx], ',' ; background color? |
6023 | hidnplayr | 342 | jne .no_colors |
343 | inc edx |
||
344 | call dec_to_esi |
||
345 | jz .no_colors |
||
346 | mov edi, [irc_colors + 4*esi] |
||
347 | or ecx, 0x40000000 |
||
4143 | hidnplayr | 348 | .no_colors: |
349 | |||
6023 | hidnplayr | 350 | mov esi, 1 |
6026 | hidnplayr | 351 | mcall 4 ; draw text |
352 | |||
353 | mov esi, 1 |
||
354 | mov al, byte[edx] |
||
355 | test al, 10000000b |
||
356 | jz @f |
||
357 | mov esi, 4 |
||
358 | and al, 11111000b |
||
359 | cmp al, 11110000b |
||
360 | je @f |
||
361 | dec esi |
||
362 | and al, 11110000b |
||
363 | cmp al, 11100000b |
||
364 | je @f |
||
365 | dec esi |
||
366 | @@: |
||
367 | |||
6023 | hidnplayr | 368 | add ebx, FONT_WIDTH shl 16 |
6026 | hidnplayr | 369 | add edx, esi |
370 | pop esi |
||
371 | dec esi |
||
372 | jnz .line |
||
6023 | hidnplayr | 373 | jmp .line_full |
4060 | hidnplayr | 374 | |
4143 | hidnplayr | 375 | .newline_hard: |
6023 | hidnplayr | 376 | mov ecx, [colors.work_text] |
6026 | hidnplayr | 377 | or ecx, 0x30000000 |
4143 | hidnplayr | 378 | .newline_soft: |
6023 | hidnplayr | 379 | inc edx |
4143 | hidnplayr | 380 | .line_full: |
6023 | hidnplayr | 381 | and ebx, 0x0000ffff |
382 | add ebx, TEXT_X shl 16 + FONT_HEIGHT |
||
6026 | hidnplayr | 383 | pop eax |
6023 | hidnplayr | 384 | dec eax |
385 | jnz .drawloop |
||
4621 | hidnplayr | 386 | .end_of_text: |
4060 | hidnplayr | 387 | |
6023 | hidnplayr | 388 | ret |
4143 | hidnplayr | 389 | |
390 | |||
391 | |||
392 | |||
393 | dec_to_esi: |
||
394 | |||
6023 | hidnplayr | 395 | xor esi, esi |
4143 | hidnplayr | 396 | .loop: |
6023 | hidnplayr | 397 | movzx eax, byte[edx] |
398 | sub al, '0' |
||
399 | jb .done |
||
400 | cmp al, 9 |
||
401 | ja .done |
||
402 | inc edx |
||
403 | lea esi, [esi*4 + esi] ; esi * 5 |
||
404 | lea esi, [esi*2 + eax] ; esi * 2 + eax |
||
405 | jmp .loop |
||
4143 | hidnplayr | 406 | .done: |
6023 | hidnplayr | 407 | cmp esi, 16 |
408 | jae .fail |
||
409 | ret |
||
4143 | hidnplayr | 410 | |
411 | .fail: |
||
6023 | hidnplayr | 412 | xor esi, esi |
413 | ret |
||
4143 | hidnplayr | 414 | |
415 | |||
416 | |||
417 | if TIMESTAMP |
||
418 | print_timestamp: |
||
419 | |||
6023 | hidnplayr | 420 | pusha |
421 | mcall 3 ; get system time |
||
422 | mov ebx, eax |
||
4143 | hidnplayr | 423 | |
6023 | hidnplayr | 424 | mov al, '[' |
425 | call print_char |
||
426 | mov ecx, TIMESTAMP |
||
4143 | hidnplayr | 427 | .loop: |
6023 | hidnplayr | 428 | mov al, bl |
429 | shr al, 4 |
||
430 | add al, '0' |
||
431 | call print_char |
||
4143 | hidnplayr | 432 | |
6023 | hidnplayr | 433 | mov al, bl |
434 | and al, 0x0f |
||
435 | add al, '0' |
||
436 | call print_char |
||
4143 | hidnplayr | 437 | |
6023 | hidnplayr | 438 | dec ecx |
439 | jz .done |
||
4143 | hidnplayr | 440 | |
6023 | hidnplayr | 441 | mov al, ':' |
442 | call print_char |
||
443 | shr ebx, 8 |
||
444 | jmp .loop |
||
4143 | hidnplayr | 445 | .done: |
6023 | hidnplayr | 446 | mov al, ']' |
447 | call print_char |
||
448 | mov al, ' ' |
||
449 | call print_char |
||
4143 | hidnplayr | 450 | |
6023 | hidnplayr | 451 | popa |
452 | ret |
||
4143 | hidnplayr | 453 | end if |