[comp.sys.amiga] Grabbing the mouse port.

peter@sugar.UUCP (Peter da Silva) (11/09/87)

I've asked this question before, but...

How do you grab the mouse port away from intuition?

Can it be done without blowing away intuition?

If not, can it be done in such a way you still get OpenWindow, etc?

As an alternative, is it possible to use the mouse port as a joystick
port without grabbing it away from Intuition (yeh, I know the mouse will
bobble around. No biggee.)?
-- 
-- Peter da Silva  `-_-'  ...!hoptoad!academ!uhnix1!sugar!peter
-- Disclaimer: These U aren't mere opinions... these are *values*.

cmcmanis%pepper@Sun.COM (Chuck McManis) (11/10/87)

In article <1041@sugar.UUCP> peter@sugar.UUCP (Peter da Silva) writes:
>How do you grab the mouse port away from intuition?

You install an input handler at a higher priority than Intuition in 
the input food chain. The handler gives all mouse events to you.

>Can it be done without blowing away intuition?

Yes

>If not, can it be done in such a way you still get OpenWindow, etc?

See above.

>As an alternative, is it possible to use the mouse port as a joystick
>port without grabbing it away from Intuition (yeh, I know the mouse will
>bobble around. No biggee.)?

Not really, Intuition keeps resetting it back to mouse mode.



--Chuck McManis
uucp: {anywhere}!sun!cmcmanis   BIX: cmcmanis  ARPAnet: cmcmanis@sun.com
These opinions are my own and no one elses, but you knew that dT mnistre 

jimm@mitsumi.UUCP (Jim Mackraz) (11/10/87)

In article <1041@sugar.UUCP> peter@sugar.UUCP (Peter da Silva) writes:
)I've asked this question before, but...
)How do you grab the mouse port away from intuition?
)Can it be done without blowing away intuition?
)If not, can it be done in such a way you still get OpenWindow, etc?

Get an input handler installed before Intuition.  I don't know whether
joystick movements will translate into reasonable InputEvents, but
at least you get Intuition out of the loop and can read the port
directly.

)As an alternative, is it possible to use the mouse port as a joystick
)port without grabbing it away from Intuition
)-- Peter da Silva  `-_-'  ...!hoptoad!academ!uhnix1!sugar!peter

Dunno.

	jimm

-- 
	Jim Mackraz
	Mitsumi Technology, Inc.		408/980-5422
	{amiga,pyramid}!mitsumi!jimm

cs162ffl@sdcc18.ucsd.EDU (John Schultz) (11/12/87)

  I've written a very fast a simple routine that reads 
$DFF00A (port 0), $DFF00C (port 1), $BFE001 (read bit 6 for port 0
and bit 7 for port 1) for the button presses.
  All you have to do is read the appropriate bits (and xor a few).
Just read the Hardware manual Appendix_A Page 13.
  Takes only a couple of lines of C code to implement, more for
Modula-2.
  I used the RKM example and it was quite a bit slower, incurred
more overhead, and took over three pages of C code.  It also would
not work with port 0 while intuition was hooked up.

  I have used this routine in all of my games, which all run
perfectly on the 500, 1000, and 2000.
  I realize that future machines may have a different absolute
memory locations, but since it works with all three of the current
models, I am content with the inherent drawbacks of accessing a
peripheral device directly.
  Of course, if one is just hacking around, then there is no
problem.

  John

ewhac@well.UUCP (Leo 'Bols Ewhac' Schwab) (11/13/87)

In article <802@sdcc18.ucsd.EDU> cs162ffl@sdcc18.ucsd.edu.UUCP (John Schultz) writes:
>
>  I've written a very fast a simple routine that reads 
>$DFF00A (port 0), $DFF00C (port 1), $BFE001 (read bit 6 for port 0
>and bit 7 for port 1) for the button presses.
>  All you have to do is read the appropriate bits (and xor a few).
>Just read the Hardware manual Appendix_A Page 13.  [ ... ]
>  Of course, if one is just hacking around, then there is no
>problem.
>
[ If you'll permit me to start my sentence with a Joanne Dow-ism: ]

	Er...  I hack around, and I have a problem.  There are official ways
to get to things, and they should be observed in all circumstances.  You are
not officially entitled to look at anything you haven't asked permission
for.

	Consider the future:  The hardware *may* remain identical; we have
no way of knowing.  If it changes, you're screwed (as all are the people who
use your software).  But you've already made that point.

	Now let's try the same point on a slightly different tack:  Suppose
the hardware layout is identical, with one minor exception; an MMU.  The MMU
will stop you dead in your tracks if you try accessing the hardware
directly.

	However, the OS may condescend to allow you access to the hardware
if you ask it nicely.  This facility is already installed in the Amiga OS
(OpenResource()).  It really ought to be used if you're going to look at
sensitive hardware addresses.

	Issue:  I *STILL* don't know the official way to close a resource
(there's no CloseResource() call).  Someone suggested CloseLibrary(), but
that took the machine out real fast.

	Stupid Idea:  Way back when, when the Amiga first came out, I didn't
like the name "AmigaDOS" at all.  It wasn't imaginative enough.  So I
started calling it AMTOS for a while (Amiga Multi-Tasking Operating System).
What say ye?

_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
Leo L. Schwab -- The Guy in The Cape	ihnp4!ptsfa -\
 \_ -_		Recumbent Bikes:	      dual ---> !{well,unicom}!ewhac
O----^o	      The Only Way To Fly.	      hplabs / (pronounced "AE-wack")
"Work FOR?  I don't work FOR anybody!  I'm just having fun."  -- The Doctor

cs162ffl@sdcc18.ucsd.EDU (John Schultz) (11/13/87)

In article <4436@well.UUCP> ewhac@well.UUCP (Leo 'Bols Ewhac' Schwab) writes:
>[ If you'll permit me to start my sentence with a Joanne Dow-ism: ]
>	Er...  I hack around, and I have a problem. [...] 
>Leo L. Schwab -- The Guy in The Cape	ihnp4!ptsfa -\

  Ok, so how do we access port zero without futzing up intuition (as
a joystick, and without queueing up inputs and incurring large
overhead)?

  The input device? Ok howz about an example? (oh yeah, it has to
work in that it passes the events freely)

  John

dillon@CORY.BERKELEY.EDU (Matt Dillon) (11/14/87)

>	Issue:  I *STILL* don't know the official way to close a resource
>(there's no CloseResource() call).  Someone suggested CloseLibrary(), but
>that took the machine out real fast.

	Yah, that caught me to.  Somebody a while back from C-A gave us the
answer:  There is no CloseResource() because OpenResource() does not 
allocate anything... simply returns a pointer to a system structure for use
in making resource-dependant calls, etc..

>	Stupid Idea:  Way back when, when the Amiga first came out, I didn't
>like the name "AmigaDOS" at all.  It wasn't imaginative enough.  So I
>started calling it AMTOS for a while (Amiga Multi-Tasking Operating System).
>What say ye?

	Sound to much like Atari's TOS.

					-Matt

peter@sugar.UUCP (Peter da Silva) (11/14/87)

In article <33485@sun.uucp>, cmcmanis%pepper@Sun.COM (Chuck McManis) writes:
> In article <1041@sugar.UUCP> peter@sugar.UUCP (Peter da Silva) writes:
> >How do you grab the mouse port away from intuition?
> You install an input handler at a higher priority than Intuition in 
> the input food chain. The handler gives all mouse events to you.

But what I want is joystick events. I'm working on a game that needs two
joystick inputs. Hey, for the next Amiga 500 (Amiga 250?), how about
sticking some more joystick ports in?

> >As an alternative, is it possible to use the mouse port as a joystick
> >port...
> Not really, Intuition keeps resetting it back to mouse mode.

See above.
-- 
-- Peter da Silva  `-_-'  ...!hoptoad!academ!uhnix1!sugar!peter
-- Disclaimer: These U aren't mere opinions... these are *values*.

schaub@sugar.UUCP (Markus Schaub) (11/15/87)

As I replied directly to peter, I used a joystick as input device instead of
the mouse just by opening the gameport.device for unit 0 and setting the type
to joystick. It worked. I moved windows, resized them etc. BUT I really don't
know if this should be possible or if it is a little bug in the gameport.dev
letting two task accessing the same port.
-- 
     //	Markus Schaub		uunet!nuchat!sugar!schaub      (713) 523 8422
    //	M2Amiga Developer	trying to get back the money I  paid  for  my
\\ //				Amiga by selling a few M2Amiga.
 \X/	c/o Interface Technologies Corp, 3336 Richmond #323, Houston Tx 7odula

maloff@calgary.UUCP (Sheldon Maloff) (11/18/87)

In article <4436@well.UUCP>, ewhac@well.UUCP (Leo 'Bols Ewhac' Schwab) writes:
> 
> 	Stupid Idea:  Way back when, when the Amiga first came out, I didn't
> like the name "AmigaDOS" at all.  It wasn't imaginative enough.  So I
> started calling it AMTOS for a while (Amiga Multi-Tasking Operating System).
> What say ye?       ^^^^^
                     ^^^^^---AMTOS

What say ye not.  Too easily mistaken for:  (drum roll)

		AMiga Trameil Operating System!!!!
		**    *       *         *

Could have the Atari folks think we stole one of the greatest operating
systems of all time, could we now :-) :-)


|| Sheldon                               ----========== \\          -----====||
|| maloff@calgary.UUCP                      -----====== //  Calgary, Alberta ||
|| {ihnp4!alberta}!calgary!maloff               -----== \\  Winter '88 Games ||
||.. nothings changed ... its all just a state of mind. //             ----==||

peter@sugar.UUCP (Peter da Silva) (11/19/87)

What is this? I start asking how to get at the mouse port in an intuition
blessed way, and now everyone wants to do it :->.

Commodore: any input?

Leo: Marketroids would get my vote as the best demo. Funniest anyway.
-- 
-- Peter da Silva  `-_-'  ...!hoptoad!academ!uhnix1!sugar!peter
-- Disclaimer: These U aren't mere opinions... these are *values*.

kodiak@amiga.UUCP (Robert R. Burns) (11/24/87)

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 <exec/types.h>
#include <exec/ports.h>
#include <devices/gameport.h>
#include <devices/input.h>

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 <port>\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);
}