mirror of
https://github.com/TomHarte/CLK.git
synced 2025-01-11 08:30:55 +00:00
Merge branch 'master' into AppleIIgs
This commit is contained in:
commit
2a7ea9f57c
@ -19,6 +19,19 @@ Analyser::Static::TargetList Analyser::Static::Macintosh::GetTargets(const Media
|
|||||||
using Target = Analyser::Static::Macintosh::Target;
|
using Target = Analyser::Static::Macintosh::Target;
|
||||||
auto *const target = new Target;
|
auto *const target = new Target;
|
||||||
target->media = media;
|
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<Analyser::Static::Target>(target));
|
targets.push_back(std::unique_ptr<Analyser::Static::Target>(target));
|
||||||
|
|
||||||
return targets;
|
return targets;
|
||||||
|
@ -8,6 +8,36 @@
|
|||||||
|
|
||||||
#include "DriveSpeedAccumulator.hpp"
|
#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<uint8_t value> 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;
|
using namespace Apple::Macintosh;
|
||||||
|
|
||||||
void DriveSpeedAccumulator::post_sample(uint8_t sample) {
|
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,
|
// the samples until there is a certain small quantity of them,
|
||||||
// then produce a new estimate of rotation speed and start the
|
// then produce a new estimate of rotation speed and start the
|
||||||
// buffer afresh.
|
// buffer afresh.
|
||||||
samples_[sample_pointer_] = sample;
|
//
|
||||||
++sample_pointer_;
|
// Note the table lookup here; see text above.
|
||||||
|
sample_total_ += pwm_lookup[sample & 0x3f];
|
||||||
if(sample_pointer_ == samples_.size()) {
|
++sample_count_;
|
||||||
sample_pointer_ = 0;
|
|
||||||
|
|
||||||
|
if(sample_count_ == samples_per_bucket) {
|
||||||
// The below fits for a function like `a + bc`; it encapsultes the following
|
// The below fits for a function like `a + bc`; it encapsultes the following
|
||||||
// beliefs:
|
// beliefs:
|
||||||
//
|
//
|
||||||
// (i) motor speed is proportional to voltage supplied;
|
// (i) motor speed is proportional to voltage supplied;
|
||||||
// (ii) with pulse-width modulation it's therefore proportional to the duty cycle;
|
// (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.
|
// (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
|
// 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,
|
// 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.
|
// 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
|
// 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,
|
// 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
|
// I cannot guarantee the accuracy of these numbers beyond being within the
|
||||||
// range that the computer would accept.
|
// range that the computer would accept.
|
||||||
const float normalised_sum = float(sum) / float(samples_.size());
|
const float normalised_sum = float(sample_total_) / float(samples_per_bucket);
|
||||||
const float rotation_speed = (normalised_sum * 27.08f) - 259.0f;
|
const float rotation_speed = (normalised_sum - 3.7f) * 17.6f;
|
||||||
|
|
||||||
delegate_->drive_speed_accumulator_set_drive_speed(this, rotation_speed);
|
delegate_->drive_speed_accumulator_set_drive_speed(this, rotation_speed);
|
||||||
|
sample_count_ = 0;
|
||||||
|
sample_total_ = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,8 +34,9 @@ class DriveSpeedAccumulator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::array<uint8_t, 20> samples_;
|
static constexpr int samples_per_bucket = 20;
|
||||||
std::size_t sample_pointer_ = 0;
|
int sample_count_ = 0;
|
||||||
|
int sample_total_ = 0;
|
||||||
Delegate *delegate_ = nullptr;
|
Delegate *delegate_ = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -303,11 +303,11 @@ Gw
|
|||||||
</tabViewItem>
|
</tabViewItem>
|
||||||
<tabViewItem label="Macintosh" identifier="mac" id="lmR-z3-xSm">
|
<tabViewItem label="Macintosh" identifier="mac" id="lmR-z3-xSm">
|
||||||
<view key="view" id="7Yf-vi-Q0W">
|
<view key="view" id="7Yf-vi-Q0W">
|
||||||
<rect key="frame" x="10" y="33" width="674" height="94"/>
|
<rect key="frame" x="10" y="33" width="679" height="95"/>
|
||||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
<subviews>
|
<subviews>
|
||||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ZOY-4E-Cfl">
|
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ZOY-4E-Cfl">
|
||||||
<rect key="frame" x="15" y="73" width="46" height="16"/>
|
<rect key="frame" x="15" y="74" width="46" height="16"/>
|
||||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Model:" id="h9r-i6-66j">
|
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Model:" id="h9r-i6-66j">
|
||||||
<font key="font" metaFont="system"/>
|
<font key="font" metaFont="system"/>
|
||||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||||
@ -315,13 +315,15 @@ Gw
|
|||||||
</textFieldCell>
|
</textFieldCell>
|
||||||
</textField>
|
</textField>
|
||||||
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="xa6-NA-JY5">
|
<popUpButton verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="xa6-NA-JY5">
|
||||||
<rect key="frame" x="65" y="67" width="74" height="25"/>
|
<rect key="frame" x="64" y="68" width="75" height="25"/>
|
||||||
<popUpButtonCell key="cell" type="push" title="Plus" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" tag="3" imageScaling="proportionallyDown" inset="2" selectedItem="R6T-hg-rOF" id="1Kb-Q2-BGM">
|
<popUpButtonCell key="cell" type="push" title="128k" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="WCG-6u-ANQ" id="1Kb-Q2-BGM">
|
||||||
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
|
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
|
||||||
<font key="font" metaFont="menu"/>
|
<font key="font" metaFont="menu"/>
|
||||||
<menu key="menu" id="ofy-j9-YnU">
|
<menu key="menu" id="ofy-j9-YnU">
|
||||||
<items>
|
<items>
|
||||||
<menuItem title="512ke" tag="2" id="WCG-6u-ANQ"/>
|
<menuItem title="128k" id="WCG-6u-ANQ"/>
|
||||||
|
<menuItem title="512k" tag="1" id="FlG-je-OOM"/>
|
||||||
|
<menuItem title="512ke" tag="2" id="xaj-em-oZa"/>
|
||||||
<menuItem title="Plus" state="on" tag="3" id="R6T-hg-rOF"/>
|
<menuItem title="Plus" state="on" tag="3" id="R6T-hg-rOF"/>
|
||||||
</items>
|
</items>
|
||||||
</menu>
|
</menu>
|
||||||
|
@ -1196,8 +1196,10 @@ void MainWindow::start_macintosh() {
|
|||||||
auto target = std::make_unique<Target>();
|
auto target = std::make_unique<Target>();
|
||||||
|
|
||||||
switch(ui->macintoshModelComboBox->currentIndex()) {
|
switch(ui->macintoshModelComboBox->currentIndex()) {
|
||||||
default: target->model = Target::Model::Mac512ke; break;
|
default: target->model = Target::Model::Mac128k; break;
|
||||||
case 1: target->model = Target::Model::MacPlus; 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));
|
launchTarget(std::move(target));
|
||||||
|
@ -328,6 +328,16 @@
|
|||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QComboBox" name="macintoshModelComboBox">
|
<widget class="QComboBox" name="macintoshModelComboBox">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>128k</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>512k</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>512ke</string>
|
<string>512ke</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user