home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / amiga / programm / 17985 < prev    next >
Encoding:
Text File  |  1992-12-31  |  3.1 KB  |  126 lines

  1. Newsgroups: comp.sys.amiga.programmer
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!network.ucsd.edu!munnari.oz.au!metro!extro.ucc.su.OZ.AU!willw
  3. From: willw@extro.ucc.su.OZ.AU (William Waring)
  4. Subject: Re: Simple C question
  5. Message-ID: <1992Dec31.083822.783@ucc.su.OZ.AU>
  6. Keywords: PLEASE RESPOND ASAP ;) (vaction almost  over....:) )
  7. Sender: news@ucc.su.OZ.AU
  8. Nntp-Posting-Host: extro.ucc.su.oz.au
  9. Organization: /etc/organization
  10. References: <C02JCH.pC@ccu.umanitoba.ca>
  11. Date: Thu, 31 Dec 1992 08:38:22 GMT
  12. Lines: 112
  13.  
  14. In article <C02JCH.pC@ccu.umanitoba.ca> umbadiu0@ccu.umanitoba.ca (Ted Babiuk) writes:
  15. >
  16. >Ok....I'm using Lattice/SAS C 5.10 and have done the following...
  17. >
  18. >A have a main program which creates a child task using createtask()....
  19. >
  20. >The child task runs TO FASSST! (its a color cycling routine....)
  21. >
  22. >I've  tried using a Delay(x) or wait(x) function to slow it down and make
  23. >it delay/wait...but this either stops the task entirely (no cycling
  24. >occures?...strange.....with Delay(10) i believe....) or crashes the
  25. >system....:(...
  26. >
  27. >I've been able to do it with a loop as follows:
  28. >
  29. >for (count=0;count<8000;count++);
  30. >......
  31. >cycle colors....etc.
  32. >
  33. >
  34. >BUT this takes processor time.....
  35. >
  36. >I could use the timer.device to do a timed wait but...
  37. >
  38. >there must be an easier way.....
  39. >
  40. >is there something simular to a sleep() command which puts a task to sleep
  41. >for 'x' ticks? (and uses little/no cpu time?)
  42. >
  43. >Thanks in advance,
  44.  
  45. Okay, do NOT use loops a time delay on the amiga! (Take it to IBM). The
  46. reason why Delay() does not work in your TASK is because it is a TASK and
  47. TASKS's cannot call dos.library functions. Since Delay() is a dos.library
  48. function, it don't work.
  49.  
  50. There are two solutiuons:
  51. 1:    Use the timer.device, which is easier than you think
  52. 2:    Turn the task into a process.
  53.  
  54. Solution to 1: (no I'm NOT a mathmatician)
  55.  
  56.     Timer device is quite easy to program, once ytou have it going. It
  57. doesn't use the dos.library at all, but uses the hardware is the
  58. recommended way of causing a wait of xxx seconds or however long you want.
  59. Grab a copy of the RKM: Devices manual and read up on the timer device.
  60. Programming a simple wait is quite simple.
  61.  
  62. Solution to 2:
  63.  
  64.     Use CreateNewProcTags instead of CreateTask()... Here is an
  65. example:
  66.  
  67. struct Process *CycleProcess = NULL;
  68. struct Process *MainProcess = NULL;
  69.  
  70. main()
  71. {
  72.     struct TagItem CycleProcTags[] = {
  73.         NP_Entry,    ColourServer,
  74.         NP_Name,    (UBYTE *)"Colour Cycle Process",
  75.         NP_Priority,    0,
  76.         TAG_DONE};
  77.  
  78.     
  79.     MainProcess = (struct Process *)FindTask(NULL);
  80.  
  81.     if (CycleProcess = CreateNewProc(&CycleProcTags))
  82.         {
  83.         Wait(SIGBREAKF_CTRL_C);
  84.         if (!CycleProcess)
  85.             CloseAll("Cycle task startup failed");
  86.         }
  87.     else
  88.         CloseAll("Couldn't create cycle process!");
  89.     }
  90.  
  91.     Wait(ON_ANYTHING);
  92.  
  93.     .
  94.     .
  95.     .
  96.  
  97. }
  98.  
  99. VOID __saveds ColourServer(VOID)
  100. {
  101.     if (SetupCylceStuff())
  102.         Signal(MainProcess,SIGBREAKF_CTRL_C);
  103.     else
  104.         {
  105.         CycleProcess = NULL;
  106.         Signal(MainProcess,SIGBREAKF_CTRL_C);
  107.         }
  108.     
  109.     while(CheckContinue())
  110.         {
  111.         CycleColours();
  112.         Delay(length);
  113.         }
  114.  
  115.     etc..
  116. }
  117.  
  118. BTW: This is obviously a section of code..
  119.  
  120. Hope this helps...
  121.  
  122. Regards,
  123.     Eddie
  124.  
  125.  
  126.