From ee8510984f314b5424fd38012b76a10c7036a64e Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Thu, 15 Sep 2016 19:34:45 -0400 Subject: [PATCH] Added just enough wiring to restore the 2600 to functionality. --- Machines/Atari2600/Atari2600.cpp | 8 ++++-- Machines/Atari2600/Atari2600.hpp | 8 ++++-- Machines/Electron/Electron.hpp | 1 - .../Clock Signal.xcodeproj/project.pbxproj | 14 ++++++++++ .../Documents/Atari2600Document.swift | 4 --- .../Machine/Wrappers/CSAtari2600.h | 1 - .../Machine/Wrappers/CSAtari2600.mm | 6 ---- StaticAnalyser/Atari/StaticAnalyser.cpp | 28 +++++++++++++++++++ StaticAnalyser/Atari/StaticAnalyser.hpp | 27 ++++++++++++++++++ StaticAnalyser/StaticAnalyser.cpp | 2 ++ 10 files changed, 83 insertions(+), 16 deletions(-) create mode 100644 StaticAnalyser/Atari/StaticAnalyser.cpp create mode 100644 StaticAnalyser/Atari/StaticAnalyser.hpp diff --git a/Machines/Atari2600/Atari2600.cpp b/Machines/Atari2600/Atari2600.cpp index 6d76cdadb..8970ad2d1 100644 --- a/Machines/Atari2600/Atari2600.cpp +++ b/Machines/Atari2600/Atari2600.cpp @@ -736,8 +736,12 @@ void Machine::set_switch_is_enabled(Atari2600Switch input, bool state) } } -void Machine::set_rom(size_t length, const uint8_t *data) +void Machine::configure_as_target(const StaticAnalyser::Target &target) { + if(!target.cartridges.front()->get_segments().size()) return; + Storage::Cartridge::Cartridge::Segment segment = target.cartridges.front()->get_segments().front(); + size_t length = segment.data.size(); + _rom_size = 1024; while(_rom_size < length && _rom_size < 32768) _rom_size <<= 1; @@ -750,7 +754,7 @@ void Machine::set_rom(size_t length, const uint8_t *data) while(offset < _rom_size) { size_t copy_length = std::min(copy_step, _rom_size - offset); - memcpy(&_rom[offset], data, copy_length); + memcpy(&_rom[offset], &segment.data[0], copy_length); offset += copy_length; } diff --git a/Machines/Atari2600/Atari2600.hpp b/Machines/Atari2600/Atari2600.hpp index 3b9fa0131..daeab499a 100644 --- a/Machines/Atari2600/Atari2600.hpp +++ b/Machines/Atari2600/Atari2600.hpp @@ -15,6 +15,7 @@ #include "../../Components/6532/6532.hpp" #include "../CRTMachine.hpp" +#include "../ConfigurationTarget.hpp" #include "Atari2600Inputs.h" namespace Atari2600 { @@ -72,13 +73,16 @@ class PIA: public MOS::MOS6532 { }; -class Machine: public CPU6502::Processor, public CRTMachine::Machine { +class Machine: + public CPU6502::Processor, + public CRTMachine::Machine, + public ConfigurationTarget::Machine { public: Machine(); ~Machine(); - void set_rom(size_t length, const uint8_t *data); + void configure_as_target(const StaticAnalyser::Target &target); void switch_region(); void set_digital_input(Atari2600DigitalInput input, bool state); diff --git a/Machines/Electron/Electron.hpp b/Machines/Electron/Electron.hpp index b22efe095..10a6f33b8 100644 --- a/Machines/Electron/Electron.hpp +++ b/Machines/Electron/Electron.hpp @@ -148,7 +148,6 @@ class Machine: void set_rom(ROMSlot slot, size_t length, const uint8_t *data); void configure_as_target(const StaticAnalyser::Target &target); -// void set_tape(std::shared_ptr tape); void set_key_state(Key key, bool isPressed); void clear_all_keys(); diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index 3caa89e2d..9cbe1041e 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -51,6 +51,7 @@ 4B92EACA1B7C112B00246143 /* 6502TimingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B92EAC91B7C112B00246143 /* 6502TimingTests.swift */; }; 4B96F7221D75119A0058BB2D /* Tape.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B96F7201D75119A0058BB2D /* Tape.cpp */; }; 4BA22B071D8817CE0008C640 /* Disk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BA22B051D8817CE0008C640 /* Disk.cpp */; }; + 4BA799951D8B656E0045123D /* StaticAnalyser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BA799931D8B656E0045123D /* StaticAnalyser.cpp */; }; 4BAB62AD1D3272D200DF5BA0 /* Disk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BAB62AB1D3272D200DF5BA0 /* Disk.cpp */; }; 4BAB62B51D327F7E00DF5BA0 /* G64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BAB62B31D327F7E00DF5BA0 /* G64.cpp */; }; 4BAB62B81D3302CA00DF5BA0 /* PCMTrack.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BAB62B61D3302CA00DF5BA0 /* PCMTrack.cpp */; }; @@ -458,6 +459,8 @@ 4B96F7211D75119A0058BB2D /* Tape.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Tape.hpp; path = ../../StaticAnalyser/Acorn/Tape.hpp; sourceTree = ""; }; 4BA22B051D8817CE0008C640 /* Disk.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Disk.cpp; path = ../../StaticAnalyser/Commodore/Disk.cpp; sourceTree = ""; }; 4BA22B061D8817CE0008C640 /* Disk.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Disk.hpp; path = ../../StaticAnalyser/Commodore/Disk.hpp; sourceTree = ""; }; + 4BA799931D8B656E0045123D /* StaticAnalyser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StaticAnalyser.cpp; path = ../../StaticAnalyser/Atari/StaticAnalyser.cpp; sourceTree = ""; }; + 4BA799941D8B656E0045123D /* StaticAnalyser.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = StaticAnalyser.hpp; path = ../../StaticAnalyser/Atari/StaticAnalyser.hpp; sourceTree = ""; }; 4BA9C3CF1D8164A9002DDB61 /* ConfigurationTarget.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ConfigurationTarget.hpp; sourceTree = ""; }; 4BAB62AB1D3272D200DF5BA0 /* Disk.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Disk.cpp; sourceTree = ""; }; 4BAB62AC1D3272D200DF5BA0 /* Disk.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Disk.hpp; sourceTree = ""; }; @@ -1074,6 +1077,15 @@ path = Formats; sourceTree = ""; }; + 4BA799961D8B65730045123D /* Atari */ = { + isa = PBXGroup; + children = ( + 4BA799931D8B656E0045123D /* StaticAnalyser.cpp */, + 4BA799941D8B656E0045123D /* StaticAnalyser.hpp */, + ); + name = Atari; + sourceTree = ""; + }; 4BAB62AA1D3272D200DF5BA0 /* Disk */ = { isa = PBXGroup; children = ( @@ -1627,6 +1639,7 @@ 4BF1354B1D6D2C300054B2EA /* StaticAnalyser.hpp */, 4BD328FD1D7E3EB5003B8C44 /* TapeParser.hpp */, 4BD14B121D7462810088EAD6 /* Acorn */, + 4BA799961D8B65730045123D /* Atari */, 4BC830D21D6E7C6D0000A26F /* Commodore */, ); name = StaticAnalyser; @@ -2048,6 +2061,7 @@ 4B0CCC451C62D0B3001CAC5F /* CRT.cpp in Sources */, 4B643F3F1D77B88000D431D6 /* DocumentController.swift in Sources */, 4BB697C71D4B558F00248BDF /* Factors.cpp in Sources */, + 4BA799951D8B656E0045123D /* StaticAnalyser.cpp in Sources */, 4B55CE591C3B7D360093A61B /* ElectronDocument.swift in Sources */, 4B4DC82B1D2C27A4003C5BF8 /* SerialBus.cpp in Sources */, 4BC3B74F1CD194CC00F86E85 /* Shader.cpp in Sources */, diff --git a/OSBindings/Mac/Clock Signal/Documents/Atari2600Document.swift b/OSBindings/Mac/Clock Signal/Documents/Atari2600Document.swift index be4448411..ac9cd7170 100644 --- a/OSBindings/Mac/Clock Signal/Documents/Atari2600Document.swift +++ b/OSBindings/Mac/Clock Signal/Documents/Atari2600Document.swift @@ -31,10 +31,6 @@ class Atari2600Document: MachineDocument { return "Atari2600Document" } - override func readFromData(data: NSData, ofType typeName: String) throws { - atari2600.setROM(data) - } - override func windowControllerDidLoadNib(aController: NSWindowController) { super.windowControllerDidLoadNib(aController) diff --git a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSAtari2600.h b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSAtari2600.h index 4e842c19a..3fa47b124 100644 --- a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSAtari2600.h +++ b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSAtari2600.h @@ -11,7 +11,6 @@ @interface CSAtari2600 : CSMachine -- (void)setROM:(nonnull NSData *)rom; - (void)setState:(BOOL)state forDigitalInput:(Atari2600DigitalInput)digitalInput; - (void)setResetLineEnabled:(BOOL)enabled; diff --git a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSAtari2600.mm b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSAtari2600.mm index ceb1c2a15..44a16dee9 100644 --- a/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSAtari2600.mm +++ b/OSBindings/Mac/Clock Signal/Machine/Wrappers/CSAtari2600.mm @@ -49,12 +49,6 @@ struct CRTDelegate: public Outputs::CRT::Delegate { } } -- (void)setROM:(NSData *)rom { - @synchronized(self) { - _atari2600.set_rom(rom.length, (const uint8_t *)rom.bytes); - } -} - - (void)setState:(BOOL)state forDigitalInput:(Atari2600DigitalInput)digitalInput { @synchronized(self) { _atari2600.set_digital_input(digitalInput, state ? true : false); diff --git a/StaticAnalyser/Atari/StaticAnalyser.cpp b/StaticAnalyser/Atari/StaticAnalyser.cpp new file mode 100644 index 000000000..231b40e6b --- /dev/null +++ b/StaticAnalyser/Atari/StaticAnalyser.cpp @@ -0,0 +1,28 @@ +// +// StaticAnalyser.cpp +// Clock Signal +// +// Created by Thomas Harte on 15/09/2016. +// Copyright © 2016 Thomas Harte. All rights reserved. +// + +#include "StaticAnalyser.hpp" + +using namespace StaticAnalyser::Atari; + +void StaticAnalyser::Atari::AddTargets( + const std::list> &disks, + const std::list> &tapes, + const std::list> &cartridges, + std::list &destination) +{ + // TODO: any sort of sanity checking at all; at the minute just trust the file type + // approximation already performed. + Target target; + target.machine = Target::Atari2600; + target.probability = 1.0; + target.disks = disks; + target.tapes = tapes; + target.cartridges = cartridges; + destination.push_back(target); +} diff --git a/StaticAnalyser/Atari/StaticAnalyser.hpp b/StaticAnalyser/Atari/StaticAnalyser.hpp new file mode 100644 index 000000000..d6fc23ef1 --- /dev/null +++ b/StaticAnalyser/Atari/StaticAnalyser.hpp @@ -0,0 +1,27 @@ +// +// StaticAnalyser.hpp +// Clock Signal +// +// Created by Thomas Harte on 15/09/2016. +// Copyright © 2016 Thomas Harte. All rights reserved. +// + +#ifndef StaticAnalyser_Atari_StaticAnalyser_hpp +#define StaticAnalyser_Atari_StaticAnalyser_hpp + +#include "../StaticAnalyser.hpp" + +namespace StaticAnalyser { +namespace Atari { + +void AddTargets( + const std::list> &disks, + const std::list> &tapes, + const std::list> &cartridges, + std::list &destination +); + +} +} + +#endif /* StaticAnalyser_hpp */ diff --git a/StaticAnalyser/StaticAnalyser.cpp b/StaticAnalyser/StaticAnalyser.cpp index 5e8af04d6..2f57788f2 100644 --- a/StaticAnalyser/StaticAnalyser.cpp +++ b/StaticAnalyser/StaticAnalyser.cpp @@ -12,6 +12,7 @@ // Analysers #include "Acorn/StaticAnalyser.hpp" +#include "Atari/StaticAnalyser.hpp" #include "Commodore/StaticAnalyser.hpp" // Cartridges @@ -109,6 +110,7 @@ std::list StaticAnalyser::GetTargets(const char *file_name) // if so, how to load them. (TODO) if(potential_platforms & (TargetPlatformType)TargetPlatform::Acorn) Acorn::AddTargets(disks, tapes, cartridges, targets); if(potential_platforms & (TargetPlatformType)TargetPlatform::Commodore) Commodore::AddTargets(disks, tapes, cartridges, targets); + if(potential_platforms & (TargetPlatformType)TargetPlatform::Atari2600) Atari::AddTargets(disks, tapes, cartridges, targets); free(lowercase_extension); return targets;