From e3f6da6994af9f6ed82c9eff97d83ee964cf99ae Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 8 Aug 2018 20:00:14 -0400 Subject: [PATCH] Implements the 65C02 NOPs. --- .../Clock SignalTests/KlausDormannTests.swift | 2 ++ Processors/6502/6502.hpp | 3 ++- .../6502/Implementation/6502Implementation.hpp | 11 ++++++++++- Processors/6502/Implementation/6502Storage.cpp | 18 ++++++++++++++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/OSBindings/Mac/Clock SignalTests/KlausDormannTests.swift b/OSBindings/Mac/Clock SignalTests/KlausDormannTests.swift index 71a82f171..7da2aa683 100644 --- a/OSBindings/Mac/Clock SignalTests/KlausDormannTests.swift +++ b/OSBindings/Mac/Clock SignalTests/KlausDormannTests.swift @@ -76,6 +76,8 @@ class KlausDormannTests: XCTestCase { case 0x0730: return "BBS: branch not taken" case 0x0733: return "BBR: branch taken" + case 0x2884: return "JMP (abs) exhibited 6502 page-crossing bug" + case 0: return "Didn't find tests" default: return "Unknown error at \(String(format:"%04x", address))" } diff --git a/Processors/6502/6502.hpp b/Processors/6502/6502.hpp index 37a2e6eca..00fb75429 100644 --- a/Processors/6502/6502.hpp +++ b/Processors/6502/6502.hpp @@ -204,7 +204,7 @@ template class Processor: public ProcessorBas /*! Constructs an instance of the 6502 that will use @c bus_handler for all bus communications. */ - Processor(Personality personality, T &bus_handler) : ProcessorBase(personality), bus_handler_(bus_handler) {} + Processor(Personality personality, T &bus_handler) : ProcessorBase(personality), personality_(personality), bus_handler_(bus_handler) {} /*! Runs the 6502 for a supplied number of cycles. @@ -221,6 +221,7 @@ template class Processor: public ProcessorBas void set_ready_line(bool active); private: + Personality personality_; T &bus_handler_; }; diff --git a/Processors/6502/Implementation/6502Implementation.hpp b/Processors/6502/Implementation/6502Implementation.hpp index 4d3cca800..3a3ef35a5 100644 --- a/Processors/6502/Implementation/6502Implementation.hpp +++ b/Processors/6502/Implementation/6502Implementation.hpp @@ -93,7 +93,16 @@ if(number_of_cycles <= Cycles(0)) break; } break; case CycleFetchOperand: - read_mem(operand_, pc_.full); + if( + personality_ == P6502 || + (operation_&7) != 3 || + operation_ == 0xcb || + operation_ == 0xdb + ) { + read_mem(operand_, pc_.full); + } else { + printf("Skipping %02x\n", operation_); + } break; case OperationDecodeOperation: diff --git a/Processors/6502/Implementation/6502Storage.cpp b/Processors/6502/Implementation/6502Storage.cpp index 264287f4e..517a09420 100644 --- a/Processors/6502/Implementation/6502Storage.cpp +++ b/Processors/6502/Implementation/6502Storage.cpp @@ -242,6 +242,24 @@ ProcessorStorage::ProcessorStorage(Personality personality) { for(int location = 0x0f; location <= 0xff; location += 0x10) { Install(location, Program(OperationLoadAddressZeroPage, CycleFetchOperandFromAddress, OperationBBRBBS)); } + + // Add NOPs. + + // The 1-byte, 1-cycle (!) NOPs. + for(int c = 0x03; c <= 0xf3; c += 0x10) { + Install(c, ImpliedNop()); + } + for(int c = 0x0b; c <= 0xbb; c += 0x10) { + Install(c, ImpliedNop()); + } + for(int c = 0xeb; c <= 0xfb; c += 0x10) { + Install(c, ImpliedNop()); + } + + // The 2-byte, 2-cycle NOPs that the 6502 doesn't have. + for(int c = 0x02; c <= 0x62; c += 0x10) { + Install(c, ImmediateNop()); + } } #undef Install }