1
0
mirror of https://github.com/TomHarte/CLK.git synced 2026-04-19 19:16:34 +00:00

Made an attempt to get .p/.80 checked and as far as the emulated machine.

This commit is contained in:
Thomas Harte
2017-06-12 19:41:59 -04:00
parent b9dbb6bcf8
commit 22de481557
2 changed files with 53 additions and 8 deletions
+42 -2
View File
@@ -45,8 +45,48 @@ static std::shared_ptr<File> ZX80FileFromData(const std::vector<uint8_t> &data)
return file;
}
static std::shared_ptr<File> ZX81FileFromData(const std::vector<uint8_t> &data) {
// Does this look like a ZX81 file?
// Look for a file name.
size_t data_pointer = 0;
int c = 11;
while(c--) {
if(data[data_pointer] & 0x80) break;
data_pointer++;
}
if(!c) return nullptr;
data_pointer++;
if(data.size() < data_pointer + 0x405e - 0x4009) return nullptr;
if(data[data_pointer]) return nullptr;
uint16_t vars = short_at(data_pointer + 0x4010 - 0x4009, data);
uint16_t end_of_file = short_at(data_pointer + 0x4014 - 0x4009, data);
// uint16_t display_address = short_at(0x400c - 0x4009, data);
// check that the end of file is contained within the supplied data
if(data_pointer + end_of_file - 0x4009 > data.size()) return nullptr;
// check for the proper ordering of buffers
if(vars > end_of_file) return nullptr;
// if(end_of_file > display_address) return nullptr;
// TODO: does it make sense to inspect the tokenised BASIC?
// It starts at 0x4028 and proceeds as [16-bit line number] [tokens] [0x76],
// but I'm as yet unable to find documentation of the tokens.
// TODO: check that the line numbers declared above exist (?)
std::shared_ptr<File> file(new File);
file->data = data;
file->isZX81 = true;
return file;
}
std::shared_ptr<File> Storage::Data::ZX8081::FileFromData(const std::vector<uint8_t> &data) {
std::shared_ptr<Storage::Data::ZX8081::File> result = ZX80FileFromData(data);
return result;
if(result) return result;
return ZX81FileFromData(data);
}