home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / glquake_src / in_amigamouse.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-02-27  |  7.7 KB  |  347 lines

  1. /* 
  2. Copyright (C) 1996-1997 Id Software, Inc. 
  3.  
  4. This program is free software; you can redistribute it and/or 
  5. modify it under the terms of the GNU General Public License 
  6. as published by the Free Software Foundation; either version 2 
  7. of the License, or (at your option) any later version. 
  8.  
  9. This program is distributed in the hope that it will be useful, 
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of 
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   
  12.  
  13. See the GNU General Public License for more details. 
  14.  
  15. You should have received a copy of the GNU General Public License 
  16. along with this program; if not, write to the Free Software 
  17. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
  18.  
  19. */ 
  20.  
  21. /* in_amigamouse.c -- AMIGA mouse driver */
  22. /* Written by Frank Wille <frank@phoenix.owl.de> */
  23.  
  24. #include "quakedef.h"
  25.  
  26. #include <exec/memory.h>
  27. #include <exec/interrupts.h>
  28. #include <devices/input.h>
  29. #include <intuition/intuitionbase.h>
  30. #include <clib/alib_protos.h>
  31. #include <proto/exec.h>
  32. #ifdef __PPC__
  33. #ifdef WOS
  34. #include <clib/powerpc_protos.h>
  35. #else
  36. #include <powerup/gcclib/powerup_protos.h>
  37. #endif
  38. #endif
  39.  
  40. extern struct IntuitionBase *IntuitionBase;
  41.  
  42. #ifndef GLQUAKE
  43. extern struct Screen *QuakeScreen;
  44. #else
  45. extern struct Window *QuakeWindow;
  46. #endif
  47.  
  48. cvar_t  m_filter = {"m_filter","1"};
  49. cvar_t  m_speed = {"m_speed","16"};
  50.  
  51. qboolean mouse_avail = false;
  52. float mouse_x, mouse_y;
  53. float old_mouse_x, old_mouse_y;
  54.  
  55. extern int psxused;
  56.  
  57. /* AMIGA specific */
  58. static struct MsgPort *inputport=NULL;
  59. static struct IOStdReq *input=NULL;
  60. static byte input_dev = -1;
  61. static struct Interrupt InputHandler;
  62.  
  63. struct InputIntDat
  64. {
  65.     int LeftButtonDown;
  66.     int MidButtonDown;
  67.     int RightButtonDown;
  68.     int LeftButtonUp;
  69.     int MidButtonUp;
  70.     int RightButtonUp;
  71.     int MouseX;
  72.     int MouseY;
  73.   int MouseSpeed;
  74. };
  75.  
  76. static struct InputIntDat *InputIntData;
  77.  
  78.  
  79. /* this is a 68k routine! */
  80. extern void InputIntCode(void);
  81.  
  82.  
  83. #ifdef __STORM__
  84.  
  85. /*
  86. ===========
  87. IN_InitMouse
  88. ===========
  89. */
  90.  
  91. void IN_InitMouse (void)
  92. {
  93.     Cvar_RegisterVariable (&m_filter);
  94.     Cvar_RegisterVariable (&m_speed);
  95.  
  96.   if ( COM_CheckParm ("-nomouse") )
  97.     return;
  98.  
  99.   /* open input.device */
  100.   if (inputport = CreateMsgPort()) {
  101.     if (input = (struct IOStdReq *)CreateIORequest(inputport,sizeof(struct IOStdReq))) {
  102. #ifdef __PPC__
  103. #ifdef WOS
  104.       if (InputIntData = AllocVecPPC(sizeof(struct InputIntDat),
  105.           MEMF_CHIP|MEMF_PUBLIC|MEMF_CLEAR,8)) {
  106. #else
  107.       if (InputIntData = PPCAllocVec(sizeof(struct InputIntDat),
  108.           MEMF_CHIP|MEMF_PUBLIC|MEMF_CLEAR)) {
  109. #endif
  110. #else
  111.       if (InputIntData = AllocVec(sizeof(struct InputIntDat),
  112.           MEMF_CHIP|MEMF_PUBLIC|MEMF_CLEAR)) {
  113. #endif
  114.         InputIntData->MouseSpeed = (int)m_speed.value;
  115.         if (!(input_dev = OpenDevice("input.device",0,
  116.             (struct IORequest *)input,0))) {
  117.           InputHandler.is_Node.ln_Type = NT_INTERRUPT;
  118.           InputHandler.is_Node.ln_Pri = 100;
  119.           InputHandler.is_Data = InputIntData;
  120.           InputHandler.is_Code = (void(*)())InputIntCode;
  121.           input->io_Data = (void *)&InputHandler;
  122.           input->io_Command = IND_ADDHANDLER;
  123.           DoIO((struct IORequest *)input);
  124.           mouse_avail = true;
  125.         }
  126.       }
  127.     }
  128.   }
  129.   if (!mouse_avail) {
  130.     Con_Printf("Couldn't open input.device\n");
  131.     return;
  132.   }
  133.   Con_Printf("Amiga mouse available\n");
  134. }
  135.  
  136.  
  137. /*
  138. ===========
  139. IN_ShutdownMouse
  140. ===========
  141. */
  142. void IN_ShutdownMouse (void)
  143. {
  144.   if (mouse_avail) {
  145.     input->io_Data=(void *)&InputHandler;
  146.     input->io_Command=IND_REMHANDLER;
  147.     DoIO((struct IORequest *)input);
  148.   }
  149.   if (!input_dev)
  150.     CloseDevice((struct IORequest *)input);
  151.  
  152. #ifdef __PPC__
  153. #ifdef WOS
  154.   if (InputIntData)
  155.     FreeVecPPC(InputIntData);
  156. #else
  157.   if (InputIntData)
  158.     PPCFreeVec(InputIntData);
  159. #endif
  160. #else
  161.   if (InputIntData)
  162.     FreeVec(InputIntData);
  163. #endif
  164.  
  165.   if (input)
  166.     DeleteIORequest((struct IORequest *)input);
  167.   if (inputport)
  168.     DeleteMsgPort(inputport);
  169. }
  170. #else
  171.  
  172. /*
  173. ===========
  174. IN_InitMouse
  175. ===========
  176. */
  177.  
  178.  
  179. void IN_InitMouse (void)
  180. {
  181.     Cvar_RegisterVariable (&m_filter);
  182.     Cvar_RegisterVariable (&m_speed);
  183.  
  184.   if ( COM_CheckParm ("-nomouse") )
  185.     return;
  186.  
  187.   /* open input.device */
  188.   if (inputport = CreatePort(NULL,0)) {
  189.     if (input = CreateStdIO(inputport)) {
  190. #ifdef __PPC__
  191. #ifdef WOS
  192.       if (InputIntData = AllocVecPPC(sizeof(struct InputIntDat),
  193.           MEMF_CHIP|MEMF_PUBLIC|MEMF_CLEAR,0)) {
  194. #else
  195.       if (InputIntData = PPCAllocVec(sizeof(struct InputIntDat),
  196.           MEMF_CHIP|MEMF_PUBLIC|MEMF_CLEAR)) {
  197. #endif
  198. #else
  199.       if (InputIntData = AllocVec(sizeof(struct InputIntDat),
  200.           MEMF_CHIP|MEMF_PUBLIC|MEMF_CLEAR)) {
  201. #endif
  202.         InputIntData->MouseSpeed = (int)m_speed.value;
  203.         if (!(input_dev = OpenDevice("input.device",0,
  204.             (struct IORequest *)input,0))) {
  205.           InputHandler.is_Node.ln_Type = NT_INTERRUPT;
  206.           InputHandler.is_Node.ln_Pri = 100;
  207.           InputHandler.is_Data = InputIntData;
  208.           InputHandler.is_Code = (void(*)())InputIntCode;
  209.           input->io_Data = (void *)&InputHandler;
  210.           input->io_Command = IND_ADDHANDLER;
  211.           DoIO((struct IORequest *)input);
  212.           mouse_avail = true;
  213.         }
  214.       }
  215.     }
  216.   }
  217.   if (!mouse_avail) {
  218.     Con_Printf("Couldn't open input.device");
  219.     return;
  220.   }
  221.   Con_Printf("Amiga mouse available\n");
  222. }
  223.  
  224.  
  225. /*
  226. ===========
  227. IN_ShutdownMouse
  228. ===========
  229. */
  230. void IN_ShutdownMouse (void)
  231. {
  232.   if (mouse_avail) {
  233.     input->io_Data=(void *)&InputHandler;
  234.     input->io_Command=IND_REMHANDLER;
  235.     DoIO((struct IORequest *)input);
  236.   }
  237.   if (!input_dev)
  238.     CloseDevice((struct IORequest *)input);
  239.  
  240. #ifdef __PPC__
  241. #ifdef WOS
  242.   if (InputIntData)
  243.     FreeVecPPC(InputIntData);
  244. #else
  245.   if (InputIntData)
  246.     PPCFreeVec(InputIntData);
  247. #endif
  248. #else
  249.   if (InputIntData)
  250.     FreeVec(InputIntData);
  251. #endif
  252.  
  253.   if (input)
  254.     DeleteStdIO(input);
  255.   if (inputport)
  256.     DeletePort(inputport);
  257. }
  258. #endif
  259.  
  260. /*
  261. ===========
  262. IN_MouseCommands
  263. ===========
  264. */
  265. void IN_MouseCommands (void)
  266. {
  267.   if (mouse_avail && psxused) {
  268.     if (InputIntData->LeftButtonDown)
  269.         Key_Event (K_MOUSE1, TRUE);
  270.     if (InputIntData->LeftButtonUp)
  271.         Key_Event (K_MOUSE1, FALSE);
  272.     if (InputIntData->MidButtonDown)
  273.         Key_Event (K_MOUSE2, TRUE);
  274.     if (InputIntData->MidButtonUp)
  275.         Key_Event (K_MOUSE2, FALSE);
  276.     if (InputIntData->RightButtonDown)
  277.         Key_Event (K_MOUSE3, TRUE);
  278.     if (InputIntData->RightButtonUp)
  279.         Key_Event (K_MOUSE3, FALSE);
  280.   }
  281. }
  282.  
  283.  
  284. /*
  285. ===========
  286. IN_MouseMove
  287. ===========
  288. */
  289. void IN_MouseMove (usercmd_t *cmd)
  290. {
  291.     int mx, my;
  292.  
  293.     if (!mouse_avail)
  294.         return;
  295.  
  296. #ifndef GLQUAKE
  297.         if (IntuitionBase->FirstScreen != QuakeScreen)
  298.           return;
  299. #else
  300.         if (IntuitionBase->ActiveWindow != QuakeWindow)
  301.           return;
  302. #endif
  303.  
  304.     mx = (float)InputIntData->MouseX;
  305.     my = (float)InputIntData->MouseY;
  306.     InputIntData->MouseX = 0;
  307.     InputIntData->MouseY = 0;
  308.  
  309.     if (m_filter.value) {
  310.         mouse_x = (mx + old_mouse_x) * 0.5;
  311.         mouse_y = (my + old_mouse_y) * 0.5;
  312.     }
  313.     else {
  314.         mouse_x = mx;
  315.         mouse_y = my;
  316.     }
  317.     old_mouse_x = mx;
  318.     old_mouse_y = my;
  319.  
  320.     mouse_x *= sensitivity.value;
  321.     mouse_y *= sensitivity.value;
  322.  
  323.   /* add mouse X/Y movement to cmd */
  324.     if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) ))
  325.         cmd->sidemove += m_side.value * mouse_x;
  326.     else
  327.         cl.viewangles[YAW] -= m_yaw.value * mouse_x;
  328.     
  329.     if (in_mlook.state & 1)
  330.         V_StopPitchDrift ();
  331.         
  332.     if ( (in_mlook.state & 1) && !(in_strafe.state & 1)) {
  333.         cl.viewangles[PITCH] += m_pitch.value * mouse_y;
  334.         if (cl.viewangles[PITCH] > 80)
  335.             cl.viewangles[PITCH] = 80;
  336.         if (cl.viewangles[PITCH] < -70)
  337.             cl.viewangles[PITCH] = -70;
  338.     }
  339.     else {
  340.         if ((in_strafe.state & 1) && noclip_anglehack)
  341.             cmd->upmove -= m_forward.value * mouse_y;
  342.         else
  343.             cmd->forwardmove -= m_forward.value * mouse_y;
  344.     }
  345.   InputIntData->MouseSpeed = (int)m_speed.value;
  346. }
  347.