home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 357.lha / availmem_v1.0 / AvailMem.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-13  |  3.3 KB  |  97 lines

  1. /*------------------------- AvailMem V1.10 ----------------------------*/
  2. /*Written and copyright (c)1988, 1989, 1990 by Dave Schreiber. All rights*/
  3. /*reserved.  This program may not be sold, but reasonable charges for  */
  4. /*media, duplication, shipping/handling, etc. are permitted.           */
  5. /*---------------------------------------------------------------------*/
  6. /*Keeps a running count of the amount of FAST, CHIP, and total memory  */
  7. /*free.  Updates every .7 seconds.  With a stack size of 4K, it takes  */
  8. /*up about 12K of RAM.  Compiled under Lattice C V5.02                 */
  9. /*----------------------------- Enjoy ---------------------------------*/
  10. /*Version history:                                                     */
  11. /* 1.10 - Added a counter of the largest block free for FAST, CHIP, and*/
  12. /*        total memory                                                 */
  13. /* 1.03 - First release to the public.  Included on Fred Fish disk #285*/
  14. /*---------------------------------------------------------------------*/
  15.  
  16.  
  17. /*Standard #include files*/
  18. #include <exec/types.h>
  19. #include <exec/exec.h>
  20. #include <intuition/intuition.h>
  21.  
  22. /*Window and IntuiText definitions*/
  23. #include "AvailMem.h"
  24.  
  25. struct IntuitionBase *IntuitionBase;   /*Library base pointers*/
  26. struct GfxBase *GfxBase;
  27.  
  28. void MainLoop();
  29. void MakeString();
  30.  
  31. #define Rp Wdw->RPort
  32.  
  33.          /*Using _main() keeps AmigaDOS from opening an extra */
  34. _main()  /*console window when AvailMem is run from Workbench.*/
  35. {
  36.    if((IntuitionBase=(struct IntuitionBase *)   /*Open Intuition*/
  37.          OpenLibrary("intuition.library",0))==NULL)
  38.       exit(10);
  39.                               /*Open Graphics*/
  40.    if((GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0))==NULL)
  41.    {
  42.       CloseLibrary(IntuitionBase); /*Like it really matters...*/
  43.       exit(20);
  44.    }
  45.  
  46.    MainLoop();
  47.  
  48.    CloseLibrary(GfxBase);     /*Close the libraries*/
  49.    CloseLibrary(IntuitionBase);
  50. }
  51.  
  52. void MainLoop()   /*The main loop*/
  53. {
  54.    struct Window *Wdw;  /*Window pointer*/
  55.    ULONG c,f;
  56.  
  57.                               /*Open the window*/
  58.    if((Wdw=(struct Window *)OpenWindow(&NewWindowStructure1))==NULL)
  59.       exit(30);
  60.    
  61.    PrintIText(Rp,&IText1,-6,2);
  62.  
  63.    /*while the close gadget wasn't pressed...*/
  64.    while( ( GetMsg(Wdw->UserPort) ) == NULL)
  65.       {  /*For each possibility, get the memory count, convert it to text,
  66.          /*put it into the appropriate intuitext structure,*/
  67.       
  68.       c=AvailMem(MEMF_LARGEST|MEMF_CHIP);
  69.       f=AvailMem(MEMF_LARGEST|MEMF_FAST);
  70.       MakeString(IText12.IText,(c < f) ? f : c);
  71.       MakeString(IText11.IText,c);
  72.       MakeString(IText10.IText,f);
  73.       
  74.       c=AvailMem(MEMF_CHIP);
  75.       f=AvailMem(MEMF_FAST);
  76.       MakeString(IText9.IText,c+f);
  77.       MakeString(IText8.IText,c);
  78.       MakeString(IText7.IText,f);
  79.       
  80.       PrintIText(Rp,&IText7,-6,2); /*and print it*/
  81.       Delay(35);    /*Wait for .7 seconds, then do the whole thing again*/
  82.       }
  83.    CloseWindow(Wdw);    /*Close the window*/
  84. }
  85.  
  86. void MakeString(string,amt) /*Convert amt to a string, put into 'string'*/
  87. char *string;               /*and pad out with spaces*/
  88. ULONG amt;
  89. {
  90.    BYTE c;
  91.    stcu_d(string,amt,8);   /*Convert number into text*/
  92.    for(c=strlen(string);c<8;c++)
  93.       string[c]=' ';       /*Pad out with spaces*/
  94.       
  95.    string[8]=NULL;         /*And terminate with a NULL*/
  96. }
  97.