TweetFollow Us on Twitter

Jun 97 Factory Floor

Volume Number: 13 (1997)
Issue Number: 6
Column Tag: From The Factory Floor

David Hempling and the Latitude Porting Libraries

by Dave Mark, ©1997 by Metrowerks, Inc., all rights

This month's interview is with David Hempling, founder of the Latitude Group and Quorum Software Systems before that. If you have not yet heard about the Latitude porting libraries, you owe it to yourself to read this interview. The current version of Latitude makes it easy to port your Macintosh applications so they run under Unix. Recently, Metrowerks purchased the Latitude Group with an easy port from Mac to Rhapsody in mind. Read on to learn more...

Dave M: Can you tell me a bit about the history of The Latitude Group?

Dave H: The Latitude Group was founded in August of 1994 to continue development and support of the Latitude Technology which was originally developed by Quorum Software Systems, Inc.

Back in 1989 Sheldon Breiner, an entrepreneur with several companies under his belt, wanted to create a Macintosh hardware clone. As you can imagine, he found no one who would join him in such a venture. He eventually meet up with R. Martin Chavez, a Computer Science PhD and medical student, who had ideas about enabling Macintosh applications to run on other platforms. Marty's idea was very unique: under some special process, the shrink-wrapped Macintosh application would take on the native look and feel of the non-Mac platform on which it was running. Sheldon and Marty, with myself and another software engineer, Joel Kehle, founded Quorum Software Systems and began development.

Our first objective was to implement key Macintosh Toolbox functions in our own portable library -- the beginnings of Latitude. We would then couple this library with a 680x0 interpreter which would interpret the Macintosh binary executable and defer to our portable library when the interpreter encountered an A-Line trap exception. Mac programmers from the old days will remember that this is how Mac programs worked. Application machine code contained 0xAXXX instructions which triggered a 68000 exception. The lower 24 bits of the 0xAXXX instruction were used as an offset into the Mac's Trap Table and execution would jump to a function inside the Mac ROMs.

We did our initial portable Mac Toolbox library development on the 68030 NeXT Cube while another engineer, Robert Brown, developed a portable 680x0 and Microsoft P-Code interpreter. With the interpreter working, we moved our development to RISC based UNIX platforms like Sun Solaris, SGI IRIX, and HP HP-UX and released Equal, the Application Adapter which brought Microsoft Word 5.1a and Excel 4.0 to UNIX. Under Equal, Macintosh Word and Excel binaries ran on those non-Mac platforms with great performance and a native look and feel.

Because our portable Mac Toolbox library was being used to support two world-class applications, it was imperative that our Toolbox implementation behave as accurately as possible. We didn't have the Word or Excel source code to refer to -- only the sequence of Toolbox calls these applications were making. This black-box method of development, and adherence to strict clean-room engineering with regards to Apple's closely guarded Mac ROMs, led us to establish coding practices and design guidelines that we've continued to follow through our development of the portable Mac Toolbox library:

  1. With regards to application reliance on Mac Toolbox function input and output, our library's implementation must match the Mac and use published Mac data structures and paradigms internally whenever possible.
  2. Map native system facilities to Mac Toolbox functionality so the resulting application has the look and feel of the native platform.
  3. Require as little modification to the application as possible. Under Equal, there was really no practical way to alter the application's instructions. We had to implement Toolbox functionality correctly in our library so that no application modification would be needed.

Quorum also begin to license the portable library used by Equal to Mac developers who wanted to bring their applications to UNIX without the added overhead of the 680x0 interpreter. Developers also wanted the option to break out of their application's Mac source base and take advantage of features available in the new UNIX/RISC machines coming into the market. Quorum called the portable library "Latitude" and signed up developers like Adobe, Micro Planning International, and Sonic Solutions.

Early in 1994, Quorum's sales did not meet with its investors expectations and Quorum closed its doors that July. However, there were still developers using Latitude. Adobe, for example, was preparing to release Photoshop 2.5 at that time and needed Latitude support. Joel Kehle, myself, and three other Quorum engineers founded The Latitude Group, Inc., licensed Latitude from Quorum, and supplied Quorum's Latitude clients with support. We later purchased Quorum's assets from the fire sale.

Over the next two and a half years, we continued to develop Latitude, upgrading and expanding the technology as well as our client base. Adobe continued to use Latitude to bring Illustrator 5.5 and Photoshop 3.0 to Sun Solaris and SGI IRIX. Other more vertically minded developers like Vibro-Acoustic Sciences used Latitude to bring their highly specialized tools to UNIX/RISC platforms.

Dave M: How does Latitude work today (before Rhapsody)? How do I get my existing Mac application ported over to Unix? How much work is involved?

Dave H: At the heart of Latitude is our own Portable Toolbox Implementation Layer. This layer is completely platform independent. It presents the Mac Toolbox API to the application, answers these calls through a trap table mechanism, and relies on other toolbox calls within the layer whenever possible. When a native system facility is needed, such as the display of a window or control, or some graphical rendering, this layer calls out to one of Latitude's platform dependent modules through an internal, well defined API. The toolbox layer doesn't know what kind of system lies underneath, only that calling this function will display a window or that function will draw a line, etc.

Likewise, regarding the platform dependent modules. Event feedback from the GUI platform dependent module comes in the form of special calls back to Latitude's Event and Window Manager implementations. These calls in turn place event records in Latitude's Event queue. Latitude's architecture also strives to reconcile the difference between the Mac event and rendering systems and those on the platform Latitude is delivering. For example, client/server systems like Motif or OPENStep use callback mechanisms to report events to applications. A button's callback is called when the user clicks on the button. Latitude's GUI layer button callback function places a mouse down and mouse up event in Latitude's event queue. A window's update callback in the GUI calls down to the toolbox Window Manager to invalidate some or all of the window's update region, which is then picked up by CheckUpdate() from the app's call to GetNextEvent() or WaitNextEvent().

Because we've mapped native system facilities to Mac calls, the running application is an equal citizen on the desktop. The application's windows, menus, and control items are native system objects. Cutting and pasting between apps is facilitated by the native system's clipboard mechanism. Fonts come from the system font server -- including the default system font, which means the dialogs come up in something other than Chicago! Application windows are native windows -- not some rendering of a window inside of another. The performance hit is minimal. Latitude is merely mapping the Mac calls to the native system. There is very little processing going on in between.

To bring a Mac application to UNIX using Latitude, you first bring the source code to the UNIX platform and compile it. Tools included with Latitude perform some of the more mundane tasks like generating Make files and replacing '\p' Pascal string delimiters with special macros. Any changes made by these utilities can be taken back to the Mac without any ill effects. The goal is to generate both your Mac and UNIX applications from the same source code tree.

The bare minimum modification you will need to make to your application is a call to initialize Latitude. This call is equivalent to booting a Mac and double clicking your application's icon, sets up Latitude's internals, and prepares it for your application.

If your application contains compiled CDEF, MDEF, LDEF, MBDF, or WDEF resources, you will have to register these functions with Latitude and compile the definition function with the rest of your application. If your application contains any 680x0 or PPC assembler code, you will have to write equivalent code in your application's programming language.

Assuming your application is System 7 compliant (no nil pointer de-references, no low memory global accesses by address, etc.) there is little more for you to do than to compile the source code and link with Latitude's library. By specifying the location of support files in system environment variables, your Latitude ported application should find what it needs and begin running. The rest is testing and tweaking.

Of course, there are many ways to tailor your application's appearance and behavior by adding some additional Latitude auxiliary calls. For example, Latitude supports floating palettes and windows for applications that provide custom WDEFs and/or patch Window Manager functions like FrontWindow() and SendBehind(). But there are so many different ways applications achieve floating windows that we can't ensure that Latitude supports them all. Instead, we provide special auxiliary calls which help your application tell Latitude which windows should float and when. Other auxiliary calls help tailor window behavior, adornments, and appearance. Still others help to solve the different structural alignment padding rules that differ between the Mac and other platforms.

Dave M: How much of the System 7 API does Latitude currently support? Is Quickdraw supported, for example?

Dave H: Over 1,200 Macintosh Toolbox functions are implemented in Latitude. These include all of System 6 and a majority of functions introduced in System 7 except some of the newer System 7 calls. All of the user interface (windows, controls, menus, cursors, lists, events, etc.) calls are implemented as well as calls for resources, file i/o, text and script managers for Roman character sets, scrap, printing, drag-n-drop, and various utilities like SANE, OSUtils, the Time Manager, etc.

Latitude's Quickdraw implementation is one of its crowning achievements! Pictures, icons, color patterns, and off-screen graphics are automatically transformed onto native canvases. High quality dithering of 24-bit pictures for 8-bit buffers is automatic. Latitude's drawing occurs through its own set of the standard QDProcs. All pen functionality, including pixmap patterns, are supported. Latitude passes rendering operations to the native platform when ever possible to obtain top performance. But we also can render drawing operations completely in memory before being transferred to the native rendering system. This lets us support arithmetic modes in CopyBits that systems like X or DPS can't provide. Besides supporting CopyBits, CopyMask, and CopyDeepMask, Latitude's Quickdraw handles pixmaps from devices with different color byte orderings.

Latitude's picture recording and playback mechanism is completely integrated in the Quickdraw system. It reads Version 1, Version 2, and Version 2 Extended PICT formats and writes Version 2 PICTS. Latitude's PICT Interpreter has the ability to perform translation between Mac Regions and Latitude's own region implementation.

Latitude also supports GDevices of varying depths and color byte orderings. It's also possible to create GDevices with drawing area memory which is shared with the native platform image memory. This allows for extremely fast drawing performance.

For printing, Latitude has a set of QDProcs that generate PostScript that is written to a file and then sent off to the local or networked PostScript Printer. We are using some of this code to build our DPS rendering module for Rhapsody.

Dave M: How do I get to traps that Latitude doesn't support? Can I access the native APIs with a project that uses Latitude?

Dave H: There's nothing in Latitude that keeps apps from calling the native system directly. In fact, this kind of design is encouraged. Many times there are system facilities that have no equivalent in Mac Toolbox land. Latitude can be used then as a transitional tool. Developers can use it to make the first jump, put out a dot release, and then write more and more native code to take advantage of the new and evolving platform.

Latitude does have auxiliary calls to help apps access Mac Toolbox windows through their native counterparts. For example, given a WindowPtr, a special Latitude call will return the native object for that window. The app can then address the window directly. There are also calls to intercept events before Latitude processes them so that apps can manage their own windows outside of Latitude.

Dave M: I know that Latitude is written in ANSI C. Can I access the Latitude library from any language, including C++ and Objective C?

Dave H: Once Latitude is integrated into CodeWarrior and included in the CodeWarrior library set, you should be able to use it with any language supported by CodeWarrior. Latitude is currently built with GNU gcc but can also be built with the native Solaris SPARCWorks compiler and SGI's native compiler.

Dave M: If I use Latitude today to do a Unix port of my Macintosh application, will I get a free ride to Rhapsody once the Rhapsody version of Latitude is ready? Any idea of when that will be?

Dave H: As I said, one of the main goals of Latitude is to allow developers to get to many platforms with one code base. The idiosyncrasies of the platform are handled by Latitude's platform dependent modules. The API to the application remains the same. There are already Latitude clients who build their apps on SGI, SUN, and HP platforms without modifying their Mac code base. Of course, if platform specific work has been done inside the application, then this code will have to be swapped out when moving to the new platform.

Work on bringing Latitude to Rhapsody has already begun. We're also keeping close tabs on how Apple plans to shape Rhaposdy so that Latitude will be in line with what eventually comes out of Infinite Loop.

Dave M: Does Latitude hide the specifics of the file system -- i.e., will Macintosh HFS calls like StandardGetFile() or the various PB calls port?

Dave H: All of the PB and FSSpec calls to access files have been implemented in Latitude. Files in the native file system are accessible as well as Mac HFS floppies. For native files, Finder and catalog information is picked up if the files are in one of the various formats developed to represent Macintosh files under UNIX. Typically, the data and resource forks are in separate files and the file's Finder information is either included in the resource fork or kept in another separate file. Latitude understands many of these formats including AppleDouble, AppleSingle, Helios EtherShare, IPT uShare, and Xinet K-AShare. Files without resource forks or Finder information appear as plain text files.

Latitude supports all of the Standard File Package, both System 6 and System 7 calls. It supports all of the customizations applications typically make to that package's dialogs and also makes a few customizations of its own to allow the user to access files through the native file system. These Latitude customizations are done behind the scenes of the file dialog and do not interfere with any application customizations. There's even a special callback scheme in place so that apps can provide their own code to call the native get/put dialog and return a native path to the Standard File Package which in turn will fill in the appropriate reply record and return it to the app.

Again, auxiliary calls are available in Latitude to give access to the native file system by the app. There are calls, for example, to translate FSSpec formatted input into native file paths and vice versa.

Dave M: What won't port?

Dave H: Usually, not well behaved apps have the most problems. Apps that draw directly to the frame buffer or access private Mac structures, like RgnHandle data or low memory globals by address. Crawling up the stack frame using the A5 global obviously doesn't work. Basically all of the things that the Inside Macintosh books say not to do are no-nos in Latitude.

Memory Manager work-arounds don't port over well either. Some apps have the habit of seeing how much memory is available and then allocating all of it for themselves. On UNIX based systems, this kind of practice really doesn't make much sense. By disabling this kind of mechanism and simply relying on Latitude's Memory Manager calls to allocate memory, apps are assured of efficient memory usage.

Dave M: Are there any big-name apps that are currently using Latitude?

Dave H: As I mentioned earlier, Adobe has used Latitude to bring Illustrator 5.5 and Photoshop 3.0 to Sun and SGI. The Latitude Group's close work with Adobe on these projects helped us fortify Latitude a great deal. We've found that other folks using Latitude benefited enormously from the work we did on Photoshop -- the app Greg Galanos likes to call "the Mother of all apps".

Later this year, Adobe plans to begin shipping their non-linear video editing software, Premiere, on SGI's new O2 platform. From the looks of Premiere on the O2 today, this is going to be one hot product! Latitude enabled Adobe's engineers to skip past all of the user interface support and go straight to tuning Premiere's audio and video technology to SGI's amazing O2 and add a few video features that the Mac simply can't handle as well.

Other Latitude clients include more vertical market apps by developers who wanted to get to the graphics power of the SGI or the server power of the Sun or HP platform line. These apps include video and audio processing for the film industry, audio and sensitive vibration measurement and analysis for the automobile industry, and advanced photographic processing technologies used for film development and film products.

 
AAPL
$95.60
Apple Inc.
-2.55
MSFT
$43.16
Microsoft Corpora
-0.42
GOOG
$571.60
Google Inc.
-15.82

MacTech Search:
Community Search:

Software Updates via MacUpdate

OneNote 15.2 - Free digital notebook fro...
OneNote is your very own digital notebook. With OneNote, you can capture that flash of genius, that moment of inspiration, or that list of errands that’s too important to forget. Whether you’re at... Read more
iStat Menus 4.22 - Monitor your system r...
iStat Menus lets you monitor your system right from the menubar. Included are 8 menu extras that let you monitor every aspect of your system. Some features: CPU -- Monitor cpu usage. 7 display... Read more
Ember 1.8 - Versatile digital scrapbook....
Ember (formerly LittleSnapper) is your digital scrapbook of things that inspire you: websites, photos, apps or other things. Just drag in images that you want to keep, organize them into relevant... Read more
OmniPlan 2.3.6 - Robust project manageme...
With OmniPlan, you can create logical, manageable project plans with Gantt charts, schedules, summaries, milestones, and critical paths. Break down the tasks needed to make your project a success,... Read more
Command-C 1.1.1 - Clipboard sharing tool...
Command-C is a revolutionary app which makes easy to share your clipboard between iOS and OS X using your local WiFi network, even if the app is not currently opened. Copy anything (text, pictures,... Read more
Knock 1.1.7 - Unlock your Mac by knockin...
Knock is a faster, safer way to sign in. You keep your iPhone with you all the time. Now you can use it as a password. You never have to open the app -- just knock on your phone twice, even when it's... Read more
Mellel 3.3.6 - Powerful word processor w...
Mellel is the leading word processor for OS X and has been widely considered the industry standard since its inception. Mellel focuses on writers and scholars for technical writing and multilingual... Read more
LibreOffice 4.3.0.4 - Free Open Source o...
LibreOffice is an office suite (word processor, spreadsheet, presentations, drawing tool) compatible with other major office suites. The Document Foundation is coordinating development and... Read more
Freeway Pro 7.0 - Drag-and-drop Web desi...
Freeway Pro lets you build websites with speed and precision... without writing a line of code! With it's user-oriented drag-and-drop interface, Freeway Pro helps you piece together the website of... Read more
Drive Genius 3.2.4 - Powerful system uti...
Drive Genius is an OS X utility designed to provide unsurpassed storage management. Featuring an easy-to-use interface, Drive Genius is packed with powerful tools such as a drive optimizer, a... Read more

Latest Forum Discussions

See All

Dawn of the Immortals Review
Dawn of the Immortals Review By Jennifer Allen on July 31st, 2014 Our Rating: :: RESPECTABLE EXPLORATIONUniversal App - Designed for iPhone and iPad Dawn of the Immortals might not re-invent the wheel, but it does tweak it a little... | Read more »
80 Days Review
80 Days Review By Jennifer Allen on July 31st, 2014 Our Rating: :: EPIC ADVENTUREUniversal App - Designed for iPhone and iPad A fantastic and fascinating re-envisioning of the classic novel by Jules Verne, 80 Days is a delightful... | Read more »
Battleheart Legacy Guide
The world of Battleheart Legacy is fun and deep; full of wizards, warriors, and witches. Here are some tips and tactics to help you get the most enjoyment out of this great game. | Read more »
Puzzle Roo Review
Puzzle Roo Review By Jennifer Allen on July 31st, 2014 Our Rating: :: PUZZLE-BASED TWISTUniversal App - Designed for iPhone and iPad A different take on the usual block dropping puzzle game, Puzzle Roo is quite pleasant.   | Read more »
Super Crossfire Re-Release Super Crossfi...
Super Crossfire Re-Release Super Crossfighter Coming Soon, Other Radiangames Titles Go 50% Off Posted by Ellis Spice on July 31st, 2014 [ | Read more »
Hexiled Review
Hexiled Review By Rob Thomas on July 31st, 2014 Our Rating: :: HEX SELLSUniversal App - Designed for iPhone and iPad In space, no one can hear you… spell? Hexiled is a neat concept for a word scramble puzzle, but it doesn’t go too... | Read more »
Summoners War: Sky Arena Passes 10 Milli...
Summoners War: Sky Arena Passes 10 Million Installs! Posted by Jessica Fisher on July 31st, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Deep Loot Review
Deep Loot Review By Jennifer Allen on July 31st, 2014 Our Rating: :: DIVE DEEPUniversal App - Designed for iPhone and iPad Dive deep in this fun explore-em-up that’s a little grind heavy but ultimately quite entertaining.   | Read more »
Despicable Me: Minion Rush is One Year O...
Despicable Me: Minion Rush is One Year Old, Gets its Biggest Update Yet Posted by Jennifer Allen on July 31st, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Fish & Shark Review
Fish & Shark Review By Jordan Minor on July 31st, 2014 Our Rating: :: FLAPPY FISHUniversal App - Designed for iPhone and iPad Fish & Shark’s beauty is only scale deep.   | Read more »

Price Scanner via MacPrices.net

All Over For Tablets Or Just A Maturing, Evol...
CNN’s David Goldman weighs in on tablet sector doom and gloom, asking rhetorically: “Is this the beginning of the end for the tablet?” Answering that, he contends that hysteria and panic are... Read more
Letterspace 1.0.1 – New Free iOS Text Editor...
Bangkok, Thailand based independent developer Sittipon Simasanti has released Letterspace, a new text editor for iPhone, iPad, and iPod touch devices. Letterspace is a note taking app with an... Read more
Save up to $130 on an iPad mini with Apple re...
The Apple Store has Certified Refurbished 2nd generation iPad minis with Retina Displays available for up to $130 off the cost of new models, starting at $339. Apple’s one-year warranty is included... Read more
iPad Cannibalization Threat “Overblown”
Seeking Alpha’s Kevin Greenhalgh observes that while many commentators think Apple’s forthcoming 5.5-inch panel iPhone 6 will cannibalize iPad sales, in his estimation, these concerns are being... Read more
Primate Labs Releases July 2014 MacBook Pro P...
Primate Labs’ John Poole has posted Geekbench 3 results for most of the new MacBook Pro models that Apple released on Tuesday. Poole observes that overall performance improvements for the new MacBook... Read more
Apple Re-Releases Bugfixed MacBook Air EFI Fi...
Apple has posted a bugfixed version EFI Firmware Update 2.9 a for MacBook Air (Mid 2011) models. The update addresses an issue where systems may take longer to wake from sleep than expected, and... Read more
Save $50 on the 2.5GHz Mac mini, plus free sh...
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
Save up to $140 on an iPad Air with Apple ref...
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
$250 price drop on leftover 15-inch Retina Ma...
B&H Photo has dropped prices on 2013 15″ Retina MacBook Pros by $250 off original MSRP. Shipping is free, and B&H charges NY sales tax only: - 15″ 2.3GHz Retina MacBook Pro: $2249, $250 off... Read more
More iPad Upgrade Musings – The ‘Book Mystiqu...
Much discussed recently, what with Apple reporting iPad sales shrinkage over two consecutive quarters, is that it had apparently been widely assumed that tablet users would follow a two-year hardware... Read more

Jobs Board

*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
Sr. Product Leader, *Apple* Store Apps - Ap...
**Job Summary** Imagine what you could do here. At Apple , great ideas have a way of becoming great products, services, and customer experiences very quickly. Bring Read more
Sr Software Lead Engineer, *Apple* Online S...
Sr Software Lead Engineer, Apple Online Store Publishing Systems Keywords: Company: Apple Job Code: E3PCAK8MgYYkw Location (City or ZIP): Santa Clara Status: Full Read more
Sr Software Lead Engineer, *Apple* Online S...
Sr Software Lead Engineer, Apple Online Store Publishing Systems Keywords: Company: Apple Job Code: E3PCAK8MgYYkw Location (City or ZIP): Santa Clara Status: Full Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.