Redid device instantiation, now the ISA memory boards can be configured without having to restart the emulator first.

This commit is contained in:
OBattler
2018-10-23 21:14:41 +02:00
parent 09dbd59985
commit 4343f5a8a3
6 changed files with 649 additions and 738 deletions

View File

@@ -9,7 +9,7 @@
* Implementation of the generic device interface to handle * Implementation of the generic device interface to handle
* all devices attached to the emulator. * 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> * Authors: Fred N. van Kempen, <decwiz@yahoo.com>
* Miran Grca, <mgrca8@gmail.com> * Miran Grca, <mgrca8@gmail.com>
@@ -54,17 +54,9 @@
#define DEVICE_MAX 256 /* max # of devices */ #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 device_t *devices[DEVICE_MAX];
static void *device_priv[DEVICE_MAX]; static void *device_priv[DEVICE_MAX];
static device_t *device_current; static device_context_t device_current;
static clonedev_t *clones = NULL;
#ifdef ENABLE_DEVICE_LOG #ifdef ENABLE_DEVICE_LOG
@@ -86,75 +78,33 @@ device_log(const char *fmt, ...)
#define device_log(fmt, ...) #define device_log(fmt, ...)
#endif #endif
/* Initialize the module for use. */ /* Initialize the module for use. */
void void
device_init(void) device_init(void)
{ {
clonedev_t *ptr;
memset(devices, 0x00, sizeof(devices)); 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. */ void
const device_t * device_set_context(device_context_t *c, const device_t *d, int inst)
device_clone(const device_t *master)
{ {
char temp[1024], *sp; memset(c, 0, sizeof(device_context_t));
clonedev_t *cl, *ptr; c->dev = d;
device_t *dev; if (inst)
sprintf(c->name, "%s #%i", d->name, inst);
/* Look up the master. */ else
for (ptr = clones; ptr != NULL; ptr = ptr->next) sprintf(c->name, "%s", d->name);
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);
} }
void * void *
device_add(const device_t *d) device_add_common(const device_t *d, void *p, int inst)
{ {
void *priv = NULL; void *priv = NULL;
int c; int c;
device_t *old; device_context_t old;
for (c = 0; c < 256; c++) { for (c = 0; c < 256; c++) {
if (devices[c] == (device_t *)d) { if (devices[c] == (device_t *)d) {
@@ -166,50 +116,62 @@ device_add(const device_t *d)
if (c >= DEVICE_MAX) if (c >= DEVICE_MAX)
fatal("DEVICE: too many devices\n"); fatal("DEVICE: too many devices\n");
old = device_current; if (p == NULL) {
device_current = (device_t *)d; 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; 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); 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.) */ /* For devices that do not have an init function (internal video etc.) */
void void
device_add_ex(const device_t *d, void *priv) 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; void *
device_priv[c] = priv; 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 * const char *
device_get_config_string(const char *s) 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) { while (c && c->type != -1) {
if (! strcmp(s, c->name)) 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++; c++;
} }
@@ -337,11 +299,11 @@ device_get_config_string(const char *s)
int int
device_get_config_int(const char *s) 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) { while (c && c->type != -1) {
if (! strcmp(s, c->name)) 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++; c++;
} }
@@ -353,11 +315,11 @@ device_get_config_int(const char *s)
int int
device_get_config_int_ex(const char *s, int def) 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) { while (c && c->type != -1) {
if (! strcmp(s, c->name)) 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++; c++;
} }
@@ -369,11 +331,11 @@ device_get_config_int_ex(const char *s, int def)
int int
device_get_config_hex16(const char *s) 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) { while (c && c->type != -1) {
if (! strcmp(s, c->name)) 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++; c++;
} }
@@ -385,11 +347,11 @@ device_get_config_hex16(const char *s)
int int
device_get_config_hex20(const char *s) 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) { while (c && c->type != -1) {
if (! strcmp(s, c->name)) 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++; c++;
} }
@@ -401,11 +363,11 @@ device_get_config_hex20(const char *s)
int int
device_get_config_mac(const char *s, int def) 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) { while (c && c->type != -1) {
if (! strcmp(s, c->name)) 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++; c++;
} }
@@ -417,11 +379,11 @@ device_get_config_mac(const char *s, int def)
void void
device_set_config_int(const char *s, int val) 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) { while (c && c->type != -1) {
if (! strcmp(s, c->name)) { 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; break;
} }
@@ -433,11 +395,11 @@ device_set_config_int(const char *s, int val)
void void
device_set_config_hex16(const char *s, int val) 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) { while (c && c->type != -1) {
if (! strcmp(s, c->name)) { 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; break;
} }
@@ -449,11 +411,11 @@ device_set_config_hex16(const char *s, int val)
void void
device_set_config_hex20(const char *s, int val) 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) { while (c && c->type != -1) {
if (! strcmp(s, c->name)) { 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; break;
} }
@@ -465,11 +427,11 @@ device_set_config_hex20(const char *s, int val)
void void
device_set_config_mac(const char *s, int val) 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) { while (c && c->type != -1) {
if (! strcmp(s, c->name)) { 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; break;
} }

View File

@@ -8,7 +8,7 @@
* *
* Definitions for the device handler. * 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> * Authors: Fred N. van Kempen, <decwiz@yahoo.com>
* Miran Grca, <mgrca8@gmail.com> * Miran Grca, <mgrca8@gmail.com>
@@ -108,15 +108,22 @@ typedef struct _device_ {
const device_config_t *config; const device_config_t *config;
} device_t; } device_t;
typedef struct {
const device_t *dev;
char name[2048];
} device_context_t;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
extern void device_init(void); 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(const device_t *);
extern void device_add_ex(const device_t *d, void *priv); 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_close_all(void);
extern void device_reset_all(void); extern void device_reset_all(void);
extern void device_reset_all_pci(void); extern void device_reset_all_pci(void);

View File

@@ -32,7 +32,7 @@
* TODO: The EV159 is supposed to support 16b EMS transfers, but the * 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.. * 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> * Author: Fred N. van Kempen, <decwiz@yahoo.com>
* *
@@ -106,7 +106,7 @@ typedef struct {
typedef struct { typedef struct {
const char *name; const char *name;
uint8_t board : 6, /* board type */ uint8_t board : 6, /* board type */
instance : 2; /* device instance */ reserved : 2;
uint8_t flags; uint8_t flags;
#define FLAG_CONFIG 0x01 /* card is configured */ #define FLAG_CONFIG 0x01 /* card is configured */
@@ -151,15 +151,6 @@ isamem_log(const char *fmt, ...)
#endif #endif
/* Local variables. */
static const device_t *instance[ISAMEM_MAX] = {
NULL,
NULL,
NULL,
NULL
};
/* Read one byte from onboard RAM. */ /* Read one byte from onboard RAM. */
static uint8_t static uint8_t
ram_readb(uint32_t addr, void *priv) ram_readb(uint32_t addr, void *priv)
@@ -412,13 +403,10 @@ isamem_init(const device_t *info)
int i; int i;
/* Find our device and create an instance. */ /* 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)); dev = (memdev_t *)malloc(sizeof(memdev_t));
memset(dev, 0x00, sizeof(memdev_t)); memset(dev, 0x00, sizeof(memdev_t));
dev->name = info->name; dev->name = info->name;
dev->board = info->local; dev->board = info->local;
dev->instance = i;
/* Do per-board initialization. */ /* Do per-board initialization. */
tot = 0; tot = 0;
@@ -650,7 +638,7 @@ dev->frame_addr = 0xE0000;
} }
/* Let them know our device instance. */ /* Let them know our device instance. */
return((void *)dev); return((void *) dev);
} }
@@ -672,8 +660,6 @@ isamem_close(void *priv)
if (dev->ram != NULL) if (dev->ram != NULL)
free(dev->ram); free(dev->ram);
instance[dev->instance] = NULL;
free(dev); free(dev);
} }
@@ -1045,21 +1031,14 @@ static const struct {
void void
isamem_reset(void) isamem_reset(void)
{ {
const device_t *dev;
int k, i; int k, i;
for (i = 0; i < ISAMEM_MAX; i++) { for (i = 0; i < ISAMEM_MAX; i++) {
k = isamem_type[i]; k = isamem_type[i];
if (k == 0) continue; 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. */ /* 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 * const device_t *
isamem_get_device(int board) isamem_get_device(int board)
{ {
return(instance[board]); /* Add the instance to the system. */
return boards[board].dev;
} }

View File

@@ -8,7 +8,7 @@
* *
* Platform support defintions for Win32. * 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/> * Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com> * Miran Grca, <mgrca8@gmail.com>
@@ -111,6 +111,7 @@ extern intptr_t fdd_type_to_icon(int type);
#ifdef EMU_DEVICE_H #ifdef EMU_DEVICE_H
extern uint8_t deviceconfig_open(HWND hwnd, const device_t *device); 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 #endif
extern uint8_t joystickconfig_open(HWND hwnd, int joy_nr, int type); extern uint8_t joystickconfig_open(HWND hwnd, int joy_nr, int type);

File diff suppressed because it is too large Load Diff

View File

@@ -8,7 +8,7 @@
* *
* Windows 86Box Settings dialog handler. * 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> * Authors: Miran Grca, <mgrca8@gmail.com>
* David Hrdlička, <hrdlickadavid@outlook.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_3:
case IDC_CONFIGURE_ISAMEM_4: case IDC_CONFIGURE_ISAMEM_4:
c = LOWORD(wParam) - IDC_CONFIGURE_ISAMEM_1; c = LOWORD(wParam) - IDC_CONFIGURE_ISAMEM_1;
dev = isamem_get_device(c); dev = isamem_get_device(temp_isamem[c]);
if (dev != NULL) temp_deviceconfig |= deviceconfig_inst_open(hdlg, (void *)dev, c + 1);
temp_deviceconfig |= deviceconfig_open(hdlg, (void *)dev);
else
ui_msgbox(MBX_INFO, (wchar_t *)IDS_2119);
break; break;
case IDC_CHECK_IDE_TER: case IDC_CHECK_IDE_TER: