Rizin
unix-like reverse engineering framework and cli tools
snesdis.c File Reference
#include <rz_types.h>
#include <rz_util.h>
#include <rz_asm.h>
#include <rz_lib.h>
#include <string.h>
#include "snes_op_table.h"

Go to the source code of this file.

Functions

static int snesDisass (int M_flag, int X_flag, ut64 pc, RzAsmOp *op, const ut8 *buf, int len)
 

Function Documentation

◆ snesDisass()

static int snesDisass ( int  M_flag,
int  X_flag,
ut64  pc,
RzAsmOp op,
const ut8 buf,
int  len 
)
static

Definition at line 12 of file snesdis.c.

12  {
13  snes_op_t *s_op = &snes_op[buf[0]];
14  int op_len = snes_op_get_size(M_flag, X_flag, s_op);
15  if (len < op_len) {
16  return 0;
17  }
18  const char *buf_asm = "invalid";
19  switch (s_op->len) {
20  case SNES_OP_8BIT:
21  buf_asm = s_op->name;
22  break;
23  case SNES_OP_16BIT:
24  if (*buf % 0x20 == 0x10 || *buf == 0x80) { // relative branch
25  buf_asm = sdb_fmt(s_op->name, (ut32)(pc + 2 + (st8)buf[1]));
26  } else {
27  buf_asm = sdb_fmt(s_op->name, buf[1]);
28  }
29  break;
30  case SNES_OP_24BIT:
31  if (*buf == 0x44 || *buf == 0x54) { // mvp and mvn
32  buf_asm = sdb_fmt(s_op->name, buf[1], buf[2]);
33  } else if (*buf == 0x82) { // brl
34  buf_asm = sdb_fmt(s_op->name, pc + 3 + (st16)rz_read_le16(buf + 1));
35  } else {
36  buf_asm = sdb_fmt(s_op->name, rz_read_le16(buf + 1));
37  }
38  break;
39  case SNES_OP_32BIT:
40  buf_asm = sdb_fmt(s_op->name, buf[1] | buf[2] << 8 | buf[3] << 16);
41  break;
42  case SNES_OP_IMM_M:
43  if (M_flag) {
44  buf_asm = sdb_fmt("%s #0x%02x", s_op->name, buf[1]);
45  } else {
46  buf_asm = sdb_fmt("%s #0x%04x", s_op->name, rz_read_le16(buf + 1));
47  }
48  break;
49  case SNES_OP_IMM_X:
50  if (X_flag) {
51  buf_asm = sdb_fmt("%s #0x%02x", s_op->name, buf[1]);
52  } else {
53  buf_asm = sdb_fmt("%s #0x%04x", s_op->name, rz_read_le16(buf + 1));
54  }
55  break;
56  }
57  rz_strbuf_set(&op->buf_asm, buf_asm);
58  return op_len;
59 }
size_t len
Definition: 6502dis.c:15
uint32_t ut32
RZ_API char * sdb_fmt(const char *fmt,...)
Definition: fmt.c:26
voidpf void * buf
Definition: ioapi.h:138
static ut16 rz_read_le16(const void *src)
Definition: rz_endian.h:206
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
Definition: strbuf.c:153
#define st8
Definition: rz_types_base.h:16
#define st16
Definition: rz_types_base.h:14
@ SNES_OP_IMM_M
Definition: snes_op_table.h:14
@ SNES_OP_24BIT
Definition: snes_op_table.h:12
@ SNES_OP_IMM_X
Definition: snes_op_table.h:15
@ SNES_OP_32BIT
Definition: snes_op_table.h:13
@ SNES_OP_16BIT
Definition: snes_op_table.h:11
@ SNES_OP_8BIT
Definition: snes_op_table.h:10
static snes_op_t snes_op[]
Definition: snes_op_table.h:33
static int snes_op_get_size(int M_flag, int X_flag, snes_op_t *op)
Definition: snes_op_table.h:24
const char * name
Definition: snes_op_table.h:19
Definition: dis.c:32

References len, snes_op_t::len, snes_op_t::name, pc, rz_read_le16(), rz_strbuf_set(), sdb_fmt(), snes_op, SNES_OP_16BIT, SNES_OP_24BIT, SNES_OP_32BIT, SNES_OP_8BIT, snes_op_get_size(), SNES_OP_IMM_M, SNES_OP_IMM_X, st16, and st8.

Referenced by _6502Disass(), and dis().