2020-09-28 02:20:58 +00:00
|
|
|
//
|
|
|
|
// 65816Implementation.hpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 27/09/2020.
|
|
|
|
// Copyright © 2020 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2020-10-15 22:42:38 +00:00
|
|
|
template <typename BusHandler, bool uses_ready_line> void Processor<BusHandler, uses_ready_line>::run_for(const Cycles cycles) {
|
2020-09-29 22:42:07 +00:00
|
|
|
|
2020-10-04 23:12:04 +00:00
|
|
|
#define perform_bus(address, value, operation) \
|
2022-06-29 19:09:52 +00:00
|
|
|
bus_address_ = (address) & 0xff'ffff; \
|
2020-10-15 22:42:38 +00:00
|
|
|
bus_value_ = value; \
|
|
|
|
bus_operation_ = operation
|
2020-10-04 23:12:04 +00:00
|
|
|
|
|
|
|
#define read(address, value) perform_bus(address, value, MOS6502Esque::Read)
|
|
|
|
#define write(address, value) perform_bus(address, value, MOS6502Esque::Write)
|
|
|
|
|
2020-10-15 22:42:38 +00:00
|
|
|
#define m_flag() registers_.mx_flags[0]
|
|
|
|
#define x_flag() registers_.mx_flags[1]
|
2020-10-06 20:25:30 +00:00
|
|
|
|
2020-10-15 22:42:38 +00:00
|
|
|
#define stack_address() ((registers_.s.full & registers_.e_masks[1]) | (0x0100 & registers_.e_masks[0]))
|
2020-10-05 02:06:25 +00:00
|
|
|
|
2020-09-29 22:42:07 +00:00
|
|
|
Cycles number_of_cycles = cycles + cycles_left_to_run_;
|
|
|
|
while(number_of_cycles > Cycles(0)) {
|
2020-10-16 00:46:18 +00:00
|
|
|
// Wait for ready to be inactive before proceeding.
|
|
|
|
while(uses_ready_line && ready_line_ && number_of_cycles > Cycles(0)) {
|
2020-10-18 19:08:21 +00:00
|
|
|
number_of_cycles -= bus_handler_.perform_bus_operation(BusOperation::Ready, static_cast<typename BusHandler::AddressType>(bus_address_), &bus_throwaway_);
|
2020-10-16 00:46:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Process for as much time is left and/or until ready is signalled.
|
|
|
|
while((!uses_ready_line || !ready_line_) && number_of_cycles > Cycles(0)) {
|
|
|
|
const MicroOp operation = *next_op_;
|
|
|
|
++next_op_;
|
2020-09-28 02:20:58 +00:00
|
|
|
|
2020-10-10 01:48:35 +00:00
|
|
|
#ifndef NDEBUG
|
2020-10-16 00:46:18 +00:00
|
|
|
// As a sanity check.
|
|
|
|
bus_value_ = nullptr;
|
2020-10-10 01:48:35 +00:00
|
|
|
#endif
|
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
switch(operation) {
|
|
|
|
//
|
|
|
|
// Scheduling.
|
|
|
|
//
|
|
|
|
|
|
|
|
case OperationMoveToNextProgram: {
|
|
|
|
// The exception program will determine the appropriate way to respond
|
|
|
|
// based on the pending exception if one exists; otherwise just do a
|
|
|
|
// standard fetch-decode-execute.
|
2020-12-08 23:46:30 +00:00
|
|
|
if(selected_exceptions_) {
|
|
|
|
exception_is_interrupt_ = true;
|
|
|
|
|
|
|
|
// Do enough quick early decoding to spot a reset.
|
|
|
|
if(selected_exceptions_ & (Reset | PowerOn)) {
|
|
|
|
active_instruction_ = &instructions[size_t(OperationSlot::Reset)];
|
|
|
|
} else {
|
|
|
|
active_instruction_ = &instructions[size_t(OperationSlot::Exception)];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
exception_is_interrupt_ = false;
|
|
|
|
active_instruction_ = &instructions[size_t(OperationSlot::FetchDecodeExecute)];
|
|
|
|
}
|
2020-10-18 18:43:47 +00:00
|
|
|
|
|
|
|
next_op_ = µ_ops_[active_instruction_->program_offsets[0]];
|
2020-10-16 00:46:18 +00:00
|
|
|
instruction_buffer_.clear();
|
|
|
|
data_buffer_.clear();
|
|
|
|
last_operation_pc_ = registers_.pc;
|
2021-02-20 01:06:12 +00:00
|
|
|
last_operation_program_bank_ = uint8_t(registers_.program_bank >> 16);
|
2020-10-17 01:05:42 +00:00
|
|
|
memory_lock_ = false;
|
2023-08-05 18:57:43 +00:00
|
|
|
|
|
|
|
// Reenforce the top byte of S if applicable.
|
2023-08-05 19:06:18 +00:00
|
|
|
registers_.s.full = stack_address();
|
2020-10-16 00:46:18 +00:00
|
|
|
} continue;
|
|
|
|
|
|
|
|
case OperationDecode: {
|
|
|
|
active_instruction_ = &instructions[instruction_buffer_.value];
|
|
|
|
|
|
|
|
const auto size_flag = registers_.mx_flags[active_instruction_->size_field];
|
|
|
|
next_op_ = µ_ops_[active_instruction_->program_offsets[size_flag]];
|
|
|
|
instruction_buffer_.clear();
|
|
|
|
} continue;
|
|
|
|
|
|
|
|
//
|
|
|
|
// PC fetches.
|
|
|
|
//
|
|
|
|
|
2020-10-17 01:56:20 +00:00
|
|
|
case CycleFetchOpcode:
|
|
|
|
perform_bus(registers_.pc | registers_.program_bank, instruction_buffer_.next_input(), MOS6502Esque::ReadOpcode);
|
2020-10-16 00:46:18 +00:00
|
|
|
++registers_.pc;
|
|
|
|
break;
|
|
|
|
|
2020-10-17 01:56:20 +00:00
|
|
|
case CycleFetchIncrementPC:
|
|
|
|
perform_bus(registers_.pc | registers_.program_bank, instruction_buffer_.next_input(), MOS6502Esque::ReadProgram);
|
2020-10-16 00:46:18 +00:00
|
|
|
++registers_.pc;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CycleFetchPC:
|
2020-10-17 01:56:20 +00:00
|
|
|
perform_bus(registers_.pc | registers_.program_bank, instruction_buffer_.next_input(), MOS6502Esque::ReadProgram);
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CycleFetchPCThrowaway:
|
2020-10-17 01:56:20 +00:00
|
|
|
perform_bus(registers_.pc | registers_.program_bank, &bus_throwaway_, MOS6502Esque::InternalOperationRead);
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
|
|
|
|
2022-06-21 15:41:05 +00:00
|
|
|
case CycleFetchPreviousPCThrowaway:
|
|
|
|
perform_bus(((registers_.pc - 1) & 0xffff) | registers_.program_bank, &bus_throwaway_, MOS6502Esque::InternalOperationRead);
|
|
|
|
break;
|
|
|
|
|
2022-06-24 18:00:03 +00:00
|
|
|
case CycleFetchPreviousThrowaway:
|
|
|
|
perform_bus(bus_address_, &bus_throwaway_, MOS6502Esque::InternalOperationRead);
|
|
|
|
break;
|
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
//
|
|
|
|
// Data fetches and stores.
|
|
|
|
//
|
2020-10-04 01:30:24 +00:00
|
|
|
|
2020-10-13 02:33:43 +00:00
|
|
|
#define increment_data_address() data_address_ = (data_address_ & ~data_address_increment_mask_) + ((data_address_ + 1) & data_address_increment_mask_)
|
|
|
|
#define decrement_data_address() data_address_ = (data_address_ & ~data_address_increment_mask_) + ((data_address_ - 1) & data_address_increment_mask_)
|
2020-10-04 22:52:46 +00:00
|
|
|
|
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case CycleFetchData:
|
|
|
|
read(data_address_, data_buffer_.next_input());
|
|
|
|
break;
|
2020-10-04 01:30:24 +00:00
|
|
|
|
2022-06-21 18:33:06 +00:00
|
|
|
case CycleStoreOrFetchDataThrowaway:
|
|
|
|
if(registers_.emulation_flag) {
|
|
|
|
perform_bus(data_address_, data_buffer_.preview_output(), MOS6502Esque::InternalOperationWrite);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
[[fallthrough]];
|
2020-10-16 00:46:18 +00:00
|
|
|
case CycleFetchDataThrowaway:
|
2020-10-17 01:56:20 +00:00
|
|
|
perform_bus(data_address_, &bus_throwaway_, MOS6502Esque::InternalOperationRead);
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
2020-10-12 22:36:09 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case CycleFetchIncorrectDataAddress:
|
2020-10-17 01:56:20 +00:00
|
|
|
perform_bus(incorrect_data_address_, &bus_throwaway_, MOS6502Esque::InternalOperationRead);
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
2020-10-04 23:02:47 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case CycleFetchIncrementData:
|
|
|
|
read(data_address_, data_buffer_.next_input());
|
|
|
|
increment_data_address();
|
|
|
|
break;
|
2020-10-04 01:30:24 +00:00
|
|
|
|
2020-10-17 01:56:20 +00:00
|
|
|
case CycleFetchVector:
|
|
|
|
perform_bus(data_address_, data_buffer_.next_input(), MOS6502Esque::ReadVector);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CycleFetchIncrementVector:
|
|
|
|
perform_bus(data_address_, data_buffer_.next_input(), MOS6502Esque::ReadVector);
|
|
|
|
increment_data_address();
|
|
|
|
break;
|
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case CycleStoreData:
|
|
|
|
write(data_address_, data_buffer_.next_output());
|
|
|
|
break;
|
2020-10-04 01:30:24 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case CycleStoreIncrementData:
|
|
|
|
write(data_address_, data_buffer_.next_output());
|
|
|
|
increment_data_address();
|
|
|
|
break;
|
2020-10-04 01:30:24 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case CycleStoreDecrementData:
|
|
|
|
write(data_address_, data_buffer_.next_output_descending());
|
|
|
|
decrement_data_address();
|
|
|
|
break;
|
2020-10-04 22:52:46 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case CycleFetchBlockX:
|
2020-11-05 01:35:41 +00:00
|
|
|
read(((instruction_buffer_.value & 0xff00) << 8) | registers_.x.full, data_buffer_.any_byte());
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
2020-10-04 23:21:04 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case CycleFetchBlockY:
|
2020-11-15 21:08:29 +00:00
|
|
|
perform_bus(((instruction_buffer_.value & 0x00ff) << 16) | registers_.y.full, &bus_throwaway_, MOS6502Esque::InternalOperationRead);
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
2020-10-04 23:21:04 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case CycleStoreBlockY:
|
2020-11-15 21:08:29 +00:00
|
|
|
write(((instruction_buffer_.value & 0x00ff) << 16) | registers_.y.full, data_buffer_.any_byte());
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
2020-10-04 23:21:04 +00:00
|
|
|
|
2020-10-04 22:52:46 +00:00
|
|
|
#undef increment_data_address
|
|
|
|
#undef decrement_data_address
|
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
//
|
|
|
|
// Stack accesses.
|
|
|
|
//
|
2020-10-04 22:52:46 +00:00
|
|
|
|
|
|
|
#define stack_access(value, operation) \
|
2020-10-16 00:51:23 +00:00
|
|
|
bus_address_ = stack_address(); \
|
|
|
|
bus_value_ = value; \
|
2020-10-15 22:42:38 +00:00
|
|
|
bus_operation_ = operation;
|
2020-10-04 22:52:46 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case CyclePush:
|
|
|
|
stack_access(data_buffer_.next_output_descending(), MOS6502Esque::Write);
|
|
|
|
--registers_.s.full;
|
|
|
|
break;
|
2020-10-04 22:52:46 +00:00
|
|
|
|
2023-07-30 20:25:51 +00:00
|
|
|
case CyclePushNotEmulation:
|
|
|
|
bus_address_ = registers_.s.full;
|
|
|
|
bus_value_ = data_buffer_.next_output_descending();
|
|
|
|
bus_operation_ = MOS6502Esque::Write;
|
|
|
|
--registers_.s.full;
|
|
|
|
break;
|
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case CyclePullIfNotEmulation:
|
|
|
|
if(registers_.emulation_flag) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
[[fallthrough]];
|
2020-10-11 19:25:13 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case CyclePull:
|
|
|
|
++registers_.s.full;
|
|
|
|
stack_access(data_buffer_.next_input(), MOS6502Esque::Read);
|
|
|
|
break;
|
2020-10-04 22:52:46 +00:00
|
|
|
|
2023-07-30 20:25:51 +00:00
|
|
|
case CyclePullNotEmulation:
|
|
|
|
++registers_.s.full;
|
|
|
|
bus_address_ = registers_.s.full;
|
|
|
|
bus_value_ = data_buffer_.next_input();
|
|
|
|
bus_operation_ = MOS6502Esque::Read;
|
|
|
|
break;
|
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case CycleAccessStack:
|
2020-10-17 01:56:20 +00:00
|
|
|
stack_access(&bus_throwaway_, MOS6502Esque::InternalOperationRead);
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
2020-10-04 01:30:24 +00:00
|
|
|
|
2020-10-04 22:52:46 +00:00
|
|
|
#undef stack_access
|
|
|
|
|
2020-10-17 01:05:42 +00:00
|
|
|
//
|
|
|
|
// Memory lock control.
|
|
|
|
//
|
|
|
|
|
|
|
|
case OperationSetMemoryLock:
|
|
|
|
memory_lock_ = true;
|
|
|
|
continue;
|
|
|
|
|
2020-10-12 01:10:44 +00:00
|
|
|
//
|
2020-10-16 00:46:18 +00:00
|
|
|
// STP and WAI.
|
|
|
|
//
|
|
|
|
|
|
|
|
case CycleRepeatingNone:
|
2020-12-08 23:46:30 +00:00
|
|
|
if(selected_exceptions_ & required_exceptions_) {
|
2020-10-16 00:46:18 +00:00
|
|
|
continue;
|
2020-10-08 21:52:13 +00:00
|
|
|
} else {
|
2020-10-16 00:46:18 +00:00
|
|
|
--next_op_;
|
2020-11-04 01:17:44 +00:00
|
|
|
perform_bus(0xffffff, &bus_throwaway_, (required_exceptions_ & IRQ) ? MOS6502Esque::Ready : MOS6502Esque::None);
|
2020-10-08 21:52:13 +00:00
|
|
|
}
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
2020-10-07 02:29:34 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
//
|
|
|
|
// Data movement.
|
|
|
|
//
|
2020-10-04 22:52:46 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case OperationCopyPCToData:
|
|
|
|
data_buffer_.size = 2;
|
|
|
|
data_buffer_.value = registers_.pc;
|
|
|
|
continue;
|
2020-10-06 23:12:19 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case OperationCopyInstructionToData:
|
|
|
|
data_buffer_ = instruction_buffer_;
|
|
|
|
continue;
|
2020-10-08 20:48:46 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case OperationCopyDataToInstruction:
|
|
|
|
instruction_buffer_ = data_buffer_;
|
|
|
|
data_buffer_.clear();
|
|
|
|
continue;
|
2020-10-04 22:52:46 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case OperationCopyAToData:
|
|
|
|
data_buffer_.value = registers_.a.full & registers_.m_masks[1];
|
|
|
|
data_buffer_.size = 2 - m_flag();
|
|
|
|
continue;
|
2020-10-08 20:55:45 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case OperationCopyDataToA:
|
|
|
|
registers_.a.full = (registers_.a.full & registers_.m_masks[0]) + (data_buffer_.value & registers_.m_masks[1]);
|
|
|
|
continue;
|
2020-10-04 22:52:46 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case OperationCopyPBRToData:
|
|
|
|
data_buffer_.size = 1;
|
|
|
|
data_buffer_.value = registers_.program_bank >> 16;
|
|
|
|
continue;
|
2020-10-08 20:48:46 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case OperationCopyDataToPC:
|
|
|
|
registers_.pc = uint16_t(data_buffer_.value);
|
|
|
|
continue;
|
2020-10-04 22:52:46 +00:00
|
|
|
|
2020-12-08 23:46:30 +00:00
|
|
|
case OperationClearDataBuffer:
|
|
|
|
data_buffer_.clear();
|
|
|
|
continue;
|
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
//
|
|
|
|
// Address construction.
|
|
|
|
//
|
2020-10-08 22:06:11 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case OperationConstructAbsolute:
|
|
|
|
data_address_ = instruction_buffer_.value + registers_.data_bank;
|
|
|
|
data_address_increment_mask_ = 0xff'ff'ff;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case OperationConstructAbsolute16:
|
|
|
|
data_address_ = instruction_buffer_.value;
|
|
|
|
data_address_increment_mask_ = 0x00'ff'ff;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case OperationConstructAbsoluteLong:
|
|
|
|
data_address_ = instruction_buffer_.value;
|
|
|
|
data_address_increment_mask_ = 0xff'ff'ff;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Used for JMP and JSR (absolute, x).
|
|
|
|
case OperationConstructAbsoluteIndexedIndirect:
|
2020-11-05 01:35:41 +00:00
|
|
|
data_address_ = registers_.program_bank + ((instruction_buffer_.value + registers_.x.full) & 0xffff);
|
2020-10-16 00:46:18 +00:00
|
|
|
data_address_increment_mask_ = 0x00'ff'ff;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case OperationConstructAbsoluteLongX:
|
2020-11-05 01:35:41 +00:00
|
|
|
data_address_ = instruction_buffer_.value + registers_.x.full;
|
2020-10-16 00:46:18 +00:00
|
|
|
data_address_increment_mask_ = 0xff'ff'ff;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case OperationConstructAbsoluteXRead:
|
|
|
|
case OperationConstructAbsoluteX:
|
2020-11-05 01:35:41 +00:00
|
|
|
data_address_ = instruction_buffer_.value + registers_.x.full + registers_.data_bank;
|
2020-11-23 02:43:56 +00:00
|
|
|
incorrect_data_address_ = ((data_address_ & 0x00ff) | (instruction_buffer_.value & 0xff00)) + registers_.data_bank;
|
2020-10-16 00:46:18 +00:00
|
|
|
|
2022-06-23 16:46:51 +00:00
|
|
|
// "Add 1 cycle for indexing across page boundaries, or write, or X=0"
|
|
|
|
// (i.e. don't add 1 cycle if x = 1 and this is a read, and a page boundary wasn't crossed)
|
|
|
|
if(
|
|
|
|
operation == OperationConstructAbsoluteXRead &&
|
|
|
|
data_address_ == incorrect_data_address_ &&
|
|
|
|
registers_.mx_flags[1]) {
|
2020-10-16 00:46:18 +00:00
|
|
|
++next_op_;
|
|
|
|
}
|
|
|
|
data_address_increment_mask_ = 0xff'ff'ff;
|
|
|
|
continue;
|
2020-10-08 22:06:11 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case OperationConstructAbsoluteYRead:
|
|
|
|
case OperationConstructAbsoluteY:
|
2020-11-05 01:35:41 +00:00
|
|
|
data_address_ = instruction_buffer_.value + registers_.y.full + registers_.data_bank;
|
2020-10-16 00:46:18 +00:00
|
|
|
incorrect_data_address_ = (data_address_ & 0xff) + (instruction_buffer_.value & 0xff00) + registers_.data_bank;
|
2020-10-04 22:52:46 +00:00
|
|
|
|
2022-06-23 16:46:51 +00:00
|
|
|
// "Add 1 cycle for indexing across page boundaries, or write, or X=0"
|
|
|
|
// (i.e. don't add 1 cycle if x = 1 and this is a read, and a page boundary wasn't crossed)
|
|
|
|
if(
|
|
|
|
operation == OperationConstructAbsoluteYRead &&
|
|
|
|
data_address_ == incorrect_data_address_ &&
|
|
|
|
registers_.mx_flags[1]) {
|
2020-10-16 00:46:18 +00:00
|
|
|
++next_op_;
|
|
|
|
}
|
|
|
|
data_address_increment_mask_ = 0xff'ff'ff;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case OperationConstructDirect:
|
|
|
|
data_address_ = (registers_.direct + instruction_buffer_.value) & 0xffff;
|
|
|
|
data_address_increment_mask_ = 0x00'ff'ff;
|
2022-09-09 20:02:35 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
if(!(registers_.direct&0xff)) {
|
|
|
|
// If the low byte is 0 and this is emulation mode, incrementing
|
|
|
|
// is restricted to the low byte.
|
|
|
|
data_address_increment_mask_ = registers_.e_masks[1];
|
|
|
|
++next_op_;
|
|
|
|
}
|
|
|
|
continue;
|
2020-10-04 22:52:46 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case OperationConstructDirectLong:
|
|
|
|
data_address_ = (registers_.direct + instruction_buffer_.value) & 0xffff;
|
|
|
|
data_address_increment_mask_ = 0x00'ff'ff;
|
2022-09-09 20:02:35 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
if(!(registers_.direct&0xff)) {
|
|
|
|
++next_op_;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case OperationConstructDirectIndirect:
|
|
|
|
data_address_ = registers_.data_bank + data_buffer_.value;
|
|
|
|
data_address_increment_mask_ = 0xff'ff'ff;
|
|
|
|
data_buffer_.clear();
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case OperationConstructDirectIndexedIndirect:
|
2023-07-28 17:39:21 +00:00
|
|
|
// Emulation mode plus DL = 0 is required for 6502-style functionality where
|
|
|
|
// only the low byte is the result of the indirect calculation.
|
2020-10-16 00:46:18 +00:00
|
|
|
if(!(registers_.direct&0xff)) {
|
2023-07-28 17:39:21 +00:00
|
|
|
data_address_ = (
|
|
|
|
((registers_.direct + registers_.x.full + instruction_buffer_.value) & registers_.e_masks[1]) +
|
|
|
|
(registers_.direct & registers_.e_masks[0])
|
|
|
|
) & 0xffff;
|
2020-10-16 00:46:18 +00:00
|
|
|
++next_op_;
|
2023-07-28 17:39:21 +00:00
|
|
|
} else {
|
|
|
|
data_address_ = (
|
|
|
|
registers_.direct + registers_.x.full + instruction_buffer_.value
|
|
|
|
) & 0xffff;
|
2020-10-16 00:46:18 +00:00
|
|
|
}
|
2023-07-28 17:39:21 +00:00
|
|
|
data_address_increment_mask_ = 0x00'ff'ff;
|
2020-10-16 00:46:18 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
case OperationConstructDirectIndirectIndexedLong:
|
2020-11-05 01:35:41 +00:00
|
|
|
data_address_ = registers_.y.full + data_buffer_.value;
|
2020-10-16 00:46:18 +00:00
|
|
|
data_address_increment_mask_ = 0xff'ff'ff;
|
|
|
|
data_buffer_.clear();
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case OperationConstructDirectIndirectLong:
|
|
|
|
data_address_ = data_buffer_.value;
|
|
|
|
data_address_increment_mask_ = 0xff'ff'ff;
|
|
|
|
data_buffer_.clear();
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case OperationConstructDirectX:
|
2022-09-09 20:02:35 +00:00
|
|
|
// There are no direct, x instructions that access a two-byte value when
|
|
|
|
// in emulation mode, so this can assume native mode.
|
2020-10-16 00:46:18 +00:00
|
|
|
data_address_increment_mask_ = 0x00'ff'ff;
|
|
|
|
|
2022-09-09 20:02:35 +00:00
|
|
|
// If the low byte of the direct register is 0, use the current e mask
|
|
|
|
// potentially to keep the high byte of the direct register unmodified.
|
|
|
|
//
|
|
|
|
// Also skip the next program step, which would be a redundant fetch
|
|
|
|
// from the program counter.
|
|
|
|
//
|
|
|
|
// Otherwise: retain a 16-bit address.
|
|
|
|
|
|
|
|
data_address_ = instruction_buffer_.value + registers_.direct + registers_.x.full;
|
2020-10-16 00:46:18 +00:00
|
|
|
if(!(registers_.direct&0xff)) {
|
2022-09-09 20:02:35 +00:00
|
|
|
data_address_ =
|
|
|
|
(registers_.direct & registers_.e_masks[0]) |
|
|
|
|
(data_address_ & registers_.e_masks[1]);
|
2020-10-16 00:46:18 +00:00
|
|
|
++next_op_;
|
2022-09-09 20:02:35 +00:00
|
|
|
} else {
|
|
|
|
data_address_ &= 0xffff;
|
2020-10-16 00:46:18 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case OperationConstructDirectY:
|
2022-09-09 20:02:35 +00:00
|
|
|
// Cf. comments above in DirectX.
|
2020-10-16 00:46:18 +00:00
|
|
|
data_address_increment_mask_ = 0x00'ff'ff;
|
2022-09-09 20:02:35 +00:00
|
|
|
data_address_ = instruction_buffer_.value + registers_.direct + registers_.y.full;
|
2020-10-16 00:46:18 +00:00
|
|
|
if(!(registers_.direct&0xff)) {
|
2022-09-09 20:02:35 +00:00
|
|
|
data_address_ =
|
|
|
|
(registers_.direct & registers_.e_masks[0]) |
|
|
|
|
(data_address_ & registers_.e_masks[1]);
|
2020-10-16 00:46:18 +00:00
|
|
|
++next_op_;
|
2022-09-09 20:02:35 +00:00
|
|
|
} else {
|
|
|
|
data_address_ &= 0xffff;
|
2020-10-16 00:46:18 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case OperationConstructStackRelative:
|
2023-04-14 04:04:44 +00:00
|
|
|
data_address_ = (stack_address() + instruction_buffer_.value) & 0xffff;
|
2020-10-16 00:46:18 +00:00
|
|
|
data_address_increment_mask_ = 0x00'ff'ff;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case OperationConstructStackRelativeIndexedIndirect:
|
2020-11-05 01:35:41 +00:00
|
|
|
data_address_ = registers_.data_bank + data_buffer_.value + registers_.y.full;
|
2020-10-16 00:46:18 +00:00
|
|
|
data_address_increment_mask_ = 0xff'ff'ff;
|
|
|
|
data_buffer_.clear();
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case OperationConstructPER:
|
|
|
|
data_buffer_.value = instruction_buffer_.value + registers_.pc;
|
|
|
|
data_buffer_.size = 2;
|
|
|
|
continue;
|
|
|
|
|
2020-12-08 23:46:30 +00:00
|
|
|
case OperationPrepareException:
|
|
|
|
data_buffer_.value = uint32_t((registers_.pc << 8) | get_flags());
|
|
|
|
if(registers_.emulation_flag) {
|
2022-06-23 17:03:26 +00:00
|
|
|
if(exception_is_interrupt_) data_buffer_.value &= ~uint32_t(Flag::Break);
|
2020-12-08 23:46:30 +00:00
|
|
|
data_buffer_.size = 3;
|
2023-07-28 14:53:02 +00:00
|
|
|
if(pending_exceptions_ & (Reset | PowerOn)) {
|
|
|
|
registers_.data_bank = 0;
|
|
|
|
}
|
2020-12-08 23:46:30 +00:00
|
|
|
++next_op_;
|
|
|
|
} else {
|
2020-12-29 20:27:49 +00:00
|
|
|
data_buffer_.value |= registers_.program_bank << 8; // The PBR is always held such that
|
|
|
|
// PBR+PC produces a 24-bit address;
|
|
|
|
// therefore a shift by 8 is correct
|
|
|
|
// here — it matches the shift applied
|
|
|
|
// to .pc above.
|
2020-12-08 23:46:30 +00:00
|
|
|
data_buffer_.size = 4;
|
|
|
|
}
|
|
|
|
|
2021-02-18 03:08:08 +00:00
|
|
|
registers_.program_bank = 0;
|
2020-12-08 23:46:30 +00:00
|
|
|
registers_.flags.inverse_interrupt = 0;
|
|
|
|
registers_.flags.decimal = 0;
|
|
|
|
continue;
|
2020-10-16 00:46:18 +00:00
|
|
|
|
2020-12-08 23:46:30 +00:00
|
|
|
case OperationPickExceptionVector:
|
|
|
|
// Priority for abort and reset here is a guess.
|
2020-10-16 00:46:18 +00:00
|
|
|
|
|
|
|
if(pending_exceptions_ & (Reset | PowerOn)) {
|
|
|
|
pending_exceptions_ &= ~(Reset | PowerOn);
|
|
|
|
data_address_ = 0xfffc;
|
|
|
|
set_reset_state();
|
2020-10-29 01:23:35 +00:00
|
|
|
continue;
|
2020-12-08 23:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(pending_exceptions_ & Abort) {
|
2020-10-16 00:46:18 +00:00
|
|
|
// Special case: restore registers from start of instruction.
|
|
|
|
registers_ = abort_registers_copy_;
|
|
|
|
|
|
|
|
pending_exceptions_ &= ~Abort;
|
2020-12-08 23:46:30 +00:00
|
|
|
data_address_ = registers_.emulation_flag ? 0xfff8 : 0xffe8;
|
|
|
|
continue;
|
|
|
|
}
|
2020-12-08 03:43:24 +00:00
|
|
|
|
2020-12-08 23:46:30 +00:00
|
|
|
if(pending_exceptions_ & NMI) {
|
|
|
|
pending_exceptions_ &= ~NMI;
|
|
|
|
data_address_ = registers_.emulation_flag ? 0xfffa : 0xffea;
|
|
|
|
continue;
|
2020-10-16 00:46:18 +00:00
|
|
|
}
|
2020-10-06 20:25:30 +00:00
|
|
|
|
2020-12-08 23:46:30 +00:00
|
|
|
// Last chance saloon for the interrupt process.
|
|
|
|
if(exception_is_interrupt_) {
|
|
|
|
data_address_ = registers_.emulation_flag ? 0xfffe : 0xffee;
|
|
|
|
continue;
|
2020-10-16 00:46:18 +00:00
|
|
|
}
|
2020-10-06 20:25:30 +00:00
|
|
|
|
2020-12-08 23:46:30 +00:00
|
|
|
// ... then this must be a BRK or COP that is being treated as such.
|
|
|
|
assert((active_instruction_ == instructions) || (active_instruction_ == &instructions[0x02]));
|
|
|
|
|
|
|
|
// Test for BRK, given that it has opcode 00.
|
|
|
|
if(active_instruction_ == instructions) {
|
|
|
|
data_address_ = registers_.emulation_flag ? 0xfffe : 0xffe6;
|
|
|
|
} else {
|
|
|
|
// Implicitly: COP.
|
|
|
|
data_address_ = registers_.emulation_flag ? 0xfff4 : 0xffe4;
|
|
|
|
}
|
|
|
|
continue;
|
2020-10-06 20:25:30 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
//
|
|
|
|
// Performance.
|
|
|
|
//
|
2020-10-07 00:17:03 +00:00
|
|
|
|
2023-05-12 18:14:45 +00:00
|
|
|
#define LDA(src) registers_.a.full = (registers_.a.full & registers_.m_masks[0]) | (src & registers_.m_masks[1])
|
2020-11-05 01:35:41 +00:00
|
|
|
#define LDXY(dest, src) dest = (src) & registers_.x_mask
|
2020-10-11 02:00:17 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case OperationPerform:
|
|
|
|
switch(active_instruction_->operation) {
|
|
|
|
|
|
|
|
//
|
|
|
|
// Loads, stores and transfers (and NOP, and XBA).
|
|
|
|
//
|
|
|
|
|
|
|
|
case LDA:
|
2021-03-04 01:47:45 +00:00
|
|
|
assert(data_buffer_.size == 2 - m_flag());
|
2020-11-05 01:35:41 +00:00
|
|
|
LDA(data_buffer_.value);
|
2020-10-16 00:46:18 +00:00
|
|
|
registers_.flags.set_nz(registers_.a.full, registers_.m_shift);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDX:
|
2021-03-04 01:47:45 +00:00
|
|
|
assert(data_buffer_.size == 2 - x_flag());
|
2020-11-05 01:35:41 +00:00
|
|
|
LDXY(registers_.x, data_buffer_.value);
|
2020-10-16 00:46:18 +00:00
|
|
|
registers_.flags.set_nz(registers_.x.full, registers_.x_shift);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDY:
|
2021-03-04 01:47:45 +00:00
|
|
|
assert(data_buffer_.size == 2 - x_flag());
|
2020-11-05 01:35:41 +00:00
|
|
|
LDXY(registers_.y, data_buffer_.value);
|
2020-10-16 00:46:18 +00:00
|
|
|
registers_.flags.set_nz(registers_.y.full, registers_.x_shift);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLB:
|
2021-03-04 01:47:45 +00:00
|
|
|
assert(data_buffer_.size == 1);
|
2020-10-16 00:46:18 +00:00
|
|
|
registers_.data_bank = (data_buffer_.value & 0xff) << 16;
|
2020-10-18 18:55:17 +00:00
|
|
|
registers_.flags.set_nz(uint8_t(data_buffer_.value));
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PLD:
|
2021-03-04 01:47:45 +00:00
|
|
|
assert(data_buffer_.size == 2);
|
2020-10-18 18:55:17 +00:00
|
|
|
registers_.direct = uint16_t(data_buffer_.value);
|
|
|
|
registers_.flags.set_nz(uint16_t(data_buffer_.value), 8);
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PLP:
|
2021-03-04 01:47:45 +00:00
|
|
|
assert(data_buffer_.size == 1);
|
2020-10-18 18:55:17 +00:00
|
|
|
set_flags(uint8_t(data_buffer_.value));
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STA:
|
|
|
|
data_buffer_.value = registers_.a.full & registers_.m_masks[1];
|
|
|
|
data_buffer_.size = 2 - m_flag();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STZ:
|
|
|
|
data_buffer_.value = 0;
|
|
|
|
data_buffer_.size = 2 - m_flag();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STX:
|
2020-11-05 01:35:41 +00:00
|
|
|
data_buffer_.value = registers_.x.full;
|
2020-10-16 00:46:18 +00:00
|
|
|
data_buffer_.size = 2 - x_flag();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STY:
|
2020-11-05 01:35:41 +00:00
|
|
|
data_buffer_.value = registers_.y.full;
|
2020-11-04 01:17:44 +00:00
|
|
|
data_buffer_.size = 2 - x_flag();
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PHB:
|
|
|
|
data_buffer_.value = registers_.data_bank >> 16;
|
|
|
|
data_buffer_.size = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PHK:
|
|
|
|
data_buffer_.value = registers_.program_bank >> 16;
|
|
|
|
data_buffer_.size = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PHD:
|
|
|
|
data_buffer_.value = registers_.direct;
|
|
|
|
data_buffer_.size = 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PHP:
|
|
|
|
data_buffer_.value = get_flags();
|
|
|
|
data_buffer_.size = 1;
|
|
|
|
break;
|
|
|
|
|
2020-11-04 01:01:02 +00:00
|
|
|
case NOP: break;
|
|
|
|
case WDM: ++registers_.pc; break;
|
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
|
|
|
|
// The below attempt to obey the 8/16-bit mixed transfer rules
|
|
|
|
// as documented in https://softpixel.com/~cwright/sianse/docs/65816NFO.HTM
|
|
|
|
// (and make reasonable guesses as to the N flag).
|
|
|
|
|
|
|
|
case TXS:
|
2023-08-05 19:06:18 +00:00
|
|
|
registers_.s = registers_.x;
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TSX:
|
2020-11-05 01:35:41 +00:00
|
|
|
LDXY(registers_.x, registers_.s.full);
|
2020-10-16 00:46:18 +00:00
|
|
|
registers_.flags.set_nz(registers_.x.full, registers_.x_shift);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TXY:
|
2020-11-05 01:35:41 +00:00
|
|
|
LDXY(registers_.y, registers_.x.full);
|
2020-10-16 00:46:18 +00:00
|
|
|
registers_.flags.set_nz(registers_.y.full, registers_.x_shift);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TYX:
|
2020-11-05 01:35:41 +00:00
|
|
|
LDXY(registers_.x, registers_.y.full);
|
2020-10-16 00:46:18 +00:00
|
|
|
registers_.flags.set_nz(registers_.x.full, registers_.x_shift);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TAX:
|
2020-11-05 01:35:41 +00:00
|
|
|
LDXY(registers_.x, registers_.a.full);
|
2020-10-16 00:46:18 +00:00
|
|
|
registers_.flags.set_nz(registers_.x.full, registers_.x_shift);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TAY:
|
2020-11-05 01:35:41 +00:00
|
|
|
LDXY(registers_.y, registers_.a.full);
|
2020-10-16 00:46:18 +00:00
|
|
|
registers_.flags.set_nz(registers_.y.full, registers_.x_shift);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TXA:
|
2020-11-05 01:35:41 +00:00
|
|
|
LDA(registers_.x.full);
|
2020-10-16 00:46:18 +00:00
|
|
|
registers_.flags.set_nz(registers_.a.full, registers_.m_shift);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TYA:
|
2020-11-05 01:35:41 +00:00
|
|
|
LDA(registers_.y.full);
|
2020-10-16 00:46:18 +00:00
|
|
|
registers_.flags.set_nz(registers_.a.full, registers_.m_shift);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TCD:
|
|
|
|
registers_.direct = registers_.a.full;
|
|
|
|
registers_.flags.set_nz(registers_.a.full, 8);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TDC:
|
|
|
|
registers_.a.full = registers_.direct;
|
|
|
|
registers_.flags.set_nz(registers_.a.full, 8);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TCS:
|
2023-08-05 19:06:18 +00:00
|
|
|
registers_.s = registers_.a;
|
|
|
|
registers_.s.full = stack_address();
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TSC:
|
|
|
|
registers_.a.full = stack_address();
|
|
|
|
registers_.flags.set_nz(registers_.a.full, 8);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XBA: {
|
|
|
|
const uint8_t a_low = registers_.a.halves.low;
|
|
|
|
registers_.a.halves.low = registers_.a.halves.high;
|
|
|
|
registers_.a.halves.high = a_low;
|
|
|
|
registers_.flags.set_nz(registers_.a.halves.low);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Jumps and returns.
|
|
|
|
//
|
|
|
|
|
|
|
|
case JML:
|
2020-11-03 23:12:10 +00:00
|
|
|
registers_.program_bank = data_buffer_.value & 0xff0000;
|
|
|
|
registers_.pc = uint16_t(data_buffer_.value);
|
|
|
|
break;
|
2020-10-16 00:46:18 +00:00
|
|
|
|
|
|
|
case JMP:
|
|
|
|
registers_.pc = uint16_t(instruction_buffer_.value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JMPind:
|
2021-03-04 01:47:45 +00:00
|
|
|
assert(data_buffer_.size == 2);
|
2020-10-18 18:55:17 +00:00
|
|
|
registers_.pc = uint16_t(data_buffer_.value);
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
|
|
|
|
2020-10-28 21:25:40 +00:00
|
|
|
case RTL:
|
|
|
|
registers_.program_bank = data_buffer_.value & 0xff0000;
|
|
|
|
[[fallthrough]];
|
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case RTS:
|
2021-03-04 01:47:45 +00:00
|
|
|
assert(data_buffer_.size == 2 + (active_instruction_->operation == RTL));
|
2020-10-18 18:55:17 +00:00
|
|
|
registers_.pc = uint16_t(data_buffer_.value + 1);
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case JSL:
|
|
|
|
registers_.program_bank = instruction_buffer_.value & 0xff0000;
|
|
|
|
[[fallthrough]];
|
|
|
|
|
|
|
|
case JSR:
|
2021-03-04 01:47:45 +00:00
|
|
|
assert(instruction_buffer_.size == 2 + (active_instruction_->operation == JSL));
|
2020-10-16 00:46:18 +00:00
|
|
|
data_buffer_.value = registers_.pc;
|
|
|
|
data_buffer_.size = 2;
|
2021-03-04 01:47:45 +00:00
|
|
|
// The per-cycle scheduling for JSL means that the program
|
|
|
|
// bank register has already been pushed to the stack by now.
|
2020-10-16 00:46:18 +00:00
|
|
|
|
2020-10-18 18:55:17 +00:00
|
|
|
registers_.pc = uint16_t(instruction_buffer_.value);
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RTI:
|
|
|
|
registers_.pc = uint16_t(data_buffer_.value >> 8);
|
|
|
|
set_flags(uint8_t(data_buffer_.value));
|
|
|
|
|
2021-03-04 01:47:45 +00:00
|
|
|
assert(data_buffer_.size == 4 - registers_.emulation_flag);
|
2020-10-16 00:46:18 +00:00
|
|
|
if(!registers_.emulation_flag) {
|
|
|
|
registers_.program_bank = (data_buffer_.value & 0xff000000) >> 8;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Block moves.
|
|
|
|
//
|
|
|
|
|
|
|
|
case MVP:
|
|
|
|
registers_.data_bank = (instruction_buffer_.value & 0xff) << 16;
|
2020-11-05 01:35:41 +00:00
|
|
|
LDXY(registers_.x.full, registers_.x.full - 1);
|
|
|
|
LDXY(registers_.y.full, registers_.y.full - 1);
|
2020-10-16 00:46:18 +00:00
|
|
|
if(registers_.a.full) registers_.pc -= 3;
|
2020-11-03 23:29:35 +00:00
|
|
|
--registers_.a.full;
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MVN:
|
|
|
|
registers_.data_bank = (instruction_buffer_.value & 0xff) << 16;
|
2020-11-05 01:35:41 +00:00
|
|
|
LDXY(registers_.x.full, registers_.x.full + 1);
|
|
|
|
LDXY(registers_.y.full, registers_.y.full + 1);
|
2020-10-16 00:46:18 +00:00
|
|
|
if(registers_.a.full) registers_.pc -= 3;
|
2020-11-03 23:29:35 +00:00
|
|
|
--registers_.a.full;
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Flag manipulation.
|
|
|
|
//
|
|
|
|
|
|
|
|
case CLC: registers_.flags.carry = 0; break;
|
|
|
|
case CLI: registers_.flags.inverse_interrupt = Flag::Interrupt; break;
|
|
|
|
case CLV: registers_.flags.overflow = 0; break;
|
|
|
|
case CLD: registers_.flags.decimal = 0; break;
|
|
|
|
|
|
|
|
case SEC: registers_.flags.carry = Flag::Carry; break;
|
|
|
|
case SEI: registers_.flags.inverse_interrupt = 0; break;
|
|
|
|
case SED: registers_.flags.decimal = Flag::Decimal; break;
|
|
|
|
|
|
|
|
case REP:
|
2020-10-18 18:55:17 +00:00
|
|
|
set_flags(uint8_t(get_flags() &~ instruction_buffer_.value));
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SEP:
|
2020-10-18 18:55:17 +00:00
|
|
|
set_flags(uint8_t(get_flags() | instruction_buffer_.value));
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case XCE: {
|
|
|
|
const bool old_emulation_flag = registers_.emulation_flag;
|
|
|
|
set_emulation_mode(registers_.flags.carry);
|
|
|
|
registers_.flags.carry = old_emulation_flag;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Increments and decrements.
|
|
|
|
//
|
|
|
|
|
|
|
|
case INC:
|
2021-03-04 01:47:45 +00:00
|
|
|
assert(data_buffer_.size == 2 - m_flag());
|
2020-10-16 00:46:18 +00:00
|
|
|
++data_buffer_.value;
|
2020-10-18 18:55:17 +00:00
|
|
|
registers_.flags.set_nz(uint16_t(data_buffer_.value), registers_.m_shift);
|
2024-02-12 19:23:54 +00:00
|
|
|
break;
|
2020-10-16 00:46:18 +00:00
|
|
|
|
|
|
|
case DEC:
|
2021-03-04 01:47:45 +00:00
|
|
|
assert(data_buffer_.size == 2 - m_flag());
|
2020-10-16 00:46:18 +00:00
|
|
|
--data_buffer_.value;
|
2020-10-18 18:55:17 +00:00
|
|
|
registers_.flags.set_nz(uint16_t(data_buffer_.value), registers_.m_shift);
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
|
|
|
|
2020-11-05 01:35:41 +00:00
|
|
|
case INX:
|
|
|
|
LDXY(registers_.x.full, registers_.x.full + 1);
|
2020-10-16 00:46:18 +00:00
|
|
|
registers_.flags.set_nz(registers_.x.full, registers_.x_shift);
|
2020-11-05 01:35:41 +00:00
|
|
|
break;
|
2020-10-16 00:46:18 +00:00
|
|
|
|
2020-11-05 01:35:41 +00:00
|
|
|
case DEX:
|
|
|
|
LDXY(registers_.x.full, registers_.x.full - 1);
|
2020-10-16 00:46:18 +00:00
|
|
|
registers_.flags.set_nz(registers_.x.full, registers_.x_shift);
|
2020-11-05 01:35:41 +00:00
|
|
|
break;
|
2020-10-16 00:46:18 +00:00
|
|
|
|
2020-11-05 01:35:41 +00:00
|
|
|
case INY:
|
|
|
|
LDXY(registers_.y.full, registers_.y.full + 1);
|
2020-10-16 00:46:18 +00:00
|
|
|
registers_.flags.set_nz(registers_.y.full, registers_.x_shift);
|
2020-11-05 01:35:41 +00:00
|
|
|
break;
|
2020-10-16 00:46:18 +00:00
|
|
|
|
2020-11-05 01:35:41 +00:00
|
|
|
case DEY:
|
|
|
|
LDXY(registers_.y.full, registers_.y.full - 1);
|
2020-10-16 00:46:18 +00:00
|
|
|
registers_.flags.set_nz(registers_.y.full, registers_.x_shift);
|
2020-11-05 01:35:41 +00:00
|
|
|
break;
|
2020-10-16 00:46:18 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Bitwise operations.
|
|
|
|
//
|
|
|
|
|
|
|
|
case AND:
|
|
|
|
registers_.a.full &= data_buffer_.value | registers_.m_masks[0];
|
|
|
|
registers_.flags.set_nz(registers_.a.full, registers_.m_shift);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EOR:
|
|
|
|
registers_.a.full ^= data_buffer_.value;
|
|
|
|
registers_.flags.set_nz(registers_.a.full, registers_.m_shift);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ORA:
|
|
|
|
registers_.a.full |= data_buffer_.value;
|
|
|
|
registers_.flags.set_nz(registers_.a.full, registers_.m_shift);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BIT:
|
2021-03-04 01:47:45 +00:00
|
|
|
assert(data_buffer_.size == 2 - m_flag());
|
2020-10-18 18:55:17 +00:00
|
|
|
registers_.flags.set_n(uint16_t(data_buffer_.value), registers_.m_shift);
|
|
|
|
registers_.flags.set_z(uint16_t(data_buffer_.value & registers_.a.full), registers_.m_shift);
|
2022-06-23 19:24:51 +00:00
|
|
|
registers_.flags.overflow = (data_buffer_.value >> registers_.m_shift) & Flag::Overflow;
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BITimm:
|
2021-03-04 01:47:45 +00:00
|
|
|
assert(data_buffer_.size == 2 - m_flag());
|
2020-10-16 00:46:18 +00:00
|
|
|
registers_.flags.set_z(data_buffer_.value & registers_.a.full, registers_.m_shift);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TRB:
|
2021-03-04 01:47:45 +00:00
|
|
|
assert(data_buffer_.size == 2 - m_flag());
|
2020-10-16 00:46:18 +00:00
|
|
|
registers_.flags.set_z(data_buffer_.value & registers_.a.full, registers_.m_shift);
|
|
|
|
data_buffer_.value &= ~registers_.a.full;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TSB:
|
2021-03-04 01:47:45 +00:00
|
|
|
assert(data_buffer_.size == 2 - m_flag());
|
2020-10-16 00:46:18 +00:00
|
|
|
registers_.flags.set_z(data_buffer_.value & registers_.a.full, registers_.m_shift);
|
|
|
|
data_buffer_.value |= registers_.a.full;
|
|
|
|
break;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Branches.
|
|
|
|
//
|
2020-10-07 01:24:43 +00:00
|
|
|
|
2021-03-04 01:47:45 +00:00
|
|
|
#define BRA(condition) \
|
|
|
|
assert(instruction_buffer_.size == 1); \
|
|
|
|
if(!(condition)) { \
|
|
|
|
next_op_ += 3; \
|
|
|
|
} else { \
|
2020-10-18 18:55:17 +00:00
|
|
|
data_buffer_.value = uint32_t(registers_.pc + int8_t(instruction_buffer_.value)); \
|
2021-03-04 01:47:45 +00:00
|
|
|
data_buffer_.size = 2; \
|
2020-10-18 18:55:17 +00:00
|
|
|
\
|
2022-06-22 19:31:30 +00:00
|
|
|
if( \
|
|
|
|
!registers_.emulation_flag || \
|
2023-04-16 03:30:30 +00:00
|
|
|
(registers_.pc & 0xff00) == (data_buffer_.value & 0xff00) \
|
2022-06-22 19:31:30 +00:00
|
|
|
) { \
|
2020-10-18 18:55:17 +00:00
|
|
|
++next_op_; \
|
|
|
|
} \
|
2020-10-07 01:24:43 +00:00
|
|
|
}
|
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case BPL: BRA(!(registers_.flags.negative_result&0x80)); break;
|
|
|
|
case BMI: BRA(registers_.flags.negative_result&0x80); break;
|
2020-10-16 00:51:23 +00:00
|
|
|
case BVC: BRA(!registers_.flags.overflow); break;
|
2020-10-16 00:46:18 +00:00
|
|
|
case BVS: BRA(registers_.flags.overflow); break;
|
2020-10-16 00:51:23 +00:00
|
|
|
case BCC: BRA(!registers_.flags.carry); break;
|
|
|
|
case BCS: BRA(registers_.flags.carry); break;
|
2020-10-16 00:46:18 +00:00
|
|
|
case BNE: BRA(registers_.flags.zero_result); break;
|
|
|
|
case BEQ: BRA(!registers_.flags.zero_result); break;
|
2020-10-16 00:51:23 +00:00
|
|
|
case BRA: BRA(true); break;
|
2020-10-07 01:24:43 +00:00
|
|
|
|
|
|
|
#undef BRA
|
2020-10-06 23:12:19 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case BRL:
|
2021-03-04 01:47:45 +00:00
|
|
|
assert(instruction_buffer_.size == 2);
|
2020-10-16 00:46:18 +00:00
|
|
|
registers_.pc += int16_t(instruction_buffer_.value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Shifts and rolls.
|
|
|
|
//
|
|
|
|
|
|
|
|
case ASL:
|
2020-10-18 18:55:17 +00:00
|
|
|
registers_.flags.carry = uint8_t(data_buffer_.value >> (7 + registers_.m_shift));
|
2020-10-16 00:46:18 +00:00
|
|
|
data_buffer_.value <<= 1;
|
2020-10-18 18:55:17 +00:00
|
|
|
registers_.flags.set_nz(uint16_t(data_buffer_.value), registers_.m_shift);
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LSR:
|
2020-10-18 18:55:17 +00:00
|
|
|
registers_.flags.carry = uint8_t(data_buffer_.value & 1);
|
2020-10-16 00:46:18 +00:00
|
|
|
data_buffer_.value >>= 1;
|
2020-10-18 18:55:17 +00:00
|
|
|
registers_.flags.set_nz(uint16_t(data_buffer_.value), registers_.m_shift);
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ROL:
|
|
|
|
data_buffer_.value = (data_buffer_.value << 1) | registers_.flags.carry;
|
2020-10-18 18:55:17 +00:00
|
|
|
registers_.flags.carry = uint8_t(data_buffer_.value >> (8 + registers_.m_shift));
|
|
|
|
registers_.flags.set_nz(uint16_t(data_buffer_.value), registers_.m_shift);
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ROR: {
|
|
|
|
const uint8_t next_carry = data_buffer_.value & 1;
|
2020-10-18 18:55:17 +00:00
|
|
|
data_buffer_.value = (data_buffer_.value >> 1) | (uint32_t(registers_.flags.carry) << (7 + registers_.m_shift));
|
2020-10-16 00:46:18 +00:00
|
|
|
registers_.flags.carry = next_carry;
|
2020-10-18 18:55:17 +00:00
|
|
|
registers_.flags.set_nz(uint16_t(data_buffer_.value), registers_.m_shift);
|
2020-10-16 00:46:18 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Arithmetic.
|
|
|
|
//
|
2020-10-07 01:47:26 +00:00
|
|
|
|
2020-11-05 01:35:41 +00:00
|
|
|
#define cp(v, shift, mask) {\
|
|
|
|
const uint32_t temp32 = (v.full & mask) - (data_buffer_.value & mask); \
|
2020-10-15 22:42:38 +00:00
|
|
|
registers_.flags.set_nz(uint16_t(temp32), shift); \
|
|
|
|
registers_.flags.carry = ((~temp32) >> (8 + shift))&1; \
|
2020-10-07 22:09:56 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 01:35:41 +00:00
|
|
|
case CMP: cp(registers_.a, registers_.m_shift, registers_.m_masks[1]); break;
|
|
|
|
case CPX: cp(registers_.x, registers_.x_shift, registers_.x_mask); break;
|
|
|
|
case CPY: cp(registers_.y, registers_.x_shift, registers_.x_mask); break;
|
2020-10-07 22:09:56 +00:00
|
|
|
|
|
|
|
#undef cp
|
2020-10-07 01:34:39 +00:00
|
|
|
|
2020-11-04 01:37:30 +00:00
|
|
|
// As implemented below, both ADC and SBC apply the 6502 test for overflow (i.e. based
|
|
|
|
// on intermediate results) rather than the 65C02 (i.e. based on the final result).
|
|
|
|
// This tracks the online tests I found, which hail from Nintendo world. So I'm currently
|
|
|
|
// unclear whether this is correct or merely a figment of Nintendo's custom chip.
|
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case SBC:
|
|
|
|
if(registers_.flags.decimal) {
|
|
|
|
const uint16_t a = registers_.a.full & registers_.m_masks[1];
|
2022-06-21 18:33:06 +00:00
|
|
|
data_buffer_.value = ~data_buffer_.value & registers_.m_masks[1];
|
|
|
|
|
2022-06-24 01:58:09 +00:00
|
|
|
int result = registers_.flags.carry;
|
2022-06-22 19:12:08 +00:00
|
|
|
uint16_t partials = 0;
|
2022-06-21 18:33:06 +00:00
|
|
|
|
2022-06-22 19:12:08 +00:00
|
|
|
#define nibble(mask, adjustment, carry) \
|
|
|
|
result += (a & mask) + (data_buffer_.value & mask); \
|
|
|
|
partials += result & mask; \
|
2022-06-24 01:58:09 +00:00
|
|
|
result -= ((result - carry) >> 16) & adjustment; \
|
2022-06-24 11:26:07 +00:00
|
|
|
result &= (carry & ~(result >> 1)) | (carry - 1);
|
2022-06-24 01:58:09 +00:00
|
|
|
|
|
|
|
// i.e. add the next nibble to that in the accumulator, with carry, and
|
|
|
|
// store it to result. Keep a copy for the partials.
|
|
|
|
//
|
|
|
|
// If result is less than carry, subtract adjustment.
|
|
|
|
//
|
|
|
|
// Allow onward carry if the bit immediately above this nibble is 1, and
|
|
|
|
// the current partial result is positive.
|
2020-10-10 21:13:16 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
nibble(0x000f, 0x0006, 0x00010);
|
|
|
|
nibble(0x00f0, 0x0060, 0x00100);
|
|
|
|
nibble(0x0f00, 0x0600, 0x01000);
|
2022-06-22 19:12:08 +00:00
|
|
|
nibble(0xf000, 0x6000, 0x10000);
|
2020-10-10 21:13:16 +00:00
|
|
|
|
|
|
|
#undef nibble
|
|
|
|
|
2022-06-22 19:12:08 +00:00
|
|
|
registers_.flags.overflow = (( (partials ^ registers_.a.full) & (partials ^ data_buffer_.value) ) >> (1 + registers_.m_shift))&0x40;
|
2020-10-18 18:55:17 +00:00
|
|
|
registers_.flags.set_nz(uint16_t(result), registers_.m_shift);
|
2022-06-21 18:33:06 +00:00
|
|
|
registers_.flags.carry = (result >> (8 + registers_.m_shift))&1;
|
2020-11-05 01:35:41 +00:00
|
|
|
LDA(result);
|
2020-10-10 21:13:16 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-10-10 21:13:16 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
data_buffer_.value = ~data_buffer_.value & registers_.m_masks[1];
|
|
|
|
[[fallthrough]];
|
2020-10-07 22:36:17 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case ADC: {
|
|
|
|
int result;
|
|
|
|
const uint16_t a = registers_.a.full & registers_.m_masks[1];
|
2020-10-07 22:36:17 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
if(registers_.flags.decimal) {
|
2022-06-22 19:12:08 +00:00
|
|
|
uint16_t partials = 0;
|
|
|
|
result = registers_.flags.carry;
|
2022-06-21 18:33:06 +00:00
|
|
|
|
2022-06-22 19:12:08 +00:00
|
|
|
#define nibble(mask, limit, adjustment, carry) \
|
|
|
|
result += (a & mask) + (data_buffer_.value & mask); \
|
|
|
|
partials += result & mask; \
|
2022-06-21 18:33:06 +00:00
|
|
|
if(result >= limit) result = ((result + adjustment) & (carry - 1)) + carry;
|
2020-10-07 22:36:17 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
nibble(0x000f, 0x000a, 0x0006, 0x00010);
|
|
|
|
nibble(0x00f0, 0x00a0, 0x0060, 0x00100);
|
|
|
|
nibble(0x0f00, 0x0a00, 0x0600, 0x01000);
|
2022-06-22 19:12:08 +00:00
|
|
|
nibble(0xf000, 0xa000, 0x6000, 0x10000);
|
2020-10-07 22:36:17 +00:00
|
|
|
|
2022-06-21 18:33:06 +00:00
|
|
|
#undef nibble
|
2020-11-03 23:12:10 +00:00
|
|
|
|
2022-06-22 19:12:08 +00:00
|
|
|
registers_.flags.overflow = (( (partials ^ registers_.a.full) & (partials ^ data_buffer_.value) ) >> (1 + registers_.m_shift))&0x40;
|
2020-10-16 00:46:18 +00:00
|
|
|
} else {
|
2020-10-18 18:55:17 +00:00
|
|
|
result = int(a + data_buffer_.value + registers_.flags.carry);
|
2020-11-03 23:12:10 +00:00
|
|
|
registers_.flags.overflow = (( (uint16_t(result) ^ registers_.a.full) & (uint16_t(result) ^ data_buffer_.value) ) >> (1 + registers_.m_shift))&0x40;
|
2020-10-16 00:46:18 +00:00
|
|
|
}
|
2020-10-07 22:36:17 +00:00
|
|
|
|
2020-10-18 18:55:17 +00:00
|
|
|
registers_.flags.set_nz(uint16_t(result), registers_.m_shift);
|
2020-10-16 00:46:18 +00:00
|
|
|
registers_.flags.carry = (result >> (8 + registers_.m_shift))&1;
|
2020-11-05 01:35:41 +00:00
|
|
|
LDA(result);
|
2020-10-16 00:46:18 +00:00
|
|
|
} break;
|
2020-10-07 22:36:17 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
//
|
|
|
|
// STP and WAI
|
|
|
|
//
|
2020-10-11 21:56:55 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case STP:
|
|
|
|
required_exceptions_ = Reset;
|
|
|
|
break;
|
2020-10-06 23:12:19 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
case WAI:
|
|
|
|
required_exceptions_ = Reset | IRQ | NMI;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
2020-09-29 22:42:07 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
// Store a selection as to the exceptions, if any, that would be honoured after this cycle if the
|
|
|
|
// next thing is a MoveToNextProgram.
|
|
|
|
selected_exceptions_ = pending_exceptions_ & (registers_.flags.inverse_interrupt | PowerOn | Reset | NMI);
|
2020-10-18 19:08:21 +00:00
|
|
|
number_of_cycles -= bus_handler_.perform_bus_operation(bus_operation_, static_cast<typename BusHandler::AddressType>(bus_address_), bus_value_);
|
2020-10-16 00:46:18 +00:00
|
|
|
}
|
2020-09-29 22:42:07 +00:00
|
|
|
}
|
|
|
|
|
2020-11-05 01:35:41 +00:00
|
|
|
#undef LDA
|
|
|
|
#undef LDXY
|
2020-10-04 23:12:04 +00:00
|
|
|
#undef read
|
|
|
|
#undef write
|
|
|
|
#undef bus_operation
|
2020-10-05 02:06:25 +00:00
|
|
|
#undef x
|
|
|
|
#undef y
|
2020-10-06 20:25:30 +00:00
|
|
|
#undef m_flag
|
|
|
|
#undef x_flag
|
2020-10-11 01:43:05 +00:00
|
|
|
#undef stack_address
|
2020-10-04 23:12:04 +00:00
|
|
|
|
2020-09-29 22:42:07 +00:00
|
|
|
cycles_left_to_run_ = number_of_cycles;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessorBase::set_power_on(bool active) {
|
|
|
|
if(active) {
|
|
|
|
pending_exceptions_ |= PowerOn;
|
|
|
|
} else {
|
|
|
|
pending_exceptions_ &= ~PowerOn;
|
2020-10-18 18:43:47 +00:00
|
|
|
selected_exceptions_ &= ~PowerOn;
|
2020-09-29 22:42:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessorBase::set_irq_line(bool active) {
|
|
|
|
if(active) {
|
|
|
|
pending_exceptions_ |= IRQ;
|
|
|
|
} else {
|
|
|
|
pending_exceptions_ &= ~IRQ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessorBase::set_reset_line(bool active) {
|
|
|
|
if(active) {
|
|
|
|
pending_exceptions_ |= Reset;
|
|
|
|
} else {
|
|
|
|
pending_exceptions_ &= ~Reset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessorBase::set_nmi_line(bool active) {
|
|
|
|
// This is edge triggered.
|
|
|
|
if(active) {
|
|
|
|
pending_exceptions_ |= NMI;
|
2020-09-28 02:20:58 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-29 01:35:46 +00:00
|
|
|
|
2020-10-16 00:46:18 +00:00
|
|
|
void ProcessorBase::set_abort_line(bool active) {
|
|
|
|
// Take a copy of register state now to restore at the beginning of the exception
|
|
|
|
// if abort has gone active, preparing to regress the program counter.
|
|
|
|
if(active) {
|
|
|
|
pending_exceptions_ |= Abort;
|
|
|
|
abort_registers_copy_ = registers_;
|
|
|
|
abort_registers_copy_.pc = last_operation_pc_;
|
|
|
|
} else {
|
|
|
|
pending_exceptions_ &= ~Abort;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename BusHandler, bool uses_ready_line> void Processor<BusHandler, uses_ready_line>::set_ready_line(bool active) {
|
|
|
|
assert(uses_ready_line);
|
|
|
|
ready_line_ = active;
|
|
|
|
}
|
|
|
|
|
2020-09-29 22:42:07 +00:00
|
|
|
// The 65816 can't jam.
|
2020-09-29 01:35:46 +00:00
|
|
|
bool ProcessorBase::is_jammed() const { return false; }
|
2020-10-16 00:46:18 +00:00
|
|
|
|
|
|
|
bool ProcessorBase::get_is_resetting() const {
|
|
|
|
return pending_exceptions_ & (Reset | PowerOn);
|
|
|
|
}
|
2020-10-17 01:05:42 +00:00
|
|
|
|
|
|
|
int ProcessorBase::get_extended_bus_output() {
|
|
|
|
return
|
|
|
|
(memory_lock_ ? ExtendedBusOutput::MemoryLock : 0) |
|
|
|
|
(registers_.mx_flags[0] ? ExtendedBusOutput::MemorySize : 0) |
|
|
|
|
(registers_.mx_flags[1] ? ExtendedBusOutput::IndexSize : 0) |
|
|
|
|
(registers_.emulation_flag ? ExtendedBusOutput::Emulation : 0);
|
|
|
|
}
|
2022-06-18 20:25:57 +00:00
|
|
|
|
|
|
|
void ProcessorBase::restart_operation_fetch() {
|
|
|
|
// Find a OperationMoveToNextProgram, so that the main loop can make
|
|
|
|
// relevant decisions.
|
|
|
|
next_op_ = micro_ops_.data();
|
|
|
|
while(*next_op_ != OperationMoveToNextProgram) ++next_op_;
|
|
|
|
}
|