2000-06-05 H.J. Lu <hjl@gnu.org>
[binutils.git] / opcodes / w65-dis.c
blob309bd5aa0f4c5c5a2b18537cfcaf996b5b81f665
1 /* Disassemble WDC 65816 instructions.
2 Copyright (C) 1995, 1998 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 #include <stdio.h>
19 #include "sysdep.h"
20 #define STATIC_TABLE
21 #define DEFINE_TABLE
23 #include "w65-opc.h"
24 #include "dis-asm.h"
26 static fprintf_ftype fpr;
27 static void *stream;
28 static struct disassemble_info *local_info;
29 #if 0
30 static char *lname[] = {"r0","r1","r2","r3","r4","r5","r6","r7","s0"};
32 static char *findname (val)
33 unsigned int val;
35 if (val >= 0x10 && val <= 0x20)
36 return lname[(val - 0x10) / 2];
37 return 0;
39 #endif
40 static void
41 print_operand (lookup, format, args)
42 int lookup;
43 char *format;
44 unsigned int *args;
46 int val;
47 int c;
49 while (*format)
51 switch ( c = *format++)
53 case '$':
54 val = args[(*format++) - '0'];
55 if (lookup)
57 #if 0
58 name = findname(val);
59 if (name)
60 fpr(stream, "%s", name);
61 else
62 #endif
63 local_info->print_address_func (val, local_info);
65 else
66 fpr (stream, "0x%x", val);
68 break;
69 default:
70 fpr(stream,"%c", c);
71 break;
75 int
76 print_insn_w65(memaddr, info)
77 bfd_vma memaddr;
78 struct disassemble_info *info;
82 int status = 0;
83 unsigned char insn[4];
84 register struct opinfo *op;
85 int i;
86 int X =0;
87 int M = 0;
88 int args[2];
89 stream = info->stream;
90 fpr = info->fprintf_func;
91 local_info = info;
92 for (i = 0; i <4 && status == 0; i++)
94 status = info->read_memory_func(memaddr+i, insn + i, 1, info);
98 for (op = optable; op->val != insn[0]; op++)
101 fpr(stream,"%s", op->name);
103 /* Prepare all the posible operand values */
105 int size = 1;
106 int asR_W65_ABS8 = insn[1];
107 int asR_W65_ABS16 = (insn[2] << 8) + asR_W65_ABS8;
108 int asR_W65_ABS24 = (insn[3] << 16) + asR_W65_ABS16;
109 int asR_W65_PCR8 = ((char)(asR_W65_ABS8)) + memaddr + 2;
110 int asR_W65_PCR16 = ((short)(asR_W65_ABS16)) + memaddr + 3;
112 switch (op->amode) {
113 DISASM();
116 return size;