Rev 6023 | Rev 6097 | 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] |
||
210 | jle .noscroll ; There are less lines of text than fit into the window, dont scroll.. |
||
211 | sub edx, [edi + window.text_line_print] |
||
212 | je .noscroll ; We are already at the bottom pos, dont scroll.. |
||
213 | .scroll_to_pos: ; edx = number of lines to go up/down (flags must indicate direction) |
||
214 | pushf |
||
215 | add [edi + window.text_line_print], edx |
||
216 | mov esi, [edi + window.text_print] |
||
217 | popf |
||
218 | ja .loop_forward |
||
219 | std ; set direction flag so we can scan backwards |
||
220 | dec esi |
||
221 | dec esi ; move our cursor just in front of newline, for scanning backwards |
||
4143 | hidnplayr | 222 | .loop_backward: |
6023 | hidnplayr | 223 | call text_nextline |
224 | inc edx |
||
225 | jnz .loop_backward |
||
226 | inc esi |
||
227 | inc esi ; move the cursor just after last newline |
||
228 | cld |
||
229 | jmp .ok |
||
4060 | hidnplayr | 230 | |
4143 | hidnplayr | 231 | .loop_forward: |
6023 | hidnplayr | 232 | call text_nextline |
233 | dec edx |
||
234 | jnz .loop_forward |
||
4143 | hidnplayr | 235 | .ok: |
6023 | hidnplayr | 236 | mov [edi + window.text_print], esi |
4143 | hidnplayr | 237 | .noscroll: |
4060 | hidnplayr | 238 | |
4622 | hidnplayr | 239 | ; Update and draw scrollbar when nescessary |
6023 | hidnplayr | 240 | mov edx, [edi + window.text_lines] |
241 | cmp edx, [textbox_height] |
||
242 | jbe .scroll_done |
||
4622 | hidnplayr | 243 | |
6023 | hidnplayr | 244 | mov [scroll2.max_area], edx |
245 | mov eax, [edi + window.text_line_print] |
||
246 | mov [scroll2.position], eax |
||
4622 | hidnplayr | 247 | |
6023 | hidnplayr | 248 | push dword scroll2 ; redraw scrollbar |
249 | call [scrollbar_draw] |
||
250 | mov [scroll2.all_redraw], 0 ; next time, dont redraw it completely |
||
4622 | hidnplayr | 251 | .scroll_done: |
252 | |||
4621 | hidnplayr | 253 | ; Calculate start offset coordinates (align text to bottom) |
6023 | hidnplayr | 254 | mov ebx, [textbox_height] |
255 | sub ebx, [edi + window.text_lines] |
||
256 | jb .no_offset |
||
257 | imul ebx, FONT_HEIGHT |
||
258 | push [edi + window.text_start] |
||
259 | pop [edi + window.text_print] |
||
260 | jmp .draw_text |
||
4621 | hidnplayr | 261 | .no_offset: |
6023 | hidnplayr | 262 | xor ebx, ebx |
4621 | hidnplayr | 263 | .draw_text: |
6026 | hidnplayr | 264 | |
4143 | hidnplayr | 265 | ; Prepare to actually draw some text |
6026 | hidnplayr | 266 | add ebx, TEXT_X shl 16 + TEXT_Y ; text coordinates |
267 | mov ecx, [colors.work_text] ; default text color |
||
268 | or ecx, 0x30000000 |
||
269 | mov edx, [edi + window.text_print] ; start of text to print |
||
270 | |||
271 | ; Scan backwards on line for color escape codes |
||
272 | mov esi, edx |
||
273 | push edx |
||
274 | std |
||
275 | @@: |
||
276 | lodsb |
||
277 | cmp al, 0 ; end of text |
||
278 | je @f |
||
279 | cmp al, 10 ; hard newline |
||
280 | je @f |
||
281 | cmp al, 3 ; mIRC escape code |
||
282 | jne @b |
||
283 | |||
284 | cld |
||
285 | lea edx, [esi+2] |
||
286 | call dec_to_esi |
||
287 | jz @f |
||
288 | mov ecx, [irc_colors + 4*esi] |
||
289 | or ecx, 0x30000000 ; UTF-8 text |
||
290 | |||
291 | cmp byte[edx], ',' ; background color? |
||
292 | jne @f |
||
293 | inc edx |
||
294 | call dec_to_esi |
||
295 | jz @f |
||
296 | mov edi, [irc_colors + 4*esi] |
||
297 | or ecx, 0x40000000 ; enable background color |
||
298 | @@: |
||
299 | cld |
||
300 | |||
301 | pop edx |
||
302 | mov eax, [textbox_height] ; max number of lines to draw |
||
4143 | hidnplayr | 303 | .drawloop: |
6023 | hidnplayr | 304 | cmp byte[edx], 0 |
305 | je .end_of_text |
||
4060 | hidnplayr | 306 | |
4143 | hidnplayr | 307 | ; Clear one row of characters |
6023 | hidnplayr | 308 | pusha |
309 | mov cx, bx |
||
310 | shl ecx, 16 |
||
311 | mov cx, FONT_HEIGHT |
||
312 | mov ebx, TEXT_X shl 16 |
||
313 | mov bx, word[textbox_width] |
||
314 | imul bx, FONT_WIDTH |
||
315 | mov edx, [colors.work] |
||
6026 | hidnplayr | 316 | mcall 13 ; draw rectangle |
6023 | hidnplayr | 317 | popa |
4060 | hidnplayr | 318 | |
6026 | hidnplayr | 319 | push eax |
320 | mov esi, [textbox_width] |
||
4143 | hidnplayr | 321 | .line: |
6023 | hidnplayr | 322 | cmp byte[edx], 0 |
323 | je .end_of_text |
||
324 | cmp byte[edx], 13 |
||
325 | je .newline_soft |
||
326 | cmp byte[edx], 10 |
||
327 | je .newline_hard |
||
4143 | hidnplayr | 328 | |
6026 | hidnplayr | 329 | push esi |
330 | cmp byte[edx], 3 ; escape code for mIRC colors |
||
6023 | hidnplayr | 331 | jne .no_colors |
332 | inc edx |
||
333 | call dec_to_esi |
||
334 | jz .no_colors |
||
335 | mov ecx, [irc_colors + 4*esi] |
||
6026 | hidnplayr | 336 | or ecx, 0x30000000 |
4143 | hidnplayr | 337 | |
6026 | hidnplayr | 338 | cmp byte[edx], ',' ; background color? |
6023 | hidnplayr | 339 | jne .no_colors |
340 | inc edx |
||
341 | call dec_to_esi |
||
342 | jz .no_colors |
||
343 | mov edi, [irc_colors + 4*esi] |
||
344 | or ecx, 0x40000000 |
||
4143 | hidnplayr | 345 | .no_colors: |
346 | |||
6023 | hidnplayr | 347 | mov esi, 1 |
6026 | hidnplayr | 348 | mcall 4 ; draw text |
349 | |||
350 | mov esi, 1 |
||
351 | mov al, byte[edx] |
||
352 | test al, 10000000b |
||
353 | jz @f |
||
354 | mov esi, 4 |
||
355 | and al, 11111000b |
||
356 | cmp al, 11110000b |
||
357 | je @f |
||
358 | dec esi |
||
359 | and al, 11110000b |
||
360 | cmp al, 11100000b |
||
361 | je @f |
||
362 | dec esi |
||
363 | @@: |
||
364 | |||
6023 | hidnplayr | 365 | add ebx, FONT_WIDTH shl 16 |
6026 | hidnplayr | 366 | add edx, esi |
367 | pop esi |
||
368 | dec esi |
||
369 | jnz .line |
||
6023 | hidnplayr | 370 | jmp .line_full |
4060 | hidnplayr | 371 | |
4143 | hidnplayr | 372 | .newline_hard: |
6023 | hidnplayr | 373 | mov ecx, [colors.work_text] |
6026 | hidnplayr | 374 | or ecx, 0x30000000 |
4143 | hidnplayr | 375 | .newline_soft: |
6023 | hidnplayr | 376 | inc edx |
4143 | hidnplayr | 377 | .line_full: |
6023 | hidnplayr | 378 | and ebx, 0x0000ffff |
379 | add ebx, TEXT_X shl 16 + FONT_HEIGHT |
||
6026 | hidnplayr | 380 | pop eax |
6023 | hidnplayr | 381 | dec eax |
382 | jnz .drawloop |
||
4621 | hidnplayr | 383 | .end_of_text: |
4060 | hidnplayr | 384 | |
6023 | hidnplayr | 385 | ret |
4143 | hidnplayr | 386 | |
387 | |||
388 | |||
389 | |||
390 | dec_to_esi: |
||
391 | |||
6023 | hidnplayr | 392 | xor esi, esi |
4143 | hidnplayr | 393 | .loop: |
6023 | hidnplayr | 394 | movzx eax, byte[edx] |
395 | sub al, '0' |
||
396 | jb .done |
||
397 | cmp al, 9 |
||
398 | ja .done |
||
399 | inc edx |
||
400 | lea esi, [esi*4 + esi] ; esi * 5 |
||
401 | lea esi, [esi*2 + eax] ; esi * 2 + eax |
||
402 | jmp .loop |
||
4143 | hidnplayr | 403 | .done: |
6023 | hidnplayr | 404 | cmp esi, 16 |
405 | jae .fail |
||
406 | ret |
||
4143 | hidnplayr | 407 | |
408 | .fail: |
||
6023 | hidnplayr | 409 | xor esi, esi |
410 | ret |
||
4143 | hidnplayr | 411 | |
412 | |||
413 | |||
414 | if TIMESTAMP |
||
415 | print_timestamp: |
||
416 | |||
6023 | hidnplayr | 417 | pusha |
418 | mcall 3 ; get system time |
||
419 | mov ebx, eax |
||
4143 | hidnplayr | 420 | |
6023 | hidnplayr | 421 | mov al, '[' |
422 | call print_char |
||
423 | mov ecx, TIMESTAMP |
||
4143 | hidnplayr | 424 | .loop: |
6023 | hidnplayr | 425 | mov al, bl |
426 | shr al, 4 |
||
427 | add al, '0' |
||
428 | call print_char |
||
4143 | hidnplayr | 429 | |
6023 | hidnplayr | 430 | mov al, bl |
431 | and al, 0x0f |
||
432 | add al, '0' |
||
433 | call print_char |
||
4143 | hidnplayr | 434 | |
6023 | hidnplayr | 435 | dec ecx |
436 | jz .done |
||
4143 | hidnplayr | 437 | |
6023 | hidnplayr | 438 | mov al, ':' |
439 | call print_char |
||
440 | shr ebx, 8 |
||
441 | jmp .loop |
||
4143 | hidnplayr | 442 | .done: |
6023 | hidnplayr | 443 | mov al, ']' |
444 | call print_char |
||
445 | mov al, ' ' |
||
446 | call print_char |
||
4143 | hidnplayr | 447 | |
6023 | hidnplayr | 448 | popa |
449 | ret |
||
4143 | hidnplayr | 450 | end if |