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