2 // RMAC - Reboot's Macro Assembler for all Atari computers
3 // DIRECT.C - Directive Handling
4 // Copyright (C) 199x Landon Dyer, 2011-2018 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
29 TOKEN exprbuf[128]; // Expression buffer
30 SYM * symbolPtr[1000000]; // Symbol pointers table
31 static long unused; // For supressing 'write' warnings
32 char buffer[256]; // Scratch buffer for messages
33 int largestAlign[3] = { 2, 2, 2 }; // Largest alignment value seen per section
35 // Function prototypes
71 int d_equrundef(void);
83 void SetLargestAlignment(int);
85 // Directive handler table
96 (void *)d_init, // 9 init
98 (void *)d_goto, // 11 goto
99 (void *)d_dc, // 12 dc
100 (void *)d_ds, // 13 ds
101 d_undmac, // 14 undefmac
104 (void *)d_dcb, // 17 dcb
108 d_incbin, // 21 .incbin //load
109 d_unimpl, // 22 disable
110 d_unimpl, // 23 enable
112 d_regbank0, // 25 .regbank0
113 d_regbank1, // 26 .regbank1
115 d_assert, // 28 assert
117 d_unimpl, // 30* endif
118 d_unimpl, // 31* endc
120 d_include, // 33 include
122 d_unimpl, // 35* macro
123 ExitMacro, // 36* exitm
124 d_unimpl, // 37* endm
128 d_phrase, // 41* endr
129 d_dphrase, // 42 struct
130 d_qphrase, // 43 ends
132 d_subttl, // 45 subttl
136 d_noclear, // 49 .noclear
137 d_equrundef, // 50 .equrundef/.regundef
138 d_ccundef, // 51 .ccundef
139 d_print, // 52 .print
140 d_cstruct, // 53 .cstruct
141 d_jpad, // 54 .jpad (deprecated)
142 d_nojpad, // 55 .nojpad (deprecated)
143 d_gpumain, // 56 .gpumain (deprecated)
144 d_prgflags, // 57 .prgflags
145 d_68020, // 58 .68020
146 d_68030, // 59 .68030
147 d_68040, // 60 .68040
148 d_68060, // 61 .68060
149 d_68881, // 62 .68881
150 d_68882, // 63 .68882
151 d_56001, // 64 .56001
154 d_objproc, // 67 .objproc
159 // Set the largest alignment seen in the current section
161 void SetLargestAlignment(int size)
163 if ((scattr & TEXT) && (largestAlign[0] < size))
164 largestAlign[0] = size;
165 else if ((scattr & DATA) && (largestAlign[1] < size))
166 largestAlign[1] = size;
167 else if ((scattr & BSS) && (largestAlign[2] < size))
168 largestAlign[2] = size;
173 // .error - Abort compilation, printing an error message
175 int d_error(char *str)
178 return error("error directive encountered - aborting assembling");
184 return error(string[tok[1]]);
187 return error("error directive encountered--aborting assembly");
194 // .warn - Just display a warning on screen
196 int d_warn(char *str)
199 return warn("WARNING WARNING WARNING");
205 return warn(string[tok[1]]);
208 return warn("WARNING WARNING WARNING");
221 if (!rgpu && !rdsp && !robjproc && !m6502)
222 return error(".org permitted only in GPU/DSP/OP and 6502 sections");
224 if (abs_expr(&address) == ERROR)
226 error("cannot determine org'd address");
230 if (rgpu | rdsp | robjproc)
237 // 6502. We also kludge `lsloc' so the listing generator doesn't try
238 // to spew out megabytes.
239 if (address > 0xFFFF)
240 return error(range_error);
242 if (sloc != currentorg[0])
244 currentorg[1] = sloc;
248 currentorg[0] = address;
250 lsloc = sloc = address;
251 chptr = scode->chptr + address;
266 char prntstr[LNSIZ]; // String for PRINT directive
267 char format[LNSIZ]; // Format for PRINT directive
268 int formatting = 0; // Formatting on/off
269 int wordlong = 0; // WORD = 0, LONG = 1
270 int outtype = 0; // 0:hex, 1:decimal, 2:unsigned
272 uint64_t eval; // Expression value
273 WORD eattr; // Expression attributes
274 SYM * esym; // External symbol involved in expr.
275 TOKEN r_expr[EXPRSIZE];
282 sprintf(prntstr, "%s", string[tok[1]]);
283 printf("%s", prntstr);
286 unused = write(list_fd, prntstr, (LONG)strlen(prntstr));
293 if (tok[1] != SYMBOL)
296 // strcpy(prntstr, (char *)tok[2]);
297 strcpy(prntstr, string[tok[2]]);
301 case 'l': case 'L': wordlong = 1; break;
302 case 'w': case 'W': wordlong = 0; break;
303 case 'x': case 'X': outtype = 0; break;
304 case 'd': case 'D': outtype = 1; break;
305 case 'u': case 'U': outtype = 2; break;
307 error("unknown print format flag");
317 if (expr(r_expr, &eval, &eattr, &esym) != OK)
323 case 0: strcpy(format, "%X"); break;
324 case 1: strcpy(format, "%d" ); break;
325 case 2: strcpy(format, "%u" ); break;
329 sprintf(prntstr, format, eval);
331 sprintf(prntstr, format, eval & 0xFFFF);
333 printf("%s", prntstr);
336 unused = write(list_fd, prntstr, (LONG)strlen(prntstr));
352 error("illegal print token");
358 // Undefine an equated condition code
364 // Check that we are in a RISC section
367 error(".ccundef must be defined in .gpu/.dsp section");
373 error("syntax error; expected symbol");
377 ccname = lookup(string[tok[1]], LABEL, 0);
379 // Make sure symbol is a valid ccdef
380 if (!ccname || !(ccname->sattre & EQUATEDCC))
382 error("invalid equated condition name specified");
386 ccname->sattre |= UNDEF_CC;
393 // Undefine an equated register
395 int d_equrundef(void)
399 // Check that we are in a RISC section
401 return error(".equrundef/.regundef must be defined in .gpu/.dsp section");
405 // Skip preceeding or seperating commas (if any)
409 // Check we are dealing with a symbol
411 return error("syntax error; expected symbol");
413 // Lookup and undef if equated register
414 regname = lookup(string[tok[1]], LABEL, 0);
416 if (regname && (regname->sattre & EQUATEDREG))
418 // Reset the attributes of this symbol...
420 regname->sattre &= ~(EQUATEDREG | BANK_0 | BANK_1);
421 regname->sattre |= UNDEF_EQUR;
424 // Skip over symbol token and address
433 // Do not allow use of the CLR.L opcode
437 warn("CLR.L opcode ignored...");
443 // Include binary file
449 long pos, size, bytesRead;
453 // Check to see if we're in BSS, and, if so, throw an error
456 error("cannot include binary file \"%s\" in BSS section", string[tok[1]]);
462 error("syntax error; file to include missing");
466 // Attempt to open the include file in the current directory, then (if that
467 // failed) try list of include files passed in the enviroment string or by
469 if ((fd = open(string[tok[1]], _OPEN_INC)) < 0)
471 for(i=0; nthpath("RMACPATH", i, buf1)!=0; i++)
475 // Append path char if necessary
476 if (fd > 0 && buf1[fd - 1] != SLASHCHAR)
477 strcat(buf1, SLASHSTRING);
479 strcat(buf1, string[tok[1]]);
481 if ((fd = open(buf1, _OPEN_INC)) >= 0)
485 return error("cannot open: \"%s\"", string[tok[1]]);
490 size = lseek(fd, 0L, SEEK_END);
491 pos = lseek(fd, 0L, SEEK_SET);
494 DEBUG { printf("INCBIN: File '%s' is %li bytes.\n", string[tok[1]], size); }
496 char * fileBuffer = (char *)malloc(size);
497 bytesRead = read(fd, fileBuffer, size);
499 if (bytesRead != size)
501 error("was only able to read %li bytes from binary file (%s, %li bytes)", bytesRead, string[tok[1]], size);
505 memcpy(chptr, fileBuffer, size);
520 // Set RISC register banks
524 // Set active register bank zero
532 // Set active register bank one
539 // Helper function, to cut down on mistakes & typing
541 static inline void SkipBytes(unsigned bytesToSkip)
546 if ((scattr & SBSS) == 0)
548 chcheck(bytesToSkip);
549 D_ZEROFILL(bytesToSkip);
556 orgaddr += bytesToSkip;
562 // Adjust location to an EVEN value
567 return error(in_6502mode);
569 unsigned skip = (rgpu || rdsp ? orgaddr : sloc) & 0x01;
573 if ((scattr & SBSS) == 0)
592 // Adjust location to a LONG value
596 unsigned lower2Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x03;
597 unsigned bytesToSkip = (0x04 - lower2Bits) & 0x03;
598 SkipBytes(bytesToSkip);
599 SetLargestAlignment(4);
606 // Adjust location to a PHRASE value
608 // N.B.: We have to handle the GPU/DSP cases separately because you can embed
609 // RISC code in the middle of a regular 68K section. Also note that all
610 // of the alignment pseudo-ops will have to be fixed this way.
612 // This *must* behave differently when in a RISC section, as following sloc
613 // (instead of orgaddr) will fuck things up royally. Note that we do it this
614 // way because you can embed RISC code in a 68K section, and have the origin
615 // pointing to a different alignment in the RISC section than the 68K section.
619 unsigned lower3Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x07;
620 unsigned bytesToSkip = (0x08 - lower3Bits) & 0x07;
621 SkipBytes(bytesToSkip);
622 SetLargestAlignment(8);
629 // Adjust location to a DPHRASE value
633 unsigned lower4Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x0F;
634 unsigned bytesToSkip = (0x10 - lower4Bits) & 0x0F;
635 SkipBytes(bytesToSkip);
636 SetLargestAlignment(16);
643 // Adjust location to a QPHRASE value
647 unsigned lower5Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x1F;
648 unsigned bytesToSkip = (0x20 - lower5Bits) & 0x1F;
649 SkipBytes(bytesToSkip);
650 SetLargestAlignment(32);
657 // Do auto-even. This must be called ONLY if 'sloc' is odd.
659 // This is made hairy because, if there was a label on the line, we also have
660 // to adjust its value. This won't work with more than one label on the line,
661 // which is OK since multiple labels are only allowed in AS68 kludge mode, and
662 // the C compiler is VERY paranoid and uses ".even" whenever it can
664 // N.B.: This probably needs the same fixes as above...
668 if (cursect != M6502)
671 sloc++; // Bump BSS section
673 D_byte(0); // Deposit 0.b in non-BSS
675 if (lab_sym != NULL) // Bump label if we have to
682 // Unimplemened directive error
686 return error("unimplemented directive");
691 // Return absolute (not TDB) and defined expression or return an error
693 int abs_expr(uint64_t * a_eval)
697 if (expr(exprbuf, a_eval, &eattr, NULL) < 0)
700 if (!(eattr & DEFINED))
701 return error(undef_error);
704 return error(rel_error);
711 // Hand symbols in a symbol-list to a function (kind of like mapcar...)
713 int symlist(int(* func)())
715 const char * em = "symbol list syntax";
722 if ((*func)(string[tok[1]]) != OK)
741 // .include "filename"
751 if (*tok == STRING) // Leave strings ALONE
753 else if (*tok == SYMBOL) // Try to append ".s" to symbols
755 strcpy(buf, string[*++tok]);
759 else // Punt if no STRING or SYMBOL
760 return error("missing filename");
762 // Make sure the user didn't try anything like:
763 // .include equates.s
765 return error("extra stuff after filename--enclose it in quotes");
767 // Attempt to open the include file in the current directory, then (if that
768 // failed) try list of include files passed in the enviroment string or by
770 if ((j = open(fn, 0)) < 0)
772 for(i=0; nthpath("RMACPATH", i, buf1)!=0; i++)
776 // Append path char if necessary
777 if (j > 0 && buf1[j - 1] != SLASHCHAR)
778 strcat(buf1, SLASHSTRING);
782 if ((j = open(buf1, 0)) >= 0)
786 return error("cannot open: \"%s\"", fn);
796 // .assert expression [, expression...]
803 for(; expr(exprbuf, &eval, &eattr, NULL)==OK; ++tok)
805 if (!(eattr & DEFINED))
806 return error("forward or undefined .assert");
809 return error("assert failure");
821 // .globl symbol [, symbol] <<<cannot make local symbols global>>>
828 return error("cannot .globl local symbol");
830 if ((sy = lookup(p, LABEL, 0)) == NULL)
832 sy = NewSymbol(p, LABEL, 0);
835 //printf("glob1: Making global symbol: attr=%04X, eattr=%08X, %s\n", sy->sattr, sy->sattre, sy->sname);
847 return error(in_6502mode);
855 // .prgflags expression
862 return error("PRGFLAGS requires value");
863 else if (abs_expr(&eval) == OK)
865 PRGFLAGS = (uint32_t)eval;
870 return error("PRGFLAGS requires value");
883 return error(in_6502mode);
889 else if (abs_expr(&eval) != OK)
893 sloc = (uint32_t)eval;
904 return error("directive forbidden in gpu/dsp mode");
906 return error(in_6502mode);
921 return error("directive forbidden in gpu/dsp mode");
923 return error(in_6502mode);
938 return error("directive forbidden in gpu/dsp mode");
940 return error(in_6502mode);
953 // .ds[.size] expression
957 DEBUG { printf("Directive: .ds.[size] = %u, sloc = $%X\n", siz, sloc); }
961 if (cursect != M6502)
963 if ((siz != SIZB) && (sloc & 1)) // Automatic .even
967 if (abs_expr(&eval) != OK)
970 // Check to see if the value being passed in is negative (who the hell does
971 // that?--nobody does; it's the code gremlins, or rum, that does it)
972 // N.B.: Since 'eval' is of type uint32_t, if it goes negative, it will have
974 if (eval & 0x80000000)
975 return error("negative sizes not allowed");
977 // In non-TDB section (BSS, ABS and M6502) just advance the location
978 // counter appropriately. In TDB sections, deposit (possibly large) chunks
979 // of zeroed memory....
980 if ((scattr & SBSS) || cursect == M6502)
982 listvalue((uint32_t)eval);
984 sloc += (uint32_t)eval;
986 if (cursect == M6502)
989 just_bss = 1; // No data deposited (8-bit CPU mode)
993 dep_block(eval, siz, 0, (WORD)(DEFINED | ABS), NULL);
1002 // dc.b, dc.w / dc, dc.l, dc.i, dc.q, dc.d
1010 if ((scattr & SBSS) != 0)
1011 return error("illegal initialization of section");
1013 // Do an auto_even if it's not BYTE sized (hmm, should we be doing this???)
1014 if (cursect != M6502 && (siz != SIZB) && (sloc & 1))
1017 // Check to see if we're trying to set LONGS on a non 32-bit aligned
1018 // address in a GPU or DSP section, in their local RAM
1019 if ((siz == SIZL) && (orgaddr & 0x03)
1020 && ((rgpu && (orgaddr >= 0xF03000) && (orgaddr <= 0xF03FFFF))
1021 || (rdsp && (orgaddr >= 0xF1B000) && (orgaddr <= 0xF1CFFFF))))
1022 warn("depositing LONGs on a non-long address in local RAM");
1026 // dc.b 'string' [,] ...
1027 if (siz == SIZB && (*tok == STRING || *tok == STRINGA8) && (tok[2] == ',' || tok[2] == EOL))
1029 uint32_t i = strlen(string[tok[1]]);
1031 if ((challoc - ch_size) < i)
1036 for(p=string[tok[1]]; *p!=EOS; p++)
1039 else if(*tok == STRINGA8)
1041 for(p=string[tok[1]]; *p!=EOS; p++)
1042 D_byte(strtoa8[*p]);
1046 error("String format not supported... yet");
1053 int movei = 0; // MOVEI flag for dc.i
1062 // dc.x <expression>
1065 if (expr(exprbuf, &eval, &eattr, &esym) != OK)
1068 uint16_t tdb = eattr & TDB;
1069 uint16_t defined = eattr & DEFINED;
1076 AddFixup(FU_BYTE | FU_SEXT, sloc, exprbuf);
1082 return error("non-absolute byte value");
1084 if (eval + 0x100 >= 0x200)
1085 return error("%s (value = $%X)", range_error, eval);
1095 AddFixup(FU_WORD | FU_SEXT, sloc, exprbuf);
1100 if (eval + 0x10000 >= 0x20000)
1101 return error(range_error);
1104 MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
1106 // Deposit 68000 or 6502 (byte-reversed) word
1107 if (cursect != M6502)
1115 // Shamus: Why can't we do longs in 6502 mode?
1117 return error(in_6502mode);
1122 AddFixup(FU_LONG | FU_MOVEI, sloc, exprbuf);
1124 AddFixup(FU_LONG, sloc, exprbuf);
1131 MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
1134 eval = WORDSWAP32(eval);
1143 return error(in_6502mode);
1145 // Shamus: We only handle DC.Q type stuff, will have to add fixups
1146 // and stuff later (maybe... might not be needed...)
1147 // DEFINITELY NEED FIXUPS HERE!
1150 AddFixup(FU_QUAD, sloc, exprbuf);
1160 // 32-bit float size
1162 return error(in_6502mode);
1166 AddFixup(FU_FLOATSING, sloc, exprbuf);
1171 //Would this *ever* happen?
1173 // MarkRelocatable(cursect, sloc, tdb, MSINGLE, NULL);
1177 uint32_t ieee754 = FloatToIEEE754((float)*ptr.dp);
1183 // 64-bit double size
1185 return error(in_6502mode);
1189 AddFixup(FU_FLOATDOUB, sloc, exprbuf);
1194 //Would this *ever* happen?
1196 // MarkRelocatable(cursect, sloc, tdb, MDOUBLE, NULL);
1200 uint64_t ieee754 = DoubleToIEEE754(*ptr.dp);
1207 return error(in_6502mode);
1210 memset(extDbl, 0, 12);
1214 AddFixup(FU_FLOATEXT, sloc, exprbuf);
1219 //Would this *ever* happen?
1221 // MarkRelocatable(cursect, sloc, tdb, MEXTEND, NULL);
1225 DoubleToExtended(*ptr.dp, extDbl);
1243 // dcb[.siz] expr1,expr2 - Make 'expr1' copies of 'expr2'
1247 uint64_t evalc, eval;
1250 DEBUG { printf("dcb: section is %s%s%s (scattr=$%X)\n", (cursect & TEXT ? "TEXT" : ""), (cursect & DATA ? " DATA" : ""), (cursect & BSS ? "BSS" : ""), scattr); }
1252 if ((scattr & SBSS) != 0)
1253 return error("illegal initialization of section");
1255 if (abs_expr(&evalc) != OK)
1259 return error("missing comma");
1261 if (expr(exprbuf, &eval, &eattr, NULL) < 0)
1264 if (cursect != M6502 && (siz != SIZB) && (sloc & 1))
1267 dep_block((uint32_t)evalc, siz, (uint32_t)eval, eattr, exprbuf);
1273 // Generalized initialization directive
1275 // .init[.siz] [#count,] expression [.size] , ...
1277 // The size suffix on the ".init" directive becomes the default size of the
1278 // objects to deposit. If an item is preceeded with a sharp (immediate) sign
1279 // and an expression, it specifies a repeat count. The value to be deposited
1280 // may be followed by a size suffix, which overrides the default size.
1282 int d_init(WORD def_siz)
1289 if ((scattr & SBSS) != 0)
1290 return error(".init not permitted in BSS or ABS");
1293 return error("directive forbidden in gpu/dsp mode");
1297 // Get repeat count (defaults to 1)
1302 if (abs_expr(&count) != OK)
1306 return error(comma_error);
1311 // Evaluate expression to deposit
1312 if (expr(exprbuf, &eval, &eattr, NULL) < 0)
1316 { // Determine size of object to deposit
1317 case DOTB: siz = SIZB; break;
1318 case DOTW: siz = SIZB; break;
1319 case DOTL: siz = SIZL; break;
1326 dep_block((uint32_t)count, siz, (uint32_t)eval, eattr, exprbuf);
1336 return error(comma_error);
1343 // Deposit 'count' values of size 'siz' in the current (non-BSS) segment
1345 int dep_block(uint32_t count, WORD siz, uint32_t eval, WORD eattr, TOKEN * exprbuf)
1350 tdb = (WORD)(eattr & TDB);
1351 defined = (WORD)(eattr & DEFINED);
1355 if ((challoc - ch_size) < 4)
1363 AddFixup(FU_BYTE | FU_SEXT, sloc, exprbuf);
1369 return error("non-absolute byte value");
1371 if (eval + 0x100 >= 0x200)
1372 return error(range_error);
1382 AddFixup(FU_WORD | FU_SEXT, sloc, exprbuf);
1388 MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
1390 if (eval + 0x10000 >= 0x20000)
1391 return error(range_error);
1393 // Deposit 68000 or 6502 (byte-reversed) word
1394 if (cursect != M6502)
1404 return error(in_6502mode);
1408 AddFixup(FU_LONG, sloc, exprbuf);
1414 MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
1428 // .comm symbol, size
1437 return error(in_6502mode);
1440 return error("missing symbol");
1445 if (*p == '.') // Cannot .comm a local symbol
1446 return error(locgl_error);
1448 if ((sym = lookup(p, LABEL, 0)) == NULL)
1449 sym = NewSymbol(p, LABEL, 0);
1452 if (sym->sattr & DEFINED)
1453 return error(".comm symbol already defined");
1456 sym->sattr = GLOBAL | COMMON | BSS;
1459 return error(comma_error);
1461 if (abs_expr(&eval) != OK) // Parse size of common region
1464 sym->svalue = eval; // Install common symbol's size
1471 // .list - Turn listing on
1483 // .nlist - Turn listing off
1495 // .68000 - Back to 68000 TEXT segment
1499 rgpu = rdsp = robjproc = 0;
1500 // Switching from gpu/dsp sections should reset any ORG'd Address
1504 SwitchSection(TEXT);
1505 activecpu = CPU_68000;
1511 // .68020 - Back to 68000 TEXT segment and select 68020
1516 activecpu = CPU_68020;
1522 // .68030 - Back to 68000 TEXT segment and select 68030
1527 activecpu = CPU_68030;
1533 // .68040 - Back to 68000 TEXT segment and select 68040
1538 activecpu = CPU_68040;
1539 activefpu = FPU_68040;
1545 // .68060 - Back to 68000 TEXT segment and select 68060
1550 activecpu = CPU_68060;
1551 activefpu = FPU_68060;
1557 // .68881 - Back to 680x0 TEXT segment and select 68881 FPU
1562 activefpu = FPU_68881;
1568 // .68882 - Back to 680x0 TEXT segment and select 68882 FPU
1573 activefpu = FPU_68882;
1579 // nofpu - Deselect FPUs.
1583 activefpu = FPU_NONE;
1593 return error("Not yet, child. Be patient.");
1598 // .gpu - Switch to GPU assembler
1602 if ((cursect != TEXT) && (cursect != DATA))
1604 error(".gpu can only be used in the TEXT or DATA segments");
1608 // If previous section was DSP or 68000 then we need to reset ORG'd Addresses
1615 rgpu = 1; // Set GPU assembly
1616 rdsp = 0; // Unset DSP assembly
1617 robjproc = 0; // Unset OP assembly
1618 regbank = BANK_N; // Set no default register bank
1624 // .dsp - Switch to DSP assembler
1628 if ((cursect != TEXT) && (cursect != DATA))
1630 error(".dsp can only be used in the TEXT or DATA segments");
1634 // If previous section was gpu or 68000 then we need to reset ORG'd Addresses
1641 rdsp = 1; // Set DSP assembly
1642 rgpu = 0; // Unset GPU assembly
1643 robjproc = 0; // Unset OP assembly
1644 regbank = BANK_N; // Set no default register bank
1650 // .cargs [#offset], symbol[.size], ...
1652 // Lists of registers may also be mentioned; they just take up space. Good for
1653 // "documentation" purposes:
1655 // .cargs a6, .arg1, .arg2, .arg3...
1657 // Symbols thus created are ABS and EQUATED.
1661 uint64_t eval = 4; // Default to 4 if no offset specified (to account for
1670 return error("directive forbidden in gpu/dsp mode");
1676 if (abs_expr(&eval) != OK)
1679 // Eat the comma, if it's there
1690 // Set env to either local (dot prefixed) or global scope
1691 env = (*p == '.' ? curenv : 0);
1692 symbol = lookup(p, LABEL, env);
1696 symbol = NewSymbol(p, LABEL, env);
1699 else if (symbol->sattr & DEFINED)
1700 return error("multiply-defined label '%s'", p);
1702 // Put symbol in "order of definition" list
1703 AddToSymbolDeclarationList(symbol);
1705 symbol->sattr |= (ABS | DEFINED | EQUATED);
1706 symbol->svalue = eval;
1709 // What this does is eat any dot suffixes attached to a symbol. If
1710 // it's a .L, it adds 4 to eval; if it's .W or .B, it adds 2. If
1711 // there is no dot suffix, it assumes a size of 2.
1723 else if (*tok >= KW_D0 && *tok <= KW_A7)
1725 if (reglist(&rlist) < 0)
1728 for(i=0; i<16; i++, rlist>>=1)
1751 return error(".cargs syntax");
1755 // Eat commas in between each argument, if they exist
1763 // .cstruct [#offset], symbol[.size], ...
1765 // Lists of registers may also be mentioned; they just take up space. Good for
1766 // "documentation" purposes:
1768 // .cstruct a6, .arg1, .arg2, .arg3...
1770 // Symbols thus created are ABS and EQUATED. Note that this is for
1771 // compatibility with VBCC and the Remover's library. Thanks to GroovyBee for
1776 uint64_t eval = 0; // Default, if no offset specified, is zero
1784 return error("directive forbidden in gpu/dsp mode");
1790 if (abs_expr(&eval) != OK)
1793 // Eat the comma, if it's there
1802 symbolName = string[tok[1]];
1804 // Set env to either local (dot prefixed) or global scope
1805 env = (symbolName[0] == '.' ? curenv : 0);
1806 symbol = lookup(symbolName, LABEL, env);
1808 // If the symbol wasn't found, then define it. Otherwise, throw an
1812 symbol = NewSymbol(symbolName, LABEL, env);
1815 else if (symbol->sattr & DEFINED)
1816 return error("multiply-defined label '%s'", symbolName);
1818 // Put symbol in "order of definition" list
1819 AddToSymbolDeclarationList(symbol);
1823 // Adjust label start address if it's a word or a long, as a byte
1824 // label might have left us on an odd address.
1829 eval += eval & 0x01;
1832 symbol->sattr |= (ABS | DEFINED | EQUATED);
1833 symbol->svalue = eval;
1835 // Check for dot suffixes and adjust space accordingly (longs and
1836 // words on an odd boundary get bumped to the next word aligned
1837 // address). If no suffix, then throw an error.
1850 return error("Symbol missing dot suffix in .cstruct construct");
1855 else if (*tok >= KW_D0 && *tok <= KW_A7)
1857 if (reglist(&rlist) < 0)
1860 for(i=0; i<16; i++, rlist>>=1)
1883 return error(".cstruct syntax");
1887 // Eat commas in between each argument, if they exist
1895 // Define start of OP object list (allows the use of ORG)
1899 if ((cursect != TEXT) && (cursect != DATA))
1901 error(".objproc can only be used in the TEXT or DATA segments");
1905 // If previous section was DSP or 68000 then we need to reset ORG'd
1913 robjproc = 1; // Set OP assembly
1914 rgpu = 0; // Unset GPU assembly
1915 rdsp = 0; // Unset DSP assembly
1921 // Undefine a macro - .undefmac macname [, macname...]
1923 int undmac1(char * p)
1925 SYM * symbol = lookup(p, MACRO, 0);
1927 // If the macro symbol exists, cause it to disappear
1929 symbol->stype = (BYTE)SY_UNDEF;
1944 warn("JPAD directive is deprecated/non-functional");
1951 warn("NOJPAD directive is deprecated/non-functional");
1958 return error("What the hell? Do you think we adhere to the Goof standard?");
1963 // .opt - turn a specific (or all) optimisation on or off
1972 char * tmpstr = string[*tok++];
1974 if (ParseOptimization(tmpstr) != OK)
1975 return error("unknown optimization flag '%s'", tmpstr);
1978 return error(".opt directive needs every switch enclosed inside quotation marks");
1986 // .if, Start conditional assembly
1993 IFENT * rif = f_ifent;
1997 rif = (IFENT *)malloc(sizeof(IFENT));
1999 f_ifent = rif->if_prev;
2001 rif->if_prev = ifent;
2006 if (expr(exprbuf, &eval, &eattr, &esym) != OK)
2009 if ((eattr & DEFINED) == 0)
2010 return error(undef_error);
2015 rif->if_state = (WORD)disabled;
2021 // .else, Do alternate case for .if
2025 IFENT * rif = ifent;
2027 if (rif->if_prev == NULL)
2028 return error("mismatched .else");
2031 disabled = rif->if_prev->if_state;
2035 rif->if_state = (WORD)disabled;
2041 // .endif, End of conditional assembly block
2042 // This is also called by fpop() to pop levels of IFENTs in case a macro or
2043 // include file exits early with `exitm' or `end'.
2047 IFENT * rif = ifent;
2049 if (rif->if_prev == NULL)
2050 return error("mismatched .endif");
2052 ifent = rif->if_prev;
2053 disabled = rif->if_prev->if_state;
2054 rif->if_prev = f_ifent;