]> Shamusworld >> Repos - rmac/blob - riscasm.c
Fixed a nasty bug that dropped symbols that shouldn't have been.
[rmac] / riscasm.c
1 //
2 // RMAC - Reboot's Macro Assembler for the Atari Jaguar Console System
3 // RISCA.C - GPU/DSP Assembler
4 // Copyright (C) 199x Landon Dyer, 2011 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 "riscasm.h"
10 #include "error.h"
11 #include "sect.h"
12 #include "token.h"
13 #include "expr.h"
14 #include "direct.h"
15 #include "mark.h"
16 #include "amode.h"
17
18 #define DEF_MR                          // Declare keyword values
19 #include "risckw.h"                     // Incl. generated risc keywords
20
21 #define DEF_KW                          // Declare keyword values 
22 #include "kwtab.h"                      // Incl. generated keyword tables & defs
23
24
25 unsigned altbankok = 0;         // Ok to use alternate register bank
26 unsigned orgactive = 0;         // RISC org directive active
27 unsigned orgaddr = 0;           // Org'd address
28 unsigned orgwarning = 0;        // Has an ORG warning been issued
29 int lastOpcode = -1;            // Last RISC opcode assembled
30 uint8_t riscImmTokenSeen;       // The '#' (immediate) token was seen
31
32 const char reg_err[] = "missing register R0...R31";
33
34 // Jaguar jump condition names
35 const char condname[MAXINTERNCC][5] = { 
36         "NZ", "Z", "NC", "NCNZ", "NCZ", "C", "CNZ", "CZ", "NN", "NNNZ", "NNZ",
37         "N", "N_NZ", "N_Z", "T", "A", "NE", "EQ", "CC", "HS", "HI", "CS", "LO",
38         "PL", "MI", "F"
39 };
40
41 // Jaguar jump condition numbers
42 const char condnumber[] = {
43         1, 2, 4, 5, 6, 8, 9, 10, 20, 21, 22, 24, 25, 26,
44         0, 0, 1, 2, 4, 4, 5,  8,  8, 20, 24, 31
45 };
46
47 const struct opcoderecord roptbl[] = {
48         { MR_ADD,     RI_TWO,    0 },
49         { MR_ADDC,    RI_TWO,    1 },
50         { MR_ADDQ,    RI_NUM_32, 2 },
51         { MR_ADDQT,   RI_NUM_32, 3 },
52         { MR_SUB,     RI_TWO,    4 },
53         { MR_SUBC,    RI_TWO,    5 },
54         { MR_SUBQ,    RI_NUM_32, 6 },
55         { MR_SUBQT,   RI_NUM_32, 7 },
56         { MR_NEG,     RI_ONE,    8 },
57         { MR_AND,     RI_TWO,    9 },
58         { MR_OR,      RI_TWO,    10 },
59         { MR_XOR,     RI_TWO,    11 },
60         { MR_NOT,     RI_ONE,    12 },
61         { MR_BTST,    RI_NUM_31, 13 },
62         { MR_BSET,    RI_NUM_31, 14 },
63         { MR_BCLR,    RI_NUM_31, 15 },
64         { MR_MULT,    RI_TWO,    16 },
65         { MR_IMULT,   RI_TWO,    17 },
66         { MR_IMULTN,  RI_TWO,    18 },
67         { MR_RESMAC,  RI_ONE,    19 },
68         { MR_IMACN,   RI_TWO,    20 },
69         { MR_DIV,     RI_TWO,    21 },
70         { MR_ABS,     RI_ONE,    22 },
71         { MR_SH,      RI_TWO,    23 },
72         { MR_SHLQ,    RI_NUM_32, 24 + SUB32 },
73         { MR_SHRQ,    RI_NUM_32, 25 },
74         { MR_SHA,     RI_TWO,    26 },
75         { MR_SHARQ,   RI_NUM_32, 27 },
76         { MR_ROR,     RI_TWO,    28 },
77         { MR_RORQ,    RI_NUM_32, 29 },
78         { MR_ROLQ,    RI_NUM_32, 29 + SUB32 },
79         { MR_CMP,     RI_TWO,    30 },
80         { MR_CMPQ,    RI_NUM_15, 31 },
81         { MR_SAT8,    RI_ONE,    32 + GPUONLY },
82         { MR_SUBQMOD, RI_NUM_32, 32 + DSPONLY },
83         { MR_SAT16,   RI_ONE,    33 + GPUONLY },
84         { MR_SAT16S,  RI_ONE,    33 + DSPONLY },
85         { MR_MOVEQ,   RI_NUM_31, 35 },
86         { MR_MOVETA,  RI_TWO,    36 },
87         { MR_MOVEFA,  RI_TWO,    37 },
88         { MR_MOVEI,   RI_MOVEI,  38 },
89         { MR_LOADB,   RI_LOADN,  39 },
90         { MR_LOADW,   RI_LOADN,  40 },
91         { MR_LOADP,   RI_LOADN,  42 + GPUONLY },
92         { MR_SAT32S,  RI_ONE,    42 + DSPONLY },
93         { MR_STOREB,  RI_STOREN, 45 },
94         { MR_STOREW,  RI_STOREN, 46 },
95         { MR_STOREP,  RI_STOREN, 48 + GPUONLY },
96         { MR_MIRROR,  RI_ONE,    48 + DSPONLY },
97         { MR_JUMP,    RI_JUMP,   52 },
98         { MR_JR,      RI_JR,     53 },
99         { MR_MMULT,   RI_TWO,    54 },
100         { MR_MTOI,    RI_TWO,    55 },
101         { MR_NORMI,   RI_TWO,    56 },
102         { MR_NOP,     RI_NONE,   57 },
103         { MR_SAT24,   RI_ONE,    62 },
104         { MR_UNPACK,  RI_ONE,    63 + GPUONLY },
105         { MR_PACK,    RI_ONE,    63 + GPUONLY },
106         { MR_ADDQMOD, RI_NUM_32, 63 + DSPONLY },
107         { MR_MOVE,    RI_MOVE,   0 },
108         { MR_LOAD,    RI_LOAD,   0 },
109         { MR_STORE,   RI_STORE,  0 }
110 };
111
112
113 //
114 // Convert a string to uppercase
115 //
116 void strtoupper(char * s)
117 {
118         while (*s)
119                 *s++ &= 0xDF;
120 }
121
122
123 //
124 // Function to return "malformed expression" error
125 // This is done mainly to remove a bunch of GOTO statements in the parser
126 //
127 static inline int MalformedOpcode(int signal)
128 {
129         char buf[16];
130         sprintf(buf, "%02X", signal);
131         return errors("Malformed opcode [internal $%s]", buf);
132 }
133
134
135 //
136 // Build RISC instruction word
137 //
138 void BuildRISCIntructionWord(unsigned short opcode, int reg1, int reg2)
139 {
140         // Check for absolute address setting
141         if (!orgwarning && !orgactive)
142         {
143 //              warn("GPU/DSP code outside of absolute section");
144                 warn("RISC code generated with no origin defined");
145                 orgwarning = 1;
146         }
147
148         int value = ((opcode & 0x3F) << 10) + ((reg1 & 0x1F) << 5) + (reg2 & 0x1F);
149         D_word(value);
150 }
151
152
153 //
154 // Get a RISC register
155 //
156 int GetRegister(WORD rattr)
157 {
158         VALUE eval;                                     // Expression value
159         WORD eattr;                                     // Expression attributes
160         SYM * esym;                                     // External symbol involved in expr.
161         TOKEN r_expr[EXPRSIZE];         // Expression token list
162
163         // Evaluate what's in the global "tok" buffer
164         if (expr(r_expr, &eval, &eattr, &esym) != OK)
165                 return ERROR;
166
167         if ((challoc - ch_size) < 4)
168                 chcheck(4L);
169
170         if (!(eattr & DEFINED))
171         {
172                 AddFixup((WORD)(FU_WORD | rattr), sloc, r_expr);      
173                 return 0;
174         }
175
176         // If we got a register in range (0-31), return it
177         if ((eval >= 0) && (eval <= 31))
178                 return eval;
179
180         // Otherwise, it's out of range & we flag an error
181         return error(reg_err);
182 }
183
184
185 //
186 // Do RISC code generation
187 //
188 int GenerateRISCCode(int state)
189 {
190         int reg1;                                       // Register 1
191         int reg2;                                       // Register 2
192         int val = 0;                            // Constructed value
193         char scratch[80];
194         SYM * ccsym;
195         SYM * sy;
196         int i, commaFound;
197         TOKEN * t;
198         WORD attrflg;
199         int indexed;                            // Indexed register flag
200
201         VALUE eval;                                     // Expression value
202         WORD eattr;                                     // Expression attributes
203         SYM * esym;                                     // External symbol involved in expr.
204         TOKEN r_expr[EXPRSIZE];         // Expression token list
205
206         // Get opcode parameter and type
207         unsigned short parm = (WORD)(roptbl[state - 3000].parm);
208         unsigned type = roptbl[state - 3000].typ;
209         riscImmTokenSeen = 0;           // Set to "token not seen yet"
210
211         // Detect whether the opcode parmeter passed determines that the opcode is
212         // specific to only one of the RISC processors and ensure it is legal in
213         // the current code section. If not then show error and return.
214         if (((parm & GPUONLY) && rdsp) || ((parm & DSPONLY) && rgpu))
215                 return error("Opcode is not valid in this code section");
216
217         // Process RISC opcode
218         switch (type)
219         {
220         // No operand instructions
221         // NOP (57)
222         case RI_NONE:
223                 BuildRISCIntructionWord(parm, 0, 0);
224                 break;
225
226         // Single operand instructions (Rd)
227         // ABS, MIRROR, NEG, NOT, PACK, RESMAC, SAT8, SAT16, SAT16S, SAT24, SAT32S,
228         // UNPACK
229         case RI_ONE:
230                 reg2 = GetRegister(FU_REGTWO);
231                 at_eol();
232                 BuildRISCIntructionWord(parm, parm >> 6, reg2);
233                 break;   
234
235         // Two operand instructions (Rs,Rd)
236         // ADD, ADDC, AND, CMP, DIV, IMACN, IMULT, IMULTN, MOVEFA, MOVETA, MULT,
237         // MMULT, MTOI, NORMI, OR, ROR, SH, SHA, SUB, SUBC, XOR
238         case RI_TWO:                      
239                 if (parm == 37)
240                         altbankok = 1;                      // MOVEFA
241
242                 reg1 = GetRegister(FU_REGONE);
243                 CHECK_COMMA;         
244
245                 if (parm == 36)
246                         altbankok = 1;                      // MOVETA
247
248                 reg2 = GetRegister(FU_REGTWO);
249                 at_eol();
250                 BuildRISCIntructionWord(parm, reg1, reg2);
251                 break;
252
253         // Numeric operand (n,Rd) where n = -16..+15
254         // CMPQ
255         case RI_NUM_15:
256
257         // Numeric operand (n,Rd) where n = 0..31
258         // BCLR, BSET, BTST, MOVEQ
259         case RI_NUM_31:
260
261         // Numeric operand (n,Rd) where n = 1..32
262         // ADDQ, ADDQMOD, ADDQT, SHARQ, SHLQ, SHRQ, SUBQ, SUBQMOD, SUBQT, ROLQ,
263         // RORQ
264         case RI_NUM_32:
265                 switch (type)
266                 {
267                 case RI_NUM_15:
268                         reg1 = -16; reg2 = 15; attrflg = FU_NUM15;
269                         break;
270                 default:
271                 case RI_NUM_31:
272                         reg1 =   0; reg2 = 31; attrflg = FU_NUM31;
273                         break;
274                 case RI_NUM_32:
275                         reg1 =   1; reg2 = 32; attrflg = FU_NUM32;
276                         break;
277                 }
278
279                 if (parm & SUB32)
280                         attrflg |= FU_SUB32;
281
282                 if (*tok != '#')
283                         return MalformedOpcode(0x01);
284
285                 tok++;
286                 riscImmTokenSeen = 1;
287
288                 if (expr(r_expr, &eval, &eattr, &esym) != OK)
289                         return MalformedOpcode(0x02);
290
291                 if ((challoc - ch_size) < 4)
292                         chcheck(4L);
293
294                 if (!(eattr & DEFINED))
295                 {
296                         AddFixup((WORD)(FU_WORD | attrflg), sloc, r_expr);
297                         reg1 = 0;
298                 }
299                 else
300                 {
301                         if ((int)eval < reg1 || (int)eval > reg2)
302                                 return error("constant out of range");
303
304                         if (parm & SUB32) 
305                                 reg1 = 32 - eval; 
306                         else if (type == RI_NUM_32)
307                                 reg1 = (reg1 == 32 ? 0 : eval);
308                         else
309                                 reg1 = eval;
310                 }
311
312                 CHECK_COMMA;
313                 reg2 = GetRegister(FU_REGTWO);
314                 at_eol();
315                 BuildRISCIntructionWord(parm, reg1, reg2);
316                 break;
317
318         // Move Immediate--n,Rn--n in Second Word
319         case RI_MOVEI:
320                 if (*tok != '#')
321                         return MalformedOpcode(0x03);
322
323                 tok++;
324                 riscImmTokenSeen = 1;
325
326                 if (expr(r_expr, &eval, &eattr, &esym) != OK)
327                         return MalformedOpcode(0x04);
328
329                 if (lastOpcode == RI_JUMP || lastOpcode == RI_JR)
330                 {
331                         if (legacy_flag)
332                         {
333                                 // User doesn't care, emit a NOP to fix
334                                 BuildRISCIntructionWord(57, 0, 0);
335                                 warn("MOVEI following JUMP, inserting NOP to fix your BROKEN CODE");
336                         }
337                         else
338                                 warn("MOVEI immediately follows JUMP");
339                 }
340
341                 if ((challoc - ch_size) < 4)
342                         chcheck(4L);
343
344                 if (!(eattr & DEFINED))
345                 {
346                         AddFixup(FU_LONG | FU_MOVEI, sloc + 2, r_expr);
347                         eval = 0;
348                 }
349                 else
350                 {
351                         if (eattr & TDB)
352 //{
353 //printf("RISCASM: Doing rmark for RI_MOVEI (tdb=$%X)...\n", eattr & TDB);
354                                 rmark(cursect, sloc + 2, (eattr & TDB), (MLONG | MMOVEI), NULL);
355 //}
356                 }
357
358                 val = ((eval >> 16) & 0x0000FFFF) | ((eval << 16) & 0xFFFF0000);
359                 CHECK_COMMA;
360                 reg2 = GetRegister(FU_REGTWO);
361                 at_eol();
362                 D_word((((parm & 0x3F) << 10) + reg2));
363                 D_long(val);
364                 break;
365
366         // PC,Rd or Rs,Rd
367         case RI_MOVE:
368                 if (*tok == KW_PC)
369                 {
370                         parm = 51;
371                         reg1 = 0;
372                         tok++;
373                 }
374                 else
375                 {
376                         parm = 34;
377                         reg1 = GetRegister(FU_REGONE);
378                 }
379
380                 CHECK_COMMA;
381                 reg2 = GetRegister(FU_REGTWO);
382                 at_eol();
383                 BuildRISCIntructionWord(parm, reg1, reg2);
384                 break;
385
386         // (Rn),Rn = 41 / (R14/R15+n),Rn = 43/44 / (R14/R15+Rn),Rn = 58/59
387         case RI_LOAD:          
388                 indexed = 0;
389                 parm = 41;
390
391                 if (*tok != '(')
392                         return MalformedOpcode(0x05);
393
394                 tok++;
395
396                 if ((*tok == KW_R14 || *tok == KW_R15) && (*(tok + 1) != ')')) 
397                         indexed = (*tok - KW_R0);
398
399                 if (*tok == SYMBOL)
400                 {
401 //                      sy = lookup((char *)tok[1], LABEL, 0);
402                         sy = lookup(string[tok[1]], LABEL, 0);
403
404                         if (!sy)
405                         {
406                                 error(reg_err);
407                                 return ERROR;
408                         }
409
410                         if (sy->sattre & EQUATEDREG)
411                         {
412                                 if (((sy->svalue & 0x1F) == 14 || (sy->svalue & 0x1F) == 15)
413                                         && (*(tok + 2) != ')'))
414                                 {
415                                         indexed = (sy->svalue & 0x1F);
416                                         tok++;
417                                 }
418                         }
419                 }
420
421                 if (!indexed)
422                 {
423                         reg1 = GetRegister(FU_REGONE);
424                 }
425                 else
426                 {
427                         reg1 = indexed;
428                         indexed = 0;
429                         tok++;
430
431                         if (*tok == '+')
432                         {
433                                 parm = (WORD)(reg1 - 14 + 58);
434                                 tok++;
435
436                                 if (*tok >= KW_R0 && *tok <= KW_R31)
437                                         indexed = 1;
438
439                                 if (*tok == SYMBOL)
440                                 {
441 //                                      sy = lookup((char *)tok[1], LABEL, 0);
442                                         sy = lookup(string[tok[1]], LABEL, 0);
443
444                                         if (!sy)
445                                         {
446                                                 error(reg_err);
447                                                 return ERROR;
448                                         }
449
450                                         if (sy->sattre & EQUATEDREG)
451                                                 indexed = 1;
452                                 }
453
454                                 if (indexed)
455                                 {
456                                         reg1 = GetRegister(FU_REGONE);
457                                 }
458                                 else
459                                 {
460                                         if (expr(r_expr, &eval, &eattr, &esym) != OK)
461                                                 return MalformedOpcode(0x06);
462
463                                         if ((challoc - ch_size) < 4)
464                                                 chcheck(4L);
465
466                                         if (!(eattr & DEFINED))
467                                                 return error("constant expected after '+'");
468
469                                         reg1 = eval;
470
471                                         if (reg1 == 0)
472                                         {
473                                                 reg1 = 14 + (parm - 58);
474                                                 parm = 41;
475                                                 warn("NULL offset in LOAD ignored");
476                                         }
477                                         else
478                                         {
479                                                 if (reg1 < 1 || reg1 > 32)
480                                                         return error("constant in LOAD out of range");
481
482                                                 if (reg1 == 32)
483                                                         reg1 = 0;
484
485                                                 parm = (WORD)(parm - 58 + 43);
486                                         }
487                                 }
488                         }
489                         else
490                         {
491                                 reg1 = GetRegister(FU_REGONE);
492                         }
493                 }
494
495                 if (*tok != ')')
496                         return MalformedOpcode(0x07);
497
498                 tok++;
499                 CHECK_COMMA;
500                 reg2 = GetRegister(FU_REGTWO);
501                 at_eol();
502                 BuildRISCIntructionWord(parm, reg1, reg2);
503                 break;
504
505         // Rn,(Rn) = 47 / Rn,(R14/R15+n) = 49/50 / Rn,(R14/R15+Rn) = 60/61
506         case RI_STORE:    
507                 parm = 47;
508                 reg1 = GetRegister(FU_REGONE);
509                 CHECK_COMMA;
510
511                 if (*tok != '(')
512                         return MalformedOpcode(0x08);
513
514                 tok++;
515                 indexed = 0;
516
517                 if ((*tok == KW_R14 || *tok == KW_R15) && (*(tok + 1) != ')')) 
518                         indexed = (*tok - KW_R0);
519
520                 if (*tok == SYMBOL)
521                 {
522                         sy = lookup(string[tok[1]], LABEL, 0);
523
524                         if (!sy)
525                         {
526                                 error(reg_err);
527                                 return ERROR;
528                         }
529
530                         if (sy->sattre & EQUATEDREG) 
531                         {
532                                 if (((sy->svalue & 0x1F) == 14 || (sy->svalue & 0x1F) == 15)
533                                         && (*(tok + 2) != ')'))
534                                 {
535                                         indexed = (sy->svalue & 0x1F);
536                                         tok++;
537                                 }
538                         }
539                 }
540
541                 if (!indexed)
542                 {
543                         reg2 = GetRegister(FU_REGTWO);
544                 }
545                 else
546                 {
547                         reg2 = indexed;
548                         indexed = 0;
549                         tok++;
550
551                         if (*tok == '+')
552                         {
553                                 parm = (WORD)(reg2 - 14 + 60);
554                                 tok++;
555
556                                 if (*tok >= KW_R0 && *tok <= KW_R31)
557                                         indexed = 1;
558
559                                 if (*tok == SYMBOL)
560                                 {
561                                         sy = lookup(string[tok[1]], LABEL, 0);
562
563                                         if (!sy)
564                                         {
565                                                 error(reg_err);
566                                                 return ERROR;
567                                         }
568
569                                         if (sy->sattre & EQUATEDREG)
570                                                 indexed = 1;
571                                 }
572
573                                 if (indexed)
574                                 {
575                                         reg2 = GetRegister(FU_REGTWO);
576                                 }
577                                 else
578                                 {
579                                         if (expr(r_expr, &eval, &eattr, &esym) != OK)
580                                                 return MalformedOpcode(0x09);
581
582                                         if ((challoc - ch_size) < 4)
583                                                 chcheck(4L);
584
585                                         if (!(eattr & DEFINED))
586                                         {
587                                                 AddFixup(FU_WORD | FU_REGTWO, sloc, r_expr);
588                                                 reg2 = 0;
589                                         }
590                                         else
591                                         {
592                                                 reg2 = eval;
593
594                                                 if (reg2 == 0)
595                                                 {
596                                                         reg2 = 14 + (parm - 60);
597                                                         parm = 47;
598                                                         warn("NULL offset in STORE ignored");
599                                                 }
600                                                 else
601                                                 {
602                                                         if (reg2 < 1 || reg2 > 32)
603                                                                 return error("constant in STORE out of range");
604
605                                                         if (reg2 == 32)
606                                                                 reg2 = 0;
607
608                                                         parm = (WORD)(parm - 60 + 49);
609                                                 }
610                                         }
611                                 }
612                         }
613                         else
614                         {
615                                 reg2 = GetRegister(FU_REGTWO);
616                         }
617                 }
618
619                 if (*tok != ')')
620                         return MalformedOpcode(0x0A);
621
622                 tok++;
623                 at_eol();
624                 BuildRISCIntructionWord(parm, reg2, reg1);
625                 break;
626
627         // LOADB/LOADP/LOADW (Rn),Rn
628         case RI_LOADN:                    
629                 if (*tok != '(')
630                         return MalformedOpcode(0x0B);
631
632                 tok++;
633                 reg1 = GetRegister(FU_REGONE);
634
635                 if (*tok != ')')
636                         return MalformedOpcode(0x0C);
637
638                 tok++;
639                 CHECK_COMMA;
640                 reg2 = GetRegister(FU_REGTWO);
641                 at_eol();
642                 BuildRISCIntructionWord(parm, reg1, reg2);
643                 break;
644
645         // STOREB/STOREP/STOREW Rn,(Rn)
646         case RI_STOREN:                   
647                 reg1 = GetRegister(FU_REGONE);
648                 CHECK_COMMA;
649
650                 if (*tok != '(')
651                         return MalformedOpcode(0x0D);
652
653                 tok++;
654                 reg2 = GetRegister(FU_REGTWO);
655
656                 if (*tok != ')')
657                         return MalformedOpcode(0x0E);
658
659                 tok++;
660                 at_eol();
661                 BuildRISCIntructionWord(parm, reg2, reg1);
662                 break;
663
664         // Jump Relative - cc,n - n=-16..+15 words, reg2=cc
665         case RI_JR:
666
667         // Jump Absolute - cc,(Rs) - reg2=cc
668         case RI_JUMP:
669                 // Check to see if there is a comma in the token string. If not then
670                 // the JR or JUMP should default to 0, Jump Always
671                 commaFound = 0;
672
673                 for(t=tok; *t!=EOL; t++)
674                 {
675                         if (*t == ',')
676                         {
677                                 commaFound = 1;
678                                 break;
679                         }
680                 }
681
682                 if (commaFound)
683                 {
684                         if (*tok == CONST)
685                         {
686                                 // CC using a constant number
687                                 tok++;
688                                 val = *tok;
689                                 tok++;
690                                 CHECK_COMMA;
691                         }
692                         else if (*tok == SYMBOL)
693                         {
694                                 val = 99;
695 //                              strcpy(scratch, (char *)tok[1]);
696                                 strcpy(scratch, string[tok[1]]);
697                                 strtoupper(scratch);
698
699                                 for(i=0; i<MAXINTERNCC; i++)
700                                 {
701                                         // Look for the condition code & break if found
702                                         if (strcmp(condname[i], scratch) == 0)
703                                         {
704                                                 val = condnumber[i];
705                                                 break;
706                                         }
707                                 }
708
709                                 // Standard CC was not found, look for an equated one
710                                 if (val == 99)
711                                 {
712 //                                      ccsym = lookup((char *)tok[1], LABEL, 0);
713                                         ccsym = lookup(string[tok[1]], LABEL, 0);
714
715                                         if (ccsym && (ccsym->sattre & EQUATEDCC) && !(ccsym->sattre & UNDEF_CC))
716                                         {
717                                                 val = ccsym->svalue;
718                                         }
719                                         else
720                                                 return error("unknown condition code");
721                                 }
722
723                                 tok += 2;
724                                 CHECK_COMMA;
725                         }
726                         else if (*tok == '(')
727                         {
728                                 // Set CC to "Jump Always"
729                                 val = 0;
730                         }
731                 }
732                 else
733                 {
734                         // Set CC to "Jump Always"
735                         val = 0;
736                 }
737
738                 if (val < 0 || val > 31)
739                         return error("condition constant out of range");
740
741                 // Store condition code
742                 reg1 = val;
743
744                 if (type == RI_JR)
745                 {
746                         // JR cc,n
747                         if (expr(r_expr, &eval, &eattr, &esym) != OK)
748                                 return MalformedOpcode(0x0F);
749
750                         if ((challoc - ch_size) < 4)
751                                 chcheck(4L);
752
753                         if (!(eattr & DEFINED))
754                         {
755                                 AddFixup(FU_WORD | FU_JR, sloc, r_expr);
756                                 reg2 = 0;
757                         }
758                         else
759                         {
760                                 reg2 = ((int)(eval - ((orgactive ? orgaddr : sloc) + 2))) / 2;
761
762                                 if ((reg2 < -16) || (reg2 > 15))
763                                         error("PC relative overflow");
764                         }
765
766                         BuildRISCIntructionWord(parm, reg2, reg1);
767                 }
768                 else
769                 {
770                         // JUMP cc, (Rn)
771                         if (*tok != '(')
772                                 return MalformedOpcode(0x10);
773
774                         tok++;
775                         reg2 = GetRegister(FU_REGTWO);
776
777                         if (*tok != ')')
778                                 return MalformedOpcode(0x11);
779
780                         tok++;
781                         at_eol();
782                         BuildRISCIntructionWord(parm, reg2, reg1);
783                 }
784
785                 break;
786
787         // Should never get here :-D
788         default:
789                 return error("Unknown RISC opcode type");
790         }
791
792         lastOpcode = type;
793         return 0;
794 }
795