From d8e42c4379786fedf6d617c05b8fa99267554872 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 9 Sep 2021 22:06:36 -0400 Subject: [PATCH 1/6] Tweak guess at initial state. --- Machines/Apple/AppleII/AuxiliaryMemorySwitches.hpp | 2 +- Machines/Apple/AppleIIgs/MemoryMap.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Machines/Apple/AppleII/AuxiliaryMemorySwitches.hpp b/Machines/Apple/AppleII/AuxiliaryMemorySwitches.hpp index 9dc5b56fb..9e56f0f74 100644 --- a/Machines/Apple/AppleII/AuxiliaryMemorySwitches.hpp +++ b/Machines/Apple/AppleII/AuxiliaryMemorySwitches.hpp @@ -82,7 +82,7 @@ template class AuxiliaryMemorySwitches { bool read_auxiliary_memory = false; bool write_auxiliary_memory = false; - bool internal_CX_rom = false; + bool internal_CX_rom = true; bool slot_C3_rom = false; bool internal_C8_rom = false; diff --git a/Machines/Apple/AppleIIgs/MemoryMap.hpp b/Machines/Apple/AppleIIgs/MemoryMap.hpp index 59aee99d3..68f6400e0 100644 --- a/Machines/Apple/AppleIIgs/MemoryMap.hpp +++ b/Machines/Apple/AppleIIgs/MemoryMap.hpp @@ -241,7 +241,7 @@ class MemoryMap { friend AuxiliaryMemorySwitches; friend LanguageCardSwitches; - uint8_t shadow_register_ = 0x08; + uint8_t shadow_register_ = 0x00; uint8_t speed_register_ = 0x00; // MARK: - Memory banking. From a6221ca322ed706f187834b9fe63cb40d0435ba1 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 9 Sep 2021 22:07:03 -0400 Subject: [PATCH 2/6] Reload data only if an output is found. --- Components/AppleClock/AppleClock.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Components/AppleClock/AppleClock.hpp b/Components/AppleClock/AppleClock.hpp index 2ba395650..e153f2eae 100644 --- a/Components/AppleClock/AppleClock.hpp +++ b/Components/AppleClock/AppleClock.hpp @@ -257,7 +257,10 @@ class ParallelClock: public ClockStorage { // A no-op for now. } else { // Write to the RTC. Which in this implementation also sets up a future read. - data_ = uint8_t(perform(data_)); + const auto result = perform(data_); + if(result != NoResult) { + data_ = uint8_t(result); + } } // MAGIC! The transaction took 0 seconds. From 7e5fc4444a8f1b3c88e47a584b44182e5b1dc431 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 9 Sep 2021 22:09:09 -0400 Subject: [PATCH 3/6] Default to ROM01. --- Analyser/Static/AppleIIgs/Target.hpp | 2 +- Machines/Apple/AppleIIgs/AppleIIgs.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Analyser/Static/AppleIIgs/Target.hpp b/Analyser/Static/AppleIIgs/Target.hpp index 0394312d4..a0eb988aa 100644 --- a/Analyser/Static/AppleIIgs/Target.hpp +++ b/Analyser/Static/AppleIIgs/Target.hpp @@ -29,7 +29,7 @@ struct Target: public Analyser::Static::Target, public Reflection::StructImpl Date: Thu, 9 Sep 2021 23:08:13 -0400 Subject: [PATCH 4/6] Switch to zero-initialised state; be more careful about resetting data. --- Components/AppleClock/AppleClock.hpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Components/AppleClock/AppleClock.hpp b/Components/AppleClock/AppleClock.hpp index e153f2eae..b0229c16d 100644 --- a/Components/AppleClock/AppleClock.hpp +++ b/Components/AppleClock/AppleClock.hpp @@ -24,15 +24,15 @@ class ClockStorage { ClockStorage() { // TODO: this should persist, if possible, rather than // being default initialised. - constexpr uint8_t default_data[] = { - 0xa8, 0x00, 0x00, 0x00, - 0xcc, 0x0a, 0xcc, 0x0a, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x02, 0x63, 0x00, - 0x03, 0x88, 0x00, 0x4c - }; - memcpy(data_, default_data, sizeof(default_data)); - memset(&data_[sizeof(default_data)], 0xff, sizeof(data_) - sizeof(default_data)); +// constexpr uint8_t default_data[] = { +// 0xa8, 0x00, 0x00, 0x00, +// 0xcc, 0x0a, 0xcc, 0x0a, +// 0x00, 0x00, 0x00, 0x00, +// 0x00, 0x02, 0x63, 0x00, +// 0x03, 0x88, 0x00, 0x4c +// }; +// memcpy(data_, default_data, sizeof(default_data)); +// memset(&data_[sizeof(default_data)], 0xff, sizeof(data_) - sizeof(default_data)); } /*! @@ -162,10 +162,10 @@ class ClockStorage { private: - uint8_t data_[256]; - uint8_t seconds_[4]; - uint8_t write_protect_; - int address_; + uint8_t data_[256]{}; + uint8_t seconds_[4]{}; + uint8_t write_protect_ = 0; + int address_ = 0; static constexpr int SecondsBuffer = 0x100; static constexpr int RegisterTest = 0x200; @@ -258,7 +258,7 @@ class ParallelClock: public ClockStorage { } else { // Write to the RTC. Which in this implementation also sets up a future read. const auto result = perform(data_); - if(result != NoResult) { + if(result < 0x100) { data_ = uint8_t(result); } } From dfcd1508c969cbc7c11600cfc033cdbf17608a02 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Fri, 10 Sep 2021 19:56:20 -0400 Subject: [PATCH 5/6] Establishes valid initial BRAM. --- Components/AppleClock/AppleClock.hpp | 44 +++++++++++++++----------- Machines/Apple/AppleIIgs/AppleIIgs.cpp | 42 ++++++++++++++++++++++++ Machines/Apple/Macintosh/Macintosh.cpp | 9 ++++++ 3 files changed, 76 insertions(+), 19 deletions(-) diff --git a/Components/AppleClock/AppleClock.hpp b/Components/AppleClock/AppleClock.hpp index b0229c16d..0b06bb2cf 100644 --- a/Components/AppleClock/AppleClock.hpp +++ b/Components/AppleClock/AppleClock.hpp @@ -9,6 +9,8 @@ #ifndef Apple_RealTimeClock_hpp #define Apple_RealTimeClock_hpp +#include + namespace Apple { namespace Clock { @@ -21,32 +23,36 @@ namespace Clock { */ class ClockStorage { public: - ClockStorage() { - // TODO: this should persist, if possible, rather than - // being default initialised. -// constexpr uint8_t default_data[] = { -// 0xa8, 0x00, 0x00, 0x00, -// 0xcc, 0x0a, 0xcc, 0x0a, -// 0x00, 0x00, 0x00, 0x00, -// 0x00, 0x02, 0x63, 0x00, -// 0x03, 0x88, 0x00, 0x4c -// }; -// memcpy(data_, default_data, sizeof(default_data)); -// memset(&data_[sizeof(default_data)], 0xff, sizeof(data_) - sizeof(default_data)); - } + ClockStorage() {} /*! Advances the clock by 1 second. - The caller should also signal an interrupt. + The caller should also signal an interrupt if applicable. */ void update() { - for(int c = 0; c < 4; ++c) { + for(size_t c = 0; c < 4; ++c) { ++seconds_[c]; if(seconds_[c]) break; } } + /*! + Sets the current [P/B]RAM contents. + */ + template void set_data(const CollectionT &collection) { + set_data(collection.begin(), collection.end()); + } + + template void set_data(IteratorT begin, const IteratorT end) { + size_t c = 0; + while(begin != end && c < 256) { + data_[c] = *begin; + ++begin; + ++c; + } + } + protected: static constexpr uint16_t NoResult = 0x100; static constexpr uint16_t DidComplete = 0x101; @@ -92,7 +98,7 @@ class ClockStorage { case 0x30: // Either a register access or an extended instruction. if(command & 0x08) { - address_ = (command & 0x7) << 5; + address_ = unsigned((command & 0x7) << 5); phase_ = (command & 0x80) ? Phase::SecondAddressByteRead : Phase::SecondAddressByteWrite; return NoResult; } else { @@ -162,10 +168,10 @@ class ClockStorage { private: - uint8_t data_[256]{}; - uint8_t seconds_[4]{}; + std::array data_{0xff}; + std::array seconds_{}; uint8_t write_protect_ = 0; - int address_ = 0; + unsigned int address_ = 0; static constexpr int SecondsBuffer = 0x100; static constexpr int RegisterTest = 0x200; diff --git a/Machines/Apple/AppleIIgs/AppleIIgs.cpp b/Machines/Apple/AppleIIgs/AppleIIgs.cpp index 947430c54..4f79ded00 100644 --- a/Machines/Apple/AppleIIgs/AppleIIgs.cpp +++ b/Machines/Apple/AppleIIgs/AppleIIgs.cpp @@ -42,6 +42,27 @@ namespace { constexpr int CLOCK_RATE = 14'318'180; +// This is the first result that came up when searching for valid Apple IIgs BRAM states; +// I'm unclear on its provenance. +constexpr uint8_t default_bram[] = { + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x0d, 0x06, 0x02, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x07, 0x06, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x06, 0x06, 0x00, 0x05, 0x06, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x02, 0x02, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, + 0x07, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, + 0x0e, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfd, 0x96, 0x57, 0x3c, +}; + class MemManagerChecker { int handle_total_ = 0; bool dump_bank(const Apple::IIgs::MemoryMap &memory, const char *name, uint32_t address, bool print, uint32_t must_contain = 0xffffffff) { @@ -187,6 +208,7 @@ class ConcreteMachine: set_clock_rate(double(CLOCK_RATE)); speaker_.set_input_rate(float(CLOCK_RATE) / float(audio_divider)); + clock_.ClockStorage::set_data(std::begin(default_bram), std::end(default_bram)); using Target = Analyser::Static::AppleIIgs::Target; ROM::Name system; @@ -353,6 +375,26 @@ class ConcreteMachine: static bool log = false; bool is_1Mhz = false; + if(operation == CPU::WDC65816::BusOperation::ReadOpcode) { + if(address == 0xffb626 && m65816_.get_value_of_register(CPU::WDC65816::Register::X) == 0x51) { + printf(""); + } + if(address == 0xffb54c) { + printf(""); + } + + printf("%06x a:%04x x:%04x y:%04x s:%04x d:%04x b:%04x\n", + address, + m65816_.get_value_of_register(CPU::WDC65816::Register::A), + m65816_.get_value_of_register(CPU::WDC65816::Register::X), + m65816_.get_value_of_register(CPU::WDC65816::Register::Y), +// m65816_.get_value_of_register(CPU::WDC65816::Register::Flags), + m65816_.get_value_of_register(CPU::WDC65816::Register::StackPointer), + m65816_.get_value_of_register(CPU::WDC65816::Register::Direct), + m65816_.get_value_of_register(CPU::WDC65816::Register::DataBank) + ); + } + if(operation == CPU::WDC65816::BusOperation::ReadVector && !(memory_.get_shadow_register()&0x40)) { // I think vector pulls always go to ROM? // That's slightly implied in the documentation, and doing so makes GS/OS boot, so... diff --git a/Machines/Apple/Macintosh/Macintosh.cpp b/Machines/Apple/Macintosh/Macintosh.cpp index 4903055f3..bf9f06e9d 100644 --- a/Machines/Apple/Macintosh/Macintosh.cpp +++ b/Machines/Apple/Macintosh/Macintosh.cpp @@ -49,6 +49,15 @@ namespace { constexpr int CLOCK_RATE = 7833600; + +// Former default PRAM: +// +// 0xa8, 0x00, 0x00, 0x00, +// 0xcc, 0x0a, 0xcc, 0x0a, +// 0x00, 0x00, 0x00, 0x00, +// 0x00, 0x02, 0x63, 0x00, +// 0x03, 0x88, 0x00, 0x4c + } namespace Apple { From fa71ae31745ad9eb9ff55084ba69eac095feee05 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 14 Sep 2021 20:23:36 -0400 Subject: [PATCH 6/6] Add apology. --- Machines/Apple/AppleIIgs/AppleIIgs.cpp | 54 ++++++++++++++------------ 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/Machines/Apple/AppleIIgs/AppleIIgs.cpp b/Machines/Apple/AppleIIgs/AppleIIgs.cpp index 4f79ded00..68e315e01 100644 --- a/Machines/Apple/AppleIIgs/AppleIIgs.cpp +++ b/Machines/Apple/AppleIIgs/AppleIIgs.cpp @@ -38,6 +38,14 @@ #include #include +// +// HEAVY WARNING: THIS IS INCOMPLETE AND VERY PROVISIONAL. +// +// You'll notice lots of random bits of debugging code sitting around but commented out. +// Most of this will go when this machine is complete. Please look past the gross ugliness +// of this code's intermediate state if you are able. +// + namespace { constexpr int CLOCK_RATE = 14'318'180; @@ -63,7 +71,7 @@ constexpr uint8_t default_bram[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfd, 0x96, 0x57, 0x3c, }; -class MemManagerChecker { +/*class MemManagerChecker { int handle_total_ = 0; bool dump_bank(const Apple::IIgs::MemoryMap &memory, const char *name, uint32_t address, bool print, uint32_t must_contain = 0xffffffff) { const auto handles = memory.regions[memory.region_map[0xe117]].read; @@ -170,7 +178,7 @@ class MemManagerChecker { return result; } -}; +};*/ } @@ -375,25 +383,22 @@ class ConcreteMachine: static bool log = false; bool is_1Mhz = false; - if(operation == CPU::WDC65816::BusOperation::ReadOpcode) { - if(address == 0xffb626 && m65816_.get_value_of_register(CPU::WDC65816::Register::X) == 0x51) { - printf(""); - } - if(address == 0xffb54c) { - printf(""); - } - - printf("%06x a:%04x x:%04x y:%04x s:%04x d:%04x b:%04x\n", - address, - m65816_.get_value_of_register(CPU::WDC65816::Register::A), - m65816_.get_value_of_register(CPU::WDC65816::Register::X), - m65816_.get_value_of_register(CPU::WDC65816::Register::Y), -// m65816_.get_value_of_register(CPU::WDC65816::Register::Flags), - m65816_.get_value_of_register(CPU::WDC65816::Register::StackPointer), - m65816_.get_value_of_register(CPU::WDC65816::Register::Direct), - m65816_.get_value_of_register(CPU::WDC65816::Register::DataBank) - ); - } +// if(operation == CPU::WDC65816::BusOperation::ReadOpcode) { +// if(address == 0xfe00d5) { +// printf(""); +// } +// +// printf("%06x a:%04x x:%04x y:%04x s:%04x d:%04x b:%04x\n", +// address, +// m65816_.get_value_of_register(CPU::WDC65816::Register::A), +// m65816_.get_value_of_register(CPU::WDC65816::Register::X), +// m65816_.get_value_of_register(CPU::WDC65816::Register::Y), +//// m65816_.get_value_of_register(CPU::WDC65816::Register::Flags), +// m65816_.get_value_of_register(CPU::WDC65816::Register::StackPointer), +// m65816_.get_value_of_register(CPU::WDC65816::Register::Direct), +// m65816_.get_value_of_register(CPU::WDC65816::Register::DataBank) +// ); +// } if(operation == CPU::WDC65816::BusOperation::ReadVector && !(memory_.get_shadow_register()&0x40)) { // I think vector pulls always go to ROM? @@ -983,9 +988,9 @@ class ConcreteMachine: // } if(operation == CPU::WDC65816::BusOperation::ReadOpcode) { - if(total > 482342960 && total < 482352960 && address == 0xe10000) { - printf("entry: %llu\n", static_cast(total)); - } +// if(total > 482342960 && total < 482352960 && address == 0xe10000) { +// printf("entry: %llu\n", static_cast(total)); +// } // log |= address == 0xfc144f; // log &= !((address < 0xfc144f) || (address >= 0xfc1490)); @@ -1194,3 +1199,4 @@ Machine *Machine::AppleIIgs(const Analyser::Static::Target *target, const ROMMac } Machine::~Machine() {} +