From a847654ef2b4a4d85f058d2113f23bfcfc9d4c76 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 22 Dec 2019 00:00:23 -0500 Subject: [PATCH] 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); };