mirror of
https://github.com/TomHarte/CLK.git
synced 2025-04-10 22:37:30 +00:00
Corrects various old-fashioned bits of indentation, plus the odd const.
This commit is contained in:
parent
05d77d3297
commit
a847654ef2
@ -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) {\
|
||||
|
@ -10,8 +10,7 @@
|
||||
|
||||
@implementation NSData (StdVector)
|
||||
|
||||
- (std::vector<uint8_t>)stdVector8
|
||||
{
|
||||
- (std::vector<uint8_t>)stdVector8 {
|
||||
uint8_t *bytes8 = (uint8_t *)self.bytes;
|
||||
return std::vector<uint8_t>(bytes8, bytes8 + self.length);
|
||||
}
|
||||
|
@ -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<NSString *, AtariROMRecord *> *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
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -15,21 +15,18 @@
|
||||
|
||||
@implementation PCMSegmentEventSourceTests
|
||||
|
||||
- (Storage::Disk::PCMSegmentEventSource)segmentSource
|
||||
{
|
||||
- (Storage::Disk::PCMSegmentEventSource)segmentSource {
|
||||
std::vector<uint8_t> 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);
|
||||
|
||||
|
@ -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_;
|
||||
}
|
||||
|
@ -77,8 +77,7 @@ std::unique_ptr<Header> Parser::get_next_header_body(const std::shared_ptr<Stora
|
||||
|
||||
// get header type
|
||||
uint8_t header_type = get_next_byte(tape);
|
||||
switch(header_type)
|
||||
{
|
||||
switch(header_type) {
|
||||
default: header->type = Header::Unknown; break;
|
||||
case 0x01: header->type = Header::RelocatableProgram; break;
|
||||
case 0x02: header->type = Header::DataBlock; break;
|
||||
@ -89,8 +88,7 @@ std::unique_ptr<Header> Parser::get_next_header_body(const std::shared_ptr<Stora
|
||||
|
||||
// grab rest of data
|
||||
header->data.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<Header> Parser::get_next_header_body(const std::shared_ptr<Stora
|
||||
header->parity_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<uint16_t>(header->data[0] | (header->data[1] << 8));
|
||||
header->ending_address = static_cast<uint16_t>(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);
|
||||
|
@ -10,15 +10,13 @@
|
||||
|
||||
using namespace Storage::Tape::Oric;
|
||||
|
||||
int Parser::get_next_byte(const std::shared_ptr<Storage::Tape::Tape> &tape, bool use_fast_encoding)
|
||||
{
|
||||
int Parser::get_next_byte(const std::shared_ptr<Storage::Tape::Tape> &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<Storage::Tape::Tape> &tape, bool
|
||||
return tape->is_at_end() ? -1 : ((result >> 1)&0xff);
|
||||
}
|
||||
|
||||
bool Parser::sync_and_get_encoding_speed(const std::shared_ptr<Storage::Tape::Tape> &tape)
|
||||
{
|
||||
bool Parser::sync_and_get_encoding_speed(const std::shared_ptr<Storage::Tape::Tape> &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<Storage::Tape::Ta
|
||||
return false;
|
||||
}
|
||||
|
||||
void Parser::process_pulse(const Storage::Tape::Tape::Pulse &pulse)
|
||||
{
|
||||
const float maximum_short_length = 0.000512f;
|
||||
const float maximum_medium_length = 0.000728f;
|
||||
const float maximum_long_length = 0.001456f;
|
||||
void Parser::process_pulse(const Storage::Tape::Tape::Pulse &pulse) {
|
||||
constexpr float maximum_short_length = 0.000512f;
|
||||
constexpr float maximum_medium_length = 0.000728f;
|
||||
constexpr float maximum_long_length = 0.001456f;
|
||||
|
||||
bool wave_is_high = pulse.type == Storage::Tape::Tape::Pulse::High;
|
||||
if(!wave_was_high_ && wave_is_high != wave_was_high_)
|
||||
{
|
||||
if(!wave_was_high_ && wave_is_high != wave_was_high_) {
|
||||
if(cycle_length_ < maximum_short_length) push_wave(WaveType::Short);
|
||||
else if(cycle_length_ < maximum_medium_length) push_wave(WaveType::Medium);
|
||||
else if(cycle_length_ < maximum_long_length) push_wave(WaveType::Long);
|
||||
@ -65,14 +58,11 @@ void Parser::process_pulse(const Storage::Tape::Tape::Pulse &pulse)
|
||||
cycle_length_ += pulse.length.get<float>();
|
||||
}
|
||||
|
||||
void Parser::inspect_waves(const std::vector<WaveType> &waves)
|
||||
{
|
||||
switch(detection_mode_)
|
||||
{
|
||||
void Parser::inspect_waves(const std::vector<WaveType> &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<WaveType> &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<WaveType> &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<WaveType> &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<WaveType> &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<WaveType> &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<WaveType> &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<int>(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<WaveType> &waves)
|
||||
remove_waves(1);
|
||||
}
|
||||
|
||||
std::size_t Parser::pattern_matching_depth(const std::vector<WaveType> &waves, Pattern *pattern)
|
||||
{
|
||||
std::size_t Parser::pattern_matching_depth(const std::vector<WaveType> &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++;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ class Parser: public Storage::Tape::PulseClassificationParser<WaveType, SymbolTy
|
||||
WaveType type;
|
||||
int count;
|
||||
};
|
||||
std::size_t pattern_matching_depth(const std::vector<WaveType> &waves, Pattern *pattern);
|
||||
std::size_t pattern_matching_depth(const std::vector<WaveType> &waves, const Pattern *pattern);
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user