1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-23 03:32:32 +00:00
CLK/Analyser/Static/Commodore/Tape.cpp

75 lines
2.1 KiB
C++
Raw Normal View History

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.
2016-08-27 17:42:51 +00:00
//
#include "Tape.hpp"
#include "../../../Storage/Tape/Parsers/Commodore.hpp"
using namespace Analyser::Static::Commodore;
std::vector<File> Analyser::Static::Commodore::GetFiles(const std::shared_ptr<Storage::Tape::Tape> &tape) {
Storage::Tape::Commodore::Parser parser;
std::vector<File> file_list;
std::unique_ptr<Storage::Tape::Commodore::Header> header = parser.get_next_header(tape);
2017-03-26 18:34:47 +00:00
while(!tape->is_at_end()) {
if(!header) {
header = parser.get_next_header(tape);
continue;
}
2017-03-26 18:34:47 +00:00
switch(header->type) {
case Storage::Tape::Commodore::Header::DataSequenceHeader: {
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()) {
header = parser.get_next_header(tape);
if(!header) continue;
if(header->type != Storage::Tape::Commodore::Header::DataBlock) break;
std::copy(header->data.begin(), header->data.end(), std::back_inserter(new_file.data));
}
file_list.push_back(new_file);
}
break;
case Storage::Tape::Commodore::Header::RelocatableProgram:
2017-03-26 18:34:47 +00:00
case Storage::Tape::Commodore::Header::NonRelocatableProgram: {
std::unique_ptr<Storage::Tape::Commodore::Data> data = parser.get_next_data(tape);
2017-03-26 18:34:47 +00:00
if(data) {
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);
new_file.type = (header->type == Storage::Tape::Commodore::Header::RelocatableProgram) ? File::RelocatableProgram : File::NonRelocatableProgram;
file_list.push_back(new_file);
}
header = parser.get_next_header(tape);
}
break;
default:
header = parser.get_next_header(tape);
break;
}
}
return file_list;
}