1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-25 16:31:42 +00:00

Adjusted factoring to introduce support for block 10.

This commit is contained in:
Thomas Harte 2017-08-02 14:36:47 -04:00
parent 2fd071e45d
commit 2d2cefb0b0
2 changed files with 50 additions and 27 deletions

View File

@ -162,48 +162,58 @@ void TZX::get_generalised_segment(uint32_t output_symbols, uint8_t max_pulses_pe
}
void TZX::get_standard_speed_data_block() {
__unused uint16_t pause_after_block = fgetc16le();
uint16_t data_length = fgetc16le();
if(!data_length) return;
DataBlock data_block;
data_block.length_of_pilot_pulse = 2168;
data_block.length_of_sync_first_pulse = 667;
data_block.length_of_sync_second_pulse = 735;
data_block.length_of_zero_bit_pulse = 855;
data_block.length_of_one_bit_pulse = 1710;
data_block.number_of_bits_in_final_byte = 8;
data_block.pause_after_block = fgetc16le();
data_block.data_length = fgetc16le();
if(!data_block.data_length) return;
uint8_t first_byte = (uint8_t)fgetc(file_);
__unused int pilot_tone_pulses = (first_byte < 128) ? 8063 : 3223;
data_block.length_of_pilot_tone = (first_byte < 128) ? 8063 : 3223;
ungetc(first_byte, file_);
// TODO: output pilot_tone_pulses pulses
// TODO: output data_length bytes, in the Spectrum encoding
fseek(file_, data_length, SEEK_CUR);
// TODO: output a pause of length paused_after_block ms
get_data_block(data_block);
}
void TZX::get_turbo_speed_data_block() {
uint16_t length_of_pilot_pulse = fgetc16le();
uint16_t length_of_sync_first_pulse = fgetc16le();
uint16_t length_of_sync_second_pulse = fgetc16le();
uint16_t length_of_zero_bit_pulse = fgetc16le();
uint16_t length_of_one_bit_pulse = fgetc16le();
uint16_t length_of_pilot_tone = fgetc16le();
uint8_t number_of_bits_in_final_byte = (uint8_t)fgetc(file_);
uint16_t pause_after_block = fgetc16le();
long data_length = fgetc16le();
data_length |= (long)(fgetc(file_) << 16);
DataBlock data_block;
data_block.length_of_pilot_pulse = fgetc16le();
data_block.length_of_sync_first_pulse = fgetc16le();
data_block.length_of_sync_second_pulse = fgetc16le();
data_block.length_of_zero_bit_pulse = fgetc16le();
data_block.length_of_one_bit_pulse = fgetc16le();
data_block.length_of_pilot_tone = fgetc16le();
data_block.number_of_bits_in_final_byte = (uint8_t)fgetc(file_);
data_block.pause_after_block = fgetc16le();
data_block.data_length = fgetc16le();
data_block.data_length |= (long)(fgetc(file_) << 16);
get_data_block(data_block);
}
void TZX::get_data_block(const DataBlock &data_block) {
// Output pilot tone.
while(length_of_pilot_tone--) {
post_pulse(length_of_pilot_pulse);
for(unsigned int c = 0; c < data_block.length_of_pilot_tone; c++) {
post_pulse(data_block.length_of_pilot_pulse);
}
// Output sync pulses.
post_pulse(length_of_sync_first_pulse);
post_pulse(length_of_sync_second_pulse);
post_pulse(data_block.length_of_sync_first_pulse);
post_pulse(data_block.length_of_sync_second_pulse);
// Output data.
while(data_length--) {
for(unsigned int c = 0; c < data_block.data_length; c++) {
uint8_t next_byte = (uint8_t)fgetc(file_);
int c = data_length ? 8 : number_of_bits_in_final_byte;
while(c--) {
uint16_t pulse_length = (next_byte & 0x80) ? length_of_one_bit_pulse : length_of_zero_bit_pulse;
unsigned int bits = (c != data_block.data_length-1) ? 8 : data_block.number_of_bits_in_final_byte;
while(bits--) {
unsigned int pulse_length = (next_byte & 0x80) ? data_block.length_of_one_bit_pulse : data_block.length_of_zero_bit_pulse;
next_byte <<= 1;
post_pulse(pulse_length);
@ -212,7 +222,7 @@ void TZX::get_turbo_speed_data_block() {
}
// Output gap.
post_gap(pause_after_block);
post_gap(data_block.pause_after_block);
}
void TZX::get_pure_tone_data_block() {

View File

@ -44,7 +44,20 @@ class TZX: public PulseQueuedTape, public Storage::FileHolder {
void get_generalised_data_block();
void get_pause();
struct DataBlock {
unsigned int length_of_pilot_pulse;
unsigned int length_of_sync_first_pulse;
unsigned int length_of_sync_second_pulse;
unsigned int length_of_zero_bit_pulse;
unsigned int length_of_one_bit_pulse;
unsigned int length_of_pilot_tone;
unsigned int number_of_bits_in_final_byte;
unsigned int pause_after_block;
long data_length;
};
void get_generalised_segment(uint32_t output_symbols, uint8_t max_pulses_per_symbol, uint8_t number_of_symbols, bool is_data);
void get_data_block(const DataBlock &);
void post_pulse(unsigned int length);
void post_gap(unsigned int milliseconds);