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