2020-09-24 02:14:42 +00:00
|
|
|
//
|
|
|
|
// 65816Implementation.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 23/09/2020.
|
|
|
|
// Copyright © 2020 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef WDC65816Implementation_h
|
|
|
|
#define WDC65816Implementation_h
|
|
|
|
|
|
|
|
class ProcessorStorage {
|
|
|
|
public:
|
|
|
|
ProcessorStorage();
|
|
|
|
|
|
|
|
enum MicroOp: uint8_t {
|
|
|
|
/// Fetches a byte from the program counter to the instruction buffer and increments the program counter.
|
|
|
|
CycleFetchIncrementPC,
|
2020-09-24 21:36:11 +00:00
|
|
|
/// Fetches a byte from the program counter without incrementing it, and throws it away.
|
|
|
|
CycleFetchPCDiscard,
|
2020-09-24 02:23:23 +00:00
|
|
|
|
2020-09-24 21:36:11 +00:00
|
|
|
/// Fetches a byte from the data address to the data buffer.
|
|
|
|
CycleFetchData,
|
2020-09-24 02:14:42 +00:00
|
|
|
/// Fetches a byte from the data address to the data buffer and increments the data address.
|
|
|
|
CycleFetchIncrementData,
|
2020-09-24 21:36:11 +00:00
|
|
|
|
|
|
|
/// Stores a byte from the data buffer.
|
|
|
|
CycleStoreData,
|
2020-09-24 02:14:42 +00:00
|
|
|
/// Stores a byte to the data address from the data buffer and increments the data address.
|
|
|
|
CycleStoreIncrementData,
|
2020-09-24 21:36:11 +00:00
|
|
|
/// Stores a byte to the data address from the data buffer and decrements the data address.
|
|
|
|
CycleStoreDecrementData,
|
2020-09-24 02:14:42 +00:00
|
|
|
|
2020-09-24 02:23:23 +00:00
|
|
|
/// Pushes a single byte from the data buffer to the stack.
|
|
|
|
CyclePush,
|
|
|
|
|
2020-09-24 02:14:42 +00:00
|
|
|
/// Sets the data address by copying the final two bytes of the instruction buffer.
|
|
|
|
OperationConstructAbsolute,
|
|
|
|
|
|
|
|
/// Performs whatever operation goes with this program.
|
|
|
|
OperationPerform,
|
|
|
|
|
|
|
|
/// Complete this set of micr-ops.
|
|
|
|
OperationMoveToNextProgram
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Operation: uint8_t {
|
2020-09-24 02:23:23 +00:00
|
|
|
// These perform the named operation using the value in the data buffer.
|
|
|
|
ADC, AND, BIT, CMP, CPX, CPY, EOR, ORA, SBC,
|
|
|
|
|
|
|
|
// These load the respective register from the data buffer.
|
|
|
|
LDA, LDX, LDY,
|
2020-09-24 02:14:42 +00:00
|
|
|
|
2020-09-24 02:23:23 +00:00
|
|
|
// These move the respective register (or value) to the data buffer.
|
2020-09-24 02:14:42 +00:00
|
|
|
STA, STX, STY, STZ,
|
2020-09-24 02:23:23 +00:00
|
|
|
|
|
|
|
/// Loads the PC with the operand from the instruction buffer.
|
|
|
|
JMP,
|
|
|
|
|
|
|
|
/// Loads the PC with the operand from the instruction buffer, placing
|
|
|
|
/// the old PC into the data buffer.
|
|
|
|
JSR,
|
2020-09-24 02:14:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Instruction {
|
|
|
|
size_t program_offset;
|
|
|
|
Operation operation;
|
|
|
|
};
|
|
|
|
Instruction instructions[256];
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<MicroOp> micro_ops_;
|
|
|
|
|
|
|
|
size_t install_ops(std::initializer_list<MicroOp> ops) {
|
|
|
|
// Just copy into place and return the index at which copying began.
|
|
|
|
const size_t index = micro_ops_.size();
|
|
|
|
micro_ops_.insert(micro_ops_.end(), ops.begin(), ops.end());
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_instruction(uint8_t opcode, size_t micro_ops, Operation operation) {
|
|
|
|
instructions[opcode].program_offset = micro_ops;
|
|
|
|
instructions[opcode].operation = operation;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* WDC65816Implementation_h */
|