FKEY for FKEYs
Volume Number: 4
Issue Number: 6
Column Tag: Assembly Language Lab
FKEY that runs other FKEYs!
By John Holder, Contributing Editor
[John Holder is a previous contributor to MacTutor and is well known for his
numerous FKEY shareware products. In this article, John shows us how to create an
FKEY that runs other FKEYS without installing them in the system folder! Hence this
FKEY has an event loop, menu bar and all the other goodies normally found in a regular
application. The source code disk for this month also includes two of his more popular
FKEYS to use as launch samples, along with a shareware application so you can contact
John about other goodies he might have for you. -Ed]
What’s an FKEY?
FKEY’s (Function Keys) are resources containing executable code that are called
upon by hitting the keys Command-Shift-# (any number 0-9) at the same time. In
the standard System file there are two FKEY’s; with an ID#3 and #4 that are used to
dump the current screen or window onto disk or printer.
There are also many other FKEY’s out in the Mac world, some Public Domain or
Shareware, and others are sold commercially. They can be installed into the System
file by using “ResEdit” or “Fkey Installer” (this application was created by “Dreams
of the Phoenix, Inc™” and released into the public domain to encourage people to make
Fkeys). The Fkey presented in this article can be used to access other Fkey’s which
are not in the System file!
What’s this all about?
This article will show you how to create an FKEY with an interface similar to a
standard applications (menus with command key equivalents, windows, and an event
loop). It does not support DA’s nor does it have an EDIT menu, but if you need to add
this function to your own Fkey it would be very simple.
This Fkey was created with the Macintosh 68000 Development System. All
applications are on a disk titled ‘MDS1’ and all .D files are on a disk titled ‘MDS2’.
First assemble the file ‘FkeyTemp.Asm’, then run the linker on the file
‘FkeyTemp.Link’, and finally run RMaker on the file ‘FkeyTemp.R’. You will now have
an FKEY ready to put into your System file!
Fig. 1 Our FKEY launches other fkeys!
Fkey Sampler, How it Works
First, we create an offset table that is used to store the FKEY’s many “global”
variables. This is done by naming the offsets that it will need such as sfReply,
WindPtr, etc., and calculating how many bytes each will take (explained under “How to
set up the offset Table”).
When the Fkey starts, there is a short jump over its header, then the
applications current port and all registers are saved, next it brings up the standard
arrow cursor with _InitCursor. We now check the global variable MenuList to see if
the application which is currently running has a menu, if it doesn’t have one (like the
MiniFinder) then we can’t let the Fkey run! If it does have a menu, we try to allocate
enough space for the Fkey’s global variables by making a non-relocatable block with
_NewPtr. If there is not enough memory for the globals (there has been an error if
_NewPtr returns a zero in register A0) it beeps the speaker and returns to the
Application. Otherwise, a pointer to the storage area is put into register A4.
If the storage was allocated, we go on and get a handle to a copy of the applications
menu bar with _GetMenuBar, and clear the menu so that we may replace it with our
own. After the Fkey’s menus are created with _NewMenu, _AppendMenu, and
_InsertMenu, we create a window that will simulate the standard desktop. Creating a
new window generates an update event, so when it gets to the main event loop, the
window will be filled with the current desktop pattern.
The Main Event
Now its off to the main loop to look for events. This Fkey uses only keydown,
mousedown & update events. Upon a useable event we jump to the appropriate routine
to handle it, if it’s an update event the background window is filled with the current
desktop pattern (found in the system global variable “DeskPattern”). Other events
are handled just like a standard application by using a jump table to jump to the
appropriate routines.
Doing the About...
When the mouse is clicked in the “About Fkey Sampler...” menu item under the
Apple menu, a window is created and set as the current port. Then the windows text
font and size is set to 9 point Monaco with _TextFont and _TextSize. Now the stack is
set up for _TextBox (a very handy routine that displays text in a given rectangle with
left, right or center justification!) Then we jump to a routine that uses _GetOSEvent
to watch for a mousedown or key down event. When a key or the mouse button has been
clicked we dispose of the window, unhighlight the menu and return to the main loop to
get the next event!
Fig. 2 A useful FKEY running under our FKEY
Opening the Fkey
The purpose of this particular Fkey is to open and use other FKEY’s (of Type
‘FKEY’) that are not in the System file. When this routine is called, the standard get
file dialog is displayed with _Pack3. If a name is chosen, the volume the file is on is