🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #1472

Re: back to dual playfields under Intuition

#1472
From: Dana B Bourgeois
Date: Sat, 30 Sep 1989 07:31
260 lines
6331 bytes
[[ line-eater food ]]

Here is the example from the 1.2 Enhancer Manual.  Had a couple extra
hours and typed it in.  Enjoy!

Dana Bourgeois @ cup.portal.com
/********************************************************************

* Example program for Dual-Playfield Screens

*

* copyright Commodore-Amiga, Inc., Sept. 1986. use at will

* author: jim mackraz(amiga!jimm)
*********************************************************************

* Turn the workbench into dual playfield.

* You can use the same trick for your own screens,
* which is the recommended method for creating duall-playfield
* screens. (Please don't really do this to the Workbench.)
*
* Start with a new, single-playfield screen
* (don't set DUALPF in NewScreen.ViewModes)
* Allocate a second palyfield, set up a rastport for
* rendering into it, and install it into your open screen
* as shown here.  Intuition will never know about or use your
* second playfiled for its rendering(menus, gadgets, etc.).
* Be sure to remove evidence of your deed before CloseScreen().
*/

#define printf kprintf


struct Remember	*rememberkey=NULL;
struct Window	*getNewWind();

struct IntuitionBase	*IntuitionBase;
struct GfxBase		*GfxBase;

ULONG iflg=CLOSEWINDOW;

main()
{
	struct Intuimessage *msg;
	struct Window *window=NULL;
	WORD exitval=0;

/* hold data from *msg */
	ULONG class;

/* specific for this test */
	struct Screen *wbscreen;
	struct RasInfo *rinfo2=NULL; /* second playfield rasinfo*/
	struct BitMap *bmap2=NULL;   /* and bitmap              */
	struct RasPort *rport2=NULL; /* for rendering into bmap2*/
	BOOL it_is_done=FALSE;       /* success flag            */
	int counter=0;               /* for timing the visuals  */

	if(!(IntuitionBAse=(struct IntuitionBase*)
		OpenLibrary("intuition.library",0)))

	{
		printf("NO INTUITION LIBRARY 0);

		exitval=1;
		goto EXITING;
	}

	if(!(GfxBase=(struct GfxBase *)
		OpenLibrary("graphics.library",0)))

	{
		printf("NO GRAPHICS LIBRARY0);
		exitval=2;
		goto EXITING;
	}

/* get a window on the workbench */
	window=getNewWindow(320,20,300,50,flg,iflg);
	if(window==NULL)
	{
		printf("test:can't get window.0);
		exitval=1;
		goto EXITING;
	}

/*----- Add a second playfield for WorkBench-----*/

	wbscreen=window -> WScreen;	/*find it */

/* allocate seconde palyfield's rasinfo, bitmap, and bitplane */
	if(!rinfo2=(struct RasInfo *)
		AllocMem(sizeof(struct RasInfo),
		MEMF_PUBLIC|MEMF_CLEAR)))
	{
		printf("alloc rasinfo failed0);
		goto EXITING;
	}

	if(!(bmap2=struct BitMap *)
		AllocMem(sizeof(struct BitMap),
		MEMF_PUBLIC|MEMF_CLEAR)))
	{
		printf("aloc bitmap failed0);
		goto EXITING;
	}

	InitBitMap(bmap2,1,wbscreen -> Width,wbscreen -> Height);

/* we'll use 1 plane. */
	if (!(bmap2 -> Planes[0]=
		(UWORD *) AllocRaster(wbscreen -> Width,
		wbscreen -> Height)))
	{
		printf("alloc raster failed0);
		goto EXITING;
	}

/* get a tastport, and set it up for rendering into bmap2 */
	if(!(rport2=(struct RastPort *)
		AllocMem(sizeof(struct RastPort), MEMF_PUBLIC)))
	{
		printf("alloc rastport failed0);
		goto EXITING;
	}

	InitRastPort(rport2);
	rport2 -> BitMap=bmap2;

	SetRAst(rport2,0);

/* manhandle viewport: install second playfield and change modes */
	Forbid();
	rinfo2 -> BitMap=bmap2;/*install my bitmap in my rasinfo */

	wbscreen -> ViewPort.Modes | =DUALPF;
		/* convert viewport */

	it_is_done=TRUE;

	Permit();

/* set my foreground color */
	SetRGB4(&wbscreen->ViewPort,9,0,0xF,0);
/* color 9 is color 1 for second playfield of hi-res viewport */

/* put viewport changed into effect */
	MakeScreen(wbscreen);
	RethinkDisplay();

	drawSomething(rport2);

	printf("test program ok0);

	FOREVER
	{
		if ((msg=(struct IntuiMessage *) 
			GetMsg(window->UserPort))==NULL)
		{
			Wait(1<<window->UserPort->
				UserPort->mp_SigBit);
			continue;
		}

		class=msg->Class;
		ReplyMsg(msg);
		switch(class)
		{
		case CLOSEWINDOW:
			printf("event CLOSEWINDOW0);
			goto EXITING;
		default:
			printf("unknown event class%1x0,class);
		}
	}

EXITING:
/* clean up dual-playfield trick */
	if(it_is_done)
	{
		Forbid();
		wbscreen->ViewPort.RasInfo->Next=NULL;
		wbscreen->ViewPort.Modes &= DUALPF;
		Permit();
		MakeScreen(wbscreen);
		RethinkDisplay();
	}

	if(rport2)FreeMem(rport2,sizeof(struct RastPort));
	if(bmap2)
	{
		if(bmap2->Planes[0])
		{
			FreeRaster(bmap2->Planes[0],wbscreen->Width,
				 wbscreen->Height);
		}
		FreeMem(bmap2,sizeof(struct BitMap));
	}
	if(rinfo2)FreeMem(rinfo2,sizeof(struct RasInfo));

	if(window)CloseWindow(window);
	if(GfxBase)CloseLibrary(GfxBase);
	if(IntuitionBase)CloseLibrary(IntuitionBase);

	exit(exitval);
}

drawSomething(rp)
struct RastPort *rp;
{
	int width, height;
	int r,c;

	width=rp->BitMap->BytesPerRow*8;
	height=rp->BitMap->Rows;

	SetAPen(rp,1);

	for(r=0;r<height;r+=40)
		for(c=0;c<width;c+=40)
		{
			Move(rp,0,r);
			Draw(rp,c,0);
		}
}

struct Window * getNewWind(left,top,width,height,flg,iflg)
SHORT left, top, width, height;
ULONG flg, iflg;
{
	struct Window *OpenWindow();
	struct NewWindow nw;

	nw.LeftEdge=(SHORT)left;
	nw.TopEdge=(SHORT)top;
	nw.Width=(SHORT)width;
	nw.Height=(SHORT)height;
	nw.DetailPen=(UBYTE)-1;
	nw.BlockPen=(UBYTE)-1;
	nw.IDCMPFlags=(ULONG)iflg;

	nw.Flags=(ULONG)flg;

	nw.FirstGadget=(struct Gadget *)NULL;
	nw.CheckMark=(struct Image *)NULL;
	nw.Title=(UBYTE *)"DUAL Playfield Mode";
	nw.Screen=(struct Screen *)NULL;
	nw.BitMap=(struct BitMap *)NULL;
	nw.MinWidth=(struct BitMap *)NULL;
	nw.MInWidth=(SHORT)50;
	nw.MinHeight=(SHORT)30;
/* work around a bug */
	nw.MaxWidth=(SHORT)nw.Width;
	nw.MaxHeight=(SHORT)nw.Height;
	nw.Type=(SHORT)WBENCHSCREEN;

	return ((struct Window *)OpenWindow(&nw));
}
Technical Details
Message-ID: <22679@cup.portal.com>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!portal!cup.portal.com!FelineGrace
References: <20125@usc.edu> <20136@usc.edu> <3806@blake.acs.washington.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!portal!cup.portal.com!FelineGrace
From: FelineGrace@cup.portal.com (Dana B Bourgeois)
Newsgroups: comp.sys.amiga.tech
Subject: Re: back to dual playfields under Intuition
Message-ID: <22679@cup.portal.com>
Date: 30 Sep 89 07:31:24 GMT
References: <20125@usc.edu> <20136@usc.edu> <3806@blake.acs.washington.edu>
Distribution: na
Organization: The Portal System (TM)
Lines: 260