]> Shamusworld >> Repos - rmac/blob - riscasm.c
Fix for extraneous newlines in .print directive.
[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                          // 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 int lastOpcode = -1;            // Last RISC opcode assembled
30
31 char reg_err[] = "missing register R0...R31";
32
33 // Jaguar Jump Condition Names
34 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 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 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         errors("Malformed opcode [internal $%s]", buf);
131         return ERROR;
132 }
133
134
135 //
136 // Build RISC Instruction Word
137 //
138 void BuildRISCIntructionWord(unsigned short opcode, int reg1, int reg2)
139 {
140         // Check for absolute address setting
141         if (!orgwarning && !orgactive)
142         {
143                 warn("GPU/DSP code outside of absolute section");
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                 // Hmm, the evaluator should report the error to us...
165 //              return MalformedOpcode(0x00);
166                 return ERROR;
167
168         if ((challoc - ch_size) < 4)
169                 chcheck(4L);
170
171         if (!(eattr & DEFINED))
172         {
173                 fixup((WORD)(FU_WORD | rattr), sloc, r_expr);      
174                 return 0;
175         }
176
177         // If we got a register in range (0-31), return it
178         if ((eval >= 0) && (eval <= 31))
179                 return eval;
180
181         // Otherwise, it's out of range & we flag an error
182         error(reg_err);
183         return ERROR;
184 }
185
186
187 //
188 // Do RISC Code Generation
189 //
190 int GenerateRISCCode(int state)
191 {
192         int reg1;                                       // Register 1
193         int reg2;                                       // Register 2
194         int val = 0;                            // Constructed value
195         char scratch[80];
196         SYM * ccsym;
197         SYM * sy;
198         int i, commaFound;
199         TOKEN * t;
200         WORD attrflg;
201         int indexed;                            // Indexed register flag
202
203         VALUE eval;                                     // Expression value
204         WORD eattr;                                     // Expression attributes
205         SYM * esym;                                     // External symbol involved in expr.
206         TOKEN r_expr[EXPRSIZE];         // Expression token list
207
208         // Get opcode parameter and type
209         unsigned short parm = (WORD)(roptbl[state - 3000].parm);
210         unsigned type = roptbl[state - 3000].typ;
211
212         // Detect whether the opcode parmeter passed determines that the opcode is
213         // specific to only one of the RISC processors and ensure it is legal in
214         // the current code section. If not then show error and return.
215         if (((parm & GPUONLY) && rdsp) || ((parm & DSPONLY) && rgpu))
216         {
217                 error("Opcode is not valid in this code section");
218                 return ERROR;
219         }
220
221         // Process RISC opcode
222         switch (type)
223         {
224         // No operand instructions
225         // NOP (57)
226         case RI_NONE:
227                 BuildRISCIntructionWord(parm, 0, 0);
228                 break;
229
230         // Single operand instructions (Rd)
231         // ABS, MIRROR, NEG, NOT, PACK, RESMAC, SAT8, SAT16, SAT16S, SAT24, SAT32S, UNPACK
232         case RI_ONE:
233                 reg2 = GetRegister(FU_REGTWO);
234                 at_eol();
235                 BuildRISCIntructionWord(parm, parm >> 6, reg2);
236                 break;   
237
238         // Two operand instructions (Rs,Rd)
239         // ADD, ADDC, AND, CMP, DIV, IMACN, IMULT, IMULTN, MOVEFA, MOVETA, MULT, MMULT, 
240         // MTOI, NORMI, OR, ROR, SH, SHA, SUB, SUBC, XOR
241         case RI_TWO:                      
242                 if (parm == 37)
243                         altbankok = 1;                      // MOVEFA
244
245                 reg1 = GetRegister(FU_REGONE);
246                 CHECK_COMMA;         
247
248                 if (parm == 36)
249                         altbankok = 1;                      // MOVETA
250
251                 reg2 = GetRegister(FU_REGTWO);
252                 at_eol();
253                 BuildRISCIntructionWord(parm, reg1, reg2);
254                 break;
255
256         // Numeric operand (n,Rd) where n = -16..+15
257         // CMPQ
258         case RI_NUM_15:
259
260         // Numeric operand (n,Rd) where n = 0..31
261         // BCLR, BSET, BTST, MOVEQ
262         case RI_NUM_31:
263
264         // Numeric operand (n,Rd) where n = 1..32
265         // ADDQ, ADDQMOD, ADDQT, SHARQ, SHLQ, SHRQ, SUBQ, SUBQMOD, SUBQT, ROLQ, RORQ
266         case RI_NUM_32:
267                 switch (type)
268                 {
269                 case RI_NUM_15:
270                         reg1 = -16; reg2 = 15; attrflg = FU_NUM15;
271                         break;
272                 default:
273                 case RI_NUM_31:
274                         reg1 =   0; reg2 = 31; attrflg = FU_NUM31;
275                         break;
276                 case RI_NUM_32:
277                         reg1 =   1; reg2 = 32; attrflg = FU_NUM32;
278                         break;
279                 }
280
281                 if (parm & SUB32)
282                         attrflg |= FU_SUB32;
283
284                 if (*tok != '#')
285                         return MalformedOpcode(0x01);
286
287                 tok++;
288
289                 if (expr(r_expr, &eval, &eattr, &esym) != OK)
290                         return MalformedOpcode(0x02);
291
292                 if ((challoc - ch_size) < 4)
293                         chcheck(4L);
294
295                 if (!(eattr & DEFINED))
296                 {
297                         fixup((WORD)(FU_WORD | attrflg), sloc, r_expr);
298                         reg1 = 0;
299                 }
300                 else
301                 {
302                         if ((int)eval < reg1 || (int)eval > reg2)
303                         {
304                                 error("constant out of range");
305                                 return ERROR;
306                         }
307
308                         if (parm & SUB32) 
309                                 reg1 = 32 - eval; 
310                         else if (type == RI_NUM_32)
311                                 reg1 = (reg1 == 32 ? 0 : eval);
312                         else
313                                 reg1 = eval;
314                 }
315
316                 CHECK_COMMA;
317                 reg2 = GetRegister(FU_REGTWO);
318                 at_eol();
319                 BuildRISCIntructionWord(parm, reg1, reg2);
320                 break;
321
322         // Move Immediate--n,Rn--n in Second Word
323         case RI_MOVEI:
324                 if (*tok != '#')
325                         return MalformedOpcode(0x03);
326
327                 tok++;
328
329                 if (expr(r_expr, &eval, &eattr, &esym) != OK)
330                         return MalformedOpcode(0x04);
331
332                 if (lastOpcode == RI_JUMP || lastOpcode == RI_JR)
333                 {
334                         if (legacy_flag)
335                         {
336                                 // User doesn't care, emit a NOP to fix
337                                 BuildRISCIntructionWord(57, 0, 0);
338                                 warn("MOVEI following JUMP, inserting NOP to fix your BROKEN CODE");
339                         }
340                         else
341                                 warn("MOVEI immediately follows JUMP");
342                 }
343
344                 if ((challoc - ch_size) < 4)
345                         chcheck(4L);
346
347                 if (!(eattr & DEFINED))
348                 {
349                         fixup(FU_LONG | FU_MOVEI, sloc + 2, r_expr);
350                         eval = 0;
351                 }
352                 else
353                 {
354                         if (eattr & TDB)
355 //{
356 //printf("risca: Doing rmark for RI_MOVEI (tdb=$%X)...\n", eattr & TDB);
357                                 rmark(cursect, sloc + 2, (eattr & TDB), (MLONG | MMOVEI), NULL);
358 //}
359                 }
360
361                 val = ((eval >> 16) & 0x0000FFFF) | ((eval << 16) & 0xFFFF0000);
362                 CHECK_COMMA;
363                 reg2 = GetRegister(FU_REGTWO);
364                 at_eol();
365                 D_word((((parm & 0x3F) << 10) + reg2));
366                 D_long(val);
367                 break;
368
369         // PC,Rd or Rs,Rd
370         case RI_MOVE:
371                 if (*tok == KW_PC)
372                 {
373                         parm = 51;
374                         reg1 = 0;
375                         tok++;
376                 }
377                 else
378                 {
379                         parm = 34;
380                         reg1 = GetRegister(FU_REGONE);
381                 }
382
383                 CHECK_COMMA;
384                 reg2 = GetRegister(FU_REGTWO);
385                 at_eol();
386                 BuildRISCIntructionWord(parm, reg1, reg2);
387                 break;
388
389         // (Rn),Rn = 41 / (R14/R15+n),Rn = 43/44 / (R14/R15+Rn),Rn = 58/59
390         case RI_LOAD:          
391                 indexed = 0;
392                 parm = 41;
393
394                 if (*tok != '(')
395                         return MalformedOpcode(0x05);
396
397                 tok++;
398
399                 if ((*tok == KW_R14 || *tok == KW_R15) && (*(tok + 1) != ')')) 
400                         indexed = (*tok - KW_R0);
401
402                 if (*tok == SYMBOL)
403                 {
404 //                      sy = lookup((char *)tok[1], LABEL, 0);
405                         sy = lookup(string[tok[1]], LABEL, 0);
406
407                         if (!sy)
408                         {
409                                 error(reg_err);
410                                 return ERROR;
411                         }
412
413                         if (sy->sattre & EQUATEDREG)
414                         {
415                                 if (((sy->svalue & 0x1F) == 14 || (sy->svalue & 0x1F) == 15)
416                                         && (*(tok + 2) != ')'))
417                                 {
418                                         indexed = (sy->svalue & 0x1F);
419                                         tok++;
420                                 }
421                         }
422                 }
423
424                 if (!indexed)
425                 {
426                         reg1 = GetRegister(FU_REGONE);
427                 }
428                 else
429                 {
430                         reg1 = indexed;
431                         indexed = 0;
432                         tok++;
433
434                         if (*tok == '+')
435                         {
436                                 parm = (WORD)(reg1 - 14 + 58);
437                                 tok++;
438
439                                 if (*tok >= KW_R0 && *tok <= KW_R31)
440                                         indexed = 1;
441
442                                 if (*tok == SYMBOL)
443                                 {
444 //                                      sy = lookup((char *)tok[1], LABEL, 0);
445                                         sy = lookup(string[tok[1]], LABEL, 0);
446
447                                         if (!sy)
448                                         {
449                                                 error(reg_err);
450                                                 return ERROR;
451                                         }
452
453                                         if (sy->sattre & EQUATEDREG)
454                                                 indexed = 1;
455                                 }
456
457                                 if (indexed)
458                                 {
459                                         reg1 = GetRegister(FU_REGONE);
460                                 }
461                                 else
462                                 {
463                                         if (expr(r_expr, &eval, &eattr, &esym) != OK)
464                                                 return MalformedOpcode(0x06);
465
466                                         if ((challoc - ch_size) < 4)
467                                                 chcheck(4L);
468
469                                         if (!(eattr & DEFINED))
470                                         {
471                                                 error("constant expected after '+'");
472                                                 return ERROR;
473                                         }
474
475                                         reg1 = eval;
476
477                                         if (reg1 == 0)
478                                         {
479                                                 reg1 = 14 + (parm - 58);
480                                                 parm = 41;
481                                                 warn("NULL offset in LOAD ignored");
482                                         }
483                                         else
484                                         {
485                                                 if (reg1 < 1 || reg1 > 32)
486                                                 {
487                                                         error("constant in LOAD out of range");
488                                                         return ERROR;
489                                                 }
490
491                                                 if (reg1 == 32)
492                                                         reg1 = 0;
493
494                                                 parm = (WORD)(parm - 58 + 43);
495                                         }
496                                 }
497                         }
498                         else
499                         {
500                                 reg1 = GetRegister(FU_REGONE);
501                         }
502                 }
503
504                 if (*tok != ')')
505                         return MalformedOpcode(0x07);
506
507                 tok++;
508                 CHECK_COMMA;
509                 reg2 = GetRegister(FU_REGTWO);
510                 at_eol();
511                 BuildRISCIntructionWord(parm, reg1, reg2);
512                 break;
513
514         // Rn,(Rn) = 47 / Rn,(R14/R15+n) = 49/50 / Rn,(R14/R15+Rn) = 60/61
515         case RI_STORE:    
516                 parm = 47;
517                 reg1 = GetRegister(FU_REGONE);
518                 CHECK_COMMA;
519
520                 if (*tok != '(')
521                         return MalformedOpcode(0x08);
522
523                 tok++;
524                 indexed = 0;
525
526                 if ((*tok == KW_R14 || *tok == KW_R15) && (*(tok + 1) != ')')) 
527                         indexed = (*tok - KW_R0);
528
529                 if (*tok == SYMBOL)
530                 {
531 //                      sy = lookup((char *)tok[1], LABEL, 0);
532                         sy = lookup(string[tok[1]], LABEL, 0);
533
534                         if (!sy)
535                         {
536                                 error(reg_err);
537                                 return ERROR;
538                         }
539
540                         if (sy->sattre & EQUATEDREG) 
541                         {
542                                 if (((sy->svalue & 0x1F) == 14 || (sy->svalue & 0x1F) == 15)
543                                         && (*(tok + 2) != ')'))
544                                 {
545                                         indexed = (sy->svalue & 0x1F);
546                                         tok++;
547                                 }
548                         }
549                 }
550
551                 if (!indexed)
552                 {
553                         reg2 = GetRegister(FU_REGTWO);
554                 }
555                 else
556                 {
557                         reg2 = indexed;
558                         indexed = 0;
559                         tok++;
560
561                         if (*tok == '+')
562                         {
563                                 parm = (WORD)(reg2 - 14 + 60);
564                                 tok++;
565
566                                 if (*tok >= KW_R0 && *tok <= KW_R31)
567                                         indexed = 1;
568
569                                 if (*tok == SYMBOL)
570                                 {
571 //                                      sy = lookup((char *)tok[1], LABEL, 0);
572                                         sy = lookup(string[tok[1]], LABEL, 0);
573
574                                         if (!sy)
575                                         {
576                                                 error(reg_err);
577                                                 return ERROR;
578                                         }
579
580                                         if (sy->sattre & EQUATEDREG)
581                                                 indexed = 1;
582                                 }
583
584                                 if (indexed)
585                                 {
586                                         reg2 = GetRegister(FU_REGTWO);
587                                 }
588                                 else
589                                 {
590                                         if (expr(r_expr, &eval, &eattr, &esym) != OK)
591                                                 return MalformedOpcode(0x09);
592
593                                         if ((challoc - ch_size) < 4)
594                                                 chcheck(4L);
595
596                                         if (!(eattr & DEFINED))
597                                         {
598                                                 fixup(FU_WORD | FU_REGTWO, sloc, r_expr);
599                                                 reg2 = 0;
600                                         }
601                                         else
602                                         {
603                                                 reg2 = eval;
604
605                                                 if (reg2 == 0)
606                                                 {
607                                                         reg2 = 14 + (parm - 60);
608                                                         parm = 47;
609                                                         warn("NULL offset in STORE ignored");
610                                                 }
611                                                 else
612                                                 {
613                                                         if (reg2 < 1 || reg2 > 32)
614                                                         {
615                                                                 error("constant in STORE out of range");
616                                                                 return ERROR;
617                                                         }
618
619                                                         if (reg2 == 32)
620                                                                 reg2 = 0;
621
622                                                         parm = (WORD)(parm - 60 + 49);
623                                                 }
624                                         }
625                                 }
626                         }
627                         else
628                         {
629                                 reg2 = GetRegister(FU_REGTWO);
630                         }
631                 }
632
633                 if (*tok != ')')
634                         return MalformedOpcode(0x0A);
635
636                 tok++;
637                 at_eol();
638                 BuildRISCIntructionWord(parm, reg2, reg1);
639                 break;
640
641         // LOADB/LOADP/LOADW (Rn),Rn
642         case RI_LOADN:                    
643                 if (*tok != '(')
644                         return MalformedOpcode(0x0B);
645
646                 tok++;
647                 reg1 = GetRegister(FU_REGONE);
648
649                 if (*tok != ')')
650                         return MalformedOpcode(0x0C);
651
652                 tok++;
653                 CHECK_COMMA;
654                 reg2 = GetRegister(FU_REGTWO);
655                 at_eol();
656                 BuildRISCIntructionWord(parm, reg1, reg2);
657                 break;
658
659         // STOREB/STOREP/STOREW Rn,(Rn)
660         case RI_STOREN:                   
661                 reg1 = GetRegister(FU_REGONE);
662                 CHECK_COMMA;
663
664                 if (*tok != '(')
665                         return MalformedOpcode(0x0D);
666
667                 tok++;
668                 reg2 = GetRegister(FU_REGTWO);
669
670                 if (*tok != ')')
671                         return MalformedOpcode(0x0E);
672
673                 tok++;
674                 at_eol();
675                 BuildRISCIntructionWord(parm, reg2, reg1);
676                 break;
677
678         // Jump Relative - cc,n - n=-16..+15 words, reg2=cc
679         case RI_JR:
680
681         // Jump Absolute - cc,(Rs) - reg2=cc
682         case RI_JUMP:
683                 // Check to see if there is a comma in the token string. If not then
684                 // the JR or JUMP should default to 0, Jump Always
685                 commaFound = 0;
686
687                 for(t=tok; *t!=EOL; t++)
688                 {
689                         if (*t == ',')
690                         {
691                                 commaFound = 1;
692                                 break;
693                         }
694                 }
695
696                 if (commaFound)
697                 {
698                         if (*tok == CONST)
699                         {
700                                 // CC using a constant number
701                                 tok++;
702                                 val = *tok;
703                                 tok++;
704                                 CHECK_COMMA;
705                         }
706                         else if (*tok == SYMBOL)
707                         {
708                                 val = 99;
709 //                              strcpy(scratch, (char *)tok[1]);
710                                 strcpy(scratch, string[tok[1]]);
711                                 strtoupper(scratch);
712
713                                 for(i=0; i<MAXINTERNCC; i++)
714                                 {
715                                         // Look for the condition code & break if found
716                                         if (strcmp(condname[i], scratch) == 0)
717                                         {
718                                                 val = condnumber[i];
719                                                 break;
720                                         }
721                                 }
722
723                                 // Standard CC was not found, look for an equated one
724                                 if (val == 99)
725                                 {
726 //                                      ccsym = lookup((char *)tok[1], LABEL, 0);
727                                         ccsym = lookup(string[tok[1]], LABEL, 0);
728
729                                         if (ccsym && (ccsym->sattre & EQUATEDCC) && !(ccsym->sattre & UNDEF_CC))
730                                         {
731                                                 val = ccsym->svalue;
732                                         }
733                                         else
734                                         {
735                                                 error("unknown condition code");
736                                                 return ERROR;
737                                         }
738                                 }
739
740                                 tok += 2;
741                                 CHECK_COMMA;
742                         }
743                         else if (*tok == '(')
744                         {
745                                 // Set CC to "Jump Always"
746                                 val = 0;
747                         }
748                 }
749                 else
750                 {
751                         // Set CC to "Jump Always"
752                         val = 0;
753                 }
754
755                 if (val < 0 || val > 31)
756                 {
757                         error("condition constant out of range");
758                         return ERROR;
759                 }
760
761                 // Store condition code
762                 reg1 = val;
763
764                 if (type == RI_JR)
765                 {
766                         // JR cc,n
767                         if (expr(r_expr, &eval, &eattr, &esym) != OK)
768                                 return MalformedOpcode(0x0F);
769
770                         if ((challoc - ch_size) < 4)
771                                 chcheck(4L);
772
773                         if (!(eattr & DEFINED))
774                         {
775                                 fixup(FU_WORD | FU_JR, sloc, r_expr);
776                                 reg2 = 0;
777                         }
778                         else
779                         {
780                                 reg2 = ((int)(eval - ((orgactive ? orgaddr : sloc) + 2))) / 2;
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(0x10);
793
794                         tok++;
795                         reg2 = GetRegister(FU_REGTWO);
796
797                         if (*tok != ')')
798                                 return MalformedOpcode(0x11);
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         lastOpcode = type;
814         return 0;
815 }
816