home *** CD-ROM | disk | FTP | other *** search
- /*******************************************************************************
- *
- * (c) Copyright 1993 Commodore-Amiga, Inc. All rights reserved.
- *
- * This software is provided as-is and is subject to change; no warranties
- * are made. All use is at your own risk. No liability or responsibility
- * is assumed.
- *
- * input.c - handles joystick input and IDCMP RAWKEY input. Creates input events
- * for the input.device based on the joystick.
- *
- ******************************************************************************/
-
- #include <exec/ports.h>
- #include <devices/input.h>
- #include <devices/inputevent.h>
- #include <intuition/screens.h>
- #include <proto/exec.h>
- #include <stdio.h>
-
- #include "stick.h"
- #include "sprites.h"
-
- ULONG __asm ReadJoystick(register __a0 struct JoyStick *stick);
- void FireMissile(struct Input *input);
-
-
- void DoJoystick(struct Input *input)
- {
- static ULONG laststate;
- static WORD accelx = 1, accely = 1;
- ULONG stickstate = ReadJoystick(input->Stick);
-
- if (stickstate & FIRE)
- {
- FireMissile(input);
- }
-
- if (stickstate & (LEFT | RIGHT | UP | DOWN))
- {
- input->FakeEvent->ie_NextEvent = NULL;
- input->FakeEvent->ie_Class = IECLASS_NEWPOINTERPOS;
- input->FakeEvent->ie_SubClass = IESUBCLASS_PIXEL;
- input->FakeEvent->ie_Code = IECODE_NOBUTTON;
- input->FakeEvent->ie_Qualifier = NULL;
- input->FakeEvent->ie_EventAddress = (APTR)input->NewPixel;
-
- input->InputIO->io_Data = (APTR)input->FakeEvent;
- input->InputIO->io_Length = sizeof(struct InputEvent);
- input->InputIO->io_Command = IND_WRITEEVENT;
-
- input->NewPixel->iepp_Position.X = input->Screen->MouseX;
- input->NewPixel->iepp_Position.Y = input->Screen->MouseY;
- input->NewPixel->iepp_Screen = input->Screen;
-
- if ((stickstate & laststate) & (LEFT | RIGHT))
- {
- accelx++;
- accelx = min(10, accelx);
- }
- else
- {
- accelx = 0;
- }
-
- if ((stickstate & laststate) & (UP | DOWN))
- {
- accely++;
- accely = min(10, accely);
- }
- else
- {
- accely = 0;
- }
-
- if (stickstate & LEFT)
- {
- input->NewPixel->iepp_Position.X += -accelx;
- }
- if (stickstate & RIGHT)
- {
- input->NewPixel->iepp_Position.X += accelx;
- }
- if (stickstate & UP)
- {
- input->NewPixel->iepp_Position.Y += -accely;
- }
- if (stickstate & DOWN)
- {
- input->NewPixel->iepp_Position.Y += accely;
- }
-
- /* limit the movements */
- if (input->NewPixel->iepp_Position.Y > (input->Screen->Height - XHAIRHEIGHT))
- {
- input->NewPixel->iepp_Position.Y = (input->Screen->Height - XHAIRHEIGHT);
- }
-
- DoIO((struct IORequest *)input->InputIO);
- }
- laststate = stickstate;
- }
-
- void HandleInput(struct Input *input)
- {
- struct Message *msg;
-
- /* If the a key was pressed, bug out. */
- if (msg = GetMsg(input->Screen->FirstWindow->UserPort))
- {
- ReplyMsg(msg);
- /* The only possible message was a keypress */
- *(input->BugOut) = NULL;
- }
- else
- {
- DoJoystick(input);
- }
- }
-
-