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