Redid device instantiation, now the ISA memory boards can be configured without having to restart the emulator first.
This commit is contained in:
190
src/device.c
190
src/device.c
@@ -9,7 +9,7 @@
|
||||
* Implementation of the generic device interface to handle
|
||||
* all devices attached to the emulator.
|
||||
*
|
||||
* Version: @(#)device.c 1.0.20 2018/10/17
|
||||
* Version: @(#)device.c 1.0.21 2018/10/23
|
||||
*
|
||||
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
@@ -54,17 +54,9 @@
|
||||
#define DEVICE_MAX 256 /* max # of devices */
|
||||
|
||||
|
||||
typedef struct clonedev {
|
||||
const device_t *master;
|
||||
int count;
|
||||
struct clonedev *next;
|
||||
} clonedev_t;
|
||||
|
||||
|
||||
static device_t *devices[DEVICE_MAX];
|
||||
static void *device_priv[DEVICE_MAX];
|
||||
static device_t *device_current;
|
||||
static clonedev_t *clones = NULL;
|
||||
static device_context_t device_current;
|
||||
|
||||
|
||||
#ifdef ENABLE_DEVICE_LOG
|
||||
@@ -86,75 +78,33 @@ device_log(const char *fmt, ...)
|
||||
#define device_log(fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
/* Initialize the module for use. */
|
||||
void
|
||||
device_init(void)
|
||||
{
|
||||
clonedev_t *ptr;
|
||||
|
||||
memset(devices, 0x00, sizeof(devices));
|
||||
|
||||
ptr = NULL;
|
||||
while (clones != NULL) {
|
||||
ptr = clones->next;
|
||||
free(clones);
|
||||
clones = ptr;
|
||||
}
|
||||
|
||||
clones = NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Clone a master device for multi-instance devices. */
|
||||
const device_t *
|
||||
device_clone(const device_t *master)
|
||||
void
|
||||
device_set_context(device_context_t *c, const device_t *d, int inst)
|
||||
{
|
||||
char temp[1024], *sp;
|
||||
clonedev_t *cl, *ptr;
|
||||
device_t *dev;
|
||||
|
||||
/* Look up the master. */
|
||||
for (ptr = clones; ptr != NULL; ptr = ptr->next)
|
||||
if (ptr->master == master) break;
|
||||
|
||||
/* If not found, add this master to the list. */
|
||||
if (ptr == NULL) {
|
||||
ptr = (clonedev_t *)malloc(sizeof(clonedev_t));
|
||||
memset(ptr, 0x00, sizeof(clonedev_t));
|
||||
if (clones != NULL) {
|
||||
for (cl = clones; cl->next != NULL; cl = cl->next)
|
||||
;
|
||||
cl->next = ptr;
|
||||
} else
|
||||
clones = ptr;
|
||||
ptr->master = master;
|
||||
}
|
||||
|
||||
/* Create a new device. */
|
||||
dev = (device_t *)malloc(sizeof(device_t));
|
||||
|
||||
/* Copy the master info. */
|
||||
memcpy(dev, ptr->master, sizeof(device_t));
|
||||
|
||||
/* Set up a clone. */
|
||||
if (++ptr->count > 1)
|
||||
sprintf(temp, "%s #%i", ptr->master->name, ptr->count);
|
||||
else
|
||||
strcpy(temp, ptr->master->name);
|
||||
sp = (char *)malloc(strlen(temp) + 1);
|
||||
strcpy(sp, temp);
|
||||
dev->name = (const char *)sp;
|
||||
|
||||
return((const device_t *)dev);
|
||||
memset(c, 0, sizeof(device_context_t));
|
||||
c->dev = d;
|
||||
if (inst)
|
||||
sprintf(c->name, "%s #%i", d->name, inst);
|
||||
else
|
||||
sprintf(c->name, "%s", d->name);
|
||||
}
|
||||
|
||||
|
||||
void *
|
||||
device_add(const device_t *d)
|
||||
device_add_common(const device_t *d, void *p, int inst)
|
||||
{
|
||||
void *priv = NULL;
|
||||
int c;
|
||||
device_t *old;
|
||||
device_context_t old;
|
||||
|
||||
for (c = 0; c < 256; c++) {
|
||||
if (devices[c] == (device_t *)d) {
|
||||
@@ -166,50 +116,62 @@ device_add(const device_t *d)
|
||||
if (c >= DEVICE_MAX)
|
||||
fatal("DEVICE: too many devices\n");
|
||||
|
||||
old = device_current;
|
||||
device_current = (device_t *)d;
|
||||
if (p == NULL) {
|
||||
memcpy(&old, &device_current, sizeof(device_context_t));
|
||||
device_set_context(&device_current, d, inst);
|
||||
|
||||
if (d->init != NULL) {
|
||||
priv = d->init(d);
|
||||
if (priv == NULL) {
|
||||
if (d->name)
|
||||
device_log("DEVICE: device '%s' init failed\n", d->name);
|
||||
else
|
||||
device_log("DEVICE: device init failed\n");
|
||||
|
||||
device_priv[c] = NULL;
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(&device_current, &old, sizeof(device_context_t));
|
||||
device_priv[c] = priv;
|
||||
} else
|
||||
device_priv[c] = p;
|
||||
|
||||
devices[c] = (device_t *)d;
|
||||
|
||||
if (d->init != NULL) {
|
||||
priv = d->init(d);
|
||||
if (priv == NULL) {
|
||||
if (d->name)
|
||||
device_log("DEVICE: device '%s' init failed\n", d->name);
|
||||
else
|
||||
device_log("DEVICE: device init failed\n");
|
||||
|
||||
device_priv[c] = NULL;
|
||||
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
device_priv[c] = priv;
|
||||
device_current = old;
|
||||
|
||||
return(priv);
|
||||
}
|
||||
|
||||
|
||||
void *
|
||||
device_add(const device_t *d)
|
||||
{
|
||||
return device_add_common(d, NULL, 0);
|
||||
}
|
||||
|
||||
|
||||
/* For devices that do not have an init function (internal video etc.) */
|
||||
void
|
||||
device_add_ex(const device_t *d, void *priv)
|
||||
{
|
||||
int c;
|
||||
device_add_common(d, priv, 0);
|
||||
}
|
||||
|
||||
for (c = 0; c < 256; c++) {
|
||||
if (devices[c] == (device_t *)d) {
|
||||
fatal("device_add: device already exists!\n");
|
||||
break;
|
||||
}
|
||||
if (devices[c] == NULL) break;
|
||||
}
|
||||
if (c >= DEVICE_MAX)
|
||||
fatal("device_add: too many devices\n");
|
||||
|
||||
devices[c] = (device_t *)d;
|
||||
device_priv[c] = priv;
|
||||
void *
|
||||
device_add_inst(const device_t *d, int inst)
|
||||
{
|
||||
return device_add_common(d, NULL, inst);
|
||||
}
|
||||
|
||||
|
||||
/* For devices that do not have an init function (internal video etc.) */
|
||||
void
|
||||
device_add_inst_ex(const device_t *d, void *priv, int inst)
|
||||
{
|
||||
device_add_common(d, priv, inst);
|
||||
}
|
||||
|
||||
|
||||
@@ -321,11 +283,11 @@ device_force_redraw(void)
|
||||
const char *
|
||||
device_get_config_string(const char *s)
|
||||
{
|
||||
const device_config_t *c = device_current->config;
|
||||
const device_config_t *c = device_current.dev->config;
|
||||
|
||||
while (c && c->type != -1) {
|
||||
if (! strcmp(s, c->name))
|
||||
return(config_get_string((char *) device_current->name, (char *) s, (char *) c->default_string));
|
||||
return(config_get_string((char *) device_current.name, (char *) s, (char *) c->default_string));
|
||||
|
||||
c++;
|
||||
}
|
||||
@@ -337,11 +299,11 @@ device_get_config_string(const char *s)
|
||||
int
|
||||
device_get_config_int(const char *s)
|
||||
{
|
||||
const device_config_t *c = device_current->config;
|
||||
const device_config_t *c = device_current.dev->config;
|
||||
|
||||
while (c && c->type != -1) {
|
||||
if (! strcmp(s, c->name))
|
||||
return(config_get_int((char *) device_current->name, (char *) s, c->default_int));
|
||||
return(config_get_int((char *) device_current.name, (char *) s, c->default_int));
|
||||
|
||||
c++;
|
||||
}
|
||||
@@ -353,11 +315,11 @@ device_get_config_int(const char *s)
|
||||
int
|
||||
device_get_config_int_ex(const char *s, int def)
|
||||
{
|
||||
const device_config_t *c = device_current->config;
|
||||
const device_config_t *c = device_current.dev->config;
|
||||
|
||||
while (c && c->type != -1) {
|
||||
if (! strcmp(s, c->name))
|
||||
return(config_get_int((char *) device_current->name, (char *) s, def));
|
||||
return(config_get_int((char *) device_current.name, (char *) s, def));
|
||||
|
||||
c++;
|
||||
}
|
||||
@@ -369,11 +331,11 @@ device_get_config_int_ex(const char *s, int def)
|
||||
int
|
||||
device_get_config_hex16(const char *s)
|
||||
{
|
||||
const device_config_t *c = device_current->config;
|
||||
const device_config_t *c = device_current.dev->config;
|
||||
|
||||
while (c && c->type != -1) {
|
||||
if (! strcmp(s, c->name))
|
||||
return(config_get_hex16((char *) device_current->name, (char *) s, c->default_int));
|
||||
return(config_get_hex16((char *) device_current.name, (char *) s, c->default_int));
|
||||
|
||||
c++;
|
||||
}
|
||||
@@ -385,11 +347,11 @@ device_get_config_hex16(const char *s)
|
||||
int
|
||||
device_get_config_hex20(const char *s)
|
||||
{
|
||||
const device_config_t *c = device_current->config;
|
||||
const device_config_t *c = device_current.dev->config;
|
||||
|
||||
while (c && c->type != -1) {
|
||||
if (! strcmp(s, c->name))
|
||||
return(config_get_hex20((char *) device_current->name, (char *) s, c->default_int));
|
||||
return(config_get_hex20((char *) device_current.name, (char *) s, c->default_int));
|
||||
|
||||
c++;
|
||||
}
|
||||
@@ -401,11 +363,11 @@ device_get_config_hex20(const char *s)
|
||||
int
|
||||
device_get_config_mac(const char *s, int def)
|
||||
{
|
||||
const device_config_t *c = device_current->config;
|
||||
const device_config_t *c = device_current.dev->config;
|
||||
|
||||
while (c && c->type != -1) {
|
||||
if (! strcmp(s, c->name))
|
||||
return(config_get_mac((char *) device_current->name, (char *) s, def));
|
||||
return(config_get_mac((char *) device_current.name, (char *) s, def));
|
||||
|
||||
c++;
|
||||
}
|
||||
@@ -417,11 +379,11 @@ device_get_config_mac(const char *s, int def)
|
||||
void
|
||||
device_set_config_int(const char *s, int val)
|
||||
{
|
||||
const device_config_t *c = device_current->config;
|
||||
const device_config_t *c = device_current.dev->config;
|
||||
|
||||
while (c && c->type != -1) {
|
||||
if (! strcmp(s, c->name)) {
|
||||
config_set_int((char *) device_current->name, (char *) s, val);
|
||||
config_set_int((char *) device_current.name, (char *) s, val);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -433,11 +395,11 @@ device_set_config_int(const char *s, int val)
|
||||
void
|
||||
device_set_config_hex16(const char *s, int val)
|
||||
{
|
||||
const device_config_t *c = device_current->config;
|
||||
const device_config_t *c = device_current.dev->config;
|
||||
|
||||
while (c && c->type != -1) {
|
||||
if (! strcmp(s, c->name)) {
|
||||
config_set_hex16((char *) device_current->name, (char *) s, val);
|
||||
config_set_hex16((char *) device_current.name, (char *) s, val);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -449,11 +411,11 @@ device_set_config_hex16(const char *s, int val)
|
||||
void
|
||||
device_set_config_hex20(const char *s, int val)
|
||||
{
|
||||
const device_config_t *c = device_current->config;
|
||||
const device_config_t *c = device_current.dev->config;
|
||||
|
||||
while (c && c->type != -1) {
|
||||
if (! strcmp(s, c->name)) {
|
||||
config_set_hex20((char *) device_current->name, (char *) s, val);
|
||||
config_set_hex20((char *) device_current.name, (char *) s, val);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -465,11 +427,11 @@ device_set_config_hex20(const char *s, int val)
|
||||
void
|
||||
device_set_config_mac(const char *s, int val)
|
||||
{
|
||||
const device_config_t *c = device_current->config;
|
||||
const device_config_t *c = device_current.dev->config;
|
||||
|
||||
while (c && c->type != -1) {
|
||||
if (! strcmp(s, c->name)) {
|
||||
config_set_mac((char *) device_current->name, (char *) s, val);
|
||||
config_set_mac((char *) device_current.name, (char *) s, val);
|
||||
break;
|
||||
}
|
||||
|
||||
|
11
src/device.h
11
src/device.h
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Definitions for the device handler.
|
||||
*
|
||||
* Version: @(#)device.h 1.0.9 2018/09/06
|
||||
* Version: @(#)device.h 1.0.10 2018/10/23
|
||||
*
|
||||
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
@@ -108,15 +108,22 @@ typedef struct _device_ {
|
||||
const device_config_t *config;
|
||||
} device_t;
|
||||
|
||||
typedef struct {
|
||||
const device_t *dev;
|
||||
char name[2048];
|
||||
} device_context_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void device_init(void);
|
||||
extern const device_t * device_clone(const device_t *master);
|
||||
extern void device_set_context(device_context_t *c, const device_t *d, int inst);
|
||||
extern void *device_add(const device_t *);
|
||||
extern void device_add_ex(const device_t *d, void *priv);
|
||||
extern void *device_add_inst(const device_t *, int inst);
|
||||
extern void device_add_inst_ex(const device_t *d, void *priv, int inst);
|
||||
extern void device_close_all(void);
|
||||
extern void device_reset_all(void);
|
||||
extern void device_reset_all_pci(void);
|
||||
|
32
src/isamem.c
32
src/isamem.c
@@ -32,7 +32,7 @@
|
||||
* TODO: The EV159 is supposed to support 16b EMS transfers, but the
|
||||
* EMM.sys driver for it doesn't seem to want to do that..
|
||||
*
|
||||
* Version: @(#)isamem.c 1.0.7 2018/10/17
|
||||
* Version: @(#)isamem.c 1.0.8 2018/10/23
|
||||
*
|
||||
* Author: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
*
|
||||
@@ -106,7 +106,7 @@ typedef struct {
|
||||
typedef struct {
|
||||
const char *name;
|
||||
uint8_t board : 6, /* board type */
|
||||
instance : 2; /* device instance */
|
||||
reserved : 2;
|
||||
|
||||
uint8_t flags;
|
||||
#define FLAG_CONFIG 0x01 /* card is configured */
|
||||
@@ -151,15 +151,6 @@ isamem_log(const char *fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
/* Local variables. */
|
||||
static const device_t *instance[ISAMEM_MAX] = {
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
/* Read one byte from onboard RAM. */
|
||||
static uint8_t
|
||||
ram_readb(uint32_t addr, void *priv)
|
||||
@@ -412,13 +403,10 @@ isamem_init(const device_t *info)
|
||||
int i;
|
||||
|
||||
/* Find our device and create an instance. */
|
||||
for (i = 0; i < ISAMEM_MAX; i++)
|
||||
if (instance[i] == info) break;
|
||||
dev = (memdev_t *)malloc(sizeof(memdev_t));
|
||||
memset(dev, 0x00, sizeof(memdev_t));
|
||||
dev->name = info->name;
|
||||
dev->board = info->local;
|
||||
dev->instance = i;
|
||||
|
||||
/* Do per-board initialization. */
|
||||
tot = 0;
|
||||
@@ -650,7 +638,7 @@ dev->frame_addr = 0xE0000;
|
||||
}
|
||||
|
||||
/* Let them know our device instance. */
|
||||
return((void *)dev);
|
||||
return((void *) dev);
|
||||
}
|
||||
|
||||
|
||||
@@ -672,8 +660,6 @@ isamem_close(void *priv)
|
||||
if (dev->ram != NULL)
|
||||
free(dev->ram);
|
||||
|
||||
instance[dev->instance] = NULL;
|
||||
|
||||
free(dev);
|
||||
}
|
||||
|
||||
@@ -1045,21 +1031,14 @@ static const struct {
|
||||
void
|
||||
isamem_reset(void)
|
||||
{
|
||||
const device_t *dev;
|
||||
int k, i;
|
||||
|
||||
for (i = 0; i < ISAMEM_MAX; i++) {
|
||||
k = isamem_type[i];
|
||||
if (k == 0) continue;
|
||||
|
||||
/* Clone the device. */
|
||||
dev = device_clone(boards[k].dev);
|
||||
|
||||
/* Store the device instance. */
|
||||
instance[i] = dev;
|
||||
|
||||
/* Add the instance to the system. */
|
||||
device_add(dev);
|
||||
device_add_inst(boards[k].dev, i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1100,5 +1079,6 @@ isamem_get_from_internal_name(const char *s)
|
||||
const device_t *
|
||||
isamem_get_device(int board)
|
||||
{
|
||||
return(instance[board]);
|
||||
/* Add the instance to the system. */
|
||||
return boards[board].dev;
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Platform support defintions for Win32.
|
||||
*
|
||||
* Version: @(#)win.h 1.0.23 2018/10/23
|
||||
* Version: @(#)win.h 1.0.24 2018/10/23
|
||||
*
|
||||
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
|
||||
* Miran Grca, <mgrca8@gmail.com>
|
||||
@@ -111,6 +111,7 @@ extern intptr_t fdd_type_to_icon(int type);
|
||||
|
||||
#ifdef EMU_DEVICE_H
|
||||
extern uint8_t deviceconfig_open(HWND hwnd, const device_t *device);
|
||||
extern uint8_t deviceconfig_inst_open(HWND hwnd, const device_t *device, int inst);
|
||||
#endif
|
||||
extern uint8_t joystickconfig_open(HWND hwnd, int joy_nr, int type);
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Windows 86Box Settings dialog handler.
|
||||
*
|
||||
* Version: @(#)win_settings.c 1.0.67 2018/10/23
|
||||
* Version: @(#)win_settings.c 1.0.68 2018/10/23
|
||||
*
|
||||
* Authors: Miran Grca, <mgrca8@gmail.com>
|
||||
* David Hrdlička, <hrdlickadavid@outlook.com>
|
||||
@@ -1669,11 +1669,8 @@ win_settings_peripherals_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lPa
|
||||
case IDC_CONFIGURE_ISAMEM_3:
|
||||
case IDC_CONFIGURE_ISAMEM_4:
|
||||
c = LOWORD(wParam) - IDC_CONFIGURE_ISAMEM_1;
|
||||
dev = isamem_get_device(c);
|
||||
if (dev != NULL)
|
||||
temp_deviceconfig |= deviceconfig_open(hdlg, (void *)dev);
|
||||
else
|
||||
ui_msgbox(MBX_INFO, (wchar_t *)IDS_2119);
|
||||
dev = isamem_get_device(temp_isamem[c]);
|
||||
temp_deviceconfig |= deviceconfig_inst_open(hdlg, (void *)dev, c + 1);
|
||||
break;
|
||||
|
||||
case IDC_CHECK_IDE_TER:
|
||||
|
Reference in New Issue
Block a user