diff --git a/src/device.c b/src/device.c index 52d2bb18e..79c84cd10 100644 --- a/src/device.c +++ b/src/device.c @@ -135,7 +135,7 @@ device_context_restore(void) } static void * -device_add_common(const device_t *d, const device_t *cd, void *p, int inst) +device_add_common(const device_t *d, const device_t *cd, void *p, void* params, int inst) { void *priv = NULL; int c; @@ -160,7 +160,7 @@ device_add_common(const device_t *d, const device_t *cd, void *p, int inst) device_set_context(&device_current, cd, inst); if (d->init != NULL) { - priv = d->init(d); + priv = (d->flags & DEVICE_EXTPARAMS) ? d->init_ext(d, params) : d->init(d); if (priv == NULL) { if (d->name) device_log("DEVICE: device '%s' init failed\n", d->name); @@ -199,55 +199,103 @@ device_get_internal_name(const device_t *d) void * device_add(const device_t *d) { - return device_add_common(d, d, NULL, 0); + return device_add_common(d, d, NULL, NULL, 0); +} + +void * +device_add_parameters(const device_t *d, void* params) +{ + return device_add_common(d, d, NULL, params, 0); } /* For devices that do not have an init function (internal video etc.) */ void device_add_ex(const device_t *d, void *priv) { - device_add_common(d, d, priv, 0); + device_add_common(d, d, priv, NULL, 0); +} + +void +device_add_ex_parameters(const device_t *d, void* priv, void *params) +{ + device_add_common(d, d, priv, params, 0); } void * device_add_inst(const device_t *d, int inst) { - return device_add_common(d, d, NULL, inst); + return device_add_common(d, d, NULL, NULL, inst); +} + +void * +device_add_inst_parameters(const device_t *d, int inst, void *params) +{ + return device_add_common(d, d, NULL, params, 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, d, priv, inst); + device_add_common(d, d, priv, NULL, inst); } -/* These four are to add a device with another device's context - will be +void +device_add_inst_ex_parameters(const device_t *d, void *priv, int inst, void *params) +{ + device_add_common(d, d, priv, params, inst); +} + +/* These eight are to add a device with another device's context - will be used to add machines' internal devices. */ void * device_cadd(const device_t *d, const device_t *cd) { - return device_add_common(d, cd, NULL, 0); + return device_add_common(d, cd, NULL, NULL, 0); +} + +void * +device_cadd_parameters(const device_t *d, const device_t *cd, void *params) +{ + return device_add_common(d, cd, NULL, params, 0); } /* For devices that do not have an init function (internal video etc.) */ void device_cadd_ex(const device_t *d, const device_t *cd, void *priv) { - device_add_common(d, cd, priv, 0); + device_add_common(d, cd, priv, NULL, 0); +} + +void +device_cadd_ex_parameters(const device_t *d, const device_t *cd, void *priv, void *params) +{ + device_add_common(d, cd, priv, params, 0); } void * device_cadd_inst(const device_t *d, const device_t *cd, int inst) { - return device_add_common(d, cd, NULL, inst); + return device_add_common(d, cd, NULL, NULL, inst); +} + +void * +device_cadd_inst_parameters(const device_t *d, const device_t *cd, int inst, void *params) +{ + return device_add_common(d, cd, NULL, params, inst); } /* For devices that do not have an init function (internal video etc.) */ void device_cadd_inst_ex(const device_t *d, const device_t *cd, void *priv, int inst) { - device_add_common(d, cd, priv, inst); + device_add_common(d, cd, priv, NULL, inst); +} + +void +device_cadd_inst_ex_parameters(const device_t *d, const device_t *cd, void *priv, int inst, void* params) +{ + device_add_common(d, cd, priv, params, inst); } void diff --git a/src/include/86box/device.h b/src/include/86box/device.h index 877ef660a..1c0e34045 100644 --- a/src/include/86box/device.h +++ b/src/include/86box/device.h @@ -57,19 +57,21 @@ #define CONFIG_SERPORT 12 enum { - DEVICE_PCJR = 2, /* requires an IBM PCjr */ - DEVICE_AT = 4, /* requires an AT-compatible system */ - DEVICE_PS2 = 8, /* requires a PS/1 or PS/2 system */ - DEVICE_ISA = 0x10, /* requires the ISA bus */ - DEVICE_CBUS = 0x20, /* requires the C-BUS bus */ - DEVICE_MCA = 0x40, /* requires the MCA bus */ - DEVICE_EISA = 0x80, /* requires the EISA bus */ - DEVICE_VLB = 0x100, /* requires the PCI bus */ - DEVICE_PCI = 0x200, /* requires the VLB bus */ - DEVICE_AGP = 0x400, /* requires the AGP bus */ - DEVICE_AC97 = 0x800, /* requires the AC'97 bus */ - DEVICE_COM = 0x1000, /* requires a serial port */ - DEVICE_LPT = 0x2000 /* requires a parallel port */ + DEVICE_PCJR = 2, /* requires an IBM PCjr */ + DEVICE_AT = 4, /* requires an AT-compatible system */ + DEVICE_PS2 = 8, /* requires a PS/1 or PS/2 system */ + DEVICE_ISA = 0x10, /* requires the ISA bus */ + DEVICE_CBUS = 0x20, /* requires the C-BUS bus */ + DEVICE_MCA = 0x40, /* requires the MCA bus */ + DEVICE_EISA = 0x80, /* requires the EISA bus */ + DEVICE_VLB = 0x100, /* requires the PCI bus */ + DEVICE_PCI = 0x200, /* requires the VLB bus */ + DEVICE_AGP = 0x400, /* requires the AGP bus */ + DEVICE_AC97 = 0x800, /* requires the AC'97 bus */ + DEVICE_COM = 0x1000, /* requires a serial port */ + DEVICE_LPT = 0x2000, /* requires a parallel port */ + + DEVICE_EXTPARAMS = 0x40000000 /* accepts extended parameters */ }; #define BIOS_NORMAL 0 @@ -118,9 +120,12 @@ typedef struct _device_ { const char *name; const char *internal_name; uint32_t flags; /* system flags */ - uint32_t local; /* flags local to device */ + uintptr_t local; /* flags local to device */ - void *(*init)(const struct _device_ *); + union { + void *(*init)(const struct _device_ *); + void *(*init_ext)(const struct _device_ *, void*); + }; void (*close)(void *priv); void (*reset)(void *priv); union { @@ -150,13 +155,21 @@ extern void device_context(const device_t *d); extern void device_context_inst(const device_t *d, int inst); extern void device_context_restore(void); extern void *device_add(const device_t *d); +extern void *device_add_parameters(const device_t *d, void *params); extern void device_add_ex(const device_t *d, void *priv); +extern void device_add_ex_parameters(const device_t *d, void *priv, void *params); extern void *device_add_inst(const device_t *d, int inst); +extern void *device_add_inst_parameters(const device_t *d, int inst, void *params); extern void device_add_inst_ex(const device_t *d, void *priv, int inst); +extern void device_add_inst_ex_parameters(const device_t *d, void *priv, int inst, void *params); extern void *device_cadd(const device_t *d, const device_t *cd); +extern void *device_cadd_parameters(const device_t *d, const device_t *cd, void *params); extern void device_cadd_ex(const device_t *d, const device_t *cd, void *priv); +extern void device_cadd_ex_parameters(const device_t *d, const device_t *cd, void *priv, void *params); extern void *device_cadd_inst(const device_t *d, const device_t *cd, int inst); +extern void *device_cadd_inst_parameters(const device_t *d, const device_t *cd, int inst, void *params); extern void device_cadd_inst_ex(const device_t *d, const device_t *cd, void *priv, int inst); +extern void device_cadd_inst_ex_parameters(const device_t *d, const device_t *cd, void *priv, int inst, void *params); extern void device_close_all(void); extern void device_reset_all(void); extern void device_reset_all_pci(void); diff --git a/src/include/86box/machine.h b/src/include/86box/machine.h index 5a5b0bfda..4d1effe9a 100644 --- a/src/include/86box/machine.h +++ b/src/include/86box/machine.h @@ -279,7 +279,7 @@ typedef struct _machine_ { const char *name; const char *internal_name; uint32_t type; - uint32_t chipset; + uintptr_t chipset; int (*init)(const struct _machine_ *); uintptr_t pad, pad0, pad1, pad2; const machine_cpu_t cpu;