home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 378.lha / WBD / WBD.c < prev    next >
C/C++ Source or Header  |  1980-02-02  |  2KB  |  90 lines

  1. /*
  2.  
  3.     ---
  4.   < WBD >
  5.     ---
  6.  
  7.     set workbench screen depth
  8.  
  9.     © 1990 by Oliver Wagner
  10.           Landsberge 5
  11.           4322 Sprockhövel
  12.           Tel.: 02339/7536
  13.  
  14.     Usage: WBD depth [1..4]
  15.     CLI only!
  16.  
  17.     Make with Lettuce C V5.04
  18.  
  19.     lc -rr -v -mt -rr -csmuq wbd
  20.     blink wbd.o
  21.  
  22.     No startup module necessary (Hi John °¡°)
  23.  
  24. */
  25.  
  26. int main(char*);
  27. int alloc(struct BitMap*,int);
  28. void free(struct BitMap*,int);
  29.  
  30. #include <proto/dos.h>
  31. #include <proto/exec.h>
  32. #include <proto/intuition.h>
  33. #include <string.h>
  34. #include <exec/memory.h>
  35.  
  36. #define print(s) Write(output,s,strlen(s))
  37.  
  38. int main(line)
  39. char *line;
  40. {
  41.     struct DosBase *DOSBase=OldOpenLibrary("dos.library");
  42.     struct IntuitionBase *IntuitionBase=OldOpenLibrary("intuition.library");
  43.     struct Screen *scr=(struct Screen*)OpenWorkBench();
  44.     struct BitMap *bm=&scr->BitMap;
  45.     BPTR output=Output();
  46.     int depth=*line-'0';
  47.  
  48.     if(depth<1||depth>4) {
  49.     print("WBD: depth [1..4]\n");
  50.     return(20);
  51.     }
  52.     if(depth<4) free(bm,4);
  53.     if(depth<3) free(bm,3);
  54.     if(depth<2) free(bm,2);
  55.     if(depth>1) if(!alloc(bm,2)) {
  56.     print("\x07WBD: No memory!\n");
  57.     depth=1;
  58.     }
  59.     if(depth>2)  if(!alloc(bm,3)) {
  60.     print("\x07WBD: No memory!\n");
  61.     depth=2;
  62.     }
  63.     if(depth>3) if(!alloc(bm,4)) {
  64.     print("\x07WBD: No memory!\n");
  65.     depth=3;
  66.     }
  67.     bm->Depth=depth;
  68.     RemakeDisplay();
  69.     return(0);
  70. }
  71.  
  72. int alloc(bm,p)
  73. int p;
  74. struct BitMap *bm;
  75. {
  76.     if(bm->Depth<p) {
  77.     return((int)(bm->Planes[p-1]=AllocMem(bm->BytesPerRow*bm->Rows,MEMF_CHIP|MEMF_CLEAR)));
  78.     }
  79.     return(-1);
  80. }
  81.  
  82. void free(bm,p)
  83. int p;
  84. struct BitMap *bm;
  85. {
  86.     if(bm->Depth>=p)
  87.     FreeMem(bm->Planes[p-1],bm->BytesPerRow*bm->Rows);
  88. }
  89.  
  90.