From 968ba402618f9ed171308167ab57d8f4582d89cd Mon Sep 17 00:00:00 2001 From: holub Date: Mon, 27 Jan 2025 17:26:11 -0500 Subject: [PATCH] formats/oric_tap.cpp, formats/uef_cas.cpp: Fixed build after #13289, tidied code. (#13290) --- src/lib/formats/oric_tap.cpp | 194 +++++++++++++++++------------------ src/lib/formats/uef_cas.cpp | 14 ++- 2 files changed, 101 insertions(+), 107 deletions(-) diff --git a/src/lib/formats/oric_tap.cpp b/src/lib/formats/oric_tap.cpp index 47a1447de68..52a6c308b87 100644 --- a/src/lib/formats/oric_tap.cpp +++ b/src/lib/formats/oric_tap.cpp @@ -348,136 +348,132 @@ static int oric_cassette_calculate_size_in_samples(const uint8_t *bytes, int len static int oric_cassette_fill_wave(int16_t *buffer, int length, const uint8_t *bytes) { unsigned char header[9]; - const uint8_t *data_ptr; - int16_t *p; - int i; - uint8_t data; - - p = buffer; - + int16_t *p = buffer; /* header and trailer act as pauses */ /* the trailer is required so that the via sees the last bit of the last byte */ - if (bytes == CODE_HEADER) { - for (i = 0; i < ORIC_WAVESAMPLES_HEADER; i++) + if (bytes == CODE_HEADER) + { + for (int i = 0; i < ORIC_WAVESAMPLES_HEADER; i++) *(p++) = WAVEENTRY_NULL; } - else if (bytes == CODE_TRAILER) { - for (i = 0; i < ORIC_WAVESAMPLES_TRAILER; i++) + else if (bytes == CODE_TRAILER) + { + for (int i = 0; i < ORIC_WAVESAMPLES_TRAILER; i++) *(p++) = WAVEENTRY_NULL; } else -{ - /* the length is the number of samples left in the buffer and NOT the number of bytes for the input file */ - length = length - ORIC_WAVESAMPLES_TRAILER; - - oric.cassette_state = ORIC_CASSETTE_SEARCHING_FOR_SYNC_BYTE; - data_ptr = bytes; - - while ((data_ptr<(bytes + oric.tap_size)) && (p < (buffer+length)) ) { - data = data_ptr[0]; - data_ptr++; + /* the length is the number of samples left in the buffer and NOT the number of bytes for the input file */ + length = length - ORIC_WAVESAMPLES_TRAILER; - switch (oric.cassette_state) + oric.cassette_state = ORIC_CASSETTE_SEARCHING_FOR_SYNC_BYTE; + const uint8_t *data_ptr = bytes; + + while ((data_ptr < (bytes + oric.tap_size)) && (p < (buffer+length)) ) { - case ORIC_CASSETTE_SEARCHING_FOR_SYNC_BYTE: - { - if (data==ORIC_SYNC_BYTE) - { - LOG_FORMATS("found sync byte!\n"); - /* found first sync byte */ - oric.cassette_state = ORIC_CASSETTE_GOT_SYNC_BYTE; - } - } - break; + const uint8_t data = data_ptr[0]; + data_ptr++; - case ORIC_CASSETTE_GOT_SYNC_BYTE: + switch (oric.cassette_state) { - if (data!=ORIC_SYNC_BYTE) + case ORIC_CASSETTE_SEARCHING_FOR_SYNC_BYTE: { - /* 0.25 second pause */ - p = oric_fill_pause(p, oric_seconds_to_samples(0.25)); - - LOG_FORMATS("found end of sync bytes!\n"); - /* found end of sync bytes */ - for (i=0; i> i) & 1 ); } p = uef_cas_fill_bit( loops, p, 1 ); @@ -286,11 +285,10 @@ static int uef_cas_fill_wave( int16_t *buffer, int length, const uint8_t *bytes LOG_FORMATS( "Unsupported chunk type: %04x\n", chunk_type ); break; case 0x0102: /* explicit tape data block */ - j = ( chunk_length * 10 ) - bytes[pos]; c = bytes + pos; - while( j ) { + for( uint32_t j = ( chunk_length * 10 ) - bytes[pos]; j; ) { uint8_t byte = *c; - for( i = 0; i < 8 && i < j; i++ ) { + for( uint8_t i = 0; i < 8 && i < j; i++ ) { p = uef_cas_fill_bit( loops, p, (byte >> i) & 1 ); j--; } @@ -312,7 +310,7 @@ static int uef_cas_fill_wave( int16_t *buffer, int length, const uint8_t *bytes } break; case 0x0116: /* floating point gap */ - for( baud_length = (get_uef_float(bytes+pos)*UEF_WAV_FREQUENCY); baud_length; baud_length-- ) { + for( baud_length = (get_uef_float(bytes + pos)*UEF_WAV_FREQUENCY); baud_length; baud_length-- ) { *p = WAVE_NULL; p++; length -= 1; }