Grow Window in Asm
Volume Number: 1
Issue Number: 11
Column Tag: Assembly Language Lab
Grow Window in MacAsm
By Jan Eugenides, Software Engineer, Assembly Corner, Pembroke
Pines, FL
There are several stages a programmer goes through when learning to program
the Macintosh. The first is to learn about the tools available to you, how they work and
what they can do. The second is to unlearn everything you know about interacting with
the person using the program. This in itself is quite an undertaking. Then and only
then can you begin putting the tools together into a complete program that works like a
Macintosh program should work. This article, and the program which accompanies it,
is designed to help you with the first stage - learning to use the Macintosh Tool Kit.
This article deals with assembly language programming, to fill the need for
technical information directly related to Macintosh programming. Apple Computer,
Inc. is not overly supportive of assembly language programming, and most of Inside
Macintosh deals with Pascal examples and procedures. I'm not knocking Apple, they
had to choose some language to use in the examples and I suppose Pascal was a logical
choice. They did include some very helpful information for assembly language
programmers at the end of each chapter. However, the assembly language programmer
is still faced with translating the Pascal procedures and definitions into the necessary
stack setups and such. Not an easy task, e specially if you are not familiar with
Pascal's inner workings.
What it Does
This month's program is a complete, double-clickable application, designed to
demonstrate some very useful programming techniques. You can use it as a "shell" for
writing your own applications. Everything is in place and working, all you have to do
is insert your own code in the appropriate places.
The program, called "Show Windows," displays three common types of windows,
and shows how to handle each one properly from assembly language. It also shows how
to set up and display the menu bar, how to get events from the Mac operating system
(in this case mouse events), and shows how to create resource files such as icons and
dialog boxes for use by the application. Desk accessories are fully supported, and the
application can be run by double-clicking its icon.
Running the Program
Before you run the application you must assemble and compile it (see the "Typing
in the Program" section of this article for more details about assembling and
compiling). When you double-click the icon, you'll see the familiar zoom boxes, the
menu bar will be redrawn, and a window with the title "Window 1" will appear. You
can drag and re-size the window with the mouse as usual. Clicking in the goaway box
will close the window, and a new one will appear. Three types of windows can be seen
in this fashion.
When the program first runs, you'll notice the disk whirrs when you close a
window, before the next one is drawn. It also whirrs the first time you open the dialog
box. This is the resources being fetched from the disk. After this, they will be in
memory and everything will run much faster the next time you display the windows or
dialog box. They will stay in memory until another application or accessory needs the
space and then they'll be purged. When you need them again after that, they'll have to
be re-loaded from the disk.
Open a desk accessory or two, and experiment with clicking on the various
windows, moving them about. As you can see, everything runs con currently with no
problems.
Typing in the Program
This application was written using the Mainstay MasASM assembler. The
MacASM assembler is a very fast 68000 assembler. It does not use the Mac interface
much, but is more like running an assembler on a conventional computer. In fact, it is
very similar to the S-C Macro Assembler for the Apple II. I admit I would like to see it
use the mouse for editing, but otherwise it's great, and it is FAST.
MacASM comes with several examples on the disk, written by Yves Lempereur.
They certainly helped me get this application working, thanks, Yves!
MacASM also comes with an automatic resource compiler that will translate
resource definitions into actual resource files. This makes life easy for the
programmer. Ordinarily, I just use "filler" resources, standard templates which are
assembled with the program. Then, I use ResEdit to change them into the actual
resources I need. That's generally a faster and easier method. But for the sake of
demonstration, I have spelled out all the resources as they should be in this example.
After you have typed in the source code and assembled it, all you need to do is
double-click the assembled program's icon, and the compiler will automatically run
and compile the assembled binary file into a Macintosh application file with a data and
resource fork. The application is then ready to run.
Blow by Blow Description
From here on out I'll be dealing with the technical description of the program.
I'm assuming you are already familiar with 68000 assembly language, and with the
information in "Inside Macintosh.
Line 250 starts off the program with an .INCLUDE "Library.Asm" directive,
which causes the file "Library.Asm" to be included in the assembly. This is a file
which is included on the MacASM disk, and contains all the trap words for the various
Mac ROM calls, as well as some simple macro definitions, such as DEFV which
simulates the "define variable" directive, and GLOBAL which handles allocation of