mirror of
https://github.com/TomHarte/CLK.git
synced 2025-04-22 09:37:21 +00:00
Test data only once.
This commit is contained in:
parent
7f5d290b66
commit
1bef37d504
@ -11,16 +11,7 @@
|
||||
|
||||
using namespace Storage::Tape;
|
||||
|
||||
ZX80O81P::ZX80O81P(const std::string &file_name) : file_name_(file_name) {
|
||||
Serialiser test_serialiser(file_name);
|
||||
target_platforms_ = test_serialiser.target_platforms();
|
||||
}
|
||||
|
||||
std::unique_ptr<FormatSerialiser> ZX80O81P::format_serialiser() const {
|
||||
return std::make_unique<Serialiser>(file_name_);
|
||||
}
|
||||
|
||||
ZX80O81P::Serialiser::Serialiser(const std::string &file_name) {
|
||||
ZX80O81P::ZX80O81P(const std::string &file_name) {
|
||||
Storage::FileHolder file(file_name, FileHolder::FileMode::Read);
|
||||
|
||||
// Grab the actual file contents
|
||||
@ -29,17 +20,26 @@ ZX80O81P::Serialiser::Serialiser(const std::string &file_name) {
|
||||
|
||||
// If it's a ZX81 file, prepend a file name.
|
||||
std::string type = file.extension();
|
||||
platform_type_ = TargetPlatform::ZX80;
|
||||
target_platforms_ = TargetPlatform::ZX80;
|
||||
if(type == "p" || type == "81") {
|
||||
// TODO, maybe: prefix a proper file name; this is leaving the file nameless.
|
||||
data_.insert(data_.begin(), 0x80);
|
||||
platform_type_ = TargetPlatform::ZX81;
|
||||
target_platforms_ = TargetPlatform::ZX81;
|
||||
}
|
||||
|
||||
std::shared_ptr<::Storage::Data::ZX8081::File> zx_file = Storage::Data::ZX8081::FileFromData(data_);
|
||||
if(!zx_file) throw ErrorNotZX80O81P;
|
||||
}
|
||||
|
||||
// then rewind and start again
|
||||
TargetPlatform::Type ZX80O81P::target_platforms() {
|
||||
return target_platforms_;
|
||||
}
|
||||
|
||||
std::unique_ptr<FormatSerialiser> ZX80O81P::format_serialiser() const {
|
||||
return std::make_unique<Serialiser>(data_);
|
||||
}
|
||||
|
||||
ZX80O81P::Serialiser::Serialiser(const std::vector<uint8_t> &data) : data_(data) {
|
||||
reset();
|
||||
}
|
||||
|
||||
@ -111,11 +111,3 @@ Pulse ZX80O81P::Serialiser::next_pulse() {
|
||||
|
||||
return pulse;
|
||||
}
|
||||
|
||||
TargetPlatform::Type ZX80O81P::target_platforms() {
|
||||
return target_platforms_;
|
||||
}
|
||||
|
||||
TargetPlatform::Type ZX80O81P::Serialiser::target_platforms() {
|
||||
return platform_type_;
|
||||
}
|
||||
|
@ -41,8 +41,7 @@ private:
|
||||
std::unique_ptr<FormatSerialiser> format_serialiser() const override;
|
||||
|
||||
struct Serialiser: public FormatSerialiser {
|
||||
Serialiser(const std::string &file_name);
|
||||
TargetPlatform::Type target_platforms();
|
||||
Serialiser(const std::vector<uint8_t> &data);
|
||||
|
||||
private:
|
||||
bool is_at_end() const override;
|
||||
@ -50,19 +49,17 @@ private:
|
||||
Pulse next_pulse() override;
|
||||
bool has_finished_data() const;
|
||||
|
||||
TargetPlatform::Type platform_type_;
|
||||
|
||||
uint8_t byte_;
|
||||
int bit_pointer_;
|
||||
int wave_pointer_;
|
||||
bool is_past_silence_, has_ended_final_byte_;
|
||||
bool is_high_;
|
||||
|
||||
std::vector<uint8_t> data_;
|
||||
const std::vector<uint8_t> &data_;
|
||||
std::size_t data_pointer_;
|
||||
};
|
||||
std::string file_name_;
|
||||
TargetPlatform::Type target_platforms_;
|
||||
std::vector<uint8_t> data_;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user