DEFINITION MODULE Hardware; (*$ Implementation:=FALSE *)
(* 20-May-1993/bp *)

FROM SYSTEM IMPORT ADDRESS,BITSET,SHORTSET;

IMPORT ExecD;

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
 AudioInfo=RECORD
  acptr:ADDRESS;
  aclen:CARDINAL;
  acper:CARDINAL;
  acvol:CARDINAL;
  acdat:CARDINAL;
  acpad:ARRAY [0..1] OF CARDINAL;
 END;
 AudioChannels=ARRAY [0..3] OF AudioInfo;

 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
 BeamConFlags=(
  hSyncTrue,vSyncTrue,cSyncTrue,cSBlank,
  varCSync,displayPal,displayDual,varBeam,
  varHSync,varVSync,cSBlankEn,lolDis,
  varVBlank,bcf13,bcf14,bcf15
 );
 BeamConFlagSet=SET OF BeamConFlags;

 BPLC0Flags=(
  useBPLCon3,ersy,lace,lpen,bp4,bp5,bp6,bp7,
  gaud,color,dblpf,homod,bpu0,bpu1,bpu2,hires
 );
 BPLC0FlagSet=SET OF BPLC0Flags;

CONST
 bplCon2ZdCtEn=0400H;
 bplCon2ZdBpEn=0800H;
 bplcon2ZdBpSel0=1000H;
 bplCon2ZdBpSel1=2000H;
 bplCon2ZdBpSel2=4000H;

TYPE
 BPLC3Flags=(
  extBlnkEn,extBlkZd,zdClkEn,bpl33,brdnTran,brdnBlnk,bpl36,bpl37,
  bpl38,blp39,bpl310,bpl311,bpl312,bpl313,bpl314,bpl315
 );
 BPLC3FlagSet=SET OF BPLC3Flags;

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
 CollisionControlFlags=(
  plane1,plane2,plane3,plane4,plane5,plane6,
  enablePlane1,enablePlane2,enablePlane3,
  enablePlane4,enablePlane5,enablePlane6,
  enableSprite01,enableSprite23,
  enableSprite45,enableSprite67
 );
 CollisionControlFlagSet=SET OF CollisionControlFlags;
 CollisionFlags=(
  play1toPlay2,
  play1toSprite01,play1toSprite23,play1toSprite45,play1toSprite67,
  play2toSprite01,play2toSprite23,play2toSprite45,play2toSprite67,
  sprite01toSprite23,sprite01toSprite45,sprite01toSprite67,
  sprite23toSprite45,sprite23toSprite67,sprite45toSprite67
 );
 CollisionFlagSet=SET OF CollisionFlags;

 Coord=RECORD
  v,h:SHORTINT;
 END;

 DiskFlags=(df0,df1,df2,df3,wordEqual,diskWrite,dmaOn,dskByte);
 DiskFlagSet=SET OF DiskFlags;
 DiskInfo=RECORD
  flags:DiskFlagSet;
  data:SHORTCARD;
 END;

 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=ExecD.IntFlags;
 IntFlagSet=SET OF IntFlags;

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

 aMaxBytesPerRow=128;
 sMinBytesPerRow=128;
 sMaxBytesPerRow=4096;

TYPE
 PotFlags=(
  start,pf1,pf2,pf3,pf4,pf5,pf6,pf7,
  datalx,outlx,dataly,outly,datarx,outrx,datary,outry
 );
 PotFlagSet=SET OF PotFlags;

 SerialFlags=(d8,stop,sf2,rxd,tsre,tbe,rbf,ovrun);
 SerialFlagSet=SET OF SerialFlags;
 SerialInfo=RECORD
  flags:SerialFlagSet;
  data:CHAR;
 END;

 SpriteControlFlags=(sho,ev8,sv8,sct3,sct4,sct5,sct6,att);
 SpriteControlFlagSet=SET OF SpriteControlFlags;
 SpriteControlInfo=RECORD
  ev:SHORTCARD;
  flags:SpriteControlFlagSet;
 END;
 SpriteInfo=RECORD
  pos:CARDINAL;
  ctl:SpriteControlInfo;
  data:LONGCARD;
 END;
 Sprites=ARRAY [0..7] OF SpriteInfo;

 Custom=RECORD
  bltddat:CARDINAL;
  dmaconr:DmaFlagSet;
  vposr:LONGCARD;
  dskdatr:CARDINAL;
  joy0dat:Coord;
  joy1dat:Coord;
  clxdat:CollisionFlagSet;
  adkconr:AdkFlagSet;
  pot0dat:Coord;
  pot1dat:Coord;
  potinp:PotFlagSet;
  serdatr:SerialInfo;
  dskbytr:DiskInfo;
  intenar:IntFlagSet;
  intreqr:IntFlagSet;
  dskpt:ADDRESS;
  dsklen:CARDINAL;
  dskdat:CARDINAL;
  refptr:CARDINAL;
  vposw:LONGCARD;
  copcon:BITSET;
  serdat:SerialInfo;
  serper:CARDINAL;
  potgo:PotFlagSet;
  joytest:Coord;
  strequ:CARDINAL;
  strvbl:CARDINAL;
  strhor:CARDINAL;
  strlong:CARDINAL;
  bltcon0:BC0FlagSet;
  bltcon1:BC1FlagSet;
  bltafwm:BITSET;
  bltalwm:BITSET;
  bltcpt:ADDRESS;
  bltbpt:ADDRESS;
  bltapt:ADDRESS;
  bltdpt:ADDRESS;
  bltsize:CARDINAL;
  pad2d:SHORTCARD;
  bltcon0l:SHORTCARD;
  bltsizv:CARDINAL;
  bltsizh:CARDINAL;
  bltcmod:CARDINAL;
  bltbmod:CARDINAL;
  bltamod:CARDINAL;
  bltdmod:CARDINAL;
  pad34:ARRAY [0..3] OF CARDINAL;
  bltcdat:CARDINAL;
  bltbdat:CARDINAL;
  bltadat:CARDINAL;
  pad3b:ARRAY [0..2] OF CARDINAL;
  deniseid:CARDINAL;
  dsksync:CARDINAL;
  cop1lc:ADDRESS;
  cop2lc:ADDRESS;
  copjmp1:CARDINAL;
  copjmp2:CARDINAL;
  copins:CARDINAL;
  diwstrt:Coord;
  diwstop:Coord;
  ddfstrt:Coord;
  ddfstop:Coord;
  dmacon:DmaFlagSet;
  clxcon:CollisionControlFlagSet;
  intena:IntFlagSet;
  intreq:IntFlagSet;
  adkcon:AdkFlagSet;
  aud:AudioChannels;
  bplpt:ARRAY [0..7] OF ADDRESS;
  bplcon0:BPLC0FlagSet;
  bplcon1:CARDINAL;
  bplcon2:CARDINAL;
  bplcon3:BPLC3FlagSet;
  bpl1mod:CARDINAL;
  bpl2mod:CARDINAL;
  bplhmod:CARDINAL;
  pad86:ARRAY [0..0] OF CARDINAL;
  bpldat:ARRAY [0..7] OF CARDINAL;
  sprpt:ARRAY [0..7] OF ADDRESS;
  spr:Sprites;
  color:ARRAY [0..31] OF CARDINAL;
  htotal:CARDINAL;
  hsstop:CARDINAL;
  hbstrt:CARDINAL;
  hbstop:CARDINAL;
  vtotal:CARDINAL;
  vsstop:CARDINAL;
  vbstrt:CARDINAL;
  vbstop:CARDINAL;
  sprhstrt:CARDINAL;
  sprhstop:CARDINAL;
  bplhstrt:CARDINAL;
  bplhstop:CARDINAL;
  hhposw:CARDINAL;
  hhposr:CARDINAL;
  beamcon0:BeamConFlagSet;
  hsstrt:CARDINAL;
  vsstrt:CARDINAL;
  hcenter:CARDINAL;
  diwhigh:CARDINAL; (* 01E4H *)
  padf3:ARRAY[0..10] OF CARDINAL;
  fmode: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;

CONST
 crbInPhi2=CiaCrbFlagSet{};
 crbInCnt=CiaCrbFlagSet{crbInmode0};
 crbInTA=CiaCrbFlagSet{crbInmode1};
 crbInCntTA=CiaCrbFlagSet{crbInmode0,crbInmode1};

TYPE
 CiaaPraFlags=(
  overlay,led,dskChange,dskProt,dskTrack0,dskRdy,gamePort0,gamePort1
 );
 CiaaPraFlagSet=SET OF CiaaPraFlags;

 CiaaPrbFlags=[0..7];
 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;

 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:SHORTCARD; pad4:Pad;
  tahi:SHORTCARD; pad5:Pad;
  tblo:SHORTCARD; pad6:Pad;
  tbhi:SHORTCARD; pad7:Pad;
  todlow:SHORTCARD; pad8:Pad;
  todmid:SHORTCARD; pad9:Pad;
  todhi:SHORTCARD; 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:SHORTCARD; pad4:Pad;
  tahi:SHORTCARD; pad5:Pad;
  tblo:SHORTCARD; pad6:Pad;
  tbhi:SHORTCARD; pad7:Pad;
  todlow:SHORTCARD; pad8:Pad;
  todmid:SHORTCARD; pad9:Pad;
  todhi:SHORTCARD; 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.
