TweetFollow Us on Twitter

ROM Exploring
Volume Number:7
Issue Number:4
Column Tag:Pascal Procedures

Related Info: Resource Manager

Exploring the ROM

By Micheal Budiansky, Berkeley, CA

[Michael Budiansky is a physicist-turned-engineer specializing in Macintosh software. He worked in the areas of heavy-ion collisions, optical telescope design, and semiconductor image processing, before discovering the Macintosh in 1986. He’s been programming the Mac ever since, first for Bear River Associates, then for Applied Biosystems. He received a Ph.D. in Physics from the University of California at Berkeley.]

Re: Sources of Resources

Resources only come from the resource fork of disk files. Right? Wrong! Since the days of the 128K ROM a number of important resources have also been stored in the ROM itself. In this article, we’ll discuss how to get at these hidden resources - the accompanying Pascal code for a simple MPW tool illustrates the necessary technique, as well as providing a means of exploring what these resources are and finding out which of them have been modified by later patches to the System software.

The Resource Chain

First, let’s review how resources are loaded by a program. When an application requests a resource, the Resource Manager searches through a chain of resource files until it is found. Normally, the chain begins with the most-recently-opened document’s resource file, followed by the application’s resource fork, and then the System file. If the resource isn’t in the document (or if there’s no document open), the manager looks in the application. If it’s not in the application, the manager looks in the System file. If it’s not in the System file, you’re probably in trouble.

To get at the ROM resources, you’ll need to adjust the resource chain by means of techniques described in Inside Macintosh,Volumes IV and V. There are two different methods: one is to set the values of certain low-memory globals before making an ordinary Resource Manager call, and the other is to use the special toolbox call RGetResource. The first method puts the ROM resource map at the front of the resource chain for one call to the Resource Manager, as shown in Figure 1. Set the low-memory global RomMapInsert to true and then make your call; the ROM resource map will be searched first for that one call only. The second method is to use the RGetResource call; this behaves exactly like GetResource, except that it puts the ROM resource map at the end of the chain, as shown in Figure 2. After all the resource files in the chain have been searched for the requested resource, RGetResource looks in the ROM resource map.

Figure 1. Moving ROM resources to the front

Figure 2. ROM resources at front

Roving around

What are the resources in the ROM and what good are they? Obtaining the complete list is an exercise left to the reader - armed with the program that follows. (Lazy readers can look up the answer in Inside Macintosh - but those lucky enough to own one of the newer models may have to wait until volume VI is published.) Here are three examples of how these resources can be used:

First, you may find a secret resource that is not present in the system file. The only way to get at these is from the ROM. In Macintosh II class machines, for example, the ROM contains a hidden ‘snd’ resource. It’s named “Brass Horn,” (although it actually sounds more like a squeaky toy) and if it catches your fancy, you could copy it, renumber it, and paste it into your System file to use as a beep sound.

Also, you can optimize your code to use a ROM resource if it is available, thus saving the time required to read in the resource from disk. This technique is used by MacApp to save time in reading the standard cursor resources (watch, plus, cross, and I-beam). This is a fairly safe technique, since if for some reason the resource that you expected to be in ROM is not there, the Resource manager will simply continue looking for it farther along the resource file chain (probably to find it in the System file). You need to be a little careful, however, since sometimes resources are present in both the System file and in the ROM for a reason: the one in ROM is no good any more, and the System file version is a replacement!

Finally, you may need to know about the ROM resources if you want to replace or modify one of the standard system resources. If a resource is first loaded into the System Heap from the ROM, then it doesn’t matter if you edit the copy in the System file--you’re stuck with the ROM version. As it does for so many other functions, however, the Macintosh operating system provides a “hook” that lets you override the default behavior: the ‘Rov#’ resource. The System file contains a number of ‘Rov#’ resources; a ‘Rov#’ resource contains a list of types and ID numbers of ROM resources that are to be replaced by their System file counterparts. In current systems, there is one ‘Rov#’ resource for each version of the ROM (e.g., Mac Plus in resource #117, Mac SE in resource #630, Mac II in resource #376, etc.). By editing the appropriate ‘Rov#’ resource in the System file, you can instruct the system to ignore the ROM version of a resource and to use the version in the System file itself. Readers who are now all set to disassemble and rewrite the Disk Driver ROM resource may proceed without further delay; they probably wouldn’t pay much attention to the safety lecture below, anyway. As for the rest of you, there is an example of resource overriding that may be of interest to any programmer, even those who aren’t the daredevil type.

The Monaco font is a clean, monospaced, font--ideal for viewing program listings on the screen. Its one deficiency, however, is that the digit ‘0’ and the capital letter ‘O’ are indistinguishable, as are the lower case ‘l’ and the capital letter ‘I’. You can repair this problem by using ResEdit to edit the Monaco ‘FONT’ resources (9 point and 12 point) in a copy of your System file: add a dot in the middle of the zero digit and add serifs (short horizontal lines at the top and bottom of the character) to the capital ‘I’. (Please! edit a copy, not your current and/or only version of the System file! And read the safety lecture, too!) If you try out this edited System file on a Mac newer than the Plus, however, you will probably find that while the modifications appear when you use Monaco 12, they do NOT when you use Monaco 9; that’s because Monaco 9 is in a ROM resource. To use the System file’s version of the font, you must edit the ‘Rov#’ resource appropriate for your machine by adding a entry for ‘FONT’ number 521. This will take a certain amount of skill with ResEdit, since to add the entry requires editing the resource in hex form. Open the ‘Rov#’ as a general hex resource. The second word (group of 4 hex digits) in the resource is the number of overridden resources minus one. Edit this number to be one greater than its current value, then add three words of zeroes at the end of the resource; these three words are placeholders for the new entry. Close the resource, then open it again, in the ordinary way that uses the ‘Rov#’ template. The last entry in the list should be blank; change it to FONT 521. If you run into trouble, refer to Inside Macintosh IV-20 for the detailed format of the ‘Rov#’ resource. (Note: Inside Macintosh, Volume IV says that you’ll need to obtain a ‘Rovr’ resource from Developer Tech Support at Apple before you can do any overriding; current System files already contain this resource, so there’s no need to bug the folks at DTS to send it to you.)

ROMRes tool: Theory & Practice

This MPW tool has three options for exploring the ROM resources, plus a self-contained help text. If no option or an invalid option is supplied, the help text is printed out; this is a convenient feature for MPW tools in general, particularly those that are not likely to be used frequently. The listing feature (-l) looks up and lists all resources in the ROM; resources are listed by type, ID, and name. The override feature (-r) looks in your System file and lists all the ‘Rov#’ resources found. For each one, it lists the ROM resources that are flagged to be overridden. Note that only the resources listed for the particular ‘Rov#’ that matches your machine will actually be overridden in your machine. The extract feature (-x) copies a particular resource from the ROM into the file of your choice; if the file does not exist, it will be created.

The comment at the beginning of the code contains the text for the make file; copy the text between (* and *) and paste it into a file named ‘ROMRes.make’. The main section of the program sets up a few variables and then has a case statement that dispatches control to one of three subroutines, one for each feature. If there is a problem with the command line arguments, the code at the end of the main section prints out the help text. The tool gets access to the text on the command line via the global variables ArgC and ArgV, which are defined in the unit IntEnv included in the MPW development system.

The tool uses the first method described above for gaining access to the ROM resources: setting the appropriate low-memory global to TRUE. The routine that lists all the ROM resources deserves some comment. This routine examines all the resources in the resource chain, and identifies those that are in the ROM by using the call HomeResFile; HomeResFile returns a reference number of 1 for resources in ROM. The value 1 is ordinarily an illegal value for a resource file reference number, but in this one case it is used to identify the source of ROM resources. The call CurResFile does not return a value of 1, even if you have set the low-memory global RomMapInsert to true. Trying the call UseResFile(1) will not give good results either. The ROM resource map is not a “file,” and it does not work in general to pretend that it is. This explains why we can’t simply use the Resource Manager calls Count1Types, Count1Resources, and Get1IndResource to examine resources that are only in the ROM. These calls, described in volume IV of Inside Macintosh, search the current resource file only, rather than the entire resource chain, but they don’t behave the way you might expect for the ROM resource map.

Safety lecture

First of all, if you choose to use ResEdit on your System file, be aware that it’s serious business. Back up your files, work on a copy of your System file, and be prepared for your system to crash if you make a mistake. MacTutor readers are a pretty fearless bunch, but even rock climbers use ropes, so you should take reasonable precautions when experimenting with your System.

Almost as fearsome as system crashes are lawyers. If you filch some nifty resource out of the ROM, it’s fine to play around with it on your own machine, but before you include it in an insanely great application to be distributed for fame and fortune, it might be a good idea to talk to Software Licensing at Apple.

Software compatibility is what separates the professionals from the amateurs. Obviously, if you write a program that depends on a ROM resource being there, you are asking for trouble when a new model of the Macintosh comes out. Similarly, if you write a program that expects a newer ROM version, you may unnecessarily be shutting out thousands of Mac owners with a Plus or SE. More subtle (i.e., hard to debug) problems may arise if your program demands a ROM version of a resource when the current System file actually supplies a new and improved version of the resource. Remember, your users will not thank you for saving them a few microseconds by reading a resource from ROM instead of disk if it costs them hours of trying to figure out why the program doesn’t work with a new System version!

Happy exploring!

PROGRAM ROMRes;
(* ROMRes.Make

ROMRes.p.o ƒ ROMRes.Make 
 ROMRes.p
 Pascal ROMRes.p  

ROMRes ƒƒ   ROMRes.Make 
 ROMRes.p.o
 Link -w -t ‘MPST’ -c ‘MPS ‘ 
 ROMRes.p.o 
 “{Libraries}”Runtime.o 
 “{Libraries}”Interface.o 
 “{PLibraries}”PasLib.o 
 “{Libraries}”ToolLibs.o 
 -o ROMRes
*)

USES
 MemTypes,
 QuickDraw,
 OSIntf,
 ToolIntf,
 PackIntf,
 SysEqu,
 Signal,
 PasLibIntf,
 IntEnv;

TYPE
 IntPtr = ^INTEGER;

VAR
 printUsage:BOOLEAN;
 flagPtr: IntPtr;
 numTypes:INTEGER;
 theType: ResType;
 aType: ResType;
 numOfType: INTEGER;
 index: INTEGER;
 aHandle: Handle;
 theID: INTEGER;
 name:  Str255;

 {=========================}
 PROCEDURE ListROMResources;

 VAR
 i:INTEGER;
 k:INTEGER;

 BEGIN
 flagPtr^ := mapTrue;
 numTypes := CountTypes;
 { Scan all types of resources }
 FOR i := 1 TO numTypes DO
 BEGIN
 flagPtr^ := mapTrue;
 GetIndType(theType, i);
 flagPtr^ := mapTrue;
 numOfType := CountResources(theType);
 { Scan all resources of each type }
 FOR k := 1 TO numOfType DO
 BEGIN
 flagPtr^ := mapFalse;
 aHandle := GetIndResource(theType, k);
 GetResInfo(aHandle, theID, aType, name);
 flagPtr^ := mapFalse;
 { Only print the ROM resources }
 IF HomeResFile(aHandle) = 1 THEN
  Writeln(theType,’ ‘, theID,’ ‘,name);
 END;
 END;
 END;

 {=========================}
 PROCEDURE ListROvResources;

 TYPE
 OneROv = PACKED RECORD
 rType: ResType;
 rID: INTEGER;
 END;
 ROvType = PACKED RECORD
 romVersion:INTEGER;
 count: INTEGER;
 rovs:  PACKED ARRAY [0..32000] OF OneROv;
 END;
 ROvTypePtr = ^ROvType;
 ROvTypeHdl = ^ROvTypePtr;

 VAR
 i:INTEGER;
 k:INTEGER;
 rovHandle: ROvTypeHdl;

 BEGIN
 numOfType := CountResources(‘ROv#’);
 FOR k := 1 TO numOfType DO
 BEGIN
 aHandle := GetIndResource(‘ROv#’, k);
 GetResInfo(aHandle, theID, aType, name);
 rovHandle := ROvTypeHdl(aHandle);
 Writeln(‘ROv# ‘, theID:0);
 Write(‘  Rom version ‘, rovHandle^^.romVersion:0,’ - ‘);
 { Identify ROM version type }
 CASE rovHandle^^.romVersion OF
 117: Writeln(‘Mac Plus’);
 376: Writeln(‘Mac II’);  
 630: Writeln(‘Mac SE’);  
 890: Writeln(‘Mac Portable’);
 1660:  Writeln(‘Mac IIci’);
 OTHERWISE
 Writeln(‘ Unknown’);
 END;
 { List contents of each Rov# }
 FOR i := 0 TO rovHandle^^.count DO
 BEGIN
 Writeln(‘  ‘, rovHandle^^.rovs[i].rType, ‘ ‘,
 rovHandle^^.rovs[i].rID:0);
 END;
 Writeln;
 END;
 END;
 
 {===========================}
 PROCEDURE ExtractROMResource;
 VAR
 rType: ResType;
 rTypePtr:StringPtr;
 value: LongInt;
 rID:   INTEGER;
 fileName:Str255;
 i:INTEGER;
 refNum:INTEGER;
 BEGIN
 { Get desired type from command line }
 rType := ‘    ‘;
 rTypePtr := StringPtr(@rType);
 FOR i := 1 TO Ord(argV^[2]^[0]) DO
 rTypePtr^[i - 1] := argV^[2]^[i];
 { Get ID number from command line }
 StringToNum(argV^[3]^, value);
 rID := INTEGER(value);
 { Get output file name from command line }
 fileName := argV^[4]^;
 { Get ROM resource, if there }
 flagPtr^ := mapTrue;
 aHandle := GetResource(rType, rID);
 IF aHandle = NIL THEN
 Writeln(‘No such resource’)
 ELSE
 BEGIN
 Writeln(‘Extracting ‘,rType, ‘ ‘, rID:0, ‘ to file ‘,fileName);
 GetResInfo(aHandle, theID, aType, name);
 HNoPurge(aHandle);
 DetachResource(aHandle);
 { Open output file; create it if it doesn’t exist }
 refNum := OpenResFile(fileName);
 IF refNum = -1 THEN
 BEGIN
 IF Create(fileName, 0, ‘RSED’,    ‘rsrc’) = noErr THEN
 BEGIN
 CreateResFile(fileName);
 refNum := OpenResFile(fileName);
 END;
 END;
 IF refNum = -1 THEN
 Writeln(‘Problem with file’)
 ELSE
 BEGIN
 AddResource(aHandle, rType, rID, name);
 CloseResFile(refNum);
 END;
 END;
 END;

BEGIN
 { if error in command line, print info }
 printUsage := TRUE;
 { save pointer to low-mem global, for convenience }
 flagPtr := IntPtr(RomMapInsert);
 { act on option: -l -r or -x }
 IF argC > 1 THEN
 IF (Ord(argV^[1]^[0]) > 1) AND 
 (argV^[1]^[1] = ‘-’) THEN
 CASE argV^[1]^[2] OF
 ‘l’:
 BEGIN
 ListROMResources;
 printUsage := FALSE;
 END;
 ‘r’:
 BEGIN
 ListRovResources;
 printUsage := FALSE;
 END;
 ‘x’:
 IF argC > 4 THEN
 BEGIN
 ExtractROMResource;
 printUsage := FALSE;
 END;
 END;
 { print instructions if problem with command line }
 IF printUsage THEN
 BEGIN
 Writeln(‘ROMRes [option ]’);
 Write(‘    -l                            #’);
 Writeln(‘ list types and ids of ROM resources’);
 Write(‘    -r                            #’);
 Writeln(‘ list all overridden resources’);
 Write(‘    -x resType resID outputFile   #’);
 Writeln(‘ extract a ROM resource and write to file’);
 END;
END.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Fresh From the Land Down Under – The Tou...
After a two week hiatus, we are back with another episode of The TouchArcade Show. Eli is fresh off his trip to Australia, which according to him is very similar to America but more upside down. Also kangaroos all over. Other topics this week... | Read more »
TouchArcade Game of the Week: ‘Dungeon T...
I’m a little conflicted on this week’s pick. Pretty much everyone knows the legend of Dungeon Raid, the match-3 RPG hybrid that took the world by storm way back in 2011. Everyone at the time was obsessed with it, but for whatever reason the... | Read more »
SwitchArcade Round-Up: Reviews Featuring...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for July 19th, 2024. In today’s article, we finish up the week with the unusual appearance of a review. I’ve spent my time with Hot Lap Racing, and I’m ready to give my verdict. After... | Read more »
Draknek Interview: Alan Hazelden on Thin...
Ever since I played my first release from Draknek & Friends years ago, I knew I wanted to sit down with Alan Hazelden and chat about the team, puzzle games, and much more. | Read more »
The Latest ‘Marvel Snap’ OTA Update Buff...
I don’t know about all of you, my fellow Marvel Snap (Free) players, but these days when I see a balance update I find myself clenching my… teeth and bracing for the impact to my decks. They’ve been pretty spicy of late, after all. How will the... | Read more »
‘Honkai Star Rail’ Version 2.4 “Finest D...
HoYoverse just announced the Honkai Star Rail (Free) version 2.4 “Finest Duel Under the Pristine Blue" update alongside a surprising collaboration. Honkai Star Rail 2.4 follows the 2.3 “Farewell, Penacony" update. Read about that here. | Read more »
‘Vampire Survivors+’ on Apple Arcade Wil...
Earlier this month, Apple revealed that poncle’s excellent Vampire Survivors+ () would be heading to Apple Arcade as a new App Store Great. I reached out to poncle to check in on the DLC for Vampire Survivors+ because only the first two DLCs were... | Read more »
Homerun Clash 2: Legends Derby opens for...
Since launching in 2018, Homerun Clash has performed admirably for HAEGIN, racking up 12 million players all eager to prove they could be the next baseball champions. Well, the title will soon be up for grabs again, as Homerun Clash 2: Legends... | Read more »
‘Neverness to Everness’ Is a Free To Pla...
Perfect World Games and Hotta Studio (Tower of Fantasy) announced a new free to play open world RPG in the form of Neverness to Everness a few days ago (via Gematsu). Neverness to Everness has an urban setting, and the two reveal trailers for it... | Read more »
Meditative Puzzler ‘Ouros’ Coming to iOS...
Ouros is a mediative puzzle game from developer Michael Kamm that launched on PC just a couple of months back, and today it has been revealed that the title is now heading to iOS and Android devices next month. Which is good news I say because this... | Read more »

Price Scanner via MacPrices.net

Amazon is still selling 16-inch MacBook Pros...
Prime Day in July is over, but Amazon is still selling 16-inch Apple MacBook Pros for $500-$600 off MSRP. Shipping is free. These are the lowest prices available this weekend for new 16″ Apple... Read more
Walmart continues to sell clearance 13-inch M...
Walmart continues to offer clearance, but new, Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBooks... Read more
Apple is offering steep discounts, up to $600...
Apple has standard-configuration 16″ M3 Max MacBook Pros available, Certified Refurbished, starting at $2969 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free,... Read more
Save up to $480 with these 14-inch M3 Pro/M3...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
Amazon has clearance 9th-generation WiFi iPad...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80-$100 off MSRP, starting only $249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Apple is offering a $50 discount on 2nd-gener...
Apple has Certified Refurbished White and Midnight HomePods available for $249, Certified Refurbished. That’s $50 off MSRP and the lowest price currently available for a full-size Apple HomePod today... Read more
The latest MacBook Pro sale at Amazon: 16-inc...
Amazon is offering instant discounts on 16″ M3 Pro and 16″ M3 Max MacBook Pros ranging up to $400 off MSRP as part of their early July 4th sale. Shipping is free. These are the lowest prices... Read more
14-inch M3 Pro MacBook Pros with 36GB of RAM...
B&H Photo has 14″ M3 Pro MacBook Pros with 36GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 Pro MacBook Pro (... Read more
14-inch M3 MacBook Pros with 16GB of RAM on s...
B&H Photo has 14″ M3 MacBook Pros with 16GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $150-$200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 MacBook Pro (... Read more
Amazon is offering $170-$200 discounts on new...
Amazon is offering a $170-$200 discount on every configuration and color of Apple’s M3-powered 15″ MacBook Airs. Prices start at $1129 for models with 8GB of RAM and 256GB of storage: – 15″ M3... Read more

Jobs Board

*Apple* Systems Engineer - Chenega Corporati...
…LLC,** a **Chenega Professional Services** ' company, is looking for a ** Apple Systems Engineer** to support the Information Technology Operations and Maintenance Read more
Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
*Apple* / Mac Administrator - JAMF Pro - Ame...
Amentum is seeking an ** Apple / Mac Administrator - JAMF Pro** to provide support with the Apple Ecosystem to include hardware and software to join our team and Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.