diff --git a/Analyser/Static/Macintosh/StaticAnalyser.cpp b/Analyser/Static/Macintosh/StaticAnalyser.cpp index 9c9b203d8..94356ef98 100644 --- a/Analyser/Static/Macintosh/StaticAnalyser.cpp +++ b/Analyser/Static/Macintosh/StaticAnalyser.cpp @@ -19,6 +19,19 @@ Analyser::Static::TargetList Analyser::Static::Macintosh::GetTargets(const Media using Target = Analyser::Static::Macintosh::Target; auto *const target = new Target; target->media = media; + + // If this is a single-sided floppy disk, guess the Macintosh 512kb. + if(media.mass_storage_devices.empty()) { + bool has_800kb_disks = false; + for(const auto &disk: media.disks) { + has_800kb_disks |= disk->get_head_count() > 1; + } + + if(!has_800kb_disks) { + target->model = Target::Model::Mac512k; + } + } + targets.push_back(std::unique_ptr(target)); return targets; diff --git a/Machines/Apple/Macintosh/DriveSpeedAccumulator.cpp b/Machines/Apple/Macintosh/DriveSpeedAccumulator.cpp index b4277def4..7a6a3ec1b 100644 --- a/Machines/Apple/Macintosh/DriveSpeedAccumulator.cpp +++ b/Machines/Apple/Macintosh/DriveSpeedAccumulator.cpp @@ -8,6 +8,36 @@ #include "DriveSpeedAccumulator.hpp" +namespace { + +/* + For knowledge encapsulate below, all credit goes to the MAME team. No original research here. + + Per their investigation, the bytes collected for PWM output feed a 6-bit LFSR, which then keeps + output high until it eventually reaches a state of 0x20. The LFSR shifts rightward and taps bits + 0 and 1 as the new input into bit 5. + + I've therefore implemented the LFSR as below, feeding into a lookup table to calculate actual + pulse widths from the values stored into the PWM buffer. +*/ +template constexpr uint8_t lfsr() { + if constexpr (value == 0x20 || !value) return 0; + return 1+lfsr<(((value ^ (value >> 1))&1) << 5) | (value >> 1)>(); +} + +constexpr uint8_t pwm_lookup[] = { + lfsr<0>(), lfsr<1>(), lfsr<2>(), lfsr<3>(), lfsr<4>(), lfsr<5>(), lfsr<6>(), lfsr<7>(), + lfsr<8>(), lfsr<9>(), lfsr<10>(), lfsr<11>(), lfsr<12>(), lfsr<13>(), lfsr<14>(), lfsr<15>(), + lfsr<16>(), lfsr<17>(), lfsr<18>(), lfsr<19>(), lfsr<20>(), lfsr<21>(), lfsr<22>(), lfsr<23>(), + lfsr<24>(), lfsr<25>(), lfsr<26>(), lfsr<27>(), lfsr<28>(), lfsr<29>(), lfsr<30>(), lfsr<31>(), + lfsr<32>(), lfsr<33>(), lfsr<34>(), lfsr<35>(), lfsr<36>(), lfsr<37>(), lfsr<38>(), lfsr<39>(), + lfsr<40>(), lfsr<41>(), lfsr<42>(), lfsr<43>(), lfsr<44>(), lfsr<45>(), lfsr<46>(), lfsr<47>(), + lfsr<48>(), lfsr<49>(), lfsr<50>(), lfsr<51>(), lfsr<52>(), lfsr<53>(), lfsr<54>(), lfsr<55>(), + lfsr<56>(), lfsr<57>(), lfsr<58>(), lfsr<59>(), lfsr<60>(), lfsr<61>(), lfsr<62>(), lfsr<63>(), +}; + +} + using namespace Apple::Macintosh; void DriveSpeedAccumulator::post_sample(uint8_t sample) { @@ -17,40 +47,33 @@ void DriveSpeedAccumulator::post_sample(uint8_t sample) { // the samples until there is a certain small quantity of them, // then produce a new estimate of rotation speed and start the // buffer afresh. - samples_[sample_pointer_] = sample; - ++sample_pointer_; - - if(sample_pointer_ == samples_.size()) { - sample_pointer_ = 0; + // + // Note the table lookup here; see text above. + sample_total_ += pwm_lookup[sample & 0x3f]; + ++sample_count_; + if(sample_count_ == samples_per_bucket) { // The below fits for a function like `a + bc`; it encapsultes the following // beliefs: // // (i) motor speed is proportional to voltage supplied; // (ii) with pulse-width modulation it's therefore proportional to the duty cycle; - // (iii) the Mac pulse-width modulates whatever it reads from the disk speed buffer; + // (iii) the Mac pulse-width modulates whatever it reads from the disk speed buffer, as per the LFSR rules above; // (iv) ... subject to software pulse-width modulation of that pulse-width modulation. // // So, I believe current motor speed is proportional to a low-pass filtering of // the speed buffer. Which I've implemented very coarsely via 'large' bucketed-averages, // noting also that exact disk motor speed is always a little approximate. - // Sum all samples. - // TODO: if the above is the correct test, do it on sample receipt rather than - // bothering with an intermediate buffer. - int sum = 0; - for(auto s: samples_) { - sum += s; - } - // The formula below was derived from observing values the Mac wrote into its // disk-speed buffer. Given that it runs a calibration loop before doing so, // I cannot guarantee the accuracy of these numbers beyond being within the // range that the computer would accept. - const float normalised_sum = float(sum) / float(samples_.size()); - const float rotation_speed = (normalised_sum * 27.08f) - 259.0f; + const float normalised_sum = float(sample_total_) / float(samples_per_bucket); + const float rotation_speed = (normalised_sum - 3.7f) * 17.6f; delegate_->drive_speed_accumulator_set_drive_speed(this, rotation_speed); + sample_count_ = 0; + sample_total_ = 0; } } - diff --git a/Machines/Apple/Macintosh/DriveSpeedAccumulator.hpp b/Machines/Apple/Macintosh/DriveSpeedAccumulator.hpp index f626217d1..45568e006 100644 --- a/Machines/Apple/Macintosh/DriveSpeedAccumulator.hpp +++ b/Machines/Apple/Macintosh/DriveSpeedAccumulator.hpp @@ -34,8 +34,9 @@ class DriveSpeedAccumulator { } private: - std::array samples_; - std::size_t sample_pointer_ = 0; + static constexpr int samples_per_bucket = 20; + int sample_count_ = 0; + int sample_total_ = 0; Delegate *delegate_ = nullptr; }; diff --git a/OSBindings/Mac/Clock Signal/MachinePicker/Base.lproj/MachinePicker.xib b/OSBindings/Mac/Clock Signal/MachinePicker/Base.lproj/MachinePicker.xib index 3b8df9258..d41dbd583 100644 --- a/OSBindings/Mac/Clock Signal/MachinePicker/Base.lproj/MachinePicker.xib +++ b/OSBindings/Mac/Clock Signal/MachinePicker/Base.lproj/MachinePicker.xib @@ -303,11 +303,11 @@ Gw - + - + @@ -315,13 +315,15 @@ Gw - - + + - + + + diff --git a/OSBindings/Qt/mainwindow.cpp b/OSBindings/Qt/mainwindow.cpp index 761d931d4..de27dc5a0 100644 --- a/OSBindings/Qt/mainwindow.cpp +++ b/OSBindings/Qt/mainwindow.cpp @@ -1196,8 +1196,10 @@ void MainWindow::start_macintosh() { auto target = std::make_unique(); switch(ui->macintoshModelComboBox->currentIndex()) { - default: target->model = Target::Model::Mac512ke; break; - case 1: target->model = Target::Model::MacPlus; break; + default: target->model = Target::Model::Mac128k; break; + case 1: target->model = Target::Model::Mac512k; break; + case 2: target->model = Target::Model::Mac512ke; break; + case 3: target->model = Target::Model::MacPlus; break; } launchTarget(std::move(target)); diff --git a/OSBindings/Qt/mainwindow.ui b/OSBindings/Qt/mainwindow.ui index f3d2dea23..ed2fb7835 100644 --- a/OSBindings/Qt/mainwindow.ui +++ b/OSBindings/Qt/mainwindow.ui @@ -328,6 +328,16 @@ + + + 128k + + + + + 512k + + 512ke