home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377a.lha / libraries / graphics / primitives / uCopperExample.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-02-04  |  4.8 KB  |  151 lines

  1. /*  UserCopperExample
  2.     User Copper List Example
  3.     For Lattice, compile and link with:  LC -b1 -cfist -L -v -y uCopperExample.c
  4.  
  5.    Copyright (c) 1990 Commodore-Amiga, Inc.
  6.   
  7.    This example is provided in electronic form by Commodore-Amiga, Inc. for
  8.    use with the 1.3 revisions of the Addison-Wesley Amiga reference manuals. 
  9.    The 1.3 Addison-Wesley Amiga Reference Manual series contains additional
  10.    information on the correct usage of the techniques and operating system
  11.    functions presented in this example.  The source and executable code of
  12.    this example may only be distributed in free electronic form, via bulletin
  13.    board or as part of a fully non-commercial and freely redistributable
  14.    diskette.  Both the source and executable code (including comments) must
  15.    be included, without modification, in any copy.  This example may not be
  16.    published in printed form or distributed with any commercial product.
  17.    However, the programming techniques and support routines set forth in
  18.    this example may be used in the development of original executable
  19.    software products for Commodore Amiga computers.
  20.    All other rights reserved.
  21.    This example is provided "as-is" and is subject to change; no warranties
  22.    are made.  All use is at your own risk.  No liability or responsibility
  23.    is assumed.
  24. */
  25.  
  26. #include <exec/types.h>
  27. #include <exec/memory.h>
  28. #include <graphics/gfxbase.h>
  29. #include <graphics/gfxmacros.h>
  30. #include <graphics/copper.h>
  31. #include <intuition/intuition.h>
  32. #include <hardware/custom.h>
  33. #include <libraries/dos.h>
  34.  
  35. #include <proto/all.h>
  36. #include <stdlib.h>
  37.  
  38. /*  Use this structure to gain access to the custom registers.  */
  39. extern struct Custom far custom;
  40.  
  41. VOID openAll(VOID), cleanExit(int);
  42. BOOL loadCopper(VOID);
  43.  
  44. struct IntuitionBase  *IntuitionBase = NULL;
  45. struct GfxBase        *GfxBase = NULL;
  46. struct Window         *window = NULL;
  47. struct IntuiMessage   *intuiMessage;
  48. struct ViewPort       *viewPort = NULL;
  49. struct UCopList       *uCopList = NULL;
  50.  
  51. struct  NewWindow  newWindow =
  52. {
  53.     40,0,          /* Upper Left Corner */
  54.     175,10,        /* Width and Height */
  55.     -1,-1,         /* Use screen default pens */
  56.     CLOSEWINDOW,   /* IDCMP flags */
  57.     WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|NOCAREREFRESH, /* Flags */
  58.     NULL,          /* no gadgets */
  59.     NULL,          /* use default checkmark image */
  60.     "Copper!",     /* Title */
  61.     NULL,          /* using WorkBench screen */
  62.     NULL,          /* no super-bitmap */
  63.     0,0,0,0,       /* no sizing */
  64.     WBENCHSCREEN   /* it goes on the WorkBench screen */
  65. };
  66.  
  67. #define NUMCOLORS      32
  68. #define NUMLINES_EACH   8
  69.  
  70. UWORD  colors[] =
  71. {
  72.       0x0604, 0x0605, 0x0606, 0x0607, 0x0617, 0x0618, 0x0619,
  73.       0x0629, 0x072a, 0x073b, 0x074b, 0x074c, 0x075d, 0x076e,
  74.       0x077e, 0x088f, 0x07af, 0x06cf, 0x05ff, 0x04fb, 0x04f7,
  75.       0x03f3, 0x07f2, 0x0bf1, 0x0ff0, 0x0fc0, 0x0ea0, 0x0e80,
  76.       0x0e60, 0x0d40, 0x0d20, 0x0d00
  77. };
  78.  
  79.  
  80. VOID main(VOID)
  81. {
  82. openAll();    /* Open the libraries and a window. */
  83. if (loadCopper())    /* Do the Copper specific stuff. */
  84.     {
  85.     /* Wait until the user clicks in the close gadget */
  86.     (VOID) Wait(1<<window->UserPort->mp_SigBit);
  87.     while (intuiMessage = (struct IntuiMessage *)GetMsg(window->UserPort)) 
  88.         ReplyMsg((struct Message *)intuiMessage);
  89.  
  90.     }
  91. cleanExit(RETURN_OK);
  92. }
  93.  
  94.  
  95. VOID openAll(VOID)
  96. {
  97. IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library", 33L);
  98. if (IntuitionBase == NULL)
  99.     cleanExit(ERROR_INVALID_RESIDENT_LIBRARY);
  100. GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 33L);
  101. if (GfxBase == NULL)
  102.     cleanExit(ERROR_INVALID_RESIDENT_LIBRARY);
  103. if (! (window = OpenWindow(&newWindow)))    /* Open a Window. */
  104.     cleanExit(ERROR_NO_FREE_STORE);
  105. viewPort = ViewPortAddress(window);    /* Get a pointer to the ViewPort. */
  106. }
  107.  
  108.  
  109. VOID cleanExit(int retval)
  110. {
  111. if (uCopList)    /* Free the memory allocated for the Copper. */
  112.     {
  113.     FreeVPortCopLists(viewPort);
  114.     RemakeDisplay();
  115.     }
  116. if (window)
  117.     CloseWindow(window);
  118. if (IntuitionBase)
  119.     CloseLibrary((struct Library *)IntuitionBase);
  120. if (GfxBase)
  121.     CloseLibrary((struct Library *)GfxBase);
  122. exit(retval);
  123. }
  124.  
  125.  
  126. BOOL loadCopper(VOID)
  127. {
  128. register USHORT i;
  129.  
  130. /* Allocate memory for the Copper list */
  131. /* Make certain that the initial memory is cleared.  */
  132. uCopList = (struct UCopList *)
  133.   AllocMem(sizeof(struct UCopList), MEMF_PUBLIC|MEMF_CLEAR);
  134. if (uCopList == NULL)
  135.     return(FALSE);
  136. CINIT(uCopList, NUMCOLORS);   /* Initialize the Copper list buffer. */
  137. for (i=0; i<NUMCOLORS; i++)    /* Load in each color. */
  138.     { 
  139.     CWAIT(uCopList, (i*NUMLINES_EACH), 0);
  140.     CMOVE(uCopList, custom.color[0], colors[i]);
  141.     }
  142. CEND(uCopList);    /* End the Copper list */
  143. /*  Forbid task switching while changing the Copper list. */
  144. Forbid();
  145. viewPort->UCopIns=uCopList;
  146. Permit();    /* Permit task switching again. */
  147. RethinkDisplay();    /* Display the new Copper list. */
  148. return(TRUE);
  149. }
  150.  
  151.