1
0
Fork 0

Add timed joystick support (Justice and others) and silence a few warnings.

Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2750
This commit is contained in:
Peter Veenstra 2007-01-11 09:51:37 +00:00
parent 293fc7679f
commit 91eb2fa612
3 changed files with 95 additions and 27 deletions

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id: dosbox.cpp,v 1.107 2007-01-10 15:00:38 c2woody Exp $ */
/* $Id: dosbox.cpp,v 1.108 2007-01-11 09:51:37 qbix79 Exp $ */
#include <stdlib.h>
#include <stdarg.h>
@ -402,17 +402,23 @@ void DOSBOX_Init(void) {
secprop=control->AddSection_prop("joystick",&BIOS_Init,false);//done
MSG_Add("JOYSTICK_CONFIGFILE_HELP",
"joysticktype -- Type of joystick to emulate: auto (default), none,\n"
" 2axis (supports two joysticks), 4axis,\n"
"joysticktype -- Type of joystick to emulate: auto (default), none,\n"
" 2axis (supports two joysticks), 4axis,\n"
" fcs (Thrustmaster), ch (CH Flightstick).\n"
" none disables joystick emulation.\n"
" auto chooses emulation depending on real joystick(s).\n"
"timed -- enable timed intervals for axis. (false is old style behaviour).\n"
"autofire -- continuously fires as long as you keep the button pressed.\n"
"swap34 -- swap the 3rd and the 4th axis. can be useful for certain joysticks.\n"
);
secprop->AddInitFunction(&INT10_Init);
secprop->AddInitFunction(&MOUSE_Init); //Must be after int10 as it uses CurMode
secprop->AddInitFunction(&JOYSTICK_Init);
secprop->Add_string("joysticktype","auto");
secprop->Add_bool("timed","true");
secprop->Add_bool("autofire","false");
secprop->Add_bool("swap34","false");
// had to rename these to serial due to conflicts in config
secprop=control->AddSection_prop("serial",&SERIAL_Init,true);

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id: sdl_mapper.cpp,v 1.30 2007-01-10 15:01:15 c2woody Exp $ */
/* $Id: sdl_mapper.cpp,v 1.31 2007-01-11 09:51:37 qbix79 Exp $ */
#include <vector>
#include <list>
@ -102,8 +102,8 @@ public:
void AddBind(CBind * bind);
virtual ~CEvent() {}
virtual void Active(bool yesno)=0;
virtual INLINE void Activate(bool ev_trigger)=0;
virtual INLINE void DeActivate(bool ev_trigger)=0;
virtual void Activate(bool ev_trigger)=0;
virtual void DeActivate(bool ev_trigger)=0;
void DeActivateAll(void);
void SetValue(Bits value){
current_value=value;
@ -127,7 +127,7 @@ public:
virtual bool IsTrigger(void) {
return true;
}
INLINE void Activate(bool ev_trigger) {
void Activate(bool ev_trigger) {
if (current_value>25000) {
/* value exceeds boundary, trigger event if not active */
if (!activity) Active(true);
@ -140,7 +140,7 @@ public:
}
}
}
INLINE void DeActivate(bool /*ev_trigger*/) {
void DeActivate(bool /*ev_trigger*/) {
activity--;
if (!activity) Active(false);
}
@ -153,7 +153,7 @@ public:
virtual bool IsTrigger(void) {
return false;
}
INLINE void Activate(bool ev_trigger) {
void Activate(bool ev_trigger) {
if (ev_trigger) {
activity++;
Active(true);
@ -163,7 +163,7 @@ public:
if (!GetActivityCount()) Active(true);
}
}
INLINE void DeActivate(bool ev_trigger) {
void DeActivate(bool ev_trigger) {
if (ev_trigger) {
if (activity>0) activity--;
if (activity==0) {
@ -515,12 +515,13 @@ protected:
#define MAX_VJOY_BUTTONS 8
struct {
static struct {
bool button_pressed[MAX_VJOY_BUTTONS];
Bit16s axis_pos[8];
bool hat_pressed[16];
} virtual_joysticks[2];
class CJAxisBind;
class CJButtonBind;
class CJHatBind;
@ -588,7 +589,7 @@ protected:
Bit8u dir;
};
static bool autofire=false;
bool autofire = false;
class CStickBindGroup : public CBindGroup {
public:

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id: joystick.cpp,v 1.16 2007-01-10 15:01:15 c2woody Exp $ */
/* $Id: joystick.cpp,v 1.17 2007-01-11 09:51:37 qbix79 Exp $ */
#include <string.h>
#include "dosbox.h"
@ -29,9 +29,14 @@
#define RANGE 64
#define TIMEOUT 10
#define OHMS 120000/2
#define JOY_S_CONSTANT 0.0000242
#define S_PER_OHM 0.000000011
struct JoyStick {
bool enabled;
float xpos,ypos;
double xtick,ytick;
Bitu xcount,ycount;
bool button[2];
};
@ -41,6 +46,9 @@ static JoyStick stick[2];
static Bit32u last_write = 0;
static bool write_active = false;
static bool swap34 = false;
extern bool autofire; //sdl_mapper.cpp
static Bitu read_p201(Bitu port,Bitu iolen) {
/* Reset Joystick to 0 after TIMEOUT ms */
@ -78,6 +86,29 @@ static Bitu read_p201(Bitu port,Bitu iolen) {
return ret;
}
static Bitu read_p201_timed(Bitu port,Bitu iolen) {
Bit8u ret=0xff;
double currentTick = PIC_FullIndex();
if( stick[0].enabled ){
if( stick[0].xtick < currentTick ) ret &=~1;
if( stick[0].ytick < currentTick ) ret &=~2;
}
if( stick[1].enabled ){
if( stick[1].xtick < currentTick ) ret &=~4;
if( stick[1].ytick < currentTick ) ret &=~8;
}
if (stick[0].enabled) {
if (stick[0].button[0]) ret&=~16;
if (stick[0].button[1]) ret&=~32;
}
if (stick[1].enabled) {
if (stick[1].button[0]) ret&=~64;
if (stick[1].button[1]) ret&=~128;
}
return ret;
}
static void write_p201(Bitu port,Bitu val,Bitu iolen) {
/* Store writetime index */
write_active = true;
@ -87,11 +118,30 @@ static void write_p201(Bitu port,Bitu val,Bitu iolen) {
stick[0].ycount=(Bitu)((stick[0].ypos*RANGE)+RANGE);
}
if (stick[1].enabled) {
stick[1].xcount=(Bitu)((stick[1].xpos*RANGE)+RANGE);
stick[1].ycount=(Bitu)((stick[1].ypos*RANGE)+RANGE);
stick[1].xcount=(Bitu)(((swap34? stick[1].ypos : stick[1].xpos)*RANGE)+RANGE);
stick[1].ycount=(Bitu)(((swap34? stick[1].xpos : stick[1].ypos)*RANGE)+RANGE);
}
}
static void write_p201_timed(Bitu port,Bitu val,Bitu iolen) {
// Store writetime index
// Axes take time = 24.2 microseconds + ( 0.011 microsecons/ohm * resistance )
// to reset to 0
// Precalculate the time at which each axis hits 0 here
double currentTick = PIC_FullIndex();
if (stick[0].enabled) {
stick[0].xtick = currentTick + 1000.0*( JOY_S_CONSTANT + S_PER_OHM *
(double)(((stick[0].xpos+1.0)* OHMS)) );
stick[0].ytick = currentTick + 1000.0*( JOY_S_CONSTANT + S_PER_OHM *
(double)(((stick[0].ypos+1.0)* OHMS)) );
}
if (stick[1].enabled) {
stick[1].xtick = currentTick + 1000.0*( JOY_S_CONSTANT + S_PER_OHM *
(double)((swap34? stick[1].ypos : stick[1].xpos)+1.0) * OHMS);
stick[1].ytick = currentTick + 1000.0*( JOY_S_CONSTANT + S_PER_OHM *
(double)((swap34? stick[1].xpos : stick[1].ypos)+1.0) * OHMS);
}
}
void JOYSTICK_Enable(Bitu which,bool enabled) {
if (which<2) stick[which].enabled=enabled;
@ -145,18 +195,29 @@ public:
JOYSTICK(Section* configuration):Module_base(configuration){
Section_prop * section=static_cast<Section_prop *>(configuration);
const char * type=section->Get_string("joysticktype");
if (!strcasecmp(type,"none")) joytype=JOY_NONE;
else if (!strcasecmp(type,"false")) joytype=JOY_NONE;
else if (!strcasecmp(type,"auto")) joytype=JOY_AUTO;
else if (!strcasecmp(type,"2axis")) joytype=JOY_2AXIS;
else if (!strcasecmp(type,"4axis")) joytype=JOY_4AXIS;
else if (!strcasecmp(type,"fcs")) joytype=JOY_FCS;
else if (!strcasecmp(type,"ch")) joytype=JOY_CH;
else joytype=JOY_AUTO;
ReadHandler.Install(0x201,read_p201,IO_MB);
WriteHandler.Install(0x201,write_p201,IO_MB);
stick[0].enabled=false;
stick[1].enabled=false;
if (!strcasecmp(type,"none")) joytype = JOY_NONE;
else if (!strcasecmp(type,"false")) joytype = JOY_NONE;
else if (!strcasecmp(type,"auto")) joytype = JOY_AUTO;
else if (!strcasecmp(type,"2axis")) joytype = JOY_2AXIS;
else if (!strcasecmp(type,"4axis")) joytype = JOY_4AXIS;
else if (!strcasecmp(type,"fcs")) joytype = JOY_FCS;
else if (!strcasecmp(type,"ch")) joytype = JOY_CH;
else joytype = JOY_AUTO;
bool timed = section->Get_bool("timed");
if(timed) {
ReadHandler.Install(0x201,read_p201_timed,IO_MB);
WriteHandler.Install(0x201,write_p201_timed,IO_MB);
} else {
ReadHandler.Install(0x201,read_p201,IO_MB);
WriteHandler.Install(0x201,write_p201,IO_MB);
}
autofire = section->Get_bool("autofire");
swap34 = section->Get_bool("swap34");
stick[0].enabled = false;
stick[1].enabled = false;
stick[0].xtick = stick[0].ytick = stick[1].xtick =
stick[1].ytick = PIC_FullIndex();
}
};
static JOYSTICK* test;