home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / 3_1EXAM1.DMS / in.adf / intuition / 8hamdemo.c next >
Encoding:
C/C++ Source or Header  |  1993-11-17  |  8.8 KB  |  393 lines

  1. /*
  2.  * 8hamdemo.c - shows off 262144 colors simultaneously
  3.  *
  4.  * (c) Copyright 1992 Commodore-Amiga, Inc.  All rights reserved.
  5.  *
  6.  * This software is provided as-is and is subject to change; no warranties
  7.  * are made.  All use is at your own risk.  No liability or responsibility
  8.  * is assumed.
  9.  * 
  10.  */
  11.  
  12. #include <exec/types.h>
  13. #include <graphics/displayinfo.h>
  14. #include <intuition/intuition.h>
  15.  
  16. #include <clib/exec_protos.h>
  17. #include <clib/graphics_protos.h>
  18. #include <clib/diskfont_protos.h>
  19. #include <clib/intuition_protos.h>
  20.  
  21. /*----------------------------------------------------------------------*/
  22.  
  23. void error_exit(STRPTR errorstring);
  24.  
  25. int CXBRK(void) { return(0); }
  26. void chkabort(void) { return; }
  27.  
  28. /*----------------------------------------------------------------------*/
  29.  
  30. struct Library *DiskfontBase = NULL;
  31. struct GfxBase *GfxBase = NULL;
  32. struct IntuitionBase *IntuitionBase = NULL;
  33. struct Screen *myscreen = NULL;
  34. struct Window *mywindow = NULL;
  35. struct BitMap *bm[2] = {NULL,NULL};
  36. struct RastPort temprp;
  37. struct TextFont *font = NULL;
  38.  
  39. /*----------------------------------------------------------------------*/
  40.  
  41. UWORD pens[] =
  42. {
  43.     0, /* DETAILPEN */
  44.     1, /* BLOCKPEN    */
  45.     1, /* TEXTPEN    */
  46.     2, /* SHINEPEN    */
  47.     1, /* SHADOWPEN    */
  48.     3, /* FILLPEN    */
  49.     1, /* FILLTEXTPEN    */
  50.     0, /* BACKGROUNDPEN    */
  51.     2, /* HIGHLIGHTTEXTPEN    */
  52.  
  53.     1, /* BARDETAILPEN    */
  54.     2, /* BARBLOCKPEN    */
  55.     1, /* BARTRIMPEN    */
  56.  
  57.     ~0,
  58. };
  59.  
  60.  
  61. /* Color table to pass to SA_Colors32 or LoadRGB32() */
  62. ULONG colortable[] =
  63. {
  64.     0x00040000,    /* 5 colors to load, from zero */
  65.  
  66.     0xAAAAAAAA, 0xAAAAAAAA, 0xAAAAAAAA,    /* Gray */
  67.     0x00000000, 0x00000000, 0x00000000,    /* Black */
  68.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,    /* White */
  69.     0x66666666, 0x88888888, 0xBBBBBBBB,    /* Blue-gray */
  70.  
  71.     0x00000000,    /* terminator */
  72. };
  73.  
  74. /*----------------------------------------------------------------------*/
  75.  
  76. #define PLOTWIDTH 64
  77. #define PLOTHEIGHT 64
  78.  
  79.  
  80. /*----------------------------------------------------------------------*/
  81.  
  82. /* Let's arrange the blue values in a spiral, just to be cute.
  83.  * We'll do it with a table instead of an algorithm out of
  84.  * laziness.
  85.  */
  86. int bluespiral1[] =
  87. {
  88.     56, 55, 54, 53, 52, 51, 50, 49,
  89.     57, 30, 29, 28, 27, 26, 25, 48,
  90.     58, 31, 12, 11, 10,  9, 24, 47,
  91.     59, 32, 13,  2,  1,  8, 23, 46,
  92.     60, 33, 14,  3,  0,  7, 22, 45,
  93.     61, 34, 15,  4,  5,  6, 21, 44,
  94.     62, 35, 16, 17, 18, 19, 20, 43,
  95.     63, 36, 37, 38, 39, 40, 41, 42,
  96. };
  97.  
  98. int bluespiral2[] =
  99. {
  100.     60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45,
  101.     61, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 44,
  102.     62, 27,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 43,
  103.     63, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
  104. };
  105.  
  106. /*----------------------------------------------------------------------*/
  107.  
  108. struct TextAttr topaz80 =
  109. {
  110.     "topaz.font",
  111.     8,
  112.     0,
  113.     0,
  114. };
  115.  
  116. struct TextAttr preffont =
  117. {
  118.     "times.font",
  119.     15,
  120.     0,
  121.     0,
  122. };
  123.  
  124. #define MOD_BLUE    64
  125. #define MOD_RED        128
  126. #define MOD_GREEN    192
  127.  
  128. #define XOFF 6
  129. #define YOFF 5
  130.  
  131. main(argc, argv)
  132. int argc;
  133. char *argv[];
  134. {
  135.     int blue, x, ybase, column;
  136.     int redreverse, red, dred;
  137.     int left, top, width, height, b;
  138.     int perrow = 16;
  139.     int *bluespiral = bluespiral2;
  140.     struct TextAttr *scfont = &topaz80;
  141.  
  142.     ULONG displayID = NTSC_MONITOR_ID | SUPERHAMLACE_KEY;
  143.     int overscan = OSCAN_TEXT;
  144.  
  145.     if ( ( argc > 1 ) && ( *argv[1] == '?' ) )
  146.     {
  147.     printf("8HAMDemo [S|P|D|N]\n");
  148.     printf("- S = use Super72\n");
  149.     printf("- P = use PAL hires-lace\n");
  150.     printf("- D = use double-PAL hires-lace\n");
  151.     printf("- N = use NTSC superhires-lace [default]\n");
  152.     }
  153.     else
  154.     {
  155.     if ( ( argc > 1 ) && ( ( *argv[1] == 'D' ) || ( *argv[1] == 'd' ) ) )
  156.     {
  157.         displayID = DBLPALHIRESHAMFF_KEY;
  158.         overscan = OSCAN_MAX;
  159.         perrow = 8;
  160.             bluespiral = bluespiral1;
  161.     }
  162.  
  163.     if ( ( argc > 1 ) && ( ( *argv[1] == 'P' ) || ( *argv[1] == 'p' ) ) )
  164.     {
  165.         displayID = PAL_MONITOR_ID | HIRESHAMLACE_KEY;
  166.         overscan = OSCAN_MAX;
  167.         perrow = 8;
  168.             bluespiral = bluespiral1;
  169.     }
  170.  
  171.     if ( ( argc > 1 ) && ( ( *argv[1] == 'S' ) || ( *argv[1] == 's' ) ) )
  172.     {
  173.         displayID = 0x89824;
  174.         overscan = OSCAN_TEXT;
  175.         perrow = 8;
  176.             bluespiral = bluespiral1;
  177.     }
  178.  
  179.     if ( ( argc > 1 ) && ( ( *argv[1] == 'N' ) || ( *argv[1] == 'n' ) ) )
  180.     {
  181.         displayID = NTSC_MONITOR_ID | SUPERHAMLACE_KEY;
  182.         overscan = OSCAN_TEXT;
  183.         perrow = 16;
  184.             bluespiral = bluespiral2;
  185.     }
  186.  
  187.     if (!( GfxBase = (struct GfxBase *)
  188.         OpenLibrary("graphics.library", 39L) ))
  189.         {
  190.         error_exit("Couldn't open Gfx V39\n");
  191.         }
  192.  
  193.     if (!( IntuitionBase = (struct IntuitionBase *)
  194.         OpenLibrary("intuition.library", 39L) ))
  195.         {
  196.         error_exit("Couldn't open Intuition V39\n");
  197.         }
  198.  
  199.     if (!( DiskfontBase = (struct Library *)
  200.         OpenLibrary("diskfont.library", 37L) ))
  201.         {
  202.         error_exit("Couldn't open Diskfont V37\n");
  203.         }
  204.  
  205.     if ( font = OpenDiskFont( &preffont ) )
  206.     {
  207.         scfont = &preffont;
  208.     }
  209.  
  210.     InitRastPort( &temprp );
  211.     bm[0] = AllocBitMap( PLOTWIDTH, PLOTHEIGHT, 8, BMF_INTERLEAVED|BMF_CLEAR, NULL );
  212.     temprp.BitMap = bm[0];
  213.     for ( x=0; x<64; x++ )
  214.     {
  215.         SetAPen( &temprp, MOD_GREEN+x );
  216.         Move( &temprp, x, 0 );
  217.         Draw( &temprp, x, 63 );
  218.     }
  219.  
  220.     bm[1] = AllocBitMap( PLOTWIDTH, PLOTHEIGHT, 8, BMF_INTERLEAVED|BMF_CLEAR, NULL );
  221.     temprp.BitMap = bm[1];
  222.  
  223.     for ( x=0; x<64; x++ )
  224.     {
  225.         SetAPen( &temprp, MOD_GREEN+63-x );
  226.         Move( &temprp, x, 0 );
  227.         Draw( &temprp, x, 63 );
  228.     }
  229.  
  230.     if (!(myscreen = OpenScreenTags(NULL,
  231.         SA_DisplayID, displayID,
  232.         SA_Overscan, overscan,
  233.         /*  Other tags can go here: */
  234.         SA_Font, scfont,
  235.         SA_Depth, 8,
  236.         SA_AutoScroll, 1,
  237.         SA_Pens, pens,
  238.         SA_Interleaved, TRUE,
  239.         SA_Title, "8-plane HAM Demo",
  240.         SA_Colors32, colortable,
  241.         SA_Behind, TRUE,
  242.         TAG_DONE )))
  243.         {
  244.         error_exit("Couldn't open screen\n");
  245.         }
  246.  
  247.     width = 14 + (perrow*65);
  248.     height = 10 + scfont->ta_YSize + (64/perrow)*64;
  249.     left = ( myscreen->Width - width - scfont->ta_YSize - 2 ) / 2;
  250.     top = ( myscreen->Height - height ) / 2;
  251.  
  252.     if (!( mywindow = OpenWindowTags(NULL,
  253.         WA_Left, left,
  254.         WA_Top, top,
  255.         WA_Width, width,
  256.         WA_Height, height,
  257.         WA_MinWidth, 50,
  258.         WA_MinHeight, 40,
  259.         WA_MaxWidth, -1,
  260.         WA_MaxHeight, -1,
  261.         WA_IDCMP, CLOSEWINDOW|VANILLAKEY,
  262.         WA_DepthGadget, TRUE,
  263.         WA_DragBar, TRUE,
  264.         WA_Title, "262144 Colors!",
  265.         WA_CloseGadget, TRUE,
  266.         WA_NoCareRefresh, TRUE,
  267.         WA_SmartRefresh, TRUE,
  268.         WA_CustomScreen, myscreen,
  269.         WA_Activate, TRUE,
  270.         TAG_DONE ) ))
  271.         {
  272.         error_exit("Couldn't open window\n");
  273.         }
  274.  
  275.     b = 0;
  276.     ybase = 0;
  277.     column = 0;
  278.     redreverse=0;
  279.  
  280.     for ( blue = 0; blue < 64; blue++ )
  281.     {
  282.         if ( column == 0 )
  283.         {
  284.         int dy;
  285.  
  286.         SetAPen( mywindow->RPort, 1 );
  287.         Move( mywindow->RPort, XOFF-1, (YOFF+scfont->ta_YSize)+ybase );
  288.         Draw( mywindow->RPort, XOFF-1, (YOFF+scfont->ta_YSize)+ybase+63 );
  289.  
  290.         for ( dy = 0; dy < 64; dy++ )
  291.         {
  292.             if ( redreverse )
  293.             {
  294.             SetAPen( mywindow->RPort, MOD_RED + 63-dy );
  295.             }
  296.             else
  297.             {
  298.             SetAPen( mywindow->RPort, MOD_RED + dy );
  299.             }
  300.             WritePixel( mywindow->RPort, XOFF, (YOFF+scfont->ta_YSize)+ybase+dy );
  301.         }
  302.         }
  303.  
  304.         SetAPen( mywindow->RPort, MOD_BLUE+63-bluespiral[blue]);
  305.         Move( mywindow->RPort, XOFF+column*65+1, (YOFF+scfont->ta_YSize)+ybase );
  306.         Draw( mywindow->RPort, XOFF+column*65+1, (YOFF+scfont->ta_YSize)+ybase+63 );
  307.     
  308.         BltBitMapRastPort( bm[b], 0, 0,
  309.         mywindow->RPort, XOFF+column*65 + 2, (YOFF+scfont->ta_YSize)+ybase,
  310.         PLOTWIDTH, PLOTHEIGHT, 0xC0 );
  311.         b = 1-b;
  312.  
  313.         column++;
  314.         if ( column == perrow )
  315.         {
  316.         column = 0;
  317.         ybase += 64;
  318.         redreverse = 1-redreverse;
  319.         }
  320.     }
  321.     ScreenToFront( myscreen );
  322.     dred = 1; red = 0;
  323.     /* Exit on break or on any IntuiMessage */
  324.     while ( !( SetSignal(0,0) & ( ( 1 << mywindow->UserPort->mp_SigBit ) | SIGBREAKF_CTRL_C ) ) )
  325.     {
  326.         ScrollRaster( mywindow->RPort, 0, -1, XOFF, (YOFF+scfont->ta_YSize), XOFF, (YOFF+scfont->ta_YSize)+(4096/perrow)-1 );
  327.         SetAPen( mywindow->RPort, MOD_RED + red );
  328.         red += dred;
  329.         if ( red == -1 )
  330.         {
  331.         dred = 1;
  332.         red = 0;
  333.         }
  334.         else if (red == 64 )
  335.         {
  336.         red = 63;
  337.         dred = -1;
  338.         }
  339.         WritePixel( mywindow->RPort, XOFF, (YOFF+scfont->ta_YSize) );
  340.     }
  341.     }
  342.     error_exit(NULL);
  343. }
  344.  
  345.  
  346. /*----------------------------------------------------------------------*/
  347.  
  348. void error_exit(STRPTR errorstring)
  349.  
  350.     {
  351.     if (mywindow)
  352.     {
  353.     ScreenToBack(myscreen);
  354.     CloseWindow(mywindow);
  355.     }
  356.  
  357.     if (myscreen)
  358.     {
  359.     CloseScreen(myscreen);
  360.     }
  361.  
  362.     if ( bm[1] ) FreeBitMap( bm[1] );
  363.     if ( bm[0] ) FreeBitMap( bm[0] );
  364.  
  365.     if (font) CloseFont(font);
  366.  
  367.     if (DiskfontBase)
  368.     {
  369.     CloseLibrary(DiskfontBase);
  370.     }
  371.  
  372.     if (IntuitionBase)
  373.     {
  374.     CloseLibrary(IntuitionBase);
  375.     }
  376.  
  377.     if (GfxBase)
  378.     {
  379.     CloseLibrary(GfxBase);
  380.     }
  381.  
  382.     if (errorstring)
  383.     {
  384.     printf(errorstring);
  385.     exit(20);
  386.     }
  387.  
  388.     exit(0);
  389.     }
  390.  
  391.  
  392. /*----------------------------------------------------------------------*/
  393.