home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
drdobbs
/
1989
/
07
/
mcmanis.lst
< prev
next >
Wrap
File List
|
1989-06-01
|
8KB
|
258 lines
_MULTITASKING OS AND GRAPHICS COPROCESSORS_
by Chuck McManis
[LISTING ONE]
/* 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);
}
[LISTING TWO]
000208a8 2b01:fffe WAIT (00,2b) ; (x = 0, y = 43)
--- load color table ---
000208bc 008e:0581 MOVE 0581,diwstrt ; (left = 129, top = 5)
000208c0 0100:0200 MOVE 0200,bplcon0
000208c4 0104:0024 MOVE 0024,bplcon2
000208c8 0090:40c1 MOVE 40c1,diwstop ; (right = 449, bottom = 320)
000208cc 0092:0038 MOVE 0038,ddfstrt ; pixel val = 112
000208d0 0094:00d0 MOVE 00d0,ddfstop ; pixel val = 416
000208d4 0102:0000 MOVE 0000,bplcon1
000208d8 0108:0028 MOVE 0028,bpl1mod
000208dc 010a:0028 MOVE 0028,bpl2mod
000208e0 00e0:0002 MOVE 0002,bpl1pth
000208e4 00e2:86e8 MOVE 86e8,bpl1ptl
000208e8 00e4:0002 MOVE 0002,bpl2pth
000208ec 00e6:c568 MOVE c568,bpl2ptl
000208f0 2c01:fffe WAIT (00,2c) ; (x = 0, y = 44)
000208f4 0100:2200 MOVE 2200,bplcon0
000208f8 db01:fffe WAIT (00,db) ; (x = 0, y = 219)
000208fc 0100:0200 MOVE 0200,bplcon0
00020900 de01:fffe WAIT (00,de) ; (x = 0, y = 222)
--- load color table ---
00020914 008e:0581 MOVE 0581,diwstrt ; (left = 129, top = 5)
00020918 0100:0200 MOVE 0200,bplcon0
0002091c 0104:0024 MOVE 0024,bplcon2
00020920 0090:40c1 MOVE 40c1,diwstop ; (right = 449, bottom = 320)
00020924 0092:003c MOVE 003c,ddfstrt ; pixel val = 120
00020928 0094:00d0 MOVE 00d0,ddfstop ; pixel val = 416
0002092c 0102:0000 MOVE 0000,bplcon1
00020930 0108:0000 MOVE 0000,bpl1mod
00020934 010a:0000 MOVE 0000,bpl2mod
00020938 00e0:0002 MOVE 0002,bpl1pth
0002093c 00e2:86e8 MOVE 86e8,bpl1ptl
00020940 00e4:0002 MOVE 0002,bpl2pth
00020944 00e6:c568 MOVE c568,bpl2ptl
00020948 df01:fffe WAIT (00,df) ; (x = 0, y = 223)
0002094c 0100:a200 MOVE a200,bplcon0
00020950 f301:fffe WAIT (00,f3) ; (x = 0, y = 243)
00020954 0100:0200 MOVE 0200,bplcon0
00020958 ffff:fffe WAIT (7f,ff) ; (x = 127, y = 255)
[LISTING THREE]
/* blit.c - Demonstrates the benefit of the blitter.
* Written 4/9/89 by C. McManis using Lattice C 5.02
* The difference on my machine between waiting for the blitter
* to complete before calculating the next set of draw parameters
* is 1.6 vs 1.4 seconds, about a 12.5% increase in speed.
*/
#include <exec/types.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <graphics/gfx.h>
extern struct IntuitionBase *IntuitionBase;
extern struct GfxBase *GfxBase;
struct NewScreen NS = {
0, 0, /* Position on the display */
320, 200, 4, /* Attributes (Width, Height, Depth) */
1,0, /* Detail and Block pens */
0, /* ViewModes nothing special */
CUSTOMSCREEN, /* It is our own screen we want */
0, /* Using the Default font */
"Blitter Test", /* With a simple title. */
0, /* No special gadgets */
0 /* And no special bitmap */
};
struct Screen *MyScreen;
struct RastPort *RPort;
void
cleanup(n)
int n;
{
if (GfxBase)
CloseLibrary(GfxBase);
if (MyScreen)
CloseScreen(MyScreen);
if (IntuitionBase)
CloseLibrary(IntuitionBase);
exit(n);
}
void
main()
{
int i, /* Loop counter */
x, y, c, /* some random draw parameters */
t0[2], /* Start Time */
t1[2]; /* End time */
IntuitionBase = (struct IntuitionBase *)
OpenLibrary("intuition.library",0L);
if (! IntuitionBase)
cleanup(1);
GfxBase = (struct GfxBase *)
OpenLibrary("graphics.library", 0L);
if (! GfxBase)
cleanup(1);
/* This does all of the view construction for us */
MyScreen = (struct Screen *) OpenScreen(&NS);
if (!MyScreen)
cleanup(1);
timer(t0); /* Start the clock running */
/* Get the RastPort of this screen */
RPort = &(MyScreen->RastPort);
SetAPen(RPort, 1); /* Foreground pen = 1 */
SetBPen(RPort, 0); /* Background pen = 0 */
srand(42); /* set the seed */
Move(RPort, 160, 100); /* Move to the moiddle of the screen */
/*
* Note we generate psuedo random numbers (eg the same set of
* random numbers every time.
*/
for (i=0; i<1000; i++) {
x = (rand() % 300) + 10;
y = (rand() % 180) + 10;
c = rand() % 16;
SetAPen(RPort, c);
Draw(RPort, x, y);
#ifdef WAIT_BLIT
WaitBlit(); /* Simulate non-coprocessor */
#endif
}
timer(t1); /* stop the clock */
#ifdef WAIT_BLIT
printf("With waiting for the blitter, we took %d microseconds.\n",
(t1[0] - t0[0]) * 1000000 + (t1[1] - t0[1]));
#else
printf("Without waiting for the blitter, we took %d microseconds.\n",
(t1[0] - t0[0]) * 1000000 + (t1[1] - t0[1]));
#endif
cleanup(0);
}
Example 1. Sample Copper code
WAIT 0,261 ; Wait for line 261
MOVE COPR, INTREQ ; Interrupt the CPU
WAIT 0,$FFFE ; Wait until VBlank