-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLISTING.CPP
More file actions
309 lines (279 loc) · 9.38 KB
/
Copy pathLISTING.CPP
File metadata and controls
309 lines (279 loc) · 9.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/***********************************************************************
*
* LISTING.C
* Listing File Routines for 68000 Assembler
*
* Function: initList()
* Opens the specified listing file for writing. If the
* file cannot be opened, then the routine prints a
* message and exits.
*
* listLine(char text[])
* Writes the specified line to the listing file. If
* the line is not a continuation, then the routine
* includes the source line as the last part of the
* listing line. If an error occurs during the writing,
* the routine prints a message and exits.
*
* listLoc()
* Starts the process of assembling a listing line by
* printing the location counter value into listData and
* initializing listPtr.
*
* listObj()
* Prints the data whose size and value are specified in
* the object field of the current listing line. Bytes are
* printed as two digits, words as four digits, and
* longwords as eight digits, and a space follows each
* group of digits.
* If the item to be printed will not fit in the
* object code field, one of two things will occur. If
* CEXflag is TRUE, then the current listing line will be
* output to the listing file and the data will be printed
* on a continuation line. Otherwise, elipses ("...") will
* be printed to indicate the omission of values from the
* listing, and the data will not be added to the file.
*
* Usage: initList(name)
* char *name;
*
* listLine(line)
*
* listLoc()
*
* listObj(data, size)
* int data, size;
*
* Author: Paul McKee
* ECE492 North Carolina State University
*
* Date: 12/13/86
*
* Modified: Charles Kelly
* Monroe County Community College
* http://www.monroeccc.edu/ckelly
*
************************************************************************/
// include <vcl.h>
#include <stdio.h>
#include <ctype.h>
// include "editorOptions.h"
// #include "texts.h"
// include "mainS.h"
#include "asm.h"
/* Declarations of global variables */
extern int loc;
extern bool pass2, CEXflag, continuation;
extern bool CREflag, offsetMode, showEqual;
extern char line[256];
extern FILE *listFile;
extern int lineNum;
extern int lineNumL68;
//static
char listData[49]; /* Buffer in which listing lines are assembled */
extern char *listPtr; /* Pointer to above buffer (this pointer is
global because it is actually manipulated
by equ() and set() to put specially formatted
information in the listing) */
extern int errorCount, warningCount; /* Number of errors and warnings */
extern char buffer[256]; //ck used to form messages for display in windows
extern char numBuf[20];
extern unsigned int startAddress; // starting address of program
extern tabTypes tabType;
bool createdL68; // true when L68 (listing) file is created
int initList(char *name)
{
try {
createdL68 = false;
listFile = fopen(name, "w");
if (!listFile) {
sprintf(buffer,"Unable to create listing file");
//Application->MessageBox(buffer, "Error", MB_OK);
fprintf(stderr,"%s\n",buffer);
return MILD_ERROR;
}
if (!listPtr) listPtr=listData;
// TDateTime DateTime = Time(); // store the current date and time
// RA vvv added OS agnostic #ifdefs, On Windows it's like this: 'Created On: 4/29/2019 8:47:37 PM'
#if 0
AnsiString timeStr = DateTimeToStr(Now()); // date & time to a string
#else
#include <time.h> // The format of this is not "4/29/2019 8:47:37 PM", it's "Mon Apr 29 20:47:37 2019"
// will rewrite this if it's an issue, but I think it's only for the LISTING and it isn't parsed elsewhere
time_t rawtime;
struct tm * timeinfo;
time (&rawtime);
timeinfo = localtime (&rawtime);
AnsiString timeStr=(string)(asctime(timeinfo));
#endif
// reserve room for starting address
fprintf(listFile, "00000000 Starting Address\n");
fprintf(listFile, "Assembler used: %s\n", TITLE);
fprintf(listFile, "Created On: %s\n\n", timeStr.c_str());
createdL68 = true;
return NORMAL;
}
catch( ... ) {
sprintf(buffer, "ERROR: An exception occurred in routine 'initList'. \n");
printError(NULL, EXCEPTION, 0);
return MILD_ERROR;
}
}
int listLine(char text[], char lineIdent[]) // ck 4-2006 lineIdent[]
{
// FixedTabSize->Value
try {
if (!createdL68)
return NORMAL;
//RA// TTextStuff *Active = (TTextStuff*)Main->ActiveMDIChild; //grab active mdi child
fprintf(listFile, "%-32.32s", listData);
if (!continuation) {
// replace tab with spaces
int i=0, j=0, k, t;
while (text[i] && j < 255-8) {
if (text[i] == '\t') { // if tab
//RA// if (Active->Project.TabType == Assembly) {
if (true) {
if (j <= TAB1)
t = TAB1 - j;
else if (j <= TAB2)
t = TAB2 - j;
else
t = TAB3 - j;
} //else { // else fixed tabs
//t = Active->Project.TabSize - (j % Active->Project.TabSize);
//}
for (k=0; k<t; k++) // replace with spaces
buffer[j++] = ' ';
} else
buffer[j++] = text[i]; // else, copy character
i++;
}
if (j>0 && buffer[j-1] != '\n') // if line does not end in '\n'
buffer[j++] = '\n'; // add it
buffer[j] = '\0';
if (lineIdent[0]) // if line identifier
fprintf(listFile, "%6d%s %s", lineNumL68, lineIdent, buffer);
else
fprintf(listFile, "%6d %s", lineNumL68, buffer);
} else
putc('\n', listFile);
if (ferror(listFile)) {
sprintf(buffer,"Error writing to listing file\n");
//Application->MessageBox(buffer, "Error", MB_OK);
fprintf(stderr,"%s\n",buffer);
return MILD_ERROR;
}
lineNumL68++;
}
catch( ... ) {
sprintf(buffer, "ERROR: An exception occurred in routine 'listLine'. \n");
printError(NULL, EXCEPTION, 0);
return MILD_ERROR;
}
return NORMAL;
}
int listLoc()
{
if (!listPtr) listPtr=listData; // prevent crash RA
if (offsetMode || showEqual)
sprintf(listData, "%08X= ", loc); //RA warning: format ‘%lX’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘int’
else
sprintf(listData, "%08X ", loc); // RA
listPtr = listData + 10;
return NORMAL;
}
// Lists the value of skipCond
// when skipCond is True the conditional test was False
int listCond(bool cond)
{
if (!listPtr) listPtr=listData; // prevent crash RA
if (cond)
sprintf(listPtr," %s ","FALSE");
else
sprintf(listPtr," %s ","TRUE");
return NORMAL;
}
// List error message
// Errors are always written to file if possible
// They are not turned off by NOLIST directive
int listError(char *lineNum, char *errMsg)
{
if (!createdL68)
return NORMAL;
fprintf(listFile, "%s", lineNum); // write line number to file // RA warning: format not a string literal and no format arguments [-Wformat-security]
fprintf(listFile, "%s", errMsg); // write error message to file // RA
return NORMAL;
}
// List text
int listText(const char *text)
{
if (!createdL68)
return NORMAL;
fprintf(listFile, "%s", text); // write text to file // RA warning: format not a string literal and no format arguments [-Wformat-security]
return NORMAL;
}
int listObj(int data, int size)
{
if (!CEXflag && (listPtr - listData + size > 31)) {
strcpy(listData + ((size == WORD_SIZE) ? 26 : 28), "...");
return NORMAL;
}
if (CEXflag && (listPtr - listData + size > 31)) {
listLine(line);
strcpy(listData, " ");
listPtr = listData + 10;
continuation = true;
}
switch (size) {
case BYTE_SIZE: sprintf(listPtr, "%02X ", (unsigned int)(data & 0xFF)); // RA
listPtr += 3;
break;
case WORD_SIZE: sprintf(listPtr, "%04X ", (unsigned int)(data & 0xFFFF)); // RA
listPtr += 5;
break;
case LONG_SIZE: sprintf(listPtr, "%08X ", data); // RA
listPtr += 9;
break;
default: sprintf(buffer,"LISTOBJ: INVALID SIZE CODE!\n");
//Application->MessageBox(buffer, "Error", MB_OK);
fprintf(stderr,"%s\n",buffer);
return MILD_ERROR;
}
return NORMAL;
}
int finishList()
{
try {
if (!createdL68)
return NORMAL;
putc('\n', listFile);
if (errorCount > 0)
fprintf(listFile, "%d error%s detected\n", errorCount,
(errorCount > 1) ? "s" : "");
else {
//***** DO NOT CHANGE THIS TEXT *****
// "No error" is used by simulator to find the end of the code in the listing
fprintf(listFile, "No errors detected\n");
}
if (warningCount > 0)
fprintf(listFile, "%d warning%s generated\n", warningCount,
(warningCount > 1) ? "s" : "");
else
fprintf(listFile, "No warnings generated\n");
// If OPT CRE Display Symbol Table ?
if (CREflag)
optCRE(); // Write symbol table to listing file
// write starting address to first line of file
rewind(listFile); // rewind to start of file
fprintf(listFile, "%08X", startAddress);
fclose(listFile);
return NORMAL;
}
catch( ... ) {
fclose(listFile);
sprintf(buffer, "ERROR: An exception occurred in routine 'finishList'. \n");
printError(NULL, EXCEPTION, 0);
return MILD_ERROR;
}
}