[Ajay Nath has two B.A.s, one in Chemistry and one in Mathematics. He is currently a second year medical student and is using Macs to develop Color Vision tests.]

AACK OR ATApp?

Example AppleTalk programs have appeared before in MacTutor but none recently except in one of the HyperCard columns. The introduction of MultiFinder, a new interface to the AppleTalk routines and new features added to AppleTalk itself, have changed the way applications should use AppleTalk. In this article I present a program called AACK, the AppleTalk Application Construction Kit, which was written in LightSpeed Pascal 2.0, which demonstrates how to use the new AppleTalk interface and how to use the background features of MultiFinder. The resources of the program were created by ResEdit and stored in a file called aack.rsrc, a rez description of the resources is found in the file resources.r. The code of the program is in 4 files/units as follows:

FILE/UNIT CONTENTS

globals.p global declarations

lowlevelATprocs.p low level procs

hooks.p code specific to the application

main.p generic application code

The code is designed to be easily modifiable. By simply changing code in the file hooks.p the nature of the applications produced can be changed. For example, in the file main.p, the code that handles menu selections look like:

where the function HookedMenuChoice is declared in the file/unit hooks.p. It returns false if it DIDNT handle the menu choice, it allows the programmer to hook or handle menu choices before the applications generic code does and to override the generic codes response. For example, the generic code of AACK simply puts up a windows, some menus, and allows the user to see others of his type on the network and to confirm their presence. There is a menu titled Special which has items labeled LookUp, Confirm and Send. The generic code handles the first two items (this can be overridden) but does nothing but beep when Send is chosen. By changing the code in the hooks.p file, you can create an application that does something else with AppleTalk, perhaps sending strings through the net as was shown in a previous MacTutor article. There is obviously a code/speed overhead introduced by using this method, but its far more easy to get something to work and to later go back and optimize than to start each application from scratch. (Maybe I should have called it ATApp: The Expandable Macintosh AppleTalk Application?)

Bypassing Generic (Brand?) Code OR OverRidem CowBoy!

Most of the generic code is trivial stuff to MacTutor readers and I have left out some things such as handling DAs which is left to the reader as an exercise. The code does use LSPs ability to have compiler variables. I declare a compiler option called TALK_DEBUG and set it to TRUE when I want the compiler to include certain debugging code in the app. Basically, the generic code does a SetUp routine and lets the code from the Hooks unit do any SetUp - i.e. - the generic routine SetUpGlobals does its SetUps and then calls the procedure SetUpHooksGlobals, which lets the Hooks code do its SetUps. Similarly the generic code lets the Hooks code do any Window and AppleTalk SetUps after it has done its own such SetUps. The generic code also checks to see if the Hooks code has decided to take over the duties of taking care of the applications window by examining a global Boolean variable called UserWindowProcsChanged which the Hooks code can set to true in its SetUp code. For example when activating the UserWindow the generic code does the following:

One consequence of this is that even if the Hooks code wants to override only one of the procedures that controls the windows activation, deactivation, updating, or disposal, it must override them ALL. You only have to copy and paste the generic code from the file main.p into the file hooks.p to mimic the generic codes handling of the other procedures though. For example, you might write an app using AACK which receives/sends messages and overrides the way the generic code draws the windows contents to draw any received messages at the bottom of the window, but it wouldnt need to override any other of the generic codes window handling routines. You could just copy the other generic code routines from the file main.p and pasted them into the right places in the file hooks.p.

Generic AppleTalk Code OR AppleTalk is cheap

The AppleTalk generic code does the following:

1) calls MPPOpen and then SysEnvirons which returns to us among other information, the type of machine were running on and the version of AppleTalk available. We exit if were not running on at least a 512KE, and if we are, set a boolean variable called NewCallsExist to true if the AppleTalk driver version supports the new AppleTalk calls

2) opens an ATP socket

3) calls WaitNextEvent a few times to make sure our dialog that lets the user select a name comes up in front and lets the user register on the network with a name (1->31 chars)

4) depending on the setting of a compiler variable called TALK_DEBUG  tries to call PSetSelfSend, a new AppleTalk call which lets you send AppleTalk packets to your own node. This is useful if your network consists of one machine as mine does, unfortunately this feature is implemented only on machines with the drivers with version numbers >= 48, (actually its listed as 48 in IM V but 45 in the MPW Assembler Equates, which is it Apple?)

5) then the generic code lets the Hooks unit do any AppleTalk SetUps, (such as post asynchronous GetRequests if it was going to receive requests)

If all of the above goes well then the generic code sets up its Menus, lets the Hooks unit do any of its menu setups, then the generic code sets up its window and lets the Hooks unit modify that window or set up any of its own and were off into our event loop!

MultiFinder and AppleTalk OR ASYNC or swim!

The generic codes event loop calls WaitNextEvent (you already know how to check for the presence of WNE so I dont do this) and calls a procedure called AppleTalkCallChecks before it handles any events. This procedure is going to check for any ASYNC calls that may have finished and handle them. For example, the generic code calls PLookUpName ASYNChronously, this allows the user to start a LookUp to see if any other users of the same type are on the network, and work on other things while the LookUp is begin done. This IS after all is what MultiFinder is for! The tricky part of making ASYNC calls is knowing when theyve finished and taking care of them when they do finish. I solve this problem by using Completion Routines and special data structures. I got the idea from Tech Note #180 - MultiFinder Miscellanea, in which it is suggested that applications making ASYNC calls store their A5 somewhere RELATIVE to the parameter block which they use to make the ASYNC calls, so that when their Completion Routines are executed they can load the applications A5 and set a global variable to indicate that an ASYNC call has finished. I use a similar approach. I define the following structure in the file globals.p:

When a call is made using a record of this type the field PbInUse is set to TRUE and CallDone is set to zero. The Completion Routine that is executed when the call finishes sets the CallDone field to -1.

The routine AppleTalkCallChecks (called once through each event loop) just checks the CallDone field of the record and if it is non-zero we know that an ASYNC call has just completed. The advantages of this method are as follows:

1) the Completion Routine used is VERY simple, as it must be since Completion Routines cannot make any calls that affect memory, all it does is set the CallDone field to a non-zero value. The completion routine is declared in LSP in the following way in the file lowlevelATprocs.p:

2) we dont have to worry about whether our A5 is valid when our Completion Routine runs

The drawbacks of using this method are that we must check our ASYNC calls EVERY time through our event loop and that the parameter blocks we use to make them MUST be global variables so that we can check them.

Using the PREFERRED interface OR Learning to AppleTalk all over again

Wed like to use the (new) preferred AppleTalk interface because its more robust, and if were running with the right versions of the AppleTalk drivers we can use the new AppleTalk calls. Information about the new AppleTalk calls is in IM V (and I suppose, in Inside AppleTalk which is available from APDA which I dont have). There are two different types of parameter blocks defined in the new interface, the ATPParamBlock and the MPPParamBlock, and you just fill in the fields necessary for the call you want to make and then pass a ptr to the ParamBlock to the function youre calling - i.e. -

{5}
err = PCallName (@ParamBlock, true or false for ASYNC);

The catch is that when filling out the fields in parameter blocks for OLD AppleTalk routines that you call with the NEW interface, you use the information from Calling the AppleTalk Manager routines from Assembly Language from IM II. Look at the pages in IM V which describe the new types, it shows which fields have to be filled with which values to make a call. Some field names have changed though, so be careful, make sure youve filled them out right - then check them again!

New (and Improved?) AppleTalk Calls OR Dont LookUp before you leave

A few new AppleTalk calls are quite useful to us, for example, the generic code of AACK does ASYNC LookUps, but what happens if the user quits BEFORE the LookUp completes? If the application just quit, then sooner or later that ASYNC call would complete and the Completion Routine (which is no longer around) would be called and BOOOOM! If we dont have access to the new calls then we just have to wait till the ASYNC call completes which we can do by:

while CallDone = 0 do
;

, which just waits till a particular call is done before proceeding. There is however a new call, PKillNBP, which allows us to kill pending calls, (but if it fails we will have to wait the call out). Note that IM V in some places incorrectly lists which ParamBlock, ATP or MPP to use, this call requires an MPPParamBlock. The generic code also uses the call PSetSelfSend to allow the user to receive/send packets to his own node, a feature of the new AppleTalk drivers which is useful to programmers, but we must be careful to restore the state of this flag - i.e. - if it wasnt enabled when we started, then we should disable it when we leave.

The future OR Everybody AppleTalks but nobody DOES anything with it

Should the PConfirmName calls be made ASYNC? Ill leave it to you as an exercise. Ive already written an application (modifying ONLY the file hooks.p) which uses the AACK shell to receive/send strings (Str255s actually). If anyone is interested in seeing it, let Dave Smith at MacTutor know and Ill write it up, its code will be shorter than this article but it may take longer to explain.

Using PSetSelfSend on a Mac Plus OR AppleTalking to yourself on a Plus

Ive found a way to get the new AppleTalk drivers running on my Mac Plus and I can test my AppleTalk code on my network of one using PSetSelfSend to enable me to send packets to myself. Those of you who are thinking, Thats easy, just copy the DRVR resources out of the latest System File and paste them into the System File you use on your Mac Plus!, are thinking along the wrong lines. The new drivers are in the Mac II ROM and perhaps the SE ROM (I dont have one to test). Im not sure its a good idea to use the new drivers on a Mac Plus, but I havent had any problems with my system (yet). Apple must have some reason not to make the new drivers available for the Mac Plus so I wont pass this information along unless anyone out there is interested and Apple says its OK (youve figured out how to do it though, right?).

Id like to thank K.S. without whose love and support this article would not be possible.

Software Updates via MacUpdate

Hopper Disassembler 4.3.16- - Binary dis...

Hopper Disassembler is a binary disassembler, decompiler, and debugger for 32- and 64-bit executables. It will let you disassemble any binary you want, and provide you all the information about its... Read more

Default Folder X 5.2.2 - Enhances Open a...

Default Folder X attaches a toolbar to the right side of the Open and Save dialogs in any OS X-native application. The toolbar gives you fast access to various folders and commands. You just click on... Read more

EtreCheck 4.0.1 - For troubleshooting yo...

EtreCheck is an app that displays the important details of your system configuration and allow you to copy that information to the Clipboard. It is meant to be used with Apple Support Communities to... Read more

Carbon Copy Cloner 5.0.9 - Easy-to-use b...

Carbon Copy Cloner backups are better than ordinary backups. Suppose the unthinkable happens while you're under deadline to finish a project: your Mac is unresponsive and all you hear is an ominous,... Read more

QuickBooks 17.2.25.638 R26 - Financial m...

QuickBooks helps you manage your business easily and efficiently. Organize your finances all in one place, track money going in and out of your business, and spot areas where you can save.
Built for... Read more

Monosnap 3.4.10 - Versatile screenshot u...

Monosnap lets you capture screenshots, share files, and record video and .gifs!
Features
Capture
Capture full screen, just part of the screen, or a selected window
Make your crop area pixel... Read more

Vivaldi 1.14.1077.50 - An advanced brows...

Vivaldi is a browser for our friends.
In 1994, two programmers started working on a web browser. Our idea was to make a really fast browser, capable of running on limited hardware, keeping in mind... Read more

Viber 8.2.0 - Send messages and make fre...

Viber lets you send free messages and make free calls to other Viber users, on any device and network, in any country!
Viber syncs your contacts, messages and call history with your mobile device, so... Read more

QuickBooks 17.2.25.638 R26 - Financial m...

QuickBooks helps you manage your business easily and efficiently. Organize your finances all in one place, track money going in and out of your business, and spot areas where you can save.
Built for... Read more

Carbon Copy Cloner 5.0.9 - Easy-to-use b...

Carbon Copy Cloner backups are better than ordinary backups. Suppose the unthinkable happens while you're under deadline to finish a project: your Mac is unresponsive and all you hear is an ominous,... Read more

Latest Forum Discussions

Our top 5 characters from casual RPG Cre...

Creature Quest definitely lives up to its name with a host of collectible creatures based on fantasy tales and world mythologies. To celebrate Creature Quest’s first birthday, we’re going to lay out what we think are the five best characters in the... | Read more »

Around the Empire: What have you missed...

Did you know that Steel Media has a whole swathe of other sites dedicated to all aspects of mobile gaming? Sure you'll get the very best iPhone news, reviews, and opinions right here at 148Apps, but we don't want you missing out on a single piece... | Read more »

All the best games on sale for iPhone an...

Oh hi there, and welcome to our round-up of the best games that are currently on sale for iPhone and iPad. You thought I didn't see you there, did you, skulking behind the bushes? Trust me though, the bushes aren't where the best deals are. The... | Read more »

The Battle of Polytopia Guide - How to H...

A new update just released for The Battle of Polytopia (formerly Super Tribes), which introduces online multiplayer. For all the fans of Midjiwan’s lite take on Civilization, this is certainly welcome news, but playing online isn’t as easy and... | Read more »

Here are the very best mobile games to p...

It's Valentine's Day! Did you get loads of cards and chocolates and other tacky, simple expressions of human affection? Did you send out tat because you find it almost impossible to express emotion unless there's a section dedicated to it at your... | Read more »

A laid-back mix of RPG and TCG, Creature Quest is all about building your deck, evolving your creatures and winning in battle. It’s the creation of VC Mobile, set up by Might and Magic producer Jon Van Caneghem. There are elements of that classic... | Read more »

Check out this awesome hands-on with the...

Well, PlayerUnknown's Battlegrounds has come out on mobile. This isn't a clone, this isn't a riff on the battleroyale mechanics of the game, it's the official mobile port by Tencent. But there's a little bit of a hitch.
[Read more]
| Read more »

Hostage Negotiator (Entertainment)

Hostage Negotiator 1.1.0
Device: iOS Universal
Category: Entertainment
Price: $3.99, Version: 1.1.0 (iTunes)
Description:
Official app of the board game by AJ Porfirio and Van Ryder Games.
In Hostage Negotiator, you play the part of... | Read more »

Price Scanner via MacPrices.net

Saturday Sale: Amazon offers 13″ 1.8GHz/256GB...

Amazon has the 13″ 1.8GHz/256B Apple MacBook Air on sale today for $250 off MSRP including free shipping:
– 13″ 1.8GHz/256GB MacBook Air (MQD42LL/A): $949.99, $250 off MSRP
Their price is the lowest... Read more

Roundup of Apple Certified Refurbished 12″ Ma...

Apple has Certified Refurbished 2017 12″ Retina MacBooks available for $200-$240 off the cost of new models. Apple will include a standard one-year warranty with each MacBook, and shipping is free.... Read more

Apple offers Certified Refurbished 10″ and 12...

Apple is now offering Certified Refurbished 2017 10″ and 12″ iPad Pros for $100-$190 off MSRP, depending on the model. An Apple one-year warranty is included with each model, and shipping is free:
–... Read more

Apple Canada offers Certified Refurbished Mac...

Canadian shoppers can save up to $560 on the purchase of a 2017 current-generation MacBook Pro, MacBook, or MacBook Air with Certified Refurbished models at Apple Canada. Apple’s refurbished prices... Read more

Adorama has the 8-core iMac Pro on sale for $4799 including free shipping plus NY & NJ sales tax only. Their price is $200 off MSRP, and it’s the currently lowest price available for an iMac Pro.
Read more

Sale! Walmart lowers prices even more on 9″ i...

Walmart has lowered their sale price on 9.7″ Apple iPads to $80 off MSRP for a limited time. Sale prices are for online orders only, in-store prices may vary:
– 9″ 32GB iPad: $249.99 $80 off
– 9″... Read more

Roundup of 13″ MacBook Pro sales, models avai...

B&H Photo has 13″ MacBook Pros on sale for up to $200 off MSRP. Shipping is free, and B&H charges sales tax for NY & NJ residents only. Their prices are the lowest available for these... Read more

MacTech is a registered trademark of Xplain Corporation. Xplain, "The journal of Apple technology", Apple Expo, Explain It, MacDev, MacDev-1, THINK Reference, NetProfessional, Apple Expo, MacTech Central, MacTech Domains, MacNews, MacForge, and the MacTutorMan are trademarks or service marks of Xplain Corporation. Sprocket is a registered trademark of eSprocket Corporation. Other trademarks and copyrights appearing in this printing or software remain the property of their respective holders. Not responsible for typographical errors.

All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.