2 // RMAC - Reboot's Macro Assembler for all Atari computers
3 // DIRECT.C - Directive Handling
4 // Copyright (C) 199x Landon Dyer, 2011-2017 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
27 TOKEN exprbuf[128]; // Expression buffer
28 SYM * symbolPtr[1000000]; // Symbol pointers table
29 static long unused; // For supressing 'write' warnings
30 char buffer[256]; // Scratch buffer for messages
31 int largestAlign[3] = { 2, 2, 2 }; // Largest alignment value seen per section
33 // Function prototypes
70 int d_equrundef(void);
81 void SetLargestAlignment(int);
83 // Directive handler table
94 (void *)d_init, // 9 init
96 (void *)d_goto, // 11 goto
97 (void *)d_dc, // 12 dc
98 (void *)d_ds, // 13 ds
99 d_undmac, // 14 undefmac
102 (void *)d_dcb, // 17 dcb
106 d_incbin, // 21 .incbin //load
107 d_unimpl, // 22 disable
108 d_unimpl, // 23 enable
110 d_regbank0, // 25 .regbank0
111 d_regbank1, // 26 .regbank1
113 d_assert, // 28 assert
115 d_unimpl, // 30* endif
116 d_unimpl, // 31* endc
118 d_include, // 33 include
120 d_unimpl, // 35* macro
121 ExitMacro, // 36* exitm
122 d_unimpl, // 37* endm
126 d_phrase, // 41* endr
127 d_dphrase, // 42 struct
128 d_qphrase, // 43 ends
130 d_subttl, // 45 subttl
134 d_noclear, // 49 .noclear
135 d_equrundef, // 50 .equrundef/.regundef
136 d_ccundef, // 51 .ccundef
137 d_print, // 52 .print
138 d_cstruct, // 53 .cstruct
139 d_jpad, // 54 .jpad (deprecated)
140 d_nojpad, // 55 .nojpad (deprecated)
141 d_gpumain, // 56 .gpumain (deprecated)
142 d_prgflags, // 57 .prgflags
143 d_68020, // 58 .68020
144 d_68030, // 59 .68030
145 d_68040, // 60 .68040
146 d_68060, // 61 .68060
147 d_68881, // 62 .68881
148 d_68882, // 63 .68882
149 d_56001, // 64 .56001
156 // Set the largest alignment seen in the current section
158 void SetLargestAlignment(int size)
160 if ((scattr & TEXT) && (largestAlign[0] < size))
161 largestAlign[0] = size;
162 else if ((scattr & DATA) && (largestAlign[1] < size))
163 largestAlign[1] = size;
164 else if ((scattr & BSS) && (largestAlign[2] < size))
165 largestAlign[2] = size;
170 // .error - Abort compilation, printing an error message
172 int d_error(char *str)
175 return error("error directive encountered - aborting assembling");
181 return error(string[tok[1]]);
184 return error("error directive encountered--aborting assembly");
191 // .warn - Just display a warning on screen
193 int d_warn(char *str)
196 return warn("WARNING WARNING WARNING");
202 return warn(string[tok[1]]);
205 return warn("WARNING WARNING WARNING");
218 if (!rgpu && !rdsp && !m6502)
219 return error(".org permitted only in gpu/dsp and 6502 sections");
221 if (abs_expr(&address) == ERROR)
223 error("cannot determine org'd address");
234 // 6502. We also kludge `lsloc' so the listing generator doesn't try
235 // to spew out megabytes.
236 if (address > 0xFFFF)
237 return error(range_error);
239 if (sloc != currentorg[0])
241 currentorg[1] = sloc;
245 currentorg[0] = address;
247 lsloc = sloc = address;
248 chptr = scode->chptr + address;
263 char prntstr[LNSIZ]; // String for PRINT directive
264 char format[LNSIZ]; // Format for PRINT directive
265 int formatting = 0; // Formatting on/off
266 int wordlong = 0; // WORD = 0, LONG = 1
267 int outtype = 0; // 0:hex, 1:decimal, 2:unsigned
269 uint64_t eval; // Expression value
270 WORD eattr; // Expression attributes
271 SYM * esym; // External symbol involved in expr.
272 TOKEN r_expr[EXPRSIZE];
279 sprintf(prntstr, "%s", string[tok[1]]);
280 printf("%s", prntstr);
283 unused = write(list_fd, prntstr, (LONG)strlen(prntstr));
290 if (tok[1] != SYMBOL)
293 // strcpy(prntstr, (char *)tok[2]);
294 strcpy(prntstr, string[tok[2]]);
298 case 'l': case 'L': wordlong = 1; break;
299 case 'w': case 'W': wordlong = 0; break;
300 case 'x': case 'X': outtype = 0; break;
301 case 'd': case 'D': outtype = 1; break;
302 case 'u': case 'U': outtype = 2; break;
304 error("unknown print format flag");
314 if (expr(r_expr, &eval, &eattr, &esym) != OK)
320 case 0: strcpy(format, "%X"); break;
321 case 1: strcpy(format, "%d" ); break;
322 case 2: strcpy(format, "%u" ); break;
326 sprintf(prntstr, format, eval);
328 sprintf(prntstr, format, eval & 0xFFFF);
330 printf("%s", prntstr);
333 unused = write(list_fd, prntstr, (LONG)strlen(prntstr));
349 error("illegal print token");
355 // Undefine an equated condition code
361 // Check that we are in a RISC section
364 error(".ccundef must be defined in .gpu/.dsp section");
370 error("syntax error; expected symbol");
374 ccname = lookup(string[tok[1]], LABEL, 0);
376 // Make sure symbol is a valid ccdef
377 if (!ccname || !(ccname->sattre & EQUATEDCC))
379 error("invalid equated condition name specified");
383 ccname->sattre |= UNDEF_CC;
390 // Undefine an equated register
392 int d_equrundef(void)
396 // Check that we are in a RISC section
398 return error(".equrundef/.regundef must be defined in .gpu/.dsp section");
402 // Skip preceeding or seperating commas (if any)
406 // Check we are dealing with a symbol
408 return error("syntax error; expected symbol");
410 // Lookup and undef if equated register
411 regname = lookup(string[tok[1]], LABEL, 0);
413 if (regname && (regname->sattre & EQUATEDREG))
415 // Reset the attributes of this symbol...
417 regname->sattre &= ~(EQUATEDREG | BANK_0 | BANK_1);
418 regname->sattre |= UNDEF_EQUR;
421 // Skip over symbol token and address
430 // Do not allow use of the CLR.L opcode
434 warn("CLR.L opcode ignored...");
440 // Include binary file
446 long pos, size, bytesRead;
450 // Check to see if we're in BSS, and, if so, throw an error
453 error("cannot include binary file \"%s\" in BSS section", string[tok[1]]);
459 error("syntax error; string missing");
463 // Attempt to open the include file in the current directory, then (if that
464 // failed) try list of include files passed in the enviroment string or by
466 if ((fd = open(string[tok[1]], _OPEN_INC)) < 0)
468 for(i=0; nthpath("RMACPATH", i, buf1)!=0; i++)
472 // Append path char if necessary
473 if (fd > 0 && buf1[fd - 1] != SLASHCHAR)
474 strcat(buf1, SLASHSTRING);
476 strcat(buf1, string[tok[1]]);
478 if ((fd = open(buf1, _OPEN_INC)) >= 0)
482 return error("cannot open: \"%s\"", string[tok[1]]);
487 size = lseek(fd, 0L, SEEK_END);
488 pos = lseek(fd, 0L, SEEK_SET);
491 DEBUG { printf("INCBIN: File '%s' is %li bytes.\n", string[tok[1]], size); }
493 char * fileBuffer = (char *)malloc(size);
494 bytesRead = read(fd, fileBuffer, size);
496 if (bytesRead != size)
498 error("was only able to read %li bytes from binary file (%s, %li bytes)", bytesRead, string[tok[1]], size);
502 memcpy(chptr, fileBuffer, size);
517 // Set RISC register banks
521 // Set active register bank zero
529 // Set active register bank one
536 // Helper function, to cut down on mistakes & typing
538 static inline void SkipBytes(unsigned bytesToSkip)
543 if ((scattr & SBSS) == 0)
545 chcheck(bytesToSkip);
546 D_ZEROFILL(bytesToSkip);
553 orgaddr += bytesToSkip;
559 // Adjust location to an EVEN value
564 return error(in_6502mode);
566 unsigned skip = (rgpu || rdsp ? orgaddr : sloc) & 0x01;
570 if ((scattr & SBSS) == 0)
589 // Adjust location to a LONG value
593 unsigned lower2Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x03;
594 unsigned bytesToSkip = (0x04 - lower2Bits) & 0x03;
595 SkipBytes(bytesToSkip);
596 SetLargestAlignment(4);
603 // Adjust location to a PHRASE value
605 // N.B.: We have to handle the GPU/DSP cases separately because you can embed
606 // RISC code in the middle of a regular 68K section. Also note that all
607 // of the alignment pseudo-ops will have to be fixed this way.
609 // This *must* behave differently when in a RISC section, as following sloc
610 // (instead of orgaddr) will fuck things up royally. Note that we do it this
611 // way because you can embed RISC code in a 68K section, and have the origin
612 // pointing to a different alignment in the RISC section than the 68K section.
616 unsigned lower3Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x07;
617 unsigned bytesToSkip = (0x08 - lower3Bits) & 0x07;
618 SkipBytes(bytesToSkip);
619 SetLargestAlignment(8);
626 // Adjust location to a DPHRASE value
630 unsigned lower4Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x0F;
631 unsigned bytesToSkip = (0x10 - lower4Bits) & 0x0F;
632 SkipBytes(bytesToSkip);
633 SetLargestAlignment(16);
640 // Adjust location to a QPHRASE value
644 unsigned lower5Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x1F;
645 unsigned bytesToSkip = (0x20 - lower5Bits) & 0x1F;
646 SkipBytes(bytesToSkip);
647 SetLargestAlignment(32);
654 // Do auto-even. This must be called ONLY if 'sloc' is odd.
656 // This is made hairy because, if there was a label on the line, we also have
657 // to adjust its value. This won't work with more than one label on the line,
658 // which is OK since multiple labels are only allowed in AS68 kludge mode, and
659 // the C compiler is VERY paranoid and uses ".even" whenever it can
661 // N.B.: This probably needs the same fixes as above...
665 if (cursect != M6502)
668 sloc++; // Bump BSS section
670 D_byte(0); // Deposit 0.b in non-BSS
672 if (lab_sym != NULL) // Bump label if we have to
679 // Unimplemened directive error
683 return error("unimplemented directive");
688 // Return absolute (not TDB) and defined expression or return an error
690 int abs_expr(uint64_t * a_eval)
694 if (expr(exprbuf, a_eval, &eattr, NULL) < 0)
697 if (!(eattr & DEFINED))
698 return error(undef_error);
701 return error(rel_error);
708 // Hand symbols in a symbol-list to a function (kind of like mapcar...)
710 int symlist(int(* func)())
712 const char * em = "symbol list syntax";
719 if ((*func)(string[tok[1]]) != OK)
738 // .include "filename"
748 if (*tok == STRING) // Leave strings ALONE
750 else if (*tok == SYMBOL) // Try to append ".s" to symbols
752 strcpy(buf, string[*++tok]);
756 else // Punt if no STRING or SYMBOL
757 return error("missing filename");
759 // Make sure the user didn't try anything like:
760 // .include equates.s
762 return error("extra stuff after filename--enclose it in quotes");
764 // Attempt to open the include file in the current directory, then (if that
765 // failed) try list of include files passed in the enviroment string or by
767 if ((j = open(fn, 0)) < 0)
769 for(i=0; nthpath("RMACPATH", i, buf1)!=0; i++)
773 // Append path char if necessary
774 if (j > 0 && buf1[j - 1] != SLASHCHAR)
775 strcat(buf1, SLASHSTRING);
779 if ((j = open(buf1, 0)) >= 0)
783 return error("cannot open: \"%s\"", fn);
793 // .assert expression [, expression...]
800 for(; expr(exprbuf, &eval, &eattr, NULL)==OK; ++tok)
802 if (!(eattr & DEFINED))
803 return error("forward or undefined .assert");
806 return error("assert failure");
818 // .globl symbol [, symbol] <<<cannot make local symbols global>>>
825 return error("cannot .globl local symbol");
827 if ((sy = lookup(p, LABEL, 0)) == NULL)
829 sy = NewSymbol(p, LABEL, 0);
832 //printf("glob1: Making global symbol: attr=%04X, eattr=%08X, %s\n", sy->sattr, sy->sattre, sy->sname);
844 return error(in_6502mode);
852 // .prgflags expression
859 return error("PRGFLAGS requires value");
860 else if (abs_expr(&eval) == OK)
867 return error("PRGFLAGS requires value");
880 return error(in_6502mode);
886 else if (abs_expr(&eval) != OK)
901 return error("directive forbidden in gpu/dsp mode");
903 return error(in_6502mode);
918 return error("directive forbidden in gpu/dsp mode");
920 return error(in_6502mode);
935 return error("directive forbidden in gpu/dsp mode");
937 return error(in_6502mode);
950 // .ds[.size] expression
954 DEBUG { printf("Directive: .ds.[size] = %u, sloc = $%X\n", siz, sloc); }
958 if (cursect != M6502)
960 if ((siz != SIZB) && (sloc & 1)) // Automatic .even
964 if (abs_expr(&eval) != OK)
967 // Check to see if the value being passed in is negative (who the hell does
968 // that?--nobody does; it's the code gremlins, or rum, that does it)
969 // N.B.: Since 'eval' is of type uint32_t, if it goes negative, it will have
971 if (eval & 0x80000000)
972 return error("negative sizes not allowed");
974 // In non-TDB section (BSS, ABS and M6502) just advance the location
975 // counter appropriately. In TDB sections, deposit (possibly large) chunks
976 // of zeroed memory....
977 if ((scattr & SBSS) || cursect == M6502)
983 if (cursect == M6502)
986 just_bss = 1; // No data deposited (8-bit CPU mode)
990 dep_block(eval, siz, 0, (WORD)(DEFINED | ABS), NULL);
999 // dc.b, dc.w / dc, dc.l, dc.i
1007 if ((scattr & SBSS) != 0)
1008 return error("illegal initialization of section");
1010 // Do an auto_even if it's not BYTE sized (hmm, should we be doing this???)
1011 if (cursect != M6502 && (siz != SIZB) && (sloc & 1))
1014 // Check to see if we're trying to set LONGS on a non 32-bit aligned
1015 // address in a GPU or DSP section, in their local RAM
1016 if ((siz == SIZL) && (orgaddr & 0x03)
1017 && ((rgpu && (orgaddr >= 0xF03000) && (orgaddr <= 0xF03FFFF))
1018 || (rdsp && (orgaddr >= 0xF1B000) && (orgaddr <= 0xF1CFFFF))))
1019 warn("depositing LONGs on a non-long address in local RAM");
1023 // dc.b 'string' [,] ...
1024 if (siz == SIZB && (*tok == STRING || *tok == STRINGA8) && (tok[2] == ',' || tok[2] == EOL))
1026 uint32_t i = strlen(string[tok[1]]);
1028 if ((challoc - ch_size) < i)
1033 for(p=string[tok[1]]; *p!=EOS; p++)
1036 else if(*tok == STRINGA8)
1038 for(p=string[tok[1]]; *p!=EOS; p++)
1039 D_byte(strtoa8[*p]);
1043 error("String format not supported... yet");
1050 int movei = 0; // MOVEI flag for dc.i
1059 // dc.x <expression>
1062 if (expr(exprbuf, &eval, &eattr, &esym) != OK)
1065 uint16_t tdb = eattr & TDB;
1066 uint16_t defined = eattr & DEFINED;
1068 if ((challoc - ch_size) < 4)
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);
1141 // N.B.: May have to come up with section/fixup markers for this;
1142 // ATM it's only used in dc.d statements...
1144 D_long(eval & 0xFFFFFFFF);
1159 // dcb[.siz] expr1,expr2 - Make 'expr1' copies of 'expr2'
1163 uint64_t evalc, eval;
1166 DEBUG { printf("dcb: section is %s%s%s (scattr=$%X)\n", (cursect & TEXT ? "TEXT" : ""), (cursect & DATA ? " DATA" : ""), (cursect & BSS ? "BSS" : ""), scattr); }
1168 if ((scattr & SBSS) != 0)
1169 return error("illegal initialization of section");
1171 if (abs_expr(&evalc) != OK)
1175 return error("missing comma");
1177 if (expr(exprbuf, &eval, &eattr, NULL) < 0)
1180 if (cursect != M6502 && (siz != SIZB) && (sloc & 1))
1183 dep_block(evalc, siz, eval, eattr, exprbuf);
1189 // Generalized initialization directive
1191 // .init[.siz] [#count,] expression [.size] , ...
1193 // The size suffix on the ".init" directive becomes the default size of the
1194 // objects to deposit. If an item is preceeded with a sharp (immediate) sign
1195 // and an expression, it specifies a repeat count. The value to be deposited
1196 // may be followed by a size suffix, which overrides the default size.
1198 int d_init(WORD def_siz)
1205 if ((scattr & SBSS) != 0)
1206 return error(".init not permitted in BSS or ABS");
1209 return error("directive forbidden in gpu/dsp mode");
1213 // Get repeat count (defaults to 1)
1218 if (abs_expr(&count) != OK)
1222 return error(comma_error);
1227 // Evaluate expression to deposit
1228 if (expr(exprbuf, &eval, &eattr, NULL) < 0)
1231 switch ((int)*tok++)
1232 { // Determine size of object to deposit
1233 case DOTB: siz = SIZB; break;
1234 case DOTW: siz = SIZB; break;
1235 case DOTL: siz = SIZL; break;
1242 dep_block(count, siz, eval, eattr, exprbuf);
1252 return error(comma_error);
1259 // Deposit 'count' values of size 'siz' in the current (non-BSS) segment
1261 int dep_block(uint32_t count, WORD siz, uint32_t eval, WORD eattr, TOKEN * exprbuf)
1266 tdb = (WORD)(eattr & TDB);
1267 defined = (WORD)(eattr & DEFINED);
1271 if ((challoc - ch_size) < 4)
1279 AddFixup(FU_BYTE | FU_SEXT, sloc, exprbuf);
1285 return error("non-absolute byte value");
1287 if (eval + 0x100 >= 0x200)
1288 return error(range_error);
1298 AddFixup(FU_WORD | FU_SEXT, sloc, exprbuf);
1304 MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
1306 if (eval + 0x10000 >= 0x20000)
1307 return error(range_error);
1309 // Deposit 68000 or 6502 (byte-reversed) word
1310 if (cursect != M6502)
1320 return error(in_6502mode);
1324 AddFixup(FU_LONG, sloc, exprbuf);
1330 MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
1344 // .comm symbol, size
1353 return error(in_6502mode);
1356 return error("missing symbol");
1361 if (*p == '.') // Cannot .comm a local symbol
1362 return error(locgl_error);
1364 if ((sym = lookup(p, LABEL, 0)) == NULL)
1365 sym = NewSymbol(p, LABEL, 0);
1368 if (sym->sattr & DEFINED)
1369 return error(".comm symbol already defined");
1372 sym->sattr = GLOBAL | COMMON | BSS;
1375 return error(comma_error);
1377 if (abs_expr(&eval) != OK) // Parse size of common region
1380 sym->svalue = eval; // Install common symbol's size
1387 // .list - Turn listing on
1399 // .nlist - Turn listing off
1411 // .68000 - Back to 68000 TEXT segment
1416 // Switching from gpu/dsp sections should reset any ORG'd Address
1420 SwitchSection(TEXT);
1421 activecpu = CPU_68000;
1427 // .68020 - Back to 68000 TEXT segment and select 68020
1432 activecpu = CPU_68020;
1438 // .68030 - Back to 68000 TEXT segment and select 68030
1443 activecpu = CPU_68030;
1449 // .68040 - Back to 68000 TEXT segment and select 68040
1454 activecpu = CPU_68040;
1455 activefpu = FPU_68040;
1461 // .68060 - Back to 68000 TEXT segment and select 68060
1466 activecpu = CPU_68060;
1467 activefpu = FPU_68040;
1473 // .68881 - Back to 68000 TEXT segment and select 68881 FPU
1478 activefpu = FPU_68881;
1484 // .68882 - Back to 68000 TEXT segment and select 68882 FPU
1489 activefpu = FPU_68881;
1495 // nofpu - Deselect FPUs.
1499 activefpu = FPU_NONE;
1509 return error("Not yet, child. Be patient.");
1514 // .gpu - Switch to GPU assembler
1518 if ((cursect != TEXT) && (cursect != DATA))
1520 error(".gpu can only be used in the TEXT or DATA segments");
1524 // If previous section was dsp or 68000 then we need to reset ORG'd Addresses
1527 //printf("Resetting ORG...\n");
1531 //else printf("NOT resetting ORG!\n");
1533 rgpu = 1; // Set GPU assembly
1534 rdsp = 0; // Unset DSP assembly
1535 regbank = BANK_N; // Set no default register bank
1541 // .dsp - Switch to DSP assembler
1545 if ((cursect != TEXT) && (cursect != DATA))
1547 error(".dsp can only be used in the TEXT or DATA segments");
1551 // If previous section was gpu or 68000 then we need to reset ORG'd Addresses
1558 rdsp = 1; // Set DSP assembly
1559 rgpu = 0; // Unset GPU assembly
1560 regbank = BANK_N; // Set no default register bank
1566 // .cargs [#offset], symbol[.size], ...
1568 // Lists of registers may also be mentioned; they just take up space. Good for
1569 // "documentation" purposes:
1571 // .cargs a6, .arg1, .arg2, .arg3...
1573 // Symbols thus created are ABS and EQUATED.
1577 uint64_t eval = 4; // Default to 4 if no offset specified (to account for
1586 return error("directive forbidden in gpu/dsp mode");
1592 if (abs_expr(&eval) != OK)
1595 // Eat the comma, if it's there
1606 // Set env to either local (dot prefixed) or global scope
1607 env = (*p == '.' ? curenv : 0);
1608 symbol = lookup(p, LABEL, env);
1612 symbol = NewSymbol(p, LABEL, env);
1615 else if (symbol->sattr & DEFINED)
1616 return error("multiply-defined label '%s'", p);
1618 // Put symbol in "order of definition" list
1619 AddToSymbolDeclarationList(symbol);
1621 symbol->sattr |= (ABS | DEFINED | EQUATED);
1622 symbol->svalue = eval;
1625 // What this does is eat any dot suffixes attached to a symbol. If
1626 // it's a .L, it adds 4 to eval; if it's .W or .B, it adds 2. If
1627 // there is no dot suffix, it assumes a size of 2.
1639 else if (*tok >= KW_D0 && *tok <= KW_A7)
1641 if (reglist(&rlist) < 0)
1644 for(i=0; i<16; i++, rlist>>=1)
1667 return error(".cargs syntax");
1671 // Eat commas in between each argument, if they exist
1679 // .cstruct [#offset], symbol[.size], ...
1681 // Lists of registers may also be mentioned; they just take up space. Good for
1682 // "documentation" purposes:
1684 // .cstruct a6, .arg1, .arg2, .arg3...
1686 // Symbols thus created are ABS and EQUATED. Note that this is for
1687 // compatibility with VBCC and the Remover's library. Thanks to GroovyBee for
1692 uint64_t eval = 0; // Default, if no offset specified, is zero
1700 return error("directive forbidden in gpu/dsp mode");
1706 if (abs_expr(&eval) != OK)
1709 // Eat the comma, if it's there
1718 symbolName = string[tok[1]];
1720 // Set env to either local (dot prefixed) or global scope
1721 env = (symbolName[0] == '.' ? curenv : 0);
1722 symbol = lookup(symbolName, LABEL, env);
1724 // If the symbol wasn't found, then define it. Otherwise, throw an
1728 symbol = NewSymbol(symbolName, LABEL, env);
1731 else if (symbol->sattr & DEFINED)
1732 return error("multiply-defined label '%s'", symbolName);
1734 // Put symbol in "order of definition" list
1735 AddToSymbolDeclarationList(symbol);
1739 // Adjust label start address if it's a word or a long, as a byte
1740 // label might have left us on an odd address.
1745 eval += eval & 0x01;
1748 symbol->sattr |= (ABS | DEFINED | EQUATED);
1749 symbol->svalue = eval;
1751 // Check for dot suffixes and adjust space accordingly (longs and
1752 // words on an odd boundary get bumped to the next word aligned
1753 // address). If no suffix, then throw an error.
1766 return error("Symbol missing dot suffix in .cstruct construct");
1771 else if (*tok >= KW_D0 && *tok <= KW_A7)
1773 if (reglist(&rlist) < 0)
1776 for(i=0; i<16; i++, rlist>>=1)
1799 return error(".cstruct syntax");
1803 // Eat commas in between each argument, if they exist
1811 // Undefine a macro - .undefmac macname [, macname...]
1813 int undmac1(char * p)
1815 SYM * symbol = lookup(p, MACRO, 0);
1817 // If the macro symbol exists, cause it to disappear
1819 symbol->stype = (BYTE)SY_UNDEF;
1834 warn("JPAD directive is deprecated/non-functional");
1841 warn("NOJPAD directive is deprecated/non-functional");
1848 return error("What the hell? Do you think we adhere to the Goof standard?");
1853 // .opt - turn a specific (or all) optimisation on or off
1862 char * tmpstr = string[*tok++];
1864 if (ParseOptimization(tmpstr) != OK)
1865 return error("unknown optimization flag '%s'", tmpstr);
1868 return error(".opt directive needs every switch enclosed inside quotation marks");
1876 // .if, Start conditional assembly
1883 IFENT * rif = f_ifent;
1887 rif = (IFENT *)malloc(sizeof(IFENT));
1889 f_ifent = rif->if_prev;
1891 rif->if_prev = ifent;
1896 if (expr(exprbuf, &eval, &eattr, &esym) != OK)
1899 if ((eattr & DEFINED) == 0)
1900 return error(undef_error);
1905 rif->if_state = (WORD)disabled;
1911 // .else, Do alternate case for .if
1915 IFENT * rif = ifent;
1917 if (rif->if_prev == NULL)
1918 return error("mismatched .else");
1921 disabled = rif->if_prev->if_state;
1925 rif->if_state = (WORD)disabled;
1931 // .endif, End of conditional assembly block
1932 // This is also called by fpop() to pop levels of IFENTs in case a macro or
1933 // include file exits early with `exitm' or `end'.
1937 IFENT * rif = ifent;
1939 if (rif->if_prev == NULL)
1940 return error("mismatched .endif");
1942 ifent = rif->if_prev;
1943 disabled = rif->if_prev->if_state;
1944 rif->if_prev = f_ifent;