From dfd6d4e2df6f22bdd18c0c40c422db5b4f97c25a Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Thu, 3 Jun 2021 01:14:48 -0300 Subject: [PATCH] Add game port device with 6 I/O ports for the Crystal CS4237/8B --- src/game/gameport.c | 25 ++++++++++++++++++------- src/include/86box/gameport.h | 1 + src/sound/snd_cs423x.c | 7 ++++--- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/game/gameport.c b/src/game/gameport.c index 2c56f13b8..d33efb897 100644 --- a/src/game/gameport.c +++ b/src/game/gameport.c @@ -45,6 +45,7 @@ typedef struct { typedef struct _gameport_ { uint16_t addr; + uint8_t len; struct _joystick_instance_ *joystick; struct _gameport_ *next; } gameport_t; @@ -314,7 +315,7 @@ gameport_remap(void *priv, uint16_t address) } } - io_removehandler(dev->addr, (dev->addr & 1) ? 1 : 8, + io_removehandler(dev->addr, dev->len, gameport_read, NULL, NULL, gameport_write, NULL, NULL, dev); } @@ -334,7 +335,7 @@ gameport_remap(void *priv, uint16_t address) other_dev->next = dev; } - io_sethandler(dev->addr, (dev->addr & 1) ? 1 : 8, + io_sethandler(dev->addr, dev->len, gameport_read, NULL, NULL, gameport_write, NULL, NULL, dev); } } @@ -358,7 +359,7 @@ gameport_add(const device_t *gameport_type) { /* Prevent a standalone game port from being added later on, unless this is an unused Super I/O game port (no MACHINE_GAMEPORT machine flag). */ - if (!(gameport_type->local & 0x10000) || (machines[machine].flags & MACHINE_GAMEPORT)) + if (!(gameport_type->local & 0x1000000) || (machines[machine].flags & MACHINE_GAMEPORT)) standalone_gameport_type = NULL; /* Add game port device. */ @@ -401,6 +402,7 @@ gameport_init(const device_t *info) dev->joystick = joystick_instance; /* Map game port to the default address. Not applicable on PnP-only ports. */ + dev->len = (info->local >> 16) & 0xff; gameport_remap(dev, info->local & 0xffff); /* Register ISAPnP if this is a standard game port card. */ @@ -433,7 +435,7 @@ gameport_close(void *priv) const device_t gameport_device = { "Game port", - 0, 0x200, + 0, 0x080200, gameport_init, gameport_close, NULL, { NULL }, NULL, @@ -442,7 +444,7 @@ const device_t gameport_device = { const device_t gameport_201_device = { "Game port (port 201h only)", - 0, 0x201, + 0, 0x010201, gameport_init, gameport_close, NULL, { NULL }, NULL, @@ -451,7 +453,16 @@ const device_t gameport_201_device = { const device_t gameport_pnp_device = { "Game port (Plug and Play only)", - 0, 0, + 0, 0x080000, + gameport_init, + gameport_close, + NULL, { NULL }, NULL, + NULL +}; + +const device_t gameport_pnp_6io_device = { + "Game port (Plug and Play only, 6 I/O ports)", + 0, 0x060000, gameport_init, gameport_close, NULL, { NULL }, NULL, @@ -460,7 +471,7 @@ const device_t gameport_pnp_device = { const device_t gameport_sio_device = { "Game port (Super I/O)", - 0, 0x10000, + 0, 0x1080000, gameport_init, gameport_close, NULL, { NULL }, NULL, diff --git a/src/include/86box/gameport.h b/src/include/86box/gameport.h index 9f5da7f00..be8eec813 100644 --- a/src/include/86box/gameport.h +++ b/src/include/86box/gameport.h @@ -108,6 +108,7 @@ extern "C" { extern const device_t gameport_device; extern const device_t gameport_201_device; extern const device_t gameport_pnp_device; +extern const device_t gameport_pnp_6io_device; extern const device_t gameport_sio_device; extern const device_t *standalone_gameport_type; diff --git a/src/sound/snd_cs423x.c b/src/sound/snd_cs423x.c index 57bf083ca..fbc8595b1 100644 --- a/src/sound/snd_cs423x.c +++ b/src/sound/snd_cs423x.c @@ -720,6 +720,10 @@ cs423x_init(const device_t *info) break; } + /* Initialize game port. The '7B and '8B game port only responds to 6 I/O ports; the remaining + 2 ports are reserved on those chips, and probably connected to the Digital Assist feature. */ + dev->gameport = gameport_add((dev->type == CRYSTAL_CS4236B) ? &gameport_pnp_device : &gameport_pnp_6io_device); + break; } @@ -731,9 +735,6 @@ cs423x_init(const device_t *info) cs423x_reset(dev); sound_add_handler(cs423x_get_buffer, dev); - /* Initialize game port. */ - dev->gameport = gameport_add(&gameport_pnp_device); - /* Initialize I2C bus for the EEPROM. */ dev->i2c = i2c_gpio_init("nvr_cs423x");