7 ms·
The UCSD p-System, Apple Pascal, and a dream of cross-platform compatibility
- csdvrx 2y agoThe dream has been realized with the release of cosmopolitan. There's no reason we couldn't have a cross-platform minimal set of common utilities.
- _mlbt 2y agoCosmopolitan is very impressive indeed, although it is a very different approach than byte code systems like the p-System, Java, and .NET. Each approach has its merits.
- detourdog 2y agoI think it’s interesting when one considers the Macintosh and Pascal and NeXT and Objective-c
- wahern 2y agoI think Cosmopolitan support on OpenBSD is broken (since 7.5?). And IIRC it also conflicts with WINE on Linux without explicit binfmt support. It's amazing and laudable that Cosmopolitan managed to thread the needle the way that it did, but it's also entirely unsurprising that it's been broken; and even if fixed would be broken again.
- frumplestlatz 2y agoUnless something has changed since I last looked at it, cosmopolitan depends directly on the host's raw syscall interface everywhere but Windows (on Windows, it correctly dispatches syscalls through supported userspace libraries, e.g. `kernel32.dll`). This is unsupported, undocumented, and unstable on every target cosmopolitan supports other than Linux — macOS and (Free|Net|Open)BSD define their syscall ABI as private and subject to arbitrary change, and they do change it. The only supported syscall interface is via their userspace libraries, and binaries that target the syscall ABI directly will fail on future releases. Furthermore, while cosmopolitan binaries are multi-arch (amd64/arm64 currently) and multi-OS (Linux/Windows/macOS/...), they are arch-specific and OS-specific. Once support for a new target has been added to cosmopolitan, existing binaries must be rebuilt to include it; existing binaries cannot run simply by porting a common runtime. On top of all that, the APE executable format relies on ill-defined fallback heuristics — which may or may not be implemented by a shell — for executable files that fail with ENOEXEC after first calling `exec()`, but look like they may be '#!'-less shell scripts. Unsurprisingly, this is unreliable, depends on the user's shell, and means that programmatically executing an APE executable using `exec`, `posix_spawn()`, etc, will simply fail. Cosmopolitan is neat hack, but it's not a viable multiplatform executable format, runtime sysytem, or distribution mechanism. Something like WASM + WASI seems much more likely to fulfill this function in the future.
- mbessey 2y agoYes, it's a cool hack, but doesn't really even approach the same use cases as something like p-code.
- csdvrx 2y ago> Cosmopolitan is neat hack, but it's not a viable multiplatform executable format, runtime sysytem, or distribution mechanism. It's the best we have to ensure programs will be kept running. The multiple payloads are like a rosetta stone. If I had 1 wish, I would make wine support sixel output + VNC to a localhost port + webgl or equivalent to extend this redundancy to GUIs > Something like WASM + WASI seems much more likely to fulfill this function in the future. Time will tell, but given 2 binaries (Sun Java vs Windows i386) from the same time period, the one that was "much more likely to fulfill this function in the future" is much harder to use p-code is a neat technology, but failing at what it was supposed to achieve
- wduquette 2y agoThe UCSD p-System was amazing. I used it on a Heathkit-branded PDP-11, the Apple II, and an HP-9000 workstation; and though the author doesn't mention it, the first version of Borland's Turbo Pascal for CP/M and DOS had a UI that was clearly influenced by the p-System's UI. The coolest thing about UCSD Pascal when I first encountered it was it supported "full screen" programs, notably the system's text editor, via the `gotoxy(x, y)` intrinsic. This procedure moved the cursor to the specified character cell on the terminal. Prior to this I'd only used line-oriented editors.
- mbessey 2y agoI did mention the Turbo Pascal connection briefly, and I'll probably make a more in-depth comparison in a later post on just the IDE. I used a fairly early version of Turbo Pascal for DOS for several years after High School. I can still remember the absolute terror of realizing you'd pressed "R" without saving first.
- sitkack 2y agoI never used it, are you saying you could Run the current program and it might accidentally bring your entire system down without having saved the program? Seems like at least a two file circular buffer with autosave wouldn't take up too much space, or maybe streaming diffs into a compressed buffer (even on a 286, this shouldn't be too much trouble).
- kragen 2y agoI think that is what he is saying, though I can't remember the TP command set well enough. Turbo Pascal wasn't written on a 286; it was written for CP/M, where I think it required 48KiB of RAM. A "fairly early version of Turbo Pascal for DOS" might have required 64KiB? You can't really stream things onto a floppy disk (remember that early home computers and the IBM PC didn't have hard disks; they didn't become standard equipment until the late 80s). You have to write a whole sector at a time, which can take a second or two to seek the disk to the appropriate track; rotating the disk to the right sector takes a significant fraction of a second. Journaling your edits to a journal file was a feature that EDT on VAX/VMS had around that time, but there wasn't really a practical way to do that on a home computer.
- stevekemp 2y agoI "recently" wrote a CP/M emulator, and I have a lot of love for the kinda vintage software out there that still runs on it. https://github.com/skx/cpmulator/ https://github.com/skx/cpmulator/ Over the past few days I've seen posts on hacker news discussion 6502 assembly, people coming to the infocom games, and similar things. There's a lot of interest out there in this retro stuff, even now.
- mbessey 2y agoSurely some of it is just nostalgia for a "simpler" time, but I think there is a legitimate reason to preserve and celebrate these older systems, too. It's essentially impossible for a single person to build something as complex as a modern PC "from scratch", or indeed to build an operating system that compares to Windows, Linux, or MacOS. These old microcomputer systems are simple enough for one person or a small team to understand and build, and they are/were capable of doing "useful work", too, and not so overly-abstracted like some "teaching systems" are. I think that for me, part of the point of digging into something like the p-System is to show some of the brilliant (and stupid) ideas that went into building something as ambitious as a "universal operating system" in the mid-1970s.
- kragen 2y agoProbably what you want to check out is Oberon, which is a modern PC built basically from scratch, along with an operating system that compares to Windows, Linux, or MacOS, built originally not by a single person but by maybe a dozen people. It's capable enough that it was the daily driver for numerous students during the 80s; the earliest versions of it were built in-house by necessity because graphical workstations weren't a product you could buy yet. Wirth's RISC CPU architecture avoids all the braindamage in things like the Z80 and the 80386. I think that, with their example to work from, a single person could build such a thing. Oscar Toledo G. also wrote a similar graphical operating system in the 01990s and early 02000s, working on the computers his family designed and built (though using off-the-shelf CPUs). You can see a screenshot of the browser at http://www.biyubi.com/art30.html http://www.biyubi.com/art30.html and read some of his reflections on the C compiler he wrote for the Transputer in his recent blog post at https://nanochess.org/transputer_operating_system.html https://nanochess.org/transputer_operating_system.html. There's a lacuna in the recursivity of Wirth's system: although he provides synthesizable source code for the processor (in Verilog, I think) there's no logic synthesis software in Oberon so that you can rebuild the FPGA configuration. Instead you have to use, IIRC, Xilinx's software, which won't even run under Oberon. Since then, though, Claire Wolf has written yosys, so the situation is improving on that front. CP/M is interesting because it's close to being the smallest system where self-hosted development is bearable; the 8080 is just powerful enough that you can write a usable assembler and WYSIWYG text editor for it. But I don't think that makes it a good example to follow. We saw this weekend that Olof Kindgren's SeRV implementation of RISC-V can be squoze into 5900 transistors (in one-atom-thick molybdenum disulfide, no less) https://arstechnica.com/science/2025/04/researchers-build-a-risc-v-processor-using-a-2d-semiconductor/ https://arstechnica.com/science/2025/04/researchers-build-a-... https://news.ycombinator.com/item?id=43621378 https://news.ycombinator.com/item?id=43621378 which is about equivalent to the 8080 and less than the Z80. And Graham Smecher's "Minimax" https://github.com/gsmecher/minimax https://github.com/gsmecher/minimax is only two or three times the size of SeRV and over an order of magnitude faster. There's no reason to repeat the mistakes Intel made in the 01970s today. We know how to do better!
- sillywalk 2y agoIn a similar vein, the game Another World[0] had a VM, and the IBM System/38 (aka AS/400 aka iSeries aka System i(5) aka i)[1][2] had/has a Technology Independent Machine Interface that acts as an abstract machine that sits underneath most of the Operating System. [0] https://fabiensanglard.net/anotherWorld_code_review/index.php https://fabiensanglard.net/anotherWorld_code_review/index.ph... [1] https://treasures.scss.tcd.ie/hardware/TCD-SCSS-T.20121208.068/IBM-AS400-technical-introduction.pdf https://treasures.scss.tcd.ie/hardware/TCD-SCSS-T.20121208.0... [2] https://en.wikipedia.org/wiki/IBM_i https://en.wikipedia.org/wiki/IBM_i
- musicale 2y agoScummVM seems to support several game VMs in addition to SCUMM. Another World seems to have been considered but determined to be out-of-scope. https://en.wikipedia.org/wiki/ScummVM https://en.wikipedia.org/wiki/ScummVM
- kragen 2y agoI used the p-System on a Heathkit H-89. I think the overall approach of future-proofing your software by compiling it to a simple, portable virtual machine is valid. Since the p-System, in addition to the JVM and Zork Z-machine mentioned in this post, we've seen Smalltalk-80, PostScript, Open Firmware aka OpenBoot, Glulx, the ASS/400, the Open Software Foundation's ANDF (the architecture-neutral distribution format), Google's NaCl and pNaCl, Microsoft's CIL, JS as a compilation target, WebAssembly, uxn, and the revival of old video game consoles in emulation as a stable software target. A problem with this approach is that most of these portable platform layers are still far too unstable for reliable archival; even video game emulators face a constant struggle to maintain compatibility as they are updated to keep up with whatever platform they're running on. Platforms like the JVM, which make more concessions to efficiency than MAME, have even more difficulty, so the JVM's slogan of "write once, run anywhere" was widely mocked as "write once, debug everywhere". But it's a good aspiration. I'd like to see it realized in a practical way. My memory of the p-System is that it was almost unusably slow, a problem made worse by its filesystem being so simple it didn't support fragmentation, so sometimes you had to defragment your floppy disk in order to write new files onto it. It's true that its UI was screen-oriented, as wduquette said, and it was driven by a Lotus-1-2-3-like menu system, which enhanced its usability quite a lot. Being a pure bytecode interpreter was a serious handicap, especially on the sub-1-MIPS machines we were running it on. EUMEL managed to make a go of it. I never got a chance to use EUMEL on an actual Z80, but I hear it was usably fast; I suspect the EUMEL virtual-machine instruction set (which included string operations) and operating environment went a long way towards compensating for the slowness of bytecode interpretation, much as Numpy does on CPython today. I suspect you could have done a better job with a bytecode more like Dalvik, designed for efficient JIT compilation by leaving less work for the JIT compiler. But Deutsch and Schiffman didn't publish the first JIT-compilation paper until a few years after the p-System was released. (Schiffman told me a self-deprecating joke about this which I guess I can't really repeat.) Long Tien Nguyen and Alan Kay published a paper on designing a very simple virtual machine for such digital preservation 10 years ago: https://tinlizzie.org/VPRIPapers/tr2015004_cuneiform.pdf https://tinlizzie.org/VPRIPapers/tr2015004_cuneiform.pdf I think these ideas point the way to achieving the kind of future-proofness that the p-System was shooting for.
- 2y ago
- Mn7cB_3kL 2y ago[dead]
- wahern 2y agoWhat's the relevance of Docker here? It's not mentioned in the article, and more generally I can't think of cases where Docker would help with backward compatibility, except perhaps making it easier to, e.g., handle old code with hardcoded paths (i.e. a fancier chroot).
- kragen 2y agoLike any chroot, Docker images include all your library dependencies, which keeps your code from being broken by library upgrades — or from having its security vulnerabilities closed.
- nxobject 2y agoApropos of that: know QEMU has an extensive hardware emulation library, but it shouldn't be taken for granted – Apple M-series support isn't quite there (here's a console-only solution [1]), and it would a significant platform to lose emulation for. [1] https://github.com/cylance/macos-arm64-emulation https://github.com/cylance/macos-arm64-emulation
- kwertyoowiyop 2y agoJust think, Pascal on an Apple II cost about $1,800 in today’s dollars.
- timbit42 2y agoWas that before or including the extra hardware (RAM) to run it?
- creeble 2y agoVersaCAD was the only commercial program I can remember for p-System. It ran from floppies, or a hard drive that could be set to boot it. It was a great CAD program, I many ways ahead of AutoCAD in its time. But AutoCAD was written in C, which proved far more popular (and, ultimately, more portable) than UCSD-p.
- cduzz 2y agoThe first Wizardry[1] was built on the P system. My dad spent a small fortune buying an IBM PC with 544k of memory and an external Davong hard drive that emulated an enormous floppy drive. He also put UCSD P system on this beast, along with a tecmar graphics master... I used the p system's editor to write school papers for a long time. It was some weird modal editor; he switched to Dos and turbo pascal after a while... I got to use this computer for games when he wasn't using it and found that the _wizardry_ save game disks were formatted in UCSD P system format and I could even noodle around with the save games (mostly resulting in the game crashing). [1]https://en.wikipedia.org/wiki/Wizardry:_Proving_Grounds_of_the_Mad_Overlord https://en.wikipedia.org/wiki/Wizardry:_Proving_Grounds_of_t...
- dlinder 2y agoAround 1995, our high school "Pascal I" and "Pascal II" classes were taught in a forgotten Apple //e lab in the Math wing of the school. The PC and Mac labs were occupied by typing, word processing, and desktop publishing classes. I think every other kid in class groaned, but to a hamfest scrounger of PDPs, Vaxen, and weird UNIX workstations, UCSD p-System Pascal on Apple hardware was weirdly intriguing, the cherry on top being that the whole lab was served by a Corvus hard disk shared over, I think, an "Omninet" network. We'd all come in, turn on the lights, turn on the computers, and then have the lecture portion of class while this poor early NAS would serve Pascal to 20-odd machines simultaneously. I think we saved our work on floppy disks, though maybe that was a backup, as I think I recall turning in our work by saving to the Corvus? Even at the time, it all had a very "you are living the early experimental days" feeling to it.
- icedchai 2y agoThat brings back memories. My high school also had a Corvus. You could definitely save files to it. I remember writing some Basic programs and it would show up as a Prodos "device" (or maybe it was a volume.) That was the first time saw any type of network.
- SomeHacker44 2y agoI used this in/around 1982 or 83 on an Apple ][+. I remember hacking Wizardry, my favorite game, and discovering it seemed to run on Apple Pascal as well. Such fun times. I love this hacking project of the OP.
- whartung 2y agoFrom the Terak Museum[0] from the Terak thread[1] there was this anecdote > What does the Terak have to do with the Macintosh and MacPaint? The Macintosh's operating system was bootstrapped on an Apple Lisa computer. The Lisa's OS was written on the Lisa using a port of the UCSD Pascal compiler and P-System. The Lisa's port of the P-System was prepared on an Apple II, which had its own version of the P-System that was developed by Bill Atkinson, the Apple programmer who later wrote MacPaint. Atkinson ported the P-System to the Apple II while visiting UCSD, who helped Apple with the port using a Terak. Some people think he got the idea for MacPaint from the paint programs he saw in use on the graphics-intensive, square-pixel Terak. Thanks in part to Gary Capell (gary@cs.su.oz.au) for parts of this story. Its a great anecdote. And it also makes one think "They wanted to use Pascal so badly, they were willing to use UCSD Pascal for it." UCSD Pascal was a wonder and a pioneer. Unfortunately, it was in the early era of microcomputers. When microcomputers were, frankly, horrible. File this anecdote under "its amazing we managed to get any software written at all" back then. In the P-System, you had the core VM, and everything else was compiled into that P-code. The shell, the compiler, the file utilities, everything. Again, it's a marvel. It's (almost) self hosted (did it come with an assembler? I don't recall). But if you had a VM running, everything else was self hosted. The compiler compiled itself, being written in UCSD Pascal. Marvel yes, speedy, not so much. It certainly qualified as "better than nothing". It had a lousy file system. Files had to be continuous, which makes it difficult to write to more than one file at a time. Compressing the disk structure was a routine process. The editor was also very interesting. Also, text files naturally compressed whitespace -- important with Pascal source code where whitespace is probably 20-30% of the space on disk. However, on the other hand, the runtime was quite sophisticated. P-Code was position independent, so it could read, run, and flush code at will. The code was segmented into chunks, "overlays" being the norm. But as user of the code, it was mostly invisible to you (you know, the way RPC is invisible). If you look at the original Macintosh memory and resource manager, and how it stored applications in segments, you can see the lineage straight from what UCSD was doing back in 1977. And, of course, UCSD Pascal had that novel feature of being an actual, usable Pascal for, well, demonstrable system level programming, and also large system design through the use of Units and such. Novel at the time. The real shame of the UCSD eco-system, specifically today, was when USCD licensed it to SofTech (something like that), who came out with P-System IV (P-III was a unique port to, I think, a Sage 68K machine). The ship had sailed for "but it's not DOS" types of systems that SofTech was trying to squeeze UCSD back into. But it had some cool features, notably it supported co-routines. But, while P-System 1.5 and P-System II are all flying free around the interwebs, P-IV is not. It IS well documented, but whoever owns SofTech today, hasn't released the legacy stuff to world. Also, as a shout out to the Blog author. Do a search for, I think, the game SunDog. This was written in P-System IV, and they have a P-machine in C (or C++) that you can look at. The part of the P-Machine I haven't quite grokked, is the way it handles stack frames. Because Pascal allows nested functions (and scopes), it had primitives to access "variable 3, 4 stacks frames up" kind of thing, so its a bit of a maze (plus the first class support for the segments in the runtime as well). I was looking at trying to port it to the 65816. The P-System would naturally work well with a 128K 65816 using their data bank model. You could have the runtime in its own 64K bank, the P-Code in its own, and then 64K of data ram in a 3rd. I thought that would be a neat '816 project. [0] https://www.threedee.com/jcm/terak/index.html https://www.threedee.com/jcm/terak/index.html [1] https://news.ycombinator.com/item?id=43708726 https://news.ycombinator.com/item?id=43708726
- musicale 2y ago> Get Apple Pascal up and running in some kind of emulator on my Mac, so I can experience it again I wonder if Lisa Pascal will run in a Lisa emulator... > Build a p-machine emulator, in Rust Probably a p-code interpreter and/or p-system VM! (Analogous to the JVM but for Pascal/p-system rather than Java and its bytecode. p-code translator/JIT compiler probably left as an exercise for the reader.) I'm surprised that nobody seems to have written one in JavaScript and/or webassembly... the latter basically being p-code for the 2020s.
- mbessey 2y agoI haven't seen a web-based p-System, either, which was a little surprising to me. You can run either the Apple or CP/M versions through emulating the entire computer, though. That is probably why nobody's felt the need to make a p-System for the web.
- deleted 2y ago[deleted]
- GregDavidson 2y agoThe UCSD "Computer Scientists" were a small group of undergraduates working in Ken Bowles' lab. We were supposedly following Professor Bowles' directions but he was a fairly conservative physicist and we had lots of radical ideas - fortunately he was tolerant. The p-code was not just machine independent - by careful design it was approximately 1/4 the size of native code on those early 8 and 16-bit microprocessors, allowing us to effectively almost quadruple the amount of code we could fit in 64K - minus the interpreter which was 8K of machine code and minus another 8K on PDP-11s for I/O space. We would also use native code for hotspots without appreciably expanding code size. This key idea is what allowed us to have a high-level OS and development environment on those dinky machines when everyone else was compromising quality to get things to fit. Alas, CopyLeft had not yet been invented, the UC sold the P-System and we lost legal access to the code we'd written.
- musicale 2y ago> Alas, CopyLeft had not yet been invented, the UC sold the P-System and we lost legal access to the code we'd written. Compare with UC Berkeley's BSD UNIX, which was originally open sourced in 1988 (though hamstrung from 1992-94 by the Unix lawsuit, opening the way for Linux), and happens to be running in the system I'm typing on... It appears that UCSD eventually (2006?) made the p-System 1.5 source code available for download, but unfortunately non-commercial only (CC BY-NC-SA?) rather than BSD, etc.
- mbessey 2y agoWhen I get around to analyzing the p-code instruction set, the code-compression aspect will definitely get a mention. Stack-based vs register-based instruction sets are a very clear size vs speed tradeoff. That's also one reason that the Java VM was designed with a stack architecture, though in that case, it was download time they wanted to minimize. The whole thing with UCSD having to essentially "give away" the p-System to a separate commercial entity is a sad part of the history, for sure.
- rgleaves 2y agoThe saddest part of the UCSD Pascal giveaway: SofTech in fact achieved its goal with the purchase, which was not to keep the p-System competitive, but rather to polish their 1981 public stock offering: https://www.sec.gov/news/digest/1981/dig072081.pdf https://www.sec.gov/news/digest/1981/dig072081.pdf