inline static int read_gap_backward_v1(long *read_tap) { /* examine, if previous gap was long by rewinding until 3 non-zero-values in a row found, then reading forward (FIXME???) */ int non_zeros_in_a_row = 0; long remember_file_seek_position; remember_file_seek_position = current_image->current_file_seek_position; current_image->current_file_seek_position -= 4; next_tap -= 4; while ((non_zeros_in_a_row < 3) && current_image->current_file_seek_position) { if (!datasette_move_buffer_back(-1)) { return 1; } current_image->current_file_seek_position--; next_tap--; if (tap_buffer[next_tap]) { non_zeros_in_a_row++; } else { non_zeros_in_a_row = 0; } } /* now forward */ while (current_image->current_file_seek_position < remember_file_seek_position - 4) { if (!datasette_move_buffer_forward(1)) { return -1; } if (tap_buffer[next_tap]) { current_image->current_file_seek_position++; next_tap++; } else { current_image->current_file_seek_position += 4; next_tap += 4; } } if (!datasette_move_buffer_forward(4)) { return -1; } *read_tap = next_tap; next_tap += (remember_file_seek_position - current_image->current_file_seek_position); current_image->current_file_seek_position = remember_file_seek_position; return 0; }
static CLOCK datasette_read_gap(int direction) { /* direction 1: forward, -1: rewind */ long read_tap = 0; CLOCK gap = 0; /* if (current_image->system != 2 || current_image->version != 1 || !fullwave) {*/ if (current_image->system != 2 ) { if ((direction < 0) && !datasette_move_buffer_back(direction * 4)) return 0; if ((direction > 0 ) && !datasette_move_buffer_forward(direction * 4)) return 0; if (direction > 0) { read_gap_forward(&read_tap); } else { if ((current_image->version == 0) || (next_tap < 4) || tap_buffer[next_tap-4]) { read_gap_backward_v0(&read_tap); } else { if (read_gap_backward_v1(&read_tap) < 0) return 0; } } if (fetch_gap(&gap, &direction, read_tap) < 0) return 0; next_tap += direction; current_image->current_file_seek_position += direction; } if (current_image->system == 2 && current_image->version == 1) { if (!fullwave) { if ((direction < 0) && !datasette_move_buffer_back(direction * 4)) return 0; if ((direction > 0 ) && !datasette_move_buffer_forward(direction * 4)) return 0; if (direction > 0) { read_gap_forward(&read_tap); } else { if ((current_image->version == 0) || (next_tap < 4) || tap_buffer[next_tap-4]) { read_gap_backward_v0(&read_tap); } else { if (read_gap_backward_v1(&read_tap) < 0) return 0; } } if (fetch_gap(&gap, &direction, read_tap) < 0) return 0; fullwave_gap = gap; next_tap += direction; current_image->current_file_seek_position += direction; } else { gap = fullwave_gap; } fullwave ^= 1; } else if (current_image->system == 2 && current_image->version == 2) { if ((direction < 0) && !datasette_move_buffer_back(direction * 4)) return 0; if ((direction > 0 ) && !datasette_move_buffer_forward(direction * 4)) return 0; if (direction > 0) { read_gap_forward(&read_tap); } else { if ((current_image->version == 0) || (next_tap < 4) || tap_buffer[next_tap-4]) { read_gap_backward_v0(&read_tap); } else { if (read_gap_backward_v1(&read_tap) < 0) return 0; } } if (fetch_gap(&gap, &direction, read_tap) < 0) return 0; gap *= 2; fullwave ^= 1; next_tap += direction; current_image->current_file_seek_position += direction; } return gap; }