This repository has been archived by the owner on Apr 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
FC.ASM
1684 lines (1428 loc) · 63.5 KB
/
FC.ASM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
title File Compare Routine for MSDOS 2.0
;-----------------------------------------------------------------------;
; Revision History: ;
; ;
; V1.0 Rev. 0 10/27/82 M.A.Ulloa ;
; ;
; Rev. 1 10/28/82 M.A.Ulloa ;
; Changed switch names and added binary compare using the ;
; -b switch. ;
; ;
; Rev. 1 11/4/82 A.R. Reynolds ;
; Messages in separate module ;
; Also added header for MSVER ;
; ;
; Rev. 2 11/29/82 M.A. Ulloa ;
; Corrected sysntex problem with references to [base...] ;
; ;
; Rev. 3 01/03/83 M.A. Ulloa ;
; Stack is right size now. ;
; ;
;-----------------------------------------------------------------------;
FALSE equ 0
TRUE equ 0ffh
buf_size equ 4096 ;buffer size
;-----------------------------------------------------------------------;
; Description ;
; ;
; FC [-# -b -w -c] <file1> <file2> ;
; ;
; Options: ;
; ;
; -# were # is a number from 1 to 9, how many lines have to ;
; before the end of an area of difference ends. ;
; ;
; -b will force a binary comparation of both files. ;
; ;
; -w will cause all spaces and tabs to be compressed to a single ;
; space before comparing. All leading and trailing spaces and/or tabs ;
; in a line are ignored. ;
; ;
; -c will cause FC to ignore the case of the letters. ;
; ;
; Algorithm for text compare: (The one for binary comp. is trivial) ;
; ;
; The files are read into two separate buffers and the ;
; comparation starts. If two lines are found to be different in the ;
; two buffers, say line i of buffer A and line j of buffer B differ. ;
; The program will try to match line i with line j+1, then with line ;
; j+2 and so on, if the end of buffer is reached the program will ;
; recompact the buffer and try to read more lines into the buffer, if ;
; no more lines can be read because either the buffer is full, or the ;
; end of file was reached, then it will revert and try to match line ;
; j of buffer B to line i+1, i+2 and so on of buffer A. If an end of ;
; buffer is found, it tries to refill it as before. If no matches are ;
; found, then it will try to match line i+1 of buffer A to line j+1, ;
; j+2, j+3, .... of buffer B, if still no matches are found, it reverts ;
; again and tries to match line j+1 of buffer B with lines i+2, i+3,... ;
; of buffer A. And so on till a match is found. ;
; ;
; Once a match is found it continues chcking pairs of lines till ;
; the specified number are matched (option #, 3 by default), and then ;
; it prints the differing area in both files, each followed by the ;
; first line matched. ;
; ;
; If no match is found (the difference is bigger than the buffer) ;
; a "files different" message is printed. ;
; ;
; If one of the files finishes before another the remaining ;
; portion of the file (plus any ongoing difference) is printed out. ;
; ;
;-----------------------------------------------------------------------;
subttl Debug Macros
page
m_debug macro str
local a,b
jmp short b
a db str,0dh,0ah,"$"
b: pushf
push dx
mov dx,offset code:a
push ds
push cs
pop ds
push ax
mov ah,9h
int 21h
pop ax
pop ds
pop dx
popf
endm
m_bname macro
local a0,a1,a2,b1,b2
jmp short a0
b1 db "------ buffer 1",0dh,0ah,"$"
b2 db "------ buffer 2",0dh,0ah,"$"
a0: pushf
push dx
cmp bx,offset dg:buf1
je a1
mov dx,offset code:b2
jmp short a2
a1: mov dx,offset code:b1
a2: push ds
push cs
pop ds
push ax
mov ah,9h
int 21h
pop ax
pop ds
pop dx
popf
endm
page
.SALL
.XLIST
include dossym.asm
.LIST
subttl General Definitions
page
CR equ 0dh
LF equ 0ah
;-----------------------------------------------------------------------;
; Offsets to buffer structure
; For text comparations:
fname equ 0 ;file name ptr
fname_len equ 2 ;file name length
handle equ 4 ;handle
curr equ 6 ;current line ptr
lst_curr equ 8 ;last current line ptr
fst_sinc equ 10 ;first line towards a sinc ptr
fst_nosinc equ 12 ;first line out of sinc ptr
dat_end equ 14 ;ptr to last char of the buffer
buf_end equ 16 ;pointer to the end of the buffer
buf equ 18 ;pointer to the buffer
; For binary comparations:
by_read equ 6 ;bytes read into buffer
;-----------------------------------------------------------------------;
code segment word
code ends
const segment public word
const ends
data segment word
data ends
dg group code,const,data
subttl Constants Area
page
const segment public word
make db "MAUlloa/Microsoft/V10"
rev db "2"
;----- CAREFULL WITH PRESERVING THE ORDER OF THE TABLE -----
opt_tbl equ $ ;option table
flg_b db FALSE
flg_c db FALSE
flg_s db FALSE
flg_w db FALSE
;-----------------------------------------------------------
ib_first1 db FALSE ;flags used when comparing lines
ib_first2 db FALSE ; while in ignore white mode.
m_num dw 3 ;lines that have to match before
; reporting a match
mtch_cntr dw 0 ;matches towards a sinc
mode db FALSE ;If false then trying to match a line
; from buf1 to lines in buf2. If true
; then viceversa.
sinc db TRUE ;Sinc flag, start IN SINC
bend db 0 ;binary end of file flag, 0= none yet,
; 1= file 1 ended, 2= file 2 ended
base dd 0 ;base address of files for binary
; comparations
bhead_flg db false ;true if heading for binary comp.
; has been printed already.
;-----------------------------------------------------------
bp_buf equ $ ;binary compare difference template
bp_buf1 db 8 dup(' ') ;file address
db 3 dup(' ')
bp_buf2 db 2 dup(' ') ;byte of file 1
db 3 dup(' ')
bp_buf3 db 2 dup(' ') ;byte of file 1
db CR,LF
bp_buf_len equ $ - bp_buf ;length of template
;-----------------------------------------------------------
EXTRN vers_err:byte,opt_err:byte,opt_e:byte,crlf:byte,opt_err_len:byte
EXTRN bhead_len:byte
EXTRN found_err_pre:byte,found_err_pre_len:byte
EXTRN found_err_post:byte,found_err_post_len:byte
EXTRN read_err_pre:byte,read_err_pre_len:byte
EXTRN read_err_post:byte,read_err_post_len:byte
EXTRN file_err:byte,file_err_len:byte
EXTRN bf1ne:byte,bf1ne_len:byte,bf2ne:byte,bf2ne_len:byte,bhead:byte
EXTRN int_err:byte,int_err_len:byte,dif_err:byte,dif_err_len:byte
EXTRN args_err:byte,args_err_len:byte,fname_sep:byte,fname_sep_len:byte
EXTRN diff_sep:byte,diff_sep_len:byte
const ends
subttl Data Area
page
data segment word
com_buf db 128 dup(?) ;command line buffer
;----- Buffer structures
buf1 dw 11 dup(?)
buf2 dw 11 dup(?)
; two extra for guard in case of need to insert a CR,LF pair
b1 db buf_size dup(?)
end_b1 db 2 dup(?)
b2 db buf_size dup(?)
end_b2 db 2 dup(?)
data ends
subttl MAIN Routine
page
code segment
assume cs:dg,ds:nothing,es:nothing,ss:stack
start:
jmp short FCSTRT
;-----------------------------------------------------------------------;
; Check version number
HEADER DB "Vers 1.00"
FCSTRT:
;Code to print header
; PUSH DS
; push cs
; pop ds
; MOV DX,OFFSET DG:HEADER
; mov ah,std_con_string_output
; int 21h
; POP DS
mov ah,get_version
int 21h
cmp al,2
jge vers_ok
mov dx,offset dg:vers_err
mov ah,std_con_string_output
int 21h
push es ;bad vers, exit a la 1.x
xor ax,ax
push ax
badvex proc far
ret
badvex endp
vers_ok:
push cs
pop es
assume es:dg
;-----------------------------------------------------------------------;
; Copy command line
mov si,80h ;command line address
cld
lodsb ;get char count
mov cl,al
xor ch,ch
inc cx ;include the CR
mov di,offset dg:com_buf
cld
rep movsb
push cs
pop ds
assume ds:dg
;-----------------------------------------------------------------------;
; Initialize buffer structures
mov bx,offset dg:buf1
mov word ptr [bx].buf,offset dg:b1
mov word ptr [bx].buf_end,offset dg:end_b1
mov bx,offset dg:buf2
mov word ptr [bx].buf,offset dg:b2
mov word ptr [bx].buf_end,offset dg:end_b2
;-----------------------------------------------------------------------;
; Process options
mov ah,char_oper
mov al,0
int 21h ;get switch character
mov si,offset dg:com_buf
cont_opt:
call kill_bl
jc bad_args ;arguments missing
cmp al,dl ;switch character?
jne get_file ;no, process file names
cld
lodsb ;get option
call make_caps ;capitalize option
mov bx,offset dg:opt_tbl
cmp al,'B'
je b_opt
cmp al,'C'
je c_opt
cmp al,'S'
je s_opt
cmp al,'W'
je w_opt
cmp al,'1' ;a number option?
jb bad_opt
cmp al,'9'
ja bad_opt
and al,0fh ;a number option, convert to binary
xor ah,ah ;zero high nibble
mov [m_num],ax
jmp short cont_opt
bad_opt: ;a bad option:
push dx ; save switch character
mov [opt_e],al ; option in error
mov dx,offset dg:opt_err
mov cl,opt_err_len
call prt_err ; print error message
pop dx
jmp short cont_opt ; process rest of options
b_opt:
mov di,0
jmp short opt_dispatch
c_opt:
mov di,1
jmp short opt_dispatch
s_opt:
mov di,2
jmp short opt_dispatch
w_opt:
mov di,3
opt_dispatch:
mov byte ptr dg:[bx+di],TRUE ;set the corresponding flag
jmp short cont_opt
bad_args:
mov dx,offset dg:args_err
mov cl,args_err_len
jmp an_err
;-----------------------------------------------------------------------;
; Get the file names
get_file:
dec si ;adjust pointer
call find_nonb ;find first non blank in com. buffer
jc bad_args ;file (or files) missing
mov byte ptr [di],0 ;nul terminate
mov dx,si ;pointer to file name
mov bx,offset dg:buf1
mov word ptr [bx].fname,dx ;save pointer to file name
mov word ptr [bx].fname_len,cx ;file name length
mov ah,open
mov al,0 ;open for reading
int 21h
jc bad_file
mov word ptr [bx].handle,ax ;save the handle
mov si,di
inc si ;point past the nul
call kill_bl ;find other file name
jc bad_args ;a CR found: file name missing
dec si ;adjust pointer
call find_nonb
mov byte ptr [di],0 ;nul terminate the file name
mov dx,si
mov bx,offset dg:buf2
mov word ptr [bx].fname,dx ;save pointer to file name
mov word ptr [bx].fname_len,cx ;file name length
mov ah,open
mov al,0 ;open for reading
int 21h
jc bad_file
mov word ptr [bx].handle,ax ;save the handle
jmp short go_compare
bad_file:
cmp ax,error_file_not_found
je sj01
mov dx,offset dg:int_err
mov cl,int_err_len
jmp short an_err
sj01:
push cx ;save file name length
mov dx,offset dg:found_err_pre
mov cl,found_err_pre_len
call prt_err
pop cx
mov dx,si ;pointer to file name length
call prt_err
mov dx,offset dg:found_err_post
mov cl,found_err_post_len
an_err:
call prt_err
mov al,-1 ;return an error code
mov ah,exit
int 21h
;-----------------------------------------------------------------------;
; CHECK COMPARE MODE
go_compare:
cmp [flg_b],true ;do we do a binary comparation?
je bin_compare
jmp txt_compare
subttl Binary Compare Routine
page
;-----------------------------------------------------------------------;
; COMPARE BUFFERS IN BINARY MODE
bin_compare:
;----- Fill in the buffers
mov bx,offset dg:buf1 ;pointer to buffer structure
mov dx,word ptr[bx].buf ;pointer to buffer
mov si,dx ;save for latter comparation
call read_dat ;read into buffer
jc bad_datj ;an error
mov word ptr[bx].by_read,AX ;save ammount read
push ax ;save for now
mov bx,offset dg:buf2 ;pointer to buffer structure
mov dx,word ptr[bx].buf ;pointer to buffer
mov di,dx ;save for comparation
call read_dat ;read into buffer
bad_datj: jc bad_dat ;an error
mov word ptr[bx].by_read,AX ;save ammount read
pop cx ;restore byte count of buffer1
cmp ax,cx ;compare byte counts
ja morein_b2
jb morein_b1
or ax,ax ;the same ammount, is it 0?
jne go_bcomp ;no,compare
jmp go_quit ;yes, all done....
morein_b2:
mov [bend],1 ;file 1 ended
jmp short go_bcomp
morein_b1:
mov [bend],2 ;file 2 ended
mov cx,ax
;----- Compare data in buffers
go_bcomp:
mov ax,word ptr [base] ;load base addrs. to AX,BX pair
mov bx,word ptr [base+2]
add bx,cx ;add to base num. of bytes to
adc ax,0 ; compare.
mov word ptr [base],ax ;save total
mov word ptr [base+2],bx
next_bcomp:
cld
jcxz end_check
repz cmpsb ;compare both buffers
jz end_check ;all bytes match
push cx ;save count so far
push ax
push bx
inc cx
sub bx,cx ;get file address of bytes that
sbb ax,0 ; are different.
call prt_bdif ;print difference
pop bx
pop ax
pop cx ;restore on-going comparation count
jmp short next_bcomp
bnot_yet:
jmp bin_compare
end_check:
cmp [bend],0 ;have any file ended yet?
je bnot_yet ;no, read in more data
cmp [bend],1 ;yes, was it file 1?
je bf1_ended ;yes, data left in file 2
mov dx,offset dg:bf1ne
mov cl,bf1ne_len
jmp short bend_mes
bf1_ended:
mov dx,offset dg:bf2ne
mov cl,bf2ne_len
bend_mes:
xor ch,ch
call prout
jmp go_quit
subttl Text Compare Routine
page
;-----------------------------------------------------------------------;
; Fill in the buffers
bad_dat:
mov dx,offset dg:file_err
mov cl,file_err_len
jmp an_err
txt_compare:
mov bx,offset dg:buf1
mov dx,word ptr [bx].buf
mov word ptr [bx].fst_nosinc,dx
mov word ptr [bx].curr,dx
call fill_buffer
jc bad_dat
mov bx,offset dg:buf2
mov dx,word ptr [bx].buf
mov word ptr [bx].fst_nosinc,dx
mov word ptr [bx].curr,dx
call fill_buffer
jc bad_dat
;-----------------------------------------------------------------------;
; COMPARE BUFFERS IN TEXT MODE
another_line:
call go_match ;try to match both current lines
jc sj02 ;a match
jmp no_match ;no match, continue....
sj02:
cmp byte ptr[sinc],true ;are we in SINC?
je sj04
mov ax,[mtch_cntr]
or ax,ax ;first line of a possible SINC?
jnz sj03
mov bx,offset dg:buf1
mov word ptr [bx].fst_sinc,si ;yes, save curr line buffer 1
mov bx,offset dg:buf2
mov word ptr [bx].fst_sinc,di ;save curr line buffer 2
sj03:
inc ax ;increment match counter
mov [mtch_cntr],ax ;save number of matches
cmp m_num,ax ;enough lines matched for a SINC?
jne sj04 ;not yet, match some more
mov [sinc],true ;yes, flag we are now in sinc
call print_diff ;print mismatched lines
;-----------------------------------------------------------------------;
; Advance current line pointer in both buffers
sj04:
mov bx,offset dg:buf1
call adv_b
jnc sj05
jmp no_more1
sj05:
mov word ptr[bx].curr,si
mov bx,offset dg:buf2
call adv_b
jnc sj051
jmp no_more2
sj051:
mov word ptr[bx].curr,si
jmp another_line ;continue matching
;-----------------------------------------------------------------------;
; Process a mismatch
no_match:
cmp [sinc],true ;are we in SINC?
jne sj06
mov [sinc],false ;not any more....
mov bx,offset dg:buf1
mov word ptr [bx].fst_nosinc,si ;save current lines
mov word ptr [bx].lst_curr,si
mov bx,offset dg:buf2
mov word ptr [bx].fst_nosinc,di
mov word ptr [bx].lst_curr,di
sj06:
mov [mtch_cntr],0 ;reset match counter
cmp [mode],true
je sj09
;----- MODE A -----
mov bx,offset dg:buf2
call adv_b ;get next line in buffer (or file)
jc sj08 ;no more lines in buffer
sj07:
mov word ptr [bx].curr,si
jmp another_line
sj08:
mov [mode],true ;change mode
mov si,word ptr [bx].lst_curr
mov word ptr [bx].curr,si
mov bx,offset dg:buf1
mov si,word ptr [bx].lst_curr
mov word ptr [bx].curr,si
call adv_b ;get next line
jc no_more1 ;no more lines fit in buffer 1
mov word ptr [bx].lst_curr,si
jmp short sj10
;----- MODE B -----
sj09:
mov bx,offset dg:buf1
call adv_b ;get next line in buffer (or file)
jc sj11 ;no more lines in buffer
sj10:
mov word ptr [bx].curr,si
jmp another_line
sj11:
mov [mode],false
mov si,word ptr [bx].lst_curr
mov word ptr [bx].curr,si
mov bx,offset dg:buf2
mov si,word ptr [bx].lst_curr
mov word ptr [bx].curr,si
call adv_b ;get next line
jc no_more2 ;no more lines fit in buffer 2
mov word ptr [bx].lst_curr,si
jmp sj07
;-----------------------------------------------------------------------;
; Process end of files
no_more1:
cmp ax,0 ;end of file reached?
jz xj1
jmp dif_files ;no, difference was too big
xj1:
cmp [sinc],true ;file1 ended, are we in SINC?
je xj3
jmp no_sinc
xj3:
mov bx,offset dg:buf2
call adv_b ;advance current line in buf2
jnc xj5
jmp go_quit ;file2 ended too, terminate prog.
xj5:
;----- File 1 ended but NOT file 2
mov bx,offset dg:buf1
call print_head
mov bx,offset dg:buf2
call print_head
call print_all ;print the rest of file2
jmp go_quit
no_more2:
cmp ax,0 ;end of file reached?
jz xj2
jmp dif_files ;no, difference was too big
xj2:
cmp [sinc],true ;file1 ended, are we in SINC?
je xj4
jmp no_sinc
xj4:
mov bx,offset dg:buf1
call adv_b ;advance current line in buf2
jnc xj6
jmp go_quit ;file2 ended too, terminate prog.
xj6:
;----- File 2 ended but NOT file 1
mov bx,offset dg:buf1
call print_head
call print_all ;print the rest of file1
mov bx,offset dg:buf2
call print_head
jmp go_quit
no_sinc:
mov bx,offset dg:buf1
call print_head
call print_all
mov bx,offset dg:buf2
call print_head
call print_all
jmp go_quit
dif_files:
mov dx,offset dg:dif_err
mov cl,dif_err_len
jmp an_err
go_quit:
mov al,0
mov ah,exit
int 21h
subttl Subroutines: make caps
page
;-----------------------------------------------------------------------;
; CAPIALIZES THE CHARACTER IN AL ;
; ;
; entry: ;
; AL has the character to Capitalize ;
; ;
; exit: ;
; AL has the capitalized character ;
; ;
; Called from MAIN and go_match ;
;-----------------------------------------------------------------------;
make_caps:
cmp al,'a'
jb sa1
cmp al,'z'
jg sa1
and al,0dfh
sa1: ret
subttl Subroutines: kill_bl
page
;-----------------------------------------------------------------------;
; Get rid of blanks in command line. ;
; ;
; entry: ;
; SI points to the first character on the line to scan. ;
; ;
; exit: ;
; SI points to the next char after the first non-blank ;
; char found. ;
; Carry Set if a CR found ;
; ;
; modifies: ;
; SI and AX ;
; ;
; Called from MAIN ;
;-----------------------------------------------------------------------;
kill_bl:
cld ;increment
sb1: lodsb ;get rid of blanks
cmp al,' '
je sb1
cmp al,9
je sb1
cmp al,CR
clc ;assume not a CR
jne sb2
stc ;a CR found, set carry
sb2: ret
subttl Subroutines: find_nonb
page
;-----------------------------------------------------------------------;
; Find the first non-blank in a line ;
; ;
; entry: ;
; SI points to the line buffer ;
; ;
; exit: ;
; DI pointer to the first blank found (incl. CR) ;
; CX character count of non-blanks ;
; Carry Set if a CR was found ;
; ;
; modifies: ;
; AX ;
; ;
; Called from MAIN ;
;-----------------------------------------------------------------------;
find_nonb:
push si ;save pointer
xor cx,cx ;zero character count
cld
sc1:
lodsb
cmp al,' '
je sc2
cmp al,9
je sc2
cmp al,CR
je sc2
inc cx ;inc character count
jmp short sc1
sc2:
dec si
mov di,si
pop si
cmp al,CR
jne sc3
stc
ret
sc3:
clc
ret
subttl Subroutines: prt_bdif
page
;-----------------------------------------------------------------------;
; Print a binary difference ;
; ;
; entry: ;
; AX,BX file address of diference ;
; SI pointer to one past byte in buffer1 ;
; DI pointer to one past byte in buffer2 ;
; ;
; modifies: ;
; AX, DX and CX ;
; ;
; called from bin_compare ;
;-----------------------------------------------------------------------;
prt_bdif:
cmp [bhead_flg],true ;have we peinted head yet?
je bhead_ok
mov [bhead_flg],true ;no, set flag
push ax ;print heading
mov dx,offset dg:bhead
mov cl,bhead_len
xor ch,ch
call prout
pop ax
bhead_ok:
mov dx,di ;conver file address
mov di,offset dg:bp_buf1
push ax
mov al,ah
call bin2hex
pop ax
call bin2hex
mov al,bh
call bin2hex
mov al,bl
call bin2hex
mov di,offset dg:bp_buf2 ;convert byte from file 1
mov al, byte ptr[si-1]
call bin2hex
mov di,offset dg:bp_buf3 ;convert byte from file 2
push si
mov si,dx
mov al, byte ptr[si-1]
pop si
call bin2hex
mov di,dx ;print result
mov dx,offset dg:bp_buf
mov cx,bp_buf_len
call prout
ret
subttl Subroutines: bin2hex
page
;-----------------------------------------------------------------------;
; Binary to ASCII hex conversion ;
; ;
; entry: ;
; AL byte to convert ;
; DI pointer to were the two result ASCII bytes should go ;
; ;
; exit: ;
; DI points to one past were the last result byte whent ;
; ;
; modifies: ;
; AH and CL ;
; ;
; Called from prt_bdif ;
;-----------------------------------------------------------------------;
bin2hex:
mov cl,4
ror ax,cl ;get the high nibble
and al,0fh ;mask of high nible
call pt_hex
rol ax,cl ;get the low nibble
and al,0fh ;mask....
pt_hex:
cmp al,0ah ;is it past an A ?
jae pasta
add al,30h
jmp short put_hex
pasta:
add al,37h
put_hex:
stosb ;place in buffer
ret
subttl Subroutines: go_match
page
;-----------------------------------------------------------------------;
; Match current lines ;
; ;
; exit: ;
; Carry set if the match reset otherwise ;
; SI Current line of buff1 ;
; DI Current line of buff2 ;
; ;
; ;
; modifies: ;
; AX,BX,CX,DX and BP ;
; ;
; Called from txt_compare ;
;-----------------------------------------------------------------------;
go_match: