2 // RMAC - Reboot's Macro Assembler for all Atari computers
3 // DIRECT.C - Directive Handling
4 // Copyright (C) 199x Landon Dyer, 2011-2018 Reboot and Friends
5 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
6 // Source utilised with the kind permission of Landon Dyer
29 TOKEN exprbuf[128]; // Expression buffer
30 SYM * symbolPtr[1000000]; // Symbol pointers table
31 static long unused; // For supressing 'write' warnings
32 char buffer[256]; // Scratch buffer for messages
33 int largestAlign[3] = { 2, 2, 2 }; // Largest alignment value seen per section
35 // Function prototypes
71 int d_equrundef(void);
83 void SetLargestAlignment(int);
85 // Directive handler table
96 (void *)d_init, // 9 init
98 (void *)d_goto, // 11 goto
99 (void *)d_dc, // 12 dc
100 (void *)d_ds, // 13 ds
101 d_undmac, // 14 undefmac
104 (void *)d_dcb, // 17 dcb
108 d_incbin, // 21 .incbin //load
109 d_unimpl, // 22 disable
110 d_unimpl, // 23 enable
112 d_regbank0, // 25 .regbank0
113 d_regbank1, // 26 .regbank1
115 d_assert, // 28 assert
117 d_unimpl, // 30* endif
118 d_unimpl, // 31* endc
120 d_include, // 33 include
122 d_unimpl, // 35* macro
123 ExitMacro, // 36* exitm
124 d_unimpl, // 37* endm
128 d_phrase, // 41* endr
129 d_dphrase, // 42 struct
130 d_qphrase, // 43 ends
132 d_subttl, // 45 subttl
136 d_noclear, // 49 .noclear
137 d_equrundef, // 50 .equrundef/.regundef
138 d_ccundef, // 51 .ccundef
139 d_print, // 52 .print
140 d_cstruct, // 53 .cstruct
141 d_jpad, // 54 .jpad (deprecated)
142 d_nojpad, // 55 .nojpad (deprecated)
143 d_gpumain, // 56 .gpumain (deprecated)
144 d_prgflags, // 57 .prgflags
145 d_68020, // 58 .68020
146 d_68030, // 59 .68030
147 d_68040, // 60 .68040
148 d_68060, // 61 .68060
149 d_68881, // 62 .68881
150 d_68882, // 63 .68882
151 d_56001, // 64 .56001
154 d_objproc, // 67 .objproc
159 // Set the largest alignment seen in the current section
161 void SetLargestAlignment(int size)
163 if ((scattr & TEXT) && (largestAlign[0] < size))
164 largestAlign[0] = size;
165 else if ((scattr & DATA) && (largestAlign[1] < size))
166 largestAlign[1] = size;
167 else if ((scattr & BSS) && (largestAlign[2] < size))
168 largestAlign[2] = size;
173 // .error - Abort compilation, printing an error message
175 int d_error(char *str)
178 return error("error directive encountered - aborting assembling");
184 return error(string[tok[1]]);
187 return error("error directive encountered--aborting assembly");
194 // .warn - Just display a warning on screen
196 int d_warn(char *str)
199 return warn("WARNING WARNING WARNING");
205 return warn(string[tok[1]]);
208 return warn("WARNING WARNING WARNING");
221 if (!rgpu && !rdsp && !robjproc && !m6502 && !dsp56001)
222 return error(".org permitted only in GPU/DSP/OP, 56001 and 6502 sections");
224 // M56K can leave the expression off the org for some reason :-/
225 if ((abs_expr(&address) == ERROR) && !dsp56001)
227 error("cannot determine org'd address");
231 if (rgpu | rdsp | robjproc)
238 // 6502. We also kludge 'lsloc' so the listing generator doesn't try
239 // to spew out megabytes.
240 if (address > 0xFFFF)
241 return error(range_error);
243 if (sloc != currentorg[0])
245 currentorg[1] = sloc;
249 currentorg[0] = address;
251 lsloc = sloc = address;
252 chptr = scode->chptr + address;
270 char prntstr[LNSIZ]; // String for PRINT directive
271 char format[LNSIZ]; // Format for PRINT directive
272 int formatting = 0; // Formatting on/off
273 int wordlong = 0; // WORD = 0, LONG = 1
274 int outtype = 0; // 0:hex, 1:decimal, 2:unsigned
276 uint64_t eval; // Expression value
277 WORD eattr; // Expression attributes
278 SYM * esym; // External symbol involved in expr.
279 TOKEN r_expr[EXPRSIZE];
286 sprintf(prntstr, "%s", string[tok[1]]);
287 printf("%s", prntstr);
290 unused = write(list_fd, prntstr, (LONG)strlen(prntstr));
297 // "X" & "L" get tokenized now... :-/ Probably should look into preventing this kind of thing from happening (was added with DSP56K code)
298 if ((tok[1] != SYMBOL) && (tok[1] != KW_L) && (tok[1] != KW_X))
306 else if (tok[1] == KW_X)
313 strcpy(prntstr, string[tok[2]]);
317 case 'l': case 'L': wordlong = 1; break;
318 case 'w': case 'W': wordlong = 0; break;
319 case 'x': case 'X': outtype = 0; break;
320 case 'd': case 'D': outtype = 1; break;
321 case 'u': case 'U': outtype = 2; break;
323 error("unknown print format flag");
335 if (expr(r_expr, &eval, &eattr, &esym) != OK)
341 case 0: strcpy(format, "%X"); break;
342 case 1: strcpy(format, "%d" ); break;
343 case 2: strcpy(format, "%u" ); break;
347 sprintf(prntstr, format, eval);
349 sprintf(prntstr, format, eval & 0xFFFF);
351 printf("%s", prntstr);
354 unused = write(list_fd, prntstr, (LONG)strlen(prntstr));
370 error("illegal print token [@ '%s']", prntstr);
376 // Undefine an equated condition code
382 // Check that we are in a RISC section
385 error(".ccundef must be defined in .gpu/.dsp section");
391 error("syntax error; expected symbol");
395 ccname = lookup(string[tok[1]], LABEL, 0);
397 // Make sure symbol is a valid ccdef
398 if (!ccname || !(ccname->sattre & EQUATEDCC))
400 error("invalid equated condition name specified");
404 ccname->sattre |= UNDEF_CC;
411 // Undefine an equated register
413 int d_equrundef(void)
417 // Check that we are in a RISC section
419 return error(".equrundef/.regundef must be defined in .gpu/.dsp section");
423 // Skip preceeding or seperating commas (if any)
427 // Check we are dealing with a symbol
429 return error("syntax error; expected symbol");
431 // Lookup and undef if equated register
432 regname = lookup(string[tok[1]], LABEL, 0);
434 if (regname && (regname->sattre & EQUATEDREG))
436 // Reset the attributes of this symbol...
438 regname->sattre &= ~(EQUATEDREG | BANK_0 | BANK_1);
439 regname->sattre |= UNDEF_EQUR;
442 // Skip over symbol token and address
451 // Do not allow use of the CLR.L opcode
455 warn("CLR.L opcode ignored...");
461 // Include binary file
467 long pos, size, bytesRead;
471 // Check to see if we're in BSS, and, if so, throw an error
474 error("cannot include binary file \"%s\" in BSS section", string[tok[1]]);
480 error("syntax error; file to include missing");
484 // Attempt to open the include file in the current directory, then (if that
485 // failed) try list of include files passed in the enviroment string or by
487 if ((fd = open(string[tok[1]], _OPEN_INC)) < 0)
489 for(i=0; nthpath("RMACPATH", i, buf1)!=0; i++)
493 // Append path char if necessary
494 if (fd > 0 && buf1[fd - 1] != SLASHCHAR)
495 strcat(buf1, SLASHSTRING);
497 strcat(buf1, string[tok[1]]);
499 if ((fd = open(buf1, _OPEN_INC)) >= 0)
503 return error("cannot open: \"%s\"", string[tok[1]]);
508 size = lseek(fd, 0L, SEEK_END);
509 pos = lseek(fd, 0L, SEEK_SET);
512 DEBUG { printf("INCBIN: File '%s' is %li bytes.\n", string[tok[1]], size); }
514 char * fileBuffer = (char *)malloc(size);
515 bytesRead = read(fd, fileBuffer, size);
517 if (bytesRead != size)
519 error("was only able to read %li bytes from binary file (%s, %li bytes)", bytesRead, string[tok[1]], size);
523 memcpy(chptr, fileBuffer, size);
538 // Set RISC register banks
542 // Set active register bank zero
550 // Set active register bank one
557 // Helper function, to cut down on mistakes & typing
559 static inline void SkipBytes(unsigned bytesToSkip)
564 if ((scattr & SBSS) == 0)
566 chcheck(bytesToSkip);
567 D_ZEROFILL(bytesToSkip);
574 orgaddr += bytesToSkip;
580 // Adjust location to an EVEN value
585 return error(in_6502mode);
587 unsigned skip = (rgpu || rdsp ? orgaddr : sloc) & 0x01;
591 if ((scattr & SBSS) == 0)
610 // Adjust location to a LONG value
614 unsigned lower2Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x03;
615 unsigned bytesToSkip = (0x04 - lower2Bits) & 0x03;
616 SkipBytes(bytesToSkip);
617 SetLargestAlignment(4);
624 // Adjust location to a PHRASE value
626 // N.B.: We have to handle the GPU/DSP cases separately because you can embed
627 // RISC code in the middle of a regular 68K section. Also note that all
628 // of the alignment pseudo-ops will have to be fixed this way.
630 // This *must* behave differently when in a RISC section, as following sloc
631 // (instead of orgaddr) will fuck things up royally. Note that we do it this
632 // way because you can embed RISC code in a 68K section, and have the origin
633 // pointing to a different alignment in the RISC section than the 68K section.
637 unsigned lower3Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x07;
638 unsigned bytesToSkip = (0x08 - lower3Bits) & 0x07;
639 SkipBytes(bytesToSkip);
640 SetLargestAlignment(8);
647 // Adjust location to a DPHRASE value
651 unsigned lower4Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x0F;
652 unsigned bytesToSkip = (0x10 - lower4Bits) & 0x0F;
653 SkipBytes(bytesToSkip);
654 SetLargestAlignment(16);
661 // Adjust location to a QPHRASE value
665 unsigned lower5Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x1F;
666 unsigned bytesToSkip = (0x20 - lower5Bits) & 0x1F;
667 SkipBytes(bytesToSkip);
668 SetLargestAlignment(32);
675 // Do auto-even. This must be called ONLY if 'sloc' is odd.
677 // This is made hairy because, if there was a label on the line, we also have
678 // to adjust its value. This won't work with more than one label on the line,
679 // which is OK since multiple labels are only allowed in AS68 kludge mode, and
680 // the C compiler is VERY paranoid and uses ".even" whenever it can
682 // N.B.: This probably needs the same fixes as above...
686 if (cursect != M6502)
689 sloc++; // Bump BSS section
691 D_byte(0); // Deposit 0.b in non-BSS
693 if (lab_sym != NULL) // Bump label if we have to
700 // Unimplemened directive error
704 return error("unimplemented directive");
709 // Return absolute (not TDB) and defined expression or return an error
711 int abs_expr(uint64_t * a_eval)
715 if (expr(exprbuf, a_eval, &eattr, NULL) < 0)
718 if (!(eattr & DEFINED))
719 return error(undef_error);
722 return error(rel_error);
729 // Hand symbols in a symbol-list to a function (kind of like mapcar...)
731 int symlist(int(* func)())
733 const char * em = "symbol list syntax";
740 if ((*func)(string[tok[1]]) != OK)
759 // .include "filename"
769 if (*tok == STRING) // Leave strings ALONE
771 else if (*tok == SYMBOL) // Try to append ".s" to symbols
773 strcpy(buf, string[*++tok]);
777 else // Punt if no STRING or SYMBOL
778 return error("missing filename");
780 // Make sure the user didn't try anything like:
781 // .include equates.s
783 return error("extra stuff after filename--enclose it in quotes");
785 // Attempt to open the include file in the current directory, then (if that
786 // failed) try list of include files passed in the enviroment string or by
788 if ((j = open(fn, 0)) < 0)
790 for(i=0; nthpath("RMACPATH", i, buf1)!=0; i++)
794 // Append path char if necessary
795 if (j > 0 && buf1[j - 1] != SLASHCHAR)
796 strcat(buf1, SLASHSTRING);
800 if ((j = open(buf1, 0)) >= 0)
804 return error("cannot open: \"%s\"", fn);
814 // .assert expression [, expression...]
821 for(; expr(exprbuf, &eval, &eattr, NULL)==OK; ++tok)
823 if (!(eattr & DEFINED))
824 return error("forward or undefined .assert");
827 return error("assert failure");
839 // .globl symbol [, symbol] <<<cannot make local symbols global>>>
846 return error("cannot .globl local symbol");
848 if ((sy = lookup(p, LABEL, 0)) == NULL)
850 sy = NewSymbol(p, LABEL, 0);
853 //printf("glob1: Making global symbol: attr=%04X, eattr=%08X, %s\n", sy->sattr, sy->sattre, sy->sname);
865 return error(in_6502mode);
873 // .prgflags expression
880 return error("PRGFLAGS requires value");
881 else if (abs_expr(&eval) == OK)
883 PRGFLAGS = (uint32_t)eval;
888 return error("PRGFLAGS requires value");
901 return error(in_6502mode);
907 else if (abs_expr(&eval) != OK)
911 sloc = (uint32_t)eval;
922 return error("directive forbidden in gpu/dsp mode");
924 return error(in_6502mode);
939 return error("directive forbidden in gpu/dsp mode");
941 return error(in_6502mode);
956 return error("directive forbidden in gpu/dsp mode");
958 return error(in_6502mode);
971 // .ds[.size] expression
975 DEBUG { printf("Directive: .ds.[size] = %u, sloc = $%X\n", siz, sloc); }
979 if ((cursect & (M6502 | M56KPXYL)) == 0)
981 if ((siz != SIZB) && (sloc & 1)) // Automatic .even
985 if (abs_expr(&eval) != OK)
988 // Check to see if the value being passed in is negative (who the hell does
989 // that?--nobody does; it's the code gremlins, or rum, that does it)
990 // N.B.: Since 'eval' is of type uint32_t, if it goes negative, it will have
992 if (eval & 0x80000000)
993 return error("negative sizes not allowed");
995 // In non-TDB section (BSS, ABS and M6502) just advance the location
996 // counter appropriately. In TDB sections, deposit (possibly large) chunks
997 // of zeroed memory....
998 if ((scattr & SBSS) || cursect == M6502)
1000 listvalue((uint32_t)eval);
1002 sloc += (uint32_t)eval;
1004 if (cursect == M6502)
1007 just_bss = 1; // No data deposited (8-bit CPU mode)
1011 dep_block(eval, siz, 0, (WORD)(DEFINED | ABS), NULL);
1020 // dc.b, dc.w / dc, dc.l, dc.i, dc.q, dc.d
1028 if ((scattr & SBSS) != 0)
1029 return error("illegal initialization of section");
1031 // Do an auto_even if it's not BYTE sized (hmm, should we be doing this???)
1032 if (cursect != M6502 && (siz != SIZB) && (sloc & 1))
1035 // Check to see if we're trying to set LONGS on a non 32-bit aligned
1036 // address in a GPU or DSP section, in their local RAM
1037 if ((siz == SIZL) && (orgaddr & 0x03)
1038 && ((rgpu && (orgaddr >= 0xF03000) && (orgaddr <= 0xF03FFFF))
1039 || (rdsp && (orgaddr >= 0xF1B000) && (orgaddr <= 0xF1CFFFF))))
1040 warn("depositing LONGs on a non-long address in local RAM");
1044 // dc.b 'string' [,] ...
1045 if (siz == SIZB && (*tok == STRING || *tok == STRINGA8) && (tok[2] == ',' || tok[2] == EOL))
1047 uint32_t i = strlen(string[tok[1]]);
1049 if ((challoc - ch_size) < i)
1054 for(p=string[tok[1]]; *p!=EOS; p++)
1057 else if (*tok == STRINGA8)
1059 for(p=string[tok[1]]; *p!=EOS; p++)
1060 D_byte(strtoa8[*p]);
1064 error("String format not supported... yet");
1071 int movei = 0; // MOVEI flag for dc.i
1080 // dc.x <expression>
1083 if (expr(exprbuf, &eval, &eattr, &esym) != OK)
1086 uint16_t tdb = eattr & TDB;
1087 uint16_t defined = eattr & DEFINED;
1094 AddFixup(FU_BYTE | FU_SEXT, sloc, exprbuf);
1100 return error("non-absolute byte value");
1102 if (eval + 0x100 >= 0x200)
1103 return error("%s (value = $%X)", range_error, eval);
1113 AddFixup(FU_WORD | FU_SEXT, sloc, exprbuf);
1118 if (eval + 0x10000 >= 0x20000)
1119 return error(range_error);
1122 MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
1124 // Deposit 68000 or 6502 (byte-reversed) word
1125 if (cursect != M6502)
1133 // Shamus: Why can't we do longs in 6502 mode?
1135 return error(in_6502mode);
1140 AddFixup(FU_LONG | FU_MOVEI, sloc, exprbuf);
1142 AddFixup(FU_LONG, sloc, exprbuf);
1149 MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
1152 eval = WORDSWAP32(eval);
1161 return error(in_6502mode);
1163 // Shamus: We only handle DC.Q type stuff, will have to add fixups
1164 // and stuff later (maybe... might not be needed...)
1165 // DEFINITELY NEED FIXUPS HERE!
1168 AddFixup(FU_QUAD, sloc, exprbuf);
1178 // 32-bit float size
1180 return error(in_6502mode);
1184 AddFixup(FU_FLOATSING, sloc, exprbuf);
1189 //Would this *ever* happen?
1191 // MarkRelocatable(cursect, sloc, tdb, MSINGLE, NULL);
1195 uint32_t ieee754 = FloatToIEEE754((float)*ptr.dp);
1201 // 64-bit double size
1203 return error(in_6502mode);
1207 AddFixup(FU_FLOATDOUB, sloc, exprbuf);
1212 //Would this *ever* happen?
1214 // MarkRelocatable(cursect, sloc, tdb, MDOUBLE, NULL);
1218 uint64_t ieee754 = DoubleToIEEE754(*ptr.dp);
1225 return error(in_6502mode);
1228 memset(extDbl, 0, 12);
1232 AddFixup(FU_FLOATEXT, sloc, exprbuf);
1237 //Would this *ever* happen?
1239 // MarkRelocatable(cursect, sloc, tdb, MEXTEND, NULL);
1243 DoubleToExtended(*ptr.dp, extDbl);
1261 // dcb[.siz] expr1,expr2 - Make 'expr1' copies of 'expr2'
1265 uint64_t evalc, eval;
1268 DEBUG { printf("dcb: section is %s%s%s (scattr=$%X)\n", (cursect & TEXT ? "TEXT" : ""), (cursect & DATA ? " DATA" : ""), (cursect & BSS ? "BSS" : ""), scattr); }
1270 if ((scattr & SBSS) != 0)
1271 return error("illegal initialization of section");
1273 if (abs_expr(&evalc) != OK)
1277 return error("missing comma");
1279 if (expr(exprbuf, &eval, &eattr, NULL) < 0)
1282 if (cursect != M6502 && (siz != SIZB) && (sloc & 1))
1285 dep_block((uint32_t)evalc, siz, (uint32_t)eval, eattr, exprbuf);
1291 // Generalized initialization directive
1293 // .init[.siz] [#count,] expression [.size] , ...
1295 // The size suffix on the ".init" directive becomes the default size of the
1296 // objects to deposit. If an item is preceeded with a sharp (immediate) sign
1297 // and an expression, it specifies a repeat count. The value to be deposited
1298 // may be followed by a size suffix, which overrides the default size.
1300 int d_init(WORD def_siz)
1307 if ((scattr & SBSS) != 0)
1308 return error(".init not permitted in BSS or ABS");
1311 return error("directive forbidden in gpu/dsp mode");
1315 // Get repeat count (defaults to 1)
1320 if (abs_expr(&count) != OK)
1324 return error(comma_error);
1329 // Evaluate expression to deposit
1330 if (expr(exprbuf, &eval, &eattr, NULL) < 0)
1334 { // Determine size of object to deposit
1335 case DOTB: siz = SIZB; break;
1336 case DOTW: siz = SIZB; break;
1337 case DOTL: siz = SIZL; break;
1344 dep_block((uint32_t)count, siz, (uint32_t)eval, eattr, exprbuf);
1354 return error(comma_error);
1361 // Deposit 'count' values of size 'siz' in the current (non-BSS) segment
1363 int dep_block(uint32_t count, WORD siz, uint32_t eval, WORD eattr, TOKEN * exprbuf)
1368 tdb = (WORD)(eattr & TDB);
1369 defined = (WORD)(eattr & DEFINED);
1373 if ((challoc - ch_size) < 4)
1381 AddFixup(FU_BYTE | FU_SEXT, sloc, exprbuf);
1387 return error("non-absolute byte value");
1389 if (eval + 0x100 >= 0x200)
1390 return error(range_error);
1400 AddFixup(FU_WORD | FU_SEXT, sloc, exprbuf);
1406 MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
1408 if (eval + 0x10000 >= 0x20000)
1409 return error(range_error);
1411 // Deposit 68000 or 6502 (byte-reversed) word
1412 if (cursect != M6502)
1422 return error(in_6502mode);
1426 AddFixup(FU_LONG, sloc, exprbuf);
1432 MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
1446 // .comm symbol, size
1455 return error(in_6502mode);
1458 return error("missing symbol");
1463 if (*p == '.') // Cannot .comm a local symbol
1464 return error(locgl_error);
1466 if ((sym = lookup(p, LABEL, 0)) == NULL)
1467 sym = NewSymbol(p, LABEL, 0);
1470 if (sym->sattr & DEFINED)
1471 return error(".comm symbol already defined");
1474 sym->sattr = GLOBAL | COMMON | BSS;
1477 return error(comma_error);
1479 if (abs_expr(&eval) != OK) // Parse size of common region
1482 sym->svalue = eval; // Install common symbol's size
1489 // .list - Turn listing on
1501 // .nlist - Turn listing off
1513 // .68000 - Back to 68000 TEXT segment
1517 rgpu = rdsp = robjproc = dsp56001 = 0;
1518 // Switching from gpu/dsp sections should reset any ORG'd Address
1522 SwitchSection(TEXT);
1523 activecpu = CPU_68000;
1529 // .68020 - Back to 68000 TEXT segment and select 68020
1534 activecpu = CPU_68020;
1540 // .68030 - Back to 68000 TEXT segment and select 68030
1545 activecpu = CPU_68030;
1551 // .68040 - Back to 68000 TEXT segment and select 68040
1556 activecpu = CPU_68040;
1557 activefpu = FPU_68040;
1563 // .68060 - Back to 68000 TEXT segment and select 68060
1568 activecpu = CPU_68060;
1569 activefpu = FPU_68060;
1575 // .68881 - Back to 680x0 TEXT segment and select 68881 FPU
1580 activefpu = FPU_68881;
1586 // .68882 - Back to 680x0 TEXT segment and select 68882 FPU
1591 activefpu = FPU_68882;
1597 // nofpu - Deselect FPUs.
1601 activefpu = FPU_NONE;
1607 // .56001 - Switch to DSP56001 assembler
1612 rgpu = rdsp = robjproc = 0;
1615 if (obj_format == LOD || obj_format == P56)
1616 SwitchSection(M56001P);
1623 // .gpu - Switch to GPU assembler
1627 if ((cursect != TEXT) && (cursect != DATA))
1629 error(".gpu can only be used in the TEXT or DATA segments");
1633 // If previous section was DSP or 68000 then we need to reset ORG'd Addresses
1640 rgpu = 1; // Set GPU assembly
1641 rdsp = 0; // Unset DSP assembly
1642 robjproc = 0; // Unset OP assembly
1643 dsp56001 = 0; // Unset 56001 assembly
1644 regbank = BANK_N; // Set no default register bank
1650 // .dsp - Switch to DSP assembler
1654 if ((cursect != TEXT) && (cursect != DATA))
1656 error(".dsp can only be used in the TEXT or DATA segments");
1660 // If previous section was gpu or 68000 then we need to reset ORG'd Addresses
1667 rdsp = 1; // Set DSP assembly
1668 rgpu = 0; // Unset GPU assembly
1669 robjproc = 0; // Unset OP assembly
1670 dsp56001 = 0; // Unset 56001 assembly
1671 regbank = BANK_N; // Set no default register bank
1677 // .cargs [#offset], symbol[.size], ...
1679 // Lists of registers may also be mentioned; they just take up space. Good for
1680 // "documentation" purposes:
1682 // .cargs a6, .arg1, .arg2, .arg3...
1684 // Symbols thus created are ABS and EQUATED.
1688 uint64_t eval = 4; // Default to 4 if no offset specified (to account for
1697 return error("directive forbidden in gpu/dsp mode");
1703 if (abs_expr(&eval) != OK)
1706 // Eat the comma, if it's there
1717 // Set env to either local (dot prefixed) or global scope
1718 env = (*p == '.' ? curenv : 0);
1719 symbol = lookup(p, LABEL, env);
1723 symbol = NewSymbol(p, LABEL, env);
1726 else if (symbol->sattr & DEFINED)
1727 return error("multiply-defined label '%s'", p);
1729 // Put symbol in "order of definition" list
1730 AddToSymbolDeclarationList(symbol);
1732 symbol->sattr |= (ABS | DEFINED | EQUATED);
1733 symbol->svalue = eval;
1736 // What this does is eat any dot suffixes attached to a symbol. If
1737 // it's a .L, it adds 4 to eval; if it's .W or .B, it adds 2. If
1738 // there is no dot suffix, it assumes a size of 2.
1750 else if (*tok >= KW_D0 && *tok <= KW_A7)
1752 if (reglist(&rlist) < 0)
1755 for(i=0; i<16; i++, rlist>>=1)
1778 return error(".cargs syntax");
1782 // Eat commas in between each argument, if they exist
1790 // .cstruct [#offset], symbol[.size], ...
1792 // Lists of registers may also be mentioned; they just take up space. Good for
1793 // "documentation" purposes:
1795 // .cstruct a6, .arg1, .arg2, .arg3...
1797 // Symbols thus created are ABS and EQUATED. Note that this is for
1798 // compatibility with VBCC and the Remover's library. Thanks to GroovyBee for
1803 uint64_t eval = 0; // Default, if no offset specified, is zero
1811 return error("directive forbidden in gpu/dsp mode");
1817 if (abs_expr(&eval) != OK)
1820 // Eat the comma, if it's there
1829 symbolName = string[tok[1]];
1831 // Set env to either local (dot prefixed) or global scope
1832 env = (symbolName[0] == '.' ? curenv : 0);
1833 symbol = lookup(symbolName, LABEL, env);
1835 // If the symbol wasn't found, then define it. Otherwise, throw an
1839 symbol = NewSymbol(symbolName, LABEL, env);
1842 else if (symbol->sattr & DEFINED)
1843 return error("multiply-defined label '%s'", symbolName);
1845 // Put symbol in "order of definition" list
1846 AddToSymbolDeclarationList(symbol);
1850 // Adjust label start address if it's a word or a long, as a byte
1851 // label might have left us on an odd address.
1856 eval += eval & 0x01;
1859 symbol->sattr |= (ABS | DEFINED | EQUATED);
1860 symbol->svalue = eval;
1862 // Check for dot suffixes and adjust space accordingly (longs and
1863 // words on an odd boundary get bumped to the next word aligned
1864 // address). If no suffix, then throw an error.
1877 return error("Symbol missing dot suffix in .cstruct construct");
1882 else if (*tok >= KW_D0 && *tok <= KW_A7)
1884 if (reglist(&rlist) < 0)
1887 for(i=0; i<16; i++, rlist>>=1)
1910 return error(".cstruct syntax");
1914 // Eat commas in between each argument, if they exist
1922 // Define start of OP object list (allows the use of ORG)
1926 if ((cursect != TEXT) && (cursect != DATA))
1928 error(".objproc can only be used in the TEXT or DATA segments");
1932 // If previous section was DSP or 68000 then we need to reset ORG'd
1940 robjproc = 1; // Set OP assembly
1941 rgpu = 0; // Unset GPU assembly
1942 rdsp = 0; // Unset DSP assembly
1943 dsp56001 = 0; // Unset 56001 assembly
1949 // Undefine a macro - .undefmac macname [, macname...]
1951 int undmac1(char * p)
1953 SYM * symbol = lookup(p, MACRO, 0);
1955 // If the macro symbol exists, cause it to disappear
1957 symbol->stype = (BYTE)SY_UNDEF;
1972 warn("JPAD directive is deprecated/non-functional");
1979 warn("NOJPAD directive is deprecated/non-functional");
1986 return error("What the hell? Do you think we adhere to the Goof standard?");
1991 // .opt - turn a specific (or all) optimisation on or off
2000 char * tmpstr = string[*tok++];
2002 if (ParseOptimization(tmpstr) != OK)
2003 return error("unknown optimization flag '%s'", tmpstr);
2006 return error(".opt directive needs every switch enclosed inside quotation marks");
2014 // .if, Start conditional assembly
2021 IFENT * rif = f_ifent;
2025 rif = (IFENT *)malloc(sizeof(IFENT));
2027 f_ifent = rif->if_prev;
2029 rif->if_prev = ifent;
2034 if (expr(exprbuf, &eval, &eattr, &esym) != OK)
2037 if ((eattr & DEFINED) == 0)
2038 return error(undef_error);
2043 rif->if_state = (WORD)disabled;
2049 // .else, Do alternate case for .if
2053 IFENT * rif = ifent;
2055 if (rif->if_prev == NULL)
2056 return error("mismatched .else");
2059 disabled = rif->if_prev->if_state;
2063 rif->if_state = (WORD)disabled;
2069 // .endif, End of conditional assembly block
2070 // This is also called by fpop() to pop levels of IFENTs in case a macro or
2071 // include file exits early with `exitm' or `end'.
2075 IFENT * rif = ifent;
2077 if (rif->if_prev == NULL)
2078 return error("mismatched .endif");
2080 ifent = rif->if_prev;
2081 disabled = rif->if_prev->if_state;
2082 rif->if_prev = f_ifent;