mirror of
https://github.com/TomHarte/CLK.git
synced 2026-04-26 19:17:52 +00:00
Introduces a container for ZX Spectrum-style TAPs.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
//
|
||||
// SpectrumTAP.cpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 19/03/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#include "ZXSpectrumTAP.hpp"
|
||||
|
||||
using namespace Storage::Tape;
|
||||
|
||||
ZXSpectrumTAP::ZXSpectrumTAP(const std::string &file_name) :
|
||||
file_(file_name)
|
||||
{
|
||||
// Check for a continuous series of blocks through to
|
||||
// file end, alternating header and data.
|
||||
uint8_t next_block_type = 0x00;
|
||||
while(true) {
|
||||
const uint16_t block_length = file_.get16le();
|
||||
const uint8_t block_type = file_.get8();
|
||||
if(file_.eof()) throw ErrorNotZXSpectrumTAP;
|
||||
|
||||
if(block_type != next_block_type) {
|
||||
throw ErrorNotZXSpectrumTAP;
|
||||
}
|
||||
next_block_type ^= 0xff;
|
||||
|
||||
file_.seek(block_length - 1, SEEK_CUR);
|
||||
if(file_.tell() == file_.stats().st_size) break;
|
||||
}
|
||||
|
||||
virtual_reset();
|
||||
}
|
||||
|
||||
bool ZXSpectrumTAP::is_at_end() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void ZXSpectrumTAP::virtual_reset() {
|
||||
file_.seek(0, SEEK_SET);
|
||||
block_length_ = file_.get16le();
|
||||
}
|
||||
|
||||
Tape::Pulse ZXSpectrumTAP::virtual_get_next_pulse() {
|
||||
return Pulse();
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// SpectrumTAP.hpp
|
||||
// Clock Signal
|
||||
//
|
||||
// Created by Thomas Harte on 19/03/2021.
|
||||
// Copyright © 2021 Thomas Harte. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SpectrumTAP_hpp
|
||||
#define SpectrumTAP_hpp
|
||||
|
||||
#include "../Tape.hpp"
|
||||
#include "../../FileHolder.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace Storage {
|
||||
namespace Tape {
|
||||
|
||||
/*!
|
||||
Provides a @c Tape containing an Spectrum-format tape image, which contains a series of
|
||||
header and data blocks.
|
||||
*/
|
||||
class ZXSpectrumTAP: public Tape {
|
||||
public:
|
||||
/*!
|
||||
Constructs a @c ZXSpectrumTAP containing content from the file with name @c file_name.
|
||||
|
||||
@throws ErrorNotZXSpectrumTAP if this file could not be opened and recognised as a valid Spectrum-format TAP.
|
||||
*/
|
||||
ZXSpectrumTAP(const std::string &file_name);
|
||||
|
||||
enum {
|
||||
ErrorNotZXSpectrumTAP
|
||||
};
|
||||
|
||||
private:
|
||||
Storage::FileHolder file_;
|
||||
|
||||
uint16_t block_length_ = 0;
|
||||
|
||||
// Implemented to satisfy @c Tape.
|
||||
bool is_at_end() override;
|
||||
void virtual_reset() override;
|
||||
Pulse virtual_get_next_pulse() override;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SpectrumTAP_hpp */
|
||||
Reference in New Issue
Block a user