TweetFollow Us on Twitter

Monkey CDEV
Volume Number:3
Issue Number:9
Column Tag:C Workshop

CDEV Extends Control Panel

By Jan Eugenides, Assembly Corner, Maynard, MA

The new control panel that comes with System 4.1 is extensible. You can write a code resource called a ‘cdev’ to add functions to the control panel. The process is not difficult, and it offers a number of interesting possibilities.

What I had in mind for this project was to write a fairly simple cdev, just to test the waters. Having just acquired a Macintosh II, I also wanted to explore some of the sound generation capabilities. The result is Monkey, an amusing addition to the control panel. Although this particular cdev will only work on a Macintosh II (because it calls the Mac II’s sound routines), the techniques shown here will work for more generalized cdevs as well.

The Control Panel

Figure 1 shows the new Control Panel with the General panel displayed. The panel allows choosing the Desktop pattern, setting the rate of insertion point blinking, setting the time, and more. Some other standard panels allow setting keyboard options, sound options, and display options.

By writing your own cdev, you can add a new icon to the scrollable list that appears on the left edge of the Control Panel. In Figure 1, you can see the icon for the Monkey cdev at the bottom. Clicking on an icon selects it, and the Control Panel displays various controls, depending on the item list contained in the corresponding cdev. Figure 2 shows how the Control Panel appears when Monkey is selected. Clicking on the picture of a monkey causes the Macintosh II to generate the a monkey screech sound.

How It Works

When the user opens the Control Panel, it scans the System Folder for all resource files of type ‘cdev’. When it finds one, it loads the icon and the file’s name and adds it to the icon list. After all the cdevs are loaded, the General icon is selected and the standard controls are displayed. The Control Panel then calls the cdev with various event messages, indicating which items the user has clicked or dragged, enabling the cdev to track its controls.

A cdev file must contain eight resources:

• cdev - a code resource

• mach - some data that indicates which machines the cdev is compatible with

• DITL - a standard Dialog item list

• nrct - some data that defines the number of rectangles needed for the cdev’s display, and their sizes.

• ICN# - a standard icon with mask

• BNDL - a standard bundle resource

• FREF - a standard file reference resource

• An owner resource, that must be a unique four-character identifier, just like the ones used for applications. The Monkey cdev uses the type ‘mOnk’.

With the exception of the owner resource, all the resources should have the same ID number, -4064. The owner resource ID depends on how the BNDL is structured, and is usually zero.

Fig. 1 Adding our own control functions

The nrct and mach Resources

These two resources are unique to cdevs, and require some more detailed explanation. The nrct type is a list of rectangles. The first word of the resource is the number of rectangles in the list. It is followed by eight bytes for each rectangle, which describe the top, left, bottom, and right boundaries. For each rectangle defined in the nrct, the Control Panel clears out some white space in its window, and draws a frame around it. The nrct, along with the DITL, define the look of the cdev panel.

The mach resource type consists of two words. The first is called the Softmask, and is compared to the global variable ROM85 to determine which toolbox features are available (such as Color Quickdraw). The second word is called the Hardmask, and it is used to determine which hardware features are available. The values of these masks determines on which machines the cdev will appear. Table 1 shows some possible settings.

The cdev code

Listing 1 shows the code used in the Monkey cdev, written in LightspeedC. The main function is declared as:

pascal  Handle main(message,item,numItems,CPanelID,ep,cdevStorage, CPDialog)
EventRecord *ep;
Handle  cdevStorage;
DialogPtr CPDialog;

Message is a number that tells the cdev what event just took place. Monkey only responds to three types of messages: initDev, which means “do your initialization”; closeDev, which means “dispose of any allocated storage and close up shop”; and hitDev, which means “the user clicked on an item”.

For initDev, Monkey just allocates 16 bytes of storage, and returns the handle in cdevStorage. Monkey does not use this storage, but the Control Panel wants to see a valid handle. For closeDev, Monkey releases the 16 bytes of storage, and clears the cdevStorage variable. For hitDev, Monkey loads the ‘snd ’ resource with ID# 4 (the monkey screech),and then calls the Macintosh II Sound Manager routine SndPlay to generate the sound. Since there is only one item, the DoHit routine does not have to determine which item was clicked on. If there were more items, the DoHit routine would have to subtract numItems from item to determine which item in its DITL was clicked. This is because the cdev’s DITL is appended to the Control Panel’s DITL.

Fig. 2 Our Monkey Squeek!

Compiling the cdev in LightspeedC

Creating the Monkey cdev is fairly straightforward in LightspeedC. First use RMaker to compile the necessary resources, as given in Listing 3. Create a new project called MonkeyCdevP, and set the project type to a code resource of type cdev. Enter Listing 2, and save it as SoundMgr.h, in the same folder with your other Macintosh header files. Add the MacTraps library to the project. Enter Listing 1, save it as MonkeyCdev.c and add it to the project. Then build the code resource (select Build Code Resource from the Project menu). Save it as Monkey. Finally, use ResEdit to set the creator type to mOnk, and set the bundle bit. Now drag the finished cdev into the System Folder, open the Control Panel, and make the monkey screech!

A Note About the Resources

I didn’t actually use RMaker to create the resources for the Monkey cdev. I created them with ResEdit, and then used a shareware resource decompiler called ResDecomp, by Robert Comer, to create the RMaker source code for publication. To save yourself some typing, you may want to create your own ICN# and PICT resources using ResEdit, rather than enter all the hex code for them. Just be sure to give them the correct ID numbers, and make them purgeable.

By the way, the monkey picture was originally taken from a clip art disk called WetPaint, put out by Dubl-Clik software. I modified it some, but I like to give credit for these things.

Table 1: Sample mach Settings

Softmask Hardmask Function

$0000 $FFFF call cdev to determine whether it should show up

$FFFF $0000 show up on all machines

$7FFF $0400 show up on machines with an Apple Desktop Bus only

$3FFF $0000 show up on the Macintosh II only

Listing 1.
/* Monkey CDEV
 * by Jan Eugenides
 * 6/6/87
 * An example of adding a function to the
 * Control Panel, and using the Macintosh II’s
 * SndPlay routine
#include <MacTypes.h>
#include <pascal.h>
#include <MemoryMgr.h>
#include <OSUtil.h>
#include <ToolboxUtil.h>
#include <DialogMgr.h>
#include <EventMgr.h>
#include <SoundMgr.h>
/*First define some needed constants*/
 Handle InitStorage();
 /*This is main routine, entry point for the CDEV*/
 pascal Handle main(message,item,numItems,CPanelID,ep,cdevStorage,CPDialog)
 int    message,item,numItems,CPanelID;
 Handle cdevStorage;
 if(message == macDev)return((Handle)1);
 case initDev: /*Init message received, 
 allocate some storage*/
 cdevStorage = InitStorage();
 if(cdevStorage)DoHit(1+numItems, numItems,CPDialog);
 case closeDev: /*Close message received, dispose of           
 cdevStorage = (Handle)0L;
 case hitDev: /*User clicked an item, handle it*/
 } /*end switch*/
 } /*end else if*/ 
  Handle  InitStorage()  /*ultra-simple storage allocation*/
 { /*The storage is not used in this example*/
 DisposeStorage(h) /*Release our storage area*/
 Handle h;
 DoHit(item,numItems,CPDialog)/*Handle a click on one of       
 our items*/
 int  item,numItems;   /*This example has one item, so it’s*/
 DialogPtrCPDialog;  /*very simple*/
 Handle soundH;
soundH = GetResource(‘snd ‘,4);/*there is a space after snd */
 SndPlay(0L,soundH,TRUE);   /*play the monkey screech*/

* Resources for Monkey cdev


Type ICN# = GNRL
 ,-4064 (32) ;; attributes -> Purgeable
00000000 0000FE00 0003FF80 000F01E0
6AEC992E 7FCDDBB7 6ACD99B6 7FCC0037
6AC60066 3FC4FF27 3BC1FF87 1FE3D7CF
0F67FFED 00363C78 003C003D 001DFFB0
000DC3B5 000C4230 00077E75 001F00E0
003DFFD5 0078FF08 00F57555 01E2B000
03D57555 07E8F080 0DF5F555 1FFFB000
00000000 0000FE00 0003FF80 000FFFE0
000FFFF5 000FFFF0 0007FFF5 001FFFE0
003FFFD5 007FFF08 00FFF555 01FFF000
03FFF555 07FFF080 0FFFF555 1FFFB000

 ,-4064 (32) ;; attributes -> Purgeable
cdev 0 

 ,-4064 (32) ;; attributes -> Purgeable
mOnk 0
 0 -4064 
 0 -4064 

 ,-4064 (32) ;; attributes -> Purgeable

1 128 76 194

StatText Disabled
77 133 93 206
Click Me!

 ,-4064 (32) ;; attributes -> Purgeable
03850000 0000004B 00421101 01000A00
00000000 4B004298 000A0031 0066007C
00A80031 0066007C 00A80000 0000004B
00420000 08FC0002 01FFF0FF 0008FC00
0203FFFC FF0008FC 000206AA AAFF0008
FC00020F F7F7FF00 08FC0002 0AAAABFF
0008FC00 020FFFFF FF0008FC 00040BFF
AA800008 FC000406 00FF8000 06FA0002
2A800006 FA00023F 800006FA 00021AC0
000A0200 00FEFD00 0217C000 0B030003
FF80FE00 021AC000 0B03000F 01E0FE00
021FC000 0B090F9C 007FC000 001AC000
0B091FF9 C7BFF000 001F4000 0B093AF7
FFDAB800 001AC000 0B097FEE 3C6FFC00
001FC000 0B096AEC 992EAC00 001AC000
0B097FCD DBB7FC00 0017C000 0B096ACD
99B6AC00 001AC000 0B097FCC 0037FC00
001FC000 0B096AC6 0066B800 001AC000
0B093FC4 FF27F800 001F4000 0B093BC1
FF87FFC0 001AC000 0B091FE3 D7CFFFF8
001FC000 0B090F67 FFED557F 001AC000
0B090036 3C78080F C0178000 0B09003C
003D5555 F01A8000 0B09001D FFB00000
7C3F8000 0B09000D C3B55555 5E2A8000
0B09000C 42308080 87BF8000 0B030007
7E75FE55 02EA8000 0B03001F 00E0FE00
02FF8000 0B03003D FFD5FE55 027A8000
0A020078 FFFD0802 3F80000A 0200F575
FD55025A 80000A02 01E2B0FD 00021F80
000A0203 D575FD55 025E8000 0A0207E8
F0FD8002 8F80000A 020DF5F5 FD55025F
00000A02 1FFFB0FD 00020700 000A023A
AF35FD55 02570000 0A027FFE 78FD0802
0F00000A 02777C75 FD550257 00000A02
FFF860FD 00020300 000A02EA B075FD55
02570000 0B09FFE0 6080FE80 80830000
0B09DDC0 7557FFD5 55570000 0B09FF80
C0073BC0 00030000 0B09EF00 D55E35F5
55570000 0B097E00 C81C38F8 080B0000
0B073800 D558357D 5557FF00 0B070000
C03032BC 0003FF00 0B070001 D570755D
5557FF00 0B070001 80E0688E 8083FF00
0B070001 D560755F 5557FF00 0B070003
80C06A3B 0003FF00 0B070003 D5C0D55B
5557FF00 0B070003 0980C8B1 880BFF00
0B070007 5580D571 D557FF00 0B070006
0300E2E0 C003FF00 0B070007 5700D560
D557FF00 0B07000E 860188C0 6083FF00
0B07000F 5601D5C0 7556FF00 0B07001C
0C01AB80 3006FF00 0B07001F FC01FF80
1FFEFF00 0B07003F F803FF00 1FFEFF00
0B090077 78037700 0F760000 0B0901FF
F807FF00 0FFE0000 0B097FEA B9FEAB0F

Type mOnk = GNRL
 ,-4064 (32) ;; attributes -> Purgeable
1C4D6F6E 6B657920 63646576 20627920
4A616E20 45756765 6E696465 73

Type nrct = GNRL
0001FFFF 00570066 00CE

Type mach = GNRL
 ,-4064 (32) ;; attributes -> Purgeable

Community Search:
MacTech Search:

Software Updates via MacUpdate

BBEdit 11.1.1 - Powerful text and HTML e...
BBEdit is the leading professional HTML and text editor for the Mac. Specifically crafted in response to the needs of Web authors and software developers, this award-winning product provides a... Read more
CrossOver 14.1.3 - Run Windows apps on y...
CrossOver can get your Windows productivity applications and PC games up and running on your Mac quickly and easily. CrossOver runs the Windows software that you need on Mac at home, in the office,... Read more
Little Snitch 3.5.3 - Alerts you about o...
Little Snitch gives you control over your private outgoing data. Track background activity As soon as your computer connects to the Internet, applications often have permission to send any... Read more
OmniGraffle Pro 6.2.3 - Create diagrams,...
OmniGraffle Pro helps you draw beautiful diagrams, family trees, flow charts, org charts, layouts, and (mathematically speaking) any other directed or non-directed graphs. We've had people use... Read more
OmniFocus 2.2 - GTD task manager with iO...
OmniFocus helps you manage your tasks the way that you want, freeing you to focus your attention on the things that matter to you most. Capturing tasks and ideas is always a keyboard shortcut away in... Read more
Cocktail 8.4 - General maintenance and o...
Cocktail is a general purpose utility for OS X that lets you clean, repair and optimize your Mac. It is a powerful digital toolset that helps hundreds of thousands of Mac users around the world get... Read more
PDFKey Pro 4.3 - Edit and print password...
PDFKey Pro can unlock PDF documents protected for printing and copying when you've forgotten your password. It can now also protect your PDF files with a password to prevent unauthorized access and/... Read more
Kodi 15.0.beta1 - Powerful media center...
Kodi (was XBMC) is an award-winning free and open-source (GPL) software media player and entertainment hub that can be installed on Linux, OS X, Windows, iOS, and Android, featuring a 10-foot user... Read more
DiskCatalogMaker 6.4.12 - Catalog your d...
DiskCatalogMaker is a simple disk management tool which catalogs disks. Simple, light-weight, and fast. Finder-like intuitive look and feel. Super-fast search algorithm. Can compress catalog data... Read more
Macs Fan Control - Monitor and c...
Macs Fan Control allows you to monitor and control almost any aspect of your computer's fans, with support for controlling fan speed, temperature sensors pane, menu-bar icon, and autostart with... Read more

Moleskine Timepage – Calendar for iCloud...
Moleskine Timepage – Calendar for iCloud, Google & Exchange 1.0 Device: iOS iPhone Category: Productivity Price: $4.99, Version: 1.0 (iTunes) Description: The most elegant calendar for your pocket and wrist, Timepage is a... | Read more »
QuizUp Gets Social in its New Update
Plain Vanilla Corp has released a new and improved version of their popular trivia game, QuizUp. The app now emphasizes social play so you can challenge friends from all over the world. [Read more] | Read more »
The Deep (Games)
The Deep 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: Swipe Controls Delve into the deep in this retro rogue-like! Swipe to move your diver around and keep away from the enemies as you... | Read more »
Battle of Gods: Ascension (Games)
Battle of Gods: Ascension 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: TURN-BASED TACTICAL COMBATFight tactical battles against the forces of Hades! In Battle of Gods: Ascension you play... | Read more »
Shadowmatic's Latest Update Adds a...
Shadowmatic's shadowy shadow-ness is getting a little shadowy-er thanks to a recent update that adds an Arcade Mode. [Read more] | Read more »
Sunrise Calendar and Slack Have Assimila...
Wunderlist is perhaps one of the most populat and beloved productivity apps on the App Store - and now it's gone and incorporated itself into other useful services like Sunrise Calendar and Slack. [Read more] | Read more »
Crossy Road Devs Hipster Whale are Bring...
Hipster Whale, the minds behind the rather popular (and rather great) Crossy Road, have teamed-up with Bandai Namco to create PAC-MAN 256: an absolutely bonkers looking maze runner chaser thing. | Read more »
Meet the New Spotify Music
Spotify Music  has a lot going on. They're introducing 3 new modes to serve all your musical needs, with the "Now" start page  gives you curated playlists based on your particular tastes. As you listen the app will learn more about your tastes and... | Read more »
What the Apple Watch Gets Right, and Wha...
| Read more »
Celebrate PAC-MAN's 35th Birthday W...
BANDAI NAMCO Entertainment America is celebrating PAC-MAN's 35th anniversary by releasing updates for PAC-MAN and PAC-MAN Lite for iOS. [Read more] | Read more »

Price Scanner via

What Would the ideal Apple Productivity Platf...
For the past four years I’ve kept a foot in both the Mac and iPad camps respectively. my daily computing hours divided about 50/50 between the two devices with remarkable consistency. However, there’... Read more
PageMeUp 1.2.1 Ten Dollar Page Layout Applica...
Paris, France-based Softobe, an OS X software development company, has announced that their PageMeUp v. 1.2.1, is available on the Mac App Store for $9.99. The license can be installed on up to 5... Read more
Eight New Products For USB Type-C Application...
Fresco Logic, specialists in advanced connectivity technologies and ICs, has introduced two new product families targeting the Type-C connector recently introduced across a number of consumer... Read more
Scripps National Spelling Bee Launches Buzzwo...
Scripps National Spelling Bee fans can monitor the action at the 2015 Spelling Bee with the new Buzzworthy app for iOS, Android and Windows mobile devices. The free Buzzworthy app provides friendly... Read more
13-inch 2.5GHz MacBook Pro on sale for $120 o...
B&H Photo has the 13″ 2.5GHz MacBook Pro on sale for $979 including free shipping plus NY sales tax only. Their price is $120 off MSRP, and it’s the lowest price for this model (except for Apple’... Read more
27-inch 3.3GHz 5K iMac on sale for $1899, $10...
B&H Photo has the new 27″ 3.3GHz 5K iMac on sale for $1899.99 including free shipping plus NY tax only. Their price is $100 off MSRP. Read more
Save up to $50 on iPad Air 2, NY tax only, fr...
B&H Photo has iPad Air 2s on sale for up to $50 off MSRP including free shipping plus NY sales tax only: - 16GB iPad Air 2 WiFi: $469 $30 off - 64GB iPad Air 2 WiFi: $549.99 $50 off - 128GB iPad... Read more
Updated Mac Price Trackers
We’ve updated our Mac Price Trackers with the latest information on prices, bundles, and availability on systems from Apple’s authorized internet/catalog resellers: - 15″ MacBook Pros - 13″ MacBook... Read more
New 13-inch 2.9GHz Retina MacBook Pro on sale...
B&H Photo has the 13″ 2.9GHz/512GB Retina MacBook Pro on sale for $1699.99 including free shipping plus NY tax only. Their price is $100 off MSRP, and it’s the lowest price for this model from... Read more
Apple refurbished 2014 MacBook Airs available...
The Apple Store has Apple Certified Refurbished 2014 MacBook Airs available starting at $679. An Apple one-year warranty is included with each MacBook, and shipping is free: - 11″ 1.4GHz/128GB... Read more

Jobs Board

*Apple* Solutions Consultant - Retail Sales...
**Job Summary** As an Apple Solutions Consultant (ASC) you are the link between our customers and our products. Your role is to drive the Apple business in a retail Read more
*Apple* Watch SW Application Project Manager...
**Job Summary** The Apple Watch software team is looking for an Application Engineering Project Manager to work on new projects for Apple . The successful candidate Read more
Engineering Manager for *Apple* Maps on the...
…the Maps App Team get to take part in just about any new feature in Apple Maps, often contributing a majority of the feature work. In our day-to-day engineering work, we Read more
Senior Software Engineer - *Apple* SIM - Ap...
Changing the world is all in a day039s work at Apple . If you love innovation, here039s your chance to make a career of it. You039ll work hard. But the job comes with Read more
Lead *Apple* Solutions Consultant - Retail...
**Job Summary** Job Summary The Lead ASC is an Apple employee who serves as the Apple business manager and influencer in a hyper-business critical Reseller's store Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.