Article View: comp.sys.amiga.tech
Article #829Re: Copper Effects In C.
From: Chuck McManis
Date: Thu, 10 Aug 1989 19:14
Date: Thu, 10 Aug 1989 19:14
140 lines
4388 bytes
4388 bytes
In article <7741@charlie.OZ> (Shane Hyde) writes:
> I was wondering if there was anyone out there, who could tell me
>how to program copper effects in C on Amy. The ones I am specifically
>trying to do are color changes midway down the screen. I don't have any
>docs on the register assignments.
There are a couple of ways to do this, one is to much with UCopList et al
and the other is to simply set up two viewports with different colors.
Have the second one start where you want the colors to change. Then you
can MrgCop()/LoadView() and poof. I wrote a little program that did it
this way for the Dr. Dobbs article, 'cuz it's short I've included it below.
/*
* dualvp.c - Dual Viewports on the amiga
* Written 4/4/89 by C. McManis using Lattice C 5.02
*/
#include <exec/types.h>
#include <exec/memory.h>
#include <graphics/gfx.h>
#include <graphics/view.h>
#include <graphics/gfxbase.h>
#include <graphics/rastport.h>
extern struct GfxBase *GfxBase;
char *TextString = "Amiga Graphics Example";
/* Viewport 0 colors */
UWORD colors0[4] = {0xccc, 0x000, 0x0f0, 0x00f},
/* Viewport 1 colors */
colors1[4] = {0x0f0, 0xc0c, 0xf00, 0xfff};
void
_main()
{
struct View MyView, *OldView;
struct ViewPort Vp0, Vp1;
struct BitMap Bits;
struct RasInfo MyRaster;
struct RastPort rp;
int i;
/* Open the resident graphics library */
GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0L);
if (!GfxBase)
exit(1);
OldView = GfxBase->ActiView; /* Save this away */
/* Initialize the View structures */
InitView(&MyView);
InitVPort(&Vp0);
InitVPort(&Vp1);
Vp1.Next = NULL;
Vp0.Next = &Vp1; /* create a linked list of viewports */
MyView.ViewPort = &Vp0; /* With the first one being Vp0 */
/* Set up some display memory */
InitBitMap(&Bits, 2, 640, 200);
Bits.Planes[0] = (PLANEPTR)
AllocMem(2*RASSIZE(640, 200),MEMF_CHIP+MEMF_CLEAR);
Bits.Planes[1] = Bits.Planes[0] + RASSIZE(640, 200);
if (!Bits.Planes[0])
goto cleanup;
MyRaster.BitMap = &Bits;
MyRaster.RxOffset = 0;
MyRaster.RyOffset = 0;
MyRaster.Next = NULL;
/* Both viewports are looking at the same display memory but have
* different sets of colors
*/
Vp0.RasInfo = &MyRaster;
Vp0.DWidth = 320;
Vp0.DHeight = 175;
Vp0.ColorMap = (struct ColorMap *)GetColorMap(4);
LoadRGB4(&Vp0, colors0, 4);
Vp1.RasInfo = &MyRaster;
Vp1.DWidth = 640;
Vp1.DHeight = 20;
Vp1.DyOffset = 179;
Vp1.Modes = HIRES;
Vp1.ColorMap = (struct ColorMap *)GetColorMap(4);
LoadRGB4(&Vp1, colors1, 4);
/* Initialize a RastPort so that we can draw into that memory. */
InitRastPort(&rp);
rp.BitMap = &Bits;
SetAPen(&rp, 1); /* Foreground color */
SetBPen(&rp, 0); /* Background color */
Move(&rp, 3, 12); /* Move the graphics cursor to (3, 12) */
/* Write something */
Text(&rp, TextString, strlen(TextString));
MakeVPort(&MyView, &Vp0); /* Build the copper list for Viewport 0 */
MakeVPort(&MyView, &Vp1); /* Build the copper list for Viewport 1 */
MrgCop(&MyView); /* Merge it into the final list */
LoadView(&MyView); /* Show it off */
/* SPIN FOR A WHILE */
for (i=0; i<1000000; i++)
;
LoadView(OldView); /* Return to the old view */
cleanup:
/* Now give back the memory other tasks may need it */
if (!Vp0.ColorMap)
FreeColorMap(Vp0.ColorMap);
if (!Vp1.ColorMap)
FreeColorMap(Vp1.ColorMap);
FreeVPortCopLists(&Vp0);
FreeVPortCopLists(&Vp1);
FreeCprList(MyView.LOFCprList);
if (!Bits.Planes[0])
FreeMem(Bits.Planes[0], 2*RASSIZE(640, 200));
if (!GfxBase)
CloseLibrary(GfxBase);
exit(0);
}
--Chuck McManis
uucp: {anywhere}!sun!cmcmanis BIX: cmcmanis ARPAnet: cmcmanis@sun.com
These opinions are my own and no one elses, but you knew that didn't you.
"A most excellent barbarian ... Genghis Kahn!"
Technical Details
Message-ID:
<120748@sun.Eng.Sun.COM>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!tut.cis.ohio-state.edu!brutus.cs.uiuc.edu!apple!sun-barr!sun!pepper!cmcmanisReferences:
<7741@charlie.OZ>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!tut.cis.ohio-state.edu!brutus.cs.uiuc.edu!apple!sun-barr!sun!pepper!cmcmanis From: cmcmanis%pepper@Sun.COM (Chuck McManis) Newsgroups: comp.sys.amiga.tech Subject: Re: Copper Effects In C. Message-ID: <120748@sun.Eng.Sun.COM> Date: 10 Aug 89 19:14:42 GMT References: <7741@charlie.OZ> Sender: news@sun.Eng.Sun.COM Reply-To: cmcmanis@sun.UUCP (Chuck McManis) Organization: Sun Microsystems, Mountain View Lines: 140