1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-10-04 01:57:54 +00:00

Fixed: length of 0 is a special case.

This commit is contained in:
Thomas Harte 2017-07-13 20:57:27 -04:00
parent 33d16ae0cd
commit ae1a130843
2 changed files with 18 additions and 0 deletions

View File

@ -87,6 +87,22 @@ uint8_t CSW::get_next_byte() {
}
}
uint32_t CSW::get_next_int32le() {
switch(compression_type_) {
case RLE: return fgetc32le();
case ZRLE: {
if(source_data_pointer_ > source_data_.size() - 4) return 0xffff;
uint32_t result = (uint32_t)(
(source_data_[source_data_pointer_ + 0] << 0) |
(source_data_[source_data_pointer_ + 1] << 8) |
(source_data_[source_data_pointer_ + 2] << 16) |
(source_data_[source_data_pointer_ + 3] << 24));
source_data_pointer_ += 4;
return result;
}
}
}
void CSW::invert_pulse() {
pulse_.type = (pulse_.type == Pulse::High) ? Pulse::Low : Pulse::High;
}
@ -108,5 +124,6 @@ void CSW::virtual_reset() {
Tape::Pulse CSW::virtual_get_next_pulse() {
invert_pulse();
pulse_.length.length = get_next_byte();
if(!pulse_.length.length) pulse_.length.length = get_next_int32le();
return pulse_;
}

View File

@ -48,6 +48,7 @@ class CSW: public Tape, public Storage::FileHolder {
} compression_type_;
uint8_t get_next_byte();
uint32_t get_next_int32le();
void invert_pulse();
std::vector<uint8_t> source_data_;