-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2-ZDIR.ASM
executable file
·1177 lines (972 loc) · 33.1 KB
/
2-ZDIR.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
; A86 +E 1-Zdir.asm 15-Zdir.asm 2-Zdir.asm # End-Zdir.asm TO Zdir.com
Illegal_table DB '."/\[]:|<>+=;,?*'
Length_illegal_table EQU $ - Illegal_table
;------------------------------------------------------------------------------
Put_char:
TEST AL
IF Z MOV AL," "
TEST Internal
JNZ Store
TEST Printer
JNZ >L1
Screen_char:
TEST Bios
JNZ >L0
Store:
STOSW
RET
L0: PUSH AX,BX,CX,DX
PUSH AX
MOV AX,DI
xor dx,dx
mov bx,row_bytes
div bx
SHR dl,1
mov dh,al
XOR BH,BH
MOV AH,2
INT 10h
POP AX
MOV BL,AH
XOR BH,BH
MOV AH,9
MOV CX,1
INT 10h
POP DX,CX,BX,AX
INC DI,Col
RET
Char_put DB ?
Prev_color DB 0
L1:
CALL Screen_Char
Printer_char:
PUSH AX,BX,CX,DX
TEST Print_graphics
JNZ >L2
CMP AL,Horizontal_line
IF E MOV AL,"-"
CMP AL,Vertical_line
IF E MOV AL,"|"
CMP AL,Intersection_up
IF E MOV AL,"+"
CMP AL,Intersection_down
IF E MOV AL,"+"
CMP AL,"Ä"
IF E MOV AL,"-"
CMP AL,"³"
IF E MOV AL,"|"
CMP AL,179
JB >L2
CMP AL,218
JA >L2
MOV AL,"+"
L2:
MOV BX,Printer_Handle
MOV CX,1
MOV DX,OFFSET Char_put
TEST ANSI_printer
JZ >L3
CMP AH,Prev_color
JE >L3
MOV Prev_color,AH
PUSH AX
CALL ANSI_Color
POP AX
MOV AH,40h
MOV Char_put,AL
INT 21h
JMP short End_print
L3:
MOV Char_put,AL
MOV AH,40h
INT 21h
End_print:
POP DX,CX,BX,AX
RET
Print_space:
PUSH AX
MOV AH,Empty_color
CMP Entry_one_color,0
IF NE MOV AH,Entry_color
MOV AL," "
CALL Put_Char
POP AX
RET
print_bar:
mov ah,graphics_color
mov al,vertical_line
cmp columns_left,1
if ne call put_char
ret
Change_attributes:
CMP b[FileName],'.'
JE end_change_attributes
MOV DI,OFFSET Full_path
ADD DI,Length_Full_path
MOV SI,OFFSET FileName
MOV CX,13
REP MOVSB
MOV AX,4300h
MOV DX,OFFSET Full_Path
INT 21h
TEST CL,Directory
JZ >L1
CMP Change_dir_attrib,0
JZ end_change_attributes
L1:
OR CL,New_on_attrib
AND CL,New_off_attrib
PUSH CX
CMP Change_dir_attrib,0
IF NE AND CL,NOT Directory
MOV AX,4301h
TEST AL,Directory
IF Z INT 21h
POP CX
IF NC MOV Attrib,CL
end_change_attributes:
CALL Fix_FileName
RET
Size_to_Clusters:
MOV BX,AX ;DX:AX has file size
MOV CX,Bytes_per_sector
DEC CX
NOT CX ;Fill CX w/1s above size
AND AX,CX ;Get out bottom stuff
CMP AX,BX
JE RET
ADD AX,Bytes_per_sector
adc dx,0 ;If overflow
RET
;------------------------------------------------------------------------------
Print_file_size:
; in: ch has color
cmp number_of_columns,1
je short print_size_non_abbrev
;---------
CMP DX,0Fh
JA short print_size_abbrev ;If 1 M +
JB print_size_non_abbrev
CMP AX,04240h
JB print_size_non_abbrev
print_size_abbrev:
cmp entry_one_color,0
if e mov ch,megabyte_size_color
AND Right_justify,0
push cx
mov cx,6
l1:
call div_10
loop l1
pop cx
; ax now has millions, bl has remainder of last div which
; is hundred thousands
cmp ax,1000
if ae call print_space
cmp ax,100
if b call print_space
cmp ax,10
if b call print_space
push ax,bx
call print_number
pop bx,ax
cmp ax,1000
jae print_size_m
mov ah,ch
MOV AL,"."
CALL Put_Char
mov al,bl
add al,"0"
call put_char
print_size_m:
mov ah,ch
mov al,"M"
call put_char
jmp ret
print_size_non_abbrev:
OR Right_justify,-1
CMP Number_of_columns,1
jne short check_allow_commas
print_size_and_ret:
CALL Print_Number
RET
check_allow_commas:
PUSH AX,BX,DX
MOV BX,10_000
DIV BX
CMP AX,10
POP DX,BX,AX
jb print_size_and_ret
MOV BL,Commas_in_numbers
PUSH BX
AND Commas_in_numbers,0 ; not enough room
; for commas if 100000
CALL Print_number
POP BX
MOV Commas_in_numbers,BL
RET
;------------------------------------------------------------------------------
Print_disk_info:
TEST Disk_totals
JZ >L1
CMP Disk_totals,Totals_AB_only
JNE RET
MOV BX,Path_spot
CMP b[BX],"A"
JE >L1
CMP b[BX],"B"
JNE RET
L1:
OR Internal,-1
MOV DI,OFFSET String_spot
MOV AX,w[Free_space]
MOV DX,w[Free_space+2]
MOV CH,totals_color
CALL Print_number
MOV SI,OFFSET Free_space_msg
MOV CX,Length_Free_space
MOV AH,Totals_msg_clr
CALL Print_string
MOV AX,w[Total_space]
MOV DX,w[Total_space+2]
MOV CH,totals_color
;AND Right_justify,0
CALL Print_number
MOV SI,OFFSET Total_space_msg
MOV CX,Length_Total_space
MOV AH,Totals_msg_clr
CALL Print_string
MOV SI,Path_spot
MOV CX,2
MOV AH,Totals_color
CALL Print_string
To_video ES
AND Internal,0
CALL Print_string_spot
mov ah,empty_color
call print_space
call scroll_up
RET
Clear_string_spot:
MOV AX,0 BY " "
MOV DI,OFFSET String_spot
MOV CX,80
REP STOSW
RET
Print_string:
L1: LODSB
CALL Put_char
LOOP L1
RET
Print_to_screen:
L1: LODSB
CALL Screen_char
LOOP L1
RET
Clr_Scr:
and bottom_row,0
TEST Bios
JNZ >L1
PUSH ES
To_video ES
XOR DI,DI
mov ax,row_bytes
mov dl,screen_rows
xor dh,dh
mul dx
mov cx,ax
MOV AH,Empty_color
MOV AL," "
REP STOSW
POP ES
RET
L1:
MOV AX,0600h
JMP Bios_do
Check_AL_file_char:
;Pre : AL = char to check
;Post: C if illegal char, NC if legal
PUSH CX,DI,ES
CMP AL,21h
JB Illegal_char
Restore ES
MOV DI,OFFSET Illegal_Table
MOV CX,Length_Illegal_Table
REPNE SCASB
JNE Legal_char
Illegal_char:
STC
JMP Exit_file_char
Legal_char:
CLC
Exit_file_char:
POP ES,DI,CX
RET
Check_AL_path_char:
CMP AL,":"
JE Ok_char
CMP AL,"\"
JE Ok_char
CMP AL,"."
JNE Check_AL_file_char
OK_char:
CLC
RET
Check_AL_any_char:
CMP AL,"*"
JE Ok_char
CMP AL,"?"
JE OK_char
JMP Check_AL_path_char
print_just_user_ext_str:
cmp number_of_files,0
jnz >l0
test num_user_extensions
jz ret
l0:
mov ah,just_user_ext_color
mov si,offset just_user_ext_str
mov di,offset string_spot
mov cx,len_just_user_ext_str
or internal,-1
call print_string
mov si,offset extension_data
mov cx,num_extensions
mov dx,len_just_user_ext_str
xor bx,bx
l1:
cmp b[si+4],user_ext
jne next_user_ext_check
test bx,bx
jz >l2
cmp dx,80-9
jae >l3
mov ah,just_user_ext_color
mov al,","
call put_char
mov al," "
call put_char
add dx,2
l2:
mov ah,b[si+3]
lodsb
call put_char
lodsb
call put_char
lodsb
call put_char
add dx,3
or bx,-1
sub si,3
next_user_ext_check:
add si,5
loop l1
jmp >l4
l3: mov al," "
mov ah,just_user_ext_color
call put_char
mov al,"."
call put_char
call put_char
call put_char
l4:
to_video es
and internal,0
call print_string_spot
call scroll_up
restore es
ret
check_if_ext:
; pre : filename has the filename
; post : carry set if not a user extension
push si,di
mov di,offset filename
mov al,"."
mov cx,9
repne scasb
mov si,offset extension_data
mov cx,num_extensions
each_ext_check:
cmp b[si+4],not_user_ext
je next_ext_check
call move_si_to_ext_check
push si,di
mov si,offset ext_check
call match
pop di,si
test al,al
jnz is_user_ext
next_ext_check:
add si,5
loop each_ext_check
; if here, didn't match any user ext
isnt_user_ext:
stc
jmp end_ext_if_check
is_user_ext:
clc
end_ext_if_check:
pop di,si
ret
;==============================================================================
move_si_to_ext_check:
push si,di
mov di,offset ext_check
lodsb
cmp al," "
if e xor al,al
stosb
lodsb
cmp al," "
if e xor al,al
stosb
lodsb
cmp al," "
if e xor al,al
stosb
pop di,si
ret
;==============================================================================
File_match:
;Pre : DS=ES:SI -> a file spec (w/ * or ?), DS=ES:DI -> a filename to match
;Post: AL = 0 if did NOT meet form of the spec
PUSH BX,CX,DX,SI,DI
MOV DX,SI
MOV BX,DI
MOV DI,SI
MOV CX,9;;;;;;;;;15 ; 9 is not long enough, for end-zdir*.*
L1:
INC DI
TEST b[DI-1]
JNE >L2
DEC DI
OR AL,-1 ; clear the zero flag so it'll NOT find the "."
JMP >L3
L2:
CMP b[DI-1],"."
LOOPNE L1
L3:
PUSHF
MOV w[Specextension],DI
MOV DI,OFFSET Tempspec
POPF
JNE >L2
; SI still at start
L1:
CMP CX,8 ; don't store .
JE >L4
MOVSB
INC CX
JMP L1
L2:
L3:
CMP b[SI],0
JE >L4
MOVSB
JMP L3
L4:
XOR AL,AL
STOSB
L6:
MOV SI,DI,BX
MOV CX,9
L1:
INC DI
TEST b[DI-1]
JNE >L2
DEC DI
OR AL,-1 ; clear the zero flag so it'll NOT find the "."
JMP >L3
L2:
CMP b[DI-1],"."
LOOPNE L1
L3:
PUSHF
MOV w[Stringextension],DI
MOV DI,OFFSET Tempstring
POPF
JNE >L2
L1:
CMP CX,8 ; don't store .
JE >L4
MOVSB
INC CX
JMP L1
L2:
L3:
CMP b[SI],0
JE >L4
MOVSB
JMP L3
L4:
XOR AL,AL
STOSB
MOV SI,OFFSET Tempspec
MOV DI,OFFSET Tempstring
CALL Match
TEST AL
JZ End_file_match
MOV SI,Specextension
MOV DI,Stringextension
CALL Match
End_file_match:
POP DI,SI,DX,BX,CX
RET
;==============================================================================
Match:
;Pre : DS:SI -> a string spec (w/ * or ?), ES:DI -> a string to match
;Post: AL = 0 if did NOT meet form of the spec
TEST b[SI]
JNZ >L1
TEST b[ES:DI]
JZ Do_match
JMP short Dont_match
L1:
TEST b[ES:DI]
JNZ >L3
CMP b[SI],"*"
JE >L2
CMP b[SI],"?"
JNE Dont_match
L2:
INC SI
JMP Match
L3:
CMP b[SI],"?"
JNE >L4
INC SI
PUSH SI,DI
CALL Match
POP DI,SI
TEST AL,AL
JNZ RET ; ? was replaced with nothing, ok
INC DI ; ? was replaced with char
JMP Match ; see if it is ok
L4:
CMP b[SI],"*"
JNE >L5
PUSH SI,DI
INC SI
CALL Match
POP DI,SI
TEST AL,AL
JNZ RET ; * was replaced with nothing, ok
PUSH SI,DI
INC SI
INC DI
CALL Match
POP DI,SI
TEST AL,AL
JNZ RET ; * was replaced with this char, ok
INC DI
JMP Match ; * not replaced, skip this char
L5:
MOV AL,b[SI]
CMP AL,"a"
JB >L6
CMP AL,"z"
JA >L6
AND AL,NOT 20h
L6:
PUSH AX
MOV AH,b[ES:DI]
CMP AH,"a"
JB >L7
CMP AH,"z"
JA >L7
AND AH,NOT 20h
L7:
CMP AL,AH
POP AX
JNE Dont_match
INC SI
INC DI
JMP Match
Do_match:
OR AL,-1
RET
Dont_match:
XOR AL,AL
RET
;==============================================================================
Fixup_file_spec:
; add *'s to the variable file_spec, general cleanup (repeat *?s, etc.)
MOV CX,Length_file_spec
MOV DI,OFFSET File_spec
TEST CX,CX
JNZ >L0
MOV SI,OFFSET Star_dot_star
JMP >L1
L0:
MOV AL,"."
REPNE SCASB
JNE >L05
CMP b[DI],0 ; in case dir ZDir asfdj.
JNE >L2
DEC DI
XOR AL,AL
STOSB
JMP >L5
L05:
MOV SI,OFFSET Star_dot_star
CMP b[DI-1],"*"
IF E INC SI
CMP b[DI-1],"?"
IF E INC SI
L1:
PUSH DI
MOV CX,4
REP MOVSB
TEST Put_star_in_front
JZ >L15
MOV DI,OFFSET File_spec + 24
MOV SI,OFFSET File_spec + 23
MOV CX,24 ; 24 max, not go past data
STD
REP MOVSB
CLD
MOV b[File_spec],"*"
L15:
POP DI
L2: ; fixup if too long
MOV CX,OFFSET File_spec
ADD CX,Length_file_spec
SUB CX,DI
CMP CX,3 ; if within 3 chars of end
JBE >L3 ; if so, then ok
PUSH DI
ADD DI,3 ; to cut off extra long extension
XOR AL,AL
STOSB
POP DI
L3:
CALL Remove_multiple_star
CALL Fixup_first_8
L5:
CALL Check_dot_ext
MOV DI,OFFSET File_spec
XOR AL,AL
MOV CX,13
REPNE SCASB
NEG CX
ADD CX,12 ; don't count the 0 at end
MOV Length_file_spec,CX
RET
Check_dot_ext:
CMP b[File_spec],"."
JNE RET
MOV SI,OFFSET File_spec
ADD SI,Length_file_spec
MOV DI,SI
INC DI
MOV CX,Length_file_spec
INC CX ; for the terminating 0
STD
REP MOVSB
CLD
MOV b[DI],"*"
RET
;==============================================================================
Fixup_first_8:
; Make the filename have only 8 chars, leaving in all file chars, then
; all wildcards that fit
PUSH CX,SI,DI
MOV CX,25 ; 20 max length, + 5 for *.* stuff
MOV DI,OFFSET File_spec
XOR AL,AL
REPNE SCASB
NEG CX
ADD CX,25
MOV SI,DI,OFFSET File_spec
JCXZ End_fixup_first_8
MOV AL,"."
REPNE SCASB
MOV CX,DI
SUB CX,SI
CMP CX,8
JBE End_fixup_first_8
PUSH DI
; now count how many NON wildcards, and keep first 8-(# nonwildcards)
; and trash the rest
MOV DX,CX ; for storage
XOR BX,BX
MOV SI,OFFSET File_spec
L1:
DEC CX
JCXZ >L2
LODSB
; count stuff
CMP AL,"?"
JE L1
CMP AL,"*"
JE L1
INC BX
JMP L1
L2: ; BX has # of nonwildcard chars
CMP BX,8
IF A MOV BX,8
NEG BX
ADD BX,8 ; has # of wildcards to keep
MOV SI,DI,OFFSET File_spec
MOV CX,DX
MOV DX,8 ; chars stored
L3:
TEST DX,DX
JZ Put_back_ext
LODSB
CMP AL,"?"
JE Check_store_file
CMP AL,"*"
JE Check_store_file
L4:
STOSB
DEC DX
JMP L3
Check_store_file:
TEST BX,BX
JZ L3
DEC BX
JMP L4
Put_back_ext:
POP DI
DEC DI ; to pick up the .
MOV SI,OFFSET File_spec + 8
XCHG SI,DI
MOV CX,5 ; .ext0 maxes at 5
REP MOVSB
End_fixup_first_8:
POP DI,SI,CX
RET
;==============================================================================
Remove_multiple_star:
; Replace all strings of (*'s and ?'s with at least one *) with just a single
; *
MOV SI,BX,DI,OFFSET File_spec
; SI keeps track of beginning of current searching string
; BX keeps track of current spot in current string
; DI keeps track of current writing spot
Check_each_char:
LODSB
TEST AL,AL
JZ End_remove_multiple_star
CMP AL,"*"
JE Check_wild_string
CMP AL,"?"
JE Check_wild_string
STOSB
JMP Check_each_char
Check_wild_string:
CALL Do_wild_string ; process the ***?*???
JMP Check_each_char ; and keep going
End_remove_multiple_star:
STOSB ; put in the 0 at the end
MOV DI,OFFSET File_spec
XOR AL,AL
MOV CX,25
REPNE SCASB
NEG CX
ADD CX,24 ; recalc'd cause we could
MOV Length_file_spec,CX ; have changed it
; don't count the 0 at end
RET
;------------------------------------------------------------------------------
Do_wild_string:
;Pre : SI-1 -> a string of *'s and ?'s
;Post: string either kept in (if all ?) or replaced with a *
DEC SI ; now points to string
MOV BX,SI ; store beginning of string
XOR CH,CH ; 0 means no * yet
L1:
LODSB
CMP AL,"*"
JNE >L2
OR CH,-1
JMP L1
L2: CMP AL,"?"
JE L1
TEST CH,CH ; check if any *'s in string
JZ >L3 ; nope, no *'s, so put back ?'s
MOV AL,"*"
STOSB
JMP End_do_wild_string
RET
L3:
MOV CX,SI ; current location
SUB CX,BX ; sub start location, has count of ?'s
DEC CX
MOV AL,"?"
REP STOSB ; write in as many ?'s as we found
End_do_wild_string:
DEC SI ; so points to the non-*? char
RET
;==============================================================================
High_path_spot EQU w[$]
Paths EQU w[$+2]
UnCrunch:
;
;Parameters Required:
; DS:SI ImageData source pointer.
; ES:DI Display address pointer.
; CX Length of ImageData source data.
;
PUSH SI ;Save registers.
PUSH DI
PUSH AX
PUSH CX
PUSH DX
MOV DX,DI ;Save X coordinate for later.
XOR AX,AX ;Set Current attributes.
LOOPA: LODSB ;Get next character.
CMP AL,27 ;Does user want to toggle the blink
JNE ForeGround ;attibute?
XOR AH,128 ;Done.
JMP short Next