home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / quakeworld_src / client / in_amigamouse.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-17  |  7.5 KB  |  338 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. #pragma amiga-align
  27. #include <exec/memory.h>
  28. #include <exec/interrupts.h>
  29. #include <devices/input.h>
  30. #include <intuition/intuitionbase.h>
  31. #include <clib/alib_protos.h>
  32. #include <proto/exec.h>
  33. #ifdef __PPC__
  34. #ifdef WOS
  35. #include <clib/powerpc_protos.h>
  36. #else
  37. #include <powerup/gcclib/powerup_protos.h>
  38. #endif
  39. #endif
  40. #pragma default-align
  41.  
  42. extern struct IntuitionBase *IntuitionBase;
  43. extern struct Screen *QuakeScreen;
  44.  
  45. cvar_t  m_filter = {"m_filter","1"};
  46. cvar_t  m_speed = {"m_speed","16"};
  47.  
  48. qboolean mouse_avail = false;
  49. float mouse_x, mouse_y;
  50. float old_mouse_x, old_mouse_y;
  51.  
  52. extern int psxused;
  53.  
  54. /* AMIGA specific */
  55. static struct MsgPort *inputport=NULL;
  56. static struct IOStdReq *input=NULL;
  57. static byte input_dev = -1;
  58. static struct Interrupt InputHandler;
  59.  
  60. struct InputIntDat
  61. {
  62.     int LeftButtonDown;
  63.     int MidButtonDown;
  64.     int RightButtonDown;
  65.     int LeftButtonUp;
  66.     int MidButtonUp;
  67.     int RightButtonUp;
  68.     int MouseX;
  69.     int MouseY;
  70.   int MouseSpeed;
  71. };
  72.  
  73. static struct InputIntDat *InputIntData;
  74.  
  75.  
  76. /* this is a 68k routine! */
  77. extern void InputIntCode(void);
  78.  
  79.  
  80. #ifdef __STORM__
  81.  
  82. /*
  83. ===========
  84. IN_InitMouse
  85. ===========
  86. */
  87.  
  88. void IN_InitMouse (void)
  89. {
  90.     Cvar_RegisterVariable (&m_filter);
  91.     Cvar_RegisterVariable (&m_speed);
  92.  
  93.   if ( COM_CheckParm ("-nomouse") )
  94.     return;
  95.  
  96.   /* open input.device */
  97.   if (inputport = CreateMsgPort()) {
  98.     if (input = (struct IOStdReq *)CreateIORequest(inputport,sizeof(struct IOStdReq))) {
  99. #ifdef __PPC__
  100. #ifdef WOS
  101.       if (InputIntData = AllocVecPPC(sizeof(struct InputIntDat),
  102.           MEMF_CHIP|MEMF_PUBLIC|MEMF_CLEAR,0)) {
  103. #else
  104.       if (InputIntData = PPCAllocVec(sizeof(struct InputIntDat),
  105.           MEMF_CHIP|MEMF_PUBLIC|MEMF_CLEAR)) {
  106. #endif
  107. #else
  108.       if (InputIntData = AllocVec(sizeof(struct InputIntDat),
  109.           MEMF_CHIP|MEMF_PUBLIC|MEMF_CLEAR)) {
  110. #endif
  111.         InputIntData->MouseSpeed = (int)m_speed.value;
  112.         if (!(input_dev = OpenDevice("input.device",0,
  113.             (struct IORequest *)input,0))) {
  114.           InputHandler.is_Node.ln_Type = NT_INTERRUPT;
  115.           InputHandler.is_Node.ln_Pri = 100;
  116.           InputHandler.is_Data = InputIntData;
  117.           InputHandler.is_Code = (void(*)())InputIntCode;
  118.           input->io_Data = (void *)&InputHandler;
  119.           input->io_Command = IND_ADDHANDLER;
  120.           DoIO((struct IORequest *)input);
  121.           mouse_avail = true;
  122.         }
  123.       }
  124.     }
  125.   }
  126.   if (!mouse_avail) {
  127.     Con_Printf("Couldn't open input.device\n");
  128.     return;
  129.   }
  130.   Con_Printf("Amiga mouse available\n");
  131. }
  132.  
  133.  
  134. /*
  135. ===========
  136. IN_ShutdownMouse
  137. ===========
  138. */
  139. void IN_ShutdownMouse (void)
  140. {
  141.   if (mouse_avail) {
  142.     input->io_Data=(void *)&InputHandler;
  143.     input->io_Command=IND_REMHANDLER;
  144.     DoIO((struct IORequest *)input);
  145.   }
  146.   if (!input_dev)
  147.     CloseDevice((struct IORequest *)input);
  148.  
  149. #ifdef __PPC__
  150. #ifdef WOS
  151.   if (InputIntData)
  152.     FreeVecPPC(InputIntData);
  153. #else
  154.   if (InputIntData)
  155.     PPCFreeVec(InputIntData);
  156. #endif
  157. #else
  158.   if (InputIntData)
  159.     FreeVec(InputIntData);
  160. #endif
  161.  
  162.   if (input)
  163.     DeleteIORequest((struct IORequest *)input);
  164.   if (inputport)
  165.     DeleteMsgPort(inputport);
  166. }
  167. #else
  168.  
  169. /*
  170. ===========
  171. IN_InitMouse
  172. ===========
  173. */
  174.  
  175.  
  176. void IN_InitMouse (void)
  177. {
  178.     Cvar_RegisterVariable (&m_filter);
  179.     Cvar_RegisterVariable (&m_speed);
  180.  
  181.   if ( COM_CheckParm ("-nomouse") )
  182.     return;
  183.  
  184.   /* open input.device */
  185.   if (inputport = CreatePort(NULL,0)) {
  186.     if (input = CreateStdIO(inputport)) {
  187. #ifdef __PPC__
  188. #ifdef WOS
  189.       if (InputIntData = AllocVecPPC(sizeof(struct InputIntDat),
  190.           MEMF_CHIP|MEMF_PUBLIC|MEMF_CLEAR,0)) {
  191. #else
  192.       if (InputIntData = PPCAllocVec(sizeof(struct InputIntDat),
  193.           MEMF_CHIP|MEMF_PUBLIC|MEMF_CLEAR)) {
  194. #endif
  195. #else
  196.       if (InputIntData = AllocVec(sizeof(struct InputIntDat),
  197.           MEMF_CHIP|MEMF_PUBLIC|MEMF_CLEAR)) {
  198. #endif
  199.         InputIntData->MouseSpeed = (int)m_speed.value;
  200.         if (!(input_dev = OpenDevice("input.device",0,
  201.             (struct IORequest *)input,0))) {
  202.           InputHandler.is_Node.ln_Type = NT_INTERRUPT;
  203.           InputHandler.is_Node.ln_Pri = 100;
  204.           InputHandler.is_Data = InputIntData;
  205.           InputHandler.is_Code = (void(*)())InputIntCode;
  206.           input->io_Data = (void *)&InputHandler;
  207.           input->io_Command = IND_ADDHANDLER;
  208.           DoIO((struct IORequest *)input);
  209.           mouse_avail = true;
  210.         }
  211.       }
  212.     }
  213.   }
  214.   if (!mouse_avail) {
  215.     Con_Printf("Couldn't open input.device\n");
  216.     return;
  217.   }
  218.   Con_Printf("Amiga mouse available\n");
  219. }
  220.  
  221.  
  222. /*
  223. ===========
  224. IN_ShutdownMouse
  225. ===========
  226. */
  227. void IN_ShutdownMouse (void)
  228. {
  229.   if (mouse_avail) {
  230.     input->io_Data=(void *)&InputHandler;
  231.     input->io_Command=IND_REMHANDLER;
  232.     DoIO((struct IORequest *)input);
  233.   }
  234.   if (!input_dev)
  235.     CloseDevice((struct IORequest *)input);
  236.  
  237. #ifdef __PPC__
  238. #ifdef WOS
  239.   if (InputIntData)
  240.     FreeVecPPC(InputIntData);
  241. #else
  242.   if (InputIntData)
  243.     PPCFreeVec(InputIntData);
  244. #endif
  245. #else
  246.   if (InputIntData)
  247.     FreeVec(InputIntData);
  248. #endif
  249.  
  250.   if (input)
  251.     DeleteStdIO(input);
  252.   if (inputport)
  253.     DeletePort(inputport);
  254. }
  255. #endif
  256.  
  257. /*
  258. ===========
  259. IN_MouseCommands
  260. ===========
  261. */
  262. void IN_MouseCommands (void)
  263. {
  264.     if (mouse_avail && psxused) {
  265.     if (InputIntData->LeftButtonDown)
  266.         Key_Event (K_MOUSE1, TRUE);
  267.     if (InputIntData->LeftButtonUp)
  268.         Key_Event (K_MOUSE1, FALSE);
  269.     if (InputIntData->MidButtonDown)
  270.         Key_Event (K_MOUSE2, TRUE);
  271.     if (InputIntData->MidButtonUp)
  272.         Key_Event (K_MOUSE2, FALSE);
  273.     if (InputIntData->RightButtonDown)
  274.         Key_Event (K_MOUSE3, TRUE);
  275.     if (InputIntData->RightButtonUp)
  276.         Key_Event (K_MOUSE3, FALSE);
  277.     }
  278. }
  279.  
  280.  
  281. /*
  282. ===========
  283. IN_MouseMove
  284. ===========
  285. */
  286. void IN_MouseMove (usercmd_t *cmd)
  287. {
  288.     int mx, my;
  289.  
  290.     if (!mouse_avail)
  291.         return;
  292.   if (IntuitionBase->FirstScreen != QuakeScreen)
  293.     return;
  294.  
  295.     mx = (float)InputIntData->MouseX;
  296.     my = (float)InputIntData->MouseY;
  297.     InputIntData->MouseX = 0;
  298.     InputIntData->MouseY = 0;
  299.  
  300.     if (m_filter.value) {
  301.         mouse_x = (mx + old_mouse_x) * 0.5;
  302.         mouse_y = (my + old_mouse_y) * 0.5;
  303.     }
  304.     else {
  305.         mouse_x = mx;
  306.         mouse_y = my;
  307.     }
  308.     old_mouse_x = mx;
  309.     old_mouse_y = my;
  310.  
  311.     mouse_x *= sensitivity.value;
  312.     mouse_y *= sensitivity.value;
  313.  
  314.   /* add mouse X/Y movement to cmd */
  315.     if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) ))
  316.         cmd->sidemove += m_side.value * mouse_x;
  317.     else
  318.         cl.viewangles[YAW] -= m_yaw.value * mouse_x;
  319.     
  320.     if (in_mlook.state & 1)
  321.         V_StopPitchDrift ();
  322.         
  323.     if ( (in_mlook.state & 1) && !(in_strafe.state & 1)) {
  324.         cl.viewangles[PITCH] += m_pitch.value * mouse_y;
  325.         if (cl.viewangles[PITCH] > 80)
  326.             cl.viewangles[PITCH] = 80;
  327.         if (cl.viewangles[PITCH] < -70)
  328.             cl.viewangles[PITCH] = -70;
  329.     }
  330.     else {
  331.         if ((in_strafe.state & 1) && noclip_anglehack)
  332.             cmd->upmove -= m_forward.value * mouse_y;
  333.         else
  334.             cmd->forwardmove -= m_forward.value * mouse_y;
  335.     }
  336.   InputIntData->MouseSpeed = (int)m_speed.value;
  337. }
  338.