2016-08-27 13:42:51 -04:00
|
|
|
//
|
|
|
|
// Tape.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 24/08/2016.
|
2018-05-13 15:19:52 -04:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-08-27 13:42:51 -04:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "Tape.hpp"
|
2016-09-06 06:39:40 -04:00
|
|
|
|
2018-01-24 21:48:44 -05:00
|
|
|
#include "../../../Storage/Tape/Parsers/Commodore.hpp"
|
2016-09-06 06:59:51 -04:00
|
|
|
|
2018-01-24 21:48:44 -05:00
|
|
|
using namespace Analyser::Static::Commodore;
|
2016-09-06 06:39:40 -04:00
|
|
|
|
2018-01-24 21:48:44 -05:00
|
|
|
std::vector<File> Analyser::Static::Commodore::GetFiles(const std::shared_ptr<Storage::Tape::Tape> &tape) {
|
2016-11-06 16:13:13 -05:00
|
|
|
Storage::Tape::Commodore::Parser parser;
|
2018-01-23 22:18:16 -05:00
|
|
|
std::vector<File> file_list;
|
2016-09-07 07:34:48 -04:00
|
|
|
|
2016-11-06 16:13:13 -05:00
|
|
|
std::unique_ptr<Storage::Tape::Commodore::Header> header = parser.get_next_header(tape);
|
2016-09-06 06:39:40 -04:00
|
|
|
|
2017-03-26 14:34:47 -04:00
|
|
|
while(!tape->is_at_end()) {
|
|
|
|
if(!header) {
|
2016-11-06 15:25:18 -05:00
|
|
|
header = parser.get_next_header(tape);
|
2016-09-07 07:34:48 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-03-26 14:34:47 -04:00
|
|
|
switch(header->type) {
|
|
|
|
case Storage::Tape::Commodore::Header::DataSequenceHeader: {
|
2016-09-07 07:34:48 -04: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 14:34:47 -04:00
|
|
|
while(!tape->is_at_end()) {
|
2016-11-06 15:25:18 -05:00
|
|
|
header = parser.get_next_header(tape);
|
2016-09-08 21:09:05 -04:00
|
|
|
if(!header) continue;
|
2016-11-06 16:13:13 -05:00
|
|
|
if(header->type != Storage::Tape::Commodore::Header::DataBlock) break;
|
2016-09-07 07:34:48 -04: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 16:13:13 -05:00
|
|
|
case Storage::Tape::Commodore::Header::RelocatableProgram:
|
2017-03-26 14:34:47 -04:00
|
|
|
case Storage::Tape::Commodore::Header::NonRelocatableProgram: {
|
2016-11-06 16:13:13 -05:00
|
|
|
std::unique_ptr<Storage::Tape::Commodore::Data> data = parser.get_next_data(tape);
|
2017-03-26 14:34:47 -04:00
|
|
|
if(data) {
|
2016-09-08 07:39:43 -04: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 16:13:13 -05:00
|
|
|
new_file.type = (header->type == Storage::Tape::Commodore::Header::RelocatableProgram) ? File::RelocatableProgram : File::NonRelocatableProgram;
|
2016-09-08 07:39:43 -04:00
|
|
|
|
|
|
|
file_list.push_back(new_file);
|
|
|
|
}
|
2016-09-07 07:34:48 -04:00
|
|
|
|
2016-11-06 15:25:18 -05:00
|
|
|
header = parser.get_next_header(tape);
|
2016-09-07 07:34:48 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2016-11-06 15:25:18 -05:00
|
|
|
header = parser.get_next_header(tape);
|
2016-09-07 07:34:48 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-06 06:39:40 -04:00
|
|
|
return file_list;
|
|
|
|
}
|