RSS

Daily Archives: March 15, 2012

Pascal and the P-Machine

Working with a small team of assistants, Niklaus Wirth designed Pascal between 1968 and 1970 at the Swiss Federal Institute of Technology in Zürich. His specification was implemented for the first time on the university’s CDC Cyber mainframe in mid-1970, and the system was finally considered complete and robust enough to introduce in beginning programming classes there in 1972. With his language essentially complete and with a working proof of concept in daily use, Wirth now shifted roles, from design and implementation to the equally daunting task of convincing computer-science departments around the world to give up their old languages and give his new one a shot. Like the PC industry of a decade later, the world of institutional computing was full of incompatible systems that often had trouble even exchanging data, much less programs. And yet Pascal needed to be available on all or most of these machines — or at least the ones commonly chosen by computer-science departments for pedagogical use — to have a chance of realizing Wirth’s goal of Pascal serving as an antidote to the deadly virus of BASIC. Porting the compiler by hand to all of those disparate architectures looked to be a daunting task indeed.

Wirth’s next epiphany should sound familiar if you read my earlier posts about Infocom: working closely with a graduate student, Urs Amman, he created a virtual machine, named the P-Machine, that could be hosted on all of these physical machines. They rewrote the Pascal compiler to output P-Code that could run under the P-Machine, just as Infocom later did in designing ZIL and the Z-Machine. (That’s of course no big surprise, as the P-Machine was the inspiration for the Z-Machine. If you’ve been reading these posts chronologically, I’m afraid we’ve rather put the cart before the horse.) Wirth, however, went one step further: he rewrote the Pascal compiler and other development tools themselves in P-Code, thus completing the circle. Once a P-Machine interpreter was written for any given platform, that platform could not only run the whole universe of already extant Pascal software, but also run the compiler, allowing users to create more software that could not only run on that platform but on all others for which P-Machine interpreters had been written. Similarly, updates to Pascal could be made instantly available on every platform hosting the language. Neat trick, no?

Beginning in 1973, Wirth began offering a “P-Kit” to anyone who wanted one. It consisted of the P-Code Pascal compiler and the source code, itself written in Pascal, for a P-Machine interpreter. The recipient need only (?) translate this source into a program runnable on their platform, working in assembly or some other high-level language, to get a complete Pascal environment up and running. To further encourage as many implementations as possible, Wirth published the specifications for the P-Machine in his book Algorithms + Data Structures = Programs, published in German in 1975 and in English the following year. The P-Machine did its job. By the mid-1970s universities were increasingly adapting Pascal as their standard beginning pedagogical language in lieu of comparative dinosaurs like BASIC and FORTRAN.

Meanwhile, the PC revolution was beginning, a development of which Wirth remained virtually unaware. He was after all firmly entrenched in the established institutional computing culture, and, further, he was working from Europe, where microcomputer technology was oddly slow in arriving. It would therefore be someone else, Ken Bowles of the University of California San Diego, who would spearhead a drive to bring Pascal and the P-Machine to microcomputers.

Bowles was an angry, frustrated man when he received his P-Kit in 1974. A devotee of interactive, time-shared computing over the old batch-processing model, Bowles had ascended to director of UCSD’s computer center in 1968. One of his first actions had been to replace the mainframe at the core of the center, an aged, batch-processing-bound Control Data system, with a state-of-the-art Burroughs capable of timesharing. Incredibly, however, Bowles got word from a lecturing stint in Oxford, England, in mid-1974 that the university’s administrators had decided, without even consulting him, to replace the Burroughs system with another big, traditional, batch-processing IBM mainframe. Even better, he got this news not from the university but from contacts at Burroughs, who contacted him asking why UCSD was pulling its contract. Bowles resigned his position as director in protest, going back to being just an ordinary professor, but could only watch helplessly as the trucks arrived to cart away the Burroughs system that had been essential to much of the research of him and his students. Worse, his programming classes would now have to be taught in the old way once again: instead of being able to write a program, compile it, and instantly see the result, students would have to type it out onto punched cards, deliver it to the computer center, then return the next day — if they were lucky — to see if it had actually worked. And rinse and repeat, ad nauseum.

Bowles saw the P-Kit as a possible solution to his woes, a chance to get a proper development environment back into the hands of his students. He would let the administrators have their mainframe, and try to get Pascal running on smaller, cheaper machines. Unlike his colleague in Switzerland, Bowles could even in 1974 see where the new generation of microchip technology was leading; he realized that desktop computers were on the horizon. While he would initially implement his P-Machine on a PDP-11 minicomputer, he could already envision the day when every student would have her own private computer to program. Thus the portability of the P-Machine was key to his project.

By mid-1976, Bowles and a small group of students had already come a long way, with a working PDP-11 Pascal environment that they had begun using to teach introduction-to-programming classes. (It replaced, not without controversy from traditionalists, the older FORTRAN-based curriculum.) And they had not just created a clone of Wirth’s compiler but had gone far beyond it. They had expanded greatly upon Wirth’s relatively stripped-down language, adding everyday conveniences such as better string handling and easier file access. Around it they had built what amounted to an entire Pascal operating system, all running in virtualized P-Code, similar to the interactive BASIC environments of the time but better; the text editor, for instance, was something of a marvel for its time. When UCSD Pascal began to spread, their tinkering with Pascal raised a fair amount of ire from some quarters, not least from Wirth himself, a pedantic sort who regarded the language in its original form as perfect, with everything it needed and nothing it didn’t. Still, UCSD Pascal would soon supersede Wirth’s own implementation as the standard, most notably inspiring what became the commercial juggernaut Turbo Pascal. And whatever his misgivings at the time, Wirth has since come to acknowledge the enormous role UCSD Pascal played in popularizing his design in the PC world.

In July of 1976, Bowles and his students brought their Pascal up for the first time on a microcomputer, a Z80-based system built from a kit. He describes this moment as a “revelation”; all of the software his team had created for the PDP-11 version just worked, immediately, with no changes whatsoever.

Bowles had begun his project to provide a better tool for his students, but it was soon obvious that UCSD Pascal had commercial potential outside the university. The first partnership was with a tiny startup called Terak, who had developed a workstation called the 8510/a that was basically a stripped-down, semi-compatible clone of the PDP-11 minicomputer with added bitmapped graphics capabilities that were stunning for their time. Having been first implemented on a PDP-11, UCSD Pascal was of course a natural fit there. Bowles went on the road with Terak to demonstrate the system, where the programming environment combined with the machine’s display capabilities inspired “gasps of amazement.” Terak machines soon became the standard platforms for running UCSD Pascal at UCSD itself.

The greenest pastures, however, beckoned from the burgeoning PC market. Microcomputer users and programmers were already as early as 1977 trying to reckon with the incompatible machines on the market: the TRS-80, Apple II, and Commodore PET, not to mention the dozens of kit and boutique computers, were all incompatible with one another, fragmenting an already tiny software market. Yes, these machines all ran BASIC, but each hosted a subtly different version of the language, crafted in response to the hardware’s capabilities and the whims of the machine’s manufacturer, enough to guarantee that all but the simplest BASIC programs would need some translation to move from platform to platform.

Every programmer had to deal with this reality, whether by coding in BASIC and translating as necessary (as did the general-purpose magazines, who often published type-in listings footnoted with the changes needed to run the program on platforms X, Y, and Z), developing some sort of portable game engine (as did Scott Adams, Automated Simulations, and Infocom), or just focusing on a single platform and hoping it was enough to sustain a business (as did the Apple II-specific supercoders I mentioned in my last post). The UCSD system offered another solution. Beginning in 1978, Bowles and his students started a quasi-business selling versions of the system for S-100-bus PCs to anyone who asked for one for $15. Those machines, descendents of the original Altair and generally either built from kits or provided by boutique manufacturers, inhabited a somewhat different ecosystem than the friendlier, more mass-market trinity of 1977, being the domain of the hardcore technical set that made up the core of Byte magazine’s readership and, increasingly, business users. (Tellingly, games, which dominated early software on the trinity of 1977, were few and far between on these machines.) For all that, however, there were quite a lot of them out there, and quite lot of their owners were eager to experiment with UCSD Pascal in lieu of their normal operating system of choice, Digital Research’s CP/M.

Bowles first met Steve Jobs and Steve Wozniak at the very West Coast Computer Faire at which they unveiled the Apple II. Jobs was already eying the education market, eager to forge “respectable” ties for Apple, and eager to bring professional-level software to the platform, and so the two men remained in intermittent contact. The relationship was given a boost the following year when Bill Atkinson, a UCSD alum, came to work for Apple. Atkinson, a computer engineer whose word held a great deal of sway with the un-technical Jobs, was greatly enamored of UCSD Pascal, convinced it would be a great booster for the Apple II. Still, that remained a problematic proposition at this point. Although UCSD Pascal had been designed to run on tiny machines in comparison to its inspiration, there were inevitable limits. The system was designed for a machine with at least 64 K of memory. By contrast, the first Apple IIs could be purchased with as little as 4 K, and seldom exceeded 16 K. It was an obvious nonstarter. And so the relationship between Apple and UCSD remained just talk for the moment.

In mid-1979 Apple introduced the dramatically improved Apple II Plus, which generally sold with what was taken at the time as the machine’s maximum possible memory of 48 K; the 6502 CPU used in the Apple II can only address 64 K at one time, of which 16 K was used by the ROM memory that hosted the machine’s BASIC-based operating system. They were getting close, but an Apple II version of UCSD Pascal still seemed out of reach. As it turned out, however, they were close enough that some clever hacking could get the job done.

The UCSD system would by design completely take over the machine. This meant that the 16 K of BASIC ROM would be superfluous when the machine was running the new operating system. Therefore Apple came up with a new expansion card (reason to bless Woz’s insistence on having all those slots again!) containing 16 K of RAM memory. The user could choose whether the CPU addressed this RAM (for running UCSD Pascal), or the standard 16 K of ROM (for running other software). Just like that, they had their 64 K machine.

The USCD Pascal software, renamed to Apple Pascal, was sold as a single package along with this “Language Card” for about $500 from shortly after the arrival of the Apple II Plus. It transformed just about everything about the Apple II; even its disks used their own format, unreadable under the normal Apple II environment. It would not be an exaggeration to say that an Apple II equipped with Apple Pascal was a completely new and different machine from Woz’s original creation, with a personality all its own. The inability to exchange programs and data with users who hadn’t purchased the system was, undeniably, a drawback. On the plus side, however, the user got easily the most advanced development environment available on any microcomputer of this era. Not only did she have access to the Pascal language in lieu of BASIC, but Apple and UCSD worked in quite a lot of extensions to take advantage of the Apple II’s unique bitmapped graphics capabilities, borrowing from the older Terak implementation. I’ll come back to that a couple of posts from now, when I demonstrate a concrete example of Apple Pascal in action. And we’ll start on the story that will lead to that next time.

 
 

Tags: ,