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
30 TOKEN exprbuf[128]; // Expression buffer
31 SYM * symbolPtr[1000000]; // Symbol pointers table
32 static long unused; // For supressing 'write' warnings
33 char buffer[256]; // Scratch buffer for messages
34 int largestAlign[3] = { 2, 2, 2 }; // Largest alignment value seen per section
36 // Function prototypes
73 int d_equrundef(void);
84 void SetLargestAlignment(int);
86 // Directive handler table
97 (void *)d_init, // 9 init
99 (void *)d_goto, // 11 goto
100 (void *)d_dc, // 12 dc
101 (void *)d_ds, // 13 ds
102 d_undmac, // 14 undefmac
105 (void *)d_dcb, // 17 dcb
109 d_incbin, // 21 .incbin //load
110 d_unimpl, // 22 disable
111 d_unimpl, // 23 enable
113 d_regbank0, // 25 .regbank0
114 d_regbank1, // 26 .regbank1
116 d_assert, // 28 assert
118 d_unimpl, // 30* endif
119 d_unimpl, // 31* endc
121 d_include, // 33 include
123 d_unimpl, // 35* macro
124 ExitMacro, // 36* exitm
125 d_unimpl, // 37* endm
129 d_phrase, // 41* endr
130 d_dphrase, // 42 struct
131 d_qphrase, // 43 ends
133 d_subttl, // 45 subttl
137 d_noclear, // 49 .noclear
138 d_equrundef, // 50 .equrundef/.regundef
139 d_ccundef, // 51 .ccundef
140 d_print, // 52 .print
141 d_cstruct, // 53 .cstruct
142 d_jpad, // 54 .jpad (deprecated)
143 d_nojpad, // 55 .nojpad (deprecated)
144 d_gpumain, // 56 .gpumain (deprecated)
145 d_prgflags, // 57 .prgflags
146 d_68020, // 58 .68020
147 d_68030, // 59 .68030
148 d_68040, // 60 .68040
149 d_68060, // 61 .68060
150 d_68881, // 62 .68881
151 d_68882, // 63 .68882
152 d_56001, // 64 .56001
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 && !m6502)
222 return error(".org permitted only in gpu/dsp and 6502 sections");
224 if (abs_expr(&address) == ERROR)
226 error("cannot determine org'd address");
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; string 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;
1071 if ((challoc - ch_size) < 4)
1079 AddFixup(FU_BYTE | FU_SEXT, sloc, exprbuf);
1085 return error("non-absolute byte value");
1087 if (eval + 0x100 >= 0x200)
1088 return error("%s (value = $%X)", range_error, eval);
1098 AddFixup(FU_WORD | FU_SEXT, sloc, exprbuf);
1103 if (eval + 0x10000 >= 0x20000)
1104 return error(range_error);
1107 MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
1109 // Deposit 68000 or 6502 (byte-reversed) word
1110 if (cursect != M6502)
1118 // Shamus: Why can't we do longs in 6502 mode?
1120 return error(in_6502mode);
1125 AddFixup(FU_LONG | FU_MOVEI, sloc, exprbuf);
1127 AddFixup(FU_LONG, sloc, exprbuf);
1134 MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
1137 eval = WORDSWAP32(eval);
1145 return error(in_6502mode);
1147 // Shamus: We only handle DC.Q type stuff, will have to add fixups
1148 // and stuff later (maybe... might not be needed...)
1153 return error(in_6502mode);
1158 AddFixup(FU_FLOATSING, sloc, exprbuf);
1165 MarkRelocatable(cursect, sloc, tdb, MSINGLE, NULL);
1173 return error(in_6502mode);
1178 AddFixup(FU_FLOATDOUB, sloc, exprbuf);
1185 MarkRelocatable(cursect, sloc, tdb, MDOUBLE, NULL);
1187 double vv = *(double *)&eval;
1194 return error(in_6502mode);
1199 AddFixup(FU_FLOATEXT, sloc, exprbuf);
1206 MarkRelocatable(cursect, sloc, tdb, MEXTEND, NULL);
1208 float vv = *(double *)&eval;
1226 // dcb[.siz] expr1,expr2 - Make 'expr1' copies of 'expr2'
1230 uint64_t evalc, eval;
1233 DEBUG { printf("dcb: section is %s%s%s (scattr=$%X)\n", (cursect & TEXT ? "TEXT" : ""), (cursect & DATA ? " DATA" : ""), (cursect & BSS ? "BSS" : ""), scattr); }
1235 if ((scattr & SBSS) != 0)
1236 return error("illegal initialization of section");
1238 if (abs_expr(&evalc) != OK)
1242 return error("missing comma");
1244 if (expr(exprbuf, &eval, &eattr, NULL) < 0)
1247 if (cursect != M6502 && (siz != SIZB) && (sloc & 1))
1250 dep_block((uint32_t)evalc, siz, (uint32_t)eval, eattr, exprbuf);
1256 // Generalized initialization directive
1258 // .init[.siz] [#count,] expression [.size] , ...
1260 // The size suffix on the ".init" directive becomes the default size of the
1261 // objects to deposit. If an item is preceeded with a sharp (immediate) sign
1262 // and an expression, it specifies a repeat count. The value to be deposited
1263 // may be followed by a size suffix, which overrides the default size.
1265 int d_init(WORD def_siz)
1272 if ((scattr & SBSS) != 0)
1273 return error(".init not permitted in BSS or ABS");
1276 return error("directive forbidden in gpu/dsp mode");
1280 // Get repeat count (defaults to 1)
1285 if (abs_expr(&count) != OK)
1289 return error(comma_error);
1294 // Evaluate expression to deposit
1295 if (expr(exprbuf, &eval, &eattr, NULL) < 0)
1299 { // Determine size of object to deposit
1300 case DOTB: siz = SIZB; break;
1301 case DOTW: siz = SIZB; break;
1302 case DOTL: siz = SIZL; break;
1309 dep_block((uint32_t)count, siz, (uint32_t)eval, eattr, exprbuf);
1319 return error(comma_error);
1326 // Deposit 'count' values of size 'siz' in the current (non-BSS) segment
1328 int dep_block(uint32_t count, WORD siz, uint32_t eval, WORD eattr, TOKEN * exprbuf)
1333 tdb = (WORD)(eattr & TDB);
1334 defined = (WORD)(eattr & DEFINED);
1338 if ((challoc - ch_size) < 4)
1346 AddFixup(FU_BYTE | FU_SEXT, sloc, exprbuf);
1352 return error("non-absolute byte value");
1354 if (eval + 0x100 >= 0x200)
1355 return error(range_error);
1365 AddFixup(FU_WORD | FU_SEXT, sloc, exprbuf);
1371 MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
1373 if (eval + 0x10000 >= 0x20000)
1374 return error(range_error);
1376 // Deposit 68000 or 6502 (byte-reversed) word
1377 if (cursect != M6502)
1387 return error(in_6502mode);
1391 AddFixup(FU_LONG, sloc, exprbuf);
1397 MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
1411 // .comm symbol, size
1420 return error(in_6502mode);
1423 return error("missing symbol");
1428 if (*p == '.') // Cannot .comm a local symbol
1429 return error(locgl_error);
1431 if ((sym = lookup(p, LABEL, 0)) == NULL)
1432 sym = NewSymbol(p, LABEL, 0);
1435 if (sym->sattr & DEFINED)
1436 return error(".comm symbol already defined");
1439 sym->sattr = GLOBAL | COMMON | BSS;
1442 return error(comma_error);
1444 if (abs_expr(&eval) != OK) // Parse size of common region
1447 sym->svalue = (uint32_t)eval; // Install common symbol's size
1454 // .list - Turn listing on
1466 // .nlist - Turn listing off
1478 // .68000 - Back to 68000 TEXT segment
1483 // Switching from gpu/dsp sections should reset any ORG'd Address
1487 SwitchSection(TEXT);
1488 activecpu = CPU_68000;
1494 // .68020 - Back to 68000 TEXT segment and select 68020
1499 activecpu = CPU_68020;
1505 // .68030 - Back to 68000 TEXT segment and select 68030
1510 activecpu = CPU_68030;
1516 // .68040 - Back to 68000 TEXT segment and select 68040
1521 activecpu = CPU_68040;
1522 activefpu = FPU_68040;
1528 // .68060 - Back to 68000 TEXT segment and select 68060
1533 activecpu = CPU_68060;
1534 activefpu = FPU_68040;
1540 // .68881 - Back to 68000 TEXT segment and select 68881 FPU
1545 activefpu = FPU_68881;
1551 // .68882 - Back to 68000 TEXT segment and select 68882 FPU
1556 activefpu = FPU_68881;
1562 // nofpu - Deselect FPUs.
1566 activefpu = FPU_NONE;
1576 return error("Not yet, child. Be patient.");
1581 // .gpu - Switch to GPU assembler
1585 if ((cursect != TEXT) && (cursect != DATA))
1587 error(".gpu can only be used in the TEXT or DATA segments");
1591 // If previous section was DSP or 68000 then we need to reset ORG'd Addresses
1598 rgpu = 1; // Set GPU assembly
1599 rdsp = 0; // Unset DSP assembly
1600 regbank = BANK_N; // Set no default register bank
1606 // .dsp - Switch to DSP assembler
1610 if ((cursect != TEXT) && (cursect != DATA))
1612 error(".dsp can only be used in the TEXT or DATA segments");
1616 // If previous section was gpu or 68000 then we need to reset ORG'd Addresses
1623 rdsp = 1; // Set DSP assembly
1624 rgpu = 0; // Unset GPU assembly
1625 regbank = BANK_N; // Set no default register bank
1631 // .cargs [#offset], symbol[.size], ...
1633 // Lists of registers may also be mentioned; they just take up space. Good for
1634 // "documentation" purposes:
1636 // .cargs a6, .arg1, .arg2, .arg3...
1638 // Symbols thus created are ABS and EQUATED.
1642 uint64_t eval = 4; // Default to 4 if no offset specified (to account for
1651 return error("directive forbidden in gpu/dsp mode");
1657 if (abs_expr(&eval) != OK)
1660 // Eat the comma, if it's there
1671 // Set env to either local (dot prefixed) or global scope
1672 env = (*p == '.' ? curenv : 0);
1673 symbol = lookup(p, LABEL, env);
1677 symbol = NewSymbol(p, LABEL, env);
1680 else if (symbol->sattr & DEFINED)
1681 return error("multiply-defined label '%s'", p);
1683 // Put symbol in "order of definition" list
1684 AddToSymbolDeclarationList(symbol);
1686 symbol->sattr |= (ABS | DEFINED | EQUATED);
1687 symbol->svalue = (uint32_t)eval;
1690 // What this does is eat any dot suffixes attached to a symbol. If
1691 // it's a .L, it adds 4 to eval; if it's .W or .B, it adds 2. If
1692 // there is no dot suffix, it assumes a size of 2.
1704 else if (*tok >= KW_D0 && *tok <= KW_A7)
1706 if (reglist(&rlist) < 0)
1709 for(i=0; i<16; i++, rlist>>=1)
1732 return error(".cargs syntax");
1736 // Eat commas in between each argument, if they exist
1744 // .cstruct [#offset], symbol[.size], ...
1746 // Lists of registers may also be mentioned; they just take up space. Good for
1747 // "documentation" purposes:
1749 // .cstruct a6, .arg1, .arg2, .arg3...
1751 // Symbols thus created are ABS and EQUATED. Note that this is for
1752 // compatibility with VBCC and the Remover's library. Thanks to GroovyBee for
1757 uint64_t eval = 0; // Default, if no offset specified, is zero
1765 return error("directive forbidden in gpu/dsp mode");
1771 if (abs_expr(&eval) != OK)
1774 // Eat the comma, if it's there
1783 symbolName = string[tok[1]];
1785 // Set env to either local (dot prefixed) or global scope
1786 env = (symbolName[0] == '.' ? curenv : 0);
1787 symbol = lookup(symbolName, LABEL, env);
1789 // If the symbol wasn't found, then define it. Otherwise, throw an
1793 symbol = NewSymbol(symbolName, LABEL, env);
1796 else if (symbol->sattr & DEFINED)
1797 return error("multiply-defined label '%s'", symbolName);
1799 // Put symbol in "order of definition" list
1800 AddToSymbolDeclarationList(symbol);
1804 // Adjust label start address if it's a word or a long, as a byte
1805 // label might have left us on an odd address.
1810 eval += eval & 0x01;
1813 symbol->sattr |= (ABS | DEFINED | EQUATED);
1814 symbol->svalue = (uint32_t)eval;
1816 // Check for dot suffixes and adjust space accordingly (longs and
1817 // words on an odd boundary get bumped to the next word aligned
1818 // address). If no suffix, then throw an error.
1831 return error("Symbol missing dot suffix in .cstruct construct");
1836 else if (*tok >= KW_D0 && *tok <= KW_A7)
1838 if (reglist(&rlist) < 0)
1841 for(i=0; i<16; i++, rlist>>=1)
1864 return error(".cstruct syntax");
1868 // Eat commas in between each argument, if they exist
1876 // Undefine a macro - .undefmac macname [, macname...]
1878 int undmac1(char * p)
1880 SYM * symbol = lookup(p, MACRO, 0);
1882 // If the macro symbol exists, cause it to disappear
1884 symbol->stype = (BYTE)SY_UNDEF;
1899 warn("JPAD directive is deprecated/non-functional");
1906 warn("NOJPAD directive is deprecated/non-functional");
1913 return error("What the hell? Do you think we adhere to the Goof standard?");
1918 // .opt - turn a specific (or all) optimisation on or off
1927 char * tmpstr = string[*tok++];
1929 if (ParseOptimization(tmpstr) != OK)
1930 return error("unknown optimization flag '%s'", tmpstr);
1933 return error(".opt directive needs every switch enclosed inside quotation marks");
1941 // .if, Start conditional assembly
1948 IFENT * rif = f_ifent;
1952 rif = (IFENT *)malloc(sizeof(IFENT));
1954 f_ifent = rif->if_prev;
1956 rif->if_prev = ifent;
1961 if (expr(exprbuf, &eval, &eattr, &esym) != OK)
1964 if ((eattr & DEFINED) == 0)
1965 return error(undef_error);
1970 rif->if_state = (WORD)disabled;
1976 // .else, Do alternate case for .if
1980 IFENT * rif = ifent;
1982 if (rif->if_prev == NULL)
1983 return error("mismatched .else");
1986 disabled = rif->if_prev->if_state;
1990 rif->if_state = (WORD)disabled;
1996 // .endif, End of conditional assembly block
1997 // This is also called by fpop() to pop levels of IFENTs in case a macro or
1998 // include file exits early with `exitm' or `end'.
2002 IFENT * rif = ifent;
2004 if (rif->if_prev == NULL)
2005 return error("mismatched .endif");
2007 ifent = rif->if_prev;
2008 disabled = rif->if_prev->if_state;
2009 rif->if_prev = f_ifent;