2021-01-16 02:30:30 +00:00
|
|
|
//
|
|
|
|
// Instruction.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
2021-01-17 03:09:19 +00:00
|
|
|
// Created by Thomas Harte on 15/01/21.
|
2021-01-16 02:30:30 +00:00
|
|
|
// Copyright © 2021 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef InstructionSets_M50740_Instruction_h
|
|
|
|
#define InstructionSets_M50740_Instruction_h
|
|
|
|
|
|
|
|
#include <cstdint>
|
2021-01-17 01:04:01 +00:00
|
|
|
#include "../AccessType.hpp"
|
2021-01-16 02:30:30 +00:00
|
|
|
|
|
|
|
namespace InstructionSet {
|
|
|
|
namespace M50740 {
|
|
|
|
|
|
|
|
enum class AddressingMode {
|
2021-01-16 03:47:52 +00:00
|
|
|
Implied, Accumulator, Immediate,
|
|
|
|
Absolute, AbsoluteX, AbsoluteY,
|
|
|
|
ZeroPage, ZeroPageX, ZeroPageY,
|
|
|
|
XIndirect, IndirectY,
|
2021-01-16 02:30:30 +00:00
|
|
|
Relative,
|
2021-01-16 03:47:52 +00:00
|
|
|
AbsoluteIndirect, ZeroPageIndirect,
|
2021-01-16 02:30:30 +00:00
|
|
|
SpecialPage,
|
2021-01-16 02:50:05 +00:00
|
|
|
ImmediateZeroPage,
|
|
|
|
|
|
|
|
Bit0Accumulator, Bit1Accumulator, Bit2Accumulator, Bit3Accumulator,
|
2021-01-16 03:24:37 +00:00
|
|
|
Bit4Accumulator, Bit5Accumulator, Bit6Accumulator, Bit7Accumulator,
|
2021-01-16 02:50:05 +00:00
|
|
|
|
|
|
|
Bit0ZeroPage, Bit1ZeroPage, Bit2ZeroPage, Bit3ZeroPage,
|
|
|
|
Bit4ZeroPage, Bit5ZeroPage, Bit6ZeroPage, Bit7ZeroPage,
|
|
|
|
|
|
|
|
Bit0AccumulatorRelative, Bit1AccumulatorRelative, Bit2AccumulatorRelative, Bit3AccumulatorRelative,
|
|
|
|
Bit4AccumulatorRelative, Bit5AccumulatorRelative, Bit6AccumulatorRelative, Bit7AccumulatorRelative,
|
|
|
|
|
|
|
|
Bit0ZeroPageRelative, Bit1ZeroPageRelative, Bit2ZeroPageRelative, Bit3ZeroPageRelative,
|
|
|
|
Bit4ZeroPageRelative, Bit5ZeroPageRelative, Bit6ZeroPageRelative, Bit7ZeroPageRelative,
|
2021-01-16 02:30:30 +00:00
|
|
|
};
|
|
|
|
|
2021-01-17 02:45:44 +00:00
|
|
|
static constexpr auto MaxAddressingMode = int(AddressingMode::Bit7ZeroPageRelative);
|
|
|
|
static constexpr auto MinAddressingMode = int(AddressingMode::Implied);
|
|
|
|
|
2021-01-17 01:04:01 +00:00
|
|
|
constexpr int size(AddressingMode mode) {
|
2021-01-16 03:47:52 +00:00
|
|
|
// This is coupled to the AddressingMode list above; be careful!
|
|
|
|
constexpr int sizes[] = {
|
|
|
|
0, 0, 0,
|
|
|
|
2, 2, 2,
|
|
|
|
1, 1, 1,
|
|
|
|
1, 1,
|
|
|
|
1,
|
|
|
|
2, 1,
|
|
|
|
1,
|
|
|
|
2,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1,
|
|
|
|
1, 1, 1, 1,
|
|
|
|
2, 2, 2, 2,
|
|
|
|
2, 2, 2, 2,
|
|
|
|
};
|
2021-01-17 02:45:44 +00:00
|
|
|
static_assert(sizeof(sizes)/sizeof(*sizes) == int(MaxAddressingMode) + 1);
|
2021-01-16 03:47:52 +00:00
|
|
|
return sizes[int(mode)];
|
|
|
|
}
|
|
|
|
|
2021-01-16 02:30:30 +00:00
|
|
|
enum class Operation: uint8_t {
|
2021-01-16 02:50:05 +00:00
|
|
|
Invalid,
|
|
|
|
|
2021-01-17 00:54:40 +00:00
|
|
|
// Operations that don't access memory.
|
|
|
|
BBC, BBS, BCC, BCS,
|
|
|
|
BEQ, BMI, BNE, BPL,
|
|
|
|
BVC, BVS, BRA, BRK,
|
|
|
|
JMP, JSR,
|
|
|
|
RTI, RTS,
|
|
|
|
CLC, CLD, CLI, CLT, CLV,
|
|
|
|
SEC, SED, SEI, SET,
|
|
|
|
INX, INY, DEX, DEY,
|
|
|
|
FST, SLW,
|
|
|
|
NOP,
|
|
|
|
PHA, PHP, PLA, PLP,
|
|
|
|
STP,
|
|
|
|
TAX, TAY, TSX, TXA,
|
|
|
|
TXS, TYA,
|
|
|
|
|
|
|
|
// Read operations.
|
|
|
|
ADC, SBC,
|
|
|
|
AND, ORA, EOR, BIT,
|
|
|
|
CMP, CPX, CPY,
|
|
|
|
LDA, LDX, LDY,
|
|
|
|
TST,
|
|
|
|
|
|
|
|
// Read-modify-write operations.
|
|
|
|
ASL, LSR,
|
|
|
|
CLB, SEB,
|
|
|
|
COM,
|
|
|
|
DEC, INC,
|
|
|
|
ROL, ROR, RRF,
|
2021-01-17 01:04:01 +00:00
|
|
|
|
|
|
|
// Write operations.
|
|
|
|
LDM,
|
|
|
|
STA, STX, STY,
|
2021-01-16 02:30:30 +00:00
|
|
|
};
|
|
|
|
|
2021-01-17 02:45:44 +00:00
|
|
|
static constexpr auto MaxOperation = int(Operation::STY);
|
|
|
|
static constexpr auto MinOperation = int(Operation::BBC);
|
|
|
|
|
2021-01-17 01:04:01 +00:00
|
|
|
constexpr AccessType access_type(Operation operation) {
|
|
|
|
if(operation < Operation::ADC) return AccessType::None;
|
2021-01-17 01:04:48 +00:00
|
|
|
if(operation < Operation::ASL) return AccessType::Read;
|
2021-01-17 01:04:01 +00:00
|
|
|
if(operation < Operation::LDM) return AccessType::Write;
|
|
|
|
return AccessType::ReadModifyWrite;
|
|
|
|
}
|
|
|
|
|
2021-01-16 02:30:30 +00:00
|
|
|
struct Instruction {
|
2021-01-16 02:50:05 +00:00
|
|
|
Operation operation = Operation::Invalid;
|
|
|
|
AddressingMode addressing_mode = AddressingMode::Implied;
|
2021-01-16 02:30:30 +00:00
|
|
|
|
|
|
|
Instruction(Operation operation, AddressingMode addressing_mode) : operation(operation), addressing_mode(addressing_mode) {}
|
2021-01-16 02:50:05 +00:00
|
|
|
Instruction(Operation operation) : operation(operation) {}
|
|
|
|
Instruction() {}
|
2021-01-16 02:30:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* InstructionSets_M50740_Instruction_h */
|