-
Notifications
You must be signed in to change notification settings - Fork 5
/
DIRH.ASM
196 lines (157 loc) · 2.32 KB
/
DIRH.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
; *******************************************************
; * *
; * Turbo Pascal Run-time Library *
; * Directory Handling Routines *
; * *
; * Copyright (c) 1988,92 Borland International *
; * *
; *******************************************************
TITLE DIRH
INCLUDE SE.ASM
DATA SEGMENT WORD PUBLIC
; Externals
EXTRN InOutRes:WORD
DATA ENDS
IF WindowsVersion
; Windows entry points
EXTRN AnsiToOem:FAR,OemToAnsi:FAR
ENDIF
CODE SEGMENT BYTE PUBLIC
ASSUME CS:CODE,DS:DATA
; Publics
PUBLIC DirGet,DirSet,DirCreate,DirRemove
; GetDir standard procedure
DirGet:
ARG Drive,BYTE,2
ARG StrP,DWORD,1
ARG StrLen,WORD,1
LOC Path,BYTE,128
ENTRY FAR
PUSH DS
LEA SI,Path
PUSH SS
POP DS
MOV AL,Drive
OR AL,AL
JNZ @@1
MOV AH,dosGetDrive
INT DOS
INC AL
@@1: MOV DL,AL
ADD AL,'A'-1
MOV [SI],AL
INC SI
MOV WORD PTR [SI],'\:'
INC SI
INC SI
MOV AH,dosGetDir
INT DOS
JNC @@2
MOV BYTE PTR [SI],0
@@2: LEA SI,Path
IF WindowsVersion
PUSH DS
PUSH SI
PUSH DS
PUSH SI
CALL OemToAnsi
ENDIF
LES DI,StrP
MOV CX,StrLen
XOR BX,BX
CLD
@@3: LODSB
OR AL,AL
JE @@4
INC BX
MOV ES:[DI+BX],AL
LOOP @@3
@@4: MOV ES:[DI],BL
POP DS
EXIT
; ChDir standard procedure
DirSet:
ARG StrP,DWORD,1
LOC Path,BYTE,128
ENTRY FAR
CALL GetPath
MOV AX,Path.w0
OR AL,AL
JE @@3
CMP AH,':'
JNE @@2
AND AL,NOT ' '
SUB AL,'A'
MOV DL,AL
MOV AH,dosSetDrive
INT DOS
MOV AH,dosGetDrive
INT DOS
CMP AL,DL
JE @@1
MOV InOutRes,15
JMP SHORT @@3
@@1: CMP Path[2],0
JE @@3
@@2: MOV AH,dosSetDir
CALL DosPath
@@3: EXIT
; MkDir standard procedure
DirCreate:
ARG StrP,DWORD,1
LOC Path,BYTE,128
ENTRY FAR
CALL GetPath
MOV AH,dosCreateDir
CALL DosPath
EXIT
; RmDir standard procedure
DirRemove:
ARG StrP,DWORD,1
LOC Path,BYTE,128
ENTRY FAR
CALL GetPath
MOV AH,dosRemoveDir
CALL DosPath
EXIT
; Copy string to zero terminated path
GetPath:
PUSH DS
LDS SI,[BP+6]
LEA DI,[BP-128]
PUSH SS
POP ES
IF WindowsVersion
PUSH ES
PUSH DI
PUSH ES
PUSH DI
ENDIF
CLD
LODSB
CMP AL,127
JB @@1
MOV AL,127
@@1: CBW
MOV CX,AX
REP MOVSB
XOR AL,AL
STOSB
IF WindowsVersion
CALL AnsiToOem
ENDIF
POP DS
RET
; Do DOS function on path
DosPath:
PUSH DS
LEA DX,[BP-128]
PUSH SS
POP DS
INT DOS
POP DS
JNC @@1
MOV InOutRes,AX
@@1: RET
CODE ENDS
END