[comp.sys.apple] IIgs TaskMaster and Tool dispatching

AWCTTYPA@UIAMVS.BITNET ("David A. Lyons") (07/31/88)

>Date:         Sun, 24 Jul 88 01:13:00 GMT
>From:         dogie!terranova%csd1.milw.wisc.edu@BRL.ARPA
>Subject:      Re: If the GS meant business...

>I am a Mac man, myself, but I would appreciate any info GS hackers/
>programmers can give me regarding similarities and differences between
>it and the Mac (when the GS is running in the graphics/window mode).

>Do programs get and handle events like the Mac?

Yes, window/graphics ones do.  They are "event-driven" just like on
the Mac.  (So the main program consists, for example, of a loop
calling GetNextEvent and then doing something depending on what kind
of event happened; then the loop continues & gets the next event.
Events are things like key-x-pressed, mouse pressed at x,y, mouse
released, window x comes to front or goes to behind, window x needs
to be redrawn.)

>What is the TaskMaster?  I have read a little about it on the net
>but don't understand too well.

TaskMaster is a part of the Window Manager that makes life much
easier for application programmers.  An application that uses
TaskMaster (lots do) calls TaskMaster in its main loop instead of
calling GetNextEvent.  TaskMaster starts off by calling GetNextEvent
all by itself and then, in many cases, doing the "normal" activity
to the kind of event that occured.  Eventually TaskMaster will
return an event to the application if there is something that the
application needs to handle itself.

Examples of TaskMaster events:  Mouse was pressed in window W at
location X,Y in the window's own coordinate system; Item X was
chosen from a menu; window W's go-away box was clicked.  Many other
things are handled automatically by TaskMaster, and the application
doesn't ever know about it (although it CAN find out what TaskMaster
did if it wants that information for some reason).  Some things that
TaskMaster does for you automatically (unless you ask it not to):
moving windows, resizing windows, zooming windows, opening desk
accessories, clsoing desk accessories, passing Edit menu selections
to desk accessories, allowing desk accessories to update themselves
periodically; scrolling windows; updating windows; activating and
deactivating windows and any controls they contain.

>How are the toolbox (toolsets?) calls handled/dispatched?

The X register is loaded with a 2-byte number; one byte specifies
the toolset and the other specifies the function within the toolset.
The first 8 functions are defined across ALL toolsets.  Any toolsets
function #1 is the BootInit function, called once when the system
first loads the toolset (or boots, if the toolset is in ROM).  2 is
StartUp; 3 is ShutDown; 4 is Version; 5 is Reset; 6 is Status
(checks whether a tool is on or off); 7 and 8 are reserved for
future use.  All the rest (up to #255) are specific to each toolset.

Anyway, once X is loaded with the right value for the tool you want
to call, you just call a fixed location:  JSL $E10000.  (This is for
System tools; for User tools, which few people use, JSL $E10008.)

(Parameter passing summary:  before making the call, PUSH room on
the stack for any results the tool will return; then push input
parameters; then make the call; then pull the results.)

The actual dispatching happens through a 2-level table lookup. First
the tool dispatcher uses the low byte of the X register to index into
a table of Function Table Pointers (FTPs).  Then the other byte is
used as an index into the function table just found for the
particular toolset, resulting in the address of the function to be
called.  Any of the FTPs can be moved to RAM if they aren't there
already, so patches can be made to them if buggy tools are
discovered.  (TOOL.SETUP makes some patches this way.)

>--------------------------------+----------------------------------------
>John C. Terranova               |  I said it.
>  CS, BS to be                  |  So, flame me.
>terranova@vms.macc.wisc.edu     |  No one else.
>--------------------------------+----------------------------------------

--David A. Lyons  a.k.a.  DAL Systems
  PO Box 287 | North Liberty, IA 52317
  BITNET: AWCTTYPA@UIAMVS
  CompuServe: 72177,3233
  GEnie mail: D.LYONS2