]> Shamusworld >> Repos - rmac/blob - riscasm.c
Fix for spurious 'undefined register equate' error.
[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, UNPACK
228         case RI_ONE:
229                 reg2 = GetRegister(FU_REGTWO);
230                 at_eol();
231                 BuildRISCIntructionWord(parm, parm >> 6, reg2);
232                 break;   
233
234         // Two operand instructions (Rs,Rd)
235         // ADD, ADDC, AND, CMP, DIV, IMACN, IMULT, IMULTN, MOVEFA, MOVETA, MULT, MMULT, 
236         // MTOI, NORMI, OR, ROR, SH, SHA, SUB, SUBC, XOR
237         case RI_TWO:                      
238                 if (parm == 37)
239                         altbankok = 1;                      // MOVEFA
240
241                 reg1 = GetRegister(FU_REGONE);
242                 CHECK_COMMA;         
243
244                 if (parm == 36)
245                         altbankok = 1;                      // MOVETA
246
247                 reg2 = GetRegister(FU_REGTWO);
248                 at_eol();
249                 BuildRISCIntructionWord(parm, reg1, reg2);
250                 break;
251
252         // Numeric operand (n,Rd) where n = -16..+15
253         // CMPQ
254         case RI_NUM_15:
255
256         // Numeric operand (n,Rd) where n = 0..31
257         // BCLR, BSET, BTST, MOVEQ
258         case RI_NUM_31:
259
260         // Numeric operand (n,Rd) where n = 1..32
261         // ADDQ, ADDQMOD, ADDQT, SHARQ, SHLQ, SHRQ, SUBQ, SUBQMOD, SUBQT, ROLQ, RORQ
262         case RI_NUM_32:
263                 switch (type)
264                 {
265                 case RI_NUM_15:
266                         reg1 = -16; reg2 = 15; attrflg = FU_NUM15;
267                         break;
268                 default:
269                 case RI_NUM_31:
270                         reg1 =   0; reg2 = 31; attrflg = FU_NUM31;
271                         break;
272                 case RI_NUM_32:
273                         reg1 =   1; reg2 = 32; attrflg = FU_NUM32;
274                         break;
275                 }
276
277                 if (parm & SUB32)
278                         attrflg |= FU_SUB32;
279
280                 if (*tok != '#')
281                         return MalformedOpcode(0x01);
282
283                 tok++;
284                 riscImmTokenSeen = 1;
285
286                 if (expr(r_expr, &eval, &eattr, &esym) != OK)
287                         return MalformedOpcode(0x02);
288
289                 if ((challoc - ch_size) < 4)
290                         chcheck(4L);
291
292                 if (!(eattr & DEFINED))
293                 {
294                         AddFixup((WORD)(FU_WORD | attrflg), sloc, r_expr);
295                         reg1 = 0;
296                 }
297                 else
298                 {
299                         if ((int)eval < reg1 || (int)eval > reg2)
300                                 return error("constant out of range");
301
302                         if (parm & SUB32) 
303                                 reg1 = 32 - eval; 
304                         else if (type == RI_NUM_32)
305                                 reg1 = (reg1 == 32 ? 0 : eval);
306                         else
307                                 reg1 = eval;
308                 }
309
310                 CHECK_COMMA;
311                 reg2 = GetRegister(FU_REGTWO);
312                 at_eol();
313                 BuildRISCIntructionWord(parm, reg1, reg2);
314                 break;
315
316         // Move Immediate--n,Rn--n in Second Word
317         case RI_MOVEI:
318                 if (*tok != '#')
319                         return MalformedOpcode(0x03);
320
321                 tok++;
322                 riscImmTokenSeen = 1;
323
324                 if (expr(r_expr, &eval, &eattr, &esym) != OK)
325                         return MalformedOpcode(0x04);
326
327                 if (lastOpcode == RI_JUMP || lastOpcode == RI_JR)
328                 {
329                         if (legacy_flag)
330                         {
331                                 // User doesn't care, emit a NOP to fix
332                                 BuildRISCIntructionWord(57, 0, 0);
333                                 warn("MOVEI following JUMP, inserting NOP to fix your BROKEN CODE");
334                         }
335                         else
336                                 warn("MOVEI immediately follows JUMP");
337                 }
338
339                 if ((challoc - ch_size) < 4)
340                         chcheck(4L);
341
342                 if (!(eattr & DEFINED))
343                 {
344                         AddFixup(FU_LONG | FU_MOVEI, sloc + 2, r_expr);
345                         eval = 0;
346                 }
347                 else
348                 {
349                         if (eattr & TDB)
350 //{
351 //printf("risca: Doing rmark for RI_MOVEI (tdb=$%X)...\n", eattr & TDB);
352                                 rmark(cursect, sloc + 2, (eattr & TDB), (MLONG | MMOVEI), NULL);
353 //}
354                 }
355
356                 val = ((eval >> 16) & 0x0000FFFF) | ((eval << 16) & 0xFFFF0000);
357                 CHECK_COMMA;
358                 reg2 = GetRegister(FU_REGTWO);
359                 at_eol();
360                 D_word((((parm & 0x3F) << 10) + reg2));
361                 D_long(val);
362                 break;
363
364         // PC,Rd or Rs,Rd
365         case RI_MOVE:
366                 if (*tok == KW_PC)
367                 {
368                         parm = 51;
369                         reg1 = 0;
370                         tok++;
371                 }
372                 else
373                 {
374                         parm = 34;
375                         reg1 = GetRegister(FU_REGONE);
376                 }
377
378                 CHECK_COMMA;
379                 reg2 = GetRegister(FU_REGTWO);
380                 at_eol();
381                 BuildRISCIntructionWord(parm, reg1, reg2);
382                 break;
383
384         // (Rn),Rn = 41 / (R14/R15+n),Rn = 43/44 / (R14/R15+Rn),Rn = 58/59
385         case RI_LOAD:          
386                 indexed = 0;
387                 parm = 41;
388
389                 if (*tok != '(')
390                         return MalformedOpcode(0x05);
391
392                 tok++;
393
394                 if ((*tok == KW_R14 || *tok == KW_R15) && (*(tok + 1) != ')')) 
395                         indexed = (*tok - KW_R0);
396
397                 if (*tok == SYMBOL)
398                 {
399 //                      sy = lookup((char *)tok[1], LABEL, 0);
400                         sy = lookup(string[tok[1]], LABEL, 0);
401
402                         if (!sy)
403                         {
404                                 error(reg_err);
405                                 return ERROR;
406                         }
407
408                         if (sy->sattre & EQUATEDREG)
409                         {
410                                 if (((sy->svalue & 0x1F) == 14 || (sy->svalue & 0x1F) == 15)
411                                         && (*(tok + 2) != ')'))
412                                 {
413                                         indexed = (sy->svalue & 0x1F);
414                                         tok++;
415                                 }
416                         }
417                 }
418
419                 if (!indexed)
420                 {
421                         reg1 = GetRegister(FU_REGONE);
422                 }
423                 else
424                 {
425                         reg1 = indexed;
426                         indexed = 0;
427                         tok++;
428
429                         if (*tok == '+')
430                         {
431                                 parm = (WORD)(reg1 - 14 + 58);
432                                 tok++;
433
434                                 if (*tok >= KW_R0 && *tok <= KW_R31)
435                                         indexed = 1;
436
437                                 if (*tok == SYMBOL)
438                                 {
439 //                                      sy = lookup((char *)tok[1], LABEL, 0);
440                                         sy = lookup(string[tok[1]], LABEL, 0);
441
442                                         if (!sy)
443                                         {
444                                                 error(reg_err);
445                                                 return ERROR;
446                                         }
447
448                                         if (sy->sattre & EQUATEDREG)
449                                                 indexed = 1;
450                                 }
451
452                                 if (indexed)
453                                 {
454                                         reg1 = GetRegister(FU_REGONE);
455                                 }
456                                 else
457                                 {
458                                         if (expr(r_expr, &eval, &eattr, &esym) != OK)
459                                                 return MalformedOpcode(0x06);
460
461                                         if ((challoc - ch_size) < 4)
462                                                 chcheck(4L);
463
464                                         if (!(eattr & DEFINED))
465                                                 return error("constant expected after '+'");
466
467                                         reg1 = eval;
468
469                                         if (reg1 == 0)
470                                         {
471                                                 reg1 = 14 + (parm - 58);
472                                                 parm = 41;
473                                                 warn("NULL offset in LOAD ignored");
474                                         }
475                                         else
476                                         {
477                                                 if (reg1 < 1 || reg1 > 32)
478                                                         return error("constant in LOAD out of range");
479
480                                                 if (reg1 == 32)
481                                                         reg1 = 0;
482
483                                                 parm = (WORD)(parm - 58 + 43);
484                                         }
485                                 }
486                         }
487                         else
488                         {
489                                 reg1 = GetRegister(FU_REGONE);
490                         }
491                 }
492
493                 if (*tok != ')')
494                         return MalformedOpcode(0x07);
495
496                 tok++;
497                 CHECK_COMMA;
498                 reg2 = GetRegister(FU_REGTWO);
499                 at_eol();
500                 BuildRISCIntructionWord(parm, reg1, reg2);
501                 break;
502
503         // Rn,(Rn) = 47 / Rn,(R14/R15+n) = 49/50 / Rn,(R14/R15+Rn) = 60/61
504         case RI_STORE:    
505                 parm = 47;
506                 reg1 = GetRegister(FU_REGONE);
507                 CHECK_COMMA;
508
509                 if (*tok != '(')
510                         return MalformedOpcode(0x08);
511
512                 tok++;
513                 indexed = 0;
514
515                 if ((*tok == KW_R14 || *tok == KW_R15) && (*(tok + 1) != ')')) 
516                         indexed = (*tok - KW_R0);
517
518                 if (*tok == SYMBOL)
519                 {
520                         sy = lookup(string[tok[1]], LABEL, 0);
521
522                         if (!sy)
523                         {
524                                 error(reg_err);
525                                 return ERROR;
526                         }
527
528                         if (sy->sattre & EQUATEDREG) 
529                         {
530                                 if (((sy->svalue & 0x1F) == 14 || (sy->svalue & 0x1F) == 15)
531                                         && (*(tok + 2) != ')'))
532                                 {
533                                         indexed = (sy->svalue & 0x1F);
534                                         tok++;
535                                 }
536                         }
537                 }
538
539                 if (!indexed)
540                 {
541                         reg2 = GetRegister(FU_REGTWO);
542                 }
543                 else
544                 {
545                         reg2 = indexed;
546                         indexed = 0;
547                         tok++;
548
549                         if (*tok == '+')
550                         {
551                                 parm = (WORD)(reg2 - 14 + 60);
552                                 tok++;
553
554                                 if (*tok >= KW_R0 && *tok <= KW_R31)
555                                         indexed = 1;
556
557                                 if (*tok == SYMBOL)
558                                 {
559                                         sy = lookup(string[tok[1]], LABEL, 0);
560
561                                         if (!sy)
562                                         {
563                                                 error(reg_err);
564                                                 return ERROR;
565                                         }
566
567                                         if (sy->sattre & EQUATEDREG)
568                                                 indexed = 1;
569                                 }
570
571                                 if (indexed)
572                                 {
573                                         reg2 = GetRegister(FU_REGTWO);
574                                 }
575                                 else
576                                 {
577                                         if (expr(r_expr, &eval, &eattr, &esym) != OK)
578                                                 return MalformedOpcode(0x09);
579
580                                         if ((challoc - ch_size) < 4)
581                                                 chcheck(4L);
582
583                                         if (!(eattr & DEFINED))
584                                         {
585                                                 AddFixup(FU_WORD | FU_REGTWO, sloc, r_expr);
586                                                 reg2 = 0;
587                                         }
588                                         else
589                                         {
590                                                 reg2 = eval;
591
592                                                 if (reg2 == 0)
593                                                 {
594                                                         reg2 = 14 + (parm - 60);
595                                                         parm = 47;
596                                                         warn("NULL offset in STORE ignored");
597                                                 }
598                                                 else
599                                                 {
600                                                         if (reg2 < 1 || reg2 > 32)
601                                                                 return error("constant in STORE out of range");
602
603                                                         if (reg2 == 32)
604                                                                 reg2 = 0;
605
606                                                         parm = (WORD)(parm - 60 + 49);
607                                                 }
608                                         }
609                                 }
610                         }
611                         else
612                         {
613                                 reg2 = GetRegister(FU_REGTWO);
614                         }
615                 }
616
617                 if (*tok != ')')
618                         return MalformedOpcode(0x0A);
619
620                 tok++;
621                 at_eol();
622                 BuildRISCIntructionWord(parm, reg2, reg1);
623                 break;
624
625         // LOADB/LOADP/LOADW (Rn),Rn
626         case RI_LOADN:                    
627                 if (*tok != '(')
628                         return MalformedOpcode(0x0B);
629
630                 tok++;
631                 reg1 = GetRegister(FU_REGONE);
632
633                 if (*tok != ')')
634                         return MalformedOpcode(0x0C);
635
636                 tok++;
637                 CHECK_COMMA;
638                 reg2 = GetRegister(FU_REGTWO);
639                 at_eol();
640                 BuildRISCIntructionWord(parm, reg1, reg2);
641                 break;
642
643         // STOREB/STOREP/STOREW Rn,(Rn)
644         case RI_STOREN:                   
645                 reg1 = GetRegister(FU_REGONE);
646                 CHECK_COMMA;
647
648                 if (*tok != '(')
649                         return MalformedOpcode(0x0D);
650
651                 tok++;
652                 reg2 = GetRegister(FU_REGTWO);
653
654                 if (*tok != ')')
655                         return MalformedOpcode(0x0E);
656
657                 tok++;
658                 at_eol();
659                 BuildRISCIntructionWord(parm, reg2, reg1);
660                 break;
661
662         // Jump Relative - cc,n - n=-16..+15 words, reg2=cc
663         case RI_JR:
664
665         // Jump Absolute - cc,(Rs) - reg2=cc
666         case RI_JUMP:
667                 // Check to see if there is a comma in the token string. If not then
668                 // the JR or JUMP should default to 0, Jump Always
669                 commaFound = 0;
670
671                 for(t=tok; *t!=EOL; t++)
672                 {
673                         if (*t == ',')
674                         {
675                                 commaFound = 1;
676                                 break;
677                         }
678                 }
679
680                 if (commaFound)
681                 {
682                         if (*tok == CONST)
683                         {
684                                 // CC using a constant number
685                                 tok++;
686                                 val = *tok;
687                                 tok++;
688                                 CHECK_COMMA;
689                         }
690                         else if (*tok == SYMBOL)
691                         {
692                                 val = 99;
693 //                              strcpy(scratch, (char *)tok[1]);
694                                 strcpy(scratch, string[tok[1]]);
695                                 strtoupper(scratch);
696
697                                 for(i=0; i<MAXINTERNCC; i++)
698                                 {
699                                         // Look for the condition code & break if found
700                                         if (strcmp(condname[i], scratch) == 0)
701                                         {
702                                                 val = condnumber[i];
703                                                 break;
704                                         }
705                                 }
706
707                                 // Standard CC was not found, look for an equated one
708                                 if (val == 99)
709                                 {
710 //                                      ccsym = lookup((char *)tok[1], LABEL, 0);
711                                         ccsym = lookup(string[tok[1]], LABEL, 0);
712
713                                         if (ccsym && (ccsym->sattre & EQUATEDCC) && !(ccsym->sattre & UNDEF_CC))
714                                         {
715                                                 val = ccsym->svalue;
716                                         }
717                                         else
718                                                 return error("unknown condition code");
719                                 }
720
721                                 tok += 2;
722                                 CHECK_COMMA;
723                         }
724                         else if (*tok == '(')
725                         {
726                                 // Set CC to "Jump Always"
727                                 val = 0;
728                         }
729                 }
730                 else
731                 {
732                         // Set CC to "Jump Always"
733                         val = 0;
734                 }
735
736                 if (val < 0 || val > 31)
737                         return error("condition constant out of range");
738
739                 // Store condition code
740                 reg1 = val;
741
742                 if (type == RI_JR)
743                 {
744                         // JR cc,n
745                         if (expr(r_expr, &eval, &eattr, &esym) != OK)
746                                 return MalformedOpcode(0x0F);
747
748                         if ((challoc - ch_size) < 4)
749                                 chcheck(4L);
750
751                         if (!(eattr & DEFINED))
752                         {
753                                 AddFixup(FU_WORD | FU_JR, sloc, r_expr);
754                                 reg2 = 0;
755                         }
756                         else
757                         {
758                                 reg2 = ((int)(eval - ((orgactive ? orgaddr : sloc) + 2))) / 2;
759
760                                 if ((reg2 < -16) || (reg2 > 15))
761                                         error("PC relative overflow");
762                         }
763
764                         BuildRISCIntructionWord(parm, reg2, reg1);
765                 }
766                 else
767                 {
768                         // JUMP cc, (Rn)
769                         if (*tok != '(')
770                                 return MalformedOpcode(0x10);
771
772                         tok++;
773                         reg2 = GetRegister(FU_REGTWO);
774
775                         if (*tok != ')')
776                                 return MalformedOpcode(0x11);
777
778                         tok++;
779                         at_eol();
780                         BuildRISCIntructionWord(parm, reg2, reg1);
781                 }
782
783                 break;
784
785         // Should never get here :-D
786         default:
787                 return error("Unknown RISC opcode type");
788         }
789
790         lastOpcode = type;
791         return 0;
792 }
793