{$A+,B-,D+,E-,F-,G-,I-,L+,N-,O-,R-,S-,V-,X-}
{$IFDEF VER70}
{$P-,Q-,T-}
{$ENDIF}
unit
  AVars;

interface

type
  PathStr = string[79];

const
  Errs  : Integer = 0;
  Diag  : Integer = 0;
  Delim : set of char = [' ',',',#9];
  CmdDelim : set of char = [' ',',',#9];

  { flag values }
  _MachOp       = $0001;
  _AutoW        = $0004;
  { bits 3-5 reserved for ext. values }
  _AddReg       = $0040;
  _NeedExt      = $0080;
  _NeedDisp8    = $0100;
  _NeedDisp16   = $0200;
  _NeedModeByte = $0400;
  _NeedImmed8   = $0800;
  _NeedImmed    = $1000;
  _Direction    = $2000;
  _NeedMem      = $4000;
  _AutoC        = $8000;

  { operand types }
  _Acum8   = $0001;
  _Acum16  = $0002;
  _Reg8    = $0004;
  _Reg16   = $0008;
  _MemReg  = $0010;
  _CS      = $0020;
  _Seg     = $0040;
  _Mem     = $0080;
  _Immed8  = $0100;
  _Immed16 = $0200;
  _None    = $0400;
  _String  = $0800;
  _Near    = $1000;
  _Far     = $2000;
  _CL      = $4000;

const
  MaxObj = 50;
  MaxStk = 10;
  StkTop : Word = 0;
  BytesGen : Word = 0;

const
  { Exit code constants }
  exHelpShown         = $01;

  exError             = $80;
  exInternalError     = $40;

  exFileNotFound      = $02;
  exFileReadError     = $03;
  exFileCreateError   = $04;
  exFileWriteError    = $05;
  exUnknownOption     = $06;
  exTooManyParameters = $07;

var
  Obj      : Array [1..MaxObj] of Word;
  ProcType : Array [1..MaxStk] of Word;

var
  { Files - input, listing, xref, output }
  InFile, LstFile, XrefFile, InlFile : Text;
  OutFile                            : File;

  { File names }
  InFileName, LstFileName, XrefFileName, OutFileName : PathStr;
  SearchPath : PathStr;

const
  { page }
  LWidth  : Integer = 79;
  LinesPerPage : Integer = 64;
  LLine   : Integer = 1;
  PageNum : Integer = 1;

var
  Pass    : Integer; { current pass number }
  Loctr   : Integer; { position into code }
  LineNum : Integer;

var
  { assembler parse variables }
  _Label  : String;
  _Op     : String;
  _Source : String;
  _Dest   : String;
  _Fld    : String;
  _Target : String;
  _Reg    : String;
  _Disp   : String;

  InpLine : String;
  { position(s) into InpLine }
  LinePtr1, LinePtr2, LinePtr, EndPtr, OpdPtr : Integer;
  Found : Boolean;  { TRUE if field in InpLine found (GetField()) }

  TablePtr : Integer; { last found position into the Sym table }

  NeedOffset : Word;

  NumLow, NumHigh : word;

const
  ObjLen     : Word = 0;
  DSFlag     : Boolean = FALSE;

type
  String3 = String[3];

const
  { Program title and copyright }
  ProcTitle     : string[24]  = '"A" Assembler  Version 1.0';
  Copyright     : string[34]  = 'Copyright (c) 1993 Serge Kostigoff';

const
  { File extensions }
  InFileExt   : string3 = 'A';
  OutFileExt  : string3 = 'COM';
  LstFileExt  : string3 = 'LST';
  XrefFileExt : string3 = 'XRF';

const
  { start messages }
  UnknownOption     : string[16]  = 'Unknown option: ';
  Usage             : string[20]  = 'Usage: A /h for Help';
  TooManyParameters : string[21]  = 'Too many parameters: ';

const
  { warning messages }
  WarnString : string[10] = '*Warning* ';
  SpecifyWordOrByteOperation : string[30] = 'Specify word or byte operation';
  CouldUseJMPS               : string[14] = 'Could use JMPS';

const
  { error messages }
  ErrString  : string[10] = '**Error** ';

  DuplicateDefinition : string[24] = 'Duplicate definition of ';
  UndefinedSymbol     : string[17] = 'Undefined symbol ';
  TooManySymbols      : string[21] = 'Too many user symbols';
  IllegalArgument     : string[40] = 'Illegal or undefined argument for Offset';
  TooFarForShortJump  : string[22] = 'Too far for short jump';
(*  IllegalReverseJump  : string[25] = 'Illegal reverse long jump'; *)
  DataTooLong         : string[13] = 'Data too long';
  equWithoutSymbol    : string[18] = 'EQU without symbol';
  equWithForwardRef   : string[26] = 'EQU with forward reference';
  UnrecognizedOperand : string[20] = 'Unrecognized operand';
  ProcsNestedTooDeeply: string[23] = 'PROCs nested too deeply';
  ENDPwithoutPROC     : string[17] = 'ENDP without PROC';
  MissingENDP         : string[12] = 'Missing ENDP';
  SyntaxError         : string[13] = 'Syntax error ';
  PhaseError          : string[11] = 'Phase error';

const
  { final proc messages }
  ErrorMessages       : string[15] = 'Error messages:';
  WarningMessages     : string[17] = 'Warning messages:';
  Passes              : string[07] = 'Passes:';
  Memory              : string[17] = 'Remaining memory:';

const
  PageString          : string[ 5] = 'Page ';

const
  HexDigits : string[16] = '0123456789ABCDEF';

const
  _Word      : Boolean = TRUE;   { word operation by default }

var
  { target code generator variables }
  TargType   : Word; { type of target, see "_" flags }
  TargVal1   : Word;
  TargVal2   : Word;

  DType      : word;
  DVal1      : word;
  DVal2      : word;

  SType      : word;
  SVal1      : word;
  SVal2      : word;

  IVal       : Integer;

  DSVal      : word;

  NumVal     : word;
  NumType    : word;
  MemAddr    : word;
  RegVal     : word;
  OffsetVal  : word;
  OffsetType : word;
  CharVal    : word;

  OpPtr      : word;

  Flag       : word;

  Offset     : Integer; { special case to check < 0 }

implementation

end.
