From 29c5c45609d0e6df8712e8a2004dbdf1987d660e Mon Sep 17 00:00:00 2001 From: Volker Ruppert Date: Thu, 31 Mar 2011 16:54:06 +0000 Subject: [PATCH] - implemented gameport (joystick) presence control by external device and use it in the ES1370 device (enabled by default) --- bochs/iodev/devices.cc | 3 +++ bochs/iodev/es1370.cc | 11 ++++++--- bochs/iodev/gameport.cc | 51 ++++++++++++++++++++++++++--------------- bochs/iodev/gameport.h | 5 ++-- bochs/iodev/iodev.h | 15 ++++++++++++ bochs/plugin.h | 3 +++ 6 files changed, 64 insertions(+), 24 deletions(-) diff --git a/bochs/iodev/devices.cc b/bochs/iodev/devices.cc index d36e5ab56..161a7ba64 100644 --- a/bochs/iodev/devices.cc +++ b/bochs/iodev/devices.cc @@ -89,6 +89,9 @@ void bx_devices_c::init_stubs() #if BX_SUPPORT_APIC pluginIOAPIC = &stubIOAPIC; #endif +#if BX_SUPPORT_GAMEPORT + pluginGameport = &stubGameport; +#endif #if BX_SUPPORT_PCIUSB pluginUsbDevCtl = &stubUsbDevCtl; #endif diff --git a/bochs/iodev/es1370.cc b/bochs/iodev/es1370.cc index 29019de9b..882bc4b4c 100644 --- a/bochs/iodev/es1370.cc +++ b/bochs/iodev/es1370.cc @@ -192,6 +192,8 @@ void bx_es1370_c::reset(unsigned type) BX_ES1370_THIS s.chan[i].leftover = 0; } + DEV_gameport_set_enabled(0); + // Deassert IRQ set_irq_level(0); } @@ -356,6 +358,9 @@ void bx_es1370_c::write(Bit32u address, Bit32u value, unsigned io_len) case ES1370_CTL: mask = (0xffffffff >> ((4 - io_len) << 3)) << shift; value = (BX_ES1370_THIS s.ctl & ~mask) | ((value << shift) & mask); + if ((value ^ BX_ES1370_THIS s.ctl) & 0x04) { + DEV_gameport_set_enabled((value & 0x04) != 0); + } BX_ES1370_THIS update_voices(value, BX_ES1370_THIS s.sctl, 0); break; case ES1370_UART_DATA: @@ -555,7 +560,7 @@ void bx_es1370_c::update_voices(Bit32u ctl, Bit32u sctl, bx_bool force) new_freq = 1411200 / (((ctl >> 16) & 0x1fff) + 2); } - if (((old_fmt != new_fmt) || (old_freq != new_freq)) || force) { + if ((old_fmt != new_fmt) || (old_freq != new_freq) || force) { d->shift = (new_fmt & 1) + (new_fmt >> 1); if (new_freq) { if (i == DAC2_CHANNEL) { @@ -570,8 +575,8 @@ void bx_es1370_c::update_voices(Bit32u ctl, Bit32u sctl, bx_bool force) } } } - if ((((ctl ^ BX_ES1370_THIS s.ctl) & ctl_ch_en[i]) || - ((sctl ^ BX_ES1370_THIS s.sctl) & sctl_ch_pause[i])) || force) { + if (((ctl ^ BX_ES1370_THIS s.ctl) & ctl_ch_en[i]) || + ((sctl ^ BX_ES1370_THIS s.sctl) & sctl_ch_pause[i]) || force) { bx_bool on = ((ctl & ctl_ch_en[i]) && !(sctl & sctl_ch_pause[i])); if (i == DAC1_CHANNEL) { diff --git a/bochs/iodev/gameport.cc b/bochs/iodev/gameport.cc index b45080229..a0cb80f67 100644 --- a/bochs/iodev/gameport.cc +++ b/bochs/iodev/gameport.cc @@ -57,6 +57,7 @@ bx_gameport_c *theGameport = NULL; int libgameport_LTX_plugin_init(plugin_t *plugin, plugintype_t type, int argc, char *argv[]) { theGameport = new bx_gameport_c(); + bx_devices.pluginGameport = theGameport; BX_REGISTER_DEVICE_DEVMODEL(plugin, type, theGameport, BX_PLUGIN_GAMEPORT); return(0); // Success } @@ -86,6 +87,8 @@ void bx_gameport_c::init(void) DEV_register_iowrite_handler(this, write_handler, addr, "Gameport", 1); } + // always enabled unless controlled by external device + BX_GAMEPORT_THIS enabled = 1; BX_GAMEPORT_THIS port = 0xf0; BX_GAMEPORT_THIS write_usec = 0; BX_GAMEPORT_THIS timer_x = 0; @@ -115,7 +118,8 @@ void bx_gameport_c::reset(unsigned type) void bx_gameport_c::register_state(void) { - bx_list_c *list = new bx_list_c(SIM->get_bochs_root(), "gameport", "Gameport State", 6); + bx_list_c *list = new bx_list_c(SIM->get_bochs_root(), "gameport", "Gameport State", 7); + BXRS_PARAM_BOOL(list, enabled, BX_GAMEPORT_THIS enabled); BXRS_HEX_PARAM_FIELD(list, port, BX_GAMEPORT_THIS port); BXRS_DEC_PARAM_FIELD(list, delay_x, BX_GAMEPORT_THIS delay_x); BXRS_DEC_PARAM_FIELD(list, delay_y, BX_GAMEPORT_THIS delay_y); @@ -189,25 +193,30 @@ Bit32u bx_gameport_c::read(Bit32u address, unsigned io_len) #endif // !BX_USE_GAMEPORT_SMF Bit64u usec; - if (BX_GAMEPORT_THIS joyfd >= 0) { - poll_joydev(); - usec = bx_pc_system.time_usec(); - if (BX_GAMEPORT_THIS timer_x) { - if ((usec - BX_GAMEPORT_THIS write_usec) >= BX_GAMEPORT_THIS delay_x) { - BX_GAMEPORT_THIS port &= 0xfe; - BX_GAMEPORT_THIS timer_x = 0; + if (BX_GAMEPORT_THIS enabled) { + if (BX_GAMEPORT_THIS joyfd >= 0) { + poll_joydev(); + usec = bx_pc_system.time_usec(); + if (BX_GAMEPORT_THIS timer_x) { + if ((usec - BX_GAMEPORT_THIS write_usec) >= BX_GAMEPORT_THIS delay_x) { + BX_GAMEPORT_THIS port &= 0xfe; + BX_GAMEPORT_THIS timer_x = 0; + } } - } - if (BX_GAMEPORT_THIS timer_y) { - if ((usec - BX_GAMEPORT_THIS write_usec) >= BX_GAMEPORT_THIS delay_y) { - BX_GAMEPORT_THIS port &= 0xfd; - BX_GAMEPORT_THIS timer_y = 0; + if (BX_GAMEPORT_THIS timer_y) { + if ((usec - BX_GAMEPORT_THIS write_usec) >= BX_GAMEPORT_THIS delay_y) { + BX_GAMEPORT_THIS port &= 0xfd; + BX_GAMEPORT_THIS timer_y = 0; + } } + } else { + BX_DEBUG(("read: joystick not present")); } + return BX_GAMEPORT_THIS port; } else { - BX_DEBUG(("read: joystick not present")); + BX_DEBUG(("read: gameport disabled")); + return 0xff; } - return BX_GAMEPORT_THIS port; } @@ -227,8 +236,12 @@ void bx_gameport_c::write(Bit32u address, Bit32u value, unsigned io_len) UNUSED(this_ptr); #endif // !BX_USE_GAMEPORT_SMF - BX_GAMEPORT_THIS write_usec = bx_pc_system.time_usec(); - BX_GAMEPORT_THIS timer_x = 1; - BX_GAMEPORT_THIS timer_y = 1; - BX_GAMEPORT_THIS port |= 0x0f; + if (BX_GAMEPORT_THIS enabled) { + BX_GAMEPORT_THIS write_usec = bx_pc_system.time_usec(); + BX_GAMEPORT_THIS timer_x = 1; + BX_GAMEPORT_THIS timer_y = 1; + BX_GAMEPORT_THIS port |= 0x0f; + } else { + BX_DEBUG(("write: gameport disabled")); + } } diff --git a/bochs/iodev/gameport.h b/bochs/iodev/gameport.h index a1dacfbc5..f4ecb86f1 100644 --- a/bochs/iodev/gameport.h +++ b/bochs/iodev/gameport.h @@ -31,16 +31,17 @@ #endif -class bx_gameport_c : public bx_devmodel_c { +class bx_gameport_c : public bx_game_stub_c { public: bx_gameport_c(); virtual ~bx_gameport_c(); virtual void init(void); virtual void reset(unsigned type); virtual void register_state(void); + virtual void set_enabled(bx_bool val) {enabled = val;} private: - + bx_bool enabled; int joyfd; Bit8u port; Bit16u delay_x; diff --git a/bochs/iodev/iodev.h b/bochs/iodev/iodev.h index 5c2af1eec..dc41aee9c 100644 --- a/bochs/iodev/iodev.h +++ b/bochs/iodev/iodev.h @@ -341,6 +341,15 @@ public: }; #endif +#if BX_SUPPORT_GAMEPORT +class BOCHSAPI bx_game_stub_c : public bx_devmodel_c { +public: + virtual void set_enabled(bx_bool val) { + STUBFUNC(gameport, set_enabled); + } +}; +#endif + #if BX_SUPPORT_PCIUSB class BOCHSAPI bx_usb_devctl_stub_c : public bx_devmodel_c { public: @@ -447,6 +456,9 @@ public: #if BX_SUPPORT_APIC bx_ioapic_stub_c *pluginIOAPIC; #endif +#if BX_SUPPORT_GAMEPORT + bx_game_stub_c *pluginGameport; +#endif #if BX_SUPPORT_PCIUSB bx_usb_devctl_stub_c *pluginUsbDevCtl; #endif @@ -481,6 +493,9 @@ public: #if BX_SUPPORT_APIC bx_ioapic_stub_c stubIOAPIC; #endif +#if BX_SUPPORT_GAMEPORT + bx_game_stub_c stubGameport; +#endif #if BX_SUPPORT_PCIUSB bx_usb_devctl_stub_c stubUsbDevCtl; #endif diff --git a/bochs/plugin.h b/bochs/plugin.h index cf5683bb5..6829a0283 100644 --- a/bochs/plugin.h +++ b/bochs/plugin.h @@ -253,6 +253,9 @@ extern "C" { ///////// Sound macro #define DEV_sound_init_module(a,b,c) bx_devices.pluginSoundModCtl->init_module(a,(void**)b,c) +///////// Gameport macro +#define DEV_gameport_set_enabled(a) bx_devices.pluginGameport->set_enabled(a) + #if BX_HAVE_DLFCN_H #include