2018-02-24 03:47:15 +00:00
|
|
|
//
|
|
|
|
// StaticAnalyser.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 23/02/2018.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2018 Thomas Harte. All rights reserved.
|
2018-02-24 03:47:15 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "StaticAnalyser.hpp"
|
|
|
|
|
|
|
|
static std::vector<std::shared_ptr<Storage::Cartridge::Cartridge>>
|
2024-11-30 02:08:35 +00:00
|
|
|
ColecoCartridgesFrom(const std::vector<std::shared_ptr<Storage::Cartridge::Cartridge>> &cartridges) {
|
2018-02-24 03:47:15 +00:00
|
|
|
std::vector<std::shared_ptr<Storage::Cartridge::Cartridge>> coleco_cartridges;
|
|
|
|
|
|
|
|
for(const auto &cartridge : cartridges) {
|
|
|
|
const auto &segments = cartridge->get_segments();
|
|
|
|
|
|
|
|
// only one mapped item is allowed
|
|
|
|
if(segments.size() != 1) continue;
|
|
|
|
const Storage::Cartridge::Cartridge::Segment &segment = segments.front();
|
|
|
|
const std::size_t data_size = segment.data.size();
|
2018-03-02 23:40:01 +00:00
|
|
|
|
|
|
|
// the two bytes that will be first must be 0xaa and 0x55, either way around
|
|
|
|
auto *start = &segment.data[0];
|
2020-05-10 03:00:39 +00:00
|
|
|
if((data_size & size_t(~8191)) > 32768) {
|
2018-03-02 23:40:01 +00:00
|
|
|
start = &segment.data[segment.data.size() - 16384];
|
|
|
|
}
|
|
|
|
if(start[0] != 0xaa && start[0] != 0x55 && start[1] != 0xaa && start[1] != 0x55) continue;
|
|
|
|
if(start[0] == start[1]) continue;
|
2018-02-24 03:47:15 +00:00
|
|
|
|
|
|
|
// probability of a random binary blob that isn't a Coleco ROM proceeding to here is 1 - 1/32768.
|
2018-03-03 00:20:37 +00:00
|
|
|
|
2018-08-05 01:40:02 +00:00
|
|
|
// Round up to the next multiple of 8kb if this image is less than 32kb. Otherwise round down if
|
|
|
|
// this image is within a short distance of 32kb.
|
|
|
|
std::vector<Storage::Cartridge::Cartridge::Segment> output_segments;
|
2018-03-03 00:20:37 +00:00
|
|
|
|
2018-08-05 01:40:02 +00:00
|
|
|
size_t target_size;
|
|
|
|
if(data_size >= 32*1024 && data_size < 32*1024 + 512) {
|
|
|
|
target_size = 32 * 1024;
|
|
|
|
} else {
|
|
|
|
target_size = data_size + ((8192 - (data_size & 8191)) & 8191);
|
2018-03-03 00:20:37 +00:00
|
|
|
}
|
2018-08-05 01:40:02 +00:00
|
|
|
|
|
|
|
std::vector<uint8_t> truncated_data;
|
|
|
|
truncated_data = segment.data;
|
|
|
|
truncated_data.resize(target_size);
|
|
|
|
output_segments.emplace_back(0x8000, truncated_data);
|
|
|
|
|
|
|
|
coleco_cartridges.emplace_back(new Storage::Cartridge::Cartridge(output_segments));
|
2018-02-24 03:47:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return coleco_cartridges;
|
|
|
|
}
|
|
|
|
|
2024-11-30 02:08:35 +00:00
|
|
|
Analyser::Static::TargetList Analyser::Static::Coleco::GetTargets(
|
|
|
|
const Media &media,
|
|
|
|
const std::string &,
|
|
|
|
TargetPlatform::IntType
|
|
|
|
) {
|
2018-04-14 16:12:12 +00:00
|
|
|
TargetList targets;
|
2020-03-15 04:13:38 +00:00
|
|
|
auto target = std::make_unique<Target>(Machine::ColecoVision);
|
2018-03-07 19:25:25 +00:00
|
|
|
target->confidence = 1.0f - 1.0f / 32768.0f;
|
2018-02-24 03:47:15 +00:00
|
|
|
target->media.cartridges = ColecoCartridgesFrom(media.cartridges);
|
|
|
|
if(!target->media.empty())
|
2018-04-14 16:12:12 +00:00
|
|
|
targets.push_back(std::move(target));
|
|
|
|
return targets;
|
2018-02-24 03:47:15 +00:00
|
|
|
}
|