From e9318efeb604147125a8eb82649b1dbccfd21b36 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 21 Dec 2019 23:34:25 -0500 Subject: [PATCH 1/4] Switches to std::make_shared/make_unique in a bunch of applicable places. No doubt many more similar improvements are available, these are just the ones that were easy to find. --- Analyser/Static/AppleII/StaticAnalyser.cpp | 2 +- Configurable/StandardOptions.cpp | 4 ++-- .../xcshareddata/xcschemes/Clock Signal.xcscheme | 2 +- OSBindings/SDL/main.cpp | 3 +-- Outputs/OpenGL/ScanTargetGLSLFragments.cpp | 12 ++++++------ Storage/Disk/DiskImage/Formats/D64.cpp | 2 +- Storage/Disk/DiskImage/Formats/WOZ.cpp | 2 +- Storage/Disk/Encodings/MFM/Encoder.cpp | 6 +++--- 8 files changed, 16 insertions(+), 17 deletions(-) diff --git a/Analyser/Static/AppleII/StaticAnalyser.cpp b/Analyser/Static/AppleII/StaticAnalyser.cpp index 6c09bb6b0..b0b280fb1 100644 --- a/Analyser/Static/AppleII/StaticAnalyser.cpp +++ b/Analyser/Static/AppleII/StaticAnalyser.cpp @@ -10,7 +10,7 @@ #include "Target.hpp" Analyser::Static::TargetList Analyser::Static::AppleII::GetTargets(const Media &media, const std::string &file_name, TargetPlatform::IntType potential_platforms) { - auto target = std::unique_ptr(new Target); + auto target = std::make_unique(); target->machine = Machine::AppleII; target->media = media; diff --git a/Configurable/StandardOptions.cpp b/Configurable/StandardOptions.cpp index 7f140557f..1cb0badf2 100644 --- a/Configurable/StandardOptions.cpp +++ b/Configurable/StandardOptions.cpp @@ -14,7 +14,7 @@ namespace { Appends a Boolean selection of @c selection for option @c name to @c selection_set. */ void append_bool(Configurable::SelectionSet &selection_set, const std::string &name, bool selection) { - selection_set[name] = std::unique_ptr(new Configurable::BooleanSelection(selection)); + selection_set[name] = std::make_unique(selection); } /*! @@ -64,7 +64,7 @@ void Configurable::append_display_selection(Configurable::SelectionSet &selectio case Display::CompositeMonochrome: string_selection = "composite-mono"; break; case Display::CompositeColour: string_selection = "composite"; break; } - selection_set["display"] = std::unique_ptr(new Configurable::ListSelection(string_selection)); + selection_set["display"] = std::make_unique(string_selection); } void Configurable::append_quick_boot_selection(Configurable::SelectionSet &selection_set, bool selection) { diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme b/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme index 7b1a6914b..175c1d515 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme +++ b/OSBindings/Mac/Clock Signal.xcodeproj/xcshareddata/xcschemes/Clock Signal.xcscheme @@ -67,7 +67,7 @@ (new Outputs::Display::OpenGL::Rectangle(right_x, y, width, height)))); + lights_.emplace(std::make_pair(drive, std::make_unique(right_x, y, width, height))); y -= height * 2.0f; } diff --git a/Outputs/OpenGL/ScanTargetGLSLFragments.cpp b/Outputs/OpenGL/ScanTargetGLSLFragments.cpp index 1d5d3ca14..cf18e6c26 100644 --- a/Outputs/OpenGL/ScanTargetGLSLFragments.cpp +++ b/Outputs/OpenGL/ScanTargetGLSLFragments.cpp @@ -470,11 +470,11 @@ std::unique_ptr ScanTarget::conversion_shader() const { "fragColour = vec4(fragColour3, 0.64);" "}"; - return std::unique_ptr(new Shader( + return std::make_unique( vertex_shader, fragment_shader, bindings(ShaderType::Conversion) - )); + ); } std::unique_ptr ScanTarget::composition_shader() const { @@ -544,11 +544,11 @@ std::unique_ptr ScanTarget::composition_shader() const { break; } - return std::unique_ptr(new Shader( + return std::make_unique( vertex_shader, fragment_shader + "}", bindings(ShaderType::Composition) - )); + ); } std::unique_ptr ScanTarget::qam_separation_shader() const { @@ -656,9 +656,9 @@ std::unique_ptr ScanTarget::qam_separation_shader() const { "fragColour = fragColour*0.5 + vec4(0.5);" "}"; - return std::unique_ptr(new Shader( + return std::make_unique( vertex_shader, fragment_shader, bindings(ShaderType::QAMSeparation) - )); + ); } diff --git a/Storage/Disk/DiskImage/Formats/D64.cpp b/Storage/Disk/DiskImage/Formats/D64.cpp index 35f277af1..2620fc876 100644 --- a/Storage/Disk/DiskImage/Formats/D64.cpp +++ b/Storage/Disk/DiskImage/Formats/D64.cpp @@ -136,5 +136,5 @@ std::shared_ptr D64::get_track_at_position(Track::Address address) { Encodings::CommodoreGCR::encode_block(§or_data[target_data_offset], end_of_data); } - return std::shared_ptr(new PCMTrack(PCMSegment(data))); + return std::make_shared(PCMSegment(data)); } diff --git a/Storage/Disk/DiskImage/Formats/WOZ.cpp b/Storage/Disk/DiskImage/Formats/WOZ.cpp index 80a54ef5f..1b2659134 100644 --- a/Storage/Disk/DiskImage/Formats/WOZ.cpp +++ b/Storage/Disk/DiskImage/Formats/WOZ.cpp @@ -121,7 +121,7 @@ std::shared_ptr WOZ::get_track_at_position(Track::Address address) { number_of_bits = std::min(file_.get16le(), static_cast(6646*8)); } - return std::shared_ptr(new PCMTrack(PCMSegment(number_of_bits, track_contents))); + return std::make_shared(PCMSegment(number_of_bits, track_contents)); } void WOZ::set_tracks(const std::map> &tracks) { diff --git a/Storage/Disk/Encodings/MFM/Encoder.cpp b/Storage/Disk/Encodings/MFM/Encoder.cpp index 122010952..0c8bc8c9e 100644 --- a/Storage/Disk/Encodings/MFM/Encoder.cpp +++ b/Storage/Disk/Encodings/MFM/Encoder.cpp @@ -236,7 +236,7 @@ template std::shared_ptr // Allow the amount of data written to be up to 10% more than the expected size. Which is generous. if(segment.data.size() > max_size) segment.data.resize(max_size); - return std::shared_ptr(new Storage::Disk::PCMTrack(std::move(segment))); + return std::make_shared(std::move(segment)); } Encoder::Encoder(std::vector &target) : @@ -311,9 +311,9 @@ std::shared_ptr Storage::Encodings::MFM::GetMFMTrackWithSe } std::unique_ptr Storage::Encodings::MFM::GetMFMEncoder(std::vector &target) { - return std::unique_ptr(new MFMEncoder(target)); + return std::make_unique(target); } std::unique_ptr Storage::Encodings::MFM::GetFMEncoder(std::vector &target) { - return std::unique_ptr(new FMEncoder(target)); + return std::make_unique(target); } From 05d77d3297501c5c74eff34d267baf0ddb3cd026 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 21 Dec 2019 23:52:04 -0500 Subject: [PATCH 2/4] Also deploys make_unique/shared to avoid type repetition. --- Analyser/Static/Acorn/Disk.cpp | 4 +- Analyser/Static/Acorn/StaticAnalyser.cpp | 2 +- Analyser/Static/Acorn/Tape.cpp | 4 +- Analyser/Static/AmstradCPC/StaticAnalyser.cpp | 2 +- Analyser/Static/Atari2600/StaticAnalyser.cpp | 2 +- Analyser/Static/Coleco/StaticAnalyser.cpp | 2 +- Analyser/Static/Commodore/Disk.cpp | 2 +- Analyser/Static/Commodore/StaticAnalyser.cpp | 2 +- Analyser/Static/MSX/StaticAnalyser.cpp | 4 +- Analyser/Static/Oric/StaticAnalyser.cpp | 2 +- Analyser/Static/Sega/StaticAnalyser.cpp | 2 +- Concurrency/AsyncTaskQueue.cpp | 4 +- Machines/Commodore/Vic-20/Vic20.cpp | 3 +- Machines/Electron/Electron.cpp | 3 +- Machines/ZX8081/ZX8081.cpp | 3 +- .../Mac/Clock Signal/Machine/CSROMFetcher.mm | 2 +- .../StaticAnalyser/CSStaticAnalyser.mm | 20 ++--- OSBindings/SDL/main.cpp | 2 +- Storage/Data/ZX8081.cpp | 4 +- Storage/Tape/Parsers/Commodore.cpp | 82 +++++++------------ Storage/Tape/Parsers/MSX.cpp | 2 +- Storage/Tape/Parsers/ZX8081.cpp | 2 +- 22 files changed, 63 insertions(+), 92 deletions(-) diff --git a/Analyser/Static/Acorn/Disk.cpp b/Analyser/Static/Acorn/Disk.cpp index ac359ec3c..ff4327b91 100644 --- a/Analyser/Static/Acorn/Disk.cpp +++ b/Analyser/Static/Acorn/Disk.cpp @@ -18,7 +18,7 @@ using namespace Analyser::Static::Acorn; std::unique_ptr Analyser::Static::Acorn::GetDFSCatalogue(const std::shared_ptr &disk) { // c.f. http://beebwiki.mdfs.net/Acorn_DFS_disc_format - std::unique_ptr catalogue(new Catalogue); + auto catalogue = std::make_unique(); Storage::Encodings::MFM::Parser parser(false, disk); Storage::Encodings::MFM::Sector *names = parser.get_sector(0, 0, 0); @@ -75,7 +75,7 @@ std::unique_ptr Analyser::Static::Acorn::GetDFSCatalogue(const std::s return catalogue; } std::unique_ptr Analyser::Static::Acorn::GetADFSCatalogue(const std::shared_ptr &disk) { - std::unique_ptr catalogue(new Catalogue); + auto catalogue = std::make_unique(); Storage::Encodings::MFM::Parser parser(true, disk); Storage::Encodings::MFM::Sector *free_space_map_second_half = parser.get_sector(0, 0, 1); diff --git a/Analyser/Static/Acorn/StaticAnalyser.cpp b/Analyser/Static/Acorn/StaticAnalyser.cpp index 9d74a094a..252176f56 100644 --- a/Analyser/Static/Acorn/StaticAnalyser.cpp +++ b/Analyser/Static/Acorn/StaticAnalyser.cpp @@ -58,7 +58,7 @@ static std::vector> } Analyser::Static::TargetList Analyser::Static::Acorn::GetTargets(const Media &media, const std::string &file_name, TargetPlatform::IntType potential_platforms) { - std::unique_ptr target(new Target); + auto target = std::make_unique(); target->machine = Machine::Electron; target->confidence = 0.5; // TODO: a proper estimation target->has_dfs = false; diff --git a/Analyser/Static/Acorn/Tape.cpp b/Analyser/Static/Acorn/Tape.cpp index ca8eba1b0..43f71e69e 100644 --- a/Analyser/Static/Acorn/Tape.cpp +++ b/Analyser/Static/Acorn/Tape.cpp @@ -16,7 +16,7 @@ using namespace Analyser::Static::Acorn; static std::unique_ptr GetNextChunk(const std::shared_ptr &tape, Storage::Tape::Acorn::Parser &parser) { - std::unique_ptr new_chunk(new File::Chunk); + auto new_chunk = std::make_unique(); int shift_register = 0; // TODO: move this into the parser @@ -90,7 +90,7 @@ static std::unique_ptr GetNextFile(std::deque &chunks) { if(!chunks.size()) return nullptr; // accumulate chunks for as long as block number is sequential and the end-of-file bit isn't set - std::unique_ptr file(new File); + auto file = std::make_unique(); uint16_t block_number = 0; diff --git a/Analyser/Static/AmstradCPC/StaticAnalyser.cpp b/Analyser/Static/AmstradCPC/StaticAnalyser.cpp index ee95fd072..7efadf16d 100644 --- a/Analyser/Static/AmstradCPC/StaticAnalyser.cpp +++ b/Analyser/Static/AmstradCPC/StaticAnalyser.cpp @@ -181,7 +181,7 @@ static bool CheckBootSector(const std::shared_ptr &disk, co Analyser::Static::TargetList Analyser::Static::AmstradCPC::GetTargets(const Media &media, const std::string &file_name, TargetPlatform::IntType potential_platforms) { TargetList destination; - std::unique_ptr target(new Target); + auto target = std::make_unique(); target->machine = Machine::AmstradCPC; target->confidence = 0.5; diff --git a/Analyser/Static/Atari2600/StaticAnalyser.cpp b/Analyser/Static/Atari2600/StaticAnalyser.cpp index 74d048cd5..cd756e59e 100644 --- a/Analyser/Static/Atari2600/StaticAnalyser.cpp +++ b/Analyser/Static/Atari2600/StaticAnalyser.cpp @@ -183,7 +183,7 @@ static void DeterminePagingForCartridge(Target &target, const Storage::Cartridge Analyser::Static::TargetList Analyser::Static::Atari2600::GetTargets(const Media &media, const std::string &file_name, TargetPlatform::IntType potential_platforms) { // TODO: sanity checking; is this image really for an Atari 2600? - std::unique_ptr target(new Target); + auto target = std::make_unique(); target->machine = Machine::Atari2600; target->confidence = 0.5; target->media.cartridges = media.cartridges; diff --git a/Analyser/Static/Coleco/StaticAnalyser.cpp b/Analyser/Static/Coleco/StaticAnalyser.cpp index 157e51f96..25f69e926 100644 --- a/Analyser/Static/Coleco/StaticAnalyser.cpp +++ b/Analyser/Static/Coleco/StaticAnalyser.cpp @@ -54,7 +54,7 @@ static std::vector> Analyser::Static::TargetList Analyser::Static::Coleco::GetTargets(const Media &media, const std::string &file_name, TargetPlatform::IntType potential_platforms) { TargetList targets; - std::unique_ptr target(new Target); + auto target = std::make_unique(); target->machine = Machine::ColecoVision; target->confidence = 1.0f - 1.0f / 32768.0f; target->media.cartridges = ColecoCartridgesFrom(media.cartridges); diff --git a/Analyser/Static/Commodore/Disk.cpp b/Analyser/Static/Commodore/Disk.cpp index 0a47a8d8c..07b3cfe74 100644 --- a/Analyser/Static/Commodore/Disk.cpp +++ b/Analyser/Static/Commodore/Disk.cpp @@ -125,7 +125,7 @@ class CommodoreGCRParser: public Storage::Disk::Controller { } std::shared_ptr get_next_sector() { - std::shared_ptr sector(new Sector); + auto sector = std::make_shared(); const int max_index_count = index_count_ + 2; while(index_count_ < max_index_count) { diff --git a/Analyser/Static/Commodore/StaticAnalyser.cpp b/Analyser/Static/Commodore/StaticAnalyser.cpp index 789db5c0f..b7e63f160 100644 --- a/Analyser/Static/Commodore/StaticAnalyser.cpp +++ b/Analyser/Static/Commodore/StaticAnalyser.cpp @@ -44,7 +44,7 @@ static std::vector> Analyser::Static::TargetList Analyser::Static::Commodore::GetTargets(const Media &media, const std::string &file_name, TargetPlatform::IntType potential_platforms) { TargetList destination; - std::unique_ptr target(new Target); + auto target = std::make_unique(); target->machine = Machine::Vic20; // TODO: machine estimation target->confidence = 0.5; // TODO: a proper estimation diff --git a/Analyser/Static/MSX/StaticAnalyser.cpp b/Analyser/Static/MSX/StaticAnalyser.cpp index 79a869ccd..a20350ca9 100644 --- a/Analyser/Static/MSX/StaticAnalyser.cpp +++ b/Analyser/Static/MSX/StaticAnalyser.cpp @@ -34,7 +34,7 @@ static std::unique_ptr CartridgeTarget( output_segments.emplace_back(start_address, segment.data); } - std::unique_ptr target(new Analyser::Static::MSX::Target); + auto target = std::make_unique(); target->machine = Analyser::Machine::MSX; target->confidence = confidence; @@ -269,7 +269,7 @@ Analyser::Static::TargetList Analyser::Static::MSX::GetTargets(const Media &medi std::move(cartridge_targets.begin(), cartridge_targets.end(), std::back_inserter(destination)); // Consider building a target for disks and/or tapes. - std::unique_ptr target(new Target); + auto target = std::make_unique(); // Check tapes for loadable files. for(auto &tape : media.tapes) { diff --git a/Analyser/Static/Oric/StaticAnalyser.cpp b/Analyser/Static/Oric/StaticAnalyser.cpp index 2ec0457c0..854c2cabb 100644 --- a/Analyser/Static/Oric/StaticAnalyser.cpp +++ b/Analyser/Static/Oric/StaticAnalyser.cpp @@ -101,7 +101,7 @@ static bool IsMicrodisc(Storage::Encodings::MFM::Parser &parser) { } Analyser::Static::TargetList Analyser::Static::Oric::GetTargets(const Media &media, const std::string &file_name, TargetPlatform::IntType potential_platforms) { - std::unique_ptr target(new Target); + auto target = std::make_unique(); target->machine = Machine::Oric; target->confidence = 0.5; diff --git a/Analyser/Static/Sega/StaticAnalyser.cpp b/Analyser/Static/Sega/StaticAnalyser.cpp index 038be85be..37b9d54d4 100644 --- a/Analyser/Static/Sega/StaticAnalyser.cpp +++ b/Analyser/Static/Sega/StaticAnalyser.cpp @@ -18,7 +18,7 @@ Analyser::Static::TargetList Analyser::Static::Sega::GetTargets(const Media &med return {}; TargetList targets; - std::unique_ptr target(new Target); + auto target = std::make_unique(); target->machine = Machine::MasterSystem; diff --git a/Concurrency/AsyncTaskQueue.cpp b/Concurrency/AsyncTaskQueue.cpp index 838e1fbf1..fc3b885c3 100644 --- a/Concurrency/AsyncTaskQueue.cpp +++ b/Concurrency/AsyncTaskQueue.cpp @@ -70,8 +70,8 @@ void AsyncTaskQueue::flush() { #ifdef __APPLE__ dispatch_sync(serial_dispatch_queue_, ^{}); #else - std::shared_ptr flush_mutex(new std::mutex); - std::shared_ptr flush_condition(new std::condition_variable); + auto flush_mutex = std::make_shared(); + auto flush_condition = std::make_shared(); std::unique_lock lock(*flush_mutex); enqueue([=] () { std::unique_lock inner_lock(*flush_mutex); diff --git a/Machines/Commodore/Vic-20/Vic20.cpp b/Machines/Commodore/Vic-20/Vic20.cpp index cb7682c80..3faf30930 100644 --- a/Machines/Commodore/Vic-20/Vic20.cpp +++ b/Machines/Commodore/Vic-20/Vic20.cpp @@ -646,8 +646,7 @@ class ConcreteMachine: } void type_string(const std::string &string) override final { - std::unique_ptr mapper(new CharacterMapper()); - Utility::TypeRecipient::add_typer(string, std::move(mapper)); + Utility::TypeRecipient::add_typer(string, std::make_unique()); } void tape_did_change_input(Storage::Tape::BinaryTapePlayer *tape) override final { diff --git a/Machines/Electron/Electron.cpp b/Machines/Electron/Electron.cpp index 1370cf3c0..98b3eb2e4 100644 --- a/Machines/Electron/Electron.cpp +++ b/Machines/Electron/Electron.cpp @@ -409,8 +409,7 @@ class ConcreteMachine: } void type_string(const std::string &string) override final { - std::unique_ptr mapper(new CharacterMapper()); - Utility::TypeRecipient::add_typer(string, std::move(mapper)); + Utility::TypeRecipient::add_typer(string, std::make_unique()); } KeyboardMapper *get_keyboard_mapper() override { diff --git a/Machines/ZX8081/ZX8081.cpp b/Machines/ZX8081/ZX8081.cpp index c06bd8d10..f0de30e17 100644 --- a/Machines/ZX8081/ZX8081.cpp +++ b/Machines/ZX8081/ZX8081.cpp @@ -336,8 +336,7 @@ template class ConcreteMachine: } void type_string(const std::string &string) override final { - std::unique_ptr mapper(new CharacterMapper(is_zx81)); - Utility::TypeRecipient::add_typer(string, std::move(mapper)); + Utility::TypeRecipient::add_typer(string, std::make_unique(is_zx81)); } // MARK: - Keyboard diff --git a/OSBindings/Mac/Clock Signal/Machine/CSROMFetcher.mm b/OSBindings/Mac/Clock Signal/Machine/CSROMFetcher.mm index 474a36b41..b1f36c455 100644 --- a/OSBindings/Mac/Clock Signal/Machine/CSROMFetcher.mm +++ b/OSBindings/Mac/Clock Signal/Machine/CSROMFetcher.mm @@ -48,7 +48,7 @@ ROMMachine::ROMFetcher CSROMFetcher(std::vector *missing_roms) } } else { - std::unique_ptr> data(new std::vector); + auto data = std::make_unique>(); *data = fileData.stdVector8; results.emplace_back(std::move(data)); } diff --git a/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.mm b/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.mm index a73c3e4ea..2caaea298 100644 --- a/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.mm +++ b/OSBindings/Mac/Clock Signal/Machine/StaticAnalyser/CSStaticAnalyser.mm @@ -45,7 +45,7 @@ self = [super init]; if(self) { using Target = Analyser::Static::Acorn::Target; - std::unique_ptr target(new Target); + auto target = std::make_unique(); target->machine = Analyser::Machine::Electron; target->has_dfs = !!dfs; target->has_adfs = !!adfs; @@ -58,7 +58,7 @@ self = [super init]; if(self) { using Target = Analyser::Static::AmstradCPC::Target; - std::unique_ptr target(new Target); + auto target = std::make_unique(); target->machine = Analyser::Machine::AmstradCPC; switch(model) { case CSMachineCPCModel464: target->model = Analyser::Static::AmstradCPC::Target::Model::CPC464; break; @@ -74,7 +74,7 @@ self = [super init]; if(self) { using Target = Analyser::Static::MSX::Target; - std::unique_ptr target(new Target); + auto target = std::make_unique(); target->machine = Analyser::Machine::MSX; target->has_disk_drive = !!hasDiskDrive; switch(region) { @@ -91,7 +91,7 @@ self = [super init]; if(self) { using Target = Analyser::Static::Oric::Target; - std::unique_ptr target(new Target); + auto target = std::make_unique(); target->machine = Analyser::Machine::Oric; switch(model) { case CSMachineOricModelOric1: target->rom = Target::ROM::BASIC10; break; @@ -112,7 +112,7 @@ self = [super init]; if(self) { using Target = Analyser::Static::Commodore::Target; - std::unique_ptr target(new Target); + auto target = std::make_unique(); target->machine = Analyser::Machine::Vic20; switch(region) { case CSMachineVic20RegionDanish: target->region = Target::Region::Danish; break; @@ -145,7 +145,7 @@ static Analyser::Static::ZX8081::Target::MemoryModel ZX8081MemoryModelFromSize(K self = [super init]; if(self) { using Target = Analyser::Static::ZX8081::Target; - std::unique_ptr target(new Target); + auto target = std::make_unique(); target->machine = Analyser::Machine::ZX8081; target->is_ZX81 = false; target->ZX80_uses_ZX81_ROM = !!useZX81ROM; @@ -159,7 +159,7 @@ static Analyser::Static::ZX8081::Target::MemoryModel ZX8081MemoryModelFromSize(K self = [super init]; if(self) { using Target = Analyser::Static::ZX8081::Target; - std::unique_ptr target(new Target); + auto target = std::make_unique(); target->machine = Analyser::Machine::ZX8081; target->is_ZX81 = true; target->memory_model = ZX8081MemoryModelFromSize(memorySize); @@ -172,7 +172,7 @@ static Analyser::Static::ZX8081::Target::MemoryModel ZX8081MemoryModelFromSize(K self = [super init]; if(self) { using Target = Analyser::Static::AppleII::Target; - std::unique_ptr target(new Target); + auto target = std::make_unique(); target->machine = Analyser::Machine::AppleII; switch(model) { default: target->model = Target::Model::II; break; @@ -195,7 +195,7 @@ static Analyser::Static::ZX8081::Target::MemoryModel ZX8081MemoryModelFromSize(K self = [super init]; if(self) { using Target = Analyser::Static::Macintosh::Target; - std::unique_ptr target(new Target); + auto target = std::make_unique(); target->machine = Analyser::Machine::Macintosh; using Model = Target::Model; @@ -216,7 +216,7 @@ static Analyser::Static::ZX8081::Target::MemoryModel ZX8081MemoryModelFromSize(K self = [super init]; if(self) { using Target = Analyser::Static::Macintosh::Target; - std::unique_ptr target(new Target); + auto target = std::make_unique(); target->machine = Analyser::Machine::AtariST; _targets.push_back(std::move(target)); } diff --git a/OSBindings/SDL/main.cpp b/OSBindings/SDL/main.cpp index 6ec21135e..2a45c8a09 100644 --- a/OSBindings/SDL/main.cpp +++ b/OSBindings/SDL/main.cpp @@ -423,7 +423,7 @@ int main(int argc, char *argv[]) { continue; } - std::unique_ptr> data(new std::vector); + auto data = std::make_unique>(); std::fseek(file, 0, SEEK_END); data->resize(std::ftell(file)); diff --git a/Storage/Data/ZX8081.cpp b/Storage/Data/ZX8081.cpp index 8ac0be5ce..ffdf6ba24 100644 --- a/Storage/Data/ZX8081.cpp +++ b/Storage/Data/ZX8081.cpp @@ -39,7 +39,7 @@ static std::shared_ptr ZX80FileFromData(const std::vector &data) // TODO: check that the line numbers declared above exist (?) - std::shared_ptr file(new File); + auto file = std::make_shared(); file->data = data; file->isZX81 = false; return file; @@ -81,7 +81,7 @@ static std::shared_ptr ZX81FileFromData(const std::vector &data) // TODO: check that the line numbers declared above exist (?) - std::shared_ptr file(new File); + auto file = std::make_shared(); file->name = StringFromData(name_data, true); file->data = data; file->isZX81 = true; diff --git a/Storage/Tape/Parsers/Commodore.cpp b/Storage/Tape/Parsers/Commodore.cpp index b7d3695f4..c646c0fe6 100644 --- a/Storage/Tape/Parsers/Commodore.cpp +++ b/Storage/Tape/Parsers/Commodore.cpp @@ -20,8 +20,7 @@ Parser::Parser() : Advances to the next block on the tape, treating it as a header, then consumes, parses, and returns it. Returns @c nullptr if any wave-encoding level errors are encountered. */ -std::unique_ptr
Parser::get_next_header(const std::shared_ptr &tape) -{ +std::unique_ptr
Parser::get_next_header(const std::shared_ptr &tape) { return duplicate_match
( get_next_header_body(tape, true), get_next_header_body(tape, false) @@ -32,8 +31,7 @@ std::unique_ptr
Parser::get_next_header(const std::shared_ptr Parser::get_next_data(const std::shared_ptr &tape) -{ +std::unique_ptr Parser::get_next_data(const std::shared_ptr &tape) { return duplicate_match( get_next_data_body(tape, true), get_next_data_body(tape, false) @@ -45,8 +43,7 @@ std::unique_ptr Parser::get_next_data(const std::shared_ptr - std::unique_ptr Parser::duplicate_match(std::unique_ptr first_copy, std::unique_ptr second_copy) -{ + std::unique_ptr Parser::duplicate_match(std::unique_ptr first_copy, std::unique_ptr second_copy) { // if only one copy was parsed successfully, return it if(!first_copy) return second_copy; if(!second_copy) return first_copy; @@ -67,9 +64,8 @@ template return std::move(*copy_to_return); } -std::unique_ptr
Parser::get_next_header_body(const std::shared_ptr &tape, bool is_original) -{ - std::unique_ptr
header(new Header); +std::unique_ptr
Parser::get_next_header_body(const std::shared_ptr &tape, bool is_original) { + auto header = std::make_unique
(); reset_error_flag(); // find and proceed beyond lead-in tone @@ -119,8 +115,7 @@ std::unique_ptr
Parser::get_next_header_body(const std::shared_ptr Parser::get_next_data_body(const std::shared_ptr &tape, bool is_original) -{ - std::unique_ptr data(new Data); +std::unique_ptr Parser::get_next_data_body(const std::shared_ptr &tape, bool is_original) { + auto data = std::make_unique(); reset_error_flag(); // find and proceed beyond lead-in tone to the next landing zone @@ -143,8 +137,7 @@ std::unique_ptr Parser::get_next_data_body(const std::shared_ptris_at_end()) - { + while(!tape->is_at_end()) { SymbolType start_symbol = get_next_symbol(tape); if(start_symbol != SymbolType::Word) break; data->data.push_back(get_next_byte_contents(tape)); @@ -163,19 +156,15 @@ std::unique_ptr Parser::get_next_data_body(const std::shared_ptr &tape, bool is_original) -{ +void Parser::proceed_to_landing_zone(const std::shared_ptr &tape, bool is_original) { uint8_t landing_zone[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; - while(!tape->is_at_end()) - { + while(!tape->is_at_end()) { memmove(landing_zone, &landing_zone[1], sizeof(uint8_t) * 8); landing_zone[8] = get_next_byte(tape); bool is_landing_zone = true; - for(int c = 0; c < 9; c++) - { - if(landing_zone[c] != ((is_original ? 0x80 : 0x00) | 0x9) - c) - { + for(int c = 0; c < 9; c++) { + if(landing_zone[c] != ((is_original ? 0x80 : 0x00) | 0x9) - c) { is_landing_zone = false; break; } @@ -188,10 +177,8 @@ void Parser::proceed_to_landing_zone(const std::shared_ptr Swallows symbols until it reaches the first instance of the required symbol, swallows that and returns. */ -void Parser::proceed_to_symbol(const std::shared_ptr &tape, SymbolType required_symbol) -{ - while(!tape->is_at_end()) - { +void Parser::proceed_to_symbol(const std::shared_ptr &tape, SymbolType required_symbol) { + while(!tape->is_at_end()) { SymbolType symbol = get_next_symbol(tape); if(symbol == required_symbol) return; } @@ -200,8 +187,7 @@ void Parser::proceed_to_symbol(const std::shared_ptr &tape, /*! Swallows the next byte; sets the error flag if it is not equal to @c value. */ -void Parser::expect_byte(const std::shared_ptr &tape, uint8_t value) -{ +void Parser::expect_byte(const std::shared_ptr &tape, uint8_t value) { uint8_t next_byte = get_next_byte(tape); if(next_byte != value) set_error_flag(); } @@ -213,8 +199,7 @@ void Parser::add_parity_byte(uint8_t byte) { parity_byte_ ^= byte; } /*! Proceeds to the next word marker then returns the result of @c get_next_byte_contents. */ -uint8_t Parser::get_next_byte(const std::shared_ptr &tape) -{ +uint8_t Parser::get_next_byte(const std::shared_ptr &tape) { proceed_to_symbol(tape, SymbolType::Word); return get_next_byte_contents(tape); } @@ -224,12 +209,10 @@ uint8_t Parser::get_next_byte(const std::shared_ptr &tape) Returns a byte composed of the first eight of those as bits; sets the error flag if any symbol is not ::One and not ::Zero, or if the ninth bit is not equal to the odd parity of the other eight. */ -uint8_t Parser::get_next_byte_contents(const std::shared_ptr &tape) -{ +uint8_t Parser::get_next_byte_contents(const std::shared_ptr &tape) { int byte_plus_parity = 0; int c = 9; - while(c--) - { + while(c--) { SymbolType next_symbol = get_next_symbol(tape); if((next_symbol != SymbolType::One) && (next_symbol != SymbolType::Zero)) set_error_flag(); byte_plus_parity = (byte_plus_parity >> 1) | (((next_symbol == SymbolType::One) ? 1 : 0) << 8); @@ -249,8 +232,7 @@ uint8_t Parser::get_next_byte_contents(const std::shared_ptr &tape) -{ +uint16_t Parser::get_next_short(const std::shared_ptr &tape) { uint16_t value = get_next_byte(tape); value |= get_next_byte(tape) << 8; return value; @@ -261,15 +243,13 @@ uint16_t Parser::get_next_short(const std::shared_ptr &tape indicates a high to low transition, inspects the time since the last transition, to produce a long, medium, short or unrecognised wave period. */ -void Parser::process_pulse(const Storage::Tape::Tape::Pulse &pulse) -{ +void Parser::process_pulse(const Storage::Tape::Tape::Pulse &pulse) { // The Complete Commodore Inner Space Anthology, P 97, gives half-cycle lengths of: // short: 182us => 0.000364s cycle // medium: 262us => 0.000524s cycle // long: 342us => 0.000684s cycle bool is_high = pulse.type == Storage::Tape::Tape::Pulse::High; - if(!is_high && previous_was_high_) - { + if(!is_high && previous_was_high_) { if(wave_period_ >= 0.000764) push_wave(WaveType::Unrecognised); else if(wave_period_ >= 0.000604) push_wave(WaveType::Long); else if(wave_period_ >= 0.000444) push_wave(WaveType::Medium); @@ -287,36 +267,30 @@ void Parser::process_pulse(const Storage::Tape::Tape::Pulse &pulse) Per the contract with Analyser::Static::TapeParser; produces any of a word marker, an end-of-block marker, a zero, a one or a lead-in symbol based on the currently captured waves. */ -void Parser::inspect_waves(const std::vector &waves) -{ +void Parser::inspect_waves(const std::vector &waves) { if(waves.size() < 2) return; - if(waves[0] == WaveType::Long && waves[1] == WaveType::Medium) - { + if(waves[0] == WaveType::Long && waves[1] == WaveType::Medium) { push_symbol(SymbolType::Word, 2); return; } - if(waves[0] == WaveType::Long && waves[1] == WaveType::Short) - { + if(waves[0] == WaveType::Long && waves[1] == WaveType::Short) { push_symbol(SymbolType::EndOfBlock, 2); return; } - if(waves[0] == WaveType::Short && waves[1] == WaveType::Medium) - { + if(waves[0] == WaveType::Short && waves[1] == WaveType::Medium) { push_symbol(SymbolType::Zero, 2); return; } - if(waves[0] == WaveType::Medium && waves[1] == WaveType::Short) - { + if(waves[0] == WaveType::Medium && waves[1] == WaveType::Short) { push_symbol(SymbolType::One, 2); return; } - if(waves[0] == WaveType::Short) - { + if(waves[0] == WaveType::Short) { push_symbol(SymbolType::LeadIn, 1); return; } diff --git a/Storage/Tape/Parsers/MSX.cpp b/Storage/Tape/Parsers/MSX.cpp index 3af952cd3..723f44fbe 100644 --- a/Storage/Tape/Parsers/MSX.cpp +++ b/Storage/Tape/Parsers/MSX.cpp @@ -71,7 +71,7 @@ std::unique_ptr Parser::find_header(Storage::Tape::BinaryTape // To convert to the loop count format used by the MSX BIOS. uint8_t int_result = static_cast(total_length / (0.00001145f * 0.75f)); - std::unique_ptr result(new FileSpeed); + auto result = std::make_unique(); result->minimum_start_bit_duration = int_result; result->low_high_disrimination_duration = (int_result * 3) >> 2; diff --git a/Storage/Tape/Parsers/ZX8081.cpp b/Storage/Tape/Parsers/ZX8081.cpp index 61148c9b5..10754909f 100644 --- a/Storage/Tape/Parsers/ZX8081.cpp +++ b/Storage/Tape/Parsers/ZX8081.cpp @@ -120,7 +120,7 @@ std::shared_ptr> Parser::get_next_file_data(const std::shar if(is_at_end(tape)) return nullptr; return_symbol(symbol); - std::shared_ptr> result(new std::vector); + auto result = std::make_shared>(); int byte; while(!is_at_end(tape)) { byte = get_next_byte(tape); From a847654ef2b4a4d85f058d2113f23bfcfc9d4c76 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 22 Dec 2019 00:00:23 -0500 Subject: [PATCH 3/4] Corrects various old-fashioned bits of indentation, plus the odd const. --- Components/9918/9918.cpp | 3 +- .../Clock Signal/Machine/NSData+StdVector.mm | 3 +- .../AtariStaticAnalyserTests.mm | 9 +-- OSBindings/Mac/Clock SignalTests/CRCTests.mm | 15 ++-- .../Clock SignalTests/MasterSystemVDPTests.mm | 3 +- .../PCMSegmentEventSourceTests.mm | 24 ++---- Storage/Tape/Formats/CommodoreTAP.cpp | 36 +++------ Storage/Tape/Parsers/Commodore.cpp | 12 +-- Storage/Tape/Parsers/Oric.cpp | 80 +++++++------------ Storage/Tape/Parsers/Oric.hpp | 2 +- 10 files changed, 64 insertions(+), 123 deletions(-) diff --git a/Components/9918/9918.cpp b/Components/9918/9918.cpp index ebd290fb1..f5df4eecb 100644 --- a/Components/9918/9918.cpp +++ b/Components/9918/9918.cpp @@ -352,8 +352,7 @@ void TMS9918::run_for(const HalfCycles cycles) { // Output video stream. // -------------------- -#define intersect(left, right, code) \ - { \ +#define intersect(left, right, code) { \ const int start = std::max(read_pointer_.column, left); \ const int end = std::min(end_column, right); \ if(end > start) {\ diff --git a/OSBindings/Mac/Clock Signal/Machine/NSData+StdVector.mm b/OSBindings/Mac/Clock Signal/Machine/NSData+StdVector.mm index 720e87057..6320d7a9b 100644 --- a/OSBindings/Mac/Clock Signal/Machine/NSData+StdVector.mm +++ b/OSBindings/Mac/Clock Signal/Machine/NSData+StdVector.mm @@ -10,8 +10,7 @@ @implementation NSData (StdVector) -- (std::vector)stdVector8 -{ +- (std::vector)stdVector8 { uint8_t *bytes8 = (uint8_t *)self.bytes; return std::vector(bytes8, bytes8 + self.length); } diff --git a/OSBindings/Mac/Clock SignalTests/AtariStaticAnalyserTests.mm b/OSBindings/Mac/Clock SignalTests/AtariStaticAnalyserTests.mm index dfc5d56ca..6fdbe160e 100644 --- a/OSBindings/Mac/Clock SignalTests/AtariStaticAnalyserTests.mm +++ b/OSBindings/Mac/Clock SignalTests/AtariStaticAnalyserTests.mm @@ -21,8 +21,7 @@ using PagingModel = Analyser::Static::Atari2600::Target::PagingModel; @end @implementation AtariROMRecord -+ (instancetype)recordWithPagingModel:(PagingModel)pagingModel usesSuperchip:(BOOL)usesSuperchip -{ ++ (instancetype)recordWithPagingModel:(PagingModel)pagingModel usesSuperchip:(BOOL)usesSuperchip { AtariROMRecord *record = [[AtariROMRecord alloc] init]; record->_pagingModel = pagingModel; record->_usesSuperchip = usesSuperchip; @@ -578,11 +577,9 @@ static NSDictionary *romRecordsBySHA1 = @{ @implementation AtariStaticAnalyserTests -- (void)testROMsOfSize:(NSInteger)size -{ +- (void)testROMsOfSize:(NSInteger)size { NSString *basePath = [[[NSBundle bundleForClass:[self class]] resourcePath] stringByAppendingPathComponent:@"Atari ROMs"]; - for(NSString *testFile in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:basePath error:nil]) - { + for(NSString *testFile in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:basePath error:nil]) { NSString *fullPath = [basePath stringByAppendingPathComponent:testFile]; // get a SHA1 for the file diff --git a/OSBindings/Mac/Clock SignalTests/CRCTests.mm b/OSBindings/Mac/Clock SignalTests/CRCTests.mm index 32cbcd6af..938004326 100644 --- a/OSBindings/Mac/Clock SignalTests/CRCTests.mm +++ b/OSBindings/Mac/Clock SignalTests/CRCTests.mm @@ -15,18 +15,15 @@ @implementation CRCTests -- (uint16_t)crcOfData:(uint8_t *)data length:(size_t)length generator:(CRC::CCITT &)generator -{ +- (uint16_t)crcOfData:(uint8_t *)data length:(size_t)length generator:(CRC::CCITT &)generator { generator.reset(); for(size_t c = 0; c < length; c++) generator.add(data[c]); return generator.get_value(); } -- (void)testIDMark -{ - uint8_t IDMark[] = - { +- (void)testIDMark { + uint8_t IDMark[] = { 0xa1, 0xa1, 0xa1, 0xfe, 0x00, 0x00, 0x01, 0x01 }; uint16_t crc = 0xfa0c; @@ -36,10 +33,8 @@ XCTAssert(computedCRC == crc, @"Calculated CRC should have been %04x, was %04x", crc, computedCRC); } -- (void)testData -{ - uint8_t sectorData[] = - { +- (void)testData { + uint8_t sectorData[] = { 0xa1, 0xa1, 0xa1, 0xfb, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x53, 0x45, 0x44, 0x4f, 0x52, 0x49, 0x43, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, diff --git a/OSBindings/Mac/Clock SignalTests/MasterSystemVDPTests.mm b/OSBindings/Mac/Clock SignalTests/MasterSystemVDPTests.mm index fc584108b..76460fbe5 100644 --- a/OSBindings/Mac/Clock SignalTests/MasterSystemVDPTests.mm +++ b/OSBindings/Mac/Clock SignalTests/MasterSystemVDPTests.mm @@ -22,8 +22,7 @@ [super setUp]; // Create a valid OpenGL context, so that a VDP can be constructed. - NSOpenGLPixelFormatAttribute attributes[] = - { + NSOpenGLPixelFormatAttribute attributes[] = { NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, 0 }; diff --git a/OSBindings/Mac/Clock SignalTests/PCMSegmentEventSourceTests.mm b/OSBindings/Mac/Clock SignalTests/PCMSegmentEventSourceTests.mm index 053058012..6eca9d231 100644 --- a/OSBindings/Mac/Clock SignalTests/PCMSegmentEventSourceTests.mm +++ b/OSBindings/Mac/Clock SignalTests/PCMSegmentEventSourceTests.mm @@ -15,21 +15,18 @@ @implementation PCMSegmentEventSourceTests -- (Storage::Disk::PCMSegmentEventSource)segmentSource -{ +- (Storage::Disk::PCMSegmentEventSource)segmentSource { std::vector data = {0xff, 0x00, 0xff, 0x00}; Storage::Disk::PCMSegment alternatingFFs(Storage::Time(1, 10), data.size()*8, data); return Storage::Disk::PCMSegmentEventSource(alternatingFFs); } -- (void)testCentring -{ +- (void)testCentring { Storage::Disk::PCMSegmentEventSource segmentSource = self.segmentSource; [self assertFirstTwoEventLengthsForSource:segmentSource]; } -- (void)assertFirstTwoEventLengthsForSource:(Storage::Disk::PCMSegmentEventSource &)segmentSource -{ +- (void)assertFirstTwoEventLengthsForSource:(Storage::Disk::PCMSegmentEventSource &)segmentSource { Storage::Disk::Track::Event first_event = segmentSource.get_next_event(); Storage::Disk::Track::Event second_event = segmentSource.get_next_event(); @@ -39,8 +36,7 @@ XCTAssertTrue(second_event.length.length == 1 && second_event.length.clock_rate == 10, @"Second event should occur a whole bit's length after the first"); } -- (void)testLongerGap -{ +- (void)testLongerGap { Storage::Disk::PCMSegmentEventSource segmentSource = self.segmentSource; // skip first eight flux transitions @@ -52,8 +48,7 @@ XCTAssertTrue(next_event.length.length == 9 && next_event.length.clock_rate == 10, @"Zero byte should give a nine bit length event gap"); } -- (void)testTermination -{ +- (void)testTermination { Storage::Disk::PCMSegmentEventSource segmentSource = self.segmentSource; Storage::Time total_time; for(int c = 0; c < 16; c++) total_time += segmentSource.get_next_event().length; @@ -66,16 +61,14 @@ XCTAssertTrue(total_time.length == 16 && total_time.clock_rate == 5, @"Should have taken 32 bit lengths to finish the segment"); } -- (void)testReset -{ +- (void)testReset { Storage::Disk::PCMSegmentEventSource segmentSource = self.segmentSource; for(int c = 0; c < 8; c++) segmentSource.get_next_event(); segmentSource.reset(); [self assertFirstTwoEventLengthsForSource:segmentSource]; } -- (void)testSeekToSecondBit -{ +- (void)testSeekToSecondBit { Storage::Disk::PCMSegmentEventSource segmentSource = self.segmentSource; Storage::Time target_time(1, 10); @@ -90,8 +83,7 @@ XCTAssertTrue(next_event.length.length == 1 && next_event.length.clock_rate == 10, @"Next event should be 1/10th later"); } -- (void)testSeekBeyondFinalBit -{ +- (void)testSeekBeyondFinalBit { Storage::Disk::PCMSegmentEventSource segmentSource = self.segmentSource; Storage::Time target_time(24, 10); diff --git a/Storage/Tape/Formats/CommodoreTAP.cpp b/Storage/Tape/Formats/CommodoreTAP.cpp index fb4f1b5fa..da856ddf2 100644 --- a/Storage/Tape/Formats/CommodoreTAP.cpp +++ b/Storage/Tape/Formats/CommodoreTAP.cpp @@ -19,8 +19,7 @@ CommodoreTAP::CommodoreTAP(const std::string &file_name) : throw ErrorNotCommodoreTAP; // check the file version - switch(file_.get8()) - { + switch(file_.get8()) { case 0: updated_layout_ = false; break; case 1: updated_layout_ = true; break; default: throw ErrorNotCommodoreTAP; @@ -40,52 +39,41 @@ CommodoreTAP::CommodoreTAP(const std::string &file_name) : current_pulse_.type = Pulse::High; } -void CommodoreTAP::virtual_reset() -{ +void CommodoreTAP::virtual_reset() { file_.seek(0x14, SEEK_SET); current_pulse_.type = Pulse::High; is_at_end_ = false; } -bool CommodoreTAP::is_at_end() -{ +bool CommodoreTAP::is_at_end() { return is_at_end_; } -Storage::Tape::Tape::Pulse CommodoreTAP::virtual_get_next_pulse() -{ - if(is_at_end_) - { +Storage::Tape::Tape::Pulse CommodoreTAP::virtual_get_next_pulse() { + if(is_at_end_) { return current_pulse_; } - if(current_pulse_.type == Pulse::High) - { + if(current_pulse_.type == Pulse::High) { uint32_t next_length; uint8_t next_byte = file_.get8(); - if(!updated_layout_ || next_byte > 0) - { + if(!updated_layout_ || next_byte > 0) { next_length = (uint32_t)next_byte << 3; - } - else - { + } else { next_length = file_.get24le(); } - if(file_.eof()) - { + if(file_.eof()) { is_at_end_ = true; current_pulse_.length.length = current_pulse_.length.clock_rate; current_pulse_.type = Pulse::Zero; - } - else - { + } else { current_pulse_.length.length = next_length; current_pulse_.type = Pulse::Low; } - } - else + } else { current_pulse_.type = Pulse::High; + } return current_pulse_; } diff --git a/Storage/Tape/Parsers/Commodore.cpp b/Storage/Tape/Parsers/Commodore.cpp index c646c0fe6..8f2ed4555 100644 --- a/Storage/Tape/Parsers/Commodore.cpp +++ b/Storage/Tape/Parsers/Commodore.cpp @@ -77,8 +77,7 @@ std::unique_ptr
Parser::get_next_header_body(const std::shared_ptrtype = Header::Unknown; break; case 0x01: header->type = Header::RelocatableProgram; break; case 0x02: header->type = Header::DataBlock; break; @@ -89,8 +88,7 @@ std::unique_ptr
Parser::get_next_header_body(const std::shared_ptrdata.reserve(191); - for(std::size_t c = 0; c < 191; c++) - { + for(std::size_t c = 0; c < 191; c++) { header->data.push_back(get_next_byte(tape)); } @@ -98,13 +96,11 @@ std::unique_ptr
Parser::get_next_header_body(const std::shared_ptrparity_was_valid = get_next_byte(tape) == parity_byte; // parse if this is not pure data - if(header->type != Header::DataBlock) - { + if(header->type != Header::DataBlock) { header->starting_address = static_cast(header->data[0] | (header->data[1] << 8)); header->ending_address = static_cast(header->data[2] | (header->data[3] << 8)); - for(std::size_t c = 0; c < 16; c++) - { + for(std::size_t c = 0; c < 16; c++) { header->raw_name.push_back(header->data[4 + c]); } header->name = Storage::Data::Commodore::petscii_from_bytes(&header->raw_name[0], 16, false); diff --git a/Storage/Tape/Parsers/Oric.cpp b/Storage/Tape/Parsers/Oric.cpp index 47218e71e..efa4a5724 100644 --- a/Storage/Tape/Parsers/Oric.cpp +++ b/Storage/Tape/Parsers/Oric.cpp @@ -10,15 +10,13 @@ using namespace Storage::Tape::Oric; -int Parser::get_next_byte(const std::shared_ptr &tape, bool use_fast_encoding) -{ +int Parser::get_next_byte(const std::shared_ptr &tape, bool use_fast_encoding) { detection_mode_ = use_fast_encoding ? FastZero : SlowZero; cycle_length_ = 0.0f; int result = 0; int bit_count = 0; - while(bit_count < 11 && !tape->is_at_end()) - { + while(bit_count < 11 && !tape->is_at_end()) { SymbolType symbol = get_next_symbol(tape); if(!bit_count && symbol != SymbolType::Zero) continue; detection_mode_ = use_fast_encoding ? FastData : SlowData; @@ -29,14 +27,11 @@ int Parser::get_next_byte(const std::shared_ptr &tape, bool return tape->is_at_end() ? -1 : ((result >> 1)&0xff); } -bool Parser::sync_and_get_encoding_speed(const std::shared_ptr &tape) -{ +bool Parser::sync_and_get_encoding_speed(const std::shared_ptr &tape) { detection_mode_ = Sync; - while(!tape->is_at_end()) - { - SymbolType symbol = get_next_symbol(tape); - switch(symbol) - { + while(!tape->is_at_end()) { + const SymbolType symbol = get_next_symbol(tape); + switch(symbol) { case SymbolType::FoundSlow: return false; case SymbolType::FoundFast: return true; default: break; @@ -45,15 +40,13 @@ bool Parser::sync_and_get_encoding_speed(const std::shared_ptr(); } -void Parser::inspect_waves(const std::vector &waves) -{ - switch(detection_mode_) - { +void Parser::inspect_waves(const std::vector &waves) { + switch(detection_mode_) { case FastZero: if(waves.empty()) return; - if(waves[0] == WaveType::Medium) - { + if(waves[0] == WaveType::Medium) { push_symbol(SymbolType::Zero, 1); return; } @@ -80,13 +70,11 @@ void Parser::inspect_waves(const std::vector &waves) case FastData: if(waves.empty()) return; - if(waves[0] == WaveType::Medium) - { + if(waves[0] == WaveType::Medium) { push_symbol(SymbolType::Zero, 1); return; } - if(waves[0] == WaveType::Short) - { + if(waves[0] == WaveType::Short) { push_symbol(SymbolType::One, 1); return; } @@ -94,8 +82,7 @@ void Parser::inspect_waves(const std::vector &waves) case SlowZero: if(waves.size() < 4) return; - if(waves[0] == WaveType::Long && waves[1] == WaveType::Long && waves[2] == WaveType::Long && waves[3] == WaveType::Long) - { + if(waves[0] == WaveType::Long && waves[1] == WaveType::Long && waves[2] == WaveType::Long && waves[3] == WaveType::Long) { push_symbol(SymbolType::Zero, 4); return; } @@ -103,12 +90,10 @@ void Parser::inspect_waves(const std::vector &waves) case SlowData: #define CHECK_RUN(length, type, symbol) \ - if(waves.size() >= length)\ - {\ + if(waves.size() >= length) {\ std::size_t c;\ for(c = 0; c < length; c++) if(waves[c] != type) break;\ - if(c == length)\ - {\ + if(c == length) {\ push_symbol(symbol, length);\ return;\ }\ @@ -120,11 +105,9 @@ void Parser::inspect_waves(const std::vector &waves) if(waves.size() < 16) return; // TODO, maybe: if there are any inconsistencies in the first 8, don't return break; - case Sync: - { + case Sync: { // Sync is 0x16, either encoded fast or slow; i.e. 0 0110 1000 1 - Pattern slow_sync[] = - { + const Pattern slow_sync[] = { {WaveType::Long, 8}, {WaveType::Short, 16}, {WaveType::Long, 4}, @@ -133,8 +116,7 @@ void Parser::inspect_waves(const std::vector &waves) {WaveType::Short, 8}, {WaveType::Unrecognised} }; - Pattern fast_sync[] = - { + const Pattern fast_sync[] = { {WaveType::Medium, 2}, {WaveType::Short, 2}, {WaveType::Medium, 1}, @@ -147,18 +129,15 @@ void Parser::inspect_waves(const std::vector &waves) std::size_t slow_sync_matching_depth = pattern_matching_depth(waves, slow_sync); std::size_t fast_sync_matching_depth = pattern_matching_depth(waves, fast_sync); - if(slow_sync_matching_depth == 52) - { + if(slow_sync_matching_depth == 52) { push_symbol(SymbolType::FoundSlow, 52); return; } - if(fast_sync_matching_depth == 10) - { + if(fast_sync_matching_depth == 10) { push_symbol(SymbolType::FoundFast, 10); return; } - if(slow_sync_matching_depth < waves.size() && fast_sync_matching_depth < waves.size()) - { + if(slow_sync_matching_depth < waves.size() && fast_sync_matching_depth < waves.size()) { int least_depth = static_cast(std::min(slow_sync_matching_depth, fast_sync_matching_depth)); remove_waves(least_depth ? least_depth : 1); } @@ -171,17 +150,14 @@ void Parser::inspect_waves(const std::vector &waves) remove_waves(1); } -std::size_t Parser::pattern_matching_depth(const std::vector &waves, Pattern *pattern) -{ +std::size_t Parser::pattern_matching_depth(const std::vector &waves, const Pattern *pattern) { std::size_t depth = 0; int pattern_depth = 0; - while(depth < waves.size() && pattern->type != WaveType::Unrecognised) - { + while(depth < waves.size() && pattern->type != WaveType::Unrecognised) { if(waves[depth] != pattern->type) break; depth++; pattern_depth++; - if(pattern_depth == pattern->count) - { + if(pattern_depth == pattern->count) { pattern_depth = 0; pattern++; } diff --git a/Storage/Tape/Parsers/Oric.hpp b/Storage/Tape/Parsers/Oric.hpp index 71607bd1b..7c62821d2 100644 --- a/Storage/Tape/Parsers/Oric.hpp +++ b/Storage/Tape/Parsers/Oric.hpp @@ -50,7 +50,7 @@ class Parser: public Storage::Tape::PulseClassificationParser &waves, Pattern *pattern); + std::size_t pattern_matching_depth(const std::vector &waves, const Pattern *pattern); }; From 274867579bf612560f43661cda46eeccff848ab3 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 22 Dec 2019 00:22:17 -0500 Subject: [PATCH 4/4] Deploys `constexpr` as a stricter `const`. --- Components/6850/6850.hpp | 2 +- Components/68901/MFP68901.cpp | 2 +- Components/68901/MFP68901.hpp | 2 +- Components/8272/i8272.cpp | 2 +- Components/9918/9918.cpp | 18 +++++------ Components/AY38910/AY38910.cpp | 4 +-- Components/DiskII/DiskII.hpp | 2 +- Components/DiskII/IWM.cpp | 18 +++++------ Machines/AmstradCPC/AmstradCPC.cpp | 2 +- Machines/Apple/AppleII/AppleII.cpp | 4 +-- Machines/Apple/AppleII/Video.hpp | 8 ++--- Machines/Apple/Macintosh/Keyboard.hpp | 2 +- Machines/Apple/Macintosh/Macintosh.cpp | 2 +- Machines/Apple/Macintosh/Video.hpp | 10 +++--- Machines/Atari/2600/TIA.cpp | 8 ++--- Machines/Atari/2600/TIASound.hpp | 2 +- Machines/Atari/ST/AtariST.cpp | 2 +- Machines/Atari/ST/Video.cpp | 4 +-- Machines/ColecoVision/ColecoVision.cpp | 2 +- Machines/Electron/SoundGenerator.hpp | 2 +- Machines/Electron/Video.cpp | 32 +++++++++---------- Machines/MasterSystem/MasterSystem.cpp | 2 +- OSBindings/SDL/main.cpp | 4 +-- Outputs/CRT/CRT.cpp | 16 +++++----- Processors/68000/68000.hpp | 22 ++++++------- .../68000/Implementation/68000Storage.hpp | 4 +-- Storage/Disk/DiskImage/Formats/AcornADF.cpp | 4 +-- Storage/Disk/DiskImage/Formats/AppleDSK.cpp | 4 +-- Storage/Disk/DiskImage/Formats/MSXDSK.cpp | 6 ++-- Storage/Disk/DiskImage/Formats/SSD.cpp | 4 +-- Storage/Disk/DiskImage/Formats/ST.cpp | 4 +-- Storage/Disk/Drive.cpp | 4 +-- Storage/MassStorage/SCSI/SCSI.hpp | 2 +- Storage/Tape/Formats/TapePRG.cpp | 16 +++++----- Storage/Tape/Parsers/Acorn.cpp | 2 +- Storage/Tape/Parsers/MSX.cpp | 8 ++--- Storage/Tape/Parsers/ZX8081.cpp | 6 ++-- 37 files changed, 119 insertions(+), 119 deletions(-) diff --git a/Components/6850/6850.hpp b/Components/6850/6850.hpp index 6f3734cd6..0e9c91152 100644 --- a/Components/6850/6850.hpp +++ b/Components/6850/6850.hpp @@ -100,7 +100,7 @@ class ACIA: public ClockingHint::Source, private Serial::Line::ReadDelegate { } parity_ = Parity::None; int data_bits_ = 7, stop_bits_ = 2; - static const int NoValueMask = 0x100; + static constexpr int NoValueMask = 0x100; int next_transmission_ = NoValueMask; int received_data_ = NoValueMask; diff --git a/Components/68901/MFP68901.cpp b/Components/68901/MFP68901.cpp index 95c2a1992..d22b59792 100644 --- a/Components/68901/MFP68901.cpp +++ b/Components/68901/MFP68901.cpp @@ -110,7 +110,7 @@ void MFP68901::write(int address, uint8_t value) { return; } - const int timer_prescales[] = { + constexpr int timer_prescales[] = { 1, 4, 10, 16, 50, 64, 100, 200 }; diff --git a/Components/68901/MFP68901.hpp b/Components/68901/MFP68901.hpp index 974e195e7..25cc88cc4 100644 --- a/Components/68901/MFP68901.hpp +++ b/Components/68901/MFP68901.hpp @@ -61,7 +61,7 @@ class MFP68901: public ClockingHint::Source { /// @returns @c true if the interrupt output is currently active; @c false otherwise.s bool get_interrupt_line(); - static const int NoAcknowledgement = 0x100; + static constexpr int NoAcknowledgement = 0x100; /// Communicates an interrupt acknowledge cycle. /// diff --git a/Components/8272/i8272.cpp b/Components/8272/i8272.cpp index 10598525c..df5d54622 100644 --- a/Components/8272/i8272.cpp +++ b/Components/8272/i8272.cpp @@ -292,7 +292,7 @@ void i8272::posit_event(int event_type) { WAIT_FOR_EVENT(Event8272::CommandByte) SetBusy(); - static const std::size_t required_lengths[32] = { + static constexpr std::size_t required_lengths[32] = { 0, 0, 9, 3, 2, 9, 9, 2, 1, 9, 2, 0, 9, 6, 0, 3, 0, 9, 0, 0, 0, 0, 0, 0, diff --git a/Components/9918/9918.cpp b/Components/9918/9918.cpp index f5df4eecb..3556b18c3 100644 --- a/Components/9918/9918.cpp +++ b/Components/9918/9918.cpp @@ -17,16 +17,16 @@ using namespace TI::TMS; namespace { -const uint8_t StatusInterrupt = 0x80; -const uint8_t StatusSpriteOverflow = 0x40; +constexpr uint8_t StatusInterrupt = 0x80; +constexpr uint8_t StatusSpriteOverflow = 0x40; -const int StatusSpriteCollisionShift = 5; -const uint8_t StatusSpriteCollision = 0x20; +constexpr int StatusSpriteCollisionShift = 5; +constexpr uint8_t StatusSpriteCollision = 0x20; // 342 internal cycles are 228/227.5ths of a line, so 341.25 cycles should be a whole // line. Therefore multiply everything by four, but set line length to 1365 rather than 342*4 = 1368. -const unsigned int CRTCyclesPerLine = 1365; -const unsigned int CRTCyclesDivider = 4; +constexpr unsigned int CRTCyclesPerLine = 1365; +constexpr unsigned int CRTCyclesDivider = 4; struct ReverseTable { std::uint8_t map[256]; @@ -624,7 +624,7 @@ void TMS9918::set_register(int address, uint8_t value) { uint8_t TMS9918::get_current_line() { // Determine the row to return. - static const int row_change_position = 63; // This is the proper Master System value; substitute if any other VDPs turn out to have this functionality. + constexpr int row_change_position = 63; // This is the proper Master System value; substitute if any other VDPs turn out to have this functionality. int source_row = (write_pointer_.column < row_change_position) ? (write_pointer_.row + mode_timing_.total_lines - 1)%mode_timing_.total_lines @@ -829,8 +829,8 @@ void Base::draw_tms_character(int start, int end) { int sprite_collision = 0; memset(&sprite_buffer[start], 0, size_t(end - start)*sizeof(sprite_buffer[0])); - static const uint32_t sprite_colour_selection_masks[2] = {0x00000000, 0xffffffff}; - static const int colour_masks[16] = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + constexpr uint32_t sprite_colour_selection_masks[2] = {0x00000000, 0xffffffff}; + constexpr int colour_masks[16] = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; // Draw all sprites into the sprite buffer. const int shifter_target = sprites_16x16_ ? 32 : 16; diff --git a/Components/AY38910/AY38910.cpp b/Components/AY38910/AY38910.cpp index 30e5ddc46..5ed753bf5 100644 --- a/Components/AY38910/AY38910.cpp +++ b/Components/AY38910/AY38910.cpp @@ -72,8 +72,8 @@ AY38910::AY38910(Personality personality, Concurrency::DeferringAsyncTaskQueue & void AY38910::set_sample_volume_range(std::int16_t range) { // set up volume lookup table - const float max_volume = static_cast(range) / 3.0f; // As there are three channels. - const float root_two = sqrtf(2.0f); + const float max_volume = float(range) / 3.0f; // As there are three channels. + constexpr float root_two = 1.414213562373095f; for(int v = 0; v < 32; v++) { volumes_[v] = int(max_volume / powf(root_two, float(v ^ 0x1f) / 2.0f)); } diff --git a/Components/DiskII/DiskII.hpp b/Components/DiskII/DiskII.hpp index 13b44e4e9..edc1d0789 100644 --- a/Components/DiskII/DiskII.hpp +++ b/Components/DiskII/DiskII.hpp @@ -48,7 +48,7 @@ class DiskII final: The value returned by @c read_address if accessing that address didn't cause the disk II to place anything onto the bus. */ - const int DidNotLoad = -1; + static constexpr int DidNotLoad = -1; /// Advances the controller by @c cycles. void run_for(const Cycles cycles); diff --git a/Components/DiskII/IWM.cpp b/Components/DiskII/IWM.cpp index b8b2d20e0..3a21a8fab 100644 --- a/Components/DiskII/IWM.cpp +++ b/Components/DiskII/IWM.cpp @@ -13,15 +13,15 @@ using namespace Apple; namespace { - const int CA0 = 1 << 0; - const int CA1 = 1 << 1; - const int CA2 = 1 << 2; - const int LSTRB = 1 << 3; - const int ENABLE = 1 << 4; - const int DRIVESEL = 1 << 5; /* This means drive select, like on the original Disk II. */ - const int Q6 = 1 << 6; - const int Q7 = 1 << 7; - const int SEL = 1 << 8; /* This is an additional input, not available on a Disk II, with a confusingly-similar name to SELECT but a distinct purpose. */ + constexpr int CA0 = 1 << 0; + constexpr int CA1 = 1 << 1; + constexpr int CA2 = 1 << 2; + constexpr int LSTRB = 1 << 3; + constexpr int ENABLE = 1 << 4; + constexpr int DRIVESEL = 1 << 5; /* This means drive select, like on the original Disk II. */ + constexpr int Q6 = 1 << 6; + constexpr int Q7 = 1 << 7; + constexpr int SEL = 1 << 8; /* This is an additional input, not available on a Disk II, with a confusingly-similar name to SELECT but a distinct purpose. */ } IWM::IWM(int clock_rate) : diff --git a/Machines/AmstradCPC/AmstradCPC.cpp b/Machines/AmstradCPC/AmstradCPC.cpp index 3b707348e..870efb114 100644 --- a/Machines/AmstradCPC/AmstradCPC.cpp +++ b/Machines/AmstradCPC/AmstradCPC.cpp @@ -509,7 +509,7 @@ class CRTCBusHandler { uint8_t mapped_palette_value(uint8_t colour) { #define COL(r, g, b) (r << 4) | (g << 2) | b - static const uint8_t mapping[32] = { + constexpr uint8_t mapping[32] = { COL(1, 1, 1), COL(1, 1, 1), COL(0, 2, 1), COL(2, 2, 1), COL(0, 0, 1), COL(2, 0, 1), COL(0, 1, 1), COL(2, 1, 1), COL(2, 0, 1), COL(2, 2, 1), COL(2, 2, 0), COL(2, 2, 2), diff --git a/Machines/Apple/AppleII/AppleII.cpp b/Machines/Apple/AppleII/AppleII.cpp index f561059ca..5c635935a 100644 --- a/Machines/Apple/AppleII/AppleII.cpp +++ b/Machines/Apple/AppleII/AppleII.cpp @@ -79,7 +79,7 @@ template class ConcreteMachine: void update_video() { video_.run_for(cycles_since_video_update_.flush()); } - static const int audio_divider = 8; + static constexpr int audio_divider = 8; void update_audio() { speaker_.run_for(audio_queue_, cycles_since_audio_update_.divide(Cycles(audio_divider))); } @@ -329,7 +329,7 @@ template class ConcreteMachine: audio_toggle_(audio_queue_), speaker_(audio_toggle_) { // The system's master clock rate. - const float master_clock = 14318180.0; + constexpr float master_clock = 14318180.0; // This is where things get slightly convoluted: establish the machine as having a clock rate // equal to the number of cycles of work the 6502 will actually achieve. Which is less than diff --git a/Machines/Apple/AppleII/Video.hpp b/Machines/Apple/AppleII/Video.hpp index 4a1356de8..ac7e4ab70 100644 --- a/Machines/Apple/AppleII/Video.hpp +++ b/Machines/Apple/AppleII/Video.hpp @@ -203,7 +203,7 @@ class VideoBase { std::array auxiliary_stream_; bool is_iie_ = false; - static const int flash_length = 8406; + static constexpr int flash_length = 8406; // Describes the current text mode mapping from in-memory character index // to output character. @@ -339,9 +339,9 @@ template class Video: public VideoBase { A frame is oriented around 65 cycles across, 262 lines down. */ - static const int first_sync_line = 220; // A complete guess. Information needed. - static const int first_sync_column = 49; // Also a guess. - static const int sync_length = 4; // One of the two likely candidates. + constexpr int first_sync_line = 220; // A complete guess. Information needed. + constexpr int first_sync_column = 49; // Also a guess. + constexpr int sync_length = 4; // One of the two likely candidates. int int_cycles = int(cycles.as_integral()); while(int_cycles) { diff --git a/Machines/Apple/Macintosh/Keyboard.hpp b/Machines/Apple/Macintosh/Keyboard.hpp index 65c043268..2caf4bbd0 100644 --- a/Machines/Apple/Macintosh/Keyboard.hpp +++ b/Machines/Apple/Macintosh/Keyboard.hpp @@ -18,7 +18,7 @@ namespace Apple { namespace Macintosh { -static const uint16_t KeypadMask = 0x100; +static constexpr uint16_t KeypadMask = 0x100; /*! Defines the keycodes that could be passed directly to a Macintosh via set_key_pressed. diff --git a/Machines/Apple/Macintosh/Macintosh.cpp b/Machines/Apple/Macintosh/Macintosh.cpp index 5b8a82663..0f71be531 100644 --- a/Machines/Apple/Macintosh/Macintosh.cpp +++ b/Machines/Apple/Macintosh/Macintosh.cpp @@ -49,7 +49,7 @@ namespace { -const int CLOCK_RATE = 7833600; +constexpr int CLOCK_RATE = 7833600; } diff --git a/Machines/Apple/Macintosh/Video.hpp b/Machines/Apple/Macintosh/Video.hpp index 5836816ad..3c52289ed 100644 --- a/Machines/Apple/Macintosh/Video.hpp +++ b/Machines/Apple/Macintosh/Video.hpp @@ -17,11 +17,11 @@ namespace Apple { namespace Macintosh { -static const HalfCycles line_length(704); -static const int number_of_lines = 370; -static const HalfCycles frame_length(line_length * HalfCycles(number_of_lines)); -static const int sync_start = 36; -static const int sync_end = 38; +static constexpr HalfCycles line_length(704); +static constexpr int number_of_lines = 370; +static constexpr HalfCycles frame_length(line_length * HalfCycles(number_of_lines)); +static constexpr int sync_start = 36; +static constexpr int sync_end = 38; /*! Models the 68000-era Macintosh video hardware, producing a 512x348 pixel image, diff --git a/Machines/Atari/2600/TIA.cpp b/Machines/Atari/2600/TIA.cpp index a7d73a0d8..64a4603d2 100644 --- a/Machines/Atari/2600/TIA.cpp +++ b/Machines/Atari/2600/TIA.cpp @@ -13,11 +13,11 @@ using namespace Atari2600; namespace { - const int cycles_per_line = 228; - const int first_pixel_cycle = 68; + constexpr int cycles_per_line = 228; + constexpr int first_pixel_cycle = 68; - const int sync_flag = 0x1; - const int blank_flag = 0x2; + constexpr int sync_flag = 0x1; + constexpr int blank_flag = 0x2; uint8_t reverse_table[256]; } diff --git a/Machines/Atari/2600/TIASound.hpp b/Machines/Atari/2600/TIASound.hpp index c29f50411..ec41e40de 100644 --- a/Machines/Atari/2600/TIASound.hpp +++ b/Machines/Atari/2600/TIASound.hpp @@ -16,7 +16,7 @@ namespace Atari2600 { // This should be a divisor of 38; audio counters are updated every 38 cycles, though lesser dividers // will give greater resolution to changes in audio state. 1, 2 and 19 are the only divisors of 38. -const int CPUTicksPerAudioTick = 2; +constexpr int CPUTicksPerAudioTick = 2; class TIASound: public Outputs::Speaker::SampleSource { public: diff --git a/Machines/Atari/ST/AtariST.cpp b/Machines/Atari/ST/AtariST.cpp index 9d2c00a85..52c66b41c 100644 --- a/Machines/Atari/ST/AtariST.cpp +++ b/Machines/Atari/ST/AtariST.cpp @@ -47,7 +47,7 @@ std::vector> get_options() { ); } -const int CLOCK_RATE = 8021247; +constexpr int CLOCK_RATE = 8021247; using Target = Analyser::Static::Target; class ConcreteMachine: diff --git a/Machines/Atari/ST/Video.cpp b/Machines/Atari/ST/Video.cpp index b321e01fe..97ccbd842 100644 --- a/Machines/Atari/ST/Video.cpp +++ b/Machines/Atari/ST/Video.cpp @@ -626,9 +626,9 @@ void Video::Shifter::output_pixels(int duration, OutputBpp bpp) { } break; case OutputBpp::Two: { #if TARGET_RT_BIG_ENDIAN - const int upper = 0; + constexpr int upper = 0; #else - const int upper = 1; + constexpr int upper = 1; #endif if(pixel_buffer_) { while(duration--) { diff --git a/Machines/ColecoVision/ColecoVision.cpp b/Machines/ColecoVision/ColecoVision.cpp index 965cc7604..1ed351b38 100644 --- a/Machines/ColecoVision/ColecoVision.cpp +++ b/Machines/ColecoVision/ColecoVision.cpp @@ -27,7 +27,7 @@ #include "../../Analyser/Dynamic/ConfidenceCounter.hpp" namespace { -const int sn76489_divider = 2; +constexpr int sn76489_divider = 2; } namespace Coleco { diff --git a/Machines/Electron/SoundGenerator.hpp b/Machines/Electron/SoundGenerator.hpp index 6a4a1308f..9df5769da 100644 --- a/Machines/Electron/SoundGenerator.hpp +++ b/Machines/Electron/SoundGenerator.hpp @@ -22,7 +22,7 @@ class SoundGenerator: public ::Outputs::Speaker::SampleSource { void set_is_enabled(bool is_enabled); - static const unsigned int clock_rate_divider = 8; + static constexpr unsigned int clock_rate_divider = 8; // To satisfy ::SampleSource. void get_samples(std::size_t number_of_samples, int16_t *target); diff --git a/Machines/Electron/Video.cpp b/Machines/Electron/Video.cpp index 9b7ac2f1c..97aeb31ec 100644 --- a/Machines/Electron/Video.cpp +++ b/Machines/Electron/Video.cpp @@ -16,24 +16,24 @@ using namespace Electron; #define graphics_column(v) ((((v) & 127) - first_graphics_cycle + 128) & 127) namespace { - static const int cycles_per_line = 128; - static const int lines_per_frame = 625; - static const int cycles_per_frame = lines_per_frame * cycles_per_line; - static const int crt_cycles_multiplier = 8; - static const int crt_cycles_per_line = crt_cycles_multiplier * cycles_per_line; + static constexpr int cycles_per_line = 128; + static constexpr int lines_per_frame = 625; + static constexpr int cycles_per_frame = lines_per_frame * cycles_per_line; + static constexpr int crt_cycles_multiplier = 8; + static constexpr int crt_cycles_per_line = crt_cycles_multiplier * cycles_per_line; - static const int field_divider_line = 312; // i.e. the line, simultaneous with which, the first field's sync ends. So if - // the first line with pixels in field 1 is the 20th in the frame, the first line - // with pixels in field 2 will be 20+field_divider_line - static const int first_graphics_line = 31; - static const int first_graphics_cycle = 33; + static constexpr int field_divider_line = 312; // i.e. the line, simultaneous with which, the first field's sync ends. So if + // the first line with pixels in field 1 is the 20th in the frame, the first line + // with pixels in field 2 will be 20+field_divider_line + static constexpr int first_graphics_line = 31; + static constexpr int first_graphics_cycle = 33; - static const int display_end_interrupt_line = 256; + static constexpr int display_end_interrupt_line = 256; - static const int real_time_clock_interrupt_1 = 16704; - static const int real_time_clock_interrupt_2 = 56704; - static const int display_end_interrupt_1 = (first_graphics_line + display_end_interrupt_line)*cycles_per_line; - static const int display_end_interrupt_2 = (first_graphics_line + field_divider_line + display_end_interrupt_line)*cycles_per_line; + static constexpr int real_time_clock_interrupt_1 = 16704; + static constexpr int real_time_clock_interrupt_2 = 56704; + static constexpr int display_end_interrupt_1 = (first_graphics_line + display_end_interrupt_line)*cycles_per_line; + static constexpr int display_end_interrupt_2 = (first_graphics_line + field_divider_line + display_end_interrupt_line)*cycles_per_line; } // MARK: - Lifecycle @@ -272,7 +272,7 @@ void VideoOutput::set_register(int address, uint8_t value) { break; case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: case 0x0e: case 0x0f: { - static const int registers[4][4] = { + constexpr int registers[4][4] = { {10, 8, 2, 0}, {14, 12, 6, 4}, {15, 13, 7, 5}, diff --git a/Machines/MasterSystem/MasterSystem.cpp b/Machines/MasterSystem/MasterSystem.cpp index b32453eda..df0c3997d 100644 --- a/Machines/MasterSystem/MasterSystem.cpp +++ b/Machines/MasterSystem/MasterSystem.cpp @@ -29,7 +29,7 @@ #include namespace { -const int sn76489_divider = 2; +constexpr int sn76489_divider = 2; } namespace Sega { diff --git a/OSBindings/SDL/main.cpp b/OSBindings/SDL/main.cpp index 2a45c8a09..52dd42892 100644 --- a/OSBindings/SDL/main.cpp +++ b/OSBindings/SDL/main.cpp @@ -43,7 +43,7 @@ struct BestEffortUpdaterDelegate: public Concurrency::BestEffortUpdater::Delegat struct SpeakerDelegate: public Outputs::Speaker::Speaker::Delegate { // This is set to a relatively large number for now. - static const int buffer_size = 1024; + static constexpr int buffer_size = 1024; void speaker_did_complete_samples(Outputs::Speaker::Speaker *speaker, const std::vector &buffer) override { std::lock_guard lock_guard(audio_buffer_mutex_); @@ -106,7 +106,7 @@ class ActivityObserver: public Activity::Observer { lights_.clear(); // Generate a bunch of LEDs for connected drives. - const float height = 0.05f; + constexpr float height = 0.05f; const float width = height / aspect_ratio; const float right_x = 1.0f - 2.0f * width; float y = 1.0f - 2.0f * height; diff --git a/Outputs/CRT/CRT.cpp b/Outputs/CRT/CRT.cpp index fa73fb94b..c97a34f2f 100644 --- a/Outputs/CRT/CRT.cpp +++ b/Outputs/CRT/CRT.cpp @@ -17,15 +17,15 @@ using namespace Outputs::CRT; void CRT::set_new_timing(int cycles_per_line, int height_of_display, Outputs::Display::ColourSpace colour_space, int colour_cycle_numerator, int colour_cycle_denominator, int vertical_sync_half_lines, bool should_alternate) { - const int millisecondsHorizontalRetraceTime = 7; // Source: Dictionary of Video and Television Technology, p. 234. - const int scanlinesVerticalRetraceTime = 8; // Source: ibid. + constexpr int millisecondsHorizontalRetraceTime = 7; // Source: Dictionary of Video and Television Technology, p. 234. + constexpr int scanlinesVerticalRetraceTime = 8; // Source: ibid. - // To quote: - // - // "retrace interval; The interval of time for the return of the blanked scanning beam of - // a TV picture tube or camera tube to the starting point of a line or field. It is about - // 7 microseconds for horizontal retrace and 500 to 750 microseconds for vertical retrace - // in NTSC and PAL TV." + // To quote: + // + // "retrace interval; The interval of time for the return of the blanked scanning beam of + // a TV picture tube or camera tube to the starting point of a line or field. It is about + // 7 microseconds for horizontal retrace and 500 to 750 microseconds for vertical retrace + // in NTSC and PAL TV." time_multiplier_ = 65535 / cycles_per_line; phase_denominator_ = int64_t(cycles_per_line) * int64_t(colour_cycle_denominator) * int64_t(time_multiplier_); diff --git a/Processors/68000/68000.hpp b/Processors/68000/68000.hpp index 25fa263f1..6a7f0399b 100644 --- a/Processors/68000/68000.hpp +++ b/Processors/68000/68000.hpp @@ -51,45 +51,45 @@ namespace MC68000 { struct Microcycle { /// Indicates that the address strobe and exactly one of the data strobes are active; you can determine /// which by inspecting the low bit of the provided address. The RW line indicates a read. - static const int SelectByte = 1 << 0; + static constexpr int SelectByte = 1 << 0; // Maintenance note: this is bit 0 to reduce the cost of getting a host-endian // bytewise address. The assumption that it is bit 0 is also used for branchless // selection in a few places. See implementation of host_endian_byte_address(), // value8_high(), value8_low() and value16(). /// Indicates that the address and both data select strobes are active. - static const int SelectWord = 1 << 1; + static constexpr int SelectWord = 1 << 1; /// A NewAddress cycle is one in which the address strobe is initially low but becomes high; /// this correlates to states 0 to 5 of a standard read/write cycle. - static const int NewAddress = 1 << 2; + static constexpr int NewAddress = 1 << 2; /// A SameAddress cycle is one in which the address strobe is continuously asserted, but neither /// of the data strobes are. - static const int SameAddress = 1 << 3; + static constexpr int SameAddress = 1 << 3; /// A Reset cycle is one in which the RESET output is asserted. - static const int Reset = 1 << 4; + static constexpr int Reset = 1 << 4; /// If set, indicates a read. Otherwise, a write. - static const int Read = 1 << 5; + static constexpr int Read = 1 << 5; /// Contains the value of line FC0 if it is not implicit via InterruptAcknowledge. - static const int IsData = 1 << 6; + static constexpr int IsData = 1 << 6; /// Contains the value of line FC1 if it is not implicit via InterruptAcknowledge. - static const int IsProgram = 1 << 7; + static constexpr int IsProgram = 1 << 7; /// The interrupt acknowledge cycle is that during which the 68000 seeks to obtain the vector for /// an interrupt it plans to observe. Noted on a real 68000 by all FCs being set to 1. - static const int InterruptAcknowledge = 1 << 8; + static constexpr int InterruptAcknowledge = 1 << 8; /// Represents the state of the 68000's valid memory address line — indicating whether this microcycle /// is synchronised with the E clock to satisfy a valid peripheral address request. - static const int IsPeripheral = 1 << 9; + static constexpr int IsPeripheral = 1 << 9; /// Provides the 68000's bus grant line — indicating whether a bus request has been acknowledged. - static const int BusGrant = 1 << 10; + static constexpr int BusGrant = 1 << 10; /// Contains a valid combination of the various static const int flags, describing the operation /// performed by this Microcycle. diff --git a/Processors/68000/Implementation/68000Storage.hpp b/Processors/68000/Implementation/68000Storage.hpp index 772bf0d92..2670ce6fc 100644 --- a/Processors/68000/Implementation/68000Storage.hpp +++ b/Processors/68000/Implementation/68000Storage.hpp @@ -317,8 +317,8 @@ class ProcessorStorage { // steps detail appropriately. PrepareINTVector, }; - static const int SourceMask = 1 << 7; - static const int DestinationMask = 1 << 6; + static constexpr int SourceMask = 1 << 7; + static constexpr int DestinationMask = 1 << 6; uint8_t action = uint8_t(Action::None); static const uint16_t NoBusProgram = std::numeric_limits::max(); diff --git a/Storage/Disk/DiskImage/Formats/AcornADF.cpp b/Storage/Disk/DiskImage/Formats/AcornADF.cpp index 75546b1cc..d7ba4f197 100644 --- a/Storage/Disk/DiskImage/Formats/AcornADF.cpp +++ b/Storage/Disk/DiskImage/Formats/AcornADF.cpp @@ -11,8 +11,8 @@ #include "Utility/ImplicitSectors.hpp" namespace { - static const int sectors_per_track = 16; - static const int sector_size = 1; + constexpr int sectors_per_track = 16; + constexpr int sector_size = 1; } using namespace Storage::Disk; diff --git a/Storage/Disk/DiskImage/Formats/AppleDSK.cpp b/Storage/Disk/DiskImage/Formats/AppleDSK.cpp index 879abb303..a12b59b91 100644 --- a/Storage/Disk/DiskImage/Formats/AppleDSK.cpp +++ b/Storage/Disk/DiskImage/Formats/AppleDSK.cpp @@ -18,8 +18,8 @@ using namespace Storage::Disk; namespace { - const int number_of_tracks = 35; - const int bytes_per_sector = 256; + constexpr int number_of_tracks = 35; + constexpr int bytes_per_sector = 256; } AppleDSK::AppleDSK(const std::string &file_name) : diff --git a/Storage/Disk/DiskImage/Formats/MSXDSK.cpp b/Storage/Disk/DiskImage/Formats/MSXDSK.cpp index 7ed36d5fc..25f9788da 100644 --- a/Storage/Disk/DiskImage/Formats/MSXDSK.cpp +++ b/Storage/Disk/DiskImage/Formats/MSXDSK.cpp @@ -11,9 +11,9 @@ #include "Utility/ImplicitSectors.hpp" namespace { - const int sectors_per_track = 9; - const int sector_size = 2; - const off_t track_size = (128 << sector_size)*sectors_per_track; + constexpr int sectors_per_track = 9; + constexpr int sector_size = 2; + constexpr off_t track_size = (128 << sector_size)*sectors_per_track; } using namespace Storage::Disk; diff --git a/Storage/Disk/DiskImage/Formats/SSD.cpp b/Storage/Disk/DiskImage/Formats/SSD.cpp index 7e455e69e..455fddc4a 100644 --- a/Storage/Disk/DiskImage/Formats/SSD.cpp +++ b/Storage/Disk/DiskImage/Formats/SSD.cpp @@ -9,8 +9,8 @@ #include "SSD.hpp" namespace { - static const int sectors_per_track = 10; - static const int sector_size = 1; + constexpr int sectors_per_track = 10; + constexpr int sector_size = 1; } using namespace Storage::Disk; diff --git a/Storage/Disk/DiskImage/Formats/ST.cpp b/Storage/Disk/DiskImage/Formats/ST.cpp index 2b3a069f2..7c4a05194 100644 --- a/Storage/Disk/DiskImage/Formats/ST.cpp +++ b/Storage/Disk/DiskImage/Formats/ST.cpp @@ -9,8 +9,8 @@ #include "ST.hpp" namespace { - static const int sectors_per_track = 10; - static const int sector_size = 2; + constexpr int sectors_per_track = 10; + constexpr int sector_size = 2; } using namespace Storage::Disk; diff --git a/Storage/Disk/Drive.cpp b/Storage/Disk/Drive.cpp index 04d126603..5bb509dad 100644 --- a/Storage/Disk/Drive.cpp +++ b/Storage/Disk/Drive.cpp @@ -122,7 +122,7 @@ bool Drive::get_tachometer() { // I have made a guess here that the tachometer is a symmetric square wave; // if that is correct then around 60 beats per rotation appears to be correct // to proceed beyond the speed checks I've so far uncovered. - const float ticks_per_rotation = 60.0f; // 56 was too low; 64 too high. + constexpr float ticks_per_rotation = 60.0f; // 56 was too low; 64 too high. return int(get_rotation() * 2.0f * ticks_per_rotation) & 1; } @@ -264,7 +264,7 @@ void Drive::get_next_event(float duration_already_passed) { // An interval greater than 15ms => adjust gain up the point where noise starts happening. // Seed that up and leave a 15ms gap until it starts. - const float safe_gain_period = 15.0f / 1000000.0f; + constexpr float safe_gain_period = 15.0f / 1000000.0f; if(interval >= safe_gain_period) { random_interval_ = interval - safe_gain_period; interval = safe_gain_period; diff --git a/Storage/MassStorage/SCSI/SCSI.hpp b/Storage/MassStorage/SCSI/SCSI.hpp index 4caf3f667..48dcb9a72 100644 --- a/Storage/MassStorage/SCSI/SCSI.hpp +++ b/Storage/MassStorage/SCSI/SCSI.hpp @@ -21,7 +21,7 @@ namespace SCSI { typedef int BusState; -static const BusState DefaultBusState = 0; +static constexpr BusState DefaultBusState = 0; /*! SCSI bus state is encoded entirely within an int. diff --git a/Storage/Tape/Formats/TapePRG.cpp b/Storage/Tape/Formats/TapePRG.cpp index 868b66d37..288ebcef3 100644 --- a/Storage/Tape/Formats/TapePRG.cpp +++ b/Storage/Tape/Formats/TapePRG.cpp @@ -65,10 +65,10 @@ PRG::PRG(const std::string &file_name) : Storage::Tape::Tape::Pulse PRG::virtual_get_next_pulse() { // these are all microseconds per pole - static const unsigned int leader_zero_length = 179; - static const unsigned int zero_length = 169; - static const unsigned int one_length = 247; - static const unsigned int marker_length = 328; + constexpr unsigned int leader_zero_length = 179; + constexpr unsigned int zero_length = 169; + constexpr unsigned int one_length = 247; + constexpr unsigned int marker_length = 328; bit_phase_ = (bit_phase_+1)&3; if(!bit_phase_) get_next_output_token(); @@ -100,10 +100,10 @@ bool PRG::is_at_end() { } void PRG::get_next_output_token() { - static const int block_length = 192; // not counting the checksum - static const int countdown_bytes = 9; - static const int leadin_length = 20000; - static const int block_leadin_length = 5000; + constexpr int block_length = 192; // not counting the checksum + constexpr int countdown_bytes = 9; + constexpr int leadin_length = 20000; + constexpr int block_leadin_length = 5000; if(file_phase_ == FilePhaseHeaderDataGap || file_phase_ == FilePhaseAtEnd) { output_token_ = Silence; diff --git a/Storage/Tape/Parsers/Acorn.cpp b/Storage/Tape/Parsers/Acorn.cpp index dc5193e7f..7101a3d05 100644 --- a/Storage/Tape/Parsers/Acorn.cpp +++ b/Storage/Tape/Parsers/Acorn.cpp @@ -11,7 +11,7 @@ using namespace Storage::Tape::Acorn; namespace { -const int PLLClockRate = 1920000; +constexpr int PLLClockRate = 1920000; } Parser::Parser(): crc_(0x1021) { diff --git a/Storage/Tape/Parsers/MSX.cpp b/Storage/Tape/Parsers/MSX.cpp index 723f44fbe..c39ce7238 100644 --- a/Storage/Tape/Parsers/MSX.cpp +++ b/Storage/Tape/Parsers/MSX.cpp @@ -101,7 +101,7 @@ int Parser::get_byte(const FileSpeed &speed, Storage::Tape::BinaryTapePlayer &ta So I'm going to look for the next two consecutive pulses that are each big enough to be half of a zero. */ - const float minimum_start_bit_duration = static_cast(speed.minimum_start_bit_duration) * 0.00001145f * 0.5f; + const float minimum_start_bit_duration = float(speed.minimum_start_bit_duration) * 0.00001145f * 0.5f; int input = 0; while(!tape_player.get_tape()->is_at_end()) { // Find next transition. @@ -126,9 +126,9 @@ int Parser::get_byte(const FileSpeed &speed, Storage::Tape::BinaryTapePlayer &ta int result = 0; const int cycles_per_window = static_cast( 0.5f + - static_cast(speed.low_high_disrimination_duration) * + float(speed.low_high_disrimination_duration) * 0.0000173f * - static_cast(tape_player.get_input_clock_rate()) + float(tape_player.get_input_clock_rate()) ); int bits_left = 8; bool level = tape_player.get_input(); @@ -137,7 +137,7 @@ int Parser::get_byte(const FileSpeed &speed, Storage::Tape::BinaryTapePlayer &ta int transitions = 0; int cycles_remaining = cycles_per_window; while(!tape_player.get_tape()->is_at_end() && cycles_remaining) { - const int cycles_until_next_event = static_cast(tape_player.get_cycles_until_next_event()); + const int cycles_until_next_event = int(tape_player.get_cycles_until_next_event()); const int cycles_to_run_for = std::min(cycles_until_next_event, cycles_remaining); cycles_remaining -= cycles_to_run_for; diff --git a/Storage/Tape/Parsers/ZX8081.cpp b/Storage/Tape/Parsers/ZX8081.cpp index 10754909f..3b8e893bb 100644 --- a/Storage/Tape/Parsers/ZX8081.cpp +++ b/Storage/Tape/Parsers/ZX8081.cpp @@ -29,9 +29,9 @@ void Parser::process_pulse(const Storage::Tape::Tape::Pulse &pulse) { } void Parser::post_pulse() { - const float expected_pulse_length = 300.0f / 1000000.0f; - const float expected_gap_length = 1300.0f / 1000000.0f; - float pulse_time = pulse_time_.get(); + constexpr float expected_pulse_length = 300.0f / 1000000.0f; + constexpr float expected_gap_length = 1300.0f / 1000000.0f; + auto pulse_time = pulse_time_.get(); if(pulse_time > expected_gap_length * 1.25f) { push_wave(WaveType::LongGap);