home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.1 / JimmDemos / DemoSource / cpr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  5.7 KB  |  298 lines

  1. /*
  2.  * cpr.c --  experiment with user copper lists
  3.  * Copyright (c) 1988, I and I Computing, and Commodore-Amiga, Inc.
  4.  *
  5.  *
  6.  * Executables based on this information may be used in software
  7.  * for Commodore Amiga computers.  All other rights reserved.
  8.  *
  9.  * This information is provided "as is"; no warranties are made.
  10.  * All use is at your own risk, and no liability or responsibility is assumed.
  11.  */
  12.  
  13. #include "sysall.h"
  14. #include "getargs.h"
  15.  
  16. /* debug */
  17. #define D( x )     ;
  18.  
  19. struct Screen *screen = NULL;
  20. struct ViewPort *vp = NULL;
  21. struct UCopList    *ucl = NULL;
  22.  
  23. int        which_demo = 0;
  24.  
  25. struct Arg myargs[] = {
  26.     {'w', ARG_TINT, &which_demo, "0-colors, 1-wait/move, 2-bitplanes"},
  27. };
  28.  
  29. main(argc, argv)
  30. char    **argv;
  31. {
  32.     void *AllocMem();
  33.     long int i;
  34.     struct UCopList    *oldwbucl;
  35.     struct Window *awindow;
  36.     struct Window *AWindow();
  37.  
  38.     OpenI( 33 );
  39.     OpenGfx( 33 );
  40.  
  41.     /* hope we'll get the workbench    */
  42.     if ( !( awindow = AWindow() ) )
  43.     {
  44.         printf( "no active window!\n" );
  45.         goto OUT;
  46.     }
  47.  
  48.     if ( getargs( argv, myargs, NUMARGS( myargs ), NULL ) < 0 ) goto OUT;
  49.  
  50.     screen = awindow->WScreen;
  51.     vp = &screen->ViewPort;
  52.     oldwbucl = vp->UCopIns;    /* save previous    */
  53.  
  54.     D( printf("largest hpos: %d, or %d lores pixels\n", 0xe2, 0xe2<<1) );
  55.     D( printf("Custom base at %lx\n", &custom) );
  56.     D( printf("Color0 at %lx\n", &custom.color[0]) );
  57.  
  58.     /* i will free this myself    */
  59.     if ( !(ucl = AllocMem( (LONG) sizeof (struct UCopList), 
  60.         (LONG) MEMF_CHIP | (LONG) MEMF_CLEAR) )) goto OUT;
  61.  
  62.     CINIT( ucl, 400L );
  63.  
  64.     switch ( which_demo )
  65.     {
  66.     case 0:
  67.         colorsCopList( ucl );
  68.         break;
  69.     case 1:
  70.         waitmoveCopList( ucl );
  71.         break;
  72.     case 2:
  73.         bplCopList( ucl, screen );
  74.         break;
  75.     default:
  76.         printf("arg out of range\n");
  77.         break;
  78.     }
  79.  
  80.     CEND( ucl );
  81.  
  82.     vp->UCopIns = ucl;
  83.     D( dumpUCL( ucl ) );
  84.  
  85.     MakeScreen( screen );
  86.     RethinkDisplay();
  87.  
  88.     printf("cool?\n");
  89.     getchar();
  90.  
  91. OUT:
  92.     /* put him back    */
  93.     if (screen)
  94.     {
  95.         vp->UCopIns = oldwbucl;
  96.         MakeScreen( screen );
  97.         RethinkDisplay();
  98.     }
  99.  
  100.     if ( ucl )
  101.     {
  102.         FreeCopList( ucl->FirstCopList );
  103.         FreeMem( ucl, (LONG) sizeof (struct UCopList) );
  104.     }
  105.  
  106.     CloseI();
  107.     CloseGfx();
  108.  
  109.     printf("bye.\n");
  110. }
  111.  
  112. /* recall format:
  113.  *    CWAIT( ucl, vbeam, hbeam )
  114.  *    CMOVE( ucl, register, value )
  115.  */
  116.  
  117. #define HWAIT2    (0)
  118.  
  119. /* macros for specifying bitplane pointer registers    */
  120. #define BPLPTH( p )         (*((UWORD *) &custom.bplpt[0] + (2 * ((p) - 1))))
  121. #define BPLPTL( p )         (*((UWORD *) &custom.bplpt[0] + (2 * ((p) - 1)) + 1))
  122.  
  123. /*
  124.  * demonstrate technique of changing bitplane pointers on the fly.
  125.  * only works with 2 bitplane screen
  126.  */
  127. bplCopList( ucl, screen )
  128. struct UCopList *ucl;
  129. struct Screen *screen;
  130. {
  131.     int        splitline;
  132.     struct BitMap    *bmap = &screen->BitMap;
  133.     long    planeaddr;
  134.  
  135.     splitline = 140;
  136.  
  137.     planeaddr = (long) bmap->Planes[ 0 ];
  138.     CWAIT( ucl, (long) splitline, (long) HWAIT2 );
  139.     CMOVE( ucl, BPLPTH( 1 ), (long) (planeaddr >> 16) & 0xffff );
  140.     CMOVE( ucl, BPLPTL( 1 ), (long) planeaddr & 0xffff );
  141.  
  142.     planeaddr = (long) bmap->Planes[ 1 ];
  143.     CMOVE( ucl, BPLPTH( 2 ), (long) (planeaddr >> 16) & 0xffff );
  144.     CMOVE( ucl, BPLPTL( 2 ), (long) planeaddr & 0xffff );
  145. }
  146.  
  147.  
  148. #define RED        (0x0f00)
  149. #define GREEN    (0x00f0)
  150. #define BLUE    (0x000f)
  151.  
  152. #define HWAIT1    (0x3e)
  153.  
  154. /*
  155.  * visually demonstrate the amounts of time taken by wait and move
  156.  * copper instructions.  Note that MakeVPort() will eliminate wait
  157.  * instructions that it deems to be irrelevant.
  158.  */
  159. waitmoveCopList( ucl )
  160. struct UCopList *ucl;
  161. {
  162.     CWAIT( ucl, (long) 100, (long) HWAIT1 );
  163.     CMOVE( ucl, custom.color[ 0 ], (long) RED );
  164.     CWAIT( ucl, (long) 100, (long) HWAIT1 + 1 );
  165.     CMOVE( ucl, custom.color[ 0 ], (long) GREEN );
  166.     CWAIT( ucl, (long) 100, (long) HWAIT1 + 2 );
  167.     CMOVE( ucl, custom.color[ 0 ], (long) BLUE );
  168.  
  169.     CWAIT( ucl, (long) 101, (long) HWAIT1 );
  170.     CMOVE( ucl, custom.color[ 0 ], (long) RED );
  171.     CMOVE( ucl, custom.color[ 0 ], (long) GREEN );
  172.     CMOVE( ucl, custom.color[ 0 ], (long) BLUE );
  173. }
  174.  
  175. /*
  176.  * change the background color every display row
  177.  */
  178. colorsCopList( ucl )
  179. struct UCopList *ucl;
  180. {
  181.     int        row;
  182.     int        numlines;
  183.  
  184.     numlines = screen->Height;
  185.  
  186.  
  187.     clLineColor( ucl, 0, 1, 0xf );
  188.     for (row = 0; row < numlines; ++row)
  189.     {
  190.         clLineColor( ucl, row + 1, 0, funcolor( row ) );
  191.     }
  192. }
  193.  
  194. #define FUNCOL( x, y, z) (((x)<<8)+((y)<<4)+(z))
  195.  
  196.  
  197. funcolor( num )
  198. {
  199.     int    inc;
  200.     int    dec;
  201.     int    block;
  202.     int    funcol;
  203.  
  204. #if JUST_BLUE
  205.     return (num & 0xf);
  206. #endif
  207.  
  208.     inc = num & 0xf;
  209.     dec = 0xf - inc;
  210.  
  211.     block =  (num >> 4) % 6;
  212.  
  213.     switch ( block )
  214.     {
  215.     case 0:
  216.         funcol = FUNCOL( inc, 0xf, dec);
  217.         break;
  218.     case 1:
  219.         funcol = FUNCOL( 0xf, dec, inc);
  220.         break;
  221.     case 2:
  222.         funcol = FUNCOL( dec, inc, 0xf);
  223.         break;
  224.     case 3:
  225.         funcol = FUNCOL( inc, dec, 0xf);
  226.         break;
  227.     case 4:
  228.         funcol = FUNCOL( 0xf, inc, dec);
  229.         break;
  230.     case 5:
  231.         funcol = FUNCOL( dec, 0xf, inc);
  232.         break;
  233.     }
  234.     return( funcol );
  235. }
  236.  
  237. #define HLINESTART (0L)
  238.  
  239. clLineColor( ucl, line, pen, color)
  240. struct UCopList *ucl;
  241. {
  242.     CWAIT( ucl, (long) line, HLINESTART)
  243.     CMOVE( ucl, custom.color[ pen ], (long) color);
  244. }
  245.  
  246.  
  247. dumpUCL( ucl )
  248. struct UCopList *ucl;
  249. {
  250.     printf("UCL at %lx\n", ucl);
  251.     if (ucl)
  252.     {
  253.         printf("FirstCL: %lx\n", ucl->FirstCopList);
  254.         printf("CurrentCL: %lx\n", ucl->CopList);
  255.  
  256.         dumpCL( ucl->FirstCopList );
  257.     }
  258. }
  259.  
  260. dumpCL( cl )
  261. struct CopList    *cl;
  262. {
  263.     int i;
  264.     printf("CopList at %lx\n", cl);
  265.  
  266.     for( i = 0 ; cl && ++i < 10; cl = cl->Next)
  267.     {
  268.         printf("CopIns block at %lx, count %d\n", cl->CopIns, cl->MaxCount);
  269.         dumpCIns( cl->CopIns, cl->MaxCount );
  270.     }
  271. }
  272.  
  273. dumpCIns( ci, num )
  274. struct CopIns *ci;
  275. {
  276.     while (num--)
  277.     {
  278.         switch (ci->OpCode)
  279.         {
  280.         case COPPER_MOVE:
  281.             printf("CMOVE\t0x%x\t0x%x\n", ci->DESTADDR, ci->DESTDATA);
  282.             break;
  283.         case COPPER_WAIT:
  284.             printf("CWAIT\t%d\t%d\n", ci->VWAITPOS, ci->HWAITPOS);
  285.             break;
  286.         case CPRNXTBUF:
  287.             printf("NXTBUF\t\t%lx\n", ci->NXTLIST);
  288.             break;
  289.         default:
  290.             printf("unknown copper instruction: %x, (%x, %x)\n",
  291.                 ci->OpCode, ci->DESTADDR, ci->DESTDATA);
  292.  
  293.             return;
  294.         }
  295.         ++ci;
  296.     }
  297. }
  298.