MacTech Network:   MacForge.net  |  Computer Memory  |  Register Domains  |  Printer Supplies  |  Cables  |  iPod Deals  |  Mac Deals  |  Mac Book Shelf


  MacTech Magazine

The journal of Macintosh technology

 
 
StuffIt

Magazine In Print
  About MacTech  
  Home Page  
  Subscribe  
  Archives DVD  
  Submit News  
  Submit a Tip!  
  Get a copy of MacTech RISK FREE  
Google
Entire Web
mactech.com
Mac Community
More...
MacTech Central
  by Category  
  by Company  
  by Product  
MacTech News
  MacTech News  
  Previous News  
  MacTech RSS  
Article Archives
  Show Indices  
  by Volume  
  by Author  
  Source Code FTP  
Inside MacTech
  Writer's Kit  
  Editorial Staff  
  Editorial Calendar  
  Back Issues  
  Advertising  
Contact Us
  Customer Service  
  MacTech Store  
  Legal/Disclaimers  
  Webmaster Feedback  
ADVERTISEMENT
Click Here
Volume Number:5
Issue Number:10
Column Tag:Kelly's Corner

After Dark™ and S.P.A.M.M.

By Dave Kelly, MacTutor Editorial Board

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

A Versatile Screen Saver

Ever since the invention of the CDEV, I have been fascinated with all the ideas that have surfaced which may be accessed from the control panel. Control panel DEVices were introduced to us when System 4.1/Finder 5.5 was released. The control panel is a way to extend user control over system functions. Among my favorite CDEVs is the Pyro™ screen saver with displays fireworks or by clicking a button in the control panel, Pyro™ displays a clock. This is a lot more interesting than simply blanking out the screen. There are quite a few public domain screen saver programs around and a few are commercially available.

A new CDEV has recently been released by Berkeley Systems. After Dark™ is not just another screen save CDEV. After Dark™ picks up where Pyro™ left off. After Dark™ is unique because it allows you (the user) to select which graphics display you would like to see when the screen blanks out. Thirteen modules have been included with After Dark™ which vary from Lissajous to messages to time warps. So what? Well, the best thing about After Dark™ and the reason I’m recommending it here in MacTutor is that you (the programmer) can program your own modules for use with After Dark™.

Another feature of After Dark™ is that you may initiate “Anti-Snoop Sleep” which means that you may assign a password to After Dark™ which will prevent anyone from awakening the screen without first typing the password. This is especially good if you have children (or other co-workers some of whom may still be children) nearby when you are working and want to take a break without your work being disturbed. Like Pyro™, you can put the screen to sleep by moving the mouse to the corner which you specify.

Is there life After Dark?

You can think of After Dark as the shell of the screen saver. It provides the support to handle your unique graphics module. The graphics modules reside in a folder in the system folder named ‘After Dark Files’. The module you have selected in the control panel will be loaded into memory by After Dark when the user places the pointer in a chosen corner of the screen, or after a specified delay. You can develop your own graphics modules in any development system which allows generation of code resources. The After Dark disk contains two example graphics modules written in C and Pascal for the MPW and Lightspeed programming environments. One is a generic graphics module which may be used as a skeleton for your own module and the other shows some of the more advanced features available in After Dark.

The manual explains the programming process in detail. In fact, anyone with only a fair amount of Macintosh programming experience can use the Generic Module and turn it into an exciting graphics display. After Dark sends messages to the module which ask the module to do certain tasks. In particular, first After Dark sends an Initialize message which is the cue for the module to allocate a Handle to memory and assign it to the storage parameter. This block of memory is locked down for use by the module and unlocked when returning from the module to After Dark. When the Blank message is sent, the module should blank the screen if desired. Then subsequent calls to the module will send the DrawFrame message which will do the bulk of the graphics routine. Finally, the Close message is sent so that the module will dispose of any memory which has been allocated and free it up for use by other Macintosh programs. In addition, another procedure is used to setup parameters which the module will use.

The parameters passed to each procedure in the module contain information which can help you in determining what monitors are in use, if Color Quickdraw is available and other important information. The manual explains the structure of the parameters and how to use them. In addition, you may set up buttons, sliders, popup menus, check boxes, and text strings. Any combination of up to four of these controls may be defined in unique resource types which After Dark recognizes. When After Dark sees these resources in the module, the resource is used to draw the controls in the control panel window (when it is open). The id number of the control on the first line is 1000, the second is 1001, and so on for up to 4 lines. The resource name is displayed with the control to describe it; for example, the resource name of the check box resource which is type ‘xVal’ is the name that is used with the check box. For your convenience, After Dark includes a template file for ResEdit which supports the After Dark resources to make it easier to create them. You can even include your own ‘clut’ resource for enhancing color graphics.

I’ve included a sample module which I wrote created based on the generic module provided with After Dark. After Dark is fun! Programming After Dark is a good way to experiment with graphics designs you may have or just write a quick routine to amaze your friends. You do have to be programming aware as you acquire and dispose of memory or you could have some unexplained crashes. Several hints are provided in the manual which should help to make your module crash free.

By the way, the pricing of After Dark is reasonable too. The program lists for $39.95. It was available at MacWorld Expo and is available now. Jack Eastman wrote After Dark and many of the modules. Patrick Beard wrote much of the example code and several modules. Bruce Burkhalter wrote example code, the technical manual, and a couple of the modules.

After Dark™ is available from:

Berkeley Systems, Inc.

1700 Shattuck Avenue

Berkeley, California 94709

(415) 540-5535

Price: $39.95

NOT COPY PROTECTED!!

Introducing S.P.A.M.M.

Don’t you just love those acronyms? Ok, you ask, just what does S.P.A.M.M. stand for? S.P.A.M.M. (System Program for Accelerated Macintosh Mathematics) is an INIT that speeds up arithmetic operations on the Mac Plus and SE for most applications. I’m not going to say much about this INIT, but if you are wishing that you could speed up your Mac Plus or SE, this is a cheap way to get a little boost in performance. You may not be able to tell any difference unless your application is math intensive. Depending on the test being run, S.P.A.M.M. has shown a 20% to 60% increase in speed. I personally only measured 20%, but I have to admit that I do most of my heavy computing on the Macintosh II.

The only annoying thing is that in order to install S.P.A.M.M. the master disk must be present for the user to enter name and organization information. Once the user name/organization information is entered, the INIT is completely copyable. It doesn’t bother me to have to type in my name etc., but I don’t like the idea of modifying the master disk for any reason. If this bothers you then I recommend you make a bit-copy of the master disk and use the backup.

Bravo Technologies, Inc.

P. O. Box 10078

Berkeley, CA. 94709-0078

(415) 841-8552

Price:

User ID Copy protection!

FOR MAC PLUS & SE ONLY!

Listing: BH Module.p
{Black Hole Module Module.p}
{A very simple graphics module for After Dark™}
{ Generic Shell by Patrick Beard and Bruce Burkhalter }
{ © 1989 Berkeley Systems Inc . }
{ module by Dave Kelly, © 1989 MacTutor}
unit BlackHole;
interface
 uses
 Quickdraw, GraphicsModuleTypes;

 function DoInitialize (var storage: Handle; blankRgn: rgnHandle; params: 
GMParamBlockPtr): OSErr;

 function DoBlank (storage: Handle; blankRgn: rgnHandle; params: GMParamBlockPtr): 
OSErr;

 function DoDrawFrame (storage: Handle; blankRgn: rgnHandle; params: 
GMParamBlockPtr): OSErr;

 function DoClose (storage: Handle; blankRgn: RgnHandle; params: GMParamBlockPtr): 
OSErr;

 function DoSetup (blankRgn: rgnHandle; message: integer; params: GMParamBlockPtr): 
OSErr;

implementation
 type
 BHStorage = record
 CircleRect: Rect; 
 {this is the rectangle for the circle to be drawn}
 CircleColor: integer;
 BlankingColor: integer;
 Center: Point;
 Origin: Point;
 ScreenRect: Rect;
 end;
 BHStoragePtr = ^BHStorage;
 BHStorageHandle = ^BHStoragePtr;

 function DoInitialize (var storage: Handle; blankRgn: rgnHandle; params: 
GMParamBlockPtr): OSErr;
{Allocate memory and initialize variables here}
 var
 result: OSErr;
 myStorage: BHStorageHandle;
 begin
{ allocate handle to my storage }
 myStorage := BHStorageHandle(NewHandle(sizeof(BHStorage)));

 if MemError <> noErr then
 begin
 DoInitialize := MemError;
 exit(DoInitialize);
 end;
 MoveHHi(Handle(myStorage));
 HLock(Handle(myStorage));{ Lock it down. }
 myStorage^^.circlecolor := blackcolor;
 myStorage^^.blankingcolor := blackcolor;
 storage := Handle(myStorage);
 { assign myStorage to passed handle }
 myStorage^^.screenrect := params^.qdGlobalsCopy^.qdScreenBits.bounds;
 myStorage^^.Center.h := params^.qdGlobalsCopy^.qdScreenBits.bounds.right 
div 2;
 myStorage^^.Center.v := params^.qdGlobalsCopy^.qdScreenBits.bounds.bottom 
div 2;
 myStorage^^.origin.h := 0;
 myStorage^^.origin.v := 0;
 myStorage^^.CircleRect := params^.qdGlobalsCopy^.qdScreenBits.bounds;
 InsetRect(myStorage^^.CircleRect, myStorage^^.Center.h, myStorage^^.Center.v);
 HUnlock(Handle(myStorage));
 DoInitialize := noErr;
 end;

 function DoBlank (storage: Handle; blankRgn: rgnHandle; params: GMParamBlockPtr): 
OSErr;
 begin
{Blank the screen.  You could also have “credits” appear on the screen 
here}
 FillRgn(blankRgn, params^.qdGlobalsCopy^.qdBlack);
 params^.brightness := params^.controlValues[1] * 255 div 100;
 DoBlank := noErr;
 end;

 function DoDrawFrame (storage: Handle; blankRgn: rgnHandle; params: 
GMParamBlockPtr): OSErr;
 var
 result: OSErr;
 myStorage: BHStoragePtr;
 { to hold dereferenced storage handle }
 dh, dv: integer; {horiz and vert change parameters}
 begin
{This function is repeatedly called by After Dark™.  This is where the 
main drawing is done.}
{lock our storage down so we can deference it once for faster access}
 MoveHHi(storage);
 HLock(storage);
 myStorage := BHStoragePtr(storage^);
 dv := -1;
 dh := -1;
 InsetRect(myStorage^.CircleRect, dh, dv);
 if PtInRect(myStorage^.Origin, myStorage^.CircleRect) then
 begin
 myStorage^.CircleRect := params^.qdGlobalsCopy^.qdScreenBits.bounds;
 InsetRect(myStorage^.CircleRect, myStorage^.Center.h, myStorage^.Center.v);
 forecolor(myStorage^.Blankingcolor);
 FillRgn(blankRgn, params^.qdGlobalsCopy^.qdBlack);
 if params^.controlValues[0] = 1 then
 case myStorage^.blankingcolor of
 blackcolor: 
 myStorage^.blankingcolor := whitecolor;
 whitecolor: 
 myStorage^.blankingcolor := redcolor;
 redcolor: 
 myStorage^.blankingcolor := greencolor;
 greencolor: 
 myStorage^.blankingcolor := bluecolor;
 bluecolor: 
 myStorage^.blankingcolor := cyancolor;
 cyancolor: 
 myStorage^.blankingcolor := magentacolor;
 magentacolor: 
 myStorage^.blankingcolor := yellowcolor;
 yellowcolor: 
 myStorage^.blankingcolor := blackcolor;
 otherwise
 myStorage^.blankingcolor := blackcolor;
 end
 else
 case myStorage^.blankingcolor of
 blackcolor: 
 myStorage^.blankingcolor := whitecolor;
 whitecolor: 
 myStorage^.blankingcolor := blackcolor;
 otherwise
 myStorage^.blankingcolor := blackcolor;
 end;
 end;
 if params^.controlValues[0] = 1 then
 case myStorage^.circlecolor of
 blackcolor: 
 myStorage^.circlecolor := whitecolor;
 whitecolor: 
 myStorage^.circlecolor := redcolor;
 redcolor: 
 myStorage^.circlecolor := greencolor;
 greencolor: 
 myStorage^.circlecolor := bluecolor;
 bluecolor: 
 myStorage^.circlecolor := cyancolor;
 cyancolor: 
 myStorage^.circlecolor := magentacolor;
 magentacolor: 
 myStorage^.circlecolor := yellowcolor;
 yellowcolor: 
 myStorage^.circlecolor := blackcolor;
 otherwise
 myStorage^.circlecolor := blackcolor;
 end
 else
 case myStorage^.circlecolor of
 blackcolor: 
 myStorage^.circlecolor := whitecolor;
 whitecolor: 
 myStorage^.circlecolor := blackcolor;
 otherwise
 myStorage^.circlecolor := blackcolor;
 end;
 params^.brightness := params^.controlValues[1] * 255 div 100;
 forecolor(myStorage^.circlecolor);
 frameoval(myStorage^.CircleRect);
 HUnlock(storage);
 DoDrawFrame := noErr;
 end;

 function DoClose (storage: Handle; blankRgn: RgnHandle; params: GMParamBlockPtr): 
OSErr;
{Deallocate your memory here.  You can also put something on the screen.}
 var
 myStorage: BHStorageHandle;
 begin
{deallocate our storage}
 myStorage := BHStorageHandle(storage);
 if (myStorage <> nil) then
 begin
 MoveHHi(storage);
 HLock(storage);
 if (params^.colorQDAvail = true) then
 begin
 end;
 DisposHandle(storage);
 end;
{check for memory errors}

 DoClose := noErr;
 end;

 function DoSetup (blankRgn: rgnHandle; message: integer; params: GMParamBlockPtr): 
OSErr;
 begin
{This is called when the used clicks on a button in the Control Panel.}
 DoSetup := noErr;
 end;

end.

Listing:  BH Module.proj.r
data ‘STR ‘ (128, “credits”) {
 $”29 42 6C 61 63 6B 20 48 6F 6C 65 2C 20 62 79 20"      
  /* )Black Hole, by  */
 $”44 61 76 65 20 4B 65 6C 6C 79 0D 20 A9 31 39 38"       
 /* Dave Kelly¬ ©198 */
 $”39 20 4D 61 63 54 75 74 6F 72"                     
  /* 9 MacTutor */
};

data ‘xVal’ (1000, “Use Color”) {
 $”00 00"                /* .. */
};

data ‘µVal’ (1000, “Use Color”) {
 $”00 01"              /* .. */
};

data ‘sVal’ (1001, “Intensity”) {
 $”00 1E”                        /* .. */
};

data ‘sUnt’ (1001, “Intensity Units”) {
 $”00 65 00 00 02 30 25 00 01 02 31 25 00 02 02 32"    
 /* .e...0%...1%...2 */
 $”25 00 03 02 33 25 00 04 02 34 25 00 05 02 35 25"    
 /* %...3%...4%...5% */
 $”00 06 02 36 25 00 07 02 37 25 00 08 02 38 25 00"    
 /* ...6%...7%...8%. */
 $”09 02 39 25 00 0A 03 31 30 25 00 0B 03 31 31 25"    
 /* .9%...10%...11% */
 $”00 0C 03 31 32 25 00 0D 03 31 33 25 00 0E 03 31"    
 /* ...12%.¬.13%...1 */
 $”34 25 00 0F 03 31 35 25 00 10 03 31 36 25 00 11"    
 /* 4%...15%...16%.. */
 $”03 31 37 25 00 12 03 31 38 25 00 13 03 31 39 25"    
 /* .17%...18%...19% */
 $”00 14 03 32 30 25 00 15 03 32 31 25 00 16 03 32"    
 /* ...20%...21%...2 */
 $”32 25 00 17 03 32 33 25 00 18 03 32 34 25 00 19"    
 /* 2%...23%...24%.. */
 $”03 32 35 25 00 1A 03 32 36 25 00 1B 03 32 37 25"   
 /* .25%...26%...27% */
 $”00 1C 03 32 38 25 00 1D 03 32 39 25 00 1E 03 33"    
 /* ...28%...29%...3 */
 $”30 25 00 1F 03 33 31 25 00 20 03 33 32 25 00 21"    
 /* 0%...31%. .32%.! */
 $”03 33 33 25 00 22 03 33 34 25 00 23 03 33 35 25"    
 /* .33%.”.34%.#.35% */
 $”00 24 03 33 36 25 00 25 03 33 37 25 00 26 03 33"    
 /* .$.36%.%.37%.&.3 */
 $”38 25 00 27 03 33 39 25 00 28 03 34 30 25 00 29"    
 /* 8%.’.39%.(.40%.) */
 $”03 34 31 25 00 2A 03 34 32 25 00 2B 03 34 33 25"    
 /* .41%.*.42%.+.43% */
 $”00 2C 03 34 34 25 00 2D 03 34 35 25 00 2E 03 34"    
 /* .,.44%.-.45%...4 */
 $”36 25 00 2F 03 34 37 25 00 30 03 34 38 25 00 31"    
 /* 6%./.47%.0.48%.1 */
 $”03 34 39 25 00 32 03 35 30 25 00 33 03 35 31 25"    
 /* .49%.2.50%.3.51% */
 $”00 34 03 35 32 25 00 35 03 35 33 25 00 36 03 35"    
 /* .4.52%.5.53%.6.5 */
 $”34 25 00 37 03 35 35 25 00 38 03 35 36 25 00 39"    
 /* 4%.7.55%.8.56%.9 */
 $”03 35 37 25 00 3A 03 35 38 25 00 3B 03 35 39 25"    
 /* .57%.:.58%.;.59% */
 $”00 3C 03 36 30 25 00 3D 03 36 31 25 00 3E 03 36"    
 /* .<.60%.=.61%.>.6 */
 $”32 25 00 3F 03 36 33 25 00 40 03 36 34 25 00 41"    
 /* 2%.?.63%.@.64%.A */
 $”03 36 35 25 00 42 03 36 36 25 00 43 03 36 37 25"    
 /* .65%.B.66%.C.67% */
 $”00 44 03 36 38 25 00 45 03 36 39 25 00 46 03 37"    
 /* .D.68%.E.69%.F.7 */
 $”30 25 00 47 03 37 31 25 00 48 03 37 32 25 00 49"    
 /* 0%.G.71%.H.72%.I */
 $”03 37 33 25 00 4A 03 37 34 25 00 4B 03 37 35 25"    
 /* .73%.J.74%.K.75% */
 $”00 4C 03 37 36 25 00 4D 03 37 37 25 00 4E 03 37"    
 /* .L.76%.M.77%.N.7 */
 $”38 25 00 4F 03 37 39 25 00 50 03 38 30 25 00 51"    
 /* 8%.O.79%.P.80%.Q */
 $”03 38 31 25 00 52 03 38 32 25 00 53 03 38 33 25"    
 /* .81%.R.82%.S.83% */
 $”00 54 03 38 34 25 00 55 03 38 35 25 00 56 03 38"    
 /* .T.84%.U.85%.V.8 */
 $”36 25 00 57 03 38 37 25 00 58 03 38 38 25 00 59"    
 /* 6%.W.87%.X.88%.Y */
 $”03 38 39 25 00 5A 03 39 30 25 00 5B 03 39 31 25"    
 /* .89%.Z.90%.[.91% */
 $”00 5C 03 39 32 25 00 5D 03 39 33 25 00 5E 03 39"    
 /* .\.92%.].93%.^.9 */
 $”34 25 00 5F 03 39 35 25 00 60 03 39 36 25 00 61"    
 /* 4%._.95%.‘.96%.a */
 $”03 39 37 25 00 62 03 39 38 25 00 63 03 39 39 25"    
 /* .97%.b.98%.c.99% */
 $”00 64 04 31 30 30 25"                               
 /* .d.100% */
};



Click here to find out more about our best subscription bundle deal ever!
2 years of the magazine, and the all new MacTech DVD ... at 70% off!



Click on the cover to
see this month's issue!

TRIAL SUBSCRIPTION
Get a RISK-FREE subscription to the only technical Mac magazine!
 
 


MacTech Magazine. www.mactech.com
Toll Free 877-MACTECH, Outside US/Canada: 805-494-9797

Register Low Cost (ok dirt cheap!) Domain Names in the MacTech Domain Store. As low as $1.99!
Save on brand compatible and name brank ink jet and laser supplies.
Save on long distance * Upgrade your Computer
Movies with No Late Fees!

See local info about Westlake Village
SJ * BRJ * BJ * OJ * NITS
Staff Site Links



All contents are Copyright 1984-2007 by Xplain Corporation. All rights reserved.

MacTech is a registered trademark of Xplain Corporation. Xplain, Video Depot, Movie Depot, Palm OS Depot, Explain It, MacDev, MacDev-1, THINK Reference, NetProfessional, NetProLive, JavaTech, WebTech, BeTech, LinuxTech, Apple Expo, MacTech Central 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.