home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Orlando_1993 / Devcon93.3 / Graphics / wbtricks.c next >
Encoding:
C/C++ Source or Header  |  1993-01-05  |  7.9 KB  |  260 lines

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