mirror of
https://github.com/TomHarte/CLK.git
synced 2024-08-17 07:29:04 +00:00
Modified to use an in-memory buffer for file contents.
This commit is contained in:
parent
302c2e94de
commit
ee0283c985
@ -21,14 +21,14 @@ ZX80O::ZX80O(const char *file_name) :
|
|||||||
|
|
||||||
if(!file || file->isZX81) throw ErrorNotZX80O;
|
if(!file || file->isZX81) throw ErrorNotZX80O;
|
||||||
|
|
||||||
size_of_file_ = file->data.size();
|
data_ = file->data;
|
||||||
|
|
||||||
// then rewind and start again
|
// then rewind and start again
|
||||||
virtual_reset();
|
virtual_reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZX80O::virtual_reset() {
|
void ZX80O::virtual_reset() {
|
||||||
fseek(file_, 0, SEEK_SET);
|
data_pointer_ = 0;
|
||||||
is_past_silence_ = false;
|
is_past_silence_ = false;
|
||||||
has_ended_final_byte_ = false;
|
has_ended_final_byte_ = false;
|
||||||
is_high_ = true;
|
is_high_ = true;
|
||||||
@ -36,7 +36,7 @@ void ZX80O::virtual_reset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool ZX80O::has_finished_data() {
|
bool ZX80O::has_finished_data() {
|
||||||
return (ftell(file_) == size_of_file_) && !wave_pointer_ && !bit_pointer_;
|
return (data_pointer_ == data_.size()) && !wave_pointer_ && !bit_pointer_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZX80O::is_at_end() {
|
bool ZX80O::is_at_end() {
|
||||||
@ -58,7 +58,8 @@ Tape::Pulse ZX80O::virtual_get_next_pulse() {
|
|||||||
|
|
||||||
// For each byte, output 8 bits and then silence.
|
// For each byte, output 8 bits and then silence.
|
||||||
if(!bit_pointer_ && !wave_pointer_) {
|
if(!bit_pointer_ && !wave_pointer_) {
|
||||||
byte_ = (uint8_t)fgetc(file_);
|
byte_ = data_[data_pointer_];
|
||||||
|
data_pointer_++;
|
||||||
bit_pointer_ = 0;
|
bit_pointer_ = 0;
|
||||||
wave_pointer_ = 0;
|
wave_pointer_ = 0;
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,9 @@
|
|||||||
|
|
||||||
#include "../Tape.hpp"
|
#include "../Tape.hpp"
|
||||||
#include "../../FileHolder.hpp"
|
#include "../../FileHolder.hpp"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace Storage {
|
namespace Storage {
|
||||||
namespace Tape {
|
namespace Tape {
|
||||||
@ -46,7 +48,8 @@ class ZX80O: public Tape, public Storage::FileHolder {
|
|||||||
bool is_past_silence_, has_ended_final_byte_;
|
bool is_past_silence_, has_ended_final_byte_;
|
||||||
bool is_high_;
|
bool is_high_;
|
||||||
|
|
||||||
size_t size_of_file_;
|
std::vector<uint8_t> data_;
|
||||||
|
size_t data_pointer_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user