- implemented gameport (joystick) presence control by external device and use

it in the ES1370 device (enabled by default)
This commit is contained in:
Volker Ruppert 2011-03-31 16:54:06 +00:00
parent 2b596e1bc4
commit 29c5c45609
6 changed files with 64 additions and 24 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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"));
}
}

View File

@ -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;

View File

@ -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

View File

@ -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 <dlfcn.h>