home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / OTL-MC7.DMS / in.adf / ansicdemo.lha / ANSI-C / Intuition / wbtricks.c < prev   
Encoding:
C/C++ Source or Header  |  1994-10-30  |  7.5 KB  |  248 lines

  1. #include <exec/types.h>
  2. #include <exec/exec.h>
  3. #include <dos/dos.h>
  4. #include <dos/rdargs.h>
  5. #include <clib/dos_protos.h>
  6. #include <intuition/screens.h>
  7. #include <intuition/intuition.h>
  8. #include <intuition/intuitionbase.h>
  9. #include <graphics/gfx.h>
  10. #include <graphics/gfxbase.h>
  11. #include <graphics/displayinfo.h>
  12. #include <graphics/view.h>
  13. #include <graphics/videocontrol.h>
  14.  
  15. #include <pragma/all_lib.h>
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20.  
  21. struct IntuitionBase *IntuitionBase = NULL ;
  22. struct GfxBase *GfxBase = NULL ;
  23.  
  24. /**********************************************************************/
  25. /*                                                                    */
  26. /* void Error (char *String)                                          */
  27. /* Print string and exit                                              */
  28. /*                                                                    */
  29. /**********************************************************************/
  30.  
  31. void Error (char *String)
  32. {
  33.     void CloseAll (void) ;
  34.     
  35.     printf (String) ;
  36.     CloseAll () ;
  37.     exit(0) ;
  38. }
  39.  
  40.  
  41. /**********************************************************************/
  42. /*                                                                    */
  43. /* void Init ()                                                       */
  44. /*                                                                    */
  45. /* Opens all the required libraries                                   */
  46. /* allocates all memory, etc.                                         */
  47. /*                                                                    */
  48. /**********************************************************************/
  49.  
  50. void Init ( void )
  51. {
  52.     /* Open the intuition library.... */
  53.     if ((IntuitionBase = (struct IntuitionBase *)OpenLibrary ("intuition.library", 37)) == NULL)
  54.         Error ("Could not open the Intuition.library") ;
  55.  
  56.     /* Open the graphics library.... */
  57.     if ((GfxBase = (struct GfxBase *)OpenLibrary ("graphics.library", 39)) == NULL)
  58.         Error ("Could not open the Graphics.library") ;
  59.  
  60.     return ;
  61. }
  62.  
  63. /**********************************************************************/
  64. /*                                                                    */
  65. /* void CloseAll ()                                                   */
  66. /*                                                                    */
  67. /* Closes and tidies up everything that was used.                     */
  68. /*                                                                    */
  69. /**********************************************************************/
  70.  
  71. void CloseAll ()
  72. {
  73.     /* Close everything in the reverse order in which they were opened */
  74.  
  75.     /* Close the Graphics Library */
  76.     if (GfxBase)
  77.         CloseLibrary ((struct Library *) GfxBase) ;
  78.  
  79.     /* Close the Intuition Library */
  80.     if (IntuitionBase)
  81.         CloseLibrary ((struct Library *) IntuitionBase) ;
  82.  
  83.     return ;
  84. }
  85.  
  86. /***************************************************************************/
  87.  
  88. void main (int argc, char *argv[])
  89. {
  90.     #define TEMPLATE "B=BORDERSPRITE/S,R=RESOLUTION/N,PF1/N,PF2/N,SPODD/N,SPEVEN/N,BASE1/N,BASE2/N,S=SHOW/S"
  91.     #define OPT_BSPRITE 0
  92.     #define OPT_RESOLUTION 1
  93.     #define OPT_PF1 2
  94.     #define OPT_PF2 3
  95.     #define OPT_SPODD 4
  96.     #define OPT_SPEVEN 5
  97.     #define OPT_BASE1 6
  98.     #define OPT_BASE2 7
  99.     #define OPT_SHOW 8
  100.     #define OPT_COUNT 9
  101.  
  102.     LONG result[OPT_COUNT];
  103.     LONG *val;
  104.     struct Screen *wb;
  105.     struct RDArgs *rdargs;
  106.     struct TagItem ti[] =
  107.     {
  108.         {VTAG_BORDERSPRITE_GET, TRUE},
  109.         {VTAG_SPRITERESN_GET, SPRITERESN_ECS},
  110.         {VTAG_PF1_TO_SPRITEPRI_GET, 0},
  111.         {VTAG_PF2_TO_SPRITEPRI_GET, 0},
  112.         {VTAG_SPODD_BASE_GET, 0},
  113.         {VTAG_SPEVEN_BASE_GET, 0},
  114.         {VTAG_PF1_BASE_GET, 0},
  115.         {VTAG_PF2_BASE_GET, 0},
  116.         {TAG_DONE, NULL},
  117.     };
  118.  
  119.     Init () ;
  120.  
  121.     result[OPT_BSPRITE] = FALSE;
  122.     result[OPT_RESOLUTION] = 0;
  123.     result[OPT_PF1] = 0;
  124.     result[OPT_PF2] = 0;
  125.     result[OPT_SPODD] = 0;
  126.     result[OPT_SPEVEN] = 0;
  127.     result[OPT_BASE1] = 0;
  128.     result[OPT_BASE2] = 0;
  129.     result[OPT_SHOW] = FALSE;
  130.  
  131.     /* We are going to hijack the Workbench ColorMap for this. Not very
  132.      * friendly, but it's just to show you what the new AA features can do.
  133.      */
  134.  
  135.     if (wb = LockPubScreen("Workbench"))
  136.     {
  137.         /* Get all the current settings */
  138.         if ((VideoControl(wb->ViewPort.ColorMap, ti)) == NULL)
  139.         {
  140.             if (rdargs = ReadArgs(TEMPLATE, result, NULL))
  141.             {
  142.                 if (result[OPT_BSPRITE])
  143.                 {
  144.                     /* Enable the sprite in the border */
  145.                     ti[OPT_BSPRITE].ti_Tag = ((ti[OPT_BSPRITE].ti_Tag == VTAG_BORDERSPRITE_SET) ?
  146.                                     VTAG_BORDERSPRITE_CLR :
  147.                                     VTAG_BORDERSPRITE_SET);
  148.                 }
  149.  
  150.                 if (val = (LONG *)result[OPT_RESOLUTION])
  151.                 {
  152.                     /* set the sprite pixel speed */
  153.                     switch (*val)
  154.                     {
  155.                         case 140 : ti[OPT_RESOLUTION].ti_Data = SPRITERESN_140NS; break;
  156.                         case 70  : ti[OPT_RESOLUTION].ti_Data = SPRITERESN_70NS; break;
  157.                         case 35  : ti[OPT_RESOLUTION].ti_Data = SPRITERESN_35NS; break;
  158.                         case 0   : ti[OPT_RESOLUTION].ti_Data = SPRITERESN_ECS; break;
  159.                         case -1 :
  160.                         default  : ti[OPT_RESOLUTION].ti_Data = SPRITERESN_DEFAULT; break;
  161.                     }
  162.                 }
  163.  
  164.                 /* Sprite-to-Pfd1 priority. This has always been settable
  165.                  * on the Amiga, but this is the first time a
  166.                  * friendly programmable interface has been given.
  167.                  */
  168.                 if (val = (LONG *)result[OPT_PF1])
  169.                 {
  170.                     ti[OPT_PF1].ti_Data = *val;
  171.                 }
  172.                 /* Sprite-to-pfd2 priority */
  173.                 if (val = (LONG *)result[OPT_PF2])
  174.                 {
  175.                     ti[OPT_PF2].ti_Data = *val;
  176.                 }
  177.  
  178.                 /* AA lets you set the colour-offset for the odd and
  179.                  * even sprite numbers. The default is  colour 16-31.
  180.                  * You can set only multiples of 16 for AA.
  181.                  */
  182.                 if (val = (LONG *)result[OPT_SPODD])
  183.                 {
  184.                     ti[OPT_SPODD].ti_Data = *val;
  185.                 }
  186.                 if (val = (LONG *)result[OPT_SPEVEN])
  187.                 {
  188.                     ti[OPT_SPEVEN].ti_Data = *val;
  189.                 }
  190.  
  191.                 /* This controls the base colour of the playfields in weird and
  192.                  * wacky ways.
  193.                  */
  194.                 if (val = (LONG *)result[OPT_BASE1])
  195.                 {
  196.                     ti[OPT_BASE1].ti_Data = *val;
  197.                 }
  198.                 if (val = (LONG *)result[OPT_BASE2])
  199.                 {
  200.                     ti[OPT_BASE2].ti_Data = *val;
  201.                 }
  202.  
  203.                 /* Now go do it */
  204.                 VideoControl(wb->ViewPort.ColorMap, ti);
  205.                 MakeScreen(wb);
  206.                 RethinkDisplay();
  207.  
  208.                 if (result[OPT_SHOW])
  209.                 {
  210.                     /* Read everything back again. */
  211.                     ti[OPT_BSPRITE].ti_Tag = VTAG_BORDERSPRITE_GET;
  212.                     ti[OPT_RESOLUTION].ti_Tag = VTAG_SPRITERESN_GET;
  213.                     ti[OPT_PF1].ti_Tag = VTAG_PF1_TO_SPRITEPRI_GET;
  214.                     ti[OPT_PF2].ti_Tag = VTAG_PF2_TO_SPRITEPRI_GET;
  215.                     ti[OPT_SPODD].ti_Tag = VTAG_SPODD_BASE_GET;
  216.                     ti[OPT_SPEVEN].ti_Tag = VTAG_SPEVEN_BASE_GET;
  217.                     ti[OPT_BASE1].ti_Tag = VTAG_PF1_BASE_GET;
  218.                     ti[OPT_BASE2].ti_Tag = VTAG_PF2_BASE_GET;
  219.                     if ((VideoControl(wb->ViewPort.ColorMap, ti)) == NULL)
  220.                     {
  221.                         UBYTE *res;
  222.                         printf("BorderSprite = %s\n", ((ti[OPT_BSPRITE].ti_Tag == VTAG_BORDERSPRITE_SET) ? "On" : "Off"));
  223.                         switch (ti[OPT_RESOLUTION].ti_Data)
  224.                         {
  225.                             case SPRITERESN_140NS : res = "140ns"; break;
  226.                             case SPRITERESN_70NS : res = "70ns"; break;
  227.                             case SPRITERESN_35NS : res = "35ns"; break;
  228.                             case SPRITERESN_ECS : res = "ECS compatible"; break;
  229.                             default : res = "Default"; break;
  230.                         }
  231.                         printf("Resolution = %s\n", res);
  232.                         printf("Playfield 1 to Sprite Priority = %ld\n", ti[OPT_PF1].ti_Data);
  233.                         printf("Playfield 2 to Sprite Priority = %ld\n", ti[OPT_PF2].ti_Data);
  234.                         printf("Odd Sprite base = %ld\n", ti[OPT_SPODD].ti_Data);
  235.                         printf("Even Sprite base = %ld\n", ti[OPT_SPEVEN].ti_Data);
  236.                         printf("Playfield 1 base = %ld\n", ti[OPT_BASE1].ti_Data);
  237.                         printf("Playfield 2 base = %ld\n", ti[OPT_BASE2].ti_Data);
  238.                     }
  239.                 }
  240.             }
  241.             FreeArgs(rdargs);
  242.         }
  243.         UnlockPubScreen(NULL, wb);
  244.     }
  245.  
  246.     CloseAll () ;
  247. }
  248.