Subversion Repositories Kolibri OS

Rev

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