]> Shamusworld >> Repos - rmac/blob - riscasm.c
Version bump for last commit. :-)
[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 - 2017 Reboot and Friends
5 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
6 // Source utilised with the kind permission of Landon Dyer
7 //
8
9 #include "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 | (0 << 6) },
105         { MR_PACK,    RI_ONE,    63 + GPUONLY | (1 << 6) },
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 // Function to return "Illegal Indexed Register" error
136 // Anyone trying to index something other than R14 or R15
137 //
138 static inline int IllegalIndexedRegister(int reg)
139 {
140     char buf[16];
141     sprintf(buf, "%d", reg - KW_R0);
142     return errors("Attempted index reference with non-indexable register (r%s)", buf);
143 }
144
145 //
146 // Function to return "Illegal Indexed Register" error for EQUR scenarios
147 // Trying to use register value within EQUR that isn't 14 or 15
148 //
149 static inline int IllegalIndexedRegisterEqur(SYM *sy)
150 {
151     //char buf[160];
152     char *buf = NULL;
153     buf = (char *)malloc((strlen(sy->sname) + 7) * sizeof(char));
154     if (NULL != buf) {
155         sprintf(buf, "%s = r%d",sy->sname, sy->svalue);
156         return errors("Attempted index reference with non-indexable register within EQUR (%s)", buf);
157     }
158     return errors("Unable to allocate memory! (IllegalIndexRegisterEqur)", "OOPS");
159 }
160
161 //
162 // Build RISC instruction word
163 //
164 void BuildRISCIntructionWord(unsigned short opcode, int reg1, int reg2)
165 {
166         // Check for absolute address setting
167         if (!orgwarning && !orgactive)
168         {
169                 warn("RISC code generated with no origin defined");
170                 orgwarning = 1;
171         }
172
173         int value = ((opcode & 0x3F) << 10) + ((reg1 & 0x1F) << 5) + (reg2 & 0x1F);
174         D_word(value);
175 //printf("BuildRISC: opcode=$%X, reg1=$%X, reg2=$%X, final=$%04X\n", opcode, reg1, reg2, value);
176 }
177
178
179 //
180 // Get a RISC register
181 //
182 int GetRegister(WORD rattr)
183 {
184         VALUE eval;                                     // Expression value
185         WORD eattr;                                     // Expression attributes
186         SYM * esym;                                     // External symbol involved in expr.
187         TOKEN r_expr[EXPRSIZE];         // Expression token list
188
189         // Evaluate what's in the global "tok" buffer
190         if (expr(r_expr, &eval, &eattr, &esym) != OK)
191                 return ERROR;
192
193         if ((challoc - ch_size) < 4)
194                 chcheck(4L);
195
196         if (!(eattr & DEFINED))
197         {
198                 AddFixup((WORD)(FU_WORD | rattr), sloc, r_expr);
199                 return 0;
200         }
201
202         // If we got a register in range (0-31), return it
203         if ((eval >= 0) && (eval <= 31))
204                 return eval;
205
206         // Otherwise, it's out of range & we flag an error
207         return error(reg_err);
208 }
209
210
211 //
212 // Do RISC code generation
213 //
214 int GenerateRISCCode(int state)
215 {
216         int reg1;                                       // Register 1
217         int reg2;                                       // Register 2
218         int val = 0;                            // Constructed value
219         char scratch[80];
220         SYM * ccsym;
221         SYM * sy;
222         int i, commaFound;
223         TOKEN * t;
224         WORD attrflg;
225         int indexed;                            // Indexed register flag
226
227         VALUE eval;                                     // Expression value
228         WORD eattr;                                     // Expression attributes
229         SYM * esym;                                     // External symbol involved in expr.
230         TOKEN r_expr[EXPRSIZE];         // Expression token list
231
232         // Get opcode parameter and type
233         unsigned short parm = (WORD)(roptbl[state - 3000].parm);
234         unsigned type = roptbl[state - 3000].typ;
235         riscImmTokenSeen = 0;           // Set to "token not seen yet"
236
237         // Detect whether the opcode parmeter passed determines that the opcode is
238         // specific to only one of the RISC processors and ensure it is legal in
239         // the current code section. If not then show error and return.
240         if (((parm & GPUONLY) && rdsp) || ((parm & DSPONLY) && rgpu))
241                 return error("Opcode is not valid in this code section");
242
243         // Process RISC opcode
244         switch (type)
245         {
246         // No operand instructions
247         // NOP (57)
248         case RI_NONE:
249                 BuildRISCIntructionWord(parm, 0, 0);
250                 break;
251
252         // Single operand instructions (Rd)
253         // ABS, MIRROR, NEG, NOT, PACK, RESMAC, SAT8, SAT16, SAT16S, SAT24, SAT32S,
254         // UNPACK
255         case RI_ONE:
256                 reg2 = GetRegister(FU_REGTWO);
257                 at_eol();
258                 BuildRISCIntructionWord(parm, parm >> 6, reg2);
259                 break;
260
261         // Two operand instructions (Rs,Rd)
262         // ADD, ADDC, AND, CMP, DIV, IMACN, IMULT, IMULTN, MOVEFA, MOVETA, MULT,
263         // MMULT, MTOI, NORMI, OR, ROR, SH, SHA, SUB, SUBC, XOR
264         case RI_TWO:
265                 if (parm == 37)
266                         altbankok = 1;                      // MOVEFA
267
268                 reg1 = GetRegister(FU_REGONE);
269                 CHECK_COMMA;
270
271                 if (parm == 36)
272                         altbankok = 1;                      // MOVETA
273
274                 reg2 = GetRegister(FU_REGTWO);
275                 at_eol();
276                 BuildRISCIntructionWord(parm, reg1, reg2);
277                 break;
278
279         // Numeric operand (n,Rd) where n = -16..+15
280         // CMPQ
281         case RI_NUM_15:
282
283         // Numeric operand (n,Rd) where n = 0..31
284         // BCLR, BSET, BTST, MOVEQ
285         case RI_NUM_31:
286
287         // Numeric operand (n,Rd) where n = 1..32
288         // ADDQ, ADDQMOD, ADDQT, SHARQ, SHLQ, SHRQ, SUBQ, SUBQMOD, SUBQT, ROLQ,
289         // RORQ
290         case RI_NUM_32:
291                 switch (type)
292                 {
293                 case RI_NUM_15:
294                         reg1 = -16; reg2 = 15; attrflg = FU_NUM15;
295                         break;
296                 default:
297                 case RI_NUM_31:
298                         reg1 =   0; reg2 = 31; attrflg = FU_NUM31;
299                         break;
300                 case RI_NUM_32:
301                         reg1 =   1; reg2 = 32; attrflg = FU_NUM32;
302                         break;
303                 }
304
305                 if (parm & SUB32)
306                         attrflg |= FU_SUB32;
307
308                 if (*tok != '#')
309                         return MalformedOpcode(0x01);
310
311                 tok++;
312                 riscImmTokenSeen = 1;
313
314                 if (expr(r_expr, &eval, &eattr, &esym) != OK)
315                         return MalformedOpcode(0x02);
316
317                 if ((challoc - ch_size) < 4)
318                         chcheck(4L);
319
320                 if (!(eattr & DEFINED))
321                 {
322                         AddFixup((WORD)(FU_WORD | attrflg), sloc, r_expr);
323                         reg1 = 0;
324                 }
325                 else
326                 {
327                         if ((int)eval < reg1 || (int)eval > reg2)
328                                 return error("constant out of range");
329
330                         if (parm & SUB32)
331                                 reg1 = 32 - eval;
332                         else if (type == RI_NUM_32)
333                                 reg1 = (reg1 == 32 ? 0 : eval);
334                         else
335                                 reg1 = eval;
336                 }
337
338                 CHECK_COMMA;
339                 reg2 = GetRegister(FU_REGTWO);
340                 at_eol();
341                 BuildRISCIntructionWord(parm, reg1, reg2);
342                 break;
343
344         // Move Immediate--n,Rn--n in Second Word
345         case RI_MOVEI:
346                 if (*tok != '#')
347                         return MalformedOpcode(0x03);
348
349                 tok++;
350                 riscImmTokenSeen = 1;
351
352                 // Check for equated register after # and return error if so
353                 if (*tok == SYMBOL)
354                 {
355                         sy = lookup(string[tok[1]], LABEL, 0);
356
357                         if (sy && (sy->sattre & EQUATEDREG))
358                                 return error("equated register in 1st operand of MOVEI instruction");
359                 }
360
361                 if (expr(r_expr, &eval, &eattr, &esym) != OK)
362                         return MalformedOpcode(0x04);
363
364                 if (lastOpcode == RI_JUMP || lastOpcode == RI_JR)
365                 {
366                         if (legacy_flag)
367                         {
368                                 // User doesn't care, emit a NOP to fix
369                                 BuildRISCIntructionWord(57, 0, 0);
370                                 warn("MOVEI following JUMP, inserting NOP to fix your BROKEN CODE");
371                         }
372                         else
373                                 warn("MOVEI immediately follows JUMP");
374                 }
375
376                 if ((challoc - ch_size) < 4)
377                         chcheck(4L);
378
379                 if (!(eattr & DEFINED))
380                 {
381                         AddFixup(FU_LONG | FU_MOVEI, sloc + 2, r_expr);
382                         eval = 0;
383                 }
384                 else
385                 {
386                         if (eattr & TDB)
387 //{
388 //printf("RISCASM: Doing MarkRelocatable for RI_MOVEI (tdb=$%X)...\n", eattr & TDB);
389                                 MarkRelocatable(cursect, sloc + 2, (eattr & TDB), (MLONG | MMOVEI), NULL);
390 //}
391                 }
392
393 //              val = ((eval >> 16) & 0x0000FFFF) | ((eval << 16) & 0xFFFF0000);
394                 val = WORDSWAP32(eval);
395                 CHECK_COMMA;
396                 reg2 = GetRegister(FU_REGTWO);
397                 at_eol();
398                 D_word((((parm & 0x3F) << 10) + reg2));
399                 D_long(val);
400                 break;
401
402         // PC,Rd or Rs,Rd
403         case RI_MOVE:
404                 if (*tok == KW_PC)
405                 {
406                         parm = 51;
407                         reg1 = 0;
408                         tok++;
409                 }
410                 else
411                 {
412                         parm = 34;
413                         reg1 = GetRegister(FU_REGONE);
414                 }
415
416                 CHECK_COMMA;
417                 reg2 = GetRegister(FU_REGTWO);
418                 at_eol();
419                 BuildRISCIntructionWord(parm, reg1, reg2);
420                 break;
421
422         // (Rn),Rn = 41 / (R14/R15+n),Rn = 43/44 / (R14/R15+Rn),Rn = 58/59
423         case RI_LOAD:
424                 indexed = 0;
425                 parm = 41;
426
427                 if (*tok != '(')
428                         return MalformedOpcode(0x05);
429
430                 tok++;
431
432         if ((*(tok + 1) == '+') || (*(tok + 1) == '-')) {
433             // Trying to make indexed call
434             if ((*tok == KW_R14 || *tok == KW_R15)) {
435                 indexed = (*tok - KW_R0);
436             } else {
437                 return IllegalIndexedRegister(*tok);
438             }
439         }
440
441                 if (*tok == SYMBOL)
442                 {
443 //                      sy = lookup((char *)tok[1], LABEL, 0);
444                         sy = lookup(string[tok[1]], LABEL, 0);
445
446                         if (!sy)
447                         {
448                                 error(reg_err);
449                                 return ERROR;
450                         }
451
452                         if (sy->sattre & EQUATEDREG)
453                         {
454                                 if ((*(tok + 2) == '+') || (*(tok + 2) == '-')) {
455                                     if ((sy->svalue & 0x1F) == 14 || (sy->svalue & 0x1F) == 15) {
456                                         indexed = (sy->svalue & 0x1F);
457                         tok++;
458                                     } else {
459                                         return IllegalIndexedRegisterEqur(sy);
460                                     }
461                                 }
462                         }
463                 }
464
465                 if (!indexed)
466                 {
467                         reg1 = GetRegister(FU_REGONE);
468                 }
469                 else
470                 {
471                         reg1 = indexed;
472                         indexed = 0;
473                         tok++;
474
475                         if (*tok == '+')
476                         {
477                                 parm = (WORD)(reg1 - 14 + 58);
478                                 tok++;
479
480                                 if (*tok >= KW_R0 && *tok <= KW_R31)
481                                         indexed = 1;
482
483                                 if (*tok == SYMBOL)
484                                 {
485 //                                      sy = lookup((char *)tok[1], LABEL, 0);
486                                         sy = lookup(string[tok[1]], LABEL, 0);
487
488                                         if (!sy)
489                                         {
490                                                 error(reg_err);
491                                                 return ERROR;
492                                         }
493
494                                         if (sy->sattre & EQUATEDREG)
495                                                 indexed = 1;
496                                 }
497
498                                 if (indexed)
499                                 {
500                                         reg1 = GetRegister(FU_REGONE);
501                                 }
502                                 else
503                                 {
504                                         if (expr(r_expr, &eval, &eattr, &esym) != OK)
505                                                 return MalformedOpcode(0x06);
506
507                                         if ((challoc - ch_size) < 4)
508                                                 chcheck(4L);
509
510                                         if (!(eattr & DEFINED))
511                                                 return error("constant expected after '+'");
512
513                                         reg1 = eval;
514
515                                         if (reg1 == 0)
516                                         {
517                                                 reg1 = 14 + (parm - 58);
518                                                 parm = 41;
519                                                 warn("NULL offset in LOAD ignored");
520                                         }
521                                         else
522                                         {
523                                                 if (reg1 < 1 || reg1 > 32)
524                                                         return error("constant in LOAD out of range");
525
526                                                 if (reg1 == 32)
527                                                         reg1 = 0;
528
529                                                 parm = (WORD)(parm - 58 + 43);
530                                         }
531                                 }
532                         }
533                         else
534                         {
535                                 reg1 = GetRegister(FU_REGONE);
536                         }
537                 }
538
539                 if (*tok != ')')
540                         return MalformedOpcode(0x07);
541
542                 tok++;
543                 CHECK_COMMA;
544                 reg2 = GetRegister(FU_REGTWO);
545                 at_eol();
546                 BuildRISCIntructionWord(parm, reg1, reg2);
547                 break;
548
549         // Rn,(Rn) = 47 / Rn,(R14/R15+n) = 49/50 / Rn,(R14/R15+Rn) = 60/61
550         case RI_STORE:
551                 parm = 47;
552                 reg1 = GetRegister(FU_REGONE);
553                 CHECK_COMMA;
554
555                 if (*tok != '(')
556                         return MalformedOpcode(0x08);
557
558                 tok++;
559                 indexed = 0;
560
561                 if ((*tok == KW_R14 || *tok == KW_R15) && (*(tok + 1) != ')'))
562                         indexed = (*tok - KW_R0);
563
564                 if (*tok == SYMBOL)
565                 {
566                         sy = lookup(string[tok[1]], LABEL, 0);
567
568                         if (!sy)
569                         {
570                                 error(reg_err);
571                                 return ERROR;
572                         }
573
574                         if (sy->sattre & EQUATEDREG)
575                         {
576                                 if (((sy->svalue & 0x1F) == 14 || (sy->svalue & 0x1F) == 15)
577                                         && (*(tok + 2) != ')'))
578                                 {
579                                         indexed = (sy->svalue & 0x1F);
580                                         tok++;
581                                 }
582                         }
583                 }
584
585                 if (!indexed)
586                 {
587                         reg2 = GetRegister(FU_REGTWO);
588                 }
589                 else
590                 {
591                         reg2 = indexed;
592                         indexed = 0;
593                         tok++;
594
595                         if (*tok == '+')
596                         {
597                                 parm = (WORD)(reg2 - 14 + 60);
598                                 tok++;
599
600                                 if (*tok >= KW_R0 && *tok <= KW_R31)
601                                         indexed = 1;
602
603                                 if (*tok == SYMBOL)
604                                 {
605                                         sy = lookup(string[tok[1]], LABEL, 0);
606
607                                         if (!sy)
608                                         {
609                                                 error(reg_err);
610                                                 return ERROR;
611                                         }
612
613                                         if (sy->sattre & EQUATEDREG)
614                                                 indexed = 1;
615                                 }
616
617                                 if (indexed)
618                                 {
619                                         reg2 = GetRegister(FU_REGTWO);
620                                 }
621                                 else
622                                 {
623                                         if (expr(r_expr, &eval, &eattr, &esym) != OK)
624                                                 return MalformedOpcode(0x09);
625
626                                         if ((challoc - ch_size) < 4)
627                                                 chcheck(4L);
628
629                                         if (!(eattr & DEFINED))
630                                         {
631                                                 AddFixup(FU_WORD | FU_REGTWO, sloc, r_expr);
632                                                 reg2 = 0;
633                                         }
634                                         else
635                                         {
636                                                 reg2 = eval;
637
638                                                 if (reg2 == 0)
639                                                 {
640                                                         reg2 = 14 + (parm - 60);
641                                                         parm = 47;
642                                                         warn("NULL offset in STORE ignored");
643                                                 }
644                                                 else
645                                                 {
646                                                         if (reg2 < 1 || reg2 > 32)
647                                                                 return error("constant in STORE out of range");
648
649                                                         if (reg2 == 32)
650                                                                 reg2 = 0;
651
652                                                         parm = (WORD)(parm - 60 + 49);
653                                                 }
654                                         }
655                                 }
656                         }
657                         else
658                         {
659                                 reg2 = GetRegister(FU_REGTWO);
660                         }
661                 }
662
663                 if (*tok != ')')
664                         return MalformedOpcode(0x0A);
665
666                 tok++;
667                 at_eol();
668                 BuildRISCIntructionWord(parm, reg2, reg1);
669                 break;
670
671         // LOADB/LOADP/LOADW (Rn),Rn
672         case RI_LOADN:
673                 if (*tok != '(')
674                         return MalformedOpcode(0x0B);
675
676                 tok++;
677                 reg1 = GetRegister(FU_REGONE);
678
679                 if (*tok != ')')
680                         return MalformedOpcode(0x0C);
681
682                 tok++;
683                 CHECK_COMMA;
684                 reg2 = GetRegister(FU_REGTWO);
685                 at_eol();
686                 BuildRISCIntructionWord(parm, reg1, reg2);
687                 break;
688
689         // STOREB/STOREP/STOREW Rn,(Rn)
690         case RI_STOREN:
691                 reg1 = GetRegister(FU_REGONE);
692                 CHECK_COMMA;
693
694                 if (*tok != '(')
695                         return MalformedOpcode(0x0D);
696
697                 tok++;
698                 reg2 = GetRegister(FU_REGTWO);
699
700                 if (*tok != ')')
701                         return MalformedOpcode(0x0E);
702
703                 tok++;
704                 at_eol();
705                 BuildRISCIntructionWord(parm, reg2, reg1);
706                 break;
707
708         // Jump Relative - cc,n - n=-16..+15 words, reg2=cc
709         case RI_JR:
710
711         // Jump Absolute - cc,(Rs) - reg2=cc
712         case RI_JUMP:
713                 // Check to see if there is a comma in the token string. If not then
714                 // the JR or JUMP should default to 0, Jump Always
715                 commaFound = 0;
716
717                 for(t=tok; *t!=EOL; t++)
718                 {
719                         if (*t == ',')
720                         {
721                                 commaFound = 1;
722                                 break;
723                         }
724                 }
725
726                 if (commaFound)
727                 {
728                         if (*tok == CONST)
729                         {
730                                 // CC using a constant number
731                                 tok++;
732                                 val = *tok;
733                                 tok++;
734                                 CHECK_COMMA;
735                         }
736                         else if (*tok == SYMBOL)
737                         {
738                                 val = 99;
739 //                              strcpy(scratch, (char *)tok[1]);
740                                 strcpy(scratch, string[tok[1]]);
741                                 strtoupper(scratch);
742
743                                 for(i=0; i<MAXINTERNCC; i++)
744                                 {
745                                         // Look for the condition code & break if found
746                                         if (strcmp(condname[i], scratch) == 0)
747                                         {
748                                                 val = condnumber[i];
749                                                 break;
750                                         }
751                                 }
752
753                                 // Standard CC was not found, look for an equated one
754                                 if (val == 99)
755                                 {
756 //                                      ccsym = lookup((char *)tok[1], LABEL, 0);
757                                         ccsym = lookup(string[tok[1]], LABEL, 0);
758
759                                         if (ccsym && (ccsym->sattre & EQUATEDCC) && !(ccsym->sattre & UNDEF_CC))
760                                         {
761                                                 val = ccsym->svalue;
762                                         }
763                                         else
764                                                 return error("unknown condition code");
765                                 }
766
767                                 tok += 2;
768                                 CHECK_COMMA;
769                         }
770                         else if (*tok == '(')
771                         {
772                                 // Set CC to "Jump Always"
773                                 val = 0;
774                         }
775                 }
776                 else
777                 {
778                         // Set CC to "Jump Always"
779                         val = 0;
780                 }
781
782                 if (val < 0 || val > 31)
783                         return error("condition constant out of range");
784
785                 // Store condition code
786                 reg1 = val;
787
788                 if (type == RI_JR)
789                 {
790                         // JR cc,n
791                         if (expr(r_expr, &eval, &eattr, &esym) != OK)
792                                 return MalformedOpcode(0x0F);
793
794                         if ((challoc - ch_size) < 4)
795                                 chcheck(4L);
796
797                         if (!(eattr & DEFINED))
798                         {
799                                 AddFixup(FU_WORD | FU_JR, sloc, r_expr);
800                                 reg2 = 0;
801                         }
802                         else
803                         {
804                                 reg2 = ((int)(eval - ((orgactive ? orgaddr : sloc) + 2))) / 2;
805
806                                 if ((reg2 < -16) || (reg2 > 15))
807                                         error("PC relative overflow");
808                         }
809
810                         BuildRISCIntructionWord(parm, reg2, reg1);
811                 }
812                 else
813                 {
814                         // JUMP cc, (Rn)
815                         if (*tok != '(')
816                                 return MalformedOpcode(0x10);
817
818                         tok++;
819                         reg2 = GetRegister(FU_REGTWO);
820
821                         if (*tok != ')')
822                                 return MalformedOpcode(0x11);
823
824                         tok++;
825                         at_eol();
826                         BuildRISCIntructionWord(parm, reg2, reg1);
827                 }
828
829                 break;
830
831         // Should never get here :-D
832         default:
833                 return error("Unknown RISC opcode type");
834         }
835
836         lastOpcode = type;
837         return 0;
838 }
839