Subversion Repositories Kolibri OS

Rev

Rev 4622 | Rev 4827 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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