-
Notifications
You must be signed in to change notification settings - Fork 2
/
instruction.h
42 lines (35 loc) · 925 Bytes
/
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
#pragma once
#include "instructiontype.h"
#include "operandsformat.h"
#include <cstdint>
struct Instruction {
static constexpr auto NumberOfOpCodes = 256;
static constexpr uint8_t sizeForAddressingMode(OperandsFormat mode) {
switch (mode) {
case ImpliedOrAccumulator: return 1;
case Branch:
case Immediate:
case ZeroPage:
case ZeroPageX:
case ZeroPageY:
case IndexedIndirectX:
case IndirectIndexedY: return 2;
case Indirect:
case Absolute:
case AbsoluteX:
case AbsoluteY: return 3;
}
return 0;
}
InstructionType type = KIL;
OperandsFormat mode = ImpliedOrAccumulator;
uint8_t size = 1;
uint8_t cycles = 0;
Instruction() = default;
constexpr Instruction(InstructionType type, OperandsFormat mode, uint8_t cycles) {
this->type = type;
this->mode = mode;
this->cycles = cycles;
this->size = sizeForAddressingMode(mode);
}
};