diff --git a/src/cpu/808x.c b/src/cpu/808x.c index 57153f8..d1e774d 100644 --- a/src/cpu/808x.c +++ b/src/cpu/808x.c @@ -8,7 +8,7 @@ * * 808x CPU emulation. * - * Version: @(#)808x.c 1.0.18 2019/05/07 + * Version: @(#)808x.c 1.0.19 2019/05/15 * * Authors: Miran Grca, * Andrew Jenner (reenigne), @@ -2867,5 +2867,4 @@ cpu_reset(int hard) codegen_reset(); #endif x86_was_reset = 1; - port_92_clear_reset(); } diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c index 7210472..cd8efe8 100644 --- a/src/cpu/cpu.c +++ b/src/cpu/cpu.c @@ -8,7 +8,7 @@ * * CPU type handler. * - * Version: @(#)cpu.c 1.0.13 2019/05/03 + * Version: @(#)cpu.c 1.0.14 2019/05/13 * * Authors: Fred N. van Kempen, * Sarah Walker, @@ -212,6 +212,79 @@ static uint8_t ccr0, ccr1, ccr2, ccr3, ccr4, ccr5, ccr6; static int cyrix_addr; +static void +cyrix_write(uint16_t addr, uint8_t val, priv_t priv) +{ + if (addr & 1) switch (cyrix_addr) { + case 0xc0: /*CCR0*/ + ccr0 = val; + break; + + case 0xc1: /*CCR1*/ + ccr1 = val; + break; + + case 0xc2: /*CCR2*/ + ccr2 = val; + break; + + case 0xc3: /*CCR3*/ + ccr3 = val; + break; + + case 0xe8: /*CCR4*/ + if ((ccr3 & 0xf0) == 0x10) { + ccr4 = val; + if (cpu->type >= CPU_Cx6x86) { + if (val & 0x80) + CPUID = cpu->cpuid_model; + else + CPUID = 0; + } + } + break; + + case 0xe9: /*CCR5*/ + if ((ccr3 & 0xf0) == 0x10) + ccr5 = val; + break; + + case 0xea: /*CCR6*/ + if ((ccr3 & 0xf0) == 0x10) + ccr6 = val; + break; + } else + cyrix_addr = val; +} + + +static uint8_t +cyrix_read(uint16_t addr, priv_t priv) +{ + if (addr & 1) { + switch (cyrix_addr) { + case 0xc0: return ccr0; + case 0xc1: return ccr1; + case 0xc2: return ccr2; + case 0xc3: return ccr3; + case 0xe8: return ((ccr3 & 0xf0) == 0x10) ? ccr4 : 0xff; + case 0xe9: return ((ccr3 & 0xf0) == 0x10) ? ccr5 : 0xff; + case 0xea: return ((ccr3 & 0xf0) == 0x10) ? ccr6 : 0xff; + case 0xfe: return cpu->cyrix_id & 0xff; + case 0xff: return cpu->cyrix_id >> 8; + } + + if ((cyrix_addr & 0xf0) == 0xc0) + return 0xff; + + if (cyrix_addr == 0x20 && cpu->type == CPU_Cx5x86) + return 0xff; + } + + return 0xff; +} + + /* * Actually do the 'setup' work. * @@ -282,8 +355,8 @@ cpu_activate(void) pci_set_speed(cpu->fsb_speed); if (is_cyrix) - io_sethandler(0x0022, 2, - cyrix_read,NULL,NULL, cyrix_write,NULL,NULL, NULL); + io_sethandler(0x0022, 2, + cyrix_read,NULL,NULL, cyrix_write,NULL,NULL, NULL); else io_removehandler(0x0022, 2, cyrix_read,NULL,NULL, cyrix_write,NULL,NULL, NULL); @@ -2234,79 +2307,6 @@ i686_invalid_wrmsr: } -void -cyrix_write(uint16_t addr, uint8_t val, void *priv) -{ - if (addr & 1) switch (cyrix_addr) { - case 0xc0: /*CCR0*/ - ccr0 = val; - break; - - case 0xc1: /*CCR1*/ - ccr1 = val; - break; - - case 0xc2: /*CCR2*/ - ccr2 = val; - break; - - case 0xc3: /*CCR3*/ - ccr3 = val; - break; - - case 0xe8: /*CCR4*/ - if ((ccr3 & 0xf0) == 0x10) { - ccr4 = val; - if (cpu->type >= CPU_Cx6x86) { - if (val & 0x80) - CPUID = cpu->cpuid_model; - else - CPUID = 0; - } - } - break; - - case 0xe9: /*CCR5*/ - if ((ccr3 & 0xf0) == 0x10) - ccr5 = val; - break; - - case 0xea: /*CCR6*/ - if ((ccr3 & 0xf0) == 0x10) - ccr6 = val; - break; - } else - cyrix_addr = val; -} - - -uint8_t -cyrix_read(uint16_t addr, void *priv) -{ - if (addr & 1) { - switch (cyrix_addr) { - case 0xc0: return ccr0; - case 0xc1: return ccr1; - case 0xc2: return ccr2; - case 0xc3: return ccr3; - case 0xe8: return ((ccr3 & 0xf0) == 0x10) ? ccr4 : 0xff; - case 0xe9: return ((ccr3 & 0xf0) == 0x10) ? ccr5 : 0xff; - case 0xea: return ((ccr3 & 0xf0) == 0x10) ? ccr6 : 0xff; - case 0xfe: return cpu->cyrix_id & 0xff; - case 0xff: return cpu->cyrix_id >> 8; - } - - if ((cyrix_addr & 0xf0) == 0xc0) - return 0xff; - - if (cyrix_addr == 0x20 && cpu->type == CPU_Cx5x86) - return 0xff; - } - - return 0xff; -} - - void #ifdef USE_DYNAREC x86_setopcodes(const OpFn *opcodes, const OpFn *opcodes_0f, diff --git a/src/cpu/cpu.h b/src/cpu/cpu.h index e5792c3..b93d55d 100644 --- a/src/cpu/cpu.h +++ b/src/cpu/cpu.h @@ -8,7 +8,7 @@ * * Definitions for the CPU module. * - * Version: @(#)cpu.h 1.0.12 2019/05/03 + * Version: @(#)cpu.h 1.0.13 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -423,8 +423,6 @@ extern int timing_misaligned; /* Functions. */ -extern void cyrix_write(uint16_t addr, uint8_t val, void *priv); -extern uint8_t cyrix_read(uint16_t addr, void *priv); extern void loadseg(uint16_t seg, x86seg *s); extern void loadcs(uint16_t seg); diff --git a/src/device.c b/src/device.c index 6c1af73..b98c889 100644 --- a/src/device.c +++ b/src/device.c @@ -11,7 +11,7 @@ * * **TODO** Merge the various 'add' variants, its getting too messy. * - * Version: @(#)device.c 1.0.24 2019/05/05 + * Version: @(#)device.c 1.0.26 2019/05/15 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -67,7 +67,7 @@ typedef struct clonedev { static device_t *devices[DEVICE_MAX]; -static void *device_priv[DEVICE_MAX]; +static priv_t device_priv[DEVICE_MAX]; static device_t *device_current; static clonedev_t *clones = NULL; @@ -152,11 +152,11 @@ device_clone(const device_t *master) /* Add a new device to the system. */ -void * -device_add_parent(const device_t *d, void *parent) +priv_t +device_add_parent(const device_t *d, priv_t parent) { wchar_t temp[1024]; - void *priv = NULL; + priv_t priv = NULL; device_t *old; int c; @@ -225,7 +225,7 @@ device_add_parent(const device_t *d, void *parent) } -void * +priv_t device_add(const device_t *d) { return(device_add_parent(d, device_priv[0])); @@ -234,7 +234,7 @@ device_add(const device_t *d) /* For devices that do not have an init function (internal video etc.) */ void -device_add_ex(const device_t *d, void *priv) +device_add_ex(const device_t *d, priv_t priv) { int c; @@ -260,6 +260,33 @@ device_add_ex(const device_t *d, void *priv) } +void +device_remove(const device_t *d, priv_t priv) +{ + int c; + + for (c = 0; c < DEVICE_MAX; c++) { + if ((devices[c] == (device_t *)d) && (device_priv[c] == priv)) { + /* Found it. Close the device. */ + if (devices[c]->close != NULL) + devices[c]->close(device_priv[c]); + + /* Now move up all slots. */ + for (; c < DEVICE_MAX - 1; c++) { + devices[c] = devices[c + 1]; + device_priv[c] = device_priv[c + 1]; + } + + /* Zap last slot. */ + devices[c] = NULL; + device_priv[c] = NULL; + + return; + } + } +} + + void device_close_all(void) { @@ -295,7 +322,7 @@ device_reset_all(int flags) } -void * +priv_t device_get_priv(const device_t *d) { int c; @@ -443,17 +470,17 @@ device_get_config_int(const char *s) int -device_get_config_int_ex(const char *s, int def) +device_get_config_int_ex(const char *s, int dflt) { const device_config_t *c = device_current->config; while (c && c->name) { if (! strcmp(s, c->name)) - return(config_get_int(device_current->name, s, def)); + return(config_get_int(device_current->name, s, dflt)); c++; } - return(def); + return(dflt); } @@ -488,17 +515,17 @@ device_get_config_hex20(const char *s) int -device_get_config_mac(const char *s, int def) +device_get_config_mac(const char *s, int dflt) { const device_config_t *c = device_current->config; while (c && c->name) { if (! strcmp(s, c->name)) - return(config_get_mac(device_current->name, s, def)); + return(config_get_mac(device_current->name, s, dflt)); c++; } - return(def); + return(dflt); } diff --git a/src/device.h b/src/device.h index 0fb22ea..af5b890 100644 --- a/src/device.h +++ b/src/device.h @@ -8,7 +8,7 @@ * * Definitions for the device handler. * - * Version: @(#)device.h 1.0.12 2019/04/18 + * Version: @(#)device.h 1.0.13 2019/05/15 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -76,30 +76,30 @@ enum { typedef struct { - const char *description; - int value; -} device_config_selection_t; + const char *description; + int value; +} devcfg_selection_t; typedef struct { - const char *description; - const char *extensions[5]; -} device_config_file_filter_t; + const char *description; + const char *extensions[5]; +} devcfg_fn_filter_t; typedef struct { - int min; - int max; - int step; -} device_config_spinner_t; + int min; + int max; + int step; +} devcfg_spinner_t; typedef struct { - const char *name; - const char *description; - int type; - const char *default_string; - int default_int; - device_config_selection_t selection[16]; - device_config_file_filter_t file_filter[16]; - device_config_spinner_t spinner; + const char *name; + const char *description; + int type; + const char *default_string; + int default_int; + devcfg_selection_t selection[16]; + devcfg_fn_filter_t file_filter[16]; + devcfg_spinner_t spinner; } device_config_t; typedef struct _device_ { @@ -109,14 +109,14 @@ typedef struct _device_ { const wchar_t *path; /* path to BIOS/ROM file(s) */ - void *(*init)(const struct _device_ *, void *arg); - void (*close)(void *priv); - void (*reset)(void *priv); + priv_t (*init)(const struct _device_ *, void *arg); + void (*close)(priv_t); + void (*reset)(priv_t); void *u1_reuse; #define ms_poll u1_reuse #define dev_available u1_reuse - void (*speed_changed)(void *priv); - void (*force_redraw)(void *priv); + void (*speed_changed)(priv_t); + void (*force_redraw)(priv_t); const void *u2_reuse; #define vid_timing u2_reuse #define mca_reslist u2_reuse @@ -134,12 +134,13 @@ extern void device_reset(void); extern void device_dump(void); #endif extern const device_t *device_clone(const device_t *master); -extern void *device_add(const device_t *); -extern void *device_add_parent(const device_t *, void *parent); -extern void device_add_ex(const device_t *, void *priv); +extern priv_t device_add(const device_t *); +extern priv_t device_add_parent(const device_t *, priv_t parent); +extern void device_add_ex(const device_t *, priv_t); +extern void device_remove(const device_t *, priv_t); extern void device_close_all(void); extern void device_reset_all(int flags); -extern void *device_get_priv(const device_t *); +extern priv_t device_get_priv(const device_t *); extern const char *device_get_bus_name(const device_t *); extern int device_available(const device_t *); extern void device_speed_changed(void); @@ -148,10 +149,10 @@ extern void device_force_redraw(void); extern int device_is_valid(const device_t *, int machine_flags); extern int device_get_config_int(const char *name); -extern int device_get_config_int_ex(const char *s, int dflt_int); +extern int device_get_config_int_ex(const char *s, int dflt); extern int device_get_config_hex16(const char *name); extern int device_get_config_hex20(const char *name); -extern int device_get_config_mac(const char *name, int dflt_int); +extern int device_get_config_mac(const char *name, int dflt); extern void device_set_config_int(const char *s, int val); extern void device_set_config_hex16(const char *s, int val); extern void device_set_config_hex20(const char *s, int val); diff --git a/src/devices/chipsets/acc2168.c b/src/devices/chipsets/acc2168.c index 1ef3f10..0711874 100644 --- a/src/devices/chipsets/acc2168.c +++ b/src/devices/chipsets/acc2168.c @@ -8,7 +8,7 @@ * * Implementation of the ACC 2168 chipset. * - * Version: @(#)acc2168.c 1.0.2 2019/05/05 + * Version: @(#)acc2168.c 1.0.3 2019/05/15 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -48,6 +48,7 @@ #include "../../rom.h" #include "../../device.h" #include "../../plat.h" +#include "../system/port92.h" #include "acc2168.h" @@ -113,7 +114,7 @@ shadow_recalc(acc2168_t *dev) static void -acc2168_write(uint16_t addr, uint8_t val, void *priv) +acc2168_write(uint16_t addr, uint8_t val, priv_t priv) { acc2168_t *dev = (acc2168_t *)priv; @@ -131,7 +132,7 @@ acc2168_write(uint16_t addr, uint8_t val, void *priv) static uint8_t -acc2168_read(uint16_t addr, void *priv) +acc2168_read(uint16_t addr, priv_t priv) { acc2168_t *dev = (acc2168_t *)priv; @@ -143,7 +144,7 @@ acc2168_read(uint16_t addr, void *priv) static void -acc2168_close(void *priv) +acc2168_close(priv_t priv) { acc2168_t *dev = (acc2168_t *)priv; @@ -151,7 +152,7 @@ acc2168_close(void *priv) } -static void * +static priv_t acc2168_init(const device_t *info, UNUSED(void *parent)) { acc2168_t *dev; @@ -162,9 +163,9 @@ acc2168_init(const device_t *info, UNUSED(void *parent)) io_sethandler(0x00f2, 2, acc2168_read,NULL,NULL, acc2168_write,NULL,NULL, dev); - port_92_add(1); + device_add_parent(&port92_inverted_device, (priv_t)dev); - return(dev); + return((priv_t)dev); } diff --git a/src/devices/chipsets/ali1429.c b/src/devices/chipsets/ali1429.c index e94e5e5..9ea5182 100644 --- a/src/devices/chipsets/ali1429.c +++ b/src/devices/chipsets/ali1429.c @@ -8,7 +8,7 @@ * * Implementation of the ALi M-1429/1431 chipset. * - * Version: @(#)ali1429.c 1.0.8 2019/04/08 + * Version: @(#)ali1429.c 1.0.9 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -101,7 +101,7 @@ ali1429_recalc(ali_t *dev) static void -ali1429_write(uint16_t port, uint8_t val, void *priv) +ali1429_write(uint16_t port, uint8_t val, priv_t priv) { ali_t *dev = (ali_t *)priv; @@ -125,7 +125,7 @@ ali1429_write(uint16_t port, uint8_t val, void *priv) static uint8_t -ali1429_read(uint16_t port, void *priv) +ali1429_read(uint16_t port, priv_t priv) { ali_t *dev = (ali_t *)priv; @@ -147,7 +147,7 @@ ali1429_reset(ali_t *dev) static void -ali_close(void *priv) +ali_close(priv_t priv) { ali_t *dev = (ali_t *)priv; @@ -155,7 +155,7 @@ ali_close(void *priv) } -static void * +static priv_t ali_init(const device_t *info, UNUSED(void *parent)) { ali_t *dev; @@ -169,7 +169,7 @@ ali_init(const device_t *info, UNUSED(void *parent)) io_sethandler(0x0022, 2, ali1429_read,NULL,NULL, ali1429_write,NULL,NULL, dev); - return(dev); + return((priv_t)dev); } diff --git a/src/devices/chipsets/headland.c b/src/devices/chipsets/headland.c index 3399a64..b5bb5fe 100644 --- a/src/devices/chipsets/headland.c +++ b/src/devices/chipsets/headland.c @@ -8,7 +8,7 @@ * * Implementation of the HEADLAND AT286 chipset. * - * Version: @(#)headland.c 1.0.12 2019/04/20 + * Version: @(#)headland.c 1.0.13 2019/05/13 * * Authors: Fred N. van Kempen, * Original by GreatPsycho for PCem. @@ -209,7 +209,7 @@ memmap_state_update(headland_t *dev) static void -hl_write(uint16_t addr, uint8_t val, void *priv) +hl_write(uint16_t addr, uint8_t val, priv_t priv) { headland_t *dev = (headland_t *)priv; uint32_t base_addr, virt_addr; @@ -335,7 +335,7 @@ hl_write(uint16_t addr, uint8_t val, void *priv) static void -hl_writew(uint16_t addr, uint16_t val, void *priv) +hl_writew(uint16_t addr, uint16_t val, priv_t priv) { headland_t *dev = (headland_t *)priv; uint32_t base_addr, virt_addr; @@ -377,7 +377,7 @@ hl_writew(uint16_t addr, uint16_t val, void *priv) static uint8_t -hl_read(uint16_t addr, void *priv) +hl_read(uint16_t addr, priv_t priv) { headland_t *dev = (headland_t *)priv; uint8_t ret = 0xff; @@ -444,7 +444,7 @@ hl_read(uint16_t addr, void *priv) static uint16_t -hl_readw(uint16_t addr, void *priv) +hl_readw(uint16_t addr, priv_t priv) { headland_t *dev = (headland_t *)priv; uint16_t ret = 0xffff; @@ -465,7 +465,7 @@ hl_readw(uint16_t addr, void *priv) static uint8_t -mem_read_b(uint32_t addr, void *priv) +mem_read_b(uint32_t addr, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; headland_t *dev = (headland_t *)map->dev; @@ -481,7 +481,7 @@ mem_read_b(uint32_t addr, void *priv) static uint16_t -mem_read_w(uint32_t addr, void *priv) +mem_read_w(uint32_t addr, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; headland_t *dev = (headland_t *)map->dev; @@ -497,7 +497,7 @@ mem_read_w(uint32_t addr, void *priv) static uint32_t -mem_read_l(uint32_t addr, void *priv) +mem_read_l(uint32_t addr, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; headland_t *dev = (headland_t *)map->dev; @@ -513,7 +513,7 @@ mem_read_l(uint32_t addr, void *priv) static void -mem_write_b(uint32_t addr, uint8_t val, void *priv) +mem_write_b(uint32_t addr, uint8_t val, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; headland_t *dev = (headland_t *)map->dev; @@ -526,7 +526,7 @@ mem_write_b(uint32_t addr, uint8_t val, void *priv) static void -mem_write_w(uint32_t addr, uint16_t val, void *priv) +mem_write_w(uint32_t addr, uint16_t val, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; headland_t *dev = (headland_t *)map->dev; @@ -539,7 +539,7 @@ mem_write_w(uint32_t addr, uint16_t val, void *priv) static void -mem_write_l(uint32_t addr, uint32_t val, void *priv) +mem_write_l(uint32_t addr, uint32_t val, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; headland_t *dev = (headland_t *)map->dev; @@ -552,7 +552,7 @@ mem_write_l(uint32_t addr, uint32_t val, void *priv) static void -headland_close(void *priv) +headland_close(priv_t priv) { headland_t *dev = (headland_t *)priv; @@ -560,7 +560,7 @@ headland_close(void *priv) } -static void * +static priv_t headland_init(const device_t *info, UNUSED(void *parent)) { headland_t *dev; @@ -648,7 +648,7 @@ headland_init(const device_t *info, UNUSED(void *parent)) memmap_state_update(dev); - return(dev); + return((priv_t)dev); } diff --git a/src/devices/chipsets/intel4x0.c b/src/devices/chipsets/intel4x0.c index ce1b799..8b5c696 100644 --- a/src/devices/chipsets/intel4x0.c +++ b/src/devices/chipsets/intel4x0.c @@ -8,7 +8,7 @@ * * Implementation of the Intel 430/440 PCISet chipsets. * - * Version: @(#)intel4x0.c 1.0.6 2019/04/11 + * Version: @(#)intel4x0.c 1.0.7 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -100,7 +100,7 @@ i4x0_map(uint32_t addr, uint32_t size, int state) static void -i4x0_write(int func, int addr, uint8_t val, void *priv) +i4x0_write(int func, int addr, uint8_t val, priv_t priv) { i4x0_t *dev = (i4x0_t *)priv; @@ -210,7 +210,7 @@ i4x0_write(int func, int addr, uint8_t val, void *priv) static uint8_t -i4x0_read(int func, int addr, void *priv) +i4x0_read(int func, int addr, priv_t priv) { i4x0_t *dev = (i4x0_t *)priv; @@ -222,7 +222,7 @@ i4x0_read(int func, int addr, void *priv) static void -i4x0_reset(void *priv) +i4x0_reset(priv_t priv) { i4x0_t *dev = (i4x0_t *)priv; @@ -233,7 +233,7 @@ i4x0_reset(void *priv) static void -i4x0_close(void *priv) +i4x0_close(priv_t priv) { i4x0_t *dev = (i4x0_t *)priv; @@ -241,7 +241,7 @@ i4x0_close(void *priv) } -static void * +static priv_t i4x0_init(const device_t *info, UNUSED(void *parent)) { i4x0_t *dev; @@ -343,7 +343,7 @@ i4x0_init(const device_t *info, UNUSED(void *parent)) pci_add_card(0, i4x0_read, i4x0_write, dev); - return dev; + return((priv_t)dev); } diff --git a/src/devices/chipsets/neat.c b/src/devices/chipsets/neat.c index 3681e06..6aa3f33 100644 --- a/src/devices/chipsets/neat.c +++ b/src/devices/chipsets/neat.c @@ -13,7 +13,7 @@ * 8MB of DRAM chips', because it works fine with bus-based * memory expansion. * - * Version: @(#)neat.c 1.0.5 2019/04/08 + * Version: @(#)neat.c 1.0.6 2019/05/13 * * Author: Fred N. van Kempen, * @@ -258,7 +258,7 @@ typedef struct { /* Read one byte from paged RAM. */ static uint8_t -ems_readb(uint32_t addr, void *priv) +ems_readb(uint32_t addr, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; neat_t *dev = (neat_t *)map->dev; @@ -277,7 +277,7 @@ ems_readb(uint32_t addr, void *priv) /* Read one word from paged RAM. */ static uint16_t -ems_readw(uint32_t addr, void *priv) +ems_readw(uint32_t addr, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; neat_t *dev = (neat_t *)map->dev; @@ -296,7 +296,7 @@ ems_readw(uint32_t addr, void *priv) /* Write one byte to paged RAM. */ static void -ems_writeb(uint32_t addr, uint8_t val, void *priv) +ems_writeb(uint32_t addr, uint8_t val, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; neat_t *dev = (neat_t *)map->dev; @@ -312,7 +312,7 @@ ems_writeb(uint32_t addr, uint8_t val, void *priv) /* Write one word to paged RAM. */ static void -ems_writew(uint32_t addr, uint16_t val, void *priv) +ems_writew(uint32_t addr, uint16_t val, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; neat_t *dev = (neat_t *)map->dev; @@ -355,7 +355,7 @@ ems_recalc(neat_t *dev, emspage_t *ems) static void -ems_write(uint16_t port, uint8_t val, void *priv) +ems_write(uint16_t port, uint8_t val, priv_t priv) { neat_t *dev = (neat_t *)priv; emspage_t *ems; @@ -380,7 +380,7 @@ ems_write(uint16_t port, uint8_t val, void *priv) static uint8_t -ems_read(uint16_t port, void *priv) +ems_read(uint16_t port, priv_t priv) { neat_t *dev = (neat_t *)priv; uint8_t ret = 0xff; @@ -467,7 +467,7 @@ ems_init(neat_t *dev, int en) static void -neat_write(uint16_t port, uint8_t val, void *priv) +neat_write(uint16_t port, uint8_t val, priv_t priv) { neat_t *dev = (neat_t *)priv; uint8_t xval, *reg; @@ -629,7 +629,7 @@ neat_write(uint16_t port, uint8_t val, void *priv) static uint8_t -neat_read(uint16_t port, void *priv) +neat_read(uint16_t port, priv_t priv) { neat_t *dev = (neat_t *)priv; uint8_t ret = 0xff; @@ -654,7 +654,7 @@ neat_read(uint16_t port, void *priv) static void -neat_close(void *priv) +neat_close(priv_t priv) { neat_t *dev = (neat_t *)priv; @@ -662,7 +662,7 @@ neat_close(void *priv) } -static void * +static priv_t neat_init(const device_t *info, UNUSED(void *parent)) { neat_t *dev; @@ -817,7 +817,7 @@ neat_init(const device_t *info, UNUSED(void *parent)) io_sethandler(0x0022, 2, neat_read,NULL,NULL, neat_write,NULL,NULL, dev); - return(dev); + return((priv_t)dev); } diff --git a/src/devices/chipsets/opti495.c b/src/devices/chipsets/opti495.c index 96e1110..4aac935 100644 --- a/src/devices/chipsets/opti495.c +++ b/src/devices/chipsets/opti495.c @@ -258,7 +258,7 @@ Note: the block address is forced to be a multiple of the block size by ignoring the appropriate number of the least-significant bits SeeAlso: #P0178,#P0187 * - * Version: @(#)opti495.c 1.0.11 2019/04/08 + * Version: @(#)opti495.c 1.0.12 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -310,7 +310,7 @@ typedef struct { static void -opti495_write(uint16_t addr, uint8_t val, void *priv) +opti495_write(uint16_t addr, uint8_t val, priv_t priv) { opti_t *dev = (opti_t *)priv; @@ -341,7 +341,7 @@ opti495_write(uint16_t addr, uint8_t val, void *priv) static uint8_t -opti495_read(uint16_t addr, void *priv) +opti495_read(uint16_t addr, priv_t priv) { opti_t *dev = (opti_t *)priv; uint8_t ret = 0xff; @@ -358,7 +358,7 @@ opti495_read(uint16_t addr, void *priv) static void -opti_close(void *priv) +opti_close(priv_t priv) { opti_t *dev = (opti_t *)priv; @@ -366,7 +366,7 @@ opti_close(void *priv) } -static void * +static priv_t opti_init(const device_t *info, UNUSED(void *parent)) { opti_t *dev; @@ -382,7 +382,7 @@ opti_init(const device_t *info, UNUSED(void *parent)) io_sethandler(0x0024, 1, opti495_read,NULL,NULL, opti495_write,NULL,NULL, dev); - return(dev); + return((priv_t)dev); } diff --git a/src/devices/chipsets/scat.c b/src/devices/chipsets/scat.c index 4da95c8..6b548ea 100644 --- a/src/devices/chipsets/scat.c +++ b/src/devices/chipsets/scat.c @@ -8,7 +8,7 @@ * * Implementation of the C&T 82C235 ("SCAT") chipset. * - * Version: @(#)scat.c 1.0.17 2019/05/03 + * Version: @(#)scat.c 1.0.18 2019/05/13 * * Authors: Fred N. van Kempen, * Original by GreatPsycho for PCem. @@ -124,8 +124,8 @@ static const uint8_t scatsx_external_is_RAS[33] = { }; -static uint8_t scat_read(uint16_t port, void *priv); -static void scat_write(uint16_t port, uint8_t val, void *priv); +static uint8_t scat_read(uint16_t port, priv_t priv); +static void scat_write(uint16_t port, uint8_t val, priv_t priv); static void @@ -1038,7 +1038,7 @@ memmap_state_update(scat_t *dev) static void -scat_write(uint16_t port, uint8_t val, void *priv) +scat_write(uint16_t port, uint8_t val, priv_t priv) { scat_t *dev = (scat_t *)priv; uint8_t reg_valid = 0, @@ -1245,7 +1245,7 @@ scat_write(uint16_t port, uint8_t val, void *priv) static uint8_t -scat_read(uint16_t port, void *priv) +scat_read(uint16_t port, priv_t priv) { scat_t *dev = (scat_t *)priv; uint8_t ret = 0xff, indx; @@ -1318,7 +1318,7 @@ scat_read(uint16_t port, void *priv) static uint8_t -mem_read_scatb(uint32_t addr, void *priv) +mem_read_scatb(uint32_t addr, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; scat_t *dev = (scat_t *)map->dev; @@ -1334,7 +1334,7 @@ mem_read_scatb(uint32_t addr, void *priv) static uint16_t -mem_read_scatw(uint32_t addr, void *priv) +mem_read_scatw(uint32_t addr, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; scat_t *dev = (scat_t *)map->dev; @@ -1350,7 +1350,7 @@ mem_read_scatw(uint32_t addr, void *priv) static uint32_t -mem_read_scatl(uint32_t addr, void *priv) +mem_read_scatl(uint32_t addr, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; scat_t *dev = (scat_t *)map->dev; @@ -1366,7 +1366,7 @@ mem_read_scatl(uint32_t addr, void *priv) static void -mem_write_scatb(uint32_t addr, uint8_t val, void *priv) +mem_write_scatb(uint32_t addr, uint8_t val, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; scat_t *dev = (scat_t *)map->dev; @@ -1385,7 +1385,7 @@ mem_write_scatb(uint32_t addr, uint8_t val, void *priv) static void -mem_write_scatw(uint32_t addr, uint16_t val, void *priv) +mem_write_scatw(uint32_t addr, uint16_t val, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; scat_t *dev = (scat_t *)map->dev; @@ -1404,7 +1404,7 @@ mem_write_scatw(uint32_t addr, uint16_t val, void *priv) static void -mem_write_scatl(uint32_t addr, uint32_t val, void *priv) +mem_write_scatl(uint32_t addr, uint32_t val, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; scat_t *dev = (scat_t *)map->dev; @@ -1422,7 +1422,7 @@ mem_write_scatl(uint32_t addr, uint32_t val, void *priv) static void -scat_close(void *priv) +scat_close(priv_t priv) { scat_t *dev = (scat_t *)priv; @@ -1430,7 +1430,7 @@ scat_close(void *priv) } -static void * +static priv_t scat_init(const device_t *info, UNUSED(void *parent)) { scat_t *dev; @@ -1607,7 +1607,7 @@ scat_init(const device_t *info, UNUSED(void *parent)) io_sethandler(0x0092, 1, scat_read,NULL,NULL, scat_write,NULL,NULL, dev); - return(dev); + return((priv_t)dev); } diff --git a/src/devices/chipsets/sis471.c b/src/devices/chipsets/sis471.c index d07015e..3730feb 100644 --- a/src/devices/chipsets/sis471.c +++ b/src/devices/chipsets/sis471.c @@ -8,7 +8,7 @@ * * Emulation of the SiS 85C471 System Controller chip. * - * Version: @(#)sis471.c 1.0.14 2019/04/08 + * Version: @(#)sis471.c 1.0.15 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -60,7 +60,7 @@ typedef struct { static void -sis_write(uint16_t port, uint8_t val, void *priv) +sis_write(uint16_t port, uint8_t val, priv_t priv) { sis471_t *dev = (sis471_t *)priv; uint8_t indx = (port & 1) ? 0 : 1; @@ -110,7 +110,7 @@ sis_write(uint16_t port, uint8_t val, void *priv) static uint8_t -sis_read(uint16_t port, void *priv) +sis_read(uint16_t port, priv_t priv) { sis471_t *dev = (sis471_t *)priv; uint8_t indx = (port & 1) ? 0 : 1; @@ -130,7 +130,7 @@ sis_read(uint16_t port, void *priv) static void -sis_close(void *priv) +sis_close(priv_t priv) { sis471_t *dev = (sis471_t *)priv; @@ -138,7 +138,7 @@ sis_close(void *priv) } -static void * +static priv_t sis_init(const device_t *info, UNUSED(void *parent)) { int mem_size_mb, i; @@ -274,7 +274,7 @@ sis_init(const device_t *info, UNUSED(void *parent)) io_sethandler(0x0022, 2, sis_read,NULL,NULL, sis_write,NULL,NULL, dev); - return(dev); + return((priv_t)dev); } diff --git a/src/devices/chipsets/sis496.c b/src/devices/chipsets/sis496.c index 112c5f2..76bbe74 100644 --- a/src/devices/chipsets/sis496.c +++ b/src/devices/chipsets/sis496.c @@ -8,7 +8,7 @@ * * Implementation of the SiS 85C496/497 chipset. * - * Version: @(#)sis49x.c 1.0.11 2019/04/08 + * Version: @(#)sis49x.c 1.0.12 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -60,7 +60,7 @@ typedef struct { static void -sis497_write(uint16_t port, uint8_t val, void *priv) +sis497_write(uint16_t port, uint8_t val, priv_t priv) { sis49x_t *dev = (sis49x_t *)priv; uint8_t indx = (port & 1) ? 0 : 1; @@ -82,7 +82,7 @@ sis497_write(uint16_t port, uint8_t val, void *priv) static uint8_t -sis497_read(uint16_t port, void *priv) +sis497_read(uint16_t port, priv_t priv) { sis49x_t *dev = (sis49x_t *)priv; uint8_t indx = (port & 1) ? 0 : 1; @@ -272,7 +272,7 @@ recalc_mapping(sis49x_t *dev) static void -sis496_write(int func, int addr, uint8_t val, void *priv) +sis496_write(int func, int addr, uint8_t val, priv_t priv) { sis49x_t *dev = (sis49x_t *)priv; @@ -331,7 +331,7 @@ sis496_write(int func, int addr, uint8_t val, void *priv) static uint8_t -sis496_read(int func, int addr, void *priv) +sis496_read(int func, int addr, priv_t priv) { sis49x_t *dev = (sis49x_t *)priv; @@ -355,7 +355,7 @@ sis496_reset(void *priv) static void -sis496_close(void *priv) +sis496_close(priv_t priv) { sis49x_t *dev = (sis49x_t *)priv; @@ -363,7 +363,7 @@ sis496_close(void *priv) } -static void * +static priv_t sis496_init(const device_t *info, UNUSED(void *parent)) { sis49x_t *dev = (sis49x_t *)mem_alloc(sizeof(sis49x_t)); @@ -391,7 +391,7 @@ sis496_init(const device_t *info, UNUSED(void *parent)) sis497_reset(dev); - return dev; + return((priv_t)dev); } diff --git a/src/devices/chipsets/sis50x.c b/src/devices/chipsets/sis50x.c index eb0993e..9f7376b 100644 --- a/src/devices/chipsets/sis50x.c +++ b/src/devices/chipsets/sis50x.c @@ -8,7 +8,7 @@ * * Emulation of the SiS 85C50x PCI chips. * - * Version: @(#)sis50x.c 1.0.6 2019/04/08 + * Version: @(#)sis50x.c 1.0.7 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -106,7 +106,7 @@ static void static void -85c501_write(int func, int addr, uint8_t val, void *p) +85c501_write(int func, int addr, uint8_t val, priv_t priv) { if (func) return; @@ -149,7 +149,7 @@ static void static uint8_t -85c501_read(int func, int addr, void *p) +85c501_read(int func, int addr, priv_t priv) { if (func) return 0xff; @@ -202,7 +202,7 @@ static void static void -85c503_write(int func, int addr, uint8_t val, void *p) +85c503_write(int func, int addr, uint8_t val, priv_t priv) { if (func > 0) return; @@ -271,7 +271,7 @@ static void static uint8_t -85c503_read(int func, int addr, void *p) +85c503_read(int func, int addr, priv_t priv) { if (func > 0) return 0xff; @@ -317,7 +317,6 @@ static void trc_init(); port_92_reset(); - port_92_add(); pci_reset_handler.pci_set_reset = 85c503_reset; @@ -325,7 +324,7 @@ static void static void -85c50x_isa_write(uint16_t port, uint8_t val, void *priv) +85c50x_isa_write(uint16_t port, uint8_t val, priv_t priv) { if (port & 1) { if (85c50x_isa.reg <= 0x0b) @@ -336,7 +335,7 @@ static void static uint8_t -85c50x_isa_read(uint16_t port, void *priv) +85c50x_isa_read(uint16_t port, priv_t priv) { if (port & 1) { if (85c50x_isa.reg <= 0x0b) diff --git a/src/devices/chipsets/wd76c10.c b/src/devices/chipsets/wd76c10.c index 958b598..91ea390 100644 --- a/src/devices/chipsets/wd76c10.c +++ b/src/devices/chipsets/wd76c10.c @@ -8,7 +8,7 @@ * * Implementation of the WD76C10 System Controller chip. * - * Version: @(#)wd76c10.c 1.0.12 2019/04/08 + * Version: @(#)wd76c10.c 1.0.13 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -66,7 +66,7 @@ typedef struct { static uint16_t -wd76c10_read(uint16_t port, void *priv) +wd76c10_read(uint16_t port, priv_t priv) { wd76c10_t *dev = (wd76c10_t *)priv; int16_t ret = 0xffff; @@ -93,8 +93,18 @@ wd76c10_read(uint16_t port, void *priv) } +static uint8_t +wd76c10_readb(uint16_t port, priv_t priv) +{ + if (port & 1) + return(wd76c10_read(port & ~1, priv) >> 8); + + return(wd76c10_read(port, priv) & 0xff); +} + + static void -wd76c10_write(uint16_t port, uint16_t val, void *priv) +wd76c10_write(uint16_t port, uint16_t val, priv_t priv) { wd76c10_t *dev = (wd76c10_t *)priv; @@ -176,18 +186,8 @@ wd76c10_write(uint16_t port, uint16_t val, void *priv) } -static uint8_t -wd76c10_readb(uint16_t port, void *priv) -{ - if (port & 1) - return(wd76c10_read(port & ~1, priv) >> 8); - - return(wd76c10_read(port, priv) & 0xff); -} - - static void -wd76c10_writeb(uint16_t port, uint8_t val, void *priv) +wd76c10_writeb(uint16_t port, uint8_t val, priv_t priv) { uint16_t temp = wd76c10_read(port, priv); @@ -199,7 +199,7 @@ wd76c10_writeb(uint16_t port, uint8_t val, void *priv) static void -wd76c10_close(void *priv) +wd76c10_close(priv_t priv) { wd76c10_t *dev = (wd76c10_t *)priv; @@ -207,7 +207,7 @@ wd76c10_close(void *priv) } -static void * +static priv_t wd76c10_init(const device_t *info, UNUSED(void *parent)) { wd76c10_t *dev; @@ -231,7 +231,7 @@ wd76c10_init(const device_t *info, UNUSED(void *parent)) wd76c10_readb,wd76c10_read,NULL, wd76c10_writeb,wd76c10_write,NULL, dev); - return(dev); + return((priv_t)dev); } diff --git a/src/devices/disk/hdc_esdi_at.c b/src/devices/disk/hdc_esdi_at.c index e474ef8..5b7a3b4 100644 --- a/src/devices/disk/hdc_esdi_at.c +++ b/src/devices/disk/hdc_esdi_at.c @@ -8,7 +8,7 @@ * * Driver for the ESDI controller (WD1007-vse1) for PC/AT. * - * Version: @(#)hdc_esdi_at.c 1.0.16 2019/04/25 + * Version: @(#)hdc_esdi_at.c 1.0.17 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -211,7 +211,7 @@ next_sector(hdc_t *dev) static void -hdc_writew(uint16_t port, uint16_t val, void *priv) +hdc_writew(uint16_t port, uint16_t val, priv_t priv) { hdc_t *dev = (hdc_t *)priv; @@ -232,7 +232,7 @@ hdc_writew(uint16_t port, uint16_t val, void *priv) static void -hdc_write(uint16_t port, uint8_t val, void *priv) +hdc_write(uint16_t port, uint8_t val, priv_t priv) { hdc_t *dev = (hdc_t *)priv; @@ -406,7 +406,7 @@ hdc_write(uint16_t port, uint8_t val, void *priv) static uint16_t -hdc_readw(uint16_t port, void *priv) +hdc_readw(uint16_t port, priv_t priv) { hdc_t *dev = (hdc_t *)priv; uint16_t temp; @@ -437,7 +437,7 @@ hdc_readw(uint16_t port, void *priv) static uint8_t -hdc_read(uint16_t port, void *priv) +hdc_read(uint16_t port, priv_t priv) { hdc_t *dev = (hdc_t *)priv; uint8_t temp = 0xff; @@ -484,7 +484,7 @@ hdc_read(uint16_t port, void *priv) static void -hdc_callback(void *priv) +hdc_callback(priv_t priv) { hdc_t *dev = (hdc_t *)priv; drive_t *drive = &dev->drives[dev->drive_sel]; @@ -785,7 +785,26 @@ loadhd(hdc_t *dev, int hdd_num, int d, const wchar_t *fn) } -static void * +static void +wd1007vse1_close(priv_t priv) +{ + hdc_t *dev = (hdc_t *)priv; + drive_t *drive; + int d; + + for (d=0; d<2; d++) { + drive = &dev->drives[d]; + + hdd_image_close(drive->hdd_num); + } + + free(dev); + + ui_sb_icon_update(SB_DISK | HDD_BUS_ESDI, 0); +} + + +static priv_t wd1007vse1_init(const device_t *info, UNUSED(void *parent)) { hdc_t *dev; @@ -822,26 +841,7 @@ wd1007vse1_init(const device_t *info, UNUSED(void *parent)) timer_add(hdc_callback, dev, &dev->callback, &dev->callback); - return(dev); -} - - -static void -wd1007vse1_close(void *priv) -{ - hdc_t *dev = (hdc_t *)priv; - drive_t *drive; - int d; - - for (d=0; d<2; d++) { - drive = &dev->drives[d]; - - hdd_image_close(drive->hdd_num); - } - - free(dev); - - ui_sb_icon_update(SB_DISK | HDD_BUS_ESDI, 0); + return((priv_t)dev); } diff --git a/src/devices/disk/hdc_esdi_mca.c b/src/devices/disk/hdc_esdi_mca.c index 8976e8a..0f9e76b 100644 --- a/src/devices/disk/hdc_esdi_mca.c +++ b/src/devices/disk/hdc_esdi_mca.c @@ -52,7 +52,7 @@ * however, are auto-configured by the system software as * shown above. * - * Version: @(#)hdc_esdi_mca.c 1.0.17 2019/04/25 + * Version: @(#)hdc_esdi_mca.c 1.0.18 2019/05/13 * * Authors: Fred N. van Kempen, * Sarah Walker, @@ -128,7 +128,9 @@ typedef struct { uint32_t bios; rom_t bios_rom; - + + uint8_t pos_regs[8]; + uint8_t basic_ctrl; uint8_t status; uint8_t irq_status; @@ -138,36 +140,33 @@ typedef struct { uint16_t cmd_data[4]; int cmd_dev; - int status_pos, - status_len; + int command; + int cmd_state; - uint16_t status_data[256]; + int in_reset; + int64_t callback; + + uint32_t rba; + + struct { + int req_in_progress; + } cmds[3]; + + drive_t drives[2]; int data_pos; uint16_t data[256]; + int status_pos, + status_len; + uint16_t status_data[256]; + + int sector_pos, + sector_count; uint16_t sector_buffer[256][256]; - - int sector_pos; - int sector_count; - - int command; - int cmd_state; - - int in_reset; - int64_t callback; - - uint32_t rba; - - struct { - int req_in_progress; - } cmds[3]; - - drive_t drives[2]; - - uint8_t pos_regs[8]; } hdc_t; + #define STATUS_DMA_ENA (1 << 7) #define STATUS_IRQ_PENDING (1 << 6) #define STATUS_CMD_IN_PROGRESS (1 << 5) @@ -262,8 +261,8 @@ device_not_present(hdc_t *dev) dev->status_data[3] = 0; dev->status_data[4] = 0; dev->status_data[5] = 0; - dev->status_data[6] = 0; - dev->status_data[7] = 0; + dev->status_data[6] = 0; + dev->status_data[7] = 0; dev->status_data[8] = 0; dev->status = STATUS_IRQ | STATUS_STATUS_OUT_FULL; @@ -284,8 +283,8 @@ rba_out_of_range(hdc_t *dev) dev->status_data[3] = 0; dev->status_data[4] = 0; dev->status_data[5] = 0; - dev->status_data[6] = 0; - dev->status_data[7] = 0; + dev->status_data[6] = 0; + dev->status_data[7] = 0; dev->status_data[8] = 0; dev->status = STATUS_IRQ | STATUS_STATUS_OUT_FULL; @@ -332,10 +331,10 @@ complete_command_status(hdc_t *dev) else \ drive = &dev->drives[1]; \ } while (0) - + static void -hdc_callback(void *priv) +hdc_callback(priv_t priv) { hdc_t *dev = (hdc_t *)priv; drive_t *drive; @@ -382,7 +381,7 @@ hdc_callback(void *priv) dev->callback = ESDI_TIME; dev->data_pos = 0; break; - + case 1: if (!(dev->basic_ctrl & CTRL_DMA_ENA)) { dev->callback = ESDI_TIME; @@ -400,7 +399,7 @@ hdc_callback(void *priv) while (dev->data_pos < 256) { val = dma_channel_write(dev->dma, dev->data[dev->data_pos]); - + if (val == DMA_NODATA) { dev->callback = ESDI_TIME; return; @@ -436,7 +435,7 @@ hdc_callback(void *priv) device_not_present(dev); return; } - + switch (dev->cmd_state) { case 0: dev->rba = (dev->cmd_data[2] | (dev->cmd_data[3] << 16)) & 0x0fffffff; @@ -453,7 +452,7 @@ hdc_callback(void *priv) dev->irq_status = dev->cmd_dev | IRQ_DATA_TRANSFER_READY; dev->irq_in_progress = 1; set_irq(dev); - + dev->cmd_state = 1; dev->callback = ESDI_TIME; dev->data_pos = 0; @@ -468,7 +467,7 @@ hdc_callback(void *priv) while (dev->sector_pos < dev->sector_count) { while (dev->data_pos < 256) { val = dma_channel_read(dev->dma); - + if (val == DMA_NODATA) { dev->callback = ESDI_TIME; return; @@ -640,7 +639,7 @@ hdc_callback(void *priv) dev->callback = ESDI_TIME; dev->data_pos = 0; break; - + case 1: if (! (dev->basic_ctrl & CTRL_DMA_ENA)) { dev->callback = ESDI_TIME; @@ -649,7 +648,7 @@ hdc_callback(void *priv) while (dev->sector_pos < dev->sector_count) { while (dev->data_pos < 256) { val = dma_channel_read(dev->dma); - + if (val == DMA_NODATA) { dev->callback = ESDI_TIME; return; @@ -706,7 +705,7 @@ hdc_callback(void *priv) memcpy(dev->data, dev->sector_buffer[dev->sector_pos++], 512); while (dev->data_pos < 256) { val = dma_channel_write(dev->dma, dev->data[dev->data_pos]); - + if (val == DMA_NODATA) { dev->callback = ESDI_TIME; return; @@ -756,7 +755,7 @@ hdc_callback(void *priv) static uint8_t -hdc_read(uint16_t port, void *priv) +hdc_read(uint16_t port, priv_t priv) { hdc_t *dev = (hdc_t *)priv; uint8_t ret = 0xff; @@ -782,7 +781,7 @@ hdc_read(uint16_t port, void *priv) static void -hdc_write(uint16_t port, uint8_t val, void *priv) +hdc_write(uint16_t port, uint8_t val, priv_t priv) { hdc_t *dev = (hdc_t *)priv; @@ -843,13 +842,13 @@ hdc_write(uint16_t port, uint8_t val, void *priv) dev->cmd_pos = 0; dev->status_pos = 0; break; - + case ATTN_EOI: dev->irq_in_progress = 0; dev->status &= ~STATUS_IRQ; clear_irq(dev); break; - + default: DEBUG("ESDI: bad attention request %02x\n", val); } @@ -871,7 +870,7 @@ hdc_write(uint16_t port, uint8_t val, void *priv) dev->status &= ~STATUS_IRQ; clear_irq(dev); break; - + default: DEBUG("ESDI: bad attention request %02x\n", val); } @@ -889,7 +888,7 @@ hdc_write(uint16_t port, uint8_t val, void *priv) static uint16_t -hdc_readw(uint16_t port, void *priv) +hdc_readw(uint16_t port, priv_t priv) { hdc_t *dev = (hdc_t *)priv; uint16_t ret = 0xffff; @@ -908,13 +907,13 @@ hdc_readw(uint16_t port, void *priv) default: DEBUG("ESDI: readw from invalid port %04x\n", port); } - + return(ret); } static void -hdc_writew(uint16_t port, uint16_t val, void *priv) +hdc_writew(uint16_t port, uint16_t val, priv_t priv) { hdc_t *dev = (hdc_t *)priv; @@ -947,7 +946,7 @@ hdc_writew(uint16_t port, uint16_t val, void *priv) static uint8_t -hdc_mca_read(int port, void *priv) +hdc_mca_read(int port, priv_t priv) { hdc_t *dev = (hdc_t *)priv; uint8_t ret = dev->pos_regs[port & 7]; @@ -959,7 +958,7 @@ hdc_mca_read(int port, void *priv) static void -hdc_mca_write(int port, uint8_t val, void *priv) +hdc_mca_write(int port, uint8_t val, priv_t priv) { hdc_t *dev = (hdc_t *)priv; @@ -1074,7 +1073,26 @@ hdc_mca_write(int port, uint8_t val, void *priv) } -static void * +static void +esdi_close(priv_t priv) +{ + hdc_t *dev = (hdc_t *)priv; + drive_t *drive; + int d; + + dev->drives[0].present = dev->drives[1].present = 0; + + for (d = 0; d < ESDI_NUM; d++) { + drive = &dev->drives[d]; + + hdd_image_close(drive->hdd_num); + } + + free(dev); +} + + +static priv_t esdi_init(const device_t *info, UNUSED(void *parent)) { drive_t *drive; @@ -1140,26 +1158,7 @@ esdi_init(const device_t *info, UNUSED(void *parent)) /* Set the reply timer. */ timer_add(hdc_callback, dev, &dev->callback, &dev->callback); - return(dev); -} - - -static void -esdi_close(void *priv) -{ - hdc_t *dev = (hdc_t *)priv; - drive_t *drive; - int d; - - dev->drives[0].present = dev->drives[1].present = 0; - - for (d = 0; d < ESDI_NUM; d++) { - drive = &dev->drives[d]; - - hdd_image_close(drive->hdd_num); - } - - free(dev); + return((priv_t)dev); } diff --git a/src/devices/disk/hdc_ide.h b/src/devices/disk/hdc_ide.h index fcbf7c1..e698838 100644 --- a/src/devices/disk/hdc_ide.h +++ b/src/devices/disk/hdc_ide.h @@ -8,7 +8,7 @@ * * Definitions for the IDE module. * - * Version: @(#)hdc_ide.h 1.0.12 2019/05/03 + * Version: @(#)hdc_ide.h 1.0.13 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -128,16 +128,16 @@ extern void ide_irq_lower(ide_t *); extern void *ide_xtide_init(void); extern void ide_xtide_close(void); -extern void ide_writew(uint16_t addr, uint16_t val, void *priv); -extern void ide_write_devctl(uint16_t addr, uint8_t val, void *priv); -extern void ide_writeb(uint16_t addr, uint8_t val, void *priv); -extern uint8_t ide_readb(uint16_t addr, void *priv); -extern uint8_t ide_read_alt_status(uint16_t addr, void *priv); -extern uint16_t ide_readw(uint16_t addr, void *priv); -extern void ide_set_bus_master(int (*read)(int channel, uint8_t *data, int transfer_length, void *priv), - int (*write)(int channel, uint8_t *data, int transfer_length, void *priv), - void (*set_irq)(int channel, void *priv), - void *priv0, void *priv1); +extern void ide_writew(uint16_t addr, uint16_t val, priv_t priv); +extern void ide_write_devctl(uint16_t addr, uint8_t val, priv_t priv); +extern void ide_writeb(uint16_t addr, uint8_t val, priv_t priv); +extern uint8_t ide_readb(uint16_t addr, priv_t priv); +extern uint8_t ide_read_alt_status(uint16_t addr, priv_t priv); +extern uint16_t ide_readw(uint16_t addr, priv_t priv); +extern void ide_set_bus_master(int (*read)(int channel, uint8_t *data, int transfer_length, priv_t priv), + int (*write)(int channel, uint8_t *data, int transfer_length, priv_t priv), + void (*set_irq)(int channel, priv_t priv), + priv_t priv0, priv_t priv1); extern void win_cdrom_eject(uint8_t id); @@ -158,10 +158,10 @@ extern void secondary_ide_check(void); extern void ide_padstr(char *str, const char *src, int len); extern void ide_padstr8(uint8_t *buf, int buf_size, const char *src); -extern int (*ide_bus_master_read)(int channel, uint8_t *data, int transfer_length, void *priv); -extern int (*ide_bus_master_write)(int channel, uint8_t *data, int transfer_length, void *priv); -extern void (*ide_bus_master_set_irq)(int channel, void *priv); -extern void *ide_bus_master_priv[2]; +extern int (*ide_bus_master_read)(int channel, uint8_t *data, int transfer_length, priv_t priv); +extern int (*ide_bus_master_write)(int channel, uint8_t *data, int transfer_length, priv_t priv); +extern void (*ide_bus_master_set_irq)(int channel, priv_t priv); +extern priv_t ide_bus_master_priv[2]; extern void ide_enable_pio_override(void); extern void ide_allocate_buffer(ide_t *dev); diff --git a/src/devices/disk/hdc_ide_ata.c b/src/devices/disk/hdc_ide_ata.c index 42429bd..820f2cf 100644 --- a/src/devices/disk/hdc_ide_ata.c +++ b/src/devices/disk/hdc_ide_ata.c @@ -14,7 +14,7 @@ * Devices currently implemented are hard disk, CD-ROM and * ZIP IDE/ATAPI devices. * - * Version: @(#)hdc_ide_ata.c 1.0.32 2019/04/21 + * Version: @(#)hdc_ide_ata.c 1.0.33 2019/05/13 * * Authors: Miran Grca, * Sarah Walker, @@ -145,10 +145,10 @@ static ide_board_t *ide_boards[4]; static int pio_override = 0; ide_t *ide_drives[IDE_NUM+XTIDE_NUM]; -int (*ide_bus_master_read)(int channel, uint8_t *data, int transfer_length, void *priv); -int (*ide_bus_master_write)(int channel, uint8_t *data, int transfer_length, void *priv); -void (*ide_bus_master_set_irq)(int channel, void *priv); -void *ide_bus_master_priv[2]; +int (*ide_bus_master_read)(int channel, uint8_t *data, int transfer_length, priv_t priv); +int (*ide_bus_master_write)(int channel, uint8_t *data, int transfer_length, priv_t priv); +void (*ide_bus_master_set_irq)(int channel, priv_t priv); +priv_t ide_bus_master_priv[2]; int ide_inited = 0; int ide_sec_optional = 0; int ide_ter_enabled = 0, ide_qua_enabled = 0; @@ -156,7 +156,7 @@ int ide_ter_enabled = 0, ide_qua_enabled = 0; static uint16_t ide_base_main[4] = { 0x1f0, 0x170, 0x168, 0x1e8 }; static uint16_t ide_side_main[4] = { 0x3f6, 0x376, 0x36e, 0x3ee }; -static void ide_callback(void *priv); +static void ide_callback(priv_t priv); #define IDE_TIME (20LL * TIMER_USEC) / 3LL @@ -368,7 +368,8 @@ ide_padstr(char *str, const char *src, int len) * this length will be padded with spaces. * @param src Source string */ -void ide_padstr8(uint8_t *buf, int buf_size, const char *src) +void +ide_padstr8(uint8_t *buf, int buf_size, const char *src) { int i; @@ -1020,9 +1021,9 @@ ide_write_data(ide_t *ide, uint32_t val, int length) void -ide_writew(uint16_t addr, uint16_t val, void *priv) +ide_writew(uint16_t addr, uint16_t val, priv_t priv) { - ide_board_t *dev = (ide_board_t *) priv; + ide_board_t *dev = (ide_board_t *)priv; ide_t *ide; int ch; @@ -1045,9 +1046,9 @@ ide_writew(uint16_t addr, uint16_t val, void *priv) static void -ide_writel(uint16_t addr, uint32_t val, void *priv) +ide_writel(uint16_t addr, uint32_t val, priv_t priv) { - ide_board_t *dev = (ide_board_t *) priv; + ide_board_t *dev = (ide_board_t *)priv; ide_t *ide; int ch; @@ -1071,9 +1072,9 @@ ide_writel(uint16_t addr, uint32_t val, void *priv) void -ide_write_devctl(uint16_t addr, uint8_t val, void *priv) +ide_write_devctl(uint16_t addr, uint8_t val, priv_t priv) { - ide_board_t *dev = (ide_board_t *) priv; + ide_board_t *dev = (ide_board_t *)priv; scsi_device_data_t *atapi; ide_t *ide, *ide_other; int ch; @@ -1115,9 +1116,9 @@ ide_write_devctl(uint16_t addr, uint8_t val, void *priv) void -ide_writeb(uint16_t addr, uint8_t val, void *priv) +ide_writeb(uint16_t addr, uint8_t val, priv_t priv) { - ide_board_t *dev = (ide_board_t *) priv; + ide_board_t *dev = (ide_board_t *)priv; scsi_device_data_t *atapi, *atapi_other; ide_t *ide, *ide_other; int ch; @@ -1569,9 +1570,9 @@ ide_status(ide_t *ide, int ch) uint8_t -ide_readb(uint16_t addr, void *priv) +ide_readb(uint16_t addr, priv_t priv) { - ide_board_t *dev = (ide_board_t *) priv; + ide_board_t *dev = (ide_board_t *)priv; scsi_device_data_t *atapi; int ch; ide_t *ide; @@ -1670,11 +1671,11 @@ ide_readb(uint16_t addr, void *priv) uint8_t -ide_read_alt_status(uint16_t addr, void *priv) +ide_read_alt_status(uint16_t addr, priv_t priv) { uint8_t temp = 0xff; - ide_board_t *dev = (ide_board_t *) priv; + ide_board_t *dev = (ide_board_t *)priv; ide_t *ide; int ch; @@ -1692,9 +1693,9 @@ ide_read_alt_status(uint16_t addr, void *priv) uint16_t -ide_readw(uint16_t addr, void *priv) +ide_readw(uint16_t addr, priv_t priv) { - ide_board_t *dev = (ide_board_t *) priv; + ide_board_t *dev = (ide_board_t *)priv; uint16_t temp = 0xffff; ide_t *ide; int ch; @@ -1714,9 +1715,9 @@ ide_readw(uint16_t addr, void *priv) static uint32_t -ide_readl(uint16_t addr, void *priv) +ide_readl(uint16_t addr, priv_t priv) { - ide_board_t *dev = (ide_board_t *) priv; + ide_board_t *dev = (ide_board_t *)priv; uint32_t temp = 0xffffffff; uint16_t temp2; ide_t *ide; @@ -1738,9 +1739,9 @@ ide_readl(uint16_t addr, void *priv) static void -ide_callback(void *priv) +ide_callback(priv_t priv) { - ide_board_t *dev = (ide_board_t *) priv; + ide_board_t *dev = (ide_board_t *)priv; scsi_device_data_t *atapi, *atapi_other; ide_t *ide, *ide_other; int snum, ret, ch; @@ -2114,7 +2115,7 @@ ide_callback(void *priv) ide->cfg_spt = ide->secount; ide->cfg_hpc = ide->head + 1; } - ide->command = 0x00; + ide->command = 0x00; ide->atastat = DRDY_STAT | DSC_STAT; ide->error = 1; ide_irq_raise(ide); @@ -2311,32 +2312,36 @@ ide_set_side(int controller, uint16_t port) } -static void * +static priv_t ide_ter_init(const device_t *info, UNUSED(void *parent)) { - ide_boards[2] = (ide_board_t *)mem_alloc(sizeof(ide_board_t)); - memset(ide_boards[2], 0, sizeof(ide_board_t)); + ide_board_t *dev; - ide_boards[2]->irq = device_get_config_int("irq"); - ide_boards[2]->cur_dev = 4; + dev = (ide_board_t *)mem_alloc(sizeof(ide_board_t)); + memset(dev, 0x00, sizeof(ide_board_t)); + + dev->irq = device_get_config_int("irq"); + dev->cur_dev = 4; + ide_boards[2] = dev; ide_set_handlers(2); - timer_add(ide_callback, ide_boards[2], - &ide_boards[2]->callback, &ide_boards[2]->callback); + timer_add(ide_callback, dev, &dev->callback, &dev->callback); ide_board_init(2); - return(ide_drives); + return((priv_t)dev); } /* Close a standalone IDE unit. */ static void -ide_ter_close(void *priv) +ide_ter_close(priv_t priv) { - if (ide_boards[2]) { - free(ide_boards[2]); + ide_board_t *dev = (ide_board_t *)priv; + + if (dev) { + free(dev); ide_boards[2] = NULL; ide_board_close(2); @@ -2344,32 +2349,36 @@ ide_ter_close(void *priv) } -static void * +static priv_t ide_qua_init(const device_t *info, UNUSED(void *parent)) { - ide_boards[3] = (ide_board_t *)mem_alloc(sizeof(ide_board_t)); - memset(ide_boards[3], 0, sizeof(ide_board_t)); + ide_board_t *dev; - ide_boards[3]->irq = device_get_config_int("irq"); - ide_boards[3]->cur_dev = 6; + dev = (ide_board_t *)mem_alloc(sizeof(ide_board_t)); + memset(dev, 0x00, sizeof(ide_board_t)); + + dev->irq = device_get_config_int("irq"); + dev->cur_dev = 6; + ide_boards[3] = dev; ide_set_handlers(3); - timer_add(ide_callback, ide_boards[3], - &ide_boards[3]->callback, &ide_boards[3]->callback); + timer_add(ide_callback, dev, &dev->callback, &dev->callback); ide_board_init(3); - return(ide_drives); + return((priv_t)dev); } /* Close a standalone IDE unit. */ static void -ide_qua_close(void *priv) +ide_qua_close(priv_t priv) { - if (ide_boards[3]) { - free(ide_boards[3]); + ide_board_t *dev = (ide_board_t *)priv; + + if (dev) { + free(dev); ide_boards[3] = NULL; ide_board_close(3); @@ -2389,21 +2398,24 @@ ide_clear_bus_master(void) void * ide_xtide_init(void) { + ide_board_t *dev; + ide_clear_bus_master(); - if (!ide_boards[0]) { - ide_boards[0] = (ide_board_t *)mem_alloc(sizeof(ide_board_t)); - memset(ide_boards[0], 0, sizeof(ide_board_t)); - ide_boards[0]->cur_dev = 0; + if (! ide_boards[0]) { + dev = (ide_board_t *)mem_alloc(sizeof(ide_board_t)); + memset(dev, 0x00, sizeof(ide_board_t)); + dev->cur_dev = 0; + ide_boards[0] = dev; - timer_add(ide_callback, ide_boards[0], - &ide_boards[0]->callback, &ide_boards[0]->callback); + timer_add(ide_callback, dev, &dev->callback, &dev->callback); ide_board_init(0); - } - ide_boards[0]->irq = -1; + } else + dev = ide_boards[0]; + dev->irq = -1; - return ide_boards[0]; + return((priv_t)dev); } @@ -2420,10 +2432,10 @@ ide_xtide_close(void) void -ide_set_bus_master(int (*read)(int channel, uint8_t *data, int transfer_length, void *priv), - int (*write)(int channel, uint8_t *data, int transfer_length, void *priv), - void (*set_irq)(int channel, void *priv), - void *priv0, void *priv1) +ide_set_bus_master(int (*read)(int channel, uint8_t *data, int transfer_length, priv_t priv), + int (*write)(int channel, uint8_t *data, int transfer_length, priv_t priv), + void (*set_irq)(int channel, priv_t priv), + priv_t priv0, priv_t priv1) { ide_bus_master_read = read; ide_bus_master_write = write; @@ -2443,8 +2455,8 @@ secondary_ide_check(void) } -static void * -ide_init(const device_t *info, UNUSED(void *parent)) +static priv_t +ide_init(const device_t *info, void *parent) { DEBUG("Initializing IDE...\n"); @@ -2505,7 +2517,7 @@ ide_init(const device_t *info, UNUSED(void *parent)) break; } - return(ide_drives); + return((priv_t)parent); } @@ -2541,7 +2553,7 @@ ide_drive_reset(int d) /* Reset a standalone IDE unit. */ static void -ide_reset(void *p) +ide_reset(priv_t priv) { int d; @@ -2561,7 +2573,7 @@ ide_reset(void *p) /* Close a standalone IDE unit. */ static void -ide_close(void *priv) +ide_close(priv_t priv) { DEBUG("Closing IDE...\n"); diff --git a/src/devices/disk/hdc_ide_xta.c b/src/devices/disk/hdc_ide_xta.c index 68e07eb..0bd642d 100644 --- a/src/devices/disk/hdc_ide_xta.c +++ b/src/devices/disk/hdc_ide_xta.c @@ -46,7 +46,7 @@ * * NOTE: The XTA interface is 0-based for sector numbers !! * - * Version: @(#)hdc_ide_xta.c 1.0.14 2019/04/25 + * Version: @(#)hdc_ide_xta.c 1.0.15 2019/05/13 * * Author: Fred N. van Kempen, * @@ -430,7 +430,7 @@ do_fmt: /* Execute the DCB we just received. */ static void -hdc_callback(void *priv) +hdc_callback(priv_t priv) { hdc_t *dev = (hdc_t *)priv; dcb_t *dcb = &dev->dcb; @@ -907,7 +907,7 @@ do_recv: /* Read one of the controller registers. */ static uint8_t -hdc_read(uint16_t port, void *priv) +hdc_read(uint16_t port, priv_t priv) { hdc_t *dev = (hdc_t *)priv; uint8_t ret = 0xff; @@ -954,7 +954,7 @@ hdc_read(uint16_t port, void *priv) /* Write to one of the controller registers. */ static void -hdc_write(uint16_t port, uint8_t val, void *priv) +hdc_write(uint16_t port, uint8_t val, priv_t priv) { hdc_t *dev = (hdc_t *)priv; @@ -1013,7 +1013,30 @@ hdc_write(uint16_t port, uint8_t val, void *priv) } -static void * +static void +xta_close(priv_t priv) +{ + hdc_t *dev = (hdc_t *)priv; + drive_t *drive; + int d; + + /* Remove the I/O handler. */ + io_removehandler(dev->base, 4, + hdc_read,NULL,NULL, hdc_write,NULL,NULL, dev); + + /* Close all disks and their images. */ + for (d = 0; d < XTA_NUM; d++) { + drive = &dev->drives[d]; + + hdd_image_close(drive->hdd_num); + } + + /* Release the device. */ + free(dev); +} + + +static priv_t xta_init(const device_t *info, UNUSED(void *parent)) { drive_t *drive; @@ -1095,8 +1118,7 @@ xta_init(const device_t *info, UNUSED(void *parent)) } /* Enable the I/O block. */ - io_sethandler(dev->base, 4, - hdc_read,NULL,NULL, hdc_write,NULL,NULL, dev); + io_sethandler(dev->base, 4, hdc_read,NULL,NULL, hdc_write,NULL,NULL, dev); /* Load BIOS if it has one. */ if (dev->rom_addr != 0x000000) @@ -1106,30 +1128,7 @@ xta_init(const device_t *info, UNUSED(void *parent)) /* Create a timer for command delays. */ timer_add(hdc_callback, dev, &dev->callback, &dev->callback); - return(dev); -} - - -static void -xta_close(void *priv) -{ - hdc_t *dev = (hdc_t *)priv; - drive_t *drive; - int d; - - /* Remove the I/O handler. */ - io_removehandler(dev->base, 4, - hdc_read,NULL,NULL, hdc_write,NULL,NULL, dev); - - /* Close all disks and their images. */ - for (d = 0; d < XTA_NUM; d++) { - drive = &dev->drives[d]; - - hdd_image_close(drive->hdd_num); - } - - /* Release the device. */ - free(dev); + return((priv_t)dev); } diff --git a/src/devices/disk/hdc_st506_at.c b/src/devices/disk/hdc_st506_at.c index bfd2873..5460d7e 100644 --- a/src/devices/disk/hdc_st506_at.c +++ b/src/devices/disk/hdc_st506_at.c @@ -12,7 +12,7 @@ * based design. Most cards were WD1003-WA2 or -WAH, where the * -WA2 cards had a floppy controller as well (to save space.) * - * Version: @(#)hdc_st506_at.c 1.0.15 2019/04/25 + * Version: @(#)hdc_st506_at.c 1.0.16 2019/05/13 * * Authors: Fred N. van Kempen, * Sarah Walker, @@ -361,7 +361,7 @@ hdc_cmd(hdc_t *dev, uint8_t val) static void -hdc_writew(uint16_t port, uint16_t val, void *priv) +hdc_writew(uint16_t port, uint16_t val, priv_t priv) { hdc_t *dev = (hdc_t *)priv; @@ -382,7 +382,7 @@ hdc_writew(uint16_t port, uint16_t val, void *priv) static void -hdc_write(uint16_t port, uint8_t val, void *priv) +hdc_write(uint16_t port, uint8_t val, priv_t priv) { hdc_t *dev = (hdc_t *)priv; @@ -454,7 +454,7 @@ hdc_write(uint16_t port, uint8_t val, void *priv) static uint16_t -hdc_readw(uint16_t port, void *priv) +hdc_readw(uint16_t port, priv_t priv) { hdc_t *dev = (hdc_t *)priv; uint16_t ret; @@ -484,7 +484,7 @@ hdc_readw(uint16_t port, void *priv) static uint8_t -hdc_read(uint16_t port, void *priv) +hdc_read(uint16_t port, priv_t priv) { hdc_t *dev = (hdc_t *)priv; uint8_t ret = 0xff; @@ -549,7 +549,7 @@ do_seek(hdc_t *dev) static void -do_callback(void *priv) +do_callback(priv_t priv) { hdc_t *dev = (hdc_t *)priv; drive_t *drive = &dev->drives[dev->drvsel]; @@ -696,7 +696,25 @@ loadhd(hdc_t *dev, int c, int d, const wchar_t *fn) } -static void * +static void +st506_close(priv_t priv) +{ + hdc_t *dev = (hdc_t *)priv; + int d; + + for (d = 0; d < 2; d++) { + drive_t *drive = &dev->drives[d]; + + hdd_image_close(drive->hdd_num); + } + + free(dev); + + ui_sb_icon_update(SB_DISK|HDD_BUS_ST506, 0); +} + + +static priv_t st506_init(const device_t *info, UNUSED(void *parent)) { hdc_t *dev; @@ -733,25 +751,7 @@ st506_init(const device_t *info, UNUSED(void *parent)) timer_add(do_callback, dev, &dev->callback, &dev->callback); - return(dev); -} - - -static void -st506_close(void *priv) -{ - hdc_t *dev = (hdc_t *)priv; - int d; - - for (d = 0; d < 2; d++) { - drive_t *drive = &dev->drives[d]; - - hdd_image_close(drive->hdd_num); - } - - free(dev); - - ui_sb_icon_update(SB_DISK|HDD_BUS_ST506, 0); + return((priv_t)dev); } diff --git a/src/devices/disk/hdc_st506_xt.c b/src/devices/disk/hdc_st506_xt.c index dfe166e..2c6f698 100644 --- a/src/devices/disk/hdc_st506_xt.c +++ b/src/devices/disk/hdc_st506_xt.c @@ -41,7 +41,7 @@ * Since all controllers (including the ones made by DTC) use * (mostly) the same API, we keep them all in this module. * - * Version: @(#)hdc_st506_xt.c 1.0.20 2019/05/05 + * Version: @(#)hdc_st506_xt.c 1.0.21 2019/05/13 * * Authors: Fred N. van Kempen, * Sarah Walker, @@ -385,7 +385,7 @@ get_chs(hdc_t *dev, drive_t *drive) static void -st506_callback(void *priv) +st506_callback(priv_t priv) { hdc_t *dev = (hdc_t *)priv; drive_t *drive; @@ -1157,7 +1157,7 @@ st506_callback(void *priv) /* Read from one of the registers. */ static uint8_t -st506_read(uint16_t port, void *priv) +st506_read(uint16_t port, priv_t priv) { hdc_t *dev = (hdc_t *)priv; uint8_t ret = 0xff; @@ -1201,7 +1201,7 @@ st506_read(uint16_t port, void *priv) /* Write to one of the registers. */ static void -st506_write(uint16_t port, uint8_t val, void *priv) +st506_write(uint16_t port, uint8_t val, priv_t priv) { hdc_t *dev = (hdc_t *)priv; @@ -1254,7 +1254,7 @@ st506_write(uint16_t port, uint8_t val, void *priv) /* Write to ROM (or scratchpad RAM.) */ static void -mem_write(uint32_t addr, uint8_t val, void *priv) +mem_write(uint32_t addr, uint8_t val, priv_t priv) { hdc_t *dev = (hdc_t *)priv; uint32_t ptr, mask = 0; @@ -1280,7 +1280,7 @@ mem_write(uint32_t addr, uint8_t val, void *priv) static uint8_t -mem_read(uint32_t addr, void *priv) +mem_read(uint32_t addr, priv_t priv) { hdc_t *dev = (hdc_t *)priv; uint32_t ptr, mask = 0; @@ -1438,7 +1438,29 @@ set_switches(hdc_t *dev) } -static void * +static void +st506_close(priv_t priv) +{ + hdc_t *dev = (hdc_t *)priv; + drive_t *drive; + int d; + + for (d = 0; d < ST506_NUM; d++) { + drive = &dev->drives[d]; + + hdd_image_close(drive->hdd_num); + } + + if (dev->bios_rom.rom != NULL) { + free(dev->bios_rom.rom); + dev->bios_rom.rom = NULL; + } + + free(dev); +} + + +static priv_t st506_init(const device_t *info, UNUSED(void *parent)) { const wchar_t *fn; @@ -1566,29 +1588,7 @@ st506_init(const device_t *info, UNUSED(void *parent)) dev->drives[c].cfg_spt = dev->drives[c].spt; } - return(dev); -} - - -static void -st506_close(void *priv) -{ - hdc_t *dev = (hdc_t *)priv; - drive_t *drive; - int d; - - for (d = 0; d < ST506_NUM; d++) { - drive = &dev->drives[d]; - - hdd_image_close(drive->hdd_num); - } - - if (dev->bios_rom.rom != NULL) { - free(dev->bios_rom.rom); - dev->bios_rom.rom = NULL; - } - - free(dev); + return((priv_t)dev); } diff --git a/src/devices/disk/hdc_xtide.c b/src/devices/disk/hdc_xtide.c index 2ad61fe..72e4cb9 100644 --- a/src/devices/disk/hdc_xtide.c +++ b/src/devices/disk/hdc_xtide.c @@ -24,7 +24,7 @@ * FIXME: Make sure this works with the new IDE stuff, the AT and PS/2 * controllers do not have dev->ide set to anything... * - * Version: @(#)hdc_xtide.c 1.0.12 2019/04/25 + * Version: @(#)hdc_xtide.c 1.0.13 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -82,7 +82,7 @@ typedef struct { static void -hdc_write(uint16_t port, uint8_t val, void *priv) +hdc_write(uint16_t port, uint8_t val, priv_t priv) { hdc_t *dev = (hdc_t *)priv; @@ -113,7 +113,7 @@ hdc_write(uint16_t port, uint8_t val, void *priv) static uint8_t -hdc_read(uint16_t port, void *priv) +hdc_read(uint16_t port, priv_t priv) { hdc_t *dev = (hdc_t *)priv; uint16_t tempw = 0xffff; @@ -150,7 +150,18 @@ hdc_read(uint16_t port, void *priv) } -static void * +static void +xtide_close(priv_t priv) +{ + hdc_t *dev = (hdc_t *)priv; + + free(dev); + + ide_xtide_close(); +} + + +static priv_t xtide_init(const device_t *info, UNUSED(void *parent)) { int rom_sz = 0; @@ -192,18 +203,7 @@ xtide_init(const device_t *info, UNUSED(void *parent)) io_sethandler(io, 16, hdc_read,NULL,NULL, hdc_write,NULL,NULL, dev); - return(dev); -} - - -static void -xtide_close(void *priv) -{ - hdc_t *dev = (hdc_t *)priv; - - free(dev); - - ide_xtide_close(); + return((priv_t)dev); } diff --git a/src/devices/floppy/fdc.c b/src/devices/floppy/fdc.c index 06de91b..10a53cb 100644 --- a/src/devices/floppy/fdc.c +++ b/src/devices/floppy/fdc.c @@ -9,7 +9,7 @@ * Implementation of the NEC uPD-765 and compatible floppy disk * controller. * - * Version: @(#)fdc.c 1.0.22 2019/04/27 + * Version: @(#)fdc.c 1.0.23 2019/05/13 * * Authors: Miran Grca, * Sarah Walker, @@ -111,7 +111,7 @@ int floppymodified[FDD_NUM]; int floppyrate[FDD_NUM]; -static void fdc_callback(void *priv); +static void fdc_callback(priv_t priv); #ifdef _LOGGING @@ -139,7 +139,7 @@ fdc_get_current_drive(void) void -fdc_ctrl_reset(void *priv) +fdc_ctrl_reset(priv_t priv) { fdc_t *fdc = (fdc_t *)priv; @@ -347,7 +347,7 @@ fdc_int(fdc_t *fdc) static void -fdc_watchdog_poll(void *priv) +fdc_watchdog_poll(priv_t priv) { fdc_t *fdc = (fdc_t *)priv; @@ -721,7 +721,7 @@ fdc_sis(fdc_t *fdc) static void -fdc_write(uint16_t addr, uint8_t val, void *priv) +fdc_write(uint16_t addr, uint8_t val, priv_t priv) { fdc_t *fdc = (fdc_t *) priv; @@ -1244,7 +1244,7 @@ fdc_write(uint16_t addr, uint8_t val, void *priv) uint8_t -fdc_read(uint16_t addr, void *priv) +fdc_read(uint16_t addr, priv_t priv) { fdc_t *fdc = (fdc_t *)priv; uint8_t ret = 0xff; @@ -1498,7 +1498,7 @@ fdc_no_dma_end(fdc_t *fdc, int compare) static void -fdc_callback(void *priv) +fdc_callback(priv_t priv) { fdc_t *fdc = (fdc_t *)priv; int compare = 0; @@ -2187,7 +2187,7 @@ fdc_remove(fdc_t *fdc) void -fdc_reset(void *priv) +fdc_reset(priv_t priv) { fdc_t *fdc = (fdc_t *)priv; uint8_t default_rwc; @@ -2248,7 +2248,7 @@ fdc_reset(void *priv) static void -fdc_close(void *priv) +fdc_close(priv_t priv) { fdc_t *fdc = (fdc_t *)priv; @@ -2264,7 +2264,7 @@ fdc_close(void *priv) } -static void * +static priv_t fdc_init(const device_t *info, UNUSED(void *parent)) { fdc_t *fdc; @@ -2297,7 +2297,7 @@ fdc_init(const device_t *info, UNUSED(void *parent)) fdc_reset(fdc); - return(fdc); + return((priv_t)fdc); } diff --git a/src/devices/floppy/fdc.h b/src/devices/floppy/fdc.h index f5eff55..745f40a 100644 --- a/src/devices/floppy/fdc.h +++ b/src/devices/floppy/fdc.h @@ -6,10 +6,9 @@ * * This file is part of the VARCem Project. * - * Implementation of the NEC uPD-765 and compatible floppy disk - * controller. + * Definitions for the floppy disk controller driver. * - * Version: @(#)fdc.h 1.0.6 2019/04/27 + * Version: @(#)fdc.h 1.0.8 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -190,8 +189,8 @@ extern void fdc_sectorid(fdc_t *fdc, uint8_t track, uint8_t side, uint8_t sector, uint8_t size, uint8_t crc1, uint8_t crc2); -extern uint8_t fdc_read(uint16_t addr, void *priv); -extern void fdc_reset(void *priv); +extern uint8_t fdc_read(uint16_t addr, priv_t priv); +extern void fdc_reset(priv_t priv); extern uint8_t fdc_get_current_drive(void); diff --git a/src/devices/input/keyboard.h b/src/devices/input/keyboard.h index b439701..0644fc3 100644 --- a/src/devices/input/keyboard.h +++ b/src/devices/input/keyboard.h @@ -8,7 +8,7 @@ * * Definitions for the keyboard interface. * - * Version: @(#)keyboard.h 1.0.14 2019/04/27 + * Version: @(#)keyboard.h 1.0.15 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -126,16 +126,16 @@ extern void keyboard_cab(void); extern int keyboard_isfsexit(void); extern int keyboard_ismsexit(void); -extern void keyboard_xt_set_funcs(void *arg, - uint8_t (*func)(void *), void *priv); -extern void keyboard_at_set_funcs(void *arg, - uint8_t (*rfunc)(void *), - void (*wfunc)(void *, uint8_t), - void *priv); +extern void keyboard_xt_set_funcs(priv_t arg, + uint8_t (*func)(priv_t), priv_t priv); +extern void keyboard_at_set_funcs(priv_t arg, + uint8_t (*rfunc)(priv_t), + void (*wfunc)(priv_t, uint8_t), + priv_t priv); extern void keyboard_at_adddata_keyboard_raw(uint8_t val); extern void keyboard_at_adddata_mouse(uint8_t val); -extern void keyboard_at_set_mouse(void (*mouse_write)(uint8_t val,void *), void *); +extern void keyboard_at_set_mouse(void (*mouse_write)(uint8_t val,priv_t), priv_t); extern uint8_t keyboard_at_get_mouse_scan(void); extern void keyboard_at_set_mouse_scan(uint8_t val); diff --git a/src/devices/input/keyboard_at.c b/src/devices/input/keyboard_at.c index ab401db..2f853f8 100644 --- a/src/devices/input/keyboard_at.c +++ b/src/devices/input/keyboard_at.c @@ -16,7 +16,7 @@ * it either will not process ctrl-alt-esc, or it will not do * ANY input. * - * Version: @(#)keyboard_at.c 1.0.27 2019/04/30 + * Version: @(#)keyboard_at.c 1.0.28 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -67,13 +67,14 @@ #include "../../plat.h" #include "keyboard.h" -#define USE_SET1 0 -#define USE_IGNORE 0 - //FIXME: get rid of this! #include "../../machines/m_tosh3100e.h" +#define USE_SET1 0 +#define USE_IGNORE 0 + + #define STAT_PARITY 0x80 #define STAT_RTIMEOUT 0x40 #define STAT_TTIMEOUT 0x20 @@ -117,7 +118,7 @@ #define KBC_VENDOR(x) ((x)->flags & KBC_VEN_MASK) -typedef struct { +typedef struct atkbd { int initialized; int want60, wantirq, @@ -154,13 +155,13 @@ typedef struct { int64_t pulse_cb; uint8_t ami_stat; - uint8_t (*write60_ven)(void *p, uint8_t val); - uint8_t (*write64_ven)(void *p, uint8_t val); + uint8_t (*write60_ven)(struct atkbd *, uint8_t val); + uint8_t (*write64_ven)(struct atkbd *, uint8_t val); /* Custom machine-dependent keyboard stuff. */ - uint8_t (*read_func)(void *priv); - void (*write_func)(void *priv, uint8_t val); - void *func_priv; + uint8_t (*read_func)(priv_t priv); + void (*write_func)(priv_t priv, uint8_t val); + priv_t func_priv; } atkbd_t; @@ -183,8 +184,8 @@ static uint8_t key_queue[16]; static int key_queue_start = 0, key_queue_end = 0; static uint8_t mouse_queue[16]; -static void (*mouse_write)(uint8_t val, void *priv) = NULL; -static void *mouse_p = NULL; +static void (*mouse_write)(uint8_t val, priv_t priv) = NULL; +static priv_t mouse_p = NULL; static uint8_t sc_or = 0; static atkbd_t *SavedKbd = NULL; // FIXME: remove!!! --FvK @@ -1759,7 +1760,7 @@ set_scancode_map(atkbd_t *dev) static void -kbd_poll(void *priv) +kbd_poll(priv_t priv) { atkbd_t *dev = (atkbd_t *)priv; @@ -2159,7 +2160,7 @@ pulse_output(atkbd_t *dev, uint8_t mask) static void -pulse_poll(void *priv) +pulse_poll(priv_t priv) { atkbd_t *dev = (atkbd_t *)priv; @@ -2194,9 +2195,8 @@ set_enable_mouse(atkbd_t *dev, uint8_t enable) static uint8_t -write64_generic(void *priv, uint8_t val) +write64_generic(atkbd_t *dev, uint8_t val) { - atkbd_t *dev = (atkbd_t *)priv; uint8_t current_drive; switch (val) { @@ -2293,11 +2293,9 @@ write64_generic(void *priv, uint8_t val) static uint8_t -write60_acer(void *priv, uint8_t val) +write60_acer(atkbd_t *dev, uint8_t val) { #if 0 - atkbd_t *dev = (atkbd_t *)priv; - switch(dev->command) { case 0xc0: /* sent by Acer V30 BIOS */ return 0; @@ -2309,10 +2307,8 @@ write60_acer(void *priv, uint8_t val) static uint8_t -write64_acer(void *priv, uint8_t val) +write64_acer(atkbd_t *dev, uint8_t val) { - atkbd_t *dev = (atkbd_t *)priv; - INFO("ACER: write64(%02x, %02x)\n", dev->command, val); #if 0 @@ -2327,10 +2323,8 @@ write64_acer(void *priv, uint8_t val) static uint8_t -write60_ami(void *priv, uint8_t val) +write60_ami(atkbd_t *dev, uint8_t val) { - atkbd_t *dev = (atkbd_t *)priv; - switch(dev->command) { /* 0x40 - 0x5F are aliases for 0x60-0x7F */ case 0x40: case 0x41: case 0x42: case 0x43: @@ -2369,10 +2363,8 @@ write60_ami(void *priv, uint8_t val) static uint8_t -write64_ami(void *priv, uint8_t val) +write64_ami(atkbd_t *dev, uint8_t val) { - atkbd_t *dev = (atkbd_t *)priv; - switch (val) { case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07: @@ -2544,10 +2536,8 @@ write64_ami(void *priv, uint8_t val) static uint8_t -write64_ibm_mca(void *priv, uint8_t val) +write64_ibm_mca(atkbd_t *dev, uint8_t val) { - atkbd_t *dev = (atkbd_t *)priv; - switch (val) { case 0xc1: /*Copy bits 0 to 3 of input port to status bits 4 to 7*/ DEBUG("ATkbd: copy bits 0 to 3 of input port to status bits 4 to 7\n"); @@ -2579,10 +2569,8 @@ write64_ibm_mca(void *priv, uint8_t val) static uint8_t -write60_quadtel(void *priv, uint8_t val) +write60_quadtel(atkbd_t *dev, uint8_t val) { - atkbd_t *dev = (atkbd_t *)priv; - switch(dev->command) { case 0xcf: /*??? - sent by MegaPC BIOS*/ DEBUG("ATkbd: ??? - sent by MegaPC BIOS\n"); @@ -2594,10 +2582,8 @@ write60_quadtel(void *priv, uint8_t val) static uint8_t -write64_quadtel(void *priv, uint8_t val) +write64_quadtel(atkbd_t *dev, uint8_t val) { - atkbd_t *dev = (atkbd_t *)priv; - switch (val) { case 0xaf: DEBUG("ATkbd: bad KBC command AF\n"); @@ -2614,10 +2600,8 @@ write64_quadtel(void *priv, uint8_t val) static uint8_t -write60_toshiba(void *priv, uint8_t val) +write60_toshiba(atkbd_t *dev, uint8_t val) { - atkbd_t *dev = (atkbd_t *)priv; - switch(dev->command) { case 0xb6: /* T3100e - set color/mono switch */ t3100e_mono_set(dev->func_priv, val); @@ -2629,10 +2613,8 @@ write60_toshiba(void *priv, uint8_t val) static uint8_t -write64_toshiba(void *priv, uint8_t val) +write64_toshiba(atkbd_t *dev, uint8_t val) { - atkbd_t *dev = (atkbd_t *)priv; - switch (val) { case 0xaf: DEBUG("ATkbd: bad KBC command AF\n"); @@ -2700,7 +2682,7 @@ write64_toshiba(void *priv, uint8_t val) static void -kbd_write(uint16_t port, uint8_t val, void *priv) +kbd_write(uint16_t port, uint8_t val, priv_t priv) { atkbd_t *dev = (atkbd_t *)priv; int i = 0; @@ -3134,7 +3116,7 @@ do_command: static uint8_t -kbd_read(uint16_t port, void *priv) +kbd_read(uint16_t port, priv_t priv) { atkbd_t *dev = (atkbd_t *)priv; uint8_t ret = 0xff; @@ -3190,7 +3172,7 @@ kbd_read(uint16_t port, void *priv) static void -kbd_refresh(void *priv) +kbd_refresh(priv_t priv) { atkbd_t *dev = (atkbd_t *)priv; @@ -3200,7 +3182,7 @@ kbd_refresh(void *priv) static void -kbd_reset(void *priv) +kbd_reset(priv_t priv) { atkbd_t *dev = (atkbd_t *)priv; @@ -3241,7 +3223,7 @@ kbd_reset(void *priv) static void -kbd_close(void *priv) +kbd_close(priv_t priv) { atkbd_t *dev = (atkbd_t *)priv; @@ -3261,20 +3243,19 @@ kbd_close(void *priv) } -static void * +static priv_t kbd_init(const device_t *info, UNUSED(void *parent)) { atkbd_t *dev; dev = (atkbd_t *)mem_alloc(sizeof(atkbd_t)); memset(dev, 0x00, sizeof(atkbd_t)); - dev->flags = info->local; kbd_reset(dev); io_sethandler(0x0060, 5, - kbd_read, NULL, NULL, kbd_write, NULL, NULL, dev); + kbd_read,NULL,NULL, kbd_write,NULL,NULL, dev); keyboard_send = add_data_kbd; timer_add(kbd_poll, dev, &keyboard_delay, TIMER_ALWAYS_ENABLED); @@ -3321,7 +3302,7 @@ kbd_init(const device_t *info, UNUSED(void *parent)) /* We need this, sadly. */ SavedKbd = dev; - return(dev); + return((priv_t)dev); } @@ -3471,7 +3452,7 @@ const device_t keyboard_ps2_xi8088_device = { void -keyboard_at_set_mouse(void (*func)(uint8_t val, void *priv), void *priv) +keyboard_at_set_mouse(void (*func)(uint8_t val, priv_t), priv_t priv) { mouse_write = func; mouse_p = priv; @@ -3496,7 +3477,7 @@ keyboard_at_adddata_mouse(uint8_t val) /* Set custom machine-dependent keyboard stuff. */ void -keyboard_at_set_funcs(void *arg, uint8_t (*readfunc)(void *), void (*writefunc)(void *, uint8_t), void *priv) +keyboard_at_set_funcs(priv_t arg, uint8_t (*readfunc)(priv_t), void (*writefunc)(priv_t, uint8_t), priv_t priv) { atkbd_t *dev = (atkbd_t *)arg; diff --git a/src/devices/input/keyboard_xt.c b/src/devices/input/keyboard_xt.c index 0890032..46a6273 100644 --- a/src/devices/input/keyboard_xt.c +++ b/src/devices/input/keyboard_xt.c @@ -10,7 +10,7 @@ * * **NOTE** The key_queue stuff should be in the device data. * - * Version: @(#)keyboard_xt.c 1.0.18 2019/04/26 + * Version: @(#)keyboard_xt.c 1.0.19 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -94,8 +94,8 @@ typedef struct { int8_t blocked; uint8_t key_waiting; - uint8_t (*read_func)(void *); - void *func_priv; + uint8_t (*read_func)(priv_t); + priv_t func_priv; } xtkbd_t; @@ -622,7 +622,7 @@ static int key_queue_start, static void -kbd_poll(void *priv) +kbd_poll(priv_t priv) { xtkbd_t *dev = (xtkbd_t *)priv; @@ -662,7 +662,7 @@ kbd_adddata_ex(uint16_t val) static void -kbd_write(uint16_t port, uint8_t val, void *priv) +kbd_write(uint16_t port, uint8_t val, priv_t priv) { xtkbd_t *dev = (xtkbd_t *)priv; @@ -724,7 +724,7 @@ kbd_write(uint16_t port, uint8_t val, void *priv) static uint8_t -kbd_read(uint16_t port, void *priv) +kbd_read(uint16_t port, priv_t priv) { xtkbd_t *dev = (xtkbd_t *)priv; uint8_t ret = 0xff; @@ -797,7 +797,7 @@ kbd_read(uint16_t port, void *priv) static void -kbd_reset(void *priv) +kbd_reset(priv_t priv) { xtkbd_t *dev = (xtkbd_t *)priv; @@ -813,7 +813,27 @@ kbd_reset(void *priv) } -static void * +static void +kbd_close(priv_t priv) +{ + xtkbd_t *dev = (xtkbd_t *)priv; + + /* Stop the timer. */ + keyboard_delay = 0; + + /* Disable scanning. */ + keyboard_scan = 0; + + keyboard_send = NULL; + + io_removehandler(0x0060, 4, + kbd_read,NULL,NULL, kbd_write,NULL,NULL, dev); + + free(dev); +} + + +static priv_t kbd_init(const device_t *info, UNUSED(void *parent)) { int i, fdd_count = 0; @@ -933,27 +953,7 @@ kbd_init(const device_t *info, UNUSED(void *parent)) keyboard_set_table(scancode_xt); - return(dev); -} - - -static void -kbd_close(void *priv) -{ - xtkbd_t *dev = (xtkbd_t *)priv; - - /* Stop the timer. */ - keyboard_delay = 0; - - /* Disable scanning. */ - keyboard_scan = 0; - - keyboard_send = NULL; - - io_removehandler(0x0060, 4, - kbd_read,NULL,NULL, kbd_write,NULL,NULL, dev); - - free(dev); + return((priv_t)dev); } @@ -1029,7 +1029,7 @@ const device_t keyboard_laserxt3_device = { void -keyboard_xt_set_funcs(void *arg, uint8_t (*func)(void *), void *priv) +keyboard_xt_set_funcs(priv_t arg, uint8_t (*func)(priv_t), priv_t priv) { xtkbd_t *dev = (xtkbd_t *)arg; diff --git a/src/devices/input/mouse.c b/src/devices/input/mouse.c index bd35f41..580813b 100644 --- a/src/devices/input/mouse.c +++ b/src/devices/input/mouse.c @@ -8,7 +8,7 @@ * * Common driver module for MOUSE devices. * - * Version: @(#)mouse.c 1.0.20 2019/05/09 + * Version: @(#)mouse.c 1.0.21 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -89,8 +89,8 @@ static const struct { static int mouse_nbut; -static void *mouse_priv; -static int (*mouse_func)(int,int,int,int,void *); +static priv_t mouse_priv; +static int (*mouse_func)(int,int,int,int,priv_t); #ifdef _LOGGING @@ -186,7 +186,7 @@ mouse_process(void) void -mouse_set_poll(int (*func)(int,int,int,int,void *), void *arg) +mouse_set_poll(int (*func)(int,int,int,int,priv_t), priv_t arg) { if (config.mouse_type != MOUSE_INTERNAL) return; diff --git a/src/devices/input/mouse.h b/src/devices/input/mouse.h index 17d15e3..83cfe15 100644 --- a/src/devices/input/mouse.h +++ b/src/devices/input/mouse.h @@ -8,7 +8,7 @@ * * Definitions for the mouse driver. * - * Version: @(#)mouse.h 1.0.12 2019/05/09 + * Version: @(#)mouse.h 1.0.13 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -90,10 +90,10 @@ extern void mouse_close(void); extern void mouse_reset(void); extern void mouse_set_buttons(int buttons); extern void mouse_process(void); -extern void mouse_set_poll(int (*f)(int,int,int,int,void*), void*); +extern void mouse_set_poll(int (*f)(int,int,int,int,priv_t), priv_t); extern void mouse_poll(void); -extern void mouse_bus_set_irq(void *priv, int irq); +extern void mouse_bus_set_irq(priv_t priv, int irq); extern const char *mouse_get_name(int mouse); extern const char *mouse_get_internal_name(int mouse); diff --git a/src/devices/input/mouse_bus.c b/src/devices/input/mouse_bus.c index 2bf08c2..d91c52e 100644 --- a/src/devices/input/mouse_bus.c +++ b/src/devices/input/mouse_bus.c @@ -55,7 +55,7 @@ * Microsoft Windows 98 SE * Linux kernel 1.2.13-ELF * - * Version: @(#)mouse_bus.c 1.1.10 2019/05/09 + * Version: @(#)mouse_bus.c 1.1.11 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -189,7 +189,7 @@ static const double periods[4] = { 30.0, 50.0, 100.0, 200.0 }; /* Handle a READ operation from one of the Logitech registers. */ static uint8_t -lt_read(uint16_t port, void *priv) +lt_read(uint16_t port, priv_t priv) { mouse_t *dev = (mouse_t *)priv; uint8_t ret = 0xff; @@ -264,7 +264,7 @@ lt_read(uint16_t port, void *priv) /* Handle a WRITE operation to one of the Logitech registers. */ static void -lt_write(uint16_t port, uint8_t val, void *priv) +lt_write(uint16_t port, uint8_t val, priv_t priv) { mouse_t *dev = (mouse_t *)priv; uint8_t bit; @@ -351,7 +351,7 @@ lt_write(uint16_t port, uint8_t val, void *priv) /* Handle a READ operation from one of the MS InPort registers. */ static uint8_t -ms_read(uint16_t port, void *priv) +ms_read(uint16_t port, priv_t priv) { mouse_t *dev = (mouse_t *)priv; uint8_t ret = 0xff; @@ -403,7 +403,7 @@ ms_read(uint16_t port, void *priv) /* Handle a WRITE operation to one of the MS InPort registers. */ static void -ms_write(uint16_t port, uint8_t val, void *priv) +ms_write(uint16_t port, uint8_t val, priv_t priv) { mouse_t *dev = (mouse_t *)priv; @@ -496,7 +496,7 @@ ms_write(uint16_t port, uint8_t val, void *priv) /* The emulator calls us with an update on the host mouse device. */ static int -bm_poll(int x, int y, int z, int b, void *priv) +bm_poll(int x, int y, int z, int b, priv_t priv) { mouse_t *dev = (mouse_t *)priv; int xor; @@ -568,7 +568,7 @@ bm_poll(int x, int y, int z, int b, void *priv) * 45 times per second (MS/Logitech Bus mouse). */ static void -bm_timer(void *priv) +bm_timer(priv_t priv) { mouse_t *dev = (mouse_t *)priv; int delta_x, delta_y; @@ -647,7 +647,7 @@ bm_timer(void *priv) /* Release all resources held by the device. */ static void -bm_close(void *priv) +bm_close(priv_t priv) { mouse_t *dev = (mouse_t *)priv; @@ -657,7 +657,7 @@ bm_close(void *priv) /* Initialize the device for use by the user. */ -static void * +static priv_t bm_init(const device_t *info, UNUSED(void *parent)) { mouse_t *dev; @@ -745,7 +745,7 @@ bm_init(const device_t *info, UNUSED(void *parent)) INFO("MOUSE: %s (I/O=%04x, IRQ=%i, buttons=%i\n", dev->name, dev->base, dev->irq, dev->bn); - return(dev); + return((priv_t)dev); } @@ -943,7 +943,7 @@ const device_t mouse_msinport_onboard_device = { * currently needed for onboard devices. */ void -mouse_bus_set_irq(void *priv, int irq) +mouse_bus_set_irq(priv_t priv, int irq) { mouse_t *dev = (mouse_t *)priv; diff --git a/src/devices/misc/bugger.c b/src/devices/misc/bugger.c index b6f0623..1198edc 100644 --- a/src/devices/misc/bugger.c +++ b/src/devices/misc/bugger.c @@ -44,7 +44,7 @@ * configuration register (CTRL_SPCFG bit set) but have to * remember that stuff first... * - * Version: @(#)bugger.c 1.0.10 2019/04/08 + * Version: @(#)bugger.c 1.0.11 2019/05/13 * * Author: Fred N. van Kempen, * @@ -120,8 +120,8 @@ typedef struct { seg1, /* LEFT and RIGHT 7SEG displays */ seg2, spcfg; /* serial port configuration */ - uint8_t buff[FIFO_LEN], /* serial port data buffer */ - *bptr; + uint8_t *bptr, /* serial port data buffer */ + buff[FIFO_LEN]; } bugger_t; @@ -293,7 +293,7 @@ bug_reset(bugger_t *dev) /* Handle a WRITE operation to one of our registers. */ static void -bug_write(uint16_t port, uint8_t val, UNUSED(void *priv)) +bug_write(uint16_t port, uint8_t val, priv_t priv) { bugger_t *dev = (bugger_t *)priv; @@ -320,7 +320,7 @@ bug_write(uint16_t port, uint8_t val, UNUSED(void *priv)) /* Handle a READ operation from one of our registers. */ static uint8_t -bug_read(uint16_t port, UNUSED(void *priv)) +bug_read(uint16_t port, priv_t priv) { bugger_t *dev = (bugger_t *)priv; uint8_t ret = 0xff; @@ -349,8 +349,21 @@ bug_read(uint16_t port, UNUSED(void *priv)) } +/* Remove the ISA BusBugger emulator from the system. */ +static void +bug_close(priv_t priv) +{ + bugger_t *dev = (bugger_t *)priv; + + io_removehandler(dev->base, 2, + bug_read,NULL,NULL, bug_write,NULL,NULL, dev); + + free(dev); +} + + /* Initialize the ISA BusBugger emulator. */ -static void * +static priv_t bug_init(const device_t *info, UNUSED(void *parent)) { bugger_t *dev; @@ -372,19 +385,6 @@ bug_init(const device_t *info, UNUSED(void *parent)) } -/* Remove the ISA BusBugger emulator from the system. */ -static void -bug_close(void *priv) -{ - bugger_t *dev = (bugger_t *)priv; - - io_removehandler(dev->base, 2, - bug_read,NULL,NULL, bug_write,NULL,NULL, dev); - - free(dev); -} - - const device_t bugger_device = { "ISA/PCI Bus Bugger", DEVICE_ISA, diff --git a/src/devices/misc/isamem.c b/src/devices/misc/isamem.c index c7e8fea..156851b 100644 --- a/src/devices/misc/isamem.c +++ b/src/devices/misc/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.9 2019/05/03 + * Version: @(#)isamem.c 1.0.10 2019/05/13 * * Author: Fred N. van Kempen, * @@ -142,7 +142,7 @@ static const device_t *instance[ISAMEM_MAX] = { /* Read one byte from onboard RAM. */ static uint8_t -ram_readb(uint32_t addr, void *priv) +ram_readb(uint32_t addr, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; memdev_t *dev = (memdev_t *)map->dev; @@ -157,7 +157,7 @@ ram_readb(uint32_t addr, void *priv) /* Read one word from onboard RAM. */ static uint16_t -ram_readw(uint32_t addr, void *priv) +ram_readw(uint32_t addr, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; memdev_t *dev = (memdev_t *)map->dev; @@ -172,7 +172,7 @@ ram_readw(uint32_t addr, void *priv) /* Write one byte to onboard RAM. */ static void -ram_writeb(uint32_t addr, uint8_t val, void *priv) +ram_writeb(uint32_t addr, uint8_t val, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; memdev_t *dev = (memdev_t *)map->dev; @@ -184,7 +184,7 @@ ram_writeb(uint32_t addr, uint8_t val, void *priv) /* Write one word to onboard RAM. */ static void -ram_writew(uint32_t addr, uint16_t val, void *priv) +ram_writew(uint32_t addr, uint16_t val, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; memdev_t *dev = (memdev_t *)map->dev; @@ -196,7 +196,7 @@ ram_writew(uint32_t addr, uint16_t val, void *priv) /* Read one byte from onboard paged RAM. */ static uint8_t -ems_readb(uint32_t addr, void *priv) +ems_readb(uint32_t addr, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; memdev_t *dev = (memdev_t *)map->dev; @@ -215,7 +215,7 @@ ems_readb(uint32_t addr, void *priv) /* Read one word from onboard paged RAM. */ static uint16_t -ems_readw(uint32_t addr, void *priv) +ems_readw(uint32_t addr, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; memdev_t *dev = (memdev_t *)map->dev; @@ -234,7 +234,7 @@ ems_readw(uint32_t addr, void *priv) /* Write one byte to onboard paged RAM. */ static void -ems_writeb(uint32_t addr, uint8_t val, void *priv) +ems_writeb(uint32_t addr, uint8_t val, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; memdev_t *dev = (memdev_t *)map->dev; @@ -250,7 +250,7 @@ ems_writeb(uint32_t addr, uint8_t val, void *priv) /* Write one word to onboard paged RAM. */ static void -ems_writew(uint32_t addr, uint16_t val, void *priv) +ems_writew(uint32_t addr, uint16_t val, priv_t priv) { mem_map_t *map = (mem_map_t *)priv; memdev_t *dev = (memdev_t *)map->dev; @@ -266,7 +266,7 @@ ems_writew(uint32_t addr, uint16_t val, void *priv) /* Handle a READ operation from one of our registers. */ static uint8_t -ems_read(uint16_t port, void *priv) +ems_read(uint16_t port, priv_t priv) { memdev_t *dev = (memdev_t *)priv; uint8_t ret = 0xff; @@ -295,7 +295,7 @@ ems_read(uint16_t port, void *priv) /* Handle a WRITE operation to one of our registers. */ static void -ems_write(uint16_t port, uint8_t val, void *priv) +ems_write(uint16_t port, uint8_t val, priv_t priv) { memdev_t *dev = (memdev_t *)priv; int vpage; @@ -364,8 +364,32 @@ DEBUG("EMS: write(%02x) to register 1 !\n"); } +/* Remove the device from the system. */ +static void +isamem_close(priv_t priv) +{ + memdev_t *dev = (memdev_t *)priv; + int i; + + if (dev->flags & FLAG_EMS) { + for (i = 0; i < EMS_MAXPAGE; i++) { + io_removehandler(dev->base_addr + (EMS_PGSIZE*i), 2, + ems_read,NULL,NULL, ems_write,NULL,NULL, dev); + + } + } + + if (dev->ram != NULL) + free(dev->ram); + + instance[dev->instance] = NULL; + + free(dev); +} + + /* Initialize the device for use. */ -static void * +static priv_t isamem_init(const device_t *info, UNUSED(void *parent)) { memdev_t *dev; @@ -620,31 +644,7 @@ dev->frame_addr = 0xE0000; } /* Let them know our device instance. */ - return((void *)dev); -} - - -/* Remove the device from the system. */ -static void -isamem_close(void *priv) -{ - memdev_t *dev = (memdev_t *)priv; - int i; - - if (dev->flags & FLAG_EMS) { - for (i = 0; i < EMS_MAXPAGE; i++) { - io_removehandler(dev->base_addr + (EMS_PGSIZE*i), 2, - ems_read,NULL,NULL, ems_write,NULL,NULL, dev); - - } - } - - if (dev->ram != NULL) - free(dev->ram); - - instance[dev->instance] = NULL; - - free(dev); + return((priv_t)dev); } diff --git a/src/devices/misc/isartc.c b/src/devices/misc/isartc.c index 143559a..b420c82 100644 --- a/src/devices/misc/isartc.c +++ b/src/devices/misc/isartc.c @@ -28,7 +28,7 @@ * NOTE: The IRQ functionalities have been implemented, but not yet * tested, as I need to write test software for them first :) * - * Version: @(#)isartc.c 1.0.8 2019/05/03 + * Version: @(#)isartc.c 1.0.9 2019/05/13 * * Author: Fred N. van Kempen, * @@ -95,8 +95,8 @@ typedef struct { uint32_t base_addr; /* configured I/O address */ /* Fields for the specific driver. */ - void (*f_wr)(uint16_t, uint8_t, void *); - uint8_t (*f_rd)(uint16_t, void *); + void (*f_wr)(uint16_t, uint8_t, priv_t); + uint8_t (*f_rd)(uint16_t, priv_t); int8_t year; /* register for YEAR value */ char pad[3]; @@ -290,7 +290,7 @@ mm67_time_get(nvr_t *nvr, struct tm *tm) /* Set the current NVR time. */ static void -mm67_time_set(nvr_t *nvr, struct tm *tm) +mm67_time_set(nvr_t *nvr, const struct tm *tm) { rtcdev_t *dev = (rtcdev_t *)nvr->data; uint8_t *regs = nvr->regs; @@ -354,7 +354,7 @@ mm67_reset(nvr_t *nvr) /* Handle a READ operation from one of our registers. */ static uint8_t -mm67_read(uint16_t port, void *priv) +mm67_read(uint16_t port, priv_t priv) { rtcdev_t *dev = (rtcdev_t *)priv; int reg = port - dev->base_addr; @@ -384,7 +384,7 @@ mm67_read(uint16_t port, void *priv) /* Handle a WRITE operation to one of our registers. */ static void -mm67_write(uint16_t port, uint8_t val, void *priv) +mm67_write(uint16_t port, uint8_t val, priv_t priv) { rtcdev_t *dev = (rtcdev_t *)priv; int reg = port - dev->base_addr; @@ -457,8 +457,24 @@ DEBUG("RTC: write test=%02x\n", val); * * ************************************************************************/ +/* Remove the device from the system. */ +static void +isartc_close(priv_t priv) +{ + rtcdev_t *dev = (rtcdev_t *)priv; + + io_removehandler(dev->base_addr, dev->base_addrsz, + dev->f_rd,NULL,NULL, dev->f_wr,NULL,NULL, dev); + + if (dev->nvr.fn != NULL) + free((wchar_t *)dev->nvr.fn); + + free(dev); +} + + /* Initialize the device for use. */ -static void * +static priv_t isartc_init(const device_t *info, UNUSED(void *parent)) { rtcdev_t *dev; @@ -533,23 +549,7 @@ isartc_init(const device_t *info, UNUSED(void *parent)) nvr_init(&dev->nvr); /* Let them know our device instance. */ - return(dev); -} - - -/* Remove the device from the system. */ -static void -isartc_close(void *priv) -{ - rtcdev_t *dev = (rtcdev_t *)priv; - - io_removehandler(dev->base_addr, dev->base_addrsz, - dev->f_rd,NULL,NULL, dev->f_wr,NULL,NULL, dev); - - if (dev->nvr.fn != NULL) - free((wchar_t *)dev->nvr.fn); - - free(dev); + return((priv_t)dev); } @@ -593,6 +593,7 @@ static const device_config_t ev170_config[] = { } }; + static const device_t ev170_device = { "Everex EV-170 Magic I/O", DEVICE_ISA, diff --git a/src/devices/network/net_3c503.c b/src/devices/network/net_3c503.c index ff70098..4311262 100644 --- a/src/devices/network/net_3c503.c +++ b/src/devices/network/net_3c503.c @@ -8,7 +8,7 @@ * * Implementation of the 3Com Etherlink II 3c503 (ISA 8-bit). * - * Version: @(#)net_3c503.c 1.0.8 2019/05/06 + * Version: @(#)net_3c503.c 1.0.9 2019/05/13 * * Based on @(#)3c503.cpp Carl (MAME) * @@ -92,10 +92,6 @@ typedef struct { } el2_t; -static void el2_rx(void *, uint8_t *, int); -static void el2_tx(el2_t *, uint32_t); - - static void el2_interrupt(el2_t *dev, int set) { @@ -124,115 +120,171 @@ el2_interrupt(el2_t *dev, int set) } +/* + * Called by the platform-specific code when an Ethernet frame + * has been received. The destination address is tested to see + * if it should be accepted, and if the RX ring has enough room, + * it is copied into it and the receive process is updated. + */ static void -el2_ram_write(uint32_t addr, uint8_t val, void *priv) +el2_rx(void *priv, uint8_t *buf, int io_len) { + static uint8_t bcast_addr[6] = {0xff,0xff,0xff,0xff,0xff,0xff}; el2_t *dev = (el2_t *)priv; + uint8_t pkthdr[4]; + uint8_t *startptr; + int rx_pages, avail; + int idx, nextpage; + int endbytes; - if ((addr & 0x3fff) >= 0x2000) + /* FIXME: move to upper layer */ + ui_sb_icon_update(SB_NETWORK, 1); + + if (io_len != 60) { + DEBUG("3C503: rx_frame with length %d\n", io_len); + } + + if ((dev->dp8390.CR.stop != 0) || (dev->dp8390.page_start == 0)) return; + + /* + * Add the pkt header + CRC to the length, and work + * out how many 256-byte pages the frame would occupy. + */ + rx_pages = (io_len + sizeof(pkthdr) + sizeof(uint32_t) + 255)/256; + if (dev->dp8390.curr_page < dev->dp8390.bound_ptr) { + avail = dev->dp8390.bound_ptr - dev->dp8390.curr_page; + } else { + avail = (dev->dp8390.page_stop - dev->dp8390.page_start) - + (dev->dp8390.curr_page - dev->dp8390.bound_ptr); + } + + /* + * Avoid getting into a buffer overflow condition by + * not attempting to do partial receives. The emulation + * to handle this condition seems particularly painful. + */ + if ((avail < rx_pages) +#if DP8390_NEVER_FULL_RING + || (avail == rx_pages) +#endif + ) { + DEBUG("3C503: no space\n"); + + /* FIXME: move to upper layer */ + ui_sb_icon_update(SB_NETWORK, 0); return; + } - dev->dp8390.mem[addr & 0x1fff] = val; -} + if ((io_len < 40/*60*/) && !dev->dp8390.RCR.runts_ok) { + DEBUG("3C503: rejected small packet, length %d\n", io_len); + /* FIXME: move to upper layer */ + ui_sb_icon_update(SB_NETWORK, 0); + return; + } -static uint8_t -el2_ram_read(uint32_t addr, void *priv) -{ - el2_t *dev = (el2_t *)priv; + /* Some computers don't care... */ + if (io_len < 60) + io_len = 60; - if ((addr & 0x3fff) >= 0x2000) - return(0xff); + DBGLOG(1, "3C503: RX %x:%x:%x:%x:%x:%x > %x:%x:%x:%x:%x:%x len %d\n", + buf[6], buf[7], buf[8], buf[9], buf[10], buf[11], + buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], io_len); - return(dev->dp8390.mem[addr & 0x1fff]); + /* Do address filtering if not in promiscuous mode. */ + if (! dev->dp8390.RCR.promisc) { + /* If this is a broadcast frame.. */ + if (! memcmp(buf, bcast_addr, 6)) { + /* Broadcast not enabled, we're done. */ + if (! dev->dp8390.RCR.broadcast) { + DEBUG("3C503: RX BC disabled\n"); + + /* FIXME: move to upper layer */ + ui_sb_icon_update(SB_NETWORK, 0); + return; + } + } + + /* If this is a multicast frame.. */ + else if (buf[0] & 0x01) { + /* Multicast not enabled, we're done. */ + if (! dev->dp8390.RCR.multicast) { + DEBUG("3C503: RX MC disabled\n"); + + /* FIXME: move to upper layer */ + ui_sb_icon_update(SB_NETWORK, 0); + return; + } + + /* Are we listening to this multicast address? */ + idx = mcast_index(buf); + if (! (dev->dp8390.mchash[idx>>3] & (1<<(idx&0x7)))) { + DEBUG("3C503: RX MC not listed\n"); + + /* FIXME: move to upper layer */ + ui_sb_icon_update(SB_NETWORK, 0); + return; + } + } + + /* Unicast, must be for us.. */ + else if (memcmp(buf, dev->dp8390.physaddr, 6)) return; + } else { + DEBUG("3C503: RX promiscuous receive\n"); + } + + nextpage = dev->dp8390.curr_page + rx_pages; + if (nextpage >= dev->dp8390.page_stop) + nextpage -= (dev->dp8390.page_stop - dev->dp8390.page_start); + + /* Set up packet header. */ + pkthdr[0] = 0x01; /* RXOK - packet is OK */ + if (buf[0] & 0x01) + pkthdr[0] |= 0x20; /* MULTICAST packet */ + pkthdr[1] = nextpage; /* ptr to next packet */ + pkthdr[2] = (uint8_t) ((io_len + sizeof(pkthdr)) & 0xff); /* length-low */ + pkthdr[3] = (uint8_t) ((io_len + sizeof(pkthdr)) >> 8); /* length-hi */ + DBGLOG(1, "3C503: RX pkthdr [%02x %02x %02x %02x]\n", + pkthdr[0], pkthdr[1], pkthdr[2], pkthdr[3]); + + /* Copy into buffer, update curpage, and signal interrupt if config'd */ + startptr = &dev->dp8390.mem[(dev->dp8390.curr_page * 256) - DP8390_WORD_MEMSTART]; + memcpy(startptr, pkthdr, sizeof(pkthdr)); + if ((nextpage > dev->dp8390.curr_page) || + ((dev->dp8390.curr_page + rx_pages) == dev->dp8390.page_stop)) { + memcpy(startptr+sizeof(pkthdr), buf, io_len); + } else { + endbytes = (dev->dp8390.page_stop - dev->dp8390.curr_page) * 256; + memcpy(startptr+sizeof(pkthdr), buf, endbytes-sizeof(pkthdr)); + startptr = &dev->dp8390.mem[(dev->dp8390.page_start * 256) - DP8390_WORD_MEMSTART]; + memcpy(startptr, buf+endbytes-sizeof(pkthdr), io_len-endbytes+8); + } + dev->dp8390.curr_page = nextpage; + + dev->dp8390.RSR.rx_ok = 1; + dev->dp8390.RSR.rx_mbit = (buf[0] & 0x01) ? 1 : 0; + dev->dp8390.ISR.pkt_rx = 1; + + if (dev->dp8390.IMR.rx_inte) + el2_interrupt(dev, 1); + + /* FIXME: move to upper layer */ + ui_sb_icon_update(SB_NETWORK, 0); } static void -el2_set_drq(el2_t *dev) +el2_tx(el2_t *dev, uint32_t val) { - switch (dev->dma_channel) { - case 1: - dev->regs.idcfr = 1; - break; + dev->dp8390.CR.tx_packet = 0; + dev->dp8390.TSR.tx_ok = 1; + dev->dp8390.ISR.pkt_tx = 1; - case 2: - dev->regs.idcfr = 2; - break; - - case 3: - dev->regs.idcfr = 4; - break; - } -} - - -/* Restore state to power-up, cancelling all I/O. */ -static void -el2_reset(void *priv) -{ - el2_t *dev = (el2_t *)priv; - int i; - - DEBUG("3C503: reset\n"); - - /* Initialize the MAC address area by doubling the physical address. */ - dev->prom[0] = dev->dp8390.physaddr[0]; - dev->prom[1] = dev->dp8390.physaddr[1]; - dev->prom[2] = dev->dp8390.physaddr[2]; - dev->prom[3] = dev->dp8390.physaddr[3]; - dev->prom[4] = dev->dp8390.physaddr[4]; - dev->prom[5] = dev->dp8390.physaddr[5]; - -//FIXME: why?? --Fvk - /* NE1K signature. */ - for (i = 6; i < 16; i++) - dev->prom[i] = 0x57; - - /* Zero out registers and memory. */ - memset(&dev->dp8390.CR, 0x00, sizeof(dev->dp8390.CR) ); - memset(&dev->dp8390.ISR, 0x00, sizeof(dev->dp8390.ISR)); - memset(&dev->dp8390.IMR, 0x00, sizeof(dev->dp8390.IMR)); - memset(&dev->dp8390.DCR, 0x00, sizeof(dev->dp8390.DCR)); - memset(&dev->dp8390.TCR, 0x00, sizeof(dev->dp8390.TCR)); - memset(&dev->dp8390.TSR, 0x00, sizeof(dev->dp8390.TSR)); - memset(&dev->dp8390.RSR, 0x00, sizeof(dev->dp8390.RSR)); + /* Generate an interrupt if not masked */ + if (dev->dp8390.IMR.tx_inte) + el2_interrupt(dev, 1); dev->dp8390.tx_timer_active = 0; - dev->dp8390.local_dma = 0; - dev->dp8390.page_start = 0; - dev->dp8390.page_stop = 0; - dev->dp8390.bound_ptr = 0; - dev->dp8390.tx_page_start = 0; - dev->dp8390.num_coll = 0; - dev->dp8390.tx_bytes = 0; - dev->dp8390.fifo = 0; - dev->dp8390.remote_dma = 0; - dev->dp8390.remote_start = 0; - dev->dp8390.remote_bytes = 0; - dev->dp8390.tallycnt_0 = 0; - dev->dp8390.tallycnt_1 = 0; - dev->dp8390.tallycnt_2 = 0; - - dev->dp8390.curr_page = 0; - - dev->dp8390.rempkt_ptr = 0; - dev->dp8390.localpkt_ptr = 0; - dev->dp8390.address_cnt = 0; - - memset(&dev->dp8390.mem, 0x00, sizeof(dev->dp8390.mem)); - - /* Set power-up conditions. */ - dev->dp8390.CR.stop = 1; - dev->dp8390.CR.rdma_cmd = 4; - dev->dp8390.ISR.reset = 1; - dev->dp8390.DCR.longaddr = 1; - - memset(&dev->regs, 0, sizeof(dev->regs)); - - dev->regs.ctrl = 0x0a; - - el2_interrupt(dev, 0); } @@ -246,7 +298,7 @@ el2_reset(void *priv) * and there is 16K of buffer memory starting at 16K. */ static uint32_t -el2_chipmem_read(el2_t *dev, uint32_t addr, unsigned int len) +chipmem_read(el2_t *dev, uint32_t addr, unsigned int len) { uint32_t retval = 0; @@ -271,7 +323,7 @@ el2_chipmem_read(el2_t *dev, uint32_t addr, unsigned int len) static void -el2_chipmem_write(el2_t *dev, uint32_t addr, uint32_t val, unsigned len) +chipmem_write(el2_t *dev, uint32_t addr, uint32_t val, unsigned len) { if ((addr >= DP8390_WORD_MEMSTART) && (addr < DP8390_WORD_MEMEND)) { dev->dp8390.mem[addr-DP8390_WORD_MEMSTART] = val & 0xff; @@ -284,7 +336,7 @@ el2_chipmem_write(el2_t *dev, uint32_t addr, uint32_t val, unsigned len) /* Handle reads/writes to the 'zeroth' page of the DS8390 register file. */ static uint32_t -el2_page0_read(el2_t *dev, uint32_t off, unsigned int len) +page0_read(el2_t *dev, uint32_t off, unsigned int len) { uint8_t retval = 0; @@ -392,7 +444,7 @@ el2_page0_read(el2_t *dev, uint32_t off, unsigned int len) static void -el2_page0_write(el2_t *dev, uint32_t off, uint32_t val, unsigned len) +page0_write(el2_t *dev, uint32_t off, uint32_t val, unsigned len) { uint8_t val2; @@ -400,9 +452,9 @@ el2_page0_write(el2_t *dev, uint32_t off, uint32_t val, unsigned len) /* break up outw into two outb's */ if (len == 2) { - el2_page0_write(dev, off, (val & 0xff), 1); + page0_write(dev, off, (val & 0xff), 1); if (off < 0x0f) - el2_page0_write(dev, off+1, ((val>>8)&0xff), 1); + page0_write(dev, off+1, ((val>>8)&0xff), 1); return; } @@ -601,7 +653,7 @@ el2_page0_write(el2_t *dev, uint32_t off, uint32_t val, unsigned len) /* Handle reads/writes to the first page of the DS8390 register file. */ static uint32_t -el2_page1_read(el2_t *dev, uint32_t off, unsigned int len) +page1_read(el2_t *dev, uint32_t off, unsigned int len) { DBGLOG(2, "3C503: Page1 read from register 0x%02x, len=%u\n", off, len); @@ -637,7 +689,7 @@ el2_page1_read(el2_t *dev, uint32_t off, unsigned int len) static void -el2_page1_write(el2_t *dev, uint32_t off, uint32_t val, unsigned len) +page1_write(el2_t *dev, uint32_t off, uint32_t val, unsigned int len) { DBGLOG(2, "3C503: Page1 write to register 0x%02x, len=%u, value=0x%04x\n", off, len, val); @@ -681,7 +733,7 @@ el2_page1_write(el2_t *dev, uint32_t off, uint32_t val, unsigned len) /* Handle reads/writes to the second page of the DS8390 register file. */ static uint32_t -el2_page2_read(el2_t *dev, uint32_t off, unsigned int len) +page2_read(el2_t *dev, uint32_t off, unsigned int len) { DBGLOG(2, "3C503: Page2 read from register 0x%02x, len=%u\n", off, len); @@ -758,7 +810,7 @@ el2_page2_read(el2_t *dev, uint32_t off, unsigned int len) affect internal operation, but let them through for now and print a warning. */ static void -el2_page2_write(el2_t *dev, uint32_t off, uint32_t val, unsigned len) +page2_write(el2_t *dev, uint32_t off, uint32_t val, unsigned int len) { DBGLOG(2, "3C503: Page2 write to register 0x%02x, len=%u, value=0x%04x\n", off, len, val); @@ -817,9 +869,28 @@ el2_page2_write(el2_t *dev, uint32_t off, uint32_t val, unsigned len) } +static void +set_drq(el2_t *dev) +{ + switch (dev->dma_channel) { + case 1: + dev->regs.idcfr = 1; + break; + + case 2: + dev->regs.idcfr = 2; + break; + + case 3: + dev->regs.idcfr = 4; + break; + } +} + + /* Routines for handling reads/writes to the Command Register. */ static uint32_t -el2_read_cr(el2_t *dev) +read_cr(el2_t *dev) { uint32_t retval; @@ -836,7 +907,7 @@ el2_read_cr(el2_t *dev) static void -el2_write_cr(el2_t *dev, uint32_t val) +write_cr(el2_t *dev, uint32_t val) { DBGLOG(1, "3C503: wrote 0x%02x to CR\n", val); @@ -867,7 +938,7 @@ el2_write_cr(el2_t *dev, uint32_t val) if (dev->dp8390.CR.rdma_cmd == 3) { /* Set up DMA read from receive ring */ dev->dp8390.remote_start = dev->dp8390.remote_dma = dev->dp8390.bound_ptr * 256; - dev->dp8390.remote_bytes = (uint16_t) el2_chipmem_read(dev, dev->dp8390.bound_ptr * 256 + 2, 2); + dev->dp8390.remote_bytes = (uint16_t)chipmem_read(dev, dev->dp8390.bound_ptr * 256 + 2, 2); DEBUG("3C503: sending buffer %x length %d\n", dev->dp8390.remote_start, dev->dp8390.remote_bytes); } @@ -919,34 +990,33 @@ el2_write_cr(el2_t *dev, uint32_t val) static uint8_t -el2_lo_read(uint16_t addr, void *priv) +read_lo(uint16_t addr, priv_t priv) { el2_t *dev = (el2_t *)priv; - uint8_t retval = 0; int off = addr - dev->base_address; + uint8_t retval = 0; switch ((dev->regs.ctrl >> 2) & 3) { case 0x00: DEBUG(0, "Read offset=%04x\n", off); - if (off == 0x00) - retval = el2_read_cr(dev); - else switch(dev->dp8390.CR.pgsel) { + if (off != 0x00) switch(dev->dp8390.CR.pgsel) { case 0x00: - retval = el2_page0_read(dev, off, 1); + retval = page0_read(dev, off, 1); break; case 0x01: - retval = el2_page1_read(dev, off, 1); + retval = page1_read(dev, off, 1); break; case 0x02: - retval = el2_page2_read(dev, off, 1); + retval = page2_read(dev, off, 1); break; case 0x03: retval = 0xff; break; - } + } else + retval = read_cr(dev); break; case 0x01: @@ -967,7 +1037,7 @@ el2_lo_read(uint16_t addr, void *priv) static void -el2_lo_write(uint16_t addr, uint8_t val, void *priv) +write_lo(uint16_t addr, uint8_t val, priv_t priv) { el2_t *dev = (el2_t *)priv; int off = addr - dev->base_address; @@ -978,24 +1048,23 @@ el2_lo_write(uint16_t addr, uint8_t val, void *priv) the low 16 bytes are for the DS8390, with the current page being selected by the PS0,PS1 registers in the command register */ - if (off == 0x00) - el2_write_cr(dev, val); - else switch(dev->dp8390.CR.pgsel) { + if (off != 0x00) switch(dev->dp8390.CR.pgsel) { case 0x00: - el2_page0_write(dev, off, val, 1); + page0_write(dev, off, val, 1); break; case 0x01: - el2_page1_write(dev, off, val, 1); + page1_write(dev, off, val, 1); break; case 0x02: - el2_page2_write(dev, off, val, 1); + page2_write(dev, off, val, 1); break; case 0x03: break; - } + } else + write_cr(dev, val); break; case 0x01: @@ -1008,8 +1077,77 @@ el2_lo_write(uint16_t addr, uint8_t val, void *priv) } +/* Restore state to power-up, cancelling all I/O. */ +static void +el2_reset(priv_t priv) +{ + el2_t *dev = (el2_t *)priv; + int i; + + DEBUG("3C503: reset\n"); + + /* Initialize the MAC address area by doubling the physical address. */ + dev->prom[0] = dev->dp8390.physaddr[0]; + dev->prom[1] = dev->dp8390.physaddr[1]; + dev->prom[2] = dev->dp8390.physaddr[2]; + dev->prom[3] = dev->dp8390.physaddr[3]; + dev->prom[4] = dev->dp8390.physaddr[4]; + dev->prom[5] = dev->dp8390.physaddr[5]; + +//FIXME: why?? --Fvk + /* NE1K signature. */ + for (i = 6; i < 16; i++) + dev->prom[i] = 0x57; + + /* Zero out registers and memory. */ + memset(&dev->dp8390.CR, 0x00, sizeof(dev->dp8390.CR) ); + memset(&dev->dp8390.ISR, 0x00, sizeof(dev->dp8390.ISR)); + memset(&dev->dp8390.IMR, 0x00, sizeof(dev->dp8390.IMR)); + memset(&dev->dp8390.DCR, 0x00, sizeof(dev->dp8390.DCR)); + memset(&dev->dp8390.TCR, 0x00, sizeof(dev->dp8390.TCR)); + memset(&dev->dp8390.TSR, 0x00, sizeof(dev->dp8390.TSR)); + memset(&dev->dp8390.RSR, 0x00, sizeof(dev->dp8390.RSR)); + + dev->dp8390.tx_timer_active = 0; + dev->dp8390.local_dma = 0; + dev->dp8390.page_start = 0; + dev->dp8390.page_stop = 0; + dev->dp8390.bound_ptr = 0; + dev->dp8390.tx_page_start = 0; + dev->dp8390.num_coll = 0; + dev->dp8390.tx_bytes = 0; + dev->dp8390.fifo = 0; + dev->dp8390.remote_dma = 0; + dev->dp8390.remote_start = 0; + dev->dp8390.remote_bytes = 0; + dev->dp8390.tallycnt_0 = 0; + dev->dp8390.tallycnt_1 = 0; + dev->dp8390.tallycnt_2 = 0; + + dev->dp8390.curr_page = 0; + + dev->dp8390.rempkt_ptr = 0; + dev->dp8390.localpkt_ptr = 0; + dev->dp8390.address_cnt = 0; + + memset(&dev->dp8390.mem, 0x00, sizeof(dev->dp8390.mem)); + + /* Set power-up conditions. */ + dev->dp8390.CR.stop = 1; + dev->dp8390.CR.rdma_cmd = 4; + dev->dp8390.ISR.reset = 1; + dev->dp8390.DCR.longaddr = 1; + + memset(&dev->regs, 0, sizeof(dev->regs)); + + dev->regs.ctrl = 0x0a; + + el2_interrupt(dev, 0); +} + + static uint8_t -el2_hi_read(uint16_t addr, void *priv) +read_hi(uint16_t addr, priv_t priv) { el2_t *dev = (el2_t *)priv; @@ -1114,9 +1252,9 @@ el2_hi_read(uint16_t addr, void *priv) if (!(dev->regs.ctrl & 0x80)) return 0xff; - el2_set_drq(dev); + set_drq(dev); - return el2_chipmem_read(dev, dev->regs.da++, 1); + return chipmem_read(dev, dev->regs.da++, 1); } return 0; @@ -1124,7 +1262,7 @@ el2_hi_read(uint16_t addr, void *priv) static void -el2_hi_write(uint16_t addr, uint8_t val, void *priv) +write_hi(uint16_t addr, uint8_t val, priv_t priv) { el2_t *dev = (el2_t *)priv; @@ -1244,9 +1382,9 @@ el2_hi_write(uint16_t addr, uint8_t val, void *priv) if (!(dev->regs.ctrl & 0x80)) return; - el2_set_drq(dev); + set_drq(dev); - el2_chipmem_write(dev, dev->regs.da++, val, 1); + chipmem_write(dev, dev->regs.da++, val, 1); break; } } @@ -1256,12 +1394,10 @@ static void el2_ioremove(el2_t *dev, uint16_t addr) { io_removehandler(addr, 16, - el2_lo_read, NULL, NULL, - el2_lo_write, NULL, NULL, dev); + read_lo,NULL,NULL, write_lo,NULL,NULL, dev); - io_removehandler(addr+0x400, 16, - el2_hi_read, NULL, NULL, - el2_hi_write, NULL, NULL, dev); + io_removehandler(addr + 0x400, 16, + read_hi,NULL,NULL, write_hi,NULL,NULL, dev); } @@ -1269,185 +1405,39 @@ static void el2_ioset(el2_t *dev, uint16_t addr) { io_sethandler(addr, 16, - el2_lo_read, NULL, NULL, - el2_lo_write, NULL, NULL, dev); + read_lo,NULL,NULL, write_lo,NULL,NULL, dev); - io_sethandler(addr+0x400, 16, - el2_hi_read, NULL, NULL, - el2_hi_write, NULL, NULL, dev); + io_sethandler(addr + 0x400, 16, + read_hi,NULL,NULL, write_hi,NULL,NULL, dev); } -static void -el2_tx(el2_t *dev, uint32_t val) +static uint8_t +ram_read(uint32_t addr, priv_t priv) { - dev->dp8390.CR.tx_packet = 0; - dev->dp8390.TSR.tx_ok = 1; - dev->dp8390.ISR.pkt_tx = 1; - - /* Generate an interrupt if not masked */ - if (dev->dp8390.IMR.tx_inte) - el2_interrupt(dev, 1); - - dev->dp8390.tx_timer_active = 0; -} - - -/* - * Called by the platform-specific code when an Ethernet frame - * has been received. The destination address is tested to see - * if it should be accepted, and if the RX ring has enough room, - * it is copied into it and the receive process is updated. - */ -static void -el2_rx(void *priv, uint8_t *buf, int io_len) -{ - static uint8_t bcast_addr[6] = {0xff,0xff,0xff,0xff,0xff,0xff}; el2_t *dev = (el2_t *)priv; - uint8_t pkthdr[4]; - uint8_t *startptr; - int rx_pages, avail; - int idx, nextpage; - int endbytes; - /* FIXME: move to upper layer */ - ui_sb_icon_update(SB_NETWORK, 1); + if ((addr & 0x3fff) >= 0x2000) + return(0xff); - if (io_len != 60) { - DEBUG("3C503: rx_frame with length %d\n", io_len); - } - - if ((dev->dp8390.CR.stop != 0) || (dev->dp8390.page_start == 0)) return; - - /* - * Add the pkt header + CRC to the length, and work - * out how many 256-byte pages the frame would occupy. - */ - rx_pages = (io_len + sizeof(pkthdr) + sizeof(uint32_t) + 255)/256; - if (dev->dp8390.curr_page < dev->dp8390.bound_ptr) { - avail = dev->dp8390.bound_ptr - dev->dp8390.curr_page; - } else { - avail = (dev->dp8390.page_stop - dev->dp8390.page_start) - - (dev->dp8390.curr_page - dev->dp8390.bound_ptr); - } - - /* - * Avoid getting into a buffer overflow condition by - * not attempting to do partial receives. The emulation - * to handle this condition seems particularly painful. - */ - if ((avail < rx_pages) -#if DP8390_NEVER_FULL_RING - || (avail == rx_pages) -#endif - ) { - DEBUG("3C503: no space\n"); - - /* FIXME: move to upper layer */ - ui_sb_icon_update(SB_NETWORK, 0); - return; - } - - if ((io_len < 40/*60*/) && !dev->dp8390.RCR.runts_ok) { - DEBUG("3C503: rejected small packet, length %d\n", io_len); - - /* FIXME: move to upper layer */ - ui_sb_icon_update(SB_NETWORK, 0); - return; - } - - /* Some computers don't care... */ - if (io_len < 60) - io_len = 60; - - DBGLOG(1, "3C503: RX %x:%x:%x:%x:%x:%x > %x:%x:%x:%x:%x:%x len %d\n", - buf[6], buf[7], buf[8], buf[9], buf[10], buf[11], - buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], io_len); - - /* Do address filtering if not in promiscuous mode. */ - if (! dev->dp8390.RCR.promisc) { - /* If this is a broadcast frame.. */ - if (! memcmp(buf, bcast_addr, 6)) { - /* Broadcast not enabled, we're done. */ - if (! dev->dp8390.RCR.broadcast) { - DEBUG("3C503: RX BC disabled\n"); - - /* FIXME: move to upper layer */ - ui_sb_icon_update(SB_NETWORK, 0); - return; - } - } - - /* If this is a multicast frame.. */ - else if (buf[0] & 0x01) { - /* Multicast not enabled, we're done. */ - if (! dev->dp8390.RCR.multicast) { - DEBUG("3C503: RX MC disabled\n"); - - /* FIXME: move to upper layer */ - ui_sb_icon_update(SB_NETWORK, 0); - return; - } - - /* Are we listening to this multicast address? */ - idx = mcast_index(buf); - if (! (dev->dp8390.mchash[idx>>3] & (1<<(idx&0x7)))) { - DEBUG("3C503: RX MC not listed\n"); - - /* FIXME: move to upper layer */ - ui_sb_icon_update(SB_NETWORK, 0); - return; - } - } - - /* Unicast, must be for us.. */ - else if (memcmp(buf, dev->dp8390.physaddr, 6)) return; - } else { - DEBUG("3C503: RX promiscuous receive\n"); - } - - nextpage = dev->dp8390.curr_page + rx_pages; - if (nextpage >= dev->dp8390.page_stop) - nextpage -= (dev->dp8390.page_stop - dev->dp8390.page_start); - - /* Set up packet header. */ - pkthdr[0] = 0x01; /* RXOK - packet is OK */ - if (buf[0] & 0x01) - pkthdr[0] |= 0x20; /* MULTICAST packet */ - pkthdr[1] = nextpage; /* ptr to next packet */ - pkthdr[2] = (uint8_t) ((io_len + sizeof(pkthdr)) & 0xff); /* length-low */ - pkthdr[3] = (uint8_t) ((io_len + sizeof(pkthdr)) >> 8); /* length-hi */ - DBGLOG(1, "3C503: RX pkthdr [%02x %02x %02x %02x]\n", - pkthdr[0], pkthdr[1], pkthdr[2], pkthdr[3]); - - /* Copy into buffer, update curpage, and signal interrupt if config'd */ - startptr = &dev->dp8390.mem[(dev->dp8390.curr_page * 256) - DP8390_WORD_MEMSTART]; - memcpy(startptr, pkthdr, sizeof(pkthdr)); - if ((nextpage > dev->dp8390.curr_page) || - ((dev->dp8390.curr_page + rx_pages) == dev->dp8390.page_stop)) { - memcpy(startptr+sizeof(pkthdr), buf, io_len); - } else { - endbytes = (dev->dp8390.page_stop - dev->dp8390.curr_page) * 256; - memcpy(startptr+sizeof(pkthdr), buf, endbytes-sizeof(pkthdr)); - startptr = &dev->dp8390.mem[(dev->dp8390.page_start * 256) - DP8390_WORD_MEMSTART]; - memcpy(startptr, buf+endbytes-sizeof(pkthdr), io_len-endbytes+8); - } - dev->dp8390.curr_page = nextpage; - - dev->dp8390.RSR.rx_ok = 1; - dev->dp8390.RSR.rx_mbit = (buf[0] & 0x01) ? 1 : 0; - dev->dp8390.ISR.pkt_rx = 1; - - if (dev->dp8390.IMR.rx_inte) - el2_interrupt(dev, 1); - - /* FIXME: move to upper layer */ - ui_sb_icon_update(SB_NETWORK, 0); + return(dev->dp8390.mem[addr & 0x1fff]); } static void -el2_close(void *priv) +ram_write(uint32_t addr, uint8_t val, priv_t priv) +{ + el2_t *dev = (el2_t *)priv; + + if ((addr & 0x3fff) >= 0x2000) + return; + + dev->dp8390.mem[addr & 0x1fff] = val; +} + + +static void +el2_close(priv_t priv) { el2_t *dev = (el2_t *)priv; @@ -1462,7 +1452,7 @@ el2_close(void *priv) } -static void * +static priv_t el2_init(const device_t *info, UNUSED(void *parent)) { uint32_t mac; @@ -1506,16 +1496,16 @@ el2_init(const device_t *info, UNUSED(void *parent)) } memcpy(dev->dp8390.physaddr, dev->maclocal, sizeof(dev->maclocal)); - INFO("I/O=%04x, IRQ=%d, MAC=%02x:%02x:%02x:%02x:%02x:%02x\n", + INFO("I/O=%04x, IRQ=%i, MAC=%02x:%02x:%02x:%02x:%02x:%02x\n", dev->base_address, dev->base_irq, - dev->dp8390.physaddr[0], dev->dp8390.physaddr[1], dev->dp8390.physaddr[2], - dev->dp8390.physaddr[3], dev->dp8390.physaddr[4], dev->dp8390.physaddr[5]); + dev->maclocal[0], dev->maclocal[1], dev->maclocal[2], + dev->maclocal[3], dev->maclocal[4], dev->maclocal[5]); /* Reset the board. */ el2_reset(dev); /* Attach ourselves to the network module. */ - if (! network_attach(dev, dev->dp8390.physaddr, el2_rx)) { + if (! network_attach(dev, dev->maclocal, el2_rx)) { el2_close(dev); return(NULL); @@ -1523,12 +1513,11 @@ el2_init(const device_t *info, UNUSED(void *parent)) /* Map this system into the memory map. */ mem_map_add(&dev->ram_mapping, dev->bios_addr, 0x4000, - el2_ram_read, NULL, NULL, - el2_ram_write, NULL, NULL, + ram_read,NULL,NULL, ram_write,NULL,NULL, NULL, MEM_MAPPING_EXTERNAL, dev); mem_map_disable(&dev->ram_mapping); - return(dev); + return((priv_t)dev); } diff --git a/src/devices/network/net_ne2000.c b/src/devices/network/net_ne2000.c index c6920df..94f6e77 100644 --- a/src/devices/network/net_ne2000.c +++ b/src/devices/network/net_ne2000.c @@ -16,7 +16,7 @@ * * FIXME: move statbar calls to upper layer * - * Version: @(#)net_ne2000.c 1.0.18 2019/05/05 + * Version: @(#)net_ne2000.c 1.0.19 2019/05/13 * * Based on @(#)ne2k.cc v1.56.2.1 2004/02/02 22:37:22 cbothamy * @@ -191,7 +191,7 @@ nic_interrupt(nic_t *dev, int set) /* Restore state to power-up, cancelling all I/O .*/ static void -nic_reset(void *priv) +nic_reset(priv_t priv) { nic_t *dev = (nic_t *)priv; dp8390_t *dp = &dev->dp8390; @@ -276,7 +276,7 @@ nic_reset(void *priv) static void -nic_soft_reset(void *priv) +nic_soft_reset(priv_t priv) { nic_t *dev = (nic_t *)priv; dp8390_t *dp = &dev->dp8390; @@ -295,7 +295,7 @@ nic_soft_reset(void *priv) * it is copied into it and the receive process is updated. */ static void -nic_rx(void *priv, uint8_t *buf, int io_len) +nic_rx(priv_t priv, uint8_t *buf, int io_len) { static uint8_t bcast_addr[6] = {0xff,0xff,0xff,0xff,0xff,0xff}; nic_t *dev = (nic_t *)priv; @@ -530,7 +530,7 @@ chipmem_read(nic_t *dev, uint32_t addr, unsigned int len) static void -chipmem_write(nic_t *dev, uint32_t addr, uint32_t val, unsigned len) +chipmem_write(nic_t *dev, uint32_t addr, uint32_t val, unsigned int len) { dp8390_t *dp = &dev->dp8390; @@ -659,7 +659,7 @@ asic_read(nic_t *dev, uint32_t off, unsigned int len) static void -asic_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) +asic_write(nic_t *dev, uint32_t off, uint32_t val, unsigned int len) { dp8390_t *dp = &dev->dp8390; @@ -856,7 +856,7 @@ page0_read(nic_t *dev, uint32_t off, unsigned int len) static void -page0_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) +page0_write(nic_t *dev, uint32_t off, uint32_t val, unsigned int len) { dp8390_t *dp = &dev->dp8390; uint8_t val2; @@ -1110,7 +1110,7 @@ page1_read(nic_t *dev, uint32_t off, unsigned int len) static void -page1_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) +page1_write(nic_t *dev, uint32_t off, uint32_t val, unsigned int len) { dp8390_t *dp = &dev->dp8390; @@ -1251,7 +1251,7 @@ page2_read(nic_t *dev, uint32_t off, unsigned int len) affect internal operation, but let them through for now and print a warning. */ static void -page2_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) +page2_write(nic_t *dev, uint32_t off, uint32_t val, unsigned int len) { dp8390_t *dp = &dev->dp8390; @@ -1361,7 +1361,7 @@ page3_read(nic_t *dev, uint32_t off, unsigned int len) static void -page3_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len) +page3_write(nic_t *dev, uint32_t off, uint32_t val, unsigned int len) { if (dev->board >= NE2K_RTL8019AS) { DBGLOG(2, "%s: Page3 write to register 0x%02x, len=%u, value=0x%04x\n", @@ -1512,7 +1512,7 @@ write_cr(nic_t *dev, uint32_t val) static uint32_t -nic_read(nic_t *dev, uint32_t addr, unsigned len) +nic_read(nic_t *dev, uint32_t addr, unsigned int len) { int off = addr - dev->base_address; uint32_t ret = 0; @@ -1551,14 +1551,14 @@ nic_read(nic_t *dev, uint32_t addr, unsigned len) static uint8_t -nic_readb(uint16_t addr, void *priv) +nic_readb(uint16_t addr, priv_t priv) { return(nic_read((nic_t *)priv, addr, 1)); } static uint16_t -nic_readw(uint16_t addr, void *priv) +nic_readw(uint16_t addr, priv_t priv) { nic_t *dev = (nic_t *)priv; @@ -1570,14 +1570,14 @@ nic_readw(uint16_t addr, void *priv) static uint32_t -nic_readl(uint16_t addr, void *priv) +nic_readl(uint16_t addr, priv_t priv) { return(nic_read((nic_t *)priv, addr, 4)); } static void -nic_write(nic_t *dev, uint32_t addr, uint32_t val, unsigned len) +nic_write(nic_t *dev, uint32_t addr, uint32_t val, unsigned int len) { int off = addr - dev->base_address; @@ -1617,14 +1617,14 @@ nic_write(nic_t *dev, uint32_t addr, uint32_t val, unsigned len) static void -nic_writeb(uint16_t addr, uint8_t val, void *priv) +nic_writeb(uint16_t addr, uint8_t val, priv_t priv) { nic_write((nic_t *)priv, addr, val, 1); } static void -nic_writew(uint16_t addr, uint16_t val, void *priv) +nic_writew(uint16_t addr, uint16_t val, priv_t priv) { nic_t *dev = (nic_t *)priv; @@ -1636,20 +1636,97 @@ nic_writew(uint16_t addr, uint16_t val, void *priv) static void -nic_writel(uint16_t addr, uint32_t val, void *priv) +nic_writel(uint16_t addr, uint32_t val, priv_t priv) { nic_write((nic_t *)priv, addr, val, 4); } -static void nic_iocheckset(nic_t *dev, uint16_t addr); -static void nic_iocheckremove(nic_t *dev, uint16_t addr); -static void nic_ioset(nic_t *dev, uint16_t addr); -static void nic_ioremove(nic_t *dev, uint16_t addr); +static void +nic_ioset(nic_t *dev, uint16_t addr) +{ + if (dev->is_mca) { + io_sethandler(addr, 16, + nic_readb, nic_readw, nic_readl, + nic_writeb, nic_writew, nic_writel, dev); + io_sethandler(addr+16, 16, + nic_readb, nic_readw, nic_readl, + nic_writeb, nic_writew, nic_writel, dev); + io_sethandler(addr+0x1f, 16, + nic_readb, nic_readw, nic_readl, + nic_writeb, nic_writew, nic_writel, dev); + } else if (dev->is_pci) { + io_sethandler(addr, 16, + nic_readb, nic_readw, nic_readl, + nic_writeb, nic_writew, nic_writel, dev); + io_sethandler(addr+16, 16, + nic_readb, nic_readw, nic_readl, + nic_writeb, nic_writew, nic_writel, dev); + io_sethandler(addr+0x1f, 1, + nic_readb, nic_readw, nic_readl, + nic_writeb, nic_writew, nic_writel, dev); + } else { + io_sethandler(addr, 16, + nic_readb,NULL,NULL, nic_writeb,NULL,NULL, dev); + if (dev->is_8bit) + io_sethandler(addr+16, 16, + nic_readb, NULL, NULL, + nic_writeb, NULL, NULL, dev); + else + io_sethandler(addr+16, 16, + nic_readb, nic_readw, NULL, + nic_writeb, nic_writew, NULL, dev); + io_sethandler(addr+0x1f, 1, + nic_readb, NULL, NULL, nic_writeb, NULL, NULL, dev); + } +} +static void +nic_ioremove(nic_t *dev, uint16_t addr) +{ + if (dev->is_mca) { + io_removehandler(addr, 16, + nic_readb, nic_readw, nic_readl, + nic_writeb, nic_writew, nic_writel, dev); + io_removehandler(addr+16, 16, + nic_readb, nic_readw, nic_readl, + nic_writeb, nic_writew, nic_writel, dev); + io_removehandler(addr+0x1f, 16, + nic_readb, nic_readw, nic_readl, + nic_writeb, nic_writew, nic_writel, dev); + } else if (dev->is_pci) { + io_removehandler(addr, 16, + nic_readb, nic_readw, nic_readl, + nic_writeb, nic_writew, nic_writel, dev); + io_removehandler(addr+16, 16, + nic_readb, nic_readw, nic_readl, + nic_writeb, nic_writew, nic_writel, dev); + io_removehandler(addr+0x1f, 1, + nic_readb, nic_readw, nic_readl, + nic_writeb, nic_writew, nic_writel, dev); + } else { + io_removehandler(addr, 16, + nic_readb, NULL, NULL, + nic_writeb, NULL, NULL, dev); + if (dev->is_8bit) + io_removehandler(addr+16, 16, + nic_readb, NULL, NULL, + nic_writeb, NULL, NULL, dev); + else + io_removehandler(addr+16, 16, + nic_readb, nic_readw, NULL, + nic_writeb, nic_writew, NULL, dev); + io_removehandler(addr+0x1f, 1, + nic_readb, NULL, NULL, + nic_writeb, NULL, NULL, dev); + } +} + + +/* FIXME: ISA-PNP handlers, should be moved to devices/system/isa.c */ static uint8_t -nic_pnp_io_check_readb(uint16_t addr, void *priv) +pnp_io_check_readb(uint16_t addr, priv_t priv) { nic_t *dev = (nic_t *)priv; @@ -1657,8 +1734,24 @@ nic_pnp_io_check_readb(uint16_t addr, void *priv) } +static void +pnp_io_checkset(nic_t *dev, uint16_t addr) +{ + io_sethandler(addr, 32, + pnp_io_check_readb,NULL,NULL, NULL,NULL,NULL, dev); +} + + +static void +pnp_io_checkremove(nic_t *dev, uint16_t addr) +{ + io_removehandler(addr, 32, + pnp_io_check_readb,NULL,NULL, NULL,NULL,NULL, dev); +} + + static uint8_t -nic_pnp_readb(uint16_t addr, void *priv) +pnp_readb(uint16_t addr, priv_t priv) { nic_t *dev = (nic_t *)priv; uint8_t bit, next_shift; @@ -1747,7 +1840,7 @@ nic_pnp_readb(uint16_t addr, void *priv) break; case 0x61: /* I/O base address bits[7:0] */ - ret = (dev->base_address & 0xFF); + ret = (dev->base_address & 0xff); break; /* Interrupt Configuration Registers */ @@ -1783,23 +1876,41 @@ nic_pnp_readb(uint16_t addr, void *priv) ret = (dev->pnp_csnsav); break; } - DBGLOG(1, "nic_pnp_readb(%04X) = %02X\n", addr, ret); + DBGLOG(1, "pnp_readb(%04X) = %02X\n", addr, ret); return(ret); } -static void nic_pnp_io_set(nic_t *dev, uint16_t read_addr); -static void nic_pnp_io_remove(nic_t *dev); +static void +pnp_io_set(nic_t *dev, uint16_t read_addr) +{ + if ((read_addr >= 0x0200) && (read_addr <= 0x03FF)) { + io_sethandler(read_addr, 1, + pnp_readb,NULL,NULL, NULL,NULL,NULL, dev); + } + + dev->pnp_read = read_addr; +} static void -nic_pnp_writeb(uint16_t addr, uint8_t val, void *priv) +pnp_io_remove(nic_t *dev) +{ + if ((dev->pnp_read >= 0x0200) && (dev->pnp_read <= 0x03FF)) { + io_removehandler(dev->pnp_read, 1, + pnp_readb,NULL,NULL, NULL,NULL,NULL, dev); + } +} + + +static void +pnp_writeb(uint16_t addr, uint8_t val, priv_t priv) { nic_t *dev = (nic_t *)priv; uint16_t new_addr = 0; - DBGLOG(1, "nic_pnp_writeb(%04X, %02X)\n", addr, val); + DBGLOG(1, "pnp_writeb(%04X, %02X)\n", addr, val); /* Plug and Play Registers */ switch(dev->pnp_address) { @@ -1808,15 +1919,15 @@ nic_pnp_writeb(uint16_t addr, uint8_t val, void *priv) new_addr = val; new_addr <<= 2; new_addr |= 3; - nic_pnp_io_remove(dev); - nic_pnp_io_set(dev, new_addr); + pnp_io_remove(dev); + pnp_io_set(dev, new_addr); DBGLOG(1, "PnP read data address now: %04X\n", new_addr); break; case 0x02: /* Config Control */ if (val & 0x01) { /* Reset command */ - nic_pnp_io_remove(dev); + pnp_io_remove(dev); memset(dev->pnp_regs, 0, 256); DBGLOG(1, "All logical devices reset\n"); } @@ -1866,9 +1977,9 @@ nic_pnp_writeb(uint16_t addr, uint8_t val, void *priv) case 0x31: /* I/O Range Check */ if ((dev->pnp_io_check ^ val) & 0x02) { - nic_iocheckremove(dev, dev->base_address); + pnp_io_checkremove(dev, dev->base_address); if (val & 0x02) - nic_iocheckset(dev, dev->base_address); + pnp_io_checkset(dev, dev->base_address); DBGLOG(1, "I/O range check %sabled\n", val & 0x02 ? "en" : "dis"); @@ -1913,38 +2024,15 @@ nic_pnp_writeb(uint16_t addr, uint8_t val, void *priv) dev->pnp_csn = 0; break; } - return; } static void -nic_pnp_io_set(nic_t *dev, uint16_t read_addr) -{ - if ((read_addr >= 0x0200) && (read_addr <= 0x03FF)) { - io_sethandler(read_addr, 1, - nic_pnp_readb,NULL,NULL, NULL,NULL,NULL, dev); - } - - dev->pnp_read = read_addr; -} - - -static void -nic_pnp_io_remove(nic_t *dev) -{ - if ((dev->pnp_read >= 0x0200) && (dev->pnp_read <= 0x03FF)) { - io_removehandler(dev->pnp_read, 1, - nic_pnp_readb,NULL,NULL, NULL,NULL,NULL, dev); - } -} - - -static void -nic_pnp_address_writeb(uint16_t addr, uint8_t val, void *priv) +pnp_address_writeb(uint16_t addr, uint8_t val, void *priv) { nic_t *dev = (nic_t *) priv; - /* DBGLOG(2, "nic_pnp_address_writeb(%04X, %02X)\n", addr, val); */ + /* DBGLOG(2, "pnp_address_writeb(%04X, %02X)\n", addr, val); */ switch(dev->pnp_phase) { case PNP_PHASE_WAIT_FOR_KEY: @@ -1960,107 +2048,6 @@ nic_pnp_address_writeb(uint16_t addr, uint8_t val, void *priv) dev->pnp_address = val; break; } - return; -} - - -static void -nic_iocheckset(nic_t *dev, uint16_t addr) -{ - io_sethandler(addr, 32, - nic_pnp_io_check_readb, NULL, NULL, - NULL, NULL, NULL, dev); -} - - -static void -nic_iocheckremove(nic_t *dev, uint16_t addr) -{ - io_removehandler(addr, 32, - nic_pnp_io_check_readb, NULL, NULL, - NULL, NULL, NULL, dev); -} - - -static void -nic_ioset(nic_t *dev, uint16_t addr) -{ - if (dev->is_mca) { - io_sethandler(addr, 16, - nic_readb, nic_readw, nic_readl, - nic_writeb, nic_writew, nic_writel, dev); - io_sethandler(addr+16, 16, - nic_readb, nic_readw, nic_readl, - nic_writeb, nic_writew, nic_writel, dev); - io_sethandler(addr+0x1f, 16, - nic_readb, nic_readw, nic_readl, - nic_writeb, nic_writew, nic_writel, dev); - } else if (dev->is_pci) { - io_sethandler(addr, 16, - nic_readb, nic_readw, nic_readl, - nic_writeb, nic_writew, nic_writel, dev); - io_sethandler(addr+16, 16, - nic_readb, nic_readw, nic_readl, - nic_writeb, nic_writew, nic_writel, dev); - io_sethandler(addr+0x1f, 1, - nic_readb, nic_readw, nic_readl, - nic_writeb, nic_writew, nic_writel, dev); - } else { - io_sethandler(addr, 16, - nic_readb,NULL,NULL, nic_writeb,NULL,NULL, dev); - if (dev->is_8bit) - io_sethandler(addr+16, 16, - nic_readb, NULL, NULL, - nic_writeb, NULL, NULL, dev); - else - io_sethandler(addr+16, 16, - nic_readb, nic_readw, NULL, - nic_writeb, nic_writew, NULL, dev); - io_sethandler(addr+0x1f, 1, - nic_readb, NULL, NULL, nic_writeb, NULL, NULL, dev); - } -} - - -static void -nic_ioremove(nic_t *dev, uint16_t addr) -{ - if (dev->is_mca) { - io_removehandler(addr, 16, - nic_readb, nic_readw, nic_readl, - nic_writeb, nic_writew, nic_writel, dev); - io_removehandler(addr+16, 16, - nic_readb, nic_readw, nic_readl, - nic_writeb, nic_writew, nic_writel, dev); - io_removehandler(addr+0x1f, 16, - nic_readb, nic_readw, nic_readl, - nic_writeb, nic_writew, nic_writel, dev); - } else if (dev->is_pci) { - io_removehandler(addr, 16, - nic_readb, nic_readw, nic_readl, - nic_writeb, nic_writew, nic_writel, dev); - io_removehandler(addr+16, 16, - nic_readb, nic_readw, nic_readl, - nic_writeb, nic_writew, nic_writel, dev); - io_removehandler(addr+0x1f, 1, - nic_readb, nic_readw, nic_readl, - nic_writeb, nic_writew, nic_writel, dev); - } else { - io_removehandler(addr, 16, - nic_readb, NULL, NULL, - nic_writeb, NULL, NULL, dev); - if (dev->is_8bit) - io_removehandler(addr+16, 16, - nic_readb, NULL, NULL, - nic_writeb, NULL, NULL, dev); - else - io_removehandler(addr+16, 16, - nic_readb, nic_readw, NULL, - nic_writeb, nic_writew, NULL, dev); - io_removehandler(addr+0x1f, 1, - nic_readb, NULL, NULL, - nic_writeb, NULL, NULL, dev); - } } @@ -2089,7 +2076,7 @@ nic_update_bios(nic_t *dev) static uint8_t -nic_pci_read(int func, int addr, void *priv) +nic_pci_read(int func, int addr, priv_t priv) { nic_t *dev = (nic_t *)priv; uint8_t ret = 0x00; @@ -2197,7 +2184,7 @@ nic_pci_read(int func, int addr, void *priv) static void -nic_pci_write(int func, int addr, uint8_t val, void *priv) +nic_pci_write(int func, int addr, uint8_t val, priv_t priv) { nic_t *dev = (nic_t *)priv; uint8_t valxor; @@ -2288,46 +2275,8 @@ nic_pci_write(int func, int addr, uint8_t val, void *priv) } -static void -nic_rom_init(nic_t *dev, wchar_t *s) -{ - uint32_t temp; - FILE *f; - - if (s == NULL) return; - - if (dev->bios_addr == 0) return; - - if ((f = rom_fopen(s, L"rb")) != NULL) { - fseek(f, 0L, SEEK_END); - temp = ftell(f); - fclose(f); - dev->bios_size = 0x10000; - if (temp <= 0x8000) - dev->bios_size = 0x8000; - if (temp <= 0x4000) - dev->bios_size = 0x4000; - if (temp <= 0x2000) - dev->bios_size = 0x2000; - dev->bios_mask = (dev->bios_size >> 8) & 0xff; - dev->bios_mask = (0x100 - dev->bios_mask) & 0xff; - } else { - dev->bios_addr = 0x00000; - dev->bios_size = 0; - return; - } - - /* Create a memory mapping for the space. */ - rom_init(&dev->bios_rom, s, dev->bios_addr, - dev->bios_size, dev->bios_size-1, 0, MEM_MAPPING_EXTERNAL); - - INFO("%s: BIOS configured at %06lX (size %lu)\n", - dev->name, dev->bios_addr, dev->bios_size); -} - - static uint8_t -nic_mca_read(int port, void *priv) +nic_mca_read(int port, priv_t priv) { nic_t *dev = (nic_t *)priv; @@ -2336,7 +2285,7 @@ nic_mca_read(int port, void *priv) static void -nic_mca_write(int port, uint8_t val, void *priv) +nic_mca_write(int port, uint8_t val, priv_t priv) { nic_t *dev = (nic_t *)priv; @@ -2379,7 +2328,41 @@ nic_mca_write(int port, uint8_t val, void *priv) static void -nic_close(void *priv) +nic_rom_init(nic_t *dev, const wchar_t *fn) +{ + uint32_t temp; + FILE *fp; + + if ((fp = rom_fopen(fn, L"rb")) != NULL) { + fseek(fp, 0L, SEEK_END); + temp = ftell(fp); + fclose(fp); + dev->bios_size = 0x10000; + if (temp <= 0x8000) + dev->bios_size = 0x8000; + if (temp <= 0x4000) + dev->bios_size = 0x4000; + if (temp <= 0x2000) + dev->bios_size = 0x2000; + dev->bios_mask = (dev->bios_size >> 8) & 0xff; + dev->bios_mask = (0x100 - dev->bios_mask) & 0xff; + } else { + dev->bios_addr = 0x00000; + dev->bios_size = 0; + return; + } + + /* Create a memory mapping for the space. */ + rom_init(&dev->bios_rom, fn, dev->bios_addr, + dev->bios_size, dev->bios_size-1, 0, MEM_MAPPING_EXTERNAL); + + INFO("%s: BIOS configured at %06lX (size %iKB)\n", + dev->name, dev->bios_addr, dev->bios_size>>10); +} + + +static void +nic_close(priv_t priv) { nic_t *dev = (nic_t *)priv; @@ -2394,12 +2377,12 @@ nic_close(void *priv) } -static void * +static priv_t nic_init(const device_t *info, UNUSED(void *parent)) { char *ansi_id = "REALTEK PLUG & PLAY ETHERNET CARD"; + const wchar_t *fn; uint32_t mac; - wchar_t *fn; nic_t *dev; int c; @@ -2519,7 +2502,7 @@ nic_init(const device_t *info, UNUSED(void *parent)) dev->maclocal[5] = (mac & 0xff); } - INFO("%s: I/O=%04x, IRQ=%d, MAC=%02x:%02x:%02x:%02x:%02x:%02x\n", + INFO("%s: I/O=%04x, IRQ=%i, MAC=%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, dev->base_address, dev->base_irq, dev->maclocal[0], dev->maclocal[1], dev->maclocal[2], dev->maclocal[3], dev->maclocal[4], dev->maclocal[5]); @@ -2572,8 +2555,8 @@ nic_init(const device_t *info, UNUSED(void *parent)) nic_pci_read, nic_pci_write, dev); } else { io_sethandler(0x0279, 1, - NULL, NULL, NULL, - nic_pnp_address_writeb, NULL, NULL, dev); + NULL,NULL,NULL, + pnp_address_writeb,NULL,NULL, dev); dev->pnp_id = PNP_DEVID; dev->pnp_id <<= 32LL; @@ -2654,7 +2637,7 @@ nic_init(const device_t *info, UNUSED(void *parent)) io_sethandler(0x0A79, 1, NULL, NULL, NULL, - nic_pnp_writeb, NULL, NULL, dev); + pnp_writeb, NULL, NULL, dev); } } @@ -2665,19 +2648,20 @@ nic_init(const device_t *info, UNUSED(void *parent)) nic_reset(dev); /* Attach ourselves to the network module. */ - if (! network_attach(dev, dev->dp8390.physaddr, nic_rx)) { + if (! network_attach(dev, dev->maclocal, nic_rx)) { nic_close(dev); return(NULL); } - INFO("%s: %s attached IO=0x%X IRQ=%d\n", dev->name, + INFO("%s: %s attached IO=0x%X IRQ=%i\n", dev->name, dev->is_pci?"PCI":"ISA", dev->base_address, dev->base_irq); /* Set up our BIOS ROM space, if any. */ - nic_rom_init(dev, fn); + if ((fn != NULL) && (dev->bios_addr > 0)) + nic_rom_init(dev, fn); - return(dev); + return((priv_t)dev); } diff --git a/src/devices/network/net_wd80x3.c b/src/devices/network/net_wd80x3.c index b13ea98..265288e 100644 --- a/src/devices/network/net_wd80x3.c +++ b/src/devices/network/net_wd80x3.c @@ -7,11 +7,14 @@ * This file is part of the VARCem Project. * * Implementation of the following network controllers: - * - SMC/WD 8003E (ISA 8-bit); - * - SMC/WD 8013EBT (ISA 16-bit); - * - SMC/WD 8013EP/A (MCA). * - * Version: @(#)net_wd80x3.c 1.0.7 2019/05/02 + * - SMC/WD 8003E (ISA 8-bit) + * - SMC/WD 8013EBT (ISA 16-bit) + * - SMC/WD 8013EP/A (MCA) + * + * as well as a number of compatibles. + * + * Version: @(#)net_wd80x3.c 1.0.8 2019/05/13 * * Authors: Fred N. van Kempen, * TheCollector1995, @@ -99,7 +102,7 @@ typedef struct { /* POS registers, MCA boards only */ uint8_t pos_regs[8]; - + dp8390_t dp8390; uint32_t ram_addr, @@ -116,73 +119,168 @@ typedef struct { } nic_t; -static void nic_rx(void *, uint8_t *, int); -static void nic_tx(nic_t *, uint32_t); - - static void nic_interrupt(nic_t *dev, int set) { if (set) picint(1 << dev->base_irq); - else + else picintc(1 << dev->base_irq); } -/* reset - restore state to power-up, cancelling all i/o */ +/* + * Called by the platform-specific code when an Ethernet frame + * has been received. The destination address is tested to see + * if it should be accepted, and if the RX ring has enough room, + * it is copied into it and the receive process is updated. + */ static void -nic_reset(void *priv) +nic_rx(priv_t priv, uint8_t *buf, int io_len) { + static uint8_t bcast_addr[6] = {0xff,0xff,0xff,0xff,0xff,0xff}; nic_t *dev = (nic_t *)priv; + uint8_t pkthdr[4]; + uint8_t *startptr; + int pages, avail; + int idx, nextpage; + int endbytes; - DEBUG("%s: reset\n", dev->name); + //FIXME: move to upper layer + ui_sb_icon_update(SB_NETWORK, 1); + + if (io_len != 60) { + DBGLOG(1, "%s: rx_frame with length %d\n", dev->name, io_len); + } + + if ((dev->dp8390.CR.stop != 0) || (dev->dp8390.page_start == 0)) return; + + /* + * Add the pkt header + CRC to the length, and work + * out how many 256-byte pages the frame would occupy. + */ + pages = (io_len + sizeof(pkthdr) + sizeof(uint32_t) + 255)/256; + if (dev->dp8390.curr_page < dev->dp8390.bound_ptr) { + avail = dev->dp8390.bound_ptr - dev->dp8390.curr_page; + } else { + avail = (dev->dp8390.page_stop - dev->dp8390.page_start) - + (dev->dp8390.curr_page - dev->dp8390.bound_ptr); + } + + /* + * Avoid getting into a buffer overflow condition by + * not attempting to do partial receives. The emulation + * to handle this condition seems particularly painful. + */ + if ((avail < pages) +#if DP8390_NEVER_FULL_RING + || (avail == pages) +#endif + ) { + DEBUG("%s: no space\n", dev->name); + ui_sb_icon_update(SB_NETWORK, 0); + return; + } + + if ((io_len < 40/*60*/) && !dev->dp8390.RCR.runts_ok) { + DEBUG("%s: rejected small packet, length %d\n", dev->name, io_len); + ui_sb_icon_update(SB_NETWORK, 0); + return; + } + + /* Some computers don't care... */ + if (io_len < 60) + io_len = 60; + + DBGLOG(1, "%s: RX %x:%x:%x:%x:%x:%x > %x:%x:%x:%x:%x:%x len %d\n", + dev->name, buf[6], buf[7], buf[8], buf[9], buf[10], buf[11], + buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], io_len); + + /* Do address filtering if not in promiscuous mode. */ + if (! dev->dp8390.RCR.promisc) { + /* If this is a broadcast frame.. */ + if (! memcmp(buf, bcast_addr, 6)) { + /* Broadcast not enabled, we're done. */ + if (! dev->dp8390.RCR.broadcast) { + DEBUG("%s: RX BC disabled\n", dev->name); + ui_sb_icon_update(SB_NETWORK, 0); + return; + } + } + + /* If this is a multicast frame.. */ + else if (buf[0] & 0x01) { + /* Multicast not enabled, we're done. */ + if (! dev->dp8390.RCR.multicast) { + DEBUG("%s: RX MC disabled\n", dev->name); + ui_sb_icon_update(SB_NETWORK, 0); + return; + } + + /* Are we listening to this multicast address? */ + idx = mcast_index(buf); + if (! (dev->dp8390.mchash[idx>>3] & (1<<(idx&0x7)))) { + DEBUG("%s: RX MC not listed\n", dev->name); + ui_sb_icon_update(SB_NETWORK, 0); + return; + } + } + + /* Unicast, must be for us.. */ + else if (memcmp(buf, dev->dp8390.physaddr, 6)) return; + } else { + DBGLOG(1, "%s: RX promiscuous receive\n", dev->name); + } + + nextpage = dev->dp8390.curr_page + pages; + if (nextpage >= dev->dp8390.page_stop) + nextpage -= (dev->dp8390.page_stop - dev->dp8390.page_start); + + /* Set up packet header. */ + pkthdr[0] = 0x01; /* RXOK - packet is OK */ + pkthdr[1] = nextpage; /* ptr to next packet */ + pkthdr[2] = (uint8_t) ((io_len + sizeof(pkthdr)) & 0xff); /* length-low */ + pkthdr[3] = (uint8_t) ((io_len + sizeof(pkthdr)) >> 8); /* length-hi */ + DBGLOG(1, "%s: RX pkthdr [%02x %02x %02x %02x]\n", + dev->name, pkthdr[0], pkthdr[1], pkthdr[2], pkthdr[3]); + + /* Copy into buffer, update curpage, and signal interrupt if config'd */ + startptr = dev->dp8390.mem + (dev->dp8390.curr_page * 256); + memcpy(startptr, pkthdr, sizeof(pkthdr)); + if ((nextpage > dev->dp8390.curr_page) || + ((dev->dp8390.curr_page + pages) == dev->dp8390.page_stop)) { + memcpy(startptr+sizeof(pkthdr), buf, io_len); + } else { + endbytes = (dev->dp8390.page_stop - dev->dp8390.curr_page) * 256; + memcpy(startptr+sizeof(pkthdr), buf, endbytes-sizeof(pkthdr)); + startptr = dev->dp8390.mem + (dev->dp8390.page_start * 256); + memcpy(startptr, buf+endbytes-sizeof(pkthdr), io_len-endbytes+8); + } + dev->dp8390.curr_page = nextpage; + + dev->dp8390.RSR.rx_ok = 1; + dev->dp8390.RSR.rx_mbit = (buf[0] & 0x01) ? 1 : 0; + dev->dp8390.ISR.pkt_rx = 1; + + if (dev->dp8390.IMR.rx_inte) + nic_interrupt(dev, 1); + + ui_sb_icon_update(SB_NETWORK, 0); +} + + +static void +nic_tx(nic_t *dev, uint32_t val) +{ + dev->dp8390.CR.tx_packet = 0; + dev->dp8390.TSR.tx_ok = 1; + dev->dp8390.ISR.pkt_tx = 1; + + /* Generate an interrupt if not masked */ + if (dev->dp8390.IMR.tx_inte) + nic_interrupt(dev, 1); - /* Initialize the MAC address area by doubling the physical address */ - dev->macaddr[0] = dev->dp8390.physaddr[0]; - dev->macaddr[1] = dev->dp8390.physaddr[1]; - dev->macaddr[2] = dev->dp8390.physaddr[2]; - dev->macaddr[3] = dev->dp8390.physaddr[3]; - dev->macaddr[4] = dev->dp8390.physaddr[4]; - dev->macaddr[5] = dev->dp8390.physaddr[5]; - - /* Zero out registers and memory */ - memset(&dev->dp8390.CR, 0x00, sizeof(dev->dp8390.CR) ); - memset(&dev->dp8390.ISR, 0x00, sizeof(dev->dp8390.ISR)); - memset(&dev->dp8390.IMR, 0x00, sizeof(dev->dp8390.IMR)); - memset(&dev->dp8390.DCR, 0x00, sizeof(dev->dp8390.DCR)); - memset(&dev->dp8390.TCR, 0x00, sizeof(dev->dp8390.TCR)); - memset(&dev->dp8390.TSR, 0x00, sizeof(dev->dp8390.TSR)); - memset(&dev->dp8390.RSR, 0x00, sizeof(dev->dp8390.RSR)); dev->dp8390.tx_timer_active = 0; - dev->dp8390.local_dma = 0; - dev->dp8390.page_start = 0; - dev->dp8390.page_stop = 0; - dev->dp8390.bound_ptr = 0; - dev->dp8390.tx_page_start = 0; - dev->dp8390.num_coll = 0; - dev->dp8390.tx_bytes = 0; - dev->dp8390.fifo = 0; - dev->dp8390.remote_dma = 0; - dev->dp8390.remote_start = 0; - dev->dp8390.remote_bytes = 0; - dev->dp8390.tallycnt_0 = 0; - dev->dp8390.tallycnt_1 = 0; - dev->dp8390.tallycnt_2 = 0; - dev->dp8390.curr_page = 0; - dev->dp8390.rempkt_ptr = 0; - dev->dp8390.localpkt_ptr = 0; - dev->dp8390.address_cnt = 0; - - memset(&dev->dp8390.mem, 0x00, sizeof(dev->dp8390.mem)); - - /* Set power-up conditions */ - dev->dp8390.CR.stop = 1; - dev->dp8390.CR.rdma_cmd = 4; - dev->dp8390.ISR.reset = 1; - dev->dp8390.DCR.longaddr = 1; - - nic_interrupt(dev, 0); } @@ -209,242 +307,6 @@ chipmem_read(nic_t *dev, uint32_t addr, unsigned int len) } -static uint32_t -ram_read(uint32_t addr, unsigned len, void *priv) -{ - nic_t *dev = (nic_t *)priv; - uint32_t ret; - - if ((addr & 0x3fff) >= 0x2000) { - if (len == 2) - return 0xffff; - else if (len == 1) - return 0xff; - else - return 0xffffffff; - } - - ret = dev->dp8390.mem[addr & 0x1fff]; - - if (len == 2 || len == 4) - ret |= dev->dp8390.mem[(addr+1) & 0x1fff] << 8; - - if (len == 4) { - ret |= dev->dp8390.mem[(addr+2) & 0x1fff] << 16; - ret |= dev->dp8390.mem[(addr+3) & 0x1fff] << 24; - } - - return ret; -} - - -static uint8_t -ram_readb(uint32_t addr, void *priv) -{ - nic_t *dev = (nic_t *)priv; - - return ram_read(addr, 1, dev); -} - - -static uint16_t -ram_readw(uint32_t addr, void *priv) -{ - nic_t *dev = (nic_t *)priv; - - return ram_read(addr, 2, dev); -} - - -static uint32_t -ram_readl(uint32_t addr, void *priv) -{ - nic_t *dev = (nic_t *)priv; - - return ram_read(addr, 4, dev); -} - - -static void -ram_write(uint32_t addr, uint32_t val, unsigned len, void *priv) -{ - nic_t *dev = (nic_t *)priv; - - if ((addr & 0x3fff) >= 0x2000) - return; - - dev->dp8390.mem[addr & 0x1fff] = val & 0xff; - if (len == 2 || len == 4) - dev->dp8390.mem[(addr+1) & 0x1fff] = val >> 8; - if (len == 4) { - dev->dp8390.mem[(addr+2) & 0x1fff] = val >> 16; - dev->dp8390.mem[(addr+3) & 0x1fff] = val >> 24; - } -} - - -static void -ram_writeb(uint32_t addr, uint8_t val, void *priv) -{ - nic_t *dev = (nic_t *)priv; - - ram_write(addr, val, 1, dev); -} - - -static void -ram_writew(uint32_t addr, uint16_t val, void *priv) -{ - nic_t *dev = (nic_t *)priv; - - ram_write(addr, val, 2, dev); -} - - -static void -ram_writel(uint32_t addr, uint32_t val, void *priv) -{ - nic_t *dev = (nic_t *)priv; - - ram_write(addr, val, 4, dev); -} - - -static uint32_t -smc_read(nic_t *dev, uint32_t off) -{ - uint32_t sum; - uint32_t ret = 0; - - switch(off) { - case 0x00: - break; - - case 0x01: - if (dev->board == WD8003E) - ret = dev->dp8390.physaddr[0]; - if (dev->board == WD8013EPA) - ret = dev->reg1; - break; - - case 0x02: - if (dev->board == WD8003E) - ret = dev->dp8390.physaddr[1]; - break; - - case 0x03: - if (dev->board == WD8003E) - ret = dev->dp8390.physaddr[2]; - break; - - case 0x04: - if (dev->board == WD8003E) - ret = dev->dp8390.physaddr[3]; - break; - - case 0x05: - if (dev->board == WD8003E) - ret = dev->dp8390.physaddr[4]; - if (dev->board == WD8013EPA) - ret = dev->reg5; - break; - - case 0x06: - if (dev->board == WD8003E) - ret = dev->dp8390.physaddr[5]; - break; - - case 0x07: - if (dev->board == WD8013EPA) { - if (dev->if_chip != 0x35 && dev->if_chip != 0x3A) { - ret = 0; - break; - } - - ret = dev->if_chip; - } - break; - - case 0x08: - case 0x09: - case 0x0a: - case 0x0b: - case 0x0c: - case 0x0d: - ret = dev->dp8390.physaddr[off - 8]; - break; - - case 0x0e: - ret = dev->board_chip; - break; - - case 0x0f: - /*This has to return the byte that adds up to 0xFF*/ - sum = (dev->dp8390.physaddr[0] + \ - dev->dp8390.physaddr[1] + \ - dev->dp8390.physaddr[2] + \ - dev->dp8390.physaddr[3] + \ - dev->dp8390.physaddr[4] + \ - dev->dp8390.physaddr[5] + \ - dev->board_chip); - - ret = 0xff - (sum & 0xff); - break; - } - - DBGLOG(2, "%s: ASIC read addr=0x%02x, value=0x%04x\n", - dev->name, (unsigned)off, (unsigned)ret); - - return(ret); -} - - -static void -smc_write(nic_t *dev, uint32_t off, uint32_t val) -{ - DBGLOG(2, "%s: ASIC write addr=0x%02x, value=0x%04x\n", - dev->name, (unsigned)off, (unsigned)val); - - switch(off) { - case 0x00: /* WD Control register */ - if (val & 0x80) { - dev->dp8390.ISR.reset = 1; - return; - } - - mem_map_disable(&dev->ram_mapping); - - if (val & 0x40) - mem_map_enable(&dev->ram_mapping); - break; - - case 0x01: - dev->reg1 = val; - break; - - case 0x04: - break; - - case 0x05: - dev->reg5 = val; - break; - - case 0x06: - break; - - case 0x07: - dev->if_chip = val; - break; - - default: - /* Invalid, but happens under Win95 device detection. */ - DEBUG("%s: ASIC write invalid address %04x, ignoring\n", - dev->name, (unsigned)off); - break; - } -} - - /* Handle reads/writes to the 'zeroth' page of the DS8390 register file. */ static uint8_t page0_read(nic_t *dev, uint32_t off) @@ -1072,8 +934,198 @@ write_cr(nic_t *dev, uint8_t val) } +static void +nic_reset(priv_t priv) +{ + nic_t *dev = (nic_t *)priv; + + DEBUG("%s: reset\n", dev->name); + + /* Initialize the MAC address area by doubling the physical address */ + dev->macaddr[0] = dev->dp8390.physaddr[0]; + dev->macaddr[1] = dev->dp8390.physaddr[1]; + dev->macaddr[2] = dev->dp8390.physaddr[2]; + dev->macaddr[3] = dev->dp8390.physaddr[3]; + dev->macaddr[4] = dev->dp8390.physaddr[4]; + dev->macaddr[5] = dev->dp8390.physaddr[5]; + + /* Zero out registers and memory */ + memset(&dev->dp8390.CR, 0x00, sizeof(dev->dp8390.CR) ); + memset(&dev->dp8390.ISR, 0x00, sizeof(dev->dp8390.ISR)); + memset(&dev->dp8390.IMR, 0x00, sizeof(dev->dp8390.IMR)); + memset(&dev->dp8390.DCR, 0x00, sizeof(dev->dp8390.DCR)); + memset(&dev->dp8390.TCR, 0x00, sizeof(dev->dp8390.TCR)); + memset(&dev->dp8390.TSR, 0x00, sizeof(dev->dp8390.TSR)); + memset(&dev->dp8390.RSR, 0x00, sizeof(dev->dp8390.RSR)); + dev->dp8390.tx_timer_active = 0; + dev->dp8390.local_dma = 0; + dev->dp8390.page_start = 0; + dev->dp8390.page_stop = 0; + dev->dp8390.bound_ptr = 0; + dev->dp8390.tx_page_start = 0; + dev->dp8390.num_coll = 0; + dev->dp8390.tx_bytes = 0; + dev->dp8390.fifo = 0; + dev->dp8390.remote_dma = 0; + dev->dp8390.remote_start = 0; + dev->dp8390.remote_bytes = 0; + dev->dp8390.tallycnt_0 = 0; + dev->dp8390.tallycnt_1 = 0; + dev->dp8390.tallycnt_2 = 0; + dev->dp8390.curr_page = 0; + dev->dp8390.rempkt_ptr = 0; + dev->dp8390.localpkt_ptr = 0; + dev->dp8390.address_cnt = 0; + + memset(&dev->dp8390.mem, 0x00, sizeof(dev->dp8390.mem)); + + /* Set power-up conditions */ + dev->dp8390.CR.stop = 1; + dev->dp8390.CR.rdma_cmd = 4; + dev->dp8390.ISR.reset = 1; + dev->dp8390.DCR.longaddr = 1; + + nic_interrupt(dev, 0); +} + + +static uint32_t +smc_read(nic_t *dev, uint32_t off) +{ + uint32_t sum; + uint32_t ret = 0; + + switch(off) { + case 0x00: + break; + + case 0x01: + if (dev->board == WD8003E) + ret = dev->dp8390.physaddr[0]; + if (dev->board == WD8013EPA) + ret = dev->reg1; + break; + + case 0x02: + if (dev->board == WD8003E) + ret = dev->dp8390.physaddr[1]; + break; + + case 0x03: + if (dev->board == WD8003E) + ret = dev->dp8390.physaddr[2]; + break; + + case 0x04: + if (dev->board == WD8003E) + ret = dev->dp8390.physaddr[3]; + break; + + case 0x05: + if (dev->board == WD8003E) + ret = dev->dp8390.physaddr[4]; + if (dev->board == WD8013EPA) + ret = dev->reg5; + break; + + case 0x06: + if (dev->board == WD8003E) + ret = dev->dp8390.physaddr[5]; + break; + + case 0x07: + if (dev->board == WD8013EPA) { + if (dev->if_chip != 0x35 && dev->if_chip != 0x3A) { + ret = 0; + break; + } + + ret = dev->if_chip; + } + break; + + case 0x08: + case 0x09: + case 0x0a: + case 0x0b: + case 0x0c: + case 0x0d: + ret = dev->dp8390.physaddr[off - 8]; + break; + + case 0x0e: + ret = dev->board_chip; + break; + + case 0x0f: + /*This has to return the byte that adds up to 0xFF*/ + sum = (dev->dp8390.physaddr[0] + \ + dev->dp8390.physaddr[1] + \ + dev->dp8390.physaddr[2] + \ + dev->dp8390.physaddr[3] + \ + dev->dp8390.physaddr[4] + \ + dev->dp8390.physaddr[5] + \ + dev->board_chip); + + ret = 0xff - (sum & 0xff); + break; + } + + DBGLOG(2, "%s: ASIC read addr=0x%02x, value=0x%04x\n", + dev->name, (unsigned)off, (unsigned)ret); + + return(ret); +} + + +static void +smc_write(nic_t *dev, uint32_t off, uint32_t val) +{ + DBGLOG(2, "%s: ASIC write addr=0x%02x, value=0x%04x\n", + dev->name, (unsigned)off, (unsigned)val); + + switch(off) { + case 0x00: /* WD Control register */ + if (val & 0x80) { + dev->dp8390.ISR.reset = 1; + return; + } + + mem_map_disable(&dev->ram_mapping); + + if (val & 0x40) + mem_map_enable(&dev->ram_mapping); + break; + + case 0x01: + dev->reg1 = val; + break; + + case 0x04: + break; + + case 0x05: + dev->reg5 = val; + break; + + case 0x06: + break; + + case 0x07: + dev->if_chip = val; + break; + + default: + /* Invalid, but happens under Win95 device detection. */ + DEBUG("%s: ASIC write invalid address %04x, ignoring\n", + dev->name, (unsigned)off); + break; + } +} + + static uint8_t -nic_readb(uint16_t addr, void *priv) +nic_readb(uint16_t addr, priv_t priv) { nic_t *dev = (nic_t *)priv; int off = addr - dev->base_address; @@ -1109,7 +1161,7 @@ nic_readb(uint16_t addr, void *priv) static void -nic_writeb(uint16_t addr, uint8_t val, void *priv) +nic_writeb(uint16_t addr, uint8_t val, priv_t priv) { nic_t *dev = (nic_t *)priv; int off = addr - dev->base_address; @@ -1141,7 +1193,7 @@ static void nic_ioset(nic_t *dev, uint16_t addr) { io_sethandler(addr, 0x20, - nic_readb, NULL, NULL, nic_writeb, NULL, NULL, dev); + nic_readb,NULL,NULL, nic_writeb,NULL,NULL, dev); } @@ -1149,167 +1201,113 @@ static void nic_ioremove(nic_t *dev, uint16_t addr) { io_removehandler(addr, 0x20, - nic_readb, NULL, NULL, nic_writeb, NULL, NULL, dev); + nic_readb,NULL,NULL, nic_writeb,NULL,NULL, dev); } -/* - * Called by the platform-specific code when an Ethernet frame - * has been received. The destination address is tested to see - * if it should be accepted, and if the RX ring has enough room, - * it is copied into it and the receive process is updated. - */ -static void -nic_rx(void *priv, uint8_t *buf, int io_len) +static uint32_t +ram_read(priv_t priv, uint32_t addr, int len) { - static uint8_t bcast_addr[6] = {0xff,0xff,0xff,0xff,0xff,0xff}; nic_t *dev = (nic_t *)priv; - uint8_t pkthdr[4]; - uint8_t *startptr; - int pages, avail; - int idx, nextpage; - int endbytes; + uint32_t ret; - //FIXME: move to upper layer - ui_sb_icon_update(SB_NETWORK, 1); - - if (io_len != 60) { - DBGLOG(1, "%s: rx_frame with length %d\n", dev->name, io_len); + if ((addr & 0x3fff) >= 0x2000) { + if (len == 2) + return 0xffff; + else if (len == 1) + return 0xff; + else + return 0xffffffff; } - if ((dev->dp8390.CR.stop != 0) || (dev->dp8390.page_start == 0)) return; + ret = dev->dp8390.mem[addr & 0x1fff]; - /* - * Add the pkt header + CRC to the length, and work - * out how many 256-byte pages the frame would occupy. - */ - pages = (io_len + sizeof(pkthdr) + sizeof(uint32_t) + 255)/256; - if (dev->dp8390.curr_page < dev->dp8390.bound_ptr) { - avail = dev->dp8390.bound_ptr - dev->dp8390.curr_page; - } else { - avail = (dev->dp8390.page_stop - dev->dp8390.page_start) - - (dev->dp8390.curr_page - dev->dp8390.bound_ptr); + if (len == 2 || len == 4) + ret |= dev->dp8390.mem[(addr+1) & 0x1fff] << 8; + + if (len == 4) { + ret |= dev->dp8390.mem[(addr+2) & 0x1fff] << 16; + ret |= dev->dp8390.mem[(addr+3) & 0x1fff] << 24; } - /* - * Avoid getting into a buffer overflow condition by - * not attempting to do partial receives. The emulation - * to handle this condition seems particularly painful. - */ - if ((avail < pages) -#if DP8390_NEVER_FULL_RING - || (avail == pages) -#endif - ) { - DEBUG("%s: no space\n", dev->name); - ui_sb_icon_update(SB_NETWORK, 0); - return; - } - - if ((io_len < 40/*60*/) && !dev->dp8390.RCR.runts_ok) { - DEBUG("%s: rejected small packet, length %d\n", dev->name, io_len); - ui_sb_icon_update(SB_NETWORK, 0); - return; - } - - /* Some computers don't care... */ - if (io_len < 60) - io_len = 60; - - DBGLOG(1, "%s: RX %x:%x:%x:%x:%x:%x > %x:%x:%x:%x:%x:%x len %d\n", - dev->name, buf[6], buf[7], buf[8], buf[9], buf[10], buf[11], - buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], io_len); - - /* Do address filtering if not in promiscuous mode. */ - if (! dev->dp8390.RCR.promisc) { - /* If this is a broadcast frame.. */ - if (! memcmp(buf, bcast_addr, 6)) { - /* Broadcast not enabled, we're done. */ - if (! dev->dp8390.RCR.broadcast) { - DEBUG("%s: RX BC disabled\n", dev->name); - ui_sb_icon_update(SB_NETWORK, 0); - return; - } - } - - /* If this is a multicast frame.. */ - else if (buf[0] & 0x01) { - /* Multicast not enabled, we're done. */ - if (! dev->dp8390.RCR.multicast) { - DEBUG("%s: RX MC disabled\n", dev->name); - ui_sb_icon_update(SB_NETWORK, 0); - return; - } - - /* Are we listening to this multicast address? */ - idx = mcast_index(buf); - if (! (dev->dp8390.mchash[idx>>3] & (1<<(idx&0x7)))) { - DEBUG("%s: RX MC not listed\n", dev->name); - ui_sb_icon_update(SB_NETWORK, 0); - return; - } - } - - /* Unicast, must be for us.. */ - else if (memcmp(buf, dev->dp8390.physaddr, 6)) return; - } else { - DBGLOG(1, "%s: RX promiscuous receive\n", dev->name); - } - - nextpage = dev->dp8390.curr_page + pages; - if (nextpage >= dev->dp8390.page_stop) - nextpage -= (dev->dp8390.page_stop - dev->dp8390.page_start); - - /* Set up packet header. */ - pkthdr[0] = 0x01; /* RXOK - packet is OK */ - pkthdr[1] = nextpage; /* ptr to next packet */ - pkthdr[2] = (uint8_t) ((io_len + sizeof(pkthdr)) & 0xff); /* length-low */ - pkthdr[3] = (uint8_t) ((io_len + sizeof(pkthdr)) >> 8); /* length-hi */ - DBGLOG(1, "%s: RX pkthdr [%02x %02x %02x %02x]\n", - dev->name, pkthdr[0], pkthdr[1], pkthdr[2], pkthdr[3]); - - /* Copy into buffer, update curpage, and signal interrupt if config'd */ - startptr = dev->dp8390.mem + (dev->dp8390.curr_page * 256); - memcpy(startptr, pkthdr, sizeof(pkthdr)); - if ((nextpage > dev->dp8390.curr_page) || - ((dev->dp8390.curr_page + pages) == dev->dp8390.page_stop)) { - memcpy(startptr+sizeof(pkthdr), buf, io_len); - } else { - endbytes = (dev->dp8390.page_stop - dev->dp8390.curr_page) * 256; - memcpy(startptr+sizeof(pkthdr), buf, endbytes-sizeof(pkthdr)); - startptr = dev->dp8390.mem + (dev->dp8390.page_start * 256); - memcpy(startptr, buf+endbytes-sizeof(pkthdr), io_len-endbytes+8); - } - dev->dp8390.curr_page = nextpage; - - dev->dp8390.RSR.rx_ok = 1; - dev->dp8390.RSR.rx_mbit = (buf[0] & 0x01) ? 1 : 0; - dev->dp8390.ISR.pkt_rx = 1; - - if (dev->dp8390.IMR.rx_inte) - nic_interrupt(dev, 1); - - ui_sb_icon_update(SB_NETWORK, 0); -} - - -static void -nic_tx(nic_t *dev, uint32_t val) -{ - dev->dp8390.CR.tx_packet = 0; - dev->dp8390.TSR.tx_ok = 1; - dev->dp8390.ISR.pkt_tx = 1; - - /* Generate an interrupt if not masked */ - if (dev->dp8390.IMR.tx_inte) - nic_interrupt(dev, 1); - - dev->dp8390.tx_timer_active = 0; + return ret; } static uint8_t -nic_mca_read(int port, void *priv) +ram_readb(uint32_t addr, priv_t priv) +{ + nic_t *dev = (nic_t *)priv; + + return ram_read(dev, addr, 1); +} + + +static uint16_t +ram_readw(uint32_t addr, priv_t priv) +{ + nic_t *dev = (nic_t *)priv; + + return ram_read(dev, addr, 2); +} + + +static uint32_t +ram_readl(uint32_t addr, priv_t priv) +{ + nic_t *dev = (nic_t *)priv; + + return ram_read(dev, addr, 4); +} + + +static void +ram_write(priv_t priv, uint32_t addr, uint32_t val, int len) +{ + nic_t *dev = (nic_t *)priv; + + if ((addr & 0x3fff) >= 0x2000) + return; + + dev->dp8390.mem[addr & 0x1fff] = val & 0xff; + if (len == 2 || len == 4) + dev->dp8390.mem[(addr+1) & 0x1fff] = val >> 8; + if (len == 4) { + dev->dp8390.mem[(addr+2) & 0x1fff] = val >> 16; + dev->dp8390.mem[(addr+3) & 0x1fff] = val >> 24; + } +} + + +static void +ram_writeb(uint32_t addr, uint8_t val, priv_t priv) +{ + nic_t *dev = (nic_t *)priv; + + ram_write(dev, addr, val, 1); +} + + +static void +ram_writew(uint32_t addr, uint16_t val, priv_t priv) +{ + nic_t *dev = (nic_t *)priv; + + ram_write(dev, addr, val, 2); +} + + +static void +ram_writel(uint32_t addr, uint32_t val, priv_t priv) +{ + nic_t *dev = (nic_t *)priv; + + ram_write(dev, addr, val, 4); +} + + +static uint8_t +nic_mca_read(int port, priv_t priv) { nic_t *dev = (nic_t *)priv; @@ -1318,7 +1316,7 @@ nic_mca_read(int port, void *priv) static void -nic_mca_write(int port, uint8_t val, void *priv) +nic_mca_write(int port, uint8_t val, priv_t priv) { nic_t *dev = (nic_t *)priv; int8_t irqs[4] = { 3, 4, 10, 15 }; @@ -1330,7 +1328,7 @@ nic_mca_write(int port, uint8_t val, void *priv) /* Save the MCA register value. */ dev->pos_regs[port & 7] = val; - nic_ioremove(dev, dev->base_address); + nic_ioremove(dev, dev->base_address); dev->base_address = 0x800 + (((dev->pos_regs[2] & 0xf0) >> 4) * 0x1000); dev->base_irq = irqs[(dev->pos_regs[5] & 0x0c) >> 2]; @@ -1358,16 +1356,16 @@ nic_mca_write(int port, uint8_t val, void *priv) ram_writeb, ram_writew, ram_writel, NULL, MEM_MAPPING_EXTERNAL, dev); - mem_map_disable(&dev->ram_mapping); + mem_map_disable(&dev->ram_mapping); - INFO("%s: attached IO=0x%X IRQ=%d, RAM=0x%06X\n", + INFO("%s: attached IO=0x%X IRQ=%i, RAM=0x%06X\n", dev->name, dev->base_address, dev->base_irq, dev->ram_addr); } } static void -nic_close(void *priv) +nic_close(priv_t priv) { nic_t *dev = (nic_t *)priv; @@ -1382,7 +1380,7 @@ nic_close(void *priv) } -static void * +static priv_t nic_init(const device_t *info, UNUSED(void *parent)) { uint32_t mac; @@ -1392,7 +1390,7 @@ nic_init(const device_t *info, UNUSED(void *parent)) memset(dev, 0x00, sizeof(nic_t)); dev->name = info->name; dev->board = info->local; - + switch(dev->board) { case WD8003E: dev->board_chip = WE_WD8003E; @@ -1400,7 +1398,7 @@ nic_init(const device_t *info, UNUSED(void *parent)) dev->maclocal[1] = 0x00; dev->maclocal[2] = 0xC0; break; - + case WD8013EBT: dev->board_chip = WE_WD8013EBT; dev->maclocal[0] = 0x00; /* 00:00:C0 (WD/SMC OID) */ @@ -1453,35 +1451,35 @@ nic_init(const device_t *info, UNUSED(void *parent)) } memcpy(dev->dp8390.physaddr, dev->maclocal, sizeof(dev->maclocal)); - INFO("%s: I/O=%04x, IRQ=%d, MAC=%02x:%02x:%02x:%02x:%02x:%02x\n", + INFO("%s: I/O=%04x, IRQ=%i, MAC=%02x:%02x:%02x:%02x:%02x:%02x\n", dev->name, dev->base_address, dev->base_irq, dev->dp8390.physaddr[0], dev->dp8390.physaddr[1], dev->dp8390.physaddr[2], dev->dp8390.physaddr[3], dev->dp8390.physaddr[4], dev->dp8390.physaddr[5]); /* Reset the board. */ - if (dev->board != WD8013EPA) + if (dev->board != WD8013EPA) nic_reset(dev); /* Attach ourselves to the network module. */ - if (! network_attach(dev, dev->dp8390.physaddr, nic_rx)) { + if (! network_attach(dev, dev->maclocal, nic_rx)) { nic_close(dev); return(NULL); } - - /* Map this system into the memory map. */ + + /* Map this system into the memory map. */ if (dev->board != WD8013EPA) { mem_map_add(&dev->ram_mapping, dev->ram_addr, 0x4000, - ram_readb, NULL, NULL, ram_writeb, NULL, NULL, + ram_readb,NULL,NULL, ram_writeb,NULL,NULL, NULL, MEM_MAPPING_EXTERNAL, dev); - mem_map_disable(&dev->ram_mapping); + mem_map_disable(&dev->ram_mapping); - INFO("%s: attached IO=0x%X IRQ=%d, RAM addr=0x%06x\n", + INFO("%s: attached IO=0x%X IRQ=%i, RAM addr=0x%06x\n", dev->name, dev->base_address, dev->base_irq, dev->ram_addr); } - return(dev); + return((priv_t)dev); } diff --git a/src/devices/ports/game.c b/src/devices/ports/game.c index e8b8e1a..64d0cbb 100644 --- a/src/devices/ports/game.c +++ b/src/devices/ports/game.c @@ -8,7 +8,7 @@ * * Implementation of a generic Game Port. * - * Version: @(#)game.c 1.0.22 2019/05/03 + * Version: @(#)game.c 1.0.23 2019/05/13 * * Authors: Fred N. van Kempen, * Sarah Walker, @@ -109,7 +109,7 @@ game_time(int axis) static void -game_write(uint16_t addr, uint8_t val, void *priv) +game_write(uint16_t addr, uint8_t val, priv_t priv) { game_t *dev = (game_t *)priv; int i; @@ -134,7 +134,7 @@ game_write(uint16_t addr, uint8_t val, void *priv) static uint8_t -game_read(uint16_t addr, void *priv) +game_read(uint16_t addr, priv_t priv) { game_t *dev = (game_t *)priv; uint8_t ret; @@ -156,7 +156,7 @@ game_read(uint16_t addr, void *priv) /* Timer expired... game over. Just couldn't resist... --FvK */ static void -game_over(void *priv) +game_over(priv_t priv) { g_axis_t *axis = (g_axis_t *)priv; game_t *dev = axis->game; @@ -170,7 +170,7 @@ game_over(void *priv) static void -game_close(void *priv) +game_close(priv_t priv) { game_t *dev = (game_t *)priv; @@ -185,13 +185,13 @@ game_close(void *priv) } -static void * +static priv_t game_init(const device_t *info, UNUSED(void *parent)) { game_t *dev; int i; - INFO("GAME: initializing, type=%d\n", config.joystick_type); + INFO("GAME: initializing, type=%i\n", config.joystick_type); dev = (game_t *)mem_alloc(sizeof(game_t)); memset(dev, 0x00, sizeof(game_t)); @@ -223,7 +223,7 @@ game_init(const device_t *info, UNUSED(void *parent)) } - return(dev); + return((priv_t)dev); } diff --git a/src/devices/ports/parallel.c b/src/devices/ports/parallel.c index 6e3c14f..3de45d7 100644 --- a/src/devices/ports/parallel.c +++ b/src/devices/ports/parallel.c @@ -8,7 +8,7 @@ * * Implementation of the "LPT" style parallel ports. * - * Version: @(#)parallel.c 1.0.18 2019/05/03 + * Version: @(#)parallel.c 1.0.19 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -60,13 +60,13 @@ typedef struct { ctrl; /* port control register */ /* Port overloading stuff. */ - void *func_priv; - uint8_t (*func_read)(uint16_t, void *); + priv_t func_priv; + uint8_t (*func_read)(uint16_t, priv_t); /* Device stuff. */ int dev_id; /* attached device */ const lpt_device_t *dev_ts; - void *dev_ps; + priv_t dev_ps; } parallel_t; @@ -102,7 +102,7 @@ parallel_log(int level, const char *fmt, ...) /* Write a value to a port (and/or its attached device.) */ static void -parallel_write(uint16_t port, uint8_t val, void *priv) +parallel_write(uint16_t port, uint8_t val, priv_t priv) { parallel_t *dev = (parallel_t *)priv; @@ -129,7 +129,7 @@ parallel_write(uint16_t port, uint8_t val, void *priv) /* Read a value from a port (and/or its attached device.) */ static uint8_t -parallel_read(uint16_t port, void *priv) +parallel_read(uint16_t port, priv_t priv) { parallel_t *dev = (parallel_t *)priv; uint8_t ret = 0xff; @@ -170,7 +170,7 @@ parallel_read(uint16_t port, void *priv) static void -parallel_close(void *priv) +parallel_close(priv_t priv) { parallel_t *dev = (parallel_t *)priv; @@ -196,7 +196,7 @@ parallel_close(void *priv) } -static void * +static priv_t parallel_init(const device_t *info, UNUSED(void *parent)) { parallel_t *dev; @@ -211,8 +211,7 @@ parallel_init(const device_t *info, UNUSED(void *parent)) /* Enable the I/O handler for this port. */ io_sethandler(dev->base, 4, - parallel_read,NULL,NULL, - parallel_write,NULL,NULL, dev); + parallel_read,NULL,NULL, parallel_write,NULL,NULL, dev); /* If the user configured a device for this port, attach it. */ if (config.parallel_device[port] != 0) { @@ -224,7 +223,7 @@ parallel_init(const device_t *info, UNUSED(void *parent)) INFO("PARALLEL: %s (I/O=%04X, device=%i)\n", info->name, dev->base, config.parallel_device[port]); - return(dev); + return((priv_t)dev); } @@ -288,7 +287,7 @@ parallel_setup(int id, uint16_t port) void -parallel_set_func(void *arg, uint8_t (*rfunc)(uint16_t, void *), void *priv) +parallel_set_func(priv_t arg, uint8_t (*rfunc)(uint16_t, priv_t), priv_t priv) { parallel_t *dev = (parallel_t *)arg; diff --git a/src/devices/ports/parallel.h b/src/devices/ports/parallel.h index 658760d..95f7abe 100644 --- a/src/devices/ports/parallel.h +++ b/src/devices/ports/parallel.h @@ -8,7 +8,7 @@ * * Definitions for the "LPT" parallel port handlerss. * - * Version: @(#)parallel.h 1.0.7 2019/05/03 + * Version: @(#)parallel.h 1.0.8 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -56,8 +56,8 @@ extern void parallel_log(int level, const char *fmt, ...); extern void parallel_reset(void); extern void parallel_setup(int id, uint16_t port); -extern void parallel_set_func(void *arg, - uint8_t (*rfunc)(uint16_t, void *), void *priv); +extern void parallel_set_func(priv_t arg, + uint8_t (*rfunc)(uint16_t, priv_t), priv_t); #endif /*EMU_PARALLEL_H*/ diff --git a/src/devices/ports/parallel_dev.c b/src/devices/ports/parallel_dev.c index d074af8..d8f95a9 100644 --- a/src/devices/ports/parallel_dev.c +++ b/src/devices/ports/parallel_dev.c @@ -8,7 +8,7 @@ * * Implementation of the parallel-port-attached devices. * - * Version: @(#)parallel_dev.c 1.0.10 2019/01/03 + * Version: @(#)parallel_dev.c 1.0.11 2019/05/13 * * Author: Fred N. van Kempen, * diff --git a/src/devices/ports/serial.c b/src/devices/ports/serial.c index 48468c2..2941657 100644 --- a/src/devices/ports/serial.c +++ b/src/devices/ports/serial.c @@ -32,7 +32,7 @@ * The lower half of the driver can interface to the host system * serial ports, or other channels, for real-world access. * - * Version: @(#)serial.c 1.0.17 2019/05/03 + * Version: @(#)serial.c 1.0.18 2019/05/13 * * Author: Fred N. van Kempen, * @@ -196,11 +196,11 @@ typedef struct serial { /* Callback data. */ serial_ops_t *ops; - void *ops_arg; + priv_t ops_arg; int64_t delay; - void *bh; /* BottomHalf handler */ + priv_t bh; /* BottomHalf handler */ int fifo_read, fifo_write; @@ -259,7 +259,7 @@ update_ints(serial_t *dev) dev->iir = IID_IDMDM; } - DEBUG("Serial%d: intr, IIR=%02X, type=%d, mcr=%02X\n", + DEBUG("Serial%d: intr, IIR=%02X, type=%i, mcr=%02X\n", dev->port, dev->iir, dev->type, dev->mcr); /* Are hardware interrupts enabled? */ @@ -342,7 +342,7 @@ read_fifo(serial_t *dev) static void -receive_callback(void *priv) +receive_callback(priv_t priv) { serial_t *dev = (serial_t *)priv; @@ -368,7 +368,7 @@ reset_port(serial_t *dev) static void -read_timer(void *priv) +read_timer(priv_t priv) { serial_t *dev = (serial_t *)priv; @@ -385,7 +385,7 @@ read_timer(void *priv) #ifdef USE_HOST_SERIAL /* Platform module has data, so read it! */ static void -read_done(void *arg, int num) +read_done(priv_t arg, int num) { serial_t *dev = (serial_t *)arg; @@ -405,7 +405,7 @@ read_done(void *arg, int num) static void -ser_write(uint16_t addr, uint8_t val, void *priv) +ser_write(uint16_t addr, uint8_t val, priv_t priv) { serial_t *dev = (serial_t *)priv; #if defined(_LOGGING) || defined(USE_HOST_SERIAL) @@ -601,7 +601,7 @@ INFO("Serial%i: enable FIFO (%02x), type %i!\n", dev->port, val, dev->type); static uint8_t -ser_read(uint16_t addr, void *priv) +ser_read(uint16_t addr, priv_t priv) { serial_t *dev = (serial_t *)priv; uint8_t ret = 0x00; @@ -699,7 +699,27 @@ ser_read(uint16_t addr, void *priv) } -static void * +static void +ser_close(priv_t priv) +{ + serial_t *dev = (serial_t *)priv; + +#ifdef USE_HOST_SERIAL + /* Close the host device. */ + if (dev->bh != NULL) + (void)serial_link(dev->port, NULL); +#endif + + /* Remove the I/O handler. */ + io_removehandler(dev->base, 8, + ser_read,NULL,NULL, ser_write,NULL,NULL, dev); + + /* Clear port. */ + reset_port(dev); +} + + +static priv_t ser_init(const device_t *info, UNUSED(void *parent)) { serial_t *dev; @@ -722,27 +742,7 @@ ser_init(const device_t *info, UNUSED(void *parent)) INFO("SERIAL: COM%i (I/O=%04X, IRQ=%i)\n", info->local & 127, dev->base, dev->irq); - return(dev); -} - - -static void -ser_close(void *priv) -{ - serial_t *dev = (serial_t *)priv; - -#ifdef USE_HOST_SERIAL - /* Close the host device. */ - if (dev->bh != NULL) - (void)serial_link(dev->port, NULL); -#endif - - /* Remove the I/O handler. */ - io_removehandler(dev->base, 8, - ser_read,NULL,NULL, ser_write,NULL,NULL, dev); - - /* Clear port. */ - reset_port(dev); + return((priv_t)dev); } @@ -844,7 +844,7 @@ serial_setup(int id, uint16_t port, int8_t irq) /* API: attach another device to a serial port. */ void * -serial_attach(int port, serial_ops_t *ops, void *arg) +serial_attach(int port, serial_ops_t *ops, priv_t arg) { serial_t *dev; @@ -910,7 +910,7 @@ serial_link(int port, const char *arg) /* API: clear the FIFO buffers of a serial port. */ void -serial_clear(void *arg) +serial_clear(priv_t arg) { serial_t *dev = (serial_t *)arg; @@ -920,7 +920,7 @@ serial_clear(void *arg) /* API: write data to a serial port. */ void -serial_write(void *arg, uint8_t *ptr, uint8_t len) +serial_write(priv_t arg, uint8_t *ptr, uint8_t len) { serial_t *dev = (serial_t *)arg; diff --git a/src/devices/ports/serial.h b/src/devices/ports/serial.h index 42e6cee..f56e1f1 100644 --- a/src/devices/ports/serial.h +++ b/src/devices/ports/serial.h @@ -8,7 +8,7 @@ * * Definitions for the SERIAL card. * - * Version: @(#)serial.h 1.0.10 2019/05/03 + * Version: @(#)serial.h 1.0.11 2019/05/13 * * Author: Fred N. van Kempen, * @@ -85,21 +85,21 @@ extern const device_t serial_1_pcjr_device; extern void serial_reset(void); extern void serial_setup(int port, uint16_t addr, int8_t irq); -extern void *serial_attach(int port, serial_ops_t *ops, void *priv); +extern void *serial_attach(int port, serial_ops_t *ops, priv_t priv); extern int serial_link(int port, const char *name); -extern void serial_clear(void *arg); -extern void serial_write(void *arg, uint8_t *ptr, uint8_t len); +extern void serial_clear(priv_t arg); +extern void serial_write(priv_t arg, uint8_t *ptr, uint8_t len); /* Platform serial driver support. */ -extern void *plat_serial_open(const char *port, int tmo); -extern void plat_serial_close(void *); -extern int plat_serial_active(void *, int flg); -extern int plat_serial_params(void *, char dbit, char par, char sbit); -extern int plat_serial_flush(void *); -extern int plat_serial_speed(void *, long speed); -extern int plat_serial_write(void *, uint8_t val); -extern int plat_serial_read(void *, uint8_t *bufp, int max); +extern priv_t plat_serial_open(const char *port, int tmo); +extern void plat_serial_close(priv_t); +extern int plat_serial_active(priv_t, int flg); +extern int plat_serial_params(priv_t, char dbit, char par, char sbit); +extern int plat_serial_flush(priv_t); +extern int plat_serial_speed(priv_t, long speed); +extern int plat_serial_write(priv_t, uint8_t val); +extern int plat_serial_read(priv_t, uint8_t *bufp, int max); #endif /*EMU_SERIAL_H*/ diff --git a/src/devices/scsi/scsi_ncr5380.c b/src/devices/scsi/scsi_ncr5380.c index a89179a..eb0c980 100644 --- a/src/devices/scsi/scsi_ncr5380.c +++ b/src/devices/scsi/scsi_ncr5380.c @@ -11,7 +11,7 @@ * * NOTE: This code now only supports targets at LUN=0 !! * - * Version: @(#)scsi_ncr5380.c 1.0.17 2019/04/25 + * Version: @(#)scsi_ncr5380.c 1.0.18 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -169,7 +169,7 @@ typedef struct { mem_map_t mapping; uint8_t buffer[128], - int_ram[0x40], + int_ram[0x40], ext_ram[0x600]; } ncr5380_t; @@ -220,7 +220,7 @@ get_bus_host(ncr_t *ncr) uint32_t bus_host = 0; if (ncr->icr & ICR_DBP) { - DEBUG("Data bus phase\n"); + DEBUG("Data bus phase\n"); bus_host |= BUS_DBP; } if (ncr->icr & ICR_SEL) { @@ -265,7 +265,7 @@ ncr_wait_process(ncr5380_t *ncr_dev) { ncr_t *ncr = &ncr_dev->ncr; scsi_device_t *dev; - + /* Wait processes to handle bus requests. */ DEBUG("Clear REQ=%d\n", ncr->clear_req); if (ncr->clear_req) { @@ -276,12 +276,12 @@ ncr_wait_process(ncr5380_t *ncr_dev) ncr->cur_bus |= BUS_REQ; } } - + if (ncr->wait_data) { ncr->wait_data--; if (! ncr->wait_data) { dev = &scsi_devices[ncr->target_id][ncr->target_lun]; - SET_BUS_STATE(ncr, ncr->new_phase); + SET_BUS_STATE(ncr, ncr->new_phase); if (ncr->new_phase == SCSI_PHASE_DATA_IN) { DEBUG("Data In bus phase\n"); @@ -305,18 +305,18 @@ ncr_wait_process(ncr5380_t *ncr_dev) } else { ncr->state = STATE_DATAOUT; DEBUG("Data Out bus phase\n"); - } + } } } } - + if (ncr->wait_complete) { ncr->wait_complete--; if (! ncr->wait_complete) ncr->cur_bus |= BUS_REQ; } - - ncr->bus_host = ncr->cur_bus; + + ncr->bus_host = ncr->cur_bus; } @@ -339,8 +339,8 @@ ncr_callback(void *priv) else ncr_dev->timer_period += 40LL * TIMER_USEC; - if (ncr->dma_mode == DMA_IDLE) { - ncr->bus_host = get_bus_host(ncr); + if (ncr->dma_mode == DMA_IDLE) { + ncr->bus_host = get_bus_host(ncr); /*Start the SCSI command layer, which will also make the timings*/ if (ncr->bus_host & BUS_ARB) { @@ -549,7 +549,7 @@ ncr_callback(void *priv) c++; - if (ncr_dev->buffer_pos == 128) { + if (ncr_dev->buffer_pos == 128) { ncr_dev->buffer_pos = 0; ncr_dev->buffer_host_pos = 0; ncr_dev->status_ctrl &= ~STATUS_BUFFER_NOT_READY; @@ -571,7 +571,7 @@ ncr_callback(void *priv) } break; } - } + } } else if (ncr->dma_mode == DMA_SEND) { if (ncr_dev->status_ctrl & CTRL_DATA_DIR) { DEBUG("NCR: DMA_SEND with DMA direction set wrong\n"); @@ -585,7 +585,7 @@ ncr_callback(void *priv) return; } - if (!ncr_dev->block_count_loaded) return; + if (!ncr_dev->block_count_loaded) return; while (c < 64) { /* Data ready. */ @@ -638,7 +638,7 @@ ncr_callback(void *priv) } break; } - } + } } } else { if (ncr->dma_mode == DMA_INITIATOR_RECEIVE) { @@ -693,7 +693,7 @@ ncr_callback(void *priv) } break; } - } + } } else if (ncr->dma_mode == DMA_SEND) { if (!ncr_dev->block_count_loaded) return; @@ -747,7 +747,7 @@ ncr_callback(void *priv) } break; } - } + } } } @@ -760,8 +760,8 @@ ncr_callback(void *priv) } -static void -ncr_write(uint16_t port, uint8_t val, void *priv) +static void +ncr_write(uint16_t port, uint8_t val, priv_t priv) { ncr5380_t *ncr_dev = (ncr5380_t *)priv; ncr_t *ncr = &ncr_dev->ncr; @@ -777,7 +777,7 @@ ncr_write(uint16_t port, uint8_t val, void *priv) case 1: /* Initiator Command Register */ DEBUG("Write: Initiator command register\n"); ncr->icr = val; - + ncr_dev->timer_enabled = 1; break; @@ -829,8 +829,8 @@ ncr_write(uint16_t port, uint8_t val, void *priv) } -static uint8_t -ncr_read(uint16_t port, void *priv) +static uint8_t +ncr_read(uint16_t port, priv_t priv) { ncr5380_t *ncr_dev = (ncr5380_t *)priv; ncr_t *ncr = &ncr_dev->ncr; @@ -883,7 +883,7 @@ ncr_read(uint16_t port, void *priv) ncr->bus_host = get_bus_host(ncr); DEBUG("Get host from Interrupt\n"); - + /*Check if the phase in process matches with TCR's*/ if ((ncr->bus_host & SCSI_PHASE_MESSAGE_IN) == (ncr->cur_bus & SCSI_PHASE_MESSAGE_IN)) { @@ -898,13 +898,13 @@ ncr_read(uint16_t port, void *priv) if (ncr->bus_host & BUS_ACK) ret |= STATUS_ACK; - + if ((ncr->bus_host & BUS_REQ) && (ncr->mode & MODE_DMA)) { DEBUG("Entering DMA mode\n"); ret |= STATUS_DRQ; - + int bus = 0; - + if (ncr->bus_host & BUS_IO) bus |= TCR_IO; if (ncr->bus_host & BUS_CD) @@ -941,8 +941,8 @@ ncr_read(uint16_t port, void *priv) /* Memory-mapped I/O READ handler. */ -static uint8_t -memio_read(uint32_t addr, void *priv) +static uint8_t +memio_read(uint32_t addr, priv_t priv) { ncr5380_t *ncr_dev = (ncr5380_t *)priv; uint8_t ret = 0xff; @@ -966,11 +966,11 @@ memio_read(uint32_t addr, void *priv) DBGLOG(1, "Read 53c80 %04x\n", addr); ret = ncr_read(addr, ncr_dev); break; - + case 0x3900: DBGLOG(1, "Read 3900 host pos %i status ctrl %02x\n", ncr_dev->buffer_host_pos, ncr_dev->status_ctrl); DEBUG("Read port 0x3900-0x397f\n"); - + if (ncr_dev->buffer_host_pos >= 128 || !(ncr_dev->status_ctrl & CTRL_DATA_DIR)) ret = 0xff; else { @@ -978,8 +978,7 @@ memio_read(uint32_t addr, void *priv) DEBUG("Read host buffer=%d\n", ncr_dev->buffer_host_pos); - if (ncr_dev->buffer_host_pos == 128) - { + if (ncr_dev->buffer_host_pos == 128) { DEBUG("Not ready\n"); ncr_dev->status_ctrl |= STATUS_BUFFER_NOT_READY; } @@ -1008,7 +1007,7 @@ memio_read(uint32_t addr, void *priv) ret = 0xff; break; } - break; + break; } if (addr >= 0x3880) { @@ -1020,16 +1019,15 @@ memio_read(uint32_t addr, void *priv) /* Memory-mapped I/O WRITE handler. */ -static void -memio_write(uint32_t addr, uint8_t val, void *priv) +static void +memio_write(uint32_t addr, uint8_t val, priv_t priv) { ncr5380_t *ncr_dev = (ncr5380_t *)priv; - + addr &= 0x3fff; DBGLOG(2, "memio_write(%08x,%02x) %i %02x\n", addr, val, ncr_dev->buffer_host_pos, ncr_dev->status_ctrl); - if (addr >= 0x3a00) ncr_dev->ext_ram[addr - 0x3a00] = val; else switch (addr & 0x3f80) { @@ -1042,11 +1040,11 @@ memio_write(uint32_t addr, uint8_t val, void *priv) DBGLOG(1, "Write 53c80 %04x %02x\n", addr, val); ncr_write(addr, val, ncr_dev); break; - + case 0x3900: if (!(ncr_dev->status_ctrl & CTRL_DATA_DIR) && ncr_dev->buffer_host_pos < 128) { ncr_dev->buffer[ncr_dev->buffer_host_pos++] = val; - + if (ncr_dev->buffer_host_pos == 128) { ncr_dev->status_ctrl |= STATUS_BUFFER_NOT_READY; ncr_dev->ncr_busy = 1; @@ -1083,7 +1081,7 @@ memio_write(uint32_t addr, uint8_t val, void *priv) ncr_dev->block_count_loaded = 1; DEBUG("Timer for transfers=%02x\n", ncr_dev->timer_enabled); - + if (ncr_dev->status_ctrl & CTRL_DATA_DIR) { DEBUG("Data Read\n"); ncr_dev->buffer_host_pos = 128; @@ -1101,8 +1099,8 @@ memio_write(uint32_t addr, uint8_t val, void *priv) /* Memory-mapped I/O READ handler for the Trantor T130B. */ -static uint8_t -t130b_read(uint32_t addr, void *priv) +static uint8_t +t130b_read(uint32_t addr, priv_t priv) { ncr5380_t *ncr_dev = (ncr5380_t *)priv; uint8_t ret = 0xff; @@ -1119,8 +1117,8 @@ t130b_read(uint32_t addr, void *priv) /* Memory-mapped I/O WRITE handler for the Trantor T130B. */ -static void -t130b_write(uint32_t addr, uint8_t val, void *priv) +static void +t130b_write(uint32_t addr, uint8_t val, priv_t priv) { ncr5380_t *ncr_dev = (ncr5380_t *)priv; @@ -1130,10 +1128,9 @@ t130b_write(uint32_t addr, uint8_t val, void *priv) } -static uint8_t -t130b_in(uint16_t port, void *priv) +static uint8_t +t130b_in(uint16_t port, priv_t priv) { - ncr5380_t *ncr_dev = (ncr5380_t *)priv; uint8_t ret = 0xff; switch (port & 0x0f) { @@ -1141,14 +1138,14 @@ t130b_in(uint16_t port, void *priv) case 0x01: case 0x02: case 0x03: - ret = memio_read((port & 7) | 0x3980, ncr_dev); + ret = memio_read((port & 7) | 0x3980, priv); break; case 0x04: case 0x05: - ret = memio_read(0x3900, ncr_dev); - break; - + ret = memio_read(0x3900, priv); + break; + case 0x08: case 0x09: case 0x0a: @@ -1157,7 +1154,7 @@ t130b_in(uint16_t port, void *priv) case 0x0d: case 0x0e: case 0x0f: - ret = ncr_read(port, ncr_dev); + ret = ncr_read(port, priv); break; } @@ -1165,24 +1162,22 @@ t130b_in(uint16_t port, void *priv) } -static void -t130b_out(uint16_t port, uint8_t val, void *priv) +static void +t130b_out(uint16_t port, uint8_t val, priv_t priv) { - ncr5380_t *ncr_dev = (ncr5380_t *)priv; - switch (port & 0x0f) { case 0x00: case 0x01: case 0x02: case 0x03: - memio_write((port & 7) | 0x3980, val, ncr_dev); + memio_write((port & 7) | 0x3980, val, priv); break; case 0x04: case 0x05: - memio_write(0x3900, val, ncr_dev); - break; - + memio_write(0x3900, val, priv); + break; + case 0x08: case 0x09: case 0x0a: @@ -1191,16 +1186,15 @@ t130b_out(uint16_t port, uint8_t val, void *priv) case 0x0d: case 0x0e: case 0x0f: - ncr_write(port, val, ncr_dev); + ncr_write(port, val, priv); break; } } -static uint8_t -scsiat_in(uint16_t port, void *priv) +static uint8_t +scsiat_in(uint16_t port, priv_t priv) { - ncr5380_t *ncr_dev = (ncr5380_t *)priv; uint8_t ret = 0xff; switch (port & 0x0f) { @@ -1212,18 +1206,18 @@ scsiat_in(uint16_t port, void *priv) case 0x05: case 0x06: case 0x07: - ret = ncr_read(port, ncr_dev); + ret = ncr_read(port, priv); break; } - DBGLOG(2, "SCSI-AT read=0x%03x, ret=%02x\n", port, ret); - + DBGLOG(2, "SCSI-AT read=0x%03x, ret=%02x\n", port, ret); + return(ret); } static void -scsiat_out(uint16_t port, uint8_t val, void *priv) +scsiat_out(uint16_t port, uint8_t val, priv_t priv) { ncr5380_t *ncr_dev = (ncr5380_t *)priv; ncr_t *ncr = &ncr_dev->ncr; @@ -1232,21 +1226,32 @@ scsiat_out(uint16_t port, uint8_t val, void *priv) DBGLOG(2, "SCSI-AT write=0x%03x, val=%02x\n", port, val); switch (port & 0x0f) { + case 0x00: + case 0x01: + case 0x02: + case 0x03: + case 0x04: + case 0x05: + case 0x06: + case 0x07: + ncr_write(port, val, priv); + break; + case 0x08: - ncr->unk_08 = val; - - if (ncr->unk_08 & 0x08) { + ncr->unk_08 = val; + + if (ncr->unk_08 & 0x08) { if (ncr->dma_mode == DMA_INITIATOR_RECEIVE) { while (ncr_dev->buffer_host_pos < 128) { uint8_t temp; - + temp = ncr_dev->buffer[ncr_dev->buffer_host_pos++]; - + DBGLOG(1, "Read Buffer host=%d\n", ncr_dev->buffer_host_pos); - + ncr->bus_host = get_bus_host(ncr) & ~BUS_DATAMASK; - ncr->bus_host |= BUS_SETDATA(temp); - + ncr->bus_host |= BUS_SETDATA(temp); + if (ncr_dev->buffer_host_pos == 128) break; } @@ -1258,43 +1263,31 @@ scsiat_out(uint16_t port, uint8_t val, void *priv) ncr_wait_process(ncr_dev); temp = BUS_GETDATA(ncr->bus_host); ncr->bus_host = get_bus_host(ncr); - + ncr_dev->buffer[ncr_dev->buffer_host_pos++] = temp; - + DBGLOG(1, "Write Buffer host=%d\n", ncr_dev->buffer_host_pos); if (ncr_dev->buffer_host_pos == 128) { - + break; } - } + } } } - + if (ncr->unk_08 & 0x01) { ncr_dev->block_count_loaded = 1; ncr_dev->block_count = dev->buffer_length / 128; } - break; - - case 0x00: - case 0x01: - case 0x02: - case 0x03: - case 0x04: - case 0x05: - case 0x06: - case 0x07: - ncr_write(port, val, ncr_dev); break; } } static uint8_t -dev_in(uint16_t port, void *priv) +dev_in(uint16_t port, priv_t priv) { - ncr5380_t *ncr_dev = (ncr5380_t *)priv; uint8_t ret = 0xff; switch (port & 0x0f) { @@ -1306,18 +1299,18 @@ dev_in(uint16_t port, void *priv) case 0x05: case 0x06: case 0x07: - ret = ncr_read(port, ncr_dev); + ret = ncr_read(port, priv); break; } - DBGLOG(2, "5380: in(0x%03x) = %02x\n", port, ret); - + DBGLOG(2, "5380: in(0x%03x) = %02x\n", port, ret); + return(ret); } static void -dev_out(uint16_t port, uint8_t val, void *priv) +dev_out(uint16_t port, uint8_t val, priv_t priv) { ncr5380_t *ncr_dev = (ncr5380_t *)priv; ncr_t *ncr = &ncr_dev->ncr; @@ -1326,21 +1319,32 @@ dev_out(uint16_t port, uint8_t val, void *priv) DBGLOG(2, "5380 write(0x%03x, %02x)\n", port, val); switch (port & 0x0f) { + case 0x00: + case 0x01: + case 0x02: + case 0x03: + case 0x04: + case 0x05: + case 0x06: + case 0x07: + ncr_write(port, val, priv); + break; + case 0x08: - ncr->unk_08 = val; - - if (ncr->unk_08 & 0x08) { + ncr->unk_08 = val; + + if (ncr->unk_08 & 0x08) { if (ncr->dma_mode == DMA_INITIATOR_RECEIVE) { while (ncr_dev->buffer_host_pos < 128) { uint8_t temp; - + temp = ncr_dev->buffer[ncr_dev->buffer_host_pos++]; - + DBGLOG(1, "Read Buffer host=%d\n", ncr_dev->buffer_host_pos); - + ncr->bus_host = get_bus_host(ncr) & ~BUS_DATAMASK; - ncr->bus_host |= BUS_SETDATA(temp); - + ncr->bus_host |= BUS_SETDATA(temp); + if (ncr_dev->buffer_host_pos == 128) break; } @@ -1352,41 +1356,30 @@ dev_out(uint16_t port, uint8_t val, void *priv) ncr_wait_process(ncr_dev); temp = BUS_GETDATA(ncr->bus_host); ncr->bus_host = get_bus_host(ncr); - + ncr_dev->buffer[ncr_dev->buffer_host_pos++] = temp; - + DBGLOG(1, "Write Buffer host=%d\n", ncr_dev->buffer_host_pos); if (ncr_dev->buffer_host_pos == 128) { - + break; } - } + } } } - + if (ncr->unk_08 & 0x01) { ncr_dev->block_count_loaded = 1; ncr_dev->block_count = dev->buffer_length / 128; } - break; - - case 0x00: - case 0x01: - case 0x02: - case 0x03: - case 0x04: - case 0x05: - case 0x06: - case 0x07: - ncr_write(port, val, ncr_dev); break; } } static void -ncr_close(void *priv) +ncr_close(priv_t priv) { ncr5380_t *ncr_dev = (ncr5380_t *)priv; @@ -1400,7 +1393,7 @@ ncr_close(void *priv) } -static void * +static priv_t ncr_init(const device_t *info, UNUSED(void *parent)) { char temp[128]; @@ -1468,8 +1461,8 @@ ncr_init(const device_t *info, UNUSED(void *parent)) ncr_dev->rom_addr, 0x4000, 0x3fff, 0, MEM_MAPPING_EXTERNAL); - mem_map_disable(&ncr_dev->bios_rom.mapping); - + mem_map_disable(&ncr_dev->bios_rom.mapping); + mem_map_add(&ncr_dev->mapping, ncr_dev->rom_addr, 0x4000, t130b_read, NULL, NULL, t130b_write, NULL, NULL, @@ -1491,12 +1484,12 @@ ncr_init(const device_t *info, UNUSED(void *parent)) ncr_dev->status_ctrl = STATUS_BUFFER_NOT_READY; ncr_dev->buffer_host_pos = 128; - + ncr_dev->timer_period = 10LL * TIMER_USEC; timer_add(ncr_callback, ncr_dev, &ncr_dev->timer_period, TIMER_ALWAYS_ENABLED); - return(ncr_dev); + return((priv_t)ncr_dev); } @@ -1698,7 +1691,7 @@ const device_t scsi_scsiat_device = { * currently needed for onboard devices. */ void -scsi_ncr5380_set_info(void *priv, int base, int irq) +scsi_ncr5380_set_info(priv_t priv, int base, int irq) { ncr5380_t *dev = (ncr5380_t *)priv; diff --git a/src/devices/scsi/scsi_ncr5380.h b/src/devices/scsi/scsi_ncr5380.h index 2f8f9ae..3f7fdda 100644 --- a/src/devices/scsi/scsi_ncr5380.h +++ b/src/devices/scsi/scsi_ncr5380.h @@ -10,7 +10,7 @@ * made by NCR. These controllers were designed for * the ISA bus. * - * Version: @(#)scsi_ncr5380.c 1.0.3 2019/04/23 + * Version: @(#)scsi_ncr5380.c 1.0.4 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -48,7 +48,7 @@ extern const device_t scsi_t130b_device; extern const device_t scsi_scsiat_device; -extern void scsi_ncr5380_set_info(void *priv, int base, int irq); +extern void scsi_ncr5380_set_info(priv_t priv, int base, int irq); #endif /*SCSI_NCR5380_H*/ diff --git a/src/devices/scsi/scsi_ncr53c810.c b/src/devices/scsi/scsi_ncr53c810.c index 7738f7d..f34aecb 100644 --- a/src/devices/scsi/scsi_ncr53c810.c +++ b/src/devices/scsi/scsi_ncr53c810.c @@ -10,7 +10,7 @@ * NCR and later Symbios and LSI. This controller was designed * for the PCI bus. * - * Version: @(#)scsi_ncr53c810.c 1.0.15 2019/04/25 + * Version: @(#)scsi_ncr53c810.c 1.0.16 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -242,7 +242,7 @@ typedef struct { ncr53c810_request_t *current; int irq; - + uint32_t dsa; uint32_t temp; uint32_t dnad; @@ -321,8 +321,7 @@ sextract32(uint32_t value, int start, int length) #if 0 /*NOT_USED*/ static __inline uint32_t -deposit32(uint32_t value, int start, int length, - uint32_t fieldval) +deposit32(uint32_t value, int start, int length, uint32_t fieldval) { uint32_t mask; mask = (~0U >> (32 - length)) << start; @@ -586,7 +585,7 @@ ncr53c810_bad_selection(ncr53c810_t *dev, uint32_t id) /* Callback to indicate that the SCSI layer has completed a command. */ static void -ncr53c810_command_complete(void *priv, uint32_t status) +ncr53c810_command_complete(priv_t priv, uint32_t status) { ncr53c810_t *dev = (ncr53c810_t *)priv; int out; @@ -1377,9 +1376,9 @@ ncr53c810_execute_script(ncr53c810_t *dev) static void -ncr53c810_callback(void *p) +ncr53c810_callback(priv_t priv) { - ncr53c810_t *dev = (ncr53c810_t *) p; + ncr53c810_t *dev = (ncr53c810_t *)priv; dev->timer_period = 0; if (!dev->sstop) { @@ -1832,17 +1831,17 @@ ncr53c810_reg_readb(ncr53c810_t *dev, uint32_t offset) static uint8_t -ncr53c810_io_readb(uint16_t addr, void *p) +ncr53c810_io_readb(uint16_t addr, priv_t priv) { - ncr53c810_t *dev = (ncr53c810_t *)p; + ncr53c810_t *dev = (ncr53c810_t *)priv; return ncr53c810_reg_readb(dev, addr & 0xff); } static uint16_t -ncr53c810_io_readw(uint16_t addr, void *p) +ncr53c810_io_readw(uint16_t addr, priv_t priv) { - ncr53c810_t *dev = (ncr53c810_t *)p; + ncr53c810_t *dev = (ncr53c810_t *)priv; uint16_t val; addr &= 0xff; @@ -1853,9 +1852,9 @@ ncr53c810_io_readw(uint16_t addr, void *p) static uint32_t -ncr53c810_io_readl(uint16_t addr, void *p) +ncr53c810_io_readl(uint16_t addr, priv_t priv) { - ncr53c810_t *dev = (ncr53c810_t *)p; + ncr53c810_t *dev = (ncr53c810_t *)priv; uint32_t val; addr &= 0xff; @@ -1868,18 +1867,18 @@ ncr53c810_io_readl(uint16_t addr, void *p) static void -ncr53c810_io_writeb(uint16_t addr, uint8_t val, void *p) +ncr53c810_io_writeb(uint16_t addr, uint8_t val, priv_t priv) { - ncr53c810_t *dev = (ncr53c810_t *)p; + ncr53c810_t *dev = (ncr53c810_t *)priv; ncr53c810_reg_writeb(dev, addr & 0xff, val); } static void -ncr53c810_io_writew(uint16_t addr, uint16_t val, void *p) +ncr53c810_io_writew(uint16_t addr, uint16_t val, priv_t priv) { - ncr53c810_t *dev = (ncr53c810_t *)p; + ncr53c810_t *dev = (ncr53c810_t *)priv; addr &= 0xff; ncr53c810_reg_writeb(dev, addr, val & 0xff); @@ -1888,9 +1887,9 @@ ncr53c810_io_writew(uint16_t addr, uint16_t val, void *p) static void -ncr53c810_io_writel(uint16_t addr, uint32_t val, void *p) +ncr53c810_io_writel(uint16_t addr, uint32_t val, priv_t priv) { - ncr53c810_t *dev = (ncr53c810_t *)p; + ncr53c810_t *dev = (ncr53c810_t *)priv; addr &= 0xff; ncr53c810_reg_writeb(dev, addr, val & 0xff); @@ -1901,18 +1900,18 @@ ncr53c810_io_writel(uint16_t addr, uint32_t val, void *p) static void -ncr53c810_mmio_writeb(uint32_t addr, uint8_t val, void *p) +ncr53c810_mmio_writeb(uint32_t addr, uint8_t val, priv_t priv) { - ncr53c810_t *dev = (ncr53c810_t *)p; + ncr53c810_t *dev = (ncr53c810_t *)priv; ncr53c810_reg_writeb(dev, addr & 0xff, val); } static void -ncr53c810_mmio_writew(uint32_t addr, uint16_t val, void *p) +ncr53c810_mmio_writew(uint32_t addr, uint16_t val, priv_t priv) { - ncr53c810_t *dev = (ncr53c810_t *)p; + ncr53c810_t *dev = (ncr53c810_t *)priv; addr &= 0xff; ncr53c810_reg_writeb(dev, addr, val & 0xff); @@ -1921,9 +1920,9 @@ ncr53c810_mmio_writew(uint32_t addr, uint16_t val, void *p) static void -ncr53c810_mmio_writel(uint32_t addr, uint32_t val, void *p) +ncr53c810_mmio_writel(uint32_t addr, uint32_t val, priv_t priv) { - ncr53c810_t *dev = (ncr53c810_t *)p; + ncr53c810_t *dev = (ncr53c810_t *)priv; addr &= 0xff; ncr53c810_reg_writeb(dev, addr, val & 0xff); @@ -1934,18 +1933,18 @@ ncr53c810_mmio_writel(uint32_t addr, uint32_t val, void *p) static uint8_t -ncr53c810_mmio_readb(uint32_t addr, void *p) +ncr53c810_mmio_readb(uint32_t addr, priv_t priv) { - ncr53c810_t *dev = (ncr53c810_t *)p; + ncr53c810_t *dev = (ncr53c810_t *)priv; return ncr53c810_reg_readb(dev, addr & 0xff); } static uint16_t -ncr53c810_mmio_readw(uint32_t addr, void *p) +ncr53c810_mmio_readw(uint32_t addr, priv_t priv) { - ncr53c810_t *dev = (ncr53c810_t *)p; + ncr53c810_t *dev = (ncr53c810_t *)priv; uint16_t val; addr &= 0xff; @@ -1957,9 +1956,9 @@ ncr53c810_mmio_readw(uint32_t addr, void *p) static uint32_t -ncr53c810_mmio_readl(uint32_t addr, void *p) +ncr53c810_mmio_readl(uint32_t addr, priv_t priv) { - ncr53c810_t *dev = (ncr53c810_t *)p; + ncr53c810_t *dev = (ncr53c810_t *)priv; uint32_t val; addr &= 0xff; @@ -2048,9 +2047,9 @@ bar_t ncr53c810_pci_bar[2]; static uint8_t -ncr53c810_pci_read(int func, int addr, void *p) +ncr53c810_pci_read(int func, int addr, priv_t priv) { - ncr53c810_t *dev = (ncr53c810_t *)p; + ncr53c810_t *dev = (ncr53c810_t *)priv; DEBUG("NCR53c810: Reading register %02X\n", addr & 0xff); @@ -2142,9 +2141,9 @@ ncr53c810_pci_read(int func, int addr, void *p) static void -ncr53c810_pci_write(int func, int addr, uint8_t val, void *p) +ncr53c810_pci_write(int func, int addr, uint8_t val, priv_t priv) { - ncr53c810_t *dev = (ncr53c810_t *)p; + ncr53c810_t *dev = (ncr53c810_t *)priv; uint8_t valxor; DEBUG("NCR53c810: Write value %02X to register %02X\n", val, addr & 0xff); @@ -2250,7 +2249,19 @@ ncr53c810_pci_write(int func, int addr, uint8_t val, void *p) } -static void * +static void +ncr53c810_close(priv_t priv) +{ + ncr53c810_t *dev = (ncr53c810_t *)priv; + + if (dev) { + free(dev); + dev = NULL; + } +} + + +static priv_t ncr53c810_init(const device_t *info, UNUSED(void *parent)) { ncr53c810_t *dev; @@ -2289,19 +2300,7 @@ ncr53c810_init(const device_t *info, UNUSED(void *parent)) 0xc8000, 0x4000, 0x3fff, 0, MEM_MAPPING_EXTERNAL); #endif - return(dev); -} - - -static void -ncr53c810_close(void *priv) -{ - ncr53c810_t *dev = (ncr53c810_t *)priv; - - if (dev) { - free(dev); - dev = NULL; - } + return((priv_t)dev); } diff --git a/src/devices/scsi/scsi_x54x.c b/src/devices/scsi/scsi_x54x.c index 934a588..f661c82 100644 --- a/src/devices/scsi/scsi_x54x.c +++ b/src/devices/scsi/scsi_x54x.c @@ -12,7 +12,7 @@ * * These controllers were designed for various buses. * - * Version: @(#)scsi_x54x.c 1.0.17 2019/04/25 + * Version: @(#)scsi_x54x.c 1.0.18 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -67,10 +67,6 @@ #define X54X_RESET_DURATION_US UINT64_C(50000) -static void x54x_cmd_callback(void *priv); -static x54x_t *x54x_dev; - - static void x54x_irq(x54x_t *dev, int set) { @@ -79,7 +75,7 @@ x54x_irq(x54x_t *dev, int set) if (dev->ven_get_irq) irq = dev->ven_get_irq(dev); - else + else irq = dev->Irq; if (dev->bus & DEVICE_PCI) { @@ -245,9 +241,8 @@ completion_code(uint8_t *sense) } - static uint8_t -x54x_bios_scsi_command(scsi_device_t *dev, uint8_t *cdb, uint8_t *buf, int len, uint32_t addr) +bios_scsi_command(scsi_device_t *dev, uint8_t *cdb, uint8_t *buf, int len, uint32_t addr) { dev->buffer_length = -1; @@ -285,7 +280,7 @@ x54x_bios_scsi_command(scsi_device_t *dev, uint8_t *cdb, uint8_t *buf, int len, static uint8_t -x54x_bios_read_capacity(scsi_device_t *sd, uint8_t *buf) +bios_read_capacity(scsi_device_t *sd, uint8_t *buf) { uint8_t *cdb; uint8_t ret; @@ -296,7 +291,7 @@ x54x_bios_read_capacity(scsi_device_t *sd, uint8_t *buf) memset(buf, 0, 8); - ret = x54x_bios_scsi_command(sd, cdb, buf, 8, 0); + ret = bios_scsi_command(sd, cdb, buf, 8, 0); free(cdb); @@ -305,7 +300,7 @@ x54x_bios_read_capacity(scsi_device_t *sd, uint8_t *buf) static uint8_t -x54x_bios_inquiry(scsi_device_t *sd, uint8_t *buf) +bios_inquiry(scsi_device_t *sd, uint8_t *buf) { uint8_t *cdb; uint8_t ret; @@ -317,7 +312,7 @@ x54x_bios_inquiry(scsi_device_t *sd, uint8_t *buf) memset(buf, 0, 36); - ret = x54x_bios_scsi_command(sd, cdb, buf, 36, 0); + ret = bios_scsi_command(sd, cdb, buf, 36, 0); free(cdb); @@ -326,7 +321,7 @@ x54x_bios_inquiry(scsi_device_t *sd, uint8_t *buf) static uint8_t -x54x_bios_command_08(scsi_device_t *sd, uint8_t *buffer) +bios_command_08(scsi_device_t *sd, uint8_t *buffer) { uint8_t *rcbuf; uint8_t ret; @@ -336,7 +331,7 @@ x54x_bios_command_08(scsi_device_t *sd, uint8_t *buffer) rcbuf = (uint8_t *)mem_alloc(8); - ret = x54x_bios_read_capacity(sd, rcbuf); + ret = bios_read_capacity(sd, rcbuf); if (ret) { free(rcbuf); return(ret); @@ -358,7 +353,7 @@ x54x_bios_command_08(scsi_device_t *sd, uint8_t *buffer) static int -x54x_bios_command_15(scsi_device_t *sd, uint8_t *buffer) +bios_command_15(scsi_device_t *sd, uint8_t *buffer) { uint8_t *inqbuf, *rcbuf; uint8_t ret; @@ -367,7 +362,7 @@ x54x_bios_command_15(scsi_device_t *sd, uint8_t *buffer) memset(buffer, 0x00, 6); inqbuf = (uint8_t *)mem_alloc(36); - ret = x54x_bios_inquiry(sd, inqbuf); + ret = bios_inquiry(sd, inqbuf); if (ret) { free(inqbuf); return(ret); @@ -377,7 +372,7 @@ x54x_bios_command_15(scsi_device_t *sd, uint8_t *buffer) buffer[5] = inqbuf[1]; rcbuf = (uint8_t *)mem_alloc(8); - ret = x54x_bios_read_capacity(sd, rcbuf); + ret = bios_read_capacity(sd, rcbuf); if (ret) { free(rcbuf); free(inqbuf); @@ -399,7 +394,7 @@ x54x_bios_command_15(scsi_device_t *sd, uint8_t *buffer) /* This returns the completion code. */ static uint8_t -x54x_bios_command(x54x_t *x54x, uint8_t max_id, BIOSCMD *cmd, int8_t islba) +bios_command(x54x_t *x54x, uint8_t max_id, BIOSCMD *cmd, int8_t islba) { const int bios_cmd_to_scsi[18] = { 0, 0, GPCMD_READ_10, GPCMD_WRITE_10, GPCMD_VERIFY_10, 0, 0, @@ -504,7 +499,7 @@ x54x_bios_command(x54x_t *x54x, uint8_t max_id, BIOSCMD *cmd, int8_t islba) DBGLOG(1, "BIOS CMD(READ/WRITE/VERIFY, %08lx, %d)\n", lba, cmd->secount); - ret = x54x_bios_scsi_command(dev, cdb, NULL, sector_len, dma_address); + ret = bios_scsi_command(dev, cdb, NULL, sector_len, dma_address); if (cmd->command == 0x0c) ret = !!ret; break; @@ -536,7 +531,7 @@ x54x_bios_command(x54x_t *x54x, uint8_t max_id, BIOSCMD *cmd, int8_t islba) cdb[0] = bios_cmd_to_scsi[cmd->command]; cdb[1] = (cmd->lun & 7) << 5; - ret = x54x_bios_scsi_command(dev, cdb, NULL, sector_len, dma_address); + ret = bios_scsi_command(dev, cdb, NULL, sector_len, dma_address); break; case 0x08: /* Read Drive Parameters */ @@ -549,9 +544,9 @@ x54x_bios_command(x54x_t *x54x, uint8_t max_id, BIOSCMD *cmd, int8_t islba) buf = (uint8_t *) malloc(6); if (cmd->command == 0x08) - ret = x54x_bios_command_08(dev, buf); + ret = bios_command_08(dev, buf); else - ret = x54x_bios_command_15(dev, buf); + ret = bios_command_15(dev, buf); DEBUG("BIOS DMA: Reading 4 bytes at %08X\n", dma_address); DMAPageWrite(dma_address, buf, 4); @@ -576,7 +571,7 @@ x54x_bios_command(x54x_t *x54x, uint8_t max_id, BIOSCMD *cmd, int8_t islba) static void -x54x_cmd_done(x54x_t *dev, int suppress) +cmd_done(x54x_t *dev, int suppress) { int fast = 0; @@ -598,15 +593,15 @@ x54x_cmd_done(x54x_t *dev, int suppress) static void -x54x_add_to_period(int TransferLength) +add_to_period(x54x_t *dev, int TransferLength) { - x54x_dev->temp_period += (int64_t)TransferLength; + dev->temp_period += (int64_t)TransferLength; } static void -x54x_mbi_setup(x54x_t *dev, uint32_t CCBPointer, CCBU *CmdBlock, - uint8_t HostStatus, uint8_t TargetStatus, uint8_t mbcc) +mbi_setup(x54x_t *dev, uint32_t CCBPointer, CCBU *CmdBlock, + uint8_t HostStatus, uint8_t TargetStatus, uint8_t mbcc) { Req_t *req = &dev->Req; @@ -633,7 +628,7 @@ x54x_ccb(x54x_t *dev) DMAPageWrite(req->CCBPointer + 0x000D, &(req->MailboxCompletionCode), 1); DMAPageWrite(req->CCBPointer + 0x000E, &(req->HostStatus), 1); DMAPageWrite(req->CCBPointer + 0x000F, &(req->TargetStatus), 1); - x54x_add_to_period(3); + add_to_period(dev, 3); if (dev->MailboxOutInterrupts) dev->ToRaise = INTR_MBOA | INTR_ANY; @@ -644,7 +639,7 @@ x54x_ccb(x54x_t *dev) static void x54x_mbi(x54x_t *dev) -{ +{ Req_t *req = &dev->Req; addr24 CCBPointer; CCBU *CmdBlock = &(req->CmdBlock); @@ -663,7 +658,7 @@ x54x_mbi(x54x_t *dev) DEBUG("CCB statuses rewritten (pointer %08X)\n", req->CCBPointer); DMAPageWrite(req->CCBPointer + 0x000E, &(req->HostStatus), 1); DMAPageWrite(req->CCBPointer + 0x000F, &(req->TargetStatus), 1); - x54x_add_to_period(2); + add_to_period(dev, 2); } else { DEBUG("Mailbox not found!\n"); } @@ -675,7 +670,7 @@ x54x_mbi(x54x_t *dev) DEBUG("Mailbox 24-bit: Status=0x%02X, CCB at 0x%04X\n", req->MailboxCompletionCode, CCBPointer); DMAPageWrite(Incoming, &(req->MailboxCompletionCode), 1); DMAPageWrite(Incoming + 1, (uint8_t *)&CCBPointer, 3); - x54x_add_to_period(4); + add_to_period(dev, 4); DEBUG("%i bytes of 24-bit mailbox written to: %08X\n", sizeof(Mailbox_t), Incoming); } else { U32_TO_ADDR(CCBPointer, req->CCBPointer); @@ -684,13 +679,13 @@ x54x_mbi(x54x_t *dev) DMAPageWrite(Incoming + 4, &(req->HostStatus), 1); DMAPageWrite(Incoming + 5, &(req->TargetStatus), 1); DMAPageWrite(Incoming + 7, &(req->MailboxCompletionCode), 1); - x54x_add_to_period(7); + add_to_period(dev, 7); DEBUG("%i bytes of 32-bit mailbox written to: %08X\n", sizeof(Mailbox32_t), Incoming); } dev->MailboxInPosCur++; if (dev->MailboxInPosCur >= dev->MailboxCount) - dev->MailboxInPosCur = 0; + dev->MailboxInPosCur = 0; dev->ToRaise = INTR_MBIF | INTR_ANY; if (dev->MailboxOutInterrupts) @@ -699,13 +694,13 @@ x54x_mbi(x54x_t *dev) static void -x54x_rd_sge(int Is24bit, uint32_t Address, SGE32 *SG) +read_sge(x54x_t *dev, int Is24bit, uint32_t Address, SGE32 *SG) { SGE SGE24; if (Is24bit) { DMAPageRead(Address, (uint8_t *)&SGE24, sizeof(SGE)); - x54x_add_to_period(sizeof(SGE)); + add_to_period(dev, sizeof(SGE)); /* Convert the 24-bit entries into 32-bit entries. */ DEBUG("Read S/G block: %06X, %06X\n", SGE24.Segment, SGE24.SegmentPointer); @@ -713,13 +708,13 @@ x54x_rd_sge(int Is24bit, uint32_t Address, SGE32 *SG) SG->SegmentPointer = ADDR_TO_U32(SGE24.SegmentPointer); } else { DMAPageRead(Address, (uint8_t *)SG, sizeof(SGE32)); - x54x_add_to_period(sizeof(SGE32)); + add_to_period(dev, sizeof(SGE32)); } } static int -x54x_get_length(Req_t *req, int Is24bit) +get_length(x54x_t *dev, Req_t *req, int Is24bit) { uint32_t DataPointer, DataLength; uint32_t SGEntryLength = (Is24bit ? sizeof(SGE) : sizeof(SGE32)); @@ -744,7 +739,7 @@ x54x_get_length(Req_t *req, int Is24bit) if (req->CmdBlock.common.Opcode == SCATTER_GATHER_COMMAND || req->CmdBlock.common.Opcode == SCATTER_GATHER_COMMAND_RES) { for (i = 0; i < DataLength; i += SGEntryLength) { - x54x_rd_sge(Is24bit, DataPointer + i, &SGBuffer); + read_sge(dev, Is24bit, DataPointer + i, &SGBuffer); DataToTransfer += SGBuffer.Segment; } @@ -752,17 +747,16 @@ x54x_get_length(Req_t *req, int Is24bit) } else if (req->CmdBlock.common.Opcode == SCSI_INITIATOR_COMMAND || req->CmdBlock.common.Opcode == SCSI_INITIATOR_COMMAND_RES) { return(DataLength); - } else { - return(0); } - } else { return(0); } + + return(0); } static void -x54x_set_residue(Req_t *req, int32_t TransferLength) +set_residue(x54x_t *dev, Req_t *req, int32_t TransferLength) { uint32_t Residue = 0; addr24 Residue24; @@ -780,11 +774,11 @@ x54x_set_residue(Req_t *req, int32_t TransferLength) if (req->Is24bit) { U32_TO_ADDR(Residue24, Residue); DMAPageWrite(req->CCBPointer + 0x0004, (uint8_t *)&Residue24, 3); - x54x_add_to_period(3); + add_to_period(dev, 3); DEBUG("24-bit Residual data length for reading: %d\n", Residue); } else { DMAPageWrite(req->CCBPointer + 0x0004, (uint8_t *)&Residue, 4); - x54x_add_to_period(4); + add_to_period(dev, 4); DEBUG("32-bit Residual data length for reading: %d\n", Residue); } } @@ -792,7 +786,7 @@ x54x_set_residue(Req_t *req, int32_t TransferLength) static void -x54x_buf_dma_transfer(Req_t *req, int Is24bit, int TransferLength, int dir) +buf_dma_transfer(x54x_t *dev, Req_t *req, int Is24bit, int TransferLength, int dir) { uint32_t DataPointer, DataLength; uint32_t SGEntryLength = (Is24bit ? sizeof(SGE) : sizeof(SGE32)); @@ -826,7 +820,7 @@ x54x_buf_dma_transfer(Req_t *req, int Is24bit, int TransferLength, int dir) checking its length, so do this procedure for both no read/write commands. */ if ((DataLength > 0) && (req->CmdBlock.common.ControlByte < 0x03)) { for (i = 0; i < DataLength; i += SGEntryLength) { - x54x_rd_sge(Is24bit, DataPointer + i, &SGBuffer); + read_sge(dev, Is24bit, DataPointer + i, &SGBuffer); Address = SGBuffer.SegmentPointer; DataToTransfer = MIN((int)SGBuffer.Segment, BufLen); @@ -925,7 +919,7 @@ SenseBufferPointer(Req_t *req) static void -SenseBufferFree(Req_t *req, int Copy) +SenseBufferFree(x54x_t *dev, Req_t *req, int Copy) { uint8_t SenseLength = ConvertSenseLength(req->CmdBlock.common.RequestSenseLength); uint32_t SenseBufferAddress; @@ -946,7 +940,7 @@ SenseBufferFree(Req_t *req, int Copy) DEBUG("SenseBufferFree(): Writing %i bytes at %08X\n", SenseLength, SenseBufferAddress); DMAPageWrite(SenseBufferAddress, temp_sense, SenseLength); - x54x_add_to_period(SenseLength); + add_to_period(dev, SenseLength); DEBUG("Sense data written to buffer: %02X %02X %02X\n", temp_sense[2], temp_sense[12], temp_sense[13]); } @@ -954,7 +948,7 @@ SenseBufferFree(Req_t *req, int Copy) static void -x54x_scsi_cmd(x54x_t *dev) +scsi_cmd(x54x_t *dev) { Req_t *req = &dev->Req; uint8_t phase, bit24 = !!req->Is24bit; @@ -968,7 +962,7 @@ x54x_scsi_cmd(x54x_t *dev) sd = &scsi_devices[req->TargetID][req->LUN]; target_cdb_len = 12; - target_data_len = x54x_get_length(req, bit24); + target_data_len = get_length(dev, req, bit24); if (! scsi_device_valid(sd)) fatal("SCSI target on %i:%i has disappeared\n", req->TargetID, req->LUN); @@ -983,10 +977,10 @@ x54x_scsi_cmd(x54x_t *dev) if (req->CmdBlock.common.CdbLength <= target_cdb_len) { memcpy(temp_cdb, req->CmdBlock.common.Cdb, req->CmdBlock.common.CdbLength); - x54x_add_to_period(req->CmdBlock.common.CdbLength); + add_to_period(dev, req->CmdBlock.common.CdbLength); } else { memcpy(temp_cdb, req->CmdBlock.common.Cdb, target_cdb_len); - x54x_add_to_period(target_cdb_len); + add_to_period(dev, target_cdb_len); } dev->Residue = 0; @@ -1011,38 +1005,38 @@ x54x_scsi_cmd(x54x_t *dev) if ((sd->status != SCSI_STATUS_OK) && (*BufLen > 0)) { SenseBufferAddress = SenseBufferPointer(req); DMAPageWrite(SenseBufferAddress, sd->cmd_buffer, *BufLen); - x54x_add_to_period(*BufLen); + add_to_period(dev, *BufLen); } } else { p = scsi_device_get_callback(sd); if (p <= 0LL) - x54x_add_to_period(*BufLen); + add_to_period(dev, *BufLen); else dev->media_period += p; x54x_buf_alloc(sd, MIN(target_data_len, *BufLen)); if (phase == SCSI_PHASE_DATA_OUT) - x54x_buf_dma_transfer(req, bit24, target_data_len, 1); + buf_dma_transfer(dev, req, bit24, target_data_len, 1); scsi_device_command_phase1(sd); if (phase == SCSI_PHASE_DATA_IN) - x54x_buf_dma_transfer(req, bit24, target_data_len, 0); + buf_dma_transfer(dev, req, bit24, target_data_len, 0); - SenseBufferFree(req, (sd->status != SCSI_STATUS_OK)); + SenseBufferFree(dev, req, (sd->status != SCSI_STATUS_OK)); } } else - SenseBufferFree(req, (sd->status != SCSI_STATUS_OK)); + SenseBufferFree(dev, req, (sd->status != SCSI_STATUS_OK)); - x54x_set_residue(req, target_data_len); + set_residue(dev, req, target_data_len); x54x_buf_free(sd); DEBUG("Request complete\n"); if (sd->status == SCSI_STATUS_OK) { - x54x_mbi_setup(dev, req->CCBPointer, &req->CmdBlock, - CCB_COMPLETE, SCSI_STATUS_OK, MBI_SUCCESS); + mbi_setup(dev, req->CCBPointer, &req->CmdBlock, + CCB_COMPLETE, SCSI_STATUS_OK, MBI_SUCCESS); } else if (sd->status == SCSI_STATUS_CHECK_CONDITION) { - x54x_mbi_setup(dev, req->CCBPointer, &req->CmdBlock, - CCB_COMPLETE, SCSI_STATUS_CHECK_CONDITION, MBI_ERROR); + mbi_setup(dev, req->CCBPointer, &req->CmdBlock, + CCB_COMPLETE, SCSI_STATUS_CHECK_CONDITION, MBI_ERROR); } DEBUG("scsi_devices[%i][%i].status = %02X\n", req->TargetID, req->LUN, sd->status); @@ -1054,20 +1048,20 @@ x54x_notify(x54x_t *dev) { if (dev->MailboxIsBIOS) x54x_ccb(dev); - else + else x54x_mbi(dev); } static void -x54x_req_setup(x54x_t *dev, uint32_t CCBPointer, Mailbox32_t *Mailbox32) +req_setup(x54x_t *dev, uint32_t CCBPointer, Mailbox32_t *Mailbox32) { Req_t *req = &dev->Req; scsi_device_t *sd; /* Fetch data from the Command Control Block. */ DMAPageRead(CCBPointer, (uint8_t *)&req->CmdBlock, sizeof(CCB32)); - x54x_add_to_period(sizeof(CCB32)); + add_to_period(dev, sizeof(CCB32)); req->Is24bit = dev->Mbx24bit; req->CCBPointer = CCBPointer; @@ -1076,8 +1070,8 @@ x54x_req_setup(x54x_t *dev, uint32_t CCBPointer, Mailbox32_t *Mailbox32) if ((req->TargetID > dev->max_id) || (req->LUN > 7)) { DEBUG("SCSI Target ID %i or LUN %i is not valid\n", req->TargetID, req->LUN); - x54x_mbi_setup(dev, CCBPointer, &req->CmdBlock, - CCB_SELECTION_TIMEOUT, SCSI_STATUS_OK, MBI_ERROR); + mbi_setup(dev, CCBPointer, &req->CmdBlock, + CCB_SELECTION_TIMEOUT, SCSI_STATUS_OK, MBI_ERROR); DEBUG("%s: Callback: Send incoming mailbox\n", dev->name); x54x_notify(dev); return; @@ -1091,8 +1085,8 @@ x54x_req_setup(x54x_t *dev, uint32_t CCBPointer, Mailbox32_t *Mailbox32) /* If there is no device at ID:0, timeout the selection - the LUN is then checked later. */ if (! scsi_device_present(sd)) { DEBUG("SCSI Target ID %i and LUN %i have no device attached\n", req->TargetID, req->LUN); - x54x_mbi_setup(dev, CCBPointer, &req->CmdBlock, - CCB_SELECTION_TIMEOUT, SCSI_STATUS_OK, MBI_ERROR); + mbi_setup(dev, CCBPointer, &req->CmdBlock, + CCB_SELECTION_TIMEOUT, SCSI_STATUS_OK, MBI_ERROR); DEBUG("%s: Callback: Send incoming mailbox\n", dev->name); x54x_notify(dev); } else { @@ -1105,7 +1099,7 @@ x54x_req_setup(x54x_t *dev, uint32_t CCBPointer, Mailbox32_t *Mailbox32) DEBUG("Invalid opcode: %02X\n", req->CmdBlock.common.ControlByte); - x54x_mbi_setup(dev, CCBPointer, &req->CmdBlock, CCB_INVALID_OP_CODE, SCSI_STATUS_OK, MBI_ERROR); + mbi_setup(dev, CCBPointer, &req->CmdBlock, CCB_INVALID_OP_CODE, SCSI_STATUS_OK, MBI_ERROR); DEBUG("%s: Callback: Send incoming mailbox\n", dev->name); x54x_notify(dev); return; @@ -1114,8 +1108,8 @@ x54x_req_setup(x54x_t *dev, uint32_t CCBPointer, Mailbox32_t *Mailbox32) DEBUG("Bus reset opcode\n"); scsi_device_reset(sd); - x54x_mbi_setup(dev, req->CCBPointer, &req->CmdBlock, - CCB_COMPLETE, SCSI_STATUS_OK, MBI_SUCCESS); + mbi_setup(dev, req->CCBPointer, &req->CmdBlock, + CCB_COMPLETE, SCSI_STATUS_OK, MBI_SUCCESS); DEBUG("%s: Callback: Send incoming mailbox\n", dev->name); x54x_notify(dev); @@ -1125,14 +1119,14 @@ x54x_req_setup(x54x_t *dev, uint32_t CCBPointer, Mailbox32_t *Mailbox32) if (req->CmdBlock.common.ControlByte > 0x03) { DEBUG("Invalid control byte: %02X\n", req->CmdBlock.common.ControlByte); - x54x_mbi_setup(dev, CCBPointer, &req->CmdBlock, CCB_INVALID_DIRECTION, SCSI_STATUS_OK, MBI_ERROR); + mbi_setup(dev, CCBPointer, &req->CmdBlock, CCB_INVALID_DIRECTION, SCSI_STATUS_OK, MBI_ERROR); DEBUG("%s: Callback: Send incoming mailbox\n", dev->name); x54x_notify(dev); return; } DEBUG("%s: Callback: Process SCSI request\n", dev->name); - x54x_scsi_cmd(dev); + scsi_cmd(dev); DEBUG("%s: Callback: Send incoming mailbox\n", dev->name); x54x_notify(dev); @@ -1141,16 +1135,15 @@ x54x_req_setup(x54x_t *dev, uint32_t CCBPointer, Mailbox32_t *Mailbox32) static void -x54x_req_abort(x54x_t *dev, uint32_t CCBPointer) +req_abort(x54x_t *dev, uint32_t CCBPointer) { CCBU CmdBlock; /* Fetch data from the Command Control Block. */ DMAPageRead(CCBPointer, (uint8_t *)&CmdBlock, sizeof(CCB32)); - x54x_add_to_period(sizeof(CCB32)); + add_to_period(dev, sizeof(CCB32)); - x54x_mbi_setup(dev, CCBPointer, &CmdBlock, - 0x26, SCSI_STATUS_OK, MBI_NOT_FOUND); + mbi_setup(dev, CCBPointer, &CmdBlock, 0x26, SCSI_STATUS_OK, MBI_NOT_FOUND); DEBUG("%s: Callback: Send incoming mailbox\n", dev->name); x54x_notify(dev); } @@ -1158,7 +1151,7 @@ x54x_req_abort(x54x_t *dev, uint32_t CCBPointer) static uint32_t x54x_mbo(x54x_t *dev, Mailbox32_t *Mailbox32) -{ +{ Mailbox_t MailboxOut; uint32_t Outgoing; uint32_t ccbp; @@ -1176,7 +1169,7 @@ x54x_mbo(x54x_t *dev, Mailbox32_t *Mailbox32) if (dev->Mbx24bit) { Outgoing = Addr + (Cur * sizeof(Mailbox_t)); DMAPageRead(Outgoing, (uint8_t *)&MailboxOut, sizeof(Mailbox_t)); - x54x_add_to_period(sizeof(Mailbox_t)); + add_to_period(dev, sizeof(Mailbox_t)); ccbp = *(uint32_t *) &MailboxOut; Mailbox32->CCBPointer = (ccbp >> 24) | ((ccbp >> 8) & 0xff00) | ((ccbp << 8) & 0xff0000); @@ -1185,7 +1178,7 @@ x54x_mbo(x54x_t *dev, Mailbox32_t *Mailbox32) Outgoing = Addr + (Cur * sizeof(Mailbox32_t)); DMAPageRead(Outgoing, (uint8_t *)Mailbox32, sizeof(Mailbox32_t)); - x54x_add_to_period(sizeof(Mailbox32_t)); + add_to_period(dev, sizeof(Mailbox32_t)); } return(Outgoing); @@ -1206,10 +1199,10 @@ x54x_mbo_process(x54x_t *dev) if (mb32.u.out.ActionCode == MBO_START) { DEBUG("Start Mailbox Command\n"); - x54x_req_setup(dev, mb32.CCBPointer, &mb32); + req_setup(dev, mb32.CCBPointer, &mb32); } else if (!dev->MailboxIsBIOS && (mb32.u.out.ActionCode == MBO_ABORT)) { DEBUG("Abort Mailbox Command\n"); - x54x_req_abort(dev, mb32.CCBPointer); + req_abort(dev, mb32.CCBPointer); } /* else { DEBUG("Invalid action code: %02X\n", mb32.u.out.ActionCode); } */ @@ -1218,7 +1211,7 @@ x54x_mbo_process(x54x_t *dev) /* We got the mailbox, mark it as free in the guest. */ DEBUG("x54x_do_mail(): Writing %i bytes at %08X\n", sizeof(CmdStatus), Outgoing + CodeOffset); DMAPageWrite(Outgoing + CodeOffset, &CmdStatus, 1); - x54x_add_to_period(1); + add_to_period(dev, 1); if (dev->ToRaise) raise_irq(dev, 0, dev->ToRaise); @@ -1236,7 +1229,7 @@ x54x_mbo_process(x54x_t *dev) static void -x54x_do_mail(x54x_t *dev) +do_mail(x54x_t *dev) { int aggressive = 1; @@ -1272,13 +1265,10 @@ x54x_do_mail_again: } -static void x54x_cmd_done(x54x_t *dev, int suppress); - - static void -x54x_cmd_callback(void *priv) +cmd_callback(priv_t priv) { - x54x_t *dev = (x54x_t *) x54x_dev; + x54x_t *dev = (x54x_t *)priv; double period; int mailboxes_present, bios_mailboxes_present; @@ -1297,18 +1287,18 @@ x54x_cmd_callback(void *priv) dev->ven_callback(dev); } else if (!bios_mailboxes_present) { /* Do only normal mailboxes. */ - x54x_do_mail(dev); + do_mail(dev); } else { /* Do both kinds of mailboxes. */ if (dev->callback_phase) dev->ven_callback(dev); else - x54x_do_mail(dev); + do_mail(dev); dev->callback_phase = (dev->callback_phase + 1) & 0x01; } - period = (1000000.0 / x54x_dev->ha_bps) * ((double) TIMER_USEC) * ((double) dev->temp_period); + period = (1000000.0 / dev->ha_bps) * ((double) TIMER_USEC) * ((double) dev->temp_period); dev->timer_period = dev->media_period + ((int64_t) period) + (40LL * TIMER_USEC); DEBUG("Temporary period: %" PRId64 " us (%" PRIi64 " periods)\n", @@ -1317,7 +1307,7 @@ x54x_cmd_callback(void *priv) static uint8_t -x54x_in(uint16_t port, void *priv) +x54x_in(uint16_t port, priv_t priv) { x54x_t *dev = (x54x_t *)priv; uint8_t ret; @@ -1334,7 +1324,7 @@ x54x_in(uint16_t port, void *priv) dev->DataReply++; dev->DataReplyLeft--; if (! dev->DataReplyLeft) - x54x_cmd_done(dev, 0); + cmd_done(dev, 0); } break; @@ -1380,42 +1370,42 @@ x54x_in(uint16_t port, void *priv) static uint16_t -x54x_inw(uint16_t port, void *priv) +x54x_inw(uint16_t port, priv_t priv) { return((uint16_t) x54x_in(port, priv)); } static uint32_t -x54x_inl(uint16_t port, void *priv) +x54x_inl(uint16_t port, priv_t priv) { return((uint32_t) x54x_in(port, priv)); } static uint8_t -x54x_read(uint32_t port, void *priv) +x54x_read(uint32_t port, priv_t priv) { return(x54x_in(port & 3, priv)); } static uint16_t -x54x_readw(uint32_t port, void *priv) +x54x_readw(uint32_t port, priv_t priv) { return(x54x_inw(port & 3, priv)); } static uint32_t -x54x_readl(uint32_t port, void *priv) +x54x_readl(uint32_t port, priv_t priv) { return(x54x_inl(port & 3, priv)); } static void -x54x_reset_poll(void *priv) +x54x_reset_poll(priv_t priv) { x54x_t *dev = (x54x_t *)priv; @@ -1477,7 +1467,7 @@ x54x_reset_ctrl(x54x_t *dev, uint8_t Reset) static void -x54x_out(uint16_t port, uint8_t val, void *priv) +x54x_out(uint16_t port, uint8_t val, priv_t priv) { ReplyInquireSetupInformation *ReplyISI; x54x_t *dev = (x54x_t *)priv; @@ -1630,7 +1620,7 @@ x54x_out(uint16_t port, uint8_t val, void *priv) cmd->u.chs.head, cmd->u.chs.sec); } - dev->DataBuf[0] = x54x_bios_command(dev, dev->max_id, cmd, (dev->lba_bios)?1:0); + dev->DataBuf[0] = bios_command(dev, dev->max_id, cmd, (dev->lba_bios)?1:0); DEBUG("BIOS Completion/Status Code %x\n", dev->DataBuf[0]); dev->DataReplyLeft = 1; break; @@ -1782,7 +1772,7 @@ x54x_out(uint16_t port, uint8_t val, void *priv) if (dev->DataReplyLeft) dev->Status |= STAT_DFULL; else if (!dev->CmdParamLeft) - x54x_cmd_done(dev, suppress); + cmd_done(dev, suppress); break; case 2: @@ -1799,35 +1789,35 @@ x54x_out(uint16_t port, uint8_t val, void *priv) static void -x54x_outw(uint16_t port, uint16_t val, void *priv) +x54x_outw(uint16_t port, uint16_t val, priv_t priv) { x54x_out(port, val & 0xFF, priv); } static void -x54x_outl(uint16_t port, uint32_t val, void *priv) +x54x_outl(uint16_t port, uint32_t val, priv_t priv) { x54x_out(port, val & 0xFF, priv); } static void -x54x_write(uint32_t port, uint8_t val, void *priv) +x54x_write(uint32_t port, uint8_t val, priv_t priv) { x54x_out(port & 3, val, priv); } static void -x54x_writew(uint32_t port, uint16_t val, void *priv) +x54x_writew(uint32_t port, uint16_t val, priv_t priv) { x54x_outw(port & 3, val, priv); } static void -x54x_writel(uint32_t port, uint32_t val, void *priv) +x54x_writel(uint32_t port, uint32_t val, priv_t priv) { x54x_outl(port & 3, val, priv); } @@ -1926,39 +1916,12 @@ x54x_mem_disable(x54x_t *dev) } -/* General initialization routine for all boards. */ -void * -x54x_init(const device_t *info) -{ - x54x_t *dev; - - /* Allocate control block and set up basic stuff. */ - dev = (x54x_t *)mem_alloc(sizeof(x54x_t)); - if (dev == NULL) return(dev); - memset(dev, 0x00, sizeof(x54x_t)); - dev->type = info->local; - - dev->bus = info->flags; - dev->callback_phase = 0; - - timer_add(x54x_reset_poll, dev, &dev->ResetCB, &dev->ResetCB); - dev->timer_period = 10LL * TIMER_USEC; - timer_add(x54x_cmd_callback, dev, &dev->timer_period, TIMER_ALWAYS_ENABLED); - - x54x_dev = dev; - - return(dev); -} - - void -x54x_close(void *priv) +x54x_close(priv_t priv) { x54x_t *dev = (x54x_t *)priv; if (dev) { - x54x_dev = NULL; - /* Tell the timer to terminate. */ dev->timer_period = 0LL; @@ -1978,11 +1941,32 @@ x54x_close(void *priv) } -void -x54x_device_reset(void *priv) +/* General initialization routine for all boards. */ +priv_t +x54x_init(const device_t *info) { - x54x_t *dev = (x54x_t *)priv; + x54x_t *dev; + /* Allocate control block and set up basic stuff. */ + dev = (x54x_t *)mem_alloc(sizeof(x54x_t)); + if (dev == NULL) return(dev); + memset(dev, 0x00, sizeof(x54x_t)); + dev->type = info->local; + + dev->bus = info->flags; + dev->callback_phase = 0; + + timer_add(x54x_reset_poll, dev, &dev->ResetCB, &dev->ResetCB); + dev->timer_period = 10LL * TIMER_USEC; + timer_add(cmd_callback, dev, &dev->timer_period, TIMER_ALWAYS_ENABLED); + + return(dev); +} + + +void +x54x_device_reset(x54x_t *dev) +{ x54x_reset_ctrl(dev, 1); dev->ResetCB = 0LL; diff --git a/src/devices/scsi/scsi_x54x.h b/src/devices/scsi/scsi_x54x.h index a3030ce..5c65515 100644 --- a/src/devices/scsi/scsi_x54x.h +++ b/src/devices/scsi/scsi_x54x.h @@ -8,7 +8,7 @@ * * Definitions for the common AHA/BL code. * - * Version: @(#)scsi_x54x.h 1.0.7 2019/04/09 + * Version: @(#)scsi_x54x.h 1.0.8 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -513,20 +513,21 @@ typedef struct { } x54x_t; -extern void x54x_reset_ctrl(x54x_t *dev, uint8_t Reset); -extern void x54x_buf_alloc(scsi_device_t *sd, int length); -extern void x54x_buf_free(scsi_device_t *sd); -extern uint8_t x54x_mbo_process(x54x_t *dev); +extern void x54x_buf_alloc(scsi_device_t *, int length); +extern void x54x_buf_free(scsi_device_t *); + +extern uint8_t x54x_mbo_process(x54x_t *); extern void x54x_wait_for_poll(void); -extern void x54x_io_set(x54x_t *dev, uint32_t base, uint8_t len); -extern void x54x_io_remove(x54x_t *dev, uint32_t base, uint8_t len); -extern void x54x_mem_init(x54x_t *dev, uint32_t addr); -extern void x54x_mem_enable(x54x_t *dev); -extern void x54x_mem_set_addr(x54x_t *dev, uint32_t base); -extern void x54x_mem_disable(x54x_t *dev); -extern void *x54x_init(const device_t *info); -extern void x54x_close(void *priv); -extern void x54x_device_reset(void *priv); +extern void x54x_io_set(x54x_t *, uint32_t base, uint8_t len); +extern void x54x_io_remove(x54x_t *, uint32_t base, uint8_t len); +extern void x54x_mem_init(x54x_t *, uint32_t addr); +extern void x54x_mem_enable(x54x_t *); +extern void x54x_mem_set_addr(x54x_t *, uint32_t base); +extern void x54x_mem_disable(x54x_t *); +extern void x54x_reset_ctrl(x54x_t *, uint8_t Reset); +extern void x54x_device_reset(x54x_t *); +extern priv_t x54x_init(const device_t *info); +extern void x54x_close(priv_t); #endif /*SCSI_X54X_H*/ diff --git a/src/devices/sio/sio_acc3221.c b/src/devices/sio/sio_acc3221.c index 6b6b26b..91c9aa0 100644 --- a/src/devices/sio/sio_acc3221.c +++ b/src/devices/sio/sio_acc3221.c @@ -8,7 +8,7 @@ * * Implementation of the ACC 3221 Super I/O Chip. * - * Version: @(#)sio_acc3221.c 1.0.1 2019/05/02 + * Version: @(#)sio_acc3221.c 1.0.2 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -58,6 +58,7 @@ typedef struct { int reg_idx; uint8_t regs[256]; + fdc_t *fdc; } acc3221_t; @@ -127,7 +128,7 @@ serial2_handler(acc3221_t *dev) static void -acc3221_write(uint16_t addr, uint8_t val, void *priv) +acc3221_write(uint16_t addr, uint8_t val, priv_t priv) { acc3221_t *dev = (acc3221_t *)priv; uint8_t old; @@ -193,7 +194,7 @@ acc3221_write(uint16_t addr, uint8_t val, void *priv) static uint8_t -acc3221_read(uint16_t addr, void *priv) +acc3221_read(uint16_t addr, priv_t priv) { acc3221_t *dev = (acc3221_t *)priv; uint8_t ret = 0xff; @@ -228,7 +229,7 @@ acc3221_reset(acc3221_t *dev) static void -acc3221_close(void *priv) +acc3221_close(priv_t priv) { acc3221_t *dev = (acc3221_t *)priv; @@ -236,7 +237,7 @@ acc3221_close(void *priv) } -static void * +static priv_t acc3221_init(const device_t *info, UNUSED(void *parent)) { acc3221_t *dev; @@ -251,7 +252,7 @@ acc3221_init(const device_t *info, UNUSED(void *parent)) acc3221_reset(dev); - return(dev); + return((priv_t)dev); } diff --git a/src/devices/sio/sio_detect.c b/src/devices/sio/sio_detect.c index e9765aa..e4e1b2f 100644 --- a/src/devices/sio/sio_detect.c +++ b/src/devices/sio/sio_detect.c @@ -8,7 +8,7 @@ * * Super I/O chip detection code. * - * Version: @(#)sio_detect.c 1.0.6 2019/04/09 + * Version: @(#)sio_detect.c 1.0.7 2019/05/13 * * Author: Miran Grca, * @@ -52,7 +52,7 @@ typedef struct { static void -detect_write(uint16_t port, uint8_t val, void *priv) +detect_write(uint16_t port, uint8_t val, priv_t priv) { sio_detect_t *dev = (sio_detect_t *)priv; @@ -63,7 +63,7 @@ detect_write(uint16_t port, uint8_t val, void *priv) static uint8_t -detect_read(uint16_t port, void *priv) +detect_read(uint16_t port, priv_t priv) { sio_detect_t *dev = (sio_detect_t *)priv; uint8_t ret; @@ -77,7 +77,7 @@ detect_read(uint16_t port, void *priv) static void -detect_close(void *priv) +detect_close(priv_t priv) { sio_detect_t *dev = (sio_detect_t *)priv; @@ -85,7 +85,7 @@ detect_close(void *priv) } -static void * +static priv_t detect_init(const device_t *info, UNUSED(void *parent)) { sio_detect_t *dev = (sio_detect_t *)mem_alloc(sizeof(sio_detect_t)); @@ -110,7 +110,7 @@ detect_init(const device_t *info, UNUSED(void *parent)) io_sethandler(0x03f0, 2, detect_read,NULL,NULL, detect_write,NULL,NULL, dev); - return dev; + return((priv_t)dev); } diff --git a/src/devices/sio/sio_fdc37c669.c b/src/devices/sio/sio_fdc37c669.c index 23fea30..3086745 100644 --- a/src/devices/sio/sio_fdc37c669.c +++ b/src/devices/sio/sio_fdc37c669.c @@ -8,7 +8,7 @@ * * Implementation of the SMC FDC37C669 Super I/O Chip. * - * Version: @(#)sio_fdc37c669.c 1.0.11 2019/04/09 + * Version: @(#)sio_fdc37c669.c 1.0.12 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -98,7 +98,7 @@ make_port(fdc37c669_t *dev, uint8_t reg) static void -fdc37c669_write(uint16_t port, uint8_t val, void *priv) +fdc37c669_write(uint16_t port, uint8_t val, priv_t priv) { fdc37c669_t *dev = (fdc37c669_t *)priv; uint8_t indx = (port & 1) ? 0 : 1; @@ -244,7 +244,7 @@ fdc37c669_write(uint16_t port, uint8_t val, void *priv) static uint8_t -fdc37c669_read(uint16_t port, void *priv) +fdc37c669_read(uint16_t port, priv_t priv) { fdc37c669_t *dev = (fdc37c669_t *)priv; uint8_t indx = (port & 1) ? 0 : 1; @@ -300,7 +300,7 @@ fdc37c669_reset(fdc37c669_t *dev) static void -fdc37c669_close(void *priv) +fdc37c669_close(priv_t priv) { fdc37c669_t *dev = (fdc37c669_t *)priv; @@ -308,7 +308,7 @@ fdc37c669_close(void *priv) } -static void * +static priv_t fdc37c669_init(const device_t *info, UNUSED(void *parent)) { fdc37c669_t *dev = (fdc37c669_t *)mem_alloc(sizeof(fdc37c669_t)); @@ -321,7 +321,7 @@ fdc37c669_init(const device_t *info, UNUSED(void *parent)) fdc37c669_reset(dev); - return dev; + return((priv_t)dev); } diff --git a/src/devices/sio/sio_fdc37c66x.c b/src/devices/sio/sio_fdc37c66x.c index 7d80683..d330d43 100644 --- a/src/devices/sio/sio_fdc37c66x.c +++ b/src/devices/sio/sio_fdc37c66x.c @@ -9,7 +9,7 @@ * Implementation of the SMC FDC37C663 and FDC37C665 Super * I/O Chips. * - * Version: @(#)sio_fdc37c66x.c 1.0.11 2019/04/09 + * Version: @(#)sio_fdc37c66x.c 1.0.12 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -157,7 +157,7 @@ lpt1_handler(fdc37c66x_t *dev) static void -fdc37c66x_write(uint16_t port, uint8_t val, void *priv) +fdc37c66x_write(uint16_t port, uint8_t val, priv_t priv) { fdc37c66x_t *dev = (fdc37c66x_t *)priv; uint8_t valxor = 0; @@ -221,7 +221,7 @@ fdc37c66x_write(uint16_t port, uint8_t val, void *priv) static uint8_t -fdc37c66x_read(uint16_t port, void *priv) +fdc37c66x_read(uint16_t port, priv_t priv) { fdc37c66x_t *dev = (fdc37c66x_t *)priv; uint8_t ret = 0xff; @@ -268,7 +268,7 @@ fdc37c66x_reset(fdc37c66x_t *dev) static void -fdc37c66x_close(void *priv) +fdc37c66x_close(priv_t priv) { fdc37c66x_t *dev = (fdc37c66x_t *)priv; @@ -276,7 +276,7 @@ fdc37c66x_close(void *priv) } -static void * +static priv_t fdc37c66x_init(const device_t *info, UNUSED(void *parent)) { fdc37c66x_t *dev = (fdc37c66x_t *)mem_alloc(sizeof(fdc37c66x_t)); @@ -290,7 +290,7 @@ fdc37c66x_init(const device_t *info, UNUSED(void *parent)) fdc37c66x_reset(dev); - return dev; + return((priv_t)dev); } diff --git a/src/devices/sio/sio_fdc37c93x.c b/src/devices/sio/sio_fdc37c93x.c index 8091b96..e880e4b 100644 --- a/src/devices/sio/sio_fdc37c93x.c +++ b/src/devices/sio/sio_fdc37c93x.c @@ -9,7 +9,7 @@ * Implementation of the SMC FDC37C932FR and FDC37C935 Super * I/O Chips. * - * Version: @(#)sio_fdc37c93x.c 1.0.13 2019/04/09 + * Version: @(#)sio_fdc37c93x.c 1.0.14 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -100,7 +100,7 @@ make_port(fdc37c93x_t *dev, uint8_t ld) static uint8_t -auxio_read(uint16_t port, void *priv) +auxio_read(uint16_t port, priv_t priv) { fdc37c93x_t *dev = (fdc37c93x_t *)priv; @@ -109,7 +109,7 @@ auxio_read(uint16_t port, void *priv) static void -auxio_write(uint16_t port, uint8_t val, void *priv) +auxio_write(uint16_t port, uint8_t val, priv_t priv) { fdc37c93x_t *dev = (fdc37c93x_t *)priv; @@ -136,7 +136,7 @@ auxio_handler(fdc37c93x_t *dev) static uint8_t -gpio_read(uint16_t port, void *priv) +gpio_read(uint16_t port, priv_t priv) { fdc37c93x_t *dev = (fdc37c93x_t *)priv; @@ -145,7 +145,7 @@ gpio_read(uint16_t port, void *priv) static void -gpio_write(uint16_t port, uint8_t val, void *priv) +gpio_write(uint16_t port, uint8_t val, priv_t priv) { fdc37c93x_t *dev = (fdc37c93x_t *)priv; @@ -239,7 +239,7 @@ serial_handler(fdc37c93x_t *dev, int uart) static uint8_t -access_bus_read(uint16_t port, void *priv) +access_bus_read(uint16_t port, priv_t priv) { access_bus_t *dev = (access_bus_t *)priv; uint8_t ret = 0xff; @@ -267,7 +267,7 @@ access_bus_read(uint16_t port, void *priv) static void -access_bus_write(uint16_t port, uint8_t val, void *priv) +access_bus_write(uint16_t port, uint8_t val, priv_t priv) { access_bus_t *dev = (access_bus_t *)priv; @@ -292,6 +292,36 @@ access_bus_write(uint16_t port, uint8_t val, void *priv) } +static void +access_bus_close(priv_t priv) +{ + access_bus_t *dev = (access_bus_t *)priv; + + free(dev); +} + + +static priv_t +access_bus_init(const device_t *info, UNUSED(void *parent)) +{ + access_bus_t *dev = (access_bus_t *)mem_alloc(sizeof(access_bus_t)); + memset(dev, 0x00, sizeof(access_bus_t)); + + return((priv_t)dev); +} + + +static const device_t access_bus_device = { + "SMC FDC37C932FR ACCESS.bus", + 0, + 0x03, + NULL, + access_bus_init, access_bus_close, NULL, + NULL, NULL, NULL, NULL, + NULL +}; + + static void access_bus_handler(fdc37c93x_t *dev) { @@ -314,7 +344,7 @@ access_bus_handler(fdc37c93x_t *dev) static void -fdc37c93x_write(uint16_t port, uint8_t val, void *priv) +fdc37c93x_write(uint16_t port, uint8_t val, priv_t priv) { fdc37c93x_t *dev = (fdc37c93x_t *)priv; uint8_t indx = (port & 1) ? 0 : 1; @@ -526,7 +556,7 @@ fdc37c93x_write(uint16_t port, uint8_t val, void *priv) static uint8_t -fdc37c93x_read(uint16_t port, void *priv) +fdc37c93x_read(uint16_t port, priv_t priv) { fdc37c93x_t *dev = (fdc37c93x_t *)priv; uint8_t indx = (port & 1) ? 0 : 1; @@ -656,37 +686,7 @@ fdc37c93x_reset(fdc37c93x_t *dev) static void -access_bus_close(void *priv) -{ - access_bus_t *dev = (access_bus_t *)priv; - - free(dev); -} - - -static void * -access_bus_init(const device_t *info, UNUSED(void *parent)) -{ - access_bus_t *dev = (access_bus_t *)mem_alloc(sizeof(access_bus_t)); - memset(dev, 0x00, sizeof(access_bus_t)); - - return dev; -} - - -static const device_t access_bus_device = { - "SMC FDC37C932FR ACCESS.bus", - 0, - 0x03, - NULL, - access_bus_init, access_bus_close, NULL, - NULL, NULL, NULL, NULL, - NULL -}; - - -static void -fdc37c93x_close(void *priv) +fdc37c93x_close(priv_t priv) { fdc37c93x_t *dev = (fdc37c93x_t *)priv; @@ -694,10 +694,12 @@ fdc37c93x_close(void *priv) } -static void * -fdc37c93x_init(const device_t *info, UNUSED(void *parent)) +static priv_t +fdc37c93x_init(const device_t *info, void *parent) { - fdc37c93x_t *dev = (fdc37c93x_t *)mem_alloc(sizeof(fdc37c93x_t)); + fdc37c93x_t *dev; + + dev = (fdc37c93x_t *)mem_alloc(sizeof(fdc37c93x_t)); memset(dev, 0x00, sizeof(fdc37c93x_t)); dev->chip_id = info->local; @@ -707,14 +709,14 @@ fdc37c93x_init(const device_t *info, UNUSED(void *parent)) dev->gpio_regs[1] = 0xff; if (dev->chip_id == 0x03) - dev->access_bus = device_add(&access_bus_device); + dev->access_bus = device_add_parent(&access_bus_device, parent); io_sethandler(0x3f0, 2, fdc37c93x_read,NULL,NULL, fdc37c93x_write,NULL,NULL, dev); fdc37c93x_reset(dev); - return dev; + return((priv_t)dev); } diff --git a/src/devices/sio/sio_pc87306.c b/src/devices/sio/sio_pc87306.c index 09c37e5..47ff829 100644 --- a/src/devices/sio/sio_pc87306.c +++ b/src/devices/sio/sio_pc87306.c @@ -8,7 +8,7 @@ * * Emulation of the NatSemi PC87306 Super I/O chip. * - * Version: @(#)sio_pc87306.c 1.0.11 2019/04/09 + * Version: @(#)sio_pc87306.c 1.0.12 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -65,7 +65,7 @@ typedef struct { static void -gpio_write(uint16_t port, uint8_t val, void *priv) +gpio_write(uint16_t port, uint8_t val, priv_t priv) { pc87306_t *dev = (pc87306_t *)priv; @@ -74,7 +74,7 @@ gpio_write(uint16_t port, uint8_t val, void *priv) static uint8_t -gpio_read(uint16_t port, void *priv) +gpio_read(uint16_t port, priv_t priv) { pc87306_t *dev = (pc87306_t *)priv; @@ -216,7 +216,7 @@ serial_handler(pc87306_t *dev, int uart) static void -pc87306_write(uint16_t port, uint8_t val, void *priv) +pc87306_write(uint16_t port, uint8_t val, priv_t priv) { pc87306_t *dev = (pc87306_t *)priv; uint8_t indx, valxor; @@ -369,7 +369,7 @@ pc87306_write(uint16_t port, uint8_t val, void *priv) uint8_t -pc87306_read(uint16_t port, void *priv) +pc87306_read(uint16_t port, priv_t priv) { pc87306_t *dev = (pc87306_t *)priv; uint8_t ret = 0xff, indx; @@ -434,7 +434,7 @@ pc87306_reset(pc87306_t *dev) static void -pc87306_close(void *priv) +pc87306_close(priv_t priv) { pc87306_t *dev = (pc87306_t *)priv; @@ -442,7 +442,7 @@ pc87306_close(void *priv) } -static void * +static priv_t pc87306_init(const device_t *info, UNUSED(void *parent)) { pc87306_t *dev = (pc87306_t *)mem_alloc(sizeof(pc87306_t)); @@ -455,7 +455,7 @@ pc87306_init(const device_t *info, UNUSED(void *parent)) io_sethandler(0x02e, 2, pc87306_read,NULL,NULL, pc87306_write,NULL,NULL, dev); - return dev; + return((priv_t)dev); } diff --git a/src/devices/sio/sio_um8669f.c b/src/devices/sio/sio_um8669f.c index ffacf42..64252f1 100644 --- a/src/devices/sio/sio_um8669f.c +++ b/src/devices/sio/sio_um8669f.c @@ -29,7 +29,7 @@ * 70 - IRQ * 74 - DMA * - * Version: @(#)sio_um8669f.c 1.0.11 2019/04/09 + * Version: @(#)sio_um8669f.c 1.0.12 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -110,7 +110,7 @@ typedef struct { static void -pnp_write(uint16_t port, uint8_t val, void *priv) +pnp_write(uint16_t port, uint8_t val, priv_t priv) { um8669f_t *dev = (um8669f_t *)priv; uint8_t valxor = 0; @@ -191,7 +191,7 @@ pnp_write(uint16_t port, uint8_t val, void *priv) static uint8_t -pnp_read(uint16_t port, void *priv) +pnp_read(uint16_t port, priv_t priv) { um8669f_t *dev = (um8669f_t *)priv; uint8_t ret = 0xff; @@ -227,7 +227,7 @@ pnp_read(uint16_t port, void *priv) static void -um8669f_write(uint16_t port, uint8_t val, void *priv) +um8669f_write(uint16_t port, uint8_t val, priv_t priv) { um8669f_t *dev = (um8669f_t *)priv; int new_pnp_active; @@ -271,7 +271,7 @@ um8669f_write(uint16_t port, uint8_t val, void *priv) static uint8_t -um8669f_read(uint16_t port, void *priv) +um8669f_read(uint16_t port, priv_t priv) { um8669f_t *dev = (um8669f_t *)priv; uint8_t ret = 0xff; @@ -338,7 +338,7 @@ um8669f_reset(um8669f_t *dev) static void -um8669f_close(void *priv) +um8669f_close(priv_t priv) { um8669f_t *dev = (um8669f_t *)priv; @@ -346,7 +346,7 @@ um8669f_close(void *priv) } -static void * +static priv_t um8669f_init(const device_t *info, UNUSED(void *parent)) { um8669f_t *dev = (um8669f_t *)mem_alloc(sizeof(um8669f_t)); @@ -359,7 +359,7 @@ um8669f_init(const device_t *info, UNUSED(void *parent)) um8669f_reset(dev); - return dev; + return((priv_t)dev); } diff --git a/src/devices/sio/sio_w83877f.c b/src/devices/sio/sio_w83877f.c index db46095..fa7fc8d 100644 --- a/src/devices/sio/sio_w83877f.c +++ b/src/devices/sio/sio_w83877f.c @@ -10,7 +10,7 @@ * * Winbond W83877F Super I/O Chip * - * Version: @(#)sio_w83877f.c 1.0.11 2019/04/09 + * Version: @(#)sio_w83877f.c 1.0.12 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -93,8 +93,8 @@ typedef struct { } w83877f_t; -static void w83877f_write(uint16_t port, uint8_t val, void *priv); -static uint8_t w83877f_read(uint16_t port, void *priv); +static void w83877f_write(uint16_t port, uint8_t val, priv_t priv); +static uint8_t w83877f_read(uint16_t port, priv_t priv); static void @@ -196,7 +196,7 @@ serial_handler(w83877f_t *dev, int uart) static void -w83877f_write(uint16_t port, uint8_t val, void *priv) +w83877f_write(uint16_t port, uint8_t val, priv_t priv) { w83877f_t *dev = (w83877f_t *)priv; uint8_t indx = (port & 1) ? 0 : 1; @@ -380,7 +380,7 @@ w83877f_write(uint16_t port, uint8_t val, void *priv) static uint8_t -w83877f_read(uint16_t port, void *priv) +w83877f_read(uint16_t port, priv_t priv) { w83877f_t *dev = (w83877f_t *)priv; uint8_t indx = (port & 1) ? 0 : 1; @@ -448,7 +448,7 @@ w83877f_reset(w83877f_t *dev) static void -w83877f_close(void *priv) +w83877f_close(priv_t priv) { w83877f_t *dev = (w83877f_t *)priv; @@ -456,7 +456,7 @@ w83877f_close(void *priv) } -static void * +static priv_t w83877f_init(const device_t *info, UNUSED(void *parent)) { w83877f_t *dev = (w83877f_t *)mem_alloc(sizeof(w83877f_t)); @@ -467,7 +467,7 @@ w83877f_init(const device_t *info, UNUSED(void *parent)) w83877f_reset(dev); - return dev; + return((priv_t)dev); } diff --git a/src/devices/sound/snd_adlib.c b/src/devices/sound/snd_adlib.c index 39a80d3..91e10ed 100644 --- a/src/devices/sound/snd_adlib.c +++ b/src/devices/sound/snd_adlib.c @@ -8,7 +8,7 @@ * * Implementation of the ADLIB sound device. * - * Version: @(#)snd_adlib.c 1.0.9 2019/04/09 + * Version: @(#)snd_adlib.c 1.0.10 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -59,7 +59,7 @@ typedef struct { static void -get_buffer(int32_t *buffer, int len, void *priv) +get_buffer(int32_t *buffer, int len, priv_t priv) { adlib_t *dev = (adlib_t *)priv; int c; @@ -74,7 +74,7 @@ get_buffer(int32_t *buffer, int len, void *priv) static uint8_t -adlib_mca_read(int port, void *priv) +adlib_mca_read(int port, priv_t priv) { adlib_t *dev = (adlib_t *)priv; @@ -85,7 +85,7 @@ adlib_mca_read(int port, void *priv) static void -adlib_mca_write(int port, uint8_t val, void *priv) +adlib_mca_write(int port, uint8_t val, priv_t priv) { adlib_t *dev = (adlib_t *)priv; @@ -111,7 +111,7 @@ adlib_mca_write(int port, uint8_t val, void *priv) } -static void * +static priv_t adlib_init(const device_t *info, UNUSED(void *parent)) { adlib_t *dev; @@ -129,20 +129,20 @@ adlib_init(const device_t *info, UNUSED(void *parent)) case 1: /* MCA */ dev->pos_regs[0] = 0xd7; dev->pos_regs[1] = 0x70; - mca_add(adlib_mca_read, adlib_mca_write, dev); + mca_add(adlib_mca_read, adlib_mca_write, (priv_t)dev); break; } opl2_init(&dev->opl); - sound_add_handler(get_buffer, dev); + sound_add_handler(get_buffer, (priv_t)dev); - return(dev); + return((priv_t)dev); } static void -adlib_close(void *priv) +adlib_close(priv_t priv) { adlib_t *dev = (adlib_t *)priv; diff --git a/src/devices/sound/snd_adlibgold.c b/src/devices/sound/snd_adlibgold.c index 8f2ba9e..8129205 100644 --- a/src/devices/sound/snd_adlibgold.c +++ b/src/devices/sound/snd_adlibgold.c @@ -10,7 +10,7 @@ * * TODO: Stack allocation of big buffers (line 688 et al.) * - * Version: @(#)snd_adlibgold.c 1.0.13 2019/04/25 + * Version: @(#)snd_adlibgold.c 1.0.14 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -58,8 +58,7 @@ #include "snd_ym7128.h" -typedef struct adgold_t -{ +typedef struct { int adgold_irq_status; uint8_t adgold_eeprom[0x19]; @@ -81,19 +80,18 @@ typedef struct adgold_t int64_t adgold_mma_timer_count; - struct - { + struct { int timer0_latch, timer0_count; int timerbase_latch, timerbase_count; int timer1_latch, timer1_count; int timer2_latch, timer2_count, timer2_read; - + int voice_count[2], voice_latch[2]; } adgold_mma; opl_t opl; ym7128_t ym7128; - + int fm_vol_l, fm_vol_r; int samp_vol_l, samp_vol_r; int vol_l, vol_r; @@ -103,7 +101,7 @@ typedef struct adgold_t int16_t mma_buffer[2][SOUNDBUFLEN]; int pos; - + int surround_enabled; } adgold_t; @@ -148,7 +146,7 @@ static int treble_attenuation[0x10] = (int)(0.708 * 16384), /*3 dB*/ (int)(0 * 16384), /*0 dB*/ (int)(0.708 * 16384), /*3 dB*/ - (int)(1 * 16384), /*6 dB*/ + (int)(1 * 16384), /*6 dB*/ (int)(1.413 * 16384), /*9 dB*/ (int)(1.995 * 16384), /*12 dB*/ (int)(1.995 * 16384), @@ -187,12 +185,12 @@ void adgold_update_irq_status(adgold_t *adgold) if ((adgold->adgold_mma_status & 0x02) && !(adgold->adgold_mma_regs[1][0xc] & 2)) temp &= ~2; adgold->adgold_status = temp; - + if ((adgold->adgold_status ^ 0xf) && !adgold->adgold_irq_status) { picint(0x80); } - + adgold->adgold_irq_status = adgold->adgold_status ^ 0xf; } @@ -202,7 +200,7 @@ void adgold_getsamp_dma(adgold_t *adgold, int channel) if ((adgold->adgold_mma_regs[channel][0xc] & 0x60) && (((adgold->adgold_mma_fifo_end[channel] - adgold->adgold_mma_fifo_start[channel]) & 255) >= 127)) return; - + temp = dma_channel_read(1); if (temp == DMA_NODATA) return; adgold->adgold_mma_fifo[channel][adgold->adgold_mma_fifo_end[channel]] = temp; @@ -212,7 +210,7 @@ void adgold_getsamp_dma(adgold_t *adgold, int channel) temp = dma_channel_read(1); adgold->adgold_mma_fifo[channel][adgold->adgold_mma_fifo_end[channel]] = temp; adgold->adgold_mma_fifo_end[channel] = (adgold->adgold_mma_fifo_end[channel] + 1) & 255; - } + } if (((adgold->adgold_mma_fifo_end[channel] - adgold->adgold_mma_fifo_start[channel]) & 255) >= adgold->adgold_mma_intpos[channel]) { adgold->adgold_mma_status &= ~(0x01 << channel); @@ -220,9 +218,9 @@ void adgold_getsamp_dma(adgold_t *adgold, int channel) } } -void adgold_write(uint16_t addr, uint8_t val, void *p) +void adgold_write(uint16_t addr, uint8_t val, priv_t priv) { - adgold_t *adgold = (adgold_t *)p; + adgold_t *adgold = (adgold_t *)priv; switch (addr & 7) { case 0: case 1: @@ -257,7 +255,7 @@ void adgold_write(uint16_t addr, uint8_t val, void *p) if (val & 2) memcpy(adgold->adgold_eeprom, adgold->adgold_38x_regs, 0x19); break; - + case 0x04: /*Final output volume left*/ adgold->adgold_38x_regs[0x04] = val; adgold->vol_l = attenuation[val & 0x3f]; @@ -274,7 +272,7 @@ void adgold_write(uint16_t addr, uint8_t val, void *p) adgold->adgold_38x_regs[0x07] = val; adgold->treble = val & 0xf; break; - + case 0x09: /*FM volume left*/ adgold->adgold_38x_regs[0x09] = val; adgold->fm_vol_l = (int)(int8_t)(val - 128); @@ -291,12 +289,12 @@ void adgold_write(uint16_t addr, uint8_t val, void *p) adgold->adgold_38x_regs[0x0c] = val; adgold->samp_vol_r = (int)(int8_t)(val - 128); break; - + case 0x18: /*Surround*/ adgold->adgold_38x_regs[0x18] = val; ym7128_write(&adgold->ym7128, val); - break; - + break; + default: adgold->adgold_38x_regs[adgold->adgold_38x_addr] = val; break; @@ -331,11 +329,11 @@ void adgold_write(uint16_t addr, uint8_t val, void *p) case 0x7: adgold->adgold_mma.timer2_latch = (adgold->adgold_mma.timer2_latch & 0xff) | (val << 8); break; - + case 0x8: if ((val & 1) && !(adgold->adgold_mma_regs[0][8] & 1)) /*Reload timer 0*/ adgold->adgold_mma.timer0_count = adgold->adgold_mma.timer0_latch; - + if ((val & 2) && !(adgold->adgold_mma_regs[0][8] & 2)) /*Reload timer 1*/ adgold->adgold_mma.timer1_count = adgold->adgold_mma.timer1_latch; @@ -345,7 +343,7 @@ void adgold_write(uint16_t addr, uint8_t val, void *p) if ((val & 8) && !(adgold->adgold_mma_regs[0][8] & 8)) /*Reload base timer*/ adgold->adgold_mma.timerbase_count = adgold->adgold_mma.timerbase_latch; break; - + case 0x9: switch (val & 0x18) { @@ -365,7 +363,7 @@ void adgold_write(uint16_t addr, uint8_t val, void *p) { if (!(adgold->adgold_mma_regs[0][0x9] & 1)) adgold->adgold_mma.voice_count[0] = adgold->adgold_mma.voice_latch[0]; - + if (adgold->adgold_mma_regs[0][0xc] & 1) { if (adgold->adgold_mma_regs[0][0xc] & 0x80) @@ -405,7 +403,7 @@ void adgold_write(uint16_t addr, uint8_t val, void *p) } adgold->adgold_mma_enable[0] = val & 0x01; break; - + case 0xb: if (((adgold->adgold_mma_fifo_end[0] - adgold->adgold_mma_fifo_start[0]) & 255) < 128) { @@ -418,7 +416,7 @@ void adgold_write(uint16_t addr, uint8_t val, void *p) } } break; - + case 0xc: adgold->adgold_mma_intpos[0] = (7 - ((val >> 2) & 7)) * 8; break; @@ -449,7 +447,7 @@ void adgold_write(uint16_t addr, uint8_t val, void *p) { if (!(adgold->adgold_mma_regs[1][0x9] & 1)) adgold->adgold_mma.voice_count[1] = adgold->adgold_mma.voice_latch[1]; - + if (adgold->adgold_mma_regs[1][0xc] & 1) { while (((adgold->adgold_mma_fifo_end[1] - adgold->adgold_mma_fifo_start[1]) & 255) < 128) @@ -460,7 +458,7 @@ void adgold_write(uint16_t addr, uint8_t val, void *p) } adgold->adgold_mma_enable[1] = val & 0x01; break; - + case 0xb: if (((adgold->adgold_mma_fifo_end[1] - adgold->adgold_mma_fifo_start[1]) & 255) < 128) { @@ -483,17 +481,17 @@ void adgold_write(uint16_t addr, uint8_t val, void *p) } } -uint8_t adgold_read(uint16_t addr, void *p) +uint8_t adgold_read(uint16_t addr, priv_t priv) { - adgold_t *adgold = (adgold_t *)p; + adgold_t *adgold = (adgold_t *)priv; uint8_t temp = 0; - + switch (addr & 7) { case 0: case 1: temp = opl3_read(addr, &adgold->opl); break; - + case 2: if (adgold->adgold_38x_state) /*Read from control chip*/ temp = adgold->adgold_status; @@ -614,9 +612,9 @@ void adgold_mma_poll(adgold_t *adgold, int channel) } } -void adgold_timer_poll(void *p) +void adgold_timer_poll(priv_t priv) { - adgold_t *adgold = (adgold_t *)p; + adgold_t *adgold = (adgold_t *)priv; while (adgold->adgold_mma_timer_count <= 0LL) { @@ -681,9 +679,9 @@ void adgold_timer_poll(void *p) } } -static void adgold_get_buffer(int32_t *buffer, int len, void *p) +static void adgold_get_buffer(int32_t *buffer, int len, priv_t priv) { - adgold_t *adgold = (adgold_t *)p; + adgold_t *adgold = (adgold_t *)priv; #ifdef _MSC_VER /* TODO: Fix this to use a static buffer */ if (len > 512 * 1024) @@ -812,7 +810,8 @@ static void adgold_get_buffer(int32_t *buffer, int len, void *p) } -void *adgold_init(const device_t *info, UNUSED(void *parent)) +static priv_t +adgold_init(const device_t *info, UNUSED(void *parent)) { FILE *f; int c; @@ -868,13 +867,13 @@ void *adgold_init(const device_t *info, UNUSED(void *parent)) sound_add_handler(adgold_get_buffer, adgold); - return adgold; + return (priv_t)adgold; } -void adgold_close(void *p) +static void adgold_close(priv_t priv) { FILE *f; - adgold_t *adgold = (adgold_t *)p; + adgold_t *adgold = (adgold_t *)priv; f = plat_fopen(nvr_path(L"adgold.bin"), L"wb"); if (f != NULL) diff --git a/src/devices/sound/snd_audiopci.c b/src/devices/sound/snd_audiopci.c index ebb8393..fdc5e9d 100644 --- a/src/devices/sound/snd_audiopci.c +++ b/src/devices/sound/snd_audiopci.c @@ -8,7 +8,7 @@ * * Implementation of the AudioPCI sound device. * - * Version: @(#)snd_audiopci.c 1.0.17 2019/04/25 + * Version: @(#)snd_audiopci.c 1.0.18 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -206,7 +206,7 @@ es1371_update_irqs(es1371_t *dev) static uint8_t -es1371_inb(uint16_t port, void *priv) +es1371_inb(uint16_t port, priv_t priv) { es1371_t *dev = (es1371_t *)priv; uint8_t ret = 0; @@ -287,7 +287,7 @@ es1371_inb(uint16_t port, void *priv) static uint16_t -es1371_inw(uint16_t port, void *priv) +es1371_inw(uint16_t port, priv_t priv) { es1371_t *dev = (es1371_t *)priv; uint16_t ret = 0; @@ -346,7 +346,7 @@ es1371_inw(uint16_t port, void *priv) static uint32_t -es1371_inl(uint16_t port, void *priv) +es1371_inl(uint16_t port, priv_t priv) { es1371_t *dev = (es1371_t *)priv; uint32_t ret = 0; @@ -408,7 +408,7 @@ es1371_inl(uint16_t port, void *priv) static void -es1371_outb(uint16_t port, uint8_t val, void *priv) +es1371_outb(uint16_t port, uint8_t val, priv_t priv) { es1371_t *dev = (es1371_t *)priv; @@ -491,7 +491,7 @@ es1371_outb(uint16_t port, uint8_t val, void *priv) static void -es1371_outw(uint16_t port, uint16_t val, void *priv) +es1371_outw(uint16_t port, uint16_t val, priv_t priv) { es1371_t *dev = (es1371_t *)priv; @@ -517,7 +517,7 @@ es1371_outw(uint16_t port, uint16_t val, void *priv) static void -es1371_outl(uint16_t port, uint32_t val, void *priv) +es1371_outl(uint16_t port, uint32_t val, priv_t priv) { es1371_t *dev = (es1371_t *)priv; @@ -707,7 +707,7 @@ es1371_outl(uint16_t port, uint32_t val, void *priv) static void -capture_event(void *priv, int type, int rw, uint16_t port) +capture_event(priv_t priv, int type, int rw, uint16_t port) { es1371_t *dev = (es1371_t *)priv; @@ -728,92 +728,92 @@ capture_event(void *priv, int type, int rw, uint16_t port) static void -cap_write_sscape(uint16_t port, uint8_t val, void *p) +cap_write_sscape(uint16_t port, uint8_t val, priv_t priv) { - capture_event(p, LEGACY_EVENT_SSCAPE, 1, port); + capture_event(priv, LEGACY_EVENT_SSCAPE, 1, port); } static void -cap_write_codec(uint16_t port, uint8_t val, void *p) +cap_write_codec(uint16_t port, uint8_t val, priv_t priv) { - capture_event(p, LEGACY_EVENT_CODEC, 1, port); + capture_event(priv, LEGACY_EVENT_CODEC, 1, port); } static void -cap_write_sb(uint16_t port, uint8_t val, void *p) +cap_write_sb(uint16_t port, uint8_t val, priv_t priv) { - capture_event(p, LEGACY_EVENT_SB, 1, port); + capture_event(priv, LEGACY_EVENT_SB, 1, port); } static void -cap_write_adlib(uint16_t port, uint8_t val, void *p) +cap_write_adlib(uint16_t port, uint8_t val, priv_t priv) { - capture_event(p, LEGACY_EVENT_ADLIB, 1, port); + capture_event(priv, LEGACY_EVENT_ADLIB, 1, port); } static void -cap_write_master_pic(uint16_t port, uint8_t val, void *p) +cap_write_master_pic(uint16_t port, uint8_t val, priv_t priv) { - capture_event(p, LEGACY_EVENT_MASTER_PIC, 1, port); + capture_event(priv, LEGACY_EVENT_MASTER_PIC, 1, port); } static void -cap_write_master_dma(uint16_t port, uint8_t val, void *p) +cap_write_master_dma(uint16_t port, uint8_t val, priv_t priv) { - capture_event(p, LEGACY_EVENT_MASTER_DMA, 1, port); + capture_event(priv, LEGACY_EVENT_MASTER_DMA, 1, port); } static void -cap_write_slave_pic(uint16_t port, uint8_t val, void *p) +cap_write_slave_pic(uint16_t port, uint8_t val, priv_t priv) { - capture_event(p, LEGACY_EVENT_SLAVE_PIC, 1, port); + capture_event(priv, LEGACY_EVENT_SLAVE_PIC, 1, port); } static void -cap_write_slave_dma(uint16_t port, uint8_t val, void *p) +cap_write_slave_dma(uint16_t port, uint8_t val, priv_t priv) { - capture_event(p, LEGACY_EVENT_SLAVE_DMA, 1, port); + capture_event(priv, LEGACY_EVENT_SLAVE_DMA, 1, port); } static uint8_t -cap_read_sscape(uint16_t port, void *p) +cap_read_sscape(uint16_t port, priv_t priv) { - capture_event(p, LEGACY_EVENT_SSCAPE, 0, port); + capture_event(priv, LEGACY_EVENT_SSCAPE, 0, port); return 0xff; } static uint8_t -cap_read_codec(uint16_t port, void *p) +cap_read_codec(uint16_t port, priv_t priv) { - capture_event(p, LEGACY_EVENT_CODEC, 0, port); + capture_event(priv, LEGACY_EVENT_CODEC, 0, port); return 0xff; } static uint8_t -cap_read_sb(uint16_t port, void *p) +cap_read_sb(uint16_t port, priv_t priv) { - capture_event(p, LEGACY_EVENT_SB, 0, port); + capture_event(priv, LEGACY_EVENT_SB, 0, port); return 0xff; } static uint8_t -cap_read_adlib(uint16_t port, void *p) +cap_read_adlib(uint16_t port, priv_t priv) { - capture_event(p, LEGACY_EVENT_ADLIB, 0, port); + capture_event(priv, LEGACY_EVENT_ADLIB, 0, port); return 0xff; } static uint8_t -cap_read_master_pic(uint16_t port, void *p) +cap_read_master_pic(uint16_t port, priv_t priv) { - capture_event(p, LEGACY_EVENT_MASTER_PIC, 0, port); + capture_event(priv, LEGACY_EVENT_MASTER_PIC, 0, port); return 0xff; } static uint8_t -cap_read_master_dma(uint16_t port, void *p) +cap_read_master_dma(uint16_t port, priv_t priv) { - capture_event(p, LEGACY_EVENT_MASTER_DMA, 0, port); + capture_event(priv, LEGACY_EVENT_MASTER_DMA, 0, port); return 0xff; } static uint8_t -cap_read_slave_pic(uint16_t port, void *p) +cap_read_slave_pic(uint16_t port, priv_t priv) { - capture_event(p, LEGACY_EVENT_SLAVE_PIC, 0, port); + capture_event(priv, LEGACY_EVENT_SLAVE_PIC, 0, port); return 0xff; } static uint8_t -cap_read_slave_dma(uint16_t port, void *p) +cap_read_slave_dma(uint16_t port, priv_t priv) { - capture_event(p, LEGACY_EVENT_SLAVE_DMA, 0, port); + capture_event(priv, LEGACY_EVENT_SLAVE_DMA, 0, port); return 0xff; } @@ -1064,7 +1064,7 @@ es1371_update(es1371_t *dev) static void -es1371_poll(void *priv) +es1371_poll(priv_t priv) { es1371_t *dev = (es1371_t *)priv; @@ -1135,7 +1135,7 @@ es1371_poll(void *priv) static void -es1371_get_buffer(int32_t *buffer, int len, void *priv) +es1371_get_buffer(int32_t *buffer, int len, priv_t priv) { es1371_t *dev = (es1371_t *)priv; int c; @@ -1190,7 +1190,7 @@ generate_es1371_filter(void) static uint8_t -es1371_pci_read(int func, int addr, void *priv) +es1371_pci_read(int func, int addr, priv_t priv) { es1371_t *dev = (es1371_t *)priv; @@ -1249,9 +1249,9 @@ es1371_pci_read(int func, int addr, void *priv) static void -es1371_pci_write(int func, int addr, uint8_t val, void *p) +es1371_pci_write(int func, int addr, uint8_t val, priv_t priv) { - es1371_t *dev = (es1371_t *)p; + es1371_t *dev = (es1371_t *)priv; if (func) return; @@ -1330,7 +1330,7 @@ es1371_pci_write(int func, int addr, uint8_t val, void *p) } -static void * +static priv_t es1371_init(const device_t *info, UNUSED(void *parent)) { es1371_t *dev = (es1371_t *)mem_alloc(sizeof(es1371_t)); @@ -1345,12 +1345,12 @@ es1371_init(const device_t *info, UNUSED(void *parent)) generate_es1371_filter(); - return dev; + return (priv_t)dev; } static void -es1371_close(void *priv) +es1371_close(priv_t priv) { es1371_t *dev = (es1371_t *)priv; @@ -1359,7 +1359,7 @@ es1371_close(void *priv) static void -es1371_speed_changed(void *priv) +es1371_speed_changed(priv_t priv) { es1371_t *dev = (es1371_t *)priv; diff --git a/src/devices/sound/snd_cms.c b/src/devices/sound/snd_cms.c index 91bd9e4..5c26ec8 100644 --- a/src/devices/sound/snd_cms.c +++ b/src/devices/sound/snd_cms.c @@ -8,7 +8,7 @@ * * Implementation of the Creative CMS/GameBlaster sound device. * - * Version: @(#)snd_cms.c 1.0.9 2019/04/09 + * Version: @(#)snd_cms.c 1.0.10 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -136,7 +136,7 @@ cms_update(cms_t *dev) static void -get_buffer(int32_t *buffer, int len, void *priv) +get_buffer(int32_t *buffer, int len, priv_t priv) { cms_t *dev = (cms_t *)priv; int c; @@ -151,7 +151,7 @@ get_buffer(int32_t *buffer, int len, void *priv) static void -cms_write(uint16_t addr, uint8_t val, void *priv) +cms_write(uint16_t addr, uint8_t val, priv_t priv) { cms_t *dev = (cms_t *)priv; int voice; @@ -209,7 +209,7 @@ cms_write(uint16_t addr, uint8_t val, void *priv) static uint8_t -cms_read(uint16_t addr, void *priv) +cms_read(uint16_t addr, priv_t priv) { cms_t *dev = (cms_t *)priv; uint8_t ret = 0xff; @@ -240,7 +240,7 @@ cms_read(uint16_t addr, void *priv) } -static void * +static priv_t cms_init(const device_t *info, UNUSED(void *parent)) { cms_t *dev; @@ -249,16 +249,16 @@ cms_init(const device_t *info, UNUSED(void *parent)) memset(dev, 0x00, sizeof(cms_t)); io_sethandler(0x0220, 16, - cms_read,NULL,NULL, cms_write,NULL,NULL, dev); + cms_read,NULL,NULL, cms_write,NULL,NULL, (priv_t)dev); - sound_add_handler(get_buffer, dev); + sound_add_handler(get_buffer, (priv_t)dev); - return(dev); + return((priv_t)dev); } static void -cms_close(void *priv) +cms_close(priv_t priv) { cms_t *dev = (cms_t *)priv; diff --git a/src/devices/sound/snd_emu8k.c b/src/devices/sound/snd_emu8k.c index b0c1ab0..5693607 100644 --- a/src/devices/sound/snd_emu8k.c +++ b/src/devices/sound/snd_emu8k.c @@ -8,7 +8,7 @@ * * Implementation of Emu8000 emulator. * - * Version: @(#)snd_emu8k.c 1.0.14 2019/05/05 + * Version: @(#)snd_emu8k.c 1.0.15 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -396,9 +396,9 @@ static inline void EMU8K_WRITE(emu8k_t *emu8k, uint32_t addr, uint16_t val) emu8k->ram[addr - EMU8K_RAM_MEM_START] = val; } -uint16_t emu8k_inw(uint16_t addr, void *p) +uint16_t emu8k_inw(uint16_t addr, priv_t priv) { - emu8k_t *emu8k = (emu8k_t *)p; + emu8k_t *emu8k = (emu8k_t *)priv; uint16_t ret = 0xffff; #ifdef EMU8K_DEBUG_REGISTERS @@ -764,9 +764,9 @@ uint16_t emu8k_inw(uint16_t addr, void *p) return 0xffff; } -void emu8k_outw(uint16_t addr, uint16_t val, void *p) +void emu8k_outw(uint16_t addr, uint16_t val, priv_t priv) { - emu8k_t *emu8k = (emu8k_t *)p; + emu8k_t *emu8k = (emu8k_t *)priv; /*TODO: I would like to not call this here, but i found it was needed or else cubic player would not finish opening (take a looot more of time than usual). * Basically, being here means that the audio is generated in the emulation thread, instead of the audio thread.*/ @@ -1530,23 +1530,23 @@ void emu8k_outw(uint16_t addr, uint16_t val, void *p) } -uint8_t emu8k_inb(uint16_t addr, void *p) +uint8_t emu8k_inb(uint16_t addr, priv_t priv) { /* Reading a single byte is a feature that at least Impulse tracker uses, * but only on detection code and not for odd addresses.*/ if (addr & 1) - return emu8k_inw(addr & ~1, p) >> 1; - return emu8k_inw(addr, p) & 0xff; + return emu8k_inw(addr & ~1, priv) >> 1; + return emu8k_inw(addr, priv) & 0xff; } -void emu8k_outb(uint16_t addr, uint8_t val, void *p) +void emu8k_outb(uint16_t addr, uint8_t val, priv_t priv) { /* TODO: AWE32 docs says that you cannot write in bytes, but if * an app were to use this implementation, the content of the LS Byte would be lost.*/ if (addr & 1) - emu8k_outw(addr & ~1, val << 8, p); + emu8k_outw(addr & ~1, val << 8, priv); else - emu8k_outw(addr, val, p); + emu8k_outw(addr, val, priv); } /* TODO: This is not a correct emulation, just a workalike implementation. */ diff --git a/src/devices/sound/snd_gus.c b/src/devices/sound/snd_gus.c index 2bf6a8d..5da46dd 100644 --- a/src/devices/sound/snd_gus.c +++ b/src/devices/sound/snd_gus.c @@ -8,7 +8,7 @@ * * Implementation of the Gravis UltraSound sound device. * - * Version: @(#)snd_gus.c 1.0.13 2019/04/25 + * Version: @(#)snd_gus.c 1.0.14 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -238,7 +238,7 @@ midi_update_int_status(gus_t *dev) static void -gus_write(uint16_t addr, uint8_t val, void *priv) +gus_write(uint16_t addr, uint8_t val, priv_t priv) { gus_t *dev = (gus_t *)priv; #if defined(DEV_BRANCH) && defined(USE_GUSMAX) @@ -688,7 +688,7 @@ gus_write(uint16_t addr, uint8_t val, void *priv) static uint8_t -gus_read(uint16_t addr, void *priv) +gus_read(uint16_t addr, priv_t priv) { gus_t *dev = (gus_t *)priv; uint8_t val = 0xff; @@ -907,7 +907,7 @@ gus_read(uint16_t addr, void *priv) static void -poll_timer_1(void *priv) +poll_timer_1(priv_t priv) { gus_t *dev = (gus_t *)priv; @@ -939,7 +939,7 @@ poll_timer_1(void *priv) static void -poll_timer_2(void *priv) +poll_timer_2(priv_t priv) { gus_t *dev = (gus_t *)priv; @@ -989,7 +989,7 @@ gus_update(gus_t *dev) static void -poll_wave(void *priv) +poll_wave(priv_t priv) { gus_t *dev = (gus_t *)priv; uint32_t addr; @@ -1127,7 +1127,7 @@ poll_wave(void *priv) static void -get_buffer(int32_t *buffer, int len, void *priv) +get_buffer(int32_t *buffer, int len, priv_t priv) { gus_t *dev = (gus_t *)priv; int c; @@ -1155,7 +1155,7 @@ get_buffer(int32_t *buffer, int len, void *priv) } -static void * +static priv_t gus_init(const device_t *info, UNUSED(void *parent)) { gus_t *dev; @@ -1221,18 +1221,18 @@ gus_init(const device_t *info, UNUSED(void *parent)) #endif } - timer_add(poll_wave, dev, &dev->samp_timer, TIMER_ALWAYS_ENABLED); - timer_add(poll_timer_1, dev, &dev->timer_1, TIMER_ALWAYS_ENABLED); - timer_add(poll_timer_2, dev, &dev->timer_2, TIMER_ALWAYS_ENABLED); + timer_add(poll_wave, (priv_t)dev, &dev->samp_timer, TIMER_ALWAYS_ENABLED); + timer_add(poll_timer_1, (priv_t)dev, &dev->timer_1, TIMER_ALWAYS_ENABLED); + timer_add(poll_timer_2, (priv_t)dev, &dev->timer_2, TIMER_ALWAYS_ENABLED); - sound_add_handler(get_buffer, dev); + sound_add_handler(get_buffer, (priv_t)dev); - return(dev); + return((priv_t)dev); } static void -gus_close(void *priv) +gus_close(priv_t priv) { gus_t *dev = (gus_t *)priv; @@ -1244,7 +1244,7 @@ gus_close(void *priv) static void -speed_changed(void *priv) +speed_changed(priv_t priv) { gus_t *dev = (gus_t *)priv; diff --git a/src/devices/sound/snd_mpu401.c b/src/devices/sound/snd_mpu401.c index 63845c6..e7ddbdc 100644 --- a/src/devices/sound/snd_mpu401.c +++ b/src/devices/sound/snd_mpu401.c @@ -8,7 +8,7 @@ * * Roland MPU-401 emulation. * - * Version: @(#)snd_mpu401.c 1.0.14 2019/04/25 + * Version: @(#)snd_mpu401.c 1.0.15 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -69,12 +69,12 @@ static int64_t mpu401_eoi_callback = 0LL; static int64_t mpu401_reset_callback = 0LL; -static void MPU401_WriteCommand(mpu_t *mpu, uint8_t val); -static void MPU401_EOIHandlerDispatch(void *p); +static void MPU401_WriteCommand(mpu_t *, uint8_t); +static void MPU401_EOIHandlerDispatch(priv_t); static void -QueueByte(mpu_t *mpu, uint8_t data) +QueueByte(mpu_t *mpu, uint8_t data) { if (mpu->state.block_ack) { mpu->state.block_ack = 0; @@ -102,7 +102,7 @@ QueueByte(mpu_t *mpu, uint8_t data) static void -ClrQueue(mpu_t *mpu) +ClrQueue(mpu_t *mpu) { mpu->queue_used=0; mpu->queue_pos=0; @@ -110,7 +110,7 @@ ClrQueue(mpu_t *mpu) static void -MPU401_Reset(mpu_t *mpu) +MPU401_Reset(mpu_t *mpu) { uint8_t i; @@ -156,7 +156,7 @@ MPU401_Reset(mpu_t *mpu) static void -MPU401_ResetDone(void *priv) +MPU401_ResetDone(priv_t priv) { mpu_t *mpu = (mpu_t *)priv; @@ -357,7 +357,7 @@ MPU401_WriteCommand(mpu_t *mpu, uint8_t val) static void -MPU401_WriteData(mpu_t *mpu, uint8_t val) +MPU401_WriteData(mpu_t *mpu, uint8_t val) { static int length, cnt, posd; @@ -370,7 +370,7 @@ MPU401_WriteData(mpu_t *mpu, uint8_t val) mpu->state.command_byte = 0; return; } - + switch (mpu->state.command_byte) { /* 0xe# command data */ case 0x00: break; @@ -587,7 +587,7 @@ MPU401_WriteData(mpu_t *mpu, uint8_t val) case 0x90: case 0xa0: case 0xb0: - case 0xe0: + case 0xe0: mpu->playbuf[mpu->state.channel].type = T_MIDI_NORM; length = mpu->playbuf[mpu->state.channel].length = 3; break; @@ -609,7 +609,7 @@ MPU401_WriteData(mpu_t *mpu, uint8_t val) static void -MPU401_IntelligentOut(mpu_t *mpu, uint8_t chan) +MPU401_IntelligentOut(mpu_t *mpu, uint8_t chan) { uint8_t val; uint8_t i; @@ -639,7 +639,7 @@ MPU401_IntelligentOut(mpu_t *mpu, uint8_t chan) static void -UpdateTrack(mpu_t *mpu, uint8_t chan) +UpdateTrack(mpu_t *mpu, uint8_t chan) { MPU401_IntelligentOut(mpu, chan); @@ -656,7 +656,7 @@ UpdateTrack(mpu_t *mpu, uint8_t chan) static void -UpdateConductor(mpu_t *mpu) +UpdateConductor(mpu_t *mpu) { if (mpu->condbuf.value[0] == 0xfc) { mpu->condbuf.value[0] = 0; @@ -708,7 +708,7 @@ MPU401_EOIHandler(void *priv) static void -MPU401_EOIHandlerDispatch(void *priv) +MPU401_EOIHandlerDispatch(priv_t priv) { mpu_t *mpu = (mpu_t *)priv; @@ -721,7 +721,7 @@ MPU401_EOIHandlerDispatch(void *priv) static void -imf_write(uint16_t addr, uint8_t val, void *priv) +imf_write(uint16_t addr, uint8_t val, priv_t priv) { DBGLOG(1, "IMF:Wr %4X,%X\n", addr, val); } @@ -731,7 +731,7 @@ uint8_t MPU401_ReadData(mpu_t *mpu) { uint8_t ret; - + ret = MSG_MPU_ACK; if (mpu->queue_used) { if (mpu->queue_pos >= MPU401_QUEUE) @@ -784,7 +784,7 @@ MPU401_ReadData(mpu_t *mpu) static void -mpu401_write(uint16_t addr, uint8_t val, void *priv) +mpu401_write(uint16_t addr, uint8_t val, priv_t priv) { mpu_t *mpu = (mpu_t *)priv; @@ -805,7 +805,7 @@ mpu401_write(uint16_t addr, uint8_t val, void *priv) static uint8_t -mpu401_read(uint16_t addr, void *priv) +mpu401_read(uint16_t addr, priv_t priv) { mpu_t *mpu = (mpu_t *)priv; uint8_t ret = 0; @@ -833,7 +833,7 @@ mpu401_read(uint16_t addr, void *priv) static void -MPU401_Event(void *priv) +MPU401_Event(priv_t priv) { mpu_t *mpu = (mpu_t *)priv; int new_time; @@ -916,11 +916,11 @@ mpu401_init(mpu_t *mpu, uint16_t addr, int irq, int mode) io_sethandler(0x2A20, 16, NULL, NULL, NULL, imf_write, NULL, NULL, mpu); - timer_add(MPU401_Event, mpu, + timer_add(MPU401_Event, (priv_t)mpu, &mpu401_event_callback, &mpu401_event_callback); - timer_add(MPU401_EOIHandler, mpu, + timer_add(MPU401_EOIHandler, (priv_t)mpu, &mpu401_eoi_callback, &mpu401_eoi_callback); - timer_add(MPU401_ResetDone, mpu, + timer_add(MPU401_ResetDone, (priv_t)mpu, &mpu401_reset_callback, &mpu401_reset_callback); MPU401_Reset(mpu); @@ -930,7 +930,6 @@ mpu401_init(mpu_t *mpu, uint16_t addr, int irq, int mode) void mpu401_device_add(void) { - if (MCA) device_add(&mpu401_mca_device); else @@ -939,7 +938,7 @@ mpu401_device_add(void) static uint8_t -mpu401_mca_read(int port, void *priv) +mpu401_mca_read(int port, priv_t priv) { mpu_t *dev = (mpu_t *)priv; @@ -948,7 +947,7 @@ mpu401_mca_read(int port, void *priv) static void -mpu401_mca_write(int port, uint8_t val, void *priv) +mpu401_mca_write(int port, uint8_t val, priv_t priv) { mpu_t *dev = (mpu_t *)priv; uint16_t addr; @@ -971,7 +970,7 @@ mpu401_mca_write(int port, uint8_t val, void *priv) } -static void * +static priv_t mpu401_standalone_init(const device_t *info, UNUSED(void *parent)) { mpu_t *dev; @@ -995,12 +994,12 @@ mpu401_standalone_init(const device_t *info, UNUSED(void *parent)) mpu401_init(dev, base, irq, M_INTELLIGENT); - return(dev); + return((priv_t)dev); } static void -mpu401_standalone_close(void *priv) +mpu401_standalone_close(priv_t priv) { mpu_t *dev = (mpu_t *)priv; diff --git a/src/devices/sound/snd_pas16.c b/src/devices/sound/snd_pas16.c index 5744839..9ac3e3f 100644 --- a/src/devices/sound/snd_pas16.c +++ b/src/devices/sound/snd_pas16.c @@ -79,13 +79,13 @@ * FF88 - board model * 3 = PAS16 * - * Version: @(#)snd_pas16.c 1.0.14 2019/05/05 + * Version: @(#)snd_pas16.c 1.0.15 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, * Sarah Walker, * - * Copyright 2017,2019 Fred N. van Kempen. + * Copyright 2017-2019 Fred N. van Kempen. * Copyright 2016-2018 Miran Grca. * Copyright 2008-2018 Sarah Walker. * @@ -134,30 +134,18 @@ typedef struct pas16_t { uint16_t base; - int irq, dma; - uint8_t audiofilt; - uint8_t audio_mixer; - uint8_t compat, compat_base; - uint8_t enhancedscsi; - uint8_t io_conf_1, io_conf_2, io_conf_3, io_conf_4; - uint8_t irq_stat, irq_ena; - uint8_t pcm_ctrl; uint16_t pcm_dat; - uint16_t pcm_dat_l, pcm_dat_r; - uint8_t sb_irqdma; - int stereo_lr; - uint8_t sys_conf_1, sys_conf_2, sys_conf_3, sys_conf_4; struct @@ -182,9 +170,9 @@ typedef struct pas16_t int pos; } pas16_t; -static uint8_t pas16_pit_in(uint16_t port, void *priv); -static void pas16_pit_out(uint16_t port, uint8_t val, void *priv); -static void pas16_update(pas16_t *pas16); +static uint8_t pas16_pit_in(uint16_t, priv_t); +static void pas16_pit_out(uint16_t, uint8_t, priv_t); +static void pas16_update(pas16_t *); static int pas16_dmas[8] = {4, 1, 2, 3, 0, 5, 6, 7}; static int pas16_irqs[16] = {0, 2, 3, 4, 5, 6, 7, 10, 11, 12, 14, 15, 0, 0, 0, 0}; @@ -214,14 +202,11 @@ enum PAS16_FILT_MUTE = 0x20 }; -static uint8_t pas16_in(uint16_t port, void *p) +static uint8_t pas16_in(uint16_t port, priv_t priv) { - pas16_t *pas16 = (pas16_t *)p; + pas16_t *pas16 = (pas16_t *)priv; uint8_t temp; -/* if (CS == 0xCA53 && pc == 0x3AFC) - fatal("here");*/ - switch ((port - pas16->base) + 0x388) { case 0x388: case 0x389: case 0x38a: case 0x38b: @@ -313,24 +298,12 @@ static uint8_t pas16_in(uint16_t port, void *p) break; } -/* if (port != 0x388 && port != 0x389 && port != 0xb8b) */DEBUG("pas16_in : port %04X return %02X %04X:%04X\n", port, temp, CS,cpu_state.pc); -/* if (CS == 0x1FF4 && pc == 0x0585) - { - if (output) - fatal("here"); - output = 3; - }*/ - return temp; } -static void pas16_out(uint16_t port, uint8_t val, void *p) +static void pas16_out(uint16_t port, uint8_t val, priv_t priv) { - pas16_t *pas16 = (pas16_t *)p; - -/* if (port != 0x388 && port != 0x389) */DEBUG("pas16_out : port %04X val %02X %04X:%04X\n", port, val, CS,cpu_state.pc); -/* if (CS == 0x369 && pc == 0x2AC5) - fatal("here\n");*/ + pas16_t *pas16 = (pas16_t *)priv; switch ((port - pas16->base) + 0x388) { @@ -430,25 +403,11 @@ static void pas16_out(uint16_t port, uint8_t val, void *p) default: DEBUG("pas16_out : unknown %04X\n", port); } - if (cpu_state.pc == 0x80048CF3) - { -#if 0 - if (output) -#endif - fatal("here\n"); -#if 0 - output = 3; -#endif - } -#if 0 - if (CS == 0x1FF4 && pc == 0x0431) - output = 3; -#endif } -static void pas16_pit_out(uint16_t port, uint8_t val, void *p) +static void pas16_pit_out(uint16_t port, uint8_t val, priv_t priv) { - pas16_t *pas16 = (pas16_t *)p; + pas16_t *pas16 = (pas16_t *)priv; int t; switch (port & 3) { @@ -546,9 +505,9 @@ static void pas16_pit_out(uint16_t port, uint8_t val, void *p) } } -static uint8_t pas16_pit_in(uint16_t port, void *p) +static uint8_t pas16_pit_in(uint16_t port, priv_t priv) { - pas16_t *pas16 = (pas16_t *)p; + pas16_t *pas16 = (pas16_t *)priv; uint8_t temp = 0xff; int t = port & 3; switch (port & 3) @@ -604,9 +563,9 @@ static uint8_t pas16_readdma(pas16_t *pas16) return dma_channel_read(pas16->dma); } -static void pas16_pcm_poll(void *p) +static void pas16_pcm_poll(priv_t priv) { - pas16_t *pas16 = (pas16_t *)p; + pas16_t *pas16 = (pas16_t *)priv; pas16_update(pas16); if (pas16->pit.m[0] & 2) @@ -684,9 +643,9 @@ static void pas16_pcm_poll(void *p) } } -static void pas16_out_base(uint16_t port, uint8_t val, void *p) +static void pas16_out_base(uint16_t port, uint8_t val, priv_t priv) { - pas16_t *pas16 = (pas16_t *)p; + pas16_t *pas16 = (pas16_t *)priv; io_removehandler((pas16->base - 0x388) + 0x0388, 0x0004, pas16_in, NULL, NULL, pas16_out, NULL, NULL, pas16); io_removehandler((pas16->base - 0x388) + 0x0788, 0x0004, pas16_in, NULL, NULL, pas16_out, NULL, NULL, pas16); @@ -706,7 +665,7 @@ static void pas16_out_base(uint16_t port, uint8_t val, void *p) io_removehandler((pas16->base - 0x388) + 0xf788, 0x0004, pas16_in, NULL, NULL, pas16_out, NULL, NULL, pas16); io_removehandler((pas16->base - 0x388) + 0xfb88, 0x0004, pas16_in, NULL, NULL, pas16_out, NULL, NULL, pas16); io_removehandler((pas16->base - 0x388) + 0xff88, 0x0004, pas16_in, NULL, NULL, pas16_out, NULL, NULL, pas16); - + pas16->base = val << 2; DEBUG("pas16_write_base : PAS16 base now at %04X\n", pas16->base); @@ -751,9 +710,9 @@ static void pas16_update(pas16_t *pas16) } } -void pas16_get_buffer(int32_t *buffer, int len, void *p) +void pas16_get_buffer(int32_t *buffer, int len, priv_t priv) { - pas16_t *pas16 = (pas16_t *)p; + pas16_t *pas16 = (pas16_t *)priv; int c; opl3_update2(&pas16->opl); @@ -772,7 +731,8 @@ void pas16_get_buffer(int32_t *buffer, int len, void *p) } -static void *pas16_init(const device_t *info, UNUSED(void *parent)) +static priv_t +pas16_init(const device_t *info, UNUSED(void *parent)) { pas16_t *pas16 = (pas16_t *)mem_alloc(sizeof(pas16_t)); memset(pas16, 0, sizeof(pas16_t)); @@ -781,19 +741,19 @@ static void *pas16_init(const device_t *info, UNUSED(void *parent)) sb_dsp_init(&pas16->dsp, SB2); io_sethandler(0x9a01, 0x0001, NULL, NULL, NULL, pas16_out_base, NULL, NULL, pas16); - + timer_add(pas16_pcm_poll, pas16, &pas16->pit.c[0], &pas16->pit.enable[0]); - + sound_add_handler(pas16_get_buffer, pas16); - - return pas16; + + return (priv_t)pas16; } -static void pas16_close(void *p) +static void pas16_close(priv_t priv) { - pas16_t *pas16 = (pas16_t *)p; - + pas16_t *pas16 = (pas16_t *)priv; + free(pas16); } diff --git a/src/devices/sound/snd_sb.c b/src/devices/sound/snd_sb.c index 06ca65e..cad495b 100644 --- a/src/devices/sound/snd_sb.c +++ b/src/devices/sound/snd_sb.c @@ -8,7 +8,7 @@ * * Sound Blaster emulation. * - * Version: @(#)snd_sb.c 1.0.12 2019/04/27 + * Version: @(#)snd_sb.c 1.0.13 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -197,9 +197,9 @@ const int32_t sb_att_7dbstep_2bits[]= /* sb 1, 1.5, 2, 2 mvc do not have a mixer, so signal is hardwired */ -static void sb_get_buffer_sb2(int32_t *buffer, int len, void *p) +static void sb_get_buffer_sb2(int32_t *buffer, int len, priv_t priv) { - sb_t *sb = (sb_t *)p; + sb_t *sb = (sb_t *)priv; int c; @@ -223,9 +223,9 @@ static void sb_get_buffer_sb2(int32_t *buffer, int len, void *p) sb->dsp.pos = 0; } -static void sb_get_buffer_sb2_mixer(int32_t *buffer, int len, void *p) +static void sb_get_buffer_sb2_mixer(int32_t *buffer, int len, priv_t priv) { - sb_t *sb = (sb_t *)p; + sb_t *sb = (sb_t *)priv; sb_ct1335_mixer_t *mixer = &sb->mixer_sb2; int c; @@ -254,9 +254,9 @@ static void sb_get_buffer_sb2_mixer(int32_t *buffer, int len, void *p) sb->dsp.pos = 0; } -static void sb_get_buffer_sbpro(int32_t *buffer, int len, void *p) +static void sb_get_buffer_sbpro(int32_t *buffer, int len, priv_t priv) { - sb_t *sb = (sb_t *)p; + sb_t *sb = (sb_t *)priv; sb_ct1345_mixer_t *mixer = &sb->mixer_sbpro; int c; @@ -303,9 +303,9 @@ static void sb_get_buffer_sbpro(int32_t *buffer, int len, void *p) sb->dsp.pos = 0; } -static void sb_get_buffer_sb16(int32_t *buffer, int len, void *p) +static void sb_get_buffer_sb16(int32_t *buffer, int len, priv_t priv) { - sb_t *sb = (sb_t *)p; + sb_t *sb = (sb_t *)priv; sb_ct1745_mixer_t *mixer = &sb->mixer_sb16; int c; @@ -384,9 +384,9 @@ int last_crecord=0; #endif -static void sb_get_buffer_emu8k(int32_t *buffer, int len, void *p) +static void sb_get_buffer_emu8k(int32_t *buffer, int len, priv_t priv) { - sb_t *sb = (sb_t *)p; + sb_t *sb = (sb_t *)priv; sb_ct1745_mixer_t *mixer = &sb->mixer_sb16; int c; @@ -491,9 +491,9 @@ static void sb_get_buffer_emu8k(int32_t *buffer, int len, void *p) } -void sb_ct1335_mixer_write(uint16_t addr, uint8_t val, void *p) +void sb_ct1335_mixer_write(uint16_t addr, uint8_t val, priv_t priv) { - sb_t *sb = (sb_t *)p; + sb_t *sb = (sb_t *)priv; sb_ct1335_mixer_t *mixer = &sb->mixer_sb2; if (!(addr & 1)) @@ -535,9 +535,9 @@ void sb_ct1335_mixer_write(uint16_t addr, uint8_t val, void *p) } } -uint8_t sb_ct1335_mixer_read(uint16_t addr, void *p) +uint8_t sb_ct1335_mixer_read(uint16_t addr, priv_t priv) { - sb_t *sb = (sb_t *)p; + sb_t *sb = (sb_t *)priv; sb_ct1335_mixer_t *mixer = &sb->mixer_sb2; if (!(addr & 1)) @@ -561,9 +561,9 @@ void sb_ct1335_mixer_reset(sb_t* sb) sb_ct1335_mixer_write(0x255,0,sb); } -void sb_ct1345_mixer_write(uint16_t addr, uint8_t val, void *p) +void sb_ct1345_mixer_write(uint16_t addr, uint8_t val, priv_t priv) { - sb_t *sb = (sb_t *)p; + sb_t *sb = (sb_t *)priv; sb_ct1345_mixer_t *mixer = &sb->mixer_sbpro; if (!(addr & 1)) @@ -656,9 +656,9 @@ void sb_ct1345_mixer_write(uint16_t addr, uint8_t val, void *p) } } -uint8_t sb_ct1345_mixer_read(uint16_t addr, void *p) +uint8_t sb_ct1345_mixer_read(uint16_t addr, priv_t priv) { - sb_t *sb = (sb_t *)p; + sb_t *sb = (sb_t *)priv; sb_ct1345_mixer_t *mixer = &sb->mixer_sbpro; if (!(addr & 1)) @@ -684,9 +684,9 @@ void sb_ct1345_mixer_reset(sb_t* sb) sb_ct1345_mixer_write(5,0,sb); } -void sb_ct1745_mixer_write(uint16_t addr, uint8_t val, void *p) +void sb_ct1745_mixer_write(uint16_t addr, uint8_t val, priv_t priv) { - sb_t *sb = (sb_t *)p; + sb_t *sb = (sb_t *)priv; sb_ct1745_mixer_t *mixer = &sb->mixer_sb16; if (!(addr & 1)) @@ -823,9 +823,9 @@ void sb_ct1745_mixer_write(uint16_t addr, uint8_t val, void *p) } } -uint8_t sb_ct1745_mixer_read(uint16_t addr, void *p) +uint8_t sb_ct1745_mixer_read(uint16_t addr, priv_t priv) { - sb_t *sb = (sb_t *)p; + sb_t *sb = (sb_t *)priv; sb_ct1745_mixer_t *mixer = &sb->mixer_sb16; uint8_t temp; @@ -933,19 +933,19 @@ void sb_ct1745_mixer_reset(sb_t* sb) static uint16_t sb_mcv_addr[8] = {0x200, 0x210, 0x220, 0x230, 0x240, 0x250, 0x260, 0x270}; -uint8_t sb_mcv_read(int port, void *p) +uint8_t sb_mcv_read(int port, priv_t priv) { - sb_t *sb = (sb_t *)p; + sb_t *sb = (sb_t *)priv; DEBUG("sb_mcv_read: port=%04x\n", port); return sb->pos_regs[port & 7]; } -void sb_mcv_write(int port, uint8_t val, void *p) +void sb_mcv_write(int port, uint8_t val, priv_t priv) { uint16_t addr; - sb_t *sb = (sb_t *)p; + sb_t *sb = (sb_t *)priv; if (port < 0x102) return; @@ -977,19 +977,19 @@ void sb_mcv_write(int port, uint8_t val, void *p) static int sb_pro_mcv_irqs[4] = {7, 5, 3, 3}; -uint8_t sb_pro_mcv_read(int port, void *p) +uint8_t sb_pro_mcv_read(int port, priv_t priv) { - sb_t *sb = (sb_t *)p; + sb_t *sb = (sb_t *)priv; DEBUG("sb_pro_mcv_read: port=%04x\n", port); return sb->pos_regs[port & 7]; } -void sb_pro_mcv_write(int port, uint8_t val, void *p) +void sb_pro_mcv_write(int port, uint8_t val, priv_t priv) { uint16_t addr; - sb_t *sb = (sb_t *)p; + sb_t *sb = (sb_t *)priv; if (port < 0x102) return; @@ -1021,7 +1021,8 @@ void sb_pro_mcv_write(int port, uint8_t val, void *p) sb_dsp_setdma8(&sb->dsp, sb->pos_regs[4] & 3); } -void *sb_1_init(const device_t *info, UNUSED(void *parent)) +priv_t +sb_1_init(const device_t *info, UNUSED(void *parent)) { /*sb1/2 port mappings, 210h to 260h in 10h steps 2x0 to 2x3 -> CMS chip @@ -1044,10 +1045,11 @@ void *sb_1_init(const device_t *info, UNUSED(void *parent)) io_sethandler(addr+8, 0x0002, opl2_read, NULL, NULL, opl2_write, NULL, NULL, &sb->opl); io_sethandler(0x0388, 0x0002, opl2_read, NULL, NULL, opl2_write, NULL, NULL, &sb->opl); } - sound_add_handler(sb_get_buffer_sb2, sb); - return sb; + sound_add_handler(sb_get_buffer_sb2, (priv_t)sb); + return (priv_t)sb; } -void *sb_15_init(const device_t *info, UNUSED(void *parent)) +priv_t +sb_15_init(const device_t *info, UNUSED(void *parent)) { /*sb1/2 port mappings, 210h to 260h in 10h steps 2x0 to 2x3 -> CMS chip @@ -1070,11 +1072,12 @@ void *sb_15_init(const device_t *info, UNUSED(void *parent)) io_sethandler(addr+8, 0x0002, opl2_read, NULL, NULL, opl2_write, NULL, NULL, &sb->opl); io_sethandler(0x0388, 0x0002, opl2_read, NULL, NULL, opl2_write, NULL, NULL, &sb->opl); } - sound_add_handler(sb_get_buffer_sb2, sb); - return sb; + sound_add_handler(sb_get_buffer_sb2, (priv_t)sb); + return (priv_t)sb; } -void *sb_mcv_init(const device_t *info, UNUSED(void *parent)) +priv_t +sb_mcv_init(const device_t *info, UNUSED(void *parent)) { /*sb1/2 port mappings, 210h to 260h in 10h steps 2x6, 2xA, 2xC, 2xE -> DSP chip @@ -1089,14 +1092,15 @@ void *sb_mcv_init(const device_t *info, UNUSED(void *parent)) sb_dsp_setaddr(&sb->dsp, 0);//addr); sb_dsp_setirq(&sb->dsp, device_get_config_int("irq")); sb_dsp_setdma8(&sb->dsp, device_get_config_int("dma")); - sound_add_handler(sb_get_buffer_sb2, sb); + sound_add_handler(sb_get_buffer_sb2, (priv_t)sb); /* I/O handlers activated in sb_mcv_write */ - mca_add(sb_mcv_read, sb_mcv_write, sb); + mca_add(sb_mcv_read, sb_mcv_write, (priv_t)sb); sb->pos_regs[0] = 0x84; sb->pos_regs[1] = 0x50; - return sb; + return (priv_t)sb; } -void *sb_2_init(const device_t *info, UNUSED(void *parent)) +priv_t +sb_2_init(const device_t *info, UNUSED(void *parent)) { /*sb2 port mappings. 220h or 240h. 2x0 to 2x3 -> CMS chip @@ -1138,15 +1142,16 @@ void *sb_2_init(const device_t *info, UNUSED(void *parent)) if (mixer_addr > 0) { io_sethandler(mixer_addr+4, 0x0002, sb_ct1335_mixer_read, NULL, NULL, sb_ct1335_mixer_write, NULL, NULL, sb); - sound_add_handler(sb_get_buffer_sb2_mixer, sb); + sound_add_handler(sb_get_buffer_sb2_mixer, (priv_t)sb); } else - sound_add_handler(sb_get_buffer_sb2, sb); + sound_add_handler(sb_get_buffer_sb2, (priv_t)sb); - return sb; + return (priv_t)sb; } -void *sb_pro_v1_init(const device_t *info, UNUSED(void *parent)) +priv_t +sb_pro_v1_init(const device_t *info, UNUSED(void *parent)) { /*sbpro port mappings. 220h or 240h. 2x0 to 2x3 -> FM chip, Left and Right (9*2 voices) @@ -1174,12 +1179,13 @@ void *sb_pro_v1_init(const device_t *info, UNUSED(void *parent)) io_sethandler(0x0388, 0x0002, opl2_read, NULL, NULL, opl2_write, NULL, NULL, &sb->opl); } io_sethandler(addr+4, 0x0002, sb_ct1345_mixer_read, NULL, NULL, sb_ct1345_mixer_write, NULL, NULL, sb); - sound_add_handler(sb_get_buffer_sbpro, sb); + sound_add_handler(sb_get_buffer_sbpro, (priv_t)sb); - return sb; + return (priv_t)sb; } -void *sb_pro_v2_init(const device_t *info, UNUSED(void *parent)) +priv_t +sb_pro_v2_init(const device_t *info, UNUSED(void *parent)) { /*sbpro port mappings. 220h or 240h. 2x0 to 2x3 -> FM chip (18 voices) @@ -1206,12 +1212,13 @@ void *sb_pro_v2_init(const device_t *info, UNUSED(void *parent)) io_sethandler(0x0388, 0x0004, opl3_read, NULL, NULL, opl3_write, NULL, NULL, &sb->opl); } io_sethandler(addr+4, 0x0002, sb_ct1345_mixer_read, NULL, NULL, sb_ct1345_mixer_write, NULL, NULL, sb); - sound_add_handler(sb_get_buffer_sbpro, sb); + sound_add_handler(sb_get_buffer_sbpro, (priv_t)sb); - return sb; + return (priv_t)sb; } -void *sb_pro_mcv_init(const device_t *info, UNUSED(void *parent)) +priv_t +sb_pro_mcv_init(const device_t *info, UNUSED(void *parent)) { /*sbpro port mappings. 220h or 240h. 2x0 to 2x3 -> FM chip, Left and Right (18 voices) @@ -1226,17 +1233,18 @@ void *sb_pro_mcv_init(const device_t *info, UNUSED(void *parent)) sb_dsp_init(&sb->dsp, SBPRO2); sb_ct1345_mixer_reset(sb); /* I/O handlers activated in sb_mcv_write */ - sound_add_handler(sb_get_buffer_sbpro, sb); + sound_add_handler(sb_get_buffer_sbpro, (priv_t)sb); /* I/O handlers activated in sb_pro_mcv_write */ - mca_add(sb_pro_mcv_read, sb_pro_mcv_write, sb); + mca_add(sb_pro_mcv_read, sb_pro_mcv_write, (priv_t)sb); sb->pos_regs[0] = 0x03; sb->pos_regs[1] = 0x51; - return sb; + return (priv_t)sb; } -void *sb_16_init(const device_t *info, UNUSED(void *parent)) +priv_t +sb_16_init(const device_t *info, UNUSED(void *parent)) { sb_t *sb = (sb_t *)mem_alloc(sizeof(sb_t)); uint16_t addr = device_get_config_hex16("base"); @@ -1258,7 +1266,7 @@ void *sb_16_init(const device_t *info, UNUSED(void *parent)) io_sethandler(0x0388, 0x0004, opl3_read, NULL, NULL, opl3_write, NULL, NULL, &sb->opl); } io_sethandler(addr+4, 0x0002, sb_ct1745_mixer_read, NULL, NULL, sb_ct1745_mixer_write, NULL, NULL, sb); - sound_add_handler(sb_get_buffer_sb16, sb); + sound_add_handler(sb_get_buffer_sb16, (priv_t)sb); if (mpu_addr) { sb->mpu = (mpu_t *)mem_alloc(sizeof(mpu_t)); memset(sb->mpu, 0, sizeof(mpu_t)); @@ -1267,10 +1275,11 @@ void *sb_16_init(const device_t *info, UNUSED(void *parent)) } else sb->mpu = NULL; - return sb; + return (priv_t)sb; } -void *sb_awe32_init(const device_t *info, UNUSED(void *parent)) +priv_t +sb_awe32_init(const device_t *info, UNUSED(void *parent)) { sb_t *sb = (sb_t *)mem_alloc(sizeof(sb_t)); uint16_t addr = device_get_config_hex16("base"); @@ -1279,7 +1288,6 @@ void *sb_awe32_init(const device_t *info, UNUSED(void *parent)) int onboard_ram = device_get_config_int("onboard_ram"); memset(sb, 0, sizeof(sb_t)); - sb->opl_enabled = device_get_config_int("opl"); if (sb->opl_enabled) opl3_init(&sb->opl); @@ -1296,7 +1304,7 @@ void *sb_awe32_init(const device_t *info, UNUSED(void *parent)) io_sethandler(0x0388, 0x0004, opl3_read, NULL, NULL, opl3_write, NULL, NULL, &sb->opl); } io_sethandler(addr+4, 0x0002, sb_ct1745_mixer_read, NULL, NULL, sb_ct1745_mixer_write, NULL, NULL, sb); - sound_add_handler(sb_get_buffer_emu8k, sb); + sound_add_handler(sb_get_buffer_emu8k, (priv_t)sb); if (mpu_addr) { sb->mpu = (mpu_t *)mem_alloc(sizeof(mpu_t)); memset(sb->mpu, 0, sizeof(mpu_t)); @@ -1306,12 +1314,12 @@ void *sb_awe32_init(const device_t *info, UNUSED(void *parent)) sb->mpu = NULL; emu8k_init(&sb->emu8k, ROM_PATH_AWE32, emu_addr, onboard_ram); - return sb; + return (priv_t)sb; } -void sb_close(void *p) +void sb_close(priv_t priv) { - sb_t *sb = (sb_t *)p; + sb_t *sb = (sb_t *)priv; sb_dsp_close(&sb->dsp); #ifdef SB_DSP_RECORD_DEBUG if (soundfsb != 0) @@ -1329,18 +1337,18 @@ void sb_close(void *p) free(sb); } -void sb_awe32_close(void *p) +void sb_awe32_close(priv_t priv) { - sb_t *sb = (sb_t *)p; + sb_t *sb = (sb_t *)priv; emu8k_close(&sb->emu8k); sb_close(sb); } -void sb_speed_changed(void *p) +void sb_speed_changed(priv_t priv) { - sb_t *sb = (sb_t *)p; + sb_t *sb = (sb_t *)priv; sb_dsp_speed_changed(&sb->dsp); } diff --git a/src/devices/sound/snd_sb_dsp.c b/src/devices/sound/snd_sb_dsp.c index aab120e..26076d7 100644 --- a/src/devices/sound/snd_sb_dsp.c +++ b/src/devices/sound/snd_sb_dsp.c @@ -14,7 +14,7 @@ * 486-50 - 32kHz * Pentium - 45kHz * - * Version: @(#)snd_sb_dsp.c 1.0.9 2019/04/25 + * Version: @(#)snd_sb_dsp.c 1.0.10 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -67,8 +67,8 @@ #define SB_DSP_REC_SAFEFTY_MARGIN 4096 -extern void pollsb(void *p); -extern void sb_poll_i(void *p); +extern void pollsb(priv_t); +extern void sb_poll_i(priv_t); static const int sbe2dat[4][9] = { @@ -673,7 +673,7 @@ void sb_exec_command(sb_dsp_t *dsp) } } -void sb_write(uint16_t a, uint8_t v, void *priv) +void sb_write(uint16_t a, uint8_t v, priv_t priv) { sb_dsp_t *dsp = (sb_dsp_t *)priv; switch (a&0xF) @@ -723,7 +723,7 @@ void sb_write(uint16_t a, uint8_t v, void *priv) } } -uint8_t sb_read(uint16_t a, void *priv) +uint8_t sb_read(uint16_t a, priv_t priv) { sb_dsp_t *dsp = (sb_dsp_t *)priv; switch (a & 0xf) @@ -763,9 +763,9 @@ uint8_t sb_read(uint16_t a, void *priv) return 0; } -static void sb_wb_clear(void *p) +static void sb_wb_clear(priv_t priv) { - sb_dsp_t *dsp = (sb_dsp_t *)p; + sb_dsp_t *dsp = (sb_dsp_t *)priv; dsp->wb_time = 0LL; } @@ -815,9 +815,9 @@ void sb_dsp_set_stereo(sb_dsp_t *dsp, int stereo) dsp->stereo = stereo; } -void pollsb(void *p) +void pollsb(priv_t priv) { - sb_dsp_t *dsp = (sb_dsp_t *)p; + sb_dsp_t *dsp = (sb_dsp_t *)priv; int tempi,ref; dsp->sbcount += dsp->sblatcho; @@ -1049,9 +1049,9 @@ void pollsb(void *p) } } -void sb_poll_i(void *p) +void sb_poll_i(priv_t priv) { - sb_dsp_t *dsp = (sb_dsp_t *)p; + sb_dsp_t *dsp = (sb_dsp_t *)priv; int processed=0; dsp->sb_count_i += dsp->sblatchi; if (dsp->sb_8_enable && !dsp->sb_8_pause && dsp->sb_pausetime < 0 && !dsp->sb_8_output) diff --git a/src/devices/sound/snd_sn76489.c b/src/devices/sound/snd_sn76489.c index e31264c..728604d 100644 --- a/src/devices/sound/snd_sn76489.c +++ b/src/devices/sound/snd_sn76489.c @@ -8,7 +8,7 @@ * * Implementation of the TI SN74689 PSG sound devices. * - * Version: @(#)snd_sn76489.c 1.0.8 2019/04/09 + * Version: @(#)snd_sn76489.c 1.0.9 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -105,9 +105,9 @@ void sn76489_update(sn76489_t *sn76489) } } -void sn76489_get_buffer(int32_t *buffer, int len, void *p) +void sn76489_get_buffer(int32_t *buffer, int len, priv_t priv) { - sn76489_t *sn76489 = (sn76489_t *)p; + sn76489_t *sn76489 = (sn76489_t *)priv; int c; @@ -122,9 +122,9 @@ void sn76489_get_buffer(int32_t *buffer, int len, void *p) sn76489->pos = 0; } -void sn76489_write(uint16_t addr, uint8_t data, void *p) +void sn76489_write(uint16_t addr, uint8_t data, priv_t priv) { - sn76489_t *sn76489 = (sn76489_t *)p; + sn76489_t *sn76489 = (sn76489_t *)priv; int freq; sn76489_update(sn76489); @@ -245,28 +245,32 @@ void sn76489_init(sn76489_t *sn76489, uint16_t base, uint16_t size, int type, in io_sethandler(base, size, NULL, NULL, NULL, sn76489_write, NULL, NULL, sn76489); } -void *sn76489_device_init(const device_t *info, UNUSED(void *parent)) +priv_t +sn76489_device_init(const device_t *info, UNUSED(void *parent)) { sn76489_t *sn76489 = (sn76489_t *)mem_alloc(sizeof(sn76489_t)); memset(sn76489, 0, sizeof(sn76489_t)); sn76489_init(sn76489, 0x00c0, 0x0008, SN76496, 3579545); - return sn76489; + return (priv_t)sn76489; } -void *ncr8496_device_init(const device_t *info, UNUSED(void *parent)) + + +priv_t +ncr8496_device_init(const device_t *info, UNUSED(void *parent)) { sn76489_t *sn76489 = (sn76489_t *)mem_alloc(sizeof(sn76489_t)); memset(sn76489, 0, sizeof(sn76489_t)); sn76489_init(sn76489, 0x00c0, 0x0008, NCR8496, 3579545); - return sn76489; + return (priv_t)sn76489; } -void sn76489_device_close(void *p) +void sn76489_device_close(priv_t priv) { - sn76489_t *sn76489 = (sn76489_t *)p; + sn76489_t *sn76489 = (sn76489_t *)priv; free(sn76489); } diff --git a/src/devices/sound/snd_ssi2001.c b/src/devices/sound/snd_ssi2001.c index f6c2f82..9aa7ffa 100644 --- a/src/devices/sound/snd_ssi2001.c +++ b/src/devices/sound/snd_ssi2001.c @@ -8,7 +8,7 @@ * * Implementation of the SSI2001 sound device. * - * Version: @(#)snd_ssi2001.c 1.0.9 2019/04/11 + * Version: @(#)snd_ssi2001.c 1.0.10 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -54,7 +54,7 @@ typedef struct { uint16_t base; int16_t game; - void *psid; + priv_t psid; int pos; int16_t buffer[SOUNDBUFLEN * 2]; @@ -73,7 +73,7 @@ ssi_update(ssi2001_t *dev) static void -get_buffer(int32_t *buffer, int len, void *priv) +get_buffer(int32_t *buffer, int len, priv_t priv) { ssi2001_t *dev = (ssi2001_t *)priv; int c; @@ -88,28 +88,44 @@ get_buffer(int32_t *buffer, int len, void *priv) static uint8_t -ssi_read(uint16_t addr, void *priv) +ssi_read(uint16_t addr, priv_t priv) { ssi2001_t *dev = (ssi2001_t *)priv; - + ssi_update(dev); - + return(sid_read(addr, priv)); } static void -ssi_write(uint16_t addr, uint8_t val, void *priv) +ssi_write(uint16_t addr, uint8_t val, priv_t priv) { ssi2001_t *dev = (ssi2001_t *)priv; - - ssi_update(dev); + + ssi_update(dev); sid_write(addr, val, priv); } -static void * +static void +ssi_close(priv_t priv) +{ + ssi2001_t *dev = (ssi2001_t *)priv; + + /* Remove our I/O handler. */ + io_removehandler(dev->base, 32, + ssi_read,NULL,NULL, ssi_write,NULL,NULL, (priv_t)dev); + + /* Close the SID. */ + sid_close(dev->psid); + + free(dev); +} + + +static priv_t ssi_init(const device_t *info, UNUSED(void *parent)) { ssi2001_t *dev; @@ -127,27 +143,11 @@ ssi_init(const device_t *info, UNUSED(void *parent)) /* Set up our I/O handler. */ io_sethandler(dev->base, 32, - ssi_read,NULL,NULL, ssi_write,NULL,NULL, dev); + ssi_read,NULL,NULL, ssi_write,NULL,NULL, (priv_t)dev); sound_add_handler(get_buffer, dev); - return(dev); -} - - -static void -ssi_close(void *priv) -{ - ssi2001_t *dev = (ssi2001_t *)priv; - - /* Remove our I/O handler. */ - io_removehandler(dev->base, 32, - ssi_read,NULL,NULL, ssi_write,NULL,NULL, dev); - - /* Close the SID. */ - sid_close(dev->psid); - - free(dev); + return((priv_t)dev); } diff --git a/src/devices/sound/snd_wss.c b/src/devices/sound/snd_wss.c index 9f2ffa0..0d80b9c 100644 --- a/src/devices/sound/snd_wss.c +++ b/src/devices/sound/snd_wss.c @@ -8,7 +8,7 @@ * * Implementation of the Windows Sound System sound device. * - * Version: @(#)snd_wss.c 1.0.8 2019/04/09 + * Version: @(#)snd_wss.c 1.0.9 2019/05/13 * * Authors: Fred N. van Kempen, * TheCollector1995, @@ -68,7 +68,7 @@ typedef struct { uint8_t config; - ad1848_t ad1848; + ad1848_t ad1848; opl_t opl; int opl_enabled; @@ -78,7 +78,7 @@ typedef struct { static void -get_buffer(int32_t *buffer, int len, void *priv) +get_buffer(int32_t *buffer, int len, priv_t priv) { wss_t *dev = (wss_t *)priv; int c; @@ -98,7 +98,7 @@ get_buffer(int32_t *buffer, int len, void *priv) static uint8_t -wss_read(uint16_t addr, void *priv) +wss_read(uint16_t addr, priv_t priv) { wss_t *dev = (wss_t *)priv; uint8_t ret; @@ -110,7 +110,7 @@ wss_read(uint16_t addr, void *priv) static void -wss_write(uint16_t addr, uint8_t val, void *priv) +wss_write(uint16_t addr, uint8_t val, priv_t priv) { wss_t *dev = (wss_t *)priv; @@ -122,7 +122,7 @@ wss_write(uint16_t addr, uint8_t val, void *priv) static uint8_t -ncr_audio_mca_read(int port, void *priv) +ncr_audio_mca_read(int port, priv_t priv) { wss_t *dev = (wss_t *)priv; @@ -131,7 +131,7 @@ ncr_audio_mca_read(int port, void *priv) static void -ncr_audio_mca_write(int port, uint8_t val, void *priv) +ncr_audio_mca_write(int port, uint8_t val, priv_t priv) { wss_t *dev = (wss_t *)priv; uint16_t ports[] = { 0x0530, 0x0E80, 0x0F40, 0x0604 }; @@ -148,7 +148,7 @@ ncr_audio_mca_write(int port, uint8_t val, void *priv) wss_read,NULL,NULL, wss_write,NULL,NULL, dev); io_removehandler(addr+4, 4, ad1848_read,NULL,NULL, ad1848_write,NULL,NULL, &dev->ad1848); - INFO("%s: OPL=%d, I/O=%04XH\n", dev->name, dev->opl_enabled, addr); + INFO("%s: OPL=%i, I/O=%04XH\n", dev->name, dev->opl_enabled, addr); dev->pos_regs[port & 7] = val; if (dev->pos_regs[2] & 1) { @@ -165,7 +165,25 @@ ncr_audio_mca_write(int port, uint8_t val, void *priv) } -static void * +static void +wss_close(priv_t priv) +{ + wss_t *dev = (wss_t *)priv; + + free(dev); +} + + +static void +speed_changed(priv_t priv) +{ + wss_t *dev = (wss_t *)priv; + + ad1848_speed_changed(&dev->ad1848); +} + + +static priv_t wss_init(const device_t *info, UNUSED(void *parent)) { wss_t *dev; @@ -182,7 +200,7 @@ wss_init(const device_t *info, UNUSED(void *parent)) case 1: /* NCR Business Audio MCA */ dev->pos_regs[0] = 0x16; dev->pos_regs[1] = 0x51; - mca_add(ncr_audio_mca_read, ncr_audio_mca_write, dev); + mca_add(ncr_audio_mca_read, ncr_audio_mca_write, (priv_t)dev); break; } @@ -199,27 +217,9 @@ wss_init(const device_t *info, UNUSED(void *parent)) io_sethandler(0x0534, 4, ad1848_read,NULL,NULL, ad1848_write,NULL,NULL, &dev->ad1848); - sound_add_handler(get_buffer, dev); + sound_add_handler(get_buffer, (priv_t)dev); - return(dev); -} - - -static void -wss_close(void *priv) -{ - wss_t *dev = (wss_t *)priv; - - free(dev); -} - - -static void -wss_speed_changed(void *priv) -{ - wss_t *dev = (wss_t *)priv; - - ad1848_speed_changed(&dev->ad1848); + return((priv_t)dev); } @@ -230,7 +230,7 @@ const device_t wss_device = { NULL, wss_init, wss_close, NULL, NULL, - wss_speed_changed, + speed_changed, NULL, NULL, NULL }; @@ -242,7 +242,7 @@ const device_t ncr_business_audio_device = { NULL, wss_init, wss_close, NULL, NULL, - wss_speed_changed, + speed_changed, NULL, NULL, NULL }; diff --git a/src/devices/system/dma.c b/src/devices/system/dma.c index 29eefec..5a0f6a1 100644 --- a/src/devices/system/dma.c +++ b/src/devices/system/dma.c @@ -8,7 +8,7 @@ * * Implementation of the Intel DMA controllers. * - * Version: @(#)dma.c 1.0.10 2019/04/11 + * Version: @(#)dma.c 1.0.11 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -189,7 +189,7 @@ dma_ps2_run(int channel) static uint8_t -dma_ps2_read(uint16_t addr, UNUSED(void *priv)) +dma_ps2_read(uint16_t addr, UNUSED(priv_t priv)) { dma_t *dma_c = &dma[dma_ps2.xfr_channel]; uint8_t temp = 0xff; @@ -256,7 +256,7 @@ dma_ps2_read(uint16_t addr, UNUSED(void *priv)) static void -dma_ps2_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) +dma_ps2_write(uint16_t addr, uint8_t val, UNUSED(priv_t priv)) { dma_t *dma_c = &dma[dma_ps2.xfr_channel]; uint8_t mode; @@ -347,7 +347,7 @@ dma_ps2_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) static uint8_t -dma_read(uint16_t addr, UNUSED(void *priv)) +dma_read(uint16_t addr, UNUSED(priv_t priv)) { int channel = (addr >> 1) & 3; uint8_t temp; @@ -387,7 +387,7 @@ dma_read(uint16_t addr, UNUSED(void *priv)) static void -dma_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) +dma_write(uint16_t addr, uint8_t val, UNUSED(priv_t priv)) { int channel = (addr >> 1) & 3; @@ -459,7 +459,7 @@ dma_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) static uint8_t -dma16_read(uint16_t addr, UNUSED(void *priv)) +dma16_read(uint16_t addr, UNUSED(priv_t priv)) { int channel = ((addr >> 2) & 3) + 4; uint8_t temp; @@ -502,7 +502,7 @@ dma16_read(uint16_t addr, UNUSED(void *priv)) static void -dma16_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) +dma16_write(uint16_t addr, uint8_t val, UNUSED(priv_t priv)) { int channel = ((addr >> 2) & 3) + 4; addr >>= 1; @@ -581,14 +581,14 @@ dma16_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) static uint8_t -dma_page_read(uint16_t addr, UNUSED(void *priv)) +dma_page_read(uint16_t addr, UNUSED(priv_t priv)) { return(dmapages[addr & 0xf]); } static void -dma_page_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) +dma_page_write(uint16_t addr, uint8_t val, UNUSED(priv_t priv)) { dmapages[addr & 0xf] = val; diff --git a/src/devices/system/i82335.c b/src/devices/system/i82335.c index 50a9a30..77dabd2 100644 --- a/src/devices/system/i82335.c +++ b/src/devices/system/i82335.c @@ -8,13 +8,13 @@ * * Intel 82335 SX emulation, used by the Phoenix 386 clone. * - * Version: @(#)i82335.c 1.0.5 2018/10/07 + * Version: @(#)i82335.c 1.0.6 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, * Sarah Walker, * - * Copyright 2017,2018 Fred N. van Kempen. + * Copyright 2017-2019 Fred N. van Kempen. * Copyright 2016-2018 Miran Grca. * Copyright 2008-2018 Sarah Walker. * @@ -52,26 +52,26 @@ typedef struct { } i82335_t; -static i82335_t i82335; - - static uint8_t -i82335_read(uint16_t addr, UNUSED(void *priv)) +i82335_read(uint16_t addr, priv_t priv) { + i82335_t *dev = (i82335_t *)priv; + DBGLOG(1, "i82335_read(%04X)\n", addr); if (addr == 0x22) - return(i82335.reg_22); + return(dev->reg_22); if (addr == 0x23) - return(i82335.reg_23); + return(dev->reg_23); return(0); } static void -i82335_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) +i82335_write(uint16_t addr, uint8_t val, priv_t priv) { + i82335_t *dev = (i82335_t *)priv; int mem_write = 0; int i = 0; @@ -79,7 +79,7 @@ i82335_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) switch (addr) { case 0x22: - if ((val ^ i82335.reg_22) & 1) { + if ((val ^ dev->reg_22) & 1) { if (val & 1) { for (i = 0; i < 8; i++) mem_set_mem_state(0xe0000, 0x20000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); @@ -93,13 +93,13 @@ i82335_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) flushmmucache(); } - i82335.reg_22 = val | 0xd8; + dev->reg_22 = val | 0xd8; break; case 0x23: - i82335.reg_23 = val; + dev->reg_23 = val; - if ((val ^ i82335.reg_22) & 2) { + if ((val ^ dev->reg_22) & 2) { if (val & 2) { for (i = 0; i < 8; i++) mem_set_mem_state(0xc0000, 0x20000, MEM_READ_INTERNAL | MEM_WRITE_INTERNAL); @@ -111,7 +111,7 @@ i82335_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) } } - if ((val ^ i82335.reg_22) & 0xc) { + if ((val ^ dev->reg_22) & 0xc) { if (val & 2) { for (i = 0; i < 8; i++) { mem_write = (val & 8) ? MEM_WRITE_DISABLED : MEM_WRITE_INTERNAL; @@ -127,26 +127,51 @@ i82335_write(uint16_t addr, uint8_t val, UNUSED(void *priv)) } } - if ((val ^ i82335.reg_22) & 0xe) + if ((val ^ dev->reg_22) & 0xe) flushmmucache(); if (val & 0x80) { io_removehandler(0x0022, 1, i82335_read,NULL,NULL, - i82335_write,NULL,NULL, NULL); + i82335_write,NULL,NULL, dev); } break; } } -void -i82335_init(void) +static void +i82335_close(priv_t priv) { - memset(&i82335, 0x00, sizeof(i82335_t)); + i82335_t *dev = (i82335_t *)priv; - i82335.reg_22 = 0xd8; + free(dev); +} + + +static priv_t +i82335_init(const device_t *info, UNUSED(void *parent)) +{ + i82335_t *dev; + + dev = (i82335_t *)mem_alloc(sizeof(i82335_t)); + memset(dev, 0x00, sizeof(i82335_t)); + + dev->reg_22 = 0xd8; io_sethandler(0x0022, 20, - i82335_read,NULL,NULL, i82335_write,NULL,NULL, NULL); + i82335_read,NULL,NULL, i82335_write,NULL,NULL, dev); + + return((priv_t)dev); } + + +const device_t i82335sx_device = { + "Intel 82335SX", + 0, + 0, + NULL, + sx_init, sx_close, NULL, + NULL, NULL, NULL, NULL, + NULL +}; diff --git a/src/devices/system/i82335.h b/src/devices/system/i82335.h index e8246a1..fc3980a 100644 --- a/src/devices/system/i82335.h +++ b/src/devices/system/i82335.h @@ -6,15 +6,15 @@ * * This file is part of the VARCem Project. * - * Definitions for Intel 82335 SX emulation. + * Definitions for Intel 82335SX emulation. * - * Version: @(#)i82335.h 1.0.1 2018/02/14 + * Version: @(#)i82335.h 1.0.2 2019/05/34 * * Authors: Fred N. van Kempen, * Miran Grca, * Sarah Walker, * - * Copyright 2017,2018 Fred N. van Kempen. + * Copyright 2017-2019 Fred N. van Kempen. * Copyright 2016-2018 Miran Grca. * Copyright 2008-2018 Sarah Walker. * @@ -40,7 +40,7 @@ # define EMU_I82335_H -extern void i82335_init(void); +extern const device_t i82335_device; #endif /*EMU_I82335*/ diff --git a/src/devices/system/intel.c b/src/devices/system/intel.c index 18dc0f1..9fd5769 100644 --- a/src/devices/system/intel.c +++ b/src/devices/system/intel.c @@ -8,7 +8,7 @@ * * Implementation of Intel mainboards. * - * Version: @(#)intel.c 1.0.11 2019/05/05 + * Version: @(#)intel.c 1.0.12 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -59,8 +59,9 @@ typedef struct { static uint8_t -config_read(uint16_t port, void *priv) +config_read(uint16_t port, priv_t priv) { +// batman_t *dev = (batman_t *)priv; uint8_t ret = 0x00; switch (port & 0x000f) { @@ -73,12 +74,12 @@ config_read(uint16_t port, void *priv) break; } - return ret; + return(ret); } static void -timer_over(void *priv) +timer_over(priv_t priv) { batman_t *dev = (batman_t *)priv; @@ -87,7 +88,7 @@ timer_over(void *priv) static void -timer_write(uint16_t addr, uint8_t val, void *priv) +timer_write(uint16_t addr, uint8_t val, priv_t priv) { batman_t *dev = (batman_t *)priv; @@ -101,7 +102,7 @@ timer_write(uint16_t addr, uint8_t val, void *priv) static uint8_t -timer_read(uint16_t addr, void *priv) +timer_read(uint16_t addr, priv_t priv) { batman_t *dev = (batman_t *)priv; uint16_t latch; @@ -121,36 +122,38 @@ timer_read(uint16_t addr, void *priv) else ret = latch & 0xff; - return ret; + return(ret); } static void -batman_close(void *priv) +batman_close(priv_t priv) { - batman_t *dev = (batman_t *) priv; + batman_t *dev = (batman_t *)priv; free(dev); } -static void * +static priv_t batman_init(const device_t *info, UNUSED(void *parent)) { - batman_t *dev = (batman_t *)mem_alloc(sizeof(batman_t)); + batman_t *dev; + + dev = (batman_t *)mem_alloc(sizeof(batman_t)); memset(dev, 0x00, sizeof(batman_t)); - io_sethandler(0x0073, 0x0001, + io_sethandler(0x0073, 1, config_read,NULL,NULL, NULL,NULL,NULL, dev); - io_sethandler(0x0075, 0x0001, + io_sethandler(0x0075, 1, config_read,NULL,NULL, NULL,NULL,NULL, dev); - io_sethandler(0x0078, 0x0002, + io_sethandler(0x0078, 2, timer_read,NULL,NULL, timer_write,NULL,NULL, dev); timer_add(timer_over, dev, &dev->timer, &dev->timer); - return(dev); + return((priv_t)dev); } diff --git a/src/devices/system/intel_flash.c b/src/devices/system/intel_flash.c index bf33497..ea18f0d 100644 --- a/src/devices/system/intel_flash.c +++ b/src/devices/system/intel_flash.c @@ -6,9 +6,9 @@ * * This file is part of the VARCem Project. * - * Implementation of the Intel 2 Mbit 8-bit flash devices. + * Implementation of Intel 28F001BX (2Mbit,8-bit) flash devices. * - * Version: @(#)intel_flash.c 1.0.12 2019/04/11 + * Version: @(#)intel_flash.c 1.0.13 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -58,286 +58,323 @@ #define BLOCK_DATA2 2 #define BLOCK_BOOT 3 -enum -{ - CMD_READ_ARRAY = 0xff, - CMD_IID = 0x90, - CMD_READ_STATUS = 0x70, - CMD_CLEAR_STATUS = 0x50, - CMD_ERASE_SETUP = 0x20, - CMD_ERASE_CONFIRM = 0xd0, - CMD_ERASE_SUSPEND = 0xb0, - CMD_PROGRAM_SETUP = 0x40, - CMD_PROGRAM_SETUP_ALT = 0x10 + +enum { + CMD_READ_ARRAY = 0xff, + CMD_IID = 0x90, + CMD_READ_STATUS = 0x70, + CMD_CLEAR_STATUS = 0x50, + CMD_ERASE_SETUP = 0x20, + CMD_ERASE_CONFIRM = 0xd0, + CMD_ERASE_SUSPEND = 0xb0, + CMD_PROGRAM_SETUP = 0x40, + CMD_PROGRAM_SETUP_ALT = 0x10 }; -typedef struct flash_t -{ - uint8_t command, status; - uint8_t flash_id; - int invert_high_pin; - mem_map_t mapping[8], mapping_h[8]; - uint32_t block_start[4], block_end[4], block_len[4]; - uint8_t array[131072]; + +typedef struct { + uint8_t id; + int8_t invert_high_pin; + + uint8_t command, + status; + + mem_map_t mapping[8], + mapping_h[8]; + + uint32_t block_start[4], + block_end[4], + block_len[4]; + + wchar_t path[1024]; + + uint8_t array[131072]; } flash_t; -static wchar_t flash_path[1024]; -static uint8_t flash_read(uint32_t addr, void *p) +static uint8_t +flash_read(uint32_t addr, priv_t priv) { - flash_t *flash = (flash_t *)p; - if (flash->invert_high_pin) - addr ^= 0x10000; - addr &= 0x1ffff; - switch (flash->command) { - case CMD_READ_ARRAY: - default: - return flash->array[addr]; + flash_t *dev = (flash_t *)priv; + uint8_t ret = 0xff; - case CMD_IID: + if (dev->invert_high_pin) + addr ^= 0x10000; + addr &= 0x1ffff; + + switch (dev->command) { + case CMD_IID: if (addr & 1) - return flash->flash_id; - return 0x89; + ret = dev->id; + else + ret = 0x89; + break; - case CMD_READ_STATUS: - return flash->status; - } + case CMD_READ_STATUS: + ret = dev->status; + break; + + case CMD_READ_ARRAY: + /*FALLTHROUGH*/ + + default: + ret = dev->array[addr]; + break; + } + + return(ret); } -static uint16_t flash_readw(uint32_t addr, void *p) + +static uint16_t +flash_readw(uint32_t addr, priv_t priv) { - flash_t *flash = (flash_t *)p; - uint16_t *q; - addr &= 0x1ffff; - if (flash->invert_high_pin) addr ^= 0x10000; - q = (uint16_t *)&(flash->array[addr]); - return *q; + flash_t *dev = (flash_t *)priv; + uint16_t *q; + + addr &= 0x1ffff; + if (dev->invert_high_pin) + addr ^= 0x10000; + + q = (uint16_t *)&dev->array[addr]; + + return(*q); } -static uint32_t flash_readl(uint32_t addr, void *p) + +static uint32_t +flash_readl(uint32_t addr, priv_t priv) { - flash_t *flash = (flash_t *)p; - uint32_t *q; - addr &= 0x1ffff; - if (flash->invert_high_pin) addr ^= 0x10000; - q = (uint32_t *)&(flash->array[addr]); - return *q; + flash_t *dev = (flash_t *)priv; + uint32_t *q; + + addr &= 0x1ffff; + if (dev->invert_high_pin) + addr ^= 0x10000; + + q = (uint32_t *)&dev->array[addr]; + + return(*q); } -static void flash_write(uint32_t addr, uint8_t val, void *p) + +static void +flash_write(uint32_t addr, uint8_t val, priv_t priv) { - flash_t *flash = (flash_t *)p; - int i; + flash_t *dev = (flash_t *)priv; + int i; - if (flash->invert_high_pin) - addr ^= 0x10000; - addr &= 0x1ffff; + if (dev->invert_high_pin) + addr ^= 0x10000; + addr &= 0x1ffff; - switch (flash->command) { - case CMD_ERASE_SETUP: + switch (dev->command) { + case CMD_ERASE_SETUP: if (val == CMD_ERASE_CONFIRM) { for (i = 0; i < 3; i++) { - if ((addr >= flash->block_start[i]) && (addr <= flash->block_end[i])) - memset(&(flash->array[flash->block_start[i]]), 0xff, flash->block_len[i]); + if ((addr >= dev->block_start[i]) && (addr <= dev->block_end[i])) + memset(&dev->array[dev->block_start[i]], 0xff, dev->block_len[i]); } - flash->status = 0x80; + dev->status = 0x80; } - flash->command = CMD_READ_STATUS; + dev->command = CMD_READ_STATUS; break; - - case CMD_PROGRAM_SETUP: - case CMD_PROGRAM_SETUP_ALT: - if ((addr & 0x1e000) != (flash->block_start[3] & 0x1e000)) - flash->array[addr] = val; - flash->command = CMD_READ_STATUS; - flash->status = 0x80; + + case CMD_PROGRAM_SETUP: + case CMD_PROGRAM_SETUP_ALT: + if ((addr & 0x1e000) != (dev->block_start[3] & 0x1e000)) + dev->array[addr] = val; + dev->command = CMD_READ_STATUS; + dev->status = 0x80; break; - - default: - flash->command = val; + + default: + dev->command = val; switch (val) { case CMD_CLEAR_STATUS: - flash->status = 0; - break; + dev->status = 0; + break; } - } + } } -static void intel_flash_add_mappings(flash_t *flash) + +static void +add_mappings(flash_t *dev, int inverted) { - int i = 0; + uint32_t addr; + int i; - for (i = 0; i <= 7; i++) { - mem_map_add(&(flash->mapping[i]), 0xe0000 + (i << 14), 0x04000, flash_read, flash_readw, flash_readl, flash_write, mem_write_nullw, mem_write_nulll, flash->array + ((i << 14) & 0x1ffff), MEM_MAPPING_EXTERNAL, (void *)flash); - mem_map_add(&(flash->mapping_h[i]), 0xfffe0000 + (i << 14), 0x04000, flash_read, flash_readw, flash_readl, flash_write, mem_write_nullw, mem_write_nulll, flash->array + ((i << 14) & 0x1ffff), 0, (void *)flash); - } + for (i = 0; i < 8; i++) { + /* + * Some boards invert the high pin - the flash->array pointers + * need to pointer invertedly in order for INTERNAL writes to + * go to the right part of the array. + */ + addr = (inverted) ? ((i << 14) ^ 0x10000) : (i << 14); + + mem_map_add(&dev->mapping[i], 0xe0000 + (i << 14), 0x04000, + flash_read,flash_readw,flash_readl, + flash_write,mem_write_nullw,mem_write_nulll, + dev->array + (addr & 0x1ffff), MEM_MAPPING_EXTERNAL, dev); + + mem_map_add(&dev->mapping_h[i], 0xfffe0000 + (i << 14), 0x04000, + flash_read,flash_readw,flash_readl, + flash_write,mem_write_nullw,mem_write_nulll, + dev->array + (addr & 0x1ffff), 0, dev); + } } -/* This is for boards which invert the high pin - the flash->array pointers need to pointer invertedly in order for INTERNAL writes to go to the right part of the array. */ -static void intel_flash_add_mappings_inverted(flash_t *flash) + +static void +flash_close(priv_t priv) { - int i = 0; + flash_t *dev = (flash_t *)priv; + FILE *fp; - for (i = 0; i <= 7; i++) { - mem_map_add(&(flash->mapping[i]), 0xe0000 + (i << 14), 0x04000, flash_read, flash_readw, flash_readl, flash_write, mem_write_nullw, mem_write_nulll, flash->array + (((i << 14) ^ 0x10000) & 0x1ffff), MEM_MAPPING_EXTERNAL, (void *)flash); - mem_map_add(&(flash->mapping_h[i]), 0xfffe0000 + (i << 14), 0x04000, flash_read, flash_readw, flash_readl, flash_write, mem_write_nullw, mem_write_nulll, flash->array + (((i << 14) ^ 0x10000) & 0x1ffff), 0, (void *)flash); - } + fp = plat_fopen(nvr_path(dev->path), L"wb"); + if (fp != NULL) { + fwrite(&dev->array[dev->block_start[BLOCK_MAIN]], + dev->block_len[BLOCK_MAIN], 1, fp); + fwrite(&dev->array[dev->block_start[BLOCK_DATA1]], + dev->block_len[BLOCK_DATA1], 1, fp); + fwrite(&dev->array[dev->block_start[BLOCK_DATA2]], + dev->block_len[BLOCK_DATA2], 1, fp); + fclose(fp); + } + + free(dev); } -void *intel_flash_init(uint8_t type) + +static priv_t +flash_init(const device_t *info, UNUSED(void *parent)) { - FILE *f; - int i, l; - flash_t *flash; - wchar_t *machine_name; - wchar_t *flash_name; + wchar_t temp[128]; + flash_t *dev; + int i, type = 0; + FILE *fp; - flash = (flash_t *)mem_alloc(sizeof(flash_t)); - memset(flash, 0, sizeof(flash_t)); + dev = (flash_t *)mem_alloc(sizeof(flash_t)); + memset(dev, 0x00, sizeof(flash_t)); - l = (int)strlen(machine_get_internal_name())+1; - machine_name = (wchar_t *)mem_alloc(l * sizeof(wchar_t)); - mbstowcs(machine_name, machine_get_internal_name(), l); - l = (int)wcslen(machine_name)+5; - flash_name = (wchar_t *)mem_alloc(l*sizeof(wchar_t)); - swprintf(flash_name, l, L"%ls.bin", machine_name); + mbstowcs(temp, machine_get_internal_name(), sizeof_w(temp)); + swprintf(dev->path, sizeof_w(dev->path), L"%ls.bin", temp); - wcscpy(flash_path, flash_name); + switch(info->local) { + case 0: /* Intel BXT */ + break; - flash->flash_id = (type & FLASH_IS_BXB) ? 0x95 : 0x94; - flash->invert_high_pin = (type & FLASH_INVERT); + case 1: /* Intel BXB */ + type = FLASH_IS_BXB; + break; - /* The block lengths are the same both flash types. */ - flash->block_len[BLOCK_MAIN] = 0x1c000; - flash->block_len[BLOCK_DATA1] = 0x01000; - flash->block_len[BLOCK_DATA2] = 0x01000; - flash->block_len[BLOCK_BOOT] = 0x02000; + case 10: /* Intel BXT, Inverted */ + type = FLASH_INVERT; + break; - if (type & FLASH_IS_BXB) { /* 28F001BX-B */ - flash->block_start[BLOCK_MAIN] = 0x04000; /* MAIN BLOCK */ - flash->block_end[BLOCK_MAIN] = 0x1ffff; - flash->block_start[BLOCK_DATA1] = 0x03000; /* DATA AREA 1 BLOCK */ - flash->block_end[BLOCK_DATA1] = 0x03fff; - flash->block_start[BLOCK_DATA2] = 0x04000; /* DATA AREA 2 BLOCK */ - flash->block_end[BLOCK_DATA2] = 0x04fff; - flash->block_start[BLOCK_BOOT] = 0x00000; /* BOOT BLOCK */ - flash->block_end[BLOCK_BOOT] = 0x01fff; - } else { /* 28F001BX-T */ - flash->block_start[BLOCK_MAIN] = 0x00000; /* MAIN BLOCK */ - flash->block_end[BLOCK_MAIN] = 0x1bfff; - flash->block_start[BLOCK_DATA1] = 0x1c000; /* DATA AREA 1 BLOCK */ - flash->block_end[BLOCK_DATA1] = 0x1cfff; - flash->block_start[BLOCK_DATA2] = 0x1d000; /* DATA AREA 2 BLOCK */ - flash->block_end[BLOCK_DATA2] = 0x1dfff; - flash->block_start[BLOCK_BOOT] = 0x1e000; /* BOOT BLOCK */ - flash->block_end[BLOCK_BOOT] = 0x1ffff; - } + case 11: /* Intel BXB, Inverted */ + type = FLASH_IS_BXB | FLASH_INVERT; + break; + } - for (i = 0; i < 8; i++) { - mem_map_disable(&bios_mapping[i]); - mem_map_disable(&bios_high_mapping[i]); - } + dev->id = (type & FLASH_IS_BXB) ? 0x95 : 0x94; + dev->invert_high_pin = !!(type & FLASH_INVERT); - if (flash->invert_high_pin) { - memcpy(flash->array, bios + 65536, 65536); - memcpy(flash->array + 65536, bios, 65536); - } - else - memcpy(flash->array, bios, 131072); + /* The block lengths are the same both flash types. */ + dev->block_len[BLOCK_MAIN] = 0x1c000; + dev->block_len[BLOCK_DATA1] = 0x01000; + dev->block_len[BLOCK_DATA2] = 0x01000; + dev->block_len[BLOCK_BOOT] = 0x02000; - if (flash->invert_high_pin) - intel_flash_add_mappings_inverted(flash); - else - intel_flash_add_mappings(flash); + if (type & FLASH_IS_BXB) { /* 28F001BX-B */ + dev->block_start[BLOCK_MAIN] = 0x04000; /* MAIN BLOCK */ + dev->block_end[BLOCK_MAIN] = 0x1ffff; + dev->block_start[BLOCK_DATA1] = 0x03000;/* DATA AREA 1 BLOCK */ + dev->block_end[BLOCK_DATA1] = 0x03fff; + dev->block_start[BLOCK_DATA2] = 0x04000;/* DATA AREA 2 BLOCK */ + dev->block_end[BLOCK_DATA2] = 0x04fff; + dev->block_start[BLOCK_BOOT] = 0x00000; /* BOOT BLOCK */ + dev->block_end[BLOCK_BOOT] = 0x01fff; + } else { /* 28F001BX-T */ + dev->block_start[BLOCK_MAIN] = 0x00000; /* MAIN BLOCK */ + dev->block_end[BLOCK_MAIN] = 0x1bfff; + dev->block_start[BLOCK_DATA1] = 0x1c000;/* DATA AREA 1 BLOCK */ + dev->block_end[BLOCK_DATA1] = 0x1cfff; + dev->block_start[BLOCK_DATA2] = 0x1d000;/* DATA AREA 2 BLOCK */ + dev->block_end[BLOCK_DATA2] = 0x1dfff; + dev->block_start[BLOCK_BOOT] = 0x1e000; /* BOOT BLOCK */ + dev->block_end[BLOCK_BOOT] = 0x1ffff; + } - flash->command = CMD_READ_ARRAY; - flash->status = 0; + for (i = 0; i < 8; i++) { + mem_map_disable(&bios_mapping[i]); + mem_map_disable(&bios_high_mapping[i]); + } - f = plat_fopen(nvr_path(flash_path), L"rb"); - if (f) { - fread(&(flash->array[flash->block_start[BLOCK_MAIN]]), flash->block_len[BLOCK_MAIN], 1, f); - fread(&(flash->array[flash->block_start[BLOCK_DATA1]]), flash->block_len[BLOCK_DATA1], 1, f); - fread(&(flash->array[flash->block_start[BLOCK_DATA2]]), flash->block_len[BLOCK_DATA2], 1, f); - fclose(f); - } + if (dev->invert_high_pin) { + memcpy(dev->array, bios + 65536, 65536); + memcpy(dev->array + 65536, bios, 65536); + } else + memcpy(dev->array, bios, 131072); - free(flash_name); - free(machine_name); + add_mappings(dev, dev->invert_high_pin); - return flash; + dev->command = CMD_READ_ARRAY; + dev->status = 0; + + fp = plat_fopen(nvr_path(dev->path), L"rb"); + if (fp != NULL) { + fread(&dev->array[dev->block_start[BLOCK_MAIN]], + dev->block_len[BLOCK_MAIN], 1, fp); + fread(&dev->array[dev->block_start[BLOCK_DATA1]], + dev->block_len[BLOCK_DATA1], 1, fp); + fread(&dev->array[dev->block_start[BLOCK_DATA2]], + dev->block_len[BLOCK_DATA2], 1, fp); + fclose(fp); + } + + return((priv_t)dev); } -void *intel_flash_bxb_ami_init(const device_t *info, UNUSED(void *parent)) -{ - return intel_flash_init(info->local); -} - -/* For AMI BIOS'es - Intel 28F001BXT with high address pin inverted. */ -void *intel_flash_bxt_ami_init(const device_t *info, UNUSED(void *parent)) -{ - return intel_flash_init(info->local); -} - -/* For Award BIOS'es - Intel 28F001BXT with high address pin not inverted. */ -void *intel_flash_bxt_init(const device_t *info, UNUSED(void *parent)) -{ - return intel_flash_init(info->local); -} - -/* For Acer BIOS'es - Intel 28F001BXB. */ -void *intel_flash_bxb_init(const device_t *info, UNUSED(void *parent)) -{ - return intel_flash_init(info->local); -} - -void intel_flash_close(void *p) -{ - FILE *f; - flash_t *flash = (flash_t *)p; - - f = plat_fopen(nvr_path(flash_path), L"wb"); - fwrite(&(flash->array[flash->block_start[BLOCK_MAIN]]), flash->block_len[BLOCK_MAIN], 1, f); - fwrite(&(flash->array[flash->block_start[BLOCK_DATA1]]), flash->block_len[BLOCK_DATA1], 1, f); - fwrite(&(flash->array[flash->block_start[BLOCK_DATA2]]), flash->block_len[BLOCK_DATA2], 1, f); - fclose(f); - - free(flash); -} - - -const device_t intel_flash_bxt_ami_device = { - "Intel 28F001BXT Flash BIOS", - 0, FLASH_INVERT, - NULL, - intel_flash_bxt_ami_init, intel_flash_close, NULL, - NULL, NULL, NULL, NULL, - NULL -}; - -const device_t intel_flash_bxb_ami_device = { - "Intel 28F001BXB Flash BIOS", - 0, FLASH_IS_BXB | FLASH_INVERT, - NULL, - intel_flash_bxb_ami_init, intel_flash_close, NULL, - NULL, NULL, NULL, NULL, - NULL -}; const device_t intel_flash_bxt_device = { - "Intel 28F001BXT Flash BIOS", - 0, 0, + "Intel 28F001BXT Flash", + 0, + 0, NULL, - intel_flash_bxt_init, intel_flash_close, NULL, + flash_init, flash_close, NULL, NULL, NULL, NULL, NULL, NULL }; const device_t intel_flash_bxb_device = { - "Intel 28F001BXB Flash BIOS", - 0, FLASH_IS_BXB, + "Intel 28F001BXB Flash", + 0, + 1, NULL, - intel_flash_bxb_init, intel_flash_close, NULL, + flash_init, flash_close, NULL, + NULL, NULL, NULL, NULL, + NULL +}; + +const device_t intel_flash_bxt_ami_device = { + "Intel 28F001BXT Flash (Inverted)", + 0, + 10, + NULL, + flash_init, flash_close, NULL, + NULL, NULL, NULL, NULL, + NULL +}; + +const device_t intel_flash_bxb_ami_device = { + "Intel 28F001BXB Flash (Inverted)", + 0, + 11, + NULL, + flash_init, flash_close, NULL, NULL, NULL, NULL, NULL, NULL }; diff --git a/src/devices/system/intel_piix.c b/src/devices/system/intel_piix.c index e6958cd..f59471e 100644 --- a/src/devices/system/intel_piix.c +++ b/src/devices/system/intel_piix.c @@ -12,7 +12,7 @@ * word 0 - base address * word 1 - bits 1-15 = byte count, bit 31 = end of transfer * - * Version: @(#)intel_piix.c 1.0.11 2019/04/25 + * Version: @(#)intel_piix.c 1.0.12 2019/05/15 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -61,6 +61,7 @@ #include "dma.h" #include "pic.h" #include "intel_piix.h" +#include "port92.h" typedef struct @@ -80,12 +81,12 @@ typedef struct } piix_t; -static uint8_t piix_bus_master_read(uint16_t port, void *priv); -static uint16_t piix_bus_master_readw(uint16_t port, void *priv); -static uint32_t piix_bus_master_readl(uint16_t port, void *priv); -static void piix_bus_master_write(uint16_t port, uint8_t val, void *priv); -static void piix_bus_master_writew(uint16_t port, uint16_t val, void *priv); -static void piix_bus_master_writel(uint16_t port, uint32_t val, void *priv); +static uint8_t piix_bus_master_read(uint16_t port, priv_t priv); +static uint16_t piix_bus_master_readw(uint16_t port, priv_t priv); +static uint32_t piix_bus_master_readl(uint16_t port, priv_t priv); +static void piix_bus_master_write(uint16_t port, uint8_t val, priv_t priv); +static void piix_bus_master_writew(uint16_t port, uint16_t val, priv_t priv); +static void piix_bus_master_writel(uint16_t port, uint32_t val, priv_t priv); static void @@ -117,9 +118,9 @@ piix_bus_master_handlers(piix_t *dev, uint16_t old_base) static void -piix_write(int func, int addr, uint8_t val, void *priv) +piix_write(int func, int addr, uint8_t val, priv_t priv) { - piix_t *dev = (piix_t *) priv; + piix_t *dev = (piix_t *)priv; uint8_t valxor; uint16_t old_base = (dev->regs_ide[0x20] & 0xf0) | (dev->regs_ide[0x21] << 8); @@ -276,9 +277,9 @@ piix_write(int func, int addr, uint8_t val, void *priv) static uint8_t -piix_read(int func, int addr, void *priv) +piix_read(int func, int addr, priv_t priv) { - piix_t *dev = (piix_t *) priv; + piix_t *dev = (piix_t *)priv; if ((func == 1) && (dev->type & 0x100)) /* PB640's PIIX has no IDE part. */ return 0xff; @@ -425,9 +426,9 @@ piix_bus_master_next_addr(piix_busmaster_t *dev) static void -piix_bus_master_write(uint16_t port, uint8_t val, void *priv) +piix_bus_master_write(uint16_t port, uint8_t val, priv_t priv) { - piix_busmaster_t *dev = (piix_busmaster_t *) priv; + piix_busmaster_t *dev = (piix_busmaster_t *)priv; #ifdef _LOGGING int channel = (port & 8) ? 1 : 0; #endif @@ -481,9 +482,9 @@ piix_bus_master_write(uint16_t port, uint8_t val, void *priv) static void -piix_bus_master_writew(uint16_t port, uint16_t val, void *priv) +piix_bus_master_writew(uint16_t port, uint16_t val, priv_t priv) { - piix_busmaster_t *dev = (piix_busmaster_t *) priv; + piix_busmaster_t *dev = (piix_busmaster_t *)priv; DBGLOG(1, "PIIX Bus master WORD write: %04X %04X\n", port, val); @@ -506,9 +507,9 @@ piix_bus_master_writew(uint16_t port, uint16_t val, void *priv) static void -piix_bus_master_writel(uint16_t port, uint32_t val, void *priv) +piix_bus_master_writel(uint16_t port, uint32_t val, priv_t priv) { - piix_busmaster_t *dev = (piix_busmaster_t *) priv; + piix_busmaster_t *dev = (piix_busmaster_t *)priv; DBGLOG(1, "PIIX Bus master DWORD write: %04X %08X\n", port, val); @@ -527,10 +528,9 @@ piix_bus_master_writel(uint16_t port, uint32_t val, void *priv) static uint8_t -piix_bus_master_read(uint16_t port, void *priv) +piix_bus_master_read(uint16_t port, priv_t priv) { - piix_busmaster_t *dev = (piix_busmaster_t *) priv; - + piix_busmaster_t *dev = (piix_busmaster_t *)priv; uint8_t ret = 0xff; switch (port & 7) { @@ -561,10 +561,9 @@ piix_bus_master_read(uint16_t port, void *priv) static uint16_t -piix_bus_master_readw(uint16_t port, void *priv) +piix_bus_master_readw(uint16_t port, priv_t priv) { - piix_busmaster_t *dev = (piix_busmaster_t *) priv; - + piix_busmaster_t *dev = (piix_busmaster_t *)priv; uint16_t ret = 0xffff; switch (port & 7) { @@ -587,10 +586,9 @@ piix_bus_master_readw(uint16_t port, void *priv) static uint32_t -piix_bus_master_readl(uint16_t port, void *priv) +piix_bus_master_readl(uint16_t port, priv_t priv) { - piix_busmaster_t *dev = (piix_busmaster_t *) priv; - + piix_busmaster_t *dev = (piix_busmaster_t *)priv; uint32_t ret = 0xffffffff; switch (port & 7) { @@ -610,9 +608,9 @@ piix_bus_master_readl(uint16_t port, void *priv) static int -piix_bus_master_dma_op(int channel, uint8_t *data, int transfer_length, int out, void *priv) +piix_bus_master_dma_op(int channel, uint8_t *data, int transfer_length, int out, priv_t priv) { - piix_busmaster_t *dev = (piix_busmaster_t *) priv; + piix_busmaster_t *dev = (piix_busmaster_t *)priv; int force_end = 0, buffer_pos = 0; #ifdef _LOGGING char *sop = out ? "Writ" : "Read"; @@ -673,23 +671,23 @@ piix_bus_master_dma_op(int channel, uint8_t *data, int transfer_length, int out, int -piix_bus_master_dma_read(int channel, uint8_t *data, int transfer_length, void *priv) +piix_bus_master_dma_read(int channel, uint8_t *data, int transfer_length, priv_t priv) { return piix_bus_master_dma_op(channel, data, transfer_length, 1, priv); } int -piix_bus_master_dma_write(int channel, uint8_t *data, int transfer_length, void *priv) +piix_bus_master_dma_write(int channel, uint8_t *data, int transfer_length, priv_t priv) { return piix_bus_master_dma_op(channel, data, transfer_length, 0, priv); } void -piix_bus_master_set_irq(int channel, void *priv) +piix_bus_master_set_irq(int channel, priv_t priv) { - piix_busmaster_t *dev = (piix_busmaster_t *) priv; + piix_busmaster_t *dev = (piix_busmaster_t *)priv; dev->status &= ~4; dev->status |= (channel >> 4); @@ -737,9 +735,9 @@ piix_bus_master_reset(piix_t *dev) static void -piix_reset_hard(void *priv) +piix_reset_hard(priv_t priv) { - piix_t *piix = (piix_t *) priv; + piix_t *piix = (piix_t *)priv; piix_bus_master_reset(piix); @@ -822,7 +820,7 @@ piix_reset_hard(void *priv) static void -piix_reset(void *p) +piix_reset(priv_t priv) { //FIXME: this should be ide_reset() ... cdrom_reset_bus(CDROM_BUS_ATAPI); @@ -831,41 +829,40 @@ piix_reset(void *p) static void -piix_close(void *p) +piix_close(priv_t priv) { - piix_t *piix = (piix_t *)p; + piix_t *dev = (piix_t *)priv; - free(piix); + free(dev); } -static void * +static priv_t piix_init(const device_t *info, UNUSED(void *parent)) { - piix_t *piix = (piix_t *)mem_alloc(sizeof(piix_t)); - memset(piix, 0, sizeof(piix_t)); + piix_t *dev; - device_add(&ide_pci_2ch_device); + dev = (piix_t *)mem_alloc(sizeof(piix_t)); + memset(dev, 0x00, sizeof(piix_t)); + dev->type = info->local; - pci_add_card(7, piix_read, piix_write, piix); + device_add_parent(&ide_pci_2ch_device, dev); - piix->type = info->local; - piix_reset_hard(piix); + pci_add_card(7, piix_read, piix_write, dev); + + piix_reset_hard(dev); ide_set_bus_master(piix_bus_master_dma_read, piix_bus_master_dma_write, - piix_bus_master_set_irq, - &piix->bm[0], &piix->bm[1]); + piix_bus_master_set_irq, &dev->bm[0], &dev->bm[1]); - port_92_reset(); - - port_92_add(0); + device_add_parent(&port92_device, (priv_t)dev); dma_alias_set(); pci_enable_mirq(0); pci_enable_mirq(1); - return piix; + return((priv_t)dev); } diff --git a/src/devices/system/intel_piix.h b/src/devices/system/intel_piix.h index ce0f03e..0bba2fc 100644 --- a/src/devices/system/intel_piix.h +++ b/src/devices/system/intel_piix.h @@ -8,13 +8,13 @@ * * Emulation of the Intel PIIX and PIIX3 Xcelerators. * - * Version: @(#)intel_piix.h 1.0.2 2018/09/06 + * Version: @(#)intel_piix.h 1.0.3 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, * Sarah Walker, * - * Copyright 2017,2018 Fred N. van Kempen. + * Copyright 2017-2019 Fred N. van Kempen. * Copyright 2016-2018 Miran Grca. * Copyright 2008-2018 Sarah Walker. * @@ -47,10 +47,10 @@ extern const device_t piix_pb640_device; #endif -extern int piix_bus_master_dma_read(int channel, uint8_t *data, int transfer_length, void *priv); -extern int piix_bus_master_dma_write(int channel, uint8_t *data, int transfer_length, void *priv); +extern int piix_bus_master_dma_read(int channel, uint8_t *data, int transfer_length, priv_t priv); +extern int piix_bus_master_dma_write(int channel, uint8_t *data, int transfer_length, priv_t priv); -extern void piix_bus_master_set_irq(int channel, void *priv); +extern void piix_bus_master_set_irq(int channel, priv_t priv); #endif /*EMU_INTELPIIX_H*/ diff --git a/src/devices/system/intel_sio.c b/src/devices/system/intel_sio.c index d38d57b..3883fac 100644 --- a/src/devices/system/intel_sio.c +++ b/src/devices/system/intel_sio.c @@ -8,7 +8,7 @@ * * Emulation of Intel System I/O PCI chip. * - * Version: @(#)intel_sio.c 1.0.7 2019/04/25 + * Version: @(#)intel_sio.c 1.0.8 2019/05/15 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -49,6 +49,7 @@ #include "dma.h" #include "pci.h" #include "intel_sio.h" +#include "port92.h" typedef struct { @@ -57,9 +58,9 @@ typedef struct { static void -sio_write(int func, int addr, uint8_t val, void *priv) +sio_write(int func, int addr, uint8_t val, priv_t priv) { - sio_t *dev = (sio_t *) priv; + sio_t *dev = (sio_t *)priv; if (func > 0) return; @@ -103,9 +104,9 @@ sio_write(int func, int addr, uint8_t val, void *priv) return; if (val & 0x40) - port_92_add(0); + device_add_parent(&port92_device, (priv_t)dev); else - port_92_remove(); + device_remove(&port92_device, (priv_t)dev); case 0x60: if (val & 0x80) @@ -137,9 +138,9 @@ sio_write(int func, int addr, uint8_t val, void *priv) static uint8_t -sio_read(int func, int addr, void *priv) +sio_read(int func, int addr, priv_t priv) { - sio_t *dev = (sio_t *) priv; + sio_t *dev = (sio_t *)priv; uint8_t ret; ret = 0xff; @@ -152,9 +153,9 @@ sio_read(int func, int addr, void *priv) static void -sio_reset(void *priv) +sio_reset(priv_t priv) { - sio_t *dev = (sio_t *) priv; + sio_t *dev = (sio_t *)priv; memset(dev->regs, 0, 256); @@ -186,31 +187,31 @@ sio_reset(void *priv) static void -sio_close(void *p) +sio_close(priv_t priv) { - sio_t *sio = (sio_t *)p; + sio_t *sio = (sio_t *)priv; free(sio); } -static void * +static priv_t sio_init(const device_t *info, UNUSED(void *parent)) { - sio_t *sio = (sio_t *)mem_alloc(sizeof(sio_t)); - memset(sio, 0, sizeof(sio_t)); + sio_t *sio; + + sio = (sio_t *)mem_alloc(sizeof(sio_t)); + memset(sio, 0x00, sizeof(sio_t)); pci_add_card(2, sio_read, sio_write, sio); - + sio_reset(sio); - port_92_reset(); - - port_92_add(0); + device_add_parent(&port92_device, (priv_t)sio); dma_alias_set(); - return sio; + return((priv_t)sio); } diff --git a/src/devices/system/mca.c b/src/devices/system/mca.c index e95d560..6d39247 100644 --- a/src/devices/system/mca.c +++ b/src/devices/system/mca.c @@ -8,13 +8,13 @@ * * Implementation of the MCA bus primitives. * - * Version: @(#)mca.c 1.0.2 2018/05/06 + * Version: @(#)mca.c 1.0.3 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, * Sarah Walker, * - * Copyright 2017,2018 Fred N. van Kempen. + * Copyright 2017-2019 Fred N. van Kempen. * Copyright 2016-2018 Miran Grca. * Copyright 2008-2018 Sarah Walker. * @@ -40,13 +40,14 @@ #include #include #include +#include "../../emu.h" #include "../../io.h" #include "mca.h" -void (*mca_card_write[8])(int addr, uint8_t val, void *priv); -uint8_t (*mca_card_read[8])(int addr, void *priv); -void *mca_priv[8]; +void (*mca_card_write[8])(int addr, uint8_t val, priv_t); +uint8_t (*mca_card_read[8])(int addr, priv_t); +priv_t *mca_priv[8]; static int mca_index; static int mca_nr_cards; @@ -56,7 +57,7 @@ void mca_init(int nr_cards) { int c; - + for (c = 0; c < 8; c++) { mca_card_read[c] = NULL; mca_card_write[c] = NULL; @@ -100,7 +101,7 @@ mca_write(uint16_t port, uint8_t val) void -mca_add(uint8_t (*read)(int addr, void *priv), void (*write)(int addr, uint8_t val, void *priv), void *priv) +mca_add(uint8_t (*read)(int, priv_t), void (*write)(int, uint8_t, priv_t), priv_t priv) { int c; diff --git a/src/devices/system/mca.h b/src/devices/system/mca.h index d093fe2..817df2a 100644 --- a/src/devices/system/mca.h +++ b/src/devices/system/mca.h @@ -8,13 +8,13 @@ * * Definitions for the MCA bus handlers. * - * Version: @(#)mca.h 1.0.2 2018/03/12 + * Version: @(#)mca.h 1.0.3 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, * Sarah Walker, * - * Copyright 2017,2018 Fred N. van Kempen. + * Copyright 2017-2019 Fred N. van Kempen. * Copyright 2016-2018 Miran Grca. * Copyright 2008-2018 Sarah Walker. * @@ -41,7 +41,8 @@ extern void mca_init(int nr_cards); -extern void mca_add(uint8_t (*read)(int addr, void *priv), void (*write)(int addr, uint8_t val, void *priv), void *priv); + +extern void mca_add(uint8_t (*read)(int, priv_t), void (*write)(int, uint8_t, priv_t), priv_t priv); extern void mca_set_index(int index); extern uint8_t mca_read(uint16_t port); extern void mca_write(uint16_t port, uint8_t val); diff --git a/src/devices/system/memregs.c b/src/devices/system/memregs.c index 1d4a758..41b7613 100644 --- a/src/devices/system/memregs.c +++ b/src/devices/system/memregs.c @@ -9,10 +9,12 @@ * Emulation of the memory I/O scratch registers on ports 0xE1 * and 0xE2, used by just about any emulated machine. * - * Version: @(#)memregs.c 1.0.3 2018/09/06 + * Version: @(#)memregs.c 1.0.4 2019/05/13 * - * Author: Miran Grca, + * Authors: Fred N. van Kempen, + * Miran Grca, * + * Copyright 2019 Fred N. van Kempen. * Copyright 2016-2018 Miran Grca. * * This program is free software; you can redistribute it and/or modify @@ -35,54 +37,98 @@ */ #include #include +#include #include #include #include "../../emu.h" #include "../../io.h" +#include "../../device.h" +#include "../../plat.h" #include "memregs.h" -static uint8_t mem_regs[16] = { - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff -}; -static uint8_t mem_reg_ffff = 0; +typedef struct { + uint8_t regs[16]; + + uint8_t reg_ffff; +} memregs_t; static void -memregs_write(uint16_t port, uint8_t val, void *priv) +memregs_write(uint16_t port, uint8_t val, priv_t priv) { - if (port == 0xffff) - mem_reg_ffff = 0; + memregs_t *dev = (memregs_t *)priv; - mem_regs[port & 0xf] = val; + if (port == 0xffff) + dev->reg_ffff = 0; + + dev->regs[port & 0x0f] = val; } static uint8_t -memregs_read(uint16_t port, void *priv) +memregs_read(uint16_t port, priv_t priv) { + memregs_t *dev = (memregs_t *)priv; + if (port == 0xffff) - return mem_reg_ffff; + return dev->reg_ffff; - return mem_regs[port & 0xf]; + return dev->regs[port & 0xf]; } -void -memregs_init(void) +static void +memregs_close(priv_t priv) { - io_sethandler(0x00e1, 2, - memregs_read,NULL,NULL, memregs_write,NULL,NULL, NULL); + memregs_t *dev = (memregs_t *)priv; + + free(dev); } -void -powermate_memregs_init(void) +static priv_t +memregs_init(const device_t *info, UNUSED(void *parent)) { - io_sethandler(0x00ed, 2, - memregs_read,NULL,NULL, memregs_write,NULL,NULL, NULL); + memregs_t *dev; - io_sethandler(0xffff, 1, - memregs_read,NULL,NULL, memregs_write,NULL,NULL, NULL); + dev = (memregs_t *)mem_alloc(sizeof(memregs_t)); + memset(dev, 0xff, sizeof(memregs_t)); + dev->reg_ffff = 0; + + switch(info->local) { + case 0: /* default */ + io_sethandler(0x00e1, 2, + memregs_read,NULL,NULL, + memregs_write,NULL,NULL, dev); + break; + + case 1: /* powermate */ + io_sethandler(0x00ed, 2, + memregs_read,NULL,NULL, + memregs_write,NULL,NULL, dev); + io_sethandler(0xffff, 1, + memregs_read,NULL,NULL, + memregs_write,NULL,NULL, dev); + break; + } + + return((priv_t)dev); } + + +const device_t memregs_device = { + "Memory Registers", + 0, 0, NULL, + memregs_init, memregs_close, NULL, + NULL, NULL, NULL, NULL, + NULL +}; + +const device_t memregs_powermate_device = { + "Memory Registers (PowerMate)", + 0, 1, NULL, + memregs_init, memregs_close, NULL, + NULL, NULL, NULL, NULL, + NULL +}; diff --git a/src/devices/system/memregs.h b/src/devices/system/memregs.h index 12af25d..0d9d516 100644 --- a/src/devices/system/memregs.h +++ b/src/devices/system/memregs.h @@ -8,10 +8,12 @@ * * Definitions for the memory control module. * - * Version: @(#)memregs.h 1.0.1 2018/02/14 + * Version: @(#)memregs.h 1.0.2 2019/05/13 * - * Author: Miran Grca, + * Authors: Fred N. van Kempen, + * Miran Grca, * + * Copyright 2019 Fred N. van Kempen. * Copyright 2016-2018 Miran Grca. * * This program is free software; you can redistribute it and/or modify @@ -36,8 +38,8 @@ # define EMU_MEMREGS_H -extern void powermate_memregs_init(void); -extern void memregs_init(void); +extern const device_t memregs_device; +extern const device_t memregs_powermate_device; #endif /*EMU_MEMREGS_H*/ diff --git a/src/devices/system/nmi.c b/src/devices/system/nmi.c index eb1f5cd..09595b9 100644 --- a/src/devices/system/nmi.c +++ b/src/devices/system/nmi.c @@ -8,13 +8,13 @@ * * Implementation of the NMI handler. * - * Version: @(#)nmi.c 1.0.2 2018/05/06 + * Version: @(#)nmi.c 1.0.3 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, * Sarah Walker, * - * Copyright 2017,2018 Fred N. van Kempen. + * Copyright 2017-2019 Fred N. van Kempen. * Copyright 2016-2018 Miran Grca. * Copyright 2008-2018 Sarah Walker. * @@ -40,6 +40,7 @@ #include #include #include +#include "../../emu.h" #include "../../io.h" #include "nmi.h" @@ -48,7 +49,7 @@ int nmi_mask; static void -nmi_write(uint16_t port, uint8_t val, void *priv) +nmi_write(uint16_t port, uint8_t val, priv_t priv) { nmi_mask = val & 0x80; } @@ -57,6 +58,8 @@ nmi_write(uint16_t port, uint8_t val, void *priv) void nmi_init(void) { - io_sethandler(0x00a0, 1, NULL,NULL,NULL, nmi_write,NULL,NULL, NULL); + io_sethandler(0x00a0, 1, + NULL,NULL,NULL, nmi_write,NULL,NULL, NULL); + nmi_mask = 0; } diff --git a/src/devices/system/nmi.h b/src/devices/system/nmi.h index e6b3cea..36d7d3b 100644 --- a/src/devices/system/nmi.h +++ b/src/devices/system/nmi.h @@ -8,13 +8,13 @@ * * Definitions for the NMI handler. * - * Version: @(#)nmi.h 1.0.2 2018/05/06 + * Version: @(#)nmi.h 1.0.3 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, * Sarah Walker, * - * Copyright 2017,2018 Fred N. van Kempen. + * Copyright 2017-2019 Fred N. van Kempen. * Copyright 2016-2018 Miran Grca. * Copyright 2008-2018 Sarah Walker. * @@ -40,13 +40,12 @@ # define EMU_NMI_H -extern int nmi_mask; extern int nmi; +extern int nmi_mask; extern int nmi_auto_clear; extern void nmi_init(void); -//extern void nmi_write(uint16_t port, uint8_t val, void *p); #endif /*EMU_NMI_H*/ diff --git a/src/devices/system/nvr_at.c b/src/devices/system/nvr_at.c index 1a02db7..b1cbd11 100644 --- a/src/devices/system/nvr_at.c +++ b/src/devices/system/nvr_at.c @@ -189,7 +189,7 @@ * including the later update (DS12887A) which implemented a * "century" register to be compatible with Y2K. * - * Version: @(#)nvr_at.c 1.0.19 2019/05/05 + * Version: @(#)nvr_at.c 1.0.20 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -336,7 +336,7 @@ time_get(nvr_t *nvr, struct tm *tm) /* Set the current NVR time. */ static void -time_set(nvr_t *nvr, struct tm *tm) +time_set(nvr_t *nvr, const struct tm *tm) { local_t *local = (local_t *)nvr->data; int year = (tm->tm_year + 1900); @@ -398,7 +398,7 @@ check_alarm(nvr_t *nvr, int8_t addr) /* Update the NVR registers from the internal clock. */ static void -timer_update(void *priv) +timer_update(priv_t priv) { nvr_t *nvr = (nvr_t *)priv; local_t *local = (local_t *)nvr->data; @@ -467,7 +467,7 @@ timer_recalc(nvr_t *nvr, int add) static void -timer_intr(void *priv) +timer_intr(priv_t priv) { nvr_t *nvr = (nvr_t *)priv; local_t *local = (local_t *)nvr->data; @@ -510,7 +510,7 @@ timer_tick(nvr_t *nvr) /* Write to one of the NVR registers. */ static void -nvr_write(uint16_t addr, uint8_t val, void *priv) +nvr_write(uint16_t addr, uint8_t val, priv_t priv) { nvr_t *nvr = (nvr_t *)priv; local_t *local = (local_t *)nvr->data; @@ -573,7 +573,7 @@ nvr_write(uint16_t addr, uint8_t val, void *priv) /* Read from one of the NVR registers. */ static uint8_t -nvr_read(uint16_t addr, void *priv) +nvr_read(uint16_t addr, priv_t priv) { nvr_t *nvr = (nvr_t *)priv; local_t *local = (local_t *)nvr->data; @@ -659,7 +659,22 @@ nvr_recalc(void *priv) } -static void * +static void +nvr_at_close(priv_t priv) +{ + nvr_t *nvr = (nvr_t *)priv; + + if (nvr->fn != NULL) + free((wchar_t *)nvr->fn); + + if (nvr->data != NULL) + free(nvr->data); + + free(nvr); +} + + +static priv_t nvr_at_init(const device_t *info, UNUSED(void *parent)) { local_t *local; @@ -715,22 +730,7 @@ nvr_at_init(const device_t *info, UNUSED(void *parent)) io_sethandler(0x0070, 2, nvr_read,NULL,NULL, nvr_write,NULL,NULL, nvr); - return(nvr); -} - - -static void -nvr_at_close(void *priv) -{ - nvr_t *nvr = (nvr_t *)priv; - - if (nvr->fn != NULL) - free((wchar_t *)nvr->fn); - - if (nvr->data != NULL) - free(nvr->data); - - free(nvr); + return((priv_t)nvr); } diff --git a/src/devices/system/nvr_ps2.c b/src/devices/system/nvr_ps2.c index a095266..c4e1666 100644 --- a/src/devices/system/nvr_ps2.c +++ b/src/devices/system/nvr_ps2.c @@ -8,7 +8,7 @@ * * Handling of the PS/2 series CMOS devices. * - * Version: @(#)nvr_ps2.c 1.0.12 2019/04/09 + * Version: @(#)nvr_ps2.c 1.0.13 2019/05/13 * * Authors: Fred N. van Kempen, * Sarah Walker, @@ -59,7 +59,7 @@ typedef struct { static uint8_t -ps2_nvr_read(uint16_t port, void *priv) +ps2_nvr_read(uint16_t port, priv_t priv) { ps2_nvr_t *nvr = (ps2_nvr_t *)priv; uint8_t ret = 0xff; @@ -83,7 +83,7 @@ ps2_nvr_read(uint16_t port, void *priv) static void -ps2_nvr_write(uint16_t port, uint8_t val, void *priv) +ps2_nvr_write(uint16_t port, uint8_t val, priv_t priv) { ps2_nvr_t *nvr = (ps2_nvr_t *)priv; @@ -103,7 +103,25 @@ ps2_nvr_write(uint16_t port, uint8_t val, void *priv) } -static void * +static void +ps2_nvr_close(priv_t priv) +{ + ps2_nvr_t *nvr = (ps2_nvr_t *)priv; + FILE *fp; + + fp = plat_fopen(nvr_path(nvr->fn), L"wb"); + if (fp != NULL) { + (void)fwrite(nvr->ram, sizeof(nvr->ram), 1, fp); + fclose(fp); + } + + free(nvr->fn); + + free(nvr); +} + + +static priv_t ps2_nvr_init(const device_t *info, UNUSED(void *parent)) { char temp[128]; @@ -130,25 +148,7 @@ ps2_nvr_init(const device_t *info, UNUSED(void *parent)) io_sethandler(0x0074, 3, ps2_nvr_read,NULL,NULL, ps2_nvr_write,NULL,NULL, nvr); - return(nvr); -} - - -static void -ps2_nvr_close(void *priv) -{ - ps2_nvr_t *nvr = (ps2_nvr_t *)priv; - FILE *fp; - - fp = plat_fopen(nvr_path(nvr->fn), L"wb"); - if (fp != NULL) { - (void)fwrite(nvr->ram, sizeof(nvr->ram), 1, fp); - fclose(fp); - } - - free(nvr->fn); - - free(nvr); + return((priv_t)nvr); } diff --git a/src/devices/system/pci.c b/src/devices/system/pci.c index fa7980d..b329bad 100644 --- a/src/devices/system/pci.c +++ b/src/devices/system/pci.c @@ -8,7 +8,7 @@ * * Implement the PCI bus. * - * Version: @(#)pci.c 1.0.11 2019/04/20 + * Version: @(#)pci.c 1.0.12 2019/05/15 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -59,9 +59,9 @@ typedef struct { uint8_t id, type; uint8_t irq_routing[4]; - void *priv; - void (*write)(int func, int addr, uint8_t val, void *priv); - uint8_t (*read)(int func, int addr, void *priv); + priv_t priv; + void (*write)(int func, int addr, uint8_t val, priv_t priv); + uint8_t (*read)(int func, int addr, priv_t priv); } pci_card_t; typedef struct { @@ -110,7 +110,7 @@ pcilog(int level, const char *fmt, ...) static void -pci_cf8_write(uint16_t port, uint32_t val, UNUSED(void *priv)) +pci_cf8_write(uint16_t port, uint32_t val, UNUSED(priv_t priv)) { pci_index = val & 0xff; pci_func = (val >> 8) & 7; @@ -121,7 +121,7 @@ pci_cf8_write(uint16_t port, uint32_t val, UNUSED(void *priv)) static uint32_t -pci_cf8_read(uint16_t port, UNUSED(void *priv)) +pci_cf8_read(uint16_t port, UNUSED(priv_t priv)) { return pci_index | (pci_func << 8) | (pci_card << 11) | (pci_bus << 16) | (pci_enable << 31); @@ -129,7 +129,7 @@ pci_cf8_read(uint16_t port, UNUSED(void *priv)) static void -pci_write(uint16_t port, uint8_t val, UNUSED(void *priv)) +pci_write(uint16_t port, uint8_t val, UNUSED(priv_t priv)) { uint8_t slot = 0; @@ -154,7 +154,7 @@ pci_write(uint16_t port, uint8_t val, UNUSED(void *priv)) static uint8_t -pci_read(uint16_t port, UNUSED(void *priv)) +pci_read(uint16_t port, UNUSED(priv_t priv)) { uint8_t slot = 0; @@ -181,7 +181,7 @@ pci_read(uint16_t port, UNUSED(void *priv)) static void -elcr_write(uint16_t port, uint8_t val, UNUSED(void *priv)) +elcr_write(uint16_t port, uint8_t val, UNUSED(priv_t priv)) { DBGLOG(1, "ELCR%i: WRITE %02X\n", port & 1, val); @@ -206,7 +206,7 @@ elcr_write(uint16_t port, uint8_t val, UNUSED(void *priv)) static uint8_t -elcr_read(uint16_t port, UNUSED(void *priv)) +elcr_read(uint16_t port, UNUSED(priv_t priv)) { DBGLOG(1, "ELCR%i: READ %02X\n", port & 1, elcr[port & 1]); @@ -224,12 +224,12 @@ elcr_reset(void) } -static void pci_type2_write(uint16_t port, uint8_t val, void *priv); -static uint8_t pci_type2_read(uint16_t port, UNUSED(void *priv)); +static void pci_type2_write(uint16_t, uint8_t, priv_t); +static uint8_t pci_type2_read(uint16_t, priv_t); static void -pci_type2_write(uint16_t port, uint8_t val, void *priv) +pci_type2_write(uint16_t port, uint8_t val, priv_t priv) { uint8_t slot = 0; @@ -265,7 +265,7 @@ pci_type2_write(uint16_t port, uint8_t val, void *priv) static uint8_t -pci_type2_read(uint16_t port, UNUSED(void *priv)) +pci_type2_read(uint16_t port, UNUSED(priv_t priv)) { uint8_t slot = 0; @@ -605,7 +605,7 @@ pci_slots_clear(void) static uint8_t -trc_read(uint16_t port, UNUSED(void *priv)) +trc_read(uint16_t port, UNUSED(priv_t priv)) { return trc_reg & 0xfb; } @@ -617,8 +617,6 @@ trc_reset(uint8_t val) if (val & 2) { device_reset_all(DEVICE_PCI); - port_92_reset(); - pci_reset(); } @@ -627,7 +625,7 @@ trc_reset(uint8_t val) static void -trc_write(uint16_t port, uint8_t val, UNUSED(void *priv)) +trc_write(uint16_t port, uint8_t val, UNUSED(priv_t priv)) { DEBUG("TRC Write: %02X\n", val); @@ -734,7 +732,7 @@ pci_register_slot(int card, int type, int inta, int intb, int intc, int intd) uint8_t -pci_add_card(uint8_t add_type, uint8_t (*read)(int func, int addr, void *priv), void (*write)(int func, int addr, uint8_t val, void *priv), void *priv) +pci_add_card(uint8_t add_type, uint8_t (*read)(int, int, priv_t), void (*write)(int, int, uint8_t, priv_t), priv_t priv) { pci_card_t *dev; uint8_t i; diff --git a/src/devices/system/pci.h b/src/devices/system/pci.h index 07db1ce..a04742e 100644 --- a/src/devices/system/pci.h +++ b/src/devices/system/pci.h @@ -8,7 +8,7 @@ * * Definitions for the PCI handler module. * - * Version: @(#)pci.h 1.0.3 2019/04/11 + * Version: @(#)pci.h 1.0.4 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -95,7 +95,7 @@ extern uint32_t pci_get_speed(int burst); extern void pci_register_slot(int card, int type, int inta, int intb, int intc, int intd); extern void pci_close(void); -extern uint8_t pci_add_card(uint8_t add_type, uint8_t (*read)(int func, int addr, void *priv), void (*write)(int func, int addr, uint8_t val, void *priv), void *priv); +extern uint8_t pci_add_card(uint8_t add_type, uint8_t (*read)(int, int, priv_t), void (*write)(int, int, uint8_t, priv_t), priv_t priv); extern void trc_init(void); diff --git a/src/devices/system/pci_dummy.c b/src/devices/system/pci_dummy.c index 1ace871..f9b008f 100644 --- a/src/devices/system/pci_dummy.c +++ b/src/devices/system/pci_dummy.c @@ -8,7 +8,7 @@ * * Example implementation of a PCI device. * - * Version: @(#)pci_dummy.c 1.0.5 2018/09/04 + * Version: @(#)pci_dummy.c 1.0.6 2019/05/13 * * Author: Miran Grca, * @@ -59,7 +59,7 @@ dummy_interrupt(int set) static uint8_t -dummy_read(uint16_t port, void *priv) +dummy_read(uint16_t port, priv_t priv) { uint8_t ret = 0; @@ -98,21 +98,21 @@ dummy_read(uint16_t port, void *priv) static uint16_t -dummy_readw(uint16_t port, void *priv) +dummy_readw(uint16_t port, priv_t priv) { return(dummy_read(port, priv)); } static uint32_t -dummy_readl(uint16_t port, void *priv) +dummy_readl(uint16_t port, priv_t priv) { return(dummy_read(port, priv)); } static void -dummy_write(uint16_t port, uint8_t val, void *priv) +dummy_write(uint16_t port, uint8_t val, priv_t priv) { switch(port & 0x20) { case 0x06: @@ -129,14 +129,14 @@ dummy_write(uint16_t port, uint8_t val, void *priv) static void -dummy_writew(uint16_t port, uint16_t val, void *priv) +dummy_writew(uint16_t port, uint16_t val, priv_t priv) { dummy_write(port, val & 0xff, priv); } static void -dummy_writel(uint16_t port, uint32_t val, void *priv) +dummy_writel(uint16_t port, uint32_t val, priv_t priv) { dummy_write(port, val & 0xff, priv); } @@ -159,9 +159,9 @@ dummy_io_set(void) static uint8_t -dummy_pci_read(int func, int addr, void *priv) +dummy_pci_read(int func, int addr, priv_t priv) { - pclog("AB0B:071A: PCI_Read(%d, %04x)\n", func, addr); + DEBUG("AB0B:071A: PCI_Read(%d, %04x)\n", func, addr); switch(addr) { case 0x00: @@ -232,11 +232,11 @@ dummy_pci_read(int func, int addr, void *priv) static void -dummy_pci_write(int func, int addr, uint8_t val, void *priv) +dummy_pci_write(int func, int addr, uint8_t val, priv_t priv) { uint8_t valxor; - pclog("AB0B:071A: PCI_Write(%d, %04x, %02x)\n", func, addr, val); + DEBUG("AB0B:071A: PCI_Write(%d, %04x, %02x)\n", func, addr, val); switch(addr) { case 0x04: /* PCI_COMMAND_LO */ diff --git a/src/devices/system/pic.c b/src/devices/system/pic.c index 4d2ac15..b2f6e06 100644 --- a/src/devices/system/pic.c +++ b/src/devices/system/pic.c @@ -8,7 +8,7 @@ * * Implementation of Intel 8259 interrupt controller. * - * Version: @(#)pic.c 1.0.7 2019/04/11 + * Version: @(#)pic.c 1.0.8 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -118,7 +118,7 @@ update_pending(void) static void -pic_write(uint16_t addr, uint8_t val, void *priv) +pic_write(uint16_t addr, uint8_t val, priv_t priv) { PIC *dev = (PIC *)priv; int c; @@ -222,7 +222,7 @@ pic_write(uint16_t addr, uint8_t val, void *priv) static uint8_t -pic_read(uint16_t addr, void *priv) +pic_read(uint16_t addr, priv_t priv) { PIC *dev = (PIC *)priv; @@ -273,7 +273,7 @@ pic_autoeoi(void) static void -pic2_write(uint16_t addr, uint8_t val, void *priv) +pic2_write(uint16_t addr, uint8_t val, priv_t priv) { PIC *dev = (PIC *)priv; int c; @@ -364,7 +364,7 @@ pic2_write(uint16_t addr, uint8_t val, void *priv) static uint8_t -pic2_read(uint16_t addr, void *priv) +pic2_read(uint16_t addr, priv_t priv) { PIC *dev = (PIC *)priv; diff --git a/src/devices/system/pit.c b/src/devices/system/pit.c index 2f2378d..2e42447 100644 --- a/src/devices/system/pit.c +++ b/src/devices/system/pit.c @@ -13,7 +13,7 @@ * B4 to 40, two writes to 43, then two reads * - value _does_ change! * - * Version: @(#)pit.c 1.0.15 2019/05/05 + * Version: @(#)pit.c 1.0.16 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -310,7 +310,7 @@ load_timer(PIT *dev, int t) static void -pit_write(uint16_t addr, uint8_t val, void *priv) +pit_write(uint16_t addr, uint8_t val, priv_t priv) { PIT *dev = (PIT *)priv; double sv = 0.0; @@ -421,7 +421,7 @@ pit_write(uint16_t addr, uint8_t val, void *priv) static uint8_t -pit_read(uint16_t addr, void *priv) +pit_read(uint16_t addr, priv_t priv) { PIT *dev = (PIT *)priv; uint8_t temp = 0xff; diff --git a/src/devices/system/port92.c b/src/devices/system/port92.c new file mode 100644 index 0000000..5ec92ed --- /dev/null +++ b/src/devices/system/port92.c @@ -0,0 +1,151 @@ +/* + * VARCem Virtual ARchaeological Computer EMulator. + * An emulator of (mostly) x86-based PC systems and devices, + * using the ISA,EISA,VLB,MCA and PCI system buses, roughly + * spanning the era between 1981 and 1995. + * + * This file is part of the VARCem Project. + * + * Implementation of the "port 92" pseudo-device. + * + * Version: @(#)port92.c 1.0.1 2019/05/15 + * + * Authors: Fred N. van Kempen, + * Miran Grca, + * Sarah Walker, + * + * Copyright 2017-2019 Fred N. van Kempen. + * Copyright 2016-2019 Miran Grca. + * Copyright 2008-2019 Sarah Walker. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the: + * + * Free Software Foundation, Inc. + * 59 Temple Place - Suite 330 + * Boston, MA 02111-1307 + * USA. + */ +#include +#include +#include +#include +#include +#include "../../emu.h" +#include "../../cpu/cpu.h" +#include "../../io.h" +#include "../../mem.h" +#include "../../device.h" +#include "../../plat.h" +#include "port92.h" + + +typedef struct { + uint8_t reg, + mask; +} port92_t; + + +static void +p92_reset(priv_t priv) +{ + port92_t *dev = (port92_t *)priv; + + dev->reg = 0; + + mem_a20_alt = 0; + mem_a20_recalc(); + + flushmmucache(); +} + + +static uint8_t +p92_read(uint16_t port, priv_t priv) +{ + port92_t *dev = (port92_t *)priv; + + return(dev->reg | dev->mask); +} + + +static void +p92_write(uint16_t port, uint8_t val, priv_t priv) +{ + port92_t *dev = (port92_t *)priv; + + if ((mem_a20_alt ^ val) & 2) { + mem_a20_alt = (val & 2); + mem_a20_recalc(); + } + + if ((~dev->reg & val) & 1) { + cpu_reset(0); + cpu_set_edx(); + } + + dev->reg = val | dev->mask; +} + + +static void +p92_close(priv_t priv) +{ + port92_t *dev = (port92_t *)priv; + + io_removehandler(0x0092, 1, + p92_read,NULL,NULL, p92_write,NULL,NULL, dev); + + free(dev); +} + + +static priv_t +p92_init(const device_t *info, UNUSED(void *parent)) +{ + port92_t *dev; + + dev = (port92_t *)mem_alloc(sizeof(port92_t)); + memset(dev, 0x00, sizeof(port92_t)); + + dev->mask = (info->local) ? 0xfc : 0x00; + + io_sethandler(0x0092, 1, + p92_read,NULL,NULL, p92_write,NULL,NULL, dev); + + p92_reset((priv_t)dev); + + return((priv_t)dev); +} + + +const device_t port92_device = { + "Port 92", + 0, + 0, + NULL, + p92_init, p92_close, p92_reset, + NULL, NULL, NULL, NULL, + NULL +}; + + +const device_t port92_inverted_device = { + "Port 92 (Inverted)", + 0, + 1, + NULL, + p92_init, p92_close, p92_reset, + NULL, NULL, NULL, NULL, + NULL +}; diff --git a/src/devices/system/port92.h b/src/devices/system/port92.h new file mode 100644 index 0000000..1ea34ec --- /dev/null +++ b/src/devices/system/port92.h @@ -0,0 +1,45 @@ +/* + * VARCem Virtual ARchaeological Computer EMulator. + * An emulator of (mostly) x86-based PC systems and devices, + * using the ISA,EISA,VLB,MCA and PCI system buses, roughly + * spanning the era between 1981 and 1995. + * + * This file is part of the VARCem Project. + * + * Definitions for the Port92 pseudo-device. + * + * Version: @(#)port92.h 1.0.1 2019/05/15 + * + * Authors: Fred N. van Kempen, + * Sarah Walker, + * + * Copyright 2017-2019 Fred N. van Kempen. + * Copyright 2008-2018 Sarah Walker. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the: + * + * Free Software Foundation, Inc. + * 59 Temple Place - Suite 330 + * Boston, MA 02111-1307 + * USA. + */ +#ifndef PORT_92_H +# define PORT_92_H + + +extern const device_t port92_device; +extern const device_t port92_inverted_device; + + +#endif /*PORT_92_H*/ diff --git a/src/devices/video/vid_ati18800.c b/src/devices/video/vid_ati18800.c index edec8d3..29e0f64 100644 --- a/src/devices/video/vid_ati18800.c +++ b/src/devices/video/vid_ati18800.c @@ -8,7 +8,7 @@ * * ATI 18800 emulation (VGA Edge-16) * - * Version: @(#)vid_ati18800.c 1.0.13 2019/04/19 + * Version: @(#)vid_ati18800.c 1.0.14 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -82,9 +82,9 @@ typedef struct ati18800_t } ati18800_t; -static void ati18800_out(uint16_t addr, uint8_t val, void *p) +static void ati18800_out(uint16_t addr, uint8_t val, priv_t priv) { - ati18800_t *ati18800 = (ati18800_t *)p; + ati18800_t *ati18800 = (ati18800_t *)priv; svga_t *svga = &ati18800->svga; uint8_t old; @@ -141,9 +141,9 @@ static void ati18800_out(uint16_t addr, uint8_t val, void *p) svga_out(addr, val, svga); } -static uint8_t ati18800_in(uint16_t addr, void *p) +static uint8_t ati18800_in(uint16_t addr, priv_t priv) { - ati18800_t *ati18800 = (ati18800_t *)p; + ati18800_t *ati18800 = (ati18800_t *)priv; svga_t *svga = &ati18800->svga; uint8_t temp; @@ -204,7 +204,7 @@ static void ati18800_recalctimings(svga_t *svga) } -static void * +static priv_t ati18800_init(const device_t *info, UNUSED(void *parent)) { ati18800_t *dev; @@ -212,34 +212,18 @@ ati18800_init(const device_t *info, UNUSED(void *parent)) dev = (ati18800_t *)mem_alloc(sizeof(ati18800_t)); memset(dev, 0x00, sizeof(ati18800_t)); - switch (info->local) { -#if defined(DEV_BRANCH) && defined(USE_WONDER) - case ATI18800_WONDER: - break; -#endif - - case ATI18800_VGA88: - break; - - case ATI18800_EDGE16: - break; - - default: - break; - }; - if (info->path != NULL) { rom_init(&dev->bios_rom, info->path, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); } - svga_init(&dev->svga, dev, 1 << 20, /*512KB*/ + svga_init(&dev->svga, (priv_t)dev, 1 << 20, /*512KB*/ ati18800_recalctimings, ati18800_in, ati18800_out, NULL, NULL); io_sethandler(0x01ce, 0x0002, - ati18800_in,NULL,NULL, ati18800_out,NULL,NULL, dev); + ati18800_in,NULL,NULL, ati18800_out,NULL,NULL, (priv_t)dev); io_sethandler(0x03c0, 0x0020, - ati18800_in,NULL,NULL, ati18800_out,NULL,NULL, dev); + ati18800_in,NULL,NULL, ati18800_out,NULL,NULL, (priv_t)dev); dev->svga.miscout = 1; @@ -248,12 +232,12 @@ ati18800_init(const device_t *info, UNUSED(void *parent)) video_inform(DEVICE_VIDEO_GET(info->flags), (const video_timings_t *)info->vid_timing); - return dev; + return (priv_t)dev; } static void -ati18800_close(void *priv) +ati18800_close(priv_t priv) { ati18800_t *dev = (ati18800_t *)priv; @@ -262,7 +246,7 @@ ati18800_close(void *priv) static void -speed_changed(void *priv) +speed_changed(priv_t priv) { ati18800_t *dev = (ati18800_t *)priv; @@ -271,7 +255,7 @@ speed_changed(void *priv) static void -force_redraw(void *priv) +force_redraw(priv_t priv) { ati18800_t *dev = (ati18800_t *)priv; diff --git a/src/devices/video/vid_ati28800.c b/src/devices/video/vid_ati28800.c index 3025283..94df5b7 100644 --- a/src/devices/video/vid_ati28800.c +++ b/src/devices/video/vid_ati28800.c @@ -8,7 +8,7 @@ * * ATI 28800 emulation (VGA Charger and Korean VGA) * - * Version: @(#)vid_ati28800.c 1.0.21 2019/05/05 + * Version: @(#)vid_ati28800.c 1.0.22 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -102,7 +102,7 @@ typedef struct { static void -ati28800_out(uint16_t port, uint8_t val, void *priv) +ati28800_out(uint16_t port, uint8_t val, priv_t priv) { ati28800_t *dev = (ati28800_t *)priv; svga_t *svga = &dev->svga; @@ -187,7 +187,7 @@ ati28800_out(uint16_t port, uint8_t val, void *priv) static void -ati28800k_out(uint16_t port, uint8_t val, void *priv) +ati28800k_out(uint16_t port, uint8_t val, priv_t priv) { ati28800_t *dev = (ati28800_t *)priv; svga_t *svga = &dev->svga; @@ -250,7 +250,7 @@ ati28800k_out(uint16_t port, uint8_t val, void *priv) static uint8_t -ati28800_in(uint16_t port, void *priv) +ati28800_in(uint16_t port, priv_t priv) { ati28800_t *dev = (ati28800_t *)priv; svga_t *svga = &dev->svga; @@ -323,7 +323,7 @@ ati28800_in(uint16_t port, void *priv) static uint8_t -ati28800k_in(uint16_t port, void *priv) +ati28800k_in(uint16_t port, priv_t priv) { ati28800_t *dev = (ati28800_t *)priv; svga_t *svga = &dev->svga; @@ -482,7 +482,7 @@ ati28800k_load_font(svga_t *svga, const wchar_t *fn) } -static void * +static priv_t ati28800_init(const device_t *info, UNUSED(void *parent)) { ati28800_t *dev; @@ -542,7 +542,7 @@ ati28800_init(const device_t *info, UNUSED(void *parent)) } if (info->local == VID_ATIKOREANVGA) { - svga_init(&dev->svga, dev, dev->memory << 10, /*default: 512KB*/ + svga_init(&dev->svga, (priv_t)dev, dev->memory << 10, /*default: 512KB*/ ati28800k_recalctimings, ati28800k_in, ati28800k_out, NULL, NULL); dev->svga.ksc5601_sbyte_mask = 0; @@ -550,21 +550,21 @@ ati28800_init(const device_t *info, UNUSED(void *parent)) dev->svga.ramdac = device_add(&sc1502x_ramdac_device); io_sethandler(0x01ce, 2, - ati28800k_in,NULL,NULL, ati28800k_out,NULL,NULL, dev); + ati28800k_in,NULL,NULL, ati28800k_out,NULL,NULL, (priv_t)dev); io_sethandler(0x03c0, 32, - ati28800k_in,NULL,NULL, ati28800k_out,NULL,NULL, dev); + ati28800k_in,NULL,NULL, ati28800k_out,NULL,NULL, (priv_t)dev); } else { - svga_init(&dev->svga, dev, dev->memory << 10, /*default: 512kb*/ + svga_init(&dev->svga, (priv_t)dev, dev->memory << 10, /*default: 512kb*/ ati28800_recalctimings, ati28800_in, ati28800_out, NULL, NULL); dev->svga.ramdac = device_add(&sc1502x_ramdac_device); io_sethandler(0x01ce, 2, - ati28800_in,NULL,NULL, ati28800_out,NULL,NULL, dev); + ati28800_in,NULL,NULL, ati28800_out,NULL,NULL, (priv_t)dev); io_sethandler(0x03c0, 32, - ati28800_in,NULL,NULL, ati28800_out,NULL,NULL, dev); + ati28800_in,NULL,NULL, ati28800_out,NULL,NULL, (priv_t)dev); } dev->svga.miscout = 1; @@ -580,12 +580,12 @@ ati28800_init(const device_t *info, UNUSED(void *parent)) video_inform(DEVICE_VIDEO_GET(info->flags), (const video_timings_t *)info->vid_timing); - return(dev); + return((priv_t)dev); } static void -ati28800_close(void *priv) +ati28800_close(priv_t priv) { ati28800_t *dev = (ati28800_t *)priv; @@ -620,7 +620,7 @@ ati28800_wonderxl24_available(void) static void -speed_changed(void *priv) +speed_changed(priv_t priv) { ati28800_t *dev = (ati28800_t *)priv; @@ -629,7 +629,7 @@ speed_changed(void *priv) static void -force_redraw(void *priv) +force_redraw(priv_t priv) { ati28800_t *dev = (ati28800_t *)priv; diff --git a/src/devices/video/vid_ati_mach64.c b/src/devices/video/vid_ati_mach64.c index 9fd8493..da4f470 100644 --- a/src/devices/video/vid_ati_mach64.c +++ b/src/devices/video/vid_ati_mach64.c @@ -8,7 +8,7 @@ * * ATi Mach64 graphics card emulation. * - * Version: @(#)vid_ati_mach64.c 1.0.19 2019/05/03 + * Version: @(#)vid_ati_mach64.c 1.0.20 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -339,12 +339,12 @@ enum HOST_BYTE_ALIGN = (1 << 0) }; -void mach64_write(uint32_t addr, uint8_t val, void *priv); -void mach64_writew(uint32_t addr, uint16_t val, void *priv); -void mach64_writel(uint32_t addr, uint32_t val, void *priv); -uint8_t mach64_read(uint32_t addr, void *priv); -uint16_t mach64_readw(uint32_t addr, void *priv); -uint32_t mach64_readl(uint32_t addr, void *priv); +void mach64_write(uint32_t addr, uint8_t val, priv_t); +void mach64_writew(uint32_t addr, uint16_t val, priv_t); +void mach64_writel(uint32_t addr, uint32_t val, priv_t); +uint8_t mach64_read(uint32_t addr, priv_t); +uint16_t mach64_readw(uint32_t addr, priv_t); +uint32_t mach64_readl(uint32_t addr, priv_t); void mach64_updatemapping(mach64_t *mach64); void mach64_recalctimings(svga_t *svga); void mach64_start_fill(mach64_t *mach64); @@ -352,16 +352,16 @@ void mach64_start_line(mach64_t *mach64); void mach64_blit(uint32_t cpu_dat, int count, mach64_t *mach64); void mach64_load_context(mach64_t *mach64); -uint8_t mach64_ext_readb(uint32_t addr, void *priv); -uint16_t mach64_ext_readw(uint32_t addr, void *priv); -uint32_t mach64_ext_readl(uint32_t addr, void *priv); -void mach64_ext_writeb(uint32_t addr, uint8_t val, void *priv); -void mach64_ext_writew(uint32_t addr, uint16_t val, void *priv); -void mach64_ext_writel(uint32_t addr, uint32_t val, void *priv); +uint8_t mach64_ext_readb(uint32_t addr, priv_t); +uint16_t mach64_ext_readw(uint32_t addr, priv_t); +uint32_t mach64_ext_readl(uint32_t addr, priv_t); +void mach64_ext_writeb(uint32_t addr, uint8_t val, priv_t); +void mach64_ext_writew(uint32_t addr, uint16_t val, priv_t); +void mach64_ext_writel(uint32_t addr, uint32_t val, priv_t); -void mach64_out(uint16_t addr, uint8_t val, void *p) +void mach64_out(uint16_t addr, uint8_t val, priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; svga_t *svga = &mach64->svga; uint8_t old; @@ -423,9 +423,9 @@ void mach64_out(uint16_t addr, uint8_t val, void *p) svga_out(addr, val, svga); } -uint8_t mach64_in(uint16_t addr, void *p) +uint8_t mach64_in(uint16_t addr, priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; svga_t *svga = &mach64->svga; if (((addr&0xFFF0) == 0x3D0 || (addr&0xFFF0) == 0x3B0) && !(svga->miscout&1)) @@ -1700,9 +1700,9 @@ static void mach64_vblank_start(svga_t *svga) mach64->scaler_update = 1; } -uint8_t mach64_ext_readb(uint32_t addr, void *p) +uint8_t mach64_ext_readb(uint32_t addr, priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; ati68860_ramdac_t *ramdac = (ati68860_ramdac_t *) mach64->svga.ramdac; uint8_t ret; @@ -2073,7 +2073,7 @@ uint8_t mach64_ext_readb(uint32_t addr, void *p) DEBUG("mach64_ext_readb : addr %08X ret %02X\n", addr, ret); return ret; } -uint16_t mach64_ext_readw(uint32_t addr, void *p) +uint16_t mach64_ext_readw(uint32_t addr, priv_t priv) { uint16_t ret; if (!(addr & 0x400)) @@ -2085,18 +2085,18 @@ uint16_t mach64_ext_readw(uint32_t addr, void *p) { default: DEBUG(" "); - ret = mach64_ext_readb(addr, p); + ret = mach64_ext_readb(addr, priv); DEBUG(" "); - ret |= mach64_ext_readb(addr + 1, p) << 8; + ret |= mach64_ext_readb(addr + 1, priv) << 8; break; } if ((addr & 0x3fc) != 0x018) DEBUG("mach64_ext_readw : addr %08X ret %04X\n", addr, ret); return ret; } -uint32_t mach64_ext_readl(uint32_t addr, void *p) +uint32_t mach64_ext_readl(uint32_t addr, priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; uint32_t ret; if (!(addr & 0x400)) { @@ -2120,9 +2120,9 @@ uint32_t mach64_ext_readl(uint32_t addr, void *p) default: DEBUG(" "); - ret = mach64_ext_readw(addr, p); + ret = mach64_ext_readw(addr, priv); DEBUG(" "); - ret |= mach64_ext_readw(addr + 2, p) << 16; + ret |= mach64_ext_readw(addr + 2, priv) << 16; break; } if ((addr & 0x3fc) != 0x018) @@ -2130,9 +2130,9 @@ uint32_t mach64_ext_readl(uint32_t addr, void *p) return ret; } -void mach64_ext_writeb(uint32_t addr, uint8_t val, void *p) +void mach64_ext_writeb(uint32_t addr, uint8_t val, priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; svga_t *svga = &mach64->svga; ati68860_ramdac_t *ramdac = (ati68860_ramdac_t *) svga->ramdac; ics2595_t *clock_gen = (ics2595_t *) svga->clock_gen; @@ -2347,15 +2347,15 @@ void mach64_ext_writeb(uint32_t addr, uint8_t val, void *p) break; } } -void mach64_ext_writew(uint32_t addr, uint16_t val, void *p) +void mach64_ext_writew(uint32_t addr, uint16_t val, priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; DEBUG("mach64_ext_writew : addr %08X val %04X\n", addr, val); if (!(addr & 0x400)) { DEBUG("nmach64_ext_writew: addr=%04x val=%04x\n", addr, val); - mach64_ext_writeb(addr, val & 0xff, p); - mach64_ext_writeb(addr + 1, val >> 8, p); + mach64_ext_writeb(addr, val & 0xff, priv); + mach64_ext_writeb(addr + 1, val >> 8, priv); } else if (addr & 0x300) { @@ -2365,15 +2365,15 @@ void mach64_ext_writew(uint32_t addr, uint16_t val, void *p) { default: DEBUG(" "); - mach64_ext_writeb(addr, val & 0xff, p); + mach64_ext_writeb(addr, val & 0xff, priv); DEBUG(" "); - mach64_ext_writeb(addr + 1, val >> 8, p); + mach64_ext_writeb(addr + 1, val >> 8, priv); break; } } -void mach64_ext_writel(uint32_t addr, uint32_t val, void *p) +void mach64_ext_writel(uint32_t addr, uint32_t val, priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; if ((addr & 0x3c0) != 0x200) DEBUG("mach64_ext_writel : addr %08X val %08X\n", addr, val); @@ -2382,8 +2382,8 @@ void mach64_ext_writel(uint32_t addr, uint32_t val, void *p) { DEBUG("nmach64_ext_writel: addr=%04x val=%08x\n", addr, val); - mach64_ext_writew(addr, val, p); - mach64_ext_writew(addr + 2, val >> 16, p); + mach64_ext_writew(addr, val, priv); + mach64_ext_writew(addr + 2, val >> 16, priv); } else if (addr & 0x300) { @@ -2393,16 +2393,16 @@ void mach64_ext_writel(uint32_t addr, uint32_t val, void *p) { default: DEBUG(" "); - mach64_ext_writew(addr, val, p); + mach64_ext_writew(addr, val, priv); DEBUG(" "); - mach64_ext_writew(addr + 2, val >> 16, p); + mach64_ext_writew(addr + 2, val >> 16, priv); break; } } -uint8_t mach64_ext_inb(uint16_t port, void *p) +uint8_t mach64_ext_inb(uint16_t port, priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; ati68860_ramdac_t *ramdac = (ati68860_ramdac_t *) mach64->svga.ramdac; uint8_t ret; @@ -2410,82 +2410,82 @@ uint8_t mach64_ext_inb(uint16_t port, void *p) { case 0x02ec: case 0x02ed: case 0x02ee: case 0x02ef: case 0x7eec: case 0x7eed: case 0x7eee: case 0x7eef: - ret = mach64_ext_readb(0x400 | 0x00 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x00 | (port & 3), priv); break; case 0x0aec: case 0x0aed: case 0x0aee: case 0x0aef: - ret = mach64_ext_readb(0x400 | 0x08 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x08 | (port & 3), priv); break; case 0x0eec: case 0x0eed: case 0x0eee: case 0x0eef: - ret = mach64_ext_readb(0x400 | 0x0c | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x0c | (port & 3), priv); break; case 0x12ec: case 0x12ed: case 0x12ee: case 0x12ef: - ret = mach64_ext_readb(0x400 | 0x10 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x10 | (port & 3), priv); break; case 0x16ec: case 0x16ed: case 0x16ee: case 0x16ef: - ret = mach64_ext_readb(0x400 | 0x14 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x14 | (port & 3), priv); break; case 0x1aec: - ret = mach64_ext_readb(0x400 | 0x18, p); + ret = mach64_ext_readb(0x400 | 0x18, priv); break; case 0x1eec: case 0x1eed: case 0x1eee: case 0x1eef: - ret = mach64_ext_readb(0x400 | 0x1c | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x1c | (port & 3), priv); break; case 0x22ec: case 0x22ed: case 0x22ee: case 0x22ef: - ret = mach64_ext_readb(0x400 | 0x40 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x40 | (port & 3), priv); break; case 0x26ec: case 0x26ed: case 0x26ee: case 0x26ef: - ret = mach64_ext_readb(0x400 | 0x44 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x44 | (port & 3), priv); break; case 0x2aec: case 0x2aed: case 0x2aee: case 0x2aef: - ret = mach64_ext_readb(0x400 | 0x48 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x48 | (port & 3), priv); break; case 0x2eec: case 0x2eed: case 0x2eee: case 0x2eef: - ret = mach64_ext_readb(0x400 | 0x60 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x60 | (port & 3), priv); break; case 0x32ec: case 0x32ed: case 0x32ee: case 0x32ef: - ret = mach64_ext_readb(0x400 | 0x64 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x64 | (port & 3), priv); break; case 0x36ec: case 0x36ed: case 0x36ee: case 0x36ef: - ret = mach64_ext_readb(0x400 | 0x68 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x68 | (port & 3), priv); break; case 0x3aec: case 0x3aed: case 0x3aee: case 0x3aef: - ret = mach64_ext_readb(0x400 | 0x6c | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x6c | (port & 3), priv); break; case 0x3eec: case 0x3eed: case 0x3eee: case 0x3eef: - ret = mach64_ext_readb(0x400 | 0x70 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x70 | (port & 3), priv); break; case 0x42ec: case 0x42ed: case 0x42ee: case 0x42ef: - ret = mach64_ext_readb(0x400 | 0x80 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x80 | (port & 3), priv); break; case 0x46ec: case 0x46ed: case 0x46ee: case 0x46ef: - ret = mach64_ext_readb(0x400 | 0x84 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x84 | (port & 3), priv); break; case 0x4aec: case 0x4aed: case 0x4aee: case 0x4aef: - ret = mach64_ext_readb(0x400 | 0x90 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0x90 | (port & 3), priv); break; case 0x52ec: case 0x52ed: case 0x52ee: case 0x52ef: - ret = mach64_ext_readb(0x400 | 0xb0 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0xb0 | (port & 3), priv); break; case 0x56ec: - ret = mach64_ext_readb(0x400 | 0xb4, p); + ret = mach64_ext_readb(0x400 | 0xb4, priv); break; case 0x56ed: case 0x56ee: - ret = mach64_ext_readb(0x400 | 0xb5, p); + ret = mach64_ext_readb(0x400 | 0xb5, priv); break; case 0x5aec: - ret = mach64_ext_readb(0x400 | 0xb8, p); + ret = mach64_ext_readb(0x400 | 0xb8, priv); break; case 0x5aed: case 0x5aee: - ret = mach64_ext_readb(0x400 | 0xb9, p); + ret = mach64_ext_readb(0x400 | 0xb9, priv); break; case 0x5eec: case 0x5eed: case 0x5eee: case 0x5eef: @@ -2496,11 +2496,11 @@ uint8_t mach64_ext_inb(uint16_t port, void *p) break; case 0x62ec: case 0x62ed: case 0x62ee: case 0x62ef: - ret = mach64_ext_readb(0x400 | 0xc4 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0xc4 | (port & 3), priv); break; case 0x66ec: case 0x66ed: case 0x66ee: case 0x66ef: - ret = mach64_ext_readb(0x400 | 0xd0 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0xd0 | (port & 3), priv); break; case 0x6aec: case 0x6aed: case 0x6aee: case 0x6aef: @@ -2509,11 +2509,11 @@ uint8_t mach64_ext_inb(uint16_t port, void *p) break; case 0x6eec: case 0x6eed: case 0x6eee: case 0x6eef: - ret = mach64_ext_readb(0x400 | 0xe0 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0xe0 | (port & 3), priv); break; case 0x72ec: case 0x72ed: case 0x72ee: case 0x72ef: - ret = mach64_ext_readb(0x400 | 0xe4 | (port & 3), p); + ret = mach64_ext_readb(0x400 | 0xe4 | (port & 3), priv); break; default: @@ -2523,47 +2523,47 @@ uint8_t mach64_ext_inb(uint16_t port, void *p) DEBUG("mach64_ext_inb : port %04X ret %02X\n", port, ret); return ret; } -uint16_t mach64_ext_inw(uint16_t port, void *p) +uint16_t mach64_ext_inw(uint16_t port, priv_t priv) { uint16_t ret; switch (port) { default: DEBUG(" "); - ret = mach64_ext_inb(port, p); + ret = mach64_ext_inb(port, priv); DEBUG(" "); - ret |= (mach64_ext_inb(port + 1, p) << 8); + ret |= (mach64_ext_inb(port + 1, priv) << 8); break; } DEBUG("mach64_ext_inw : port %04X ret %04X\n", port, ret); return ret; } -uint32_t mach64_ext_inl(uint16_t port, void *p) +uint32_t mach64_ext_inl(uint16_t port, priv_t priv) { uint32_t ret; switch (port) { case 0x56ec: - ret = mach64_ext_readl(0x400 | 0xb4, p); + ret = mach64_ext_readl(0x400 | 0xb4, priv); break; case 0x5aec: - ret = mach64_ext_readl(0x400 | 0xb8, p); + ret = mach64_ext_readl(0x400 | 0xb8, priv); break; default: DEBUG(" "); - ret = mach64_ext_inw(port, p); + ret = mach64_ext_inw(port, priv); DEBUG(" "); - ret |= (mach64_ext_inw(port + 2, p) << 16); + ret |= (mach64_ext_inw(port + 2, priv) << 16); break; } DEBUG("mach64_ext_inl : port %04X ret %08X\n", port, ret); return ret; } -void mach64_ext_outb(uint16_t port, uint8_t val, void *p) +void mach64_ext_outb(uint16_t port, uint8_t val, priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; ati68860_ramdac_t *ramdac = (ati68860_ramdac_t *) mach64->svga.ramdac; DEBUG("mach64_ext_outb : port %04X val %02X\n", port, val); @@ -2572,78 +2572,78 @@ void mach64_ext_outb(uint16_t port, uint8_t val, void *p) { case 0x02ec: case 0x02ed: case 0x02ee: case 0x02ef: case 0x7eec: case 0x7eed: case 0x7eee: case 0x7eef: - mach64_ext_writeb(0x400 | 0x00 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x00 | (port & 3), val, priv); break; case 0x0aec: case 0x0aed: case 0x0aee: case 0x0aef: - mach64_ext_writeb(0x400 | 0x08 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x08 | (port & 3), val, priv); break; case 0x0eec: case 0x0eed: case 0x0eee: case 0x0eef: - mach64_ext_writeb(0x400 | 0x0c | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x0c | (port & 3), val, priv); break; case 0x16ec: case 0x16ed: case 0x16ee: case 0x16ef: - mach64_ext_writeb(0x400 | 0x14 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x14 | (port & 3), val, priv); break; case 0x1aec: - mach64_ext_writeb(0x400 | 0x18, val, p); + mach64_ext_writeb(0x400 | 0x18, val, priv); break; case 0x1eec: case 0x1eed: case 0x1eee: case 0x1eef: - mach64_ext_writeb(0x400 | 0x1c | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x1c | (port & 3), val, priv); break; case 0x22ec: case 0x22ed: case 0x22ee: case 0x22ef: - mach64_ext_writeb(0x400 | 0x40 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x40 | (port & 3), val, priv); break; case 0x26ec: case 0x26ed: case 0x26ee: case 0x26ef: - mach64_ext_writeb(0x400 | 0x44 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x44 | (port & 3), val, priv); break; case 0x2aec: case 0x2aed: case 0x2aee: case 0x2aef: - mach64_ext_writeb(0x400 | 0x48 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x48 | (port & 3), val, priv); break; case 0x2eec: case 0x2eed: case 0x2eee: case 0x2eef: - mach64_ext_writeb(0x400 | 0x60 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x60 | (port & 3), val, priv); break; case 0x32ec: case 0x32ed: case 0x32ee: case 0x32ef: - mach64_ext_writeb(0x400 | 0x64 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x64 | (port & 3), val, priv); break; case 0x36ec: case 0x36ed: case 0x36ee: case 0x36ef: - mach64_ext_writeb(0x400 | 0x68 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x68 | (port & 3), val, priv); break; case 0x3aec: case 0x3aed: case 0x3aee: case 0x3aef: - mach64_ext_writeb(0x400 | 0x6c | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x6c | (port & 3), val, priv); break; case 0x3eec: case 0x3eed: case 0x3eee: case 0x3eef: - mach64_ext_writeb(0x400 | 0x70 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x70 | (port & 3), val, priv); break; case 0x42ec: case 0x42ed: case 0x42ee: case 0x42ef: - mach64_ext_writeb(0x400 | 0x80 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x80 | (port & 3), val, priv); break; case 0x46ec: case 0x46ed: case 0x46ee: case 0x46ef: - mach64_ext_writeb(0x400 | 0x84 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x84 | (port & 3), val, priv); break; case 0x4aec: case 0x4aed: case 0x4aee: case 0x4aef: - mach64_ext_writeb(0x400 | 0x90 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0x90 | (port & 3), val, priv); break; case 0x52ec: case 0x52ed: case 0x52ee: case 0x52ef: - mach64_ext_writeb(0x400 | 0xb0 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0xb0 | (port & 3), val, priv); break; case 0x56ec: - mach64_ext_writeb(0x400 | 0xb4, val, p); + mach64_ext_writeb(0x400 | 0xb4, val, priv); break; case 0x56ed: case 0x56ee: - mach64_ext_writeb(0x400 | 0xb5, val, p); + mach64_ext_writeb(0x400 | 0xb5, val, priv); break; case 0x5aec: - mach64_ext_writeb(0x400 | 0xb8, val, p); + mach64_ext_writeb(0x400 | 0xb8, val, priv); break; case 0x5aed: case 0x5aee: - mach64_ext_writeb(0x400 | 0xb9, val, p); + mach64_ext_writeb(0x400 | 0xb9, val, priv); break; case 0x5eec: case 0x5eed: case 0x5eee: case 0x5eef: @@ -2654,11 +2654,11 @@ void mach64_ext_outb(uint16_t port, uint8_t val, void *p) break; case 0x62ec: case 0x62ed: case 0x62ee: case 0x62ef: - mach64_ext_writeb(0x400 | 0xc4 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0xc4 | (port & 3), val, priv); break; case 0x66ec: case 0x66ed: case 0x66ee: case 0x66ef: - mach64_ext_writeb(0x400 | 0xd0 | (port & 3), val, p); + mach64_ext_writeb(0x400 | 0xd0 | (port & 3), val, priv); break; case 0x6aec: case 0x6aed: case 0x6aee: case 0x6aef: @@ -2667,7 +2667,7 @@ void mach64_ext_outb(uint16_t port, uint8_t val, void *p) break; } } -void mach64_ext_outw(uint16_t port, uint16_t val, void *p) +void mach64_ext_outw(uint16_t port, uint16_t val, priv_t priv) { DEBUG("mach64_ext_outw : port %04X val %04X\n", port, val); @@ -2675,47 +2675,47 @@ void mach64_ext_outw(uint16_t port, uint16_t val, void *p) { default: DEBUG(" "); - mach64_ext_outb(port, val & 0xff, p); + mach64_ext_outb(port, val & 0xff, priv); DEBUG(" "); - mach64_ext_outb(port + 1, val >> 8, p); + mach64_ext_outb(port + 1, val >> 8, priv); break; } } -void mach64_ext_outl(uint16_t port, uint32_t val, void *p) +void mach64_ext_outl(uint16_t port, uint32_t val, priv_t priv) { /* DEBUG("mach64_ext_outl : port %04X val %08X\n", port, val); */ switch (port) { default: DEBUG(" "); - mach64_ext_outw(port, val, p); + mach64_ext_outw(port, val, priv); DEBUG(" "); - mach64_ext_outw(port + 2, val >> 16, p); + mach64_ext_outw(port + 2, val >> 16, priv); break; } } -static uint8_t mach64_block_inb(uint16_t port, void *p) +static uint8_t mach64_block_inb(uint16_t port, priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; uint8_t ret; ret = mach64_ext_readb(0x400 | (port & 0x3ff), mach64); DEBUG("mach64_block_inb : port %04X ret %02X\n", port, ret); return ret; } -static uint16_t mach64_block_inw(uint16_t port, void *p) +static uint16_t mach64_block_inw(uint16_t port, priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; uint16_t ret; ret = mach64_ext_readw(0x400 | (port & 0x3ff), mach64); DEBUG("mach64_block_inw : port %04X ret %04X\n", port, ret); return ret; } -static uint32_t mach64_block_inl(uint16_t port, void *p) +static uint32_t mach64_block_inl(uint16_t port, priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; uint32_t ret; ret = mach64_ext_readl(0x400 | (port & 0x3ff), mach64); @@ -2723,72 +2723,72 @@ static uint32_t mach64_block_inl(uint16_t port, void *p) return ret; } -static void mach64_block_outb(uint16_t port, uint8_t val, void *p) +static void mach64_block_outb(uint16_t port, uint8_t val, priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; DEBUG("mach64_block_outb : port %04X val %02X\n ", port, val); mach64_ext_writeb(0x400 | (port & 0x3ff), val, mach64); } -static void mach64_block_outw(uint16_t port, uint16_t val, void *p) +static void mach64_block_outw(uint16_t port, uint16_t val, priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; DEBUG("mach64_block_outw : port %04X val %04X\n ", port, val); mach64_ext_writew(0x400 | (port & 0x3ff), val, mach64); } -static void mach64_block_outl(uint16_t port, uint32_t val, void *p) +static void mach64_block_outl(uint16_t port, uint32_t val, priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; DEBUG("mach64_block_outl : port %04X val %08X\n ", port, val); mach64_ext_writel(0x400 | (port & 0x3ff), val, mach64); } -void mach64_write(uint32_t addr, uint8_t val, void *p) +void mach64_write(uint32_t addr, uint8_t val, priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; svga_t *svga = &mach64->svga; addr = (addr & 0x7fff) + mach64->bank_w[(addr >> 15) & 1]; svga_write_linear(addr, val, svga); } -void mach64_writew(uint32_t addr, uint16_t val, void *p) +void mach64_writew(uint32_t addr, uint16_t val, priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; svga_t *svga = &mach64->svga; addr = (addr & 0x7fff) + mach64->bank_w[(addr >> 15) & 1]; svga_writew_linear(addr, val, svga); } -void mach64_writel(uint32_t addr, uint32_t val, void *p) +void mach64_writel(uint32_t addr, uint32_t val, priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; svga_t *svga = &mach64->svga; addr = (addr & 0x7fff) + mach64->bank_w[(addr >> 15) & 1]; svga_writel_linear(addr, val, svga); } -uint8_t mach64_read(uint32_t addr, void *p) +uint8_t mach64_read(uint32_t addr, priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; svga_t *svga = &mach64->svga; uint8_t ret; addr = (addr & 0x7fff) + mach64->bank_r[(addr >> 15) & 1]; ret = svga_read_linear(addr, svga); return ret; } -uint16_t mach64_readw(uint32_t addr, void *p) +uint16_t mach64_readw(uint32_t addr, priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; svga_t *svga = &mach64->svga; addr = (addr & 0x7fff) + mach64->bank_r[(addr >> 15) & 1]; return svga_readw_linear(addr, svga); } -uint32_t mach64_readl(uint32_t addr, void *p) +uint32_t mach64_readl(uint32_t addr, priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; svga_t *svga = &mach64->svga; addr = (addr & 0x7fff) + mach64->bank_r[(addr >> 15) & 1]; @@ -3155,9 +3155,9 @@ static void mach64_io_set(mach64_t *mach64) io_sethandler(mach64->block_decoded_io, 0x0400, mach64_block_inb, mach64_block_inw, mach64_block_inl, mach64_block_outb, mach64_block_outw, mach64_block_outl, mach64); } -uint8_t mach64_pci_read(int func, int addr, void *p) +uint8_t mach64_pci_read(int func, int addr, priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; switch (addr) { @@ -3217,9 +3217,9 @@ uint8_t mach64_pci_read(int func, int addr, void *p) return 0; } -void mach64_pci_write(int func, int addr, uint8_t val, void *p) +void mach64_pci_write(int func, int addr, uint8_t val, priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; switch (addr) { @@ -3306,7 +3306,7 @@ void mach64_pci_write(int func, int addr, uint8_t val, void *p) } -static void * +static priv_t mach64_common_init(const device_t *info) { mach64_t *mach64 = (mach64_t *)mem_alloc(sizeof(mach64_t)); @@ -3354,11 +3354,11 @@ mach64_common_init(const device_t *info) video_inform(DEVICE_VIDEO_GET(info->flags), (const video_timings_t *)info->vid_timing); - return mach64; + return (priv_t)mach64; } -static void * +static priv_t mach64gx_init(const device_t *info, UNUSED(void *parent)) { mach64_t *mach64 = (mach64_t *)mach64_common_init(info); @@ -3383,11 +3383,11 @@ mach64gx_init(const device_t *info, UNUSED(void *parent)) else if (info->flags & DEVICE_ISA) rom_init(&mach64->bios_rom, info->path, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); - return mach64; + return (priv_t)mach64; } -static void * +static priv_t mach64vt2_init(const device_t *info, UNUSED(void *parent)) { mach64_t *mach64 = (mach64_t *)mach64_common_init(info); @@ -3407,14 +3407,14 @@ mach64vt2_init(const device_t *info, UNUSED(void *parent)) svga->vblank_start = mach64_vblank_start; - return mach64; + return (priv_t)mach64; } static void -mach64_close(void *p) +mach64_close(priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; svga_close(&mach64->svga); @@ -3427,18 +3427,18 @@ mach64_close(void *p) static void -mach64_speed_changed(void *p) +mach64_speed_changed(priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; svga_recalctimings(&mach64->svga); } static void -mach64_force_redraw(void *p) +mach64_force_redraw(priv_t priv) { - mach64_t *mach64 = (mach64_t *)p; + mach64_t *mach64 = (mach64_t *)priv; mach64->svga.fullchange = changeframecount; } diff --git a/src/devices/video/vid_cga.c b/src/devices/video/vid_cga.c index 9308e57..d834147 100644 --- a/src/devices/video/vid_cga.c +++ b/src/devices/video/vid_cga.c @@ -8,7 +8,7 @@ * * Emulation of the old and new IBM CGA graphics cards. * - * Version: @(#)vid_cga.c 1.0.18 2019/05/05 + * Version: @(#)vid_cga.c 1.0.19 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -146,7 +146,7 @@ cga_recalctimings(cga_t *dev) void -cga_out(uint16_t port, uint8_t val, void *priv) +cga_out(uint16_t port, uint8_t val, priv_t priv) { cga_t *dev = (cga_t *)priv; uint8_t old; @@ -188,7 +188,7 @@ cga_out(uint16_t port, uint8_t val, void *priv) uint8_t -cga_in(uint16_t port, void *priv) +cga_in(uint16_t port, priv_t priv) { cga_t *dev = (cga_t *)priv; uint8_t ret = 0xff; @@ -215,7 +215,7 @@ cga_in(uint16_t port, void *priv) void -cga_waitstates(void *priv) +cga_waitstates(priv_t priv) { int ws; @@ -225,7 +225,7 @@ cga_waitstates(void *priv) void -cga_write(uint32_t addr, uint8_t val, void *priv) +cga_write(uint32_t addr, uint8_t val, priv_t priv) { cga_t *dev = (cga_t *)priv; @@ -241,7 +241,7 @@ cga_write(uint32_t addr, uint8_t val, void *priv) uint8_t -cga_read(uint32_t addr, void *priv) +cga_read(uint32_t addr, priv_t priv) { cga_t *dev = (cga_t *)priv; @@ -270,7 +270,7 @@ cga_hline(bitmap_t *b, int x1, int y, int x2, uint8_t col) void -cga_poll(void *priv) +cga_poll(priv_t priv) { cga_t *dev = (cga_t *)priv; uint16_t ca = (dev->crtc[15] | (dev->crtc[14] << 8)) & 0x3fff; @@ -617,7 +617,7 @@ cga_init(cga_t *dev) void -cga_close(void *priv) +cga_close(priv_t priv) { cga_t *dev = (cga_t *)priv; @@ -631,7 +631,7 @@ cga_close(void *priv) void -cga_speed_changed(void *priv) +cga_speed_changed(priv_t priv) { cga_t *dev = (cga_t *)priv; @@ -639,7 +639,7 @@ cga_speed_changed(void *priv) } -static void * +static priv_t cga_standalone_init(const device_t *info, UNUSED(void *parent)) { int display_type; @@ -662,14 +662,14 @@ cga_standalone_init(const device_t *info, UNUSED(void *parent)) if (dev->composite) dev->cpriv = cga_comp_init(dev->revision); - timer_add(cga_poll, dev, &dev->vidtime, TIMER_ALWAYS_ENABLED); + timer_add(cga_poll, (priv_t)dev, &dev->vidtime, TIMER_ALWAYS_ENABLED); mem_map_add(&dev->mapping, 0xb8000, 0x08000, cga_read,NULL,NULL, cga_write,NULL,NULL, - dev->vram, MEM_MAPPING_EXTERNAL, dev); + dev->vram, MEM_MAPPING_EXTERNAL, (priv_t)dev); io_sethandler(0x03d0, 16, - cga_in,NULL,NULL, cga_out,NULL,NULL, dev); + cga_in,NULL,NULL, cga_out,NULL,NULL, (priv_t)dev); overscan_x = overscan_y = 16; @@ -682,7 +682,7 @@ cga_standalone_init(const device_t *info, UNUSED(void *parent)) video_inform(DEVICE_VIDEO_GET(info->flags), (const video_timings_t *)info->vid_timing); - return(dev); + return((priv_t)dev); } diff --git a/src/devices/video/vid_cga.h b/src/devices/video/vid_cga.h index f313fbe..d11785d 100644 --- a/src/devices/video/vid_cga.h +++ b/src/devices/video/vid_cga.h @@ -8,7 +8,7 @@ * * Definitions for the CGA driver. * - * Version: @(#)vid_cga.h 1.0.8 2019/03/08 + * Version: @(#)vid_cga.h 1.0.9 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -83,7 +83,7 @@ typedef struct { int font_type; int composite; - void *cpriv; + priv_t cpriv; } cga_t; @@ -93,12 +93,12 @@ extern const device_config_t cga_config[]; extern void cga_init(cga_t *cga); -extern void cga_out(uint16_t addr, uint8_t val, void *priv); -extern uint8_t cga_in(uint16_t addr, void *priv); -extern void cga_write(uint32_t addr, uint8_t val, void *priv); -extern uint8_t cga_read(uint32_t addr, void *priv); +extern void cga_out(uint16_t addr, uint8_t val, priv_t); +extern uint8_t cga_in(uint16_t addr, priv_t); +extern void cga_write(uint32_t addr, uint8_t val, priv_t); +extern uint8_t cga_read(uint32_t addr, priv_t); extern void cga_recalctimings(cga_t *cga); -extern void cga_poll(void *priv); +extern void cga_poll(priv_t); extern void cga_hline(bitmap_t *b, int x1, int y, int x2, uint8_t col); diff --git a/src/devices/video/vid_cga_comp.c b/src/devices/video/vid_cga_comp.c index b8e435f..616a777 100644 --- a/src/devices/video/vid_cga_comp.c +++ b/src/devices/video/vid_cga_comp.c @@ -15,7 +15,7 @@ * * Reworked to have its data on the heap. * - * Version: @(#)vid_cga_comp.c 1.0.7 2019/03/07 + * Version: @(#)vid_cga_comp.c 1.0.8 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -120,7 +120,7 @@ byte_clamp(int v) void -cga_comp_process(void *priv, uint8_t cgamode, uint8_t border, +cga_comp_process(priv_t priv, uint8_t cgamode, uint8_t border, uint32_t blocks/*, int8_t doublewidth*/, pel_t *pels) { cga_comp_t *state = (cga_comp_t *)priv; @@ -205,7 +205,7 @@ cga_comp_process(void *priv, uint8_t cgamode, uint8_t border, void -cga_comp_update(void *priv, uint8_t cgamode) +cga_comp_update(priv_t priv, uint8_t cgamode) { static const double ri = 0.9563; static const double rq = 0.6210; @@ -285,7 +285,7 @@ cga_comp_update(void *priv, uint8_t cgamode) } -void * +priv_t cga_comp_init(int revision) { cga_comp_t *state; @@ -300,12 +300,12 @@ cga_comp_init(int revision) cga_comp_update(state, 0); - return(state); + return((priv_t)state); } void -cga_comp_close(void *priv) +cga_comp_close(priv_t priv) { cga_comp_t *state = (cga_comp_t *)priv; @@ -315,7 +315,7 @@ cga_comp_close(void *priv) #if 0 /*NOT_USED*/ void -IncreaseHue(void *priv, uint8_t cgamode) +IncreaseHue(priv_t priv, uint8_t cgamode) { cga_comp_t *state = (cga_comp_t *)priv; @@ -326,7 +326,7 @@ IncreaseHue(void *priv, uint8_t cgamode) void -DecreaseHue(void *priv, uint8_t cgamode) +DecreaseHue(priv_t priv, uint8_t cgamode) { cga_comp_t *state = (cga_comp_t *)priv; @@ -337,7 +337,7 @@ DecreaseHue(void *priv, uint8_t cgamode) void -IncreaseSaturation(void *priv, uint8_t cgamode) +IncreaseSaturation(priv_t priv, uint8_t cgamode) { cga_comp_t *state = (cga_comp_t *)priv; @@ -348,7 +348,7 @@ IncreaseSaturation(void *priv, uint8_t cgamode) void -DecreaseSaturation(void *priv, uint8_t cgamode) +DecreaseSaturation(priv_t priv, uint8_t cgamode) { cga_comp_t *state = (cga_comp_t *)priv; @@ -359,7 +359,7 @@ DecreaseSaturation(void *priv, uint8_t cgamode) void -IncreaseContrast(void *priv, uint8_t cgamode) +IncreaseContrast(priv_t priv, uint8_t cgamode) { cga_comp_t *state = (cga_comp_t *)priv; @@ -370,7 +370,7 @@ IncreaseContrast(void *priv, uint8_t cgamode) void -DecreaseContrast(void *priv, uint8_t cgamode) +DecreaseContrast(priv_t priv, uint8_t cgamode) { cga_comp_t *state = (cga_comp_t *)priv; @@ -381,7 +381,7 @@ DecreaseContrast(void *priv, uint8_t cgamode) void -IncreaseBrightness(void *priv, uint8_t cgamode) +IncreaseBrightness(priv_t priv, uint8_t cgamode) { cga_comp_t *state = (cga_comp_t *)priv; @@ -392,7 +392,7 @@ IncreaseBrightness(void *priv, uint8_t cgamode) void -DecreaseBrightness(void *priv, uint8_t cgamode) +DecreaseBrightness(priv_t priv, uint8_t cgamode) { cga_comp_t *state = (cga_comp_t *)priv; @@ -403,7 +403,7 @@ DecreaseBrightness(void *priv, uint8_t cgamode) void -IncreaseSharpness(void *priv, uint8_t cgamode) +IncreaseSharpness(priv_t priv, uint8_t cgamode) { cga_comp_t *state = (cga_comp_t *)priv; @@ -414,7 +414,7 @@ IncreaseSharpness(void *priv, uint8_t cgamode) void -DecreaseSharpness(void *priv, uint8_t cgamode) +DecreaseSharpness(priv_t priv, uint8_t cgamode) { cga_comp_t *state = (cga_comp_t *)priv; diff --git a/src/devices/video/vid_cga_comp.h b/src/devices/video/vid_cga_comp.h index 416918c..8a02664 100644 --- a/src/devices/video/vid_cga_comp.h +++ b/src/devices/video/vid_cga_comp.h @@ -8,7 +8,7 @@ * * Definitions for the IBM CGA composite filter. * - * Version: @(#)vid_cga_comp.h 1.0.3 2019/03/07 + * Version: @(#)vid_cga_comp.h 1.0.4 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -39,11 +39,11 @@ # define VIDEO_CGA_COMP_H -extern void *cga_comp_init(int revision); -extern void cga_comp_close(void *); +extern priv_t cga_comp_init(int revision); +extern void cga_comp_close(priv_t); -extern void cga_comp_update(void *, uint8_t cgamode); -extern void cga_comp_process(void *, uint8_t cgamode, uint8_t border, +extern void cga_comp_update(priv_t, uint8_t cgamode); +extern void cga_comp_process(priv_t, uint8_t cgamode, uint8_t border, uint32_t blocks, /*int8_t doublewidth,*/ pel_t *pels); diff --git a/src/devices/video/vid_cga_compaq.c b/src/devices/video/vid_cga_compaq.c index 4e8941c..01bd8a1 100644 --- a/src/devices/video/vid_cga_compaq.c +++ b/src/devices/video/vid_cga_compaq.c @@ -8,7 +8,7 @@ * * Implementation of CGA used by Compaq PC's. * - * Version: @(#)vid_cga_compaq.c 1.0.11 2019/05/05 + * Version: @(#)vid_cga_compaq.c 1.0.12 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -84,7 +84,7 @@ recalc_timings(compaq_cga_t *dev) static void -compaq_poll(void *priv) +compaq_poll(priv_t priv) { compaq_cga_t *dev = (compaq_cga_t *)priv; uint16_t ca = (dev->cga.crtc[15] | (dev->cga.crtc[14] << 8)) & 0x3fff; @@ -360,7 +360,7 @@ compaq_poll(void *priv) } -static void * +static priv_t compaq_cga_init(const device_t *info, UNUSED(void *parent)) { compaq_cga_t *dev; @@ -379,14 +379,14 @@ compaq_cga_init(const device_t *info, UNUSED(void *parent)) dev->cga.cpriv = cga_comp_init(dev->cga.revision); - timer_add(compaq_poll, dev, &dev->cga.vidtime, TIMER_ALWAYS_ENABLED); + timer_add(compaq_poll, (priv_t)dev, &dev->cga.vidtime, TIMER_ALWAYS_ENABLED); mem_map_add(&dev->cga.mapping, 0xb8000, 0x08000, cga_read,NULL,NULL, cga_write,NULL,NULL, - dev->cga.vram, MEM_MAPPING_EXTERNAL, dev); + dev->cga.vram, MEM_MAPPING_EXTERNAL, (priv_t)dev); io_sethandler(0x03d0, 16, - cga_in,NULL,NULL, cga_out,NULL,NULL, dev); + cga_in,NULL,NULL, cga_out,NULL,NULL, (priv_t)dev); if (info->local) { for (c = 0; c < 256; c++) { @@ -420,12 +420,12 @@ compaq_cga_init(const device_t *info, UNUSED(void *parent)) video_inform(DEVICE_VIDEO_GET(info->flags), (const video_timings_t *)info->vid_timing); - return(dev); + return((priv_t)dev); } static void -compaq_cga_close(void *priv) +compaq_cga_close(priv_t priv) { compaq_cga_t *dev = (compaq_cga_t *)priv; @@ -439,7 +439,7 @@ compaq_cga_close(void *priv) static void -speed_changed(void *priv) +speed_changed(priv_t priv) { compaq_cga_t *dev = (compaq_cga_t *)priv; diff --git a/src/devices/video/vid_cl54xx.c b/src/devices/video/vid_cl54xx.c index b529465..a014f00 100644 --- a/src/devices/video/vid_cl54xx.c +++ b/src/devices/video/vid_cl54xx.c @@ -9,7 +9,7 @@ * Emulation of select Cirrus Logic cards (CL-GD 5428, * CL-GD 5429, 5430, 5434 and 5436 are supported). * - * Version: @(#)vid_cl54xx.c 1.0.29 2019/05/03 + * Version: @(#)vid_cl54xx.c 1.0.30 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -217,12 +217,12 @@ typedef struct { } gd54xx_t; -static void gd543x_mmio_write(uint32_t addr, uint8_t val, void *p); -static void gd543x_mmio_writew(uint32_t addr, uint16_t val, void *p); -static void gd543x_mmio_writel(uint32_t addr, uint32_t val, void *p); -static uint8_t gd543x_mmio_read(uint32_t addr, void *p); -static uint16_t gd543x_mmio_readw(uint32_t addr, void *p); -static uint32_t gd543x_mmio_readl(uint32_t addr, void *p); +static void gd543x_mmio_write(uint32_t addr, uint8_t val, priv_t); +static void gd543x_mmio_writew(uint32_t addr, uint16_t val, priv_t); +static void gd543x_mmio_writel(uint32_t addr, uint32_t val, priv_t); +static uint8_t gd543x_mmio_read(uint32_t addr, priv_t); +static uint16_t gd543x_mmio_readw(uint32_t addr, priv_t); +static uint32_t gd543x_mmio_readl(uint32_t addr, priv_t); static void gd54xx_start_blit(uint32_t cpu_dat, int count, gd54xx_t *gd54xx, svga_t *svga); @@ -489,7 +489,7 @@ recalc_timings(svga_t *svga) static void -gd54xx_out(uint16_t addr, uint8_t val, void *priv) +gd54xx_out(uint16_t addr, uint8_t val, priv_t priv) { gd54xx_t *dev = (gd54xx_t *)priv; svga_t *svga = &dev->svga; @@ -906,7 +906,7 @@ gd54xx_out(uint16_t addr, uint8_t val, void *priv) static uint8_t -gd54xx_in(uint16_t addr, void *priv) +gd54xx_in(uint16_t addr, priv_t priv) { gd54xx_t *dev = (gd54xx_t *)priv; svga_t *svga = &dev->svga; @@ -1174,7 +1174,7 @@ blit_dword(gd54xx_t *dev, svga_t *svga) static void -blit_write_w(uint32_t addr, uint16_t val, void *priv) +blit_write_w(uint32_t addr, uint16_t val, priv_t priv) { gd54xx_t *dev = (gd54xx_t *)priv; @@ -1183,7 +1183,7 @@ blit_write_w(uint32_t addr, uint16_t val, void *priv) static void -blit_write_l(uint32_t addr, uint32_t val, void *priv) +blit_write_l(uint32_t addr, uint32_t val, priv_t priv) { gd54xx_t *dev = (gd54xx_t *)priv; @@ -1198,7 +1198,7 @@ blit_write_l(uint32_t addr, uint32_t val, void *priv) static void -gd54xx_write(uint32_t addr, uint8_t val, void *priv) +gd54xx_write(uint32_t addr, uint8_t val, priv_t priv) { gd54xx_t *dev = (gd54xx_t *)priv; svga_t *svga = &dev->svga; @@ -1237,7 +1237,7 @@ gd54xx_write(uint32_t addr, uint8_t val, void *priv) static void -gd54xx_writew(uint32_t addr, uint16_t val, void *priv) +gd54xx_writew(uint32_t addr, uint16_t val, priv_t priv) { gd54xx_t *dev = (gd54xx_t *)priv; svga_t *svga = &dev->svga; @@ -1273,7 +1273,7 @@ gd54xx_writew(uint32_t addr, uint16_t val, void *priv) static void -gd54xx_writel(uint32_t addr, uint32_t val, void *priv) +gd54xx_writel(uint32_t addr, uint32_t val, priv_t priv) { gd54xx_t *dev = (gd54xx_t *)priv; svga_t *svga = &dev->svga; @@ -1372,7 +1372,7 @@ gd54xx_get_aperture(uint32_t addr) static uint8_t -gd54xx_readb_linear(uint32_t addr, void *priv) +gd54xx_readb_linear(uint32_t addr, priv_t priv) { svga_t *svga = (svga_t *)priv; gd54xx_t *dev = (gd54xx_t *)svga->p; @@ -1409,7 +1409,7 @@ gd54xx_readb_linear(uint32_t addr, void *priv) static uint16_t -gd54xx_readw_linear(uint32_t addr, void *priv) +gd54xx_readw_linear(uint32_t addr, priv_t priv) { svga_t *svga = (svga_t *)priv; gd54xx_t *dev = (gd54xx_t *)svga->p; @@ -1468,7 +1468,7 @@ gd54xx_readw_linear(uint32_t addr, void *priv) static uint32_t -gd54xx_readl_linear(uint32_t addr, void *priv) +gd54xx_readl_linear(uint32_t addr, priv_t priv) { svga_t *svga = (svga_t *)priv; gd54xx_t *dev = (gd54xx_t *)svga->p; @@ -1541,7 +1541,7 @@ gd54xx_readl_linear(uint32_t addr, void *priv) static void -gd54xx_writeb_linear(uint32_t addr, uint8_t val, void *priv) +gd54xx_writeb_linear(uint32_t addr, uint8_t val, priv_t priv) { svga_t *svga = (svga_t *)priv; gd54xx_t *dev = (gd54xx_t *)svga->p; @@ -1591,7 +1591,7 @@ gd54xx_writeb_linear(uint32_t addr, uint8_t val, void *priv) static void -gd54xx_writew_linear(uint32_t addr, uint16_t val, void *priv) +gd54xx_writew_linear(uint32_t addr, uint16_t val, priv_t priv) { svga_t *svga = (svga_t *)priv; gd54xx_t *dev = (gd54xx_t *)svga->p; @@ -1678,7 +1678,7 @@ gd54xx_writew_linear(uint32_t addr, uint16_t val, void *priv) static void -gd54xx_writel_linear(uint32_t addr, uint32_t val, void *priv) +gd54xx_writel_linear(uint32_t addr, uint32_t val, priv_t priv) { svga_t *svga = (svga_t *)priv; gd54xx_t *dev = (gd54xx_t *)svga->p; @@ -1785,7 +1785,7 @@ gd54xx_writel_linear(uint32_t addr, uint32_t val, void *priv) static uint8_t -gd54xx_read(uint32_t addr, void *priv) +gd54xx_read(uint32_t addr, priv_t priv) { gd54xx_t *dev = (gd54xx_t *)priv; svga_t *svga = &dev->svga; @@ -1803,7 +1803,7 @@ gd54xx_read(uint32_t addr, void *priv) static uint16_t -gd54xx_readw(uint32_t addr, void *priv) +gd54xx_readw(uint32_t addr, priv_t priv) { gd54xx_t *dev = (gd54xx_t *)priv; svga_t *svga = &dev->svga; @@ -1820,7 +1820,7 @@ gd54xx_readw(uint32_t addr, void *priv) static uint32_t -gd54xx_readl(uint32_t addr, void *priv) +gd54xx_readl(uint32_t addr, priv_t priv) { gd54xx_t *dev = (gd54xx_t *)priv; svga_t *svga = &dev->svga; @@ -1846,7 +1846,7 @@ gd543x_do_mmio(svga_t *svga, uint32_t addr) static void -gd543x_mmio_write(uint32_t addr, uint8_t val, void *priv) +gd543x_mmio_write(uint32_t addr, uint8_t val, priv_t priv) { gd54xx_t *dev = (gd54xx_t *)priv; svga_t *svga = &dev->svga; @@ -2038,14 +2038,14 @@ gd543x_mmio_write(uint32_t addr, uint8_t val, void *priv) static void -gd543x_mmio_writew(uint32_t addr, uint16_t val, void *priv) +gd543x_mmio_writew(uint32_t addr, uint16_t val, priv_t priv) { gd54xx_t *dev = (gd54xx_t *)priv; svga_t *svga = &dev->svga; if (gd543x_do_mmio(svga, addr)) { gd543x_mmio_write(addr, val & 0xff, dev); - gd543x_mmio_write(addr+1, val >> 8, dev); + gd543x_mmio_write(addr+1, val >> 8, dev); } else if (dev->mmio_vram_overlap) { gd54xx_write(addr, val & 0xff, dev); gd54xx_write(addr+1, val >> 8, dev); @@ -2054,7 +2054,7 @@ gd543x_mmio_writew(uint32_t addr, uint16_t val, void *priv) static void -gd543x_mmio_writel(uint32_t addr, uint32_t val, void *priv) +gd543x_mmio_writel(uint32_t addr, uint32_t val, priv_t priv) { gd54xx_t *dev = (gd54xx_t *)priv; svga_t *svga = &dev->svga; @@ -2063,18 +2063,18 @@ gd543x_mmio_writel(uint32_t addr, uint32_t val, void *priv) gd543x_mmio_write(addr, val & 0xff, dev); gd543x_mmio_write(addr+1, val >> 8, dev); gd543x_mmio_write(addr+2, val >> 16, dev); - gd543x_mmio_write(addr+3, val >> 24, dev); + gd543x_mmio_write(addr+3, val >> 24, dev); } else if (dev->mmio_vram_overlap) { gd54xx_write(addr, val, dev); gd54xx_write(addr+1, val >> 8, dev); gd54xx_write(addr+2, val >> 16, dev); - gd54xx_write(addr+3, val >> 24, dev); + gd54xx_write(addr+3, val >> 24, dev); } } static uint8_t -gd543x_mmio_read(uint32_t addr, void *priv) +gd543x_mmio_read(uint32_t addr, priv_t priv) { gd54xx_t *dev = (gd54xx_t *)priv; svga_t *svga = &dev->svga; @@ -2094,7 +2094,7 @@ gd543x_mmio_read(uint32_t addr, void *priv) static uint16_t -gd543x_mmio_readw(uint32_t addr, void *priv) +gd543x_mmio_readw(uint32_t addr, priv_t priv) { gd54xx_t *dev = (gd54xx_t *)priv; svga_t *svga = &dev->svga; @@ -2109,7 +2109,7 @@ gd543x_mmio_readw(uint32_t addr, void *priv) static uint32_t -gd543x_mmio_readl(uint32_t addr, void *priv) +gd543x_mmio_readl(uint32_t addr, priv_t priv) { gd54xx_t *dev = (gd54xx_t *)priv; svga_t *svga = &dev->svga; @@ -2402,7 +2402,7 @@ gd54xx_start_blit(uint32_t cpu_dat, int count, gd54xx_t *dev, svga_t *svga) static uint8_t -cl_pci_read(int func, int addr, void *priv) +cl_pci_read(int func, int addr, priv_t priv) { gd54xx_t *dev = (gd54xx_t *)priv; svga_t *svga = &dev->svga; @@ -2449,7 +2449,7 @@ cl_pci_read(int func, int addr, void *priv) static void -cl_pci_write(int func, int addr, uint8_t val, void *priv) +cl_pci_write(int func, int addr, uint8_t val, priv_t priv) { gd54xx_t *dev = (gd54xx_t *)priv; @@ -2486,7 +2486,7 @@ cl_pci_write(int func, int addr, uint8_t val, void *priv) } -static void * +static priv_t gd54xx_init(const device_t *info, UNUSED(void *parent)) { gd54xx_t *dev = (gd54xx_t *)mem_alloc(sizeof(gd54xx_t)); @@ -2496,8 +2496,8 @@ gd54xx_init(const device_t *info, UNUSED(void *parent)) int vram; memset(dev, 0x00, sizeof(gd54xx_t)); - dev->pci = !!(info->flags & DEVICE_PCI); - dev->vlb = !!(info->flags & DEVICE_VLB); + dev->pci = !!(info->flags & DEVICE_PCI); + dev->vlb = !!(info->flags & DEVICE_VLB); dev->rev = 0; dev->has_bios = 1; @@ -2512,7 +2512,7 @@ gd54xx_init(const device_t *info, UNUSED(void *parent)) case CIRRUS_ID_CLGD5426: break; - + case CIRRUS_ID_CLGD5428: if (dev->vlb) romfn = BIOS_GD5428_VLB_PATH; @@ -2564,7 +2564,7 @@ gd54xx_init(const device_t *info, UNUSED(void *parent)) vram = 0; if (vram) - dev->vram_size = vram << 20; + dev->vram_size = vram << 20; else dev->vram_size = 1 << 19; dev->vram_mask = dev->vram_size - 1; @@ -2594,7 +2594,7 @@ gd54xx_init(const device_t *info, UNUSED(void *parent)) NULL, 0, svga); io_sethandler(0x03c0, 32, - gd54xx_in,NULL,NULL, gd54xx_out,NULL,NULL, dev); + gd54xx_in,NULL,NULL, gd54xx_out,NULL,NULL, (priv_t)dev); svga->hwcursor.yoff = 32; svga->hwcursor.xoff = 0; @@ -2635,12 +2635,12 @@ gd54xx_init(const device_t *info, UNUSED(void *parent)) video_inform(DEVICE_VIDEO_GET(info->flags), (const video_timings_t *)info->vid_timing); - return(dev); + return((priv_t)dev); } static void -gd54xx_close(void *priv) +gd54xx_close(priv_t priv) { gd54xx_t *dev = (gd54xx_t *)priv; @@ -2651,7 +2651,7 @@ gd54xx_close(void *priv) static void -gd54xx_speed_changed(void *priv) +gd54xx_speed_changed(priv_t priv) { gd54xx_t *dev = (gd54xx_t *)priv; @@ -2660,7 +2660,7 @@ gd54xx_speed_changed(void *priv) static void -gd54xx_force_redraw(void *priv) +gd54xx_force_redraw(priv_t priv) { gd54xx_t *dev = (gd54xx_t *)priv; diff --git a/src/devices/video/vid_colorplus.c b/src/devices/video/vid_colorplus.c index bab399e..68f8834 100644 --- a/src/devices/video/vid_colorplus.c +++ b/src/devices/video/vid_colorplus.c @@ -8,7 +8,7 @@ * * Plantronics ColorPlus emulation. * - * Version: @(#)vid_colorplus.c 1.0.16 2019/05/05 + * Version: @(#)vid_colorplus.c 1.0.17 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -86,7 +86,7 @@ static const int cols16[16] = { static void -colorplus_out(uint16_t port, uint8_t val, void *priv) +colorplus_out(uint16_t port, uint8_t val, priv_t priv) { colorplus_t *dev = (colorplus_t *)priv; @@ -98,7 +98,7 @@ colorplus_out(uint16_t port, uint8_t val, void *priv) static uint8_t -colorplus_in(uint16_t port, void *priv) +colorplus_in(uint16_t port, priv_t priv) { colorplus_t *dev = (colorplus_t *)priv; @@ -107,7 +107,7 @@ colorplus_in(uint16_t port, void *priv) static void -colorplus_write(uint32_t addr, uint8_t val, void *priv) +colorplus_write(uint32_t addr, uint8_t val, priv_t priv) { colorplus_t *dev = (colorplus_t *)priv; @@ -130,7 +130,7 @@ colorplus_write(uint32_t addr, uint8_t val, void *priv) static uint8_t -colorplus_read(uint32_t addr, void *priv) +colorplus_read(uint32_t addr, priv_t priv) { colorplus_t *dev = (colorplus_t *)priv; @@ -154,7 +154,7 @@ colorplus_read(uint32_t addr, void *priv) static void -colorplus_poll(void *priv) +colorplus_poll(priv_t priv) { colorplus_t *dev = (colorplus_t *)priv; uint8_t *plane0 = dev->cga.vram; @@ -374,7 +374,7 @@ colorplus_poll(void *priv) } -static void * +static priv_t colorplus_init(const device_t *info, UNUSED(void *parent)) { colorplus_t *dev; @@ -392,14 +392,14 @@ colorplus_init(const device_t *info, UNUSED(void *parent)) dev->cga.cpriv = cga_comp_init(1); - timer_add(colorplus_poll, dev, &dev->cga.vidtime, TIMER_ALWAYS_ENABLED); + timer_add(colorplus_poll, (priv_t)dev, &dev->cga.vidtime, TIMER_ALWAYS_ENABLED); mem_map_add(&dev->cga.mapping, 0xb8000, 0x08000, colorplus_read,NULL,NULL, colorplus_write,NULL,NULL, - NULL, MEM_MAPPING_EXTERNAL, dev); + NULL, MEM_MAPPING_EXTERNAL, (priv_t)dev); io_sethandler(0x03d0, 16, - colorplus_in,NULL,NULL, colorplus_out,NULL,NULL, dev); + colorplus_in,NULL,NULL, colorplus_out,NULL,NULL, (priv_t)dev); video_inform(DEVICE_VIDEO_GET(info->flags), (const video_timings_t *)info->vid_timing); @@ -408,12 +408,12 @@ colorplus_init(const device_t *info, UNUSED(void *parent)) config.parallel_enabled[2] = 1; parallel_setup(2, 0x03bc); - return dev; + return (priv_t)dev; } static void -colorplus_close(void *priv) +colorplus_close(priv_t priv) { colorplus_t *dev = (colorplus_t *)priv; @@ -427,10 +427,10 @@ colorplus_close(void *priv) static void -speed_changed(void *priv) +speed_changed(priv_t priv) { colorplus_t *dev = (colorplus_t *)priv; - + cga_recalctimings(&dev->cga); } diff --git a/src/devices/video/vid_ega.c b/src/devices/video/vid_ega.c index 31726dd..069a2b4 100644 --- a/src/devices/video/vid_ega.c +++ b/src/devices/video/vid_ega.c @@ -9,7 +9,7 @@ * Emulation of the EGA, Chips & Technologies SuperEGA, and * AX JEGA graphics cards. * - * Version: @(#)vid_ega.c 1.0.19 2019/05/05 + * Version: @(#)vid_ega.c 1.0.20 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -324,7 +324,7 @@ ega_recalctimings(ega_t *dev) void -ega_poll(void *priv) +ega_poll(priv_t priv) { ega_t *dev = (ega_t *)priv; int y_add = enable_overscan ? (overscan_y >> 1) : 0; @@ -554,7 +554,7 @@ ega_poll(void *priv) void -ega_out(uint16_t port, uint8_t val, void *priv) +ega_out(uint16_t port, uint8_t val, priv_t priv) { ega_t *dev = (ega_t *)priv; uint8_t o, old; @@ -692,7 +692,7 @@ ega_out(uint16_t port, uint8_t val, void *priv) uint8_t -ega_in(uint16_t port, void *priv) +ega_in(uint16_t port, priv_t priv) { ega_t *dev = (ega_t *)priv; uint8_t ret = 0xff; @@ -759,7 +759,7 @@ ega_in(uint16_t port, void *priv) void -ega_write(uint32_t addr, uint8_t val, void *priv) +ega_write(uint32_t addr, uint8_t val, priv_t priv) { ega_t *dev = (ega_t *)priv; uint8_t vala, valb, valc, vald; @@ -940,7 +940,7 @@ ega_write(uint32_t addr, uint8_t val, void *priv) uint8_t -ega_read(uint32_t addr, void *priv) +ega_read(uint32_t addr, priv_t priv) { ega_t *dev = (ega_t *)priv; uint8_t temp, temp2, temp3, temp4; @@ -1113,7 +1113,7 @@ ega_init(ega_t *dev, int monitor_type, int is_mono) static void -ega_close(void *priv) +ega_close(priv_t priv) { ega_t *dev = (ega_t *)priv; @@ -1124,7 +1124,7 @@ ega_close(void *priv) static void -speed_changed(void *priv) +speed_changed(priv_t priv) { ega_t *dev = (ega_t *)priv; @@ -1132,7 +1132,7 @@ speed_changed(void *priv) } -static void * +static priv_t ega_standalone_init(const device_t *info, UNUSED(void *parent)) { ega_t *dev; @@ -1187,17 +1187,17 @@ ega_standalone_init(const device_t *info, UNUSED(void *parent)) mem_map_add(&dev->mapping, 0xa0000, 0x20000, ega_read,NULL,NULL, ega_write,NULL,NULL, - NULL, MEM_MAPPING_EXTERNAL, dev); + NULL, MEM_MAPPING_EXTERNAL, (priv_t)dev); - timer_add(ega_poll, dev, &dev->vidtime, TIMER_ALWAYS_ENABLED); + timer_add(ega_poll, (priv_t)dev, &dev->vidtime, TIMER_ALWAYS_ENABLED); io_sethandler(0x03a0, 64, - ega_in,NULL,NULL, ega_out,NULL,NULL, dev); + ega_in,NULL,NULL, ega_out,NULL,NULL, (priv_t)dev); video_inform(DEVICE_VIDEO_GET(info->flags), (const video_timings_t *)info->vid_timing); - return(dev); + return((priv_t)dev); } diff --git a/src/devices/video/vid_ega.h b/src/devices/video/vid_ega.h index f1be9e4..9928e98 100644 --- a/src/devices/video/vid_ega.h +++ b/src/devices/video/vid_ega.h @@ -8,7 +8,7 @@ * * Definitions for the IBM EGA driver. * - * Version: @(#)vid_ega.h 1.0.5 2019/04/30 + * Version: @(#)vid_ega.h 1.0.6 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -171,11 +171,11 @@ extern void ega_init(ega_t *ega, int monitor_type, int is_mono); extern void ega_recalctimings(ega_t *ega); #endif -extern void ega_out(uint16_t addr, uint8_t val, void *p); -extern uint8_t ega_in(uint16_t addr, void *p); -extern void ega_poll(void *p); -extern void ega_write(uint32_t addr, uint8_t val, void *p); -extern uint8_t ega_read(uint32_t addr, void *p); +extern void ega_out(uint16_t addr, uint8_t val, priv_t); +extern uint8_t ega_in(uint16_t addr, priv_t); +extern void ega_poll(priv_t); +extern void ega_write(uint32_t addr, uint8_t val, priv_t); +extern uint8_t ega_read(uint32_t addr, priv_t); #endif /*VIDEO_EGA_H*/ diff --git a/src/devices/video/vid_et4000.c b/src/devices/video/vid_et4000.c index 8abc1f3..4122dd2 100644 --- a/src/devices/video/vid_et4000.c +++ b/src/devices/video/vid_et4000.c @@ -8,7 +8,7 @@ * * Emulation of the Tseng Labs ET4000. * - * Version: @(#)vid_et4000.c 1.0.16 2019/04/19 + * Version: @(#)vid_et4000.c 1.0.17 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -141,7 +141,7 @@ et4000_in(uint16_t addr, void *priv) static uint8_t -et4000k_in(uint16_t addr, void *priv) +et4000k_in(uint16_t addr, priv_t priv) { et4000_t *dev = (et4000_t *)priv; uint8_t val = 0xff; @@ -207,7 +207,7 @@ et4000k_in(uint16_t addr, void *priv) static void -et4000_out(uint16_t addr, uint8_t val, void *priv) +et4000_out(uint16_t addr, uint8_t val, priv_t priv) { et4000_t *dev = (et4000_t *)priv; svga_t *svga = &dev->svga; @@ -329,7 +329,7 @@ et4000_out(uint16_t addr, uint8_t val, void *priv) static void -et4000k_out(uint16_t addr, uint8_t val, void *priv) +et4000k_out(uint16_t addr, uint8_t val, priv_t priv) { et4000_t *dev = (et4000_t *)priv; @@ -453,7 +453,7 @@ et4000_recalctimings(svga_t *svga) static uint8_t -et4000_mca_read(int port, void *priv) +et4000_mca_read(int port, priv_t priv) { et4000_t *et4000 = (et4000_t *)priv; @@ -462,7 +462,7 @@ et4000_mca_read(int port, void *priv) static void -et4000_mca_write(int port, uint8_t val, void *priv) +et4000_mca_write(int port, uint8_t val, priv_t priv) { et4000_t *et4000 = (et4000_t *)priv; @@ -474,7 +474,7 @@ et4000_mca_write(int port, uint8_t val, void *priv) } -static void * +static priv_t et4000_init(const device_t *info, UNUSED(void *parent)) { et4000_t *dev; @@ -552,12 +552,12 @@ et4000_init(const device_t *info, UNUSED(void *parent)) video_inform(DEVICE_VIDEO_GET(info->flags), (const video_timings_t *)info->vid_timing); - return(dev); + return((priv_t)dev); } static void -et4000_close(void *priv) +et4000_close(priv_t priv) { et4000_t *dev = (et4000_t *)priv; @@ -568,7 +568,7 @@ et4000_close(void *priv) static void -speed_changed(void *priv) +speed_changed(priv_t priv) { et4000_t *dev = (et4000_t *)priv; @@ -577,7 +577,7 @@ speed_changed(void *priv) static void -force_redraw(void *priv) +force_redraw(priv_t priv) { et4000_t *dev = (et4000_t *)priv; diff --git a/src/devices/video/vid_et4000w32.c b/src/devices/video/vid_et4000w32.c index 1066633..2d6ba6f 100644 --- a/src/devices/video/vid_et4000w32.c +++ b/src/devices/video/vid_et4000w32.c @@ -12,7 +12,7 @@ * * FIXME: Note the madness on line 1163, fix that somehow? --FvK * - * Version: @(#)vid_et4000w32.c 1.0.20 2019/05/03 + * Version: @(#)vid_et4000w32.c 1.0.21 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -161,8 +161,8 @@ typedef struct } et4000w32p_t; -static uint8_t et4000w32p_mmu_read(uint32_t addr, void *p); -static void et4000w32p_mmu_write(uint32_t addr, uint8_t val, void *p); +static uint8_t et4000w32p_mmu_read(uint32_t addr, priv_t); +static void et4000w32p_mmu_write(uint32_t addr, uint8_t val, priv_t); static void et4000w32_blit_start(et4000w32p_t *et4000); static void et4000w32_blit(int count, uint32_t mix, uint32_t sdat, int cpu_input, et4000w32p_t *et4000); @@ -268,9 +268,9 @@ et4000w32p_recalctimings(svga_t *svga) static uint8_t -et4000w32p_in(uint16_t addr, void *p) +et4000w32p_in(uint16_t addr, priv_t priv) { - et4000w32p_t *et4000 = (et4000w32p_t *)p; + et4000w32p_t *et4000 = (et4000w32p_t *)priv; svga_t *svga = &et4000->svga; if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) @@ -323,9 +323,9 @@ et4000w32p_in(uint16_t addr, void *p) static void -et4000w32p_out(uint16_t addr, uint8_t val, void *p) +et4000w32p_out(uint16_t addr, uint8_t val, priv_t priv) { - et4000w32p_t *et4000 = (et4000w32p_t *)p; + et4000w32p_t *et4000 = (et4000w32p_t *)priv; svga_t *svga = &et4000->svga; uint8_t old; @@ -596,9 +596,9 @@ static void et4000w32p_queue(et4000w32p_t *et4000, uint32_t addr, uint32_t val, wake_fifo_thread(et4000); } -static void et4000w32p_mmu_write(uint32_t addr, uint8_t val, void *p) +static void et4000w32p_mmu_write(uint32_t addr, uint8_t val, priv_t priv) { - et4000w32p_t *et4000 = (et4000w32p_t *)p; + et4000w32p_t *et4000 = (et4000w32p_t *)priv; svga_t *svga = &et4000->svga; int bank; switch (addr & 0x6000) @@ -645,9 +645,9 @@ static void et4000w32p_mmu_write(uint32_t addr, uint8_t val, void *p) } } -static uint8_t et4000w32p_mmu_read(uint32_t addr, void *p) +static uint8_t et4000w32p_mmu_read(uint32_t addr, priv_t pric) { - et4000w32p_t *et4000 = (et4000w32p_t *)p; + et4000w32p_t *et4000 = (et4000w32p_t *)pric; svga_t *svga = &et4000->svga; int bank; uint8_t temp; @@ -1142,9 +1142,9 @@ static void et4000w32p_io_set(et4000w32p_t *et4000) io_sethandler(0x217A, 0x0002, et4000w32p_in, NULL, NULL, et4000w32p_out, NULL, NULL, et4000); } -static uint8_t et4000w32p_pci_read(int func, int addr, void *p) +static uint8_t et4000w32p_pci_read(int func, int addr, priv_t priv) { - et4000w32p_t *et4000 = (et4000w32p_t *)p; + et4000w32p_t *et4000 = (et4000w32p_t *)priv; addr &= 0xff; @@ -1181,9 +1181,9 @@ static uint8_t et4000w32p_pci_read(int func, int addr, void *p) return 0; } -static void et4000w32p_pci_write(int func, int addr, uint8_t val, void *p) +static void et4000w32p_pci_write(int func, int addr, uint8_t val, priv_t priv) { - et4000w32p_t *et4000 = (et4000w32p_t *)p; + et4000w32p_t *et4000 = (et4000w32p_t *)priv; svga_t *svga = &et4000->svga; addr &= 0xff; @@ -1233,7 +1233,7 @@ static void et4000w32p_pci_write(int func, int addr, uint8_t val, void *p) } -static void * +static priv_t et4000w32p_init(const device_t *info, UNUSED(void *parent)) { int vram_size; @@ -1243,14 +1243,14 @@ et4000w32p_init(const device_t *info, UNUSED(void *parent)) et4000->pci = !!(info->flags & DEVICE_PCI); vram_size = device_get_config_int("memory"); - + et4000->interleaved = (vram_size == 2) ? 1 : 0; - + svga_init(&et4000->svga, et4000, vram_size << 20, et4000w32p_recalctimings, et4000w32p_in, et4000w32p_out, et4000w32p_hwcursor_draw, - NULL); + NULL); et4000->svga.ramdac = device_add(&stg_ramdac_device); @@ -1284,26 +1284,26 @@ et4000w32p_init(const device_t *info, UNUSED(void *parent)) et4000w32p_mmu_write, NULL, NULL, NULL, 0, et4000); et4000w32p_io_set(et4000); - + if (info->flags & DEVICE_PCI) pci_add_card(PCI_ADD_VIDEO, - et4000w32p_pci_read, et4000w32p_pci_write, et4000); + et4000w32p_pci_read, et4000w32p_pci_write, (priv_t)et4000); /* Hardwired bits: 00000000 1xx0x0xx */ /* R/W bits: xx xxxx */ /* PCem bits: 111 */ et4000->pci_regs[0x04] = 0x83; - + et4000->pci_regs[0x10] = 0x00; et4000->pci_regs[0x11] = 0x00; et4000->pci_regs[0x12] = 0xff; et4000->pci_regs[0x13] = 0xff; - + et4000->pci_regs[0x30] = 0x00; et4000->pci_regs[0x31] = 0x00; et4000->pci_regs[0x32] = 0x00; et4000->pci_regs[0x33] = 0xf0; - + et4000->wake_fifo_thread = thread_create_event(); et4000->fifo_not_full_event = thread_create_event(); et4000->fifo_thread = thread_create(fifo_thread, et4000); @@ -1311,17 +1311,17 @@ et4000w32p_init(const device_t *info, UNUSED(void *parent)) video_inform(DEVICE_VIDEO_GET(info->flags), (const video_timings_t *)info->vid_timing); - return et4000; + return (priv_t)et4000; } static void -et4000w32p_close(void *p) +et4000w32p_close(priv_t priv) { - et4000w32p_t *et4000 = (et4000w32p_t *)p; + et4000w32p_t *et4000 = (et4000w32p_t *)priv; svga_close(&et4000->svga); - + thread_kill(et4000->fifo_thread); thread_destroy_event(et4000->wake_fifo_thread); thread_destroy_event(et4000->fifo_not_full_event); @@ -1331,18 +1331,18 @@ et4000w32p_close(void *p) static void -speed_changed(void *p) +speed_changed(priv_t priv) { - et4000w32p_t *et4000 = (et4000w32p_t *)p; - + et4000w32p_t *et4000 = (et4000w32p_t *)priv; + svga_recalctimings(&et4000->svga); } static void -force_redraw(void *p) +force_redraw(priv_t priv) { - et4000w32p_t *et4000w32p = (et4000w32p_t *)p; + et4000w32p_t *et4000w32p = (et4000w32p_t *)priv; et4000w32p->svga.fullchange = changeframecount; } diff --git a/src/devices/video/vid_genius.c b/src/devices/video/vid_genius.c index 00b53c3..efc3eac 100644 --- a/src/devices/video/vid_genius.c +++ b/src/devices/video/vid_genius.c @@ -63,7 +63,7 @@ * reducing the height of characters so they fit in an 8x12 cell * if necessary. * - * Version: @(#)vid_genius.c 1.0.15 2019/05/05 + * Version: @(#)vid_genius.c 1.0.16 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -180,7 +180,7 @@ recalc_timings(genius_t *dev) static void -genius_out(uint16_t port, uint8_t val, void *priv) +genius_out(uint16_t port, uint8_t val, priv_t priv) { genius_t *dev = (genius_t *)priv; @@ -229,7 +229,7 @@ genius_out(uint16_t port, uint8_t val, void *priv) static uint8_t -genius_in(uint16_t port, void *priv) +genius_in(uint16_t port, priv_t priv) { genius_t *dev = (genius_t *)priv; uint8_t ret = 0xff; @@ -274,7 +274,7 @@ genius_in(uint16_t port, void *priv) static void -genius_write(uint32_t addr, uint8_t val, void *priv) +genius_write(uint32_t addr, uint8_t val, priv_t priv) { genius_t *dev = (genius_t *)priv; @@ -290,7 +290,7 @@ genius_write(uint32_t addr, uint8_t val, void *priv) static uint8_t -genius_read(uint32_t addr, void *priv) +genius_read(uint32_t addr, priv_t priv) { genius_t *dev = (genius_t *)priv; @@ -476,7 +476,7 @@ hires_line(genius_t *dev) static void -genius_poll(void *priv) +genius_poll(priv_t priv) { genius_t *dev = (genius_t *)priv; uint8_t background; @@ -584,7 +584,7 @@ load_font(genius_t *dev, const wchar_t *s) } -static void * +static priv_t genius_init(const device_t *info, UNUSED(void *parent)) { genius_t *dev; @@ -602,19 +602,19 @@ genius_init(const device_t *info, UNUSED(void *parent)) /* 160K video RAM */ dev->vram = (uint8_t *)mem_alloc(0x28000); - timer_add(genius_poll, dev, &dev->vidtime, TIMER_ALWAYS_ENABLED); + timer_add(genius_poll, (priv_t)dev, &dev->vidtime, TIMER_ALWAYS_ENABLED); /* Occupy memory between 0xB0000 and 0xBFFFF (moves to 0xA0000 in * high-resolution modes) */ mem_map_add(&dev->mapping, 0xb0000, 0x10000, genius_read,NULL,NULL, genius_write,NULL,NULL, - NULL, MEM_MAPPING_EXTERNAL, dev); + NULL, MEM_MAPPING_EXTERNAL, (priv_t)dev); /* Respond to both MDA and CGA I/O ports */ io_sethandler(0x03b0, 0x000C, - genius_in,NULL,NULL, genius_out,NULL,NULL, dev); + genius_in,NULL,NULL, genius_out,NULL,NULL, (priv_t)dev); io_sethandler(0x03d0, 0x0010, - genius_in,NULL,NULL, genius_out,NULL,NULL, dev); + genius_in,NULL,NULL, genius_out,NULL,NULL, (priv_t)dev); dev->pal[0] = makecol(0x00, 0x00, 0x00); dev->pal[1] = makecol(0x55, 0x55, 0x55); @@ -658,12 +658,12 @@ genius_init(const device_t *info, UNUSED(void *parent)) video_inform(DEVICE_VIDEO_GET(info->flags), (const video_timings_t *)info->vid_timing); - return(dev); + return((priv_t)dev); } static void -genius_close(void *priv) +genius_close(priv_t priv) { genius_t *dev = (genius_t *)priv; @@ -673,7 +673,7 @@ genius_close(void *priv) static void -speed_changed(void *priv) +speed_changed(priv_t priv) { genius_t *dev = (genius_t *)priv; diff --git a/src/devices/video/vid_hercules.c b/src/devices/video/vid_hercules.c index ff63a69..32c6e81 100644 --- a/src/devices/video/vid_hercules.c +++ b/src/devices/video/vid_hercules.c @@ -8,7 +8,7 @@ * * Hercules emulation. * - * Version: @(#)vid_hercules.c 1.0.20 2019/05/05 + * Version: @(#)vid_hercules.c 1.0.21 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -113,7 +113,7 @@ recalc_timings(hercules_t *dev) static void -hercules_out(uint16_t addr, uint8_t val, void *priv) +hercules_out(uint16_t addr, uint8_t val, priv_t priv) { hercules_t *dev = (hercules_t *)priv; uint8_t old; @@ -168,7 +168,7 @@ hercules_out(uint16_t addr, uint8_t val, void *priv) static uint8_t -hercules_in(uint16_t addr, void *priv) +hercules_in(uint16_t addr, priv_t priv) { hercules_t *dev = (hercules_t *)priv; uint8_t ret = 0xff; @@ -204,7 +204,7 @@ hercules_in(uint16_t addr, void *priv) static void -hercules_waitstates(void *p) +hercules_waitstates(priv_t priv) { int ws; @@ -215,7 +215,7 @@ hercules_waitstates(void *p) static void -hercules_write(uint32_t addr, uint8_t val, void *priv) +hercules_write(uint32_t addr, uint8_t val, priv_t priv) { hercules_t *dev = (hercules_t *)priv; @@ -225,7 +225,7 @@ hercules_write(uint32_t addr, uint8_t val, void *priv) static uint8_t -hercules_read(uint32_t addr, void *priv) +hercules_read(uint32_t addr, priv_t priv) { hercules_t *dev = (hercules_t *)priv; @@ -236,7 +236,7 @@ hercules_read(uint32_t addr, void *priv) static void -hercules_poll(void *priv) +hercules_poll(priv_t priv) { hercules_t *dev = (hercules_t *)priv; uint8_t chr, attr; @@ -427,7 +427,7 @@ hercules_poll(void *priv) } -static void * +static priv_t hercules_init(const device_t *info, UNUSED(void *parent)) { hercules_t *dev; @@ -440,7 +440,7 @@ hercules_init(const device_t *info, UNUSED(void *parent)) dev->vram = (uint8_t *)mem_alloc(0x10000); - timer_add(hercules_poll, dev, &dev->vidtime, TIMER_ALWAYS_ENABLED); + timer_add(hercules_poll, (priv_t)dev, &dev->vidtime, TIMER_ALWAYS_ENABLED); /* * Map in the memory, enable exec on it (for software like basich.com @@ -448,10 +448,10 @@ hercules_init(const device_t *info, UNUSED(void *parent)) */ mem_map_add(&dev->mapping, 0xb0000, 0x08000, hercules_read,NULL,NULL, hercules_write,NULL,NULL, - dev->vram, MEM_MAPPING_EXTERNAL, dev); + dev->vram, MEM_MAPPING_EXTERNAL, (priv_t)dev); io_sethandler(0x03b0, 16, - hercules_in,NULL,NULL, hercules_out,NULL,NULL, dev); + hercules_in,NULL,NULL, hercules_out,NULL,NULL, (priv_t)dev); for (c = 0; c < 256; c++) { dev->cols[c][0][0] = dev->cols[c][1][0] = dev->cols[c][1][1] = 16; @@ -492,12 +492,12 @@ hercules_init(const device_t *info, UNUSED(void *parent)) config.parallel_enabled[2] = 1; parallel_setup(2, 0x03bc); - return(dev); + return((priv_t)dev); } static void -hercules_close(void *priv) +hercules_close(priv_t priv) { hercules_t *dev = (hercules_t *)priv; @@ -512,7 +512,7 @@ hercules_close(void *priv) static void -speed_changed(void *priv) +speed_changed(priv_t priv) { hercules_t *dev = (hercules_t *)priv; diff --git a/src/devices/video/vid_herculesplus.c b/src/devices/video/vid_herculesplus.c index 4c13cd9..a168a7b 100644 --- a/src/devices/video/vid_herculesplus.c +++ b/src/devices/video/vid_herculesplus.c @@ -8,7 +8,7 @@ * * Hercules Plus emulation. * - * Version: @(#)vid_hercules_plus.c 1.0.21 2019/05/05 + * Version: @(#)vid_hercules_plus.c 1.0.22 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -130,7 +130,7 @@ recalc_timings(herculesplus_t *dev) static void -herculesplus_out(uint16_t port, uint8_t val, void *priv) +herculesplus_out(uint16_t port, uint8_t val, priv_t priv) { herculesplus_t *dev = (herculesplus_t *)priv; uint8_t old; @@ -179,7 +179,7 @@ herculesplus_out(uint16_t port, uint8_t val, void *priv) static uint8_t -herculesplus_in(uint16_t port, void *priv) +herculesplus_in(uint16_t port, priv_t priv) { herculesplus_t *dev = (herculesplus_t *)priv; uint8_t ret = 0xff; @@ -211,7 +211,7 @@ herculesplus_in(uint16_t port, void *priv) static void -herculesplus_write(uint32_t addr, uint8_t val, void *priv) +herculesplus_write(uint32_t addr, uint8_t val, priv_t priv) { herculesplus_t *dev = (herculesplus_t *)priv; @@ -220,7 +220,7 @@ herculesplus_write(uint32_t addr, uint8_t val, void *priv) static uint8_t -herculesplus_read(uint32_t addr, void *priv) +herculesplus_read(uint32_t addr, priv_t priv) { herculesplus_t *dev = (herculesplus_t *)priv; @@ -510,7 +510,7 @@ graphics_line(herculesplus_t *dev) static void -herculesplus_poll(void *priv) +herculesplus_poll(priv_t priv) { herculesplus_t *dev = (herculesplus_t *)priv; uint16_t ca = (dev->crtc[15] | (dev->crtc[14] << 8)) & 0x3fff; @@ -637,7 +637,7 @@ herculesplus_poll(void *priv) } -static void * +static priv_t herculesplus_init(const device_t *info, UNUSED(void *parent)) { herculesplus_t *dev; @@ -655,15 +655,15 @@ herculesplus_init(const device_t *info, UNUSED(void *parent)) dev->vram = (uint8_t *)mem_alloc(0x10000); /* 64k VRAM */ - timer_add(herculesplus_poll, dev, &dev->vidtime, TIMER_ALWAYS_ENABLED); + timer_add(herculesplus_poll, (priv_t)dev, &dev->vidtime, TIMER_ALWAYS_ENABLED); mem_map_add(&dev->mapping, 0xb0000, 0x10000, herculesplus_read,NULL,NULL, herculesplus_write,NULL,NULL, - dev->vram, MEM_MAPPING_EXTERNAL, dev); + dev->vram, MEM_MAPPING_EXTERNAL, (priv_t)dev); io_sethandler(0x03b0, 16, - herculesplus_in,NULL, NULL, herculesplus_out,NULL,NULL, dev); + herculesplus_in,NULL, NULL, herculesplus_out,NULL,NULL, (priv_t)dev); for (c = 0; c < 256; c++) { dev->cols[c][0][0] = dev->cols[c][1][0] = dev->cols[c][1][1] = 16; @@ -696,12 +696,12 @@ herculesplus_init(const device_t *info, UNUSED(void *parent)) config.parallel_enabled[2] = 1; parallel_setup(2, 0x03bc); - return dev; + return (priv_t)dev; } static void -herculesplus_close(void *priv) +herculesplus_close(priv_t priv) { herculesplus_t *dev = (herculesplus_t *)priv; @@ -716,7 +716,7 @@ herculesplus_close(void *priv) static void -speed_changed(void *priv) +speed_changed(priv_t priv) { herculesplus_t *dev = (herculesplus_t *)priv; diff --git a/src/devices/video/vid_ht216.c b/src/devices/video/vid_ht216.c index 819ac9b..8532fe3 100644 --- a/src/devices/video/vid_ht216.c +++ b/src/devices/video/vid_ht216.c @@ -8,7 +8,7 @@ * * Video7 VGA 1024i emulation. * - * Version: @(#)vid_ht216.c 1.0.4 2019/05/11 + * Version: @(#)vid_ht216.c 1.0.5 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -96,7 +96,7 @@ typedef struct { int ext_reg_enable; int clk_sel; - + uint8_t read_bank_reg[2], write_bank_reg[2]; uint32_t read_bank[2], @@ -104,9 +104,9 @@ typedef struct { uint8_t misc, pad; uint16_t id; - + uint8_t bg_latch[8]; - + uint8_t ht_regs[256]; } ht216_t; @@ -191,255 +191,6 @@ recalc_timings(svga_t *svga) } -static uint8_t -ht216_in(uint16_t addr, void *priv) -{ - ht216_t *dev = (ht216_t *)priv; - svga_t *svga = &dev->svga; - - if (((addr & 0xfff0) == 0x03d0 || - (addr & 0xfff0) == 0x03b0) && !(svga->miscout & 1)) addr ^= 0x60; - - switch (addr) { - case 0x03c2: - break; - - case 0x03c5: - if (svga->seqaddr == 6) - return dev->ext_reg_enable; - - if (svga->seqaddr >= 0x80) { - if (dev->ext_reg_enable) { - switch (svga->seqaddr & 0xff) { - case 0x83: - if (svga->attrff) - return svga->attraddr | 0x80; - return svga->attraddr; - - case 0x8e: - return dev->id & 0xff; - - case 0x8f: - return (dev->id >> 8) & 0xff; - - case 0xa0: - return svga->latch & 0xff; - - case 0xa1: - return (svga->latch >> 8) & 0xff; - case 0xa2: - return (svga->latch >> 16) & 0xff; - case 0xa3: - return (svga->latch >> 24) & 0xff; - case 0xf7: - return 0x01; - - case 0xff: - return 0x80; - } - - return dev->ht_regs[svga->seqaddr & 0xff]; - } else - return 0xff; - } - break; - - case 0x03d4: - return svga->crtcreg; - - case 0x03d5: - if (svga->crtcreg == 0x1f) - return svga->crtc[0xc] ^ 0xea; - return svga->crtc[svga->crtcreg]; - } - - return svga_in(addr, svga); -} - - -static void -ht216_out(uint16_t addr, uint8_t val, void *priv) -{ - ht216_t *dev = (ht216_t *)priv; - svga_t *svga = &dev->svga; - uint8_t old; - - if (((addr & 0xfff0) == 0x03d0 || - (addr & 0xfff0) == 0x03b0) && !(svga->miscout & 1)) addr ^= 0x60; - - switch (addr) { - case 0x03c2: - dev->clk_sel = (dev->clk_sel & ~3) | ((val & 0x0c) >> 2); - dev->misc = val; - dev->read_bank_reg[0] = (dev->read_bank_reg[0] & ~0x20) | ((val & HT_MISC_PAGE_SEL) ? 0x20 : 0); - dev->write_bank_reg[0] = (dev->write_bank_reg[0] & ~0x20) | ((val & HT_MISC_PAGE_SEL) ? 0x20 : 0); - ht216_remap(dev); - svga_recalctimings(&dev->svga); - break; - - case 0x03c5: - if (svga->seqaddr == 4) { - svga->chain4 = val & 8; - ht216_remap(dev); - } else if (svga->seqaddr == 6) { - if (val == 0xea) - dev->ext_reg_enable = 1; - else if (val == 0xae) - dev->ext_reg_enable = 0; - } else if (svga->seqaddr >= 0x80 && dev->ext_reg_enable) { - old = dev->ht_regs[svga->seqaddr & 0xff]; - dev->ht_regs[svga->seqaddr & 0xff] = val; - switch (svga->seqaddr & 0xff) { - case 0x83: - svga->attraddr = val & 0x1f; - svga->attrff = (val & 0x80) ? 1 : 0; - break; - - case 0x94: - svga->hwcursor.addr = ((val << 6) | (3 << 14) | ((dev->ht_regs[0xff] & 0x60) << 11)) << 2; - break; - - case 0x9c: - case 0x9d: - svga->hwcursor.x = dev->ht_regs[0x9d] | ((dev->ht_regs[0x9c] & 7) << 8); - break; - - case 0x9e: - case 0x9f: - svga->hwcursor.y = dev->ht_regs[0x9f] | ((dev->ht_regs[0x9e] & 3) << 8); - break; - - case 0xa0: - svga->latch = (svga->latch & 0xffffff00) | val; - break; - - case 0xa1: - svga->latch = (svga->latch & 0xffff00ff) | (val << 8); - break; - - case 0xa2: - svga->latch = (svga->latch & 0xff00ffff) | (val << 16); - break; - - case 0xa3: - svga->latch = (svga->latch & 0x00ffffff) | (val << 24); - break; - - case 0xa4: - dev->clk_sel = (val >> 2) & 0xf; - svga->miscout = (svga->miscout & ~0xc) | ((dev->clk_sel & 3) << 2); - break; - - case 0xa5: - svga->hwcursor.ena = val & 0x80; - break; - - case 0xc8: - if ((old ^ val) & 0x10) { - svga->fullchange = changeframecount; - svga_recalctimings(svga); - } - break; - - case 0xe8: - dev->read_bank_reg[0] = val; - dev->write_bank_reg[0] = val; - break; - - case 0xe9: - dev->read_bank_reg[1] = val; - dev->write_bank_reg[1] = val; - break; - - case 0xf6: - svga->vram_display_mask = (val & 0x40) ? dev->vram_mask : 0x3ffff; - dev->read_bank_reg[0] = (dev->read_bank_reg[0] & ~0xc0) | ((val & 0xc) << 4); - dev->write_bank_reg[0] = (dev->write_bank_reg[0] & ~0xc0) | ((val & 0x3) << 6); - break; - - case 0xf9: - dev->read_bank_reg[0] = (dev->read_bank_reg[0] & ~0x10) | ((val & 1) ? 0x10 : 0); - dev->write_bank_reg[0] = (dev->write_bank_reg[0] & ~0x10) | ((val & 1) ? 0x10 : 0); - break; - - case 0xff: - svga->hwcursor.addr = ((dev->ht_regs[0x94] << 6) | (3 << 14) | ((val & 0x60) << 11)) << 2; - break; - } - - switch (svga->seqaddr & 0xff) { - case 0xa4: - case 0xf6: - case 0xfc: - svga->fullchange = changeframecount; - svga_recalctimings(&dev->svga); - break; - } - - switch (svga->seqaddr & 0xff) { - case 0xc8: - case 0xc9: - case 0xcf: - case 0xe0: - case 0xe8: - case 0xe9: - case 0xf6: - case 0xf9: - ht216_remap(dev); - break; - } - return; - } - break; - - case 0x03cf: - if (svga->gdcaddr == 6) { - if (val & 8) - svga->banked_mask = 0x7fff; - else - svga->banked_mask = 0xffff; - } - break; - - case 0x03d4: - svga->crtcreg = val & 0x3f; - return; - - case 0x03d5: - if ((svga->crtcreg < 7) && (svga->crtc[0x11] & 0x80)) - return; - if ((svga->crtcreg == 7) && (svga->crtc[0x11] & 0x80)) - val = (svga->crtc[7] & ~0x10) | (val & 0x10); - - old = svga->crtc[svga->crtcreg]; - svga->crtc[svga->crtcreg] = val; - - if (old != val) { - if (svga->crtcreg < 0xe || svga->crtcreg > 0x10) { - svga->fullchange = changeframecount; - svga_recalctimings(&dev->svga); - } - } - break; - - case 0x46e8: - io_removehandler(0x03c0, 32, - ht216_in,NULL,NULL, ht216_out,NULL,NULL, dev); - mem_map_disable(&dev->svga.mapping); - mem_map_disable(&dev->linear_mapping); - if (val & 8) { - io_sethandler(0x03c0, 32, - ht216_in,NULL,NULL, ht216_out,NULL,NULL, dev); - mem_map_enable(&dev->svga.mapping); - ht216_remap(dev); - } - break; - } - - svga_out(addr, val, svga); -} - - static void hwcursor_draw(svga_t *svga, int displine) { @@ -861,7 +612,7 @@ write_common(ht216_t *dev, uint32_t addr, uint8_t val) static void -ht216_write(uint32_t addr, uint8_t val, void *priv) +ht216_write(uint32_t addr, uint8_t val, priv_t priv) { ht216_t *dev = (ht216_t *)priv; svga_t *svga = &dev->svga; @@ -877,7 +628,7 @@ ht216_write(uint32_t addr, uint8_t val, void *priv) static void -ht216_writew(uint32_t addr, uint16_t val, void *priv) +ht216_writew(uint32_t addr, uint16_t val, priv_t priv) { ht216_t *dev = (ht216_t *)priv; svga_t *svga = &dev->svga; @@ -893,7 +644,7 @@ ht216_writew(uint32_t addr, uint16_t val, void *priv) static void -ht216_writel(uint32_t addr, uint32_t val, void *priv) +ht216_writel(uint32_t addr, uint32_t val, priv_t priv) { ht216_t *dev = (ht216_t *)priv; svga_t *svga = &dev->svga; @@ -912,7 +663,7 @@ ht216_writel(uint32_t addr, uint32_t val, void *priv) static void -write_linear(uint32_t addr, uint8_t val, void *priv) +write_linear(uint32_t addr, uint8_t val, priv_t priv) { ht216_t *dev = (ht216_t *)priv; svga_t *svga = &dev->svga; @@ -928,7 +679,7 @@ write_linear(uint32_t addr, uint8_t val, void *priv) static void -writew_linear(uint32_t addr, uint16_t val, void *priv) +writew_linear(uint32_t addr, uint16_t val, priv_t priv) { ht216_t *dev = (ht216_t *)priv; svga_t *svga = &dev->svga; @@ -945,7 +696,7 @@ writew_linear(uint32_t addr, uint16_t val, void *priv) static void -writel_linear(uint32_t addr, uint32_t val, void *priv) +writel_linear(uint32_t addr, uint32_t val, priv_t priv) { ht216_t *dev = (ht216_t *)priv; svga_t *svga = &dev->svga; @@ -1069,7 +820,7 @@ read_common(ht216_t *dev, uint32_t addr) static uint8_t -ht216_read(uint32_t addr, void *priv) +ht216_read(uint32_t addr, priv_t priv) { ht216_t *dev = (ht216_t *)priv; svga_t *svga = &dev->svga; @@ -1082,7 +833,7 @@ ht216_read(uint32_t addr, void *priv) static uint8_t -read_linear(uint32_t addr, void *priv) +read_linear(uint32_t addr, priv_t priv) { ht216_t *dev = (ht216_t *)priv; svga_t *svga = &dev->svga; @@ -1094,8 +845,257 @@ read_linear(uint32_t addr, void *priv) } +static uint8_t +ht216_in(uint16_t addr, priv_t priv) +{ + ht216_t *dev = (ht216_t *)priv; + svga_t *svga = &dev->svga; + + if (((addr & 0xfff0) == 0x03d0 || + (addr & 0xfff0) == 0x03b0) && !(svga->miscout & 1)) addr ^= 0x60; + + switch (addr) { + case 0x03c2: + break; + + case 0x03c5: + if (svga->seqaddr == 6) + return dev->ext_reg_enable; + + if (svga->seqaddr >= 0x80) { + if (dev->ext_reg_enable) { + switch (svga->seqaddr & 0xff) { + case 0x83: + if (svga->attrff) + return svga->attraddr | 0x80; + return svga->attraddr; + + case 0x8e: + return dev->id & 0xff; + + case 0x8f: + return (dev->id >> 8) & 0xff; + + case 0xa0: + return svga->latch & 0xff; + + case 0xa1: + return (svga->latch >> 8) & 0xff; + case 0xa2: + return (svga->latch >> 16) & 0xff; + case 0xa3: + return (svga->latch >> 24) & 0xff; + case 0xf7: + return 0x01; + + case 0xff: + return 0x80; + } + + return dev->ht_regs[svga->seqaddr & 0xff]; + } else + return 0xff; + } + break; + + case 0x03d4: + return svga->crtcreg; + + case 0x03d5: + if (svga->crtcreg == 0x1f) + return svga->crtc[0xc] ^ 0xea; + return svga->crtc[svga->crtcreg]; + } + + return svga_in(addr, svga); +} + + static void -ht216_close(void *priv) +ht216_out(uint16_t addr, uint8_t val, priv_t priv) +{ + ht216_t *dev = (ht216_t *)priv; + svga_t *svga = &dev->svga; + uint8_t old; + + if (((addr & 0xfff0) == 0x03d0 || + (addr & 0xfff0) == 0x03b0) && !(svga->miscout & 1)) addr ^= 0x60; + + switch (addr) { + case 0x03c2: + dev->clk_sel = (dev->clk_sel & ~3) | ((val & 0x0c) >> 2); + dev->misc = val; + dev->read_bank_reg[0] = (dev->read_bank_reg[0] & ~0x20) | ((val & HT_MISC_PAGE_SEL) ? 0x20 : 0); + dev->write_bank_reg[0] = (dev->write_bank_reg[0] & ~0x20) | ((val & HT_MISC_PAGE_SEL) ? 0x20 : 0); + ht216_remap(dev); + svga_recalctimings(&dev->svga); + break; + + case 0x03c5: + if (svga->seqaddr == 4) { + svga->chain4 = val & 8; + ht216_remap(dev); + } else if (svga->seqaddr == 6) { + if (val == 0xea) + dev->ext_reg_enable = 1; + else if (val == 0xae) + dev->ext_reg_enable = 0; + } else if (svga->seqaddr >= 0x80 && dev->ext_reg_enable) { + old = dev->ht_regs[svga->seqaddr & 0xff]; + dev->ht_regs[svga->seqaddr & 0xff] = val; + switch (svga->seqaddr & 0xff) { + case 0x83: + svga->attraddr = val & 0x1f; + svga->attrff = (val & 0x80) ? 1 : 0; + break; + + case 0x94: + svga->hwcursor.addr = ((val << 6) | (3 << 14) | ((dev->ht_regs[0xff] & 0x60) << 11)) << 2; + break; + + case 0x9c: + case 0x9d: + svga->hwcursor.x = dev->ht_regs[0x9d] | ((dev->ht_regs[0x9c] & 7) << 8); + break; + + case 0x9e: + case 0x9f: + svga->hwcursor.y = dev->ht_regs[0x9f] | ((dev->ht_regs[0x9e] & 3) << 8); + break; + + case 0xa0: + svga->latch = (svga->latch & 0xffffff00) | val; + break; + + case 0xa1: + svga->latch = (svga->latch & 0xffff00ff) | (val << 8); + break; + + case 0xa2: + svga->latch = (svga->latch & 0xff00ffff) | (val << 16); + break; + + case 0xa3: + svga->latch = (svga->latch & 0x00ffffff) | (val << 24); + break; + + case 0xa4: + dev->clk_sel = (val >> 2) & 0xf; + svga->miscout = (svga->miscout & ~0xc) | ((dev->clk_sel & 3) << 2); + break; + + case 0xa5: + svga->hwcursor.ena = val & 0x80; + break; + + case 0xc8: + if ((old ^ val) & 0x10) { + svga->fullchange = changeframecount; + svga_recalctimings(svga); + } + break; + + case 0xe8: + dev->read_bank_reg[0] = val; + dev->write_bank_reg[0] = val; + break; + + case 0xe9: + dev->read_bank_reg[1] = val; + dev->write_bank_reg[1] = val; + break; + + case 0xf6: + svga->vram_display_mask = (val & 0x40) ? dev->vram_mask : 0x3ffff; + dev->read_bank_reg[0] = (dev->read_bank_reg[0] & ~0xc0) | ((val & 0xc) << 4); + dev->write_bank_reg[0] = (dev->write_bank_reg[0] & ~0xc0) | ((val & 0x3) << 6); + break; + + case 0xf9: + dev->read_bank_reg[0] = (dev->read_bank_reg[0] & ~0x10) | ((val & 1) ? 0x10 : 0); + dev->write_bank_reg[0] = (dev->write_bank_reg[0] & ~0x10) | ((val & 1) ? 0x10 : 0); + break; + + case 0xff: + svga->hwcursor.addr = ((dev->ht_regs[0x94] << 6) | (3 << 14) | ((val & 0x60) << 11)) << 2; + break; + } + + switch (svga->seqaddr & 0xff) { + case 0xa4: + case 0xf6: + case 0xfc: + svga->fullchange = changeframecount; + svga_recalctimings(&dev->svga); + break; + } + + switch (svga->seqaddr & 0xff) { + case 0xc8: + case 0xc9: + case 0xcf: + case 0xe0: + case 0xe8: + case 0xe9: + case 0xf6: + case 0xf9: + ht216_remap(dev); + break; + } + return; + } + break; + + case 0x03cf: + if (svga->gdcaddr == 6) { + if (val & 8) + svga->banked_mask = 0x7fff; + else + svga->banked_mask = 0xffff; + } + break; + + case 0x03d4: + svga->crtcreg = val & 0x3f; + return; + + case 0x03d5: + if ((svga->crtcreg < 7) && (svga->crtc[0x11] & 0x80)) + return; + if ((svga->crtcreg == 7) && (svga->crtc[0x11] & 0x80)) + val = (svga->crtc[7] & ~0x10) | (val & 0x10); + + old = svga->crtc[svga->crtcreg]; + svga->crtc[svga->crtcreg] = val; + + if (old != val) { + if (svga->crtcreg < 0xe || svga->crtcreg > 0x10) { + svga->fullchange = changeframecount; + svga_recalctimings(&dev->svga); + } + } + break; + + case 0x46e8: + io_removehandler(0x03c0, 32, + ht216_in,NULL,NULL, ht216_out,NULL,NULL, dev); + mem_map_disable(&dev->svga.mapping); + mem_map_disable(&dev->linear_mapping); + if (val & 8) { + io_sethandler(0x03c0, 32, + ht216_in,NULL,NULL, ht216_out,NULL,NULL, dev); + mem_map_enable(&dev->svga.mapping); + ht216_remap(dev); + } + break; + } + + svga_out(addr, val, svga); +} + + +static void +ht216_close(priv_t priv) { ht216_t *dev = (ht216_t *)priv; @@ -1105,7 +1105,25 @@ ht216_close(void *priv) } -static void * +static void +speed_changed(priv_t priv) +{ + ht216_t *dev = (ht216_t *)priv; + + svga_recalctimings(&dev->svga); +} + + +static void +force_redraw(priv_t priv) +{ + ht216_t *dev = (ht216_t *)priv; + + dev->svga.fullchange = changeframecount; +} + + +static priv_t ht216_init(const device_t *info, UNUSED(void *parent)) { ht216_t *dev; @@ -1130,16 +1148,16 @@ ht216_init(const device_t *info, UNUSED(void *parent)) dev->ht_regs[0xb4] = 0x08; /*32-bit DRAM bus*/ io_sethandler(0x03c0, 32, - ht216_in,NULL,NULL, ht216_out,NULL,NULL, dev); + ht216_in,NULL,NULL, ht216_out,NULL,NULL, (priv_t)dev); io_sethandler(0x46e8, 1, - ht216_in,NULL,NULL, ht216_out,NULL,NULL, dev); + ht216_in,NULL,NULL, ht216_out,NULL,NULL, (priv_t)dev); if (info->path != NULL) rom_init(&dev->bios_rom, info->path, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); svga = &dev->svga; - svga_init(svga, dev, vram_sz, + svga_init(svga, (priv_t)dev, vram_sz, recalc_timings, ht216_in, ht216_out, hwcursor_draw, NULL); svga->hwcursor.ysize = 32; svga->decode_mask = vram_sz - 1; @@ -1149,34 +1167,16 @@ ht216_init(const device_t *info, UNUSED(void *parent)) mem_map_set_handler(&svga->mapping, ht216_read,NULL,NULL, ht216_write,ht216_writew,ht216_writel); - mem_map_set_p(&svga->mapping, dev); + mem_map_set_p(&svga->mapping, (priv_t)dev); mem_map_add(&dev->linear_mapping, 0, 0, read_linear,NULL,NULL, write_linear,writew_linear,writel_linear, - NULL, 0, svga); + NULL, 0, (priv_t)svga); video_inform(VID_TYPE_SPEC, &v7vga_timings); - return(dev); -} - - -static void -speed_changed(void *priv) -{ - ht216_t *dev = (ht216_t *)priv; - - svga_recalctimings(&dev->svga); -} - - -static void -force_redraw(void *priv) -{ - ht216_t *dev = (ht216_t *)priv; - - dev->svga.fullchange = changeframecount; + return((priv_t)dev); } diff --git a/src/devices/video/vid_im1024.c b/src/devices/video/vid_im1024.c index 4dad5b3..2891a08 100644 --- a/src/devices/video/vid_im1024.c +++ b/src/devices/video/vid_im1024.c @@ -38,7 +38,7 @@ * This is implemented by holding a FIFO of unlimited depth in * the IM1024 to receive the data. * - * Version: @(#)vid_im1024.c 1.0.4 2019/04/19 + * Version: @(#)vid_im1024.c 1.0.5 2019/05/13 * * Authors: Fred N. van Kempen, * John Elliott, @@ -96,6 +96,9 @@ typedef struct { } im1024_t; +static const video_timings_t im1024_timings = { VID_ISA,8,16,32,8,16,32 }; + + static void fifo_write(im1024_t *dev, uint8_t val) { @@ -205,7 +208,7 @@ input_byte(pgc_t *pgc, uint8_t *result) /* Override memory read to return FIFO space. */ static uint8_t -im1024_read(uint32_t addr, void *priv) +im1024_read(uint32_t addr, priv_t priv) { im1024_t *dev = (im1024_t *)priv; @@ -220,7 +223,7 @@ im1024_read(uint32_t addr, void *priv) /* Override memory write to handle writes to the FIFO. */ static void -im1024_write(uint32_t addr, uint8_t val, void *priv) +im1024_write(uint32_t addr, uint8_t val, priv_t priv) { im1024_t *dev = (im1024_t *)priv; @@ -933,7 +936,27 @@ static const pgc_cmd_t im1024_commands[] = { }; -static void * +static void +im1024_close(priv_t priv) +{ + im1024_t *dev = (im1024_t *)priv; + + pgc_close(&dev->pgc); + + free(dev); +} + + +static void +speed_changed(priv_t priv) +{ + im1024_t *dev = (im1024_t *)priv; + + pgc_speed_changed(&dev->pgc); +} + + +static priv_t im1024_init(const device_t *info, UNUSED(void *parent)) { im1024_t *dev; @@ -954,35 +977,12 @@ im1024_init(const device_t *info, UNUSED(void *parent)) mem_map_set_handler(&dev->pgc.mapping, im1024_read,NULL,NULL, im1024_write,NULL,NULL); - video_inform(DEVICE_VIDEO_GET(info->flags), - (const video_timings_t *)info->vid_timing); + video_inform(DEVICE_VIDEO_GET(info->flags), &im1024_timings); - return(dev); + return((priv_t)dev); } -static void -im1024_close(void *priv) -{ - im1024_t *dev = (im1024_t *)priv; - - pgc_close(&dev->pgc); - - free(dev); -} - - -static void -speed_changed(void *priv) -{ - im1024_t *dev = (im1024_t *)priv; - - pgc_speed_changed(&dev->pgc); -} - - -static const video_timings_t im1024_timings = { VID_ISA,8,16,32,8,16,32 }; - static const device_config_t im1024_config[] = { { NULL @@ -999,6 +999,6 @@ const device_t im1024_device = { NULL, speed_changed, NULL, - &im1024_timings, + NULL, im1024_config }; diff --git a/src/devices/video/vid_incolor.c b/src/devices/video/vid_incolor.c index fda81de..a4666c3 100644 --- a/src/devices/video/vid_incolor.c +++ b/src/devices/video/vid_incolor.c @@ -8,7 +8,7 @@ * * Hercules InColor emulation. * - * Version: @(#)vid_incolor.c 1.0.19 2019/05/05 + * Version: @(#)vid_incolor.c 1.0.20 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -226,7 +226,7 @@ recalc_timings(incolor_t *dev) static void -incolor_out(uint16_t port, uint8_t val, void *priv) +incolor_out(uint16_t port, uint8_t val, priv_t priv) { incolor_t *dev = (incolor_t *)priv; uint8_t old; @@ -281,7 +281,7 @@ incolor_out(uint16_t port, uint8_t val, void *priv) static uint8_t -incolor_in(uint16_t port, void *priv) +incolor_in(uint16_t port, priv_t priv) { incolor_t *dev = (incolor_t *)priv; uint8_t ret = 0xff; @@ -318,7 +318,7 @@ incolor_in(uint16_t port, void *priv) static void -incolor_write(uint32_t addr, uint8_t val, void *priv) +incolor_write(uint32_t addr, uint8_t val, priv_t priv) { incolor_t *dev = (incolor_t *)priv; uint8_t wmask = dev->crtc[INCOLOR_CRTC_MASK]; @@ -384,7 +384,7 @@ incolor_write(uint32_t addr, uint8_t val, void *priv) static uint8_t -incolor_read(uint32_t addr, void *priv) +incolor_read(uint32_t addr, priv_t priv) { incolor_t *dev = (incolor_t *)priv; uint8_t plane; @@ -855,7 +855,7 @@ graphics_line(incolor_t *dev) static void -incolor_poll(void *priv) +incolor_poll(priv_t priv) { incolor_t *dev = (incolor_t *)priv; uint16_t ca = (dev->crtc[15] | (dev->crtc[14] << 8)) & 0x3fff; @@ -980,7 +980,7 @@ incolor_poll(void *priv) } -static void * +static priv_t incolor_init(const device_t *info, UNUSED(void *parent)) { incolor_t *dev; @@ -991,14 +991,14 @@ incolor_init(const device_t *info, UNUSED(void *parent)) dev->vram = (uint8_t *)mem_alloc(0x40000); /* 4 planes of 64k */ - timer_add(incolor_poll, dev, &dev->vidtime, TIMER_ALWAYS_ENABLED); + timer_add(incolor_poll, (priv_t)dev, &dev->vidtime, TIMER_ALWAYS_ENABLED); mem_map_add(&dev->mapping, 0xb0000, 0x08000, incolor_read,NULL,NULL, incolor_write,NULL,NULL, - NULL, MEM_MAPPING_EXTERNAL, dev); + NULL, MEM_MAPPING_EXTERNAL, (priv_t)dev); io_sethandler(0x03b0, 16, - incolor_in,NULL,NULL, incolor_out,NULL,NULL, dev); + incolor_in,NULL,NULL, incolor_out,NULL,NULL, (priv_t)dev); for (c = 0; c < 64; c++) { dev->rgb[c] = makecol32(init_rgb[c][0], init_rgb[c][1], init_rgb[c][2]); @@ -1020,12 +1020,12 @@ incolor_init(const device_t *info, UNUSED(void *parent)) config.parallel_enabled[2] = 1; parallel_setup(2, 0x03bc); - return(dev); + return((priv_t)dev); } static void -incolor_close(void *priv) +incolor_close(priv_t priv) { incolor_t *dev = (incolor_t *)priv; @@ -1040,7 +1040,7 @@ incolor_close(void *priv) static void -speed_changed(void *priv) +speed_changed(priv_t priv) { incolor_t *dev = (incolor_t *)priv; diff --git a/src/devices/video/vid_mda.c b/src/devices/video/vid_mda.c index 5f097f9..1fcc5ce 100644 --- a/src/devices/video/vid_mda.c +++ b/src/devices/video/vid_mda.c @@ -8,7 +8,7 @@ * * MDA emulation. * - * Version: @(#)vid_mda.c 1.0.16 2019/05/05 + * Version: @(#)vid_mda.c 1.0.17 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -75,7 +75,7 @@ mda_recalctimings(mda_t *dev) void -mda_out(uint16_t port, uint8_t val, void *priv) +mda_out(uint16_t port, uint8_t val, priv_t priv) { mda_t *dev = (mda_t *)priv; @@ -109,7 +109,7 @@ mda_out(uint16_t port, uint8_t val, void *priv) uint8_t -mda_in(uint16_t port, void *priv) +mda_in(uint16_t port, priv_t priv) { mda_t *dev = (mda_t *)priv; uint8_t ret = 0xff; @@ -142,7 +142,7 @@ mda_in(uint16_t port, void *priv) void -mda_write(uint32_t addr, uint8_t val, void *priv) +mda_write(uint32_t addr, uint8_t val, priv_t priv) { mda_t *dev = (mda_t *)priv; @@ -151,7 +151,7 @@ mda_write(uint32_t addr, uint8_t val, void *priv) uint8_t -mda_read(uint32_t addr, void *priv) +mda_read(uint32_t addr, priv_t priv) { mda_t *dev = (mda_t *)priv; @@ -160,7 +160,7 @@ mda_read(uint32_t addr, void *priv) void -mda_poll(void *priv) +mda_poll(priv_t priv) { mda_t *dev = (mda_t *)priv; uint16_t ca = (dev->crtc[15] | (dev->crtc[14] << 8)) & 0x3fff; @@ -347,7 +347,7 @@ mda_init(mda_t *dev) } -static void * +static priv_t mda_standalone_init(const device_t *info, UNUSED(void *parent)) { mda_t *dev; @@ -362,12 +362,12 @@ mda_standalone_init(const device_t *info, UNUSED(void *parent)) mem_map_add(&dev->mapping, 0xb0000, 0x08000, mda_read,NULL,NULL, mda_write,NULL,NULL, - NULL, MEM_MAPPING_EXTERNAL, dev); + NULL, MEM_MAPPING_EXTERNAL, (priv_t)dev); io_sethandler(0x03b0, 16, - mda_in,NULL,NULL, mda_out,NULL,NULL, dev); + mda_in,NULL,NULL, mda_out,NULL,NULL, (priv_t)dev); - timer_add(mda_poll, dev, &dev->vidtime, TIMER_ALWAYS_ENABLED); + timer_add(mda_poll, (priv_t)dev, &dev->vidtime, TIMER_ALWAYS_ENABLED); video_inform(DEVICE_VIDEO_GET(info->flags), (const video_timings_t *)&mda_timings); @@ -376,12 +376,12 @@ mda_standalone_init(const device_t *info, UNUSED(void *parent)) config.parallel_enabled[2] = 1; parallel_setup(2, 0x03bc); - return(dev); + return((priv_t)dev); } static void -mda_close(void *priv) +mda_close(priv_t priv) { mda_t *dev = (mda_t *)priv; @@ -392,7 +392,7 @@ mda_close(void *priv) static void -speed_changed(void *priv) +speed_changed(priv_t priv) { mda_t *dev = (mda_t *)priv; diff --git a/src/devices/video/vid_mda.h b/src/devices/video/vid_mda.h index 146af2f..1cfb774 100644 --- a/src/devices/video/vid_mda.h +++ b/src/devices/video/vid_mda.h @@ -8,7 +8,7 @@ * * Definitions for the MDA driver. * - * Version: @(#)vid_mda.h 1.0.1 2019/03/09 + * Version: @(#)vid_mda.h 1.0.2 2019/05/13 * * Authors: Fred N. van Kempen, * @@ -74,12 +74,12 @@ extern const device_config_t mda_config[]; extern void mda_init(mda_t *); -extern void mda_out(uint16_t port, uint8_t val, void *priv); -extern uint8_t mda_in(uint16_t port, void *priv); -extern void mda_write(uint32_t addr, uint8_t val, void *priv); -extern uint8_t mda_read(uint32_t addr, void *priv); +extern void mda_out(uint16_t port, uint8_t val, priv_t); +extern uint8_t mda_in(uint16_t port, priv_t); +extern void mda_write(uint32_t addr, uint8_t val, priv_t); +extern uint8_t mda_read(uint32_t addr, priv_t); extern void mda_recalctimings(mda_t *); -extern void mda_poll(void *priv); +extern void mda_poll(priv_t); extern void mda_setcol(mda_t *, int chr, int blink, int fg, uint8_t ink); diff --git a/src/devices/video/vid_oak_oti.c b/src/devices/video/vid_oak_oti.c index 37c2a78..248e457 100644 --- a/src/devices/video/vid_oak_oti.c +++ b/src/devices/video/vid_oak_oti.c @@ -8,7 +8,7 @@ * * Oak OTI037C/67/077 emulation. * - * Version: @(#)vid_oak_oti.c 1.0.16 2019/04/19 + * Version: @(#)vid_oak_oti.c 1.0.17 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -83,7 +83,7 @@ typedef struct { static void -oti_out(uint16_t addr, uint8_t val, void *priv) +oti_out(uint16_t addr, uint8_t val, priv_t priv) { oti_t *dev = (oti_t *)priv; svga_t *svga = &dev->svga; @@ -200,7 +200,7 @@ oti_out(uint16_t addr, uint8_t val, void *priv) static uint8_t -oti_in(uint16_t addr, void *priv) +oti_in(uint16_t addr, priv_t priv) { oti_t *dev = (oti_t *)priv; svga_t *svga = &dev->svga; @@ -318,7 +318,7 @@ oti_in(uint16_t addr, void *priv) static void -oti_pos_out(uint16_t addr, uint8_t val, void *priv) +oti_pos_out(uint16_t addr, uint8_t val, priv_t priv) { oti_t *dev = (oti_t *)priv; @@ -336,7 +336,7 @@ oti_pos_out(uint16_t addr, uint8_t val, void *priv) static uint8_t -oti_pos_in(uint16_t addr, void *priv) +oti_pos_in(uint16_t addr, priv_t priv) { oti_t *dev = (oti_t *)priv; @@ -358,7 +358,7 @@ recalc_timings(svga_t *svga) static void -speed_changed(void *priv) +speed_changed(priv_t priv) { oti_t *dev = (oti_t *)priv; @@ -367,7 +367,7 @@ speed_changed(void *priv) static void -force_redraw(void *priv) +force_redraw(priv_t priv) { oti_t *dev = (oti_t *)priv; @@ -375,7 +375,7 @@ force_redraw(void *priv) } -static void * +static priv_t oti_init(const device_t *info, UNUSED(void *parent)) { oti_t *dev; @@ -453,19 +453,19 @@ oti_init(const device_t *info, UNUSED(void *parent)) recalc_timings, oti_in, oti_out, NULL, NULL); io_sethandler(0x03c0, 32, - oti_in,NULL,NULL, oti_out,NULL,NULL, dev); + oti_in,NULL,NULL, oti_out,NULL,NULL, (priv_t)dev); dev->svga.miscout = 1; video_inform(DEVICE_VIDEO_GET(info->flags), (const video_timings_t *)info->vid_timing); - return(dev); + return((priv_t)dev); } static void -oti_close(void *priv) +oti_close(priv_t priv) { oti_t *dev = (oti_t *)priv; diff --git a/src/devices/video/vid_paradise.c b/src/devices/video/vid_paradise.c index a2461c3..71b80ed 100644 --- a/src/devices/video/vid_paradise.c +++ b/src/devices/video/vid_paradise.c @@ -13,7 +13,7 @@ * NOTE: The MegaPC video device should be moved to the MegaPC * machine file. * - * Version: @(#)vid_paradise.c 1.0.10 2019/04/19 + * Version: @(#)vid_paradise.c 1.0.11 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -78,9 +78,9 @@ typedef struct { static void paradise_remap(paradise_t *paradise); -static void paradise_out(uint16_t addr, uint8_t val, void *p) +static void paradise_out(uint16_t addr, uint8_t val, priv_t priv) { - paradise_t *paradise = (paradise_t *)p; + paradise_t *paradise = (paradise_t *)priv; svga_t *svga = ¶dise->svga; uint8_t old; @@ -178,9 +178,9 @@ static void paradise_out(uint16_t addr, uint8_t val, void *p) svga_out(addr, val, svga); } -static uint8_t paradise_in(uint16_t addr, void *p) +static uint8_t paradise_in(uint16_t addr, priv_t priv) { - paradise_t *paradise = (paradise_t *)p; + paradise_t *paradise = (paradise_t *)priv; svga_t *svga = ¶dise->svga; if (((addr & 0xfff0) == 0x3d0 || (addr & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) @@ -282,9 +282,9 @@ paradise_recalctimings(svga_t *svga) static void -paradise_write(uint32_t addr, uint8_t val, void *p) +paradise_write(uint32_t addr, uint8_t val, priv_t priv) { - paradise_t *paradise = (paradise_t *)p; + paradise_t *paradise = (paradise_t *)priv; addr = (addr & 0x7fff) + paradise->write_bank[(addr >> 15) & 3]; @@ -293,9 +293,9 @@ paradise_write(uint32_t addr, uint8_t val, void *p) static void -paradise_writew(uint32_t addr, uint16_t val, void *p) +paradise_writew(uint32_t addr, uint16_t val, priv_t priv) { - paradise_t *paradise = (paradise_t *)p; + paradise_t *paradise = (paradise_t *)priv; addr = (addr & 0x7fff) + paradise->write_bank[(addr >> 15) & 3]; svga_writew_linear(addr, val, ¶dise->svga); @@ -303,9 +303,9 @@ paradise_writew(uint32_t addr, uint16_t val, void *p) static uint8_t -paradise_read(uint32_t addr, void *p) +paradise_read(uint32_t addr, priv_t priv) { - paradise_t *paradise = (paradise_t *)p; + paradise_t *paradise = (paradise_t *)priv; addr = (addr & 0x7fff) + paradise->read_bank[(addr >> 15) & 3]; @@ -314,9 +314,9 @@ paradise_read(uint32_t addr, void *p) static uint16_t -paradise_readw(uint32_t addr, void *p) +paradise_readw(uint32_t addr, priv_t priv) { - paradise_t *paradise = (paradise_t *)p; + paradise_t *paradise = (paradise_t *)priv; addr = (addr & 0x7fff) + paradise->read_bank[(addr >> 15) & 3]; @@ -331,20 +331,18 @@ pvga1a_init(const device_t *info, uint32_t memsize) svga_t *svga = ¶dise->svga; memset(paradise, 0, sizeof(paradise_t)); - + io_sethandler(0x03c0, 0x0020, paradise_in, NULL, NULL, paradise_out, NULL, NULL, paradise); svga_init(¶dise->svga, paradise, memsize, /*256kb*/ - NULL, - paradise_in, paradise_out, - NULL, NULL); + NULL, paradise_in, paradise_out, NULL, NULL); mem_map_set_handler(¶dise->svga.mapping, paradise_read, paradise_readw, NULL, paradise_write, paradise_writew, NULL); mem_map_set_p(¶dise->svga.mapping, paradise); - + svga->crtc[0x31] = 'W'; svga->crtc[0x32] = 'D'; svga->crtc[0x33] = '9'; @@ -354,8 +352,8 @@ pvga1a_init(const device_t *info, uint32_t memsize) svga->bpp = 8; svga->miscout = 1; - paradise->type = PVGA1A; - + paradise->type = PVGA1A; + video_inform(DEVICE_VIDEO_GET(info->flags), (const video_timings_t *)info->vid_timing); @@ -370,15 +368,12 @@ wd90c11_init(const device_t *info) svga_t *svga = ¶dise->svga; memset(paradise, 0, sizeof(paradise_t)); - + io_sethandler(0x03c0, 0x0020, paradise_in, NULL, NULL, paradise_out, NULL, NULL, paradise); svga_init(¶dise->svga, paradise, 1 << 19, /*512kb*/ - paradise_recalctimings, - paradise_in, paradise_out, - NULL, - NULL); + paradise_recalctimings, paradise_in, paradise_out, NULL, NULL); mem_map_set_handler(¶dise->svga.mapping, paradise_read, paradise_readw, NULL, @@ -395,9 +390,9 @@ wd90c11_init(const device_t *info) svga->bpp = 8; svga->miscout = 1; - - paradise->type = WD90C11; - + + paradise->type = WD90C11; + video_inform(DEVICE_VIDEO_GET(info->flags), (const video_timings_t *)info->vid_timing); @@ -412,15 +407,12 @@ wd90c30_init(const device_t *info, uint32_t memsize) svga_t *svga = ¶dise->svga; memset(paradise, 0, sizeof(paradise_t)); - + io_sethandler(0x03c0, 0x0020, paradise_in, NULL, NULL, paradise_out, NULL, NULL, paradise); svga_init(¶dise->svga, paradise, memsize, - paradise_recalctimings, - paradise_in, paradise_out, - NULL, - NULL); + paradise_recalctimings, paradise_in, paradise_out, NULL, NULL); mem_map_set_handler(¶dise->svga.mapping, paradise_read, paradise_readw, NULL, @@ -437,9 +429,9 @@ wd90c30_init(const device_t *info, uint32_t memsize) svga->bpp = 8; svga->miscout = 1; - - paradise->type = WD90C11; - + + paradise->type = WD90C11; + video_inform(DEVICE_VIDEO_GET(info->flags), (const video_timings_t *)info->vid_timing); @@ -447,7 +439,7 @@ wd90c30_init(const device_t *info, uint32_t memsize) } -static void * +static priv_t pvga1a_pc2086_init(const device_t *info, UNUSED(void *parent)) { paradise_t *paradise = pvga1a_init(info, 1 << 18); @@ -455,12 +447,12 @@ pvga1a_pc2086_init(const device_t *info, UNUSED(void *parent)) if (paradise) rom_init(¶dise->bios_rom, info->path, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); - - return paradise; + + return (priv_t)paradise; } -static void * +static priv_t pvga1a_pc3086_init(const device_t *info, UNUSED(void *parent)) { paradise_t *paradise = pvga1a_init(info, 1 << 18); @@ -469,30 +461,30 @@ pvga1a_pc3086_init(const device_t *info, UNUSED(void *parent)) rom_init(¶dise->bios_rom, info->path, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); - return paradise; + return (priv_t)paradise; } -static void * +static priv_t pvga1a_standalone_init(const device_t *info, UNUSED(void *parent)) { paradise_t *paradise; - uint32_t memory = 512; + uint32_t memory; memory = device_get_config_int("memory"); memory <<= 10; paradise = pvga1a_init(info, memory); - + if (paradise) rom_init(¶dise->bios_rom, info->path, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); - return paradise; + return (priv_t)paradise; } -static void * +static priv_t wd90c11_megapc_init(const device_t *info, UNUSED(void *parent)) { paradise_t *paradise = wd90c11_init(info); @@ -503,11 +495,11 @@ wd90c11_megapc_init(const device_t *info, UNUSED(void *parent)) L"machines/amstrad/megapc/211253-bios hi.u19", 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); - return paradise; + return (priv_t)paradise; } -static void * +static priv_t wd90c11_standalone_init(const device_t *info, UNUSED(void *parent)) { paradise_t *paradise = wd90c11_init(info); @@ -516,32 +508,32 @@ wd90c11_standalone_init(const device_t *info, UNUSED(void *parent)) rom_init(¶dise->bios_rom, info->path, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); - return paradise; + return (priv_t)paradise; } -static void * +static priv_t wd90c30_standalone_init(const device_t *info, UNUSED(void *parent)) { paradise_t *paradise; - uint32_t memory = 512; + uint32_t memory; memory = device_get_config_int("memory"); memory <<= 10; paradise = wd90c30_init(info, memory); - + if (paradise) rom_init(¶dise->bios_rom, L"video/wd/wd90c30/90c30-lr.vbi", 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); - return paradise; + return (priv_t)paradise; } static void -paradise_close(void *p) +paradise_close(priv_t priv) { - paradise_t *paradise = (paradise_t *)p; + paradise_t *paradise = (paradise_t *)priv; svga_close(¶dise->svga); @@ -550,18 +542,18 @@ paradise_close(void *p) static void -speed_changed(void *p) +speed_changed(priv_t priv) { - paradise_t *paradise = (paradise_t *)p; + paradise_t *paradise = (paradise_t *)priv; svga_recalctimings(¶dise->svga); } static void -force_redraw(void *p) +force_redraw(priv_t priv) { - paradise_t *paradise = (paradise_t *)p; + paradise_t *paradise = (paradise_t *)priv; paradise->svga.fullchange = changeframecount; } diff --git a/src/devices/video/vid_pgc.c b/src/devices/video/vid_pgc.c index 961c8c9..5409110 100644 --- a/src/devices/video/vid_pgc.c +++ b/src/devices/video/vid_pgc.c @@ -44,7 +44,7 @@ * * This is expected to be done shortly. * - * Version: @(#)vid_pgc.c 1.0.5 2019/04/25 + * Version: @(#)vid_pgc.c 1.0.6 2019/05/13 * * Authors: Fred N. van Kempen, * John Elliott, @@ -99,6 +99,8 @@ #define WAKE_DELAY (TIMER_USEC * 500) +static const video_timings_t pgc_timings = { VID_ISA,8,16,32,8,16,32 }; + static const char *pgc_err_msgs[] = { "Range \r", "Integer \r", @@ -120,7 +122,7 @@ static const uint32_t init_palette[6][256] = { }; -static inline int +static __inline int is_whitespace(char ch) { return (ch != 0 && strchr(" \r\n\t,;()+-", ch) != NULL); @@ -2083,172 +2085,6 @@ pgc_recalctimings(pgc_t *dev) } -/* Write to CGA registers are copied into the transfer memory buffer. */ -void -pgc_out(uint16_t addr, uint8_t val, void *priv) -{ - pgc_t *dev = (pgc_t *)priv; - - DEBUG("PGC: out(%04x, %02x)\n", addr, val); - - switch(addr) { - case 0x03d0: /* CRTC Index register */ - case 0x03d2: - case 0x03d4: - case 0x03d6: - dev->mapram[0x03d0] = val; - break; - - case 0x03d1: /* CRTC Data register */ - case 0x03d3: - case 0x03d5: - case 0x03d7: - /* We store the CRTC registers in RAM at offset 0x03e0. */ - if (dev->mapram[0x03d0] <= 15) - dev->mapram[0x03e0 + dev->mapram[0x03d0]] = val; - break; - - case 0x03d8: /* CRTC Mode Control register */ - dev->mapram[0x03d8] = val; - break; - - case 0x03d9: /* CRTC Color Select register */ - dev->mapram[0x03d9] = val; - break; - } -} - - -/* Read back the CGA registers. */ -uint8_t -pgc_in(uint16_t addr, void *priv) -{ - pgc_t *dev = (pgc_t *)priv; - uint8_t ret = 0xff; - - switch(addr) { - case 0x03d0: /* CRTC Index register */ - case 0x03d2: - case 0x03d4: - case 0x03d6: - ret = dev->mapram[0x03d0]; - break; - - case 0x03d1: /* CRTC Data register */ - case 0x03d3: - case 0x03d5: - case 0x03d7: - /* We store the CRTC registers in RAM at offset 0x03e0. */ - if (dev->mapram[0x03d0] <= 15) - ret = dev->mapram[0x03e0 + dev->mapram[0x03d0]]; - break; - - case 0x03d8: /* CRTC Mode Control register */ - ret = dev->mapram[0x03d8]; - break; - - case 0x03d9: /* CRTC Color Select register */ - ret = dev->mapram[0x03d9]; - break; - - case 0x03da: /* CRTC Status register */ - ret = dev->mapram[0x03da]; - break; - } - - DEBUG("PGC: in(%04x) = %02x\n", addr, ret); - - return ret; -} - - -/* Memory write to the transfer buffer. */ -void -pgc_write(uint32_t addr, uint8_t val, void *priv) -{ - pgc_t *dev = (pgc_t *)priv; - - /* - * It seems variable whether the PGC maps 1K or 2K at 0xc6000. - * - * Map 2K here in case a clone requires it. - */ - if (addr >= 0xc6000 && addr < 0xc6800) { - addr &= 0x7ff; - - /* If one of the FIFOs has been updated, this may cause - * the drawing thread to be woken */ - - if (dev->mapram[addr] != val) { - dev->mapram[addr] = val; - - switch (addr) { - case 0x300: /* input write pointer */ - if (dev->waiting_input_fifo && - dev->mapram[0x300] != dev->mapram[0x301]) { - dev->waiting_input_fifo = 0; - pgc_wake(dev); - } - break; - - case 0x303: /* output read pointer */ - if (dev->waiting_output_fifo && - dev->mapram[0x302] != (uint8_t)(dev->mapram[0x303] - 1)) { - dev->waiting_output_fifo = 0; - pgc_wake(dev); - } - break; - - case 0x305: /* error read pointer */ - if (dev->waiting_error_fifo && - dev->mapram[0x304] != (uint8_t)(dev->mapram[0x305] - 1)) { - dev->waiting_error_fifo = 0; - pgc_wake(dev); - } - break; - - case 0x306: /* cold start flag */ - /* XXX This should be in IM-1024 specific code */ - dev->mapram[0x306] = 0; - break; - - case 0x30c: /* display type */ - pgc_setdisplay(priv, dev->mapram[0x30c]); - dev->mapram[0x30d] = dev->mapram[0x30c]; - break; - - case 0x3ff: /* reboot the PGC */ - pgc_wake(dev); - break; - } - } - } - - if (addr >= 0xb8000 && addr < 0xc0000 && dev->cga_selected) { - addr &= 0x3fff; - dev->cga_vram[addr] = val; - } -} - - -uint8_t -pgc_read(uint32_t addr, void *priv) -{ - pgc_t *dev = (pgc_t *)priv; - uint8_t ret = 0xff; - - if (addr >= 0xc6000 && addr < 0xc6800) { - addr &= 0x7ff; - ret = dev->mapram[addr]; - } else if (addr >= 0xb8000 && addr < 0xc0000 && dev->cga_selected) { - addr &= 0x3fff; - ret = dev->cga_vram[addr]; - } - - return ret; -} - - /* Draw the display in CGA (640x400) text mode. */ void pgc_cga_text(pgc_t *dev, int w) @@ -2447,7 +2283,7 @@ pgc_cga_poll(pgc_t *dev) /* Draw the screen in CGA or native mode. */ void -pgc_poll(void *priv) +pgc_poll(priv_t priv) { pgc_t *dev = (pgc_t *)priv; uint32_t x, y; @@ -2519,8 +2355,174 @@ pgc_poll(void *priv) } +/* Write to CGA registers are copied into the transfer memory buffer. */ void -pgc_speed_changed(void *priv) +pgc_out(uint16_t addr, uint8_t val, priv_t priv) +{ + pgc_t *dev = (pgc_t *)priv; + + DEBUG("PGC: out(%04x, %02x)\n", addr, val); + + switch(addr) { + case 0x03d0: /* CRTC Index register */ + case 0x03d2: + case 0x03d4: + case 0x03d6: + dev->mapram[0x03d0] = val; + break; + + case 0x03d1: /* CRTC Data register */ + case 0x03d3: + case 0x03d5: + case 0x03d7: + /* We store the CRTC registers in RAM at offset 0x03e0. */ + if (dev->mapram[0x03d0] <= 15) + dev->mapram[0x03e0 + dev->mapram[0x03d0]] = val; + break; + + case 0x03d8: /* CRTC Mode Control register */ + dev->mapram[0x03d8] = val; + break; + + case 0x03d9: /* CRTC Color Select register */ + dev->mapram[0x03d9] = val; + break; + } +} + + +/* Read back the CGA registers. */ +uint8_t +pgc_in(uint16_t addr, priv_t priv) +{ + pgc_t *dev = (pgc_t *)priv; + uint8_t ret = 0xff; + + switch(addr) { + case 0x03d0: /* CRTC Index register */ + case 0x03d2: + case 0x03d4: + case 0x03d6: + ret = dev->mapram[0x03d0]; + break; + + case 0x03d1: /* CRTC Data register */ + case 0x03d3: + case 0x03d5: + case 0x03d7: + /* We store the CRTC registers in RAM at offset 0x03e0. */ + if (dev->mapram[0x03d0] <= 15) + ret = dev->mapram[0x03e0 + dev->mapram[0x03d0]]; + break; + + case 0x03d8: /* CRTC Mode Control register */ + ret = dev->mapram[0x03d8]; + break; + + case 0x03d9: /* CRTC Color Select register */ + ret = dev->mapram[0x03d9]; + break; + + case 0x03da: /* CRTC Status register */ + ret = dev->mapram[0x03da]; + break; + } + + DEBUG("PGC: in(%04x) = %02x\n", addr, ret); + + return ret; +} + + +void +pgc_write(uint32_t addr, uint8_t val, priv_t priv) +{ + pgc_t *dev = (pgc_t *)priv; + + /* + * It seems variable whether the PGC maps 1K or 2K at 0xc6000. + * + * Map 2K here in case a clone requires it. + */ + if (addr >= 0xc6000 && addr < 0xc6800) { + addr &= 0x7ff; + + /* If one of the FIFOs has been updated, this may cause + * the drawing thread to be woken */ + + if (dev->mapram[addr] != val) { + dev->mapram[addr] = val; + + switch (addr) { + case 0x300: /* input write pointer */ + if (dev->waiting_input_fifo && + dev->mapram[0x300] != dev->mapram[0x301]) { + dev->waiting_input_fifo = 0; + pgc_wake(dev); + } + break; + + case 0x303: /* output read pointer */ + if (dev->waiting_output_fifo && + dev->mapram[0x302] != (uint8_t)(dev->mapram[0x303] - 1)) { + dev->waiting_output_fifo = 0; + pgc_wake(dev); + } + break; + + case 0x305: /* error read pointer */ + if (dev->waiting_error_fifo && + dev->mapram[0x304] != (uint8_t)(dev->mapram[0x305] - 1)) { + dev->waiting_error_fifo = 0; + pgc_wake(dev); + } + break; + + case 0x306: /* cold start flag */ + /* XXX This should be in IM-1024 specific code */ + dev->mapram[0x306] = 0; + break; + + case 0x30c: /* display type */ + pgc_setdisplay(priv, dev->mapram[0x30c]); + dev->mapram[0x30d] = dev->mapram[0x30c]; + break; + + case 0x3ff: /* reboot the PGC */ + pgc_wake(dev); + break; + } + } + } + + if (addr >= 0xb8000 && addr < 0xc0000 && dev->cga_selected) { + addr &= 0x3fff; + dev->cga_vram[addr] = val; + } +} + + +uint8_t +pgc_read(uint32_t addr, priv_t priv) +{ + pgc_t *dev = (pgc_t *)priv; + uint8_t ret = 0xff; + + if (addr >= 0xc6000 && addr < 0xc6800) { + addr &= 0x7ff; + ret = dev->mapram[addr]; + } else if (addr >= 0xb8000 && addr < 0xc0000 && dev->cga_selected) { + addr &= 0x3fff; + ret = dev->cga_vram[addr]; + } + + return ret; +} + + +/* Memory write to the transfer buffer. */ +void +pgc_speed_changed(priv_t priv) { pgc_t *dev = (pgc_t *)priv; @@ -2529,7 +2531,7 @@ pgc_speed_changed(void *priv) void -pgc_close(void *priv) +pgc_close(priv_t priv) { pgc_t *dev = (pgc_t *)priv; @@ -2538,7 +2540,6 @@ pgc_close(void *priv) * flag, and then simulating a reset so it * stops reading data. */ -INFO("PGC: telling thread to stop..\n"); dev->stopped = 1; dev->mapram[0x3ff] = 1; if (dev->waiting_input_fifo || dev->waiting_output_fifo) { @@ -2547,9 +2548,7 @@ INFO("PGC: telling thread to stop..\n"); } /* Wait for thread to stop. */ -INFO("PGC: waiting for thread to stop..\n"); while (dev->stopped); -INFO("PGC: thread stopped, closing up.\n"); if (dev->cga_vram) free(dev->cga_vram); @@ -2575,13 +2574,13 @@ pgc_init(pgc_t *dev, int maxw, int maxh, int visw, int vish, mem_map_add(&dev->mapping, 0xc6000, 2048, pgc_read,NULL,NULL, pgc_write,NULL,NULL, - NULL, MEM_MAPPING_EXTERNAL, dev); + NULL, MEM_MAPPING_EXTERNAL, (priv_t)dev); mem_map_add(&dev->cga_mapping, 0xb8000, 32768, pgc_read,NULL,NULL, pgc_write,NULL,NULL, - NULL, MEM_MAPPING_EXTERNAL, dev); + NULL, MEM_MAPPING_EXTERNAL, (priv_t)dev); io_sethandler(0x03d0, 16, - pgc_in,NULL,NULL, pgc_out,NULL,NULL, dev); + pgc_in,NULL,NULL, pgc_out,NULL,NULL, (priv_t)dev); dev->maxw = maxw; dev->maxh = maxh; @@ -2613,12 +2612,12 @@ pgc_init(pgc_t *dev, int maxw, int maxh, int visw, int vish, dev->pgc_wake_thread = thread_create_event(); dev->pgc_thread = thread_create(pgc_thread, dev); - timer_add(pgc_poll, dev, &dev->vidtime, TIMER_ALWAYS_ENABLED); - timer_add(wake_timer, dev, &dev->wake_timer, &dev->wake_timer); + timer_add(pgc_poll, (priv_t)dev, &dev->vidtime, TIMER_ALWAYS_ENABLED); + timer_add(wake_timer, (priv_t)dev, &dev->wake_timer, &dev->wake_timer); } -static void * +static priv_t pgc_standalone_init(const device_t *info, UNUSED(void *parent)) { pgc_t *dev; @@ -2630,15 +2629,12 @@ pgc_standalone_init(const device_t *info, UNUSED(void *parent)) /* Framebuffer and screen are both 640x480. */ pgc_init(dev, 640, 480, 640, 480, input_byte); - video_inform(DEVICE_VIDEO_GET(info->flags), - (const video_timings_t *)info->vid_timing); + video_inform(DEVICE_VIDEO_GET(info->flags), &pgc_timings); - return(dev); + return((priv_t)dev); } -static const video_timings_t pgc_timings = { VID_ISA,8,16,32,8,16,32 }; - static const device_config_t pgc_config[] = { { NULL @@ -2655,6 +2651,6 @@ const device_t pgc_device = { NULL, pgc_speed_changed, NULL, - &pgc_timings, + NULL, pgc_config }; diff --git a/src/devices/video/vid_pgc.h b/src/devices/video/vid_pgc.h index c4389af..d237035 100644 --- a/src/devices/video/vid_pgc.h +++ b/src/devices/video/vid_pgc.h @@ -8,7 +8,7 @@ * * Definitions for the PGC driver. * - * Version: @(#)vid_pgc.h 1.0.3 2019/03/04 + * Version: @(#)vid_pgc.h 1.0.4 2019/05/13 * * Authors: Fred N. van Kempen, * John Elliott, @@ -139,18 +139,18 @@ typedef struct pgc { /* I/O functions and worker thread handlers. */ -extern void pgc_out(uint16_t addr, uint8_t val, void *priv); -extern uint8_t pgc_in(uint16_t addr, void *priv); -extern void pgc_write(uint32_t addr, uint8_t val, void *priv); -extern uint8_t pgc_read(uint32_t addr, void *priv); +extern void pgc_out(uint16_t addr, uint8_t val, priv_t); +extern uint8_t pgc_in(uint16_t addr, priv_t); +extern void pgc_write(uint32_t addr, uint8_t val, priv_t); +extern uint8_t pgc_read(uint32_t addr, priv_t); extern void pgc_recalctimings(pgc_t *); -extern void pgc_poll(void *priv); +extern void pgc_poll(priv_t); extern void pgc_reset(pgc_t *); extern void pgc_wake(pgc_t *); extern void pgc_sleep(pgc_t *); extern void pgc_setdisplay(pgc_t *, int cga); -extern void pgc_speed_changed(void *priv); -extern void pgc_close(void *priv); +extern void pgc_speed_changed(priv_t); +extern void pgc_close(priv_t); extern void pgc_init(pgc_t *, int maxw, int maxh, int visw, int vish, int (*inpbyte)(pgc_t *, uint8_t *)); diff --git a/src/devices/video/vid_s3.c b/src/devices/video/vid_s3.c index e582dc6..2f8aa08 100644 --- a/src/devices/video/vid_s3.c +++ b/src/devices/video/vid_s3.c @@ -10,7 +10,7 @@ * * NOTE: ROM images need more/better organization per chipset. * - * Version: @(#)vid_s3.c 1.0.17 2019/04/19 + * Version: @(#)vid_s3.c 1.0.18 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -131,7 +131,7 @@ typedef struct { typedef struct { mem_map_t linear_mapping; mem_map_t mmio_mapping; - + uint8_t has_bios; rom_t bios_rom; @@ -234,10 +234,10 @@ static const video_timings_t timing_s3_trio64 = {VID_BUS,3,2,4,25,25,40}; void s3_updatemapping(); -void s3_accel_write(uint32_t addr, uint8_t val, void *p); -void s3_accel_write_w(uint32_t addr, uint16_t val, void *p); -void s3_accel_write_l(uint32_t addr, uint32_t val, void *p); -uint8_t s3_accel_read(uint32_t addr, void *p); +void s3_accel_write(uint32_t addr, uint8_t val, priv_t); +void s3_accel_write_w(uint32_t addr, uint16_t val, priv_t); +void s3_accel_write_l(uint32_t addr, uint32_t val, priv_t); +uint8_t s3_accel_read(uint32_t addr, priv_t); static __inline void @@ -1027,9 +1027,9 @@ static void s3_queue(s3_t *s3, uint32_t addr, uint32_t val, uint32_t type) wake_fifo_thread(s3); } -void s3_out(uint16_t addr, uint8_t val, void *p) +void s3_out(uint16_t addr, uint8_t val, priv_t priv) { - s3_t *s3 = (s3_t *)p; + s3_t *s3 = (s3_t *)priv; svga_t *svga = &s3->svga; uint8_t old; int rs2, rs3; @@ -1246,9 +1246,9 @@ void s3_out(uint16_t addr, uint8_t val, void *p) svga_out(addr, val, svga); } -uint8_t s3_in(uint16_t addr, void *p) +uint8_t s3_in(uint16_t addr, priv_t priv) { - s3_t *s3 = (s3_t *)p; + s3_t *s3 = (s3_t *)priv; svga_t *svga = &s3->svga; int rs2, rs3; uint8_t temp; @@ -1491,9 +1491,9 @@ void s3_updatemapping(s3_t *s3) mem_map_disable(&s3->mmio_mapping); } -static float s3_trio64_getclock(int clock, void *p) +static float s3_trio64_getclock(int clock, priv_t priv) { - s3_t *s3 = (s3_t *)p; + s3_t *s3 = (s3_t *)priv; svga_t *svga = &s3->svga; float t; int m, n1, n2; @@ -1507,9 +1507,9 @@ static float s3_trio64_getclock(int clock, void *p) } -void s3_accel_out(uint16_t port, uint8_t val, void *p) +void s3_accel_out(uint16_t port, uint8_t val, priv_t priv) { - s3_t *s3 = (s3_t *)p; + s3_t *s3 = (s3_t *)priv; if (port >= 0x8000) { @@ -1535,21 +1535,21 @@ void s3_accel_out(uint16_t port, uint8_t val, void *p) } } -void s3_accel_out_w(uint16_t port, uint16_t val, void *p) +void s3_accel_out_w(uint16_t port, uint16_t val, priv_t peiv) { - s3_t *s3 = (s3_t *)p; + s3_t *s3 = (s3_t *)peiv; s3_queue(s3, port, val, FIFO_OUT_WORD); } -void s3_accel_out_l(uint16_t port, uint32_t val, void *p) +void s3_accel_out_l(uint16_t port, uint32_t val, priv_t priv) { - s3_t *s3 = (s3_t *)p; + s3_t *s3 = (s3_t *)priv; s3_queue(s3, port, val, FIFO_OUT_DWORD); } -uint8_t s3_accel_in(uint16_t port, void *p) +uint8_t s3_accel_in(uint16_t port, priv_t priv) { - s3_t *s3 = (s3_t *)p; + s3_t *s3 = (s3_t *)priv; int temp; switch (port) { @@ -1745,26 +1745,26 @@ uint8_t s3_accel_in(uint16_t port, void *p) return 0; } -void s3_accel_write(uint32_t addr, uint8_t val, void *p) +void s3_accel_write(uint32_t addr, uint8_t val, priv_t priv) { - s3_t *s3 = (s3_t *)p; + s3_t *s3 = (s3_t *)priv; s3_queue(s3, addr & 0xffff, val, FIFO_WRITE_BYTE); } -void s3_accel_write_w(uint32_t addr, uint16_t val, void *p) +void s3_accel_write_w(uint32_t addr, uint16_t val, priv_t priv) { - s3_t *s3 = (s3_t *)p; + s3_t *s3 = (s3_t *)priv; s3_queue(s3, addr & 0xffff, val, FIFO_WRITE_WORD); } -void s3_accel_write_l(uint32_t addr, uint32_t val, void *p) +void s3_accel_write_l(uint32_t addr, uint32_t val, priv_t priv) { - s3_t *s3 = (s3_t *)p; + s3_t *s3 = (s3_t *)priv; s3_queue(s3, addr & 0xffff, val, FIFO_WRITE_DWORD); } -uint8_t s3_accel_read(uint32_t addr, void *p) +uint8_t s3_accel_read(uint32_t addr, priv_t priv) { if (addr & 0x8000) - return s3_accel_in(addr & 0xffff, p); + return s3_accel_in(addr & 0xffff, priv); return 0; } @@ -2758,9 +2758,9 @@ static void s3_io_set(s3_t *s3) } -uint8_t s3_pci_read(int func, int addr, void *p) +uint8_t s3_pci_read(int func, int addr, priv_t priv) { - s3_t *s3 = (s3_t *)p; + s3_t *s3 = (s3_t *)priv; svga_t *svga = &s3->svga; switch (addr) { @@ -2805,9 +2805,9 @@ uint8_t s3_pci_read(int func, int addr, void *p) return 0; } -void s3_pci_write(int func, int addr, uint8_t val, void *p) +void s3_pci_write(int func, int addr, uint8_t val, priv_t priv) { - s3_t *s3 = (s3_t *)p; + s3_t *s3 = (s3_t *)priv; svga_t *svga = &s3->svga; switch (addr) { @@ -2864,14 +2864,18 @@ static int vram_sizes[] = }; -static void * +static priv_t s3_init(const device_t *info, UNUSED(void *parent)) { int chip, stepping; - s3_t *s3 = (s3_t *)mem_alloc(sizeof(s3_t)); - svga_t *svga = &s3->svga; - int vram; uint32_t vram_size; + svga_t *svga; + s3_t *s3; + int vram; + + s3 = (s3_t *)mem_alloc(sizeof(s3_t)); + memset(s3, 0x00, sizeof(s3_t)); + svga = &s3->svga; switch(info->local) { case S3_V7MIRAGE_86C801: @@ -2929,10 +2933,8 @@ s3_init(const device_t *info, UNUSED(void *parent)) return NULL; } - memset(s3, 0, sizeof(s3_t)); - vram = device_get_config_int("memory"); - + if (vram) vram_size = vram << 20; else @@ -2960,17 +2962,11 @@ s3_init(const device_t *info, UNUSED(void *parent)) mem_map_disable(&s3->mmio_mapping); if (chip == S3_VISION964) - svga_init(&s3->svga, s3, vram_size, - s3_recalctimings, - s3_in, s3_out, - bt48x_hwcursor_draw, - NULL); + svga_init(&s3->svga, s3, vram_size, s3_recalctimings, + s3_in, s3_out, bt48x_hwcursor_draw, NULL); else - svga_init(&s3->svga, s3, vram_size, - s3_recalctimings, - s3_in, s3_out, - s3_hwcursor_draw, - NULL); + svga_init(&s3->svga, s3, vram_size, s3_recalctimings, + s3_in, s3_out, s3_hwcursor_draw, NULL); if (s3->chip != S3_86C801 && s3->chip != S3_86C805) { switch (vram) { @@ -3121,16 +3117,16 @@ s3_init(const device_t *info, UNUSED(void *parent)) return NULL; } - return s3; + return (priv_t)s3; } -static void s3_close(void *p) +static void s3_close(priv_t priv) { - s3_t *s3 = (s3_t *)p; + s3_t *s3 = (s3_t *)priv; svga_close(&s3->svga); - + thread_kill(s3->fifo_thread); thread_destroy_event(s3->wake_fifo_thread); thread_destroy_event(s3->fifo_not_full_event); @@ -3138,20 +3134,21 @@ static void s3_close(void *p) free(s3); } -static void s3_speed_changed(void *p) +static void s3_speed_changed(priv_t priv) { - s3_t *s3 = (s3_t *)p; - + s3_t *s3 = (s3_t *)priv; + svga_recalctimings(&s3->svga); } -static void s3_force_redraw(void *p) +static void s3_force_redraw(priv_t priv) { - s3_t *s3 = (s3_t *)p; + s3_t *s3 = (s3_t *)priv; s3->svga.fullchange = changeframecount; } + static const device_config_t s3_9fx_config[] = { { diff --git a/src/devices/video/vid_s3_virge.c b/src/devices/video/vid_s3_virge.c index 3cacb6c..a143355 100644 --- a/src/devices/video/vid_s3_virge.c +++ b/src/devices/video/vid_s3_virge.c @@ -8,7 +8,7 @@ * * S3 ViRGE emulation. * - * Version: @(#)vid_s3_virge.c 1.0.18 2019/04/19 + * Version: @(#)vid_s3_virge.c 1.0.19 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -305,12 +305,12 @@ static void s3_virge_updatemapping(virge_t *virge); static void s3_virge_bitblt(virge_t *virge, int count, uint32_t cpu_dat); -static uint8_t s3_virge_mmio_read(uint32_t addr, void *p); -static uint16_t s3_virge_mmio_read_w(uint32_t addr, void *p); -static uint32_t s3_virge_mmio_read_l(uint32_t addr, void *p); -static void s3_virge_mmio_write(uint32_t addr, uint8_t val, void *p); -static void s3_virge_mmio_write_w(uint32_t addr, uint16_t val, void *p); -static void s3_virge_mmio_write_l(uint32_t addr, uint32_t val, void *p); +static uint8_t s3_virge_mmio_read(uint32_t addr, priv_t); +static uint16_t s3_virge_mmio_read_w(uint32_t addr, priv_t); +static uint32_t s3_virge_mmio_read_l(uint32_t addr, priv_t); +static void s3_virge_mmio_write(uint32_t addr, uint8_t val, priv_t); +static void s3_virge_mmio_write_w(uint32_t addr, uint16_t val, priv_t); +static void s3_virge_mmio_write_l(uint32_t addr, uint32_t val, priv_t); enum { @@ -396,9 +396,9 @@ static void s3_virge_update_irqs(virge_t *virge) pci_clear_irq(virge->card, PCI_INTA); } -static void s3_virge_out(uint16_t addr, uint8_t val, void *p) +static void s3_virge_out(uint16_t addr, uint8_t val, priv_t priv) { - virge_t *virge = (virge_t *)p; + virge_t *virge = (virge_t *)priv; svga_t *svga = &virge->svga; uint8_t old; @@ -541,9 +541,9 @@ static void s3_virge_out(uint16_t addr, uint8_t val, void *p) svga_out(addr, val, svga); } -static uint8_t s3_virge_in(uint16_t addr, void *p) +static uint8_t s3_virge_in(uint16_t addr, priv_t priv) { - virge_t *virge = (virge_t *)p; + virge_t *virge = (virge_t *)priv; svga_t *svga = &virge->svga; uint8_t ret; @@ -817,9 +817,9 @@ static void s3_virge_wait_fifo_idle(virge_t *virge) } } -static uint8_t s3_virge_mmio_read(uint32_t addr, void *p) +static uint8_t s3_virge_mmio_read(uint32_t addr, priv_t priv) { - virge_t *virge = (virge_t *)p; + virge_t *virge = (virge_t *)priv; uint8_t ret; reg_reads++; @@ -846,23 +846,23 @@ static uint8_t s3_virge_mmio_read(uint32_t addr, void *p) case 0x83d4: case 0x83d5: case 0x83d6: case 0x83d7: case 0x83d8: case 0x83d9: case 0x83da: case 0x83db: case 0x83dc: case 0x83dd: case 0x83de: case 0x83df: - return s3_virge_in(addr & 0x3ff, p); + return s3_virge_in(addr & 0x3ff, priv); } return 0xff; } -static uint16_t s3_virge_mmio_read_w(uint32_t addr, void *p) +static uint16_t s3_virge_mmio_read_w(uint32_t addr, priv_t priv) { reg_reads++; switch (addr & 0xfffe) { default: - return s3_virge_mmio_read(addr, p) | (s3_virge_mmio_read(addr + 1, p) << 8); + return s3_virge_mmio_read(addr, priv) | (s3_virge_mmio_read(addr + 1, priv) << 8); } return 0xffff; } -static uint32_t s3_virge_mmio_read_l(uint32_t addr, void *p) +static uint32_t s3_virge_mmio_read_l(uint32_t addr, priv_t priv) { - virge_t *virge = (virge_t *)p; + virge_t *virge = (virge_t *)priv; uint32_t ret = 0xffffffff; reg_reads++; switch (addr & 0xfffc) @@ -1005,7 +1005,7 @@ static uint32_t s3_virge_mmio_read_l(uint32_t addr, void *p) break; default: - ret = s3_virge_mmio_read_w(addr, p) | (s3_virge_mmio_read_w(addr + 2, p) << 16); + ret = s3_virge_mmio_read_w(addr, priv) | (s3_virge_mmio_read_w(addr + 2, priv) << 16); } return ret; } @@ -1384,9 +1384,9 @@ static void s3_virge_queue(virge_t *virge, uint32_t addr, uint32_t val, uint32_t wake_fifo_thread(virge); } -static void s3_virge_mmio_write(uint32_t addr, uint8_t val, void *p) +static void s3_virge_mmio_write(uint32_t addr, uint8_t val, priv_t priv) { - virge_t *virge = (virge_t *)p; + virge_t *virge = (virge_t *)priv; reg_writes++; if ((addr & 0xfffc) < 0x8000) @@ -1407,15 +1407,15 @@ static void s3_virge_mmio_write(uint32_t addr, uint8_t val, void *p) case 0x83d4: case 0x83d5: case 0x83d6: case 0x83d7: case 0x83d8: case 0x83d9: case 0x83da: case 0x83db: case 0x83dc: case 0x83dd: case 0x83de: case 0x83df: - s3_virge_out(addr & 0x3ff, val, p); + s3_virge_out(addr & 0x3ff, val, priv); break; } } -static void s3_virge_mmio_write_w(uint32_t addr, uint16_t val, void *p) +static void s3_virge_mmio_write_w(uint32_t addr, uint16_t val, priv_t priv) { - virge_t *virge = (virge_t *)p; + virge_t *virge = (virge_t *)priv; reg_writes++; if ((addr & 0xfffc) < 0x8000) { @@ -1424,14 +1424,14 @@ static void s3_virge_mmio_write_w(uint32_t addr, uint16_t val, void *p) else switch (addr & 0xfffe) { case 0x83d4: - s3_virge_mmio_write(addr, val & 0xff, p); - s3_virge_mmio_write(addr + 1, val >> 8, p); + s3_virge_mmio_write(addr, val & 0xff, priv); + s3_virge_mmio_write(addr + 1, val >> 8, priv); break; } } -static void s3_virge_mmio_write_l(uint32_t addr, uint32_t val, void *p) +static void s3_virge_mmio_write_l(uint32_t addr, uint32_t val, priv_t priv) { - virge_t *virge = (virge_t *)p; + virge_t *virge = (virge_t *)priv; svga_t *svga = &virge->svga; reg_writes++; @@ -3738,16 +3738,16 @@ static void s3_virge_overlay_draw(svga_t *svga, int displine) int y_add = enable_overscan ? 16 : 0; int x_add = enable_overscan ? 8 : 0; pel_t *p; - + p = &screen->line[displine + y_add][offset + 32 + x_add]; - + if ((offset + virge->streams.sec_w) > virge->streams.pri_w) x_size = (virge->streams.pri_w - virge->streams.sec_x) + 1; else x_size = virge->streams.sec_w + 1; OVERLAY_SAMPLE(); - + for (x = 0; x < x_size; x++) { p[0].val = r[x_read] | (g[x_read] << 8) | (b[x_read] << 16); @@ -3772,31 +3772,31 @@ static void s3_virge_overlay_draw(svga_t *svga, int displine) } } -static uint8_t s3_virge_pci_read(int func, int addr, void *p) +static uint8_t s3_virge_pci_read(int func, int addr, priv_t priv) { - virge_t *virge = (virge_t *)p; + virge_t *virge = (virge_t *)priv; svga_t *svga = &virge->svga; uint8_t ret = 0; switch (addr) { case 0x00: ret = 0x33; break; /*'S3'*/ case 0x01: ret = 0x53; break; - + case 0x02: ret = virge->virge_id_low; break; case 0x03: ret = virge->virge_id_high; break; case 0x04: ret = virge->pci_regs[0x04] & 0x27; break; - + case 0x07: ret = virge->pci_regs[0x07] & 0x36; break; - + case 0x08: ret = 0; break; /*Revision ID*/ case 0x09: ret = 0; break; /*Programming interface*/ - + case 0x0a: ret = 0x00; break; /*Supports VGA interface*/ case 0x0b: ret = 0x03; /*output = 3; */break; case 0x0d: ret = virge->pci_regs[0x0d] & 0xf8; break; - + case 0x10: ret = 0x00; break;/*Linear frame buffer address*/ case 0x11: ret = 0x00; break; case 0x12: ret = 0x00; break; @@ -3808,19 +3808,19 @@ static uint8_t s3_virge_pci_read(int func, int addr, void *p) case 0x33: ret = virge->pci_regs[0x33]; break; case 0x3c: ret = virge->pci_regs[0x3c]; break; - + case 0x3d: ret = 0x01; break; /*INTA*/ - + case 0x3e: ret = 0x04; break; case 0x3f: ret = 0xff; break; - + } return ret; } -static void s3_virge_pci_write(int func, int addr, uint8_t val, void *p) +static void s3_virge_pci_write(int func, int addr, uint8_t val, priv_t priv) { - virge_t *virge = (virge_t *)p; + virge_t *virge = (virge_t *)priv; svga_t *svga = &virge->svga; switch (addr) { @@ -3828,7 +3828,7 @@ static void s3_virge_pci_write(int func, int addr, uint8_t val, void *p) case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x3d: case 0x3e: case 0x3f: return; - + case PCI_REG_COMMAND: if (val & PCI_COMMAND_IO) { @@ -3838,18 +3838,18 @@ static void s3_virge_pci_write(int func, int addr, uint8_t val, void *p) else io_removehandler(0x03c0, 0x0020, s3_virge_in, NULL, NULL, s3_virge_out, NULL, NULL, virge); virge->pci_regs[PCI_REG_COMMAND] = val & 0x27; - s3_virge_updatemapping(virge); + s3_virge_updatemapping(virge); return; case 0x07: virge->pci_regs[0x07] = val & 0x3e; return; - case 0x0d: + case 0x0d: virge->pci_regs[0x0d] = val & 0xf8; return; - - case 0x13: - svga->crtc[0x59] = val & 0xfc; - s3_virge_updatemapping(virge); + + case 0x13: + svga->crtc[0x59] = val & 0xfc; + s3_virge_updatemapping(virge); return; case 0x30: case 0x32: case 0x33: @@ -3872,7 +3872,7 @@ static void s3_virge_pci_write(int func, int addr, uint8_t val, void *p) } -static void * +static priv_t s3_virge_init(const device_t *info, UNUSED(void *parent)) { virge_t *virge; @@ -3883,7 +3883,7 @@ s3_virge_init(const device_t *info, UNUSED(void *parent)) virge->bilinear_enabled = device_get_config_int("bilinear"); virge->dithering_enabled = device_get_config_int("dithering"); virge->memory_size = device_get_config_int("memory"); - + svga_init(&virge->svga, virge, virge->memory_size << 20, s3_virge_recalctimings, s3_virge_in, s3_virge_out, @@ -3922,7 +3922,7 @@ s3_virge_init(const device_t *info, UNUSED(void *parent)) virge->pci_regs[0x3d] = 1; virge->pci_regs[0x3e] = 4; virge->pci_regs[0x3f] = 0xff; - + virge->virge_rev = 0; virge->virge_id = 0xe1; @@ -3980,44 +3980,44 @@ s3_virge_init(const device_t *info, UNUSED(void *parent)) virge->wake_fifo_thread = thread_create_event(); virge->fifo_not_full_event = thread_create_event(); virge->fifo_thread = thread_create(fifo_thread, virge); - - return virge; + + return (priv_t)virge; } static void -s3_virge_close(void *p) +s3_virge_close(priv_t priv) { - virge_t *virge = (virge_t *)p; + virge_t *virge = (virge_t *)priv; thread_kill(virge->render_thread); thread_destroy_event(virge->not_full_event); thread_destroy_event(virge->wake_main_thread); thread_destroy_event(virge->wake_render_thread); - + thread_kill(virge->fifo_thread); thread_destroy_event(virge->wake_fifo_thread); thread_destroy_event(virge->fifo_not_full_event); svga_close(&virge->svga); - + free(virge); } static void -s3_virge_speed_changed(void *p) +s3_virge_speed_changed(priv_t priv) { - virge_t *virge = (virge_t *)p; - + virge_t *virge = (virge_t *)priv; + svga_recalctimings(&virge->svga); } static void -s3_virge_force_redraw(void *p) +s3_virge_force_redraw(priv_t priv) { - virge_t *virge = (virge_t *)p; + virge_t *virge = (virge_t *)priv; virge->svga.fullchange = changeframecount; } diff --git a/src/devices/video/vid_sigma.c b/src/devices/video/vid_sigma.c index bbdc77d..8327dc2 100644 --- a/src/devices/video/vid_sigma.c +++ b/src/devices/video/vid_sigma.c @@ -54,7 +54,7 @@ * is well, but some strange mishaps with cursor positioning * occur. * - * Version: @(#)vid_sigma.c 1.0.10 2019/05/08 + * Version: @(#)vid_sigma.c 1.0.11 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -276,7 +276,7 @@ recalc_timings(sigma_t *dev) static void -sigma_out(uint16_t port, uint8_t val, void *priv) +sigma_out(uint16_t port, uint8_t val, priv_t priv) { sigma_t *dev = (sigma_t *)priv; uint8_t old; @@ -359,7 +359,7 @@ sigma_out(uint16_t port, uint8_t val, void *priv) static uint8_t -sigma_in(uint16_t port, void *priv) +sigma_in(uint16_t port, priv_t priv) { sigma_t *dev = (sigma_t *)priv; uint8_t ret = 0xff; @@ -424,7 +424,7 @@ sigma_in(uint16_t port, void *priv) static void -sigma_write(uint32_t addr, uint8_t val, void *priv) +sigma_write(uint32_t addr, uint8_t val, priv_t priv) { sigma_t *dev = (sigma_t *)priv; @@ -435,7 +435,7 @@ sigma_write(uint32_t addr, uint8_t val, void *priv) static uint8_t -sigma_read(uint32_t addr, void *priv) +sigma_read(uint32_t addr, priv_t priv) { sigma_t *dev = (sigma_t *)priv; @@ -447,7 +447,7 @@ sigma_read(uint32_t addr, void *priv) /* Write to the RAM part of the 8K ROM/RAM area. */ static void -sigma_bwrite(uint32_t addr, uint8_t val, void *priv) +sigma_bwrite(uint32_t addr, uint8_t val, priv_t priv) { sigma_t *dev = (sigma_t *)priv; @@ -459,7 +459,7 @@ sigma_bwrite(uint32_t addr, uint8_t val, void *priv) /* Read from the 8K ROM/RAM area. */ static uint8_t -sigma_bread(uint32_t addr, void *priv) +sigma_bread(uint32_t addr, priv_t priv) { sigma_t *dev = (sigma_t *)priv; uint8_t ret = 0xff; @@ -703,7 +703,7 @@ sigma_gfx4col(sigma_t *dev) static void -sigma_poll(void *priv) +sigma_poll(priv_t priv) { sigma_t *dev = (sigma_t *)priv; uint8_t cols[4]; @@ -930,7 +930,7 @@ load_font(sigma_t *dev, const wchar_t *fn) static void -sigma_close(void *priv) +sigma_close(priv_t priv) { sigma_t *dev = (sigma_t *)priv; @@ -941,7 +941,7 @@ sigma_close(void *priv) static void -speed_changed(void *priv) +speed_changed(priv_t priv) { sigma_t *dev = (sigma_t *)priv; @@ -949,7 +949,7 @@ speed_changed(void *priv) } -static void * +static priv_t sigma_init(const device_t *info, UNUSED(void *parent)) { sigma_t *dev; @@ -974,8 +974,8 @@ sigma_init(const device_t *info, UNUSED(void *parent)) dev->vram = (uint8_t *)mem_alloc(131072); mem_map_add(&dev->mapping, 0xb8000, 0x08000, - sigma_read,NULL,NULL, sigma_write,NULL,NULL, - NULL, MEM_MAPPING_EXTERNAL, dev); + sigma_read,NULL,NULL, sigma_write,NULL,NULL, + NULL, MEM_MAPPING_EXTERNAL, (priv_t)dev); rom_init(&dev->bios_rom, info->path, 0xc0000, 0x2000, 0x1fff, 0, MEM_MAPPING_EXTERNAL); @@ -988,15 +988,15 @@ sigma_init(const device_t *info, UNUSED(void *parent)) memcpy(dev->bram, &dev->bios_rom.rom[0x1800], 0x0800); mem_map_add(&dev->bios_ram, 0xc0000, 0x2000, - sigma_bread,NULL,NULL, sigma_bwrite,NULL,NULL, - dev->bios_rom.rom, MEM_MAPPING_EXTERNAL, dev); + sigma_bread,NULL,NULL, sigma_bwrite,NULL,NULL, + dev->bios_rom.rom, MEM_MAPPING_EXTERNAL, (priv_t)dev); io_sethandler(0x03d0, 16, - sigma_in,NULL,NULL, sigma_out,NULL,NULL, dev); + sigma_in,NULL,NULL, sigma_out,NULL,NULL, (priv_t)dev); io_sethandler(0x02d0, 16, - sigma_in,NULL,NULL, sigma_out,NULL,NULL, dev); + sigma_in,NULL,NULL, sigma_out,NULL,NULL, (priv_t)dev); - timer_add(sigma_poll, dev, &dev->vidtime, TIMER_ALWAYS_ENABLED); + timer_add(sigma_poll, (priv_t)dev, &dev->vidtime, TIMER_ALWAYS_ENABLED); /* Start with ROM paged in, BIOS RAM paged out */ dev->rom_paged = 1; @@ -1006,7 +1006,7 @@ sigma_init(const device_t *info, UNUSED(void *parent)) video_inform(DEVICE_VIDEO_GET(info->flags), &sigma_timing); - return(dev); + return((priv_t)dev); } diff --git a/src/devices/video/vid_svga.c b/src/devices/video/vid_svga.c index 816e018..b1da6ed 100644 --- a/src/devices/video/vid_svga.c +++ b/src/devices/video/vid_svga.c @@ -11,7 +11,7 @@ * This is intended to be used by another SVGA driver, * and not as a card in it's own right. * - * Version: @(#)vid_svga.c 1.0.22 2019/05/05 + * Version: @(#)vid_svga.c 1.0.23 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -95,7 +95,7 @@ svga_set_override(svga_t *svga, int val) void -svga_out(uint16_t addr, uint8_t val, void *priv) +svga_out(uint16_t addr, uint8_t val, priv_t priv) { svga_t *svga = (svga_t *)priv; uint8_t indx, o; @@ -299,7 +299,7 @@ svga_out(uint16_t addr, uint8_t val, void *priv) uint8_t -svga_in(uint16_t addr, void *priv) +svga_in(uint16_t addr, priv_t priv) { svga_t *svga = (svga_t *)priv; uint8_t indx, ret = 0xff; @@ -588,9 +588,9 @@ svga_recalctimings(svga_t *svga) void -svga_poll(void *p) +svga_poll(priv_t priv) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *)priv; uint32_t x; int wx, wy; @@ -802,16 +802,16 @@ svga_poll(void *p) int -svga_init(svga_t *svga, void *p, int vramsize, +svga_init(svga_t *svga, priv_t priv, int vramsize, void (*recalctimings_ex)(struct svga_t *svga), - uint8_t (*video_in) (uint16_t addr, void *p), - void (*video_out)(uint16_t addr, uint8_t val, void *p), + uint8_t (*video_in) (uint16_t addr, priv_t), + void (*video_out)(uint16_t addr, uint8_t val, priv_t), void (*hwcursor_draw)(struct svga_t *svga, int displine), void (*overlay_draw)(struct svga_t *svga, int displine)) { int c, d, e; - svga->p = p; + svga->p = priv; for (c = 0; c < 256; c++) { e = c; @@ -872,9 +872,9 @@ svga_close(svga_t *svga) void -svga_write_common(uint32_t addr, uint8_t val, uint8_t linear, void *p) +svga_write_common(uint32_t addr, uint8_t val, uint8_t linear, priv_t priv) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *)priv; uint32_t write_mask, bit_mask, set_mask, val32 = (uint32_t) val; int func_select, writemask2 = svga->writemask; int memory_map_mode; @@ -1033,9 +1033,9 @@ svga_write_common(uint32_t addr, uint8_t val, uint8_t linear, void *p) uint8_t -svga_read_common(uint32_t addr, uint8_t linear, void *p) +svga_read_common(uint32_t addr, uint8_t linear, priv_t priv) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *)priv; uint32_t latch_addr = 0, ret; int memory_map_mode, readplane = svga->readplane; @@ -1130,30 +1130,30 @@ svga_read_common(uint32_t addr, uint8_t linear, void *p) void -svga_write(uint32_t addr, uint8_t val, void *p) +svga_write(uint32_t addr, uint8_t val, priv_t priv) { - svga_write_common(addr, val, 0, p); + svga_write_common(addr, val, 0, priv); } void -svga_write_linear(uint32_t addr, uint8_t val, void *p) +svga_write_linear(uint32_t addr, uint8_t val, priv_t priv) { - svga_write_common(addr, val, 1, p); + svga_write_common(addr, val, 1, priv); } uint8_t -svga_read(uint32_t addr, void *p) +svga_read(uint32_t addr, priv_t priv) { - return svga_read_common(addr, 0, p); + return svga_read_common(addr, 0, priv); } uint8_t -svga_read_linear(uint32_t addr, void *p) +svga_read_linear(uint32_t addr, priv_t priv) { - return svga_read_common(addr, 1, p); + return svga_read_common(addr, 1, priv); } @@ -1221,12 +1221,12 @@ svga_doblit(int y1, int y2, int wx, int wy, svga_t *svga) void -svga_writeb_linear(uint32_t addr, uint8_t val, void *p) +svga_writeb_linear(uint32_t addr, uint8_t val, priv_t priv) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *)priv; if (!svga->fast) { - svga_write_linear(addr, val, p); + svga_write_linear(addr, val, priv); return; } @@ -1240,13 +1240,13 @@ svga_writeb_linear(uint32_t addr, uint8_t val, void *p) void -svga_writew_common(uint32_t addr, uint16_t val, uint8_t linear, void *p) +svga_writew_common(uint32_t addr, uint16_t val, uint8_t linear, priv_t priv) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *)priv; if (!svga->fast) { - svga_write_common(addr, val & 0xff, linear, p); - svga_write_common(addr + 1, val >> 8, linear, p); + svga_write_common(addr, val & 0xff, linear, priv); + svga_write_common(addr + 1, val >> 8, linear, priv); return; } @@ -1264,29 +1264,29 @@ svga_writew_common(uint32_t addr, uint16_t val, uint8_t linear, void *p) void -svga_writew(uint32_t addr, uint16_t val, void *p) +svga_writew(uint32_t addr, uint16_t val, priv_t priv) { - svga_writew_common(addr, val, 0, p); + svga_writew_common(addr, val, 0, priv); } void -svga_writew_linear(uint32_t addr, uint16_t val, void *p) +svga_writew_linear(uint32_t addr, uint16_t val, priv_t priv) { - svga_writew_common(addr, val, 1, p); + svga_writew_common(addr, val, 1, priv); } void -svga_writel_common(uint32_t addr, uint32_t val, uint8_t linear, void *p) +svga_writel_common(uint32_t addr, uint32_t val, uint8_t linear, priv_t priv) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *)priv; if (!svga->fast) { - svga_write_common(addr, val, linear, p); - svga_write_common(addr + 1, val >> 8, linear, p); - svga_write_common(addr + 2, val >> 16, linear, p); - svga_write_common(addr + 3, val >> 24, linear, p); + svga_write_common(addr, val, linear, priv); + svga_write_common(addr + 1, val >> 8, linear, priv); + svga_write_common(addr + 2, val >> 16, linear, priv); + svga_write_common(addr + 3, val >> 24, linear, priv); return; } @@ -1305,26 +1305,26 @@ svga_writel_common(uint32_t addr, uint32_t val, uint8_t linear, void *p) void -svga_writel(uint32_t addr, uint32_t val, void *p) +svga_writel(uint32_t addr, uint32_t val, priv_t priv) { - svga_writel_common(addr, val, 0, p); + svga_writel_common(addr, val, 0, priv); } void -svga_writel_linear(uint32_t addr, uint32_t val, void *p) +svga_writel_linear(uint32_t addr, uint32_t val, priv_t priv) { - svga_writel_common(addr, val, 1, p); + svga_writel_common(addr, val, 1, priv); } uint8_t -svga_readb_linear(uint32_t addr, void *p) +svga_readb_linear(uint32_t addr, priv_t priv) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *)priv; if (!svga->fast) - return svga_read_linear(addr, p); + return svga_read_linear(addr, priv); addr &= svga->decode_mask; if (addr >= svga->vram_max) @@ -1335,12 +1335,12 @@ svga_readb_linear(uint32_t addr, void *p) uint16_t -svga_readw_common(uint32_t addr, uint8_t linear, void *p) +svga_readw_common(uint32_t addr, uint8_t linear, priv_t priv) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *)priv; if (!svga->fast) - return svga_read_common(addr, linear, p) | (svga_read_common(addr + 1, linear, p) << 8); + return svga_read_common(addr, linear, priv) | (svga_read_common(addr + 1, linear, priv) << 8); cycles -= video_timing_read_w; @@ -1355,27 +1355,27 @@ svga_readw_common(uint32_t addr, uint8_t linear, void *p) uint16_t -svga_readw(uint32_t addr, void *p) +svga_readw(uint32_t addr, priv_t priv) { - return svga_readw_common(addr, 0, p); + return svga_readw_common(addr, 0, priv); } uint16_t -svga_readw_linear(uint32_t addr, void *p) +svga_readw_linear(uint32_t addr, priv_t priv) { - return svga_readw_common(addr, 1, p); + return svga_readw_common(addr, 1, priv); } uint32_t -svga_readl_common(uint32_t addr, uint8_t linear, void *p) +svga_readl_common(uint32_t addr, uint8_t linear, priv_t priv) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *)priv; if (!svga->fast) { - return svga_read_common(addr, linear, p) | (svga_read_common(addr + 1, linear, p) << 8) | - (svga_read_common(addr + 2, linear, p) << 16) | (svga_read_common(addr + 3, linear, p) << 24); + return svga_read_common(addr, linear, priv) | (svga_read_common(addr + 1, linear, priv) << 8) | + (svga_read_common(addr + 2, linear, priv) << 16) | (svga_read_common(addr + 3, linear, priv) << 24); } cycles -= video_timing_read_l; @@ -1391,14 +1391,14 @@ svga_readl_common(uint32_t addr, uint8_t linear, void *p) uint32_t -svga_readl(uint32_t addr, void *p) +svga_readl(uint32_t addr, priv_t priv) { - return svga_readl_common(addr, 0, p); + return svga_readl_common(addr, 0, priv); } uint32_t -svga_readl_linear(uint32_t addr, void *p) +svga_readl_linear(uint32_t addr, priv_t priv) { - return svga_readl_common(addr, 1, p); + return svga_readl_common(addr, 1, priv); } diff --git a/src/devices/video/vid_svga.h b/src/devices/video/vid_svga.h index 32fd67e..0a03098 100644 --- a/src/devices/video/vid_svga.h +++ b/src/devices/video/vid_svga.h @@ -8,13 +8,13 @@ * * Definitions for the generic SVGA driver. * - * Version: @(#)vid_svga.h 1.0.6 2018/10/05 + * Version: @(#)vid_svga.h 1.0.7 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, * Sarah Walker, * - * Copyright 2017,2018 Fred N. van Kempen. + * Copyright 2017-2019 Fred N. van Kempen. * Copyright 2016-2018 Miran Grca. * Copyright 2008-2018 Sarah Walker. * @@ -103,18 +103,18 @@ typedef struct svga_t void (*render)(struct svga_t *svga); void (*recalctimings_ex)(struct svga_t *svga); - void (*video_out)(uint16_t addr, uint8_t val, void *p); - uint8_t (*video_in) (uint16_t addr, void *p); + void (*video_out)(uint16_t addr, uint8_t val, priv_t); + uint8_t (*video_in) (uint16_t addr, priv_t); void (*hwcursor_draw)(struct svga_t *svga, int displine); void (*overlay_draw)(struct svga_t *svga, int displine); void (*vblank_start)(struct svga_t *svga); void (*ven_write)(struct svga_t *svga, uint8_t val, uint32_t addr); - float (*getclock)(int clock, void *p); + float (*getclock)(int clock, priv_t); /*If set then another device is driving the monitor output and the SVGA card should not attempt to display anything */ - int override; - void *p; + int override; + priv_t p; uint8_t crtc[128], gdcreg[64], attrregs[32], seqregs[64], egapal[16], @@ -127,37 +127,38 @@ typedef struct svga_t dac_mask, dac_status, ksc5601_sbyte_mask; - void *ramdac, *clock_gen; + priv_t ramdac, + clock_gen; } svga_t; -extern int svga_init(svga_t *svga, void *p, int memsize, +extern int svga_init(svga_t *svga, priv_t, int memsize, void (*recalctimings_ex)(struct svga_t *svga), - uint8_t (*video_in) (uint16_t addr, void *p), - void (*video_out)(uint16_t addr, uint8_t val, void *p), + uint8_t (*video_in) (uint16_t addr, priv_t), + void (*video_out)(uint16_t addr, uint8_t val, priv_t), void (*hwcursor_draw)(struct svga_t *svga, int displine), void (*overlay_draw)(struct svga_t *svga, int displine)); extern void svga_recalctimings(svga_t *svga); extern void svga_close(svga_t *svga); -uint8_t svga_read(uint32_t addr, void *p); -uint16_t svga_readw(uint32_t addr, void *p); -uint32_t svga_readl(uint32_t addr, void *p); -void svga_write(uint32_t addr, uint8_t val, void *p); -void svga_writew(uint32_t addr, uint16_t val, void *p); -void svga_writel(uint32_t addr, uint32_t val, void *p); -uint8_t svga_read_linear(uint32_t addr, void *p); -uint8_t svga_readb_linear(uint32_t addr, void *p); -uint16_t svga_readw_linear(uint32_t addr, void *p); -uint32_t svga_readl_linear(uint32_t addr, void *p); -void svga_write_linear(uint32_t addr, uint8_t val, void *p); -void svga_writeb_linear(uint32_t addr, uint8_t val, void *p); -void svga_writew_linear(uint32_t addr, uint16_t val, void *p); -void svga_writel_linear(uint32_t addr, uint32_t val, void *p); +uint8_t svga_read(uint32_t addr, priv_t); +uint16_t svga_readw(uint32_t addr, priv_t); +uint32_t svga_readl(uint32_t addr, priv_t); +void svga_write(uint32_t addr, uint8_t val, priv_t); +void svga_writew(uint32_t addr, uint16_t val, priv_t); +void svga_writel(uint32_t addr, uint32_t val, priv_t); +uint8_t svga_read_linear(uint32_t addr, priv_t); +uint8_t svga_readb_linear(uint32_t addr, priv_t); +uint16_t svga_readw_linear(uint32_t addr, priv_t); +uint32_t svga_readl_linear(uint32_t addr, priv_t); +void svga_write_linear(uint32_t addr, uint8_t val, priv_t); +void svga_writeb_linear(uint32_t addr, uint8_t val, priv_t); +void svga_writew_linear(uint32_t addr, uint16_t val, priv_t); +void svga_writel_linear(uint32_t addr, uint32_t val, priv_t); extern uint8_t svga_rotate[8][256]; -extern void svga_out(uint16_t addr, uint8_t val, void *p); -extern uint8_t svga_in(uint16_t addr, void *p); +extern void svga_out(uint16_t addr, uint8_t val, priv_t); +extern uint8_t svga_in(uint16_t addr, priv_t); extern svga_t *svga_get_pri(void); extern void svga_set_override(svga_t *svga, int val); diff --git a/src/devices/video/vid_tgui9440.c b/src/devices/video/vid_tgui9440.c index 3ee2f94..8932a38 100644 --- a/src/devices/video/vid_tgui9440.c +++ b/src/devices/video/vid_tgui9440.c @@ -47,7 +47,7 @@ * access size or host data has any affect, but the Windows 3.1 * driver always reads bytes and write words of 0xffff. * - * Version: @(#)vid_tgui9440.c 1.0.15 2019/05/03 + * Version: @(#)vid_tgui9440.c 1.0.16 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -172,10 +172,10 @@ typedef struct tgui_t mem_map_t accel_mapping; rom_t bios_rom; - + svga_t svga; int pci; - + int type; struct @@ -190,17 +190,17 @@ typedef struct tgui_t int command; int offset; uint8_t ger22; - + int x, y; uint32_t src, dst, src_old, dst_old; int pat_x, pat_y; int use_src; - + int pitch, bpp; uint16_t tgui_pattern[8][8]; } accel; - + uint8_t ext_gdc_regs[16]; /*TGUI9400CXi only*/ uint8_t copy_latch[16]; @@ -210,12 +210,12 @@ typedef struct tgui_t uint8_t oldctrl2,newctrl2; uint32_t linear_base, linear_size; - + int ramdac_state; uint8_t ramdac_ctrl; - + int clock_m, clock_n, clock_k; - + uint32_t vram_size, vram_mask; fifo_entry_t fifo[FIFO_SIZE]; @@ -224,11 +224,11 @@ typedef struct tgui_t thread_t *fifo_thread; event_t *wake_fifo_thread; event_t *fifo_not_full_event; - + int blitter_busy; uint64_t blitter_time; uint64_t status_time; - + volatile int write_blitter; } tgui_t; @@ -240,31 +240,31 @@ void tgui_recalcmapping(tgui_t *tgui); static void fifo_thread(void *param); -uint8_t tgui_accel_read(uint32_t addr, void *priv); -uint16_t tgui_accel_read_w(uint32_t addr, void *priv); -uint32_t tgui_accel_read_l(uint32_t addr, void *priv); +uint8_t tgui_accel_read(uint32_t addr, priv_t); +uint16_t tgui_accel_read_w(uint32_t addr, priv_t); +uint32_t tgui_accel_read_l(uint32_t addr, priv_t); -void tgui_accel_write(uint32_t addr, uint8_t val, void *priv); -void tgui_accel_write_w(uint32_t addr, uint16_t val, void *priv); -void tgui_accel_write_l(uint32_t addr, uint32_t val, void *priv); +void tgui_accel_write(uint32_t addr, uint8_t val, priv_t); +void tgui_accel_write_w(uint32_t addr, uint16_t val, priv_t); +void tgui_accel_write_l(uint32_t addr, uint32_t val, priv_t); -void tgui_accel_write_fb_b(uint32_t addr, uint8_t val, void *priv); -void tgui_accel_write_fb_w(uint32_t addr, uint16_t val, void *priv); -void tgui_accel_write_fb_l(uint32_t addr, uint32_t val, void *priv); +void tgui_accel_write_fb_b(uint32_t addr, uint8_t val, priv_t); +void tgui_accel_write_fb_w(uint32_t addr, uint16_t val, priv_t); +void tgui_accel_write_fb_l(uint32_t addr, uint32_t val, priv_t); -static uint8_t tgui_ext_linear_read(uint32_t addr, void *p); -static void tgui_ext_linear_write(uint32_t addr, uint8_t val, void *p); -static void tgui_ext_linear_writew(uint32_t addr, uint16_t val, void *p); -static void tgui_ext_linear_writel(uint32_t addr, uint32_t val, void *p); +static uint8_t tgui_ext_linear_read(uint32_t addr, priv_t); +static void tgui_ext_linear_write(uint32_t addr, uint8_t val, priv_t); +static void tgui_ext_linear_writew(uint32_t addr, uint16_t val, priv_t); +static void tgui_ext_linear_writel(uint32_t addr, uint32_t val, priv_t); -static uint8_t tgui_ext_read(uint32_t addr, void *p); -static void tgui_ext_write(uint32_t addr, uint8_t val, void *p); -static void tgui_ext_writew(uint32_t addr, uint16_t val, void *p); -static void tgui_ext_writel(uint32_t addr, uint32_t val, void *p); +static uint8_t tgui_ext_read(uint32_t addr, priv_t); +static void tgui_ext_write(uint32_t addr, uint8_t val, priv_t); +static void tgui_ext_writew(uint32_t addr, uint16_t val, priv_t); +static void tgui_ext_writel(uint32_t addr, uint32_t val, priv_t); -void tgui_out(uint16_t addr, uint8_t val, void *p) +void tgui_out(uint16_t addr, uint8_t val, priv_t priv) { - tgui_t *tgui = (tgui_t *)p; + tgui_t *tgui = (tgui_t *)priv; svga_t *svga = &tgui->svga; uint8_t old; @@ -452,9 +452,9 @@ void tgui_out(uint16_t addr, uint8_t val, void *p) svga_out(addr, val, svga); } -uint8_t tgui_in(uint16_t addr, void *p) +uint8_t tgui_in(uint16_t addr, priv_t priv) { - tgui_t *tgui = (tgui_t *)p; + tgui_t *tgui = (tgui_t *)priv; svga_t *svga = &tgui->svga; if (((addr&0xFFF0) == 0x3D0 || (addr&0xFFF0) == 0x3B0) && !(svga->miscout & 1)) addr ^= 0x60; @@ -734,9 +734,9 @@ void tgui_hwcursor_draw(svga_t *svga, int disp_line) svga->hwcursor_latch.addr += 8; } -uint8_t tgui_pci_read(int func, int addr, void *p) +uint8_t tgui_pci_read(int func, int addr, priv_t priv) { - tgui_t *tgui = (tgui_t *)p; + tgui_t *tgui = (tgui_t *)priv; switch (addr) { @@ -769,9 +769,9 @@ uint8_t tgui_pci_read(int func, int addr, void *p) return 0; } -void tgui_pci_write(int func, int addr, uint8_t val, void *p) +void tgui_pci_write(int func, int addr, uint8_t val, priv_t priv) { - tgui_t *tgui = (tgui_t *)p; + tgui_t *tgui = (tgui_t *)priv; svga_t *svga = &tgui->svga; switch (addr) @@ -794,9 +794,9 @@ void tgui_pci_write(int func, int addr, uint8_t val, void *p) } -static uint8_t tgui_ext_linear_read(uint32_t addr, void *p) +static uint8_t tgui_ext_linear_read(uint32_t addr, priv_t priv) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *)priv; tgui_t *tgui = (tgui_t *)svga->p; int c; @@ -813,18 +813,18 @@ static uint8_t tgui_ext_linear_read(uint32_t addr, void *p) return svga->vram[addr & svga->vram_mask]; } -static uint8_t tgui_ext_read(uint32_t addr, void *p) +static uint8_t tgui_ext_read(uint32_t addr, priv_t priv) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *)priv; addr = (addr & svga->banked_mask) + svga->read_bank; return tgui_ext_linear_read(addr, svga); } -static void tgui_ext_linear_write(uint32_t addr, uint8_t val, void *p) +static void tgui_ext_linear_write(uint32_t addr, uint8_t val, priv_t priv) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *)priv; tgui_t *tgui = (tgui_t *)svga->p; int c; uint8_t fg[2] = {tgui->ext_gdc_regs[4], tgui->ext_gdc_regs[5]}; @@ -891,9 +891,9 @@ static void tgui_ext_linear_write(uint32_t addr, uint8_t val, void *p) } } -static void tgui_ext_linear_writew(uint32_t addr, uint16_t val, void *p) +static void tgui_ext_linear_writew(uint32_t addr, uint16_t val, priv_t priv) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *)priv; tgui_t *tgui = (tgui_t *)svga->p; int c; uint8_t fg[2] = {tgui->ext_gdc_regs[4], tgui->ext_gdc_regs[5]}; @@ -961,30 +961,30 @@ static void tgui_ext_linear_writew(uint32_t addr, uint16_t val, void *p) } } -static void tgui_ext_linear_writel(uint32_t addr, uint32_t val, void *p) +static void tgui_ext_linear_writel(uint32_t addr, uint32_t val, priv_t priv) { - tgui_ext_linear_writew(addr, val, p); + tgui_ext_linear_writew(addr, val, priv); } -static void tgui_ext_write(uint32_t addr, uint8_t val, void *p) +static void tgui_ext_write(uint32_t addr, uint8_t val, priv_t priv) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *)priv; addr = (addr & svga->banked_mask) + svga->read_bank; tgui_ext_linear_write(addr, val, svga); } -static void tgui_ext_writew(uint32_t addr, uint16_t val, void *p) +static void tgui_ext_writew(uint32_t addr, uint16_t val, priv_t priv) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *)priv; addr = (addr & svga->banked_mask) + svga->read_bank; tgui_ext_linear_writew(addr, val, svga); } -static void tgui_ext_writel(uint32_t addr, uint32_t val, void *p) +static void tgui_ext_writel(uint32_t addr, uint32_t val, priv_t priv) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *)priv; addr = (addr & svga->banked_mask) + svga->read_bank; @@ -1495,33 +1495,33 @@ static void tgui_queue(tgui_t *tgui, uint32_t addr, uint32_t val, uint32_t type) } -void tgui_accel_write(uint32_t addr, uint8_t val, void *p) +void tgui_accel_write(uint32_t addr, uint8_t val, priv_t priv) { - tgui_t *tgui = (tgui_t *)p; + tgui_t *tgui = (tgui_t *)priv; if ((addr & ~0xff) != 0xbff00) return; tgui_queue(tgui, addr, val, FIFO_WRITE_BYTE); } -void tgui_accel_write_w(uint32_t addr, uint16_t val, void *p) +void tgui_accel_write_w(uint32_t addr, uint16_t val, priv_t priv) { - tgui_t *tgui = (tgui_t *)p; + tgui_t *tgui = (tgui_t *)priv; tgui_accel_write(addr, val & 0xff, tgui); tgui_accel_write(addr + 1, val >> 8, tgui); } -void tgui_accel_write_l(uint32_t addr, uint32_t val, void *p) +void tgui_accel_write_l(uint32_t addr, uint32_t val, priv_t priv) { - tgui_t *tgui = (tgui_t *)p; + tgui_t *tgui = (tgui_t *)priv; tgui_accel_write(addr, val, tgui); tgui_accel_write(addr + 1, val >> 8, tgui); tgui_accel_write(addr + 2, val >> 16, tgui); tgui_accel_write(addr + 3, val >> 24, tgui); } -uint8_t tgui_accel_read(uint32_t addr, void *p) +uint8_t tgui_accel_read(uint32_t addr, priv_t priv) { - tgui_t *tgui = (tgui_t *)p; + tgui_t *tgui = (tgui_t *)priv; if ((addr & ~0xff) != 0xbff00) return 0xff; if ((addr & 0xff) != 0x20) @@ -1532,10 +1532,10 @@ uint8_t tgui_accel_read(uint32_t addr, void *p) if (!FIFO_EMPTY) return 1 << 5; return 0; - + case 0x27: /*ROP*/ return tgui->accel.rop; - + case 0x28: /*Flags*/ return tgui->accel.flags & 0xff; case 0x29: /*Flags*/ @@ -1543,7 +1543,7 @@ uint8_t tgui_accel_read(uint32_t addr, void *p) case 0x2b: return tgui->accel.offset; - + case 0x2c: /*Background colour*/ return tgui->accel.bg_col & 0xff; case 0x2d: /*Background colour*/ @@ -1580,7 +1580,7 @@ uint8_t tgui_accel_read(uint32_t addr, void *p) return tgui->accel.size_y & 0xff; case 0x43: /*Size Y*/ return tgui->accel.size_y >> 8; - + case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: case 0x88: case 0x89: case 0x8a: case 0x8b: @@ -1618,21 +1618,21 @@ uint8_t tgui_accel_read(uint32_t addr, void *p) return 0xff; } -uint16_t tgui_accel_read_w(uint32_t addr, void *p) +uint16_t tgui_accel_read_w(uint32_t addr, priv_t priv) { - tgui_t *tgui = (tgui_t *)p; + tgui_t *tgui = (tgui_t *)priv; return tgui_accel_read(addr, tgui) | (tgui_accel_read(addr + 1, tgui) << 8); } -uint32_t tgui_accel_read_l(uint32_t addr, void *p) +uint32_t tgui_accel_read_l(uint32_t addr, priv_t priv) { - tgui_t *tgui = (tgui_t *)p; + tgui_t *tgui = (tgui_t *)priv; return tgui_accel_read_w(addr, tgui) | (tgui_accel_read_w(addr + 2, tgui) << 16); } -void tgui_accel_write_fb_b(uint32_t addr, uint8_t val, void *p) +void tgui_accel_write_fb_b(uint32_t addr, uint8_t val, priv_t priv) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *)priv; tgui_t *tgui = (tgui_t *)svga->p; if (tgui->write_blitter) @@ -1641,9 +1641,9 @@ void tgui_accel_write_fb_b(uint32_t addr, uint8_t val, void *p) svga_write_linear(addr, val, svga); } -void tgui_accel_write_fb_w(uint32_t addr, uint16_t val, void *p) +void tgui_accel_write_fb_w(uint32_t addr, uint16_t val, priv_t priv) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *)priv; tgui_t *tgui = (tgui_t *)svga->p; if (tgui->write_blitter) @@ -1652,9 +1652,9 @@ void tgui_accel_write_fb_w(uint32_t addr, uint16_t val, void *p) svga_writew_linear(addr, val, svga); } -void tgui_accel_write_fb_l(uint32_t addr, uint32_t val, void *p) +void tgui_accel_write_fb_l(uint32_t addr, uint32_t val, priv_t priv) { - svga_t *svga = (svga_t *)p; + svga_t *svga = (svga_t *)priv; tgui_t *tgui = (tgui_t *)svga->p; if (tgui->write_blitter) @@ -1664,7 +1664,7 @@ void tgui_accel_write_fb_l(uint32_t addr, uint32_t val, void *p) } -static void * +static priv_t tgui_init(const device_t *info, UNUSED(void *parent)) { tgui_t *tgui = (tgui_t *)mem_alloc(sizeof(tgui_t)); @@ -1674,15 +1674,13 @@ tgui_init(const device_t *info, UNUSED(void *parent)) tgui->vram_size = device_get_config_int("memory") << 20; tgui->vram_mask = tgui->vram_size - 1; - + rom_init(&tgui->bios_rom, info->path, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); - svga_init(&tgui->svga, tgui, tgui->vram_size, - tgui_recalctimings, - tgui_in, tgui_out, - tgui_hwcursor_draw, - NULL); + svga_init(&tgui->svga, (priv_t)tgui, + tgui->vram_size, tgui_recalctimings, + tgui_in, tgui_out, tgui_hwcursor_draw, NULL); if (tgui->type == TGUI_9400CXI) tgui->svga.ramdac = device_add(&tkd8001_ramdac_device); @@ -1704,12 +1702,12 @@ tgui_init(const device_t *info, UNUSED(void *parent)) video_inform(DEVICE_VIDEO_GET(info->flags), &tgui_timing); - return tgui; + return (priv_t)tgui; } static void -tgui_close(void *priv) +tgui_close(priv_t priv) { tgui_t *tgui = (tgui_t *)priv; @@ -1724,7 +1722,7 @@ tgui_close(void *priv) static void -speed_changed(void *priv) +speed_changed(priv_t priv) { tgui_t *tgui = (tgui_t *)priv; @@ -1733,7 +1731,7 @@ speed_changed(void *priv) static void -force_redraw(void *priv) +force_redraw(priv_t priv) { tgui_t *tgui = (tgui_t *)priv; diff --git a/src/devices/video/vid_ti_cf62011.c b/src/devices/video/vid_ti_cf62011.c index 135047c..9758311 100644 --- a/src/devices/video/vid_ti_cf62011.c +++ b/src/devices/video/vid_ti_cf62011.c @@ -42,7 +42,7 @@ * which are the same as the XGA. It supports up to 1MB of VRAM, * but we lock it down to 512K. The PS/1 2122 had 256K. * - * Version: @(#)vid_ti_cf62011.c 1.0.10 2019/04/27 + * Version: @(#)vid_ti_cf62011.c 1.0.11 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -104,20 +104,20 @@ static const video_timings_t ti_cf62011_timing = {VID_ISA,8,16,32,8,16,32}; static void -vid_out(uint16_t addr, uint8_t val, void *priv) +vid_out(uint16_t addr, uint8_t val, priv_t priv) { - tivga_t *ti = (tivga_t *)priv; - svga_t *svga = &ti->svga; + tivga_t *dev = (tivga_t *)priv; + svga_t *svga = &dev->svga; uint8_t old; #if 0 - if (((addr & 0xfff0) == 0x03d0 || (addr & 0xfff0) == 0x03b0) && - !(svga->miscout & 1)) addr ^= 0x60; + if (((addr & 0xfff0) == 0x03d0 || + (addr & 0xfff0) == 0x03b0) && !(svga->miscout & 1)) addr ^= 0x60; #endif switch (addr) { case 0x0102: - ti->enabled = (val & 0x01); + dev->enabled = (val & 0x01); return; case 0x03d4: @@ -142,21 +142,21 @@ vid_out(uint16_t addr, uint8_t val, void *priv) break; case 0x2100: - ti->reg_2100 = val; + dev->reg_2100 = val; if ((val & 7) < 4) svga->read_bank = svga->write_bank = 0; else - svga->read_bank = svga->write_bank = (ti->banking & 0x7) * 0x10000; + svga->read_bank = svga->write_bank = (dev->banking & 0x7) * 0x10000; break; case 0x2108: - if ((ti->reg_2100 & 7) >= 4) + if ((dev->reg_2100 & 7) >= 4) svga->read_bank = svga->write_bank = (val & 0x7) * 0x10000; - ti->banking = val; + dev->banking = val; break; case 0x210a: - ti->reg_210a = val; + dev->reg_210a = val; break; } @@ -165,15 +165,15 @@ vid_out(uint16_t addr, uint8_t val, void *priv) static uint8_t -vid_in(uint16_t addr, void *priv) +vid_in(uint16_t addr, priv_t priv) { - tivga_t *ti = (tivga_t *)priv; - svga_t *svga = &ti->svga; + tivga_t *dev = (tivga_t *)priv; + svga_t *svga = &dev->svga; uint8_t ret; #if 0 - if (((addr & 0xfff0) == 0x03d0 || (addr & 0xfff0) == 0x03b0) && - !(svga->miscout & 1)) addr ^= 0x60; + if (((addr & 0xfff0) == 0x03d0 || + (addr & 0xfff0) == 0x03b0) && !(svga->miscout & 1)) addr ^= 0x60; #endif switch (addr) { @@ -186,7 +186,7 @@ vid_in(uint16_t addr, void *priv) break; case 0x0102: - ret = ti->enabled; + ret = dev->enabled; break; case 0x03d4: @@ -201,15 +201,15 @@ vid_in(uint16_t addr, void *priv) break; case 0x2100: - ret = ti->reg_2100; + ret = dev->reg_2100; break; case 0x2108: - ret = ti->banking; + ret = dev->banking; break; case 0x210a: - ret = ti->reg_210a; + ret = dev->reg_210a; break; default: @@ -222,92 +222,93 @@ vid_in(uint16_t addr, void *priv) static void -speed_changed(void *priv) +speed_changed(priv_t priv) { - tivga_t *ti = (tivga_t *)priv; + tivga_t *dev = (tivga_t *)priv; - svga_recalctimings(&ti->svga); + svga_recalctimings(&dev->svga); } static void -force_redraw(void *priv) +force_redraw(priv_t priv) { - tivga_t *ti = (tivga_t *)priv; + tivga_t *dev = (tivga_t *)priv; - ti->svga.fullchange = changeframecount; + dev->svga.fullchange = changeframecount; } static void -vid_close(void *priv) +vid_close(priv_t priv) { - tivga_t *ti = (tivga_t *)priv; + tivga_t *dev = (tivga_t *)priv; - svga_close(&ti->svga); + svga_close(&dev->svga); - free(ti); + free(dev); } -static void * +static priv_t vid_init(const device_t *info, UNUSED(void *parent)) { - tivga_t *ti; + tivga_t *dev; /* Allocate control block and initialize. */ - ti = (tivga_t *)mem_alloc(sizeof(tivga_t)); - memset(ti, 0x00, sizeof(tivga_t)); + dev = (tivga_t *)mem_alloc(sizeof(tivga_t)); + memset(dev, 0x00, sizeof(tivga_t)); /* Set amount of VRAM in KB. */ if (info->local == 0) - ti->vram_size = device_get_config_int("vram_size"); + dev->vram_size = device_get_config_int("vram_size"); else - ti->vram_size = info->local; + dev->vram_size = info->local; - DEBUG("VIDEO: initializing %s, %dK VRAM\n", info->name, ti->vram_size); + DEBUG("VIDEO: initializing %s, %iK VRAM\n", info->name, dev->vram_size); - svga_init(&ti->svga, ti, - ti->vram_size<<10, - NULL, vid_in, vid_out, NULL, NULL); + svga_init(&dev->svga, (priv_t)dev, + dev->vram_size << 10, NULL, vid_in, vid_out, NULL, NULL); - io_sethandler(0x0100, 2, vid_in, NULL, NULL, NULL, NULL, NULL, ti); - io_sethandler(0x03c0, 32, vid_in, NULL, NULL, vid_out, NULL, NULL, ti); - io_sethandler(0x2100, 16, vid_in, NULL, NULL, vid_out, NULL, NULL, ti); + io_sethandler(0x0100, 2, + vid_in,NULL,NULL, NULL,NULL,NULL, (priv_t)dev); + io_sethandler(0x03c0, 32, + vid_in,NULL,NULL, vid_out,NULL,NULL, (priv_t)dev); + io_sethandler(0x2100, 16, + vid_in,NULL,NULL, vid_out,NULL,NULL, (priv_t)dev); - ti->svga.bpp = 8; - ti->svga.miscout = 1; + dev->svga.bpp = 8; + dev->svga.miscout = 1; video_inform(DEVICE_VIDEO_GET(info->flags), (const video_timings_t *)info->vid_timing); - return(ti); + return((priv_t)dev); } #if defined(DEV_BRANCH) && defined(USE_TI) -static const device_config_t ti_cf62011_config[] = -{ - { - "vram_size", "Memory Size", CONFIG_SELECTION, "", 256, - { - { - "256K", 256 - }, - { - "512K", 512 - }, - { - "1024K", 1024 - }, - { - NULL - } - } - }, - { - NULL - } +static const device_config_t ti_cf62011_config[] = { + { + "vram_size", "Memory Size", CONFIG_SELECTION, "", 256, + { + { + "256K", 256 + }, + { + "512K", 512 + }, + { + "1024K", 1024 + }, + { + NULL + } + } + }, + { + NULL + } }; @@ -325,7 +326,6 @@ const device_t ti_cf62011_device = { }; #endif - const device_t ti_ps1_device = { "IBM PS/1 Model 2121 SVGA", DEVICE_VIDEO(VID_TYPE_SPEC) | DEVICE_ISA, diff --git a/src/devices/video/vid_tvga.c b/src/devices/video/vid_tvga.c index e0a7722..9c5e7b9 100644 --- a/src/devices/video/vid_tvga.c +++ b/src/devices/video/vid_tvga.c @@ -8,7 +8,7 @@ * * Trident TVGA (8900B/8900C/8900D) emulation. * - * Version: @(#)vid_tvga.c 1.0.14 2019/04/26 + * Version: @(#)vid_tvga.c 1.0.15 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -63,21 +63,21 @@ typedef struct { - mem_map_t linear_mapping; - mem_map_t accel_mapping; + mem_map_t linear_mapping; + mem_map_t accel_mapping; - svga_t svga; - - rom_t bios_rom; - uint8_t card_id; + svga_t svga; - uint8_t tvga_3d8, tvga_3d9; - int oldmode; - uint8_t oldctrl1; - uint8_t oldctrl2, newctrl2; + rom_t bios_rom; + uint8_t card_id; - int vram_size; - uint32_t vram_mask; + uint8_t tvga_3d8, tvga_3d9; + int oldmode; + uint8_t oldctrl1; + uint8_t oldctrl2, newctrl2; + + int vram_size; + uint32_t vram_mask; } tvga_t; @@ -91,49 +91,134 @@ static const uint8_t crtc_mask[0x40] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - - -static void tvga_recalcbanking(tvga_t *tvga); +static const video_timings_t tvga8900_timing = {VID_ISA,3,3,6,8,8,12}; static void -tvga_out(uint16_t addr, uint8_t val, void *priv) +recalc_banking(tvga_t *dev) { - tvga_t *tvga = (tvga_t *)priv; - svga_t *svga = &tvga->svga; + svga_t *svga = &dev->svga; + + svga->write_bank = (dev->tvga_3d8 & 0x1f) * 65536; + + if (svga->gdcreg[0xf] & 1) + svga->read_bank = (dev->tvga_3d9 & 0x1f) * 65536; + else + svga->read_bank = svga->write_bank; +} + + +static void +recalc_timings(svga_t *svga) +{ + tvga_t *dev = (tvga_t *)svga->p; + + /* + * This is the only sensible way I can see this being handled, + * given that TVGA8900D has no overflow bits. + * Some sort of overflow is required for 320x200x24 and 1024x768x16 + */ + if (!svga->rowoffset) svga->rowoffset = 0x100; + + if (svga->crtc[0x29] & 0x10) + svga->rowoffset += 0x100; + + if (svga->bpp == 24) + svga->hdisp = (svga->crtc[1] + 1) * 8; + + if ((svga->crtc[0x1e] & 0xA0) == 0xA0) svga->ma_latch |= 0x10000; + if ((svga->crtc[0x27] & 0x01) == 0x01) svga->ma_latch |= 0x20000; + if ((svga->crtc[0x27] & 0x02) == 0x02) svga->ma_latch |= 0x40000; + + if (dev->oldctrl2 & 0x10) { + svga->rowoffset <<= 1; + svga->ma_latch <<= 1; + } + + if (svga->gdcreg[0xf] & 0x08) { + svga->htotal *= 2; + svga->hdisp *= 2; + svga->hdisp_time *= 2; + } + + svga->interlace = (svga->crtc[0x1e] & 4); + + if (svga->interlace) + svga->rowoffset >>= 1; + + switch (((svga->miscout >> 2) & 3) | ((dev->newctrl2 << 2) & 4)) { + case 2: svga->clock = cpuclock/44900000.0; break; + case 3: svga->clock = cpuclock/36000000.0; break; + case 4: svga->clock = cpuclock/57272000.0; break; + case 5: svga->clock = cpuclock/65000000.0; break; + case 6: svga->clock = cpuclock/50350000.0; break; + case 7: svga->clock = cpuclock/40000000.0; break; + } + + if (dev->oldctrl2 & 0x10) { + switch (svga->bpp) { + case 8: + svga->render = svga_render_8bpp_highres; + break; + + case 15: + svga->render = svga_render_15bpp_highres; + svga->hdisp /= 2; + break; + + case 16: + svga->render = svga_render_16bpp_highres; + svga->hdisp /= 2; + break; + + case 24: + svga->render = svga_render_24bpp_highres; + svga->hdisp /= 3; + break; + } + svga->lowres = 0; + } +} + + +static void +tvga_out(uint16_t addr, uint8_t val, priv_t priv) +{ + tvga_t *dev = (tvga_t *)priv; + svga_t *svga = &dev->svga; uint8_t old; - if (((addr&0xfff0) == 0x3d0 || (addr&0xfff0) == 0x3b0) && - !(svga->miscout & 1)) addr ^= 0x60; + if (((addr&0xfff0) == 0x3d0 || + (addr&0xfff0) == 0x3b0) && !(svga->miscout & 1)) addr ^= 0x60; switch (addr) { case 0x3c5: switch (svga->seqaddr & 0x0f) { - case 0x0b: - tvga->oldmode = 1; + case 0x0b: + dev->oldmode = 1; break; - case 0x0c: - if (svga->seqregs[0xe] & 0x80) + case 0x0c: + if (svga->seqregs[0xe] & 0x80) svga->seqregs[0xc] = val; break; - case 0x0d: - if (tvga->oldmode) - tvga->oldctrl2 = val; + case 0x0d: + if (dev->oldmode) + dev->oldctrl2 = val; else { - tvga->newctrl2 = val; + dev->newctrl2 = val; svga_recalctimings(svga); } break; case 0x0e: - if (tvga->oldmode) - tvga->oldctrl1 = val; + if (dev->oldmode) + dev->oldctrl1 = val; else { svga->seqregs[0xe] = val ^ 2; - tvga->tvga_3d8 = svga->seqregs[0xe] & 0xf; - tvga_recalcbanking(tvga); + dev->tvga_3d8 = svga->seqregs[0xe] & 0xf; + recalc_banking(dev); } return; } @@ -150,13 +235,13 @@ tvga_out(uint16_t addr, uint8_t val, void *priv) switch (svga->gdcaddr & 15) { case 0x0e: svga->gdcreg[0xe] = val ^ 2; - tvga->tvga_3d9 = svga->gdcreg[0xe] & 0xf; - tvga_recalcbanking(tvga); + dev->tvga_3d9 = svga->gdcreg[0xe] & 0xf; + recalc_banking(dev); break; case 0x0f: svga->gdcreg[0xf] = val; - tvga_recalcbanking(tvga); + recalc_banking(dev); break; } break; @@ -181,7 +266,7 @@ tvga_out(uint16_t addr, uint8_t val, void *priv) } switch (svga->crtcreg) { case 0x1e: - svga->vram_display_mask = (val & 0x80) ? tvga->vram_mask : 0x3ffff; + svga->vram_display_mask = (val & 0x80) ? dev->vram_mask : 0x3ffff; break; default: @@ -191,15 +276,15 @@ tvga_out(uint16_t addr, uint8_t val, void *priv) case 0x3d8: if (svga->gdcreg[0xf] & 4) { - tvga->tvga_3d8 = val; - tvga_recalcbanking(tvga); + dev->tvga_3d8 = val; + recalc_banking(dev); } return; case 0x3d9: if (svga->gdcreg[0xf] & 4) { - tvga->tvga_3d9 = val; - tvga_recalcbanking(tvga); + dev->tvga_3d9 = val; + recalc_banking(dev); } return; } @@ -209,28 +294,28 @@ tvga_out(uint16_t addr, uint8_t val, void *priv) static uint8_t -tvga_in(uint16_t addr, void *priv) +tvga_in(uint16_t addr, priv_t priv) { - tvga_t *tvga = (tvga_t *)priv; - svga_t *svga = &tvga->svga; + tvga_t *dev = (tvga_t *)priv; + svga_t *svga = &dev->svga; - if (((addr&0xfff0) == 0x3d0 || (addr&0xfff0) == 0x3b0) && - !(svga->miscout & 1)) addr ^= 0x60; + if (((addr&0xfff0) == 0x3d0 || + (addr&0xfff0) == 0x3b0) && !(svga->miscout & 1)) addr ^= 0x60; switch (addr) { case 0x3c5: if ((svga->seqaddr & 0x0f) == 0x0b) { - tvga->oldmode = 0; - return tvga->card_id; /*Must be at least a TVGA8900*/ + dev->oldmode = 0; + return dev->card_id; /*Must be at least a TVGA8900*/ } if ((svga->seqaddr & 0x0f) == 0x0d) { - if (tvga->oldmode) - return tvga->oldctrl2; - return tvga->newctrl2; + if (dev->oldmode) + return dev->oldctrl2; + return dev->newctrl2; } if ((svga->seqaddr & 0x0f) == 0x0e) { - if (tvga->oldmode) - return tvga->oldctrl1; + if (dev->oldmode) + return dev->oldctrl1; } break; @@ -249,10 +334,10 @@ tvga_in(uint16_t addr, void *priv) return svga->crtc[svga->crtcreg]; case 0x3d8: - return tvga->tvga_3d8; + return dev->tvga_3d8; case 0x3d9: - return tvga->tvga_3d9; + return dev->tvga_3d9; } return svga_in(addr, svga); @@ -260,191 +345,101 @@ tvga_in(uint16_t addr, void *priv) static void -tvga_recalcbanking(tvga_t *tvga) +tvga_close(priv_t priv) { - svga_t *svga = &tvga->svga; + tvga_t *dev = (tvga_t *)priv; - svga->write_bank = (tvga->tvga_3d8 & 0x1f) * 65536; + svga_close(&dev->svga); - if (svga->gdcreg[0xf] & 1) - svga->read_bank = (tvga->tvga_3d9 & 0x1f) * 65536; - else - svga->read_bank = svga->write_bank; + free(dev); } static void -tvga_recalctimings(svga_t *svga) +speed_changed(priv_t priv) { - tvga_t *tvga = (tvga_t *)svga->p; + tvga_t *dev = (tvga_t *)priv; - /* - * This is the only sensible way I can see this being handled, - * given that TVGA8900D has no overflow bits. - * Some sort of overflow is required for 320x200x24 and 1024x768x16 - */ - if (!svga->rowoffset) svga->rowoffset = 0x100; - - if (svga->crtc[0x29] & 0x10) - svga->rowoffset += 0x100; - - if (svga->bpp == 24) - svga->hdisp = (svga->crtc[1] + 1) * 8; - - if ((svga->crtc[0x1e] & 0xA0) == 0xA0) svga->ma_latch |= 0x10000; - if ((svga->crtc[0x27] & 0x01) == 0x01) svga->ma_latch |= 0x20000; - if ((svga->crtc[0x27] & 0x02) == 0x02) svga->ma_latch |= 0x40000; - - if (tvga->oldctrl2 & 0x10) { - svga->rowoffset <<= 1; - svga->ma_latch <<= 1; - } - - if (svga->gdcreg[0xf] & 0x08) { - svga->htotal *= 2; - svga->hdisp *= 2; - svga->hdisp_time *= 2; - } - - svga->interlace = (svga->crtc[0x1e] & 4); - - if (svga->interlace) - svga->rowoffset >>= 1; - - switch (((svga->miscout >> 2) & 3) | ((tvga->newctrl2 << 2) & 4)) { - case 2: svga->clock = cpuclock/44900000.0; break; - case 3: svga->clock = cpuclock/36000000.0; break; - case 4: svga->clock = cpuclock/57272000.0; break; - case 5: svga->clock = cpuclock/65000000.0; break; - case 6: svga->clock = cpuclock/50350000.0; break; - case 7: svga->clock = cpuclock/40000000.0; break; - } - - if (tvga->oldctrl2 & 0x10) { - switch (svga->bpp) { - case 8: - svga->render = svga_render_8bpp_highres; - break; - - case 15: - svga->render = svga_render_15bpp_highres; - svga->hdisp /= 2; - break; - - case 16: - svga->render = svga_render_16bpp_highres; - svga->hdisp /= 2; - break; - - case 24: - svga->render = svga_render_24bpp_highres; - svga->hdisp /= 3; - break; - } - svga->lowres = 0; - } + svga_recalctimings(&dev->svga); } -static void * -tvga_init(const device_t *info, UNUSED(void *parent)) +static void +force_redraw(priv_t priv) { - tvga_t *tvga; + tvga_t *dev = (tvga_t *)priv; - tvga = (tvga_t *)mem_alloc(sizeof(tvga_t)); - memset(tvga, 0x00, sizeof(tvga_t)); - tvga->card_id = info->local; + dev->svga.fullchange = changeframecount; +} - tvga->vram_size = device_get_config_int("memory") << 10; - tvga->vram_mask = tvga->vram_size - 1; - svga_init(&tvga->svga, tvga, tvga->vram_size, - tvga_recalctimings, tvga_in, tvga_out, NULL, NULL); +static priv_t +tvga_init(const device_t *info, void *parent) +{ + tvga_t *dev; + + dev = (tvga_t *)mem_alloc(sizeof(tvga_t)); + memset(dev, 0x00, sizeof(tvga_t)); + dev->card_id = info->local; + + dev->vram_size = device_get_config_int("memory") << 10; + dev->vram_mask = dev->vram_size - 1; + + svga_init(&dev->svga, (priv_t)dev, dev->vram_size, + recalc_timings, tvga_in, tvga_out, NULL, NULL); switch(info->local) { case TVGA8900B_ID: /* TVGA 8900B */ - tvga->svga.ramdac = device_add(&tkd8001_ramdac_device); + dev->svga.ramdac = device_add_parent(&tkd8001_ramdac_device, parent); break; case TVGA8900CLD_ID: /* TVGA 8900CX LC2 */ - tvga->svga.ramdac = device_add(&tkd8001_ramdac_device); + dev->svga.ramdac = device_add_parent(&tkd8001_ramdac_device, parent); break; case 1: /* TVGA 8900D */ - tvga->svga.ramdac = device_add(&tkd8001_ramdac_device); + dev->svga.ramdac = device_add_parent(&tkd8001_ramdac_device, parent); break; } if (info->path) - rom_init(&tvga->bios_rom, info->path, + rom_init(&dev->bios_rom, info->path, 0xc0000, 0x8000, 0x7fff, 0, MEM_MAPPING_EXTERNAL); io_sethandler(0x03c0, 32, - tvga_in,NULL,NULL, tvga_out,NULL,NULL, tvga); + tvga_in,NULL,NULL, tvga_out,NULL,NULL, (priv_t)dev); video_inform(DEVICE_VIDEO_GET(info->flags), (const video_timings_t *)info->vid_timing); - return(tvga); + return((priv_t)dev); } -static void -tvga_close(void *priv) -{ - tvga_t *tvga = (tvga_t *)priv; - - svga_close(&tvga->svga); - - free(tvga); -} - - -static void -speed_changed(void *p) -{ - tvga_t *tvga = (tvga_t *)p; - - svga_recalctimings(&tvga->svga); -} - - -static void -force_redraw(void *p) -{ - tvga_t *tvga = (tvga_t *)p; - - tvga->svga.fullchange = changeframecount; -} - - -static const device_config_t tvga_config[] = -{ +static const device_config_t tvga_config[] = { + { + "memory", "Memory size", CONFIG_SELECTION, "", 1024, { - "memory", "Memory size", CONFIG_SELECTION, "", 1024, { - { - "256 KB", 256 - }, - { - "512 KB", 512 - }, - { - "1 MB", 1024 - }, - /*Chip supports 2MB, but drivers are buggy*/ - { - NULL - } + "256 KB", 256 + }, + { + "512 KB", 512 + }, + { + "1 MB", 1024 + }, + /*Chip supports 2MB, but drivers are buggy*/ + { + NULL } - }, - { - NULL } + }, + { + NULL + } }; -static const video_timings_t tvga8900_timing = {VID_ISA,3,3,6,8,8,12}; - const device_t tvga8900b_device = { "Trident TVGA 8900B", diff --git a/src/devices/video/vid_vga.c b/src/devices/video/vid_vga.c index 3236d15..34b0f61 100644 --- a/src/devices/video/vid_vga.c +++ b/src/devices/video/vid_vga.c @@ -8,7 +8,7 @@ * * IBM VGA emulation. * - * Version: @(#)vid_vga.c 1.0.10 2019/04/27 + * Version: @(#)vid_vga.c 1.0.11 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -61,16 +61,18 @@ typedef struct { } vga_t; +static video_timings_t vga_timing = {VID_ISA, 8,16,32, 8,16,32}; + + static void -vga_out(uint16_t port, uint8_t val, void *priv) +vga_out(uint16_t port, uint8_t val, priv_t priv) { vga_t *dev = (vga_t *)priv; svga_t *svga = &dev->svga; uint8_t old; if (((port & 0xfff0) == 0x3d0 || - (port & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) - port ^= 0x60; + (port & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) port ^= 0x60; switch (port) { case 0x3d4: @@ -100,15 +102,14 @@ vga_out(uint16_t port, uint8_t val, void *priv) static uint8_t -vga_in(uint16_t port, void *priv) +vga_in(uint16_t port, priv_t priv) { vga_t *dev = (vga_t *)priv; svga_t *svga = &dev->svga; uint8_t ret; if (((port & 0xfff0) == 0x3d0 || - (port & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) - port ^= 0x60; + (port & 0xfff0) == 0x3b0) && !(svga->miscout & 1)) port ^= 0x60; switch (port) { case 0x3d4: @@ -127,11 +128,40 @@ vga_in(uint16_t port, void *priv) break; } - return ret; + return(ret); } -static void * +static void +vga_close(priv_t priv) +{ + vga_t *dev = (vga_t *)priv; + + svga_close(&dev->svga); + + free(dev); +} + + +static void +speed_changed(priv_t priv) +{ + vga_t *dev = (vga_t *)priv; + + svga_recalctimings(&dev->svga); +} + + +static void +force_redraw(priv_t priv) +{ + vga_t *dev = (vga_t *)priv; + + dev->svga.fullchange = changeframecount; +} + + +static priv_t vga_init(const device_t *info, UNUSED(void *parent)) { vga_t *dev; @@ -143,11 +173,11 @@ vga_init(const device_t *info, UNUSED(void *parent)) rom_init(&dev->bios_rom, info->path, 0xc0000, 0x8000, 0x7fff, 0x2000, MEM_MAPPING_EXTERNAL); - svga_init(&dev->svga, dev, 1 << 18, /*256kb*/ + svga_init(&dev->svga, (priv_t)dev, 1 << 18, /*256kb*/ NULL, vga_in, vga_out, NULL, NULL); io_sethandler(0x03c0, 32, - vga_in,NULL,NULL, vga_out,NULL,NULL, dev); + vga_in,NULL,NULL, vga_out,NULL,NULL, (priv_t)dev); dev->svga.bpp = 8; dev->svga.miscout = 1; @@ -155,41 +185,10 @@ vga_init(const device_t *info, UNUSED(void *parent)) video_inform(DEVICE_VIDEO_GET(info->flags), (const video_timings_t *)info->vid_timing); - return(dev); + return((priv_t)dev); } -static void -vga_close(void *priv) -{ - vga_t *dev = (vga_t *)priv; - - svga_close(&dev->svga); - - free(dev); -} - - -static void -speed_changed(void *priv) -{ - vga_t *dev = (vga_t *)priv; - - svga_recalctimings(&dev->svga); -} - - -static void -force_redraw(void *priv) -{ - vga_t *dev = (vga_t *)priv; - - dev->svga.fullchange = changeframecount; -} - - -static video_timings_t vga_timing = {VID_ISA, 8,16,32, 8,16,32}; - const device_t vga_device = { "VGA", DEVICE_VIDEO(VID_TYPE_SPEC) | DEVICE_ISA, diff --git a/src/devices/video/vid_wy700.c b/src/devices/video/vid_wy700.c index 28c502c..4a3cd61 100644 --- a/src/devices/video/vid_wy700.c +++ b/src/devices/video/vid_wy700.c @@ -53,7 +53,7 @@ * What doesn't work, is untested or not well understood: * - Cursor detach (commands 4 and 5) * - * Version: @(#)vid_wy700.c 1.0.12 2019/05/05 + * Version: @(#)vid_wy700.c 1.0.13 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -226,7 +226,7 @@ typedef struct { int64_t dispontime, dispofftime; int64_t vidtime; - + int linepos, displine; int vc; int dispon, blink; @@ -245,6 +245,9 @@ typedef struct { } wy700_t; +static const video_timings_t wy700_timings = { VID_ISA,8,16,32,8,16,32 }; + + static void recalc_timings(wy700_t *dev) { @@ -287,15 +290,15 @@ check_changes(wy700_t *dev) dev->enabled = 1; dev->detach = 0; break; - + case 2: /* Font 1 */ dev->font = 0; break; - + case 3: /* Font 2 */ dev->font = 1; break; - + /* Even with the microprogram from an original card, I can't really work out * what commands 4 and 5 (which I've called 'cursor detach' / 'cursor attach') * do. Command 4 sets a flag in microcontroller RAM, and command 5 clears @@ -309,15 +312,15 @@ check_changes(wy700_t *dev) case 4: /* Detach cursor */ dev->detach = 1; break; - + case 5: /* Attach cursor */ dev->detach = 0; break; - + case 6: /* Disable display */ dev->enabled = 0; break; - + case 7: /* Enable display */ dev->enabled = 1; break; @@ -392,7 +395,7 @@ check_changes(wy700_t *dev) static void -wy700_out(uint16_t port, uint8_t val, void *priv) +wy700_out(uint16_t port, uint8_t val, priv_t priv) { wy700_t *dev = (wy700_t *)priv; @@ -446,7 +449,7 @@ wy700_out(uint16_t port, uint8_t val, void *priv) static uint8_t -wy700_in(uint16_t port, void *priv) +wy700_in(uint16_t port, priv_t priv) { wy700_t *dev = (wy700_t *)priv; @@ -477,7 +480,7 @@ wy700_in(uint16_t port, void *priv) static void -wy700_write(uint32_t addr, uint8_t val, void *priv) +wy700_write(uint32_t addr, uint8_t val, priv_t priv) { wy700_t *dev = (wy700_t *)priv; @@ -498,7 +501,7 @@ wy700_write(uint32_t addr, uint8_t val, void *priv) static uint8_t -wy700_read(uint32_t addr, void *priv) +wy700_read(uint32_t addr, priv_t priv) { wy700_t *dev = (wy700_t *)priv; @@ -746,7 +749,7 @@ hires_line(wy700_t *dev) static void -wy700_poll(void *priv) +wy700_poll(priv_t priv) { wy700_t *dev = (wy700_t *)priv; int mode; @@ -856,14 +859,14 @@ wy700_poll(void *priv) static int -load_font(wy700_t *dev, const wchar_t *s) +load_font(wy700_t *dev, const wchar_t *fn) { FILE *fp; int c; - fp = rom_fopen(s, L"rb"); + fp = rom_fopen(fn, L"rb"); if (fp == NULL) { - ERRLOG("%s: cannot load font '%ls'\n", dev->name, s); + ERRLOG("%s: cannot load font '%ls'\n", dev->name, fn); return(0); } @@ -876,7 +879,27 @@ load_font(wy700_t *dev, const wchar_t *s) } -static void * +static void +wy700_close(priv_t priv) +{ + wy700_t *dev = (wy700_t *)priv; + + free(dev->vram); + + free(dev); +} + + +static void +speed_changed(priv_t priv) +{ + wy700_t *dev = (wy700_t *)priv; + + recalc_timings(dev); +} + + +static priv_t wy700_init(const device_t *info, UNUSED(void *parent)) { wy700_t *dev; @@ -894,20 +917,20 @@ wy700_init(const device_t *info, UNUSED(void *parent)) /* 128K video RAM */ dev->vram = (uint8_t *)mem_alloc(0x20000); - timer_add(wy700_poll, dev, &dev->vidtime, TIMER_ALWAYS_ENABLED); + timer_add(wy700_poll, (priv_t)dev, &dev->vidtime, TIMER_ALWAYS_ENABLED); /* Occupy memory between 0xB0000 and 0xBFFFF (moves to 0xA0000 in * high-resolution modes) */ mem_map_add(&dev->mapping, 0xb0000, 0x10000, wy700_read,NULL,NULL, wy700_write,NULL,NULL, - NULL, MEM_MAPPING_EXTERNAL, dev); + NULL, MEM_MAPPING_EXTERNAL, (priv_t)dev); /* Respond to both MDA and CGA I/O ports */ io_sethandler(0x03b0, 12, - wy700_in,NULL,NULL, wy700_out,NULL,NULL, dev); + wy700_in,NULL,NULL, wy700_out,NULL,NULL, (priv_t)dev); io_sethandler(0x03d0, 16, - wy700_in,NULL,NULL, wy700_out,NULL,NULL, dev); + wy700_in,NULL,NULL, wy700_out,NULL,NULL, (priv_t)dev); /* Set up the emulated attributes. * CGA is done in four groups: 00-0F, 10-7F, 80-8F, 90-FF */ @@ -986,35 +1009,12 @@ wy700_init(const device_t *info, UNUSED(void *parent)) dev->enabled = 1; memcpy(dev->real_crtc, mode_80x24, sizeof(mode_80x24)); - video_inform(DEVICE_VIDEO_GET(info->flags), - (const video_timings_t *)info->vid_timing); + video_inform(DEVICE_VIDEO_GET(info->flags), &wy700_timings); - return(dev); + return((priv_t)dev); } -static void -wy700_close(void *priv) -{ - wy700_t *dev = (wy700_t *)priv; - - free(dev->vram); - - free(dev); -} - - -static void -speed_changed(void *priv) -{ - wy700_t *dev = (wy700_t *)priv; - - recalc_timings(dev); -} - - -static const video_timings_t wy700_timings = { VID_ISA,8,16,32,8,16,32 }; - const device_t wy700_device = { "Wyse 700", DEVICE_VIDEO(VID_TYPE_CGA) | DEVICE_ISA, @@ -1024,6 +1024,6 @@ const device_t wy700_device = { NULL, speed_changed, NULL, - &wy700_timings, + NULL, NULL }; diff --git a/src/emu.h b/src/emu.h index 616979b..ee09cea 100644 --- a/src/emu.h +++ b/src/emu.h @@ -8,7 +8,7 @@ * * Main include file for the application. * - * Version: @(#)emu.h 1.0.35 2019/05/03 + * Version: @(#)emu.h 1.0.36 2019/05/13 * * Author: Fred N. van Kempen, * @@ -156,6 +156,11 @@ extern "C" { #endif +/* Define global types. */ +typedef void *priv_t; /* generic "handle" type */ +//typedef float *priv_t; /* generic "handle" type */ + + /* Commandline option variables. */ extern int dump_on_exit; /* (O) dump regs on exit*/ extern int do_dump_config; /* (O) dump cfg after load */ diff --git a/src/io.c b/src/io.c index 8c41e8e..12af104 100644 --- a/src/io.c +++ b/src/io.c @@ -8,7 +8,7 @@ * * Implement I/O ports and their operations. * - * Version: @(#)io.c 1.0.4 2019/04/12 + * Version: @(#)io.c 1.0.5 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -50,15 +50,15 @@ typedef struct _io_ { - uint8_t (*inb)(uint16_t addr, void *priv); - uint16_t (*inw)(uint16_t addr, void *priv); - uint32_t (*inl)(uint16_t addr, void *priv); + uint8_t (*inb)(uint16_t addr, priv_t); + uint16_t (*inw)(uint16_t addr, priv_t); + uint32_t (*inl)(uint16_t addr, priv_t); - void (*outb)(uint16_t addr, uint8_t val, void *priv); - void (*outw)(uint16_t addr, uint16_t val, void *priv); - void (*outl)(uint16_t addr, uint32_t val, void *priv); + void (*outb)(uint16_t addr, uint8_t val, priv_t); + void (*outw)(uint16_t addr, uint16_t val, priv_t); + void (*outl)(uint16_t addr, uint32_t val, priv_t); - void *priv; + priv_t priv; struct _io_ *prev, *next; } io_t; @@ -70,12 +70,12 @@ static io_t *io[NPORTS], #ifdef IO_CATCH -static uint8_t null_inb(uint16_t addr, void *priv) { DEBUG("IO: read(%04x)\n"); return(0xff); } -static uint16_t null_inw(uint16_t addr, void *priv) { DEBUG("IO: readw(%04x)\n"); return(0xffff); } -static uint32_t null_inl(uint16_t addr, void *priv) { DEBUG("IO: readl(%04x)\n"); return(0xffffffff); } -static void null_outb(uint16_t addr, uint8_t val, void *priv) { DEBUG("IO: write(%04x, %02x)\n", val); } -static void null_outw(uint16_t addr, uint16_t val, void *priv) { DEBUG("IO: writew(%04x, %04x)\n", val); } -static void null_outl(uint16_t addr, uint32_t val, void *priv) { DEBUG("IO: writel(%04x, %08lx)\n", val); } +static uint8_t null_inb(uint16_t addr, priv_t p) { DEBUG("IO: read(%04x)\n"); return(0xff); } +static uint16_t null_inw(uint16_t addr, priv_t p) { DEBUG("IO: readw(%04x)\n"); return(0xffff); } +static uint32_t null_inl(uint16_t addr, priv_t p) { DEBUG("IO: readl(%04x)\n"); return(0xffffffff); } +static void null_outb(uint16_t addr, uint8_t val, priv_t p) { DEBUG("IO: write(%04x, %02x)\n", val); } +static void null_outw(uint16_t addr, uint16_t val, priv_t p) { DEBUG("IO: writew(%04x, %04x)\n", val); } +static void null_outl(uint16_t addr, uint32_t val, priv_t p) { DEBUG("IO: writel(%04x, %08lx)\n", val); } #endif @@ -127,13 +127,13 @@ io_reset(void) void io_sethandler(uint16_t base, int size, - uint8_t (*f_inb)(uint16_t addr, void *priv), - uint16_t (*f_inw)(uint16_t addr, void *priv), - uint32_t (*f_inl)(uint16_t addr, void *priv), - void (*f_outb)(uint16_t addr, uint8_t val, void *priv), - void (*f_outw)(uint16_t addr, uint16_t val, void *priv), - void (*f_outl)(uint16_t addr, uint32_t val, void *priv), - void *priv) + uint8_t (*f_inb)(uint16_t addr, priv_t priv), + uint16_t (*f_inw)(uint16_t addr, priv_t priv), + uint32_t (*f_inl)(uint16_t addr, priv_t priv), + void (*f_outb)(uint16_t addr, uint8_t val, priv_t priv), + void (*f_outw)(uint16_t addr, uint16_t val, priv_t priv), + void (*f_outl)(uint16_t addr, uint32_t val, priv_t priv), + priv_t priv) { io_t *p, *q = NULL; int c; @@ -164,13 +164,13 @@ io_sethandler(uint16_t base, int size, void io_removehandler(uint16_t base, int size, - uint8_t (*f_inb)(uint16_t addr, void *priv), - uint16_t (*f_inw)(uint16_t addr, void *priv), - uint32_t (*f_inl)(uint16_t addr, void *priv), - void (*f_outb)(uint16_t addr, uint8_t val, void *priv), - void (*f_outw)(uint16_t addr, uint16_t val, void *priv), - void (*f_outl)(uint16_t addr, uint32_t val, void *priv), - void *priv) + uint8_t (*f_inb)(uint16_t addr, priv_t priv), + uint16_t (*f_inw)(uint16_t addr, priv_t priv), + uint32_t (*f_inl)(uint16_t addr, priv_t priv), + void (*f_outb)(uint16_t addr, uint8_t val, priv_t priv), + void (*f_outw)(uint16_t addr, uint16_t val, priv_t priv), + void (*f_outl)(uint16_t addr, uint32_t val, priv_t priv), + priv_t priv) { io_t *p; int c; @@ -205,13 +205,13 @@ io_removehandler(uint16_t base, int size, #ifdef PC98 void io_sethandler_interleaved(uint16_t base, int size, - uint8_t (*f_inb)(uint16_t addr, void *priv), - uint16_t (*f_inw)(uint16_t addr, void *priv), - uint32_t (*f_inl)(uint16_t addr, void *priv), - void (*f_outb)(uint16_t addr, uint8_t val, void *priv), - void (*f_outw)(uint16_t addr, uint16_t val, void *priv), - void (*f_outl)(uint16_t addr, uint32_t val, void *priv), - void *priv) + uint8_t (*f_inb)(uint16_t addr, priv_t priv), + uint16_t (*f_inw)(uint16_t addr, priv_t priv), + uint32_t (*f_inl)(uint16_t addr, priv_t priv), + void (*f_outb)(uint16_t addr, uint8_t val, priv_t priv), + void (*f_outw)(uint16_t addr, uint16_t val, priv_t priv), + void (*f_outl)(uint16_t addr, uint32_t val, priv_t priv), + priv_t priv) { io_t *p, *q; int c; @@ -240,13 +240,13 @@ io_sethandler_interleaved(uint16_t base, int size, void io_removehandler_interleaved(uint16_t base, int size, - uint8_t (*f_inb)(uint16_t addr, void *priv), - uint16_t (*f_inw)(uint16_t addr, void *priv), - uint32_t (*f_inl)(uint16_t addr, void *priv), - void (*f_outb)(uint16_t addr, uint8_t val, void *priv), - void (*f_outw)(uint16_t addr, uint16_t val, void *priv), - void (*f_outl)(uint16_t addr, uint32_t val, void *priv), - void *priv) + uint8_t (*f_inb)(uint16_t addr, priv_t priv), + uint16_t (*f_inw)(uint16_t addr, priv_t priv), + uint32_t (*f_inl)(uint16_t addr, priv_t priv), + void (*f_outb)(uint16_t addr, uint8_t val, priv_t priv), + void (*f_outw)(uint16_t addr, uint16_t val, priv_t priv), + void (*f_outl)(uint16_t addr, uint32_t val, priv_t priv), + priv_t priv) { io_t *p; int c; diff --git a/src/io.h b/src/io.h index d99808f..f79c188 100644 --- a/src/io.h +++ b/src/io.h @@ -8,7 +8,7 @@ * * Definitions for the I/O handler. * - * Version: @(#)io.h 1.0.2 2019/04/12 + * Version: @(#)io.h 1.0.3 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -43,41 +43,41 @@ extern void io_reset(void); extern void io_sethandler(uint16_t base, int size, - uint8_t (*inb)(uint16_t addr, void *priv), - uint16_t (*inw)(uint16_t addr, void *priv), - uint32_t (*inl)(uint16_t addr, void *priv), - void (*outb)(uint16_t addr, uint8_t val, void *priv), - void (*outw)(uint16_t addr, uint16_t val, void *priv), - void (*outl)(uint16_t addr, uint32_t val, void *priv), - void *priv); + uint8_t (*inb)(uint16_t addr, priv_t), + uint16_t (*inw)(uint16_t addr, priv_t), + uint32_t (*inl)(uint16_t addr, priv_t), + void (*outb)(uint16_t addr, uint8_t val, priv_t), + void (*outw)(uint16_t addr, uint16_t val, priv_t), + void (*outl)(uint16_t addr, uint32_t val, priv_t), + priv_t); extern void io_removehandler(uint16_t base, int size, - uint8_t (*inb)(uint16_t addr, void *priv), - uint16_t (*inw)(uint16_t addr, void *priv), - uint32_t (*inl)(uint16_t addr, void *priv), - void (*outb)(uint16_t addr, uint8_t val, void *priv), - void (*outw)(uint16_t addr, uint16_t val, void *priv), - void (*outl)(uint16_t addr, uint32_t val, void *priv), - void *priv); + uint8_t (*inb)(uint16_t addr, priv_t), + uint16_t (*inw)(uint16_t addr, priv_t), + uint32_t (*inl)(uint16_t addr, priv_t), + void (*outb)(uint16_t addr, uint8_t val, priv_t), + void (*outw)(uint16_t addr, uint16_t val, priv_t), + void (*outl)(uint16_t addr, uint32_t val, priv_t), + priv_t); #ifdef PC98 extern void io_sethandler_interleaved(uint16_t base, int size, - uint8_t (*inb)(uint16_t addr, void *priv), - uint16_t (*inw)(uint16_t addr, void *priv), - uint32_t (*inl)(uint16_t addr, void *priv), - void (*outb)(uint16_t addr, uint8_t val, void *priv), - void (*outw)(uint16_t addr, uint16_t val, void *priv), - void (*outl)(uint16_t addr, uint32_t val, void *priv), - void *priv); + uint8_t (*inb)(uint16_t addr, priv_t), + uint16_t (*inw)(uint16_t addr, priv_t), + uint32_t (*inl)(uint16_t addr, priv_t), + void (*outb)(uint16_t addr, uint8_t val, priv_t), + void (*outw)(uint16_t addr, uint16_t val, priv_t), + void (*outl)(uint16_t addr, uint32_t val, priv_t), + priv_t); extern void io_removehandler_interleaved(uint16_t base, int size, - uint8_t (*inb)(uint16_t addr, void *priv), - uint16_t (*inw)(uint16_t addr, void *priv), - uint32_t (*inl)(uint16_t addr, void *priv), - void (*outb)(uint16_t addr, uint8_t val, void *priv), - void (*outw)(uint16_t addr, uint16_t val, void *priv), - void (*outl)(uint16_t addr, uint32_t val, void *priv), - void *priv); + uint8_t (*inb)(uint16_t addr, priv_t), + uint16_t (*inw)(uint16_t addr, priv_t), + uint32_t (*inl)(uint16_t addr, priv_t), + void (*outb)(uint16_t addr, uint8_t val, priv_t), + void (*outw)(uint16_t addr, uint16_t val, priv_t), + void (*outl)(uint16_t addr, uint32_t val, priv_t), + priv_t); #endif extern uint8_t inb(uint16_t port); diff --git a/src/machines/m_acer.c b/src/machines/m_acer.c index 15b4655..580aff5 100644 --- a/src/machines/m_acer.c +++ b/src/machines/m_acer.c @@ -8,7 +8,7 @@ * * Implementation of the Intel 430xx-based Acer machines. * - * Version: @(#)m_acer.c 1.0.2 2019/04/22 + * Version: @(#)m_acer.c 1.0.4 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -69,7 +69,7 @@ typedef struct { static void -m3a_out(uint16_t port, uint8_t val, void *priv) +m3a_out(uint16_t port, uint8_t val, priv_t priv) { acer_t *dev = (acer_t *)priv; @@ -79,7 +79,7 @@ m3a_out(uint16_t port, uint8_t val, void *priv) static uint8_t -m3a_in(uint16_t port, void *priv) +m3a_in(uint16_t port, priv_t priv) { acer_t *dev = (acer_t *)priv; @@ -95,7 +95,7 @@ m3a_in(uint16_t port, void *priv) static void -acer_close(void *priv) +acer_close(priv_t priv) { acer_t *dev = (acer_t *)priv; @@ -103,7 +103,7 @@ acer_close(void *priv) } -static void * +static priv_t acer_init(const device_t *info, void *arg) { acer_t *dev; @@ -113,7 +113,7 @@ acer_init(const device_t *info, void *arg) dev->type = info->local; /* Add machine device to system. */ - device_add_ex(info, dev); + device_add_ex(info, (priv_t)dev); m_at_common_init(); @@ -128,7 +128,7 @@ acer_init(const device_t *info, void *arg) pci_register_slot(0x1F, PCI_CARD_NORMAL, 4, 1, 2, 3); pci_register_slot(0x10, PCI_CARD_ONBOARD, 4, 0, 0, 0); - powermate_memregs_init(); + device_add(&memregs_powermate_device); device_add(&i430hx_device); device_add(&piix3_device); @@ -151,7 +151,7 @@ acer_init(const device_t *info, void *arg) pci_register_slot(0x14, PCI_CARD_NORMAL, 4, 1, 2, 3); pci_register_slot(0x0D, PCI_CARD_NORMAL, 1, 2, 3, 4); - powermate_memregs_init(); + device_add(&memregs_powermate_device); device_add(&i430hx_device); device_add(&piix3_device); @@ -174,7 +174,7 @@ acer_init(const device_t *info, void *arg) pci_register_slot(0x14, PCI_CARD_NORMAL, 4, 1, 2, 3); pci_register_slot(0x0D, PCI_CARD_NORMAL, 1, 2, 3, 4); - powermate_memregs_init(); + device_add(&memregs_powermate_device); device_add(&i430fx_device); device_add(&piix3_device); @@ -186,7 +186,7 @@ acer_init(const device_t *info, void *arg) break; } - return(dev); + return((priv_t)dev); } diff --git a/src/machines/m_ali.c b/src/machines/m_ali.c index 505aeee..643eabd 100644 --- a/src/machines/m_ali.c +++ b/src/machines/m_ali.c @@ -8,7 +8,7 @@ * * Implementation of the ALi-based machines. * - * Version: @(#)m_ali.c 1.0.8 2019/04/08 + * Version: @(#)m_ali.c 1.0.9 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -55,11 +55,11 @@ #include "machine.h" -static void * +static priv_t common_init(const device_t *info, void *arg) { /* Allocate machine device to system. */ - device_add_ex(info, arg); + device_add_ex(info, (priv_t)arg); device_add(&ali1429_device); @@ -74,7 +74,7 @@ common_init(const device_t *info, void *arg) break; } - return(arg); + return((priv_t)arg); } diff --git a/src/machines/m_amstrad.c b/src/machines/m_amstrad.c index d202b6b..eb2ca57 100644 --- a/src/machines/m_amstrad.c +++ b/src/machines/m_amstrad.c @@ -15,7 +15,7 @@ * 80 columns. To be fixed... * Also, the DDM bits stuff needs to be verified. * - * Version: @(#)m_amstrad.c 1.0.28 2019/05/03 + * Version: @(#)m_amstrad.c 1.0.29 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -117,7 +117,7 @@ typedef struct { pb; /* Video stuff. */ - void *vid; + priv_t vid; /* Mouse stuff. */ uint8_t mousex, @@ -135,7 +135,7 @@ static int key_queue_start = 0, static void -mse_write(uint16_t port, uint8_t val, void *priv) +mse_write(uint16_t port, uint8_t val, priv_t priv) { amstrad_t *dev = (amstrad_t *)priv; @@ -147,7 +147,7 @@ mse_write(uint16_t port, uint8_t val, void *priv) static uint8_t -mse_read(uint16_t port, void *priv) +mse_read(uint16_t port, priv_t priv) { amstrad_t *dev = (amstrad_t *)priv; uint8_t ret; @@ -165,7 +165,7 @@ mse_read(uint16_t port, void *priv) static int -mse_poll(int x, int y, int z, int b, void *priv) +mse_poll(int x, int y, int z, int b, priv_t priv) { amstrad_t *dev = (amstrad_t *)priv; @@ -204,7 +204,7 @@ kbd_adddata_ex(uint16_t val) static void -kbd_write(uint16_t port, uint8_t val, void *priv) +kbd_write(uint16_t port, uint8_t val, priv_t priv) { amstrad_t *dev = (amstrad_t *)priv; @@ -282,7 +282,7 @@ kbd_write(uint16_t port, uint8_t val, void *priv) static uint8_t -kbd_read(uint16_t port, void *priv) +kbd_read(uint16_t port, priv_t priv) { amstrad_t *dev = (amstrad_t *)priv; uint8_t ret = 0xff; @@ -373,7 +373,7 @@ kbd_read(uint16_t port, void *priv) static void -kbd_poll(void *priv) +kbd_poll(priv_t priv) { amstrad_t *dev = (amstrad_t *)priv; @@ -394,7 +394,7 @@ kbd_poll(void *priv) static void -ams_write(uint16_t port, uint8_t val, void *priv) +ams_write(uint16_t port, uint8_t val, priv_t priv) { amstrad_t *dev = (amstrad_t *)priv; @@ -407,7 +407,7 @@ ams_write(uint16_t port, uint8_t val, void *priv) static uint8_t -ams_read(uint16_t port, void *priv) +ams_read(uint16_t port, priv_t priv) { amstrad_t *dev = (amstrad_t *)priv; uint8_t ddm, ret = 0xff; @@ -484,7 +484,7 @@ ams_read(uint16_t port, void *priv) static void -amstrad_close(void *priv) +amstrad_close(priv_t priv) { amstrad_t *dev = (amstrad_t *)priv; @@ -492,7 +492,7 @@ amstrad_close(void *priv) } -static void * +static priv_t amstrad_init(const device_t *info, void *arg) { romdef_t *roms = (romdef_t *)arg; @@ -504,7 +504,7 @@ amstrad_init(const device_t *info, void *arg) dev->type = info->local; /* Add machine device to system. */ - device_add_ex(info, dev); + device_add_ex(info, (priv_t)dev); /* Force the LPT1 port disabled and add our own. */ config.parallel_enabled[0] = 0; @@ -525,7 +525,7 @@ amstrad_init(const device_t *info, void *arg) roms->fontnum, dev->codepage); device_add(&fdc_xt_device); - parallel_set_func(lpt, ams_read, dev); + parallel_set_func(lpt, ams_read, (priv_t)dev); break; case 1: /* PC1640 */ @@ -535,7 +535,7 @@ amstrad_init(const device_t *info, void *arg) dev->vid = m_amstrad_1640_vid_init(roms->vidfn, roms->vidsz); device_add(&fdc_xt_device); - parallel_set_func(lpt, ams_read, dev); + parallel_set_func(lpt, ams_read, (priv_t)dev); break; case 2: /* PC200 */ @@ -557,7 +557,7 @@ amstrad_init(const device_t *info, void *arg) } device_add(&fdc_xt_device); - parallel_set_func(lpt, ams_read, dev); + parallel_set_func(lpt, ams_read, (priv_t)dev); break; case 3: /* PPC */ @@ -575,7 +575,7 @@ amstrad_init(const device_t *info, void *arg) } device_add(&fdc_xt_device); - parallel_set_func(lpt, ams_read, dev); + parallel_set_func(lpt, ams_read, (priv_t)dev); break; case 4: /* PC2086 */ @@ -621,10 +621,10 @@ amstrad_init(const device_t *info, void *arg) mouse_reset(); - mouse_set_poll(mse_poll, dev); + mouse_set_poll(mse_poll, (priv_t)dev); } - return(dev); + return((priv_t)dev); } diff --git a/src/machines/m_amstrad.h b/src/machines/m_amstrad.h index a136ecf..848fb3f 100644 --- a/src/machines/m_amstrad.h +++ b/src/machines/m_amstrad.h @@ -8,7 +8,7 @@ * * Definitions for the Amstrad machines. * - * Version: @(#)m_amstrad.h 1.0.2 2019/04/14 + * Version: @(#)m_amstrad.h 1.0.3 2019/05/13 * * Author: Fred N. van Kempen, * @@ -67,13 +67,13 @@ extern const device_t m_amstrad_mega; #endif -extern void *m_amstrad_1512_vid_init(const wchar_t *fn, int fnt, int cp); +extern priv_t m_amstrad_1512_vid_init(const wchar_t *fn, int fnt, int cp); -extern void *m_amstrad_1640_vid_init(const wchar_t *fn, int sz); +extern priv_t m_amstrad_1640_vid_init(const wchar_t *fn, int sz); -extern void *m_amstrad_ida_init(int type, const wchar_t *fn, +extern priv_t m_amstrad_ida_init(int type, const wchar_t *fn, int cp, int em, int dt); -extern uint8_t m_amstrad_ida_ddm(void *arg); +extern uint8_t m_amstrad_ida_ddm(priv_t); #endif /*MACHINE_AMSTRAD_H*/ diff --git a/src/machines/m_amstrad_vid.c b/src/machines/m_amstrad_vid.c index a837c71..474dc63 100644 --- a/src/machines/m_amstrad_vid.c +++ b/src/machines/m_amstrad_vid.c @@ -25,7 +25,7 @@ * by the ROS. * PPC: MDA Monitor results in half-screen, half-cell-height display?? * - * Version: @(#)m_amstrad_vid.c 1.0.4 2019/05/05 + * Version: @(#)m_amstrad_vid.c 1.0.5 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -211,7 +211,7 @@ pc1512_recalc_timings(vid_t *dev) static void -pc1512_out(uint16_t addr, uint8_t val, void *priv) +pc1512_out(uint16_t addr, uint8_t val, priv_t priv) { vid_t *dev = (vid_t *)priv; uint8_t old; @@ -260,7 +260,7 @@ pc1512_out(uint16_t addr, uint8_t val, void *priv) static uint8_t -pc1512_in(uint16_t addr, void *priv) +pc1512_in(uint16_t addr, priv_t priv) { vid_t *dev = (vid_t *)priv; uint8_t ret = 0xff; @@ -281,7 +281,7 @@ pc1512_in(uint16_t addr, void *priv) static void -pc1512_write(uint32_t addr, uint8_t val, void *priv) +pc1512_write(uint32_t addr, uint8_t val, priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -303,7 +303,7 @@ pc1512_write(uint32_t addr, uint8_t val, void *priv) static uint8_t -pc1512_read(uint32_t addr, void *priv) +pc1512_read(uint32_t addr, priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -318,7 +318,7 @@ pc1512_read(uint32_t addr, void *priv) static void -pc1512_poll(void *priv) +pc1512_poll(priv_t priv) { vid_t *dev = (vid_t *)priv; uint16_t ca = (dev->crtc[15] | (dev->crtc[14] << 8)) & 0x3fff; @@ -560,7 +560,7 @@ pc1512_poll(void *priv) static void -pc1512_close(void *priv) +pc1512_close(priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -571,7 +571,7 @@ pc1512_close(void *priv) static void -pc1512_speed_change(void *priv) +pc1512_speed_change(priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -592,7 +592,7 @@ static const device_t pc1512_video_device = { /* Initialize the PC1512 display controller, return the correct DDM bits. */ -void * +priv_t m_amstrad_1512_vid_init(const wchar_t *fn, int fnt, int cp) { vid_t *dev; @@ -645,7 +645,7 @@ m_amstrad_1512_vid_init(const wchar_t *fn, int fnt, int cp) video_inform(VID_TYPE_CGA, &pc1512_timing); - return(dev); + return((priv_t)dev); } @@ -671,7 +671,7 @@ pc1640_recalc_timings(vid_t *dev) static void -pc1640_out(uint16_t addr, uint8_t val, void *priv) +pc1640_out(uint16_t addr, uint8_t val, priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -731,7 +731,7 @@ pc1640_out(uint16_t addr, uint8_t val, void *priv) static uint8_t -pc1640_in(uint16_t addr, void *priv) +pc1640_in(uint16_t addr, priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -748,7 +748,7 @@ pc1640_in(uint16_t addr, void *priv) static void -pc1640_poll(void *priv) +pc1640_poll(priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -769,7 +769,7 @@ pc1640_poll(void *priv) static void -pc1640_close(void *priv) +pc1640_close(priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -780,7 +780,7 @@ pc1640_close(void *priv) static void -pc1640_speed_changed(void *priv) +pc1640_speed_changed(priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -801,7 +801,7 @@ static const device_t pc1640_video_device = { /* Initialize the PC1640 display controller, return the correct DDM bits. */ -void * +priv_t m_amstrad_1640_vid_init(const wchar_t *fn, int sz) { vid_t *dev; @@ -835,7 +835,7 @@ m_amstrad_1640_vid_init(const wchar_t *fn, int sz) video_inform(VID_TYPE_CGA, &pc1640_timing); - return(dev); + return((priv_t)dev); } @@ -1310,7 +1310,7 @@ cga->ma++; static void -ida_poll(void *priv) +ida_poll(priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -1340,7 +1340,7 @@ ida_poll(void *priv) static void -ida_out(uint16_t addr, uint8_t val, void *priv) +ida_out(uint16_t addr, uint8_t val, priv_t priv) { vid_t *dev = (vid_t *)priv; cga_t *cga = &dev->cga; @@ -1511,7 +1511,7 @@ ida_out(uint16_t addr, uint8_t val, void *priv) static uint8_t -ida_in(uint16_t addr, void *priv) +ida_in(uint16_t addr, priv_t priv) { vid_t *dev = (vid_t *)priv; cga_t *cga = &dev->cga; @@ -1552,7 +1552,7 @@ ida_in(uint16_t addr, void *priv) static void -ida_close(void *priv) +ida_close(priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -1563,7 +1563,7 @@ ida_close(void *priv) static void -ida_speed_changed(void *priv) +ida_speed_changed(priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -1587,7 +1587,7 @@ static const device_t ida_video_device = { /* Initialize the PC200/PPC display controller, return the correct DDM bits. */ -void * +priv_t m_amstrad_ida_init(int type, const wchar_t *fn, int cp, int em, int dt) { vid_t *dev; @@ -1717,12 +1717,12 @@ m_amstrad_ida_init(int type, const wchar_t *fn, int cp, int em, int dt) else video_inform(VID_TYPE_CGA, &ida_timing); - return(dev); + return((priv_t)dev); } uint8_t -m_amstrad_ida_ddm(void *arg) +m_amstrad_ida_ddm(priv_t arg) { vid_t *dev = (vid_t *)arg; uint8_t ret = 0x00; diff --git a/src/machines/m_aopen.c b/src/machines/m_aopen.c index b77c447..2ba1280 100644 --- a/src/machines/m_aopen.c +++ b/src/machines/m_aopen.c @@ -8,7 +8,7 @@ * * Implementation of various A/Open mainboards. * - * Version: @(#)m_aopen.c 1.0.1 2019/04/08 + * Version: @(#)m_aopen.c 1.0.2 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -63,11 +63,11 @@ #include "machine.h" -static void * +static priv_t common_init(const device_t *info, void *arg) { /* Allocate machine device to system. */ - device_add_ex(info, arg); + device_add_ex(info, (priv_t)arg); switch(info->local) { /* AP53: AOpen AP53/430HX/AMI/SMC FDC37C665/669 */ @@ -81,8 +81,8 @@ common_init(const device_t *info, void *arg) pci_register_slot(0x07, PCI_CARD_SPECIAL, 0, 0, 0, 0); pci_register_slot(0x06, PCI_CARD_ONBOARD, 1, 2, 3, 4); - memregs_init(); - powermate_memregs_init(); + device_add(&memregs_device); + device_add(&memregs_powermate_device); device_add(&i430hx_device); device_add(&piix3_device); @@ -96,7 +96,7 @@ common_init(const device_t *info, void *arg) break; } - return(arg); + return((priv_t)arg); } diff --git a/src/machines/m_asus.c b/src/machines/m_asus.c index da343b5..094da6e 100644 --- a/src/machines/m_asus.c +++ b/src/machines/m_asus.c @@ -8,7 +8,7 @@ * * Implementation of several ASUS mainboards. * - * Version: @(#)m_asus.c 1.0.1 2019/04/08 + * Version: @(#)m_asus.c 1.0.2 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -60,11 +60,11 @@ #include "machine.h" -static void * +static priv_t common_init(const device_t *info, void *arg) { /* Allocate machine device to system. */ - device_add_ex(info, arg); + device_add_ex(info, (priv_t)arg); switch(info->local) { /* P54TP4XE: ASUS P/I-P55TP4XE/430FX/Award/SMC FDC37C665 */ @@ -77,7 +77,7 @@ common_init(const device_t *info, void *arg) pci_register_slot(0x09, PCI_CARD_NORMAL, 4, 1, 2, 3); pci_register_slot(0x07, PCI_CARD_SPECIAL, 0, 0, 0, 0); - memregs_init(); + device_add(&memregs_device); device_add(&i430fx_device); device_add(&piix_device); @@ -99,7 +99,7 @@ common_init(const device_t *info, void *arg) pci_register_slot(0x09, PCI_CARD_NORMAL, 4, 1, 2, 3); pci_register_slot(0x07, PCI_CARD_SPECIAL, 0, 0, 0, 0); - memregs_init(); + device_add(&memregs_device); device_add(&i430hx_device); device_add(&piix3_device); @@ -121,7 +121,7 @@ common_init(const device_t *info, void *arg) pci_register_slot(0x09, PCI_CARD_NORMAL, 4, 1, 2, 3); pci_register_slot(0x07, PCI_CARD_SPECIAL, 0, 0, 0, 0); - memregs_init(); + device_add(&memregs_device); device_add(&i430vx_device); device_add(&piix3_device); @@ -134,7 +134,7 @@ common_init(const device_t *info, void *arg) break; } - return(arg); + return((priv_t)arg); } diff --git a/src/machines/m_at.c b/src/machines/m_at.c index b1b05cb..61e00a6 100644 --- a/src/machines/m_at.c +++ b/src/machines/m_at.c @@ -8,7 +8,7 @@ * * Standard PC/AT implementation. * - * Version: @(#)m_at.c 1.0.14 2019/05/05 + * Version: @(#)m_at.c 1.0.15 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -115,10 +115,10 @@ m_at_ps2_ide_init(void) } -static void * +static priv_t ibm_at_init(const device_t *info, void *arg) { - device_add_ex(info, arg); + device_add_ex(info, (priv_t)arg); m_at_init(); @@ -126,7 +126,7 @@ ibm_at_init(const device_t *info, void *arg) device_add(&fdc_at_device); - return(arg); + return((priv_t)arg); } diff --git a/src/machines/m_bull.c b/src/machines/m_bull.c index a7d5d7e..f695d1b 100644 --- a/src/machines/m_bull.c +++ b/src/machines/m_bull.c @@ -18,7 +18,7 @@ * * Other than the above, the machine works as expected. * - * Version: @(#)m_bull.c 1.0.2 2019/05/03 + * Version: @(#)m_bull.c 1.0.3 2019/05/13 * * Authors: Fred N. van Kempen, * Idea from a patch for PCem by DNS2KV2, but fully rewritten. @@ -77,15 +77,15 @@ #include "machine.h" -static void * +static priv_t common_init(const device_t *info, void *arg) { int ega, mouse, scsi; - void *priv; + priv_t priv; int irq; /* Allocate machine device to system. */ - device_add_ex(info, arg); + device_add_ex(info, (priv_t)arg); ega = machine_get_config_int("pega"); mouse = machine_get_config_int("mouse"); @@ -123,7 +123,7 @@ common_init(const device_t *info, void *arg) break; } - return(arg); + return((priv_t)arg); } diff --git a/src/machines/m_commodore.c b/src/machines/m_commodore.c index c80b075..a3a4eb8 100644 --- a/src/machines/m_commodore.c +++ b/src/machines/m_commodore.c @@ -8,7 +8,7 @@ * * Implementation of the Commodore PC-30 system. * - * Version: @(#)m_commodore.c 1.0.14 2019/04/08 + * Version: @(#)m_commodore.c 1.0.15 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -59,7 +59,7 @@ typedef struct { static void -pc30_write(uint16_t port, uint8_t val, void *priv) +pc30_write(uint16_t port, uint8_t val, priv_t priv) { switch (val & 0x03) { case 1: @@ -88,7 +88,7 @@ pc30_write(uint16_t port, uint8_t val, void *priv) static void -pc30_close(void *priv) +pc30_close(priv_t priv) { pc30_t *dev = (pc30_t *)priv; @@ -96,7 +96,7 @@ pc30_close(void *priv) } -static void * +static priv_t pc30_init(const device_t *info, void *arg) { pc30_t *dev; @@ -106,7 +106,7 @@ pc30_init(const device_t *info, void *arg) dev->type = info->local; /* Add machine device to system. */ - device_add_ex(info, dev); + device_add_ex(info, (priv_t)dev); m_at_ide_init(); @@ -117,7 +117,7 @@ pc30_init(const device_t *info, void *arg) io_sethandler(0x0230, 1, NULL,NULL,NULL, pc30_write,NULL,NULL, NULL); - return(dev); + return((priv_t)dev); } diff --git a/src/machines/m_compaq.c b/src/machines/m_compaq.c index cc93d5c..47e5934 100644 --- a/src/machines/m_compaq.c +++ b/src/machines/m_compaq.c @@ -14,7 +14,7 @@ * (which is in m_compaq_vid.c), the Portable 3 needs the * Plasma driver, there are some ROM issues, etc. * - * Version: @(#)m_compaq.c 1.0.13 2019/05/05 + * Version: @(#)m_compaq.c 1.0.14 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -77,7 +77,7 @@ typedef struct { static uint8_t -read_ram(uint32_t addr, void *priv) +read_ram(uint32_t addr, priv_t priv) { // cpq_t *dev = (cpq_t *)priv; @@ -89,7 +89,7 @@ read_ram(uint32_t addr, void *priv) static uint16_t -read_ramw(uint32_t addr, void *priv) +read_ramw(uint32_t addr, priv_t priv) { // cpq_t *dev = (cpq_t *)priv; @@ -101,7 +101,7 @@ read_ramw(uint32_t addr, void *priv) static uint32_t -read_raml(uint32_t addr, void *priv) +read_raml(uint32_t addr, priv_t priv) { // cpq_t *dev = (cpq_t *)priv; @@ -113,7 +113,7 @@ read_raml(uint32_t addr, void *priv) static void -write_ram(uint32_t addr, uint8_t val, void *priv) +write_ram(uint32_t addr, uint8_t val, priv_t priv) { // cpq_t *dev = (cpq_t *)priv; @@ -125,7 +125,7 @@ write_ram(uint32_t addr, uint8_t val, void *priv) static void -write_ramw(uint32_t addr, uint16_t val, void *priv) +write_ramw(uint32_t addr, uint16_t val, priv_t priv) { // cpq_t *dev = (cpq_t *)priv; @@ -137,7 +137,7 @@ write_ramw(uint32_t addr, uint16_t val, void *priv) static void -write_raml(uint32_t addr, uint32_t val, void *priv) +write_raml(uint32_t addr, uint32_t val, priv_t priv) { // cpq_t *dev = (cpq_t *)priv; @@ -149,7 +149,7 @@ write_raml(uint32_t addr, uint32_t val, void *priv) static void -cpq_close(void *priv) +cpq_close(priv_t priv) { cpq_t *dev = (cpq_t *)priv; @@ -157,7 +157,7 @@ cpq_close(void *priv) } -static void * +static priv_t cpq_init(const device_t *info, void *arg) { cpq_t *dev; @@ -167,7 +167,7 @@ cpq_init(const device_t *info, void *arg) dev->type = info->local; /* Add machine device to system. */ - device_add_ex(info, dev); + device_add_ex(info, (priv_t)dev); switch(dev->type) { case 0: /* Portable */ @@ -256,7 +256,7 @@ cpq_init(const device_t *info, void *arg) break; } - return(dev); + return((priv_t)dev); } diff --git a/src/machines/m_compaq_vid.c b/src/machines/m_compaq_vid.c index 5e979ed..738fb82 100644 --- a/src/machines/m_compaq_vid.c +++ b/src/machines/m_compaq_vid.c @@ -19,7 +19,7 @@ * plasma display. The code for this was taken from the code * for the Toshiba 3100e machine, which used a similar display. * - * Version: @(#)m_compaq_vid.c 1.0.2 2019/04/25 + * Version: @(#)m_compaq_vid.c 1.0.3 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -60,6 +60,7 @@ #include "../rom.h" #include "../device.h" #include "../timer.h" +#include "../plat.h" #include "../devices/system/nmi.h" #include "../devices/system/pit.h" #include "../devices/video/video.h" @@ -245,7 +246,7 @@ recalc_attrs(vid_t *dev) static void -vid_poll_plasma(void *priv) +vid_poll_plasma(priv_t priv) { vid_t *dev = (vid_t *)priv; cga_t *cga = &dev->cga; @@ -500,7 +501,7 @@ vid_poll_plasma(void *priv) static void -vid_poll(void *priv) +vid_poll(priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -518,7 +519,7 @@ INFO("CPQ: poll (mode=%i)\n", dev->mode); static void -vid_out(uint16_t addr, uint8_t val, void *priv) +vid_out(uint16_t addr, uint8_t val, priv_t priv) { vid_t *dev = (vid_t *)priv; mda_t *mda = &dev->mda; @@ -595,7 +596,7 @@ INFO("CPQ: write(%04x, %02x)\n", addr, val); static uint8_t -vid_in(uint16_t addr, void *priv) +vid_in(uint16_t addr, priv_t priv) { vid_t *dev = (vid_t *)priv; mda_t *mda = &dev->mda; @@ -643,7 +644,7 @@ INFO("%02x\n", ret); static void -vid_write(uint32_t addr, uint8_t val, void *priv) +vid_write(uint32_t addr, uint8_t val, priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -654,7 +655,7 @@ vid_write(uint32_t addr, uint8_t val, void *priv) static uint8_t -vid_read(uint32_t addr, void *priv) +vid_read(uint32_t addr, priv_t priv) { vid_t *dev = (vid_t *)priv; uint8_t ret; @@ -668,7 +669,7 @@ vid_read(uint32_t addr, void *priv) static void -vid_close(void *priv) +vid_close(priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -680,7 +681,7 @@ vid_close(void *priv) static void -speed_changed(void *priv) +speed_changed(priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -693,8 +694,8 @@ INFO("CPQ: speed_changed(mode=%i)\n", dev->mode); } -static void * -vid_init(const device_t *info, void *arg) +static priv_t +vid_init(const device_t *info, UNUSED(void *parent)) { vid_t *dev; @@ -751,7 +752,7 @@ INFO("CPQ: video_init(type=%i)\n", dev->type); video_inform(VID_TYPE_CGA, &cpq_timing); #endif - return(dev); + return((priv_t)dev); } diff --git a/src/machines/m_europc.c b/src/machines/m_europc.c index 683f3c4..347388a 100644 --- a/src/machines/m_europc.c +++ b/src/machines/m_europc.c @@ -69,7 +69,7 @@ * FIXME: Find a new way to handle the switching of color/mono on * external cards. New video_get_type(int card) function? * - * Version: @(#)m_europc.c 1.0.25 2019/05/05 + * Version: @(#)m_europc.c 1.0.26 2019/05/13 * * Author: Fred N. van Kempen, * @@ -234,7 +234,7 @@ rtc_time_get(uint8_t *regs, struct tm *tm) /* Set the current NVR time. */ static void -rtc_time_set(uint8_t *regs, struct tm *tm) +rtc_time_set(uint8_t *regs, const struct tm *tm) { /* NVR is in BCD data mode. */ regs[MRTC_SECONDS] = RTC_BCD(tm->tm_sec); @@ -432,7 +432,7 @@ jim_set(europc_t *dev, uint8_t reg, uint8_t val) /* Write to one of the JIM registers. */ static void -jim_write(uint16_t addr, uint8_t val, void *priv) +jim_write(uint16_t addr, uint8_t val, priv_t priv) { europc_t *dev = (europc_t *)priv; uint8_t b; @@ -485,7 +485,7 @@ jim_write(uint16_t addr, uint8_t val, void *priv) /* Read from one of the JIM registers. */ static uint8_t -jim_read(uint16_t addr, void *priv) +jim_read(uint16_t addr, priv_t priv) { europc_t *dev = (europc_t *)priv; uint8_t r = 0xff; @@ -534,6 +534,21 @@ jim_read(uint16_t addr, void *priv) } +static void +europc_close(priv_t priv) +{ + europc_t *dev = (europc_t *)priv; + nvr_t *nvr = &dev->nvr; + + if (nvr->fn != NULL) { + free((wchar_t *)nvr->fn); + nvr->fn = NULL; + } + + free(dev); +} + + /* * Initialize the mainboard 'device' of the machine. * @@ -542,7 +557,7 @@ jim_read(uint16_t addr, void *priv) * allows it to reset (dev init) and configured by the * user. */ -static void * +static priv_t europc_init(const device_t *info, void *arg) { europc_t *dev; @@ -555,7 +570,7 @@ europc_init(const device_t *info, void *arg) memset(dev, 0x00, sizeof(europc_t)); /* Add the machine device. */ - device_add_ex(info, dev); + device_add_ex(info, (priv_t)dev); /* Get configurable things. */ i = machine_get_config_int("js9"); @@ -752,22 +767,7 @@ europc_init(const device_t *info, void *arg) if (config.hdc_type == HDC_INTERNAL) (void)device_add(&xta_hd20_device); - return(dev); -} - - -static void -europc_close(void *priv) -{ - europc_t *dev = (europc_t *)priv; - nvr_t *nvr = &dev->nvr; - - if (nvr->fn != NULL) { - free((wchar_t *)nvr->fn); - nvr->fn = NULL; - } - - free(dev); + return((priv_t)dev); } diff --git a/src/machines/m_headland.c b/src/machines/m_headland.c index 69fe44c..024b543 100644 --- a/src/machines/m_headland.c +++ b/src/machines/m_headland.c @@ -12,7 +12,7 @@ * so we can add configuration dialog for the onboard video * controller for the AMA machine. * - * Version: @(#)m_headland.c 1.0.13 2019/05/03 + * Version: @(#)m_headland.c 1.0.14 2019/05/13 * * Authors: Fred N. van Kempen, * Original by GreatPsycho for PCem. @@ -70,7 +70,7 @@ typedef struct { static void -headland_close(void *priv) +headland_close(priv_t priv) { headland_t *dev = (headland_t *)priv; @@ -78,7 +78,7 @@ headland_close(void *priv) } -static void * +static priv_t headland_init(const device_t *info, void *arg) { romdef_t *roms = (romdef_t *)arg; @@ -89,7 +89,7 @@ headland_init(const device_t *info, void *arg) dev->type = info->local; /* Add machine device to system. */ - device_add_ex(info, dev); + device_add_ex(info, (priv_t)dev); m_at_common_init(); @@ -121,7 +121,7 @@ headland_init(const device_t *info, void *arg) break; } - return(dev); + return((priv_t)dev); } diff --git a/src/machines/m_intel4x0.c b/src/machines/m_intel4x0.c index 96c7a5a..10b89cb 100644 --- a/src/machines/m_intel4x0.c +++ b/src/machines/m_intel4x0.c @@ -8,7 +8,7 @@ * * Implementation of the Intel 430/440-based machines. * - * Version: @(#)m_intel4x0.c 1.0.7 2019/05/03 + * Version: @(#)m_intel4x0.c 1.0.8 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -73,7 +73,7 @@ premiere_init(int nx) pci_register_slot(0x0C, PCI_CARD_NORMAL, 1, 3, 2, 4); pci_register_slot(0x02, PCI_CARD_SPECIAL, 0, 0, 0, 0); - memregs_init(); + device_add(&memregs_device); if (nx) device_add(&i430nx_device); @@ -94,7 +94,7 @@ premiere_init(int nx) } -static void * +static priv_t common_init(const device_t *info, void *arg) { static video_timings_t endeavor_timing = {VID_BUS,3,2,4,25,25,40}; @@ -124,7 +124,7 @@ common_init(const device_t *info, void *arg) pci_register_slot(0x10, PCI_CARD_NORMAL, 4, 1, 2, 3); pci_register_slot(0x07, PCI_CARD_SPECIAL, 0, 0, 0, 0); - memregs_init(); + device_add(&memregs_device); device_add(&i430fx_device); device_add(&piix_device); @@ -148,7 +148,7 @@ common_init(const device_t *info, void *arg) pci_register_slot(0x0F, PCI_CARD_NORMAL, 2, 3, 4, 1); pci_register_slot(0x07, PCI_CARD_SPECIAL, 0, 0, 0, 0); - memregs_init(); + device_add(&memregs_device); device_add(&i430fx_device); device_add(&piix_device); @@ -170,7 +170,7 @@ common_init(const device_t *info, void *arg) pci_register_slot(0x10, PCI_CARD_NORMAL, 4, 3, 2, 1); pci_register_slot(0x07, PCI_CARD_SPECIAL, 0, 0, 0, 0); - memregs_init(); + device_add(&memregs_device); device_add(&i430fx_device); device_add(&piix_device); @@ -181,7 +181,7 @@ common_init(const device_t *info, void *arg) break; } - return(arg); + return((priv_t)arg); } diff --git a/src/machines/m_laserxt.c b/src/machines/m_laserxt.c index c0cd67d..49d94d1 100644 --- a/src/machines/m_laserxt.c +++ b/src/machines/m_laserxt.c @@ -8,7 +8,7 @@ * * Emulation of the Laser XT series of machines. * - * Version: @(#)m_laserxt.c 1.0.12 2019/05/05 + * Version: @(#)m_laserxt.c 1.0.13 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -77,8 +77,58 @@ ems_addr(laser_t *dev, uint32_t addr) } +static uint8_t +ems_read(uint32_t addr, priv_t priv) +{ + laser_t *dev = (laser_t *)priv; + uint8_t val = 0xff; + + addr = ems_addr(dev, addr); + + if (addr < ((uint32_t)mem_size << 10)) + val = ram[addr]; + + return val; +} + + static void -do_write(uint16_t port, uint8_t val, void *priv) +ems_write(uint32_t addr, uint8_t val, priv_t priv) +{ + laser_t *dev = (laser_t *)priv; + + addr = ems_addr(dev, addr); + + if (addr < ((uint32_t)mem_size << 10)) + ram[addr] = val; +} + + +static uint8_t +do_read(uint16_t port, priv_t priv) +{ + laser_t *dev = (laser_t *)priv; + + switch (port) { + case 0x0208: + case 0x4208: + case 0x8208: + case 0xc208: + return dev->ems_page[port >> 14]; + + case 0x0209: + case 0x4209: + case 0x8209: + case 0xc209: + return dev->ems_control[port >> 14]; + } + + return 0xff; +} + + +static void +do_write(uint16_t port, uint8_t val, priv_t priv) { laser_t *dev = (laser_t *)priv; uint32_t paddr, vaddr; @@ -120,57 +170,16 @@ do_write(uint16_t port, uint8_t val, void *priv) } -static uint8_t -do_read(uint16_t port, void *priv) -{ - laser_t *dev = (laser_t *)priv; - - switch (port) { - case 0x0208: - case 0x4208: - case 0x8208: - case 0xc208: - return dev->ems_page[port >> 14]; - - case 0x0209: - case 0x4209: - case 0x8209: - case 0xc209: - return dev->ems_control[port >> 14]; - } - - return 0xff; -} - - static void -ems_write(uint32_t addr, uint8_t val, void *priv) +laser_close(priv_t priv) { laser_t *dev = (laser_t *)priv; - addr = ems_addr(dev, addr); - - if (addr < ((uint32_t)mem_size << 10)) - ram[addr] = val; + free(dev); } -static uint8_t -ems_read(uint32_t addr, void *priv) -{ - laser_t *dev = (laser_t *)priv; - uint8_t val = 0xff; - - addr = ems_addr(dev, addr); - - if (addr < ((uint32_t)mem_size << 10)) - val = ram[addr]; - - return val; -} - - -static void * +static priv_t laser_init(const device_t *info, void *arg) { laser_t *dev; @@ -181,7 +190,7 @@ laser_init(const device_t *info, void *arg) dev->type = info->local; /* Add machine device to system. */ - device_add_ex(info, dev); + device_add_ex(info, (priv_t)dev); machine_common_init(); @@ -231,16 +240,7 @@ laser_init(const device_t *info, void *arg) mem_set_mem_state(0x0c0000, 0x40000, MEM_READ_EXTERNAL | MEM_WRITE_EXTERNAL); - return(dev); -} - - -static void -laser_close(void *priv) -{ - laser_t *dev = (laser_t *)priv; - - free(dev); + return((priv_t)dev); } diff --git a/src/machines/m_misc.c b/src/machines/m_misc.c index 630f79c..860720b 100644 --- a/src/machines/m_misc.c +++ b/src/machines/m_misc.c @@ -8,7 +8,7 @@ * * Implementation of various systems and mainboards. * - * Version: @(#)m_misc.c 1.0.1 2019/04/08 + * Version: @(#)m_misc.c 1.0.2 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -63,11 +63,11 @@ #include "machine.h" -static void * +static priv_t common_init(const device_t *info, void *arg) { /* Allocate machine device to system. */ - device_add_ex(info, arg); + device_add_ex(info, (priv_t)arg); switch(info->local) { /* 430VX: Award 430VX PCI/430VX/Award/UMC UM8669F*/ @@ -80,7 +80,7 @@ common_init(const device_t *info, void *arg) pci_register_slot(0x13, PCI_CARD_NORMAL, 4, 1, 2, 3); pci_register_slot(0x07, PCI_CARD_SPECIAL, 0, 0, 0, 0); - memregs_init(); + device_add(&memregs_device); device_add(&i430vx_device); device_add(&piix3_device); @@ -122,7 +122,7 @@ common_init(const device_t *info, void *arg) pci_register_slot(0x0B, PCI_CARD_NORMAL, 4, 1, 2, 3); pci_register_slot(0x07, PCI_CARD_SPECIAL, 0, 0, 0, 0); - memregs_init(); + device_add(&memregs_device); device_add(&i430fx_device); device_add(&piix_device); @@ -183,8 +183,8 @@ common_init(const device_t *info, void *arg) pci_register_slot(0x11, PCI_CARD_NORMAL, 2, 3, 4, 1); pci_register_slot(0x07, PCI_CARD_SPECIAL, 0, 0, 0, 0); - memregs_init(); - powermate_memregs_init(); + device_add(&memregs_device); + device_add(&memregs_powermate_device); device_add(&i430hx_device); device_add(&piix3_device); @@ -197,7 +197,7 @@ common_init(const device_t *info, void *arg) break; } - return(arg); + return((priv_t)arg); } diff --git a/src/machines/m_neat.c b/src/machines/m_neat.c index c11d58f..ad3a0d5 100644 --- a/src/machines/m_neat.c +++ b/src/machines/m_neat.c @@ -8,7 +8,7 @@ * * Emulation of C&T CS8121 ("NEAT") based machines. * - * Version: @(#)m_neat.c 1.0.5 2019/04/08 + * Version: @(#)m_neat.c 1.0.6 2019/05/13 * * Author: Fred N. van Kempen, * @@ -60,11 +60,11 @@ #include "machine.h" -static void * +static priv_t common_init(const device_t *info, void *arg) { /* Add machine device to system. */ - device_add_ex(info, arg); + device_add_ex(info, (priv_t)arg); device_add(&neat_device); @@ -81,7 +81,7 @@ common_init(const device_t *info, void *arg) device_add(&fdc_at_device); - return(arg); + return((priv_t)arg); } diff --git a/src/machines/m_olim24.c b/src/machines/m_olim24.c index e91c4d7..088aeb9 100644 --- a/src/machines/m_olim24.c +++ b/src/machines/m_olim24.c @@ -21,7 +21,7 @@ * data at all, so there seems to not be a way to properly do * that.. The chip's interrupt pin is not connected. * - * Version: @(#)m_olim24.c 1.0.209 2019/05/03 + * Version: @(#)m_olim24.c 1.0.21 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -144,7 +144,7 @@ static int key_queue_start = 0, static void -kbd_poll(void *priv) +kbd_poll(priv_t priv) { olim24_t *dev = (olim24_t *)priv; @@ -180,7 +180,7 @@ kbd_adddata_ex(uint16_t val) static void -kbd_write(uint16_t port, uint8_t val, void *priv) +kbd_write(uint16_t port, uint8_t val, priv_t priv) { olim24_t *dev = (olim24_t *)priv; @@ -260,7 +260,7 @@ kbd_write(uint16_t port, uint8_t val, void *priv) static uint8_t -kbd_read(uint16_t port, void *priv) +kbd_read(uint16_t port, priv_t priv) { olim24_t *dev = (olim24_t *)priv; uint8_t ret = 0xff; @@ -299,7 +299,7 @@ kbd_read(uint16_t port, void *priv) static int -mse_poll(int x, int y, int z, int b, void *priv) +mse_poll(int x, int y, int z, int b, priv_t priv) { olim24_t *dev = (olim24_t *)priv; @@ -386,7 +386,7 @@ mse_poll(int x, int y, int z, int b, void *priv) /* Set the current NVR time. */ #define set_nibbles(a, v) regs[(a##10)] = ((v)/10) ; regs[(a##1)] = ((v)%10) static void -rtc_time_set(uint8_t *regs, struct tm *tm) +rtc_time_set(uint8_t *regs, const struct tm *tm) { set_nibbles(RTC_SECOND, tm->tm_sec); set_nibbles(RTC_MINUTE, tm->tm_min); @@ -503,7 +503,7 @@ rtc_reset(nvr_t *nvr) /* Write to one of the RTC registers. */ static void -rtc_write(uint16_t addr, uint8_t val, void *priv) +rtc_write(uint16_t addr, uint8_t val, priv_t priv) { nvr_t *nvr = (nvr_t *)priv; uint8_t *regs = nvr->regs; @@ -543,7 +543,7 @@ rtc_write(uint16_t addr, uint8_t val, void *priv) /* Read from one of the RTC registers. */ static uint8_t -rtc_read(uint16_t addr, void *priv) +rtc_read(uint16_t addr, priv_t priv) { nvr_t *nvr = (nvr_t *)priv; uint8_t *regs = nvr->regs; @@ -580,7 +580,7 @@ rtc_read(uint16_t addr, void *priv) static uint8_t -m24_read(uint16_t port, void *priv) +m24_read(uint16_t port, priv_t priv) { switch (port) { case 0x66: /* System Configuration 1 (DIPSW-0) */ @@ -636,7 +636,7 @@ m24_read(uint16_t port, void *priv) static void -olim24_close(void *priv) +olim24_close(priv_t priv) { olim24_t *dev = (olim24_t *)priv; nvr_t *nvr = &dev->nvr; @@ -651,7 +651,7 @@ olim24_close(void *priv) } -static void * +static priv_t olim24_init(const device_t *info, void *arg) { olim24_t *dev; @@ -661,7 +661,7 @@ olim24_init(const device_t *info, void *arg) dev->type = info->local; /* Add machine device to system. */ - device_add_ex(info, dev); + device_add_ex(info, (priv_t)dev); machine_common_init(); @@ -710,7 +710,7 @@ olim24_init(const device_t *info, void *arg) if (dev->type == 2) device_add(&st506_xt_olim240_hdc_device); - return(dev); + return((priv_t)dev); } diff --git a/src/machines/m_olim24_vid.c b/src/machines/m_olim24_vid.c index 2da600a..829609b 100644 --- a/src/machines/m_olim24_vid.c +++ b/src/machines/m_olim24_vid.c @@ -8,7 +8,7 @@ * * Emulation of the Olivetti M24 built-in video controller. * - * Version: @(#)m_olim24_vid.c 1.0.4 2019/05/05 + * Version: @(#)m_olim24_vid.c 1.0.5 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -111,7 +111,7 @@ recalc_timings(olivid_t *dev) static void -vid_out(uint16_t addr, uint8_t val, void *priv) +vid_out(uint16_t addr, uint8_t val, priv_t priv) { olivid_t *dev = (olivid_t *)priv; uint8_t old; @@ -157,7 +157,7 @@ vid_out(uint16_t addr, uint8_t val, void *priv) static uint8_t -vid_in(uint16_t addr, void *priv) +vid_in(uint16_t addr, priv_t priv) { olivid_t *dev = (olivid_t *)priv; uint8_t ret = 0xff; @@ -189,7 +189,7 @@ vid_in(uint16_t addr, void *priv) static void -vid_write(uint32_t addr, uint8_t val, void *priv) +vid_write(uint32_t addr, uint8_t val, priv_t priv) { olivid_t *dev = (olivid_t *)priv; @@ -200,7 +200,7 @@ vid_write(uint32_t addr, uint8_t val, void *priv) static uint8_t -vid_read(uint32_t addr, void *priv) +vid_read(uint32_t addr, priv_t priv) { olivid_t *dev = (olivid_t *)priv; @@ -209,7 +209,7 @@ vid_read(uint32_t addr, void *priv) static void -vid_poll(void *priv) +vid_poll(priv_t priv) { olivid_t *dev = (olivid_t *)priv; uint16_t ca = (dev->crtc[15] | (dev->crtc[14] << 8)) & 0x3fff; @@ -475,7 +475,7 @@ vid_poll(void *priv) static void -speed_changed(void *priv) +speed_changed(priv_t priv) { olivid_t *dev = (olivid_t *)priv; @@ -484,7 +484,7 @@ speed_changed(void *priv) static void -vid_close(void *priv) +vid_close(priv_t priv) { olivid_t *dev = (olivid_t *)priv; diff --git a/src/machines/m_opti495.c b/src/machines/m_opti495.c index d458a1c..2912eb0 100644 --- a/src/machines/m_opti495.c +++ b/src/machines/m_opti495.c @@ -8,7 +8,7 @@ * * Implementation of the Opti 82C495 based machines. * - * Version: @(#)m_opti495.c 1.0.11 2019/04/08 + * Version: @(#)m_opti495.c 1.0.12 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -53,11 +53,11 @@ #include "machine.h" -static void * +static priv_t common_init(const device_t *info, void *arg) { /* Add machine device to system. */ - device_add_ex(info, arg); + device_add_ex(info, (priv_t)arg); device_add(&opti495_device); @@ -79,7 +79,7 @@ common_init(const device_t *info, void *arg) break; } - return(arg); + return((priv_t)arg); } diff --git a/src/machines/m_pbell.c b/src/machines/m_pbell.c index 9d9ded1..2ef5ef3 100644 --- a/src/machines/m_pbell.c +++ b/src/machines/m_pbell.c @@ -15,7 +15,7 @@ * _MUST_ enable the Internal mouse, or the PS/2 mouse as * this is onboard. There is a jumper for this as well. * - * Version: @(#)m_pbell.c 1.0.3 2019/05/05 + * Version: @(#)m_pbell.c 1.0.4 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -74,7 +74,7 @@ /* Read out the configuration port. */ //FIXME: bit5 makes it sound an alarm of some kind! static uint8_t -port78_read(uint16_t addr, void *priv) +port78_read(uint16_t addr, priv_t priv) { uint8_t ret = 0x00; @@ -92,11 +92,11 @@ port78_read(uint16_t addr, void *priv) } -static void * +static priv_t common_init(const device_t *info, void *arg) { /* Allocate machine device to system. */ - device_add_ex(info, arg); + device_add_ex(info, (priv_t)arg); switch(info->local) { /* PB410A/PB430/ACC2168/ACC3221 */ @@ -104,7 +104,7 @@ common_init(const device_t *info, void *arg) device_add(&acc2168_device); io_sethandler(0x0078, 1, port78_read,NULL,NULL, NULL,NULL,NULL, NULL); - memregs_init(); + device_add(&memregs_device); m_at_common_ide_init(); device_add(&keyboard_ps2_device); device_add(&acc3221_device); @@ -121,7 +121,7 @@ common_init(const device_t *info, void *arg) device_add(&intel_flash_bxt_ami_device); m_at_common_init(); device_add(&keyboard_ps2_ami_pci_device); - memregs_init(); + device_add(&memregs_device); pci_init(PCI_CONFIG_TYPE_1); pci_register_slot(0x00, PCI_CARD_SPECIAL, 0, 0, 0, 0); @@ -139,7 +139,7 @@ common_init(const device_t *info, void *arg) break; } - return(arg); + return((priv_t)arg); } diff --git a/src/machines/m_pcjr.c b/src/machines/m_pcjr.c index db6d892..fd5faa9 100644 --- a/src/machines/m_pcjr.c +++ b/src/machines/m_pcjr.c @@ -8,7 +8,7 @@ * * Emulation of the IBM PCjr. * - * Version: @(#)m_pcjr.c 1.0.21 2019/05/05 + * Version: @(#)m_pcjr.c 1.0.22 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -165,7 +165,7 @@ recalc_timings(pcjr_t *dev) static void -vid_out(uint16_t addr, uint8_t val, void *priv) +vid_out(uint16_t addr, uint8_t val, priv_t priv) { pcjr_t *dev = (pcjr_t *)priv; uint8_t old; @@ -209,7 +209,7 @@ vid_out(uint16_t addr, uint8_t val, void *priv) static uint8_t -vid_in(uint16_t addr, void *priv) +vid_in(uint16_t addr, priv_t priv) { pcjr_t *dev = (pcjr_t *)priv; uint8_t ret = 0xff; @@ -235,7 +235,7 @@ vid_in(uint16_t addr, void *priv) static void -vid_write(uint32_t addr, uint8_t val, void *priv) +vid_write(uint32_t addr, uint8_t val, priv_t priv) { pcjr_t *dev = (pcjr_t *)priv; @@ -246,7 +246,7 @@ vid_write(uint32_t addr, uint8_t val, void *priv) static uint8_t -vid_read(uint32_t addr, void *priv) +vid_read(uint32_t addr, priv_t priv) { pcjr_t *dev = (pcjr_t *)priv; @@ -257,7 +257,7 @@ vid_read(uint32_t addr, void *priv) static void -vid_poll(void *priv) +vid_poll(priv_t priv) { pcjr_t *dev = (pcjr_t *)priv; uint16_t ca = (dev->crtc[15] | (dev->crtc[14] << 8)) & 0x3fff; @@ -576,7 +576,7 @@ vid_poll(void *priv) static void -kbd_write(uint16_t port, uint8_t val, void *priv) +kbd_write(uint16_t port, uint8_t val, priv_t priv) { pcjr_t *dev = (pcjr_t *)priv; @@ -618,7 +618,7 @@ kbd_write(uint16_t port, uint8_t val, void *priv) static uint8_t -kbd_read(uint16_t port, void *priv) +kbd_read(uint16_t port, priv_t priv) { pcjr_t *dev = (pcjr_t *)priv; uint8_t ret = 0xff; @@ -656,7 +656,7 @@ kbd_read(uint16_t port, void *priv) static void -kbd_poll(void *priv) +kbd_poll(priv_t priv) { pcjr_t *dev = (pcjr_t *)priv; int c, p = 0, key; @@ -739,7 +739,7 @@ irq0_timer(int new_out, int old_out) static void -pcjr_close(void *priv) +pcjr_close(priv_t priv) { pcjr_t *dev = (pcjr_t *)priv; @@ -751,7 +751,7 @@ pcjr_close(void *priv) static void -speed_changed(void *priv) +speed_changed(priv_t priv) { pcjr_t *dev = (pcjr_t *)priv; @@ -759,7 +759,7 @@ speed_changed(void *priv) } -static void * +static priv_t pcjr_init(const device_t *info, UNUSED(void *arg)) { pcjr_t *dev; @@ -768,7 +768,7 @@ pcjr_init(const device_t *info, UNUSED(void *arg)) memset(dev, 0x00, sizeof(pcjr_t)); /* Add the machine device. */ - device_add_ex(info, dev); + device_add_ex(info, (priv_t)dev); dev->memctrl = -1; dev->display_type = machine_get_config_int("display_type"); @@ -814,7 +814,7 @@ pcjr_init(const device_t *info, UNUSED(void *arg)) /* Add the floppy controller. */ device_add(&fdc_pcjr_device); - return(dev); + return((priv_t)dev); } diff --git a/src/machines/m_ps1.c b/src/machines/m_ps1.c index d511751..fe371a4 100644 --- a/src/machines/m_ps1.c +++ b/src/machines/m_ps1.c @@ -22,7 +22,7 @@ * The reserved 384K is remapped to the top of extended memory. * If this is not done then you get an error on startup. * - * Version: @(#)m_ps1.c 1.0.28 2019/05/05 + * Version: @(#)m_ps1.c 1.0.29 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -118,11 +118,6 @@ typedef struct { } ps1_t; -/* Defined in the Video module. */ -extern const device_t ps1vga_device; -extern const device_t ibm_ps1_2121_device; - - static void snd_update_irq(ps1snd_t *snd) { @@ -134,7 +129,7 @@ snd_update_irq(ps1snd_t *snd) static uint8_t -snd_read(uint16_t port, void *priv) +snd_read(uint16_t port, priv_t priv) { ps1snd_t *snd = (ps1snd_t *)priv; uint8_t ret = 0xff; @@ -176,7 +171,7 @@ snd_read(uint16_t port, void *priv) static void -snd_write(uint16_t port, uint8_t val, void *priv) +snd_write(uint16_t port, uint8_t val, priv_t priv) { ps1snd_t *snd = (ps1snd_t *)priv; @@ -217,7 +212,7 @@ snd_update(ps1snd_t *snd) static void -snd_callback(void *priv) +snd_callback(priv_t priv) { ps1snd_t *snd = (ps1snd_t *)priv; @@ -239,7 +234,7 @@ snd_callback(void *priv) static void -snd_get_buffer(int32_t *bufp, int len, void *priv) +snd_get_buffer(int32_t *bufp, int len, priv_t priv) { ps1snd_t *snd = (ps1snd_t *)priv; int c; @@ -253,7 +248,16 @@ snd_get_buffer(int32_t *bufp, int len, void *priv) } -static void * +static void +snd_close(priv_t priv) +{ + ps1snd_t *snd = (ps1snd_t *)priv; + + free(snd); +} + + +static priv_t snd_init(const device_t *info, UNUSED(void *parent)) { ps1snd_t *snd; @@ -272,16 +276,7 @@ snd_init(const device_t *info, UNUSED(void *parent)) sound_add_handler(snd_get_buffer, snd); - return(snd); -} - - -static void -snd_close(void *priv) -{ - ps1snd_t *snd = (ps1snd_t *)priv; - - free(snd); + return((priv_t)snd); } @@ -295,7 +290,7 @@ static const device_t snd_device = { static uint8_t -ps1_read_romext(uint32_t addr, void *priv) +read_romext(uint32_t addr, priv_t priv) { ps1_t *dev = (ps1_t *)priv; @@ -304,7 +299,7 @@ ps1_read_romext(uint32_t addr, void *priv) static uint16_t -ps1_read_romextw(uint32_t addr, void *priv) +read_romextw(uint32_t addr, priv_t priv) { ps1_t *dev = (ps1_t *)priv; uint16_t *p = (uint16_t *)&dev->romext[addr & 0x7fff]; @@ -314,7 +309,7 @@ ps1_read_romextw(uint32_t addr, void *priv) static uint32_t -ps1_read_romextl(uint32_t addr, void *priv) +read_romextl(uint32_t addr, priv_t priv) { ps1_t *dev = (ps1_t *)priv; uint32_t *p = (uint32_t *)&dev->romext[addr & 0x7fff]; @@ -341,7 +336,7 @@ recalc_memory(ps1_t *dev) static void -ps1_write(uint16_t port, uint8_t val, void *priv) +ps1_write(uint16_t port, uint8_t val, priv_t priv) { ps1_t *dev = (ps1_t *)priv; @@ -421,7 +416,7 @@ ps1_write(uint16_t port, uint8_t val, void *priv) static uint8_t -ps1_read(uint16_t port, void *priv) +ps1_read(uint16_t port, priv_t priv) { ps1_t *dev = (ps1_t *)priv; uint8_t ret = 0xff; @@ -480,7 +475,7 @@ ps1_read(uint16_t port, void *priv) static void -ps1_close(void *priv) +ps1_close(priv_t priv) { ps1_t *dev = (ps1_t *)priv; @@ -488,7 +483,7 @@ ps1_close(void *priv) } -static void * +static priv_t ps1_init(const device_t *info, void *arg) { // romdef_t *bios = (romdef_t *)arg; @@ -500,7 +495,7 @@ ps1_init(const device_t *info, void *arg) dev->model = info->local; /* Add machine device to system. */ - device_add_ex(info, dev); + device_add_ex(info, (priv_t)dev); if (dev->model == 2011) { /* Force some configuration settings. */ @@ -508,7 +503,7 @@ ps1_init(const device_t *info, void *arg) config.mouse_type = MOUSE_PS2; mem_map_add(&dev->romext_mapping, 0xc8000, 0x08000, - ps1_read_romext,ps1_read_romextw,ps1_read_romextl, + read_romext,read_romextw,read_romextl, NULL,NULL, NULL, dev->romext, 0, dev); if (machine_get_config_int("rom_shell")) { @@ -609,7 +604,7 @@ ps1_init(const device_t *info, void *arg) if (config.game_enabled) device_add(&game_201_device); - return(dev); + return((priv_t)dev); } @@ -698,7 +693,7 @@ const device_t m_ps1_2133 = { /* Set the Card Selected Flag */ void -ps1_set_feedback(void *priv) +ps1_set_feedback(priv_t priv) { ps1_t *dev = (ps1_t *)priv; diff --git a/src/machines/m_ps1.h b/src/machines/m_ps1.h index f3e0873..9f5ce4f 100644 --- a/src/machines/m_ps1.h +++ b/src/machines/m_ps1.h @@ -8,7 +8,7 @@ * * Definitions for the IBM PS/1 machines. * - * Version: @(#)m_ps1.h 1.0.1 2019/04/19 + * Version: @(#)m_ps1.h 1.0.2 2019/05/13 * * Author: Fred N. van Kempen, * @@ -58,7 +58,7 @@ extern const device_t ps1_hdc_device; #endif -extern void ps1_set_feedback(void *); +extern void ps1_set_feedback(priv_t); #endif /*MACHINE_PS1_H*/ diff --git a/src/machines/m_ps1_hdc.c b/src/machines/m_ps1_hdc.c index 056ae4f..74ffd70 100644 --- a/src/machines/m_ps1_hdc.c +++ b/src/machines/m_ps1_hdc.c @@ -43,7 +43,7 @@ * Type table with the main code, so the user can only select * items from that list... * - * Version: @(#)m_ps1_hdc.c 1.0.12 2018/04/25 + * Version: @(#)m_ps1_hdc.c 1.0.13 2018/05/13 * * Author: Fred N. van Kempen, * @@ -388,7 +388,7 @@ typedef struct { status, /* Status register (ASR) */ intstat; /* Interrupt Status register (ISR) */ - void *sys; /* handle to system board */ + priv_t sys; /* handle to system board */ /* Controller state. */ int64_t callback; @@ -1231,7 +1231,7 @@ hdc_send_ssb(hdc_t *dev) /* Read one of the controller registers. */ static uint8_t -hdc_read(uint16_t port, void *priv) +hdc_read(uint16_t port, priv_t priv) { hdc_t *dev = (hdc_t *)priv; uint8_t ret = 0xff; @@ -1276,7 +1276,7 @@ hdc_read(uint16_t port, void *priv) /* Write to one of the controller registers. */ static void -hdc_write(uint16_t port, uint8_t val, void *priv) +hdc_write(uint16_t port, uint8_t val, priv_t priv) { hdc_t *dev = (hdc_t *)priv; @@ -1381,7 +1381,7 @@ hdc_write(uint16_t port, uint8_t val, void *priv) static void -hdc_close(void *priv) +hdc_close(priv_t priv) { hdc_t *dev = (hdc_t *)priv; drive_t *drive; @@ -1404,7 +1404,7 @@ hdc_close(void *priv) } -static void * +static priv_t hdc_init_ps1(const device_t *info, void *parent) { drive_t *drive; @@ -1414,7 +1414,7 @@ hdc_init_ps1(const device_t *info, void *parent) /* Allocate and initialize device block. */ dev = (hdc_t *)mem_alloc(sizeof(hdc_t)); memset(dev, 0x00, sizeof(hdc_t)); - dev->sys = parent; + dev->sys = (priv_t)parent; /* Set up controller parameters for PS/1 2011. */ dev->base = 0x0320; @@ -1468,7 +1468,7 @@ hdc_init_ps1(const device_t *info, void *parent) /* Create a timer for command delays. */ timer_add(hdc_callback, dev, &dev->callback, &dev->callback); - return(dev); + return((priv_t)dev); } diff --git a/src/machines/m_ps2_isa.c b/src/machines/m_ps2_isa.c index d463612..173f124 100644 --- a/src/machines/m_ps2_isa.c +++ b/src/machines/m_ps2_isa.c @@ -8,7 +8,7 @@ * * Implementation of ISA-based PS/2 machines. * - * Version: @(#)m_ps2_isa.c 1.0.19 2019/05/05 + * Version: @(#)m_ps2_isa.c 1.0.20 2019/05/15 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -51,6 +51,7 @@ #include "../devices/system/dma.h" #include "../devices/system/pic.h" #include "../devices/system/pit.h" +#include "../devices/system/port92.h" #include "../devices/ports/parallel.h" #include "../devices/ports/serial.h" #include "../devices/input/keyboard.h" @@ -78,7 +79,7 @@ typedef struct { static uint8_t -ps2_read(uint16_t port, void *priv) +ps2_read(uint16_t port, priv_t priv) { ps2_t *dev = (ps2_t *)priv; uint8_t ret = 0xff; @@ -130,7 +131,7 @@ ps2_read(uint16_t port, void *priv) static void -ps2_write(uint16_t port, uint8_t val, void *priv) +ps2_write(uint16_t port, uint8_t val, priv_t priv) { ps2_t *dev = (ps2_t *)priv; @@ -205,8 +206,7 @@ common_init(ps2_t *dev) io_sethandler(0x0322, 1, ps2_read,NULL,NULL, ps2_write,NULL,NULL, dev); io_sethandler(0x0324, 1, ps2_read,NULL,NULL, ps2_write,NULL,NULL, dev); - port_92_reset(); - port_92_add(0); + device_add_parent(&port92_device, (priv_t)dev); dev->reg_190 = 0; @@ -215,7 +215,7 @@ common_init(ps2_t *dev) static void -ps2_close(void *priv) +ps2_close(priv_t priv) { ps2_t *dev = (ps2_t *)priv; @@ -223,7 +223,7 @@ ps2_close(void *priv) } -static void * +static priv_t ps2_init(const device_t *info, void *arg) { ps2_t *dev; @@ -233,7 +233,7 @@ ps2_init(const device_t *info, void *arg) dev->type = info->local; /* Add machine device to system. */ - device_add_ex(info, dev); + device_add_ex(info, (priv_t)dev); machine_common_init(); @@ -257,7 +257,7 @@ ps2_init(const device_t *info, void *arg) common_init(dev); - return(dev); + return((priv_t)dev); } diff --git a/src/machines/m_ps2_mca.c b/src/machines/m_ps2_mca.c index 5520149..1f63dfd 100644 --- a/src/machines/m_ps2_mca.c +++ b/src/machines/m_ps2_mca.c @@ -48,7 +48,7 @@ * * This works around the timing loop mentioned above. * - * Version: @(#)m_ps2_mca.c 1.0.25 2019/05/03 + * Version: @(#)m_ps2_mca.c 1.0.26 2019/05/15 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -94,6 +94,7 @@ #include "../devices/system/nmi.h" #include "../devices/system/pic.h" #include "../devices/system/pit.h" +#include "../devices/system/port92.h" #include "../devices/system/mca.h" #include "../devices/system/nvr_ps2.h" #include "../devices/ports/parallel.h" @@ -150,11 +151,11 @@ typedef struct _ps2_ { } ps2_t; -static void *saved_dev = NULL; /* needed for clear_cache() */ +static ps2_t *saved_dev = NULL; /* needed for clear_cache() */ static uint8_t -cache_read(uint32_t addr, void *priv) +cache_read(uint32_t addr, priv_t priv) { ps2_t *dev = (ps2_t *)priv; @@ -172,7 +173,7 @@ cache_read(uint32_t addr, void *priv) static uint16_t -cache_readw(uint32_t addr, void *priv) +cache_readw(uint32_t addr, priv_t priv) { ps2_t *dev = (ps2_t *)priv; @@ -190,7 +191,7 @@ cache_readw(uint32_t addr, void *priv) static uint32_t -cache_readl(uint32_t addr, void *priv) +cache_readl(uint32_t addr, priv_t priv) { ps2_t *dev = (ps2_t *)priv; @@ -208,7 +209,7 @@ cache_readl(uint32_t addr, void *priv) static void -cache_write(uint32_t addr, uint8_t val, void *priv) +cache_write(uint32_t addr, uint8_t val, priv_t priv) { ps2_t *dev = (ps2_t *)priv; @@ -230,7 +231,7 @@ ps2_cache_clean(void) static uint8_t -shadow_read(uint32_t addr, void *priv) +shadow_read(uint32_t addr, priv_t priv) { addr = (addr & 0x1ffff) + 0xe0000; @@ -239,7 +240,7 @@ shadow_read(uint32_t addr, void *priv) static uint16_t -shadow_readw(uint32_t addr, void *priv) +shadow_readw(uint32_t addr, priv_t priv) { addr = (addr & 0x1ffff) + 0xe0000; @@ -248,7 +249,7 @@ shadow_readw(uint32_t addr, void *priv) static uint32_t -shadow_readl(uint32_t addr, void *priv) +shadow_readl(uint32_t addr, priv_t priv) { addr = (addr & 0x1ffff) + 0xe0000; @@ -257,7 +258,7 @@ shadow_readl(uint32_t addr, void *priv) static void -shadow_write(uint32_t addr, uint8_t val, void *priv) +shadow_write(uint32_t addr, uint8_t val, priv_t priv) { addr = (addr & 0x1ffff) + 0xe0000; @@ -266,7 +267,7 @@ shadow_write(uint32_t addr, uint8_t val, void *priv) static void -shadow_writew(uint32_t addr, uint16_t val, void *priv) +shadow_writew(uint32_t addr, uint16_t val, priv_t priv) { addr = (addr & 0x1ffff) + 0xe0000; @@ -275,7 +276,7 @@ shadow_writew(uint32_t addr, uint16_t val, void *priv) static void -shadow_writel(uint32_t addr, uint32_t val, void *priv) +shadow_writel(uint32_t addr, uint32_t val, priv_t priv) { addr = (addr & 0x1ffff) + 0xe0000; @@ -284,7 +285,7 @@ shadow_writel(uint32_t addr, uint32_t val, void *priv) static uint8_t -split_read(uint32_t addr, void *priv) +split_read(uint32_t addr, priv_t priv) { ps2_t *dev = (ps2_t *)priv; @@ -295,7 +296,7 @@ split_read(uint32_t addr, void *priv) static uint16_t -split_readw(uint32_t addr, void *priv) +split_readw(uint32_t addr, priv_t priv) { ps2_t *dev = (ps2_t *)priv; @@ -306,7 +307,7 @@ split_readw(uint32_t addr, void *priv) static uint32_t -split_readl(uint32_t addr, void *priv) +split_readl(uint32_t addr, priv_t priv) { ps2_t *dev = (ps2_t *)priv; @@ -317,7 +318,7 @@ split_readl(uint32_t addr, void *priv) static void -split_write(uint32_t addr, uint8_t val, void *priv) +split_write(uint32_t addr, uint8_t val, priv_t priv) { ps2_t *dev = (ps2_t *)priv; @@ -328,7 +329,7 @@ split_write(uint32_t addr, uint8_t val, void *priv) static void -split_writew(uint32_t addr, uint16_t val, void *priv) +split_writew(uint32_t addr, uint16_t val, priv_t priv) { ps2_t *dev = (ps2_t *)priv; @@ -339,7 +340,7 @@ split_writew(uint32_t addr, uint16_t val, void *priv) static void -split_writel(uint32_t addr, uint32_t val, void *priv) +split_writel(uint32_t addr, uint32_t val, priv_t priv) { ps2_t *dev = (ps2_t *)priv; @@ -350,7 +351,7 @@ split_writel(uint32_t addr, uint32_t val, void *priv) static uint8_t -exp_read(int port, void *priv) +exp_read(int port, priv_t priv) { ps2_t *dev = (ps2_t *)priv; @@ -359,7 +360,7 @@ exp_read(int port, void *priv) static void -exp_write(int port, uint8_t val, void *priv) +exp_write(int port, uint8_t val, priv_t priv) { ps2_t *dev = (ps2_t *)priv; @@ -796,7 +797,7 @@ mem_encoding_update(ps2_t *dev) static uint8_t -mem_encoding_read(uint16_t addr, void *priv) +mem_encoding_read(uint16_t addr, priv_t priv) { ps2_t *dev = (ps2_t *)priv; uint8_t ret = 0xff; @@ -816,7 +817,7 @@ mem_encoding_read(uint16_t addr, void *priv) static void -mem_encoding_write(uint16_t addr, uint8_t val, void *priv) +mem_encoding_write(uint16_t addr, uint8_t val, priv_t priv) { ps2_t *dev = (ps2_t *)priv; @@ -835,7 +836,7 @@ mem_encoding_write(uint16_t addr, uint8_t val, void *priv) static uint8_t -mem_encoding_read_cached(uint16_t addr, void *priv) +mem_encoding_read_cached(uint16_t addr, priv_t priv) { ps2_t *dev = (ps2_t *)priv; uint8_t ret = 0xff; @@ -859,7 +860,7 @@ mem_encoding_read_cached(uint16_t addr, void *priv) static void -mem_encoding_write_cached(uint16_t addr, uint8_t val, void *priv) +mem_encoding_write_cached(uint16_t addr, uint8_t val, priv_t priv) { ps2_t *dev = (ps2_t *)priv; uint8_t old; @@ -1245,7 +1246,7 @@ model_80_init(ps2_t *dev) static uint8_t -ps2_mca_read(uint16_t port, void *priv) +ps2_mca_read(uint16_t port, priv_t priv) { ps2_t *dev = (ps2_t *)priv; uint8_t ret = 0xff; @@ -1337,7 +1338,7 @@ ps2_mca_read(uint16_t port, void *priv) static void -ps2_mca_write(uint16_t port, uint8_t val, void *priv) +ps2_mca_write(uint16_t port, uint8_t val, priv_t priv) { ps2_t *dev = (ps2_t *)priv; @@ -1416,7 +1417,7 @@ ps2_mca_write(uint16_t port, uint8_t val, void *priv) static void -ps2_close(void *priv) +ps2_close(priv_t priv) { ps2_t *dev = (ps2_t *)priv; @@ -1426,7 +1427,7 @@ ps2_close(void *priv) } -static void * +static priv_t ps2_init(const device_t *info, void *arg) { ps2_t *dev; @@ -1436,7 +1437,7 @@ ps2_init(const device_t *info, void *arg) dev->type = info->local; /* Add machine device to system. */ - device_add_ex(info, dev); + device_add_ex(info, (priv_t)dev); machine_common_init(); @@ -1453,9 +1454,7 @@ ps2_init(const device_t *info, void *arg) parallel_setup(0, 0x03bc); - port_92_reset(); - - port_92_add(0); + device_add_parent(&port92_device, (priv_t)dev); io_sethandler(0x0091, 1, ps2_mca_read,NULL,NULL, ps2_mca_write,NULL,NULL, dev); @@ -1493,7 +1492,7 @@ ps2_init(const device_t *info, void *arg) saved_dev = dev; - return(dev); + return((priv_t)dev); } diff --git a/src/machines/m_scat.c b/src/machines/m_scat.c index 1079e4b..350e358 100644 --- a/src/machines/m_scat.c +++ b/src/machines/m_scat.c @@ -8,7 +8,7 @@ * * Implementation of the C&T 82C235 ("SCAT") based machines. * - * Version: @(#)m_scat.c 1.0.16 2019/04/08 + * Version: @(#)m_scat.c 1.0.17 2019/05/13 * * Authors: Fred N. van Kempen, * Original by GreatPsycho for PCem. @@ -54,11 +54,11 @@ #include "machine.h" -static void * +static priv_t common_init(const device_t *info, void *arg) { /* Add machine device to system. */ - device_add_ex(info, arg); + device_add_ex(info, (priv_t)arg); switch(info->local) { case 0: /* Generic Award SCAT */ @@ -91,7 +91,7 @@ common_init(const device_t *info, void *arg) device_add(&fdc_at_device); - return(arg); + return((priv_t)arg); } diff --git a/src/machines/m_sis471.c b/src/machines/m_sis471.c index 6c803a3..7108e19 100644 --- a/src/machines/m_sis471.c +++ b/src/machines/m_sis471.c @@ -8,7 +8,7 @@ * * Emulation of the SiS 85c471 based machines. * - * Version: @(#)m_sis471.c 1.0.14 2019/04/08 + * Version: @(#)m_sis471.c 1.0.15 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -49,11 +49,11 @@ #include "machine.h" -static void * +static priv_t common_init(const device_t *info, void *arg) { /* Add machine device to system. */ - device_add_ex(info, arg); + device_add_ex(info, (priv_t)arg); device_add(&sis_85c471_device); @@ -65,9 +65,9 @@ common_init(const device_t *info, void *arg) device_add(&fdc_at_device); - memregs_init(); + device_add(&memregs_device); - return(arg); + return((priv_t)arg); } diff --git a/src/machines/m_sis496.c b/src/machines/m_sis496.c index f29248a..c399b00 100644 --- a/src/machines/m_sis496.c +++ b/src/machines/m_sis496.c @@ -8,7 +8,7 @@ * * Implementation of the SiS 85C496/497 based machines. * - * Version: @(#)m_sis49x.c 1.0.11 2019/04/08 + * Version: @(#)m_sis49x.c 1.0.12 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -57,11 +57,11 @@ #include "machine.h" -static void * +static priv_t common_init(const device_t *info, void *arg) { /* Add machine device to system. */ - device_add_ex(info, arg); + device_add_ex(info, (priv_t)arg); switch(info->local) { case 0: /* Generic SiS496 */ @@ -78,7 +78,7 @@ common_init(const device_t *info, void *arg) pci_set_irq_routing(PCI_INTC, PCI_IRQ_DISABLED); pci_set_irq_routing(PCI_INTD, PCI_IRQ_DISABLED); - memregs_init(); + device_add(&memregs_device); ///////// device_add(&sis_85c496_device); m_at_common_ide_init(); @@ -99,7 +99,7 @@ common_init(const device_t *info, void *arg) pci_set_irq_routing(PCI_INTC, PCI_IRQ_DISABLED); pci_set_irq_routing(PCI_INTD, PCI_IRQ_DISABLED); - memregs_init(); + device_add(&memregs_device); device_add(&sis_85c496_device); m_at_common_init(); @@ -108,7 +108,7 @@ common_init(const device_t *info, void *arg) device_add(&fdc37c665_device); } - return(arg); + return((priv_t)arg); } diff --git a/src/machines/m_tandy1000.c b/src/machines/m_tandy1000.c index fd11be2..9a6473d 100644 --- a/src/machines/m_tandy1000.c +++ b/src/machines/m_tandy1000.c @@ -8,7 +8,7 @@ * * Emulation of Tandy models 1000, 1000HX and 1000SL2. * - * Version: @(#)m_tandy1000.c 1.0.22 2019/04/26 + * Version: @(#)m_tandy1000.c 1.0.23 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -653,7 +653,7 @@ snd_update_irq(t1ksnd_t *dev) static void -snd_write(uint16_t port, uint8_t val, void *priv) +snd_write(uint16_t port, uint8_t val, priv_t priv) { t1ksnd_t *dev = (t1ksnd_t *)priv; @@ -693,7 +693,7 @@ snd_write(uint16_t port, uint8_t val, void *priv) static uint8_t -snd_read(uint16_t port, void *priv) +snd_read(uint16_t port, priv_t priv) { t1ksnd_t *dev = (t1ksnd_t *)priv; uint8_t ret = 0xff; @@ -749,7 +749,7 @@ snd_update(t1ksnd_t *dev) static void -snd_callback(void *priv) +snd_callback(priv_t priv) { t1ksnd_t *dev = (t1ksnd_t *)priv; int data; @@ -803,7 +803,7 @@ snd_callback(void *priv) static void -snd_get_buffer(int32_t *bufp, int len, void *priv) +snd_get_buffer(int32_t *bufp, int len, priv_t priv) { t1ksnd_t *dev = (t1ksnd_t *)priv; int c; @@ -817,7 +817,7 @@ snd_get_buffer(int32_t *bufp, int len, void *priv) } -static void * +static priv_t snd_init(const device_t *info, UNUSED(void *parent)) { t1ksnd_t *dev; @@ -834,12 +834,12 @@ snd_init(const device_t *info, UNUSED(void *parent)) sound_add_handler(snd_get_buffer, dev); - return(dev); + return((priv_t)dev); } static void -snd_close(void *priv) +snd_close(priv_t priv) { t1ksnd_t *dev = (t1ksnd_t *)priv; @@ -858,7 +858,7 @@ static const device_t snd_device = { static void -eep_write(uint16_t addr, uint8_t val, void *priv) +eep_write(uint16_t addr, uint8_t val, priv_t priv) { t1keep_t *dev = (t1keep_t *)priv; @@ -932,7 +932,25 @@ eep_write(uint16_t addr, uint8_t val, void *priv) } -static void * +static void +eep_close(priv_t priv) +{ + t1keep_t *dev = (t1keep_t *)priv; + FILE *fp; + + fp = plat_fopen(nvr_path(dev->fn), L"wb"); + if (fp != NULL) { + (void)fwrite(dev->store, sizeof(dev->store), 1, fp); + (void)fclose(fp); + } + + free(dev->fn); + + free(dev); +} + + +static priv_t eep_init(const device_t *info, UNUSED(void *parent)) { char temp[128]; @@ -957,31 +975,13 @@ eep_init(const device_t *info, UNUSED(void *parent)) io_sethandler(0x037c, 1, NULL,NULL,NULL, eep_write,NULL,NULL, dev); - return(dev); -} - - -static void -eep_close(void *priv) -{ - t1keep_t *dev = (t1keep_t *)priv; - FILE *fp; - - fp = plat_fopen(nvr_path(dev->fn), L"wb"); - if (fp != NULL) { - (void)fwrite(dev->store, sizeof(dev->store), 1, fp); - (void)fclose(fp); - } - - free(dev->fn); - - free(dev); + return((priv_t)dev); } /* Called by the keyboard driver to read the next bit. */ static uint8_t -eep_readbit(void *priv) +eep_readbit(priv_t priv) { t1keep_t *dev = (t1keep_t *)priv; @@ -999,7 +999,7 @@ static const device_t eep_device = { static void -tandy_write(uint16_t addr, uint8_t val, void *priv) +tandy_write(uint16_t addr, uint8_t val, priv_t priv) { tandy_t *dev = (tandy_t *)priv; @@ -1031,7 +1031,7 @@ tandy_write(uint16_t addr, uint8_t val, void *priv) static uint8_t -tandy_read(uint16_t addr, void *priv) +tandy_read(uint16_t addr, priv_t priv) { tandy_t *dev = (tandy_t *)priv; uint8_t ret = 0xff; @@ -1055,7 +1055,7 @@ tandy_read(uint16_t addr, void *priv) static void -write_ram(uint32_t addr, uint8_t val, void *priv) +write_ram(uint32_t addr, uint8_t val, priv_t priv) { tandy_t *dev = (tandy_t *)priv; @@ -1064,7 +1064,7 @@ write_ram(uint32_t addr, uint8_t val, void *priv) static uint8_t -read_ram(uint32_t addr, void *priv) +read_ram(uint32_t addr, priv_t priv) { tandy_t *dev = (tandy_t *)priv; @@ -1073,7 +1073,7 @@ read_ram(uint32_t addr, void *priv) static uint8_t -read_rom(uint32_t addr, void *priv) +read_rom(uint32_t addr, priv_t priv) { tandy_t *dev = (tandy_t *)priv; uint32_t addr2 = (addr & 0xffff) + dev->rom_offset; @@ -1083,7 +1083,7 @@ read_rom(uint32_t addr, void *priv) static uint16_t -read_romw(uint32_t addr, void *priv) +read_romw(uint32_t addr, priv_t priv) { tandy_t *dev = (tandy_t *)priv; uint32_t addr2 = (addr & 0xffff) + dev->rom_offset; @@ -1093,7 +1093,7 @@ read_romw(uint32_t addr, void *priv) static uint32_t -read_roml(uint32_t addr, void *priv) +read_roml(uint32_t addr, priv_t priv) { tandy_t *dev = (tandy_t *)priv; @@ -1147,11 +1147,23 @@ init_romdos(tandy_t *dev, romdef_t *roms) } -static void * +static void +tandy_close(priv_t priv) +{ + tandy_t *dev = (tandy_t *)priv; + + if (dev->rom != NULL) + free(dev->rom); + + free(dev); +} + + +static priv_t tandy_init(const device_t *info, void *arg) { romdef_t *roms = (romdef_t *)arg; - void *eep = NULL, *kbd; + priv_t eep = NULL, kbd; tandy_t *dev; dev = (tandy_t *)mem_alloc(sizeof(tandy_t)); @@ -1159,7 +1171,7 @@ tandy_init(const device_t *info, void *arg) dev->type = info->local; /* Add machine device. */ - device_add_ex(info, dev); + device_add_ex(info, (priv_t)dev); dev->display_type = machine_get_config_int("display_type"); @@ -1210,19 +1222,7 @@ tandy_init(const device_t *info, void *arg) /* Set the callback function for the keyboard controller. */ keyboard_xt_set_funcs(kbd, eep_readbit, eep); - return(dev); -} - - -static void -tandy_close(void *priv) -{ - tandy_t *dev = (tandy_t *)priv; - - if (dev->rom != NULL) - free(dev->rom); - - free(dev); + return((priv_t)dev); } diff --git a/src/machines/m_tandy1000_vid.c b/src/machines/m_tandy1000_vid.c index 402cf7a..d620022 100644 --- a/src/machines/m_tandy1000_vid.c +++ b/src/machines/m_tandy1000_vid.c @@ -8,7 +8,7 @@ * * Emulation of video controllers for Tandy models. * - * Version: @(#)m_tandy1000_vid.c 1.0.4 2019/05/05 + * Version: @(#)m_tandy1000_vid.c 1.0.5 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -119,8 +119,8 @@ static const uint8_t crtcmask_sl[32] = { static const video_timings_t tandy_timing = { VID_BUS,1,2,4,1,2,4 }; -static uint8_t vid_in(uint16_t addr, void *priv); -static void vid_out(uint16_t addr, uint8_t val, void *priv); +static uint8_t vid_in(uint16_t, priv_t); +static void vid_out(uint16_t, uint8_t, priv_t); static void @@ -196,7 +196,7 @@ recalc_address(t1kvid_t *dev, int sl) static void -vid_out(uint16_t addr, uint8_t val, void *priv) +vid_out(uint16_t addr, uint8_t val, priv_t priv) { t1kvid_t *dev = (t1kvid_t *)priv; uint8_t old; @@ -264,7 +264,7 @@ vid_out(uint16_t addr, uint8_t val, void *priv) static uint8_t -vid_in(uint16_t addr, void *priv) +vid_in(uint16_t addr, priv_t priv) { t1kvid_t *dev = (t1kvid_t *)priv; uint8_t ret = 0xff; @@ -288,7 +288,7 @@ vid_in(uint16_t addr, void *priv) static void -vid_write(uint32_t addr, uint8_t val, void *priv) +vid_write(uint32_t addr, uint8_t val, priv_t priv) { t1kvid_t *dev = (t1kvid_t *)priv; @@ -308,7 +308,7 @@ vid_write(uint32_t addr, uint8_t val, void *priv) static uint8_t -vid_read(uint32_t addr, void *priv) +vid_read(uint32_t addr, priv_t priv) { t1kvid_t *dev = (t1kvid_t *)priv; uint8_t ret = 0xff; @@ -328,7 +328,7 @@ vid_read(uint32_t addr, void *priv) static void -vid_poll(void *priv) +vid_poll(priv_t priv) { t1kvid_t *dev = (t1kvid_t *)priv; uint16_t ca = (dev->crtc[15] | (dev->crtc[14] << 8)) & 0x3fff; @@ -662,7 +662,7 @@ vid_poll(void *priv) static void -vid_poll_sl(void *priv) +vid_poll_sl(priv_t priv) { t1kvid_t *dev = (t1kvid_t *)priv; uint16_t ca = (dev->crtc[15] | (dev->crtc[14] << 8)) & 0x3fff; @@ -1006,7 +1006,7 @@ vid_poll_sl(void *priv) static void -speed_changed(void *priv) +speed_changed(priv_t priv) { t1kvid_t *dev = (t1kvid_t *)priv; @@ -1015,7 +1015,7 @@ speed_changed(void *priv) static void -vid_close(void *priv) +vid_close(priv_t priv) { t1kvid_t *dev = (t1kvid_t *)priv; diff --git a/src/machines/m_tosh1x00.c b/src/machines/m_tosh1x00.c index 9c21f60..18d7ac0 100644 --- a/src/machines/m_tosh1x00.c +++ b/src/machines/m_tosh1x00.c @@ -96,7 +96,7 @@ * * FIXME: The ROM drive should be re-done using the "option file". * - * Version: @(#)m_tosh1x00.c 1.0.22 2019/05/05 + * Version: @(#)m_tosh1x00.c 1.0.23 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -227,7 +227,7 @@ typedef struct { /* Set the chip time. */ static void -tc8521_time_set(uint8_t *regs, struct tm *tm) +tc8521_time_set(uint8_t *regs, const struct tm *tm) { regs[TC8521_SECOND1] = (tm->tm_sec % 10); regs[TC8521_SECOND10] = (tm->tm_sec / 10); @@ -303,7 +303,7 @@ tc8521_start(nvr_t *nvr) /* Write to one of the chip registers. */ static void -tc8521_write(uint16_t addr, uint8_t val, void *priv) +tc8521_write(uint16_t addr, uint8_t val, priv_t priv) { nvr_t *nvr = (nvr_t *)priv; uint8_t page; @@ -324,7 +324,7 @@ tc8521_write(uint16_t addr, uint8_t val, void *priv) /* Read from one of the chip registers. */ static uint8_t -tc8521_read(uint16_t addr, void *priv) +tc8521_read(uint16_t addr, priv_t priv) { nvr_t *nvr = (nvr_t *)priv; uint8_t page; @@ -396,7 +396,7 @@ ems_execaddr(t1000_t *dev, int pg, uint16_t val) static uint8_t -ems_in(uint16_t addr, void *priv) +ems_in(uint16_t addr, priv_t priv) { t1000_t *dev = (t1000_t *)priv; uint8_t ret; @@ -409,7 +409,7 @@ ems_in(uint16_t addr, void *priv) static void -ems_out(uint16_t addr, uint8_t val, void *priv) +ems_out(uint16_t addr, uint8_t val, priv_t priv) { t1000_t *dev = (t1000_t *)priv; int pg = (addr >> 14) & 3; @@ -507,7 +507,7 @@ addr_to_page(uint32_t addr) /* Read RAM in the EMS page frame. */ static uint8_t -ems_read(uint32_t addr, void *priv) +ems_read(uint32_t addr, priv_t priv) { t1000_t *dev = (t1000_t *)priv; int pg = addr_to_page(addr); @@ -520,7 +520,7 @@ ems_read(uint32_t addr, void *priv) static uint16_t -ems_readw(uint32_t addr, void *priv) +ems_readw(uint32_t addr, priv_t priv) { t1000_t *dev = (t1000_t *)priv; int pg = addr_to_page(addr); @@ -539,7 +539,7 @@ ems_readw(uint32_t addr, void *priv) static uint32_t -ems_readl(uint32_t addr, void *priv) +ems_readl(uint32_t addr, priv_t priv) { t1000_t *dev = (t1000_t *)priv; int pg = addr_to_page(addr); @@ -555,7 +555,7 @@ ems_readl(uint32_t addr, void *priv) /* Write RAM in the EMS page frame. */ static void -ems_write(uint32_t addr, uint8_t val, void *priv) +ems_write(uint32_t addr, uint8_t val, priv_t priv) { t1000_t *dev = (t1000_t *)priv; int pg = addr_to_page(addr); @@ -571,7 +571,7 @@ ems_write(uint32_t addr, uint8_t val, void *priv) static void -ems_writew(uint32_t addr, uint16_t val, void *priv) +ems_writew(uint32_t addr, uint16_t val, priv_t priv) { t1000_t *dev = (t1000_t *)priv; int pg = addr_to_page(addr); @@ -590,7 +590,7 @@ ems_writew(uint32_t addr, uint16_t val, void *priv) static void -ems_writel(uint32_t addr, uint32_t val, void *priv) +ems_writel(uint32_t addr, uint32_t val, priv_t priv) { t1000_t *dev = (t1000_t *)priv; int pg = addr_to_page(addr); @@ -605,44 +605,6 @@ ems_writel(uint32_t addr, uint32_t val, void *priv) } -static uint8_t -read_ctl(uint16_t addr, void *priv) -{ - t1000_t *dev = (t1000_t *)priv; - uint8_t ret = 0xff; - - switch (addr & 0x0f) { - case 1: - ret = dev->syskeys; - break; - - case 0x0f: /* Detect EMS board */ - switch (dev->sys_ctl[0x0e]) { - case 0x50: - if (mem_size > 512) break; - ret = (0x90 | dev->ems_port_index); - break; - - case 0x51: - /* 0x60 is the page frame address: - (0xd000 - 0xc400) / 0x20 */ - ret = (dev->ems_base | 0x60); - break; - - case 0x52: - ret = (dev->is_640k ? 0x80 : 0); - break; - } - break; - - default: - ret = (dev->sys_ctl[addr & 0x0f]); - } - - return(ret); -} - - /* Load contents of "CONFIG.SYS" device from file. */ static void cfgsys_load(t1000_t *dev) @@ -729,7 +691,7 @@ turbo_set(t1000_t *dev, uint8_t value) static void -write_ctl(uint16_t addr, uint8_t val, void *priv) +ctl_write(uint16_t addr, uint8_t val, priv_t priv) { t1000_t *dev = (t1000_t *)priv; @@ -773,6 +735,44 @@ write_ctl(uint16_t addr, uint8_t val, void *priv) } +static uint8_t +ctl_read(uint16_t addr, priv_t priv) +{ + t1000_t *dev = (t1000_t *)priv; + uint8_t ret = 0xff; + + switch (addr & 0x0f) { + case 1: + ret = dev->syskeys; + break; + + case 0x0f: /* Detect EMS board */ + switch (dev->sys_ctl[0x0e]) { + case 0x50: + if (mem_size > 512) break; + ret = (0x90 | dev->ems_port_index); + break; + + case 0x51: + /* 0x60 is the page frame address: + (0xd000 - 0xc400) / 0x20 */ + ret = (dev->ems_base | 0x60); + break; + + case 0x52: + ret = (dev->is_640k ? 0x80 : 0); + break; + } + break; + + default: + ret = (dev->sys_ctl[addr & 0x0f]); + } + + return(ret); +} + + /* * Ports 0xc0 to 0xc3 appear to have two purposes: * @@ -782,7 +782,7 @@ write_ctl(uint16_t addr, uint8_t val, void *priv) * */ static uint8_t -read_nvram(uint16_t addr, void *priv) +nvram_read(uint16_t addr, priv_t priv) { t1000_t *dev = (t1000_t *)priv; uint8_t tmp = 0xff; @@ -808,18 +808,17 @@ read_nvram(uint16_t addr, void *priv) } -/* Read from T1200 NVRAM. */ static uint8_t -nvram_read(uint32_t addr, void *priv) +nvram_mem_read(uint32_t addr, priv_t priv) { t1000_t *dev = (t1000_t *)priv; - return(dev->cfgsys[addr & 0x7ff]); + return(dev->cfgsys[addr & 0x07ff]); } static void -write_nvram(uint16_t addr, uint8_t val, void *priv) +nvram_write(uint16_t addr, uint8_t val, priv_t priv) { t1000_t *dev = (t1000_t *)priv; @@ -866,22 +865,22 @@ write_nvram(uint16_t addr, uint8_t val, void *priv) } -/* Write to T1200 NVRAM. */ static void -nvram_write(uint32_t addr, uint8_t val, void *priv) +nvram_mem_write(uint32_t addr, uint8_t val, priv_t priv) { t1000_t *dev = (t1000_t *)priv; - if (dev->cfgsys[addr & 0x7ff] != val) + if (dev->cfgsys[addr & 0x07ff] != val) { nvr_dosave = 1; - dev->cfgsys[addr & 0x7ff] = val; + dev->cfgsys[addr & 0x07ff] = val; + } } /* Port 0xc8 controls the ROM drive. */ static uint8_t -read_rom_ctl(uint16_t addr, void *priv) +ctl_rom_read(uint16_t addr, priv_t priv) { t1000_t *dev = (t1000_t *)priv; @@ -890,7 +889,7 @@ read_rom_ctl(uint16_t addr, void *priv) static void -write_rom_ctl(uint16_t addr, uint8_t val, void *priv) +ctl_rom_write(uint16_t addr, uint8_t val, priv_t priv) { t1000_t *dev = (t1000_t *)priv; @@ -909,7 +908,7 @@ write_rom_ctl(uint16_t addr, uint8_t val, void *priv) /* Read the ROM drive */ static uint8_t -read_rom(uint32_t addr, void *priv) +read_rom(uint32_t addr, priv_t priv) { t1000_t *dev = (t1000_t *)priv; @@ -921,7 +920,7 @@ read_rom(uint32_t addr, void *priv) static uint16_t -read_romw(uint32_t addr, void *priv) +read_romw(uint32_t addr, priv_t priv) { t1000_t *dev = (t1000_t *)priv; @@ -933,7 +932,7 @@ read_romw(uint32_t addr, void *priv) static uint32_t -read_roml(uint32_t addr, void *priv) +read_roml(uint32_t addr, priv_t priv) { t1000_t *dev = (t1000_t *)priv; @@ -944,7 +943,21 @@ read_roml(uint32_t addr, void *priv) } -static void * +static void +t1000_close(priv_t priv) +{ + t1000_t *dev = (t1000_t *)priv; + + if (dev->romdrive != NULL) + free(dev->romdrive); + + cfgsys_save(dev); + + free(dev); +} + + +static priv_t t1000_init(const device_t *info, void *arg) { t1000_t *dev; @@ -959,14 +972,15 @@ t1000_init(const device_t *info, void *arg) dev->ems_port_index = 7; /* EMS disabled */ /* Add machine device to the system. */ - device_add_ex(info, dev); + device_add_ex(info, (priv_t)dev); if (dev->is_t1200) { /* Non-volatile RAM for CONFIG.SYS */ dev->cfgsys_len = 2048; dev->cfgsys = (uint8_t *)mem_alloc(dev->cfgsys_len); mem_map_add(&dev->nvr_mapping, 0x0f0000, dev->cfgsys_len, - nvram_read,NULL,NULL, nvram_write,NULL,NULL, NULL, 0, dev); + nvram_mem_read,NULL,NULL, + nvram_mem_write,NULL,NULL, NULL, 0, dev); } else { /* * The ROM drive is optional. @@ -992,14 +1006,14 @@ t1000_init(const device_t *info, void *arg) } io_sethandler(0xc8, 1, - read_rom_ctl,NULL,NULL, write_rom_ctl,NULL,NULL, dev); + ctl_rom_read,NULL,NULL, ctl_rom_write,NULL,NULL, dev); } /* Non-volatile RAM for CONFIG.SYS */ dev->cfgsys_len = 160; dev->cfgsys = (uint8_t *)mem_alloc(dev->cfgsys_len); io_sethandler(0xc0, 4, - read_nvram,NULL,NULL, write_nvram,NULL,NULL, dev); + nvram_read,NULL,NULL, nvram_write,NULL,NULL, dev); } /* Load or initialize the NVRAM "config.sys" file. */ @@ -1018,7 +1032,7 @@ t1000_init(const device_t *info, void *arg) /* System control functions, and add-on memory board */ io_sethandler(0xe0, 16, - read_ctl,NULL,NULL, write_ctl,NULL,NULL, dev); + ctl_read,NULL,NULL, ctl_write,NULL,NULL, dev); machine_common_init(); @@ -1054,21 +1068,7 @@ t1000_init(const device_t *info, void *arg) } } - return(dev); -} - - -static void -t1000_close(void *priv) -{ - t1000_t *dev = (t1000_t *)priv; - - if (dev->romdrive != NULL) - free(dev->romdrive); - - cfgsys_save(dev); - - free(dev); + return((priv_t)dev); } diff --git a/src/machines/m_tosh1x00_vid.c b/src/machines/m_tosh1x00_vid.c index 11f0571..3f08fa7 100644 --- a/src/machines/m_tosh1x00_vid.c +++ b/src/machines/m_tosh1x00_vid.c @@ -9,7 +9,7 @@ * Implementation of the Toshiba T1000 plasma display, which * has a fixed resolution of 640x200 pixels. * - * Version: @(#)m_tosh1x00_vid.c 1.0.11 2019/04/25 + * Version: @(#)m_tosh1x00_vid.c 1.0.12 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -346,7 +346,7 @@ vid_cgaline4(vid_t *dev) static void -vid_poll(void *priv) +vid_poll(priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -556,7 +556,7 @@ recalc_attrs(vid_t *dev) static void -vid_out(uint16_t addr, uint8_t val, void *priv) +vid_out(uint16_t addr, uint8_t val, priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -596,7 +596,7 @@ vid_out(uint16_t addr, uint8_t val, void *priv) static uint8_t -vid_in(uint16_t addr, void *priv) +vid_in(uint16_t addr, priv_t priv) { vid_t *dev = (vid_t *)priv; uint8_t ret; @@ -620,7 +620,7 @@ vid_in(uint16_t addr, void *priv) static void -vid_write(uint32_t addr, uint8_t val, void *priv) +vid_write(uint32_t addr, uint8_t val, priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -631,7 +631,7 @@ vid_write(uint32_t addr, uint8_t val, void *priv) static uint8_t -vid_read(uint32_t addr, void *priv) +vid_read(uint32_t addr, priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -641,7 +641,27 @@ vid_read(uint32_t addr, void *priv) } -static void * +static void +vid_close(priv_t priv) +{ + vid_t *dev = (vid_t *)priv; + + free(dev->vram); + + free(dev); +} + + +static void +speed_changed(priv_t priv) +{ + vid_t *dev = (vid_t *)priv; + + recalc_timings(dev); +} + + +static priv_t vid_init(const device_t *info, UNUSED(void *parent)) { vid_t *dev; @@ -679,27 +699,7 @@ vid_init(const device_t *info, UNUSED(void *parent)) video_inform(VID_TYPE_CGA, &timing_t1000); - return(dev); -} - - -static void -vid_close(void *priv) -{ - vid_t *dev = (vid_t *)priv; - - free(dev->vram); - - free(dev); -} - - -static void -speed_changed(void *priv) -{ - vid_t *dev = (vid_t *)priv; - - recalc_timings(dev); + return((priv_t)dev); } diff --git a/src/machines/m_tosh3100e.c b/src/machines/m_tosh3100e.c index b622f88..16a6f0b 100644 --- a/src/machines/m_tosh3100e.c +++ b/src/machines/m_tosh3100e.c @@ -121,7 +121,7 @@ * bit 2 set for single-pixel LCD font * bits 0,1 for display font * - * Version: @(#)m_t3100e.c 1.0.12 2019/04/10 + * Version: @(#)m_t3100e.c 1.0.13 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -193,7 +193,7 @@ typedef struct { } t3100e_t; -static void ems_out(uint16_t addr, uint8_t val, void *priv); +static void ems_out(uint16_t, uint8_t, priv_t); /* Given a memory address (which ought to be in the page frame at 0xD0000), @@ -378,7 +378,7 @@ map_ram(t3100e_t *dev, uint8_t val) static uint8_t -sys_in(uint16_t addr, void *priv) +sys_in(uint16_t addr, priv_t priv) { t3100e_t *dev = (t3100e_t *)priv; @@ -393,7 +393,7 @@ sys_in(uint16_t addr, void *priv) /* Handle writes to the T3100e system control port at 0x8084 */ static void -sys_out(uint16_t addr, uint8_t val, void *priv) +sys_out(uint16_t addr, uint8_t val, priv_t priv) { t3100e_t *dev = (t3100e_t *)priv; @@ -419,7 +419,7 @@ sys_out(uint16_t addr, uint8_t val, void *priv) /* Read EMS page register */ static uint8_t -ems_in(uint16_t addr, void *priv) +ems_in(uint16_t addr, priv_t priv) { t3100e_t *dev = (t3100e_t *)priv; @@ -430,7 +430,7 @@ ems_in(uint16_t addr, void *priv) /* Write EMS page register */ static void -ems_out(uint16_t addr, uint8_t val, void *priv) +ems_out(uint16_t addr, uint8_t val, priv_t priv) { t3100e_t *dev = (t3100e_t *)priv; int pg = port_to_page(addr); @@ -455,7 +455,7 @@ ems_out(uint16_t addr, uint8_t val, void *priv) /* Read RAM in the EMS page frame. */ static uint8_t -ems_read(uint32_t addr, void *priv) +ems_read(uint32_t addr, priv_t priv) { t3100e_t *dev = (t3100e_t *)priv; int pg = addr_to_page(addr); @@ -469,7 +469,7 @@ ems_read(uint32_t addr, void *priv) static uint16_t -ems_readw(uint32_t addr, void *priv) +ems_readw(uint32_t addr, priv_t priv) { t3100e_t *dev = (t3100e_t *)priv; int pg = addr_to_page(addr); @@ -485,7 +485,7 @@ ems_readw(uint32_t addr, void *priv) static uint32_t -ems_readl(uint32_t addr, void *priv) +ems_readl(uint32_t addr, priv_t priv) { t3100e_t *dev = (t3100e_t *)priv; int pg = addr_to_page(addr); @@ -500,7 +500,7 @@ ems_readl(uint32_t addr, void *priv) /* Write RAM in the EMS page frame. */ static void -ems_write(uint32_t addr, uint8_t val, void *priv) +ems_write(uint32_t addr, uint8_t val, priv_t priv) { t3100e_t *dev = (t3100e_t *)priv; int pg = addr_to_page(addr); @@ -513,7 +513,7 @@ ems_write(uint32_t addr, uint8_t val, void *priv) static void -ems_writew(uint32_t addr, uint16_t val, void *priv) +ems_writew(uint32_t addr, uint16_t val, priv_t priv) { t3100e_t *dev = (t3100e_t *)priv; int pg = addr_to_page(addr); @@ -529,7 +529,7 @@ ems_writew(uint32_t addr, uint16_t val, void *priv) static void -ems_writel(uint32_t addr, uint32_t val, void *priv) +ems_writel(uint32_t addr, uint32_t val, priv_t priv) { t3100e_t *dev = (t3100e_t *)priv; int pg = addr_to_page(addr); @@ -544,7 +544,7 @@ ems_writel(uint32_t addr, uint32_t val, void *priv) /* Read RAM in the upper area. This is basically what the 'remapped' * mapping in mem.c does, except that the upper area can move around */ static uint8_t -upper_read(uint32_t addr, void *priv) +upper_read(uint32_t addr, priv_t priv) { t3100e_t *dev = (t3100e_t *)priv; @@ -555,7 +555,7 @@ upper_read(uint32_t addr, void *priv) static uint16_t -upper_readw(uint32_t addr, void *priv) +upper_readw(uint32_t addr, priv_t priv) { t3100e_t *dev = (t3100e_t *)priv; @@ -566,7 +566,7 @@ upper_readw(uint32_t addr, void *priv) static uint32_t -upper_readl(uint32_t addr, void *priv) +upper_readl(uint32_t addr, priv_t priv) { t3100e_t *dev = (t3100e_t *)priv; @@ -577,7 +577,7 @@ upper_readl(uint32_t addr, void *priv) static void -upper_write(uint32_t addr, uint8_t val, void *priv) +upper_write(uint32_t addr, uint8_t val, priv_t priv) { t3100e_t *dev = (t3100e_t *)priv; @@ -587,7 +587,7 @@ upper_write(uint32_t addr, uint8_t val, void *priv) static void -upper_writew(uint32_t addr, uint16_t val, void *priv) +upper_writew(uint32_t addr, uint16_t val, priv_t priv) { t3100e_t *dev = (t3100e_t *)priv; @@ -597,7 +597,7 @@ upper_writew(uint32_t addr, uint16_t val, void *priv) static void -upper_writel(uint32_t addr, uint32_t val, void *priv) +upper_writel(uint32_t addr, uint32_t val, priv_t priv) { t3100e_t *dev = (t3100e_t *)priv; @@ -607,7 +607,7 @@ upper_writel(uint32_t addr, uint32_t val, void *priv) static uint8_t -kbd_get(void *priv) +kbd_get(priv_t priv) { t3100e_t *dev = (t3100e_t *)priv; @@ -616,7 +616,7 @@ kbd_get(void *priv) static void -kbd_set(void *priv, uint8_t value) +kbd_set(priv_t priv, uint8_t value) { t3100e_t *dev = (t3100e_t *)priv; @@ -625,7 +625,7 @@ kbd_set(void *priv, uint8_t value) static void -t3100e_close(void *priv) +t3100e_close(priv_t priv) { t3100e_t *dev = (t3100e_t *)priv; @@ -633,7 +633,7 @@ t3100e_close(void *priv) } -static void * +static priv_t t3100e_init(const device_t *info, void *arg) { t3100e_t *dev; @@ -644,7 +644,7 @@ t3100e_init(const device_t *info, void *arg) memset(dev, 0x00, sizeof(t3100e_t)); /* Add machine device to system. */ - device_add_ex(info, dev); + device_add_ex(info, (priv_t)dev); m_at_common_ide_init(); @@ -686,7 +686,7 @@ t3100e_init(const device_t *info, void *arg) device_add(&t3100e_vid_device); - return(dev); + return((priv_t)dev); } @@ -721,7 +721,7 @@ const device_t m_tosh_3100e = { * Bit 0: Set if the F2HD jumper is present (internal floppy is 720k) */ uint8_t -t3100e_config_get(void *priv) +t3100e_config_get(priv_t priv) { t3100e_t *dev = (t3100e_t *)priv; uint8_t ret = 0x28; /* start with bits 5 and 3 set */ @@ -792,7 +792,7 @@ t3100e_config_get(void *priv) void -t3100e_notify_set(void *priv, uint8_t val) +t3100e_notify_set(priv_t priv, uint8_t val) { t3100e_t *dev = (t3100e_t *)priv; @@ -801,7 +801,7 @@ t3100e_notify_set(void *priv, uint8_t val) void -t3100e_mono_set(void *priv, uint8_t val) +t3100e_mono_set(priv_t priv, uint8_t val) { t3100e_t *dev = (t3100e_t *)priv; @@ -810,7 +810,7 @@ t3100e_mono_set(void *priv, uint8_t val) uint8_t -t3100e_mono_get(void *priv) +t3100e_mono_get(priv_t priv) { t3100e_t *dev = (t3100e_t *)priv; @@ -819,7 +819,7 @@ t3100e_mono_get(void *priv) void -t3100e_turbo_set(void *priv, uint8_t val) +t3100e_turbo_set(priv_t priv, uint8_t val) { t3100e_t *dev = (t3100e_t *)priv; diff --git a/src/machines/m_tosh3100e.h b/src/machines/m_tosh3100e.h index d5b127b..4059f3d 100644 --- a/src/machines/m_tosh3100e.h +++ b/src/machines/m_tosh3100e.h @@ -8,7 +8,7 @@ * * Definitions for the Toshiba T3100e system. * - * Version: @(#)m_tosh3100e.h 1.0.4 2019/03/31 + * Version: @(#)m_tosh3100e.h 1.0.5 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -44,11 +44,11 @@ extern const device_t t3100e_vid_device; /* Used by the AT keyboard driver. */ -extern void t3100e_notify_set(void *priv, uint8_t value); -extern uint8_t t3100e_config_get(void *priv); -extern void t3100e_turbo_set(void *priv, uint8_t value); -extern uint8_t t3100e_mono_get(void *priv); -extern void t3100e_mono_set(void *priv, uint8_t value); +extern void t3100e_notify_set(priv_t, uint8_t value); +extern uint8_t t3100e_config_get(priv_t); +extern void t3100e_turbo_set(priv_t, uint8_t value); +extern uint8_t t3100e_mono_get(priv_t); +extern void t3100e_mono_set(priv_t, uint8_t value); extern void t3100e_video_options_set(uint8_t options); extern void t3100e_display_set(uint8_t value); diff --git a/src/machines/m_tosh3100e_vid.c b/src/machines/m_tosh3100e_vid.c index 5d70ee0..fe44616 100644 --- a/src/machines/m_tosh3100e_vid.c +++ b/src/machines/m_tosh3100e_vid.c @@ -22,7 +22,7 @@ * 61 50 52 0F 19 06 19 19 02 0D 0B 0C MONO * 2D 28 22 0A 67 00 64 67 02 03 06 07 640x400 * - * Version: @(#)m_t3100e_vid.c 1.0.12 2019/05/05 + * Version: @(#)m_t3100e_vid.c 1.0.13 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -241,7 +241,7 @@ recalc_attrs(vid_t *dev) static void -vid_out(uint16_t port, uint8_t val, void *priv) +vid_out(uint16_t port, uint8_t val, priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -279,7 +279,7 @@ vid_out(uint16_t port, uint8_t val, void *priv) static uint8_t -vid_in(uint16_t port, void *priv) +vid_in(uint16_t port, priv_t priv) { vid_t *dev = (vid_t *)priv; uint8_t ret; @@ -300,7 +300,7 @@ vid_in(uint16_t port, void *priv) static void -vid_write(uint32_t addr, uint8_t val, void *priv) +vid_write(uint32_t addr, uint8_t val, priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -311,7 +311,7 @@ vid_write(uint32_t addr, uint8_t val, void *priv) static uint8_t -vid_read(uint32_t addr, void *priv) +vid_read(uint32_t addr, priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -557,7 +557,7 @@ cga_line4(vid_t *dev) static void -vid_poll(void *priv) +vid_poll(priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -656,14 +656,14 @@ vid_poll(void *priv) static int -load_font(vid_t *dev, const wchar_t *s) +load_font(vid_t *dev, const wchar_t *fn) { FILE *fp; int c, d; - fp = rom_fopen(s, L"rb"); + fp = rom_fopen(fn, L"rb"); if (fp == NULL) { - ERRLOG("T3100e: cannot load font '%ls'\n", s); + ERRLOG("T3100e: cannot load font '%ls'\n", fn); return(0); } @@ -693,7 +693,27 @@ load_font(vid_t *dev, const wchar_t *s) } -static void * +static void +vid_close(priv_t priv) +{ + vid_t *dev = (vid_t *)priv; + + free(dev->vram); + + free(dev); +} + + +static void +speed_changed(priv_t priv) +{ + vid_t *dev = (vid_t *)priv; + + recalc_timings(dev); +} + + +static priv_t vid_init(const device_t *info, UNUSED(void *parent)) { vid_t *dev; @@ -734,27 +754,7 @@ vid_init(const device_t *info, UNUSED(void *parent)) video_inform(VID_TYPE_CGA, &t3100e_timing); - return(dev); -} - - -static void -vid_close(void *priv) -{ - vid_t *dev = (vid_t *)priv; - - free(dev->vram); - - free(dev); -} - - -static void -speed_changed(void *priv) -{ - vid_t *dev = (vid_t *)priv; - - recalc_timings(dev); + return((priv_t)dev); } diff --git a/src/machines/m_tyan.c b/src/machines/m_tyan.c index ea3d854..53be53e 100644 --- a/src/machines/m_tyan.c +++ b/src/machines/m_tyan.c @@ -27,7 +27,7 @@ * As stated above, it is hoped that by re-adding these, more * testing will get done so they can be 'completed' sometime. * - * Version: @(#)m_tyan.c 1.0.1 2019/04/13 + * Version: @(#)m_tyan.c 1.0.2 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -79,11 +79,11 @@ #include "machine.h" -static void * +static priv_t common_init(const device_t *info, void *arg) { /* Allocate machine device to system. */ - device_add_ex(info, arg); + device_add_ex(info, (priv_t)arg); switch(info->local) { /* S1662: Tyan Titan-Pro AT/440FX/Award BIOS/SMC FDC37C665 */ @@ -102,7 +102,7 @@ common_init(const device_t *info, void *arg) device_add(&intel_flash_bxt_device); m_at_common_init(); device_add(&keyboard_ps2_pci_device); - memregs_init(); + device_add(&memregs_device); device_add(&fdc37c669_device); break; @@ -123,13 +123,13 @@ common_init(const device_t *info, void *arg) device_add(&intel_flash_bxt_device); m_at_common_init(); device_add(&keyboard_ps2_ami_pci_device); - memregs_init(); + device_add(&memregs_device); device_add(&fdc37c665_device); break; } - return(arg); + return((priv_t)arg); } diff --git a/src/machines/m_wd76c10.c b/src/machines/m_wd76c10.c index fecd694..43492d5 100644 --- a/src/machines/m_wd76c10.c +++ b/src/machines/m_wd76c10.c @@ -8,7 +8,7 @@ * * Implementation of the WD76C10 based machines. * - * Version: @(#)m_wd76c10.c 1.0.12 2019/04/08 + * Version: @(#)m_wd76c10.c 1.0.13 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -51,11 +51,11 @@ #include "machine.h" -static void * +static priv_t common_init(const device_t *info, void *arg) { /* Add machine device to system. */ - device_add_ex(info, arg); + device_add_ex(info, (priv_t)arg); device_add(&wd76c10_device); @@ -68,7 +68,7 @@ common_init(const device_t *info, void *arg) break; } - return(arg); + return((priv_t)arg); } diff --git a/src/machines/m_xi8088.c b/src/machines/m_xi8088.c index 761ba19..8d2a7c0 100644 --- a/src/machines/m_xi8088.c +++ b/src/machines/m_xi8088.c @@ -8,7 +8,7 @@ * * Implementation of the Xi8088 open-source machine. * - * Version: @(#)m_xi8088.c 1.0.14 2019/04/10 + * Version: @(#)m_xi8088.c 1.0.15 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -82,7 +82,7 @@ bios_128k_set(xi8088_t *dev, int val) static uint8_t -turbo_get(void *priv) +turbo_get(priv_t priv) { xi8088_t *dev = (xi8088_t *)priv; @@ -91,7 +91,7 @@ turbo_get(void *priv) static void -turbo_set(void *priv, uint8_t val) +turbo_set(priv_t priv, uint8_t val) { xi8088_t *dev = (xi8088_t *)priv; @@ -103,17 +103,26 @@ turbo_set(void *priv, uint8_t val) } -static void * +static void +xi_close(priv_t priv) +{ + xi8088_t *dev = (xi8088_t *)priv; + + free(dev); +} + + +static priv_t xi_init(const device_t *info, void *arg) { xi8088_t *dev; - void *kbd; + priv_t kbd; dev = (xi8088_t *)mem_alloc(sizeof(xi8088_t)); memset(dev, 0x00, sizeof(xi8088_t)); /* Add machine device to system. */ - device_add_ex(info, dev); + device_add_ex(info, (priv_t)dev); machine_common_init(); @@ -152,16 +161,7 @@ xi_init(const device_t *info, void *arg) device_add(&fdc_xt_device); - return(dev); -} - - -static void -xi_close(void *priv) -{ - xi8088_t *dev = (xi8088_t *)priv; - - free(dev); + return((priv_t)dev); } diff --git a/src/machines/m_xt.c b/src/machines/m_xt.c index 7848fab..ee2f128 100644 --- a/src/machines/m_xt.c +++ b/src/machines/m_xt.c @@ -8,7 +8,7 @@ * * Implementation of standard IBM PC/XT class machine. * - * Version: @(#)m_xt.c 1.0.18 2019/05/05 + * Version: @(#)m_xt.c 1.0.19 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -66,8 +66,15 @@ typedef struct { } pcxt_t; +static void +xt_close(priv_t priv) +{ + free(priv); +} + + /* Generic PC/XT system board with just the basics. */ -static void * +static priv_t xt_common_init(const device_t *info, void *arg) { pcxt_t *dev; @@ -78,7 +85,7 @@ xt_common_init(const device_t *info, void *arg) dev->type = info->local; /* First of all, add the root device. */ - device_add_ex(info, dev); + device_add_ex(info, (priv_t)dev); /* Check if we support a BASIC ROM. */ dev->basic = machine_get_config_int("rom_basic"); @@ -119,14 +126,7 @@ xt_common_init(const device_t *info, void *arg) if (dev->floppy) device_add(&fdc_xt_device); - return(dev); -} - - -static void -xt_close(void *priv) -{ - free(priv); + return((priv_t)dev); } diff --git a/src/machines/m_zenith.c b/src/machines/m_zenith.c index cf5b0da..64747c8 100644 --- a/src/machines/m_zenith.c +++ b/src/machines/m_zenith.c @@ -25,7 +25,7 @@ * to be done on implementing other parts of the Yamaha V6355 * chip that implements the video controller. * - * Version: @(#)m_zenith.c 1.0.7 2019/05/05 + * Version: @(#)m_zenith.c 1.0.8 2019/05/13 * * Authors: Fred N. van Kempen, * Original patch for PCem by 'Tux' @@ -123,7 +123,7 @@ typedef struct { /* Set the current NVR time. */ #define set_nibbles(a, v) regs[(a##10)] = ((v)/10) ; regs[(a##1)] = ((v)%10) static void -rtc_time_set(uint8_t *regs, struct tm *tm) +rtc_time_set(uint8_t *regs, const struct tm *tm) { set_nibbles(RTC_SECOND, tm->tm_sec); set_nibbles(RTC_MINUTE, tm->tm_min); @@ -245,7 +245,7 @@ rtc_reset(nvr_t *nvr) /* Write to one of the RTC registers. */ static void -rtc_write(uint16_t addr, uint8_t val, void *priv) +rtc_write(uint16_t addr, uint8_t val, priv_t priv) { nvr_t *nvr = (nvr_t *)priv; uint8_t *ptr; @@ -274,7 +274,7 @@ INFO("Zenith: rtc_wr(%04x, %02x)\n", addr, val); /* Read from one of the RTC registers. */ static uint8_t -rtc_read(uint16_t addr, void *priv) +rtc_read(uint16_t addr, priv_t priv) { nvr_t *nvr = (nvr_t *)priv; uint8_t r = 0xff; @@ -303,7 +303,7 @@ INFO("Zenith: rtc_rd(%04x) = %02x\n", addr, r); /* Read from the Scratchpad RAM, which is apparently 2K in size. */ static uint8_t -sp_read(uint32_t addr, void *priv) +sp_read(uint32_t addr, priv_t priv) { zenith_t *dev = (zenith_t *)priv; @@ -313,7 +313,7 @@ sp_read(uint32_t addr, void *priv) /* Write to the Scratchpad RAM, which is apparently 2K in size. */ static void -sp_write(uint32_t addr, uint8_t val, void *priv) +sp_write(uint32_t addr, uint8_t val, priv_t priv) { zenith_t *dev = (zenith_t *)priv; @@ -322,7 +322,7 @@ sp_write(uint32_t addr, uint8_t val, void *priv) static void -zenith_close(void *priv) +zenith_close(priv_t priv) { zenith_t *dev = (zenith_t *)priv; @@ -337,17 +337,17 @@ zenith_close(void *priv) } -static void * +static priv_t zenith_init(const device_t *info, void *arg) { zenith_t *dev; - void *vid; + priv_t vid; dev = (zenith_t *)mem_alloc(sizeof(zenith_t)); memset(dev, 0x00, sizeof(zenith_t)); /* Add machine device to system. */ - device_add_ex(info, dev); + device_add_ex(info, (priv_t)dev); dev->lcd = machine_get_config_int("lcd"); @@ -391,7 +391,7 @@ zenith_init(const device_t *info, void *arg) device_add(&fdc_xt_device); - return(dev); + return((priv_t)dev); } diff --git a/src/machines/m_zenith_vid.c b/src/machines/m_zenith_vid.c index d379920..b9e42f9 100644 --- a/src/machines/m_zenith_vid.c +++ b/src/machines/m_zenith_vid.c @@ -17,7 +17,7 @@ * done on implementing other parts of the Yamaha V6355 chip * that implements the video controller. * - * Version: @(#)m_zenith_vid.c 1.0.3 2019/04/25 + * Version: @(#)m_zenith_vid.c 1.0.4 2019/05/13 * * Authors: Fred N. van Kempen, * John Elliott, @@ -330,7 +330,7 @@ vid_cgaline4(vid_t *dev) static void -vid_poll(void *priv) +vid_poll(priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -525,7 +525,7 @@ recalc_attrs(vid_t *dev) static void -vid_out(uint16_t addr, uint8_t val, void *priv) +vid_out(uint16_t addr, uint8_t val, priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -560,7 +560,7 @@ INFO("Zenith: vid_out(%04x, %02x)\n", addr, val); static uint8_t -vid_in(uint16_t addr, void *priv) +vid_in(uint16_t addr, priv_t priv) { vid_t *dev = (vid_t *)priv; uint8_t ret = 0xff; @@ -585,7 +585,7 @@ INFO("Zenith: vid_in(%04x) = %02x\n", addr, ret); static void -vid_write(uint32_t addr, uint8_t val, void *priv) +vid_write(uint32_t addr, uint8_t val, priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -596,7 +596,7 @@ vid_write(uint32_t addr, uint8_t val, void *priv) static uint8_t -vid_read(uint32_t addr, void *priv) +vid_read(uint32_t addr, priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -607,7 +607,7 @@ vid_read(uint32_t addr, void *priv) static void -vid_close(void *priv) +vid_close(priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -618,7 +618,7 @@ vid_close(void *priv) static void -speed_changed(void *priv) +speed_changed(priv_t priv) { vid_t *dev = (vid_t *)priv; @@ -626,7 +626,7 @@ speed_changed(void *priv) } -static void * +static priv_t vid_init(const device_t *info, UNUSED(void *parent)) { vid_t *dev; @@ -662,7 +662,7 @@ vid_init(const device_t *info, UNUSED(void *parent)) video_inform(VID_TYPE_CGA, &timing_zenith); - return(dev); + return((priv_t)dev); } diff --git a/src/mem.c b/src/mem.c index 097f408..ad97567 100644 --- a/src/mem.c +++ b/src/mem.c @@ -12,7 +12,7 @@ * The Port92 stuff should be moved to devices/system/memctl.c * as a standard device. * - * Version: @(#)mem.c 1.0.35 2019/05/03 + * Version: @(#)mem.c 1.0.37 2019/05/15 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -114,9 +114,6 @@ static int _mem_state[0x40000]; static uint8_t ff_pccache[4] = { 0xff, 0xff, 0xff, 0xff }; -static uint8_t port_92_reg = 0, - port_92_mask = 0; - int mem_addr_is_ram(uint32_t addr) @@ -1582,6 +1579,7 @@ mem_remap_top(int kb) uint32_t start = (mem_size >= 1024) ? mem_size : 1024; int size = mem_size - 640; uint32_t i; + int offset; INFO("MEM: remapping top %iKB (mem=%i)\n", kb, mem_size); @@ -1598,10 +1596,16 @@ mem_remap_top(int kb) size = kb; for (i = ((start * 1024) >> 12); i < (((start + size) * 1024) >> 12); i++) { - pages[i].mem = &ram[0xA0000 + ((i - ((start * 1024) >> 12)) << 12)]; + offset = i - ((start * 1024) >> 12); + pages[i].mem = &ram[0xA0000 + (offset << 12)]; pages[i].write_b = mem_write_ramb_page; pages[i].write_w = mem_write_ramw_page; pages[i].write_l = mem_write_raml_page; +#if 0 /* new CPU code only */ + pages[c].evict_prev = EVICT_NOT_IN_LIST; + pages[c].byte_dirty_mask = &byte_dirty_mask[offset * 64]; + pages[c].byte_code_present_mask = &byte_code_present_mask[offset * 64]; +#endif } mem_set_mem_state(start * 1024, size * 1024, @@ -1656,64 +1660,3 @@ mem_a20_recalc(void) mem_a20_state = state; } - - -uint8_t -port_92_read(uint16_t port, void *priv) -{ - return port_92_reg | port_92_mask; -} - - -void -port_92_write(uint16_t port, uint8_t val, void *priv) -{ - if ((mem_a20_alt ^ val) & 2) { - mem_a20_alt = (val & 2); - mem_a20_recalc(); - } - - if ((~port_92_reg & val) & 1) { - cpu_reset(0); - cpu_set_edx(); - } - - port_92_reg = val | port_92_mask; -} - - -void -port_92_clear_reset(void) -{ - port_92_reg &= 2; -} - - -void -port_92_add(int inv) -{ - port_92_mask = (inv) ? 0xfc : 0x00; - - io_sethandler(0x0092, 1, - port_92_read,NULL,NULL, port_92_write, NULL,NULL,NULL); -} - - -void -port_92_remove(void) -{ - io_removehandler(0x0092, 1, - port_92_read,NULL,NULL, port_92_write,NULL,NULL, NULL); -} - - -void -port_92_reset(void) -{ - port_92_reg = 0; - - mem_a20_alt = 0; - mem_a20_recalc(); - - flushmmucache(); -} diff --git a/src/mem.h b/src/mem.h index a816ee2..70275a1 100644 --- a/src/mem.h +++ b/src/mem.h @@ -8,7 +8,7 @@ * * Definitions for the memory interface. * - * Version: @(#)mem.h 1.0.17 2019/04/27 + * Version: @(#)mem.h 1.0.18 2019/05/15 * * Authors: Fred N. van Kempen, * Sarah Walker, @@ -242,13 +242,6 @@ extern void mem_init(void); extern void mem_reset(void); extern void mem_remap_top(int kb); -extern uint8_t port_92_read(uint16_t port, void *priv); -extern void port_92_write(uint16_t port, uint8_t val, void *priv); -extern void port_92_clear_reset(void); -extern void port_92_add(int inv); -extern void port_92_remove(void); -extern void port_92_reset(void); - #ifdef EMU_CPU_H static __inline uint32_t get_phys_noabrt(uint32_t addr) diff --git a/src/nvr.c b/src/nvr.c index 45df497..237ad32 100644 --- a/src/nvr.c +++ b/src/nvr.c @@ -8,7 +8,7 @@ * * Implement a generic NVRAM/CMOS/RTC device. * - * Version: @(#)nvr.c 1.0.19 2019/05/05 + * Version: @(#)nvr.c 1.0.20 2019/05/13 * * Author: Fred N. van Kempen, * @@ -118,7 +118,7 @@ rtc_tick(void) /* This is the RTC one-second timer. */ static void -onesec_timer(void *priv) +onesec_timer(priv_t priv) { nvr_t *nvr = (nvr_t *)priv; diff --git a/src/timer.c b/src/timer.c index 5ac9f01..30a9006 100644 --- a/src/timer.c +++ b/src/timer.c @@ -8,7 +8,7 @@ * * System timer module. * - * Version: @(#)timer.c 1.0.3 2019/04/25 + * Version: @(#)timer.c 1.0.4 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -59,8 +59,8 @@ static struct { int64_t *count; int64_t *enable; - void (*callback)(void *priv); - void *priv; + void (*callback)(priv_t); + priv_t priv; } timers[TIMERS_MAX]; static int present = 0; static int64_t latch = 0; @@ -140,7 +140,7 @@ timer_reset(void) int -timer_add(void (*callback)(void *priv), void *priv, int64_t *count, int64_t *enable) +timer_add(void (*callback)(priv_t), priv_t priv, int64_t *count, int64_t *enable) { int i = 0; diff --git a/src/timer.h b/src/timer.h index a6504d2..9368562 100644 --- a/src/timer.h +++ b/src/timer.h @@ -8,7 +8,7 @@ * * Definitions for the system timer module. * - * Version: @(#)timer.h 1.0.3 2019/04/25 + * Version: @(#)timer.h 1.0.4 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -84,7 +84,7 @@ extern int64_t timer_count; extern void timer_process(void); extern void timer_update_outstanding(void); extern void timer_reset(void); -extern int timer_add(void (*callback)(void *priv), void *priv, +extern int timer_add(void (*callback)(priv_t), priv_t priv, int64_t *count, int64_t *enable); diff --git a/src/win/mingw/Makefile.MinGW b/src/win/mingw/Makefile.MinGW index 8de5725..248d9b2 100644 --- a/src/win/mingw/Makefile.MinGW +++ b/src/win/mingw/Makefile.MinGW @@ -8,7 +8,7 @@ # # Makefile for Windows systems using the MinGW32 environment. # -# Version: @(#)Makefile.mingw 1.0.88 2019/05/12 +# Version: @(#)Makefile.mingw 1.0.88 2019/05/15 # # Author: Fred N. van Kempen, # @@ -737,7 +737,7 @@ CPUOBJ := cpu.o cpu_table.o \ 386_dynarec.o $(DYNARECOBJ) SYSOBJ := clk.o dma.o nmi.o pic.o pit.o ppi.o pci.o mca.o \ - mcr.o memregs.o nvr_at.o nvr_ps2.o + mcr.o memregs.o nvr_at.o nvr_ps2.o port92.o CHIPOBJ := neat.o scat.o headland.o \ acc2168.o ali1429.o opti495.o sis471.o sis496.o \ diff --git a/src/win/msvc/Makefile.VC b/src/win/msvc/Makefile.VC index f6ff001..e306067 100644 --- a/src/win/msvc/Makefile.VC +++ b/src/win/msvc/Makefile.VC @@ -8,7 +8,7 @@ # # Makefile for Windows using Visual Studio 2015. # -# Version: @(#)Makefile.VC 1.0.72 2019/05/12 +# Version: @(#)Makefile.VC 1.0.72 2019/05/15 # # Author: Fred N. van Kempen, # @@ -646,7 +646,8 @@ CPUOBJ := cpu.obj cpu_table.obj \ 386_dynarec.obj $(DYNARECOBJ) SYSOBJ := clk.obj dma.obj nmi.obj pic.obj pit.obj ppi.obj pci.obj \ - mca.obj mcr.obj memregs.obj nvr_at.obj nvr_ps2.obj + mca.obj mcr.obj memregs.obj nvr_at.obj nvr_ps2.obj \ + port92.obj CHIPOBJ := neat.obj scat.obj headland.obj \ acc2168.obj ali1429.obj opti495.obj sis471.obj sis496.obj \ diff --git a/src/win/win_devconf.c b/src/win/win_devconf.c index 86b808d..889da0d 100644 --- a/src/win/win_devconf.c +++ b/src/win/win_devconf.c @@ -12,7 +12,7 @@ * and builds a complete Win32 DIALOG resource block in a * buffer in memory, and then passes that to the API handler. * - * Version: @(#)win_devconf.c 1.0.23 2019/04/11 + * Version: @(#)win_devconf.c 1.0.24 2019/05/13 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -70,7 +70,7 @@ dlg_init(HWND hdlg) wchar_t temp[512]; char ansitmp[512]; const device_config_t *cfg; - const device_config_selection_t *sel; + const devcfg_selection_t *sel; const device_t *dev = devconf_device; int c, id, num, val; wchar_t* str; @@ -175,7 +175,7 @@ dlg_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { wchar_t ws[512], temp[512]; char s[512], *ansistr; - const device_config_selection_t *sel; + const devcfg_selection_t *sel; const device_t *dev = devconf_device; const device_config_t *cfg = dev->config; int c, cid, changed, d, id, val; diff --git a/src/win/win_serial.c b/src/win/win_serial.c index 24da2b6..53d3df1 100644 --- a/src/win/win_serial.c +++ b/src/win/win_serial.c @@ -12,11 +12,11 @@ * Windows and UNIX systems, with support for FTDI and Prolific * USB ports. Support for these has been removed. * - * Version: @(#)win_serial.c 1.0.5 2018/11/22 + * Version: @(#)win_serial.c 1.0.6 2019/05/13 * * Author: Fred N. van Kempen, * - * Copyright 2017,2018 Fred N. van Kempen. + * Copyright 2017-2019 Fred N. van Kempen. * * Redistribution and use in source and binary forms, with * or without modification, are permitted provided that the @@ -60,8 +60,8 @@ typedef struct { char name[80]; /* name of open port */ - void (*rd_done)(void *, int); - void *rd_arg; + void (*rd_done)(priv_t, int); + priv_t rd_arg; HANDLE handle; OVERLAPPED rov, /* READ and WRITE events */ wov; @@ -200,7 +200,7 @@ set_crtscts(serial_t *dev, int8_t yes) /* Set the port parameters. */ int -plat_serial_params(void *arg, char dbit, char par, char sbit) +plat_serial_params(priv_t arg, char dbit, char par, char sbit) { serial_t *dev = (serial_t *)arg; @@ -289,7 +289,7 @@ plat_serial_params(void *arg, char dbit, char par, char sbit) /* Put a port in transparent ("raw") state. */ void -plat_serial_raw(void *arg, void *data) +plat_serial_raw(priv_t arg, void *data) { serial_t *dev = (serial_t *)arg; DCB *dcb = (DCB *)data; @@ -334,7 +334,7 @@ plat_serial_raw(void *arg, void *data) /* Set the port speed. */ int -plat_serial_speed(void *arg, long speed) +plat_serial_speed(priv_t arg, long speed) { serial_t *dev = (serial_t *)arg; @@ -359,7 +359,7 @@ plat_serial_speed(void *arg, long speed) /* Clean up and flush. */ int -plat_serial_flush(void *arg) +plat_serial_flush(priv_t arg) { serial_t *dev = (serial_t *)arg; DWORD dwErrs; @@ -388,7 +388,7 @@ plat_serial_flush(void *arg) /* API: close an open serial port. */ void -plat_serial_close(void *arg) +plat_serial_close(priv_t arg) { serial_t *dev = (serial_t *)arg; @@ -417,7 +417,7 @@ plat_serial_close(void *arg) /* API: open a host serial port for I/O. */ -void * +priv_t plat_serial_open(const char *port, int tmo) { char temp[84]; @@ -479,17 +479,17 @@ plat_serial_open(const char *port, int tmo) * current settings, and save these for later. */ if (get_state(dev, &dev->odcb) < 0) { - plat_serial_close(dev); + plat_serial_close((priv_t)dev); return(NULL); } memcpy(&dev->dcb, &dev->odcb, sizeof(DCB)); /* Force the port to BINARY mode. */ - plat_serial_raw(dev, &dev->dcb); + plat_serial_raw((priv_t)dev, &dev->dcb); /* Set new state of this port. */ if (set_state(dev, &dev->dcb) < 0) { - plat_serial_close(dev); + plat_serial_close((priv_t)dev); return(NULL); } @@ -500,7 +500,7 @@ plat_serial_open(const char *port, int tmo) if (GetCommTimeouts(dev->handle, &to) == FALSE) { ERRLOG("%s: error %i while getting current TO\n", dev->name, GetLastError()); - plat_serial_close(dev); + plat_serial_close((priv_t)dev); return(NULL); } @@ -520,23 +520,23 @@ plat_serial_open(const char *port, int tmo) } if (SetCommTimeouts(dev->handle, &to) == FALSE) { ERRLOG("%s: error %i while setting TO\n", dev->name, GetLastError()); - plat_serial_close(dev); + plat_serial_close((priv_t)dev); return(NULL); } /* Clear all errors and flush all buffers. */ - if (plat_serial_flush(dev) < 0) { - plat_serial_close(dev); + if (plat_serial_flush((priv_t)dev) < 0) { + plat_serial_close((priv_t)dev); return(NULL); } - return(dev); + return((priv_t)dev); } /* API: activate the I/O for this port. */ int -plat_serial_active(void *arg, int flg) +plat_serial_active(priv_t arg, int flg) { serial_t *dev = (serial_t *)arg; @@ -557,7 +557,7 @@ plat_serial_active(void *arg, int flg) /* API: try to write data to an open port. */ int -plat_serial_write(void *arg, unsigned char val) +plat_serial_write(priv_t arg, unsigned char val) { serial_t *dev = (serial_t *)arg; DWORD n = 0; @@ -591,7 +591,7 @@ pclog(0,"%s: writing byte %02x\n", dev->name, val); * just to speed things up a bit. --FvK */ int -plat_serial_read(void *arg, unsigned char *bufp, int max) +plat_serial_read(priv_t arg, unsigned char *bufp, int max) { serial_t *dev = (serial_t *)arg;