Subversion Repositories Kolibri OS

Rev

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