mirror of
https://github.com/holub/mame
synced 2025-05-10 00:01:52 +03:00
Cassette device modernized (no whatsnew)
This commit is contained in:
parent
d565bd41e6
commit
079e1fa5fa
@ -18,205 +18,193 @@
|
||||
#define VERBOSE 0
|
||||
#define LOG(x) do { if (VERBOSE) logerror x; } while (0)
|
||||
|
||||
|
||||
typedef struct _dev_cassette_t dev_cassette_t;
|
||||
struct _dev_cassette_t
|
||||
{
|
||||
const cassette_config *config;
|
||||
cassette_image *cassette;
|
||||
cassette_state state;
|
||||
double position;
|
||||
double position_time;
|
||||
INT32 value;
|
||||
};
|
||||
|
||||
|
||||
/* Default cassette_config for drivers only wav files */
|
||||
const cassette_config default_cassette_config =
|
||||
/* Default cassette_interface for drivers only wav files */
|
||||
const cassette_interface default_cassette_interface =
|
||||
{
|
||||
cassette_default_formats,
|
||||
NULL,
|
||||
CASSETTE_PLAY,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
INLINE dev_cassette_t *get_safe_token(device_t *device)
|
||||
// device type definition
|
||||
const device_type CASSETTE = &device_creator<cassette_image_device>;
|
||||
|
||||
//-------------------------------------------------
|
||||
// cassette_image_device - constructor
|
||||
//-------------------------------------------------
|
||||
|
||||
cassette_image_device::cassette_image_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
|
||||
: device_t(mconfig, CASSETTE, "Cassette", tag, owner, clock),
|
||||
device_image_interface(mconfig, *this)
|
||||
{
|
||||
assert( device != NULL );
|
||||
assert( device->type() == CASSETTE );
|
||||
return (dev_cassette_t *) downcast<legacy_device_base *>(device)->token();
|
||||
|
||||
}
|
||||
|
||||
INLINE const inline_cassette_config *get_config_dev(const device_t *device)
|
||||
//-------------------------------------------------
|
||||
// cassette_image_device - destructor
|
||||
//-------------------------------------------------
|
||||
|
||||
cassette_image_device::~cassette_image_device()
|
||||
{
|
||||
assert(device != NULL);
|
||||
assert(device->type() == CASSETTE);
|
||||
return (const inline_cassette_config *)downcast<const legacy_device_base *>(device)->inline_config();
|
||||
}
|
||||
|
||||
//-------------------------------------------------
|
||||
// device_config_complete - perform any
|
||||
// operations now that the configuration is
|
||||
// complete
|
||||
//-------------------------------------------------
|
||||
|
||||
void cassette_image_device::device_config_complete()
|
||||
{
|
||||
// inherit a copy of the static data
|
||||
const cassette_interface *intf = reinterpret_cast<const cassette_interface *>(static_config());
|
||||
if (intf != NULL)
|
||||
*static_cast<cassette_interface *>(this) = *intf;
|
||||
|
||||
// or initialize to defaults if none provided
|
||||
else
|
||||
{
|
||||
memset(&m_formats, 0, sizeof(m_formats));
|
||||
memset(&m_create_opts, 0, sizeof(m_create_opts));
|
||||
memset(&m_default_state, 0, sizeof(m_default_state));
|
||||
memset(&m_interface, 0, sizeof(m_interface));
|
||||
memset(&m_device_displayinfo, 0, sizeof(m_device_displayinfo));
|
||||
}
|
||||
|
||||
m_extension_list[0] = '\0';
|
||||
for (int i = 0; m_formats[i]; i++ )
|
||||
image_specify_extension( m_extension_list, 256, m_formats[i]->extensions );
|
||||
|
||||
// set brief and instance name
|
||||
update_names();
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
cassette IO
|
||||
*********************************************************************/
|
||||
|
||||
INLINE int cassette_is_motor_on(device_t *device)
|
||||
bool cassette_image_device::is_motor_on()
|
||||
{
|
||||
dev_cassette_t *cassette = get_safe_token( device );
|
||||
|
||||
if ((cassette->state & CASSETTE_MASK_UISTATE) == CASSETTE_STOPPED)
|
||||
if ((m_state & CASSETTE_MASK_UISTATE) == CASSETTE_STOPPED)
|
||||
return FALSE;
|
||||
if ((cassette->state & CASSETTE_MASK_MOTOR) != CASSETTE_MOTOR_ENABLED)
|
||||
if ((m_state & CASSETTE_MASK_MOTOR) != CASSETTE_MOTOR_ENABLED)
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void cassette_update(device_t *device)
|
||||
void cassette_image_device::update()
|
||||
{
|
||||
dev_cassette_t *cassette = get_safe_token( device );
|
||||
double cur_time = device->machine().time().as_double();
|
||||
double cur_time = device().machine().time().as_double();
|
||||
|
||||
if (cassette_is_motor_on(device))
|
||||
if (is_motor_on())
|
||||
{
|
||||
double new_position = cassette->position + (cur_time - cassette->position_time);
|
||||
double new_position = m_position + (cur_time - m_position_time);
|
||||
|
||||
switch(cassette->state & CASSETTE_MASK_UISTATE) {
|
||||
switch(m_state & CASSETTE_MASK_UISTATE) {
|
||||
case CASSETTE_RECORD:
|
||||
cassette_put_sample(cassette->cassette, 0, cassette->position, new_position - cassette->position, cassette->value);
|
||||
cassette_put_sample(m_cassette, 0, m_position, new_position - m_position, m_value);
|
||||
break;
|
||||
|
||||
case CASSETTE_PLAY:
|
||||
if ( cassette->cassette )
|
||||
if ( m_cassette )
|
||||
{
|
||||
cassette_get_sample(cassette->cassette, 0, new_position, 0.0, &cassette->value);
|
||||
cassette_get_sample(m_cassette, 0, new_position, 0.0, &m_value);
|
||||
/* See if reached end of tape */
|
||||
double length = cassette_get_length(device);
|
||||
double length = get_length();
|
||||
if (new_position > length)
|
||||
{
|
||||
cassette->state = (cassette_state)(( cassette->state & ~CASSETTE_MASK_UISTATE ) | CASSETTE_STOPPED);
|
||||
m_state = (cassette_state)(( m_state & ~CASSETTE_MASK_UISTATE ) | CASSETTE_STOPPED);
|
||||
new_position = length;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
cassette->position = new_position;
|
||||
m_position = new_position;
|
||||
}
|
||||
cassette->position_time = cur_time;
|
||||
m_position_time = cur_time;
|
||||
}
|
||||
|
||||
|
||||
|
||||
cassette_state cassette_get_state(device_t *device)
|
||||
void cassette_image_device::change_state(cassette_state state, cassette_state mask)
|
||||
{
|
||||
dev_cassette_t *cassette = get_safe_token( device );
|
||||
return cassette->state;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void cassette_change_state(device_t *device, cassette_state state, cassette_state mask)
|
||||
{
|
||||
dev_cassette_t *cassette = get_safe_token( device );
|
||||
cassette_state new_state;
|
||||
|
||||
new_state = cassette->state;
|
||||
new_state = m_state;
|
||||
new_state = (cassette_state)(new_state & ~mask);
|
||||
new_state = (cassette_state)(new_state | (state & mask));
|
||||
|
||||
if (new_state != cassette->state)
|
||||
if (new_state != m_state)
|
||||
{
|
||||
cassette_update(device);
|
||||
cassette->state = new_state;
|
||||
update();
|
||||
m_state = new_state;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void cassette_set_state(device_t *device, cassette_state state)
|
||||
double cassette_image_device::input()
|
||||
{
|
||||
cassette_change_state(device, state, (cassette_state)(~0));
|
||||
}
|
||||
|
||||
|
||||
|
||||
double cassette_input(device_t *device)
|
||||
{
|
||||
dev_cassette_t *cassette = get_safe_token( device );
|
||||
INT32 sample;
|
||||
double double_value;
|
||||
|
||||
cassette_update(device);
|
||||
sample = cassette->value;
|
||||
update();
|
||||
sample = m_value;
|
||||
double_value = sample / ((double) 0x7FFFFFFF);
|
||||
|
||||
LOG(("cassette_input(): time_index=%g value=%g\n", cassette->position, double_value));
|
||||
LOG(("cassette_input(): time_index=%g value=%g\n", m_position, double_value));
|
||||
|
||||
return double_value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void cassette_output(device_t *device, double value)
|
||||
void cassette_image_device::output(double value)
|
||||
{
|
||||
dev_cassette_t *cassette = get_safe_token( device );
|
||||
|
||||
if (((cassette->state & CASSETTE_MASK_UISTATE) == CASSETTE_RECORD) && (cassette->value != value))
|
||||
if (((m_state & CASSETTE_MASK_UISTATE) == CASSETTE_RECORD) && (m_value != value))
|
||||
{
|
||||
cassette_update(device);
|
||||
update();
|
||||
|
||||
value = MIN(value, 1.0);
|
||||
value = MAX(value, -1.0);
|
||||
|
||||
cassette->value = (INT32) (value * 0x7FFFFFFF);
|
||||
m_value = (INT32) (value * 0x7FFFFFFF);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
cassette_image *cassette_get_image(device_t *device)
|
||||
double cassette_image_device::get_position()
|
||||
{
|
||||
dev_cassette_t *cassette = get_safe_token( device );
|
||||
double position = m_position;
|
||||
|
||||
return cassette->cassette;
|
||||
}
|
||||
|
||||
|
||||
|
||||
double cassette_get_position(device_t *device)
|
||||
{
|
||||
dev_cassette_t *cassette = get_safe_token( device );
|
||||
double position;
|
||||
|
||||
position = cassette->position;
|
||||
|
||||
if (cassette_is_motor_on(device))
|
||||
position += device->machine().time().as_double() - cassette->position_time;
|
||||
if (is_motor_on())
|
||||
position += device().machine().time().as_double() - m_position_time;
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
|
||||
double cassette_get_length(device_t *device)
|
||||
double cassette_image_device::get_length()
|
||||
{
|
||||
dev_cassette_t *cassette = get_safe_token( device );
|
||||
struct CassetteInfo info;
|
||||
|
||||
cassette_get_info(cassette->cassette, &info);
|
||||
cassette_get_info(m_cassette, &info);
|
||||
return ((double) info.sample_count) / info.sample_frequency;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void cassette_seek(device_t *device, double time, int origin)
|
||||
void cassette_image_device::seek(double time, int origin)
|
||||
{
|
||||
dev_cassette_t *cassette = get_safe_token( device );
|
||||
|
||||
double length;
|
||||
|
||||
cassette_update(device);
|
||||
update();
|
||||
|
||||
length = cassette_get_length(device);
|
||||
length = get_length();
|
||||
|
||||
switch(origin) {
|
||||
case SEEK_SET:
|
||||
@ -227,7 +215,7 @@ void cassette_seek(device_t *device, double time, int origin)
|
||||
break;
|
||||
|
||||
case SEEK_CUR:
|
||||
time += cassette_get_position(device);
|
||||
time += get_position();
|
||||
break;
|
||||
}
|
||||
|
||||
@ -238,7 +226,7 @@ void cassette_seek(device_t *device, double time, int origin)
|
||||
if (time > length)
|
||||
time = length;
|
||||
|
||||
cassette->position = time;
|
||||
m_position = time;
|
||||
}
|
||||
|
||||
|
||||
@ -247,37 +235,26 @@ void cassette_seek(device_t *device, double time, int origin)
|
||||
cassette device init/load/unload/specify
|
||||
*********************************************************************/
|
||||
|
||||
static DEVICE_START( cassette )
|
||||
void cassette_image_device::device_start()
|
||||
{
|
||||
dev_cassette_t *cassette = get_safe_token( device );
|
||||
|
||||
/* set to default state */
|
||||
cassette->config = (const cassette_config*)device->static_config();
|
||||
cassette->cassette = NULL;
|
||||
cassette->state = cassette->config->default_state;
|
||||
m_cassette = NULL;
|
||||
m_state = m_default_state;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static DEVICE_IMAGE_LOAD( cassette )
|
||||
bool cassette_image_device::call_load()
|
||||
{
|
||||
device_t *device = &image.device();
|
||||
dev_cassette_t *cassette = get_safe_token( device );
|
||||
casserr_t err;
|
||||
int cassette_flags;
|
||||
const struct CassetteFormat * const *formats;
|
||||
const struct CassetteOptions *create_opts;
|
||||
const char *extension;
|
||||
int is_writable;
|
||||
device_image_interface *image = NULL;
|
||||
interface(image);
|
||||
|
||||
/* figure out the cassette format */
|
||||
formats = cassette->config->formats;
|
||||
|
||||
if (image.has_been_created())
|
||||
if (has_been_created())
|
||||
{
|
||||
/* creating an image */
|
||||
create_opts = cassette->config->create_opts;
|
||||
err = cassette_create((void *) &image, &image_ioprocs, &wavfile_format, create_opts, CASSETTE_FLAG_READWRITE|CASSETTE_FLAG_SAVEONEXIT, &cassette->cassette);
|
||||
err = cassette_create((void *)image, &image_ioprocs, &wavfile_format, m_create_opts, CASSETTE_FLAG_READWRITE|CASSETTE_FLAG_SAVEONEXIT, &m_cassette);
|
||||
if (err)
|
||||
goto error;
|
||||
}
|
||||
@ -286,14 +263,14 @@ static DEVICE_IMAGE_LOAD( cassette )
|
||||
/* opening an image */
|
||||
do
|
||||
{
|
||||
is_writable = !image.is_readonly();
|
||||
is_writable = !is_readonly();
|
||||
cassette_flags = is_writable ? (CASSETTE_FLAG_READWRITE|CASSETTE_FLAG_SAVEONEXIT) : CASSETTE_FLAG_READONLY;
|
||||
extension = image.filetype();
|
||||
err = cassette_open_choices((void *) &image, &image_ioprocs, extension, formats, cassette_flags, &cassette->cassette);
|
||||
extension = filetype();
|
||||
err = cassette_open_choices((void *)image, &image_ioprocs, extension, m_formats, cassette_flags, &m_cassette);
|
||||
|
||||
/* this is kind of a hack */
|
||||
if (err && is_writable)
|
||||
image.make_readonly();
|
||||
make_readonly();
|
||||
}
|
||||
while(err && is_writable);
|
||||
|
||||
@ -302,11 +279,11 @@ static DEVICE_IMAGE_LOAD( cassette )
|
||||
}
|
||||
|
||||
/* set to default state, but only change the UI state */
|
||||
cassette_change_state(device, cassette->config->default_state, CASSETTE_MASK_UISTATE);
|
||||
change_state(m_default_state, CASSETTE_MASK_UISTATE);
|
||||
|
||||
/* reset the position */
|
||||
cassette->position = 0.0;
|
||||
cassette->position_time = device->machine().time().as_double();
|
||||
m_position = 0.0;
|
||||
m_position_time = device().machine().time().as_double();
|
||||
|
||||
return IMAGE_INIT_PASS;
|
||||
|
||||
@ -316,21 +293,19 @@ error:
|
||||
|
||||
|
||||
|
||||
static DEVICE_IMAGE_UNLOAD( cassette )
|
||||
void cassette_image_device::call_unload()
|
||||
{
|
||||
device_t *device = &image.device();
|
||||
dev_cassette_t *cassette = get_safe_token( device );
|
||||
|
||||
/* if we are recording, write the value to the image */
|
||||
if ((cassette->state & CASSETTE_MASK_UISTATE) == CASSETTE_RECORD)
|
||||
cassette_update(device);
|
||||
if ((m_state & CASSETTE_MASK_UISTATE) == CASSETTE_RECORD)
|
||||
update();
|
||||
|
||||
/* close out the cassette */
|
||||
cassette_close(cassette->cassette);
|
||||
cassette->cassette = NULL;
|
||||
cassette_close(m_cassette);
|
||||
m_cassette = NULL;
|
||||
|
||||
/* set to default state, but only change the UI state */
|
||||
cassette_change_state(device, CASSETTE_STOPPED, CASSETTE_MASK_UISTATE);
|
||||
change_state(CASSETTE_STOPPED, CASSETTE_MASK_UISTATE);
|
||||
}
|
||||
|
||||
|
||||
@ -338,9 +313,8 @@ static DEVICE_IMAGE_UNLOAD( cassette )
|
||||
/*
|
||||
display a small tape icon, with the current position in the tape image
|
||||
*/
|
||||
static DEVICE_IMAGE_DISPLAY(cassette)
|
||||
void cassette_image_device::call_display()
|
||||
{
|
||||
device_t *device = &image.device();
|
||||
char buf[65];
|
||||
float x, y;
|
||||
int n;
|
||||
@ -350,29 +324,29 @@ static DEVICE_IMAGE_DISPLAY(cassette)
|
||||
static const UINT8 shapes[8] = { 0x2d, 0x5c, 0x7c, 0x2f, 0x2d, 0x20, 0x20, 0x20 };
|
||||
|
||||
/* abort if we should not be showing the image */
|
||||
if (!image.exists())
|
||||
if (!exists())
|
||||
return;
|
||||
if (!cassette_is_motor_on(device))
|
||||
if (!is_motor_on())
|
||||
return;
|
||||
|
||||
/* figure out where we are in the cassette */
|
||||
position = cassette_get_position(device);
|
||||
length = cassette_get_length(device);
|
||||
uistate = (cassette_state)(cassette_get_state(device) & CASSETTE_MASK_UISTATE);
|
||||
position = get_position();
|
||||
length = get_length();
|
||||
uistate = (cassette_state)(get_state() & CASSETTE_MASK_UISTATE);
|
||||
|
||||
/* choose a location on the screen */
|
||||
x = 0.2f;
|
||||
y = 0.5f;
|
||||
|
||||
dev = device->machine().devicelist().first(CASSETTE );
|
||||
dev = device().machine().devicelist().first(CASSETTE );
|
||||
|
||||
while ( dev && strcmp( dev->tag(), device->tag() ) )
|
||||
while ( dev && strcmp( dev->tag(), device().tag() ) )
|
||||
{
|
||||
y += 1;
|
||||
dev = dev->typenext();
|
||||
}
|
||||
|
||||
y *= ui_get_line_height(device->machine()) + 2.0f * UI_BOX_TB_BORDER;
|
||||
y *= ui_get_line_height(device().machine()) + 2.0f * UI_BOX_TB_BORDER;
|
||||
/* choose which frame of the animation we are at */
|
||||
n = ((int) position / ANIMATION_FPS) % ANIMATION_FRAMES;
|
||||
/* Since you can have anything in a BDF file, we will use crude ascii characters instead */
|
||||
@ -397,67 +371,5 @@ static DEVICE_IMAGE_DISPLAY(cassette)
|
||||
(int) length);
|
||||
|
||||
/* draw the cassette */
|
||||
ui_draw_text_box(&device->machine().render().ui_container(), buf, JUSTIFY_LEFT, x, y, UI_BACKGROUND_COLOR);
|
||||
ui_draw_text_box(&device().machine().render().ui_container(), buf, JUSTIFY_LEFT, x, y, UI_BACKGROUND_COLOR);
|
||||
}
|
||||
|
||||
/*-------------------------------------------------
|
||||
DEVICE_IMAGE_SOFTLIST_LOAD(cassette)
|
||||
-------------------------------------------------*/
|
||||
static DEVICE_IMAGE_SOFTLIST_LOAD(cassette)
|
||||
{
|
||||
return image.load_software(swlist, swname, start_entry);
|
||||
}
|
||||
|
||||
DEVICE_GET_INFO(cassette)
|
||||
{
|
||||
switch( state )
|
||||
{
|
||||
/* --- the following bits of info are returned as 64-bit signed integers --- */
|
||||
case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(dev_cassette_t); break;
|
||||
case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = sizeof(inline_cassette_config); break;
|
||||
case DEVINFO_INT_IMAGE_TYPE: info->i = IO_CASSETTE; break;
|
||||
case DEVINFO_INT_IMAGE_READABLE: info->i = 1; break;
|
||||
case DEVINFO_INT_IMAGE_WRITEABLE: info->i = 1; break;
|
||||
case DEVINFO_INT_IMAGE_CREATABLE: info->i = 1; break;
|
||||
|
||||
/* --- the following bits of info are returned as pointers to data or functions --- */
|
||||
case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(cassette); break;
|
||||
case DEVINFO_FCT_IMAGE_LOAD: info->f = (genf *) DEVICE_IMAGE_LOAD_NAME(cassette); break;
|
||||
case DEVINFO_FCT_IMAGE_UNLOAD: info->f = (genf *) DEVICE_IMAGE_UNLOAD_NAME(cassette); break;
|
||||
case DEVINFO_FCT_IMAGE_DISPLAY: info->f = (genf *) DEVICE_IMAGE_DISPLAY_NAME(cassette); break;
|
||||
case DEVINFO_FCT_IMAGE_SOFTLIST_LOAD: info->f = (genf *) DEVICE_IMAGE_SOFTLIST_LOAD_NAME(cassette); break;
|
||||
case DEVINFO_FCT_IMAGE_DISPLAY_INFO:
|
||||
if ( device && downcast<const legacy_image_device_base *>(device)->inline_config() && get_config_dev(device)->device_displayinfo) {
|
||||
info->f = (genf *) get_config_dev(device)->device_displayinfo;
|
||||
} else {
|
||||
info->f = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
/* --- the following bits of info are returned as NULL-terminated strings --- */
|
||||
case DEVINFO_STR_NAME: strcpy(info->s, "Cassette"); break;
|
||||
case DEVINFO_STR_FAMILY: strcpy(info->s, "Cassette"); break;
|
||||
case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break;
|
||||
case DEVINFO_STR_IMAGE_FILE_EXTENSIONS:
|
||||
if ( device && device->static_config() )
|
||||
{
|
||||
const struct CassetteFormat * const *formats = ((cassette_config *)device->static_config())->formats;
|
||||
int i;
|
||||
|
||||
/* set up a temporary string */
|
||||
info->s[0] = '\0';
|
||||
|
||||
for ( i = 0; formats[i]; i++ )
|
||||
image_specify_extension( info->s, 256, formats[i]->extensions );
|
||||
}
|
||||
break;
|
||||
case DEVINFO_STR_IMAGE_INTERFACE:
|
||||
if ( device && device->static_config() && ((cassette_config *)device->static_config())->interface)
|
||||
{
|
||||
strcpy(info->s, ((cassette_config *)device->static_config())->interface );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DEFINE_LEGACY_IMAGE_DEVICE(CASSETTE, cassette);
|
||||
|
@ -40,38 +40,77 @@ typedef enum _cassette_state cassette_state;
|
||||
TYPE DEFINITIONS
|
||||
***************************************************************************/
|
||||
|
||||
typedef struct cassette_config_t cassette_config;
|
||||
struct cassette_config_t
|
||||
// ======================> cassette_interface
|
||||
|
||||
struct cassette_interface
|
||||
{
|
||||
const struct CassetteFormat* const *formats;
|
||||
const struct CassetteOptions *create_opts;
|
||||
const cassette_state default_state;
|
||||
const char * interface;
|
||||
const struct CassetteFormat* const *m_formats;
|
||||
const struct CassetteOptions *m_create_opts;
|
||||
cassette_state m_default_state;
|
||||
const char * m_interface;
|
||||
device_image_display_info_func m_device_displayinfo;
|
||||
};
|
||||
|
||||
typedef struct inline_cassette_config_t inline_cassette_config;
|
||||
struct inline_cassette_config_t
|
||||
// ======================> cassette_image_device
|
||||
|
||||
class cassette_image_device : public device_t,
|
||||
public cassette_interface,
|
||||
public device_image_interface
|
||||
{
|
||||
device_image_display_info_func device_displayinfo;
|
||||
public:
|
||||
// construction/destruction
|
||||
cassette_image_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
|
||||
virtual ~cassette_image_device();
|
||||
|
||||
// image-level overrides
|
||||
virtual bool call_load();
|
||||
virtual void call_unload();
|
||||
virtual void call_display();
|
||||
virtual void call_display_info() { m_device_displayinfo(*this); }
|
||||
virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) { return load_software(swlist, swname, start_entry); }
|
||||
|
||||
virtual iodevice_t image_type() const { return IO_CASSETTE; }
|
||||
|
||||
virtual bool is_readable() const { return 1; }
|
||||
virtual bool is_writeable() const { return 1; }
|
||||
virtual bool is_creatable() const { return 1; }
|
||||
virtual bool must_be_loaded() const { return 0; }
|
||||
virtual bool is_reset_on_load() const { return 0; }
|
||||
virtual const char *image_interface() const { return m_interface; }
|
||||
virtual const char *file_extensions() const { return m_extension_list; }
|
||||
virtual const option_guide *create_option_guide() const { return NULL; }
|
||||
|
||||
// specific implementation
|
||||
cassette_state get_state() { return m_state; }
|
||||
void set_state(cassette_state state) { change_state(m_state, (cassette_state)(~0)); }
|
||||
void change_state(cassette_state state, cassette_state mask);
|
||||
|
||||
double input();
|
||||
void output(double value);
|
||||
|
||||
cassette_image *get_image() { return m_cassette; }
|
||||
double get_position();
|
||||
double get_length();
|
||||
void seek(double time, int origin);
|
||||
|
||||
protected:
|
||||
bool is_motor_on();
|
||||
void update();
|
||||
|
||||
// device-level overrides
|
||||
virtual void device_config_complete();
|
||||
virtual void device_start();
|
||||
private:
|
||||
cassette_image *m_cassette;
|
||||
cassette_state m_state;
|
||||
double m_position;
|
||||
double m_position_time;
|
||||
INT32 m_value;
|
||||
char m_extension_list[256];
|
||||
};
|
||||
|
||||
/***************************************************************************
|
||||
FUNCTION PROTOTYPES
|
||||
***************************************************************************/
|
||||
|
||||
cassette_state cassette_get_state(device_t *cassette);
|
||||
void cassette_set_state(device_t *cassette, cassette_state state);
|
||||
void cassette_change_state(device_t *cassette, cassette_state state, cassette_state mask);
|
||||
|
||||
double cassette_input(device_t *cassette);
|
||||
void cassette_output(device_t *cassette, double value);
|
||||
|
||||
cassette_image *cassette_get_image(device_t *cassette);
|
||||
double cassette_get_position(device_t *cassette);
|
||||
double cassette_get_length(device_t *cassette);
|
||||
void cassette_seek(device_t *cassette, double time, int origin);
|
||||
|
||||
DECLARE_LEGACY_IMAGE_DEVICE(CASSETTE, cassette);
|
||||
// device type definition
|
||||
extern const device_type CASSETTE;
|
||||
|
||||
/***************************************************************************
|
||||
DEVICE CONFIGURATION MACROS
|
||||
@ -87,9 +126,6 @@ DECLARE_LEGACY_IMAGE_DEVICE(CASSETTE, cassette);
|
||||
MCFG_DEVICE_MODIFY(_tag) \
|
||||
MCFG_DEVICE_CONFIG(_config)
|
||||
|
||||
#define MCFG_CASSETTE_DISPLAY_INFO(_displayinfo) \
|
||||
MCFG_DEVICE_CONFIG_DATAPTR(inline_cassette_config, device_displayinfo, DEVICE_IMAGE_DISPLAY_INFO_NAME(_displayinfo))
|
||||
|
||||
extern const cassette_config default_cassette_config;
|
||||
extern const cassette_interface default_cassette_interface;
|
||||
|
||||
#endif /* CASSETTE_H */
|
||||
|
@ -21,8 +21,8 @@
|
||||
|
||||
static STREAM_UPDATE( wave_sound_update )
|
||||
{
|
||||
device_image_interface *image = (device_image_interface *)param;
|
||||
int speakers = image->device().machine().devicelist().count(SPEAKER);
|
||||
cassette_image_device *cass = (cassette_image_device *)param;
|
||||
int speakers = cass->machine().devicelist().count(SPEAKER);
|
||||
cassette_image *cassette;
|
||||
cassette_state state;
|
||||
double time_index;
|
||||
@ -34,15 +34,15 @@ static STREAM_UPDATE( wave_sound_update )
|
||||
if (speakers>1)
|
||||
right_buffer = outputs[1];
|
||||
|
||||
state = cassette_get_state(&image->device());
|
||||
state = cass->get_state();
|
||||
|
||||
state = (cassette_state)(state & (CASSETTE_MASK_UISTATE | CASSETTE_MASK_MOTOR | CASSETTE_MASK_SPEAKER));
|
||||
|
||||
if (image->exists() && (ALWAYS_PLAY_SOUND || (state == (CASSETTE_PLAY | CASSETTE_MOTOR_ENABLED | CASSETTE_SPEAKER_ENABLED))))
|
||||
if (cass->exists() && (ALWAYS_PLAY_SOUND || (state == (CASSETTE_PLAY | CASSETTE_MOTOR_ENABLED | CASSETTE_SPEAKER_ENABLED))))
|
||||
{
|
||||
cassette = cassette_get_image(&image->device());
|
||||
time_index = cassette_get_position(&image->device());
|
||||
duration = ((double) samples) / image->device().machine().sample_rate();
|
||||
cassette = cass->get_image();
|
||||
time_index = cass->get_position();
|
||||
duration = ((double) samples) / cass->machine().sample_rate();
|
||||
|
||||
cassette_get_samples(cassette, 0, time_index, duration, samples, 2, left_buffer, CASSETTE_WAVEFORM_16BIT);
|
||||
if (speakers > 1)
|
||||
@ -67,12 +67,12 @@ static STREAM_UPDATE( wave_sound_update )
|
||||
|
||||
static DEVICE_START( wave )
|
||||
{
|
||||
device_image_interface *image = NULL;
|
||||
cassette_image_device *image = NULL;
|
||||
|
||||
assert( device != NULL );
|
||||
assert( device->static_config() != NULL );
|
||||
int speakers = device->machine().config().devicelist().count(SPEAKER);
|
||||
image = dynamic_cast<device_image_interface *>(device->machine().device( (const char *)device->static_config()));
|
||||
image = dynamic_cast<cassette_image_device *>(device->machine().device( (const char *)device->static_config()));
|
||||
if (speakers > 1)
|
||||
device->machine().sound().stream_alloc(*device, 0, 2, device->machine().sample_rate(), (void *)image, wave_sound_update);
|
||||
else
|
||||
|
@ -1207,12 +1207,12 @@ INLINE int bitbanger_count( running_machine &machine )
|
||||
representation of the time
|
||||
-------------------------------------------------*/
|
||||
|
||||
astring *tapecontrol_gettime(astring *dest, device_t *device, int *curpos, int *endpos)
|
||||
astring *tapecontrol_gettime(astring *dest, cassette_image_device *cassette, int *curpos, int *endpos)
|
||||
{
|
||||
double t0, t1;
|
||||
|
||||
t0 = cassette_get_position(device);
|
||||
t1 = cassette_get_length(device);
|
||||
t0 = cassette->get_position();
|
||||
t1 = cassette->get_length();
|
||||
|
||||
if (t1)
|
||||
astring_printf(dest, "%04d/%04d", (int) t0, (int) t1);
|
||||
@ -1253,9 +1253,10 @@ static void menu_tape_control_populate(running_machine &machine, ui_menu *menu,
|
||||
{
|
||||
double t0, t1;
|
||||
UINT32 tapeflags = 0;
|
||||
cassette_image_device* cassette = dynamic_cast<cassette_image_device*>(&menustate->device->device());
|
||||
|
||||
t0 = cassette_get_position(&menustate->device->device());
|
||||
t1 = cassette_get_length(&menustate->device->device());
|
||||
t0 = cassette->get_position();
|
||||
t1 = cassette->get_length();
|
||||
|
||||
if (t1 > 0)
|
||||
{
|
||||
@ -1269,8 +1270,8 @@ static void menu_tape_control_populate(running_machine &machine, ui_menu *menu,
|
||||
ui_menu_item_append(menu, menustate->device->device().name(), menustate->device->filename(), flags, TAPECMD_SELECT);
|
||||
|
||||
/* state */
|
||||
tapecontrol_gettime(&timepos, &menustate->device->device(), NULL, NULL);
|
||||
state = cassette_get_state(&menustate->device->device());
|
||||
tapecontrol_gettime(&timepos, cassette, NULL, NULL);
|
||||
state = cassette->get_state();
|
||||
ui_menu_item_append(
|
||||
menu,
|
||||
(state & CASSETTE_MASK_UISTATE) == CASSETTE_STOPPED
|
||||
@ -1394,6 +1395,8 @@ void ui_mess_menu_tape_control(running_machine &machine, ui_menu *menu, void *pa
|
||||
ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_POSITION);
|
||||
menu_tape_control_populate(machine, menu, (tape_control_menu_state*)state);
|
||||
|
||||
cassette_image_device* cassette = dynamic_cast<cassette_image_device*>(&menustate->device->device());
|
||||
|
||||
/* process the menu */
|
||||
event = ui_menu_process(machine, menu, UI_MENU_PROCESS_LR_REPEAT);
|
||||
if (event != NULL)
|
||||
@ -1402,7 +1405,7 @@ void ui_mess_menu_tape_control(running_machine &machine, ui_menu *menu, void *pa
|
||||
{
|
||||
case IPT_UI_LEFT:
|
||||
if (event->itemref==TAPECMD_SLIDER)
|
||||
cassette_seek(&menustate->device->device(), -1, SEEK_CUR);
|
||||
cassette->seek(-1, SEEK_CUR);
|
||||
else
|
||||
if (event->itemref==TAPECMD_SELECT)
|
||||
{
|
||||
@ -1417,7 +1420,7 @@ void ui_mess_menu_tape_control(running_machine &machine, ui_menu *menu, void *pa
|
||||
|
||||
case IPT_UI_RIGHT:
|
||||
if (event->itemref==TAPECMD_SLIDER)
|
||||
cassette_seek(&menustate->device->device(), +1, SEEK_CUR);
|
||||
cassette->seek(+1, SEEK_CUR);
|
||||
else
|
||||
if (event->itemref==TAPECMD_SELECT)
|
||||
{
|
||||
@ -1433,22 +1436,22 @@ void ui_mess_menu_tape_control(running_machine &machine, ui_menu *menu, void *pa
|
||||
case IPT_UI_SELECT:
|
||||
{
|
||||
if (event->itemref==TAPECMD_STOP)
|
||||
cassette_change_state(&menustate->device->device(), CASSETTE_STOPPED, CASSETTE_MASK_UISTATE);
|
||||
cassette->change_state(CASSETTE_STOPPED, CASSETTE_MASK_UISTATE);
|
||||
else
|
||||
if (event->itemref==TAPECMD_PLAY)
|
||||
cassette_change_state(&menustate->device->device(), CASSETTE_PLAY, CASSETTE_MASK_UISTATE);
|
||||
cassette->change_state(CASSETTE_PLAY, CASSETTE_MASK_UISTATE);
|
||||
else
|
||||
if (event->itemref==TAPECMD_RECORD)
|
||||
cassette_change_state(&menustate->device->device(), CASSETTE_RECORD, CASSETTE_MASK_UISTATE);
|
||||
cassette->change_state(CASSETTE_RECORD, CASSETTE_MASK_UISTATE);
|
||||
else
|
||||
if (event->itemref==TAPECMD_REWIND)
|
||||
cassette_seek(&menustate->device->device(), -30, SEEK_CUR);
|
||||
cassette->seek(-30, SEEK_CUR);
|
||||
else
|
||||
if (event->itemref==TAPECMD_FAST_FORWARD)
|
||||
cassette_seek(&menustate->device->device(), 30, SEEK_CUR);
|
||||
cassette->seek(30, SEEK_CUR);
|
||||
else
|
||||
if (event->itemref==TAPECMD_SLIDER)
|
||||
cassette_seek(&menustate->device->device(), 0, SEEK_SET);
|
||||
cassette->seek(0, SEEK_SET);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -2435,7 +2435,7 @@ static void image_update_menu(debugwin_info *info)
|
||||
if (img->device().type() == CASSETTE)
|
||||
{
|
||||
cassette_state state;
|
||||
state = (cassette_state)(img->exists() ? (cassette_get_state(&img->device()) & CASSETTE_MASK_UISTATE) : CASSETTE_STOPPED);
|
||||
state = (cassette_state)(img->exists() ? (dynamic_cast<cassette_image_device*>(&img->device())->get_state() & CASSETTE_MASK_UISTATE) : CASSETTE_STOPPED);
|
||||
AppendMenu(devicesubmenu, MF_SEPARATOR, 0, NULL);
|
||||
AppendMenu(devicesubmenu, flags_for_exists | ((state == CASSETTE_STOPPED) ? MF_CHECKED : 0), new_item + DEVOPTION_CASSETTE_STOPPAUSE, TEXT("Pause/Stop"));
|
||||
AppendMenu(devicesubmenu, flags_for_exists | ((state == CASSETTE_PLAY) ? MF_CHECKED : 0), new_item + DEVOPTION_CASSETTE_PLAY, TEXT("Play"));
|
||||
@ -2946,23 +2946,24 @@ static int global_handle_command(debugwin_info *info, WPARAM wparam, LPARAM lpar
|
||||
return 1;
|
||||
default:
|
||||
if (img->device().type() == CASSETTE) {
|
||||
cassette_image_device* cassette = dynamic_cast<cassette_image_device*>(&img->device());
|
||||
switch ((LOWORD(wparam) - ID_DEVICE_OPTIONS) % DEVOPTION_MAX)
|
||||
{
|
||||
|
||||
case DEVOPTION_CASSETTE_STOPPAUSE:
|
||||
cassette_change_state(&img->device(), CASSETTE_STOPPED, CASSETTE_MASK_UISTATE);
|
||||
cassette->change_state(CASSETTE_STOPPED, CASSETTE_MASK_UISTATE);
|
||||
return 1;
|
||||
case DEVOPTION_CASSETTE_PLAY:
|
||||
cassette_change_state(&img->device(), CASSETTE_PLAY, CASSETTE_MASK_UISTATE);
|
||||
cassette->change_state(CASSETTE_PLAY, CASSETTE_MASK_UISTATE);
|
||||
return 1;
|
||||
case DEVOPTION_CASSETTE_RECORD:
|
||||
cassette_change_state(&img->device(), CASSETTE_RECORD, CASSETTE_MASK_UISTATE);
|
||||
cassette->change_state(CASSETTE_RECORD, CASSETTE_MASK_UISTATE);
|
||||
return 1;
|
||||
case DEVOPTION_CASSETTE_REWIND:
|
||||
cassette_seek(&img->device(), -60.0, SEEK_CUR);
|
||||
cassette->seek(-60.0, SEEK_CUR);
|
||||
return 1;
|
||||
case DEVOPTION_CASSETTE_FASTFORWARD:
|
||||
cassette_seek(&img->device(), +60.0, SEEK_CUR);
|
||||
cassette->seek(+60.0, SEEK_CUR);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user