The XPL0 Programming Language
This is the distribution site for the XPL0 language. It's also the place
to get examples, utilities, and games written
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
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 made for many different kinds of computers. The programs
provided here are mostly for IBM-compatible PCs. They all run under DOS
and under versions of Windows that can still run DOS programs. *
Here is an example of a complete XPL0 program. It displays the (moving)
image at the right, and runs on any 32-bit PC (such as a Pentium) under
DOS or WinXP. If you're running under Vista or Win7, or Linux or MacOS
X, you'll need something like DOSBox.
int X, Y, Z;
SetVid($111); \640x480x65536 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
SetVid(3); \restore text mode
More examples of simple XPL0 programs are here.
If you like demo programs, Hugi Magazine has a couple articles showing how to make them with
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
30-Jan-2016: Thanks to Ed at http://dxforth.netbay.com.au/
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.1.
Download XPLCPM11.ZIP (229k, 29-Jan-2016).
5-Oct-2015: Raspberry Pi programs now run up to four times faster with
the new optimizing compiler. Sluggish animations now go as fast as the
PC versions under Windows and DOSBox. Check it out. www.xpl0.org/rpi.
6-Apr-2014: Now you can run XPL0 programs on your Raspberry Pi.
Patched up the cracks in the raycasting program and added other
enhancements (see CAST.ZIP).
11-Jun-2012: XPL0 now supports Windows applications! EXPL also provides
an integrated development environment (IDE) with an editor, debugger, and
profiler. It's available from this site:
Improved versions of the DOS-based compilers and their supporting
runtime code are posted below. You can read about these improvements in
the Addendum section in the new manual, but
here's the latest:
- The double backslash "\\" comments out everything on the rest of
line regardless of any backslashes it might contain. This is handy for
commenting out sections of code.
- When a program starts, any characters entered on the command line after
the program name are copied into device 8's buffer. This provides a
convenient way to pass information to a program, such as file names or
- The at-sign (@) is an alternative "addr" operator that works better when
returning reals from a procedure that uses the call-by-reference
technique. It works exactly the same as "addr" when used on an integer
variable, but it returns a real pointer when used on a real variable.
Note that "addr" and @ also work on subscripted variables.
- The starting (integer) value for an enumeration can be specified instead
of always starting at zero. For example:
- The "string 0" option for zero-terminated strings is now available in
all versions. The Text intrinsic works no matter which termination is
- The random number generator has been improved several times to
where it now passes all the Diehard tests. Diehard tests
5-Mar-2012: 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
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
These programs use the Z-buffer rendering technique, which solves the
visible surface problem for objects of any shape. It also provides X-ray
Download GRINDER.ZIP (58k, 5-Mar-2012).
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).
This will tell you how late it is while saving you lots of money
on Nixie tubes. Download NIXIECLK.ZIP (53k,
26-Jul-2011: Some long-neglected maintenance has been done, such as
fixing broken links and re-linking programs that didn't run under DOSBox
("packed file corrupt" - thanks Rugxulo!). There are new versions for
Matey, See, and DPR.
One of the things I have to admit I like about Windows XP 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
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
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 8 levels of procedure and
function nesting (compare this to C which only has 2). 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 of this webpage 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 massive support behind other
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.
These examples will give you a quick idea of
what XPL0 is like.
If you're familiar with C, Pascal or FreeBASIC; you might find this chart helpful to see how XPL0 compares.
- Less cryptic than C
- Less restrictive than Pascal
- More powerful than BASIC
- Three compilers:
- Cross-reference utility
- Library routines
- Many program examples
- 140-page manual with index and addendum
- Runs on an IBM PC-XT (8088)
The native and optimizing compilers require an assembler such as MASM or
TASM. A free version of MASM can be downloaded from here:
http://www.aurskogcity.8m.com/compilers/compilers.html. Version 5.10
is sufficient and recommended.
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-30.ZIP (220k, 12-Jul-2012).
Here is the source code for the compilers and run-time support routines.
Download XSRC-30.ZIP (254k, 10-Jun-2012).
XPLPX compiles programs that run in 32-bit protected mode under DOS 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 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 is assumed.
These are screen shots of some of the example programs included in the
Download XPLPX340.ZIP (247k, 9-Jun-2012).
- Borland's TASMX 3.1 and TLINK 5.1 (or later)
- '386 PC with math coprocessor and 2 megabytes of RAM (no problem for Pentiums, Athlons, etc.)
TASMX and TLINK can be obtained from here:
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.
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,
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,
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 is 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).
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).
Yer basic shooter...with source of course. Have fun!
Download PEDE.ZIP (22k, 11-Jul-2012).
3D 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).
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
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
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
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
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).
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).
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
Animation Players 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
http://cd.textfiles.com/maxx/tothemaxss/FLI/, and the FLI format is
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).
"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
Snarf is a TSR program that takes snapshots of virtually any DOS graphic
or text screen. It's particularly useful under Windows XP, which will
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 Snarf15.zip (31k, 25-May-2007).
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.
QPR prints four pages in two columns in portrait mode.
Download DPR.ZIP (13k, 25-Jul-2011).
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 (15k, 25-Jul-2011).
- Paper size (11 or 14 inch)
- Orientation (portrait or landscape)
- Number of lines per page
- Characters per inch (font size)
- Stroke weight (boldness)
- Number of copies
Some utility programs to make DOS text files more compatible.
The source code shows a nice way to handle file I/O.
- EatEOF removes the final end-of-file character.
- Tab2Sp converts tab characters to equivalent spaces.
- Sp2Tab does the opposite.
Download COMPAT.ZIP (26k, 25-Jul-2011).
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).
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
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).
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
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.
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,
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).
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
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).
18-Apr-2008: Thanks to Ed of DX-Forth fame ( http://dxforth.netbay.com.au/)
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 posted below. (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:
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 is 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
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).
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 seems determined to
exterminate DOS programs because each successive version of Windows does
a poorer and 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 applications, but it still introduced many
incompatibilities. Windows Vista and Win7 won't run any kind of DOS
graphics program, not just XPL0's. Instead, they pop up the message
"This system does not support fullscreen mode." Nothing in the
Compatibility mode settings solves the problem. Win7 64-bit is the final
straw. It won't even run a one-byte program (RET) that has worked on
everything prior - so much for "upward compatibility." 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 good-old-fashioned DOS (which works fine on 64-bit CPUs). If
you're dismayed by all the problems created by Windows, it might be
helpful to remember what W.I.N.D.O.W.S. stands for: Windows Is Not DOS -
Only Works Sometimes.
This site is maintained by Loren Blaney. He'd
very much enjoy hearing from someone other than spammers for a change.
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)
Last update: 30-Jan-2016