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);
82 void SetLargestAlignment(int);
84 // Directive handler table
95 (void *)d_init, // 9 init
97 (void *)d_goto, // 11 goto
98 (void *)d_dc, // 12 dc
99 (void *)d_ds, // 13 ds
100 d_undmac, // 14 undefmac
103 (void *)d_dcb, // 17 dcb
107 d_incbin, // 21 .incbin //load
108 d_unimpl, // 22 disable
109 d_unimpl, // 23 enable
111 d_regbank0, // 25 .regbank0
112 d_regbank1, // 26 .regbank1
114 d_assert, // 28 assert
116 d_unimpl, // 30* endif
117 d_unimpl, // 31* endc
119 d_include, // 33 include
121 d_unimpl, // 35* macro
122 ExitMacro, // 36* exitm
123 d_unimpl, // 37* endm
127 d_phrase, // 41* endr
128 d_dphrase, // 42 struct
129 d_qphrase, // 43 ends
131 d_subttl, // 45 subttl
135 d_noclear, // 49 .noclear
136 d_equrundef, // 50 .equrundef/.regundef
137 d_ccundef, // 51 .ccundef
138 d_print, // 52 .print
139 d_cstruct, // 53 .cstruct
140 d_jpad, // 54 .jpad (deprecated)
141 d_nojpad, // 55 .nojpad (deprecated)
142 d_gpumain, // 56 .gpumain (deprecated)
143 d_prgflags, // 57 .prgflags
144 d_68020, // 58 .68020
145 d_68030, // 59 .68030
146 d_68040, // 60 .68040
147 d_68060, // 61 .68060
148 d_68881, // 62 .68881
149 d_68882, // 63 .68882
150 d_56001, // 64 .56001
157 // Set the largest alignment seen in the current section
159 void SetLargestAlignment(int size)
161 if ((scattr & TEXT) && (largestAlign[0] < size))
162 largestAlign[0] = size;
163 else if ((scattr & DATA) && (largestAlign[1] < size))
164 largestAlign[1] = size;
165 else if ((scattr & BSS) && (largestAlign[2] < size))
166 largestAlign[2] = size;
171 // .error - Abort compilation, printing an error message
173 int d_error(char *str)
176 return error("error directive encountered - aborting assembling");
182 return error(string[tok[1]]);
185 return error("error directive encountered--aborting assembly");
192 // .warn - Just display a warning on screen
194 int d_warn(char *str)
197 return warn("WARNING WARNING WARNING");
203 return warn(string[tok[1]]);
206 return warn("WARNING WARNING WARNING");
219 if (!rgpu && !rdsp && !m6502)
220 return error(".org permitted only in gpu/dsp and 6502 sections");
222 if (abs_expr(&address) == ERROR)
224 error("cannot determine org'd address");
235 // 6502. We also kludge `lsloc' so the listing generator doesn't try
236 // to spew out megabytes.
237 if (address > 0xFFFF)
238 return error(range_error);
240 if (sloc != currentorg[0])
242 currentorg[1] = sloc;
246 currentorg[0] = address;
248 lsloc = sloc = address;
249 chptr = scode->chptr + address;
264 char prntstr[LNSIZ]; // String for PRINT directive
265 char format[LNSIZ]; // Format for PRINT directive
266 int formatting = 0; // Formatting on/off
267 int wordlong = 0; // WORD = 0, LONG = 1
268 int outtype = 0; // 0:hex, 1:decimal, 2:unsigned
270 uint64_t eval; // Expression value
271 WORD eattr; // Expression attributes
272 SYM * esym; // External symbol involved in expr.
273 TOKEN r_expr[EXPRSIZE];
280 sprintf(prntstr, "%s", string[tok[1]]);
281 printf("%s", prntstr);
284 unused = write(list_fd, prntstr, (LONG)strlen(prntstr));
291 if (tok[1] != SYMBOL)
294 // strcpy(prntstr, (char *)tok[2]);
295 strcpy(prntstr, string[tok[2]]);
299 case 'l': case 'L': wordlong = 1; break;
300 case 'w': case 'W': wordlong = 0; break;
301 case 'x': case 'X': outtype = 0; break;
302 case 'd': case 'D': outtype = 1; break;
303 case 'u': case 'U': outtype = 2; break;
305 error("unknown print format flag");
315 if (expr(r_expr, &eval, &eattr, &esym) != OK)
321 case 0: strcpy(format, "%X"); break;
322 case 1: strcpy(format, "%d" ); break;
323 case 2: strcpy(format, "%u" ); break;
327 sprintf(prntstr, format, eval);
329 sprintf(prntstr, format, eval & 0xFFFF);
331 printf("%s", prntstr);
334 unused = write(list_fd, prntstr, (LONG)strlen(prntstr));
350 error("illegal print token");
356 // Undefine an equated condition code
362 // Check that we are in a RISC section
365 error(".ccundef must be defined in .gpu/.dsp section");
371 error("syntax error; expected symbol");
375 ccname = lookup(string[tok[1]], LABEL, 0);
377 // Make sure symbol is a valid ccdef
378 if (!ccname || !(ccname->sattre & EQUATEDCC))
380 error("invalid equated condition name specified");
384 ccname->sattre |= UNDEF_CC;
391 // Undefine an equated register
393 int d_equrundef(void)
397 // Check that we are in a RISC section
399 return error(".equrundef/.regundef must be defined in .gpu/.dsp section");
403 // Skip preceeding or seperating commas (if any)
407 // Check we are dealing with a symbol
409 return error("syntax error; expected symbol");
411 // Lookup and undef if equated register
412 regname = lookup(string[tok[1]], LABEL, 0);
414 if (regname && (regname->sattre & EQUATEDREG))
416 // Reset the attributes of this symbol...
418 regname->sattre &= ~(EQUATEDREG | BANK_0 | BANK_1);
419 regname->sattre |= UNDEF_EQUR;
422 // Skip over symbol token and address
431 // Do not allow use of the CLR.L opcode
435 warn("CLR.L opcode ignored...");
441 // Include binary file
447 long pos, size, bytesRead;
451 // Check to see if we're in BSS, and, if so, throw an error
454 error("cannot include binary file \"%s\" in BSS section", string[tok[1]]);
460 error("syntax error; string missing");
464 // Attempt to open the include file in the current directory, then (if that
465 // failed) try list of include files passed in the enviroment string or by
467 if ((fd = open(string[tok[1]], _OPEN_INC)) < 0)
469 for(i=0; nthpath("RMACPATH", i, buf1)!=0; i++)
473 // Append path char if necessary
474 if (fd > 0 && buf1[fd - 1] != SLASHCHAR)
475 strcat(buf1, SLASHSTRING);
477 strcat(buf1, string[tok[1]]);
479 if ((fd = open(buf1, _OPEN_INC)) >= 0)
483 return error("cannot open: \"%s\"", string[tok[1]]);
488 size = lseek(fd, 0L, SEEK_END);
489 pos = lseek(fd, 0L, SEEK_SET);
492 DEBUG { printf("INCBIN: File '%s' is %li bytes.\n", string[tok[1]], size); }
494 char * fileBuffer = (char *)malloc(size);
495 bytesRead = read(fd, fileBuffer, size);
497 if (bytesRead != size)
499 error("was only able to read %li bytes from binary file (%s, %li bytes)", bytesRead, string[tok[1]], size);
503 memcpy(chptr, fileBuffer, size);
518 // Set RISC register banks
522 // Set active register bank zero
530 // Set active register bank one
537 // Helper function, to cut down on mistakes & typing
539 static inline void SkipBytes(unsigned bytesToSkip)
544 if ((scattr & SBSS) == 0)
546 chcheck(bytesToSkip);
547 D_ZEROFILL(bytesToSkip);
554 orgaddr += bytesToSkip;
560 // Adjust location to an EVEN value
565 return error(in_6502mode);
567 unsigned skip = (rgpu || rdsp ? orgaddr : sloc) & 0x01;
571 if ((scattr & SBSS) == 0)
590 // Adjust location to a LONG value
594 unsigned lower2Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x03;
595 unsigned bytesToSkip = (0x04 - lower2Bits) & 0x03;
596 SkipBytes(bytesToSkip);
597 SetLargestAlignment(4);
604 // Adjust location to a PHRASE value
606 // N.B.: We have to handle the GPU/DSP cases separately because you can embed
607 // RISC code in the middle of a regular 68K section. Also note that all
608 // of the alignment pseudo-ops will have to be fixed this way.
610 // This *must* behave differently when in a RISC section, as following sloc
611 // (instead of orgaddr) will fuck things up royally. Note that we do it this
612 // way because you can embed RISC code in a 68K section, and have the origin
613 // pointing to a different alignment in the RISC section than the 68K section.
617 unsigned lower3Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x07;
618 unsigned bytesToSkip = (0x08 - lower3Bits) & 0x07;
619 SkipBytes(bytesToSkip);
620 SetLargestAlignment(8);
627 // Adjust location to a DPHRASE value
631 unsigned lower4Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x0F;
632 unsigned bytesToSkip = (0x10 - lower4Bits) & 0x0F;
633 SkipBytes(bytesToSkip);
634 SetLargestAlignment(16);
641 // Adjust location to a QPHRASE value
645 unsigned lower5Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x1F;
646 unsigned bytesToSkip = (0x20 - lower5Bits) & 0x1F;
647 SkipBytes(bytesToSkip);
648 SetLargestAlignment(32);
655 // Do auto-even. This must be called ONLY if 'sloc' is odd.
657 // This is made hairy because, if there was a label on the line, we also have
658 // to adjust its value. This won't work with more than one label on the line,
659 // which is OK since multiple labels are only allowed in AS68 kludge mode, and
660 // the C compiler is VERY paranoid and uses ".even" whenever it can
662 // N.B.: This probably needs the same fixes as above...
666 if (cursect != M6502)
669 sloc++; // Bump BSS section
671 D_byte(0); // Deposit 0.b in non-BSS
673 if (lab_sym != NULL) // Bump label if we have to
680 // Unimplemened directive error
684 return error("unimplemented directive");
689 // Return absolute (not TDB) and defined expression or return an error
691 int abs_expr(uint64_t * a_eval)
695 if (expr(exprbuf, a_eval, &eattr, NULL) < 0)
698 if (!(eattr & DEFINED))
699 return error(undef_error);
702 return error(rel_error);
709 // Hand symbols in a symbol-list to a function (kind of like mapcar...)
711 int symlist(int(* func)())
713 const char * em = "symbol list syntax";
720 if ((*func)(string[tok[1]]) != OK)
739 // .include "filename"
749 if (*tok == STRING) // Leave strings ALONE
751 else if (*tok == SYMBOL) // Try to append ".s" to symbols
753 strcpy(buf, string[*++tok]);
757 else // Punt if no STRING or SYMBOL
758 return error("missing filename");
760 // Make sure the user didn't try anything like:
761 // .include equates.s
763 return error("extra stuff after filename--enclose it in quotes");
765 // Attempt to open the include file in the current directory, then (if that
766 // failed) try list of include files passed in the enviroment string or by
768 if ((j = open(fn, 0)) < 0)
770 for(i=0; nthpath("RMACPATH", i, buf1)!=0; i++)
774 // Append path char if necessary
775 if (j > 0 && buf1[j - 1] != SLASHCHAR)
776 strcat(buf1, SLASHSTRING);
780 if ((j = open(buf1, 0)) >= 0)
784 return error("cannot open: \"%s\"", fn);
794 // .assert expression [, expression...]
801 for(; expr(exprbuf, &eval, &eattr, NULL)==OK; ++tok)
803 if (!(eattr & DEFINED))
804 return error("forward or undefined .assert");
807 return error("assert failure");
819 // .globl symbol [, symbol] <<<cannot make local symbols global>>>
826 return error("cannot .globl local symbol");
828 if ((sy = lookup(p, LABEL, 0)) == NULL)
830 sy = NewSymbol(p, LABEL, 0);
833 //printf("glob1: Making global symbol: attr=%04X, eattr=%08X, %s\n", sy->sattr, sy->sattre, sy->sname);
845 return error(in_6502mode);
853 // .prgflags expression
860 return error("PRGFLAGS requires value");
861 else if (abs_expr(&eval) == OK)
863 PRGFLAGS = (uint32_t)eval;
868 return error("PRGFLAGS requires value");
881 return error(in_6502mode);
887 else if (abs_expr(&eval) != OK)
891 sloc = (uint32_t)eval;
902 return error("directive forbidden in gpu/dsp mode");
904 return error(in_6502mode);
919 return error("directive forbidden in gpu/dsp mode");
921 return error(in_6502mode);
936 return error("directive forbidden in gpu/dsp mode");
938 return error(in_6502mode);
951 // .ds[.size] expression
955 DEBUG { printf("Directive: .ds.[size] = %u, sloc = $%X\n", siz, sloc); }
959 if (cursect != M6502)
961 if ((siz != SIZB) && (sloc & 1)) // Automatic .even
965 if (abs_expr(&eval) != OK)
968 // Check to see if the value being passed in is negative (who the hell does
969 // that?--nobody does; it's the code gremlins, or rum, that does it)
970 // N.B.: Since 'eval' is of type uint32_t, if it goes negative, it will have
972 if (eval & 0x80000000)
973 return error("negative sizes not allowed");
975 // In non-TDB section (BSS, ABS and M6502) just advance the location
976 // counter appropriately. In TDB sections, deposit (possibly large) chunks
977 // of zeroed memory....
978 if ((scattr & SBSS) || cursect == M6502)
980 listvalue((uint32_t)eval);
982 sloc += (uint32_t)eval;
984 if (cursect == M6502)
987 just_bss = 1; // No data deposited (8-bit CPU mode)
991 dep_block(eval, siz, 0, (WORD)(DEFINED | ABS), NULL);
1000 // dc.b, dc.w / dc, dc.l, dc.i, dc.q, dc.d
1008 if ((scattr & SBSS) != 0)
1009 return error("illegal initialization of section");
1011 // Do an auto_even if it's not BYTE sized (hmm, should we be doing this???)
1012 if (cursect != M6502 && (siz != SIZB) && (sloc & 1))
1015 // Check to see if we're trying to set LONGS on a non 32-bit aligned
1016 // address in a GPU or DSP section, in their local RAM
1017 if ((siz == SIZL) && (orgaddr & 0x03)
1018 && ((rgpu && (orgaddr >= 0xF03000) && (orgaddr <= 0xF03FFFF))
1019 || (rdsp && (orgaddr >= 0xF1B000) && (orgaddr <= 0xF1CFFFF))))
1020 warn("depositing LONGs on a non-long address in local RAM");
1024 // dc.b 'string' [,] ...
1025 if (siz == SIZB && (*tok == STRING || *tok == STRINGA8) && (tok[2] == ',' || tok[2] == EOL))
1027 uint32_t i = strlen(string[tok[1]]);
1029 if ((challoc - ch_size) < i)
1034 for(p=string[tok[1]]; *p!=EOS; p++)
1037 else if(*tok == STRINGA8)
1039 for(p=string[tok[1]]; *p!=EOS; p++)
1040 D_byte(strtoa8[*p]);
1044 error("String format not supported... yet");
1051 int movei = 0; // MOVEI flag for dc.i
1060 // dc.x <expression>
1063 if (expr(exprbuf, &eval, &eattr, &esym) != OK)
1066 uint16_t tdb = eattr & TDB;
1067 uint16_t defined = eattr & DEFINED;
1069 if ((challoc - ch_size) < 4)
1077 AddFixup(FU_BYTE | FU_SEXT, sloc, exprbuf);
1083 return error("non-absolute byte value");
1085 if (eval + 0x100 >= 0x200)
1086 return error("%s (value = $%X)", range_error, eval);
1096 AddFixup(FU_WORD | FU_SEXT, sloc, exprbuf);
1101 if (eval + 0x10000 >= 0x20000)
1102 return error(range_error);
1105 MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
1107 // Deposit 68000 or 6502 (byte-reversed) word
1108 if (cursect != M6502)
1116 // Shamus: Why can't we do longs in 6502 mode?
1118 return error(in_6502mode);
1123 AddFixup(FU_LONG | FU_MOVEI, sloc, exprbuf);
1125 AddFixup(FU_LONG, sloc, exprbuf);
1132 MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
1135 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...)
1150 // 32-bit float size
1152 return error(in_6502mode);
1156 AddFixup(FU_FLOATSING, sloc, exprbuf);
1162 MarkRelocatable(cursect, sloc, tdb, MSINGLE, NULL);
1166 uint32_t ieee754 = FloatToIEEE754((float)*ptr.dp);
1172 // 64-bit double size
1174 return error(in_6502mode);
1178 AddFixup(FU_FLOATDOUB, sloc, exprbuf);
1184 MarkRelocatable(cursect, sloc, tdb, MDOUBLE, NULL);
1188 uint64_t ieee754 = DoubleToIEEE754(*ptr.dp);
1195 return error(in_6502mode);
1198 memset(extDbl, 0, 12);
1202 AddFixup(FU_FLOATEXT, sloc, exprbuf);
1208 MarkRelocatable(cursect, sloc, tdb, MEXTEND, NULL);
1212 DoubleToExtended(*ptr.dp, extDbl);
1230 // dcb[.siz] expr1,expr2 - Make 'expr1' copies of 'expr2'
1234 uint64_t evalc, eval;
1237 DEBUG { printf("dcb: section is %s%s%s (scattr=$%X)\n", (cursect & TEXT ? "TEXT" : ""), (cursect & DATA ? " DATA" : ""), (cursect & BSS ? "BSS" : ""), scattr); }
1239 if ((scattr & SBSS) != 0)
1240 return error("illegal initialization of section");
1242 if (abs_expr(&evalc) != OK)
1246 return error("missing comma");
1248 if (expr(exprbuf, &eval, &eattr, NULL) < 0)
1251 if (cursect != M6502 && (siz != SIZB) && (sloc & 1))
1254 dep_block((uint32_t)evalc, siz, (uint32_t)eval, eattr, exprbuf);
1260 // Generalized initialization directive
1262 // .init[.siz] [#count,] expression [.size] , ...
1264 // The size suffix on the ".init" directive becomes the default size of the
1265 // objects to deposit. If an item is preceeded with a sharp (immediate) sign
1266 // and an expression, it specifies a repeat count. The value to be deposited
1267 // may be followed by a size suffix, which overrides the default size.
1269 int d_init(WORD def_siz)
1276 if ((scattr & SBSS) != 0)
1277 return error(".init not permitted in BSS or ABS");
1280 return error("directive forbidden in gpu/dsp mode");
1284 // Get repeat count (defaults to 1)
1289 if (abs_expr(&count) != OK)
1293 return error(comma_error);
1298 // Evaluate expression to deposit
1299 if (expr(exprbuf, &eval, &eattr, NULL) < 0)
1303 { // Determine size of object to deposit
1304 case DOTB: siz = SIZB; break;
1305 case DOTW: siz = SIZB; break;
1306 case DOTL: siz = SIZL; break;
1313 dep_block((uint32_t)count, siz, (uint32_t)eval, eattr, exprbuf);
1323 return error(comma_error);
1330 // Deposit 'count' values of size 'siz' in the current (non-BSS) segment
1332 int dep_block(uint32_t count, WORD siz, uint32_t eval, WORD eattr, TOKEN * exprbuf)
1337 tdb = (WORD)(eattr & TDB);
1338 defined = (WORD)(eattr & DEFINED);
1342 if ((challoc - ch_size) < 4)
1350 AddFixup(FU_BYTE | FU_SEXT, sloc, exprbuf);
1356 return error("non-absolute byte value");
1358 if (eval + 0x100 >= 0x200)
1359 return error(range_error);
1369 AddFixup(FU_WORD | FU_SEXT, sloc, exprbuf);
1375 MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
1377 if (eval + 0x10000 >= 0x20000)
1378 return error(range_error);
1380 // Deposit 68000 or 6502 (byte-reversed) word
1381 if (cursect != M6502)
1391 return error(in_6502mode);
1395 AddFixup(FU_LONG, sloc, exprbuf);
1401 MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
1415 // .comm symbol, size
1424 return error(in_6502mode);
1427 return error("missing symbol");
1432 if (*p == '.') // Cannot .comm a local symbol
1433 return error(locgl_error);
1435 if ((sym = lookup(p, LABEL, 0)) == NULL)
1436 sym = NewSymbol(p, LABEL, 0);
1439 if (sym->sattr & DEFINED)
1440 return error(".comm symbol already defined");
1443 sym->sattr = GLOBAL | COMMON | BSS;
1446 return error(comma_error);
1448 if (abs_expr(&eval) != OK) // Parse size of common region
1451 sym->svalue = eval; // Install common symbol's size
1458 // .list - Turn listing on
1470 // .nlist - Turn listing off
1482 // .68000 - Back to 68000 TEXT segment
1487 // Switching from gpu/dsp sections should reset any ORG'd Address
1491 SwitchSection(TEXT);
1492 activecpu = CPU_68000;
1498 // .68020 - Back to 68000 TEXT segment and select 68020
1503 activecpu = CPU_68020;
1509 // .68030 - Back to 68000 TEXT segment and select 68030
1514 activecpu = CPU_68030;
1520 // .68040 - Back to 68000 TEXT segment and select 68040
1525 activecpu = CPU_68040;
1526 activefpu = FPU_68040;
1532 // .68060 - Back to 68000 TEXT segment and select 68060
1537 activecpu = CPU_68060;
1538 activefpu = FPU_68060;
1544 // .68881 - Back to 680x0 TEXT segment and select 68881 FPU
1549 activefpu = FPU_68881;
1555 // .68882 - Back to 680x0 TEXT segment and select 68882 FPU
1560 activefpu = FPU_68882;
1566 // nofpu - Deselect FPUs.
1570 activefpu = FPU_NONE;
1580 return error("Not yet, child. Be patient.");
1585 // .gpu - Switch to GPU assembler
1589 if ((cursect != TEXT) && (cursect != DATA))
1591 error(".gpu can only be used in the TEXT or DATA segments");
1595 // If previous section was DSP or 68000 then we need to reset ORG'd Addresses
1602 rgpu = 1; // Set GPU assembly
1603 rdsp = 0; // Unset DSP assembly
1604 regbank = BANK_N; // Set no default register bank
1610 // .dsp - Switch to DSP assembler
1614 if ((cursect != TEXT) && (cursect != DATA))
1616 error(".dsp can only be used in the TEXT or DATA segments");
1620 // If previous section was gpu or 68000 then we need to reset ORG'd Addresses
1627 rdsp = 1; // Set DSP assembly
1628 rgpu = 0; // Unset GPU assembly
1629 regbank = BANK_N; // Set no default register bank
1635 // .cargs [#offset], symbol[.size], ...
1637 // Lists of registers may also be mentioned; they just take up space. Good for
1638 // "documentation" purposes:
1640 // .cargs a6, .arg1, .arg2, .arg3...
1642 // Symbols thus created are ABS and EQUATED.
1646 uint64_t eval = 4; // Default to 4 if no offset specified (to account for
1655 return error("directive forbidden in gpu/dsp mode");
1661 if (abs_expr(&eval) != OK)
1664 // Eat the comma, if it's there
1675 // Set env to either local (dot prefixed) or global scope
1676 env = (*p == '.' ? curenv : 0);
1677 symbol = lookup(p, LABEL, env);
1681 symbol = NewSymbol(p, LABEL, env);
1684 else if (symbol->sattr & DEFINED)
1685 return error("multiply-defined label '%s'", p);
1687 // Put symbol in "order of definition" list
1688 AddToSymbolDeclarationList(symbol);
1690 symbol->sattr |= (ABS | DEFINED | EQUATED);
1691 symbol->svalue = eval;
1694 // What this does is eat any dot suffixes attached to a symbol. If
1695 // it's a .L, it adds 4 to eval; if it's .W or .B, it adds 2. If
1696 // there is no dot suffix, it assumes a size of 2.
1708 else if (*tok >= KW_D0 && *tok <= KW_A7)
1710 if (reglist(&rlist) < 0)
1713 for(i=0; i<16; i++, rlist>>=1)
1736 return error(".cargs syntax");
1740 // Eat commas in between each argument, if they exist
1748 // .cstruct [#offset], symbol[.size], ...
1750 // Lists of registers may also be mentioned; they just take up space. Good for
1751 // "documentation" purposes:
1753 // .cstruct a6, .arg1, .arg2, .arg3...
1755 // Symbols thus created are ABS and EQUATED. Note that this is for
1756 // compatibility with VBCC and the Remover's library. Thanks to GroovyBee for
1761 uint64_t eval = 0; // Default, if no offset specified, is zero
1769 return error("directive forbidden in gpu/dsp mode");
1775 if (abs_expr(&eval) != OK)
1778 // Eat the comma, if it's there
1787 symbolName = string[tok[1]];
1789 // Set env to either local (dot prefixed) or global scope
1790 env = (symbolName[0] == '.' ? curenv : 0);
1791 symbol = lookup(symbolName, LABEL, env);
1793 // If the symbol wasn't found, then define it. Otherwise, throw an
1797 symbol = NewSymbol(symbolName, LABEL, env);
1800 else if (symbol->sattr & DEFINED)
1801 return error("multiply-defined label '%s'", symbolName);
1803 // Put symbol in "order of definition" list
1804 AddToSymbolDeclarationList(symbol);
1808 // Adjust label start address if it's a word or a long, as a byte
1809 // label might have left us on an odd address.
1814 eval += eval & 0x01;
1817 symbol->sattr |= (ABS | DEFINED | EQUATED);
1818 symbol->svalue = eval;
1820 // Check for dot suffixes and adjust space accordingly (longs and
1821 // words on an odd boundary get bumped to the next word aligned
1822 // address). If no suffix, then throw an error.
1835 return error("Symbol missing dot suffix in .cstruct construct");
1840 else if (*tok >= KW_D0 && *tok <= KW_A7)
1842 if (reglist(&rlist) < 0)
1845 for(i=0; i<16; i++, rlist>>=1)
1868 return error(".cstruct syntax");
1872 // Eat commas in between each argument, if they exist
1880 // Undefine a macro - .undefmac macname [, macname...]
1882 int undmac1(char * p)
1884 SYM * symbol = lookup(p, MACRO, 0);
1886 // If the macro symbol exists, cause it to disappear
1888 symbol->stype = (BYTE)SY_UNDEF;
1903 warn("JPAD directive is deprecated/non-functional");
1910 warn("NOJPAD directive is deprecated/non-functional");
1917 return error("What the hell? Do you think we adhere to the Goof standard?");
1922 // .opt - turn a specific (or all) optimisation on or off
1931 char * tmpstr = string[*tok++];
1933 if (ParseOptimization(tmpstr) != OK)
1934 return error("unknown optimization flag '%s'", tmpstr);
1937 return error(".opt directive needs every switch enclosed inside quotation marks");
1945 // .if, Start conditional assembly
1952 IFENT * rif = f_ifent;
1956 rif = (IFENT *)malloc(sizeof(IFENT));
1958 f_ifent = rif->if_prev;
1960 rif->if_prev = ifent;
1965 if (expr(exprbuf, &eval, &eattr, &esym) != OK)
1968 if ((eattr & DEFINED) == 0)
1969 return error(undef_error);
1974 rif->if_state = (WORD)disabled;
1980 // .else, Do alternate case for .if
1984 IFENT * rif = ifent;
1986 if (rif->if_prev == NULL)
1987 return error("mismatched .else");
1990 disabled = rif->if_prev->if_state;
1994 rif->if_state = (WORD)disabled;
2000 // .endif, End of conditional assembly block
2001 // This is also called by fpop() to pop levels of IFENTs in case a macro or
2002 // include file exits early with `exitm' or `end'.
2006 IFENT * rif = ifent;
2008 if (rif->if_prev == NULL)
2009 return error("mismatched .endif");
2011 ifent = rif->if_prev;
2012 disabled = rif->if_prev->if_state;
2013 rif->if_prev = f_ifent;