home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol2 / v-11 / getaspect.c < prev   
C/C++ Source or Header  |  1996-01-30  |  4KB  |  137 lines

  1. ;/* getaspect.c - Execute me to compile me with SAS/C 6.56
  2. sc DATA=NEAR NMINC STRMERGE STREQ NOSTKCHK SAVEDS IGNORE=73 getaspect.c
  3. slink FROM LIB:c.o,getaspect.o TO getaspect LIBRARY LIB:sc.lib,LIB:amiga.lib
  4. quit
  5.  
  6. Gets X/Y pixel aspect of a screen's ViewPort
  7. */
  8. /*
  9. Copyright (c) 1991 Commodore-Amiga, Inc.
  10.  
  11. This example is provided in electronic form by Commodore-Amiga,
  12. Inc. for use with the Amiga Mail Volume II technical publication.
  13. Amiga Mail Volume II contains additional information on the correct
  14. usage of the techniques and operating system functions presented in
  15. these examples.  The source and executable code of these examples may
  16. only be distributed in free electronic form, via bulletin board or
  17. as part of a fully non-commercial and freely redistributable
  18. diskette.  Both the source and executable code (including comments)
  19. must be included, without modification, in any copy.  This example
  20. may not be published in printed form or distributed with any
  21. commercial product. However, the programming techniques and support
  22. routines set forth in these examples may be used in the development
  23. of original executable software products for Commodore Amiga
  24. computers.
  25.  
  26. All other rights reserved.
  27.  
  28. This example is provided "as-is" and is subject to change; no
  29. warranties are made.  All use is at your own risk. No liability or
  30. responsibility is assumed.
  31. */
  32.  
  33. #include <exec/types.h>
  34. #include <exec/memory.h>
  35. #include <libraries/dos.h>
  36. #include <intuition/intuition.h>
  37. #include <intuition/intuitionbase.h>
  38. #include <graphics/displayinfo.h>
  39. #include <graphics/gfxbase.h>
  40.  
  41. #include <clib/exec_protos.h>
  42. #include <clib/dos_protos.h>
  43. #include <clib/intuition_protos.h>
  44. #include <clib/graphics_protos.h>
  45. #include <stdlib.h>
  46. #include <stdio.h>
  47. #include <string.h>
  48.  
  49. #ifdef LATTICE
  50. int CXBRK(void) { return(0); }  /* Disable Lattice CTRL/C handling */
  51. int chkabort(void) { return(0); }  /* really */
  52. #endif
  53.  
  54.  
  55. #define MINARGS 1
  56.  
  57. UBYTE *vers = "\0$VER: getaspect 37.1";
  58. UBYTE *Copyright =
  59.   "getaspect v37.1\nCopyright (c) 1990 Commodore-Amiga, Inc.  All Rights Reserved";
  60. UBYTE *usage = "Usage: getaspect";
  61.  
  62. void bye(UBYTE *s, int e);
  63. void cleanup(void);
  64.  
  65. struct Library *IntuitionBase;
  66. struct Library *GfxBase;
  67.  
  68. void main(int argc, char **argv)
  69.     {
  70.     struct Screen *first;
  71.     struct ViewPort *vp;
  72.     struct DisplayInfo DI;
  73.     ULONG  modeid;
  74.     UBYTE  xAspect, yAspect;
  75.  
  76.     if(((argc)&&(argc<MINARGS))||(argv[argc-1][0]=='?'))
  77.     {
  78.     printf("%s\n%s\n",Copyright,usage);
  79.     bye("",RETURN_OK);
  80.     }
  81.  
  82.     /* We will check later to see if we can call V36 functions */
  83.     IntuitionBase = OpenLibrary("intuition.library",34);
  84.     GfxBase = OpenLibrary("graphics.library",34);
  85.     if((!IntuitionBase)||(!GfxBase))
  86.     bye("Can't open intuition or graphics library",RETURN_FAIL);
  87.  
  88.     printf("Using front screen's ViewPort (for example purposes only):\n");
  89.  
  90.     first = ((struct IntuitionBase *)IntuitionBase)->FirstScreen;
  91.     vp = &first->ViewPort;
  92.  
  93.     xAspect = 0;    /* So we can tell when we've got it */
  94.  
  95.     if(GfxBase->lib_Version >= 36)
  96.     {
  97.         modeid = GetVPModeID(vp);
  98.  
  99.         if(GetDisplayInfoData(NULL, (UBYTE *)&DI, sizeof(struct DisplayInfo),
  100.         DTAG_DISP, modeid))
  101.         {
  102.         printf("Running 2.0,  ViewPort modeid is $%08lx\n",modeid);
  103.         xAspect = DI.Resolution.x;
  104.         yAspect = DI.Resolution.y;
  105.         printf("Pixel  xAspect=%ld  yAspect=%ld\n",xAspect, yAspect);
  106.         printf("PaletteRange is %ld\n",DI.PaletteRange);
  107.         }
  108.     }
  109.  
  110.     if(!xAspect)  /* pre-2.0 or GetDisplayInfoData failed */
  111.     {
  112.     modeid = vp->Modes;
  113.     printf("Not running 2.0, ViewPort mode is $%04lx\n",modeid);
  114.         /* default lores pixel ratio */
  115.         xAspect = 44;
  116.         yAspect = ((struct GfxBase *)GfxBase)->DisplayFlags & PAL  ? 44 : 52;
  117.         if(modeid & HIRES)      xAspect = xAspect >> 1;
  118.         if(modeid & LACE)       yAspect = yAspect >> 1;
  119.     printf("Pixel  xAspect=%ld  yAspect=%ld\n",xAspect, yAspect);
  120.         }
  121.  
  122.     bye("",RETURN_OK);
  123.     }
  124.  
  125.  
  126. void bye(UBYTE *s, int e)
  127.     {
  128.     cleanup();
  129.     exit(e);
  130.     }
  131.  
  132. void cleanup()
  133.     {
  134.     if(GfxBase) CloseLibrary(GfxBase);
  135.     if(IntuitionBase)   CloseLibrary(IntuitionBase);
  136.     }
  137.