Automatic date update in version.in
[deliverable/binutils-gdb.git] / opcodes / z80-dis.c
index 38ce4d118098a87bfc3d130909fc4565efe79e64..e30d6383de31cd53239cee04dea4d3376c9359f0 100644 (file)
@@ -1,16 +1,18 @@
 /* Print Z80 and R800 instructions
-   Copyright 2005 Free Software Foundation, Inc.
+   Copyright (C) 2005-2019 Free Software Foundation, Inc.
    Contributed by Arnold Metselaar <arnold_m@operamail.com>
 
-   This file is free software; you can redistribute it and/or modify
+   This file is part of the GNU opcodes library.
+
+   This library is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
+   the Free Software Foundation; either version 3, or (at your option)
+   any later version.
 
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
+   It is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+   or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+   License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
@@ -18,7 +20,7 @@
    MA 02110-1301, USA.  */
 
 #include "sysdep.h"
-#include "dis-asm.h"
+#include "disassemble.h"
 #include <stdio.h>
 
 struct buffer
@@ -26,7 +28,7 @@ struct buffer
   bfd_vma base;
   int n_fetch;
   int n_used;
-  char data[4];
+  signed char data[4];
 } ;
 
 typedef int (*func)(struct buffer *, disassemble_info *, char *);
@@ -39,7 +41,7 @@ struct tab_elt
   char *        text;
 } ;
 
-#define TXTSIZ 16
+#define TXTSIZ 24
 /* Names of 16-bit registers.  */
 static char * rr_str[] = { "bc", "de", "hl", "sp" };
 /* Names of 8-bit registers.  */
@@ -61,7 +63,7 @@ fetch_data (struct buffer *buf, disassemble_info * info, int n)
     abort ();
 
   r = info->read_memory_func (buf->base + buf->n_fetch,
-                             buf->data + buf->n_fetch,
+                             (unsigned char*) buf->data + buf->n_fetch,
                              n, info);
   if (r == 0)
     buf->n_fetch += n;
@@ -126,8 +128,10 @@ static int
 prt_rr_nn (struct buffer *buf, disassemble_info * info, char *txt)
 {
   char mytxt[TXTSIZ];
+  int rr;
 
-  snprintf (mytxt, TXTSIZ, txt, rr_str[(buf->data[0] >> 4) & 3]);
+  rr = (buf->data[buf->n_fetch - 1] >> 4) & 3;
+  snprintf (mytxt, TXTSIZ, txt, rr_str[rr]);
   return prt_nn (buf, info, mytxt);
 }
 
@@ -295,9 +299,11 @@ struct tab_elt opc_ed[] =
   { 0x4A, 0xCF, prt_rr, "adc hl," },
   { 0x4B, 0xCF, prt_rr_nn, "ld %s,(0x%%04x)" },
   { 0x4D, 0xFF, prt, "reti" },
+  { 0x4F, 0xFF, prt, "ld r,a" },
   { 0x56, 0xFF, prt, "im 1" },
   { 0x57, 0xFF, prt, "ld a,i" },
   { 0x5E, 0xFF, prt, "im 2" },
+  { 0x5F, 0xFF, prt, "ld a,r" },
   { 0x67, 0xFF, prt, "rrd" },
   { 0x6F, 0xFF, prt, "rld" },
   { 0xA0, 0xE4, cis, "" },
@@ -308,7 +314,7 @@ struct tab_elt opc_ed[] =
 };
 
 static int
-pref_ed (struct buffer * buf, disassemble_info * info, 
+pref_ed (struct buffer * buf, disassemble_info * info,
         char* txt ATTRIBUTE_UNUSED)
 {
   struct tab_elt *p;
@@ -379,7 +385,7 @@ prt_d (struct buffer *buf, disassemble_info * info, char *txt)
   int d;
   signed char *p;
 
-  p = (unsigned char*) buf->data + buf->n_fetch;
+  p = buf->data + buf->n_fetch;
 
   if (fetch_data (buf, info, 1))
     {
@@ -400,7 +406,7 @@ prt_d_n (struct buffer *buf, disassemble_info * info, char *txt)
   int d;
   signed char *p;
 
-  p = (unsigned char*) buf->data + buf->n_fetch;
+  p = buf->data + buf->n_fetch;
 
   if (fetch_data (buf, info, 1))
     {
@@ -418,7 +424,7 @@ static int
 arit_d (struct buffer *buf, disassemble_info * info, char *txt)
 {
   char mytxt[TXTSIZ];
-  unsigned char c;
+  signed char c;
 
   c = buf->data[buf->n_fetch - 1];
   snprintf (mytxt, TXTSIZ, txt, arit_str[(c >> 3) & 7]);
@@ -429,7 +435,7 @@ static int
 ld_r_d (struct buffer *buf, disassemble_info * info, char *txt)
 {
   char mytxt[TXTSIZ];
-  unsigned char c;
+  signed char c;
 
   c = buf->data[buf->n_fetch - 1];
   snprintf (mytxt, TXTSIZ, txt, r_str[(c >> 3) & 7]);
@@ -440,7 +446,7 @@ static int
 ld_d_r(struct buffer *buf, disassemble_info * info, char *txt)
 {
   char mytxt[TXTSIZ];
-  unsigned char c;
+  signed char c;
 
   c = buf->data[buf->n_fetch - 1];
   snprintf (mytxt, TXTSIZ, txt, r_str[c & 7]);
@@ -461,9 +467,9 @@ pref_xd_cb (struct buffer * buf, disassemble_info * info, char* txt)
       d = p[2];
 
       if (((p[3] & 0xC0) == 0x40) || ((p[3] & 7) == 0x06))
-       snprintf (arg, TXTSIZ, "(%s+%d)", txt, d);
+       snprintf (arg, TXTSIZ, "(%s%+d)", txt, d);
       else
-       snprintf (arg, TXTSIZ, "(%s+%d),%s", txt, d, r_str[p[3] & 7]);
+       snprintf (arg, TXTSIZ, "(%s%+d),%s", txt, d, r_str[p[3] & 7]);
 
       if ((p[3] & 0xc0) == 0)
        info->fprintf_func (info->stream, "%s %s",
@@ -494,18 +500,18 @@ static struct tab_elt opc_ind[] =
   { 0x2B, 0xFF, prt, "dec %s" },
   { 0x29, 0xFF, addvv, "%s" },
   { 0x09, 0xCF, prt_rr, "add %s," },
-  { 0x34, 0xFF, prt_d, "inc (%s+%%d)" },
-  { 0x35, 0xFF, prt_d, "dec (%s+%%d)" },
-  { 0x36, 0xFF, prt_d_n, "ld (%s+%%d),0x%%02x" },
+  { 0x34, 0xFF, prt_d, "inc (%s%%+d)" },
+  { 0x35, 0xFF, prt_d, "dec (%s%%+d)" },
+  { 0x36, 0xFF, prt_d_n, "ld (%s%%+d),0x%%%%02x" },
 
   { 0x76, 0xFF, dump, "h" },
-  { 0x46, 0xC7, ld_r_d, "ld %%s,(%s+%%%%d)" },
-  { 0x70, 0xF8, ld_d_r, "ld (%s+%%%%d),%%s" },
+  { 0x46, 0xC7, ld_r_d, "ld %%s,(%s%%%%+d)" },
+  { 0x70, 0xF8, ld_d_r, "ld (%s%%%%+d),%%s" },
   { 0x64, 0xF6, ld_v_v, "%s" },
   { 0x60, 0xF0, ld_r_r, "ld %s%%s,%%s" },
   { 0x44, 0xC6, ld_r_r, "ld %%s,%s%%s" },
 
-  { 0x86, 0xC7, arit_d, "%%s(%s+%%%%d)" },
+  { 0x86, 0xC7, arit_d, "%%s(%s%%%%+d)" },
   { 0x84, 0xC6, arit_r, "%%s%s%%s" },
 
   { 0xE1, 0xFF, prt, "pop %s" },
This page took 0.027364 seconds and 4 git commands to generate.