davidgiven / cpm65

CP/M for the 6502
BSD 2-Clause "Simplified" License
264 stars 24 forks source link

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!

CP/M-65 running on a BBC Micro CP/M-65 running on a Commodore 64 CP/M-65 running on a Commander X16 CP/M-65 running on an Apple IIe CP/M-65 running on a Commodore PET 4032 CP/M-65 running on a Commodore PET 8032 CP/M-65 running on a Commodore PET 8096 CP/M-65 running on a Commodore VIC-20 CP/M-65 running on an Atari 800XL CP/M-65 running on an Tangerine Oric 1 CP/M-65 running on the Sorbus Computer CP/M-65 running on the Olimex neo6502 CP/M-65 running on the nano6502 CP/M-65 running on the KIM-1

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 the Commodore 64 (with 1541 drive) and BBC Micro (producing a 200kB SSSD DFS disk):

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

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: 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), and FreePascal (because the MADS assembler is written in Pascal). Use these Debian packages:

cc1541 cpmtools libfmt-dev python3 fp-compiler srecord

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

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

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).

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.