]> Shamusworld >> Repos - rmac/blob - direct.c
c9a82d938714730471728f4868820e47ace156c0
[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 assembly");
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 buf1[256];
432         int i;
433
434         // Check to see if we're in BSS, and, if so, throw an error
435         if (scattr & SBSS)
436         {
437                 error("cannot include binary file \"%s\" in BSS section", string[tok[1]]);
438                 return ERROR;
439         }
440
441         if (*tok != STRING)
442         {
443                 error("syntax error; string missing");
444                 return ERROR;
445         }
446
447         // Attempt to open the include file in the current directory, then (if that
448         // failed) try list of include files passed in the enviroment string or by
449         // the "-d" option.
450         if ((fd = open(string[tok[1]], _OPEN_INC)) < 0)
451         {
452                 for(i=0; nthpath("RMACPATH", i, buf1)!=0; i++)
453                 {
454                         fd = strlen(buf1);
455
456                         // Append path char if necessary
457                         if (fd > 0 && buf1[fd - 1] != SLASHCHAR)
458                                 strcat(buf1, SLASHSTRING);
459
460                         strcat(buf1, string[tok[1]]);
461
462                         if ((fd = open(buf1, _OPEN_INC)) >= 0)
463                                 goto allright;
464                 }
465
466                 return error("cannot open: \"%s\"", string[tok[1]]);
467         }
468
469 allright:
470
471         size = lseek(fd, 0L, SEEK_END);
472         pos = lseek(fd, 0L, SEEK_SET);
473         chcheck(size);
474
475         DEBUG { printf("INCBIN: File '%s' is %li bytes.\n", string[tok[1]], size); }
476
477         char * fileBuffer = (char *)malloc(size);
478         bytesRead = read(fd, fileBuffer, size);
479
480         if (bytesRead != size)
481         {
482                 error("was only able to read %li bytes from binary file (%s, %li bytes)", bytesRead, string[tok[1]], size);
483                 return ERROR;
484         }
485
486         memcpy(chptr, fileBuffer, size);
487         chptr += size;
488         sloc += size;
489         ch_size += size;
490
491         if (orgactive)
492                 orgaddr += size;
493
494         free(fileBuffer);
495         close(fd);
496         return 0;
497 }
498
499
500 //
501 // Set RISC register banks
502 //
503 int d_regbank0(void)
504 {
505         // Set active register bank zero
506         regbank = BANK_0;
507         return 0;
508 }
509
510
511 int d_regbank1(void)
512 {
513         // Set active register bank one
514         regbank = BANK_1;
515         return 0;
516 }
517
518
519 //
520 // Helper function, to cut down on mistakes & typing
521 //
522 static inline void SkipBytes(unsigned bytesToSkip)
523 {
524         if (!bytesToSkip)
525                 return;
526
527         if ((scattr & SBSS) == 0)
528         {
529                 chcheck(bytesToSkip);
530                 D_ZEROFILL(bytesToSkip);
531         }
532         else
533         {
534                 sloc += bytesToSkip;
535
536                 if (orgactive)
537                         orgaddr += bytesToSkip;
538         }
539 }
540
541
542 //
543 // Adjust location to an EVEN value
544 //
545 int d_even(void)
546 {
547         if (m6502)
548                 return error(in_6502mode);
549
550         unsigned skip = (rgpu || rdsp ? orgaddr : sloc) & 0x01;
551
552         if (skip)
553         {
554                 if ((scattr & SBSS) == 0)
555                 {
556                         chcheck(1);
557                         D_byte(0);
558                 }
559                 else
560                 {
561                         sloc++;
562
563                         if (orgactive)
564                                 orgaddr++;
565                 }
566         }
567
568         return 0;
569 }
570
571
572 //
573 // Adjust location to a LONG value
574 //
575 int d_long(void)
576 {
577         unsigned lower2Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x03;
578         unsigned bytesToSkip = (0x04 - lower2Bits) & 0x03;
579         SkipBytes(bytesToSkip);
580
581         return 0;
582 }
583
584
585 //
586 // Adjust location to a PHRASE value
587 //
588 // N.B.: We have to handle the GPU/DSP cases separately because you can embed
589 //       RISC code in the middle of a regular 68K section. Also note that all
590 //       of the alignment pseudo-ops will have to be fixed this way.
591 //
592 // This *must* behave differently when in a RISC section, as following sloc
593 // (instead of orgaddr) will fuck things up royally. Note that we do it this
594 // way because you can embed RISC code in a 68K section, and have the origin
595 // pointing to a different alignment in the RISC section than the 68K section.
596 //
597 int d_phrase(void)
598 {
599         unsigned lower3Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x07;
600         unsigned bytesToSkip = (0x08 - lower3Bits) & 0x07;
601         SkipBytes(bytesToSkip);
602
603         return 0;
604 }
605
606
607 //
608 // Adjust location to a DPHRASE value
609 //
610 int d_dphrase(void)
611 {
612         unsigned lower4Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x0F;
613         unsigned bytesToSkip = (0x10 - lower4Bits) & 0x0F;
614         SkipBytes(bytesToSkip);
615
616         return 0;
617 }
618
619
620 //
621 // Adjust location to a QPHRASE value
622 //
623 int d_qphrase(void)
624 {
625         unsigned lower5Bits = (rgpu || rdsp ? orgaddr : sloc) & 0x1F;
626         unsigned bytesToSkip = (0x20 - lower5Bits) & 0x1F;
627         SkipBytes(bytesToSkip);
628
629         return 0;
630 }
631
632
633 //
634 // Do auto-even.  This must be called ONLY if 'sloc' is odd.
635 //
636 // This is made hairy because, if there was a label on the line, we also have
637 // to adjust its value. This won't work with more than one label on the line,
638 // which is OK since multiple labels are only allowed in AS68 kludge mode, and
639 // the C compiler is VERY paranoid and uses ".even" whenever it can
640 //
641 // N.B.: This probably needs the same fixes as above...
642 //
643 void auto_even(void)
644 {
645         if (cursect != M6502)
646         {
647                 if (scattr & SBSS)
648                         sloc++;                         // Bump BSS section
649                 else
650                         D_byte(0);                      // Deposit 0.b in non-BSS
651
652                 if (lab_sym != NULL)    // Bump label if we have to
653                         lab_sym->svalue++;
654         }
655 }
656
657
658 //
659 // Unimplemened directive error
660 //
661 int d_unimpl(void)
662 {
663         return error("unimplemented directive");
664 }
665
666
667 //
668 // Return absolute (not TDB) and defined expression or return an error
669 //
670 int abs_expr(VALUE * a_eval)
671 {
672         WORD eattr;
673
674         if (expr(exprbuf, a_eval, &eattr, NULL) < 0)
675                 return ERROR;
676
677         if (!(eattr & DEFINED))
678                 return error(undef_error);
679
680         if (eattr & TDB)
681                 return error(rel_error);
682
683         return OK;
684 }
685
686
687 //
688 // Hand symbols in a symbol-list to a function (kind of like mapcar...)
689 //
690 int symlist(int(* func)())
691 {
692         const char * em = "symbol list syntax";
693
694         for(;;)
695         {
696                 if (*tok != SYMBOL)
697                         return error(em);
698
699                 if ((*func)(string[tok[1]]) != OK)
700                         break;
701
702                 tok += 2;
703
704                 if (*tok == EOL)
705                         break;
706
707                 if (*tok != ',')
708                         return error(em);
709
710                 tok++;
711         }
712
713         return 0;
714 }
715
716
717 //
718 // .include "filename"
719 //
720 int d_include(void)
721 {
722         int j;
723         int i;
724         char * fn;
725         char buf[128];
726         char buf1[128];
727
728         if (*tok == STRING)                     // Leave strings ALONE
729                 fn = string[*++tok];
730         else if (*tok == SYMBOL)        // Try to append ".s" to symbols
731         {
732                 strcpy(buf, string[*++tok]);
733                 fext(buf, ".s", 0);
734                 fn = &buf[0];
735         }
736         else                                            // Punt if no STRING or SYMBOL
737                 return error("missing filename");
738
739         // Make sure the user didn't try anything like:
740         // .include equates.s
741         if (*++tok != EOL)
742                 return error("extra stuff after filename--enclose it in quotes");
743
744         // Attempt to open the include file in the current directory, then (if that
745         // failed) try list of include files passed in the enviroment string or by
746         // the "-i" option.
747         if ((j = open(fn, 0)) < 0)
748         {
749                 for(i=0; nthpath("RMACPATH", i, buf1)!=0; i++)
750                 {
751                         j = strlen(buf1);
752
753                         // Append path char if necessary
754                         if (j > 0 && buf1[j - 1] != SLASHCHAR)
755                                 strcat(buf1, SLASHSTRING);
756
757                         strcat(buf1, fn);
758
759                         if ((j = open(buf1, 0)) >= 0)
760                                 goto allright;
761                 }
762
763                 return error("cannot open: \"%s\"", fn);
764         }
765
766 allright:
767         include(j, fn);
768         return 0;
769 }
770
771
772 //
773 // .assert expression [, expression...]
774 //
775 int d_assert(void)
776 {
777         WORD eattr;
778         VALUE eval;
779
780         for(; expr(exprbuf, &eval, &eattr, NULL)==OK; ++tok)
781         {
782                 if (!(eattr & DEFINED))
783                         return error("forward or undefined .assert");
784
785                 if (!eval)
786                         return error("assert failure");
787
788                 if (*tok != ',')
789                         break;
790         }
791
792         at_eol();
793         return 0;
794 }
795
796
797 //
798 // .globl symbol [, symbol] <<<cannot make local symbols global>>>
799 //
800 int globl1(char * p)
801 {
802         SYM * sy;
803
804         if (*p == '.')
805                 return error("cannot .globl local symbol");
806
807         if ((sy = lookup(p, LABEL, 0)) == NULL)
808         {
809                 sy = NewSymbol(p, LABEL, 0);
810                 sy->svalue = 0;
811                 sy->sattr = GLOBAL;
812 //printf("glob1: Making global symbol: attr=%04X, eattr=%08X, %s\n", sy->sattr, sy->sattre, sy->sname);
813         }
814         else
815                 sy->sattr |= GLOBAL;
816
817         return OK;
818 }
819
820
821 int d_globl(void)
822 {
823         if (m6502)
824                 return error(in_6502mode);
825
826         symlist(globl1);
827         return 0;
828 }
829
830
831 //
832 // .prgflags expression
833 //
834 int d_prgflags(void)
835 {
836         VALUE eval;
837
838         if (*tok == EOL)
839                 return error("PRGFLAGS requires value");
840         else if (abs_expr(&eval) == OK)
841         {
842                 PRGFLAGS=eval;
843                 return 0;
844         }
845         else
846         {
847                 return error("PRGFLAGS requires value");
848         }
849 }
850
851
852 //
853 // .abs [expression]
854 //
855 int d_abs(void)
856 {
857         VALUE eval;
858
859         if (m6502)
860                 return error(in_6502mode);
861
862         SaveSection();
863
864         if (*tok == EOL)
865                 eval = 0;
866         else if (abs_expr(&eval) != OK)
867                 return 0;
868
869         SwitchSection(ABS);
870         sloc = eval;
871         return 0;
872 }
873
874
875 //
876 // Switch segments
877 //
878 int d_text(void)
879 {
880         if (rgpu || rdsp)
881                 return error("directive forbidden in gpu/dsp mode");
882         else if (m6502)
883                 return error(in_6502mode);
884
885         if (cursect != TEXT)
886         {
887                 SaveSection();
888                 SwitchSection(TEXT);
889         }
890
891         return 0;
892 }
893
894
895 int d_data(void)
896 {
897         if (rgpu || rdsp)
898                 return error("directive forbidden in gpu/dsp mode");
899         else if (m6502)
900                 return error(in_6502mode);
901
902         if (cursect != DATA)
903         {
904                 SaveSection();
905                 SwitchSection(DATA);
906         }
907
908         return 0;
909 }
910
911
912 int d_bss(void)
913 {
914         if (rgpu || rdsp)
915                 return error("directive forbidden in gpu/dsp mode");
916         else if (m6502)
917                 return error(in_6502mode);
918
919         if (cursect != BSS)
920         {
921                 SaveSection();
922                 SwitchSection(BSS);
923         }
924
925         return 0;
926 }
927
928
929 //
930 // .ds[.size] expression
931 //
932 int d_ds(WORD siz)
933 {
934         DEBUG { printf("Directive: .ds.[size] = %u, sloc = $%X\n", siz, sloc); }
935
936         VALUE eval;
937
938         if (cursect != M6502)
939         {
940                 if ((siz != SIZB) && (sloc & 1))        // Automatic .even
941                         auto_even();
942         }
943
944         if (abs_expr(&eval) != OK)
945                 return 0;
946
947         // Check to see if the value being passed in is negative (who the hell does
948         // that?--nobody does; it's the code gremlins, or rum, that does it)
949         // N.B.: Since VALUE is of type uint32_t, if it goes negative, it will have
950         //       its high bit set.
951         if (eval & 0x80000000)
952                 return error("negative sizes not allowed");
953
954         // In non-TDB section (BSS, ABS and M6502) just advance the location
955         // counter appropriately. In TDB sections, deposit (possibly large) chunks
956         // of zeroed memory....
957         if ((scattr & SBSS) || cursect == M6502)
958         {
959                 listvalue(eval);
960                 eval *= siz;
961                 sloc += eval;
962
963                 if (cursect == M6502)
964                         chptr += eval;
965
966                 just_bss = 1;                                   // No data deposited (8-bit CPU mode)
967         }
968         else
969         {
970                 dep_block(eval, siz, (VALUE)0, (WORD)(DEFINED | ABS), NULL);
971         }
972
973         at_eol();
974         return 0;
975 }
976
977
978 //
979 // dc.b, dc.w / dc, dc.l, dc.i
980 //
981 int d_dc(WORD siz)
982 {
983         WORD eattr;
984         VALUE eval;
985         uint8_t * p;
986
987         if ((scattr & SBSS) != 0)
988                 return error("illegal initialization of section");
989
990         // Do an auto_even if it's not BYTE sized (hmm, should we be doing this???)
991         if (cursect != M6502 && (siz != SIZB) && (sloc & 1))
992                 auto_even();
993
994         // Check to see if we're trying to set LONGS on a non 32-bit aligned
995         // address in a GPU or DSP section, in their local RAM
996         if ((siz == SIZL) && (orgaddr & 0x03)
997                 && ((rgpu && (orgaddr >= 0xF03000) && (orgaddr <= 0xF03FFFF))
998                 || (rdsp && (orgaddr >= 0xF1B000) && (orgaddr <= 0xF1CFFFF))))
999                 warn("depositing LONGs on a non-long address in local RAM");
1000
1001         for(;; tok++)
1002         {
1003                 // dc.b 'string' [,] ...
1004                 if (siz == SIZB && (*tok == STRING || *tok == STRINGA8) && (tok[2] == ',' || tok[2] == EOL))
1005                 {
1006                         uint32_t i = strlen(string[tok[1]]);
1007
1008                         if ((challoc - ch_size) < i)
1009                                 chcheck(i);
1010
1011                         if (*tok == STRING)
1012                         {
1013                                 for(p=string[tok[1]]; *p!=EOS; p++)
1014                                         D_byte(*p);
1015                         }
1016                         else if(*tok == STRINGA8)
1017                         {
1018                                 for(p=string[tok[1]]; *p!=EOS; p++)
1019                                         D_byte(strtoa8[*p]);
1020                         }
1021                         else
1022                         {
1023                                 error("String format not supported... yet");
1024                         }
1025
1026                         tok += 2;
1027                         goto comma;
1028                 }
1029
1030                 int movei = 0; // MOVEI flag for dc.i
1031
1032                 if (*tok == DOTI)
1033                 {
1034                         movei = 1;
1035                         tok++;
1036                         siz = SIZL;
1037                 }
1038
1039                 // dc.x <expression>
1040                 SYM * esym = 0;
1041
1042                 if (expr(exprbuf, &eval, &eattr, &esym) != OK)
1043                         return 0;
1044
1045                 uint16_t tdb = eattr & TDB;
1046                 uint16_t defined = eattr & DEFINED;
1047
1048                 if ((challoc - ch_size) < 4)
1049                         chcheck(4);
1050
1051                 switch (siz)
1052                 {
1053                 case SIZB:
1054                         if (!defined)
1055                         {
1056                                 AddFixup(FU_BYTE | FU_SEXT, sloc, exprbuf);
1057                                 D_byte(0);
1058                         }
1059                         else
1060                         {
1061                                 if (tdb)
1062                                         return error("non-absolute byte value");
1063
1064                                 if (eval + 0x100 >= 0x200)
1065                                         return error("%s (value = $%X)", range_error, eval);
1066
1067                                 D_byte(eval);
1068                         }
1069
1070                         break;
1071                 case SIZW:
1072                 case SIZN:
1073                         if (!defined)
1074                         {
1075                                 AddFixup(FU_WORD | FU_SEXT, sloc, exprbuf);
1076                                 D_word(0);
1077                         }
1078                         else
1079                         {
1080                                 if (eval + 0x10000 >= 0x20000)
1081                                         return error(range_error);
1082
1083                                 if (tdb)
1084                                         MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
1085
1086                                 // Deposit 68000 or 6502 (byte-reversed) word
1087                                 if (cursect != M6502)
1088                                         D_word(eval)
1089                                 else
1090                                         D_rword(eval)
1091                         }
1092
1093                         break;
1094                 case SIZL:
1095                         if (m6502)
1096                                 return error(in_6502mode);
1097
1098                         if (!defined)
1099                         {
1100                                 if (movei)
1101                                         AddFixup(FU_LONG | FU_MOVEI, sloc, exprbuf);
1102                                 else
1103                                         AddFixup(FU_LONG, sloc, exprbuf);
1104
1105                                 D_long(0);
1106                         }
1107                         else
1108                         {
1109                                 if (tdb)
1110                                         MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
1111
1112                                 if (movei)
1113                                         eval = WORDSWAP32(eval);
1114
1115                                 D_long(eval);
1116                         }
1117                         break;
1118                 }
1119
1120 comma:
1121                 if (*tok != ',')
1122                         break;
1123         }
1124
1125         at_eol();
1126         return 0;
1127 }
1128
1129
1130 //
1131 // dcb[.siz] expr1,expr2 - Make 'expr1' copies of 'expr2'
1132 //
1133 int d_dcb(WORD siz)
1134 {
1135         VALUE evalc, eval;
1136         WORD eattr;
1137
1138         DEBUG { printf("dcb: section is %s%s%s (scattr=$%X)\n", (cursect & TEXT ? "TEXT" : ""), (cursect & DATA ? " DATA" : ""), (cursect & BSS ? "BSS" : ""), scattr); }
1139
1140         if ((scattr & SBSS) != 0)
1141                 return error("illegal initialization of section");
1142
1143         if (abs_expr(&evalc) != OK)
1144                 return 0;
1145
1146         if (*tok++ != ',')
1147                 return error("missing comma");
1148
1149         if (expr(exprbuf, &eval, &eattr, NULL) < 0)
1150                 return 0;
1151
1152         if (cursect != M6502 && (siz != SIZB) && (sloc & 1))
1153                 auto_even();
1154
1155         dep_block(evalc, siz, eval, eattr, exprbuf);
1156         return 0;
1157 }
1158
1159
1160 //
1161 // Generalized initialization directive
1162 //
1163 // .init[.siz] [#count,] expression [.size] , ...
1164 //
1165 // The size suffix on the ".init" directive becomes the default size of the
1166 // objects to deposit. If an item is preceeded with a sharp (immediate) sign
1167 // and an expression, it specifies a repeat count. The value to be deposited
1168 // may be followed by a size suffix, which overrides the default size.
1169 //
1170 int d_init(WORD def_siz)
1171 {
1172         VALUE count;
1173         VALUE eval;
1174         WORD eattr;
1175         WORD siz;
1176
1177         if ((scattr & SBSS) != 0)
1178                 return error(".init not permitted in BSS or ABS");
1179
1180         if (rgpu || rdsp)
1181                 return error("directive forbidden in gpu/dsp mode");
1182
1183         for(;;)
1184         {
1185                 // Get repeat count (defaults to 1)
1186                 if (*tok == '#')
1187                 {
1188                         ++tok;
1189
1190                         if (abs_expr(&count) != OK)
1191                                 return 0;
1192
1193                         if (*tok++ != ',')
1194                                 return error(comma_error);
1195                 }
1196                 else
1197                         count = 1;
1198
1199                 // Evaluate expression to deposit
1200                 if (expr(exprbuf, &eval, &eattr, NULL) < 0)
1201                         return 0;
1202
1203                 switch ((int)*tok++)
1204                 {                                 // Determine size of object to deposit
1205                 case DOTB: siz = SIZB; break;
1206                 case DOTW: siz = SIZB; break;
1207                 case DOTL: siz = SIZL; break;
1208                 default:
1209                         siz = def_siz;
1210                         tok--;
1211                         break;
1212                 }
1213
1214                 dep_block(count, siz, eval, eattr, exprbuf);
1215
1216                 switch ((int)*tok)
1217                 {
1218                 case EOL:
1219                         return 0;
1220                 case ',':
1221                         tok++;
1222                         continue;
1223                 default:
1224                         return error(comma_error);
1225                 }
1226         }
1227 }
1228
1229
1230 //
1231 // Deposit 'count' values of size 'siz' in the current (non-BSS) segment
1232 //
1233 int dep_block(VALUE count, WORD siz, VALUE eval, WORD eattr, TOKEN * exprbuf)
1234 {
1235         WORD tdb;
1236         WORD defined;
1237
1238         tdb = (WORD)(eattr & TDB);
1239         defined = (WORD)(eattr & DEFINED);
1240
1241         while (count--)
1242         {
1243                 if ((challoc - ch_size) < 4)
1244                         chcheck(4L);
1245
1246                 switch(siz)
1247                 {
1248                 case SIZB:
1249                         if (!defined)
1250                         {
1251                                 AddFixup(FU_BYTE | FU_SEXT, sloc, exprbuf);
1252                                 D_byte(0);
1253                         }
1254                         else
1255                         {
1256                                 if (tdb)
1257                                         return error("non-absolute byte value");
1258
1259                                 if (eval + 0x100 >= 0x200)
1260                                         return error(range_error);
1261
1262                                 D_byte(eval);
1263                         }
1264
1265                         break;
1266                 case SIZW:
1267                 case SIZN:
1268                         if (!defined)
1269                         {
1270                                 AddFixup(FU_WORD | FU_SEXT, sloc, exprbuf);
1271                                 D_word(0);
1272                         }
1273                         else
1274                         {
1275                                 if (tdb)
1276                                         MarkRelocatable(cursect, sloc, tdb, MWORD, NULL);
1277
1278                                 if (eval + 0x10000 >= 0x20000)
1279                                         return error(range_error);
1280
1281                                 // Deposit 68000 or 6502 (byte-reversed) word
1282                                 if (cursect != M6502)
1283                                         D_word(eval)
1284                                 else
1285                                         D_rword(eval)
1286
1287                         }
1288
1289                         break;
1290                 case SIZL:
1291                         if (m6502)
1292                                 return error(in_6502mode);
1293
1294                         if (!defined)
1295                         {
1296                                 AddFixup(FU_LONG, sloc, exprbuf);
1297                                 D_long(0);
1298                         }
1299                         else
1300                         {
1301                                 if (tdb)
1302                                         MarkRelocatable(cursect, sloc, tdb, MLONG, NULL);
1303
1304                                 D_long(eval);
1305                         }
1306
1307                         break;
1308                 }
1309         }
1310
1311         return 0;
1312 }
1313
1314
1315 //
1316 // .comm symbol, size
1317 //
1318 int d_comm(void)
1319 {
1320         SYM * sym;
1321         char * p;
1322         VALUE eval;
1323
1324         if (m6502)
1325                 return error(in_6502mode);
1326
1327         if (*tok != SYMBOL)
1328                 return error("missing symbol");
1329
1330         p = string[tok[1]];
1331         tok += 2;
1332
1333         if (*p == '.')                                                  // Cannot .comm a local symbol
1334                 return error(locgl_error);
1335
1336         if ((sym = lookup(p, LABEL, 0)) == NULL)
1337                 sym = NewSymbol(p, LABEL, 0);
1338         else
1339         {
1340                 if (sym->sattr & DEFINED)
1341                         return error(".comm symbol already defined");
1342         }
1343
1344         sym->sattr = GLOBAL | COMMON | BSS;
1345
1346         if (*tok++ != ',')
1347                 return error(comma_error);
1348
1349         if (abs_expr(&eval) != OK)                              // Parse size of common region
1350                 return 0;
1351
1352         sym->svalue = eval;                                             // Install common symbol's size
1353         at_eol();
1354         return 0;
1355 }
1356
1357
1358 //
1359 // .list - Turn listing on
1360 //
1361 int d_list(void)
1362 {
1363         if (list_flag)
1364                 listing++;
1365
1366         return 0;
1367 }
1368
1369
1370 //
1371 // .nlist - Turn listing off
1372 //
1373 int d_nlist(void)
1374 {
1375         if (list_flag)
1376                 listing--;
1377
1378         return 0;
1379 }
1380
1381
1382 //
1383 // .68000 - Back to 68000 TEXT segment
1384 //
1385 int d_68000(void)
1386 {
1387         rgpu = rdsp = 0;
1388         // Switching from gpu/dsp sections should reset any ORG'd Address
1389         orgactive = 0;
1390         orgwarning = 0;
1391         SaveSection();
1392         SwitchSection(TEXT);
1393         activecpu = CPU_68000;
1394         return 0;
1395 }
1396
1397
1398 //
1399 // .68020 - Back to 68000 TEXT segment and select 68020
1400 //
1401 int d_68020(void)
1402 {
1403         d_68000();
1404         activecpu = CPU_68020;
1405         return 0;
1406 }
1407
1408
1409 //
1410 // .68030 - Back to 68000 TEXT segment and select 68030
1411 //
1412 int d_68030(void)
1413 {
1414         d_68000();
1415         activecpu = CPU_68030;
1416         return 0;
1417 }
1418
1419
1420 //
1421 // .68040 - Back to 68000 TEXT segment and select 68040
1422 //
1423 int d_68040(void)
1424 {
1425         d_68000();
1426         activecpu = CPU_68040;
1427         activefpu = FPU_68040;
1428         return 0;
1429 }
1430
1431
1432 //
1433 // .68060 - Back to 68000 TEXT segment and select 68060
1434 //
1435 int d_68060(void)
1436 {
1437         d_68000();
1438         activecpu = CPU_68060;
1439         activefpu = FPU_68040;
1440         return 0;
1441 }
1442
1443
1444 //
1445 // .68881 - Back to 68000 TEXT segment and select 68881 FPU
1446 //
1447 int d_68881(void)
1448 {
1449         d_68000();
1450         activefpu = FPU_68881;
1451         return 0;
1452 }
1453
1454
1455 //
1456 // .68882 - Back to 68000 TEXT segment and select 68882 FPU
1457 //
1458 int d_68882(void)
1459 {
1460         d_68000();
1461         activefpu = FPU_68881;
1462         return 0;
1463 }
1464
1465
1466 //
1467 // nofpu - Deselect FPUs.
1468 //
1469 int d_nofpu(void)
1470 {
1471         activefpu = FPU_NONE;
1472         return 0;
1473 }
1474
1475
1476 //
1477 // DSP56001
1478 //
1479 int d_56001(void)
1480 {
1481         return error("Not yet, child. Be patient.");
1482 }
1483
1484
1485 //
1486 // .gpu - Switch to GPU assembler
1487 //
1488 int d_gpu(void)
1489 {
1490         if ((cursect != TEXT) && (cursect != DATA))
1491         {
1492                 error(".gpu can only be used in the TEXT or DATA segments");
1493                 return ERROR;
1494         }
1495
1496         // If previous section was dsp or 68000 then we need to reset ORG'd Addresses
1497         if (!rgpu)
1498         {
1499 //printf("Resetting ORG...\n");
1500                 orgactive = 0;
1501                 orgwarning = 0;
1502         }
1503 //else printf("NOT resetting ORG!\n");
1504
1505         rgpu = 1;                       // Set GPU assembly
1506         rdsp = 0;                       // Unset DSP assembly
1507         regbank = BANK_N;       // Set no default register bank
1508         return 0;
1509 }
1510
1511
1512 //
1513 // .dsp - Switch to DSP assembler
1514 //
1515 int d_dsp(void)
1516 {
1517         if ((cursect != TEXT) && (cursect != DATA))
1518         {
1519                 error(".dsp can only be used in the TEXT or DATA segments");
1520                 return ERROR;
1521         }
1522
1523         // If previous section was gpu or 68000 then we need to reset ORG'd Addresses
1524         if (!rdsp)
1525         {
1526                 orgactive = 0;
1527                 orgwarning = 0;
1528         }
1529
1530         rdsp = 1;                       // Set DSP assembly
1531         rgpu = 0;                       // Unset GPU assembly
1532         regbank = BANK_N;       // Set no default register bank
1533         return 0;
1534 }
1535
1536
1537 //
1538 // .cargs [#offset], symbol[.size], ...
1539 //
1540 // Lists of registers may also be mentioned; they just take up space. Good for
1541 // "documentation" purposes:
1542 //
1543 // .cargs a6, .arg1, .arg2, .arg3...
1544 //
1545 // Symbols thus created are ABS and EQUATED.
1546 //
1547 int d_cargs(void)
1548 {
1549         VALUE eval = 4;         // Default to 4 if no offset specified (to account for
1550                                                 // return address)
1551         WORD rlist;
1552         SYM * symbol;
1553         char * p;
1554         int env;
1555         int i;
1556
1557         if (rgpu || rdsp)
1558                 return error("directive forbidden in gpu/dsp mode");
1559
1560         if (*tok == '#')
1561         {
1562                 tok++;
1563
1564                 if (abs_expr(&eval) != OK)
1565                         return 0;
1566
1567                 // Eat the comma, if it's there
1568                 if (*tok == ',')
1569                         tok++;
1570         }
1571
1572         for(;;)
1573         {
1574                 if (*tok == SYMBOL)
1575                 {
1576                         p = string[tok[1]];
1577
1578                         // Set env to either local (dot prefixed) or global scope
1579                         env = (*p == '.' ? curenv : 0);
1580                         symbol = lookup(p, LABEL, env);
1581
1582                         if (symbol == NULL)
1583                         {
1584                                 symbol = NewSymbol(p, LABEL, env);
1585                                 symbol->sattr = 0;
1586                         }
1587                         else if (symbol->sattr & DEFINED)
1588                                 return error("multiply-defined label '%s'", p);
1589
1590                         // Put symbol in "order of definition" list
1591                         AddToSymbolDeclarationList(symbol);
1592
1593                         symbol->sattr |= (ABS | DEFINED | EQUATED);
1594                         symbol->svalue = eval;
1595                         tok += 2;
1596
1597                         // What this does is eat any dot suffixes attached to a symbol. If
1598                         // it's a .L, it adds 4 to eval; if it's .W or .B, it adds 2. If
1599                         // there is no dot suffix, it assumes a size of 2.
1600                         switch ((int)*tok)
1601                         {
1602                         case DOTL:
1603                                 eval += 2;
1604                         case DOTB:
1605                         case DOTW:
1606                                 tok++;
1607                         }
1608
1609                         eval += 2;
1610                 }
1611                 else if (*tok >= KW_D0 && *tok <= KW_A7)
1612                 {
1613                         if (reglist(&rlist) < 0)
1614                                 return 0;
1615
1616                         for(i=0; i<16; i++, rlist>>=1)
1617                         {
1618                                 if (rlist & 1)
1619                                         eval += 4;
1620                         }
1621                 }
1622                 else
1623                 {
1624                         switch ((int)*tok)
1625                         {
1626                         case KW_USP:
1627                         case KW_SSP:
1628                         case KW_PC:
1629                                 eval += 2;
1630                                 // FALLTHROUGH
1631                         case KW_SR:
1632                         case KW_CCR:
1633                                 eval += 2;
1634                                 tok++;
1635                                 break;
1636                         case EOL:
1637                                 return 0;
1638                         default:
1639                                 return error(".cargs syntax");
1640                         }
1641                 }
1642
1643                 // Eat commas in between each argument, if they exist
1644                 if (*tok == ',')
1645                         tok++;
1646         }
1647 }
1648
1649
1650 //
1651 // .cstruct [#offset], symbol[.size], ...
1652 //
1653 // Lists of registers may also be mentioned; they just take up space. Good for
1654 // "documentation" purposes:
1655 //
1656 // .cstruct a6, .arg1, .arg2, .arg3...
1657 //
1658 // Symbols thus created are ABS and EQUATED. Note that this is for
1659 // compatibility with VBCC and the Remover's library. Thanks to GroovyBee for
1660 // the suggestion.
1661 //
1662 int d_cstruct(void)
1663 {
1664         VALUE eval = 0;         // Default, if no offset specified, is zero
1665         WORD rlist;
1666         SYM * symbol;
1667         char * symbolName;
1668         int env;
1669         int i;
1670
1671         if (rgpu || rdsp)
1672                 return error("directive forbidden in gpu/dsp mode");
1673
1674         if (*tok == '#')
1675         {
1676                 tok++;
1677
1678                 if (abs_expr(&eval) != OK)
1679                         return 0;
1680
1681                 // Eat the comma, if it's there
1682                 if (*tok == ',')
1683                         tok++;
1684         }
1685
1686         for(;;)
1687         {
1688                 if (*tok == SYMBOL)
1689                 {
1690                         symbolName = string[tok[1]];
1691
1692                         // Set env to either local (dot prefixed) or global scope
1693                         env = (symbolName[0] == '.' ? curenv : 0);
1694                         symbol = lookup(symbolName, LABEL, env);
1695
1696                         // If the symbol wasn't found, then define it. Otherwise, throw an
1697                         // error.
1698                         if (symbol == NULL)
1699                         {
1700                                 symbol = NewSymbol(symbolName, LABEL, env);
1701                                 symbol->sattr = 0;
1702                         }
1703                         else if (symbol->sattr & DEFINED)
1704                                 return error("multiply-defined label '%s'", symbolName);
1705
1706                         // Put symbol in "order of definition" list
1707                         AddToSymbolDeclarationList(symbol);
1708
1709                         tok += 2;
1710
1711                         // Adjust label start address if it's a word or a long, as a byte
1712                         // label might have left us on an odd address.
1713                         switch ((int)*tok)
1714                         {
1715                         case DOTW:
1716                         case DOTL:
1717                                 eval += eval & 0x01;
1718                         }
1719
1720                         symbol->sattr |= (ABS | DEFINED | EQUATED);
1721                         symbol->svalue = eval;
1722
1723                         // Check for dot suffixes and adjust space accordingly (longs and
1724                         // words on an odd boundary get bumped to the next word aligned
1725                         // address). If no suffix, then throw an error.
1726                         switch ((int)*tok)
1727                         {
1728                         case DOTL:
1729                                 eval += 4;
1730                                 break;
1731                         case DOTW:
1732                                 eval += 2;
1733                                 break;
1734                         case DOTB:
1735                                 eval += 1;
1736                                 break;
1737                         default:
1738                                 return error("Symbol missing dot suffix in .cstruct construct");
1739                         }
1740
1741                         tok++;
1742                 }
1743                 else if (*tok >= KW_D0 && *tok <= KW_A7)
1744                 {
1745                         if (reglist(&rlist) < 0)
1746                                 return 0;
1747
1748                         for(i=0; i<16; i++, rlist>>=1)
1749                         {
1750                                 if (rlist & 1)
1751                                         eval += 4;
1752                         }
1753                 }
1754                 else
1755                 {
1756                         switch ((int)*tok)
1757                         {
1758                         case KW_USP:
1759                         case KW_SSP:
1760                         case KW_PC:
1761                                 eval += 2;
1762                                 // FALLTHROUGH
1763                         case KW_SR:
1764                         case KW_CCR:
1765                                 eval += 2;
1766                                 tok++;
1767                                 break;
1768                         case EOL:
1769                                 return 0;
1770                         default:
1771                                 return error(".cstruct syntax");
1772                         }
1773                 }
1774
1775                 // Eat commas in between each argument, if they exist
1776                 if (*tok == ',')
1777                         tok++;
1778         }
1779 }
1780
1781
1782 //
1783 // Undefine a macro - .undefmac macname [, macname...]
1784 //
1785 int undmac1(char * p)
1786 {
1787         SYM * symbol = lookup(p, MACRO, 0);
1788
1789         // If the macro symbol exists, cause it to disappear
1790         if (symbol != NULL)
1791                 symbol->stype = (BYTE)SY_UNDEF;
1792
1793         return OK;
1794 }
1795
1796
1797 int d_undmac(void)
1798 {
1799         symlist(undmac1);
1800         return 0;
1801 }
1802
1803
1804 int d_jpad(void)
1805 {
1806         warn("JPAD directive is deprecated/non-functional");
1807         return OK;
1808 }
1809
1810
1811 int d_nojpad(void)
1812 {
1813         warn("NOJPAD directive is deprecated/non-functional");
1814         return OK;
1815 }
1816
1817
1818 int d_gpumain(void)
1819 {
1820         return error("What the hell? Do you think we adhere to the Goof standard?");
1821 }
1822
1823
1824 //
1825 // .opt - turn a specific (or all) optimisation on or off
1826 //
1827 int d_opt(void)
1828 {
1829         while (*tok != EOL)
1830         {
1831                 if (*tok == STRING)
1832                 {
1833                         tok++;
1834                         char * tmpstr = string[*tok++];
1835
1836                         if (ParseOptimization(tmpstr) != OK)
1837                                 return error("unknown optimization flag '%s'", tmpstr);
1838                 }
1839                 else
1840                         return error(".opt directive needs every switch enclosed inside quotation marks");
1841         }
1842
1843         return OK;
1844 }
1845
1846
1847 //
1848 // .if, Start conditional assembly
1849 //
1850 int d_if(void)
1851 {
1852         WORD eattr;
1853         VALUE eval;
1854         SYM * esym;
1855         IFENT * rif = f_ifent;
1856
1857         // Alloc an IFENTRY
1858         if (rif == NULL)
1859                 rif = (IFENT *)malloc(sizeof(IFENT));
1860         else
1861                 f_ifent = rif->if_prev;
1862
1863         rif->if_prev = ifent;
1864         ifent = rif;
1865
1866         if (!disabled)
1867         {
1868                 if (expr(exprbuf, &eval, &eattr, &esym) != OK)
1869                         return 0;
1870
1871                 if ((eattr & DEFINED) == 0)
1872                         return error(undef_error);
1873
1874                 disabled = !eval;
1875         }
1876
1877         rif->if_state = (WORD)disabled;
1878         return 0;
1879 }
1880
1881
1882 //
1883 // .else, Do alternate case for .if
1884 //
1885 int d_else(void)
1886 {
1887         IFENT * rif = ifent;
1888
1889         if (rif->if_prev == NULL)
1890                 return error("mismatched .else");
1891
1892         if (disabled)
1893                 disabled = rif->if_prev->if_state;
1894         else
1895                 disabled = 1;
1896
1897         rif->if_state = (WORD)disabled;
1898         return 0;
1899 }
1900
1901
1902 //
1903 // .endif, End of conditional assembly block
1904 // This is also called by fpop() to pop levels of IFENTs in case a macro or
1905 // include file exits early with `exitm' or `end'.
1906 //
1907 int d_endif(void)
1908 {
1909         IFENT * rif = ifent;
1910
1911         if (rif->if_prev == NULL)
1912                 return error("mismatched .endif");
1913
1914         ifent = rif->if_prev;
1915         disabled = rif->if_prev->if_state;
1916         rif->if_prev = f_ifent;
1917         f_ifent = rif;
1918         return 0;
1919 }
1920