summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/formats/h8_cas.cpp
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2025-02-07 03:56:49 +1100
committer Vas Crabb <vas@vastheman.com>2025-02-07 03:57:56 +1100
commitd246968ffcbda78411211a3850e6c64e6d3ad3fa (patch)
tree54f397b1ab01ea7e779346afa42720687280c945 /src/lib/formats/h8_cas.cpp
parent270c31899f17d566321be487001d5d18ed729bd9 (diff)
Cleaned up some recent commits.
Diffstat (limited to 'src/lib/formats/h8_cas.cpp')
-rw-r--r--src/lib/formats/h8_cas.cpp47
1 files changed, 25 insertions, 22 deletions
diff --git a/src/lib/formats/h8_cas.cpp b/src/lib/formats/h8_cas.cpp
index 300c8f3654f..526e411d5ae 100644
--- a/src/lib/formats/h8_cas.cpp
+++ b/src/lib/formats/h8_cas.cpp
@@ -20,45 +20,49 @@ We output a leader, followed by the contents of the H8T file.
namespace {
-static constexpr double ONE_FREQ = 1200.0;
-static constexpr double ONE_FREQ_VARIANCE = 300.0;
-static constexpr double ZERO_FREQ = 2400.0;
-static constexpr double ZERO_FREQ_VARIANCE = 600.0;
+constexpr double ONE_FREQ = 1200.0;
+constexpr double ONE_FREQ_VARIANCE = 300.0;
+constexpr double ZERO_FREQ = 2400.0;
+constexpr double ZERO_FREQ_VARIANCE = 600.0;
-static const cassette_image::Modulation heath_h8t_modulation =
+const cassette_image::Modulation heath_h8t_modulation =
{
cassette_image::MODULATION_SINEWAVE,
ONE_FREQ - ONE_FREQ_VARIANCE, ONE_FREQ, ONE_FREQ + ONE_FREQ_VARIANCE,
ZERO_FREQ - ZERO_FREQ_VARIANCE, ZERO_FREQ, ZERO_FREQ + ZERO_FREQ_VARIANCE
};
-static cassette_image::error heath_h8t_identify(cassette_image *cassette, cassette_image::Options *opts)
+cassette_image::error heath_h8t_identify(cassette_image *cassette, cassette_image::Options *opts)
{
return cassette->modulation_identify(heath_h8t_modulation, opts);
}
-#define MODULATE(_value) \
- for (int i = 0; i < (_value ? 8 : 4); i++) { \
- err = cassette->put_modulated_data_bit(0, time_index, _value, heath_h8t_modulation, &time_displacement); \
- if (err != cassette_image::error::SUCCESS) return err; \
- time_index += time_displacement; \
- }
-
-static cassette_image::error heath_h8t_load(cassette_image *cassette)
+cassette_image::error heath_h8t_load(cassette_image *cassette)
{
cassette_image::error err = cassette_image::error::SUCCESS;
uint64_t image_size = cassette->image_size();
double time_index = 0.0;
double time_displacement;
+ auto const MODULATE =
+ [&cassette, &err, &time_index, &time_displacement] (unsigned value)
+ {
+ for (int i = 0; (i < (value ? 8 : 4)); i++)
+ {
+ err = cassette->put_modulated_data_bit(0, time_index, value, heath_h8t_modulation, &time_displacement);
+ if (cassette_image::error::SUCCESS == err)
+ time_index += time_displacement;
+ else
+ return;
+ }
+ };
+
// leader - 1 second
- while (time_index < 1.0)
- {
+ while ((cassette_image::error::SUCCESS == err) && (time_index < 1.0))
MODULATE(1);
- }
- for (uint64_t image_pos = 0; image_pos < image_size; image_pos++)
+ for (uint64_t image_pos = 0; (cassette_image::error::SUCCESS == err) && (image_pos < image_size); image_pos++)
{
uint8_t data = cassette->image_read_byte(image_pos);
@@ -66,13 +70,12 @@ static cassette_image::error heath_h8t_load(cassette_image *cassette)
MODULATE(0);
// data bits
- for (int bit = 0; bit < 8; bit++)
- {
+ for (int bit = 0; (cassette_image::error::SUCCESS == err) && (bit < 8); bit++)
MODULATE(util::BIT(data, bit));
- }
// stop bit
- MODULATE(1);
+ if (cassette_image::error::SUCCESS == err)
+ MODULATE(1);
}
return err;