unit Controllers; interface const cctrlDataSignature='Controller Emulator'; type { tData=record Signature:string[50]; end; } tController=class private public constructor Create; destructor Destroy; override; procedure Init; virtual; abstract; function InB(Port:word):byte; virtual; abstract; procedure OutB(b:byte; Port:word); virtual; abstract; function ValidPort(Port:word; BasePort:word):boolean; virtual; abstract; function ValidReadPort(Port:word):boolean; virtual; abstract; function ValidWritePort(Port:word):boolean; virtual; abstract; function SetData(aData:Pointer):boolean; virtual; abstract; function GetData(aData:Pointer):boolean; virtual; abstract; function SubPath:string; virtual; abstract; function DataSize:cardinal; virtual; abstract; procedure ReadData; procedure WriteData; end; implementation uses // Classes, SysUtils, Emulator_Registry; //***************************************************************************** // t C o n t r o l l e r //***************************************************************************** //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- constructor tController.Create; begin Init; ReadData; end; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- destructor tController.Destroy; begin inherited; WriteData; end; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- procedure tController.ReadData; var pData:Pointer; Size:cardinal; begin if EmulatorRegistry.OpenRead(SubPath) then begin Size:=DataSize; try GetMem(pData, Size); except pData:=nil; end; if Assigned(pData) then begin try EmulatorRegistry.ReadBinaryData('Data', pData^, Size); SetData(pData); except end; FreeMem(pData, Size); end; EmulatorRegistry.CloseKey; end; end; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- procedure tController.WriteData; var pData:Pointer; Size:cardinal; begin if EmulatorRegistry.OpenWrite(SubPath) then begin Size:=DataSize; try GetMem(pData, Size); except pData:=nil; end; if Assigned(pData) then begin try if GetData(pData) then EmulatorRegistry.WriteBinaryData('Data', pData^, Size); except end; FreeMem(pData, Size); end; EmulatorRegistry.CloseKey; end; end; //----------------------------------------------------------------------------- end.