+char * constr_bsdsymtab(char * buf, SYM * sym, int globflag)
+{
+ chptr = buf; // Point to buffer for deposit longs
+ D_long(strindx); // Deposit the symbol string index
+
+ WORD w1 = sym->sattr; // Obtain symbol attribute
+ int w2 = sym->sattre;
+ LONG z = 0; // Initialise resulting symbol flags
+
+ if (w1 & EQUATED)
+ {
+ z = 0x02000000; // Set equated flag
+ }
+ else
+ {
+ switch (w1 & TDB)
+ {
+ case TEXT: z = 0x04000000; break; // Set TEXT segment flag
+ case DATA: z = 0x06000000; break; // Set DATA segment flag
+ case BSS : z = 0x08000000; break; // Set BSS segment flag
+ }
+ }
+
+ if (globflag)
+ z |= 0x01000000; // Set global flag if requested
+
+ D_long(z); // Deposit symbol attribute
+
+ z = sym->svalue; // Obtain symbol value
+ w1 &= DATA | BSS; // Determine DATA or BSS flag
+
+ if (w1)
+ z += sect[TEXT].sloc; // If DATA or BSS add TEXT segment size
+
+ if (w1 & BSS)
+ z += sect[DATA].sloc; // If BSS add DATA segment size
+
+ D_long(z); // Deposit symbol value
+
+ strcpy(strtable + strindx, sym->sname);
+
+ strindx += strlen(sym->sname) + 1; // Incr string index incl null terminate
+ buf += 12; // Increment buffer to next record
+ symsize += 12; // Increment symbol table size
+
+ return buf;
+}
+
+
+/*
+ * Alcyon symbol flags
+ */
+#define AL_DEFINED 0x8000
+#define AL_EQUATED 0x4000
+#define AL_GLOBAL 0x2000
+#define AL_EQUREG 0x1000
+#define AL_EXTERN 0x0800
+#define AL_DATA 0x0400
+#define AL_TEXT 0x0200
+#define AL_BSS 0x0100
+#define AL_FILE 0x0080
+
+LONG PRGFLAGS; /* PRGFLAGS as defined in Atari Compendium Chapter 2 */
+ /* Definition Bit(s) Meaning */
+ /* PF_FASTLOAD 0 If set, clear only the BSS area on program load, */
+ /* otherwise clear the entire heap. */
+ /* PF_TTRAMLOAD 1 If set, the program may be loaded into alternative RAM, */
+ /* otherwise it must be loaded into standard RAM. */
+ /* PF_TTRAMMEM 2 If set, the program's Malloc() requests may be satisfied */
+ /* from alternative RAM, otherwise they must be satisfied */
+ /* from standard RAM. */
+ /* - 3 Currently unused. */
+ /* See left. 4 & 5 If these bits are set to 0 (PF_PRIVATE), the processes' */
+ /* entire memory space will be considered private */
+ /* (when memory protection is enabled).If these bits are */
+ /* set to 1 (PF_GLOBAL), the processes' entire memory space */
+ /* will be readable and writable by any process (i.e. global). */
+ /* If these bits are set to 2 (PF_SUPERVISOR), the processes' */
+ /* entire memory space will only be readable and writable by */
+ /* itself and any other process in supervisor mode.If these */
+ /* bits are set to 3 (PF_READABLE), the processes' entire memory */
+ /* space will be readable by any application but only */
+ /* writable by itself. */
+ /* - 6-15 Currently unused. */
+
+static WORD tdb_tab[] = {
+ 0, /* absolute */
+ AL_TEXT, /* TEXT segment based */
+ AL_DATA, 0, /* DATA segment based */
+ AL_BSS /* BSS segment based */
+};
+
+
+#define HDRSIZE 0x1C /* size of Alcyon header */
+
+
+/*
+ * Add entry to symbol table;
+ * if `globflag' is 1, make the symbol global;
+ * if in .PRG mode, adjust symbol values for fake link.
+ *
+ */
+char * constr_symtab(register char * buf, SYM * sym, int globflag)
+{
+ register int i;
+ register char * s;
+ register WORD w;
+ register LONG z;
+ register WORD w1;
+
+ /*
+ * Copy symbol name
+ */
+ s = sym->sname;
+
+ for(i=0; i<8 && *s; i++)
+ *buf++ = *s++;
+
+ while (i++ < 8)
+ *buf++ = '\0';
+
+ /*
+ * Construct and deposit flag word
+ *
+ * o all symbols are AL_DEFINED
+ * o install T/D/B/A base
+ * o install 'equated'
+ * o commons (COMMON) are AL_EXTERN, but not BSS
+ * o exports (DEFINED) are AL_GLOBAL
+ * o imports (~DEFINED) are AL_EXTERN
+ *
+ */
+ w1 = sym->sattr;
+ w = AL_DEFINED | tdb_tab[w1 & TDB];
+
+ if (w1 & EQUATED) /* equated */
+ w |= AL_EQUATED;
+
+ if (w1 & COMMON)
+ {
+ w |= AL_EXTERN | AL_GLOBAL; /* common symbol */
+ w &= ~AL_BSS; /* they're not BSS in Alcyon object files */
+ }
+ else if (w1 & DEFINED)
+ {
+ if (globflag) /* export the symbol */
+ w |= AL_GLOBAL;
+ }
+ else w |= AL_EXTERN; /* imported symbol */
+
+ *buf++ = w >> 8;
+ *buf++ = (char)w;
+
+ z = sym->svalue;
+
+ if (prg_flag) /* relocate value in .PRG segment */
+ {
+ w1 &= DATA | BSS;