- implementation of the standard PC gameport for the Linux platform
- removed gameport stubs from the SB16 code - TODO: bochsrc option for the joystick device, implement joystick access for other platforms
This commit is contained in:
parent
52aaefacf5
commit
359dce2185
@ -252,6 +252,7 @@
|
||||
#define BX_USE_PCIUSB_SMF 1 // USB hub
|
||||
#define BX_USE_NE2K_SMF 1 // NE2K
|
||||
#define BX_USE_EFI_SMF 1 // External FPU IRQ
|
||||
#define BX_USE_GAME_SMF 1 // Gameport
|
||||
|
||||
#define BX_PLUGINS 0
|
||||
#define BX_HAVE_DLFCN_H 0
|
||||
@ -263,7 +264,7 @@
|
||||
|| !BX_USE_SER_SMF || !BX_USE_UM_SMF || !BX_USE_VGA_SMF \
|
||||
|| !BX_USE_SB16_SMF || !BX_USE_DEV_SMF || !BX_USE_PCI_SMF \
|
||||
|| !BX_USE_P2I_SMF || !BX_USE_PCIVGA_SMF || !BX_USE_PCIUSB_SMF \
|
||||
|| !BX_USE_NE2K_SMF || !BX_USE_EFI_SMF)
|
||||
|| !BX_USE_NE2K_SMF || !BX_USE_EFI_SMF || !BX_USE_GAME_SMF)
|
||||
#error You must use SMF to have plugins
|
||||
#endif
|
||||
|
||||
|
@ -86,6 +86,7 @@ OBJS_THAT_CAN_BE_PLUGINS = \
|
||||
dma.o \
|
||||
unmapped.o \
|
||||
extfpuirq.o \
|
||||
gameport.o \
|
||||
@PCI_OBJ@ \
|
||||
@SB16_OBJS@ \
|
||||
@NE2K_OBJS@
|
||||
|
@ -1,5 +1,5 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: devices.cc,v 1.53 2003-04-25 22:06:27 cbothamy Exp $
|
||||
// $Id: devices.cc,v 1.54 2003-06-21 12:55:19 vruppert Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2002 MandrakeSoft S.A.
|
||||
@ -73,6 +73,7 @@ bx_devices_c::bx_devices_c(void)
|
||||
pluginSB16Device = NULL;
|
||||
pluginNE2kDevice =&stubNE2k;
|
||||
pluginExtFpuIrq = NULL;
|
||||
pluginGameport = NULL;
|
||||
g2h = NULL;
|
||||
#if BX_IODEBUG_SUPPORT
|
||||
iodebug = NULL;
|
||||
@ -93,7 +94,7 @@ bx_devices_c::init(BX_MEM_C *newmem)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
BX_DEBUG(("Init $Id: devices.cc,v 1.53 2003-04-25 22:06:27 cbothamy Exp $"));
|
||||
BX_DEBUG(("Init $Id: devices.cc,v 1.54 2003-06-21 12:55:19 vruppert Exp $"));
|
||||
mem = newmem;
|
||||
|
||||
/* no read / write handlers defined */
|
||||
@ -145,6 +146,7 @@ bx_devices_c::init(BX_MEM_C *newmem)
|
||||
if (is_parallel_enabled ())
|
||||
PLUG_load_plugin(parallel, PLUGTYPE_OPTIONAL);
|
||||
PLUG_load_plugin(extfpuirq, PLUGTYPE_OPTIONAL);
|
||||
PLUG_load_plugin(gameport, PLUGTYPE_OPTIONAL);
|
||||
|
||||
// Start with registering the default (unmapped) handler
|
||||
pluginUnmapped->init ();
|
||||
|
216
bochs/iodev/gameport.cc
Normal file
216
bochs/iodev/gameport.cc
Normal file
@ -0,0 +1,216 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: gameport.cc,v 1.1 2003-06-21 12:55:19 vruppert Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2003 MandrakeSoft S.A.
|
||||
//
|
||||
// MandrakeSoft S.A.
|
||||
// 43, rue d'Aboukir
|
||||
// 75002 Paris - France
|
||||
// http://www.linux-mandrake.com/
|
||||
// http://www.mandrakesoft.com/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
//
|
||||
// Standard PC gameport
|
||||
//
|
||||
|
||||
// Define BX_PLUGGABLE in files that can be compiled into plugins. For
|
||||
// platforms that require a special tag on exported symbols, BX_PLUGGABLE
|
||||
// is used to know when we are exporting symbols and when we are importing.
|
||||
#define BX_PLUGGABLE
|
||||
|
||||
#include "bochs.h"
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
#include <linux/joystick.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#endif
|
||||
|
||||
#define LOG_THIS theGameport->
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
void
|
||||
libgameport_LTX_plugin_fini(void)
|
||||
{
|
||||
}
|
||||
|
||||
bx_gameport_c::bx_gameport_c(void)
|
||||
{
|
||||
put("GAME");
|
||||
settype(EXTFPUIRQLOG);
|
||||
}
|
||||
|
||||
bx_gameport_c::~bx_gameport_c(void)
|
||||
{
|
||||
if (joyfd >= 0) close(joyfd);
|
||||
BX_DEBUG(("Exit."));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
bx_gameport_c::init(void)
|
||||
{
|
||||
// Allocate the gameport IO address range 0x200..0x207
|
||||
for (unsigned addr=0x200; addr<0x208; addr++) {
|
||||
DEV_register_ioread_handler(this, read_handler, addr, "Gameport", 7);
|
||||
DEV_register_iowrite_handler(this, write_handler, addr, "Gameport", 7);
|
||||
}
|
||||
|
||||
BX_GAMEPORT_THIS port = 0xf0;
|
||||
BX_GAMEPORT_THIS write_usec = 0;
|
||||
BX_GAMEPORT_THIS timer_x = 0;
|
||||
BX_GAMEPORT_THIS timer_y = 0;
|
||||
|
||||
#ifdef __linux__
|
||||
BX_GAMEPORT_THIS joyfd = open("/dev/input/js0", O_RDONLY);
|
||||
if (BX_GAMEPORT_THIS joyfd >= 0) {
|
||||
for (unsigned i=0; i<4; i++) poll_joydev();
|
||||
}
|
||||
#else
|
||||
BX_GAMEPORT_THIS joyfd = -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
bx_gameport_c::reset(unsigned type)
|
||||
{
|
||||
// nothing for now
|
||||
}
|
||||
|
||||
void
|
||||
bx_gameport_c::poll_joydev(void)
|
||||
{
|
||||
#ifdef __linux__
|
||||
struct js_event e;
|
||||
fd_set joyfds;
|
||||
struct timeval tv;
|
||||
|
||||
memset(&tv, 0, sizeof(tv));
|
||||
FD_ZERO(&joyfds);
|
||||
FD_SET(BX_GAMEPORT_THIS joyfd, &joyfds);
|
||||
e.type = 0;
|
||||
if (select(BX_GAMEPORT_THIS joyfd+1, &joyfds, NULL, NULL, &tv)) {
|
||||
read(BX_GAMEPORT_THIS joyfd, &e, sizeof(struct js_event));
|
||||
if (e.type & JS_EVENT_BUTTON) {
|
||||
if (e.value == 1) {
|
||||
BX_GAMEPORT_THIS port &= ~(0x10 << e.number);
|
||||
} else {
|
||||
BX_GAMEPORT_THIS port |= (0x10 << e.number);
|
||||
}
|
||||
}
|
||||
if (e.type & JS_EVENT_AXIS) {
|
||||
if (e.number == 0) {
|
||||
BX_GAMEPORT_THIS delay_x = 25 + ((e.value + 0x8000) / 60);
|
||||
}
|
||||
if (e.number == 1) {
|
||||
BX_GAMEPORT_THIS delay_y = 25 + ((e.value + 0x8000) / 62);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// static IO port read callback handler
|
||||
// redirects to non-static class handler to avoid virtual functions
|
||||
|
||||
Bit32u
|
||||
bx_gameport_c::read_handler(void *this_ptr, Bit32u address, unsigned io_len)
|
||||
{
|
||||
#if !BX_USE_GAME_SMF
|
||||
bx_gameport_c *class_ptr = (bx_gameport_c *) this_ptr;
|
||||
|
||||
return( class_ptr->read(address, io_len) );
|
||||
}
|
||||
|
||||
|
||||
Bit32u
|
||||
bx_gameport_c::read(Bit32u address, unsigned io_len)
|
||||
{
|
||||
#else
|
||||
UNUSED(this_ptr);
|
||||
#endif // !BX_USE_GAME_SMF
|
||||
Bit64u usec;
|
||||
|
||||
if (io_len > 1)
|
||||
BX_PANIC(("io read from port %04x, len=%u", (unsigned) address,
|
||||
(unsigned) io_len));
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
BX_INFO(("read: joystick not present"));
|
||||
}
|
||||
return BX_GAMEPORT_THIS port;
|
||||
}
|
||||
|
||||
|
||||
// static IO port write callback handler
|
||||
// redirects to non-static class handler to avoid virtual functions
|
||||
|
||||
void
|
||||
bx_gameport_c::write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len)
|
||||
{
|
||||
#if !BX_USE_GAME_SMF
|
||||
bx_gameport_c *class_ptr = (bx_gameport_c *) this_ptr;
|
||||
|
||||
class_ptr->write(address, value, io_len);
|
||||
}
|
||||
|
||||
void
|
||||
bx_gameport_c::write(Bit32u address, Bit32u value, unsigned io_len)
|
||||
{
|
||||
#else
|
||||
UNUSED(this_ptr);
|
||||
#endif // !BX_USE_GAME_SMF
|
||||
if (io_len > 1)
|
||||
BX_PANIC(("io write to port %04x, len=%u", (unsigned) address,
|
||||
(unsigned) io_len));
|
||||
|
||||
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;
|
||||
}
|
63
bochs/iodev/gameport.h
Normal file
63
bochs/iodev/gameport.h
Normal file
@ -0,0 +1,63 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: gameport.h,v 1.1 2003-06-21 12:55:19 vruppert Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2003 MandrakeSoft S.A.
|
||||
//
|
||||
// MandrakeSoft S.A.
|
||||
// 43, rue d'Aboukir
|
||||
// 75002 Paris - France
|
||||
// http://www.linux-mandrake.com/
|
||||
// http://www.mandrakesoft.com/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
#if BX_USE_GAME_SMF
|
||||
# define BX_GAMEPORT_SMF static
|
||||
# define BX_GAMEPORT_THIS theGameport->
|
||||
#else
|
||||
# define BX_GAMEPORT_SMF
|
||||
# define BX_GAMEPORT_THIS this->
|
||||
#endif
|
||||
|
||||
|
||||
class bx_gameport_c : public bx_devmodel_c {
|
||||
|
||||
public:
|
||||
bx_gameport_c(void);
|
||||
~bx_gameport_c(void);
|
||||
virtual void init(void);
|
||||
virtual void reset(unsigned type);
|
||||
|
||||
private:
|
||||
|
||||
int joyfd;
|
||||
Bit8u port;
|
||||
Bit16u delay_x;
|
||||
Bit16u delay_y;
|
||||
bx_bool timer_x;
|
||||
bx_bool timer_y;
|
||||
Bit64u write_usec;
|
||||
|
||||
BX_GAMEPORT_SMF void poll_joydev(void);
|
||||
|
||||
static Bit32u read_handler(void *this_ptr, Bit32u address, unsigned io_len);
|
||||
static void write_handler(void *this_ptr, Bit32u address, Bit32u value, unsigned io_len);
|
||||
#if !BX_USE_GAME_SMF
|
||||
Bit32u read(Bit32u address, unsigned io_len);
|
||||
void write(Bit32u address, Bit32u value, unsigned io_len);
|
||||
#endif
|
||||
};
|
@ -1,5 +1,5 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: iodev.h,v 1.32 2003-05-03 16:37:17 cbothamy Exp $
|
||||
// $Id: iodev.h,v 1.33 2003-06-21 12:55:19 vruppert Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2002 MandrakeSoft S.A.
|
||||
@ -314,6 +314,7 @@ public:
|
||||
bx_ne2k_stub_c *pluginNE2kDevice;
|
||||
bx_g2h_c *g2h;
|
||||
bx_devmodel_c *pluginExtFpuIrq;
|
||||
bx_devmodel_c *pluginGameport;
|
||||
#if BX_IODEBUG_SUPPORT
|
||||
bx_iodebug_c *iodebug;
|
||||
#endif
|
||||
@ -417,3 +418,4 @@ private:
|
||||
#include "iodev/guest2host.h"
|
||||
#include "iodev/slowdown_timer.h"
|
||||
#include "iodev/extfpuirq.h"
|
||||
#include "iodev/gameport.h"
|
||||
|
@ -1,5 +1,5 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: sb16.cc,v 1.33 2003-04-25 23:32:55 cbothamy Exp $
|
||||
// $Id: sb16.cc,v 1.34 2003-06-21 12:55:19 vruppert Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2002 MandrakeSoft S.A.
|
||||
@ -253,14 +253,6 @@ void bx_sb16_c::init(void)
|
||||
write_handler, addr, "SB16", 7);
|
||||
}
|
||||
|
||||
// Allocate the SB16 gameport IO address range 0x200..0x207
|
||||
for (addr=0x200; addr<0x208; addr++) {
|
||||
DEV_register_ioread_handler(this, read_handler, addr, "SB16", 7);
|
||||
DEV_register_iowrite_handler(this, write_handler, addr, "SB16", 7);
|
||||
}
|
||||
|
||||
BX_SB16_THIS gameport = 0xf0;
|
||||
|
||||
writelog(BOTHLOG(3),
|
||||
"driver initialised, IRQ %d, IO %03x/%03x/%03x, DMA %d/%d",
|
||||
BX_SB16_IRQ, BX_SB16_IO, BX_SB16_IOMPU, BX_SB16_IOADLIB,
|
||||
@ -3073,17 +3065,6 @@ Bit32u bx_sb16_c::read(Bit32u address, unsigned io_len)
|
||||
case BX_SB16_IOMPU + 0x03:
|
||||
return emul_read();
|
||||
|
||||
// gameport
|
||||
case 0x0200:
|
||||
case 0x0201:
|
||||
case 0x0202:
|
||||
case 0x0203:
|
||||
case 0x0204:
|
||||
case 0x0205:
|
||||
case 0x0206:
|
||||
case 0x0207:
|
||||
BX_INFO(("read: joystick not present yet"));
|
||||
return BX_SB16_THIS gameport;
|
||||
}
|
||||
|
||||
// If we get here, the port wasn't valid
|
||||
@ -3218,19 +3199,6 @@ void bx_sb16_c::write(Bit32u address, Bit32u value, unsigned io_len)
|
||||
case BX_SB16_IOMPU + 0x03:
|
||||
emul_write(value);
|
||||
return;
|
||||
|
||||
// gameport
|
||||
case 0x0200:
|
||||
case 0x0201:
|
||||
case 0x0202:
|
||||
case 0x0203:
|
||||
case 0x0204:
|
||||
case 0x0205:
|
||||
case 0x0206:
|
||||
case 0x0207:
|
||||
BX_INFO(("write: joystick not present yet"));
|
||||
BX_SB16_THIS gameport |= 0x0f;
|
||||
break;
|
||||
}
|
||||
|
||||
// if we arrive here, the port is unsupported
|
||||
|
@ -1,5 +1,5 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: sb16.h,v 1.13 2003-04-07 17:08:38 vruppert Exp $
|
||||
// $Id: sb16.h,v 1.14 2003-06-21 12:55:19 vruppert Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2001 MandrakeSoft S.A.
|
||||
@ -208,7 +208,6 @@ private:
|
||||
int currentirq;
|
||||
int currentdma8;
|
||||
int currentdma16;
|
||||
Bit8u gameport;
|
||||
|
||||
// the MPU 401 relevant variables
|
||||
struct bx_sb16_mpu_struct {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// $Id: plugin.h,v 1.15 2003-01-28 16:56:58 vruppert Exp $
|
||||
// $Id: plugin.h,v 1.16 2003-06-21 12:55:19 vruppert Exp $
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// This file provides macros and types needed for plugins. It is based on
|
||||
@ -39,6 +39,7 @@ extern "C" {
|
||||
#define BX_PLUGIN_EXTFPUIRQ "extfpuirq"
|
||||
#define BX_PLUGIN_PCIVGA "pcivga"
|
||||
#define BX_PLUGIN_PCIUSB "pciusb"
|
||||
#define BX_PLUGIN_GAMEPORT "gameport"
|
||||
|
||||
|
||||
#define BX_REGISTER_DEVICE pluginRegisterDevice
|
||||
@ -307,6 +308,7 @@ DECLARE_PLUGIN_INIT_FINI_FOR_MODULE(pciusb)
|
||||
DECLARE_PLUGIN_INIT_FINI_FOR_MODULE(sb16)
|
||||
DECLARE_PLUGIN_INIT_FINI_FOR_MODULE(ne2k)
|
||||
DECLARE_PLUGIN_INIT_FINI_FOR_MODULE(extfpuirq)
|
||||
DECLARE_PLUGIN_INIT_FINI_FOR_MODULE(gameport)
|
||||
DECLARE_PLUGIN_INIT_FINI_FOR_MODULE(amigaos)
|
||||
DECLARE_PLUGIN_INIT_FINI_FOR_MODULE(beos)
|
||||
DECLARE_PLUGIN_INIT_FINI_FOR_MODULE(carbon)
|
||||
|
Loading…
Reference in New Issue
Block a user