Home

Awesome

CP/M-65

What?

This is a native port of Digital Research's seminal 1977 operating system CP/M to the 6502. So far it runs on:

Unlike the original, it supports relocatable binaries, so allowing unmodified binaries to run on any system: this is necessary as 6502 systems tend to be much less standardised than 8080 and Z80 systems. (The systems above all load programs at different base addresses.)

Currently you can cross-assemble programs from a PC, as well as a working C toolchain with llvm-mos. For native development, there's a basic assembler, a couple of editors, a BASIC, and a byte-compiled Pascal subset and interpreter. You need about 20kB to run the assembler at all, and of course more memory the bigger the program.

No, it won't let you run 8080 programs on the 6502!

<div style="text-align: left"> <a href="doc/bbcmicro.png"><img src="doc/bbcmicro.png" style="width:40%" alt="CP/M-65 running on a BBC Micro"></a> <a href="doc/c64.png"><img src="doc/c64.png" style="width:40%" alt="CP/M-65 running on a Commodore 64"></a> <a href="doc/x16.png"><img src="doc/x16.png" style="width:40%" alt="CP/M-65 running on a Commander X16"></a> <a href="doc/apple2e.png"><img src="doc/apple2e.png" style="width:40%" alt="CP/M-65 running on an Apple IIe"></a> <a href="doc/pet4032.png"><img src="doc/pet4032.png" style="width:40%" alt="CP/M-65 running on a Commodore PET 4032"></a> <a href="doc/pet8032.png"><img src="doc/pet8032.png" style="width:40%" alt="CP/M-65 running on a Commodore PET 8032"></a> <a href="doc/pet8096.png"><img src="doc/pet8096.png" style="width:40%" alt="CP/M-65 running on a Commodore PET 8096"></a> <a href="doc/vic20.png"><img src="doc/vic20.png" style="width:40%" alt="CP/M-65 running on a Commodore VIC-20"></a> <a href="doc/atari800.png"><img src="doc/atari800.png" style="width:40%" alt="CP/M-65 running on an Atari 800XL"></a> <a href="doc/oric.png"><img src="doc/oric.png" style="width:40%" alt="CP/M-65 running on an Tangerine Oric 1"></a> <a href="doc/snes.png"><img src="doc/snes.png" style="width:40%" alt="CP/M-65 running on the Super Nintendo"></a> <a href="doc/sorbus.png"><img src="doc/sorbus.png" style="width:40%" alt="CP/M-65 running on the Sorbus Computer"></a> <a href="doc/neo6502.png"><img src="doc/neo6502.png" style="width:40%" alt="CP/M-65 running on the Olimex neo6502"></a> <a href="doc/nano6502.png"><img src="doc/nano6502.png" style="width:40%" alt="CP/M-65 running on the nano6502"></a> <a href="doc/kim-1.png"><img src="doc/kim-1.png" style="width:40%" alt="CP/M-65 running on the KIM-1"></a> <a href="doc/osi.png"><img src="doc/osi.png" style="width:40%" alt="CP/M-65 running on the Ohio Scientific"></a> </div>

Why?

Why not?

Where?

It's open source on GitHub!

How?

You have two options:

To build it, you will need the llvm-mos toolchain. CP/M-65 support is available out of the box. Once installed, you should just be able to run the Makefile and you'll get bootable disk images for all supported platforms in the images directory:

make LLVM=<your llvm-mos bin directory here>/

Building CP/M-65 is a bit of a performance because it's aggregating lots of other software, all of which need building in turn. You'll need primarily: a C and C++ compiler, cc1541 (for creating 1541 disk images), cpmtools (for creating CP/M disk images), libfmt (all the C++ tools use this), python3 (for the build system), FreePascal (because the MADS assembler is written in Pascal), 64tass (for the Super Nintendo 65816 stuff). Use these Debian packages:

cc1541 cpmtools libfmt-dev fp-compiler moreutils mame srecord 64tass libreadline-dev

There are also automated tests which use mame to emulate a reasonable number of the platforms, to verify that they actually work. To use this, install mame, and then run scripts/get-roms.sh to download the necessary system ROMs. Then do:

make LLVM=<your llvm-mos bin directory here>/ -j$(nproc) +mametest

You can add +all to that if you want to do a normal build and run the tests at the same time.

BBC Micro notes

Commodore 64 notes

VIC-20 notes

Commodore PET notes

Commander X16 notes

Apple IIe notes

Atari 800 XL/XE notes

Oric notes

Super Nintendo notes

Sorbus notes

neo6502 notes

nano6502 notes

KIM-1 with K-1013 FDC notes

KIM-1 with directly attached SD card notes

KIM-1 with Commodore 1541 drive

Ohio Scientific notes

Supported programs

Commands include DUMP, STAT, COPY, SUBMIT, ASM, QE and BEDIT plus some smaller utilities. I'd love more --- send me pull requests! The build system supports cc65 assembler and llvm-mos C programs. The native assembler can be used (in emulation) to cross compile programs for CP/M-65.

In the CCP, you get the usual DIR, ERA, REN, TYPE and USER. There is no SAVE as on the relocatable CP/M-65 system assembling images in memory is of questionable utility, but there's a new FREE command which shows memory usage.

You also get a port of Altirra BASIC, an open source Atari BASIC clone. This is called ATBASIC. See below for more details.

Pokey the Penguin loves to read your pull requests!

The assembler

The CP/M-65 assembler is extremely simple and very much customised to work for the CP/M-65 environment. It operates entirely in memory (so it should be fast) but it's written in C (so it's going to be big and slow). It's very very new and is likely to have lots of bugs. There is, at least, a port of the DUMP program to it which assembles, works, and is ready to play with.

Go read cpmfs/asm.txt for the documentation.

The BASIC

Altirra BASIC is an open source recreation of the BASIC used on the Atari 8-bit machines (on which CP/M-65 runs, coincidentally). It has been heavily modified by me to work on CP/M-65. Anything Atari-related has been removed, including graphics, sound, etc. In addition, I have extended the error reporting, added support for case-insensitive keywords (simply because Atari BASIC traditionally requires upper case but most CP/M-65 platforms don't have caps lock keys!), and fairly crudely added file I/O support. There is no screen editor. It is (should be) binary compatible with Atari BASIC, although programs using Atari features which aren't supported will of course not run.

It is currently rather fragile with a number of known (and, probably, unknown) bugs. Please file bug reports!

Atari BASIC is rather different from Microsoft BASIC. Please consult the user manual.

Important! Do not contact the author of Altirra BASIC for anything related to the CP/M-65 port! Any bugs are strictly my fault.

The editors

BEdit is an incredibly simple line editor modelled after a basic interpreter (command entry, with LOAD, SAVE, LIST, line numbers etc). It's written in machine code and assembled with the CP/M-65 assembler; you can assemble it locally if you have a system with 30kB or more TPA. It'll run on all platforms.

Go read cpmfs/bedit.txt for the documentation.

QE is a much less simple vi-inspired screen editor, written in C. it's much more comfortable to use than BEDIT, but is about five times the size, and will only run on systems with a SCREEN driver, as noted above (you can also use the DEVICES command to see what devices your system supports).

DwarfStar is another screen editor. It has the same keybindings as WordStar, so those familiar with that will feel right at home. For a refresher, see the documentation, which was written in DS itself and is also available within CP/M-65 on the systems that have DS.COM installed.

The Pascal

Pascal-M is a Pascal subset intended for use on very small machines. It compiles to bytecode, M-code, which is then run with an interpreter. The compiler is itself written in Pascal-M and is capable of compiling itself (very slowly). There is a basic port to CP/M-65.

To use it, you need to use the interpreter, PINT, to run the compiler to compile your program into an OBP file. This is then translated into an OBB file by PLOAD (not written in Pascal!). You can then run the resulting OBB file with PINT. For example:

A> PINT PASC.OBB HELLO.PAS HELLO.OBP
A> PLOAD HELLO.OBP HELLO.OBB
A> PINT HELLO.OBB

The compiler will also generate a PROGRAM.ERR file containing a copy of any error messages that result from the compilation process.

Sadly, you need at least 36kB of free RAM to run the compiler, and also the disk images for various systems are full, so it's only included for a few platforms.

Pascal-M is considerably simplified from the full Pascal language, with support for only 16-bit integers, but it does support records, sets, enumerations, pointers, nested functions and procedures, etc. Performance isn't brilliant but it does work. CP/M-65 is very basic, consisting of support for text files using the traditional assign/reset/rewrite/close API. You can have as many open at once as you like but you can't seek inside a file. In addition, while new is supported, there is no dispose.

For more information on Pascal-M, see Hans Otten's website. However, do not report bugs on the CP/M-65 port to him --- file bug reports here instead.

Utilities

bin/cpmemu contains a basic CP/M-65 user mode emulator and debugger. It'll run programs on the host environment with an emulated disk, which is very useful for testing and development. To use:

./bin/cpmemu .obj/dump.com diskdefs

Add -d at the front of the command line to drop into the debugger --- use ? for basic help. It can only access 8.3-format all-lowercase filenames in the current directory, but you can also map drives. Use -h for help.

Who?

You may contact me at dg@cowlark.com, or visit my website at http://www.cowlark.com. There may or may not be anything interesting there. The CP/M-65 project was designed and written by me, David Given.

License

Everything here so far except the contents of the third_party directory is © 2022-2023 David Given, and is licensed under the two-clause BSD open source license. Please see LICENSE for the full text. The tl;dr is: you can do what you like with it provided you don't claim you wrote it.

The exceptions are the contents of the third_party directory, which were written by other people and are not covered by this license. This directory as a whole contains GPL software, which means that if you redistribute the entire directory, you must conform to the terms of the GPL.

third_party/lib6502 contains a hacked copy of the lib6502 library, which is © 2005 Ian Plumarta and is available under the terms of the MIT license. See third_party/lib6502/COPYING.lib6502 for the full text.

third_party/tomsfonts contains a copy of the atari-small font, which is © 1999 Thomas A. Fine and is available under the terms of a minimal free license. See third_party/tomsfonts/LICENSE for the full text.

third_party/altirrabasic contains a hacked copy of Altirra Basic, which is © 2014 Avery Lee and is available under the terms of a minimal free license. See third_party/altirrabasic/LICENSE.md for the full text.

third_party/mads contains a copy of Mad Assembler, which is © 2018-2023 Tomasz Biela and is available under the terms of the MIT license. See third_party/mads/LICENSE for the full text.

third_party/pascal-m contains a extremely hacked up copy of the Pascal-M bytecode compiler and interpreter, which is © 1978-2021 Niklaus Wirth, Mark Rustad and Hans Otten and is available under the terms of the MIT license. See third_party/pascal-m/LICENSE for the full text.

third_party/dwarfstar contains DwarfStar, which is © 2024 by Ivo van Poorten and is available under the terms of the BSD 2-Clause License. See third_party/dwarfstar/LICENSE for the full text.

third_party/zmalloc contains a copy of zmalloc, which is © 2024 by Ivo van Poorten and is available under the terms of the 0BSD License. See third_party/zmalloc/LICENSE for the full text.