home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / CBMDevKit3.dms / CBMDevKit3.adf / graphics / wbtricks.c next >
Encoding:
C/C++ Source or Header  |  1993-11-17  |  7.7 KB  |  253 lines

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