home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Der Mediaplex Sampler - Die 6 von Plex
/
6_v_plex.zip
/
6_v_plex
/
DISK5
/
DOS_18
/
DATEX3.ZIP
/
UNIDAT.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-05-11
|
17KB
|
627 lines
unit unidat;
(********************************************************************)
(* Unit UniDat von A.Mehling *)
(* Version vom 10.04.1993 *)
(********************************************************************)
interface
uses dos;
type UType = (UShortInt,UByte,UWord,UInteger,ULongint,
UReal,USingle,UDouble,UExtended,UComp);
CType = (USI,UBY,UWO,UIN,ULO,UC,UG,US);
UniFile = record
Uf : file;
end;
UniInfo = record
Max : word;
XPack: CType;
YPack: CType;
Info : string;
end;
const UniComp : boolean = false;
UniOK = 0;
UniError = -1;
NoUniFile = -2;
NoUniMem = -3;
NoUniAss = -4;
UniInvRec = -5;
NoUniExist = -6;
UniTooSmall = -7;
UniResult : integer = UniError;
Procedure UniAssign (var Ufr:UniFile; Name:pathstr);
Function UniGetMax (var Ufr:UniFile):word;
Procedure UniGetInfo (var Ufr:UniFile; var Inf:UniInfo; Nr:word);
Procedure UniReWrite (var Ufr:UniFile; xp,yp:Pointer;
TMax:word; UID:string; T:UType);
Procedure UniAppend (var Ufr:UniFile; xp,yp:Pointer;
TMax:word; UID:string; T:UType);
Procedure UniRead (var Ufr:UniFile; var xp,yp:Pointer; Nr:word;
var TMax:word; T:UType);
implementation
Type PRec = record
O,S : word;
end;
UFMask = record
Handle : word;
Mode : word;
RecSize : word;
Private : array[1..26] of byte;
UserData : array[1..10] of byte;
Exist : boolean;
AssErr : integer;
MaxK : word;
NamStr : string[80];
end;
TUniDatHead = record
HSize : word;
HIdent : string[4];
Max : word;
HWModeX : CType;
HWModeY : CType;
X0,XS : extended;
Y0,YS : extended;
HInfo : string;
end;
const TSUShortint = SizeOf(ShortInt);
TSUByte = SizeOf(Byte);
TSUWord = SizeOf(Word);
TSUInteger = SizeOf(Integer);
TSULongint = SizeOf(Longint);
TSUReal = SizeOf(Real);
TSUSingle = SizeOf(Single);
TSUDouble = SizeOf(Double);
TSUExtended = SizeOf(Extended);
TSUComp = SizeOf(Comp);
TCS : array[CType] of Byte = (1,1,2,2,4,2,0,4);
TInt : set of UType = [UShortInt,UByte,UWord,UInteger,ULongint];
TSin : set of UType = [UReal,USingle,UDouble,UExtended,UComp];
UIdent = 'UniD';
Toll = 1e-4;
MaxWord = $FFFF;
MaxHSize = SizeOf(TUniDatHead);
var NewOne : boolean;
sAR : single;
iAR : array[1..2] of integer absolute sAR;
bAR : array[1..4] of byte absolute sAR;
Function TS(T:UType):byte;
begin
case T of
UShortint : TS := SizeOf(ShortInt);
UByte : TS := SizeOf(Byte);
UWord : TS := SizeOf(Word);
UInteger : TS := SizeOf(Integer);
ULongint : TS := SizeOf(Longint);
UReal : TS := SizeOf(Real);
USingle : TS := SizeOf(Single);
UDouble : TS := SizeOf(Double);
UExtended : TS := SizeOf(Extended);
UComp : TS := SizeOf(Comp);
end;
end;
Procedure Make_HSize(var Head:TUniDatHead);
begin
with Head do
begin
HIdent := UIdent;
HSize := (SizeOf(TUniDatHead)-$FF+Length(HInfo));
end;
end;
function exist(name:pathstr):boolean;
var probe:file;
w:word;
begin
assign(probe,name);
getfattr(probe,w);
if doserror=0 then exist:=true else exist:=false;
if w=$10 then exist:=false;
end;
Procedure ReadHead(var Ufr:UniFile; var Head:TUniDatHead);
var i : longint;
Rest : longint;
Result : word;
const S = SizeOf(word);
begin
With Ufr do
begin
UniResult:=NoUniFile;
with Head do
begin
BlockRead(Uf,HSize,S,result);
if Result<S then exit;
if HSize>MaxHSize then exit;
if HSize<S then exit;
BlockRead(Uf,HIdent,HSize-S,result);
if Result<(HSize-S) then exit;
if HIdent<>UIdent then exit;
end;
UniResult:=UniOK;
end;
end;
Procedure WriteHead(var Ufr:UniFile; var Head:TUniDatHead);
var Result:word;
begin
With Ufr do
begin
UniResult:=UniError;
BlockWrite(Uf,Head,Head.HSize,Result);
if Result<Head.HSize then exit;
UNiResult:=UniOK;
end;
end;
Function DSize(Head:TUniDatHead):longint;
var xsize,ysize : word;
begin
DSize:=0;
with Head do
begin
xsize:=TCS[HWModeX]*Max;
ysize:=TCS[HWModeY]*Max;
end;
DSize:=xsize+ysize;
end;
Function UniGetMax;
var MUf : UfMask absolute Ufr;
begin
UniGetMax:=MUf.MaxK;
end;
Procedure UniAssign;
var Head : TUniDatHead;
MUf : UfMask absolute Ufr;
Stop : boolean;
begin
With Ufr do
begin
UniResult:=UniOK;
assign(Uf,Name);
MUf.MaxK := 0;
MUf.Exist := exist(Name);
Stop:=false;
if MUf.Exist then
begin
reset(Uf,1);
repeat
ReadHead(Ufr,Head);
MUf.AssErr:=UniResult;
if UniResult<0 then Stop:=true;
if not Stop then
begin
inc(MUf.MaxK);
seek(Uf,FilePos(Uf)+DSize(Head));
end
else MUf.AssErr:=UniResult;
until eof(UF) or Stop;
close(Uf);
end
else
begin
UniResult:=NoUniExist;
MUf.AssErr := UniOK;
end;
end;
end;
Procedure UniGetInfo;
var Head : TUniDatHead;
HNr : word;
MUf : UfMask absolute Ufr;
begin
with Ufr do
begin
if MUf.Handle<5 then begin UniResult:=NoUniAss; exit end;
if not MUf.Exist then begin UniResult:=NoUniExist; exit end;
if Nr>MUf.MaxK then begin UniResult:=UniInvRec; exit end;
reset(Uf,1);
HNr:=0;
repeat
ReadHead(Ufr,Head);
if UniResult<0 then exit;
inc(HNr);
seek(Uf,FilePos(Uf)+DSize(Head));
until HNr=Nr;
close(Uf);
Inf.max := Head.max;
Inf.XPack := Head.HWModeX;
Inf.YPack := Head.HWModeY;
Inf.Info := Head.HInfo;
UniResult := UniOK;
end;
end;
Procedure ShortenPointer(var SP:Pointer);
var P : PRec absolute SP;
begin
P.S:=P.S+P.O div 16;
P.O:=P.O mod 16;
end;
Function E(k:Pointer; i:word; Typ:UType):extended;
var P : PRec absolute k;
PReal : ^Real absolute k;
PSingle : ^Single absolute k;
PDouble : ^Double absolute k;
PExtended : ^Extended absolute k;
PComp : ^Comp absolute k;
begin
inc(P.O,i*TS(Typ));
case Typ of
UReal : E := PReal^;
USingle : E := PSingle^;
UDouble : E := PDouble^;
UExtended : E := PExtended^;
UComp : E := PComp^;
else
RunError(99);
end;
end;
Function L(k:Pointer; i:word; Typ:UType):Longint;
var P : PRec absolute k;
PShortInt : ^ShortInt absolute k;
PByte : ^Byte absolute k;
PWord : ^Word absolute k;
PInteger : ^Integer absolute k;
PLongint : ^Longint absolute k;
begin
inc(P.O,i*TS(Typ));
case Typ of
UShortInt : L := PShortInt^;
UByte : L := PByte^;
UWord : L := PWord^;
UInteger : L := PInteger^;
ULongint : L := PLongint^;
else
RunError(99);
end;
end;
Procedure SetZ(k:Pointer; i:word; ZTyp:UType; QTyp:CType; Z:Pointer);
var P : PRec absolute k;
PReal : ^Real absolute k;
PSingle : ^Single absolute k;
PDouble : ^Double absolute k;
PExtended : ^Extended absolute k;
PComp : ^Comp absolute k;
PShortInt : ^ShortInt absolute k;
PByte : ^Byte absolute k;
PWord : ^Word absolute k;
PInteger : ^Integer absolute k;
PLongint : ^Longint absolute k;
XReal : ^Real absolute z;
XSingle : ^Single absolute z;
XDouble : ^Double absolute z;
XExtended : ^Extended absolute z;
XComp : ^Comp absolute z;
XShortInt : ^ShortInt absolute z;
XByte : ^Byte absolute z;
XWord : ^Word absolute z;
XInteger : ^Integer absolute z;
XLongint : ^Longint absolute z;
X : extended;
begin
inc(P.O,i*TS(ZTyp));
case QTyp of
USI : x := XShortInt^;
UBY : x := XByte^;
UWO : x := XWord^;
UIN : x := XInteger^;
ULO : x := XLongint^;
US : x := XSingle^;
else
RunError(99);
end;
case ZTyp of
UShortInt : PShortInt^ := round(x);
UByte : PByte^ := round(x);
UWord : PWord^ := round(x);
UInteger : PInteger^ := round(x);
ULongint : PLongint^ := round(x);
UReal : PReal^ := x;
USingle : PSingle^ := x;
UDouble : PDouble^ := x;
UExtended : PExtended^ := x;
UComp : PComp^ := x;
else
RunError(99);
end;
end;
Function Aequi(k:Pointer; max:word; var dx:single; T:UType):boolean;
var dx1,dx2,d : extended;
w : word;
begin
ShortenPointer(k);
d:=E(k,1,T)-E(k,0,T);
dx1:=(1-Toll)*d;
dx2:=(1+Toll)*d;
Aequi:=true;
for w:=2 to (max-1) do
begin
d:=abs(E(k,w,T)-E(k,w-1,T));
if (d<dx1) or (d>dx2) then begin Aequi:=false; exit end;
end;
dx:=(E(k,max-1,T)-E(k,0,T))/(max-1);
end;
Procedure UniWrite (var Ufr:UniFile; xp,yp:Pointer;
TMax:word; UID:string; T:UType);
var Head : TUniDatHead;
MUf : UfMask absolute Ufr;
XMin,XMax,YMin,YMax : extended;
w,c : word;
x,y : single;
UniCompX,UniCompY : boolean;
Tx : UType absolute T;
Ty : UType absolute T;
begin
UniCompX:=UniComp;
UniCompY:=UniComp;
UniResult:=MUf.AssErr; if UniResult<0 then exit;
UniResult:=UniError;
if TMax<2 then begin UniResult:=UniTooSmall; exit end;
ShortenPointer(xp);
ShortenPointer(yp);
with Head do
begin
max:=TMax;
HInfo:=UID;
if UniCompX
and (Tx in TSin) then begin
if Aequi(xp,Max,x,Tx) then begin
HWModeX:=UG;
X0:=E(xp,0,Tx);
XS:=x;
end
else begin
HWModeX:=UC;
XMin:=E(xp,0,Tx);
XMax:=XMin;
for w:=1 to (Max-1) do
begin
x:=E(xp,w,Tx);
if x<XMin then XMin:=x;
if x>XMax then XMax:=x;
end;
X0:=XMin;
XS:=(XMax-XMin)/MaxWord;
if XS=0 then XS:=1;
end;
end
else case Tx of
UShortint : HWModeX:=USI;
UByte : HWModeX:=UBY;
UWord : HWModeX:=UWO;
UInteger : HWModeX:=UIN;
ULongint : HWModeX:=ULO;
else HWModeX:=US;
end;
if UniCompY
and (Ty in TSin) then begin
if Aequi(yp,Max,y,Ty) then begin
HWModeY:=UG;
Y0:=E(yp,0,Ty);
YS:=y;
end
else begin
HWModeY:=UC;
YMin:=E(yp,0,Ty);
YMax:=YMin;
for w:=1 to (Max-1) do
begin
y:=E(yp,w,Ty);
if y<YMin then YMin:=y;
if y>YMax then YMax:=y;
end;
Y0:=YMin;
YS:=(YMax-YMin)/MaxWord;
if YS=0 then YS:=1;
end;
end
else case Ty of
UShortint : HWModeY:=USI;
UByte : HWModeY:=UBY;
UWord : HWModeY:=UWO;
UInteger : HWModeY:=UIN;
ULongint : HWModeY:=ULO;
else HWModeY:=US;
end;
end;
Make_HSize(Head);
With Ufr do
begin
if NewOne then rewrite(Uf,1)
else begin reset(Uf,1); seek(Uf,FileSize(Uf)) end;
WriteHead(Ufr,Head);
if UniResult<0 then exit;
MUf.Exist:=true;
inc(MUf.MaxK);
with Head do
begin
Case HWModeX of
UG : { Tue nichts };
UC : for w:=0 to Max-1 do
begin
c:=round((E(xp,w,Tx)-X0)/XS);
BlockWrite(Uf,c,2);
end;
USI,UBY,
UWO,UIN,
ULO : begin
c:=Max*TCS[HWModeX];
BlockWrite(Uf,xp^,c);
end;
US : for w:=0 to Max-1 do
begin
x:=E(xp,w,Tx);
BlockWrite(Uf,x,4);
end;
end;
Case HWModeY of
UG : { Tue nichts };
UC : for w:=0 to Max-1 do
begin
c:=round((E(yp,w,Ty)-Y0)/YS);
BlockWrite(Uf,c,2);
end;
USI,UBY,
UWO,UIN,
ULO : begin
c:=Max*TCS[HWModeY];
BlockWrite(Uf,yp^,c);
end;
US : for w:=0 to Max-1 do
begin
y:=E(yp,w,Ty);
BlockWrite(Uf,y,4);
end;
end;
end;
close(Uf);
UniResult:=UniOK;
end;
end;
Procedure UniRewrite;
begin
NewOne:=True;
UniWrite (Ufr,xp,yp,TMax,UID,T);
end;
Procedure UniAppend;
begin
NewOne:=false;
UniWrite (Ufr,xp,yp,TMax,UID,T);
end;
Procedure UniRead;
var Head : TUniDatHead;
HNr : word;
MUf : UfMask absolute Ufr;
w : word;
x,y : single;
dsi : Shortint;
dby : Byte;
dwo : Word;
din : Integer;
dlo : Longint;
ds : Single;
Tx : UType absolute T;
Ty : UType absolute T;
begin
UniResult:=MUf.AssErr; if UniResult<0 then exit;
UniResult:=UniError;
if not MUf.Exist then begin UniResult:=NoUniExist; exit end;
if Nr>MUf.MaxK then begin UniResult:=UniInvRec; exit end;
With Ufr do
begin
Reset(Uf,1);
HNr:=1;
ReadHead(Ufr,Head);
if UniResult<0 then exit;
while Nr>HNr do
begin
seek(Uf,FilePos(Uf)+DSize(Head));
ReadHead(Ufr,Head);
inc(HNr);
end;
with Head do
begin
if TMax<>Max then
begin
if TMax>0 then
begin
FreeMem(xp,TMax*TS(Tx));
FreeMem(yp,TMax*TS(Ty));
end;
UniResult:=NoUniMem;
if MaxAvail<(Max*TS(Tx)) then exit;
GetMem(xp,Max*TS(Tx));
if MaxAvail<(Max*TS(Ty)) then begin FreeMem(xp,Max*TS(Tx)); exit end;
GetMem(yp,Max*TS(Ty));
TMax:=Max;
end;
ShortenPointer(xp);
ShortenPointer(yp);
for w:=0 to Max-1 do
begin
Case HWModeX of
UG : begin
x:=X0+XS*w;
SetZ(xp,w,Tx,US,@x);
end;
UC : begin
BlockRead(Uf,dwo,2);
x:=X0+XS*dwo;
SetZ(xp,w,Tx,US,@x);
end;
USI,
UBY,
UWO,
UIN,
ULO,
US : begin
BlockRead(Uf,x,TCS[HWModeX]);
SetZ(xp,w,Tx,HWModeX,@x);
end;
end;
end;
for w:=0 to Max-1 do
begin
Case HWModeY of
UG : begin
y:=Y0+YS*w;
SetZ(yp,w,Ty,US,@y);
end;
UC : begin
BlockRead(Uf,dwo,2);
y:=Y0+YS*dwo;
SetZ(yp,w,Ty,US,@y);
end;
USI,
UBY,
UWO,
UIN,
ULO,
US : begin
BlockRead(Uf,y,TCS[HWModeY]);
SetZ(yp,w,Ty,HWModeY,@y);
end;
end;
end;
end;
UniResult:=UniOK;
Close(Uf);
end;
end;
end.