From 7be3578497084155a5f3c1ded50def0aa2cc4de8 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 9 Nov 2021 07:11:23 -0500 Subject: [PATCH] Adds a target for audio writes. --- Machines/Amiga/Audio.cpp | 27 ++++++++++++ Machines/Amiga/Audio.hpp | 30 +++++++++++++ Machines/Amiga/Chipset.cpp | 44 ++++++++++++++----- Machines/Amiga/Chipset.hpp | 5 +++ .../Clock Signal.xcodeproj/project.pbxproj | 8 ++++ 5 files changed, 102 insertions(+), 12 deletions(-) create mode 100644 Machines/Amiga/Audio.cpp create mode 100644 Machines/Amiga/Audio.hpp diff --git a/Machines/Amiga/Audio.cpp b/Machines/Amiga/Audio.cpp new file mode 100644 index 000000000..2a0a2ea02 --- /dev/null +++ b/Machines/Amiga/Audio.cpp @@ -0,0 +1,27 @@ +// +// Audio.cpp +// Clock Signal +// +// Created by Thomas Harte on 09/11/2021. +// Copyright © 2021 Thomas Harte. All rights reserved. +// + +#include "Audio.hpp" + +using namespace Amiga; + +bool Audio::advance(int) { + return false; +} + +void Audio::set_length(int, uint16_t) { +} + +void Audio::set_period(int, uint16_t) { +} + +void Audio::set_volume(int, uint16_t) { +} + +void Audio::set_data(int, uint16_t) { +} diff --git a/Machines/Amiga/Audio.hpp b/Machines/Amiga/Audio.hpp new file mode 100644 index 000000000..86931ebe9 --- /dev/null +++ b/Machines/Amiga/Audio.hpp @@ -0,0 +1,30 @@ +// +// Audio.hpp +// Clock Signal +// +// Created by Thomas Harte on 09/11/2021. +// Copyright © 2021 Thomas Harte. All rights reserved. +// + +#ifndef Audio_hpp +#define Audio_hpp + +#include "DMADevice.hpp" + +namespace Amiga { + +class Audio: public DMADevice<4> { + public: + using DMADevice::DMADevice; + + bool advance(int channel); + + void set_length(int, uint16_t); + void set_period(int, uint16_t); + void set_volume(int, uint16_t); + void set_data(int, uint16_t); +}; + +} + +#endif /* Audio_hpp */ diff --git a/Machines/Amiga/Chipset.cpp b/Machines/Amiga/Chipset.cpp index f945eb1db..f071002d4 100644 --- a/Machines/Amiga/Chipset.cpp +++ b/Machines/Amiga/Chipset.cpp @@ -73,6 +73,7 @@ Chipset::Chipset(MemoryMap &map, int input_clock_rate) : }, bitplanes_(DMA_CONSTRUCT), copper_(DMA_CONSTRUCT), + audio_(DMA_CONSTRUCT), crt_(908, 4, Outputs::Display::Type::PAL50, Outputs::Display::InputDataType::Red4Green4Blue4), cia_a_handler_(map, disk_controller_, mouse_), cia_b_handler_(disk_controller_), @@ -316,6 +317,12 @@ void Chipset::flush_output() { /// @returns @c true if this was a CPU slot; @c false otherwise. template bool Chipset::perform_cycle() { + constexpr uint16_t AudioFlags[] = { + DMAMask::value, + DMAMask::value, + DMAMask::value, + DMAMask::value, + }; constexpr auto BlitterFlag = DMAMask::value; constexpr auto BitplaneFlag = DMAMask::value; constexpr auto CopperFlag = DMAMask::value; @@ -358,7 +365,16 @@ template bool Chipset::perform_cycle() { } } - if constexpr(cycle >= 0x15 && cycle < 0x35) { + if constexpr (cycle >= 0xd && cycle < 0x14) { + constexpr auto channel = (cycle - 0xd) >> 1; + if((dma_control_ & AudioFlags[channel]) == AudioFlags[channel]) { + if(audio_.advance(channel)) { + return false; + } + } + } + + if constexpr (cycle >= 0x15 && cycle < 0x35) { if((dma_control_ & SpritesFlag) == SpritesFlag) { constexpr auto sprite_id = (cycle - 0x15) >> 2; if(sprites_[sprite_id].advance(y_)) { @@ -850,17 +866,21 @@ void Chipset::perform(const CPU::MC68000::Microcycle &cycle) { case Write(0x072): blitter_.set_data(1, cycle.value16()); break; case Write(0x074): blitter_.set_data(0, cycle.value16()); break; - // Paula. - case Write(0x0a0): case Write(0x0a2): case Write(0x0a4): case Write(0x0a6): - case Write(0x0a8): case Write(0x0aa): - case Write(0x0b0): case Write(0x0b2): case Write(0x0b4): case Write(0x0b6): - case Write(0x0b8): case Write(0x0ba): - case Write(0x0c0): case Write(0x0c2): case Write(0x0c4): case Write(0x0c6): - case Write(0x0c8): case Write(0x0ca): - case Write(0x0d0): case Write(0x0d2): case Write(0x0d4): case Write(0x0d6): - case Write(0x0d8): case Write(0x0da): - LOG("TODO: Paula write " << PADHEX(2) << (*cycle.address & 0xff) << " " << PADHEX(4) << cycle.value16()); - break; + // Audio. +#define Audio(index, pointer) \ + case Write(pointer + 0): audio_.set_pointer(cycle.value16()); break; \ + case Write(pointer + 2): audio_.set_pointer(cycle.value16()); break; \ + case Write(pointer + 4): audio_.set_length(index, cycle.value16()); break; \ + case Write(pointer + 6): audio_.set_period(index, cycle.value16()); break; \ + case Write(pointer + 8): audio_.set_volume(index, cycle.value16()); break; \ + case Write(pointer + 10): audio_.set_data(index, cycle.value16()); break; \ + + Audio(0, 0x0a0); + Audio(1, 0x0b0); + Audio(2, 0x0c0); + Audio(3, 0x0d0); + +#undef Audio // Copper. case Write(0x02e): copper_.set_control(cycle.value16()); break; // COPCON diff --git a/Machines/Amiga/Chipset.hpp b/Machines/Amiga/Chipset.hpp index 00e051397..a2b15f2d0 100644 --- a/Machines/Amiga/Chipset.hpp +++ b/Machines/Amiga/Chipset.hpp @@ -24,6 +24,7 @@ #include "../../Storage/Disk/Controller/DiskController.hpp" #include "../../Storage/Disk/Drive.hpp" +#include "Audio.hpp" #include "Blitter.hpp" #include "Copper.hpp" #include "DMADevice.hpp" @@ -305,6 +306,10 @@ class Chipset: private ClockingHint::Observer { Copper copper_; + // MARK: - Audio. + + Audio audio_; + // MARK: - Serial port. class SerialPort { diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 4f563e6c8..45dedb34d 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -182,6 +182,8 @@ 4B1EC716255398B000A1F44B /* Sound.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B1EC714255398B000A1F44B /* Sound.cpp */; }; 4B1EC717255398B000A1F44B /* Sound.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B1EC714255398B000A1F44B /* Sound.cpp */; }; 4B1EDB451E39A0AC009D6819 /* chip.png in Resources */ = {isa = PBXBuildFile; fileRef = 4B1EDB431E39A0AC009D6819 /* chip.png */; }; + 4B2130E2273A7A0A008A77B4 /* Audio.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B2130E0273A7A0A008A77B4 /* Audio.cpp */; }; + 4B2130E3273A7A0A008A77B4 /* Audio.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B2130E0273A7A0A008A77B4 /* Audio.cpp */; }; 4B228CD524D773B40077EF25 /* CSScanTarget.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4B228CD424D773B30077EF25 /* CSScanTarget.mm */; }; 4B228CD924DA12C60077EF25 /* CSScanTargetView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B228CD824DA12C60077EF25 /* CSScanTargetView.m */; }; 4B228CDB24DA41890077EF25 /* ScanTarget.metal in Sources */ = {isa = PBXBuildFile; fileRef = 4B228CDA24DA41880077EF25 /* ScanTarget.metal */; }; @@ -1183,6 +1185,8 @@ 4B1EC714255398B000A1F44B /* Sound.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Sound.cpp; sourceTree = ""; }; 4B1EC715255398B000A1F44B /* Sound.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Sound.hpp; sourceTree = ""; }; 4B1EDB431E39A0AC009D6819 /* chip.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = chip.png; sourceTree = ""; }; + 4B2130E0273A7A0A008A77B4 /* Audio.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Audio.cpp; sourceTree = ""; }; + 4B2130E1273A7A0A008A77B4 /* Audio.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Audio.hpp; sourceTree = ""; }; 4B228CD424D773B30077EF25 /* CSScanTarget.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CSScanTarget.mm; sourceTree = ""; }; 4B228CD624D773CA0077EF25 /* CSScanTarget.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CSScanTarget.h; sourceTree = ""; }; 4B228CD724DA12C50077EF25 /* CSScanTargetView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSScanTargetView.h; sourceTree = ""; }; @@ -4301,12 +4305,14 @@ isa = PBXGroup; children = ( 4BC080D826A25ADA00D03FD8 /* Amiga.cpp */, + 4B2130E0273A7A0A008A77B4 /* Audio.cpp */, 4B9EC0E126AA27BA0060A31F /* Blitter.cpp */, 4B9EC0E426AA4A660060A31F /* Chipset.cpp */, 4BC6236C26F4235400F83DFE /* Copper.cpp */, 4B1A1B1C27320FBB00119335 /* Disk.cpp */, 4B9EC0E826B384080060A31F /* Keyboard.cpp */, 4BC080D726A25ADA00D03FD8 /* Amiga.hpp */, + 4B2130E1273A7A0A008A77B4 /* Audio.hpp */, 4B9EC0E026AA260C0060A31F /* Blitter.hpp */, 4B9EC0E526AA4A660060A31F /* Chipset.hpp */, 4BC6236B26F4224300F83DFE /* Copper.hpp */, @@ -5477,6 +5483,7 @@ 4BE0A3EF237BB170002AB46F /* ST.cpp in Sources */, 4B055A971FAE85BB0060FFFF /* ZX8081.cpp in Sources */, 4B055AAD1FAE85FD0060FFFF /* PCMTrack.cpp in Sources */, + 4B2130E3273A7A0A008A77B4 /* Audio.cpp in Sources */, 4BD67DD1209BF27B00AB2146 /* Encoder.cpp in Sources */, 4BE2121A253FCE9C00435408 /* AppleIIgs.cpp in Sources */, 4B051CAD26783E2000CA44E8 /* Nick.cpp in Sources */, @@ -5593,6 +5600,7 @@ 4B89453C201967B4007DE474 /* StaticAnalyser.cpp in Sources */, 4B595FAD2086DFBA0083CAA8 /* AudioToggle.cpp in Sources */, 4B2E86BE25D74F160024F1E9 /* Mouse.cpp in Sources */, + 4B2130E2273A7A0A008A77B4 /* Audio.cpp in Sources */, 4B643F3F1D77B88000D431D6 /* DocumentController.swift in Sources */, 4BDA00E422E663B900AC3CD0 /* NSData+CRC32.m in Sources */, 4B9EC0E626AA4A660060A31F /* Chipset.cpp in Sources */,