1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-08-15 14:27:29 +00:00

In theory this should 'execute' up to the first unconditional branch.

Where execution means: do very little.
This commit is contained in:
Thomas Harte
2021-01-18 17:11:11 -05:00
parent ec0018df79
commit 9b92753e0a
2 changed files with 21 additions and 4 deletions

View File

@@ -105,6 +105,10 @@ template <
and doing any translation as is necessary. and doing any translation as is necessary.
*/ */
void set_program_counter(ProgramCounterType address) { void set_program_counter(ProgramCounterType address) {
// Set flag to terminate any inner loop currently running through
// previously-parsed content.
has_branched_ = true;
// Temporary implementation: just interpret. // Temporary implementation: just interpret.
program_.clear(); program_.clear();
static_cast<Executor *>(this)->parse(address, ProgramCounterType(max_address)); static_cast<Executor *>(this)->parse(address, ProgramCounterType(max_address));
@@ -118,6 +122,19 @@ template <
// } // }
} }
void perform_all() {
// TEMPORARY (?). Execute all current instructions, unless
// and until one branches.
has_branched_ = false;
for(auto index: program_) {
performers_[index]();
if(has_branched_) break;
}
}
private:
bool has_branched_ = false;
private: private:
std::vector<PerformerIndex> program_; std::vector<PerformerIndex> program_;

View File

@@ -27,9 +27,6 @@ Executor::Executor() {
performers_[c] = performer_lookup_.performer(instruction.operation, instruction.addressing_mode); performers_[c] = performer_lookup_.performer(instruction.operation, instruction.addressing_mode);
} }
} }
// TODO: read reset vector, etc. This is just the start of ROM.
set_program_counter(0x1400);
} }
void Executor::set_rom(const std::vector<uint8_t> &rom) { void Executor::set_rom(const std::vector<uint8_t> &rom) {
@@ -37,11 +34,14 @@ void Executor::set_rom(const std::vector<uint8_t> &rom) {
const auto length = std::min(size_t(0x1000), rom.size()); const auto length = std::min(size_t(0x1000), rom.size());
memcpy(&memory_[0x2000 - length], rom.data(), length); memcpy(&memory_[0x2000 - length], rom.data(), length);
reset(); reset();
// TEMPORARY: just to test initial wiring.
perform_all();
} }
void Executor::reset() { void Executor::reset() {
// Just jump to the reset vector. // Just jump to the reset vector.
set_program_counter(uint16_t(memory_[0x1ffe] | (memory_[0x1fff] << 8))); set_program_counter(uint16_t(memory_[0x1ffe] | (memory_[0x1fff] << 8)) & 0x1fff);
} }
template <Operation operation, AddressingMode addressing_mode> void Executor::perform() { template <Operation operation, AddressingMode addressing_mode> void Executor::perform() {