home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d7xx / d754 / softrack.lha / SofTrack / SofTrack.C < prev    next >
C/C++ Source or Header  |  1992-11-05  |  4KB  |  175 lines

  1. /* program SofTrack.Shows the floppy head position and whether it is a read or 
  2. write operation.compile with lattice C 3.1 and link with Install.o and 
  3. GetUnitID.o using blink.
  4.  
  5. Written by Kamran Karimi
  6. */ 
  7.  
  8.  
  9. #include <exec/exec.h>
  10. #include <intuition/intuition.h>
  11. #include <resources/disk.h>
  12.  
  13. struct TextAttr ROMFont = 
  14.  { (STRPTR)"topaz.font",TOPAZ_EIGHTY,FS_NORMAL,FPF_ROMFONT };
  15.  
  16. struct TextAttr MyPRG =
  17.  { (STRPTR)"topaz.font",TOPAZ_EIGHTY,FSF_BOLD,FPF_ROMFONT };
  18.  
  19. struct IntuiText DF0 =
  20.  { 2,0,JAM2,2,1,&ROMFont,(UBYTE *) "DF0:  ?   DF1:  ?   ",NULL };
  21.  
  22. struct IntuiText DF2 =
  23.  { 2,0,JAM2,2,10,&ROMFont,(UBYTE *)"DF2:  ?   DF3:  ?   ",&DF0 };
  24.  
  25. struct IntuiText DFT =
  26.  { 1,0,JAM2,12,1,&ROMFont,(UBYTE *)"000 R",NULL };
  27.  
  28. struct IntuiText Intro = 
  29.  { 2,0,JAM2,2,1,&MyPRG,(UBYTE *)   "      SofTrack     ",NULL };
  30.  
  31. struct IntuiText MyName = 
  32.  { 1,0,JAM2,2,10,&ROMFont,(UBYTE *)"  By Kamran Karimi ",&Intro };
  33.  
  34. struct IntuiText NoDisk = 
  35.  { 2,0,JAM2,12,1,&ROMFont,(UBYTE *)" N/A",NULL };   
  36.  
  37. struct IntuitionBase *IntuitionBase;
  38. struct Window *MyWindow;
  39. struct MsgPort *Port;
  40. struct DiscResource *DiskBase;
  41.  
  42. ULONG CoOrd[4][2] = 
  43.          { {23,10},{105,10},{23,19},{105,19} };
  44.  
  45. struct NewWindow WindowPar =
  46.  { 400,0,171,30,0,1,NULL,WINDOWDEPTH|WINDOWDRAG,NULL,NULL,
  47.    (UBYTE *)"SofTrack",NULL,NULL,0,0,0,0,WBENCHSCREEN};
  48.  
  49. short Install();
  50. struct MsgPort *CreatePort();
  51. unsigned long GetUnitID();
  52.  
  53. struct Library *OpenLibrary(),*OpenResource();
  54. struct Window *OpenWindow();
  55. char   SetTaskPri();
  56. struct Task    *FindTask();
  57. struct Message *GetMsg(),*WaitPort();
  58. struct MsgPort  *FindPort();
  59. void ReplyMsg(),CloseLibrary(),CloseWindow(),CloseAll();
  60. void PrintIText(),Forbid(),Permit();
  61.  
  62. void main()
  63. {
  64.  char *titel,NewTitel[6],OldTitel0[6],OldTitel1[6],OldTitel2[6],OldTitel3[6];
  65.  char Unit;
  66.  struct Task *task;
  67.  unsigned long count;
  68.  struct Message *message;
  69.  struct RastPort *MyWindowRP;
  70.  
  71.   if(FindPort("SofTrack's Port"))  exit(0); 
  72.  
  73.   if(!(IntuitionBase =
  74.               (struct IntuitionBase *)OpenLibrary("intuition.library",0L)))
  75.   {
  76.    CloseAll();
  77.    exit(10);
  78.   }
  79.  
  80.  if(!(MyWindow = OpenWindow(&WindowPar)))
  81.   {
  82.    CloseAll();
  83.    exit(10);
  84.   }
  85.  MyWindowRP = MyWindow->RPort;
  86.  PrintIText(MyWindowRP,&MyName,2L,10L);
  87.  Delay(150L);
  88.  PrintIText(MyWindowRP,&DF2,2L,10L);
  89.  if(!(Port = CreatePort("SofTrack's Port",1L)))
  90.   {
  91.    CloseAll();
  92.    exit(10);
  93.   }
  94.   if (Install())
  95.   {
  96.    CloseAll();
  97.    exit(10);
  98.   }
  99.  
  100.  if(DiskBase = (struct DiscResource *)OpenResource("disk.resource",0L))
  101.   {
  102.    for(count = 0;count <= 4;count++)
  103.     {
  104.      if(GetUnitID(count) == DRT_EMPTY)
  105.         PrintIText(MyWindowRP,&NoDisk,CoOrd[count][0],CoOrd[count][1]);
  106.     }
  107.   }
  108.    
  109.  strcpy(OldTitel0,"     ");
  110.  strcpy(OldTitel1,"     ");
  111.  strcpy(OldTitel2,"     ");
  112.  strcpy(OldTitel3,"     ");
  113.  
  114.  task = FindTask(NULL);
  115.  SetTaskPri(task,19L);
  116.  for (;;)
  117.  {
  118.    WaitPort(Port);
  119.    message = GetMsg(Port);
  120.    Forbid();
  121.    titel = (char *)(&message->mn_Length);
  122.    titel += 2;
  123.    Unit = *titel;
  124.    titel += 2; 
  125.    strcpy(NewTitel,titel);
  126.    switch(Unit)
  127.     {
  128.      case 0:
  129.       if(strcmp(NewTitel,OldTitel0))
  130.        {
  131.         DFT.IText = (UBYTE *)NewTitel;
  132.         PrintIText(MyWindowRP,&DFT,23L,10L);
  133.         strcpy(OldTitel0,NewTitel);
  134.        }
  135.       break;
  136.  
  137.      case 1:
  138.       if (strcmp(NewTitel,OldTitel1))
  139.       {
  140.        DFT.IText = (UBYTE *)NewTitel;
  141.        PrintIText(MyWindowRP,&DFT,105L,10L);
  142.        strcpy(OldTitel1,NewTitel);
  143.       }
  144.      break;
  145.  
  146.      case 2:
  147.       if (strcmp(NewTitel,OldTitel2))
  148.        {
  149.         DFT.IText = (UBYTE *)NewTitel;
  150.         PrintIText(MyWindowRP,&DFT,23L,19L);
  151.         strcpy(OldTitel2,NewTitel);
  152.        }
  153.       break;
  154.  
  155.      case 3:
  156.       if (strcmp(NewTitel,OldTitel3))
  157.        {
  158.         DFT.IText = (UBYTE *)NewTitel;
  159.         PrintIText(MyWindowRP,&DFT,105L,19L);
  160.         strcpy(OldTitel3,NewTitel);
  161.        }
  162.      break;
  163.     }
  164.   Permit();
  165.   ReplyMsg(message);
  166.  }
  167. }
  168.  
  169.  
  170. void CloseAll()
  171. {
  172.  if (MyWindow)      CloseWindow(MyWindow);
  173.  if (IntuitionBase) CloseLibrary(IntuitionBase);
  174. }
  175.