2016-08-27 17:42:51 +00:00
|
|
|
//
|
|
|
|
// Tape.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 24/08/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Tape.hpp"
|
2016-09-06 10:39:40 +00:00
|
|
|
|
2018-01-25 02:48:44 +00:00
|
|
|
#include "../../../Storage/Tape/Parsers/Commodore.hpp"
|
2016-09-06 10:59:51 +00:00
|
|
|
|
2018-01-25 02:48:44 +00:00
|
|
|
using namespace Analyser::Static::Commodore;
|
2016-09-06 10:39:40 +00:00
|
|
|
|
2018-01-25 02:48:44 +00:00
|
|
|
std::vector<File> Analyser::Static::Commodore::GetFiles(const std::shared_ptr<Storage::Tape::Tape> &tape) {
|
2016-11-06 21:13:13 +00:00
|
|
|
Storage::Tape::Commodore::Parser parser;
|
2018-01-24 03:18:16 +00:00
|
|
|
std::vector<File> file_list;
|
2016-09-07 11:34:48 +00:00
|
|
|
|
2016-11-06 21:13:13 +00:00
|
|
|
std::unique_ptr<Storage::Tape::Commodore::Header> header = parser.get_next_header(tape);
|
2016-09-06 10:39:40 +00:00
|
|
|
|
2017-03-26 18:34:47 +00:00
|
|
|
while(!tape->is_at_end()) {
|
|
|
|
if(!header) {
|
2016-11-06 20:25:18 +00:00
|
|
|
header = parser.get_next_header(tape);
|
2016-09-07 11:34:48 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-03-26 18:34:47 +00:00
|
|
|
switch(header->type) {
|
|
|
|
case Storage::Tape::Commodore::Header::DataSequenceHeader: {
|
2016-09-07 11:34:48 +00:00
|
|
|
File new_file;
|
|
|
|
new_file.name = header->name;
|
|
|
|
new_file.raw_name = header->raw_name;
|
|
|
|
new_file.starting_address = header->starting_address;
|
|
|
|
new_file.ending_address = header->ending_address;
|
|
|
|
new_file.type = File::DataSequence;
|
|
|
|
|
|
|
|
new_file.data.swap(header->data);
|
2017-03-26 18:34:47 +00:00
|
|
|
while(!tape->is_at_end()) {
|
2016-11-06 20:25:18 +00:00
|
|
|
header = parser.get_next_header(tape);
|
2016-09-09 01:09:05 +00:00
|
|
|
if(!header) continue;
|
2016-11-06 21:13:13 +00:00
|
|
|
if(header->type != Storage::Tape::Commodore::Header::DataBlock) break;
|
2016-09-07 11:34:48 +00:00
|
|
|
std::copy(header->data.begin(), header->data.end(), std::back_inserter(new_file.data));
|
|
|
|
}
|
|
|
|
|
|
|
|
file_list.push_back(new_file);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-11-06 21:13:13 +00:00
|
|
|
case Storage::Tape::Commodore::Header::RelocatableProgram:
|
2017-03-26 18:34:47 +00:00
|
|
|
case Storage::Tape::Commodore::Header::NonRelocatableProgram: {
|
2016-11-06 21:13:13 +00:00
|
|
|
std::unique_ptr<Storage::Tape::Commodore::Data> data = parser.get_next_data(tape);
|
2017-03-26 18:34:47 +00:00
|
|
|
if(data) {
|
2016-09-08 11:39:43 +00:00
|
|
|
File new_file;
|
|
|
|
new_file.name = header->name;
|
|
|
|
new_file.raw_name = header->raw_name;
|
|
|
|
new_file.starting_address = header->starting_address;
|
|
|
|
new_file.ending_address = header->ending_address;
|
|
|
|
new_file.data.swap(data->data);
|
2016-11-06 21:13:13 +00:00
|
|
|
new_file.type = (header->type == Storage::Tape::Commodore::Header::RelocatableProgram) ? File::RelocatableProgram : File::NonRelocatableProgram;
|
2016-09-08 11:39:43 +00:00
|
|
|
|
|
|
|
file_list.push_back(new_file);
|
|
|
|
}
|
2016-09-07 11:34:48 +00:00
|
|
|
|
2016-11-06 20:25:18 +00:00
|
|
|
header = parser.get_next_header(tape);
|
2016-09-07 11:34:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-11-06 20:25:18 +00:00
|
|
|
header = parser.get_next_header(tape);
|
2016-09-07 11:34:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-06 10:39:40 +00:00
|
|
|
return file_list;
|
|
|
|
}
|