home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 113_01 / a15put.c < prev    next >
Text File  |  1985-03-10  |  4KB  |  176 lines

  1. /*
  2.     HEADER:        CUG113;
  3.     TITLE:        1802 Cross-Assembler (BDS C Version);
  4.     FILENAME:    A15PUT.C;
  5.     VERSION:    1.2;
  6.     DATE:        07/22/1985;
  7.  
  8.     DESCRIPTION:    "This program lets you use your CP/M-80-based computer
  9.             to assemble code for the RCA 1802, 1804, 1805, 1805A,
  10.             1806, AND 1806A microprocessors.  The program is
  11.             written in BDS C for the best possible performance on
  12.             8-bit machines.  All assembler features are supported
  13.             except relocation, linkage, listing control, and
  14.             macros.";
  15.  
  16.     KEYWORDS:    Software Development, Assemblers, Cross-Assemblers,
  17.             RCA, CDP1802, CDP1805A;
  18.  
  19.     SEE-ALSO:    CUG149, 1805A Cross-Assembler (Portable);
  20.  
  21.     SYSTEM:        CP/M-80;
  22.     COMPILERS:    BDS C;
  23.  
  24.     WARNINGS:    "This package is specifically tailored to CP/M-80
  25.             machines and the rather non-standard, but high-
  26.             performance BDS C compiler.  For other environments,
  27.             use the portable version of this package on CUG149.";
  28.  
  29.     AUTHORS:    William C. Colley III;
  30. */
  31.  
  32. /*
  33.     1805A Cross-Assembler  v 1.2
  34.  
  35.     Copyright (c) 1980, 82, 83, 85 William C. Colley, III.
  36.  
  37.     July 1982 -- Adapted from my 1802 cross-assembler.  WCC3.
  38.  
  39.     Vers 1.0 -- March 1983 -- Added 1805A opcodes to the 1805 set.  WCC3.
  40.  
  41.     Vers 1.1 -- March 1983 -- Added CPU pseudo-op to combine 1802 and 1805A
  42.             cross-assemblers into a single program.  WCC3.
  43.  
  44.     Vers 1.2 -- June 1985 -- Fixed IF block nesting mechanism bug and bug
  45.             in 1805A SCAL opcode.  WCC3.
  46.  
  47. File:    a15put.c
  48.  
  49. List and hex output routines.
  50. */
  51.  
  52. /*  Get globals:  */
  53.  
  54. #include "a15.h"
  55.  
  56. /*
  57. Function to form the list output line and put it to the list device.  Routine
  58. also puts the line to the console in the event of an error.
  59. */
  60.  
  61. lineout()
  62. {
  63.     char tbuf[25], *tptr, *bptr, count;
  64.  
  65.     if (list == NOFILE && errcode == ' ') return;
  66.     setmem(tbuf,24,' ');  tbuf[24] = '\0';
  67.     tptr = tbuf;  *tptr++ = errcode;  tptr++;
  68.     if (hexflg != NOCODE) puthex4(address,&tptr);
  69.     else tptr += 4;
  70.     tptr += 3;  count = 0;  bptr = binbuf;
  71.  
  72.     for (;;) {
  73.     if (count == nbytes || count != 0 && count % 4 == 0) {
  74.         if (list != NOFILE) {
  75.         fputs(tbuf,list);
  76.         if (count > 4) fputs("\n",list);
  77.         else fputs(linbuf,list);
  78.         }
  79.         if (list != CONO && errcode != ' ') {
  80.         puts(tbuf);
  81.         if (count >= 4) putchar('\n');
  82.         else puts(linbuf);
  83.         }
  84.         tptr = tbuf + 2;  puthex4(address,&tptr);
  85.         setmem(tptr,14,' ');  tptr += 3;
  86.     }
  87.     if (count == nbytes) return;
  88.     count++;  address++;  puthex2(*bptr++,&tptr);  tptr++;
  89.     }
  90. }
  91.  
  92. /*
  93. Function to form the hex output line and put it to
  94. the hex output device.
  95. */
  96.  
  97. hexout()
  98. {
  99.     char count, *bptr;
  100.  
  101.     if (hex == NOFILE) return;
  102.  
  103.     switch (hexflg) {
  104.     case PUTCODE:    bptr =binbuf;
  105.             for (count = 1; count <= nbytes; count++) {
  106.                 puthex2(*bptr,&hxlnptr);  chksum += *bptr++;
  107.                 if (++hxbytes == 16) flshhbf(pc+count);
  108.             }
  109.  
  110.     case NOCODE:    return;
  111.  
  112.     case FLUSH:    flshhbf(pc);  return;
  113.  
  114.     case NOMORE:    flshhbf(0);  fputs(":0000000000\n",hex);
  115.             if (hex >= LODISK) putc(CPMEOF,hex);
  116.             else if (hex == LST) putc('\f',hex);
  117.             fflush(hex);  fclose(hex);
  118.     }
  119. }
  120.  
  121. /*
  122. Function to put a line of intel hex to the appropriate
  123. device and get a new line started.
  124. */
  125.  
  126. flshhbf(loadaddr)
  127. unsigned loadaddr;
  128. {
  129.     if (hex == NOFILE) return;
  130.     if (hxbytes != 0) {
  131.     puthex2(-(chksum+hxbytes),&hxlnptr);  *hxlnptr++ = '\n';
  132.     *hxlnptr++ = '\0';  hxlnptr = hxlnbuf + 1;
  133.     puthex2(hxbytes,&hxlnptr);  fputs(hxlnbuf,hex);
  134.     }
  135.     hxbytes = 0;  hxlnptr = hxlnbuf;  *hxlnptr++ = ':';
  136.     hxlnptr += 2;  puthex4(loadaddr,&hxlnptr);  puthex2(0,&hxlnptr);
  137.     chksum = (loadaddr >> 8) + (loadaddr & 0xff);
  138. }
  139.  
  140. /*
  141. Function to put a 4-digit hex number into an output line.
  142. */
  143.  
  144. puthex4(number,lineptr)
  145. unsigned number;
  146. char **lineptr;
  147. {
  148.     puthex2(number>>8,lineptr);  puthex2(number,lineptr);
  149. }
  150.  
  151. /*
  152. Function to put a 2-digit hex number into an output line.
  153. */
  154.  
  155. puthex2(number,lineptr)
  156. char number, **lineptr;
  157. {
  158.     if ((**lineptr = (number >> 4) + '0') > '9') **lineptr += 7;
  159.     if ((*++*lineptr = (number & 0xf) + '0') > '9') **lineptr += 7;
  160.     ++(*lineptr);
  161. }
  162.  
  163. /*
  164. Function to put a decimal number into an output line.
  165. */
  166.  
  167. putdec(number,lineptr)
  168. unsigned number;
  169. char **lineptr;
  170. {
  171.     if (number == 0) return;
  172.     putdec(number/10,lineptr);  *(*lineptr)++ = number % 10 + '0';
  173. }
  174. ,&hxlnptr);  *hxlnptr++ = '\n';
  175.     *hxlnptr++ = '\0';  hxlnptr = hxlnbuf + 1;
  176.     puthex2(hxbytes,&hxlnptr);  fputs(hxlnbuf,