2017-06-04 17:04:06 -04:00
|
|
|
//
|
|
|
|
// StaticAnalyser.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 04/06/2017.
|
2018-05-13 15:19:52 -04:00
|
|
|
// Copyright 2017 Thomas Harte. All rights reserved.
|
2017-06-04 17:04:06 -04:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "StaticAnalyser.hpp"
|
|
|
|
|
2017-06-07 17:30:53 -04:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2018-03-09 15:36:11 -05:00
|
|
|
#include "Target.hpp"
|
2018-01-24 21:48:44 -05:00
|
|
|
#include "../../../Storage/Tape/Parsers/ZX8081.hpp"
|
2017-06-07 17:30:53 -04:00
|
|
|
|
2017-06-08 19:09:51 -04:00
|
|
|
static std::vector<Storage::Data::ZX8081::File> GetFiles(const std::shared_ptr<Storage::Tape::Tape> &tape) {
|
|
|
|
std::vector<Storage::Data::ZX8081::File> files;
|
2017-06-07 17:30:53 -04:00
|
|
|
Storage::Tape::ZX8081::Parser parser;
|
|
|
|
|
|
|
|
while(!tape->is_at_end()) {
|
2017-06-08 19:09:51 -04:00
|
|
|
std::shared_ptr<Storage::Data::ZX8081::File> next_file = parser.get_next_file(tape);
|
2017-06-07 17:30:53 -04:00
|
|
|
if(next_file != nullptr) {
|
|
|
|
files.push_back(*next_file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
2018-04-14 12:12:12 -04:00
|
|
|
Analyser::Static::TargetList Analyser::Static::ZX8081::GetTargets(const Media &media, const std::string &file_name, TargetPlatform::IntType potential_platforms) {
|
2018-04-14 19:46:38 -04:00
|
|
|
TargetList destination;
|
2017-08-17 10:48:29 -04:00
|
|
|
if(!media.tapes.empty()) {
|
|
|
|
std::vector<Storage::Data::ZX8081::File> files = GetFiles(media.tapes.front());
|
|
|
|
media.tapes.front()->reset();
|
2017-06-07 17:30:53 -04:00
|
|
|
if(!files.empty()) {
|
2018-03-09 15:36:11 -05:00
|
|
|
Target *target = new Target;
|
|
|
|
destination.push_back(std::unique_ptr<::Analyser::Static::Target>(target));
|
2018-01-24 22:35:54 -05:00
|
|
|
target->machine = Machine::ZX8081;
|
2017-08-27 15:20:22 -04:00
|
|
|
|
|
|
|
// Guess the machine type from the file only if it isn't already known.
|
|
|
|
switch(potential_platforms & (TargetPlatform::ZX80 | TargetPlatform::ZX81)) {
|
|
|
|
default:
|
2018-04-02 22:42:41 -04:00
|
|
|
target->is_ZX81 = files.front().isZX81;
|
2017-08-27 15:20:22 -04:00
|
|
|
break;
|
|
|
|
|
2018-04-02 22:42:41 -04:00
|
|
|
case TargetPlatform::ZX80: target->is_ZX81 = false; break;
|
2018-04-06 17:42:24 -04:00
|
|
|
case TargetPlatform::ZX81: target->is_ZX81 = true; break;
|
2017-08-27 15:20:22 -04:00
|
|
|
}
|
|
|
|
|
2017-07-21 20:43:56 -04:00
|
|
|
/*if(files.front().data.size() > 16384) {
|
2018-01-24 22:35:54 -05:00
|
|
|
target->zx8081.memory_model = ZX8081MemoryModel::SixtyFourKB;
|
2017-07-21 20:43:56 -04:00
|
|
|
} else*/ if(files.front().data.size() > 1024) {
|
2018-03-09 15:36:11 -05:00
|
|
|
target->memory_model = Target::MemoryModel::SixteenKB;
|
2017-06-11 19:12:20 -04:00
|
|
|
} else {
|
2018-03-09 15:36:11 -05:00
|
|
|
target->memory_model = Target::MemoryModel::Unexpanded;
|
2017-06-11 19:12:20 -04:00
|
|
|
}
|
2018-01-24 22:35:54 -05:00
|
|
|
target->media.tapes = media.tapes;
|
2017-07-09 22:07:12 -04:00
|
|
|
|
|
|
|
// TODO: how to run software once loaded? Might require a BASIC detokeniser.
|
2018-04-02 22:42:41 -04:00
|
|
|
if(target->is_ZX81) {
|
2018-01-24 22:35:54 -05:00
|
|
|
target->loading_command = "J\"\"\n";
|
2017-07-09 22:07:12 -04:00
|
|
|
} else {
|
2018-01-24 22:35:54 -05:00
|
|
|
target->loading_command = "W\n";
|
2017-07-09 22:07:12 -04:00
|
|
|
}
|
|
|
|
|
2017-06-07 17:30:53 -04:00
|
|
|
}
|
|
|
|
}
|
2018-04-14 12:12:12 -04:00
|
|
|
return destination;
|
2017-06-04 17:04:06 -04:00
|
|
|
}
|