home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.amiga.programmer
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!network.ucsd.edu!munnari.oz.au!metro!extro.ucc.su.OZ.AU!willw
- From: willw@extro.ucc.su.OZ.AU (William Waring)
- Subject: Re: Simple C question
- Message-ID: <1992Dec31.083822.783@ucc.su.OZ.AU>
- Keywords: PLEASE RESPOND ASAP ;) (vaction almost over....:) )
- Sender: news@ucc.su.OZ.AU
- Nntp-Posting-Host: extro.ucc.su.oz.au
- Organization: /etc/organization
- References: <C02JCH.pC@ccu.umanitoba.ca>
- Date: Thu, 31 Dec 1992 08:38:22 GMT
- Lines: 112
-
- In article <C02JCH.pC@ccu.umanitoba.ca> umbadiu0@ccu.umanitoba.ca (Ted Babiuk) writes:
- >
- >Ok....I'm using Lattice/SAS C 5.10 and have done the following...
- >
- >A have a main program which creates a child task using createtask()....
- >
- >The child task runs TO FASSST! (its a color cycling routine....)
- >
- >I've tried using a Delay(x) or wait(x) function to slow it down and make
- >it delay/wait...but this either stops the task entirely (no cycling
- >occures?...strange.....with Delay(10) i believe....) or crashes the
- >system....:(...
- >
- >I've been able to do it with a loop as follows:
- >
- >for (count=0;count<8000;count++);
- >......
- >cycle colors....etc.
- >
- >
- >BUT this takes processor time.....
- >
- >I could use the timer.device to do a timed wait but...
- >
- >there must be an easier way.....
- >
- >is there something simular to a sleep() command which puts a task to sleep
- >for 'x' ticks? (and uses little/no cpu time?)
- >
- >Thanks in advance,
-
- Okay, do NOT use loops a time delay on the amiga! (Take it to IBM). The
- reason why Delay() does not work in your TASK is because it is a TASK and
- TASKS's cannot call dos.library functions. Since Delay() is a dos.library
- function, it don't work.
-
- There are two solutiuons:
- 1: Use the timer.device, which is easier than you think
- 2: Turn the task into a process.
-
- Solution to 1: (no I'm NOT a mathmatician)
-
- Timer device is quite easy to program, once ytou have it going. It
- doesn't use the dos.library at all, but uses the hardware is the
- recommended way of causing a wait of xxx seconds or however long you want.
- Grab a copy of the RKM: Devices manual and read up on the timer device.
- Programming a simple wait is quite simple.
-
- Solution to 2:
-
- Use CreateNewProcTags instead of CreateTask()... Here is an
- example:
-
- struct Process *CycleProcess = NULL;
- struct Process *MainProcess = NULL;
-
- main()
- {
- struct TagItem CycleProcTags[] = {
- NP_Entry, ColourServer,
- NP_Name, (UBYTE *)"Colour Cycle Process",
- NP_Priority, 0,
- TAG_DONE};
-
-
- MainProcess = (struct Process *)FindTask(NULL);
-
- if (CycleProcess = CreateNewProc(&CycleProcTags))
- {
- Wait(SIGBREAKF_CTRL_C);
- if (!CycleProcess)
- CloseAll("Cycle task startup failed");
- }
- else
- CloseAll("Couldn't create cycle process!");
- }
-
- Wait(ON_ANYTHING);
-
- .
- .
- .
-
- }
-
- VOID __saveds ColourServer(VOID)
- {
- if (SetupCylceStuff())
- Signal(MainProcess,SIGBREAKF_CTRL_C);
- else
- {
- CycleProcess = NULL;
- Signal(MainProcess,SIGBREAKF_CTRL_C);
- }
-
- while(CheckContinue())
- {
- CycleColours();
- Delay(length);
- }
-
- etc..
- }
-
- BTW: This is obviously a section of code..
-
- Hope this helps...
-
- Regards,
- Eddie
-
-
-