-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstruction.h
144 lines (100 loc) · 3.23 KB
/
Instruction.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//
// Mnemonic.h
// 65calc02
//
// Created by Kelvin Sherlock on 9/5/2011.
// Copyright 2011 Kelvin W Sherlock LLC. All rights reserved.
//
#ifndef __Mnemonic_h__
#define __Mnemonic_h__
#include "Machine.h"
#include <string>
#include <stdint.h>
#include "include/const_vector.h"
class Instruction {
private:
Machine _machine = kUndefinedMachine;
Mnemonic _mnemonic = kUndefinedMnemonic;
uint_least32_t _addressModes = 0;
public:
// static methods
static const_vector<Instruction> Instructions(Machine machine);
static bool coerce(Instruction &instruction, AddressMode &addressMode, bool explicitAddress);
// constructors
Instruction(Machine machine, const std::string &s) : Instruction(machine, s.c_str()) {}
Instruction() = default;
Instruction(const Instruction & rhs) = default;
Instruction(Machine machine, const char *name);
Instruction(Machine machine, Mnemonic mnemonic);
Instruction &operator=(const Instruction&) = default;
// -- instance methods
Machine machine() const;
Mnemonic mnemonic() const;
uint_least32_t addressModes() const;
bool hasAddressMode(AddressMode mode) const;
bool isRelative() const;
explicit operator bool() const;
const char *toString() const;
unsigned bytes(AddressMode addressMode, bool longM = false, bool longXY = false) const;
#ifdef __COREFOUNDATION_CFSTRING__
CFStringRef toCFString() const
{
return MnemonicToCFString(_mnemonic);
}
#endif
#ifdef __OBJC__
NSString *toNSString() const
{
return MnemonicToNSString(_mnemonic);
}
NSString *formatOperand(uint32_t operand, AddressMode addressMode, uint16_t address, bool longM = false, bool longX = false);
#endif
private:
friend class OpCode;
static Instruction m6502_instructions[];
static Instruction m65c02_instructions[];
static Instruction m65ce02_instructions[];
static Instruction mw65c02_instructions[];
static Instruction mr65c02_instructions[];
static Instruction m65816_instructions[];
static Mnemonic m6502_mnemonics[];
static Mnemonic m65c02_mnemonics[];
static Mnemonic m65ce02_mnemonics[];
static Mnemonic mw65c02_mnemonics[];
static Mnemonic mr65c02_mnemonics[];
static Mnemonic m65816_mnemonics[];
Instruction(Machine machine, Mnemonic mnemonic, uint_least32_t addressModes);
};
inline Instruction::Instruction(Machine machine, Mnemonic mnemonic, uint_least32_t addressModes) :
_machine(machine), _mnemonic(mnemonic), _addressModes(addressModes)
{
}
inline Machine Instruction::machine() const
{
return _machine;
}
inline Mnemonic Instruction::mnemonic() const
{
return _mnemonic;
}
inline uint_least32_t Instruction::addressModes() const
{
return _addressModes;
}
inline bool Instruction::hasAddressMode(AddressMode mode) const
{
return _addressModes & (1 << mode);
}
inline bool Instruction::isRelative() const
{
return _addressModes & ((1 << relative) | (1 << relative_long));
}
inline Instruction::operator bool() const
{
return _mnemonic != kUndefinedMnemonic;
}
inline const char *Instruction::toString() const
{
return MnemonicToString(_mnemonic);
}
#endif