static libspectrum_error turbo_edge( libspectrum_tape_turbo_block *block, libspectrum_dword *tstates, int *end_of_block ) { int error; switch( block->state ) { case LIBSPECTRUM_TAPE_STATE_PILOT: /* The next edge occurs in one pilot edge timing */ *tstates = block->pilot_length; /* If that was the last pilot edge, change state */ if( --(block->edge_count) == 0 ) block->state = LIBSPECTRUM_TAPE_STATE_SYNC1; break; case LIBSPECTRUM_TAPE_STATE_SYNC1: /* The first short sync pulse */ *tstates = block->sync1_length; /* Followed by the second sync pulse */ block->state = LIBSPECTRUM_TAPE_STATE_SYNC2; break; case LIBSPECTRUM_TAPE_STATE_SYNC2: /* The second short sync pulse */ *tstates = block->sync2_length; /* Followed by the first bit of data */ error = turbo_next_bit( block ); if( error ) return error; break; case LIBSPECTRUM_TAPE_STATE_DATA1: /* The first edge for a bit of data */ *tstates = block->bit_tstates; /* Followed by the second edge */ block->state = LIBSPECTRUM_TAPE_STATE_DATA2; break; case LIBSPECTRUM_TAPE_STATE_DATA2: /* The second edge for a bit of data */ *tstates = block->bit_tstates; /* Followed by the next bit of data (or the end of data) */ error = turbo_next_bit( block ); if( error ) return error; break; case LIBSPECTRUM_TAPE_STATE_PAUSE: /* The pause at the end of the block */ *tstates = (block->pause * 69888)/20; /* FIXME: should vary with tstates per frame */ *end_of_block = 1; break; default: libspectrum_print_error( "turbo_edge: unknown state %d\n", block->state ); return LIBSPECTRUM_ERROR_LOGIC; } return LIBSPECTRUM_ERROR_NONE; }
static libspectrum_error turbo_edge( libspectrum_tape_turbo_block *block, libspectrum_tape_turbo_block_state *state, libspectrum_dword *tstates, int *end_of_block ) { int error; switch( state->state ) { case LIBSPECTRUM_TAPE_STATE_PILOT: /* Check we actually have some edges */ if( state->edge_count-- != 0 ) { *tstates = block->pilot_length; break; } /* Fall through */ case LIBSPECTRUM_TAPE_STATE_SYNC1: /* The first short sync pulse */ *tstates = block->sync1_length; /* Followed by the second sync pulse */ state->state = LIBSPECTRUM_TAPE_STATE_SYNC2; break; case LIBSPECTRUM_TAPE_STATE_SYNC2: /* The second short sync pulse */ *tstates = block->sync2_length; /* Followed by the first bit of data */ error = turbo_next_bit( block, state ); if( error ) return error; break; case LIBSPECTRUM_TAPE_STATE_DATA1: /* The first edge for a bit of data */ *tstates = state->bit_tstates; /* Followed by the second edge */ state->state = LIBSPECTRUM_TAPE_STATE_DATA2; break; case LIBSPECTRUM_TAPE_STATE_DATA2: /* The second edge for a bit of data */ *tstates = state->bit_tstates; /* Followed by the next bit of data (or the end of data) */ error = turbo_next_bit( block, state ); if( error ) return error; break; case LIBSPECTRUM_TAPE_STATE_PAUSE: /* The pause at the end of the block */ *tstates = (block->pause * 69888)/20; /* FIXME: should vary with tstates per frame */ *end_of_block = 1; break; default: libspectrum_print_error( LIBSPECTRUM_ERROR_LOGIC, "turbo_edge: unknown state %d", state->state ); return LIBSPECTRUM_ERROR_LOGIC; } return LIBSPECTRUM_ERROR_NONE; }