Rizin
unix-like reverse engineering framework and cli tools
asm_snes.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2012-2015 condret <condr3t@protonmail.com>
2 // SPDX-FileCopyrightText: 2012-2015 pancake <pancake@nopcode.org>
3 // SPDX-License-Identifier: LGPL-3.0-only
4 
5 #include <rz_types.h>
6 #include <rz_util.h>
7 #include <rz_asm.h>
8 #include <rz_lib.h>
9 #include "../arch/snes/snesdis.c"
10 #include "asm_snes.h"
11 
12 static int dis(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) {
13  struct snes_asm_flags *snesflags = (struct snes_asm_flags *)a->plugin_data;
14  int dlen = snesDisass(snesflags->M, snesflags->X, a->pc, op, buf, len);
15  if (dlen < 0) {
16  dlen = 0;
17  }
18  op->size = dlen;
19  if (buf[0] == 0xc2) { // REP
20  if (buf[1] & 0x10) {
21  snesflags->X = 0;
22  }
23  if (buf[1] & 0x20) {
24  snesflags->M = 0;
25  }
26  } else if (buf[0] == 0xe2) { // SEP
27  if (buf[1] & 0x10) {
28  snesflags->X = 1;
29  }
30  if (buf[1] & 0x20) {
31  snesflags->M = 1;
32  }
33  }
34  return dlen;
35 }
36 
37 static bool snes_asm_init(void **user) {
38  *user = RZ_NEW0(struct snes_asm_flags);
39  return *user != NULL;
40 }
41 
42 static bool snes_asm_fini(void *user) {
43  rz_return_val_if_fail(user, false);
44  free(user);
45  return true;
46 }
47 
49  .name = "snes",
50  .desc = "SuperNES CPU",
51  .arch = "snes",
52  .bits = 8 | 16,
53  .init = snes_asm_init,
54  .fini = snes_asm_fini,
55  .endian = RZ_SYS_ENDIAN_LITTLE,
56  .license = "LGPL3",
57  .disassemble = &dis
58 };
59 
60 #ifndef RZ_PLUGIN_INCORE
63  .data = &rz_asm_plugin_snes,
65 };
66 #endif
size_t len
Definition: 6502dis.c:15
static bool snes_asm_fini(void *user)
Definition: asm_snes.c:42
RZ_API RzLibStruct rizin_plugin
Definition: asm_snes.c:61
RzAsmPlugin rz_asm_plugin_snes
Definition: asm_snes.c:48
static int dis(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len)
Definition: asm_snes.c:12
static bool snes_asm_init(void **user)
Definition: asm_snes.c:37
#define RZ_API
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
@ RZ_LIB_TYPE_ASM
Definition: rz_lib.h:72
#define RZ_SYS_ENDIAN_LITTLE
Definition: rz_types.h:526
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_VERSION
Definition: rz_version.h:8
#define a(i)
Definition: sha256.c:41
static int snesDisass(int M_flag, int X_flag, ut64 pc, RzAsmOp *op, const ut8 *buf, int len)
Definition: snesdis.c:12
const char * name
Definition: rz_asm.h:130
const char * version
Definition: rz_asm.h:133
unsigned char M
Definition: asm_snes.h:9
unsigned char X
Definition: asm_snes.h:10
Definition: dis.c:32