]> Shamusworld >> Repos - rmac/blob - direct.c
7076358cf0db46c2fa2384a0791b0761391b22ce
[rmac] / direct.c
1 //
2 // RMAC - Reboot's Macro Assembler for the Atari Jaguar Console System
3 // DIRECT.C - Directive Handling
4 // Copyright (C) 199x Landon Dyer, 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
7 //
8
9 #include "direct.h"
10 #include "6502.h"
11 #include "error.h"
12 #include "expr.h"
13 #include "listing.h"
14 #include "mach.h"
15 #include "macro.h"
16 #include "mark.h"
17 #include "procln.h"
18 #include "riscasm.h"
19 #include "sect.h"
20 #include "symbol.h"
21 #include "token.h"
22
23 #define DEF_KW
24 #include "kwtab.h"
25
26 TOKEN exprbuf[128];                     // Expression buffer
27 SYM * symbolPtr[1000000];       // Symbol pointers table
28 static long unused;                     // For supressing 'write' warnings
29 char buffer[256];                       // Scratch buffer for messages
30
31 // Function prototypes
32 int d_unimpl(void);
33 int d_68000(void);
34 int d_bss(void);
35 int d_data(void);
36 int d_text(void);
37 int d_abs(void);
38 int d_comm(void);
39 int d_dc(WORD);
40 int d_ds(WORD);
41 int d_dcb(WORD);
42 int d_globl(void);
43 int d_gpu(void);
44 int d_dsp(void);
45 int d_assert(void);
46 int d_include(void);
47 int d_list(void);
48 int d_nlist(void);
49 int d_error(char *);
50 int d_warn(char *);
51 int d_org(void);
52 int d_init(WORD);
53 int d_cargs(void);
54 int d_undmac(void);
55 int d_regbank0(void);
56 int d_regbank1(void);
57 int d_incbin(void);
58 int d_noclear(void);
59 int d_equrundef(void);
60 int d_ccundef(void);
61 int d_print(void);
62 int d_gpumain(void);
63 int d_jpad(void);
64 int d_nojpad(void);
65 int d_fail(void);
66 int d_cstruct(void);
67 int d_prgflags(void);
68 int d_opt(void);
69 int d_dsp(void);
70
71 // Directive handler table
72 int (*dirtab[])() = {
73         d_org,                          // 0 org
74         d_even,                         // 1 even
75         d_6502,                         // 2 .6502
76         d_68000,                        // 3 .68000
77         d_bss,                          // 4 bss
78         d_data,                         // 5 data
79         d_text,                         // 6 text
80         d_abs,                          // 7 abs
81         d_comm,                         // 8 comm
82         (void *)d_init,         // 9 init
83         d_cargs,                        // 10 cargs
84         (void *)d_goto,         // 11 goto
85         (void *)d_dc,           // 12 dc
86         (void *)d_ds,           // 13 ds
87         d_undmac,                       // 14 undefmac
88         d_gpu,                          // 15 .gpu
89         d_dsp,                          // 16 .dsp
90         (void *)d_dcb,          // 17 dcb
91         d_unimpl,                       // 18* set
92         d_unimpl,                       // 19* reg
93         d_unimpl,                       // 20 dump
94         d_incbin,                       // 21 .incbin //load
95         d_unimpl,                       // 22 disable
96         d_unimpl,                       // 23 enable
97         d_globl,                        // 24 globl
98         d_regbank0,                     // 25 .regbank0
99         d_regbank1,                     // 26 .regbank1
100         d_unimpl,                       // 27 xdef
101         d_assert,                       // 28 assert
102         d_unimpl,                       // 29* if
103         d_unimpl,                       // 30* endif
104         d_unimpl,                       // 31* endc
105         d_unimpl,                       // 32* iif
106         d_include,                      // 33 include
107         fpop,                           // 34 end
108         d_unimpl,                       // 35* macro
109         ExitMacro,                      // 36* exitm
110         d_unimpl,                       // 37* endm
111         d_list,                         // 38 list
112         d_nlist,                        // 39 nlist
113         d_long,                         // 40* rept
114         d_phrase,                       // 41* endr
115         d_dphrase,                      // 42 struct
116         d_qphrase,                      // 43 ends
117         d_title,                        // 44 title
118         d_subttl,                       // 45 subttl
119         eject,                          // 46 eject
120         d_error,                        // 47 error
121         d_warn,                         // 48 warn
122         d_noclear,                      // 49 .noclear
123         d_equrundef,            // 50 .equrundef/.regundef
124         d_ccundef,                      // 51 .ccundef
125         d_print,                        // 52 .print
126         d_cstruct,                      // 53 .cstruct
127         d_jpad,                         // 54 .jpad (deprecated)
128         d_nojpad,                       // 55 .nojpad (deprecated)
129         d_gpumain,                      // 56 .gpumain (deprecated)
130         d_prgflags,                     // 57 .prgflags
131         d_68020,                        // 58 .68020
132         d_68030,                        // 59 .68030
133         d_68040,                        // 60 .68040
134         d_68060,                        // 61 .68060
135         d_68881,                        // 62 .68881
136         d_68882,                        // 63 .68882
137         d_56001,                        // 64 .56001
138         d_nofpu,                        // 65 nofpu
139         d_opt,                          // 58 .opt
140 };
141
142
143 //
144 // .error - Abort compilation, printing an error message
145 //
146 int d_error(char *str)
147 {
148         if (*tok == EOL)
149                 return error("error directive encountered - aborting assembling");
150         else
151         {
152                 switch(*tok)
153                 {
154                 case STRING:
155                         return error(string[tok[1]]);
156                         break;
157                 default:
158                         return error("error directive encountered - aborting assembling");
159                 }
160         }
161 }
162
163
164 //
165 // .warn - Just display a warning on screen
166 //
167 int d_warn(char *str)
168 {
169         if (*tok == EOL)
170                 return warn("WARNING WARNING WARNING");
171         else
172         {
173                 switch(*tok)
174                 {
175                 case STRING:
176                         return warn(string[tok[1]]);
177                         break;
178                 default:
179                         return warn("WARNING WARNING WARNING");
180                 }
181         }
182 }
183
184
185 //
186 // .org - Set origin
187 //
188 int d_org(void)
189 {
190         VALUE address;
191
192         if (!rgpu && !rdsp && !m6502)
193                 return error(".org permitted only in gpu/dsp and 6502 sections");
194
195         if (abs_expr(&address) == ERROR)
196         {
197                 error("cannot determine org'd address");
198                 return ERROR;
199         }
200
201         if (rgpu | rdsp)
202         {
203                 orgaddr = address;
204                 orgactive = 1;
205         }
206         else
207         {
208                 // 6502.  We also kludge `lsloc' so the listing generator doesn't try
209                 // to spew out megabytes.
210                 if (address > 0xFFFF)
211                         return error(range_error);
212
213                 if (sloc != currentorg[0])
214                 {
215                         currentorg[1] = sloc;
216                         currentorg += 2;
217                 }
218
219                 currentorg[0] = address;
220                 ch_size = 0;
221                 lsloc = sloc = address;
222                 chptr = scode->chptr + address;
223                 orgaddr = address;
224                 orgactive = 1;
225                 at_eol();
226         }
227
228         return 0;
229 }
230
231
232 //
233 // Print directive
234 //
235 int d_print(void)
236 {
237         char prntstr[LNSIZ];            // String for PRINT directive
238         char format[LNSIZ];                     // Format for PRINT directive
239         int formatting = 0;                     // Formatting on/off
240         int wordlong = 0;                       // WORD = 0, LONG = 1
241         int outtype = 0;                        // 0:hex, 1:decimal, 2:unsigned
242
243         VALUE eval;                                     // Expression value
244         WORD eattr;                                     // Expression attributes
245         SYM * esym;                                     // External symbol involved in expr.
246         TOKEN r_expr[EXPRSIZE];
247
248         while (*tok != EOL)
249         {
250                 switch(*tok)
251                 {
252                 case STRING:
253                         sprintf(prntstr, "%s", string[tok[1]]);
254                         printf("%s", prntstr);
255
256                         if (list_fd)
257                                 unused = write(list_fd, prntstr, (LONG)strlen(prntstr));
258
259                         tok += 2;
260                         break;
261                 case '/':
262                         formatting = 1;
263
264                         if (tok[1] != SYMBOL)
265                                 goto token_err;
266
267 //                      strcpy(prntstr, (char *)tok[2]);
268                         strcpy(prntstr, string[tok[2]]);
269
270                         switch(prntstr[0])
271                         {
272                         case 'l': case 'L': wordlong = 1; break;
273                         case 'w': case 'W': wordlong = 0; break;
274                         case 'x': case 'X': outtype  = 0; break;
275                         case 'd': case 'D': outtype  = 1; break;
276                         case 'u': case 'U': outtype  = 2; break;
277                         default:
278                                 error("unknown print format flag");
279                                 return ERROR;
280                         }
281
282                         tok += 3;
283                         break;
284                 case ',':
285                         tok++;
286                         break;
287                 default:
288                         if (expr(r_expr, &eval, &eattr, &esym) != OK)
289                                 goto token_err;
290                         else
291                         {
292                                 switch(outtype)
293                                 {
294                                 case 0: strcpy(format, "%X"); break;
295                                 case 1: strcpy(format, "%d" ); break;
296                                 case 2: strcpy(format, "%u" ); break;
297                                 }
298
299                                 if (wordlong)
300                                         sprintf(prntstr, format, eval);
301                                 else
302                                         sprintf(prntstr, format, eval & 0xFFFF);
303
304                                 printf("%s", prntstr);
305
306                                 if (list_fd)
307                                         unused = write(list_fd, prntstr, (LONG)strlen(prntstr));
308
309                                 formatting = 0;
310                                 wordlong = 0;
311                                 outtype = 0;
312                         }
313
314                         break;
315                 }
316         }
317
318         printf("\n");
319
320         return 0;
321
322 token_err:
323         error("illegal print token");
324         return ERROR;
325 }
326
327
328 //
329 // Undefine an equated condition code
330 //
331 int d_ccundef(void)
332 {
333         SYM * ccname;
334
335         // Check that we are in a RISC section
336         if (!rgpu && !rdsp)
337         {
338                 error(".ccundef must be defined in .gpu/.dsp section");
339                 return ERROR;
340         }
341
342         if (*tok != SYMBOL)
343         {
344                 error("syntax error; expected symbol");
345                 return ERROR;
346         }
347
348         ccname = lookup(string[tok[1]], LABEL, 0);
349
350         // Make sure symbol is a valid ccdef
351         if (!ccname || !(ccname->sattre & EQUATEDCC))
352         {
353                 error("invalid equated condition name specified");
354                 return ERROR;
355         }
356
357         ccname->sattre |= UNDEF_CC;
358
359         return 0;
360 }
361
362
363 //
364 // Undefine an equated register
365 //
366 int d_equrundef(void)
367 {
368         SYM * regname;
369
370         // Check that we are in a RISC section
371         if (!rgpu && !rdsp)
372                 return error(".equrundef/.regundef must be defined in .gpu/.dsp section");
373
374         while (*tok != EOL)
375         {
376                 // Skip preceeding or seperating commas (if any)
377                 if (*tok == ',')
378                         tok++;
379
380                 // Check we are dealing with a symbol
381                 if (*tok != SYMBOL)
382                         return error("syntax error; expected symbol");
383
384                 // Lookup and undef if equated register
385                 regname = lookup(string[tok[1]], LABEL, 0);
386
387                 if (regname && (regname->sattre & EQUATEDREG))
388                 {
389                         // Reset the attributes of this symbol...
390                         regname->sattr = 0;
391                         regname->sattre &= ~(EQUATEDREG | BANK_0 | BANK_1);
392                         regname->sattre |= UNDEF_EQUR;
393                 }
394
395                 // Skip over symbol token and address
396                 tok += 2;
397         }
398
399         return 0;
400 }
401
402
403 //
404 // Do not allow use of the CLR.L opcode
405 //
406 int d_noclear(void)
407 {
408         warn("CLR.L opcode ignored...");
409         return 0;
410 }
411
412
413 //
414 // Include binary file
415 //
416 int d_incbin(void)
417 {
418         int fd;
419         int bytes = 0;
420         long pos, size, bytesRead;
421         char msg[256];
422         char buf1[256];
423         int i;
424
425         // Check to see if we're in BSS, and, if so, throw an error
426         if (scattr & SBSS)
427         {
428                 errors("cannot include binary file \"%s\" in BSS section", string[tok[1]]);
429                 return ERROR;
430         }
431
432         if (*tok != STRING)
433         {
434                 error("syntax error; string missing");
435                 return ERROR;
436         }
437
438         // Attempt to open the include file in the current directory, then (if that
439         // failed) try list of include files passed in the enviroment string or by
440         // the "-d" option.
441         if ((fd = open(string[tok[1]], _OPEN_INC)) < 0)
442         {
443                 for(i=0; nthpath("RMACPATH", i, buf1)!=0; i++)
444                 {
445                         fd = strlen(buf1);
446
447                         // Append path char if necessary
448                         if (fd > 0 && buf1[fd - 1] != SLASHCHAR)
449                                 strcat(buf1, SLASHSTRING);
450
451                         strcat(buf1, string[tok[1]]);
452
453                         if ((fd = open(buf1, _OPEN_INC)) >= 0)
454                                 goto allright;
455                 }
456
457                 return errors("cannot open: \"%s\"", string[tok[1]]);
458         }
459
460 allright:
461
462         size = lseek(fd, 0L, SEEK_END);
463         pos = lseek(fd, 0L, SEEK_SET);
464         chcheck(size);
465
466         DEBUG { printf("INCBIN: File '%s' is %li bytes.\n", string[tok[1]], size); }
467
468         char * fileBuffer = (char *)malloc(size);
469         bytesRead = read(fd, fileBuffer, size);
470
471         if (bytesRead != size)
472         {
473                 sprintf(msg, "was only able to read %li bytes from binary file (%s, %li bytes)", bytesRead, string[tok[1]], size);
474                 error(msg);
475                 return ERROR;
476         }
477
478         memcpy(chptr, fileBuffer, size);
479         chptr += size;
480         sloc += size;
481         ch_size += size;
482
483         if (orgactive)
484                 orgaddr += size;
485
486         free(fileBuffer);
487         close(fd);
488         return 0;
489 }
490
491
492 //
493 // Set RISC register banks
494 //
495 int d_regbank0(void)
496 {
497         // Set active register bank zero
498         regbank = BANK_0;
499         return 0;
500 }
501
502
503 int d_regbank1(void)
504 {
505         // Set active register bank one
506         regbank = BANK_1;
507         return 0;
508 }
509
510
511 //
512 // Helper function, to cut down on mistakes & typing
513 //
514 static inline void SkipBytes(unsigned bytesToSkip)
515 {
516         if (!bytesToSkip)
517                 return;
518
519         if ((scattr & SBSS) == 0)
520         {
521                 chcheck(bytesToSkip);
522                 D_ZEROFILL(bytesToSkip);
523         }
524         else
525         {
526                 sloc += bytesToSkip;
527
528                 if (orgactive)
529                         orgaddr += bytesToSkip;
530         }
531 }
532
533
534 //
535 // Adjust location to an EVEN value
536 //
537 int d_even(void)
538 {
539         if (m6502)
540                 return error(in_6502mode);
541
542         unsigned skip = (rgpu || rdsp ? orgaddr : sloc) & 0x01;
543
544         if (skip)
545         {
546                 if ((scattr & SBSS) == 0)
547                 {
548                         chcheck(1);
549                         D_byte(0);
550                 }
551                 else
552                 {
553                         sloc++;
554
555                         if (orgactive)
556                                 orgaddr++;
557                 }
558         }
559
560         return 0;
561 }
562
563
564 //
565 // Adjust location to a LONG value
566 //
567 int d_long(void)
568 {
569         unsigned lower2Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x03;
570         unsigned bytesToSkip = (0x04 - lower2Bits) & 0x03;
571         SkipBytes(bytesToSkip);
572
573         return 0;
574 }
575
576
577 //
578 // Adjust location to a PHRASE value
579 //
580 // N.B.: We have to handle the GPU/DSP cases separately because you can embed
581 //       RISC code in the middle of a regular 68K section. Also note that all
582 //       of the alignment pseudo-ops will have to be fixed this way.
583 //
584 // This *must* behave differently when in a RISC section, as following sloc
585 // (instead of orgaddr) will fuck things up royally. Note that we do it this
586 // way because you can embed RISC code in a 68K section, and have the origin
587 // pointing to a different alignment in the RISC section than the 68K section.
588 //
589 int d_phrase(void)
590 {
591         unsigned lower3Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x07;
592         unsigned bytesToSkip = (0x08 - lower3Bits) & 0x07;
593         SkipBytes(bytesToSkip);
594
595         return 0;
596 }
597
598
599 //
600 // Adjust location to a DPHRASE value
601 //
602 int d_dphrase(void)
603 {
604         unsigned lower4Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x0F;
605         unsigned bytesToSkip = (0x10 - lower4Bits) & 0x0F;
606         SkipBytes(bytesToSkip);
607
608         return 0;
609 }
610
611
612 //
613 // Adjust location to a QPHRASE value
614 //
615 int d_qphrase(void)
616 {
617         unsigned lower5Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x1F;
618         unsigned bytesToSkip = (0x20 - lower5Bits) & 0x1F;
619         SkipBytes(bytesToSkip);
620
621         return 0;
622 }
623
624
625 //
626 // Do auto-even.  This must be called ONLY if 'sloc' is odd.
627 //
628 // This is made hairy because, if there was a label on the line, we also have
629 // to adjust its value. This won't work with more than one label on the line,
630 // which is OK since multiple labels are only allowed in AS68 kludge mode, and
631 // the C compiler is VERY paranoid and uses ".even" whenever it can
632 //
633 // N.B.: This probably needs the same fixes as above...
634 //
635 void auto_even(void)
636 {
637         if (cursect != M6502)
638         {
639                 if (scattr & SBSS)
640                         sloc++;                         // Bump BSS section
641                 else
642                         D_byte(0);                      // Deposit 0.b in non-BSS
643
644                 if (lab_sym != NULL)    // Bump label if we have to
645                         lab_sym->svalue++;
646         }
647 }
648
649
650 //
651 // Unimplemened directive error
652 //
653 int d_unimpl(void)
654 {
655         return error("unimplemented directive");
656 }
657
658
659 //
660 // Return absolute (not TDB) and defined expression or return an error
661 //
662 int abs_expr(VALUE * a_eval)
663 {
664         WORD eattr;
665
666         if (expr(exprbuf, a_eval, &eattr, NULL) < 0)
667                 return ERROR;
668
669         if (!(eattr & DEFINED))
670                 return error(undef_error);
671
672         if (eattr & TDB)
673                 return error(rel_error);
674
675         return OK;
676 }
677
678
679 //
680 // Hand symbols in a symbol-list to a function (kind of like mapcar...)
681 //
682 int symlist(int(* func)())
683 {
684         const char * em = "symbol list syntax";
685
686         for(;;)
687         {
688                 if (*tok != SYMBOL)
689                         return error(em);
690
691                 if ((*func)(string[tok[1]]) != OK)
692                         break;
693
694                 tok += 2;
695
696                 if (*tok == EOL)
697                         break;
698
699                 if (*tok != ',')
700                         return error(em);
701
702                 tok++;
703         }
704
705         return 0;
706 }
707
708
709 //
710 // .include "filename"
711 //
712 int d_include(void)
713 {
714         int j;
715         int i;
716         char * fn;
717         char buf[128];
718         char buf1[128];
719
720         if (*tok == STRING)                     // Leave strings ALONE
721                 fn = string[*++tok];
722         else if (*tok == SYMBOL)        // Try to append ".s" to symbols
723         {
724                 strcpy(buf, string[*++tok]);
725                 fext(buf, ".s", 0);
726                 fn = &buf[0];
727         }
728         else                                            // Punt if no STRING or SYMBOL
729                 return error("missing filename");
730
731         // Make sure the user didn't try anything like:
732         // .include equates.s
733         if (*++tok != EOL)
734                 return error("extra stuff after filename -- enclose it in quotes");
735
736         // Attempt to open the include file in the current directory, then (if that
737         // failed) try list of include files passed in the enviroment string or by
738         // the "-i" option.
739         if ((j = open(fn, 0)) < 0)
740         {
741                 for(i=0; nthpath("RMACPATH", i, buf1)!=0; i++)
742                 {
743                         j = strlen(buf1);
744
745                         // Append path char if necessary
746                         if (j > 0 && buf1[j - 1] != SLASHCHAR)
747                                 strcat(buf1, SLASHSTRING);
748
749                         strcat(buf1, fn);
750
751                         if ((j = open(buf1, 0)) >= 0)
752                                 goto allright;
753                 }
754
755                 return errors("cannot open: \"%s\"", fn);
756         }
757
758 allright:
759         include(j, fn);
760         return 0;
761 }
762
763
764 //
765 // .assert expression [, expression...]
766 //
767 int d_assert(void)
768 {
769         WORD eattr;
770         VALUE eval;
771
772         for(; expr(exprbuf, &eval, &eattr, NULL)==OK; ++tok)
773         {
774                 if (!(eattr & DEFINED))
775                         return error("forward or undefined .assert");
776
777                 if (!eval)
778                         return error("assert failure");
779
780                 if (*tok != ',')
781                         break;
782         }
783
784         at_eol();
785         return 0;
786 }
787
788
789 //
790 // .globl symbol [, symbol] <<<cannot make local symbols global>>>
791 //
792 int globl1(char * p)
793 {
794         SYM * sy;
795
796         if (*p == '.')
797                 return error("cannot .globl local symbol");
798
799         if ((sy = lookup(p, LABEL, 0)) == NULL)
800         {
801                 sy = NewSymbol(p, LABEL, 0);
802                 sy->svalue = 0;
803                 sy->sattr = GLOBAL;
804 //printf("glob1: Making global symbol: attr=%04X, eattr=%08X, %s\n", sy->sattr, sy->sattre, sy->sname);
805         }
806         else
807                 sy->sattr |= GLOBAL;
808
809         return OK;
810 }
811
812
813 int d_globl(void)
814 {
815         if (m6502)
816                 return error(in_6502mode);
817
818         symlist(globl1);
819         return 0;
820 }
821
822
823 //
824 // .prgflags expression
825 //
826 int d_prgflags(void)
827 {
828         VALUE eval;
829
830         if (*tok == EOL)
831                 return error("PRGFLAGS requires value");
832         else if (abs_expr(&eval) == OK)
833         {
834                 PRGFLAGS=eval;
835                 return 0;
836         }
837         else
838         {
839                 return error("PRGFLAGS requires value");
840         }
841 }
842
843
844 //
845 // .abs [expression]
846 //
847 int d_abs(void)
848 {
849         VALUE eval;
850
851         if (m6502)
852                 return error(in_6502mode);
853
854         SaveSection();
855
856         if (*tok == EOL)
857                 eval = 0;
858         else if (abs_expr(&eval) != OK)
859                 return 0;
860
861         SwitchSection(ABS);
862         sloc = eval;
863         return 0;
864 }
865
866
867 //
868 // Switch segments
869 //
870 int d_text(void)
871 {
872         if (rgpu || rdsp)
873                 return error("directive forbidden in gpu/dsp mode");
874         else if (m6502)
875                 return error(in_6502mode);
876
877         if (cursect != TEXT)
878         {
879                 SaveSection();
880                 SwitchSection(TEXT);
881         }
882
883         return 0;
884 }
885
886
887 int d_data(void)
888 {
889         if (rgpu || rdsp)
890                 return error("directive forbidden in gpu/dsp mode");
891         else if (m6502)
892                 return error(in_6502mode);
893
894         if (cursect != DATA)
895         {
896                 SaveSection();
897                 SwitchSection(DATA);
898         }
899
900         return 0;
901 }
902
903
904 int d_bss(void)
905 {
906         if (rgpu || rdsp)
907                 return error("directive forbidden in gpu/dsp mode");
908         else if (m6502)
909                 return error(in_6502mode);
910
911         if (cursect != BSS)
912         {
913                 SaveSection();
914                 SwitchSection(BSS);
915         }
916
917         return 0;
918 }
919
920
921 //
922 // .ds[.size] expression
923 //
924 int d_ds(WORD siz)
925 {
926         DEBUG { printf("Directive: .ds.[size] = %u, sloc = $%X\n", siz, sloc); }
927
928         VALUE eval;
929
930         if (cursect != M6502)
931         {
932                 if ((siz != SIZB) && (sloc & 1))        // Automatic .even
933                         auto_even();
934         }
935
936         if (abs_expr(&eval) != OK)
937                 return 0;
938
939         // Check to see if the value being passed in is negative (who the hell does
940         // that?--nobody does; it's the code gremlins, or rum, that does it)
941         // N.B.: Since VALUE is of type uint32_t, if it goes negative, it will have
942         //       its high bit set.
943         if (eval & 0x80000000)
944                 return error("negative sizes not allowed");
945
946         // In non-TDB section (BSS, ABS and M6502) just advance the location
947         // counter appropriately. In TDB sections, deposit (possibly large) chunks
948         // of zeroed memory....
949         if ((scattr & SBSS) || cursect == M6502)
950         {
951                 listvalue(eval);
952                 eval *= siz;
953                 sloc += eval;
954
955                 if (cursect == M6502)
956                         chptr += eval;
957
958                 just_bss = 1;                                   // No data deposited (8-bit CPU mode)
959         }
960         else
961         {
962                 dep_block(eval, siz, (VALUE)0, (WORD)(DEFINED | ABS), NULL);
963         }
964
965         at_eol();
966         return 0;
967 }
968
969
970 //
971 // dc.b, dc.w / dc, dc.l, dc.i
972 //
973 int d_dc(WORD siz)
974 {
975         WORD eattr;
976         VALUE eval;
977         uint8_t * p;
978
979         if ((scattr & SBSS) != 0)
980                 return error("illegal initialization of section");
981
982         // Do an auto_even if it's not BYTE sized (hmm, should we be doing this???)
983         if (cursect != M6502 && (siz != SIZB) && (sloc & 1))
984                 auto_even();
985
986         // Check to see if we're trying to set LONGS on a non 32-bit aligned
987         // address in a GPU or DSP section, in their local RAM
988         if ((siz == SIZL) && (orgaddr & 0x03)
989                 && ((rgpu && (orgaddr >= 0xF03000) && (orgaddr <= 0xF03FFFF))
990                 || (rdsp && (orgaddr >= 0xF1B000) && (orgaddr <= 0xF1CFFFF))))
991                 warn("depositing LONGs on a non-long address in local RAM");
992
993         for(;; tok++)
994         {
995                 // dc.b 'string' [,] ...
996                 if (siz == SIZB && (*tok == STRING || *tok == STRINGA8) && (tok[2] == ',' || tok[2] == EOL))
997                 {
998                         uint32_t i = strlen(string[tok[1]]);
999
1000                         if ((challoc - ch_size) < i)
1001                                 chcheck(i);
1002
1003                         if (*tok == STRING)
1004                         {
1005                                 for(p=string[tok[1]]; *p!=EOS; p++)
1006                                         D_byte(*p);
1007                         }
1008                         else if(*tok == STRINGA8)
1009                         {
1010                                 for(p=string[tok[1]]; *p!=EOS; p++)
1011                                         D_byte(strtoa8[*p]);
1012                         }
1013                         else
1014                         {
1015                                 error("String format not supported... yet");
1016                         }
1017
1018                         tok += 2;
1019                         goto comma;
1020                 }
1021
1022                 int movei = 0; // MOVEI flag for dc.i
1023
1024                 if (*tok == DOTI)
1025                 {
1026                         movei = 1;
1027                         tok++;
1028                         siz = SIZL;
1029                 }
1030
1031                 // dc.x <expression>
1032                 SYM * esym = 0;
1033
1034                 if (expr(exprbuf, &eval, &eattr, &esym) != OK)
1035                         return 0;
1036
1037                 uint16_t tdb = eattr & TDB;
1038                 uint16_t defined = eattr & DEFINED;
1039
1040                 if ((challoc - ch_size) < 4)
1041                         chcheck(4);
1042
1043                 switch (siz)
1044                 {
1045                 case SIZB:
1046                         if (!defined)
1047                         {
1048                                 AddFixup(FU_BYTE | FU_SEXT, sloc, exprbuf);
1049                                 D_byte(0);
1050                         }
1051                         else
1052                         {
1053                                 if (tdb)
1054                                         return error("non-absolute byte value");
1055
1056                                 if (eval + 0x100 >= 0x200)
1057                                 {
1058                                         sprintf(buffer, "%s (value = $%X)", range_error, eval);
1059                                         return error(buffer);
1060                                 }
1061
1062                                 D_byte(eval);
1063                         }
1064
1065                         break;
1066                 case SIZW:
1067                 case SIZN:
1068                         if (!defined)
1069                         {
1070                                 AddFixup(FU_WORD | FU_SEXT, sloc, exprbuf);
1071                                 D_word(0);
1072                         }
1073                         else
1074                         {
1075                                 if (eval + 0x10000 >= 0x20000)
1076                                         return error(range_error);
1077
1078                                 if (tdb)
1079                                         MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
1080
1081                                 // Deposit 68000 or 6502 (byte-reversed) word
1082                                 if (cursect != M6502)
1083                                         D_word(eval)
1084                                 else
1085                                         D_rword(eval)
1086                         }
1087
1088                         break;
1089                 case SIZL:
1090                         if (m6502)
1091                                 return error(in_6502mode);
1092
1093                         if (!defined)
1094                         {
1095                                 if (movei)
1096                                         AddFixup(FU_LONG | FU_MOVEI, sloc, exprbuf);
1097                                 else
1098                                         AddFixup(FU_LONG, sloc, exprbuf);
1099
1100                                 D_long(0);
1101                         }
1102                         else
1103                         {
1104                                 if (tdb)
1105                                         MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
1106
1107                                 if (movei)
1108                                         eval = WORDSWAP32(eval);
1109
1110                                 D_long(eval);
1111                         }
1112                         break;
1113                 }
1114
1115 comma:
1116                 if (*tok != ',')
1117                         break;
1118         }
1119
1120         at_eol();
1121         return 0;
1122 }
1123
1124
1125 //
1126 // dcb[.siz] expr1,expr2 - Make 'expr1' copies of 'expr2'
1127 //
1128 int d_dcb(WORD siz)
1129 {
1130         VALUE evalc, eval;
1131         WORD eattr;
1132
1133         DEBUG { printf("dcb: section is %s%s%s (scattr=$%X)\n", (cursect & TEXT ? "TEXT" : ""), (cursect & DATA ? " DATA" : ""), (cursect & BSS ? "BSS" : ""), scattr); }
1134
1135         if ((scattr & SBSS) != 0)
1136                 return error("illegal initialization of section");
1137
1138         if (abs_expr(&evalc) != OK)
1139                 return 0;
1140
1141         if (*tok++ != ',')
1142                 return error("missing comma");
1143
1144         if (expr(exprbuf, &eval, &eattr, NULL) < 0)
1145                 return 0;
1146
1147         if (cursect != M6502 && (siz != SIZB) && (sloc & 1))
1148                 auto_even();
1149
1150         dep_block(evalc, siz, eval, eattr, exprbuf);
1151         return 0;
1152 }
1153
1154
1155 //
1156 // Generalized initialization directive
1157 //
1158 // .init[.siz] [#count,] expression [.size] , ...
1159 //
1160 // The size suffix on the ".init" directive becomes the default size of the
1161 // objects to deposit. If an item is preceeded with a sharp (immediate) sign
1162 // and an expression, it specifies a repeat count. The value to be deposited
1163 // may be followed by a size suffix, which overrides the default size.
1164 //
1165 int d_init(WORD def_siz)
1166 {
1167         VALUE count;
1168         VALUE eval;
1169         WORD eattr;
1170         WORD siz;
1171
1172         if ((scattr & SBSS) != 0)
1173                 return error(".init not permitted in BSS or ABS");
1174
1175         if (rgpu || rdsp)
1176                 return error("directive forbidden in gpu/dsp mode");
1177
1178         for(;;)
1179         {
1180                 // Get repeat count (defaults to 1)
1181                 if (*tok == '#')
1182                 {
1183                         ++tok;
1184
1185                         if (abs_expr(&count) != OK)
1186                                 return 0;
1187
1188                         if (*tok++ != ',')
1189                                 return error(comma_error);
1190                 }
1191                 else
1192                         count = 1;
1193
1194                 // Evaluate expression to deposit
1195                 if (expr(exprbuf, &eval, &eattr, NULL) < 0)
1196                         return 0;
1197
1198                 switch ((int)*tok++)
1199                 {                                 // Determine size of object to deposit
1200                 case DOTB: siz = SIZB; break;
1201                 case DOTW: siz = SIZB; break;
1202                 case DOTL: siz = SIZL; break;
1203                 default:
1204                         siz = def_siz;
1205                         tok--;
1206                         break;
1207                 }
1208
1209                 dep_block(count, siz, eval, eattr, exprbuf);
1210
1211                 switch ((int)*tok)
1212                 {
1213                 case EOL:
1214                         return 0;
1215                 case ',':
1216                         tok++;
1217                         continue;
1218                 default:
1219                         return error(comma_error);
1220                 }
1221         }
1222 }
1223
1224
1225 //
1226 // Deposit 'count' values of size 'siz' in the current (non-BSS) segment
1227 //
1228 int dep_block(VALUE count, WORD siz, VALUE eval, WORD eattr, TOKEN * exprbuf)
1229 {
1230         WORD tdb;
1231         WORD defined;
1232
1233         tdb = (WORD)(eattr & TDB);
1234         defined = (WORD)(eattr & DEFINED);
1235
1236         while (count--)
1237         {
1238                 if ((challoc - ch_size) < 4)
1239                         chcheck(4L);
1240
1241                 switch(siz)
1242                 {
1243                 case SIZB:
1244                         if (!defined)
1245                         {
1246                                 AddFixup(FU_BYTE | FU_SEXT, sloc, exprbuf);
1247                                 D_byte(0);
1248                         }
1249                         else
1250                         {
1251                                 if (tdb)
1252                                         return error("non-absolute byte value");
1253
1254                                 if (eval + 0x100 >= 0x200)
1255                                         return error(range_error);
1256
1257                                 D_byte(eval);
1258                         }
1259
1260                         break;
1261                 case SIZW:
1262                 case SIZN:
1263                         if (!defined)
1264                         {
1265                                 AddFixup(FU_WORD | FU_SEXT, sloc, exprbuf);
1266                                 D_word(0);
1267                         }
1268                         else
1269                         {
1270                                 if (tdb)
1271                                         MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
1272
1273                                 if (eval + 0x10000 >= 0x20000)
1274                                         return error(range_error);
1275
1276                                 // Deposit 68000 or 6502 (byte-reversed) word
1277                                 if (cursect != M6502)
1278                                         D_word(eval)
1279                                 else
1280                                         D_rword(eval)
1281
1282                         }
1283
1284                         break;
1285                 case SIZL:
1286                         if (m6502)
1287                                 return error(in_6502mode);
1288
1289                         if (!defined)
1290                         {
1291                                 AddFixup(FU_LONG, sloc, exprbuf);
1292                                 D_long(0);
1293                         }
1294                         else
1295                         {
1296                                 if (tdb)
1297                                         MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
1298
1299                                 D_long(eval);
1300                         }
1301
1302                         break;
1303                 }
1304         }
1305
1306         return 0;
1307 }
1308
1309
1310 //
1311 // .comm symbol, size
1312 //
1313 int d_comm(void)
1314 {
1315         SYM * sym;
1316         char * p;
1317         VALUE eval;
1318
1319         if (m6502)
1320                 return error(in_6502mode);
1321
1322         if (*tok != SYMBOL)
1323                 return error("missing symbol");
1324
1325         p = string[tok[1]];
1326         tok += 2;
1327
1328         if (*p == '.')                                                  // Cannot .comm a local symbol
1329                 return error(locgl_error);
1330
1331         if ((sym = lookup(p, LABEL, 0)) == NULL)
1332                 sym = NewSymbol(p, LABEL, 0);
1333         else
1334         {
1335                 if (sym->sattr & DEFINED)
1336                         return error(".comm symbol already defined");
1337         }
1338
1339         sym->sattr = GLOBAL | COMMON | BSS;
1340
1341         if (*tok++ != ',')
1342                 return error(comma_error);
1343
1344         if (abs_expr(&eval) != OK)                              // Parse size of common region
1345                 return 0;
1346
1347         sym->svalue = eval;                                             // Install common symbol's size
1348         at_eol();
1349         return 0;
1350 }
1351
1352
1353 //
1354 // .list - Turn listing on
1355 //
1356 int d_list(void)
1357 {
1358         if (list_flag)
1359                 listing++;
1360
1361         return 0;
1362 }
1363
1364
1365 //
1366 // .nlist - Turn listing off
1367 //
1368 int d_nlist(void)
1369 {
1370         if (list_flag)
1371                 listing--;
1372
1373         return 0;
1374 }
1375
1376
1377 //
1378 // .68000 - Back to 68000 TEXT segment
1379 //
1380 int d_68000(void)
1381 {
1382         rgpu = rdsp = 0;
1383         // Switching from gpu/dsp sections should reset any ORG'd Address
1384         orgactive = 0;
1385         orgwarning = 0;
1386         SaveSection();
1387         SwitchSection(TEXT);
1388         activecpu=CPU_68000;
1389         return 0;
1390 }
1391
1392 //
1393 // .68020 - Back to 68000 TEXT segment and select 68020
1394 //
1395 int d_68020(void)
1396 {
1397         d_68000();
1398         activecpu=CPU_68020;
1399         return 0;
1400 }
1401
1402 //
1403 // .68030 - Back to 68000 TEXT segment and select 68030
1404 //
1405 int d_68030(void)
1406 {
1407         d_68000();
1408         activecpu=CPU_68030;
1409         return 0;
1410 }
1411
1412 //
1413 // .68040 - Back to 68000 TEXT segment and select 68040
1414 //
1415 int d_68040(void)
1416 {
1417         d_68000();
1418         activecpu=CPU_68040;
1419         activefpu=FPU_68040;
1420         return 0;
1421 }
1422
1423 //
1424 // .68060 - Back to 68000 TEXT segment and select 68060
1425 //
1426 int d_68060(void)
1427 {
1428         d_68000();
1429         activecpu=CPU_68060;
1430         activefpu=FPU_68040;
1431         return 0;
1432 }
1433
1434 //
1435 // .68881 - Back to 68000 TEXT segment and select 68881 FPU
1436 //
1437 int d_68881(void)
1438 {
1439         d_68000();
1440         activefpu=FPU_68881;
1441         return 0;
1442 }
1443
1444 //
1445 // .68882 - Back to 68000 TEXT segment and select 68882 FPU
1446 //
1447 int d_68882(void)
1448 {
1449         d_68000();
1450         activefpu=FPU_68881;
1451         return 0;
1452 }
1453
1454 //
1455 // nofpu - Deselect FPUs.
1456 //
1457 int d_nofpu(void)
1458 {
1459         activefpu=FPU_NONE;
1460         return 0;
1461 }
1462
1463 //
1464 // DSP56001
1465 //
1466 int d_56001(void)
1467 {
1468         return error("Not yet, child. Be patient.");
1469 }
1470
1471 //
1472 // .gpu - Switch to GPU assembler
1473 //
1474 int d_gpu(void)
1475 {
1476         if ((cursect != TEXT) && (cursect != DATA))
1477         {
1478                 error(".gpu can only be used in the TEXT or DATA segments");
1479                 return ERROR;
1480         }
1481
1482         // If previous section was dsp or 68000 then we need to reset ORG'd Addresses
1483         if (!rgpu)
1484         {
1485 //printf("Resetting ORG...\n");
1486                 orgactive = 0;
1487                 orgwarning = 0;
1488         }
1489 //else printf("NOT resetting ORG!\n");
1490
1491         rgpu = 1;                       // Set GPU assembly
1492         rdsp = 0;                       // Unset DSP assembly
1493         regbank = BANK_N;       // Set no default register bank
1494         return 0;
1495 }
1496
1497
1498 //
1499 // .dsp - Switch to DSP assembler
1500 //
1501 int d_dsp(void)
1502 {
1503         if ((cursect != TEXT) && (cursect != DATA))
1504         {
1505                 error(".dsp can only be used in the TEXT or DATA segments");
1506                 return ERROR;
1507         }
1508
1509         // If previous section was gpu or 68000 then we need to reset ORG'd Addresses
1510         if (!rdsp)
1511         {
1512                 orgactive = 0;
1513                 orgwarning = 0;
1514         }
1515
1516         rdsp = 1;                       // Set DSP assembly
1517         rgpu = 0;                       // Unset GPU assembly
1518         regbank = BANK_N;       // Set no default register bank
1519         return 0;
1520 }
1521
1522
1523 //
1524 // .cargs [#offset], symbol[.size], ...
1525 //
1526 // Lists of registers may also be mentioned; they just take up space. Good for
1527 // "documentation" purposes:
1528 //
1529 // .cargs a6, .arg1, .arg2, .arg3...
1530 //
1531 // Symbols thus created are ABS and EQUATED.
1532 //
1533 int d_cargs(void)
1534 {
1535         VALUE eval = 4;         // Default to 4 if no offset specified (to account for
1536                                                 // return address)
1537         WORD rlist;
1538         SYM * symbol;
1539         char * p;
1540         int env;
1541         int i;
1542
1543         if (rgpu || rdsp)
1544                 return error("directive forbidden in gpu/dsp mode");
1545
1546         if (*tok == '#')
1547         {
1548                 tok++;
1549
1550                 if (abs_expr(&eval) != OK)
1551                         return 0;
1552
1553                 // Eat the comma, if it's there
1554                 if (*tok == ',')
1555                         tok++;
1556         }
1557
1558         for(;;)
1559         {
1560                 if (*tok == SYMBOL)
1561                 {
1562                         p = string[tok[1]];
1563
1564                         // Set env to either local (dot prefixed) or global scope
1565                         env = (*p == '.' ? curenv : 0);
1566                         symbol = lookup(p, LABEL, env);
1567
1568                         if (symbol == NULL)
1569                         {
1570                                 symbol = NewSymbol(p, LABEL, env);
1571                                 symbol->sattr = 0;
1572                         }
1573                         else if (symbol->sattr & DEFINED)
1574                                 return errors("multiply-defined label '%s'", p);
1575
1576                         // Put symbol in "order of definition" list
1577                         AddToSymbolDeclarationList(symbol);
1578
1579                         symbol->sattr |= (ABS | DEFINED | EQUATED);
1580                         symbol->svalue = eval;
1581                         tok += 2;
1582
1583                         // What this does is eat any dot suffixes attached to a symbol. If
1584                         // it's a .L, it adds 4 to eval; if it's .W or .B, it adds 2. If
1585                         // there is no dot suffix, it assumes a size of 2.
1586                         switch ((int)*tok)
1587                         {
1588                         case DOTL:
1589                                 eval += 2;
1590                         case DOTB:
1591                         case DOTW:
1592                                 tok++;
1593                         }
1594
1595                         eval += 2;
1596                 }
1597                 else if (*tok >= KW_D0 && *tok <= KW_A7)
1598                 {
1599                         if (reglist(&rlist) < 0)
1600                                 return 0;
1601
1602                         for(i=0; i<16; i++, rlist>>=1)
1603                         {
1604                                 if (rlist & 1)
1605                                         eval += 4;
1606                         }
1607                 }
1608                 else
1609                 {
1610                         switch ((int)*tok)
1611                         {
1612                         case KW_USP:
1613                         case KW_SSP:
1614                         case KW_PC:
1615                                 eval += 2;
1616                                 // FALLTHROUGH
1617                         case KW_SR:
1618                         case KW_CCR:
1619                                 eval += 2;
1620                                 tok++;
1621                                 break;
1622                         case EOL:
1623                                 return 0;
1624                         default:
1625                                 return error(".cargs syntax");
1626                         }
1627                 }
1628
1629                 // Eat commas in between each argument, if they exist
1630                 if (*tok == ',')
1631                         tok++;
1632         }
1633 }
1634
1635
1636 //
1637 // .cstruct [#offset], symbol[.size], ...
1638 //
1639 // Lists of registers may also be mentioned; they just take up space. Good for
1640 // "documentation" purposes:
1641 //
1642 // .cstruct a6, .arg1, .arg2, .arg3...
1643 //
1644 // Symbols thus created are ABS and EQUATED. Note that this is for
1645 // compatibility with VBCC and the Remover's library. Thanks to GroovyBee for
1646 // the suggestion.
1647 //
1648 int d_cstruct(void)
1649 {
1650         VALUE eval = 0;         // Default, if no offset specified, is zero
1651         WORD rlist;
1652         SYM * symbol;
1653         char * symbolName;
1654         int env;
1655         int i;
1656
1657         if (rgpu || rdsp)
1658                 return error("directive forbidden in gpu/dsp mode");
1659
1660         if (*tok == '#')
1661         {
1662                 tok++;
1663
1664                 if (abs_expr(&eval) != OK)
1665                         return 0;
1666
1667                 // Eat the comma, if it's there
1668                 if (*tok == ',')
1669                         tok++;
1670         }
1671
1672         for(;;)
1673         {
1674                 if (*tok == SYMBOL)
1675                 {
1676                         symbolName = string[tok[1]];
1677
1678                         // Set env to either local (dot prefixed) or global scope
1679                         env = (symbolName[0] == '.' ? curenv : 0);
1680                         symbol = lookup(symbolName, LABEL, env);
1681
1682                         // If the symbol wasn't found, then define it. Otherwise, throw an
1683                         // error.
1684                         if (symbol == NULL)
1685                         {
1686                                 symbol = NewSymbol(symbolName, LABEL, env);
1687                                 symbol->sattr = 0;
1688                         }
1689                         else if (symbol->sattr & DEFINED)
1690                                 return errors("multiply-defined label '%s'", symbolName);
1691
1692                         // Put symbol in "order of definition" list
1693                         AddToSymbolDeclarationList(symbol);
1694
1695                         tok += 2;
1696
1697                         // Adjust label start address if it's a word or a long, as a byte
1698                         // label might have left us on an odd address.
1699                         switch ((int)*tok)
1700                         {
1701                         case DOTW:
1702                         case DOTL:
1703                                 eval += eval & 0x01;
1704                         }
1705
1706                         symbol->sattr |= (ABS | DEFINED | EQUATED);
1707                         symbol->svalue = eval;
1708
1709                         // Check for dot suffixes and adjust space accordingly (longs and
1710                         // words on an odd boundary get bumped to the next word aligned
1711                         // address). If no suffix, then throw an error.
1712                         switch ((int)*tok)
1713                         {
1714                         case DOTL:
1715                                 eval += 4;
1716                                 break;
1717                         case DOTW:
1718                                 eval += 2;
1719                                 break;
1720                         case DOTB:
1721                                 eval += 1;
1722                                 break;
1723                         default:
1724                                 return error("Symbol missing dot suffix in .cstruct construct");
1725                         }
1726
1727                         tok++;
1728                 }
1729                 else if (*tok >= KW_D0 && *tok <= KW_A7)
1730                 {
1731                         if (reglist(&rlist) < 0)
1732                                 return 0;
1733
1734                         for(i=0; i<16; i++, rlist>>=1)
1735                         {
1736                                 if (rlist & 1)
1737                                         eval += 4;
1738                         }
1739                 }
1740                 else
1741                 {
1742                         switch ((int)*tok)
1743                         {
1744                         case KW_USP:
1745                         case KW_SSP:
1746                         case KW_PC:
1747                                 eval += 2;
1748                                 // FALLTHROUGH
1749                         case KW_SR:
1750                         case KW_CCR:
1751                                 eval += 2;
1752                                 tok++;
1753                                 break;
1754                         case EOL:
1755                                 return 0;
1756                         default:
1757                                 return error(".cstruct syntax");
1758                         }
1759                 }
1760
1761                 // Eat commas in between each argument, if they exist
1762                 if (*tok == ',')
1763                         tok++;
1764         }
1765 }
1766
1767
1768 //
1769 // Undefine a macro - .undefmac macname [, macname...]
1770 //
1771 int undmac1(char * p)
1772 {
1773         SYM * symbol = lookup(p, MACRO, 0);
1774
1775         // If the macro symbol exists, cause it to disappear
1776         if (symbol != NULL)
1777                 symbol->stype = (BYTE)SY_UNDEF;
1778
1779         return OK;
1780 }
1781
1782
1783 int d_undmac(void)
1784 {
1785         symlist(undmac1);
1786         return 0;
1787 }
1788
1789
1790 int d_jpad(void)
1791 {
1792         warn("JPAD directive is deprecated/non-functional");
1793         return OK;
1794 }
1795
1796
1797 int d_nojpad(void)
1798 {
1799         warn("NOJPAD directive is deprecated/non-functional");
1800         return OK;
1801 }
1802
1803
1804 int d_gpumain(void)
1805 {
1806         return error("What the hell? Do you think we adhere to the Goof standard?");
1807 }
1808
1809
1810 //
1811 // .opt - turn a specific (or all) optimisation on or off
1812 //
1813 int d_opt(void)
1814 {
1815         while (*tok != EOL)
1816         {
1817                 if (*tok == STRING)
1818                 {
1819                         tok++;
1820                         char * tmpstr = string[*tok++];
1821
1822                         if (ParseOptimization(tmpstr) != OK)
1823                         {
1824                                 char temperr[256];
1825                                 sprintf(temperr, "unknown optimization flag '%s'", tmpstr);
1826                                 return error(temperr);
1827                         }
1828                 }
1829                 else
1830                         return error(".opt directive needs every switch enclosed inside quotation marks");
1831         }
1832
1833         return OK;
1834 }
1835