Subversion Repositories Kolibri OS

Rev

Rev 6023 | Rev 6097 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2004-2016. All rights reserved.    ;;
  4. ;; Distributed under terms of the GNU General Public License       ;;
  5. ;;                                                                 ;;
  6. ;;   Written by hidnplayr@kolibrios.org                            ;;
  7. ;;                                                                 ;;
  8. ;;         GNU GENERAL PUBLIC LICENSE                              ;;
  9. ;;          Version 2, June 1991                                   ;;
  10. ;;                                                                 ;;
  11. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12.  
  13.  
  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, 0x80
  28.         jnz     .multiball!
  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
  39.   .soft_nl:
  40.         mov     byte[esi-1], ' '
  41.   .space:
  42.         mov     ebx, esi                ; last detected space
  43.         jmp     .more
  44.   .end_of_line:
  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              ;
  51.   .almost_done:
  52.         dec     esi
  53.   .done:
  54.  
  55.         ret
  56.  
  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.  
  71. ;----------------------------------
  72. ; scan untill next line is reached
  73. ;
  74. ; When you set the direction flag before calling, you can also scan for previous line!
  75. ; IN:   esi
  76. ; OUT:  esi
  77. ;----------------------------------
  78. text_nextline:
  79.  
  80.         mov     ecx, [textbox_width]
  81.   .loop:
  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
  91.   .done:
  92.  
  93.         ret
  94.  
  95.  
  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:
  104.  
  105.         push    eax
  106.   .loop:
  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
  116.   .done:
  117.         pop     eax
  118.  
  119.         ret
  120.  
  121.  
  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:
  129.  
  130.         push    eax
  131.   .loop:
  132.         lodsb
  133.         test    al, al
  134.         jz      .done
  135.         call    print_char
  136.         jmp     .loop
  137.   .done:
  138.         pop     eax
  139.  
  140.         ret
  141.  
  142.  
  143. ;----------------------------------
  144. ; print character
  145. ;
  146. ; IN:   al = char to print
  147. ; OUT:  /
  148. ;----------------------------------
  149. print_char:
  150.  
  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
  158.   .continue:
  159.         or      [esi + window.flags], FLAG_UPDATED
  160.         pop     edi esi
  161.  
  162.         ret
  163.  
  164.   .uh_ow:
  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
  174.  
  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
  181.  
  182.         jmp     .continue
  183.  
  184.  
  185.  
  186. draw_channel_text:
  187.  
  188.         mov     edi, [window_active]
  189.         and     [edi + window.flags], not FLAG_UPDATED  ; clear the 'window is updated' flag
  190.  
  191. ; Scan new text for newlines
  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
  196.  
  197. ; Is scrollbar at lowest position?
  198.         test    [edi + window.flags], FLAG_SCROLL_LOW
  199.         jnz     .yesscroll                              ; Yes
  200.         cmp     [scroll2.all_redraw], 1                 ; No
  201.         jnz      .noscroll
  202.         mov     edx, [textbox_height]
  203.         add     edx, [edi + window.text_line_print]
  204.     cmp edx, [edi + window.text_lines]
  205.         jl      .noscroll
  206.   .yesscroll:
  207. ; Scrollbar was at lowest position, scroll down automatically when new text arrived.
  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
  222.   .loop_backward:
  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
  230.  
  231.   .loop_forward:
  232.         call    text_nextline
  233.         dec     edx
  234.         jnz     .loop_forward
  235.   .ok:
  236.         mov     [edi + window.text_print], esi
  237.   .noscroll:
  238.  
  239. ; Update and draw scrollbar when nescessary
  240.         mov     edx, [edi + window.text_lines]
  241.         cmp     edx, [textbox_height]
  242.         jbe     .scroll_done
  243.  
  244.         mov     [scroll2.max_area], edx
  245.         mov     eax, [edi + window.text_line_print]
  246.         mov     [scroll2.position], eax
  247.  
  248.         push    dword scroll2                   ; redraw scrollbar
  249.         call    [scrollbar_draw]
  250.         mov     [scroll2.all_redraw], 0         ; next time, dont redraw it completely
  251.   .scroll_done:
  252.  
  253. ; Calculate start offset coordinates (align text to bottom)
  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
  261.   .no_offset:
  262.         xor     ebx, ebx
  263.   .draw_text:
  264.  
  265. ; Prepare to actually draw some text
  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
  303.   .drawloop:
  304.         cmp     byte[edx], 0
  305.         je      .end_of_text
  306.  
  307. ; Clear one row of characters
  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]
  316.         mcall   13                              ; draw rectangle
  317.         popa
  318.  
  319.         push    eax
  320.         mov     esi, [textbox_width]
  321.   .line:
  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
  328.  
  329.         push    esi
  330.         cmp     byte[edx], 3                    ; escape code for mIRC colors
  331.         jne     .no_colors
  332.         inc     edx
  333.         call    dec_to_esi
  334.         jz      .no_colors
  335.         mov     ecx, [irc_colors + 4*esi]
  336.         or      ecx, 0x30000000
  337.  
  338.         cmp     byte[edx], ','                  ; background color?
  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
  345.   .no_colors:
  346.  
  347.         mov     esi, 1
  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.  
  365.         add     ebx, FONT_WIDTH shl 16
  366.         add     edx, esi
  367.         pop     esi
  368.         dec     esi
  369.         jnz     .line
  370.         jmp     .line_full
  371.  
  372.   .newline_hard:
  373.         mov     ecx, [colors.work_text]
  374.         or      ecx, 0x30000000
  375.   .newline_soft:
  376.         inc     edx
  377.   .line_full:
  378.         and     ebx, 0x0000ffff
  379.         add     ebx, TEXT_X shl 16 + FONT_HEIGHT
  380.         pop     eax
  381.         dec     eax
  382.         jnz     .drawloop
  383.   .end_of_text:
  384.  
  385.         ret
  386.  
  387.  
  388.  
  389.  
  390. dec_to_esi:
  391.  
  392.         xor     esi, esi
  393.   .loop:
  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
  403.   .done:
  404.         cmp     esi, 16
  405.         jae     .fail
  406.         ret
  407.  
  408.   .fail:
  409.         xor     esi, esi
  410.         ret
  411.  
  412.  
  413.  
  414. if TIMESTAMP
  415. print_timestamp:
  416.  
  417.         pusha
  418.         mcall   3                       ; get system time
  419.         mov     ebx, eax
  420.  
  421.         mov     al, '['
  422.         call    print_char
  423.         mov     ecx, TIMESTAMP
  424.   .loop:
  425.         mov     al, bl
  426.         shr     al, 4
  427.         add     al, '0'
  428.         call    print_char
  429.  
  430.         mov     al, bl
  431.         and     al, 0x0f
  432.         add     al, '0'
  433.         call    print_char
  434.  
  435.         dec     ecx
  436.         jz      .done
  437.  
  438.         mov     al, ':'
  439.         call    print_char
  440.         shr     ebx, 8
  441.         jmp     .loop
  442.   .done:
  443.         mov     al, ']'
  444.         call    print_char
  445.         mov     al, ' '
  446.         call    print_char
  447.  
  448.         popa
  449.         ret
  450. end if