home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / CROSSASM / 68ASMSIM.ZIP / asmsrc / listing.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-09-07  |  3.6 KB  |  149 lines

  1. /***********************************************************************
  2.  *
  3.  *        LISTING.C
  4.  *        Listing File Routines for 68000 Assembler
  5.  *
  6.  *    Function: initList()
  7.  *        Opens the specified listing file for writing. If the
  8.  *        file cannot be opened, then the routine prints a
  9.  *        message and exits.
  10.  *
  11.  *        listLine()
  12.  *        Writes the current listing line to the listing file. If 
  13.  *        the line is not a continuation, then the routine 
  14.  *        includes the source line as the last part of the 
  15.  *        listing line. If an error occurs during the writing, 
  16.  *        the routine prints a message and exits.
  17.  *
  18.  *        listLoc()
  19.  *        Starts the process of assembling a listing line by 
  20.  *        printing the location counter value into listData and 
  21.  *        initializing listPtr.
  22.  *
  23.  *        listObj()
  24.  *        Prints the data whose size and value are specified in
  25.  *        the object field of the current listing line. Bytes are
  26.  *        printed as two digits, words as four digits, and
  27.  *        longwords as eight digits, and a space follows each
  28.  *        group of digits. 
  29.  *             If the item to be printed will not fit in the
  30.  *        object code field, one of two things will occur. If
  31.  *        cexFlag is TRUE, then the current listing line will be
  32.  *        output to the listing file and the data will be printed
  33.  *        on a continuation line. Otherwise, elipses ("...") will
  34.  *        be printed to indicate the omission of values from the
  35.  *        listing, and the data will not be added to the file. 
  36.  *
  37.  *     Usage: initList(name)
  38.  *        char *name;
  39.  *
  40.  *        listLine()
  41.  *
  42.  *        listLoc()
  43.  *
  44.  *        listObj(data, size)
  45.  *        int data, size;
  46.  *
  47.  *      Author: Paul McKee
  48.  *        ECE492    North Carolina State University
  49.  *
  50.  *        Date:    12/13/86
  51.  *
  52.  ************************************************************************/
  53.  
  54.  
  55. #include <stdio.h>
  56. #include <ctype.h>
  57. #include "asm.h"
  58.  
  59.  
  60. /* Declarations of global variables */
  61. extern long    loc;
  62. extern char pass2, cexFlag, continuation;
  63. extern char line[256];
  64. extern FILE *listFile;
  65. extern int lineNum;
  66.  
  67. static char listData[49];      /* Buffer in which listing lines are assembled */
  68.  
  69. extern char *listPtr;           /* Pointer to above buffer (this pointer is
  70.                   global because it is actually manipulated
  71.                   by equ() and set() to put specially formatted
  72.                   information in the listing) */
  73.  
  74. int    initList(name)
  75. char *name;
  76. {
  77.  
  78.     listFile = fopen(name, "w");
  79.     if (!listFile) {    
  80.         puts("Can't open listing file");
  81.         exit(0);
  82.         }
  83.  
  84.     return NORMAL;
  85.  
  86. }
  87.  
  88.  
  89. int    listLine()
  90. {
  91.     
  92.     fprintf(listFile, "%-41.41s", listData);
  93.     if (!continuation)
  94.         fprintf(listFile, "%5d  %s", lineNum, line);
  95.     else
  96.         putc('\n', listFile);
  97.     if ferror(listFile) {
  98.         fputs("Error writing to listing file\n", stderr);
  99.         exit(0);
  100.         }
  101.  
  102.     return NORMAL;
  103.  
  104. }
  105.  
  106.  
  107. int    listLoc()
  108. {
  109.     sprintf(listData, "%08lX  ", loc);
  110.     listPtr = listData + 10;
  111.  
  112.     return NORMAL;
  113.  
  114. }
  115.  
  116.  
  117. int    listObj(data, size)
  118. long    data;
  119. int    size;
  120. {
  121.     if (!cexFlag && (listPtr - listData + size > 40)) {
  122.         strcpy(listData + ((size == WORD) ? 35 : 37), "...");
  123.         return NORMAL;
  124.         }
  125.     if (cexFlag && (listPtr - listData + size > 40)) {
  126.         listLine();
  127.         strcpy(listData, "          ");
  128.         listPtr = listData + 10;
  129.         continuation = TRUE;
  130.         } 
  131.     switch (size) {
  132.         case BYTE : sprintf(listPtr, "%02X ", data & 0xFF);
  133.                         listPtr += 3;
  134.                         break;
  135.         case WORD : sprintf(listPtr, "%04X ", data & 0xFFFF);
  136.                         listPtr += 5;
  137.                         break;
  138.         case LONG : sprintf(listPtr, "%08lX ", data);
  139.                         listPtr += 9;
  140.                         break;
  141.         default   : printf("LISTOBJ: INVALID SIZE CODE!\n");
  142.                         exit(0);
  143.         }
  144.  
  145.     return NORMAL;
  146.  
  147. }
  148.  
  149.