2 // RMAC - Reboot's Macro Assembler for the Atari Jaguar Console System
3 // LISTING.C - Listing Output
4 // Copyright (C) 199x Landon Dyer, 2011-2012 Reboot and Friends
5 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
6 // Source Utilised with the Kind Permission of Landon Dyer
8 // --------------------------------------------------------------------------
9 // 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7
10 // 012345678901234567890123456789012345678901234567890123456789012345678901234567
11 // filename.... Reboot's Macro Assembler N.N.NN (Unknown)
12 // nnnnn aaaaaaaa dddddddddddddddddddd T source code
13 // nnnnn aaaaaaaa dddddddddddddddd
23 char * list_fname; // Listing filename
24 char subttl[TITLESIZ]; // Current subtitle
25 int listing; // Listing level
26 int pagelen = 61; // Lines on a page
27 int nlines; // #lines on page so far
28 LONG lsloc; // `sloc' at start of line
31 static int lcursect; // `cursect' at start of line
32 static int llineno; // `curlineno' at start of line
33 static int pageno; // Current page number
34 static int pagewidth; // #columns on a page
35 static int subflag; // 0, don't do .eject on subttl (set 1)
36 static char lnimage[IMAGESIZ]; // Image of output line
37 static char title[TITLESIZ]; // Current title
38 static char datestr[20]; // Current date dd-mon-yyyy
39 static char timestr[20]; // Current time hh:mm:ss [am|pm]
40 static char buf[IMAGESIZ]; // Buffer for numbers
41 static long unused; // For supressing 'write' warnings
43 static char * month[16] = { "", "Jan", "Feb", "Mar",
44 "Apr", "May", "Jun", "Jul",
45 "Aug", "Sep", "Oct", "Nov",
49 // Eject the Page (Print Empty Lines), Reset the Line Count and Bump the Page Number
64 // Return GEMDOS Format Date
73 tm = localtime(&tloc);
74 v = ((tm->tm_year - 80) << 9) | ((tm->tm_mon+1) << 5) | tm->tm_mday;
81 // Return GEMDOS Format Time
90 tm = localtime(&tloc);
91 v = (tm->tm_hour << 11) | (tm->tm_min) << 5 | tm->tm_sec;
98 // Generate a Time String
100 void time_string(char * buf, VALUE time)
115 sprintf(buf, "%d:%02d:%02d %s",
116 hour, (int)((time >> 5) & 0x3F), (int)((time & 0x1F) << 1), ampm);
121 // Generate a Date String
123 void date_string(char * buf, VALUE date)
125 sprintf(buf, "%d-%s-%d",
126 (int)(date & 0x1F), month[(date >> 5) & 0xF], (int)((date >> 9) + 1980));
131 // Copy `n' Characters from `src' to `dest' (also stops on EOS in src).
132 // Does not null-terminate dest.
134 void scopy(char *dest, char *src, int len)
137 len = 1000; // Some large number
139 while (len-- && *src)
145 // Transform letters a-f in the address and data columns of the listing to
146 // uppercase. (People seem to like uppercase hex better in assembly-language
149 void uc_ln(char * ln)
154 for(i=LOC_COL; i<SRC_COL; ++i)
156 if ((j = ln[i]) >= 'a' && j <= 'f')
157 ln[i] = (char)(j - 0x20);
163 // Fill Region `dest' with `len' Characters `c' and Null Terminate the Region
165 void lnfill(char * dest, int len, char chr)
175 // Create Listing File with the Appropriate Name
177 void list_setup(void)
181 strcpy(fnbuf, list_fname);
185 strcpy(fnbuf, firstfname);
186 fext(fnbuf, ".prn", 1);
191 if ((list_fd = open(fnbuf, _OPEN_FLAGS, _PERM_MODE)) < 0)
197 // Tag Listing with a Character, Typically for Errors or Warnings
199 void taglist(char chr)
201 lnimage[TAG_COL+1] = chr;
206 // Print a Line to the Listing File
208 void println(const char * ln)
212 if (list_fname != NULL) // Create listing file, if necessary
216 unused = write(list_fd, ln, length);
217 unused = write(list_fd, "\n", 1L);
222 // Ship Line `ln' Out; Do Page Breaks and Title Stuff
224 void ship_ln(const char * ln)
226 // If listing level is <= 0, then don't print anything
230 // Notice bottom of page
231 if (nlines >= pagelen - BOT_MAR)
234 // Print title, boilerplate, and subtitle at top of page
239 date_string(datestr, dos_date());
240 time_string(timestr, dos_time());
242 "%-40s%-20s Page %-4d %s %s RMAC %01i.%01i.%02i (%s)",
243 title, curfname, pageno, timestr, datestr, MAJOR, MINOR, PATCH, PLATFORM);
245 sprintf(buf, "%s", subttl);
257 // Initialize Listing Generator
259 void InitListing(void)
261 extern VALUE dos_date(), dos_time();
270 date_string(datestr, dos_date());
271 time_string(timestr, dos_time());
286 DEBUG printf("~list: lsloc=$%ux sloc=$%ux\n", lsloc, sloc);
290 sprintf(buf, "%08ux", lsloc);
291 scopy(lnimage+LOC_COL, buf, 8);
294 if (llineno != curlineno)
296 sprintf(buf, "%5d", llineno);
297 scopy(lnimage+LN_COL, buf, 5);
300 // List bytes only when section stayed the same and the section is not a
301 // "no-data" (SBSS) section. An extra annoyance is caused by "ds.b" in a
302 // microprocessor mode, which prints out bytes of zero as if they had been
303 // deposited with dcb. The fix (kludge) is an extra variable which records
304 // the fact that a 'ds.x' directive generated all the data, and it
305 // shouldn't be listed
306 savsect(); // Update section variables
308 if (lcursect == cursect && (sect[lcursect].scattr & SBSS) == 0
309 && lsloc != sloc && just_bss == 0)
311 ch = sect[lcursect].sfcode;
313 for(; ch!=NULL; ch=ch->chnext)
315 if (lsloc >= ch->chloc && lsloc < (ch->chloc + ch->ch_size))
319 // Fatal: Can't find chunk holding code
323 interror(6); // Can't find generated code in section
326 p = ch->chptr + (lsloc - ch->chloc);
330 for(count=sloc-lsloc; count--; col+=2, ++lsloc)
337 lnfill(lnimage, SRC_COL, SPACE); // Fill with spaces
338 sprintf(buf, "%08ux", lsloc);
339 scopy(lnimage+LOC_COL, buf, 8);
342 if (lsloc >= (ch->chloc + ch->ch_size))
344 if ((ch = ch->chnext) == NULL)
351 fixcount = fixtest(lcursect, lsloc);
357 ++p; // Advance anyway
360 sprintf(buf, "%02x", *p++ & 0xff);
362 scopy(lnimage+col, buf, 2);
365 // Flush partial line
381 // Copy Current (Saved) Line to Output Buffer and Tag it with a Character
383 void lstout(char tag)
392 lnfill(lnimage, SRC_COL, SPACE); // Fill with spaces
393 lnimage[TAG_COL] = tag;
395 // Copy line image and handle control characters
396 d = lnimage + SRC_COL;
398 for(s=lnbuf; *s; ++s)
400 if (*s >= 0x20 || *s == '\t')
405 *d++ = (char)(*s + 0x40);
414 // Output a Value to Listing
416 int listvalue(VALUE v)
418 sprintf(buf, "=%08ux", v);
419 scopy(lnimage + DATA_COL - 1, buf, 9);
425 * .subttl [-] "string"
428 * o leading '-' supresses page eject
429 * o don't .eject on first .subttl, but do so on all other ones,
430 * o arrange not to print the .subttl directive
445 return error("missing string");
447 // strcpy(subttl, (char *)tok[1]);
448 strcpy(subttl, string[tok[1]]);
452 if (ejectok && (subflag || pageno > 1)) // Always eject on pages 2+
462 // Set title on titles not on the first page, do an eject and clobber the subtitle
467 return error("missing string");
469 // strcpy(title, (char*)tok[1]);
470 strcpy(title, string[tok[1]]);