Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!seismo!mimsy!cvl!umd5!umbc3!chiafari From: chiafari@umbc3.UUCP Newsgroups: comp.sys.amiga Subject: gameport.device Message-ID: <292@umbc3.UMD.EDU> Date: Wed, 18-Feb-87 06:15:34 EST Article-I.D.: umbc3.292 Posted: Wed Feb 18 06:15:34 1987 Date-Received: Thu, 19-Feb-87 19:11:49 EST Organization: Univ of Maryland Baltimore County Lines: 157 Keywords: gameport joystick cleanup arrrrgggg ARRRRRRRGGGGGGGGG!!!!!!! Has anyone gotten the gameport.device to work? I've gotten entirely too frustrated with this. My problem goes something like this: I run a program using a joystick. The program works fine. If I run it again, it STILL works fine. If I run some OTHER program, then run the joystick program, none of the system calls complain, but GetMsg() always returns 0. Occationally after this happens, the system crashes. Typical crash: mouse pointer becomes vertical column, power light starts to blink. Other interesting notes: I first typed the joystick code in (doing a translation to my style) from the RKM joystick example under gameport.device. When this ran fine, I incorperated it in another program, calling the joystick init code at the beginning of main() in the new code. Consequently, CHIP memory is apparently being allocated in exactly the same way by the two programs, and I can alternate running them successfully, as long as I don't run anything else that uses CHIP ram. When either of them doesn't work, the other one won't either. I suspect that there is something wrong with the way I'm cleaning up. System configuration: Amiga 1000 w/512K CHIP RAM. ASDG MiniRack-C w/2M FAST RAM (using 2M rrd: programs usually load 1 External Drive. into FAST RAM). Mouse in left mouse port. Joystick in right mouse port. KickStart 1.2 V33.180 WorkBench 1.2 V33.47 Shell V2.05M Lattice 3.03 Blink V6.5 (1986/09/29) I think that's about all I can say... Code follows... Any suggestions would be appreciated... MAIL them (for GOD'S SAKE!) and if there's interest, I'll post my eventual solution. They nuked my account when I graduated, so send mail to: chiafari@umbc3.umd.edu soon to be !...!some!unknown!path!...!wedge!eric, but for right now I'm NOT on USENET, so find an arpa gateway.... -eric messick -----------------------joy.c---begins---here------------------------------- #include #include #include #include #include #include #define setmsg(msg, com, len, dat) { \ (msg)->io_Command = (com) ; \ (msg)->io_Length = (len) ; \ (msg)->io_Data = (APTR)(dat) ; } struct InputEvent *joyie; struct IOStdReq *joyio; struct MsgPort *joymp; struct GamePortTrigger gpt; int gamedevice = 0 ; extern int joybutton, joyx, joyy, debug; extern struct MsgPort *CreatePort(); extern struct IOStdReq *CreateStdIO(); initjoy() { printf("insert joystick in right mouse port.\n"); joyie = (struct InputEvent *)AllocMem(sizeof(struct InputEvent), MEMF_PUBLIC); if (!joyie) cleanup ("no inputevent"); joymp = CreatePort("gameport", 0); if (!joymp) cleanup ("no gameport"); joyio = CreateStdIO(joymp); if (!joyio) cleanup ("no stdioreq"); if (OpenDevice("gameport.device", 1, joyio, 0)) cleanup ("no gameport device"); gamedevice = 1 ; setmsg(joyio, GPD_SETCTYPE, 1, joyie); *(BYTE *)joyie = GPCT_ABSJOYSTICK ; SendIO(joyio); WaitPort(joymp); GetMsg(joymp); if (joyio->io_Error) cleanup ("can't GPD_SETCTYPE"); setmsg(joyio, GPD_SETTRIGGER, sizeof(gpt), &gpt); gpt.gpt_Keys = GPTF_UPKEYS | GPTF_DOWNKEYS ; gpt.gpt_Timeout = 0 ; gpt.gpt_XDelta = 1 ; gpt.gpt_YDelta = 1 ; if (DoIO(joyio)) cleanup("can't GPD_SETTRIGGER"); setmsg(joyio, GPD_READEVENT, sizeof(struct InputEvent), joyie); joyio->io_Flags = 0 ; SendIO(joyio); } checkjoy() { if (GetMsg(joymp)) { joybutton = joyie->ie_Qualifier & IEQUALIFIER_MBUTTON ; joyx = joyie->ie_X ; joyy = joyie->ie_Y ; SendIO(joyio); return 1; } return 0; } cleanupjoy() { if (joymp) { while (GetMsg(joymp)) ; setmsg(joyio, GPD_SETCTYPE, 1, joyie); *(BYTE *)joyie = GPCT_NOCONTROLLER ; SendIO(joyio); WaitPort(joymp); GetMsg(joymp); } if (gamedevice) CloseDevice(joyio); if (joyio) DeleteStdIO(joyio); if (joymp) DeletePort(joymp); if (joyie) FreeMem(joyie, sizeof(struct InputEvent)); } /* notes on code: cleanup() calls cleanupjoy() main() calls initjoy() and checkjoy() cleanup() is ALWAYS called before exiting. joybutton, joyx, and joyy are defined elsewhere, and used to communicate with the rest of the world */