include/mgba/internal/lr35902/decoder.h (view raw)
1/* Copyright (c) 2013-2017 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef LR35902_DECODER_H
7#define LR35902_DECODER_H
8
9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13enum LR35902Condition {
14 LR35902_COND_NONE = 0x0,
15 LR35902_COND_C = 0x1,
16 LR35902_COND_Z = 0x2,
17 LR35902_COND_NC = 0x3,
18 LR35902_COND_NZ = 0x4
19};
20
21enum LR35902Mnemonic {
22 LR35902_MN_ILL = 0,
23 LR35902_MN_ADC,
24 LR35902_MN_ADD,
25 LR35902_MN_AND,
26 LR35902_MN_BIT,
27 LR35902_MN_CALL,
28 LR35902_MN_CCF,
29 LR35902_MN_CP,
30 LR35902_MN_CPL,
31 LR35902_MN_DAA,
32 LR35902_MN_DEC,
33 LR35902_MN_DI,
34 LR35902_MN_EI,
35 LR35902_MN_HALT,
36 LR35902_MN_INC,
37 LR35902_MN_JP,
38 LR35902_MN_JR,
39 LR35902_MN_LD,
40 LR35902_MN_NOP,
41 LR35902_MN_OR,
42 LR35902_MN_POP,
43 LR35902_MN_PUSH,
44 LR35902_MN_RES,
45 LR35902_MN_RET,
46 LR35902_MN_RETI,
47 LR35902_MN_RL,
48 LR35902_MN_RLC,
49 LR35902_MN_RR,
50 LR35902_MN_RRC,
51 LR35902_MN_RST,
52 LR35902_MN_SBC,
53 LR35902_MN_SCF,
54 LR35902_MN_SET,
55 LR35902_MN_SLA,
56 LR35902_MN_SRA,
57 LR35902_MN_SRL,
58 LR35902_MN_STOP,
59 LR35902_MN_SUB,
60 LR35902_MN_SWAP,
61 LR35902_MN_XOR,
62
63 LR35902_MN_MAX
64};
65
66enum LR35902Register {
67 LR35902_REG_B = 1,
68 LR35902_REG_C,
69 LR35902_REG_D,
70 LR35902_REG_E,
71 LR35902_REG_H,
72 LR35902_REG_L,
73 LR35902_REG_A,
74 LR35902_REG_F,
75 LR35902_REG_BC,
76 LR35902_REG_DE,
77 LR35902_REG_HL,
78 LR35902_REG_AF,
79
80 LR35902_REG_SP,
81 LR35902_REG_PC
82};
83
84enum {
85 LR35902_OP_FLAG_IMPLICIT = 1,
86 LR35902_OP_FLAG_MEMORY = 2,
87 LR35902_OP_FLAG_INCREMENT = 4,
88 LR35902_OP_FLAG_DECREMENT = 8,
89 LR35902_OP_FLAG_RELATIVE = 16,
90};
91
92struct LR35902Operand {
93 uint8_t reg;
94 uint8_t flags;
95 uint16_t immediate;
96};
97
98struct LR35902InstructionInfo {
99 uint8_t opcode[3];
100 uint8_t opcodeSize;
101 struct LR35902Operand op1;
102 struct LR35902Operand op2;
103 unsigned mnemonic;
104 unsigned condition;
105};
106
107size_t LR35902Decode(uint8_t opcode, struct LR35902InstructionInfo* info);
108int LR35902Disassemble(struct LR35902InstructionInfo* info, uint16_t pc, char* buffer, int blen);
109
110CXX_GUARD_END
111
112#endif