Subversion Repositories Kolibri OS

Rev

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

  1. virtual at 0
  2. viewer_data:
  3.         .buf_start      dq      ?
  4.         .cur_pos        dq      ?
  5.         .filesize       dq      ?
  6.         .buf_pos        dd      ?
  7.         .buf_size       dd      ?
  8.         .col            dq      ?
  9.         .encoding       db      ?
  10.         .bEofReached    db      ?
  11.         .flags          db      ?       ; & 1: hex mode
  12.                                         ; & 2: unwrap
  13.                         rb      1
  14.         .filename       rb      1024
  15.         .buf            rb      16384
  16.         .size = $
  17. end virtual
  18.  
  19. view_file:
  20.         mov     eax, [ebp + panel1_files - panel1_data]
  21.         mov     ecx, [eax+ecx*4]
  22.         test    byte [ecx], 10h
  23.         jz      .file
  24.         ret
  25. .file:
  26.         lea     esi, [ebp + panel1_dir - panel1_data]
  27.         mov     eax, viewer_data.size
  28.         mov     edx, viewer_vtable
  29.         call    new_screen
  30.         test    eax, eax
  31.         jnz     @f
  32.         ret
  33. @@:
  34.         mov     [ebp+viewer_data.encoding], encodings.cp866
  35.         mov     [ebp+viewer_data.flags], 0
  36.         and     dword [ebp+viewer_data.col], 0
  37.         and     dword [ebp+viewer_data.col+4], 0
  38.         lea     edi, [ebp+viewer_data.filename]
  39.         push    edi
  40. @@:
  41.         lodsb
  42.         test    al, al
  43.         jz      @f
  44.         stosb
  45.         jmp     @b
  46. @@:
  47.         lea     esi, [ecx+40]
  48.         mov     al, '/'
  49.         stosb
  50. @@:
  51.         lodsb
  52.         stosb
  53.         test    al, al
  54.         jnz     @b
  55.         pop     eax
  56.         push    eax
  57.         mov     ebx, attrinfo
  58.         mov     [ebx+21], eax
  59. .attr_retry:
  60.         push    70
  61.         pop     eax
  62.         int     40h
  63.         test    eax, eax
  64.         jz      @f
  65.         lea     ebx, [ebp+viewer_data.filename]
  66.         push    ebx
  67.         push    aCannotReadFile
  68.         call    get_error_msg
  69.         push    eax
  70.         mov     eax, esp
  71.         push    RetryOrCancelBtn
  72.         push    2
  73.         push    eax
  74.         push    3
  75.         push    -1
  76.         push    -1
  77.         push    aError
  78.         call    SayErr
  79.         add     esp, 3*4
  80.         mov     ebx, attrinfo
  81.         test    eax, eax
  82.         jz      .attr_retry
  83.         jmp     delete_active_screen
  84. @@:
  85.         mov     eax, dword [attrinfo.attr+32]
  86.         mov     dword [ebp+viewer_data.filesize], eax
  87.         mov     eax, dword [attrinfo.attr+36]
  88.         mov     dword [ebp+viewer_data.filesize+4], eax
  89.         mov     ebx, readinfo
  90.         xor     eax, eax
  91.         mov     dword [ebx+readinfo.first-readinfo], eax
  92.         mov     dword [ebx+readinfo.first+4-readinfo], eax
  93.         mov     dword [ebp+viewer_data.buf_start], eax
  94.         mov     dword [ebp+viewer_data.buf_start+4], eax
  95.         mov     dword [ebp+viewer_data.cur_pos], eax
  96.         mov     dword [ebp+viewer_data.cur_pos+4], eax
  97.         mov     [ebx+readinfo.size-readinfo], 16384
  98.         lea     eax, [ebp+viewer_data.buf]
  99.         mov     [readinfo.data], eax
  100.         mov     [ebp+viewer_data.buf_pos], eax
  101.         pop     dword [readinfo.name]
  102. .retry:
  103.         push    70
  104.         pop     eax
  105.         int     40h
  106.         mov     [ebp+viewer_data.buf_size], ebx
  107.         test    eax, eax
  108.         jz      .readok
  109.         cmp     eax, 6
  110.         jz      .readok
  111.         lea     ebx, [ebp+viewer_data.filename]
  112.         push    ebx
  113.         push    aCannotReadFile
  114.         call    get_error_msg
  115.         push    eax
  116.         mov     eax, esp
  117.         push    RetryOrCancelBtn
  118.         push    2
  119.         push    eax
  120.         push    3
  121.         push    -1
  122.         push    -1
  123.         push    aError
  124.         call    SayErr
  125.         add     esp, 3*4
  126.         mov     ebx, readinfo
  127.         test    eax, eax
  128.         jz      .attr_retry
  129.         jmp     delete_active_screen
  130. .readok:
  131.         call    viewer_set_keybar
  132.         call    viewer_draw_text
  133.         ret
  134.  
  135. viewer_get_next_char:
  136.         pusha
  137.         mov     eax, [ebp+viewer_data.buf_pos]
  138.         lea     ecx, [ebp+viewer_data.buf]
  139.         add     ecx, [ebp+viewer_data.buf_size]
  140.         cmp     eax, ecx
  141.         jb      .buffered
  142.         mov     al, ' '
  143.         sub     ecx, ebp
  144.         cmp     ecx, viewer_data.buf + 16384
  145.         jb      .err
  146.         mov     eax, dword [ebp+viewer_data.buf_start]
  147.         add     eax, 8192
  148.         mov     dword [ebp+viewer_data.buf_start], eax
  149.         mov     edx, dword [ebp+viewer_data.buf_start+4]
  150.         adc     edx, 0
  151.         mov     dword [ebp+viewer_data.buf_start+4], edx
  152.         add     eax, 16384-8192
  153.         adc     edx, 0
  154.         mov     dword [readinfo.first], eax
  155.         mov     dword [readinfo.first+4], edx
  156.         mov     dword [readinfo.size], 8192
  157.         lea     edi, [ebp+viewer_data.buf]
  158.         lea     esi, [edi+8192]
  159.         mov     ecx, (16384-8192)/4
  160.         rep     movsd
  161.         mov     [readinfo.data], edi
  162.         lea     eax, [ebp+viewer_data.filename]
  163.         mov     [readinfo.name], eax
  164. .readretry:
  165.         mov     ebx, readinfo
  166.         push    70
  167.         pop     eax
  168.         int     40h
  169.         test    eax, eax
  170.         jz      .readok
  171.         cmp     eax, 6
  172.         jz      .readok
  173.         call    ask_retry_ignore
  174.         jz      .readretry
  175. .readok:
  176.         sub     [ebp+viewer_data.buf_pos], 8192
  177.         add     ebx, 16384-8192
  178.         mov     [ebp+viewer_data.buf_size], ebx
  179.         mov     eax, [ebp+viewer_data.buf_pos]
  180.         cmp     ecx, 16384-8192
  181.         jnz     .buffered
  182. .err:
  183.         stc
  184.         popa
  185.         ret
  186. .buffered:
  187.         mov     al, [eax]
  188. .done:
  189.         mov     [esp+28], al
  190.         inc     [ebp+viewer_data.buf_pos]
  191.         clc
  192.         popa
  193.         ret
  194.  
  195. viewer_get_prev_char:
  196.         pusha
  197.         lea     ecx, [ebp+viewer_data.buf]
  198.         cmp     [ebp+viewer_data.buf_pos], ecx
  199.         ja      .buffered
  200.         mov     eax, dword [ebp+viewer_data.buf_start]
  201.         mov     edx, dword [ebp+viewer_data.buf_start+4]
  202.         test    eax, eax
  203.         jnz     @f
  204.         test    edx, edx
  205.         jnz     @f
  206.         stc
  207.         jmp     .ret
  208. @@:
  209.         sub     eax, 8192
  210.         sbb     edx, 0
  211.         jnc     @f
  212.         xor     eax, eax
  213.         xor     edx, edx
  214. @@:
  215.         call    viewer_seek
  216.         add     [ebp+viewer_data.buf_pos], 8192
  217. .buffered:
  218.         mov     eax, [ebp+viewer_data.buf_pos]
  219.         dec     eax
  220.         mov     [ebp+viewer_data.buf_pos], eax
  221.         mov     al, [eax]
  222.         mov     [esp+28], al
  223.         clc
  224. .ret:
  225.         popa
  226.         ret
  227.  
  228. fld_uint64:
  229.         fild    qword [eax]
  230.         test    byte [eax+7], 80h
  231.         jz      .ret
  232.         fadd    [@f]
  233. .ret:
  234.         ret
  235. @@      dq      18446744073709551616.0 ;0x10000000000000000
  236.  
  237. viewer_draw_text:
  238.         call    viewer_seek_to_current
  239.         xor     eax, eax
  240.         xor     edx, edx
  241.         call    get_console_ptr
  242.         mov     ah, [view_status_color]
  243.         lea     esi, [ebp+viewer_data.filename]
  244.         mov     dl, 3
  245.         mov     ecx, [cur_width]
  246.         sub     ecx, 44
  247.         cmp     ecx, 20
  248.         jae     .5
  249.         mov     cl, 20
  250. .5:
  251.         lodsb
  252.         cmp     al, '/'
  253.         jnz     @f
  254.         dec     edx
  255.         jz      .6
  256. @@:
  257.         stosw
  258.         loop    .5
  259. .6:
  260.         dec     ecx
  261.         stosw
  262.         push    esi
  263. @@:
  264.         inc     esi
  265.         cmp     byte [esi-1], 0
  266.         jnz     @b
  267.         sub     esi, [esp]
  268.         dec     esi
  269.         cmp     ecx, esi
  270.         jae     .7
  271.         mov     al, '.'
  272.         stosw
  273.         stosw
  274.         stosw
  275.         sub     ecx, 3
  276.         sub     esi, ecx
  277.         add     [esp], esi
  278. .7:
  279.         pop     esi
  280. @@:
  281.         lodsb
  282.         test    al, al
  283.         jz      @f
  284.         dec     ecx
  285.         stosw
  286.         jmp     @b
  287. @@:
  288.         mov     al, ' '
  289.         add     ecx, 8
  290.         rep     stosw
  291.         movzx   esi, [ebp+viewer_data.encoding]
  292.         lea     esi, [encodings.names+esi*8]
  293.         mov     cl, 8
  294. @@:
  295.         lodsb
  296.         stosw
  297.         loop    @b
  298.         mov     al, ' '
  299.         mov     cl, 8
  300.         rep     stosw
  301.         std
  302.         push    edi
  303.         mov     edx, dword [ebp+viewer_data.filesize+4]
  304.         mov     eax, dword [ebp+viewer_data.filesize]
  305.         mov     cl, 10
  306. @@:
  307.         push    eax
  308.         mov     eax, edx
  309.         xor     edx, edx
  310.         div     ecx
  311.         xchg    eax, [esp]
  312.         div     ecx
  313.         xchg    eax, edx
  314.         add     al, '0'
  315.         mov     ah, [view_status_color]
  316.         stosw
  317.         xchg    eax, edx
  318.         pop     edx
  319.         test    eax, eax
  320.         jnz     @b
  321.         test    edx, edx
  322.         jnz     @b
  323.         mov     al, ' '
  324.         mov     ah, [view_status_color]
  325.         stosw
  326.         cld
  327.         pop     edi
  328.         inc     edi
  329.         inc     edi
  330.         mov     al, ' '
  331.         mov     cl, 5
  332.         rep     stosw
  333. if lang eq ru
  334.         mov     al, 'Š'
  335.         stosw
  336.         mov     al, '®'
  337.         stosw
  338.         mov     al, '«'
  339.         stosw
  340. else
  341.         mov     al, 'C'
  342.         stosw
  343.         mov     al, 'o'
  344.         stosw
  345.         mov     al, 'l'
  346.         stosw
  347. end if
  348.         mov     al, ' '
  349.         stosw
  350.         push    edi
  351.         mov     eax, dword [ebp+viewer_data.col]
  352.         mov     edx, dword [ebp+viewer_data.col+4]
  353.         test    edx, edx
  354.         jnz     .col_big
  355.         cmp     eax, 100000
  356.         jae     .col_big
  357.         mov     cl, 10
  358.         push    -'0'
  359. @@:
  360.         div     ecx
  361.         push    edx
  362.         xor     edx, edx
  363.         test    eax, eax
  364.         jnz     @b
  365. @@:
  366.         pop     eax
  367.         add     eax, '0'
  368.         jz      .col_done
  369.         mov     ah, [view_status_color]
  370.         stosw
  371.         jmp     @b
  372. .col_big:
  373.         push    eax
  374.         mov     al, '.'
  375.         mov     ah, [view_status_color]
  376.         stosw
  377.         stosw
  378.         stosw
  379.         xor     eax, eax
  380.         xchg    eax, edx
  381.         mov     cl, 100
  382.         div     ecx
  383.         pop     eax
  384.         div     ecx
  385.         mov     cl, 10
  386.         xor     eax, eax
  387.         xchg    eax, edx
  388.         div     ecx
  389.         add     al, '0'
  390.         mov     ah, [view_status_color]
  391.         stosw
  392.         mov     al, dl
  393.         add     al, '0'
  394.         stosw
  395. .col_done:
  396.         pop     ecx
  397.         add     ecx, 10*2
  398.         sub     ecx, edi
  399.         shr     ecx, 1
  400.         mov     al, ' '
  401.         mov     ah, [view_status_color]
  402.         rep     stosw
  403.         finit
  404.         fldcw   [fpu_cw]
  405.         mov     [tmp], 100
  406.         lea     eax, [ebp+viewer_data.filesize]
  407.         cmp     dword [eax], 0
  408.         jnz     @f
  409.         cmp     dword [eax+4], 0
  410.         jz      .size_zero
  411. @@:
  412.         call    fld_uint64
  413.         lea     eax, [ebp+viewer_data.cur_pos]
  414.         call    fld_uint64
  415.         fdivrp
  416.         fimul   [_100d]
  417.         fistp   [tmp]
  418. .size_zero:
  419.         mov     byte [edi-2], '%'
  420.         sub     edi, 4
  421.         mov     eax, [tmp]
  422.         mov     cl, 10
  423. @@:
  424.         xor     edx, edx
  425.         div     ecx
  426.         xchg    eax, edx
  427.         add     al, '0'
  428.         mov     [edi], al
  429.         sub     edi, 2
  430.         xchg    eax, edx
  431.         test    eax, eax
  432.         jnz     @b
  433.         xor     eax, eax
  434.         push    1
  435.         pop     edx
  436.         call    get_console_ptr
  437.         test    [ebp+viewer_data.flags], 1
  438.         jnz     .DrawHex
  439.         push    2
  440.         pop     edx
  441.         xor     ecx, ecx
  442.         mov     dword [scrpos], ecx
  443.         mov     dword [scrpos+4], ecx
  444.         mov     dword [viewer_right_side], ecx
  445.         mov     dword [viewer_right_side+4], ecx
  446. .1:
  447.         call    viewer_get_next_char
  448.         jc      .done
  449. .2:
  450.         cmp     al, 0xD
  451.         jz      .newline
  452.         cmp     al, 0xA
  453.         jz      .newline
  454.         cmp     ecx, [cur_width]
  455.         jb      .no_newline
  456.         test    [ebp+viewer_data.flags], 2
  457.         jnz     .no_newline
  458. .newline:
  459.         push    eax
  460.         mov     ecx, dword [scrpos]
  461.         mov     eax, dword [scrpos+4]
  462.         sub     ecx, dword [ebp+viewer_data.col]
  463.         sbb     eax, dword [ebp+viewer_data.col+4]
  464.         ja      .line_filled
  465.         jb      .line_full
  466.         cmp     ecx, [cur_width]
  467.         ja      .line_filled
  468.         jmp     @f
  469. .line_full:
  470.         xor     ecx, ecx
  471. @@:
  472.         test    ecx, ecx
  473.         jnz     @f
  474.         mov     eax, dword [scrpos]
  475.         or      eax, dword [scrpos+4]
  476.         jz      @f
  477.         inc     ecx
  478. @@:
  479.         sub     ecx, [cur_width]
  480.         neg     ecx
  481.         mov     al, ' '
  482.         mov     ah, [view_normal_color]
  483.         rep     stosw
  484. .line_filled:
  485.         mov     eax, dword [scrpos]
  486.         sub     eax, dword [viewer_right_side]
  487.         mov     eax, dword [scrpos+4]
  488.         sbb     eax, dword [viewer_right_side+4]
  489.         jb      @f
  490.         mov     eax, dword [scrpos]
  491.         mov     dword [viewer_right_side], eax
  492.         mov     eax, dword [scrpos+4]
  493.         mov     dword [viewer_right_side+4], eax
  494. @@:
  495.         xor     ecx, ecx
  496.         mov     dword [scrpos], ecx
  497.         mov     dword [scrpos+4], ecx
  498.         inc     edx
  499.         pop     eax
  500.         cmp     edx, [cur_height]
  501.         jae     .done
  502. .no_newline:
  503.         cmp     al, 0xD
  504.         jz      .3
  505.         cmp     al, 0xA
  506.         jz      .3
  507. .4:
  508.         test    al, al
  509.         jns     @f
  510.         movzx   esi, [ebp+viewer_data.encoding]
  511.         shl     esi, 7
  512.         movzx   eax, al
  513.         mov     al, [encodings.tables-80h+esi+eax]
  514. @@:
  515.         cmp     al, 9
  516.         jz      .tab
  517.         call    .write_char
  518.         inc     ecx
  519.         jns     .1
  520.         push    edx
  521.         mov     eax, ecx
  522.         xor     edx, edx
  523.         div     [tabsize]
  524.         mov     ecx, edx
  525.         pop     edx
  526.         jmp     .1
  527. .3:
  528.         mov     bl, al
  529.         call    viewer_get_next_char
  530.         jc      .done
  531.         xor     bl, al
  532.         cmp     bl, 0xA xor 0xD
  533.         jz      .1
  534.         jmp     .2
  535. .tab:
  536.         push    edx
  537.         push    ecx
  538.         mov     eax, ecx
  539.         mov     ecx, [tabsize]
  540.         xor     edx, edx
  541.         div     ecx
  542.         pop     eax
  543.         sub     ecx, edx
  544.         add     eax, ecx
  545.         test    [ebp+viewer_data.flags], 2
  546.         jnz     @f
  547.         cmp     eax, [cur_width]
  548.         jbe     @f
  549.         sub     eax, [cur_width]
  550.         sub     ecx, eax
  551.         mov     eax, [cur_width]
  552. @@:
  553.         push    eax
  554.         mov     al, ' '
  555. @@:
  556.         call    .write_char
  557.         loop    @b
  558.         pop     ecx
  559.         pop     edx
  560.         jmp     .1
  561. .done:
  562.         setc    [ebp+viewer_data.bEofReached]
  563. .done2:
  564.         inc     edx
  565.         cmp     edx, [cur_height]
  566.         jnc     @f
  567.         mov     eax, dword [ebp+viewer_data.cur_pos]
  568.         or      eax, dword [ebp+viewer_data.cur_pos+4]
  569.         jz      @f
  570.         call    viewer_seek_to_current
  571.         call    viewer_prev_newline
  572.         jmp     viewer_draw_text
  573. @@:
  574.         push    edi
  575.         xor     eax, eax
  576.         mov     edx, [cur_height]
  577.         dec     edx
  578.         call    get_console_ptr
  579.         mov     ecx, edi
  580.         pop     edi
  581.         sub     ecx, edi
  582.         shr     ecx, 1
  583.         mov     al, ' '
  584.         mov     ah, [view_normal_color]
  585.         rep     stosw
  586.         cmp     [ebp+viewer_data.bEofReached], 0
  587.         jz      @f
  588.         xor     edx, edx
  589.         mov     eax, [cur_width]
  590.         sub     eax, 4
  591.         call    get_console_ptr
  592.         mov     ah, [view_status_color]
  593.         mov     al, '1'
  594.         stosw
  595.         mov     al, '0'
  596.         stosw
  597.         stosw
  598. @@:
  599.         call    draw_image
  600.         ret
  601. .DrawHex:
  602.         xor     esi, esi
  603.         mov     [ebp+viewer_data.bEofReached], 0
  604. .line:
  605.         mov     al, ' '
  606.         mov     ah, [view_normal_color]
  607.         push    edi
  608.         mov     ecx, [cur_width]
  609.         rep     stosw
  610.         mov     ebx, edi
  611.         pop     edi
  612.         call    viewer_get_next_char
  613.         jc      .hexdone
  614.         push    eax
  615.         push    edi
  616.         add     edi, 36*2
  617.         mov     al, 0xB3
  618.         call    .safechar
  619.         pop     edi
  620.         mov     eax, dword [ebp+viewer_data.cur_pos]
  621.         mov     edx, dword [ebp+viewer_data.cur_pos+4]
  622.         push    esi
  623.         shl     esi, 4
  624.         add     eax, esi
  625.         adc     edx, 0
  626.         pop     esi
  627.         push    eax
  628.         mov     al, dl
  629.         shr     eax, 4
  630.         and     al, 0xF
  631.         call    .hex_digit
  632.         mov     al, dl
  633.         and     al, 0xF
  634.         call    .hex_digit
  635.         pop     eax
  636.         push    8
  637.         pop     ecx
  638.         add     edi, 7*2
  639.         std
  640. @@:
  641.         push    eax
  642.         and     al, 0xF
  643.         call    .hex_digit
  644.         pop     eax
  645.         shr     eax, 4
  646.         loop    @b
  647.         cld
  648.         add     edi, 9*2
  649.         mov     al, ':'
  650.         mov     ah, [view_normal_color]
  651.         stosw
  652.         mov     al, ' '
  653.         stosw
  654.         xor     ecx, ecx
  655.         pop     eax
  656.         jmp     @f
  657. .hexchar:
  658.         call    viewer_get_next_char
  659.         jc      .hexdone
  660. @@:
  661.         push    eax
  662.         shr     al, 4
  663.         call    .hex_digit
  664.         pop     eax
  665.         push    eax
  666.         and     al, 0xF
  667.         call    .hex_digit
  668.         mov     al, ' '
  669.         call    .safechar
  670.         pop     eax
  671.         push    edi
  672.         add     edi, 48*2
  673.         push    ecx
  674.         shl     ecx, 2
  675.         sub     edi, ecx
  676.         pop     ecx
  677.         cmp     ecx, 8
  678.         jb      @f
  679.         sub     edi, 4
  680. @@:
  681.         test    al, al
  682.         jns     @f
  683.         movzx   edx, [ebp+viewer_data.encoding]
  684.         shl     edx, 7
  685.         movzx   eax, al
  686.         mov     al, [encodings.tables+eax+edx-80h]
  687.         mov     ah, [view_normal_color]
  688. @@:
  689.         call    .safechar
  690.         pop     edi
  691.         inc     ecx
  692.         cmp     ecx, 8
  693.         jnz     @f
  694.         mov     al, 0xB3
  695.         call    .safechar
  696.         mov     al, ' '
  697.         call    .safechar
  698. @@:
  699.         cmp     ecx, 16
  700.         jnz     .hexchar
  701.         mov     edi, ebx
  702.         add     esi, 3
  703.         mov     edx, esi
  704.         cmp     esi, [cur_height]
  705.         jae     .done2
  706.         dec     esi
  707.         dec     esi
  708.         jmp     .line
  709. .hexdone:
  710.         mov     [ebp+viewer_data.bEofReached], 1
  711.         mov     edi, ebx
  712.         lea     edx, [esi+2]
  713.         jmp     .done2
  714.  
  715. .hex_digit:
  716.         push    eax
  717.         cmp     al, 10
  718.         sbb     al, 69h
  719.         das
  720.         mov     ah, [view_normal_color]
  721.         call    .safechar
  722.         pop     eax
  723.         ret
  724. .safechar:
  725.         cmp     edi, ebx
  726.         jae     @f
  727.         stosw
  728. @@:
  729.         ret
  730. .write_char:
  731.         push    ecx eax
  732.         mov     ecx, dword [scrpos]
  733.         mov     eax, dword [scrpos+4]
  734.         sub     ecx, dword [ebp+viewer_data.col]
  735.         sbb     eax, dword [ebp+viewer_data.col+4]
  736.         jb      .left
  737.         ja      .skip
  738.         test    ecx, ecx
  739.         jnz     @f
  740.         mov     eax, dword [scrpos]
  741.         or      eax, dword [scrpos+4]
  742.         jnz     .skip
  743. @@:
  744.         cmp     ecx, [cur_width]
  745.         ja      .skip
  746.         jb      .do
  747.         mov     al, '>'
  748.         mov     [edi-2], al
  749.         mov     al, [view_arrows_color]
  750.         mov     [edi-1], al
  751.         jmp     .skip
  752. .left:
  753.         mov     eax, dword [scrpos]
  754.         or      eax, dword [scrpos+4]
  755.         jnz     .skip
  756.         mov     al, '<'
  757.         mov     ah, [view_arrows_color]
  758.         stosw
  759.         jmp     .skip
  760. .do:
  761.         mov     al, [esp]
  762.         mov     ah, [view_normal_color]
  763.         stosw
  764. .skip:
  765.         pop     eax ecx
  766.         add     dword [scrpos], 1
  767.         adc     dword [scrpos+4], 0
  768.         ret
  769.  
  770. viewer_seek_to_current:
  771.         mov     eax, dword [ebp+viewer_data.cur_pos]
  772.         mov     edx, dword [ebp+viewer_data.cur_pos+4]
  773. viewer_seek:
  774.         push    eax edx
  775.         sub     eax, dword [ebp+viewer_data.buf_start]
  776.         sbb     edx, dword [ebp+viewer_data.buf_start+4]
  777.         jb      .prev
  778.         ja      .next
  779.         cmp     eax, 16384
  780.         jae     .next
  781.         lea     eax, [ebp+viewer_data.buf+eax]
  782.         mov     [ebp+viewer_data.buf_pos], eax
  783.         pop     edx eax
  784.         ret
  785. .prev:
  786.         inc     edx
  787.         jnz     .read_full
  788.         and     eax, not 511
  789.         cmp     eax, -16384
  790.         jbe     .read_full
  791.         lea     edi, [ebp+viewer_data.buf+16384-4]
  792.         lea     esi, [edi+eax]
  793.         lea     ecx, [eax+16384]
  794.         push    ecx
  795.         shr     ecx, 2
  796.         std
  797.         rep     movsd
  798.         cld
  799.         pop     ecx
  800.         add     dword [ebp+viewer_data.buf_start], eax
  801.         adc     dword [ebp+viewer_data.buf_start+4], -1
  802.         neg     eax
  803.         cmp     dword [ebp+viewer_data.buf_size], ecx
  804.         jb      .doread
  805.         mov     dword [ebp+viewer_data.buf_size], ecx
  806.         jmp     .doread
  807. .read_full:
  808.         pop     edx eax
  809.         push    eax edx
  810.         and     eax, not 511
  811.         sub     eax, 8192-512
  812.         sbb     edx, 0
  813.         jnc     @f
  814.         xor     eax, eax
  815.         xor     edx, edx
  816. @@:
  817.         mov     dword [ebp+viewer_data.buf_start], eax
  818.         mov     dword [ebp+viewer_data.buf_start+4], edx
  819.         and     dword [ebp+viewer_data.buf_size], 0
  820.         mov     eax, 16384
  821. .doread:
  822.         mov     ebx, readinfo
  823.         push    dword [ebp+viewer_data.buf_start]
  824.         pop     dword [ebx+4]
  825.         push    dword [ebp+viewer_data.buf_start+4]
  826.         pop     dword [ebx+8]
  827.         mov     [ebx+12], eax
  828.         lea     eax, [ebp+viewer_data.buf]
  829.         mov     [ebx+16], eax
  830.         lea     eax, [ebp+viewer_data.filename]
  831.         mov     [ebx+21], eax
  832.         push    70
  833.         pop     eax
  834.         int     40h
  835.         test    eax, eax
  836.         jz      .readok
  837.         cmp     eax, 6
  838.         jz      .readok
  839.         call    ask_retry_ignore
  840.         jz      .doread
  841. .readok:
  842.         cmp     ebx, [readinfo.size]
  843.         jnz     @f
  844.         add     ebx, [ebp+viewer_data.buf_size]
  845. @@:
  846. .ret:
  847.         mov     [ebp+viewer_data.buf_size], ebx
  848.         pop     edx eax
  849.         sub     eax, dword [ebp+viewer_data.buf_start]
  850.         lea     eax, [ebp+eax+viewer_data.buf]
  851.         mov     [ebp+viewer_data.buf_pos], eax
  852.         ret
  853. .next:
  854.         or      eax, 511
  855.         sub     eax, 16384-1
  856.         sbb     edx, 0
  857.         jnz     .read_full
  858.         cmp     eax, 16384
  859.         jae     .read_full
  860.         cmp     [ebp+viewer_data.buf_size], 16384
  861.         jb      .read_full
  862.         lea     edi, [ebp+viewer_data.buf]
  863.         lea     esi, [edi+eax]
  864.         mov     ecx, 16384
  865.         sub     ecx, eax
  866.         shr     ecx, 2
  867.         rep     movsd
  868.         add     dword [ebp+viewer_data.buf_start], eax
  869.         adc     dword [ebp+viewer_data.buf_start+4], 0
  870.         mov     ebx, readinfo
  871.         mov     [ebx+16], edi
  872.         sub     edi, ebp
  873.         sub     edi, viewer_data.buf
  874.         mov     edx, dword [ebp+viewer_data.buf_start]
  875.         add     edx, edi
  876.         mov     [ebx+4], edx
  877.         mov     edx, dword [ebp+viewer_data.buf_start+4]
  878.         adc     edx, 0
  879.         mov     [ebx+8], edx
  880.         mov     [ebx+12], eax
  881.         lea     eax, [ebp+viewer_data.filename]
  882.         mov     [ebx+21], eax
  883. @@:
  884.         push    70
  885.         pop     eax
  886.         int     40h
  887.         test    eax, eax
  888.         jz      @f
  889.         cmp     eax, 6
  890.         jz      @f
  891.         call    ask_retry_ignore
  892.         jnz     @f
  893.         mov     ebx, readinfo
  894.         jmp     @b
  895. @@:
  896.         sub     ebx, [readinfo.size]
  897.         add     ebx, 16384
  898.         jmp     .ret
  899.  
  900. ask_retry_ignore:
  901.         push    esi
  902.         lea     esi, [ebp+viewer_data.filename]
  903.         push    esi
  904.         push    aCannotReadFile
  905.         call    get_error_msg
  906.         push    eax
  907.         mov     eax, esp
  908.         push    RetryOrIgnoreBtn
  909.         push    2
  910.         push    eax
  911.         push    3
  912.         push    -1
  913.         push    -1
  914.         push    aError
  915.         call    SayErr
  916.         add     esp, 3*4
  917.         pop     esi
  918.         test    eax, eax
  919.         ret
  920.  
  921. viewer_set_curpos:
  922.         mov     eax, [ebp+viewer_data.buf_pos]
  923.         sub     eax, ebp
  924.         sub     eax, viewer_data.buf
  925.         xor     edx, edx
  926.         add     eax, dword [ebp+viewer_data.buf_start]
  927.         adc     edx, dword [ebp+viewer_data.buf_start+4]
  928.         mov     dword [ebp+viewer_data.cur_pos], eax
  929.         mov     dword [ebp+viewer_data.cur_pos+4], edx
  930.         ret
  931.  
  932. viewer_next_newline:
  933.         test    [ebp+viewer_data.flags], 1
  934.         jz      .nohex
  935.         push    10h
  936.         pop     ecx
  937. @@:
  938.         call    viewer_get_next_char
  939.         jc      @f
  940.         loop    @b
  941.         call    viewer_set_curpos
  942.         clc
  943. @@:     ret
  944. .nohex:
  945.         xor     ecx, ecx
  946. @@:
  947.         call    viewer_get_next_char
  948.         jc      .ret
  949.         cmp     al, 0xD
  950.         jz      .1
  951.         cmp     al, 0xA
  952.         jz      .1
  953.         cmp     al, 9
  954.         jz      .tab
  955.         inc     ecx
  956. .next:
  957.         test    [ebp+viewer_data.flags], 2
  958.         jnz     @b
  959.         cmp     ecx, [cur_width]
  960.         jbe     @b
  961.         call    viewer_get_prev_char
  962.         jmp     .2
  963. .tab:
  964.         push    ecx
  965.         mov     eax, ecx
  966.         mov     ecx, [tabsize]
  967.         xor     edx, edx
  968.         div     ecx
  969.         sub     ecx, edx
  970.         add     [esp], ecx
  971.         pop     ecx
  972.         jmp     .next
  973. .1:
  974.         mov     cl, al
  975.         call    viewer_get_next_char
  976.         jc      .ret
  977.         xor     cl, al
  978.         cmp     cl, 0xD xor 0xA
  979.         jz      .2
  980.         dec     [ebp+viewer_data.buf_pos]
  981. .2:
  982. .ret:
  983.         call    viewer_set_curpos
  984.         ret
  985.  
  986. viewer_prev_newline:
  987.         test    [ebp+viewer_data.flags], 1
  988.         jz      .nohex
  989.         push    10h
  990.         pop     ecx
  991. @@:
  992.         call    viewer_get_prev_char
  993.         jc      @f
  994.         loop    @b
  995. @@:     call    viewer_set_curpos
  996.         ret
  997. .nohex:
  998.         mov     eax, 8192
  999.         push    eax
  1000.         cdq
  1001.         div     [cur_width]
  1002.         pop     eax
  1003.         sub     eax, edx
  1004.         mov     edx, eax
  1005.         call    viewer_get_prev_char
  1006.         jc      .0
  1007.         dec     edx
  1008.         cmp     al, 0xD
  1009.         jz      .2
  1010.         cmp     al, 0xA
  1011.         jnz     .3
  1012. .2:
  1013.         mov     cl, al
  1014.         call    viewer_get_prev_char
  1015.         jc      .0
  1016.         dec     edx
  1017.         xor     cl, al
  1018.         cmp     cl, 0xD xor 0xA
  1019.         jnz     .3
  1020. @@:
  1021.         call    viewer_get_prev_char
  1022.         jc      .0
  1023.         dec     edx
  1024.         jz      .0
  1025. .3:
  1026.         cmp     al, 0xD
  1027.         jz      .1
  1028.         cmp     al, 0xA
  1029.         jnz     @b
  1030. .1:
  1031.         call    viewer_get_next_char
  1032. .0:
  1033.         push    dword [ebp+viewer_data.cur_pos+4]
  1034.         push    dword [ebp+viewer_data.cur_pos]
  1035.         call    viewer_set_curpos
  1036. @@:
  1037.         push    dword [ebp+viewer_data.cur_pos+4]
  1038.         push    dword [ebp+viewer_data.cur_pos]
  1039.         call    viewer_next_newline
  1040.         jc      .ret3
  1041.         mov     eax, dword [ebp+viewer_data.cur_pos]
  1042.         mov     edx, dword [ebp+viewer_data.cur_pos+4]
  1043.         sub     eax, [esp+8]
  1044.         sbb     edx, [esp+12]
  1045.         jae     .ret3
  1046.         pop     eax
  1047.         pop     eax
  1048.         jmp     @b
  1049. .ret3:
  1050.         pop     dword [ebp+viewer_data.cur_pos]
  1051.         pop     dword [ebp+viewer_data.cur_pos+4]
  1052. .ret:
  1053.         pop     eax
  1054.         pop     eax
  1055.         jmp     viewer_seek_to_current
  1056.  
  1057. viewer_set_keybar:
  1058.         mov     eax, keybar_viewer
  1059. if lang eq ru
  1060.         test    [ebp+viewer_data.flags], 1
  1061.         jnz     .hex
  1062.         mov     dword [eax+(4-1)*6], 'Š®¤ '
  1063.         mov     word [eax+(4-1)*6+4], '  '
  1064.         jmp     @f
  1065. .hex:
  1066.         mov     dword [eax+(4-1)*6], '’¥ªá'
  1067.         mov     word [eax+(4-1)*6+4], 'â '
  1068. @@:
  1069.         test    [ebp+viewer_data.flags], 2
  1070.         jnz     .unwrap
  1071.         mov     dword [eax+6], ' §¢'
  1072.         mov     word [eax+6+4], '¥à'
  1073.         jmp     @f
  1074. .unwrap:
  1075.         mov     dword [eax+6], '‘¢¥à'
  1076.         mov     word [eax+6+4], '­ '
  1077. @@:
  1078. else
  1079.         test    [ebp+viewer_data.flags], 1
  1080.         jnz     .hex
  1081.         mov     dword [eax+(4-1)*6], 'Hex '
  1082. ;        mov     word [eax+(4-1)*6+4], '  '
  1083.         jmp     @f
  1084. .hex:
  1085.         mov     dword [eax+(4-1)*6], 'Text'
  1086. ;        mov     word [eax+(4-1)*6+4], '  '
  1087. @@:
  1088.         test    [ebp+viewer_data.flags], 2
  1089.         jnz     .unwrap
  1090.         mov     dword [eax+6], 'Unwr'
  1091.         mov     word [eax+6+4], 'ap'
  1092.         jmp     @f
  1093. .unwrap:
  1094.         mov     dword [eax+6], 'Wrap'
  1095.         mov     word [eax+6+4], '  '
  1096. @@:
  1097. end if
  1098.         movzx   esi, [ebp+viewer_data.encoding]
  1099.         xor     esi, 1
  1100.         lea     esi, [encodings.names+esi*8]
  1101.         lea     edi, [eax+keybar_cp-keybar_viewer]
  1102.         movsd
  1103.         movsw
  1104.         jmp     draw_keybar
  1105.  
  1106. viewer_OnRedraw:
  1107.         call    viewer_set_keybar
  1108.         call    viewer_draw_text
  1109.         ret
  1110.  
  1111. viewer_OnKey:
  1112.         mov     esi, viewer_ctrlkeys
  1113.         jmp     process_ctrl_keys
  1114. .exit:
  1115.         call    delete_active_screen
  1116.         ret
  1117. .down:
  1118.         cmp     [ebp+viewer_data.bEofReached], 0
  1119.         jnz     .ret
  1120.         call    viewer_seek_to_current
  1121.         call    viewer_next_newline
  1122.         jc      .ret
  1123.         call    viewer_draw_text
  1124.         ret
  1125. .pgdn:
  1126.         cmp     [ebp+viewer_data.bEofReached], 0
  1127.         jnz     .ret
  1128.         call    viewer_seek_to_current
  1129.         mov     ebx, [cur_height]
  1130.         sub     ebx, 3
  1131. @@:
  1132.         call    viewer_next_newline
  1133.         jc      .ret
  1134.         dec     ebx
  1135.         jnz     @b
  1136.         call    viewer_draw_text
  1137.         ret
  1138. .up:
  1139.         call    viewer_seek_to_current
  1140.         call    viewer_prev_newline
  1141.         call    viewer_draw_text
  1142.         ret
  1143. .pgup:
  1144.         call    viewer_seek_to_current
  1145.         mov     ebx, [cur_height]
  1146.         sub     ebx, 3
  1147. @@:
  1148.         call    viewer_prev_newline
  1149.         dec     ebx
  1150.         jnz     @b
  1151. .done_redraw:
  1152.         call    viewer_draw_text
  1153. .ret:
  1154.         ret
  1155. .f8:
  1156.         movzx   esi, [ebp+viewer_data.encoding]
  1157.         xor     [ebp+viewer_data.encoding], 1
  1158.         call    viewer_set_keybar
  1159.         jmp     .done_redraw
  1160. .f2:
  1161.         xor     [ebp+viewer_data.flags], 2
  1162.         call    viewer_set_keybar
  1163.         jmp     .done_redraw
  1164. .f4:
  1165.         xor     [ebp+viewer_data.flags], 1
  1166.         pushf
  1167.         call    viewer_set_keybar
  1168.         popf
  1169.         jnz     .tohex
  1170.         add     dword [ebp+viewer_data.cur_pos], 1
  1171.         adc     dword [ebp+viewer_data.cur_pos+4], 0
  1172.         call    viewer_seek_to_current
  1173.         call    viewer_prev_newline
  1174.         jmp     .done_redraw
  1175. .tohex:
  1176.         and     byte [ebp+viewer_data.cur_pos], 0xF0
  1177.         jmp     .done_redraw
  1178. .home:
  1179.         xor     eax, eax
  1180.         mov     dword [ebp+viewer_data.cur_pos], eax
  1181.         mov     dword [ebp+viewer_data.cur_pos+4], eax
  1182.         mov     dword [ebp+viewer_data.col], eax
  1183.         mov     dword [ebp+viewer_data.col+4], eax
  1184.         jmp     .done_redraw
  1185. .end:
  1186.         mov     eax, dword [ebp+viewer_data.filesize]
  1187.         mov     edx, dword [ebp+viewer_data.filesize+4]
  1188.         and     al, 0xF0
  1189.         mov     dword [ebp+viewer_data.cur_pos], eax
  1190.         mov     dword [ebp+viewer_data.cur_pos+4], edx
  1191.         and     dword [ebp+viewer_data.col], 0
  1192.         and     dword [ebp+viewer_data.col+4], 0
  1193.         jmp     .done_redraw
  1194. .right:
  1195.         add     dword [ebp+viewer_data.col], 1
  1196.         adc     dword [ebp+viewer_data.col+4], 0
  1197.         jnc     .done_redraw
  1198.         sub     dword [ebp+viewer_data.col], 1
  1199.         sbb     dword [ebp+viewer_data.col+4], 0
  1200.         ret
  1201. .left:
  1202.         sub     dword [ebp+viewer_data.col], 1
  1203.         sbb     dword [ebp+viewer_data.col+4], 0
  1204.         jnc     .done_redraw
  1205.         add     dword [ebp+viewer_data.col], 1
  1206.         adc     dword [ebp+viewer_data.col+4], 0
  1207.         ret
  1208. .ctrl_left:
  1209.         test    [ebp+viewer_data.flags], 1
  1210.         jnz     .ctrl_left_hex
  1211.         sub     dword [ebp+viewer_data.col], 20
  1212.         sbb     dword [ebp+viewer_data.col+4], 0
  1213.         jnc     .done_redraw
  1214. .ctrl_shift_left:
  1215.         and     dword [ebp+viewer_data.col], 0
  1216.         and     dword [ebp+viewer_data.col+4], 0
  1217.         jmp     .done_redraw
  1218. .ctrl_left_hex:
  1219.         call    viewer_seek_to_current
  1220.         call    viewer_get_prev_char
  1221.         jc      @f
  1222.         call    viewer_set_curpos
  1223.         jmp     .done_redraw
  1224. .ctrl_right:
  1225.         test    [ebp+viewer_data.flags], 1
  1226.         jnz     .ctrl_right_hex
  1227.         add     dword [ebp+viewer_data.col], 20
  1228.         adc     dword [ebp+viewer_data.col+4], 0
  1229.         jnc     .done_redraw
  1230.         sub     dword [ebp+viewer_data.col], 20
  1231.         sbb     dword [ebp+viewer_data.col+4], 0
  1232. @@:     ret
  1233. .ctrl_right_hex:
  1234.         call    viewer_seek_to_current
  1235.         call    viewer_get_next_char
  1236.         call    viewer_set_curpos
  1237.         jmp     .done_redraw
  1238. .ctrl_shift_right:
  1239.         test    [ebp+viewer_data.flags], 1
  1240.         jnz     @b
  1241.         mov     eax, dword [viewer_right_side]
  1242.         mov     edx, dword [viewer_right_side+4]
  1243.         sub     eax, [cur_width]
  1244.         sbb     edx, 0
  1245.         jnc     @f
  1246.         xor     eax, eax
  1247.         xor     edx, edx
  1248. @@:
  1249.         mov     dword [ebp+viewer_data.col], eax
  1250.         mov     dword [ebp+viewer_data.col+4], edx
  1251.         jmp     .done_redraw
  1252.  
  1253. viewer_getname:
  1254. if lang eq ru
  1255.         mov     eax, 'à®á'
  1256.         stosd
  1257.         mov     eax, '¬®âà'
  1258.         stosd
  1259.         mov     eax, '    '
  1260.         stosd
  1261.         stosb
  1262. else
  1263.         mov     eax, 'View'
  1264.         stosd
  1265.         mov     eax, '    '
  1266.         stosd
  1267.         stosd
  1268.         stosb
  1269. end if
  1270.         sub     ecx, 13
  1271.         lea     esi, [ebp+viewer_data.filename]
  1272.         push    3
  1273.         pop     edx
  1274. @@:
  1275.         lodsb
  1276.         stosb
  1277.         dec     ecx
  1278.         cmp     al, '/'
  1279.         jnz     @b
  1280.         dec     edx
  1281.         jnz     @b
  1282.         push    esi
  1283. @@:
  1284.         lodsb
  1285.         test    al, al
  1286.         jnz     @b
  1287.         sub     esi, [esp]
  1288.         dec     esi
  1289.         cmp     esi, ecx
  1290.         jbe     @f
  1291.         mov     al, '.'
  1292.         stosb
  1293.         stosb
  1294.         stosb
  1295.         sub     ecx, 3
  1296.         sub     esi, ecx
  1297.         add     [esp], esi
  1298. @@:
  1299.         pop     esi
  1300. @@:
  1301.         lodsb
  1302.         stosb
  1303.         test    al, al
  1304.         jnz     @b
  1305.         ret
  1306.