Authorization

{procedure UpString - author Victor Vagner}

unit UTILS;

interface

type Search_Rec=record
 Fill:array[1..21] of byte;
 Attr:byte;
 Time:longint;
 Size:longint;
 Name:string[12];
end;
type shortstring=string[12];

procedure UpString(var s:string);
function fileExists(Path:string):boolean;
function strCont(substr,find:string):boolean;
function extractFileName(path:string):shortstring;

implementation

procedure UpString(var s:string);assembler;
asm
PUSH DS
LDS BX,s
XOR CX,CX
MOV CL,[BX]
INC BX
MOV DX,BX
MOV AX,6521H
INT 21H
POP DS
end;

function fileExists(Path:String):boolean;assembler;
var fullmask:array[0..255] of char;
F:Search_Rec;
LABEL ERR,GOOD;
asm
PUSH DS
MOV AH,1AH
LEA DX,F
INT 21H
LDS SI,Path
LEA DI,fullmask
PUSH SS
POP ES
CLD
LODSB
CMP AL,255
JB @@1
MOV AL,255
@@1:
CBW
XCHG AX,CX
REP MOVSB
XOR AL,AL
STOSB
LEA DX,fullmask
PUSH ES
POP DS
MOV CX,3FH
MOV AH,4EH
INT 21H
JC ERR
MOV AL,1
JMP GOOD
ERR:
XOR AX,AX
GOOD:
POP DS
end;

function strCont(substr,find:string):boolean;assembler;
label RUN,ERR_END,GOOD;
asm
PUSH DS
LDS DI,find
XOR CH,CH
MOV CL,[DI]
LDS SI,substr
CLD
LODSB
SUB CL,AL
JB ERR_END
MOV AH,AL
MOV BX,SI
INC CX
INC DI
RUN:
LODSB
REPNE SCASB
JNE ERR_END
MOV DX,DI
MOV AL,CL
MOV CL,AH
DEC CX
REPE CMPSB
JE GOOD
MOV DI,DX
MOV CL,AL
MOV SI,BX
JMP RUN
ERR_END:
XOR AX,AX
GOOD:
POP DS
end;

function extractFileName(path:string):shortstring;assembler;
asm
PUSH DS
STD
LDS DI,path
XOR DX,DX
MOV DL,[DI]
LES DI,path
ADD DI,DX
MOV AX,'\'
MOV CX,DX
REPNZ SCASB
ADD DI,2
MOV SI,DI
LES DI,@Result
SUB DX,CX
MOV CX,DX
DEC CX
CLD
MOV AL,CL
STOSB
REP MOVSB
POP DS
end;

end.