Technotes


InitGraf with MPW Assembly



Technote PT 16February 1989



Written by: Dennis Hescox February 1989

The Macintosh Programmer's Workshop (MPW) requires assembly-language programmers to allocate their own QuickDraw global variables rather than use the default record as indicated in Inside Macintosh.


In the Beginning...

Early Macintosh assembly-language development systems automatically allocated a set of QuickDraw global variables (a QuickDraw record) on the application's stack. The assembly-language note in Inside Macintosh, I-163 indicates that the programmer should use the following code to specify that automatically allocated record to _InitGraf:

		PEA		-4(A5)
		_InitGraf

Here and Now

Despite the note in Inside Macintosh, MPW does not automatically allocate a set of QuickDraw global variables for the programmer; it is the responsibility of the programmer to allocate this record for QuickDraw's use.

An Example...

Here is an example of creating a QuickDraw global variables template taken from Sample.a, V1.01, which is distributed with MPW 3.0 and on Developer Technical Support's sample source code disk:

	QDGlobals	RECORD	0,DECREMENT
	GrafPort	DS.L	1
	White		DS.B	8
	Black		DS.B	8
	Gray		DS.B	8
	LtGray		DS.B	8
	DkGray		DS.B	8
	Arrow		DS.B	cursRec
	ScreenBits	DS.B	BitMap
	RandSeed	DS.L	1
			ORG	-GrafSize
			ENDR

Here is an example, again from Sample.a, of how to use the above template.

First we use the template to allocate an occurrence of our record:

QD		DS		QDGlobals		; QuickDraw's globals

Next we set up for and make our call:

		PEA		QD.GrafPort
		_InitGraf

The declaration of QD with a DS creates an occurrence of our record in the application's global variable space and the assembler implicitly provides the reference to A5 as the base register .

Truth or Consequences

If you use the MPW assembler and also use the code specified by the note in Inside Macintosh, you are telling QuickDraw (by calling _InitGraf) to use an inappropriate area of memory as global variables space. QuickDraw will happily initialize this area of memory to the correct values for its use, but in doing so, it will also be blasting information that is probably important to some other part of the system.

Further Reference:




Technotes
Previous Technote | Contents | Next Technote