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