TweetFollow Us on Twitter

ATalk Server
Volume Number:1
Issue Number:10
Column Tag:C Workshop

"Dial a Fortune Apple Talk Server"

By Robert B. Denny, Timothy T. Coad, Alisa Systems, Inc., MacTutor Editorial Board

It's been about six months since the AppleTalk network was released. Yet there seems to be little software available which uses this network. One reason is that the market is too small as yet and developers can't see enough potential to risk the investment. Another reason is that AppleTalk applications appear difficult to implement, requiring a great deal of knowledge and understanding that is not easy to obtain. Last, but certainly not least, Apple has failed to complete the basic services that history has shown are required for successful introduction of a computer network.

About six or seven months ago, Apple released a publication called Inside AppleTalk, available from the same source as Inside Macintosh. In addition, most developers who subscribed to the Apple "Software Supplement" have received The AppleTalk Manager: A Programmer's Guide, a part of Inside AppleTalk. These documents do a fairly good job of describing the network architecture and the details of using the AppleTalk services. If you have no experience with local area networks, however, you may get lost in the jargon and fail to "see the forest through the trees".

This month's C Workshop is devoted to AppleTalk. It includes a complete server application called Confucious which, when run on a Mac connected to the network, provides a "guru" service. A Mac Pascal client application is described by Alan Wootton in a separate article in this issue of Mac Tutor. The Pascal client, running on another Mac, locates the C server and makes requests for pearls of wisdom, which the server gladly sends back.

In order to keep this article's size reasonable, we assume that (1) you understand how to use the Mac's I/O services and (2) you have access to (at least) the AppleTalk Manager Programmer's Guide. The article describes the overall architecture of the AppleTalk network, and concludes with a listing of the server's code, written mostly in C. We'll look at programming details next month.

Fig. 1 - AppleTalk Components

NOTE: The descriptions given in this article are simplified so as to make it easier to understand the overall architecture of AppleTalk. Please consult the Apple documentation for full details.

Protocols and Layers

The lifeblood of any network is its suite of protocols that are used to negotiate and communicate. Usually, there are two agents in a network operation, the client and the server. The operation consists of a set of information exchanges between the client and the server, according to a protocol.

In order to bring some order to the chaos that would be created by a multitude of protocols, some of which are clients of other protocols and servers to yet others, network designers use the concepts of layers and interfaces. A layer implements a set of services via an interface. For example, the file system on the Mac has a layer that handles "raw" disk I/O (the device manager), and a layer on top of that which handles the organization of data on the disk into files and directories (the file manager). This separation of functions makes it possible to handle both hard disks and floppies with the same file manager routines. The file manager uses a defined interface to the device manager for its requests. Finally, the organization of data on the disk as files and directories is a sort of "spatial protocol".

Network architectures are normally divided into seven layers, according to the ISO "Open Systems Interconnection" convention adopted about five years ago. These layers, from lowest to highest are:

Physical: Electrical and mechanical aspects of communication circuits.

Data Link: Data and frame formats, bus access & contention protocols, error detection, other low level link services.

Network: Addressing and routing of messages between "sockets" transparently across multiple data links.

Transport: Error and flow control between sockets. Exchanges of information between routing agents on special sockets.

Session: Opening and closing logical links between sockets. Starting up remote servers on request. Naming of entities and name services.

Presentation: Cryptosystems, code conversion (e.g., ASCII to EBCDIC), other transformations needed for the native application environment.

Application: Protocols used between specific applications.

AppleTalk Architecture

Apple Computer has so far defined and published protocols for the physical through the transport layers of AppleTalk. Generally speaking, AppleTalk has a bus oriented, packet-based architecture, supporting internetworking, named objects, adaptive routing and a transaction-oriented transport service.

Services are implemented in a pair of I/O drivers and associated resources which are opened permanently on 512K Macs, and live in the system heap. On 128K Macs, applications which want to use the network must manually open the drivers, loading them into the application heap. This means that no "detached" service processes in the system heap can be supported on the smaller systems. Figure 1 shows the breakdown of AppleTalk functions and the drivers that implement them.

Physical & Data Link Layers: ALAP

The physical layer consists of a bus topology twisted-pair cable carrying electrical signals conforming to the EIA RS-422 standard. The Mac hardware has a "serial communications controller" (SCC) which is capable of being software configured as a standard async or sync port, or as an AppleTalk port. AppleTalk uses the printer port on the Mac.

The data link layer is implemented in software and uses the "AppleTalk Link Access Protocol" (ALAP) to manage usage of the common bus and to detect transmission errors between physically connected Mac systems. ALAP uses a frame format which is similar to that used by several well known block-oriented protocols such as HDLC. The algorithms used to manage multiple access to the bus are specific to AppleTalk, and fall into the category of "Carrier Sense Multiple Access" (CSMA).

Simply stated, the rules of CSMA are: (1) talk if no one else is talking; (2) if you want to talk and some one else is already talking, go away and try again later; (3) if two of you start talking at the same time, yell "Abort!" so everyone else knows, then both of you go away and try again later.

One other thing to note: The assignment of node numbers to each station on a network is not done by the user. Rather, the ALAP software tries to assign a random node number when the Mac is booted, then shouts it out over the net. If no one else objects, that is the node number to be used. Otherwise, another try is made.As an application developer, you'll rarely deal directly with ALAP.

Network Layer: DDP

The network layer uses the "Datagram Delivery Protocol" (DDP), which defines the format of the address header which is included in each packet and which stays with the packet between cooperating processes through communication endpoints called sockets. The path between sockets may span several physical links, and may go through intermediate systems. One Mac may have several AppleTalk connections open at a time, so the node number is not enough to identify a network address.

An address must consist of at least a node number and a socket number. In fact, AppleTalk considers a socket to be the one and only network-visible entity. Socket numbers fall into two groups. The "well-known" sockets (1-127) are assigned by Apple for specific generic network services and experimentation. The others (128-254) are called "dynamic" sockets. They are assigned temporarily and are often associated with a name managed by the Name Binding service of AppleTalk (see below).

Individual AppleTalk networks may be tied together to form an internetwork. Node numbers are unique only within a single physical network, so DDP requires that each network be assigned a network number. Figure 2 (see top of next page) shows a three-net internetwork. The Networks are connected by either a full bridge or a pair of half-bridges. The full bridge attaches directly to two physical networks and provides datagram routing from one to the other. The pair of half bridges does the same thing, but they use an intermediate transmission medium such as a long-distance telephone line.

Fig. 2 - An AppleTalk Internetwork

DDP defines an internet address consisting of a net number, a node number and a socket number. One might argue that the net number is superfluous, since the node number could be made unique within the entire internet. True, but the early local net designers at Xerox PARC decided that routing overhead should be minimized.

The key to their idea is that many nodes are attached to a single network, and that getting the packet to the proper local network is all that's needed to get it to the destination node. Normally, there are far fewer networks than nodes, so the routers have a much easier task. AppleTalk incorporates this network-oriented routing system.

The basic service provided by DDP is to "try its best" to get a packet from the source to the destination. If there is a problem somewhere, the packet is vaporized. DDP doesn't care about the details of link management or signalling, it only needs some sort of link service to it's neighbors in the net. Application developers rarely use the datagram services directly.

Routing Services: RTMP

The DDP internet routing process requires information as to the topology (interconnect configuration) of the internet. Each router involved in getting a DDP datagram from the source to the destination net must know where to send the datagram next. The routers use a set of routing tables to maintain this information.

The tables consist of a list of net numbers paired with the local node number of the bridge through which the shortest path to that net exists. These tables are dynamically constructed and maintained, with no need for a network manager to describe the topology. Automatic routing table maintenance is done by the routers carrying on a continuous chit-chat, proclaiming themselves as routers and broadcasting routing information for other routers, using the Routing Table Maintenance Protocol (RTMP).

Routing information exchange uses DDP at its communication medium, via socket number 1. Each Mac has a small RTMP-speaking process that keeps track of the nearest router and the network number of the local net. Bridges have a full-function RTMP-speaking process which engages in the prescribed chit-chat to maintain their routing tables. Bridges use this routing table to relay DDP datagrams according to their destination network number.

Transport Layer: ATP

The transport layer protocols are used to control the flow of data between sockets, and for end-to-end error recovery. Clients of the transport layer are offered some sort of "logical link" or "virtual circuit" service between themselves and other network visible entities.

Most networks are fairly similar in the first three layers, up through the network layer. Above that, however, their architectures begin to diverge. The transport layer is usually the first to reflect the main purpose for which the network was designed. AppleTalk is quite unusual in this respect.

Typically, the transport layer supports a two-way link between clients. Some sort of higher level protocol handles the opening of the link, and the transport layer provides error and flow control. The clients at each end can act as though they have an error-free hardwired line between them. AppleTalk does not support this sort of protocol.

Instead, AppleTalk has a transaction-oriented transport protocol, called AppleTalk Transaction Protocol (ATP). Here, one end acts as a requestor and the other acts as a responder. The responder usually sets itself up on a "permanent" socket. Requestors can "pop up" anywhere, at any time, and send requests. The example application at the end of this article is a responder.

The requestor sends a request which may carry with it up to 578 bytes of data in a single segment. The responder may send back up to eight such segments, for 4624 bytes total. If the request arrives in error, it is simply discarded. The requestor keeps trying until it receives a response. Response segments that are damaged are re-transmitted. This selective retransmission is handled by the ATP protocol, invisible to ATP clients.

Sometimes it is important that a request be serviced once and only once. An example of such a request would be to backspace a record in a remote file. Remember that the requestor repeatedly requests until it receives a response.

ATP provides a special class of transaction service called "exactly once". Each request is tagged with a transaction ID. The responder ATP has the logic needed to assure that the request with a given transaction ID is executed only once. The penalty for such service is extra overhead.

Named Entities: NBP

Recall that the only network-visible entities are sockets (socket clients, actually). Communication between processes on AppleTalk takes place between socket clients. A key feature of the network is that most objects are accessible by name rather than by address. Node numbers and dynamic socket numbers are assigned randomly. People prefer names.

The Name Binding Protocol (NBP) defines a set of services that applications can use to register names for their sockets, and to locate named entities. AppleTalk names consist of three fields: the object name, the type name and the zone name. The object name is the "name" as we usually think of it. The type indicates what sort of object it is. The zone field is not currently supported by AppleTalk and is always set to the value "*", meaning "this zone". The format of a name is:


The object and type fields in a name may contain the wildcard character "=" which stands for "all possible values". Thus the name "=:printer@*" means "all printers in this zone", or simply "all printers" since the zone concept is not yet supported.

Usually, a server will make itself available to the network by opening an ATP-responding socket, then registering itself by name, associating the name with its network address (net/node/socket). Then a client may lookup the server by name, or it may look up all servers of that type (using the "=" wildcard) then choose a particular one for use.

Limitations of AppleTalk

Now that we have an overview of the network architecture, let's look at the limitations of AppleTalk, especially its unusual transport layer protocol, ATP. Understanding these limitations is very important to you, as a developer. Unless Apple faces up to these limitations, you will be saddled with the responsibility of creating your own "session" oriented service, either on top of ATP or in addition to it. Let's see why.

Recall that ATP provides a transaction-oriented service. There is no provision for sequencing or otherwise grouping transactions. There is no "private wire" service between cooperating applications.

Consider a file server, whose ATP responding socket is visible to the whole network. Anyone, at any time, is free to issue an ATP request to the server's socket, and to expect a response. But file service implies a "context" spanning several transactions: an open file with a current file position.

This means that the file server must remember what's going on for each client who has a file open on that server. And a single client may have more than one file open, further complicating matters. The client and server need to set up a conversation which will continue across several transactions.

An open file is typical of a general class of network operations which require a private "session" to be maintained between the client and the server. This is the domain of the ISO session layer. AppleTalk has no session layer support.

You may say, "Well, at least ATP handles error and flow control; I can build sessions myself". But layering a session protocol on top of a "reliable transaction" protocol creates other problems. If we believe in internetworking, systems of interconnected AppleTalk bus networks, then we must face the problem of transport delay.

Suppose we want to set up an internet session, between sockets on nodes which are on different physical networks, separated by several bridges and perhaps a backbone network. The connection between client and server has plenty of speed capacity, but packets may be delayed up to 100 milliseconds in bridges and routers. ATP requires completion of a transaction before another can start. With a 100 mS delay from one end to the other, our transport protocol is capable of one transaction every 200 mS, or 5 transactions per second! Without the transport delay, the Macintosh ATP implementation is capable of hundreds of transactions per second.

It is important to understand that the degradation is not due to speed limits of the transmission medium, but instead due to the transport delay from one end to the other and ATP's need to complete a transaction before the next can be started. In an internetworking environment such as AppleTalk, transport delays are a fact of life. ATP is poorly suited as a transport protocol in such situations.

Another aspect of ATP is its asymmetry. An ATP request may carry up to 578 bytes of data. The response, on the other hand, can carry 8 times that amount of data. The responding socket is more or less permanent, the requesting socket is opened and closed for each request. The responder has no way of delivering an asynchronous message to the requestor. Data flow from the requestor to the responder has a higher overhead than that in the opposite direction.

These facts have caused some developers to set up responding sockets at each end of a client-server connection. This approach uses two sockets at each end (temporary requestor, permanent responder). But there is a limit to the total number of ATP sockets that may be open in the current version of AppleTalk, 6 requestors and 6 responders. So sockets are a precious quantity and this approach wastes sockets unnecessarily.

AppleTalk has no session layer, a severe architectural deficiency which will promote multiple "private" session protocols, some of which may be poorly designed for the internet environment. Session protocols are among the most difficult to design and test. Often, the theoretical behavior of the network used as the basis for protocol design turns out to be inaccurate. Error recovery in the session layer is probably the most complex design issue in networking.

There is another limitation that took me by surprise. AppleTalk does not support transactions between sockets on the same node. At first this might not seem to be too serious but, as any networking veteran will tell you, it is serious. If your node happens to be the one with a server you need, you can't get to it. Keep this in mind when designing AppleTalk applications: your application must handle the case where the server and client are on the same node.

A Sample AppleTalk Server

The rest of this article contains the sources for an example AppleTalk "Dial-A-Fortune" Server. Note that the main program is fairly simple, and that most of the AppleTalk access functions are broken out separately and written for general use. (See fig. 3 on the previous page.)

There is not room for explanation of the details, but much of the information you'll need to understand this program is covered in Alan Wootton's article in this issue. I will explain its operation next month, along with more about AppleTalk.

One last item: You do NOT have a copy of the file ATALK.H, which contains the structure definitions and constant definitions needed for AppleTalk I/O. The items required for this program will be published next month. The full ATALK.H will be available on a MacTutor Source Disk. Also, look for some interesting AppleTalk developer's tools from Consulair soon.

Resource File in RMaker Format
* DFServer.R - RMAKER source.
* Load linker output
Include Dev:DFServer.Rsrc
* Define the DIAL-A-FORTUNE SERVER Modal dialog.
 No Title
40 96 240 416


175 20 195 90

175 230 195 300

StaticText Disabled
5 80 20 310
AppleTalk Dial-A-Fortune

StaticText Disabled
20 72 35 310

StaticText Disabled
45 110 60 310
Confucious Say: 

StaticText Disabled
70 20 170 310
Press FORTUNE to get your Fortune or QUIT to ++ shutdown the AppleTalk 
Dial-A-Fortune Server.

* Entity string components
Type STR 

Type STR 

Type STR 

* Number of fortunes and the fortunes themselves.

Type STR 
One of the greatest sources of energy is pride in ++
what you are doing.

Type STR
Take a cannibal to lunch.

( more fortune strings ...)

Type STR
Every successful person has had failures but repeated failure is no ++
guarantee of eventual success.


  *Dial-A-Fortune AppleTalk™ Server Application
  *Written by:   Timothy T. Coad, Alisa Systems, Inc.
  *June, 1985
  *Written for:  Apple Computer MDS Development System and Consulair 
Mac C™
  *This program uses specific features of the MDS system and Mac C
  *and will almost certainly require modifications for other systems.
  *  LINKER COMMAND FILE (uses Mac C minimum library, output is read 
by RMaker)
  * !Start
  * /Output Dev:DFServer.Rsrc
  * /Type 'RSRC'
  * MacCLib
  * DFServer
  * $
  *Copyright (C) 1985, MacTutor Magazine
  *Permission granted to use only for non-commercial purposes.  This 
notice must be
  *included in any copies made hereof.  All rights otherwise reserved.
  *Warning: This code was edited for publication and may possibly contain 
minor errors

#define VERSION  "\032Experimental version 1.0.A"

#include"Lib:MacDefs.H"   /* The usual collection of Mac definitions 
#include  "Lib:TextEdit.H"
#include  "Lib:PBDefs.H"

#include"Lib:ATalk.H"/* AppleTalk definitions  to be published next month 

#define FALSE    0
#define TRUE1

#define DIALOG_ID128
#define FORTUNE_DI 6 /* Dialog Item number of Fortune item */

#define NUMOFSTRINGS_ID 128 /* Resource ID of fortune string count ('DATA') 
#define FIRSTSTR_ID131  /* Resource ID of first fortune string ('STR') 

  * Resource IDs of the three parts of server's Network Entity Name.
#define OBJECT_ID128 /* Object name (Confucious) */
#define TYPE_ID  129 /* Object type (Dial-A-Fortune) */
#define ZONE_ID  130 /* Our zone ('*' = 'This zone') */

  *Global Variables

NBPElem *ourName;/* -> Our registered name/skt (locked block) */
ATPBlockATPGetReq, ATPResp; /* Statically allocated I/O parameter blocks 
BDSRespBDS; /* Buffer Descriptor Structure for response */
char    ReqPkt[256]; /* Buffer to receive incoming requests */
char    RespPkt[256];/* Buffer for responses (fortune text) */
unsigned short NumOfStrings;/* Number of fortune string resources */
Handle  Fortuneitem; /* Handle to currently selected fortune string */

extern shortatpOpenSkt();
extern shortatpCloseSkt();
extern intGetReqComplete();
extern intFilterGlue();

  * Dial-A-Fortune Main Program
 unsigned short button, i;/* Locals, usage is obvious except as noted 
 Handle handle;
 DialogPtr dlog;
 unsigned short type;
 Rect rect;
 char fortune[256];
 InitDialogs (0);/* No restart function */
 InitCursor ();  /* Make arrow cursor */
 SaveA5();/* Save our A5 for async completion routines */

   * Allocate a non-relocatable NBPElem structure, request for an ephemeral 
responding socket 
   * and register ourselves on the net.
 ourName = (NBPElem *)NewPtr (sizeof(NBPElem));
 ourName->tuple.addr.skt = 0;
 ourName-> = 0;
 { /* Can't open a socket */
 DisposPtr (ourName);/* Release tuple storage */
 return;/* and exit. */
   * Get the three parts of the Network Entity Name and register ourselves 
using NBP.
 handle = (Handle)GetResource ('STR ', OBJECT_ID);
 i = pstrcpy(ourName->tuple.entity, *handle);
 ReleaseResource (handle);
 handle = (Handle)GetResource ('STR ', TYPE_ID);
 i += pstrcpy(ourName->tuple.entity + i, *handle);
 ReleaseResource (handle);
 handle = (Handle)GetResource ('STR ', ZONE_ID);
 pstrcpy(ourName->tuple.entity + i, *handle);
 ReleaseResource (handle);
 if(NBPRegister(2, 8, ourName))    /* Registration error? */
 atpCloseSkt(ourName->tuple.addr.skt); /* Yes, free the socket and ... 
 DisposPtr (ourName);/* ... release tuple storage. */
 return;/* Exit */
   * The number of fortunes is stored in a resource to make it possible 
to add new ones.
 handle = (Handle)GetResource ('DATA', NUMOFSTRINGS_ID); 
 NumOfStrings = (unsigned short)(*((unsigned short *)(*handle)));
 ReleaseResource (handle);

   * Prime the pump with the initial asynchronous ATP Get Request.
 GetATPRequest(&ATPGetReq, ourName->tuple.addr.skt, ReqPkt, 256, GetReqComplete);

   * Put up our dialog box.  Use a modal dialog filter procedure to handle 
the completion of the
   *  GetATPRequest.  The GetATPRequest completion routine posts an event 
which is filtered
   * and processed by the modaldialog filter procedure.
 dlog = (DialogPtr)GetNewDialog (DIALOG_ID, 0, -1);
 GetDItem (dlog, FORTUNE_DI, &type, &Fortuneitem, &rect);
 ParamText (VERSION, "", "", "");
 button = 0;
 while(button != cancel)
 ModalDialog (FilterGlue, &button);
 if(button == oK)/* Fortune button pressed? */
 { /* Yes, put up a fortune */
 SetIText (Fortuneitem, fortune);
 DisposeDialog (dlog);    /* Dispose of dialog */
 NBPRemove(ourName->tuple.entity); /* Remove us from net */
 atpCloseSkt(ourName->tuple.addr.skt); /* Free the socket */

  * SendFortune
  * Get a random STR resource, display in the server's dialog box, ship 
it back to the 
  * requestor as an ATP response packet and finally re-arm ourselves 
for another request.
 SetIText (Fortuneitem, RespPkt);
 SendATPResp(&ATPResp, &ATPGetReq.csParam.atpGetRequest.addr, 
 ourName->tuple.addr.skt, RespPkt, 256, &RespBDS,              
 ATPGetReq.csParam.atpGetRequest.transID, 0);
 GetATPRequest(&ATPGetReq, ourName->tuple.addr.skt, ReqPkt, 256, GetReqComplete);

  * GetFortune
  * Get a random STR resource, modulo number of strings.  Return pointer 
to string in memory.
char *fortune;
 Handle string;
 unsigned short index;
 index = FIRSTSTR_ID + ((unsigned short)Random ()) % NumOfStrings;
 string = (Handle)GetResource ('STR ', index);
 pstrcpy(fortune, *string);
 ReleaseResource (string);

  * AppleTalk Name Binding Protocol (NBP) Low Level I/O Routines

  * nbpRegister - Register an element with AppleTalk.
  * Returns the I/O result.
short nbpRegister(interval, count, elem)
unsigned char interval;   /* Retry interval, ticks */
unsigned char count; /* Number of retries */
NBPElem *elem;   /* -> Element with name to register */
 MPPBlock block;
 block.ioRefNum = mppRefNum;/* I/O is to the MPP driver */
 block.csCode = _nbpRegister; /* Function is "Register name" */
 block.csParam.nbpRegister.retry.interval = interval;    /* Fill in retry 
interval */
 block.csParam.nbpRegister.retry.count = count;    /* Fill in retry count 
 block.csParam.nbpRegister.verify = 1; /* Enable name clash checking 
 block.csParam.nbpRegister.elem = elem;/* Fill in -> name to register 
 return(PBControl(&block, 0));/* DO IT, return the result */

  * nbpRemove - Remove an entity from AppleTalk Registry.
  * Return the I/O result code.
short nbpRemove(entity)
Entity *entity;  /* -> Entity string for name to remove */
 MPPBlock block; /* I/O parameter block */
 block.ioRefNum = mppRefNum;/* I/O to .MPP driver */
 block.csCode = _nbpRemove; /* Function is "Remove name" */
 block.csParam.nbpRemove.entity = entity;          /* Fill in -> to entity 
string */
 return(PBControl(&block, 0));/* DO IT and return result */

  * AppleTalk Transaction Protocol (ATP) Low Level I/O Routines.

  * atpOpenSkt - Open an dynamic ATP responding socket.
  * Socket number set to 0 if it fails.  Returns the I/O result code.
short atpOpenSkt(skt)
unsigned char *skt;/* -> byte to receive assigned socket number */
 ATPBlock block; /* I/O Parameter block */
 block.ioRefNum = atpRefNum;/* I/O is for .ATP driver */
 block.csCode = _atpOpenSkt;/* Func is "Open Responding Socket */
 block.csParam.atpOpenSkt.skt = 0; /* Socket=0 for dynamically assigned 
*/ = 0;/* Zero internet fields */
 block.csParam.atpOpenSkt.addr.node = 0;
 block.csParam.atpOpenSkt.addr.skt = 0;
 *skt = PBControl(&block, 0) ? 0 : block.csParam.atpOpenSkt.skt; /* OPEN 
IT */
 return(block.ioResult);  /* Return result */

  * atpCloseSkt - Close an ATP responding socket.
  * Returns I/O result code.
short atpCloseSkt(skt)
unsigned char skt; /* Number of ATP socket to close */
 ATPBlock block;
 block.ioRefNum = atpRefNum;/* I/O is for .ATP driver */
 block.csCode = _atpCloseSkt; /* Function is "Close Resp. Socket" */
 block.csParam.atpCloseSkt.skt = skt;/* Fill in socket to close */
 return(PBControl(&block, 0));/* DO IT and return result */

  * SendATPResp - Send a single-packet ATP response. 
  * Currently, this routine only supports responses consisting of a single 
ATP packet.
  * The I/O parameter block is allocated statically because the I/O may 
be  asynchronous,
  * thus the block must stay around after this routine exits.  Same goes 
for the BDS,
  * which gets filled in here.
SendATPResp(ATPSendResp, Dest_NetAddr, SourceSkt, Resp, RespSize,
 atpRespBDS, TransID, asynch)
ATPBlock *ATPSendResp;    /* -> Statically allocated I/O parameter block 
AddrBlock *Dest_NetAddr;  /* -> Destination network address for response 
byte SourceSkt;  /* Local responding socket number */
char *Resp; /* -> response data */
unsigned short RespSize;  /* Length in bytes of response data */
BDS *atpRespBDS; /* Statically allocated Buffer Descriptor Scructure 
unsigned short TransID;   /* ID of transcation being replied to */
short asynch;    /* Boolean defining whether or not it is async. */
 unsigned short atpBDS();

 ATPSendResp->ioRefNum = atpRefNum;/* I/O is for .ATP driver */
 ATPSendResp->csCode = _atpSendResponse;     /* Function is "Send Response 
   * Copy Requestor's net address into parameter block
 bcopy(&((ATPSendResp->csParam).atpSendResponse.addr), Dest_NetAddr, 

 (ATPSendResp->csParam).atpSendResponse.skt = SourceSkt;       /* Responding 
Skt. */
 (ATPSendResp->csParam).atpSendResponse.bdsPtr = atpRespBDS;   /* Fill 
in -> BDS */
 (ATPSendResp->csParam).atpSendResponse.bdsSize = 1;           /* 1-packet 
resp. */
 (ATPSendResp->csParam).atpSendResponse.numOfBuffs = 1;        /* (same) 
 (ATPSendResp->csParam).atpSendResponse.flags = atpEOM;        /* 1st 
has EOM */
 (ATPSendResp->csParam).atpSendResponse.transID = TransID;     /* 
 atpBDS(atpRespBDS, Resp, RespSize); /* Fill in the BDS */
 if(asynch) /* Only 1/0 legal in PBControl */
 PBControl(ATPSendResp, 1); /* Do it asynchronously */
 PBControl(ATPSendResp, 0); /* Do it synchronously */
 return(ATPSendResp->ioResult);    /* Return result code */

  * GetATPRequest - Get an ATP Request
  * Issue an ATP "GetRequest".  If a non-NULL completion routine address 
is supplied, issue the
  * request asynchronously.
GetATPRequest(ATPGetReq, skt, ReqPkt, ReqPktSize, ioCompletion)
ATPBlock *ATPGetReq; /* Statically allocated I/O parameter block */
byte skt; /* Local responding socket on which to accept request */
byte *ReqPkt;    /* -> buffer to get filled in with request data */
unsigned short ReqPktSize;/* Size of request buffer, bytes */
ProcPtr ioCompletion;/* -> entry point of completion routine or NULL 
 ATPGetReq->ioRefNum = atpRefNum;  /* I/O is for .ATP driver */
 ATPGetReq->csCode = _atpGetRequest; /* Function is "Get Request" */
 (ATPGetReq->csParam).atpGetRequest.reqPtr = ReqPkt;     /* Fill in buffer 
data */
 (ATPGetReq->csParam).atpGetRequest.reqSize = ReqPktSize;
 (ATPGetReq->csParam).atpGetRequest.skt = skt;     /* Socket on which 
to receive req. */
   * Fill in completion routine address, and if non-NULL, issue asynch 
I/O otherwise
   * issue it synchronously.
 if((ATPGetReq->ioCompletion = ioCompletion)) != NULL)   
 PBControl(ATPGetReq, 1);
 PBControl(ATPGetReq, 0);
 return(ATPGetReq->ioResult); /* Return I/O result code */

  * Miscellaneous Low-Level Routines

  * GetReqComplete
  * ATP Get Request Completion Routine simply posts an event with a unique 
event/message pair.
  * When the event is identified by the modal dialog filter procedure, 
a fortune is returned to the
  * requestor and another GetRequest is issued.  Registers must be preserved 
because this routine
  * runs asynchronously, and may interrupt some other process, including 
a local fortune fetch.
  * It's written in assembler 
 Movem.La0-a6/d0-d7,-(sp) ; Save registers
 Move.L _SavedA5,a5; Restore A5 context
 Move.W #MouseDown,-(sp)  ; Event type = Mouse Down
 Pea    ATPGetReq; Event message is pointer to GetReq block
 _PostEvent ; Post it
 Movem.L(sp)+,a0-a6/d0-d7 ; Restore registers

  * FilterGlue - Interface for ModalDialog Filter Proc. Callback
  * This is a glue routine to get back into C.  It is called back from 
ModalDialog() with 
  * (naturally) Pascal-flavored arguments on the stack.  See the C Workshop 
in MacTutor
  * Vol. 1, No. 7 (June, 1985) and Inside Macintosh for more information 
on ModalDialog
  * event filter procedures.
 ; Inputs (Pascal callfrom ModalDialog):
 ;      4(SP)      Address of word to fill in with item number
 ;      8(SP)      Address of the event record
 ;     12(SP)      Dialog (window) pointer
 Link   a6,#0    ; no local automatics
 Movem.Ld1-d7/a1-a4,-(sp) ; Save regs
 Move.L 8(a6),d0 ; D0 -> Item number word
 Move.L 12(a6),d1; D1 -> Event record
 Move.L 16(a6),d2; D2 -> Window record
 Jsr    filter   ; Call C for dirty work
 Movem.L(sp)+,d1-d7/a1-a4 ; Restore regs
 Unlk   a6; "standard" Pascal routine exit
 Move.l (sp)+,a0 ; A0 -> return point
 Addq.L #6,sp    ; Pop args
 Addq.L #6,sp
 Move.B d0,(sp)  ; Copy C result to Pascal return
 Jmp    (a0); Return

  * filter - "Real" ModalDialog filter function
  * If there is a "phoney" mouse down event (with message = address of 
our GetReq block)
  * then we have received a fortune request.  In that case, send a fortune 
back to the requestor.
filter(ip, ep, wp)
short *ip;/* -> Word to receive dialog item code */
EventRecord *ep; /* -> Event record */
WindowPtr wp;    /* -> Window record for modal dialog */
 if(ep->what == mouseDown && ep->message == (long)&ATPGetReq)
 SendFortune();  /* Send a responding fortune */
 *ip = 0; /* No item was hit */
 return(TRUE);   /* Indicate that we handled the event */
 return(FALSE);  /* We didn't handle this event */

  * atpBDS- Setup an ATP Buffer Descriptor Structure.
  * Given a buffer-load of data to send, fill in a BDS which describes 
the buffer as possibly 
  * several ATP packets.  Return the number of ATP packets required to 
send the data as
  * a response.
unsigned short atpBDS(bds, buf, size)
BDS *bds; /* -> Buffer Descriptor Structure to fill in */
unsigned char *buf;/* -> Response data buffer */
short size; /* Size (bytes) of response data */
 unsigned short i; /* Counts number of segments */
 i = 0;
 while(size > 0) /* Loop till enough packets set up */
 bds->buffSize = (size > atpMaxData) ? atpMaxData : size;      /* Size 
of this packet */
 bds->buffPtr = buf; /* Fill in -> to this segment/packet */
 buf += atpMaxData;/* Advance segment pointer */
 size -= atpMaxData; /* Count down segment size */
 bds++; /* Advance BDS pointer to next seg. */
 i++;   /* Count a segment */ }
 return(i); /* Return segment count */

  * pstrcpy - Pascal String Copy routine.
  * Returns number of bytes copied, including count byte.
pstrcpy(d, s)
char *d;/* -> Destination string */
char *s;/* -> Source string */
 bcopy(d, s, *s + 1);
 return(*s + 1);

  * bcopy -  General purpose byte copy routine.
bcopy(d, s, n)
char *d;/* Destination address */
char *s;/* Source address */
short n;/* Number of bytes to copy */
 Move.L d0,a0    ; A0 -> Destination
 Move.L d1,a1    ; A1 -> Source 
 Bra.S  @1; Jump past to correct for dumb DBRA inst.
@0 Move.B (a1)+,(a0)+; Copy a byte
@1 Dbra.W d2,@0  ; Loop till done

  * SaveA5
 Lea    _SavedA5,a0  ; A0 -> Save cell 
 Move.l a5,(a0)     ; Save A5 
 Rts       ; Return
_SavedA5Dc.l0  ; Storage area for A5
Apple Inc.
Microsoft Corpora
Google Inc.

MacTech Search:
Community Search:

Software Updates via MacUpdate

Chromium 36.0.1985.143 - Fast and stable...
Chromium is an open-source browser project that aims to build a safer, faster, and more stable way for all Internet users to experience the web. FreeSMUG-Free OpenSource Mac User Group build is... Read more
Macgo Blu-ray Player - Blu-r...
Macgo Mac Blu-ray Player can bring you the most unforgettable Blu-ray experience on your Mac. Overview Macgo Mac Blu-ray Player can satisfy just about every need you could possibly have in a Blu-ray... Read more
Apple Motion 5.1.2 - Create and customiz...
Apple Motion is designed for video editors, Motion 5 lets you customize Final Cut Pro titles, transitions, and effects. Or create your own dazzling animations in 2D or 3D space, with real-time... Read more
A Better Finder Rename 9.39 - File, phot...
A Better Finder Rename is the most complete renaming solution available on the market today. That's why, since 1996, tens of thousands of hobbyists, professionals and businesses depend on A Better... Read more
PopChar X 6.6 - Floating window shows av...
PopChar X helps you get the most out of your font collection. With its crystal-clear interface, PopChar X provides a frustration-free way to access any font's special characters. Expanded... Read more
MacUpdate Desktop 6.0.2 - Install Mac ap...
MacUpdate Desktop 6 brings seamless 1-click installs and version updates to your Mac. With a free MacUpdate account and MacUpdate Desktop 6, Mac users can now install almost any Mac app on macupdate.... Read more
PDFpenPro 6.3.2 - Advanced PDF toolkit f...
PDFpenPro allows users to edit PDF's easily. Add text, images and signatures. Fill out PDF forms. Merge or split PDF documents. Reorder and delete pages. Even correct text and edit graphics! Create... Read more
PDFpen 6.3.2 - Edit and annotate PDFs wi...
PDFpen allows users to easily edit PDF's. Add text, images and signatures. Fill out PDF forms. Merge or split PDF documents. Reorder and delete pages. Even correct text and edit graphics! Features... Read more
OS X Yosemite 10.10 DP6 - Developer Prev...
Note: This is a Developer Preview. You must be a registered Apple Mac Developer to download this update. You can also sign up for the free OS X Beta Program to download and preview public beta... Read more
Flavours 1.1.15 - Create and apply theme...
Flavours is a Mac application that allow users to create, apply and share beautifully designed themes. Classy Give your Mac a gorgeous new look by applying delicious themes! Easy Unleash your... Read more

Latest Forum Discussions

See All

Go to Bed – An Interview With Touchfight...
Touchfight Games is an exciting new indie studio that was co-formed between game journalist and author Nathan Meunier, artist Leonard Kenyon, and programmer Jon Kenyon. Their debut game Go To Bed will be released this fall, and with all the... | Read more »
Assault Vector Review
Assault Vector Review By Rob Thomas on August 19th, 2014 Our Rating: :: SIMPLE STRATEGYUniversal App - Designed for iPhone and iPad While this hex-based warp ride is fine in theory, Assault Vector is a bit too simple to be... | Read more »
Tom Hanks’ Hanx Writer has Taken the App...
Tom Hanks’ Hanx Writer has Taken the App Store by Storm Posted by Jessica Fisher on August 19th, 2014 [ permalink ] iPad Only App - Designed for the iPad | Read more »
It Came from Canada: Galaxy Dash
With its use of well-established tropes like endless flying and sci-fi space shooting, the upcoming Galaxy Dash: Race to the Outer Run most likely won’t confound expectations. However, with its robust amount of opportunities for fun player... | Read more »
PromptSmart Review
PromptSmart Review By Jennifer Allen on August 19th, 2014 Our Rating: :: SNAPPY SPEECHGIVINGUniversal App - Designed for iPhone and iPad Offering you a teleprompter in your pocket, PromptSmart is immensely helpful for those who do... | Read more »
The Firm (Games)
The Firm 1 Device: iOS iPhone Category: Games Price: $.99, Version: 1 (iTunes) Description: RELEASE SPECIAL SALE 50%! Welcome to THE FIRM, Your profil retained our full consideration and we have the pleasure to inform you that your... | Read more »
They Need To Be Fed 3 (Games)
They Need To Be Fed 3 1.0.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0.0 (iTunes) Description: 360 degree gravity platforming is back! Run, jump, collect, avoid enemies and feed yourself to the monster at the... | Read more »
Who Wore it Best? Phantom Flower vs. And...
Who Wore it Best? takes a break from all the bloodshed to check out two decidedly tranquil and nature-loving puzzles games: Phantom Flower and And Then it Rained. [ Who Wore it Best? Phantom Flower vs. And Then it Rained is a post from... | Read more »
Sentinel 4: Dark Star Review
Sentinel 4: Dark Star Review By Jennifer Allen on August 19th, 2014 Our Rating: :: STURDY TOWER DEFENSEUniversal App - Designed for iPhone and iPad After 4 years, the latest entry to the Sentinel series is here. It’s not quite as... | Read more »
TrashEver2 - You can move your selected...
TrashEver2 - You can move your selected notes to trash box. 1.0.0 Device: iOS Universal Category: Productivity Price: $.99, Version: 1.0.0 (iTunes) Description: TrashEver is an application only for throwing away the note of Evernote... | Read more »

Price Scanner via

Razer Taipan Mouse For Gamers And Non-Gamers...
If you’re a serious gamer on either Mac or Windows PCs, a serious gaming mouse is a necessity for first-tier performance. However, even if like me you’re not much of a gamer, there’s still a strong... Read more
15-inch 2.2GHz MacBook Pro on sale for $1899,...
Adorama has the new 15″ 2.2GHz Retina MacBook Pro on sale for $1899 including free shipping plus NY & NJ sales tax only. Their price is $100 off MSRP, and it’s the lowest price available for this... Read more
Mid-Size Tablet Shootout Posted: iPad mini wi...
I ‘m curious about how many iPads Apple is actually selling these days. It’s been widely rumored and anticipated that new models with A8 SoCs, 2 GB of RAM, 8 megapixel cameras, and fingerprint... Read more
The 15 Biggest iPad Air Problems And How To A...
What’s this? Fifteen “biggest” problems with the iPad Air? Does that mean there are a lot of smaller problems as well? Say it isn’t so! My old iPad 2 has manifested no hardware problems in three... Read more
TYLT Syncable-Duo, 2-in-1 USB Cable With Appl...
TYLT has introduced the Syncable-Duo, a universal cable solution for charging and syncing data to smartphones and tablets. The Syncable-Duo eliminates the need for multiple cables by incorporating... Read more
Save up to $140 off MSRP with Apple refurbish...
Apple is offering Certified Refurbished iPad Airs for up to $140 off MSRP. Apple’s one-year warranty is included with each model, and shipping is free. Stock tends to come and go with some of these... Read more
2.5GHz Mac mini on sale for $549, save $50
B&H Photo has the 2.5GHz Mac mini on sale for $549.99 including free shipping. That’s $50 off MSRP, and B&H will also include a free copy of Parallels Desktop software. NY sales tax only. Read more
Chromebooks Are Actually Sometimes A Better C...
Mac360′s Kate MacKenzie notes that when Steve Jobs announced the post-PC era, he was assuming that the dominant post-PC device would be the iPad he was unveiling, or another Apple product like the... Read more
Files-Finder Edition 1.0 app Brings Finder/Ex...
Appsicum’s Files Finder App is designed for iPad users who miss the functionality of the OS X Finder and Windows’ Explorer on their tablet. Files-Finder Edition App is a complete tool having rich... Read more
Apple and Samsung Both Face Growth Declines I...
As the tablet PC market matures and growth slows, the dominance of market leaders Apple and Samsung is also weakening, according to the latest NPD DisplaySearch Monthly Tablet PC Panel Shipment... Read more

Jobs Board

Project Manager / Business Analyst, WW *Appl...
…a senior project manager / business analyst to work within our Worldwide Apple Fulfillment Operations and the Business Process Re-engineering team. This role will work Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** As businesses discover the power of Apple computers and mobile devices, it's your job - as a Solutions Engineer - to show them how to introduce these Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** As more and more people discover Apple , they visit our stores seeking ways to incorporate our products into their lives. It's your job, as a Store Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** Being a Business Manager at an Apple Store means you're the catalyst for businesses to discover and leverage the power, ease, and flexibility of Apple Read more
Project Manager / Business Analyst, WW *Appl...
…a senior project manager / business analyst to work within our Worldwide Apple Fulfillment Operations and the Business Process Re-engineering team. This role will work Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.