Emulation of a Z80-based CP/M 2.2 machine with 64K ram on an ESP8266
To make the experience fit your profile, pick a username and tell us what interests you.
We found and based on your interests.
{You really should look in my repo for updated info on this, but since this empty field beckons me to write something here I'll just copy the current text from my github repo}
You will need ESP-Open-SDK installed. If you don't already have it you can get it at https://github.com/pfalcon/esp-open-sdk. Just follow the installation instructions there and be prepared for a lengthy (but automated) process.
I've only setup this for for Debian/Ubuntu but most dists should be fairly similar.
Unless you already have git installed you should install it
apt-get install git
Then install the prerequisites for pfalcon/esp-open-sdk
apt-get install make unrar-free autoconf automake libtool gcc g++
apt-get install gperf flex bison texinfo gawk ncurses-dev
apt-get install libexpat-dev python-dev python python-serial
apt-get install sed git unzip bash help2man wget bzip2 libtool-bin
Install the esp-open-sdk
git clone --recursive https://github.com/pfalcon/esp-open-sdk.git
cd esp-open-sdk
make
export PATH=~/esp-open-sdk/xtensa-lx106-elf/bin:$PATH
cd ..
Install prerequisites for cpm8266
apt-get install z80asm cpmtools zip
Clone the cpm8266 repo and config your environment
Instead of setting and exporting these environment variables you could change the settings in the top of the Makefile instead
git clone https://github.com/SmallRoomLabs/cpm8266.git
cd cpm8266/code
export ESP8266SDK=~/esp-open-sdk
export ESPTOOL=~/esp-open-sdk/esptool/esptool.py
export ESPPORT=/dev/ttyUSB0
Compile the emulator and all cp/m disks and upload it to the ESP8266
make full
Connect to the emulator and boot into CP/M
Run any serial terminal emulator set to 8N1 at any standard speed between 300 and 115200 baud. To run any full screen CP/M programs you should have VT100/ANSI terminal emulation.
Just to get started you can install the "screen" package and use that as a serial terminal.
apt-get install screen
And then connect with:
screen /dev/ttyUSB0 9600
Press Enter twice to autobaud to get the EMON:-prompt and then B <Enter>
to Boot into CP/M.
To compile with the wifi option enabled
Either do a
BUILD=WIFI make full
or change the BUILD option in the Makefile.
After the full re-compile and upload of all disks you can connect via telnet port 23 (the default telnet port) after the red led (on the NodeMCU board) goes off. The led is lit as long as the wifi has not received the ip address via DHCP.
Create an account to leave a comment. Already have an account? Log In.
Don't forget the ESP32ers with the additional megabytes of PSRAM!
For a CP/M on an ESP32 not using PSRAM look at: https://hackaday.io/project/18291-runcpm and https://github.com/MockbaTheBorg/RunCPM
Pro: Easy to use because it maps file access to a FATFS where directories are used as CP/M drives.
Pro: Multiplatform: It runs on some other platforms than the ESP32 too.
Pro: Where possible, it allows accessing the GPIO pins with CP/M software.
Contra: Only CP/M-2.2 so far. Because it does not mimic a well known hardware (e.g. like AltairZ80 ports to MCUs), every other CP/M sibling would need to be adapted first..
Great points Yeti! More research needed as this sounds very promising. Right now, RunCP/M on a Due is my main board I am using. I have another arduino (Mega) running a VT100 emulation for a touchscreen, with fast (30ms) screen redraws, but that uses a fair bit of ram to hold all the font data. With an ESP32, it should be entirely possible to combine both into one board. Plus it would be brilliant to have the wifi still available. MP/M is the operating system I'd love to see in an emulation. I have code for this on a FPGA (cyclone II, III, IV) with a model for a MMU in VHDL. It should be possible to translate that code into C.
There's lots of potential in these little cuties!
Telnetting into RunCPM is not yet in the main branch: https://github.com/MockbaTheBorg/RunCPM/issues/74
ESP32 and displays (e.g. 480x320 for acceptable 80 chars/line) already is no dark magic.
The big hurdle to get a nice mobile/mini unit is finding a nice keyboard but even there the ESP32 might already contain the answer (having BT/BLE)...
Ommmmmmmmm... ;-)
Take a look at Fabrizio Di Vittorio's ESP32 CP/M emulation with PS2 keyboard/mouse input, and VGA terminal emulation.: https://www.youtube.com/watch?v=v7eKlSkGKWw
Question and sorry it's very stupid one: It's possible to connect a screen and load some game ? Would that work ?
Great project I really like it a lot. Years ago I had an Spectrum 48Kb and also one of this gray Timex Sinclair 2068 that had a great sound chip :)
In theory it should be possible, but it would stretch the resources on the ESP even more, and it would also take a bit of programming. This system is made to use a terminal to show the text, it doesn't have any video memory of its own.
soo cool!!!! i'm going to build a mini cp/m computer with a keyboard ad display connected to an arduino nano and, maybe, another esp8266 just for wifi connection. really magic!!!
as a terminal the best choice seem to be putty.
how much funny is to run old software :-)
First of all, great job!
I could not get the supplied xmodem program to work. However, there is a patch at https://github.com/sbelectronics/rc2014/tree/master/patches (xmodem.patch) that can be applied to the supplied XMODEM.ASM, which can then be reassembled to get it working.
Fantastic work! Any rough idea how fast the emulation runs, like a 1Mhz Z80 or a 10Mhz Z80 etc? Also very interested in the idea of getting wifi working, like you say, then you can telnet in remotely, use any PC as a terminal, and start to think about crazy things like networking CP/M. I have built a few CP/M systems over the years, one perennial problem is getting files in and out. Using the esp8266 at, say, 38k baud over a serial link would be painfully slow but over wifi would be much faster. You are building something brilliant here, keep up the good work :)
Thanks for the kind words...
Running a 400 000 000 T-cycles test code I wrote that have a mix of all instruction groups I get a figure of about being equal to a 12MHz Z80. This is with the full emulation of undocumented instructions and flags being turned on (passing the ZEXALL tests). Turning off this might give another MHz or so.
But it's hard to accurately tell the speed of an emulated machine. Some instructions probably are much faster emulated than others relative to the timings of a real Z80.
Turning on the wifi-mode slows the emulation down a bit though. I think I ended up at 10MHz.
Running the serial link at 115200 issnt too bad, especially considering a floppy only hold 256KB, so at full speed it only takes 23 seconds to fill up a floppy. The xmodem protocol adds a bit of overhead so say 30 seconds. I guess I could up the 115200 higher without any issues, but my autobauding algorithm currently only handles speed between 300 and 115K.
But as you say, doing some kind of network of multiple machines over a wifi link would be kinda fun. Seems like I have to purchase a few more nodemcus to test. (The one that I got will probably break soon anyways since I've flashed it what feels like a gazillion times during this project - and I'm not doing any wear-levelling on the emulated floppies either) ;-)
12Mhz is very impressive. My original computer was a 4Mhz machine but of course the (real) floppy drives were the slow part. More recently I've used an emulation on the Propeller chip which was about the same as a 1Mhz chip. A bit slow, and then for the last year I have had one of Grant Searle's fpga boards running CP/M and using an ESP8266 to upload data to the internet. The code is written in C using wordstar and then compiled on the board. I've managed to get the ESP8266 working reliably with the various commands, and lots of software tweaks to manage timeouts and unreliable connections.
The wifi part of the ESP8266 is very useful, but I had no idea there was enough room in there to also fit CP/M!
What clever wizardry are you using to share the wifi and CP/M emulation?
The big issue when using wifi is the available dram (data ram). It starts out at 96KB and without the wifi stack going there's about 80K available, so I have plenty of space for the 64K cp/m ram and a 4K flash buffer.
But the wifi & tcp/ip stacks eats up so much ram that had reduce the 64K down to 38K in order to fit it all. And the code size blew up so much that I had to remove one 256K floppy image as well.
Without wifi:
text data bss dec hex filename
12788 10 70408 83206 14506 image.elf
With wifi:
text data bss dec hex filename
244000 892 69760 314652 4cd1c image.elf
Quite a difference! But I can allocate some of the iram (instruction ram) and use that as more ram for the cp/m machine. I got that tip from [sprite_tm], so some day I'll have at least 48K in wifi mode. The 38 is too little for many applications... ;-(
Hmm, tricky re the memory usage and wifi. 64K CP/M with wifi sounds so close yet unattainable...!
I have ordered a couple of nodemcu's. This is such a brilliant project!
I briefly looked at the esp-32 boards but they are $20 and there arduino solutions for similar prices. Back to the nodemcu, how much access do you have to the source code for the wifi? Just wondering why it needs so much data space? Ok, presumably it needs to buffer data coming back when you do a web request, but presumably one is not buffering pictures as CP/M can't display them anyway. So for talking just data, eg thingspeak, that would be less, (I think each request/data return cycle for thingspeak/xively was just a few hundred bytes each time). Just thinking aloud, say you request something in CP/M, then the data buffers could be in CP/M (or even better, within a program running on CP/M in C or BASIC or whatever), not so much within the wifi stack. Then the wifi stack's main purpose is to get rid of data as quickly as possible and CP/M can handle it (or not), which might get the data part of the wifi stack down. If that is what is taking up all the data space?
What language is the wifi stack written in? Able to modify??
I'm confused as to the various versions of ESP8266 LN and ESP8266 F5
I can't find a sight that would tell me the difference! So which one should I buy,
or is there another vsersion I should use?
Sorry, I've got no idea about the difference between the LN and F5 models. But in general all the ESP8266 chips are identical. The only differences is the PCB's they are put on, like how many pins that are brought out from the chip to the pin headers on the pcb, or whether there is a USB/Serial converter or a voltage regulator added to the PCB.
I prefer using a NodeMCU, they plug in to the computer using a usb cable and you don't have to press any buttons or fiddle around when uploading new code to it. Very convenient. The Adafruit Huzzah or the Wemos D1 are good alternatives to the NodeMCU and operates similarly.
Get one of those and save yourself a lot of headaches.
Become a member to follow this project and never miss any updates
Regarding the memory requirements, over the last year the ESP32 has been coming down in price. The spec sheet says that has 512k of ram. In theory, that could mean several CP/M emulations in parallel, or ram disks, or MP/M etc. I wonder how hard it would be to port across from the ESP8266 to the ESP32?