bfd/ChangeLog
[binutils.git] / opcodes / w65-dis.c
blob97ad74ec20a4ebfb0e0b7864a494102304e30685
1 /* Disassemble WDC 65816 instructions.
2 Copyright 1995, 1998, 2000, 2001, 2002, 2005
3 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19 #include <stdio.h>
20 #include "sysdep.h"
21 #define STATIC_TABLE
22 #define DEFINE_TABLE
24 #include "w65-opc.h"
25 #include "dis-asm.h"
27 static fprintf_ftype fpr;
28 static void *stream;
29 static struct disassemble_info *local_info;
31 static void print_operand PARAMS ((int, char *, int *));
33 #if 0
34 static char *lname[] = { "r0","r1","r2","r3","r4","r5","r6","r7","s0" };
36 static char *
37 findname (val)
38 unsigned int val;
40 if (val >= 0x10 && val <= 0x20)
41 return lname[(val - 0x10) / 2];
42 return 0;
44 #endif
45 static void
46 print_operand (lookup, format, args)
47 int lookup;
48 char *format;
49 int *args;
51 int val;
52 int c;
54 while (*format)
56 switch (c = *format++)
58 case '$':
59 val = args[(*format++) - '0'];
60 if (lookup)
62 #if 0
63 name = findname (val);
64 if (name)
65 fpr (stream, "%s", name);
66 else
67 #endif
68 local_info->print_address_func (val, local_info);
70 else
71 fpr (stream, "0x%x", val);
73 break;
74 default:
75 fpr (stream, "%c", c);
76 break;
81 int
82 print_insn_w65 (memaddr, info)
83 bfd_vma memaddr;
84 struct disassemble_info *info;
86 int status = 0;
87 unsigned char insn[4];
88 const struct opinfo *op;
89 int i;
90 int X = 0;
91 int M = 0;
92 int args[2];
93 stream = info->stream;
94 fpr = info->fprintf_func;
95 local_info = info;
96 for (i = 0; i < 4 && status == 0; i++)
98 status = info->read_memory_func (memaddr + i, insn + i, 1, info);
101 for (op = optable; op->val != insn[0]; op++)
104 fpr (stream, "%s", op->name);
106 /* Prepare all the posible operand values. */
108 int size = 1;
109 int asR_W65_ABS8 = insn[1];
110 int asR_W65_ABS16 = (insn[2] << 8) + asR_W65_ABS8;
111 int asR_W65_ABS24 = (insn[3] << 16) + asR_W65_ABS16;
112 int asR_W65_PCR8 = ((char) (asR_W65_ABS8)) + memaddr + 2;
113 int asR_W65_PCR16 = ((short) (asR_W65_ABS16)) + memaddr + 3;
115 switch (op->amode)
117 DISASM ();
120 return size;