home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
useful
/
dev
/
c
/
cmanual
/
devices
/
gameportdevice
/
gameportdevice.doc
< prev
next >
Wrap
Text File
|
1993-10-12
|
34KB
|
1,060 lines
3 GAMEPORT DEVICE
3.1 INTRODUCTION
All Amiga models have two contacts to which you can connect extra
input devices like a mouse, joystick, trackball, proportional
joystick etc. If Intuition is used, the left gameport is
reserved for a mouse that controls the pointer. However, the
right port can be used freely.
To monitor these two gameports you can uses the Gameport
Device. It is a clean and polite way of controlling the
gameports. You can of course go directly on the hardware
and check what is happening. This is both easier and faster,
but should only be used in games since it is not so polite
to the system.
If you go directly on the hardware your program will be
machine dependent, and may not run on future models of the
Amiga.
I doubt that Commodore ever will try to change the hardware
position of the gameport, but you never know. Programs that
use the Gameport device will on the other hand always work,
even if an Amiga 4000 is released. So if you can use the
Gameport Device instead of hitting the hardware directly,
stick to the device.
3.2 COMMON INPUT DEVICES FOR THE GAMEPORT
To the gameports you can connect several types of input
devices, like: - Mouse
- Joystick
- Proportional (analogue) joystick
- Light pen
- Drawing (Digitizing) tablet
- Trackball
The most commonly used input devices is undoubtedly the mouse and
joystick. However, inputdevices like analogue joysticks, light
pens and digitizing tablets are getting more and more popular.
It is very common that a joystick is already connected to the
right port. Most games expect that, but it does not mean that
you can not connect a second mouse or proportional joystick
there. It is a good rule to always tell the user what type
of input device he/she should use, before your program starts.
3.2.1 MOUSE
The mouse is the most commonly used device since all Amigas are
sold together with one. It is perfect for positioning cursors
(like Intuition's pointer), or to move a gun-sight over some
enemies.
A mouse usually consists of a rubber ball covered by a box
with one or more buttons on top. When the user is sliding the
mouse, the rubber ball is rotated and delta x and y movements
are reported.
The normal Amiga mouse comes with two buttons, but there exist
those with only one or three buttons.
3.2.2 JOYSTICK
A normal joystick (also called absolute joystick) can only
report 8 stick movements like: up, right, down, left and
possible combinations like up and to the right. A joystick
can have one or two buttons. Sadly most joystick comes with only
one button.
3.2.3 PROPORTIONAL JOYSTICK
A proportional (or analog) joystick is like a normal absolute
joystick with one difference, it will report the exact delta
position on the stick. The further in one direction, the higher
number is broadcasted.
Proportional joysticks are perfect for flight simulators and
similar programs. They are becoming more available nowadays,
so it is a good idea to start supporting this type of device.
The Gameport Device can sadly not handle proportional joysticks
for the moment which is a pity. However, I have included a
small program in the "Input" drawer called "Analogue" which
reads proportional (analogue) joystick movements directly from
the hardware registers.
3.2.4 LIGHT PEN
A light pen is a small device with which you can point anywhere
on the screen in order to position a cursor or select an
option. There have during the last years been a big discussion
about which device, a mouse or a light pen, is easiest to use.
I think it depends on what you are going to do. A pen is
undoubtedly more natural for a beginner, but your arm gets very
tired after some minutes, so it should not be used to much.
Luckily you do not need to bother about the light pen since it
is also sadly not supported by the Gameport Device. However,
newly made light pens usually comes with some software that
replaces Intuition's mouse with the light pen. If you write
your program as normal and is monitoring a mouse, the user can
still connected and use a light pen. Your program whould not
notice any difference.
3.2.5 DRAWING (DIGITIZING) TABLET
Drawing (Digitizing) tablet is used in the same manner as a
light pen, but with the advantage that your arm does not get
so tired, and with the disadvantage that all your free space
on your desk is suddenly occupied by a large sensitive tablet.
(It is not recommended to spill hot coffee on it for example.)
Drawing tablets are not either supported by the Gameport
Device. However, as same as with the light pen, most digitizing
tablets comes with some software that replaces the normal
mouse driver with its own driver. So if your program supports
a mouse, it can also handle most digitizing tablets.
3.2.5 TRACKBALL
A trackball is working exactly as a mouse, but with the
advantage that you do not have to move it around. Since it
acts exactly as a mouse you do not have to bother about any
special routines for handling trackballs. Simply support
mouse events and the user can connect a trackball instead.
3.3 THE GAMEPORT DEVICE
The Gameport Device helps you to monitor the Amiga's two
gameports. Port 1 (unit 0) is usually already occupied by
Intuition, but port 2 (unit 1) can normally be used. The
Gameport Device supports for the moment only two types
of input devices, and they are: 1. Mouse (Trackball)
2. Joystick
To prepare the Gameport Device to handle input events you
have to:
1. Create a message port with which the Gameport Device
can communicate with you.
[ CreatePort() ]
2. Allocate an input/output request block (structure).
[ CreateStdIO() ]
3. Open the Gameport Device
[ OpenDevice() ]
4. Check if some other task is already using the gameport.
(A gameport can only be monitored by one task.)
5. Tell the Gameport Device what type of input device you
want to monitor. (For the moment you can only monitor
mouse or joystick events.)
6. Tell the Gameport Device what events should be reported,
and when.
7. Tell the Gameport Device that we want to start collecting
gameport events.
3.3.1 CREATE A MESSAGE PORT
As normal when you are using a device, you first have to create
a message port with which the device can communicate with you.
The simplest way is to create a message port by calling the
CreatePort() function, which will return a pointer to a MsgPort
structure (defined in the headerfile "exec/ports.h").
CreatePort() allocates and initializes a MsgPort structure. If
you give it a string as first parameter it will also make the
port public. If CreatePort() of some reason could not create a
message port it returns NULL, otherwise if everything is OK it
returns a pointer to the new MsgPort structure.
Synopsis: msgp = CreatePort( name, pri );
msgp: (struct MsgPort *) Pointer to the new MsgPort
structure, or NULL if something went wrong.
name: (char *) Pointer to a string containing the name
of the message port, or NULL. If it is a string
the port will be made public (so other tasks can
find it) else only our task can use it.
msgp: (struct MsgPort *) Pointer to the MsgPort structure
that should be allocated.
pri: (BYTE) This message port's priority. Usually set
to 0 - normal priority.
When your program terminates you must close the message port
by calling the DeletePort() function!
DeletePort() deletes a message port. Every message port that
has been allocated by CreatePort() must be deleted before the
program terminates.
Synopsis: DeletePort( msgp );
msgp: (struct MsgPort *) Pointer to the MsgPort structure,
that should be deallocated.
Here is an example:
/* Declare a pointer to our message port: */
struct MsgPort *game_msg_port;
/* Create the message port: */
/* (No name, priority 0.) */
game_msg_port = CreatePort( 0, 0 );
/* Check if we have received a message port or not: */
if( !game_msg_port )
/* ERROR! Could not create m