OXYGENHUB
# 2980b7b6d7cd enhanced-x16-emulator / src / insn_info.h
2.3 KiB · Objective-C · last changed chore(): initial commit 26 days ago source blame history raw
1
// Commander X16 Emulator
2
// Instruction reference data for the debugger.
3
//
4
// disasm.c can render an instruction, but it carries no description of what an
5
// instruction *does*: no summary, no flag effects, no "will this branch be
6
// taken". The debug UI wants all of that for its hover tooltips, so it lives
7
// here, keyed by mnemonic rather than by opcode (the mnemonic is what the user
8
// hovers in a source listing, and it is what disasm.c already produces).
9
10
#ifndef _INSN_INFO_H_
11
#define _INSN_INFO_H_
12
13
#include <stdbool.h>
14
#include <stdint.h>
15
16
#ifdef __cplusplus
17
extern "C" {
18
#endif
19
20
// Status bits an instruction can affect, for insn_info_t.flags_set.
21
#define INSN_FLAG_N 0x80
22
#define INSN_FLAG_V 0x40
23
#define INSN_FLAG_M 0x20
24
#define INSN_FLAG_X 0x10
25
#define INSN_FLAG_D 0x08
26
#define INSN_FLAG_I 0x04
27
#define INSN_FLAG_Z 0x02
28
#define INSN_FLAG_C 0x01
29
30
// What kind of instruction this is, so the debugger can decide what extra
31
// information is worth predicting.
32
typedef enum {
33
	INSN_KIND_OTHER = 0,
34
	INSN_KIND_LOAD,        // reads memory into a register
35
	INSN_KIND_STORE,       // writes a register to memory
36
	INSN_KIND_TRANSFER,    // register to register
37
	INSN_KIND_ALU,         // arithmetic / logic
38
	INSN_KIND_SHIFT,
39
	INSN_KIND_COMPARE,
40
	INSN_KIND_BRANCH,      // conditional relative branch
41
	INSN_KIND_JUMP,        // unconditional jump/call
42
	INSN_KIND_RETURN,
43
	INSN_KIND_STACK,
44
	INSN_KIND_FLAG,        // sets/clears a status bit
45
	INSN_KIND_INCDEC,
46
	INSN_KIND_BIT,
47
	INSN_KIND_INTERRUPT,
48
	INSN_KIND_NOP,
49
} insn_kind_t;
50
51
typedef struct {
52
	const char *mnemonic;   // lower case, as disasm.c emits
53
	const char *title;      // e.g. "Load Accumulator"
54
	const char *summary;    // one line of what it does
55
	insn_kind_t kind;
56
	uint8_t     flags_set;  // INSN_FLAG_* bits this instruction can change
57
	// For branches: the status bit tested and the value it must have for the
58
	// branch to be taken. Zero for everything else.
59
	uint8_t     branch_flag;
60
	bool        branch_when_set;
61
} insn_info_t;
62
63
// Look up by mnemonic (case-insensitive). NULL if unknown.
64
const insn_info_t *insn_info_lookup(const char *mnemonic);
65
66
// Render "N V - - - - Z C"-style text listing the flags an instruction touches.
67
// Writes at most `max` bytes including the terminator. Empty when none.
68
void insn_info_flag_text(uint8_t flags_set, char *out, unsigned int max);
69
70
#ifdef __cplusplus
71
}
72
#endif
73
74
#endif