From 3e3d6f97f49c4c0657aa45f672ae1d0c468684f2 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 3 Jun 2017 12:16:21 -0400 Subject: [PATCH] Edged towards being able to implement interrupt mode 0: created a special-case micro-op for incrementing the PC, and formalised that DecodeOperation is a terminal operation. --- Processors/Z80/Z80.hpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Processors/Z80/Z80.hpp b/Processors/Z80/Z80.hpp index 7d39f0d6e..be00730a6 100644 --- a/Processors/Z80/Z80.hpp +++ b/Processors/Z80/Z80.hpp @@ -92,6 +92,8 @@ struct MicroOp { Move8, Move16, + IncrementPC, + AssembleAF, DisassembleAF, @@ -230,8 +232,10 @@ template class Processor: public MicroOpScheduler { #define FINDEX() {MicroOp::IndexedPlaceHolder}, FETCH(temp8_, pc_), {MicroOp::CalculateIndexAddress, &index} #define INDEX_ADDR() (add_offsets ? temp16_ : index) +#define INC16(r) {(&r == &pc_) ? MicroOp::IncrementPC : MicroOp::Increment16, &r.full} + /// Fetches into x from address y, and then increments y. -#define FETCH(x, y) {MicroOp::BusOperation, nullptr, nullptr, {Read, 3, &y.full, &x}}, {MicroOp::Increment16, &y.full} +#define FETCH(x, y) {MicroOp::BusOperation, nullptr, nullptr, {Read, 3, &y.full, &x}}, INC16(y) /// Fetches into x from address y. #define FETCHL(x, y) {MicroOp::BusOperation, nullptr, nullptr, {Read, 3, &y.full, &x}} @@ -634,28 +638,23 @@ template class Processor: public MicroOpScheduler { } void assemble_fetch_decode_execute(InstructionPage &target, int length) { - // TODO: this can't legitimately be static and contain references to this via pc_ and operation_; - // make it something else that is built at instance construction. const MicroOp fetch_decode_execute[] = { { MicroOp::BusOperation, nullptr, nullptr, {(length == 4) ? ReadOpcode : Read, length, &pc_.full, &operation_}}, { MicroOp::DecodeOperation }, { MicroOp::MoveToNextProgram } }; - target.fetch_decode_execute.resize(3); - target.fetch_decode_execute[0] = fetch_decode_execute[0]; - target.fetch_decode_execute[1] = fetch_decode_execute[1]; - target.fetch_decode_execute[2] = fetch_decode_execute[2]; + copy_program(fetch_decode_execute, target.fetch_decode_execute); target.fetch_decode_execute_data = target.fetch_decode_execute.data(); } - void copy_program(MicroOp *source, std::vector &destination) { + void copy_program(const MicroOp *source, std::vector &destination) { size_t length = 0; - while(source[length].type != MicroOp::MoveToNextProgram) length++; + while(source[length].type != MicroOp::MoveToNextProgram && source[length].type != MicroOp::DecodeOperation) length++; destination.resize(length + 1); size_t pointer = 0; while(true) { destination[pointer] = source[pointer]; - if(source[pointer].type == MicroOp::MoveToNextProgram) break; + if(source[pointer].type == MicroOp::MoveToNextProgram || source[pointer].type == MicroOp::DecodeOperation) break; pointer++; } } @@ -764,6 +763,7 @@ template class Processor: public MicroOpScheduler { break; case MicroOp::Increment16: (*(uint16_t *)operation->source)++; break; + case MicroOp::IncrementPC: pc_.full++; break; case MicroOp::Decrement16: (*(uint16_t *)operation->source)--; break; case MicroOp::Move8: *(uint8_t *)operation->destination = *(uint8_t *)operation->source; break; case MicroOp::Move16: *(uint16_t *)operation->destination = *(uint16_t *)operation->source; break;