home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / devcon / milan_1991 / devcon91.2 / aa / maxdepthlores.c < prev    next >
C/C++ Source or Header  |  1992-09-01  |  3KB  |  132 lines

  1. /*
  2.  * maxdepthlores.c by Christian Ludwig (CATS)
  3.  * (91.08.02)
  4.  */
  5.  
  6. #include <intuition/intuition.h>
  7. #include <graphics/gfxbase.h>
  8. #include <graphics/displayinfo.h>
  9. #include <intuition/screens.h>
  10.  
  11. #include <clib/exec_protos.h>
  12. #include <clib/dos_protos.h>
  13. #include <clib/intuition_protos.h>
  14. #include <clib/graphics_protos.h>
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18.  
  19. struct IntuitionBase *IntuitionBase;
  20. struct GfxBase *GfxBase;
  21. extern struct ExecBase *SysBase;
  22.  
  23.  
  24. void Quit(char whytext[],UBYTE failcode)
  25. {
  26.     if (IntuitionBase) CloseLibrary((struct Library *) IntuitionBase);
  27.  
  28.     if (GfxBase) CloseLibrary((struct Library *) GfxBase);
  29.  
  30.     printf("%s\n",whytext);
  31.  
  32.     Delay(50*10);
  33.  
  34.     exit(failcode);
  35. }
  36.  
  37. void main(void)
  38. {
  39.     ULONG modeID = LORES_KEY;
  40.     DisplayInfoHandle displayhandle;
  41.     struct DimensionInfo dimensioninfo;
  42.  
  43.     UWORD maxdepth, maxcolors;
  44.  
  45.     ULONG soerror = NULL,colornum;
  46.  
  47.     struct Screen *screen;
  48.  
  49.     if ((GfxBase=
  50.     (struct GfxBase *) OpenLibrary("graphics.library",36))==NULL)
  51.         Quit("graphics.library is too old <V36",25);
  52.  
  53.     if ((IntuitionBase=
  54.     (struct IntuitionBase *) OpenLibrary("intuition.library",36))==NULL)
  55.         Quit("intuition.library is too old <V36",25);
  56.  
  57.     if ((displayhandle=FindDisplayInfo(modeID))==NULL)
  58.         Quit("modeID not found in display database",25);
  59.  
  60.     if (GetDisplayInfoData(displayhandle,(UBYTE *) &dimensioninfo,
  61.     sizeof(struct DimensionInfo),DTAG_DIMS,NULL)==0)
  62.         Quit("mode dimension info not available",25);
  63.  
  64.     maxdepth=dimensioninfo.MaxDepth;
  65.     printf("dimensioninfo.MaxDepth=%d\n",(int) maxdepth);
  66.  
  67.  
  68.     if (screen=OpenScreenTags(NULL,SA_DisplayID        ,modeID,
  69.                                    SA_Depth            ,(UBYTE) maxdepth,
  70.                                    SA_Title            ,"MaxDepth LORES",
  71.                                    SA_ErrorCode        ,&soerror,
  72.                                    SA_FullPalette    ,TRUE,
  73.                                    TAG_END))
  74.         {
  75.             /* Zowee! we actually got the screen open!
  76.              *
  77.              * now let's try drawing into it.
  78.              */
  79.  
  80.             maxcolors=1<<maxdepth;
  81.  
  82.             printf("maxcolors=%d\n",(int) maxcolors);
  83.  
  84.             for(colornum=0;colornum<maxcolors;++colornum)
  85.             {
  86.                 SetAPen(&(screen->RastPort),colornum);
  87.                 Move(&(screen->RastPort),colornum,screen->BarHeight + 2);
  88.                 Draw(&(screen->RastPort),colornum,199);
  89.             }
  90.  
  91.             Delay(50*1*6);
  92.  
  93.             CloseScreen(screen);
  94.         }
  95.  
  96.     else
  97.         {
  98.             /*
  99.              * Hmmm.  Couldn't open the screen.  maybe not
  100.              * enough CHIP RAM? Maybe not enough chips! ;-)
  101.              */
  102.  
  103.             switch(soerror)
  104.             {
  105.                 case OSERR_NOCHIPS:
  106.                     Quit("Bummer! You need new chips dude!",25);
  107.                     break;
  108.  
  109.                 case OSERR_UNKNOWNMODE:
  110.                     Quit("Bummer! Unknown screen mode.",25);
  111.                     break;
  112.  
  113.                 case OSERR_NOCHIPMEM:
  114.                     Quit("Not enough CHIP memory.",25);
  115.                     break;
  116.  
  117.                 case OSERR_NOMEM:
  118.                     Quit("Not enough FAST memory.",25);
  119.                     break;
  120.  
  121.                 default:
  122.                     printf("soerror=%d\n",soerror);
  123.                     Quit("Screen opening error.",25);
  124.                     break;
  125.             }
  126.  
  127.             Quit("Couldn't open screen.",25);
  128.         }
  129.  
  130.     Quit("Done.",0);
  131. }
  132.