2016-11-07 03:56:38 +00:00
|
|
|
//
|
|
|
|
// Tape.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 06/11/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-11-07 03:56:38 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "Tape.hpp"
|
2018-01-25 02:48:44 +00:00
|
|
|
#include "../../../Storage/Tape/Parsers/Oric.hpp"
|
2016-11-07 03:56:38 +00:00
|
|
|
|
2018-01-25 02:48:44 +00:00
|
|
|
using namespace Analyser::Static::Oric;
|
2016-11-07 03:56:38 +00:00
|
|
|
|
2018-01-25 02:48:44 +00:00
|
|
|
std::vector<File> Analyser::Static::Oric::GetFiles(const std::shared_ptr<Storage::Tape::Tape> &tape) {
|
2018-01-24 03:18:16 +00:00
|
|
|
std::vector<File> files;
|
2016-11-07 03:56:38 +00:00
|
|
|
Storage::Tape::Oric::Parser parser;
|
|
|
|
|
2017-03-26 18:34:47 +00:00
|
|
|
while(!tape->is_at_end()) {
|
2016-11-07 03:56:38 +00:00
|
|
|
// sync to next lead-in, check that it's one of three 0x16s
|
|
|
|
bool is_fast = parser.sync_and_get_encoding_speed(tape);
|
|
|
|
int next_bytes[2];
|
|
|
|
next_bytes[0] = parser.get_next_byte(tape, is_fast);
|
|
|
|
next_bytes[1] = parser.get_next_byte(tape, is_fast);
|
|
|
|
|
|
|
|
if(next_bytes[0] != 0x16 || next_bytes[1] != 0x16) continue;
|
|
|
|
|
|
|
|
// get the first byte that isn't a 0x16, check it was a 0x24
|
|
|
|
int byte = 0x16;
|
2017-03-26 18:34:47 +00:00
|
|
|
while(!tape->is_at_end() && byte == 0x16) {
|
2016-11-07 03:56:38 +00:00
|
|
|
byte = parser.get_next_byte(tape, is_fast);
|
|
|
|
}
|
|
|
|
if(byte != 0x24) continue;
|
|
|
|
|
|
|
|
// skip two empty bytes
|
|
|
|
parser.get_next_byte(tape, is_fast);
|
|
|
|
parser.get_next_byte(tape, is_fast);
|
|
|
|
|
|
|
|
// get data and launch types
|
|
|
|
File new_file;
|
2017-03-26 18:34:47 +00:00
|
|
|
switch(parser.get_next_byte(tape, is_fast)) {
|
2016-11-07 03:56:38 +00:00
|
|
|
case 0x00: new_file.data_type = File::ProgramType::BASIC; break;
|
|
|
|
case 0x80: new_file.data_type = File::ProgramType::MachineCode; break;
|
|
|
|
default: new_file.data_type = File::ProgramType::None; break;
|
|
|
|
}
|
2017-03-26 18:34:47 +00:00
|
|
|
switch(parser.get_next_byte(tape, is_fast)) {
|
2016-11-08 01:17:06 +00:00
|
|
|
case 0x80: new_file.launch_type = File::ProgramType::BASIC; break;
|
2016-11-07 03:56:38 +00:00
|
|
|
case 0xc7: new_file.launch_type = File::ProgramType::MachineCode; break;
|
|
|
|
default: new_file.launch_type = File::ProgramType::None; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// read end and start addresses
|
2017-10-22 01:50:53 +00:00
|
|
|
new_file.ending_address = static_cast<uint16_t>(parser.get_next_byte(tape, is_fast) << 8);
|
|
|
|
new_file.ending_address |= static_cast<uint16_t>(parser.get_next_byte(tape, is_fast));
|
|
|
|
new_file.starting_address = static_cast<uint16_t>(parser.get_next_byte(tape, is_fast) << 8);
|
|
|
|
new_file.starting_address |= static_cast<uint16_t>(parser.get_next_byte(tape, is_fast));
|
2016-11-07 03:56:38 +00:00
|
|
|
|
2016-11-08 01:17:06 +00:00
|
|
|
// skip an empty byte
|
2016-11-07 03:56:38 +00:00
|
|
|
parser.get_next_byte(tape, is_fast);
|
|
|
|
|
|
|
|
// read file name, up to 16 characters and null terminated
|
|
|
|
char file_name[17];
|
|
|
|
int name_pos = 0;
|
2017-03-26 18:34:47 +00:00
|
|
|
while(name_pos < 16) {
|
2016-11-07 03:56:38 +00:00
|
|
|
file_name[name_pos] = (char)parser.get_next_byte(tape, is_fast);
|
|
|
|
if(!file_name[name_pos]) break;
|
|
|
|
name_pos++;
|
|
|
|
}
|
|
|
|
file_name[16] = '\0';
|
|
|
|
new_file.name = file_name;
|
|
|
|
|
|
|
|
// read body
|
2017-11-11 20:28:40 +00:00
|
|
|
std::size_t body_length = new_file.ending_address - new_file.starting_address + 1;
|
2016-11-07 03:56:38 +00:00
|
|
|
new_file.data.reserve(body_length);
|
2017-11-11 20:28:40 +00:00
|
|
|
for(std::size_t c = 0; c < body_length; c++) {
|
2017-10-22 01:50:53 +00:00
|
|
|
new_file.data.push_back(static_cast<uint8_t>(parser.get_next_byte(tape, is_fast)));
|
2016-11-07 03:56:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// only one validation check: was there enough tape?
|
2017-03-26 18:34:47 +00:00
|
|
|
if(!tape->is_at_end()) {
|
2016-11-07 03:56:38 +00:00
|
|
|
files.push_back(new_file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return files;
|
|
|
|
}
|