Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

65816: correct emulation-mode [d], y, PEI and PLB. #1404

Merged
merged 5 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ClockReceiver/ClockReceiver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,19 @@ template <class T> class WrappedInt {

/// @returns The underlying int, converted to an integral type of your choosing, clamped to that int's range.
template<typename Type = IntType> forceinline constexpr Type as() const {
if constexpr (sizeof(Type) == sizeof(IntType)) {
if constexpr (std::is_same_v<Type, IntType>) {
return length_;
} else if constexpr (std::is_signed_v<Type>) {
// Both integers are the same size, but a signed result is being asked for
// from an unsigned original.
return length_ > Type(std::numeric_limits<Type>::max()) ? Type(std::numeric_limits<Type>::max()) : Type(length_);
} else {
// An unsigned result is being asked for from a signed original.
return length_ < 0 ? 0 : Type(length_);
}
}

const auto clamped = std::clamp(length_, IntType(std::numeric_limits<Type>::min()), IntType(std::numeric_limits<Type>::max()));
return Type(clamped);
}
Expand Down
16 changes: 8 additions & 8 deletions Processors/65816/Implementation/65816Storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ struct CPU::WDC65816::ProcessorStorageConstructor {
static void direct_indirect_indexed_long(AccessType type, bool is8bit, const std::function<void(MicroOp)> &target) {
target(CycleFetchIncrementPC); // DO.

target(OperationConstructDirect);
target(OperationConstructDirectLong);
target(CycleFetchPreviousPCThrowaway); // IO.

target(CycleFetchIncrementData); // AAL.
Expand Down Expand Up @@ -667,13 +667,13 @@ struct CPU::WDC65816::ProcessorStorageConstructor {
target(OperationPerform);
}

// 22b(ii). Stack; s, PLx, ignoring emulation mode. I.e. PLD.
static void stack_pld(AccessType, bool, const std::function<void(MicroOp)> &target) {
// 22b(ii). Stack; s, PLx, ignoring emulation mode. I.e. PLD and PLB.
static void stack_pld_plb(AccessType, bool is8bit, const std::function<void(MicroOp)> &target) {
target(CycleFetchPCThrowaway); // IO.
target(CycleFetchPCThrowaway); // IO.

target(CyclePullNotEmulation); // REG low.
target(CyclePullNotEmulation); // REG [high].
if(!is8bit) target(CyclePullNotEmulation); // REG low.
target(CyclePullNotEmulation); // REG [high].

target(OperationPerform);
}
Expand Down Expand Up @@ -713,7 +713,7 @@ struct CPU::WDC65816::ProcessorStorageConstructor {
static void stack_pei(AccessType, bool, const std::function<void(MicroOp)> &target) {
target(CycleFetchIncrementPC); // DO.

target(OperationConstructDirect);
target(OperationConstructDirectLong);
target(CycleFetchPreviousPCThrowaway); // IO.

target(CycleFetchIncrementData); // AAL.
Expand Down Expand Up @@ -873,7 +873,7 @@ ProcessorStorage::ProcessorStorage() {
/* 0x28 PLP s */ op(stack_pull, PLP, AccessMode::Always8Bit);
/* 0x29 AND # */ op(immediate, AND);
/* 0x2a ROL A */ op(accumulator, ROL);
/* 0x2b PLD s */ op(stack_pld, PLD);
/* 0x2b PLD s */ op(stack_pld_plb, PLD, AccessMode::Always16Bit);
/* 0x2c BIT a */ op(absolute, BIT);
/* 0x2d AND a */ op(absolute, AND);
/* 0x2e ROL a */ op(absolute_rmw, ROL);
Expand Down Expand Up @@ -1009,7 +1009,7 @@ ProcessorStorage::ProcessorStorage() {
/* 0xa8 TAY i */ op(implied, TAY);
/* 0xa9 LDA # */ op(immediate, LDA);
/* 0xaa TAX i */ op(implied, TAX);
/* 0xab PLB s */ op(stack_pull, PLB, AccessMode::Always8Bit);
/* 0xab PLB s */ op(stack_pld_plb, PLB, AccessMode::Always8Bit);
/* 0xac LDY a */ op(absolute, LDY);
/* 0xad LDA a */ op(absolute, LDA);
/* 0xae LDX a */ op(absolute, LDX);
Expand Down
Loading