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

  1. /*
  2.     HEADER:        CUG149;
  3.     TITLE:        1805A Cross-Assembler (Portable);
  4.     FILENAME:    A18.H;
  5.     VERSION:    2.5;
  6.     DATE:        08/27/1988;
  7.  
  8.     DESCRIPTION:    "This program lets you use your computer to assemble
  9.             code for the RCA 1802, 1804, 1805, 1805A, 1806, and
  10.             1806A 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.             RCA, CDP1802, CDP1805A;
  16.  
  17.     SEE-ALSO:    CUG113, 1802 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.               1805A 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. 2.0    MAY 1985    Recoded from BDS C version 1.1.  WCC3.
  41.  
  42. 2.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. 2.2    SEP 1985    Added the INCL pseudo-op and associated stuff.  WCC3.
  50.  
  51. 2.3    JUL 1986    Added compilation instructions and tweaks for CI-C86,
  52.             Eco-C88, and Lattice C.  WCC3.
  53.  
  54. 2.4    JAN 1987    Fixed bug that made "BYTE 0," legal syntax.  WCC3.
  55.  
  56. 2.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 "A18 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 A18.H.
  96.  
  97.     B)  Assuming that all files are on drive A:, run the following sequence
  98.         of command lines:
  99.  
  100.         A>cc a18
  101.         A>cc a18eval
  102.         A>cc a18util
  103.         A>ln a18.o a18eval.o a18util.o -lc
  104.         A>era a18*.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 A18.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 a18
  115.         A>as -zap a18
  116.         A>cc a18eval
  117.         A>as -zap a18eval
  118.         A>cc a18util
  119.         A>as -zap a18util
  120.         A>ln a18.o a18eval.o a18util.o -lc
  121.         A>era a18*.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 A18.H.
  127.  
  128.     B)  Compile the files A18.C, A18EVAL.C, and A18UTIL.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 A18.H.
  135.  
  136.     B)  Assuming all files are on drive A:, run the following sequence of
  137.         command lines:
  138.  
  139.         A>cp a18 -i -m
  140.         A>cp a18eval -i -m
  141.         A>cp a18util -i -m
  142.         A>l80 a18,a18eval,a18util,a18/n/e
  143.         A>era a18*.mac
  144.         A>era a18*.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 A18.H.
  150.  
  151.     B)  Compile the files A18.C, A18EVAL.C, and A18UTIL.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 A18.H.
  159.  
  160.     B)  Run the following command line:
  161.  
  162.         . cc a18.c a18eval.c a18util.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 A18.H.
  168.  
  169.     B)  Compile the files A18.C, A18EVAL.C, and A18UTIL.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 a18.c a18eval.c a18util.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 A18.H.
  185.  
  186.     B)  Run the following command line:
  187.  
  188.         . cc a18.c a18eval.c a18util.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 (A18.C) constants:                    */
  277.  
  278. #define    BIGINST        4        /* longest instruction length    */
  279. #define    IFDEPTH        16        /* maximum IF nesting level    */
  280. #define    PREBYTE        0x68        /* processor's opcode prebyte    */
  281. #define    PLO        0xa0        /* processor's PLO R0 opcode    */
  282. #define    PHI        0xb0        /* processor's PHI R0 opcode    */
  283. #define    NOP        0xc4        /* processor's NOP opcode    */
  284. #define    LDI        0xf8        /* processor's LDI opcode    */
  285. #define    ON        1        /* assembly turned on        */
  286. #define    OFF        -1        /* assembly turned off        */
  287.  
  288. /*  Line assembler (A18.C) opcode attribute word flag masks:        */
  289.  
  290. #define    PSEUDO        0x200        /* is pseudo-op            */
  291. #define    ISIF        0x100        /* is IF, ELSE, or ENDI        */
  292. #define    IS1805        0x080        /* is 1805A-only opcode        */
  293. #define    REGTYP        0x060        /* register argument type:    */
  294. #define    IOPORT        0x060        /*    i/o port        */
  295. #define    NOT_R0        0x040        /*    any register but R0    */
  296. #define    ANY        0x020        /*    any register        */
  297. #define    NUMTYP        0x018        /* numerical argument type:    */
  298. #define    SIXTN        0x018        /*    16-bit word        */
  299. #define    BRANCH        0x010        /*    8-bit branch target    */
  300. #define    IMMED        0x008        /*    8-bit immediate    byte    */
  301. #define    BYTES        0x007        /* number of instruction bytes    */
  302.  
  303. /*  Line assembler (A18.C) pseudo-op opcode token values:        */
  304.  
  305. #define    BLK        1
  306. #define    BYTE        2
  307. #define    CPU        3
  308. #define    EJCT        4
  309. #define    ELSE        5
  310. #define    END        6
  311. #define    ENDI        7
  312. #define    EQU        8
  313. #define    IF        9
  314. #define    INCL        10
  315. #define    LOAD        11
  316. #define    ORG        12
  317. #define    PAGE        13
  318. #define    SET        14
  319. #define    TEXT        15
  320. #define    TITL        16
  321. #define    WORD        17
  322.  
  323. /*  Lexical analyzer (A18EVAL.C) token buffer and stream pointer:    */
  324.  
  325. typedef struct {
  326.     unsigned attr;
  327.     unsigned valu;
  328.     char sval[MAXLINE + 1];
  329. } TOKEN;
  330.  
  331. /*  Lexical analyzer (A18EVAL.C) token attribute values:        */
  332.  
  333. #define    EOL        0    /*  end of line                */
  334. #define    SEP        1    /*  field separator            */
  335. #define    OPR        2    /*  operator                */
  336. #define    STR        3    /*  character string            */
  337. #define    VAL        4    /*  value                */
  338.  
  339. /*  Lexical analyzer (A18EVAL.C) token attribute word flag masks:    */
  340.  
  341. #define    BINARY        0x8000    /*  Operator:    is binary operator    */
  342. #define    UNARY        0x4000    /*        is unary operator    */
  343. #define    PREC        0x0f00    /*        precedence        */
  344.  
  345. #define    FORWD        0x8000    /*  Value:    is forward referenced    */
  346. #define    SOFT        0x4000    /*        is redefinable        */
  347.  
  348. #define    TYPE        0x000f    /*  All:    token type        */
  349.  
  350. /*  Lexical analyzer (A18EVAL.C) operator token values (unlisted ones    */
  351. /*  use ASCII characters):                        */
  352.  
  353. #define    AND        0
  354. #define    GE        1
  355. #define    HIGH        2
  356. #define    LE        3
  357. #define    LOW        4
  358. #define    MOD        5
  359. #define    NE        6
  360. #define    NOT        7
  361. #define    OR        8
  362. #define    SHR        9
  363. #define    SHL        10
  364. #define    XOR        11
  365.  
  366. /*  Lexical analyzer (A18EVAL.C) operator precedence values:        */
  367.  
  368. #define    UOP1        0x0000    /*  unary +, unary -            */
  369. #define    MULT        0x0100    /*  *, /, MOD, SHL, SHR            */
  370. #define    ADDIT        0x0200    /*  binary +, binary -            */
  371. #define    RELAT        0x0300    /*  >, >=, =, <=, <, <>            */
  372. #define    UOP2        0x0400    /*  NOT                    */
  373. #define    LOG1        0x0500    /*  AND                    */
  374. #define    LOG2        0x0600    /*  OR, XOR                */
  375. #define    UOP3        0x0700    /*  HIGH, LOW                */
  376. #define    RPREN        0x0800    /*  )                    */
  377. #define    LPREN        0x0900    /*  (                    */
  378. #define    ENDEX        0x0a00    /*  end of expression            */
  379. #define    START        0x0b00    /*  beginning of expression        */
  380.  
  381. /*  Utility package (A18UTIL.C) symbol table routines:            */
  382.  
  383. struct _symbol {
  384.     unsigned attr;
  385.     unsigned valu;
  386.     struct _symbol *left, *right;
  387.     char sname[1];
  388. };
  389.  
  390. typedef struct _symbol SYMBOL;
  391.  
  392. #define    SYMCOLS        4
  393.  
  394. /*  Utility package (A18UTIL.C) opcode/operator table routines:        */
  395.  
  396. typedef struct {
  397.     unsigned attr;
  398.     unsigned valu;
  399.     char oname[5];
  400. } OPCODE;
  401.  
  402. /*  Utility package (A18UTIL.C) hex file output routines:        */
  403.  
  404. #define    HEXSIZE        32
  405.