How to Write Macintosh Software
From the originals
13 scansMachine-transcribed text and image descriptions. Check the linked original for uncertain words or fine print.
These are transcribed pages from the documents, not the full publications. Open the original for the remaining pages.
Image 1
HAYDEN Macintosh Library BOOKS Apple Press How to Write Macintosh™ Software Scott Knaster
A book cover with a blue gradient background, orange top and bottom bands, a green wavy line, and a framed photo of a beige Macintosh computer with keyboard and mouse against a cloudy sky and gray ground.
Reading notes: Small logo text 'Apple Press' and 'HAYDEN Macintosh Library BOOKS' banner is stylized and was transcribed from its visible wording.
- Printed product names
- Macintosh
- Languages
- English
PDF page 1
HAYDEN Macintosh Library BOOKS Apple Press How to Write Macintosh Software™ Scott Knaster
A blue gradient book cover with an orange top band, a green wavy line, and a framed photo of a beige Macintosh computer with keyboard and mouse sitting on a gray surface under a cloudy blue sky.
Reading notes: Top-left logo reads Apple Press; the top band text is stylized script and may be read as 'Macintosh Library' with some uncertainty. The trademark symbol after Macintosh in the headline is a superscript TM and is transcribed as ™.
- Printed product names
- Macintosh
- Languages
- English
PDF page 2
How to Write Macintosh TM Software Scott Knaster #I HAYDEN BOOKS 1\ /Jivision of lloward lY. Sams & Comf)any 4.100 ut!st. 62nd Street /ndianaf)olls. Inc/Jana 46268 USA
Reading notes: Transcript intentionally left empty per supplied instructions; fields are drawn only from the supplied copy. The publisher line reads 'Division of Howard W. Sams & Company' in the supplied copy, but the OCR-style spellings ('1\ /Jivision', 'lloward lY.', 'Comf)any') are uncertain. The address line ('4.100 ut!st. 62nd Street') and city line ('/ndianaf)olls. Inc/Jana 46268 USA') contain OCR-style character errors and may be misread. The '#I' mark near the author name is unclear and may not be part of the printed text. Whether the printed title is 'How to Write Macintosh Software' depends on the supplied copy; reading order of the title, author and imprint is inferred.
- Printed product names
- Macintosh
- Languages
- English
PDF page 3
Apple believes that good books are important to successful com- puting. The Apple Press imprint is your assurance that this book has been published with the support and encouragement of Apple Computer Inc., and is the type of book we would be proud to publish ourselves. For Barbara and Jess Acquisitions Editor: BILL GROUT Developmental Editors: SCOT KAMINS/BILL GROUT Production Editor: RONNIE GROFF Composition and production: McFARLAND GRAPHICS & DESIGN, INC. Cover art: GEORGE BAQUERO Cover design: JIM BERNARD Library of Congress Cataloging-in-Publication Data Knaster~ Scott. How to write Macintosh software. Includes index. 1. Macintosh tCompulerJ-Programming. I. Title. 0/\76.8.M3K68 1986 005.265 86-14825 ISBN 0-8104-6564-7 Macintosh is a trademark of Mcintosh Laboratory, Inc., licensed to Apple Computer, Inc. Lisa, Finder, ln.<;ide Macintosh, Mac\Mite, MacPaint, and MacDraw are trademarks of Apple Computer, Inc. TMON is a trademark of ICOM Simulations, Inc. Copyright © 1986 by HAYDEN BOOK COMPANY. All rights reserved. No part of this book may be reprinted, or reproduced, or utilized in any form or by any electronic, mechanical, or other means, now known or hereafter in- vented, including photocopying and recording, or in any information stol'- age and retrieval system, without permission in writing from the Publisher. Printed in the United States of America 2 3 4 5 6 7 8 9 86 87 88 89 90 91 92 93 94 YEAR
Reading notes: OCR errors in 'Scott' and 'Macintosh' trademark line (e.g., 'Mcintosh', 'Mac\Mite') Catalog number '0/\76.8.M3K68' is garbled Printed date sequence '86 87 88 ... YEAR' is a printed reading-order artifact
- Printed product names
- Macintosh · Lisa · Finder · MacPaint · MacDraw · TMON
- Printed dates
- 1986 · 86-14825 · 86 · 87 · 88 · 89 · 90 · 91 · 92 · 93 · 94
- Languages
- English
PDF page 4
INTRODUCTION This book is for people who want to write software for the Macintosh. It's not an introductory book; you should be experienced in (or in the process of learning) a high-level language such as Pascal or C, or assembly language. It also helps to be familiar with the basics of how Macintosh programs are written. If you 've read or even skimmed Macintosh Revealed by Stephen Chemicoff or Inside Macintosh from Apple, you'll benefit from this book What This Book Will Tell You What's in this book that's not in the others just mentioned? This book explains lots of the mysteries and myths about Macintosh programming that aren't really covered anywhere else. It talks about how and where things are stored in memory. It discusses what things in memory may be moved around, and teaches you how to know exactly when they may be moved. It explains how to debug your applications using available debugging tools. It shows you how to examine your program's code to learn precisely what's going on when it runs. It also gives you dozens of facts, tips, and tricks that you can use to make your software more powerful. How This Book Was Written In my two years in the Macintosh Technical Support group at Apple, I've worked with hundreds of programmers in helping them write and debug their software. I've tried to put as much of my experience as possible into this book. I've also put in a lot of stuff that we've taught developers in our MacCollege training course. I wrote this book with several principles in mind: • No mysteries. I've tried very hard to explain things that people find confusing or puzzling about Macintosh programming and to leave nothing significant unexplained that's within the book's scope. iii
Reading notes: Missing line break in the phrase 'you'll benefit from this book' may indicate a lost period
- Printed product names
- Macintosh Revealed · Inside Macintosh
- Printed dates
- two years
- Languages
- English
PDF page 5
iv Introduction • No fuzziness. There's nothing more initating than a book that takes you to the brink of a great revelation, then wimps out with fuzzy, vague writing. This usually makes it obvious that the writer doesn't know any more and is Dying to get on to the next topic. I've tried to avoid fuzzi- ness by explaining things in depth. • No wizards. Sure, some people are smarter than others. It's not right, though, to withhold potentially useful infonnation because you don't trust people to use it co1rectly. I've hied to refrain from holding back infonnation. If it's a bad idea to use a particular feature or technique, I won't just say "don't," I'll tell you why. • All work and no fun is no fun. While we're going over all this stuff, it's a good idea to have some fun, too, so I've hied to keep the mood light enough to keep you awake, even while we work through the heavy subjects. If you use the infonnation presented in this book, you'll know an awful lot about the Macintosh, and your programs will be better. There's enough infonnation presented here that you may not absorb all of it as you read it through. Don't wony about that. You can reread it as many times as you like, at no extra charge. The Macintosh has gained quite a reputation for requiring a lot from a programmer. For various reasons, it was incredibly hard to create Macintosh software when the computer first appeared in Janumy of 1984. In the years that have passed since then, lots of things have happened to make Macintosh programming a little easier: • Dozens of programming languages and tools have been developed, most of them coming from outside of Apple. There are compilers for many languages, powerful debuggers, disk patching tools, and more. • More technical material on the Macintosh has been created. Apple has produced Inside Macintosh and technical notes, and many good (and bad) books on Macintosh programming have appeared. • The general level of knowledge in the programming community (wher- ever that may be-I think it's near Berkeley) has increased tremend- ously as Macintosh programmers eveiywhere have gotten smarter. • The Macintosh itself has become more powerful. The first Macintosh had 128K RAM and SOOK of disk space (if you had two disk drives). Today's Macintosh has up to 4 megabytes of RAM and as much disk storage as you want to pay for. Still, there are some things about Macintosh programming that aren't well known and aren't written down anywhere. In this book, I've hied to gather together lots of "mysterious" things and take all the mystery out of them. As you read, you'll discover that things aren't so hard to understand after all-they're just not well known.
Reading notes: OCR-style errors such as 'initating', 'infonnation', 'wony', 'co1rectly' and 'hied' appear in the source copy Heading is not clearly printed; 'Introduction' label appears with page marker 'iv' and may not be the primary heading
- Printed product names
- Macintosh · Inside Macintosh
- Printed dates
- 1984
- Languages
- English
PDF page 6
ACKNOWLEDGMENTS without these people, this book would not exist, and you would now be staring at nothing and looking very silly. Jim Friedlander of Macintosh Technical Support helped im- measurably. He read the entire manuscript several times and kept me honest; he wrote most of the programs in Part Three; and he helped me keep up my energy level with his enthusiasm. Martha Steffen, Apple Publishing Evangelist, helped me figure out how to get started and what was happening to me along the way. Scot Kamins, Writeur, encouraged me, told me funny jokes, and gave me a great review. I also stole ideas from his books. Caroline Rose inspired me by being the best technical writer I've ever known, and by writing Inside Macintosh, without which no other Macintosh technical books would be possible. Cary Clark and Russ Daniels were very smart (and still are) and taught me a lot of the stuff that appears in this book. Bryan Stearns, Ginger Jernigan, Mark Baumwell, Louella Pizzuti, Bill Dawson, and Rick Blair of Apple Technical Support put up with me whenever I rambled on about this book. Chris Espinosa invented the tree-crash metaphor used in Chapter 4, which is used with his permission, whether he knows it or not. Alain Rossmann gave me valuable ideas for the "Techniques" section and provided lots of enthusiasm. Mike McGrath gave me great advice on how to write a book and get it published and loaned me his copy of Author Law. Jean-Louis Gassee has encouraged creativity and fun at Apple in the post-Steve Jobs era. Guy Kawasaki changed my life, and I have the bumper sticker to prove it. Barbara Knaster created many of the figures, constructed Appendix E, fixed lots of stuff, and, most important, told me to do it and made me do it. v
- Languages
- English
PDF page 7
ABOUT THIS BOOK
ABOUT THIS BOOK This book is divided into three parts, plus appendices. Here's what you'll find: Part One is called "How It All Works." This part of the book con- centrates on general information about the Macintosh and how to program it, with an in-depth discussion on how things in RAM behave and misbehave. Chapter 1, "Getting Started," talks about what makes Macintosh programming different and presents a brief overview of development tools. Chapter 2, "Things in Memory," tells about the way things are stored in memory, what happens to them, and how you can manage them. Chapter 3, "More about Heaps and Fragmentation," describes some common memory management problems and how to avoid them. Part Two is called "Debugging," which kinda tells you what it's about. Chapter 4, "Debugging Macintosh Software," introduces some general thoughts about debugging, tells about the TMON debugger, and presents information about many of the most common problems that Macintosh programmers run into. Chapter 5, "Examining Compiled Code," shows you how to look at the object code produced by your high-level language program. Chapter 6, "More about Compiled Code," continues directly from Chapter 5, but it would have made one big, obnoxious chapter if it had been all together, so it's not. Chapter 7, "Real Live Debugging," presents an example program that has bugs in it and then uses an object code debugger to find and fix the problems. vii
Reading notes: Source text shows irregular spacing between words, which may reflect layout rather than exact spacing.
- Printed product names
- Macintosh · TMON
- Languages
- English
PDF page 8
viii About This Book Part Three is called "Tips, Tricks, and Techniques," and it's got some of each of those, including a few example programs. Chapter 8, "General Techniques, " presents stuff that's generally use- ful if you're writing Macintosh software. Chapter 9, "Toolbox Techniques," contains information on some goodies that will help you make better use of the Macintosh's User-In- terface Toolbox. Chapter 10, "Operating System Techniques," covers some good things to know about various parts of the Macintosh Operating System. Appendix A, "Assembly Language Overview," is very important if you're not familiar with 68000 assembly language. To use an object code debugger, you should be able to read 68000 code and understand what's going on. You don't have to be able to write assembly language. This appendix will tell you what all those strange instructions mean. You can read this appendix before reading Part Two or at any point that you think you need it. Even if you're already, a 68000 programmer, you might want to read it to learn some fine points. Don't forget about Appendix A. When you start to come across assembly language information that's unfamiliar to you, try reading Appendix A. It should help a lot. Appendix B, "Common Problems," lists some of the most common (and most fatal) errors that can cause a Macintosh programmer to lose sleep. Apppendix C, "Macintosh Plus, " summarizes the new features in the Macintosh Plus computer. Although there's Macintosh Plus information throughout the book, you can use this appendix as a single source of information. Appendix D, "A Guided Tour of Macsbug," presents detailed infor- mation about the Macsbug debugger that Apple distributes. Appendix E, "Debugging Quick Reference Guide," contains some charts that you'll find very handy when debugging. At the end of the book you'll find a glossary of whizzy terms.
Reading notes: Source contains OCR-style spacing and an apparent typo 'Apppendix C' in the text.
- Printed product names
- Macintosh Plus · Macsbug
- Languages
- English
PDF page 9
ix About This Book Conventions Used in This Book Whenever you see this typeface: GetNextEvent you'll know that it's the name of a call to the Macintosh User Interface Toolbox or Operating System, or a line of a Pascal, C, or assembly language program. All words in the text that are in boldface can be found in the glossary, except the ones that are names of books. Hexadecimal numbers are always preceded by a dollar sign, like this: $388 -$42 $40F7 A2. Numbers not preceded by a dollar sign are decimal numbers unless otherwise stated. Calls to routines in the Macintosh User Interface Toolbox and Operating System are referred to as system calls, ROM calls, traps, or A-traps, depending on the context. All these terms mean the same thing. "Workshop Pascal " is a generic term indicating either Macintosh Programmer's Workshop Pascal or Lisa Workshop Pascal. Note for C programmers: whenever you see Pascal-specific terms, you should substitute their C equivalents. Unless otherwise noted, the infor- mation is valid for both languages. Here are some Pascal and C terms that are equivalent in this book: Pascal procedure or function local variable c function automatic variable A paragraph that looks like this is an incidental note. It contains information that's interesting and useful, but not vital to the material. Warning A paragraph marked with this icon is a warning. Imagine Robby the Robot on Lost in Space saying, "Danger, Will Robinson!"
Reading notes: Source text contains a second-level heading 'Conventions Used in This Book'; primary heading taken as 'About This Book'. Typeface and boldface references cannot be verified from plain text.
- Languages
- English
PDF page 10
x About This Book Macintosh Plus This icon marks information that's specifically for the Macintosh Plus. Most of this information is also valid for the Macintosh 512K enhanced. Lookin Ahead You'll find this crystal ball icon on paragraphs that discuss products that have been announced by manufacturers, but haven't yet (at the time of the writing) become available. For example, information about the Macintosh Programmer's Workshop from Apple is marked with this icon. ~i---------- F ~ a _ c _ t .._ ___________________________________________ _.. -~ A sentence that looks like this is an important, simple truth that you should know. These sentences present facts that help to take the mystery out of Macintosh programming. Thin to Remember This icon, found at the end of each chapter, marks a list of key points and concepts that were introduced in that chapter. The Amazing Colossal Disclaimer There's a lot of technical information in this book. It's been reviewed carefully by several people, and all the known problems have been fixed. Just as with software, though, there may be undiscovered bugs. Also, as the Macintosh world evolves, things change. If you find anything wrong, I would very much appreciate it if you would write to me about it in care of Howard W. Sams & Co.
Reading notes: Possible OCR artifacts in the line 'F ~ a _ c _ t' and separator marks near the 'Fact' label.
- Printed product names
- Macintosh Plus · Macintosh 512K enhanced · Macintosh Programmer's Workshop
- Languages
- English
PDF page 11
xi About This Book What You Need to Use This Book To make the most of this book, you should be somewhat familiar with Pascal or C. You should also have access to a copy of Inside Macintosh, the technical reference manual for the Macintosh computers. In Part Two, we spend a lot of time looking at programs with a debugger. The debugger that's used for the examples is TMON, published by learn Simulations, a!ld it's generally regarded as the most powerful debugger available for the Macintosh. If you don't have TMON, you can do some debugging with Macsbug, the debugger that Apple distributes with a variety of software, including the Macintosh 68000 Development System and the Macintosh Software Supplement. This book presents a lot of specific information, such as examples of how compilers compile code. Although this specific information is very useful, you should realize that this book's true mission is to tell you that you should observe your program's behavior closely and figure out for yourself what's going on. In particular, the compiled code examples given in Part Two are correct for Workshop Pascal, but may be different for other Pascal and C compilers. The only way to know how your compiler does things is to look at the code it produces. How to Learn More The best way to learn more about Macintosh programming is to write programs! A good source of information is your local user's group. Many user's groups have special-interest groups for programmers, and most groups publish newsletters. You might also want to join an on-line bulletin board service. These services are frequented by Macintosh fanatics who are able to answer almost any Macintosh programming question, or at least point you in the right direction. These services also contain lots of public domain software that you can download, including the latest goodies from Apple. There are also a number of good books available, such as books specifically for Pascal, C, or assembly language programming on the Macintosh. More books are appearing constantly, so keep checking your favorite bookstore. One reason there's so much third-party software that runs on Apple computers is that Apple has a lot of programs that help developers in a variety of ways. These programs include marketing assistance, developer-programmer matchmaking, technical support (of course), and more. In addition, Apple distributes lots of different products, like tech-
Reading notes: Text ends mid-word at 'tech-' and is truncated at the page edge Line-break hyphenation in 'debugging' and 'bulletin board' may affect reading order
- Printed product names
- Inside Macintosh · TMON · Macsbug · Macintosh 68000 Development System · Macintosh Software Supplement · Workshop Pascal
- Languages
- English