DEFINITION MODULE Resources; (*$Implementation:=FALSE*)
(* 05-Jun-1993/bp *)

FROM SYSTEM IMPORT ADDRESS,BPTR,LONGSET,SHORTSET;

FROM DosD IMPORT
 BSTR,FileLockPtr;

FROM ExecD IMPORT vectSize,Interrupt,InterruptPtr,Library,LibraryPtr,
 List,Message,Node,ResidentPtr,TaskPtr;

FROM Hardware IMPORT
 CiaIcrFlags,CiaIcrFlagSet,PotFlags,PotFlagSet;

IMPORT R;

TYPE
 StrPtr=ADDRESS;

(*
 battclock resource
*)

CONST
 battclockName="battclock.resource";

PROCEDURE ReadBattClock(base{R.A6}:ADDRESS):LONGCARD; CODE -12;

PROCEDURE ResetBattClock(base{R.A6}:ADDRESS); CODE -6;

PROCEDURE WriteBattClock(
           base{R.A6}:ADDRESS;
           time{R.D0}:LONGCARD); CODE -18;

(*
 battmem resource
*)

CONST
 battmemName="battmem.resource";

 battmemAmigaAmnesiaAddr=0;
 battmemAmigaAmnesiaLen=1;

 battmemScsiTimeoutAddr=1;
 battmemScsiTimeoutLen=1;

 battmemScsiLunsAddr=2;
 battmemScsiLunsLen=1;

 battmemSharedAmnesiaAddr=64;
 battmemSharedAmnesiaLen=1;

 battmemScsiHostIdAddr=65;
 battmemScsiHostIdLen=3;

 battmemScsiSyncXferAddr=68;
 battmemScsiSyncXferLen=1;

PROCEDURE ObtainBattSemaphore(base{R.A6}:ADDRESS); CODE -6;

PROCEDURE ReadBattMem(
           base{R.A6}:ADDRESS;
           buffer{R.A0}:ADDRESS;
           offset{R.D0}:LONGCARD;
           length{R.D1}:LONGCARD):LONGCARD; CODE -18;

PROCEDURE ReleaseBattSemaphore(base{R.A6}:ADDRESS); CODE -12;

PROCEDURE WriteBattMem(
           base{R.A6}:ADDRESS;
           buffer{R.A0}:ADDRESS;
           offset{R.D0}:LONGCARD;
           length{R.D1}:LONGCARD):LONGCARD; CODE -24;


(*
 card.resource (*39*)
*)
CONST
  cardName="card.resource";

TYPE
  CardHandleFlags=(resetRemove,ifAvailable,delayOwnerShip,
                  cah3,cah4,cah5,cah6,cah7);
  CardHandleFlagSet=SET OF CardHandleFlags;

  CardHandle=RECORD
    cardNode:Node;
    cardRemoved:InterruptPtr;
    cardInserted:InterruptPtr;
    cardStatus:InterruptPtr;
    cardFlags:CardHandleFlagSet;
  END;
  CardHandlePtr=POINTER TO CardHandle;

  DeviceTData=RECORD
    dtSize:LONGCARD;
    dtSpeed:LONGCARD;
    dtType:SHORTCARD;
    dtFlags:SHORTSET;
  END;
  DeviceTDataPtr=POINTER TO DeviceTData;

  CardMemoryMap=RECORD
    commonMemory:ADDRESS;
    attributeMemeory:ADDRESS;
    ioMemory:ADDRESS;
  END;
  CardMemoryMapPtr=POINTER TO CardMemoryMap;

CONST
  removeHandle=0; (* Element f. LONGSET *)

TYPE
  CardStatusFlags=(cs0,cs1,irq,wr,da,sc,ccdet,cs7);
  CardStatusFlagSet=SET OF CardStatusFlags;
CONST
  bvd1=sc;
  bvd2=da;
  bsy=irq;

  cardVoltage0V=0;
  cardVoltage5V=1;
  cardVoltage12V=2;

TYPE
  CardMiscControlFlags=(cmc0,enableDigAudio,cmc2,disableWp,
                        cmc4,cmc5,cmc6,cmc7);
  CardMiscControlFlagSet=SET OF CardMiscControlFlags;

CONST
  cardInterfaceAmiga0=0;

TYPE
  XIPFlags=(autoRun,xf1,xf2,xf3,xf4,xf5,xf6,xf7);
  XIPFlagSet=SET OF XIPFlags;
  TPAmigaXIP=RECORD
    code:SHORTCARD;
    link:SHORTCARD;
    xipLoc:ARRAY [0..3] OF SHORTCARD;
    xipFlags:XIPFlagSet;
    xipResrv:SHORTCARD;
  END;
  TPAmigaXIPPtr=POINTER TO TPAmigaXIP;

PROCEDURE BeginCardAccess(base{R.A6}:ADDRESS;
           handle{R.A1}:CardHandlePtr
           ):BOOLEAN; CODE -24;
PROCEDURE CardAccessSpeed(base{R.A6}:ADDRESS;
           handle{R.A1}:CardHandlePtr;
           nano{R.D0}:LONGCARD
           ):LONGCARD; CODE -54;
PROCEDURE CardChangeCount(base{R.A6}:ADDRESS
           ):LONGCARD; CODE -96;
PROCEDURE CardForceChange(base{R.A6}:ADDRESS
           ):BOOLEAN; CODE -90;
PROCEDURE CardInterface(base{R.A6}:ADDRESS
           ):LONGCARD; CODE -102;
PROCEDURE CardMiscControl(base{R.A6}:ADDRESS;
           handle{R.A1}:CardHandlePtr;
           bits{R.D1}:CardMiscControlFlagSet
           ):CardMiscControlFlagSet; CODE -48;
PROCEDURE CardProgramVoltage(base{R.A6}:ADDRESS;
           handle{R.A1}:CardHandlePtr;
           voltage{R.D0}:LONGCARD
           ):LONGINT; CODE -60;
PROCEDURE CardResetCard(base{R.A6}:ADDRESS;
           handle{R.A1}:CardHandlePtr
           ):BOOLEAN; CODE -66;
PROCEDURE CardResetRemove(base{R.A6}:ADDRESS;
           handle{R.A1}:CardHandlePtr;
           flag{R.D0}:LONGSET
           ):BOOLEAN; CODE -42;
PROCEDURE CopyTuple(base{R.A6}:ADDRESS;
           handle{R.A1}:CardHandlePtr;
           buffer{R.A0}:ADDRESS;
           tuplecode{R.D1}:LONGCARD;
           size{R.D0}:LONGCARD
           ):BOOLEAN; CODE -72;
PROCEDURE DeviceTuple(base{R.A6}:ADDRESS;
           tupleData{R.A0}:ADDRESS;
           storage{R.A1}:DeviceTDataPtr
           ):LONGCARD; CODE -78;
PROCEDURE EndCardAccess(base{R.A6}:ADDRESS;
           handle{R.A1}:CardHandlePtr
           ):LONGCARD; CODE -30;
PROCEDURE GetCardMap(base{R.A6}:ADDRESS
           ):CardMemoryMapPtr; CODE -18;
PROCEDURE IfAmigaXIP(base{R.A6}:ADDRESS;
           handle{R.A2}:CardHandlePtr
           ):ResidentPtr; CODE -84;
PROCEDURE OwnCard(base{R.A6}:ADDRESS;
           handle{R.A1}:CardHandlePtr
           ):LONGINT; CODE -6;
PROCEDURE ReadCardStatus(base{R.A6}:ADDRESS
           ):CardStatusFlagSet; CODE -36;
PROCEDURE ReleaseCard(base{R.A6}:ADDRESS;
           handle{R.A1}:CardHandlePtr;
           flags{R.D0}:LONGSET); CODE -12;


(*
 cia resources
*)

CONST
 ciaaName="ciaa.resource";
 ciabName="ciab.resource";

TYPE
 CiaResourcePtr=ADDRESS;

PROCEDURE AbleICR(
           cia{R.A6}:CiaResourcePtr;
           mask{R.D0}:CiaIcrFlagSet):CiaIcrFlagSet; CODE -18;

PROCEDURE AddICRVector(
           cia{R.A6}:CiaResourcePtr;
           icrBit{R.D0}:CiaIcrFlags;
           interrupt{R.A1}:InterruptPtr):InterruptPtr; CODE -6;

PROCEDURE RemICRVector(
           cia{R.A6}:CiaResourcePtr;
           icrBit{R.D0}:CiaIcrFlags;
           interrupt{R.A1}:InterruptPtr); CODE -12;

PROCEDURE SetICR(
           cia{R.A6}:CiaResourcePtr;
           mask{R.D0}:CiaIcrFlagSet):CiaIcrFlagSet; CODE -24;


(*
 disk resource
*)

TYPE
 DiscResourceUnit=RECORD
  message:Message;
  discBlock:Interrupt;
  discSync:Interrupt;
  index:Interrupt
 END;
 DiscResourceUnitPtr=POINTER TO DiscResourceUnit;

 DiscResourceFlags=(
  alloc0,alloc1,alloc2,alloc3,drf4,drf5,drf6,active
 );
 DiscResourceFlagSet=SET OF DiscResourceFlags;

 DiscResource=RECORD
  library:Library;
  current:DiscResourceUnitPtr;
  flags:DiscResourceFlagSet;
  pad:SHORTCARD;
  sysLib:LibraryPtr;
  ciaResource:LibraryPtr;
  unitID:ARRAY [alloc0..alloc3] OF LONGCARD;
  waiting:List;
  discBlock:Interrupt;
  discSync:Interrupt;
  index:Interrupt;
  currTask:TaskPtr;
 END;
 DiscResourcePtr=POINTER TO DiscResource;

CONST
 diskName="disk.resource";

 dskDmaOff=4000H;

 amiga=0;
 drt37422D2S=55555555H;
 drt150rpm=0AAAAAAAAH;
 empty=0FFFFFFFFH;

PROCEDURE AllocUnit(
           disk{R.A6}:DiscResourcePtr;
           unitNum{R.D0}:LONGINT):BOOLEAN; CODE -6;

PROCEDURE FreeUnit(
           disk{R.A6}:DiscResourcePtr;
           unitNum{R.D0}:LONGINT); CODE -12;

PROCEDURE GetUnit(
           disk{R.A6}:DiscResourcePtr;
           unitPointer{R.A1}:DiscResourceUnitPtr
          ):DiscResourceUnitPtr; CODE -18;

PROCEDURE GetUnitID(
           disk{R.A6}:DiscResourcePtr;
           unitNum{R.D0}:LONGINT):LONGCARD; CODE -30;

PROCEDURE GiveUnit(disk{R.A6}:DiscResourcePtr); CODE -24;

PROCEDURE(*37*) ReadUnitID(
                 disk{R.A6}:DiscResourcePtr;
                 unitNum{R.D0}:LONGINT):LONGCARD; CODE -36;

(*
 filesystem resource
*)

CONST
 fsrName="FileSystem.resource";

TYPE
 FileSysResource=RECORD
  node:Node;
  creator:StrPtr;
  fileSysEntries:List;
 END;

 FileSysEntry=RECORD
  node:Node;
  dosType:LONGCARD;
  version:LONGCARD;
  patchFlags:LONGSET;
  type:LONGCARD;
  task:TaskPtr;
  lock:FileLockPtr;
  handler:BSTR;
  stackSize:LONGCARD;
  priority:LONGINT;
  startup:BPTR;
  segList:BPTR;
  globalVec:BPTR;
 END;

(*
 mathieee resource
*)

CONST
 mathIEEEName="MathIEEE.resource";

TYPE
 MathIEEEResourceFlags=(
  dblbas,dbltrans,sglbas,sgltrans,extbas,exttrans,mirf6,mirf7,
  mirf8,mirf9,mirf10,mirf11,mirf12,mirf13,mirf14,mirf15
 );
 MathIEEEResourceFlagSet=SET OF MathIEEEResourceFlags;

 MathIEEEResource=RECORD
  node:Node;
  flags:MathIEEEResourceFlagSet;
  baseAddr:ADDRESS;
  dblBasInit:PROC;
  dblTransInit:PROC;
  sglBasInit:PROC;
  sglTransInit:PROC;
  extBasInit:PROC;
  extTransInit:PROC;
 END;
 MathIEEEResourcePtr=POINTER TO MathIEEEResource;

(*
 misc resource
*)

CONST
 miscName="misc.resource";

TYPE
 ResourceTypes=(
  serialPort,serialBits,parallelPort,parallelBits
 );
  MiscResource=RECORD
    library: Library;
    allocArray: ARRAY ResourceTypes OF ADDRESS;
  END;
  MiscResourcePtr=POINTER TO MiscResource;

PROCEDURE AllocMiscResource(
           misc{R.A6}:MiscResourcePtr;
           unitNum{R.D0}:LONGINT;
           name{R.A1}:StrPtr):ADDRESS; CODE -6;

PROCEDURE FreeMiscResource(
           misc{R.A6}:MiscResourcePtr;
           unitNum{R.D0}:LONGINT); CODE -12;

(*
 potgo resource
*)

CONST
 potgoName="potgo.resource";

TYPE
 PotgoBits=PotFlags;
 PotgoBitSet=PotFlagSet;

PROCEDURE AllocPotBits(
           potgo{R.A6}:ADDRESS;
           bits{R.D0}:PotgoBitSet):PotgoBitSet; CODE -6;

PROCEDURE FreePotBits(
           potgo{R.A6}:ADDRESS;
           allocated{R.D0}:PotgoBitSet); CODE -12;

PROCEDURE WritePotgo(
           potgo{R.A6}:ADDRESS;
           word{R.D0}:PotgoBitSet;
           mask{R.D1}:PotgoBitSet); CODE -18;

END Resources.noimp
