]> Shamusworld >> Repos - rmac/blob - procln.c
Extend incbin to incbin "filename" [,][size][,][offset]
[rmac] / procln.c
1 //
2 // RMAC - Reboot's Macro Assembler for all Atari computers
3 // PROCLN.C - Line Processing
4 // Copyright (C) 199x Landon Dyer, 2011-2020 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 "procln.h"
10 #include "6502.h"
11 #include "amode.h"
12 #include "direct.h"
13 #include "dsp56k_amode.h"
14 #include "dsp56k_mach.h"
15 #include "error.h"
16 #include "expr.h"
17 #include "listing.h"
18 #include "mach.h"
19 #include "macro.h"
20 #include "op.h"
21 #include "riscasm.h"
22 #include "sect.h"
23 #include "symbol.h"
24
25 #define DEF_KW                                  // Declare keyword values
26 #include "kwtab.h"                              // Incl generated keyword tables & defs
27
28 #define DEF_MN                                  // Incl 68k keyword definitions
29 #define DECL_MN                                 // Incl 68k keyword state machine tables
30 #include "mntab.h"
31
32 #define DEF_MR
33 #define DECL_MR
34 #include "risckw.h"
35
36 #define DEF_MP                                  // Include 6502 keyword definitions
37 #define DECL_MP                                 // Include 6502 keyword state machine tables
38 #include "6502kw.h"
39
40 #define DEF_MO                                  // Include OP keyword definitions
41 #define DECL_MO                                 // Include OP keyword state machine tables
42 #include "opkw.h"
43
44 #define DEF_DSP                                 // Include DSP56K keywords definitions
45 #define DECL_DSP                                // Include DSP56K keyword state machine tables
46 #include "dsp56kkw.h"
47
48
49 IFENT * ifent;                                  // Current ifent
50 static IFENT ifent0;                    // Root ifent
51 IFENT * f_ifent;                                // Freelist of ifents
52 int disabled;                                   // Assembly conditionally disabled
53 int just_bss;                                   // 1, ds.b in microprocessor mode
54 uint32_t pcloc;                                 // Value of "PC" at beginning of line
55 SYM * lab_sym;                                  // Label on line (or NULL)
56 char * label_defined;                   // The name of the last label defined in current line (if any)
57
58 const char extra_stuff[] = "extra (unexpected) text found after addressing mode";
59 const char comma_error[] = "missing comma";
60 const char syntax_error[] = "syntax error";
61 const char locgl_error[] = "cannot GLOBL local symbol";
62 const char lab_ignored[] = "label ignored";
63
64 // Table to convert an addressing-mode number to a bitmask.
65 LONG amsktab[0124] = {
66         M_DREG, M_DREG, M_DREG, M_DREG,
67         M_DREG, M_DREG, M_DREG, M_DREG,
68
69         M_AREG, M_AREG, M_AREG, M_AREG,
70         M_AREG, M_AREG, M_AREG, M_AREG,
71
72         M_AIND, M_AIND, M_AIND, M_AIND,
73         M_AIND, M_AIND, M_AIND, M_AIND,
74
75         M_APOSTINC, M_APOSTINC, M_APOSTINC, M_APOSTINC,
76         M_APOSTINC, M_APOSTINC, M_APOSTINC, M_APOSTINC,
77
78         M_APREDEC, M_APREDEC, M_APREDEC, M_APREDEC,
79         M_APREDEC, M_APREDEC, M_APREDEC, M_APREDEC,
80
81         M_ADISP, M_ADISP, M_ADISP, M_ADISP,
82         M_ADISP, M_ADISP, M_ADISP, M_ADISP,
83
84         M_AINDEXED, M_AINDEXED, M_AINDEXED, M_AINDEXED,
85         M_AINDEXED, M_AINDEXED, M_AINDEXED, M_AINDEXED,
86
87         M_ABSW,                 // 070
88         M_ABSL,                 // 071
89         M_PCDISP,               // 072
90         M_PCINDEXED,    // 073
91         M_IMMED,                // 074
92         0L,                             // 075
93         0L,                             // 076
94         0L,                             // 077
95         M_ABASE,                // 0100
96         M_MEMPOST,              // 0101
97         M_MEMPRE,               // 0102
98         M_PCBASE,               // 0103
99         M_PCMPOST,              // 0104
100         M_PCMPRE,               // 0105
101         M_AM_USP,               // 0106
102         M_AM_SR,                // 0107
103         M_AM_CCR,               // 0110
104         M_AM_NONE,              // 0111
105         0x30,                   // 0112
106         0x30,                   // 0113
107         0L,                             // 0114
108         0L,                             // 0115
109         0L,                             // 0116
110         0L,                             // 0117
111         M_CACHE40,              // 0120
112         M_CREG,                 // 0121
113         M_FREG,                 // 0122
114         M_FPSCR                 // 0123
115 };                                      // 0123 length
116
117
118 // Function prototypes
119 int HandleLabel(char *, int);
120
121
122 //
123 // Initialize line processor
124 //
125 void InitLineProcessor(void)
126 {
127         disabled = 0;
128         ifent = &ifent0;
129         f_ifent = ifent0.if_prev = NULL;
130         ifent0.if_state = 0;
131 }
132
133
134 //
135 // Line processor
136 //
137 void Assemble(void)
138 {
139         int state;                                      // Keyword machine state (output)
140         int j;                                          // Random int, must be fast
141         char * p;                                       // Random char ptr, must be fast
142         TOKEN * tk;                                     // First token in line
143         char * label;                           // Symbol (or NULL)
144         char * equate;                          // Symbol (or NULL)
145         int labtyp = 0;                         // Label type (':', DCOLON)
146         int equtyp = 0;                         // Equ type ('=', DEQUALS)
147         uint64_t eval;                          // Expression value
148         WORD eattr;                                     // Expression attributes
149         SYM * esym;                                     // External symbol involved in expr.
150         WORD siz = 0;                           // Size suffix to mnem/diretve/macro
151         LONG amsk0, amsk1;                      // Address-type masks for ea0, ea1
152         MNTAB * m;                                      // Code generation table pointer
153         SYM * sy, * sy2;                        // Symbol (temp usage)
154         char * opname = NULL;           // Name of dirctve/mnemonic/macro
155         int listflag;                           // 0: Don't call listeol()
156         WORD rmask;                                     // Register list, for REG
157         int registerbank;                       // RISC register bank
158         int riscreg;                            // RISC register
159         listflag = 0;                           // Initialise listing flag
160
161 loop:                                                   // Line processing loop label
162
163         // Get another line of tokens
164         if (TokenizeLine() == TKEOF)
165         {
166 DEBUG { printf("Assemble: Found TKEOF flag...\n"); }
167                 if (list_flag && listflag)                      // Flush last line of source
168                         listeol();
169
170                 if (ifent->if_prev != NULL)                     // Check conditional token
171                         error("hit EOF without finding matching .endif");
172
173                 return;
174         }
175
176         DEBUG { DumpTokenBuffer(); }
177
178         if (list_flag)
179         {
180                 if (listflag && listing > 0)
181                         listeol();                                              // Tell listing generator about EOL
182
183                 lstout((char)(disabled ? '-' : lntag)); // Prepare new line for listing
184                 listflag = 1;                                           // OK to call `listeol' now
185                 just_bss = 0;                                           // Reset just_bss mode
186         }
187
188         state = -3;                                                             // No keyword (just EOL)
189         label = NULL;                                                   // No label
190         label_defined = NULL;                                   // No label defined yet
191         lab_sym = NULL;                                                 // No (exported) label
192         equate = NULL;                                                  // No equate
193         tk = tok;                                                               // Save first token in line
194         pcloc = (uint32_t)sloc;                                 // Set beginning-of-line PC
195
196 loop1:                                                                          // Internal line processing loop
197
198         if (*tok == EOL)                                                // Restart loop if end-of-line
199                 goto loop;
200
201         // First token MUST be a symbol (Shamus: not sure why :-/)
202         if (*tok != SYMBOL)
203         {
204                 if ((*tok >= KW_D0) && (*tok <= KW_R31))
205                         error("cannot use reserved keyword as label name or .equ");
206                 else
207                         error("syntax error; expected symbol");
208
209                 goto loop;
210         }
211
212         j = (int)tok[2];                                                // Skip equates (normal statements)
213
214         if (j == '=' || j == DEQUALS || j == SET || j == REG || j == EQUREG || j == CCDEF)
215         {
216                 equate = string[tok[1]];
217                 equtyp = j;
218                 tok += 3;
219                 goto normal;
220         }
221
222         // Skip past label (but record it)
223         if (j == ':' || j == DCOLON)
224         {
225 as68label:
226                 label = string[tok[1]];                         // Get label name
227                 labtyp = tok[2];                                        // Get label type
228                 tok += 3;                                                       // Go to next line token
229
230                 // AS68 MODE:
231                 // Looks like another label follows the previous one, so handle
232                 // the previous one until there aren't any more
233                 if (as68_flag && (*tok == SYMBOL && tok[2] == ':'))
234                 {
235                         if (HandleLabel(label, labtyp) != 0)
236                                 goto loop;
237
238                         label_defined = label;
239
240                         goto as68label;
241                 }
242         }
243
244         // EOL is legal here...
245         if (*tok == EOL)
246                 goto normal;
247
248         // First token MUST be a symbol (if we get here, tok didn't advance)
249         if (*tok++ != SYMBOL)
250         {
251                 error("syntax error; expected symbol");
252                 goto loop;
253         }
254
255         opname = p = string[*tok++];
256
257         // Check to see if the SYMBOL is a keyword (a mnemonic or directive).
258         // On output, `state' will have one of the values:
259         //    -3          there was no symbol (EOL)
260         //    -2..-1      the symbol didn't match any keyword
261         //    0..499      vanilla directives (dc, ds, etc.)
262         //    500..999    electric directives (macro, rept, etc.)
263         //    1000..+     mnemonics (move, lsr, etc.)
264         for(state=0; state>=0;)
265         {
266                 j = mnbase[state] + (int)tolowertab[*p];
267
268                 // Reject, character doesn't match
269                 if (mncheck[j] != state)
270                 {
271                         state = -1;                                             // No match
272                         break;
273                 }
274
275                 // Must accept or reject at EOS
276                 if (!*++p)
277                 {
278                         state = mnaccept[j];                    // (-1 on no terminal match)
279                         break;
280                 }
281
282                 state = mntab[j];
283         }
284
285         // Check for ".b" ".w" ".l" after directive, macro or mnemonic.
286         siz = SIZN;
287
288         switch (*tok)
289         {
290         case DOTW: siz = SIZW, tok++; break;
291         case DOTL: siz = SIZL, tok++; break;
292         case DOTB: siz = SIZB, tok++; break;
293         case DOTD: siz = SIZD, tok++; break;
294         case DOTP: siz = SIZP, tok++; break;
295         case DOTQ: siz = SIZQ, tok++; break;
296         case DOTS: siz = SIZS, tok++; break;
297         case DOTX: siz = SIZX, tok++; break;
298         }
299
300         // Do special directives (500..999) (These must be handled in "real time")
301         if (state >= 500 && state < 1000)
302         {
303                 switch (state)
304                 {
305                 case MN_IF:
306                         d_if();
307                         goto loop;
308
309                 case MN_ELSE:
310                         d_else();
311                         goto loop;
312
313                 case MN_ENDIF:
314                         d_endif();
315                         goto loop;
316
317                 case MN_IIF:                                            // .iif --- immediate if
318                         if (disabled || expr(exprbuf, &eval, &eattr, &esym) != OK)
319                                 goto loop;
320
321                         if (!(eattr & DEFINED))
322                         {
323                                 error(undef_error);
324                                 goto loop;
325                         }
326
327                         if (*tok++ != ',')
328                         {
329                                 error(comma_error);
330                                 goto loop;
331                         }
332
333                         if (eval == 0)
334                                 goto loop;
335
336                         goto loop1;
337
338                 case MN_MACRO:                                          // .macro --- macro definition
339                         if (!disabled)
340                         {
341                                 // Label on a macro definition is bad mojo... Warn the user
342                                 if (label != NULL)
343                                         warn(lab_ignored);
344
345                                 DefineMacro();
346                         }
347
348                         goto loop;
349
350                 case MN_EXITM:                                          // .exitm --- exit macro
351                 case MN_ENDM:                                           // .endm --- same as .exitm
352                         if (!disabled)
353                         {
354                                 if (label != NULL)
355                                         warn(lab_ignored);
356
357                                 ExitMacro();
358                         }
359
360                         goto loop;
361
362                 case MN_REPT:
363                         if (!disabled)
364                         {
365                                 // Handle labels on REPT directive lines...
366                                 if (label)
367                                 {
368                                         if (HandleLabel(label, labtyp) != 0)
369                                                 goto loop;
370
371                                         label_defined = label;
372                                 }
373
374                                 HandleRept();
375                         }
376
377                         goto loop;
378
379                 case MN_ENDR:
380                         if (!disabled)
381                                 error("mis-nested .endr");
382
383                         goto loop;
384                 }
385         }
386
387 normal:
388         if (disabled)                                                   // Conditionally disabled code
389                 goto loop;
390
391         // Do equates
392         if (equate != NULL)
393         {
394                 // Pick global or local symbol enviroment
395                 j = (*equate == '.' ? curenv : 0);
396                 sy = lookup(equate, LABEL, j);
397
398                 if (sy == NULL)
399                 {
400                         sy = NewSymbol(equate, LABEL, j);
401                         sy->sattr = 0;
402
403                         if (equtyp == DEQUALS)
404                         {
405                                 // Can't GLOBAL a local symbol
406                                 if (j)
407                                 {
408                                         error(locgl_error);
409                                         goto loop;
410                                 }
411
412                                 sy->sattr = GLOBAL;
413                         }
414                 }
415                 else if ((sy->sattr & DEFINED) && equtyp != SET)
416                 {
417                         if ((equtyp == EQUREG) && (sy->sattre & UNDEF_EQUR))
418                         {
419                                 sy->sattre &= ~UNDEF_EQUR;
420                                 sy->svalue = 0;
421                         }
422                         else if ((equtyp == CCDEF) && (sy->sattre & UNDEF_CC))
423                         {
424                                 sy->sattre &= ~UNDEF_CC;
425                                 sy->svalue = 0;
426                         }
427                         else
428                         {
429                                 error("multiple equate to '%s'", sy->sname);
430                                 goto loop;
431                         }
432                 }
433
434                 // Put symbol in "order of definition" list if it's not already there
435                 AddToSymbolDeclarationList(sy);
436
437                 // Parse value to equate symbol to;
438                 // o  .equr
439                 // o  .reg
440                 // o  everything else
441                 if (equtyp == EQUREG)
442                 {
443 //Linko's request to issue a warning on labels that equated to the same
444 //register would go here. Not sure how to implement it though. :-/
445 /*
446 Maybe like this way:
447 have an array of bools with 64 entries. Whenever a register is equated, set the
448 corresponding register bool to true. Whenever it's undef'ed, set it to false.
449 When checking to see if it's already been equated, issue a warning.
450 */
451                         // Check that we are in a RISC section
452                         if (!rgpu && !rdsp)
453                         {
454                                 error(".equr/.regequ must be defined in .gpu/.dsp section");
455                                 goto loop;
456                         }
457
458                         // Check for register to equate to
459                         if ((*tok >= KW_R0) && (*tok <= KW_R31))
460                         {
461 //                              sy->sattre  = EQUATEDREG | RISCSYM;     // Mark as equated register
462                                 sy->sattre  = EQUATEDREG;       // Mark as equated register
463                                 riscreg = (*tok - KW_R0);
464 //is there any reason to do this, since we're putting this in svalue?
465 //i'm thinking, no. Let's test that out! :-D
466 //                              sy->sattre |= (riscreg << 8);           // Store register number
467 //everything seems to build fine without it... We'll leave it here Just In Case(tm)
468
469 #define DEBODGE_REGBANK
470 #ifdef DEBODGE_REGBANK
471                                 // Default is current state of "regbank"
472                                 registerbank = regbank;
473 #else
474                                 // Default is no register bank specified
475                                 registerbank = BANK_N;
476 #endif
477
478                                 // Check for ",<bank #>" override notation
479                                 if ((tok[1] == ',') && (tok[2] == CONST))
480                                 {
481                                         // Advance token pointer to the constant
482                                         tok += 3;
483
484                                         // Anything other than a 0 or a 1 will result in "No Bank"
485                                         if (*(uint64_t *)tok == 0)
486                                                 registerbank = BANK_0;
487                                         else if (*(uint64_t *)tok == 1)
488                                                 registerbank = BANK_1;
489
490                                         // Advance half-way through the 64-bit const.
491                                         // The code below, expecting a regular token,
492                                         // will advance past the second half.
493                                         tok++;
494                                 }
495
496 #ifdef DEBODGE_REGBANK
497                                 sy->sattre |= registerbank;     // Store register bank
498 #else
499 // What needs to happen here is to prime registerbank with regbank, then use
500 // registerbank down below for the bank marking.
501 #warning "!!! regbank <-> registerbank confusion here !!!"
502 // The question here is why, if we're allowed to override the ".regbankN" rules
503 // above, then why is it using the one set by the directive in the extended
504 // attributes and not in what ends up in symbol->svalue?
505 // ".regbankN" is not an original Madmac directive, so it's suspect
506                                 sy->sattre |= regbank;          // Store register bank
507 #endif
508                                 eattr = ABS | DEFINED | GLOBAL;
509                                 eval = riscreg;
510                                 tok++;
511                         }
512                         // Checking for a register symbol
513                         else if (tok[0] == SYMBOL)
514                         {
515                                 sy2 = lookup(string[tok[1]], LABEL, j);
516
517                                 // Make sure symbol is a valid equreg
518                                 if (!sy2 || !(sy2->sattre & EQUATEDREG))
519                                 {
520                                         error("invalid GPU/DSP .equr/.regequ definition");
521                                         goto loop;
522                                 }
523                                 else
524                                 {
525                                         eattr = ABS | DEFINED | GLOBAL; // Copy symbols attributes
526                                         sy->sattre = sy2->sattre;
527                                         eval = (sy2->svalue & 0xFFFFF0FF);
528                                         tok += 2;
529                                 }
530                         }
531                         else
532                         {
533                                 error("invalid GPU/DSP .equr/.regequ definition");
534                                 goto loop;
535                         }
536                 }
537                 else if (equtyp == REG)
538                 {
539                         if (reglist(&rmask) < 0)
540                                 goto loop;
541
542                         eval = (uint32_t)rmask;
543                         eattr = ABS | DEFINED;
544                 }
545                 else if (equtyp == CCDEF)
546                 {
547                         sy->sattre |= EQUATEDCC;
548                         eattr = ABS | DEFINED | GLOBAL;
549
550                         if (tok[0] == SYMBOL)
551                         {
552                                 sy2 = lookup(string[tok[1]], LABEL, j);
553
554                                 if (!sy2 || !(sy2->sattre & EQUATEDCC))
555                                 {
556                                         error("invalid gpu/dsp .ccdef definition");
557                                         goto loop;
558                                 }
559                                 else
560                                 {
561                                         eattr = ABS | DEFINED | GLOBAL;
562                                         sy->sattre = sy2->sattre;
563                                         eval = sy2->svalue;
564                                         tok += 2;
565                                 }
566                         }
567                         else if (expr(exprbuf, &eval, &eattr, &esym) != OK)
568                                 goto loop;
569                 }
570                 // equ an equr
571                 else if (*tok == SYMBOL)
572                 {
573                         sy2 = lookup(string[tok[1]], LABEL, j);
574
575                         if (sy2 && (sy2->sattre & EQUATEDREG))
576                         {
577                                 sy->stype = sy2->stype;
578                                 sy->sattr = sy2->sattr;
579                                 sy->sattre = sy2->sattre;
580                                 sy->svalue = sy2->svalue;
581                                 goto loop;
582                         }
583                         else if (expr(exprbuf, &eval, &eattr, &esym) != OK)
584                                 goto loop;
585                 }
586                 else if (expr(exprbuf, &eval, &eattr, &esym) != OK)
587                         goto loop;
588
589                 if (!(eattr & DEFINED))
590                 {
591                         error(undef_error);
592                         goto loop;
593                 }
594
595                 sy->sattr |= eattr | EQUATED;   // Symbol inherits value and attributes
596                 sy->svalue = eval;
597
598                 if (list_flag)                                  // Put value in listing
599                         listvalue((uint32_t)eval);
600
601                 ErrorIfNotAtEOL();                              // Must be at EOL now
602                 goto loop;
603         }
604
605         // Do labels
606         if (label != NULL)
607         {
608                 // Non-zero == error occurred
609                 if (HandleLabel(label, labtyp) != 0)
610                         goto loop;
611
612                 label_defined = label;
613         }
614
615         // Punt on EOL
616         if (state == -3)
617                 goto loop;
618
619         // If we're in 6502 mode and are still in need of a mnemonic, then search
620         // for valid 6502 mnemonic.
621         if (m6502 && (state < 0 || state >= 1000))
622         {
623 #ifdef ST
624                 state = kmatch(opname, mpbase, mpcheck, mptab, mpaccept);
625 #else
626                 for(state=0, p=opname; state>= 0; )
627                 {
628                         j = mpbase[state] + tolowertab[*p];
629
630                         if (mpcheck[j] != state)        // Reject, character doesn't match
631                         {
632                                 state = -1;             // No match
633                                 break;
634                         }
635
636                         if (!*++p)
637                         {                       // Must accept or reject at EOS
638                                 state = mpaccept[j];    // (-1 on no terminal match)
639                                 break;
640                         }
641
642                         state = mptab[j];
643                 }
644 #endif
645
646                 // Call 6502 code generator if we found a mnemonic
647                 if (state >= 2000)
648                 {
649                         m6502cg(state - 2000);
650                         goto loop;
651                 }
652         }
653
654         // If we are in GPU or DSP mode and still in need of a mnemonic then search
655         // for one
656         if ((rgpu || rdsp) && (state < 0 || state >= 1000))
657         {
658                 for(state=0, p=opname; state>=0;)
659                 {
660                         j = mrbase[state] + (int)tolowertab[*p];
661
662                         // Reject, character doesn't match
663                         if (mrcheck[j] != state)
664                         {
665                                 state = -1;                                     // No match
666                                 break;
667                         }
668
669                         // Must accept or reject at EOS
670                         if (!*++p)
671                         {
672                                 state = mraccept[j];            // (-1 on no terminal match)
673                                 break;
674                         }
675
676                         state = mrtab[j];
677                 }
678
679                 // Call RISC code generator if we found a mnemonic
680                 if (state >= 3000)
681                 {
682                         GenerateRISCCode(state);
683                         goto loop;
684                 }
685         }
686
687         // If we are in OP mode and still in need of a mnemonic then search for one
688         if (robjproc && ((state < 0) || (state >= 1000)))
689         {
690                 for(state=0, p=opname; state>=0;)
691                 {
692                         j = mobase[state] + (int)tolowertab[*p];
693
694                         // Reject, character doesn't match
695                         if (mocheck[j] != state)
696                         {
697                                 state = -1;                                     // No match
698                                 break;
699                         }
700
701                         // Must accept or reject at EOS
702                         if (!*++p)
703                         {
704                                 state = moaccept[j];            // (-1 on no terminal match)
705                                 break;
706                         }
707
708                         state = motab[j];
709                 }
710
711                 // Call OP code generator if we found a mnemonic
712                 if (state >= 3100)
713                 {
714                         GenerateOPCode(state);
715                         goto loop;
716                 }
717         }
718
719         // If we are in 56K mode and still in need of a mnemonic then search for one
720         if (dsp56001 && ((state < 0) || (state >= 1000)))
721         {
722                 for(state=0, p=opname; state>=0;)
723                 {
724                         j = dspbase[state] + (int)tolowertab[*p];
725
726                         // Reject, character doesn't match
727                         if (dspcheck[j] != state)
728                         {
729                                 state = -1;                                     // No match
730                                 break;
731                         }
732
733                         // Must accept or reject at EOS
734                         if (!*++p)
735                         {
736                                 state = dspaccept[j];           // (-1 on no terminal match)
737                                 break;
738                         }
739
740                         state = dsptab[j];
741                 }
742
743                 // Call DSP code generator if we found a mnemonic
744                 if (state >= 2000)
745                 {
746                         LONG parcode;
747                         int operands;
748                         MNTABDSP * md = &dsp56k_machtab[state - 2000];
749                         deposit_extra_ea = 0;   // Assume no extra word needed
750
751                         if (md->mnfunc == dsp_mult)
752                         {
753                                 // Special case for multiplication instructions: they require
754                                 // 3 operands
755                                 if ((operands = dsp_amode(3)) == ERROR)
756                                         goto loop;
757                         }
758                         else if ((md->mnattr & PARMOVE) && md->mn0 != M_AM_NONE)
759                         {
760                                 if (dsp_amode(2) == ERROR)
761                                         goto loop;
762                         }
763                         else if ((md->mnattr & PARMOVE) && md->mn0 == M_AM_NONE)
764                         {
765                                 // Instructions that have parallel moves but use no operands
766                                 // (probably only move). In this case, don't parse addressing
767                                 // modes--just go straight to parallel parse
768                                 dsp_am0 = dsp_am1 = M_AM_NONE;
769                         }
770                         else
771                         {
772                                 // Non parallel move instructions can have up to 4 parameters
773                                 // (well, only tcc instructions really)
774                                 if ((operands = dsp_amode(4)) == ERROR)
775                                         goto loop;
776
777                                 if (operands == 4)
778                                 {
779                                         dsp_tcc4(md->mninst);
780                                         goto loop;
781                                 }
782                         }
783
784                         if (md->mnattr & PARMOVE)
785                         {
786                                 // Check for parallel moves
787                                 if ((parcode = parmoves(dsp_a1reg)) == ERROR)
788                                         goto loop;
789                         }
790                         else
791                         {
792                                 if (*tok != EOL)
793                                         error("parallel moves not allowed with this instruction");
794
795                                 parcode = 0;
796                         }
797
798                         while ((dsp_am0 & md->mn0) == 0 || (dsp_am1 & md->mn1) == 0)
799                                 md = &dsp56k_machtab[md->mncont];
800
801                         (*md->mnfunc)(md->mninst | (parcode << 8));
802                         goto loop;
803                 }
804         }
805
806         // Invoke macro or complain about bad mnemonic
807         if (state < 0)
808         {
809                 if ((sy = lookup(opname, MACRO, 0)) != NULL)
810                         InvokeMacro(sy, siz);
811                 else
812                         error("unknown op '%s'", opname);
813
814                 goto loop;
815         }
816
817         // Call directive handlers
818         if (state < 500)
819         {
820                 (*dirtab[state])(siz);
821                 goto loop;
822         }
823
824         // Do mnemonics
825         //  o  can't deposit instrs in BSS or ABS
826         //  o  do automatic .EVEN for instrs
827         //  o  allocate space for largest possible instr
828         //  o  can't do ".b" operations with an address register
829         if (scattr & SBSS)
830         {
831                 error("cannot initialize non-storage (BSS) section");
832                 goto loop;
833         }
834
835         if (sloc & 1)                                   // Automatic .even
836                 auto_even();
837
838         if (challoc - ch_size < 18)             // Make sure have space in current chunk
839                 chcheck(0);
840
841         m = &machtab[state - 1000];
842
843         // Call special-mode handler
844         if (m->mnattr & CGSPECIAL)
845         {
846                 (*m->mnfunc)(m->mninst, siz);
847                 goto loop;
848         }
849
850         if (amode(1) < 0)                               // Parse 0, 1 or 2 addr modes
851                 goto loop;
852
853         // Check that we're at EOL
854         // The only exception is ptestr/ptestw instructions
855         // that have 3 or 4 operands and are not handled by
856         // amode(). (yes, we're taking a performance hit here sadly)
857         if (m->mnfunc != m_ptestr && m->mnfunc != m_ptestw)
858                 if (*tok != EOL)
859                         error(extra_stuff);
860
861         amsk0 = amsktab[am0];
862         amsk1 = amsktab[am1];
863
864         // Catch attempts to use ".B" with an address register (yes, this check
865         // does work at this level)
866         if (siz == SIZB && (am0 == AREG || am1 == AREG))
867         {
868                 error("cannot use '.b' with an address register");
869                 goto loop;
870         }
871
872         // Keep a backup of chptr (used for optimisations during codegen)
873         chptr_opcode = chptr;
874
875         while (!(m->mnattr & siz) || (amsk0 & m->mn0) == 0 || (amsk1 & m->mn1) == 0)
876                 m = &machtab[m->mncont];
877
878         DEBUG { printf("    68K: mninst=$%X, siz=$%X, mnattr=$%X, amsk0=$%X, mn0=$%X, amsk1=$%X, mn1=$%X\n", m->mninst, siz, m->mnattr, amsk0, m->mn0, amsk1, m->mn1); }
879
880         (*m->mnfunc)(m->mninst, siz);
881         goto loop;
882 }
883
884
885 //
886 // Handle the creation of labels
887 //
888 int HandleLabel(char * label, int labelType)
889 {
890         // Check for dot in front of label; means this is a local label if present
891         int environment = (*label == '.' ? curenv : 0);
892         SYM * symbol = lookup(label, LABEL, environment);
893
894         if (symbol == NULL)
895         {
896                 symbol = NewSymbol(label, LABEL, environment);
897                 symbol->sattr = 0;
898                 symbol->sattre = 0;
899         }
900         else if (symbol->sattr & DEFINED)
901                 return error("multiply-defined label '%s'", label);
902
903         // Put symbol in "order of definition" list if it's not already in it
904         AddToSymbolDeclarationList(symbol);
905
906         if (orgactive)
907         {
908                 symbol->svalue = orgaddr;
909                 symbol->sattr |= ABS | DEFINED | EQUATED;
910         }
911         else
912         {
913                 symbol->svalue = sloc;
914                 symbol->sattr |= DEFINED | cursect;
915         }
916
917         lab_sym = symbol;
918
919         // Yes, our CS professors told us to write checks for equality this way,
920         // but damn, it hurts my brain every time I look at it. :-/
921         if (0 == environment)
922                 curenv++;
923
924         // Make label global if it has a double colon
925         if (labelType == DCOLON)
926         {
927                 if (environment != 0)
928                         return error(locgl_error);
929
930                 symbol->sattr |= GLOBAL;
931         }
932
933         return 0;
934 }
935