]> Shamusworld >> Repos - rmac/blob - risca.c
Added win32 cross-compilation script.
[rmac] / risca.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 "risca.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                          // Declar 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
30 char reg_err[] = "missing register R0...R31";
31
32 // Jaguar Jump Condition Names
33 char condname[MAXINTERNCC][5] = { 
34         "NZ", "Z", "NC", "NCNZ", "NCZ", "C", "CNZ", "CZ", "NN", "NNNZ", "NNZ",
35         "N", "N_NZ", "N_Z ", "T", "A", "NE", "EQ", "CC", "HS", "HI", "CS", "LO",
36         "PL", "MI", "F"
37 };
38
39 // Jaguar Jump Condition Numbers
40 char condnumber[] = {
41         1, 2, 4, 5, 6, 8, 9, 10, 20, 21, 22, 24, 25, 26,
42         0, 0, 1, 2, 4, 4, 5,  8,  8, 20, 24, 31
43 };
44
45 struct opcoderecord roptbl[] = {
46         { MR_ADD,     RI_TWO,    0 },
47         { MR_ADDC,    RI_TWO,    1 },
48         { MR_ADDQ,    RI_NUM_32, 2 },
49         { MR_ADDQT,   RI_NUM_32, 3 },
50         { MR_SUB,     RI_TWO,    4 },
51         { MR_SUBC,    RI_TWO,    5 },
52         { MR_SUBQ,    RI_NUM_32, 6 },
53         { MR_SUBQT,   RI_NUM_32, 7 },
54         { MR_NEG,     RI_ONE,    8 },
55         { MR_AND,     RI_TWO,    9 },
56         { MR_OR,      RI_TWO,    10 },
57         { MR_XOR,     RI_TWO,    11 },
58         { MR_NOT,     RI_ONE,    12 },
59         { MR_BTST,    RI_NUM_31, 13 },
60         { MR_BSET,    RI_NUM_31, 14 },
61         { MR_BCLR,    RI_NUM_31, 15 },
62         { MR_MULT,    RI_TWO,    16 },
63         { MR_IMULT,   RI_TWO,    17 },
64         { MR_IMULTN,  RI_TWO,    18 },
65         { MR_RESMAC,  RI_ONE,    19 },
66         { MR_IMACN,   RI_TWO,    20 },
67         { MR_DIV,     RI_TWO,    21 },
68         { MR_ABS,     RI_ONE,    22 },
69         { MR_SH,      RI_TWO,    23 },
70         { MR_SHLQ,    RI_NUM_32, 24 + SUB32 },
71         { MR_SHRQ,    RI_NUM_32, 25 },
72         { MR_SHA,     RI_TWO,    26 },
73         { MR_SHARQ,   RI_NUM_32, 27 },
74         { MR_ROR,     RI_TWO,    28 },
75         { MR_RORQ,    RI_NUM_32, 29 },
76         { MR_ROLQ,    RI_NUM_32, 29 + SUB32 },
77         { MR_CMP,     RI_TWO,    30 },
78         { MR_CMPQ,    RI_NUM_15, 31 },
79         { MR_SAT8,    RI_ONE,    32 + GPUONLY },
80         { MR_SUBQMOD, RI_NUM_32, 32 + DSPONLY },
81         { MR_SAT16,   RI_ONE,    33 + GPUONLY },
82         { MR_SAT16S,  RI_ONE,    33 + DSPONLY },
83         { MR_MOVEQ,   RI_NUM_31, 35 },
84         { MR_MOVETA,  RI_TWO,    36 },
85         { MR_MOVEFA,  RI_TWO,    37 },
86         { MR_MOVEI,   RI_MOVEI,  38 },
87         { MR_LOADB,   RI_LOADN,  39 },
88         { MR_LOADW,   RI_LOADN,  40 },
89         { MR_LOADP,   RI_LOADN,  42 + GPUONLY },
90         { MR_SAT32S,  RI_ONE,    42 + DSPONLY },
91         { MR_STOREB,  RI_STOREN, 45 },
92         { MR_STOREW,  RI_STOREN, 46 },
93         { MR_STOREP,  RI_STOREN, 48 + GPUONLY },
94         { MR_MIRROR,  RI_ONE,    48 + DSPONLY },
95         { MR_JUMP,    RI_JUMP,   52 },
96         { MR_JR,      RI_JR,     53 },
97         { MR_MMULT,   RI_TWO,    54 },
98         { MR_MTOI,    RI_TWO,    55 },
99         { MR_NORMI,   RI_TWO,    56 },
100         { MR_NOP,     RI_NONE,   57 },
101         { MR_SAT24,   RI_ONE,    62 },
102         { MR_UNPACK,  RI_ONE,    63 + GPUONLY },
103         { MR_PACK,    RI_ONE,    63 + GPUONLY },
104         { MR_ADDQMOD, RI_NUM_32, 63 + DSPONLY },
105         { MR_MOVE,    RI_MOVE,   0 },
106         { MR_LOAD,    RI_LOAD,   0 },
107         { MR_STORE,   RI_STORE,  0 }
108 };
109
110
111 //
112 // Convert a String to Uppercase
113 //
114 void strtoupper(char * s)
115 {
116 #if 0
117         while (*s)
118         {
119                 *s = (char)(toupper(*s));
120                 s++;
121         }
122 #else
123         while (*s)
124                 *s++ &= 0xDF;
125 #endif
126 }
127
128
129 //
130 // Function to return "malformed expression" error
131 // This is done mainly to remove a bunch of GOTO statements in the parser
132 //
133 static inline int MalformedOpcode(void)
134 {
135         error("Malformed opcode");
136         return ERROR;
137 }
138
139
140 //
141 // Build RISC Instruction Word
142 //
143 void BuildRISCIntructionWord(unsigned short opcode, int reg1, int reg2)
144 {
145         // Check for absolute address setting
146         if (!orgwarning && !orgactive)
147         {
148                 warn("GPU/DSP code outside of absolute section");
149                 orgwarning = 1;
150         }
151
152         int value = ((opcode & 0x3F) << 10) + ((reg1 & 0x1F) << 5) + (reg2 & 0x1F);
153         D_word(value);
154 }
155
156
157 //
158 // Get a RISC Register
159 //
160 int GetRegister(WORD rattr)
161 {
162         VALUE eval;                                     // Expression value
163         WORD eattr;                                     // Expression attributes
164         SYM * esym;                                     // External symbol involved in expr.
165         TOKEN r_expr[EXPRSIZE];         // Expression token list
166
167         // Evaluate what's in the global "tok" buffer
168         if (expr(r_expr, &eval, &eattr, &esym) != OK)
169                 return MalformedOpcode();
170
171         if ((challoc - ch_size) < 4)
172                 chcheck(4L);
173
174         if (!(eattr & DEFINED))
175         {
176                 fixup((WORD)(FU_WORD | rattr), sloc, r_expr);      
177                 return 0;
178         }
179
180         // If we got a register in range (0-31), return it
181         if ((eval >= 0) && (eval <= 31))
182                 return eval;
183
184         // Otherwise, it's out of range & we flag an error
185         error(reg_err);
186         return ERROR;
187 }
188
189
190 //
191 // Do RISC Code Generation
192 //
193 int GenerateRISCCode(int state)
194 {
195         int reg1;                                       // Register 1
196         int reg2;                                       // Register 2
197         int val = 0;                            // Constructed value
198         char scratch[80];
199         SYM * ccsym;
200         SYM * sy;
201         int i, commaFound;
202         TOKEN * t;
203         WORD tdb;
204         WORD attrflg;
205         int indexed;                            // Indexed register flag
206
207         VALUE eval;                                     // Expression value
208         WORD eattr;                                     // Expression attributes
209         SYM * esym;                                     // External symbol involved in expr.
210         TOKEN r_expr[EXPRSIZE];         // Expression token list
211
212         // Get opcode parameter and type
213         unsigned short parm = (WORD)(roptbl[state - 3000].parm);
214         unsigned type = roptbl[state - 3000].typ;
215
216         // Detect whether the opcode parmeter passed determines that the opcode is
217         // specific to only one of the RISC processors and ensure it is legal in
218         // the current code section. If not then show error and return.
219         if (((parm & GPUONLY) && rdsp) || ((parm & DSPONLY) && rgpu))
220         {
221                 error("Opcode is not valid in this code section");
222                 return ERROR;
223         }
224
225         // Process RISC opcode
226         switch (type)
227         {
228         // No operand instructions
229         // NOP
230         case RI_NONE: 
231                 BuildRISCIntructionWord(parm, 0, 0);
232                 break;
233
234         // Single operand instructions (Rd)
235         // ABS, MIRROR, NEG, NOT, PACK, RESMAC, SAT8, SAT16, SAT16S, SAT24, SAT32S, UNPACK
236         case RI_ONE:
237                 reg2 = GetRegister(FU_REGTWO);
238                 at_eol();
239                 BuildRISCIntructionWord(parm, parm >> 6, reg2);
240                 break;   
241
242         // Two operand instructions (Rs,Rd)
243         // ADD, ADDC, AND, CMP, DIV, IMACN, IMULT, IMULTN, MOVEFA, MOVETA, MULT, MMULT, 
244         // MTOI, NORMI, OR, ROR, SH, SHA, SUB, SUBC, XOR
245         case RI_TWO:                      
246                 if (parm == 37)
247                         altbankok = 1;                      // MOVEFA
248
249                 reg1 = GetRegister(FU_REGONE);
250                 CHECK_COMMA;         
251
252                 if (parm == 36)
253                         altbankok = 1;                      // MOVETA
254
255                 reg2 = GetRegister(FU_REGTWO);
256                 at_eol();
257                 BuildRISCIntructionWord(parm, reg1, reg2);
258                 break;
259
260         // Numeric operand (n,Rd) where n = -16..+15
261         // CMPQ
262         case RI_NUM_15:
263
264         // Numeric operand (n,Rd) where n = 0..31
265         // BCLR, BSET, BTST, MOVEQ
266         case RI_NUM_31:
267
268         // Numeric operand (n,Rd) where n = 1..32
269         // ADDQ, ADDQMOD, ADDQT, SHARQ, SHLQ, SHRQ, SUBQ, SUBQMOD, SUBQT, ROLQ, RORQ
270         case RI_NUM_32:
271                 switch (type)
272                 {
273                 case RI_NUM_15:
274                         reg1 = -16; reg2 = 15; attrflg = FU_NUM15;
275                         break;
276                 default:
277                 case RI_NUM_31:
278                         reg1 =   0; reg2 = 31; attrflg = FU_NUM31;
279                         break;
280                 case RI_NUM_32:
281                         reg1 =   1; reg2 = 32; attrflg = FU_NUM32;
282                         break;
283                 }
284
285                 if (parm & SUB32)
286                         attrflg |= FU_SUB32;
287
288                 if (*tok != '#')
289                         return MalformedOpcode();
290
291                 tok++;
292
293                 if (expr(r_expr, &eval, &eattr, &esym) != OK)
294                         return MalformedOpcode();
295
296                 if ((challoc - ch_size) < 4)
297                         chcheck(4L);
298
299                 if (!(eattr & DEFINED))
300                 {
301                         fixup((WORD)(FU_WORD | attrflg), sloc, r_expr);
302                         reg1 = 0;
303                 }
304                 else
305                 {
306                         if ((int)eval < reg1 || (int)eval > reg2)
307                         {
308                                 error("constant out of range");
309                                 return ERROR;
310                         }
311
312                         if (parm & SUB32) 
313                                 reg1 = 32 - eval; 
314                         else if (type == RI_NUM_32)
315                                 reg1 = (reg1 == 32 ? 0 : eval);
316                         else
317                                 reg1 = eval;
318                 }
319
320                 CHECK_COMMA;
321                 reg2 = GetRegister(FU_REGTWO);
322                 at_eol();
323                 BuildRISCIntructionWord(parm, reg1, reg2);
324                 break;
325
326         // Move Immediate--n,Rn--n in Second Word
327         case RI_MOVEI:
328                 if (*tok != '#')
329                         return MalformedOpcode();
330
331                 tok++;
332
333                 if (expr(r_expr, &eval, &eattr, &esym) != OK)
334                         return MalformedOpcode();
335
336                 if ((challoc - ch_size) < 4)
337                         chcheck(4L);
338
339                 if (!(eattr & DEFINED))
340                 {
341                         fixup(FU_LONG | FU_MOVEI, sloc + 2, r_expr);
342                         eval = 0;
343                 }
344                 else
345                 {
346                         if (eattr & TDB)
347                                 rmark(cursect, sloc + 2, tdb, MLONG | MMOVEI, NULL);
348                 }       
349
350 //              val = eval;
351                 val = ((eval >> 16) & 0x0000FFFF) | ((eval << 16) & 0xFFFF0000);
352 //              tok++;  // assuming a comma here? tsk tsk
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();
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();
456
457                                         if ((challoc - ch_size) < 4)
458                                                 chcheck(4L);
459
460                                         if (!(eattr & DEFINED))
461                                         {
462                                                 error("constant expected");
463                                                 return ERROR;
464                                         }
465
466                                         reg1 = eval;
467
468                                         if (reg1 == 0)
469                                         {
470                                                 reg1 = 14 + (parm - 58);
471                                                 parm = 41;
472                                                 warn("NULL offset removed");
473                                         }
474                                         else
475                                         {
476                                                 if (reg1 < 1 || reg1 > 32)
477                                                 {
478                                                         error("constant out of range");
479                                                         return ERROR;
480                                                 }
481
482                                                 if (reg1 == 32)
483                                                         reg1 = 0;
484
485                                                 parm = (WORD)(parm - 58 + 43);
486                                         }
487                                 }
488                         }
489                         else
490                         {
491                                 reg1 = GetRegister(FU_REGONE);
492                         }
493                 }
494
495                 if (*tok != ')')
496                         return MalformedOpcode();
497
498                 tok++;
499                 CHECK_COMMA;
500                 reg2 = GetRegister(FU_REGTWO);
501                 at_eol();
502                 BuildRISCIntructionWord(parm, reg1, reg2);
503                 break;
504
505         // Rn,(Rn) = 47 / Rn,(R14/R15+n) = 49/50 / Rn,(R14/R15+Rn) = 60/61
506         case RI_STORE:    
507                 parm = 47;
508                 reg1 = GetRegister(FU_REGONE);
509                 CHECK_COMMA;
510
511                 if (*tok != '(')
512                         return MalformedOpcode();
513
514                 tok++;
515                 indexed = 0;
516
517                 if ((*tok == KW_R14 || *tok == KW_R15) && (*(tok + 1) != ')')) 
518                         indexed = (*tok - KW_R0);
519
520                 if (*tok == SYMBOL)
521                 {
522 //                      sy = lookup((char *)tok[1], LABEL, 0);
523                         sy = lookup(string[tok[1]], LABEL, 0);
524
525                         if (!sy)
526                         {
527                                 error(reg_err);
528                                 return ERROR;
529                         }
530
531                         if (sy->sattre & EQUATEDREG) 
532                         {
533                                 if (((sy->svalue & 0x1F) == 14 || (sy->svalue & 0x1F) == 15)
534                                         && (*(tok + 2) != ')'))
535                                 {
536                                         indexed = (sy->svalue & 0x1F);
537                                         tok++;
538                                 }
539                         }
540                 }
541
542                 if (!indexed)
543                 {
544                         reg2 = GetRegister(FU_REGTWO);
545                 }
546                 else
547                 {
548                         reg2 = indexed;
549                         indexed = 0;
550                         tok++;
551
552                         if (*tok == '+')
553                         {
554                                 parm = (WORD)(reg2 - 14 + 60);
555                                 tok++;
556
557                                 if (*tok >= KW_R0 && *tok <= KW_R31)
558                                         indexed = 1;
559
560                                 if (*tok == SYMBOL)
561                                 {
562 //                                      sy = lookup((char *)tok[1], LABEL, 0);
563                                         sy = lookup(string[tok[1]], LABEL, 0);
564
565                                         if (!sy)
566                                         {
567                                                 error(reg_err);
568                                                 return ERROR;
569                                         }
570
571                                         if (sy->sattre & EQUATEDREG)
572                                                 indexed = 1;
573                                 }
574
575                                 if (indexed)
576                                 {
577                                         reg2 = GetRegister(FU_REGTWO);
578                                 }
579                                 else
580                                 {
581                                         if (expr(r_expr, &eval, &eattr, &esym) != OK)
582                                                 return MalformedOpcode();
583
584                                         if ((challoc - ch_size) < 4)
585                                                 chcheck(4L);
586
587                                         if (!(eattr & DEFINED))
588                                         {
589                                                 fixup(FU_WORD | FU_REGTWO, sloc, r_expr);
590                                                 reg2 = 0;
591                                         }
592                                         else
593                                         {
594                                                 reg2 = eval;
595
596                                                 if (reg2 == 0)
597                                                 {
598                                                         reg2 = 14 + (parm - 60);
599                                                         parm = 47;
600                                                         warn("NULL offset removed");
601                                                 }
602                                                 else
603                                                 {
604                                                         if (reg2 < 1 || reg2 > 32)
605                                                         {
606                                                                 error("constant out of range");
607                                                                 return ERROR;
608                                                         }
609
610                                                         if (reg2 == 32)
611                                                                 reg2 = 0;
612
613                                                         parm = (WORD)(parm - 60 + 49);
614                                                 }
615                                         }
616                                 }
617                         }
618                         else
619                         {
620                                 reg2 = GetRegister(FU_REGTWO);
621                         }
622                 }
623
624                 if (*tok != ')')
625                         return MalformedOpcode();
626
627                 tok++;
628                 at_eol();
629                 BuildRISCIntructionWord(parm, reg2, reg1);
630                 break;
631
632         // LOADB/LOADP/LOADW (Rn),Rn
633         case RI_LOADN:                    
634                 if (*tok != '(')
635                         return MalformedOpcode();
636
637                 tok++;
638                 reg1 = GetRegister(FU_REGONE);
639
640                 if (*tok != ')')
641                         return MalformedOpcode();
642
643                 tok++;
644                 CHECK_COMMA;
645                 reg2 = GetRegister(FU_REGTWO);
646                 at_eol();
647                 BuildRISCIntructionWord(parm, reg1, reg2);
648                 break;
649
650         // STOREB/STOREP/STOREW Rn,(Rn)
651         case RI_STOREN:                   
652                 reg1 = GetRegister(FU_REGONE);
653                 CHECK_COMMA;
654
655                 if (*tok != '(')
656                         return MalformedOpcode();
657
658                 tok++;
659                 reg2 = GetRegister(FU_REGTWO);
660
661                 if (*tok != ')')
662                         return MalformedOpcode();
663
664                 tok++;
665                 at_eol();
666                 BuildRISCIntructionWord(parm, reg2, reg1);
667                 break;
668
669         // Jump Relative - cc,n - n=-16..+15 words, reg2=cc
670         case RI_JR:
671
672         // Jump Absolute - cc,(Rs) - reg2=cc
673         case RI_JUMP:
674                 // Check to see if there is a comma in the token string. If not then
675                 // the JR or JUMP should default to 0, Jump Always
676                 commaFound = 0;
677
678                 for(t=tok; *t!=EOL; t++)
679                 {
680                         if (*t == ',')
681                         {
682                                 commaFound = 1;
683                                 break;
684                         }
685                 }
686
687                 if (commaFound)
688                 {
689                         if (*tok == CONST)
690                         {
691                                 // CC using a constant number
692                                 tok++;
693                                 val = *tok;
694                                 tok++;
695                                 CHECK_COMMA;
696                         }
697                         else if (*tok == SYMBOL)
698                         {
699                                 val = 99;
700 //                              strcpy(scratch, (char *)tok[1]);
701                                 strcpy(scratch, string[tok[1]]);
702                                 strtoupper(scratch);
703
704                                 for(i=0; i<MAXINTERNCC; i++)
705                                 {
706                                         // Look for the condition code & break if found
707                                         if (strcmp(condname[i], scratch) == 0)
708                                         {
709                                                 val = condnumber[i];
710                                                 break;
711                                         }
712                                 }
713
714                                 // Standard CC was not found, look for an equated one
715                                 if (val == 99)
716                                 {
717 //                                      ccsym = lookup((char *)tok[1], LABEL, 0);
718                                         ccsym = lookup(string[tok[1]], LABEL, 0);
719
720                                         if (ccsym && (ccsym->sattre & EQUATEDCC) && !(ccsym->sattre & UNDEF_CC))
721                                         {
722                                                 val = ccsym->svalue;
723                                         }
724                                         else
725                                         {
726                                                 error("unknown condition code");
727                                                 return ERROR;
728                                         }
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                 {
748                         error("condition constant out of range");
749                         return ERROR;
750                 }
751
752                 // Store condition code
753                 reg1 = val;
754
755                 if (type == RI_JR)
756                 {
757                         // JR cc,n
758                         if (expr(r_expr, &eval, &eattr, &esym) != OK)
759                                 return MalformedOpcode();
760
761                         if ((challoc - ch_size) < 4)
762                                 chcheck(4L);
763
764                         if (!(eattr & DEFINED))
765                         {
766                                 fixup(FU_WORD | FU_JR, sloc, r_expr);
767                                 reg2 = 0;
768                         }
769                         else
770                         {
771 #if 0
772                                 val = eval;
773
774                                 if (orgactive)
775                                         reg2 = ((int)(val - (orgaddr + 2))) / 2;
776                                 else
777                                         reg2 = ((int)(val - (sloc + 2))) / 2;
778 #else
779                                 reg2 = ((int)(eval - ((orgactive ? orgaddr : sloc) + 2))) / 2;
780 #endif
781
782                                 if ((reg2 < -16) || (reg2 > 15))
783                                         error("PC relative overflow");
784                         }
785
786                         BuildRISCIntructionWord(parm, reg2, reg1);
787                 }
788                 else
789                 {
790                         // JUMP cc, (Rn)
791                         if (*tok != '(')
792                                 return MalformedOpcode();
793
794                         tok++;
795                         reg2 = GetRegister(FU_REGTWO);
796
797                         if (*tok != ')')
798                                 return MalformedOpcode();
799
800                         tok++;
801                         at_eol();
802                         BuildRISCIntructionWord(parm, reg2, reg1);
803                 }
804
805                 break;
806
807         // Should never get here :-D
808         default:
809                 error("Unknown risc opcode type");
810                 return ERROR;
811         }
812
813         return 0;
814 }
815