all repos — mgba @ b1828dbc59b8a9cc080c8c7f9472c46a3d39e90c

mGBA Game Boy Advance Emulator

include/mgba/internal/sm83/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 SM83_DECODER_H
  7#define SM83_DECODER_H
  8
  9#include <mgba-util/common.h>
 10
 11CXX_GUARD_START
 12
 13enum SM83Condition {
 14	SM83_COND_NONE = 0x0,
 15	SM83_COND_C = 0x1,
 16	SM83_COND_Z = 0x2,
 17	SM83_COND_NC = 0x3,
 18	SM83_COND_NZ = 0x4
 19};
 20
 21enum SM83Mnemonic {
 22	SM83_MN_ILL = 0,
 23	SM83_MN_ADC,
 24	SM83_MN_ADD,
 25	SM83_MN_AND,
 26	SM83_MN_BIT,
 27	SM83_MN_CALL,
 28	SM83_MN_CCF,
 29	SM83_MN_CP,
 30	SM83_MN_CPL,
 31	SM83_MN_DAA,
 32	SM83_MN_DEC,
 33	SM83_MN_DI,
 34	SM83_MN_EI,
 35	SM83_MN_HALT,
 36	SM83_MN_INC,
 37	SM83_MN_JP,
 38	SM83_MN_JR,
 39	SM83_MN_LD,
 40	SM83_MN_NOP,
 41	SM83_MN_OR,
 42	SM83_MN_POP,
 43	SM83_MN_PUSH,
 44	SM83_MN_RES,
 45	SM83_MN_RET,
 46	SM83_MN_RETI,
 47	SM83_MN_RL,
 48	SM83_MN_RLC,
 49	SM83_MN_RR,
 50	SM83_MN_RRC,
 51	SM83_MN_RST,
 52	SM83_MN_SBC,
 53	SM83_MN_SCF,
 54	SM83_MN_SET,
 55	SM83_MN_SLA,
 56	SM83_MN_SRA,
 57	SM83_MN_SRL,
 58	SM83_MN_STOP,
 59	SM83_MN_SUB,
 60	SM83_MN_SWAP,
 61	SM83_MN_XOR,
 62
 63	SM83_MN_MAX
 64};
 65
 66enum SM83Register {
 67	SM83_REG_B = 1,
 68	SM83_REG_C,
 69	SM83_REG_D,
 70	SM83_REG_E,
 71	SM83_REG_H,
 72	SM83_REG_L,
 73	SM83_REG_A,
 74	SM83_REG_F,
 75	SM83_REG_BC,
 76	SM83_REG_DE,
 77	SM83_REG_HL,
 78	SM83_REG_AF,
 79
 80	SM83_REG_SP,
 81	SM83_REG_PC
 82};
 83
 84enum {
 85	SM83_OP_FLAG_IMPLICIT = 1,
 86	SM83_OP_FLAG_MEMORY = 2,
 87	SM83_OP_FLAG_INCREMENT = 4,
 88	SM83_OP_FLAG_DECREMENT = 8,
 89	SM83_OP_FLAG_RELATIVE = 16,
 90};
 91
 92struct SM83Operand {
 93	uint8_t reg;
 94	uint8_t flags;
 95	uint16_t immediate;
 96};
 97
 98struct SM83InstructionInfo {
 99	uint8_t opcode[3];
100	uint8_t opcodeSize;
101	struct SM83Operand op1;
102	struct SM83Operand op2;
103	unsigned mnemonic;
104	unsigned condition;
105};
106
107size_t SM83Decode(uint8_t opcode, struct SM83InstructionInfo* info);
108int SM83Disassemble(struct SM83InstructionInfo* info, uint16_t pc, char* buffer, int blen);
109
110CXX_GUARD_END
111
112#endif