cf2811b9ecce2a02c05c559e6bc508c2c6cad439
[fw/sdcc] / sim / ucsim / xa.src / xa.cc
1 /*
2  * Simulator of microcontrollers (xa.cc)
3  *
4  * Copyright (C) 1999,2002 Drotos Daniel, Talker Bt.
5  *
6  * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
7  * Other contributors include:
8  *   Karl Bongers karl@turbobit.com,
9  *   Johan Knol 
10  */
11
12 /* This file is part of microcontroller simulator: ucsim.
13
14 UCSIM is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 UCSIM is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with UCSIM; see the file COPYING.  If not, write to the Free
26 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 02111-1307, USA. */
28 /*@1@*/
29
30 #include "ddconfig.h"
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <ctype.h>
35 #include "i_string.h"
36
37 // prj
38 #include "pobjcl.h"
39
40 // sim
41 #include "simcl.h"
42
43 // local
44 #include "xacl.h"
45 #include "glob.h"
46 #include "regsxa.h"
47
48 /*
49  * Base type of xa controllers
50  */
51
52 cl_xa::cl_xa(class cl_sim *asim):
53   cl_uc(asim)
54 {
55   type= CPU_XA;
56 }
57
58 int
59 cl_xa::init(void)
60 {
61   cl_uc::init(); /* Memories now exist */
62   ram= mem(MEM_XRAM);
63   rom= mem(MEM_ROM);
64
65   /* set SCR to osc/4, native XA mode, flat 24 */
66   set_scr(0);
67   /* initialize SP to 100H */
68   set_reg2(7, 0x100);
69   /* set PSW from reset vector */
70   set_psw(getcode2(0));
71   /* set PC from reset vector */
72   PC = getcode2(2);
73
74   printf("The XA Simulator is in development, UNSTABLE, DEVELOPERS ONLY!\n");
75
76   return(0);
77 }
78
79 class cl_mem *
80 cl_xa::mk_mem(enum mem_class type, char *class_name)
81 {
82   class cl_mem *m= cl_uc::mk_mem(type, class_name);
83   if (type == MEM_SFR)
84     sfr= m;
85   if (type == MEM_IRAM)
86     iram= m;
87   return(m);
88 }
89
90 char *
91 cl_xa::id_string(void)
92 {
93   return("unspecified XA");
94 }
95
96
97 /*
98  * Making elements of the controller
99  */
100
101 t_addr
102 cl_xa::get_mem_size(enum mem_class type)
103 {
104   switch(type)
105     {
106     case MEM_IRAM: return(0x2000);
107     case MEM_SFR: return(0x2000);
108     case MEM_ROM: return(0x10000);
109     case MEM_XRAM: return(0x10000);
110     default: return(0);
111     }
112  return(cl_uc::get_mem_size(type));
113 }
114
115 void
116 cl_xa::mk_hw_elements(void)
117 {
118   //class cl_base *o;
119   /* t_uc::mk_hw() does nothing */
120 }
121
122
123 /*
124  * Help command interpreter
125  */
126
127 struct dis_entry *
128 cl_xa::dis_tbl(void)
129 {
130   // this should be unused, we need to make main prog code
131   // independent of any array thing.
132   printf("ERROR - Using disass[] table in XA sim code!\n");
133   return(glob_disass_xa);
134 }
135
136 struct name_entry *cl_xa::sfr_tbl(void)
137 {
138   return(sfr_tabXA51);
139 }
140
141 struct name_entry *cl_xa::bit_tbl(void)
142 {
143   return(bit_tabXA51);
144 }
145
146 int
147 cl_xa::inst_length(t_addr addr)
148 {
149   int len = 0;
150
151   get_disasm_info(addr, &len, NULL, NULL, NULL, NULL);
152
153   return len;
154 }
155
156 int
157 cl_xa::inst_branch(t_addr addr)
158 {
159   int b;
160
161   get_disasm_info(addr, NULL, &b, NULL, NULL, NULL);
162
163   return b;
164 }
165
166 int
167 cl_xa::longest_inst(void)
168 {
169   return 6;
170 }
171
172 static char dir_name[64];
173 char *cl_xa::get_dir_name(short addr) {
174   if (!get_name(addr, sfr_tbl(), dir_name)) {
175     sprintf (dir_name, "0x%03x", addr);
176   }
177   return dir_name;
178 }
179
180 static char bit_name[64];
181 char *cl_xa::get_bit_name(short addr) {
182   if (!get_name(addr, bit_tbl(), bit_name)) {
183     sprintf (bit_name, "0x%03x", addr);
184   }
185   return bit_name;
186 }
187
188 /*--------------------------------------------------------------------
189 get_disasm_info - Given an address, return information about the opcode
190   which resides there.
191   addr - address of opcode we want information on.
192   ret_len - return length of opcode.
193   ret_branch - return a character which indicates if we are
194     a branching opcode.  Used by main app to implement "Next"
195     function which steps over functions.
196   immed_offset - return a number which represents the number of bytes
197     offset to where any immediate data is(tail end of opcode).  Used
198     for printing disassembly.
199   operands - return a key indicating the form of the operands,
200     used for printing the disassembly.
201   mnemonic - return a key indicating the mnemonic of the instruction.
202
203   Return value: Return the operand code formed by either the single
204   byte opcode or 2 bytes of the opcode for multi-byte opcodes.
205
206   Note: Any of the return pointer parameters can be set to NULL to
207     indicate the caller does not want the information.
208 |--------------------------------------------------------------------*/
209 int
210 cl_xa::get_disasm_info(t_addr addr,
211                        int *ret_len,
212                        int *ret_branch,
213                        int *immed_offset,
214                        int *parms,
215                        int *mnemonic)
216 {
217   uint code;
218   int len = 0;
219   int immed_n = 0;
220   int i;
221   int start_addr = addr;
222
223   code= get_mem(MEM_ROM, addr++);
224   if (code == 0x00) {
225     i= 0;
226     while (disass_xa[i].mnemonic != NOP)
227       i++;
228   } else {
229     len = 2;
230     code = (code << 8) | get_mem(MEM_ROM, addr++);
231     i= 0;
232     while ((code & disass_xa[i].mask) != disass_xa[i].code &&
233            disass_xa[i].mnemonic != BAD_OPCODE)
234       i++;
235   }
236
237   if (ret_len)
238     *ret_len = disass_xa[i].length;
239   if (ret_branch)
240    *ret_branch = disass_xa[i].branch;
241   if (immed_offset) {
242     if (immed_n > 0)
243          *immed_offset = immed_n;
244     else *immed_offset = (addr - start_addr);
245   }
246   if (parms) {
247     *parms = disass_xa[i].operands;
248   }
249   if (mnemonic) {
250     *mnemonic = disass_xa[i].mnemonic;
251   }
252
253   return code;
254 }
255
256 static char *w_reg_strs[] = {
257  "R0", "R1",
258  "R2", "R3",
259  "R4", "R5",
260  "R6", "R7",
261  "R8", "R9",
262  "R10", "R11",
263  "R12", "R13",
264  "R14", "R15"};
265
266 static char *b_reg_strs[] = {
267  "R0l", "R0h",
268  "R1l", "R1h",
269  "R2l", "R2h",
270  "R3l", "R3h",
271  "R4l", "R4h",
272  "R5l", "R5h",
273  "R6l", "R6h",
274  "R7l", "R7h"};
275
276 /*--------------------------------------------------------------------
277 disass - Disassemble an opcode.
278     addr - address of opcode to disassemble/print.
279     sep - optionally points to string(tab) to use as separator.
280 |--------------------------------------------------------------------*/
281 char *
282 cl_xa::disass(t_addr addr, char *sep)
283 {
284   char work[256], parm_str[40];
285   char *buf, *p, *b;
286   int code;
287   int len = 0;
288   int immed_offset = 0;
289   int operands;
290   int mnemonic;
291   char **reg_strs;
292
293   p= work;
294
295   code = get_disasm_info(addr, &len, NULL, &immed_offset, &operands, &mnemonic);
296
297   if (mnemonic == BAD_OPCODE) {
298     buf= (char*)malloc(30);
299     strcpy(buf, "UNKNOWN/INVALID");
300     return(buf);
301   }
302
303   if (code & 0x0800)
304     reg_strs = w_reg_strs;
305   else
306     reg_strs = b_reg_strs;
307
308   switch(operands) {
309      // the repeating common parameter encoding for ADD, ADDC, SUB, AND...
310     case REG_REG :
311       sprintf(parm_str, "%s,%s",
312               reg_strs[((code >> 4) & 0xf)],
313               reg_strs[(code & 0xf)]);
314     break;
315     case REG_IREG :
316       sprintf(parm_str, "%s,[%s]",
317               reg_strs[((code >> 4) & 0xf)],
318               w_reg_strs[(code & 0xf)]);
319     break;
320     case IREG_REG :
321       sprintf(parm_str, "[%s],%s",
322               w_reg_strs[(code & 0x7)],
323               reg_strs[((code >> 4) & 0xf)] );
324     break;
325     case REG_IREGOFF8 :
326       sprintf(parm_str, "%s,[%s+%02d]",
327               reg_strs[((code >> 4) & 0xf)],
328               w_reg_strs[(code & 0x7)],
329               get_mem(MEM_ROM, addr+immed_offset));
330       ++immed_offset;
331     break;
332     case IREGOFF8_REG :
333       sprintf(parm_str, "[%s+%02d],%s",
334               w_reg_strs[(code & 0x7)],
335               get_mem(MEM_ROM, addr+immed_offset),
336               reg_strs[((code >> 4) & 0xf)] );
337       ++immed_offset;
338     break;
339     case REG_IREGOFF16 :
340       sprintf(parm_str, "%s,[%s+%04d]",
341               reg_strs[((code >> 4) & 0xf)],
342               w_reg_strs[(code & 0x7)],
343               (short)((get_mem(MEM_ROM, addr+immed_offset+1)) |
344                      (get_mem(MEM_ROM, addr+immed_offset)<<8)) );
345       ++immed_offset;
346       ++immed_offset;
347     break;
348     case IREGOFF16_REG :
349       sprintf(parm_str, "[%s+%04d],%s",
350               w_reg_strs[(code & 0x7)],
351               (short)((get_mem(MEM_ROM, addr+immed_offset+1)) |
352                      (get_mem(MEM_ROM, addr+immed_offset)<<8)),
353               reg_strs[((code >> 4) & 0xf)] );
354       ++immed_offset;
355       ++immed_offset;
356     break;
357     case REG_IREGINC :
358       sprintf(parm_str, "%s,[%s+]",
359               reg_strs[((code >> 4) & 0xf)],
360               w_reg_strs[(code & 0xf)]);
361     break;
362     case IREGINC_REG :
363       sprintf(parm_str, "[%s+],%s",
364               w_reg_strs[(code & 0x7)],
365               reg_strs[((code >> 4) & 0xf)] );
366     break;
367     case DIRECT_REG :
368       sprintf(parm_str, "%s,%s",
369               get_dir_name(((code & 0x7) << 8) | 
370                            get_mem(MEM_ROM, addr+immed_offset)),
371               reg_strs[((code >> 4) & 0xf)] );
372       ++immed_offset;
373     break;
374     case REG_DIRECT :
375       sprintf(parm_str, "%s,%s",
376               reg_strs[((code >> 4) & 0xf)], 
377               get_dir_name(((code & 0x7) << 8) | 
378                            get_mem(MEM_ROM, addr+immed_offset)));
379       ++immed_offset;
380     break;
381     case REG_DATA8 :
382       sprintf(parm_str, "%s,#0x%02x",
383               b_reg_strs[((code >> 4) & 0xf)],
384               get_mem(MEM_ROM, addr+immed_offset) );
385       ++immed_offset;
386     break;
387     case REG_DATA16 :
388       sprintf(parm_str, "%s,#0x%04x",
389               reg_strs[((code >> 4) & 0xf)],
390               (short)((get_mem(MEM_ROM, addr+immed_offset+1)) |
391                      (get_mem(MEM_ROM, addr+immed_offset)<<8)) );
392       ++immed_offset;
393       ++immed_offset;
394     break;
395     case IREG_DATA8 :
396       sprintf(parm_str, "[%s], 0x%02x",
397               w_reg_strs[((code >> 4) & 0x7)],
398               get_mem(MEM_ROM, addr+immed_offset) );
399       ++immed_offset;
400     break;
401     case IREG_DATA16 :
402       sprintf(parm_str, "[%s], 0x%04x",
403               w_reg_strs[((code >> 4) & 0x7)],
404               (short)((get_mem(MEM_ROM, addr+immed_offset+1)) |
405                      (get_mem(MEM_ROM, addr+immed_offset)<<8)) );
406       ++immed_offset;
407       ++immed_offset;
408     break;
409     case IREGINC_DATA8 :
410       sprintf(parm_str, "[%s+], 0x%02x",
411               w_reg_strs[((code >> 4) & 0x7)],
412               get_mem(MEM_ROM, addr+immed_offset) );
413       ++immed_offset;
414     break;
415     case IREGINC_DATA16 :
416       sprintf(parm_str, "[%s+], 0x%04x",
417               w_reg_strs[((code >> 4) & 0x7)],
418               (short)((get_mem(MEM_ROM, addr+immed_offset+1)) |
419                      (get_mem(MEM_ROM, addr+immed_offset)<<8)) );
420       ++immed_offset;
421       ++immed_offset;
422     break;
423     case IREGOFF8_DATA8 :
424       sprintf(parm_str, "[%s+%02d], 0x%02x",
425               w_reg_strs[((code >> 4) & 0x7)],
426               get_mem(MEM_ROM, addr+immed_offset),
427               get_mem(MEM_ROM, addr+immed_offset+1) );
428       immed_offset += 2;
429     break;
430     case IREGOFF8_DATA16 :
431       sprintf(parm_str, "[%s+%02d], 0x%04x",
432               w_reg_strs[((code >> 4) & 0x7)],
433               get_mem(MEM_ROM, addr+immed_offset),
434               (short)((get_mem(MEM_ROM, addr+immed_offset+2)) |
435                      (get_mem(MEM_ROM, addr+immed_offset+1)<<8)) );
436       immed_offset += 3;
437     break;
438     case IREGOFF16_DATA8 :
439       sprintf(parm_str, "[%s+%04d], 0x%02x",
440               w_reg_strs[((code >> 4) & 0x7)],
441               (short)((get_mem(MEM_ROM, addr+immed_offset+1)) |
442                      (get_mem(MEM_ROM, addr+immed_offset+0)<<8)),
443               get_mem(MEM_ROM, addr+immed_offset+2) );
444       immed_offset += 3;
445     break;
446     case IREGOFF16_DATA16 :
447       sprintf(parm_str, "[%s+%04d], 0x%04x",
448               w_reg_strs[((code >> 4) & 0x7)],
449               (short)((get_mem(MEM_ROM, addr+immed_offset+1)) |
450                      (get_mem(MEM_ROM, addr+immed_offset+0)<<8)),
451               (short)((get_mem(MEM_ROM, addr+immed_offset+3)) |
452                      (get_mem(MEM_ROM, addr+immed_offset+2)<<8)) );
453       immed_offset += 4;
454     break;
455     case DIRECT_DATA8 :
456       sprintf(parm_str, "%s,#0x%02x",
457               get_dir_name(((code & 0x0070) << 4) | 
458                            get_mem(MEM_ROM, addr+immed_offset)),
459               get_mem(MEM_ROM, addr+immed_offset+1));
460       immed_offset += 3;
461     break;
462     case DIRECT_DATA16 :
463       sprintf(parm_str, "%s,#0x%04x",
464               get_dir_name(((code & 0x0070) << 4) | 
465                            get_mem(MEM_ROM, addr+immed_offset)),
466               get_mem(MEM_ROM, addr+immed_offset+2) +
467               (get_mem(MEM_ROM, addr+immed_offset+1)<<8));
468       immed_offset += 3;
469     break;
470
471 // odd-ball ones
472     case NO_OPERANDS :  // for NOP
473       strcpy(parm_str, "");
474     break;
475     case C_BIT :
476       strcpy(parm_str, "C_BIT");
477     break;
478     case REG_DATA4 :
479       strcpy(parm_str, "REG_DATA4");
480     break;
481     case IREG_DATA4 :
482       strcpy(parm_str, "IREG_DATA4");
483     break;
484     case IREGINC_DATA4 :
485       strcpy(parm_str, "IREGINC_DATA4");
486     break;
487     case IREGOFF8_DATA4 :
488       strcpy(parm_str, "IREGOFF8_DATA4");
489     break;
490     case IREGOFF16_DATA4 :
491       strcpy(parm_str, "IREGOFF16_DATA4");
492     break;
493     case DIRECT_DATA4 :
494       sprintf(parm_str, "%s,#0x%x",
495               get_dir_name(((code & 0x70)<<4) |
496                            get_mem(MEM_ROM, addr+2)),
497               code&0x0f);
498     break;
499     case DIRECT :
500       sprintf(parm_str, "%s",
501               get_dir_name(((code & 0x007) << 4) + 
502                            get_mem(MEM_ROM, addr+2)));
503     break;
504     case REG :
505       sprintf(parm_str, "%s",
506               reg_strs[((code >> 4) & 0xf)] );
507     break;
508     case IREG :
509       sprintf(parm_str, "[%s]",
510               reg_strs[((code >> 4) & 0xf)] );
511     break;
512     case BIT_ALONE :
513       sprintf(parm_str, "%s",
514               get_bit_name(((code&0x0003)<<8) + get_mem(MEM_ROM, addr+2)));
515     break;
516     case BIT_REL8 :
517       sprintf(parm_str, "%s,0x%04x",
518               get_bit_name((code&0x0003)<<8) + get_mem(MEM_ROM, addr+2),
519               ((signed char)get_mem(MEM_ROM, addr+3)*2+addr+len)&0xfffe);
520     break;
521     case ADDR24 :
522       strcpy(parm_str, "ADDR24");
523     break;
524     case REG_REL8 :
525       sprintf(parm_str, "%s,0x%04x",
526               reg_strs[(code>>4) & 0xf],
527               ((signed char)get_mem(MEM_ROM, addr+2)*2+addr+len)&0xfffe);
528     break;
529     case DIRECT_REL8 :
530       sprintf(parm_str, "%s,0x%04x",
531               get_dir_name(((code&0x07)<<8) +
532                            get_mem(MEM_ROM, addr+2)),
533               ((signed char)get_mem(MEM_ROM, addr+2)*2+addr+len)&0xfffe);
534     break;
535
536     case REL8 :
537       sprintf(parm_str, "0x%04x",
538               ((signed char)get_mem(MEM_ROM, addr+1)*2+addr+len)&0xfffe);
539     break;
540     case REL16 :
541       sprintf(parm_str, "0x%04x",
542               ((signed short)((get_mem(MEM_ROM, addr+1)<<8) + get_mem(MEM_ROM, addr+2))*2+addr+len)&0xfffe);
543     break;
544
545     case RLIST :
546       strcpy(parm_str, "RLIST");
547     break;
548
549     case REG_DIRECT_REL8 :
550       sprintf(parm_str, "%s,%s,0x%02x",
551               reg_strs[((code >> 4) & 0xf)],
552               get_dir_name(((code & 0x7) << 8) + 
553                            get_mem(MEM_ROM, addr+immed_offset)),
554               ((signed char) get_mem(MEM_ROM, addr+immed_offset+1) * 2) & 0xfffe );
555     break;
556     case REG_DATA8_REL8 :
557       sprintf(parm_str, "%s,#0x%04x,0x%02x",
558               reg_strs[((code >> 4) & 0xf)],
559               get_mem(MEM_ROM, addr+immed_offset),
560               ((signed char)get_mem(MEM_ROM, addr+immed_offset+1) * 2) & 0xfffe );
561     break;
562     case REG_DATA16_REL8 :
563       sprintf(parm_str, "%s,#0x%02x,0x%02x",
564               w_reg_strs[((code >> 4) & 0x7)*2],
565               get_mem(MEM_ROM, addr+immed_offset+1) +
566                  (get_mem(MEM_ROM, addr+immed_offset+0)<<8),
567               ((signed char)get_mem(MEM_ROM, addr+immed_offset+2) * 2) & 0xfffe );
568     break;
569     case IREG_DATA8_REL8 :
570       sprintf(parm_str, "[%s],#0x%04x,0x%02x",
571               reg_strs[((code >> 4) & 0x7)],
572               get_mem(MEM_ROM, addr+immed_offset),
573               ((signed char)get_mem(MEM_ROM, addr+immed_offset+1) * 2) & 0xfffe );
574     break;
575     case IREG_DATA16_REL8 :
576       sprintf(parm_str, "[%s],#0x%02x,0x%02x",
577               w_reg_strs[((code >> 4) & 0x7)*2],
578               get_mem(MEM_ROM, addr+immed_offset+1) +
579                  (get_mem(MEM_ROM, addr+immed_offset+0)<<8),
580               ((signed char)get_mem(MEM_ROM, addr+immed_offset+2) * 2) & 0xfffe );
581     break;
582
583     case A_APLUSDPTR :
584       strcpy(parm_str, "A, [A+DPTR]");
585     break;
586
587     case A_APLUSPC :
588       strcpy(parm_str, "A, [A+PC]");
589     break;
590
591     default:
592       strcpy(parm_str, "???");
593     break;
594   }
595
596   sprintf(work, "%s %s",
597           op_mnemonic_str[ mnemonic ],
598           parm_str);
599
600   p= strchr(work, ' ');
601   if (!p)
602     {
603       buf= strdup(work);
604       return(buf);
605     }
606   if (sep == NULL)
607     buf= (char *)malloc(6+strlen(p)+1);
608   else
609     buf= (char *)malloc((p-work)+strlen(sep)+strlen(p)+1);
610   for (p= work, b= buf; *p != ' '; p++, b++)
611     *b= *p;
612   p++;
613   *b= '\0';
614   if (sep == NULL)
615     {
616       while (strlen(buf) < 6)
617         strcat(buf, " ");
618     }
619   else
620     strcat(buf, sep);
621   strcat(buf, p);
622   return(buf);
623 }
624
625 /*--------------------------------------------------------------------
626  print_regs - Print the registers, flags and other useful information.
627    Used to print a status line while stepping through the code.
628 |--------------------------------------------------------------------*/
629 void
630 cl_xa::print_regs(class cl_console *con)
631 {
632   unsigned char flags;
633
634   flags = get_psw();
635   con->dd_printf("CA---VNZ  Flags: %02x ", flags);
636   con->dd_printf("R0:%04x R1:%04x R2:%04x R3:%04x\n",
637                  reg2(0), reg2(1), reg2(2), reg2(3));
638
639   con->dd_printf("%c%c---%c%c%c            ",
640          (flags & BIT_C)?'1':'0',
641          (flags & BIT_AC)?'1':'0',
642          (flags & BIT_V)?'1':'0',
643          (flags & BIT_N)?'1':'0',
644          (flags & BIT_Z)?'1':'0');
645
646   con->dd_printf("R4:%04x R5:%04x R6:%04x R7(SP):%04x ES:%04x  DS:%04x\n",
647                  reg2(4), reg2(5), reg2(6), reg2(7), 0, 0);
648
649   print_disass(PC, con);
650 }
651
652
653 /*--------------------------------------------------------------------
654  exec_inst - Called to implement simulator execution of 1 instruction
655    at the current PC(program counter) address.
656 |--------------------------------------------------------------------*/
657 int cl_xa::exec_inst(void)
658 {
659   t_mem code1;
660   uint code;
661   int i;
662   int operands;
663
664   if (fetch(&code1))
665     return(resBREAKPOINT);
666   tick(1);
667
668 /* the following lookups make for a slow simulation, we will
669   figure out how to make it fast later... */
670
671   /* scan to see if its a 1 byte-opcode */
672   code = (code1 << 8);
673   i= 0;
674   while ( ((code & disass_xa[i].mask) != disass_xa[i].code ||
675           (!disass_xa[i].is1byte)) /* not a one byte op code */
676                     &&
677          disass_xa[i].mnemonic != BAD_OPCODE)
678     i++;
679
680   if (disass_xa[i].mnemonic == BAD_OPCODE) {
681     /* hit the end of the list, must be a 2 or more byte opcode */
682     /* fetch another code byte and search the list again */
683       //if (fetch(&code2))  ?not sure if break allowed in middle of opcode?
684       //  return(resBREAKPOINT);
685     code |= fetch();  /* add 2nd opcode */
686
687     i= 0;
688     while ((code & disass_xa[i].mask) != disass_xa[i].code &&
689            disass_xa[i].mnemonic != BAD_OPCODE)
690       i++;
691     /* we should have found the opcode by now, if not invalid entry at eol */
692   }
693
694   operands = (int)(disass_xa[i].operands);
695   switch (disass_xa[i].mnemonic)
696   {
697     case ADD:
698     return inst_ADD(code, operands);
699     case ADDC:
700     return inst_ADDC(code, operands);
701     case ADDS:
702     return inst_ADDS(code, operands);
703     case AND:
704     return inst_AND(code, operands);
705     case ANL:
706     return inst_ANL(code, operands);
707     case ASL:
708     return inst_ASL(code, operands);
709     case ASR:
710     return inst_ASR(code, operands);
711     case BCC:
712     return inst_BCC(code, operands);
713     case BCS:
714     return inst_BCS(code, operands);
715     case BEQ:
716     return inst_BEQ(code, operands);
717     case BG:
718     return inst_BG(code, operands);
719     case BGE:
720     return inst_BGE(code, operands);
721     case BGT:
722     return inst_BGT(code, operands);
723     case BKPT:
724     return inst_BKPT(code, operands);
725     case BL:
726     return inst_BL(code, operands);
727     case BLE:
728     return inst_BLE(code, operands);
729     case BLT:
730     return inst_BLT(code, operands);
731     case BMI:
732     return inst_BMI(code, operands);
733     case BNE:
734     return inst_BNE(code, operands);
735     case BNV:
736     return inst_BNV(code, operands);
737     case BOV:
738     return inst_BOV(code, operands);
739     case BPL:
740     return inst_BPL(code, operands);
741     case BR:
742     return inst_BR(code, operands);
743     case CALL:
744     return inst_CALL(code, operands);
745     case CJNE:
746     return inst_CJNE(code, operands);
747     case CLR:
748     return inst_CLR(code, operands);
749     case CMP:
750     return inst_CMP(code, operands);
751     case CPL:
752     return inst_CPL(code, operands);
753     case DA:
754     return inst_DA(code, operands);
755     case DIV_w :
756     case DIV_d :
757     case DIVU_b:
758     case DIVU_w:
759     case DIVU_d:
760     return inst_DIV(code, operands);
761     case DJNZ:
762     return inst_DJNZ(code, operands);
763     case FCALL:
764     return inst_FCALL(code, operands);
765     case FJMP:
766     return inst_FJMP(code, operands);
767     case JB:
768     return inst_JB(code, operands);
769     case JBC:
770     return inst_JBC(code, operands);
771     case JMP:
772     return inst_JMP(code, operands);
773     case JNB:
774     return inst_JNB(code, operands);
775     case JNZ:
776     return inst_JNZ(code, operands);
777     case JZ:
778     return inst_JZ(code, operands);
779     case LEA:
780     return inst_LEA(code, operands);
781     case LSR:
782     return inst_LSR(code, operands);
783     case MOV:
784     return inst_MOV(code, operands);
785     case MOVC:
786     return inst_MOVC(code, operands);
787     case MOVS:
788     return inst_MOVS(code, operands);
789     case MOVX:
790     return inst_MOVX(code, operands);
791     case MUL_w:
792     case MULU_b:
793     case MULU_w:
794     return inst_MUL(code, operands);
795     case NEG:
796     return inst_NEG(code, operands);
797     case NOP:
798     return inst_NOP(code, operands);
799     case NORM:
800     return inst_NORM(code, operands);
801     case OR:
802     return inst_OR(code, operands);
803     case ORL:
804     return inst_ORL(code, operands);
805     case POP:
806     case POPU:
807     return inst_POP(code, operands);
808     case PUSH:
809     case PUSHU:
810     return inst_PUSH(code, operands);
811     case RESET:
812     return inst_RESET(code, operands);
813     case RET:
814     return inst_RET(code, operands);
815     case RETI:
816     return inst_RETI(code, operands);
817     case RL:
818     return inst_RL(code, operands);
819     case RLC:
820     return inst_RLC(code, operands);
821     case RR:
822     return inst_RR(code, operands);
823     case RRC:
824     return inst_RRC(code, operands);
825     case SETB:
826     return inst_SETB(code, operands);
827     case SEXT:
828     return inst_SEXT(code, operands);
829     case SUB:
830     return inst_SUB(code, operands);
831     case SUBB:
832     return inst_SUBB(code, operands);
833     case TRAP:
834     return inst_TRAP(code, operands);
835     case XCH:
836     return inst_XCH(code, operands);
837     case XOR:
838     return inst_XOR(code, operands);
839
840     case BAD_OPCODE:
841     default:
842     break;
843   }
844
845   if (PC)
846     PC--;
847   else
848     PC= get_mem_size(MEM_ROM)-1;
849   //tick(-clock_per_cycle());
850   sim->stop(resINV_INST);
851   return(resINV_INST);
852 }
853
854
855 /* End of xa.src/xa.cc */