|##########|
|#MAGIC   #|CLABLNCE
|#PROJECT #|"IMPORTALL"
|#PATHS   #|"StdProject"
|#FLAGS   #|xx-x-x--x---x-x-----------------
|#USERSW  #|--------------------------------
|#USERMASK#|--------------------------------
|#SWITCHES#|xx---xxxxx------
|##########|
(* $A- *)
DEFINITION MODULE Expansion;

FROM System IMPORT LONGSET, Register, SysStringPtr;
FROM Dos    IMPORT DeviceNodePtr, DosEnvec, DosEnvecPtr;
FROM Exec   IMPORT Interrupt, Library, LibraryPtr, List, Node,
                   SignalSemaphore;


TYPE
  ERomTypeFlags       = (er_mem0,er_mem1,er_mem2,chainedConfig,
                         diagValid,memList,er_type0,er_type1);
  ERomTypeFlagSet     = SET OF ERomTypeFlags;
  ExpansionRomFlags   = (erf0,erf1,erf2,erf3,zorro3,extended,noShutup,
                         memSpace);
  ExpansionRomFlagSet = SET OF ExpansionRomFlags;
  ExpansionRom        = RECORD
                          type          : ERomTypeFlagSet;
                          product       : SHORTCARD;
                          flags         : ExpansionRomFlagSet;
                          reserved03    : SHORTCARD;
                          manufacturer  : CARDINAL;
                          serialNumber  : LONGCARD;
                          initDiagVec   : CARDINAL;
                          reserved0c    : SHORTCARD;
                          reserved0d    : SHORTCARD;
                          reserved0e    : SHORTCARD;
                          reserved0f    : SHORTCARD
                        END;

  InterruptFlags      = (if0,intena,if2,reset,int2pend,int6pend,int7pend,
                         interrupting);
  InterruptFlagSet    = SET OF InterruptFlags;
  ExpansionControl    = RECORD
                          interrupt   : InterruptFlagSet;
                          z3HighBase  : SHORTCARD;
                          baseAddress : SHORTCARD;
                          shutup      : SHORTCARD;
                          reserved14  : SHORTCARD;
                          reserved15  : SHORTCARD;
                          reserved16  : SHORTCARD;
                          reserved17  : SHORTCARD;
                          reserved18  : SHORTCARD;
                          reserved19  : SHORTCARD;
                          reserved1a  : SHORTCARD;
                          reserved1b  : SHORTCARD;
                          reserved1c  : SHORTCARD;
                          reserved1d  : SHORTCARD;
                          reserved1e  : SHORTCARD;
                          reserved1f  : SHORTCARD;
                        END;


CONST
  slotSize            = $10000;
  slotMask            = $FFFF;
  slotShift           = 16;

  expansionBase       = $00E80000;
  z3ExpansionBase     = $FF000000;
  expansionSize       = $00080000;
  expansionSlots      = 8;
  memoryBase          = $00200000;
  memorySize          = $00800000;
  memorySlots         = 128;
  z3ConfigArea        = $40000000;
  z3ConfigAreaEnd     = $7FFFFFFF;
  z3SizeGranularity   = $00080000;

TYPE
  ConfigFlags         = (cf0,cf1,cf2,cf3,configTime,bindTime,byteWide,
                         wordWide);
  ConfigFlagSet       = SET OF ConfigFlags;
  DiagArea            = RECORD
                          config        : ConfigFlagSet;
                          flags         : SHORTCARD;
                          size          : CARDINAL;
                          diagPoint     : CARDINAL;
                          bootPoint     : CARDINAL;
                          name          : CARDINAL;
                          reserved01    : CARDINAL;
                          reserved02    : CARDINAL
                        END;

CONST
  busWidth            = ConfigFlagSet:{byteWide,wordWide};
  nibbleWide          = ConfigFlagSet:{};

  bootTime            = ConfigFlagSet:{configTime,bindTime};
  never               = ConfigFlagSet:{};

TYPE
  ConfigDevFlags      = (shutup,configMe,badMemory,cdf3,cdf4,cdf5,cdf6,
                         cdf7);
  ConfigDevFlagSet    = SET OF ConfigDevFlags;
  ConfigDevPtr        = POINTER TO ConfigDev;
  ConfigDev           = RECORD OF Node
                          flags       : ConfigDevFlagSet;
                          pad         : SHORTCARD;
                          rom         : ExpansionRom;
                          boardAddr   : ANYPTR;
                          boardSize   : LONGCARD;
                          slotAddr    : CARDINAL;
                          slotSize    : CARDINAL;
                          driver      : ANYPTR;
                          nextCD      : ConfigDevPtr;
                          unused      : ARRAY [0..3] OF LONGINT;
                        END;

TYPE
  CurrentBindingPtr   = POINTER TO CurrentBinding;
  CurrentBinding      = RECORD
                          configDev     : ConfigDevPtr;
                          fileName      : SysStringPtr;
                          productString : SysStringPtr;
                          toolTypes     : POINTER TO SysStringPtr;
                        END;

  BootNodeFlags       = (startProc,bnf1,bnf2,bnf3,bnf4,bnf5,bnf6,bnf7,
                         bnf8);
  BootNodeFlagSet     = SET OF BootNodeFlags;

  BootNodePtr         = POINTER TO BootNode;
  BootNode            = RECORD OF Node
                          flags       : BootNodeFlagSet;
                          deviceNode  : ANYPTR
                        END;

  ExpansionBaseFlags  = (clogged,shortmem,badmem,dosflag,kickback33,
                         kickback36,silentStart);
  ExpansionBaseFlagSet= SET OF ExpansionBaseFlags;

  ExpansionBasePtr    = POINTER TO ExpansionBaseType;
  ExpansionBaseType   = RECORD OF Library
                          flags       : ExpansionBaseFlagSet;
                          private01   : SHORTCARD;
                          private02   : LONGCARD;
                          private03   : LONGCARD;
                          private04   : CurrentBinding;
                          private05   : List;
                          mountList   : List;
                        END;

CONST
  errOk           = 0;
  errLastboard    = 40;
  errNoexpansion  = 41;
  errNomemory     = 42;
  errNoboard      = 43;
  errBadmem       = 44;

TYPE
  ParameterPktPtr = POINTER TO ParameterPkt;
  ParameterPkt    = RECORD
                      dosName   : SysStringPtr;
                      execName  : SysStringPtr;
                      unit      : LONGCARD;
                      flags     : LONGSET;
                      env       : DosEnvec;
                    END;

VAR ExpansionBase : ExpansionBasePtr;


LIBRARY ExpansionBase BY -30
  PROCEDURE AddConfigDev(configDev IN A0 : ConfigDevPtr);

LIBRARY ExpansionBase BY -36
  PROCEDURE AddBootNode(bootPri    IN D0 : SHORTINT;
                        flags      IN D1 : LONGSET;
                        deviceNode IN A0 : DeviceNodePtr;
                        configDev  IN A1 : ConfigDevPtr):BOOLEAN;

LIBRARY ExpansionBase BY -42
  PROCEDURE AllocBoardMem(slotSpec IN D0 : LONGINT);

LIBRARY ExpansionBase BY -78
  PROCEDURE FreeBoardMem(startSlot IN D0 : LONGCARD;
                         slotSpec  IN D1 : LONGCARD);


LIBRARY ExpansionBase BY -54
  PROCEDURE AllocExpansionMem(numSlots   IN D0 : LONGINT;
                              slotAlign  IN D1 : LONGINT;
                              slotOffset IN D2 : LONGINT):LONGINT;

LIBRARY ExpansionBase BY -90
  PROCEDURE FreeExpansionMem(startSlot IN D0 : LONGINT;
                             numSlots  IN D1 : LONGINT);

LIBRARY ExpansionBase BY -60
  PROCEDURE ConfigBoard(board     IN A0 : ANYPTR;
                        configDev IN A1 : ConfigDevPtr);

LIBRARY ExpansionBase BY -66
  PROCEDURE ConfigChain(baseAddr IN A0 : ANYPTR);


LIBRARY ExpansionBase BY -48
  PROCEDURE AllocConfigDev():ConfigDevPtr;

LIBRARY ExpansionBase BY -72
  PROCEDURE FindConfigDev(oldConfigDev IN A0 : ConfigDevPtr;
                          manufacturer IN D0 : LONGINT;
                          product      IN D1 : LONGINT):ConfigDevPtr;

LIBRARY ExpansionBase BY -84
  PROCEDURE FreeConfigDev(configDev IN A0 : ConfigDevPtr);

LIBRARY ExpansionBase BY -108
  PROCEDURE RemConfigDev(configDev IN A0 : ConfigDevPtr);

LIBRARY ExpansionBase BY -96
  PROCEDURE ReadExpansionByte(board  IN A0 : ANYPTR;
                              offset IN D0 : LONGINT):SHORTINT;

LIBRARY ExpansionBase BY -114
  PROCEDURE WriteExpansionByte(board  IN A0 : ANYPTR;
                               offset IN D0 : LONGCARD;
                               byte   IN D1 : SHORTCARD);


LIBRARY ExpansionBase BY -102
  PROCEDURE ReadExpansionRom(board     IN A0 : ANYPTR;
                             configDev IN A1 : ConfigDevPtr);


LIBRARY ExpansionBase BY -120 PROCEDURE ObtainConfigBinding;

LIBRARY ExpansionBase BY -126 PROCEDURE ReleaseConfigBinding;


LIBRARY ExpansionBase BY -132
  PROCEDURE SetCurrentBinding(currentBinding IN A0 : CurrentBindingPtr;
                              bindingSize    IN D0 : INTEGER);

LIBRARY ExpansionBase BY -138
  PROCEDURE GetCurrentBinding(currentBinding IN A0 : CurrentBindingPtr;
                              bindingSize    IN D0 : INTEGER):LONGINT;


LIBRARY ExpansionBase BY -144
  PROCEDURE MakeDosNode(parmPacket IN A0 : ParameterPktPtr):DeviceNodePtr;

LIBRARY ExpansionBase BY -150
  PROCEDURE AddDosNode(bootPri    IN D0 : SHORTINT;
                       flags      IN D1 : LONGSET;
                       deviceNode IN A0 : DeviceNodePtr):BOOLEAN;

END Expansion.

