From 3e9fa63799e51481807eb1aa70b0915551b4e355 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 1 Jun 2019 19:31:32 -0400 Subject: [PATCH] Adds a receiver for drive-motor control bytes. My new belief is that I'm either reading the buffer from the wrong place, or the 68000 isn't filling it for some reason. --- .../Apple/Macintosh/DriveSpeedAccumulator.cpp | 29 ++++++++++++++++ .../Apple/Macintosh/DriveSpeedAccumulator.hpp | 34 +++++++++++++++++++ Machines/Apple/Macintosh/Macintosh.cpp | 12 ++++--- Machines/Apple/Macintosh/Video.cpp | 7 ++-- Machines/Apple/Macintosh/Video.hpp | 6 ++-- .../Clock Signal.xcodeproj/project.pbxproj | 6 ++++ 6 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 Machines/Apple/Macintosh/DriveSpeedAccumulator.cpp create mode 100644 Machines/Apple/Macintosh/DriveSpeedAccumulator.hpp diff --git a/Machines/Apple/Macintosh/DriveSpeedAccumulator.cpp b/Machines/Apple/Macintosh/DriveSpeedAccumulator.cpp new file mode 100644 index 000000000..b7c5eac1e --- /dev/null +++ b/Machines/Apple/Macintosh/DriveSpeedAccumulator.cpp @@ -0,0 +1,29 @@ +// +// DriveSpeedAccumulator.cpp +// Clock Signal +// +// Created by Thomas Harte on 01/06/2019. +// Copyright © 2019 Thomas Harte. All rights reserved. +// + +#include "DriveSpeedAccumulator.hpp" + +using namespace Apple::Macintosh; + +void DriveSpeedAccumulator::post_sample(uint8_t sample) { + // An Euler-esque approximation is used here: just collect all + // 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; + + for(int c = 0; c < 512; c += 32) { + printf("%u ", samples_[c]); + } + printf("\n"); + } +} diff --git a/Machines/Apple/Macintosh/DriveSpeedAccumulator.hpp b/Machines/Apple/Macintosh/DriveSpeedAccumulator.hpp new file mode 100644 index 000000000..9da8fa3f1 --- /dev/null +++ b/Machines/Apple/Macintosh/DriveSpeedAccumulator.hpp @@ -0,0 +1,34 @@ +// +// DriveSpeedAccumulator.hpp +// Clock Signal +// +// Created by Thomas Harte on 01/06/2019. +// Copyright © 2019 Thomas Harte. All rights reserved. +// + +#ifndef DriveSpeedAccumulator_hpp +#define DriveSpeedAccumulator_hpp + +#include +#include +#include + +namespace Apple { +namespace Macintosh { + +class DriveSpeedAccumulator { + public: + /*! + Accepts fetched motor control values. + */ + void post_sample(uint8_t sample); + + private: + std::array samples_; + std::size_t sample_pointer_ = 0; +}; + +} +} + +#endif /* DriveSpeedAccumulator_hpp */ diff --git a/Machines/Apple/Macintosh/Macintosh.cpp b/Machines/Apple/Macintosh/Macintosh.cpp index e4bb411c0..e329ab64f 100644 --- a/Machines/Apple/Macintosh/Macintosh.cpp +++ b/Machines/Apple/Macintosh/Macintosh.cpp @@ -11,6 +11,7 @@ #include #include "DeferredAudio.hpp" +#include "DriveSpeedAccumulator.hpp" #include "Keyboard.hpp" #include "RealTimeClock.hpp" #include "Video.hpp" @@ -41,10 +42,10 @@ class ConcreteMachine: public: ConcreteMachine(const ROMMachine::ROMFetcher &rom_fetcher) : mc68000_(*this), - video_(ram_.data(), audio_), + iwm_(CLOCK_RATE), + video_(ram_.data(), audio_, drive_speed_accumulator_), via_(via_port_handler_), - via_port_handler_(*this, clock_, keyboard_, video_, audio_, iwm_), - iwm_(CLOCK_RATE) { + via_port_handler_(*this, clock_, keyboard_, video_, audio_, iwm_) { // Grab a copy of the ROM and convert it into big-endian data. const auto roms = rom_fetcher("Macintosh", { "mac128k.rom" }); @@ -367,6 +368,9 @@ class ConcreteMachine: CPU::MC68000::Processor mc68000_; + DriveSpeedAccumulator drive_speed_accumulator_; + IWM iwm_; + DeferredAudio audio_; Video video_; @@ -376,8 +380,6 @@ class ConcreteMachine: MOS::MOS6522::MOS6522 via_; VIAPortHandler via_port_handler_; - IWM iwm_; - HalfCycles via_clock_; HalfCycles real_time_clock_; HalfCycles keyboard_clock_; diff --git a/Machines/Apple/Macintosh/Video.cpp b/Machines/Apple/Macintosh/Video.cpp index bcdf4b17f..50e426c1e 100644 --- a/Machines/Apple/Macintosh/Video.cpp +++ b/Machines/Apple/Macintosh/Video.cpp @@ -33,8 +33,9 @@ const int sync_end = 38; // "The visible portion of a full-screen display consists of 342 horizontal scan lines... // During the vertical blanking interval, the turned-off beam ... traces out an additional 28 scan lines," // -Video::Video(uint16_t *ram, DeferredAudio &audio) : +Video::Video(uint16_t *ram, DeferredAudio &audio, DriveSpeedAccumulator &drive_speed_accumulator) : audio_(audio), + drive_speed_accumulator_(drive_speed_accumulator), crt_(704, 1, 370, Outputs::Display::ColourSpace::YIQ, 1, 1, 6, false, Outputs::Display::InputDataType::Luminance1), ram_(ram) { @@ -138,7 +139,7 @@ void Video::run_for(HalfCycles duration) { const uint16_t audio_word = ram_[audio_address_]; ++audio_address_; audio_.audio.post_sample(audio_word >> 8); - // TODO: post disk byte. + drive_speed_accumulator_.post_sample(audio_word & 0xff); } } @@ -155,7 +156,7 @@ void Video::run_for(HalfCycles duration) { "The main sound buffer is at $1FD00 in a 128K Macintosh, and the alternate buffer is at $1A100; for a 512K Macintosh, add $60000 to these values." */ - audio_address_ = use_alternate_audio_buffer_ ? (0x1fd00 >> 1) : (0x1a100 >> 1); + audio_address_ = use_alternate_audio_buffer_ ? (0x1a100 >> 1) : (0x1fd00 >> 1); } } } diff --git a/Machines/Apple/Macintosh/Video.hpp b/Machines/Apple/Macintosh/Video.hpp index 612b0b92e..2f3360949 100644 --- a/Machines/Apple/Macintosh/Video.hpp +++ b/Machines/Apple/Macintosh/Video.hpp @@ -12,13 +12,14 @@ #include "../../../Outputs/CRT/CRT.hpp" #include "../../../ClockReceiver/ClockReceiver.hpp" #include "DeferredAudio.hpp" +#include "DriveSpeedAccumulator.hpp" namespace Apple { namespace Macintosh { class Video { public: - Video(uint16_t *ram, DeferredAudio &audio); + Video(uint16_t *ram, DeferredAudio &audio, DriveSpeedAccumulator &drive_speed_accumulator); void set_scan_target(Outputs::Display::ScanTarget *scan_target); void run_for(HalfCycles duration); @@ -30,9 +31,10 @@ class Video { private: DeferredAudio &audio_; - uint16_t *ram_ = nullptr; + DriveSpeedAccumulator &drive_speed_accumulator_; Outputs::CRT::CRT crt_; + uint16_t *ram_ = nullptr; HalfCycles frame_position_; diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 55d44c5bb..6c8a4f7a1 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -586,6 +586,7 @@ 4BB299F81B587D8400A49093 /* txsn in Resources */ = {isa = PBXBuildFile; fileRef = 4BB298EC1B587D8400A49093 /* txsn */; }; 4BB299F91B587D8400A49093 /* tyan in Resources */ = {isa = PBXBuildFile; fileRef = 4BB298ED1B587D8400A49093 /* tyan */; }; 4BB2A9AF1E13367E001A5C23 /* CRCTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4BB2A9AE1E13367E001A5C23 /* CRCTests.mm */; }; + 4BB4BFAD22A33DE50069048D /* DriveSpeedAccumulator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BB4BFAC22A33DE50069048D /* DriveSpeedAccumulator.cpp */; }; 4BB697CB1D4B6D3E00248BDF /* TimedEventLoop.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BB697C91D4B6D3E00248BDF /* TimedEventLoop.cpp */; }; 4BB697CE1D4BA44400248BDF /* CommodoreGCR.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BB697CC1D4BA44400248BDF /* CommodoreGCR.cpp */; }; 4BB73EA21B587A5100552FC2 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BB73EA11B587A5100552FC2 /* AppDelegate.swift */; }; @@ -1329,6 +1330,8 @@ 4BB298ED1B587D8400A49093 /* tyan */ = {isa = PBXFileReference; lastKnownFileType = file; path = tyan; sourceTree = ""; }; 4BB2A9AE1E13367E001A5C23 /* CRCTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CRCTests.mm; sourceTree = ""; }; 4BB4BFAA22A300710069048D /* DeferredAudio.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = DeferredAudio.hpp; sourceTree = ""; }; + 4BB4BFAB22A33D710069048D /* DriveSpeedAccumulator.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = DriveSpeedAccumulator.hpp; sourceTree = ""; }; + 4BB4BFAC22A33DE50069048D /* DriveSpeedAccumulator.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = DriveSpeedAccumulator.cpp; sourceTree = ""; }; 4BB697C61D4B558F00248BDF /* Factors.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Factors.hpp; path = ../../NumberTheory/Factors.hpp; sourceTree = ""; }; 4BB697C91D4B6D3E00248BDF /* TimedEventLoop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TimedEventLoop.cpp; sourceTree = ""; }; 4BB697CA1D4B6D3E00248BDF /* TimedEventLoop.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = TimedEventLoop.hpp; sourceTree = ""; }; @@ -3070,10 +3073,12 @@ isa = PBXGroup; children = ( 4B9378E222A199C600973513 /* Audio.cpp */, + 4BB4BFAC22A33DE50069048D /* DriveSpeedAccumulator.cpp */, 4BCE0058227CFFCA000CA200 /* Macintosh.cpp */, 4BCE005E227D39AB000CA200 /* Video.cpp */, 4B9378E322A199C600973513 /* Audio.hpp */, 4BB4BFAA22A300710069048D /* DeferredAudio.hpp */, + 4BB4BFAB22A33D710069048D /* DriveSpeedAccumulator.hpp */, 4BDB3D8522833321002D3CEE /* Keyboard.hpp */, 4BCE0059227CFFCA000CA200 /* Macintosh.hpp */, 4BD0692B22828A2D00D2A54F /* RealTimeClock.hpp */, @@ -4011,6 +4016,7 @@ 4B622AE5222E0AD5008B59F2 /* DisplayMetrics.cpp in Sources */, 4B1497881EE4A1DA00CE2596 /* ZX80O81P.cpp in Sources */, 4B894520201967B4007DE474 /* StaticAnalyser.cpp in Sources */, + 4BB4BFAD22A33DE50069048D /* DriveSpeedAccumulator.cpp in Sources */, 4B2B3A4B1F9B8FA70062DABF /* Typer.cpp in Sources */, 4B4518821F75E91A00926311 /* PCMSegment.cpp in Sources */, 4B894522201967B4007DE474 /* StaticAnalyser.cpp in Sources */,