(*$M-*)
DEFINITION MODULE Resources;

FROM SYSTEM IMPORT
 ADDRESS,LONGSET;
FROM Exec IMPORT
 base,vectSize,Interrupt,InterruptPtr,Library,LibraryPtr,
 List,Message,UByte;
FROM Hardware IMPORT
 CiaIcrFlags,CiaIcrFlagSet;

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

TYPE
 CiaResourcePtr=ADDRESS;
 
PROCEDURE AbleICR(
           cia{14}:CiaResourcePtr;
           mask{0}:CiaIcrFlagSet):CiaIcrFlagSet; CODE -18;
PROCEDURE AddICRVector(
           cia{14}:CiaResourcePtr; icrBit{0}:CiaIcrFlags;
           interrupt{9}:InterruptPtr):InterruptPtr; CODE -6;
PROCEDURE RemICRVector(cia{14}:CiaResourcePtr; 
                       icrBit{0}:CiaIcrFlags;
                       interrupt{9}:InterruptPtr); CODE -12;
PROCEDURE SetICR(
           cia{14}:CiaResourcePtr;
           mask{0}:CiaIcrFlagSet):CiaIcrFlagSet; CODE -24;

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:UByte;
  sysLib:LibraryPtr;
  ciaResource:LibraryPtr;
  unitID:ARRAY [alloc0..alloc3] OF LONGCARD;
  waiting:List;
  discBlock:Interrupt;
  discSync:Interrupt;
  index:Interrupt;
 END;
 DiscResourcePtr=POINTER TO DiscResource;

CONST
 diskName="disk.resource";
 dskDmaOff=4000H;
 amiga=0;
 drt37422D2S=55555555H;
 empty=0FFFFFFFFH;
 
PROCEDURE AllocUnit(disk{14}:DiscResourcePtr;
                    unitNum{0}:LONGINT):LONGINT; CODE -6;
PROCEDURE FreeUnit(disk{14}:DiscResourcePtr;
                   unitNum{0}:LONGINT); CODE -12;
PROCEDURE GetUnit(
           disk{14}:DiscResourcePtr;
           unitPointer{9}:DiscResourceUnitPtr
          ):DiscResourceUnitPtr; CODE -18;
PROCEDURE GetUnitID(
           disk{14}:DiscResourcePtr;
           unitNum{0}:LONGINT):LONGCARD; CODE -30;
PROCEDURE GiveUnit(disk{14}:DiscResourcePtr); CODE -24;

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{14}:MiscResourcePtr;
           unitNum{0}:LONGINT;
           name{9}:ADDRESS):ADDRESS; CODE -6;
PROCEDURE FreeMiscResource(misc{14}:MiscResourcePtr;
                            unitNum{0}:LONGINT); CODE -12;

CONST
 potgoName="potgo.resource";

TYPE
 PotgoBits=(
  start,pb1,pb2,pb3,pb4,pb5,pb6,pb7,
  datlx,outlx,datly,outly,datrx,outrx,datry,outry,pb16
 );
 PotgoBitSet=SET OF PotgoBits;

PROCEDURE AllocPotBits(
           potgo{14}: ADDRESS;
           bits{0}: PotgoBitSet): PotgoBitSet; CODE -6;
PROCEDURE FreePotBits(potgo{14}: ADDRESS;
                      allocated{0}: PotgoBitSet); CODE -12;
PROCEDURE WritePotgo(potgo{14}: ADDRESS;
                     word{0}: PotgoBitSet;
                     mask{1}: PotgoBitSet); CODE -18;

END Resources.
