[comp.sys.mac.programmer] THINK C & 32-bit quickdraw

oster@dewey.soe.berkeley.edu (David Phillip Oster) (11/12/89)

As my way of saying thank you, here are the interfaces for 32-bit
Quickdraw for THINK C.  You  may want to save this file and upload it,
since it contains tabs and fairly long lines.:

> The mac is a detour in the inevitable march of mediocre computers.
> drs@bnlux0.bnl.gov (David R. Stampf)
--- David Phillip Oster          -master of the ad hoc odd hack. 
Arpa: oster@dewey.soe.berkeley.edu 
Uucp: {uwvax,decvax}!ucbvax!oster%dewey.soe.berkeley.edu 

(cut here, call this QuickDraw32Bit.h).
/* let's get a real juicy 32 bit discussion going based on this maybe !!
   by bhamlin@well.sf.ca.us (Brian M. Hamlin)
   from oster@well.sf.ca.us (David Phillip Oster)
 */

/* I think that's it - check it out, write something fun. Remember: You 
	don't have to have a 32bit video card, just Sys 6.0.3 or greater on 
	a color-capable machine and the 32bit Quickdraw INIT in your system 
	folder to use these calls !
 */
/* hoo-boy, well ANYWAY thanks to Sam Roberts for assembler tweaking. */


#ifndef _QuickDraw32Bit_
#define _QuickDraw32Bit_

#ifndef _Quickdraw_
#include <Quickdraw.h>
#endif

#ifndef _Color_
#include <Color.h>
#endif

/* New Constants for 32-Bit QuickDraw */

#define ditherCopy 64		/* Dither mode for Copybits */
#define RGBDirect 16		/* 16 & 32 bits/pixel pixelType value */


/* New error codes */

#define rgnOverflowErr -147			/* Region accumulation failed. Resulting region may be currupt */
#define pixmapTooDeepErr -148		/* Pixmap is not 1-bit/pixel for BitmapToRegion */
#define insufficientStackErr -149	/* QuickDraw could not complete the operation */
#define cDepthErr -157		 		/* invalid pixel depth passed to NewGWorld or UpdateGWorld */


#define	pixPurgeMask		1
#define	noNewDeviceMask		2

/* Flag bits passed to or returned by Offscreen routines */

enum  {
	pixPurgeBit = 0,
	nowNewDeviceBit = 1,
	pixelsPurgeableBit = 6,
	pixelsLockedBit = 7,

	mapPixBit = 16,			/* set if color table mapping occurred */
	newDepthBit = 17,		/* set if pixels were scaled to a different depth */
	alignPixBit = 18,		/* set if pixels were realigned to screen alignment */
	newRowBytesBit = 19,	/* set if pixmap was reconfigured in a new rowBytes */
	reallocPixBit = 20,		/* set if offscreen buffer had to be reallocated */
	clipPixBit = 28,		/* set if pixels were or are to be clipped */
	stretchPixBit = 29,		/* set if pixels were or are to be stretched/shrinked */
	ditherPixBit = 30,
	gwFlagErrBit = 31
};

typedef enum {
	pixPurge = 1L << pixPurgeBit,
	nowNewDevice = 1L << nowNewDeviceBit,
	pixelsPurgeable = 1L << pixelsPurgeableBit,
	pixelsLocked = 1L << pixelsLockedBit,
	mapPix = 1L << mapPixBit,
	newDepth = 1L << newDepthBit,
	alignPix = 1L << alignPixBit,
	newRowBytes = 1L << newRowBytesBit,
	reallocPix = 1L << reallocPixBit,
	clipPix = 1L << clipPixBit,
	stretchPix = 1L << stretchPixBit,
	ditherPix = 1L << ditherPixBit,
	gwFlagErr = 1L << gwFlagErrBit
}GWorldFlag;

typedef long GWorldFlags;

/* Type definition of a GWorldPtr */

typedef CGrafPtr GWorldPtr;


/* Function Prototypes (necessary to get automatic type coercion -- see LSC User's Manual p.125)
 */
pascal OSErr	BitmapToRegion(RgnHandle, BitMap *);
pascal QDErr	NewGWorld(GWorldPtr *, short, Rect *, CTabHandle, GDHandle, GWorldFlags);
pascal Boolean	LockPixels(PixMapHandle);
pascal void		UnlockPixels(PixMapHandle);
pascal GWorldFlags	UpdateGWorld(GWorldPtr *, short, Rect *, CTabHandle, GDHandle, GWorldFlags);
pascal void		DisposeGWorld(GWorldPtr);
pascal void		GetGWorld(CGrafPtr *, GDHandle *);
pascal void		SetGWorld(CGrafPtr, GDHandle);
pascal void		CTabChanged(CTabHandle);
pascal void		PixPatChanged(PixPatHandle);
pascal void		PortChanged(GrafPtr);
pascal void		GDeviceChanged(GDHandle);
pascal void		AllowPurgePixels(PixMapHandle);
pascal void		NoPurgePixels(PixMapHandle);
pascal GWorldFlags	GetPixelsState(PixMapHandle);
pascal void		SetPixelsState(PixMapHandle, GWorldFlags);
pascal Ptr		GetPixBaseAddr(PixMapHandle);
pascal QDErr	NewScreenBuffer(Rect *, Boolean, GDHandle *, PixMapHandle *);
pascal void		DisposeScreenBuffer(PixMapHandle);
pascal GDHandle	GetGWorldDevice(GWorldPtr);

#endif

oster@dewey.soe.berkeley.edu (David Phillip Oster) (11/12/89)

As my way of saying thank you, here are the interfaces for 32-bit
Quickdraw for THINK C. You can save this, compile it, then get at
all the 32-bit quickdraw traps from THINK C.
You  may want to save this file and upload it, since it contains tabs 
and fairly long lines.:
 
> The mac is a detour in the inevitable march of mediocre computers.
> drs@bnlux0.bnl.gov (David R. Stampf)
--- David Phillip Oster          -master of the ad hoc odd hack.
Arpa: oster@dewey.soe.berkeley.edu
Uucp: {uwvax,decvax}!ucbvax!oster%dewey.soe.berkeley.edu
 
(cut here, call this QuickDraw32Bit.c).
#include <QuickDraw32Bit.h>

/* let's get a real juicy 32 bit discussion going based on this maybe !!
   by bhamlin@well.sf.ca.us (Brian M. Hamlin)
   from oster@well.sf.ca.us (David Phillip Oster)
 */

/* BitmapToRegion - 
 */
pascal OSErr BitmapToRegion(region, bmap)
	RgnHandle	region;
	BitMap		*bmap;{

	asm {
		SUBQ.L	#2,SP
		MOVE.L	region(A6),-(SP)
		MOVE.L	bmap(A6),-(SP)
		DC.W	0xA8D7
		MOVE.W	(SP)+,D0
	}
}

/* NewGWorld - 
 */
pascal QDErr NewGWorld(offscreenGWorld, pixelDepth, boundsRect, cTable, aGDevice, flags)
	GWorldPtr		*offscreenGWorld;
	short			pixelDepth;
	Rect			*boundsRect;
	CTabHandle		cTable;
	GDHandle		aGDevice;
	GWorldFlags		flags;{

	asm {
		SUBQ.L	#2,SP
		MOVE.L	offscreenGWorld(A6),-(SP)
		MOVE.W	pixelDepth(A6),-(SP)
		MOVE.L	boundsRect(A6),-(SP)
		MOVE.L	cTable(A6),-(SP)
		MOVE.L	aGDevice(A6),-(SP)
		MOVE.L	flags(A6),-(SP)
		MOVEQ	#0,D0
		DC.W	0xAB1D
		MOVE.W	(SP)+,D0
	}
}

/* LockPixels - 
 */
pascal Boolean LockPixels(pm)PixMapHandle	pm;{
	asm {
		SUBQ.L	#2,SP
		MOVE.L	pm(A6),-(SP)
		MOVEQ	#1,D0
		DC.W	0xAB1D
		MOVE.B	(SP)+,D0
	}
}

/* UnlockPixels - 
 */
pascal void UnlockPixels(pm)PixMapHandle	pm;{
	asm {
		MOVE.L	pm(A6),-(SP)
		MOVEQ	#2,D0
		DC.W	0xAB1D
	}
}

/* UpdateGWorld - 
 */
pascal GWorldFlags UpdateGWorld(offscreenGWorld, pixelDepth, boundsRect, cTable, aGDevice, flags)
	GWorldPtr		*offscreenGWorld;
	short			pixelDepth;
	Rect			*boundsRect;
	CTabHandle		cTable;
	GDHandle		aGDevice;
	GWorldFlags		flags;{

	asm {
		SUBQ.L	#4,SP
		MOVE.L	offscreenGWorld(A6),-(SP)
		MOVE.W	pixelDepth(A6),-(SP)
		MOVE.L	boundsRect(A6),-(SP)
		MOVE.L	cTable(A6),-(SP)
		MOVE.L	aGDevice(A6),-(SP)
		MOVE.L	flags(A6),-(SP)
		MOVEQ	#3,D0
		DC.W	0xAB1D
		MOVE.L	(SP)+,D0
	}
}

/* DisposeGWorld - 
 */
pascal void DisposeGWorld(offscreenGWorld)GWorldPtr offscreenGWorld;{
	asm {
		MOVE.L	offscreenGWorld(A6),-(SP)
		MOVEQ	#4,D0
		DC.W	0xAB1D
	}
}

/* GetGWorld - 
 */
pascal void GetGWorld(port, gdh)CGrafPtr *port;GDHandle *gdh;{
	asm {
		MOVE.L	port(A6),-(SP)
		MOVE.L	gdh(A6),-(SP)
		MOVEQ	#5,D0
		DC.W	0xAB1D
	}
}

/* SetGWorld - 
 */
pascal void SetGWorld(port, gdh)CGrafPtr port;GDHandle gdh;{
	asm {
		MOVE.L	port(A6),-(SP)
		MOVE.L	gdh(A6),-(SP)
		MOVEQ	#6,D0
		DC.W	0xAB1D
	}
}

/* CTabChanged - 
 */
pascal void CTabChanged(ctab)CTabHandle	ctab;{
	asm {
		MOVE.L	ctab(A6),-(SP)
		MOVEQ		#7,D0
		DC.W		0xAB1D
	}
}

/* PixPatChanged - 
 */
pascal void PixPatChanged(ppat)PixPatHandle	ppat;{
	asm {
		MOVE.L	ppat(A6),-(SP)
		MOVEQ	#8,D0
		DC.W	0xAB1D
	}
}

/* PortChanged - 
 */
pascal void PortChanged(port)GrafPtr port;{
	asm {
		MOVE.L	port(A6),-(SP)
		MOVEQ	#9,D0
		DC.W	0xAB1D
	}
}

/* GDeviceChanged - 
 */
pascal void GDeviceChanged(gdh)GDHandle gdh;{
	asm {
		MOVE.L	gdh(A6),-(SP)
		MOVEQ	#0x0A,D0
		DC.W	0xAB1D
	}
}

/* AllowPurgePixels - 
 */
pascal void AllowPurgePixels(pm)PixMapHandle pm;{
	asm {
		MOVE.L	pm(A6),-(SP)
		MOVEQ	#0x0B,D0
		DC.W	0xAB1D
	}
}

/* NoPurgePixels - 
 */
pascal void NoPurgePixels(pm)PixMapHandle pm;{
	asm {
		MOVE.L	pm(A6),-(SP)
		MOVEQ	#0x0C,D0
		DC.W	0xAB1D
	}
}

/* GetPixelsState - 
 */
pascal GWorldFlags GetPixelsState(pm)PixMapHandle pm;{
	asm {
		SUBQ.L	#4,SP
		MOVE.L	pm(A6),-(SP)
		MOVEQ	#0x0D,D0
		DC.W	0xAB1D
		MOVE.L	(SP)+,D0
	}
}

/* SetPixelsState - 
 */
pascal void SetPixelsState(pm, state)PixMapHandle pm;GWorldFlags state;{
	asm {
		MOVE.L	pm(A6),-(SP)
		MOVE.L	state(A6),-(SP)
		MOVEQ	#0x0E,D0
		DC.W	0xAB1D
	}
}

/* GetPixBaseAddr - 
 */
pascal Ptr GetPixBaseAddr(pm)PixMapHandle pm;{
	asm {
		SUBQ.L	#4,SP
		MOVE.L	pm(A6),-(SP)
		MOVEQ	#0x0F,D0
		DC.W	0xAB1D
		MOVE.L	(SP)+,D0
	}
}

/* NewScreenBuffer - 
 */
pascal QDErr NewScreenBuffer(globalRect, purgeable, gdh, offscreenPixMap)
	Rect			*globalRect;
	Boolean		 	purgeable;
	GDHandle		*gdh;
	PixMapHandle	*offscreenPixMap;{

	asm {
		SUBQ.L	#2,SP
		MOVE.L	globalRect(A6),-(SP)
		MOVE.B	purgeable(A6),-(SP)
		MOVE.L	gdh(A6),-(SP)
		MOVE.L	offscreenPixMap(A6),-(SP)
		MOVEQ	#0x10,D0
		DC.W	0xAB1D
		MOVE.W	(SP),D0
	}
}

/* DisposeScreenBuffer - 
 */
pascal void DisposeScreenBuffer(offscreenPixMap)PixMapHandle offscreenPixMap;{
	asm {
		MOVE.L	offscreenPixMap(A6),-(SP)
		MOVEQ	#0x11,D0
		DC.W	0xAB1D
	}
}

/* GetGWorldDevice - 
 */
pascal GDHandle GetGWorldDevice(offscreenGWorld)GWorldPtr offscreenGWorld;{
	asm {
		SUBQ.L	#4,SP
		MOVE.L	offscreenGWorld(A6),-(SP)
		MOVEQ	#0x12,D0
		DC.W	0xAB1D
		MOVE.L	(SP)+,D0
	}
}