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