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
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
72 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
158 // Set the largest alignment seen in the current section
160 void SetLargestAlignment(int size)
162 if ((scattr & TEXT) && (largestAlign[0] < size))
163 largestAlign[0] = size;
164 else if ((scattr & DATA) && (largestAlign[1] < size))
165 largestAlign[1] = size;
166 else if ((scattr & BSS) && (largestAlign[2] < size))
167 largestAlign[2] = size;
172 // .error - Abort compilation, printing an error message
174 int d_error(char *str)
177 return error("error directive encountered - aborting assembling");
183 return error(string[tok[1]]);
186 return error("error directive encountered--aborting assembly");
193 // .warn - Just display a warning on screen
195 int d_warn(char *str)
198 return warn("WARNING WARNING WARNING");
204 return warn(string[tok[1]]);
207 return warn("WARNING WARNING WARNING");
220 if (!rgpu && !rdsp && !m6502)
221 return error(".org permitted only in gpu/dsp and 6502 sections");
223 if (abs_expr(&address) == ERROR)
225 error("cannot determine org'd address");
236 // 6502. We also kludge `lsloc' so the listing generator doesn't try
237 // to spew out megabytes.
238 if (address > 0xFFFF)
239 return error(range_error);
241 if (sloc != currentorg[0])
243 currentorg[1] = sloc;
247 currentorg[0] = address;
249 lsloc = sloc = address;
250 chptr = scode->chptr + address;
265 char prntstr[LNSIZ]; // String for PRINT directive
266 char format[LNSIZ]; // Format for PRINT directive
267 int formatting = 0; // Formatting on/off
268 int wordlong = 0; // WORD = 0, LONG = 1
269 int outtype = 0; // 0:hex, 1:decimal, 2:unsigned
271 uint64_t eval; // Expression value
272 WORD eattr; // Expression attributes
273 SYM * esym; // External symbol involved in expr.
274 TOKEN r_expr[EXPRSIZE];
281 sprintf(prntstr, "%s", string[tok[1]]);
282 printf("%s", prntstr);
285 unused = write(list_fd, prntstr, (LONG)strlen(prntstr));
292 if (tok[1] != SYMBOL)
295 // strcpy(prntstr, (char *)tok[2]);
296 strcpy(prntstr, string[tok[2]]);
300 case 'l': case 'L': wordlong = 1; break;
301 case 'w': case 'W': wordlong = 0; break;
302 case 'x': case 'X': outtype = 0; break;
303 case 'd': case 'D': outtype = 1; break;
304 case 'u': case 'U': outtype = 2; break;
306 error("unknown print format flag");
316 if (expr(r_expr, &eval, &eattr, &esym) != OK)
322 case 0: strcpy(format, "%X"); break;
323 case 1: strcpy(format, "%d" ); break;
324 case 2: strcpy(format, "%u" ); break;
328 sprintf(prntstr, format, eval);
330 sprintf(prntstr, format, eval & 0xFFFF);
332 printf("%s", prntstr);
335 unused = write(list_fd, prntstr, (LONG)strlen(prntstr));
351 error("illegal print token");
357 // Undefine an equated condition code
363 // Check that we are in a RISC section
366 error(".ccundef must be defined in .gpu/.dsp section");
372 error("syntax error; expected symbol");
376 ccname = lookup(string[tok[1]], LABEL, 0);
378 // Make sure symbol is a valid ccdef
379 if (!ccname || !(ccname->sattre & EQUATEDCC))
381 error("invalid equated condition name specified");
385 ccname->sattre |= UNDEF_CC;
392 // Undefine an equated register
394 int d_equrundef(void)
398 // Check that we are in a RISC section
400 return error(".equrundef/.regundef must be defined in .gpu/.dsp section");
404 // Skip preceeding or seperating commas (if any)
408 // Check we are dealing with a symbol
410 return error("syntax error; expected symbol");
412 // Lookup and undef if equated register
413 regname = lookup(string[tok[1]], LABEL, 0);
415 if (regname && (regname->sattre & EQUATEDREG))
417 // Reset the attributes of this symbol...
419 regname->sattre &= ~(EQUATEDREG | BANK_0 | BANK_1);
420 regname->sattre |= UNDEF_EQUR;
423 // Skip over symbol token and address
432 // Do not allow use of the CLR.L opcode
436 warn("CLR.L opcode ignored...");
442 // Include binary file
448 long pos, size, bytesRead;
452 // Check to see if we're in BSS, and, if so, throw an error
455 error("cannot include binary file \"%s\" in BSS section", string[tok[1]]);
461 error("syntax error; string missing");
465 // Attempt to open the include file in the current directory, then (if that
466 // failed) try list of include files passed in the enviroment string or by
468 if ((fd = open(string[tok[1]], _OPEN_INC)) < 0)
470 for(i=0; nthpath("RMACPATH", i, buf1)!=0; i++)
474 // Append path char if necessary
475 if (fd > 0 && buf1[fd - 1] != SLASHCHAR)
476 strcat(buf1, SLASHSTRING);
478 strcat(buf1, string[tok[1]]);
480 if ((fd = open(buf1, _OPEN_INC)) >= 0)
484 return error("cannot open: \"%s\"", string[tok[1]]);
489 size = lseek(fd, 0L, SEEK_END);
490 pos = lseek(fd, 0L, SEEK_SET);
493 DEBUG { printf("INCBIN: File '%s' is %li bytes.\n", string[tok[1]], size); }
495 char * fileBuffer = (char *)malloc(size);
496 bytesRead = read(fd, fileBuffer, size);
498 if (bytesRead != size)
500 error("was only able to read %li bytes from binary file (%s, %li bytes)", bytesRead, string[tok[1]], size);
504 memcpy(chptr, fileBuffer, size);
519 // Set RISC register banks
523 // Set active register bank zero
531 // Set active register bank one
538 // Helper function, to cut down on mistakes & typing
540 static inline void SkipBytes(unsigned bytesToSkip)
545 if ((scattr & SBSS) == 0)
547 chcheck(bytesToSkip);
548 D_ZEROFILL(bytesToSkip);
555 orgaddr += bytesToSkip;
561 // Adjust location to an EVEN value
566 return error(in_6502mode);
568 unsigned skip = (rgpu || rdsp ? orgaddr : sloc) & 0x01;
572 if ((scattr & SBSS) == 0)
591 // Adjust location to a LONG value
595 unsigned lower2Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x03;
596 unsigned bytesToSkip = (0x04 - lower2Bits) & 0x03;
597 SkipBytes(bytesToSkip);
598 SetLargestAlignment(4);
605 // Adjust location to a PHRASE value
607 // N.B.: We have to handle the GPU/DSP cases separately because you can embed
608 // RISC code in the middle of a regular 68K section. Also note that all
609 // of the alignment pseudo-ops will have to be fixed this way.
611 // This *must* behave differently when in a RISC section, as following sloc
612 // (instead of orgaddr) will fuck things up royally. Note that we do it this
613 // way because you can embed RISC code in a 68K section, and have the origin
614 // pointing to a different alignment in the RISC section than the 68K section.
618 unsigned lower3Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x07;
619 unsigned bytesToSkip = (0x08 - lower3Bits) & 0x07;
620 SkipBytes(bytesToSkip);
621 SetLargestAlignment(8);
628 // Adjust location to a DPHRASE value
632 unsigned lower4Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x0F;
633 unsigned bytesToSkip = (0x10 - lower4Bits) & 0x0F;
634 SkipBytes(bytesToSkip);
635 SetLargestAlignment(16);
642 // Adjust location to a QPHRASE value
646 unsigned lower5Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x1F;
647 unsigned bytesToSkip = (0x20 - lower5Bits) & 0x1F;
648 SkipBytes(bytesToSkip);
649 SetLargestAlignment(32);
656 // Do auto-even. This must be called ONLY if 'sloc' is odd.
658 // This is made hairy because, if there was a label on the line, we also have
659 // to adjust its value. This won't work with more than one label on the line,
660 // which is OK since multiple labels are only allowed in AS68 kludge mode, and
661 // the C compiler is VERY paranoid and uses ".even" whenever it can
663 // N.B.: This probably needs the same fixes as above...
667 if (cursect != M6502)
670 sloc++; // Bump BSS section
672 D_byte(0); // Deposit 0.b in non-BSS
674 if (lab_sym != NULL) // Bump label if we have to
681 // Unimplemened directive error
685 return error("unimplemented directive");
690 // Return absolute (not TDB) and defined expression or return an error
692 int abs_expr(uint64_t * a_eval)
696 if (expr(exprbuf, a_eval, &eattr, NULL) < 0)
699 if (!(eattr & DEFINED))
700 return error(undef_error);
703 return error(rel_error);
710 // Hand symbols in a symbol-list to a function (kind of like mapcar...)
712 int symlist(int(* func)())
714 const char * em = "symbol list syntax";
721 if ((*func)(string[tok[1]]) != OK)
740 // .include "filename"
750 if (*tok == STRING) // Leave strings ALONE
752 else if (*tok == SYMBOL) // Try to append ".s" to symbols
754 strcpy(buf, string[*++tok]);
758 else // Punt if no STRING or SYMBOL
759 return error("missing filename");
761 // Make sure the user didn't try anything like:
762 // .include equates.s
764 return error("extra stuff after filename--enclose it in quotes");
766 // Attempt to open the include file in the current directory, then (if that
767 // failed) try list of include files passed in the enviroment string or by
769 if ((j = open(fn, 0)) < 0)
771 for(i=0; nthpath("RMACPATH", i, buf1)!=0; i++)
775 // Append path char if necessary
776 if (j > 0 && buf1[j - 1] != SLASHCHAR)
777 strcat(buf1, SLASHSTRING);
781 if ((j = open(buf1, 0)) >= 0)
785 return error("cannot open: \"%s\"", fn);
795 // .assert expression [, expression...]
802 for(; expr(exprbuf, &eval, &eattr, NULL)==OK; ++tok)
804 if (!(eattr & DEFINED))
805 return error("forward or undefined .assert");
808 return error("assert failure");
820 // .globl symbol [, symbol] <<<cannot make local symbols global>>>
827 return error("cannot .globl local symbol");
829 if ((sy = lookup(p, LABEL, 0)) == NULL)
831 sy = NewSymbol(p, LABEL, 0);
834 //printf("glob1: Making global symbol: attr=%04X, eattr=%08X, %s\n", sy->sattr, sy->sattre, sy->sname);
846 return error(in_6502mode);
854 // .prgflags expression
861 return error("PRGFLAGS requires value");
862 else if (abs_expr(&eval) == OK)
864 PRGFLAGS = (uint32_t)eval;
869 return error("PRGFLAGS requires value");
882 return error(in_6502mode);
888 else if (abs_expr(&eval) != OK)
892 sloc = (uint32_t)eval;
903 return error("directive forbidden in gpu/dsp mode");
905 return error(in_6502mode);
920 return error("directive forbidden in gpu/dsp mode");
922 return error(in_6502mode);
937 return error("directive forbidden in gpu/dsp mode");
939 return error(in_6502mode);
952 // .ds[.size] expression
956 DEBUG { printf("Directive: .ds.[size] = %u, sloc = $%X\n", siz, sloc); }
960 if (cursect != M6502)
962 if ((siz != SIZB) && (sloc & 1)) // Automatic .even
966 if (abs_expr(&eval) != OK)
969 // Check to see if the value being passed in is negative (who the hell does
970 // that?--nobody does; it's the code gremlins, or rum, that does it)
971 // N.B.: Since 'eval' is of type uint32_t, if it goes negative, it will have
973 if (eval & 0x80000000)
974 return error("negative sizes not allowed");
976 // In non-TDB section (BSS, ABS and M6502) just advance the location
977 // counter appropriately. In TDB sections, deposit (possibly large) chunks
978 // of zeroed memory....
979 if ((scattr & SBSS) || cursect == M6502)
981 listvalue((uint32_t)eval);
983 sloc += (uint32_t)eval;
985 if (cursect == M6502)
988 just_bss = 1; // No data deposited (8-bit CPU mode)
992 dep_block(eval, siz, 0, (WORD)(DEFINED | ABS), NULL);
1001 // dc.b, dc.w / dc, dc.l, dc.i, dc.q, dc.d
1009 if ((scattr & SBSS) != 0)
1010 return error("illegal initialization of section");
1012 // Do an auto_even if it's not BYTE sized (hmm, should we be doing this???)
1013 if (cursect != M6502 && (siz != SIZB) && (sloc & 1))
1016 // Check to see if we're trying to set LONGS on a non 32-bit aligned
1017 // address in a GPU or DSP section, in their local RAM
1018 if ((siz == SIZL) && (orgaddr & 0x03)
1019 && ((rgpu && (orgaddr >= 0xF03000) && (orgaddr <= 0xF03FFFF))
1020 || (rdsp && (orgaddr >= 0xF1B000) && (orgaddr <= 0xF1CFFFF))))
1021 warn("depositing LONGs on a non-long address in local RAM");
1025 // dc.b 'string' [,] ...
1026 if (siz == SIZB && (*tok == STRING || *tok == STRINGA8) && (tok[2] == ',' || tok[2] == EOL))
1028 uint32_t i = strlen(string[tok[1]]);
1030 if ((challoc - ch_size) < i)
1035 for(p=string[tok[1]]; *p!=EOS; p++)
1038 else if(*tok == STRINGA8)
1040 for(p=string[tok[1]]; *p!=EOS; p++)
1041 D_byte(strtoa8[*p]);
1045 error("String format not supported... yet");
1052 int movei = 0; // MOVEI flag for dc.i
1061 // dc.x <expression>
1064 if (expr(exprbuf, &eval, &eattr, &esym) != OK)
1067 uint16_t tdb = eattr & TDB;
1068 uint16_t defined = eattr & DEFINED;
1070 if ((challoc - ch_size) < 4)
1078 AddFixup(FU_BYTE | FU_SEXT, sloc, exprbuf);
1084 return error("non-absolute byte value");
1086 if (eval + 0x100 >= 0x200)
1087 return error("%s (value = $%X)", range_error, eval);
1097 AddFixup(FU_WORD | FU_SEXT, sloc, exprbuf);
1102 if (eval + 0x10000 >= 0x20000)
1103 return error(range_error);
1106 MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
1108 // Deposit 68000 or 6502 (byte-reversed) word
1109 if (cursect != M6502)
1117 // Shamus: Why can't we do longs in 6502 mode?
1119 return error(in_6502mode);
1124 AddFixup(FU_LONG | FU_MOVEI, sloc, exprbuf);
1126 AddFixup(FU_LONG, sloc, exprbuf);
1133 MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
1136 eval = WORDSWAP32(eval);
1144 return error(in_6502mode);
1146 // Shamus: We only handle DC.Q type stuff, will have to add fixups
1147 // and stuff later (maybe... might not be needed...)
1151 // 32-bit float size
1153 return error(in_6502mode);
1157 AddFixup(FU_FLOATSING, sloc, exprbuf);
1163 MarkRelocatable(cursect, sloc, tdb, MSINGLE, NULL);
1167 uint32_t ieee754 = FloatToIEEE754((float)*ptr.dp);
1173 // 64-bit double size
1175 return error(in_6502mode);
1179 AddFixup(FU_FLOATDOUB, sloc, exprbuf);
1185 MarkRelocatable(cursect, sloc, tdb, MDOUBLE, NULL);
1189 uint64_t ieee754 = DoubleToIEEE754(*ptr.dp);
1196 return error(in_6502mode);
1199 memset(extDbl, 0, 12);
1203 AddFixup(FU_FLOATEXT, sloc, exprbuf);
1209 MarkRelocatable(cursect, sloc, tdb, MEXTEND, NULL);
1213 DoubleToExtended(*ptr.dp, extDbl);
1231 // dcb[.siz] expr1,expr2 - Make 'expr1' copies of 'expr2'
1235 uint64_t evalc, eval;
1238 DEBUG { printf("dcb: section is %s%s%s (scattr=$%X)\n", (cursect & TEXT ? "TEXT" : ""), (cursect & DATA ? " DATA" : ""), (cursect & BSS ? "BSS" : ""), scattr); }
1240 if ((scattr & SBSS) != 0)
1241 return error("illegal initialization of section");
1243 if (abs_expr(&evalc) != OK)
1247 return error("missing comma");
1249 if (expr(exprbuf, &eval, &eattr, NULL) < 0)
1252 if (cursect != M6502 && (siz != SIZB) && (sloc & 1))
1255 dep_block((uint32_t)evalc, siz, (uint32_t)eval, eattr, exprbuf);
1261 // Generalized initialization directive
1263 // .init[.siz] [#count,] expression [.size] , ...
1265 // The size suffix on the ".init" directive becomes the default size of the
1266 // objects to deposit. If an item is preceeded with a sharp (immediate) sign
1267 // and an expression, it specifies a repeat count. The value to be deposited
1268 // may be followed by a size suffix, which overrides the default size.
1270 int d_init(WORD def_siz)
1277 if ((scattr & SBSS) != 0)
1278 return error(".init not permitted in BSS or ABS");
1281 return error("directive forbidden in gpu/dsp mode");
1285 // Get repeat count (defaults to 1)
1290 if (abs_expr(&count) != OK)
1294 return error(comma_error);
1299 // Evaluate expression to deposit
1300 if (expr(exprbuf, &eval, &eattr, NULL) < 0)
1304 { // Determine size of object to deposit
1305 case DOTB: siz = SIZB; break;
1306 case DOTW: siz = SIZB; break;
1307 case DOTL: siz = SIZL; break;
1314 dep_block((uint32_t)count, siz, (uint32_t)eval, eattr, exprbuf);
1324 return error(comma_error);
1331 // Deposit 'count' values of size 'siz' in the current (non-BSS) segment
1333 int dep_block(uint32_t count, WORD siz, uint32_t eval, WORD eattr, TOKEN * exprbuf)
1338 tdb = (WORD)(eattr & TDB);
1339 defined = (WORD)(eattr & DEFINED);
1343 if ((challoc - ch_size) < 4)
1351 AddFixup(FU_BYTE | FU_SEXT, sloc, exprbuf);
1357 return error("non-absolute byte value");
1359 if (eval + 0x100 >= 0x200)
1360 return error(range_error);
1370 AddFixup(FU_WORD | FU_SEXT, sloc, exprbuf);
1376 MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
1378 if (eval + 0x10000 >= 0x20000)
1379 return error(range_error);
1381 // Deposit 68000 or 6502 (byte-reversed) word
1382 if (cursect != M6502)
1392 return error(in_6502mode);
1396 AddFixup(FU_LONG, sloc, exprbuf);
1402 MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
1416 // .comm symbol, size
1425 return error(in_6502mode);
1428 return error("missing symbol");
1433 if (*p == '.') // Cannot .comm a local symbol
1434 return error(locgl_error);
1436 if ((sym = lookup(p, LABEL, 0)) == NULL)
1437 sym = NewSymbol(p, LABEL, 0);
1440 if (sym->sattr & DEFINED)
1441 return error(".comm symbol already defined");
1444 sym->sattr = GLOBAL | COMMON | BSS;
1447 return error(comma_error);
1449 if (abs_expr(&eval) != OK) // Parse size of common region
1452 sym->svalue = (uint32_t)eval; // Install common symbol's size
1459 // .list - Turn listing on
1471 // .nlist - Turn listing off
1483 // .68000 - Back to 68000 TEXT segment
1488 // Switching from gpu/dsp sections should reset any ORG'd Address
1492 SwitchSection(TEXT);
1493 activecpu = CPU_68000;
1499 // .68020 - Back to 68000 TEXT segment and select 68020
1504 activecpu = CPU_68020;
1510 // .68030 - Back to 68000 TEXT segment and select 68030
1515 activecpu = CPU_68030;
1521 // .68040 - Back to 68000 TEXT segment and select 68040
1526 activecpu = CPU_68040;
1527 activefpu = FPU_68040;
1533 // .68060 - Back to 68000 TEXT segment and select 68060
1538 activecpu = CPU_68060;
1539 activefpu = FPU_68040;
1545 // .68881 - Back to 68000 TEXT segment and select 68881 FPU
1550 activefpu = FPU_68881;
1556 // .68882 - Back to 68000 TEXT segment and select 68882 FPU
1561 activefpu = FPU_68881;
1567 // nofpu - Deselect FPUs.
1571 activefpu = FPU_NONE;
1581 return error("Not yet, child. Be patient.");
1586 // .gpu - Switch to GPU assembler
1590 if ((cursect != TEXT) && (cursect != DATA))
1592 error(".gpu can only be used in the TEXT or DATA segments");
1596 // If previous section was DSP or 68000 then we need to reset ORG'd Addresses
1603 rgpu = 1; // Set GPU assembly
1604 rdsp = 0; // Unset DSP assembly
1605 regbank = BANK_N; // Set no default register bank
1611 // .dsp - Switch to DSP assembler
1615 if ((cursect != TEXT) && (cursect != DATA))
1617 error(".dsp can only be used in the TEXT or DATA segments");
1621 // If previous section was gpu or 68000 then we need to reset ORG'd Addresses
1628 rdsp = 1; // Set DSP assembly
1629 rgpu = 0; // Unset GPU assembly
1630 regbank = BANK_N; // Set no default register bank
1636 // .cargs [#offset], symbol[.size], ...
1638 // Lists of registers may also be mentioned; they just take up space. Good for
1639 // "documentation" purposes:
1641 // .cargs a6, .arg1, .arg2, .arg3...
1643 // Symbols thus created are ABS and EQUATED.
1647 uint64_t eval = 4; // Default to 4 if no offset specified (to account for
1656 return error("directive forbidden in gpu/dsp mode");
1662 if (abs_expr(&eval) != OK)
1665 // Eat the comma, if it's there
1676 // Set env to either local (dot prefixed) or global scope
1677 env = (*p == '.' ? curenv : 0);
1678 symbol = lookup(p, LABEL, env);
1682 symbol = NewSymbol(p, LABEL, env);
1685 else if (symbol->sattr & DEFINED)
1686 return error("multiply-defined label '%s'", p);
1688 // Put symbol in "order of definition" list
1689 AddToSymbolDeclarationList(symbol);
1691 symbol->sattr |= (ABS | DEFINED | EQUATED);
1692 symbol->svalue = (uint32_t)eval;
1695 // What this does is eat any dot suffixes attached to a symbol. If
1696 // it's a .L, it adds 4 to eval; if it's .W or .B, it adds 2. If
1697 // there is no dot suffix, it assumes a size of 2.
1709 else if (*tok >= KW_D0 && *tok <= KW_A7)
1711 if (reglist(&rlist) < 0)
1714 for(i=0; i<16; i++, rlist>>=1)
1737 return error(".cargs syntax");
1741 // Eat commas in between each argument, if they exist
1749 // .cstruct [#offset], symbol[.size], ...
1751 // Lists of registers may also be mentioned; they just take up space. Good for
1752 // "documentation" purposes:
1754 // .cstruct a6, .arg1, .arg2, .arg3...
1756 // Symbols thus created are ABS and EQUATED. Note that this is for
1757 // compatibility with VBCC and the Remover's library. Thanks to GroovyBee for
1762 uint64_t eval = 0; // Default, if no offset specified, is zero
1770 return error("directive forbidden in gpu/dsp mode");
1776 if (abs_expr(&eval) != OK)
1779 // Eat the comma, if it's there
1788 symbolName = string[tok[1]];
1790 // Set env to either local (dot prefixed) or global scope
1791 env = (symbolName[0] == '.' ? curenv : 0);
1792 symbol = lookup(symbolName, LABEL, env);
1794 // If the symbol wasn't found, then define it. Otherwise, throw an
1798 symbol = NewSymbol(symbolName, LABEL, env);
1801 else if (symbol->sattr & DEFINED)
1802 return error("multiply-defined label '%s'", symbolName);
1804 // Put symbol in "order of definition" list
1805 AddToSymbolDeclarationList(symbol);
1809 // Adjust label start address if it's a word or a long, as a byte
1810 // label might have left us on an odd address.
1815 eval += eval & 0x01;
1818 symbol->sattr |= (ABS | DEFINED | EQUATED);
1819 symbol->svalue = (uint32_t)eval;
1821 // Check for dot suffixes and adjust space accordingly (longs and
1822 // words on an odd boundary get bumped to the next word aligned
1823 // address). If no suffix, then throw an error.
1836 return error("Symbol missing dot suffix in .cstruct construct");
1841 else if (*tok >= KW_D0 && *tok <= KW_A7)
1843 if (reglist(&rlist) < 0)
1846 for(i=0; i<16; i++, rlist>>=1)
1869 return error(".cstruct syntax");
1873 // Eat commas in between each argument, if they exist
1881 // Undefine a macro - .undefmac macname [, macname...]
1883 int undmac1(char * p)
1885 SYM * symbol = lookup(p, MACRO, 0);
1887 // If the macro symbol exists, cause it to disappear
1889 symbol->stype = (BYTE)SY_UNDEF;
1904 warn("JPAD directive is deprecated/non-functional");
1911 warn("NOJPAD directive is deprecated/non-functional");
1918 return error("What the hell? Do you think we adhere to the Goof standard?");
1923 // .opt - turn a specific (or all) optimisation on or off
1932 char * tmpstr = string[*tok++];
1934 if (ParseOptimization(tmpstr) != OK)
1935 return error("unknown optimization flag '%s'", tmpstr);
1938 return error(".opt directive needs every switch enclosed inside quotation marks");
1946 // .if, Start conditional assembly
1953 IFENT * rif = f_ifent;
1957 rif = (IFENT *)malloc(sizeof(IFENT));
1959 f_ifent = rif->if_prev;
1961 rif->if_prev = ifent;
1966 if (expr(exprbuf, &eval, &eattr, &esym) != OK)
1969 if ((eattr & DEFINED) == 0)
1970 return error(undef_error);
1975 rif->if_state = (WORD)disabled;
1981 // .else, Do alternate case for .if
1985 IFENT * rif = ifent;
1987 if (rif->if_prev == NULL)
1988 return error("mismatched .else");
1991 disabled = rif->if_prev->if_state;
1995 rif->if_state = (WORD)disabled;
2001 // .endif, End of conditional assembly block
2002 // This is also called by fpop() to pop levels of IFENTs in case a macro or
2003 // include file exits early with `exitm' or `end'.
2007 IFENT * rif = ifent;
2009 if (rif->if_prev == NULL)
2010 return error("mismatched .endif");
2012 ifent = rif->if_prev;
2013 disabled = rif->if_prev->if_state;
2014 rif->if_prev = f_ifent;