home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 113 / EnigmaAmiga113CD.iso / software / sviluppo / quake_src / in_amigamouse.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-17  |  7.4 KB  |  333 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.  
  91.   if ( COM_CheckParm ("-nomouse") )
  92.     return;
  93.  
  94.   /* open input.device */
  95.   if (inputport = CreateMsgPort()) {
  96.     if (input = (struct IOStdReq *)CreateIORequest(inputport,sizeof(struct IOStdReq))) {
  97. #ifdef __PPC__
  98. #ifdef WOS
  99.       if (InputIntData = AllocVecPPC(sizeof(struct InputIntDat),
  100.           MEMF_CHIP|MEMF_PUBLIC|MEMF_CLEAR,0)) {
  101. #else
  102.       if (InputIntData = PPCAllocVec(sizeof(struct InputIntDat),
  103.           MEMF_CHIP|MEMF_PUBLIC|MEMF_CLEAR)) {
  104. #endif
  105. #else
  106.       if (InputIntData = AllocVec(sizeof(struct InputIntDat),
  107.           MEMF_CHIP|MEMF_PUBLIC|MEMF_CLEAR)) {
  108. #endif
  109.         InputIntData->MouseSpeed = (int)m_speed.value;
  110.         if (!(input_dev = OpenDevice("input.device",0,
  111.             (struct IORequest *)input,0))) {
  112.           InputHandler.is_Node.ln_Type = NT_INTERRUPT;
  113.           InputHandler.is_Node.ln_Pri = 100;
  114.           InputHandler.is_Data = InputIntData;
  115.           InputHandler.is_Code = (void(*)())InputIntCode;
  116.           input->io_Data = (void *)&InputHandler;
  117.           input->io_Command = IND_ADDHANDLER;
  118.           DoIO((struct IORequest *)input);
  119.           mouse_avail = true;
  120.         }
  121.       }
  122.     }
  123.   }
  124.   if (!mouse_avail) {
  125.     Con_Printf("Couldn't open input.device\n");
  126.     return;
  127.   }
  128.   Con_Printf("Amiga mouse available\n");
  129. }
  130.  
  131.  
  132. /*
  133. ===========
  134. IN_ShutdownMouse
  135. ===========
  136. */
  137. void IN_ShutdownMouse (void)
  138. {
  139.   if (mouse_avail) {
  140.     input->io_Data=(void *)&InputHandler;
  141.     input->io_Command=IND_REMHANDLER;
  142.     DoIO((struct IORequest *)input);
  143.   }
  144.   if (!input_dev)
  145.     CloseDevice((struct IORequest *)input);
  146.  
  147. #ifdef __PPC__
  148. #ifdef WOS
  149.   if (InputIntData)
  150.     FreeVecPPC(InputIntData);
  151. #else
  152.   if (InputIntData)
  153.     PPCFreeVec(InputIntData);
  154. #endif
  155. #else
  156.   if (InputIntData)
  157.     FreeVec(InputIntData);
  158. #endif
  159.  
  160.   if (input)
  161.     DeleteIORequest((struct IORequest *)input);
  162.   if (inputport)
  163.     DeleteMsgPort(inputport);
  164. }
  165. #else
  166.  
  167. /*
  168. ===========
  169. IN_InitMouse
  170. ===========
  171. */
  172.  
  173.  
  174. void IN_InitMouse (void)
  175. {
  176.   if ( COM_CheckParm ("-nomouse") )
  177.     return;
  178.  
  179.   /* open input.device */
  180.   if (inputport = CreatePort(NULL,0)) {
  181.     if (input = CreateStdIO(inputport)) {
  182. #ifdef __PPC__
  183. #ifdef WOS
  184.       if (InputIntData = AllocVecPPC(sizeof(struct InputIntDat),
  185.           MEMF_CHIP|MEMF_PUBLIC|MEMF_CLEAR,0)) {
  186. #else
  187.       if (InputIntData = PPCAllocVec(sizeof(struct InputIntDat),
  188.           MEMF_CHIP|MEMF_PUBLIC|MEMF_CLEAR)) {
  189. #endif
  190. #else
  191.       if (InputIntData = AllocVec(sizeof(struct InputIntDat),
  192.           MEMF_CHIP|MEMF_PUBLIC|MEMF_CLEAR)) {
  193. #endif
  194.         InputIntData->MouseSpeed = (int)m_speed.value;
  195.         if (!(input_dev = OpenDevice("input.device",0,
  196.             (struct IORequest *)input,0))) {
  197.           InputHandler.is_Node.ln_Type = NT_INTERRUPT;
  198.           InputHandler.is_Node.ln_Pri = 100;
  199.           InputHandler.is_Data = InputIntData;
  200.           InputHandler.is_Code = (void(*)())InputIntCode;
  201.           input->io_Data = (void *)&InputHandler;
  202.           input->io_Command = IND_ADDHANDLER;
  203.           DoIO((struct IORequest *)input);
  204.           mouse_avail = true;
  205.         }
  206.       }
  207.     }
  208.   }
  209.   if (!mouse_avail) {
  210.     Con_Printf("Couldn't open input.device\n");
  211.     return;
  212.   }
  213.   Con_Printf("Amiga mouse available\n");
  214. }
  215.  
  216.  
  217. /*
  218. ===========
  219. IN_ShutdownMouse
  220. ===========
  221. */
  222. void IN_ShutdownMouse (void)
  223. {
  224.   if (mouse_avail) {
  225.     input->io_Data=(void *)&InputHandler;
  226.     input->io_Command=IND_REMHANDLER;
  227.     DoIO((struct IORequest *)input);
  228.   }
  229.   if (!input_dev)
  230.     CloseDevice((struct IORequest *)input);
  231.  
  232. #ifdef __PPC__
  233. #ifdef WOS
  234.   if (InputIntData)
  235.     FreeVecPPC(InputIntData);
  236. #else
  237.   if (InputIntData)
  238.     PPCFreeVec(InputIntData);
  239. #endif
  240. #else
  241.   if (InputIntData)
  242.     FreeVec(InputIntData);
  243. #endif
  244.  
  245.   if (input)
  246.     DeleteStdIO(input);
  247.   if (inputport)
  248.     DeletePort(inputport);
  249. }
  250. #endif
  251.  
  252. /*
  253. ===========
  254. IN_MouseCommands
  255. ===========
  256. */
  257. void IN_MouseCommands (void)
  258. {
  259.     if (mouse_avail && psxused) {
  260.     if (InputIntData->LeftButtonDown)
  261.         Key_Event (K_MOUSE1, TRUE);
  262.     if (InputIntData->LeftButtonUp)
  263.         Key_Event (K_MOUSE1, FALSE);
  264.     if (InputIntData->MidButtonDown)
  265.         Key_Event (K_MOUSE2, TRUE);
  266.     if (InputIntData->MidButtonUp)
  267.         Key_Event (K_MOUSE2, FALSE);
  268.     if (InputIntData->RightButtonDown)
  269.         Key_Event (K_MOUSE3, TRUE);
  270.     if (InputIntData->RightButtonUp)
  271.         Key_Event (K_MOUSE3, FALSE);
  272.     }
  273. }
  274.  
  275.  
  276. /*
  277. ===========
  278. IN_MouseMove
  279. ===========
  280. */
  281. void IN_MouseMove (usercmd_t *cmd)
  282. {
  283.     int mx, my;
  284.  
  285.     if (!mouse_avail)
  286.         return;
  287.   if (IntuitionBase->FirstScreen != QuakeScreen)
  288.     return;
  289.  
  290.     mx = (float)InputIntData->MouseX;
  291.     my = (float)InputIntData->MouseY;
  292.     InputIntData->MouseX = 0;
  293.     InputIntData->MouseY = 0;
  294.  
  295.     if (m_filter.value) {
  296.         mouse_x = (mx + old_mouse_x) * 0.5;
  297.         mouse_y = (my + old_mouse_y) * 0.5;
  298.     }
  299.     else {
  300.         mouse_x = mx;
  301.         mouse_y = my;
  302.     }
  303.     old_mouse_x = mx;
  304.     old_mouse_y = my;
  305.  
  306.     mouse_x *= sensitivity.value;
  307.     mouse_y *= sensitivity.value;
  308.  
  309.   /* add mouse X/Y movement to cmd */
  310.     if ( (in_strafe.state & 1) || (lookstrafe.value && (in_mlook.state & 1) ))
  311.         cmd->sidemove += m_side.value * mouse_x;
  312.     else
  313.         cl.viewangles[YAW] -= m_yaw.value * mouse_x;
  314.     
  315.     if (in_mlook.state & 1)
  316.         V_StopPitchDrift ();
  317.         
  318.     if ( (in_mlook.state & 1) && !(in_strafe.state & 1)) {
  319.         cl.viewangles[PITCH] += m_pitch.value * mouse_y;
  320.         if (cl.viewangles[PITCH] > 80)
  321.             cl.viewangles[PITCH] = 80;
  322.         if (cl.viewangles[PITCH] < -70)
  323.             cl.viewangles[PITCH] = -70;
  324.     }
  325.     else {
  326.         if ((in_strafe.state & 1) && noclip_anglehack)
  327.             cmd->upmove -= m_forward.value * mouse_y;
  328.         else
  329.             cmd->forwardmove -= m_forward.value * mouse_y;
  330.     }
  331.   InputIntData->MouseSpeed = (int)m_speed.value;
  332. }
  333.