• Updated 2023-07-12: Hello, Guest! Welcome back, and be sure to check out this follow-up post about our outage a week or so ago.

Problem with InitGraf in MPW 3.2.3 (assembly)

Omp

New member
Hi,

For the life of me I can’t figure out why this code is crashing. It’s literally the first Init call for the toolbox:

PEA -4(A5)     ; push address of thePort onto the stack for call to InitGraf

_InitGraf

I’m using Mini vMac. I’ve tried: different host computers (OS X, Windows 10), compiling equivalent code in C on Think C without issue, MPW 1.0, attempts at application disassembly. I only stopped at that because I thought for such a common problem the answer would be sooner found on a forum.

It has something to do with either how vMac emulates memory or an issue with MPW.

A solution or stab appreciated.

Thanks.

 

basalgangster

Well-known member
Probably, you have figured this out by now, but...

The MDS linker placed the application globals 256 bytes below the a5 boundary. The MPW linker put the application globals right below the a5 boundary, without any cushion. 

The ROM call InitGraf expects a pointer to the 203rd byte of a 206 byte area for the QuickDraw globals. Because MDS put a 256 byte cushion below the a5 boundary before the application’s globals, MDS programs could call InitGraf with a pointer to a long word four bytes below the a5 boundary, as in your example

For the MPW assembler, you must explicitly allocate some global storage for the Quickdraw globals in a data module and then pass a pointer to that module when calling InitGraf. 

The assembly include file QuickEqu.a includes this record definition:

QDGlobals RECORD ,DECREMENT
thePort 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 bitmapRec
randSeed DS.L 1
ORG -grafSize
ENDR

You need to include this, then you can allocate space for your Quickdraw Globals like this:
QD DS QDGlobals

And, once you are using the QD globals you have defined, you can point directly to the QD data area when initializing QuickDraw, as shown below.

; thePort is a variable in QDGlobals
 pea    QD.thePort  
 _InitGraf

There is a good example in the MPW AExamples folder, called Sample.a, which shows how to do this and a lot of other similar things that you will encounter in MPW Assembly.

 

Omp

New member
That explains everything. Thanks.

I had looked through Sample.a and tried the same includes and referenced the QD record instead of the A5-4 memory location, but I was missing the QD DS QDGlobals allocation line. 

 

ChefDeadpool

New member
Probably, you have figured this out by now, but...

The MDS linker placed the application globals 256 bytes below the a5 boundary. The MPW linker put the application globals right below the a5 boundary, without any cushion. 

The ROM call InitGraf expects a pointer to the 203rd byte of a 206 byte area for the QuickDraw globals. Because MDS put a 256 byte cushion below the a5 boundary before the application’s globals, MDS programs could call InitGraf with a pointer to a long word four bytes below the a5 boundary, as in your example

For the MPW assembler, you must explicitly allocate some global storage for the Quickdraw globals in a data module and then pass a pointer to that module when calling InitGraf. 

The assembly include file QuickEqu.a includes this record definition:

QDGlobals RECORD ,DECREMENT
thePort 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 bitmapRec
randSeed DS.L 1
ORG -grafSize
ENDR

You need to include this, then you can allocate space for your Quickdraw Globals like this:
QD DS QDGlobals

And, once you are using the QD globals you have defined, you can point directly to the QD data area when initializing QuickDraw, as shown below.

; thePort is a variable in QDGlobals
 pea    QD.thePort  
 _InitGraf

There is a good example in the MPW AExamples folder, called Sample.a, which shows how to do this and a lot of other similar things that you will encounter in MPW Assembly.
I just wanted to add that your assistance also helped me over the hump in the following thread:



Thanks so much!

 
Top