Restructure LPT devices so that lpt_device_t is now only used internally while the exposed LPT devices are now regular device_t's.

This commit is contained in:
OBattler
2026-01-27 06:47:08 +01:00
parent bd21459940
commit 9b7b92622b
12 changed files with 214 additions and 247 deletions

View File

@@ -1704,6 +1704,8 @@ pc_reset_hard_init(void)
ide_hard_reset();
lpt_ports_reset();
/* Initialize the actual machine and its basic modules. */
machine_init();

View File

@@ -302,13 +302,13 @@ hasp_read_status(void *priv)
}
static void *
hasp_init(void *lpt, int type)
hasp_init(const device_t *info, int type)
{
hasp_t *dev = calloc(1, sizeof(hasp_t));
hasp_log("HASP: init(%d)\n", type);
dev->lpt = lpt;
dev->lpt = lpt_attach(info->local & 0xf, hasp_write_data, NULL, NULL, hasp_read_status, NULL, NULL, NULL, dev);
dev->type = &hasp_types[type];
dev->status = 0x80;
@@ -317,9 +317,9 @@ hasp_init(void *lpt, int type)
}
static void *
hasp_init_savquest(void *lpt)
hasp_init_savquest(const device_t *info)
{
return hasp_init(lpt, HASP_TYPE_SAVQUEST);
return hasp_init(info, HASP_TYPE_SAVQUEST);
}
static void
@@ -332,16 +332,16 @@ hasp_close(void *priv)
free(dev);
}
const lpt_device_t lpt_hasp_savquest_device = {
.name = "Protection Dongle for Savage Quest",
.internal_name = "dongle_savquest",
.init = hasp_init_savquest,
.close = hasp_close,
.write_data = hasp_write_data,
.write_ctrl = NULL,
.strobe = NULL,
.read_status = hasp_read_status,
.read_ctrl = NULL,
.epp_write_data = NULL,
.epp_request_read = NULL
const device_t lpt_hasp_savquest_device = {
.name = "Protection Dongle for Savage Quest",
.internal_name = "dongle_savquest",
.flags = DEVICE_LPT,
.local = 0,
.init = hasp_init_savquest,
.close = hasp_close,
.reset = NULL,
.available = NULL,
.speed_changed = NULL,
.force_redraw = NULL,
.config = NULL
};

View File

@@ -34,19 +34,22 @@ lpt_port_t lpt_ports[PARALLEL_MAX];
lpt_device_t lpt_devs[PARALLEL_MAX];
const lpt_device_t lpt_none_device = {
const device_t lpt_none_device = {
.name = "None",
.internal_name = "none",
.flags = DEVICE_LPT,
.local = 0,
.init = NULL,
.close = NULL,
.write_data = NULL,
.write_ctrl = NULL,
.read_status = NULL,
.read_ctrl = NULL
.reset = NULL,
.available = NULL,
.speed_changed = NULL,
.force_redraw = NULL,
.config = NULL
};
static const struct {
const lpt_device_t *device;
const device_t *device;
} lpt_devices[] = {
// clang-format off
{ &lpt_none_device },
@@ -83,50 +86,41 @@ lpt_log(const char *fmt, ...)
# define lpt_log(fmt, ...)
#endif
int
lpt_device_available(int id)
{
if (lpt_devices[id].device)
return device_available(lpt_devices[id].device);
return 1;
}
const device_t *
lpt_device_getdevice(const int id)
{
return (device_t *) lpt_devices[id].device->cfgdevice;
return lpt_devices[id].device;
}
int
lpt_device_has_config(const int id)
{
int c = 0;
const device_t *dev = (device_t *) lpt_devices[id].device->cfgdevice;
const device_config_t *config;
if (dev == NULL)
if (lpt_devices[id].device == NULL)
return 0;
if (dev->config == NULL)
return 0;
config = dev->config;
while (config->type != CONFIG_END) {
c++;
config++;
}
return (c > 0) ? 1 : 0;
return device_has_config(lpt_devices[id].device);
}
const char *
lpt_device_get_name(const int id)
{
if (lpt_devices[id].device == NULL)
return NULL;
return 0;
return lpt_devices[id].device->name;
}
const char *
lpt_device_get_internal_name(const int id)
{
if (lpt_devices[id].device == NULL)
return NULL;
return lpt_devices[id].device->internal_name;
return device_get_internal_name(lpt_devices[id].device);
}
int
@@ -147,29 +141,42 @@ void
lpt_devices_init(void)
{
for (uint8_t i = 0; i < PARALLEL_MAX; i++) {
lpt_t *dev = lpt_devs[i].lpt;
memset(&(lpt_devs[i]), 0x00, sizeof(lpt_device_t));
if (lpt_devices[lpt_ports[i].device].device != NULL) {
memcpy(&(lpt_devs[i]), (lpt_device_t *) lpt_devices[lpt_ports[i].device].device, sizeof(lpt_device_t));
if (lpt_devs[i].init)
lpt_devs[i].priv = lpt_devs[i].init(dev);
} else
memset(&(lpt_devs[i]), 0x00, sizeof(lpt_device_t));
lpt_devs[i].lpt = dev;
if ((lpt_devices[lpt_ports[i].device].device != NULL) &&
(lpt_devices[lpt_ports[i].device].device != &lpt_none_device))
device_add_params((device_t *) lpt_devices[lpt_ports[i].device].device, (void *) (uintptr_t) i);
}
}
void *
lpt_attach(int port,
void (*write_data)(uint8_t val, void *priv),
void (*write_ctrl)(uint8_t val, void *priv),
void (*strobe)(uint8_t old, uint8_t val,void *priv),
uint8_t (*read_status)(void *priv),
uint8_t (*read_ctrl)(void *priv),
void (*epp_write_data)(uint8_t is_addr, uint8_t val, void *priv),
void (*epp_request_read)(uint8_t is_addr, void *priv),
void *priv)
{
lpt_devs[port].write_data = write_data;
lpt_devs[port].write_ctrl = write_ctrl;
lpt_devs[port].strobe = strobe;
lpt_devs[port].read_status = read_status;
lpt_devs[port].read_ctrl = read_ctrl;
lpt_devs[port].epp_write_data = epp_write_data;
lpt_devs[port].epp_request_read = epp_request_read;
lpt_devs[port].priv = priv;
return lpt_ports[port].lpt;
}
void
lpt_devices_close(void)
{
for (uint8_t i = 0; i < PARALLEL_MAX; i++) {
if (lpt_devs[i].close)
lpt_devs[i].close(lpt_devs[i].priv);
for (uint8_t i = 0; i < PARALLEL_MAX; i++)
memset(&(lpt_devs[i]), 0x00, sizeof(lpt_device_t));
}
}
static uint8_t
@@ -954,10 +961,10 @@ lpt_init(const device_t *info)
if (lpt_ports[next_inst].enabled || (info->local & 0xFFF00000)) {
lpt_log("Adding parallel port %i...\n", next_inst);
dev->dt = &(lpt_devs[next_inst]);
dev->dt->lpt = dev;
dev->dt = &(lpt_devs[next_inst]);
lpt_ports[next_inst].lpt = dev;
dev->fifo = NULL;
dev->fifo = NULL;
memset(&dev->fifo_out_timer, 0x00, sizeof(pc_timer_t));
lpt_port_zero(dev);
@@ -1033,7 +1040,14 @@ lpt_standalone_init(void)
{
while (next_inst < (PARALLEL_MAX - 1))
device_add_inst(&lpt_port_device, next_inst + 1);
};
}
void
lpt_ports_reset(void)
{
for (int i = 0; i < PARALLEL_MAX; i++)
lpt_ports[i].lpt = NULL;
}
const device_t lpt_port_device = {
.name = "Parallel Port",

View File

@@ -18,11 +18,6 @@
#endif
typedef struct lpt_device_s {
const char *name;
const char *internal_name;
void *(*init)(void *lpt);
void (*close)(void *priv);
void (*write_data)(uint8_t val, void *priv);
void (*write_ctrl)(uint8_t val, void *priv);
void (*strobe)(uint8_t old, uint8_t val,void *priv);
@@ -31,13 +26,7 @@ typedef struct lpt_device_s {
void (*epp_write_data)(uint8_t is_addr, uint8_t val, void *priv);
void (*epp_request_read)(uint8_t is_addr, void *priv);
void *priv;
struct lpt_t *lpt;
//#ifdef EMU_DEVICE_H
// struct device_t *cfgdevice;
//#else
void *cfgdevice;
//#endif
void * priv;
} lpt_device_t;
#ifdef _TIMER_H_
@@ -86,6 +75,8 @@ typedef struct lpt_port_s {
uint8_t enabled;
int device;
lpt_t *lpt;
} lpt_port_t;
extern lpt_port_t lpt_ports[PARALLEL_MAX];
@@ -96,6 +87,22 @@ typedef enum {
LPT_STATE_WRITE_FIFO
} lpt_state_t;
extern const device_t lpt_dac_device;
extern const device_t lpt_dac_stereo_device;
extern const device_t dss_device;
extern const device_t lpt_hasp_savquest_device;
extern int lpt_device_available(int id);
#ifdef EMU_DEVICE_H
extern const device_t *lpt_device_getdevice(const int id);
#endif
extern int lpt_device_has_config(const int id);
extern const char *lpt_device_get_name(int id);
extern const char *lpt_device_get_internal_name(int id);
extern int lpt_device_get_from_internal_name(const char *str);
extern void lpt_write(uint16_t port, uint8_t val, void *priv);
extern void lpt_write_to_fifo(void *priv, uint8_t val);
@@ -109,24 +116,6 @@ extern uint8_t lpt_read_ecp_mode(lpt_t *dev);
extern void lpt_irq(void *priv, int raise);
extern int lpt_device_get_from_internal_name(const char *str);
extern const char *lpt_device_get_name(int id);
extern const char *lpt_device_get_internal_name(int id);
#ifdef EMU_DEVICE_H
extern const device_t *lpt_device_getdevice(const int id);
#endif
extern int lpt_device_has_config(const int id);
extern const lpt_device_t lpt_dac_device;
extern const lpt_device_t lpt_dac_stereo_device;
extern const lpt_device_t dss_device;
extern const lpt_device_t lpt_hasp_savquest_device;
extern void lpt_set_ext(lpt_t *dev, uint8_t ext);
extern void lpt_set_ecp(lpt_t *dev, uint8_t ecp);
extern void lpt_set_epp(lpt_t *dev, uint8_t epp);
@@ -143,12 +132,22 @@ extern void lpt_port_remove(lpt_t *dev);
extern void lpt1_remove_ams(lpt_t *dev);
extern void lpt_devices_init(void);
extern void * lpt_attach(int port,
void (*write_data)(uint8_t val, void *priv),
void (*write_ctrl)(uint8_t val, void *priv),
void (*strobe)(uint8_t old, uint8_t val,void *priv),
uint8_t (*read_status)(void *priv),
uint8_t (*read_ctrl)(void *priv),
void (*epp_write_data)(uint8_t is_addr, uint8_t val, void *priv),
void (*epp_request_read)(uint8_t is_addr, void *priv),
void *priv);
extern void lpt_devices_close(void);
extern void lpt_set_next_inst(int ni);
extern void lpt_set_3bc_used(int is_3bc_used);
extern void lpt_standalone_init(void);
extern void lpt_ports_reset(void);
extern const device_t lpt_port_device;

View File

@@ -244,10 +244,8 @@ extern const device_t pcnet_am79c973_onboard_device;
extern const device_t modem_device;
/* PLIP */
#ifdef EMU_LPT_H
extern const lpt_device_t lpt_plip_device;
#endif
extern const device_t plip_device;
extern const device_t lpt_plip_device;
extern const device_t plip_device;
/* Realtek RTL8139C+ */
extern const device_t rtl8139c_plus_device;

View File

@@ -1,15 +1,11 @@
#ifndef EMU_PRT_DEVS_H
#define EMU_PRT_DEVS_H
extern const lpt_device_t lpt_prt_text_device;
extern const device_t prt_text_device;
extern const lpt_device_t lpt_prt_escp_device;
extern const device_t prt_escp_device;
extern const lpt_device_t lpt_prt_ps_device;
extern const device_t prt_ps_device;
extern const device_t lpt_prt_text_device;
extern const device_t lpt_prt_escp_device;
extern const device_t lpt_prt_ps_device;
#ifdef USE_PCL
extern const lpt_device_t lpt_prt_pcl_device;
extern const device_t prt_pcl_device;
extern const device_t lpt_prt_pcl_device;
#endif
#endif /*EMU_PRT_DEVS_H*/

View File

@@ -441,13 +441,14 @@ plip_rx(void *priv, uint8_t *buf, int io_len)
}
static void *
plip_lpt_init(void *lpt)
plip_lpt_init(const device_t *info)
{
plip_t *dev = (plip_t *) calloc(1, sizeof(plip_t));
plip_log(1, "PLIP: lpt_init()\n");
dev->lpt = lpt;
dev->lpt = lpt_attach(info->local & 0xf, plip_write_data, plip_write_ctrl, NULL, plip_read_status, NULL, NULL, NULL, dev);
memset(dev->mac, 0xfc, 6); /* static MAC used by Linux; just a placeholder */
dev->status = 0x80;
@@ -485,24 +486,22 @@ plip_close(void *priv)
free(priv);
}
const lpt_device_t lpt_plip_device = {
.name = "Parallel Line Internet Protocol",
.internal_name = "plip",
.init = plip_lpt_init,
.close = plip_close,
.write_data = plip_write_data,
.write_ctrl = plip_write_ctrl,
.strobe = NULL,
.read_status = plip_read_status,
.read_ctrl = NULL,
.epp_write_data = NULL,
.epp_request_read = NULL,
.priv = NULL,
.lpt = NULL
const device_t lpt_plip_device = {
.name = "Parallel Line Internet Protocol (LPT)",
.internal_name = "plip",
.flags = DEVICE_LPT,
.local = 0,
.init = plip_lpt_init,
.close = plip_close,
.reset = NULL,
.available = NULL,
.speed_changed = NULL,
.force_redraw = NULL,
.config = NULL
};
const device_t plip_device = {
.name = "Parallel Line Internet Protocol",
.name = "Parallel Line Internet Protocol (Network)",
.internal_name = "plip",
.flags = DEVICE_LPT,
.local = 0,

View File

@@ -1979,7 +1979,7 @@ read_status(void *priv)
}
static void *
escp_init(void *lpt)
escp_init(const device_t *info)
{
escp_t *dev = NULL;
@@ -1995,7 +1995,8 @@ escp_init(void *lpt)
/* Initialize a device instance. */
dev = (escp_t *) calloc(1, sizeof(escp_t));
dev->ctrl = 0x04;
dev->lpt = lpt;
dev->lpt = lpt_attach(info->local & 0xf, write_data, write_ctrl, strobe, read_status, read_ctrl, NULL, NULL, dev);
rom_get_full_path(dev->fontpath, "roms/printer/fonts/");
@@ -2109,13 +2110,13 @@ static const device_config_t lpt_prt_escp_config[] = {
#endif
// clang-format on
const device_t prt_escp_device = {
const device_t lpt_prt_escp_device = {
.name = "Generic ESC/P 2 Dot-Matrix Printer",
.internal_name = "dot_matrix",
.flags = DEVICE_LPT,
.local = 0,
.init = NULL,
.close = NULL,
.init = escp_init,
.close = escp_close,
.reset = NULL,
.available = NULL,
.speed_changed = NULL,
@@ -2126,20 +2127,3 @@ const device_t prt_escp_device = {
.config = NULL
#endif
};
const lpt_device_t lpt_prt_escp_device = {
.name = "Generic ESC/P 2 Dot-Matrix Printer",
.internal_name = "dot_matrix",
.init = escp_init,
.close = escp_close,
.write_data = write_data,
.write_ctrl = write_ctrl,
.strobe = strobe,
.read_status = read_status,
.read_ctrl = read_ctrl,
.epp_write_data = NULL,
.epp_request_read = NULL,
.priv = NULL,
.lpt = NULL,
.cfgdevice = (device_t *) &prt_escp_device
};

View File

@@ -465,15 +465,16 @@ ps_read_status(void *priv)
}
static void *
ps_init(void *lpt)
ps_init(const device_t *info)
{
ps_t *dev = (ps_t *) calloc(1, sizeof(ps_t));
gsapi_revision_t rev;
dev->ctrl = 0x04;
dev->lpt = lpt;
dev->pcl = false;
dev->lpt = lpt_attach(info->local & 0xf, ps_write_data, ps_write_ctrl, ps_strobe, ps_read_status, NULL, NULL, NULL, dev);
/* Try loading the DLL. */
ghostscript_handle = dynld_module(PATH_GHOSTSCRIPT_DLL, ghostscript_imports);
#ifdef PATH_GHOSTSCRIPT_DLL_ALT1
@@ -513,15 +514,16 @@ ps_init(void *lpt)
#ifdef USE_PCL
static void *
pcl_init(void *lpt)
pcl_init(const device_t *info)
{
ps_t *dev = (ps_t *) calloc(1, sizeof(ps_t));
gsapi_revision_t rev;
dev->ctrl = 0x04;
dev->lpt = lpt;
dev->pcl = true;
dev->lpt = lpt_attach(info->local & 0xf, ps_write_data, ps_write_ctrl, ps_strobe, ps_read_status, NULL, NULL, NULL, dev);
/* Try loading the DLL. */
ghostscript_handle = dynld_module(PATH_GHOSTPCL_DLL, ghostscript_imports);
#ifdef PATH_GHOSTPCL_DLL_ALT1
@@ -579,36 +581,32 @@ ps_close(void *priv)
free(dev);
}
const lpt_device_t lpt_prt_ps_device = {
.name = "Generic PostScript Printer",
.internal_name = "postscript",
.init = ps_init,
.close = ps_close,
.write_data = ps_write_data,
.write_ctrl = ps_write_ctrl,
.strobe = ps_strobe,
.read_status = ps_read_status,
.read_ctrl = NULL,
.epp_write_data = NULL,
.epp_request_read = NULL,
.priv = NULL,
.lpt = NULL
const device_t lpt_prt_ps_device = {
.name = "Generic PostScript Printer",
.internal_name = "postscript",
.flags = DEVICE_LPT,
.local = 0,
.init = ps_init,
.close = ps_close,
.reset = NULL,
.available = NULL,
.speed_changed = NULL,
.force_redraw = NULL,
.config = NULL
};
#ifdef USE_PCL
const lpt_device_t lpt_prt_pcl_device = {
.name = "Generic PCL5e Printer",
.internal_name = "pcl",
.init = pcl_init,
.close = ps_close,
.write_data = ps_write_data,
.write_ctrl = ps_write_ctrl,
.strobe = ps_strobe,
.read_status = ps_read_status,
.read_ctrl = NULL,
.epp_write_data = NULL,
.epp_request_read = NULL,
.priv = NULL,
.lpt = NULL
const device_t lpt_prt_pcl_device = {
.name = "Generic PCL5e Printer",
.internal_name = "pcl",
.flags = DEVICE_LPT,
.local = 0,
.init = pcl_init,
.close = ps_close,
.reset = NULL,
.available = NULL,
.speed_changed = NULL,
.force_redraw = NULL,
.config = NULL
};
#endif

View File

@@ -455,13 +455,13 @@ read_status(void *priv)
}
static void *
prnt_init(void *lpt)
prnt_init(const device_t *info)
{
/* Initialize a device instance. */
prnt_t *dev = (prnt_t *) calloc(1, sizeof(prnt_t));
dev->ctrl = 0x04;
dev->lpt = lpt;
dev->lpt = lpt_attach(info->local & 0xf, write_data, write_ctrl, strobe, read_status, NULL, NULL, NULL, dev);
/* Initialize parameters. */
reset_printer(dev);
@@ -523,13 +523,13 @@ static const device_config_t lpt_prt_text_config[] = {
#endif
// clang-format on
const device_t prt_text_device = {
const device_t lpt_prt_text_device = {
.name = "Generic Text Printer",
.internal_name = "text_prt",
.flags = DEVICE_LPT,
.local = 0,
.init = NULL,
.close = NULL,
.init = prnt_init,
.close = prnt_close,
.reset = NULL,
.available = NULL,
.speed_changed = NULL,
@@ -540,20 +540,3 @@ const device_t prt_text_device = {
.config = NULL
#endif
};
const lpt_device_t lpt_prt_text_device = {
.name = "Generic Text Printer",
.internal_name = "text_prt",
.init = prnt_init,
.close = prnt_close,
.write_data = write_data,
.write_ctrl = write_ctrl,
.strobe = strobe,
.read_status = read_status,
.read_ctrl = NULL,
.epp_write_data = NULL,
.epp_request_read = NULL,
.priv = NULL,
.lpt = NULL,
.cfgdevice = (device_t *) &prt_text_device
};

View File

@@ -89,11 +89,11 @@ dac_get_buffer(int32_t *buffer, int len, void *priv)
}
static void *
dac_init(void *lpt)
dac_init(UNUSED(const device_t *info))
{
lpt_dac_t *lpt_dac = calloc(1, sizeof(lpt_dac_t));
lpt_dac->lpt = lpt;
lpt_dac->lpt = lpt_attach(info->local & 0xf, dac_write_data, dac_write_ctrl, dac_strobe, dac_read_status, NULL, NULL, NULL, lpt_dac);
sound_add_handler(dac_get_buffer, lpt_dac);
@@ -101,9 +101,9 @@ dac_init(void *lpt)
}
static void *
dac_stereo_init(void *lpt)
dac_stereo_init(const device_t *info)
{
lpt_dac_t *lpt_dac = dac_init(lpt);
lpt_dac_t *lpt_dac = dac_init(info);
lpt_dac->is_stereo = 1;
@@ -117,34 +117,30 @@ dac_close(void *priv)
free(lpt_dac);
}
const lpt_device_t lpt_dac_device = {
.name = "LPT DAC / Covox Speech Thing",
.internal_name = "lpt_dac",
.init = dac_init,
.close = dac_close,
.write_data = dac_write_data,
.write_ctrl = dac_write_ctrl,
.strobe = dac_strobe,
.read_status = dac_read_status,
.read_ctrl = NULL,
.epp_write_data = NULL,
.epp_request_read = NULL,
.priv = NULL,
.lpt = NULL
const device_t lpt_dac_device = {
.name = "LPT DAC / Covox Speech Thing",
.internal_name = "lpt_dac",
.flags = DEVICE_LPT,
.local = 0,
.init = dac_init,
.close = dac_close,
.reset = NULL,
.available = NULL,
.speed_changed = NULL,
.force_redraw = NULL,
.config = NULL
};
const lpt_device_t lpt_dac_stereo_device = {
.name = "Stereo LPT DAC",
.internal_name = "lpt_dac_stereo",
.init = dac_stereo_init,
.close = dac_close,
.write_data = dac_write_data,
.write_ctrl = dac_write_ctrl,
.strobe = dac_strobe,
.read_status = dac_read_status,
.read_ctrl = NULL,
.epp_write_data = NULL,
.epp_request_read = NULL,
.priv = NULL,
.lpt = NULL
const device_t lpt_dac_stereo_device = {
.name = "Stereo LPT DAC",
.internal_name = "lpt_dac_stereo",
.flags = DEVICE_LPT,
.local = 0,
.init = dac_stereo_init,
.close = dac_close,
.reset = NULL,
.available = NULL,
.speed_changed = NULL,
.force_redraw = NULL,
.config = NULL
};

View File

@@ -114,11 +114,11 @@ dss_callback(void *priv)
}
static void *
dss_init(void *lpt)
dss_init(UNUSED(const device_t *info))
{
dss_t *dss = calloc(1, sizeof(dss_t));
dss->lpt = lpt;
dss->lpt = lpt_attach(info->local & 0xf, dss_write_data, dss_write_ctrl, NULL, dss_read_status, NULL, NULL, NULL, dss);
sound_add_handler(dss_get_buffer, dss);
timer_add(&dss->timer, dss_callback, dss, 1);
@@ -133,18 +133,16 @@ dss_close(void *priv)
free(dss);
}
const lpt_device_t dss_device = {
.name = "Disney Sound Source",
.internal_name = "dss",
.init = dss_init,
.close = dss_close,
.write_data = dss_write_data,
.strobe = NULL,
.write_ctrl = dss_write_ctrl,
.read_status = dss_read_status,
.read_ctrl = NULL,
.epp_write_data = NULL,
.epp_request_read = NULL,
.priv = NULL,
.lpt = NULL
const device_t dss_device = {
.name = "Disney Sound Source",
.internal_name = "dss",
.flags = DEVICE_LPT,
.local = 0,
.init = dss_init,
.close = dss_close,
.reset = NULL,
.available = NULL,
.speed_changed = NULL,
.force_redraw = NULL,
.config = NULL
};