2019-04-15 22:51:04 +00:00
|
|
|
#include "opcode-handler-directory.h"
|
|
|
|
#include "handler/load-opcode-handler-container.h"
|
2019-04-17 16:31:35 +00:00
|
|
|
#include "handler/store-opcode-handler-container.h"
|
2019-04-17 21:03:06 +00:00
|
|
|
#include "handler/transfer-opcode-handler-container.h"
|
2019-04-18 00:09:44 +00:00
|
|
|
#include "handler/maths-opcode-handler-container.h"
|
2019-04-20 22:58:03 +00:00
|
|
|
#include "handler/bitwise-opcode-handler-container.h"
|
2019-04-15 22:51:04 +00:00
|
|
|
#include "../utils.h"
|
|
|
|
|
|
|
|
namespace emu_6502 {
|
|
|
|
|
|
|
|
OpcodeHandlerDirectory::OpcodeHandlerDirectory() : handler_containers{}, handlers{} {
|
|
|
|
handler_containers.push_back(make_unique<LoadOpcodeHandlerContainer>());
|
2019-04-17 16:31:35 +00:00
|
|
|
handler_containers.push_back(make_unique<StoreOpcodeHandlerContainer>());
|
2019-04-17 21:03:06 +00:00
|
|
|
handler_containers.push_back(make_unique<TransferOpcodeHandlerContainer>());
|
2019-04-18 00:09:44 +00:00
|
|
|
handler_containers.push_back(make_unique<MathsOpcodeHandlerContainer>());
|
2019-04-20 22:58:03 +00:00
|
|
|
handler_containers.push_back(make_unique<BitwiseOpcodeHandlerContainer>());
|
2019-04-15 22:51:04 +00:00
|
|
|
|
|
|
|
init_handlers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpcodeHandlerDirectory::init_handlers() {
|
|
|
|
for (auto& hc : handler_containers) {
|
|
|
|
for (auto& h : hc->get_handlers()) {
|
|
|
|
handlers.insert({h.first, h.second});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpcodeHandlerDirectory::execute(uint8_t opcode, Machine& machine) {
|
|
|
|
auto func = handlers.find(opcode);
|
|
|
|
if (func == handlers.end())
|
|
|
|
throw runtime_error("No appropriate handler for opcode 0x" + uint_to_hex(opcode));
|
|
|
|
|
|
|
|
func->second(machine);
|
|
|
|
}
|
|
|
|
}
|