Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!mit-eddie!ll-xn!ames!oliveb!amiga!kodiak From: kodiak@amiga.UUCP (Robert R. Burns) Newsgroups: comp.sys.amiga Subject: Re: Grabbing the mouse port. Message-ID: <1967@amiga.amiga.UUCP> Date: Mon, 23-Nov-87 17:43:38 EST Article-I.D.: amiga.1967 Posted: Mon Nov 23 17:43:38 1987 Date-Received: Thu, 26-Nov-87 21:54:21 EST References: <1041@sugar.UUCP> <802@sdcc18.ucsd.EDU> <4436@well.UUCP> <1213@vaxb.calgary.UUCP> Reply-To: kodiak@amiga.UUCP (Robert R. Burns) Organization: Kodiak Software, but wearing Commodore-Amiga Inc. hat Lines: 124 The Tail of Two Ports --------------------- First, let me sing you a song: The Port 0's cconnected to the gameport device The gameport device's connected to the input device The input device's connected to the input task The input task's connected to Intuition Now hear the words of the coder Seriously. I've been following the discussion about how to grab the mouse from intuition and seen one proposed solution. That proposal was to go to the gameport hardware directly. That's not a bad solution, but it does leave the above skeleton intact, so Intuition will continue to be polled by the input task with reports of "mouse" movement that is really based on the joystick switches: swizzle the joystick to simulate quadrature. Someone mentioned going directly to one of the devices. Yup: neither the gameport nor the input device force exclusive access. The two ports of the gameport device were intended to be used by only one consumer apiece: check if there's anyone else who thinks they own it by issuing an AskCType command and testing for GPCT_NOCONTROLLER, and be sure to SetCType it back to GPCT_NOCONTROLLER after you're done. The input device also allows anyone to issue commands that affect other folks. The salient one here is SetMPort. NOTE: I remember there being a bug somewhere near here in release 1.1, it may have been the SetMPort command. SetMPort allows anyone to reassign the input device mouse (and thus intuition mouse) to any port. Fortunately for you, any port you set it to other than zero or one will fail to open, and the input task will then not reissue gameport device requests until SetMPort is used to set a valid port. So SetMPort to -1, and you can use the gameport device units 0 and 1, SetCType'd to GPCT_RELJOYSTICK and appropriately SetTrigger'ed so it will satisfy your ReadEvents when you want it to, or you can go to the hardware like most games do. NOTE: If you want to observe the GPCT_NOCONTROLLER protocol, set it with SetMType to the input device before closing the device with a SetMPort of -1. See, not even the input device followed that protocol: I suspect 1) noone else does either, and 2) few folks besides the input device use the gameport device anyway. Remember if you have more than one button and go directly to the hardware you should allocate the other buttons from the potgo resource. - Bob "Kodiak" Burns P.S. ---------------------------------------------------------------------- /**/ /* mouseport.c, by Bob "Kodiak" Burns /**/ #include #include #include #include struct MsgPort iorp = { {0, 0, NT_MSGPORT, 0, 0}, 0, -1, /* initialize signal to -1 */ 0, /* start with empty list */ {&iorp.mp_MsgList.lh_Tail, 0, &iorp.mp_MsgList.lh_Head, 0, 0} }; struct IOStdReq inputReq = { {{0, 0, NT_MESSAGE, 0, 0}, &iorp, 0} 0, 0, 0, 0, 0, 0, 0, 0, 0 }; char mousePort; endGame(code) int code; { if (code != 0) printf("Fail %ld\n", code); if (inputReq.io_Device != 0) CloseDevice(&inputReq); if (iorp.mp_SigBit != -1) FreeSignal(iorp.mp_SigBit); exit(code); } main(argc, argv) int argc; char *argv[]; { char c; if (argc != 2) { printf("usage: %s \n", argv[0]); exit(1); } /* crude: look for 0 or 1 */ mousePort = -1; if (argv[1][1] == 0) { if (argv[1][0] == '0') mousePort = 0; else if (argv[1][0] == '1') mousePort = 1; } if ((iorp.mp_SigBit = AllocSignal(-1)) < 0) endGame(21); iorp.mp_SigTask = (struct Task *) FindTask((char *) NULL); if (OpenDevice("input.device", 0, &inputReq, 0)) endGame(22); /* set the controller available or to mouse */ if (mousePort == -1) c = GPCT_NOCONTROLLER; else c = GPCT_MOUSE; inputReq.io_Command = IND_SETMTYPE; inputReq.io_Length = 1; inputReq.io_Data = &c; DoIO(&inputReq); /* shut down or restart the input device mouse reports */ inputReq.io_Command = IND_SETMPORT; inputReq.io_Length = 1; inputReq.io_Data = &mousePort; DoIO(&inputReq); endGame(0); }