The XPL0 Programming Language

This site provides distributions of XPL0 that run under DOS and early versions of Windows, up through 32-bit Windows 7. Recent 64-bit versions of Windows must use something like DOSBox to run these programs.

A fully Windows-compatible distribution of XPL0, called EXPL, is available here: fountainware.com/EXPL/index.htm.

Most recent activity for XPL0 has been on the Raspberry Pi, which is available here.

News

A Halloween Treat awaits you under Games below.

Snarf 2.0 is posted below. It captures images from any VESA display mode, not just the standard ones. Linear frame buffers are also supported. A timer option captures images from programs, such as games, that lock out the keyboard.

Because DOSBox breathes new life into DOS programs, the 32-bit version of XPL0 for DOS has been updated to more closely match the Windows and Raspberry Pi versions. Many XPL0 programs now port between these environments without any modifications at all. This was mostly accomplished by adding 24 intrinsic routines, and automatically including 'code' declarations in new programs.


XPL0 is essentially a cross between Pascal and C. It looks somewhat like Pascal but works more like C. It was originally created in 1976 by Peter J. R. Boyle, who designed it to run on a 6502 microprocessor as an alternative to BASIC. The story surrounding its early history is here.

Although XPL0 stands for eXperimental Programming Language level Zero, it's well beyond the experimental stage and, hopefully, is regarded as well beyond level zero. The name is kept for historical reasons. The language is based on PL/0, Niklaus Wirth's example compiler in his book "Algorithms + Data Structures = Programs." Over the years, versions of XPL0 have been ported to many different computers. The programs provided on this site are mostly for IBM-compatible PCs. They all run under DOS, and DOSBox for modern Windows computers. *

Here's an example of a complete XPL0 program. It displays the (moving) image at the right, and it runs on any 32-bit PC (such as a Pentium) under DOS or WinXP. If running under Vista or later versions of Windows (or Linux or MacOS X) you'll need something like DOSBox.

Moving ripples example

 int X, Y, Z;
 [SetVid($111);             \640x480 65536 colors
 repeat  for Y:= 0 to 479 do
             for X:= 0 to 639 do
                 Point(X, Y, (X*X + Y*Y + Z)>>5);
         Z:= Z - 127;       \gently move ripples
 until KeyHit;
 SetVid(3);                 \restore text display
 ]

More examples of simple XPL0 programs are here.

Hugi Magazine has a couple articles showing how to make demoscene programs with XPL0.

XPL0 is available under the terms of the Free Software Foundation's General Public License, Version 2. All downloads from this site include source code (are open-source) and are completely free.


What Is XPL0?

XPL0 is similar to Pascal and C. Although not mainstream, over the years it has proven to be immensely useful. It has been used to write everything from operating systems for 6502- and 68000-based computers, to commercial programs for 8088-based (PC) computers, to embedded firmware for PIC and other microcontrollers. Since its inception on the 6502, it has been steadily upgraded and spread to other processors such as 8080, 6800, PDP-10, IBM-360, a couple homebrew machines, 65802, 680x0, PIC, Ubicom, and, most notably, the 80x86 family used by IBM-compatible PCs.

If you're hooked on C, XPL0 might not appeal to you. It doesn't have all the features of other languages. Normally this is not a problem, and it makes the language easier to learn.

XPL0 is by no means crippled. It's a block-structured language that supports recursion. It has two data types: integer and double-precision floating point ('reals' - with and without a math coprocessor). Even the small 16-bit version allows both code and data spaces larger than 64K. It provides generalized device I/O for the console, printers, files, and serial ports. It allows unlimited-dimensional arrays and complex data structures using pointers. It allows up to eight levels of procedure and function nesting (compare this to C which only has two). It has conditional compile, include files, separately compiled modules, inline assembly code, built-in graphic and transcendental routines, peek, poke, and port I/O.

The intent here is not to persuade you to use XPL0, but merely to make the language available. XPL0 is a significant piece of work that continues to be useful despite many other choices for programming languages.

If you're new to programming, you may find XPL0 easier to learn than the myriad of languages called "Basic." If your interest in programming is to make money, you're probably better off with Delphi or Visual C++. The versions of XPL0 offered on this website do not support Windows applications, which are expected on today's PCs. However, if you think programming is fun and want a deep understanding of how programs and compilers work, XPL0 may be for you.

If you're familiar with C, Pascal or FreeBASIC; you might find this chart helpful to see how XPL0 compares.


XPLPX 32-Bit Optimizing Protected-Mode Version

XPLPX compiles programs that run in 32-bit protected mode under DOS or DOSBox or versions of Windows that still run DOS programs. Since it's an optimizing compiler that requires a math coprocessor, floating-point operations are about ten times faster than with the earlier 16-bit XPL0. This, along with its built-in hi-res VESA graphics, makes it ideal for writing animated graphic demos and games. It uses the PMODE DOS extender (thanks Tran!). A familiarity with 16-bit XPL0 (below) is assumed.

These are screen shots of some of the example programs included in the zip file:

Ray tracing and animation

Requires:

Download XPLPX350.ZIP (257k, 15-Apr-2020).

TASMX and TLINK can be gotten from here: https://sourceforge.net/projects/guitasm8086/

or from here: http://www.jumpjet.info/Application-Software/DOS/Programming/2/compilers.htm">


XPL0 Programming Language 16-Bit Versions

The native and optimizing compilers require an assembler such as MASM or TASM. A free version of MASM can be downloaded from here: https://sourceforge.net/projects/masm611/.

The optimizing compiler generates code that is about twice as fast and half the size as the non-optimizing native compiler. This shows how the Sieve of Eratosthenes benchmark gets compiled into assembly language.

Download XPL0-31.ZIP (221k, 16-Apr-2020).

Here's the source code for the compilers and run-time support routines.
Download XSRC-31.ZIP (249k, 16-Apr-2020).


Games

Even if you're not into programming, you might enjoy running some of these games. They're all written in XPL0, and they all include the source code. They make good examples for the more advanced programmer.

Treat

Halloween
game Halloween Treat: Little Herbie has donned his costume and is eager for a night of trick-or-treating. Can you guide him through the neighborhoods and collect all the treats? Download TREAT.ZIP (26k, 28-Sep-2020).

Plat

Easter
platformer Plat is a platform game that takes advantage of new features in 32-bit XPLPX. Use the arrow keys to move the Easter Bunny and collect all the eggs. Hop over boiling lava and other hazards. A particular level can be started by typing its number (0-3) on the command line. YouTube demo. Download PLAT.ZIP (61k, 17-Apr-2020).

TeXtris

Tetris +
Scrabble TeXtris is a cross between Tetris and Scrabble. The idea is to form words from falling letter tiles. Crammed into the small exe file are the 53,800 official Scrabble words between 3 and 7 letters long. Not only is the source code included, but all the utilities that went into making this game (so, for instance, you can easily make the French version). Download TEXTRIS.ZIP (276k, 25-Jul-2011).

Matey

Chess board Challenge Matey to a game of chess - or play against another person with Matey enforcing the rules. Move pieces with the mouse, specify skill level, undo bad moves, view Matey's thinking. This is more of an XPL0 programming example rather than a strong competitor. It rates about 1100 at its level 4 (blitz). Included in the source code is a Tic-Tac-Toe program that provides a simple example of recursive tree search. Download MATEY.ZIP (56k, 25-Jul-2011).

Solo

Solo game Test your skill at solving peg solitaire. The challenge is to jump over each peg (or man, like in checkers) and see how many you can clear from the board. You win when there's a single peg left in the center. Included is a simple version of the program and a deluxe version by Ed DeWan, shown here. If the deluxe version is run under WinXP, it must be started from a DOS prompt in full-screen mode (for some strange reason). Download SOLO.ZIP (67k, 25-Jul-2011).

Invaders

Space Invaders Thirty years ago Space Invaders took over the world. Here are two versions of that historic game, one in QBASIC by James Eibisch and a translation in XPL0. Both are faithful copies of the original Taito version. You may have a problem getting the sound to work. That's because the Sound Blaster's FM registers are used, and these have been phased out on modern machines. Download INVADERS.ZIP (74k, 25-Jul-2011).

Pedeicide

Centipedes Yer basic shooter...with source of course. Have fun!
Download PEDE.ZIP (22k, 11-Jul-2012).

3D Isometric Sokoban

Isometric Sokoban The code shows how to play digitized sounds
by directly controlling the Sound Blaster registers.
(It even works under Windows!)
Download SOKOBAN.ZIP (71k, 25-Jul-2011).

8-Across Solitaire

Card solitaire Similar to but different than Windows Solitaire.
386+, 800x600 SVGA and mouse required.
Windows XP does strange things with this program unless
it's started at a DOS command prompt in full-screen mode.
Download 8ACROSS.ZIP (56k, 25-Jul-2011).

Dangerously addicting Columns game

Columns game Spoof on Windows. Make horizontal, vertical
or diagonal rows from falling icons.
286+ and 640x480 VGA required.
Runs under DOS.
Download WINDOZE.ZIP (80k, 6-Jul-2012).

Mah Jongg Solitaire

Mah Jongg Venerable Chinese tile game.
3D bamboo-laminated ivory tiles.
286+, 640x480 VGA and mouse required.
Looks better on a CRT monitor than on an LCD monitor.
Download MAHJONGG.ZIP (42k, 11-Jul-2012).

Star Trek: The Nth Iteration

Star Trek Arcade version of classic Star Trek game.
16-color animation with scrolling background.
Hi-res graphic images in text mode.
Hi-fi sound from the PC's one-bit speaker.
286+ and MDA (or VGA) required.
Runs under DOSBox 0.74, and with sound!
Apologies to Mr. Worf.
Download TREK-N.ZIP (112k, 25-Jul-2011).

Sliding Block Puzzle

Sliding block puzzle Solve it yourself or watch the computer do it.
286+ and 640x480 VGA required, mouse optional.
Describes tricks for doing high-speed graphics.
Download PUZZLE.ZIP (98k, 25-Jul-2011).

Block World

Block World 9-Jan-2012: This program understands English commands such as "Put the red block on top of the green one."

It was inspired by a much more sophisticated program called SHRDLU.

Download BLKWORLD.ZIP (22k, 9-Jan-2012).

Concentration

Concentration game Now it's your turn. Here's a simple program to launch your career as a computer game programmer! The complete code is only 4.5 pages long. Match pairs of cards by clicking on them with the mouse.

The code is purposely kept simple. You might want to convert the text images to stunning graphics (see 8Across). You might want to add a timer to see how fast you can match all the cards. Download CONGAME.ZIP (8.5k, 25-Jul-2011).


Utilities

Thumbnail Viewer

Thumbnail
viewer Thumbnails close up One of the things I have to admit I like about Windows is its ability to display thumbnails of all the images in a folder. Now you can do the same thing under DOS, at least for these file formats: BMP, GIF, LBM, IFF and PCX. Meticulously commented source code is provided so you can add the formats you want. Download THUMBS.ZIP (34k, 26-Jul-2011).

Nixie Clock

Nixie
clock This will tell you how late it is while saving you lots of money on Nixie tubes.

Download NIXIECLK.ZIP (53k, 28-Jun-2011).

nVidia/WinXP Fix

Computers with nVidia displays running Windows XP do not set the video sweep rates properly for resolutions greater than 640x480. The result is either a blank or torn-up screen. Here's a patch made by Martin Sulak that solved the problem for me. Download VideoPrt.zip (13k, 17-Feb-2005). Thank you Martin!


Animation Players

FLI animation player These animation players are courtesy of Mihai Ionascu of Romania. One runs FLI files and the other ANI files. They both use 32-bit XPL0. Lots of FLI files can be downloaded from here: http://cd.textfiles.com/maxx/tothemaxss/FLI/, and the FLI format is explained here: http://www.fileformat.info/format/fli/egff.htm.

ANI player

The ANI format was originally made for the Amiga computer. Examples and further information are here: http://www.randelshofer.ch/animations/. Watch the bee buzz and Juggette do her thing! Download ANIMPLAY.ZIP (146k, 25-Jul-2011).

Image Viewer

"See" is an image file viewer that supports these formats: BMP, PCX, LBM, BBM, IFF and GIF. It handles images up to 1280x1024 in 24-bit color and displays GIF animation (like shown here). It uses a file navigator similar to the Open dialog box in Windows. Well-commented source code is included so you can add the formats you want. Download SEE.ZIP (36k, 25-Jul-2011).

Image Snarfer

Snarf is a TSR program that takes snapshots of virtually any DOS graphic or text screen. It's particularly useful under Windows XP, which does not capture DOS graphic screens. Although Snarf is not an XPL0 program, it's so useful it had to be made available somewhere. It's 100% assembly code, and the source (of course) is included. Download Snarf20.zip (30k, 18-Aug-2020).

Logic Lab

Logic lab 7-segment driver Simulate basic logic circuits. Quickly "wire-up" gates and flip-flops. Connect them to push buttons or clock generators, and watch 'em run. Red and green signal lines show the logic levels (0 or 1). A group of gates can be selected then dragged, duplicated, deleted, or deMorganized. Windows-like GUI runs under DOS, Win3.1, 95, 98, and XP (even with nVidia), but not WinNT nor 2000. Source code included. Download LOGICLAB.ZIP (69k, 25-Jul-2011).

Colorful improvement on DOS's DIR command

Sort files by name, extension, date, or size.
Discover how clusters waste your disk space!
Shows sizes of subdirectories. Includes
Customizer program and XPL0 source code.
Download COLORDIR.ZIP (67k, 25-Jul-2011).

Double Print and Quad Print utilities save paper

DPR prints two pages side-by-side in landscape
mode on an HP LaserJet or Inkjet printer.
Pages are 80 characters by 60 lines.
Lines longer than 80 characters are wrapped.
Also handles Linux newline (an LF with no CR).
QPR prints four pages in two columns in portrait mode.
Download DPR.ZIP (13k, 11-Nov-2019).

LaserJet Printer utility

Print plain ASCII files (such as listings) on a LaserJet, Inkjet
or DeskJet printer. Acts as a front panel that lets you select:
Download JPR.ZIP (14k, 11-Nov-2019).

File Compatibility

Some utility programs to make DOS text files more compatible. The source code shows a nice way to handle file I/O.
Download COMPAT.ZIP (26k, 25-Jul-2011).


Miscellaneous

Ellipse plotter BS grinder Although this device can be used to draw ellipses and is called a "Trammel of Archimedes," it's more commonly known as a "BS Grinder." With the program you can view it from any angle while it grinds away.


Escher lattice The Lattice program is a version of M.C.Escher's Cubic Space Division. It consists of 5,324 blocks which are drawn as 31,944 triangles. My Athlon 2400 updates the screen ten times per second without hardware acceleration.

These programs use the Z-buffer rendering technique, which solves the visible surface problem for objects of any shape. It also provides X-ray vision!

Download GRINDER.ZIP (58k, 24-Mar-2020).


Cubic Demo

Demoscene code
example
Here's Boreal's Cubic demo, complete with source (which is required to even run this self-referential program). It utilizes 640x480 graphics in 256 colors and runs on a 500 MHz (or faster) processor. The Caps Lock key pops up a window showing the CPU usage. Download CUBIC.ZIP (39k, 25-Jul-2011).

Maze Madness

3D mazes

Here's a selection of maze programs from simple to complex - rectangular, hexagonal, and spherical - 2D and 3D - inside and out. Perhaps one of these eight programs will strike your fancy. Download MAZEMAD.ZIP (130k, 10-Jun-2012).

Block Transfer Computations

Block transfer animation As Doctor Who would be delighted to explain, block transfer computations
are computations sooo complex that no computer can handle 'em. However
by exploiting the power of XPL0 and avoiding defenestration by Windows
you can now witness this historic event in your very own home!
Download BTC.ZIP (20k, 25-Jul-2011).

Raycaster

Raycaster example Here's a simple version of a raycaster like used in Wolfenstein 3-D.
The essentials are boiled down to seven pages of commented code.
Use your mouse to move through the rooms.
Could this be the start of your FPS game?
Download CAST.ZIP (42k, 6-Apr-2014).

Pentomino Puzzle Solver

Pentomino solver Fit the 12 pentomino pieces into the box.
Example of recursive tree search with detailed
write-up by Lenny Boreal.
Download PENTS.ZIP (19k, 25-Jul-2011).

Programs like Pents stop running after a few seconds under Windows XP unless the Idle Sensitivity lever is set all the way to the Low position. This setting is buried in a Shortcut under Properties -> Misc.

Lorenzian Waterwheel

Lorenzian waterwheel simulation This waterwheel defies expectations by periodically
reversing direction. It demonstrates the Lorenz
Attractor, the famous set of equations that turned
the physicist's world into chaos.
Download WW.ZIP (19k, 25-Jul-2011).

Lorenz Attractor

Lorenz Attractor Stereo 3D plot of the Lorenz Attractor.
"Can the flap of a butterfly's wing stir up a tornado...?"
72 Lines of XPL0 code.
Download LORENZ.ZIP (14k, 26-Apr-1999).

Dr. Eliza

Discuss your most intimate problems with the doctor.
Game? Or therapeutic tool?
Classic example of artificial intelligence run amok.
Download ELIZA.ZIP (17k, 31-Oct-2011).

Simple Mandelbrot Plotter

Simple Mandelbrot example The Mandelbrot set is the set of points C that do not cause Z
to go to infinity when this equation is repeatedly calculated:
Z := Z^2 + C
Z and C are complex numbers. They consist of two values called
real and imaginary....
Download MANDEL.ZIP (25k, 10-Jun-2012).

Simple Mandelbrot code


Old News

27-Sep-2016: Thanks to Ed at http://dxforth.mirrors.minimaltype.com/ an old version of XPL0 has been resurrected that runs under CP/M on an 8080 processor. Not all the features described in the XPL0 IBM-PC manual are available in this CP/M version. In particular 'include', floating-point, graphics, and intrinsics relating to the IBM-PC are not implemented. Some intrinsic numbers are also different. However, many modern features have been added that make this a viable version 1.2. Download XPLCPM12.ZIP (229k, 27-Sep-2016).

Version 1.2 solves an incompatibility with the CP/M emulator's method of handling file names. Here's the emulator: CPMEXE12.ZIP (136k, 27-Sep-2016).

11-Jun-2012: Improved versions of the compilers and their supporting runtime code are posted. You can read about these improvements in the Addendum section in the new manual, but here's the latest:

18-Apr-2008: Thanks to Ed of DX-Forth fame ( http://dxforth.mirrors.minimaltype.com/ ) an incompatibility between 32-bit XPL0 and some graphic display cards has been fixed. The problem was introduced with version 3.3.4. Only two programs were affected (XPLPX335 and BTC), and their updated versions are now posted. (Some BIOSes alter the contents of the AX register for *all* calls to interrupt 10h even though the documentation does not indicate they're returning a value in AX.)

3-Jul-2006: A recipe for turning a torus into a donut: Real-Time 3D Rendering in XPL0.

4-Aug-2005: XPL0 Runs on Homebrew Machine: John Doran, a member of our local computer club (the 6502 Group), designed and built a computer based on 7400-series TTL. How it came to run XPL0 is described here.

13-May-2005: Another bug has been found and fixed. This time it was in Sokoban. Thanks goes to James Newton who reported it. (James BTW is the force behind PIC List . His main website is at: http://www.massmind.org ) Thanks also goes to Larry Fish, coauthor of XPL0, who pointed out that the problem was a bad intrinsic call when a digitized sound was about to be played. (Larry's Compass website is at: http://fountainware.com/compass/)

3-Oct-2001: The complete source code for the Apex operating system that runs on the Amiga A1000 and A2000 computers is available here: APEX-SRC.ZIP (339k).

Apex is roughly similar to Amiga's CLI (Command Line Interpreter) and MS-DOS. In addition to the Apex kernel, there's source for an XPL0 compiler, 68000 assembler, debugger, text editor, and numerous utilities.

The code is released "as is." It will take some effort to sort it out. I'll improve the documentation if interest warrants. Start with README.TXT.

Executable images of bootable diskettes are here: APEX-BIN.ZIP (207k). You will need to devise a way to copy these images onto an Amiga floppy (starting at the very beginning: track 0, sector 1). A1000.BIN boots in place of KickStart and occupies the KickStart RAM. A2000.BIN boots in place of AmigaDOS and requires a 68020 chip.

28-Jul-2001: If you've been looking for the version of XPL0 that runs on Parallax SX (formerly Ubicom, formerly Scenix) microcontrollers, it's here: Download SXPL.ZIP (131k).

26-Jul-2001:
Demoscene scroller Lenny Boreal releases his text scroller.
This elegant program with its "jumpin'
graphics" is a mere two pages of code!
Download SCROLLER.ZIP (7.4k).

22-Jul-2001: Archaeological dig unearths ancient XPL0 programs. Many are for old computers, such as the Apple II and Amiga, and will not run on a PC without modification. OLDXPL.ZIP (1158k)

9-Jun-2001: Example of a driver for a SanDisk MultiMediaCard. This is 8088 assembly language rather than XPL code, but I didn't know where else to put it. MMC Source Code

2-Jun-2001: CueCat barcode scanner example


* Unfortunately Microsoft Windows gave up on being upwardly compatible with DOS programs. Each successive version of Windows did a poorer job of supporting them. Windows 98 had the ability to restart in MS-DOS mode. Windows XP went to "heroic lengths" to support DOS apps but still introduced many incompatibilities. Windows Vista and Win7 won't run any kind of DOS graphics program, not just XPL0's. They pop up the message saying, "This system does not support fullscreen mode." Nothing in the Compatibility mode settings solves this problem. Sixty-four-bit Windows is the final straw. It won't even run a one-byte program (RET) that has worked on everything prior. DOSBox and virtual machines (such as VMWare or Virtual PC) do provide a partial solution, but they run programs slowly and convulsively, and are certainly not as convenient as simply booting into good-old-fashioned DOS (which works fine on 64-bit processors). If you're dismayed by all the problems created by Windows, it might be helpful to realize that WINDOWS stands for: Windows Is Not DOS - Only Works Sometimes.


This site is maintained by Loren Blaney. He'd very much enjoy hearing from you. If you have any feedback, programs you'd like to see, or especially bug reports, please send him a note at: loren (dot) blaney (at) gmail (dot) com.

Last update: 8-Jan-2021