Unit Exec;

Interface
Type
  ULongInt = LongInt;
  pByte = ^Byte;
  ppByte = ^pByte;
  pInteger = ^Integer;
  ppInteger = ^pInteger;
  pLongInt = ^LongInt;
  ppLongInt = ^pLongInt;
  pShortInt = ^ShortInt;
  ppShortInt = ^pShortInt;
  pppShortInt = ^ppShortInt;
  pULongInt = ^ULongInt;
  pWord = ^Word;
  pPointer = ^Pointer;
  pSingle = ^Single;
  pReal = ^Real;
  CString = Packed Array [0..255] of Char;
  pCString = ^CString;

Procedure PasToC (p: String; Var c: CString);
Procedure CToPas (Var c; var p);
Function BitMask (no: ShortInt): LongInt;


Type
  pNode = ^tNode;
  tNode = Record
		  ln_Succ: pNode;
		  ln_Pred: pNode;
		  ln_Type: ShortInt;
		  ln_Pri: ShortInt;
		  ln_Name: pShortInt;
		End;

  pMsgPort = ^tMsgPort;
  tMessage = Record
		  mn_Node: tNode;
		  mn_ReplyPort: pMsgPort;
		  mn_Length: Integer;
		End;

  tList = Record
		  lh_Head: pNode;
		  lh_Tail: pNode;
		  lh_TailPred: pNode;
		  lh_Type: ShortInt;
		  l_pad: ShortInt;
		End;

  tMemEntry = Record
		Case Integer of
		0: (
		  meu_Reqs: LongInt;
		);
		1: (
		  meu_Addr: Pointer;
		  me_Length: LongInt;
		);
		End;

  pTask = ^tTask;
  tMsgPort = Record
		  mp_Node: tNode;
		  mp_Flags: ShortInt;
		  mp_SigBit: ShortInt;
		  mp_SigTask: pTask;
		  mp_MsgList: tList;
		End;

  tSoftIntList = Record
		  sh_List: tList;
		  sh_Pad: Integer;
		End;

  tUnit = Record
		  unit_MsgPort: tMsgPort;
		  unit_flags: ShortInt;
		  unit_pad: ShortInt;
		  unit_OpenCnt: Integer;
		End;

  tIntVector = Record
		  iv_Data: Pointer;
		  iv_Code: Pointer;
		  iv_Node: pNode;
		End;

  tLibrary = Record
		  lib_Node: tNode;
		  lib_Flags: ShortInt;
		  lib_pad: ShortInt;
		  lib_NegSize: Integer;
		  lib_PosSize: Integer;
		  lib_Version: Integer;
		  lib_Revision: Integer;
		  lib_IdString: Pointer;
		  lib_Sum: LongInt;
		  lib_OpenCnt: Integer;
		End;

  pResident = ^tResident;
  tResident = Record
		  rt_MatchWord: Integer;
		  rt_MatchTag: pResident;
		  rt_EndSkip: Pointer;
		  rt_Flags: ShortInt;
		  rt_Version: ShortInt;
		  rt_Type: ShortInt;
		  rt_Pri: ShortInt;
		  rt_Name: pShortInt;
		  rt_IdString: pShortInt;
		  rt_Init: Pointer;
		End;

  tSemaphore = Record
		  sm_MsgPort: tMsgPort;
		  sm_Bids: Integer;
		End;

  pMinNode = ^tMinNode;
  tMinList = Record
		  mlh_Head: pMinNode;
		  mlh_Tail: pMinNode;
		  mlh_TailPred: pMinNode;
		End;

  tMinNode = Record
		  mln_Succ: pMinNode;
		  mln_Pred: pMinNode;
		End;

  tSemaphoreRequest = Record
		  sr_Link: tMinNode;
		  sr_Waiter: pTask;
		End;

  tSignalSemaphore = Record
		  ss_Link: tNode;
		  ss_NestCount: Integer;
		  ss_WaitQueue: tMinList;
		  ss_MultipleLink: tSemaphoreRequest;
		  ss_Owner: pTask;
		  ss_QueueCount: Integer;
		End;

  pDevice = ^tDevice;
  pUnit = ^tUnit;
  tIOStdReq = Record
		  io_Message: tMessage;
		  io_Device: pDevice;
		  io_Unit: pUnit;
		  io_Command: Integer;
		  io_Flags: ShortInt;
		  io_Error: ShortInt;
		  io_Actual: LongInt;
		  io_Length: LongInt;
		  io_Data: Pointer;
		  io_Offset: LongInt;
		End;

  pIntVector = ^tIntVector;
  pSoftIntList = ^tSoftIntList;
  tExecBase = Record
		  LibNode: tLibrary;
		  SoftVer: Integer;
		  LowMemChkSum: Integer;
		  ChkBase: LongInt;
		  ColdCapture: Pointer;
		  CoolCapture: Pointer;
		  WarmCapture: Pointer;
		  SysStkUpper: Pointer;
		  SysStkLower: Pointer;
		  MaxLocMem: LongInt;
		  DebugEntry: Pointer;
		  DebugData: Pointer;
		  AlertData: Pointer;
		  MaxExtMem: Pointer;
		  ChkSum: Integer;
		  IntVects: Array [0..15] of tIntVector;
		  ThisTask: pTask;
		  IdleCount: LongInt;
		  DispCount: LongInt;
		  Quantum: Integer;
		  Elapsed: Integer;
		  SysFlags: Integer;
		  IDNestCnt: ShortInt;
		  TDNestCnt: ShortInt;
		  AttnFlags: Integer;
		  AttnResched: Integer;
		  ResModules: Pointer;
		  TaskTrapCode: Pointer;
		  TaskExceptCode: Pointer;
		  TaskExitCode: Pointer;
		  TaskSigAlloc: LongInt;
		  TaskTrapAlloc: Integer;
		  MemList: tList;
		  ResourceList: tList;
		  DeviceList: tList;
		  IntrList: tList;
		  LibList: tList;
		  PortList: tList;
		  TaskReady: tList;
		  TaskWait: tList;
		  SoftInts: Array [0..4] of tSoftIntList;
		  LastAlert: Array [0..3] of LongInt;
		  VBlankFrequency: ShortInt;
		  PowerSupplyFrequency: ShortInt;
		  SemaphoreList: tList;
		  KickMemPtr: Pointer;
		  KickTagPtr: Pointer;
		  KickCheckSum: Pointer;
		  ExecBaseReserved: Array [0..9] of ShortInt;
		  ExecBaseNewReserved: Array [0..19] of ShortInt;
		End;

  tInterrupt = Record
		  is_Node: tNode;
		  is_Data: Pointer;
		  is_Code: Pointer;
		End;

  pMemChunk = ^tMemChunk;
  tMemHeader = Record
		  mh_Node: tNode;
		  mh_Attributes: Integer;
		  mh_First: pMemChunk;
		  mh_Lower: Pointer;
		  mh_Upper: Pointer;
		  mh_Free: LongInt;
		End;

  tMemChunk = Record
		  mc_Next: pMemChunk;
		  mc_Bytes: LongInt;
		End;

  tDevice = Record
		  dd_Library: tLibrary;
		End;

  tIORequest = Record
		  io_Message: tMessage;
		  io_Device: pDevice;
		  io_Unit: pUnit;
		  io_Command: Integer;
		  io_Flags: ShortInt;
		  io_Error: ShortInt;
		End;

  pMemEntry = ^tMemEntry;
  tMemList = Record
		  ml_Node: tNode;
		  ml_NumEntries: Integer;
		End;

  tTask = Record
		  tc_Node: tNode;
		  tc_Flags: ShortInt;
		  tc_State: ShortInt;
		  tc_IDNestCnt: ShortInt;
		  tc_TDNestCnt: ShortInt;
		  tc_SigAlloc: LongInt;
		  tc_SigWait: LongInt;
		  tc_SigRecvd: LongInt;
		  tc_SigExcept: LongInt;
		  tc_TrapAlloc: Integer;
		  tc_TrapAble: Integer;
		  tc_ExceptData: Pointer;
		  tc_ExceptCode: Pointer;
		  tc_TrapData: Pointer;
		  tc_TrapCode: Pointer;
		  tc_SPReg: Pointer;
		  tc_SPLower: Pointer;
		  tc_SPUpper: Pointer;
		  tc_Switch: Pointer;
		  tc_Launch: Pointer;
		  tc_MemEntry: tList;
		  tc_UserData: Pointer;
		End;

  LONG = LongInt;
  LONGBITS = LongInt;
  BYTE = ShortInt;
  BYTEBITS = ShortInt;
  APTR = Pointer;
  CPTR = LongInt;
  WORD = Integer;
  WORDBITS = Integer;
  DOUBLE = Real;
  FLOAT = Single;
  UCOUNT = Integer;
  USHORT = Integer;
  ULONG = LongInt;
  UBYTE = ShortInt;
  COUNT = Integer;
  STRPTR = pShortInt;
  SHORT = Integer;
  UWORD = Integer;
  BOOL = Boolean;
  pLibrary = ^tLibrary;
  pMessage = ^tMessage;
  pSignalSemaphore = ^tSignalSemaphore;
  pMemList = ^tMemList;
  pInterrupt = ^tInterrupt;
  pList = ^tList;
  pIORequest = ^tIORequest;
  pSemaphore = ^tSemaphore;
  pMemHeader = ^tMemHeader;


Const
  NT_SOFTINT = $B;
  AN_FreeVec = $7000005;
  AN_IconLib = $9000000;
  BYTEMASK = $FF;
  TS_RUN = $2;
  AO_IconLib = $8009;
  AN_MathLib = $5000000;
  AN_TMBadSupply = $15000002;
  AG_OpenLib = $30000;
  AO_MathLib = $8005;
  AN_BitMap = $7000007;
  TB_SWITCH = $6;
  AN_BadState = $8400000C;
  NT_MSGPORT = $4;
  AN_InitAPtr = $81000007;
  AN_TrackDiskDev = $14000000;
  TF_SWITCH = $40;
  AO_TrackDiskDev = $8014;
  NT_UNKNOWN = $0;
  MEMF_LARGEST = $140000;
  LIB_RESERVED = $4;
  SF_ALERTWACK = $2;
  RTF_COLDSTART = $1;
  LIB_OPEN = $FFFFFFFA;
  AG_OpenDev = $40000;
  AN_EndTask = $7000002;
  AN_GamePortDev = $12000000;
  NULL = $0;
  TS_EXCEPT = $5;
  SIGB_DOS = $8;
  AO_GamePortDev = $8012;
  AN_KeyFree = $7000008;
  AN_PlaneAlloc = $84010005;
  AN_AudioDev = $10000000;
  AO_AudioDev = $8010;
  LIBF_SUMMING = $1;
  SIGF_DOS = $100;
  AG_NoSignal = $70000;
  AN_MakeVPort = $82010030;
  TRUE_ = $1;
  AN_ItemAlloc = $4010003;
  AN_SubAlloc = $4010004;
  AN_WeirdEcho = $8400000E;
  INTB_NMI = $F;
  CMD_INVALID = $0;
  IOERR_BADLENGTH = $FFFFFFFC;
  AN_LongFrame = $82010006;
  AN_KeyRange = $700000B;
  AN_BadExpansionFree = $A000001;
  DEV_BEGINIO = $FFFFFFE2;
  UNITF_ACTIVE = $1;
  LIBF_SUMUSED = $4;
  AN_FreeTwice = $81000009;
  AN_GraphicsLib = $2000000;
  INTF_NMI = $50000;
  LIB_VECTSIZE = $6;
  LIBF_DELEXP = $8;
  AG_OpenRes = $50000;
  AO_GraphicsLib = $8002;
  NT_MEMORY = $A;
  NT_SIGNALSEM = $F;
  NT_SEMAPHORE = $E;
  TB_STACKCHK = $4;
  AN_LayersNoMem = $83010000;
  RTW_NEVER = $0;
  RTW_COLDSTART = $1;
  MEMF_PUBLIC = $1;
  CMD_STOP = $6;
  AN_BadOverlay = $700000C;
  LIB_USERDEF = $FFFFFFE2;
  AN_TimerDev = $15000000;
  TF_STACKCHK = $10;
  TS_READY = $3;
  AO_TimerDev = $8015;
  AN_IntrMem = $81000006;
  AN_ItemBoxTop = $84000006;
  AN_KeyboardDev = $13000000;
  SIGB_SINGLE = $4;
  AO_KeyboardDev = $8013;
  AN_LayersLib = $3000000;
  AO_LayersLib = $8003;
  AN_GfxNoLCM = $82011234;
  AN_GadgetType = $84000001;
  AN_DiskRsrc = $21000000;
  SIGF_SINGLE = $10;
  UNITF_INTASK = $2;
  AO_DiskRsrc = $8021;
  AN_RAMLib = $8000000;
  AN_MiscRsrc = $22000000;
  AN_DiskCopy = $32000000;
  AO_RAMLib = $8008;
  AO_MiscRsrc = $8022;
  AN_OpenScreen = $84010007;
  AN_ConsoleDev = $11000000;
  SIGB_CHILD = $1;
  AO_ConsoleDev = $8011;
  DEV_ABORTIO = $FFFFFFDC;
  RTM_WHEN = $3;
  AN_NoConsole = $8400000F;
  MEMF_CLEAR = $A0000;
  AN_DOSLib = $7000000;
  SIGF_CHILD = $2;
  IOERR_NOCMD = $FFFFFFFD;
  AO_DOSLib = $8007;
  AN_StartMem = $7010001;
  AN_AsyncPkt = $7000004;
  LIB_EXPUNGE = $FFFFFFEE;
  AN_OpenScrnRast = $84010008;
  LIB_EXTFUNC = $FFFFFFE8;
  AG_NoMemory = $10000;
  AN_CreatePort = $84010002;
  RTF_AUTOINIT = $80;
  AN_DiskError = $700000A;
  SYSBASESIZE = $24C;
  AN_ExcptVect = $81000001;
  AN_ShortFrame = $82010007;
  AN_TDCalibSeek = $14000001;
  AN_CIARsrc = $20000000;
  AN_DRIntNoAct = $21000002;
  AFB_68010 = $0;
  AO_CIARsrc = $8020;
  AN_TextTmpRas = $2010009;
  AFB_68020 = $1;
  TB_PROCTIME = $0;
  AN_AddSWGadget = $8401000A;
  AN_TMBadReq = $15000001;
  SIH_PRIMASK = $F0;
  AFF_68010 = $1;
  NT_BOOTNODE = $10;
  CMD_UPDATE = $4;
  AFF_68020 = $2;
  AFB_RESERVED8 = $8;
  TF_PROCTIME = $1;
  AFB_RESERVED9 = $9;
  AN_ExpansionLib = $A000000;
  AO_ExpansionLib = $800A;
  AN_BootStrap = $30000000;
  AN_BootError = $30000001;
  AO_BootStrap = $8030;
  AN_BogusExcpt = $8100000A;
  SIGB_ABORT = $0;
  AN_DRHasDisk = $21000001;
  AN_Workbench = $31000000;
  NT_TASK = $1;
  AO_Workbench = $8031;
  FALSE_ = $0;
  CMD_CLEAR = $5;
  IOERR_OPENFAIL = $FFFFFFFF;
  AN_OpenWindow = $8401000B;
  SIGF_ABORT = $1;
  LIBF_CHANGED = $2;
  AFB_68881 = $4;
  NT_FONT = $C;
  AN_MemCorrupt = $81000005;
  NT_INTERRUPT = $2;
  NT_RESOURCE = $8;
  TS_WAIT = $4;
  AFF_68881 = $10;
  LIBRARY_VERSION = $22;
  NT_MESSAGE = $5;
  AN_SysScrnType = $84000009;
  AN_RegionMemory = $8201000B;
  CMD_NONSTD = $9;
  AN_SemCorrupt = $81000008;
  NT_FREEMSG = $6;
  MEM_BLOCKMASK = $7;
  LIB_NONSTD = $FFFFFFE2;
  TS_INVALID = $0;
  MEMF_CHIP = $2;
  NT_REPLYMSG = $7;
  EXECNAME = 'exec.library';
  AN_TDDelay = $14000002;
  LIB_CLOSE = $FFFFFFF4;
  AN_BadChkSum = $7000009;
  AN_BadGadget = $4000001;
  PA_SIGNAL = $0;
  SIGB_BLIT = $4;
  AT_DeadEnd = $80000000;
  AT_Recovery = $0;
  TB_LAUNCH = $7;
  NT_DEVICE = $3;
  NT_LIBRARY = $9;
  PA_SOFTINT = $1;
  MEMF_FAST = $4;
  IOERR_ABORTED = $FFFFFFFE;
  AG_MakeLib = $20000;
  TS_REMOVED = $6;
  SIGF_BLIT = $10;
  PF_ACTION = $3;
  TF_LAUNCH = $80;
  PA_IGNORE = $2;
  CMD_READ = $2;
  MEM_BLOCKSIZE = $8;
  CMD_FLUSH = $8;
  AN_CListLib = $6000000;
  LIB_BASE = $FFFFFFFA;
  IOB_QUICK = $0;
  CMD_RESET = $1;
  AO_CListLib = $8006;
  AN_BadSegList = $8000001;
  AN_Intuition = $4000000;
  AO_Intuition = $8004;
  AN_BltBitMap = $8201000A;
  IOF_QUICK = $1;
  NT_PROCESS = $D;
  AN_BaseChkSum = $81000002;
  AN_QPktFail = $7000003;
  AN_LibChkSum = $81000003;
  TS_ADDED = $1;
  TB_EXCEPT = $5;
  CMD_WRITE = $3;
  AG_IOError = $60000;
  AN_LibMem = $81000004;
  AN_ExecLib = $1000000;
  AN_GfxNoMem = $82010000;
  CMD_START = $7;
  AO_ExecLib = $8001;
  AN_BadMessage = $8400000D;
  TF_EXCEPT = $20;
  AN_DiskBlkSeq = $7000006;
  RTC_MATCHWORD = $4AFC;


Function Supervisor (userFunction: Pointer): LongInt;
Procedure InitCode
		 (startClass: LongInt;
		  version: LongInt);

Procedure InitStruct
		 (initTable: Pointer;
		  memory: Pointer;
		  size: LongInt);

Function MakeLibrary
		 (funcInit: Pointer;
		  structInit: Pointer;
		  libInit: Pointer;
		  dataSize: LongInt;
		  codeSize: LongInt): pLibrary;

Function MakeFunctions
		 (target: Pointer;
		  functionArray: Pointer;
		  funcDispBase: Pointer): LongInt;

Function FindResident (name: String): pResident;
Procedure InitResident
		 (resident: pResident;
		  segList: LongInt);

Procedure Alert
		 (alertNum: LongInt;
		  parameters: Pointer);

Procedure Debug (flags: LongInt);
Procedure Disable;
Procedure Enable;
Procedure Forbid;
Procedure Permit;
Function SetSR
		 (newSR: LongInt;
		  mask: LongInt): LongInt;

Function SuperState: Pointer;
Procedure UserState (sysStack: Pointer);
Function SetIntVector
		 (intNumber: LongInt;
		  interrupt: pInterrupt): pInterrupt;

Procedure AddIntServer
		 (intNumber: LongInt;
		  interrupt: pInterrupt);

Procedure RemIntServer
		 (intNumber: LongInt;
		  interrupt: pInterrupt);

Procedure Cause (interrupt: pInterrupt);
Function Allocate
		 (freeList: pMemHeader;
		  byteSize: LongInt): Pointer;

Procedure Deallocate
		 (freeList: pMemHeader;
		  memoryBlock: Pointer;
		  byteSize: LongInt);

Function AllocMem
		 (byteSize: LongInt;
		  requirements: LongInt): Pointer;

Function AllocAbs
		 (byteSize: LongInt;
		  location: Pointer): Pointer;

Procedure FreeMem_
		 (memoryBlock: Pointer;
		  byteSize: LongInt);

Function AvailMem (requirements: LongInt): LongInt;
Function AllocEntry (entry: pMemList): pMemList;
Procedure FreeEntry (entry: pMemList);
Procedure Insert_
		 (list: pList;
		  node: pNode;
		  pred: pNode);

Procedure AddHead
		 (list: pList;
		  node: pNode);

Procedure AddTail
		 (list: pList;
		  node: pNode);

Procedure Remove (node: pNode);
Function RemHead (list: pList): pNode;
Function RemTail (list: pList): pNode;
Procedure Enqueue
		 (list: pList;
		  node: pNode);

Function FindName
		 (list: pList;
		  name: String): pNode;

Function AddTask
		 (task: pTask;
		  initPC: Pointer;
		  finalPC: Pointer): Pointer;

Procedure RemTask (task: pTask);
Function FindTask (name: String): pTask;
Function SetTaskPri
		 (task: pTask;
		  priority: LongInt): ShortInt;

Function SetSignal
		 (newSignals: LongInt;
		  signalSet: LongInt): LongInt;

Function SetExcept
		 (newSignals: LongInt;
		  signalSet: LongInt): LongInt;

Function Wait (signalSet: LongInt): LongInt;
Procedure Signal
		 (task: pTask;
		  signalSet: LongInt);

Function AllocSignal (signalNum: ShortInt): ShortInt;
Procedure FreeSignal (signalNum: ShortInt);
Function AllocTrap (trapNum: LongInt): LongInt;
Procedure FreeTrap (trapNum: LongInt);
Procedure AddPort (port: pMsgPort);
Procedure RemPort (port: pMsgPort);
Procedure PutMsg
		 (port: pMsgPort;
		  message: pMessage);

Function GetMsg (port: pMsgPort): pMessage;
Procedure ReplyMsg (message: pMessage);
Function WaitPort (port: pMsgPort): pMessage;
Function FindPort (name: String): pMsgPort;
Procedure AddLibrary (library: pLibrary);
Procedure RemLibrary (library: pLibrary);
Function OldOpenLibrary (libName: Pointer): pLibrary;
Procedure CloseLibrary (library: pLibrary);
Function SetFunction
		 (library: pLibrary;
		  funcOffset: LongInt;
		  funcEntry: Pointer): Pointer;

Procedure SumLibrary (library: pLibrary);
Procedure AddDevice (device: pDevice);
Procedure RemDevice (device: pDevice);
Function OpenDevice
		 (devName: String;
		  unit_: LongInt;
		  ioRequest: pIORequest;
		  flags: LongInt): ShortInt;

Procedure CloseDevice (ioRequest: pIORequest);
Function DoIO (ioRequest: pIORequest): ShortInt;
Procedure SendIO (ioRequest: pIORequest);
Function CheckIO (ioRequest: pIORequest): Boolean;
Function WaitIO (ioRequest: pIORequest): ShortInt;
Procedure AbortIO (ioRequest: pIORequest);
Procedure AddResource (resource: Pointer);
Procedure RemResource (resource: Pointer);
Function OpenResource (resName: String): Pointer;
Procedure RawDoFmt
		 (formatString: pShortInt;
		  dataStream: Pointer;
		  putChProc: Pointer;
		  putChData: Pointer);

Function GetCC: Integer;
Function TypeOfMem (address: Pointer): LongInt;
Function Procure
		 (semaport: pSemaphore;
		  bidMsg: pMessage): ShortInt;

Procedure Vacate (semaport: pSemaphore);
Function OpenLibrary
		 (libName: String;
		  version: LongInt): pLibrary;

Procedure InitSemaphore (sigSem: pSignalSemaphore);
Procedure ObtainSemaphore (sigSem: pSignalSemaphore);
Procedure ReleaseSemaphore (sigSem: pSignalSemaphore);
Function AttemptSemaphore (sigSem: pSignalSemaphore): LongInt;
Procedure ObtainSemaphoreList (sigSem: pList);
Procedure ReleaseSemaphoreList (sigSem: pList);
Function FindSemaphore (sigSem: String): pSignalSemaphore;
Procedure AddSemaphore (sigSem: pSignalSemaphore);
Procedure RemSemaphore (sigSem: pSignalSemaphore);
Function SumKickData: LongInt;
Procedure AddMemList
		 (size: LongInt;
		  attributes: LongInt;
		  pri: LongInt;
		  base: Pointer;
		  name: pShortInt);

Procedure CopyMem
		 (source: Pointer;
		  dest: Pointer;
		  size: LongInt);

Procedure CopyMemQuick
		 (source: pLongInt;
		  dest: pLongInt;
		  size: LongInt);



End.
