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

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