summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/imagedev/cassette.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/imagedev/cassette.cpp')
-rw-r--r--src/devices/imagedev/cassette.cpp107
1 files changed, 55 insertions, 52 deletions
diff --git a/src/devices/imagedev/cassette.cpp b/src/devices/imagedev/cassette.cpp
index 21cb7e8bd10..cef022b57a5 100644
--- a/src/devices/imagedev/cassette.cpp
+++ b/src/devices/imagedev/cassette.cpp
@@ -40,8 +40,8 @@ cassette_image_device::cassette_image_device(const machine_config &mconfig, cons
device_sound_interface(mconfig, *this),
m_cassette(nullptr),
m_state(CASSETTE_STOPPED),
- m_position(0),
- m_position_time(0),
+ m_position(0.0),
+ m_position_time(0.0),
m_value(0),
m_channel(0),
m_speed(0),
@@ -71,8 +71,8 @@ cassette_image_device::~cassette_image_device()
void cassette_image_device::device_config_complete()
{
m_extension_list[0] = '\0';
- for (int i = 0; m_formats[i]; i++ )
- image_specify_extension( m_extension_list, 256, m_formats[i]->extensions );
+ for (int i = 0; m_formats[i]; i++)
+ image_specify_extension(m_extension_list, 256, m_formats[i]->extensions);
}
@@ -86,9 +86,9 @@ void cassette_image_device::update()
if (!is_stopped() && motor_on())
{
- double new_position = m_position + (cur_time - m_position_time)*m_speed*m_direction;
+ double new_position = m_position + (cur_time - m_position_time) * m_speed * m_direction;
- switch (int(m_state & CASSETTE_MASK_UISTATE)) // cast to int to suppress unhandled enum value warning
+ switch (m_state & CASSETTE_MASK_UISTATE)
{
case CASSETTE_RECORD:
m_cassette->put_sample(m_channel, m_position, new_position - m_position, m_value);
@@ -105,13 +105,16 @@ void cassette_image_device::update()
m_state = (m_state & ~CASSETTE_MASK_UISTATE) | CASSETTE_STOPPED;
new_position = length;
}
- else if (new_position < 0)
+ else if (new_position < 0.0)
{
m_state = (m_state & ~CASSETTE_MASK_UISTATE) | CASSETTE_STOPPED;
- new_position = 0;
+ new_position = 0.0;
}
}
break;
+
+ default:
+ break;
}
m_position = new_position;
}
@@ -138,12 +141,11 @@ void cassette_image_device::change_state(cassette_state state, cassette_state ma
double cassette_image_device::input()
{
update();
- int32_t sample = m_value;
- double double_value = sample / (double(0x7FFFFFFF));
+ double value = m_value / (double(0x7fffffff));
- LOGMASKED(LOG_DETAIL, "cassette_input(): time_index=%g value=%g\n", m_position, double_value);
+ LOGMASKED(LOG_DETAIL, "cassette_input(): time_index=%g value=%g\n", m_position, value);
- return double_value;
+ return value;
}
@@ -154,10 +156,8 @@ void cassette_image_device::output(double value)
{
update();
- value = std::min(value, 1.0);
- value = std::max(value, -1.0);
-
- m_value = int32_t(value * 0x7FFFFFFF);
+ value = std::clamp(value, -1.0, 1.0);
+ m_value = int32_t(value * 0x7fffffff);
}
}
@@ -167,7 +167,7 @@ double cassette_image_device::get_position()
double position = m_position;
if (!is_stopped() && motor_on())
- position += (machine().time().as_double() - m_position_time)*m_speed*m_direction;
+ position += (machine().time().as_double() - m_position_time) * m_speed * m_direction;
return position;
}
@@ -206,7 +206,8 @@ void cassette_image_device::seek(double time, int origin)
double length = get_length();
- switch(origin) {
+ switch (origin)
+ {
case SEEK_SET:
break;
@@ -219,14 +220,8 @@ void cassette_image_device::seek(double time, int origin)
break;
}
- /* clip position into legal bounds */
- if (time < 0)
- time = 0;
- else
- if (time > length)
- time = length;
-
- m_position = time;
+ // clip position into legal bounds
+ m_position = std::clamp(time, 0.0, length);
}
@@ -235,14 +230,25 @@ void cassette_image_device::seek(double time, int origin)
cassette device init/load/unload/specify
*********************************************************************/
+// allow save_item on a non-fundamental type
+ALLOW_SAVE_TYPE(cassette_state);
+
void cassette_image_device::device_start()
{
- /* set to default state */
+ // set to default state
m_cassette = nullptr;
m_state = m_default_state;
m_value = 0;
- stream_alloc(0, m_stereo? 2:1, machine().sample_rate());
+ stream_alloc(0, m_stereo ? 2 : 1, machine().sample_rate());
+
+ save_item(NAME(m_state));
+ save_item(NAME(m_position));
+ save_item(NAME(m_position_time));
+ save_item(NAME(m_value));
+ save_item(NAME(m_channel));
+ save_item(NAME(m_speed));
+ save_item(NAME(m_direction));
}
const software_list_loader &cassette_image_device::get_software_list_loader() const
@@ -267,6 +273,7 @@ bool cassette_image_device::has_any_extension(std::string_view candidate_extensi
for (std::string extension; std::getline(extension_stream, extension, separator);)
if (is_filetype(extension))
return true;
+
return false;
}
@@ -277,7 +284,7 @@ std::error_condition cassette_image_device::internal_load(bool is_create)
interface(image);
check_for_file();
- if (is_create || (length()==0)) // empty existing images are fine to write over.
+ if (is_create || (length() == 0)) // empty existing images are fine to write over.
{
auto io = util::random_read_write_fill(image_core_file(), 0x00);
if (io)
@@ -329,19 +336,19 @@ std::error_condition cassette_image_device::internal_load(bool is_create)
retry = true;
}
}
- while(retry);
+ while (retry);
}
if (err == cassette_image::error::SUCCESS)
{
- /* set to default state, but only change the UI state */
+ // set to default state, but only change the UI state
change_state(m_default_state, CASSETTE_MASK_UISTATE);
- /* reset the position */
+ // reset the position
m_position = 0.0;
m_position_time = machine().time().as_double();
- /* default channel to 0, speed multiplier to 1 */
+ // default channel to 0, speed multiplier to 1
m_channel = 0;
m_speed = 1;
m_direction = 1;
@@ -377,14 +384,14 @@ std::error_condition cassette_image_device::internal_load(bool is_create)
void cassette_image_device::call_unload()
{
- /* if we are recording, write the value to the image */
+ // if we are recording, write the value to the image
if ((m_state & CASSETTE_MASK_UISTATE) == CASSETTE_RECORD)
update();
- /* close out the cassette */
+ // close out the cassette
m_cassette.reset();
- /* set to default state, but only change the UI state */
+ // set to default state, but only change the UI state
change_state(CASSETTE_STOPPED, CASSETTE_MASK_UISTATE);
}
@@ -415,8 +422,8 @@ std::string cassette_image_device::call_display()
// play or record
const char *status_icon = (uistate == CASSETTE_PLAY)
- ? u8"\u25BA"
- : u8"\u25CF";
+ ? u8"\u25ba"
+ : u8"\u25cf";
// create information string
result = string_format("%s %s %02d:%02d (%04d) [%02d:%02d (%04d)]",
@@ -448,33 +455,29 @@ std::string cassette_image_device::call_display()
// Cassette sound
//-------------------------------------------------
-void cassette_image_device::sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs)
+void cassette_image_device::sound_stream_update(sound_stream &stream)
{
cassette_state state = get_state() & (CASSETTE_MASK_UISTATE | CASSETTE_MASK_MOTOR | CASSETTE_MASK_SPEAKER);
if (exists() && (state == (CASSETTE_PLAY | CASSETTE_MOTOR_ENABLED | CASSETTE_SPEAKER_ENABLED)))
{
+ int samples = stream.samples();
cassette_image *cassette = get_image();
double time_index = get_position();
- double duration = ((double) outputs[0].samples()) / outputs[0].sample_rate();
+ double duration = ((double) samples) / stream.sample_rate();
- if (m_samples.size() < outputs[0].samples())
- m_samples.resize(outputs[0].samples());
+ if (m_samples.size() < samples)
+ m_samples.resize(samples);
const cassette_image::Info info = cassette->get_info();
- for (int ch = 0; ch < outputs.size(); ch++)
+ for (int ch = 0; ch < stream.output_count(); ch++)
{
if (ch < info.channels)
- cassette->get_samples(ch, time_index, duration, outputs[0].samples(), 2, &m_samples[0], cassette_image::WAVEFORM_16BIT);
+ cassette->get_samples(ch, time_index, duration, samples, 2, &m_samples[0], cassette_image::WAVEFORM_16BIT);
else
- cassette->get_samples(0, time_index, duration, outputs[0].samples(), 2, &m_samples[0], cassette_image::WAVEFORM_16BIT);
- for (int sampindex = 0; sampindex < outputs[ch].samples(); sampindex++)
- outputs[ch].put_int(sampindex, m_samples[sampindex], 32768);
+ cassette->get_samples(0, time_index, duration, samples, 2, &m_samples[0], cassette_image::WAVEFORM_16BIT);
+ for (int sampindex = 0; sampindex < samples; sampindex++)
+ stream.put_int(ch, sampindex, m_samples[sampindex], 32768);
}
}
- else
- {
- for (int ch = 0; ch < outputs.size(); ch++)
- outputs[ch].fill(0);
- }
}