(*$M-*)
DEFINITION MODULE Hardware;

FROM SYSTEM IMPORT
 ADDRESS,BITSET;

TYPE
 Byte=[-128..127];
 UByte=[0..255];

TYPE
 AdkFlags=(
  use0v1,use1v2,use2v3,use3vn,use0p1,use1p2,use2p3,use3pn,
  fast,msbSync,wordSync,uartBrk,mfmPrec,preComp0,preComp1,
  adkSet
 );
 AdkFlagSet=SET OF AdkFlags;

CONST
 pre000ns=AdkFlagSet{};
 pre140ns=AdkFlagSet{preComp0};
 pre280ns=AdkFlagSet{preComp1};
 pre560ns=AdkFlagSet{preComp0,preComp1};

TYPE
 DmaFlags=(
  aud0,aud1,aud2,aud3,disk,sprite,blitter,copper,
  raster,master,blithog,df11,df12,bltnzero,bltdone,dmaSet
 );
 DmaFlagSet=SET OF DmaFlags;

CONST
 dmaAll=DmaFlagSet{aud0..raster};

TYPE
 IntFlags=(
  tbe,dskblk,softint,ports,coper,vertb,blit,aud0i,
  aud1i,aud2i,aud3i,rbf,disksync,exter,inten,intSet
 );
 IntFlagSet=SET OF IntFlags;

CONST
 hSizeBits=6;
 vSizeBits=16-hSizeBits;
 hSizeMask=03FH;
 vSizeMask=03FFH;
 maxBytesPerRow=128;

TYPE
 BC0Flags=(
  nanbnc,nanbc,nabnc,nabc,anbnc,anbc,abnc,abc,
  dest,srcC,srcB,srcA,ash1,ash2,ash4,ash8
 );
 BC0FlagSet=SET OF BC0Flags;

CONST
 aORb=BC0FlagSet{abc,anbc,nabc,abnc,anbnc,nabnc};
 aORc=BC0FlagSet{abc,nabc,abnc,anbc,nanbc,anbnc};
 aXORc=BC0FlagSet{nabc,abnc,nanbc,anbnc};
 aTOd=BC0FlagSet{abc,anbc,abnc,anbnc};

TYPE
 BC1Flags=(
  lineMode,desc,fillCarryIn,fillOr,fillXor,ovFlag,signFlag,
  bf7,bf8,bf9,bf10,bf11,bsh1,bsh2,bsh4,bsh8
 );
 BC1FlagSet=SET OF BC1Flags;
CONST
 oneDot=desc;
 blitReverse=desc;
 aul=BC1FlagSet{fillCarryIn};
 sul=BC1FlagSet{fillOr};
 sud=BC1FlagSet{fillXor};
 octant1=sud;
 octant2=BC1FlagSet{};
 octant3=sul;
 octant4=aul+sud;
 octant5=aul+sul+sud;
 octant6=aul+sul;
 octant7=aul;
 octant8=sul+sud;

TYPE
 BltnodePtr=POINTER TO Bltnode;
 Bltnode=RECORD
  n:BltnodePtr;
  function:ADDRESS;
  stat:CHAR;
  blitsize:INTEGER;
  beamsync:INTEGER;
  cleanup:ADDRESS;
 END;

CONST
 cleanup=40H;
 cleanme=cleanup;

TYPE
 Coord=RECORD
  v,h:Byte;
 END;
 Custom=RECORD
  bltddat:CARDINAL;
  dmaconr:DmaFlagSet;
  vposr:LONGCARD;
  dskdatr:CARDINAL;
  joy0dat:Coord;
  joy1dat:Coord;
  clxdat:CARDINAL;
  adkconr:BITSET;
  pot0dat:CARDINAL;
  pot1dat:CARDINAL;
  potinp:CARDINAL;
  serdatr:CARDINAL;
  dskbytr:CARDINAL;
  intenar:IntFlagSet;
  intreqr:CARDINAL;
  dskpt:ADDRESS;
  dsklen:CARDINAL;
  dskdat:CARDINAL;
  refptr:CARDINAL;
  vposw:CARDINAL;
  vhposw:CARDINAL;
  copcon:BITSET;
  serdat:CARDINAL;
  serper:CARDINAL;
  potgo:CARDINAL;
  joytest:CARDINAL;
  strequ:CARDINAL;
  strvbl:CARDINAL;
  strhor:CARDINAL;
  strlong:CARDINAL;
  bltcon0:BITSET;
  bltcon1:BITSET;
  bltafwm:CARDINAL;
  bltalwm:CARDINAL;
  bltcpt:ADDRESS;
  bltbpt:ADDRESS;
  bltapt:ADDRESS;
  bltdpt:ADDRESS;
  bltsize:CARDINAL;
  pad2d:ARRAY [0..2] OF CARDINAL;
  bltcmod:CARDINAL;
  bltbmod:CARDINAL;
  bltamod:CARDINAL;
  bltdmod:CARDINAL;
  pad34:ARRAY [0..3] OF CARDINAL;
  bltcdat:CARDINAL;
  bltbdat:CARDINAL;
  bltadat:CARDINAL;
  pad3b:ARRAY [0..3] OF CARDINAL;
  dsksync:CARDINAL;
  cop1lc:LONGCARD;
  cop2lc:LONGCARD;
  copjmp1:CARDINAL;
  copjmp2:CARDINAL;
  copins:CARDINAL;
  diwstrt:CARDINAL;
  diwstop:CARDINAL;
  ddfstrt:CARDINAL;
  ddfstop:CARDINAL;
  dmacon:DmaFlagSet;
  clxcon:CARDINAL;
  intena:IntFlagSet;
  intreq:CARDINAL;
  adkcon:BITSET;
  aud:ARRAY [0..3] OF RECORD
   acptr:ADDRESS;
   aclen:CARDINAL;
   acper:CARDINAL;
   acvol:CARDINAL;
   acdat:CARDINAL;
   acpad:ARRAY [0..1] OF CARDINAL;
  END;
  bplpt:ARRAY [0..5] OF ADDRESS;
  pad7c:ARRAY [0..3] OF CARDINAL;
  bplcon0:CARDINAL;
  bplcon1:CARDINAL;
  bplcon2:CARDINAL;
  pad83:CARDINAL;
  bpl1mod:CARDINAL;
  bpl2mod:CARDINAL;
  pad86:ARRAY [0..1] OF CARDINAL;
  bpldat:ARRAY [0..5] OF CARDINAL;
  pad8e:ARRAY [0..1] OF CARDINAL;
  sprpt:ARRAY [0..7] OF ADDRESS;
  spr:ARRAY [0..7] OF RECORD
   pos:CARDINAL;
   ctl:CARDINAL;
   dataa:CARDINAL;
   datab:CARDINAL;
  END;
  color:ARRAY [0..31] OF CARDINAL;
 END;

VAR
 custom[0DFF000H]:Custom;

TYPE
 CiaIcrFlags=(ta,tb,alrm,sp,flg,if5,if6,setclr);
 CiaIcrFlagSet=SET OF CiaIcrFlags;
CONST
 ir=setclr; (* On read setclr has the meaning of ir *)
TYPE
 CiaCraFlags=(
  craStart,craPbon,craOutmode,craRunmode,craLoad,craInmode,
  craSpmode,craTodin
 );
 CiaCraFlagSet=SET OF CiaCraFlags;
 CiaCrbFlags=(
  crbStart,crbPbon,crbOutmode,crbRunmode,crbLoad,crbInmode0,
  crbInmode1,crbAlarm
 );
 CiaCrbFlagSet=SET OF CiaCrbFlags;
 CiaaPraFlags=(
  overlay,led,dskChange,dskProt,dskTrack0,dskRdy,gamePort0,
  gamePort1
 );
 CiaaPraFlagSet=SET OF CiaaPraFlags;
 CiaaPrbFlags=[0..7]; (* Parallel port *)
 CiaaPrbFlagSet=SET OF CiaaPrbFlags;
 CiabPraFlags=(
  prtrBusy,prtrPOut,prtrSel,comDSR,comCTS,comCD,comRTS,comDTR
 );
 CiabPraFlagSet=SET OF CiabPraFlags;
 CiabPrbFlags=(
  dskStep,dskDirec,dskSide,dskSel0,dskSel1,dskSel2,dskSel3,
  dskMotor
 );
 CiabPrbFlagSet=SET OF CiabPrbFlags;

TYPE
 ShortSet=SET OF [0..7];
 Pad=ARRAY [0..253] OF ShortSet;
 CIAA=RECORD
  pra:CiaaPraFlagSet; pad0:Pad;
  prb:CiaaPrbFlagSet; pad1:Pad;
  ddra:CiaaPraFlagSet; pad2:Pad;
  ddrb:CiaaPrbFlagSet; pad3:Pad;
  talo:UByte; pad4:Pad;
  tahi:UByte; pad5:Pad;
  tblo:UByte; pad6:Pad;
  tbhi:UByte; pad7:Pad;
  todlow:UByte; pad8:Pad;
  todmid:UByte; pad9:Pad;
  todhi:UByte; pad10:Pad;
  unusedreg:ShortSet; pad11:Pad;
  sdr:ShortSet; pad12:Pad;
  icr:CiaIcrFlagSet; pad13:Pad;
  cra:CiaCraFlagSet; pad14:Pad;
  crb:CiaCrbFlagSet;
 END;
 CIAB=RECORD
  pra:CiabPraFlagSet; pad0:Pad;
  prb:CiabPrbFlagSet; pad1:Pad;
  ddra:CiabPraFlagSet; pad2:Pad;
  ddrb:CiabPrbFlagSet; pad3:Pad;
  talo:UByte; pad4:Pad;
  tahi:UByte; pad5:Pad;
  tblo:UByte; pad6:Pad;
  tbhi:UByte; pad7:Pad;
  todlow:UByte; pad8:Pad;
  todmid:UByte; pad9:Pad;
  todhi:UByte; pad10:Pad;
  unusedreg:ShortSet; pad11:Pad;
  sdr:ShortSet; pad12:Pad;
  icr:CiaIcrFlagSet; pad13:Pad;
  cra:CiaCraFlagSet; pad14:Pad;
  crb:CiaCrbFlagSet;
 END;

VAR
 ciaa[0BFE001H]:CIAA;
 ciab[0BFD000H]:CIAB;

END Hardware.
