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