2007-09-09 14:28:59 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2006-2007 Mark Olsen
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program 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 General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2006-03-06 22:10:32 +00:00
|
|
|
#include <exec/exec.h>
|
|
|
|
#include <intuition/intuition.h>
|
|
|
|
#include <intuition/extensions.h>
|
|
|
|
#include <intuition/intuitionbase.h>
|
|
|
|
#include <devices/input.h>
|
|
|
|
|
|
|
|
#include <proto/exec.h>
|
|
|
|
#include <proto/intuition.h>
|
|
|
|
|
|
|
|
#include <clib/alib_protos.h>
|
|
|
|
|
|
|
|
#include "quakedef.h"
|
|
|
|
#include "input.h"
|
|
|
|
|
|
|
|
#include "in_morphos.h"
|
|
|
|
|
|
|
|
struct InputEvent imsgs[MAXIMSGS];
|
|
|
|
extern struct IntuitionBase *IntuitionBase;
|
|
|
|
extern struct Window *window;
|
|
|
|
extern struct Screen *screen;
|
|
|
|
|
|
|
|
int imsglow = 0;
|
|
|
|
int imsghigh = 0;
|
|
|
|
|
|
|
|
extern qboolean mouse_active;
|
|
|
|
|
|
|
|
static struct Interrupt InputHandler;
|
|
|
|
|
|
|
|
static struct Interrupt InputHandler;
|
|
|
|
static struct MsgPort *inputport = 0;
|
|
|
|
static struct IOStdReq *inputreq = 0;
|
|
|
|
static BYTE inputret = -1;
|
|
|
|
|
|
|
|
extern cvar_t _windowed_mouse;
|
|
|
|
|
|
|
|
#define DEBUGRING(x)
|
|
|
|
|
2012-10-14 09:00:49 +00:00
|
|
|
void INS_Shutdown(void)
|
2006-03-06 22:10:32 +00:00
|
|
|
{
|
|
|
|
if (inputret == 0)
|
|
|
|
{
|
|
|
|
inputreq->io_Data = (void *)&InputHandler;
|
|
|
|
inputreq->io_Command = IND_REMHANDLER;
|
|
|
|
DoIO((struct IORequest *)inputreq);
|
|
|
|
|
|
|
|
CloseDevice((struct IORequest *)inputreq);
|
|
|
|
|
|
|
|
inputret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inputreq)
|
|
|
|
{
|
|
|
|
DeleteStdIO(inputreq);
|
|
|
|
|
|
|
|
inputreq = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inputport)
|
|
|
|
{
|
|
|
|
DeletePort(inputport);
|
|
|
|
|
|
|
|
inputport = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-14 09:00:49 +00:00
|
|
|
void INS_ReInit()
|
2006-03-06 22:10:32 +00:00
|
|
|
{
|
|
|
|
/* Cvar_Register (&m_filter, "input controls");*/
|
|
|
|
|
2012-10-14 09:00:49 +00:00
|
|
|
if (inputport)
|
|
|
|
return;
|
|
|
|
|
2006-03-06 22:10:32 +00:00
|
|
|
inputport = CreatePort(0, 0);
|
|
|
|
if (inputport == 0)
|
|
|
|
{
|
|
|
|
IN_Shutdown();
|
|
|
|
Sys_Error("Unable to create message port");
|
|
|
|
}
|
|
|
|
|
|
|
|
inputreq = CreateStdIO(inputport);
|
|
|
|
if (inputreq == 0)
|
|
|
|
{
|
|
|
|
IN_Shutdown();
|
|
|
|
Sys_Error("Unable to create IO request");
|
|
|
|
}
|
|
|
|
|
|
|
|
inputret = OpenDevice("input.device", 0, (struct IORequest *)inputreq, 0);
|
|
|
|
if (inputret != 0)
|
|
|
|
{
|
|
|
|
IN_Shutdown();
|
|
|
|
Sys_Error("Unable to open input.device");
|
|
|
|
}
|
|
|
|
|
|
|
|
InputHandler.is_Node.ln_Type = NT_INTERRUPT;
|
|
|
|
InputHandler.is_Node.ln_Pri = 100;
|
2006-03-12 12:51:17 +00:00
|
|
|
InputHandler.is_Node.ln_Name = "FTEQW input handler";
|
2006-03-06 22:10:32 +00:00
|
|
|
InputHandler.is_Data = 0;
|
|
|
|
InputHandler.is_Code = (void(*)())&myinputhandler;
|
|
|
|
inputreq->io_Data = (void *)&InputHandler;
|
|
|
|
inputreq->io_Command = IND_ADDHANDLER;
|
|
|
|
DoIO((struct IORequest *)inputreq);
|
2006-05-10 22:12:20 +00:00
|
|
|
}
|
2006-03-06 22:10:32 +00:00
|
|
|
|
2012-10-14 09:00:49 +00:00
|
|
|
void INS_Init(void)
|
2006-05-10 22:12:20 +00:00
|
|
|
{
|
2012-10-14 09:00:49 +00:00
|
|
|
INS_ReInit();
|
2006-03-06 22:10:32 +00:00
|
|
|
}
|
|
|
|
|
2012-10-14 09:00:49 +00:00
|
|
|
//IN_KeyEvent is threadsafe (for one other thread, anyway)
|
|
|
|
void INS_ProcessInputMessage(struct InputEvent *msg, qboolean consumemotion)
|
2006-03-06 22:10:32 +00:00
|
|
|
{
|
2012-10-14 11:20:14 +00:00
|
|
|
int key;
|
|
|
|
qboolean down;
|
|
|
|
int code;
|
|
|
|
|
2012-10-14 09:00:49 +00:00
|
|
|
if ((window->Flags & WFLG_WINDOWACTIVE))
|
2006-03-06 22:10:32 +00:00
|
|
|
{
|
2012-10-14 09:00:49 +00:00
|
|
|
if (msg->ie_Class == IECLASS_NEWMOUSE)
|
2006-03-06 22:10:32 +00:00
|
|
|
{
|
2012-10-14 09:00:49 +00:00
|
|
|
key = 0;
|
2006-03-06 22:10:32 +00:00
|
|
|
|
2012-10-14 09:00:49 +00:00
|
|
|
if (msg->ie_Code == NM_WHEEL_UP)
|
|
|
|
key = K_MWHEELUP;
|
|
|
|
else if (msg->ie_Code == NM_WHEEL_DOWN)
|
|
|
|
key = K_MWHEELDOWN;
|
2006-03-06 22:10:32 +00:00
|
|
|
|
2012-10-14 09:00:49 +00:00
|
|
|
if (msg->ie_Code == NM_BUTTON_FOURTH)
|
|
|
|
{
|
|
|
|
IN_KeyEvent(0, true, K_MOUSE4, 0);
|
2006-03-06 22:10:32 +00:00
|
|
|
}
|
2012-10-14 09:00:49 +00:00
|
|
|
else if (msg->ie_Code == (NM_BUTTON_FOURTH|IECODE_UP_PREFIX))
|
2006-03-06 22:10:32 +00:00
|
|
|
{
|
2012-10-14 09:00:49 +00:00
|
|
|
IN_KeyEvent(0, false, K_MOUSE4, 0);
|
2006-03-06 22:10:32 +00:00
|
|
|
}
|
|
|
|
|
2012-10-14 09:00:49 +00:00
|
|
|
if (key)
|
2006-03-06 22:10:32 +00:00
|
|
|
{
|
2012-10-14 09:00:49 +00:00
|
|
|
IN_KeyEvent(0, true, key, 0);
|
|
|
|
IN_KeyEvent(0, false, key, 0);
|
2006-03-06 22:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2012-10-14 09:00:49 +00:00
|
|
|
else if (msg->ie_Class == IECLASS_RAWKEY)
|
|
|
|
{
|
|
|
|
down = !(msg->ie_Code&IECODE_UP_PREFIX);
|
2012-10-14 11:20:14 +00:00
|
|
|
code = msg->ie_Code & ~IECODE_UP_PREFIX;
|
2006-04-16 02:10:36 +00:00
|
|
|
|
2012-10-14 09:00:49 +00:00
|
|
|
key = 0;
|
2012-10-14 11:20:14 +00:00
|
|
|
if (code <= 255)
|
|
|
|
key = keyconv[code];
|
2006-04-16 02:10:36 +00:00
|
|
|
|
2012-10-14 09:00:49 +00:00
|
|
|
if (key)
|
|
|
|
IN_KeyEvent(0, down, key, key);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// if (developer.value)
|
|
|
|
// printf("Unknown key %d\n", msg->ie_Code);
|
|
|
|
}
|
|
|
|
}
|
2006-04-16 02:10:36 +00:00
|
|
|
|
2012-10-14 09:00:49 +00:00
|
|
|
else if (msg->ie_Class == IECLASS_RAWMOUSE)
|
|
|
|
{
|
|
|
|
if (msg->ie_Code == IECODE_LBUTTON)
|
|
|
|
IN_KeyEvent(0, true, K_MOUSE1, 0);
|
|
|
|
else if (msg->ie_Code == (IECODE_LBUTTON|IECODE_UP_PREFIX))
|
|
|
|
IN_KeyEvent(0, false, K_MOUSE1, 0);
|
|
|
|
else if (msg->ie_Code == IECODE_RBUTTON)
|
|
|
|
IN_KeyEvent(0, true, K_MOUSE2, 0);
|
|
|
|
else if (msg->ie_Code == (IECODE_RBUTTON|IECODE_UP_PREFIX))
|
|
|
|
IN_KeyEvent(0, false, K_MOUSE2, 0);
|
|
|
|
else if (msg->ie_Code == IECODE_MBUTTON)
|
|
|
|
IN_KeyEvent(0, true, K_MOUSE3, 0);
|
|
|
|
else if (msg->ie_Code == (IECODE_MBUTTON|IECODE_UP_PREFIX))
|
|
|
|
IN_KeyEvent(0, false, K_MOUSE3, 0);
|
|
|
|
|
|
|
|
if (_windowed_mouse.ival)
|
|
|
|
{
|
|
|
|
if (consumemotion)
|
|
|
|
{
|
|
|
|
IN_MouseMove(0, 0, msg->ie_position.ie_xy.ie_x, msg->ie_position.ie_xy.ie_y, 0, 0);
|
2006-04-16 02:10:36 +00:00
|
|
|
|
2012-10-14 09:00:49 +00:00
|
|
|
#if 0
|
2012-10-14 11:20:14 +00:00
|
|
|
msg->ie_Class = IECLASS_NULL;
|
2012-10-14 09:00:49 +00:00
|
|
|
#else
|
2012-10-14 11:20:14 +00:00
|
|
|
msg->ie_position.ie_xy.ie_x = 0;
|
|
|
|
msg->ie_position.ie_xy.ie_y = 0;
|
2006-04-16 02:10:36 +00:00
|
|
|
#endif
|
2012-10-14 09:00:49 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-06 22:10:32 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-14 09:00:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void INS_Commands(void)
|
|
|
|
{
|
|
|
|
}
|
2016-07-21 19:27:59 +00:00
|
|
|
void INS_EnumerateDevices(void *ctx, void(*callback)(void *ctx, const char *type, const char *devicename, unsigned int *qdevid))
|
2015-04-14 23:12:17 +00:00
|
|
|
{
|
|
|
|
}
|
2018-03-04 14:41:16 +00:00
|
|
|
void INS_Move (void)
|
2012-10-14 09:00:49 +00:00
|
|
|
{
|
2006-03-06 22:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char keyconv[] =
|
|
|
|
{
|
|
|
|
'`', /* 0 */
|
|
|
|
'1',
|
|
|
|
'2',
|
|
|
|
'3',
|
|
|
|
'4',
|
|
|
|
'5',
|
|
|
|
'6',
|
|
|
|
'7',
|
|
|
|
'8',
|
|
|
|
'9',
|
|
|
|
'0', /* 10 */
|
|
|
|
'-',
|
|
|
|
'=',
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
K_INS,
|
|
|
|
'q',
|
|
|
|
'w',
|
|
|
|
'e',
|
|
|
|
'r',
|
|
|
|
't', /* 20 */
|
|
|
|
'y',
|
|
|
|
'u',
|
|
|
|
'i',
|
|
|
|
'o',
|
|
|
|
'p',
|
|
|
|
'[',
|
|
|
|
']',
|
|
|
|
0,
|
|
|
|
K_KP_END,
|
|
|
|
K_KP_DOWNARROW, /* 30 */
|
|
|
|
K_KP_PGDN,
|
|
|
|
'a',
|
|
|
|
's',
|
|
|
|
'd',
|
|
|
|
'f',
|
|
|
|
'g',
|
|
|
|
'h',
|
|
|
|
'j',
|
|
|
|
'k',
|
|
|
|
'l', /* 40 */
|
|
|
|
';',
|
|
|
|
'\'',
|
|
|
|
'\\',
|
|
|
|
0,
|
|
|
|
K_KP_LEFTARROW,
|
|
|
|
K_KP_5,
|
|
|
|
K_KP_RIGHTARROW,
|
|
|
|
'<',
|
|
|
|
'z',
|
|
|
|
'x', /* 50 */
|
|
|
|
'c',
|
|
|
|
'v',
|
|
|
|
'b',
|
|
|
|
'n',
|
|
|
|
'm',
|
|
|
|
',',
|
|
|
|
'.',
|
|
|
|
'/',
|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
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0, /* 220 */
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0, /* 230 */
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0, /* 240 */
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0, /* 250 */
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
struct InputEvent *myinputhandler_real(void);
|
|
|
|
|
|
|
|
struct EmulLibEntry myinputhandler =
|
|
|
|
{
|
|
|
|
TRAP_LIB, 0, (void(*)(void))myinputhandler_real
|
|
|
|
};
|
|
|
|
|
|
|
|
struct InputEvent *myinputhandler_real()
|
|
|
|
{
|
|
|
|
struct InputEvent *moo = (struct InputEvent *)REG_A0;
|
|
|
|
|
|
|
|
struct InputEvent *coin;
|
|
|
|
|
|
|
|
int screeninfront;
|
|
|
|
|
|
|
|
coin = moo;
|
|
|
|
|
|
|
|
if (screen)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
if (IntuitionBase->LibNode.lib_Version > 50 || (IntuitionBase == 50 && IntuitionBase->LibNode.lib_Revision >= 56))
|
|
|
|
GetAttr(screen, SA_Displayed, &screeninfront);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
screeninfront = screen==IntuitionBase->FirstScreen;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
screeninfront = 1;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (coin->ie_Class == IECLASS_RAWMOUSE || coin->ie_Class == IECLASS_RAWKEY || coin->ie_Class == IECLASS_NEWMOUSE)
|
|
|
|
{
|
2012-10-14 09:00:49 +00:00
|
|
|
INS_ProcessInputMessage(coin, screeninfront && window->MouseX > 0 && window->MouseY > 0);
|
2006-03-06 22:10:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
coin = coin->ie_NextEvent;
|
|
|
|
} while(coin);
|
|
|
|
|
|
|
|
return moo;
|
|
|
|
}
|
|
|
|
|