Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
180 heavyiron 1
virtual at 0
2
viewer_data:
814 diamond 3
        .hPlugin        dd      ?
4
        .hFile          dd      ?
180 heavyiron 5
        .buf_start      dq      ?
6
        .cur_pos        dq      ?
7
        .filesize       dq      ?
8
        .buf_pos        dd      ?
9
        .buf_size       dd      ?
10
        .col            dq      ?
589 diamond 11
        .hWorkFile      dd      ?
180 heavyiron 12
        .encoding       db      ?
13
        .flags          db      ?       ; & 1: hex mode
14
                                        ; & 2: unwrap
474 diamond 15
                                        ; & 4: big-endian unicode
814 diamond 16
        .bEofReached    db      ?
180 heavyiron 17
                        rb      1
814 diamond 18
        align 200h
180 heavyiron 19
        .filename       rb      1024
589 diamond 20
        .hostname       rb      1024
180 heavyiron 21
        .buf            rb      16384
22
        .size = $
23
end virtual
24
 
25
view_file:
26
        mov     eax, [ebp + panel1_files - panel1_data]
27
        mov     ecx, [eax+ecx*4]
28
        test    byte [ecx], 10h
29
        jz      .file
30
        ret
31
.file:
32
        lea     esi, [ebp + panel1_dir - panel1_data]
474 diamond 33
        push    ecx
34
        mov     ecx, viewer_data.size
180 heavyiron 35
        mov     edx, viewer_vtable
36
        call    new_screen
474 diamond 37
        pop     ecx
180 heavyiron 38
        test    eax, eax
39
        jnz     @f
40
        ret
41
@@:
589 diamond 42
        mov     eax, dword [esi+panel1_hPlugin-panel1_dir]
43
        mov     [ebp+viewer_data.hPlugin], eax
44
        test    eax, eax
45
        jz      .nocopyhostname
46
        lea     edi, [ebp+viewer_data.hostname]
47
        push    esi
48
        mov     eax, dword [esi+panel1_parents-panel1_dir]
49
        mov     esi, dword [esi+panel1_parents_sz-panel1_dir]
50
        add     esi, eax
51
@@:
52
        dec     esi
53
        cmp     byte [esi-1], 0
54
        jz      @f
55
        cmp     byte [esi-1], '/'
56
        jnz     @b
57
@@:
58
        lodsb
59
        stosb
60
        test    al, al
61
        jnz     @b
62
        pop     esi
63
.nocopyhostname:
64
        mov     eax, dword [esi+panel1_hFile-panel1_dir]
65
        mov     [ebp+viewer_data.hFile], eax
180 heavyiron 66
        mov     [ebp+viewer_data.encoding], encodings.cp866
67
        mov     [ebp+viewer_data.flags], 0
68
        and     dword [ebp+viewer_data.col], 0
69
        and     dword [ebp+viewer_data.col+4], 0
70
        lea     edi, [ebp+viewer_data.filename]
71
        push    edi
72
@@:
73
        lodsb
74
        test    al, al
75
        jz      @f
76
        stosb
77
        jmp     @b
78
@@:
79
        lea     esi, [ecx+40]
589 diamond 80
        cmp     byte [edi-1], '/'
81
        jz      @f
180 heavyiron 82
        mov     al, '/'
83
        stosb
84
@@:
85
        lodsb
86
        stosb
87
        test    al, al
88
        jnz     @b
89
        pop     eax
90
        push    eax
91
        mov     ebx, attrinfo
92
        mov     [ebx+21], eax
321 diamond 93
.attr_retry:
589 diamond 94
        mov     edx, [ebp+viewer_data.hPlugin]
95
        test    edx, edx
96
        jz      .attr_native
97
        push    ebp
98
        push    dword [ebx+16]
99
        push    eax
100
        push    [ebp+viewer_data.hFile]
101
        call    [edx+PluginInfo.getattr]
102
        pop     ebp
103
        jmp     .attr_common
104
.attr_native:
180 heavyiron 105
        push    70
106
        pop     eax
517 diamond 107
        int     40h
589 diamond 108
.attr_common:
321 diamond 109
        test    eax, eax
110
        jz      @f
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
        call    SayErr
122
        add     esp, 3*4
123
        mov     ebx, attrinfo
124
        test    eax, eax
125
        jz      .attr_retry
589 diamond 126
        pop     eax
321 diamond 127
        jmp     delete_active_screen
128
@@:
180 heavyiron 129
        mov     eax, dword [attrinfo.attr+32]
130
        mov     dword [ebp+viewer_data.filesize], eax
131
        mov     eax, dword [attrinfo.attr+36]
132
        mov     dword [ebp+viewer_data.filesize+4], eax
133
        mov     ebx, readinfo
134
        xor     eax, eax
135
        mov     dword [ebx+readinfo.first-readinfo], eax
136
        mov     dword [ebx+readinfo.first+4-readinfo], eax
137
        mov     dword [ebp+viewer_data.buf_start], eax
138
        mov     dword [ebp+viewer_data.buf_start+4], eax
139
        mov     dword [ebp+viewer_data.cur_pos], eax
140
        mov     dword [ebp+viewer_data.cur_pos+4], eax
141
        mov     [ebx+readinfo.size-readinfo], 16384
142
        lea     eax, [ebp+viewer_data.buf]
143
        mov     [readinfo.data], eax
144
        mov     [ebp+viewer_data.buf_pos], eax
145
        pop     dword [readinfo.name]
589 diamond 146
        mov     eax, [ebp+viewer_data.hPlugin]
147
        test    eax, eax
148
        jz      .retry
149
        push    ebx ebp
150
        push    O_READ
151
        push    dword [readinfo.name]
152
        push    [ebp+viewer_data.hFile]
153
        call    [eax+PluginInfo.open]
154
        pop     ebp ebx
155
        mov     [ebp+viewer_data.hWorkFile], eax
156
        test    eax, eax
157
        jnz     .retry
814 diamond 158
..openerr_in_screen:
589 diamond 159
        push    ContinueBtn
160
        push    1
161
        push    aCannotOpenFile_ptr
162
        push    1
163
        call    SayErr
164
        jmp     delete_active_screen
321 diamond 165
.retry:
589 diamond 166
        mov     eax, [ebp+viewer_data.hPlugin]
167
        test    eax, eax
168
        jz      .read_native
169
        push    ebp
170
        push    16384
171
        push    [ebx+readinfo.data-readinfo]
172
        push    [ebp+viewer_data.hWorkFile]
173
        call    [eax+PluginInfo.read]
174
        pop     ebp
175
        cmp     eax, -1
176
        jz      .readok         ; let's hope that plugin says error itself
177
        mov     [ebp+viewer_data.buf_size], eax
178
        mov     ebx, eax
179
        jmp     .readok
180
.read_native:
180 heavyiron 181
        push    70
182
        pop     eax
517 diamond 183
        int     40h
180 heavyiron 184
        mov     [ebp+viewer_data.buf_size], ebx
321 diamond 185
        test    eax, eax
186
        jz      .readok
187
        cmp     eax, 6
188
        jz      .readok
589 diamond 189
.readerr:
321 diamond 190
        lea     ebx, [ebp+viewer_data.filename]
191
        push    ebx
192
        push    aCannotReadFile
193
        call    get_error_msg
194
        push    eax
195
        mov     eax, esp
196
        push    RetryOrCancelBtn
197
        push    2
198
        push    eax
199
        push    3
200
        call    SayErr
201
        add     esp, 3*4
202
        mov     ebx, readinfo
203
        test    eax, eax
204
        jz      .attr_retry
205
        jmp     delete_active_screen
206
.readok:
474 diamond 207
        cmp     ebx, 2
208
        jb      .nounicode
209
        cmp     word [ebp+viewer_data.buf], 0xFEFF
210
        jz      @f
211
        cmp     word [ebp+viewer_data.buf], 0xFFFE
212
        jnz     .nounicode
213
        or      byte [ebp+viewer_data.flags], 4
214
@@:
215
        mov     [ebp+viewer_data.encoding], encodings.unicode
216
.nounicode:
814 diamond 217
viewer_OnRedraw:
218
        or      [cursor_x], -1
219
        or      [cursor_y], -1
180 heavyiron 220
        call    viewer_set_keybar
221
        call    viewer_draw_text
222
        ret
223
 
224
viewer_get_next_char:
225
        pusha
474 diamond 226
        cmp     [ebp+viewer_data.encoding], encodings.unicode
227
        jnz     @f
228
        cmp     [bForHex], 0
229
        jnz     @f
230
        cmp     dword [ebp+viewer_data.buf_start], 0
231
        jnz     @f
232
        cmp     dword [ebp+viewer_data.buf_start+4], 0
233
        jnz     @f
234
        lea     eax, [ebp+viewer_data.buf]
235
        cmp     eax, [ebp+viewer_data.buf_pos]
236
        jnz     @f
237
        cmp     word [eax], 0xFFFE
238
        jz      .skip
239
        cmp     word [eax], 0xFEFF
240
        jnz     @f
241
.skip:
242
        add     [ebp+viewer_data.buf_pos], 2
243
@@:
180 heavyiron 244
        mov     eax, [ebp+viewer_data.buf_pos]
245
        lea     ecx, [ebp+viewer_data.buf]
246
        add     ecx, [ebp+viewer_data.buf_size]
247
        cmp     eax, ecx
248
        jb      .buffered
249
        mov     al, ' '
250
        sub     ecx, ebp
251
        cmp     ecx, viewer_data.buf + 16384
252
        jb      .err
253
        mov     eax, dword [ebp+viewer_data.buf_start]
254
        add     eax, 8192
255
        mov     dword [ebp+viewer_data.buf_start], eax
256
        mov     edx, dword [ebp+viewer_data.buf_start+4]
257
        adc     edx, 0
258
        mov     dword [ebp+viewer_data.buf_start+4], edx
259
        add     eax, 16384-8192
260
        adc     edx, 0
261
        mov     dword [readinfo.first], eax
262
        mov     dword [readinfo.first+4], edx
263
        mov     dword [readinfo.size], 8192
264
        lea     edi, [ebp+viewer_data.buf]
265
        lea     esi, [edi+8192]
266
        mov     ecx, (16384-8192)/4
267
        rep     movsd
268
        mov     [readinfo.data], edi
269
        lea     eax, [ebp+viewer_data.filename]
270
        mov     [readinfo.name], eax
321 diamond 271
.readretry:
180 heavyiron 272
        mov     ebx, readinfo
589 diamond 273
        mov     eax, [ebp+viewer_data.hPlugin]
274
        test    eax, eax
275
        jz      .native
276
        push    ecx ebp
277
        push    8192
278
        push    [ebx+readinfo.data-readinfo]
279
        push    [ebp+viewer_data.hWorkFile]
280
        call    [eax+PluginInfo.read]
281
        pop     ebp ecx
282
        mov     ebx, eax
283
        cmp     eax, -1
284
        jnz     .readok
285
        xor     ebx, ebx
286
        jmp     .readok
287
.native:
180 heavyiron 288
        push    70
289
        pop     eax
517 diamond 290
        int     40h
321 diamond 291
        test    eax, eax
292
        jz      .readok
293
        cmp     eax, 6
294
        jz      .readok
589 diamond 295
.readerr:
321 diamond 296
        call    ask_retry_ignore
297
        jz      .readretry
298
.readok:
180 heavyiron 299
        sub     [ebp+viewer_data.buf_pos], 8192
300
        add     ebx, 16384-8192
301
        mov     [ebp+viewer_data.buf_size], ebx
302
        mov     eax, [ebp+viewer_data.buf_pos]
303
        cmp     ecx, 16384-8192
304
        jnz     .buffered
305
.err:
306
        stc
307
        popa
308
        ret
309
.buffered:
474 diamond 310
        cmp     [ebp+viewer_data.encoding], encodings.unicode
311
        jz      .unicode
180 heavyiron 312
        mov     al, [eax]
313
.done:
314
        mov     [esp+28], al
315
        inc     [ebp+viewer_data.buf_pos]
316
        clc
317
        popa
318
        ret
319
 
474 diamond 320
.unicode:
321
        inc     [ebp+viewer_data.buf_pos]
322
        cmp     [bForHex], 0
323
        jnz     @f
324
        call    read_unicode_char
325
        jmp     .done
326
@@:
327
        mov     ax, [eax]
328
        mov     [esp+29], ah
329
        jmp     .done
330
 
180 heavyiron 331
viewer_get_prev_char:
332
        pusha
333
        lea     ecx, [ebp+viewer_data.buf]
334
        cmp     [ebp+viewer_data.buf_pos], ecx
335
        ja      .buffered
336
        mov     eax, dword [ebp+viewer_data.buf_start]
337
        mov     edx, dword [ebp+viewer_data.buf_start+4]
338
        test    eax, eax
339
        jnz     @f
340
        test    edx, edx
341
        jnz     @f
342
        stc
343
        jmp     .ret
344
@@:
345
        sub     eax, 8192
346
        sbb     edx, 0
347
        jnc     @f
348
        xor     eax, eax
349
        xor     edx, edx
350
@@:
351
        call    viewer_seek
352
        add     [ebp+viewer_data.buf_pos], 8192
353
.buffered:
354
        mov     eax, [ebp+viewer_data.buf_pos]
355
        dec     eax
474 diamond 356
        cmp     [ebp+viewer_data.encoding], encodings.unicode
357
        jz      .unicode
180 heavyiron 358
        mov     [ebp+viewer_data.buf_pos], eax
359
        mov     al, [eax]
360
        mov     [esp+28], al
474 diamond 361
.done:
180 heavyiron 362
        clc
363
.ret:
364
        popa
365
        ret
366
 
474 diamond 367
.unicode:
368
        dec     eax
369
        mov     [ebp+viewer_data.buf_pos], eax
370
        call    read_unicode_char
371
        jmp     .done
372
 
373
read_unicode_char:
374
        mov     ax, [eax]
375
uni2ansi_char:
376
        test    [ebp+viewer_data.flags], 4
377
        jz      @f
378
        xchg    al, ah
379
@@:
380
        cmp     ax, 0x80
381
        jb      .ret
382
        cmp     ax, 0x401
383
        jz      .yo1
384
        cmp     ax, 0x451
385
        jz      .yo2
386
        cmp     ax, 0x410
387
        jb      .unk
388
        cmp     ax, 0x440
389
        jb      .rus1
390
        cmp     ax, 0x450
391
        jb      .rus2
392
.unk:
393
        mov     al, ' '
394
.ret:
395
        ret
396
.yo1:
397
        mov     al, 'Ё'
398
        ret
399
.yo2:
400
        mov     al, 'ё'
401
        ret
402
.rus1:
403
; 0x410-0x43F -> 0x80-0xAF
404
        add     al, 0x70
405
        ret
406
.rus2:
407
; 0x440-0x44F -> 0xE0-0xEF
408
        add     al, 0xA0
409
        ret
410
 
180 heavyiron 411
fld_uint64:
412
        fild    qword [eax]
413
        test    byte [eax+7], 80h
414
        jz      .ret
415
        fadd    [@f]
416
.ret:
417
        ret
418
@@      dq      18446744073709551616.0 ;0x10000000000000000
419
 
420
viewer_draw_text:
421
        call    viewer_seek_to_current
422
        xor     eax, eax
423
        xor     edx, edx
424
        call    get_console_ptr
425
        mov     ah, [view_status_color]
426
        mov     ecx, [cur_width]
427
        sub     ecx, 44
428
        cmp     ecx, 20
814 diamond 429
        jae     @f
180 heavyiron 430
        mov     cl, 20
431
@@:
814 diamond 432
        call    viewedit_draw_filename
433
        add     ecx, 11
180 heavyiron 434
        rep     stosw
435
        movzx   esi, [ebp+viewer_data.encoding]
436
        lea     esi, [encodings.names+esi*8]
814 diamond 437
        push    edi esi
438
        dec     edi
439
        dec     edi
440
        std
441
        add     esi, 8
180 heavyiron 442
@@:
814 diamond 443
        dec     esi
444
        cmp     byte [esi], ' '
445
        jz      @b
446
@@:
180 heavyiron 447
        lodsb
448
        stosw
814 diamond 449
        cmp     esi, [esp]
450
        jae     @b
451
        cld
452
        pop     esi edi
180 heavyiron 453
        mov     al, ' '
814 diamond 454
        mov     cl, 13
180 heavyiron 455
        rep     stosw
456
        std
457
        push    edi
458
        mov     edx, dword [ebp+viewer_data.filesize+4]
459
        mov     eax, dword [ebp+viewer_data.filesize]
460
        mov     cl, 10
461
@@:
462
        push    eax
463
        mov     eax, edx
464
        xor     edx, edx
465
        div     ecx
466
        xchg    eax, [esp]
467
        div     ecx
468
        xchg    eax, edx
469
        add     al, '0'
470
        mov     ah, [view_status_color]
471
        stosw
472
        xchg    eax, edx
473
        pop     edx
474
        test    eax, eax
475
        jnz     @b
476
        test    edx, edx
477
        jnz     @b
478
        mov     al, ' '
479
        mov     ah, [view_status_color]
480
        stosw
481
        cld
482
        pop     edi
483
        inc     edi
484
        inc     edi
485
        mov     al, ' '
486
        mov     cl, 5
487
        rep     stosw
488
if lang eq ru
489
        mov     al, 'К'
490
        stosw
491
        mov     al, 'о'
492
        stosw
493
        mov     al, 'л'
494
        stosw
495
else
496
        mov     al, 'C'
497
        stosw
498
        mov     al, 'o'
499
        stosw
500
        mov     al, 'l'
501
        stosw
502
end if
503
        mov     al, ' '
504
        stosw
505
        push    edi
506
        mov     eax, dword [ebp+viewer_data.col]
507
        mov     edx, dword [ebp+viewer_data.col+4]
508
        test    edx, edx
509
        jnz     .col_big
510
        cmp     eax, 100000
511
        jae     .col_big
512
        mov     cl, 10
513
        push    -'0'
514
@@:
515
        div     ecx
516
        push    edx
517
        xor     edx, edx
518
        test    eax, eax
519
        jnz     @b
520
@@:
521
        pop     eax
522
        add     eax, '0'
523
        jz      .col_done
524
        mov     ah, [view_status_color]
525
        stosw
526
        jmp     @b
527
.col_big:
528
        push    eax
529
        mov     al, '.'
530
        mov     ah, [view_status_color]
531
        stosw
532
        stosw
533
        stosw
534
        xor     eax, eax
535
        xchg    eax, edx
536
        mov     cl, 100
537
        div     ecx
538
        pop     eax
539
        div     ecx
540
        mov     cl, 10
541
        xor     eax, eax
542
        xchg    eax, edx
543
        div     ecx
544
        add     al, '0'
545
        mov     ah, [view_status_color]
546
        stosw
547
        mov     al, dl
548
        add     al, '0'
549
        stosw
550
.col_done:
551
        pop     ecx
552
        add     ecx, 10*2
553
        sub     ecx, edi
554
        shr     ecx, 1
555
        mov     al, ' '
556
        mov     ah, [view_status_color]
557
        rep     stosw
558
        finit
559
        fldcw   [fpu_cw]
560
        mov     [tmp], 100
561
        lea     eax, [ebp+viewer_data.filesize]
562
        cmp     dword [eax], 0
563
        jnz     @f
564
        cmp     dword [eax+4], 0
565
        jz      .size_zero
566
@@:
567
        call    fld_uint64
568
        lea     eax, [ebp+viewer_data.cur_pos]
569
        call    fld_uint64
570
        fdivrp
571
        fimul   [_100d]
572
        fistp   [tmp]
573
.size_zero:
574
        mov     byte [edi-2], '%'
575
        sub     edi, 4
576
        mov     eax, [tmp]
577
        mov     cl, 10
578
@@:
579
        xor     edx, edx
580
        div     ecx
581
        xchg    eax, edx
582
        add     al, '0'
583
        mov     [edi], al
584
        sub     edi, 2
585
        xchg    eax, edx
586
        test    eax, eax
587
        jnz     @b
588
        xor     eax, eax
589
        push    1
590
        pop     edx
591
        call    get_console_ptr
592
        test    [ebp+viewer_data.flags], 1
593
        jnz     .DrawHex
594
        push    2
595
        pop     edx
596
        xor     ecx, ecx
597
        mov     dword [scrpos], ecx
598
        mov     dword [scrpos+4], ecx
599
        mov     dword [viewer_right_side], ecx
600
        mov     dword [viewer_right_side+4], ecx
601
.1:
602
        call    viewer_get_next_char
603
        jc      .done
604
.2:
605
        cmp     al, 0xD
606
        jz      .newline
607
        cmp     al, 0xA
608
        jz      .newline
609
        cmp     ecx, [cur_width]
610
        jb      .no_newline
611
        test    [ebp+viewer_data.flags], 2
612
        jnz     .no_newline
613
.newline:
614
        push    eax
615
        mov     ecx, dword [scrpos]
616
        mov     eax, dword [scrpos+4]
617
        sub     ecx, dword [ebp+viewer_data.col]
618
        sbb     eax, dword [ebp+viewer_data.col+4]
619
        ja      .line_filled
620
        jb      .line_full
621
        cmp     ecx, [cur_width]
622
        ja      .line_filled
623
        jmp     @f
624
.line_full:
625
        xor     ecx, ecx
626
@@:
627
        test    ecx, ecx
628
        jnz     @f
629
        mov     eax, dword [scrpos]
630
        or      eax, dword [scrpos+4]
631
        jz      @f
632
        inc     ecx
633
@@:
634
        sub     ecx, [cur_width]
635
        neg     ecx
636
        mov     al, ' '
637
        mov     ah, [view_normal_color]
638
        rep     stosw
639
.line_filled:
640
        mov     eax, dword [scrpos]
641
        sub     eax, dword [viewer_right_side]
642
        mov     eax, dword [scrpos+4]
643
        sbb     eax, dword [viewer_right_side+4]
644
        jb      @f
645
        mov     eax, dword [scrpos]
646
        mov     dword [viewer_right_side], eax
647
        mov     eax, dword [scrpos+4]
648
        mov     dword [viewer_right_side+4], eax
649
@@:
650
        xor     ecx, ecx
651
        mov     dword [scrpos], ecx
652
        mov     dword [scrpos+4], ecx
653
        inc     edx
654
        pop     eax
655
        cmp     edx, [cur_height]
656
        jae     .done
657
.no_newline:
658
        cmp     al, 0xD
659
        jz      .3
660
        cmp     al, 0xA
661
        jz      .3
662
.4:
663
        test    al, al
664
        jns     @f
665
        movzx   esi, [ebp+viewer_data.encoding]
474 diamond 666
        cmp     esi, encodings.unicode
667
        jz      @f
180 heavyiron 668
        shl     esi, 7
669
        movzx   eax, al
670
        mov     al, [encodings.tables-80h+esi+eax]
671
@@:
672
        cmp     al, 9
673
        jz      .tab
674
        call    .write_char
675
        inc     ecx
676
        jns     .1
677
        push    edx
678
        mov     eax, ecx
679
        xor     edx, edx
814 diamond 680
        div     [viewer_tabsize]
180 heavyiron 681
        mov     ecx, edx
682
        pop     edx
683
        jmp     .1
684
.3:
685
        mov     bl, al
686
        call    viewer_get_next_char
687
        jc      .done
688
        xor     bl, al
689
        cmp     bl, 0xA xor 0xD
690
        jz      .1
691
        jmp     .2
692
.tab:
693
        push    edx
694
        push    ecx
695
        mov     eax, ecx
814 diamond 696
        mov     ecx, [viewer_tabsize]
180 heavyiron 697
        xor     edx, edx
698
        div     ecx
699
        pop     eax
700
        sub     ecx, edx
701
        add     eax, ecx
702
        test    [ebp+viewer_data.flags], 2
703
        jnz     @f
704
        cmp     eax, [cur_width]
705
        jbe     @f
706
        sub     eax, [cur_width]
707
        sub     ecx, eax
708
        mov     eax, [cur_width]
709
@@:
710
        push    eax
711
        mov     al, ' '
712
@@:
713
        call    .write_char
714
        loop    @b
715
        pop     ecx
716
        pop     edx
717
        jmp     .1
718
.done:
719
        setc    [ebp+viewer_data.bEofReached]
720
.done2:
721
        inc     edx
722
        cmp     edx, [cur_height]
723
        jnc     @f
724
        mov     eax, dword [ebp+viewer_data.cur_pos]
725
        or      eax, dword [ebp+viewer_data.cur_pos+4]
726
        jz      @f
727
        call    viewer_seek_to_current
728
        call    viewer_prev_newline
729
        jmp     viewer_draw_text
730
@@:
731
        push    edi
732
        xor     eax, eax
733
        mov     edx, [cur_height]
734
        dec     edx
735
        call    get_console_ptr
736
        mov     ecx, edi
737
        pop     edi
738
        sub     ecx, edi
739
        shr     ecx, 1
740
        mov     al, ' '
741
        mov     ah, [view_normal_color]
742
        rep     stosw
743
        cmp     [ebp+viewer_data.bEofReached], 0
744
        jz      @f
745
        xor     edx, edx
746
        mov     eax, [cur_width]
747
        sub     eax, 4
748
        call    get_console_ptr
749
        mov     ah, [view_status_color]
750
        mov     al, '1'
751
        stosw
752
        mov     al, '0'
753
        stosw
754
        stosw
755
@@:
756
        call    draw_image
757
        ret
758
.DrawHex:
759
        xor     esi, esi
760
        mov     [ebp+viewer_data.bEofReached], 0
761
.line:
762
        mov     al, ' '
763
        mov     ah, [view_normal_color]
764
        push    edi
765
        mov     ecx, [cur_width]
766
        rep     stosw
767
        mov     ebx, edi
768
        pop     edi
474 diamond 769
        mov     [bForHex], 1
180 heavyiron 770
        call    viewer_get_next_char
474 diamond 771
        mov     [bForHex], 0
180 heavyiron 772
        jc      .hexdone
773
        push    eax
774
        push    edi
775
        add     edi, 36*2
776
        mov     al, 0xB3
474 diamond 777
        mov     ah, [view_normal_color]
180 heavyiron 778
        call    .safechar
779
        pop     edi
780
        mov     eax, dword [ebp+viewer_data.cur_pos]
781
        mov     edx, dword [ebp+viewer_data.cur_pos+4]
782
        push    esi
783
        shl     esi, 4
784
        add     eax, esi
785
        adc     edx, 0
786
        pop     esi
787
        push    eax
788
        mov     al, dl
789
        shr     eax, 4
790
        and     al, 0xF
791
        call    .hex_digit
792
        mov     al, dl
793
        and     al, 0xF
794
        call    .hex_digit
795
        pop     eax
796
        push    8
797
        pop     ecx
798
        add     edi, 7*2
799
        std
800
@@:
801
        push    eax
802
        and     al, 0xF
803
        call    .hex_digit
804
        pop     eax
805
        shr     eax, 4
806
        loop    @b
807
        cld
808
        add     edi, 9*2
809
        mov     al, ':'
810
        mov     ah, [view_normal_color]
811
        stosw
812
        mov     al, ' '
813
        stosw
814
        xor     ecx, ecx
815
        pop     eax
816
        jmp     @f
817
.hexchar:
474 diamond 818
        mov     [bForHex], 1
180 heavyiron 819
        call    viewer_get_next_char
474 diamond 820
        mov     [bForHex], 0
180 heavyiron 821
        jc      .hexdone
822
@@:
474 diamond 823
        cmp     [ebp+viewer_data.encoding], encodings.unicode
824
        jz      .hexchar_unicode
180 heavyiron 825
        push    eax
826
        shr     al, 4
827
        call    .hex_digit
828
        pop     eax
829
        push    eax
830
        and     al, 0xF
831
        call    .hex_digit
832
        mov     al, ' '
833
        call    .safechar
834
        pop     eax
835
        push    edi
836
        add     edi, 48*2
837
        push    ecx
838
        shl     ecx, 2
839
        sub     edi, ecx
840
        pop     ecx
841
        cmp     ecx, 8
842
        jb      @f
843
        sub     edi, 4
844
@@:
845
        test    al, al
846
        jns     @f
847
        movzx   edx, [ebp+viewer_data.encoding]
848
        shl     edx, 7
849
        movzx   eax, al
850
        mov     al, [encodings.tables+eax+edx-80h]
851
        mov     ah, [view_normal_color]
852
@@:
853
        call    .safechar
854
        pop     edi
855
        inc     ecx
856
        cmp     ecx, 8
857
        jnz     @f
858
        mov     al, 0xB3
859
        call    .safechar
860
        mov     al, ' '
861
        call    .safechar
862
@@:
863
        cmp     ecx, 16
864
        jnz     .hexchar
474 diamond 865
        jmp     .hexchar_nextline
866
.hexchar_unicode:
867
        push    eax
868
        shr     eax, 12
869
        call    .hex_digit
870
        pop     eax
871
        push    eax
872
        shr     eax, 8
873
        and     al, 0xF
874
        call    .hex_digit
875
        pop     eax
876
        push    eax
877
        shr     al, 4
878
        call    .hex_digit
879
        pop     eax
880
        push    eax
881
        and     al, 0xF
882
        call    .hex_digit
883
        mov     al, ' '
884
        mov     ah, [view_normal_color]
885
        call    .safechar
886
        pop     eax
887
        push    edi
888
        add     edi, 38*2
889
        push    ecx
890
        shl     ecx, 3
891
        sub     edi, ecx
892
        pop     ecx
893
        cmp     ecx, 4
894
        jb      @f
895
        sub     edi, 4
896
@@:
897
        call    uni2ansi_char
898
        mov     ah, [view_normal_color]
899
        call    .safechar
900
        pop     edi
901
        inc     ecx
902
        cmp     ecx, 4
903
        jnz     @f
904
        mov     al, 0xB3
905
        call    .safechar
906
        mov     al, ' '
907
        call    .safechar
908
@@:
909
        cmp     ecx, 8
910
        jnz     .hexchar
911
.hexchar_nextline:
180 heavyiron 912
        mov     edi, ebx
913
        add     esi, 3
914
        mov     edx, esi
915
        cmp     esi, [cur_height]
916
        jae     .done2
917
        dec     esi
918
        dec     esi
919
        jmp     .line
920
.hexdone:
921
        mov     [ebp+viewer_data.bEofReached], 1
922
        mov     edi, ebx
923
        lea     edx, [esi+2]
924
        jmp     .done2
925
 
926
.hex_digit:
927
        push    eax
928
        cmp     al, 10
929
        sbb     al, 69h
930
        das
931
        mov     ah, [view_normal_color]
932
        call    .safechar
933
        pop     eax
934
        ret
935
.safechar:
936
        cmp     edi, ebx
937
        jae     @f
938
        stosw
939
@@:
940
        ret
941
.write_char:
942
        push    ecx eax
943
        mov     ecx, dword [scrpos]
944
        mov     eax, dword [scrpos+4]
945
        sub     ecx, dword [ebp+viewer_data.col]
946
        sbb     eax, dword [ebp+viewer_data.col+4]
947
        jb      .left
948
        ja      .skip
949
        test    ecx, ecx
950
        jnz     @f
951
        mov     eax, dword [scrpos]
952
        or      eax, dword [scrpos+4]
953
        jnz     .skip
954
@@:
955
        cmp     ecx, [cur_width]
956
        ja      .skip
957
        jb      .do
958
        mov     al, '>'
959
        mov     [edi-2], al
960
        mov     al, [view_arrows_color]
961
        mov     [edi-1], al
962
        jmp     .skip
963
.left:
964
        mov     eax, dword [scrpos]
965
        or      eax, dword [scrpos+4]
966
        jnz     .skip
967
        mov     al, '<'
968
        mov     ah, [view_arrows_color]
969
        stosw
970
        jmp     .skip
971
.do:
972
        mov     al, [esp]
973
        mov     ah, [view_normal_color]
974
        stosw
975
.skip:
976
        pop     eax ecx
977
        add     dword [scrpos], 1
978
        adc     dword [scrpos+4], 0
979
        ret
980
 
814 diamond 981
viewedit_draw_filename:
982
        lea     esi, [ebp+viewer_data.filename]
983
        xor     edx, edx
984
        cmp     [ebp+viewer_data.hPlugin], edx
985
        mov     dl, 3
986
        jz      .5
987
        mov     dl, 1
988
.5:
989
        lodsb
990
        cmp     al, '/'
991
        jnz     @f
992
        dec     edx
993
        jz      .6
994
@@:
995
        stosw
996
        loop    .5
997
.6:
998
        dec     ecx
999
        stosw
1000
        push    esi
1001
@@:
1002
        inc     esi
1003
        cmp     byte [esi-1], 0
1004
        jnz     @b
1005
        sub     esi, [esp]
1006
        dec     esi
1007
        cmp     ecx, esi
1008
        jae     .7
1009
        mov     al, '.'
1010
        stosw
1011
        stosw
1012
        stosw
1013
        sub     ecx, 3
1014
        sub     esi, ecx
1015
        add     [esp], esi
1016
.7:
1017
        pop     esi
1018
@@:
1019
        lodsb
1020
        test    al, al
1021
        jz      @f
1022
        dec     ecx
1023
        stosw
1024
        jmp     @b
1025
@@:
1026
        mov     al, ' '
1027
        ret
1028
 
180 heavyiron 1029
viewer_seek_to_current:
1030
        mov     eax, dword [ebp+viewer_data.cur_pos]
1031
        mov     edx, dword [ebp+viewer_data.cur_pos+4]
1032
viewer_seek:
1033
        push    eax edx
1034
        sub     eax, dword [ebp+viewer_data.buf_start]
1035
        sbb     edx, dword [ebp+viewer_data.buf_start+4]
1036
        jb      .prev
1037
        ja      .next
1038
        cmp     eax, 16384
1039
        jae     .next
1040
        lea     eax, [ebp+viewer_data.buf+eax]
1041
        mov     [ebp+viewer_data.buf_pos], eax
1042
        pop     edx eax
1043
        ret
1044
.prev:
1045
        inc     edx
1046
        jnz     .read_full
1047
        and     eax, not 511
1048
        cmp     eax, -16384
1049
        jbe     .read_full
1050
        lea     edi, [ebp+viewer_data.buf+16384-4]
1051
        lea     esi, [edi+eax]
1052
        lea     ecx, [eax+16384]
1053
        push    ecx
1054
        shr     ecx, 2
1055
        std
1056
        rep     movsd
1057
        cld
1058
        pop     ecx
1059
        add     dword [ebp+viewer_data.buf_start], eax
1060
        adc     dword [ebp+viewer_data.buf_start+4], -1
1061
        neg     eax
1062
        cmp     dword [ebp+viewer_data.buf_size], ecx
1063
        jb      .doread
1064
        mov     dword [ebp+viewer_data.buf_size], ecx
1065
        jmp     .doread
1066
.read_full:
1067
        pop     edx eax
1068
        push    eax edx
1069
        and     eax, not 511
1070
        sub     eax, 8192-512
1071
        sbb     edx, 0
1072
        jnc     @f
1073
        xor     eax, eax
1074
        xor     edx, edx
1075
@@:
1076
        mov     dword [ebp+viewer_data.buf_start], eax
1077
        mov     dword [ebp+viewer_data.buf_start+4], edx
1078
        and     dword [ebp+viewer_data.buf_size], 0
1079
        mov     eax, 16384
1080
.doread:
1081
        mov     ebx, readinfo
1082
        push    dword [ebp+viewer_data.buf_start]
1083
        pop     dword [ebx+4]
1084
        push    dword [ebp+viewer_data.buf_start+4]
1085
        pop     dword [ebx+8]
1086
        mov     [ebx+12], eax
1087
        lea     eax, [ebp+viewer_data.buf]
1088
        mov     [ebx+16], eax
1089
        lea     eax, [ebp+viewer_data.filename]
1090
        mov     [ebx+21], eax
589 diamond 1091
        call    .q
180 heavyiron 1092
        cmp     ebx, [readinfo.size]
1093
        jnz     @f
1094
        add     ebx, [ebp+viewer_data.buf_size]
1095
@@:
1096
.ret:
1097
        mov     [ebp+viewer_data.buf_size], ebx
1098
        pop     edx eax
1099
        sub     eax, dword [ebp+viewer_data.buf_start]
1100
        lea     eax, [ebp+eax+viewer_data.buf]
1101
        mov     [ebp+viewer_data.buf_pos], eax
1102
        ret
1103
.next:
1104
        or      eax, 511
1105
        sub     eax, 16384-1
1106
        sbb     edx, 0
1107
        jnz     .read_full
1108
        cmp     eax, 16384
1109
        jae     .read_full
1110
        cmp     [ebp+viewer_data.buf_size], 16384
1111
        jb      .read_full
1112
        lea     edi, [ebp+viewer_data.buf]
1113
        lea     esi, [edi+eax]
1114
        mov     ecx, 16384
1115
        sub     ecx, eax
1116
        shr     ecx, 2
1117
        rep     movsd
1118
        add     dword [ebp+viewer_data.buf_start], eax
1119
        adc     dword [ebp+viewer_data.buf_start+4], 0
1120
        mov     ebx, readinfo
1121
        mov     [ebx+16], edi
1122
        sub     edi, ebp
1123
        sub     edi, viewer_data.buf
1124
        mov     edx, dword [ebp+viewer_data.buf_start]
1125
        add     edx, edi
1126
        mov     [ebx+4], edx
1127
        mov     edx, dword [ebp+viewer_data.buf_start+4]
1128
        adc     edx, 0
1129
        mov     [ebx+8], edx
1130
        mov     [ebx+12], eax
1131
        lea     eax, [ebp+viewer_data.filename]
1132
        mov     [ebx+21], eax
589 diamond 1133
        call    .q
1134
        sub     ebx, [readinfo.size]
1135
        add     ebx, 16384
1136
        jmp     .ret
1137
 
1138
.q:
1139
        mov     ebx, readinfo
1140
        mov     eax, [ebp+viewer_data.hPlugin]
1141
        test    eax, eax
1142
        jz      .native
1143
        push    ebp
1144
        push    dword [ebx+12]
1145
        push    dword [ebx+16]
1146
        push    [ebp+viewer_data.hWorkFile]
1147
        push    eax
1148
        push    dword [ebx+8]
1149
        push    dword [ebx+4]
1150
        push    [ebp+viewer_data.hWorkFile]
1151
        call    [eax+PluginInfo.setpos]
1152
        pop     eax
1153
        call    [eax+PluginInfo.read]
1154
        pop     ebp
1155
        mov     ebx, eax
1156
        cmp     eax, -1
1157
        jnz     @f
1158
        xor     ebx, ebx
321 diamond 1159
@@:
589 diamond 1160
        ret
1161
.native:
180 heavyiron 1162
        push    70
1163
        pop     eax
517 diamond 1164
        int     40h
321 diamond 1165
        test    eax, eax
589 diamond 1166
        jz      .readok
321 diamond 1167
        cmp     eax, 6
589 diamond 1168
        jz      .readok
1169
.readerr:
321 diamond 1170
        call    ask_retry_ignore
589 diamond 1171
        jz      .q
1172
.readok:
1173
        ret
180 heavyiron 1174
 
321 diamond 1175
ask_retry_ignore:
1176
        push    esi
1177
        lea     esi, [ebp+viewer_data.filename]
1178
        push    esi
1179
        push    aCannotReadFile
1180
        call    get_error_msg
1181
        push    eax
1182
        mov     eax, esp
1183
        push    RetryOrIgnoreBtn
1184
        push    2
1185
        push    eax
1186
        push    3
1187
        call    SayErr
1188
        add     esp, 3*4
1189
        pop     esi
1190
        test    eax, eax
1191
        ret
1192
 
180 heavyiron 1193
viewer_set_curpos:
1194
        mov     eax, [ebp+viewer_data.buf_pos]
1195
        sub     eax, ebp
1196
        sub     eax, viewer_data.buf
1197
        xor     edx, edx
1198
        add     eax, dword [ebp+viewer_data.buf_start]
1199
        adc     edx, dword [ebp+viewer_data.buf_start+4]
1200
        mov     dword [ebp+viewer_data.cur_pos], eax
1201
        mov     dword [ebp+viewer_data.cur_pos+4], edx
1202
        ret
1203
 
1204
viewer_next_newline:
1205
        test    [ebp+viewer_data.flags], 1
1206
        jz      .nohex
474 diamond 1207
        push    8
180 heavyiron 1208
        pop     ecx
474 diamond 1209
        cmp     [ebp+viewer_data.encoding], encodings.unicode
1210
        jz      @f
1211
        add     ecx, ecx
180 heavyiron 1212
@@:
1213
        call    viewer_get_next_char
1214
        jc      @f
1215
        loop    @b
1216
        call    viewer_set_curpos
1217
        clc
1218
@@:     ret
1219
.nohex:
1220
        xor     ecx, ecx
1221
@@:
1222
        call    viewer_get_next_char
1223
        jc      .ret
1224
        cmp     al, 0xD
1225
        jz      .1
1226
        cmp     al, 0xA
1227
        jz      .1
1228
        cmp     al, 9
1229
        jz      .tab
1230
        inc     ecx
1231
.next:
1232
        test    [ebp+viewer_data.flags], 2
1233
        jnz     @b
1234
        cmp     ecx, [cur_width]
1235
        jbe     @b
1236
        call    viewer_get_prev_char
1237
        jmp     .2
1238
.tab:
1239
        push    ecx
1240
        mov     eax, ecx
814 diamond 1241
        mov     ecx, [viewer_tabsize]
180 heavyiron 1242
        xor     edx, edx
1243
        div     ecx
1244
        sub     ecx, edx
1245
        add     [esp], ecx
1246
        pop     ecx
1247
        jmp     .next
1248
.1:
1249
        mov     cl, al
1250
        call    viewer_get_next_char
1251
        jc      .ret
1252
        xor     cl, al
1253
        cmp     cl, 0xD xor 0xA
1254
        jz      .2
1255
        dec     [ebp+viewer_data.buf_pos]
474 diamond 1256
        cmp     [ebp+viewer_data.encoding], encodings.unicode
1257
        jnz     .2
1258
        dec     [ebp+viewer_data.buf_pos]
180 heavyiron 1259
.2:
814 diamond 1260
        clc
180 heavyiron 1261
.ret:
814 diamond 1262
        pushf
180 heavyiron 1263
        call    viewer_set_curpos
814 diamond 1264
        popf
180 heavyiron 1265
        ret
1266
 
1267
viewer_prev_newline:
1268
        test    [ebp+viewer_data.flags], 1
1269
        jz      .nohex
474 diamond 1270
        push    8
180 heavyiron 1271
        pop     ecx
474 diamond 1272
        cmp     [ebp+viewer_data.encoding], encodings.unicode
1273
        jz      @f
1274
        add     ecx, ecx
180 heavyiron 1275
@@:
1276
        call    viewer_get_prev_char
1277
        jc      @f
1278
        loop    @b
1279
@@:     call    viewer_set_curpos
1280
        ret
1281
.nohex:
1282
        mov     eax, 8192
1283
        push    eax
1284
        cdq
1285
        div     [cur_width]
1286
        pop     eax
1287
        sub     eax, edx
1288
        mov     edx, eax
1289
        call    viewer_get_prev_char
1290
        jc      .0
1291
        dec     edx
1292
        cmp     al, 0xD
1293
        jz      .2
1294
        cmp     al, 0xA
1295
        jnz     .3
1296
.2:
1297
        mov     cl, al
1298
        call    viewer_get_prev_char
1299
        jc      .0
1300
        dec     edx
1301
        xor     cl, al
1302
        cmp     cl, 0xD xor 0xA
1303
        jnz     .3
1304
@@:
1305
        call    viewer_get_prev_char
1306
        jc      .0
1307
        dec     edx
1308
        jz      .0
1309
.3:
1310
        cmp     al, 0xD
1311
        jz      .1
1312
        cmp     al, 0xA
1313
        jnz     @b
1314
.1:
1315
        call    viewer_get_next_char
1316
.0:
1317
        push    dword [ebp+viewer_data.cur_pos+4]
1318
        push    dword [ebp+viewer_data.cur_pos]
1319
        call    viewer_set_curpos
1320
@@:
1321
        push    dword [ebp+viewer_data.cur_pos+4]
1322
        push    dword [ebp+viewer_data.cur_pos]
1323
        call    viewer_next_newline
1324
        jc      .ret3
1325
        mov     eax, dword [ebp+viewer_data.cur_pos]
1326
        mov     edx, dword [ebp+viewer_data.cur_pos+4]
1327
        sub     eax, [esp+8]
1328
        sbb     edx, [esp+12]
1329
        jae     .ret3
1330
        pop     eax
1331
        pop     eax
1332
        jmp     @b
1333
.ret3:
1334
        pop     dword [ebp+viewer_data.cur_pos]
1335
        pop     dword [ebp+viewer_data.cur_pos+4]
1336
.ret:
1337
        pop     eax
1338
        pop     eax
1339
        jmp     viewer_seek_to_current
1340
 
1341
viewer_set_keybar:
1342
        mov     eax, keybar_viewer
1343
if lang eq ru
1344
        test    [ebp+viewer_data.flags], 1
1345
        jnz     .hex
1346
        mov     dword [eax+(4-1)*6], 'Код '
1347
        mov     word [eax+(4-1)*6+4], '  '
1348
        jmp     @f
1349
.hex:
1350
        mov     dword [eax+(4-1)*6], 'Текс'
1351
        mov     word [eax+(4-1)*6+4], 'т '
1352
@@:
1353
        test    [ebp+viewer_data.flags], 2
1354
        jnz     .unwrap
1355
        mov     dword [eax+6], 'Разв'
1356
        mov     word [eax+6+4], 'ер'
1357
        jmp     @f
1358
.unwrap:
1359
        mov     dword [eax+6], 'Свер'
1360
        mov     word [eax+6+4], 'н '
1361
@@:
1362
else
1363
        test    [ebp+viewer_data.flags], 1
1364
        jnz     .hex
1365
        mov     dword [eax+(4-1)*6], 'Hex '
1366
;        mov     word [eax+(4-1)*6+4], '  '
1367
        jmp     @f
1368
.hex:
1369
        mov     dword [eax+(4-1)*6], 'Text'
1370
;        mov     word [eax+(4-1)*6+4], '  '
1371
@@:
1372
        test    [ebp+viewer_data.flags], 2
1373
        jnz     .unwrap
1374
        mov     dword [eax+6], 'Unwr'
1375
        mov     word [eax+6+4], 'ap'
1376
        jmp     @f
1377
.unwrap:
1378
        mov     dword [eax+6], 'Wrap'
1379
        mov     word [eax+6+4], '  '
1380
@@:
1381
end if
1382
        movzx   esi, [ebp+viewer_data.encoding]
474 diamond 1383
        dec     esi
1384
        jz      @f
1385
        push    1
1386
        pop     esi
1387
@@:
180 heavyiron 1388
        lea     esi, [encodings.names+esi*8]
1389
        lea     edi, [eax+keybar_cp-keybar_viewer]
1390
        movsd
1391
        movsw
1392
        jmp     draw_keybar
1393
 
589 diamond 1394
viewer_OnExit:
1395
        mov     edx, [ebp+viewer_data.hPlugin]
1396
        test    edx, edx
1397
        jz      @f
1398
        and     [ebp+viewer_data.hPlugin], 0
1399
        push    edx ebp
1400
        push    [ebp+viewer_data.hWorkFile]
1401
        call    [edx+PluginInfo.close]
1402
        pop     ebp edx
1403
        mov     ebx, [ebp+viewer_data.hFile]
1404
        call    close_handle_if_unused
1405
@@:
1406
        ret
1407
 
1408
viewer_IsHandleUsed:
814 diamond 1409
editor_IsHandleUsed:
589 diamond 1410
        cmp     edx, [ebp+viewer_data.hPlugin]
1411
        jnz     @f
1412
        cmp     ebx, [ebp+viewer_data.hFile]
1413
@@:
1414
        ret
1415
 
180 heavyiron 1416
viewer_OnKey:
1417
        mov     esi, viewer_ctrlkeys
1418
        jmp     process_ctrl_keys
1419
.exit:
589 diamond 1420
        call    viewer_OnExit
1421
        jmp     delete_active_screen
180 heavyiron 1422
.down:
1423
        cmp     [ebp+viewer_data.bEofReached], 0
1424
        jnz     .ret
1425
        call    viewer_seek_to_current
1426
        call    viewer_next_newline
1427
        jc      .ret
1428
        call    viewer_draw_text
1429
        ret
1430
.pgdn:
1431
        cmp     [ebp+viewer_data.bEofReached], 0
1432
        jnz     .ret
1433
        call    viewer_seek_to_current
1434
        mov     ebx, [cur_height]
1435
        sub     ebx, 3
1436
@@:
1437
        call    viewer_next_newline
1438
        jc      .ret
1439
        dec     ebx
1440
        jnz     @b
1441
        call    viewer_draw_text
1442
        ret
1443
.up:
1444
        call    viewer_seek_to_current
1445
        call    viewer_prev_newline
1446
        call    viewer_draw_text
1447
        ret
1448
.pgup:
1449
        call    viewer_seek_to_current
1450
        mov     ebx, [cur_height]
1451
        sub     ebx, 3
1452
@@:
1453
        call    viewer_prev_newline
1454
        dec     ebx
1455
        jnz     @b
1456
.done_redraw:
1457
        call    viewer_draw_text
1458
.ret:
1459
        ret
1460
.f8:
1461
        movzx   esi, [ebp+viewer_data.encoding]
474 diamond 1462
        dec     [ebp+viewer_data.encoding]
1463
        jz      .done_redraw_keybar
1464
        mov     [ebp+viewer_data.encoding], 1
1465
        jmp     .done_redraw_keybar
180 heavyiron 1466
.f2:
1467
        xor     [ebp+viewer_data.flags], 2
474 diamond 1468
.done_redraw_keybar:
180 heavyiron 1469
        call    viewer_set_keybar
1470
        jmp     .done_redraw
1471
.f4:
1472
        xor     [ebp+viewer_data.flags], 1
1473
        pushf
1474
        call    viewer_set_keybar
1475
        popf
1476
        jnz     .tohex
474 diamond 1477
        push    1
1478
        pop     eax
1479
        cmp     [ebp+viewer_data.encoding], encodings.unicode
1480
        jnz     @f
1481
        add     eax, eax
1482
@@:
1483
        add     dword [ebp+viewer_data.cur_pos], eax
180 heavyiron 1484
        adc     dword [ebp+viewer_data.cur_pos+4], 0
1485
        call    viewer_seek_to_current
1486
        call    viewer_prev_newline
1487
        jmp     .done_redraw
1488
.tohex:
1489
        and     byte [ebp+viewer_data.cur_pos], 0xF0
1490
        jmp     .done_redraw
1491
.home:
1492
        xor     eax, eax
1493
        mov     dword [ebp+viewer_data.cur_pos], eax
1494
        mov     dword [ebp+viewer_data.cur_pos+4], eax
1495
        mov     dword [ebp+viewer_data.col], eax
1496
        mov     dword [ebp+viewer_data.col+4], eax
1497
        jmp     .done_redraw
1498
.end:
1499
        mov     eax, dword [ebp+viewer_data.filesize]
1500
        mov     edx, dword [ebp+viewer_data.filesize+4]
1501
        and     al, 0xF0
1502
        mov     dword [ebp+viewer_data.cur_pos], eax
1503
        mov     dword [ebp+viewer_data.cur_pos+4], edx
1504
        and     dword [ebp+viewer_data.col], 0
1505
        and     dword [ebp+viewer_data.col+4], 0
1506
        jmp     .done_redraw
1507
.right:
1508
        add     dword [ebp+viewer_data.col], 1
1509
        adc     dword [ebp+viewer_data.col+4], 0
1510
        jnc     .done_redraw
1511
        sub     dword [ebp+viewer_data.col], 1
1512
        sbb     dword [ebp+viewer_data.col+4], 0
1513
        ret
1514
.left:
1515
        sub     dword [ebp+viewer_data.col], 1
1516
        sbb     dword [ebp+viewer_data.col+4], 0
1517
        jnc     .done_redraw
1518
        add     dword [ebp+viewer_data.col], 1
1519
        adc     dword [ebp+viewer_data.col+4], 0
1520
        ret
1521
.ctrl_left:
1522
        test    [ebp+viewer_data.flags], 1
1523
        jnz     .ctrl_left_hex
1524
        sub     dword [ebp+viewer_data.col], 20
1525
        sbb     dword [ebp+viewer_data.col+4], 0
1526
        jnc     .done_redraw
1527
.ctrl_shift_left:
1528
        and     dword [ebp+viewer_data.col], 0
1529
        and     dword [ebp+viewer_data.col+4], 0
1530
        jmp     .done_redraw
1531
.ctrl_left_hex:
1532
        call    viewer_seek_to_current
1533
        call    viewer_get_prev_char
1534
        jc      @f
1535
        call    viewer_set_curpos
1536
        jmp     .done_redraw
1537
.ctrl_right:
1538
        test    [ebp+viewer_data.flags], 1
1539
        jnz     .ctrl_right_hex
1540
        add     dword [ebp+viewer_data.col], 20
1541
        adc     dword [ebp+viewer_data.col+4], 0
1542
        jnc     .done_redraw
1543
        sub     dword [ebp+viewer_data.col], 20
1544
        sbb     dword [ebp+viewer_data.col+4], 0
1545
@@:     ret
1546
.ctrl_right_hex:
1547
        call    viewer_seek_to_current
1548
        call    viewer_get_next_char
1549
        call    viewer_set_curpos
1550
        jmp     .done_redraw
1551
.ctrl_shift_right:
1552
        test    [ebp+viewer_data.flags], 1
1553
        jnz     @b
1554
        mov     eax, dword [viewer_right_side]
1555
        mov     edx, dword [viewer_right_side+4]
1556
        sub     eax, [cur_width]
1557
        sbb     edx, 0
1558
        jnc     @f
1559
        xor     eax, eax
1560
        xor     edx, edx
1561
@@:
1562
        mov     dword [ebp+viewer_data.col], eax
1563
        mov     dword [ebp+viewer_data.col+4], edx
1564
        jmp     .done_redraw
474 diamond 1565
.shift_f8:
1566
        mov     ecx, encodings.menu.1
1567
        mov     al, [ebp+viewer_data.encoding]
1568
@@:
1569
        cmp     byte [ecx-1], al
1570
        jz      @f
1571
        mov     ecx, [ecx]
1572
        jmp     @b
1573
@@:
1574
        push    1
1575
        push    aTables
1576
        push    ecx
1577
        call    menu
1578
        cmp     eax, -1
1579
        jz      .ret
1580
        mov     al, [eax-1]
1581
        mov     [ebp+viewer_data.encoding], al
1582
        cmp     al, encodings.unicode
1583
        jnz     .done_redraw_keybar
1584
        add     dword [ebp+viewer_data.cur_pos], 1
1585
        adc     dword [ebp+viewer_data.cur_pos+4], 0
1586
        and     dword [ebp+viewer_data.cur_pos], not 1
1587
        jmp     .done_redraw_keybar
180 heavyiron 1588
 
1589
viewer_getname:
1590
if lang eq ru
1591
        mov     eax, 'Прос'
1592
        stosd
1593
        mov     eax, 'мотр'
1594
        stosd
1595
        mov     eax, '    '
1596
        stosd
1597
        stosb
1598
else
1599
        mov     eax, 'View'
1600
        stosd
1601
        mov     eax, '    '
1602
        stosd
1603
        stosd
1604
        stosb
1605
end if
814 diamond 1606
        jmp     viewedit_getname
1607
editor_getname:
1608
if lang eq ru
1609
        mov     eax, 'Реда'
1610
        stosd
1611
        mov     eax, 'ктор'
1612
        stosd
1613
        mov     eax, '    '
1614
        stosd
1615
        stosb
1616
else
1617
        mov     eax, 'Edit'
1618
        stosd
1619
        mov     eax, '    '
1620
        stosd
1621
        stosd
1622
        stosb
1623
end if
1624
viewedit_getname:
180 heavyiron 1625
        sub     ecx, 13
589 diamond 1626
        cmp     [ebp+viewer_data.hPlugin], 0
1627
        jz      .native
1628
        lea     esi, [ebp+viewer_data.hostname]
1629
        push    ecx edi
1630
        shr     ecx, 1
1631
@@:
1632
        lodsb
1633
        test    al, al
1634
        jz      @f
1635
        stosb
1636
        loop    @b
1637
@@:
1638
        sub     edi, [esp]
1639
        sub     [esp+4], edi
1640
        add     [esp], edi
1641
        pop     edi ecx
180 heavyiron 1642
        lea     esi, [ebp+viewer_data.filename]
589 diamond 1643
        jmp     .main
1644
.native:
1645
        lea     esi, [ebp+viewer_data.filename]
180 heavyiron 1646
        push    3
1647
        pop     edx
1648
@@:
1649
        lodsb
1650
        stosb
1651
        dec     ecx
589 diamond 1652
        test    al, al
1653
        jz      .ret
180 heavyiron 1654
        cmp     al, '/'
1655
        jnz     @b
1656
        dec     edx
1657
        jnz     @b
589 diamond 1658
.main:
180 heavyiron 1659
        push    esi
1660
@@:
1661
        lodsb
1662
        test    al, al
1663
        jnz     @b
1664
        sub     esi, [esp]
1665
        dec     esi
1666
        cmp     esi, ecx
1667
        jbe     @f
1668
        mov     al, '.'
1669
        stosb
1670
        stosb
1671
        stosb
1672
        sub     ecx, 3
1673
        sub     esi, ecx
1674
        add     [esp], esi
1675
@@:
1676
        pop     esi
1677
@@:
1678
        lodsb
1679
        stosb
1680
        test    al, al
1681
        jnz     @b
589 diamond 1682
.ret:
180 heavyiron 1683
        ret