Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!sdd.hp.com!wuarchive!m.cs.uiuc.edu!schwager From: schwager@m.cs.uiuc.edu (Michael Schwager) Newsgroups: comp.sys.amiga.programmer Subject: "Task"'ing trubbles Summary: I'm trying to write a task Keywords: task programming amiga Message-ID: <1991May21.063012.1358@m.cs.uiuc.edu> Date: 21 May 91 06:30:12 GMT Organization: University of Illinois, Dept. of Comp. Sci., Urbana, IL Lines: 74 Vital stats: Amiga 500 w/ 3Meg ram, 30 Meg hard drive, using Aztec C 5.0d. Greets, I have a small (13 x 13 pixels) box in a window in a CUSTOMSCREEN. I want to make it flash, and I want it to quit flashing when the user hits another box. No sweat, right? I figger the best way to do this is to set up a little task running asynchronously that will do the flashing, so that the main program can wait for messages and kill the little flasher when a proper gadget is hit. So, it doesn't work. My main program calls the function "flash" that creates the Task "flashTask". The Task "flashTask" calls another function named "myDelay"... it works just like DOS' Delay() but using timer.device. I kill the task later in the program with a DeleteTask(). My algorithms worked when I was using simple functions (at that time, I had to limit the number of flashes so that I could go on and wait for another message). I want to make this as generic as possible, so I have some parameters come in as arguments to "flash". In the future I'll want to flash any Image in any window. For now, my Image structure is very simple: no data, just a rectangle and manipulation of PlaneOnOff. In general, I'm somewhat confused about what's legal with Tasks... can I treat 'em just like any other function in my program? Even give them arguments? Here's some pertinent code; any pointers or help would be appreciated. #include "myprogp.h" /* Intuition MUST be open for this, cuz it uses DrawImage! */ #define FLASHNAME "JohnnyFlash" #define FLASHSTK 3000 struct Task *flashTCB = NULL; /* I tried declaring the next three lines as static, but it didn't help. */ struct Window *flash_Window; struct Image *flash_Image; int x, y, mycolor; struct Task * flash (flash_Window, flash_Image, x, y, mycolor) { int i; void flashTask(); flashTCB = (struct Task *) FindTask (FLASHNAME); if (flashTCB) shutdown ("GAACK! Two flashing things at once!!?!"); /* flashTask is killed with a DeleteTask(flashTCB) elsewhere in the program; flashTCB is declared as extern there */ flashTCB = (struct Task *) CreateTask (FLASHNAME, 0, flashTask, FLASHSTK); return (flashTCB); } void flashTask () { geta4 (); for (;;) { flash_Image->PlaneOnOff = WHITE; DrawImage (flash_Window->RPort, flash_Image, x, y); flash_Image->PlaneOnOff = mycolor; myDelay(8); DrawImage (flash_Window->RPort, flash_Image, x, y); myDelay(12); } } -Mike Schwager | Machine: Amiga 500, 3 MB RAM/30 HD INTERNET:schwager@cs.uiuc.edu | Bike: '83 Kawasaki KZ750 LTD UUCP:{uunet|convex|pur-ee}!uiucdcs!schwager| Band: Poi Dog Pondering // BITNET:schwager@mike.cs.uiuc.edu | Hero: Robert Bly \\ // University of Illinois, Dept. of Comp. Sci.| DoD: #0301 \X/Amiga