unit MyCrt;
interface
Function KeyPressed : boolean;
Function ReadKey : Byte;
function ReadKeyEx:integer;
function Min(a,b:integer):integer;
function Max(a,b:integer):integer;
function IntToStr(i:integer):string;
function PointInRect(PX,PY,X1,Y1,X2,Y2:Integer):Boolean;
procedure Beep;
function FileExists(FileName: String): Boolean;
function HexToInt(HexStr:String):Longint;
function IntToHex(Int:Longint):string;
function StrToIntDef(Str:String;Def:Integer):Integer;
function HexToIntDef(HexStr:String;Def:Longint):longint;
implementation
Function ReadKey : Byte; Assembler;
asm
mov ah, 8
int 21h
end;
{funkcja rozrzerona
Lo - zwraca normalny kod litery
Hi - zwraca kod znaku specjalnego Lo := 0}
function ReadKeyEx:integer;assembler;
asm
mov ah, 0
int 16h
end;
Function KeyPressed : boolean;
begin
asm
MOV AH,1
INT 16H
jz @@1 {nie nacisniety}
mov @Result,1
Jmp @@2
@@1:mov @Result,0
@@2:
end;
end;
function Min(a,b:integer):integer;
begin
if A < b then
Min := a
else
Min := b;
end;
function Max(a,b:integer):integer;
begin
if A > b then
Max := a
else
Max := b;
end;
function IntToStr(i:integer):string;
var
S:string[30];
begin
Str(i,S);
IntToStr := s;
end;
function PointInRect(PX,PY,X1,Y1,X2,Y2:Integer):Boolean;
begin
PointInRect := (PX > X1) and (PX < X2) and (PY > Y1) and (PY < Y2);
end;
procedure Beep;
begin
{Sound(800);
Delay(50);
NoSound;}
end;
function FileExists(FileName: String): Boolean;
var
F: file;
begin
{$I-}
Assign(F, FileName);
FileMode := 0;
Reset(F);
Close(F);
{$I+}
FileExists := (IOResult = 0) and (FileName <> '');
end;
const
TabIntToHex :array[0..15] of Char = ('0','1','2','3','4','5',
'6','7','8','9','A','B','C','D','E','F');
function Power(x,y:Real):real;
begin
Power := Exp(y*Ln(x))
end;
function PowerHexToInt(Hex:Char;xPower:Byte):longint;
var
Int:longint;
begin
Int := 0;
case Hex of
'0': Int := 0;
'1': Int := 1;
'2': Int := 2;
'3': Int := 3;
'4': Int := 4;
'5': Int := 5;
'6': Int := 6;
'7': Int := 7;
'8': Int := 8;
'9': Int := 9;
'A','a': Int := 10;
'B','b': Int := 11;
'C','c': Int := 12;
'D','d': Int := 13;
'E','e': Int := 14;
'F','f': Int := 15;
end;
PowerHexToInt := int * Round(Power(16,xPower));{i tak tylko całkowite}
end;
function IntToHex(Int:longint):string;
var
R,C,Bad:longint;
RES:String;
begin
RES :='';
Bad:=int;
repeat
C := Bad div 16;
R := Bad mod 16;
RES := TabIntToHex[R]+res;
Bad := C;
until C < 16;
RES := TabIntToHex[C]+RES;
IntToHex := RES;
end;
function HexToInt(HexStr:String):longint;
const
MaxHex = 8;
var
I,Dlug:longint;
DN:array[1..MaxHex] of Char;
Buf:longint;
begin
HexToInt := 0;
Dlug := Length(HexStr);
if (Dlug = 0) or (Dlug > MaxHex) then Exit;
HexToInt := 0;
FillChar(DN,SizeOf(DN),'0');
for I := 9 - Dlug to MaxHex do
DN[I] := HexStr[ I - MaxHex + Dlug];
Buf := 0;
for I := 1 to MaxHex do{//Trik ???}
begin
Buf := Buf - PowerHexToInt(TabIntToHex[15 - PowerHexToInt(DN[I],0)],MaxHex - I);
end;
HexToInt := Buf - 1;
end;
function HexToIntDef(HexStr:String;Def:Longint):longint;
var
I:Integer;
Ex:Boolean;
begin
Ex := False;
for I := 1 to Length(HexStr) do
if not (HexStr[i] in ['0','1','2','3','4','5','6','7','8','9',
'A','B','C','D','E','F',
'a','b','c','d','e','f']) then
begin
Break;
Ex := True;
HexToIntDef := Def;
end;
if Ex then Exit;
HexToIntDef := HexToInt(HexStr);
end;
function StrToIntDef(Str:String;Def:Integer):Integer;
var
R,C:Integer;
begin
Val(Str,R,C);
if C <> 0 then
StrToIntDef := Def
else
StrToIntDef := R;
end;
end.