home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
Information
/
CSMP Digest
/
volume 1
/
csmp-v1-127.txt
< prev
next >
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
NeXTSTEP
RISC OS/Acorn
Shift JIS
UTF-8
Wrap
Text File
|
1994-12-08
|
40.3 KB
|
1,161 lines
|
[
TEXT/R*ch
]
C.S.M.P. Digest Tue, 30 Jun 92 Volume 1 : Issue 127
Today's Topics:
PBLockRange
HELP: How do traps/selectors work?
Notification Mgr. Question
Is MacApp 3.0 available???
Using Menus during Interrupts???
Color QuickDraw and GWorlds
Number of strings in a STR#?
MPW C and > 32K structs
How to tell if monitor is in color was(Re: Most efficient bla, bla...)
Need help with INITs (specifically, patching traps)
MacBinary format and empty forks
REWARD OFFERED: Think C Multisegment Driver Problem
-------------------------------------------------------
From: dcastell@csg.uwaterloo.ca (David Castell)
Subject: PBLockRange
Organization: Computer Systems Group
Date: Tue, 26 May 1992 17:04:56 GMT
In IM-IV is says that the PBLockRange call can be used on files that are
open in shared mode. However, it has been my observation that this call
can't be used on just any volume, but only works on shared volumes. Is this
call supposed to work on non-shared volumes?
Dave Castell
Computer Systems Group
+++++++++++++++++++++++++++
From: unity@mcl.ucsb.edu (Pete Gontier)
Date: 29 May 92 16:26:04 GMT
dcastell@csg.uwaterloo.ca (David Castell) writes:
>In IM-IV is says that the PBLockRange call can be used on files that are
>open in shared mode. However, it has been my observation that this call
>can't be used on just any volume, but only works on shared volumes. Is this
>call supposed to work on non-shared volumes?
I was playing around with these calls the other day. I found that I could
not only open a shared file on a local volume, but that I could lock a
range on a file opened read-only on a local volume. I don't know if the
calls had any effect, but they did not generate errors.
I'm running 7.0.1 tuned with 1.1.1 and no file sharing.
- --
Pete Gontier // EC Technology // unity@mcl.ucsb.edu
---------------------------
From: kevin@crash.cts.com (Kevin Hill)
Subject: HELP: How do traps/selectors work?
Date: 22 May 92 00:58:25 GMT
Organization: Crash TimeSharing, El Cajon, CA
I have just purchased books III and IV, and after perusing the globals section
and the system traps sections I have a couple of questions..
Are these address that contain the address of the Toolbox call in question?
What is a selector? Can I put in my own routines at these address locations
and have my program do something before the Toolbox call goes? (I know, I have
to save the A5 environment like i found, is there more I would have to watch
for?)
Thanks!
-Kevin Hill
+++++++++++++++++++++++++++
From: stevec@Apple.COM (Steve Christensen)
Date: 30 May 92 02:30:20 GMT
Organization: Apple Computer Inc., Cupertino, CA
kevin@crash.cts.com (Kevin Hill) writes:
>I have just purchased books III and IV, and after perusing the globals section
>and the system traps sections I have a couple of questions..
> Are these address that contain the address of the Toolbox call in question?
> What is a selector? Can I put in my own routines at these address locations
>and have my program do something before the Toolbox call goes? (I know, I have
>to save the A5 environment like i found, is there more I would have to watch
>for?)
Traps are not addresses, they are pseudo-instructions. Executing a trap
"instruction" causes the CPU to dispatch to the appropriate Toolbox or OS
routine (i.e., putting a size into register D0 and executing the $A022 trap
will call NewHandle).
Selectors are numbers that are passed to some routines that specify which
of the functions that a particular routine performs. For example, passing
a selector value of 1 to HFSDispatch causes it to perform the OpenWD function.
You can "patch" these trap routines with your own code when you want to do
something in addition to what the routine normally does. To do this, you
need to call GetTrapAddress to get the address of the original trap routine,
and then call SetTrapAddress to install your routine. It's your responsibility
to save the original routine's address and call it as part of your patch.
Also, you must observe the register saving convention appropriate for the
trap you are patching, not just saving A5.
steve
- --
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Steve Christensen Never hit a man with glasses.
stevec@apple.com Hit him with a baseball bat.
---------------------------
From: steve.herman%express@freedom.msfc.nasa.gov (Steve Herman)
Subject: Notification Mgr. Question
Organization: Boeing Computer Support Services (BCSS)
Date: Fri, 22 May 1992 20:56:32 GMT
Hello all,
Inside Mac Vol VI states that the nmIcon field of an NMRec can contain "a
handle to a small icon or to an icon family containing a small color icon".
If I get a handle to an 'SICN' resource and plug it into this field
everything works fine. However, if I try to put a handle to an 'ICN#',
'ics#', 'ics4' or 'ics8' into the field it doesn't work.
I'm not getting any sort of error on my GetResource call or the NMInstall
call. And the NMInstall is placing the mark by my application name under the
application menu.
Just what is meant by a handle to an icon family? Does anyone know the
trick to get this to work?
Thanks,
Steve
- -------------------------------------
Steve Herman - BCSS
"Happiness is just a 'Flaming Moe' away"
- Moe the Bartender
- -------------------------------------
+++++++++++++++++++++++++++
From: absurd@applelink.apple.com (Tim Dierks, software saboteur)
Date: 29 May 92 18:10:43 GMT
Organization: MacDTS Misfits
In article <1992May22.205632.22328@lambda.msfc.nasa.gov>, steve.herman%express@freedom.msfc.nasa.gov (Steve Herman) writes:
>
> Hello all,
>
> Inside Mac Vol VI states that the nmIcon field of an NMRec can contain "a
> handle to a small icon or to an icon family containing a small color icon".
> If I get a handle to an 'SICN' resource and plug it into this field
> everything works fine. However, if I try to put a handle to an 'ICN#',
> 'ics#', 'ics4' or 'ics8' into the field it doesn't work.
>
> I'm not getting any sort of error on my GetResource call or the NMInstall
> call. And the NMInstall is placing the mark by my application name under the
> application menu.
>
> Just what is meant by a handle to an icon family? Does anyone know the
> trick to get this to work?
This line was left in the documentation accidentally; at the time, we did
not document the icon utilities, which is what you need to do this. However,
now we do, and you should examine Tech Note #306, "Drawing Icons the System
7 Way" for details on creating and using icon families.
Tim Dierks
MacDTS, but I speak for the trees
---------------------------
From: quesnel@ems (Rene Quesnel)
Subject: Is MacApp 3.0 available???
Date: 28 May 92 11:38:33 GMT
Organization: Faculty of Music, McGill University
Does anyone has any idea when MacApp 3.0 will be available? Everybody is
talking about it but at APDA, the official word is that it is not
shipping yet (except as part of ETO). We have a project to start with
MacApp. If it is going to be released in a couple weeks, we'll wait for
the new version but if it is going to take another six months, we'll
start with 2.0.1. Does anyone have any info on this?
Thanks,
Rene Quesnel
quesnel@music.mcgill.ca
+++++++++++++++++++++++++++
From: ksand@apple.com (Kent Sandvik)
Date: 29 May 92 21:59:10 GMT
Organization: MacDTS Mongols
In article <1992May28.113833.29090@thunder.mcrcim.mcgill.edu>, quesnel@ems (Rene
Quesnel) writes:
> Does anyone has any idea when MacApp 3.0 will be available? Everybody is
> talking about it but at APDA, the official word is that it is not
> shipping yet (except as part of ETO). We have a project to start with
> MacApp. If it is going to be released in a couple weeks, we'll wait for
> the new version but if it is going to take another six months, we'll
> start with 2.0.1. Does anyone have any info on this?
MacApp 3.0 has been available for a long time on ETO (#7), as for a
full APDA product, I think we are talking about weeks or even less,
but someone from the marketing group might know better.
- --
Cheers, Kent
---------------------------
From: rsherman@mthvax.cs.miami.edu (Roby Sherman)
Subject: Using Menus during Interrupts???
Date: 27 May 92 13:44:52 GMT
Organization: The Tao of Programming
Hello all...
I'm trying to write an interrupt based routine that will bring up
a pop-up menu. Once the routine is called, I setup the A5 enviroment,
and I go to call POPUPMENUSELECT. The menu comes up and then the mouse
hangs. Any Idea how I can do this? It must be possible, since OnCueII
and other such programs draw menus at Interrupt time.
thanks in advance...
Roby
- --
rsherman@mthvax.cs.miami.edu Roby Sherman
+++++++++++++++++++++++++++
From: dougm@cns.caltech.edu (Doug McNaught)
Date: 27 May 92 20:29:03 GMT
Organization: California Institute of Technology
In article <1003okINN5af@mthvax.cs.miami.edu> rsherman@mthvax.cs.miami.edu (Roby Sherman) writes:
Hello all...
I'm trying to write an interrupt based routine that will bring up
a pop-up menu. Once the routine is called, I setup the A5 enviroment,
and I go to call POPUPMENUSELECT. The menu comes up and then the mouse
hangs. Any Idea how I can do this? It must be possible, since OnCueII
and other such programs draw menus at Interrupt time.
No, they don't. They patch traps. Calling the Toolbox at interrupt
time is a good way to crash (can you say "re-entrancy problems? Knew
you could!)
Try patching FindWindow() or MenuSelect().
regards,
doug
- --
Doug McNaught |"Sadder still to watch it die/ Then never to have
dougm@cns.caltech.edu | known it/ For you, the blind who once could see/
mcnaught@midget.towson.edu | The bell tolls for thee..." --Neil Peart
Nobody approves my opinions! Not even me, sometimes. Read at your own risk.
+++++++++++++++++++++++++++
From: buckeye@spf.trw.com (John Wallace)
Organization: TRW Data Systems Center, Redondo Beach, CA
Date: Thu, 28 May 92 18:34:29 GMT
In article <1003okINN5af@mthvax.cs.miami.edu> rsherman@mthvax.cs.miami.edu (Roby Sherman) writes:
>Hello all...
>
>
> I'm trying to write an interrupt based routine that will bring up
>a pop-up menu. Once the routine is called, I setup the A5 enviroment,
>and I go to call POPUPMENUSELECT. The menu comes up and then the mouse
>hangs. Any Idea how I can do this? It must be possible, since OnCueII
>and other such programs draw menus at Interrupt time.
>
> Roby
>--
>rsherman@mthvax.cs.miami.edu Roby Sherman
You shouldn't draw menus at interrupt time since they will definitely
move memory. You could, however, do it at idle time. The easiest
way to do this is to install a GNEFilter (which gets called when
ever the program calls GetNextEvent or WaitNextEvent). Since these
calls are allowed to move memory, then you should be ok.
I have written code that does this, and it does a good job of
letting me to do actions when someone else's program is running.
The only problem is that it won't work unless the active program
calls GetNextEvent.
Cheers!
John
- ----
John Wallace buckeye@spf.trw.com
+++++++++++++++++++++++++++
From: stevec@Apple.COM (Steve Christensen)
Date: 30 May 92 02:37:31 GMT
Organization: Apple Computer Inc., Cupertino, CA
rsherman@mthvax.cs.miami.edu (Roby Sherman) writes:
> I'm trying to write an interrupt based routine that will bring up
>a pop-up menu. Once the routine is called, I setup the A5 enviroment,
>and I go to call POPUPMENUSELECT. The menu comes up and then the mouse
>hangs. Any Idea how I can do this? It must be possible, since OnCueII
>and other such programs draw menus at Interrupt time.
Are you sure OnCueII, etc., are drawing menus at interrupt time? Generally,
any kind of drawing that involves QuickDraw can't be done at interrupt time
because heap blocks can move, and the heap could have been in an inconsistent
state. More than likely they're hooked into GetNextEvent and do the popup
menus at that time...
steve
- --
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Steve Christensen Never hit a man with glasses.
stevec@apple.com Hit him with a baseball bat.
---------------------------
From: S4161006@deimos.ucc.umass.edu (S4161006)
Subject: Color QuickDraw and GWorlds
Organization: University of Massachusetts at Amherst
Date: Wed, 27 May 1992 16:58:03 GMT
I'm about to take the big plunge into graphics with a tetris-like game.
When a piece move I want it to smoothly redraw what was underneath it. From
reading Inside Mac VI it seem like the Graphics Device Manager off-screen
gWorlds are the way to do this well. What I had a hard time figuring out is
whether this option is available on a Mac not running System 7. If not is
there another accepted way of smothly redrawing the window. Thanks in advance.
Mike Houser
UMass
- -mh
+++++++++++++++++++++++++++
From: jmatthews@desire.wright.edu
Date: 28 May 92 23:31:38 EST
Organization: Wright State University
In article <1992May27.165803.22556@nic.umass.edu>, S4161006@deimos.ucc.umass.edu (S4161006) writes:
> I'm about to take the big plunge into graphics with a tetris-like game.
> When a piece move I want it to smoothly redraw what was underneath it. From
> reading Inside Mac VI it seem like the Graphics Device Manager off-screen
> gWorlds are the way to do this well. What I had a hard time figuring out is
> whether this option is available on a Mac not running System 7. If not is
> there another accepted way of smothly redrawing the window. Thanks in adv-
> ance.
GWorlds are supposed to be available on all machines running System 7. They are
also available with System 6.0.5 and later if Color QuickDraw is present.
Inside Mac VI suggests that GWorlds should work on non-Color QuickDraw Macs
under System 7.0 given a few precautions. I've had (sorry to whine) no luck
making this happen. Anybody?
A good alternative for non-CQD machines and earlier Systems is Apple's DTS
sample code SC015.OffScreen and SC016.OffSample available from ftp.apple.com
(130.43.2.3) or the d e v e l o p CD.
o----------------------------------------------------------------------------o
| John B. Matthews, jmatthews@desire.wright.edu, disclaimer:= myViews <> WSU |
| "I'm a commensal .sig virus, indistinguishable from an ordinary organelle."|
o----------------------------------------------------------------------------o
---------------------------
From: eric@homebase.vistachrome.com (Eric Brunson)
Subject: Number of strings in a STR#?
Date: 29 May 92 17:51:20 GMT
Organization: Vista-Chrome Incorporated
The first byte of the STR# resource type tells the number
of strings in the string list, but I haven't seen a call
that will return that to my program. Has anyone ever
come up against this problem?
Please email, I'll summarize if it's non-trivial.
Thanks,
Eric
- --
Eric Brunson These opinions are mine alone,
eric@vistachrome.com but they could be yours for a low monthly fee!
"He's a genius, eh, he hooked up our stereo."
+++++++++++++++++++++++++++
From: gshields@starfish (Gerald Shields)
Organization: Interactive Systems, Cambridge, MA 02138-5302
Date: Fri, 29 May 1992 22:18:46 GMT
In article <1992May29.175120.18368@homebase.vistachrome.com>,
eric@homebase.vistachrome.com (Eric Brunson) writes:
> Path:
dirtydog.ima.isc.com!newsserver.pixel.kodak.com!rpi!uwm.edu!spool.mu.edu!uunet!r
de!eric
> From: eric@homebase.vistachrome.com (Eric Brunson)
> Newsgroups: comp.sys.mac.programmer
> Subject: Number of strings in a STR#?
> Message-ID: <1992May29.175120.18368@homebase.vistachrome.com>
> Date: 29 May 92 17:51:20 GMT
> Article-I.D.: homebase.1992May29.175120.18368
> Distribution: comp.sys.mac.programmer
> Organization: Vista-Chrome Incorporated
> Lines: 15
>
> The first byte of the STR# resource type tells the number
> of strings in the string list, but I haven't seen a call
> that will return that to my program. Has anyone ever
> come up against this problem?
>
> Please email, I'll summarize if it's non-trivial.
>
> Thanks,
> Eric
>
>
> --
> Eric Brunson These opinions are mine alone,
> eric@vistachrome.com but they could be yours for a low monthly fee!
> "He's a genius, eh, he hooked up our stereo."
Eric,
the following code snippet shold do the job
short num_strings;
Handle str_h;
str_h = GetResource( 'STR#', your string ID here );
if ( str_h == (Handle)0 )
{
handle errors here;
}
num_strings = (*(short *)(*str_h));
ReleaseResource( str_h );
Jerry Shields
---------------------------
From: Bernhard Damberger <bernied@ncsa.uiuc.edu>
Subject: MPW C and > 32K structs
Organization: NCSA - University of Illinois
Date: Thu, 28 May 1992 06:05:44 GMT
+++++++++++++++++++++++++++
From: Bernhard Damberger <bernied@ncsa.uiuc.edu>
Organization: NCSA - University of Illinois
Date: Thu, 28 May 1992 06:10:09 GMT
I am getting this annoying message from the MPW C compiler:
### Error 427 Can't use structures > 32k
Basically I am trying to port some Unix app to MPW (as a tool) and it has
a huge
pulsating data struct that is (you guessed it) > 32K. Obviously MPW C
does not
like this.
I have tried the following compiler options to no avail:
-bigseg (generate single large (>32K) code segment, 68020 only)
-m (generate 32-bit references for data (less efficient code))
-model far (generate load-time relocatable 32-bit references
for data and code).
Any ideas out there? Any possible C options that I missed? Is MPW C
really
this crippled?
Thanks for your help...
+++++++++++++++++++++++++++
From: ksand@apple.com (Kent Sandvik)
Date: 29 May 92 21:58:11 GMT
Organization: MacDTS Mongols
In article <Boy6Gy.6JD@news.cso.uiuc.edu>, bernied@ncsa.uiuc.edu (Bernhard
Damberger) writes:
> I am getting this annoying message from the MPW C compiler:
> ### Error 427 Can't use structures > 32k
>
> Basically I am trying to port some Unix app to MPW (as a tool) and it has
> a huge
> pulsating data struct that is (you guessed it) > 32K. Obviously MPW C
> does not
> like this.
> I have tried the following compiler options to no avail:
> -bigseg (generate single large (>32K) code segment, 68020 only)
> -m (generate 32-bit references for data (less efficient code))
> -model far (generate load-time relocatable 32-bit references
> for data and code).
> Any ideas out there? Any possible C options that I missed? Is MPW C
> really
> this crippled?
"Oh the pain, suffering, and grief, when UNIX programmers try to misuse
the MacOS memory system using malloc and stack based structures."
Yes, the MPW C compiler has a limitation of array/struct sizes, no bigger
than 32k, it's a compiler, not runtime, limitation.
What to do, what to do, check out handles and pointers in the Memory Manager.
And make them as big as you want, as long as end users have memory in their
machines.
- --
Cheers, Kent
+++++++++++++++++++++++++++
From: creiman@void.ncsa.uiuc.edu (Charlie Reiman)
Date: 30 May 92 05:04:17 GMT
Organization: University of Illinois at Urbana
ksand@apple.com (Kent Sandvik) writes:
>In article <Boy6Gy.6JD@news.cso.uiuc.edu>, bernied@ncsa.uiuc.edu (Bernhard
>Damberger) writes:
>> I am getting this annoying message from the MPW C compiler:
>> ### Error 427 Can't use structures > 32k
>>
>> Basically I am trying to port some Unix app to MPW (as a tool) and it has
>> a huge
>> pulsating data struct that is (you guessed it) > 32K. Obviously MPW C
>> does not
>> like this.
>> I have tried the following compiler options to no avail:
>> -bigseg (generate single large (>32K) code segment, 68020 only)
>> -m (generate 32-bit references for data (less efficient code))
>> -model far (generate load-time relocatable 32-bit references
>> for data and code).
>> Any ideas out there? Any possible C options that I missed? Is MPW C
>> really
>> this crippled?
>"Oh the pain, suffering, and grief, when UNIX programmers try to misuse
>the MacOS memory system using malloc and stack based structures."
>Yes, the MPW C compiler has a limitation of array/struct sizes, no bigger
>than 32k, it's a compiler, not runtime, limitation.
>What to do, what to do, check out handles and pointers in the Memory Manager.
>And make them as big as you want, as long as end users have memory in their
>machines.
Bernie had a 2-d array nestled within the data strucure, which isn't
the easiest thing to fake with Handles... Anyway, we managed to figure
out a solution. I don't know if he's tried it yet, but I think it'll
work.
new_thread(): Why is there a 32k limit? We can have over 32k of
globals, segments larger than 32k, code resources of enormous
magnitude-- but C structures are special? I smell something fishy
here. I don't want to put Apple folks on the spot, but I am curious as
to what gives. I know I'm not the only person to smack his nose against
that particular limit.
Although, I must admit: UNIX programmers do tend to get carried away
with memory allocation. Man, I could tell some stories of attrocious
abuse. I do envy that reckless abandon, though...
- --
Charlie Reiman - creiman@ncsa.uiuc.edu
Have a bajillion brilliant Jobsian lithium licks.
---------------------------
From: mxmora@unix.SRI.COM (Matt Mora)
Subject: How to tell if monitor is in color was(Re: Most efficient bla, bla...)
Date: 28 May 92 23:12:43 GMT
Organization: SRI International, Menlo Park, California
In article <1992May28.145037.8305@waikato.ac.nz> ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) writes:
>> I am writing a custom ldef in pascal (I know this seems to be the major
>> source of my problem) and I want to draw a gray line.
>If you persist in slurring Pascal in this way, I shall be forced to ask
>you to step outside. :-)
I personaly like Pascal and program in it when ever I get a chance. I was
just trying to beat the Pascal bashers to the punch. :-)
>For the particular case of the standard 50% grey pattern, here's a routine
>which will return a PatPtr that you can dereference and pass to the
>appropriate QuickDraw calls:
> Function grayPtr : PatPtr;
> Inline
> $2055, { move.l (a5), a0 }
> $41E8, $FFE8, { lea -24(a0), a0 }
> $2E88; { move.l a0, (sp) }
Thanks for the code. I used the one that was posted earlier but I think
yours is the same. Thanks again for such a quick response.
Now for another question. I'm putting a final touch on a program and would
like the button outline to be gray when the button is inactive and on a color
screen. Not just a gray pattern the gray color.
I got the gray part working but how do I know if the button outline
will be drawn in color or b/w? I need to know if the monitor the button
outline is on, is in the 1 bit mode show I can draw the outline in the gray
pattern instead of the gray color. Anyone know how to tell?
Thanks
Matt
- --
___________________________________________________________
Matthew Mora | my Mac Matt_Mora@sri.com
SRI International | my unix mxmora@unix.sri.com
___________________________________________________________
+++++++++++++++++++++++++++
From: keith@taligent.com (Keith Rollin)
Date: 29 May 92 02:40:50 GMT
Organization: Taligent
In article <35464@unix.SRI.COM>, mxmora@unix.SRI.COM (Matt Mora) writes:
>
> Now for another question. I'm putting a final touch on a program and would
> like the button outline to be gray when the button is inactive and on a color
> screen. Not just a gray pattern the gray color.
>
> I got the gray part working but how do I know if the button outline
> will be drawn in color or b/w? I need to know if the monitor the button
> outline is on, is in the 1 bit mode show I can draw the outline in the gray
> pattern instead of the gray color. Anyone know how to tell?
>
Well, I'm a System 7 weenie, so I'd use DeviceLoop. It tells you the depth of
the GDevice you are being asked to write to, so you can make your determination
based on that. However, I think that you have to make sure you're drawing into a
CGrafPort (as opposed to a GrafPort) before diving into DeviceLoop.
I did some stuff like this for Mac Programming Secrets. I used DeviceLoop to
draw list items in dithered grey or real grey depending on the what was
available, even if the list crossed monitors of different depths. If you want,
send me mail and I'll send you the code.
If you want to be compatible with 6.0.x, then the coolest thing would be to
write your own version of DeviceLoop (I have a vague feeling that there might be
something on this in DTS's Snippets folder on ftp.apple.com).
- --
Keith Rollin
Phantom Programmer
Taligent, Inc.
---------------------------
From: ehanson@BugsBunny.acslab.umbc.edu (Mr. Erik Hanson; ARTS-SCI (UGRAD))
Subject: Need help with INITs (specifically, patching traps)
Organization: University of Maryland Baltimore County, Mathematics Department
Date: Fri, 29 May 1992 02:38:56 GMT
Howdy.
I'm writing my first System Extension, and I need a bit o' help.
If anybody can show me some code (or point me towards some code)
that would help me learn how to patch traps (specifically the
StandardGetFile trap, but any trap will do), I'd be grateful.
I've got IM I-VI, but no X-Ref, and I haven't been able to find
any help in there. So, if it is in there, and somebody could tell
me where, I'd be quite happy.
Also, any code for that might help me write an Extension would
also be welcomed.
(And in payment, I'll release my super-cool Extension as
freeware. (And not get-payments-from-both-people-in-the-world-
who-support-sharware-ware. ;-) )
Seeya!
Erk
______________________________________________________________________________
Erik Hanson University o' Maryland Baltimore County ehanson@umbc3.umbc.edu
+++++++++++++++++++++++++++
From: keith@taligent.com (Keith Rollin)
Date: 29 May 92 21:23:24 GMT
Organization: Taligent
In article <1992May29.023856.21865@umbc3.umbc.edu>,
ehanson@BugsBunny.acslab.umbc.edu (Mr. Erik Hanson; ARTS-SCI (UGRAD)) writes:
>
> Howdy.
>
> I'm writing my first System Extension, and I need a bit o' help.
> If anybody can show me some code (or point me towards some code)
> that would help me learn how to patch traps (specifically the
> StandardGetFile trap, but any trap will do), I'd be grateful.
> I've got IM I-VI, but no X-Ref, and I haven't been able to find
> any help in there. So, if it is in there, and somebody could tell
> me where, I'd be quite happy.
>
> Also, any code for that might help me write an Extension would
> also be welcomed.
I patch Standard File in a Boomerang-like INIT that I call Pointed Stick.
Normally, if I were helping someone patch their first trap, I'd start of with
something simple (in Mac Programming Secrets, 2nd Edition, I show how to patch
MenuKey). However, patching Standard File is tricky, because a single trap is
used to dispatch to a number of functions that all take a different set of
parameters.
This is how I patched Standard File in Pointed Stick (using THINK C, which makes
the patching of traps easy by allowing the use of global variables):
void main(void)
{
// Stuff removed for Usenet posting
Ptr ourAddress;
// Stuff removed for Usenet posting
asm {
move.l A4,-(sp) ; save orig A4
bsr __GetA4 ; get pointer to saved location
lea main,A4 ; get our A4
move.l A4,(A1) ; save it so SetUpA4() will work
move.l A4, ourAddress ; for the RecoverHandle, later
lea @continue,A0 ; now, fix up the PC (Technote #245)
move.l A0,D0
StripAddress
move.l D0,A0
jmp (A0)
@continue
}
// Stuff removed for Usenet posting
gOldStandardFile = GetToolTrapAddress(_Pack3);
SetToolTrapAddress((long) MyPack3, _Pack3);
// Stuff removed for Usenet posting
RestoreA4();
}
// Example of struct used in xOffsetToXXX records below:
typedef struct {
short selector;
SFReply* reply;
DlgHookProcPtr dlgHook;
ConstStr255Param origName;
ConstStr255Param prompt;
Point where;
} SFPutFileParameters;
// Example of offset record used below:
short gOffsetToReply[] = {
offsetof(SFPutFileParameters, reply),
offsetof(SFGetFileParameters, reply),
offsetof(SFPPutFileParameters, reply),
offsetof(SFPGetFileParameters, reply),
offsetof(StandardPutFileParameters, reply),
offsetof(StandardGetFileParameters, reply),
offsetof(CustomPutFileParameters, reply),
offsetof(CustomGetFileParameters, reply)
};
//---------------------------------------------------------------------------
/*
This is the entry point to most of what Pointed Stick does. ItUs pretty
gnarly, so IUd better get this down while I can still figure it out.
The idea behind this patch to Standard File is to do two things:
% Make sure everything is OK for me to hook in, and
% Hook me in.
The first thing we do is set up our A4, strip off the return address
and save it for later, and take a look at the selector. If the selector
is not one that we know (from 1 to 8, inclusive), we just call the
standard Standard File without any funny stuff. ItUs called just as
if we didnUt exist (except that we are tail-patched, here).
Next, we try to open our INITUs resource fork. WeUll need a lot of
things from it, like MENUs, ALRTs, etc. We open the resource fork
using MyOpenResFile, which opens the resource fork, shuffles the
resource chain so that my map appears just before the System resource
map and -- presumably -- after the applicationUs. If we canUt open
our resource fork, we blow out in the same way as if the selector
was out of range.
At this point, we do one of two things. If the user had selected a
file from the hierarchical menu we attached to the Open menu item,
we are in the middle of puppet-stringing a response. If this is the
case, we call FakePack3, which fills in the reply record with something
appropriate, and then return to the caller just as if Standard File
had really interacted with the user. This is identical in concept
with what MultiFinder does with non-Apple Event aware applications.
If we arenUt puppet-stringing, then itUs time for us to hook ourselves
in to Standard File. This consists of two phases. First, we can only
hook ourselves in properly if the caller makes one of those RSFPS or
RCustomS calls. If they didnUt, the first thing we do is convert
the parameters on the stack and change the selector so it looks to
Standard File like the caller _did_ make a custom call. Second, we
replace the dlgHook, filterProc, and modalFilter parameters with
pointers to our own procedures, saving the callerUs so that we can
chain to them when necessary.
Now weUre almost ready to fall into Standard File. ThereUre only
a few things we still have to do. First, we put ourself into
a state that will cause us to munge the next dialog created so that
it has the menubar across the top. Second, we put ourself into a
state that will start the sequence of events that will find the
handle to the ListRecord holding the files and directories appearing
in the dialog (see the comments in GetItemList.c to see how this
happens). Third, we clear out the variables holding the previous
volume and directory we were in. These values are used for rebounding.
We set them to illegal values to force the rebound routines to
select the initial file. Finally, we turn off CEToolbox hotkeys so
that the user canUt bring up MiniFinder while weUre in Standard
File. If the user did that, Standard File would re-enter itself,
which is a Bad Thing.
Finally, we chain to the original Standard File entry point. At
this point, the dialog appears and the user interacts with it. When
the user closes the dialog, it goes away, and Standard File returns
to us. All we have to do now is turn the CEToolbox hotkeys back on
and close our resource file. Once thatUs done, we return to the
caller.
*/
pascal void MyPack3()
{
SetUpA4();
asm {
move.l (sp)+,pSavedA4
move.l (sp)+,pSavedReturnAddress
move.w (sp),D0
beq @NoFunnyStuff ; skip if selector is zero
cmp.w #customGetFile,D0
bhi @NoFunnyStuff ; skip if selector is too large
bsr ControlKeyIsDown
tst.b D0
bne @NoFunnyStuff ; skip if control key is down
pea pCloseIt
move.w #fsRdPerm,-(sp) ; push access priv for our resource file
lea gMe,A0 ; push name for our resource file
move.l A0,-(sp)
jsr MyOpenResFile ; try to open it
add #4+4+2,A7 ; remove my parameters
moveq #-1,D1 ; see if we failed (check refNum == -1)
cmp.w D1,D0
beq @NoFunnyStuff ; if failed, skip special effects
move.w D0,gRefNum ; save refnum so we can close it later
move.w gStandardFileMode,D0
beq.s @HookInMyProcs
bsr FakePack3 ; do special effects
lea pParameterSizes,A0 ; pull off StdFile parameters. Get size
move.w (sp),D0 ; ...of parameters from table
add.w D0,D0
move.w -2(A0,D0.W),D0
add.w D0,A7 ; add size to stack pointer
bra @CloseUp
@HookInMyProcs
move.w (sp)+,D0 ; put selector in D0
move.w D0,pOrigSelector ; save what the user passed in
sub.w #1,D0 ; make it zero based
btst #1,D0 ; is this a Custom or P routine?
bne.s @NoConversionNeeded ; yes, so donUt convert it
move.w D0,D1 ; use D1 for table index
add.w D1,D1 ; double for 2 byte table entries
lea pDialogIDs,A0
move.w (A0,D1.W),-(sp) ; push on our dialog ID
btst #2,D0 ; is this an old style routine?
beq.s @HookInMyProcsOldStyle ; yes, so donUt push mondo parms
move.l pZeroPoint,-(sp) ; location
clr.l -(sp) ; dialog hook
clr.l -(sp) ; modal dialog filter
clr.l -(sp) ; active list
clr.l -(sp) ; activate proc
@HookInMyProcsOldStyle
clr.l -(sp) ; your data / modal dialog filter
add.w #2,D0 ; convert selector to Custom/P routine
@NoConversionNeeded
move.w D0,D1 ; use D1 for table index
add.w D1,D1 ; double for 2 byte table entries
add.w #1,D0 ; make selector 1-base again
move.w D0,-(sp) ; put the possibly modified selector back
move.w D0,gSelector ; remember selector
move.l A7,pParameters ; remember pointer to all parameters
; (including the selector)
lea pOffsetToDlgHook,A0 ; remember dlgHook
move.w (A0,D1.W),D0
move.l (A7,D0.W),pDlgHook
lea DialogHookEntry,A0 ; put in my own
move.l A0,(A7,D0.W)
lea pOffsetToFileFilter,A0 ; remember fileFilter
move.w (A0,D1.W),D0
bmi.s @DontSwapFileFilter ; but only if itUs got one
move.l (A7,D0.W),pFileFilter
tst.l pFileFilter
beq.s @DontSwapFileFilter ; donUt supply one if he didnUt
lea FileFilterEntry,A0 ; put in my own
move.l A0,(A7,D0.W)
@DontSwapFileFilter
lea pOffsetToModalFilter,A0 ; remember modalFilter
move.w (A0,D1.W),D0
move.l (A7,D0.W),pModalFilter
lea ModalFilterEntry,A0 ; put in my own
move.l A0,(A7,D0.W)
jsr MungeNextDialog
jsr StartLookingForList
clr.w curVRefNum(A4)
clr.l curDirID(A4)
move.w #-1,prevCell(A4)
pea pOldValue ; Turn off hotkeys so we donUt
move.w #-1,-(sp) ; re-enter ourselves by bringing
jsr CETurnOnOff ; up the MiniFinder.
add.w #6,sp
move.l gOldStandardFile,A0
jsr (A0)
pea pOldValue
move.w pOldValue,-(sp)
jsr CETurnOnOff
add.w #6,sp
@CloseUp
tst.b pCloseIt
beq.s @continue
move.w gRefNum,-(sp) ; close our resource file
CloseResFile
moveq #-1,D1
move.w D1,gRefNum
bra.s @continue
@NoFunnyStuff
move.l gOldStandardFile,A0 ; here if we are to call old StdFile with
jsr (A0) ; ...no tricks.
@continue
move.l pSavedReturnAddress,-(sp)
move.l pSavedA4,A4
}
}
- --
Keith Rollin
Phantom Programmer
Taligent, Inc.
---------------------------
From: Martin.Friedrich@arbi.informatik.uni-oldenburg.de (Martin Friedrich)
Subject: MacBinary format and empty forks
Organization: University of Oldenburg, Germany
Date: Fri, 29 May 1992 08:04:42 GMT
Hello, Netters !
The defintion of the macbinary format states, that for both the resource and
data fork of the transferred file, null characters are padded to the next
128 byte boundary. But if (one of ) the fork(s) is/are empty, do you have
to insert 128 null characters before the next fork or end of the file,
respectively ?
Thanks in advance,
- --
LLaP
Martin Friedrich
- -----------------------------------------------------------------------------
|"I never will understand
REAL Martin Friedrich (CS-Student) | humans ..."
NICK jupp | -- Spock, Patterns of Force
UUCP friedrich@uniol --------------------------------
DOMAIN Martin.Friedrich@arbi.informatik.uni-oldenburg.de
HOME Straekweg 1 , 2986 Leezdorf
Superior abilities breed superior ambitions
- -----------------------------------------------------------------------------
+++++++++++++++++++++++++++
From: jackb@mdd.comm.mot.com (Jack Brindle)
Date: 29 May 92 17:44:42 GMT
Organization: Motorola, Mobile Data Division - Seattle, WA
In article <1992May29.081310.1089@arbi.Informatik.Uni-Oldenburg.DE> Martin.Friedrich@arbi.informatik.uni-oldenburg.de (Martin Friedrich) writes:
>Hello, Netters !
>
>The defintion of the macbinary format states, that for both the resource and
>data fork of the transferred file, null characters are padded to the next
>128 byte boundary. But if (one of ) the fork(s) is/are empty, do you have
>to insert 128 null characters before the next fork or end of the file,
>respectively ?
No. Byte counting within the MacBinary format is done with modulo 128
arithmetic. Realizing that zero mod 128 is zero, no null bytes should
be placed either in place of a fork or at the end of a fork that is
a multiple of 128 bytes in length.
If you think about this, you will realize that adding a block of nulls
where the data fork would go would really mess up decoding. The reason
is that the data fork length information in the header indicates no
data. The decoder interprets this to be an actual length of zero, and
does not skip over the block, but procedes to decode the resource fork.
At this point everything is 128 bytes off.
The real reason for the pad nulls is to assure that the two forks start
on nice even boundaries, making things a bit easier when decoding data
coming in through transfer protocols such as XModem. The only catch was
that when Dennis originally defined the standard (MacBinary 1), he placed
the file name in an awkward position - it starts on an ODD byte. For
obvious compatibility reasons, it was not corrected when the MacBinary II
standard was developed.
Jack Brindle
ham radio: wa4fib
internet: jackb@mdd.comm.mot.com
---------------------------
From: king@maui.cs.ucla.edu (Adam King)
Subject: REWARD OFFERED: Think C Multisegment Driver Problem
Date: 30 May 92 04:22:09 GMT
Organization: UCLA Computer Science Department
I'm looking for anybody who has successfully written a multi-segment
driver using ThinkC (5.02) that installs at init time.
The problem I am having with mine is a segment loader system error
when I return from closing the driver.
I have loaded this driver at INIT time using ThinkC's installRAMDriver
code and I am closing it with their removeRAMDriver code. It crashes
durring the call to PBClose (the driver).
I suspect that the glue on the driver is trying to treat the docd
segments as resources and this is bogus because they have been
detatched. Is this true? Is it avoidable?
About the reward:
This has been driving my so insane that I will send a check for $10 to
the person who first sends me info that directly leads to the solution
of my problem.
Adam
- --
*****************************************************
* Looking for Castalia. Tell me if you've found it. *
*****************************************************
+++++++++++++++++++++++++++
From: resnick@cogsci.uiuc.edu (Pete Resnick)
Organization: University of Illinois at Urbana
Date: Sat, 30 May 1992 05:39:31 GMT
king@maui.cs.ucla.edu (Adam King) writes:
>I have loaded this driver at INIT time using ThinkC's installRAMDriver
>code and I am closing it with their removeRAMDriver code. It crashes
>durring the call to PBClose (the driver).
Eeek!! The code to which you are referring (InstallRAMDriver,
RemoveRAMDriver) was written by me, and quite poorly I might add; it
has some major bugs. It will certainly fail for multi-segment drivers.
I have discovered the problem and made *oodles* of changes to how the
code works works. I would be glad to send you (and other's) new and
working code. If I get enough response, I will post it to an FTP
archive.
Sorry for the trouble you are having.
pr
- --
Pete Resnick (...so what is a mojo, and why would one be rising?)
Graduate assistant - Philosophy Department, Gregory Hall, UIUC
System manager - Cognitive Science Group, Beckman Institute, UIUC
Internet: resnick@cogsci.uiuc.edu
---------------------------
End of C.S.M.P. Digest
**********************