* Makefile.am (stamp-m32r): Fix path to cpu files.
[external/binutils.git] / opcodes / w65-dis.c
1 /* Disassemble WDC 65816 instructions.
2    Copyright 1995, 1998, 2000, 2001, 2002, 2005
3    Free Software Foundation, Inc.
4
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.
9
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.
14
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., 51 Franklin Street - Fifth Floor, Boston,
18    MA 02110-1301, USA.  */
19
20 #include <stdio.h>
21 #include "sysdep.h"
22 #define STATIC_TABLE
23 #define DEFINE_TABLE
24
25 #include "w65-opc.h"
26 #include "dis-asm.h"
27
28 static fprintf_ftype fpr;
29 static void *stream;
30 static struct disassemble_info *local_info;
31
32 static void
33 print_operand (int lookup, char *format, int *args)
34 {
35   int val;
36   int c;
37
38   while (*format)
39     {
40       switch (c = *format++)
41         {
42         case '$':
43           val = args[(*format++) - '0'];
44           if (lookup)
45             local_info->print_address_func (val, local_info);
46           else
47             fpr (stream, "0x%x", val);
48
49           break;
50         default:
51           fpr (stream, "%c", c);
52           break;
53         }
54     }
55 }
56
57 int
58 print_insn_w65 (bfd_vma memaddr, struct disassemble_info *info)
59 {
60   int status = 0;
61   unsigned char insn[4];
62   const struct opinfo *op;
63   int i;
64   int X = 0;
65   int M = 0;
66   int args[2];
67
68   stream = info->stream;
69   fpr = info->fprintf_func;
70   local_info = info;
71
72   for (i = 0; i < 4 && status == 0; i++)
73     status = info->read_memory_func (memaddr + i, insn + i, 1, info);
74
75   for (op = optable; op->val != insn[0]; op++)
76     ;
77
78   fpr (stream, "%s", op->name);
79
80   /* Prepare all the posible operand values.  */
81   {
82     int size = 1;
83     int asR_W65_ABS8 = insn[1];
84     int asR_W65_ABS16 = (insn[2] << 8) + asR_W65_ABS8;
85     int asR_W65_ABS24 = (insn[3] << 16) + asR_W65_ABS16;
86     int asR_W65_PCR8 = ((char) (asR_W65_ABS8)) + memaddr + 2;
87     int asR_W65_PCR16 = ((short) (asR_W65_ABS16)) + memaddr + 3;
88
89     switch (op->amode)
90       {
91         DISASM ();
92       }
93
94     return size;
95   }
96 }