[comp.sys.amiga] Joysticks in BOTH ports?

FATXC@USU.BITNET (01/22/88)

        Does anyone have a good example of how to use BOTH ports as
  joystick ports?  (Normal Amiga joysticks, not porportional).  I would
  like to be able to use Intuition as well, if that is possible.  I am
  using an Amiga 1000, if it makes any difference.
        Any information, reference to an existing PD example or other
  would be greatly appreciated.

                Thanks in advance,

                          J. Norman Gee
 ________________________________________________________________________
|                                     |               //                 |
|  No one pays attention to what I    |         \\   //   Bring back     |
|  say, so why bother disclaiming     |          \\ //    the checkmark! |
|  anything?                          |           \\/                    |
|_____________________________________|__________________________________|
OS/2 ??  Who wants half of an operating system?

carolyn@cbmvax.UUCP (Carolyn Scheppner CATS) (01/26/88)

In article <8801212049.AA04709@jade.berkeley.edu> FATXC@USU.BITNET writes:
>
>        Does anyone have a good example of how to use BOTH ports as
>  joystick ports?  (Normal Amiga joysticks, not porportional).  I would
>  like to be able to use Intuition as well, if that is possible.  I am
>  using an Amiga 1000, if it makes any difference.

Here's a repost of Kodiak's solution with a code fragment.  I think his
fragment is set up for doing one port or the other, but it'll give you
something to start with.

Warning though - if you plan on being a multi-tasking capable game, if
you take over both ports for joysticks, all the other tasks that need
mouse input will be left out in the cold.  So, if your game is also a
single-player game, I suggest you use the non-mouse port only in
single player mode, and only take over both ports in dual-player mode.


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


-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Carolyn Scheppner -- CATS   >>Commodore Amiga Technical Support<<
                     UUCP  ...{allegra,ihnp4,rutgers}!cbmvax!carolyn 
                     PHONE 215-431-9180
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

peter@nuchat.UUCP (Peter da Silva) (02/04/88)

In article <8801212049.AA04709@jade.berkeley.edu>, FATXC@USU.BITNET writes:
>         Does anyone have a good example of how to use BOTH ports as
>   joystick ports?  (Normal Amiga joysticks, not porportional).  I would
>   like to be able to use Intuition as well, if that is possible.  I am
>   using an Amiga 1000, if it makes any difference.
>         Any information, reference to an existing PD example or other
>   would be greatly appreciated.

I posted this recently, but basically you:

	Open game port 0
	Read trigger conditions and save them.
	Close game port 0.

	Open the input device.
	Send the SETMPORT message to set it to (say) port 2.
	Close the input device.

Do whatever you want with the joystick ports.

	Open the input device.
	Send SETMPORT to set it back to port 0.
	Send SETMTYPE to set it back to GPCT_MOUSE.
	Send SETMTRIG to the saved trigger conditions.
	Close the input device.

You really have to open and close the ports, and in that order. Otherwise it
doesn't work. No, I don't know why.
-- 
-- a clone of Peter (have you hugged your wolf today) da Silva  `-_-'
-- normally  ...!hoptoad!academ!uhnix1!sugar!peter                U
-- Disclaimer: These aren't mere opinions... these are *values*.