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