home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 149_01 / a68.h < prev    next >
Text File  |  1989-01-13  |  12KB  |  399 lines

  1. /*
  2.     HEADER:        CUG149;
  3.     TITLE:        6801 Cross-Assembler (Portable);
  4.     FILENAME:    A68.H;
  5.     VERSION:    3.5;
  6.     DATE:        08/27/1988;
  7.  
  8.     DESCRIPTION:    "This program lets you use your computer to assemble
  9.             code for the Motorola 6800, 6801, 6802, 6803, 6808,
  10.             and 68701 microprocessors.  The program is written in
  11.             portable C rather than BDS C.  All assembler features
  12.             are supported except relocation, linkage, and macros.";
  13.  
  14.     KEYWORDS:    Software Development, Assemblers, Cross-Assemblers,
  15.             Motorola, MC6800, MC6801;
  16.  
  17.     SEE-ALSO:    CUG113, 6800 Cross-Assembler;
  18.  
  19.     SYSTEM:        CP/M-80, CP/M-86, HP-UX, MSDOS, PCDOS, QNIX;
  20.     COMPILERS:    Aztec C86, Aztec CII, CI-C86, Eco-C, Eco-C88, HP-UX,
  21.             Lattice C, Microsoft C,    QNIX C;
  22.  
  23.     WARNINGS:    "This program has compiled successfully on 2 UNIX
  24.             compilers, 5 MSDOS compilers, and 2 CP/M compilers.
  25.             A port to BDS C would be extremely difficult, but see
  26.             volume CUG113.  A port to Toolworks C is untried."
  27.  
  28.     AUTHORS:    William C. Colley III;
  29. */
  30.  
  31. /*
  32.               6801 Cross-Assembler in Portable C
  33.  
  34.            Copyright (c) 1985 William C. Colley, III
  35.  
  36. Revision History:
  37.  
  38. Ver    Date        Description
  39.  
  40. 3.0    APR 1985    Recoded from BDS C version 2.5.  WCC3.
  41.  
  42. 3.1    AUG 1985    Greatly shortened the routines find_symbol() and
  43.             new_symbol().  Fixed bugs in expression evaluator.
  44.             Added compilation instructions for Aztec C86,
  45.             Microsoft C, and QNIX C.  Added optional optimizations
  46.             for 16-bit machines.  Adjusted structure members for
  47.             fussy compilers.  WCC3.
  48.  
  49. 3.2    SEP 1985    Added the INCL pseudo-op and associated stuff.  WCC3.
  50.  
  51. 3.3    JUL 1986    Added compilation instructions and tweaks for CI-C86,
  52.             Eco-C88, and Lattice C.  WCC3.
  53.  
  54. 3.4    JAN 1987    Fixed bug that made "FCB 0," legal syntax.  WCC.
  55.  
  56. 3.5    AUG 1988    Fixed a bug in the command line parser that puts it
  57.             into a VERY long loop if the user types a command line
  58.             like "A68 FILE.ASM -L".  WCC3 per Alex Cameron.
  59.  
  60. This header file contains the global constants and data type definitions for
  61. all modules of the cross-assembler.  This also seems a good place to put the
  62. compilation and linkage instructions for the animal.  This list currently
  63. includes the following compilers:
  64.  
  65.         Compiler Name        Op. Sys.    Processor
  66.  
  67.     1)  Aztec C86            CP/M-86        8086, 8088
  68.                     MSDOS/PCDOS
  69.  
  70.     2)  AZTEC C II            CP/M-80        8080, Z-80
  71.  
  72.     3)  Computer Innovations C86    MSDOS/PCDOS    8086, 8088
  73.  
  74.     4)  Eco-C            CP/M-80        Z-80
  75.  
  76.     5)  Eco-C88            MSDOS/PCDOS    8086, 8088
  77.  
  78.     6)  HP C            HP-UX        68000
  79.  
  80.     7)  Lattice C            MSDOS/PCDOS    8086, 8088
  81.  
  82.     8)  Microsoft C            MSDOS/PCDOS    8086, 8088
  83.  
  84.     9)  QNIX C            QNIX        8086, 8088
  85.  
  86. Further additions will be made to the list as users feed the information to
  87. me.  This particularly applies to UNIX and IBM-PC compilers.
  88.  
  89. Compile-assemble-link instructions for this program under various compilers
  90. and operating systems:
  91.  
  92.     1)    Aztec C86:
  93.  
  94.     A)  Uncomment out the "#define AZTEC_C 1" line and comment out all
  95.         other compiler names in A68.H.
  96.  
  97.     B)  Assuming that all files are on drive A:, run the following sequence
  98.         of command lines:
  99.  
  100.         A>cc a68
  101.         A>cc a68eval
  102.         A>cc a68util
  103.         A>ln a68.o a68eval.o a68util.o -lc
  104.         A>era a68*.o
  105.  
  106.     2)  Aztec CII (version 1.06B):
  107.  
  108.     A)  Uncomment out the "#define AZTEC_C 1" line and comment out all
  109.         other compiler names in A68.H.
  110.  
  111.     B)  Assuming the C compiler is called "CC.COM" and all files are
  112.         on drive A:, run the following sequence of command lines:
  113.  
  114.         A>cc a68
  115.         A>as -zap a68
  116.         A>cc a68eval
  117.         A>as -zap a68eval
  118.         A>cc a68util
  119.         A>as -zap a68util
  120.         A>ln a68.o a68eval.o a68util.o -lc
  121.         A>era a68*.o
  122.  
  123.     3)  Computer Innovations C86:
  124.  
  125.     A)  Uncomment out the "#define CI_C86 1" line and comment out all
  126.         other compiler names in A68.H.
  127.  
  128.     B)  Compile the files A68.C, A68EVAL.C, and A68UTIL.C.  Link
  129.         according to instructions that come with the compiler.
  130.  
  131.     4)  Eco-C (CP/M-80 version 3.10):
  132.  
  133.     A)  Uncomment out the "#define ECO_C 1" line and comment out all
  134.         other compiler names in A68.H.
  135.  
  136.     B)  Assuming all files are on drive A:, run the following sequence of
  137.         command lines:
  138.  
  139.         A>cp a68 -i -m
  140.         A>cp a68eval -i -m
  141.         A>cp a68util -i -m
  142.         A>l80 a68,a68eval,a68util,a68/n/e
  143.         A>era a68*.mac
  144.         A>era a68*.rel
  145.  
  146.     5)  Eco-C88:
  147.  
  148.     A)  Uncomment out the "#define ECO_C 1" line and comment out all
  149.         other compiler names in A68.H.
  150.  
  151.     B)  Compile the files A68.C, A68EVAL.C, and A68UTIL.C.  Link
  152.         according to instructions that come with the compiler.
  153.  
  154.     6)  HP-UX (a UNIX look-alike running on an HP-9000 Series 200/500,
  155.     68000-based machine):
  156.  
  157.     A)  Uncomment out the "#define HP_UX 1" line and comment out all
  158.         other compiler names in A68.H.
  159.  
  160.     B)  Run the following command line:
  161.  
  162.         . cc a68.c a68eval.c a68util.c
  163.  
  164.     7)  Lattice C:
  165.  
  166.     A)  Uncomment out the "#define LATTICE_C 1" line and comment out all
  167.         other compiler names in A68.H.
  168.  
  169.     B)  Compile the files A68.C, A68EVAL.C, and A68UTIL.C.  Link
  170.         according to instructions that come with the compiler.
  171.  
  172.     8)  Microsoft C (version 3.00):
  173.  
  174.     A)  Uncomment out the "#define MICROSOFT_C 1" line and comment out
  175.         all other compiler names in A68.H.
  176.  
  177.     B)  Run the following command line:
  178.  
  179.         C>cl a68.c a68eval.c a68util.c
  180.  
  181.     9)    QNIX C:
  182.  
  183.     A)  Uncomment out the "#define QNIX 1" line and comment out all other
  184.         compiler names in A68.H.
  185.  
  186.     B)  Run the following command line:
  187.  
  188.         . cc a68.c a68eval.c a68util.c
  189.  
  190. Note that, under CP/M-80, you can't re-execute a core image from a previous
  191. assembly run with the "@.COM" trick.  This technique is incompatible with the
  192. Aztec CII compiler, so I didn't bother to support it at all.
  193. */
  194.  
  195. #include <stdio.h>
  196.  
  197. /*  Comment out all but the line containing the name of your compiler:    */
  198.  
  199. #define        AZTEC_C        1
  200. /* #define    CI_C86        1                    */
  201. /* #define    ECO_C        1                    */
  202. /* #define    HP_UX        1                    */
  203. /* #define    LATTICE_C    1                    */
  204. /* #define    MICROSOFT_C    1                    */
  205. /* #define    QNIX        1                    */
  206.  
  207. /*  Compiler dependencies:                        */
  208.  
  209. #ifdef    AZTEC_C
  210. #define    getc(f)        agetc(f)
  211. #define    putc(c,f)    aputc(c,f)
  212. #endif
  213.  
  214. #ifndef    ECO_C
  215. #define    FALSE        0
  216. #define    TRUE        (!0)
  217. #endif
  218.  
  219. #ifdef    LATTICE_C
  220. #define    void        int
  221. #endif
  222.  
  223. #ifdef    QNIX
  224. #define    fprintf        tfprintf
  225. #define    printf        tprintf
  226. #endif
  227.  
  228. /*  On 8-bit machines, the static type is as efficient as the register    */
  229. /*  type and far more efficient than the auto type.  On larger machines    */
  230. /*  such as the 8086 family, this is not necessarily the case.  To    */
  231. /*  let you experiment to see what generates the fastest, smallest code    */
  232. /*  for your machine, I have declared internal scratch variables in    */
  233. /*  functions "SCRATCH int", "SCRATCH unsigned", etc.  A SCRATCH    */
  234. /*  varible is made static below, but you might want to try register    */
  235. /*  instead.                                */
  236.  
  237. #define    SCRATCH        static
  238.  
  239. /*  A slow, but portable way of cracking an unsigned into its various    */
  240. /*  component parts:                            */
  241.  
  242. #define    clamp(u)    ((u) &= 0xffff)
  243. #define    high(u)        (((u) >> 8) & 0xff)
  244. #define    low(u)        ((u) & 0xff)
  245. #define    word(u)        ((u) & 0xffff)
  246.  
  247. /*  The longest source line the assembler can hold without exploding:    */
  248.  
  249. #define    MAXLINE        255
  250.  
  251. /*  The maximum number of source files that can be open simultaneously:    */
  252.  
  253. #define    FILES        4
  254.  
  255. /*  The fatal error messages generated by the assembler:        */
  256.  
  257. #define    ASMOPEN        "Source File Did Not Open"
  258. #define    ASMREAD        "Error Reading Source File"
  259. #define    DSKFULL        "Disk or Directory Full"
  260. #define    FLOFLOW        "File Stack Overflow"
  261. #define    HEXOPEN        "Object File Did Not Open"
  262. #define    IFOFLOW        "If Stack Overflow"
  263. #define    LSTOPEN        "Listing File Did Not Open"
  264. #define    NOASM        "No Source File Specified"
  265. #define    SYMBOLS        "Too Many Symbols"
  266.  
  267. /*  The warning messages generated by the assembler:            */
  268.  
  269. #define    BADOPT        "Illegal Option Ignored"
  270. #define    NOHEX        "-o Option Ignored -- No File Name"
  271. #define    NOLST        "-l Option Ignored -- No File Name"
  272. #define    TWOASM        "Extra Source File Ignored"
  273. #define    TWOHEX        "Extra Object File Ignored"
  274. #define    TWOLST        "Extra Listing File Ignored"
  275.  
  276. /*  Line assembler (A68.C) constants:                    */
  277.  
  278. #define    BIGINST        3        /*  longest instruction length    */
  279. #define    IFDEPTH        16        /*  maximum IF nesting level    */
  280. #define    NOP        0x01        /*  processor's NOP opcode    */
  281. #define    ON        1        /*  assembly turned on        */
  282. #define    OFF        -1        /*  assembly turned off        */
  283.  
  284. /*  Line assembler (A68.C) opcode attribute word flag masks:        */
  285.  
  286. #define    PSEUDO        0x200    /*  is pseudo op            */
  287. #define    ISIF        0x100    /*  is IF, ELSE, or ENDI        */
  288. #define    IS6801        0x080    /*  is 6801 only opcode            */
  289. #define    DIROK        0x040    /*  can use direct addressing        */
  290. #define    REL        0x020    /*  must use relative addressing    */
  291. #define    INDEX        0x010    /*  can use indexed addressing        */
  292. #define    IMM16        0x008    /*  can use 16-bit immediate addressing    */
  293. #define    IMM8        0x004    /*  can use 8-bit immediate addressing    */
  294. #define    REGOPT        0x002    /*  A or B specification optional    */
  295. #define    REGREQ        0x001    /*  must have A or B specified        */
  296.  
  297. /*  Line assembler (A68.C) pseudo-op opcode token values:        */
  298.  
  299. #define    CPU        1
  300. #define    ELSE        2
  301. #define    END        3
  302. #define    ENDI        4
  303. #define    EQU        5
  304. #define    FCB        6
  305. #define    FCC        7
  306. #define    FDB        8
  307. #define    IF        9
  308. #define    INCL        10
  309. #define    ORG        11
  310. #define    PAGE        12
  311. #define    RMB        13
  312. #define    SET        14
  313. #define    TITL        15
  314.  
  315. /*  Lexical analyzer (A68EVAL.C) token buffer and stream pointer:    */
  316.  
  317. typedef struct {
  318.     unsigned attr;
  319.     unsigned valu;
  320.     char sval[MAXLINE + 1];
  321. } TOKEN;
  322.  
  323. /*  Lexical analyzer (A68EVAL.C) token attribute values:        */
  324.  
  325. #define    EOL        0    /*  end of line                */
  326. #define    SEP        1    /*  field separator            */
  327. #define    OPR        2    /*  operator                */
  328. #define    STR        3    /*  character string            */
  329. #define    VAL        4    /*  value                */
  330. #define    IMM        5    /*  immediate designator        */
  331. #define    REG        6    /*  register designator            */
  332.  
  333. /*  Lexical analyzer (A68EVAL.C) token attribute word flag masks:    */
  334.  
  335. #define    BINARY        0x8000    /*  Operator:    is binary operator    */
  336. #define    UNARY        0x4000    /*        is unary operator    */
  337. #define    PREC        0x0f00    /*        precedence        */
  338.  
  339. #define    FORWD        0x8000    /*  Value:    is forward referenced    */
  340. #define    SOFT        0x4000    /*        is redefinable        */
  341.  
  342. #define    TYPE        0x000f    /*  All:    token type        */
  343.  
  344. /*  Lexical analyzer (A68EVAL.C) operator token values (unlisted ones    */
  345. /*  use ASCII characters):                        */
  346.  
  347. #define    AND        0
  348. #define    GE        1
  349. #define    HIGH        2
  350. #define    LE        3
  351. #define    LOW        4
  352. #define    MOD        5
  353. #define    NE        6
  354. #define    NOT        7
  355. #define    OR        8
  356. #define    SHR        9
  357. #define    SHL        10
  358. #define    XOR        11
  359.  
  360. /*  Lexical analyzer (A68EVAL.C) operator precedence values:        */
  361.  
  362. #define    UOP1        0x0000    /*  unary +, unary -            */
  363. #define    MULT        0x0100    /*  *, /, MOD, SHL, SHR            */
  364. #define    ADDIT        0x0200    /*  binary +, binary -            */
  365. #define    RELAT        0x0300    /*  >, >=, =, <=, <, <>            */
  366. #define    UOP2        0x0400    /*  NOT                    */
  367. #define    LOG1        0x0500    /*  AND                    */
  368. #define    LOG2        0x0600    /*  OR, XOR                */
  369. #define    UOP3        0x0700    /*  HIGH, LOW                */
  370. #define    RPREN        0x0800    /*  )                    */
  371. #define    LPREN        0x0900    /*  (                    */
  372. #define    ENDEX        0x0a00    /*  end of expression            */
  373. #define    START        0x0b00    /*  beginning of expression        */
  374.  
  375. /*  Utility package (A68UTIL.C) symbol table routines:            */
  376.  
  377. struct _symbol {
  378.     unsigned attr;
  379.     unsigned valu;
  380.     struct _symbol *left, *right;
  381.     char sname[1];
  382. };
  383.  
  384. typedef struct _symbol SYMBOL;
  385.  
  386. #define    SYMCOLS        4
  387.  
  388. /*  Utility package (A68UTIL.C) opcode/operator table routines:        */
  389.  
  390. typedef struct {
  391.     unsigned attr;
  392.     unsigned valu;
  393.     char oname[5];
  394. } OPCODE;
  395.  
  396. /*  Utility package (A68UTIL.C) hex file output routines:        */
  397.  
  398. #define    HEXSIZE        32
  399.