       PROGRAM METAA
C   
C   
C   
C     META ASSEMBLER ASSEMBLY PROGRAM
C     FOR AMD 2900, INTEL 3000, ETC.
C     COPYRIGHT 1978
C     MICROTEC
C     P.O. BOX 60337
C     SUNNYVALE, CALIFORNIA 94088 
C 
C 
C 
C     THE VARIABLES PASSED IN COMMON ARE DEFINED BELOW
C 
C 
C     CVAL  = THE VALUE OF A NUMERIC CONSTANT OR LABEL
C     FLEN  = LENGTH OF DEFINITION FIELD CURRENTLY BEING SCANNED
C     FTYPE = FIELD TYPE FOR DEFS AND SUBS
C     IADDR = ARRAY TO HOLD HOLLERITH ADDRESS VALUES
C     IALPH = ALPHANUMERIC CHARACTER SET
C     IAMP  = HOST COMPUTER REPRESENTATION OF A HOLLERITH AMPERSAND 
C     IAST  = HOST COMPUTER REPRESENTATION OF A HOLLERITH ASTERISK
C     IATT  = LEGAL FIELD ATTRIBUTES OR MODIFIERS
C     IBIT  = NUMBER OF BITS PER HOST COMPUTER WORD 
C     IBLNK = HOST COMPUTER REPRESENTATION OF A HOLLERITH BLANK 
C     IBUG  = DEBUG PARAMETER 
C     ICCNT = NUMBER OF CHARACTERS PER HOST COMPUTER WORD 
C     ICNT  = LINE COUNT FOR SPACE DIRECTIVE
C     ICOLN = HOST COMPUTER REPRESENTATION OF A HOLLERITH COLON 
C     ICOMM = HOST COMPUTER REPRESENTATION OF A HOLLERITH COMMA 
C     ICOL  = CURRENT COLUMN NUMBER FOR SCAN
C     ICRD  = LOGICAL UNIT NUMBER OF DEFINITION FILE
C     ICTAB = HOST COMPUTER REPRESENTATION OF A TAB CHARACTER 
C     IDFLE = LOGICAL UNIT NUMBER OF DEFINITION FILE
C     IDIV  = HOST COMPUTER REPRESENTATION OF A HOLLERITH DIVIDE SIGN 
C     IDOLR = HOST COMPUTER REPRESENTATION OF A HOLLERITH DOLLAR SIGN 
C     IDREC = RECORD NUMBER FOR DIFINITION FILE 
C     IDUP  = DELAYED DUP DIRECTIVE COUNT 
C     IEND  = FLAG INDICATING END OF ASSEMBLY SOURCE
C     IERRL = ERROR INDICATOR FOR LABELS
C     IERRI = ERROR INDICATOR FOR OPCODES AND OPERANDS
C     IERR  = ERROR INDICATOR 
C     IERRS = TOTAL NUMBER OF ERRORS
C     IFBIT = MAXIMUM NUMBER OF BITS IN A FIELD 
C     IFCOL = FIRST COLUMN OF SCAN
C     IFLD  = FIELD DEFINITION TABLE
C     IFPAR = ARRAY FOR CONDITIONAL ASSEMBLY INFORMATION DURING NESTING 
C     ILEN  = EXPLICIT FIELD FENGTH FOR EXPRESSIONS AND DON"T CARES 
C     ILPAR = HOST COMPUTER REPRESENTATION OF A LEFT PARENTHESIS
C     IMFLE = LOGICAL UNIT NUMBER OF OPTIONAL INTERMEDIATE FILE 
C     IMIN  = HOST COMPUTER REPRESENTATION OF A HOLLERITH MINUS SIGN
C     IMREC = RECORD NUMBER FOR OPTIONAL INTERMEDIATE FILE
C     IMULT = HOST COMPUTER REPRESENTATION OF A HOLLERITH MULTIPLY SIGN 
C     IN    = INPUT BUFFER (FOR SCAN) 
ŠC     INB   = INPUT BUFFER (FOR CONTINUATION LINES) 
C     INDEX = INDEX OF CURRENT SYMBOL INTO SYMBOL TABLE 
C     INDET = INDEX OF LABEL INTO SYMBOL TABLE
C     IOBIN = OBJECT MODULE RECORD BUFFER 
C     IOFLG = FLAG THAT INDICATES NOTHING WRITTEN TO OBJECT MODULE FILE 
C     IOLIN = NUMBER OF LINES PER OUTPUT PAGE 
C     IOPVA = OPCODE VALUE
C     IOREC = RECORD NUMBER FOR OUTPUT OBJECT MODULE FILE 
C     IOVER = INSTRUCTION OVERLAY INDICATOR 
C     IPAGE = CURRENT PAGE NUMBER 
C     IPASS = PASS FLAG, 1=PASS 1, 2=PASS 2
C     IPCH  = LOGICAL UNIT NUMBER OF OUTPUT OBJECT MODULE 
C     IPDEF = FLAG THAT INDICATES SYMBOL MUST BE DEFINED BEFORE USE 
C     IPLUS = HOST COMPUTER REPRESENTATION OF A HOLLERITH PLUS SIGN 
C     IPRT  = LOGICAL UNIT NUMBER OF OUTPUT LISTING DEVICE
C     IRPAR = HOST COMPUTER REPRESENTATION OF A RIGHT PARENTHESIS 
C     ISEMI = HOST COMPUTER REPRESENTATION OF A HOLLERITH SEMICOLON 
C     ISHRP = HOST COMPUTER REPRESENTATION OF A HOLLERITH SHARP SIGN
C     ISYM  = NUMBER OF SYMBOLS IN SYMBOL TABLE 
C     ITAB  = SYMBOL TABLE
C     ITABS = SYMBOL TYPE, E.G. DEF,SUB,SET, OR ORDINARY SYMBOL 
C     ITABV = NUMERIC VALUE OF SYMBOL 
C     ITYPE = OPCODE TYPE 
C     IWORD = NUMBER OF WORDS IN HOST COMPUTER PER LABEL
C     IXCNT = NUMBER OF CROSS REFERENCE PAGES 
C     IXPNT = POINTER INTO CROSS REFERENCE TABLE
C     IXPAG = CROSS REFERENCE TABLE PAGE NUMBER 
C     IXTAB = CORE RESIDENT CROSS REFERENCE ARRAY 
C     IXT   = CROSS REFERENCE DISK RECORD 
C     IYFLD = NEXT INDEX INTO FIELD TABLE 
C     IZFLD = LENGTH OF FIELD TABLE 
C     JATT  = FIELD ATTRIBUTES OR MODIFIERS PRESENT IN A SUBSTIUTION
C     JBASE = DEFAULT BASE INDEX
C     JCOL  = COLUMN THAT A LABEL ENDS IN 
C     JREAD = FLAG THAT INDICATES NEXT SOURCE LINE HAS ALREADY BEEN READ
C     JTYPE = SYMBOL TYPE 
C     KFILE = FLAG THAT INDICATES WHETHER INTERMEDIATE FILE EXISTS
C     KLEN  = IMPLICIT FIELD LENGTH FOR CONSTANTS
C     KWORD = NUMBER OF BITS IN A WORD
C     LATT  = FIELD ATTRIBUTES PRESENT IN A DEFINITION FIELD
C     LC    = ASSEMBLY PROGRAM COUNTER
C     LCMAX = MAXIMUM ADDRESS ASSEMBLED 
C     LCMIN = MINIMUM ADDRESS ASSEMBLED
C     LDEF  = FLAG TO INDICATE THAT DEFINITION FILE WILL BE PRODUCED
C     LEN   = LENGTH OF CURRENT ASSEMBLER INSTRUCTION OR DIRECTIVE
C     LEND  = FLAG INDICATING END OF CURRENT SOURCE LINE
C     LIF   = FLAG TO INDICATE WHETHER IF STATEMENTS WILL BE EXPANDED 
C     LINE  = OUTPUT PAGE LINE COUNT
C     LINEL = LENGTH OF SOURCE LINE WITH TRAILING BLANKS DELETED
C     LINV  = FLAG TO INDICATE OBJECT MODULE BITS ARE TO BE INVERTED
C     LISN  = LINE NUMBER PRINTED ON LISTING
C     LLEN  = EXPLICIT FIELD LENGTH FOR CONSTANTS 
C     LOBJ  = FLAG TO INDICATE WHETHER OBJECT MODULE IS TO BE PRODUCED
C     LOBJ1 = FLAG TO INDICATE INTERLEAVED LISTING IS TO BE PRODUCED
C     LOBJ2 = FLAG TO INDICATE OBJECT MODULE IS TO BE LISTED IN BLOCK 
ŠC     LOCT  = OCTAL/HEXADECIMAL LIST FLAG 
C     LODLC = ADDRESS OF LAST OBJECT MODULE WORD ASSEMBLED
C     LREF  = FLAG TO INDICATE A CROSS REFERENCE TABLE WILL BE LISTED 
C     LSOR  = FLAG TO INDICATE SOURCE WILL BE LISTED
C     LSYM  = FLAG TO INDICATE THAT A SYMBOL TABLE WILL BE LISTED 
C     LTAB  = SYMBOL TABLE LENGTH
C     LTITL = TITLE ARRAY 
C     LWORD = LENGTH OF OBJECT MODULE RECORDS 
C     MCFLE = LOGICAL UNIT NUMBER OF INTERMEDIATE FILE
C     MCOL  = LAST COLUMN OF SCAN 
C     MCORE = BUFFER USED TO WRITE TO CROSS REFERENCE DISK FILE
C     MCREC = RECORD NUMBER FOR INTERMEDIATE FILE 
C     MLAB  = MAXIMUM LABEL LENGTH
C     MLCOL = LAST COLUMN PRINTED ON OUTPUT LISTING 
C     MOPC  = MAXIMUM OPCODE LENGTH 
C     MXREF = SIZE OF CORE RESIDENT CROSS REFERENCE ARRAY 
C     NAME  = BUFFER THAT HOLDS SYMBOL
C     NBASE = DEFAULT BASE FOR NUMBERS
C     NDUP  = DUP DIRECTIVE COUNT 
C     NFLAG = SCAN FLAG THAT ALLOWS "3F5H" TYPE CONSTANTS TO BE READ
C     ZVAL  = MAXIMUM VALUE OF ANY NUMBER OR CONSTANT 
C   
C   
C     THE MAIN ROUTINE CALLS THE MAJOR SUBROUTINES
C   
      REAL IVAL
      INTEGER FTYPE,FLEN
      REAL ITABV(384),LC,LODLC,LCMAX
      COMMON ICRD,IPRT,IPCH,MCFLE,IMFLE,IDFLE,MCREC,IMREC,IDREC,IOREC
      COMMON MLAB,MOPC,IBIT,ICCNT,IWORD,IERRL,IERRI,IEND,LEND,IFRMC
      COMMON LSOR,LIF,LSYM,LREF,LDEF,LOCT,LOBJ,LOBJ1,LOBJ2,LINV
      COMMON ILEN,KLEN,LLEN,FLEN,KWORD,IYFLD,IZFLD
      COMMON IDUP,NDUP,NFLAG,IOFLG,LWORD,LINEL,KFILE
      COMMON IFBIT,ZVAL,CVAL,JREAD,IN(80),INB(80),LINE,IPAGE,LISN
      COMMON IALPH(37),IAST,IDOLR,ISHRP,IAMP,ICOLN
      COMMON IBLNK,ICTAB,ISEMI,ICOMM,IPLUS,IMIN,IMULT,IDIV
      COMMON IRPAR,ILPAR,IATT(9),JATT(5),LATT(9),IFPAR(16),NBASE,JBASE
      COMMON ICOL,IFCOL,MCOL,MLCOL,IOLIN,ICNT,LTITL(50),IADDR(4,12)
      COMMON ITYPE,JTYPE,FTYPE,IERR,IERRS,IOPVA,JCOL,IBUG,IOVER
      COMMON IPASS,LC,IOBIN(128),IPDEF,LODLC,LCMAX,LCMIN,LEN
      COMMON ITAB(4,384),ITABS(384),ITABV,NAME(4),INDEX,INDET
      COMMON ISYM,LTAB,IFORM,ITRUN,ILOUT,IXCOL,NUMER,ITRMI,ITRMO
      COMMON IXTAB(768),MXREF,IXT,IXPNT,IXCNT,IXPAG,MCORE(128)
C
C
C	THE NAMED COMMON VARIABLE IFLD(400) IS A DUMMY ENTRY POINT FOR
C	A MUCH LARGER ARRAY -- 2000 INTEGERS.  THIS METHOD OF 
C	DEFINITION OF THE LARGE ARRAY IFLD WAS CHOSEN IN ORDER TO 
C	FOOL THE MICROSOFT LINKER INTO ALLOWING THE ARRAY OR SOME
C	PORTION OF THE CODE TO OVERLAY AN AREA OF CODE WHICH IS 
C	OCCUPIED BY THE LINKER.
C
C	AT LINK TIME, THIS ARRAY IS SET AT THE END OF THE DATA
C	AREA BY USE OF THE /D:xxxx STATEMENT.  ALL CODE IS PLACED
C	BEGINNING AT 103HEX AND ALL DATA AT THE END OF THE MEMORY.
C	BY LINKING THE DUMCMN.REL ROUTINE FIRST, THIS ARRAY
C	MAY BE FORCED TO THE END OF THE AREA USED BY THE PROGRAM,
C	AND ALLOW ALL OF THE REMAINING MEMORY UPTO THE STACK TO
C	TO BE USED AS THE IFLD ARRAY.  THIS CAN FREE UP ALL 2000
C	BYTES OF DATA FOR THE IFLD ARRAY.  IN THE INIT.FOR
C	PROGRAM IT IS INITIALLY DEFINED TO BE 2000 INTEGERS IN 
C	LENGTH.
C
      COMMON /OVRLAY/IFLD(400)
C INCLUDE(:F1:METAA.COM)
      EQUIVALENCE (IALPH(11),ICHRA)
C   
C     IF POSSIBLE, THE META ASSEMBLER DEFINITION FILE PRODUCED BY 
C     THE DEFINITION PROGRAM SHOULD BE A SEQUENTIAL FILE. 
C     THIS WILL CONSERVE DISK STORAGE.  HOWEVER, IF NECESSARY 
C     THE FILE CAN BE RANDOM ACCESS.  THE FOLLOWING DEFINE FILE 
C     STATEMENT DEFINES THE META ASSEMBLER DEFINITION FILE AND IS 
C     INCLUDED FOR INFORMATION PURPOSES ONLY.  NOTE THE STATEMENT
C     IS A COMMENT.
C     THE DEFINITION FILE (SYMBOLIC FILE NUMBER 9) CONSISTS OF
C     500 128-WORD RECORDS.  U INDICATES A BINARY FILE.  THE NAME
ŠC     IDREC IS THE RECORD INDEX.
C     VARIOUS COMPUTERS DEFINE FILES IN DIFFERENT WAYS.  THIS FILE
C     MIGHT HAVE TO BE DEFINED DIFFERENTLY ON  YOUR COMPUTER.
C   
C     DEFINE FILE 9(500,128,U,IDREC)
C   
C     THE FOLLOWING DEFINE FILE STATEMENT DEFINES AN INTERMEDIATE FILE
C     USED TO ACCUMULATE REFERENCES FOR THE CROSS REFERENCE TABLE.
C     IF THE USER WISHES TO ACCUMULATE A LIMITED NUMBER OF REFERENCES
C     IN MEMORY, THIS FILE IS NOT REQUIRED.  THIS FILE IS TEMPORARY
C     AND CAN BE DELETED AFTER PROGRAM EXECUTION.
C     THE DEFINE FILE PARAMETERS ARE SIMILAR TO THE PREVIOUS
C     DEFINE FILE AND AS WITH IT, THIS FILE MAY BE A SEQUENTIAL FILE.
C   
C     DEFINE FILE 8(100,128,U,MCREC)
C     CALL OPEN ( 8,FORM,0)
C   
C     THE FOLLOWING DEFINE FILE STATEMENT DEFINES AN INTERMEDIATE
C     FILE THE ASSEMBLER SOURCE IS COPIED TO.  THE ASSEMBLER SOURCE
C     IS READ TWICE BY THE PROGRAM, ONCE IN PASS 1 AND ONCE IN
C     PASS 2.  USE OF AN INTERMEDIATE FILE MAKES IT UNNECESSARY TO
C     READ THE SOURCE TWICE IF IT IS COMMING FROM A DEVICE SUCH AS
C     A CARD READER.  IF THE SOURCE RESIDES ON A REWINDABLE FILE,
C     THIS INTERMEDIATE FILE IS NOT NEEDED.  SEE OPERATION NOTES
C     NOTE, THE FILE MAY BE SEQUENTIAL
C   
C     DEFINE FILE 7(1000,80,U,IMREC)
C   
C   
C     THE USER MAY WANT TO OPEN A DISK FILE FOR THE OUTPUT OBJECT
C     MODULE AT THIS POINT.  SEE OPERATION NOTES FOR DETAILS
C   
C     DEFINE 4(200,128,U,IOREC)
C   
C     BRING IN FIRST OVERLAY
      IERR = 0
C     CALL ALOAD(IERR)
      IF(IERR .EQ. 0) GO TO 20
      WRITE(6,6000)
6000  FORMAT(' METAA.OV1 NOT FOUND')
      STOP
20    CONTINUE
C     INITIALIZE PROGRAM VARIABLES
      CALL INIT 
C     OPEN DEFINITION, ASSEMBLY SOURCE, AND OUTPUT FILES
      CALL FOPEN
C     READ DEFINITION FILE
      CALL INOUT(2) 
C     BRING IN SECOND OVERLAY
      IERR = 0
C     CALL ALOAD(IERR)
      IF(IERR .EQ. 0) GO TO 30
      WRITE(6,6001)
6001  FORMAT(' METAA.OV2 NOT FOUND')
      STOP
Š30    CONTINUE
C     PERFORM PASS 1 OF ASSEMBLY, BUILD SYMBOL TABLE
      IPASS = 1
      CALL XPASS
C     REWIND SOURCE OR INTERMEDIATE FILE
      IF(KFILE) 40,45,40
40    REWIND IMFLE
      GO TO 50
45    REWIND ICRD 
C     SET MAXIMUM PROGRAM COUNTER 
50    LCMAX = LC
C     INITIALIZE VARIABLES FOR PASS 2
      LC = 0.
      IEND = 0
      LISN = 0
      LSOR = 1
      LSYM = 1
      LREF = 0
      LIF  = 0
      LOBJ = 1
      LOCT = 0
      LOBJ1 = 1
      LOBJ2 = 0
      LINV = 0
      IDUP = 0
      NDUP = 0
      NFLAG = 0
      JREAD = 0
      IOVER = 0
C     PERFORM PASS 2 OF ASSEMBLY, GENERATE LISTING AND OBJECT MODULE
      IPASS = 2
      CALL XPASS
C     CHECK TO SEE IF SYMBOL OR CROSS REFERENCE TABLE IS TO BE CREATED
      IF(LSYM+LREF) 400,400,100
100   IF(IFORM.NE.0) GO TO 105
      WRITE(IPRT,1012)
      GO TO 110
105   WRITE(IPRT,1001) IFRMC
110   WRITE(IPRT,1000) LTITL,IPAGE
1000  FORMAT(9X,50A1,4X,5HPAGE ,I3,/,/)
      IF(LREF) 200,200,250
200   WRITE(IPRT,1010)
1010  FORMAT(32X,12HSYMBOL TABLE,/)
      LINE = 5
      GO TO 300
250   WRITE(IPRT,1011)
1011  FORMAT(24X,21HCROSS REFERENCE TABLE,//,
     1  6H LABEL,4X,4HTYPE,3X,5HVALUE,10X,10HREFERENCES)
      LINE = 6
C     BRING IN THIRD OVERLAY
300   IERR = 0
C     CALL ALOAD(IERR)
      IF(IERR .EQ. 0) GO TO 310
      WRITE(6,6002)
6002  FORMAT(' METAA.OV3 NOT FOUND')
Š      STOP
310   CALL SYMTA
C     CHECK FOR OBJECT CODE BLOCK FORMAT
400   IF(LOBJ2) 500,900,500
500   IF(IFORM .EQ. 1) GO TO 501
      WRITE(IPRT,1012)
      GO TO 5015
501   WRITE(IPRT,1001) IFRMC
5015  CONTINUE
      WRITE(IPRT,1002)
1002  FORMAT(16X,13HOBJECT MODULE,/)
      IF(IOFLG) 502,900,502
502   IOREC = 1
      REWIND IPCH
C     SKIP FIRST RECORD
      I = IOREC
      CALL INOUT(8)
      IOREC = IOREC+1
505   I = IOREC
      CALL INOUT(8)
      IOREC = I+1
C     CHECK FOR END OF OBJECT MODULE
      IF(IOBIN(2)-IDOLR) 510,900,510
C     CHECK FOR NEW ORIGIN ADDRESS
510   IF(IOBIN(2)-ICHRA) 515,520,515
C     INCREMENT ADDRESS
515   IVAL = IVAL+1.
      GO TO 525
C     READ OBJECT MODULE ADDRESS ON "A" RECORD
520   ICOL = 4
      NFLAG = 1
      DO 522 I=1,10
      IN(I) = IOBIN(I)
522   CONTINUE
      CALL NUMB(0)
      IVAL = CVAL-1.
      GO TO 505
C     CONVERT ADDRESS TO BINARY HOLLERITH
525   CALL AHEX(IVAL,1)
      K = 65
      IF(KWORD-64) 530,530,540
530   K = 2
      GO TO 550
540   WRITE(IPRT,2000) (IADDR(1,I),I=6,12),(IOBIN(I),I=1,64)
2000  FORMAT(1X,7A1,2X,4(16A1,1X))
550   WRITE(IPRT,2000) (IADDR(1,I),I=6,12),(IOBIN(I),I=K,KWORD)
      GO TO 505
900   IF(IFORM.NE.0) GO TO 910
      WRITE(IPRT,1012)
1012  FORMAT(//////)
      GO TO 990
910   WRITE(IPRT,1001) IFRMC
1001  FORMAT (A1)
990   CONTINUE
      END
Š,1012)
1012  FORMAT(//////)
      GO TO 990
910   WRITE(IPRT,1001) IFRMC
1001  FORMAT (A1)
990   CONTINUE
      END
Š