Converted printer image device to modern (no whatsnew)

This commit is contained in:
Miodrag Milanovic 2011-06-14 10:10:17 +00:00
parent 1f516b966d
commit 733d00f28e
6 changed files with 156 additions and 111 deletions

View File

@ -76,9 +76,6 @@ legacy_image_device_base::legacy_image_device_base(const machine_config &mconfig
void legacy_image_device_base::device_config_complete() void legacy_image_device_base::device_config_complete()
{ {
const device_image_interface *image = NULL;
int count = 0;
int index = -1;
image_device_format **formatptr; image_device_format **formatptr;
image_device_format *format; image_device_format *format;
formatptr = &m_formatlist; formatptr = &m_formatlist;
@ -107,22 +104,8 @@ void legacy_image_device_base::device_config_complete()
} }
} }
for (bool gotone = device_t::m_machine_config.devicelist().first(image); gotone; gotone = image->next(image)) update_names();
{
if (this == image)
index = count;
if (image->image_type() == image_type())
count++;
}
if (count > 1) {
m_instance_name.printf("%s%d", device_typename(image_type()), index + 1);
m_brief_instance_name.printf("%s%d", device_brieftypename(image_type()), index + 1);
}
else
{
m_instance_name = device_typename(image_type());
m_brief_instance_name = device_brieftypename(image_type());
}
// Override in case of hardcoded values // Override in case of hardcoded values
if (strlen(get_legacy_string(DEVINFO_STR_IMAGE_INSTANCE_NAME))>0) { if (strlen(get_legacy_string(DEVINFO_STR_IMAGE_INSTANCE_NAME))>0) {
m_instance_name = get_legacy_string(DEVINFO_STR_IMAGE_INSTANCE_NAME); m_instance_name = get_legacy_string(DEVINFO_STR_IMAGE_INSTANCE_NAME);

View File

@ -702,13 +702,13 @@ bool device_image_interface::load_software(char *swlist, char *swname, rom_entry
{ {
for (software_info *swinfo = software_list_find(software_list_ptr, swname, NULL); swinfo != NULL; ) for (software_info *swinfo = software_list_find(software_list_ptr, swname, NULL); swinfo != NULL; )
{ {
if (swinfo != NULL)
{ {
astring tmp(swinfo->shortname); astring tmp(swinfo->shortname);
locationtag.cat(tmp); locationtag.cat(tmp);
locationtag.cat(breakstr); locationtag.cat(breakstr);
//printf("%s\n", locationtag.cstr()); //printf("%s\n", locationtag.cstr());
} }
const char *parentname = software_get_clone(device().machine().options(), swlist, swinfo->shortname); const char *parentname = software_get_clone(device().machine().options(), swlist, swinfo->shortname);
if (parentname != NULL) if (parentname != NULL)
swinfo = software_list_find(software_list_ptr, parentname, NULL); swinfo = software_list_find(software_list_ptr, parentname, NULL);
@ -1005,3 +1005,31 @@ void device_image_interface::unload()
clear(); clear();
clear_error(); clear_error();
} }
/*-------------------------------------------------
update_names - update brief and instance names
-------------------------------------------------*/
void device_image_interface::update_names()
{
const device_image_interface *image = NULL;
int count = 0;
int index = -1;
for (bool gotone = device().mconfig().devicelist().first(image); gotone; gotone = image->next(image))
{
if (this == image)
index = count;
if (image->image_type() == image_type())
count++;
}
if (count > 1) {
m_instance_name.printf("%s%d", device_typename(image_type()), index + 1);
m_brief_instance_name.printf("%s%d", device_brieftypename(image_type()), index + 1);
}
else
{
m_instance_name = device_typename(image_type());
m_brief_instance_name = device_brieftypename(image_type());
}
}

View File

@ -164,15 +164,15 @@ public:
virtual void device_compute_hash(hash_collection &hashes, const void *data, size_t length, const char *types) const; virtual void device_compute_hash(hash_collection &hashes, const void *data, size_t length, const char *types) const;
virtual bool call_load() = 0; virtual bool call_load() { return FALSE; }
virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) = 0; virtual bool call_softlist_load(char *swlist, char *swname, rom_entry *start_entry) { return FALSE; }
virtual bool call_create(int format_type, option_resolution *format_options) = 0; virtual bool call_create(int format_type, option_resolution *format_options) { return FALSE; }
virtual void call_unload() = 0; virtual void call_unload() { }
virtual void call_display() = 0; virtual void call_display() { }
virtual void call_display_info() = 0; virtual void call_display_info() { }
virtual void call_get_devices() = 0; virtual void call_get_devices() { }
virtual void *get_device_specific_call() = 0; virtual void *get_device_specific_call() { return NULL; }
virtual device_image_partialhash_func get_partial_hash() const = 0; virtual device_image_partialhash_func get_partial_hash() const { return NULL; }
virtual iodevice_t image_type() const = 0; virtual iodevice_t image_type() const = 0;
virtual bool is_readable() const = 0; virtual bool is_readable() const = 0;
virtual bool is_writeable() const = 0; virtual bool is_writeable() const = 0;
@ -267,6 +267,7 @@ protected:
int read_hash_config(const char *sysname); int read_hash_config(const char *sysname);
void run_hash(void (*partialhash)(hash_collection &, const unsigned char *, unsigned long, const char *), hash_collection &hashes, const char *types); void run_hash(void (*partialhash)(hash_collection &, const unsigned char *, unsigned long, const char *), hash_collection &hashes, const char *types);
void image_checkhash(); void image_checkhash();
void update_names();
// derived class overrides // derived class overrides
// configuration // configuration

View File

@ -10,6 +10,60 @@
#include "printer.h" #include "printer.h"
// device type definition
const device_type PRINTER = &device_creator<printer_image_device>;
//-------------------------------------------------
// printer_image_device - constructor
//-------------------------------------------------
printer_image_device::printer_image_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, PRINTER, "Printer", tag, owner, clock),
device_image_interface(mconfig, *this)
{
}
//-------------------------------------------------
// printer_image_device - destructor
//-------------------------------------------------
printer_image_device::~printer_image_device()
{
}
//-------------------------------------------------
// device_config_complete - perform any
// operations now that the configuration is
// complete
//-------------------------------------------------
void printer_image_device::device_config_complete()
{
// inherit a copy of the static data
const printer_interface *intf = reinterpret_cast<const printer_interface *>(static_config());
if (intf != NULL)
*static_cast<printer_interface *>(this) = *intf;
// or initialize to defaults if none provided
else
{
memset(&m_online, 0, sizeof(m_online));
}
// set brief and instance name
update_names();
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void printer_image_device::device_start()
{
m_online_func.resolve(m_online, *this);
}
/*************************************************************************** /***************************************************************************
IMPLEMENTATION IMPLEMENTATION
@ -20,11 +74,9 @@
is ready is ready
-------------------------------------------------*/ -------------------------------------------------*/
int printer_is_ready(device_t *printer) int printer_image_device::is_ready()
{ {
device_image_interface *image = dynamic_cast<device_image_interface *>(printer); return exists() != 0;
/* if there is a file attached to it, it's online */
return image->exists() != 0;
} }
@ -33,12 +85,11 @@ int printer_is_ready(device_t *printer)
printer_output - outputs data to a printer printer_output - outputs data to a printer
-------------------------------------------------*/ -------------------------------------------------*/
void printer_output(device_t *printer, UINT8 data) void printer_image_device::output(UINT8 data)
{ {
device_image_interface *image = dynamic_cast<device_image_interface *>(printer); if (exists())
if (image->exists())
{ {
image->fwrite(&data, 1); fwrite(&data, 1);
} }
} }
@ -46,14 +97,11 @@ void printer_output(device_t *printer, UINT8 data)
/*------------------------------------------------- /*-------------------------------------------------
DEVICE_IMAGE_LOAD( printer ) DEVICE_IMAGE_LOAD( printer )
-------------------------------------------------*/ -------------------------------------------------*/
bool printer_image_device::call_load()
static DEVICE_IMAGE_LOAD( printer )
{ {
const printer_config *conf = (const printer_config *)downcast<const legacy_image_device_base &>(image.device()).inline_config();
/* send notify that the printer is now online */ /* send notify that the printer is now online */
if (conf != NULL && conf->online != NULL) if (!m_online_func.isnull())
conf->online(image, TRUE); m_online_func(TRUE);
/* we don't need to do anything special */ /* we don't need to do anything special */
return IMAGE_INIT_PASS; return IMAGE_INIT_PASS;
@ -63,54 +111,10 @@ static DEVICE_IMAGE_LOAD( printer )
/*------------------------------------------------- /*-------------------------------------------------
DEVICE_IMAGE_UNLOAD( printer ) DEVICE_IMAGE_UNLOAD( printer )
-------------------------------------------------*/ -------------------------------------------------*/
void printer_image_device::call_unload()
static DEVICE_IMAGE_UNLOAD( printer )
{ {
const printer_config *conf = (const printer_config *)downcast<const legacy_image_device_base &>(image.device()).inline_config();
/* send notify that the printer is now offline */ /* send notify that the printer is now offline */
if (conf != NULL && conf->online != NULL) if (!m_online_func.isnull())
conf->online(image, FALSE); m_online_func(FALSE);
} }
/*-------------------------------------------------
DEVICE_START(printer)
-------------------------------------------------*/
static DEVICE_START(printer)
{
}
/*-------------------------------------------------
DEVICE_GET_INFO(printer)
-------------------------------------------------*/
DEVICE_GET_INFO(printer)
{
switch(state)
{
/* --- the following bits of info are returned as 64-bit signed integers --- */
case DEVINFO_INT_TOKEN_BYTES: info->i = 1; break;
case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = sizeof(printer_config); break;
case DEVINFO_INT_IMAGE_TYPE: info->i = IO_PRINTER; break;
case DEVINFO_INT_IMAGE_READABLE: info->i = 0; 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(printer); break;
case DEVINFO_FCT_IMAGE_LOAD: info->f = (genf *) DEVICE_IMAGE_LOAD_NAME(printer); break;
case DEVINFO_FCT_IMAGE_UNLOAD: info->f = (genf *) DEVICE_IMAGE_UNLOAD_NAME(printer); break;
/* --- the following bits of info are returned as NULL-terminated strings --- */
case DEVINFO_STR_NAME: strcpy(info->s, "Printer"); break;
case DEVINFO_STR_FAMILY: strcpy(info->s, "Printer"); break;
case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break;
case DEVINFO_STR_IMAGE_FILE_EXTENSIONS: strcpy(info->s, "prn"); break;
}
}
DEFINE_LEGACY_IMAGE_DEVICE(PRINTER, printer);

View File

@ -9,40 +9,69 @@
#ifndef __PRINTER_H__ #ifndef __PRINTER_H__
#define __PRINTER_H__ #define __PRINTER_H__
#include "image.h" #include "diimage.h"
/*************************************************************************** /***************************************************************************
TYPE DEFINITIONS TYPE DEFINITIONS
***************************************************************************/ ***************************************************************************/
typedef void (*online_func)(device_t *device, int state); // ======================> printer_interface
typedef struct _printer_config printer_config; struct printer_interface
struct _printer_config
{ {
online_func online; devcb_write_line m_online;
};
// ======================> printer_image_device
class printer_image_device : public device_t,
public printer_interface,
public device_image_interface
{
public:
// construction/destruction
printer_image_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
virtual ~printer_image_device();
// image-level overrides
virtual bool call_load();
virtual void call_unload();
virtual iodevice_t image_type() const { return IO_PRINTER; }
virtual bool is_readable() const { return 0; }
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 NULL; }
virtual const char *file_extensions() const { return "prn"; }
virtual const option_guide *create_option_guide() const { return NULL; }
// specific implementation
/* checks to see if a printer is ready */
int is_ready();
/* outputs data to a printer */
void output(UINT8 data);
protected:
// device-level overrides
virtual void device_config_complete();
virtual void device_start();
devcb_resolved_write_line m_online_func;
}; };
DECLARE_LEGACY_IMAGE_DEVICE(PRINTER, printer); // device type definition
extern const device_type PRINTER;
#define MCFG_PRINTER_ADD(_tag) \ #define MCFG_PRINTER_ADD(_tag) \
MCFG_DEVICE_ADD(_tag, PRINTER, 0) \ MCFG_DEVICE_ADD(_tag, PRINTER, 0) \
#define MCFG_PRINTER_ONLINE(_online) \ #define MCFG_PRINTER_ONLINE(_online) \
MCFG_DEVICE_CONFIG_DATAPTR(printer_config, online, _online) MCFG_DEVICE_CONFIG_DATAPTR(printer_interface, m_online, _online)
/***************************************************************************
FUNCTION PROTOTYPES
***************************************************************************/
/* checks to see if a printer is ready */
int printer_is_ready(device_t *printer);
/* outputs data to a printer */
void printer_output(device_t *printer, UINT8 data);
#endif /* __PRINTER_H__ */ #endif /* __PRINTER_H__ */

View File

@ -25,7 +25,7 @@ static TIMER_CALLBACK( busy_callback );
typedef struct _centronics_state centronics_state; typedef struct _centronics_state centronics_state;
struct _centronics_state struct _centronics_state
{ {
device_t *printer; printer_image_device *printer;
devcb_resolved_write_line out_ack_func; devcb_resolved_write_line out_ack_func;
devcb_resolved_write_line out_busy_func; devcb_resolved_write_line out_busy_func;
@ -97,7 +97,7 @@ static DEVICE_START( centronics )
centronics->strobe = TRUE; centronics->strobe = TRUE;
/* get printer device */ /* get printer device */
centronics->printer = device->subdevice("printer"); centronics->printer = device->subdevice<printer_image_device>("printer");
/* resolve callbacks */ /* resolve callbacks */
centronics->out_ack_func.resolve(intf->out_ack_func, *device); centronics->out_ack_func.resolve(intf->out_ack_func, *device);
@ -173,7 +173,7 @@ static TIMER_CALLBACK( ack_callback )
if (param == FALSE) if (param == FALSE)
{ {
/* data is now ready, output it */ /* data is now ready, output it */
printer_output(centronics->printer, centronics->data); centronics->printer->output(centronics->data);
/* ready to receive more data, return BUSY to low */ /* ready to receive more data, return BUSY to low */
machine.scheduler().timer_set(attotime::from_usec(7), FUNC(busy_callback), FALSE, ptr); machine.scheduler().timer_set(attotime::from_usec(7), FUNC(busy_callback), FALSE, ptr);