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